@arcanejs/toolkit 1.1.0 → 2.0.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 +10 -79
- package/dist/backend/components/base.d.ts +10 -79
- package/dist/backend/components/base.js +2 -2
- package/dist/backend/components/base.mjs +1 -1
- package/dist/backend/components/button.d.mts +9 -33
- package/dist/backend/components/button.d.ts +9 -33
- package/dist/backend/components/button.js +3 -3
- package/dist/backend/components/button.mjs +2 -2
- package/dist/backend/components/group.d.mts +9 -54
- package/dist/backend/components/group.d.ts +9 -54
- package/dist/backend/components/group.js +3 -3
- package/dist/backend/components/group.mjs +2 -2
- package/dist/backend/components/label.d.mts +6 -2
- package/dist/backend/components/label.d.ts +6 -2
- package/dist/backend/components/label.js +3 -3
- package/dist/backend/components/label.mjs +2 -2
- package/dist/backend/components/rect.d.mts +7 -2
- package/dist/backend/components/rect.d.ts +7 -2
- package/dist/backend/components/rect.js +3 -3
- package/dist/backend/components/rect.mjs +2 -2
- package/dist/backend/components/slider-button.d.mts +8 -3
- package/dist/backend/components/slider-button.d.ts +8 -3
- package/dist/backend/components/slider-button.js +3 -3
- package/dist/backend/components/slider-button.mjs +2 -2
- package/dist/backend/components/switch.d.mts +8 -3
- package/dist/backend/components/switch.d.ts +8 -3
- package/dist/backend/components/switch.js +3 -3
- package/dist/backend/components/switch.mjs +2 -2
- package/dist/backend/components/tabs.d.mts +7 -2
- package/dist/backend/components/tabs.d.ts +7 -2
- package/dist/backend/components/tabs.js +3 -3
- package/dist/backend/components/tabs.mjs +2 -2
- package/dist/backend/components/text-input.d.mts +8 -3
- package/dist/backend/components/text-input.d.ts +8 -3
- package/dist/backend/components/text-input.js +3 -3
- package/dist/backend/components/text-input.mjs +2 -2
- package/dist/backend/components/timeline.d.mts +7 -2
- package/dist/backend/components/timeline.d.ts +7 -2
- package/dist/backend/components/timeline.js +3 -3
- package/dist/backend/components/timeline.mjs +2 -2
- package/dist/{chunk-HNFNG5MD.js → chunk-4OZ22IQU.js} +5 -5
- package/dist/{chunk-5TGGF5UJ.mjs → chunk-5D7OSUZ6.mjs} +3 -3
- package/dist/{chunk-T4TMVBFM.js → chunk-6CWEURJP.js} +2 -2
- package/dist/{chunk-5JPYL5IU.js → chunk-7OX2FB6C.js} +2 -2
- package/dist/{chunk-PXYXUWXE.mjs → chunk-7TTY7CBH.mjs} +1 -1
- package/dist/{chunk-SIXWXDZW.js → chunk-CME7HZZK.js} +5 -5
- package/dist/{chunk-OAPIVG6M.mjs → chunk-CUZSHFDP.mjs} +1 -1
- package/dist/{chunk-ZLJECS4H.js → chunk-DG75CS7F.js} +5 -5
- package/dist/{chunk-V5T44HCM.js → chunk-DRQVYGTI.js} +2 -2
- package/dist/{chunk-ARRRZPUK.js → chunk-GMDJYFHD.js} +3 -3
- package/dist/{chunk-IBIEYR3L.mjs → chunk-JFZXSCGK.mjs} +3 -3
- package/dist/{chunk-LX5IL6WX.mjs → chunk-K37TZB75.mjs} +1 -1
- package/dist/{chunk-BDBRQJSI.mjs → chunk-N6IHYBZH.mjs} +1 -1
- package/dist/{chunk-SBHNIFAS.mjs → chunk-NEQRLPXK.mjs} +3 -3
- package/dist/{chunk-TOPIQUBZ.js → chunk-O5ZW6JYG.js} +6 -6
- package/dist/{chunk-7SZA6JUN.mjs → chunk-RYR5I5FT.mjs} +6 -6
- package/dist/{chunk-ADH7RZG5.js → chunk-SGACFY53.js} +6 -6
- package/dist/{chunk-25LALCAN.js → chunk-VEZGD2PG.js} +5 -5
- package/dist/{chunk-EFNFSHV3.mjs → chunk-W42AOMM6.mjs} +3 -3
- package/dist/{chunk-ISHGZXPO.mjs → chunk-YBBUC3QC.mjs} +3 -3
- package/dist/frontend/entrypoint.js +18 -7
- package/dist/frontend/entrypoint.js.map +2 -2
- package/dist/frontend/index.js +11 -1
- package/dist/frontend/index.mjs +11 -1
- package/dist/index.d.mts +7 -111
- package/dist/index.d.ts +7 -111
- package/dist/index.js +65 -26
- package/dist/index.mjs +54 -15
- package/dist/toolkit-2w2SWHlT.d.ts +269 -0
- package/dist/toolkit-DB8G2TaA.d.mts +269 -0
- package/package.json +6 -5
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as _arcanejs_protocol_logging from '@arcanejs/protocol/logging';
|
|
2
|
+
import { Logger } from '@arcanejs/protocol/logging';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import * as http from 'http';
|
|
5
|
+
import { Application } from 'express';
|
|
6
|
+
import { WebSocket } from 'ws';
|
|
7
|
+
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage } from '@arcanejs/protocol';
|
|
8
|
+
import * as proto from '@arcanejs/protocol/core';
|
|
9
|
+
import { GroupComponentStyle } from '@arcanejs/protocol/styles';
|
|
10
|
+
import { I as IDMap } from './id-map-DxQ3_gyA.js';
|
|
11
|
+
|
|
12
|
+
interface Connection {
|
|
13
|
+
sendMessage(msg: ServerMessage): void;
|
|
14
|
+
}
|
|
15
|
+
declare class Server {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly onNewConnection;
|
|
18
|
+
private readonly onClosedConnection;
|
|
19
|
+
private readonly onMessage;
|
|
20
|
+
private readonly log?;
|
|
21
|
+
private readonly staticFiles;
|
|
22
|
+
private readonly entrypointFilename;
|
|
23
|
+
private title;
|
|
24
|
+
constructor(options: ToolkitOptions, onNewConnection: (connection: Connection) => void, onClosedConnection: (connection: Connection) => void, onMessage: (connection: Connection, message: ClientMessage) => void, log?: Logger | undefined);
|
|
25
|
+
handleHttpRequest: (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
26
|
+
private sendStaticFile;
|
|
27
|
+
handleWsConnection: <S extends WebSocket>(ws: S) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ToolkitOptions {
|
|
31
|
+
/**
|
|
32
|
+
* What window title should the toolkit be initialized with?
|
|
33
|
+
*/
|
|
34
|
+
title?: string;
|
|
35
|
+
/**
|
|
36
|
+
* What path should be used to serve the light desk.
|
|
37
|
+
*
|
|
38
|
+
* This is important if a express server will be used that serves other paths.
|
|
39
|
+
*/
|
|
40
|
+
path: string;
|
|
41
|
+
/**
|
|
42
|
+
* An optional object that can be used to output log events,
|
|
43
|
+
* we recommend using `pino` for this,
|
|
44
|
+
* as log levels etc... can be controlled.
|
|
45
|
+
*
|
|
46
|
+
* You can also always use `console` for logging,
|
|
47
|
+
* but this will be quite verbose.
|
|
48
|
+
*/
|
|
49
|
+
log?: Logger;
|
|
50
|
+
/**
|
|
51
|
+
* The entrypoint file that should be used to serve the light desk.
|
|
52
|
+
*
|
|
53
|
+
* This is only needed if you have defined custom extensions,
|
|
54
|
+
* and need to load custom frontend code that includes your extensions.
|
|
55
|
+
*
|
|
56
|
+
* This will allow access to both the js file and the `.map.js` file,
|
|
57
|
+
* that matches this name.
|
|
58
|
+
*/
|
|
59
|
+
entrypointJsFile?: string;
|
|
60
|
+
/**
|
|
61
|
+
* If it's not possible to automatically resolve and import the
|
|
62
|
+
* material-symbols package in node_modules
|
|
63
|
+
* (for example when bundling an electron app),
|
|
64
|
+
* you can provide the path to the material-symbols-outlined.woff2 file here.
|
|
65
|
+
*/
|
|
66
|
+
materialIconsFontFile?: string;
|
|
67
|
+
}
|
|
68
|
+
type InitializationOptions =
|
|
69
|
+
/** automatically start a simple */
|
|
70
|
+
{
|
|
71
|
+
mode: 'automatic';
|
|
72
|
+
port: number;
|
|
73
|
+
/**
|
|
74
|
+
* Optional callback that is called when the server is ready,
|
|
75
|
+
* with the url that the server is running on.
|
|
76
|
+
*/
|
|
77
|
+
onReady?: (url: string) => void;
|
|
78
|
+
}
|
|
79
|
+
/** Create a websocket server that attaches to an existing express and http server */
|
|
80
|
+
| {
|
|
81
|
+
mode: 'express';
|
|
82
|
+
express: Application;
|
|
83
|
+
server: http.Server;
|
|
84
|
+
}
|
|
85
|
+
/** Create a websocket server that attaches to an existing express and http server */
|
|
86
|
+
| {
|
|
87
|
+
mode: 'manual';
|
|
88
|
+
setup: (server: Server) => void;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace>, Props> {
|
|
92
|
+
/** @hidden */
|
|
93
|
+
private parent;
|
|
94
|
+
/** @hidden */
|
|
95
|
+
private readonly defaultProps;
|
|
96
|
+
/** @hidden */
|
|
97
|
+
private _props;
|
|
98
|
+
/** @hidden */
|
|
99
|
+
private _onPropsUpdated;
|
|
100
|
+
constructor(defaultProps: Props, props?: Partial<Props>, options?: {
|
|
101
|
+
onPropsUpdated?: (oldProps: Props) => void;
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Call if
|
|
105
|
+
*/
|
|
106
|
+
triggerInitialPropsUpdate: () => void;
|
|
107
|
+
log: () => Logger | null;
|
|
108
|
+
get props(): Props;
|
|
109
|
+
set props(props: Partial<Props>);
|
|
110
|
+
setProps: (props: Partial<Props>) => void;
|
|
111
|
+
updateProps: (updates: Partial<Props>) => void;
|
|
112
|
+
/** @hidden */
|
|
113
|
+
setParent(parent: Parent | null): void;
|
|
114
|
+
/** @hidden */
|
|
115
|
+
updateTree(): void;
|
|
116
|
+
/** @hidden */
|
|
117
|
+
abstract getProtoInfo(idMap: IDMap): Proto;
|
|
118
|
+
/** @hidden */
|
|
119
|
+
handleMessage(_message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
120
|
+
routeMessage(_idMap: IDMap, _message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
121
|
+
}
|
|
122
|
+
type AnyComponent = Base<string, BaseComponentProto<string>, any>;
|
|
123
|
+
/** @hidden */
|
|
124
|
+
interface Parent {
|
|
125
|
+
updateTree(): void;
|
|
126
|
+
removeChild(component: AnyComponent): void;
|
|
127
|
+
log(): Logger | null;
|
|
128
|
+
}
|
|
129
|
+
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace>, T> extends Base<Namespace, Proto, T> implements Parent {
|
|
130
|
+
/** @hidden */
|
|
131
|
+
private children;
|
|
132
|
+
abstract validateChildren(children: AnyComponent[]): void;
|
|
133
|
+
appendChildren: <CS extends AnyComponent[]>(...children: CS) => CS;
|
|
134
|
+
appendChild: <C extends AnyComponent>(child: C) => C;
|
|
135
|
+
removeChild: (component: AnyComponent) => void;
|
|
136
|
+
removeAllChildren: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Return all children components that messages need to be routed to
|
|
139
|
+
*/
|
|
140
|
+
getChildren: () => readonly AnyComponent[];
|
|
141
|
+
/**
|
|
142
|
+
* TODO: we can do this better, right now it broadcasts the message to all
|
|
143
|
+
* components of the tree
|
|
144
|
+
*
|
|
145
|
+
* @hidden
|
|
146
|
+
*/
|
|
147
|
+
routeMessage(idMap: IDMap, message: AnyClientComponentMessage, connection: ToolkitConnection): void;
|
|
148
|
+
insertBefore(child: AnyComponent, beforeChild: AnyComponent): void;
|
|
149
|
+
}
|
|
150
|
+
interface Listenable<Map extends Record<string, (...args: any[]) => void>> {
|
|
151
|
+
addListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
152
|
+
removeListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
153
|
+
}
|
|
154
|
+
declare class EventEmitter<Map extends Record<string, (...args: any[]) => void>> implements Listenable<Map> {
|
|
155
|
+
private readonly listeners;
|
|
156
|
+
addListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
157
|
+
removeListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
158
|
+
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<unknown>;
|
|
159
|
+
/**
|
|
160
|
+
* Process prop changes to update listeners
|
|
161
|
+
*/
|
|
162
|
+
processPropChanges: <Mapping extends Record<string, keyof Map>, Props extends { [key in keyof Mapping]?: Map[Mapping[key]] | null | undefined; }>(mapping: Mapping, oldProps: Props, newProps: Props) => void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type Events$2 = {
|
|
166
|
+
click: (connection: ToolkitConnection) => void | Promise<void>;
|
|
167
|
+
};
|
|
168
|
+
type ButtonMode = 'normal' | 'pressed';
|
|
169
|
+
type InternalProps$1 = {
|
|
170
|
+
text: string | null;
|
|
171
|
+
icon: string | null;
|
|
172
|
+
mode: ButtonMode;
|
|
173
|
+
error: string | null;
|
|
174
|
+
onClick?: Events$2['click'] | null;
|
|
175
|
+
};
|
|
176
|
+
type Props$1 = Partial<InternalProps$1>;
|
|
177
|
+
declare class Button extends Base<proto.CoreNamespace, proto.CoreComponent, InternalProps$1> implements Listenable<Events$2> {
|
|
178
|
+
/** @hidden */
|
|
179
|
+
private readonly events;
|
|
180
|
+
constructor(props?: Props$1);
|
|
181
|
+
addListener: <T extends "click">(type: T, listener: Events$2[T]) => void;
|
|
182
|
+
removeListener: <T extends "click">(type: T, listener: Events$2[T]) => void;
|
|
183
|
+
setText: (text: string | null) => this;
|
|
184
|
+
setIcon: (icon: string | undefined | null) => this;
|
|
185
|
+
setMode: (mode: ButtonMode) => this;
|
|
186
|
+
/** @hidden */
|
|
187
|
+
getProtoInfo: (idMap: IDMap) => proto.ButtonComponent;
|
|
188
|
+
/** @hidden */
|
|
189
|
+
handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type Label = (proto.GroupComponent['labels'] & Array<unknown>)[number];
|
|
193
|
+
type GroupOptions = {
|
|
194
|
+
editableTitle?: boolean;
|
|
195
|
+
defaultCollapsibleState?: proto.GroupComponent['defaultCollapsibleState'];
|
|
196
|
+
};
|
|
197
|
+
type Events$1 = {
|
|
198
|
+
'title-changed': (title: string, connection: ToolkitConnection) => void;
|
|
199
|
+
};
|
|
200
|
+
type InternalProps = GroupComponentStyle & GroupOptions & {
|
|
201
|
+
title: string | null;
|
|
202
|
+
labels: Label[] | null;
|
|
203
|
+
onTitleChanged?: Events$1['title-changed'];
|
|
204
|
+
};
|
|
205
|
+
type Props = Partial<InternalProps>;
|
|
206
|
+
declare class GroupHeader extends BaseParent<proto.CoreNamespace, proto.CoreComponent, Record<never, never>> {
|
|
207
|
+
validateChildren: () => void;
|
|
208
|
+
/** @hidden */
|
|
209
|
+
getProtoInfo: (idMap: IDMap) => proto.GroupHeaderComponent;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A collection of components, grouped in either a row or column. Can contain
|
|
213
|
+
* further groups as children to organize components however you wish, and have
|
|
214
|
+
* a number of styling options (such as removing the border).
|
|
215
|
+
*
|
|
216
|
+
* 
|
|
217
|
+
*/
|
|
218
|
+
declare class Group extends BaseParent<proto.CoreNamespace, proto.GroupComponent, Props> implements Listenable<Events$1> {
|
|
219
|
+
/** @hidden */
|
|
220
|
+
private readonly events;
|
|
221
|
+
constructor(props?: Props);
|
|
222
|
+
addListener: <T extends "title-changed">(type: T, listener: Events$1[T]) => void;
|
|
223
|
+
removeListener: <T extends "title-changed">(type: T, listener: Events$1[T]) => void;
|
|
224
|
+
validateChildren: () => void;
|
|
225
|
+
setOptions: (options: GroupOptions) => void;
|
|
226
|
+
setTitle: (title: string) => void;
|
|
227
|
+
addLabel: (label: Label) => void;
|
|
228
|
+
setLabels: (labels: Label[]) => void;
|
|
229
|
+
addHeaderChild: <C extends Button>(child: C) => C;
|
|
230
|
+
removeHeaderChild: (child: Button) => void;
|
|
231
|
+
removeAllHeaderChildren: () => void;
|
|
232
|
+
/** @hidden */
|
|
233
|
+
getProtoInfo: (idMap: IDMap) => proto.GroupComponent;
|
|
234
|
+
/** @hidden */
|
|
235
|
+
handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
type ToolkitConnection = {
|
|
239
|
+
uuid: string;
|
|
240
|
+
};
|
|
241
|
+
type Events = {
|
|
242
|
+
'new-connection': (connection: ToolkitConnection) => void;
|
|
243
|
+
'closed-connection': (connection: ToolkitConnection) => void;
|
|
244
|
+
};
|
|
245
|
+
declare class Toolkit implements Parent, Listenable<Events> {
|
|
246
|
+
private readonly options;
|
|
247
|
+
/**
|
|
248
|
+
* Mapping from components to unique IDs that identify them
|
|
249
|
+
*/
|
|
250
|
+
private readonly componentIDMap;
|
|
251
|
+
private readonly connections;
|
|
252
|
+
private rootGroup;
|
|
253
|
+
/** @hidden */
|
|
254
|
+
private readonly events;
|
|
255
|
+
constructor(options?: Partial<ToolkitOptions>);
|
|
256
|
+
addListener: <T extends keyof Events>(type: T, listener: Events[T]) => void;
|
|
257
|
+
removeListener: <T extends keyof Events>(type: T, listener: Events[T]) => void;
|
|
258
|
+
start: (opts: InitializationOptions) => void;
|
|
259
|
+
setRoot: (group: Group) => void;
|
|
260
|
+
log(): _arcanejs_protocol_logging.Logger | null;
|
|
261
|
+
getConnections: () => ToolkitConnection[];
|
|
262
|
+
updateTree: _.DebouncedFuncLeading<() => void>;
|
|
263
|
+
removeChild: (component: AnyComponent) => void;
|
|
264
|
+
private onNewConnection;
|
|
265
|
+
private onClosedConnection;
|
|
266
|
+
private onMessage;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type AnyComponent as A, Button as B, EventEmitter as E, Group as G, type InternalProps$1 as I, type Listenable as L, type Parent as P, Toolkit as T, type ToolkitConnection as a, type ToolkitOptions as b, GroupHeader as c, Base as d, BaseParent as e, type Events$2 as f, type ButtonMode as g, type Props$1 as h, type Events$1 as i, type InternalProps as j, type Props as k };
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as _arcanejs_protocol_logging from '@arcanejs/protocol/logging';
|
|
2
|
+
import { Logger } from '@arcanejs/protocol/logging';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import * as http from 'http';
|
|
5
|
+
import { Application } from 'express';
|
|
6
|
+
import { WebSocket } from 'ws';
|
|
7
|
+
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage } from '@arcanejs/protocol';
|
|
8
|
+
import * as proto from '@arcanejs/protocol/core';
|
|
9
|
+
import { GroupComponentStyle } from '@arcanejs/protocol/styles';
|
|
10
|
+
import { I as IDMap } from './id-map-DxQ3_gyA.mjs';
|
|
11
|
+
|
|
12
|
+
interface Connection {
|
|
13
|
+
sendMessage(msg: ServerMessage): void;
|
|
14
|
+
}
|
|
15
|
+
declare class Server {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly onNewConnection;
|
|
18
|
+
private readonly onClosedConnection;
|
|
19
|
+
private readonly onMessage;
|
|
20
|
+
private readonly log?;
|
|
21
|
+
private readonly staticFiles;
|
|
22
|
+
private readonly entrypointFilename;
|
|
23
|
+
private title;
|
|
24
|
+
constructor(options: ToolkitOptions, onNewConnection: (connection: Connection) => void, onClosedConnection: (connection: Connection) => void, onMessage: (connection: Connection, message: ClientMessage) => void, log?: Logger | undefined);
|
|
25
|
+
handleHttpRequest: (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
26
|
+
private sendStaticFile;
|
|
27
|
+
handleWsConnection: <S extends WebSocket>(ws: S) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ToolkitOptions {
|
|
31
|
+
/**
|
|
32
|
+
* What window title should the toolkit be initialized with?
|
|
33
|
+
*/
|
|
34
|
+
title?: string;
|
|
35
|
+
/**
|
|
36
|
+
* What path should be used to serve the light desk.
|
|
37
|
+
*
|
|
38
|
+
* This is important if a express server will be used that serves other paths.
|
|
39
|
+
*/
|
|
40
|
+
path: string;
|
|
41
|
+
/**
|
|
42
|
+
* An optional object that can be used to output log events,
|
|
43
|
+
* we recommend using `pino` for this,
|
|
44
|
+
* as log levels etc... can be controlled.
|
|
45
|
+
*
|
|
46
|
+
* You can also always use `console` for logging,
|
|
47
|
+
* but this will be quite verbose.
|
|
48
|
+
*/
|
|
49
|
+
log?: Logger;
|
|
50
|
+
/**
|
|
51
|
+
* The entrypoint file that should be used to serve the light desk.
|
|
52
|
+
*
|
|
53
|
+
* This is only needed if you have defined custom extensions,
|
|
54
|
+
* and need to load custom frontend code that includes your extensions.
|
|
55
|
+
*
|
|
56
|
+
* This will allow access to both the js file and the `.map.js` file,
|
|
57
|
+
* that matches this name.
|
|
58
|
+
*/
|
|
59
|
+
entrypointJsFile?: string;
|
|
60
|
+
/**
|
|
61
|
+
* If it's not possible to automatically resolve and import the
|
|
62
|
+
* material-symbols package in node_modules
|
|
63
|
+
* (for example when bundling an electron app),
|
|
64
|
+
* you can provide the path to the material-symbols-outlined.woff2 file here.
|
|
65
|
+
*/
|
|
66
|
+
materialIconsFontFile?: string;
|
|
67
|
+
}
|
|
68
|
+
type InitializationOptions =
|
|
69
|
+
/** automatically start a simple */
|
|
70
|
+
{
|
|
71
|
+
mode: 'automatic';
|
|
72
|
+
port: number;
|
|
73
|
+
/**
|
|
74
|
+
* Optional callback that is called when the server is ready,
|
|
75
|
+
* with the url that the server is running on.
|
|
76
|
+
*/
|
|
77
|
+
onReady?: (url: string) => void;
|
|
78
|
+
}
|
|
79
|
+
/** Create a websocket server that attaches to an existing express and http server */
|
|
80
|
+
| {
|
|
81
|
+
mode: 'express';
|
|
82
|
+
express: Application;
|
|
83
|
+
server: http.Server;
|
|
84
|
+
}
|
|
85
|
+
/** Create a websocket server that attaches to an existing express and http server */
|
|
86
|
+
| {
|
|
87
|
+
mode: 'manual';
|
|
88
|
+
setup: (server: Server) => void;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace>, Props> {
|
|
92
|
+
/** @hidden */
|
|
93
|
+
private parent;
|
|
94
|
+
/** @hidden */
|
|
95
|
+
private readonly defaultProps;
|
|
96
|
+
/** @hidden */
|
|
97
|
+
private _props;
|
|
98
|
+
/** @hidden */
|
|
99
|
+
private _onPropsUpdated;
|
|
100
|
+
constructor(defaultProps: Props, props?: Partial<Props>, options?: {
|
|
101
|
+
onPropsUpdated?: (oldProps: Props) => void;
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Call if
|
|
105
|
+
*/
|
|
106
|
+
triggerInitialPropsUpdate: () => void;
|
|
107
|
+
log: () => Logger | null;
|
|
108
|
+
get props(): Props;
|
|
109
|
+
set props(props: Partial<Props>);
|
|
110
|
+
setProps: (props: Partial<Props>) => void;
|
|
111
|
+
updateProps: (updates: Partial<Props>) => void;
|
|
112
|
+
/** @hidden */
|
|
113
|
+
setParent(parent: Parent | null): void;
|
|
114
|
+
/** @hidden */
|
|
115
|
+
updateTree(): void;
|
|
116
|
+
/** @hidden */
|
|
117
|
+
abstract getProtoInfo(idMap: IDMap): Proto;
|
|
118
|
+
/** @hidden */
|
|
119
|
+
handleMessage(_message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
120
|
+
routeMessage(_idMap: IDMap, _message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
121
|
+
}
|
|
122
|
+
type AnyComponent = Base<string, BaseComponentProto<string>, any>;
|
|
123
|
+
/** @hidden */
|
|
124
|
+
interface Parent {
|
|
125
|
+
updateTree(): void;
|
|
126
|
+
removeChild(component: AnyComponent): void;
|
|
127
|
+
log(): Logger | null;
|
|
128
|
+
}
|
|
129
|
+
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace>, T> extends Base<Namespace, Proto, T> implements Parent {
|
|
130
|
+
/** @hidden */
|
|
131
|
+
private children;
|
|
132
|
+
abstract validateChildren(children: AnyComponent[]): void;
|
|
133
|
+
appendChildren: <CS extends AnyComponent[]>(...children: CS) => CS;
|
|
134
|
+
appendChild: <C extends AnyComponent>(child: C) => C;
|
|
135
|
+
removeChild: (component: AnyComponent) => void;
|
|
136
|
+
removeAllChildren: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Return all children components that messages need to be routed to
|
|
139
|
+
*/
|
|
140
|
+
getChildren: () => readonly AnyComponent[];
|
|
141
|
+
/**
|
|
142
|
+
* TODO: we can do this better, right now it broadcasts the message to all
|
|
143
|
+
* components of the tree
|
|
144
|
+
*
|
|
145
|
+
* @hidden
|
|
146
|
+
*/
|
|
147
|
+
routeMessage(idMap: IDMap, message: AnyClientComponentMessage, connection: ToolkitConnection): void;
|
|
148
|
+
insertBefore(child: AnyComponent, beforeChild: AnyComponent): void;
|
|
149
|
+
}
|
|
150
|
+
interface Listenable<Map extends Record<string, (...args: any[]) => void>> {
|
|
151
|
+
addListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
152
|
+
removeListener<T extends keyof Map>(type: T, listener: Map[T]): void;
|
|
153
|
+
}
|
|
154
|
+
declare class EventEmitter<Map extends Record<string, (...args: any[]) => void>> implements Listenable<Map> {
|
|
155
|
+
private readonly listeners;
|
|
156
|
+
addListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
157
|
+
removeListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
158
|
+
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<unknown>;
|
|
159
|
+
/**
|
|
160
|
+
* Process prop changes to update listeners
|
|
161
|
+
*/
|
|
162
|
+
processPropChanges: <Mapping extends Record<string, keyof Map>, Props extends { [key in keyof Mapping]?: Map[Mapping[key]] | null | undefined; }>(mapping: Mapping, oldProps: Props, newProps: Props) => void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type Events$2 = {
|
|
166
|
+
click: (connection: ToolkitConnection) => void | Promise<void>;
|
|
167
|
+
};
|
|
168
|
+
type ButtonMode = 'normal' | 'pressed';
|
|
169
|
+
type InternalProps$1 = {
|
|
170
|
+
text: string | null;
|
|
171
|
+
icon: string | null;
|
|
172
|
+
mode: ButtonMode;
|
|
173
|
+
error: string | null;
|
|
174
|
+
onClick?: Events$2['click'] | null;
|
|
175
|
+
};
|
|
176
|
+
type Props$1 = Partial<InternalProps$1>;
|
|
177
|
+
declare class Button extends Base<proto.CoreNamespace, proto.CoreComponent, InternalProps$1> implements Listenable<Events$2> {
|
|
178
|
+
/** @hidden */
|
|
179
|
+
private readonly events;
|
|
180
|
+
constructor(props?: Props$1);
|
|
181
|
+
addListener: <T extends "click">(type: T, listener: Events$2[T]) => void;
|
|
182
|
+
removeListener: <T extends "click">(type: T, listener: Events$2[T]) => void;
|
|
183
|
+
setText: (text: string | null) => this;
|
|
184
|
+
setIcon: (icon: string | undefined | null) => this;
|
|
185
|
+
setMode: (mode: ButtonMode) => this;
|
|
186
|
+
/** @hidden */
|
|
187
|
+
getProtoInfo: (idMap: IDMap) => proto.ButtonComponent;
|
|
188
|
+
/** @hidden */
|
|
189
|
+
handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type Label = (proto.GroupComponent['labels'] & Array<unknown>)[number];
|
|
193
|
+
type GroupOptions = {
|
|
194
|
+
editableTitle?: boolean;
|
|
195
|
+
defaultCollapsibleState?: proto.GroupComponent['defaultCollapsibleState'];
|
|
196
|
+
};
|
|
197
|
+
type Events$1 = {
|
|
198
|
+
'title-changed': (title: string, connection: ToolkitConnection) => void;
|
|
199
|
+
};
|
|
200
|
+
type InternalProps = GroupComponentStyle & GroupOptions & {
|
|
201
|
+
title: string | null;
|
|
202
|
+
labels: Label[] | null;
|
|
203
|
+
onTitleChanged?: Events$1['title-changed'];
|
|
204
|
+
};
|
|
205
|
+
type Props = Partial<InternalProps>;
|
|
206
|
+
declare class GroupHeader extends BaseParent<proto.CoreNamespace, proto.CoreComponent, Record<never, never>> {
|
|
207
|
+
validateChildren: () => void;
|
|
208
|
+
/** @hidden */
|
|
209
|
+
getProtoInfo: (idMap: IDMap) => proto.GroupHeaderComponent;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A collection of components, grouped in either a row or column. Can contain
|
|
213
|
+
* further groups as children to organize components however you wish, and have
|
|
214
|
+
* a number of styling options (such as removing the border).
|
|
215
|
+
*
|
|
216
|
+
* 
|
|
217
|
+
*/
|
|
218
|
+
declare class Group extends BaseParent<proto.CoreNamespace, proto.GroupComponent, Props> implements Listenable<Events$1> {
|
|
219
|
+
/** @hidden */
|
|
220
|
+
private readonly events;
|
|
221
|
+
constructor(props?: Props);
|
|
222
|
+
addListener: <T extends "title-changed">(type: T, listener: Events$1[T]) => void;
|
|
223
|
+
removeListener: <T extends "title-changed">(type: T, listener: Events$1[T]) => void;
|
|
224
|
+
validateChildren: () => void;
|
|
225
|
+
setOptions: (options: GroupOptions) => void;
|
|
226
|
+
setTitle: (title: string) => void;
|
|
227
|
+
addLabel: (label: Label) => void;
|
|
228
|
+
setLabels: (labels: Label[]) => void;
|
|
229
|
+
addHeaderChild: <C extends Button>(child: C) => C;
|
|
230
|
+
removeHeaderChild: (child: Button) => void;
|
|
231
|
+
removeAllHeaderChildren: () => void;
|
|
232
|
+
/** @hidden */
|
|
233
|
+
getProtoInfo: (idMap: IDMap) => proto.GroupComponent;
|
|
234
|
+
/** @hidden */
|
|
235
|
+
handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
type ToolkitConnection = {
|
|
239
|
+
uuid: string;
|
|
240
|
+
};
|
|
241
|
+
type Events = {
|
|
242
|
+
'new-connection': (connection: ToolkitConnection) => void;
|
|
243
|
+
'closed-connection': (connection: ToolkitConnection) => void;
|
|
244
|
+
};
|
|
245
|
+
declare class Toolkit implements Parent, Listenable<Events> {
|
|
246
|
+
private readonly options;
|
|
247
|
+
/**
|
|
248
|
+
* Mapping from components to unique IDs that identify them
|
|
249
|
+
*/
|
|
250
|
+
private readonly componentIDMap;
|
|
251
|
+
private readonly connections;
|
|
252
|
+
private rootGroup;
|
|
253
|
+
/** @hidden */
|
|
254
|
+
private readonly events;
|
|
255
|
+
constructor(options?: Partial<ToolkitOptions>);
|
|
256
|
+
addListener: <T extends keyof Events>(type: T, listener: Events[T]) => void;
|
|
257
|
+
removeListener: <T extends keyof Events>(type: T, listener: Events[T]) => void;
|
|
258
|
+
start: (opts: InitializationOptions) => void;
|
|
259
|
+
setRoot: (group: Group) => void;
|
|
260
|
+
log(): _arcanejs_protocol_logging.Logger | null;
|
|
261
|
+
getConnections: () => ToolkitConnection[];
|
|
262
|
+
updateTree: _.DebouncedFuncLeading<() => void>;
|
|
263
|
+
removeChild: (component: AnyComponent) => void;
|
|
264
|
+
private onNewConnection;
|
|
265
|
+
private onClosedConnection;
|
|
266
|
+
private onMessage;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type AnyComponent as A, Button as B, EventEmitter as E, Group as G, type InternalProps$1 as I, type Listenable as L, type Parent as P, Toolkit as T, type ToolkitConnection as a, type ToolkitOptions as b, GroupHeader as c, Base as d, BaseParent as e, type Events$2 as f, type ButtonMode as g, type Props$1 as h, type Events$1 as i, type InternalProps as j, type Props as k };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcanejs/toolkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Build web-accessible control interfaces for your long-running Node.js processes",
|
|
6
6
|
"keywords": [
|
|
@@ -115,23 +115,24 @@
|
|
|
115
115
|
"tsup": "^8.1.0",
|
|
116
116
|
"typescript": "^5.3.3",
|
|
117
117
|
"@arcanejs/eslint-config": "^0.0.0",
|
|
118
|
-
"@arcanejs/
|
|
119
|
-
"@arcanejs/
|
|
118
|
+
"@arcanejs/toolkit-frontend": "^0.4.0",
|
|
119
|
+
"@arcanejs/typescript-config": "^0.0.0"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
122
|
"escape-html": "^1.0.3",
|
|
123
123
|
"express": "^4.21.1",
|
|
124
124
|
"lodash": "^4.17.21",
|
|
125
125
|
"material-symbols": "^0.25.0",
|
|
126
|
+
"uuid": "^11.0.3",
|
|
126
127
|
"ws": "^8.18.0",
|
|
127
128
|
"@arcanejs/diff": "^0.5.1",
|
|
128
|
-
"@arcanejs/protocol": "^0.
|
|
129
|
+
"@arcanejs/protocol": "^0.5.0"
|
|
129
130
|
},
|
|
130
131
|
"peerDependencies": {
|
|
131
132
|
"react": "^18",
|
|
132
133
|
"react-dom": "18.3.1",
|
|
133
134
|
"styled-components": "^6.1.13",
|
|
134
|
-
"@arcanejs/toolkit-frontend": "^0.
|
|
135
|
+
"@arcanejs/toolkit-frontend": "^0.4.0"
|
|
135
136
|
},
|
|
136
137
|
"peerDependenciesMeta": {
|
|
137
138
|
"@arcanejs/toolkit-frontend": {
|