@arcanejs/toolkit 8.0.0 → 9.0.1

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 (71) hide show
  1. package/dist/backend/components/base.d.mts +2 -1
  2. package/dist/backend/components/base.d.ts +2 -1
  3. package/dist/backend/components/base.js +2 -2
  4. package/dist/backend/components/base.mjs +1 -1
  5. package/dist/backend/components/button.d.mts +2 -1
  6. package/dist/backend/components/button.d.ts +2 -1
  7. package/dist/backend/components/button.js +3 -3
  8. package/dist/backend/components/button.mjs +2 -2
  9. package/dist/backend/components/group.d.mts +2 -1
  10. package/dist/backend/components/group.d.ts +2 -1
  11. package/dist/backend/components/group.js +3 -3
  12. package/dist/backend/components/group.mjs +2 -2
  13. package/dist/backend/components/label.d.mts +2 -1
  14. package/dist/backend/components/label.d.ts +2 -1
  15. package/dist/backend/components/label.js +3 -3
  16. package/dist/backend/components/label.mjs +2 -2
  17. package/dist/backend/components/rect.d.mts +2 -1
  18. package/dist/backend/components/rect.d.ts +2 -1
  19. package/dist/backend/components/rect.js +3 -3
  20. package/dist/backend/components/rect.mjs +2 -2
  21. package/dist/backend/components/slider-button.d.mts +2 -1
  22. package/dist/backend/components/slider-button.d.ts +2 -1
  23. package/dist/backend/components/slider-button.js +3 -3
  24. package/dist/backend/components/slider-button.mjs +2 -2
  25. package/dist/backend/components/switch.d.mts +2 -1
  26. package/dist/backend/components/switch.d.ts +2 -1
  27. package/dist/backend/components/switch.js +3 -3
  28. package/dist/backend/components/switch.mjs +2 -2
  29. package/dist/backend/components/tabs.d.mts +2 -1
  30. package/dist/backend/components/tabs.d.ts +2 -1
  31. package/dist/backend/components/tabs.js +3 -3
  32. package/dist/backend/components/tabs.mjs +2 -2
  33. package/dist/backend/components/text-input.d.mts +2 -1
  34. package/dist/backend/components/text-input.d.ts +2 -1
  35. package/dist/backend/components/text-input.js +3 -3
  36. package/dist/backend/components/text-input.mjs +2 -2
  37. package/dist/backend/components/timeline.d.mts +2 -1
  38. package/dist/backend/components/timeline.d.ts +2 -1
  39. package/dist/backend/components/timeline.js +3 -3
  40. package/dist/backend/components/timeline.mjs +2 -2
  41. package/dist/{chunk-IV3AE3CW.js → chunk-2R23ER4K.js} +3 -3
  42. package/dist/{chunk-R5OA7LLZ.mjs → chunk-5K7DK7CW.mjs} +1 -1
  43. package/dist/{chunk-RJLYYTZ6.mjs → chunk-7WTSYZOS.mjs} +1 -1
  44. package/dist/{chunk-2K4UT5QB.js → chunk-AYMITMVR.js} +3 -3
  45. package/dist/{chunk-K6V55JTG.mjs → chunk-KO24S32V.mjs} +1 -1
  46. package/dist/{chunk-XSKWLJOQ.js → chunk-KRGLXKY2.js} +4 -4
  47. package/dist/{chunk-JHWFQLLE.mjs → chunk-MNEFCU3M.mjs} +1 -1
  48. package/dist/{chunk-TF7N4O5G.js → chunk-NEFCI6N6.js} +2 -2
  49. package/dist/{chunk-TULW7CRV.mjs → chunk-NJW4ZG4X.mjs} +1 -1
  50. package/dist/{chunk-MHSAHTVN.mjs → chunk-QBZB56TQ.mjs} +1 -1
  51. package/dist/{chunk-UHEZQR2Q.js → chunk-QHCNKTKW.js} +2 -2
  52. package/dist/{chunk-4AGKM5NT.js → chunk-RELZ3VTJ.js} +3 -3
  53. package/dist/{chunk-7MQHRTBE.mjs → chunk-RGLKNCJ3.mjs} +1 -1
  54. package/dist/{chunk-A3RWE7HZ.js → chunk-SPYBETRJ.js} +3 -3
  55. package/dist/{chunk-GONHNB6V.mjs → chunk-UTTTCTUQ.mjs} +26 -5
  56. package/dist/{chunk-GXJ3JRRK.mjs → chunk-VD6S32ED.mjs} +1 -1
  57. package/dist/{chunk-5B65Q7RL.js → chunk-VTNAO4KC.js} +2 -2
  58. package/dist/{chunk-6PS3Q66F.mjs → chunk-Y3NPWW27.mjs} +1 -1
  59. package/dist/{chunk-CVY55KAR.js → chunk-Y5FC42KD.js} +3 -3
  60. package/dist/{chunk-WN3GXVUE.js → chunk-YNOJTE3G.js} +26 -5
  61. package/dist/frontend/entrypoint.js +42 -1
  62. package/dist/frontend/entrypoint.js.map +2 -2
  63. package/dist/frontend/index.js +69 -12
  64. package/dist/frontend/index.mjs +69 -12
  65. package/dist/index.d.mts +3 -2
  66. package/dist/index.d.ts +3 -2
  67. package/dist/index.js +190 -64
  68. package/dist/index.mjs +161 -35
  69. package/dist/{toolkit-Bglbv3ix.d.ts → toolkit-0nxr5FpP.d.ts} +116 -93
  70. package/dist/{toolkit-BPqxbDbk.d.mts → toolkit-BYE-VOhF.d.mts} +116 -93
  71. package/package.json +16 -16
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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 _chunkA3RWE7HZjs = require('./chunk-A3RWE7HZ.js');
4
+ var _chunkSPYBETRJjs = require('./chunk-SPYBETRJ.js');
5
5
 
