From dc6abdc2e0c3e771fc9e8596dc8b1604b8a16517 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Mon, 13 Oct 2025 13:29:19 +0200 Subject: [PATCH] [task-408] Widgets von Plankton --- lib/plankton/plankton.d.ts | 98 +++---- lib/plankton/plankton.js | 368 +++++++++++++------------- source/base/widget.ts | 18 -- source/pages/overview/logic.ts | 2 +- source/widgets/listview/logic.ts | 3 +- source/widgets/mode_switcher/logic.ts | 3 +- source/widgets/sources/logic.ts | 3 +- source/widgets/weekview/logic.ts | 3 +- tools/makefile | 1 - tools/update-plankton | 1 + 10 files changed, 239 insertions(+), 261 deletions(-) delete mode 100644 source/base/widget.ts diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 91457ef..3302bcf 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -3809,55 +3809,6 @@ declare namespace lib_plankton.translate { */ function stance(str: string): string; } -declare namespace lib_plankton.zoo_page { - /** - */ - export type type_location = { - name: string; - parameters: Record; - }; - /** - */ - type type_handler = ((parameters: Record, target_element: Element) => void); - /** - */ - type type_nav_entry_definition = { - location: type_location; - label: string; - groups: Array; - }; - /** - */ - export let _pool: Record; - /** - */ - export function encode(location: type_location): string; - /** - * encodes a location in the URL and loads it - */ - export function set(location: type_location): void; - /** - */ - export function reload(): Promise; - /** - */ - export function register(location_name: string, handler: type_handler): void; - /** - */ - export function nav_set_groups(groups: (null | Array)): void; - /** - */ - export function init(target_element: Element, { "pool": pool, "fallback": fallback, "nav_entries": nav_entries, "nav_initial_groups": nav_initial_groups, }?: { - pool?: Record; - fallback?: (null | type_location); - nav_entries?: Array; - nav_initial_groups?: (null | Array); - }): void; - /** - */ - export function start(): void; - export {}; -} declare namespace lib_plankton.zoo_widget { /** */ @@ -4043,6 +3994,55 @@ declare namespace lib_plankton.zoo_widget { load(target_element: HTMLElement): Promise; } } +declare namespace lib_plankton.zoo_page { + /** + */ + export type type_location = { + name: string; + parameters: Record; + }; + /** + */ + type type_handler = ((parameters: Record, target_element: Element) => void); + /** + */ + type type_nav_entry_definition = { + location: type_location; + label: string; + groups: Array; + }; + /** + */ + export let _pool: Record; + /** + */ + export function encode(location: type_location): string; + /** + * encodes a location in the URL and loads it + */ + export function set(location: type_location): void; + /** + */ + export function reload(): Promise; + /** + */ + export function register(location_name: string, handler: type_handler): void; + /** + */ + export function nav_set_groups(groups: (null | Array)): void; + /** + */ + export function init(target_element: Element, { "pool": pool, "fallback": fallback, "nav_entries": nav_entries, "nav_initial_groups": nav_initial_groups, }?: { + pool?: Record; + fallback?: (null | type_location); + nav_entries?: Array; + nav_initial_groups?: (null | Array); + }): void; + /** + */ + export function start(): void; + export {}; +} declare namespace lib_plankton.zoo_input { /** * @author fenris diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 6ff86ef..64e504d 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -11738,190 +11738,6 @@ var lib_plankton; })(translate = lib_plankton.translate || (lib_plankton.translate = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:zoo-page«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:zoo-page« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:zoo-page« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:zoo-page«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var zoo_page; - (function (zoo_page) { - /** - */ - zoo_page._pool = {}; - /** - */ - let _fallback = null; - /** - */ - let _current = null; - /** - */ - let _target_element = null; - /** - */ - let _nav_entries; - /** - */ - function encode(location) { - return ("#" - + - ([location.name] - .concat(Object.entries(location.parameters) - .filter(([key, value]) => (value !== null)) - .map(([key, value]) => (key + "=" + value))))); - } - zoo_page.encode = encode; - /** - */ - function decode(encoded) { - if (encoded === "") { - return null; - } - else { - if (!encoded.startsWith("#")) { - return null; - } - else { - const parts = encoded.slice(1).split(","); - return { - "name": parts[0], - "parameters": Object.fromEntries(parts.slice(1) - .map(part => { - const parts_ = part.split("="); - return [parts_[0], parts_[1]]; - })), - }; - } - } - } - /** - * renders a page to the main element - */ - async function load(location) { - // _target_element.innerHTML = "[loading …]"; - _target_element.innerHTML = ""; - if (location === null) { - // do nothing - } - else { - if (!(location.name in zoo_page._pool)) { - _target_element.innerHTML = "not found"; - } - else { - await zoo_page._pool[location.name](location.parameters, _target_element); - _current = location; - } - } - } - /** - * retrieves the location from the set URL - */ - function get() { - return decode(window.location.hash); - } - /** - * encodes a location in the URL and loads it - */ - function set(location) { - window.location.hash = encode(location); - } - zoo_page.set = set; - /** - */ - function reload() { - return load(get()); - } - zoo_page.reload = reload; - /** - */ - function register(location_name, handler) { - zoo_page._pool[location_name] = handler; - } - zoo_page.register = register; - /** - */ - 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 = fallback; - Object.entries(pool).forEach(([location_name, handler]) => { - register(location_name, handler); - }); - window.addEventListener("hashchange", () => { - const location_old = _current; - const location_new = (get() ?? _fallback); - if (((location_old === null) - && - (location_new !== null)) - || - ((location_old !== null) - && - (location_new !== null) - && - (location_old.name !== location_new.name))) { - load(location_new); - } - else { - // 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; - /** - */ - function start() { - const location = (get() ?? _fallback); - set(location); - load(location); - } - zoo_page.start = start; - })(zoo_page = lib_plankton.zoo_page || (lib_plankton.zoo_page = {})); -})(lib_plankton || (lib_plankton = {})); -/* This file is part of »bacterio-plankton:zoo-widget«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -12441,6 +12257,190 @@ var lib_plankton; })(zoo_widget = lib_plankton.zoo_widget || (lib_plankton.zoo_widget = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:zoo-page«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:zoo-page« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:zoo-page« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:zoo-page«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_page; + (function (zoo_page) { + /** + */ + zoo_page._pool = {}; + /** + */ + let _fallback = null; + /** + */ + let _current = null; + /** + */ + let _target_element = null; + /** + */ + let _nav_entries; + /** + */ + function encode(location) { + return ("#" + + + ([location.name] + .concat(Object.entries(location.parameters) + .filter(([key, value]) => (value !== null)) + .map(([key, value]) => (key + "=" + value))))); + } + zoo_page.encode = encode; + /** + */ + function decode(encoded) { + if (encoded === "") { + return null; + } + else { + if (!encoded.startsWith("#")) { + return null; + } + else { + const parts = encoded.slice(1).split(","); + return { + "name": parts[0], + "parameters": Object.fromEntries(parts.slice(1) + .map(part => { + const parts_ = part.split("="); + return [parts_[0], parts_[1]]; + })), + }; + } + } + } + /** + * renders a page to the main element + */ + async function load(location) { + // _target_element.innerHTML = "[loading …]"; + _target_element.innerHTML = ""; + if (location === null) { + // do nothing + } + else { + if (!(location.name in zoo_page._pool)) { + _target_element.innerHTML = "not found"; + } + else { + await zoo_page._pool[location.name](location.parameters, _target_element); + _current = location; + } + } + } + /** + * retrieves the location from the set URL + */ + function get() { + return decode(window.location.hash); + } + /** + * encodes a location in the URL and loads it + */ + function set(location) { + window.location.hash = encode(location); + } + zoo_page.set = set; + /** + */ + function reload() { + return load(get()); + } + zoo_page.reload = reload; + /** + */ + function register(location_name, handler) { + zoo_page._pool[location_name] = handler; + } + zoo_page.register = register; + /** + */ + 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 = fallback; + Object.entries(pool).forEach(([location_name, handler]) => { + register(location_name, handler); + }); + window.addEventListener("hashchange", () => { + const location_old = _current; + const location_new = (get() ?? _fallback); + if (((location_old === null) + && + (location_new !== null)) + || + ((location_old !== null) + && + (location_new !== null) + && + (location_old.name !== location_new.name))) { + load(location_new); + } + else { + // 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; + /** + */ + function start() { + const location = (get() ?? _fallback); + set(location); + load(location); + } + zoo_page.start = start; + })(zoo_page = lib_plankton.zoo_page || (lib_plankton.zoo_page = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:zoo-input«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' diff --git a/source/base/widget.ts b/source/base/widget.ts deleted file mode 100644 index f971ca8..0000000 --- a/source/base/widget.ts +++ /dev/null @@ -1,18 +0,0 @@ -namespace _dali -{ - - /** - * @todo outsource - */ - export abstract class class_widget - { - - /** - */ - public abstract load( - target_element : Element - ) : Promise; - - } - -} diff --git a/source/pages/overview/logic.ts b/source/pages/overview/logic.ts index 7caeb15..e6dd23b 100644 --- a/source/pages/overview/logic.ts +++ b/source/pages/overview/logic.ts @@ -27,7 +27,7 @@ namespace _dali.pages.overview // mode switcher { - const widget_mode_switcher : _dali.class_widget = new _dali.widgets.mode_switcher.class_widget_mode_switcher( + const widget_mode_switcher : lib_plankton.zoo_widget.interface_widget = new _dali.widgets.mode_switcher.class_widget_mode_switcher( [ { "mode": _dali.type.enum_view_mode.week, diff --git a/source/widgets/listview/logic.ts b/source/widgets/listview/logic.ts index 9523e4c..c79f673 100644 --- a/source/widgets/listview/logic.ts +++ b/source/widgets/listview/logic.ts @@ -28,7 +28,7 @@ namespace _dali.widgets.listview /** */ - export class class_widget_listview extends _dali.class_widget + export class class_widget_listview implements lib_plankton.zoo_widget.interface_widget { /** @@ -94,7 +94,6 @@ namespace _dali.widgets.listview }, options ); - super(); this.get_entries = get_entries; this.container = null; this.action_select_event = options.action_select_event; diff --git a/source/widgets/mode_switcher/logic.ts b/source/widgets/mode_switcher/logic.ts index 50a8e53..fd7c9b0 100644 --- a/source/widgets/mode_switcher/logic.ts +++ b/source/widgets/mode_switcher/logic.ts @@ -11,7 +11,7 @@ namespace _dali.widgets.mode_switcher /** */ - export class class_widget_mode_switcher extends _dali.class_widget + export class class_widget_mode_switcher implements lib_plankton.zoo_widget.interface_widget { /** @@ -47,7 +47,6 @@ namespace _dali.widgets.mode_switcher } ) { - super(); this.options = options; this.initial_selection = initial_selection; this.action_change = action_change; diff --git a/source/widgets/sources/logic.ts b/source/widgets/sources/logic.ts index e9b57da..01c082c 100644 --- a/source/widgets/sources/logic.ts +++ b/source/widgets/sources/logic.ts @@ -13,7 +13,7 @@ namespace _dali.widgets.sources /** */ - export class class_widget_sources extends _dali.class_widget + export class class_widget_sources implements lib_plankton.zoo_widget.interface_widget { /** @@ -53,7 +53,6 @@ namespace _dali.widgets.sources }, options ); - super(); this.keys = []; this.data = {}; entries.forEach( diff --git a/source/widgets/weekview/logic.ts b/source/widgets/weekview/logic.ts index 85686df..e788043 100644 --- a/source/widgets/weekview/logic.ts +++ b/source/widgets/weekview/logic.ts @@ -28,7 +28,7 @@ namespace _dali.widgets.weekview /** */ - export class class_widget_weekview extends _dali.class_widget + export class class_widget_weekview implements lib_plankton.zoo_widget.interface_widget { /** @@ -96,7 +96,6 @@ namespace _dali.widgets.weekview }, options ); - super(); this.get_entries = get_entries; this.container = null; this.action_select_day = options.action_select_day; diff --git a/tools/makefile b/tools/makefile index 3195a2b..dcc4413 100644 --- a/tools/makefile +++ b/tools/makefile @@ -134,7 +134,6 @@ logic: ${dir_build}/logic.js ${dir_temp}/logic-unlinked.js: \ ${dir_lib}/plankton/plankton.d.ts \ ${dir_source}/base/helpers.ts \ - ${dir_source}/base/widget.ts \ ${dir_source}/base/types.ts \ ${dir_source}/base/functions.ts \ ${dir_source}/resources/conf.ts \ diff --git a/tools/update-plankton b/tools/update-plankton index 7577b00..dad2426 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -23,6 +23,7 @@ modules="${modules} url" modules="${modules} pit" modules="${modules} www_form" modules="${modules} translate" +modules="${modules} zoo-widget" modules="${modules} zoo-page" modules="${modules} zoo-form" modules="${modules} zoo-input"