@zcomponent/core 0.0.6 → 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.
Files changed (47) hide show
  1. package/lib/actionbehavior.d.ts +12 -8
  2. package/lib/actionbehavior.js +24 -16
  3. package/lib/animation.d.ts +9 -9
  4. package/lib/behavior.d.ts +25 -12
  5. package/lib/behavior.js +34 -3
  6. package/lib/behaviors/PlaySound.d.ts +2 -1
  7. package/lib/behaviors/PlaySound.js +3 -3
  8. package/lib/component.d.ts +46 -17
  9. package/lib/component.js +85 -17
  10. package/lib/components/Children.d.ts +8 -0
  11. package/lib/components/Children.js +11 -0
  12. package/lib/components/DefaultLoader.d.ts +6 -6
  13. package/lib/components/DefaultLoader.js +20 -20
  14. package/lib/components/Gamepad.d.ts +68 -0
  15. package/lib/components/Gamepad.js +131 -0
  16. package/lib/components/LongLoad.d.ts +5 -5
  17. package/lib/components/LongLoad.js +2 -2
  18. package/lib/context.d.ts +39 -23
  19. package/lib/context.js +135 -46
  20. package/lib/contexts/analyticscontext.d.ts +3 -4
  21. package/lib/contexts/analyticscontext.js +10 -10
  22. package/lib/contexts/canvascontext.d.ts +12 -9
  23. package/lib/contexts/canvascontext.js +56 -51
  24. package/lib/contexts/cookieconsentcontext.d.ts +9 -10
  25. package/lib/contexts/cookieconsentcontext.js +19 -23
  26. package/lib/contexts/environmentcontext.d.ts +4 -5
  27. package/lib/contexts/environmentcontext.js +8 -7
  28. package/lib/contexts/gamepadcontext.d.ts +40 -0
  29. package/lib/contexts/gamepadcontext.js +99 -0
  30. package/lib/contexts/loadcontext.d.ts +15 -10
  31. package/lib/contexts/loadcontext.js +48 -51
  32. package/lib/contexts/tagcontext.d.ts +13 -0
  33. package/lib/contexts/tagcontext.js +57 -0
  34. package/lib/contexts/usereventcontext.d.ts +5 -5
  35. package/lib/contexts/usereventcontext.js +14 -19
  36. package/lib/index.d.ts +2 -0
  37. package/lib/index.js +2 -0
  38. package/lib/interfaces.d.ts +9 -9
  39. package/lib/observable.d.ts +52 -8
  40. package/lib/observable.js +37 -0
  41. package/lib/selectors.js +4 -4
  42. package/lib/types.d.ts +3 -3
  43. package/lib/zcomponent.d.ts +13 -12
  44. package/lib/zcomponent.js +31 -38
  45. package/lib/zcomponentconstruction.d.ts +3 -0
  46. package/lib/zcomponentconstruction.js +7 -0
  47. package/package.json +3 -4
@@ -1,58 +1,63 @@
1
- import { defineContextType } from '../context';
1
+ import { Context } from '../context';
2
2
  import { Event } from '../event';
3
3
  import { Observable } from '../observable';
