@zcomponent/core 0.0.6 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actionbehavior.d.ts +12 -8
- package/lib/actionbehavior.js +24 -16
- package/lib/animation.d.ts +9 -9
- package/lib/behavior.d.ts +25 -12
- package/lib/behavior.js +34 -3
- package/lib/behaviors/PlaySound.d.ts +2 -1
- package/lib/behaviors/PlaySound.js +3 -3
- package/lib/component.d.ts +46 -17
- package/lib/component.js +85 -17
- package/lib/components/Children.d.ts +8 -0
- package/lib/components/Children.js +11 -0
- package/lib/components/DefaultLoader.d.ts +6 -6
- package/lib/components/DefaultLoader.js +20 -20
- package/lib/components/Gamepad.d.ts +68 -0
- package/lib/components/Gamepad.js +131 -0
- package/lib/components/LongLoad.d.ts +5 -5
- package/lib/components/LongLoad.js +2 -2
- package/lib/context.d.ts +39 -23
- package/lib/context.js +135 -46
- package/lib/contexts/analyticscontext.d.ts +3 -4
- package/lib/contexts/analyticscontext.js +10 -10
- package/lib/contexts/canvascontext.d.ts +12 -9
- package/lib/contexts/canvascontext.js +56 -51
- package/lib/contexts/cookieconsentcontext.d.ts +9 -10
- package/lib/contexts/cookieconsentcontext.js +19 -23
- package/lib/contexts/environmentcontext.d.ts +4 -5
- package/lib/contexts/environmentcontext.js +8 -7
- package/lib/contexts/gamepadcontext.d.ts +40 -0
- package/lib/contexts/gamepadcontext.js +99 -0
- package/lib/contexts/loadcontext.d.ts +15 -10
- package/lib/contexts/loadcontext.js +48 -51
- package/lib/contexts/tagcontext.d.ts +13 -0
- package/lib/contexts/tagcontext.js +57 -0
- package/lib/contexts/usereventcontext.d.ts +5 -5
- package/lib/contexts/usereventcontext.js +14 -19
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/interfaces.d.ts +9 -9
- package/lib/observable.d.ts +52 -8
- package/lib/observable.js +37 -0
- package/lib/selectors.js +4 -4
- package/lib/types.d.ts +3 -3
- package/lib/zcomponent.d.ts +13 -12
- package/lib/zcomponent.js +31 -38
- package/lib/zcomponentconstruction.d.ts +3 -0
- package/lib/zcomponentconstruction.js +7 -0
- package/package.json +3 -4
package/lib/actionbehavior.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { Behavior
|
|
1
|
+
import { Behavior } from "./behavior";
|
|
2
|
+
import { Component } from "./component";
|
|
2
3
|
import { ContextManager } from "./context";
|
|
3
|
-
export interface ActionBehaviorConstructorProps
|
|
4
|
+
export interface ActionBehaviorConstructorProps {
|
|
4
5
|
/** @zprop
|
|
5
6
|
* @zvalues events
|
|
6
7
|
*/
|
|
7
8
|
event: string;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class ActionBehavior<ConstructorProps extends ActionBehaviorConstructorProps = ActionBehaviorConstructorProps> extends Behavior<any, ConstructorProps> {
|
|
10
9
|
/**
|
|
11
10
|
* @zprop
|
|
12
|
-
* @zdefault
|
|
11
|
+
* @zdefault false
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
runAtEditTime: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class ActionBehavior<ConstructorProps extends ActionBehaviorConstructorProps = ActionBehaviorConstructorProps> extends Behavior<Component> {
|
|
16
|
+
protected constructorProps: ConstructorProps;
|
|
17
|
+
constructor(contextManager: ContextManager, instance: Component, constructorProps: ConstructorProps);
|
|
18
|
+
private _updateRegistration;
|
|
19
|
+
private _perform;
|
|
20
|
+
abstract perform(...args: any[]): any;
|
|
17
21
|
}
|
package/lib/actionbehavior.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { Behavior } from "./behavior";
|
|
2
|
-
import { isEditTime } from "./contexts/environmentcontext";
|
|
2
|
+
import { EnvironmentContext, isEditTime } from "./contexts/environmentcontext";
|
|
3
3
|
import { Event } from "./event";
|
|
4
4
|
export class ActionBehavior extends Behavior {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.register(evt, e => {
|
|
15
|
-
this.perform();
|
|
16
|
-
if (e && typeof e === 'object' && typeof e['stopPropagation'] === 'function') {
|
|
17
|
-
e['stopPropagation'].call(e);
|
|
5
|
+
constructor(contextManager, instance, constructorProps) {
|
|
6
|
+
super(contextManager, instance);
|
|
7
|
+
this.constructorProps = constructorProps;
|
|
8
|
+
this._updateRegistration = () => {
|
|
9
|
+
const evt = this.instance[this.constructorProps.event];
|
|
10
|
+
if (evt instanceof Event) {
|
|
11
|
+
this.unregister(evt, this._perform);
|
|
12
|
+
if (this.enabledResolved.value && (!isEditTime(this.contextManager) || this.constructorProps.runAtEditTime === true)) {
|
|
13
|
+
this.register(evt, this._perform);
|
|
18
14
|
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
this._perform = (...args) => {
|
|
18
|
+
if (!this.enabledResolved.value)
|
|
19
|
+
return;
|
|
20
|
+
this.perform(...args);
|
|
21
|
+
const e = args[0];
|
|
22
|
+
if (e && typeof e === 'object' && typeof e['stopPropagation'] === 'function') {
|
|
23
|
+
e['stopPropagation'].call(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const env = contextManager.get(EnvironmentContext);
|
|
27
|
+
this.register(env.editTime, this._updateRegistration);
|
|
28
|
+
this.register(this.enabledResolved, this._updateRegistration);
|
|
21
29
|
}
|
|
22
30
|
}
|
package/lib/animation.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ByID<T> = {
|
|
2
2
|
[id: string]: T | undefined;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type ByNodeProperty<T> = {
|
|
5
5
|
[id: string]: {
|
|
6
6
|
[id: string]: T | undefined;
|
|
7
7
|
} | undefined;
|
|
@@ -10,7 +10,7 @@ export interface Animation {
|
|
|
10
10
|
clips: ByID<Clip>;
|
|
11
11
|
layers: ByID<Layer>;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type BlendType = 'overlay' | 'add';
|
|
14
14
|
export interface FadeParameters {
|
|
15
15
|
time: number;
|
|
16
16
|
pin?: 'start' | 'middle' | 'end';
|
|
@@ -25,7 +25,7 @@ export interface LayerClip {
|
|
|
25
25
|
reverse?: boolean;
|
|
26
26
|
playbackSpeed?: number;
|
|
27
27
|
}
|
|
28
|
-
export
|
|
28
|
+
export type Clip = StateClip | TimelineClip;
|
|
29
29
|
export interface BaseClip {
|
|
30
30
|
type: 'timeline' | 'state';
|
|
31
31
|
}
|
|
@@ -48,7 +48,7 @@ export interface TimelineClip extends BaseClip {
|
|
|
48
48
|
defaultFadeParameters?: FadeParameters;
|
|
49
49
|
timeSourceTrack?: string;
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export type Track = PropertyTrack | ClipTrack | StreamTrack | FunctionTrack | LabelTrack;
|
|
52
52
|
export interface BaseTrack {
|
|
53
53
|
type: 'property' | 'clip' | 'stream' | 'function' | 'label';
|
|
54
54
|
}
|
|
@@ -58,9 +58,9 @@ export interface Keyframe<T> {
|
|
|
58
58
|
label?: string;
|
|
59
59
|
easing?: Easing;
|
|
60
60
|
}
|
|
61
|
-
export
|
|
62
|
-
export
|
|
63
|
-
export
|
|
61
|
+
export type Easing = 'linear' | 'step' | 'bounce' | Bezier[];
|
|
62
|
+
export type BezierCP = [number, number];
|
|
63
|
+
export type Bezier = [
|
|
64
64
|
BezierCP,
|
|
65
65
|
BezierCP,
|
|
66
66
|
[number, number]
|
|
@@ -105,7 +105,7 @@ export interface FunctionTrack extends BaseTrack {
|
|
|
105
105
|
type: 'function';
|
|
106
106
|
data: FunctionTrackEntry[];
|
|
107
107
|
}
|
|
108
|
-
export
|
|
108
|
+
export type FunctionTrackEntry = EntityFunctionTrackEntry | ImportFunctionTrackEntry;
|
|
109
109
|
export interface BaseFunctionTrackEntry {
|
|
110
110
|
type: 'entity' | 'import';
|
|
111
111
|
args: any[];
|
package/lib/behavior.d.ts
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import { Component } from './component';
|
|
1
|
+
import { Component, ConstructorForComponent } from './component';
|
|
2
2
|
import { ContextManager } from './context';
|
|
3
3
|
import { Event } from './event';
|
|
4
4
|
import { Observable } from './observable';
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
contextManager: ContextManager;
|
|
5
|
+
import { ZComponent } from './zcomponent';
|
|
6
|
+
export type BehaviorConstructor<BehaviorType = Behavior, K extends Component = Component> = BehaviorType extends Behavior<K> ? new (contextManager: ContextManager, instance: K, ...args: any[]) => BehaviorType : never;
|
|
7
|
+
export type ConstructorPropsOfBehavior<BehaviorType> = BehaviorType extends Behavior<infer R> ? R : never;
|
|
8
|
+
export type BehaviorConstructorProps = {
|
|
9
|
+
[id: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
export declare class Behavior<InstanceType extends Component = Component> {
|
|
12
|
+
protected readonly contextManager: ContextManager;
|
|
13
|
+
readonly instance: InstanceType;
|
|
13
14
|
private static callSuperDispose;
|
|
14
15
|
onDispose: Event<[]>;
|
|
15
|
-
instance: InstanceType;
|
|
16
16
|
private _registered;
|
|
17
|
-
|
|
17
|
+
private _zcomponent;
|
|
18
|
+
constructor(contextManager: ContextManager, instance: InstanceType);
|
|
19
|
+
getZComponentInstance<T extends ZComponent = ZComponent>(type?: ConstructorForComponent<T>): T | undefined;
|
|
20
|
+
private _updateEnabledResolved;
|
|
21
|
+
/**
|
|
22
|
+
* @zprop
|
|
23
|
+
* @zdefault true
|
|
24
|
+
* @zgroup Behavior
|
|
25
|
+
* @zgrouppriority 10
|
|
26
|
+
*/
|
|
27
|
+
enabled: Observable<boolean, never>;
|
|
28
|
+
enabledResolved: Observable<boolean, never>;
|
|
18
29
|
register<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
19
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;
|
|
20
33
|
dispose(): never;
|
|
21
34
|
}
|
|
22
35
|
export declare function shouldBehaviorRunAtDesignTime(b: BehaviorConstructor): boolean;
|
|
23
|
-
export declare function registerBehaviorRunAtDesignTime(b: BehaviorConstructor): Set<new (
|
|
36
|
+
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,36 @@
|
|
|
1
1
|
import { Event } from './event';
|
|
2
2
|
import { Observable } from './observable';
|
|
3
|
+
import { getCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
3
4
|
export class Behavior {
|
|
4
|
-
constructor(
|
|
5
|
-
this.constructorProps = constructorProps;
|
|
5
|
+
constructor(contextManager, instance) {
|
|
6
6
|
this.contextManager = contextManager;
|
|
7
|
+
this.instance = instance;
|
|
7
8
|
this.onDispose = new Event();
|
|
8
9
|
this._registered = [];
|
|
9
|
-
this.
|
|
10
|
+
this._updateEnabledResolved = () => {
|
|
11
|
+
let newValue = this.enabled.value;
|
|
12
|
+
if (this.instance.enabledResolved?.value === false)
|
|
13
|
+
newValue = false;
|
|
14
|
+
if (newValue !== this.enabledResolved.value) {
|
|
15
|
+
this.enabledResolved.value = newValue;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
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
|
+
this.register(this.enabled, this._updateEnabledResolved);
|
|
28
|
+
this.register(instance.enabledResolved, this._updateEnabledResolved);
|
|
29
|
+
}
|
|
30
|
+
getZComponentInstance(type) {
|
|
31
|
+
if (!type)
|
|
32
|
+
return this._zcomponent;
|
|
33
|
+
return (type && this._zcomponent instanceof type) ? this._zcomponent : undefined;
|
|
10
34
|
}
|
|
11
35
|
register(e, fn) {
|
|
12
36
|
if (e instanceof Event)
|
|
@@ -15,6 +39,13 @@ export class Behavior {
|
|
|
15
39
|
e.withValue(fn);
|
|
16
40
|
this._registered.push([e, fn]);
|
|
17
41
|
}
|
|
42
|
+
unregister(e, fn) {
|
|
43
|
+
if (e instanceof Event)
|
|
44
|
+
e.unbindfn(fn);
|
|
45
|
+
else if (e instanceof Observable)
|
|
46
|
+
e.removeWithValue(fn);
|
|
47
|
+
this._registered = this._registered.filter(entry => (entry[0] !== e || entry[1] !== fn));
|
|
48
|
+
}
|
|
18
49
|
dispose() {
|
|
19
50
|
for (const entry of this._registered) {
|
|
20
51
|
if (entry[0] instanceof Event)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActionBehavior, ActionBehaviorConstructorProps } from "../actionbehavior";
|
|
2
|
+
import { Component } from "../component";
|
|
2
3
|
import { ContextManager } from "../context";
|
|
3
4
|
export interface PlaySoundProps extends ActionBehaviorConstructorProps {
|
|
4
5
|
/** The URL of the file to play
|
|
@@ -16,7 +17,7 @@ export interface PlaySoundProps extends ActionBehaviorConstructorProps {
|
|
|
16
17
|
*/
|
|
17
18
|
export declare class PlaySound extends ActionBehavior<PlaySoundProps> {
|
|
18
19
|
private _elm;
|
|
19
|
-
constructor(
|
|
20
|
+
constructor(contextManager: ContextManager, instance: Component, props: PlaySoundProps);
|
|
20
21
|
perform(): void;
|
|
21
22
|
/** @zprop */
|
|
22
23
|
preview(): void;
|
|
@@ -8,10 +8,9 @@ import { registerLoadable } from "../contexts/loadcontext";
|
|
|
8
8
|
* @zgroup Actions
|
|
9
9
|
*/
|
|
10
10
|
export class PlaySound extends ActionBehavior {
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
11
|
+
constructor(contextManager, instance, props) {
|
|
12
|
+
super(contextManager, instance, props);
|
|
13
13
|
this._elm = document.createElement('audio');
|
|
14
|
-
this._elm.preload = 'auto';
|
|
15
14
|
registerLoadable(contextManager, new Promise((resolve, reject) => {
|
|
16
15
|
this._elm.addEventListener('canplaythrough', () => resolve());
|
|
17
16
|
this._elm.addEventListener('error', err => {
|
|
@@ -20,6 +19,7 @@ export class PlaySound extends ActionBehavior {
|
|
|
20
19
|
});
|
|
21
20
|
}));
|
|
22
21
|
this._elm.src = props.source;
|
|
22
|
+
this._elm.load();
|
|
23
23
|
}
|
|
24
24
|
perform() {
|
|
25
25
|
this._elm.currentTime = 0;
|
package/lib/component.d.ts
CHANGED
|
@@ -1,30 +1,59 @@
|
|
|
1
1
|
import { ContextManager } from './context';
|
|
2
2
|
import { Event } from './event';
|
|
3
3
|
import { Observable } from './observable';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
4
|
+
import { ZComponent } from './zcomponent';
|
|
5
|
+
export type ConstructorPropsOfComponent<ComponentType> = ComponentType extends Component<any, infer R> ? R : never;
|
|
6
|
+
export type ComponentConstructor<ConstructorPropsType extends ConstructorProps, ComponentType extends Component> = new (props: ConstructorPropsType, contextManager: ContextManager) => ComponentType;
|
|
7
|
+
export type ConstructorForComponent<ComponentType extends Component = Component> = new (contextManager: ContextManager, props: ComponentType extends Component<any, infer PropsType> ? PropsType : never) => ComponentType;
|
|
8
|
+
export type ComponentChild<ComponentType extends Component> = [ConstructorForComponent<ComponentType>, ComponentType extends Component<any, infer U> ? U : never] | [
|
|
9
|
+
ConstructorForComponent<ComponentType>,
|
|
10
|
+
ComponentType extends Component<any, infer U> ? U : never,
|
|
11
|
+
Observable<ComponentType>
|
|
12
|
+
];
|
|
13
|
+
export type ComponentChildren = ComponentChild<Component>[];
|
|
8
14
|
export interface ConstructorProps {
|
|
15
|
+
[id: string]: any;
|
|
9
16
|
children?: ComponentChildren;
|
|
10
17
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
root?: RootType;
|
|
19
|
-
onDispose: Event<[]>;
|
|
20
|
-
children: Component[];
|
|
18
|
+
export declare class Component<ElementType = any, ConstructorPropsType extends ConstructorProps = ConstructorProps> {
|
|
19
|
+
readonly contextManager: ContextManager;
|
|
20
|
+
protected constructorProps?: ConstructorPropsType | undefined;
|
|
21
|
+
element?: ElementType;
|
|
22
|
+
readonly onDispose: Event<[]>;
|
|
23
|
+
readonly children: Component[];
|
|
24
|
+
parent?: Component;
|
|
21
25
|
disposed: boolean;
|
|
22
26
|
private _registered;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
private _zcomponent;
|
|
28
|
+
constructor(contextManager: ContextManager, constructorProps?: ConstructorPropsType | undefined);
|
|
29
|
+
constructChildren(children: ComponentChildren, contextManager?: ContextManager): void;
|
|
30
|
+
getZComponentInstance<T extends ZComponent = ZComponent>(type?: ConstructorForComponent<T>): T | undefined;
|
|
31
|
+
appendChild(c: Component): void;
|
|
32
|
+
removeChild(c: Component): void;
|
|
33
|
+
remove(): void;
|
|
34
|
+
get elementsResolved(): any[];
|
|
35
|
+
/**
|
|
36
|
+
* @zprop
|
|
37
|
+
* @zdefault true
|
|
38
|
+
* @zgroup Behavior
|
|
39
|
+
* @group Behavior
|
|
40
|
+
* @zgrouppriority 10
|
|
41
|
+
*/
|
|
42
|
+
enabled: Observable<boolean, never>;
|
|
43
|
+
enabledResolved: Observable<boolean, never>;
|
|
44
|
+
/**
|
|
45
|
+
* @zprop
|
|
46
|
+
* @zgroup Other
|
|
47
|
+
* @group Other
|
|
48
|
+
* @zgrouppriority 0
|
|
49
|
+
*/
|
|
50
|
+
tags: Observable<string[], never>;
|
|
26
51
|
protected register<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
27
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
|
+
private _updateEnabledResolved;
|
|
56
|
+
private _updateTags;
|
|
28
57
|
dispose(): never;
|
|
29
58
|
private static callSuperDispose;
|
|
30
59
|
}
|
package/lib/component.js
CHANGED
|
@@ -1,30 +1,90 @@
|
|
|
1
|
+
import { TagContext } from './contexts/tagcontext';
|
|
1
2
|
import { Event } from './event';
|
|
2
3
|
import { Observable } from './observable';
|
|
4
|
+
import { getCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
3
5
|
export class Component {
|
|
4
|
-
constructor(
|
|
5
|
-
this.constructorProps = constructorProps;
|
|
6
|
+
constructor(contextManager, constructorProps) {
|
|
6
7
|
this.contextManager = contextManager;
|
|
7
|
-
this.
|
|
8
|
+
this.constructorProps = constructorProps;
|
|
8
9
|
this.onDispose = new Event();
|
|
9
10
|
this.children = [];
|
|
10
11
|
this.disposed = false;
|
|
11
12
|
this._registered = [];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
/**
|
|
23
|
+
* @zprop
|
|
24
|
+
* @zgroup Other
|
|
25
|
+
* @group Other
|
|
26
|
+
* @zgrouppriority 0
|
|
27
|
+
*/
|
|
28
|
+
this.tags = new Observable([]);
|
|
29
|
+
this._updateEnabledResolved = () => {
|
|
30
|
+
let newValue = this.enabled.value;
|
|
31
|
+
if (this.parent?.enabledResolved?.value === false)
|
|
32
|
+
newValue = false;
|
|
33
|
+
if (newValue !== this.enabledResolved.value) {
|
|
34
|
+
this.enabledResolved.value = newValue;
|
|
35
|
+
for (const child of this.children)
|
|
36
|
+
child._updateEnabledResolved();
|
|
25
37
|
}
|
|
38
|
+
};
|
|
39
|
+
this._updateTags = () => {
|
|
40
|
+
const context = this.contextManager.get(TagContext);
|
|
41
|
+
context.registerComponent(this, this.tags.value);
|
|
42
|
+
};
|
|
43
|
+
this._zcomponent = getCurrentZComponentConstruction();
|
|
44
|
+
this.constructChildren(constructorProps?.children ?? []);
|
|
45
|
+
this.register(this.enabled, this._updateEnabledResolved);
|
|
46
|
+
this.register(this.tags, this._updateTags);
|
|
47
|
+
}
|
|
48
|
+
constructChildren(children, contextManager) {
|
|
49
|
+
contextManager = contextManager ?? this.contextManager;
|
|
50
|
+
for (const [constructor, props, ref] of children) {
|
|
51
|
+
const instance = new constructor(contextManager, props);
|
|
52
|
+
this.appendChild(instance);
|
|
53
|
+
if (ref)
|
|
54
|
+
ref.value = instance;
|
|
26
55
|
}
|
|
27
56
|
}
|
|
57
|
+
getZComponentInstance(type) {
|
|
58
|
+
if (!type)
|
|
59
|
+
return this._zcomponent;
|
|
60
|
+
return (type && this._zcomponent instanceof type) ? this._zcomponent : undefined;
|
|
61
|
+
}
|
|
62
|
+
appendChild(c) {
|
|
63
|
+
c.remove();
|
|
64
|
+
this.children.push(c);
|
|
65
|
+
c.parent = this;
|
|
66
|
+
c._updateEnabledResolved();
|
|
67
|
+
}
|
|
68
|
+
removeChild(c) {
|
|
69
|
+
const indx = this.children.indexOf(c);
|
|
70
|
+
if (indx >= 0)
|
|
71
|
+
this.children.splice(indx, 1);
|
|
72
|
+
}
|
|
73
|
+
remove() {
|
|
74
|
+
this.parent?.removeChild(this);
|
|
75
|
+
}
|
|
76
|
+
get elementsResolved() {
|
|
77
|
+
if (this.element !== undefined) {
|
|
78
|
+
if (Array.isArray(this.element))
|
|
79
|
+
return this.element;
|
|
80
|
+
return [this.element];
|
|
81
|
+
}
|
|
82
|
+
const ret = [];
|
|
83
|
+
for (const child of this.children) {
|
|
84
|
+
ret.push(...child.elementsResolved);
|
|
85
|
+
}
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
28
88
|
register(e, fn) {
|
|
29
89
|
if (e instanceof Event)
|
|
30
90
|
e.bindfn(fn);
|
|
@@ -32,6 +92,13 @@ export class Component {
|
|
|
32
92
|
e.withValue(fn);
|
|
33
93
|
this._registered.push([e, fn]);
|
|
34
94
|
}
|
|
95
|
+
unregister(e, fn) {
|
|
96
|
+
if (e instanceof Event)
|
|
97
|
+
e.unbindfn(fn);
|
|
98
|
+
else if (e instanceof Observable)
|
|
99
|
+
e.removeWithValue(fn);
|
|
100
|
+
this._registered = this._registered.filter(entry => (entry[0] !== e || entry[1] !== fn));
|
|
101
|
+
}
|
|
35
102
|
dispose() {
|
|
36
103
|
this.disposed = true;
|
|
37
104
|
for (const child of this.children) {
|
|
@@ -40,7 +107,7 @@ export class Component {
|
|
|
40
107
|
}
|
|
41
108
|
catch (err) { }
|
|
42
109
|
}
|
|
43
|
-
this.children =
|
|
110
|
+
this.children.length = 0;
|
|
44
111
|
for (const entry of this._registered) {
|
|
45
112
|
if (entry[0] instanceof Event)
|
|
46
113
|
entry[0].unbindfn(entry[1]);
|
|
@@ -50,6 +117,7 @@ export class Component {
|
|
|
50
117
|
this._registered = [];
|
|
51
118
|
this.onDispose.emit();
|
|
52
119
|
this.onDispose.clear();
|
|
120
|
+
this.contextManager.get(TagContext).unregisterComponent(this);
|
|
53
121
|
return undefined;
|
|
54
122
|
}
|
|
55
123
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Component } from "../component";
|
|
2
|
+
/**
|
|
3
|
+
* @zcomponent
|
|
4
|
+
*/
|
|
5
|
+
export class Children extends Component {
|
|
6
|
+
constructor(contextManager, props) {
|
|
7
|
+
super(contextManager, props);
|
|
8
|
+
const zcomponent = this.getZComponentInstance();
|
|
9
|
+
this.constructChildren(zcomponent?.constructorProps?.children ?? []);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Component, Observable,
|
|
2
|
-
export interface DefaultLoaderConstructorProps
|
|
1
|
+
import { Component, Observable, ContextManager } from "..";
|
|
2
|
+
export interface DefaultLoaderConstructorProps {
|
|
3
3
|
/** @zprop
|
|
4
4
|
* @zgroup Appearance
|
|
5
5
|
* @zgrouppriority 10
|
|
@@ -7,7 +7,7 @@ export interface DefaultLoaderConstructorProps extends ConstructorProps {
|
|
|
7
7
|
* @zvalues files *.png
|
|
8
8
|
* @zvalues files *.jpg
|
|
9
9
|
*/
|
|
10
|
-
backgroundImage
|
|
10
|
+
backgroundImage: string;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* The DefaultLoader shows a customizable loading bar while the assets of your experience are being downloaded and parsed by the browser.
|
|
@@ -16,8 +16,8 @@ export interface DefaultLoaderConstructorProps extends ConstructorProps {
|
|
|
16
16
|
* @zicon loader
|
|
17
17
|
* @zgroup Advanced
|
|
18
18
|
*/
|
|
19
|
-
export declare class DefaultLoader extends Component
|
|
20
|
-
|
|
19
|
+
export declare class DefaultLoader extends Component {
|
|
20
|
+
element: HTMLDivElement;
|
|
21
21
|
/** @zprop
|
|
22
22
|
* @zdefault false
|
|
23
23
|
* @zgroup Design Time
|
|
@@ -54,7 +54,7 @@ export declare class DefaultLoader extends Component<DefaultLoaderConstructorPro
|
|
|
54
54
|
zIndex: Observable<number>;
|
|
55
55
|
private _percentageElement;
|
|
56
56
|
private _attached;
|
|
57
|
-
constructor(
|
|
57
|
+
constructor(contextManager: ContextManager, constructorProps: DefaultLoaderConstructorProps);
|
|
58
58
|
private _updatePercentage;
|
|
59
59
|
private _updateVisibility;
|
|
60
60
|
private _update;
|
|
@@ -7,9 +7,9 @@ import { Component, useCanvas, Observable, isDesignTime, useIsLoaded, useLoadPer
|
|
|
7
7
|
* @zgroup Advanced
|
|
8
8
|
*/
|
|
9
9
|
export class DefaultLoader extends Component {
|
|
10
|
-
constructor(
|
|
11
|
-
super(
|
|
12
|
-
this.
|
|
10
|
+
constructor(contextManager, constructorProps) {
|
|
11
|
+
super(contextManager, constructorProps);
|
|
12
|
+
this.element = document.createElement('div');
|
|
13
13
|
/** @zprop
|
|
14
14
|
* @zdefault false
|
|
15
15
|
* @zgroup Design Time
|
|
@@ -28,11 +28,11 @@ export class DefaultLoader extends Component {
|
|
|
28
28
|
if (isDesignTime(this.contextManager) && this.preview.value)
|
|
29
29
|
shouldBeAttached = true;
|
|
30
30
|
if (!this._attached && shouldBeAttached) {
|
|
31
|
-
document.body.appendChild(this.
|
|
31
|
+
document.body.appendChild(this.element);
|
|
32
32
|
this._attached = true;
|
|
33
33
|
}
|
|
34
34
|
else if (this._attached && !shouldBeAttached) {
|
|
35
|
-
this.
|
|
35
|
+
this.element.remove();
|
|
36
36
|
this._attached = false;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
@@ -40,25 +40,25 @@ export class DefaultLoader extends Component {
|
|
|
40
40
|
if (this.disposed)
|
|
41
41
|
return;
|
|
42
42
|
const rect = useCanvas(this.contextManager).getBoundingClientRect();
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
43
|
+
this.element.style.left = rect.left.toString() + "px";
|
|
44
|
+
this.element.style.top = rect.top.toString() + "px";
|
|
45
|
+
this.element.style.width = rect.width.toString() + "px";
|
|
46
|
+
this.element.style.height = rect.height.toString() + "px";
|
|
47
47
|
requestAnimationFrame(this._update);
|
|
48
48
|
};
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
if (
|
|
52
|
-
this.
|
|
49
|
+
this.element.innerHTML = loaderHTML;
|
|
50
|
+
this.element.className = "zcomponent-defaultloader";
|
|
51
|
+
if (constructorProps.backgroundImage) {
|
|
52
|
+
this.element.style.backgroundImage = `url(${constructorProps.backgroundImage})`;
|
|
53
53
|
}
|
|
54
|
-
const titleElement = this.
|
|
55
|
-
const subtitleElement = this.
|
|
56
|
-
this._percentageElement = this.
|
|
54
|
+
const titleElement = this.element.querySelector("#zcomponent-defaultloader-title") || document.createElement("h1");
|
|
55
|
+
const subtitleElement = this.element.querySelector("#zcomponent-defaultloader-subtitle") || document.createElement("h1");
|
|
56
|
+
this._percentageElement = this.element.querySelector("#zcomponent-defaultloader-progress-percentage") || document.createElement("div");
|
|
57
57
|
this.title = new Observable('', t => titleElement.innerText = t);
|
|
58
58
|
this.subtitle = new Observable('', t => subtitleElement.innerText = t);
|
|
59
|
-
this.textColor = new Observable('white', t => this.
|
|
60
|
-
this.backgroundColor = new Observable('black', t => this.
|
|
61
|
-
this.zIndex = new Observable(1000, t => this.
|
|
59
|
+
this.textColor = new Observable('white', t => this.element.style.color = t ?? 'white');
|
|
60
|
+
this.backgroundColor = new Observable('black', t => this.element.style.backgroundColor = t ?? 'black');
|
|
61
|
+
this.zIndex = new Observable(1000, t => this.element.style.zIndex = t.toString());
|
|
62
62
|
this.register(this.preview, this._updatePercentage);
|
|
63
63
|
this.register(this.preview, this._updateVisibility);
|
|
64
64
|
this.register(useIsLoaded(contextManager), this._updateVisibility);
|
|
@@ -66,7 +66,7 @@ export class DefaultLoader extends Component {
|
|
|
66
66
|
this._update();
|
|
67
67
|
}
|
|
68
68
|
dispose() {
|
|
69
|
-
this.
|
|
69
|
+
this.element.remove();
|
|
70
70
|
return super.dispose();
|
|
71
71
|
}
|
|
72
72
|
}
|