@beyondwork/docx-react-component 1.0.18 → 1.0.20

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 (105) hide show
  1. package/README.md +8 -2
  2. package/package.json +24 -34
  3. package/src/api/README.md +5 -1
  4. package/src/api/public-types.ts +710 -4
  5. package/src/api/session-state.ts +60 -0
  6. package/src/core/commands/formatting-commands.ts +2 -1
  7. package/src/core/commands/image-commands.ts +147 -0
  8. package/src/core/commands/index.ts +19 -3
  9. package/src/core/commands/list-commands.ts +231 -36
  10. package/src/core/commands/paragraph-layout-commands.ts +339 -0
  11. package/src/core/commands/section-layout-commands.ts +680 -0
  12. package/src/core/commands/style-commands.ts +262 -0
  13. package/src/core/search/search-text.ts +357 -0
  14. package/src/core/selection/mapping.ts +41 -0
  15. package/src/core/state/editor-state.ts +4 -1
  16. package/src/index.ts +51 -0
  17. package/src/io/docx-session.ts +623 -56
  18. package/src/io/export/serialize-comments.ts +104 -34
  19. package/src/io/export/serialize-footnotes.ts +198 -1
  20. package/src/io/export/serialize-headers-footers.ts +203 -10
  21. package/src/io/export/serialize-main-document.ts +285 -8
  22. package/src/io/export/serialize-numbering.ts +28 -7
  23. package/src/io/export/split-review-boundaries.ts +181 -19
  24. package/src/io/normalize/normalize-text.ts +144 -32
  25. package/src/io/ooxml/highlight-colors.ts +39 -0
  26. package/src/io/ooxml/numbering-sentinels.ts +44 -0
  27. package/src/io/ooxml/parse-comments.ts +85 -19
  28. package/src/io/ooxml/parse-fields.ts +396 -0
  29. package/src/io/ooxml/parse-footnotes.ts +452 -22
  30. package/src/io/ooxml/parse-headers-footers.ts +657 -29
  31. package/src/io/ooxml/parse-inline-media.ts +30 -0
  32. package/src/io/ooxml/parse-main-document.ts +807 -20
  33. package/src/io/ooxml/parse-numbering.ts +7 -0
  34. package/src/io/ooxml/parse-revisions.ts +317 -38
  35. package/src/io/ooxml/parse-settings.ts +184 -0
  36. package/src/io/ooxml/parse-shapes.ts +25 -0
  37. package/src/io/ooxml/parse-styles.ts +463 -0
  38. package/src/io/ooxml/parse-theme.ts +32 -0
  39. package/src/legal/bookmarks.ts +44 -0
  40. package/src/legal/cross-references.ts +59 -1
  41. package/src/model/canonical-document.ts +250 -4
  42. package/src/model/cds-1.0.0.ts +13 -0
  43. package/src/model/snapshot.ts +87 -2
  44. package/src/review/store/revision-store.ts +6 -0
  45. package/src/review/store/revision-types.ts +1 -0
  46. package/src/runtime/document-layout.ts +332 -0
  47. package/src/runtime/document-navigation.ts +603 -0
  48. package/src/runtime/document-runtime.ts +1754 -78
  49. package/src/runtime/document-search.ts +145 -0
  50. package/src/runtime/numbering-prefix.ts +47 -26
  51. package/src/runtime/page-layout-estimation.ts +212 -0
  52. package/src/runtime/read-only-diagnostics-runtime.ts +9 -0
  53. package/src/runtime/session-capabilities.ts +35 -3
  54. package/src/runtime/story-context.ts +164 -0
  55. package/src/runtime/story-targeting.ts +162 -0
  56. package/src/runtime/surface-projection.ts +324 -36
  57. package/src/runtime/table-schema.ts +89 -7
  58. package/src/runtime/view-state.ts +477 -0
  59. package/src/runtime/workflow-markup.ts +349 -0
  60. package/src/ui/WordReviewEditor.tsx +2469 -1344
  61. package/src/ui/browser-export.ts +52 -0
  62. package/src/ui/editor-command-bag.ts +120 -0
  63. package/src/ui/editor-runtime-boundary.ts +1422 -0
  64. package/src/ui/editor-shell-view.tsx +134 -0
  65. package/src/ui/editor-surface-controller.tsx +51 -0
  66. package/src/ui/headless/preserve-editor-selection.ts +5 -0
  67. package/src/ui/headless/revision-decoration-model.ts +4 -4
  68. package/src/ui/headless/selection-helpers.ts +20 -0
  69. package/src/ui/headless/selection-toolbar-model.ts +22 -0
  70. package/src/ui/headless/use-editor-keyboard.ts +6 -1
  71. package/src/ui/runtime-snapshot-selectors.ts +197 -0
  72. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +18 -2
  73. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +129 -0
  74. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  75. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +34 -0
  76. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +386 -0
  77. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +150 -14
  78. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +128 -0
  79. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  80. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +46 -7
  81. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  82. package/src/ui-tailwind/editor-surface/pm-decorations.ts +35 -0
  83. package/src/ui-tailwind/editor-surface/pm-position-map.ts +3 -3
  84. package/src/ui-tailwind/editor-surface/pm-schema.ts +186 -13
  85. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +191 -68
  86. package/src/ui-tailwind/editor-surface/search-plugin.ts +19 -68
  87. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +51 -0
  88. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +11 -0
  89. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +7 -1
  90. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +528 -85
  91. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -1
  92. package/src/ui-tailwind/index.ts +2 -1
  93. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  94. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +277 -147
  95. package/src/ui-tailwind/review/tw-health-panel.tsx +31 -2
  96. package/src/ui-tailwind/review/tw-review-rail.tsx +8 -8
  97. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +15 -15
  98. package/src/ui-tailwind/theme/editor-theme.css +127 -0
  99. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +4 -0
  100. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +829 -12
  101. package/src/ui-tailwind/tw-review-workspace.tsx +1238 -42
  102. package/src/validation/compatibility-engine.ts +119 -24
  103. package/src/validation/compatibility-report.ts +1 -0
  104. package/src/validation/diagnostics.ts +1 -0
  105. package/src/validation/docx-comment-proof.ts +707 -0
