@zcomponent/core 0.0.13 → 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 +0 -1
- package/lib/behavior.js +1 -2
- package/lib/component.d.ts +1 -2
- package/lib/component.js +1 -2
- 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 +3 -1
- package/lib/entity.js +6 -1
- 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 +31 -4
- package/lib/types.js +61 -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
|
@@ -7,7 +7,6 @@ export type BehaviorConstructorProps = {
|
|
|
7
7
|
[id: string]: unknown;
|
|
8
8
|
};
|
|
9
9
|
export declare class Behavior<InstanceType extends Component = Component> extends Entity {
|
|
10
|
-
protected readonly contextManager: ContextManager;
|
|
11
10
|
readonly instance: InstanceType;
|
|
12
11
|
/**
|
|
13
12
|
* Constructs this behavior
|
package/lib/behavior.js
CHANGED
|
@@ -7,8 +7,7 @@ export class Behavior extends Entity {
|
|
|
7
7
|
* @param instance The instance of the component that this behavior is attached to
|
|
8
8
|
*/
|
|
9
9
|
constructor(contextManager, instance) {
|
|
10
|
-
super();
|
|
11
|
-
this.contextManager = contextManager;
|
|
10
|
+
super(contextManager);
|
|
12
11
|
this.instance = instance;
|
|
13
12
|
this._updateEnabledResolved = () => {
|
|
14
13
|
let newValue = this.enabled.value;
|
package/lib/component.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type ConstructorForComponent<ComponentType extends Component = Component>
|
|
|
7
7
|
export type ComponentChild<ComponentType extends Component> = [ConstructorForComponent<ComponentType>, ComponentType extends Component<any, infer U> ? U : never] | [
|
|
8
8
|
ConstructorForComponent<ComponentType>,
|
|
9
9
|
ComponentType extends Component<any, infer U> ? U : never,
|
|
10
|
-
Observable<ComponentType>
|
|
10
|
+
Observable<ComponentType | undefined>
|
|
11
11
|
];
|
|
12
12
|
export type ComponentChildren = ComponentChild<Component>[];
|
|
13
13
|
export interface ConstructorProps {
|
|
@@ -15,7 +15,6 @@ export interface ConstructorProps {
|
|
|
15
15
|
children?: ComponentChildren;
|
|
16
16
|
}
|
|
17
17
|
export declare class Component<ElementType = any, ConstructorPropsType extends ConstructorProps = ConstructorProps> extends Entity {
|
|
18
|
-
readonly contextManager: ContextManager;
|
|
19
18
|
protected constructorProps?: ConstructorPropsType | undefined;
|
|
20
19
|
/**
|
|
21
20
|
* The raw element(s) that this component exposes
|
package/lib/component.js
CHANGED
|
@@ -3,8 +3,7 @@ import { Entity } from './entity';
|
|
|
3
3
|
import { Observable } from './observable';
|
|
4
4
|
export class Component extends Entity {
|
|
5
5
|
constructor(contextManager, constructorProps) {
|
|
6
|
-
super();
|
|
7
|
-
this.contextManager = contextManager;
|
|
6
|
+
super(contextManager);
|
|
8
7
|
this.constructorProps = constructorProps;
|
|
9
8
|
this.children = [];
|
|
10
9
|
/**
|
|
@@ -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];
|
package/lib/entity.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ConstructorForComponent } from "./component";
|
|
2
|
+
import { ContextManager } from "./context";
|
|
2
3
|
import { Event } from "./event";
|
|
3
4
|
import { Observable } from "./observable";
|
|
4
5
|
import { ZComponent } from "./zcomponent";
|
|
5
6
|
export declare class Entity {
|
|
7
|
+
readonly contextManager: ContextManager;
|
|
6
8
|
private _registered;
|
|
7
9
|
private _zcomponent;
|
|
8
10
|
private _disposed;
|
|
@@ -10,7 +12,7 @@ export declare class Entity {
|
|
|
10
12
|
* An event that is fired as the last act of this entity being destroyed.
|
|
11
13
|
*/
|
|
12
14
|
readonly onDispose: Event<[]>;
|
|
13
|
-
constructor();
|
|
15
|
+
constructor(contextManager: ContextManager);
|
|
14
16
|
get disposed(): boolean;
|
|
15
17
|
private set disposed(value);
|
|
16
18
|
/**
|
package/lib/entity.js
CHANGED
|
@@ -2,7 +2,8 @@ import { Event } from "./event";
|
|
|
2
2
|
import { Observable } from "./observable";
|
|
3
3
|
import { getCurrentZComponentConstruction } from "./zcomponentconstruction";
|
|
4
4
|
export class Entity {
|
|
5
|
-
constructor() {
|
|
5
|
+
constructor(contextManager) {
|
|
6
|
+
this.contextManager = contextManager;
|
|
6
7
|
this._registered = [];
|
|
7
8
|
this._disposed = false;
|
|
8
9
|
/**
|
|
@@ -73,6 +74,10 @@ export class Entity {
|
|
|
73
74
|
throw new Error("getZComponentInstance called in entity passing wrong kind of ZComponent");
|
|
74
75
|
}
|
|
75
76
|
register(e, fn) {
|
|
77
|
+
for (const entry of this._registered) {
|
|
78
|
+
if (entry[0] === e && entry[1] === fn)
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
76
81
|
if (e instanceof Event)
|
|
77
82
|
e.bindfn(fn);
|
|
78
83
|
else if (e instanceof Observable)
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -29,15 +29,12 @@ export interface ZComponentData {
|
|
|
29
29
|
nodes: NodeByID;
|
|
30
30
|
root: string;
|
|
31
31
|
props: Props;
|
|
32
|
+
constructorProps?: Props;
|
|
32
33
|
entityProps: PropsByID;
|
|
33
34
|
entityConstructorProps: PropsByID;
|
|
34
35
|
preview: Import;
|
|
35
|
-
|
|
36
|
-
[
|
|
37
|
-
[entityID: string]: {
|
|
38
|
-
[propName: string]: boolean;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
36
|
+
entityPropOverrides?: {
|
|
37
|
+
[id: string]: EntityPropOverride;
|
|
41
38
|
};
|
|
42
39
|
behaviors: BehaviorByID;
|
|
43
40
|
animation?: Animation;
|
|
@@ -70,3 +67,30 @@ export interface BehaviorData {
|
|
|
70
67
|
order: string;
|
|
71
68
|
};
|
|
72
69
|
}
|
|
70
|
+
export type EntityPropOverride = PropEntityPropOverride | ImportEntityPropOverride | ContextValueEntityPropOverride;
|
|
71
|
+
export declare enum EntityPropOverrideType {
|
|
72
|
+
ComponentProp = "componentprop",
|
|
73
|
+
Import = "import",
|
|
74
|
+
ContextValue = "contextvalue"
|
|
75
|
+
}
|
|
76
|
+
export interface BaseEntityPropOverride {
|
|
77
|
+
id: string;
|
|
78
|
+
entityID: string;
|
|
79
|
+
entityPropPath: (string | number)[];
|
|
80
|
+
entityPropIsConstructor: boolean;
|
|
81
|
+
type: EntityPropOverrideType;
|
|
82
|
+
}
|
|
83
|
+
export interface PropEntityPropOverride extends BaseEntityPropOverride {
|
|
84
|
+
propName: string;
|
|
85
|
+
isConstructorProp: boolean;
|
|
86
|
+
type: EntityPropOverrideType.ComponentProp;
|
|
87
|
+
}
|
|
88
|
+
export interface ImportEntityPropOverride extends BaseEntityPropOverride {
|
|
89
|
+
imp: string;
|
|
90
|
+
type: EntityPropOverrideType.Import;
|
|
91
|
+
}
|
|
92
|
+
export interface ContextValueEntityPropOverride extends BaseEntityPropOverride {
|
|
93
|
+
imp: string;
|
|
94
|
+
val: string;
|
|
95
|
+
type: EntityPropOverrideType.ContextValue;
|
|
96
|
+
}
|
package/lib/interfaces.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var EntityPropOverrideType;
|
|
2
|
+
(function (EntityPropOverrideType) {
|
|
3
|
+
EntityPropOverrideType["ComponentProp"] = "componentprop";
|
|
4
|
+
EntityPropOverrideType["Import"] = "import";
|
|
5
|
+
EntityPropOverrideType["ContextValue"] = "contextvalue";
|
|
6
|
+
})(EntityPropOverrideType || (EntityPropOverrideType = {}));
|
package/lib/selectors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Import, NodeByID, ParsedImport, Props } from './interfaces';
|
|
1
|
+
import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './interfaces';
|
|
2
2
|
export declare function parseImport(i: Import): ParsedImport;
|
|
3
3
|
export declare function constructImport(from: string, destFile: string, imp: string): string;
|
|
4
4
|
export declare function getScriptName(n: string, requireUniqueIn: {
|
|
@@ -6,8 +6,20 @@ export declare function getScriptName(n: string, requireUniqueIn: {
|
|
|
6
6
|
}): string;
|
|
7
7
|
export declare function isValidVariableName(n: string): boolean;
|
|
8
8
|
export declare function variableNameFromImport(imp: ParsedImport): string;
|
|
9
|
-
export
|
|
9
|
+
export type EntityPropOverrideByEntityPropPath = {
|
|
10
|
+
[entityID: string]: {
|
|
11
|
+
[propName: string]: {
|
|
12
|
+
[path: string]: EntityPropOverride;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function entityPropOverrideByEntityAndProp(entityPropOverrides: {
|
|
17
|
+
[id: string]: EntityPropOverride;
|
|
18
|
+
}): EntityPropOverrideByEntityPropPath;
|
|
19
|
+
export declare function summaryForEntityPropOverrideDestination(o: EntityPropOverride): string;
|
|
20
|
+
export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props, constructorProps: Props | undefined, scriptNames: {
|
|
10
21
|
[id: string]: {
|
|
11
22
|
[id: string]: boolean;
|
|
12
23
|
};
|
|
13
|
-
}, url: string) => string;
|
|
24
|
+
} | undefined, url: string) => string;
|
|
25
|
+
export declare function getSafeKeyName(n: string): string;
|
package/lib/selectors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EntityPropOverrideType } from './interfaces';
|
|
1
2
|
import * as path from 'path';
|
|
2
3
|
import { outputForType } from './types';
|
|
3
4
|
export function parseImport(i) {
|
|
@@ -117,11 +118,52 @@ export function variableNameFromImport(imp) {
|
|
|
117
118
|
return imp[1];
|
|
118
119
|
return 'unknown';
|
|
119
120
|
}
|
|
120
|
-
export
|
|
121
|
+
export function entityPropOverrideByEntityAndProp(entityPropOverrides) {
|
|
122
|
+
const ret = Object.create(null);
|
|
123
|
+
for (const val of Object.values(entityPropOverrides)) {
|
|
124
|
+
if (!Array.isArray(val.entityPropPath) || val.entityPropPath.length < 1)
|
|
125
|
+
continue;
|
|
126
|
+
const obj = ret[val.entityID] || Object.create(null);
|
|
127
|
+
ret[val.entityID] = obj;
|
|
128
|
+
const propName = val.entityPropPath[0];
|
|
129
|
+
const arr = obj[propName] || Object.create(null);
|
|
130
|
+
obj[propName] = arr;
|
|
131
|
+
arr[val.entityPropPath.join('.')] = val;
|
|
132
|
+
}
|
|
133
|
+
return ret;
|
|
134
|
+
}
|
|
135
|
+
export function summaryForEntityPropOverrideDestination(o) {
|
|
136
|
+
switch (o.type) {
|
|
137
|
+
case EntityPropOverrideType.ComponentProp:
|
|
138
|
+
return 'Component Prop: ' + o.propName;
|
|
139
|
+
case EntityPropOverrideType.ContextValue: {
|
|
140
|
+
const imp = parseImport(o.imp);
|
|
141
|
+
if (imp[1] === 'default' && typeof imp[0] === 'string') {
|
|
142
|
+
const parts = imp[0].split(path.sep);
|
|
143
|
+
return parts[parts.length - 1] + '.' + o.val;
|
|
144
|
+
}
|
|
145
|
+
if (typeof imp[1] === 'string')
|
|
146
|
+
return imp[1] + '.' + o.val;
|
|
147
|
+
return `?.` + o.val;
|
|
148
|
+
}
|
|
149
|
+
case EntityPropOverrideType.Import: {
|
|
150
|
+
return o.imp;
|
|
151
|
+
// const imp = parseImport(o.imp);
|
|
152
|
+
// if (imp[1] === 'default' && typeof imp[0] === 'string') {
|
|
153
|
+
// const parts = imp[0].split(path.sep);
|
|
154
|
+
// return parts[parts.length - 1];
|
|
155
|
+
// }
|
|
156
|
+
// if (typeof imp[1] === 'string') return imp[1];
|
|
157
|
+
// return '?';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return '?';
|
|
161
|
+
}
|
|
162
|
+
export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, url) => {
|
|
121
163
|
const importMapping = new Map();
|
|
122
164
|
let indx = 0;
|
|
123
165
|
let importStrings = [];
|
|
124
|
-
for (const scriptNameNodes of Object.values(scriptNames)) {
|
|
166
|
+
for (const scriptNameNodes of Object.values(scriptNames ?? {})) {
|
|
125
167
|
for (const nodeID of Object.keys(scriptNameNodes)) {
|
|
126
168
|
const node = nodes[nodeID];
|
|
127
169
|
if (!node)
|
|
@@ -139,15 +181,20 @@ export const typeDefinitionForComponent = (nodes, props, scriptNames, url) => {
|
|
|
139
181
|
|
|
140
182
|
${importStrings.join('\n')}
|
|
141
183
|
|
|
184
|
+
interface ConstructorProps {
|
|
185
|
+
${Object.values(constructorProps ?? {}).map(typeOutputForConstructorProp).join('\n\n')}
|
|
186
|
+
}
|
|
187
|
+
|
|
142
188
|
/**
|
|
143
189
|
* @zcomponent
|
|
190
|
+
* @zicon zcomponent
|
|
144
191
|
*/
|
|
145
192
|
declare class Comp extends ZComponent {
|
|
146
193
|
|
|
147
|
-
constructor(contextManager: ContextManager, constructorProps:
|
|
194
|
+
constructor(contextManager: ContextManager, constructorProps: ConstructorProps);
|
|
148
195
|
|
|
149
196
|
nodes: {
|
|
150
|
-
${Object.entries(scriptNames).map(entry => {
|
|
197
|
+
${Object.entries(scriptNames ?? {}).map(entry => {
|
|
151
198
|
const values = Object.keys(entry[1]);
|
|
152
199
|
if (values.length > 1) {
|
|
153
200
|
return `\t\t${entry[0]}: {${values.map(e => `${JSON.stringify(e)}: ${importMapping.get(nodes[e].type)}`).join(', ')}},`;
|
|
@@ -158,16 +205,40 @@ ${Object.entries(scriptNames).map(entry => {
|
|
|
158
205
|
}).join("\n")}
|
|
159
206
|
};
|
|
160
207
|
|
|
161
|
-
${Object.values(props).map(typeOutputForProp).join('\n')}
|
|
208
|
+
${Object.values(props).map(typeOutputForProp).join('\n\n')}
|
|
162
209
|
}
|
|
163
210
|
|
|
164
211
|
export default Comp;
|
|
165
212
|
`;
|
|
166
213
|
};
|
|
214
|
+
function makeCommentSafe(c) {
|
|
215
|
+
return c.replaceAll('*/', '').split('\n').join('\n\t* ');
|
|
216
|
+
}
|
|
167
217
|
function typeOutputForProp(prop) {
|
|
168
|
-
|
|
218
|
+
const comments = (prop.comments && prop.comments.length > 0) ? '\n\t* ' + prop.comments.map(makeCommentSafe).join('\n\t*\n\t* ') + '\n\t* ' : '';
|
|
219
|
+
return ` /**${comments}
|
|
169
220
|
* @zprop
|
|
170
|
-
* ${prop.default
|
|
221
|
+
* ${prop.default ? `@zdefault ${JSON.stringify(prop.default)}` : ''}
|
|
171
222
|
*/
|
|
172
223
|
public ${prop.name}: Observable<${outputForType(prop.type, true)}>;`;
|
|
173
224
|
}
|
|
225
|
+
function typeOutputForConstructorProp(prop) {
|
|
226
|
+
const comments = (prop.comments && prop.comments.length > 0) ? '\n\t* ' + prop.comments.map(makeCommentSafe).join('\n\t*\n\t* ') + '\n\t* ' : '';
|
|
227
|
+
return ` /**${comments}
|
|
228
|
+
* @zprop
|
|
229
|
+
* ${prop.default && `@zdefault ${JSON.stringify(prop.default)}`}
|
|
230
|
+
*/
|
|
231
|
+
${prop.name}: ${outputForType(prop.type, true)};`;
|
|
232
|
+
}
|
|
233
|
+
export function getSafeKeyName(n) {
|
|
234
|
+
if (n.length === 0)
|
|
235
|
+
return '_';
|
|
236
|
+
let scriptname = n.replace(' ', '_');
|
|
237
|
+
scriptname = scriptname.replace('-', '_');
|
|
238
|
+
scriptname = scriptname.replace('.', '_');
|
|
239
|
+
scriptname = scriptname.replace(/[^a-zA-Z0-9_]/g, '');
|
|
240
|
+
if (scriptname.match(/^[0-9]/)) {
|
|
241
|
+
scriptname = 'n' + scriptname;
|
|
242
|
+
}
|
|
243
|
+
return scriptname;
|
|
244
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EntityPropOverride } from "./interfaces";
|
|
1
2
|
export interface BaseType {
|
|
2
3
|
comments?: string[];
|
|
3
4
|
typeHint?: TypeHint;
|
|
@@ -69,10 +70,18 @@ export interface Prop {
|
|
|
69
70
|
groupPriority?: number;
|
|
70
71
|
values?: Values[];
|
|
71
72
|
}
|
|
73
|
+
export interface DefaultChild {
|
|
74
|
+
label: string;
|
|
75
|
+
type: string;
|
|
76
|
+
initialProps: {
|
|
77
|
+
[id: string]: any;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export type ComponentInfoType = "component" | "behavior" | "context";
|
|
72
81
|
export interface ComponentInfo {
|
|
73
82
|
name: string;
|
|
74
83
|
file: string;
|
|
75
|
-
type:
|
|
84
|
+
type: ComponentInfoType;
|
|
76
85
|
isDefault?: boolean;
|
|
77
86
|
constructorProps: {
|
|
78
87
|
[id: string]: Prop;
|
|
@@ -86,10 +95,23 @@ export interface ComponentInfo {
|
|
|
86
95
|
tags: string[];
|
|
87
96
|
allowedChildren: string[];
|
|
88
97
|
allowedParents?: string[];
|
|
98
|
+
defaultChildren?: DefaultChild[];
|
|
99
|
+
}
|
|
100
|
+
export interface ValueInfo {
|
|
101
|
+
name: string;
|
|
102
|
+
file: string;
|
|
103
|
+
isDefault?: boolean;
|
|
104
|
+
type: Type;
|
|
105
|
+
comments?: string[];
|
|
106
|
+
}
|
|
107
|
+
export interface SourceFileTypeInfo {
|
|
108
|
+
components: {
|
|
109
|
+
[id: string]: ComponentInfo;
|
|
110
|
+
};
|
|
111
|
+
values: {
|
|
112
|
+
[id: string]: ValueInfo;
|
|
113
|
+
};
|
|
89
114
|
}
|
|
90
|
-
export type SourceFileTypeInfo = {
|
|
91
|
-
[id: string]: ComponentInfo;
|
|
92
|
-
};
|
|
93
115
|
export type TypeInfoByFileName = {
|
|
94
116
|
[id: string]: SourceFileTypeInfo;
|
|
95
117
|
};
|
|
@@ -105,3 +127,8 @@ export interface TemplateInfo {
|
|
|
105
127
|
export declare function symbolPathFromFilename(f: string): string;
|
|
106
128
|
export declare function isValidValueForType(def: any, t: Type, allowUndefined?: boolean): boolean;
|
|
107
129
|
export declare function outputForType(t: Type, alwaysBasic?: boolean): string;
|
|
130
|
+
export declare function overridesAreCompatible(a: {
|
|
131
|
+
[path: string]: EntityPropOverride;
|
|
132
|
+
}, b: {
|
|
133
|
+
[path: string]: EntityPropOverride;
|
|
134
|
+
}): boolean;
|
package/lib/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EntityPropOverrideType } from "./interfaces";
|
|
2
|
+
import { getSafeKeyName } from "./selectors";
|
|
1
3
|
export var TypeHint;
|
|
2
4
|
(function (TypeHint) {
|
|
3
5
|
TypeHint["proportion"] = "proportion";
|
|
@@ -291,6 +293,9 @@ function getBasicType(t) {
|
|
|
291
293
|
case 'array':
|
|
292
294
|
return outputForType(t.child) + '[]';
|
|
293
295
|
case 'tuple':
|
|
296
|
+
if (Array.isArray(t.names) && t.names.length === t.children.length) {
|
|
297
|
+
return `[${t.children.map((c, indx) => `${getSafeKeyName(t.names[indx])}: ${outputForType(c)}`).join(', ')}]`;
|
|
298
|
+
}
|
|
294
299
|
return `[${t.children.map(c => outputForType(c)).join(', ')}]`;
|
|
295
300
|
case 'unknown':
|
|
296
301
|
return 'any';
|
|
@@ -310,3 +315,59 @@ function getBasicType(t) {
|
|
|
310
315
|
return 'Event';
|
|
311
316
|
}
|
|
312
317
|
}
|
|
318
|
+
export function overridesAreCompatible(a, b) {
|
|
319
|
+
const bkeys = new Set(Object.keys(b));
|
|
320
|
+
for (const [p, obj] of Object.entries(a)) {
|
|
321
|
+
if (!b[p])
|
|
322
|
+
return false;
|
|
323
|
+
if (!overrideAreCompatible(obj, b[p]))
|
|
324
|
+
return false;
|
|
325
|
+
bkeys.delete(p);
|
|
326
|
+
}
|
|
327
|
+
if (bkeys.size > 0)
|
|
328
|
+
return false;
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
function overrideAreCompatible(a, b) {
|
|
332
|
+
if (a && b) {
|
|
333
|
+
if (a.type !== b.type)
|
|
334
|
+
return false;
|
|
335
|
+
if (a.entityPropPath.length !== b.entityPropPath.length)
|
|
336
|
+
return false;
|
|
337
|
+
if (a.entityPropIsConstructor !== b.entityPropIsConstructor)
|
|
338
|
+
return false;
|
|
339
|
+
for (let i = 0; i < a.entityPropPath.length; i++) {
|
|
340
|
+
if (a.entityPropPath[i] !== b.entityPropPath[i])
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
switch (a.type) {
|
|
344
|
+
case EntityPropOverrideType.ComponentProp: {
|
|
345
|
+
const bt = b;
|
|
346
|
+
if (a.isConstructorProp !== bt.isConstructorProp)
|
|
347
|
+
return false;
|
|
348
|
+
if (a.propName !== bt.propName)
|
|
349
|
+
return false;
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
case EntityPropOverrideType.ContextValue: {
|
|
353
|
+
const bt = b;
|
|
354
|
+
if (a.imp !== bt.imp)
|
|
355
|
+
return false;
|
|
356
|
+
if (a.val !== bt.val)
|
|
357
|
+
return false;
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
case EntityPropOverrideType.Import: {
|
|
361
|
+
const bt = b;
|
|
362
|
+
if (a.imp !== bt.imp)
|
|
363
|
+
return false;
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (!a && b)
|
|
369
|
+
return false;
|
|
370
|
+
if (a && !b)
|
|
371
|
+
return false;
|
|
372
|
+
return true;
|
|
373
|
+
}
|
package/lib/zcomponent.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, ComponentChildren, ConstructorProps } from './component';
|
|
2
2
|
import { ContextManager, Context } from './context';
|
|
3
|
+
import { Entity } from './entity';
|
|
3
4
|
import { ZComponentData } from './interfaces';
|
|
4
5
|
export interface ZComponentOptions {
|
|
5
6
|
data: ZComponentData;
|
|
@@ -35,21 +36,25 @@ export declare class ZComponent<RootType = any> extends Component<RootType> {
|
|
|
35
36
|
nodes: {
|
|
36
37
|
[id: string]: Component | Component[];
|
|
37
38
|
};
|
|
38
|
-
entityByID: Map<string,
|
|
39
|
-
entityByLabel: Map<string,
|
|
39
|
+
entityByID: Map<string, Entity>;
|
|
40
|
+
entityByLabel: Map<string, Entity>;
|
|
40
41
|
private _constructedResolve;
|
|
41
42
|
constructed: Promise<void>;
|
|
42
43
|
isConstructed: boolean;
|
|
43
44
|
private _nodesById;
|
|
44
45
|
private _behaviorsToInitialize;
|
|
46
|
+
private _constructorPropOverridesByEntityID;
|
|
45
47
|
constructor(contextManager: ContextManager, constructorProps: ConstructorProps, _opts: ZComponentOptions);
|
|
46
48
|
private _constructorForNode;
|
|
47
49
|
private _constructorForBehavior;
|
|
48
50
|
private _inflateBehaviors;
|
|
49
51
|
private _wrapBehaviors;
|
|
50
52
|
notifyPropsChanged(entries: Map<string, Set<string>>): void;
|
|
53
|
+
private _initializeOverrides;
|
|
54
|
+
private _initializeConstructorPropOverrides;
|
|
51
55
|
private _initializeComponentProps;
|
|
52
56
|
private _setEntityProp;
|
|
57
|
+
private _setEntityPropPath;
|
|
53
58
|
_getNodeById(id: string): Component | undefined;
|
|
54
59
|
dispose(): never;
|
|
55
60
|
}
|
package/lib/zcomponent.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Context } from './context';
|
|
|
4
4
|
import { isDesignTime } from './contexts/environmentcontext';
|
|
5
5
|
import { TagContext } from './contexts/tagcontext';
|
|
6
6
|
import { computeBehaviorHierarchy, computeNodeHierarchy } from './data';
|
|
7
|
+
import { EntityPropOverrideType } from './interfaces';
|
|
7
8
|
import { Observable } from './observable';
|
|
8
9
|
import { setCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
9
10
|
export class ZComponentContext extends Context {
|
|
@@ -26,8 +27,10 @@ export class ZComponent extends Component {
|
|
|
26
27
|
this.isConstructed = false;
|
|
27
28
|
this._nodesById = new Map();
|
|
28
29
|
this._behaviorsToInitialize = [];
|
|
30
|
+
this._constructorPropOverridesByEntityID = new Map();
|
|
29
31
|
const contextManagerForChildren = contextManager.forkMultiple([ZComponentContext, { zcomponent: this }], [TagContext, {}])[0];
|
|
30
32
|
this.id = this._opts.data.id;
|
|
33
|
+
this._initializeConstructorPropOverrides();
|
|
31
34
|
const rootConstructor = this._constructorForNode(this._opts.data.root);
|
|
32
35
|
if (rootConstructor) {
|
|
33
36
|
this.constructChildren([
|
|
@@ -36,6 +39,7 @@ export class ZComponent extends Component {
|
|
|
36
39
|
}
|
|
37
40
|
this._inflateBehaviors();
|
|
38
41
|
this._initializeComponentProps();
|
|
42
|
+
this._initializeOverrides();
|
|
39
43
|
this.isConstructed = true;
|
|
40
44
|
this._constructedResolve();
|
|
41
45
|
}
|
|
@@ -65,6 +69,7 @@ export class ZComponent extends Component {
|
|
|
65
69
|
...constructorProps,
|
|
66
70
|
...(that._opts.data.entityConstructorProps?.[nodeId] ?? {}),
|
|
67
71
|
...(that._opts.constructorPropReplacement?.[nodeId] ?? {}),
|
|
72
|
+
...(that._constructorPropOverridesByEntityID.get(nodeId) ?? {}),
|
|
68
73
|
children
|
|
69
74
|
};
|
|
70
75
|
setCurrentZComponentConstruction(that);
|
|
@@ -145,6 +150,7 @@ export class ZComponent extends Component {
|
|
|
145
150
|
...constructorProps,
|
|
146
151
|
...(that._opts.data.entityConstructorProps?.[behaviorId] ?? {}),
|
|
147
152
|
...(that._opts.constructorPropReplacement?.[behaviorId] ?? {}),
|
|
153
|
+
...(that._constructorPropOverridesByEntityID.get(behaviorId) ?? {}),
|
|
148
154
|
};
|
|
149
155
|
setCurrentZComponentConstruction(that);
|
|
150
156
|
super(contextManager, instance, constructorProps);
|
|
@@ -205,26 +211,84 @@ export class ZComponent extends Component {
|
|
|
205
211
|
}
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
for (const
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
214
|
+
_initializeOverrides() {
|
|
215
|
+
const overrides = this._opts.data.entityPropOverrides ?? {};
|
|
216
|
+
for (const override of Object.values(overrides)) {
|
|
217
|
+
const entity = this.entityByID.get(override.entityID);
|
|
218
|
+
if (!entity)
|
|
219
|
+
continue;
|
|
220
|
+
try {
|
|
221
|
+
switch (override.type) {
|
|
222
|
+
case EntityPropOverrideType.Import: {
|
|
223
|
+
const v = this._opts.importMapping[override.imp]?.();
|
|
224
|
+
if (!v)
|
|
225
|
+
continue;
|
|
226
|
+
if (v instanceof Observable)
|
|
227
|
+
v.withValue(val => this._setEntityPropPath(entity, override.entityPropPath, val));
|
|
228
|
+
else
|
|
229
|
+
this._setEntityPropPath(entity, override.entityPropPath, v);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case EntityPropOverrideType.ContextValue: {
|
|
233
|
+
const ctx = this._opts.importMapping[override.imp]?.();
|
|
234
|
+
const ctxInstance = entity.contextManager.getOrThrow(ctx);
|
|
235
|
+
const v = ctxInstance[override.val];
|
|
236
|
+
if (!v)
|
|
237
|
+
continue;
|
|
238
|
+
if (v instanceof Observable)
|
|
239
|
+
v.withValue(val => this._setEntityPropPath(entity, override.entityPropPath, val));
|
|
240
|
+
else
|
|
241
|
+
this._setEntityPropPath(entity, override.entityPropPath, v);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case EntityPropOverrideType.ComponentProp: {
|
|
245
|
+
if (override.isConstructorProp) {
|
|
246
|
+
const prop = this._opts.data.constructorProps?.[override.propName];
|
|
247
|
+
if (!prop)
|
|
248
|
+
break;
|
|
249
|
+
const val = this.constructorProps[override.propName] ?? prop.default;
|
|
250
|
+
if (val !== undefined)
|
|
251
|
+
this._setEntityPropPath(entity, override.entityPropPath, val);
|
|
252
|
+
break;
|
|
224
253
|
}
|
|
254
|
+
const v = this[override.propName];
|
|
255
|
+
if (!v)
|
|
256
|
+
continue;
|
|
257
|
+
if (v instanceof Observable)
|
|
258
|
+
v.withValue(val => this._setEntityPropPath(entity, override.entityPropPath, val));
|
|
259
|
+
else
|
|
260
|
+
this._setEntityPropPath(entity, override.entityPropPath, v);
|
|
261
|
+
break;
|
|
225
262
|
}
|
|
226
263
|
}
|
|
227
|
-
}
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
console.log('Unable to set entity prop override', err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
_initializeConstructorPropOverrides() {
|
|
271
|
+
for (const entry of Object.values(this._opts.data.entityPropOverrides ?? {})) {
|
|
272
|
+
if (entry.type !== EntityPropOverrideType.ComponentProp)
|
|
273
|
+
continue;
|
|
274
|
+
if (!entry.isConstructorProp)
|
|
275
|
+
continue;
|
|
276
|
+
if (entry.entityPropPath.length !== 1)
|
|
277
|
+
continue;
|
|
278
|
+
const obj = this._constructorPropOverridesByEntityID.get(entry.entityID) ?? Object.create(null);
|
|
279
|
+
this._constructorPropOverridesByEntityID.set(entry.entityID, obj);
|
|
280
|
+
const prop = this._opts.data.constructorProps?.[entry.propName];
|
|
281
|
+
if (!prop)
|
|
282
|
+
continue;
|
|
283
|
+
const val = this.constructorProps[entry.propName] ?? prop.default;
|
|
284
|
+
if (val !== undefined)
|
|
285
|
+
obj[entry.entityPropPath[0]] = val;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
_initializeComponentProps() {
|
|
289
|
+
const componentProps = this._opts.data.props ?? {};
|
|
290
|
+
for (const prop of Object.values(componentProps)) {
|
|
291
|
+
this[prop.name] = new Observable(prop.default);
|
|
228
292
|
}
|
|
229
293
|
}
|
|
230
294
|
_setEntityProp(entity, prop, v) {
|
|
@@ -233,6 +297,22 @@ export class ZComponent extends Component {
|
|
|
233
297
|
else
|
|
234
298
|
entity[prop] = v;
|
|
235
299
|
}
|
|
300
|
+
_setEntityPropPath(entity, propPath, v) {
|
|
301
|
+
if (propPath.length < 1)
|
|
302
|
+
return;
|
|
303
|
+
const prop = propPath[0];
|
|
304
|
+
let parent = entity;
|
|
305
|
+
let currentKey = prop;
|
|
306
|
+
if (entity[prop] instanceof Observable) {
|
|
307
|
+
parent = entity[prop];
|
|
308
|
+
currentKey = 'value';
|
|
309
|
+
}
|
|
310
|
+
for (let i = 1; i < propPath.length; i++) {
|
|
311
|
+
parent = parent[currentKey];
|
|
312
|
+
currentKey = propPath[i];
|
|
313
|
+
}
|
|
314
|
+
parent[currentKey] = v;
|
|
315
|
+
}
|
|
236
316
|
_getNodeById(id) {
|
|
237
317
|
return this._nodesById.get(id);
|
|
238
318
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zcomponent/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"@types/ua-parser-js": "^0.7.36",
|
|
31
31
|
"parcel": "^2.8.2",
|
|
32
32
|
"typescript": "^4.9.4",
|
|
33
|
-
"ua-parser-js": "^1.0.
|
|
33
|
+
"ua-parser-js": "^1.0.33"
|
|
34
34
|
},
|
|
35
35
|
"zexports": [
|
|
36
36
|
"./lib/components/**/*",
|
|
37
|
-
"./lib/behaviors/**/*"
|
|
37
|
+
"./lib/behaviors/**/*",
|
|
38
|
+
"./lib/contexts/**/*"
|
|
38
39
|
]
|
|
39
40
|
}
|