@zcomponent/core 0.0.8 → 0.0.9
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/lib/actionbehavior.d.ts +6 -11
- package/lib/actionbehavior.js +11 -19
- package/lib/animation.d.ts +9 -9
- package/lib/behavior.d.ts +23 -12
- package/lib/behavior.js +27 -3
- package/lib/behaviors/PlaySound.d.ts +2 -1
- package/lib/behaviors/PlaySound.js +2 -2
- package/lib/component.d.ts +26 -17
- package/lib/component.js +45 -20
- package/lib/components/Children.d.ts +8 -0
- package/lib/components/Children.js +11 -0
- package/lib/components/DefaultLoader.d.ts +2 -2
- package/lib/components/DefaultLoader.js +19 -19
- package/lib/components/Gamepad.d.ts +68 -0
- package/lib/components/Gamepad.js +131 -0
- package/lib/components/LongLoad.d.ts +3 -3
- package/lib/components/LongLoad.js +2 -2
- package/lib/context.d.ts +39 -23
- package/lib/context.js +135 -46
- package/lib/contexts/analyticscontext.d.ts +3 -4
- package/lib/contexts/analyticscontext.js +10 -10
- package/lib/contexts/canvascontext.d.ts +12 -9
- package/lib/contexts/canvascontext.js +56 -51
- package/lib/contexts/cookieconsentcontext.d.ts +9 -10
- package/lib/contexts/cookieconsentcontext.js +19 -23
- package/lib/contexts/environmentcontext.d.ts +4 -5
- package/lib/contexts/environmentcontext.js +8 -7
- package/lib/contexts/gamepadcontext.d.ts +40 -0
- package/lib/contexts/gamepadcontext.js +99 -0
- package/lib/contexts/loadcontext.d.ts +15 -10
- package/lib/contexts/loadcontext.js +48 -51
- package/lib/contexts/tagcontext.d.ts +9 -10
- package/lib/contexts/tagcontext.js +27 -35
- package/lib/contexts/usereventcontext.d.ts +5 -5
- package/lib/contexts/usereventcontext.js +14 -19
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/interfaces.d.ts +9 -9
- package/lib/observable.d.ts +52 -8
- package/lib/observable.js +37 -0
- package/lib/selectors.js +4 -4
- package/lib/types.d.ts +3 -3
- package/lib/zcomponent.d.ts +13 -12
- package/lib/zcomponent.js +31 -38
- package/lib/zcomponentconstruction.d.ts +3 -0
- package/lib/zcomponentconstruction.js +7 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
3
|
export var Status;
|
|
4
4
|
(function (Status) {
|
|
@@ -12,28 +12,24 @@ export var ConsentStatus;
|
|
|
12
12
|
ConsentStatus["granted"] = "granted";
|
|
13
13
|
ConsentStatus["rejected"] = "rejected";
|
|
14
14
|
})(ConsentStatus || (ConsentStatus = {}));
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
registerMarketingVendor,
|
|
34
|
-
showSettings
|
|
35
|
-
};
|
|
36
|
-
});
|
|
15
|
+
export class CookieConsentContext extends Context {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.status = new Observable(Status.unknown);
|
|
19
|
+
this.functionalCookies = new Observable(ConsentStatus.unknown);
|
|
20
|
+
this.performanceCookies = new Observable(ConsentStatus.unknown);
|
|
21
|
+
this.marketingCookies = new Observable(ConsentStatus.unknown);
|
|
22
|
+
this.showSettings = new Observable(undefined);
|
|
23
|
+
this.performanceVendors = [];
|
|
24
|
+
this.marketingVendors = [];
|
|
25
|
+
}
|
|
26
|
+
registerPerformanceVendor(v) {
|
|
27
|
+
this.performanceVendors.push(v);
|
|
28
|
+
}
|
|
29
|
+
registerMarketingVendor(v) {
|
|
30
|
+
this.marketingVendors.push(v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
37
33
|
export function useCookieConsentFunctional(mgr) {
|
|
38
34
|
return mgr.get(CookieConsentContext).functionalCookies;
|
|
39
35
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ContextManager } from '../context';
|
|
1
|
+
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
-
export
|
|
4
|
-
designTime: Observable<boolean>;
|
|
5
|
-
editTime: Observable<boolean>;
|
|
3
|
+
export declare class EnvironmentContext extends Context {
|
|
4
|
+
designTime: Observable<boolean, never>;
|
|
5
|
+
editTime: Observable<boolean, never>;
|
|
6
6
|
}
|
|
7
|
-
export declare const EnvironmentContext: import("../context").ContextTypeWithDefault<EnvirontmentContext, []>;
|
|
8
7
|
export declare function isDesignTime(ctx: ContextManager): boolean;
|
|
9
8
|
export declare function isEditTime(ctx: ContextManager): boolean;
|
|
10
9
|
export declare function isDevelopmentBuild(ctx: ContextManager): boolean;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
export class EnvironmentContext extends Context {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.designTime = new Observable(false);
|
|
7
|
+
this.editTime = new Observable(false);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
9
10
|
export function isDesignTime(ctx) {
|
|
10
11
|
return ctx.get(EnvironmentContext).designTime.value;
|
|
11
12
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Context, ContextManager } from '../context';
|
|
2
|
+
import { Event } from '../event';
|
|
3
|
+
export declare enum GamepadAxis {
|
|
4
|
+
LeftStickHorizontal = "LeftStickHorizontal",
|
|
5
|
+
LeftStickVertical = "LeftStickVertical",
|
|
6
|
+
RightStickHorizontal = "RightStickHorizontal",
|
|
7
|
+
RightStickVertical = "RightStickVertical"
|
|
8
|
+
}
|
|
9
|
+
export declare enum GamepadButton {
|
|
10
|
+
South = "South",
|
|
11
|
+
East = "East",
|
|
12
|
+
West = "West",
|
|
13
|
+
North = "North",
|
|
14
|
+
ShoulderLeft = "ShoulderLeft",
|
|
15
|
+
ShoulderRight = "ShoulderRight",
|
|
16
|
+
TriggerLeft = "TriggerLeft",
|
|
17
|
+
TriggerRight = "TriggerRight",
|
|
18
|
+
Select = "Select",
|
|
19
|
+
Start = "Start",
|
|
20
|
+
StickLeft = "StickLeft",
|
|
21
|
+
StickRight = "StickRight",
|
|
22
|
+
DUp = "DUp",
|
|
23
|
+
DDown = "DDown",
|
|
24
|
+
DLeft = "DLeft",
|
|
25
|
+
DRight = "DRight",
|
|
26
|
+
Center = "Center"
|
|
27
|
+
}
|
|
28
|
+
export declare class GamepadContext extends Context {
|
|
29
|
+
onGamepadsChange: Event<[]>;
|
|
30
|
+
activeGamepads: Set<number>;
|
|
31
|
+
private _registeredGamepads;
|
|
32
|
+
constructor(contextManager: ContextManager);
|
|
33
|
+
private _update;
|
|
34
|
+
getGamepad(indx: number): Gamepad | null;
|
|
35
|
+
forGamepadsMatchingIndex(requestedIndex: number | undefined, fn: (gamepad: Gamepad) => void): void;
|
|
36
|
+
registerGamepad(indx: number, gamepad: Gamepad): void;
|
|
37
|
+
unregsiterGamepad(indx: number): void;
|
|
38
|
+
dispose(): never;
|
|
39
|
+
}
|
|
40
|
+
export declare function translateGamepadAxis(axis: GamepadAxis): number;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Context } from '../context';
|
|
2
|
+
import { Event } from '../event';
|
|
3
|
+
import { isDesignTime } from './environmentcontext';
|
|
4
|
+
export var GamepadAxis;
|
|
5
|
+
(function (GamepadAxis) {
|
|
6
|
+
GamepadAxis["LeftStickHorizontal"] = "LeftStickHorizontal";
|
|
7
|
+
GamepadAxis["LeftStickVertical"] = "LeftStickVertical";
|
|
8
|
+
GamepadAxis["RightStickHorizontal"] = "RightStickHorizontal";
|
|
9
|
+
GamepadAxis["RightStickVertical"] = "RightStickVertical";
|
|
10
|
+
})(GamepadAxis || (GamepadAxis = {}));
|
|
11
|
+
export var GamepadButton;
|
|
12
|
+
(function (GamepadButton) {
|
|
13
|
+
GamepadButton["South"] = "South";
|
|
14
|
+
GamepadButton["East"] = "East";
|
|
15
|
+
GamepadButton["West"] = "West";
|
|
16
|
+
GamepadButton["North"] = "North";
|
|
17
|
+
GamepadButton["ShoulderLeft"] = "ShoulderLeft";
|
|
18
|
+
GamepadButton["ShoulderRight"] = "ShoulderRight";
|
|
19
|
+
GamepadButton["TriggerLeft"] = "TriggerLeft";
|
|
20
|
+
GamepadButton["TriggerRight"] = "TriggerRight";
|
|
21
|
+
GamepadButton["Select"] = "Select";
|
|
22
|
+
GamepadButton["Start"] = "Start";
|
|
23
|
+
GamepadButton["StickLeft"] = "StickLeft";
|
|
24
|
+
GamepadButton["StickRight"] = "StickRight";
|
|
25
|
+
GamepadButton["DUp"] = "DUp";
|
|
26
|
+
GamepadButton["DDown"] = "DDown";
|
|
27
|
+
GamepadButton["DLeft"] = "DLeft";
|
|
28
|
+
GamepadButton["DRight"] = "DRight";
|
|
29
|
+
GamepadButton["Center"] = "Center";
|
|
30
|
+
})(GamepadButton || (GamepadButton = {}));
|
|
31
|
+
export class GamepadContext extends Context {
|
|
32
|
+
constructor(contextManager) {
|
|
33
|
+
super(contextManager, {});
|
|
34
|
+
this.onGamepadsChange = new Event();
|
|
35
|
+
this.activeGamepads = new Set();
|
|
36
|
+
this._registeredGamepads = new Map();
|
|
37
|
+
this._update = () => {
|
|
38
|
+
const gamepads = navigator.getGamepads();
|
|
39
|
+
let changes = false;
|
|
40
|
+
for (let i = 0; i < gamepads.length; i++) {
|
|
41
|
+
if (gamepads[i] === null && this.activeGamepads.has(i)) {
|
|
42
|
+
this.activeGamepads.delete(i);
|
|
43
|
+
changes = true;
|
|
44
|
+
}
|
|
45
|
+
else if (gamepads[i] !== null && !this.activeGamepads.has(i)) {
|
|
46
|
+
this.activeGamepads.add(i);
|
|
47
|
+
changes = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (changes)
|
|
51
|
+
this.onGamepadsChange.emit();
|
|
52
|
+
};
|
|
53
|
+
if (!isDesignTime(contextManager) && typeof navigator.getGamepads === 'function') {
|
|
54
|
+
window.addEventListener('gamepadconnected', this._update);
|
|
55
|
+
window.addEventListener('gamepaddisconnected', this._update);
|
|
56
|
+
}
|
|
57
|
+
this._update();
|
|
58
|
+
}
|
|
59
|
+
getGamepad(indx) {
|
|
60
|
+
return this._registeredGamepads.get(indx) ?? (navigator.getGamepads?.()?.[indx] || null);
|
|
61
|
+
}
|
|
62
|
+
forGamepadsMatchingIndex(requestedIndex, fn) {
|
|
63
|
+
for (const indx of this.activeGamepads) {
|
|
64
|
+
if (requestedIndex !== undefined && indx !== requestedIndex)
|
|
65
|
+
continue;
|
|
66
|
+
const gamepad = this.getGamepad(indx);
|
|
67
|
+
if (gamepad)
|
|
68
|
+
fn(gamepad);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
registerGamepad(indx, gamepad) {
|
|
72
|
+
this._registeredGamepads.set(indx, gamepad);
|
|
73
|
+
if (gamepad !== null)
|
|
74
|
+
this.activeGamepads.add(indx);
|
|
75
|
+
this.onGamepadsChange.emit();
|
|
76
|
+
}
|
|
77
|
+
unregsiterGamepad(indx) {
|
|
78
|
+
this._registeredGamepads.delete(indx);
|
|
79
|
+
this.activeGamepads.delete(indx);
|
|
80
|
+
this.onGamepadsChange.emit();
|
|
81
|
+
}
|
|
82
|
+
dispose() {
|
|
83
|
+
window.removeEventListener('gamepadconnected', this._update);
|
|
84
|
+
window.removeEventListener('gamepaddisconnected', this._update);
|
|
85
|
+
return super.dispose();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function translateGamepadAxis(axis) {
|
|
89
|
+
switch (axis) {
|
|
90
|
+
case GamepadAxis.LeftStickHorizontal:
|
|
91
|
+
return 0;
|
|
92
|
+
case GamepadAxis.LeftStickVertical:
|
|
93
|
+
return 1;
|
|
94
|
+
case GamepadAxis.RightStickHorizontal:
|
|
95
|
+
return 2;
|
|
96
|
+
case GamepadAxis.RightStickVertical:
|
|
97
|
+
return 3;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { ContextManager } from '../context';
|
|
1
|
+
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
-
export
|
|
4
|
-
isConstructed: Observable<boolean>;
|
|
5
|
-
isLoaded: Observable<boolean>;
|
|
6
|
-
isStarted: Observable<boolean>;
|
|
3
|
+
export declare class LoadContext extends Context {
|
|
4
|
+
isConstructed: Observable<boolean, never>;
|
|
5
|
+
isLoaded: Observable<boolean, never>;
|
|
6
|
+
isStarted: Observable<boolean, never>;
|
|
7
|
+
progressPercent: Observable<number, never>;
|
|
8
|
+
private _startedResolved;
|
|
7
9
|
started: Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
private _loadables;
|
|
11
|
+
private _startWhenLoaded;
|
|
12
|
+
private _totalLoadables;
|
|
13
|
+
private _loadedCount;
|
|
14
|
+
start(): void;
|
|
15
|
+
private _update;
|
|
16
|
+
startWhenLoaded(): void;
|
|
17
|
+
registerLoadable(p: Promise<any>): void;
|
|
12
18
|
}
|
|
13
|
-
export declare const LoadContext: import("../context").ContextTypeWithDefault<LoadContext, []>;
|
|
14
19
|
export declare function useIsLoaded(mgr: ContextManager): Observable<boolean, never>;
|
|
15
20
|
export declare function isLoaded(mgr: ContextManager): boolean;
|
|
16
21
|
export declare function useIsStarted(mgr: ContextManager): Observable<boolean, never>;
|
|
@@ -1,64 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
export class LoadContext extends Context {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.isConstructed = new Observable(false);
|
|
7
|
+
this.isLoaded = new Observable(false);
|
|
8
|
+
this.isStarted = new Observable(false);
|
|
9
|
+
this.progressPercent = new Observable(0);
|
|
10
|
+
this.started = new Promise(resolve => this._startedResolved = resolve);
|
|
11
|
+
this._loadables = new Set();
|
|
12
|
+
this._startWhenLoaded = false;
|
|
13
|
+
this._totalLoadables = 0;
|
|
14
|
+
this._loadedCount = 0;
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
if (this.isStarted.value)
|
|
16
18
|
return;
|
|
17
|
-
isStarted.value = true;
|
|
18
|
-
|
|
19
|
+
this.isStarted.value = true;
|
|
20
|
+
this._startedResolved?.();
|
|
19
21
|
if (document.body)
|
|
20
|
-
document.body.classList.add(
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
isLoaded.value = false;
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
document.body.classList.add('zcomponent-started');
|
|
23
|
+
}
|
|
24
|
+
_update() {
|
|
25
|
+
if (this._loadables.size > 0 && this.isLoaded.value === true) {
|
|
26
|
+
this.isLoaded.value = false;
|
|
27
|
+
this._totalLoadables = this._loadables.size;
|
|
28
|
+
this._loadedCount = 0;
|
|
27
29
|
}
|
|
28
|
-
if (
|
|
29
|
-
isLoaded.value = true;
|
|
30
|
+
if (this._loadables.size === 0 && this.isLoaded.value === false) {
|
|
31
|
+
this.isLoaded.value = true;
|
|
30
32
|
if (document.body)
|
|
31
33
|
document.body.classList.add("zcomponent-loaded");
|
|
32
34
|
}
|
|
33
|
-
progressPercent.value = isLoaded.value ? 100 : (100 *
|
|
34
|
-
if (
|
|
35
|
-
start();
|
|
35
|
+
this.progressPercent.value = this.isLoaded.value ? 100 : (100 * this._loadedCount / this._totalLoadables);
|
|
36
|
+
if (this._startWhenLoaded && this.isLoaded.value && !this.isStarted.value) {
|
|
37
|
+
this.start();
|
|
36
38
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
}
|
|
40
|
+
startWhenLoaded() {
|
|
41
|
+
this._startWhenLoaded = true;
|
|
42
|
+
this._update();
|
|
43
|
+
}
|
|
44
|
+
registerLoadable(p) {
|
|
45
|
+
if (this.disposed)
|
|
46
|
+
return;
|
|
47
|
+
this._loadables.add(p);
|
|
48
|
+
this._totalLoadables++;
|
|
41
49
|
p.finally(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
if (this.disposed)
|
|
51
|
+
return;
|
|
52
|
+
this._loadedCount++;
|
|
53
|
+
this._loadables.delete(p);
|
|
54
|
+
this._update();
|
|
45
55
|
});
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
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
|
-
});
|
|
56
|
+
this._update();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
62
59
|
export function useIsLoaded(mgr) {
|
|
63
60
|
return mgr.get(LoadContext).isLoaded;
|
|
64
61
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Component } from "../component";
|
|
2
|
-
import { ContextManager } from "../context";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ContextManager, Context } from "../context";
|
|
3
|
+
export declare class TagContext extends Context {
|
|
4
|
+
tagsByComponent: Map<Component<any, import("../component").ConstructorProps>, Set<string>>;
|
|
5
|
+
componentsByLocalTag: Map<string, Set<Component<any, import("../component").ConstructorProps>>>;
|
|
6
|
+
componentsByGlobalTag: Map<string, Set<Component<any, import("../component").ConstructorProps>>>;
|
|
7
|
+
registerComponent(component: Component, tags: string[]): void;
|
|
8
|
+
unregisterComponent(component: Component): void;
|
|
6
9
|
getComponentsByTag(tag: string): Set<Component>;
|
|
7
10
|
getComponentsByTags(tags: string[]): Set<Component>;
|
|
8
|
-
tagsByComponent: Map<Component, Set<string>>;
|
|
9
|
-
componentsByLocalTag: Map<string, Set<Component>>;
|
|
10
|
-
componentsByGlobalTag: Map<string, Set<Component>>;
|
|
11
11
|
}
|
|
12
|
-
export declare
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function getComponentsByTags(mgr: ContextManager, tags: string[]): Set<Component<import("../component").ConstructorProps, any>>;
|
|
12
|
+
export declare function getComponentsByTag(mgr: ContextManager, tag: string): Set<Component<any, import("../component").ConstructorProps>>;
|
|
13
|
+
export declare function getComponentsByTags(mgr: ContextManager, tags: string[]): Set<Component<any, import("../component").ConstructorProps>>;
|
|
@@ -1,62 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
unregisterComponent(component);
|
|
1
|
+
import { Context } from "../context";
|
|
2
|
+
export class TagContext extends Context {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.tagsByComponent = new Map();
|
|
6
|
+
this.componentsByLocalTag = new Map();
|
|
7
|
+
this.componentsByGlobalTag = new Map();
|
|
8
|
+
}
|
|
9
|
+
registerComponent(component, tags) {
|
|
10
|
+
this.unregisterComponent(component);
|
|
11
11
|
for (const tag of tags) {
|
|
12
|
-
const map = tag.startsWith('global:') ? componentsByGlobalTag : componentsByLocalTag;
|
|
12
|
+
const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
|
|
13
13
|
const set = map.get(tag) ?? new Set();
|
|
14
14
|
set.add(component);
|
|
15
15
|
map.set(tag, set);
|
|
16
16
|
}
|
|
17
|
-
tagsByComponent.set(component, new Set(tags));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
this.tagsByComponent.set(component, new Set(tags));
|
|
18
|
+
}
|
|
19
|
+
;
|
|
20
|
+
unregisterComponent(component) {
|
|
21
|
+
let tags = this.tagsByComponent.get(component);
|
|
21
22
|
if (!tags)
|
|
22
23
|
return;
|
|
23
24
|
for (const tag of tags.values()) {
|
|
24
|
-
const map = tag.startsWith('global:') ? componentsByGlobalTag : componentsByLocalTag;
|
|
25
|
+
const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
|
|
25
26
|
const entry = map.get(tag);
|
|
26
27
|
if (!entry)
|
|
27
28
|
continue;
|
|
28
29
|
entry.delete(component);
|
|
29
30
|
}
|
|
30
|
-
tagsByComponent.delete(component);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return ((tag.startsWith('global:') ? componentsByGlobalTag : componentsByLocalTag).get(tag)) ?? new Set();
|
|
34
|
-
}
|
|
35
|
-
|
|
31
|
+
this.tagsByComponent.delete(component);
|
|
32
|
+
}
|
|
33
|
+
getComponentsByTag(tag) {
|
|
34
|
+
return ((tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag).get(tag)) ?? new Set();
|
|
35
|
+
}
|
|
36
|
+
getComponentsByTags(tags) {
|
|
36
37
|
if (tags.length === 0)
|
|
37
38
|
return new Set();
|
|
38
39
|
if (tags.length === 1)
|
|
39
|
-
return getComponentsByTag(tags[0]);
|
|
40
|
+
return this.getComponentsByTag(tags[0]);
|
|
40
41
|
const ret = new Set();
|
|
41
42
|
for (const tag of tags) {
|
|
42
|
-
const map = tag.startsWith('global:') ? componentsByGlobalTag : componentsByLocalTag;
|
|
43
|
+
const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
|
|
43
44
|
const entries = map.get(tag);
|
|
44
45
|
if (!entries)
|
|
45
46
|
continue;
|
|
46
47
|
entries.forEach(entry => ret.add(entry));
|
|
47
48
|
}
|
|
48
49
|
return ret;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
tagsByComponent,
|
|
52
|
-
componentsByLocalTag,
|
|
53
|
-
componentsByGlobalTag,
|
|
54
|
-
getComponentsByTag,
|
|
55
|
-
getComponentsByTags,
|
|
56
|
-
registerComponent,
|
|
57
|
-
unregisterComponent,
|
|
58
|
-
};
|
|
59
|
-
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
60
52
|
export function getComponentsByTag(mgr, tag) {
|
|
61
53
|
return mgr.get(TagContext).getComponentsByTag(tag);
|
|
62
54
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ContextManager } from '../context';
|
|
1
|
+
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Event as EventClass } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
-
export
|
|
4
|
+
export declare class UserEventContext extends Context {
|
|
5
5
|
onUserEvent: EventClass<[Event]>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
private _resolveNextUserEvent;
|
|
7
|
+
nextUserEvent: Observable<Promise<Event>, never>;
|
|
8
|
+
registerUserEvent(evt: Event): void;
|
|
8
9
|
}
|
|
9
|
-
export declare const UserEventContext: import("../context").ContextTypeWithDefault<UserEventContext, []>;
|
|
10
10
|
export declare function useOnUserEvent(mgr: ContextManager): EventClass<[Event]>;
|
|
11
11
|
export declare function nextUserEvent(mgr: ContextManager): Promise<Event>;
|
|
12
12
|
export declare function registerUserEvent(mgr: ContextManager, evt: Event): void;
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '../context';
|
|
2
2
|
import { Event as EventClass } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const currentResolve =
|
|
12
|
-
nextUserEvent.value = new Promise(resolve => {
|
|
13
|
-
|
|
4
|
+
export class UserEventContext extends Context {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.onUserEvent = new EventClass();
|
|
8
|
+
this.nextUserEvent = new Observable(new Promise(resolve => this._resolveNextUserEvent = resolve));
|
|
9
|
+
}
|
|
10
|
+
registerUserEvent(evt) {
|
|
11
|
+
const currentResolve = this._resolveNextUserEvent;
|
|
12
|
+
this.nextUserEvent.value = new Promise(resolve => {
|
|
13
|
+
this._resolveNextUserEvent = resolve;
|
|
14
14
|
});
|
|
15
15
|
currentResolve(evt);
|
|
16
|
-
onUserEvent.emit(evt);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
onUserEvent,
|
|
20
|
-
nextUserEvent,
|
|
21
|
-
registerUserEvent
|
|
22
|
-
};
|
|
23
|
-
});
|
|
16
|
+
this.onUserEvent.emit(evt);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
24
19
|
export function useOnUserEvent(mgr) {
|
|
25
20
|
return mgr.get(UserEventContext).onUserEvent;
|
|
26
21
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export * from './contexts/cookieconsentcontext';
|
|
|
10
10
|
export * from './contexts/analyticscontext';
|
|
11
11
|
export * from './contexts/usereventcontext';
|
|
12
12
|
export * from './contexts/tagcontext';
|
|
13
|
+
export * from './contexts/gamepadcontext';
|
|
13
14
|
export * from './observable';
|
|
14
15
|
export * from './contexts/environmentcontext';
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './contexts/cookieconsentcontext';
|
|
|
10
10
|
export * from './contexts/analyticscontext';
|
|
11
11
|
export * from './contexts/usereventcontext';
|
|
12
12
|
export * from './contexts/tagcontext';
|
|
13
|
+
export * from './contexts/gamepadcontext';
|
|
13
14
|
export * from './observable';
|
|
14
15
|
export * from './contexts/environmentcontext';
|
|
15
16
|
const link = document.createElement('link');
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -2,25 +2,25 @@ import { Prop } from './types';
|
|
|
2
2
|
export interface ID {
|
|
3
3
|
id: string;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type Child = ID;
|
|
6
|
+
export type NodeByID = {
|
|
7
7
|
[id: string]: NodeData | undefined;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type PropsByID = {
|
|
10
10
|
[id: string]: {
|
|
11
11
|
[id: string]: any;
|
|
12
12
|
} | undefined;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type BehaviorByID = {
|
|
15
15
|
[id: string]: BehaviorData | undefined;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type Props = {
|
|
18
18
|
[id: string]: Prop;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
20
|
+
export type Import = string;
|
|
21
|
+
export type ParsedImport = [string, string];
|
|
22
|
+
export type ElementType = Import;
|
|
23
|
+
export type PropType = string;
|
|
24
24
|
export interface ZComponentData {
|
|
25
25
|
id: string;
|
|
26
26
|
nodes: NodeByID;
|