docx-vue-viewer 0.4.1 → 0.4.3

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 (3) hide show
  1. package/dist/index.d.ts +40 -1306
  2. package/dist/index.js +142 -18994
  3. package/package.json +4 -12
package/dist/index.d.ts CHANGED
@@ -1,12 +1,45 @@
1
1
  import * as vue from 'vue';
2
2
  import { PropType } from 'vue';
3
- import { DocumentModel, WatermarkSpec, SectionProperties, PageBorders, SectionColumns, PendingMediaPart } from 'docx-core';
3
+ import { DocumentModel } from 'docx-core';
4
4
  export * from 'docx-core';
5
- import { Plugin, EditorState, Transaction } from 'prosemirror-state';
6
- import { EditorView } from 'prosemirror-view';
7
- import { loadDocument } from 'ooxml-core/docx/load';
5
+ import { EditorThemeMode, RibbonActionInput, DocxEditorElement, EditorLocaleInput, PageChangeDetail } from 'ooxml-ui/docx';
6
+ export * from 'ooxml-ui/docx';
8
7
  export { DocumentFormat, detectDocumentFormat, loadDocument } from 'ooxml-core/docx/load';
9
- import { Node } from 'prosemirror-model';
8
+
9
+ declare const WordEditor: vue.DefineComponent<vue.ExtractPropTypes<{
10
+ documentModel: PropType<DocumentModel>;
11
+ readOnly: BooleanConstructor;
12
+ locale: StringConstructor;
13
+ theme: PropType<EditorThemeMode>;
14
+ showThumbnails: BooleanConstructor;
15
+ showToolbar: {
16
+ type: BooleanConstructor;
17
+ default: boolean;
18
+ };
19
+ hiddenActions: PropType<readonly RibbonActionInput[]>;
20
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
21
+ [key: string]: any;
22
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("document-change" | "document-error" | "page-change" | "dirty-change")[], "document-change" | "document-error" | "page-change" | "dirty-change", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
23
+ documentModel: PropType<DocumentModel>;
24
+ readOnly: BooleanConstructor;
25
+ locale: StringConstructor;
26
+ theme: PropType<EditorThemeMode>;
27
+ showThumbnails: BooleanConstructor;
28
+ showToolbar: {
29
+ type: BooleanConstructor;
30
+ default: boolean;
31
+ };
32
+ hiddenActions: PropType<readonly RibbonActionInput[]>;
33
+ }>> & Readonly<{
34
+ "onDocument-change"?: (...args: any[]) => any;
35
+ "onDocument-error"?: (...args: any[]) => any;
36
+ "onPage-change"?: (...args: any[]) => any;
37
+ "onDirty-change"?: (...args: any[]) => any;
38
+ }>, {
39
+ readOnly: boolean;
40
+ showThumbnails: boolean;
41
+ showToolbar: boolean;
42
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
10
43
 
11
44
  /** Editor state a framework passes down as props. */
12
45
  interface EditorProps {
@@ -47,1304 +80,5 @@ interface EditorBinding extends EditorHandle {
47
80
  destroy(): void;
48
81
  }
49
82
 
50
- interface CollaborationConfig {
51
- sessionId: string;
52
- clientId: string;
53
- version?: number;
54
- }
55
- /** Version is the authority version immediately before applying these steps. */
56
- interface StepBatch {
57
- protocol: 1;
58
- sessionId: string;
59
- batchId: string;
60
- version: number;
61
- clientId: string;
62
- steps: readonly unknown[];
63
- }
64
-
65
- interface CollaborationAuthorityConfig {
66
- sessionId: string;
67
- doc: Node;
68
- version?: number;
69
- stepHistoryLimit?: number;
70
- }
71
- type AuthorityResult = {
72
- status: 'accepted' | 'duplicate';
73
- batch: StepBatch;
74
- } | {
75
- status: 'rejected';
76
- reason: string;
77
- };
78
- /** Small in-memory reference authority. A host should replace it with its server and persistence. */
79
- declare class CollaborationAuthority {
80
- readonly sessionId: string;
81
- private readonly schema;
82
- private readonly stepHistoryLimit;
83
- private version;
84
- private documents;
85
- private records;
86
- private readonly requests;
87
- constructor(config: CollaborationAuthorityConfig);
88
- get currentVersion(): number;
89
- get doc(): Node;
90
- submit(input: unknown): AuthorityResult;
91
- private pruneHistory;
92
- }
93
-
94
- type ClientReceiveResult = {
95
- status: 'applied';
96
- transaction: Transaction;
97
- } | {
98
- status: 'duplicate' | 'stale' | 'out-of-order' | 'wrong-session' | 'invalid';
99
- reason?: string;
100
- };
101
- /** Client-side plugin and transport helpers. It does not open a network connection. */
102
- declare class CollaborationClient {
103
- readonly plugin: Plugin;
104
- readonly sessionId: string;
105
- readonly clientId: string;
106
- private readonly config;
107
- private sequence;
108
- private pending?;
109
- private readonly received;
110
- constructor(config: CollaborationConfig);
111
- get hasPendingAck(): boolean;
112
- pendingStepCount(state: EditorState): number;
113
- /** Returns the same envelope until acknowledged, so transport retries are idempotent. */
114
- createPendingBatch(state: EditorState): StepBatch | null;
115
- /** Converts one ordered authority batch into the transaction hosts should dispatch. */
116
- receive(state: EditorState, input: unknown): ClientReceiveResult;
117
- }
118
-
119
- /**
120
- * Editor theme tokens.
121
- *
122
- * Provenance: the semantic key set mirrors the shared theme of pptx-viewer
123
- * (packages/shared/src/theme/types.ts, `ViewerThemeColors` plus `radius`), which follows the
124
- * shadcn/ui naming convention. Keys are camelCase here and become `--dve-*` custom properties
125
- * (kebab-case). Values accept any CSS color. Only editor chrome is themed: the document paper
126
- * stays white like Word's page.
127
- */
128
- interface EditorTheme {
129
- /** Application chrome background (title bar, window). */
130
- background: string;
131
- foreground: string;
132
- /** Ribbon, panel and status-bar surface. */
133
- card: string;
134
- cardForeground: string;
135
- /** Menus, dialogs and other floating surfaces. */
136
- popover: string;
137
- popoverForeground: string;
138
- /** Brand and primary action color. */
139
- primary: string;
140
- primaryForeground: string;
141
- secondary: string;
142
- secondaryForeground: string;
143
- /** Muted surface; also the area behind the document pages. */
144
- muted: string;
145
- mutedForeground: string;
146
- /** Hover and selected highlight. */
147
- accent: string;
148
- accentForeground: string;
149
- destructive: string;
150
- destructiveForeground: string;
151
- border: string;
152
- input: string;
153
- /** Focus ring. */
154
- ring: string;
155
- /** Base corner radius, e.g. `4px`. */
156
- radius: string;
157
- }
158
- type EditorThemeMode = 'light' | 'dark' | 'auto';
159
-
160
- /**
161
- * Light preset: Word's neutral chrome with Word blue as primary. Neutrals follow the same
162
- * role split as pptx-viewer's light theme (background, card, muted, border).
163
- */
164
- declare const lightTheme: EditorTheme;
165
- /**
166
- * Dark preset: pptx-viewer's default dark gray scale (gray-950/900/800/700) with a lighter Word
167
- * blue as primary so it stays legible on dark surfaces.
168
- */
169
- declare const darkTheme: EditorTheme;
170
-
171
- /** Convert a (partial) theme to `--dve-*` custom properties. Unknown or empty values are skipped. */
172
- declare function themeToCssVars(theme: Partial<EditorTheme> | undefined): Record<string, string>;
173
-
174
- /** Canonical codes of the supported display locales, in menu order. */
175
- declare const EDITOR_LOCALES: readonly ["en", "fr", "de", "es", "zh-CN"];
176
-
177
- /** Display-language strings for the shared editor UI. This locale never changes DOCX language marks. */
178
-
179
- type EditorLocale = (typeof EDITOR_LOCALES)[number];
180
- /** A locale code a host may pass: a canonical code (autocompleted) or any BCP 47 tag such as `de-DE`. */
181
- type EditorLocaleInput = EditorLocale | (string & {});
182
-
183
- /**
184
- * Maps any BCP 47 tag to a supported display locale, falling back to English. Region variants
185
- * resolve to their language (`fr-CA`, `de-DE`, `es-MX`); `zh`, `zh-CN`, `zh-Hans` and `zh-SG` use
186
- * Simplified Chinese, while Traditional tags (`zh-TW`, `zh-HK`, `zh-Hant`) are unsupported.
187
- */
188
- declare function normalizeEditorLocale(value: string | null | undefined): EditorLocale;
189
-
190
- interface FormatDialog {
191
- element: HTMLElement;
192
- open(): void;
193
- close(): void;
194
- setLocale(locale: EditorLocale): void;
195
- readonly isOpen: boolean;
196
- }
197
-
198
- interface WatermarkHost {
199
- current(): WatermarkSpec | undefined;
200
- canEdit(): boolean;
201
- /** Sets the watermark in every header; undefined removes it. */
202
- apply(spec: WatermarkSpec | undefined): void;
203
- restoreFocus(): void;
204
- }
205
-
206
- interface PageBordersHost {
207
- section(): SectionProperties | undefined;
208
- canEdit(): boolean;
209
- /** Replaces the current section's page borders; undefined removes them. */
210
- apply(borders: PageBorders | undefined): void;
211
- restoreFocus(): void;
212
- }
213
-
214
- /** What Word's Page Setup dialog edits for one section, in inches. */
215
- interface PageSetupValues {
216
- topIn: number;
217
- bottomIn: number;
218
- leftIn: number;
219
- rightIn: number;
220
- gutterIn: number;
221
- headerIn: number;
222
- footerIn: number;
223
- orientation: 'portrait' | 'landscape';
224
- /** Portrait width and height; landscape swaps them when applied. */
225
- widthIn: number;
226
- heightIn: number;
227
- }
228
-
229
- interface PageSetupHost {
230
- /** The section holding the selection, or undefined when there is none to edit. */
231
- section(): SectionProperties | undefined;
232
- canEdit(): boolean;
233
- apply(values: PageSetupValues): void;
234
- restoreFocus(): void;
235
- }
236
-
237
- type ZoomFit = 'actual' | 'width' | 'page' | 'pages';
238
-
239
- interface ZoomHost {
240
- /** The current zoom, in percent. */
241
- percent(): number;
242
- setPercent(percent: number): void;
243
- fit(mode: ZoomFit): void;
244
- restoreFocus(): void;
245
- }
246
-
247
- type LineNumberSettings = NonNullable<SectionProperties['lineNumberSettings']>;
248
- interface LineNumberHost {
249
- section(): SectionProperties | undefined;
250
- canEdit(): boolean;
251
- apply(settings: LineNumberSettings | undefined): void;
252
- restoreFocus(): void;
253
- }
254
-
255
- interface ColumnsHost {
256
- section(): SectionProperties | undefined;
257
- canEdit(): boolean;
258
- apply(columns: SectionColumns): void;
259
- restoreFocus(): void;
260
- }
261
-
262
- type FormatDialogKind = 'font' | 'paragraph' | 'bookmark' | 'pageSetup' | 'caption' | 'crossReference' | 'zoom' | 'borders' | 'tableProperties' | 'lineNumbers' | 'textBox' | 'pageBorders' | 'watermark' | 'dropCap' | 'columns' | 'multilevelList';
263
- interface FormatDialogsHost {
264
- view(): EditorView | undefined;
265
- /** Header/footer edits use the main document's history; notes use their own. */
266
- historyView?(): EditorView | undefined;
267
- model(): DocumentModel;
268
- canDefineList?(): boolean;
269
- /** Page Setup edits the section holding the selection. */
270
- pageSetup?: Omit<PageSetupHost, 'restoreFocus'>;
271
- /** View > Zoom: the current zoom and how to change it. */
272
- zoom?: Omit<ZoomHost, 'restoreFocus'>;
273
- lineNumbers?: Omit<LineNumberHost, 'restoreFocus'>;
274
- pageBorders?: Omit<PageBordersHost, 'restoreFocus'>;
275
- watermark?: Omit<WatermarkHost, 'restoreFocus'>;
276
- columns?: Omit<ColumnsHost, 'restoreFocus'>;
277
- }
278
- /** The Font and Paragraph dialogs opened from the ribbon's group launchers. */
279
- declare class FormatDialogs {
280
- private readonly dialogs;
281
- constructor(host: FormatDialogsHost);
282
- get elements(): HTMLElement[];
283
- get list(): FormatDialog[];
284
- /** Opens `kind`, closing the other one first. */
285
- open(kind: FormatDialogKind): void;
286
- closeAll(): void;
287
- setLocale(locale: EditorLocale): void;
288
- }
289
-
290
- interface SearchPanelHandle {
291
- element: HTMLElement;
292
- open(focus?: 'find' | 'replace'): void;
293
- close(): void;
294
- refresh(): void;
295
- setLocale(locale: string): void;
296
- readonly isOpen: boolean;
297
- }
298
-
299
- declare const PRESENCE_PALETTE: readonly ["#2563eb", "#c2410c", "#15803d", "#a21caf", "#0e7490", "#b91c1c", "#4f46e5", "#a16207"];
300
- interface PresenceConfig {
301
- sessionId: string;
302
- clientId: string;
303
- /** Display locale of peer labels; English when omitted. */
304
- locale?: () => EditorLocale;
305
- }
306
- interface PresenceMessage {
307
- protocol: 1;
308
- sessionId: string;
309
- clientId: string;
310
- kind: 'selection' | 'leave';
311
- sequence: number;
312
- version: number;
313
- name?: string;
314
- color?: string;
315
- anchor?: number;
316
- head?: number;
317
- }
318
- type PresenceReceiveResult = {
319
- status: 'applied';
320
- transaction: Transaction;
321
- } | {
322
- status: 'duplicate' | 'stale' | 'out-of-order' | 'wrong-session' | 'invalid';
323
- reason?: string;
324
- };
325
- /** Transient selection sharing for a host-provided transport; it does not send data itself. */
326
- declare class PresenceClient {
327
- readonly plugin: Plugin;
328
- readonly sessionId: string;
329
- readonly clientId: string;
330
- private readonly received;
331
- private sequence;
332
- constructor(config: PresenceConfig);
333
- publish(state: EditorState, profile: {
334
- name: string;
335
- color: string;
336
- }): PresenceMessage | null;
337
- leave(state: EditorState): PresenceMessage;
338
- receive(state: EditorState, input: unknown): PresenceReceiveResult;
339
- }
340
-
341
- declare class EditorPresence {
342
- private element;
343
- private view;
344
- readonly client: PresenceClient;
345
- private profile?;
346
- private scheduled;
347
- constructor(config: PresenceConfig, element: HTMLElement, view: () => EditorView | undefined);
348
- publish(profile: {
349
- name: string;
350
- color: string;
351
- }): PresenceMessage | null;
352
- receive(input: unknown): PresenceReceiveResult['status'];
353
- leave(): PresenceMessage | null;
354
- /** Re-renders peer labels after a display-locale change. */
355
- relocalize(): void;
356
- schedule(): void;
357
- private emit;
358
- }
359
-
360
- /** One editor's collaboration state: step client, presence and collaborative id generator. */
361
- declare class CollaborationSession {
362
- private readonly element;
363
- private readonly getView;
364
- client?: CollaborationClient | undefined;
365
- presence?: EditorPresence | undefined;
366
- ids?: ((kind: string) => string) | undefined;
367
- private sendScheduled;
368
- constructor(element: HTMLElement, getView: () => EditorView | undefined);
369
- get active(): boolean;
370
- start(config: CollaborationConfig): void;
371
- stop(): void;
372
- /** Coalesces pending steps into one `collaboration-send` event per microtask. */
373
- scheduleSend(pending: () => StepBatch | null): void;
374
- }
375
-
376
- /**
377
- * Print Layout view: a read-only, paginated render kept in sync with the
378
- * editor model on a debounced relayout, rather than a second live editing
379
- * surface. Clicking a line asks the caller to move the real ProseMirror
380
- * cursor to the nearest editor position (see `print-layout.ts`'s
381
- * `resolveClick`), which is the chosen approach for keeping a single
382
- * source of truth for editing while still allowing click-to-place-cursor
383
- * from the paginated view.
384
- */
385
- interface PrintLayoutController {
386
- /** Mount this in the DOM alongside the continuous editing surface. */
387
- element: HTMLElement;
388
- setActive(active: boolean): void;
389
- scheduleRelayout(model: DocumentModel): void;
390
- /** Recomputes which page is most visible; call on the scroll container's `scroll` event. */
391
- refreshCurrentPage(): void;
392
- pageStatus(): {
393
- current: number;
394
- total: number;
395
- } | null;
396
- /** The laid-out page sheets currently in the DOM, in order. */
397
- pageElements(): HTMLElement[];
398
- /** Increments on every layout pass so dependants (the page navigator) know when to rebuild. */
399
- layoutVersion(): number;
400
- /** Scrolls the given 1-based page to the top of the scroll container. */
401
- scrollToPage(page: number): void;
402
- /** Approximations collected by the last layout pass (see `LayoutResult.approximations`). */
403
- approximations(): string[];
404
- /** Lays out immediately (no debounce) and opens the browser print dialog for the paginated render. */
405
- print(model: DocumentModel, note: (message: string) => void): void;
406
- destroy(): void;
407
- }
408
-
409
- /**
410
- * All Markup shows insertions/deletions as authored (default CSS from schema.ts's marks).
411
- * No Markup (final) hides deleted text and shows insertions unmarked, matching the resulting document.
412
- * Original hides inserted text and shows deletions unmarked, matching the document before the changes.
413
- * Simple Markup is approximated as No Markup with a change indicator; per-line change bars are not
414
- * implemented, so it is visually identical to No Markup today (see docs/parity-roadmap.md).
415
- */
416
- type ReviewDisplayMode = 'all' | 'simple' | 'final' | 'original';
417
-
418
- interface CommentsPanelHandle {
419
- element: HTMLElement;
420
- open(): void;
421
- close(): void;
422
- refresh(): void;
423
- setLocale(locale: string): void;
424
- readonly isOpen: boolean;
425
- }
426
-
427
- type TableCommand = 'rowBefore' | 'rowAfter' | 'deleteRow' | 'columnBefore' | 'columnAfter' | 'deleteColumn' | 'deleteTable';
428
-
429
- type LanguageField = 'language' | 'eastAsiaLanguage' | 'bidiLanguage';
430
- type MultilingualAction = {
431
- type: 'paragraphDirection';
432
- value: 'inherit' | 'ltr' | 'rtl';
433
- } | {
434
- type: 'language';
435
- key: LanguageField;
436
- value: string;
437
- } | {
438
- type: 'runRtl';
439
- value: 'inherit' | 'on' | 'off';
440
- };
441
-
442
- /** Every command the ribbon can raise, dispatched as a `ribbon-action` event. */
443
- type RibbonAction = {
444
- type: 'format';
445
- key: 'bold' | 'italic' | 'underline' | 'strike' | 'superscript' | 'subscript';
446
- } | {
447
- type: 'history';
448
- key: 'undo' | 'redo';
449
- } | {
450
- type: 'align';
451
- value: 'left' | 'center' | 'right' | 'justify';
452
- } | {
453
- type: 'font';
454
- key: 'family' | 'size' | 'color' | 'highlight';
455
- value: string;
456
- } | {
457
- type: 'clear';
458
- } | {
459
- type: 'table';
460
- rows?: number;
461
- columns?: number;
462
- } | {
463
- type: 'tablePicker';
464
- } | {
465
- type: 'clipboard';
466
- key: 'cut' | 'copy' | 'paste';
467
- } | {
468
- type: 'fontStep';
469
- direction: 'grow' | 'shrink';
470
- } | {
471
- type: 'insertBreak';
472
- kind: 'page' | 'column';
473
- } | {
474
- type: 'tableEdit';
475
- key: TableCommand;
476
- } | {
477
- type: 'page';
478
- key: 'margin' | 'orientation' | 'columns' | 'numberFormat' | 'numberStart' | 'titlePage' | 'verticalAlign' | 'lineNumbers' | 'size';
479
- value: string;
480
- } | {
481
- type: 'sectionBreak';
482
- kind: 'nextPage' | 'continuous' | 'evenPage' | 'oddPage';
483
- } | {
484
- type: 'evenOddHeaders';
485
- } | {
486
- type: 'pageColor';
487
- value: string;
488
- } | {
489
- type: 'hyphenation';
490
- value: string;
491
- } | {
492
- type: 'suppressLineNumbers';
493
- } | {
494
- type: 'paragraph';
495
- key: 'indent' | 'spacingBefore' | 'spacingAfter' | 'lineSpacing';
496
- value: string;
497
- } | {
498
- type: 'zoom';
499
- value: number;
500
- } | {
501
- type: 'list';
502
- key: 'bullet' | 'number' | 'multilevel' | 'outline' | 'headings' | 'article' | 'roman' | 'increaseLevel' | 'decreaseLevel' | 'remove';
503
- } | {
504
- type: 'view';
505
- value: 'draft' | 'print';
506
- } | {
507
- type: 'print';
508
- } | MultilingualAction | {
509
- type: 'search';
510
- focus?: 'find' | 'replace';
511
- } | {
512
- type: 'changeCase';
513
- value: 'sentence' | 'lower' | 'upper' | 'title' | 'toggle';
514
- } | {
515
- type: 'formatPainter';
516
- } | {
517
- type: 'ruler';
518
- } | {
519
- type: 'coverPage';
520
- } | {
521
- type: 'sort';
522
- order: 'ascending' | 'descending';
523
- } | {
524
- type: 'goTo';
525
- } | {
526
- type: 'selectObjects';
527
- } | {
528
- type: 'addText';
529
- level: 0 | 1 | 2 | 3;
530
- } | {
531
- type: 'blankPage';
532
- } | {
533
- type: 'readAloud';
534
- } | {
535
- type: 'gridlines';
536
- } | {
537
- type: 'navigation';
538
- } | {
539
- type: 'shading';
540
- value: string;
541
- } | {
542
- type: 'borders';
543
- preset: 'none' | 'bottom' | 'top' | 'left' | 'right' | 'all' | 'outside' | 'insideH' | 'insideV' | 'horizontal';
544
- } | {
545
- type: 'pageNumber';
546
- position: 'top' | 'bottom';
547
- align: 'left' | 'center' | 'right';
548
- style?: 'plain' | 'pageOfTotal';
549
- } | {
550
- type: 'headerFooter';
551
- kind: 'header' | 'footer';
552
- slot?: 'default' | 'first' | 'even';
553
- } | {
554
- type: 'headerFooterLink';
555
- } | {
556
- type: 'headerFooterClose';
557
- } | {
558
- type: 'headerFooterNavigate';
559
- target: 'header' | 'footer' | 'previous' | 'next';
560
- } | {
561
- type: 'headerFooterPosition';
562
- kind: 'header' | 'footer';
563
- inches: number;
564
- } | {
565
- type: 'formatDialog';
566
- kind: FormatDialogKind;
567
- } | {
568
- type: 'indent';
569
- side: 'left' | 'right';
570
- inches: number;
571
- } | {
572
- type: 'zoomFit';
573
- mode: 'actual' | 'width' | 'page' | 'pages';
574
- } | {
575
- type: 'wordCount';
576
- } | {
577
- type: 'spelling';
578
- } | {
579
- type: 'insertSymbol';
580
- value: string;
581
- } | {
582
- type: 'dropCap';
583
- value: 'none' | 'drop' | 'margin';
584
- } | {
585
- type: 'insertDateTime';
586
- value: 'long' | 'short' | 'time' | 'datetime';
587
- } | {
588
- type: 'showMarks';
589
- } | {
590
- type: 'selectAll';
591
- } | {
592
- type: 'review';
593
- key: 'trackChanges' | 'acceptOne' | 'rejectOne' | 'acceptAll' | 'rejectAll' | 'previous' | 'next';
594
- } | {
595
- type: 'reviewDisplay';
596
- value: ReviewDisplayMode;
597
- } | {
598
- type: 'comments';
599
- key: 'toggle' | 'add' | 'delete' | 'previous' | 'next';
600
- } | {
601
- type: 'insertPicture';
602
- } | {
603
- type: 'formatPicture';
604
- } | {
605
- type: 'link';
606
- } | {
607
- type: 'characterStyle';
608
- value: string;
609
- } | {
610
- type: 'showHidden';
611
- } | {
612
- type: 'thumbnails';
613
- } | {
614
- type: 'insertNote';
615
- kind: 'footnote' | 'endnote';
616
- } | {
617
- type: 'toc';
618
- key: 'insert' | 'update' | 'remove' | 'fields' | 'figures' | 'updateFigures';
619
- levels?: number;
620
- label?: string;
621
- };
622
-
623
- /** Narrow view of the host element `ReviewController` needs; keeps component.ts's own diff small. */
624
- interface ReviewHost {
625
- getModel(): DocumentModel;
626
- setModel(model: DocumentModel): void;
627
- getView(): EditorView | undefined;
628
- getReviewAuthor(): string;
629
- getCollaborationIds(): ((kind: string) => string) | undefined;
630
- notifyChange(): void;
631
- refresh(): void;
632
- }
633
- /** Owns comment add/reply/resolve/delete and tracked-change accept/reject/navigate/toggle commands. */
634
- declare class ReviewController {
635
- private host;
636
- readonly commentsPanel: CommentsPanelHandle;
637
- constructor(host: ReviewHost);
638
- get commentsOpen(): boolean;
639
- setLocale(locale: string): void;
640
- /** Removes a comment, its replies and its anchored range in one go. */
641
- private deleteById;
642
- private updateComments;
643
- private addComment;
644
- handleReview(key: Extract<RibbonAction, {
645
- type: 'review';
646
- }>['key']): void;
647
- handleComments(key: 'toggle' | 'add' | 'delete' | 'previous' | 'next'): void;
648
- }
649
-
650
- /**
651
- * Resolves inline picture bytes (kept off the JSON model by docx-core) into object URLs. URLs are
652
- * cached per package part and revoked together when the owning editor releases the cache.
653
- */
654
- declare class ImageMediaCache {
655
- private readonly lookup;
656
- private readonly urls;
657
- constructor(lookup: (partName: string) => Uint8Array | undefined);
658
- urlFor(partName: string, contentType: string): string | undefined;
659
- release(): void;
660
- }
661
-
662
- type FileCommand = 'new' | 'open' | 'save' | 'saveAs' | 'export' | 'exportText' | 'print';
663
- interface FileCommandDetail {
664
- command: FileCommand;
665
- /** Save As: the name the user chose. */
666
- fileName?: string;
667
- }
668
-
669
- interface BackstageOptions {
670
- locale: string;
671
- theme: string;
672
- author: string;
673
- spellCheck?: boolean;
674
- showRuler?: boolean;
675
- showMarks?: boolean;
676
- showThumbnails?: boolean;
677
- }
678
- type BackstageOptionKey = keyof BackstageOptions;
679
-
680
- type BackstagePage = 'home' | 'info' | 'new' | 'open' | 'saveAs' | 'print' | 'export' | 'options' | 'customize';
681
- interface Backstage {
682
- element: HTMLElement;
683
- open(page?: BackstagePage): void;
684
- close(): void;
685
- readonly isOpen: boolean;
686
- }
687
-
688
- interface StatusBar {
689
- element: HTMLElement;
690
- setPageAndWords(page: string, words: string): void;
691
- setLanguage(language: string): void;
692
- setNoteCount(count: number): void;
693
- setViewMode(mode: 'draft' | 'print'): void;
694
- setZoom(percent: number): void;
695
- }
696
-
697
- type SaveState = 'saved' | 'dirty' | 'saving' | 'saved-local';
698
- interface TitleBar {
699
- element: HTMLElement;
700
- setFileName(name: string): void;
701
- setSaveState(state: SaveState): void;
702
- setReadOnly(readOnly: boolean): void;
703
- setCommentsOpen(open: boolean): void;
704
- }
705
-
706
- /** What the chrome needs from the editor element; keeps component.ts free of chrome details. */
707
- interface ChromeHost {
708
- element: HTMLElement;
709
- model(): DocumentModel;
710
- ribbon(): HTMLElement | undefined;
711
- wordCount(): number;
712
- locale(): EditorLocale;
713
- readOnly(): boolean;
714
- setReadOnly(readOnly: boolean): void;
715
- newDocument(): void;
716
- load(bytes: Uint8Array): Promise<void>;
717
- save(): Promise<Uint8Array>;
718
- print(): void;
719
- history(key: 'undo' | 'redo'): void;
720
- toggleComments(): void;
721
- setViewMode(mode: 'draft' | 'print'): void;
722
- setZoom(percent: number): void;
723
- reportError(error: Error): void;
724
- /** Mirrors the title bar's save state into `element.dirty`. */
725
- saveStateChanged?(state: SaveState): void;
726
- /** Editor options shown on File > Options. */
727
- options(): BackstageOptions;
728
- setOption(key: BackstageOptionKey, value: string): void;
729
- hiddenActions(): readonly string[];
730
- setHiddenActions(ids: string[]): void;
731
- }
732
- /** Title bar, File tab/backstage, status bar and the default browser file workflow. */
733
- declare class EditorChrome {
734
- private readonly host;
735
- readonly titleBar: TitleBar;
736
- readonly backstage: Backstage;
737
- readonly statusBar: StatusBar;
738
- readonly fileInput: HTMLInputElement;
739
- private _fileName;
740
- private state;
741
- constructor(host: ChromeHost);
742
- /** Adds the chrome around an existing frame: title bar first, status bar and backstage last. */
743
- mount(frame: HTMLElement, ribbon: HTMLElement): void;
744
- get fileName(): string;
745
- set fileName(value: string);
746
- get isDirty(): boolean;
747
- setSaveState(state: SaveState): void;
748
- setLocale(locale: EditorLocale): void;
749
- refresh(pageText: string, wordText: string): void;
750
- closeBackstage(): void;
751
- /** Runs a file command unless a host cancels the `file-command` event to handle it itself. */
752
- run(command: FileCommand, fileName?: string): Promise<void>;
753
- private newDocument;
754
- private openSelectedFile;
755
- }
756
-
757
- /** What feature controllers need from the editor element, without reaching into its internals. */
758
- interface EditorHost {
759
- readonly element: HTMLElement;
760
- view(): EditorView | undefined;
761
- model(): DocumentModel;
762
- /** Replaces the model for edits made outside the main editing surface. */
763
- setModel(model: DocumentModel): void;
764
- locale(): EditorLocale;
765
- /** Editable and not in a collaboration session (parts and page setup aren't synced). */
766
- canEditOutsideBody(): boolean;
767
- /** Marks the document changed after an edit outside the main surface. */
768
- edited(): void;
769
- reportError(cause: unknown): void;
770
- }
771
-
772
- type HeaderFooterSlotName = 'default' | 'first' | 'even';
773
-
774
- type NoteKind = 'footnote' | 'endnote';
775
-
776
- type HeaderFooterKind = 'headers' | 'footers';
777
- type HeaderFooterSlot = 'default' | 'first' | 'even';
778
-
779
- interface HeaderFooterContext {
780
- kind: HeaderFooterKind;
781
- slot: HeaderFooterSlot;
782
- index: number;
783
- }
784
-
785
- interface PartsControllerHost extends EditorHost {
786
- images(): ImageMediaCache;
787
- /** Plugins shared with in-place editors (e.g. Ctrl+K). */
788
- plugins(): Plugin[];
789
- /** Where focus may go without closing an in-place editor: the ribbon and dialogs. */
790
- keepOpenWithin(): (Element | undefined)[];
791
- sectionIndex?(): number;
792
- refreshControls?(): void;
793
- }
794
- /** Headers, footers, footnotes and endnotes around the continuous editing surface. */
795
- declare class PartsController {
796
- private readonly host;
797
- private headerEl?;
798
- private footerEl?;
799
- private notesEl?;
800
- private active?;
801
- private closeActive?;
802
- private headerContext?;
803
- private shownSection;
804
- private renderingContext?;
805
- constructor(host: PartsControllerHost);
806
- /** The in-place header/footer/note editor currently open, which the ribbon then targets. */
807
- activeView(): EditorView | undefined;
808
- /** Page-number insertion follows the first/even/default story currently being edited. */
809
- activeHeaderFooterSlot(): HeaderFooterSlotName | undefined;
810
- headerFooterContext(): HeaderFooterContext | undefined;
811
- closeHeaderFooter(canvas?: HTMLElement, paper?: HTMLElement): void;
812
- navigate(target: 'header' | 'footer' | 'previous' | 'next', canvas?: HTMLElement, paper?: HTMLElement): void;
813
- toggleLink(): void;
814
- /** Sets picture sources in a read-only preview from the package media. */
815
- private readonly decorate;
816
- private editorOptions;
817
- /** Header/footer typing and insertion use the body history; notes retain their local stack. */
818
- runHistory(key: 'undo' | 'redo'): boolean;
819
- usesBodyHistory(): boolean;
820
- syncSection(canvas?: HTMLElement, paper?: HTMLElement): void;
821
- /** Rebuilds the header/footer/note previews and wires in-place editing. */
822
- render(canvas: HTMLElement | undefined, paper: HTMLElement | undefined, keepEditor?: boolean): void;
823
- /** Inserts a footnote or endnote reference at the selection and opens the new note for typing. */
824
- insertNote(kind: NoteKind, canvas?: HTMLElement, paper?: HTMLElement): void;
825
- /** Replaces one footnote's or endnote's blocks. */
826
- private updateNote;
827
- /** Applies header/footer edits to every section slot that shares the edited part. */
828
- private updateHeaderFooter;
829
- }
830
-
831
- interface PageControllerHost extends EditorHost {
832
- paper(): HTMLElement | undefined;
833
- toolbar(): HTMLElement | undefined;
834
- statusBar(): StatusBar | undefined;
835
- printLayout(): PrintLayoutController | undefined;
836
- refreshControls(): void;
837
- }
838
- /** Page setup, section breaks, zoom, Web/Print Layout and printing. */
839
- declare class PageController {
840
- private readonly host;
841
- zoom: number;
842
- viewMode: 'draft' | 'print';
843
- constructor(host: PageControllerHost);
844
- /** Page setup applies to the section holding the selection, as in Word, and is undoable. */
845
- changePageSetup(key: Extract<RibbonAction, {
846
- type: 'page';
847
- }>['key'], value: string): void;
848
- /** Shows the selection's section settings in the Layout tab. */
849
- syncControls(): void;
850
- /** The section holding the selection, for the Page Setup dialog. */
851
- currentSection(): SectionProperties | undefined;
852
- /** Applies the Page Setup dialog to the current section as one undoable step. */
853
- applyPageSetupValues(values: PageSetupValues): void;
854
- /** Layout > More Columns, recorded as one undoable section edit. */
855
- applyColumns(columns: SectionProperties['columns']): void;
856
- /** Layout > Line Numbers options, recorded as one undoable section edit. */
857
- applyLineNumberSettings(settings: SectionProperties['lineNumberSettings']): void;
858
- /** Layout > Watermark: a text watermark in every header (or none), one undoable step. */
859
- applyWatermark(spec: WatermarkSpec | undefined): void;
860
- /** The document's current watermark, for the Watermark dialog. */
861
- currentWatermark(): WatermarkSpec | undefined;
862
- /** Layout > Page Borders, recorded as one undoable section edit. */
863
- applyPageBorders(borders: SectionProperties['pageBorders']): void;
864
- /** Insert > Page Number: a PAGE field in the header or footer, creating the part when needed. */
865
- insertPageNumber(position: 'top' | 'bottom', align: 'left' | 'center' | 'right', style?: 'plain' | 'pageOfTotal', slot?: 'default' | 'first' | 'even'): boolean;
866
- /** Insert > Header / Footer: an empty part when the document has none. */
867
- insertHeaderFooter(kind: 'header' | 'footer', slot?: 'default' | 'first' | 'even'): boolean;
868
- private changeHeaderFooter;
869
- /** Layout > Page Color (document-wide, undoable): hex with or without `#`, or `none` to clear. */
870
- setPageColor(value: string): void;
871
- /** Layout > Hyphenation: `auto` sets `w:autoHyphenation`, `none` clears it (document-wide, undoable). */
872
- setHyphenation(value: string): void;
873
- /** Header & Footer > Different Odd & Even Pages (document-wide, undoable). */
874
- toggleEvenOddHeaders(): void;
875
- insertSectionBreak(kind: 'nextPage' | 'continuous' | 'evenPage' | 'oddPage'): void;
876
- /** Records page geometry and section layout on the editor document as one undoable step. */
877
- private dispatchSections;
878
- /** Page size and margins from the model; one multi-column section also shows its columns. */
879
- refreshPageStyles(): void;
880
- /** Zoom to 100%, the page width or a whole page, from the section holding the selection. */
881
- zoomTo(mode: ZoomFit): void;
882
- /** `sideBySide` lays Print Layout's pages out two across (View > Multiple Pages). */
883
- setZoom(percent: number, sideBySide?: boolean): void;
884
- /** Switches between the continuous editing surface and the paginated Print Layout render. */
885
- setViewMode(mode: 'draft' | 'print'): void;
886
- /** Re-lays out Print Layout after a model change (debounced by the layout view). */
887
- relayout(): void;
888
- print(): void;
889
- }
890
-
891
- interface LinkDialog {
892
- element: HTMLElement;
893
- open(): void;
894
- close(): void;
895
- setLocale(locale: EditorLocale): void;
896
- readonly isOpen: boolean;
897
- }
898
-
899
- interface PictureDialog {
900
- element: HTMLElement;
901
- open(pos: number): void;
902
- close(): void;
903
- setLocale(locale: EditorLocale): void;
904
- readonly isOpen: boolean;
905
- }
906
-
907
- interface InsertControllerHost {
908
- view(): EditorView | undefined;
909
- model(): DocumentModel;
910
- /** The editable content width in CSS pixels, used to fit inserted pictures. */
911
- contentWidth(): number;
912
- paper(): HTMLElement | undefined;
913
- toolbar(): HTMLElement | undefined;
914
- reportError(error: Error): void;
915
- }
916
- /** Picture, link, character style and hidden-text commands shared by every editor instance. */
917
- declare class InsertController {
918
- private readonly host;
919
- readonly linkDialog: LinkDialog;
920
- readonly pictureDialog: PictureDialog;
921
- readonly pictureInput: HTMLInputElement;
922
- /** Bytes for pictures inserted since the document was loaded; passed to save. */
923
- readonly pendingMedia: Map<string, PendingMediaPart>;
924
- private showHidden;
925
- private showMarks;
926
- private showGridlines;
927
- private showRuler;
928
- constructor(host: InsertControllerHost);
929
- /** Handles the actions this controller owns; returns false for everything else. */
930
- handle(action: RibbonAction): boolean;
931
- /** Ctrl+K opens the link dialog; Ctrl/Cmd+Click follows a link like Word. */
932
- plugins(): Plugin[];
933
- handleClick(view: EditorView, pos: number, event: MouseEvent): boolean;
934
- /** Media bytes for rendering: pictures inserted in this session first, then the loaded package. */
935
- media(partName: string, loaded?: ReadonlyMap<string, Uint8Array>): Uint8Array | undefined;
936
- reset(): void;
937
- setLocale(locale: EditorLocale): void;
938
- /** Re-applies the hidden-text display state after the paper is rebuilt. */
939
- syncPaper(): void;
940
- /** The ruler sits above the page in the canvas while View > Ruler is on. */
941
- private syncRulerElement;
942
- private applyRulerChange;
943
- private setShowHidden;
944
- private insertSelectedPicture;
945
- }
946
-
947
- /** Unsaved-changes flag behind `element.dirty`; reports only real transitions. */
948
- declare class DirtyState {
949
- private readonly changed;
950
- private value;
951
- constructor(changed: (dirty: boolean) => void);
952
- get dirty(): boolean;
953
- set(dirty: boolean): void;
954
- }
955
-
956
- /** Payload of the `page-change` event. Pages are 1-based and come from the approximate layout. */
957
- interface PageChangeDetail {
958
- page: number;
959
- pageCount: number;
960
- }
961
- /** Emits `page-change` only when the page or the page count really changed. */
962
- declare class PageTracker {
963
- private readonly target;
964
- private last?;
965
- constructor(target: EventTarget);
966
- report(status: {
967
- current: number;
968
- total: number;
969
- } | null): void;
970
- }
971
-
972
- /** What the navigator needs from the Print Layout view and the element. */
973
- interface PageNavigatorHost {
974
- /** Laid-out page sheets in order; empty until a layout exists. */
975
- pages(): HTMLElement[];
976
- /** Changes whenever the layout was rebuilt. */
977
- version(): number;
978
- goTo(page: number): void;
979
- close(): void;
980
- }
981
- interface PageNavigatorState {
982
- /** Print Layout is the active view. */
983
- active: boolean;
984
- /** Current page and total, or null while no layout exists. */
985
- status: {
986
- current: number;
987
- total: number;
988
- } | null;
989
- locale: EditorLocale;
990
- }
991
- /**
992
- * Collapsible left rail of scaled page thumbnails. Thumbnails are clones of the Print Layout
993
- * sheets, drawn only while near the rail's viewport, so large documents stay cheap. Pagination
994
- * comes from the approximate layout engine, so the rail says so rather than implying Word parity.
995
- */
996
- declare class PageNavigator {
997
- private readonly host;
998
- readonly element: HTMLElement;
999
- private readonly heading;
1000
- private readonly closeButton;
1001
- private readonly message;
1002
- private readonly list;
1003
- private thumbs;
1004
- private observer?;
1005
- private open;
1006
- private built;
1007
- private marked;
1008
- private labels;
1009
- private state;
1010
- constructor(host: PageNavigatorHost);
1011
- get isOpen(): boolean;
1012
- get pageCount(): number;
1013
- /** The 1-based page currently marked, or 0 when no thumbnails exist. */
1014
- get currentPage(): number;
1015
- setOpen(open: boolean): void;
1016
- /** Called after every layout, scroll and locale change; cheap when nothing moved. */
1017
- sync(state: PageNavigatorState): void;
1018
- private render;
1019
- private relabelChrome;
1020
- private relabelThumbs;
1021
- private clear;
1022
- private rebuild;
1023
- private createThumb;
1024
- private draw;
1025
- private hasFocus;
1026
- /** Highlights `page` and, unless focus is inside the rail, makes it the tab stop and scrolls to it. */
1027
- private mark;
1028
- private setStop;
1029
- /** Scrolls only the rail's own list, never an ancestor (`scrollIntoView` would move the page). */
1030
- private reveal;
1031
- private indexOf;
1032
- private onKey;
1033
- }
1034
-
1035
- interface HeadingNavigatorHost {
1036
- model(): DocumentModel;
1037
- view(): EditorView | undefined;
1038
- goTo(blockId: string): void;
1039
- close(): void;
1040
- }
1041
- /** Body headings in document order; shared TOC style resolution handles inherited heading styles. */
1042
- declare class HeadingNavigator {
1043
- private readonly host;
1044
- readonly element: HTMLElement;
1045
- private readonly title;
1046
- private readonly closeButton;
1047
- private readonly tree;
1048
- private readonly empty;
1049
- private readonly collapsed;
1050
- private signature;
1051
- private locale;
1052
- private entries;
1053
- private selected;
1054
- constructor(host: HeadingNavigatorHost);
1055
- get isOpen(): boolean;
1056
- setOpen(open: boolean): void;
1057
- sync(locale: EditorLocale): void;
1058
- private rebuild;
1059
- private items;
1060
- private toggle;
1061
- private updateVisibility;
1062
- private mark;
1063
- private onKey;
1064
- }
1065
-
1066
- /**
1067
- * The English control labels `hiddenActions` accepted before ids existed. Deprecated: accepted for
1068
- * one more release, mapped to ids, and reported through a `document-warning` event.
1069
- */
1070
- type LegacyRibbonLabel = 'Font family' | 'Font size' | 'Bold' | 'Italic' | 'Underline' | 'Strikethrough' | 'Superscript' | 'Subscript' | 'Font color' | 'Text highlight' | 'Clear formatting' | 'Decrease indent' | 'Increase indent' | 'Spacing after' | 'Spacing before' | 'Line spacing' | 'Bulleted list' | 'Numbered list' | 'Decrease list level' | 'Increase list level' | 'Remove list' | 'Align left' | 'Align center' | 'Align right' | 'Justify' | 'Find and replace' | 'Insert table' | 'Insert picture' | 'Format picture' | 'Insert link' | 'Insert page break' | 'Insert column break' | 'Margins' | 'Orientation' | 'Vertical alignment' | 'Columns' | 'Page number format' | 'Page numbering' | 'Different first page' | 'Different odd and even pages' | 'Next page section break' | 'Continuous section break' | 'Even page section break' | 'Odd page section break' | 'Insert table of contents' | 'Update table of contents' | 'Update fields' | 'Insert table of figures' | 'Insert footnote' | 'Insert endnote' | 'Paragraph direction' | 'Text language' | 'Custom text language tag' | 'East Asian language' | 'Custom east asian language tag' | 'Complex script language' | 'Custom complex script language tag' | 'Run direction' | 'Track changes' | 'Display for review' | 'Previous change' | 'Next change' | 'Accept' | 'Reject' | 'Accept all' | 'Reject all' | 'Add comment' | 'Comments' | 'Show hidden text' | 'Page thumbnails' | 'Zoom' | 'Layout view' | 'Print' | 'Insert row above' | 'Insert row below' | 'Delete row' | 'Insert column left' | 'Insert column right' | 'Delete column' | 'Delete table';
1071
-
1072
- /**
1073
- * Stable, locale-independent ids of every ribbon control. `hiddenActions` is keyed on these ids;
1074
- * the English labels below are only the keys the localizer uses to find a control's display text.
1075
- * `element-api.test.ts` fails when a control is added to or removed from the ribbon without
1076
- * updating this list.
1077
- */
1078
- declare const RIBBON_ACTION_IDS: readonly ["paste", "delete-comment", "previous-comment", "next-comment", "insert-caption", "cross-reference", "ruler", "page-setup-dialog", "cover-page", "bookmark", "sort", "find-options", "select-options", "add-text", "blank-page", "read-aloud", "gridlines", "navigation-pane", "shading", "borders", "header", "footer", "page-number", "header-footer-link", "header-footer-close", "header-footer-go-header", "header-footer-go-footer", "header-footer-previous", "header-footer-next", "header-from-top", "footer-from-bottom", "page-size", "font-dialog", "paragraph-dialog", "indent-left", "indent-right", "zoom-actual-size", "multiple-pages", "page-width", "one-page", "word-count", "spelling", "symbol", "date-and-time", "line-numbers", "multilevel-list", "drop-cap", "change-case", "format-painter", "show-paragraph-marks", "select-all", "replace", "cut", "copy", "grow-font", "shrink-font", "font-family", "font-size", "bold", "italic", "underline", "strikethrough", "superscript", "subscript", "font-color", "text-highlight", "clear-formatting", "decrease-indent", "increase-indent", "spacing-after", "spacing-before", "line-spacing", "bulleted-list", "numbered-list", "decrease-list-level", "increase-list-level", "remove-list", "align-left", "align-center", "align-right", "justify", "find-and-replace", "insert-table", "insert-picture", "format-picture", "insert-link", "insert-page-break", "insert-column-break", "margins", "orientation", "vertical-alignment", "columns", "page-color", "text-box", "page-borders", "watermark", "hyphenation", "page-number-format", "page-numbering", "different-first-page", "different-odd-and-even-pages", "next-page-section-break", "continuous-section-break", "even-page-section-break", "odd-page-section-break", "insert-table-of-contents", "update-table-of-contents", "update-fields", "insert-table-of-figures", "insert-footnote", "insert-endnote", "paragraph-direction", "text-language", "custom-text-language-tag", "east-asian-language", "custom-east-asian-language-tag", "complex-script-language", "custom-complex-script-language-tag", "run-direction", "track-changes", "display-for-review", "previous-change", "next-change", "accept", "reject", "accept-all", "reject-all", "add-comment", "comments", "show-hidden-text", "page-thumbnails", "zoom", "zoom-dialog", "layout-view", "print", "insert-row-above", "insert-row-below", "delete-row", "insert-column-left", "insert-column-right", "delete-column", "delete-table", "table-properties"];
1079
- type RibbonActionId = (typeof RIBBON_ACTION_IDS)[number];
1080
- /** English control label of each action, the lookup key into the locale strings. Display-only. */
1081
- declare const RIBBON_ACTION_LABELS: Readonly<Record<RibbonActionId, string>>;
1082
-
1083
- /** A value `hiddenActions` accepts: a stable id, or (deprecated) the old English label. */
1084
- type RibbonActionInput = RibbonActionId | LegacyRibbonLabel;
1085
- declare function isRibbonActionId(value: string): value is RibbonActionId;
1086
- /**
1087
- * Maps `hiddenActions` input to ids. Deprecated English labels are converted and listed in
1088
- * `legacy`; unknown values are dropped, matching how the ribbon ignored them before.
1089
- */
1090
- declare function normalizeRibbonActions(input: readonly string[]): {
1091
- ids: RibbonActionId[];
1092
- legacy: string[];
1093
- };
1094
-
1095
- /** Host-controlled UI customisation; each value maps to one element property and attribute. */
1096
- declare class ViewOptions {
1097
- showThumbnails: boolean;
1098
- showToolbar: boolean;
1099
- hiddenActions: readonly RibbonActionId[];
1100
- }
1101
-
1102
- type LoadedDocument = Awaited<ReturnType<typeof loadDocument>>;
1103
- /** DOM pieces created by the shell once the element connects. */
1104
- interface ShellParts {
1105
- toolbar?: HTMLElement;
1106
- canvas?: HTMLElement;
1107
- paper?: HTMLElement;
1108
- searchPanel?: SearchPanelHandle;
1109
- review?: ReviewController;
1110
- chrome?: EditorChrome;
1111
- printLayout?: PrintLayoutController;
1112
- navigator?: PageNavigator;
1113
- headings?: HeadingNavigator;
1114
- }
1115
- /**
1116
- * Mutable editor state and the controllers that share it. `<docx-editor>` is a thin facade over
1117
- * this object; the shell, render, ribbon and chrome modules take it instead of reaching into the
1118
- * element's private fields.
1119
- */
1120
- declare class EditorCore {
1121
- readonly element: HTMLElement;
1122
- model: DocumentModel;
1123
- view?: EditorView | undefined;
1124
- loaded?: LoadedDocument | undefined;
1125
- loadGeneration: number;
1126
- readOnly: boolean;
1127
- locale: EditorLocale;
1128
- reviewAuthor: string;
1129
- theme: EditorThemeMode;
1130
- themeColors?: Partial<EditorTheme> | undefined;
1131
- appliedThemeVars: string[];
1132
- reviewDisplayMode: ReviewDisplayMode;
1133
- detachedState?: EditorState | undefined;
1134
- pendingFileName?: string;
1135
- readonly shell: ShellParts;
1136
- readonly collab: CollaborationSession;
1137
- readonly inserts: InsertController;
1138
- readonly formatDialogs: FormatDialogs;
1139
- readonly imageMedia: ImageMediaCache;
1140
- readonly host: EditorHost;
1141
- readonly parts: PartsController;
1142
- readonly pages: PageController;
1143
- readonly viewOptions: ViewOptions;
1144
- readonly dirtyState: DirtyState;
1145
- readonly pageTracker: PageTracker;
1146
- constructor(element: HTMLElement);
1147
- contentWidth(): number;
1148
- /** The ribbon acts on an open header/footer/note editor, otherwise on the main text. */
1149
- targetView(): EditorView | undefined;
1150
- notifyChange(): void;
1151
- markEditedOutsideBody(): void;
1152
- scheduleCollaborationSend(): void;
1153
- pendingCollaboration(): StepBatch | null;
1154
- applyTransaction(transaction: Transaction, remote?: boolean): void;
1155
- refreshControls(): void;
1156
- }
1157
-
1158
- declare const HTMLElementBase: typeof HTMLElement;
1159
- /**
1160
- * Save, dirty-tracking and UI-customisation surface of `<docx-editor>`. It only reads and writes
1161
- * the shared `EditorCore`, so the element class stays a thin lifecycle facade.
1162
- */
1163
- declare abstract class DocxEditorApi extends HTMLElementBase {
1164
- protected abstract readonly core: EditorCore;
1165
- abstract fileName: string;
1166
- /** Shows the left rail of page thumbnails. Needs Print Layout; reflected to `show-thumbnails`. */
1167
- get showThumbnails(): boolean;
1168
- set showThumbnails(value: boolean);
1169
- /** Hides the ribbon (the title bar and status bar stay). Default true; `show-toolbar="false"`. */
1170
- get showToolbar(): boolean;
1171
- set showToolbar(value: boolean);
1172
- /**
1173
- * Ribbon controls to hide, by stable id (`RIBBON_ACTION_IDS`, e.g. `'bold'`). Unknown ids are
1174
- * ignored. The old English labels (`'Bold'`) are still accepted for one release: they are mapped
1175
- * to ids and reported through a `document-warning` event. Reading returns ids only.
1176
- */
1177
- get hiddenActions(): readonly RibbonActionId[];
1178
- set hiddenActions(value: readonly RibbonActionInput[]);
1179
- /** True after an edit until the document is saved through File > Save, `download()`, loaded or `markClean()`. */
1180
- get dirty(): boolean;
1181
- /** Declares the current content saved, for hosts that persist the result of `save()` themselves. */
1182
- markClean(): void;
1183
- /** Serialized document bytes: the loaded package's own writer, else a fresh DOCX from the model. */
1184
- saveBytes(): Promise<Uint8Array>;
1185
- /** The saved document as a Blob. Does not change `dirty`; call `markClean()` after persisting it. */
1186
- save(): Promise<Blob>;
1187
- /** Saves and starts a browser download, then marks the document clean. */
1188
- download(fileName?: string): Promise<void>;
1189
- }
1190
-
1191
- /** Every CustomEvent the `<docx-editor>` element (and its controllers) dispatches, with its detail. */
1192
- interface DocxEditorEventMap {
1193
- /** The document changed through editing, review actions or edits outside the main surface. */
1194
- 'document-change': CustomEvent<DocumentModel>;
1195
- /** Loading, saving, printing or an edit failed. */
1196
- 'document-error': CustomEvent<Error>;
1197
- /** Non-fatal notice, for example that a print layout could not be produced faithfully. */
1198
- 'document-warning': CustomEvent<string>;
1199
- /** The user toggled read-only from the editor chrome. */
1200
- 'readonly-change': CustomEvent<boolean>;
1201
- /** A ribbon control was activated. Bubbles from inside the shadow tree. */
1202
- 'ribbon-action': CustomEvent<RibbonAction>;
1203
- /** The user changed which ribbon commands are shown (File > Customize Ribbon); persist the ids if you want them kept. */
1204
- 'ribbon-customize': CustomEvent<readonly string[]>;
1205
- /** Cancelable: call `preventDefault()` to handle a File command (open/save/…) yourself. */
1206
- 'file-command': CustomEvent<FileCommandDetail>;
1207
- /** Print Layout's current page or page count changed (approximate pagination, not Word's). */
1208
- 'page-change': CustomEvent<PageChangeDetail>;
1209
- /** Unsaved-changes state flipped: true after an edit, false after save, load or `markClean()`. */
1210
- 'dirty-change': CustomEvent<boolean>;
1211
- /** Local presence changed; transport it to other clients. */
1212
- 'presence-send': CustomEvent<PresenceMessage>;
1213
- /** Local steps are pending; transport the batch to the collaboration authority. */
1214
- 'collaboration-send': CustomEvent<StepBatch>;
1215
- }
1216
- type DocxEditorEventName = keyof DocxEditorEventMap;
1217
- /** Detail payload type of the named event. */
1218
- type DocxEditorEventDetail<K extends DocxEditorEventName> = DocxEditorEventMap[K] extends CustomEvent<infer D> ? D : never;
1219
- /** Runtime list of every event name; the `satisfies` check keeps it a subset of the map. */
1220
- declare const DOCX_EDITOR_EVENTS: readonly ["document-change", "document-error", "document-warning", "readonly-change", "ribbon-action", "ribbon-customize", "file-command", "page-change", "dirty-change", "presence-send", "collaboration-send"];
1221
-
1222
- /**
1223
- * Typed event overloads. Redeclaring the methods hides the inherited ones, so the standard DOM
1224
- * event map and the string fallback are repeated here.
1225
- */
1226
- interface DocxEditorElement {
1227
- addEventListener<K extends keyof DocxEditorEventMap>(type: K, listener: (this: DocxEditorElement, event: DocxEditorEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
1228
- addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: DocxEditorElement, event: HTMLElementEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
1229
- addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
1230
- removeEventListener<K extends keyof DocxEditorEventMap>(type: K, listener: (this: DocxEditorElement, event: DocxEditorEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
1231
- removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: DocxEditorElement, event: HTMLElementEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
1232
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
1233
- }
1234
- declare class DocxEditorElement extends DocxEditorApi {
1235
- /** Attributes mirrored to the `locale`, `readOnly`, `fileName`, `reviewAuthor` and `theme` properties. */
1236
- static get observedAttributes(): string[];
1237
- protected readonly core: EditorCore;
1238
- private readonly shellApi;
1239
- /** Internal seams that in-repo tests reach for; not public API. */
1240
- private get view();
1241
- private get inserts();
1242
- attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
1243
- get reviewAuthor(): string;
1244
- set reviewAuthor(value: string);
1245
- /** File name shown in the title bar and used for downloads from the built-in File commands. */
1246
- get fileName(): string;
1247
- set fileName(value: string);
1248
- /** `light`, `dark`, or `auto` (default, follows the OS). Reflected to the `theme` attribute. */
1249
- get theme(): EditorThemeMode;
1250
- set theme(value: EditorThemeMode);
1251
- /** Token overrides applied as inline `--dve-*` custom properties on the host. */
1252
- get themeColors(): Partial<EditorTheme> | undefined;
1253
- set themeColors(value: Partial<EditorTheme> | undefined);
1254
- get locale(): string;
1255
- set locale(value: string);
1256
- publishPresence(profile: {
1257
- name: string;
1258
- color: string;
1259
- }): PresenceMessage | null;
1260
- receivePresence(message: unknown): "invalid" | "duplicate" | "wrong-session" | "stale" | "out-of-order" | "applied";
1261
- leavePresence(): PresenceMessage | null;
1262
- get documentModel(): DocumentModel | null;
1263
- set documentModel(value: DocumentModel | null);
1264
- get readOnly(): boolean;
1265
- set readOnly(value: boolean);
1266
- connectedCallback(): void;
1267
- disconnectedCallback(): void;
1268
- load(input: Uint8Array | ArrayBuffer): Promise<void>;
1269
- setLoadedDocument(session: LoadedDocument): void;
1270
- /** Join only after loading the authority's matching document snapshot and version. */
1271
- startCollaboration(config: CollaborationConfig): void;
1272
- getPendingCollaboration(): StepBatch | null;
1273
- receiveCollaboration(batch: unknown): ClientReceiveResult['status'];
1274
- /** Stopping with pending edits requires an explicit discard of the transport queue. */
1275
- stopCollaboration(discardPending?: boolean): void;
1276
- private assertDocumentReplaceable;
1277
- /** Swaps in a new model (and the session that produced it) and invalidates in-flight loads. */
1278
- private replaceDocument;
1279
- }
1280
- declare global {
1281
- interface HTMLElementTagNameMap {
1282
- 'docx-editor': DocxEditorElement;
1283
- }
1284
- }
1285
- declare function registerDocxEditor(): void;
1286
-
1287
- /**
1288
- * Attribute <-> property mapping for `<docx-editor>`. Properties stay the source of truth: an
1289
- * attribute change is applied through the property setter only when it would change the value, and
1290
- * a property change is written back to its attribute only when the attribute would differ. That
1291
- * makes each direction idempotent, so the two cannot ping-pong.
1292
- */
1293
- declare const DOCX_EDITOR_ATTRIBUTES: readonly ["locale", "read-only", "file-name", "review-author", "theme", "show-thumbnails", "show-toolbar"];
1294
- type DocxEditorAttribute = (typeof DOCX_EDITOR_ATTRIBUTES)[number];
1295
-
1296
- /** Build a reference authority using exactly the shared editor's document schema. */
1297
- declare function createCollaborationAuthority(model: DocumentModel, options: Omit<CollaborationAuthorityConfig, 'doc'>): CollaborationAuthority;
1298
-
1299
- /** Generates collision-resistant document IDs within one unique client session. */
1300
- declare function createCollaborationIdGenerator(clientId: string): (kind: string) => string;
1301
- /** Repairs missing or duplicate block IDs on local transactions. */
1302
- declare function repairCollaborativeDocumentIds(state: EditorState, clientId: string, idGenerator?: (kind: string) => string): Transaction | null;
1303
-
1304
- interface RevisionRange {
1305
- id: string;
1306
- kind: 'insert' | 'delete';
1307
- from: number;
1308
- to: number;
1309
- author: string;
1310
- /** The move this range is one side of; both sides are accepted or rejected together. */
1311
- move?: string;
1312
- }
1313
-
1314
- declare const WordEditor: vue.DefineComponent<vue.ExtractPropTypes<{
1315
- documentModel: PropType<DocumentModel>;
1316
- readOnly: BooleanConstructor;
1317
- locale: StringConstructor;
1318
- theme: PropType<EditorThemeMode>;
1319
- showThumbnails: BooleanConstructor;
1320
- showToolbar: {
1321
- type: BooleanConstructor;
1322
- default: boolean;
1323
- };
1324
- hiddenActions: PropType<readonly RibbonActionInput[]>;
1325
- }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
1326
- [key: string]: any;
1327
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("document-change" | "document-error" | "page-change" | "dirty-change")[], "document-change" | "document-error" | "page-change" | "dirty-change", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1328
- documentModel: PropType<DocumentModel>;
1329
- readOnly: BooleanConstructor;
1330
- locale: StringConstructor;
1331
- theme: PropType<EditorThemeMode>;
1332
- showThumbnails: BooleanConstructor;
1333
- showToolbar: {
1334
- type: BooleanConstructor;
1335
- default: boolean;
1336
- };
1337
- hiddenActions: PropType<readonly RibbonActionInput[]>;
1338
- }>> & Readonly<{
1339
- "onDocument-change"?: (...args: any[]) => any;
1340
- "onDocument-error"?: (...args: any[]) => any;
1341
- "onPage-change"?: (...args: any[]) => any;
1342
- "onDirty-change"?: (...args: any[]) => any;
1343
- }>, {
1344
- showThumbnails: boolean;
1345
- showToolbar: boolean;
1346
- readOnly: boolean;
1347
- }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1348
-
1349
- export { CollaborationAuthority, CollaborationClient, DOCX_EDITOR_ATTRIBUTES, DOCX_EDITOR_EVENTS, DocxEditorElement, EDITOR_LOCALES, PRESENCE_PALETTE, PresenceClient, RIBBON_ACTION_IDS, RIBBON_ACTION_LABELS, WordEditor, createCollaborationAuthority, createCollaborationIdGenerator, darkTheme, isRibbonActionId, lightTheme, normalizeEditorLocale, normalizeRibbonActions, registerDocxEditor, repairCollaborativeDocumentIds, themeToCssVars };
1350
- export type { AuthorityResult, ClientReceiveResult, CollaborationAuthorityConfig, CollaborationConfig, DocxEditorAttribute, DocxEditorEventDetail, DocxEditorEventMap, DocxEditorEventName, EditorBinding, EditorEventOptions, EditorHandle, EditorLocale, EditorLocaleInput, EditorOptions, EditorProps, EditorTheme, EditorThemeMode, FileCommand, FileCommandDetail, LegacyRibbonLabel, PageChangeDetail, PresenceConfig, PresenceMessage, PresenceReceiveResult, ReviewDisplayMode, RevisionRange, RibbonAction, RibbonActionId, RibbonActionInput, StepBatch };
83
+ export { WordEditor };
84
+ export type { EditorBinding, EditorEventOptions, EditorHandle, EditorOptions, EditorProps };