ziko 1.7.0 → 1.9.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 +458 -174
- package/dist/ziko.js +458 -174
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +453 -173
- 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/constructors/mixins/dom.js +1 -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-derived.js +24 -17
- 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/hooks/use-state.js +3 -1
- package/src/symbols/index.d.ts +39 -0
- package/src/symbols/index.js +5 -0
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
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",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {UIElement} from "
|
|
2
|
-
class
|
|
1
|
+
import {UIElement} from "../../mini/UIElement.js";
|
|
2
|
+
export class UISuspense extends UIElement{
|
|
3
3
|
constructor(fallback_ui, callback){
|
|
4
4
|
super({element : "div", name : "suspense"})
|
|
5
5
|
this.setAttr({
|
|
@@ -20,8 +20,4 @@ class ZikoUISuspense extends UIElement{
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const Suspense = (fallback_ui, callback) => new
|
|
24
|
-
export{
|
|
25
|
-
ZikoUISuspense,
|
|
26
|
-
Suspense
|
|
27
|
-
}
|
|
23
|
+
export const Suspense = (fallback_ui, callback) => new UISuspense(fallback_ui, callback);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {UIElement} from "
|
|
2
|
-
import {Matrix} from "
|
|
3
|
-
class
|
|
1
|
+
import {UIElement} from "../../../constructors/UIElement.js";
|
|
2
|
+
import {Matrix} from "../../../../math/matrix/index.js"
|
|
3
|
+
class UICanvas extends UIElement{
|
|
4
4
|
constructor(w,h){
|
|
5
5
|
super("canvas","canvas");
|
|
6
6
|
this.ctx = this.element?.getContext("2d");
|
|
@@ -121,7 +121,7 @@ class ZikoUICanvas extends UIElement{
|
|
|
121
121
|
}
|
|
122
122
|
clone(){
|
|
123
123
|
console.log(this.width)
|
|
124
|
-
const canvas=new
|
|
124
|
+
const canvas=new UICanvas();
|
|
125
125
|
canvas.items=this.items;
|
|
126
126
|
canvas.transformMatrix=this.transformMatrix;
|
|
127
127
|
canvas.axisMatrix=this.axisMatrix;
|
|
@@ -168,8 +168,8 @@ class ZikoUICanvas extends UIElement{
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
const Canvas=(w,h)=>new
|
|
171
|
+
const Canvas=(w,h)=>new UICanvas(w,h);
|
|
172
172
|
export{
|
|
173
|
-
|
|
173
|
+
UICanvas,
|
|
174
174
|
Canvas
|
|
175
175
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {UIElement} from "
|
|
2
|
-
class
|
|
1
|
+
import {UIElement} from "../../../constructors/UIElement.js";
|
|
2
|
+
class UISvg extends UIElement {
|
|
3
3
|
constructor(w=360,h=300) {
|
|
4
4
|
super("svg","svg");
|
|
5
5
|
//this.cache={};
|
|
@@ -62,8 +62,8 @@ class ZikoUISvg extends UIElement {
|
|
|
62
62
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const Svg =(w,h)=>new
|
|
65
|
+
const Svg =(w,h)=>new UISvg(w,h);
|
|
66
66
|
export{
|
|
67
67
|
Svg,
|
|
68
|
-
|
|
68
|
+
UISvg,
|
|
69
69
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './View/index.js';
|
|
2
|
+
export * from './Flex/index.js';
|
|
3
|
+
export * from './Suspense/index.js';
|
|
4
|
+
export * from './Swap/index.js';
|
|
5
|
+
export * from './Fragment/index.js';
|
|
6
|
+
export * from './For/index.js';
|
|
7
|
+
export * from './Switch/index.js';
|
|
8
|
+
|
|
9
|
+
export * from './wrappers/index.js'
|
|
10
|
+
export * from './graphics/index.js'
|
|
@@ -81,6 +81,7 @@ export async function __addItem__(adder, pusher, ...ele) {
|
|
|
81
81
|
// Fix Items Latter
|
|
82
82
|
if (ele[i] instanceof Function) {
|
|
83
83
|
if (isStateGetter(ele[i])) {
|
|
84
|
+
console.log({s : ele[i]()})
|
|
84
85
|
const getter = ele[i]();
|
|
85
86
|
ele[i] = text(getter.value);
|
|
86
87
|
getter._subscribe(
|
package/src/dom/index.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
export * from './constructors/UIElement.js'
|
|
2
2
|
export * from './constructors/UINode.js'
|
|
3
3
|
export * from './utils/index.js'
|
|
4
|
-
export * from './view/index.js'
|
|
5
4
|
export * from './tags/index.js';
|
|
6
5
|
export * from './text/index.js';
|
|
7
|
-
export * from './flex/index.js';
|
|
8
|
-
// export * from './grid/index.js';
|
|
9
|
-
export * from './suspense/index.js';
|
|
10
|
-
export * from './wrappers/index.js';
|
|
11
|
-
// export * from './graphics/index.js'
|
|
12
6
|
export * from './web-component/index.js'
|
|
13
|
-
export * from './logic/index.js'
|
|
14
|
-
|
|
15
7
|
export * from './components/index.js'
|
package/src/hooks/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type * from './use-ipc'
|
|
|
2
2
|
export type * from './use-storage.d.ts'
|
|
3
3
|
export type * from './use-state.d.ts'
|
|
4
4
|
export type * from './use-derived.d.ts'
|
|
5
|
+
export type * from './use-effect.d.ts'
|
|
5
6
|
export type * from './use-reactive.d.ts'
|
|
6
7
|
export type * from './use-thread.d.ts'
|
|
7
8
|
export type * from './use-event-emitter.d.ts'
|
package/src/hooks/index.js
CHANGED
package/src/hooks/use-derived.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
+
import { STATE_GETTER } from '../symbols/index.js';
|
|
2
|
+
|
|
1
3
|
export function useDerived(deriveFn, sources) {
|
|
2
4
|
let value = deriveFn(...sources.map(s => s().value));
|
|
3
5
|
const subscribers = new Set();
|
|
4
|
-
let paused = false;
|
|
5
6
|
|
|
6
|
-
sources.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
7
|
+
// const unsubscribers = sources.map(source => {
|
|
8
|
+
// const srcValue = source();
|
|
9
|
+
|
|
10
|
+
// return srcValue._subscribe(() => {
|
|
11
|
+
// const newVal = deriveFn(...sources.map(s => s().value));
|
|
12
|
+
|
|
13
|
+
// if (!Object.is(newVal, value)) {
|
|
14
|
+
// value = newVal;
|
|
15
|
+
// subscribers.forEach(fn => fn(value));
|
|
16
|
+
// }
|
|
17
|
+
// });
|
|
18
|
+
// });
|
|
19
|
+
|
|
20
|
+
const getter = () => ({
|
|
19
21
|
value,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
_subscribe: (fn) => {
|
|
23
|
+
subscribers.add(fn);
|
|
24
|
+
return () => subscribers.delete(fn);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
getter[STATE_GETTER] = true;
|
|
29
|
+
return getter
|
|
23
30
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StateGetter } from "./use-state.d.ts";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Executes a side effect initially and whenever one of the
|
|
6
|
+
* provided reactive state dependencies changes.
|
|
7
|
+
*
|
|
8
|
+
* The current values of the state dependencies are passed
|
|
9
|
+
* to the callback in the same order as the dependency array.
|
|
10
|
+
*
|
|
11
|
+
* @param callback Effect callback receiving the current dependency values.
|
|
12
|
+
* @param deps Reactive state getters to watch.
|
|
13
|
+
* @returns A function that unsubscribes the effect and runs its cleanup.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const [count, setCount] = useState(0);
|
|
17
|
+
*
|
|
18
|
+
* useEffect(
|
|
19
|
+
* count => {
|
|
20
|
+
* console.log("Count:", count);
|
|
21
|
+
* },
|
|
22
|
+
* [count]
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // Count: 0
|
|
26
|
+
*
|
|
27
|
+
* setCount(1);
|
|
28
|
+
* // Count: 1
|
|
29
|
+
*
|
|
30
|
+
* setCount(2);
|
|
31
|
+
* // Count: 2
|
|
32
|
+
*
|
|
33
|
+
* setCount(3);
|
|
34
|
+
* // Count: 3
|
|
35
|
+
*/
|
|
36
|
+
export declare function useEffect<T extends readonly unknown[]>(
|
|
37
|
+
callback: (...values: T) => void | (() => void),
|
|
38
|
+
deps: { [K in keyof T]: StateGetter<T[K]> }
|
|
39
|
+
): () => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isStateGetter } from "./use-state.js";
|
|
2
|
+
|
|
3
|
+
export const useEffect = (callback, deps = []) =>{
|
|
4
|
+
const states = deps.filter(isStateGetter);
|
|
5
|
+
|
|
6
|
+
let cleanup;
|
|
7
|
+
|
|
8
|
+
const execute = () => {
|
|
9
|
+
// Cleanup previous effect
|
|
10
|
+
if (typeof cleanup === "function") {
|
|
11
|
+
cleanup();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Read current state values
|
|
15
|
+
const values = states.map(state => state().value);
|
|
16
|
+
|
|
17
|
+
// Execute effect
|
|
18
|
+
cleanup = callback(...values);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Subscribe to states
|
|
22
|
+
const unsubscribers = states.map(state =>
|
|
23
|
+
state()._subscribe(execute)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Initial execution
|
|
27
|
+
execute();
|
|
28
|
+
|
|
29
|
+
// Return effect cleanup
|
|
30
|
+
return () => {
|
|
31
|
+
unsubscribers.forEach(unsubscribe => {
|
|
32
|
+
unsubscribe();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (typeof cleanup === "function") {
|
|
36
|
+
cleanup();
|
|
37
|
+
cleanup = undefined;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/hooks/use-state.d.ts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
+
export declare const STATE_GETTER: unique symbol;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reactive state getter.
|
|
5
|
+
*/
|
|
6
|
+
export type StateGetter<T> = (() => {
|
|
7
|
+
value: T;
|
|
8
|
+
_subscribe: (fn: (value: T) => void) => () => void;
|
|
9
|
+
}) & {
|
|
10
|
+
[STATE_GETTER]: true;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a reactive state.
|
|
15
|
+
*
|
|
16
|
+
* @param initialValue Initial state value.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const [count, setCount] = useState(0);
|
|
20
|
+
*/
|
|
1
21
|
export function useState<T>(
|
|
2
22
|
initialValue: T
|
|
3
23
|
): [
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
value: T;
|
|
7
|
-
isStateGetter: () => true;
|
|
8
|
-
_subscribe: (fn: (value: T) => void) => void;
|
|
9
|
-
},
|
|
24
|
+
/** Getter function */
|
|
25
|
+
StateGetter<T>,
|
|
10
26
|
|
|
11
|
-
/**
|
|
27
|
+
/** Setter function */
|
|
12
28
|
(newValue: T | ((prev: T) => T)) => void,
|
|
13
29
|
|
|
14
|
-
/**
|
|
30
|
+
/** Controller */
|
|
15
31
|
{
|
|
16
32
|
pause: () => void;
|
|
17
33
|
resume: () => void;
|
|
@@ -21,5 +37,7 @@ export function useState<T>(
|
|
|
21
37
|
}
|
|
22
38
|
];
|
|
23
39
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a value is a state getter.
|
|
42
|
+
*/
|
|
43
|
+
export function isStateGetter(arg: unknown): arg is StateGetter<unknown>;
|
package/src/hooks/use-state.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// if (!globalThis.__Ziko__) __init__global__();
|
|
4
4
|
|
|
5
|
-
export const STATE_GETTER = Symbol.for("ziko.stateGetter");
|
|
5
|
+
// export const STATE_GETTER = Symbol.for("ziko.stateGetter");
|
|
6
|
+
|
|
7
|
+
import {STATE_GETTER} from '../symbols/index.js'
|
|
6
8
|
|
|
7
9
|
export function useState(initialValue) {
|
|
8
10
|
const state = {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime brand identifying a ZikoJS `mapfun` function.
|
|
3
|
+
*
|
|
4
|
+
* Used for runtime type detection without importing the `mapfun`
|
|
5
|
+
* implementation, helping prevent circular dependencies.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAPFUN: unique symbol;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Runtime brand identifying a ZikoJS `Complex` instance.
|
|
11
|
+
*
|
|
12
|
+
* Used for nominal runtime type detection without importing the
|
|
13
|
+
* `Complex` class directly.
|
|
14
|
+
*/
|
|
15
|
+
export declare const COMPLEX: unique symbol;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Runtime brand identifying a ZikoJS `Matrix` instance.
|
|
19
|
+
*
|
|
20
|
+
* Used for nominal runtime type detection without importing the
|
|
21
|
+
* `Matrix` class directly.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MATRIX: unique symbol;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Runtime brand identifying a ZikoJS `UIElement` instance.
|
|
27
|
+
*
|
|
28
|
+
* Used to detect UI elements without creating a dependency on the
|
|
29
|
+
* `UIElement` implementation.
|
|
30
|
+
*/
|
|
31
|
+
export declare const UIELEMENT: unique symbol;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Runtime brand identifying a ZikoJS state getter.
|
|
35
|
+
*
|
|
36
|
+
* Used by hooks and UI components to recognize state getters without
|
|
37
|
+
* importing the state implementation.
|
|
38
|
+
*/
|
|
39
|
+
export declare const STATE_GETTER: unique symbol;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const MAPFUN = Symbol.for('ziko/math/MAPFUN');
|
|
2
|
+
export const COMPLEX = Symbol.for('ziko/math/COMPLEX');
|
|
3
|
+
export const MATRIX = Symbol.for('ziko/math/MATRIX');
|
|
4
|
+
export const UIELEMENT = Symbol.for('ziko/dom/UIELEMENT');
|
|
5
|
+
export const STATE_GETTER = Symbol.for("ziko/hooks/STATE_GETTER");
|
package/src/dom/logic/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './switch/index.js'
|
package/src/dom/view/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UIElement } from "../constructors/UIElement.js";
|
|
2
|
-
class UIView extends UIElement{
|
|
3
|
-
constructor(...items){
|
|
4
|
-
super({element : 'div', name : 'view'})
|
|
5
|
-
this.append(...items)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const View = (...items) => new UIView(...items);
|
|
10
|
-
export{
|
|
11
|
-
View,
|
|
12
|
-
UIView
|
|
13
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
|
|
3
|
-
export class CoordinatesBasedEvent extends ZikoEvent{
|
|
4
|
-
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
5
|
-
super(signature, target, Events, details_setter, customizer)
|
|
6
|
-
Object.assign(this.cache,{
|
|
7
|
-
useNormalisedCoordinates : false
|
|
8
|
-
})
|
|
9
|
-
this.isDown = false;
|
|
10
|
-
this.isMoving = false;
|
|
11
|
-
this.dx = 0;
|
|
12
|
-
this.dy = 0;
|
|
13
|
-
this.mx = 0;
|
|
14
|
-
this.my = 0;
|
|
15
|
-
this.ux = 0;
|
|
16
|
-
this.uy = 0;
|
|
17
|
-
}
|
|
18
|
-
get isDragging(){
|
|
19
|
-
return this.isDown && this.isMoving
|
|
20
|
-
}
|
|
21
|
-
useNormalisedCoordinates(enable = true){
|
|
22
|
-
this.cache.useNormalisedCoordinates = enable;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
class ZikoCustomEvent extends ZikoEvent{
|
|
3
|
-
constructor(target, events, customizer){
|
|
4
|
-
super('custom', target, events, details_setter, customizer)
|
|
5
|
-
}
|
|
6
|
-
_register_events(events){
|
|
7
|
-
super._register_events(events, null, null, false);
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
emit(event_name, detail = {}){
|
|
11
|
-
const event = new CustomEvent(event_name, {
|
|
12
|
-
detail,
|
|
13
|
-
bubbles: true,
|
|
14
|
-
cancelable: true
|
|
15
|
-
});
|
|
16
|
-
this.targetElement.dispatchEvent(event);
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
on(event_name, ...callbacks){
|
|
20
|
-
if(!this.cache.options.hasOwnProperty(event_name)) this._register_events([event_name]);
|
|
21
|
-
this.__onEvent(event_name, this.cache.options[event_name], {}, ...callbacks);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function details_setter(){
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const bind_custom_event = (target, events, customizer) => new ZikoCustomEvent(target, events, customizer)
|
|
29
|
-
|
|
30
|
-
export{
|
|
31
|
-
bind_custom_event,
|
|
32
|
-
ZikoCustomEvent
|
|
33
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { ZikoEvent } from "../ziko-event.js";
|
|
2
|
-
import { EventsMap } from "../events-map/index.js";
|
|
3
|
-
import {
|
|
4
|
-
ptr_details_setter,
|
|
5
|
-
key_details_setter,
|
|
6
|
-
mouse_details_setter,
|
|
7
|
-
touch_details_setter
|
|
8
|
-
} from '../details-setter/index.js'
|
|
9
|
-
import {
|
|
10
|
-
CoordinatesBasedEvent
|
|
11
|
-
} from './coordinates-based-event.js'
|
|
12
|
-
import {
|
|
13
|
-
register_click_away_event,
|
|
14
|
-
register_view_event,
|
|
15
|
-
register_swipe_event
|
|
16
|
-
} from "../custom-events-registry/index.js";
|
|
17
|
-
|
|
18
|
-
export const bind_click_event = (target, customizer) => {
|
|
19
|
-
register_click_away_event(target.element)
|
|
20
|
-
return new ZikoEvent(
|
|
21
|
-
'click',
|
|
22
|
-
target,
|
|
23
|
-
EventsMap.Click,
|
|
24
|
-
null,
|
|
25
|
-
customizer
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
export const bind_clipboard_event = (target, customizer) => new ZikoEvent(
|
|
29
|
-
'clipboard',
|
|
30
|
-
target,
|
|
31
|
-
EventsMap.Clipboard,
|
|
32
|
-
null,
|
|
33
|
-
customizer
|
|
34
|
-
);
|
|
35
|
-
export const bind_drag_event = (target, customizer) => new ZikoEvent(
|
|
36
|
-
'drag',
|
|
37
|
-
target,
|
|
38
|
-
EventsMap.Drag,
|
|
39
|
-
null,
|
|
40
|
-
customizer
|
|
41
|
-
);
|
|
42
|
-
export const bind_focus_event = (target, customizer) => new ZikoEvent(
|
|
43
|
-
'focus',
|
|
44
|
-
target,
|
|
45
|
-
EventsMap.Focus,
|
|
46
|
-
null,
|
|
47
|
-
customizer
|
|
48
|
-
);
|
|
49
|
-
export const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
50
|
-
'key',
|
|
51
|
-
target,
|
|
52
|
-
EventsMap.Key,
|
|
53
|
-
key_details_setter,
|
|
54
|
-
customizer
|
|
55
|
-
);
|
|
56
|
-
export const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
57
|
-
'mouse',
|
|
58
|
-
target,
|
|
59
|
-
EventsMap.Mouse,
|
|
60
|
-
mouse_details_setter,
|
|
61
|
-
customizer
|
|
62
|
-
);
|
|
63
|
-
export const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
64
|
-
'ptr',
|
|
65
|
-
target,
|
|
66
|
-
EventsMap.Ptr,
|
|
67
|
-
ptr_details_setter,
|
|
68
|
-
customizer
|
|
69
|
-
);
|
|
70
|
-
export const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
71
|
-
'touch',
|
|
72
|
-
target,
|
|
73
|
-
EventsMap.Touch,
|
|
74
|
-
touch_details_setter,
|
|
75
|
-
customizer
|
|
76
|
-
);
|
|
77
|
-
export const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
78
|
-
'wheel',
|
|
79
|
-
target,
|
|
80
|
-
EventsMap.Wheel,
|
|
81
|
-
null,
|
|
82
|
-
customizer
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
export const bind_view_event = (target, customizer) => {
|
|
86
|
-
register_view_event(target.element)
|
|
87
|
-
return new ZikoEvent(
|
|
88
|
-
'view',
|
|
89
|
-
target,
|
|
90
|
-
EventsMap.View,
|
|
91
|
-
null,
|
|
92
|
-
customizer
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const bind_swipe_event = (target, customizer) => {
|
|
97
|
-
register_swipe_event(target.element)
|
|
98
|
-
return new ZikoEvent(
|
|
99
|
-
'swipe',
|
|
100
|
-
target,
|
|
101
|
-
EventsMap.Swipe,
|
|
102
|
-
null,
|
|
103
|
-
customizer
|
|
104
|
-
)
|
|
105
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
class ClickAwayEvent extends Event {
|
|
2
|
-
constructor(originalEvent, targetElement) {
|
|
3
|
-
super("clickaway", { bubbles: true, cancelable: true });
|
|
4
|
-
this.originalEvent = originalEvent;
|
|
5
|
-
this.targetElement = targetElement;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function register_click_away_event(element) {
|
|
10
|
-
function handler(e) {
|
|
11
|
-
if (!element.contains(e.target)) {
|
|
12
|
-
const clickAwayEvent = new ClickAwayEvent(e, element);
|
|
13
|
-
element.dispatchEvent(clickAwayEvent);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
globalThis?.document?.addEventListener("click", handler);
|
|
18
|
-
|
|
19
|
-
return () => globalThis?.document?.removeEventListener("click", handler);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export{
|
|
24
|
-
ClickAwayEvent,
|
|
25
|
-
register_click_away_event
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// // Example usage
|
|
29
|
-
// const box = document.querySelector("#my-box");
|
|
30
|
-
|
|
31
|
-
// const stop = listenClickAway(box);
|
|
32
|
-
|
|
33
|
-
// box.addEventListener("clickaway", (e) => {
|
|
34
|
-
// console.log("Clicked outside box!", e);
|
|
35
|
-
// });
|
|
36
|
-
|
|
37
|
-
// // later, you can stop listening:
|
|
38
|
-
// // stop();
|