Pages durch Widgets ablösen #2

Merged
fenris merged 9 commits from task-408 into main 2025-10-14 23:37:02 +02:00
10 changed files with 239 additions and 261 deletions
Showing only changes of commit dc6abdc2e0 - Show all commits

View file

@ -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<string, any>;
};
/**
*/
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;
/**
* encodes a location in the URL and loads it
*/
export function set(location: type_location): void;
/**
*/
export function reload(): Promise<void>;
/**
*/
export function register(location_name: string, handler: type_handler): void;
/**
*/
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;
/**
*/
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<void>;
}
}
declare namespace lib_plankton.zoo_page {
/**
*/
export type type_location = {
name: string;
parameters: Record<string, any>;
};
/**
*/
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;
/**
* encodes a location in the URL and loads it
*/
export function set(location: type_location): void;
/**
*/
export function reload(): Promise<void>;
/**
*/
export function register(location_name: string, handler: type_handler): void;
/**
*/
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;
/**
*/
export function start(): void;
export {};
}
declare namespace lib_plankton.zoo_input {
/**
* @author fenris

View file

@ -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'
<info@greenscale.de>
»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 <http://www.gnu.org/licenses/>.
*/
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'
<info@greenscale.de>
»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 <http://www.gnu.org/licenses/>.
*/
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'

View file

@ -1,18 +0,0 @@
namespace _dali
{
/**
* @todo outsource
*/
export abstract class class_widget
{
/**
*/
public abstract load(
target_element : Element
) : Promise<void>;
}
}

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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(

View file

@ -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;

View file

@ -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 \

View file

@ -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"