ziko 0.45.0 → 0.45.2

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.
Files changed (54) hide show
  1. package/dist/ziko.js +647 -696
  2. package/dist/ziko.mjs +636 -678
  3. package/package.json +1 -1
  4. package/src/__helpers__/register/index.js +3 -1
  5. package/src/__helpers__/register/register-to-instance.js +17 -5
  6. package/src/app/spa-file-based-routing.js +3 -2
  7. package/src/app/spa.js +3 -3
  8. package/src/app/ziko-app.js +1 -1
  9. package/src/events/__Events__.js +2 -1
  10. package/src/events/binders/click.js +20 -0
  11. package/src/events/binders/clipboard.js +16 -0
  12. package/src/events/{custom-event.js → binders/custom-event.js} +1 -1
  13. package/src/events/binders/drag.js +16 -0
  14. package/src/events/binders/focus.js +16 -0
  15. package/src/events/{hash.js → binders/hash.js} +2 -2
  16. package/src/events/binders/index.js +16 -0
  17. package/src/events/{key.js → binders/key.js} +4 -4
  18. package/src/events/binders/mouse.js +16 -0
  19. package/src/events/{pointer.js → binders/pointer.js} +4 -4
  20. package/src/events/{touch.js → binders/touch.js} +2 -2
  21. package/src/events/binders/wheel.js +16 -0
  22. package/src/events/custom-events/click-away.js +1 -0
  23. package/src/events/index.js +2 -16
  24. package/src/events/types/clipboard.d.ts +2 -2
  25. package/src/events/types/focus.d.ts +2 -2
  26. package/src/events/types/pointer.d.ts +2 -2
  27. package/src/hooks/use-state.js +2 -2
  28. package/src/lite.js +2 -0
  29. package/src/ui/__methods__/attrs.js +29 -45
  30. package/src/ui/__methods__/dom.js +65 -111
  31. package/src/ui/__methods__/events.js +17 -17
  32. package/src/ui/__methods__/index.js +10 -1
  33. package/src/ui/__methods__/indexing.js +14 -15
  34. package/src/ui/__methods__/style.js +28 -30
  35. package/src/ui/__methods__/utils/index.js +64 -0
  36. package/src/ui/constructors/UIElement-lite.js +10 -0
  37. package/src/ui/constructors/UIElement.js +89 -155
  38. package/src/ui/constructors/UIElementCore.js +235 -0
  39. package/src/ui/index.js +3 -3
  40. package/src/ui/suspense/index.js +1 -1
  41. package/src/ui/tags/index.js +9 -3
  42. package/src/ui/tags/tags-list.js +0 -1
  43. package/src/ui/wrappers/html/index.js +26 -0
  44. package/src/ui/wrappers/index.js +2 -0
  45. package/src/ui/wrappers/svg/index.js +46 -0
  46. package/src/events/click.js +0 -18
  47. package/src/events/clipboard.js +0 -16
  48. package/src/events/drag.js +0 -16
  49. package/src/events/focus.js +0 -16
  50. package/src/events/mouse.js +0 -16
  51. package/src/events/wheel.js +0 -16
  52. package/src/ui/__methods__/observer.js +0 -0
  53. package/src/ui/wrapper/index.js +0 -42
  54. /package/src/ui/constructors/{ZikoUIElementMethodesToBeMoved-dep.js → _m.js.txt} +0 -0
@@ -1,24 +1,24 @@
1
1
  import { Events } from "../../events/__Events__";
2
2
  import {
3
- bindPointerEvent,
4
- bindMouseEvent,
5
- bindKeyEvent,
6
- bindClickEvent,
7
- bindDragEvent,
8
- bindClipboardEvent,
9
- bindFocusEvent,
10
- bindWheelEvent
11
- } from "../../events/index.js";
3
+ bind_pointer_event,
4
+ bind_mouse_event,
5
+ bind_key_event,
6
+ bind_click_event,
7
+ bind_drag_event,
8
+ bind_clipboard_event,
9
+ bind_focus_event,
10
+ bind_wheel_event
11
+ } from "../../events/binders/index.js";
12
12
 