6
6
 
7
- var _chunkIV3AE3CWjs = require('./chunk-IV3AE3CW.js');
7
+ var _chunk2R23ER4Kjs = require('./chunk-2R23ER4K.js');
8
8
 
9
9
 
10
- var _chunkUHEZQR2Qjs = require('./chunk-UHEZQR2Q.js');
10
+ var _chunkQHCNKTKWjs = require('./chunk-QHCNKTKW.js');
11
11
 
12
12
 
13
13
  var _chunkEABM5X65js = require('./chunk-EABM5X65.js');
14
14
 
15
15
 
16
- var _chunk4AGKM5NTjs = require('./chunk-4AGKM5NT.js');
16
+ var _chunkRELZ3VTJjs = require('./chunk-RELZ3VTJ.js');
17
17
 
18
18
 
19
19
 
20
- var _chunkXSKWLJOQjs = require('./chunk-XSKWLJOQ.js');
20
+ var _chunkKRGLXKY2js = require('./chunk-KRGLXKY2.js');
21
21
 
22
22
 
23
- var _chunkTF7N4O5Gjs = require('./chunk-TF7N4O5G.js');
23
+ var _chunkNEFCI6N6js = require('./chunk-NEFCI6N6.js');
24
24
 
25
25
 
26
- var _chunk5B65Q7RLjs = require('./chunk-5B65Q7RL.js');
26
+ var _chunkVTNAO4KCjs = require('./chunk-VTNAO4KC.js');
27
27
 
28
28
 
29
- var _chunkCVY55KARjs = require('./chunk-CVY55KAR.js');
29
+ var _chunkY5FC42KDjs = require('./chunk-Y5FC42KD.js');
30
30
 
31
31
 
32
- var _chunk2K4UT5QBjs = require('./chunk-2K4UT5QB.js');
32
+ var _chunkAYMITMVRjs = require('./chunk-AYMITMVR.js');
33
33
 
34
34
 
35
- var _chunkWN3GXVUEjs = require('./chunk-WN3GXVUE.js');
35
+ var _chunkYNOJTE3Gjs = require('./chunk-YNOJTE3G.js');
36
36
 
37
37
 
38
38
  var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
@@ -69,15 +69,26 @@ var distDir = () => {
69
69
  throw new Error(`Server running from unknown location: ${__dirname}`);
70
70
  }
