@zcomponent/core 1.9.1 → 1.11.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/lib/behaviors/ActivateState.d.ts +2 -1
- package/lib/behaviors/ActivateState.js +2 -1
- package/lib/behaviors/CallFunction.d.ts +19 -0
- package/lib/behaviors/CallFunction.js +18 -0
- package/lib/behaviors/ConsoleLog.d.ts +1 -0
- package/lib/behaviors/ConsoleLog.js +1 -0
- package/lib/behaviors/DownloadSnapshot.d.ts +2 -1
- package/lib/behaviors/DownloadSnapshot.js +2 -1
- package/lib/behaviors/LaunchURL.d.ts +1 -0
- package/lib/behaviors/LaunchURL.js +1 -0
- package/lib/behaviors/LogAnalyticsEvent.d.ts +1 -0
- package/lib/behaviors/LogAnalyticsEvent.js +1 -0
- package/lib/behaviors/PauseLayerClip.d.ts +2 -1
- package/lib/behaviors/PauseLayerClip.js +2 -1
- package/lib/behaviors/PlayLayerClip.d.ts +2 -1
- package/lib/behaviors/PlayLayerClip.js +2 -1
- package/lib/behaviors/PlaySound.d.ts +2 -1
- package/lib/behaviors/PlaySound.js +2 -1
- package/lib/behaviors/SetLayerOff.d.ts +2 -1
- package/lib/behaviors/SetLayerOff.js +2 -1
- package/lib/behaviors/ShareSnapshot.d.ts +2 -1
- package/lib/behaviors/ShareSnapshot.js +2 -1
- package/lib/behaviors/ShowTextAlert.d.ts +3 -1
- package/lib/behaviors/ShowTextAlert.js +3 -1
- package/lib/behaviors/TakeSnapshot.d.ts +1 -0
- package/lib/behaviors/TakeSnapshot.js +1 -0
- package/lib/behaviors/ToggleLayerClips.d.ts +2 -1
- package/lib/behaviors/ToggleLayerClips.js +2 -1
- package/lib/behaviors/stream/PauseStream.d.ts +4 -1
- package/lib/behaviors/stream/PauseStream.js +4 -1
- package/lib/behaviors/stream/PlayStream.d.ts +2 -1
- package/lib/behaviors/stream/PlayStream.js +2 -1
- package/lib/behaviors/stream/SeekStream.d.ts +2 -1
- package/lib/behaviors/stream/SeekStream.js +2 -1
- package/lib/behaviors/stream/StopStream.d.ts +2 -1
- package/lib/behaviors/stream/StopStream.js +2 -1
- package/lib/component.d.ts +1 -1
- package/lib/components/Audio.d.ts +25 -13
- package/lib/components/Audio.js +17 -5
- package/lib/components/AudioLayerSettings.d.ts +1 -1
- package/lib/components/DefaultCookieConsent.d.ts +16 -16
- package/lib/components/DefaultLoader.d.ts +6 -6
- package/lib/components/Gamepad.d.ts +21 -21
- package/lib/components/LongLoad.d.ts +1 -1
- package/lib/components/SnapshotUI.d.ts +8 -8
- package/lib/contexts/analyticscontext.d.ts +3 -1
- package/lib/contexts/analyticscontext.js +2 -0
- package/lib/contexts/audiocontextcontext.d.ts +2 -2
- package/lib/contexts/canvascontext.d.ts +6 -6
- package/lib/contexts/cookieconsentcontext.d.ts +7 -7
- package/lib/contexts/environmentcontext.d.ts +5 -5
- package/lib/contexts/gamepadcontext.d.ts +2 -2
- package/lib/contexts/globaltagcontext.d.ts +1 -1
- package/lib/contexts/loadcontext.d.ts +8 -8
- package/lib/contexts/snapshotContext.d.ts +9 -9
- package/lib/contexts/tagcontext.d.ts +2 -2
- package/lib/contexts/tagcontext.js +1 -1
- package/lib/contexts/textalertcontext.d.ts +2 -0
- package/lib/contexts/textalertcontext.js +2 -0
- package/lib/contexts/usereventcontext.d.ts +2 -2
- package/lib/data/core.d.ts +29 -0
- package/lib/data/core.js +6 -0
- package/lib/entity.d.ts +2 -2
- package/lib/selectors.js +29 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +29 -1
- package/lib/zcomponent.d.ts +2 -0
- package/lib/zcomponent.js +68 -1
- package/package.json +1 -1
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityPropOverrideType } from './data/core';
|
|
1
|
+
import { EntityPropOverrideType, FunctionCallType } from './data/core';
|
|
2
2
|
import { getSafeKeyName } from './selectors';
|
|
3
3
|
export var TypeName;
|
|
4
4
|
(function (TypeName) {
|
|
@@ -138,6 +138,8 @@ export function mergeValues(a, b) {
|
|
|
138
138
|
export function mergeProps(a, b) {
|
|
139
139
|
if (a.name !== b.name)
|
|
140
140
|
return;
|
|
141
|
+
if ((a.readonly && !b.readonly) || (b.readonly && !a.readonly))
|
|
142
|
+
return;
|
|
141
143
|
const type = mergeTypes(a.type, b.type);
|
|
142
144
|
if (!type)
|
|
143
145
|
return;
|
|
@@ -154,6 +156,7 @@ export function mergeProps(a, b) {
|
|
|
154
156
|
priority: Math.max(a.priority ?? 0, b.priority ?? 0),
|
|
155
157
|
values: mergeValues(a.values, b.values),
|
|
156
158
|
order: Math.min(a.order ?? 0, b.order ?? 0),
|
|
159
|
+
readonly: a.readonly,
|
|
157
160
|
};
|
|
158
161
|
}
|
|
159
162
|
function mergeComments(a, b) {
|
|
@@ -328,6 +331,31 @@ export function isValidValueForType(def, t, allowUndefined) {
|
|
|
328
331
|
return true;
|
|
329
332
|
return def === t.value;
|
|
330
333
|
case 'function':
|
|
334
|
+
if (typeof def !== 'object')
|
|
335
|
+
return false;
|
|
336
|
+
if (def['_zfn'] !== true)
|
|
337
|
+
return false;
|
|
338
|
+
if (typeof def['args'] !== 'object')
|
|
339
|
+
return false;
|
|
340
|
+
if (def['t'] === FunctionCallType.Context) {
|
|
341
|
+
if (typeof def['imp'] !== 'string' || def['imp'].length === 0)
|
|
342
|
+
return false;
|
|
343
|
+
if (typeof def['fn'] !== 'string' || def['fn'].length === 0)
|
|
344
|
+
return false;
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
if (def['t'] === FunctionCallType.Entity) {
|
|
348
|
+
if (typeof def['entityID'] !== 'string' || def['entityID'].length === 0)
|
|
349
|
+
return false;
|
|
350
|
+
if (typeof def['fn'] !== 'string' || def['fn'].length === 0)
|
|
351
|
+
return false;
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
if (def['t'] === FunctionCallType.Import) {
|
|
355
|
+
if (typeof def['imp'] !== 'string' || def['imp'].length === 0)
|
|
356
|
+
return false;
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
331
359
|
return false;
|
|
332
360
|
}
|
|
333
361
|
return false;
|
package/lib/zcomponent.d.ts
CHANGED
|
@@ -59,8 +59,10 @@ export declare class ZComponent<RootType = any> extends Component<RootType> {
|
|
|
59
59
|
private _constructorForNode;
|
|
60
60
|
private _constructorForBehavior;
|
|
61
61
|
resolveNodeID<T extends Component = Component>(id: string, type?: ConstructorForComponent<T>): T | undefined;
|
|
62
|
+
resolveEntityID<T extends Entity = Entity>(id: string): T | undefined;
|
|
62
63
|
private _inflateBehaviors;
|
|
63
64
|
private _wrapBehaviors;
|
|
65
|
+
private _wrapFunctionCall;
|
|
64
66
|
notifyPropsChanged(entries: Map<string, Set<string>>): void;
|
|
65
67
|
notifyClipsChanged(clips: Set<string>): void;
|
|
66
68
|
private _initializeOverrides;
|
package/lib/zcomponent.js
CHANGED
|
@@ -7,8 +7,9 @@ import { isDesignTime } from './contexts/environmentcontext';
|
|
|
7
7
|
import { isStarted, started } from './contexts/loadcontext';
|
|
8
8
|
import { TagContext } from './contexts/tagcontext';
|
|
9
9
|
import { computeBehaviorHierarchy, computeNodeHierarchy } from './data';
|
|
10
|
+
import { Entity } from './entity';
|
|
10
11
|
import { populateAnimationStructureFromData, populateAnimationTracksFromData, updateClipFromData } from './inflate';
|
|
11
|
-
import { EntityPropOverrideType } from './data/core';
|
|
12
|
+
import { EntityPropOverrideType, FunctionCallType } from './data/core';
|
|
12
13
|
import { Observable } from './observable';
|
|
13
14
|
import { setCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
14
15
|
export class ZComponentContext extends Context {
|
|
@@ -188,6 +189,11 @@ export class ZComponent extends Component {
|
|
|
188
189
|
...(that._opts.constructorPropReplacement?.[behaviorId] ?? {}),
|
|
189
190
|
...(that._constructorPropOverridesByEntityID.get(behaviorId) ?? {}),
|
|
190
191
|
};
|
|
192
|
+
for (const key in constructorProps) {
|
|
193
|
+
const val = constructorProps[key];
|
|
194
|
+
if (val !== undefined && val !== null && val['_zfn'] === true)
|
|
195
|
+
constructorProps[key] = that._wrapFunctionCall(val);
|
|
196
|
+
}
|
|
191
197
|
setCurrentZComponentConstruction(that);
|
|
192
198
|
super(contextManager, instance, constructorProps);
|
|
193
199
|
that.entityByID.set(behaviorId, this);
|
|
@@ -227,6 +233,14 @@ export class ZComponent extends Component {
|
|
|
227
233
|
return entity;
|
|
228
234
|
return undefined;
|
|
229
235
|
}
|
|
236
|
+
resolveEntityID(id) {
|
|
237
|
+
const entity = this.entityByID.get(id);
|
|
238
|
+
if (!entity)
|
|
239
|
+
return this.getZComponentInstance()?.resolveEntityID(id);
|
|
240
|
+
if (!(entity instanceof Entity))
|
|
241
|
+
return undefined;
|
|
242
|
+
return entity;
|
|
243
|
+
}
|
|
230
244
|
_inflateBehaviors() {
|
|
231
245
|
for (const [nodeID, impl, ctx] of this._behaviorsToInitialize) {
|
|
232
246
|
this._wrapBehaviors(nodeID, impl, ctx);
|
|
@@ -248,6 +262,55 @@ export class ZComponent extends Component {
|
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
264
|
}
|
|
265
|
+
_wrapFunctionCall(c) {
|
|
266
|
+
switch (c.t) {
|
|
267
|
+
case FunctionCallType.Context:
|
|
268
|
+
return () => {
|
|
269
|
+
try {
|
|
270
|
+
if (typeof c.imp !== 'string' || typeof c.fn !== 'string' || typeof c.args !== 'object')
|
|
271
|
+
throw new Error('Invalid function call data');
|
|
272
|
+
const contextConstructor = c.resolved;
|
|
273
|
+
if (!contextConstructor)
|
|
274
|
+
throw new Error('Unable to find context');
|
|
275
|
+
const context = this.contextManager.get(contextConstructor);
|
|
276
|
+
if (!context)
|
|
277
|
+
throw new Error('Unable to get context');
|
|
278
|
+
const func = context[c.fn];
|
|
279
|
+
if (!func || typeof func !== 'function')
|
|
280
|
+
throw new Error('Unable to find function on enttiy');
|
|
281
|
+
const tf = func;
|
|
282
|
+
const converted = [];
|
|
283
|
+
for (const key in c.args)
|
|
284
|
+
converted[key] = c.args[key];
|
|
285
|
+
return tf.call(context, ...converted);
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
console.error('Unable to call context function', err);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
case FunctionCallType.Entity:
|
|
292
|
+
return () => {
|
|
293
|
+
try {
|
|
294
|
+
if (typeof c.entityID !== 'string' || typeof c.fn !== 'string' || typeof c.args !== 'object')
|
|
295
|
+
throw new Error('Invalid function call data');
|
|
296
|
+
const entity = this.resolveEntityID(c.entityID);
|
|
297
|
+
if (!entity)
|
|
298
|
+
throw new Error('Unable to find entity');
|
|
299
|
+
const func = entity[c.fn];
|
|
300
|
+
if (!func || typeof func !== 'function')
|
|
301
|
+
throw new Error('Unable to find function on enttiy');
|
|
302
|
+
const tf = func;
|
|
303
|
+
const converted = [];
|
|
304
|
+
for (const key in c.args)
|
|
305
|
+
converted[key] = c.args[key];
|
|
306
|
+
return tf.call(entity, ...converted);
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
console.error('Unable to call entity function', err);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
251
314
|
notifyPropsChanged(entries) {
|
|
252
315
|
for (const [entityID, propSet] of entries.entries()) {
|
|
253
316
|
const entity = this.entityByID.get(entityID);
|
|
@@ -354,6 +417,8 @@ export class ZComponent extends Component {
|
|
|
354
417
|
}
|
|
355
418
|
}
|
|
356
419
|
_setEntityProp(entity, prop, v) {
|
|
420
|
+
if (v !== undefined && v !== null && v['_zfn'] === true)
|
|
421
|
+
v = this._wrapFunctionCall(v);
|
|
357
422
|
if (entity[prop] instanceof Observable)
|
|
358
423
|
entity[prop].value = v;
|
|
359
424
|
else
|
|
@@ -373,6 +438,8 @@ export class ZComponent extends Component {
|
|
|
373
438
|
parent = parent[currentKey];
|
|
374
439
|
currentKey = propPath[i];
|
|
375
440
|
}
|
|
441
|
+
if (v !== undefined && v !== null && v['_zfn'] === true)
|
|
442
|
+
v = this._wrapFunctionCall(v);
|
|
376
443
|
parent[currentKey] = v;
|
|
377
444
|
}
|
|
378
445
|
_getNodeById(id) {
|