@arcanejs/toolkit 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +183 -64
  68. package/dist/index.mjs +154 -35
  69. package/dist/{toolkit-Bglbv3ix.d.ts → toolkit-CKA9A4r-.d.ts} +116 -93
  70. package/dist/{toolkit-BPqxbDbk.d.mts → toolkit-GNytD78y.d.mts} +116 -93
  71. package/package.json +8 -8
@@ -37,6 +37,19 @@ var Stage = ({ className, renderers, loadingState }) => {
37
37
  nextId: 1,
38
38
  pings: /* @__PURE__ */ new Map()
39
39
  });
40
+ const notificationListeners = _react.useRef.call(void 0, /* @__PURE__ */ new Set());
41
+ const addNotificationListener = _react.useCallback.call(void 0,
42
+ (listener) => {
43
+ notificationListeners.current.add(listener);
44
+ },
45
+ []
46
+ );
47
+ const removeNotificationListener = _react.useCallback.call(void 0,
48
+ (listener) => {
49
+ notificationListeners.current.delete(listener);
50
+ },
51
+ []
52
+ );
40
53
  const preparedRenderers = _react.useMemo.call(void 0, () => {
41
54
  const prepared = {};
42
55
  for (const renderer of renderers) {
@@ -82,6 +95,12 @@ var Stage = ({ className, renderers, loadingState }) => {
82
95
  }
83
96
  return;
84
97
  }
98
+ case "notification": {
99
+ for (const listener of notificationListeners.current) {
100
+ listener(msg);
101
+ }
102
+ return;
103
+ }
85
104
  case "pong": {
86
105
  const ping = pings.current.pings.get(msg.pingId);
87
106
  if (!ping) {
@@ -149,28 +168,62 @@ var Stage = ({ className, renderers, loadingState }) => {
149
168
  const sendMessage = _react.useCallback.call(void 0, async (msg) => {
150
169
  (await (socket.current || initializeWebsocket())).send(JSON.stringify(msg));
151
170
  }, []);
152
- const call = _react.useCallback.call(void 0,
171
+ const callHandler = _react.useCallback.call(void 0,
153
172
  async (msg) => {
154
173
  const requestId = calls.current.nextId++;
155
174
  const sendMsg = {
156
175
  ...msg,
157
176
  requestId
158
177
  };
159
- const promise = new Promise(
160
- (resolve, reject) => {
161
- calls.current.calls.set(requestId, {
162
- resolve,
163
- reject
164
- });
165
- (socket.current || initializeWebsocket()).then(
166
- (s) => s.send(JSON.stringify(sendMsg))
167
- );
168
- }
169
- );
178
+ const promise = new Promise((resolve, reject) => {
179
+ calls.current.calls.set(requestId, {
180
+ resolve,
181
+ reject
182
+ });
183
+ (socket.current || initializeWebsocket()).then(
184
+ (s) => s.send(JSON.stringify(sendMsg))
185
+ );
186
+ });
170
187
  return promise;
171
188
  },
172
189
  []
173
190
  );
191
+ const call = _react.useCallback.call(void 0,
192
+ async (msg) => callHandler(msg),
193
+ []
194
+ );
195
+ const upload = _react.useCallback.call(void 0,
196
+ async (msg, data) => {
197
+ const uploadId = await callHandler(msg);
198
+ const uploadUrl = new URL(`upload/${uploadId}`, window.location.href);
199
+ const result = await fetch(uploadUrl.href, {
200
+ method: "POST",
201
+ body: data
202
+ });
203
+ if (!result.ok) {
204
+ throw new Error(`Upload failed with status ${result.status}`);
205
+ }
206
+ },
207
+ []
208
+ );
209
+ const download = _react.useCallback.call(void 0,
210
+ async (msg) => {
211
+ const downloadId = await callHandler(msg);
212
+ const downloadUrl = new URL(
213
+ `download/${downloadId}`,
214
+ window.location.href
215
+ );
216
+ const result = await fetch(downloadUrl.href);
217
+ if (!result.ok) {
218
+ throw new Error(`Download failed with status ${result.status}`);
219
+ }
220
+ if (!result.body) {
221
+ throw new Error("Download response has no body");
222
+ }
223
+ return result.body;
224
+ },
225
+ []
226
+ );
174
227
  _react.useEffect.call(void 0, () => {
175
228
  initializeWebsocket();
176
229
  }, [initializeWebsocket]);
@@ -209,6 +262,10 @@ var Stage = ({ className, renderers, loadingState }) => {
209
262
  sendMessage,
210
263
  renderComponent,
211
264
  call,
265
+ upload,
266
+ download,
267
+ addNotificationListener,
268
+ removeNotificationListener,
212
269
  connectionUuid: connection.state === "connected" ? connection.uuid : null,
213
270
  connection,
214
271
  timeDifferenceMs: _nullishCoalesce(_optionalChain([bestPing, 'optionalAccess', _ => _.timeDifferenceMs]), () => ( null)),
@@ -37,6 +37,19 @@ var Stage = ({ className, renderers, loadingState }) => {
37
37
  nextId: 1,
38
38
  pings: /* @__PURE__ */ new Map()
39
39
  });
40
+ const notificationListeners = useRef(/* @__PURE__ */ new Set());
41
+ const addNotificationListener = useCallback(
42
+ (listener) => {
43
+ notificationListeners.current.add(listener);
44
+ },
45
+ []
46
+ );
47
+ const removeNotificationListener = useCallback(
48
+ (listener) => {
49
+ notificationListeners.current.delete(listener);
50
+ },
51
+ []
52
+ );
40
53
  const preparedRenderers = useMemo(() => {
41
54
  const prepared = {};
42
55
  for (const renderer of renderers) {
@@ -82,6 +95,12 @@ var Stage = ({ className, renderers, loadingState }) => {
82
95
  }
83
96
  return;
84
97
  }
98
+ case "notification": {
99
+ for (const listener of notificationListeners.current) {
100
+ listener(msg);
101
+ }
102
+ return;
103
+ }
85
104
  case "pong": {
86
105
  const ping = pings.current.pings.get(msg.pingId);
87
106
  if (!ping) {
@@ -149,28 +168,62 @@ var Stage = ({ className, renderers, loadingState }) => {
149
168
  const sendMessage = useCallback(async (msg) => {
150
169
  (await (socket.current || initializeWebsocket())).send(JSON.stringify(msg));
151
170
  }, []);
152
- const call = useCallback(
171
+ const callHandler = useCallback(
153
172
  async (msg) => {
154
173
  const requestId = calls.current.nextId++;
155
174
  const sendMsg = {
156
175
  ...msg,
157
176
  requestId
158
177
  };
159
- const promise = new Promise(
160
- (resolve, reject) => {
161
- calls.current.calls.set(requestId, {
162
- resolve,
163
- reject
164
- });
165
- (socket.current || initializeWebsocket()).then(
166
- (s) => s.send(JSON.stringify(sendMsg))
167
- );
168
- }
169
- );
178
+ const promise = new Promise((resolve, reject) => {
179
+ calls.current.calls.set(requestId, {
180
+ resolve,
181
+ reject
182
+ });
183
+ (socket.current || initializeWebsocket()).then(
184
+ (s) => s.send(JSON.stringify(sendMsg))
185
+ );
186
+ });
170
187
  return promise;
171
188
  },
172
189
  []
173
190
  );
191
+ const call = useCallback(
192
+ async (msg) => callHandler(msg),
193
+ []
194
+ );
195
+ const upload = useCallback(
196
+ async (msg, data) => {
197
+ const uploadId = await callHandler(msg);
198
+ const uploadUrl = new URL(`upload/${uploadId}`, window.location.href);
199
+ const result = await fetch(uploadUrl.href, {
200
+ method: "POST",
201
+ body: data
202
+ });
203
+ if (!result.ok) {
204
+ throw new Error(`Upload failed with status ${result.status}`);
205
+ }
206
+ },
207
+ []
208
+ );
209
+ const download = useCallback(
210
+ async (msg) => {
211
+ const downloadId = await callHandler(msg);
212
+ const downloadUrl = new URL(
213
+ `download/${downloadId}`,
214
+ window.location.href
215
+ );
216
+ const result = await fetch(downloadUrl.href);
217
+ if (!result.ok) {
218
+ throw new Error(`Download failed with status ${result.status}`);
219
+ }
220
+ if (!result.body) {
221
+ throw new Error("Download response has no body");
222
+ }
223
+ return result.body;
224
+ },
225
+ []
226
+ );
174
227
  useEffect(() => {
175
228
  initializeWebsocket();
176
229
  }, [initializeWebsocket]);
@@ -209,6 +262,10 @@ var Stage = ({ className, renderers, loadingState }) => {
209
262
  sendMessage,
210
263
  renderComponent,
211
264
  call,
265
+ upload,
266
+ download,
267
+ addNotificationListener,
268
+ removeNotificationListener,
212
269
  connectionUuid: connection.state === "connected" ? connection.uuid : null,
213
270
  connection,
214
271
  timeDifferenceMs: bestPing?.timeDifferenceMs ?? null,
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyComponent, B as Button, G as Group, l as GroupHeader, T as Toolkit, e as ToolkitAdditionalFiles, f as ToolkitClockSyncOptions, a as ToolkitConnection, g as ToolkitCoreAssetRelativePath, h as ToolkitHtmlPageContext, i as ToolkitOptions, b as ToolkitRenderContext, d as ToolkitServerListener, c as ToolkitServerListenerOptions, j as ToolkitStaticFile, k as ToolkitStaticFileResolver } from './toolkit-BPqxbDbk.mjs';
1
+ export { A as AnyComponent, B as Button, G as Group, l as GroupHeader, T as Toolkit, e as ToolkitAdditionalFiles, f as ToolkitClockSyncOptions, a as ToolkitConnection, g as ToolkitCoreAssetRelativePath, h as ToolkitHtmlPageContext, i as ToolkitOptions, b as ToolkitRenderContext, d as ToolkitServerListener, c as ToolkitServerListenerOptions, j as ToolkitStaticFile, k as ToolkitStaticFileResolver } from './toolkit-GNytD78y.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';
@@ -12,6 +12,7 @@ import 'http';
12
12
  import 'express';
13
13
  import 'ws';
14
14
  import '@arcanejs/protocol';
15
+ import 'node:stream';
16
+ import './id-map-DxQ3_gyA.mjs';
15
17
  import '@arcanejs/protocol/core';
16
18
  import '@arcanejs/protocol/styles';
17
- import './id-map-DxQ3_gyA.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyComponent, B as Button, G as Group, l as GroupHeader, T as Toolkit, e as ToolkitAdditionalFiles, f as ToolkitClockSyncOptions, a as ToolkitConnection, g as ToolkitCoreAssetRelativePath, h as ToolkitHtmlPageContext, i as ToolkitOptions, b as ToolkitRenderContext, d as ToolkitServerListener, c as ToolkitServerListenerOptions, j as ToolkitStaticFile, k as ToolkitStaticFileResolver } from './toolkit-Bglbv3ix.js';
1
+ export { A as AnyComponent, B as Button, G as Group, l as GroupHeader, T as Toolkit, e as ToolkitAdditionalFiles, f as ToolkitClockSyncOptions, a as ToolkitConnection, g as ToolkitCoreAssetRelativePath, h as ToolkitHtmlPageContext, i as ToolkitOptions, b as ToolkitRenderContext, d as ToolkitServerListener, c as ToolkitServerListenerOptions, j as ToolkitStaticFile, k as ToolkitStaticFileResolver } from './toolkit-CKA9A4r-.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';
@@ -12,6 +12,7 @@ import 'http';
12
12
  import 'express';
13
13
  import 'ws';
14
14
  import '@arcanejs/protocol';
15
+ import 'node:stream';
16
+ import './id-map-DxQ3_gyA.js';
15
17
  import '@arcanejs/protocol/core';
16
18
  import '@arcanejs/protocol/styles';
17
- import './id-map-DxQ3_gyA.js';