@casualoffice/sheets 0.9.0 → 0.10.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 (67) hide show
  1. package/dist/api-BI2VLYQ6.d.cts +62 -0
  2. package/dist/api-BI2VLYQ6.d.ts +62 -0
  3. package/dist/chrome.cjs +2569 -0
  4. package/dist/chrome.cjs.map +1 -0
  5. package/dist/chrome.d.cts +96 -0
  6. package/dist/chrome.d.ts +96 -0
  7. package/dist/chrome.js +2556 -0
  8. package/dist/chrome.js.map +1 -0
  9. package/dist/collab.cjs +770 -0
  10. package/dist/collab.cjs.map +1 -0
  11. package/dist/collab.d.cts +248 -0
  12. package/dist/collab.d.ts +248 -0
  13. package/dist/collab.js +737 -0
  14. package/dist/collab.js.map +1 -0
  15. package/dist/embed/embed-runtime.js +128 -128
  16. package/dist/embed.cjs +166 -0
  17. package/dist/embed.cjs.map +1 -1
  18. package/dist/embed.d.cts +78 -3
  19. package/dist/embed.d.ts +78 -3
  20. package/dist/embed.js +166 -0
  21. package/dist/embed.js.map +1 -1
  22. package/dist/index.cjs +262 -165
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -3
  25. package/dist/index.d.ts +4 -3
  26. package/dist/index.js +271 -168
  27. package/dist/index.js.map +1 -1
  28. package/dist/{protocol--KyBQUjU.d.cts → protocol-Cq4Cdoyi.d.cts} +19 -2
  29. package/dist/{protocol-cEzy7S0i.d.ts → protocol-DqDaG2yG.d.ts} +19 -2
  30. package/dist/sheets.cjs +102 -16
  31. package/dist/sheets.cjs.map +1 -1
  32. package/dist/sheets.d.cts +49 -63
  33. package/dist/sheets.d.ts +49 -63
  34. package/dist/sheets.js +111 -19
  35. package/dist/sheets.js.map +1 -1
  36. package/package.json +28 -3
  37. package/src/chrome/AutoSumPicker.tsx +176 -0
  38. package/src/chrome/BordersPicker.tsx +171 -0
  39. package/src/chrome/ChromeBottom.tsx +18 -0
  40. package/src/chrome/ChromeTop.tsx +21 -0
  41. package/src/chrome/ColorPicker.tsx +220 -0
  42. package/src/chrome/FindReplace.tsx +370 -0
  43. package/src/chrome/FormulaBar.tsx +378 -0
  44. package/src/chrome/Icon.tsx +43 -0
  45. package/src/chrome/MenuBar.tsx +336 -0
  46. package/src/chrome/NameBox.tsx +347 -0
  47. package/src/chrome/SheetTabs.tsx +346 -0
  48. package/src/chrome/StatusBar.tsx +232 -0
  49. package/src/chrome/Toolbar.tsx +401 -0
  50. package/src/chrome/fonts.ts +42 -0
  51. package/src/chrome/index.ts +24 -0
  52. package/src/collab/attachCollab.ts +151 -0
  53. package/src/collab/bridge-helpers.ts +97 -0
  54. package/src/collab/bridge.ts +885 -0
  55. package/src/collab/bridge.unit.test.ts +160 -0
  56. package/src/collab/index.ts +38 -0
  57. package/src/collab/replay-retry.ts +137 -0
  58. package/src/collab/replay-retry.unit.test.ts +223 -0
  59. package/src/collab/ws-url.ts +20 -0
  60. package/src/collab/ws-url.unit.test.ts +35 -0
  61. package/src/embed/EmbedHostTransport.ts +16 -1
  62. package/src/embed/EmbedTransport.ts +16 -0
  63. package/src/embed/EmbedTransport.unit.test.ts +88 -2
  64. package/src/embed/index.ts +7 -0
  65. package/src/embed/protocol.ts +34 -0
  66. package/src/embed-runtime/index.tsx +20 -0
  67. package/src/sheets/CasualSheets.tsx +204 -33
