ziko 0.45.0 → 0.45.1

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 (46) hide show
  1. package/dist/ziko.js +626 -712
  2. package/dist/ziko.mjs +617 -692
  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.js +3 -3
  7. package/src/app/ziko-app.js +1 -1
  8. package/src/events/__Events__.js +2 -1
  9. package/src/events/binders/click.js +20 -0
  10. package/src/events/binders/clipboard.js +16 -0
  11. package/src/events/{custom-event.js → binders/custom-event.js} +1 -1
  12. package/src/events/binders/drag.js +16 -0
  13. package/src/events/binders/focus.js +16 -0
  14. package/src/events/{hash.js → binders/hash.js} +2 -2
  15. package/src/events/binders/index.js +16 -0
  16. package/src/events/{key.js → binders/key.js} +4 -4
  17. package/src/events/binders/mouse.js +16 -0
  18. package/src/events/{pointer.js → binders/pointer.js} +4 -4
  19. package/src/events/{touch.js → binders/touch.js} +2 -2
  20. package/src/events/binders/wheel.js +16 -0
  21. package/src/events/custom-events/click-away.js +1 -0
  22. package/src/events/index.js +2 -16
  23. package/src/events/types/clipboard.d.ts +2 -2
  24. package/src/events/types/focus.d.ts +2 -2
  25. package/src/events/types/pointer.d.ts +2 -2
  26. package/src/lite.js +2 -0
  27. package/src/ui/__methods__/attrs.js +29 -45
  28. package/src/ui/__methods__/dom.js +65 -111
  29. package/src/ui/__methods__/events.js +17 -17
  30. package/src/ui/__methods__/index.js +10 -1
  31. package/src/ui/__methods__/indexing.js +14 -15
  32. package/src/ui/__methods__/style.js +28 -30
  33. package/src/ui/__methods__/utils/index.js +64 -0
  34. package/src/ui/constructors/UIElement-lite.js +10 -0
  35. package/src/ui/constructors/UIElement.js +87 -154
  36. package/src/ui/constructors/UIElementCore.js +236 -0
  37. package/src/ui/index.js +3 -3
  38. package/src/ui/suspense/index.js +1 -1
  39. package/src/events/click.js +0 -18
  40. package/src/events/clipboard.js +0 -16
  41. package/src/events/drag.js +0 -16
  42. package/src/events/focus.js +0 -16
  43. package/src/events/mouse.js +0 -16
  44. package/src/events/wheel.js +0 -16
  45. package/src/ui/__methods__/observer.js +0 -0
  46. /package/src/ui/constructors/{ZikoUIElementMethodesToBeMoved-dep.js → _m.js.txt} +0 -0
@@ -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?.tagName !== "svg") 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,4 +1,4 @@
1
- import {UINode} from "./UINode.js";
1
+ import { UIElementCore } from "./UIElementCore.js";
2
2
  import { register } from "../../__helpers__/register/index.js";
3
3
  import {
4
4
  AttrsMethods,
@@ -15,23 +15,10 @@ 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}={}){
23
- 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
- }
18
+ class UIElement extends UIElementCore{
19
+ constructor({element, name ='', type="html", render = __Ziko__.__Config__.default.render}={}){
20
+ super({element, name, type, render})
21
+ console.log(this)
35
22
  register(
36
23
  this,
37
24
  AttrsMethods,
@@ -40,61 +27,7 @@ class UIElement extends UINode{
40
27
  IndexingMethods,
41
28
  EventsMethodes
42
29
  );
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)
30
+ this.init(element, name, type, render)
98
31
  }
99
32
  get element(){
100
33
  return this.cache.element;
@@ -102,9 +35,9 @@ class UIElement extends UINode{
102
35
  isInteractive(){
103
36
  return this.cache.isInteractive;
104
37
  }
105
- isZikoUIElement(){
106
- return true;
107
- }
38
+ // isUIElement(){
39
+ // return true;
40
+ // }
108
41
  get st(){
109
42
  return this.cache.style;
110
43
  }
@@ -144,73 +77,73 @@ class UIElement extends UINode{
144
77
  get left(){
145
78
  return this.element.getBoundingClientRect().left;
146
79
  }
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
- }
80
+ // clone(render=false) {
81
+ // // UI.__proto__=this.__proto__;
82
+ // // if(this.items.length){
83
+ // // const items = [...this.items].map(n=>n.clone());
84
+ // // UI.append(...items);
85
+ // // }
86
+ // // else UI.element=this.element.cloneNode(true);
87
+ // // return UI.render(render);
88
+ // }
89
+ // [Symbol.iterator]() {
90
+ // return this.items[Symbol.iterator]();
91
+ // }
92
+ // maintain() {
93
+ // for (let i = 0; i < this.items.length; i++) {
94
+ // Object.defineProperty(this, i, {
95
+ // value: this.items[i],
96
+ // writable: true,
97
+ // configurable: true,
98
+ // enumerable: false
99
+ // });
100
+ // }
101
+ // }
102
+ // freeze(freeze){
103
+ // this.cache.isFrozzen=freeze;
104
+ // return this;
105
+ // }
173
106
  // setTarget(tg) {
174
107
  // if(this.isBody) return ;
175
- // if (tg?.isZikoUIElement) tg = tg.element;
108
+ // if (tg?.isUIElement) tg = tg.element;
176
109
  // this.unrender();
177
110
  // this.target = tg;
178
111
  // this.render();
179
112
  // return this;
180
113
  // }
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
- }
114
+ // describe(label){
115
+ // if(label)this.setAttr("aria-label",label)
116
+ // }
117
+ // get children() {
118
+ // return [...this.element.children];
119
+ // }
120
+ // get cloneElement() {
121
+ // return this.element.cloneNode(true);
122
+ // }
123
+ // setClasses(...value) {
124
+ // this.setAttr("class", value.join(" "));
125
+ // return this;
126
+ // }
127
+ // get classes(){
128
+ // const classes=this.element.getAttribute("class");
129
+ // return classes===null?[]:classes.split(" ");
130
+ // }
131
+ // addClass() {
132
+ // /*this.setAttr("class", value);
133
+ // return this;*/
134
+ // }
135
+ // setId(id) {
136
+ // this.setAttr("id", id);
137
+ // return this;
138
+ // }
139
+ // get id() {
140
+ // return this.element.getAttribute("id");
141
+ // }
142
+ // onSwipe(width_threshold, height_threshold,...callbacks){
143
+ // if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
144
+ // this.events.swipe.onSwipe(...callbacks);
145
+ // return this;
146
+ // }
214
147
  // To Fix
215
148
  // onKeysDown({keys=[],callback}={}){
216
149
  // if(!this.events.key)this.events.key = useKeyEvent(this);
@@ -232,24 +165,24 @@ class UIElement extends UINode{
232
165
  this.events.custom.emit(event_name,detail);
233
166
  return this;
234
167
  }
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
- }
168
+ // watchAttr(callback){
169
+ // if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
170
+ // return this;
171
+ // }
172
+ // watchChildren(callback){
173
+ // if(!this.observer.children)this.observer.children = watchChildren(this,callback);
174
+ // return this;
175
+ // }
176
+ // watchSize(callback){
177
+ // if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
178
+ // this.observer.resize.start();
179
+ // return this;
180
+ // }
181
+ // watchIntersection(callback,config){
182
+ // if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
183
+ // this.observer.intersection.start();
184
+ // return this;
185
+ // }
253
186
 
254
187
  }
255
188
  export { UIElement }