[upd] plankton
This commit is contained in:
parent
91a9715fbe
commit
c91c236e3d
33
lib/plankton/plankton.d.ts
vendored
33
lib/plankton/plankton.d.ts
vendored
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare type int = number;
|
||||
type int = number;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare type float = number;
|
||||
type float = number;
|
||||
declare class Buffer {
|
||||
constructor(x: string, modifier?: string);
|
||||
toString(modifier?: string): string;
|
||||
|
|
@ -19,7 +19,7 @@ declare namespace lib_plankton.base {
|
|||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare type type_pseudopointer<type_value> = {
|
||||
type type_pseudopointer<type_value> = {
|
||||
value: type_value;
|
||||
};
|
||||
/**
|
||||
|
|
@ -810,6 +810,10 @@ declare namespace lib_plankton.call {
|
|||
* @author fenris
|
||||
*/
|
||||
export function timeout(procedure: (() => void), delay_in_seconds: float): int;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
export function loop(procedure: (() => void), delay_in_seconds: float): int;
|
||||
/**
|
||||
* Promise version of "setTimeout"
|
||||
*
|
||||
|
|
@ -1965,7 +1969,7 @@ declare namespace lib_plankton.storage.memory {
|
|||
clear(): Promise<void>;
|
||||
write(key: any, value: any): Promise<boolean>;
|
||||
delete(key: any): Promise<void>;
|
||||
read(key: any): Promise<type_item>;
|
||||
read(key: any): Promise<Awaited<type_item>>;
|
||||
search(term: any): Promise<{
|
||||
key: string;
|
||||
preview: string;
|
||||
|
|
@ -3393,17 +3397,19 @@ declare namespace lib_plankton.zoo_page {
|
|||
/**
|
||||
*/
|
||||
type type_handler = ((parameters: Record<string, any>, target_element: Element) => void);
|
||||
/**
|
||||
*/
|
||||
type type_nav_entry_definition = {
|
||||
location: type_location;
|
||||
label: string;
|
||||
groups: Array<string>;
|
||||
};
|
||||
/**
|
||||
*/
|
||||
export let _pool: Record<string, type_handler>;
|
||||
/**
|
||||
*/
|
||||
export function encode(location: type_location): string;
|
||||
/**
|
||||
*/
|
||||
export function add_nav_entry(location: type_location, options?: {
|
||||
label?: (null | string);
|
||||
}): void;
|
||||
/**
|
||||
* encodes a location in the URL and loads it
|
||||
*/
|
||||
|
|
@ -3413,12 +3419,17 @@ declare namespace lib_plankton.zoo_page {
|
|||
export function reload(): Promise<void>;
|
||||
/**
|
||||
*/
|
||||
export function register(location_name: string, handler: type_handler, options?: {}): void;
|
||||
export function register(location_name: string, handler: type_handler): void;
|
||||
/**
|
||||
*/
|
||||
export function init(target_element: Element, options?: {
|
||||
export function nav_set_groups(groups: (null | Array<string>)): void;
|
||||
/**
|
||||
*/
|
||||
export function init(target_element: Element, { "pool": pool, "fallback": fallback, "nav_entries": nav_entries, "nav_initial_groups": nav_initial_groups, }?: {
|
||||
pool?: Record<string, type_handler>;
|
||||
fallback?: (null | type_location);
|
||||
nav_entries?: Array<type_nav_entry_definition>;
|
||||
nav_initial_groups?: (null | Array<string>);
|
||||
}): void;
|
||||
/**
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1883,6 +1883,14 @@ var lib_plankton;
|
|||
/*window.*/ setTimeout(procedure, Math.floor(delay_in_seconds * 1000)));
|
||||
}
|
||||
call.timeout = timeout;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function loop(procedure, delay_in_seconds) {
|
||||
return (
|
||||
/*window.*/ setInterval(procedure, Math.floor(delay_in_seconds * 1000)));
|
||||
}
|
||||
call.loop = loop;
|
||||
/**
|
||||
* Promise version of "setTimeout"
|
||||
*
|
||||
|
|
@ -2143,7 +2151,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
|
|
@ -6992,6 +7000,12 @@ var lib_plankton;
|
|||
* @author fenris
|
||||
*/
|
||||
class class_relation {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
check(value, reference) {
|
||||
return this.predicate(value, reference);
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
@ -7001,12 +7015,6 @@ var lib_plankton;
|
|||
this.name = name;
|
||||
this.predicate = predicate;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
check(value, reference) {
|
||||
return this.predicate(value, reference);
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
@ -9596,6 +9604,9 @@ var lib_plankton;
|
|||
/**
|
||||
*/
|
||||
let _target_element = null;
|
||||
/**
|
||||
*/
|
||||
let _nav_entries;
|
||||
/**
|
||||
*/
|
||||
function encode(location) {
|
||||
|
|
@ -9649,25 +9660,6 @@ var lib_plankton;
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
function add_nav_entry(location, options = {}) {
|
||||
options = Object.assign({
|
||||
"label": null,
|
||||
}, options);
|
||||
let ul_element = document.querySelector("nav > ul");
|
||||
{
|
||||
let li_element = document.createElement("li");
|
||||
{
|
||||
let a_element = document.createElement("a");
|
||||
a_element.setAttribute("href", encode(location));
|
||||
a_element.textContent = (options.label ?? location.name);
|
||||
li_element.appendChild(a_element);
|
||||
}
|
||||
ul_element.appendChild(li_element);
|
||||
}
|
||||
}
|
||||
zoo_page.add_nav_entry = add_nav_entry;
|
||||
/**
|
||||
* retrieves the location from the set URL
|
||||
*/
|
||||
|
|
@ -9689,21 +9681,27 @@ var lib_plankton;
|
|||
zoo_page.reload = reload;
|
||||
/**
|
||||
*/
|
||||
function register(location_name, handler, options = {}) {
|
||||
options = Object.assign({}, options);
|
||||
function register(location_name, handler) {
|
||||
zoo_page._pool[location_name] = handler;
|
||||
}
|
||||
zoo_page.register = register;
|
||||
/**
|
||||
*/
|
||||
function init(target_element, options = {}) {
|
||||
options = Object.assign({
|
||||
"pool": {},
|
||||
"fallback": null,
|
||||
}, options);
|
||||
function nav_set_groups(groups) {
|
||||
_nav_entries.forEach(nav_entry => {
|
||||
const active = ((groups === null)
|
||||
||
|
||||
groups.some(group => nav_entry.definition.groups.includes(group)));
|
||||
nav_entry.element.classList.toggle("active", active);
|
||||
});
|
||||
}
|
||||
zoo_page.nav_set_groups = nav_set_groups;
|
||||
/**
|
||||
*/
|
||||
function init(target_element, { "pool": pool = {}, "fallback": fallback = null, "nav_entries": nav_entries = [], "nav_initial_groups": nav_initial_groups = null, } = {}) {
|
||||
_target_element = target_element;
|
||||
_fallback = options.fallback;
|
||||
Object.entries(options.pool).forEach(([location_name, handler]) => {
|
||||
_fallback = fallback;
|
||||
Object.entries(pool).forEach(([location_name, handler]) => {
|
||||
register(location_name, handler);
|
||||
});
|
||||
window.addEventListener("hashchange", () => {
|
||||
|
|
@ -9724,6 +9722,25 @@ var lib_plankton;
|
|||
// do nothing
|
||||
}
|
||||
});
|
||||
// nav
|
||||
{
|
||||
let ul_element = document.querySelector("nav > ul");
|
||||
_nav_entries = nav_entries.map(nav_entry_definition => {
|
||||
let li_element = document.createElement("li");
|
||||
{
|
||||
let a_element = document.createElement("a");
|
||||
a_element.setAttribute("href", encode(nav_entry_definition.location));
|
||||
a_element.textContent = (nav_entry_definition.label ?? nav_entry_definition.location.name);
|
||||
li_element.appendChild(a_element);
|
||||
}
|
||||
ul_element.appendChild(li_element);
|
||||
return {
|
||||
"definition": nav_entry_definition,
|
||||
"element": li_element,
|
||||
};
|
||||
});
|
||||
nav_set_groups(nav_initial_groups);
|
||||
}
|
||||
}
|
||||
zoo_page.init = init;
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue