@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/embed.js CHANGED
@@ -56,6 +56,18 @@ var EmbedTransport = class {
56
56
  async requestSave(req, timeoutMs = 3e4) {
57
57
  return this.request("casual.save.request", req, timeoutMs, [req.bytes]);
58
58
  }
59
+ /** Editor → Host: the user asked to save (Ctrl/Cmd+S or a host save
60
+ * command). Fire-and-forget snapshot notification — the lightweight
61
+ * mirror of the React `onSave` hook. The host persists however it
62
+ * likes; no response is awaited. */
63
+ sendSaveNotify(data) {
64
+ this.post("casual.save.notify", data);
65
+ }
66
+ /** Editor → Host: the editor is unmounting. Carries the final snapshot
67
+ * so the host can persist on exit. Mirror of the React `onExit` hook. */
68
+ sendExit(data) {
69
+ this.post("casual.exit", data);
70
+ }
59
71
  /** Editor → Host: selection moved. Fire-and-forget. */
60
72
  sendSelectionChanged(data) {
61
73
  this.post("casual.selection.changed", data);
@@ -197,7 +209,161 @@ var EmbedTransport = class {
197
209
  function newRequestId() {
198
210
  return Math.random().toString(16).slice(2, 10);
199
211
  }
212
+
213
+ // src/embed/EmbedHostTransport.ts
214
+ var EmbedHostTransport = class {
215
+ constructor(opts) {
216
+ __publicField(this, "opts");
217
+ __publicField(this, "handlers", {});
218
+ __publicField(this, "boundOnMessage");
219
+ __publicField(this, "destroyed", false);
220
+ this.opts = opts;
221
+ this.boundOnMessage = this.onMessage.bind(this);
222
+ const target = opts.hostWindow ?? window;
223
+ target.addEventListener("message", this.boundOnMessage);
224
+ }
225
+ on(handlers) {
226
+ this.handlers = { ...this.handlers, ...handlers };
227
+ }
228
+ destroy() {
229
+ if (this.destroyed) return;
230
+ this.destroyed = true;
231
+ const target = this.opts.hostWindow ?? window;
232
+ target.removeEventListener("message", this.boundOnMessage);
233
+ }
234
+ sendHostHello(data) {
235
+ this.post("casual.hello", data);
236
+ }
237
+ sendSetViewMode(data) {
238
+ this.post("casual.command.set.viewmode", data);
239
+ }
240
+ sendSetReadOnly(data) {
241
+ this.post("casual.command.set.readonly", data);
242
+ }
243
+ sendSetTheme(data) {
244
+ this.post("casual.command.set.theme", data);
245
+ }
246
+ sendSetLocale(data) {
247
+ this.post("casual.command.set.locale", data);
248
+ }
249
+ sendCommandSave() {
250
+ this.post("casual.command.save", null);
251
+ }
252
+ sendCommandFocus() {
253
+ this.post("casual.command.focus", null);
254
+ }
255
+ /** Host → Editor: run a formatting / navigation command (bold,
256
+ * italic, undo, …) against the active selection. v0.6+. */
257
+ sendCommandExecute(data) {
258
+ this.post("casual.command.execute", data);
259
+ }
260
+ sendSignatureRequest(id, data) {
261
+ this.post("casual.signature.request", data, id);
262
+ }
263
+ sendSignatureCancel(data) {
264
+ this.post("casual.signature.cancel", data);
265
+ }
266
+ onMessage(ev) {
267
+ if (this.destroyed) return;
268
+ if (ev.origin !== this.opts.embedOrigin) return;
269
+ if (ev.source !== this.opts.iframeWindow) return;
270
+ if (!isCasualEnvelope(ev.data)) return;
271
+ if (ev.data.app !== this.opts.app) return;
272
+ void this.dispatch(ev.data);
273
+ }
274
+ async dispatch(env) {
275
+ switch (env.type) {
276
+ case "casual.ready":
277
+ this.handlers.onEditorReady?.(env.data);
278
+ return;
279
+ case "casual.load.request": {
280
+ if (!this.handlers.onLoadRequest) return;
281
+ const id = env.id ?? "";
282
+ try {
283
+ const resp = await this.handlers.onLoadRequest(env.data);
284
+ const transfer = resp.ok ? [resp.bytes] : [];
285
+ this.post("casual.load.response", resp, id, transfer);
286
+ } catch (err) {
287
+ this.post(
288
+ "casual.load.response",
289
+ {
290
+ ok: false,
291
+ code: "host_error",
292
+ message: err instanceof Error ? err.message : String(err)
293
+ },
294
+ id
295
+ );
296
+ }
297
+ return;
298
+ }
299
+ case "casual.save.request": {
300
+ if (!this.handlers.onSaveRequest) return;
301
+ const id = env.id ?? "";
302
+ try {
303
+ const resp = await this.handlers.onSaveRequest(env.data);
304
+ this.post("casual.save.response", resp, id);
305
+ } catch (err) {
306
+ this.post(
307
+ "casual.save.response",
308
+ {
309
+ ok: false,
310
+ code: "host_error",
311
+ message: err instanceof Error ? err.message : String(err)
312
+ },
313
+ id
314
+ );
315
+ }
316
+ return;
317
+ }
318
+ case "casual.save.notify":
319
+ this.handlers.onSaveNotify?.(env.data);
320
+ return;
321
+ case "casual.exit":
322
+ this.handlers.onExit?.(env.data);
323
+ return;
324
+ case "casual.selection.changed":
325
+ this.handlers.onSelectionChanged?.(env.data);
326
+ return;
327
+ case "casual.selection.format-state":
328
+ this.handlers.onSelectionFormatState?.(env.data);
329
+ return;
330
+ case "casual.telemetry.event":
331
+ this.handlers.onTelemetry?.(env.data);
332
+ return;
333
+ case "casual.signature.field.signed":
334
+ this.handlers.onSignatureFieldSigned?.(env.data);
335
+ return;
336
+ case "casual.signature.complete":
337
+ this.handlers.onSignatureComplete?.(env.data);
338
+ return;
339
+ case "casual.signature.cancel":
340
+ this.handlers.onSignatureCancel?.(env.data);
341
+ return;
342
+ case "casual.signature.request.ack":
343
+ return;
344
+ case "casual.error":
345
+ this.handlers.onError?.(env.data);
346
+ return;
347
+ default:
348
+ return;
349
+ }
350
+ }
351
+ post(type, data, id, transfer) {
352
+ const env = {
353
+ type,
354
+ app: this.opts.app,
355
+ v: 1,
356
+ data,
357
+ ...id ? { id } : {}
358
+ };
359
+ const send = this.opts.iframeWindow.postMessage.bind(
360
+ this.opts.iframeWindow
361
+ );
362
+ send(env, this.opts.embedOrigin, transfer);
363
+ }
364
+ };
200
365
  export {
366
+ EmbedHostTransport,
201
367
  EmbedTransport,
202
368
  isCasualEnvelope
203
369
  };
package/dist/embed.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/embed/protocol.ts","../src/embed/EmbedTransport.ts"],"sourcesContent":["/**\n * Iframe protocol — wire envelopes that match\n * `docs/internal/13-iframe-protocol.md`.\n *\n * Mirror updates to the doc whenever a new envelope shape lands.\n * The discriminator on `type` (always starts with `casual.`) and\n * the per-envelope `data` shape are the contract.\n */\n\nimport type {\n CancelReason,\n SignatureCompletePayload,\n SignatureField,\n SignatureMode,\n SignedFieldPayload,\n} from '../signing/types';\n\nexport type CasualApp = 'docs' | 'sheet';\n\n/** Common envelope shape — every postMessage on the wire matches this. */\nexport interface CasualEnvelope<T = unknown> {\n type: string;\n app: CasualApp;\n /** Per-request id for request/response correlation. Empty for fire-and-forget. */\n id?: string;\n /** Protocol version. Bumped only on breaking changes. */\n v: 1;\n data: T;\n}\n\n// ---------------------------------------------------------------\n// Handshake\n// ---------------------------------------------------------------\n\nexport interface EditorHelloData {\n capabilities: string[];\n version: string;\n commit: string;\n}\n\nexport interface HostHelloData {\n capabilities: string[];\n authToken?: string;\n}\n\n// ---------------------------------------------------------------\n// Load + save (editor → host requests; host → editor responses)\n// ---------------------------------------------------------------\n\nexport interface LoadRequestData {\n docId: string;\n}\n\nexport interface LoadResponseDataOk {\n ok: true;\n bytes: ArrayBuffer;\n etag?: string;\n fileName: string;\n readOnly?: boolean;\n}\n\nexport interface LoadResponseDataErr {\n ok: false;\n code: string;\n message?: string;\n}\n\nexport type LoadResponseData = LoadResponseDataOk | LoadResponseDataErr;\n\nexport interface SaveRequestData {\n docId: string;\n bytes: ArrayBuffer;\n baseEtag?: string;\n}\n\nexport interface SaveResponseDataOk {\n ok: true;\n etag: string;\n}\n\nexport interface SaveResponseDataErr {\n ok: false;\n code: string;\n etag?: string;\n message?: string;\n}\n\nexport type SaveResponseData = SaveResponseDataOk | SaveResponseDataErr;\n\n// ---------------------------------------------------------------\n// Selection + telemetry + lock (editor → host notifications)\n// ---------------------------------------------------------------\n\nexport interface SelectionChangedData {\n docs?: { paraId: string; from: number; to: number; selectedText: string };\n sheet?: { sheet: string; from: string; to: string };\n}\n\nexport interface TelemetryEventData {\n kind: string;\n /** Arbitrary metric fields. */\n [k: string]: unknown;\n}\n\nexport interface LockLostData {\n reason: 'taken_by_other' | 'expired' | 'host_revoked';\n}\n\n// ---------------------------------------------------------------\n// Commands (host → editor)\n// ---------------------------------------------------------------\n\nexport interface CommandSetReadOnlyData {\n readOnly: boolean;\n}\n\nexport interface CommandSetThemeData {\n theme: 'light' | 'dark' | 'system';\n}\n\nexport interface CommandSetLocaleData {\n locale: string;\n}\n\n/** Host → editor: switch chrome density between the two consumer-facing\n * modes without re-mounting. `preview` hides toolbar / formula bar /\n * side panel / status bar / sheet tabs and runs read-only; `editor`\n * shows the full UI. Mirrors the `viewMode` prop on `<CasualSheetsIframe>`. */\nexport interface CommandSetViewModeData {\n viewMode: 'preview' | 'editor';\n}\n\n/** Host → editor: execute a formatting / navigation command against\n * the active selection in the embedded workbook. Hosts (like Casual\n * Drive) build their own toolbar above the iframe and dispatch these\n * commands instead of Univer's built-in ribbon, which the SDK can't\n * ship because the ribbon resolves IRPCChannelService at construction\n * and that service needs a worker the SDK doesn't bundle.\n *\n * v0.6 covered the toggle set; v0.7 adds the rich-format set (font,\n * size, colour, fill) + merge / unmerge. Arg-carrying commands read\n * the relevant field off `args` — every other command ignores it. */\nexport interface CommandExecuteData {\n command: // v0.6 — toggle / nav (no args)\n | 'undo'\n | 'redo'\n | 'bold'\n | 'italic'\n | 'underline'\n | 'strikethrough'\n | 'align-left'\n | 'align-center'\n | 'align-right'\n // v0.7 — rich format (args carry the value)\n | 'set-font-family'\n | 'set-font-size'\n | 'set-text-color'\n | 'reset-text-color'\n | 'set-bg-color'\n | 'reset-bg-color'\n | 'merge'\n | 'unmerge'\n // v0.8 — number formats + freeze + wrap\n | 'numfmt-currency'\n | 'numfmt-percent'\n | 'numfmt-add-decimal'\n | 'numfmt-subtract-decimal'\n | 'numfmt-custom'\n | 'wrap-toggle'\n | 'freeze-first-row'\n | 'freeze-first-column'\n | 'freeze-none';\n args?: {\n /** Used by `set-font-family`. */\n family?: string;\n /** Used by `set-font-size`. Integer point size. */\n size?: number;\n /** Used by `set-text-color` and `set-bg-color`. Hex like `#1a73e8`. */\n color?: string;\n /** Used by `numfmt-custom`. The Excel-style format string, e.g.\n * `\"#,##0.00\"`, `\"$#,##0\"`, `\"0.00%\"`, `\"d-mmm-yy\"`. v0.8+. */\n pattern?: string;\n };\n}\n\n/** Editor → host: emitted whenever the selection's active cell's\n * format flags change. Drive's toolbar mirrors this state in the\n * button \"pressed\" / value indicators so the surface always reflects\n * what the user would see in the cell. v0.7 widens the payload with\n * the rich-format read-back (fontFamily, fontSize, textColor, bgColor)\n * so the toolbar's font picker / size stepper / colour swatches stay\n * in sync without the host having to poll. */\nexport interface SelectionFormatStateData {\n bold: boolean;\n italic: boolean;\n underline: boolean;\n strikethrough: boolean;\n align: 'left' | 'center' | 'right' | null;\n /** Defined font family on the active cell, or null when the cell\n * inherits the workbook default. v0.7+. */\n fontFamily: string | null;\n /** Defined font size on the active cell, or null when the cell\n * inherits the workbook default. v0.7+. */\n fontSize: number | null;\n /** Hex text colour like `#1a73e8`, or null when default. v0.7+. */\n textColor: string | null;\n /** Hex background colour, or null when no fill is set. v0.7+. */\n bgColor: string | null;\n}\n\n// ---------------------------------------------------------------\n// Errors (editor → host fatal signals)\n// ---------------------------------------------------------------\n\n/** Editor → host: a fatal error during boot / load. Hosts surface this\n * via the wrapper's `onError` callback. */\nexport interface CasualErrorData {\n code: 'embed_not_served' | 'load_failed' | 'parse_failed' | 'boot_failed' | 'internal';\n message: string;\n}\n\n// ---------------------------------------------------------------\n// Signing (uniform with the SDK `signing` prop)\n// ---------------------------------------------------------------\n\nexport interface SignatureRequestData {\n fields: SignatureField[];\n mode: SignatureMode;\n banner?: string;\n}\n\nexport interface SignatureRequestAckData {\n ok: boolean;\n code?: string;\n}\n\nexport type SignatureFieldSignedData = SignedFieldPayload;\nexport type SignatureCompleteData = SignatureCompletePayload;\n\nexport interface SignatureCancelData {\n reason: CancelReason;\n}\n\n// ---------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------\n\nexport function isCasualEnvelope(value: unknown): value is CasualEnvelope {\n if (!value || typeof value !== 'object') return false;\n const v = value as Record<string, unknown>;\n return (\n typeof v.type === 'string' &&\n v.type.startsWith('casual.') &&\n (v.app === 'docs' || v.app === 'sheet') &&\n v.v === 1 &&\n 'data' in v\n );\n}\n","/**\n * EmbedTransport — postMessage bridge for the iframe-embedded\n * editor. Validates origin, dispatches envelopes to handlers,\n * sends responses back to the host. Pure TypeScript — no React.\n *\n * Wire shape defined in\n * `docs/internal/13-iframe-protocol.md` + `./protocol.ts`.\n *\n * Lifetime: constructed once when the /embed page mounts.\n * Destroyed when the page unloads. Concurrent calls into the same\n * handler are the host's responsibility (well-behaved hosts\n * serialise requests by id).\n */\n\nimport {\n isCasualEnvelope,\n type CasualApp,\n type CasualEnvelope,\n type EditorHelloData,\n type HostHelloData,\n type LoadResponseData,\n type LoadRequestData,\n type SaveRequestData,\n type SaveResponseData,\n type SelectionChangedData,\n type TelemetryEventData,\n type CommandSetReadOnlyData,\n type CommandSetThemeData,\n type CommandSetLocaleData,\n type CommandSetViewModeData,\n type CommandExecuteData,\n type SelectionFormatStateData,\n type CasualErrorData,\n type SignatureRequestData,\n type SignatureRequestAckData,\n type SignatureFieldSignedData,\n type SignatureCompleteData,\n type SignatureCancelData,\n} from './protocol';\n\nexport interface EmbedTransportOptions {\n app: CasualApp;\n /** Origin allowed to send messages. Required — no `*` default. */\n hostOrigin: string;\n /** Editor build identity, surfaced in the editor.hello handshake. */\n version: string;\n commit: string;\n /** Editor-side capabilities advertised at handshake. */\n capabilities: string[];\n /** Optional injection for `window.parent` — tests pass a stub. */\n parentWindow?: {\n postMessage: (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;\n };\n /** Optional injection for the window receiving messages — tests pass a stub. */\n hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;\n}\n\nexport interface EmbedTransportHandlers {\n /** Host → editor handshake. Editor responds with `editor.ready`. */\n onHostHello?: (data: HostHelloData) => void | Promise<void>;\n /** Host → editor: command.* messages. */\n onCommandSetReadOnly?: (data: CommandSetReadOnlyData) => void | Promise<void>;\n onCommandSetTheme?: (data: CommandSetThemeData) => void | Promise<void>;\n onCommandSetLocale?: (data: CommandSetLocaleData) => void | Promise<void>;\n /** Host → editor: switch chrome density (preview ↔ editor). */\n onCommandSetViewMode?: (data: CommandSetViewModeData) => void | Promise<void>;\n /** Host → editor: execute a formatting / navigation command (bold,\n * italic, undo, …) against the active selection. v0.6+. */\n onCommandExecute?: (data: CommandExecuteData) => void | Promise<void>;\n onCommandFocus?: () => void | Promise<void>;\n onCommandSave?: () => void | Promise<void>;\n onCommandLoad?: () => void | Promise<void>;\n /** Host → editor signing session. Editor responds with `signature.request.ack`. */\n onSignatureRequest?: (\n data: SignatureRequestData,\n ) => SignatureRequestAckData | Promise<SignatureRequestAckData>;\n onSignatureCancel?: (data: SignatureCancelData) => void | Promise<void>;\n /** Host → editor: response to a prior load.request the editor issued. */\n onLoadResponse?: (id: string, data: LoadResponseData) => void;\n /** Host → editor: response to a prior save.request the editor issued. */\n onSaveResponse?: (id: string, data: SaveResponseData) => void;\n}\n\nexport class EmbedTransport {\n private readonly opts: Required<Omit<EmbedTransportOptions, 'parentWindow' | 'hostWindow'>> & {\n parentWindow: NonNullable<EmbedTransportOptions['parentWindow']>;\n hostWindow: NonNullable<EmbedTransportOptions['hostWindow']>;\n };\n private handlers: EmbedTransportHandlers = {};\n private destroyed = false;\n private pendingRequests = new Map<string, (env: CasualEnvelope) => void>();\n\n constructor(opts: EmbedTransportOptions) {\n this.opts = {\n ...opts,\n parentWindow:\n opts.parentWindow ??\n (typeof window !== 'undefined'\n ? (window.parent as unknown as NonNullable<EmbedTransportOptions['parentWindow']>)\n : { postMessage: () => undefined }),\n hostWindow:\n opts.hostWindow ??\n (typeof window !== 'undefined'\n ? window\n : ({\n addEventListener: () => undefined,\n removeEventListener: () => undefined,\n } as unknown as NonNullable<EmbedTransportOptions['hostWindow']>)),\n };\n this.boundMessage = this.boundMessage.bind(this);\n this.opts.hostWindow.addEventListener('message', this.boundMessage as EventListener);\n }\n\n /** Replaces the handler set. Idempotent — call multiple times. */\n on(handlers: EmbedTransportHandlers): void {\n this.handlers = { ...this.handlers, ...handlers };\n }\n\n /** Editor → Host: announce ourselves. Call once after handlers are wired. */\n sendHello(): void {\n const data: EditorHelloData = {\n capabilities: this.opts.capabilities,\n version: this.opts.version,\n commit: this.opts.commit,\n };\n this.post('casual.hello', data);\n }\n\n /** Editor → Host: editor is ready to receive commands. */\n sendReady(): void {\n this.post('casual.ready', {});\n }\n\n /** Editor → Host: ask the host to supply document bytes for `docId`. */\n async requestLoad(docId: string, timeoutMs = 30000): Promise<LoadResponseData> {\n return this.request<LoadResponseData>(\n 'casual.load.request',\n { docId } as LoadRequestData,\n timeoutMs,\n );\n }\n\n /** Editor → Host: ask the host to persist `bytes`. */\n async requestSave(req: SaveRequestData, timeoutMs = 30000): Promise<SaveResponseData> {\n return this.request<SaveResponseData>('casual.save.request', req, timeoutMs, [req.bytes]);\n }\n\n /** Editor → Host: selection moved. Fire-and-forget. */\n sendSelectionChanged(data: SelectionChangedData): void {\n this.post('casual.selection.changed', data);\n }\n\n /** Editor → Host: format flags on the active cell changed (bold,\n * italic, …). Drive's custom toolbar mirrors this state in its\n * \"pressed\" indicators. v0.6+. */\n sendSelectionFormatState(data: SelectionFormatStateData): void {\n this.post('casual.selection.format-state', data);\n }\n\n /** Editor → Host: a noteworthy event. */\n sendTelemetry(data: TelemetryEventData): void {\n this.post('casual.telemetry.event', data);\n }\n\n /** Editor → Host: per-field progress during a signing session. */\n sendSignatureFieldSigned(data: SignatureFieldSignedData): void {\n // Bytes ride the transfer list.\n this.post('casual.signature.field.signed', data, [data.bytes]);\n }\n\n /** Editor → Host: signing session is finished. */\n sendSignatureComplete(data: SignatureCompleteData): void {\n this.post('casual.signature.complete', data, [data.bytes]);\n }\n\n /** Editor → Host: editor-side cancel of a signing session. */\n sendSignatureCancel(reason: SignatureCancelData['reason']): void {\n this.post('casual.signature.cancel', { reason });\n }\n\n /** Editor → Host: fatal boot / load error. Host surfaces via wrapper\n * `onError` callback. Fire-and-forget. */\n sendError(data: CasualErrorData): void {\n this.post('casual.error', data);\n }\n\n /** Tear down listeners. Idempotent. */\n destroy(): void {\n if (this.destroyed) return;\n this.opts.hostWindow.removeEventListener('message', this.boundMessage as EventListener);\n this.pendingRequests.clear();\n this.destroyed = true;\n }\n\n // ---------------------------------------------------------------\n // Internals\n // ---------------------------------------------------------------\n\n private boundMessage(ev: Event): void {\n // MessageEvent isn't always available on the typing side when\n // a stub window is injected; cast pragmatically.\n const msg = ev as unknown as MessageEvent;\n if (msg.origin && msg.origin !== this.opts.hostOrigin) return;\n if (!isCasualEnvelope(msg.data)) return;\n void this.dispatch(msg.data as CasualEnvelope);\n }\n\n private async dispatch(env: CasualEnvelope): Promise<void> {\n // Responses to outbound requests route through the correlation map.\n if (env.id && this.pendingRequests.has(env.id)) {\n const resolve = this.pendingRequests.get(env.id)!;\n this.pendingRequests.delete(env.id);\n resolve(env);\n return;\n }\n\n switch (env.type) {\n case 'casual.hello':\n await this.handlers.onHostHello?.(env.data as HostHelloData);\n this.sendReady();\n return;\n case 'casual.command.setReadOnly':\n await this.handlers.onCommandSetReadOnly?.(env.data as CommandSetReadOnlyData);\n return;\n case 'casual.command.setTheme':\n await this.handlers.onCommandSetTheme?.(env.data as CommandSetThemeData);\n return;\n case 'casual.command.setLocale':\n await this.handlers.onCommandSetLocale?.(env.data as CommandSetLocaleData);\n return;\n case 'casual.command.set.viewmode':\n await this.handlers.onCommandSetViewMode?.(env.data as CommandSetViewModeData);\n return;\n case 'casual.command.execute':\n await this.handlers.onCommandExecute?.(env.data as CommandExecuteData);\n return;\n case 'casual.command.focus':\n await this.handlers.onCommandFocus?.();\n return;\n case 'casual.command.save':\n await this.handlers.onCommandSave?.();\n return;\n case 'casual.command.load':\n await this.handlers.onCommandLoad?.();\n return;\n case 'casual.signature.request': {\n const ack = (await this.handlers.onSignatureRequest?.(\n env.data as SignatureRequestData,\n )) ?? {\n ok: false,\n code: 'unhandled',\n };\n if (env.id) {\n this.postReply(env.id, 'casual.signature.request.ack', ack);\n }\n return;\n }\n case 'casual.signature.cancel':\n await this.handlers.onSignatureCancel?.(env.data as SignatureCancelData);\n return;\n default:\n // Unknown envelope — silently drop per the forward-compat\n // convention in the protocol doc.\n return;\n }\n }\n\n private post(type: string, data: unknown, transfer?: Transferable[]): void {\n const env: CasualEnvelope = { type, app: this.opts.app, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch {\n // Cross-origin postMessage can throw if the parent went away;\n // silently swallow — the next user action will retry.\n }\n }\n\n private postReply(id: string, type: string, data: unknown): void {\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin);\n } catch {\n // see post()\n }\n }\n\n private async request<T>(\n type: string,\n data: unknown,\n timeoutMs: number,\n transfer?: Transferable[],\n ): Promise<T> {\n const id = newRequestId();\n return new Promise<T>((resolve, reject) => {\n const timer =\n timeoutMs > 0\n ? setTimeout(() => {\n this.pendingRequests.delete(id);\n reject(new Error(`Embed request ${type} timed out after ${timeoutMs}ms`));\n }, timeoutMs)\n : null;\n this.pendingRequests.set(id, (env) => {\n if (timer) clearTimeout(timer);\n resolve(env.data as T);\n });\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch (err) {\n if (timer) clearTimeout(timer);\n this.pendingRequests.delete(id);\n reject(err);\n }\n });\n }\n}\n\nfunction newRequestId(): string {\n // 8 hex chars is plenty — IDs only need to be unique within a\n // single editor session. Math.random is fine; the host can't\n // use these for security.\n return Math.random().toString(16).slice(2, 10);\n}\n"],"mappings":";;;;;AAuPO,SAAS,iBAAiB,OAAyC;AACxE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,IAAI;AACV,SACE,OAAO,EAAE,SAAS,YAClB,EAAE,KAAK,WAAW,SAAS,MAC1B,EAAE,QAAQ,UAAU,EAAE,QAAQ,YAC/B,EAAE,MAAM,KACR,UAAU;AAEd;;;AC9KO,IAAM,iBAAN,MAAqB;AAAA,EAS1B,YAAY,MAA6B;AARzC,wBAAiB;AAIjB,wBAAQ,YAAmC,CAAC;AAC5C,wBAAQ,aAAY;AACpB,wBAAQ,mBAAkB,oBAAI,IAA2C;AAGvE,SAAK,OAAO;AAAA,MACV,GAAG;AAAA,MACH,cACE,KAAK,iBACJ,OAAO,WAAW,cACd,OAAO,SACR,EAAE,aAAa,MAAM,OAAU;AAAA,MACrC,YACE,KAAK,eACJ,OAAO,WAAW,cACf,SACC;AAAA,QACC,kBAAkB,MAAM;AAAA,QACxB,qBAAqB,MAAM;AAAA,MAC7B;AAAA,IACR;AACA,SAAK,eAAe,KAAK,aAAa,KAAK,IAAI;AAC/C,SAAK,KAAK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;AAAA,MACvB,CAAC;AACD,YAAM,MAAsB,EAAE,MAAM,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG,GAAG,KAAK;AACvE,UAAI;AACF,aAAK,KAAK,aAAa,YAAY,KAAK,KAAK,KAAK,YAAY,QAAQ;AAAA,MACxE,SAAS,KAAK;AACZ,YAAI,MAAO,cAAa,KAAK;AAC7B,aAAK,gBAAgB,OAAO,EAAE;AAC9B,eAAO,GAAG;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,SAAS,eAAuB;AAI9B,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE;AAC/C;","names":["env"]}
1
+ {"version":3,"sources":["../src/embed/protocol.ts","../src/embed/EmbedTransport.ts","../src/embed/EmbedHostTransport.ts"],"sourcesContent":["/**\n * Iframe protocol — wire envelopes that match\n * `docs/internal/13-iframe-protocol.md`.\n *\n * Mirror updates to the doc whenever a new envelope shape lands.\n * The discriminator on `type` (always starts with `casual.`) and\n * the per-envelope `data` shape are the contract.\n */\n\nimport type {\n CancelReason,\n SignatureCompletePayload,\n SignatureField,\n SignatureMode,\n SignedFieldPayload,\n} from '../signing/types';\n\nexport type CasualApp = 'docs' | 'sheet';\n\n/** Common envelope shape — every postMessage on the wire matches this. */\nexport interface CasualEnvelope<T = unknown> {\n type: string;\n app: CasualApp;\n /** Per-request id for request/response correlation. Empty for fire-and-forget. */\n id?: string;\n /** Protocol version. Bumped only on breaking changes. */\n v: 1;\n data: T;\n}\n\n// ---------------------------------------------------------------\n// Handshake\n// ---------------------------------------------------------------\n\nexport interface EditorHelloData {\n capabilities: string[];\n version: string;\n commit: string;\n}\n\nexport interface HostHelloData {\n capabilities: string[];\n authToken?: string;\n}\n\n// ---------------------------------------------------------------\n// Load + save (editor → host requests; host → editor responses)\n// ---------------------------------------------------------------\n\nexport interface LoadRequestData {\n docId: string;\n}\n\nexport interface LoadResponseDataOk {\n ok: true;\n bytes: ArrayBuffer;\n etag?: string;\n fileName: string;\n readOnly?: boolean;\n}\n\nexport interface LoadResponseDataErr {\n ok: false;\n code: string;\n message?: string;\n}\n\nexport type LoadResponseData = LoadResponseDataOk | LoadResponseDataErr;\n\nexport interface SaveRequestData {\n docId: string;\n bytes: ArrayBuffer;\n baseEtag?: string;\n}\n\nexport interface SaveResponseDataOk {\n ok: true;\n etag: string;\n}\n\nexport interface SaveResponseDataErr {\n ok: false;\n code: string;\n etag?: string;\n message?: string;\n}\n\nexport type SaveResponseData = SaveResponseDataOk | SaveResponseDataErr;\n\n// ---------------------------------------------------------------\n// Save / exit notifications (editor → host, fire-and-forget)\n// ---------------------------------------------------------------\n//\n// The lightweight counterpart to the bytes-carrying load/save *request*\n// pair above. These mirror the SDK's React `onSave` / `onExit` hooks one\n// for one — the \"one shape, two surfaces\" save/exit contract — so a host\n// that frames the iframe gets the same persistence signals a host that\n// renders `<CasualSheets>` directly does. Fire-and-forget: the editor\n// never owns storage; the host decides what to do with the snapshot.\n//\n// `casual.save.request` (above) stays the WOPI-style path for hosts that\n// want xlsx bytes + etag round-trips; these notifications are the simpler\n// \"here's the current state, persist it however you like\" path.\n\n/** Editor → host: the user explicitly asked to save — Ctrl/Cmd+S inside\n * the iframe, or the host's `casual.command.save`. Carries the full\n * editor snapshot as JSON (sheet app: Univer's `IWorkbookData`). Mirror\n * of the React `onSave` hook. v0.9+. */\nexport interface SaveNotifyData {\n /** App-specific snapshot JSON. Sheet: `IWorkbookData`. */\n snapshot: unknown;\n /** What triggered the save: the in-editor shortcut or a host command. */\n reason: 'shortcut' | 'host';\n}\n\n/** Editor → host: the editor is unmounting / navigating away. Carries\n * the final snapshot so the host can persist on exit. Mirror of the\n * React `onExit` hook. v0.9+. */\nexport interface ExitData {\n /** App-specific snapshot JSON. Sheet: `IWorkbookData`. */\n snapshot: unknown;\n}\n\n// ---------------------------------------------------------------\n// Selection + telemetry + lock (editor → host notifications)\n// ---------------------------------------------------------------\n\nexport interface SelectionChangedData {\n docs?: { paraId: string; from: number; to: number; selectedText: string };\n sheet?: { sheet: string; from: string; to: string };\n}\n\nexport interface TelemetryEventData {\n kind: string;\n /** Arbitrary metric fields. */\n [k: string]: unknown;\n}\n\nexport interface LockLostData {\n reason: 'taken_by_other' | 'expired' | 'host_revoked';\n}\n\n// ---------------------------------------------------------------\n// Commands (host → editor)\n// ---------------------------------------------------------------\n\nexport interface CommandSetReadOnlyData {\n readOnly: boolean;\n}\n\nexport interface CommandSetThemeData {\n theme: 'light' | 'dark' | 'system';\n}\n\nexport interface CommandSetLocaleData {\n locale: string;\n}\n\n/** Host → editor: switch chrome density between the two consumer-facing\n * modes without re-mounting. `preview` hides toolbar / formula bar /\n * side panel / status bar / sheet tabs and runs read-only; `editor`\n * shows the full UI. Mirrors the `viewMode` prop on `<CasualSheetsIframe>`. */\nexport interface CommandSetViewModeData {\n viewMode: 'preview' | 'editor';\n}\n\n/** Host → editor: execute a formatting / navigation command against\n * the active selection in the embedded workbook. Hosts (like Casual\n * Drive) build their own toolbar above the iframe and dispatch these\n * commands instead of Univer's built-in ribbon, which the SDK can't\n * ship because the ribbon resolves IRPCChannelService at construction\n * and that service needs a worker the SDK doesn't bundle.\n *\n * v0.6 covered the toggle set; v0.7 adds the rich-format set (font,\n * size, colour, fill) + merge / unmerge. Arg-carrying commands read\n * the relevant field off `args` — every other command ignores it. */\nexport interface CommandExecuteData {\n command: // v0.6 — toggle / nav (no args)\n | 'undo'\n | 'redo'\n | 'bold'\n | 'italic'\n | 'underline'\n | 'strikethrough'\n | 'align-left'\n | 'align-center'\n | 'align-right'\n // v0.7 — rich format (args carry the value)\n | 'set-font-family'\n | 'set-font-size'\n | 'set-text-color'\n | 'reset-text-color'\n | 'set-bg-color'\n | 'reset-bg-color'\n | 'merge'\n | 'unmerge'\n // v0.8 — number formats + freeze + wrap\n | 'numfmt-currency'\n | 'numfmt-percent'\n | 'numfmt-add-decimal'\n | 'numfmt-subtract-decimal'\n | 'numfmt-custom'\n | 'wrap-toggle'\n | 'freeze-first-row'\n | 'freeze-first-column'\n | 'freeze-none';\n args?: {\n /** Used by `set-font-family`. */\n family?: string;\n /** Used by `set-font-size`. Integer point size. */\n size?: number;\n /** Used by `set-text-color` and `set-bg-color`. Hex like `#1a73e8`. */\n color?: string;\n /** Used by `numfmt-custom`. The Excel-style format string, e.g.\n * `\"#,##0.00\"`, `\"$#,##0\"`, `\"0.00%\"`, `\"d-mmm-yy\"`. v0.8+. */\n pattern?: string;\n };\n}\n\n/** Editor → host: emitted whenever the selection's active cell's\n * format flags change. Drive's toolbar mirrors this state in the\n * button \"pressed\" / value indicators so the surface always reflects\n * what the user would see in the cell. v0.7 widens the payload with\n * the rich-format read-back (fontFamily, fontSize, textColor, bgColor)\n * so the toolbar's font picker / size stepper / colour swatches stay\n * in sync without the host having to poll. */\nexport interface SelectionFormatStateData {\n bold: boolean;\n italic: boolean;\n underline: boolean;\n strikethrough: boolean;\n align: 'left' | 'center' | 'right' | null;\n /** Defined font family on the active cell, or null when the cell\n * inherits the workbook default. v0.7+. */\n fontFamily: string | null;\n /** Defined font size on the active cell, or null when the cell\n * inherits the workbook default. v0.7+. */\n fontSize: number | null;\n /** Hex text colour like `#1a73e8`, or null when default. v0.7+. */\n textColor: string | null;\n /** Hex background colour, or null when no fill is set. v0.7+. */\n bgColor: string | null;\n}\n\n// ---------------------------------------------------------------\n// Errors (editor → host fatal signals)\n// ---------------------------------------------------------------\n\n/** Editor → host: a fatal error during boot / load. Hosts surface this\n * via the wrapper's `onError` callback. */\nexport interface CasualErrorData {\n code: 'embed_not_served' | 'load_failed' | 'parse_failed' | 'boot_failed' | 'internal';\n message: string;\n}\n\n// ---------------------------------------------------------------\n// Signing (uniform with the SDK `signing` prop)\n// ---------------------------------------------------------------\n\nexport interface SignatureRequestData {\n fields: SignatureField[];\n mode: SignatureMode;\n banner?: string;\n}\n\nexport interface SignatureRequestAckData {\n ok: boolean;\n code?: string;\n}\n\nexport type SignatureFieldSignedData = SignedFieldPayload;\nexport type SignatureCompleteData = SignatureCompletePayload;\n\nexport interface SignatureCancelData {\n reason: CancelReason;\n}\n\n// ---------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------\n\nexport function isCasualEnvelope(value: unknown): value is CasualEnvelope {\n if (!value || typeof value !== 'object') return false;\n const v = value as Record<string, unknown>;\n return (\n typeof v.type === 'string' &&\n v.type.startsWith('casual.') &&\n (v.app === 'docs' || v.app === 'sheet') &&\n v.v === 1 &&\n 'data' in v\n );\n}\n","/**\n * EmbedTransport — postMessage bridge for the iframe-embedded\n * editor. Validates origin, dispatches envelopes to handlers,\n * sends responses back to the host. Pure TypeScript — no React.\n *\n * Wire shape defined in\n * `docs/internal/13-iframe-protocol.md` + `./protocol.ts`.\n *\n * Lifetime: constructed once when the /embed page mounts.\n * Destroyed when the page unloads. Concurrent calls into the same\n * handler are the host's responsibility (well-behaved hosts\n * serialise requests by id).\n */\n\nimport {\n isCasualEnvelope,\n type CasualApp,\n type CasualEnvelope,\n type EditorHelloData,\n type HostHelloData,\n type LoadResponseData,\n type LoadRequestData,\n type SaveRequestData,\n type SaveResponseData,\n type SaveNotifyData,\n type ExitData,\n type SelectionChangedData,\n type TelemetryEventData,\n type CommandSetReadOnlyData,\n type CommandSetThemeData,\n type CommandSetLocaleData,\n type CommandSetViewModeData,\n type CommandExecuteData,\n type SelectionFormatStateData,\n type CasualErrorData,\n type SignatureRequestData,\n type SignatureRequestAckData,\n type SignatureFieldSignedData,\n type SignatureCompleteData,\n type SignatureCancelData,\n} from './protocol';\n\nexport interface EmbedTransportOptions {\n app: CasualApp;\n /** Origin allowed to send messages. Required — no `*` default. */\n hostOrigin: string;\n /** Editor build identity, surfaced in the editor.hello handshake. */\n version: string;\n commit: string;\n /** Editor-side capabilities advertised at handshake. */\n capabilities: string[];\n /** Optional injection for `window.parent` — tests pass a stub. */\n parentWindow?: {\n postMessage: (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;\n };\n /** Optional injection for the window receiving messages — tests pass a stub. */\n hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;\n}\n\nexport interface EmbedTransportHandlers {\n /** Host → editor handshake. Editor responds with `editor.ready`. */\n onHostHello?: (data: HostHelloData) => void | Promise<void>;\n /** Host → editor: command.* messages. */\n onCommandSetReadOnly?: (data: CommandSetReadOnlyData) => void | Promise<void>;\n onCommandSetTheme?: (data: CommandSetThemeData) => void | Promise<void>;\n onCommandSetLocale?: (data: CommandSetLocaleData) => void | Promise<void>;\n /** Host → editor: switch chrome density (preview ↔ editor). */\n onCommandSetViewMode?: (data: CommandSetViewModeData) => void | Promise<void>;\n /** Host → editor: execute a formatting / navigation command (bold,\n * italic, undo, …) against the active selection. v0.6+. */\n onCommandExecute?: (data: CommandExecuteData) => void | Promise<void>;\n onCommandFocus?: () => void | Promise<void>;\n onCommandSave?: () => void | Promise<void>;\n onCommandLoad?: () => void | Promise<void>;\n /** Host → editor signing session. Editor responds with `signature.request.ack`. */\n onSignatureRequest?: (\n data: SignatureRequestData,\n ) => SignatureRequestAckData | Promise<SignatureRequestAckData>;\n onSignatureCancel?: (data: SignatureCancelData) => void | Promise<void>;\n /** Host → editor: response to a prior load.request the editor issued. */\n onLoadResponse?: (id: string, data: LoadResponseData) => void;\n /** Host → editor: response to a prior save.request the editor issued. */\n onSaveResponse?: (id: string, data: SaveResponseData) => void;\n}\n\nexport class EmbedTransport {\n private readonly opts: Required<Omit<EmbedTransportOptions, 'parentWindow' | 'hostWindow'>> & {\n parentWindow: NonNullable<EmbedTransportOptions['parentWindow']>;\n hostWindow: NonNullable<EmbedTransportOptions['hostWindow']>;\n };\n private handlers: EmbedTransportHandlers = {};\n private destroyed = false;\n private pendingRequests = new Map<string, (env: CasualEnvelope) => void>();\n\n constructor(opts: EmbedTransportOptions) {\n this.opts = {\n ...opts,\n parentWindow:\n opts.parentWindow ??\n (typeof window !== 'undefined'\n ? (window.parent as unknown as NonNullable<EmbedTransportOptions['parentWindow']>)\n : { postMessage: () => undefined }),\n hostWindow:\n opts.hostWindow ??\n (typeof window !== 'undefined'\n ? window\n : ({\n addEventListener: () => undefined,\n removeEventListener: () => undefined,\n } as unknown as NonNullable<EmbedTransportOptions['hostWindow']>)),\n };\n this.boundMessage = this.boundMessage.bind(this);\n this.opts.hostWindow.addEventListener('message', this.boundMessage as EventListener);\n }\n\n /** Replaces the handler set. Idempotent — call multiple times. */\n on(handlers: EmbedTransportHandlers): void {\n this.handlers = { ...this.handlers, ...handlers };\n }\n\n /** Editor → Host: announce ourselves. Call once after handlers are wired. */\n sendHello(): void {\n const data: EditorHelloData = {\n capabilities: this.opts.capabilities,\n version: this.opts.version,\n commit: this.opts.commit,\n };\n this.post('casual.hello', data);\n }\n\n /** Editor → Host: editor is ready to receive commands. */\n sendReady(): void {\n this.post('casual.ready', {});\n }\n\n /** Editor → Host: ask the host to supply document bytes for `docId`. */\n async requestLoad(docId: string, timeoutMs = 30000): Promise<LoadResponseData> {\n return this.request<LoadResponseData>(\n 'casual.load.request',\n { docId } as LoadRequestData,\n timeoutMs,\n );\n }\n\n /** Editor → Host: ask the host to persist `bytes`. */\n async requestSave(req: SaveRequestData, timeoutMs = 30000): Promise<SaveResponseData> {\n return this.request<SaveResponseData>('casual.save.request', req, timeoutMs, [req.bytes]);\n }\n\n /** Editor → Host: the user asked to save (Ctrl/Cmd+S or a host save\n * command). Fire-and-forget snapshot notification — the lightweight\n * mirror of the React `onSave` hook. The host persists however it\n * likes; no response is awaited. */\n sendSaveNotify(data: SaveNotifyData): void {\n this.post('casual.save.notify', data);\n }\n\n /** Editor → Host: the editor is unmounting. Carries the final snapshot\n * so the host can persist on exit. Mirror of the React `onExit` hook. */\n sendExit(data: ExitData): void {\n this.post('casual.exit', data);\n }\n\n /** Editor → Host: selection moved. Fire-and-forget. */\n sendSelectionChanged(data: SelectionChangedData): void {\n this.post('casual.selection.changed', data);\n }\n\n /** Editor → Host: format flags on the active cell changed (bold,\n * italic, …). Drive's custom toolbar mirrors this state in its\n * \"pressed\" indicators. v0.6+. */\n sendSelectionFormatState(data: SelectionFormatStateData): void {\n this.post('casual.selection.format-state', data);\n }\n\n /** Editor → Host: a noteworthy event. */\n sendTelemetry(data: TelemetryEventData): void {\n this.post('casual.telemetry.event', data);\n }\n\n /** Editor → Host: per-field progress during a signing session. */\n sendSignatureFieldSigned(data: SignatureFieldSignedData): void {\n // Bytes ride the transfer list.\n this.post('casual.signature.field.signed', data, [data.bytes]);\n }\n\n /** Editor → Host: signing session is finished. */\n sendSignatureComplete(data: SignatureCompleteData): void {\n this.post('casual.signature.complete', data, [data.bytes]);\n }\n\n /** Editor → Host: editor-side cancel of a signing session. */\n sendSignatureCancel(reason: SignatureCancelData['reason']): void {\n this.post('casual.signature.cancel', { reason });\n }\n\n /** Editor → Host: fatal boot / load error. Host surfaces via wrapper\n * `onError` callback. Fire-and-forget. */\n sendError(data: CasualErrorData): void {\n this.post('casual.error', data);\n }\n\n /** Tear down listeners. Idempotent. */\n destroy(): void {\n if (this.destroyed) return;\n this.opts.hostWindow.removeEventListener('message', this.boundMessage as EventListener);\n this.pendingRequests.clear();\n this.destroyed = true;\n }\n\n // ---------------------------------------------------------------\n // Internals\n // ---------------------------------------------------------------\n\n private boundMessage(ev: Event): void {\n // MessageEvent isn't always available on the typing side when\n // a stub window is injected; cast pragmatically.\n const msg = ev as unknown as MessageEvent;\n if (msg.origin && msg.origin !== this.opts.hostOrigin) return;\n if (!isCasualEnvelope(msg.data)) return;\n void this.dispatch(msg.data as CasualEnvelope);\n }\n\n private async dispatch(env: CasualEnvelope): Promise<void> {\n // Responses to outbound requests route through the correlation map.\n if (env.id && this.pendingRequests.has(env.id)) {\n const resolve = this.pendingRequests.get(env.id)!;\n this.pendingRequests.delete(env.id);\n resolve(env);\n return;\n }\n\n switch (env.type) {\n case 'casual.hello':\n await this.handlers.onHostHello?.(env.data as HostHelloData);\n this.sendReady();\n return;\n case 'casual.command.setReadOnly':\n await this.handlers.onCommandSetReadOnly?.(env.data as CommandSetReadOnlyData);\n return;\n case 'casual.command.setTheme':\n await this.handlers.onCommandSetTheme?.(env.data as CommandSetThemeData);\n return;\n case 'casual.command.setLocale':\n await this.handlers.onCommandSetLocale?.(env.data as CommandSetLocaleData);\n return;\n case 'casual.command.set.viewmode':\n await this.handlers.onCommandSetViewMode?.(env.data as CommandSetViewModeData);\n return;\n case 'casual.command.execute':\n await this.handlers.onCommandExecute?.(env.data as CommandExecuteData);\n return;\n case 'casual.command.focus':\n await this.handlers.onCommandFocus?.();\n return;\n case 'casual.command.save':\n await this.handlers.onCommandSave?.();\n return;\n case 'casual.command.load':\n await this.handlers.onCommandLoad?.();\n return;\n case 'casual.signature.request': {\n const ack = (await this.handlers.onSignatureRequest?.(\n env.data as SignatureRequestData,\n )) ?? {\n ok: false,\n code: 'unhandled',\n };\n if (env.id) {\n this.postReply(env.id, 'casual.signature.request.ack', ack);\n }\n return;\n }\n case 'casual.signature.cancel':\n await this.handlers.onSignatureCancel?.(env.data as SignatureCancelData);\n return;\n default:\n // Unknown envelope — silently drop per the forward-compat\n // convention in the protocol doc.\n return;\n }\n }\n\n private post(type: string, data: unknown, transfer?: Transferable[]): void {\n const env: CasualEnvelope = { type, app: this.opts.app, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch {\n // Cross-origin postMessage can throw if the parent went away;\n // silently swallow — the next user action will retry.\n }\n }\n\n private postReply(id: string, type: string, data: unknown): void {\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin);\n } catch {\n // see post()\n }\n }\n\n private async request<T>(\n type: string,\n data: unknown,\n timeoutMs: number,\n transfer?: Transferable[],\n ): Promise<T> {\n const id = newRequestId();\n return new Promise<T>((resolve, reject) => {\n const timer =\n timeoutMs > 0\n ? setTimeout(() => {\n this.pendingRequests.delete(id);\n reject(new Error(`Embed request ${type} timed out after ${timeoutMs}ms`));\n }, timeoutMs)\n : null;\n this.pendingRequests.set(id, (env) => {\n if (timer) clearTimeout(timer);\n resolve(env.data as T);\n });\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch (err) {\n if (timer) clearTimeout(timer);\n this.pendingRequests.delete(id);\n reject(err);\n }\n });\n }\n}\n\nfunction newRequestId(): string {\n // 8 hex chars is plenty — IDs only need to be unique within a\n // single editor session. Math.random is fine; the host can't\n // use these for security.\n return Math.random().toString(16).slice(2, 10);\n}\n","/**\n * EmbedHostTransport — the parent side of the embed iframe bridge for\n * the sheet SDK. Mirror of @casualoffice/docs's host transport.\n *\n * Wire shape: `docs/SDK_SIGNING_EMBED.md` (cross-link in the doc repo at\n * `docs/internal/13-iframe-protocol.md`) + `16-sdk-iframe-architecture.md`.\n *\n * Lifetime: constructed once when the wrapper mounts the iframe.\n * `destroy()` removes the event listener; safe to call multiple times.\n */\n\nimport {\n isCasualEnvelope,\n type CasualApp,\n type CasualEnvelope,\n type CasualErrorData,\n type CommandSetReadOnlyData,\n type CommandSetThemeData,\n type CommandSetLocaleData,\n type CommandSetViewModeData,\n type CommandExecuteData,\n type SelectionFormatStateData,\n type EditorHelloData,\n type HostHelloData,\n type LoadRequestData,\n type LoadResponseData,\n type SaveRequestData,\n type SaveResponseData,\n type SaveNotifyData,\n type ExitData,\n type SelectionChangedData,\n type SignatureCancelData,\n type SignatureCompleteData,\n type SignatureFieldSignedData,\n type SignatureRequestData,\n type TelemetryEventData,\n} from './protocol';\n\nexport interface EmbedHostTransportOptions {\n app: CasualApp;\n /** The iframe's `contentWindow`. */\n iframeWindow: Window;\n /** Origin allowed to send + receive messages. Same-origin internal\n * embed is `window.location.origin`. */\n embedOrigin: string;\n /** Optional injection — tests pass a stub. */\n hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;\n}\n\nexport interface EmbedHostHandlers {\n onEditorReady?: (data: EditorHelloData) => void;\n /** Editor requests bytes for `docId`. */\n onLoadRequest?: (data: LoadRequestData) => Promise<LoadResponseData> | LoadResponseData;\n /** Editor requests a save (WOPI-style, carries xlsx bytes). */\n onSaveRequest?: (data: SaveRequestData) => Promise<SaveResponseData> | SaveResponseData;\n /** Editor fired its lightweight save notification (Ctrl/Cmd+S or a\n * host save command). Carries the full snapshot JSON; fire-and-forget.\n * Mirror of the React `onSave` hook. */\n onSaveNotify?: (data: SaveNotifyData) => void;\n /** Editor is unmounting; carries the final snapshot. Mirror of the\n * React `onExit` hook. */\n onExit?: (data: ExitData) => void;\n onSelectionChanged?: (data: SelectionChangedData) => void;\n onSelectionFormatState?: (data: SelectionFormatStateData) => void;\n onTelemetry?: (data: TelemetryEventData) => void;\n onSignatureFieldSigned?: (data: SignatureFieldSignedData) => void;\n onSignatureComplete?: (data: SignatureCompleteData) => void;\n onSignatureCancel?: (data: SignatureCancelData) => void;\n onError?: (data: CasualErrorData) => void;\n}\n\ntype IframePostMessage = (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;\n\nexport class EmbedHostTransport {\n private readonly opts: EmbedHostTransportOptions;\n private handlers: EmbedHostHandlers = {};\n private readonly boundOnMessage: (ev: MessageEvent) => void;\n private destroyed = false;\n\n constructor(opts: EmbedHostTransportOptions) {\n this.opts = opts;\n this.boundOnMessage = this.onMessage.bind(this);\n const target = opts.hostWindow ?? window;\n target.addEventListener('message', this.boundOnMessage);\n }\n\n on(handlers: EmbedHostHandlers): void {\n this.handlers = { ...this.handlers, ...handlers };\n }\n\n destroy(): void {\n if (this.destroyed) return;\n this.destroyed = true;\n const target = this.opts.hostWindow ?? window;\n target.removeEventListener('message', this.boundOnMessage);\n }\n\n sendHostHello(data: HostHelloData): void {\n this.post('casual.hello', data);\n }\n\n sendSetViewMode(data: CommandSetViewModeData): void {\n this.post('casual.command.set.viewmode', data);\n }\n\n sendSetReadOnly(data: CommandSetReadOnlyData): void {\n this.post('casual.command.set.readonly', data);\n }\n\n sendSetTheme(data: CommandSetThemeData): void {\n this.post('casual.command.set.theme', data);\n }\n\n sendSetLocale(data: CommandSetLocaleData): void {\n this.post('casual.command.set.locale', data);\n }\n\n sendCommandSave(): void {\n this.post('casual.command.save', null);\n }\n\n sendCommandFocus(): void {\n this.post('casual.command.focus', null);\n }\n\n /** Host → Editor: run a formatting / navigation command (bold,\n * italic, undo, …) against the active selection. v0.6+. */\n sendCommandExecute(data: CommandExecuteData): void {\n this.post('casual.command.execute', data);\n }\n\n sendSignatureRequest(id: string, data: SignatureRequestData): void {\n this.post('casual.signature.request', data, id);\n }\n\n sendSignatureCancel(data: SignatureCancelData): void {\n this.post('casual.signature.cancel', data);\n }\n\n private onMessage(ev: MessageEvent): void {\n if (this.destroyed) return;\n if (ev.origin !== this.opts.embedOrigin) return;\n if (ev.source !== this.opts.iframeWindow) return;\n if (!isCasualEnvelope(ev.data)) return;\n if (ev.data.app !== this.opts.app) return;\n\n void this.dispatch(ev.data);\n }\n\n private async dispatch(env: CasualEnvelope): Promise<void> {\n switch (env.type) {\n case 'casual.ready':\n this.handlers.onEditorReady?.(env.data as EditorHelloData);\n return;\n case 'casual.load.request': {\n if (!this.handlers.onLoadRequest) return;\n const id = env.id ?? '';\n try {\n const resp = await this.handlers.onLoadRequest(env.data as LoadRequestData);\n const transfer: Transferable[] = resp.ok ? [resp.bytes] : [];\n this.post('casual.load.response', resp, id, transfer);\n } catch (err) {\n this.post(\n 'casual.load.response',\n {\n ok: false as const,\n code: 'host_error',\n message: err instanceof Error ? err.message : String(err),\n },\n id,\n );\n }\n return;\n }\n case 'casual.save.request': {\n if (!this.handlers.onSaveRequest) return;\n const id = env.id ?? '';\n try {\n const resp = await this.handlers.onSaveRequest(env.data as SaveRequestData);\n this.post('casual.save.response', resp, id);\n } catch (err) {\n this.post(\n 'casual.save.response',\n {\n ok: false as const,\n code: 'host_error',\n message: err instanceof Error ? err.message : String(err),\n },\n id,\n );\n }\n return;\n }\n case 'casual.save.notify':\n this.handlers.onSaveNotify?.(env.data as SaveNotifyData);\n return;\n case 'casual.exit':\n this.handlers.onExit?.(env.data as ExitData);\n return;\n case 'casual.selection.changed':\n this.handlers.onSelectionChanged?.(env.data as SelectionChangedData);\n return;\n case 'casual.selection.format-state':\n this.handlers.onSelectionFormatState?.(env.data as SelectionFormatStateData);\n return;\n case 'casual.telemetry.event':\n this.handlers.onTelemetry?.(env.data as TelemetryEventData);\n return;\n case 'casual.signature.field.signed':\n this.handlers.onSignatureFieldSigned?.(env.data as SignatureFieldSignedData);\n return;\n case 'casual.signature.complete':\n this.handlers.onSignatureComplete?.(env.data as SignatureCompleteData);\n return;\n case 'casual.signature.cancel':\n this.handlers.onSignatureCancel?.(env.data as SignatureCancelData);\n return;\n case 'casual.signature.request.ack':\n return;\n case 'casual.error':\n this.handlers.onError?.(env.data as CasualErrorData);\n return;\n default:\n return;\n }\n }\n\n private post(type: string, data: unknown, id?: string, transfer?: Transferable[]): void {\n const env: CasualEnvelope = {\n type,\n app: this.opts.app,\n v: 1,\n data,\n ...(id ? { id } : {}),\n };\n const send = this.opts.iframeWindow.postMessage.bind(\n this.opts.iframeWindow,\n ) as IframePostMessage;\n send(env, this.opts.embedOrigin, transfer);\n }\n}\n"],"mappings":";;;;;AAyRO,SAAS,iBAAiB,OAAyC;AACxE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,IAAI;AACV,SACE,OAAO,EAAE,SAAS,YAClB,EAAE,KAAK,WAAW,SAAS,MAC1B,EAAE,QAAQ,UAAU,EAAE,QAAQ,YAC/B,EAAE,MAAM,KACR,UAAU;AAEd;;;AC9MO,IAAM,iBAAN,MAAqB;AAAA,EAS1B,YAAY,MAA6B;AARzC,wBAAiB;AAIjB,wBAAQ,YAAmC,CAAC;AAC5C,wBAAQ,aAAY;AACpB,wBAAQ,mBAAkB,oBAAI,IAA2C;AAGvE,SAAK,OAAO;AAAA,MACV,GAAG;AAAA,MACH,cACE,KAAK,iBACJ,OAAO,WAAW,cACd,OAAO,SACR,EAAE,aAAa,MAAM,OAAU;AAAA,MACrC,YACE,K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