@betteroffice/xlsx-react 0.2.1 → 0.5.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.
package/dist/index.d.ts CHANGED
@@ -1,56 +1,103 @@
1
+ import { XlsxEditRefusal, Selection, XlsxReadRequest, XlsxReadResult, XlsxFindRequest, XlsxFindResult, XlsxEditRequest, XlsxValidationResult, XlsxEditResult, CellRange, CellEdit, EditResult, ProposalEdit, Proposal, WorkbookHandle } from '@betteroffice/xlsx';
2
+ import { AsyncCollaborationReplica, CollaborationReplica, CollaborationAwareness } from '@betteroffice/xlsx/collaboration';
3
+ import { TranslationKey, Translations, TFunction } from '@betteroffice/xlsx-i18n';
1
4
  import * as react from 'react';
2
- import { CSSProperties, ReactNode } from 'react';
3
- import { WorkbookHandle } from '@betteroffice/xlsx';
4
- import { CollaborationReplica, CollaborationAwareness } from '@betteroffice/xlsx/collaboration';
5
- import { Translations, TFunction } from '@betteroffice/xlsx-i18n';
5
+ import { CSSProperties, ReactNode, ComponentType } from 'react';
6
6
 
7
7
  /**
8
- * The imperative surface handed to {@link XlsxEditorProps.onReady}: the open
9
- * workbook handle plus a `refreshProposals` to re-read the pending list after an
10
- * external caller (e.g. a demo agent) stages proposals on the same handle.
8
+ * A value that survives `JSON.stringify` / `JSON.parse` unchanged.
9
+ * @experimental
11
10
  */
12
- interface XlsxEditorApi {
13
- focus: () => void;
14
- handle: WorkbookHandle;
15
- refreshProposals: () => void;
16
- }
17
- interface XlsxEditorCollaborationOptions {
18
- /** Peer-unique Yrs client ID. Generated securely when omitted. */
19
- clientId?: number;
20
- /** Shared Yrs state applied before the replica is exposed. */
21
- initialUpdate?: Uint8Array;
22
- /** Receive the editor-owned collaboration replica. */
23
- onReplica?: (replica: CollaborationReplica | null) => void;
24
- /** Presence-capable provider connected to the editor-owned replica. */
25
- provider?: CollaborationAwareness | null;
11
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
12
+ readonly [key: string]: JsonValue;
13
+ };
14
+ /**
15
+ * A machine-readable code with a localized explanation for people.
16
+ * @experimental
17
+ */
18
+ interface CommandReason<Code extends string = string> {
19
+ code: Code;
20
+ message: string;
26
21
  }
27
22
  /**
28
- * Props for {@link XlsxEditor}.
23
+ * Serializable availability of one editor command. A disabled command always
24
+ * says why; branch on `disabledReason.code`, show `disabledReason.message`.
25
+ * @experimental
29
26
  */
