@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.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/dist/backend/components/base.d.mts +1 -1
  3. package/dist/backend/components/base.d.ts +1 -1
  4. package/dist/backend/components/base.js +2 -2
  5. package/dist/backend/components/base.mjs +1 -1
  6. package/dist/backend/components/button.d.mts +1 -1
  7. package/dist/backend/components/button.d.ts +1 -1
  8. package/dist/backend/components/button.js +3 -3
  9. package/dist/backend/components/button.mjs +2 -2
  10. package/dist/backend/components/group.d.mts +1 -1
  11. package/dist/backend/components/group.d.ts +1 -1
  12. package/dist/backend/components/group.js +3 -3
  13. package/dist/backend/components/group.mjs +2 -2
  14. package/dist/backend/components/label.d.mts +1 -1
  15. package/dist/backend/components/label.d.ts +1 -1
  16. package/dist/backend/components/label.js +3 -3
  17. package/dist/backend/components/label.mjs +2 -2
  18. package/dist/backend/components/rect.d.mts +1 -1
  19. package/dist/backend/components/rect.d.ts +1 -1
  20. package/dist/backend/components/rect.js +3 -3
  21. package/dist/backend/components/rect.mjs +2 -2
  22. package/dist/backend/components/slider-button.d.mts +1 -1
  23. package/dist/backend/components/slider-button.d.ts +1 -1
  24. package/dist/backend/components/slider-button.js +3 -3
  25. package/dist/backend/components/slider-button.mjs +2 -2
  26. package/dist/backend/components/switch.d.mts +1 -1
  27. package/dist/backend/components/switch.d.ts +1 -1
  28. package/dist/backend/components/switch.js +3 -3
  29. package/dist/backend/components/switch.mjs +2 -2
  30. package/dist/backend/components/tabs.d.mts +1 -1
  31. package/dist/backend/components/tabs.d.ts +1 -1
  32. package/dist/backend/components/tabs.js +3 -3
  33. package/dist/backend/components/tabs.mjs +2 -2
  34. package/dist/backend/components/text-input.d.mts +1 -1
  35. package/dist/backend/components/text-input.d.ts +1 -1
  36. package/dist/backend/components/text-input.js +3 -3
  37. package/dist/backend/components/text-input.mjs +2 -2
  38. package/dist/backend/components/timeline.d.mts +1 -1
  39. package/dist/backend/components/timeline.d.ts +1 -1
  40. package/dist/backend/components/timeline.js +3 -3
  41. package/dist/backend/components/timeline.mjs +2 -2
  42. package/dist/{chunk-DRQVYGTI.js → chunk-3GTEUTFT.js} +2 -2
  43. package/dist/{chunk-K37TZB75.mjs → chunk-3TXBS2UN.mjs} +1 -1
  44. package/dist/{chunk-DG75CS7F.js → chunk-4OCRZD4F.js} +7 -16
  45. package/dist/{chunk-VEZGD2PG.js → chunk-53EOA4UE.js} +3 -3
  46. package/dist/{chunk-N6IHYBZH.mjs → chunk-6ELB27LK.mjs} +1 -1
  47. package/dist/{chunk-6CWEURJP.js → chunk-6QWYIJLM.js} +2 -2
  48. package/dist/{chunk-O5ZW6JYG.js → chunk-7JIC2XBC.js} +4 -4
  49. package/dist/{chunk-5D7OSUZ6.mjs → chunk-E6FGU7DA.mjs} +1 -1
  50. package/dist/{chunk-RYR5I5FT.mjs → chunk-GONHNB6V.mjs} +33 -0
  51. package/dist/{chunk-4OZ22IQU.js → chunk-HTCWMJUA.js} +3 -3
  52. package/dist/{chunk-7TTY7CBH.mjs → chunk-KMEDXCBI.mjs} +1 -1
  53. package/dist/{chunk-W42AOMM6.mjs → chunk-LK6MGXYC.mjs} +5 -14
  54. package/dist/{chunk-CME7HZZK.js → chunk-NL3W4M7J.js} +3 -3
  55. package/dist/{chunk-NEQRLPXK.mjs → chunk-PG5EAV5X.mjs} +1 -1
  56. package/dist/{chunk-7OX2FB6C.js → chunk-QAH2OSHR.js} +2 -2
  57. package/dist/{chunk-JFZXSCGK.mjs → chunk-QB2WPBWV.mjs} +1 -1
  58. package/dist/{chunk-GMDJYFHD.js → chunk-U6FSQBQ3.js} +3 -3
  59. package/dist/{chunk-CUZSHFDP.mjs → chunk-UQWCTVMC.mjs} +1 -1
  60. package/dist/{chunk-YBBUC3QC.mjs → chunk-WDB3IMOP.mjs} +1 -1
  61. package/dist/{chunk-SGACFY53.js → chunk-WN3GXVUE.js} +35 -2
  62. package/dist/frontend/entrypoint.js +84 -31
  63. package/dist/frontend/entrypoint.js.map +3 -3
  64. package/dist/frontend/index.js +62 -19
  65. package/dist/frontend/index.mjs +62 -19
  66. package/dist/index.d.mts +1 -1
  67. package/dist/index.d.ts +1 -1
  68. package/dist/index.js +47 -14
  69. package/dist/index.mjs +43 -10
  70. package/dist/{toolkit-2w2SWHlT.d.ts → toolkit-C37sQAkD.d.ts} +23 -7
  71. package/dist/{toolkit-DB8G2TaA.d.mts → toolkit-CQMnQMOF.d.mts} +23 -7
  72. package/package.json +5 -5
