@casualoffice/sheets 0.9.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 (92) hide show
  1. package/LICENSE +200 -0
  2. package/dist/embed/embed-runtime.js +537 -0
  3. package/dist/embed/embed.html +29 -0
  4. package/dist/embed/parser.worker.js +48474 -0
  5. package/dist/embed.cjs +225 -0
  6. package/dist/embed.cjs.map +1 -0
  7. package/dist/embed.d.cts +100 -0
  8. package/dist/embed.d.ts +100 -0
  9. package/dist/embed.js +204 -0
  10. package/dist/embed.js.map +1 -0
  11. package/dist/index.cjs +1549 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +9 -0
  14. package/dist/index.d.ts +9 -0
  15. package/dist/index.js +1530 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/parser.worker.cjs +48469 -0
  18. package/dist/parser.worker.cjs.map +1 -0
  19. package/dist/parser.worker.js +48474 -0
  20. package/dist/parser.worker.js.map +1 -0
  21. package/dist/protocol--KyBQUjU.d.cts +171 -0
  22. package/dist/protocol-cEzy7S0i.d.ts +171 -0
  23. package/dist/sheets.cjs +677 -0
  24. package/dist/sheets.cjs.map +1 -0
  25. package/dist/sheets.d.cts +177 -0
  26. package/dist/sheets.d.ts +177 -0
  27. package/dist/sheets.js +658 -0
  28. package/dist/sheets.js.map +1 -0
  29. package/dist/signing.cjs +706 -0
  30. package/dist/signing.cjs.map +1 -0
  31. package/dist/signing.d.cts +141 -0
  32. package/dist/signing.d.ts +141 -0
  33. package/dist/signing.js +683 -0
  34. package/dist/signing.js.map +1 -0
  35. package/dist/styles.cjs +10 -0
  36. package/dist/styles.cjs.map +1 -0
  37. package/dist/styles.d.cts +2 -0
  38. package/dist/styles.d.ts +2 -0
  39. package/dist/styles.js +8 -0
  40. package/dist/styles.js.map +1 -0
  41. package/dist/types-s_O0u6Cg.d.cts +90 -0
  42. package/dist/types-s_O0u6Cg.d.ts +90 -0
  43. package/dist/univer.cjs +220 -0
  44. package/dist/univer.cjs.map +1 -0
  45. package/dist/univer.d.cts +60 -0
  46. package/dist/univer.d.ts +60 -0
  47. package/dist/univer.js +187 -0
  48. package/dist/univer.js.map +1 -0
  49. package/dist/xlsx.cjs +3388 -0
  50. package/dist/xlsx.cjs.map +1 -0
  51. package/dist/xlsx.d.cts +383 -0
  52. package/dist/xlsx.d.ts +383 -0
  53. package/dist/xlsx.js +3383 -0
  54. package/dist/xlsx.js.map +1 -0
  55. package/package.json +293 -0
  56. package/src/embed/EmbedHostTransport.ts +226 -0
  57. package/src/embed/EmbedTransport.ts +323 -0
  58. package/src/embed/EmbedTransport.unit.test.ts +161 -0
  59. package/src/embed/index.ts +40 -0
  60. package/src/embed/protocol.ts +258 -0
  61. package/src/embed-runtime/embed.html +29 -0
  62. package/src/embed-runtime/index.tsx +440 -0
  63. package/src/index.ts +16 -0
  64. package/src/sheets/CasualSheets.tsx +319 -0
  65. package/src/sheets/CasualSheetsIframe.tsx +220 -0
  66. package/src/sheets/api.ts +108 -0
  67. package/src/sheets/index.ts +11 -0
  68. package/src/signing/SigningPane.tsx +374 -0
  69. package/src/signing/SigningProvider.tsx +126 -0
  70. package/src/signing/captures.tsx +316 -0
  71. package/src/signing/controller.ts +151 -0
  72. package/src/signing/controller.unit.test.ts +133 -0
  73. package/src/signing/index.ts +44 -0
  74. package/src/signing/types.ts +89 -0
  75. package/src/styles.ts +16 -0
  76. package/src/univer/index.ts +17 -0
  77. package/src/univer/lazy-plugins.ts +280 -0
  78. package/src/xlsx/_perf.ts +14 -0
  79. package/src/xlsx/_snapshot-constants.ts +15 -0
  80. package/src/xlsx/comments-resource.ts +209 -0
  81. package/src/xlsx/constants.ts +9 -0
  82. package/src/xlsx/data-validation-resource.ts +219 -0
  83. package/src/xlsx/import.ts +35 -0
  84. package/src/xlsx/index.ts +40 -0
  85. package/src/xlsx/page-setup-resource.ts +205 -0
  86. package/src/xlsx/parse-impl.ts +418 -0
  87. package/src/xlsx/parse-in-worker.ts +82 -0
  88. package/src/xlsx/parser.worker.ts +39 -0
  89. package/src/xlsx/passthrough-resource.ts +175 -0
  90. package/src/xlsx/pivot-passthrough.ts +359 -0
  91. package/src/xlsx/style-mapping.ts +171 -0
  92. package/src/xlsx/tables-resource.ts +211 -0
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Iframe protocol — wire envelopes that match
3
+ * `docs/internal/13-iframe-protocol.md`.
4
+ *
5
+ * Mirror updates to the doc whenever a new envelope shape lands.
6
+ * The discriminator on `type` (always starts with `casual.`) and
7
+ * the per-envelope `data` shape are the contract.
8
+ */
9
+
10
+ import type {
11
+ CancelReason,
12
+ SignatureCompletePayload,
13
+ SignatureField,
14
+ SignatureMode,
15
+ SignedFieldPayload,
16
+ } from '../signing/types';
17
+
18
+ export type CasualApp = 'docs' | 'sheet';
19
+
20
+ /** Common envelope shape — every postMessage on the wire matches this. */
21
+ export interface CasualEnvelope<T = unknown> {
22
+ type: string;
23
+ app: CasualApp;
24
+ /** Per-request id for request/response correlation. Empty for fire-and-forget. */
25
+ id?: string;
26
+ /** Protocol version. Bumped only on breaking changes. */
27
+ v: 1;
28
+ data: T;
29
+ }
30
+
31
+ // ---------------------------------------------------------------
32
+ // Handshake
33
+ // ---------------------------------------------------------------
34
+
35
+ export interface EditorHelloData {
36
+ capabilities: string[];
37
+ version: string;
38
+ commit: string;
39
+ }
40
+
41
+ export interface HostHelloData {
42
+ capabilities: string[];
43
+ authToken?: string;
44
+ }
45
+
46
+ // ---------------------------------------------------------------
47
+ // Load + save (editor → host requests; host → editor responses)
48
+ // ---------------------------------------------------------------
49
+
50
+ export interface LoadRequestData {
51
+ docId: string;
52
+ }
53
+
54
+ export interface LoadResponseDataOk {
55
+ ok: true;
56
+ bytes: ArrayBuffer;
57
+ etag?: string;
58
+ fileName: string;
59
+ readOnly?: boolean;
60
+ }
61
+
62
+ export interface LoadResponseDataErr {
63
+ ok: false;
64
+ code: string;
65
+ message?: string;
66
+ }
67
+
68
+ export type LoadResponseData = LoadResponseDataOk | LoadResponseDataErr;
69
+
70
+ export interface SaveRequestData {
71
+ docId: string;
72
+ bytes: ArrayBuffer;
73
+ baseEtag?: string;
74
+ }
75
+
76
+ export interface SaveResponseDataOk {
77
+ ok: true;
78
+ etag: string;
79
+ }
80
+
81
+ export interface SaveResponseDataErr {
82
+ ok: false;
83
+ code: string;
84
+ etag?: string;
85
+ message?: string;
86
+ }
87
+
88
+ export type SaveResponseData = SaveResponseDataOk | SaveResponseDataErr;
89
+
90
+ // ---------------------------------------------------------------
91
+ // Selection + telemetry + lock (editor → host notifications)
92
+ // ---------------------------------------------------------------
93
+
94
+ export interface SelectionChangedData {
95
+ docs?: { paraId: string; from: number; to: number; selectedText: string };
96
+ sheet?: { sheet: string; from: string; to: string };
97
+ }
98
+
99
+ export interface TelemetryEventData {
100
+ kind: string;
101
+ /** Arbitrary metric fields. */
102
+ [k: string]: unknown;
103
+ }
104
+
105
+ export interface LockLostData {
106
+ reason: 'taken_by_other' | 'expired' | 'host_revoked';
107
+ }
108
+
109
+ // ---------------------------------------------------------------
110
+ // Commands (host → editor)
111
+ // ---------------------------------------------------------------
112
+
113
+ export interface CommandSetReadOnlyData {
114
+ readOnly: boolean;
115
+ }
116
+
117
+ export interface CommandSetThemeData {
118
+ theme: 'light' | 'dark' | 'system';
119
+ }
120
+
121
+ export interface CommandSetLocaleData {
122
+ locale: string;
123
+ }
124
+
125
+ /** Host → editor: switch chrome density between the two consumer-facing
126
+ * modes without re-mounting. `preview` hides toolbar / formula bar /
127
+ * side panel / status bar / sheet tabs and runs read-only; `editor`
128
+ * shows the full UI. Mirrors the `viewMode` prop on `<CasualSheetsIframe>`. */
129
+ export interface CommandSetViewModeData {
130
+ viewMode: 'preview' | 'editor';
131
+ }
132
+
133
+ /** Host → editor: execute a formatting / navigation command against
134
+ * the active selection in the embedded workbook. Hosts (like Casual
135
+ * Drive) build their own toolbar above the iframe and dispatch these
136
+ * commands instead of Univer's built-in ribbon, which the SDK can't
137
+ * ship because the ribbon resolves IRPCChannelService at construction
138
+ * and that service needs a worker the SDK doesn't bundle.
139
+ *
140
+ * v0.6 covered the toggle set; v0.7 adds the rich-format set (font,
141
+ * size, colour, fill) + merge / unmerge. Arg-carrying commands read
142
+ * the relevant field off `args` — every other command ignores it. */
143
+ export interface CommandExecuteData {
144
+ command: // v0.6 — toggle / nav (no args)
145
+ | 'undo'
146
+ | 'redo'
147
+ | 'bold'
148
+ | 'italic'
149
+ | 'underline'
150
+ | 'strikethrough'
151
+ | 'align-left'
152
+ | 'align-center'
153
+ | 'align-right'
154
+ // v0.7 — rich format (args carry the value)
155
+ | 'set-font-family'
156
+ | 'set-font-size'
157
+ | 'set-text-color'
158
+ | 'reset-text-color'
159
+ | 'set-bg-color'
160
+ | 'reset-bg-color'
161
+ | 'merge'
162
+ | 'unmerge'
163
+ // v0.8 — number formats + freeze + wrap
164
+ | 'numfmt-currency'
165
+ | 'numfmt-percent'
166
+ | 'numfmt-add-decimal'
167
+ | 'numfmt-subtract-decimal'
168
+ | 'numfmt-custom'
169
+ | 'wrap-toggle'
170
+ | 'freeze-first-row'
171
+ | 'freeze-first-column'
172
+ | 'freeze-none';
173
+ args?: {
174
+ /** Used by `set-font-family`. */
175
+ family?: string;
176
+ /** Used by `set-font-size`. Integer point size. */
177
+ size?: number;
178
+ /** Used by `set-text-color` and `set-bg-color`. Hex like `#1a73e8`. */
179
+ color?: string;
180
+ /** Used by `numfmt-custom`. The Excel-style format string, e.g.
181
+ * `"#,##0.00"`, `"$#,##0"`, `"0.00%"`, `"d-mmm-yy"`. v0.8+. */
182
+ pattern?: string;
183
+ };
184
+ }
185
+
186
+ /** Editor → host: emitted whenever the selection's active cell's
187
+ * format flags change. Drive's toolbar mirrors this state in the
188
+ * button "pressed" / value indicators so the surface always reflects
189
+ * what the user would see in the cell. v0.7 widens the payload with
190
+ * the rich-format read-back (fontFamily, fontSize, textColor, bgColor)
191
+ * so the toolbar's font picker / size stepper / colour swatches stay
192
+ * in sync without the host having to poll. */
193
+ export interface SelectionFormatStateData {
194
+ bold: boolean;
195
+ italic: boolean;
196
+ underline: boolean;
197
+ strikethrough: boolean;
198
+ align: 'left' | 'center' | 'right' | null;
199
+ /** Defined font family on the active cell, or null when the cell
200
+ * inherits the workbook default. v0.7+. */
201
+ fontFamily: string | null;
202
+ /** Defined font size on the active cell, or null when the cell
203
+ * inherits the workbook default. v0.7+. */
204
+ fontSize: number | null;
205
+ /** Hex text colour like `#1a73e8`, or null when default. v0.7+. */
206
+ textColor: string | null;
207
+ /** Hex background colour, or null when no fill is set. v0.7+. */
208
+ bgColor: string | null;
209
+ }
210
+
211
+ // ---------------------------------------------------------------
212
+ // Errors (editor → host fatal signals)
213
+ // ---------------------------------------------------------------
214
+
215
+ /** Editor → host: a fatal error during boot / load. Hosts surface this
216
+ * via the wrapper's `onError` callback. */
217
+ export interface CasualErrorData {
218
+ code: 'embed_not_served' | 'load_failed' | 'parse_failed' | 'boot_failed' | 'internal';
219
+ message: string;
220
+ }
221
+
222
+ // ---------------------------------------------------------------
223
+ // Signing (uniform with the SDK `signing` prop)
224
+ // ---------------------------------------------------------------
225
+
226
+ export interface SignatureRequestData {
227
+ fields: SignatureField[];
228
+ mode: SignatureMode;
229
+ banner?: string;
230
+ }
231
+
232
+ export interface SignatureRequestAckData {
233
+ ok: boolean;
234
+ code?: string;
235
+ }
236
+
237
+ export type SignatureFieldSignedData = SignedFieldPayload;
238
+ export type SignatureCompleteData = SignatureCompletePayload;
239
+
240
+ export interface SignatureCancelData {
241
+ reason: CancelReason;
242
+ }
243
+
244
+ // ---------------------------------------------------------------
245
+ // Type guards
246
+ // ---------------------------------------------------------------
247
+
248
+ export function isCasualEnvelope(value: unknown): value is CasualEnvelope {
249
+ if (!value || typeof value !== 'object') return false;
250
+ const v = value as Record<string, unknown>;
251
+ return (
252
+ typeof v.type === 'string' &&
253
+ v.type.startsWith('casual.') &&
254
+ (v.app === 'docs' || v.app === 'sheet') &&
255
+ v.v === 1 &&
256
+ 'data' in v
257
+ );
258
+ }
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Casual Sheets (embed)</title>
7
+ <style>
8
+ html, body { margin: 0; padding: 0; height: 100%; background: #fff; overflow: hidden; }
9
+ #casual-embed-root { width: 100%; height: 100%; }
10
+ /* Preview-mode chrome hiding — v0.5.x ties these to component
11
+ props; v0.5.0 lands the wire end-to-end and uses CSS gates. */
12
+ [data-view-mode="preview"] [data-toolbar],
13
+ [data-view-mode="preview"] [data-formula-bar],
14
+ [data-view-mode="preview"] [data-status-bar],
15
+ [data-view-mode="preview"] [data-sheet-tabs] { display: none !important; }
16
+ </style>
17
+ <link rel="stylesheet" href="./embed-runtime.css" />
18
+ </head>
19
+ <body>
20
+ <div id="casual-embed-root"></div>
21
+ <script type="module">
22
+ import { mountEmbedded } from './embed-runtime.js';
23
+ const root = document.getElementById('casual-embed-root');
24
+ if (root) {
25
+ mountEmbedded({ root });
26
+ }
27
+ </script>
28
+ </body>
29
+ </html>