@zcomponent/core 0.0.15 → 0.0.17
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/css/zcomponent.css +28 -0
- package/lib/behavior.d.ts +1 -0
- package/lib/behavior.js +7 -2
- package/lib/behaviors/ConsoleLog.d.ts +22 -0
- package/lib/behaviors/ConsoleLog.js +18 -0
- 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/PlaySound.d.ts +1 -0
- package/lib/behaviors/PlaySound.js +1 -0
- package/lib/behaviors/ShowTextAlert.d.ts +62 -0
- package/lib/behaviors/ShowTextAlert.js +77 -0
- package/lib/component.d.ts +6 -0
- package/lib/component.js +20 -2
- package/lib/components/Children.d.ts +2 -0
- package/lib/components/Children.js +2 -0
- package/lib/components/DefaultLoader.d.ts +4 -2
- package/lib/components/DefaultLoader.js +2 -2
- package/lib/components/Gamepad.d.ts +1 -0
- package/lib/components/Gamepad.js +1 -0
- package/lib/components/LongLoad.d.ts +3 -1
- package/lib/components/LongLoad.js +13 -3
- package/lib/contexts/textalertcontext.d.ts +13 -0
- package/lib/contexts/textalertcontext.js +36 -0
- package/lib/emitter.d.ts +1 -3
- package/lib/emitter.js +0 -7
- package/lib/entity.js +3 -1
- package/lib/event.d.ts +5 -0
- package/lib/event.js +19 -0
- package/lib/observable.js +1 -1
- package/lib/selectors.js +28 -11
- package/lib/types.d.ts +21 -2
- package/lib/types.js +10 -0
- package/package.json +1 -1
package/css/zcomponent.css
CHANGED
|
@@ -91,4 +91,32 @@
|
|
|
91
91
|
|
|
92
92
|
.zcomponent-hc-vc {
|
|
93
93
|
transform: translate(-50%, -50%);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.zcomponent-textalert-container {
|
|
97
|
+
position: absolute;
|
|
98
|
+
bottom: 30px;
|
|
99
|
+
left: 50%;
|
|
100
|
+
transform: translate(-50%, 0);
|
|
101
|
+
display: flex;
|
|
102
|
+
flex-direction: column;
|
|
103
|
+
justify-content: end;
|
|
104
|
+
align-items: center;
|
|
105
|
+
row-gap: 24px;
|
|
106
|
+
max-width: 80%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.zcomponent-textalert {
|
|
110
|
+
transition: opacity 0.5s;
|
|
111
|
+
background-color: black;
|
|
112
|
+
border-radius: 10px;
|
|
113
|
+
padding: 20px;
|
|
114
|
+
color: white;
|
|
115
|
+
font-family: sans-serif;
|
|
116
|
+
opacity: 0;
|
|
117
|
+
text-align: center;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.zcomponent-textalert-shown {
|
|
121
|
+
opacity: 1;
|
|
94
122
|
}
|
package/lib/behavior.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class Behavior<InstanceType extends Component = Component> extend
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(contextManager: ContextManager, instance: InstanceType);
|
|
18
18
|
private _updateEnabledResolved;
|
|
19
|
+
dispose(): never;
|
|
19
20
|
}
|
|
20
21
|
export declare function shouldBehaviorRunAtDesignTime(b: BehaviorConstructor): boolean;
|
|
21
22
|
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
|
@@ -17,8 +17,13 @@ export class Behavior extends Entity {
|
|
|
17
17
|
this.enabledResolved.value = newValue;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
this.register(
|
|
20
|
+
instance.addBehavior(this);
|
|
21
|
+
this.register(this.enabled, this._updateEnabledResolved, { bindWhenDisabled: true });
|
|
22
|
+
this.register(instance.enabledResolved, this._updateEnabledResolved, { bindWhenDisabled: true });
|
|
23
|
+
}
|
|
24
|
+
dispose() {
|
|
25
|
+
this.instance.removeBehavior(this);
|
|
26
|
+
return super.dispose();
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
const behaviorsToRunAtDesignTime = new Set();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ActionBehavior } from "../actionbehavior";
|
|
2
|
+
/**
|
|
3
|
+
* Outputs a message to the console log.
|
|
4
|
+
*
|
|
5
|
+
* @zbehavior
|
|
6
|
+
* @zicon terminal
|
|
7
|
+
* @zgroup Actions
|
|
8
|
+
*/
|
|
9
|
+
export declare class ConsoleLog extends ActionBehavior {
|
|
10
|
+
/**
|
|
11
|
+
* The text to log
|
|
12
|
+
* @zprop
|
|
13
|
+
*/
|
|
14
|
+
text: string;
|
|
15
|
+
/**
|
|
16
|
+
* If true, the event name will be logged in addition to the text
|
|
17
|
+
* @zprop
|
|
18
|
+
* @zdefault true
|
|
19
|
+
*/
|
|
20
|
+
includeEventName: boolean;
|
|
21
|
+
perform(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ActionBehavior } from "../actionbehavior";
|
|
2
|
+
import { registerBehaviorRunAtDesignTime } from "../behavior";
|
|
3
|
+
/**
|
|
4
|
+
* Outputs a message to the console log.
|
|
5
|
+
*
|
|
6
|
+
* @zbehavior
|
|
7
|
+
* @zicon terminal
|
|
8
|
+
* @zgroup Actions
|
|
9
|
+
*/
|
|
10
|
+
export class ConsoleLog extends ActionBehavior {
|
|
11
|
+
perform() {
|
|
12
|
+
if (this.includeEventName ?? true)
|
|
13
|
+
console.log(this.constructorProps.event, this.text);
|
|
14
|
+
else
|
|
15
|
+
console.log(this.text);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
registerBehaviorRunAtDesignTime(ConsoleLog);
|
|
@@ -5,6 +5,7 @@ import { ActionBehavior } from "../actionbehavior";
|
|
|
5
5
|
* **Important Note**: Safari on iOS will not open URLs in new tabs for pointer events except `onPointerUp`.
|
|
6
6
|
*
|
|
7
7
|
* @zbehavior
|
|
8
|
+
* @zicon open_in_new
|
|
8
9
|
* @zgroup Actions
|
|
9
10
|
*/
|
|
10
11
|
export declare class LaunchURL extends ActionBehavior {
|
|
@@ -5,6 +5,7 @@ import { ActionBehavior } from "../actionbehavior";
|
|
|
5
5
|
* **Important Note**: Safari on iOS will not open URLs in new tabs for pointer events except `onPointerUp`.
|
|
6
6
|
*
|
|
7
7
|
* @zbehavior
|
|
8
|
+
* @zicon open_in_new
|
|
8
9
|
* @zgroup Actions
|
|
9
10
|
*/
|
|
10
11
|
export class LaunchURL extends ActionBehavior {
|
|
@@ -5,6 +5,7 @@ import { ActionBehavior } from "../actionbehavior";
|
|
|
5
5
|
* Note: you must have added an analytics provider to the Hierarchy in one of your components for this behavior to have any effect.
|
|
6
6
|
*
|
|
7
7
|
* @zbehavior
|
|
8
|
+
* @zicon analytics
|
|
8
9
|
* @zgroup Actions
|
|
9
10
|
*/
|
|
10
11
|
export declare class LogAnalyticsEvent extends ActionBehavior {
|
|
@@ -6,6 +6,7 @@ import { logEvent } from "../contexts/analyticscontext";
|
|
|
6
6
|
* Note: you must have added an analytics provider to the Hierarchy in one of your components for this behavior to have any effect.
|
|
7
7
|
*
|
|
8
8
|
* @zbehavior
|
|
9
|
+
* @zicon analytics
|
|
9
10
|
* @zgroup Actions
|
|
10
11
|
*/
|
|
11
12
|
export class LogAnalyticsEvent extends ActionBehavior {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ActionBehavior } from "../actionbehavior";
|
|
2
|
+
import { Observable } from "../observable";
|
|
3
|
+
/**
|
|
4
|
+
* Displays a pop-up text alert on screen.
|
|
5
|
+
*
|
|
6
|
+
* @zbehavior
|
|
7
|
+
* @zicon sms
|
|
8
|
+
* @zgroup Actions
|
|
9
|
+
*/
|
|
10
|
+
export declare class ShowTextAlert extends ActionBehavior {
|
|
11
|
+
/**
|
|
12
|
+
* The text to show in the alert
|
|
13
|
+
* @zprop
|
|
14
|
+
* @zgroup ShowTextAlert
|
|
15
|
+
* @zgrouppriority 20
|
|
16
|
+
*/
|
|
17
|
+
text: Observable<string, never>;
|
|
18
|
+
/**
|
|
19
|
+
* The time (in milliseconds) that the text alert should remain on screen
|
|
20
|
+
*
|
|
21
|
+
* @zprop
|
|
22
|
+
* @zgroup Appearance
|
|
23
|
+
* @zgrouppriority 10
|
|
24
|
+
* @zdefault 3000
|
|
25
|
+
*/
|
|
26
|
+
timeout: Observable<number, never>;
|
|
27
|
+
/**
|
|
28
|
+
* The color of the background of the text alert
|
|
29
|
+
*
|
|
30
|
+
* @zprop
|
|
31
|
+
* @zgroup Appearance
|
|
32
|
+
* @zgrouppriority 10
|
|
33
|
+
* @zdefault black
|
|
34
|
+
* @ztype color-hex
|
|
35
|
+
*/
|
|
36
|
+
backgroundColor: Observable<string, never>;
|
|
37
|
+
/**
|
|
38
|
+
* The color of the text of the text alert
|
|
39
|
+
*
|
|
40
|
+
* @zprop
|
|
41
|
+
* @zgroup Appearance
|
|
42
|
+
* @zgrouppriority 10
|
|
43
|
+
* @zdefault #ffffff
|
|
44
|
+
* @ztype color-hex
|
|
45
|
+
*/
|
|
46
|
+
textColor: Observable<string, never>;
|
|
47
|
+
/**
|
|
48
|
+
* Additional CSS class names to add to the alert DOM element
|
|
49
|
+
*
|
|
50
|
+
* @zprop
|
|
51
|
+
* @zgroup Appearance
|
|
52
|
+
* @zgrouppriority 10
|
|
53
|
+
* @zdefault []
|
|
54
|
+
*/
|
|
55
|
+
classNames: Observable<string[], never>;
|
|
56
|
+
/**
|
|
57
|
+
* How long the alert will apear on the screen
|
|
58
|
+
*/
|
|
59
|
+
perform(): void;
|
|
60
|
+
/** @zprop */
|
|
61
|
+
preview(): void;
|
|
62
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ActionBehavior } from "../actionbehavior";
|
|
2
|
+
import { registerBehaviorRunAtDesignTime } from "../behavior";
|
|
3
|
+
import { showTextAlert } from "../contexts/textalertcontext";
|
|
4
|
+
import { Observable } from "../observable";
|
|
5
|
+
/**
|
|
6
|
+
* Displays a pop-up text alert on screen.
|
|
7
|
+
*
|
|
8
|
+
* @zbehavior
|
|
9
|
+
* @zicon sms
|
|
10
|
+
* @zgroup Actions
|
|
11
|
+
*/
|
|
12
|
+
export class ShowTextAlert extends ActionBehavior {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
/**
|
|
16
|
+
* The text to show in the alert
|
|
17
|
+
* @zprop
|
|
18
|
+
* @zgroup ShowTextAlert
|
|
19
|
+
* @zgrouppriority 20
|
|
20
|
+
*/
|
|
21
|
+
this.text = new Observable('');
|
|
22
|
+
/**
|
|
23
|
+
* The time (in milliseconds) that the text alert should remain on screen
|
|
24
|
+
*
|
|
25
|
+
* @zprop
|
|
26
|
+
* @zgroup Appearance
|
|
27
|
+
* @zgrouppriority 10
|
|
28
|
+
* @zdefault 3000
|
|
29
|
+
*/
|
|
30
|
+
this.timeout = new Observable(3000);
|
|
31
|
+
/**
|
|
32
|
+
* The color of the background of the text alert
|
|
33
|
+
*
|
|
34
|
+
* @zprop
|
|
35
|
+
* @zgroup Appearance
|
|
36
|
+
* @zgrouppriority 10
|
|
37
|
+
* @zdefault black
|
|
38
|
+
* @ztype color-hex
|
|
39
|
+
*/
|
|
40
|
+
this.backgroundColor = new Observable('#000000');
|
|
41
|
+
/**
|
|
42
|
+
* The color of the text of the text alert
|
|
43
|
+
*
|
|
44
|
+
* @zprop
|
|
45
|
+
* @zgroup Appearance
|
|
46
|
+
* @zgrouppriority 10
|
|
47
|
+
* @zdefault #ffffff
|
|
48
|
+
* @ztype color-hex
|
|
49
|
+
*/
|
|
50
|
+
this.textColor = new Observable('#ffffff');
|
|
51
|
+
/**
|
|
52
|
+
* Additional CSS class names to add to the alert DOM element
|
|
53
|
+
*
|
|
54
|
+
* @zprop
|
|
55
|
+
* @zgroup Appearance
|
|
56
|
+
* @zgrouppriority 10
|
|
57
|
+
* @zdefault []
|
|
58
|
+
*/
|
|
59
|
+
this.classNames = new Observable([]);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* How long the alert will apear on the screen
|
|
63
|
+
*/
|
|
64
|
+
perform() {
|
|
65
|
+
showTextAlert(this.contextManager, this.text.value, {
|
|
66
|
+
backgroundColor: this.backgroundColor.value,
|
|
67
|
+
textColor: this.textColor.value,
|
|
68
|
+
classNames: this.classNames.value,
|
|
69
|
+
timeout: this.timeout.value
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** @zprop */
|
|
73
|
+
preview() {
|
|
74
|
+
this.perform();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
registerBehaviorRunAtDesignTime(ShowTextAlert);
|
package/lib/component.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContextManager } from './context';
|
|
2
2
|
import { Entity } from './entity';
|
|
3
3
|
import { Observable } from './observable';
|
|
4
|
+
import type { Behavior, BehaviorConstructor } from './behavior';
|
|
4
5
|
export type ConstructorPropsOfComponent<ComponentType> = ComponentType extends Component<any, infer R> ? R : never;
|
|
5
6
|
export type ComponentConstructor<ConstructorPropsType extends ConstructorProps, ComponentType extends Component> = new (props: ConstructorPropsType, contextManager: ContextManager) => ComponentType;
|
|
6
7
|
export type ConstructorForComponent<ComponentType extends Component = Component> = new (contextManager: ContextManager, props: ComponentType extends Component<any, infer PropsType> ? PropsType : never) => ComponentType;
|
|
@@ -21,6 +22,7 @@ export declare class Component<ElementType = any, ConstructorPropsType extends C
|
|
|
21
22
|
*/
|
|
22
23
|
element?: ElementType;
|
|
23
24
|
readonly children: Component[];
|
|
25
|
+
readonly behaviors: Behavior[];
|
|
24
26
|
parent?: Component;
|
|
25
27
|
constructor(contextManager: ContextManager, constructorProps?: ConstructorPropsType | undefined);
|
|
26
28
|
constructChildren(children: ComponentChildren, contextManager?: ContextManager): void;
|
|
@@ -39,6 +41,10 @@ export declare class Component<ElementType = any, ConstructorPropsType extends C
|
|
|
39
41
|
* Removes this component from its parent component.
|
|
40
42
|
*/
|
|
41
43
|
remove(): void;
|
|
44
|
+
addBehavior(b: Behavior): void;
|
|
45
|
+
removeBehavior(b: Behavior): void;
|
|
46
|
+
getBehavior<T extends BehaviorConstructor>(type: T): InstanceType<T> | undefined;
|
|
47
|
+
getBehaviors<T extends BehaviorConstructor>(type: T): InstanceType<T>[];
|
|
42
48
|
/**
|
|
43
49
|
* An array of the elements that this component instance exposes. In the case that this component
|
|
44
50
|
* does not expose any elements of its own, this will be an array of the elements
|
package/lib/component.js
CHANGED
|
@@ -6,6 +6,7 @@ export class Component extends Entity {
|
|
|
6
6
|
super(contextManager);
|
|
7
7
|
this.constructorProps = constructorProps;
|
|
8
8
|
this.children = [];
|
|
9
|
+
this.behaviors = [];
|
|
9
10
|
/**
|
|
10
11
|
* An array of string 'tags' assocated with this component.
|
|
11
12
|
*
|
|
@@ -36,8 +37,8 @@ export class Component extends Entity {
|
|
|
36
37
|
context.registerComponent(this, this.tags.value);
|
|
37
38
|
};
|
|
38
39
|
this.constructChildren(constructorProps?.children ?? []);
|
|
39
|
-
this.register(this.enabled, this._updateEnabledResolved);
|
|
40
|
-
this.register(this.tags, this._updateTags);
|
|
40
|
+
this.register(this.enabled, this._updateEnabledResolved, { bindWhenDisabled: true });
|
|
41
|
+
this.register(this.tags, this._updateTags, { bindWhenDisabled: true });
|
|
41
42
|
}
|
|
42
43
|
constructChildren(children, contextManager) {
|
|
43
44
|
contextManager = contextManager ?? this.contextManager;
|
|
@@ -81,6 +82,23 @@ export class Component extends Entity {
|
|
|
81
82
|
remove() {
|
|
82
83
|
this.parent?.removeChild(this);
|
|
83
84
|
}
|
|
85
|
+
addBehavior(b) {
|
|
86
|
+
this.behaviors.push(b);
|
|
87
|
+
}
|
|
88
|
+
removeBehavior(b) {
|
|
89
|
+
const indx = this.behaviors.indexOf(b);
|
|
90
|
+
if (indx >= 0)
|
|
91
|
+
this.behaviors.splice(indx, 1);
|
|
92
|
+
}
|
|
93
|
+
getBehavior(type) {
|
|
94
|
+
for (const behavior of this.behaviors) {
|
|
95
|
+
if (behavior instanceof type)
|
|
96
|
+
return behavior;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
getBehaviors(type) {
|
|
100
|
+
return this.behaviors.filter(entry => entry instanceof type);
|
|
101
|
+
}
|
|
84
102
|
/**
|
|
85
103
|
* An array of the elements that this component instance exposes. In the case that this component
|
|
86
104
|
* does not expose any elements of its own, this will be an array of the elements
|
|
@@ -2,6 +2,8 @@ import { Component, ConstructorProps } from "../component";
|
|
|
2
2
|
import { ContextManager } from "../context";
|
|
3
3
|
/**
|
|
4
4
|
* @zcomponent
|
|
5
|
+
* @zgroup Advanced
|
|
6
|
+
* @zicon list
|
|
5
7
|
*/
|
|
6
8
|
export declare class Children extends Component {
|
|
7
9
|
constructor(contextManager: ContextManager, props: ConstructorProps);
|
|
@@ -35,15 +35,17 @@ export declare class DefaultLoader extends Component {
|
|
|
35
35
|
*/
|
|
36
36
|
subtitle: Observable<string>;
|
|
37
37
|
/** @zprop
|
|
38
|
-
* @zdefault
|
|
38
|
+
* @zdefault #000000
|
|
39
39
|
* @zgroup Appearance
|
|
40
40
|
* @zgrouppriority 10
|
|
41
|
+
* @ztype color-hex
|
|
41
42
|
*/
|
|
42
43
|
backgroundColor: Observable<string>;
|
|
43
44
|
/** @zprop
|
|
44
|
-
* @zdefault
|
|
45
|
+
* @zdefault #ffffff
|
|
45
46
|
* @zgroup Appearance
|
|
46
47
|
* @zgrouppriority 10
|
|
48
|
+
* @ztype color-hex
|
|
47
49
|
*/
|
|
48
50
|
textColor: Observable<string>;
|
|
49
51
|
/** @zprop
|
|
@@ -56,8 +56,8 @@ export class DefaultLoader extends Component {
|
|
|
56
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('
|
|
60
|
-
this.backgroundColor = new Observable('
|
|
59
|
+
this.textColor = new Observable('#ffffff', t => this.element.style.color = t);
|
|
60
|
+
this.backgroundColor = new Observable('#000000', t => this.element.style.backgroundColor = t);
|
|
61
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);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, ContextManager } from "..";
|
|
1
|
+
import { Component, ContextManager, Event } from "..";
|
|
2
2
|
export interface LongLoadConstructorProps {
|
|
3
3
|
/**
|
|
4
4
|
* The number of loading processes to simulate
|
|
@@ -41,5 +41,7 @@ export interface LongLoadConstructorProps {
|
|
|
41
41
|
* @zgroup Advanced
|
|
42
42
|
*/
|
|
43
43
|
export declare class LongLoad extends Component<any, LongLoadConstructorProps> {
|
|
44
|
+
/** @zui */
|
|
45
|
+
onLoad: Event<[]>;
|
|
44
46
|
constructor(contextManager: ContextManager, props: LongLoadConstructorProps);
|
|
45
47
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, isDevelopmentBuild, registerLoadable } from "..";
|
|
1
|
+
import { Component, Event, isDevelopmentBuild, registerLoadable } from "..";
|
|
2
2
|
/**
|
|
3
3
|
* Simulates long random loading times to facilitate development and debugging of loading processes.
|
|
4
4
|
*
|
|
@@ -9,12 +9,15 @@ import { Component, isDevelopmentBuild, registerLoadable } from "..";
|
|
|
9
9
|
export class LongLoad extends Component {
|
|
10
10
|
constructor(contextManager, props) {
|
|
11
11
|
super(contextManager, props);
|
|
12
|
+
/** @zui */
|
|
13
|
+
this.onLoad = new Event();
|
|
12
14
|
if (!props.runInProduction && !isDevelopmentBuild(contextManager))
|
|
13
15
|
return;
|
|
14
16
|
const minimumLoadTime = props.minimumLoadTime ?? 500;
|
|
15
17
|
const maximumLoadTime = props.maximumLoadTime ?? 5000;
|
|
18
|
+
const all = [];
|
|
16
19
|
for (let i = 0; i < (props.numberOfLoads ?? 10); i++) {
|
|
17
|
-
|
|
20
|
+
const promise = new Promise(resolve => {
|
|
18
21
|
if (this.disposed)
|
|
19
22
|
return;
|
|
20
23
|
setTimeout(() => {
|
|
@@ -22,7 +25,14 @@ export class LongLoad extends Component {
|
|
|
22
25
|
return;
|
|
23
26
|
resolve();
|
|
24
27
|
}, minimumLoadTime + Math.random() * (maximumLoadTime - minimumLoadTime));
|
|
25
|
-
})
|
|
28
|
+
});
|
|
29
|
+
registerLoadable(contextManager, promise);
|
|
30
|
+
all.push(promise);
|
|
26
31
|
}
|
|
32
|
+
Promise.all(all).then(() => {
|
|
33
|
+
if (this.disposed)
|
|
34
|
+
return;
|
|
35
|
+
this.onLoad.emit();
|
|
36
|
+
});
|
|
27
37
|
}
|
|
28
38
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContextManager, Context } from '../context';
|
|
2
|
+
export declare class TextAlertContext extends Context {
|
|
3
|
+
private _container;
|
|
4
|
+
constructor(contextManager: ContextManager);
|
|
5
|
+
showTextAlert(txt: string, options?: TextAlertOptions): void;
|
|
6
|
+
}
|
|
7
|
+
export interface TextAlertOptions {
|
|
8
|
+
classNames?: string[];
|
|
9
|
+
timeout?: number;
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
textColor?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function showTextAlert(mgr: ContextManager, txt: string, options?: TextAlertOptions): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Context } from '../context';
|
|
2
|
+
import { useOverlay } from './canvascontext';
|
|
3
|
+
export class TextAlertContext extends Context {
|
|
4
|
+
constructor(contextManager) {
|
|
5
|
+
super(contextManager, {});
|
|
6
|
+
this._container = document.createElement('div');
|
|
7
|
+
this._container.classList.add('zcomponent-textalert-container');
|
|
8
|
+
useOverlay(contextManager).addListener(val => {
|
|
9
|
+
val.appendChild(this._container);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
showTextAlert(txt, options) {
|
|
13
|
+
const entry = document.createElement('div');
|
|
14
|
+
entry.classList.add('zcomponent-textalert');
|
|
15
|
+
options?.classNames?.forEach(val => entry.classList.add(val));
|
|
16
|
+
entry.innerText = txt;
|
|
17
|
+
entry.style.backgroundColor = options?.backgroundColor ?? 'black';
|
|
18
|
+
entry.style.color = options?.textColor ?? 'white';
|
|
19
|
+
entry.addEventListener('click', evt => {
|
|
20
|
+
entry.remove();
|
|
21
|
+
evt.stopPropagation();
|
|
22
|
+
});
|
|
23
|
+
this._container.appendChild(entry);
|
|
24
|
+
const timeout = options?.timeout ?? 3000;
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
entry.classList.add('zcomponent-textalert-shown');
|
|
27
|
+
}, 30);
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
entry.classList.remove('zcomponent-textalert-shown');
|
|
30
|
+
setTimeout(() => entry.remove(), 1000);
|
|
31
|
+
}, timeout);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function showTextAlert(mgr, txt, options) {
|
|
35
|
+
return mgr.get(TextAlertContext).showTextAlert(txt, options);
|
|
36
|
+
}
|
package/lib/emitter.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Observable } from "./observable";
|
|
2
1
|
export declare class Emitter<Args extends Array<any> = []> {
|
|
3
|
-
|
|
4
|
-
private _funcs;
|
|
2
|
+
protected _funcs: [fn: ((...args: Args) => void), priority: number][];
|
|
5
3
|
private _emitting;
|
|
6
4
|
private _toUnbind;
|
|
7
5
|
private _needsSort;
|
package/lib/emitter.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Observable } from "./observable";
|
|
2
1
|
export class Emitter {
|
|
3
2
|
constructor() {
|
|
4
|
-
this.hasListeners = new Observable(false);
|
|
5
3
|
this._funcs = [];
|
|
6
4
|
this._emitting = false;
|
|
7
5
|
this._toUnbind = new Set();
|
|
@@ -9,7 +7,6 @@ export class Emitter {
|
|
|
9
7
|
}
|
|
10
8
|
clearListeners() {
|
|
11
9
|
this._funcs = [];
|
|
12
|
-
this.hasListeners.value = false;
|
|
13
10
|
this._needsSort = false;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
@@ -19,8 +16,6 @@ export class Emitter {
|
|
|
19
16
|
addListener(f, priority = 0) {
|
|
20
17
|
this._funcs.push([f, priority]);
|
|
21
18
|
this._needsSort = true;
|
|
22
|
-
if (!this.hasListeners.value)
|
|
23
|
-
this.hasListeners.value = true;
|
|
24
19
|
}
|
|
25
20
|
/**
|
|
26
21
|
* Unbind an existing function
|
|
@@ -36,8 +31,6 @@ export class Emitter {
|
|
|
36
31
|
if (indx > -1) {
|
|
37
32
|
this._funcs.splice(indx, 1);
|
|
38
33
|
}
|
|
39
|
-
if (this._funcs.length === 0 && this.hasListeners.value)
|
|
40
|
-
this.hasListeners.value = false;
|
|
41
34
|
}
|
|
42
35
|
/**
|
|
43
36
|
* Emit an event
|
package/lib/entity.js
CHANGED
|
@@ -49,7 +49,9 @@ export class Entity {
|
|
|
49
49
|
this.enabledResolved = new Observable(true);
|
|
50
50
|
this._updateHandlers = (enabled) => {
|
|
51
51
|
if (enabled && !this._handlersBound) {
|
|
52
|
-
for (const [e, fn, priority] of this._registered) {
|
|
52
|
+
for (const [e, fn, priority, bindWhenDisabled] of this._registered) {
|
|
53
|
+
if (bindWhenDisabled)
|
|
54
|
+
continue;
|
|
53
55
|
e.addListener(fn, priority);
|
|
54
56
|
}
|
|
55
57
|
this._handlersBound = true;
|
package/lib/event.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Emitter } from "./emitter";
|
|
2
|
+
import { Observable } from "./observable";
|
|
2
3
|
export declare class Event<Args extends Array<any> = []> extends Emitter<Args> {
|
|
4
|
+
hasListeners: Observable<boolean, never>;
|
|
3
5
|
/**
|
|
4
6
|
* Emit an event.
|
|
5
7
|
*
|
|
6
8
|
* @param a - The argument to pass to handler functions.
|
|
7
9
|
*/
|
|
8
10
|
emit(...args: Args): void;
|
|
11
|
+
clearListeners(): void;
|
|
12
|
+
addListener(f: (...args: Args) => void, priority?: number): void;
|
|
13
|
+
removeListener(f: (...args: Args) => void): void;
|
|
9
14
|
}
|
package/lib/event.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Emitter } from "./emitter";
|
|
2
|
+
import { Observable } from "./observable";
|
|
2
3
|
export class Event extends Emitter {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.hasListeners = new Observable(false);
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* Emit an event.
|
|
5
10
|
*
|
|
@@ -8,4 +13,18 @@ export class Event extends Emitter {
|
|
|
8
13
|
emit(...args) {
|
|
9
14
|
super._emit(...args);
|
|
10
15
|
}
|
|
16
|
+
clearListeners() {
|
|
17
|
+
super.clearListeners();
|
|
18
|
+
if (!this.hasListeners.value)
|
|
19
|
+
this.hasListeners.value = true;
|
|
20
|
+
}
|
|
21
|
+
addListener(f, priority) {
|
|
22
|
+
super.addListener(f, priority);
|
|
23
|
+
this.hasListeners.value = true;
|
|
24
|
+
}
|
|
25
|
+
removeListener(f) {
|
|
26
|
+
super.removeListener(f);
|
|
27
|
+
if (this._funcs.length === 0 && this.hasListeners.value)
|
|
28
|
+
this.hasListeners.value = false;
|
|
29
|
+
}
|
|
11
30
|
}
|
package/lib/observable.js
CHANGED
package/lib/selectors.js
CHANGED
|
@@ -212,22 +212,39 @@ export default Comp;
|
|
|
212
212
|
`;
|
|
213
213
|
};
|
|
214
214
|
function makeCommentSafe(c) {
|
|
215
|
-
return c.replaceAll('*/', '')
|
|
215
|
+
return c.replaceAll('*/', '');
|
|
216
|
+
}
|
|
217
|
+
function getJSDocForProp(prop) {
|
|
218
|
+
let lines = [];
|
|
219
|
+
for (const comment of (prop.comments ?? [])) {
|
|
220
|
+
lines.push(...comment.split('\n'));
|
|
221
|
+
}
|
|
222
|
+
if (lines.length > 0)
|
|
223
|
+
lines.push('');
|
|
224
|
+
lines.push('@zprop');
|
|
225
|
+
if (prop.default !== undefined)
|
|
226
|
+
lines.push(`@zdefault ${JSON.stringify(prop.default)}`);
|
|
227
|
+
if (prop.group)
|
|
228
|
+
lines.push('@zgroup ' + prop.group);
|
|
229
|
+
if (prop.groupPriority)
|
|
230
|
+
lines.push('@zgrouppriority ' + prop.groupPriority);
|
|
231
|
+
if (prop.type.typeHint)
|
|
232
|
+
lines.push('@ztype ' + prop.type.typeHint);
|
|
233
|
+
if (prop.values) {
|
|
234
|
+
for (const val of prop.values) {
|
|
235
|
+
lines.push('@zvalues ' + val.type + ' ' + val.param);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
lines = lines.map(makeCommentSafe);
|
|
239
|
+
lines = lines.map(entry => '\t * ' + entry);
|
|
240
|
+
return `\t/**\n${lines.join('\n')}\n\t */`;
|
|
216
241
|
}
|
|
217
242
|
function typeOutputForProp(prop) {
|
|
218
|
-
|
|
219
|
-
return ` /**${comments}
|
|
220
|
-
* @zprop
|
|
221
|
-
* ${prop.default !== undefined ? `@zdefault ${JSON.stringify(prop.default)}` : ''}
|
|
222
|
-
*/
|
|
243
|
+
return `${getJSDocForProp(prop)}
|
|
223
244
|
public ${prop.name}: Observable<${outputForType(prop.type, true)}>;`;
|
|
224
245
|
}
|
|
225
246
|
function typeOutputForConstructorProp(prop) {
|
|
226
|
-
|
|
227
|
-
return ` /**${comments}
|
|
228
|
-
* @zprop
|
|
229
|
-
* ${prop.default !== undefined && `@zdefault ${JSON.stringify(prop.default)}`}
|
|
230
|
-
*/
|
|
247
|
+
return `${getJSDocForProp(prop)}
|
|
231
248
|
${prop.name}: ${outputForType(prop.type, true)};`;
|
|
232
249
|
}
|
|
233
250
|
export function getSafeKeyName(n) {
|
package/lib/types.d.ts
CHANGED
|
@@ -55,10 +55,19 @@ export declare enum TypeHint {
|
|
|
55
55
|
"proportion" = "proportion",
|
|
56
56
|
'color-norm-rgb' = "color-norm-rgb",
|
|
57
57
|
'color-unnorm-rgb' = "color-unnorm-rgb",
|
|
58
|
-
'color-hex' = "color-hex"
|
|
58
|
+
'color-hex' = "color-hex",
|
|
59
|
+
'color-css' = "color-css"
|
|
60
|
+
}
|
|
61
|
+
export declare enum ValuesType {
|
|
62
|
+
'files' = "files",
|
|
63
|
+
'animations' = "animations",
|
|
64
|
+
'morphTargets' = "morphTargets",
|
|
65
|
+
'events' = "events",
|
|
66
|
+
'parentNodes' = "parentNodes",
|
|
67
|
+
'nodelabels' = "nodelabels"
|
|
59
68
|
}
|
|
60
69
|
export interface Values {
|
|
61
|
-
type:
|
|
70
|
+
type: ValuesType;
|
|
62
71
|
param: string;
|
|
63
72
|
}
|
|
64
73
|
export interface Prop {
|
|
@@ -104,6 +113,13 @@ export interface ValueInfo {
|
|
|
104
113
|
type: Type;
|
|
105
114
|
comments?: string[];
|
|
106
115
|
}
|
|
116
|
+
export interface PreviewInfo {
|
|
117
|
+
name: string;
|
|
118
|
+
file: string;
|
|
119
|
+
isDefault?: string;
|
|
120
|
+
comments?: string[];
|
|
121
|
+
filePattern: string;
|
|
122
|
+
}
|
|
107
123
|
export interface SourceFileTypeInfo {
|
|
108
124
|
components: {
|
|
109
125
|
[id: string]: ComponentInfo;
|
|
@@ -111,6 +127,9 @@ export interface SourceFileTypeInfo {
|
|
|
111
127
|
values: {
|
|
112
128
|
[id: string]: ValueInfo;
|
|
113
129
|
};
|
|
130
|
+
previewers: {
|
|
131
|
+
[id: string]: PreviewInfo;
|
|
132
|
+
};
|
|
114
133
|
}
|
|
115
134
|
export type TypeInfoByFileName = {
|
|
116
135
|
[id: string]: SourceFileTypeInfo;
|
package/lib/types.js
CHANGED
|
@@ -6,7 +6,17 @@ export var TypeHint;
|
|
|
6
6
|
TypeHint["color-norm-rgb"] = "color-norm-rgb";
|
|
7
7
|
TypeHint["color-unnorm-rgb"] = "color-unnorm-rgb";
|
|
8
8
|
TypeHint["color-hex"] = "color-hex";
|
|
9
|
+
TypeHint["color-css"] = "color-css";
|
|
9
10
|
})(TypeHint || (TypeHint = {}));
|
|
11
|
+
export var ValuesType;
|
|
12
|
+
(function (ValuesType) {
|
|
13
|
+
ValuesType["files"] = "files";
|
|
14
|
+
ValuesType["animations"] = "animations";
|
|
15
|
+
ValuesType["morphTargets"] = "morphTargets";
|
|
16
|
+
ValuesType["events"] = "events";
|
|
17
|
+
ValuesType["parentNodes"] = "parentNodes";
|
|
18
|
+
ValuesType["nodelabels"] = "nodelabels";
|
|
19
|
+
})(ValuesType || (ValuesType = {}));
|
|
10
20
|
function valuesCompatible(l, r) {
|
|
11
21
|
if (!l && !r)
|
|
12
22
|
return true;
|