@zcomponent/core 0.0.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/README.md +7 -0
- package/css/zcomponent.css +35 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/lib/actionbehavior.d.ts +20 -0
- package/lib/actionbehavior.js +32 -0
- package/lib/animation.d.ts +129 -0
- package/lib/animation.js +1 -0
- package/lib/behavior.d.ts +26 -0
- package/lib/behavior.js +10 -0
- package/lib/behaviors/LaunchURL.d.ts +12 -0
- package/lib/behaviors/LaunchURL.js +12 -0
- package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -0
- package/lib/behaviors/LogAnalyticsEvent.js +10 -0
- package/lib/behaviors/PlaySound.d.ts +12 -0
- package/lib/behaviors/PlaySound.js +18 -0
- package/lib/component.d.ts +22 -0
- package/lib/component.js +4 -0
- package/lib/components/DefaultLoader.d.ts +55 -0
- package/lib/components/DefaultLoader.js +112 -0
- package/lib/context.d.ts +28 -0
- package/lib/context.js +65 -0
- package/lib/contexts/analyticscontext.d.ts +9 -0
- package/lib/contexts/analyticscontext.js +17 -0
- package/lib/contexts/canvascontext.d.ts +15 -0
- package/lib/contexts/canvascontext.js +45 -0
- package/lib/contexts/cookieconsentcontext.d.ts +38 -0
- package/lib/contexts/cookieconsentcontext.js +63 -0
- package/lib/contexts/environmentcontext.d.ts +9 -0
- package/lib/contexts/environmentcontext.js +14 -0
- package/lib/contexts/loadcontext.d.ts +24 -0
- package/lib/contexts/loadcontext.js +94 -0
- package/lib/contexts/usereventcontext.d.ts +12 -0
- package/lib/contexts/usereventcontext.js +32 -0
- package/lib/data.d.ts +38 -0
- package/lib/data.js +240 -0
- package/lib/event.d.ts +24 -0
- package/lib/event.js +61 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +20 -0
- package/lib/interfaces.d.ts +67 -0
- package/lib/interfaces.js +1 -0
- package/lib/observable.d.ts +16 -0
- package/lib/observable.js +116 -0
- package/lib/props.d.ts +0 -0
- package/lib/props.js +4 -0
- package/lib/selectors.d.ts +13 -0
- package/lib/selectors.js +173 -0
- package/lib/types.d.ts +105 -0
- package/lib/types.js +295 -0
- package/lib/validators.d.ts +8 -0
- package/lib/validators.js +32 -0
- package/lib/zcomponent.d.ts +55 -0
- package/lib/zcomponent.js +226 -0
- package/package.json +40 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Event } from '../event';
|
|
3
|
+
export const AnalyticsContext = defineContextType((ctx) => {
|
|
4
|
+
const onEvent = new Event();
|
|
5
|
+
return {
|
|
6
|
+
onEvent,
|
|
7
|
+
logEvent: (name, params) => {
|
|
8
|
+
onEvent.emit(name, params);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
export function logEvent(mgr, name, params) {
|
|
13
|
+
return mgr.get(AnalyticsContext).logEvent(name, params);
|
|
14
|
+
}
|
|
15
|
+
export function useAnalyticsOnEvent(mgr) {
|
|
16
|
+
return mgr.get(AnalyticsContext).onEvent;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ContextManager } from '../context';
|
|
2
|
+
import { Event } from '../event';
|
|
3
|
+
import { Observable } from '../observable';
|
|
4
|
+
export interface CanvasContext {
|
|
5
|
+
canvas: HTMLCanvasElement;
|
|
6
|
+
onBeforeRender: Event<[number]>;
|
|
7
|
+
onAfterRender: Event<[number]>;
|
|
8
|
+
size: Observable<[number, number]>;
|
|
9
|
+
dispose: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const CanvasContext: import("../context").ContextTypeWithDefault<CanvasContext, [canvas?: HTMLCanvasElement | undefined]>;
|
|
12
|
+
export declare function useCanvas(mgr: ContextManager): HTMLCanvasElement;
|
|
13
|
+
export declare function useCanvasSize(mgr: ContextManager): Observable<[number, number]>;
|
|
14
|
+
export declare function useOnBeforeRender(mgr: ContextManager): Event<[number]>;
|
|
15
|
+
export declare function useOnAfterRender(mgr: ContextManager): Event<[number]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Event } from '../event';
|
|
3
|
+
import { Observable } from '../observable';
|
|
4
|
+
export const CanvasContext = defineContextType((ctx, canvas) => {
|
|
5
|
+
if (!canvas) {
|
|
6
|
+
canvas = document.createElement("canvas");
|
|
7
|
+
canvas.style.position = "fixed";
|
|
8
|
+
canvas.style.top = "0px";
|
|
9
|
+
canvas.style.left = "0px";
|
|
10
|
+
canvas.style.width = "100%";
|
|
11
|
+
canvas.style.height = "100%";
|
|
12
|
+
canvas.style.touchAction = "none";
|
|
13
|
+
document.body.append(canvas);
|
|
14
|
+
}
|
|
15
|
+
const size = new Observable([canvas.clientWidth, canvas.clientHeight]);
|
|
16
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (entry.target !== canvas)
|
|
19
|
+
continue;
|
|
20
|
+
size.value = [entry.contentRect.width, entry.contentRect.height];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
resizeObserver.observe(canvas);
|
|
24
|
+
return {
|
|
25
|
+
canvas,
|
|
26
|
+
onBeforeRender: new Event(),
|
|
27
|
+
onAfterRender: new Event(),
|
|
28
|
+
size,
|
|
29
|
+
dispose: () => {
|
|
30
|
+
resizeObserver.disconnect();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
export function useCanvas(mgr) {
|
|
35
|
+
return mgr.get(CanvasContext).canvas;
|
|
36
|
+
}
|
|
37
|
+
export function useCanvasSize(mgr) {
|
|
38
|
+
return mgr.get(CanvasContext).size;
|
|
39
|
+
}
|
|
40
|
+
export function useOnBeforeRender(mgr) {
|
|
41
|
+
return mgr.get(CanvasContext).onBeforeRender;
|
|
42
|
+
}
|
|
43
|
+
export function useOnAfterRender(mgr) {
|
|
44
|
+
return mgr.get(CanvasContext).onAfterRender;
|
|
45
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ContextManager } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export declare enum Status {
|
|
4
|
+
"unknown" = "unknown",
|
|
5
|
+
"initializing" = "initializing",
|
|
6
|
+
"initialized" = "initialized"
|
|
7
|
+
}
|
|
8
|
+
export declare enum ConsentStatus {
|
|
9
|
+
"unknown" = "unknown",
|
|
10
|
+
"granted" = "granted",
|
|
11
|
+
"rejected" = "rejected"
|
|
12
|
+
}
|
|
13
|
+
export interface Vendor {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
privacyPolicyUrl: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CookieConsentContext {
|
|
19
|
+
status: Observable<Status>;
|
|
20
|
+
functionalCookies: Observable<ConsentStatus>;
|
|
21
|
+
performanceCookies: Observable<ConsentStatus>;
|
|
22
|
+
marketingCookies: Observable<ConsentStatus>;
|
|
23
|
+
performanceVendors: Vendor[];
|
|
24
|
+
marketingVendors: Vendor[];
|
|
25
|
+
registerPerformanceVendor: (v: Vendor) => void;
|
|
26
|
+
registerMarketingVendor: (v: Vendor) => void;
|
|
27
|
+
showSettings: Observable<(() => void) | undefined>;
|
|
28
|
+
}
|
|
29
|
+
export declare const CookieConsentContext: import("../context").ContextTypeWithDefault<CookieConsentContext, []>;
|
|
30
|
+
export declare function useCookieConsentFunctional(mgr: ContextManager): Observable<ConsentStatus>;
|
|
31
|
+
export declare function useCookieConsentPerformance(mgr: ContextManager): Observable<ConsentStatus>;
|
|
32
|
+
export declare function useCookieConsentMarketing(mgr: ContextManager): Observable<ConsentStatus>;
|
|
33
|
+
export declare function useCookieConsentStatus(mgr: ContextManager): Observable<Status>;
|
|
34
|
+
export declare function registerPerformanceVendor(mgr: ContextManager, vendor: Vendor): void;
|
|
35
|
+
export declare function registerMarketingVendor(mgr: ContextManager, vendor: Vendor): void;
|
|
36
|
+
export declare function usePerformanceVendors(mgr: ContextManager): Vendor[];
|
|
37
|
+
export declare function useMarketingVendors(mgr: ContextManager): Vendor[];
|
|
38
|
+
export declare function useShowCookieSettings(mgr: ContextManager): Observable<(() => void) | undefined>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export var Status;
|
|
4
|
+
(function (Status) {
|
|
5
|
+
Status["unknown"] = "unknown";
|
|
6
|
+
Status["initializing"] = "initializing";
|
|
7
|
+
Status["initialized"] = "initialized";
|
|
8
|
+
})(Status || (Status = {}));
|
|
9
|
+
export var ConsentStatus;
|
|
10
|
+
(function (ConsentStatus) {
|
|
11
|
+
ConsentStatus["unknown"] = "unknown";
|
|
12
|
+
ConsentStatus["granted"] = "granted";
|
|
13
|
+
ConsentStatus["rejected"] = "rejected";
|
|
14
|
+
})(ConsentStatus || (ConsentStatus = {}));
|
|
15
|
+
export const CookieConsentContext = defineContextType((ctx) => {
|
|
16
|
+
const status = new Observable(Status.unknown);
|
|
17
|
+
const functionalCookies = new Observable(ConsentStatus.unknown);
|
|
18
|
+
const performanceCookies = new Observable(ConsentStatus.unknown);
|
|
19
|
+
const marketingCookies = new Observable(ConsentStatus.unknown);
|
|
20
|
+
const showSettings = new Observable(undefined);
|
|
21
|
+
const performanceVendors = [];
|
|
22
|
+
const marketingVendors = [];
|
|
23
|
+
const registerPerformanceVendor = (v) => performanceVendors.push(v);
|
|
24
|
+
const registerMarketingVendor = (v) => marketingVendors.push(v);
|
|
25
|
+
return {
|
|
26
|
+
status,
|
|
27
|
+
functionalCookies,
|
|
28
|
+
performanceCookies,
|
|
29
|
+
marketingCookies,
|
|
30
|
+
performanceVendors,
|
|
31
|
+
marketingVendors,
|
|
32
|
+
registerPerformanceVendor,
|
|
33
|
+
registerMarketingVendor,
|
|
34
|
+
showSettings
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
export function useCookieConsentFunctional(mgr) {
|
|
38
|
+
return mgr.get(CookieConsentContext).functionalCookies;
|
|
39
|
+
}
|
|
40
|
+
export function useCookieConsentPerformance(mgr) {
|
|
41
|
+
return mgr.get(CookieConsentContext).performanceCookies;
|
|
42
|
+
}
|
|
43
|
+
export function useCookieConsentMarketing(mgr) {
|
|
44
|
+
return mgr.get(CookieConsentContext).marketingCookies;
|
|
45
|
+
}
|
|
46
|
+
export function useCookieConsentStatus(mgr) {
|
|
47
|
+
return mgr.get(CookieConsentContext).status;
|
|
48
|
+
}
|
|
49
|
+
export function registerPerformanceVendor(mgr, vendor) {
|
|
50
|
+
return mgr.get(CookieConsentContext).registerPerformanceVendor(vendor);
|
|
51
|
+
}
|
|
52
|
+
export function registerMarketingVendor(mgr, vendor) {
|
|
53
|
+
return mgr.get(CookieConsentContext).registerMarketingVendor(vendor);
|
|
54
|
+
}
|
|
55
|
+
export function usePerformanceVendors(mgr) {
|
|
56
|
+
return mgr.get(CookieConsentContext).performanceVendors;
|
|
57
|
+
}
|
|
58
|
+
export function useMarketingVendors(mgr) {
|
|
59
|
+
return mgr.get(CookieConsentContext).marketingVendors;
|
|
60
|
+
}
|
|
61
|
+
export function useShowCookieSettings(mgr) {
|
|
62
|
+
return mgr.get(CookieConsentContext).showSettings;
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContextManager } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export interface EnvirontmentContext {
|
|
4
|
+
designTime: Observable<boolean>;
|
|
5
|
+
editTime: Observable<boolean>;
|
|
6
|
+
}
|
|
7
|
+
export declare const EnvironmentContext: import("../context").ContextTypeWithDefault<EnvirontmentContext, []>;
|
|
8
|
+
export declare function isDesignTime(ctx: ContextManager): boolean;
|
|
9
|
+
export declare function isEditTime(ctx: ContextManager): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export const EnvironmentContext = defineContextType(() => {
|
|
4
|
+
return {
|
|
5
|
+
designTime: new Observable(false),
|
|
6
|
+
editTime: new Observable(false)
|
|
7
|
+
};
|
|
8
|
+
});
|
|
9
|
+
export function isDesignTime(ctx) {
|
|
10
|
+
return ctx.get(EnvironmentContext).designTime.value;
|
|
11
|
+
}
|
|
12
|
+
export function isEditTime(ctx) {
|
|
13
|
+
return ctx.get(EnvironmentContext).editTime.value;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ContextManager } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export interface LoadContext {
|
|
4
|
+
isConstructed: Observable<boolean>;
|
|
5
|
+
isLoaded: Observable<boolean>;
|
|
6
|
+
isStarted: Observable<boolean>;
|
|
7
|
+
started: Promise<void>;
|
|
8
|
+
progressPercent: Observable<number>;
|
|
9
|
+
registerLoadable: (p: Promise<any>) => void;
|
|
10
|
+
start: () => void;
|
|
11
|
+
startWhenLoaded: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const LoadContext: import("../context").ContextTypeWithDefault<LoadContext, []>;
|
|
14
|
+
export declare function useIsLoaded(mgr: ContextManager): Observable<boolean>;
|
|
15
|
+
export declare function isLoaded(mgr: ContextManager): boolean;
|
|
16
|
+
export declare function useIsStarted(mgr: ContextManager): Observable<boolean>;
|
|
17
|
+
export declare function isStarted(mgr: ContextManager): boolean;
|
|
18
|
+
export declare function useIsConstructed(mgr: ContextManager): Observable<boolean>;
|
|
19
|
+
export declare function isConstructed(mgr: ContextManager): boolean;
|
|
20
|
+
export declare function useLoadPercent(mgr: ContextManager): Observable<number>;
|
|
21
|
+
export declare function registerLoadable(mgr: ContextManager, p: Promise<any>): void;
|
|
22
|
+
export declare function start(mgr: ContextManager): void;
|
|
23
|
+
export declare function startWhenLoaded(mgr: ContextManager): void;
|
|
24
|
+
export declare function started(mgr: ContextManager): Promise<void>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Observable } from '../observable';
|
|
3
|
+
export const LoadContext = defineContextType((ctx) => {
|
|
4
|
+
let totalLoadables = 0;
|
|
5
|
+
let loadedCount = 0;
|
|
6
|
+
const loadables = new Set();
|
|
7
|
+
const isConstructed = new Observable(false);
|
|
8
|
+
const isLoaded = new Observable(false);
|
|
9
|
+
const isStarted = new Observable(false);
|
|
10
|
+
const startWhenLoaded = new Observable(false);
|
|
11
|
+
const progressPercent = new Observable(0);
|
|
12
|
+
let startedResolve;
|
|
13
|
+
const started = new Promise(resolve => startedResolve = resolve);
|
|
14
|
+
const start = () => {
|
|
15
|
+
if (isStarted.value)
|
|
16
|
+
return;
|
|
17
|
+
isStarted.value = true;
|
|
18
|
+
startedResolve?.();
|
|
19
|
+
if (document.body)
|
|
20
|
+
document.body.classList.add("zcomponent-started");
|
|
21
|
+
};
|
|
22
|
+
const update = () => {
|
|
23
|
+
if (loadables.size > 0 && isLoaded.value === true) {
|
|
24
|
+
isLoaded.value = false;
|
|
25
|
+
totalLoadables = loadables.size;
|
|
26
|
+
loadedCount = 0;
|
|
27
|
+
}
|
|
28
|
+
if (loadables.size === 0 && isLoaded.value === false) {
|
|
29
|
+
isLoaded.value = true;
|
|
30
|
+
if (document.body)
|
|
31
|
+
document.body.classList.add("zcomponent-loaded");
|
|
32
|
+
}
|
|
33
|
+
progressPercent.value = isLoaded.value ? 100 : (100 * loadedCount / totalLoadables);
|
|
34
|
+
if (startWhenLoaded.value && isLoaded.value && !isStarted.value) {
|
|
35
|
+
start();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const registerLoadable = (p) => {
|
|
39
|
+
loadables.add(p);
|
|
40
|
+
totalLoadables++;
|
|
41
|
+
p.finally(() => {
|
|
42
|
+
loadedCount++;
|
|
43
|
+
loadables.delete(p);
|
|
44
|
+
update();
|
|
45
|
+
});
|
|
46
|
+
update();
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
isConstructed,
|
|
50
|
+
isLoaded,
|
|
51
|
+
isStarted,
|
|
52
|
+
started,
|
|
53
|
+
progressPercent,
|
|
54
|
+
registerLoadable,
|
|
55
|
+
start,
|
|
56
|
+
startWhenLoaded: () => {
|
|
57
|
+
startWhenLoaded.value = true;
|
|
58
|
+
update();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
export function useIsLoaded(mgr) {
|
|
63
|
+
return mgr.get(LoadContext).isLoaded;
|
|
64
|
+
}
|
|
65
|
+
export function isLoaded(mgr) {
|
|
66
|
+
return mgr.get(LoadContext).isLoaded.value;
|
|
67
|
+
}
|
|
68
|
+
export function useIsStarted(mgr) {
|
|
69
|
+
return mgr.get(LoadContext).isStarted;
|
|
70
|
+
}
|
|
71
|
+
export function isStarted(mgr) {
|
|
72
|
+
return mgr.get(LoadContext).isStarted.value;
|
|
73
|
+
}
|
|
74
|
+
export function useIsConstructed(mgr) {
|
|
75
|
+
return mgr.get(LoadContext).isConstructed;
|
|
76
|
+
}
|
|
77
|
+
export function isConstructed(mgr) {
|
|
78
|
+
return mgr.get(LoadContext).isConstructed.value;
|
|
79
|
+
}
|
|
80
|
+
export function useLoadPercent(mgr) {
|
|
81
|
+
return mgr.get(LoadContext).progressPercent;
|
|
82
|
+
}
|
|
83
|
+
export function registerLoadable(mgr, p) {
|
|
84
|
+
return mgr.get(LoadContext).registerLoadable(p);
|
|
85
|
+
}
|
|
86
|
+
export function start(mgr) {
|
|
87
|
+
return mgr.get(LoadContext).start();
|
|
88
|
+
}
|
|
89
|
+
export function startWhenLoaded(mgr) {
|
|
90
|
+
return mgr.get(LoadContext).startWhenLoaded();
|
|
91
|
+
}
|
|
92
|
+
export function started(mgr) {
|
|
93
|
+
return mgr.get(LoadContext).started;
|
|
94
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContextManager } from '../context';
|
|
2
|
+
import { Event as EventClass } from '../event';
|
|
3
|
+
import { Observable } from '../observable';
|
|
4
|
+
export interface UserEventContext {
|
|
5
|
+
onUserEvent: EventClass<[Event]>;
|
|
6
|
+
nextUserEvent: Observable<Promise<Event>>;
|
|
7
|
+
registerUserEvent: (evt: Event) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const UserEventContext: import("../context").ContextTypeWithDefault<UserEventContext, []>;
|
|
10
|
+
export declare function useOnUserEvent(mgr: ContextManager): EventClass<[Event]>;
|
|
11
|
+
export declare function nextUserEvent(mgr: ContextManager): Promise<Event>;
|
|
12
|
+
export declare function registerUserEvent(mgr: ContextManager, evt: Event): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineContextType } from '../context';
|
|
2
|
+
import { Event as EventClass } from '../event';
|
|
3
|
+
import { Observable } from '../observable';
|
|
4
|
+
export const UserEventContext = defineContextType((ctx) => {
|
|
5
|
+
const onUserEvent = new EventClass();
|
|
6
|
+
let resolveNextUserEvent;
|
|
7
|
+
const nextUserEvent = new Observable(new Promise(resolve => {
|
|
8
|
+
resolveNextUserEvent = resolve;
|
|
9
|
+
}), undefined, false);
|
|
10
|
+
const registerUserEvent = (evt) => {
|
|
11
|
+
const currentResolve = resolveNextUserEvent;
|
|
12
|
+
nextUserEvent.value = new Promise(resolve => {
|
|
13
|
+
resolveNextUserEvent = resolve;
|
|
14
|
+
});
|
|
15
|
+
currentResolve(evt);
|
|
16
|
+
onUserEvent.emit(evt);
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
onUserEvent,
|
|
20
|
+
nextUserEvent,
|
|
21
|
+
registerUserEvent
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
export function useOnUserEvent(mgr) {
|
|
25
|
+
return mgr.get(UserEventContext).onUserEvent;
|
|
26
|
+
}
|
|
27
|
+
export function nextUserEvent(mgr) {
|
|
28
|
+
return mgr.get(UserEventContext).nextUserEvent.value;
|
|
29
|
+
}
|
|
30
|
+
export function registerUserEvent(mgr, evt) {
|
|
31
|
+
return mgr.get(UserEventContext).registerUserEvent(evt);
|
|
32
|
+
}
|
package/lib/data.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BehaviorData, NodeData, ZComponentData } from "./interfaces";
|
|
2
|
+
export declare function addNode(zcomp: ZComponentData, info: NodeDataCombined, parentIndex?: number): void;
|
|
3
|
+
export declare function addBehavior(zcomp: ZComponentData, info: BehaviorDataCombined, parentIndex?: number): void;
|
|
4
|
+
export declare function addEntity(zcomp: ZComponentData, id: string, info: EntityDataCombined): void;
|
|
5
|
+
export declare function deleteNode(zcomp: ZComponentData, id: string): void;
|
|
6
|
+
export declare function deleteBehavior(zcomp: ZComponentData, id: string): void;
|
|
7
|
+
export declare function getNodeDataCombined(zcomp: ZComponentData, id: string): NodeDataCombined | undefined;
|
|
8
|
+
export declare function getBehaviorDataCombined(zcomp: ZComponentData, id: string): BehaviorDataCombined | undefined;
|
|
9
|
+
export declare function addNodeToParent(zcomp: ZComponentData, id: string, parentID: string, indx?: number): void;
|
|
10
|
+
export declare function removeNodeFromParent(zcomp: ZComponentData, id: string): void;
|
|
11
|
+
export declare function addBehaviorToNode(zcomp: ZComponentData, id: string, nodeID: string, indx?: number): void;
|
|
12
|
+
export declare function addNodeLabelToRegister(zcomp: ZComponentData, id: string): void;
|
|
13
|
+
export declare function removeNodeLabelFromRegister(zcomp: ZComponentData, id: string): void;
|
|
14
|
+
export declare function addNodeScriptNameToRegister(zcomp: ZComponentData, id: string): void;
|
|
15
|
+
export declare function removeNodeScriptNameFromRegister(zcomp: ZComponentData, id: string): void;
|
|
16
|
+
export declare function changeNodeLabel(zcomp: ZComponentData, id: string, newLabel: string | undefined): void;
|
|
17
|
+
export declare function changeNodeScriptName(zcomp: ZComponentData, id: string, newScriptName: string | undefined): void;
|
|
18
|
+
export declare function removeBehaviorFromNode(zcomp: ZComponentData, id: string): void;
|
|
19
|
+
export declare function findNodeParentAndIndex(zcomp: ZComponentData, id: string): [string, number] | undefined;
|
|
20
|
+
export declare function findBehaviorNodeAndIndex(zcomp: ZComponentData, id: string): [string, number] | undefined;
|
|
21
|
+
export declare function deleteEntity(zcomp: ZComponentData, id: string): void;
|
|
22
|
+
export declare function changeNodeID(zcomp: ZComponentData, id: string, newID: string): void;
|
|
23
|
+
export declare function forEachNodeAncestor(zcomp: ZComponentData, id: string, fn: (ancestorID: string) => void): void;
|
|
24
|
+
export declare function forEachNodeAndDescendant(zcomp: ZComponentData, id: string, fn: (nodeID: string, parent: [string, number] | undefined) => void): void;
|
|
25
|
+
export interface EntityDataCombined {
|
|
26
|
+
props: {
|
|
27
|
+
[id: string]: any;
|
|
28
|
+
};
|
|
29
|
+
constructorProps: {
|
|
30
|
+
[id: string]: any;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface NodeDataCombined extends EntityDataCombined {
|
|
34
|
+
data: NodeData;
|
|
35
|
+
}
|
|
36
|
+
export interface BehaviorDataCombined extends EntityDataCombined {
|
|
37
|
+
data: BehaviorData;
|
|
38
|
+
}
|
package/lib/data.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
export function addNode(zcomp, info, parentIndex) {
|
|
2
|
+
zcomp.nodes[info.data.id] = info.data;
|
|
3
|
+
addNodeLabelToRegister(zcomp, info.data.id);
|
|
4
|
+
addNodeScriptNameToRegister(zcomp, info.data.id);
|
|
5
|
+
addEntity(zcomp, info.data.id, info);
|
|
6
|
+
if (info.data.parent)
|
|
7
|
+
addNodeToParent(zcomp, info.data.id, info.data.parent, parentIndex);
|
|
8
|
+
}
|
|
9
|
+
export function addBehavior(zcomp, info, parentIndex) {
|
|
10
|
+
zcomp.behaviors[info.data.id] = info.data;
|
|
11
|
+
addEntity(zcomp, info.data.id, info);
|
|
12
|
+
if (info.data.nodeId)
|
|
13
|
+
addBehaviorToNode(zcomp, info.data.id, info.data.nodeId, parentIndex);
|
|
14
|
+
}
|
|
15
|
+
export function addEntity(zcomp, id, info) {
|
|
16
|
+
zcomp.entityProps[id] = info.props;
|
|
17
|
+
zcomp.entityConstructorProps[id] = info.constructorProps;
|
|
18
|
+
}
|
|
19
|
+
export function deleteNode(zcomp, id) {
|
|
20
|
+
removeNodeFromParent(zcomp, id);
|
|
21
|
+
deleteEntity(zcomp, id);
|
|
22
|
+
removeNodeLabelFromRegister(zcomp, id);
|
|
23
|
+
removeNodeScriptNameFromRegister(zcomp, id);
|
|
24
|
+
delete zcomp.nodes[id];
|
|
25
|
+
}
|
|
26
|
+
export function deleteBehavior(zcomp, id) {
|
|
27
|
+
removeBehaviorFromNode(zcomp, id);
|
|
28
|
+
deleteEntity(zcomp, id);
|
|
29
|
+
delete zcomp.behaviors[id];
|
|
30
|
+
}
|
|
31
|
+
export function getNodeDataCombined(zcomp, id) {
|
|
32
|
+
const data = zcomp.nodes[id];
|
|
33
|
+
if (!data)
|
|
34
|
+
return;
|
|
35
|
+
return {
|
|
36
|
+
data,
|
|
37
|
+
props: zcomp.entityProps[id] ?? {},
|
|
38
|
+
constructorProps: zcomp.entityConstructorProps[id] ?? {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function getBehaviorDataCombined(zcomp, id) {
|
|
42
|
+
const data = zcomp.behaviors[id];
|
|
43
|
+
if (!data)
|
|
44
|
+
return;
|
|
45
|
+
return {
|
|
46
|
+
data,
|
|
47
|
+
props: zcomp.entityProps[id] ?? {},
|
|
48
|
+
constructorProps: zcomp.entityConstructorProps[id] ?? {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function addNodeToParent(zcomp, id, parentID, indx) {
|
|
52
|
+
const node = zcomp.nodes[id];
|
|
53
|
+
if (!node)
|
|
54
|
+
return;
|
|
55
|
+
const parent = zcomp.nodes[parentID];
|
|
56
|
+
if (typeof parent !== 'object' || !Array.isArray(parent.children))
|
|
57
|
+
return;
|
|
58
|
+
parent.children.splice(indx ?? parent.children.length, 0, { id });
|
|
59
|
+
node.parent = parentID;
|
|
60
|
+
}
|
|
61
|
+
export function removeNodeFromParent(zcomp, id) {
|
|
62
|
+
const node = zcomp.nodes[id];
|
|
63
|
+
if (!node)
|
|
64
|
+
return;
|
|
65
|
+
const parent = findNodeParentAndIndex(zcomp, id);
|
|
66
|
+
if (!parent)
|
|
67
|
+
return;
|
|
68
|
+
const parentNode = zcomp.nodes[parent[0]];
|
|
69
|
+
if (typeof parentNode !== 'object' || !Array.isArray(parentNode.children))
|
|
70
|
+
return;
|
|
71
|
+
parentNode.children.splice(parent[1], 1);
|
|
72
|
+
delete node.parent;
|
|
73
|
+
}
|
|
74
|
+
export function addBehaviorToNode(zcomp, id, nodeID, indx) {
|
|
75
|
+
const behavior = zcomp.behaviors[id];
|
|
76
|
+
if (!behavior)
|
|
77
|
+
return;
|
|
78
|
+
if (!zcomp.behaviorsByNode[nodeID])
|
|
79
|
+
zcomp.behaviorsByNode[nodeID] = [];
|
|
80
|
+
if (!Array.isArray(zcomp.behaviorsByNode[nodeID]))
|
|
81
|
+
return;
|
|
82
|
+
zcomp.behaviorsByNode[nodeID].splice(indx ?? zcomp.behaviorsByNode[nodeID].length, 0, id);
|
|
83
|
+
behavior.nodeId = nodeID;
|
|
84
|
+
}
|
|
85
|
+
export function addNodeLabelToRegister(zcomp, id) {
|
|
86
|
+
const node = zcomp.nodes[id];
|
|
87
|
+
if (node?.label) {
|
|
88
|
+
if (zcomp.entitiesByLabel === undefined)
|
|
89
|
+
zcomp.entitiesByLabel = {};
|
|
90
|
+
if (zcomp.entitiesByLabel[node.label] === undefined)
|
|
91
|
+
zcomp.entitiesByLabel[node.label] = {};
|
|
92
|
+
zcomp.entitiesByLabel[node.label][node.id] = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function removeNodeLabelFromRegister(zcomp, id) {
|
|
96
|
+
const node = zcomp.nodes[id];
|
|
97
|
+
if (!node)
|
|
98
|
+
return;
|
|
99
|
+
if (node.label) {
|
|
100
|
+
if (zcomp.entitiesByLabel) {
|
|
101
|
+
delete zcomp.entitiesByLabel[node.label][id];
|
|
102
|
+
if (Object.keys(zcomp.entitiesByLabel[node.label]).length === 0) {
|
|
103
|
+
delete zcomp.entitiesByLabel[node.label];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function addNodeScriptNameToRegister(zcomp, id) {
|
|
109
|
+
const node = zcomp.nodes[id];
|
|
110
|
+
if (node?.scriptName) {
|
|
111
|
+
if (zcomp.entitiesByScriptName === undefined)
|
|
112
|
+
zcomp.entitiesByScriptName = {};
|
|
113
|
+
if (zcomp.entitiesByScriptName[node.scriptName] === undefined)
|
|
114
|
+
zcomp.entitiesByScriptName[node.scriptName] = {};
|
|
115
|
+
zcomp.entitiesByScriptName[node.scriptName][node.id] = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function removeNodeScriptNameFromRegister(zcomp, id) {
|
|
119
|
+
const node = zcomp.nodes[id];
|
|
120
|
+
if (!node)
|
|
121
|
+
return;
|
|
122
|
+
if (node.scriptName) {
|
|
123
|
+
if (zcomp.entitiesByScriptName) {
|
|
124
|
+
delete zcomp.entitiesByScriptName[node.scriptName][id];
|
|
125
|
+
if (Object.keys(zcomp.entitiesByScriptName[node.scriptName]).length === 0) {
|
|
126
|
+
delete zcomp.entitiesByScriptName[node.scriptName];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function changeNodeLabel(zcomp, id, newLabel) {
|
|
132
|
+
const node = zcomp.nodes[id];
|
|
133
|
+
if (!node)
|
|
134
|
+
return;
|
|
135
|
+
removeNodeLabelFromRegister(zcomp, id);
|
|
136
|
+
if (newLabel === undefined)
|
|
137
|
+
delete node.label;
|
|
138
|
+
else
|
|
139
|
+
node.label = newLabel;
|
|
140
|
+
addNodeLabelToRegister(zcomp, id);
|
|
141
|
+
}
|
|
142
|
+
export function changeNodeScriptName(zcomp, id, newScriptName) {
|
|
143
|
+
const node = zcomp.nodes[id];
|
|
144
|
+
if (!node)
|
|
145
|
+
return;
|
|
146
|
+
removeNodeScriptNameFromRegister(zcomp, id);
|
|
147
|
+
if (newScriptName === undefined)
|
|
148
|
+
delete node.scriptName;
|
|
149
|
+
else
|
|
150
|
+
node.scriptName = newScriptName;
|
|
151
|
+
addNodeScriptNameToRegister(zcomp, id);
|
|
152
|
+
}
|
|
153
|
+
export function removeBehaviorFromNode(zcomp, id) {
|
|
154
|
+
const behavior = zcomp.behaviors[id];
|
|
155
|
+
if (!behavior)
|
|
156
|
+
return;
|
|
157
|
+
const node = findBehaviorNodeAndIndex(zcomp, id);
|
|
158
|
+
if (!node)
|
|
159
|
+
return;
|
|
160
|
+
const nodeBehaviors = zcomp.behaviorsByNode[node[0]];
|
|
161
|
+
if (Array.isArray(nodeBehaviors))
|
|
162
|
+
nodeBehaviors.splice(node[1], 1);
|
|
163
|
+
delete behavior.nodeId;
|
|
164
|
+
}
|
|
165
|
+
export function findNodeParentAndIndex(zcomp, id) {
|
|
166
|
+
const node = zcomp.nodes[id];
|
|
167
|
+
if (!node)
|
|
168
|
+
return;
|
|
169
|
+
const parentID = node.parent;
|
|
170
|
+
if (!parentID)
|
|
171
|
+
return;
|
|
172
|
+
const parent = zcomp.nodes[parentID];
|
|
173
|
+
if (!parent)
|
|
174
|
+
return;
|
|
175
|
+
if (!Array.isArray(parent.children))
|
|
176
|
+
return;
|
|
177
|
+
const indx = parent.children.findIndex(val => val.id === id);
|
|
178
|
+
if (indx < 0)
|
|
179
|
+
return;
|
|
180
|
+
return [parentID, indx];
|
|
181
|
+
}
|
|
182
|
+
export function findBehaviorNodeAndIndex(zcomp, id) {
|
|
183
|
+
const behavior = zcomp.behaviors[id];
|
|
184
|
+
if (!behavior)
|
|
185
|
+
return;
|
|
186
|
+
const nodeID = behavior.nodeId;
|
|
187
|
+
if (!nodeID)
|
|
188
|
+
return;
|
|
189
|
+
const nodeBehaviors = zcomp.behaviorsByNode[nodeID];
|
|
190
|
+
if (!Array.isArray(nodeBehaviors))
|
|
191
|
+
return;
|
|
192
|
+
const indx = nodeBehaviors.indexOf(id);
|
|
193
|
+
if (indx < 0)
|
|
194
|
+
return;
|
|
195
|
+
return [nodeID, indx];
|
|
196
|
+
}
|
|
197
|
+
export function deleteEntity(zcomp, id) {
|
|
198
|
+
delete zcomp.entityProps[id];
|
|
199
|
+
delete zcomp.entityConstructorProps[id];
|
|
200
|
+
}
|
|
201
|
+
export function changeNodeID(zcomp, id, newID) {
|
|
202
|
+
if (id === newID)
|
|
203
|
+
return;
|
|
204
|
+
const node = zcomp.nodes[id];
|
|
205
|
+
if (!node)
|
|
206
|
+
return;
|
|
207
|
+
const parent = findNodeParentAndIndex(zcomp, id);
|
|
208
|
+
if (parent) {
|
|
209
|
+
const parentNode = zcomp.nodes[parent[0]];
|
|
210
|
+
if (parentNode) {
|
|
211
|
+
parentNode.children[parent[1]].id = newID;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
node.id = newID;
|
|
215
|
+
zcomp.entityProps[newID] = zcomp.entityProps[id];
|
|
216
|
+
delete zcomp.entityProps[id];
|
|
217
|
+
zcomp.entityConstructorProps[newID] = zcomp.entityConstructorProps[id];
|
|
218
|
+
delete zcomp.entityConstructorProps[id];
|
|
219
|
+
for (const child of node.children) {
|
|
220
|
+
const childNode = zcomp.nodes[child.id];
|
|
221
|
+
if (!childNode)
|
|
222
|
+
continue;
|
|
223
|
+
childNode.parent = newID;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export function forEachNodeAncestor(zcomp, id, fn) {
|
|
227
|
+
const parent = findNodeParentAndIndex(zcomp, id);
|
|
228
|
+
if (!parent)
|
|
229
|
+
return;
|
|
230
|
+
fn(parent[0]);
|
|
231
|
+
forEachNodeAncestor(zcomp, parent[0], fn);
|
|
232
|
+
}
|
|
233
|
+
export function forEachNodeAndDescendant(zcomp, id, fn) {
|
|
234
|
+
const node = zcomp.nodes[id];
|
|
235
|
+
if (!node)
|
|
236
|
+
return;
|
|
237
|
+
const parent = findNodeParentAndIndex(zcomp, id);
|
|
238
|
+
fn(id, parent);
|
|
239
|
+
node.children.forEach(v => forEachNodeAndDescendant(zcomp, v.id, fn));
|
|
240
|
+
}
|
package/lib/event.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Observable } from "./observable";
|
|
2
|
+
export declare class Event<Args extends Array<any> = []> {
|
|
3
|
+
hasBindings: Observable<boolean>;
|
|
4
|
+
private _funcs;
|
|
5
|
+
private _emitting;
|
|
6
|
+
private _toUnbind;
|
|
7
|
+
clear(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Bind new handler function.
|
|
10
|
+
* @param f - The callback function to be bound.
|
|
11
|
+
*/
|
|
12
|
+
bindfn(f: (...args: Args) => void): void;
|
|
13
|
+
/**
|
|
14
|
+
* Unbind an existing function.
|
|
15
|
+
* @param f - The callback function to be unbound.
|
|
16
|
+
*/
|
|
17
|
+
unbindfn(f: (...args: Args) => void): void;
|
|
18
|
+
/**
|
|
19
|
+
* Emit an event.
|
|
20
|
+
*
|
|
21
|
+
* @param a - The argument to pass to handler functions.
|
|
22
|
+
*/
|
|
23
|
+
emit(...args: Args): void;
|
|
24
|
+
}
|