71
71
  };
72
+ var UPLOAD_URL = /^\/upload\/([0-9a-f]+)$/;
73
+ var DOWNLOAD_URL = /^\/download\/([0-9a-f]+)$/;
72
74
  var Server = (_class = class {
73
- constructor(options, onNewConnection, onClosedConnection, onMessage, log) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);_class.prototype.__init11.call(this);_class.prototype.__init12.call(this);
75
+ constructor(options, onNewConnection, onClosedConnection, onMessage, onUpload, onDownload, log) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);_class.prototype.__init11.call(this);_class.prototype.__init12.call(this);
74
76
  this.options = options;
75
77
  this.onNewConnection = onNewConnection;
76
78
  this.onClosedConnection = onClosedConnection;
77
79
  this.onMessage = onMessage;
80
+ this.onUpload = onUpload;
81
+ this.onDownload = onDownload;
78
82
  this.log = log;
79
83
  this.title = _nullishCoalesce(options.title, () => ( "@arcanejs"));
80
84
  }
85
+
86
+
87
+
88
+
89
+
90
+
91
+
81
92
  __init() {this.staticFiles = null}
82
93
  __init2() {this.htmlContext = null}
83
94
  __init3() {this.staticFilesInitPromise = null}
@@ -197,7 +208,7 @@ var Server = (_class = class {
197
208
  },
198
209
  assetUrls: this.createAssetUrls(this.staticFiles)
199
210
  };
200
- _optionalChain([this, 'access', _26 => _26.log, 'optionalAccess', _27 => _27.debug, 'call', _28 => _28("Static Assets: %o", this.staticFiles)]);
211
+ _optionalChain([this, 'access', _40 => _40.log, 'optionalAccess', _41 => _41.debug, 'call', _42 => _42("Static Assets: %o", this.staticFiles)]);
201
212
  })();