30
- interface XlsxEditorProps {
31
- /** Raw .xlsx bytes to open. When omitted the shell paints a demo frame. */
32
- file?: Uint8Array;
33
- /** Download name for the save button; falls back to `workbook.xlsx`. */
34
- fileName?: string;
35
- /** Receive saved bytes instead of triggering a browser download. */
36
- onSave?: (bytes: Uint8Array) => void;
37
- /** Open a network-ready Yrs replica and repaint when peer updates arrive. */
38
- collaboration?: XlsxEditorCollaborationOptions;
39
- i18n?: Translations;
40
- /**
41
- * Called when a workbook opens, with a handle to stage agent proposals and a
42
- * way to refresh the panel afterward. Enables demo/host agents without
43
- * exposing the wasm object through the render tree. A returned cleanup runs
44
- * before the workbook is replaced or disposed.
45
- */
46
- onReady?: (api: XlsxEditorApi) => void | (() => void);
47
- className?: string;
27
+ type CommandState<Value extends JsonValue = JsonValue, Code extends string = string> = {
28
+ /** Toggle state; `'mixed'` when the selection disagrees. */
29
+ active?: boolean | 'mixed';
30
+ /** The command's current value, such as the selected style or font size. */
31
+ value?: Value;
32
+ } & ({
33
+ enabled: true;
34
+ disabledReason?: never;
35
+ } | {
36
+ enabled: false;
37
+ disabledReason: CommandReason<Code>;
38
+ });
39
+
40
+ /**
41
+ * Plugin DTOs shared by the formats' editor plugin hosts. Clients, selections, anchors, layouts
42
+ * and command maps stay format-owned; these shapes fix grants, lifecycle metadata and refusals.
43
+ */
44
+
45
+ type MaybePromise<T> = T | Promise<T>;
46
+ /**
47
+ * What a host lets one plugin do. Without a grant a plugin reads, validates and navigates only.
48
+ * Built-in commands need their id listed; mutating ones also need `document: 'write'`.
49
+ */
50
+ type PluginGrant<CommandId extends string> = {
51
+ commands?: readonly CommandId[];
52
+ } & ({
53
+ document?: 'read';
54
+ editBatches?: never;
55
+ untrackedHistory?: never;
56
+ } | {
57
+ document: 'write';
58
+ /** Allows applying edit batches. */
59
+ editBatches?: true;
60
+ /** Allows batches with `history: 'none'`. */
61
+ untrackedHistory?: true;
62
+ });
63
+ /** Why a plugin's cleanups run. */
64
+ type PluginCleanupReason = 'removed' | 'document-replaced' | 'definition-replaced' | 'unmounted' | 'failed';
65
+ /** `attached`: the plugin was added while a document was open. */
66
+ type PluginLoadReason = 'loaded' | 'replaced' | 'attached';
67
+ type PluginFailureCode = 'plugin-unavailable' | 'document-replaced' | 'aborted' | 'permission-denied' | 'read-only' | 'input-failed' | 'unsupported-policy' | 'plugin-failed';
68
+ /** A plugin client call refused before it reached the document. */
69
+ interface PluginRefusal<Code extends string = PluginFailureCode> {
70
+ ok: false;
71
+ failure: CommandReason<Code>;
72
+ }
73
+ type PluginErrorPhase = 'definition' | 'initialize' | 'event' | 'render' | 'command-state' | 'command' | 'cleanup' | 'action';
74
+ /** A plugin failure reported to the host; `generation` is null outside a document. */
75
+ interface PluginError<Phase extends string = PluginErrorPhase> {
76
+ pluginId: string;
77
+ generation: string | null;
78
+ phase: Phase;
79
+ error: unknown;
48
80
  }
49
81
  /**
50
- * The xlsx editor React component.
82
+ * Outcome of a contributed command. Failure codes are the plugin's own, and a refused edit batch
83
+ * can be returned as-is, keeping its structured failure.
51
84
  */
52
- declare function XlsxEditor({ i18n, ...props }: XlsxEditorProps): react.JSX.Element;
85
+ type PluginCommandResult<Status extends string = string, Refusal extends {
86
+ ok: false;
87
+ } = never> = {
88
+ ok: true;
89
+ status: Status;
90
+ } | {
91
+ ok: false;
92
+ failure: CommandReason;
93
+ } | Refusal;
53
94
 
95
+ /**
96
+ * How a toolbar gets its state: `'legacy'` from props and callbacks,
97
+ * `'commands'` from the editor's command store.
98
+ * @experimental
99
+ */
100
+ type ToolbarMode = 'legacy' | 'commands';
54
101
  type NumberFormat = 'automatic' | 'plainText' | 'number' | 'percent' | 'scientific' | 'currency' | 'date' | 'time' | 'custom';
55
102
  type BorderPreset = 'all' | 'inner' | 'horizontal' | 'vertical' | 'outer' | 'left' | 'top' | 'right' | 'bottom' | 'none';
56
103
  type BorderStyle = 'solid' | 'dashed' | 'dotted' | 'double';
@@ -133,25 +180,935 @@ interface ToolbarProps {
133
180
  disabled?: boolean;
134
181
  className?: string;
135
182
  style?: CSSProperties;
183
+ /** Legacy mode appends these after the built-in controls; commands mode renders only these. */
136
184
  children?: ReactNode;
185
+ /**
186
+ * `'commands'` binds the built-in controls to the editor's commands, and
187
+ * rejects the state and callback props above. Defaults to the mode of the
188
+ * surrounding `EditorToolbar`, else `'legacy'`.
189
+ * @experimental
190
+ */
191
+ mode?: ToolbarMode;
137
192
  }
138
- declare function Toolbar(explicitProps: ToolbarProps): react.JSX.Element;
193
+ /**
194
+ * The formatting rail. In legacy mode it renders the default controls from
195
+ * props and appends `children`; in commands mode, `children` replace the
196
+ * default arrangement. Narrow rails move trailing groups into a "More" menu.
197
+ */
198
+ declare function Toolbar(props: ToolbarProps): react.JSX.Element;
139
199
 
140
- type EditorToolbarProps = ToolbarProps;
200
+ /**
201
+ * Arguments of every XLSX editor command, keyed by command id.
202
+ * @experimental
203
+ */
204
+ interface XlsxCommandArgs {
205
+ bold: null;
206
+ italic: null;
207
+ strikethrough: null;
208
+ /** Captures the selection's formatting; the next selection receives it. */
209
+ paintFormat: null;
210
+ fontFamily: {
211
+ family: string;
212
+ };
213
+ /** Size in points, 1 to 400. */
214
+ fontSize: {
215
+ points: number;
216
+ };
217
+ fontSizeStep: {
218
+ direction: 'increase' | 'decrease';
219
+ };
220
+ /** `#rrggbb`. */
221
+ textColor: {
222
+ color: string;
223
+ };
224
+ /** `#rrggbb`. */
225
+ fillColor: {
226
+ color: string;
227
+ };
228
+ /** `'custom'` applies the selection's custom pattern, or `0.00`. */
229
+ numberFormat: {
230
+ value: NumberFormat;
231
+ };
232
+ decimalPlaces: {
233
+ direction: 'increase' | 'decrease';
234
+ };
235
+ /** Applies the preset with the current border style and color. */
236
+ borderPreset: {
237
+ value: BorderPreset;
238
+ };
239
+ borderStyle: {
240
+ value: BorderStyle;
241
+ };
242
+ /** `#rrggbb`. */
243
+ borderColor: {
244
+ color: string;
245
+ };
246
+ merge: {
247
+ value: MergeAction;
248
+ };
249
+ horizontalAlignment: {
250
+ value: HorizontalAlignment;
251
+ };
252
+ verticalAlignment: {
253
+ value: VerticalAlignment;
254
+ };
255
+ textWrapping: {
256
+ value: TextWrapping;
257
+ };
258
+ searchMenus: null;
259
+ save: null;
260
+ exportPng: null;
261
+ print: null;
262
+ undo: null;
263
+ redo: null;
264
+ /** 1 is 100%; 0.1 to 5. */
265
+ zoom: {
266
+ scale: number;
267
+ };
268
+ /** `null` toggles the panel. */
269
+ proposalsPanel: {
270
+ open: boolean;
271
+ } | null;
272
+ /** `force` applies a proposal whose cells changed since it was staged. */
273
+ proposalAccept: {
274
+ proposalId: string;
275
+ force?: boolean;
276
+ };
277
+ proposalReject: {
278
+ proposalId: string;
279
+ };
280
+ }
281
+ /** @experimental */
282
+ type XlsxCommandId = keyof XlsxCommandArgs;
283
+ /**
284
+ * Commands presented as a choice between options.
285
+ * @experimental
286
+ */
287
+ type XlsxSelectCommandId = 'fontFamily' | 'fontSize' | 'numberFormat' | 'borderPreset' | 'borderStyle' | 'merge' | 'horizontalAlignment' | 'verticalAlignment' | 'textWrapping' | 'zoom';
288
+ /**
289
+ * Number format of the selection; `kind` is `null` when the cells disagree.
290
+ * @experimental
291
+ */
292
+ type XlsxNumberFormatValue = {
293
+ kind: NumberFormat | null;
294
+ pattern: string | null;
295
+ };
296
+ /**
297
+ * Current values reported in {@link XlsxCommandState.value}, keyed by command id.
298
+ * @experimental
299
+ */
300
+ interface XlsxCommandValues {
301
+ bold: null;
302
+ italic: null;
303
+ strikethrough: null;
304
+ paintFormat: null;
305
+ fontFamily: string | null;
306
+ /** Points; `null` when mixed or unknown. */
307
+ fontSize: number | null;
308
+ fontSizeStep: null;
309
+ /** `#rrggbb`; `null` when mixed or unknown. */
310
+ textColor: string | null;
311
+ fillColor: string | null;
312
+ numberFormat: XlsxNumberFormatValue | null;
313
+ decimalPlaces: null;
314
+ borderPreset: BorderPreset | null;
315
+ /** The style the next border preset applies. */
316
+ borderStyle: BorderStyle | null;
317
+ /** The color the next border preset applies. */
318
+ borderColor: string | null;
319
+ /** Size of the selected range. */
320
+ merge: {
321
+ rows: number;
322
+ columns: number;
323
+ } | null;
324
+ horizontalAlignment: HorizontalAlignment | null;
325
+ verticalAlignment: VerticalAlignment | null;
326
+ textWrapping: TextWrapping | null;
327
+ searchMenus: null;
328
+ save: null;
329
+ exportPng: null;
330
+ print: null;
331
+ undo: null;
332
+ redo: null;
333
+ zoom: number;
334
+ /** Number of pending proposals. */
335
+ proposalsPanel: number;
336
+ proposalAccept: null;
337
+ proposalReject: null;
338
+ }
339
+ /**
340
+ * Why a command is unavailable.
341
+ * @experimental
342
+ */
343
+ type XlsxCommandDisabledCode = 'editor-unavailable' | 'document-loading' | 'no-document' | 'read-only' | 'cell-selection-required' | 'unsupported-selection' | 'multiple-cells-required' | 'multiple-columns-required' | 'multiple-rows-required' | 'no-merged-cells' | 'collaboration-unsupported' | 'nothing-to-undo' | 'nothing-to-redo' | 'png-unavailable' | 'no-proposals' | 'proposal-not-found' | 'host-disabled' | 'unsupported-command' | 'invalid-arguments' | 'permission-denied' | 'unsupported-policy' | 'plugin-unavailable';
344
+ /**
345
+ * Why an executed command did not complete.
346
+ * @experimental
347
+ */
348
+ type XlsxCommandFailureCode = XlsxCommandDisabledCode | 'input-failed' | 'document-replaced' | 'target-changed' | 'gesture-active' | 'proposal-stale' | 'render-failed' | 'command-failed' | 'aborted';
349
+ /**
350
+ * One choice of a selector command.
351
+ * @experimental
352
+ */
353
+ interface XlsxCommandOption<K extends XlsxCommandId = XlsxCommandId> {
354
+ args: XlsxCommandArgs[K];
355
+ label: string;
356
+ /** The state of the command for these arguments, as `getState(id, args)` reports it. */
357
+ state: CommandState<XlsxCommandValues[K], XlsxCommandDisabledCode>;
358
+ }
359
+ /**
360
+ * Serializable state of one XLSX command, optionally for specific arguments.
361
+ * @experimental
362
+ */
363
+ type XlsxCommandState<K extends XlsxCommandId = XlsxCommandId> = CommandState<XlsxCommandValues[K], XlsxCommandDisabledCode> & {
364
+ /** Choices a selector presents, in display order. */
365
+ options?: readonly XlsxCommandOption<K>[];
366
+ };
367
+ /**
368
+ * A keyboard binding; `Mod` is Cmd on macOS and Ctrl elsewhere.
369
+ * @experimental
370
+ */
371
+ interface XlsxCommandShortcut<K extends XlsxCommandId = XlsxCommandId> {
372
+ chord: string;
373
+ args: XlsxCommandArgs[K];
374
+ }
375
+ /**
376
+ * Static, serializable description of a command.
377
+ * @experimental
378
+ */
379
+ interface XlsxCommandDescriptor<K extends XlsxCommandId = XlsxCommandId> {
380
+ id: K;
381
+ labelKey: TranslationKey;
382
+ mutatesDocument: boolean;
383
+ shortcuts: readonly XlsxCommandShortcut<K>[];
384
+ }
385
+ /** @experimental */
386
+ type XlsxCommandStatus = 'executed' | 'noop' | 'opened' | 'requested';
387
+ /**
388
+ * Outcome of {@link XlsxCommandStore.execute}: `executed` changed something,
389
+ * `noop` was valid but changed nothing, `opened` showed a picker, and
390
+ * `requested` handed the change to the host.
391
+ * @experimental
392
+ */
393
+ type XlsxCommandResult = {
394
+ ok: true;
395
+ status: XlsxCommandStatus;
396
+ } | {
397
+ ok: false;
398
+ failure: CommandReason<XlsxCommandFailureCode>;
399
+ };
400
+ /**
401
+ * A command a plugin contributes, registered as `plugin:<pluginId>/<localId>`.
402
+ * @experimental
403
+ */
404
+ type XlsxPluginCommandId = `plugin:${string}/${string}`;
405
+ /**
406
+ * Static description of a contributed command.
407
+ * @experimental
408
+ */
409
+ interface XlsxPluginCommandDescriptor {
410
+ id: XlsxPluginCommandId;
411
+ label: string;
412
+ mutatesDocument: boolean;
413
+ shortcuts: readonly {
414
+ chord: string;
415
+ args: null;
416
+ }[];
417
+ }
418
+ /**
419
+ * State of a contributed command; the plugin chooses its own disabled codes.
420
+ * @experimental
421
+ */
422
+ type XlsxPluginCommandState = CommandState;
423
+ /**
424
+ * Outcome of a contributed command: a plugin-defined failure, or a refused edit batch as-is.
425
+ *
426
+ * @experimental The plugin API may change in minor releases.
427
+ */
428
+ type XlsxPluginCommandResult = PluginCommandResult<XlsxCommandStatus, XlsxEditRefusal>;
429
+ /**
430
+ * The command authority of one editor, shared by built-in and host chrome.
431
+ * @experimental
432
+ */
433
+ interface XlsxCommandStore {
434
+ getDescriptor<K extends XlsxCommandId>(id: K): XlsxCommandDescriptor<K>;
435
+ /** Null while no active plugin contributes `id`. */
436
+ getDescriptor(id: XlsxPluginCommandId): XlsxPluginCommandDescriptor | null;
437
+ /** Snapshots are stable until the state changes; pass `args` to evaluate one option. */
438
+ getState<K extends XlsxCommandId>(id: K, args?: XlsxCommandArgs[K]): XlsxCommandState<K>;
439
+ getState(id: XlsxPluginCommandId, args?: null): XlsxPluginCommandState;
440
+ subscribe(listener: () => void): () => void;
441
+ /** Runs after input accepted before the call; availability is checked again first. */
442
+ execute<K extends XlsxCommandId>(id: K, args: XlsxCommandArgs[K]): Promise<XlsxCommandResult>;
443
+ /** Runs a contributed command with its plugin's own clients, outside the input queue. */
444
+ execute(id: XlsxPluginCommandId, args: null): Promise<XlsxPluginCommandResult>;
445
+ }
446
+
447
+ /** Why work queued behind accepted input could not run. */
448
+ type XlsxCommandAdmissionCode = Extract<XlsxCommandFailureCode, 'input-failed' | 'document-replaced' | 'target-changed' | 'gesture-active' | 'editor-unavailable'>;
449
+ /**
450
+ * Raised when work queued behind accepted input cannot run: a command, or a version, read or
451
+ * edit-batch call of the editor API.
452
+ */
453
+ declare class XlsxCommandAdmissionError extends Error {
454
+ readonly code: XlsxCommandAdmissionCode;
455
+ constructor(code: XlsxCommandAdmissionCode);
456
+ }
457
+
458
+ /**
459
+ * What the host lets one plugin do. Without a grant a plugin reads, validates and navigates only.
460
+ * Built-in commands need their id listed and, when they mutate, `document: 'write'`; edit
461
+ * batches need `document: 'write'` and `editBatches`, and `history: 'none'` also needs
462
+ * `untrackedHistory`. `readOnly` refuses every write regardless.
463
+ *
464
+ * @experimental The plugin API may change in minor releases.
465
+ */
466
+ type XlsxPluginGrant = PluginGrant<XlsxCommandId>;
467
+ type XlsxPluginFailureCode = PluginFailureCode;
468
+ /**
469
+ * A client call refused before it reached the workbook.
470
+ *
471
+ * @experimental The plugin API may change in minor releases.
472
+ */
473
+ type XlsxPluginRefusal = PluginRefusal<XlsxPluginFailureCode>;
474
+ /**
475
+ * Versioned workbook reads. Each runs after pending input.
476
+ *
477
+ * @experimental The plugin API may change in minor releases.
478
+ */
479
+ interface XlsxPluginReadClient {
480
+ version(): Promise<{
481
+ ok: true;
482
+ version: string;
483
+ } | XlsxPluginRefusal>;
484
+ readCells(request: XlsxReadRequest): Promise<XlsxReadResult | XlsxPluginRefusal>;
485
+ findText(request: XlsxFindRequest): Promise<XlsxFindResult | XlsxPluginRefusal>;
486
+ /** Checks a batch without granting anything; a later apply is checked again. */
487
+ validateEdits(request: XlsxEditRequest): Promise<XlsxValidationResult | XlsxPluginRefusal>;
488
+ }
489
+ /**
490
+ * Granted edit batches; the grant and `readOnly` are checked when the batch applies.
491
+ *
492
+ * @experimental The plugin API may change in minor releases.
493
+ */
494
+ interface XlsxPluginEditClient {
495
+ applyEdits(request: XlsxEditRequest): Promise<XlsxEditResult | XlsxPluginRefusal>;
496
+ }
497
+ /**
498
+ * The editor's commands as this plugin may use them.
499
+ *
500
+ * @experimental The plugin API may change in minor releases.
501
+ */
502
+ interface XlsxPluginCommandClient {
503
+ getDescriptor<K extends XlsxCommandId>(id: K): XlsxCommandDescriptor<K>;
504
+ getDescriptor(id: XlsxPluginCommandId): XlsxPluginCommandDescriptor | null;
505
+ getState<K extends XlsxCommandId>(id: K, args?: XlsxCommandArgs[K]): XlsxCommandState<K> | {
506
+ enabled: false;
507
+ disabledReason: XlsxPluginRefusal['failure'];
508
+ };
509
+ getState(id: XlsxPluginCommandId, args?: null): XlsxPluginCommandState;
510
+ subscribe(listener: () => void): () => void;
511
+ execute<K extends XlsxCommandId>(id: K, args: XlsxCommandArgs[K]): Promise<XlsxCommandResult | XlsxPluginRefusal>;
512
+ /** Only this plugin's own contributed commands. */
513
+ execute(id: XlsxPluginCommandId, args: null): Promise<XlsxPluginCommandResult | XlsxPluginRefusal>;
514
+ }
515
+ /** A rectangle in overlay pixels. */
516
+ interface XlsxPluginRect {
517
+ x: number;
518
+ y: number;
519
+ width: number;
520
+ height: number;
521
+ }
522
+ /** A painted grid frame and the workbook version its pixels show. */
523
+ interface XlsxPluginLayout {
524
+ /** Changes with every painted frame, sheet, zoom and scroll; unrelated to document versions. */
525
+ id: string;
526
+ version: string;
527
+ sheetId: string;
528
+ zoom: number;
529
+ /** The painted part of the sheet, in unzoomed sheet pixels; `x`/`y` scroll the body. */
530
+ viewport: {
531
+ x: number;
532
+ y: number;
533
+ width: number;
534
+ height: number;
535
+ };
536
+ }
537
+ /** A cell under the pointer, with the layout it was resolved against. */
538
+ interface XlsxPluginCellPosition {
539
+ sheetId: string;
540
+ row: number;
541
+ col: number;
542
+ version: string;
543
+ layoutId: string;
544
+ }
545
+ /**
546
+ * Geometry of the painted grid. Rectangles are in pixels of the overlay layer, already zoomed
547
+ * and clipped to the visible grid; every method returns null once its layout is no longer
548
+ * painted, and for cells scrolled out of view or on another sheet.
549
+ */
550
+ interface XlsxPluginGeometry {
551
+ layout: XlsxPluginLayout;
552
+ /** One grid cell, without merge expansion; zero-based `row` and `col`. */
553
+ getCellRect(target: {
554
+ sheetId: string;
555
+ row: number;
556
+ col: number;
557
+ }): XlsxPluginRect | null;
558
+ /** The visible part of an inclusive range, such as a merged area. */
559
+ getRangeRect(target: {
560
+ sheetId: string;
561
+ range: CellRange;
562
+ }): XlsxPluginRect | null;
563
+ /** Client-coordinate hit testing; null until the editor exposes it. */
564
+ getPositionAtPoint: ((clientX: number, clientY: number) => XlsxPluginCellPosition | null) | null;
565
+ }
566
+ /** The active sheet and what is selected on it; ids are session-scoped. */
567
+ type XlsxPluginSelection = {
568
+ sheetId: string;
569
+ /** Zero-based position in the workbook. */
570
+ sheetIndex: number;
571
+ /** Zero-based cells; `focus` may precede `anchor`. Null while nothing is selected. */
572
+ cells: Selection | null;
573
+ /** The selected chart, while one is selected instead of cells. */
574
+ chartId: string | null;
575
+ } | null;
576
+ interface XlsxPluginSnapshot {
577
+ /** The open workbook; changes when a workbook replaces it. */
578
+ generation: string;
579
+ version: string;
580
+ readOnly: boolean;
581
+ grant: XlsxPluginGrant;
582
+ selection: XlsxPluginSelection;
583
+ /** Null while no painted frame shows `version`. */
584
+ layout: XlsxPluginLayout | null;
585
+ }
586
+ type XlsxPluginNavigationFailureCode = 'stale-version' | 'missing-target' | 'ambiguous-target' | 'layout-unavailable' | 'unsupported';
587
+ /** @experimental The plugin API may change in minor releases. */
588
+ type XlsxPluginNavigationResult = {
589
+ ok: true;
590
+ } | XlsxPluginRefusal | {
591
+ ok: false;
592
+ failure: {
593
+ code: XlsxPluginNavigationFailureCode;
594
+ message: string;
595
+ };
596
+ };
597
+ interface XlsxPluginNavigationOptions {
598
+ /** The version the target was read at; a newer workbook refuses with `stale-version`. */
599
+ expectVersion: string;
600
+ }
601
+ /**
602
+ * Navigation after pending input, against the current workbook. It never writes.
603
+ *
604
+ * @experimental The plugin API may change in minor releases.
605
+ */
606
+ interface XlsxPluginNavigation {
607
+ /**
608
+ * Activates the sheet, selects `selection` in its direction and reveals its anchor (the active cell).
609
+ * Keyboard focus stays where it is unless `focus` is true.
610
+ */
611
+ selectCells(target: {
612
+ sheetId: string;
613
+ selection: Selection;
614
+ }, options: XlsxPluginNavigationOptions & {
615
+ focus?: boolean;
616
+ }): Promise<XlsxPluginNavigationResult>;
617
+ /**
618
+ * Reveals a cell, `nearest` by default. The selection stays on the current sheet; on another
619
+ * sheet, which becomes active, nothing is selected.
620
+ */
621
+ scrollToCell(target: {
622
+ sheetId: string;
623
+ row: number;
624
+ col: number;
625
+ }, options: XlsxPluginNavigationOptions & {
626
+ align?: 'nearest' | 'start' | 'center';
627
+ }): Promise<XlsxPluginNavigationResult>;
628
+ }
629
+ /** Lifecycle notifications describe current state; several changes may arrive as one. */
630
+ type XlsxPluginEvent = {
631
+ type: 'load';
632
+ generation: string;
633
+ version: string;
634
+ reason: PluginLoadReason;
635
+ } | {
636
+ type: 'document-change';
637
+ generation: string;
638
+ version: string;
639
+ } | {
640
+ type: 'selection-change';
641
+ generation: string;
642
+ version: string;
643
+ selection: XlsxPluginSelection;
644
+ } | {
645
+ type: 'mode-change';
646
+ generation: string;
647
+ readOnly: boolean;
648
+ } | {
649
+ type: 'layout-change';
650
+ generation: string;
651
+ layout: XlsxPluginLayout | null;
652
+ } | {
653
+ type: 'grants-change';
654
+ generation: string;
655
+ grant: XlsxPluginGrant;
656
+ };
657
+ /**
658
+ * What a hook, renderer or action receives. Clients refuse once it is superseded or ended.
659
+ *
660
+ * @experimental The plugin API may change in minor releases.
661
+ */
662
+ interface XlsxPluginContext<S> {
663
+ pluginId: string;
664
+ snapshot: XlsxPluginSnapshot;
665
+ readonly state: Readonly<S>;
666
+ /** Aborted when this hook is superseded or the plugin ends. */
667
+ signal: AbortSignal;
668
+ /** Aborted when this activation ends. */
669
+ lifetimeSignal: AbortSignal;
670
+ read: XlsxPluginReadClient;
671
+ commands: XlsxPluginCommandClient;
672
+ /** Null without an edit batch grant. */
673
+ edits: XlsxPluginEditClient | null;
674
+ /** Null while no painted frame shows the current version. */
675
+ geometry: XlsxPluginGeometry | null;
676
+ navigation: XlsxPluginNavigation;
677
+ /**
678
+ * Replaces the plugin's state. Returns false for a superseded context, an ended plugin, or when
679
+ * the workbook is no longer at `atVersion`, which defaults to `snapshot.version`.
680
+ */
681
+ setState(next: S | ((previous: S) => S), atVersion?: string): boolean;
682
+ /** Registers a disposer; after the plugin ended it runs at once. */
683
+ onCleanup(cleanup: (reason: PluginCleanupReason) => MaybePromise<void>): void;
684
+ /** Runs an event-handler action with a fresh context, isolating its failure. */
685
+ run(action: (context: XlsxPluginContext<S>) => MaybePromise<void>): Promise<void>;
686
+ }
687
+ interface XlsxPluginPanel<S> {
688
+ title: string;
689
+ placement: 'left' | 'right' | 'bottom';
690
+ /** Width for side panels, height for the bottom panel, in CSS pixels. */
691
+ preferredSize?: number;
692
+ defaultCollapsed?: boolean;
693
+ render: ComponentType<{
694
+ context: XlsxPluginContext<S>;
695
+ width: number;
696
+ height: number;
697
+ }>;
698
+ }
699
+ /** A command registered as `plugin:<pluginId>/<id>`. */
700
+ interface XlsxPluginCommand<S> {
701
+ id: string;
702
+ label: string;
703
+ /** Disables the command while read-only; grants nothing. */
704
+ mutatesDocument: boolean;
705
+ /**
706
+ * Chords such as `Mod+Shift+R` or `F7`: each uses Mod or Alt, or is F1 to F12. Built-in shortcuts
707
+ * and keys the grid handles take precedence; a clashing chord is reported and not bound.
708
+ */
709
+ shortcuts?: readonly string[];
710
+ getState?(context: XlsxPluginContext<S>): CommandState;
711
+ execute(context: XlsxPluginContext<S>): MaybePromise<XlsxPluginCommandResult>;
712
+ }
713
+ /**
714
+ * A plugin. `createState`, renderers and command `getState` must be pure; `initialize`,
715
+ * `onEvent`, command `execute` and `context.run` are managed effects.
716
+ *
717
+ * @experimental The plugin API may change in minor releases.
718
+ */
719
+ interface XlsxPluginDefinition<S> {
720
+ id: string;
721
+ /** Changing it restarts the plugin; other definition changes keep its state. */
722
+ revision?: string | number;
723
+ createState(): S;
724
+ initialize?(context: XlsxPluginContext<S>): MaybePromise<void>;
725
+ onEvent?(context: XlsxPluginContext<S>, event: XlsxPluginEvent): MaybePromise<void>;
726
+ panel?: XlsxPluginPanel<S>;
727
+ overlay?: ComponentType<{
728
+ context: XlsxPluginContext<S>;
729
+ geometry: XlsxPluginGeometry;
730
+ }>;
731
+ commands?: readonly XlsxPluginCommand<S>[];
732
+ /** Local command ids, in display order. */
733
+ toolbar?: readonly string[];
734
+ }
735
+ declare const xlsxPluginBrand: unique symbol;
736
+ /**
737
+ * An installable plugin, created by `defineXlsxPlugin`.
738
+ *
739
+ * @experimental The plugin API may change in minor releases.
740
+ */
741
+ interface XlsxPlugin {
742
+ readonly id: string;
743
+ readonly revision?: string | number;
744
+ readonly [xlsxPluginBrand]: true;
745
+ }
746
+ type XlsxPluginErrorPhase = PluginErrorPhase;
747
+ /**
748
+ * A plugin failure; the failing activation has already been stopped and cleaned up.
749
+ *
750
+ * @experimental The plugin API may change in minor releases.
751
+ */
752
+ type XlsxPluginError = PluginError<XlsxPluginErrorPhase>;
753
+ /** @experimental The plugin API may change in minor releases. */
754
+ interface XlsxEditorPluginProps {
755
+ /** @experimental The plugin API may change in minor releases. */
756
+ plugins?: readonly XlsxPlugin[];
757
+ /**
758
+ * Keyed by plugin id; omitted plugins read, validate and navigate only.
759
+ *
760
+ * @experimental The plugin API may change in minor releases.
761
+ */
762
+ pluginGrants?: Readonly<Record<string, XlsxPluginGrant>>;
763
+ /** @experimental The plugin API may change in minor releases. */
764
+ onPluginError?(error: XlsxPluginError): void;
765
+ }
766
+
767
+ declare class WorkerInputNotReadyError extends Error {
768
+ constructor();
769
+ }
770
+
771
+ /** @experimental */
772
+ declare class XlsxPeerNotReadyError extends WorkerInputNotReadyError {
773
+ constructor();
774
+ }
775
+ /** @experimental */
776
+ declare class XlsxWorkerEditorCollaborationError extends Error {
777
+ readonly code = "collaboration-unavailable";
778
+ constructor();
779
+ }
780
+ /** @deprecated Removed in 0.6.0. Use XlsxAsyncEditorApi. */
781
+ interface XlsxWorkerEditorApi extends Omit<XlsxWorkerViewerApi, 'save' | 'selectCells'> {
782
+ readonly hydrated: boolean;
783
+ readonly failure: Error | null;
784
+ whenHydrated(): Promise<void>;
785
+ flush(): Promise<void>;
786
+ save(): Promise<Uint8Array | null>;
787
+ recoverySave(): Promise<{
788
+ bytes: Uint8Array;
789
+ recovery: true;
790
+ }>;
791
+ selectCells(sheet: number, selection: Selection): boolean;
792
+ cell(sheet: number, row: number, col: number): CellEdit | null;
793
+ cellAsync(sheet: number, row: number, col: number): Promise<CellEdit | null>;
794
+ rangeCells(sheet: number, range: string): CellEdit[][];
795
+ rangeCellsAsync(sheet: number, range: string): Promise<CellEdit[][] | null>;
796
+ readCellsSync(request: XlsxReadRequest): XlsxReadResult | null;
797
+ editCell(sheet: number, row: number, col: number, input: string): EditResult;
798
+ editCellAsync(sheet: number, row: number, col: number, input: string): Promise<EditResult | null>;
799
+ }
800
+
801
+ declare class XlsxWorkerSessionFailedError extends Error {
802
+ readonly cause: unknown;
803
+ readonly code = "worker-session-failed";
804
+ constructor(cause: unknown);
805
+ }
806
+
807
+ declare class XlsxAsyncApiSyncAccessError extends Error {
808
+ readonly member: string;
809
+ readonly alternative: string;
810
+ readonly code = "sync-api-unavailable";
811
+ constructor(member: string, alternative: string);
812
+ }
813
+
814
+ interface XlsxProposalRequest {
815
+ agentId: string;
816
+ note?: string | null;
817
+ edits: ProposalEdit[];
818
+ }
819
+ type XlsxProposalResult = {
820
+ ok: true;
821
+ proposal: Proposal;
822
+ } | Extract<XlsxCommandResult, {
823
+ ok: false;
824
+ }>;
825
+ /**
826
+ * Host reads, edits and saves commit pending input first. Admission rejects with
827
+ * XlsxCommandAdmissionError for input-failed, document-replaced or editor-unavailable.
828
+ * Session failures reject with the session error.
829
+ * @experimental
830
+ */
831
+ interface XlsxAsyncEditorApi {
832
+ readonly hydrated: boolean;
833
+ readonly failure: Error | null;
834
+ whenHydrated(): Promise<void>;
835
+ recoverySave(): Promise<{
836
+ bytes: Uint8Array;
837
+ recovery: true;
838
+ }>;
839
+ /** Commits pending input before reading the workbook version. */
840
+ version(): Promise<string>;
841
+ /** Reads cells after pending input commits. */
842
+ readCells(request: XlsxReadRequest): Promise<XlsxReadResult>;
843
+ /** Searches display text after pending input commits. */
844
+ findText(request: XlsxFindRequest): Promise<XlsxFindResult>;
845
+ /** Refuses with `read-only` while the editor is read-only. */
846
+ validateEdits(request: XlsxEditRequest): Promise<XlsxValidationResult>;
847
+ /** Applies against `expectVersion` after pending input commits; notifies once if applied. */
848
+ applyEdits(request: XlsxEditRequest): Promise<XlsxEditResult>;
849
+ /** Commits pending input, returns bytes and calls onSave without downloading. */
850
+ save(): Promise<Uint8Array>;
851
+ readonly commands: XlsxCommandStore;
852
+ readonly collaboration: AsyncCollaborationReplica | null;
853
+ /** Stages tracked cell edits after pending input drains; available on worker editors. */
854
+ proposeChanges?(request: XlsxProposalRequest): Promise<XlsxProposalResult>;
855
+ focus(): void;
856
+ renderPng(...args: Parameters<WorkbookHandle['renderPng']>): Promise<ReturnType<WorkbookHandle['renderPng']>>;
857
+ renderRangePng(...args: Parameters<WorkbookHandle['renderRangePng']>): Promise<ReturnType<WorkbookHandle['renderRangePng']>>;
858
+ exportStructured(...args: Parameters<WorkbookHandle['exportStructured']>): Promise<ReturnType<WorkbookHandle['exportStructured']>>;
859
+ exportMarkdown(...args: Parameters<WorkbookHandle['exportMarkdown']>): Promise<ReturnType<WorkbookHandle['exportMarkdown']>>;
860
+ printDisplayList(...args: Parameters<WorkbookHandle['printDisplayList']>): Promise<ReturnType<WorkbookHandle['printDisplayList']>>;
861
+ }
862
+
863
+ declare const LEGACY_SYNC_API: "legacySyncApi";
864
+
865
+ /**
866
+ * `<XlsxEditor />` — the editor shell. A dpr-aware canvas paints the grid; DOM
867
+ * overlays (selection marquee, active-cell outline, in-cell editor) sit above it,
868
+ * positioned from the same display-list geometry the painter uses. A top bar
869
+ * holds the name box, formula bar, and save/undo/redo; an offscreen `role=grid`
870
+ * mirror serves screen readers. All compute lives in `@betteroffice/xlsx`; this
871
+ * layer is framework glue — keyboard/mouse wiring, focus flow, and DOM chrome.
872
+ */
873
+
874
+ interface XlsxPointPosition {
875
+ sheet: number;
876
+ row: number;
877
+ col: number;
878
+ }
879
+ /**
880
+ * The imperative surface handed to {@link XlsxEditorProps.onReady}: the open
881
+ * workbook handle plus a `refreshProposals` to re-read the pending list after an
882
+ * external caller (e.g. a demo agent) stages proposals on the same handle.
883
+ *
884
+ * The version, read and edit-batch methods run in order with the input accepted
885
+ * before them, as commands do: cell and formula entries, chart moves, pastes and
886
+ * cuts land first, and an IME composition ends with its text written. They reject
887
+ * with {@link XlsxCommandAdmissionError}: `input-failed` while a refused entry
888
+ * waits for correction or earlier input failed, `gesture-active` during a chart
889
+ * drag, and `document-replaced` when the workbook is replaced meanwhile.
890
+ * @deprecated Removed in 0.6.0. Use XlsxAsyncEditorApi.
891
+ */
892
+ interface XlsxEditorApi {
893
+ flushPendingInput: () => Promise<void>;
894
+ /** Client coordinates; sheet, row and column are zero-based. */
895
+ getPositionAtPoint: (clientX: number, clientY: number) => XlsxPointPosition | null;
896
+ /**
897
+ * Closes the open cell entry and clears the selection. The entry is written
898
+ * at once, or queued behind input still waiting to be written. An entry the
899
+ * workbook refuses stays open, and nothing changes; one it refused earlier
900
+ * on this sheet reopens at its own cell.
901
+ */
902
+ clearSelection: () => void;
903
+ /**
904
+ * The editor's command store, shared by its toolbar and host chrome. It
905
+ * gates the editor's own UI; `handle` stays unrestricted host authority.
906
+ * @experimental
907
+ */
908
+ readonly commands: XlsxCommandStore;
909
+ focus: () => void;
910
+ handle: WorkbookHandle;
911
+ refreshProposals: () => void;
912
+ /**
913
+ * Writes the open cell entry and returns the workbook bytes at once. Throws
914
+ * {@link XlsxSaveRefusedError} rather than return bytes without accepted
915
+ * input: `input-pending` while earlier entries or a paste still wait to be
916
+ * written (await `commands.execute('save', null)` instead), `input-failed`
917
+ * while an entry the workbook refused waits for correction.
918
+ */
919
+ save: () => Uint8Array;
920
+ /**
921
+ * Scrolls the focus cell into view. Commands run after it, even in the same
922
+ * handler, act on this selection and sheet. The open cell entry is written
923
+ * first, or queued behind input still waiting to be written, so it may not
924
+ * have landed when this returns. False, changing nothing, for an invalid
925
+ * target or an open entry the workbook refuses; an entry it refused earlier
926
+ * on `sheet` reopens at its own cell.
927
+ */
928
+ selectCells: (sheet: number, selection: Selection) => boolean;
929
+ version: () => Promise<string>;
930
+ readCells: (request: XlsxReadRequest) => Promise<XlsxReadResult>;
931
+ findText: (request: XlsxFindRequest) => Promise<XlsxFindResult>;
932
+ /** Refuses with `read-only` while the editor is read-only. */
933
+ validateEdits: (request: XlsxEditRequest) => Promise<XlsxValidationResult>;
934
+ /**
935
+ * Applies the batch against the caller's `expectVersion` after committing pending input,
936
+ * so input that lands first refuses it with `stale-version`. Refuses with `read-only`
937
+ * while the editor is read-only; an applied batch calls `onChange` once.
938
+ */
939
+ applyEdits: (request: XlsxEditRequest) => Promise<XlsxEditResult>;
940
+ }
941
+ /** @deprecated Removed in 0.6.0. Use XlsxAsyncEditorApi. */
942
+ interface XlsxWorkerViewerApi extends Omit<XlsxEditorApi, 'handle' | 'save' | 'selectCells' | 'version' | 'readCells' | 'findText' | 'validateEdits' | 'applyEdits'> {
943
+ handle: null;
944
+ save: () => null;
945
+ selectCells: (sheet: number, selection: Selection) => false;
946
+ saveAsync: () => Promise<Uint8Array | null>;
947
+ selectCellsAsync: (sheet: number, selection: Selection) => Promise<boolean>;
948
+ version: () => Promise<string | null>;
949
+ readCells: (request: XlsxReadRequest) => Promise<XlsxReadResult | null>;
950
+ findText: (request: XlsxFindRequest) => Promise<XlsxFindResult | null>;
951
+ validateEdits: (request: XlsxEditRequest) => Promise<XlsxValidationResult | null>;
952
+ applyEdits: (request: XlsxEditRequest) => Promise<XlsxEditResult | null>;
953
+ }
954
+ /** Why a synchronous {@link XlsxEditorApi.save} did not return bytes. */
955
+ declare class XlsxSaveRefusedError extends Error {
956
+ readonly code: 'input-pending' | 'input-failed';
957
+ constructor(code: 'input-pending' | 'input-failed');
958
+ }
959
+ interface XlsxEditorCollaborationOptions {
960
+ /** Peer-unique Yrs client ID. Generated securely when omitted. */
961
+ clientId?: number;
962
+ /** Shared Yrs state applied before the replica is exposed. */
963
+ initialUpdate?: Uint8Array;
964
+ /** Receive the editor-owned collaboration replica. */
965
+ onReplica?: (replica: CollaborationReplica | null) => void;
966
+ /** Presence-capable provider connected to the editor-owned replica. */
967
+ provider?: CollaborationAwareness | null;
968
+ }
969
+ interface XlsxDocumentChange {
970
+ version: string;
971
+ }
972
+ interface XlsxHostProps {
973
+ /** Receives the version after a committed edit changes the workbook. */
974
+ onDocumentChange?: (change: XlsxDocumentChange) => void;
975
+ /** Whether Save also downloads a copy. Defaults to true without onSave, false with it. */
976
+ downloadOnSave?: boolean;
977
+ /** Initial scale, clamped to the supported zoom range. Defaults to 1. */
978
+ initialZoom?: number;
979
+ /** Rendered while a supplied file is opening. */
980
+ loadingIndicator?: React.ReactNode;
981
+ /** Inline style overrides for the editor root. */
982
+ style?: React.CSSProperties;
983
+ }
984
+ /** Props for XlsxEditor. */
985
+ interface XlsxInThreadEditorProps extends XlsxEditorPluginProps, XlsxHostProps {
986
+ /** @deprecated False selects the in-thread engine. */
987
+ experimentalWorkerOpen?: false;
988
+ onError?: (error: Error) => void;
989
+ /** Raw .xlsx bytes to open. When omitted the shell paints a demo frame. */
990
+ file?: Uint8Array | ArrayBuffer;
991
+ /** Download name for the save button; falls back to `workbook.xlsx`. */
992
+ fileName?: string;
993
+ /** Receives saved workbook bytes. */
994
+ onSave?: (bytes: Uint8Array) => void;
995
+ /** Return true for built-in saving; false or void handles/cancels the request. */
996
+ onSaveRequest?: () => boolean | void | Promise<boolean | void>;
997
+ /** Called after a user edit changes the workbook. */
998
+ onChange?: () => void;
999
+ /** Open a network-ready Yrs replica and repaint when peer updates arrive. */
1000
+ collaboration?: XlsxEditorCollaborationOptions;
1001
+ i18n?: Translations;
1002
+ /**
1003
+ * Called when a workbook opens, with a handle to stage agent proposals and a
1004
+ * way to refresh the panel afterward. Enables demo/host agents without
1005
+ * exposing the wasm object through the render tree. A returned cleanup runs
1006
+ * before the workbook is replaced or disposed.
1007
+ */
1008
+ onReady?: (api: XlsxEditorApi) => void | (() => void);
1009
+ className?: string;
1010
+ /** Blocks user edits; navigation and selection remain available. */
1011
+ readOnly?: boolean;
1012
+ /**
1013
+ * Replaces the default toolbar: omitted keeps it (hidden when read-only),
1014
+ * `null` removes it, and supplied chrome renders instead, also when
1015
+ * read-only. Compose it from `EditorToolbar mode="commands"` parts.
1016
+ * @experimental
1017
+ */
1018
+ toolbar?: React.ReactNode;
1019
+ /** `false` hides the toolbar region, whatever `toolbar` is. */
1020
+ showToolbar?: boolean;
1021
+ }
1022
+ /** @deprecated Removed in 0.6.0. Use XlsxAsyncEditorProps. */
1023
+ type XlsxWorkerViewerProps = Omit<XlsxInThreadEditorProps, 'onReady' | 'readOnly' | 'collaboration' | 'experimentalWorkerOpen' | keyof XlsxHostProps> & {
1024
+ /** @deprecated Removed in 0.6.0. Omit for the async editor. */
1025
+ [LEGACY_SYNC_API]: true;
1026
+ readOnly: true;
1027
+ collaboration?: undefined;
1028
+ /** Opens in the worker; without it the legacy runtime runs in-thread. */
1029
+ experimentalWorkerOpen: true;
1030
+ onReady?: (api: XlsxWorkerViewerApi) => void | (() => void);
1031
+ };
1032
+ /** @deprecated Removed in 0.6.0. Use XlsxAsyncEditorProps. */
1033
+ type XlsxWorkerEditorProps = Omit<XlsxWorkerViewerProps, 'onReady' | 'readOnly'> & {
1034
+ readOnly?: false;
1035
+ onReady?: (api: XlsxWorkerEditorApi) => void | (() => void);
1036
+ };
1037
+ type XlsxAsyncEditorProps = Omit<XlsxInThreadEditorProps, 'onReady' | 'experimentalWorkerOpen'> & {
1038
+ /** @deprecated Removed in 0.6.0. Omit for the async editor. */
1039
+ [LEGACY_SYNC_API]?: false;
1040
+ /** @deprecated False selects the in-thread engine. */
1041
+ experimentalWorkerOpen?: boolean;
1042
+ onReady?: (api: XlsxAsyncEditorApi) => void | (() => void);
1043
+ };
1044
+ /** @deprecated Removed in 0.6.0. Use XlsxAsyncEditorProps. */
1045
+ type XlsxLegacyEditorProps = Omit<XlsxInThreadEditorProps, keyof XlsxHostProps> & {
1046
+ /** @deprecated Removed in 0.6.0. Omit for the async editor. */
1047
+ [LEGACY_SYNC_API]: true;
1048
+ };
1049
+ type WorkerSessionProps = Omit<XlsxWorkerEditorProps, 'readOnly' | 'onReady'> & {
1050
+ readOnly?: boolean;
1051
+ onReady?: (api: XlsxWorkerEditorApi | XlsxWorkerViewerApi) => void | (() => void);
1052
+ };
1053
+ type GeneralEditorSessionProps = Omit<XlsxLegacyEditorProps, 'experimentalWorkerOpen' | 'onReady'> & {
1054
+ experimentalWorkerOpen?: boolean;
1055
+ onReady?: (api: XlsxEditorApi | XlsxWorkerEditorApi | XlsxWorkerViewerApi) => void | (() => void);
1056
+ };
1057
+ type XlsxEditorProps = XlsxAsyncEditorProps | GeneralEditorSessionProps;
1058
+ declare function XlsxEditor(props: XlsxAsyncEditorProps): React.JSX.Element;
1059
+ declare function XlsxEditor(props: XlsxLegacyEditorProps): React.JSX.Element;
1060
+ declare function XlsxEditor(props: XlsxWorkerViewerProps): React.JSX.Element;
1061
+ declare function XlsxEditor(props: XlsxWorkerEditorProps): React.JSX.Element;
1062
+ declare function XlsxEditor(props: WorkerSessionProps): React.JSX.Element;
1063
+ declare function XlsxEditor(props: XlsxEditorProps): React.JSX.Element;
1064
+
1065
+ declare class XlsxWorkerEditorChunkLoadError extends Error {
1066
+ readonly cause: unknown;
1067
+ readonly code = "chunk-load-failed";
1068
+ constructor(cause: unknown);
1069
+ }
1070
+
1071
+ interface EditorToolbarProps extends ToolbarProps {
1072
+ /**
1073
+ * Locale of a command-mode toolbar rendered outside the editor; defaults to the editor's.
1074
+ * @experimental
1075
+ */
1076
+ i18n?: Translations;
1077
+ }
141
1078
  declare const EditorToolbarContext: react.Context<ToolbarProps | null>;
142
1079
  declare function useEditorToolbar(): ToolbarProps;
143
1080
 
1081
+ /** @experimental */
1082
+ interface FormulaBarProps {
1083
+ className?: string;
1084
+ style?: CSSProperties;
1085
+ }
1086
+ /**
1087
+ * The name box and formula input of the surrounding `XlsxEditor`. It edits
1088
+ * the focused cell through the editor's input ordering, so commands issued
1089
+ * while a formula is typed land after it. Renders nothing outside an editor.
1090
+ * @experimental
1091
+ */
1092
+ declare function FormulaBar({ className, style }: FormulaBarProps): react.JSX.Element | null;
1093
+
144
1094
  interface EditorToolbarComponent {
145
- (props: EditorToolbarProps & {
146
- children: ReactNode;
147
- }): React.JSX.Element;
1095
+ (props: EditorToolbarProps): React.JSX.Element;
148
1096
  Toolbar: typeof Toolbar;
1097
+ FormulaBar: typeof FormulaBar;
149
1098
  }
1099
+ /**
1100
+ * The editor chrome as a compound component. `mode="commands"` binds its
1101
+ * parts to the nearest editor's commands (inside `XlsxEditor` or an
1102
+ * `XlsxCommandProvider`) and, without children, renders the formatting rail.
1103
+ * The default legacy mode shares its props with the parts, as before.
1104
+ */
150
1105
  declare const EditorToolbar: EditorToolbarComponent;
151
1106
 
152
1107
  interface ToolbarButtonProps {
153
1108
  active?: boolean;
154
1109
  disabled?: boolean;
1110
+ /** Why the button is disabled; announced and shown on hover, and it stays focusable. */
1111
+ description?: string;
155
1112
  title: string;
156
1113
  onClick?: () => void;
157
1114
  children: ReactNode;
@@ -159,7 +1116,7 @@ interface ToolbarButtonProps {
159
1116
  testId?: string;
160
1117
  ariaExpanded?: boolean;
161
1118
  }
162
- declare function ToolbarButton({ active, disabled, title, onClick, children, style, testId, ariaExpanded, }: ToolbarButtonProps): react.JSX.Element;
1119
+ declare function ToolbarButton(props: ToolbarButtonProps): react.JSX.Element;
163
1120
  declare function ToolbarGroup({ label, children, style, }: {
164
1121
  label: string;
165
1122
  children: ReactNode;
@@ -171,21 +1128,31 @@ interface ToolbarDropdownProps {
171
1128
  trigger: ReactNode;
172
1129
  children: (close: () => void) => ReactNode;
173
1130
  disabled?: boolean;
1131
+ /** Why the dropdown is disabled; announced and shown on hover, and it stays focusable. */
1132
+ description?: string;
174
1133
  active?: boolean;
175
1134
  menuWidth?: number;
176
1135
  style?: CSSProperties;
177
1136
  testId?: string;
178
1137
  }
179
- declare function ToolbarDropdown({ title, trigger, children, disabled, active, menuWidth, style, testId, }: ToolbarDropdownProps): react.JSX.Element;
1138
+ /**
1139
+ * A button with a popup. Content made only of menu items is a menu with arrow
1140
+ * keys, Home/End and typeahead; other content is a non-modal dialog. Escape
1141
+ * returns focus to the button.
1142
+ */
1143
+ declare function ToolbarDropdown({ title, trigger, children, disabled, description, active, menuWidth, style, testId, }: ToolbarDropdownProps): react.JSX.Element;
180
1144
  interface ToolbarMenuItemProps {
181
1145
  label: string;
182
1146
  icon?: ReactNode;
1147
+ /** Makes the item a radio choice, checked when true. */
183
1148
  selected?: boolean;
184
1149
  disabled?: boolean;
1150
+ /** Why the item is disabled; announced and shown on hover. */
1151
+ description?: string;
185
1152
  onClick?: () => void;
186
1153
  close?: () => void;
187
1154
  }
188
- declare function ToolbarMenuItem({ label, icon, selected, disabled, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
1155
+ declare function ToolbarMenuItem({ label, icon, selected, disabled, description, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
189
1156
  declare function ToolbarMenuSeparator(): react.JSX.Element;
190
1157
 
191
1158
  interface LocaleProviderProps {
@@ -197,4 +1164,151 @@ declare function useTranslation(): {
197
1164
  t: TFunction;
198
1165
  };
199
1166
 
200
- export { type BorderPreset, type BorderStyle, EditorToolbar, EditorToolbarContext, type EditorToolbarProps, type FormattingAction, type HorizontalAlignment, LocaleProvider, type LocaleProviderProps, type MergeAction, type NumberFormat, type SelectionFormatting, type SelectionShape, type TextWrapping, Toolbar, ToolbarButton, ToolbarDropdown, ToolbarGroup, ToolbarMenuItem, ToolbarMenuSeparator, type ToolbarProps, ToolbarSeparator, type VerticalAlignment, XlsxEditor, type XlsxEditorApi, type XlsxEditorCollaborationOptions, type XlsxEditorProps, Toolbar as XlsxToolbar, useEditorToolbar, useTranslation };
1167
+ /** @experimental */
1168
+ interface XlsxCommandProviderProps {
1169
+ /** An editor's `api.commands`; `null` until the editor is ready. */
1170
+ commands: XlsxCommandStore | null;
1171
+ children?: ReactNode;
1172
+ }
1173
+ /**
1174
+ * Provides one editor's commands to toolbar parts rendered anywhere in the tree.
1175
+ * @experimental
1176
+ */
1177
+ declare function XlsxCommandProvider({ commands, children }: XlsxCommandProviderProps): react.JSX.Element;
1178
+
1179
+ /**
1180
+ * The nearest editor's command store.
1181
+ * @experimental
1182
+ */
1183
+ declare function useXlsxCommands(): XlsxCommandStore;
1184
+ /**
1185
+ * Subscribes to one command's state, optionally for specific arguments.
1186
+ * @experimental
1187
+ */
1188
+ declare function useXlsxCommandState<K extends XlsxCommandId>(id: K, args?: XlsxCommandArgs[K]): XlsxCommandState<K>;
1189
+ /** Subscribes to a contributed command's state. */
1190
+ declare function useXlsxCommandState(id: XlsxPluginCommandId, args?: null): XlsxPluginCommandState;
1191
+ /**
1192
+ * A command bound to this component, with its localized label and shortcut.
1193
+ * @experimental
1194
+ */
1195
+ interface XlsxBoundCommand<K extends XlsxCommandId> {
1196
+ id: K;
1197
+ descriptor: XlsxCommandDescriptor<K>;
1198
+ state: XlsxCommandState<K>;
1199
+ /** The label for the bound arguments, such as "Format as currency". */
1200
+ label: string;
1201
+ shortcut: string | null;
1202
+ /** Executes with `args`, falling back to the arguments bound to the hook. */
1203
+ execute(args?: XlsxCommandArgs[K]): Promise<XlsxCommandResult>;
1204
+ }
1205
+ /**
1206
+ * A contributed command bound to this component.
1207
+ * @experimental
1208
+ */
1209
+ interface XlsxBoundPluginCommand {
1210
+ id: XlsxPluginCommandId;
1211
+ /** Null while no active plugin contributes the command. */
1212
+ descriptor: XlsxPluginCommandDescriptor | null;
1213
+ state: XlsxPluginCommandState;
1214
+ /** The contributed label, or the id while no plugin contributes it. */
1215
+ label: string;
1216
+ shortcut: string | null;
1217
+ execute(): Promise<XlsxPluginCommandResult>;
1218
+ }
1219
+ /**
1220
+ * Binds one command for a custom control.
1221
+ * @experimental
1222
+ */
1223
+ declare function useXlsxCommand<K extends XlsxCommandId>(id: K, args?: XlsxCommandArgs[K]): XlsxBoundCommand<K>;
1224
+ /** Binds a contributed command for a custom control. */
1225
+ declare function useXlsxCommand(id: XlsxPluginCommandId, args?: null): XlsxBoundPluginCommand;
1226
+
1227
+ /**
1228
+ * Arguments a control binds; required when the command takes arguments.
1229
+ * @experimental
1230
+ */
1231
+ type ToolbarCommandArgs<K extends XlsxCommandId | XlsxPluginCommandId> = K extends XlsxCommandId ? null extends XlsxCommandArgs[K] ? {
1232
+ args?: XlsxCommandArgs[K];
1233
+ } : {
1234
+ args: XlsxCommandArgs[K];
1235
+ } : {
1236
+ args?: null;
1237
+ };
1238
+ /**
1239
+ * A built-in or contributed command; a contributed one renders nothing while inactive.
1240
+ * @experimental
1241
+ */
1242
+ type ToolbarCommandButtonProps<K extends XlsxCommandId | XlsxPluginCommandId> = {
1243
+ id: K;
1244
+ /** Button content; defaults to the command's icon, or its label when it has none. */
1245
+ children?: ReactNode;
1246
+ /** Accessible name; defaults to the localized or contributed command label. */
1247
+ label?: string;
1248
+ className?: string;
1249
+ } & ToolbarCommandArgs<K>;
1250
+ /** @experimental */
1251
+ interface ToolbarCommandSelectProps<K extends XlsxSelectCommandId> {
1252
+ id: K;
1253
+ className?: string;
1254
+ }
1255
+ /** @experimental */
1256
+ interface ToolbarCommandProps<K extends XlsxCommandId | XlsxPluginCommandId> {
1257
+ id: K;
1258
+ /** Binds arguments; omit to render the command's full built-in control. */
1259
+ args?: K extends XlsxCommandId ? XlsxCommandArgs[K] : null;
1260
+ className?: string;
1261
+ }
1262
+ /**
1263
+ * A button bound to one command, showing its pressed and disabled state.
1264
+ * @experimental
1265
+ */
1266
+ declare function ToolbarCommandButton<K extends XlsxCommandId | XlsxPluginCommandId>(props: ToolbarCommandButtonProps<K>): react.JSX.Element;
1267
+ /**
1268
+ * The built-in picker of a selector command.
1269
+ * @experimental
1270
+ */
1271
+ declare function ToolbarCommandSelect<K extends XlsxSelectCommandId>({ id, className, }: ToolbarCommandSelectProps<K>): react.JSX.Element;
1272
+ /**
1273
+ * The built-in control of any command, as the default toolbar presents it.
1274
+ * @experimental
1275
+ */
1276
+ declare function ToolbarCommand<K extends XlsxCommandId | XlsxPluginCommandId>(props: ToolbarCommandProps<K>): react.JSX.Element;
1277
+
1278
+ /** @experimental */
1279
+ interface ToolbarOverflowProps {
1280
+ /** Label of the menu entry that replaces the content at narrow widths. */
1281
+ label: string;
1282
+ onSelect(): void;
1283
+ disabled?: boolean;
1284
+ /** Why the action is disabled. */
1285
+ description?: string;
1286
+ /** Toggle state for a checkbox entry. */
1287
+ checked?: boolean;
1288
+ children: ReactNode;
1289
+ }
1290
+ /**
1291
+ * Gives arbitrary host content a menu entry, so it can move into the overflow
1292
+ * menu instead of scrolling with the row in a narrow toolbar.
1293
+ * @experimental
1294
+ */
1295
+ declare function ToolbarOverflow({ label, onSelect, disabled, description, checked, children, }: ToolbarOverflowProps): react.JSX.Element;
1296
+
1297
+ /**
1298
+ * Wraps a plugin for `XlsxEditor`'s `plugins` prop. The definition is checked when the editor
1299
+ * installs it; a problem is reported through `onPluginError` and disables only this plugin. Its
1300
+ * panel, commands and toolbar are copied and frozen, so changing them takes a new definition.
1301
+ *
1302
+ * @experimental The plugin API may change in minor releases.
1303
+ */
1304
+ declare function defineXlsxPlugin<S>(definition: XlsxPluginDefinition<S>): XlsxPlugin;
1305
+
1306
+ /**
1307
+ * The toolbar commands installed plugins contribute, in plugin and declaration order. The
1308
+ * default toolbar includes it; place it in replacement chrome to keep those commands reachable.
1309
+ *
1310
+ * @experimental The plugin API may change in minor releases.
1311
+ */
1312
+ declare function XlsxPluginToolbar(): React.ReactElement | null;
1313
+
1314
+ export { type BorderPreset, type BorderStyle, type CommandReason, type CommandState, EditorToolbar, EditorToolbarContext, type EditorToolbarProps, type FormattingAction, type FormulaBarProps, type HorizontalAlignment, type JsonValue, LocaleProvider, type LocaleProviderProps, type MaybePromise, type MergeAction, type NumberFormat, type PluginCleanupReason, type PluginGrant, type PluginLoadReason, type SelectionFormatting, type SelectionShape, type TextWrapping, Toolbar, ToolbarButton, type ToolbarButtonProps, ToolbarCommand, type ToolbarCommandArgs, ToolbarCommandButton, type ToolbarCommandButtonProps, type ToolbarCommandProps, ToolbarCommandSelect, type ToolbarCommandSelectProps, ToolbarDropdown, type ToolbarDropdownProps, ToolbarGroup, ToolbarMenuItem, type ToolbarMenuItemProps, ToolbarMenuSeparator, type ToolbarMode, ToolbarOverflow, type ToolbarOverflowProps, type ToolbarProps, ToolbarSeparator, type VerticalAlignment, XlsxAsyncApiSyncAccessError, type XlsxAsyncEditorApi, type XlsxAsyncEditorProps, type XlsxBoundCommand, type XlsxBoundPluginCommand, type XlsxCommandAdmissionCode, XlsxCommandAdmissionError, type XlsxCommandArgs, type XlsxCommandDescriptor, type XlsxCommandDisabledCode, type XlsxCommandFailureCode, type XlsxCommandId, type XlsxCommandOption, XlsxCommandProvider, type XlsxCommandProviderProps, type XlsxCommandResult, type XlsxCommandShortcut, type XlsxCommandState, type XlsxCommandStatus, type XlsxCommandStore, type XlsxCommandValues, type XlsxDocumentChange, XlsxEditor, type XlsxEditorApi, type XlsxEditorCollaborationOptions, type XlsxEditorPluginProps, type XlsxEditorProps, type XlsxInThreadEditorProps, type XlsxLegacyEditorProps, type XlsxNumberFormatValue, XlsxPeerNotReadyError, type XlsxPlugin, type XlsxPluginCellPosition, type XlsxPluginCommand, type XlsxPluginCommandClient, type XlsxPluginCommandDescriptor, type XlsxPluginCommandId, type XlsxPluginCommandResult, type XlsxPluginCommandState, type XlsxPluginContext, type XlsxPluginDefinition, type XlsxPluginEditClient, type XlsxPluginError, type XlsxPluginErrorPhase, type XlsxPluginEvent, type XlsxPluginFailureCode, type XlsxPluginGeometry, type XlsxPluginGrant, type XlsxPluginLayout, type XlsxPluginNavigation, type XlsxPluginNavigationFailureCode, type XlsxPluginNavigationOptions, type XlsxPluginNavigationResult, type XlsxPluginPanel, type XlsxPluginReadClient, type XlsxPluginRect, type XlsxPluginRefusal, type XlsxPluginSelection, type XlsxPluginSnapshot, XlsxPluginToolbar, type XlsxPointPosition, type XlsxProposalRequest, type XlsxProposalResult, XlsxSaveRefusedError, type XlsxSelectCommandId, Toolbar as XlsxToolbar, type XlsxWorkerEditorApi, XlsxWorkerEditorChunkLoadError, XlsxWorkerEditorCollaborationError, type XlsxWorkerEditorProps, XlsxWorkerSessionFailedError, type XlsxWorkerViewerApi, type XlsxWorkerViewerProps, defineXlsxPlugin, useEditorToolbar, useTranslation, useXlsxCommand, useXlsxCommandState, useXlsxCommands };