ziko 0.49.6 → 0.50.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.
- package/dist/ziko.cjs +374 -363
- package/dist/ziko.js +686 -971
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +678 -953
- package/package.json +4 -1
- package/src/{reactivity → --reactivity-deprecated}/hooks/head/useFavIcon.js +4 -4
- package/src/{reactivity → --reactivity-deprecated}/hooks/head/useTitle.js +1 -1
- package/src/{reactivity → --reactivity-deprecated}/hooks/index.js +3 -3
- package/src/{reactivity → --reactivity-deprecated}/index.js +1 -1
- package/src/{use → --use-deprecated}/index.js +1 -1
- package/src/{use/use-event-emmiter.js → --use-deprecated/use-event-emmiter.js.txt} +3 -3
- package/src/__ziko__/__state__.js +1 -1
- package/src/app/ziko-app.js +6 -6
- package/src/events/binders/custom-event.js +11 -7
- package/src/events/binders/index.js +69 -13
- package/src/events/details-setter/index.js +2 -0
- package/src/events/details-setter/key.js +14 -0
- package/src/events/{binders → details-setter}/pointer.js +1 -15
- package/src/events/{__Events__.js → events-map/index.js} +7 -3
- package/src/events/index.js +1 -1
- package/src/events/types/__Shared__.d.ts +3 -3
- package/src/events/types/clipboard.d.ts +2 -2
- package/src/events/types/focus.d.ts +2 -2
- package/src/events/types/pointer.d.ts +2 -2
- package/src/events/{__ZikoEvent__.js → ziko-event.js} +17 -16
- package/src/hooks/index.js +10 -2
- package/src/hooks/use-event-emitter.js +68 -0
- package/src/hooks/use-favicon.js +59 -0
- package/src/hooks/{use-channel.js → use-ipc.js} +5 -22
- package/src/hooks/use-media-query.js +59 -0
- package/src/hooks/use-root.js +73 -0
- package/src/hooks/use-storage.js +73 -47
- package/src/hooks/use-thread.js +55 -0
- package/src/hooks/use-title.js +43 -0
- package/src/index.js +1 -1
- package/src/ui/__methods__/events.js +19 -5
- package/src/ui/constructors/UIElement.js +14 -12
- package/src/ui/constructors/UIElementCore.js +3 -136
- package/types/hooks/index.d.ts +9 -2
- package/types/hooks/use-Thread.d.ts +33 -0
- package/types/hooks/use-event-emitter.d.ts +46 -0
- package/types/hooks/use-favicon.d.ts +41 -0
- package/types/hooks/{use-channel.d.ts → use-ipc.d.ts} +2 -2
- package/types/hooks/use-media-query.d.ts +24 -0
- package/types/hooks/use-root.d.ts +15 -0
- package/types/hooks/use-storage.d.ts +47 -0
- package/types/hooks/use-title.d.ts +37 -0
- package/src/events/binders/click.js +0 -20
- package/src/events/binders/clipboard.js +0 -16
- package/src/events/binders/drag.js +0 -16
- package/src/events/binders/focus.js +0 -16
- package/src/events/binders/hash.js +0 -16
- package/src/events/binders/key.js +0 -27
- package/src/events/binders/mouse.js +0 -16
- package/src/events/binders/touch.js +0 -16
- package/src/events/binders/wheel.js +0 -16
- package/src/events/index.d.ts.txt +0 -3
- /package/src/{reactivity → --reactivity-deprecated}/events/Input.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/ZikoEvent.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/__note__ +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/custom-event.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/hash.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/media.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/mouse.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/swipe.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/events/touch.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/Contexte/useSuccesifKeys.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useCssLink.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useLinearGradient.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useMediaQuery.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRadialGradient.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useRoot.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useStyle.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/UI/useTheme.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/_useCssText.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useHead.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/head/useMeta.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/hooks/todo.md +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/idea +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/attributes.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/children.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/index.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/intersection.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/mutation.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/resize.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.js.txt +0 -0
- /package/src/{reactivity → --reactivity-deprecated}/observer/screen.txt +0 -0
- /package/src/{use → --use-deprecated}/use-channel.js.txt +0 -0
- /package/src/{use → --use-deprecated}/use-favicon.js +0 -0
- /package/src/{use → --use-deprecated}/use-link.js +0 -0
- /package/src/{use → --use-deprecated}/use-meta.js +0 -0
- /package/src/{use → --use-deprecated}/use-root.js +0 -0
- /package/src/{use → --use-deprecated}/use-storage.js.txt +0 -0
- /package/src/{use → --use-deprecated}/use-thread.js +0 -0
- /package/src/{use → --use-deprecated}/use-title.js +0 -0
- /package/src/events/{custom-events → custom-events-registry}/click-away.js +0 -0
- /package/src/events/{custom-events → custom-events-registry}/index.js +0 -0
- /package/src/events/{custom-events → custom-events-registry}/swipe.js +0 -0
- /package/src/events/{custom-events → custom-events-registry}/view.js +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
[
|
|
3
|
+
{
|
|
4
|
+
query: '(min-width: 600px)',
|
|
5
|
+
callback: () => console.log(1)
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
query: '(max-width: 300px)',
|
|
9
|
+
callback: () => console.log(2)
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class UseMediaQuery {
|
|
15
|
+
#mediaQueryRules;
|
|
16
|
+
#fallback;
|
|
17
|
+
#lastCalledCallback = null;
|
|
18
|
+
|
|
19
|
+
constructor(mediaQueryRules = [], fallback = () => {}) {
|
|
20
|
+
this.#mediaQueryRules = mediaQueryRules;
|
|
21
|
+
this.#fallback = fallback;
|
|
22
|
+
|
|
23
|
+
this.#init();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// PRIVATE: check if ANY rule matches
|
|
27
|
+
#checkAllRules() {
|
|
28
|
+
return this.#mediaQueryRules.some(
|
|
29
|
+
({ query }) => globalThis.matchMedia(query).matches
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// PRIVATE: installs listeners and initial checks
|
|
34
|
+
#init() {
|
|
35
|
+
this.#mediaQueryRules.forEach(({ query, callback }) => {
|
|
36
|
+
const mediaQueryList = globalThis.matchMedia(query);
|
|
37
|
+
|
|
38
|
+
const checkMatches = () => {
|
|
39
|
+
const anyMatch = this.#checkAllRules();
|
|
40
|
+
|
|
41
|
+
if (mediaQueryList.matches) {
|
|
42
|
+
callback();
|
|
43
|
+
this.#lastCalledCallback = callback;
|
|
44
|
+
} else if (!anyMatch && this.#lastCalledCallback !== this.#fallback) {
|
|
45
|
+
this.#fallback();
|
|
46
|
+
this.#lastCalledCallback = this.#fallback;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
checkMatches();
|
|
51
|
+
mediaQueryList.addEventListener("change", checkMatches);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const useMediaQuery = (mediaQueryRules, fallback) =>
|
|
57
|
+
new UseMediaQuery(mediaQueryRules, fallback);
|
|
58
|
+
|
|
59
|
+
export { useMediaQuery };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
class UseRoot {
|
|
2
|
+
constructor(PropsMap, { namespace = 'Ziko', ValidateCssProps = false } = {}) {
|
|
3
|
+
this.currentPropsMap = PropsMap;
|
|
4
|
+
this.namespace = namespace;
|
|
5
|
+
this.ValidateCssProps = ValidateCssProps;
|
|
6
|
+
this.use(PropsMap);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
use(PropsMap) {
|
|
10
|
+
if (this.ValidateCssProps) ValidateCssPropsFn(PropsMap);
|
|
11
|
+
this.currentPropsMap = PropsMap;
|
|
12
|
+
this.#maintain();
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#maintain() {
|
|
17
|
+
const root = globalThis?.document?.documentElement?.style;
|
|
18
|
+
for (const prop in this.currentPropsMap) {
|
|
19
|
+
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
20
|
+
root.setProperty(cssProp, this.currentPropsMap[prop]);
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(this, prop, {
|
|
23
|
+
value: `var(${cssProp})`,
|
|
24
|
+
writable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
enumerable: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ValidateCssPropsFn(PropsMap) {
|
|
33
|
+
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
34
|
+
for (const key in PropsMap) {
|
|
35
|
+
if (!validProps.has(key)) {
|
|
36
|
+
throw new Error(`Invalid CSS property: "${key}"`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const useRoot = (PropsMap, options = {}) => new UseRoot(PropsMap, options);
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
UseRoot,
|
|
45
|
+
useRoot
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// Usage
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
const Styles = {
|
|
53
|
+
S1 : {
|
|
54
|
+
background : 'white',
|
|
55
|
+
color : 'darkblue'
|
|
56
|
+
border : '2px darkblue solid"'
|
|
57
|
+
},
|
|
58
|
+
S2 : {
|
|
59
|
+
background : 'darkblue',
|
|
60
|
+
color : 'white'
|
|
61
|
+
border : '2px green solid"'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const {use, border, background, color} = useRoot(Style.S1)
|
|
65
|
+
|
|
66
|
+
tags.p("Test useRoot ").style({
|
|
67
|
+
border,
|
|
68
|
+
color,
|
|
69
|
+
background,
|
|
70
|
+
padding : '10px'
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
*/
|
package/src/hooks/use-storage.js
CHANGED
|
@@ -1,73 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class UseStorage{
|
|
4
|
-
constructor(storage, globalKey, initialValue){
|
|
5
|
-
this.cache={
|
|
1
|
+
import { useIPC } from "./use-ipc.js";
|
|
2
|
+
|
|
3
|
+
class UseStorage {
|
|
4
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
5
|
+
this.cache = {
|
|
6
6
|
storage,
|
|
7
7
|
globalKey,
|
|
8
|
-
channel:
|
|
9
|
-
oldItemKeys:new Set()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
this.#
|
|
8
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
9
|
+
oldItemKeys: new Set()
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
this.#init(initialValue, use_channel);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
get items() {
|
|
16
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
17
|
+
if (!raw) return {};
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(raw);
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
16
23
|
}
|
|
24
|
+
|
|
17
25
|
#maintain() {
|
|
18
|
-
|
|
26
|
+
const items = this.items;
|
|
27
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
28
|
+
for (const key in items) {
|
|
29
|
+
this[key] = items[key];
|
|
30
|
+
this.cache.oldItemKeys.add(key);
|
|
31
|
+
}
|
|
19
32
|
}
|
|
20
|
-
#init(initialValue){
|
|
21
|
-
this.cache.channel
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
|
|
26
|
-
// console.group("Ziko:useStorage")
|
|
27
|
-
// console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
|
|
28
|
-
// console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
|
|
29
|
-
// console.group("")
|
|
33
|
+
#init(initialValue, use_channel) {
|
|
34
|
+
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
35
|
+
if (!initialValue) {
|
|
36
|
+
this.#maintain();
|
|
37
|
+
return;
|
|
30
38
|
}
|
|
39
|
+
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
40
|
+
const existing = this.items;
|
|
41
|
+
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
42
|
+
this.#maintain();
|
|
43
|
+
}
|
|
31
44
|
else this.set(initialValue);
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.cache.
|
|
36
|
-
|
|
46
|
+
|
|
47
|
+
set(data) {
|
|
48
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
49
|
+
if (this.cache.channel) this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
37
50
|
this.#maintain();
|
|
38
|
-
return this
|
|
51
|
+
return this;
|
|
39
52
|
}
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
|
|
54
|
+
add(data) {
|
|
55
|
+
this.set({
|
|
42
56
|
...this.items,
|
|
43
57
|
...data
|
|
44
|
-
}
|
|
45
|
-
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
|
|
46
|
-
this.#maintain();
|
|
58
|
+
});
|
|
47
59
|
return this;
|
|
48
60
|
}
|
|
49
|
-
remove(...keys){
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
delete
|
|
53
|
-
delete this[
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
remove(...keys) {
|
|
62
|
+
const items = { ...this.items };
|
|
63
|
+
keys.forEach(key => {
|
|
64
|
+
delete items[key];
|
|
65
|
+
delete this[key];
|
|
66
|
+
this.cache.oldItemKeys.delete(key);
|
|
67
|
+
});
|
|
68
|
+
this.set(items);
|
|
56
69
|
return this;
|
|
57
70
|
}
|
|
58
|
-
get(key){
|
|
71
|
+
get(key) {
|
|
59
72
|
return this.items[key];
|
|
60
73
|
}
|
|
61
|
-
clear(){
|
|
74
|
+
clear() {
|
|
62
75
|
this.cache.storage.removeItem(this.cache.globalKey);
|
|
76
|
+
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
77
|
+
this.cache.oldItemKeys.clear();
|
|
63
78
|
this.#maintain();
|
|
64
79
|
return this;
|
|
65
80
|
}
|
|
66
|
-
|
|
81
|
+
onStorageUpdated(callback) {
|
|
82
|
+
if (this.cache.channel) {
|
|
83
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
84
|
+
}
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
67
87
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
|
|
89
|
+
// factory functions
|
|
90
|
+
const useLocaleStorage = (key, initialValue, use_channel = true) =>
|
|
91
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
92
|
+
|
|
93
|
+
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
94
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
95
|
+
|
|
96
|
+
export {
|
|
71
97
|
useLocaleStorage,
|
|
72
98
|
useSessionStorage
|
|
73
|
-
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
class UseThread {
|
|
2
|
+
#worker;
|
|
3
|
+
#callbacks = new Map();
|
|
4
|
+
#idCounter = 0;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
const workerCode = `
|
|
8
|
+
this.onmessage = function(e) {
|
|
9
|
+
const { id, funStr, args, close } = e.data;
|
|
10
|
+
try {
|
|
11
|
+
const func = new Function("return " + funStr)();
|
|
12
|
+
const result = func(...args);
|
|
13
|
+
postMessage({ id, result });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
postMessage({ id, error: error.message });
|
|
16
|
+
} finally {
|
|
17
|
+
if (close) self.close();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const blob = new Blob([workerCode], { type: "text/javascript" });
|
|
22
|
+
this.#worker = new Worker(URL.createObjectURL(blob));
|
|
23
|
+
|
|
24
|
+
this.#worker.addEventListener("message", (e) => {
|
|
25
|
+
const { id, result, error } = e.data;
|
|
26
|
+
const callback = this.#callbacks.get(id);
|
|
27
|
+
if (!callback) return;
|
|
28
|
+
|
|
29
|
+
callback(result, error);
|
|
30
|
+
this.#callbacks.delete(id);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
call(func, callback, args = [], close = true) {
|
|
34
|
+
if (typeof func !== "function") throw new TypeError("func must be a function");
|
|
35
|
+
const id = ++this.#idCounter;
|
|
36
|
+
this.#callbacks.set(id, callback);
|
|
37
|
+
|
|
38
|
+
this.#worker.postMessage({
|
|
39
|
+
id,
|
|
40
|
+
funStr: func.toString(),
|
|
41
|
+
args,
|
|
42
|
+
close
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
terminate() {
|
|
49
|
+
this.#worker.terminate();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const useThread = (func, callback, args = [], close = true) => new UseThread().call(func, callback, args, close);
|
|
54
|
+
|
|
55
|
+
export { UseThread, useThread };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEventEmitter } from "./use-event-emitter.js";
|
|
2
|
+
|
|
3
|
+
class UseTitle {
|
|
4
|
+
constructor(title = document.title, withEmitter = true) {
|
|
5
|
+
this.cache = {
|
|
6
|
+
emitter: null
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
if (withEmitter) this.useEventEmitter();
|
|
10
|
+
this.set(title);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
useEventEmitter() {
|
|
14
|
+
this.cache.emitter = useEventEmitter();
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setTitle(title) {
|
|
19
|
+
if (title !== document.title) {
|
|
20
|
+
document.title = title;
|
|
21
|
+
|
|
22
|
+
if (this.cache.emitter) {
|
|
23
|
+
this.cache.emitter.emit("ziko:title-changed", title);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get current() {
|
|
30
|
+
return document.title;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
onChange(callback) {
|
|
34
|
+
if (this.cache.emitter) {
|
|
35
|
+
this.cache.emitter.on("ziko:title-changed", callback);
|
|
36
|
+
}
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const useTitle = (title, withEmitter = true) => new UseTitle(title, withEmitter);
|
|
42
|
+
|
|
43
|
+
export { useTitle };
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventsMap } from "../../events/events-map/index.js";
|
|
2
2
|
import {
|
|
3
3
|
bind_pointer_event,
|
|
4
4
|
bind_mouse_event,
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
bind_wheel_event
|
|
11
11
|
} from "../../events/binders/index.js";
|
|
12
12
|
|
|
13
|
+
import { bind_custom_event } from "../../events/binders/custom-event.js";
|
|
14
|
+
|
|
13
15
|
const binderMap = {
|
|
14
16
|
ptr: bind_pointer_event,
|
|
15
17
|
mouse : bind_mouse_event,
|
|
@@ -21,14 +23,26 @@ const binderMap = {
|
|
|
21
23
|
wheel : bind_wheel_event
|
|
22
24
|
};
|
|
23
25
|
|
|
24
|
-
const EventsMethodes = {
|
|
26
|
+
const EventsMethodes = {
|
|
27
|
+
on(event_name,...callbacks){
|
|
28
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
29
|
+
this.events.custom.on(event_name,...callbacks);
|
|
30
|
+
return this;
|
|
31
|
+
},
|
|
32
|
+
emit(event_name,detail={}){
|
|
33
|
+
if(!this.events.custom)this.events.custom = bind_custom_event(this);
|
|
34
|
+
this.events.custom.emit(event_name,detail);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
25
38
|
|
|
26
|
-
Object.entries(
|
|
39
|
+
Object.entries(EventsMap).forEach(([name, eventList]) => {
|
|
40
|
+
const lname = name.toLowerCase()
|
|
27
41
|
eventList.forEach(event => {
|
|
28
42
|
const methodName = `on${event}`;
|
|
29
43
|
EventsMethodes[methodName] = function (...callbacks) {
|
|
30
|
-
if (!this.events[
|
|
31
|
-
this.events[
|
|
44
|
+
if (!this.events[lname]) this.events[lname] = binderMap[lname](this);
|
|
45
|
+
this.events[lname][methodName](...callbacks);
|
|
32
46
|
return this;
|
|
33
47
|
};
|
|
34
48
|
});
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
StyleMethods
|
|
9
9
|
} from "../__methods__/index.js";
|
|
10
10
|
import {
|
|
11
|
-
useCustomEvent,
|
|
11
|
+
// useCustomEvent,
|
|
12
12
|
// useSwipeEvent,
|
|
13
13
|
// watchIntersection,
|
|
14
14
|
// watchSize,
|
|
15
15
|
// watchAttr,
|
|
16
16
|
// watchChildren
|
|
17
|
-
} from "
|
|
17
|
+
} from "../../--reactivity-deprecated/events/custom-event.js"
|
|
18
18
|
class UIElement extends UIElementCore{
|
|
19
19
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
20
20
|
super()
|
|
@@ -28,6 +28,8 @@ class UIElement extends UIElementCore{
|
|
|
28
28
|
IndexingMethods,
|
|
29
29
|
EventsMethodes
|
|
30
30
|
);
|
|
31
|
+
|
|
32
|
+
// console.log(EventsMethodes)
|
|
31
33
|
if(element)this.init(element, name, type, render)
|
|
32
34
|
}
|
|
33
35
|
get element(){
|
|
@@ -165,16 +167,16 @@ class UIElement extends UIElementCore{
|
|
|
165
167
|
// this.events.clipboard.onSelect(...callbacks);
|
|
166
168
|
// return this;
|
|
167
169
|
// }
|
|
168
|
-
on(event_name,...callbacks){
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
emit(event_name,detail={}){
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
170
|
+
// on(event_name,...callbacks){
|
|
171
|
+
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
172
|
+
// this.events.custom.on(event_name,...callbacks);
|
|
173
|
+
// return this;
|
|
174
|
+
// }
|
|
175
|
+
// emit(event_name,detail={}){
|
|
176
|
+
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
177
|
+
// this.events.custom.emit(event_name,detail);
|
|
178
|
+
// return this;
|
|
179
|
+
// }
|
|
178
180
|
// watchAttr(callback){
|
|
179
181
|
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
180
182
|
// return this;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {UINode} from "./UINode.js";
|
|
2
|
-
import {__init__global__
|
|
3
|
-
|
|
2
|
+
// import {__init__global__} from '../../__ziko__/index.js';
|
|
3
|
+
import { UIStore } from "../../__ziko__/__ui__.js";
|
|
4
|
+
// __init__global__()
|
|
4
5
|
class UIElementCore extends UINode{
|
|
5
6
|
constructor(){
|
|
6
7
|
super()
|
|
@@ -87,139 +88,5 @@ class UIElementCore extends UINode{
|
|
|
87
88
|
isUIElement(){
|
|
88
89
|
return true;
|
|
89
90
|
}
|
|
90
|
-
// get st(){
|
|
91
|
-
// return this.cache.style;
|
|
92
|
-
// }
|
|
93
|
-
// get attr(){
|
|
94
|
-
// return this.cache.attributes;
|
|
95
|
-
// }
|
|
96
|
-
// get evt(){
|
|
97
|
-
// return this.events;
|
|
98
|
-
// }
|
|
99
|
-
// get html(){
|
|
100
|
-
// return this.element.innerHTML;
|
|
101
|
-
// }
|
|
102
|
-
// get text(){
|
|
103
|
-
// return this.element.textContent;
|
|
104
|
-
// }
|
|
105
|
-
// get isBody(){
|
|
106
|
-
// return this.element === globalThis?.document.body;
|
|
107
|
-
// }
|
|
108
|
-
// get parent(){
|
|
109
|
-
// return this.cache.parent;
|
|
110
|
-
// }
|
|
111
|
-
// get width(){
|
|
112
|
-
// return this.element.getBoundingClientRect().width;
|
|
113
|
-
// }
|
|
114
|
-
// get height(){
|
|
115
|
-
// return this.element.getBoundingClientRect().height;
|
|
116
|
-
// }
|
|
117
|
-
// get top(){
|
|
118
|
-
// return this.element.getBoundingClientRect().top;
|
|
119
|
-
// }
|
|
120
|
-
// get right(){
|
|
121
|
-
// return this.element.getBoundingClientRect().right;
|
|
122
|
-
// }
|
|
123
|
-
// get bottom(){
|
|
124
|
-
// return this.element.getBoundingClientRect().bottom;
|
|
125
|
-
// }
|
|
126
|
-
// get left(){
|
|
127
|
-
// return this.element.getBoundingClientRect().left;
|
|
128
|
-
// }
|
|
129
|
-
// clone(render=false) {
|
|
130
|
-
// // UI.__proto__=this.__proto__;
|
|
131
|
-
// // if(this.items.length){
|
|
132
|
-
// // const items = [...this.items].map(n=>n.clone());
|
|
133
|
-
// // UI.append(...items);
|
|
134
|
-
// // }
|
|
135
|
-
// // else UI.element=this.element.cloneNode(true);
|
|
136
|
-
// // return UI.mount(render);
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
// freeze(freeze){
|
|
140
|
-
// this.cache.isFrozzen=freeze;
|
|
141
|
-
// return this;
|
|
142
|
-
// }
|
|
143
|
-
// setTarget(tg) {
|
|
144
|
-
// if(this.isBody) return ;
|
|
145
|
-
// if (tg?.isUIElement) tg = tg.element;
|
|
146
|
-
// this.unmount();
|
|
147
|
-
// this.target = tg;
|
|
148
|
-
// this.mount();
|
|
149
|
-
// return this;
|
|
150
|
-
// }
|
|
151
|
-
// describe(label){
|
|
152
|
-
// if(label)this.setAttr("aria-label",label)
|
|
153
|
-
// }
|
|
154
|
-
// get children() {
|
|
155
|
-
// return [...this.element.children];
|
|
156
|
-
// }
|
|
157
|
-
// get cloneElement() {
|
|
158
|
-
// return this.element.cloneNode(true);
|
|
159
|
-
// }
|
|
160
|
-
// setClasses(...value) {
|
|
161
|
-
// this.setAttr("class", value.join(" "));
|
|
162
|
-
// return this;
|
|
163
|
-
// }
|
|
164
|
-
// get classes(){
|
|
165
|
-
// const classes=this.element.getAttribute("class");
|
|
166
|
-
// return classes===null?[]:classes.split(" ");
|
|
167
|
-
// }
|
|
168
|
-
// addClass() {
|
|
169
|
-
// /*this.setAttr("class", value);
|
|
170
|
-
// return this;*/
|
|
171
|
-
// }
|
|
172
|
-
// setId(id) {
|
|
173
|
-
// this.setAttr("id", id);
|
|
174
|
-
// return this;
|
|
175
|
-
// }
|
|
176
|
-
// get id() {
|
|
177
|
-
// return this.element.getAttribute("id");
|
|
178
|
-
// }
|
|
179
|
-
// onSwipe(width_threshold, height_threshold,...callbacks){
|
|
180
|
-
// if(!this.events.swipe)this.events.swipe = useSwipeEvent(this, width_threshold, height_threshold);
|
|
181
|
-
// this.events.swipe.onSwipe(...callbacks);
|
|
182
|
-
// return this;
|
|
183
|
-
// }
|
|
184
|
-
// To Fix
|
|
185
|
-
// onKeysDown({keys=[],callback}={}){
|
|
186
|
-
// if(!this.events.key)this.events.key = useKeyEvent(this);
|
|
187
|
-
// this.events.key.handleSuccessifKeys({keys,callback});
|
|
188
|
-
// return this;
|
|
189
|
-
// }
|
|
190
|
-
// onSelect(...callbacks){
|
|
191
|
-
// if(!this.events.clipboard)this.events.clipboard = useClipboardEvent(this);
|
|
192
|
-
// this.events.clipboard.onSelect(...callbacks);
|
|
193
|
-
// return this;
|
|
194
|
-
// }
|
|
195
|
-
// on(event_name,...callbacks){
|
|
196
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
197
|
-
// this.events.custom.on(event_name,...callbacks);
|
|
198
|
-
// return this;
|
|
199
|
-
// }
|
|
200
|
-
// emit(event_name,detail={}){
|
|
201
|
-
// if(!this.events.custom)this.events.custom = useCustomEvent(this);
|
|
202
|
-
// this.events.custom.emit(event_name,detail);
|
|
203
|
-
// return this;
|
|
204
|
-
// }
|
|
205
|
-
// watchAttr(callback){
|
|
206
|
-
// if(!this.observer.attr)this.observer.attr = watchAttr(this,callback);
|
|
207
|
-
// return this;
|
|
208
|
-
// }
|
|
209
|
-
// watchChildren(callback){
|
|
210
|
-
// if(!this.observer.children)this.observer.children = watchChildren(this,callback);
|
|
211
|
-
// return this;
|
|
212
|
-
// }
|
|
213
|
-
// watchSize(callback){
|
|
214
|
-
// if(!this.observer.resize)this.observer.resize = watchSize(this,callback);
|
|
215
|
-
// this.observer.resize.start();
|
|
216
|
-
// return this;
|
|
217
|
-
// }
|
|
218
|
-
// watchIntersection(callback,config){
|
|
219
|
-
// if(!this.observer.intersection)this.observer.intersection = watchIntersection(this,callback,config);
|
|
220
|
-
// this.observer.intersection.start();
|
|
221
|
-
// return this;
|
|
222
|
-
// }
|
|
223
|
-
|
|
224
91
|
}
|
|
225
92
|
export { UIElementCore }
|
package/types/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export type * from './use-
|
|
1
|
+
export type * from './use-ipc'
|
|
2
|
+
export type * from './use-storage.d.ts'
|
|
2
3
|
export type * from './use-state.d.ts'
|
|
3
4
|
export type * from './use-derived.d.ts'
|
|
4
|
-
export type * from './use-reactive.d.ts'
|
|
5
|
+
export type * from './use-reactive.d.ts'
|
|
6
|
+
export type * from './use-Thread.d.ts'
|
|
7
|
+
export type * from './use-event-emitter.d.ts'
|
|
8
|
+
export type * from './use-media-query.d.ts'
|
|
9
|
+
export type * from './use-title.d.ts'
|
|
10
|
+
export type * from './use-favicon.d.ts'
|
|
11
|
+
export type * from './use-root.d.ts'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// use-thread.d.ts
|
|
2
|
+
|
|
3
|
+
export declare class UseThread {
|
|
4
|
+
constructor();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Call a function inside the worker.
|
|
8
|
+
* @param func - Function to execute (cannot capture outer scope)
|
|
9
|
+
* @param callback - Callback receiving (result, error)
|
|
10
|
+
* @param args - Optional arguments array to pass to the function
|
|
11
|
+
* @param close - Automatically close the worker after execution (default true)
|
|
12
|
+
*/
|
|
13
|
+
call<T = any>(
|
|
14
|
+
func: (...args: any[]) => T,
|
|
15
|
+
callback: (result: T | null, error: string | null) => void,
|
|
16
|
+
args?: any[],
|
|
17
|
+
close?: boolean
|
|
18
|
+
): this;
|
|
19
|
+
|
|
20
|
+
/** Terminate the worker manually */
|
|
21
|
+
terminate(): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Helper function for single-use worker threads.
|
|
26
|
+
* Immediately executes the function and returns the UseThread instance.
|
|
27
|
+
*/
|
|
28
|
+
export declare const useThread: <T = any>(
|
|
29
|
+
func: (...args: any[]) => T,
|
|
30
|
+
callback: (result: T | null, error: string | null) => void,
|
|
31
|
+
args?: any[],
|
|
32
|
+
close?: boolean
|
|
33
|
+
) => UseThread;
|