package/dist/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
35
35
  CasualSheets: () => CasualSheets,
36
36
  CasualSheetsIframe: () => CasualSheetsIframe,
37
37
  DrawnSignaturePad: () => DrawnSignaturePad,
38
+ EmbedHostTransport: () => EmbedHostTransport,
38
39
  EmbedTransport: () => EmbedTransport,
39
40
  SigningPane: () => SigningPane,
40
41
  SigningProvider: () => SigningProvider,
@@ -775,6 +776,18 @@ var EmbedTransport = class {
775
776
  async requestSave(req, timeoutMs = 3e4) {
776
777
  return this.request("casual.save.request", req, timeoutMs, [req.bytes]);
777
778
  }
779
+ /** Editor → Host: the user asked to save (Ctrl/Cmd+S or a host save
780
+ * command). Fire-and-forget snapshot notification — the lightweight
781
+ * mirror of the React `onSave` hook. The host persists however it
782
+ * likes; no response is awaited. */
783
+ sendSaveNotify(data) {
784
+ this.post("casual.save.notify", data);
785
+ }
786
+ /** Editor → Host: the editor is unmounting. Carries the final snapshot
787
+ * so the host can persist on exit. Mirror of the React `onExit` hook. */
788
+ sendExit(data) {
789
+ this.post("casual.exit", data);
790
+ }
778
791
  /** Editor → Host: selection moved. Fire-and-forget. */
779
792
  sendSelectionChanged(data) {
780
793
  this.post("casual.selection.changed", data);
@@ -917,6 +930,159 @@ function newRequestId() {
917
930
  return Math.random().toString(16).slice(2, 10);
918
931
  }
919
932
 
933
+ // src/embed/EmbedHostTransport.ts
934
+ var EmbedHostTransport = class {
935
+ constructor(opts) {
936
+ __publicField(this, "opts");
937
+ __publicField(this, "handlers", {});
938
+ __publicField(this, "boundOnMessage");
939
+ __publicField(this, "destroyed", false);
940
+ this.opts = opts;
941
+ this.boundOnMessage = this.onMessage.bind(this);
942
+ const target = opts.hostWindow ?? window;
943
+ target.addEventListener("message", this.boundOnMessage);
944
+ }
945
+ on(handlers) {
946
+ this.handlers = { ...this.handlers, ...handlers };
947
+ }
948
+ destroy() {
949
+ if (this.destroyed) return;
950
+ this.destroyed = true;
951
+ const target = this.opts.hostWindow ?? window;
952
+ target.removeEventListener("message", this.boundOnMessage);
953
+ }
954
+ sendHostHello(data) {
955
+ this.post("casual.hello", data);
956
+ }
957
+ sendSetViewMode(data) {
958
+ this.post("casual.command.set.viewmode", data);
959
+ }
960
+ sendSetReadOnly(data) {
961
+ this.post("casual.command.set.readonly", data);
962
+ }
963
+ sendSetTheme(data) {
964
+ this.post("casual.command.set.theme", data);
965
+ }
966
+ sendSetLocale(data) {
967
+ this.post("casual.command.set.locale", data);
968
+ }
969
+ sendCommandSave() {
970
+ this.post("casual.command.save", null);
971
+ }
972
+ sendCommandFocus() {
973
+ this.post("casual.command.focus", null);
974
+ }
975
+ /** Host → Editor: run a formatting / navigation command (bold,
976
+ * italic, undo, …) against the active selection. v0.6+. */
977
+ sendCommandExecute(data) {
978
+ this.post("casual.command.execute", data);
979
+ }
980
+ sendSignatureRequest(id, data) {
981
+ this.post("casual.signature.request", data, id);
982
+ }
983
+ sendSignatureCancel(data) {
984
+ this.post("casual.signature.cancel", data);
985
+ }
986
+ onMessage(ev) {
987
+ if (this.destroyed) return;
988
+ if (ev.origin !== this.opts.embedOrigin) return;
989
+ if (ev.source !== this.opts.iframeWindow) return;
990
+ if (!isCasualEnvelope(ev.data)) return;
991
+ if (ev.data.app !== this.opts.app) return;
992
+ void this.dispatch(ev.data);
993
+ }
994
+ async dispatch(env) {
995
+ switch (env.type) {
996
+ case "casual.ready":
997
+ this.handlers.onEditorReady?.(env.data);
998
+ return;
999
+ case "casual.load.request": {
1000
+ if (!this.handlers.onLoadRequest) return;
1001
+ const id = env.id ?? "";
1002
+ try {
1003
+ const resp = await this.handlers.onLoadRequest(env.data);
1004
+ const transfer = resp.ok ? [resp.bytes] : [];
1005
+ this.post("casual.load.response", resp, id, transfer);
1006
+ } catch (err) {
1007
+ this.post(
1008
+ "casual.load.response",
1009
+ {
1010
+ ok: false,
1011
+ code: "host_error",
1012
+ message: err instanceof Error ? err.message : String(err)
1013
+ },
1014
+ id
1015
+ );
1016
+ }
1017
+ return;
1018
+ }
1019
+ case "casual.save.request": {
1020
+ if (!this.handlers.onSaveRequest) return;
1021
+ const id = env.id ?? "";
1022
+ try {
1023
+ const resp = await this.handlers.onSaveRequest(env.data);
1024
+ this.post("casual.save.response", resp, id);
1025
+ } catch (err) {
1026
+ this.post(
1027
+ "casual.save.response",
1028
+ {
1029
+ ok: false,
1030
+ code: "host_error",
1031
+ message: err instanceof Error ? err.message : String(err)
1032
+ },
1033
+ id
1034
+ );
1035
+ }
1036
+ return;
1037
+ }
1038
+ case "casual.save.notify":
1039
+ this.handlers.onSaveNotify?.(env.data);
1040
+ return;
1041
+ case "casual.exit":
1042
+ this.handlers.onExit?.(env.data);
1043
+ return;
1044
+ case "casual.selection.changed":
1045
+ this.handlers.onSelectionChanged?.(env.data);
1046
+ return;
1047
+ case "casual.selection.format-state":
1048
+ this.handlers.onSelectionFormatState?.(env.data);
1049
+ return;
1050
+ case "casual.telemetry.event":
1051
+ this.handlers.onTelemetry?.(env.data);
1052
+ return;
1053
+ case "casual.signature.field.signed":
1054
+ this.handlers.onSignatureFieldSigned?.(env.data);
1055
+ return;
1056
+ case "casual.signature.complete":
1057
+ this.handlers.onSignatureComplete?.(env.data);
1058
+ return;
1059
+ case "casual.signature.cancel":
1060
+ this.handlers.onSignatureCancel?.(env.data);
1061
+ return;
1062
+ case "casual.signature.request.ack":
1063
+ return;
1064
+ case "casual.error":
1065
+ this.handlers.onError?.(env.data);
1066
+ return;
1067
+ default:
1068
+ return;
1069
+ }
1070
+ }
1071
+ post(type, data, id, transfer) {
1072
+ const env = {
1073
+ type,
1074
+ app: this.opts.app,
1075
+ v: 1,
1076
+ data,
1077
+ ...id ? { id } : {}
1078
+ };
1079
+ const send = this.opts.iframeWindow.postMessage.bind(
1080
+ this.opts.iframeWindow
1081
+ );
1082
+ send(env, this.opts.embedOrigin, transfer);
1083
+ }
1084
+ };
1085
+
920
1086
  // src/sheets/CasualSheets.tsx
921
1087
  var import_react4 = require("react");
922
1088
  var import_core2 = require("@univerjs/core");
@@ -1147,6 +1313,12 @@ function snapshotHasHyperlinks(snapshot) {
1147
1313
 
1148
1314
  // src/sheets/CasualSheets.tsx
1149
1315
  var import_jsx_runtime4 = require("react/jsx-runtime");
1316
+ var ChromeTop = (0, import_react4.lazy)(
1317
+ () => import("@casualoffice/sheets/chrome").then((m) => ({ default: m.ChromeTop }))
1318
+ );
1319
+ var ChromeBottom = (0, import_react4.lazy)(
1320
+ () => import("@casualoffice/sheets/chrome").then((m) => ({ default: m.ChromeBottom }))
1321
+ );
1150
1322
  var DEFAULT_STYLE = {
1151
1323
  width: "100%",
1152
1324
  height: "100%",
@@ -1163,13 +1335,18 @@ function CasualSheets({
1163
1335
  onReady,
1164
1336
  onChange,
1165
1337
  onChangeDebounceMs = 400,
1338
+ onSave,
1339
+ onExit,
1166
1340
  lazyPlugins = true,
1341
+ onBeforeCreateUnit,
1342
+ formula,
1167
1343
  locale = import_core2.LocaleType.EN_US,
1168
1344
  locales,
1169
1345
  logLevel = import_core2.LogLevel.WARN,
1170
1346
  ui,
1171
1347
  theme = import_themes.defaultTheme,
1172
1348
  appearance = "light",
1349
+ chrome = "none",
1173
1350
  style,
1174
1351
  className,
1175
1352
  testId = "casual-sheets"
@@ -1178,7 +1355,12 @@ function CasualSheets({
1178
1355
  const onChangeRef = (0, import_react4.useRef)(onChange);
1179
1356
  onChangeRef.current = onChange;
1180
1357
  const hasOnChange = (0, import_react4.useRef)(!!onChange).current;
1358
+ const onSaveRef = (0, import_react4.useRef)(onSave);
1359
+ onSaveRef.current = onSave;
1360
+ const onExitRef = (0, import_react4.useRef)(onExit);
1361
+ onExitRef.current = onExit;
1181
1362
  const apiRef = (0, import_react4.useRef)(null);
1363
+ const [chromeApi, setChromeApi] = (0, import_react4.useState)(null);
1182
1364
  (0, import_react4.useEffect)(() => {
1183
1365
  const container = hostRef.current;
1184
1366
  if (!container) return;
@@ -1189,22 +1371,38 @@ function CasualSheets({
1189
1371
  logLevel
1190
1372
  });
1191
1373
  const uiOpts = { ...DEFAULT_UI, ...ui, container };
1192
- univer.registerPlugin(import_engine_render.UniverRenderEnginePlugin);
1193
- univer.registerPlugin(import_engine_formula.UniverFormulaEnginePlugin);
1194
- univer.registerPlugin(import_ui.UniverUIPlugin, uiOpts);
1195
- univer.registerPlugin(import_docs.UniverDocsPlugin);
1196
- univer.registerPlugin(import_docs_ui.UniverDocsUIPlugin);
1197
- univer.registerPlugin(import_sheets.UniverSheetsPlugin);
1198
- univer.registerPlugin(import_sheets_ui.UniverSheetsUIPlugin);
1199
- univer.registerPlugin(import_sheets_formula.UniverSheetsFormulaPlugin);
1200
- univer.registerPlugin(import_sheets_formula_ui.UniverSheetsFormulaUIPlugin);
1201
- univer.registerPlugin(import_sheets_numfmt.UniverSheetsNumfmtPlugin);
1202
- univer.registerPlugin(import_sheets_numfmt_ui.UniverSheetsNumfmtUIPlugin);
1203
- if (lazyPlugins) setUniverForLazyLoad(univer);
1374
+ const offMain = !!formula?.worker;
1204
1375
  let cancelled = false;
1205
1376
  let changeTimer = null;
1206
1377
  let changeSub;
1207
1378
  void (async () => {
1379
+ let RPCMainThreadPlugin = null;
1380
+ if (offMain && formula?.worker) {
1381
+ RPCMainThreadPlugin = (await import("@univerjs/rpc")).UniverRPCMainThreadPlugin;
1382
+ if (cancelled) return;
1383
+ }
1384
+ univer.registerPlugin(import_engine_render.UniverRenderEnginePlugin);
1385
+ univer.registerPlugin(
1386
+ import_engine_formula.UniverFormulaEnginePlugin,
1387
+ offMain ? { notExecuteFormula: true } : void 0
1388
+ );
1389
+ if (RPCMainThreadPlugin && formula?.worker) {
1390
+ univer.registerPlugin(RPCMainThreadPlugin, { workerURL: formula.worker });
1391
+ }
1392
+ univer.registerPlugin(import_ui.UniverUIPlugin, uiOpts);
1393
+ univer.registerPlugin(import_docs.UniverDocsPlugin);
1394
+ univer.registerPlugin(import_docs_ui.UniverDocsUIPlugin);
1395
+ univer.registerPlugin(import_sheets.UniverSheetsPlugin, offMain ? { notExecuteFormula: true } : void 0);
1396
+ univer.registerPlugin(import_sheets_ui.UniverSheetsUIPlugin);
1397
+ univer.registerPlugin(
1398
+ import_sheets_formula.UniverSheetsFormulaPlugin,
1399
+ offMain ? { notExecuteFormula: true, initialFormulaComputing: import_sheets_formula.CalculationMode.NO_CALCULATION } : void 0
1400
+ );
1401
+ univer.registerPlugin(import_sheets_formula_ui.UniverSheetsFormulaUIPlugin);
1402
+ univer.registerPlugin(import_sheets_numfmt.UniverSheetsNumfmtPlugin);
1403
+ univer.registerPlugin(import_sheets_numfmt_ui.UniverSheetsNumfmtUIPlugin);
1404
+ if (lazyPlugins) setUniverForLazyLoad(univer);
1405
+ onBeforeCreateUnit?.(univer);
1208
1406
  if (lazyPlugins) {
1209
1407
  await eagerLoadForSnapshot(univer, initialData);
1210
1408
  if (cancelled) return;
@@ -1212,6 +1410,7 @@ function CasualSheets({
1212
1410
  univer.createUnit(import_core2.UniverInstanceType.UNIVER_SHEET, initialData);
1213
1411
  const api = createCasualSheetsAPI(import_facade2.FUniver.newAPI(univer));
1214
1412
  apiRef.current = api;
1413
+ if (!cancelled && chrome !== "none") setChromeApi(api);
1215
1414
  applyAppearance(api, container, appearance);
1216
1415
  onReady?.(api);
1217
1416
  if (hasOnChange) {
@@ -1232,7 +1431,12 @@ function CasualSheets({
1232
1431
  cancelled = true;
1233
1432
  if (changeTimer) clearTimeout(changeTimer);
1234
1433
  changeSub?.dispose();
1434
+ if (onExitRef.current) {
1435
+ const snap = apiRef.current?.getSnapshot();
1436
+ if (snap) onExitRef.current(snap);
1437
+ }
1235
1438
  apiRef.current = null;
1439
+ setChromeApi(null);
1236
1440
  if (lazyPlugins) setUniverForLazyLoad(null);
1237
1441
  const toDispose = univer;
1238
1442
  queueMicrotask(() => toDispose.dispose());
@@ -1244,13 +1448,55 @@ function CasualSheets({
1244
1448
  if (!api || !container) return;
1245
1449
  applyAppearance(api, container, appearance);
1246
1450
  }, [appearance]);
1247
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1451
+ const onKeyDownCapture = (e) => {
1452
+ if ((e.metaKey || e.ctrlKey) && (e.key === "s" || e.key === "S")) {
1453
+ e.preventDefault();
1454
+ const snap = apiRef.current?.getSnapshot();
1455
+ if (snap) onSaveRef.current?.(snap);
1456
+ }
1457
+ };
1458
+ if (chrome === "none") {
1459
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1460
+ "div",
1461
+ {
1462
+ ref: hostRef,
1463
+ onKeyDownCapture,
1464
+ style: { ...DEFAULT_STYLE, ...style },
1465
+ className,
1466
+ "data-testid": testId
1467
+ }
1468
+ );
1469
+ }
1470
+ const dark = appearance === "dark";
1471
+ const chromeVars = {
1472
+ "--cs-chrome-bg": dark ? "#2a2e35" : "#eef1f5",
1473
+ "--cs-chrome-fg": dark ? "#e6e6e6" : "#201f1e",
1474
+ "--cs-chrome-muted": dark ? "#b0b3ba" : "#605e5c",
1475
+ "--cs-chrome-border": dark ? "#32363d" : "#e6e9ee",
1476
+ "--cs-chrome-input-bg": dark ? "#23262c" : "#ffffff",
1477
+ "--cs-chrome-hover": dark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.06)",
1478
+ // accent (design-system #0e7490) for active toggle states.
1479
+ "--cs-chrome-active": dark ? "rgba(21,151,186,0.22)" : "#e6f3f7",
1480
+ "--cs-chrome-active-fg": dark ? "#7fd3e6" : "#0e7490"
1481
+ };
1482
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1248
1483
  "div",
1249
1484
  {
1250
- ref: hostRef,
1251
- style: { ...DEFAULT_STYLE, ...style },
1252
1485
  className,
1253
- "data-testid": testId
1486
+ "data-testid": testId,
1487
+ onKeyDownCapture,
1488
+ style: {
1489
+ ...DEFAULT_STYLE,
1490
+ ...chromeVars,
1491
+ ...style,
1492
+ display: "flex",
1493
+ flexDirection: "column"
1494
+ },
1495
+ children: [
1496
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChromeTop, { api: chromeApi }) }),
1497
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { ref: hostRef, style: { flex: "1 1 auto", minHeight: 0, position: "relative" } }),
1498
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChromeBottom, { api: chromeApi }) })
1499
+ ]
1254
1500
  }
1255
1501
  );
1256
1502
  }
@@ -1267,155 +1513,6 @@ function applyAppearance(api, container, appearance) {
1267
1513
 
1268
1514
  // src/sheets/CasualSheetsIframe.tsx
1269
1515
  var import_react5 = require("react");
1270
-
1271
- // src/embed/EmbedHostTransport.ts
1272
- var EmbedHostTransport = class {
1273
- constructor(opts) {
1274
- __publicField(this, "opts");
1275
- __publicField(this, "handlers", {});
1276
- __publicField(this, "boundOnMessage");
1277
- __publicField(this, "destroyed", false);
1278
- this.opts = opts;
1279
- this.boundOnMessage = this.onMessage.bind(this);
1280
- const target = opts.hostWindow ?? window;
1281
- target.addEventListener("message", this.boundOnMessage);
1282
- }
1283
- on(handlers) {
1284
- this.handlers = { ...this.handlers, ...handlers };
1285
- }
1286
- destroy() {
1287
- if (this.destroyed) return;
1288
- this.destroyed = true;
1289
- const target = this.opts.hostWindow ?? window;
1290
- target.removeEventListener("message", this.boundOnMessage);
1291
- }
1292
- sendHostHello(data) {
1293
- this.post("casual.hello", data);
1294
- }
1295
- sendSetViewMode(data) {
1296
- this.post("casual.command.set.viewmode", data);
1297
- }
1298
- sendSetReadOnly(data) {
1299
- this.post("casual.command.set.readonly", data);
1300
- }
1301
- sendSetTheme(data) {
1302
- this.post("casual.command.set.theme", data);
1303
- }
1304
- sendSetLocale(data) {
1305
- this.post("casual.command.set.locale", data);
1306
- }
1307
- sendCommandSave() {
1308
- this.post("casual.command.save", null);
1309
- }
1310
- sendCommandFocus() {
1311
- this.post("casual.command.focus", null);
1312
- }
1313
- /** Host → Editor: run a formatting / navigation command (bold,
1314
- * italic, undo, …) against the active selection. v0.6+. */
1315
- sendCommandExecute(data) {
1316
- this.post("casual.command.execute", data);
1317
- }
1318
- sendSignatureRequest(id, data) {
1319
- this.post("casual.signature.request", data, id);
1320
- }
1321
- sendSignatureCancel(data) {
1322
- this.post("casual.signature.cancel", data);
1323
- }
1324
- onMessage(ev) {
1325
- if (this.destroyed) return;
1326
- if (ev.origin !== this.opts.embedOrigin) return;
1327
- if (ev.source !== this.opts.iframeWindow) return;
1328
- if (!isCasualEnvelope(ev.data)) return;
1329
- if (ev.data.app !== this.opts.app) return;
1330
- void this.dispatch(ev.data);
1331
- }
1332
- async dispatch(env) {
1333
- switch (env.type) {
1334
- case "casual.ready":
1335
- this.handlers.onEditorReady?.(env.data);
1336
- return;
1337
- case "casual.load.request": {
1338
- if (!this.handlers.onLoadRequest) return;
1339
- const id = env.id ?? "";
1340
- try {
1341
- const resp = await this.handlers.onLoadRequest(env.data);
1342
- const transfer = resp.ok ? [resp.bytes] : [];
1343
- this.post("casual.load.response", resp, id, transfer);
1344
- } catch (err) {
1345
- this.post(
1346
- "casual.load.response",
1347
- {
1348
- ok: false,
1349
- code: "host_error",
1350
- message: err instanceof Error ? err.message : String(err)
1351
- },
1352
- id
1353
- );
1354
- }
1355
- return;
1356
- }
1357
- case "casual.save.request": {
1358
- if (!this.handlers.onSaveRequest) return;
1359
- const id = env.id ?? "";
1360
- try {
1361
- const resp = await this.handlers.onSaveRequest(env.data);
1362
- this.post("casual.save.response", resp, id);
1363
- } catch (err) {
1364
- this.post(
1365
- "casual.save.response",
1366
- {
1367
- ok: false,
1368
- code: "host_error",
1369
- message: err instanceof Error ? err.message : String(err)
1370
- },
1371
- id
1372
- );
1373
- }
1374
- return;
1375
- }
1376
- case "casual.selection.changed":
1377
- this.handlers.onSelectionChanged?.(env.data);
1378
- return;
1379
- case "casual.selection.format-state":
1380
- this.handlers.onSelectionFormatState?.(env.data);
1381
- return;
1382
- case "casual.telemetry.event":
1383
- this.handlers.onTelemetry?.(env.data);
1384
- return;
1385
- case "casual.signature.field.signed":
1386
- this.handlers.onSignatureFieldSigned?.(env.data);
1387
- return;
1388
- case "casual.signature.complete":
1389
- this.handlers.onSignatureComplete?.(env.data);
1390
- return;
1391
- case "casual.signature.cancel":
1392
- this.handlers.onSignatureCancel?.(env.data);
1393
- return;
1394
- case "casual.signature.request.ack":
1395
- return;
1396
- case "casual.error":
1397
- this.handlers.onError?.(env.data);
1398
- return;
1399
- default:
1400
- return;
1401
- }
1402
- }
1403
- post(type, data, id, transfer) {
1404
- const env = {
1405
- type,
1406
- app: this.opts.app,
1407
- v: 1,
1408
- data,
1409
- ...id ? { id } : {}
1410
- };
1411
- const send = this.opts.iframeWindow.postMessage.bind(
1412
- this.opts.iframeWindow
1413
- );
1414
- send(env, this.opts.embedOrigin, transfer);
1415
- }
1416
- };
1417
-
1418
- // src/sheets/CasualSheetsIframe.tsx
1419
1516
  var import_jsx_runtime5 = require("react/jsx-runtime");
1420
1517
  var DEFAULT_STYLE2 = {
1421
1518
  width: "100%",