@@ -0,0 +1,52 @@
1
+ import type { ExportDelivery, ExportResult } from "../api/public-types";
2
+
3
+ export function withExportDelivery(
4
+ result: ExportResult,
5
+ delivery: ExportDelivery,
6
+ ): ExportResult {
7
+ return {
8
+ ...result,
9
+ delivery,
10
+ };
11
+ }
12
+
13
+ export function downloadExportResult(result: ExportResult): ExportResult {
14
+ const delivery = canDownloadInBrowser()
15
+ ? triggerBrowserDownload(result)
16
+ : {
17
+ mode: "exported-bytes-only" as const,
18
+ };
19
+ return withExportDelivery(result, delivery);
20
+ }
21
+
22
+ function canDownloadInBrowser(): boolean {
23
+ return (
24
+ typeof window !== "undefined" &&
25
+ typeof document !== "undefined" &&
26
+ typeof URL !== "undefined" &&
27
+ typeof URL.createObjectURL === "function" &&
28
+ typeof URL.revokeObjectURL === "function" &&
29
+ typeof Blob !== "undefined"
30
+ );
31
+ }
32
+
33
+ function triggerBrowserDownload(result: ExportResult): ExportDelivery {
34
+ const blob = new Blob([Uint8Array.from(result.bytes)], { type: result.mimeType });
35
+ const objectUrl = URL.createObjectURL(blob);
36
+ const link = document.createElement("a");
37
+ link.href = objectUrl;
38
+ link.download = result.fileName;
39
+ link.rel = "noopener";
40
+ link.style.display = "none";
41
+ document.body?.appendChild(link);
42
+ try {
43
+ link.click();
44
+ } finally {
45
+ link.remove();
46
+ URL.revokeObjectURL(objectUrl);
47
+ }
48
+
49
+ return {
50
+ mode: "downloaded",
51
+ };
52
+ }
@@ -0,0 +1,120 @@
1
+ import { useMemo, useRef } from "react";
2
+
3
+ import type {
4
+ CommentSidebarThreadSnapshot,
5
+ FormattingAlignment,
6
+ HeaderFooterLinkPatch,
7
+ InsertImageOptions,
8
+ SectionBreakType,
9
+ SectionLayoutPatch,
10
+ SectionPageNumberingPatch,
11
+ TrackedChangeEntrySnapshot,
12
+ ZoomLevel,
13
+ WorkspaceMode,
14
+ } from "../api/public-types.ts";
15
+ import type { ReviewRailTab } from "../ui-tailwind/review/tw-review-rail.tsx";
16
+
17
+ type CommandHandler = (...args: any[]) => unknown;
18
+
19
+ export interface EditorCommandBag {
20
+ onWorkspaceModeChange(value: WorkspaceMode): void;
21
+ onZoomChange?(level: ZoomLevel): void;
22
+ onActiveRailTabChange(value: ReviewRailTab): void;
23
+ onShowTrackedChangesChange(show: boolean): void;
24
+ onUndo(): void;
25
+ onRedo(): void;
26
+ onSetParagraphStyle?(styleId: string): void;
27
+ onToggleBold?(): void;
28
+ onToggleItalic?(): void;
29
+ onToggleUnderline?(): void;
30
+ onSetSelectionTextColor?(color: string): void;
31
+ onSetSelectionHighlightColor?(color: string | null): void;
32
+ onToggleStrikethrough?(): void;
33
+ onToggleSuperscript?(): void;
34
+ onToggleSubscript?(): void;
35
+ onSetFontFamily?(fontFamily: string): void;
36
+ onSetFontSize?(fontSize: number): void;
37
+ onSetTextColor?(color: string): void;
38
+ onSetHighlightColor?(color: string | null): void;
39
+ onSetAlignment?(alignment: FormattingAlignment): void;
40
+ onOutdent?(): void;
41
+ onIndent?(): void;
42
+ onAddComment(): void;
43
+ onInsertPageBreak?(): void;
44
+ onInsertTable?(): void;
45
+ onInsertSectionBreak?(type: SectionBreakType): void;
46
+ onInsertImage?(options: InsertImageOptions): void;
47
+ onSetTableStyle?(styleId: string): void;
48
+ onAddRowBefore?(): void;
49
+ onAddRowAfter?(): void;
50
+ onAddColumnBefore?(): void;
51
+ onAddColumnAfter?(): void;
52
+ onDeleteRow?(): void;
53
+ onDeleteColumn?(): void;
54
+ onDeleteTable?(): void;
55
+ onMergeCells?(): void;
56
+ onSplitCell?(): void;
57
+ onSetCellBackground?(color: string): void;
58
+ onSetImageLayout?(
59
+ mediaId: string,
60
+ dimensions: { widthEmu: number; heightEmu: number },
61
+ ): void;
62
+ onSetImageFrame?(
63
+ mediaId: string,
64
+ offsets: { horizontalOffsetEmu?: number; verticalOffsetEmu?: number },
65
+ ): void;
66
+ onDeleteSectionBreak?(sectionIndex: number): void;
67
+ onUpdateSectionLayout?(sectionIndex: number, patch: SectionLayoutPatch): void;
68
+ onSetSectionPageNumbering?(
69
+ sectionIndex: number,
70
+ patch: SectionPageNumberingPatch | null,
71
+ ): void;
72
+ onSetHeaderFooterLink?(
73
+ sectionIndex: number,
74
+ patch: HeaderFooterLinkPatch,
75
+ ): void;
76
+ onExport(): void;
77
+ onOpenComment(thread: CommentSidebarThreadSnapshot): void;
78
+ onResolveComment(commentId: string): void;
79
+ onReopenComment?(commentId: string): void;
80
+ onAddReply?(commentId: string, body: string): void;
81
+ onEditBody?(commentId: string, body: string): void;
82
+ onOpenRevision(revision: TrackedChangeEntrySnapshot): void;
83
+ onAcceptRevision(revisionId: string): void;
84
+ onRejectRevision(revisionId: string): void;
85
+ onAcceptAllChanges(): void;
86
+ onRejectAllChanges(): void;
87
+ onCloseStory?(): void;
88
+ onOpenHeaderStory?(): void;
89
+ onOpenFooterStory?(): void;
90
+ onSetParagraphIndentation?(indentation: {
91
+ left?: number;
92
+ right?: number;
93
+ firstLine?: number;
94
+ hanging?: number;
95
+ }): void;
96
+ onSetParagraphTabStops?(
97
+ tabStops: Array<{ pos: number; val?: string; leader?: string }>,
98
+ ): void;
99
+ onRestartNumbering?(): void;
100
+ onContinueNumbering?(): void;
101
+ onNavigateHeading?(headingId: string): void;
102
+ }
103
+
104
+ export function useCommandBag<T extends object>(commands: T): T {
105
+ const commandsRef = useRef(commands);
106
+ commandsRef.current = commands;
107
+
108
+ return useMemo(() => {
109
+ const stableBag: Partial<T> = {};
110
+
111
+ for (const key of Object.keys(commands) as Array<keyof T>) {
112
+ stableBag[key] = ((...args: unknown[]) => {
113
+ const handler = commandsRef.current[key] as CommandHandler | undefined;
114
+ return handler?.(...args);
115
+ }) as T[typeof key];
116
+ }
117
+
118
+ return stableBag as T;
119
+ }, []);
120
+ }