202
213
  this.staticFilesInitPromise.catch(() => {
203
214
  this.staticFilesInitPromise = null;
@@ -211,9 +222,9 @@ var Server = (_class = class {
211
222
  await this.ensureStaticFilesInitialized();
212
223
  } catch (err) {
213
224
  if (err instanceof Error) {
214
- _optionalChain([this, 'access', _29 => _29.log, 'optionalAccess', _30 => _30.error, 'call', _31 => _31(err)]);
225
+ _optionalChain([this, 'access', _43 => _43.log, 'optionalAccess', _44 => _44.error, 'call', _45 => _45(err)]);
215
226
  } else {
216
- _optionalChain([this, 'access', _32 => _32.log, 'optionalAccess', _33 => _33.error, 'call', _34 => _34("Error preparing static files: %o", err)]);
227
+ _optionalChain([this, 'access', _46 => _46.log, 'optionalAccess', _47 => _47.error, 'call', _48 => _48("Error preparing static files: %o", err)]);
217
228
  }
218
229
  res.writeHead(500, { "Content-Type": "text/plain" });
219
230
  res.end("Unable to prepare static files", "utf-8");
@@ -225,10 +236,10 @@ var Server = (_class = class {
225
236
  throw new Error("Static assets were not initialized");
226
237
  }
227
238
  const requestUrl = _nullishCoalesce(req.originalUrl, () => ( req.url));
228
- _optionalChain([this, 'access', _35 => _35.log, 'optionalAccess', _36 => _36.debug, 'call', _37 => _37("handleHttpRequest %s", requestUrl)]);
239
+ _optionalChain([this, 'access', _49 => _49.log, 'optionalAccess', _50 => _50.debug, 'call', _51 => _51("handleHttpRequest %s", requestUrl)]);
229
240
  const pathname = this.parsePathname(requestUrl);
230
241
  if (pathname === this.options.path) {
231
- const content = await _asyncNullishCoalesce(await _optionalChain([this, 'access', _38 => _38.options, 'access', _39 => _39.htmlPage, 'optionalCall', _40 => _40(htmlContext)]), async () => ( `
242
+ const content = await _asyncNullishCoalesce(await _optionalChain([this, 'access', _52 => _52.options, 'access', _53 => _53.htmlPage, 'optionalCall', _54 => _54(htmlContext)]), async () => ( `
232
243
  <html>
233
244
  <head>
234
245
  <title>${_escapehtml2.default.call(void 0, htmlContext.title)}</title>
@@ -263,9 +274,9 @@ var Server = (_class = class {
263
274
  return;
264
275
  } catch (err) {
265
276
  if (err instanceof Error) {
266
- _optionalChain([this, 'access', _41 => _41.log, 'optionalAccess', _42 => _42.error, 'call', _43 => _43(err)]);
277
+ _optionalChain([this, 'access', _55 => _55.log, 'optionalAccess', _56 => _56.error, 'call', _57 => _57(err)]);
267
278
  } else {
268
- _optionalChain([this, 'access', _44 => _44.log, 'optionalAccess', _45 => _45.error, 'call', _46 => _46("Error loading static file: %o", err)]);
279
+ _optionalChain([this, 'access', _58 => _58.log, 'optionalAccess', _59 => _59.error, 'call', _60 => _60("Error loading static file: %o", err)]);
269
280
  }
270
281
  res.writeHead(500, { "Content-Type": "text/plain" });
271
282
  res.end("Expected static file not found", "utf-8");
@@ -273,8 +284,45 @@ var Server = (_class = class {
273
284
  }
274
285
  }
275
286
  }
276
- res.writeHead(404, { "Content-Type": "text/plain" });
277
- res.end("not found", "utf-8");
287
+ const [uploadMatch, downloadMatch] = [
288
+ UPLOAD_URL.exec(pathname),
289
+ DOWNLOAD_URL.exec(pathname)
290
+ ];
291
+ if (_optionalChain([uploadMatch, 'optionalAccess', _61 => _61[1]])) {
292
+ const id = uploadMatch[1];
293
+ _optionalChain([this, 'access', _62 => _62.log, 'optionalAccess', _63 => _63.debug, 'call', _64 => _64("Upload request for id: %s", id)]);
294
+ this.onUpload(id, req).then(() => {
295
+ res.writeHead(200, { "Content-Type": "text/plain" });
296
+ res.end("Upload successful", "utf-8");
297
+ }).catch((cause) => {
298
+ const error = new Error(`Error handling upload for id ${id}`, {
299
+ cause
300
+ });
301
+ _optionalChain([this, 'access', _65 => _65.log, 'optionalAccess', _66 => _66.error, 'call', _67 => _67(error)]);
302
+ res.writeHead(500, { "Content-Type": "text/plain" });
303
+ res.end("Error handling upload", "utf-8");
304
+ });
305
+ } else if (_optionalChain([downloadMatch, 'optionalAccess', _68 => _68[1]])) {
306
+ const id = downloadMatch[1];
307
+ _optionalChain([this, 'access', _69 => _69.log, 'optionalAccess', _70 => _70.debug, 'call', _71 => _71("Download request for id: %s", id)]);
308
+ this.onDownload(id).then((handler) => handler()).then(({ stream, headers }) => {
309
+ res.writeHead(200, {
310
+ "Content-Type": "application/octet-stream",
311
+ ...headers
312
+ });
313
+ stream.pipe(res);
314
+ }).catch((cause) => {
315
+ const error = new Error(`Error handling download for id ${id}`, {
316
+ cause
317
+ });
318
+ _optionalChain([this, 'access', _72 => _72.log, 'optionalAccess', _73 => _73.error, 'call', _74 => _74(error)]);
319
+ res.writeHead(500, { "Content-Type": "text/plain" });
320
+ res.end("Error handling download", "utf-8");
321
+ });
322
+ } else {
323
+ res.writeHead(404, { "Content-Type": "text/plain" });
324
+ res.end("not found", "utf-8");
325
+ }
278
326
  }}
279
327
  __init8() {this.parsePathname = (url) => {
280
328
  if (!url) return "";
@@ -314,7 +362,7 @@ var Server = (_class = class {
314
362
  sendMessage: (msg) => ws.send(JSON.stringify(msg))
315
363
  };
316
364
  this.onNewConnection(connection);
317
- _optionalChain([this, 'access', _47 => _47.log, 'optionalAccess', _48 => _48.debug, 'call', _49 => _49("new connection")]);
365
+ _optionalChain([this, 'access', _75 => _75.log, 'optionalAccess', _76 => _76.debug, 'call', _77 => _77("new connection")]);
318
366
  ws.on(
319
367
  "message",
320
368
  (msg) => this.onMessage(connection, JSON.parse(msg.toString()))
@@ -327,6 +375,7 @@ var Server = (_class = class {
327
375
  var _ws = require('ws');
328
376
  var _http = require('http');
329
377
  var _uuid = require('uuid');
378
+ var _crypto = require('crypto');
330
379
  var normalizeClockSyncOptions = (clockSync) => {
331
380
  if (!clockSync) {
332
381
  return null;
@@ -351,9 +400,11 @@ var Toolkit = (_class2 = class {
351
400
  __init14() {this.connections = /* @__PURE__ */ new Map()}
352
401
  __init15() {this.rootGroup = null}
353
402
  /** @hidden */
354
- __init16() {this.events = new (0, _chunkWN3GXVUEjs.EventEmitter)()}
403
+ __init16() {this.events = new (0, _chunkYNOJTE3Gjs.EventEmitter)()}
355
404
 
356
- constructor(options = {}) {;_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);_class2.prototype.__init19.call(this);_class2.prototype.__init20.call(this);_class2.prototype.__init21.call(this);_class2.prototype.__init22.call(this);_class2.prototype.__init23.call(this);_class2.prototype.__init24.call(this);_class2.prototype.__init25.call(this);_class2.prototype.__init26.call(this);_class2.prototype.__init27.call(this);_class2.prototype.__init28.call(this);
405
+ __init17() {this.uploads = /* @__PURE__ */ new Map()}
406
+ __init18() {this.downloads = /* @__PURE__ */ new Map()}
407
+ constructor(options = {}) {;_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);_class2.prototype.__init19.call(this);_class2.prototype.__init20.call(this);_class2.prototype.__init21.call(this);_class2.prototype.__init22.call(this);_class2.prototype.__init23.call(this);_class2.prototype.__init24.call(this);_class2.prototype.__init25.call(this);_class2.prototype.__init26.call(this);_class2.prototype.__init27.call(this);_class2.prototype.__init28.call(this);_class2.prototype.__init29.call(this);_class2.prototype.__init30.call(this);_class2.prototype.__init31.call(this);_class2.prototype.__init32.call(this);_class2.prototype.__init33.call(this);
357
408
  this.options = {
358
409
  ...DEFAULT_LIGHT_DESK_OPTIONS,
359
410
  ...options
@@ -369,17 +420,19 @@ var Toolkit = (_class2 = class {
369
420
  this.onNewConnection,
370
421
  this.onClosedConnection,
371
422
  this.onMessage,
423
+ this.onUpload,
424
+ this.onDownload,
372
425
  this.options.log
373
426
  );
374
427
  }
375
- __init17() {this.addListener = this.events.addListener}
376
- __init18() {this.removeListener = this.events.removeListener}
377
- __init19() {this.start = (opts) => {
428
+ __init19() {this.addListener = this.events.addListener}
429
+ __init20() {this.removeListener = this.events.removeListener}
430
+ __init21() {this.start = (opts) => {
378
431
  if (opts.mode === "automatic") {
379
432
  this.listen({ port: opts.port }).then(() => {
380
433
  const url = `http://localhost:${opts.port}${this.options.path}`;
381
- _optionalChain([opts, 'access', _71 => _71.onReady, 'optionalCall', _72 => _72(url)]);
382
- _optionalChain([this, 'access', _73 => _73.options, 'access', _74 => _74.log, 'optionalAccess', _75 => _75.info, 'call', _76 => _76(`Light Desk Started: ${url}`)]);
434
+ _optionalChain([opts, 'access', _111 => _111.onReady, 'optionalCall', _112 => _112(url)]);
435
+ _optionalChain([this, 'access', _113 => _113.options, 'access', _114 => _114.log, 'optionalAccess', _115 => _115.info, 'call', _116 => _116(`Light Desk Started: ${url}`)]);
383
436
  });
384
437
  } else if (opts.mode === "express") {
385
438
  const wss = new (0, _ws.WebSocketServer)({
@@ -393,7 +446,7 @@ var Toolkit = (_class2 = class {
393
446
  throw new Error(`Unsupported mode`);
394
447
  }
395
448
  }}
396
- __init20() {this.listen = ({
449
+ __init22() {this.listen = ({
397
450
  port,
398
451
  host
399
452
  }) => {
@@ -428,7 +481,7 @@ var Toolkit = (_class2 = class {
428
481
  }
429
482
  });
430
483
  }}
431
- __init21() {this.setRoot = (group) => {
484
+ __init23() {this.setRoot = (group) => {
432
485
  if (this.rootGroup) {
433
486
  throw new Error("Can only set root group once");
434
487
  }
@@ -438,10 +491,10 @@ var Toolkit = (_class2 = class {
438
491
  log() {
439
492
  return _nullishCoalesce(this.options.log, () => ( null));
440
493
  }
441
- __init22() {this.getConnections = () => {
494
+ __init24() {this.getConnections = () => {
442
495
  return [...this.connections.values()].map((c) => c.publicConnection);
443
496
  }}
444
- __init23() {this.updateTree = _lodash2.default.throttle(
497
+ __init25() {this.updateTree = _lodash2.default.throttle(
445
498
  () => {
446
499
  setImmediate(() => {
447
500
  if (!this.rootGroup) return;
@@ -462,20 +515,20 @@ var Toolkit = (_class2 = class {
462
515
  10,
463
516
  { leading: true, trailing: true }
464
517
  )}
465
- __init24() {this.removeChild = (component) => {
518
+ __init26() {this.removeChild = (component) => {
466
519
  if (this.rootGroup === component) {
467
520
  this.rootGroup = null;
468
521
  component.setParent(null);
469
522
  }
470
523
  }}
471
- __init25() {this.onNewConnection = (connection) => {
524
+ __init27() {this.onNewConnection = (connection) => {
472
525
  const uuid = _uuid.v4.call(void 0, );
473
526
  const publicConnection = {
474
527
  get uuid() {
475
528
  return uuid;
476
529
  }
477
530
  };
478
- const lastTreeSent = _nullishCoalesce(_optionalChain([this, 'access', _77 => _77.rootGroup, 'optionalAccess', _78 => _78.getProtoInfo, 'call', _79 => _79(this.componentIDMap, {
531
+ const lastTreeSent = _nullishCoalesce(_optionalChain([this, 'access', _117 => _117.rootGroup, 'optionalAccess', _118 => _118.getProtoInfo, 'call', _119 => _119(this.componentIDMap, {
479
532
  connection: publicConnection
480
533
  })]), () => ( void 0));
481
534
  this.connections.set(connection, {
@@ -497,24 +550,63 @@ var Toolkit = (_class2 = class {
497
550
  });
498
551
  }
499
552
  }}
500
- __init26() {this.onClosedConnection = (connection) => {
501
- _optionalChain([this, 'access', _80 => _80.log, 'call', _81 => _81(), 'optionalAccess', _82 => _82.debug, 'call', _83 => _83("removing connection")]);
553
+ __init28() {this.onClosedConnection = (connection) => {
554
+ _optionalChain([this, 'access', _120 => _120.log, 'call', _121 => _121(), 'optionalAccess', _122 => _122.debug, 'call', _123 => _123("removing connection")]);
502
555
  const con = this.connections.get(connection);
503
556
  this.connections.delete(connection);
504
557
  if (con) {
558
+ let inProgressUploads = 0;
559
+ let inProgressDownloads = 0;
560
+ for (const [id, upload] of this.uploads.entries()) {
561
+ if (upload.connection === connection) {
562
+ this.uploads.delete(id);
563
+ inProgressUploads++;
564
+ }
565
+ }
566
+ for (const [id, download] of this.downloads.entries()) {
567
+ if (download.connection === connection) {
568
+ this.downloads.delete(id);
569
+ inProgressDownloads++;
570
+ }
571
+ }
572
+ if (inProgressUploads > 0 || inProgressDownloads > 0) {
573
+ _optionalChain([this, 'access', _124 => _124.log, 'call', _125 => _125(), 'optionalAccess', _126 => _126.info, 'call', _127 => _127(
574
+ `Connection closed with ${inProgressUploads} in-progress uploads and ${inProgressDownloads} in-progress downloads`
575
+ )]);
576
+ }
505
577
  this.events.emit("closed-connection", con.publicConnection);
506
578
  }
507
579
  }}
508
- __init27() {this.handleCall = async (connection, publicConnection, call) => {
580
+ __init29() {this.handleCall = async (connection, publicConnection, call) => {
509
581
  try {
510
582
  const rg = this.rootGroup;
511
583
  if (rg) {
512
- const returnValue = await new Promise(
584
+ const handlerValue = await new Promise(
513
585
  (resolve2, reject) => rg.routeCall(this.componentIDMap, call, publicConnection, {
514
586
  resolve: resolve2,
515
587
  reject
516
588
  })
517
589
  );
590
+ let returnValue;
591
+ if (call.type === "component-call") {
592
+ returnValue = handlerValue;
593
+ } else if (call.type === "component-call-upload") {
594
+ const uploadHandler = handlerValue;
595
+ const secureId = _crypto.randomBytes.call(void 0, 32).toString("hex");
596
+ this.uploads.set(secureId, {
597
+ connection,
598
+ handler: uploadHandler
599
+ });
600
+ returnValue = secureId;
601
+ } else if (call.type === "component-call-download") {
602
+ const downloadHandler = handlerValue;
603
+ const secureId = _crypto.randomBytes.call(void 0, 32).toString("hex");
604
+ this.downloads.set(secureId, {
605
+ connection,
606
+ handler: downloadHandler
607
+ });
608
+ returnValue = secureId;
609
+ }
518
610
  connection.sendMessage({
519
611
  type: "call-response",
520
612
  namespace: call.namespace,
@@ -525,47 +617,81 @@ var Toolkit = (_class2 = class {
525
617
  } else {
526
618
  throw new Error("No root group set");
527
619
  }
528
- } catch (err) {
620
+ } catch (cause) {
621
+ const error = new Error(`Error handling call`, { cause });
622
+ _optionalChain([this, 'access', _128 => _128.log, 'call', _129 => _129(), 'optionalAccess', _130 => _130.error, 'call', _131 => _131(error)]);
529
623
  connection.sendMessage({
530
624
  type: "call-response",
531
625
  namespace: call.namespace,
532
626
  requestId: call.requestId,
533
627
  success: false,
534
- errorMessage: `${err}`
628
+ errorMessage: `${cause}`
535
629
  });
536
630
  }
537
631
  }}
538
- __init28() {this.onMessage = (connection, message) => {
632
+ __init30() {this.onMessage = (connection, message) => {
539
633
  const con = this.connections.get(connection);
540
634
  if (!con) {
541
- _optionalChain([this, 'access', _84 => _84.log, 'call', _85 => _85(), 'optionalAccess', _86 => _86.warn, 'call', _87 => _87(`got message from unknown connection`)]);
635
+ _optionalChain([this, 'access', _132 => _132.log, 'call', _133 => _133(), 'optionalAccess', _134 => _134.warn, 'call', _135 => _135(`got message from unknown connection`)]);
542
636
  return;
543
637
  }
544
638
  const { publicConnection } = con;
545
- _optionalChain([this, 'access', _88 => _88.log, 'call', _89 => _89(), 'optionalAccess', _90 => _90.debug, 'call', _91 => _91(
639
+ _optionalChain([this, 'access', _136 => _136.log, 'call', _137 => _137(), 'optionalAccess', _138 => _138.debug, 'call', _139 => _139(
546
640
  "got message: %o from %s",
547
641
  message,
548
642
  publicConnection.uuid
549
643
  )]);
550
- switch (message.type) {
551
- case "component-message":
552
- if (this.rootGroup)
553
- this.rootGroup.routeMessage(
554
- this.componentIDMap,
555
- message,
556
- publicConnection
557
- );
558
- break;
559
- case "component-call":
560
- this.handleCall(connection, publicConnection, message);
561
- break;
562
- case "ping": {
563
- connection.sendMessage({
564
- type: "pong",
565
- pingId: message.pingId,
566
- serverTimeMillis: Date.now()
567
- });
568
- break;
644
+ try {
645
+ switch (message.type) {
646
+ case "component-message":
647
+ if (this.rootGroup)
648
+ this.rootGroup.routeMessage(
649
+ this.componentIDMap,
650
+ message,
651
+ publicConnection
652
+ );
653
+ break;
654
+ case "component-call":
655
+ case "component-call-upload":
656
+ case "component-call-download":
657
+ this.handleCall(connection, publicConnection, message);
658
+ break;
659
+ case "ping": {
660
+ connection.sendMessage({
661
+ type: "pong",
662
+ pingId: message.pingId,
663
+ serverTimeMillis: Date.now()
664
+ });
665
+ break;
666
+ }
667
+ }
668
+ } catch (cause) {
669
+ const error = new Error(
670
+ `Error handling message: ${JSON.stringify(message)}`,
671
+ { cause }
672
+ );
673
+ _optionalChain([this, 'access', _140 => _140.log, 'call', _141 => _141(), 'optionalAccess', _142 => _142.error, 'call', _143 => _143(error)]);
674
+ }
675
+ }}
676
+ __init31() {this.onUpload = async (id, data) => {
677
+ const upload = this.uploads.get(id);
678
+ if (!upload) {
679
+ throw new Error(`No upload handler found for id: ${id}`);
680
+ }
681
+ await upload.handler(data);
682
+ this.uploads.delete(id);
683
+ }}
684
+ __init32() {this.onDownload = async (id) => {
685
+ const download = this.downloads.get(id);
686
+ if (!download) {
687
+ throw new Error(`No download handler found for id: ${id}`);
688
+ }
689
+ return download.handler;
690
+ }}
691
+ __init33() {this.sendNotification = (notification, filter) => {
692
+ for (const [connection, meta] of this.connections.entries()) {
693
+ if (!filter || filter(meta.publicConnection)) {
694
+ connection.sendMessage(notification);
569
695
  }
570
696
  }
571
697
  }}
@@ -583,4 +709,4 @@ var Toolkit = (_class2 = class {
583
709
 
584
710
 
585
711
 
586
- exports.Button = _chunk4AGKM5NTjs.Button; exports.Group = _chunkXSKWLJOQjs.Group; exports.GroupHeader = _chunkXSKWLJOQjs.GroupHeader; exports.Label = _chunkTF7N4O5Gjs.Label; exports.Rect = _chunk5B65Q7RLjs.Rect; exports.SliderButton = _chunkCVY55KARjs.SliderButton; exports.Switch = _chunk2K4UT5QBjs.Switch; exports.Tab = _chunkA3RWE7HZjs.Tab; exports.Tabs = _chunkA3RWE7HZjs.Tabs; exports.TextInput = _chunkIV3AE3CWjs.TextInput; exports.Timeline = _chunkUHEZQR2Qjs.Timeline; exports.Toolkit = Toolkit;
712
+ exports.Button = _chunkRELZ3VTJjs.Button; exports.Group = _chunkKRGLXKY2js.Group; exports.GroupHeader = _chunkKRGLXKY2js.GroupHeader; exports.Label = _chunkNEFCI6N6js.Label; exports.Rect = _chunkVTNAO4KCjs.Rect; exports.SliderButton = _chunkY5FC42KDjs.SliderButton; exports.Switch = _chunkAYMITMVRjs.Switch; exports.Tab = _chunkSPYBETRJjs.Tab; exports.Tabs = _chunkSPYBETRJjs.Tabs; exports.TextInput = _chunk2R23ER4Kjs.TextInput; exports.Timeline = _chunkQHCNKTKWjs.Timeline; exports.Toolkit = Toolkit;