@zcomponent/core 0.0.12 → 0.0.14
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/behavior.d.ts +9 -24
- package/lib/behavior.js +9 -52
- package/lib/component.d.ts +30 -23
- package/lib/component.js +31 -52
- package/lib/contexts/canvascontext.d.ts +2 -0
- package/lib/contexts/canvascontext.js +1 -0
- package/lib/contexts/environmentcontext.d.ts +10 -0
- package/lib/contexts/environmentcontext.js +13 -1
- package/lib/contexts/loadcontext.d.ts +5 -0
- package/lib/contexts/loadcontext.js +5 -0
- package/lib/data.d.ts +6 -1
- package/lib/data.js +82 -0
- package/lib/entity.d.ts +104 -0
- package/lib/entity.js +126 -0
- package/lib/interfaces.d.ts +30 -6
- package/lib/interfaces.js +6 -1
- package/lib/selectors.d.ts +15 -3
- package/lib/selectors.js +78 -7
- package/lib/types.d.ts +32 -4
- package/lib/types.js +73 -0
- package/lib/zcomponent.d.ts +7 -2
- package/lib/zcomponent.js +97 -17
- package/package.json +4 -3
package/lib/behavior.d.ts
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
import { Component
|
|
1
|
+
import { Component } from './component';
|
|
2
2
|
import { ContextManager } from './context';
|
|
3
|
-
import {
|
|
4
|
-
import { Observable } from './observable';
|
|
5
|
-
import { ZComponent } from './zcomponent';
|
|
3
|
+
import { Entity } from './entity';
|
|
6
4
|
export type BehaviorConstructor<BehaviorType = Behavior, K extends Component = Component> = BehaviorType extends Behavior<K> ? new (contextManager: ContextManager, instance: K, ...args: any[]) => BehaviorType : never;
|
|
7
5
|
export type ConstructorPropsOfBehavior<BehaviorType> = BehaviorType extends Behavior<infer R> ? R : never;
|
|
8
6
|
export type BehaviorConstructorProps = {
|
|
9
7
|
[id: string]: unknown;
|
|
10
8
|
};
|
|
11
|
-
export declare class Behavior<InstanceType extends Component = Component> {
|
|
12
|
-
protected readonly contextManager: ContextManager;
|
|
9
|
+
export declare class Behavior<InstanceType extends Component = Component> extends Entity {
|
|
13
10
|
readonly instance: InstanceType;
|
|
14
|
-
private static callSuperDispose;
|
|
15
|
-
onDispose: Event<[]>;
|
|
16
|
-
private _registered;
|
|
17
|
-
private _zcomponent;
|
|
18
|
-
constructor(contextManager: ContextManager, instance: InstanceType);
|
|
19
|
-
getZComponentInstance<T extends ZComponent = ZComponent>(type?: ConstructorForComponent<T>): T;
|
|
20
|
-
private _updateEnabledResolved;
|
|
21
11
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
12
|
+
* Constructs this behavior
|
|
13
|
+
*
|
|
14
|
+
* @param contextManager The current ContextManager
|
|
15
|
+
* @param instance The instance of the component that this behavior is attached to
|
|
26
16
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
register<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
30
|
-
register<Type>(observable: Observable<Type>, fn: (v: Type) => void): any;
|
|
31
|
-
unregister<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
32
|
-
unregister<Type>(observable: Observable<Type>, fn: (v: Type) => void): any;
|
|
33
|
-
dispose(): never;
|
|
17
|
+
constructor(contextManager: ContextManager, instance: InstanceType);
|
|
18
|
+
private _updateEnabledResolved;
|
|
34
19
|
}
|
|
35
20
|
export declare function shouldBehaviorRunAtDesignTime(b: BehaviorConstructor): boolean;
|
|
36
21
|
export declare function registerBehaviorRunAtDesignTime(b: BehaviorConstructor): Set<new (contextManager: ContextManager, instance: Component<any, import("./component").ConstructorProps>, ...args: any[]) => Behavior<Component<any, import("./component").ConstructorProps>>>;
|
package/lib/behavior.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Entity } from './entity';
|
|
2
|
+
export class Behavior extends Entity {
|
|
3
|
+
/**
|
|
4
|
+
* Constructs this behavior
|
|
5
|
+
*
|
|
6
|
+
* @param contextManager The current ContextManager
|
|
7
|
+
* @param instance The instance of the component that this behavior is attached to
|
|
8
|
+
*/
|
|
5
9
|
constructor(contextManager, instance) {
|
|
6
|
-
|
|
10
|
+
super(contextManager);
|
|
7
11
|
this.instance = instance;
|
|
8
|
-
this.onDispose = new Event();
|
|
9
|
-
this._registered = [];
|
|
10
12
|
this._updateEnabledResolved = () => {
|
|
11
13
|
let newValue = this.enabled.value;
|
|
12
14
|
if (this.instance.enabledResolved?.value === false)
|
|
@@ -15,55 +17,10 @@ export class Behavior {
|
|
|
15
17
|
this.enabledResolved.value = newValue;
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
|
-
/**
|
|
19
|
-
* @zprop
|
|
20
|
-
* @zdefault true
|
|
21
|
-
* @zgroup Behavior
|
|
22
|
-
* @zgrouppriority 10
|
|
23
|
-
*/
|
|
24
|
-
this.enabled = new Observable(true);
|
|
25
|
-
this.enabledResolved = new Observable(true);
|
|
26
|
-
this._zcomponent = getCurrentZComponentConstruction();
|
|
27
20
|
this.register(this.enabled, this._updateEnabledResolved);
|
|
28
21
|
this.register(instance.enabledResolved, this._updateEnabledResolved);
|
|
29
22
|
}
|
|
30
|
-
getZComponentInstance(type) {
|
|
31
|
-
if (this._zcomponent === undefined)
|
|
32
|
-
throw new Error("getZComponentInstance called in behavior that's not part of a ZComponent");
|
|
33
|
-
if (!type)
|
|
34
|
-
return this._zcomponent;
|
|
35
|
-
if (this._zcomponent instanceof type)
|
|
36
|
-
return this._zcomponent;
|
|
37
|
-
throw new Error("getZComponentInstance called in behavior passing wrong kind of ZComponent");
|
|
38
|
-
}
|
|
39
|
-
register(e, fn) {
|
|
40
|
-
if (e instanceof Event)
|
|
41
|
-
e.bindfn(fn);
|
|
42
|
-
else if (e instanceof Observable)
|
|
43
|
-
e.withValue(fn);
|
|
44
|
-
this._registered.push([e, fn]);
|
|
45
|
-
}
|
|
46
|
-
unregister(e, fn) {
|
|
47
|
-
if (e instanceof Event)
|
|
48
|
-
e.unbindfn(fn);
|
|
49
|
-
else if (e instanceof Observable)
|
|
50
|
-
e.removeWithValue(fn);
|
|
51
|
-
this._registered = this._registered.filter(entry => (entry[0] !== e || entry[1] !== fn));
|
|
52
|
-
}
|
|
53
|
-
dispose() {
|
|
54
|
-
for (const entry of this._registered) {
|
|
55
|
-
if (entry[0] instanceof Event)
|
|
56
|
-
entry[0].unbindfn(entry[1]);
|
|
57
|
-
else if (entry[0] instanceof Observable)
|
|
58
|
-
entry[0].removeWithValue(entry[1]);
|
|
59
|
-
}
|
|
60
|
-
this._registered = [];
|
|
61
|
-
this.onDispose.emit();
|
|
62
|
-
this.onDispose.clear();
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
23
|
}
|
|
66
|
-
Behavior.callSuperDispose = Symbol('Calling super.dispose() is mandatory');
|
|
67
24
|
const behaviorsToRunAtDesignTime = new Set();
|
|
68
25
|
export function shouldBehaviorRunAtDesignTime(b) {
|
|
69
26
|
return behaviorsToRunAtDesignTime.has(b);
|
package/lib/component.d.ts
CHANGED
|
@@ -1,59 +1,66 @@
|
|
|
1
1
|
import { ContextManager } from './context';
|
|
2
|
-
import {
|
|
2
|
+
import { Entity } from './entity';
|
|
3
3
|
import { Observable } from './observable';
|
|
4
|
-
import { ZComponent } from './zcomponent';
|
|
5
4
|
export type ConstructorPropsOfComponent<ComponentType> = ComponentType extends Component<any, infer R> ? R : never;
|
|
6
5
|
export type ComponentConstructor<ConstructorPropsType extends ConstructorProps, ComponentType extends Component> = new (props: ConstructorPropsType, contextManager: ContextManager) => ComponentType;
|
|
7
6
|
export type ConstructorForComponent<ComponentType extends Component = Component> = new (contextManager: ContextManager, props: ComponentType extends Component<any, infer PropsType> ? PropsType : never) => ComponentType;
|
|
8
7
|
export type ComponentChild<ComponentType extends Component> = [ConstructorForComponent<ComponentType>, ComponentType extends Component<any, infer U> ? U : never] | [
|
|
9
8
|
ConstructorForComponent<ComponentType>,
|
|
10
9
|
ComponentType extends Component<any, infer U> ? U : never,
|
|
11
|
-
Observable<ComponentType>
|
|
10
|
+
Observable<ComponentType | undefined>
|
|
12
11
|
];
|
|
13
12
|
export type ComponentChildren = ComponentChild<Component>[];
|
|
14
13
|
export interface ConstructorProps {
|
|
15
14
|
[id: string]: any;
|
|
16
15
|
children?: ComponentChildren;
|
|
17
16
|
}
|
|
18
|
-
export declare class Component<ElementType = any, ConstructorPropsType extends ConstructorProps = ConstructorProps> {
|
|
19
|
-
readonly contextManager: ContextManager;
|
|
17
|
+
export declare class Component<ElementType = any, ConstructorPropsType extends ConstructorProps = ConstructorProps> extends Entity {
|
|
20
18
|
protected constructorProps?: ConstructorPropsType | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The raw element(s) that this component exposes
|
|
21
|
+
*/
|
|
21
22
|
element?: ElementType;
|
|
22
|
-
readonly onDispose: Event<[]>;
|
|
23
23
|
readonly children: Component[];
|
|
24
24
|
parent?: Component;
|
|
25
|
-
disposed: boolean;
|
|
26
|
-
private _registered;
|
|
27
|
-
private _zcomponent;
|
|
28
25
|
constructor(contextManager: ContextManager, constructorProps?: ConstructorPropsType | undefined);
|
|
29
26
|
constructChildren(children: ComponentChildren, contextManager?: ContextManager): void;
|
|
30
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Adds the supplied component instance as a child of this component, removing it from any existing parent.
|
|
29
|
+
*
|
|
30
|
+
* @param c The component instance to add
|
|
31
|
+
*/
|
|
31
32
|
appendChild(c: Component): void;
|
|
33
|
+
/**
|
|
34
|
+
* Removes the supplied component instance from the list of children.
|
|
35
|
+
* @param c The component to remove
|
|
36
|
+
*/
|
|
32
37
|
removeChild(c: Component): void;
|
|
38
|
+
/**
|
|
39
|
+
* Removes this component from its parent component.
|
|
40
|
+
*/
|
|
33
41
|
remove(): void;
|
|
34
|
-
get elementsResolved(): any[];
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @group Behavior
|
|
40
|
-
* @zgrouppriority 10
|
|
43
|
+
* An array of the elements that this component instance exposes. In the case that this component
|
|
44
|
+
* does not expose any elements of its own, this will be an array of the elements
|
|
45
|
+
* exposed by this component's children.
|
|
41
46
|
*/
|
|
42
|
-
|
|
43
|
-
enabledResolved: Observable<boolean, never>;
|
|
47
|
+
get elementsResolved(): any[];
|
|
44
48
|
/**
|
|
49
|
+
* An array of string 'tags' assocated with this component.
|
|
50
|
+
*
|
|
51
|
+
* The `getComponentsByTag(mgr, tag)` function can be used to get an array of components
|
|
52
|
+
* with the supplied tag.
|
|
53
|
+
*
|
|
54
|
+
* By default, tags are scoped to the ZComponent instance that a component is constructed by.
|
|
55
|
+
* Tags that begin with `global:` are scoped to the experience as a whole.
|
|
56
|
+
*
|
|
45
57
|
* @zprop
|
|
46
58
|
* @zgroup Other
|
|
47
59
|
* @group Other
|
|
48
60
|
* @zgrouppriority 0
|
|
49
61
|
*/
|
|
50
62
|
tags: Observable<string[], never>;
|
|
51
|
-
protected register<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
52
|
-
protected register<Type>(observable: Observable<Type>, fn: (v: Type) => void): any;
|
|
53
|
-
protected unregister<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
54
|
-
protected unregister<Type>(observable: Observable<Type>, fn: (v: Type) => void): any;
|
|
55
63
|
private _updateEnabledResolved;
|
|
56
64
|
private _updateTags;
|
|
57
65
|
dispose(): never;
|
|
58
|
-
private static callSuperDispose;
|
|
59
66
|
}
|
package/lib/component.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { TagContext } from './contexts/tagcontext';
|
|
2
|
-
import {
|
|
2
|
+
import { Entity } from './entity';
|
|
3
3
|
import { Observable } from './observable';
|
|
4
|
-
|
|
5
|
-
export class Component {
|
|
4
|
+
export class Component extends Entity {
|
|
6
5
|
constructor(contextManager, constructorProps) {
|
|
7
|
-
|
|
6
|
+
super(contextManager);
|
|
8
7
|
this.constructorProps = constructorProps;
|
|
9
|
-
this.onDispose = new Event();
|
|
10
8
|
this.children = [];
|
|
11
|
-
this.disposed = false;
|
|
12
|
-
this._registered = [];
|
|
13
|
-
/**
|
|
14
|
-
* @zprop
|
|
15
|
-
* @zdefault true
|
|
16
|
-
* @zgroup Behavior
|
|
17
|
-
* @group Behavior
|
|
18
|
-
* @zgrouppriority 10
|
|
19
|
-
*/
|
|
20
|
-
this.enabled = new Observable(true);
|
|
21
|
-
this.enabledResolved = new Observable(true);
|
|
22
9
|
/**
|
|
10
|
+
* An array of string 'tags' assocated with this component.
|
|
11
|
+
*
|
|
12
|
+
* The `getComponentsByTag(mgr, tag)` function can be used to get an array of components
|
|
13
|
+
* with the supplied tag.
|
|
14
|
+
*
|
|
15
|
+
* By default, tags are scoped to the ZComponent instance that a component is constructed by.
|
|
16
|
+
* Tags that begin with `global:` are scoped to the experience as a whole.
|
|
17
|
+
*
|
|
23
18
|
* @zprop
|
|
24
19
|
* @zgroup Other
|
|
25
20
|
* @group Other
|
|
@@ -40,7 +35,6 @@ export class Component {
|
|
|
40
35
|
const context = this.contextManager.get(TagContext);
|
|
41
36
|
context.registerComponent(this, this.tags.value);
|
|
42
37
|
};
|
|
43
|
-
this._zcomponent = getCurrentZComponentConstruction();
|
|
44
38
|
this.constructChildren(constructorProps?.children ?? []);
|
|
45
39
|
this.register(this.enabled, this._updateEnabledResolved);
|
|
46
40
|
this.register(this.tags, this._updateTags);
|
|
@@ -59,29 +53,39 @@ export class Component {
|
|
|
59
53
|
}
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (this._zcomponent instanceof type)
|
|
68
|
-
return this._zcomponent;
|
|
69
|
-
throw new Error("getZComponentInstance called in component passing wrong kind of ZComponent");
|
|
70
|
-
}
|
|
56
|
+
/**
|
|
57
|
+
* Adds the supplied component instance as a child of this component, removing it from any existing parent.
|
|
58
|
+
*
|
|
59
|
+
* @param c The component instance to add
|
|
60
|
+
*/
|
|
71
61
|
appendChild(c) {
|
|
72
62
|
c.remove();
|
|
73
63
|
this.children.push(c);
|
|
74
64
|
c.parent = this;
|
|
75
65
|
c._updateEnabledResolved();
|
|
76
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Removes the supplied component instance from the list of children.
|
|
69
|
+
* @param c The component to remove
|
|
70
|
+
*/
|
|
77
71
|
removeChild(c) {
|
|
78
72
|
const indx = this.children.indexOf(c);
|
|
79
73
|
if (indx >= 0)
|
|
80
74
|
this.children.splice(indx, 1);
|
|
75
|
+
if (c.parent === this)
|
|
76
|
+
delete c.parent;
|
|
81
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Removes this component from its parent component.
|
|
80
|
+
*/
|
|
82
81
|
remove() {
|
|
83
82
|
this.parent?.removeChild(this);
|
|
84
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* An array of the elements that this component instance exposes. In the case that this component
|
|
86
|
+
* does not expose any elements of its own, this will be an array of the elements
|
|
87
|
+
* exposed by this component's children.
|
|
88
|
+
*/
|
|
85
89
|
get elementsResolved() {
|
|
86
90
|
if (this.element !== undefined) {
|
|
87
91
|
if (Array.isArray(this.element))
|
|
@@ -94,22 +98,7 @@ export class Component {
|
|
|
94
98
|
}
|
|
95
99
|
return ret;
|
|
96
100
|
}
|
|
97
|
-
register(e, fn) {
|
|
98
|
-
if (e instanceof Event)
|
|
99
|
-
e.bindfn(fn);
|
|
100
|
-
else if (e instanceof Observable)
|
|
101
|
-
e.withValue(fn);
|
|
102
|
-
this._registered.push([e, fn]);
|
|
103
|
-
}
|
|
104
|
-
unregister(e, fn) {
|
|
105
|
-
if (e instanceof Event)
|
|
106
|
-
e.unbindfn(fn);
|
|
107
|
-
else if (e instanceof Observable)
|
|
108
|
-
e.removeWithValue(fn);
|
|
109
|
-
this._registered = this._registered.filter(entry => (entry[0] !== e || entry[1] !== fn));
|
|
110
|
-
}
|
|
111
101
|
dispose() {
|
|
112
|
-
this.disposed = true;
|
|
113
102
|
for (const child of this.children) {
|
|
114
103
|
try {
|
|
115
104
|
child.dispose();
|
|
@@ -117,17 +106,7 @@ export class Component {
|
|
|
117
106
|
catch (err) { }
|
|
118
107
|
}
|
|
119
108
|
this.children.length = 0;
|
|
120
|
-
for (const entry of this._registered) {
|
|
121
|
-
if (entry[0] instanceof Event)
|
|
122
|
-
entry[0].unbindfn(entry[1]);
|
|
123
|
-
else if (entry[0] instanceof Observable)
|
|
124
|
-
entry[0].removeWithValue(entry[1]);
|
|
125
|
-
}
|
|
126
|
-
this._registered = [];
|
|
127
|
-
this.onDispose.emit();
|
|
128
|
-
this.onDispose.clear();
|
|
129
109
|
this.contextManager.get(TagContext).unregisterComponent(this);
|
|
130
|
-
return
|
|
110
|
+
return super.dispose();
|
|
131
111
|
}
|
|
132
112
|
}
|
|
133
|
-
Component.callSuperDispose = Symbol('Calling super.dispose() is mandatory');
|
|
@@ -5,6 +5,7 @@ export interface CanvasContextOptions {
|
|
|
5
5
|
canvas?: HTMLCanvasElement;
|
|
6
6
|
overlay?: HTMLDivElement;
|
|
7
7
|
}
|
|
8
|
+
/** @zcontext */
|
|
8
9
|
export declare class CanvasContext extends Context {
|
|
9
10
|
constructorProps: CanvasContextOptions;
|
|
10
11
|
onBeforeRender: Event<[number]>;
|
|
@@ -12,6 +13,7 @@ export declare class CanvasContext extends Context {
|
|
|
12
13
|
canvas: HTMLCanvasElement;
|
|
13
14
|
overlayDefault: HTMLDivElement;
|
|
14
15
|
overlay: Observable<HTMLDivElement>;
|
|
16
|
+
/** @zui */
|
|
15
17
|
size: Observable<[number, number]>;
|
|
16
18
|
private _resizeObserver;
|
|
17
19
|
constructor(contextManager: ContextManager, constructorProps: CanvasContextOptions);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context } from '../context';
|
|
2
2
|
import { Event } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
+
/** @zcontext */
|
|
4
5
|
export class CanvasContext extends Context {
|
|
5
6
|
constructor(contextManager, constructorProps) {
|
|
6
7
|
super(contextManager, constructorProps);
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
+
/** @zcontext */
|
|
3
4
|
export declare class EnvironmentContext extends Context {
|
|
5
|
+
/** @zprop */
|
|
4
6
|
designTime: Observable<boolean, never>;
|
|
7
|
+
/** @zprop */
|
|
5
8
|
editTime: Observable<boolean, never>;
|
|
9
|
+
/** @zprop */
|
|
10
|
+
runTime: Observable<boolean, never>;
|
|
11
|
+
/** @zprop */
|
|
12
|
+
developmentBuild: Observable<boolean, never>;
|
|
13
|
+
/** @zprop */
|
|
14
|
+
productionBuild: Observable<boolean, never>;
|
|
6
15
|
}
|
|
7
16
|
export declare function isDesignTime(ctx: ContextManager): boolean;
|
|
8
17
|
export declare function isEditTime(ctx: ContextManager): boolean;
|
|
9
18
|
export declare function isDevelopmentBuild(ctx: ContextManager): boolean;
|
|
19
|
+
export declare function isProductionBuild(ctx: ContextManager): boolean;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
+
/** @zcontext */
|
|
3
4
|
export class EnvironmentContext extends Context {
|
|
4
5
|
constructor() {
|
|
5
6
|
super(...arguments);
|
|
7
|
+
/** @zprop */
|
|
6
8
|
this.designTime = new Observable(false);
|
|
9
|
+
/** @zprop */
|
|
7
10
|
this.editTime = new Observable(false);
|
|
11
|
+
/** @zprop */
|
|
12
|
+
this.runTime = new Observable(true);
|
|
13
|
+
/** @zprop */
|
|
14
|
+
this.developmentBuild = new Observable(typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development');
|
|
15
|
+
/** @zprop */
|
|
16
|
+
this.productionBuild = new Observable(!this.developmentBuild.value);
|
|
8
17
|
}
|
|
9
18
|
}
|
|
10
19
|
export function isDesignTime(ctx) {
|
|
@@ -14,5 +23,8 @@ export function isEditTime(ctx) {
|
|
|
14
23
|
return ctx.get(EnvironmentContext).editTime.value;
|
|
15
24
|
}
|
|
16
25
|
export function isDevelopmentBuild(ctx) {
|
|
17
|
-
return (
|
|
26
|
+
return ctx.get(EnvironmentContext).developmentBuild.value;
|
|
27
|
+
}
|
|
28
|
+
export function isProductionBuild(ctx) {
|
|
29
|
+
return ctx.get(EnvironmentContext).productionBuild.value;
|
|
18
30
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
+
/** @zcontext */
|
|
3
4
|
export declare class LoadContext extends Context {
|
|
5
|
+
/** @zui */
|
|
4
6
|
isConstructed: Observable<boolean, never>;
|
|
7
|
+
/** @zui */
|
|
5
8
|
isLoaded: Observable<boolean, never>;
|
|
9
|
+
/** @zui */
|
|
6
10
|
isStarted: Observable<boolean, never>;
|
|
11
|
+
/** @zui */
|
|
7
12
|
progressPercent: Observable<number, never>;
|
|
8
13
|
private _startedResolved;
|
|
9
14
|
started: Promise<void>;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Context } from '../context';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
|
+
/** @zcontext */
|
|
3
4
|
export class LoadContext extends Context {
|
|
4
5
|
constructor() {
|
|
5
6
|
super(...arguments);
|
|
7
|
+
/** @zui */
|
|
6
8
|
this.isConstructed = new Observable(false);
|
|
9
|
+
/** @zui */
|
|
7
10
|
this.isLoaded = new Observable(false);
|
|
11
|
+
/** @zui */
|
|
8
12
|
this.isStarted = new Observable(false);
|
|
13
|
+
/** @zui */
|
|
9
14
|
this.progressPercent = new Observable(0);
|
|
10
15
|
this.started = new Promise(resolve => this._startedResolved = resolve);
|
|
11
16
|
this._loadables = new Set();
|
package/lib/data.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { BehaviorByID, BehaviorData, ComputedHierarchy, NodeByID, NodeData, ZComponentData } from "./interfaces";
|
|
1
|
+
import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from "./interfaces";
|
|
2
|
+
import { Prop } from "./types";
|
|
2
3
|
export declare function computeNodeHierarchy(nodes: NodeByID): ComputedHierarchy;
|
|
3
4
|
export declare function computeBehaviorHierarchy(behaviors: BehaviorByID): ComputedHierarchy;
|
|
4
5
|
export declare function addNode(zcomp: ZComponentData, info: NodeDataCombined): void;
|
|
5
6
|
export declare function addBehavior(zcomp: ZComponentData, info: BehaviorDataCombined): void;
|
|
7
|
+
export declare function updateComponentProp(zcomp: ZComponentData, prop: string, isConstructorProp: boolean, newValue: Prop | undefined, newIsConstructorProp: boolean): void;
|
|
8
|
+
export declare function addEntityPropOverride(zcomp: ZComponentData, o: EntityPropOverride): void;
|
|
9
|
+
export declare function deleteEntityPropOverride(zcomp: ZComponentData, id: string): void;
|
|
10
|
+
export declare function clone<T>(obj: T): T;
|
|
6
11
|
export declare function addEntity(zcomp: ZComponentData, id: string, info: EntityDataCombined): void;
|
|
7
12
|
export declare function moveNodes(zcomp: ZComponentData, nodeIDs: string[], newParentID: string, indx: number): void;
|
|
8
13
|
export declare function deleteNode(zcomp: ZComponentData, id: string): void;
|
package/lib/data.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { generateKeyBetween, generateNKeysBetween } from "./fractionalindexing";
|
|
2
|
+
import { EntityPropOverrideType } from "./interfaces";
|
|
2
3
|
// Simple memoizing of computed hierarchy
|
|
3
4
|
const computedHierarchies = new Map();
|
|
4
5
|
const computedBehaviors = new Map();
|
|
@@ -66,6 +67,80 @@ export function addBehavior(zcomp, info) {
|
|
|
66
67
|
addEntity(zcomp, info.data.id, info);
|
|
67
68
|
computedBehaviors.delete(zcomp.behaviors);
|
|
68
69
|
}
|
|
70
|
+
export function updateComponentProp(zcomp, prop, isConstructorProp, newValue, newIsConstructorProp) {
|
|
71
|
+
if (zcomp.constructorProps === undefined)
|
|
72
|
+
zcomp.constructorProps = {};
|
|
73
|
+
if (newValue === undefined) {
|
|
74
|
+
if (isConstructorProp)
|
|
75
|
+
delete zcomp.constructorProps[prop];
|
|
76
|
+
else
|
|
77
|
+
delete zcomp.props[prop];
|
|
78
|
+
if (zcomp.entityPropOverrides) {
|
|
79
|
+
for (const [id, override] of Object.entries(zcomp.entityPropOverrides)) {
|
|
80
|
+
if (override.type !== EntityPropOverrideType.ComponentProp)
|
|
81
|
+
continue;
|
|
82
|
+
if (override.isConstructorProp !== isConstructorProp)
|
|
83
|
+
continue;
|
|
84
|
+
if (override.propName !== prop)
|
|
85
|
+
continue;
|
|
86
|
+
delete zcomp.entityPropOverrides[id];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (newValue.name !== prop || isConstructorProp !== newIsConstructorProp) {
|
|
92
|
+
if (isConstructorProp)
|
|
93
|
+
delete zcomp.constructorProps[prop];
|
|
94
|
+
else
|
|
95
|
+
delete zcomp.props[prop];
|
|
96
|
+
if (zcomp.entityPropOverrides) {
|
|
97
|
+
for (const [id, override] of Object.entries(zcomp.entityPropOverrides)) {
|
|
98
|
+
if (override.type !== EntityPropOverrideType.ComponentProp)
|
|
99
|
+
continue;
|
|
100
|
+
if (override.isConstructorProp !== isConstructorProp)
|
|
101
|
+
continue;
|
|
102
|
+
if (override.propName !== prop)
|
|
103
|
+
continue;
|
|
104
|
+
delete zcomp.entityPropOverrides[id];
|
|
105
|
+
if (!(override.entityPropIsConstructor && !newIsConstructorProp)) {
|
|
106
|
+
const newOverride = clone(override);
|
|
107
|
+
newOverride.propName = newValue.name;
|
|
108
|
+
newOverride.id = idForEntityPropOverride(override);
|
|
109
|
+
zcomp.entityPropOverrides[newOverride.id] = newOverride;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
newValue.type.isObservable = !newIsConstructorProp;
|
|
115
|
+
if (newIsConstructorProp)
|
|
116
|
+
zcomp.constructorProps[newValue.name] = newValue;
|
|
117
|
+
else
|
|
118
|
+
zcomp.props[newValue.name] = newValue;
|
|
119
|
+
}
|
|
120
|
+
export function addEntityPropOverride(zcomp, o) {
|
|
121
|
+
if (!zcomp.entityPropOverrides)
|
|
122
|
+
zcomp.entityPropOverrides = {};
|
|
123
|
+
o.id = idForEntityPropOverride(o);
|
|
124
|
+
zcomp.entityPropOverrides[o.id] = o;
|
|
125
|
+
}
|
|
126
|
+
export function deleteEntityPropOverride(zcomp, id) {
|
|
127
|
+
if (!zcomp.entityPropOverrides)
|
|
128
|
+
return;
|
|
129
|
+
delete zcomp.entityPropOverrides[id];
|
|
130
|
+
}
|
|
131
|
+
function idForEntityPropOverride(override) {
|
|
132
|
+
return override.type + ":" + (override.entityPropIsConstructor ? 'constructorprop' : 'prop') + ":" + override.entityID + ":" + override.entityPropPath.join('.');
|
|
133
|
+
}
|
|
134
|
+
export function clone(obj) {
|
|
135
|
+
try {
|
|
136
|
+
if (typeof structuredClone !== 'undefined')
|
|
137
|
+
return structuredClone(obj);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Ignore
|
|
141
|
+
}
|
|
142
|
+
return JSON.parse(JSON.stringify(obj));
|
|
143
|
+
}
|
|
69
144
|
export function addEntity(zcomp, id, info) {
|
|
70
145
|
zcomp.entityProps[id] = info.props;
|
|
71
146
|
zcomp.entityConstructorProps[id] = info.constructorProps;
|
|
@@ -265,6 +340,13 @@ export function changeNodeScriptName(zcomp, id, newScriptName) {
|
|
|
265
340
|
export function deleteEntity(zcomp, id) {
|
|
266
341
|
delete zcomp.entityProps[id];
|
|
267
342
|
delete zcomp.entityConstructorProps[id];
|
|
343
|
+
if (zcomp.entityPropOverrides) {
|
|
344
|
+
for (const [overrideID, override] of Object.entries(zcomp.entityPropOverrides)) {
|
|
345
|
+
if (override.entityID !== id)
|
|
346
|
+
continue;
|
|
347
|
+
delete zcomp.entityPropOverrides[overrideID];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
268
350
|
}
|
|
269
351
|
export function forEachNodeAncestor(zcomp, id, fn) {
|
|
270
352
|
const node = zcomp.nodes[id];
|