@@ -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.useEffect.call(void 0, () => {
272
- initializeWebsocket();
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 handleMessage = (msg) => {
303
- switch (msg.type) {
304
- case "metadata":
305
- uuid.current = msg.connectionUuid;
306
- return;
307
- case "tree-full":
308
- setRoot(msg.root);
309
- return;
310
- case "tree-diff":
311
- setRoot((prevRoot) => _diff.patchJson.call(void 0, prevRoot, msg.diff));
312
- return;
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");
@@ -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
- useEffect2(() => {
272
- initializeWebsocket();
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 handleMessage = (msg) => {
303
- switch (msg.type) {
304
- case "metadata":
305
- uuid.current = msg.connectionUuid;
306
- return;
307
- case "tree-full":
308
- setRoot(msg.root);
309
- return;
310
- case "tree-diff":
311
- setRoot((prevRoot) => patchJson(prevRoot, msg.diff));
312
- return;
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-DB8G2TaA.mjs';
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-2w2SWHlT.js';
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 _chunkGMDJYFHDjs = require('./chunk-GMDJYFHD.js');
4
+ var _chunkU6FSQBQ3js = require('./chunk-U6FSQBQ3.js');
5
5
 
6
6
 
7
- var _chunk4OZ22IQUjs = require('./chunk-4OZ22IQU.js');
7
+ var _chunkHTCWMJUAjs = require('./chunk-HTCWMJUA.js');
8
8
 
9
9
 
10
- var _chunk6CWEURJPjs = require('./chunk-6CWEURJP.js');
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 _chunkDG75CS7Fjs = require('./chunk-DG75CS7F.js');
16
+ var _chunk4OCRZD4Fjs = require('./chunk-4OCRZD4F.js');
17
17
 
18
18
 
19
19
 
20
- var _chunkO5ZW6JYGjs = require('./chunk-O5ZW6JYG.js');
20
+ var _chunk7JIC2XBCjs = require('./chunk-7JIC2XBC.js');
21
21
 
22
22
 
23
- var _chunkDRQVYGTIjs = require('./chunk-DRQVYGTI.js');
23
+ var _chunk3GTEUTFTjs = require('./chunk-3GTEUTFT.js');
24
24
 
25
25
 
26
- var _chunk7OX2FB6Cjs = require('./chunk-7OX2FB6C.js');
26
+ var _chunkQAH2OSHRjs = require('./chunk-QAH2OSHR.js');
27
27
 
28
28
 
29
- var _chunkCME7HZZKjs = require('./chunk-CME7HZZK.js');
29
+ var _chunkNL3W4M7Jjs = require('./chunk-NL3W4M7J.js');
30
30
 
31
31
 
32
- var _chunkVEZGD2PGjs = require('./chunk-VEZGD2PG.js');
32
+ var _chunk53EOA4UEjs = require('./chunk-53EOA4UE.js');
33
33
 
34
34
 
35
- var _chunkSGACFY53js = require('./chunk-SGACFY53.js');
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, _chunkSGACFY53js.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);
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.onMessage = (connection, message) => {
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 = _chunkDG75CS7Fjs.Button; exports.Group = _chunkO5ZW6JYGjs.Group; exports.GroupHeader = _chunkO5ZW6JYGjs.GroupHeader; exports.Label = _chunkDRQVYGTIjs.Label; exports.Rect = _chunk7OX2FB6Cjs.Rect; exports.SliderButton = _chunkCME7HZZKjs.SliderButton; exports.Switch = _chunkVEZGD2PGjs.Switch; exports.Tab = _chunkGMDJYFHDjs.Tab; exports.Tabs = _chunkGMDJYFHDjs.Tabs; exports.TextInput = _chunk4OZ22IQUjs.TextInput; exports.Timeline = _chunk6CWEURJPjs.Timeline; exports.Toolkit = Toolkit;
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-7TTY7CBH.mjs";
4
+ } from "./chunk-KMEDXCBI.mjs";
5
5
  import {
6
6
  TextInput
7
- } from "./chunk-YBBUC3QC.mjs";
7
+ } from "./chunk-WDB3IMOP.mjs";
8
8
  import {
9
9
  Timeline
10
- } from "./chunk-K37TZB75.mjs";
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-W42AOMM6.mjs";
16
+ } from "./chunk-LK6MGXYC.mjs";
17
17
  import {
18
18
  Group,
19
19
  GroupHeader
20
- } from "./chunk-5D7OSUZ6.mjs";
20
+ } from "./chunk-E6FGU7DA.mjs";
21
21
  import {
22
22
  Label
23
- } from "./chunk-CUZSHFDP.mjs";
23
+ } from "./chunk-UQWCTVMC.mjs";
24
24
  import {
25
25
  Rect
26
- } from "./chunk-N6IHYBZH.mjs";
26
+ } from "./chunk-6ELB27LK.mjs";
27
27
  import {
28
28
  SliderButton
29
- } from "./chunk-JFZXSCGK.mjs";
29
+ } from "./chunk-QB2WPBWV.mjs";
30
30
  import {
31
31
  Switch
32
- } from "./chunk-NEQRLPXK.mjs";
32
+ } from "./chunk-PG5EAV5X.mjs";
33
33
  import {
34
34
  EventEmitter
35
- } from "./chunk-RYR5I5FT.mjs";
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<unknown>;
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.CoreComponent, InternalProps$1> implements Listenable<Events$2> {
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
- handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
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<unknown>;
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.CoreComponent, InternalProps$1> implements Listenable<Events$2> {
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
- handleMessage: (message: AnyClientComponentMessage, connection: ToolkitConnection) => void;
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