@arcanejs/toolkit 3.1.1 → 4.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/README.md +1 -1
- package/dist/backend/components/base.d.mts +1 -1
- package/dist/backend/components/base.d.ts +1 -1
- package/dist/backend/components/base.js +2 -2
- package/dist/backend/components/base.mjs +1 -1
- package/dist/backend/components/button.d.mts +1 -1
- package/dist/backend/components/button.d.ts +1 -1
- package/dist/backend/components/button.js +3 -3
- package/dist/backend/components/button.mjs +2 -2
- package/dist/backend/components/group.d.mts +1 -1
- package/dist/backend/components/group.d.ts +1 -1
- package/dist/backend/components/group.js +3 -3
- package/dist/backend/components/group.mjs +2 -2
- package/dist/backend/components/label.d.mts +1 -1
- package/dist/backend/components/label.d.ts +1 -1
- package/dist/backend/components/label.js +3 -3
- package/dist/backend/components/label.mjs +2 -2
- package/dist/backend/components/rect.d.mts +1 -1
- package/dist/backend/components/rect.d.ts +1 -1
- package/dist/backend/components/rect.js +3 -3
- package/dist/backend/components/rect.mjs +2 -2
- package/dist/backend/components/slider-button.d.mts +1 -1
- package/dist/backend/components/slider-button.d.ts +1 -1
- 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 +1 -1
- package/dist/backend/components/switch.d.ts +1 -1
- package/dist/backend/components/switch.js +3 -3
- package/dist/backend/components/switch.mjs +2 -2
- package/dist/backend/components/tabs.d.mts +1 -1
- package/dist/backend/components/tabs.d.ts +1 -1
- package/dist/backend/components/tabs.js +3 -3
- package/dist/backend/components/tabs.mjs +2 -2
- package/dist/backend/components/text-input.d.mts +1 -1
- package/dist/backend/components/text-input.d.ts +1 -1
- 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 +1 -1
- package/dist/backend/components/timeline.d.ts +1 -1
- package/dist/backend/components/timeline.js +3 -3
- package/dist/backend/components/timeline.mjs +2 -2
- package/dist/{chunk-DRQVYGTI.js → chunk-3GTEUTFT.js} +2 -2
- package/dist/{chunk-K37TZB75.mjs → chunk-3TXBS2UN.mjs} +1 -1
- package/dist/{chunk-DG75CS7F.js → chunk-4OCRZD4F.js} +7 -16
- package/dist/{chunk-VEZGD2PG.js → chunk-53EOA4UE.js} +3 -3
- package/dist/{chunk-N6IHYBZH.mjs → chunk-6ELB27LK.mjs} +1 -1
- package/dist/{chunk-6CWEURJP.js → chunk-6QWYIJLM.js} +2 -2
- package/dist/{chunk-O5ZW6JYG.js → chunk-7JIC2XBC.js} +4 -4
- package/dist/{chunk-5D7OSUZ6.mjs → chunk-E6FGU7DA.mjs} +1 -1
- package/dist/{chunk-RYR5I5FT.mjs → chunk-GONHNB6V.mjs} +33 -0
- package/dist/{chunk-4OZ22IQU.js → chunk-HTCWMJUA.js} +3 -3
- package/dist/{chunk-7TTY7CBH.mjs → chunk-KMEDXCBI.mjs} +1 -1
- package/dist/{chunk-W42AOMM6.mjs → chunk-LK6MGXYC.mjs} +5 -14
- package/dist/{chunk-CME7HZZK.js → chunk-NL3W4M7J.js} +3 -3
- package/dist/{chunk-NEQRLPXK.mjs → chunk-PG5EAV5X.mjs} +1 -1
- package/dist/{chunk-7OX2FB6C.js → chunk-QAH2OSHR.js} +2 -2
- package/dist/{chunk-JFZXSCGK.mjs → chunk-QB2WPBWV.mjs} +1 -1
- package/dist/{chunk-GMDJYFHD.js → chunk-U6FSQBQ3.js} +3 -3
- package/dist/{chunk-CUZSHFDP.mjs → chunk-UQWCTVMC.mjs} +1 -1
- package/dist/{chunk-YBBUC3QC.mjs → chunk-WDB3IMOP.mjs} +1 -1
- package/dist/{chunk-SGACFY53.js → chunk-WN3GXVUE.js} +35 -2
- package/dist/frontend/entrypoint.js +84 -31
- package/dist/frontend/entrypoint.js.map +3 -3
- package/dist/frontend/index.js +62 -19
- package/dist/frontend/index.mjs +62 -19
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +47 -14
- package/dist/index.mjs +43 -10
- package/dist/{toolkit-2w2SWHlT.d.ts → toolkit-C37sQAkD.d.ts} +23 -7
- package/dist/{toolkit-DB8G2TaA.d.mts → toolkit-CQMnQMOF.d.mts} +23 -7
- package/package.json +5 -5
package/dist/frontend/index.js
CHANGED
|
@@ -251,6 +251,10 @@ var Stage = ({ className, renderers }) => {
|
|
|
251
251
|
);
|
|
252
252
|
const socket = _react.useRef.call(void 0, null);
|
|
253
253
|
const uuid = _react.useRef.call(void 0, null);
|
|
254
|
+
const calls = _react.useRef.call(void 0, {
|
|
255
|
+
nextId: 1,
|
|
256
|
+
calls: /* @__PURE__ */ new Map()
|
|
257
|
+
});
|
|
254
258
|
const preparedRenderers = _react.useMemo.call(void 0, () => {
|
|
255
259
|
const prepared = {};
|
|
256
260
|
for (const renderer of renderers) {
|
|
@@ -268,10 +272,36 @@ var Stage = ({ className, renderers }) => {
|
|
|
268
272
|
},
|
|
269
273
|
[preparedRenderers]
|
|
270
274
|
);
|
|
271
|
-
_react.
|
|
272
|
-
|
|
275
|
+
const handleMessage = _react.useCallback.call(void 0, (msg) => {
|
|
276
|
+
switch (msg.type) {
|
|
277
|
+
case "metadata":
|
|
278
|
+
uuid.current = msg.connectionUuid;
|
|
279
|
+
return;
|
|
280
|
+
case "tree-full":
|
|
281
|
+
setRoot(msg.root);
|
|
282
|
+
return;
|
|
283
|
+
case "tree-diff":
|
|
284
|
+
setRoot((prevRoot) => _diff.patchJson.call(void 0, prevRoot, msg.diff));
|
|
285
|
+
return;
|
|
286
|
+
case "call-response": {
|
|
287
|
+
const call2 = calls.current.calls.get(msg.requestId);
|
|
288
|
+
if (call2) {
|
|
289
|
+
calls.current.calls.delete(msg.requestId);
|
|
290
|
+
if (msg.success) {
|
|
291
|
+
call2.resolve(msg.returnValue);
|
|
292
|
+
} else {
|
|
293
|
+
call2.reject(msg.errorMessage);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
console.warn(
|
|
297
|
+
`Received response for unknown call request ID ${msg.requestId}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
273
303
|
}, []);
|
|
274
|
-
const initializeWebsocket = async () => {
|
|
304
|
+
const initializeWebsocket = _react.useCallback.call(void 0, async () => {
|
|
275
305
|
console.log("initializing websocket");
|
|
276
306
|
const wsUrl = new URL(window.location.href);
|
|
277
307
|
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
@@ -295,29 +325,42 @@ var Stage = ({ className, renderers }) => {
|
|
|
295
325
|
};
|
|
296
326
|
});
|
|
297
327
|
return ws;
|
|
298
|
-
};
|
|
299
|
-
const sendMessage = async (msg) => {
|
|
328
|
+
}, []);
|
|
329
|
+
const sendMessage = _react.useCallback.call(void 0, async (msg) => {
|
|
300
330
|
(await (socket.current || initializeWebsocket())).send(JSON.stringify(msg));
|
|
301
|
-
};
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
331
|
+
}, []);
|
|
332
|
+
const call = _react.useCallback.call(void 0,
|
|
333
|
+
async (msg) => {
|
|
334
|
+
const requestId = calls.current.nextId++;
|
|
335
|
+
const sendMsg = {
|
|
336
|
+
...msg,
|
|
337
|
+
requestId
|
|
338
|
+
};
|
|
339
|
+
const promise = new Promise(
|
|
340
|
+
(resolve, reject) => {
|
|
341
|
+
calls.current.calls.set(requestId, {
|
|
342
|
+
resolve,
|
|
343
|
+
reject
|
|
344
|
+
});
|
|
345
|
+
(socket.current || initializeWebsocket()).then(
|
|
346
|
+
(s) => s.send(JSON.stringify(sendMsg))
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
return promise;
|
|
351
|
+
},
|
|
352
|
+
[]
|
|
353
|
+
);
|
|
354
|
+
_react.useEffect.call(void 0, () => {
|
|
355
|
+
initializeWebsocket();
|
|
356
|
+
}, [initializeWebsocket]);
|
|
315
357
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
316
358
|
_toolkitfrontend.StageContext.Provider,
|
|
317
359
|
{
|
|
318
360
|
value: {
|
|
319
361
|
sendMessage,
|
|
320
362
|
renderComponent,
|
|
363
|
+
call,
|
|
321
364
|
get connectionUuid() {
|
|
322
365
|
if (!uuid.current) {
|
|
323
366
|
throw new Error("Unexpected missing UUID");
|
package/dist/frontend/index.mjs
CHANGED
|
@@ -251,6 +251,10 @@ var Stage = ({ className, renderers }) => {
|
|
|
251
251
|
);
|
|
252
252
|
const socket = useRef(null);
|
|
253
253
|
const uuid = useRef(null);
|
|
254
|
+
const calls = useRef({
|
|
255
|
+
nextId: 1,
|
|
256
|
+
calls: /* @__PURE__ */ new Map()
|
|
257
|
+
});
|
|
254
258
|
const preparedRenderers = useMemo(() => {
|
|
255
259
|
const prepared = {};
|
|
256
260
|
for (const renderer of renderers) {
|
|
@@ -268,10 +272,36 @@ var Stage = ({ className, renderers }) => {
|
|
|
268
272
|
},
|
|
269
273
|
[preparedRenderers]
|
|
270
274
|
);
|
|
271
|
-
|
|
272
|
-
|
|
275
|
+
const handleMessage = useCallback((msg) => {
|
|
276
|
+
switch (msg.type) {
|
|
277
|
+
case "metadata":
|
|
278
|
+
uuid.current = msg.connectionUuid;
|
|
279
|
+
return;
|
|
280
|
+
case "tree-full":
|
|
281
|
+
setRoot(msg.root);
|
|
282
|
+
return;
|
|
283
|
+
case "tree-diff":
|
|
284
|
+
setRoot((prevRoot) => patchJson(prevRoot, msg.diff));
|
|
285
|
+
return;
|
|
286
|
+
case "call-response": {
|
|
287
|
+
const call2 = calls.current.calls.get(msg.requestId);
|
|
288
|
+
if (call2) {
|
|
289
|
+
calls.current.calls.delete(msg.requestId);
|
|
290
|
+
if (msg.success) {
|
|
291
|
+
call2.resolve(msg.returnValue);
|
|
292
|
+
} else {
|
|
293
|
+
call2.reject(msg.errorMessage);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
console.warn(
|
|
297
|
+
`Received response for unknown call request ID ${msg.requestId}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
273
303
|
}, []);
|
|
274
|
-
const initializeWebsocket = async () => {
|
|
304
|
+
const initializeWebsocket = useCallback(async () => {
|
|
275
305
|
console.log("initializing websocket");
|
|
276
306
|
const wsUrl = new URL(window.location.href);
|
|
277
307
|
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
@@ -295,29 +325,42 @@ var Stage = ({ className, renderers }) => {
|
|
|
295
325
|
};
|
|
296
326
|
});
|
|
297
327
|
return ws;
|
|
298
|
-
};
|
|
299
|
-
const sendMessage = async (msg) => {
|
|
328
|
+
}, []);
|
|
329
|
+
const sendMessage = useCallback(async (msg) => {
|
|
300
330
|
(await (socket.current || initializeWebsocket())).send(JSON.stringify(msg));
|
|
301
|
-
};
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
331
|
+
}, []);
|
|
332
|
+
const call = useCallback(
|
|
333
|
+
async (msg) => {
|
|
334
|
+
const requestId = calls.current.nextId++;
|
|
335
|
+
const sendMsg = {
|
|
336
|
+
...msg,
|
|
337
|
+
requestId
|
|
338
|
+
};
|
|
339
|
+
const promise = new Promise(
|
|
340
|
+
(resolve, reject) => {
|
|
341
|
+
calls.current.calls.set(requestId, {
|
|
342
|
+
resolve,
|
|
343
|
+
reject
|
|
344
|
+
});
|
|
345
|
+
(socket.current || initializeWebsocket()).then(
|
|
346
|
+
(s) => s.send(JSON.stringify(sendMsg))
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
return promise;
|
|
351
|
+
},
|
|
352
|
+
[]
|
|
353
|
+
);
|
|
354
|
+
useEffect2(() => {
|
|
355
|
+
initializeWebsocket();
|
|
356
|
+
}, [initializeWebsocket]);
|
|
315
357
|
return /* @__PURE__ */ jsx2(
|
|
316
358
|
StageContext.Provider,
|
|
317
359
|
{
|
|
318
360
|
value: {
|
|
319
361
|
sendMessage,
|
|
320
362
|
renderComponent,
|
|
363
|
+
call,
|
|
321
364
|
get connectionUuid() {
|
|
322
365
|
if (!uuid.current) {
|
|
323
366
|
throw new Error("Unexpected missing UUID");
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyComponent, B as Button, G as Group, c as GroupHeader, T as Toolkit, a as ToolkitConnection, b as ToolkitOptions } from './toolkit-
|
|
1
|
+
export { A as AnyComponent, B as Button, G as Group, c as GroupHeader, T as Toolkit, a as ToolkitConnection, b as ToolkitOptions } from './toolkit-CQMnQMOF.mjs';
|
|
2
2
|
export { Label } from './backend/components/label.mjs';
|
|
3
3
|
export { Rect } from './backend/components/rect.mjs';
|
|
4
4
|
export { SliderButton } from './backend/components/slider-button.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyComponent, B as Button, G as Group, c as GroupHeader, T as Toolkit, a as ToolkitConnection, b as ToolkitOptions } from './toolkit-
|
|
1
|
+
export { A as AnyComponent, B as Button, G as Group, c as GroupHeader, T as Toolkit, a as ToolkitConnection, b as ToolkitOptions } from './toolkit-C37sQAkD.js';
|
|
2
2
|
export { Label } from './backend/components/label.js';
|
|
3
3
|
export { Rect } from './backend/components/rect.js';
|
|
4
4
|
export { SliderButton } from './backend/components/slider-button.js';
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkU6FSQBQ3js = require('./chunk-U6FSQBQ3.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkHTCWMJUAjs = require('./chunk-HTCWMJUA.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk6QWYIJLMjs = require('./chunk-6QWYIJLM.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkEABM5X65js = require('./chunk-EABM5X65.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunk4OCRZD4Fjs = require('./chunk-4OCRZD4F.js');
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _chunk7JIC2XBCjs = require('./chunk-7JIC2XBC.js');
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var _chunk3GTEUTFTjs = require('./chunk-3GTEUTFT.js');
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _chunkQAH2OSHRjs = require('./chunk-QAH2OSHR.js');
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
var
|
|
29
|
+
var _chunkNL3W4M7Jjs = require('./chunk-NL3W4M7J.js');
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _chunk53EOA4UEjs = require('./chunk-53EOA4UE.js');
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
var
|
|
35
|
+
var _chunkWN3GXVUEjs = require('./chunk-WN3GXVUE.js');
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
|
|
@@ -189,8 +189,8 @@ var Toolkit = (_class2 = class {
|
|
|
189
189
|
__init5() {this.connections = /* @__PURE__ */ new Map()}
|
|
190
190
|
__init6() {this.rootGroup = null}
|
|
191
191
|
/** @hidden */
|
|
192
|
-
__init7() {this.events = new (0,
|
|
193
|
-
constructor(options = {}) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);_class2.prototype.__init17.call(this);
|
|
192
|
+
__init7() {this.events = new (0, _chunkWN3GXVUEjs.EventEmitter)()}
|
|
193
|
+
constructor(options = {}) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);_class2.prototype.__init17.call(this);_class2.prototype.__init18.call(this);
|
|
194
194
|
this.options = {
|
|
195
195
|
...DEFAULT_LIGHT_DESK_OPTIONS,
|
|
196
196
|
...options
|
|
@@ -299,7 +299,37 @@ var Toolkit = (_class2 = class {
|
|
|
299
299
|
this.events.emit("closed-connection", con.publicConnection);
|
|
300
300
|
}
|
|
301
301
|
}}
|
|
302
|
-
__init17() {this.
|
|
302
|
+
__init17() {this.handleCall = async (connection, publicConnection, call) => {
|
|
303
|
+
try {
|
|
304
|
+
const rg = this.rootGroup;
|
|
305
|
+
if (rg) {
|
|
306
|
+
const returnValue = await new Promise(
|
|
307
|
+
(resolve2, reject) => rg.routeCall(this.componentIDMap, call, publicConnection, {
|
|
308
|
+
resolve: resolve2,
|
|
309
|
+
reject
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
connection.sendMessage({
|
|
313
|
+
type: "call-response",
|
|
314
|
+
namespace: call.namespace,
|
|
315
|
+
requestId: call.requestId,
|
|
316
|
+
success: true,
|
|
317
|
+
returnValue
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
throw new Error("No root group set");
|
|
321
|
+
}
|
|
322
|
+
} catch (err) {
|
|
323
|
+
connection.sendMessage({
|
|
324
|
+
type: "call-response",
|
|
325
|
+
namespace: call.namespace,
|
|
326
|
+
requestId: call.requestId,
|
|
327
|
+
success: false,
|
|
328
|
+
errorMessage: `${err}`
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}}
|
|
332
|
+
__init18() {this.onMessage = (connection, message) => {
|
|
303
333
|
const con = this.connections.get(connection);
|
|
304
334
|
if (!con) {
|
|
305
335
|
_optionalChain([this, 'access', _62 => _62.log, 'call', _63 => _63(), 'optionalAccess', _64 => _64.warn, 'call', _65 => _65(`got message from unknown connection`)]);
|
|
@@ -320,6 +350,9 @@ var Toolkit = (_class2 = class {
|
|
|
320
350
|
publicConnection
|
|
321
351
|
);
|
|
322
352
|
break;
|
|
353
|
+
case "component-call":
|
|
354
|
+
this.handleCall(connection, publicConnection, message);
|
|
355
|
+
break;
|
|
323
356
|
}
|
|
324
357
|
}}
|
|
325
358
|
}, _class2);
|
|
@@ -336,4 +369,4 @@ var Toolkit = (_class2 = class {
|
|
|
336
369
|
|
|
337
370
|
|
|
338
371
|
|
|
339
|
-
exports.Button =
|
|
372
|
+
exports.Button = _chunk4OCRZD4Fjs.Button; exports.Group = _chunk7JIC2XBCjs.Group; exports.GroupHeader = _chunk7JIC2XBCjs.GroupHeader; exports.Label = _chunk3GTEUTFTjs.Label; exports.Rect = _chunkQAH2OSHRjs.Rect; exports.SliderButton = _chunkNL3W4M7Jjs.SliderButton; exports.Switch = _chunk53EOA4UEjs.Switch; exports.Tab = _chunkU6FSQBQ3js.Tab; exports.Tabs = _chunkU6FSQBQ3js.Tabs; exports.TextInput = _chunkHTCWMJUAjs.TextInput; exports.Timeline = _chunk6QWYIJLMjs.Timeline; exports.Toolkit = Toolkit;
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Tab,
|
|
3
3
|
Tabs
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KMEDXCBI.mjs";
|
|
5
5
|
import {
|
|
6
6
|
TextInput
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WDB3IMOP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
Timeline
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-3TXBS2UN.mjs";
|
|
11
11
|
import {
|
|
12
12
|
IDMap
|
|
13
13
|
} from "./chunk-RGHJEMWG.mjs";
|
|
14
14
|
import {
|
|
15
15
|
Button
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LK6MGXYC.mjs";
|
|
17
17
|
import {
|
|
18
18
|
Group,
|
|
19
19
|
GroupHeader
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-E6FGU7DA.mjs";
|
|
21
21
|
import {
|
|
22
22
|
Label
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-UQWCTVMC.mjs";
|
|
24
24
|
import {
|
|
25
25
|
Rect
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-6ELB27LK.mjs";
|
|
27
27
|
import {
|
|
28
28
|
SliderButton
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-QB2WPBWV.mjs";
|
|
30
30
|
import {
|
|
31
31
|
Switch
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-PG5EAV5X.mjs";
|
|
33
33
|
import {
|
|
34
34
|
EventEmitter
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-GONHNB6V.mjs";
|
|
36
36
|
import {
|
|
37
37
|
__require
|
|
38
38
|
} from "./chunk-Y6FXYEAI.mjs";
|
|
@@ -299,6 +299,36 @@ var Toolkit = class {
|
|
|
299
299
|
this.events.emit("closed-connection", con.publicConnection);
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
|
+
handleCall = async (connection, publicConnection, call) => {
|
|
303
|
+
try {
|
|
304
|
+
const rg = this.rootGroup;
|
|
305
|
+
if (rg) {
|
|
306
|
+
const returnValue = await new Promise(
|
|
307
|
+
(resolve2, reject) => rg.routeCall(this.componentIDMap, call, publicConnection, {
|
|
308
|
+
resolve: resolve2,
|
|
309
|
+
reject
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
connection.sendMessage({
|
|
313
|
+
type: "call-response",
|
|
314
|
+
namespace: call.namespace,
|
|
315
|
+
requestId: call.requestId,
|
|
316
|
+
success: true,
|
|
317
|
+
returnValue
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
throw new Error("No root group set");
|
|
321
|
+
}
|
|
322
|
+
} catch (err) {
|
|
323
|
+
connection.sendMessage({
|
|
324
|
+
type: "call-response",
|
|
325
|
+
namespace: call.namespace,
|
|
326
|
+
requestId: call.requestId,
|
|
327
|
+
success: false,
|
|
328
|
+
errorMessage: `${err}`
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
};
|
|
302
332
|
onMessage = (connection, message) => {
|
|
303
333
|
const con = this.connections.get(connection);
|
|
304
334
|
if (!con) {
|
|
@@ -320,6 +350,9 @@ var Toolkit = class {
|
|
|
320
350
|
publicConnection
|
|
321
351
|
);
|
|
322
352
|
break;
|
|
353
|
+
case "component-call":
|
|
354
|
+
this.handleCall(connection, publicConnection, message);
|
|
355
|
+
break;
|
|
323
356
|
}
|
|
324
357
|
};
|
|
325
358
|
};
|
|
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
|
|
4
4
|
import * as http from 'http';
|
|
5
5
|
import { Application } from 'express';
|
|
6
6
|
import { WebSocket } from 'ws';
|
|
7
|
-
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage } from '@arcanejs/protocol';
|
|
7
|
+
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage, AnyClientComponentCall, ReturnForPair } from '@arcanejs/protocol';
|
|
8
8
|
import * as proto from '@arcanejs/protocol/core';
|
|
9
9
|
import { GroupComponentStyle } from '@arcanejs/protocol/styles';
|
|
10
10
|
import { I as IDMap } from './id-map-DxQ3_gyA.js';
|
|
@@ -88,7 +88,7 @@ type InitializationOptions =
|
|
|
88
88
|
setup: (server: Server) => void;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace>, Props> {
|
|
91
|
+
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace, string>, Props, CallPairs = any, CallActions extends string & keyof CallPairs = any> {
|
|
92
92
|
/** @hidden */
|
|
93
93
|
private parent;
|
|
94
94
|
/** @hidden */
|
|
@@ -117,16 +117,22 @@ declare abstract class Base<Namespace extends string, Proto extends BaseComponen
|
|
|
117
117
|
abstract getProtoInfo(idMap: IDMap): Proto;
|
|
118
118
|
/** @hidden */
|
|
119
119
|
handleMessage(_message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
120
|
+
/** @hidden */
|
|
121
|
+
handleCall(_call: AnyClientComponentCall, _connection: ToolkitConnection): Promise<ReturnForPair<CallPairs, CallActions>>;
|
|
120
122
|
routeMessage(_idMap: IDMap, _message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
123
|
+
routeCall(_idMap: IDMap, _call: AnyClientComponentCall, _connection: ToolkitConnection, _callbacks: {
|
|
124
|
+
resolve: (result: unknown) => void;
|
|
125
|
+
reject: (error: unknown) => void;
|
|
126
|
+
}): void;
|
|
121
127
|
}
|
|
122
|
-
type AnyComponent = Base<string, BaseComponentProto<string>, any>;
|
|
128
|
+
type AnyComponent = Base<string, BaseComponentProto<string, string>, any>;
|
|
123
129
|
/** @hidden */
|
|
124
130
|
interface Parent {
|
|
125
131
|
updateTree(): void;
|
|
126
132
|
removeChild(component: AnyComponent): void;
|
|
127
133
|
log(): Logger | null;
|
|
128
134
|
}
|
|
129
|
-
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace>, T> extends Base<Namespace, Proto, T> implements Parent {
|
|
135
|
+
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace, string>, T, CallPairs = any, CallActions extends string & keyof CallPairs = any> extends Base<Namespace, Proto, T, CallPairs, CallActions> implements Parent {
|
|
130
136
|
/** @hidden */
|
|
131
137
|
private children;
|
|
132
138
|
abstract validateChildren(children: AnyComponent[]): void;
|
|
@@ -145,6 +151,10 @@ declare abstract class BaseParent<Namespace extends string, Proto extends BaseCo
|
|
|
145
151
|
* @hidden
|
|
146
152
|
*/
|
|
147
153
|
routeMessage(idMap: IDMap, message: AnyClientComponentMessage, connection: ToolkitConnection): void;
|
|
154
|
+
routeCall(idMap: IDMap, call: AnyClientComponentCall, connection: ToolkitConnection, callbacks: {
|
|
155
|
+
resolve: (result: unknown) => void;
|
|
156
|
+
reject: (error: unknown) => void;
|
|
157
|
+
}): Promise<void>;
|
|
148
158
|
insertBefore(child: AnyComponent, beforeChild: AnyComponent): void;
|
|
149
159
|
}
|
|
150
160
|
interface Listenable<Map extends Record<string, (...args: any[]) => void>> {
|
|
@@ -155,7 +165,12 @@ declare class EventEmitter<Map extends Record<string, (...args: any[]) => void>>
|
|
|
155
165
|
private readonly listeners;
|
|
156
166
|
addListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
157
167
|
removeListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
158
|
-
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<
|
|
168
|
+
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<ReturnType<Map[T]>[]>;
|
|
169
|
+
/**
|
|
170
|
+
* Like {@link emit},
|
|
171
|
+
* but ensures only a single listener exists and returns its result.
|
|
172
|
+
*/
|
|
173
|
+
call: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<ReturnType<Map[T]>>;
|
|
159
174
|
/**
|
|
160
175
|
* Process prop changes to update listeners
|
|
161
176
|
*/
|
|
@@ -174,7 +189,7 @@ type InternalProps$1 = {
|
|
|
174
189
|
onClick?: Events$2['click'] | null;
|
|
175
190
|
};
|
|
176
191
|
type Props$1 = Partial<InternalProps$1>;
|
|
177
|
-
declare class Button extends Base<proto.CoreNamespace, proto.
|
|
192
|
+
declare class Button extends Base<proto.CoreNamespace, proto.ButtonComponent, InternalProps$1, proto.CoreComponentCalls, 'press'> implements Listenable<Events$2> {
|
|
178
193
|
/** @hidden */
|
|
179
194
|
private readonly events;
|
|
180
195
|
constructor(props?: Props$1);
|
|
@@ -186,7 +201,7 @@ declare class Button extends Base<proto.CoreNamespace, proto.CoreComponent, Inte
|
|
|
186
201
|
/** @hidden */
|
|
187
202
|
getProtoInfo: (idMap: IDMap) => proto.ButtonComponent;
|
|
188
203
|
/** @hidden */
|
|
189
|
-
|
|
204
|
+
handleCall: (call: AnyClientComponentCall, connection: ToolkitConnection) => Promise<true>;
|
|
190
205
|
}
|
|
191
206
|
|
|
192
207
|
type Label = (proto.GroupComponent['labels'] & Array<unknown>)[number];
|
|
@@ -263,6 +278,7 @@ declare class Toolkit implements Parent, Listenable<Events> {
|
|
|
263
278
|
removeChild: (component: AnyComponent) => void;
|
|
264
279
|
private onNewConnection;
|
|
265
280
|
private onClosedConnection;
|
|
281
|
+
private handleCall;
|
|
266
282
|
private onMessage;
|
|
267
283
|
}
|
|
268
284
|
|
|
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
|
|
4
4
|
import * as http from 'http';
|
|
5
5
|
import { Application } from 'express';
|
|
6
6
|
import { WebSocket } from 'ws';
|
|
7
|
-
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage } from '@arcanejs/protocol';
|
|
7
|
+
import { ClientMessage, ServerMessage, BaseComponentProto, AnyClientComponentMessage, AnyClientComponentCall, ReturnForPair } from '@arcanejs/protocol';
|
|
8
8
|
import * as proto from '@arcanejs/protocol/core';
|
|
9
9
|
import { GroupComponentStyle } from '@arcanejs/protocol/styles';
|
|
10
10
|
import { I as IDMap } from './id-map-DxQ3_gyA.mjs';
|
|
@@ -88,7 +88,7 @@ type InitializationOptions =
|
|
|
88
88
|
setup: (server: Server) => void;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace>, Props> {
|
|
91
|
+
declare abstract class Base<Namespace extends string, Proto extends BaseComponentProto<Namespace, string>, Props, CallPairs = any, CallActions extends string & keyof CallPairs = any> {
|
|
92
92
|
/** @hidden */
|
|
93
93
|
private parent;
|
|
94
94
|
/** @hidden */
|
|
@@ -117,16 +117,22 @@ declare abstract class Base<Namespace extends string, Proto extends BaseComponen
|
|
|
117
117
|
abstract getProtoInfo(idMap: IDMap): Proto;
|
|
118
118
|
/** @hidden */
|
|
119
119
|
handleMessage(_message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
120
|
+
/** @hidden */
|
|
121
|
+
handleCall(_call: AnyClientComponentCall, _connection: ToolkitConnection): Promise<ReturnForPair<CallPairs, CallActions>>;
|
|
120
122
|
routeMessage(_idMap: IDMap, _message: AnyClientComponentMessage, _connection: ToolkitConnection): void;
|
|
123
|
+
routeCall(_idMap: IDMap, _call: AnyClientComponentCall, _connection: ToolkitConnection, _callbacks: {
|
|
124
|
+
resolve: (result: unknown) => void;
|
|
125
|
+
reject: (error: unknown) => void;
|
|
126
|
+
}): void;
|
|
121
127
|
}
|
|
122
|
-
type AnyComponent = Base<string, BaseComponentProto<string>, any>;
|
|
128
|
+
type AnyComponent = Base<string, BaseComponentProto<string, string>, any>;
|
|
123
129
|
/** @hidden */
|
|
124
130
|
interface Parent {
|
|
125
131
|
updateTree(): void;
|
|
126
132
|
removeChild(component: AnyComponent): void;
|
|
127
133
|
log(): Logger | null;
|
|
128
134
|
}
|
|
129
|
-
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace>, T> extends Base<Namespace, Proto, T> implements Parent {
|
|
135
|
+
declare abstract class BaseParent<Namespace extends string, Proto extends BaseComponentProto<Namespace, string>, T, CallPairs = any, CallActions extends string & keyof CallPairs = any> extends Base<Namespace, Proto, T, CallPairs, CallActions> implements Parent {
|
|
130
136
|
/** @hidden */
|
|
131
137
|
private children;
|
|
132
138
|
abstract validateChildren(children: AnyComponent[]): void;
|
|
@@ -145,6 +151,10 @@ declare abstract class BaseParent<Namespace extends string, Proto extends BaseCo
|
|
|
145
151
|
* @hidden
|
|
146
152
|
*/
|
|
147
153
|
routeMessage(idMap: IDMap, message: AnyClientComponentMessage, connection: ToolkitConnection): void;
|
|
154
|
+
routeCall(idMap: IDMap, call: AnyClientComponentCall, connection: ToolkitConnection, callbacks: {
|
|
155
|
+
resolve: (result: unknown) => void;
|
|
156
|
+
reject: (error: unknown) => void;
|
|
157
|
+
}): Promise<void>;
|
|
148
158
|
insertBefore(child: AnyComponent, beforeChild: AnyComponent): void;
|
|
149
159
|
}
|
|
150
160
|
interface Listenable<Map extends Record<string, (...args: any[]) => void>> {
|
|
@@ -155,7 +165,12 @@ declare class EventEmitter<Map extends Record<string, (...args: any[]) => void>>
|
|
|
155
165
|
private readonly listeners;
|
|
156
166
|
addListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
157
167
|
removeListener: <T extends keyof Map>(type: T, listener: Map[T]) => void;
|
|
158
|
-
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<
|
|
168
|
+
emit: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<ReturnType<Map[T]>[]>;
|
|
169
|
+
/**
|
|
170
|
+
* Like {@link emit},
|
|
171
|
+
* but ensures only a single listener exists and returns its result.
|
|
172
|
+
*/
|
|
173
|
+
call: <T extends keyof Map>(type: T, ...args: Parameters<Map[T]>) => Promise<ReturnType<Map[T]>>;
|
|
159
174
|
/**
|
|
160
175
|
* Process prop changes to update listeners
|
|
161
176
|
*/
|
|
@@ -174,7 +189,7 @@ type InternalProps$1 = {
|
|
|
174
189
|
onClick?: Events$2['click'] | null;
|
|
175
190
|
};
|
|
176
191
|
type Props$1 = Partial<InternalProps$1>;
|
|
177
|
-
declare class Button extends Base<proto.CoreNamespace, proto.
|
|
192
|
+
declare class Button extends Base<proto.CoreNamespace, proto.ButtonComponent, InternalProps$1, proto.CoreComponentCalls, 'press'> implements Listenable<Events$2> {
|
|
178
193
|
/** @hidden */
|
|
179
194
|
private readonly events;
|
|
180
195
|
constructor(props?: Props$1);
|
|
@@ -186,7 +201,7 @@ declare class Button extends Base<proto.CoreNamespace, proto.CoreComponent, Inte
|
|
|
186
201
|
/** @hidden */
|
|
187
202
|
getProtoInfo: (idMap: IDMap) => proto.ButtonComponent;
|
|
188
203
|
/** @hidden */
|
|
189
|
-
|
|
204
|
+
handleCall: (call: AnyClientComponentCall, connection: ToolkitConnection) => Promise<true>;
|
|
190
205
|
}
|
|
191
206
|
|
|
192
207
|
type Label = (proto.GroupComponent['labels'] & Array<unknown>)[number];
|
|
@@ -263,6 +278,7 @@ declare class Toolkit implements Parent, Listenable<Events> {
|
|
|
263
278
|
removeChild: (component: AnyComponent) => void;
|
|
264
279
|
private onNewConnection;
|
|
265
280
|
private onClosedConnection;
|
|
281
|
+
private handleCall;
|
|
266
282
|
private onMessage;
|
|
267
283
|
}
|
|
268
284
|
|