13
13
  const binderMap = {
14
- ptr: bindPointerEvent,
15
- mouse : bindMouseEvent,
16
- key: bindKeyEvent,
17
- click : bindClickEvent,
18
- drag : bindDragEvent,
19
- clipboard : bindClipboardEvent,
20
- focus : bindFocusEvent,
21
- wheel : bindWheelEvent
14
+ ptr: bind_pointer_event,
15
+ mouse : bind_mouse_event,
16
+ key: bind_key_event,
17
+ click : bind_click_event,
18
+ drag : bind_drag_event,
19
+ clipboard : bind_clipboard_event,
20
+ focus : bind_focus_event,
21
+ wheel : bind_wheel_event
22
22
  };
23
23
 
24
24
  const EventsMethodes = {};
@@ -1,5 +1,14 @@
1
1
  export * from './attrs.js'
2
+ export * as AttrsMethods from './attrs.js'
3
+
2
4
  export * from './dom.js'
5
+ export * as DomMethods from './dom.js'
6
+
3
7
  export * from './events.js'
8
+
4
9
  export * from './indexing.js'
5
- export * from './style.js'
10
+ export * as IndexingMethods from './indexing.js'
11
+
12
+
13
+ export * from './style.js'
14
+ export * as StyleMethods from './style.js'
@@ -1,15 +1,14 @@
1
- export const IndexingMethods = {
2
- at(index) {
3
- return this.items.at(index);
4
- },
5
- forEach(callback) {
6
- this.items.forEach(callback);
7
- return this;
8
- },
9
- map(callback) {
10
- return this.items.map(callback);
11
- },
12
- find(condition) {
13
- return this.items.filter(condition);
14
- },
15
- };
1
+ export function at(index) {
2
+ return this.items.at(index);
3
+ }
4
+ export function forEach(callback) {
5
+ this.items.forEach(callback);
6
+ return this;
7
+ }
8
+ export function map(callback) {
9
+ return this.items.map(callback);
10
+ }
11
+ export function find(condition) {
12
+ return this.items.filter(condition);
13
+ }
14
+
@@ -1,34 +1,32 @@
1
1
  import { isStateGetter } from '../../hooks/use-state.js'
