@zcomponent/core 1.14.3 → 1.16.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/lib/actionbehavior.d.ts +12 -3
- package/lib/actionbehavior.js +12 -3
- package/lib/animation/animation.d.ts +96 -4
- package/lib/animation/animation.js +93 -0
- package/lib/animation/animationstate.d.ts +52 -2
- package/lib/animation/bezier.d.ts +12 -1
- package/lib/animation/bezier.js +15 -12
- package/lib/animation/clips/clip.d.ts +71 -0
- package/lib/animation/clips/clip.js +68 -0
- package/lib/animation/interpolate.d.ts +17 -0
- package/lib/animation/interpolate.js +71 -0
- package/lib/animation/keyframe.d.ts +24 -1
- package/lib/animation/layer.d.ts +73 -1
- package/lib/animation/layer.js +69 -0
- package/lib/animation/layerclip.d.ts +75 -0
- package/lib/animation/layerclip.js +69 -0
- package/lib/animation/stream.d.ts +49 -7
- package/lib/animation/stream.js +3 -0
- package/lib/animation/tracks/cliptrack.d.ts +64 -0
- package/lib/animation/tracks/cliptrack.js +65 -1
- package/lib/animation/tracks/functiontrack.d.ts +60 -0
- package/lib/animation/tracks/functiontrack.js +62 -3
- package/lib/animation/tracks/propertytrack.d.ts +84 -0
- package/lib/animation/tracks/propertytrack.js +75 -0
- package/lib/animation/tracks/streamtrack.d.ts +51 -0
- package/lib/animation/tracks/streamtrack.js +54 -3
- package/lib/animation/tracks/track.d.ts +56 -0
- package/lib/animation/tracks/track.js +40 -0
- package/lib/behavior.d.ts +37 -0
- package/lib/behavior.js +21 -0
- package/lib/behaviors/ActivateState.d.ts +10 -3
- package/lib/behaviors/ActivateState.js +8 -4
- package/lib/behaviors/CallFunction.d.ts +1 -1
- package/lib/behaviors/CallFunction.js +2 -2
- package/lib/behaviors/ConsoleLog.d.ts +1 -1
- package/lib/behaviors/ConsoleLog.js +2 -2
- package/lib/behaviors/DownloadSnapshot.d.ts +5 -2
- package/lib/behaviors/DownloadSnapshot.js +5 -2
- package/lib/behaviors/LaunchURL.d.ts +1 -1
- package/lib/behaviors/LaunchURL.js +1 -1
- package/lib/behaviors/LogAnalyticsEvent.d.ts +1 -1
- package/lib/behaviors/LogAnalyticsEvent.js +2 -2
- package/lib/behaviors/PauseLayerClip.d.ts +5 -3
- package/lib/behaviors/PauseLayerClip.js +3 -2
- package/lib/behaviors/PlayLayerClip.d.ts +10 -4
- package/lib/behaviors/PlayLayerClip.js +7 -5
- package/lib/behaviors/PlaySound.d.ts +4 -4
- package/lib/behaviors/PlaySound.js +4 -4
- package/lib/behaviors/SetLayerOff.d.ts +4 -3
- package/lib/behaviors/SetLayerOff.js +3 -2
- package/lib/behaviors/ShowTextAlert.d.ts +2 -2
- package/lib/behaviors/ShowTextAlert.js +5 -5
- package/lib/behaviors/ToggleLayerClips.d.ts +4 -3
- package/lib/behaviors/ToggleLayerClips.js +5 -4
- package/lib/behaviors/stream/PauseStream.d.ts +15 -3
- package/lib/behaviors/stream/PauseStream.js +13 -2
- package/lib/behaviors/stream/PlayStream.d.ts +14 -4
- package/lib/behaviors/stream/PlayStream.js +10 -3
- package/lib/behaviors/stream/SeekStream.d.ts +12 -3
- package/lib/behaviors/stream/SeekStream.js +10 -2
- package/lib/behaviors/stream/StopStream.d.ts +11 -3
- package/lib/behaviors/stream/StopStream.js +9 -2
- package/lib/component.d.ts +85 -5
- package/lib/component.js +49 -1
- package/lib/components/Audio.d.ts +14 -5
- package/lib/components/Audio.js +19 -10
- package/lib/components/AudioLayerSettings.d.ts +9 -3
- package/lib/components/AudioLayerSettings.js +9 -3
- package/lib/components/Children.d.ts +7 -2
- package/lib/components/Children.js +6 -1
- package/lib/components/DefaultCookieConsent.d.ts +13 -3
- package/lib/components/DefaultCookieConsent.js +62 -38
- package/lib/components/DefaultLoader.d.ts +14 -9
- package/lib/components/DefaultLoader.js +25 -20
- package/lib/components/Gamepad.d.ts +12 -4
- package/lib/components/Gamepad.js +16 -8
- package/lib/components/LongLoad.d.ts +7 -1
- package/lib/components/LongLoad.js +7 -1
- package/lib/components/SnapshotUI.d.ts +10 -0
- package/lib/components/SnapshotUI.js +24 -0
- package/lib/context.d.ts +117 -0
- package/lib/context.js +50 -71
- package/lib/contexts/analyticscontext.d.ts +6 -0
- package/lib/contexts/analyticscontext.js +6 -0
- package/lib/contexts/audiocontextcontext.d.ts +26 -1
- package/lib/contexts/audiocontextcontext.js +26 -1
- package/lib/contexts/canvascontext.d.ts +59 -1
- package/lib/contexts/canvascontext.js +54 -1
- package/lib/contexts/cookieconsentcontext.d.ts +84 -10
- package/lib/contexts/cookieconsentcontext.js +71 -0
- package/lib/contexts/environmentcontext.d.ts +40 -5
- package/lib/contexts/environmentcontext.js +40 -5
- package/lib/contexts/gamepadcontext.d.ts +38 -0
- package/lib/contexts/gamepadcontext.js +38 -0
- package/lib/contexts/gesturecontext.d.ts +31 -4
- package/lib/contexts/gesturecontext.js +28 -4
- package/lib/contexts/globaltagcontext.d.ts +14 -2
- package/lib/contexts/globaltagcontext.js +13 -1
- package/lib/contexts/loadcontext.d.ts +92 -5
- package/lib/contexts/loadcontext.js +98 -11
- package/lib/contexts/orientationcontext.d.ts +58 -1
- package/lib/contexts/orientationcontext.js +51 -1
- package/lib/contexts/snapshotContext.d.ts +97 -4
- package/lib/contexts/snapshotContext.js +115 -4
- package/lib/contexts/tagcontext.d.ts +56 -2
- package/lib/contexts/tagcontext.js +77 -7
- package/lib/contexts/textalertcontext.d.ts +35 -2
- package/lib/contexts/textalertcontext.js +20 -2
- package/lib/contexts/usereventcontext.d.ts +29 -0
- package/lib/contexts/usereventcontext.js +30 -1
- package/lib/data/animation.d.ts +163 -0
- package/lib/data/animation.js +9 -0
- package/lib/data/change.d.ts +199 -0
- package/lib/data/change.js +190 -0
- package/lib/emitter.d.ts +8 -1
- package/lib/emitter.js +7 -0
- package/lib/entity.d.ts +30 -5
- package/lib/entity.js +23 -7
- package/lib/event.d.ts +19 -2
- package/lib/event.js +19 -2
- package/lib/fractionalindexing.js +38 -42
- package/lib/inflate.d.ts +68 -0
- package/lib/inflate.js +76 -0
- package/lib/observable.d.ts +3 -3
- package/lib/observable.js +4 -4
- package/lib/profile.d.ts +27 -0
- package/lib/profile.js +26 -0
- package/lib/selectors.d.ts +114 -0
- package/lib/selectors.js +159 -7
- package/lib/types.d.ts +215 -0
- package/lib/types.js +110 -1
- package/lib/validators.d.ts +27 -0
- package/lib/validators.js +27 -0
- package/lib/values/values.d.ts +5 -0
- package/lib/values/values.js +5 -0
- package/lib/zcomponent.d.ts +72 -0
- package/lib/zcomponent.js +81 -0
- package/lib/zcomponentconstruction.d.ts +11 -1
- package/lib/zcomponentconstruction.js +10 -0
- package/package.json +7 -2
package/lib/data/change.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { generateKeyBetween, generateNKeysBetween } from '../fractionalindexing';
|
|
2
2
|
import { EntityPropOverrideType } from './core';
|
|
3
3
|
// Simple memoizing of computed hierarchy
|
|
4
|
+
/**
|
|
5
|
+
* Represents a map of node IDs to their child node IDs.
|
|
6
|
+
*/
|
|
4
7
|
const computedHierarchies = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Represents a map of behavior IDs to their child behavior IDs.
|
|
10
|
+
*/
|
|
5
11
|
const computedBehaviors = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Computes and memoizes the hierarchy of nodes.
|
|
14
|
+
*
|
|
15
|
+
* @param nodes - A map of node IDs to node data.
|
|
16
|
+
* @returns The computed hierarchy of nodes.
|
|
17
|
+
*/
|
|
6
18
|
export function computeNodeHierarchy(nodes) {
|
|
7
19
|
let existing = computedHierarchies.get(nodes);
|
|
8
20
|
if (!existing) {
|
|
@@ -29,6 +41,12 @@ export function computeNodeHierarchy(nodes) {
|
|
|
29
41
|
}
|
|
30
42
|
return existing;
|
|
31
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Computes and memoizes the hierarchy of behaviors.
|
|
46
|
+
*
|
|
47
|
+
* @param behaviors - A map of behavior IDs to behavior data.
|
|
48
|
+
* @returns The computed hierarchy of behaviors.
|
|
49
|
+
*/
|
|
32
50
|
export function computeBehaviorHierarchy(behaviors) {
|
|
33
51
|
let existing = computedBehaviors.get(behaviors);
|
|
34
52
|
if (!existing) {
|
|
@@ -55,6 +73,12 @@ export function computeBehaviorHierarchy(behaviors) {
|
|
|
55
73
|
}
|
|
56
74
|
return existing;
|
|
57
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Adds a new node to the specified ZComponentData.
|
|
78
|
+
*
|
|
79
|
+
* @param zcomp - The ZComponentData to which the node is added.
|
|
80
|
+
* @param info - The combined data of the node to be added.
|
|
81
|
+
*/
|
|
58
82
|
export function addNode(zcomp, info) {
|
|
59
83
|
zcomp.nodes[info.data.id] = info.data;
|
|
60
84
|
addNodeLabelToRegister(zcomp, info.data.id);
|
|
@@ -62,11 +86,26 @@ export function addNode(zcomp, info) {
|
|
|
62
86
|
addEntity(zcomp, info.data.id, info);
|
|
63
87
|
computedHierarchies.delete(zcomp.nodes);
|
|
64
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Adds a new behavior to the specified ZComponentData.
|
|
91
|
+
*
|
|
92
|
+
* @param zcomp - The ZComponentData to which the behavior is added.
|
|
93
|
+
* @param info - The combined data of the behavior to be added.
|
|
94
|
+
*/
|
|
65
95
|
export function addBehavior(zcomp, info) {
|
|
66
96
|
zcomp.behaviors[info.data.id] = info.data;
|
|
67
97
|
addEntity(zcomp, info.data.id, info);
|
|
68
98
|
computedBehaviors.delete(zcomp.behaviors);
|
|
69
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Updates a component property in the ZComponentData.
|
|
102
|
+
*
|
|
103
|
+
* @param zcomp - The ZComponentData to update.
|
|
104
|
+
* @param prop - The property name to update.
|
|
105
|
+
* @param isConstructorProp - Indicates if the property is a constructor property.
|
|
106
|
+
* @param newValue - The new value for the property.
|
|
107
|
+
* @param newIsConstructorProp - Indicates if the new value is a constructor property.
|
|
108
|
+
*/
|
|
70
109
|
export function updateComponentProp(zcomp, prop, isConstructorProp, newValue, newIsConstructorProp) {
|
|
71
110
|
if (zcomp.constructorProps === undefined)
|
|
72
111
|
zcomp.constructorProps = {};
|
|
@@ -123,14 +162,33 @@ export function addEntityPropOverride(zcomp, o) {
|
|
|
123
162
|
o.id = idForEntityPropOverride(o);
|
|
124
163
|
zcomp.entityPropOverrides[o.id] = o;
|
|
125
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Deletes an entity property override from the specified ZComponentData.
|
|
167
|
+
*
|
|
168
|
+
* @param zcomp - The ZComponentData to update.
|
|
169
|
+
* @param id - The ID of the EntityPropOverride to delete.
|
|
170
|
+
*/
|
|
126
171
|
export function deleteEntityPropOverride(zcomp, id) {
|
|
127
172
|
if (!zcomp.entityPropOverrides)
|
|
128
173
|
return;
|
|
129
174
|
delete zcomp.entityPropOverrides[id];
|
|
130
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Generates a unique ID for an EntityPropOverride.
|
|
178
|
+
*
|
|
179
|
+
* @param override - The EntityPropOverride for which the ID is generated.
|
|
180
|
+
* @returns The unique ID for the EntityPropOverride.
|
|
181
|
+
*/
|
|
131
182
|
function idForEntityPropOverride(override) {
|
|
132
183
|
return (override.type + ':' + (override.entityPropIsConstructor ? 'constructorprop' : 'prop') + ':' + override.entityID + ':' + override.entityPropPath.join('.'));
|
|
133
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Deep clones the given object.
|
|
187
|
+
*
|
|
188
|
+
* @typeParam T - The type of the object to clone.
|
|
189
|
+
* @param obj - The object to clone.
|
|
190
|
+
* @returns A deep clone of the object.
|
|
191
|
+
*/
|
|
134
192
|
export function clone(obj) {
|
|
135
193
|
try {
|
|
136
194
|
if (typeof structuredClone !== 'undefined')
|
|
@@ -141,6 +199,14 @@ export function clone(obj) {
|
|
|
141
199
|
}
|
|
142
200
|
return JSON.parse(JSON.stringify(obj));
|
|
143
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Checks if two objects are equal by comparing their JSON string representations.
|
|
204
|
+
*
|
|
205
|
+
* @typeParam T - The type of the objects to compare.
|
|
206
|
+
* @param obj1 - The first object to compare.
|
|
207
|
+
* @param obj2 - The second object to compare.
|
|
208
|
+
* @returns True if the objects are equal, otherwise false.
|
|
209
|
+
*/
|
|
144
210
|
export function isEqual(obj1, obj2) {
|
|
145
211
|
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
|
146
212
|
}
|
|
@@ -148,6 +214,14 @@ export function addEntity(zcomp, id, info) {
|
|
|
148
214
|
zcomp.entityProps[id] = info.props;
|
|
149
215
|
zcomp.entityConstructorProps[id] = info.constructorProps;
|
|
150
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Moves nodes to a new parent within the ZComponentData hierarchy.
|
|
219
|
+
*
|
|
220
|
+
* @param zcomp - The ZComponentData containing the nodes.
|
|
221
|
+
* @param nodeIDs - Array of node IDs to be moved.
|
|
222
|
+
* @param newParentID - The ID of the new parent node.
|
|
223
|
+
* @param indx - The index at which to insert the nodes in the new parent's child array.
|
|
224
|
+
*/
|
|
151
225
|
export function moveNodes(zcomp, nodeIDs, newParentID, indx) {
|
|
152
226
|
const parent = zcomp.nodes[newParentID];
|
|
153
227
|
if (!parent)
|
|
@@ -168,6 +242,12 @@ export function moveNodes(zcomp, nodeIDs, newParentID, indx) {
|
|
|
168
242
|
node.parent = { id: newParentID, order: newOrders[i] };
|
|
169
243
|
}
|
|
170
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Deletes a node and its child nodes and associated behaviors from ZComponentData.
|
|
247
|
+
*
|
|
248
|
+
* @param zcomp - The ZComponentData from which the node will be deleted.
|
|
249
|
+
* @param id - The ID of the node to delete.
|
|
250
|
+
*/
|
|
171
251
|
export function deleteNode(zcomp, id) {
|
|
172
252
|
// Delete child nodes
|
|
173
253
|
const children = computeNodeHierarchy(zcomp.nodes)[id] ?? [];
|
|
@@ -183,11 +263,24 @@ export function deleteNode(zcomp, id) {
|
|
|
183
263
|
delete zcomp.nodes[id];
|
|
184
264
|
computedHierarchies.delete(zcomp.nodes);
|
|
185
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Deletes a behavior from ZComponentData.
|
|
268
|
+
*
|
|
269
|
+
* @param zcomp - The ZComponentData from which the behavior will be deleted.
|
|
270
|
+
* @param id - The ID of the behavior to delete.
|
|
271
|
+
*/
|
|
186
272
|
export function deleteBehavior(zcomp, id) {
|
|
187
273
|
deleteEntity(zcomp, id);
|
|
188
274
|
delete zcomp.behaviors[id];
|
|
189
275
|
computedBehaviors.delete(zcomp.behaviors);
|
|
190
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Retrieves combined data for a specific node in ZComponentData.
|
|
279
|
+
*
|
|
280
|
+
* @param zcomp - The ZComponentData containing the node.
|
|
281
|
+
* @param id - The ID of the node.
|
|
282
|
+
* @returns Combined node data or undefined if the node doesn't exist.
|
|
283
|
+
*/
|
|
191
284
|
export function getNodeDataCombined(zcomp, id) {
|
|
192
285
|
const data = zcomp.nodes[id];
|
|
193
286
|
if (!data)
|
|
@@ -198,6 +291,13 @@ export function getNodeDataCombined(zcomp, id) {
|
|
|
198
291
|
constructorProps: zcomp.entityConstructorProps[id] ?? {},
|
|
199
292
|
};
|
|
200
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Retrieves combined data for a specific behavior in ZComponentData.
|
|
296
|
+
*
|
|
297
|
+
* @param zcomp - The ZComponentData containing the behavior.
|
|
298
|
+
* @param id - The ID of the behavior.
|
|
299
|
+
* @returns Combined behavior data or undefined if the behavior doesn't exist.
|
|
300
|
+
*/
|
|
201
301
|
export function getBehaviorDataCombined(zcomp, id) {
|
|
202
302
|
const data = zcomp.behaviors[id];
|
|
203
303
|
if (!data)
|
|
@@ -208,6 +308,14 @@ export function getBehaviorDataCombined(zcomp, id) {
|
|
|
208
308
|
constructorProps: zcomp.entityConstructorProps[id] ?? {},
|
|
209
309
|
};
|
|
210
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Fixes any duplicate index issues in the node hierarchy.
|
|
313
|
+
*
|
|
314
|
+
* @param zcomp - The ZComponentData containing the nodes.
|
|
315
|
+
* @param hierarchy - The computed hierarchy of nodes.
|
|
316
|
+
* @param nodeID - The ID of the parent node.
|
|
317
|
+
* @param indx - The index to start checking for duplicates.
|
|
318
|
+
*/
|
|
211
319
|
export function fixAnyDuplicateIndex(zcomp, hierarchy, nodeID, indx) {
|
|
212
320
|
if (indx < 0)
|
|
213
321
|
return;
|
|
@@ -229,6 +337,14 @@ export function fixAnyDuplicateIndex(zcomp, hierarchy, nodeID, indx) {
|
|
|
229
337
|
const corder = c ? zcomp.nodes[c]?.parent?.order : undefined;
|
|
230
338
|
nodeB.parent.order = generateKeyBetween(nodeA.parent.order, corder ?? null);
|
|
231
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Fixes any duplicate index issues in the behavior hierarchy.
|
|
342
|
+
*
|
|
343
|
+
* @param zcomp - The ZComponentData containing the behaviors.
|
|
344
|
+
* @param behaviors - The computed hierarchy of behaviors.
|
|
345
|
+
* @param nodeID - The ID of the parent node.
|
|
346
|
+
* @param indx - The index to start checking for duplicates.
|
|
347
|
+
*/
|
|
232
348
|
export function fixAnyDuplicateBehaviorsIndex(zcomp, behaviors, nodeID, indx) {
|
|
233
349
|
if (indx < 0)
|
|
234
350
|
return;
|
|
@@ -250,6 +366,14 @@ export function fixAnyDuplicateBehaviorsIndex(zcomp, behaviors, nodeID, indx) {
|
|
|
250
366
|
const corder = c ? zcomp.nodes[c]?.parent?.order : undefined;
|
|
251
367
|
behaviorB.parent.order = generateKeyBetween(behaviorA.parent.order, corder ?? null);
|
|
252
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Calculates the order for a node to be placed at a specific index under a parent.
|
|
371
|
+
*
|
|
372
|
+
* @param zcomp - The ZComponentData containing the nodes.
|
|
373
|
+
* @param parentID - The ID of the parent node.
|
|
374
|
+
* @param indx - The index at which the node is to be placed.
|
|
375
|
+
* @returns The order string for the node.
|
|
376
|
+
*/
|
|
253
377
|
export function nodeOrderForParentIndex(zcomp, parentID, indx) {
|
|
254
378
|
const computed = computeNodeHierarchy(zcomp.nodes);
|
|
255
379
|
const parentChildren = computed[parentID] ?? [];
|
|
@@ -261,6 +385,14 @@ export function nodeOrderForParentIndex(zcomp, parentID, indx) {
|
|
|
261
385
|
const rightOrder = zcomp.nodes[rightID]?.parent?.order ?? null;
|
|
262
386
|
return generateKeyBetween(leftOrder, rightOrder);
|
|
263
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Calculates the order for a behavior to be placed at a specific index under a parent.
|
|
390
|
+
*
|
|
391
|
+
* @param zcomp - The ZComponentData containing the behaviors.
|
|
392
|
+
* @param parentID - The ID of the parent node.
|
|
393
|
+
* @param indx - The index at which the behavior is to be placed.
|
|
394
|
+
* @returns The order string for the behavior.
|
|
395
|
+
*/
|
|
264
396
|
export function behaviorOrderForParentIndex(zcomp, parentID, indx) {
|
|
265
397
|
const computed = computeBehaviorHierarchy(zcomp.behaviors);
|
|
266
398
|
const parentChildren = computed[parentID] ?? [];
|
|
@@ -272,6 +404,12 @@ export function behaviorOrderForParentIndex(zcomp, parentID, indx) {
|
|
|
272
404
|
const rightOrder = zcomp.behaviors[rightID]?.parent?.order ?? null;
|
|
273
405
|
return generateKeyBetween(leftOrder, rightOrder);
|
|
274
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Adds a node's label to the ZComponentData's label register.
|
|
409
|
+
*
|
|
410
|
+
* @param zcomp - The ZComponentData to update.
|
|
411
|
+
* @param id - The ID of the node whose label is to be added.
|
|
412
|
+
*/
|
|
275
413
|
export function addNodeLabelToRegister(zcomp, id) {
|
|
276
414
|
const node = zcomp.nodes[id];
|
|
277
415
|
if (node?.label) {
|
|
@@ -282,6 +420,12 @@ export function addNodeLabelToRegister(zcomp, id) {
|
|
|
282
420
|
zcomp.entitiesByLabel[node.label][node.id] = true;
|
|
283
421
|
}
|
|
284
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Removes a node's label from the ZComponentData's label register.
|
|
425
|
+
*
|
|
426
|
+
* @param zcomp - The ZComponentData to update.
|
|
427
|
+
* @param id - The ID of the node whose label is to be removed.
|
|
428
|
+
*/
|
|
285
429
|
export function removeNodeLabelFromRegister(zcomp, id) {
|
|
286
430
|
const node = zcomp.nodes[id];
|
|
287
431
|
if (!node)
|
|
@@ -295,6 +439,12 @@ export function removeNodeLabelFromRegister(zcomp, id) {
|
|
|
295
439
|
}
|
|
296
440
|
}
|
|
297
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Adds a node's script name to the ZComponentData's script name register.
|
|
444
|
+
*
|
|
445
|
+
* @param zcomp - The ZComponentData to update.
|
|
446
|
+
* @param id - The ID of the node whose script name is to be added.
|
|
447
|
+
*/
|
|
298
448
|
export function addNodeScriptNameToRegister(zcomp, id) {
|
|
299
449
|
const node = zcomp.nodes[id];
|
|
300
450
|
if (node?.scriptName) {
|
|
@@ -305,6 +455,12 @@ export function addNodeScriptNameToRegister(zcomp, id) {
|
|
|
305
455
|
zcomp.entitiesByScriptName[node.scriptName][node.id] = true;
|
|
306
456
|
}
|
|
307
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* Removes a node's script name from the ZComponentData's script name register.
|
|
460
|
+
*
|
|
461
|
+
* @param zcomp - The ZComponentData to update.
|
|
462
|
+
* @param id - The ID of the node whose script name is to be removed.
|
|
463
|
+
*/
|
|
308
464
|
export function removeNodeScriptNameFromRegister(zcomp, id) {
|
|
309
465
|
const node = zcomp.nodes[id];
|
|
310
466
|
if (!node)
|
|
@@ -318,6 +474,13 @@ export function removeNodeScriptNameFromRegister(zcomp, id) {
|
|
|
318
474
|
}
|
|
319
475
|
}
|
|
320
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* Changes the label of a node in the ZComponentData.
|
|
479
|
+
*
|
|
480
|
+
* @param zcomp - The ZComponentData to update.
|
|
481
|
+
* @param id - The ID of the node whose label is to be changed.
|
|
482
|
+
* @param newLabel - The new label for the node.
|
|
483
|
+
*/
|
|
321
484
|
export function changeNodeLabel(zcomp, id, newLabel) {
|
|
322
485
|
const node = zcomp.nodes[id];
|
|
323
486
|
if (!node)
|
|
@@ -329,6 +492,13 @@ export function changeNodeLabel(zcomp, id, newLabel) {
|
|
|
329
492
|
node.label = newLabel;
|
|
330
493
|
addNodeLabelToRegister(zcomp, id);
|
|
331
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Changes the script name of a node in the ZComponentData.
|
|
497
|
+
*
|
|
498
|
+
* @param zcomp - The ZComponentData to update.
|
|
499
|
+
* @param id - The ID of the node whose script name is to be changed.
|
|
500
|
+
* @param newScriptName - The new script name for the node.
|
|
501
|
+
*/
|
|
332
502
|
export function changeNodeScriptName(zcomp, id, newScriptName) {
|
|
333
503
|
const node = zcomp.nodes[id];
|
|
334
504
|
if (!node)
|
|
@@ -340,6 +510,12 @@ export function changeNodeScriptName(zcomp, id, newScriptName) {
|
|
|
340
510
|
node.scriptName = newScriptName;
|
|
341
511
|
addNodeScriptNameToRegister(zcomp, id);
|
|
342
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Deletes an entity and its associated data from ZComponentData.
|
|
515
|
+
*
|
|
516
|
+
* @param zcomp - The ZComponentData to update.
|
|
517
|
+
* @param id - The ID of the entity to delete.
|
|
518
|
+
*/
|
|
343
519
|
export function deleteEntity(zcomp, id) {
|
|
344
520
|
delete zcomp.entityProps[id];
|
|
345
521
|
delete zcomp.entityConstructorProps[id];
|
|
@@ -361,6 +537,13 @@ export function deleteEntity(zcomp, id) {
|
|
|
361
537
|
}
|
|
362
538
|
}
|
|
363
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Iterates over each ancestor of a node and executes a function.
|
|
542
|
+
*
|
|
543
|
+
* @param zcomp - The ZComponentData containing the node.
|
|
544
|
+
* @param id - The ID of the node.
|
|
545
|
+
* @param fn - The function to execute for each ancestor.
|
|
546
|
+
*/
|
|
364
547
|
export function forEachNodeAncestor(zcomp, id, fn) {
|
|
365
548
|
const node = zcomp.nodes[id];
|
|
366
549
|
if (!node || !node.parent)
|
|
@@ -369,6 +552,13 @@ export function forEachNodeAncestor(zcomp, id, fn) {
|
|
|
369
552
|
forEachNodeAncestor(zcomp, node.parent.id, fn);
|
|
370
553
|
}
|
|
371
554
|
const lastNumberRegex = new RegExp(/[0-9]*$/);
|
|
555
|
+
/**
|
|
556
|
+
* Generates a unique label for a node in ZComponentData.
|
|
557
|
+
*
|
|
558
|
+
* @param zcomp - The ZComponentData to check for existing labels.
|
|
559
|
+
* @param label - The base label to make unique.
|
|
560
|
+
* @returns A unique label for the node.
|
|
561
|
+
*/
|
|
372
562
|
export function getUniqueLabel(zcomp, label) {
|
|
373
563
|
lastNumberRegex.lastIndex = 0;
|
|
374
564
|
let startIndex = 1;
|
package/lib/emitter.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for classes that hold a set of functions to be called in response
|
|
3
|
+
* to an event or change in value, e.g. Observable and Event.
|
|
4
|
+
*/
|
|
1
5
|
export declare class Emitter<Args extends Array<any> = []> {
|
|
2
|
-
protected _funcs: [fn: (
|
|
6
|
+
protected _funcs: [fn: (...args: Args) => void, priority: number][];
|
|
3
7
|
private _emitting;
|
|
4
8
|
private _toUnbind;
|
|
5
9
|
private _needsSort;
|
|
6
10
|
private _next;
|
|
7
11
|
private _nextFn;
|
|
12
|
+
/**
|
|
13
|
+
* Clears all listeners from the event.
|
|
14
|
+
*/
|
|
8
15
|
clearListeners(): void;
|
|
9
16
|
/**
|
|
10
17
|
* Add a new handler function
|
package/lib/emitter.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for classes that hold a set of functions to be called in response
|
|
3
|
+
* to an event or change in value, e.g. Observable and Event.
|
|
4
|
+
*/
|
|
1
5
|
export class Emitter {
|
|
2
6
|
constructor() {
|
|
3
7
|
this._funcs = [];
|
|
@@ -5,6 +9,9 @@ export class Emitter {
|
|
|
5
9
|
this._toUnbind = new Set();
|
|
6
10
|
this._needsSort = false;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Clears all listeners from the event.
|
|
14
|
+
*/
|
|
8
15
|
clearListeners() {
|
|
9
16
|
this._funcs = [];
|
|
10
17
|
this._needsSort = false;
|
package/lib/entity.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ConstructorForComponent } from
|
|
2
|
-
import { ContextManager } from
|
|
3
|
-
import { Event } from
|
|
4
|
-
import { Observable } from
|
|
5
|
-
import { ZComponent } from
|
|
1
|
+
import { ConstructorForComponent } from './component';
|
|
2
|
+
import { ContextManager } from './context';
|
|
3
|
+
import { Event } from './event';
|
|
4
|
+
import { Observable } from './observable';
|
|
5
|
+
import { ZComponent } from './zcomponent';
|
|
6
|
+
/**
|
|
7
|
+
* Base class for all components and behaviors.
|
|
8
|
+
*/
|
|
6
9
|
export declare class Entity {
|
|
7
10
|
readonly contextManager: ContextManager;
|
|
8
11
|
private _registered;
|
|
@@ -13,8 +16,21 @@ export declare class Entity {
|
|
|
13
16
|
* An event that is fired as the last act of this entity being destroyed.
|
|
14
17
|
*/
|
|
15
18
|
readonly onDispose: Event<[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of Entity.
|
|
21
|
+
* @param contextManager The current ContextManager
|
|
22
|
+
*/
|
|
16
23
|
constructor(contextManager: ContextManager);
|
|
24
|
+
/**
|
|
25
|
+
* Gets the disposed status of the entity.
|
|
26
|
+
* @returns {boolean} The disposed status.
|
|
27
|
+
*/
|
|
17
28
|
get disposed(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the disposed status of the entity.
|
|
31
|
+
* @param {boolean} v - The new disposed status.
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
18
34
|
private set disposed(value);
|
|
19
35
|
/**
|
|
20
36
|
* If `false`, this entity and its children will no longer participate in the experience.
|
|
@@ -107,7 +123,16 @@ export declare class Entity {
|
|
|
107
123
|
dispose(): never;
|
|
108
124
|
private static callSuperDispose;
|
|
109
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Options that can be passed to the `register` function.
|
|
128
|
+
*/
|
|
110
129
|
export interface RegisterOptions {
|
|
130
|
+
/**
|
|
131
|
+
* The priority of the handler function.
|
|
132
|
+
*/
|
|
111
133
|
priority?: number;
|
|
134
|
+
/**
|
|
135
|
+
* If `true`, the handler function will be bound to the underlying Event or Observable even if this entity is disabled.
|
|
136
|
+
*/
|
|
112
137
|
bindWhenDisabled?: boolean;
|
|
113
138
|
}
|
package/lib/entity.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { Event } from
|
|
2
|
-
import { Observable } from
|
|
3
|
-
import { getCurrentZComponentConstruction } from
|
|
1
|
+
import { Event } from './event';
|
|
2
|
+
import { Observable } from './observable';
|
|
3
|
+
import { getCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all components and behaviors.
|
|
6
|
+
*/
|
|
4
7
|
export class Entity {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Entity.
|
|
10
|
+
* @param contextManager The current ContextManager
|
|
11
|
+
*/
|
|
5
12
|
constructor(contextManager) {
|
|
6
13
|
this.contextManager = contextManager;
|
|
7
14
|
this._registered = [];
|
|
@@ -68,9 +75,18 @@ export class Entity {
|
|
|
68
75
|
this._zcomponent = getCurrentZComponentConstruction();
|
|
69
76
|
this.enabledResolved.addListener(this._updateHandlers);
|
|
70
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the disposed status of the entity.
|
|
80
|
+
* @returns {boolean} The disposed status.
|
|
81
|
+
*/
|
|
71
82
|
get disposed() {
|
|
72
83
|
return this._disposed;
|
|
73
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Sets the disposed status of the entity.
|
|
87
|
+
* @param {boolean} v - The new disposed status.
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
74
90
|
set disposed(v) {
|
|
75
91
|
this._disposed = v;
|
|
76
92
|
}
|
|
@@ -91,11 +107,11 @@ export class Entity {
|
|
|
91
107
|
return this._zcomponent;
|
|
92
108
|
if (this._zcomponent instanceof type)
|
|
93
109
|
return this._zcomponent;
|
|
94
|
-
throw new Error(
|
|
110
|
+
throw new Error('getZComponentInstance called in entity passing wrong kind of ZComponent');
|
|
95
111
|
}
|
|
96
112
|
register(e, fn, priorityOrOptions) {
|
|
97
|
-
const priority =
|
|
98
|
-
const bindWhenDisabled =
|
|
113
|
+
const priority = typeof priorityOrOptions === 'number' ? priorityOrOptions : priorityOrOptions?.priority;
|
|
114
|
+
const bindWhenDisabled = typeof priorityOrOptions === 'number' ? false : priorityOrOptions?.bindWhenDisabled;
|
|
99
115
|
for (const entry of this._registered) {
|
|
100
116
|
if (entry[0] === e && entry[1] === fn)
|
|
101
117
|
return;
|
|
@@ -107,7 +123,7 @@ export class Entity {
|
|
|
107
123
|
}
|
|
108
124
|
unregister(e, fn) {
|
|
109
125
|
e.removeListener(fn);
|
|
110
|
-
this._registered = this._registered.filter(entry =>
|
|
126
|
+
this._registered = this._registered.filter(entry => entry[0] !== e || entry[1] !== fn);
|
|
111
127
|
}
|
|
112
128
|
/**
|
|
113
129
|
* Destroy this entity, cleaning up any resources that it has created and
|
package/lib/event.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Emitter } from
|
|
2
|
-
import { Observable } from
|
|
1
|
+
import { Emitter } from './emitter';
|
|
2
|
+
import { Observable } from './observable';
|
|
3
|
+
/**
|
|
4
|
+
* An event emitter class used to emit events and register listeners.
|
|
5
|
+
*/
|
|
3
6
|
export declare class Event<Args extends Array<any> = []> extends Emitter<Args> {
|
|
4
7
|
hasListeners: Observable<boolean, never>;
|
|
5
8
|
/**
|
|
@@ -8,7 +11,21 @@ export declare class Event<Args extends Array<any> = []> extends Emitter<Args> {
|
|
|
8
11
|
* @param a - The argument to pass to handler functions.
|
|
9
12
|
*/
|
|
10
13
|
emit(...args: Args): void;
|
|
14
|
+
/**
|
|
15
|
+
* Clears all listeners from the event. If there are no listeners, it sets `this.hasListeners.value` to `true`.
|
|
16
|
+
*/
|
|
11
17
|
clearListeners(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a listener to the event. After adding the listener, it sets `this.hasListeners.value` to `true`.
|
|
20
|
+
*
|
|
21
|
+
* @param f - The listener function to add.
|
|
22
|
+
* @param priority - The priority of the listener. Higher priority listeners are called first.
|
|
23
|
+
*/
|
|
12
24
|
addListener(f: (...args: Args) => void, priority?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Removes a listener from the event. If there are no more listeners after the removal, it sets `this.hasListeners.value` to `false`.
|
|
27
|
+
*
|
|
28
|
+
* @param f - The listener function to remove.
|
|
29
|
+
*/
|
|
13
30
|
removeListener(f: (...args: Args) => void): void;
|
|
14
31
|
}
|
package/lib/event.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Emitter } from
|
|
2
|
-
import { Observable } from
|
|
1
|
+
import { Emitter } from './emitter';
|
|
2
|
+
import { Observable } from './observable';
|
|
3
|
+
/**
|
|
4
|
+
* An event emitter class used to emit events and register listeners.
|
|
5
|
+
*/
|
|
3
6
|
export class Event extends Emitter {
|
|
4
7
|
constructor() {
|
|
5
8
|
super(...arguments);
|
|
@@ -13,15 +16,29 @@ export class Event extends Emitter {
|
|
|
13
16
|
emit(...args) {
|
|
14
17
|
super._emit(...args);
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Clears all listeners from the event. If there are no listeners, it sets `this.hasListeners.value` to `true`.
|
|
21
|
+
*/
|
|
16
22
|
clearListeners() {
|
|
17
23
|
super.clearListeners();
|
|
18
24
|
if (!this.hasListeners.value)
|
|
19
25
|
this.hasListeners.value = true;
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Adds a listener to the event. After adding the listener, it sets `this.hasListeners.value` to `true`.
|
|
29
|
+
*
|
|
30
|
+
* @param f - The listener function to add.
|
|
31
|
+
* @param priority - The priority of the listener. Higher priority listeners are called first.
|
|
32
|
+
*/
|
|
21
33
|
addListener(f, priority) {
|
|
22
34
|
super.addListener(f, priority);
|
|
23
35
|
this.hasListeners.value = true;
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Removes a listener from the event. If there are no more listeners after the removal, it sets `this.hasListeners.value` to `false`.
|
|
39
|
+
*
|
|
40
|
+
* @param f - The listener function to remove.
|
|
41
|
+
*/
|
|
25
42
|
removeListener(f) {
|
|
26
43
|
super.removeListener(f);
|
|
27
44
|
if (this._funcs.length === 0 && this.hasListeners.value)
|