4
- export const CanvasContext = defineContextType((ctx, canvas, options) => {
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 overlayDefault = options?.overlay ?? document.createElement('div');
16
- overlayDefault.id = 'zcomponent-overlay';
17
- if (!options?.overlay) {
18
- document.body.append(overlayDefault);
19
- }
20
- const size = new Observable([canvas.clientWidth, canvas.clientHeight]);
21
- const resizeObserver = new ResizeObserver(entries => {
22
- for (const entry of entries) {
23
- if (entry.target !== canvas)
24
- continue;
25
- size.value = [entry.contentRect.width, entry.contentRect.height];
4
+ export class CanvasContext extends Context {
5
+ constructor(contextManager, constructorProps) {
6
+ super(contextManager, constructorProps);
7
+ this.constructorProps = constructorProps;
8
+ this.onBeforeRender = new Event();
9
+ this.onAfterRender = new Event();
10
+ this._resizeObserver = new ResizeObserver(entries => {
11
+ for (const entry of entries) {
12
+ if (entry.target !== this.canvas)
13
+ continue;
14
+ this.size.value = [entry.contentRect.width, entry.contentRect.height];
15
+ }
16
+ });
17
+ if (!constructorProps.canvas) {
18
+ this.canvas = document.createElement("canvas");
19
+ this.canvas.style.position = "fixed";
20
+ this.canvas.style.top = "0px";
21
+ this.canvas.style.left = "0px";
22
+ this.canvas.style.width = "100%";
23
+ this.canvas.style.height = "100%";
24
+ this.canvas.style.touchAction = "none";
25
+ document.body.append(this.canvas);
26
+ }
27
+ else {
28
+ this.canvas = constructorProps.canvas;
26
29
  }
27
- });
28
- resizeObserver.observe(canvas);
29
- const onBeforeRender = new Event();
30
- let lastRect;
31
- onBeforeRender.bindfn(() => {
32
- const rect = canvas.getBoundingClientRect();
33
- if (lastRect && lastRect.top === rect.top && lastRect.left === rect.left && lastRect.width === rect.width && lastRect.height === rect.height)
34
- return;
35
- overlayDefault.style.top = rect.top.toString() + 'px';
36
- overlayDefault.style.left = rect.left.toString() + 'px';
37
- overlayDefault.style.width = rect.width.toString() + 'px';
38
- overlayDefault.style.height = rect.height.toString() + 'px';
39
- lastRect = rect;
40
- });
41
- const onAfterRender = new Event();
42
- return {
43
- canvas,
44
- onBeforeRender,
45
- onAfterRender,
46
- size,
47
- overlayDefault,
48
- overlay: new Observable(overlayDefault, undefined, false),
49
- dispose: () => {
50
- onBeforeRender.clear();
51
- onAfterRender.clear();
52
- resizeObserver.disconnect();
30
+ this.overlayDefault = constructorProps.overlay ?? document.createElement('div');
31
+ this.overlayDefault.id = 'zcomponent-overlay';
32
+ if (!constructorProps.overlay) {
33
+ document.body.append(this.overlayDefault);
53
34
  }
54
- };
55
- });
35
+ this.overlay = new Observable(this.overlayDefault, undefined, false);
36
+ this.size = new Observable([this.canvas.clientWidth, this.canvas.clientHeight]);
37
+ this._resizeObserver.observe(this.canvas);
38
+ let lastRect;
39
+ this.onBeforeRender.bindfn(() => {
40
+ const rect = this.canvas.getBoundingClientRect();
41
+ if (lastRect && lastRect.top === rect.top && lastRect.left === rect.left && lastRect.width === rect.width && lastRect.height === rect.height)
42
+ return;
43
+ this.overlayDefault.style.top = rect.top.toString() + 'px';
44
+ this.overlayDefault.style.left = rect.left.toString() + 'px';
45
+ this.overlayDefault.style.width = rect.width.toString() + 'px';
46
+ this.overlayDefault.style.height = rect.height.toString() + 'px';
47
+ lastRect = rect;
48
+ });
49
+ }
50
+ dispose() {
51
+ this.onBeforeRender.clear();
52
+ this.onAfterRender.clear();
53
+ this._resizeObserver.disconnect();
54
+ if (!this.constructorProps.canvas)
55
+ this.canvas.remove();
56
+ if (!this.constructorProps.overlay)
57
+ this.overlayDefault.remove();
58
+ return super.dispose();
59
+ }
60
+ }
56
61
  export var HorizontalAlignment;
57
62
  (function (HorizontalAlignment) {
58
63
  HorizontalAlignment["left"] = "left";
@@ -1,4 +1,4 @@
1
- import { ContextManager } from '../context';
1
+ import { ContextManager, Context } from '../context';
2
2
  import { Observable } from '../observable';
3
3
  export declare enum Status {
4
4
  "unknown" = "unknown",
@@ -15,18 +15,17 @@ export interface Vendor {
15
15
  description: string;
16
16
  privacyPolicyUrl: string;
17
17
  }
18
- export interface CookieConsentContext {
19
- status: Observable<Status>;
20
- functionalCookies: Observable<ConsentStatus>;
21
- performanceCookies: Observable<ConsentStatus>;
22
- marketingCookies: Observable<ConsentStatus>;
18
+ export declare class CookieConsentContext extends Context {
19
+ status: Observable<Status, never>;
20
+ functionalCookies: Observable<ConsentStatus, never>;
21
+ performanceCookies: Observable<ConsentStatus, never>;
22
+ marketingCookies: Observable<ConsentStatus, never>;
23
+ showSettings: Observable<(() => void) | undefined, never>;
23
24
  performanceVendors: Vendor[];
24
25
  marketingVendors: Vendor[];
25
- registerPerformanceVendor: (v: Vendor) => void;
26
- registerMarketingVendor: (v: Vendor) => void;
27
- showSettings: Observable<(() => void) | undefined>;
26
+ registerPerformanceVendor(v: Vendor): void;
27
+ registerMarketingVendor(v: Vendor): void;
28
28
  }
29
- export declare const CookieConsentContext: import("../context").ContextTypeWithDefault<CookieConsentContext, []>;
30
29
  export declare function useCookieConsentFunctional(mgr: ContextManager): Observable<ConsentStatus, never>;
31
30
  export declare function useCookieConsentPerformance(mgr: ContextManager): Observable<ConsentStatus, never>;
32
31
  export declare function useCookieConsentMarketing(mgr: ContextManager): Observable<ConsentStatus, never>;
@@ -1,4 +1,4 @@
1
- import { defineContextType } from '../context';
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 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
- });
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 interface EnvirontmentContext {
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 { defineContextType } from '../context';
1
+ import { Context } from '../context';
2
2
  import { Observable } from '../observable';
3
- export const EnvironmentContext = defineContextType(() => {
4
- return {
5
- designTime: new Observable(false),
6
- editTime: new Observable(false)
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 interface LoadContext {
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
- progressPercent: Observable<number>;
9
- registerLoadable: (p: Promise<any>) => void;
10
- start: () => void;
11
- startWhenLoaded: () => void;
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 { defineContextType } from '../context';
1
+ import { Context } from '../context';
2
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)
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
- startedResolve?.();
19
+ this.isStarted.value = true;
20
+ this._startedResolved?.();
19
21
  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;
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 (loadables.size === 0 && isLoaded.value === false) {
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 * loadedCount / totalLoadables);
34
- if (startWhenLoaded.value && isLoaded.value && !isStarted.value) {
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
- const registerLoadable = (p) => {
39
- loadables.add(p);
40
- totalLoadables++;
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
- loadedCount++;
43
- loadables.delete(p);
44
- update();
50
+ if (this.disposed)
51
+ return;
52
+ this._loadedCount++;
53
+ this._loadables.delete(p);
54
+ this._update();
45
55
  });
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
- });
56
+ this._update();
57
+ }
58
+ }
62
59
  export function useIsLoaded(mgr) {
63
60
  return mgr.get(LoadContext).isLoaded;
64
61
  }
@@ -0,0 +1,13 @@
1
+ import { Component } from "../component";
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;
9
+ getComponentsByTag(tag: string): Set<Component>;
10
+ getComponentsByTags(tags: string[]): Set<Component>;
11
+ }
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>>;
@@ -0,0 +1,57 @@
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
+ for (const tag of tags) {
12
+ const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
13
+ const set = map.get(tag) ?? new Set();
14
+ set.add(component);
15
+ map.set(tag, set);
16
+ }
17
+ this.tagsByComponent.set(component, new Set(tags));
18
+ }
19
+ ;
20
+ unregisterComponent(component) {
21
+ let tags = this.tagsByComponent.get(component);
22
+ if (!tags)
23
+ return;
24
+ for (const tag of tags.values()) {
25
+ const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
26
+ const entry = map.get(tag);
27
+ if (!entry)
28
+ continue;
29
+ entry.delete(component);
30
+ }
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) {
37
+ if (tags.length === 0)
38
+ return new Set();
39
+ if (tags.length === 1)
40
+ return this.getComponentsByTag(tags[0]);
41
+ const ret = new Set();
42
+ for (const tag of tags) {
43
+ const map = tag.startsWith('global:') ? this.componentsByGlobalTag : this.componentsByLocalTag;
44
+ const entries = map.get(tag);
45
+ if (!entries)
46
+ continue;
47
+ entries.forEach(entry => ret.add(entry));
48
+ }
49
+ return ret;
50
+ }
51
+ }
52
+ export function getComponentsByTag(mgr, tag) {
53
+ return mgr.get(TagContext).getComponentsByTag(tag);
54
+ }
55
+ export function getComponentsByTags(mgr, tags) {
56
+ return mgr.get(TagContext).getComponentsByTags(tags);
57
+ }
@@ -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 interface UserEventContext {
4
+ export declare class UserEventContext extends Context {
5
5
  onUserEvent: EventClass<[Event]>;
6
- nextUserEvent: Observable<Promise<Event>>;
7
- registerUserEvent: (evt: Event) => void;
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;