2
- export const StyleMethods = {
3
- style(styles){
4
- for(let key in styles){
5
- const value = styles[key];
6
- if(isStateGetter(value)){
7
- const getter = value()
8
- Object.assign(this.element.style, {[key] : getter.value})
9
- getter._subscribe(
10
- (newValue) => {
11
- console.log({newValue})
12
- Object.assign(this.element.style, {[key] : newValue})
13
- },
14
- // this
15
- );
16
- }
17
- else Object.assign(this.element.style, {[key] : value})
2
+ export function style(styles){
3
+ for(let key in styles){
4
+ const value = styles[key];
5
+ if(isStateGetter(value)){
6
+ const getter = value()
7
+ Object.assign(this.element.style, {[key] : getter.value})
8
+ getter._subscribe(
9
+ (newValue) => {
10
+ console.log({newValue})
11
+ Object.assign(this.element.style, {[key] : newValue})
12
+ },
13
+ // this
14
+ );
18
15
  }
19
- return this;
20
- },
21
- size(width, height){
22
- return this.style({width, height})
23
- },
24
- hide(){
16
+ else Object.assign(this.element.style, {[key] : value})
17
+ }
18
+ return this;
19
+ }
20
+ export function size(width, height){
21
+ return this.style({width, height})
22
+ }
23
+ export function hide(){
25
24
 
26
- },
27
- show(){
25
+ }
26
+ export function show(){
28
27
 
29
- },
30
- animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
31
- this.element?.animate(keyframe,{duration, iterations, easing});
32
- return this;
33
- }
34
- }
28
+ }
29
+ export function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
30
+ this.element?.animate(keyframe,{duration, iterations, easing});
31
+ return this;
32
+ }
@@ -0,0 +1,64 @@
1
+ import { isStateGetter } from "../../../hooks/use-state.js";
2
+ import {
3
+ is_camelcase,
4
+ camel2hyphencase
5
+ } from '../../../data/string/index.js'
6
+ import { text } from "../../text/index.js";
7
+ export async function __addItem__(adder, pusher, ...ele) {
8
+ if (this.cache.isFrozzen) {
9
+ console.warn("You can't append new item to frozzen element");
10
+ return this;
11
+ }
12
+ for (let i = 0; i < ele.length; i++) {
13
+ if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
14
+ // Fix Items Latter
15
+ if (ele[i] instanceof Function) {
16
+ const getter = ele[i]();
17
+ if (getter.isStateGetter) {
18
+ ele[i] = text(getter.value);
19
+ getter._subscribe(
20
+ (newValue) => (ele[i].element.textContent = newValue),
21
+ ele[i]
22
+ );
23
+ // this.element.appendChild(textNode);
24
+ }
25
+ }
26
+ if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
27
+ if (ele[i]?.isZikoUINode) {
28
+ ele[i].cache.parent = this;
29
+ this.element?.[adder](ele[i].element);
30
+ ele[i].target = this.element;
31
+ this.items[pusher](ele[i]);
32
+ }
33
+ else if(ele[i] instanceof Promise){
34
+ const UIEle = await ele[i]
35
+ UIEle.cache.parent = this;
36
+ this.element?.[adder](UIEle.element);
37
+ UIEle.target = this.element;
38
+ this.items[pusher](UIEle)
39
+ }
40
+ else if (ele[i] instanceof Object) {
41
+ if (ele[i]?.style) this.style(ele[i]?.style);
42
+ if (ele[i]?.attr) {
43
+ Object.entries(ele[i].attr).forEach((n) =>
44
+ this.setAttr("" + n[0], n[1]),
45
+ );
46
+ }
47
+ }
48
+ }
49
+ this.maintain();
50
+ return this;
51
+ }
52
+ export function _set_attrs_(name, value){
53
+ if(this.element instanceof globalThis?.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
54
+ if(this?.attr[name] && this?.attr[name]===value) return;
55
+ if(isStateGetter(value)){
56
+ const getter = value()
57
+ getter._subscribe(
58
+ (newValue) => this.element?.setAttribute(name, newValue),
59
+ this
60
+ );
61
+ }
62
+ else this.element?.setAttribute(name, value)
63
+ Object.assign(this.cache.attributes, {[name]:value});
64
+ }
@@ -0,0 +1,10 @@
1
+ import { UIElementCore } from "./UIElementCore";
2
+ class UIElement extends UIElementCore{
3
+ constructor({element, name, type, render}){
4
+ super({element, name, type, render})
5
+ }
6
+ }
7
+
8
+ export {
9
+ UIElement
10
+ }
@@ -1,5 +1,5 @@
1
- import {UINode} from "./UINode.js";
2
- import { register } from "../../__helpers__/register/index.js";
1
+ import { UIElementCore } from "./UIElementCore.js";
2
+ import { register_to_class } from "../../__helpers__/register/register-to-class.js";
3
3
  import {
4
4
  AttrsMethods,
5
5
  DomMethods,
@@ -15,24 +15,12 @@ import {
15
15
  watchAttr,
16
16
  watchChildren
17
17
  } from "../../reactivity/index.js"
18
- // import { Random } from "../../math/index.js";
19
- import {__init__global__, UIStore} from '../../__ziko__/index.js';
20
- __init__global__()
21
- class UIElement extends UINode{
22
- constructor({element, name ='', type="html", render = __Ziko__.__Config__.default.render, useDefaultStyle=false}={}){
18
+ class UIElement extends UIElementCore{
19
+ constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
23
20
  super()
24
- this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
25
- if(typeof element === "string") {
26
- switch(type){
27
- case "html" : element = globalThis?.document?.createElement(element); break;
28
- case "svg" : element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
29
- default : throw Error("Not supported")
30
- }
31
- }
32
- else{
33
- this.target = element?.parentElement;
34
- }
35
- register(
21
+ console.log({type})
22
+ // console.log(this)
23
+ register_to_class(
36
24
  this,
37
25
  AttrsMethods,
38
26
  DomMethods,
@@ -40,61 +28,7 @@ class UIElement extends UINode{
40
28
  IndexingMethods,
41
29
  EventsMethodes
42
30
  );
43
- Object.assign(this.cache, {
44
- name,
45
- isInteractive : [true, false][Math.floor(2*Math.random())],
46
- parent:null,
47
- isBody:false,
48
- isRoot:false,
49
- isHidden: false,
50
- isFrozzen:false,
51
- legacyParent : null,
52
- attributes: {},
53
- filters: {},
54
- temp:{}
55
- })
56
- this.events = {
57
- ptr:null,
58
- mouse:null,
59
- wheel:null,
60
- key:null,
61
- drag:null,
62
- drop:null,
63
- click:null,
64
- clipboard:null,
65
- focus:null,
66
- swipe:null,
67
- custom:null,
68
- }
69
- this.observer={
70
- resize:null,
71
- intersection:null
72
- }
73
- if(element) Object.assign(this.cache,{element});
74
- // this.uuid = `${this.cache.name}-${Random.string(16)}`
75
- this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
76
- useDefaultStyle && this.style({
77
- position: "relative",
78
- boxSizing:"border-box",
79
- margin:0,
80
- padding:0,
81
- width : "auto",
82
- height : "auto"
83
- });
84
- this.items = new UIStore();
85
- globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
86
- element && render && this?.render?.()
87
- if(
88
- // globalThis.__Ziko__.__Config__.renderingMode !== "spa"
89
- // &&
90
- // !globalThis.__Ziko__.__Config__.isSSC
91
- // &&
92
- this.isInteractive()
93
- ){
94
- this.setAttr("ziko-hydration-index", globalThis.__Ziko__.__HYDRATION__.index);
95
- globalThis.__Ziko__.__HYDRATION__.register(() => this)
96
- }
97
- globalThis.__Ziko__.__UI__.push(this)
31
+ this.init(element, name, type, render)
98
32
  }
99
33
  get element(){
100
34
  return this.cache.element;
@@ -102,9 +36,9 @@ class UIElement extends UINode{
102
36
  isInteractive(){
103
37
  return this.cache.isInteractive;
104
38
  }
105
- isZikoUIElement(){
106
- return true;
107
- }
39
+ // isUIElement(){
40
+ // return true;
41
+ // }
108
42
  get st(){
109
43
  return this.cache.style;
110
44
  }
@@ -144,73 +78,73 @@ class UIElement extends UINode{
144
78
  get left(){
145
79
  return this.element.getBoundingClientRect().left;
146
80
  }
147
- clone(render=false) {
148
- // UI.__proto__=this.__proto__;
149
- // if(this.items.length){
150
- // const items = [...this.items].map(n=>n.clone());
151
- // UI.append(...items);
152
- // }
153
- // else UI.element=this.element.cloneNode(true);
154
- // return UI.render(render);
155
- }
156
- [Symbol.iterator]() {
157
- return this.items[Symbol.iterator]();
158
- }
159
- maintain() {
160
- for (let i = 0; i < this.items.length; i++) {
161
- Object.defineProperty(this, i, {
162
- value: this.items[i],
163
- writable: true,
164
- configurable: true,
165
- enumerable: false
166
- });
167
- }
168
- }
169
- freeze(freeze){
170
- this.cache.isFrozzen=freeze;
171
- return this;
172
- }
81
+ // clone(render=false) {
82
+ // // UI.__proto__=this.__proto__;
83
+ // // if(this.items.length){
84
+ // // const items = [...this.items].map(n=>n.clone());
85
+ // // UI.append(...items);
86
+ // // }
87
+ // // else UI.element=this.element.cloneNode(true);
88
+ // // return UI.render(render);
89
+ // }
90
+ // [Symbol.iterator]() {
91
+ // return this.items[Symbol.iterator]();
92
+ // }
93
+ // maintain() {
94
+ // for (let i = 0; i < this.items.length; i++) {
95
+ // Object.defineProperty(this, i, {
96
+ // value: this.items[i],
97
+ // writable: true,
98
+ // configurable: true,
99
+ // enumerable: false
100
+ // });
101
+ // }
102
+ // }
103
+ // freeze(freeze){
104
+ // this.cache.isFrozzen=freeze;
105
+ // return this;
106
+ // }
173
107
  // setTarget(tg) {
174
108
  // if(this.isBody) return ;
175
- // if (tg?.isZikoUIElement) tg = tg.element;
109
+ // if (tg?.isUIElement) tg = tg.element;
176
110
  // this.unrender();
177
111
  // this.target = tg;
178
112
  // this.render();
179
113
  // return this;
180
114
  // }
181
- describe(label){
182
- if(label)this.setAttr("aria-label",label)
183
- }
184
- get children() {
185
- return [...this.element.children];
186
- }
187
- get cloneElement() {
188
- return this.element.cloneNode(true);
189
- }
190
- setClasses(...value) {
191
- this.setAttr("class", value.join(" "));
192
- return this;
193
- }
194
- get classes(){
195
- const classes=this.element.getAttribute("class");
196
- return classes===null?[]:classes.split(" ");
197
- }
198
- addClass() {
199
- /*this.setAttr("class", value);
200
- return this;*/
201
- }
202
- setId(id) {
203
- this.setAttr("id", id);
204
- return this;
205
- }
206
- get id() {
207
- return this.element.getAttribute("id");
208
- }
209
- onSwipe(width_threshold, height_threshold,...callbacks){
210
- if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
211
- this.events.swipe.onSwipe(...callbacks);
212
- return this;
213
- }
115
+ // describe(label){
116
+ // if(label)this.setAttr("aria-label",label)
117
+ // }
118
+ // get children() {
119
+ // return [...this.element.children];
120
+ // }
121
+ // get cloneElement() {
122
+ // return this.element.cloneNode(true);
123
+ // }
124
+ // setClasses(...value) {
125
+ // this.setAttr("class", value.join(" "));
126
+ // return this;
127
+ // }
128
+ // get classes(){
129
+ // const classes=this.element.getAttribute("class");
130
+ // return classes===null?[]:classes.split(" ");
131
+ // }
132
+ // addClass() {
133
+ // /*this.setAttr("class", value);
134
+ // return this;*/
135
+ // }
136
+ // setId(id) {
137
+ // this.setAttr("id", id);
138
+ // return this;
139
+ // }
140
+ // get id() {
141
+ // return this.element.getAttribute("id");
142
+ // }
143
+ // onSwipe(width_threshold, height_threshold,...callbacks){
144
+ // if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
145
+ // this.events.swipe.onSwipe(...callbacks);
146
+ // return this;
147
+ // }
214
148
  // To Fix
215
149
  // onKeysDown({keys=[],callback}={}){
216
150
  // if(!this.events.key)this.events.key = useKeyEvent(this);
@@ -232,24 +166,24 @@ class UIElement extends UINode{
232
166
  this.events.custom.emit(event_name,detail);
233
167
  return this;
234
168
  }
235
- watchAttr(callback){
236
- if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
237
- return this;
238
- }
239
- watchChildren(callback){
240
- if(!this.observer.children)this.observer.children = watchChildren(this,callback);
241
- return this;
242
- }
243
- watchSize(callback){
244
- if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
245
- this.observer.resize.start();
246
- return this;
247
- }
248
- watchIntersection(callback,config){
249
- if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
250
- this.observer.intersection.start();
251
- return this;
252
- }
169
+ // watchAttr(callback){
170
+ // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
171
+ // return this;
172
+ // }
173
+ // watchChildren(callback){
174
+ // if(!this.observer.children)this.observer.children = watchChildren(this,callback);
175
+ // return this;
176
+ // }
177
+ // watchSize(callback){
178
+ // if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
179
+ // this.observer.resize.start();
180
+ // return this;
181
+ // }
182
+ // watchIntersection(callback,config){
183
+ // if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
184
+ // this.observer.intersection.start();
185
+ // return this;
186
+ // }
253
187
 
254
188
  }
255
189
  export { UIElement }