@arcanejs/toolkit 0.0.3 → 0.1.0
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/dist/backend/components/base.d.mts +2 -0
- package/dist/backend/components/base.d.ts +2 -0
- package/dist/backend/components/base.js +189 -0
- package/dist/backend/components/base.mjs +10 -0
- package/dist/backend/components/button.d.mts +30 -0
- package/dist/backend/components/button.d.ts +30 -0
- package/dist/backend/components/button.js +168 -0
- package/dist/backend/components/button.mjs +7 -0
- package/dist/backend/components/group.d.mts +51 -0
- package/dist/backend/components/group.d.ts +51 -0
- package/dist/backend/components/group.js +287 -0
- package/dist/backend/components/group.mjs +9 -0
- package/dist/backend/components/label.d.mts +21 -0
- package/dist/backend/components/label.d.ts +21 -0
- package/dist/backend/components/label.js +105 -0
- package/dist/backend/components/label.mjs +7 -0
- package/dist/backend/components/rect.d.mts +20 -0
- package/dist/backend/components/rect.d.ts +20 -0
- package/dist/backend/components/rect.js +105 -0
- package/dist/backend/components/rect.mjs +7 -0
- package/dist/backend/components/slider-button.d.mts +31 -0
- package/dist/backend/components/slider-button.d.ts +31 -0
- package/dist/backend/components/slider-button.js +161 -0
- package/dist/backend/components/slider-button.mjs +7 -0
- package/dist/backend/components/switch.d.mts +24 -0
- package/dist/backend/components/switch.d.ts +24 -0
- package/dist/backend/components/switch.js +144 -0
- package/dist/backend/components/switch.mjs +7 -0
- package/dist/backend/components/tabs.d.mts +28 -0
- package/dist/backend/components/tabs.d.ts +28 -0
- package/dist/backend/components/tabs.js +209 -0
- package/dist/backend/components/tabs.mjs +9 -0
- package/dist/backend/components/text-input.d.mts +26 -0
- package/dist/backend/components/text-input.d.ts +26 -0
- package/dist/backend/components/text-input.js +146 -0
- package/dist/backend/components/text-input.mjs +7 -0
- package/dist/backend/components/timeline.d.mts +17 -0
- package/dist/backend/components/timeline.d.ts +17 -0
- package/dist/backend/components/timeline.js +109 -0
- package/dist/backend/components/timeline.mjs +7 -0
- package/dist/base-BJAPu0O1.d.mts +234 -0
- package/dist/base-BJAPu0O1.d.ts +234 -0
- package/dist/chunk-37VNFO5S.mjs +42 -0
- package/dist/chunk-3ZBM7Q4A.mjs +55 -0
- package/dist/chunk-6LL3X7ZZ.mjs +44 -0
- package/dist/chunk-DBW4OPGN.mjs +33 -0
- package/dist/chunk-DP3QFYSS.mjs +66 -0
- package/dist/chunk-GQZA5K4M.mjs +29 -0
- package/dist/chunk-HF77PS7J.mjs +171 -0
- package/dist/chunk-HVFTRNLQ.mjs +59 -0
- package/dist/chunk-P6X5GIDT.mjs +29 -0
- package/dist/chunk-S5DQIYC2.mjs +107 -0
- package/dist/frontend.js +26321 -0
- package/dist/frontend.js.map +7 -0
- package/dist/index.d.mts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +852 -1
- package/dist/index.mjs +288 -2
- package/package.json +83 -3
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { Diff } from '@arcanejs/diff';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Styling options for the [[Group]] component
|
|
5
|
+
*
|
|
6
|
+
* Default Styling: [[GROUP_DEFAULT_STYLE]]
|
|
7
|
+
*/
|
|
8
|
+
type GroupComponentStyle = {
|
|
9
|
+
/**
|
|
10
|
+
* In which way should child components of this group be organized?
|
|
11
|
+
*/
|
|
12
|
+
direction: 'horizontal' | 'vertical';
|
|
13
|
+
/**
|
|
14
|
+
* If true, when the group runs out of vertical or horizontal space, child
|
|
15
|
+
* components will be wrapped, and start to be arranged on additional columns
|
|
16
|
+
* or rows.
|
|
17
|
+
*/
|
|
18
|
+
wrap?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If true, this group will have a border and a different color background
|
|
21
|
+
* to its parent.
|
|
22
|
+
*
|
|
23
|
+
* This allows you to add a distinctive border between components,
|
|
24
|
+
* without needing to set a header, add header components,
|
|
25
|
+
* or make it collapsible.
|
|
26
|
+
*/
|
|
27
|
+
border?: true;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Styling options for the [[Label]] component
|
|
31
|
+
*
|
|
32
|
+
* Default Styling: [[LABEL_DEFAULT_STYLE]]
|
|
33
|
+
*/
|
|
34
|
+
type LabelComponentStyle = {
|
|
35
|
+
/**
|
|
36
|
+
* If true, make the text of this label bold
|
|
37
|
+
*/
|
|
38
|
+
bold?: boolean;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type BaseComponent = {
|
|
42
|
+
key: number;
|
|
43
|
+
};
|
|
44
|
+
type ButtonComponent = BaseComponent & {
|
|
45
|
+
component: 'button';
|
|
46
|
+
text: string;
|
|
47
|
+
icon?: string;
|
|
48
|
+
state: {
|
|
49
|
+
state: 'normal' | 'pressed';
|
|
50
|
+
} | {
|
|
51
|
+
state: 'error';
|
|
52
|
+
error: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type GroupCollapsedState = 'open' | 'closed';
|
|
56
|
+
type DefaultGroupCollapsedState = GroupCollapsedState | 'auto';
|
|
57
|
+
type GroupHeaderComponent = BaseComponent & {
|
|
58
|
+
component: 'group-header';
|
|
59
|
+
children: Component$1[];
|
|
60
|
+
};
|
|
61
|
+
type GroupComponent = BaseComponent & GroupComponentStyle & {
|
|
62
|
+
component: 'group';
|
|
63
|
+
title?: string;
|
|
64
|
+
children: Component$1[];
|
|
65
|
+
headers?: GroupHeaderComponent[];
|
|
66
|
+
labels?: Array<{
|
|
67
|
+
text: string;
|
|
68
|
+
}>;
|
|
69
|
+
editableTitle: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* If set, allows the group to be collapsed,
|
|
72
|
+
* by default set to the given state
|
|
73
|
+
*/
|
|
74
|
+
defaultCollapsibleState?: DefaultGroupCollapsedState;
|
|
75
|
+
};
|
|
76
|
+
type LabelComponent = BaseComponent & {
|
|
77
|
+
component: 'label';
|
|
78
|
+
bold?: boolean;
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
type RectComponent = BaseComponent & {
|
|
82
|
+
component: 'rect';
|
|
83
|
+
color: string;
|
|
84
|
+
};
|
|
85
|
+
type SliderButtonComponent = BaseComponent & {
|
|
86
|
+
component: 'slider_button';
|
|
87
|
+
min: number;
|
|
88
|
+
max: number;
|
|
89
|
+
step: number;
|
|
90
|
+
value: number | null;
|
|
91
|
+
};
|
|
92
|
+
type SwitchComponent = BaseComponent & {
|
|
93
|
+
component: 'switch';
|
|
94
|
+
state: 'on' | 'off';
|
|
95
|
+
};
|
|
96
|
+
type TabComponent = BaseComponent & {
|
|
97
|
+
component: 'tab';
|
|
98
|
+
name: string;
|
|
99
|
+
child?: Component$1;
|
|
100
|
+
};
|
|
101
|
+
type TabsComponent = BaseComponent & {
|
|
102
|
+
component: 'tabs';
|
|
103
|
+
tabs: TabComponent[];
|
|
104
|
+
};
|
|
105
|
+
type TextInputComponent = BaseComponent & {
|
|
106
|
+
component: 'text-input';
|
|
107
|
+
value: string;
|
|
108
|
+
};
|
|
109
|
+
type TimelineState = {
|
|
110
|
+
state: 'playing';
|
|
111
|
+
totalTimeMillis: number;
|
|
112
|
+
effectiveStartTime: number;
|
|
113
|
+
speed: number;
|
|
114
|
+
} | {
|
|
115
|
+
state: 'stopped';
|
|
116
|
+
totalTimeMillis: number;
|
|
117
|
+
currentTimeMillis: number;
|
|
118
|
+
};
|
|
119
|
+
type TimelineComponent = BaseComponent & {
|
|
120
|
+
component: 'timeline';
|
|
121
|
+
state: TimelineState;
|
|
122
|
+
title?: string;
|
|
123
|
+
subtitles?: string[];
|
|
124
|
+
source?: {
|
|
125
|
+
name: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
type Component$1 = ButtonComponent | GroupHeaderComponent | GroupComponent | LabelComponent | RectComponent | SliderButtonComponent | SwitchComponent | TabComponent | TabsComponent | TextInputComponent | TimelineComponent;
|
|
129
|
+
type SendTreeMsg = {
|
|
130
|
+
type: 'tree-full';
|
|
131
|
+
root: GroupComponent;
|
|
132
|
+
};
|
|
133
|
+
type UpdateTreeMsg = {
|
|
134
|
+
type: 'tree-diff';
|
|
135
|
+
diff: Diff<GroupComponent>;
|
|
136
|
+
};
|
|
137
|
+
type ServerMessage = SendTreeMsg | UpdateTreeMsg;
|
|
138
|
+
type BaseClientComponentMessage = {
|
|
139
|
+
type: 'component-message';
|
|
140
|
+
componentKey: number;
|
|
141
|
+
};
|
|
142
|
+
type ButtonPressMessage = BaseClientComponentMessage & {
|
|
143
|
+
component: 'button';
|
|
144
|
+
};
|
|
145
|
+
type GroupTitleChangeMessage = BaseClientComponentMessage & {
|
|
146
|
+
component: 'group';
|
|
147
|
+
title: string;
|
|
148
|
+
};
|
|
149
|
+
type SliderButtonUpdateMessage = BaseClientComponentMessage & {
|
|
150
|
+
component: 'slider_button';
|
|
151
|
+
value: number;
|
|
152
|
+
};
|
|
153
|
+
type SwitchToggleMessage = BaseClientComponentMessage & {
|
|
154
|
+
component: 'switch';
|
|
155
|
+
};
|
|
156
|
+
type TextInputUpdateMessage = BaseClientComponentMessage & {
|
|
157
|
+
component: 'text-input';
|
|
158
|
+
value: string;
|
|
159
|
+
};
|
|
160
|
+
type ClientComponentMessage = ButtonPressMessage | GroupTitleChangeMessage | SliderButtonUpdateMessage | SwitchToggleMessage | TextInputUpdateMessage;
|
|
161
|
+
type ClientMessage = ClientComponentMessage;
|
|
162
|
+
|
|
163
|
+
declare class IDMap {
|
|
164
|
+
private readonly idMap;
|
|
165
|
+
private nextId;
|
|
166
|
+
getId(object: object): number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface Component {
|
|
170
|
+
getProtoInfo(idMap: IDMap): Component$1;
|
|
171
|
+
handleMessage(message: ClientComponentMessage): void;
|
|
172
|
+
routeMessage(idMap: IDMap, message: ClientComponentMessage): void;
|
|
173
|
+
setParent(parent: Parent | null): void;
|
|
174
|
+
}
|
|
175
|
+
declare abstract class Base<Props> implements Component {
|
|
176
|
+
/** @hidden */
|
|
177
|
+
private parent;
|
|
178
|
+
/** @hidden */
|
|
179
|
+
private readonly defaultProps;
|
|
180
|
+
/** @hidden */
|
|
181
|
+
private _props;
|
|
182
|
+
constructor(defaultProps: Props, props?: Partial<Props>);
|
|
183
|
+
get props(): Props;
|
|
184
|
+
set props(props: Partial<Props>);
|
|
185
|
+
setProps: (props: Partial<Props>) => void;
|
|
186
|
+
updateProps: (updates: Partial<Props>) => void;
|
|
187
|
+
/** @hidden */
|
|
188
|
+
setParent(parent: Parent | null): void;
|
|
189
|
+
/** @hidden */
|
|
190
|
+
updateTree(): void;
|
|
191
|
+
/** @hidden */
|
|
192
|
+
abstract getProtoInfo(idMap: IDMap): Component$1;
|
|
193
|
+
/** @hidden */
|
|
194
|
+
handleMessage(message: ClientComponentMessage): void;
|
|
195
|
+
routeMessage(_idMap: IDMap, _message: ClientComponentMessage): void;
|
|
196
|
+
}
|
|
197
|
+
/** @hidden */
|
|
198
|
+
interface Parent {
|
|
199
|
+
updateTree(): void;
|
|
200
|
+
removeChild(component: Component): void;
|
|
201
|
+
}
|
|
202
|
+
declare abstract class BaseParent<T> extends Base<T> implements Parent {
|
|
203
|
+
/** @hidden */
|
|
204
|
+
private children;
|
|
205
|
+
abstract validateChildren(children: Component[]): void;
|
|
206
|
+
appendChildren: <CS extends Component[]>(...children: CS) => CS;
|
|
207
|
+
appendChild: <C extends Component>(child: C) => C;
|
|
208
|
+
removeChild: (component: Component) => void;
|
|
209
|
+
removeAllChildren: () => void;
|
|
210
|
+
/**
|
|
211
|
+
* Return all children components that messages need to be routed to
|
|
212
|
+
*/
|
|
213
|
+
getChildren: () => readonly Component[];
|
|
214
|
+
/**
|
|
215
|
+
* TODO: we can do this better, right now it broadcasts the message to all
|
|
216
|
+
* components of the tree
|
|
217
|
+
*
|
|
218
|
+
* @hidden
|
|
219
|
+
*/
|
|
220
|
+
routeMessage(idMap: IDMap, message: ClientComponentMessage): void;
|
|
221
|
+
insertBefore(child: Component, beforeChild: Component): void;
|
|
222
|
+
}
|
|
223
|
+
interface Listenable<Map extends Record<string, (...args: any[]) => void>> {
|
|
224
|
+
addListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
225
|
+
removeListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
226
|
+
}
|
|
227
|
+
declare class EventEmitter<Map extends Record<string, (...args: any[]) => void>> implements Listenable<Map> {
|
|
228
|
+
private readonly listeners;
|
|
229
|
+
addListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
230
|
+
removeListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
231
|
+
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<unknown>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export { BaseParent as B, type ClientMessage as C, EventEmitter as E, type GroupComponentStyle as G, IDMap as I, type Listenable as L, type Parent as P, type ServerMessage as S, type TabComponent as T, type Component as a, type GroupHeaderComponent as b, type GroupComponent as c, type ClientComponentMessage as d, Base as e, type ButtonComponent as f, type Component$1 as g, type LabelComponentStyle as h, type TabsComponent as i, type TimelineState as j, type TimelineComponent as k };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base,
|
|
3
|
+
EventEmitter
|
|
4
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
5
|
+
|
|
6
|
+
// src/backend/components/switch.ts
|
|
7
|
+
var DEFAULT_PROPS = {
|
|
8
|
+
state: "off"
|
|
9
|
+
};
|
|
10
|
+
var Switch = class extends Base {
|
|
11
|
+
/** @hidden */
|
|
12
|
+
events = new EventEmitter();
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(DEFAULT_PROPS, props);
|
|
15
|
+
}
|
|
16
|
+
addListener = this.events.addListener;
|
|
17
|
+
removeListener = this.events.removeListener;
|
|
18
|
+
/** @hidden */
|
|
19
|
+
getProtoInfo(idMap) {
|
|
20
|
+
return {
|
|
21
|
+
component: "switch",
|
|
22
|
+
key: idMap.getId(this),
|
|
23
|
+
state: this.props.state
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** @hidden */
|
|
27
|
+
handleMessage(message) {
|
|
28
|
+
if (message.component === "switch") {
|
|
29
|
+
const state = this.props.state === "on" ? "off" : "on";
|
|
30
|
+
this.updateProps({ state });
|
|
31
|
+
this.events.emit("change", state);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
setValue(state) {
|
|
35
|
+
if (state === this.props.state) return;
|
|
36
|
+
this.updateProps({ state });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
Switch
|
|
42
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseParent
|
|
3
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
4
|
+
|
|
5
|
+
// src/backend/components/tabs.ts
|
|
6
|
+
var Tab = class extends BaseParent {
|
|
7
|
+
validateChildren = (children) => {
|
|
8
|
+
if (children.length > 1) {
|
|
9
|
+
throw new Error("Tab can only have one child");
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/** @hidden */
|
|
13
|
+
getProtoInfo = (idMap) => ({
|
|
14
|
+
component: "tab",
|
|
15
|
+
key: idMap.getId(this),
|
|
16
|
+
name: this.props.name,
|
|
17
|
+
child: this.getChildren().slice(0, 1).map((c) => c.getProtoInfo(idMap))[0]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var Tabs = class extends BaseParent {
|
|
21
|
+
validateChildren = (children) => {
|
|
22
|
+
for (const child of children) {
|
|
23
|
+
if (!(child instanceof Tab)) {
|
|
24
|
+
throw new Error("Tabs can only have Tab children");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super({}, { ...props });
|
|
30
|
+
}
|
|
31
|
+
addTabs(...tabs) {
|
|
32
|
+
for (const t of tabs) {
|
|
33
|
+
const tab = new Tab({ name: t.name });
|
|
34
|
+
tab.appendChildren(t.component);
|
|
35
|
+
this.appendChild(tab);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
addTab(name, component) {
|
|
39
|
+
this.addTabs({ name, component });
|
|
40
|
+
return component;
|
|
41
|
+
}
|
|
42
|
+
/** @hidden */
|
|
43
|
+
getProtoInfo(idMap) {
|
|
44
|
+
return {
|
|
45
|
+
component: "tabs",
|
|
46
|
+
key: idMap.getId(this),
|
|
47
|
+
tabs: this.getChildren().map((c) => c.getProtoInfo(idMap))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
Tab,
|
|
54
|
+
Tabs
|
|
55
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base,
|
|
3
|
+
EventEmitter
|
|
4
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
5
|
+
|
|
6
|
+
// src/backend/components/text-input.ts
|
|
7
|
+
var DEFAULT_PROPS = {
|
|
8
|
+
value: null
|
|
9
|
+
};
|
|
10
|
+
var TextInput = class extends Base {
|
|
11
|
+
/** @hidden */
|
|
12
|
+
events = new EventEmitter();
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(DEFAULT_PROPS, props);
|
|
15
|
+
}
|
|
16
|
+
addListener = this.events.addListener;
|
|
17
|
+
removeListener = this.events.removeListener;
|
|
18
|
+
/** @hidden */
|
|
19
|
+
getProtoInfo = (idMap) => {
|
|
20
|
+
return {
|
|
21
|
+
component: "text-input",
|
|
22
|
+
key: idMap.getId(this),
|
|
23
|
+
value: this.props.value ?? ""
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** @hidden */
|
|
27
|
+
handleMessage = (message) => {
|
|
28
|
+
if (message.component === "text-input") {
|
|
29
|
+
if (this.props.value !== message.value) {
|
|
30
|
+
this.updateProps({ value: message.value });
|
|
31
|
+
this.events.emit("change", message.value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
getValue = () => this.props.value;
|
|
36
|
+
getValidatedValue = (validator) => this.props.value === "" ? null : validator(this.props.value || "");
|
|
37
|
+
setValue = (value) => {
|
|
38
|
+
this.updateProps({ value });
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
TextInput
|
|
44
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base
|
|
3
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
4
|
+
|
|
5
|
+
// src/backend/components/timeline.ts
|
|
6
|
+
var DEFAULT_PROPS = {
|
|
7
|
+
state: {
|
|
8
|
+
state: "stopped",
|
|
9
|
+
totalTimeMillis: 0,
|
|
10
|
+
currentTimeMillis: 0
|
|
11
|
+
},
|
|
12
|
+
title: null,
|
|
13
|
+
subtitles: null,
|
|
14
|
+
source: null
|
|
15
|
+
};
|
|
16
|
+
var Timeline = class extends Base {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(DEFAULT_PROPS, props);
|
|
19
|
+
}
|
|
20
|
+
/** @hidden */
|
|
21
|
+
getProtoInfo = (idMap) => ({
|
|
22
|
+
component: "timeline",
|
|
23
|
+
key: idMap.getId(this),
|
|
24
|
+
state: this.props.state,
|
|
25
|
+
title: this.props.title ?? void 0,
|
|
26
|
+
subtitles: this.props.subtitles ?? void 0,
|
|
27
|
+
source: this.props.source ?? void 0
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
Timeline
|
|
33
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base,
|
|
3
|
+
EventEmitter
|
|
4
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
5
|
+
|
|
6
|
+
// src/backend/components/button.ts
|
|
7
|
+
var DEFAULT_PROPS = {
|
|
8
|
+
text: null,
|
|
9
|
+
icon: null,
|
|
10
|
+
mode: "normal",
|
|
11
|
+
error: null
|
|
12
|
+
};
|
|
13
|
+
var Button = class extends Base {
|
|
14
|
+
/** @hidden */
|
|
15
|
+
events = new EventEmitter();
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(DEFAULT_PROPS, props);
|
|
18
|
+
}
|
|
19
|
+
addListener = this.events.addListener;
|
|
20
|
+
removeListener = this.events.removeListener;
|
|
21
|
+
setText = (text) => {
|
|
22
|
+
this.updateProps({ text });
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
setIcon = (icon) => {
|
|
26
|
+
this.updateProps({ icon: icon ?? null });
|
|
27
|
+
return this;
|
|
28
|
+
};
|
|
29
|
+
setMode = (mode) => {
|
|
30
|
+
this.updateProps({
|
|
31
|
+
mode,
|
|
32
|
+
error: null
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
/** @hidden */
|
|
37
|
+
getProtoInfo = (idMap) => {
|
|
38
|
+
return {
|
|
39
|
+
component: "button",
|
|
40
|
+
key: idMap.getId(this),
|
|
41
|
+
text: this.props.text || "",
|
|
42
|
+
state: this.props.error ? { state: "error", error: this.props.error } : { state: this.props.mode },
|
|
43
|
+
icon: this.props.icon ?? void 0
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** @hidden */
|
|
47
|
+
handleMessage = (message) => {
|
|
48
|
+
if (message.component === "button") {
|
|
49
|
+
this.events.emit("click").then(() => {
|
|
50
|
+
if (this.props.error) {
|
|
51
|
+
this.updateProps({
|
|
52
|
+
error: null
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}).catch((e) => {
|
|
56
|
+
this.updateProps({
|
|
57
|
+
error: `${e}`
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
Button
|
|
66
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base
|
|
3
|
+
} from "./chunk-HF77PS7J.mjs";
|
|
4
|
+
|
|
5
|
+
// src/backend/components/rect.ts
|
|
6
|
+
var DEFAULT_PROPS = {
|
|
7
|
+
color: "rgba(0, 0, 0, 0)"
|
|
8
|
+
};
|
|
9
|
+
var Rect = class extends Base {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(DEFAULT_PROPS, props);
|
|
12
|
+
}
|
|
13
|
+
/** @hidden */
|
|
14
|
+
getProtoInfo(idMap) {
|
|
15
|
+
return {
|
|
16
|
+
component: "rect",
|
|
17
|
+
key: idMap.getId(this),
|
|
18
|
+
color: this.props.color
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
setColor(color) {
|
|
22
|
+
this.updateProps({ color });
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
Rect
|
|
29
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/backend/components/base.ts
|
|
9
|
+
var Base = class {
|
|
10
|
+
/** @hidden */
|
|
11
|
+
parent = null;
|
|
12
|
+
/** @hidden */
|
|
13
|
+
defaultProps;
|
|
14
|
+
/** @hidden */
|
|
15
|
+
_props;
|
|
16
|
+
constructor(defaultProps, props) {
|
|
17
|
+
this.defaultProps = defaultProps;
|
|
18
|
+
this._props = Object.freeze({
|
|
19
|
+
...defaultProps,
|
|
20
|
+
...props
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
get props() {
|
|
24
|
+
return this._props;
|
|
25
|
+
}
|
|
26
|
+
set props(props) {
|
|
27
|
+
this.setProps(props);
|
|
28
|
+
}
|
|
29
|
+
setProps = (props) => {
|
|
30
|
+
this._props = Object.freeze({
|
|
31
|
+
...this.defaultProps,
|
|
32
|
+
...props
|
|
33
|
+
});
|
|
34
|
+
this.updateTree();
|
|
35
|
+
};
|
|
36
|
+
updateProps = (updates) => {
|
|
37
|
+
this._props = Object.freeze({
|
|
38
|
+
...this._props,
|
|
39
|
+
...updates
|
|
40
|
+
});
|
|
41
|
+
this.updateTree();
|
|
42
|
+
};
|
|
43
|
+
/** @hidden */
|
|
44
|
+
setParent(parent) {
|
|
45
|
+
if (this.parent && this.parent !== parent) {
|
|
46
|
+
this.parent.removeChild(this);
|
|
47
|
+
}
|
|
48
|
+
this.parent = parent;
|
|
49
|
+
}
|
|
50
|
+
/** @hidden */
|
|
51
|
+
updateTree() {
|
|
52
|
+
if (this.parent) this.parent.updateTree();
|
|
53
|
+
}
|
|
54
|
+
/** @hidden */
|
|
55
|
+
handleMessage(message) {
|
|
56
|
+
console.log("Component Received Message:", message);
|
|
57
|
+
}
|
|
58
|
+
routeMessage(_idMap, _message) {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var BaseParent = class extends Base {
|
|
62
|
+
/** @hidden */
|
|
63
|
+
children = [];
|
|
64
|
+
appendChildren = (...children) => {
|
|
65
|
+
for (const c of children) {
|
|
66
|
+
const newChildren = [...this.children.filter((ch) => ch !== c), c];
|
|
67
|
+
this.validateChildren(newChildren);
|
|
68
|
+
this.children = Object.freeze(newChildren);
|
|
69
|
+
c.setParent(this);
|
|
70
|
+
}
|
|
71
|
+
this.updateTree();
|
|
72
|
+
return children;
|
|
73
|
+
};
|
|
74
|
+
appendChild = (child) => {
|
|
75
|
+
this.appendChildren(child);
|
|
76
|
+
return child;
|
|
77
|
+
};
|
|
78
|
+
removeChild = (component) => {
|
|
79
|
+
const match = this.children.findIndex((c) => c === component);
|
|
80
|
+
if (match >= 0) {
|
|
81
|
+
const removingChild = this.children[match];
|
|
82
|
+
const newChildren = [
|
|
83
|
+
...this.children.slice(0, match),
|
|
84
|
+
...this.children.slice(match + 1)
|
|
85
|
+
];
|
|
86
|
+
this.validateChildren(newChildren);
|
|
87
|
+
this.children = Object.freeze(newChildren);
|
|
88
|
+
removingChild?.setParent(null);
|
|
89
|
+
this.updateTree();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
removeAllChildren = () => {
|
|
93
|
+
this.children.map((c) => c.setParent(null));
|
|
94
|
+
this.children = Object.freeze([]);
|
|
95
|
+
this.updateTree();
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Return all children components that messages need to be routed to
|
|
99
|
+
*/
|
|
100
|
+
getChildren = () => this.children;
|
|
101
|
+
/**
|
|
102
|
+
* TODO: we can do this better, right now it broadcasts the message to all
|
|
103
|
+
* components of the tree
|
|
104
|
+
*
|
|
105
|
+
* @hidden
|
|
106
|
+
*/
|
|
107
|
+
routeMessage(idMap, message) {
|
|
108
|
+
if (idMap.getId(this) === message.componentKey) {
|
|
109
|
+
this.handleMessage(message);
|
|
110
|
+
} else {
|
|
111
|
+
for (const c of this.children) {
|
|
112
|
+
if (idMap.getId(c) === message.componentKey) {
|
|
113
|
+
c.handleMessage(message);
|
|
114
|
+
} else {
|
|
115
|
+
c.routeMessage(idMap, message);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
insertBefore(child, beforeChild) {
|
|
121
|
+
const filteredChildren = this.children.filter((c) => c !== child);
|
|
122
|
+
let match = filteredChildren.findIndex((c) => c === beforeChild);
|
|
123
|
+
console.log("match", match);
|
|
124
|
+
if (match === -1) {
|
|
125
|
+
match = filteredChildren.length;
|
|
126
|
+
}
|
|
127
|
+
const newChildren = [
|
|
128
|
+
...filteredChildren.slice(0, match),
|
|
129
|
+
child,
|
|
130
|
+
...filteredChildren.slice(match)
|
|
131
|
+
];
|
|
132
|
+
this.validateChildren(newChildren);
|
|
133
|
+
this.children = Object.freeze(newChildren);
|
|
134
|
+
child.setParent(this);
|
|
135
|
+
this.updateTree();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var EventEmitter = class {
|
|
139
|
+
listeners = /* @__PURE__ */ new Map();
|
|
140
|
+
addListener = (type, listener) => {
|
|
141
|
+
let set = this.listeners.get(type);
|
|
142
|
+
if (!set) {
|
|
143
|
+
set = /* @__PURE__ */ new Set();
|
|
144
|
+
this.listeners.set(type, set);
|
|
145
|
+
}
|
|
146
|
+
set.add(listener);
|
|
147
|
+
};
|
|
148
|
+
removeListener = (type, listener) => {
|
|
149
|
+
this.listeners.get(type)?.delete(listener);
|
|
150
|
+
};
|
|
151
|
+
emit = (type, ...args) => {
|
|
152
|
+
return Promise.all(
|
|
153
|
+
[...this.listeners.get(type) || []].map(
|
|
154
|
+
(l) => new Promise((resolve, reject) => {
|
|
155
|
+
try {
|
|
156
|
+
resolve(l(...args));
|
|
157
|
+
} catch (e) {
|
|
158
|
+
reject(e);
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
__require,
|
|
168
|
+
Base,
|
|
169
|
+
BaseParent,
|
|
170
|
+
EventEmitter
|
|
171
|
+
};
|