@zcomponent/core 0.0.8 → 0.0.10
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 +6 -11
- package/lib/actionbehavior.js +11 -19
- package/lib/animation.d.ts +9 -9
- package/lib/behavior.d.ts +23 -12
- package/lib/behavior.js +31 -3
- package/lib/behaviors/PlaySound.d.ts +2 -1
- package/lib/behaviors/PlaySound.js +2 -2
- package/lib/component.d.ts +26 -17
- package/lib/component.js +54 -20
- package/lib/components/Children.d.ts +8 -0
- package/lib/components/Children.js +11 -0
- package/lib/components/DefaultLoader.d.ts +2 -2
- package/lib/components/DefaultLoader.js +19 -19
- package/lib/components/Gamepad.d.ts +68 -0
- package/lib/components/Gamepad.js +131 -0
- package/lib/components/LongLoad.d.ts +3 -3
- 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 +9 -10
- package/lib/contexts/tagcontext.js +27 -35
- package/lib/contexts/usereventcontext.d.ts +5 -5
- package/lib/contexts/usereventcontext.js +14 -19
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -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 +40 -40
- package/lib/zcomponentconstruction.d.ts +3 -0
- package/lib/zcomponentconstruction.js +7 -0
- package/package.json +2 -2
package/lib/actionbehavior.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Behavior
|
|
1
|
+
import { Behavior } from "./behavior";
|
|
2
2
|
import { Component } from "./component";
|
|
3
3
|
import { ContextManager } from "./context";
|
|
4
|
-
|
|
5
|
-
export interface ActionBehaviorConstructorProps extends BehaviorConstructorProps {
|
|
4
|
+
export interface ActionBehaviorConstructorProps {
|
|
6
5
|
/** @zprop
|
|
7
6
|
* @zvalues events
|
|
8
7
|
*/
|
|
@@ -13,14 +12,10 @@ export interface ActionBehaviorConstructorProps extends BehaviorConstructorProps
|
|
|
13
12
|
*/
|
|
14
13
|
runAtEditTime: boolean;
|
|
15
14
|
}
|
|
16
|
-
export declare abstract class ActionBehavior<ConstructorProps extends ActionBehaviorConstructorProps = ActionBehaviorConstructorProps> extends Behavior<Component
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @zdefault true
|
|
20
|
-
*/
|
|
21
|
-
enabled: Observable<boolean, never>;
|
|
22
|
-
constructor(props: ConstructorProps, contextManager: ContextManager);
|
|
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);
|
|
23
18
|
private _updateRegistration;
|
|
24
19
|
private _perform;
|
|
25
|
-
abstract perform(): any;
|
|
20
|
+
abstract perform(...args: any[]): any;
|
|
26
21
|
}
|
package/lib/actionbehavior.js
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { Behavior } from "./behavior";
|
|
2
2
|
import { EnvironmentContext, isEditTime } from "./contexts/environmentcontext";
|
|
3
3
|
import { Event } from "./event";
|
|
4
|
-
import { Observable } from "./observable";
|
|
5
4
|
export class ActionBehavior extends Behavior {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
-
|
|
9
|
-
* @zprop
|
|
10
|
-
* @zdefault true
|
|
11
|
-
*/
|
|
12
|
-
this.enabled = new Observable(true);
|
|
5
|
+
constructor(contextManager, instance, constructorProps) {
|
|
6
|
+
super(contextManager, instance);
|
|
7
|
+
this.constructorProps = constructorProps;
|
|
13
8
|
this._updateRegistration = () => {
|
|
14
|
-
const evt = this.
|
|
9
|
+
const evt = this.instance[this.constructorProps.event];
|
|
15
10
|
if (evt instanceof Event) {
|
|
16
|
-
|
|
11
|
+
this.unregister(evt, this._perform);
|
|
12
|
+
if (this.enabledResolved.value && (!isEditTime(this.contextManager) || this.constructorProps.runAtEditTime === true)) {
|
|
17
13
|
this.register(evt, this._perform);
|
|
18
14
|
}
|
|
19
|
-
else {
|
|
20
|
-
this.unregister(evt, this._perform);
|
|
21
|
-
}
|
|
22
15
|
}
|
|
23
16
|
};
|
|
24
|
-
this._perform = (
|
|
25
|
-
if (!this.
|
|
26
|
-
return;
|
|
27
|
-
if (!this.instance.enabledResolved.value)
|
|
17
|
+
this._perform = (...args) => {
|
|
18
|
+
if (!this.enabledResolved.value)
|
|
28
19
|
return;
|
|
29
|
-
this.perform();
|
|
20
|
+
this.perform(...args);
|
|
21
|
+
const e = args[0];
|
|
30
22
|
if (e && typeof e === 'object' && typeof e['stopPropagation'] === 'function') {
|
|
31
23
|
e['stopPropagation'].call(e);
|
|
32
24
|
}
|
|
33
25
|
};
|
|
34
26
|
const env = contextManager.get(EnvironmentContext);
|
|
35
27
|
this.register(env.editTime, this._updateRegistration);
|
|
36
|
-
this.register(this.
|
|
28
|
+
this.register(this.enabledResolved, this._updateRegistration);
|
|
37
29
|
}
|
|
38
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,20 +1,31 @@
|
|
|
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;
|
|
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;
|
|
20
31
|
unregister<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
@@ -22,4 +33,4 @@ export declare class Behavior<InstanceType extends Component = Component, Constr
|
|
|
22
33
|
dispose(): never;
|
|
23
34
|
}
|
|
24
35
|
export declare function shouldBehaviorRunAtDesignTime(b: BehaviorConstructor): boolean;
|
|
25
|
-
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,40 @@
|
|
|
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 (this._zcomponent === undefined)
|
|
32
|
+
throw new Error("getZComponentInstance called in behavior that's not part of a ZComponent");
|
|
33
|
+
if (!type)
|
|
34
|
+
return this._zcomponent;
|
|
35
|
+
if (this._zcomponent instanceof type)
|
|
36
|
+
return this._zcomponent;
|
|
37
|
+
throw new Error("getZComponentInstance called in behavior passing wrong kind of ZComponent");
|
|
10
38
|
}
|
|
11
39
|
register(e, fn) {
|
|
12
40
|
if (e 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,8 +8,8 @@ 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
14
|
registerLoadable(contextManager, new Promise((resolve, reject) => {
|
|
15
15
|
this._elm.addEventListener('canplaythrough', () => resolve());
|
package/lib/component.d.ts
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
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 {
|
|
9
15
|
[id: string]: any;
|
|
10
16
|
children?: ComponentChildren;
|
|
11
17
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private _options?;
|
|
19
|
-
root?: RootType;
|
|
20
|
-
onDispose: Event<[]>;
|
|
21
|
-
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[];
|
|
22
24
|
parent?: Component;
|
|
23
25
|
disposed: boolean;
|
|
24
26
|
private _registered;
|
|
25
|
-
|
|
26
|
-
|
|
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[];
|
|
27
35
|
/**
|
|
28
36
|
* @zprop
|
|
29
37
|
* @zdefault true
|
|
30
38
|
* @zgroup Behavior
|
|
39
|
+
* @group Behavior
|
|
31
40
|
* @zgrouppriority 10
|
|
32
41
|
*/
|
|
33
42
|
enabled: Observable<boolean, never>;
|
|
@@ -35,10 +44,10 @@ export declare class Component<ConstructorPropsType extends ConstructorProps = C
|
|
|
35
44
|
/**
|
|
36
45
|
* @zprop
|
|
37
46
|
* @zgroup Other
|
|
47
|
+
* @group Other
|
|
38
48
|
* @zgrouppriority 0
|
|
39
49
|
*/
|
|
40
50
|
tags: Observable<string[], never>;
|
|
41
|
-
protected _constructChildren(children?: ComponentChildren): void;
|
|
42
51
|
protected register<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
|
43
52
|
protected register<Type>(observable: Observable<Type>, fn: (v: Type) => void): any;
|
|
44
53
|
protected unregister<Args extends Array<any>>(evt: Event<Args>, fn: (...args: Args) => void): any;
|
package/lib/component.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TagContext } from './contexts/tagcontext';
|
|
2
2
|
import { Event } from './event';
|
|
3
3
|
import { Observable } from './observable';
|
|
4
|
+
import { getCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
4
5
|
export class Component {
|
|
5
|
-
constructor(
|
|
6
|
-
this.constructorProps = constructorProps;
|
|
6
|
+
constructor(contextManager, constructorProps) {
|
|
7
7
|
this.contextManager = contextManager;
|
|
8
|
-
this.
|
|
8
|
+
this.constructorProps = constructorProps;
|
|
9
9
|
this.onDispose = new Event();
|
|
10
10
|
this.children = [];
|
|
11
11
|
this.disposed = false;
|
|
@@ -14,6 +14,7 @@ export class Component {
|
|
|
14
14
|
* @zprop
|
|
15
15
|
* @zdefault true
|
|
16
16
|
* @zgroup Behavior
|
|
17
|
+
* @group Behavior
|
|
17
18
|
* @zgrouppriority 10
|
|
18
19
|
*/
|
|
19
20
|
this.enabled = new Observable(true);
|
|
@@ -21,6 +22,7 @@ export class Component {
|
|
|
21
22
|
/**
|
|
22
23
|
* @zprop
|
|
23
24
|
* @zgroup Other
|
|
25
|
+
* @group Other
|
|
24
26
|
* @zgrouppriority 0
|
|
25
27
|
*/
|
|
26
28
|
this.tags = new Observable([]);
|
|
@@ -38,27 +40,59 @@ export class Component {
|
|
|
38
40
|
const context = this.contextManager.get(TagContext);
|
|
39
41
|
context.registerComponent(this, this.tags.value);
|
|
40
42
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
this._zcomponent = getCurrentZComponentConstruction();
|
|
44
|
+
this.constructChildren(constructorProps?.children ?? []);
|
|
43
45
|
this.register(this.enabled, this._updateEnabledResolved);
|
|
44
46
|
this.register(this.tags, this._updateTags);
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (const child of children) {
|
|
55
|
-
const instance = new child[0](child[1], this.contextManager);
|
|
56
|
-
this.children.push(instance);
|
|
57
|
-
instance.parent = this;
|
|
58
|
-
if (child[2] instanceof Observable)
|
|
59
|
-
child[2].value = instance;
|
|
48
|
+
constructChildren(children, contextManager) {
|
|
49
|
+
contextManager = contextManager ?? this.contextManager;
|
|
50
|
+
for (const [constructor, props, ref] of children) {
|
|
51
|
+
try {
|
|
52
|
+
const instance = new constructor(contextManager, props);
|
|
53
|
+
this.appendChild(instance);
|
|
54
|
+
if (ref)
|
|
55
|
+
ref.value = instance;
|
|
60
56
|
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.log('An error occurred when constructing component child of type:', constructor, err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
getZComponentInstance(type) {
|
|
63
|
+
if (this._zcomponent === undefined)
|
|
64
|
+
throw new Error("getZComponentInstance called in component that's not part of a ZComponent");
|
|
65
|
+
if (!type)
|
|
66
|
+
return this._zcomponent;
|
|
67
|
+
if (this._zcomponent instanceof type)
|
|
68
|
+
return this._zcomponent;
|
|
69
|
+
throw new Error("getZComponentInstance called in component passing wrong kind of ZComponent");
|
|
70
|
+
}
|
|
71
|
+
appendChild(c) {
|
|
72
|
+
c.remove();
|
|
73
|
+
this.children.push(c);
|
|
74
|
+
c.parent = this;
|
|
75
|
+
c._updateEnabledResolved();
|
|
76
|
+
}
|
|
77
|
+
removeChild(c) {
|
|
78
|
+
const indx = this.children.indexOf(c);
|
|
79
|
+
if (indx >= 0)
|
|
80
|
+
this.children.splice(indx, 1);
|
|
81
|
+
}
|
|
82
|
+
remove() {
|
|
83
|
+
this.parent?.removeChild(this);
|
|
84
|
+
}
|
|
85
|
+
get elementsResolved() {
|
|
86
|
+
if (this.element !== undefined) {
|
|
87
|
+
if (Array.isArray(this.element))
|
|
88
|
+
return this.element;
|
|
89
|
+
return [this.element];
|
|
61
90
|
}
|
|
91
|
+
const ret = [];
|
|
92
|
+
for (const child of this.children) {
|
|
93
|
+
ret.push(...child.elementsResolved);
|
|
94
|
+
}
|
|
95
|
+
return ret;
|
|
62
96
|
}
|
|
63
97
|
register(e, fn) {
|
|
64
98
|
if (e instanceof Event)
|
|
@@ -82,7 +116,7 @@ export class Component {
|
|
|
82
116
|
}
|
|
83
117
|
catch (err) { }
|
|
84
118
|
}
|
|
85
|
-
this.children =
|
|
119
|
+
this.children.length = 0;
|
|
86
120
|
for (const entry of this._registered) {
|
|
87
121
|
if (entry[0] instanceof Event)
|
|
88
122
|
entry[0].unbindfn(entry[1]);
|
|
@@ -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
|
+
}
|
|
@@ -17,7 +17,7 @@ export interface DefaultLoaderConstructorProps {
|
|
|
17
17
|
* @zgroup Advanced
|
|
18
18
|
*/
|
|
19
19
|
export declare class DefaultLoader extends Component {
|
|
20
|
-
|
|
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 {
|
|
|
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.
|
|
49
|
+
this.element.innerHTML = loaderHTML;
|
|
50
|
+
this.element.className = "zcomponent-defaultloader";
|
|
51
51
|
if (constructorProps.backgroundImage) {
|
|
52
|
-
this.
|
|
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
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Component } from "../component";
|
|
2
|
+
import { ContextManager } from "../context";
|
|
3
|
+
import { Event } from "../event";
|
|
4
|
+
import { Observable } from "../observable";
|
|
5
|
+
export interface GamepadButtonEvent {
|
|
6
|
+
button: number;
|
|
7
|
+
gamepad: number;
|
|
8
|
+
pressed: boolean;
|
|
9
|
+
touched: boolean;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @zcomponent
|
|
14
|
+
*/
|
|
15
|
+
export declare class Gamepad extends Component {
|
|
16
|
+
/** @zprop */
|
|
17
|
+
onButtonDown: Event<[GamepadButtonEvent]>;
|
|
18
|
+
/** @zprop */
|
|
19
|
+
onButtonUp: Event<[GamepadButtonEvent]>;
|
|
20
|
+
/** @zprop */
|
|
21
|
+
onButtonSouth: Event<[GamepadButtonEvent]>;
|
|
22
|
+
/** @zprop */
|
|
23
|
+
onButtonWest: Event<[GamepadButtonEvent]>;
|
|
24
|
+
/** @zprop */
|
|
25
|
+
onButtonNorth: Event<[GamepadButtonEvent]>;
|
|
26
|
+
/** @zprop */
|
|
27
|
+
onButtonEast: Event<[GamepadButtonEvent]>;
|
|
28
|
+
/** @zprop */
|
|
29
|
+
onButtonShoulderLeft: Event<[GamepadButtonEvent]>;
|
|
30
|
+
/** @zprop */
|
|
31
|
+
onButtonShoulderRight: Event<[GamepadButtonEvent]>;
|
|
32
|
+
/** @zprop */
|
|
33
|
+
onButtonTriggerLeft: Event<[GamepadButtonEvent]>;
|
|
34
|
+
/** @zprop */
|
|
35
|
+
onButtonTriggerRight: Event<[GamepadButtonEvent]>;
|
|
36
|
+
/** @zprop */
|
|
37
|
+
onButtonDLeft: Event<[GamepadButtonEvent]>;
|
|
38
|
+
/** @zprop */
|
|
39
|
+
onButtonDRight: Event<[GamepadButtonEvent]>;
|
|
40
|
+
/** @zprop */
|
|
41
|
+
onButtonDUp: Event<[GamepadButtonEvent]>;
|
|
42
|
+
/** @zprop */
|
|
43
|
+
onButtonDDown: Event<[GamepadButtonEvent]>;
|
|
44
|
+
/** @zprop */
|
|
45
|
+
onButtonSelect: Event<[GamepadButtonEvent]>;
|
|
46
|
+
/** @zprop */
|
|
47
|
+
onButtonStart: Event<[GamepadButtonEvent]>;
|
|
48
|
+
/** @zprop */
|
|
49
|
+
onButtonCenter: Event<[GamepadButtonEvent]>;
|
|
50
|
+
/** @zprop */
|
|
51
|
+
onButtonStickLeft: Event<[GamepadButtonEvent]>;
|
|
52
|
+
/** @zprop */
|
|
53
|
+
onButtonStickRight: Event<[GamepadButtonEvent]>;
|
|
54
|
+
private _indexMapping;
|
|
55
|
+
/**
|
|
56
|
+
* @zprop
|
|
57
|
+
*/
|
|
58
|
+
controllerIndex: Observable<number | undefined, never>;
|
|
59
|
+
/**
|
|
60
|
+
* @zprop
|
|
61
|
+
* @zdefault 0.1
|
|
62
|
+
*/
|
|
63
|
+
analogPressedThreshold: Observable<number, never>;
|
|
64
|
+
private _downLastFrame;
|
|
65
|
+
constructor(contextManager: ContextManager, props: any);
|
|
66
|
+
private _updateRegistration;
|
|
67
|
+
private _update;
|
|
68
|
+
}
|