ziko 1.7.0 → 1.8.0
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 +433 -154
- package/dist/ziko.js +433 -154
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +428 -154
- package/package.json +1 -1
- package/src/dom/{flex → components/Flex}/index.js +1 -1
- package/src/dom/components/{for → For}/index.js +1 -1
- package/src/dom/{suspense → components/Suspense}/index.js +3 -7
- package/src/dom/components/View/index.js +9 -0
- package/src/dom/{graphics/canvas.js → components/graphics/Canvas/index.js} +6 -6
- package/src/dom/{graphics/svg.js → components/graphics/Svg/index.js} +4 -4
- package/src/dom/components/graphics/index.js +2 -0
- package/src/dom/components/index.js +10 -3
- package/src/dom/{wrappers/html → components/wrappers/HTMLWrapper}/index.js +1 -1
- package/src/dom/{wrappers/svg → components/wrappers/SVGWrapper}/index.js +1 -1
- package/src/dom/components/wrappers/index.js +2 -0
- package/src/dom/index.js +0 -8
- package/src/hooks/index.d.ts +1 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/use-effect.d.ts +39 -0
- package/src/hooks/use-effect.js +40 -0
- package/src/hooks/use-state.d.ts +28 -10
- package/src/dom/graphics/index.js +0 -2
- package/src/dom/logic/index.js +0 -1
- package/src/dom/view/index.js +0 -13
- package/src/dom/wrappers/index.js +0 -2
- package/src/events-dep/binders/coordinates-based-event.js +0 -25
- package/src/events-dep/binders/custom-event.js +0 -33
- package/src/events-dep/binders/index.js +0 -105
- package/src/events-dep/custom-events-registry/click-away.js +0 -38
- package/src/events-dep/custom-events-registry/index.js +0 -3
- package/src/events-dep/custom-events-registry/swipe.js +0 -76
- package/src/events-dep/custom-events-registry/view.js +0 -74
- package/src/events-dep/customizers/normalise-coordinates.js +0 -0
- package/src/events-dep/details-setter/index.js +0 -4
- package/src/events-dep/details-setter/key.js +0 -14
- package/src/events-dep/details-setter/mouse.js +0 -35
- package/src/events-dep/details-setter/pointer.js +0 -35
- package/src/events-dep/details-setter/touch.js +0 -37
- package/src/events-dep/events-map/index.js +0 -70
- package/src/events-dep/index.js +0 -3
- package/src/events-dep/types/__Shared__.d.ts +0 -155
- package/src/events-dep/types/clipboard.d.ts +0 -20
- package/src/events-dep/types/focus.d.ts +0 -19
- package/src/events-dep/types/pointer.d.ts +0 -45
- package/src/events-dep/utils.js +0 -38
- package/src/events-dep/ziko-event.js +0 -108
- package/src/watch/dom-observer/ziko-observer.js +0 -15
- /package/src/dom/{flex → components/Flex}/utils/index.js +0 -0
- /package/src/dom/components/{fragment → Fragment}/index.d.ts +0 -0
- /package/src/dom/components/{fragment → Fragment}/index.js +0 -0
- /package/src/dom/components/{swap → Swap}/index.d.ts +0 -0
- /package/src/dom/components/{swap → Swap}/index.js +0 -0
- /package/src/dom/{logic/switch → components/Switch}/index.js +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function mouse_details_setter() {
|
|
2
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
3
|
-
const e = this.event;
|
|
4
|
-
let x = (e.clientX - rect.left) | 0;
|
|
5
|
-
let y = (e.clientY - rect.top) | 0;
|
|
6
|
-
|
|
7
|
-
if(this.cache.useNormalisedCoordinates){
|
|
8
|
-
const w = this.targetElement.clientWidth;
|
|
9
|
-
const h = this.targetElement.clientHeight;
|
|
10
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
11
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
switch (this.currentEvent) {
|
|
15
|
-
|
|
16
|
-
case "mousedown":
|
|
17
|
-
this.dx = x;
|
|
18
|
-
this.dy = y;
|
|
19
|
-
this.isDown = true;
|
|
20
|
-
break;
|
|
21
|
-
|
|
22
|
-
case "mousemove":
|
|
23
|
-
this.mx = x;
|
|
24
|
-
this.my = y;
|
|
25
|
-
this.isMoving = true;
|
|
26
|
-
break;
|
|
27
|
-
|
|
28
|
-
case "mouserup":
|
|
29
|
-
this.ux = x;
|
|
30
|
-
this.uy = y;
|
|
31
|
-
this.isDown = false;
|
|
32
|
-
this.isMoving = false;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function ptr_details_setter() {
|
|
2
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
3
|
-
const e = this.event;
|
|
4
|
-
let x = (e.clientX - rect.left) | 0;
|
|
5
|
-
let y = (e.clientY - rect.top) | 0;
|
|
6
|
-
|
|
7
|
-
if(this.cache.useNormalisedCoordinates){
|
|
8
|
-
const w = this.targetElement.clientWidth;
|
|
9
|
-
const h = this.targetElement.clientHeight;
|
|
10
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
11
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
12
|
-
}
|
|
13
|
-
switch (this.currentEvent) {
|
|
14
|
-
|
|
15
|
-
case "pointerdown":
|
|
16
|
-
this.dx = x;
|
|
17
|
-
this.dy = y;
|
|
18
|
-
this.isDown = true;
|
|
19
|
-
break;
|
|
20
|
-
|
|
21
|
-
case "pointermove":
|
|
22
|
-
this.mx = x;
|
|
23
|
-
this.my = y;
|
|
24
|
-
this.isMoving = true;
|
|
25
|
-
break;
|
|
26
|
-
|
|
27
|
-
case "pointerup":
|
|
28
|
-
this.ux = x;
|
|
29
|
-
this.uy = y;
|
|
30
|
-
this.isDown = false;
|
|
31
|
-
this.isMoving = false;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function touch_details_setter() {
|
|
2
|
-
const e = this.event;
|
|
3
|
-
const touch = e.touches?.[0] || e.changedTouches?.[0];
|
|
4
|
-
|
|
5
|
-
if (!touch) return; // should never happen but safe
|
|
6
|
-
|
|
7
|
-
const rect = this.targetElement.getBoundingClientRect();
|
|
8
|
-
let x = touch.clientX - rect.left;
|
|
9
|
-
let y = touch.clientY - rect.top;
|
|
10
|
-
|
|
11
|
-
if(this.cache.useNormalisedCoordinates){
|
|
12
|
-
const w = this.targetElement.clientWidth;
|
|
13
|
-
const h = this.targetElement.clientHeight;
|
|
14
|
-
x = +((x / w) * 2 - 1).toFixed(8);
|
|
15
|
-
y = +((y / h) * -2 + 1).toFixed(8);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
switch (this.currentEvent) {
|
|
19
|
-
case "touchstart":
|
|
20
|
-
this.dx = x;
|
|
21
|
-
this.dy = y;
|
|
22
|
-
this.isDown = true;
|
|
23
|
-
break;
|
|
24
|
-
|
|
25
|
-
case "touchmove":
|
|
26
|
-
this.mx = x;
|
|
27
|
-
this.my = y;
|
|
28
|
-
this.isMoving = true;
|
|
29
|
-
break;
|
|
30
|
-
|
|
31
|
-
case "touchend":
|
|
32
|
-
this.ux = x;
|
|
33
|
-
this.uy = y;
|
|
34
|
-
this.isDown = false;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const EventsMap = {
|
|
2
|
-
'Click' : [
|
|
3
|
-
'Click',
|
|
4
|
-
'DblClick',
|
|
5
|
-
'ClickAway'
|
|
6
|
-
],
|
|
7
|
-
'Ptr' : [
|
|
8
|
-
'PtrMove',
|
|
9
|
-
'PtrDown',
|
|
10
|
-
'PtrUp',
|
|
11
|
-
'PtrLeave',
|
|
12
|
-
'PtrEnter',
|
|
13
|
-
'PtrOut',
|
|
14
|
-
'PtrCancel'
|
|
15
|
-
],
|
|
16
|
-
'Mouse' : [
|
|
17
|
-
'MouseMove',
|
|
18
|
-
'MouseDown',
|
|
19
|
-
'MouseUp',
|
|
20
|
-
'MouseEnter',
|
|
21
|
-
'MouseLeave',
|
|
22
|
-
'MouseOut'
|
|
23
|
-
],
|
|
24
|
-
// 'Touch' : [],
|
|
25
|
-
'Key' : [
|
|
26
|
-
'KeyDown',
|
|
27
|
-
'KeyPress',
|
|
28
|
-
'KeyUp'
|
|
29
|
-
],
|
|
30
|
-
'Clipboard':[
|
|
31
|
-
'Copy',
|
|
32
|
-
'Cut',
|
|
33
|
-
'Paste'
|
|
34
|
-
],
|
|
35
|
-
'Focus':[
|
|
36
|
-
'focus',
|
|
37
|
-
'blur'
|
|
38
|
-
],
|
|
39
|
-
'Drag':[
|
|
40
|
-
"Drag",
|
|
41
|
-
"DragStart",
|
|
42
|
-
"DragEnd",
|
|
43
|
-
"Drop"
|
|
44
|
-
],
|
|
45
|
-
'Wheel': [
|
|
46
|
-
'Wheel'
|
|
47
|
-
],
|
|
48
|
-
// 'Media':[
|
|
49
|
-
|
|
50
|
-
// ],
|
|
51
|
-
// 'Hash':[
|
|
52
|
-
// "HashChange"
|
|
53
|
-
// ]
|
|
54
|
-
|
|
55
|
-
'View':[
|
|
56
|
-
'EnterView',
|
|
57
|
-
'ExitView',
|
|
58
|
-
'ResizeView'
|
|
59
|
-
],
|
|
60
|
-
'Swipe':[
|
|
61
|
-
'SwipeLeft',
|
|
62
|
-
'SwipeUp',
|
|
63
|
-
'SwipeRight',
|
|
64
|
-
'SwipeDown'
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export {
|
|
69
|
-
EventsMap
|
|
70
|
-
}
|
package/src/events-dep/index.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
export type EventCustomizer = ((this: ZikoEvent) => void) | ((ctx: ZikoEvent) => void);
|
|
2
|
-
|
|
3
|
-
export type EventMethodesBinder<
|
|
4
|
-
EventKeys extends string,
|
|
5
|
-
InstanceType
|
|
6
|
-
> = {
|
|
7
|
-
[K in EventKeys as `on${K}`]: (...callbacks: ((ctx: InstanceType) => void)[]) => InstanceType
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type Callback<InstanceType> = (ctx: InstanceType) => void;
|
|
11
|
-
|
|
12
|
-
export interface ZikoEventStream {
|
|
13
|
-
enabled: Record<string, boolean>;
|
|
14
|
-
clear: Record<string, boolean>;
|
|
15
|
-
history: Record<string, any[]>;
|
|
16
|
-
t0?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ZikoEventCache {
|
|
20
|
-
currentEvent: string | null;
|
|
21
|
-
event: Event | null;
|
|
22
|
-
options: Record<string, AddEventListenerOptions>;
|
|
23
|
-
preventDefault: Record<string, boolean>;
|
|
24
|
-
stopPropagation: Record<string, boolean>;
|
|
25
|
-
stopImmediatePropagation: Record<string, boolean>;
|
|
26
|
-
event_flow: Record<string, unknown>;
|
|
27
|
-
paused: Record<string, boolean>;
|
|
28
|
-
stream: ZikoEventStream;
|
|
29
|
-
callbacks: Record<string, ((e: any) => void)[]>;
|
|
30
|
-
__controllers__: Record<string, (e: Event) => void>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export declare class ZikoEvent {
|
|
34
|
-
constructor(
|
|
35
|
-
target: any,
|
|
36
|
-
Events: string[],
|
|
37
|
-
details_setter?: (this: ZikoEvent) => void,
|
|
38
|
-
customizer?: EventCustomizer
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
target: any;
|
|
42
|
-
cache: ZikoEventCache;
|
|
43
|
-
|
|
44
|
-
get targetElement(): HTMLElement | null;
|
|
45
|
-
get isParent(): boolean;
|
|
46
|
-
get item(): any;
|
|
47
|
-
get currentEvent(): string | null;
|
|
48
|
-
get event(): Event | null;
|
|
49
|
-
|
|
50
|
-
_register_events(
|
|
51
|
-
Events: string[] | undefined,
|
|
52
|
-
details_setter: (e: this) => any,
|
|
53
|
-
customizer: (e: this) => any, // To Check
|
|
54
|
-
REGISTER_METHODES?: boolean
|
|
55
|
-
): this;
|
|
56
|
-
|
|
57
|
-
setTarget(UI: any): this;
|
|
58
|
-
|
|
59
|
-
preventDefault(
|
|
60
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
61
|
-
defaultValue?: boolean | "default"
|
|
62
|
-
): this;
|
|
63
|
-
|
|
64
|
-
stopPropagation(
|
|
65
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
66
|
-
defaultValue?: boolean | "default"
|
|
67
|
-
): this;
|
|
68
|
-
|
|
69
|
-
stopImmediatePropagation(
|
|
70
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
71
|
-
defaultValue?: boolean | "default"
|
|
72
|
-
): this;
|
|
73
|
-
|
|
74
|
-
setEventOptions(
|
|
75
|
-
event: string,
|
|
76
|
-
options: AddEventListenerOptions
|
|
77
|
-
): this;
|
|
78
|
-
|
|
79
|
-
pause(
|
|
80
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
81
|
-
defaultValue?: boolean | "default"
|
|
82
|
-
): this;
|
|
83
|
-
|
|
84
|
-
resume(
|
|
85
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
86
|
-
defaultValue?: boolean | "default"
|
|
87
|
-
): this;
|
|
88
|
-
|
|
89
|
-
stream(
|
|
90
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
91
|
-
defaultValue?: boolean | "default"
|
|
92
|
-
): this;
|
|
93
|
-
|
|
94
|
-
clear(): this;
|
|
95
|
-
|
|
96
|
-
dispose(
|
|
97
|
-
overrides?: Partial<Record<string, boolean>>,
|
|
98
|
-
defaultValue?: boolean | "default"
|
|
99
|
-
): this;
|
|
100
|
-
|
|
101
|
-
// Internal
|
|
102
|
-
protected __handle(
|
|
103
|
-
event: string,
|
|
104
|
-
handler: EventListenerOrEventListenerObject,
|
|
105
|
-
options?: AddEventListenerOptions,
|
|
106
|
-
dispose?: any
|
|
107
|
-
): this;
|
|
108
|
-
|
|
109
|
-
protected __onEvent(
|
|
110
|
-
event: string,
|
|
111
|
-
options?: AddEventListenerOptions,
|
|
112
|
-
dispose?: any,
|
|
113
|
-
...callbacks: ((ctx: this) => void)[]
|
|
114
|
-
): this;
|
|
115
|
-
}
|
|
116
|
-
// export type ClickEventKeys =
|
|
117
|
-
// | 'Click'
|
|
118
|
-
// | 'DblClick';
|
|
119
|
-
|
|
120
|
-
// export type PointerEventKeys =
|
|
121
|
-
// | 'PtrMove'
|
|
122
|
-
// | 'PtrDown'
|
|
123
|
-
// | 'PtrUp'
|
|
124
|
-
// | 'PtrLeave'
|
|
125
|
-
// | 'PtrEnter'
|
|
126
|
-
// | 'PtrOut'
|
|
127
|
-
// | 'PtrCancel'
|
|
128
|
-
|
|
129
|
-
// export type MouseEventKeys =
|
|
130
|
-
// | 'MouseMove'
|
|
131
|
-
// | 'MouseDown';
|
|
132
|
-
// export type TouchEventKeys =
|
|
133
|
-
// | 'ToucMove'
|
|
134
|
-
// | 'ToucDown';
|
|
135
|
-
// export type KeyEventKeys =
|
|
136
|
-
// | 'keyDown'
|
|
137
|
-
// | 'keyPress'
|
|
138
|
-
// | 'keyUs';
|
|
139
|
-
// export type ClipboardEventKeys =
|
|
140
|
-
// | 'Copy'
|
|
141
|
-
// | 'Cut'
|
|
142
|
-
// | 'Paste';
|
|
143
|
-
// export type FocusEventKeys =
|
|
144
|
-
// | 'focus'
|
|
145
|
-
// | 'blur';
|
|
146
|
-
// export type DragEventKeys =
|
|
147
|
-
// | 'Drag'
|
|
148
|
-
// | 'DragStart'
|
|
149
|
-
// | 'DragEnd'
|
|
150
|
-
// | 'Drop';
|
|
151
|
-
// export type MediaEventKeys =
|
|
152
|
-
// | '__';
|
|
153
|
-
// export type HashEventKeys =
|
|
154
|
-
// | 'HashChange'
|
|
155
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
import type { Callback, ClipboardEventKeys } from './__Shared__.js';
|
|
3
|
-
import { UIElement } from "../../ui/index.js";
|
|
4
|
-
|
|
5
|
-
declare class ZikoEventClipboard extends ZikoEvent {
|
|
6
|
-
constructor(target: any, customizer?: Function);
|
|
7
|
-
|
|
8
|
-
// Explicitly declare the dynamic methods to get editor support
|
|
9
|
-
onCopy(...callbacks: Callback<ZikoEventClipboard>[]): this;
|
|
10
|
-
onCut(...callbacks: Callback<ZikoEventClipboard>[]): this;
|
|
11
|
-
onPaste(...callbacks: Callback<ZikoEventClipboard>[]): this;
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare const bind_clipboard_event: (target: UIElement, customizer?: Function) => ZikoEventClipboard;
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
ZikoEventClipboard,
|
|
19
|
-
bind_clipboard_event,
|
|
20
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
import type { Callback } from './__Shared__.js';
|
|
3
|
-
import { UIElement } from "../../ui/index.js";
|
|
4
|
-
|
|
5
|
-
declare class ZikoEventFocus extends ZikoEvent {
|
|
6
|
-
constructor(target: any, customizer?: Function);
|
|
7
|
-
|
|
8
|
-
// Explicitly declare the dynamic methods to get editor support
|
|
9
|
-
onFocus(...callbacks: Callback<ZikoEventFocus>[]): this;
|
|
10
|
-
onBlur(...callbacks: Callback<ZikoEventFocus>[]): this;
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare const bind_focus_event: (target: UIElement, customizer?: Function) => ZikoEventFocus;
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
ZikoEventFocus,
|
|
18
|
-
bind_focus_event,
|
|
19
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
import type { EventMethodesBinder, Callback, PointerEventKeys } from './__Shared__.js';
|
|
3
|
-
import { UIElement } from "../../ui/index.js";
|
|
4
|
-
|
|
5
|
-
type PointerEventMethodesBinder = EventMethodesBinder<PointerEventKeys, ZikoEventPointer>;
|
|
6
|
-
|
|
7
|
-
declare class ZikoEventPointer extends ZikoEvent implements PointerEventMethodesBinder {
|
|
8
|
-
constructor(target: any, customizer?: Function);
|
|
9
|
-
|
|
10
|
-
isDown: boolean;
|
|
11
|
-
|
|
12
|
-
dx?: number;
|
|
13
|
-
dy?: number;
|
|
14
|
-
|
|
15
|
-
mx?: number;
|
|
16
|
-
my?: number;
|
|
17
|
-
isMoving?: boolean;
|
|
18
|
-
|
|
19
|
-
ux?: number;
|
|
20
|
-
uy?: number;
|
|
21
|
-
|
|
22
|
-
swippe?: {
|
|
23
|
-
h: "left" | "right" | "none";
|
|
24
|
-
v: "top" | "bottom" | "none";
|
|
25
|
-
delta_x: number;
|
|
26
|
-
delta_y: number;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Explicitly declare the dynamic methods to get editor support
|
|
30
|
-
onPtrMove(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
31
|
-
onPtrDown(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
32
|
-
onPtrUp(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
33
|
-
onPtrLeave(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
34
|
-
onPtrEnter(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
35
|
-
onPtrOut(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
36
|
-
onPtrCancel(...callbacks: Callback<ZikoEventPointer>[]): this;
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
declare const bind_pointer_event: (target: UIElement, customizer?: Function) => ZikoEventPointer;
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
ZikoEventPointer,
|
|
44
|
-
bind_pointer_event,
|
|
45
|
-
};
|
package/src/events-dep/utils.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export function event_controller(e, event_name, details_setter, customizer) {
|
|
2
|
-
this.cache.currentEvent = event_name;
|
|
3
|
-
this.cache.event = e;
|
|
4
|
-
|
|
5
|
-
details_setter?.call(this);
|
|
6
|
-
if (customizer?.hasOwnProperty('prototype')) customizer?.call(this);
|
|
7
|
-
else customizer?.call(null, this);
|
|
8
|
-
|
|
9
|
-
if (this.cache.preventDefault[event_name]) e.preventDefault();
|
|
10
|
-
if (this.cache.stopPropagation[event_name]) e.stopPropagation();
|
|
11
|
-
if (this.cache.stopImmediatePropagation[event_name]) e.stopImmediatePropagation();
|
|
12
|
-
|
|
13
|
-
// Call the single callback if it exists
|
|
14
|
-
this.cache.callbacks[event_name]?.(this);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function toggle_event_listener(method, ...events) {
|
|
18
|
-
const keys = events.length === 0
|
|
19
|
-
? Object.keys(this.cache.paused)
|
|
20
|
-
: events;
|
|
21
|
-
keys.forEach(key => {
|
|
22
|
-
if (!this.cache.paused.hasOwnProperty(key)) return;
|
|
23
|
-
this.targetElement?.[method](
|
|
24
|
-
key,
|
|
25
|
-
this.cache.__controllers__[key],
|
|
26
|
-
this.cache.options[key]
|
|
27
|
-
);
|
|
28
|
-
this.cache.paused[key] = method === 'removeEventListener';
|
|
29
|
-
});
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
const getEvent=(event = "")=>{
|
|
33
|
-
if(event.startsWith("Ptr"))return `pointer${event.split("Ptr")[1].toLowerCase()}`;
|
|
34
|
-
return event.toLowerCase()
|
|
35
|
-
}
|
|
36
|
-
export{
|
|
37
|
-
getEvent
|
|
38
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getEvent,
|
|
3
|
-
event_controller,
|
|
4
|
-
toggle_event_listener
|
|
5
|
-
} from './utils.js'
|
|
6
|
-
class ZikoEvent {
|
|
7
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
8
|
-
this.target = target;
|
|
9
|
-
this.cache = {
|
|
10
|
-
signature,
|
|
11
|
-
currentEvent : null,
|
|
12
|
-
event: null,
|
|
13
|
-
options : {},
|
|
14
|
-
preventDefault : {},
|
|
15
|
-
stopPropagation : {},
|
|
16
|
-
stopImmediatePropagation : {},
|
|
17
|
-
paused : {},
|
|
18
|
-
callbacks : {},
|
|
19
|
-
__controllers__:{}
|
|
20
|
-
}
|
|
21
|
-
if (Events) this._register_events(Events, details_setter, customizer);
|
|
22
|
-
}
|
|
23
|
-
_register_events(Events, details_setter, customizer, REGISTER_METHODES = true) {
|
|
24
|
-
const events = Events?.map(n => getEvent(n));
|
|
25
|
-
events?.forEach((event, i) => {
|
|
26
|
-
this.cache.preventDefault[event] = false;
|
|
27
|
-
this.cache.options[event] = {};
|
|
28
|
-
this.cache.paused[event] = false;
|
|
29
|
-
this.cache.__controllers__[event] = (e) =>
|
|
30
|
-
event_controller.call(this, e, event, details_setter, customizer);
|
|
31
|
-
if (REGISTER_METHODES) {
|
|
32
|
-
this[`on${Events[i]}`] = (callback) =>
|
|
33
|
-
this.__onEvent(event, this.cache.options[event], {}, callback);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
__onEvent(event, options, dispose, callback) {
|
|
39
|
-
if (!callback) return this;
|
|
40
|
-
this.cache.callbacks[event] = callback;
|
|
41
|
-
this.__handle(event, this.cache.__controllers__[event], options, dispose);
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
get targetElement(){
|
|
45
|
-
return this.target?.element;
|
|
46
|
-
}
|
|
47
|
-
get isParent(){
|
|
48
|
-
return this.target?.element === this.event?.srcElement;
|
|
49
|
-
}
|
|
50
|
-
get item(){
|
|
51
|
-
return this.target.find(n => n.element == this.event?.srcElement)?.[0];
|
|
52
|
-
}
|
|
53
|
-
get currentEvent(){
|
|
54
|
-
return this.cache.currentEvent;
|
|
55
|
-
}
|
|
56
|
-
get event(){
|
|
57
|
-
return this.cache.event;
|
|
58
|
-
}
|
|
59
|
-
get detail(){
|
|
60
|
-
return this.cache.event.detail
|
|
61
|
-
}
|
|
62
|
-
setTarget(UI){
|
|
63
|
-
this.target = UI;
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
__handle(event, handler, options){
|
|
67
|
-
this.targetElement?.addEventListener(event, handler, options);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
#override(method, ...events) {
|
|
71
|
-
const keys = events.length === 0 ? Object.keys(this.cache[method]) : events
|
|
72
|
-
keys.forEach(e => {
|
|
73
|
-
if (this.cache[method].hasOwnProperty(e)) this.cache[method][e] = true;
|
|
74
|
-
});
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
preventDefault(...events) {
|
|
78
|
-
return this.#override('preventDefault', ...events);
|
|
79
|
-
}
|
|
80
|
-
stopPropagation(...events) {
|
|
81
|
-
return this.#override('stopPropagation', ...events);
|
|
82
|
-
}
|
|
83
|
-
stopImmediatePropagation(...events) {
|
|
84
|
-
return this.#override('stopImmediatePropagation', ...events);
|
|
85
|
-
}
|
|
86
|
-
setEventOptions(event, options){
|
|
87
|
-
const evt = getEvent(event);
|
|
88
|
-
this.pause();
|
|
89
|
-
Object.assign(this.cache.options[evt], options);
|
|
90
|
-
this.resume();
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
pause(...events) {
|
|
94
|
-
return toggle_event_listener.call(this, 'removeEventListener', ...events)
|
|
95
|
-
}
|
|
96
|
-
resume(...events) {
|
|
97
|
-
return toggle_event_listener.call(this, 'addEventListener', ...events);
|
|
98
|
-
}
|
|
99
|
-
dispose(){
|
|
100
|
-
this.pause();
|
|
101
|
-
this.target.events[this.cache.signature] = null
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
export {
|
|
106
|
-
ZikoEvent,
|
|
107
|
-
getEvent
|
|
108
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|