ziko 2.0.0-beta.0 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +68 -87
- package/dist/ziko.js +68 -87
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +68 -87
- package/package.json +1 -1
- package/src/Layout/index.d.ts +38 -0
- package/src/Layout/index.js +98 -0
- package/src/dom/UIElement/index.js +4 -4
- package/src/dom/internal-utils/checkers.js +1 -1
- package/src/internal-utils/symbols/index.d.ts +4 -1
- package/src/internal-utils/symbols/index.js +1 -0
- package/src/mini-dom/UIElement/index.js +28 -32
- package/src/mini-dom/mixins/dom.js +34 -46
- package/src/mini-dom/mixins/lifecycle.js +0 -4
- package/src/router/file-based-router/index.d.ts +1 -1
- package/src/router/file-based-router/index.js +103 -30
- package/src/router/index.d.ts +2 -2
- package/src/router/index.js +1 -1
- package/src/router/internal-utils/renderer.js +6 -0
package/dist/ziko.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Mon Sep 07 2026 22:41:50 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -276,16 +276,12 @@ let UIElement$1 = class UIElement extends UINode{
|
|
|
276
276
|
constructor(){
|
|
277
277
|
super();
|
|
278
278
|
}
|
|
279
|
-
init({element, name, type,
|
|
279
|
+
init({element, name, type, mount, props = {}, items = []} = {}){
|
|
280
280
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
281
281
|
if(typeof element === "string") {
|
|
282
282
|
switch(type){
|
|
283
|
-
case "html" :
|
|
284
|
-
|
|
285
|
-
} break;
|
|
286
|
-
case "svg" : {
|
|
287
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
288
|
-
} break;
|
|
283
|
+
case "html" : element = globalThis?.document?.createElement(element); break;
|
|
284
|
+
case "svg" : element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element); break;
|
|
289
285
|
default : throw Error("Not supported")
|
|
290
286
|
}
|
|
291
287
|
}
|
|
@@ -295,37 +291,37 @@ let UIElement$1 = class UIElement extends UINode{
|
|
|
295
291
|
itemsTarget : this,
|
|
296
292
|
isInteractive : false,
|
|
297
293
|
parent:null,
|
|
298
|
-
isBody:false,
|
|
299
|
-
isRoot:false,
|
|
300
|
-
isHidden: false,
|
|
301
|
-
isFrozzen:false,
|
|
302
|
-
attributes: {},
|
|
303
|
-
filters: {},
|
|
304
|
-
temp:{}
|
|
294
|
+
// isBody:false,
|
|
295
|
+
// isRoot:false,
|
|
296
|
+
// isHidden: false,
|
|
297
|
+
// isFrozzen:false,
|
|
298
|
+
// attributes: {},
|
|
299
|
+
// filters: {},
|
|
300
|
+
// temp:{}
|
|
305
301
|
});
|
|
306
|
-
this.events = {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
this.observer={
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
302
|
+
// this.events = {
|
|
303
|
+
// ptr:null,
|
|
304
|
+
// mouse:null,
|
|
305
|
+
// wheel:null,
|
|
306
|
+
// key:null,
|
|
307
|
+
// drag:null,
|
|
308
|
+
// drop:null,
|
|
309
|
+
// click:null,
|
|
310
|
+
// clipboard:null,
|
|
311
|
+
// focus:null,
|
|
312
|
+
// swipe:null,
|
|
313
|
+
// custom:null,
|
|
314
|
+
// }
|
|
315
|
+
// this.observer={
|
|
316
|
+
// resize:null,
|
|
317
|
+
// intersection:null
|
|
318
|
+
// }
|
|
323
319
|
if(element) Object.assign(this.cache,{element});
|
|
324
320
|
this.items = new UIStore();
|
|
325
321
|
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
326
322
|
? globalThis.__Ziko__.__UI__[this.cache.name]?.push(this)
|
|
327
323
|
: globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
328
|
-
element &&
|
|
324
|
+
element && mount && this?.mount?.();
|
|
329
325
|
globalThis.__Ziko__.__UI__.push(this);
|
|
330
326
|
|
|
331
327
|
const parsed_props = parse_props(props);
|
|
@@ -382,12 +378,9 @@ function mount(target = this.target, delay = 0) {
|
|
|
382
378
|
setTimeout(() => this.mount(target, 0), delay);
|
|
383
379
|
return this;
|
|
384
380
|
}
|
|
385
|
-
|
|
386
381
|
if (this.isBody) return this;
|
|
387
|
-
|
|
388
382
|
if (target?.isUIElement) target = target.element;
|
|
389
383
|
this.target = target;
|
|
390
|
-
|
|
391
384
|
this.target?.appendChild(this.element);
|
|
392
385
|
return this;
|
|
393
386
|
}
|
|
@@ -397,7 +390,6 @@ function unmount(delay = 0) {
|
|
|
397
390
|
setTimeout(() => this.unmount(0), delay);
|
|
398
391
|
return this;
|
|
399
392
|
}
|
|
400
|
-
|
|
401
393
|
if (this.cache.parent) {
|
|
402
394
|
this.cache.parent.remove(this);
|
|
403
395
|
} else if (
|
|
@@ -538,11 +530,11 @@ class UIText extends UINode {
|
|
|
538
530
|
const text = (...str) => new UIText(...str);
|
|
539
531
|
|
|
540
532
|
function append(...ele) {
|
|
541
|
-
|
|
533
|
+
__addItems__.call(this, "append", "push", ...ele);
|
|
542
534
|
return this;
|
|
543
535
|
}
|
|
544
536
|
function prepend(...ele) {
|
|
545
|
-
this.
|
|
537
|
+
this.__addItems__.call(this, "prepend", "unshift", ...ele);
|
|
546
538
|
return this;
|
|
547
539
|
}
|
|
548
540
|
function insertAt(index, ...ele) {
|
|
@@ -584,58 +576,46 @@ function replaceElementWith(new_element){
|
|
|
584
576
|
return this
|
|
585
577
|
}
|
|
586
578
|
function after(ui){
|
|
587
|
-
if(ui?.isUIElement) ui=ui.element;
|
|
579
|
+
if(ui?.isUIElement) ui = ui.element;
|
|
588
580
|
this.itemsTarget.element?.after(ui);
|
|
589
581
|
return this;
|
|
590
582
|
}
|
|
591
583
|
function before(ui){
|
|
592
|
-
if(ui?.isUIElement) ui=ui.element;
|
|
584
|
+
if(ui?.isUIElement) ui = ui.element;
|
|
593
585
|
this.itemsTarget.element?.before(ui);
|
|
594
586
|
return this;
|
|
595
587
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
if (
|
|
600
|
-
|
|
601
|
-
|
|
588
|
+
|
|
589
|
+
async function __addItem__(adder, pusher, item, referenceNode = null, index = null) {
|
|
590
|
+
const { element: itemsTargetEl, items } = this.itemsTarget;
|
|
591
|
+
if (["number", "string"].includes(typeof item)) item = text(item);
|
|
592
|
+
if (typeof item === "function" && isStateGetter(item)) {
|
|
593
|
+
const getter = item();
|
|
594
|
+
item = text(getter.value);
|
|
595
|
+
getter._subscribe(
|
|
596
|
+
(newValue) => { item.element.textContent = newValue; },
|
|
597
|
+
item
|
|
598
|
+
);
|
|
602
599
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
itemsTarget.items[pusher](ele[i]);
|
|
623
|
-
}
|
|
624
|
-
else if(ele[i] instanceof Promise){
|
|
625
|
-
const UIEle = await ele[i];
|
|
626
|
-
UIEle.cache.parent = this;
|
|
627
|
-
itemsTarget_el?.[adder](UIEle.element);
|
|
628
|
-
UIEle.target = this.itemsTarget.element;
|
|
629
|
-
itemsTarget.items[pusher](UIEle);
|
|
630
|
-
}
|
|
631
|
-
else if (ele[i] instanceof Object) {
|
|
632
|
-
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
633
|
-
if (ele[i]?.attr) {
|
|
634
|
-
Object.entries(ele[i].attr).forEach((n) =>
|
|
635
|
-
this.setAttr("" + n[0], n[1]),
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
600
|
+
if (typeof globalThis?.Node === "function" && item instanceof globalThis.Node)
|
|
601
|
+
item = new this.constructor(item);
|
|
602
|
+
if (item instanceof Promise) item = await item;
|
|
603
|
+
if (item?.isUINode) {
|
|
604
|
+
item.cache.parent = this;
|
|
605
|
+
item.target = itemsTargetEl;
|
|
606
|
+
if (adder === "insertBefore" && itemsTargetEl)
|
|
607
|
+
itemsTargetEl.insertBefore(item.element, referenceNode);
|
|
608
|
+
else if (typeof itemsTargetEl?.[adder] === "function")
|
|
609
|
+
itemsTargetEl[adder](item.element);
|
|
610
|
+
if (pusher === "splice" && index !== null) items.splice(index, 0, item);
|
|
611
|
+
else if (typeof items?.[pusher] === "function") items[pusher](item);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
async function __addItems__(adder, pusher, ...elements) {
|
|
617
|
+
for (const item of elements) {
|
|
618
|
+
await this.__addItem__(adder, pusher, item);
|
|
639
619
|
}
|
|
640
620
|
this.maintain();
|
|
641
621
|
return this;
|
|
@@ -644,6 +624,7 @@ async function __addItem__(adder, pusher, ...ele) {
|
|
|
644
624
|
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
645
625
|
__proto__: null,
|
|
646
626
|
__addItem__: __addItem__,
|
|
627
|
+
__addItems__: __addItems__,
|
|
647
628
|
after: after,
|
|
648
629
|
append: append,
|
|
649
630
|
before: before,
|
|
@@ -1356,9 +1337,9 @@ class UIElement extends UIElement$1{
|
|
|
1356
1337
|
if(directive)this.element.setAttribute('data-hydration-directive', directive);
|
|
1357
1338
|
return this;
|
|
1358
1339
|
}
|
|
1359
|
-
get st(){
|
|
1360
|
-
|
|
1361
|
-
}
|
|
1340
|
+
// get st(){
|
|
1341
|
+
// return this.cache.style;
|
|
1342
|
+
// }
|
|
1362
1343
|
get attr(){
|
|
1363
1344
|
return this.cache.attributes;
|
|
1364
1345
|
}
|
|
@@ -1753,7 +1734,7 @@ const is_anagram = (word, words) =>{
|
|
|
1753
1734
|
const is_isogram = (text = '') => [...new Set(text.toLowerCase())].length === text.length;
|
|
1754
1735
|
|
|
1755
1736
|
if(globalThis?.document){
|
|
1756
|
-
document?.addEventListener(
|
|
1737
|
+
document?.addEventListener('DOMContentLoaded', __Ziko__.__Config__.init());
|
|
1757
1738
|
}
|
|
1758
1739
|
|
|
1759
1740
|
// import './math/functions/proxy.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.10",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { UIElement } from "../dom/UIElement";
|
|
2
|
+
export interface UILayoutOptions {
|
|
3
|
+
title?: string;
|
|
4
|
+
icon?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
lang?: string;
|
|
7
|
+
links?: Record<string, any>[];
|
|
8
|
+
script?: Record<string, any>[];
|
|
9
|
+
meta?: Record<string, any>[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class UILayout {
|
|
13
|
+
options: UILayoutOptions;
|
|
14
|
+
ui: UIElement[];
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
options?: UILayoutOptions,
|
|
18
|
+
...ui: UIElement[]
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
render(): void | {
|
|
22
|
+
title?: string;
|
|
23
|
+
icon?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
lang?: string;
|
|
26
|
+
links: Record<string, any>[];
|
|
27
|
+
meta: Record<string, any>[];
|
|
28
|
+
script: Record<string, any>[];
|
|
29
|
+
body: UIElement[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
mount(target: Element): this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function Layout(
|
|
36
|
+
options?: UILayoutOptions,
|
|
37
|
+
...ui: UIElement[]
|
|
38
|
+
): UILayout;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { tags } from '../dom/tags/index.js'
|
|
2
|
+
import { call_with_optional_props } from '../dom/internal-utils/call_with_optional_props.js'
|
|
3
|
+
|
|
4
|
+
const { meta, link, script } = tags;
|
|
5
|
+
|
|
6
|
+
export class UILayout {
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
{
|
|
10
|
+
title,
|
|
11
|
+
icon,
|
|
12
|
+
description,
|
|
13
|
+
lang,
|
|
14
|
+
links = [],
|
|
15
|
+
script: scripts = [],
|
|
16
|
+
meta: metas = [],
|
|
17
|
+
} = {},
|
|
18
|
+
...ui
|
|
19
|
+
) {
|
|
20
|
+
this.options = {
|
|
21
|
+
title,
|
|
22
|
+
icon,
|
|
23
|
+
description,
|
|
24
|
+
lang,
|
|
25
|
+
links,
|
|
26
|
+
meta: metas,
|
|
27
|
+
script: scripts,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.ui = ui;
|
|
31
|
+
this.render()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
if (typeof document === "undefined") {
|
|
36
|
+
return {
|
|
37
|
+
...this.options,
|
|
38
|
+
body: this.ui,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
title,
|
|
44
|
+
icon,
|
|
45
|
+
description,
|
|
46
|
+
lang,
|
|
47
|
+
links,
|
|
48
|
+
meta: metas,
|
|
49
|
+
script: scripts,
|
|
50
|
+
} = this.options;
|
|
51
|
+
|
|
52
|
+
if (title) {
|
|
53
|
+
document.title = title;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (lang) {
|
|
57
|
+
document.documentElement.lang = lang;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (icon) {
|
|
61
|
+
document.head.appendChild(
|
|
62
|
+
link({
|
|
63
|
+
rel: "icon",
|
|
64
|
+
href: icon,
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (description) {
|
|
70
|
+
document.head.appendChild(
|
|
71
|
+
meta({
|
|
72
|
+
name: "description",
|
|
73
|
+
content: description,
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const attrs of links) {
|
|
79
|
+
document.head.appendChild(link(attrs));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const attrs of metas) {
|
|
83
|
+
document.head.appendChild(meta(attrs));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const attrs of scripts) {
|
|
87
|
+
document.head.appendChild(script(attrs));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
mount(target){
|
|
92
|
+
this.ui.forEach(el => el.mount(target));
|
|
93
|
+
return this
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const Layout = call_with_optional_props(UILayout)
|
|
@@ -81,15 +81,15 @@ class UIElement extends UIElementCore{
|
|
|
81
81
|
useClient(directive){
|
|
82
82
|
if(!this.cache.isInteractive){
|
|
83
83
|
this.element.setAttribute('data-hydration-index', globalThis.__Ziko__.__HYDRATION__.index);
|
|
84
|
-
globalThis.__Ziko__.__HYDRATION__.register(() => this);
|
|
84
|
+
globalThis.__Ziko__.__HYDRATION__.register(() => this.constructor);
|
|
85
85
|
this.cache.isInteractive = true;
|
|
86
86
|
}
|
|
87
87
|
if(directive)this.element.setAttribute('data-hydration-directive', directive);
|
|
88
88
|
return this;
|
|
89
89
|
}
|
|
90
|
-
get st(){
|
|
91
|
-
|
|
92
|
-
}
|
|
90
|
+
// get st(){
|
|
91
|
+
// return this.cache.style;
|
|
92
|
+
// }
|
|
93
93
|
get attr(){
|
|
94
94
|
return this.cache.attributes;
|
|
95
95
|
}
|
|
@@ -36,4 +36,7 @@ export declare const UIELEMENT: unique symbol;
|
|
|
36
36
|
* Used by hooks and UI components to recognize state getters without
|
|
37
37
|
* importing the state implementation.
|
|
38
38
|
*/
|
|
39
|
-
export declare const STATE_GETTER: unique symbol;
|
|
39
|
+
export declare const STATE_GETTER: unique symbol;
|
|
40
|
+
|
|
41
|
+
export declare const LAYOUT: unique symbol;
|
|
42
|
+
export declare const PAGE: unique symbol;
|
|
@@ -3,3 +3,4 @@ export const COMPLEX = Symbol.for('ziko/math/COMPLEX');
|
|
|
3
3
|
export const MATRIX = Symbol.for('ziko/math/MATRIX');
|
|
4
4
|
export const UIELEMENT = Symbol.for('ziko/dom/UIELEMENT');
|
|
5
5
|
export const STATE_GETTER = Symbol.for("ziko/hooks/STATE_GETTER");
|
|
6
|
+
export const LAYOUT = Symbol.for("ziko/app/LAYOUT");
|
|
@@ -7,16 +7,12 @@ class UIElement extends UINode{
|
|
|
7
7
|
constructor(){
|
|
8
8
|
super()
|
|
9
9
|
}
|
|
10
|
-
init({element, name, type,
|
|
10
|
+
init({element, name, type, mount, props = {}, items = []} = {}){
|
|
11
11
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
12
12
|
if(typeof element === "string") {
|
|
13
13
|
switch(type){
|
|
14
|
-
case "html" :
|
|
15
|
-
|
|
16
|
-
}; break;
|
|
17
|
-
case "svg" : {
|
|
18
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
19
|
-
}; break;
|
|
14
|
+
case "html" : element = globalThis?.document?.createElement(element); break;
|
|
15
|
+
case "svg" : element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element); break;
|
|
20
16
|
default : throw Error("Not supported")
|
|
21
17
|
}
|
|
22
18
|
}
|
|
@@ -26,37 +22,37 @@ class UIElement extends UINode{
|
|
|
26
22
|
itemsTarget : this,
|
|
27
23
|
isInteractive : false,
|
|
28
24
|
parent:null,
|
|
29
|
-
isBody:false,
|
|
30
|
-
isRoot:false,
|
|
31
|
-
isHidden: false,
|
|
32
|
-
isFrozzen:false,
|
|
33
|
-
attributes: {},
|
|
34
|
-
filters: {},
|
|
35
|
-
temp:{}
|
|
25
|
+
// isBody:false,
|
|
26
|
+
// isRoot:false,
|
|
27
|
+
// isHidden: false,
|
|
28
|
+
// isFrozzen:false,
|
|
29
|
+
// attributes: {},
|
|
30
|
+
// filters: {},
|
|
31
|
+
// temp:{}
|
|
36
32
|
})
|
|
37
|
-
this.events = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
this.observer={
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
33
|
+
// this.events = {
|
|
34
|
+
// ptr:null,
|
|
35
|
+
// mouse:null,
|
|
36
|
+
// wheel:null,
|
|
37
|
+
// key:null,
|
|
38
|
+
// drag:null,
|
|
39
|
+
// drop:null,
|
|
40
|
+
// click:null,
|
|
41
|
+
// clipboard:null,
|
|
42
|
+
// focus:null,
|
|
43
|
+
// swipe:null,
|
|
44
|
+
// custom:null,
|
|
45
|
+
// }
|
|
46
|
+
// this.observer={
|
|
47
|
+
// resize:null,
|
|
48
|
+
// intersection:null
|
|
49
|
+
// }
|
|
54
50
|
if(element) Object.assign(this.cache,{element});
|
|
55
51
|
this.items = new UIStore();
|
|
56
52
|
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
57
53
|
? globalThis.__Ziko__.__UI__[this.cache.name]?.push(this)
|
|
58
54
|
: globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
59
|
-
element &&
|
|
55
|
+
element && mount && this?.mount?.()
|
|
60
56
|
globalThis.__Ziko__.__UI__.push(this)
|
|
61
57
|
|
|
62
58
|
const parsed_props = parse_props(props);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { text } from "../text/index.js";
|
|
2
2
|
import { isStateGetter } from "../../hooks/use-state.js";
|
|
3
3
|
export function append(...ele) {
|
|
4
|
-
|
|
4
|
+
__addItems__.call(this, "append", "push", ...ele);
|
|
5
5
|
return this;
|
|
6
6
|
}
|
|
7
7
|
export function prepend(...ele) {
|
|
8
|
-
this.
|
|
8
|
+
this.__addItems__.call(this, "prepend", "unshift", ...ele);
|
|
9
9
|
return this;
|
|
10
10
|
}
|
|
11
11
|
export function insertAt(index, ...ele) {
|
|
@@ -47,58 +47,46 @@ export function replaceElementWith(new_element){
|
|
|
47
47
|
return this
|
|
48
48
|
}
|
|
49
49
|
export function after(ui){
|
|
50
|
-
if(ui?.isUIElement) ui=ui.element;
|
|
50
|
+
if(ui?.isUIElement) ui = ui.element;
|
|
51
51
|
this.itemsTarget.element?.after(ui)
|
|
52
52
|
return this;
|
|
53
53
|
}
|
|
54
54
|
export function before(ui){
|
|
55
|
-
if(ui?.isUIElement) ui=ui.element;
|
|
55
|
+
if(ui?.isUIElement) ui = ui.element;
|
|
56
56
|
this.itemsTarget.element?.before(ui)
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
|
|
60
|
+
export async function __addItem__(adder, pusher, item, referenceNode = null, index = null) {
|
|
61
|
+
const { element: itemsTargetEl, items } = this.itemsTarget;
|
|
62
|
+
if (["number", "string"].includes(typeof item)) item = text(item);
|
|
63
|
+
if (typeof item === "function" && isStateGetter(item)) {
|
|
64
|
+
const getter = item();
|
|
65
|
+
item = text(getter.value);
|
|
66
|
+
getter._subscribe(
|
|
67
|
+
(newValue) => { item.element.textContent = newValue; },
|
|
68
|
+
item
|
|
69
|
+
);
|
|
65
70
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
itemsTarget.items[pusher](ele[i]);
|
|
86
|
-
}
|
|
87
|
-
else if(ele[i] instanceof Promise){
|
|
88
|
-
const UIEle = await ele[i]
|
|
89
|
-
UIEle.cache.parent = this;
|
|
90
|
-
itemsTarget_el?.[adder](UIEle.element);
|
|
91
|
-
UIEle.target = this.itemsTarget.element;
|
|
92
|
-
itemsTarget.items[pusher](UIEle)
|
|
93
|
-
}
|
|
94
|
-
else if (ele[i] instanceof Object) {
|
|
95
|
-
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
96
|
-
if (ele[i]?.attr) {
|
|
97
|
-
Object.entries(ele[i].attr).forEach((n) =>
|
|
98
|
-
this.setAttr("" + n[0], n[1]),
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
71
|
+
if (typeof globalThis?.Node === "function" && item instanceof globalThis.Node)
|
|
72
|
+
item = new this.constructor(item);
|
|
73
|
+
if (item instanceof Promise) item = await item;
|
|
74
|
+
if (item?.isUINode) {
|
|
75
|
+
item.cache.parent = this;
|
|
76
|
+
item.target = itemsTargetEl;
|
|
77
|
+
if (adder === "insertBefore" && itemsTargetEl)
|
|
78
|
+
itemsTargetEl.insertBefore(item.element, referenceNode);
|
|
79
|
+
else if (typeof itemsTargetEl?.[adder] === "function")
|
|
80
|
+
itemsTargetEl[adder](item.element);
|
|
81
|
+
if (pusher === "splice" && index !== null) items.splice(index, 0, item);
|
|
82
|
+
else if (typeof items?.[pusher] === "function") items[pusher](item);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function __addItems__(adder, pusher, ...elements) {
|
|
88
|
+
for (const item of elements) {
|
|
89
|
+
await this.__addItem__(adder, pusher, item);
|
|
102
90
|
}
|
|
103
91
|
this.maintain();
|
|
104
92
|
return this;
|
|
@@ -3,12 +3,9 @@ export function mount(target = this.target, delay = 0) {
|
|
|
3
3
|
setTimeout(() => this.mount(target, 0), delay);
|
|
4
4
|
return this;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
6
|
if (this.isBody) return this;
|
|
8
|
-
|
|
9
7
|
if (target?.isUIElement) target = target.element;
|
|
10
8
|
this.target = target;
|
|
11
|
-
|
|
12
9
|
this.target?.appendChild(this.element);
|
|
13
10
|
return this;
|
|
14
11
|
}
|
|
@@ -18,7 +15,6 @@ export function unmount(delay = 0) {
|
|
|
18
15
|
setTimeout(() => this.unmount(0), delay);
|
|
19
16
|
return this;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
if (this.cache.parent) {
|
|
23
19
|
this.cache.parent.remove(this);
|
|
24
20
|
} else if (
|