@beyondwork/docx-react-component 1.0.27 → 1.0.29
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/canonical-document-BLEbzL2J.d.cts +844 -0
- package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
- package/dist/chunk-2FJS5GZM.js +763 -0
- package/dist/chunk-2FJS5GZM.js.map +1 -0
- package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
- package/dist/chunk-2OQBZS3F.js.map +1 -0
- package/dist/chunk-2S7W4KFO.js +127 -0
- package/dist/chunk-2S7W4KFO.js.map +1 -0
- package/dist/chunk-2TG72QSW.js +3874 -0
- package/dist/chunk-2TG72QSW.js.map +1 -0
- package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
- package/dist/chunk-36QNIZBO.js.map +1 -0
- package/dist/chunk-4AQOYAW4.js +3069 -0
- package/dist/chunk-4AQOYAW4.js.map +1 -0
- package/dist/chunk-4D5EWJ3P.js +77 -0
- package/dist/chunk-4D5EWJ3P.js.map +1 -0
- package/dist/chunk-5FN54NDH.js +2257 -0
- package/dist/chunk-5FN54NDH.js.map +1 -0
- package/dist/chunk-BOYGQYRQ.js +7306 -0
- package/dist/chunk-BOYGQYRQ.js.map +1 -0
- package/dist/chunk-CN3XMECL.js +212 -0
- package/dist/chunk-CN3XMECL.js.map +1 -0
- package/dist/chunk-EBI3BX6U.js +164 -0
- package/dist/chunk-EBI3BX6U.js.map +1 -0
- package/dist/chunk-EILUG3VB.js +1275 -0
- package/dist/chunk-EILUG3VB.js.map +1 -0
- package/dist/chunk-FUDY333O.js +70 -0
- package/dist/chunk-FUDY333O.js.map +1 -0
- package/dist/chunk-GBVOWFIK.js +1237 -0
- package/dist/chunk-GBVOWFIK.js.map +1 -0
- package/dist/chunk-H4TQ3H3Y.js +262 -0
- package/dist/chunk-H4TQ3H3Y.js.map +1 -0
- package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
- package/dist/chunk-JGB3IXZO.js.map +1 -0
- package/dist/chunk-KD2QRQPY.js +4342 -0
- package/dist/chunk-KD2QRQPY.js.map +1 -0
- package/dist/chunk-KLMXQVYK.js +369 -0
- package/dist/chunk-KLMXQVYK.js.map +1 -0
- package/dist/chunk-KZUG5KFQ.js +214 -0
- package/dist/chunk-KZUG5KFQ.js.map +1 -0
- package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
- package/dist/chunk-QDAQ4CJU.js.map +1 -0
- package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
- package/dist/chunk-RMH72RZI.js.map +1 -0
- package/dist/chunk-SWKWQZXM.js +117 -0
- package/dist/chunk-SWKWQZXM.js.map +1 -0
- package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
- package/dist/chunk-TJBP2K4T.js.map +1 -0
- package/dist/chunk-TLCEAQDQ.js +542 -0
- package/dist/chunk-TLCEAQDQ.js.map +1 -0
- package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
- package/dist/chunk-UZXBISGO.js.map +1 -0
- package/dist/chunk-WGBAKP3Q.js +3220 -0
- package/dist/chunk-WGBAKP3Q.js.map +1 -0
- package/dist/compare/index.cjs +5475 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +114 -0
- package/dist/compare/index.d.ts +114 -0
- package/dist/compare/index.js +731 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/core/commands/formatting-commands.cjs +828 -0
- package/dist/core/commands/formatting-commands.cjs.map +1 -0
- package/dist/core/commands/formatting-commands.d.cts +63 -0
- package/dist/core/commands/formatting-commands.d.ts +63 -0
- package/dist/core/commands/formatting-commands.js +37 -0
- package/dist/core/commands/formatting-commands.js.map +1 -0
- package/dist/core/commands/image-commands.cjs +2023 -0
- package/dist/core/commands/image-commands.cjs.map +1 -0
- package/dist/core/commands/image-commands.d.cts +58 -0
- package/dist/core/commands/image-commands.d.ts +58 -0
- package/dist/core/commands/image-commands.js +18 -0
- package/dist/core/commands/image-commands.js.map +1 -0
- package/dist/core/commands/section-layout-commands.cjs +477 -0
- package/dist/core/commands/section-layout-commands.cjs.map +1 -0
- package/dist/core/commands/section-layout-commands.d.cts +62 -0
- package/dist/core/commands/section-layout-commands.d.ts +62 -0
- package/dist/core/commands/section-layout-commands.js +21 -0
- package/dist/core/commands/section-layout-commands.js.map +1 -0
- package/dist/core/commands/style-commands.cjs +214 -0
- package/dist/core/commands/style-commands.cjs.map +1 -0
- package/dist/core/commands/style-commands.d.cts +13 -0
- package/dist/core/commands/style-commands.d.ts +13 -0
- package/dist/core/commands/style-commands.js +9 -0
- package/dist/core/commands/style-commands.js.map +1 -0
- package/dist/core/commands/table-structure-commands.cjs +1883 -0
- package/dist/core/commands/table-structure-commands.cjs.map +1 -0
- package/dist/core/commands/table-structure-commands.d.cts +59 -0
- package/dist/core/commands/table-structure-commands.d.ts +59 -0
- package/dist/core/commands/table-structure-commands.js +12 -0
- package/dist/core/commands/table-structure-commands.js.map +1 -0
- package/dist/core/commands/text-commands.cjs +2391 -0
- package/dist/core/commands/text-commands.cjs.map +1 -0
- package/dist/core/commands/text-commands.d.cts +24 -0
- package/dist/core/commands/text-commands.d.ts +24 -0
- package/dist/core/commands/text-commands.js +28 -0
- package/dist/core/commands/text-commands.js.map +1 -0
- package/dist/core/selection/mapping.cjs +200 -0
- package/dist/core/selection/mapping.cjs.map +1 -0
- package/dist/core/selection/mapping.d.cts +2 -0
- package/dist/core/selection/mapping.d.ts +2 -0
- package/dist/core/selection/mapping.js +31 -0
- package/dist/core/selection/mapping.js.map +1 -0
- package/dist/core/state/editor-state.cjs +2278 -0
- package/dist/core/state/editor-state.cjs.map +1 -0
- package/dist/core/state/editor-state.d.cts +2 -0
- package/dist/core/state/editor-state.d.ts +2 -0
- package/dist/core/state/editor-state.js +26 -0
- package/dist/core/state/editor-state.js.map +1 -0
- package/dist/index.cjs +38553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7856 -0
- package/dist/index.js.map +1 -0
- package/dist/io/docx-session.cjs +16236 -0
- package/dist/io/docx-session.cjs.map +1 -0
- package/dist/io/docx-session.d.cts +21 -0
- package/dist/io/docx-session.d.ts +21 -0
- package/dist/io/docx-session.js +18 -0
- package/dist/io/docx-session.js.map +1 -0
- package/dist/legal/index.cjs +3900 -0
- package/dist/legal/index.cjs.map +1 -0
- package/dist/legal/index.d.cts +86 -0
- package/dist/legal/index.d.ts +86 -0
- package/dist/legal/index.js +616 -0
- package/dist/legal/index.js.map +1 -0
- package/dist/public-types-7ZL_94cz.d.ts +1573 -0
- package/dist/public-types-CeMaDueh.d.cts +1573 -0
- package/dist/public-types.cjs +19 -0
- package/dist/public-types.cjs.map +1 -0
- package/dist/public-types.d.cts +2 -0
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.js +1 -0
- package/dist/public-types.js.map +1 -0
- package/dist/runtime/document-runtime.cjs +11140 -0
- package/dist/runtime/document-runtime.cjs.map +1 -0
- package/dist/runtime/document-runtime.d.cts +231 -0
- package/dist/runtime/document-runtime.d.ts +231 -0
- package/dist/runtime/document-runtime.js +21 -0
- package/dist/runtime/document-runtime.js.map +1 -0
- package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
- package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
- package/dist/ui-tailwind/index.cjs +4833 -0
- package/dist/ui-tailwind/index.cjs.map +1 -0
- package/dist/ui-tailwind/index.d.cts +617 -0
- package/dist/ui-tailwind/index.d.ts +617 -0
- package/dist/ui-tailwind/index.js +575 -0
- package/dist/ui-tailwind/index.js.map +1 -0
- package/package.json +64 -54
- package/src/README.md +0 -85
- package/src/api/README.md +0 -26
- package/src/api/public-types.ts +0 -1418
- package/src/api/session-state.ts +0 -60
- package/src/compare/diff-engine.ts +0 -623
- package/src/compare/export-redlines.ts +0 -280
- package/src/compare/index.ts +0 -25
- package/src/compare/snapshot.ts +0 -97
- package/src/component-inventory.md +0 -99
- package/src/core/README.md +0 -10
- package/src/core/commands/README.md +0 -3
- package/src/core/commands/image-commands.ts +0 -373
- package/src/core/commands/index.ts +0 -1757
- package/src/core/commands/list-commands.ts +0 -565
- package/src/core/commands/paragraph-layout-commands.ts +0 -339
- package/src/core/commands/review-commands.ts +0 -108
- package/src/core/commands/structural-helpers.ts +0 -309
- package/src/core/schema/README.md +0 -3
- package/src/core/schema/text-schema.ts +0 -516
- package/src/core/search/search-text.ts +0 -357
- package/src/core/selection/README.md +0 -3
- package/src/core/selection/mapping.ts +0 -289
- package/src/core/selection/review-anchors.ts +0 -183
- package/src/core/state/README.md +0 -3
- package/src/core/state/editor-state.ts +0 -892
- package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
- package/src/formats/xlsx/io/parse-sheet.ts +0 -459
- package/src/formats/xlsx/io/parse-styles.ts +0 -59
- package/src/formats/xlsx/io/parse-workbook.ts +0 -75
- package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
- package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
- package/src/formats/xlsx/io/serialize-styles.ts +0 -98
- package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
- package/src/formats/xlsx/io/xlsx-session.ts +0 -314
- package/src/formats/xlsx/model/cell.ts +0 -189
- package/src/formats/xlsx/model/sheet.ts +0 -326
- package/src/formats/xlsx/model/styles.ts +0 -118
- package/src/formats/xlsx/model/workbook.ts +0 -453
- package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
- package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
- package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
- package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
- package/src/index.ts +0 -101
- package/src/io/README.md +0 -10
- package/src/io/docx-session.ts +0 -2882
- package/src/io/export/README.md +0 -3
- package/src/io/export/export-session.ts +0 -220
- package/src/io/export/minimal-docx.ts +0 -115
- package/src/io/export/reattach-preserved-parts.ts +0 -54
- package/src/io/export/serialize-comments.ts +0 -947
- package/src/io/export/serialize-footnotes.ts +0 -399
- package/src/io/export/serialize-headers-footers.ts +0 -372
- package/src/io/export/serialize-main-document.ts +0 -1376
- package/src/io/export/serialize-numbering.ts +0 -118
- package/src/io/export/serialize-revisions.ts +0 -389
- package/src/io/export/serialize-runtime-revisions.ts +0 -269
- package/src/io/export/serialize-tables.ts +0 -174
- package/src/io/export/split-review-boundaries.ts +0 -356
- package/src/io/normalize/README.md +0 -3
- package/src/io/normalize/normalize-text.ts +0 -639
- package/src/io/ooxml/README.md +0 -3
- package/src/io/ooxml/highlight-colors.ts +0 -39
- package/src/io/ooxml/numbering-sentinels.ts +0 -44
- package/src/io/ooxml/parse-comments.ts +0 -846
- package/src/io/ooxml/parse-complex-content.ts +0 -287
- package/src/io/ooxml/parse-fields.ts +0 -834
- package/src/io/ooxml/parse-footnotes.ts +0 -896
- package/src/io/ooxml/parse-headers-footers.ts +0 -1169
- package/src/io/ooxml/parse-inline-media.ts +0 -461
- package/src/io/ooxml/parse-main-document.ts +0 -2877
- package/src/io/ooxml/parse-numbering.ts +0 -432
- package/src/io/ooxml/parse-revisions.ts +0 -931
- package/src/io/ooxml/parse-settings.ts +0 -184
- package/src/io/ooxml/parse-shapes.ts +0 -296
- package/src/io/ooxml/parse-styles.ts +0 -463
- package/src/io/ooxml/parse-tables.ts +0 -618
- package/src/io/ooxml/parse-theme.ts +0 -346
- package/src/io/ooxml/part-manifest.ts +0 -136
- package/src/io/ooxml/revision-boundaries.ts +0 -351
- package/src/io/opc/README.md +0 -3
- package/src/io/opc/corrupt-package.ts +0 -166
- package/src/io/opc/docx-package.ts +0 -74
- package/src/io/opc/package-reader.ts +0 -325
- package/src/io/opc/package-writer.ts +0 -273
- package/src/io/source-package-provenance.ts +0 -241
- package/src/legal/cross-references.ts +0 -414
- package/src/legal/defined-terms.ts +0 -203
- package/src/legal/index.ts +0 -32
- package/src/legal/signature-blocks.ts +0 -259
- package/src/model/README.md +0 -3
- package/src/model/canonical-document.ts +0 -2632
- package/src/model/cds-1.0.0.ts +0 -212
- package/src/model/snapshot.ts +0 -649
- package/src/preservation/README.md +0 -3
- package/src/preservation/markup-compatibility.ts +0 -48
- package/src/preservation/opaque-fragment-store.ts +0 -89
- package/src/preservation/opaque-region.ts +0 -233
- package/src/preservation/package-preservation.ts +0 -113
- package/src/preservation/preserved-part-manifest.ts +0 -56
- package/src/preservation/relationship-retention.ts +0 -57
- package/src/preservation/store.ts +0 -185
- package/src/review/README.md +0 -16
- package/src/review/store/README.md +0 -3
- package/src/review/store/comment-anchors.ts +0 -70
- package/src/review/store/comment-remapping.ts +0 -154
- package/src/review/store/comment-store.ts +0 -331
- package/src/review/store/comment-thread.ts +0 -109
- package/src/review/store/revision-actions.ts +0 -394
- package/src/review/store/revision-store.ts +0 -312
- package/src/review/store/revision-types.ts +0 -171
- package/src/review/store/runtime-comment-store.ts +0 -43
- package/src/runtime/README.md +0 -3
- package/src/runtime/ai-action-policy.ts +0 -764
- package/src/runtime/collab-review-sync.ts +0 -254
- package/src/runtime/document-layout.ts +0 -332
- package/src/runtime/document-navigation.ts +0 -603
- package/src/runtime/document-runtime.ts +0 -3159
- package/src/runtime/document-search.ts +0 -145
- package/src/runtime/numbering-prefix.ts +0 -216
- package/src/runtime/page-layout-estimation.ts +0 -212
- package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
- package/src/runtime/review-runtime.ts +0 -44
- package/src/runtime/revision-runtime.ts +0 -107
- package/src/runtime/session-capabilities.ts +0 -192
- package/src/runtime/story-context.ts +0 -164
- package/src/runtime/story-targeting.ts +0 -162
- package/src/runtime/surface-projection.ts +0 -1357
- package/src/runtime/table-commands.ts +0 -173
- package/src/runtime/table-schema.ts +0 -309
- package/src/runtime/view-state.ts +0 -477
- package/src/runtime/virtualized-rendering.ts +0 -258
- package/src/runtime/workflow-markup.ts +0 -353
- package/src/ui/README.md +0 -30
- package/src/ui/WordReviewEditor.tsx +0 -4097
- package/src/ui/browser-export.ts +0 -52
- package/src/ui/comments/README.md +0 -3
- package/src/ui/compatibility/README.md +0 -3
- package/src/ui/editor-command-bag.ts +0 -120
- package/src/ui/editor-runtime-boundary.ts +0 -1457
- package/src/ui/editor-shell-view.tsx +0 -142
- package/src/ui/editor-surface/README.md +0 -3
- package/src/ui/editor-surface-controller.tsx +0 -63
- package/src/ui/headless/comment-decoration-model.ts +0 -124
- package/src/ui/headless/preserve-editor-selection.ts +0 -5
- package/src/ui/headless/revision-decoration-model.ts +0 -128
- package/src/ui/headless/selection-helpers.ts +0 -54
- package/src/ui/headless/selection-toolbar-model.ts +0 -34
- package/src/ui/headless/use-editor-keyboard.ts +0 -103
- package/src/ui/review/README.md +0 -3
- package/src/ui/runtime-snapshot-selectors.ts +0 -197
- package/src/ui/shared/revision-filters.ts +0 -31
- package/src/ui/status/README.md +0 -3
- package/src/ui/theme/README.md +0 -3
- package/src/ui/toolbar/README.md +0 -3
- package/src/ui/workflow-surface-blocked-rails.ts +0 -94
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
- package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
- package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
- package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
- package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
- package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
- package/src/ui-tailwind/index.ts +0 -62
- package/src/ui-tailwind/page-chrome-model.ts +0 -27
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
- package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
- package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
- package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
- package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
- package/src/validation/README.md +0 -3
- package/src/validation/compatibility-engine.ts +0 -634
- package/src/validation/compatibility-report.ts +0 -161
- package/src/validation/diagnostics.ts +0 -204
- package/src/validation/docx-comment-proof.ts +0 -707
- package/src/validation/import-diagnostics.ts +0 -128
- package/src/validation/low-priority-word-surfaces.ts +0 -373
- /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
|
@@ -1,1457 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
AutosaveState,
|
|
5
|
-
CompatibilityReport,
|
|
6
|
-
DocumentNavigationSnapshot,
|
|
7
|
-
EditorDatastoreAdapter,
|
|
8
|
-
EditorError,
|
|
9
|
-
EditorHostAdapter,
|
|
10
|
-
EditorSessionState,
|
|
11
|
-
EditorViewStateSnapshot,
|
|
12
|
-
EditorWarning,
|
|
13
|
-
ExportDocxOptions,
|
|
14
|
-
ExportResult,
|
|
15
|
-
FieldSnapshot,
|
|
16
|
-
PersistedEditorSnapshot,
|
|
17
|
-
RuntimeRenderSnapshot,
|
|
18
|
-
TocRefreshResult,
|
|
19
|
-
UpdateFieldsResult,
|
|
20
|
-
ViewMode as EditorViewMode,
|
|
21
|
-
WordReviewEditorEvent,
|
|
22
|
-
WordReviewEditorProps,
|
|
23
|
-
WorkspaceMode,
|
|
24
|
-
ZoomLevel,
|
|
25
|
-
} from "../api/public-types";
|
|
26
|
-
import {
|
|
27
|
-
editorSessionStateFromPersistedSnapshot,
|
|
28
|
-
persistedSnapshotFromEditorSessionState,
|
|
29
|
-
} from "../api/session-state.ts";
|
|
30
|
-
import { createCanonicalDocumentId } from "../core/state/editor-state.ts";
|
|
31
|
-
import {
|
|
32
|
-
createDocumentRuntime,
|
|
33
|
-
type DocumentRuntime,
|
|
34
|
-
} from "../runtime/document-runtime.ts";
|
|
35
|
-
import { loadDocxEditorSession } from "../io/docx-session.ts";
|
|
36
|
-
import {
|
|
37
|
-
decodePersistedSourcePackageBytes,
|
|
38
|
-
hasValidPersistedSourcePackageDigest,
|
|
39
|
-
} from "../io/source-package-provenance.ts";
|
|
40
|
-
import {
|
|
41
|
-
createEditorViewStateSnapshot,
|
|
42
|
-
createViewState,
|
|
43
|
-
} from "../runtime/view-state.ts";
|
|
44
|
-
import {
|
|
45
|
-
recordPerfSample,
|
|
46
|
-
} from "../ui-tailwind/editor-surface/perf-probe.ts";
|
|
47
|
-
import {
|
|
48
|
-
downloadExportResult,
|
|
49
|
-
withExportDelivery,
|
|
50
|
-
} from "./browser-export";
|
|
51
|
-
|
|
52
|
-
export interface ResolvedSource {
|
|
53
|
-
source: "docx" | "session" | "snapshot";
|
|
54
|
-
sourceLabel?: string;
|
|
55
|
-
initialDocx?: Uint8Array | ArrayBuffer;
|
|
56
|
-
initialSessionState?: EditorSessionState;
|
|
57
|
-
initialSnapshot?: PersistedEditorSnapshot;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface CreateRuntimeArgs {
|
|
61
|
-
documentId: string;
|
|
62
|
-
readOnly: boolean;
|
|
63
|
-
source: ResolvedSource;
|
|
64
|
-
initialViewState?: {
|
|
65
|
-
workspaceMode?: WorkspaceMode;
|
|
66
|
-
zoomLevel?: ZoomLevel;
|
|
67
|
-
};
|
|
68
|
-
hostAdapter?: EditorHostAdapter;
|
|
69
|
-
datastore?: EditorDatastoreAdapter;
|
|
70
|
-
currentUserId?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface RuntimeLifecycleHandlers {
|
|
74
|
-
onWarning?: (warning: EditorWarning) => void;
|
|
75
|
-
onError?: (error: EditorError) => void;
|
|
76
|
-
onEvent?: (event: WordReviewEditorEvent) => void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface WordReviewEditorRuntime extends DocumentRuntime {
|
|
80
|
-
getFatalError?(): EditorError | undefined;
|
|
81
|
-
dispose?(): void;
|
|
82
|
-
setDefaultAuthorId?(authorId?: string): void;
|
|
83
|
-
emitBlockedCommand(
|
|
84
|
-
command: string,
|
|
85
|
-
reasons: Extract<WordReviewEditorEvent, { type: "command_blocked" }>["reasons"],
|
|
86
|
-
): void;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
type PackageBackedDocxSession = ReturnType<typeof loadDocxEditorSession>;
|
|
90
|
-
|
|
91
|
-
interface SnapshotExportBarrier {
|
|
92
|
-
reason:
|
|
93
|
-
| "missing_source_package_provenance"
|
|
94
|
-
| "invalid_source_package_provenance";
|
|
95
|
-
message: string;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface EditorRuntimeBoundaryState {
|
|
99
|
-
runtime: WordReviewEditorRuntime | null;
|
|
100
|
-
loadError: EditorError | null;
|
|
101
|
-
activeRuntime: WordReviewEditorRuntime;
|
|
102
|
-
fallbackSnapshot: RuntimeRenderSnapshot;
|
|
103
|
-
loadingSessionState: EditorSessionState;
|
|
104
|
-
loadingViewState: EditorViewStateSnapshot;
|
|
105
|
-
loadingNavigation: DocumentNavigationSnapshot;
|
|
106
|
-
hostAdapterRef: React.MutableRefObject<EditorHostAdapter | undefined>;
|
|
107
|
-
datastoreRef: React.MutableRefObject<EditorDatastoreAdapter | undefined>;
|
|
108
|
-
onEventRef: React.MutableRefObject<((event: WordReviewEditorEvent) => void) | undefined>;
|
|
109
|
-
onWarningRef: React.MutableRefObject<((warning: EditorWarning) => void) | undefined>;
|
|
110
|
-
onErrorRef: React.MutableRefObject<((error: EditorError) => void) | undefined>;
|
|
111
|
-
autosaveTimerRef: React.MutableRefObject<ReturnType<typeof setTimeout> | null>;
|
|
112
|
-
lastSavedRevisionTokenRef: React.MutableRefObject<string | null>;
|
|
113
|
-
runtimeViewStateSeedRef: React.MutableRefObject<{
|
|
114
|
-
workspaceMode: WorkspaceMode;
|
|
115
|
-
zoomLevel: ZoomLevel;
|
|
116
|
-
}>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export async function __resolveWordReviewEditorSource(
|
|
120
|
-
props: Pick<
|
|
121
|
-
WordReviewEditorProps,
|
|
122
|
-
| "documentId"
|
|
123
|
-
| "hostAdapter"
|
|
124
|
-
| "datastore"
|
|
125
|
-
| "externalDocSource"
|
|
126
|
-
| "initialDocx"
|
|
127
|
-
| "initialSessionState"
|
|
128
|
-
| "initialSnapshot"
|
|
129
|
-
| "initialSourceLabel"
|
|
130
|
-
| "loadRevision"
|
|
131
|
-
| "loadSourcePolicy"
|
|
132
|
-
>,
|
|
133
|
-
): Promise<ResolvedSource> {
|
|
134
|
-
const explicitInitialCount =
|
|
135
|
-
Number(Boolean(props.initialDocx)) +
|
|
136
|
-
Number(Boolean(props.initialSessionState)) +
|
|
137
|
-
Number(Boolean(props.initialSnapshot));
|
|
138
|
-
if (explicitInitialCount > 1) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
"Provide exactly one of initialDocx, initialSessionState, or initialSnapshot.",
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (props.externalDocSource) {
|
|
145
|
-
if (props.externalDocSource.kind === "docx") {
|
|
146
|
-
return {
|
|
147
|
-
source: "docx",
|
|
148
|
-
initialDocx: props.externalDocSource.bytes,
|
|
149
|
-
sourceLabel: props.externalDocSource.sourceLabel,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (props.externalDocSource.kind === "session") {
|
|
154
|
-
return {
|
|
155
|
-
source: "session",
|
|
156
|
-
initialSessionState: props.externalDocSource.sessionState,
|
|
157
|
-
sourceLabel:
|
|
158
|
-
props.externalDocSource.sourceLabel ??
|
|
159
|
-
props.externalDocSource.sessionState.sourcePackage?.sourceLabel,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
source: "snapshot",
|
|
165
|
-
initialSnapshot: props.externalDocSource.snapshot,
|
|
166
|
-
sourceLabel: props.externalDocSource.sourceLabel,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (props.initialSessionState) {
|
|
171
|
-
return {
|
|
172
|
-
source: "session",
|
|
173
|
-
initialSessionState: props.initialSessionState,
|
|
174
|
-
sourceLabel:
|
|
175
|
-
props.initialSourceLabel ??
|
|
176
|
-
props.initialSessionState.sourcePackage?.sourceLabel,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (props.initialSnapshot) {
|
|
181
|
-
return {
|
|
182
|
-
source: "snapshot",
|
|
183
|
-
initialSnapshot: props.initialSnapshot,
|
|
184
|
-
sourceLabel: props.initialSourceLabel,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (props.initialDocx) {
|
|
189
|
-
return {
|
|
190
|
-
source: "docx",
|
|
191
|
-
initialDocx: props.initialDocx,
|
|
192
|
-
sourceLabel: props.initialSourceLabel,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const loader = props.hostAdapter?.load ?? props.datastore?.load;
|
|
197
|
-
if (!loader) {
|
|
198
|
-
throw new Error(
|
|
199
|
-
`WordReviewEditor ${props.documentId} needs initialDocx, initialSessionState, initialSnapshot, or a host/datastore load source.`,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const loadResult = await loader({
|
|
204
|
-
documentId: props.documentId,
|
|
205
|
-
loadRevision: props.loadRevision,
|
|
206
|
-
loadSourcePolicy: props.loadSourcePolicy,
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
if (!loadResult.source) {
|
|
210
|
-
throw new Error(
|
|
211
|
-
`Host or datastore loader did not return a loadable source for ${props.documentId}.`,
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (loadResult.source.kind === "docx") {
|
|
216
|
-
return {
|
|
217
|
-
source: "docx",
|
|
218
|
-
initialDocx: loadResult.source.bytes,
|
|
219
|
-
sourceLabel: loadResult.source.sourceLabel,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (loadResult.source.kind === "session") {
|
|
224
|
-
return {
|
|
225
|
-
source: "session",
|
|
226
|
-
initialSessionState: loadResult.source.sessionState,
|
|
227
|
-
sourceLabel:
|
|
228
|
-
loadResult.source.sourceLabel ??
|
|
229
|
-
loadResult.source.sessionState.sourcePackage?.sourceLabel,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
source: "snapshot",
|
|
235
|
-
initialSnapshot: loadResult.source.snapshot,
|
|
236
|
-
sourceLabel: loadResult.source.sourceLabel,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function __createFallbackRuntime(args: CreateRuntimeArgs): WordReviewEditorRuntime {
|
|
241
|
-
return createRuntime(args);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function useEditorRuntimeBoundary(
|
|
245
|
-
props: WordReviewEditorProps,
|
|
246
|
-
): EditorRuntimeBoundaryState {
|
|
247
|
-
const {
|
|
248
|
-
currentUser,
|
|
249
|
-
datastore,
|
|
250
|
-
documentId,
|
|
251
|
-
externalDocSource,
|
|
252
|
-
externalDocumentRevision,
|
|
253
|
-
hostAdapter,
|
|
254
|
-
initialDocx,
|
|
255
|
-
initialSessionState,
|
|
256
|
-
initialSnapshot,
|
|
257
|
-
initialSourceLabel,
|
|
258
|
-
loadRevision,
|
|
259
|
-
loadSourcePolicy = "prefer-saved-state",
|
|
260
|
-
onError,
|
|
261
|
-
onEvent,
|
|
262
|
-
onWarning,
|
|
263
|
-
readOnly = false,
|
|
264
|
-
reviewMode = "review",
|
|
265
|
-
} = props;
|
|
266
|
-
|
|
267
|
-
const [runtime, setRuntime] = useState<WordReviewEditorRuntime | null>(null);
|
|
268
|
-
const [loadError, setLoadError] = useState<EditorError | null>(null);
|
|
269
|
-
const runtimeRef = useRef<WordReviewEditorRuntime | null>(null);
|
|
270
|
-
const autosaveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
271
|
-
const lastSavedRevisionTokenRef = useRef<string | null>(null);
|
|
272
|
-
const hostAdapterRef = useRef(hostAdapter);
|
|
273
|
-
const datastoreRef = useRef(datastore);
|
|
274
|
-
const onEventRef = useRef(onEvent);
|
|
275
|
-
const onWarningRef = useRef(onWarning);
|
|
276
|
-
const onErrorRef = useRef(onError);
|
|
277
|
-
const runtimeViewStateSeedRef = useRef<{
|
|
278
|
-
workspaceMode: WorkspaceMode;
|
|
279
|
-
zoomLevel: ZoomLevel;
|
|
280
|
-
}>({
|
|
281
|
-
workspaceMode: "canvas",
|
|
282
|
-
zoomLevel: 100,
|
|
283
|
-
});
|
|
284
|
-
const initialSourceRef = useRef<{
|
|
285
|
-
documentId: string;
|
|
286
|
-
initialDocx?: Uint8Array | ArrayBuffer;
|
|
287
|
-
initialSessionState?: EditorSessionState;
|
|
288
|
-
initialSnapshot?: PersistedEditorSnapshot;
|
|
289
|
-
initialSourceLabel?: string;
|
|
290
|
-
} | null>(null);
|
|
291
|
-
|
|
292
|
-
if (!initialSourceRef.current || initialSourceRef.current.documentId !== documentId) {
|
|
293
|
-
initialSourceRef.current = {
|
|
294
|
-
documentId,
|
|
295
|
-
initialDocx,
|
|
296
|
-
initialSessionState,
|
|
297
|
-
initialSnapshot,
|
|
298
|
-
initialSourceLabel,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const stableInitialSource = initialSourceRef.current;
|
|
303
|
-
const sourceReloadKey = externalDocSource
|
|
304
|
-
? `external:${externalDocSource.kind}:${externalDocumentRevision ?? "static"}`
|
|
305
|
-
: stableInitialSource?.initialSessionState
|
|
306
|
-
? "initial-session"
|
|
307
|
-
: stableInitialSource?.initialSnapshot
|
|
308
|
-
? "initial-snapshot"
|
|
309
|
-
: stableInitialSource?.initialDocx
|
|
310
|
-
? "initial-docx"
|
|
311
|
-
: hostAdapter
|
|
312
|
-
? `host-adapter:${loadRevision ?? "static"}`
|
|
313
|
-
: `datastore:${loadRevision ?? "static"}`;
|
|
314
|
-
|
|
315
|
-
useEffect(() => {
|
|
316
|
-
hostAdapterRef.current = hostAdapter;
|
|
317
|
-
datastoreRef.current = datastore;
|
|
318
|
-
onEventRef.current = onEvent;
|
|
319
|
-
onWarningRef.current = onWarning;
|
|
320
|
-
onErrorRef.current = onError;
|
|
321
|
-
}, [datastore, hostAdapter, onError, onEvent, onWarning]);
|
|
322
|
-
|
|
323
|
-
useEffect(() => {
|
|
324
|
-
runtimeRef.current?.setDefaultAuthorId?.(currentUser.userId);
|
|
325
|
-
}, [currentUser.userId]);
|
|
326
|
-
|
|
327
|
-
useEffect(() => {
|
|
328
|
-
let cancelled = false;
|
|
329
|
-
|
|
330
|
-
async function loadRuntime(): Promise<void> {
|
|
331
|
-
setLoadError(null);
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
const source = await __resolveWordReviewEditorSource({
|
|
335
|
-
documentId,
|
|
336
|
-
hostAdapter: hostAdapterRef.current,
|
|
337
|
-
datastore: datastoreRef.current,
|
|
338
|
-
externalDocSource,
|
|
339
|
-
initialDocx: stableInitialSource?.initialDocx,
|
|
340
|
-
initialSessionState: stableInitialSource?.initialSessionState,
|
|
341
|
-
initialSnapshot: stableInitialSource?.initialSnapshot,
|
|
342
|
-
initialSourceLabel: stableInitialSource?.initialSourceLabel,
|
|
343
|
-
loadRevision,
|
|
344
|
-
loadSourcePolicy,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
if (cancelled) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
runtimeRef.current?.dispose?.();
|
|
352
|
-
const nextRuntime = createRuntime(
|
|
353
|
-
{
|
|
354
|
-
documentId,
|
|
355
|
-
readOnly,
|
|
356
|
-
source,
|
|
357
|
-
initialViewState: runtimeViewStateSeedRef.current,
|
|
358
|
-
hostAdapter: hostAdapterRef.current,
|
|
359
|
-
datastore: datastoreRef.current,
|
|
360
|
-
currentUserId: currentUser.userId,
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
onWarning: onWarningRef.current,
|
|
364
|
-
onError: onErrorRef.current,
|
|
365
|
-
onEvent: onEventRef.current,
|
|
366
|
-
},
|
|
367
|
-
);
|
|
368
|
-
recordPerfSample("runtime.create");
|
|
369
|
-
emitEditorEvent({
|
|
370
|
-
hostAdapter: hostAdapterRef.current,
|
|
371
|
-
datastore: datastoreRef.current,
|
|
372
|
-
onEvent: onEventRef.current,
|
|
373
|
-
event: createReadyEvent(nextRuntime, source.source),
|
|
374
|
-
});
|
|
375
|
-
runtimeRef.current = nextRuntime;
|
|
376
|
-
setRuntime(nextRuntime);
|
|
377
|
-
} catch (error) {
|
|
378
|
-
if (cancelled) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const normalized = normalizeEditorError(error);
|
|
383
|
-
setLoadError(normalized);
|
|
384
|
-
onErrorRef.current?.(normalized);
|
|
385
|
-
emitEditorEvent({
|
|
386
|
-
hostAdapter: hostAdapterRef.current,
|
|
387
|
-
datastore: datastoreRef.current,
|
|
388
|
-
onEvent: onEventRef.current,
|
|
389
|
-
event: {
|
|
390
|
-
type: "error",
|
|
391
|
-
documentId,
|
|
392
|
-
error: normalized,
|
|
393
|
-
},
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
void loadRuntime();
|
|
399
|
-
|
|
400
|
-
return () => {
|
|
401
|
-
cancelled = true;
|
|
402
|
-
};
|
|
403
|
-
}, [
|
|
404
|
-
documentId,
|
|
405
|
-
readOnly,
|
|
406
|
-
sourceReloadKey,
|
|
407
|
-
]);
|
|
408
|
-
|
|
409
|
-
useEffect(() => {
|
|
410
|
-
if (!runtime?.subscribeToEvents) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return runtime.subscribeToEvents((event) => {
|
|
415
|
-
if (event.type === "export_completed" || event.type === "ready") {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
emitEditorEvent({
|
|
419
|
-
hostAdapter: hostAdapterRef.current,
|
|
420
|
-
datastore: datastoreRef.current,
|
|
421
|
-
onEvent: onEventRef.current,
|
|
422
|
-
event,
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
}, [runtime]);
|
|
426
|
-
|
|
427
|
-
useEffect(() => {
|
|
428
|
-
return () => {
|
|
429
|
-
if (autosaveTimerRef.current) {
|
|
430
|
-
clearTimeout(autosaveTimerRef.current);
|
|
431
|
-
autosaveTimerRef.current = null;
|
|
432
|
-
}
|
|
433
|
-
runtimeRef.current?.dispose?.();
|
|
434
|
-
runtimeRef.current = null;
|
|
435
|
-
};
|
|
436
|
-
}, []);
|
|
437
|
-
|
|
438
|
-
const fallbackSnapshot = useMemo(
|
|
439
|
-
() =>
|
|
440
|
-
loadError
|
|
441
|
-
? createErrorSnapshot(documentId, loadError)
|
|
442
|
-
: createLoadingSnapshot(
|
|
443
|
-
documentId,
|
|
444
|
-
readOnly,
|
|
445
|
-
guessSourceLabel(
|
|
446
|
-
initialSourceLabel,
|
|
447
|
-
initialSessionState,
|
|
448
|
-
initialSnapshot,
|
|
449
|
-
externalDocSource,
|
|
450
|
-
),
|
|
451
|
-
),
|
|
452
|
-
[
|
|
453
|
-
documentId,
|
|
454
|
-
externalDocSource,
|
|
455
|
-
initialSessionState,
|
|
456
|
-
initialSnapshot,
|
|
457
|
-
initialSourceLabel,
|
|
458
|
-
loadError,
|
|
459
|
-
readOnly,
|
|
460
|
-
],
|
|
461
|
-
);
|
|
462
|
-
const loadingPersistedSnapshot = useMemo(
|
|
463
|
-
() => createFallbackPersistedSnapshot(documentId, initialSourceLabel),
|
|
464
|
-
[documentId, initialSourceLabel],
|
|
465
|
-
);
|
|
466
|
-
const loadingSessionState = useMemo(
|
|
467
|
-
() =>
|
|
468
|
-
initialSessionState ??
|
|
469
|
-
(initialSnapshot
|
|
470
|
-
? editorSessionStateFromPersistedSnapshot(initialSnapshot)
|
|
471
|
-
: editorSessionStateFromPersistedSnapshot(loadingPersistedSnapshot)),
|
|
472
|
-
[initialSessionState, initialSnapshot, loadingPersistedSnapshot],
|
|
473
|
-
);
|
|
474
|
-
const loadingViewState = useMemo(
|
|
475
|
-
() =>
|
|
476
|
-
createLoadingViewStateSnapshot(
|
|
477
|
-
fallbackSnapshot,
|
|
478
|
-
runtimeViewStateSeedRef.current,
|
|
479
|
-
deriveEditorViewMode(fallbackSnapshot.readOnly, reviewMode),
|
|
480
|
-
),
|
|
481
|
-
[fallbackSnapshot, reviewMode],
|
|
482
|
-
);
|
|
483
|
-
const loadingNavigation = useMemo(
|
|
484
|
-
() => createLoadingNavigationSnapshot(),
|
|
485
|
-
[],
|
|
486
|
-
);
|
|
487
|
-
const loadingRuntimeBridge = useMemo(
|
|
488
|
-
() =>
|
|
489
|
-
createLoadingRuntimeBridge({
|
|
490
|
-
snapshot: fallbackSnapshot,
|
|
491
|
-
sessionState: loadingSessionState,
|
|
492
|
-
viewState: loadingViewState,
|
|
493
|
-
navigation: loadingNavigation,
|
|
494
|
-
}),
|
|
495
|
-
[fallbackSnapshot, loadingNavigation, loadingSessionState, loadingViewState],
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
return {
|
|
499
|
-
runtime,
|
|
500
|
-
loadError,
|
|
501
|
-
activeRuntime: runtime ?? loadingRuntimeBridge,
|
|
502
|
-
fallbackSnapshot,
|
|
503
|
-
loadingSessionState,
|
|
504
|
-
loadingViewState,
|
|
505
|
-
loadingNavigation,
|
|
506
|
-
hostAdapterRef,
|
|
507
|
-
datastoreRef,
|
|
508
|
-
onEventRef,
|
|
509
|
-
onWarningRef,
|
|
510
|
-
onErrorRef,
|
|
511
|
-
autosaveTimerRef,
|
|
512
|
-
lastSavedRevisionTokenRef,
|
|
513
|
-
runtimeViewStateSeedRef,
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function createRuntime(
|
|
518
|
-
args: CreateRuntimeArgs,
|
|
519
|
-
handlers: RuntimeLifecycleHandlers = {},
|
|
520
|
-
): WordReviewEditorRuntime {
|
|
521
|
-
const docxSession = args.source.initialDocx
|
|
522
|
-
? loadDocxEditorSession({
|
|
523
|
-
documentId: args.documentId,
|
|
524
|
-
sourceLabel: args.source.sourceLabel,
|
|
525
|
-
bytes: args.source.initialDocx,
|
|
526
|
-
editorBuild: "dev",
|
|
527
|
-
})
|
|
528
|
-
: undefined;
|
|
529
|
-
const snapshotExportResolution = !args.source.initialDocx
|
|
530
|
-
? resolvePackageBackedExportSession(args)
|
|
531
|
-
: undefined;
|
|
532
|
-
const initialSessionState =
|
|
533
|
-
args.source.initialSessionState ??
|
|
534
|
-
docxSession?.initialSessionState ??
|
|
535
|
-
(args.source.initialSnapshot
|
|
536
|
-
? editorSessionStateFromPersistedSnapshot(args.source.initialSnapshot)
|
|
537
|
-
: editorSessionStateFromPersistedSnapshot(
|
|
538
|
-
createFallbackPersistedSnapshot(
|
|
539
|
-
args.documentId,
|
|
540
|
-
args.source.sourceLabel ?? "Generated shell snapshot",
|
|
541
|
-
),
|
|
542
|
-
));
|
|
543
|
-
const runtimeSessionState = snapshotExportResolution?.barrier
|
|
544
|
-
? applySessionExportBarrier(initialSessionState, snapshotExportResolution.barrier)
|
|
545
|
-
: initialSessionState;
|
|
546
|
-
|
|
547
|
-
const runtime: WordReviewEditorRuntime = Object.assign(createDocumentRuntime({
|
|
548
|
-
documentId: args.documentId,
|
|
549
|
-
initialSessionState: runtimeSessionState,
|
|
550
|
-
sourceKind: args.source.source,
|
|
551
|
-
sourceLabel: args.source.sourceLabel,
|
|
552
|
-
initialViewState: args.initialViewState,
|
|
553
|
-
readOnly: args.readOnly || docxSession?.readOnly,
|
|
554
|
-
editorBuild: runtimeSessionState.editorBuild,
|
|
555
|
-
fatalError: docxSession?.fatalError,
|
|
556
|
-
protectionSnapshot: docxSession?.protectionSnapshot,
|
|
557
|
-
exportDocx: async (sessionState, options) => {
|
|
558
|
-
if (docxSession) {
|
|
559
|
-
return docxSession.exportDocx(sessionState, options);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (snapshotExportResolution?.session) {
|
|
563
|
-
return snapshotExportResolution.session.exportDocx(sessionState, options);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
throw createSnapshotExportBlockedError(
|
|
567
|
-
args.documentId,
|
|
568
|
-
snapshotExportResolution?.barrier ?? {
|
|
569
|
-
reason: "missing_source_package_provenance",
|
|
570
|
-
message:
|
|
571
|
-
"DOCX export is blocked because this session does not carry embedded source package provenance.",
|
|
572
|
-
},
|
|
573
|
-
);
|
|
574
|
-
},
|
|
575
|
-
onWarning: handlers.onWarning,
|
|
576
|
-
onError: handlers.onError,
|
|
577
|
-
defaultAuthorId: args.currentUserId,
|
|
578
|
-
}), {
|
|
579
|
-
emitBlockedCommand: (
|
|
580
|
-
command: string,
|
|
581
|
-
reasons: Extract<WordReviewEditorEvent, { type: "command_blocked" }>["reasons"],
|
|
582
|
-
) => {
|
|
583
|
-
emitEditorEvent({
|
|
584
|
-
hostAdapter: args.hostAdapter,
|
|
585
|
-
datastore: args.datastore,
|
|
586
|
-
onEvent: handlers.onEvent,
|
|
587
|
-
event: {
|
|
588
|
-
type: "command_blocked",
|
|
589
|
-
documentId: args.documentId,
|
|
590
|
-
command,
|
|
591
|
-
reasons,
|
|
592
|
-
},
|
|
593
|
-
});
|
|
594
|
-
},
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
return runtime;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
function createLoadingSnapshot(
|
|
601
|
-
documentId: string,
|
|
602
|
-
readOnly: boolean,
|
|
603
|
-
sourceLabel?: string,
|
|
604
|
-
): RuntimeRenderSnapshot {
|
|
605
|
-
return {
|
|
606
|
-
documentId,
|
|
607
|
-
sessionId: `${documentId}-loading`,
|
|
608
|
-
sourceLabel,
|
|
609
|
-
revisionToken: `${documentId}:loading`,
|
|
610
|
-
isReady: false,
|
|
611
|
-
isDirty: false,
|
|
612
|
-
readOnly,
|
|
613
|
-
documentMode: "editing",
|
|
614
|
-
selection: collapsedSelection(),
|
|
615
|
-
activeStory: { kind: "main" },
|
|
616
|
-
documentStats: {
|
|
617
|
-
storyLength: 0,
|
|
618
|
-
commentCount: 0,
|
|
619
|
-
revisionCount: 0,
|
|
620
|
-
opaqueFragmentCount: 0,
|
|
621
|
-
},
|
|
622
|
-
comments: {
|
|
623
|
-
openCommentIds: [],
|
|
624
|
-
resolvedCommentIds: [],
|
|
625
|
-
detachedCommentIds: [],
|
|
626
|
-
totalCount: 0,
|
|
627
|
-
threads: [],
|
|
628
|
-
},
|
|
629
|
-
trackedChanges: {
|
|
630
|
-
pendingChangeIds: [],
|
|
631
|
-
acceptedChangeIds: [],
|
|
632
|
-
rejectedChangeIds: [],
|
|
633
|
-
detachedChangeIds: [],
|
|
634
|
-
actionableChangeIds: [],
|
|
635
|
-
preserveOnlyChangeIds: [],
|
|
636
|
-
totalCount: 0,
|
|
637
|
-
revisions: [],
|
|
638
|
-
},
|
|
639
|
-
compatibility: {
|
|
640
|
-
blockExport: false,
|
|
641
|
-
blockExportReasons: [],
|
|
642
|
-
warningCount: 0,
|
|
643
|
-
errorCount: 0,
|
|
644
|
-
featureEntries: [],
|
|
645
|
-
},
|
|
646
|
-
warnings: [],
|
|
647
|
-
commandState: {
|
|
648
|
-
canUndo: false,
|
|
649
|
-
canRedo: false,
|
|
650
|
-
readOnly,
|
|
651
|
-
},
|
|
652
|
-
protectionSnapshot: {
|
|
653
|
-
hasDocumentProtection: false,
|
|
654
|
-
enforcementActive: false,
|
|
655
|
-
ranges: [],
|
|
656
|
-
enforcedRangeCount: 0,
|
|
657
|
-
preservedRangeCount: 0,
|
|
658
|
-
},
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function createLoadingNavigationSnapshot(): DocumentNavigationSnapshot {
|
|
663
|
-
return {
|
|
664
|
-
pageCount: 0,
|
|
665
|
-
pages: [],
|
|
666
|
-
headings: [],
|
|
667
|
-
activePageIndex: 0,
|
|
668
|
-
activeSectionIndex: 0,
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function createLoadingViewStateSnapshot(
|
|
673
|
-
snapshot: RuntimeRenderSnapshot,
|
|
674
|
-
seed: {
|
|
675
|
-
workspaceMode?: WorkspaceMode;
|
|
676
|
-
zoomLevel?: ZoomLevel;
|
|
677
|
-
},
|
|
678
|
-
viewMode: EditorViewMode,
|
|
679
|
-
): EditorViewStateSnapshot {
|
|
680
|
-
return createEditorViewStateSnapshot(
|
|
681
|
-
createViewState({
|
|
682
|
-
viewMode,
|
|
683
|
-
workspaceMode: seed.workspaceMode,
|
|
684
|
-
zoomLevel: seed.zoomLevel,
|
|
685
|
-
}),
|
|
686
|
-
snapshot.activeStory,
|
|
687
|
-
snapshot.selection,
|
|
688
|
-
snapshot.surface,
|
|
689
|
-
snapshot.surface,
|
|
690
|
-
snapshot.pageLayout,
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
function createLoadingRuntimeBridge(input: {
|
|
695
|
-
snapshot: RuntimeRenderSnapshot;
|
|
696
|
-
sessionState: EditorSessionState;
|
|
697
|
-
viewState: EditorViewStateSnapshot;
|
|
698
|
-
navigation: DocumentNavigationSnapshot;
|
|
699
|
-
}): WordReviewEditorRuntime {
|
|
700
|
-
const emptyFieldSnapshot: FieldSnapshot = {
|
|
701
|
-
totalCount: 0,
|
|
702
|
-
supportedCount: 0,
|
|
703
|
-
preserveOnlyCount: 0,
|
|
704
|
-
fields: [],
|
|
705
|
-
};
|
|
706
|
-
const emptyFieldResult: UpdateFieldsResult = {
|
|
707
|
-
totalCount: 0,
|
|
708
|
-
updatedCount: 0,
|
|
709
|
-
preserveOnlyCount: 0,
|
|
710
|
-
};
|
|
711
|
-
const emptyTocResult: TocRefreshResult = {
|
|
712
|
-
entryCount: 0,
|
|
713
|
-
entries: [],
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
return {
|
|
717
|
-
subscribe: () => () => undefined,
|
|
718
|
-
subscribeToEvents: () => () => undefined,
|
|
719
|
-
emitBlockedCommand: () => undefined,
|
|
720
|
-
getRenderSnapshot: () => input.snapshot,
|
|
721
|
-
getCanonicalDocument: () => input.sessionState.canonicalDocument,
|
|
722
|
-
getSourcePackage: () => input.sessionState.sourcePackage,
|
|
723
|
-
replaceText: () => undefined,
|
|
724
|
-
applyActiveStoryTextCommand: () => undefined,
|
|
725
|
-
dispatch: () => undefined,
|
|
726
|
-
undo: () => undefined,
|
|
727
|
-
redo: () => undefined,
|
|
728
|
-
focus: () => undefined,
|
|
729
|
-
blur: () => undefined,
|
|
730
|
-
addComment: () => {
|
|
731
|
-
throw createLoadingBoundaryError(input.snapshot.documentId, "comment");
|
|
732
|
-
},
|
|
733
|
-
openComment: () => undefined,
|
|
734
|
-
resolveComment: () => undefined,
|
|
735
|
-
reopenComment: () => undefined,
|
|
736
|
-
addCommentReply: () => undefined,
|
|
737
|
-
editCommentBody: () => undefined,
|
|
738
|
-
acceptChange: () => undefined,
|
|
739
|
-
rejectChange: () => undefined,
|
|
740
|
-
acceptAllChanges: () => undefined,
|
|
741
|
-
rejectAllChanges: () => undefined,
|
|
742
|
-
openStory: () => false,
|
|
743
|
-
closeStory: () => undefined,
|
|
744
|
-
getActiveStory: () => input.snapshot.activeStory,
|
|
745
|
-
getViewState: () => input.viewState,
|
|
746
|
-
setViewMode: () => undefined,
|
|
747
|
-
setDocumentMode: () => undefined,
|
|
748
|
-
getProtectionSnapshot: () => input.snapshot.protectionSnapshot,
|
|
749
|
-
setWorkspaceMode: () => undefined,
|
|
750
|
-
setZoom: () => undefined,
|
|
751
|
-
getPageLayoutSnapshot: () => null,
|
|
752
|
-
getDocumentNavigationSnapshot: () => input.navigation,
|
|
753
|
-
getFieldSnapshot: () => emptyFieldSnapshot,
|
|
754
|
-
updateFields: () => emptyFieldResult,
|
|
755
|
-
updateTableOfContents: () => emptyTocResult,
|
|
756
|
-
getSessionState: () => {
|
|
757
|
-
throw createLoadingBoundaryError(input.snapshot.documentId, "session");
|
|
758
|
-
},
|
|
759
|
-
getPersistedSnapshot: () => {
|
|
760
|
-
throw createLoadingBoundaryError(input.snapshot.documentId, "snapshot");
|
|
761
|
-
},
|
|
762
|
-
getCompatibilityReport: () => ({
|
|
763
|
-
reportVersion: "compatibility-report/1",
|
|
764
|
-
generatedAt: input.sessionState.updatedAt,
|
|
765
|
-
blockExport: input.snapshot.compatibility.blockExport,
|
|
766
|
-
featureEntries: input.snapshot.compatibility.featureEntries,
|
|
767
|
-
warnings: input.snapshot.warnings,
|
|
768
|
-
errors: input.snapshot.fatalError ? [input.snapshot.fatalError] : [],
|
|
769
|
-
}),
|
|
770
|
-
getWarnings: () => input.snapshot.warnings,
|
|
771
|
-
exportDocx: () =>
|
|
772
|
-
Promise.reject(createLoadingBoundaryError(input.snapshot.documentId, "export")),
|
|
773
|
-
setWorkflowOverlay: () => undefined,
|
|
774
|
-
clearWorkflowOverlay: () => undefined,
|
|
775
|
-
getWorkflowScopeSnapshot: () => null,
|
|
776
|
-
getInteractionGuardSnapshot: () => ({ effectiveMode: "edit", blockedReasons: [] }),
|
|
777
|
-
getWorkflowMarkupSnapshot: () => ({
|
|
778
|
-
totalCount: 0,
|
|
779
|
-
items: [],
|
|
780
|
-
highlights: [],
|
|
781
|
-
comments: [],
|
|
782
|
-
revisions: [],
|
|
783
|
-
fields: [],
|
|
784
|
-
protectedRanges: [],
|
|
785
|
-
opaqueFragments: [],
|
|
786
|
-
}),
|
|
787
|
-
setHostAnnotationOverlay: () => undefined,
|
|
788
|
-
clearHostAnnotationOverlay: () => undefined,
|
|
789
|
-
getHostAnnotationSnapshot: () => ({
|
|
790
|
-
totalCount: 0,
|
|
791
|
-
annotations: [],
|
|
792
|
-
}),
|
|
793
|
-
getWorkflowCandidateRanges: () => [],
|
|
794
|
-
replaceWorkflowMarkupText: () => undefined,
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
function createLoadingBoundaryError(
|
|
799
|
-
documentId: string,
|
|
800
|
-
target: "comment" | "session" | "snapshot" | "export",
|
|
801
|
-
): EditorError {
|
|
802
|
-
return {
|
|
803
|
-
errorId: `${documentId}-loading-${target}`,
|
|
804
|
-
code: "internal_invariant",
|
|
805
|
-
message: "Editor is still loading.",
|
|
806
|
-
isFatal: false,
|
|
807
|
-
source: "runtime",
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
function deriveEditorViewMode(
|
|
812
|
-
readOnly: boolean,
|
|
813
|
-
reviewMode: WordReviewEditorProps["reviewMode"] = "review",
|
|
814
|
-
): EditorViewMode {
|
|
815
|
-
if (readOnly) {
|
|
816
|
-
return "view";
|
|
817
|
-
}
|
|
818
|
-
return reviewMode === "editing" ? "editing" : "review";
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
function createErrorSnapshot(documentId: string, error: EditorError): RuntimeRenderSnapshot {
|
|
822
|
-
return {
|
|
823
|
-
...createLoadingSnapshot(documentId, true),
|
|
824
|
-
isReady: true,
|
|
825
|
-
sessionId: `${documentId}-error`,
|
|
826
|
-
revisionToken: `${documentId}:error`,
|
|
827
|
-
compatibility: {
|
|
828
|
-
blockExport: true,
|
|
829
|
-
blockExportReasons: [error.message],
|
|
830
|
-
warningCount: 0,
|
|
831
|
-
errorCount: 1,
|
|
832
|
-
featureEntries: [],
|
|
833
|
-
},
|
|
834
|
-
fatalError: error,
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
export async function persistAndExport(input: {
|
|
839
|
-
hostAdapter?: EditorHostAdapter;
|
|
840
|
-
datastore?: EditorDatastoreAdapter;
|
|
841
|
-
documentId: string;
|
|
842
|
-
runtime: WordReviewEditorRuntime;
|
|
843
|
-
onError?: (error: EditorError) => void;
|
|
844
|
-
onEvent?: (event: WordReviewEditorEvent) => void;
|
|
845
|
-
options?: ExportDocxOptions;
|
|
846
|
-
lastSavedRevisionTokenRef: React.MutableRefObject<string | null>;
|
|
847
|
-
autosaveTimerRef: React.MutableRefObject<ReturnType<typeof setTimeout> | null>;
|
|
848
|
-
}): Promise<ExportResult> {
|
|
849
|
-
if (input.autosaveTimerRef.current) {
|
|
850
|
-
clearTimeout(input.autosaveTimerRef.current);
|
|
851
|
-
input.autosaveTimerRef.current = null;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
await persistSession({
|
|
855
|
-
hostAdapter: input.hostAdapter,
|
|
856
|
-
datastore: input.datastore,
|
|
857
|
-
documentId: input.documentId,
|
|
858
|
-
runtime: input.runtime,
|
|
859
|
-
isAutosave: false,
|
|
860
|
-
onError: input.onError,
|
|
861
|
-
onEvent: input.onEvent,
|
|
862
|
-
lastSavedRevisionTokenRef: input.lastSavedRevisionTokenRef,
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
let result: ExportResult;
|
|
866
|
-
try {
|
|
867
|
-
result = await input.runtime.exportDocx(input.options);
|
|
868
|
-
} catch (error) {
|
|
869
|
-
const normalized = normalizeExportError(error, input.documentId, input.options);
|
|
870
|
-
input.onError?.(normalized);
|
|
871
|
-
emitEditorEvent({
|
|
872
|
-
hostAdapter: input.hostAdapter,
|
|
873
|
-
datastore: input.datastore,
|
|
874
|
-
onEvent: input.onEvent,
|
|
875
|
-
event: {
|
|
876
|
-
type: "error",
|
|
877
|
-
documentId: input.documentId,
|
|
878
|
-
error: normalized,
|
|
879
|
-
},
|
|
880
|
-
});
|
|
881
|
-
throw normalized;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
const saveExport = input.hostAdapter?.saveExport ?? input.datastore?.saveExport;
|
|
885
|
-
const saveExportSource = input.hostAdapter?.saveExport ? "host" : "datastore";
|
|
886
|
-
if (!saveExport) {
|
|
887
|
-
result = downloadExportResult(result);
|
|
888
|
-
emitEditorEvent({
|
|
889
|
-
hostAdapter: input.hostAdapter,
|
|
890
|
-
datastore: input.datastore,
|
|
891
|
-
onEvent: input.onEvent,
|
|
892
|
-
event: {
|
|
893
|
-
type: "export_completed",
|
|
894
|
-
documentId: input.documentId,
|
|
895
|
-
result,
|
|
896
|
-
},
|
|
897
|
-
});
|
|
898
|
-
return result;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
try {
|
|
902
|
-
const saveResult = await saveExport({
|
|
903
|
-
documentId: input.documentId,
|
|
904
|
-
result,
|
|
905
|
-
});
|
|
906
|
-
result = withExportDelivery(result, {
|
|
907
|
-
mode: "persisted-by-host",
|
|
908
|
-
savedAt: saveResult.savedAt,
|
|
909
|
-
});
|
|
910
|
-
} catch (error) {
|
|
911
|
-
const normalized = normalizeStorageError(error, {
|
|
912
|
-
message: "Export persisted bytes could not be stored.",
|
|
913
|
-
source: saveExportSource,
|
|
914
|
-
details: {
|
|
915
|
-
operation: "saveExport",
|
|
916
|
-
},
|
|
917
|
-
});
|
|
918
|
-
input.onError?.(normalized);
|
|
919
|
-
emitEditorEvent({
|
|
920
|
-
hostAdapter: input.hostAdapter,
|
|
921
|
-
datastore: input.datastore,
|
|
922
|
-
onEvent: input.onEvent,
|
|
923
|
-
event: {
|
|
924
|
-
type: "error",
|
|
925
|
-
documentId: input.documentId,
|
|
926
|
-
error: normalized,
|
|
927
|
-
},
|
|
928
|
-
});
|
|
929
|
-
result = withExportDelivery(result, {
|
|
930
|
-
mode: "exported-bytes-only",
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
emitEditorEvent({
|
|
935
|
-
hostAdapter: input.hostAdapter,
|
|
936
|
-
datastore: input.datastore,
|
|
937
|
-
onEvent: input.onEvent,
|
|
938
|
-
event: {
|
|
939
|
-
type: "export_completed",
|
|
940
|
-
documentId: input.documentId,
|
|
941
|
-
result,
|
|
942
|
-
},
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
return result;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
export function rejectExportWhileLoading(input: {
|
|
949
|
-
documentId: string;
|
|
950
|
-
hostAdapter?: EditorHostAdapter;
|
|
951
|
-
datastore?: EditorDatastoreAdapter;
|
|
952
|
-
onError?: (error: EditorError) => void;
|
|
953
|
-
onEvent?: (event: WordReviewEditorEvent) => void;
|
|
954
|
-
}): Promise<never> {
|
|
955
|
-
const error: EditorError = {
|
|
956
|
-
errorId: "word-review-editor-loading-export",
|
|
957
|
-
code: "internal_invariant",
|
|
958
|
-
message: "WordReviewEditor is still loading and cannot export yet.",
|
|
959
|
-
isFatal: false,
|
|
960
|
-
source: "runtime",
|
|
961
|
-
};
|
|
962
|
-
input.onError?.(error);
|
|
963
|
-
emitEditorEvent({
|
|
964
|
-
hostAdapter: input.hostAdapter,
|
|
965
|
-
datastore: input.datastore,
|
|
966
|
-
onEvent: input.onEvent,
|
|
967
|
-
event: {
|
|
968
|
-
type: "error",
|
|
969
|
-
documentId: input.documentId,
|
|
970
|
-
error,
|
|
971
|
-
},
|
|
972
|
-
});
|
|
973
|
-
return Promise.reject(error);
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
export async function persistSession(input: {
|
|
977
|
-
hostAdapter?: EditorHostAdapter;
|
|
978
|
-
datastore?: EditorDatastoreAdapter;
|
|
979
|
-
documentId: string;
|
|
980
|
-
runtime: WordReviewEditorRuntime;
|
|
981
|
-
isAutosave: boolean;
|
|
982
|
-
onError?: (error: EditorError) => void;
|
|
983
|
-
onEvent?: (event: WordReviewEditorEvent) => void;
|
|
984
|
-
lastSavedRevisionTokenRef: React.MutableRefObject<string | null>;
|
|
985
|
-
}): Promise<void> {
|
|
986
|
-
const saveSession = input.hostAdapter?.saveSession;
|
|
987
|
-
const saveSnapshot = input.datastore?.saveSnapshot;
|
|
988
|
-
if (!saveSession && !saveSnapshot) {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
const sessionState = input.runtime.getSessionState();
|
|
993
|
-
const snapshot = input.runtime.getPersistedSnapshot();
|
|
994
|
-
const revisionToken = input.runtime.getRenderSnapshot().revisionToken;
|
|
995
|
-
|
|
996
|
-
if (input.isAutosave) {
|
|
997
|
-
emitEditorEvent({
|
|
998
|
-
hostAdapter: input.hostAdapter,
|
|
999
|
-
datastore: input.datastore,
|
|
1000
|
-
onEvent: input.onEvent,
|
|
1001
|
-
event: {
|
|
1002
|
-
type: "autosave_state",
|
|
1003
|
-
documentId: input.documentId,
|
|
1004
|
-
state: {
|
|
1005
|
-
status: "saving",
|
|
1006
|
-
} satisfies AutosaveState,
|
|
1007
|
-
},
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
try {
|
|
1012
|
-
const result = saveSession
|
|
1013
|
-
? await saveSession({
|
|
1014
|
-
documentId: input.documentId,
|
|
1015
|
-
sessionState,
|
|
1016
|
-
isAutosave: input.isAutosave,
|
|
1017
|
-
})
|
|
1018
|
-
: await saveSnapshot!({
|
|
1019
|
-
documentId: input.documentId,
|
|
1020
|
-
snapshot,
|
|
1021
|
-
isAutosave: input.isAutosave,
|
|
1022
|
-
});
|
|
1023
|
-
input.lastSavedRevisionTokenRef.current = revisionToken;
|
|
1024
|
-
emitEditorEvent({
|
|
1025
|
-
hostAdapter: input.hostAdapter,
|
|
1026
|
-
datastore: input.datastore,
|
|
1027
|
-
onEvent: input.onEvent,
|
|
1028
|
-
event: saveSession
|
|
1029
|
-
? {
|
|
1030
|
-
type: "session_saved",
|
|
1031
|
-
documentId: input.documentId,
|
|
1032
|
-
sessionState: input.runtime.getSessionState(),
|
|
1033
|
-
savedAt: result.savedAt,
|
|
1034
|
-
isAutosave: input.isAutosave,
|
|
1035
|
-
}
|
|
1036
|
-
: {
|
|
1037
|
-
type: "snapshot_saved",
|
|
1038
|
-
documentId: input.documentId,
|
|
1039
|
-
snapshot: {
|
|
1040
|
-
...snapshot,
|
|
1041
|
-
savedAt: result.savedAt,
|
|
1042
|
-
},
|
|
1043
|
-
isAutosave: input.isAutosave,
|
|
1044
|
-
},
|
|
1045
|
-
});
|
|
1046
|
-
if (input.isAutosave) {
|
|
1047
|
-
emitEditorEvent({
|
|
1048
|
-
hostAdapter: input.hostAdapter,
|
|
1049
|
-
datastore: input.datastore,
|
|
1050
|
-
onEvent: input.onEvent,
|
|
1051
|
-
event: {
|
|
1052
|
-
type: "autosave_state",
|
|
1053
|
-
documentId: input.documentId,
|
|
1054
|
-
state: {
|
|
1055
|
-
status: "saved",
|
|
1056
|
-
savedAt: result.savedAt,
|
|
1057
|
-
} satisfies AutosaveState,
|
|
1058
|
-
},
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
} catch (error) {
|
|
1062
|
-
const normalized = normalizeStorageError(error, {
|
|
1063
|
-
message: input.isAutosave
|
|
1064
|
-
? saveSession
|
|
1065
|
-
? "Autosave failed while storing the editor session."
|
|
1066
|
-
: "Autosave failed while storing the editor snapshot."
|
|
1067
|
-
: saveSession
|
|
1068
|
-
? "Session save failed while preparing the export checkpoint."
|
|
1069
|
-
: "Snapshot save failed while preparing the export checkpoint.",
|
|
1070
|
-
source: saveSession ? "host" : "datastore",
|
|
1071
|
-
details: {
|
|
1072
|
-
operation: saveSession ? "saveSession" : "saveSnapshot",
|
|
1073
|
-
isAutosave: input.isAutosave,
|
|
1074
|
-
},
|
|
1075
|
-
});
|
|
1076
|
-
input.onError?.(normalized);
|
|
1077
|
-
emitEditorEvent({
|
|
1078
|
-
hostAdapter: input.hostAdapter,
|
|
1079
|
-
datastore: input.datastore,
|
|
1080
|
-
onEvent: input.onEvent,
|
|
1081
|
-
event: {
|
|
1082
|
-
type: "error",
|
|
1083
|
-
documentId: input.documentId,
|
|
1084
|
-
error: normalized,
|
|
1085
|
-
},
|
|
1086
|
-
});
|
|
1087
|
-
if (input.isAutosave) {
|
|
1088
|
-
emitEditorEvent({
|
|
1089
|
-
hostAdapter: input.hostAdapter,
|
|
1090
|
-
datastore: input.datastore,
|
|
1091
|
-
onEvent: input.onEvent,
|
|
1092
|
-
event: {
|
|
1093
|
-
type: "autosave_state",
|
|
1094
|
-
documentId: input.documentId,
|
|
1095
|
-
state: {
|
|
1096
|
-
status: "error",
|
|
1097
|
-
error: normalized,
|
|
1098
|
-
} satisfies AutosaveState,
|
|
1099
|
-
},
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
if (!input.isAutosave) {
|
|
1103
|
-
throw normalized;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
function emitEditorEvent(input: {
|
|
1109
|
-
hostAdapter?: EditorHostAdapter;
|
|
1110
|
-
datastore?: EditorDatastoreAdapter;
|
|
1111
|
-
onEvent?: (event: WordReviewEditorEvent) => void;
|
|
1112
|
-
event: WordReviewEditorEvent;
|
|
1113
|
-
}): void {
|
|
1114
|
-
input.onEvent?.(input.event);
|
|
1115
|
-
const logEvent = input.hostAdapter?.logEvent ?? input.datastore?.logEvent;
|
|
1116
|
-
logEvent?.({
|
|
1117
|
-
type: input.event.type,
|
|
1118
|
-
documentId: input.event.documentId,
|
|
1119
|
-
detail: summarizeEventDetail(input.event),
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
function summarizeEventDetail(
|
|
1124
|
-
event: WordReviewEditorEvent,
|
|
1125
|
-
): Record<string, unknown> | undefined {
|
|
1126
|
-
switch (event.type) {
|
|
1127
|
-
case "dirty_changed":
|
|
1128
|
-
return { isDirty: event.isDirty };
|
|
1129
|
-
case "comment_added":
|
|
1130
|
-
case "comment_resolved":
|
|
1131
|
-
return { commentId: event.commentId };
|
|
1132
|
-
case "change_accepted":
|
|
1133
|
-
case "change_rejected":
|
|
1134
|
-
return { changeId: event.changeId };
|
|
1135
|
-
case "warning_added":
|
|
1136
|
-
return { warningId: event.warning.warningId, code: event.warning.code };
|
|
1137
|
-
case "warning_cleared":
|
|
1138
|
-
return { warningId: event.warningId, code: event.code };
|
|
1139
|
-
case "error":
|
|
1140
|
-
return { errorId: event.error.errorId, code: event.error.code };
|
|
1141
|
-
case "autosave_state":
|
|
1142
|
-
return { status: event.state.status };
|
|
1143
|
-
case "snapshot_saved":
|
|
1144
|
-
return { isAutosave: event.isAutosave, savedAt: event.snapshot.savedAt };
|
|
1145
|
-
case "session_saved":
|
|
1146
|
-
return { isAutosave: event.isAutosave, savedAt: event.savedAt };
|
|
1147
|
-
case "export_completed":
|
|
1148
|
-
return {
|
|
1149
|
-
fileName: event.result.fileName,
|
|
1150
|
-
deliveryMode: event.result.delivery?.mode,
|
|
1151
|
-
savedAt: event.result.delivery?.savedAt,
|
|
1152
|
-
};
|
|
1153
|
-
case "story_changed":
|
|
1154
|
-
return { activeStory: event.activeStory };
|
|
1155
|
-
case "selection_changed":
|
|
1156
|
-
return {
|
|
1157
|
-
anchor: event.selection.anchor,
|
|
1158
|
-
head: event.selection.head,
|
|
1159
|
-
};
|
|
1160
|
-
case "ready":
|
|
1161
|
-
return {
|
|
1162
|
-
source: event.source,
|
|
1163
|
-
blockExport: event.compatibility.blockExport,
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
function createReadyEvent(
|
|
1169
|
-
runtime: Pick<WordReviewEditorRuntime, "getCompatibilityReport" | "getRenderSnapshot">,
|
|
1170
|
-
source: "docx" | "session" | "snapshot",
|
|
1171
|
-
): Extract<WordReviewEditorEvent, { type: "ready" }> {
|
|
1172
|
-
const snapshot = runtime.getRenderSnapshot();
|
|
1173
|
-
return {
|
|
1174
|
-
type: "ready",
|
|
1175
|
-
documentId: snapshot.documentId,
|
|
1176
|
-
sessionId: snapshot.sessionId,
|
|
1177
|
-
source,
|
|
1178
|
-
stats: snapshot.documentStats,
|
|
1179
|
-
compatibility: runtime.getCompatibilityReport(),
|
|
1180
|
-
comments: snapshot.comments,
|
|
1181
|
-
trackedChanges: snapshot.trackedChanges,
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
function normalizeEditorError(error: unknown): EditorError {
|
|
1186
|
-
if (
|
|
1187
|
-
typeof error === "object" &&
|
|
1188
|
-
error !== null &&
|
|
1189
|
-
"errorId" in error &&
|
|
1190
|
-
"code" in error &&
|
|
1191
|
-
"message" in error
|
|
1192
|
-
) {
|
|
1193
|
-
return error as EditorError;
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
return {
|
|
1197
|
-
errorId: "word-review-editor-load",
|
|
1198
|
-
code: "internal_invariant",
|
|
1199
|
-
message: error instanceof Error ? error.message : "Unknown editor load failure.",
|
|
1200
|
-
isFatal: true,
|
|
1201
|
-
source: "runtime",
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
function guessSourceLabel(
|
|
1206
|
-
initialSourceLabel?: string,
|
|
1207
|
-
initialSessionState?: EditorSessionState,
|
|
1208
|
-
initialSnapshot?: PersistedEditorSnapshot,
|
|
1209
|
-
externalDocSource?: WordReviewEditorProps["externalDocSource"],
|
|
1210
|
-
): string | undefined {
|
|
1211
|
-
return (
|
|
1212
|
-
externalDocSource?.sourceLabel ??
|
|
1213
|
-
(externalDocSource?.kind === "session"
|
|
1214
|
-
? externalDocSource.sessionState.sourcePackage?.sourceLabel
|
|
1215
|
-
: undefined) ??
|
|
1216
|
-
(externalDocSource?.kind === "snapshot"
|
|
1217
|
-
? externalDocSource.snapshot.sourcePackage?.sourceLabel
|
|
1218
|
-
: undefined) ??
|
|
1219
|
-
initialSourceLabel ??
|
|
1220
|
-
initialSessionState?.sourcePackage?.sourceLabel ??
|
|
1221
|
-
initialSessionState?.editorBuild ??
|
|
1222
|
-
initialSnapshot?.sourcePackage?.sourceLabel ??
|
|
1223
|
-
initialSnapshot?.editorBuild ??
|
|
1224
|
-
undefined
|
|
1225
|
-
);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
function createFallbackPersistedSnapshot(
|
|
1229
|
-
documentId: string,
|
|
1230
|
-
label = "Generated shell snapshot",
|
|
1231
|
-
): PersistedEditorSnapshot {
|
|
1232
|
-
const docId = createCanonicalDocumentId(documentId);
|
|
1233
|
-
return {
|
|
1234
|
-
snapshotVersion: "persisted-editor-snapshot/2",
|
|
1235
|
-
schemaVersion: "cds/1.0.0",
|
|
1236
|
-
documentId,
|
|
1237
|
-
docId,
|
|
1238
|
-
createdAt: "1970-01-01T00:00:00.000Z",
|
|
1239
|
-
updatedAt: "1970-01-01T00:00:00.000Z",
|
|
1240
|
-
savedAt: "1970-01-01T00:00:00.000Z",
|
|
1241
|
-
editorBuild: label,
|
|
1242
|
-
canonicalDocument: {
|
|
1243
|
-
schemaVersion: "cds/1.0.0",
|
|
1244
|
-
docId,
|
|
1245
|
-
createdAt: "1970-01-01T00:00:00.000Z",
|
|
1246
|
-
updatedAt: "1970-01-01T00:00:00.000Z",
|
|
1247
|
-
metadata: { customProperties: {} },
|
|
1248
|
-
styles: { paragraphs: {}, characters: {}, tables: {} },
|
|
1249
|
-
numbering: { abstractDefinitions: {}, instances: {} },
|
|
1250
|
-
media: { items: {} },
|
|
1251
|
-
content: {
|
|
1252
|
-
type: "doc",
|
|
1253
|
-
children: [{ type: "paragraph", children: [] }],
|
|
1254
|
-
},
|
|
1255
|
-
review: { comments: {}, revisions: {} },
|
|
1256
|
-
preservation: { opaqueFragments: {}, packageParts: {} },
|
|
1257
|
-
diagnostics: { warnings: [], errors: [] },
|
|
1258
|
-
},
|
|
1259
|
-
compatibility: emptyCompatibilityReport(),
|
|
1260
|
-
warningLog: [],
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
function emptyCompatibilityReport(): CompatibilityReport {
|
|
1265
|
-
return {
|
|
1266
|
-
reportVersion: "compatibility-report/1",
|
|
1267
|
-
generatedAt: "1970-01-01T00:00:00.000Z",
|
|
1268
|
-
blockExport: false,
|
|
1269
|
-
featureEntries: [],
|
|
1270
|
-
warnings: [],
|
|
1271
|
-
errors: [],
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
function resolvePackageBackedExportSession(args: CreateRuntimeArgs): {
|
|
1276
|
-
session?: PackageBackedDocxSession;
|
|
1277
|
-
barrier?: SnapshotExportBarrier;
|
|
1278
|
-
} {
|
|
1279
|
-
const sourcePackage =
|
|
1280
|
-
args.source.initialSessionState?.sourcePackage ??
|
|
1281
|
-
args.source.initialSnapshot?.sourcePackage;
|
|
1282
|
-
if (!sourcePackage) {
|
|
1283
|
-
return {
|
|
1284
|
-
barrier: {
|
|
1285
|
-
reason: "missing_source_package_provenance",
|
|
1286
|
-
message:
|
|
1287
|
-
"DOCX export is blocked because this session was loaded without embedded source package provenance.",
|
|
1288
|
-
},
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
try {
|
|
1293
|
-
const bytes = decodePersistedSourcePackageBytes(sourcePackage);
|
|
1294
|
-
if (!hasValidPersistedSourcePackageDigest(sourcePackage, bytes)) {
|
|
1295
|
-
return {
|
|
1296
|
-
barrier: {
|
|
1297
|
-
reason: "invalid_source_package_provenance",
|
|
1298
|
-
message:
|
|
1299
|
-
"DOCX export is blocked because the embedded source package provenance failed its integrity check.",
|
|
1300
|
-
},
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
const session = loadDocxEditorSession({
|
|
1305
|
-
documentId: args.documentId,
|
|
1306
|
-
sourceLabel: sourcePackage.sourceLabel ?? args.source.sourceLabel,
|
|
1307
|
-
bytes,
|
|
1308
|
-
editorBuild:
|
|
1309
|
-
args.source.initialSessionState?.editorBuild ??
|
|
1310
|
-
args.source.initialSnapshot?.editorBuild ??
|
|
1311
|
-
"dev",
|
|
1312
|
-
});
|
|
1313
|
-
if (session.readOnly || session.fatalError) {
|
|
1314
|
-
return {
|
|
1315
|
-
barrier: {
|
|
1316
|
-
reason: "invalid_source_package_provenance",
|
|
1317
|
-
message:
|
|
1318
|
-
"DOCX export is blocked because the embedded source package provenance is no longer loadable as a valid package-backed session.",
|
|
1319
|
-
},
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
return { session };
|
|
1324
|
-
} catch {
|
|
1325
|
-
return {
|
|
1326
|
-
barrier: {
|
|
1327
|
-
reason: "invalid_source_package_provenance",
|
|
1328
|
-
message:
|
|
1329
|
-
"DOCX export is blocked because the embedded source package provenance could not be decoded into a package-backed session.",
|
|
1330
|
-
},
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
function applySessionExportBarrier(
|
|
1336
|
-
sessionState: EditorSessionState,
|
|
1337
|
-
barrier: SnapshotExportBarrier,
|
|
1338
|
-
): EditorSessionState {
|
|
1339
|
-
const featureEntryId = `feature:source-package-provenance:${barrier.reason}`;
|
|
1340
|
-
const featureEntries = sessionState.compatibility.featureEntries.some(
|
|
1341
|
-
(entry) => entry.featureEntryId === featureEntryId,
|
|
1342
|
-
)
|
|
1343
|
-
? sessionState.compatibility.featureEntries
|
|
1344
|
-
: [
|
|
1345
|
-
...sessionState.compatibility.featureEntries,
|
|
1346
|
-
{
|
|
1347
|
-
featureEntryId,
|
|
1348
|
-
featureKey: "source-package-provenance",
|
|
1349
|
-
featureClass: "unsupported-fatal" as const,
|
|
1350
|
-
message: barrier.message,
|
|
1351
|
-
details: {
|
|
1352
|
-
reason: barrier.reason,
|
|
1353
|
-
},
|
|
1354
|
-
},
|
|
1355
|
-
];
|
|
1356
|
-
|
|
1357
|
-
return {
|
|
1358
|
-
...sessionState,
|
|
1359
|
-
compatibility: {
|
|
1360
|
-
...sessionState.compatibility,
|
|
1361
|
-
blockExport: true,
|
|
1362
|
-
featureEntries,
|
|
1363
|
-
},
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
function createSnapshotExportBlockedError(
|
|
1368
|
-
documentId: string,
|
|
1369
|
-
barrier: SnapshotExportBarrier,
|
|
1370
|
-
): EditorError {
|
|
1371
|
-
return {
|
|
1372
|
-
errorId: `${documentId}:export:${barrier.reason}`,
|
|
1373
|
-
code: "export_failed",
|
|
1374
|
-
message: barrier.message,
|
|
1375
|
-
isFatal: false,
|
|
1376
|
-
source: "export",
|
|
1377
|
-
details: {
|
|
1378
|
-
reason: barrier.reason,
|
|
1379
|
-
},
|
|
1380
|
-
};
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
function normalizeStorageError(
|
|
1384
|
-
error: unknown,
|
|
1385
|
-
fallback: {
|
|
1386
|
-
message: string;
|
|
1387
|
-
source: "host" | "datastore";
|
|
1388
|
-
details?: Record<string, unknown>;
|
|
1389
|
-
},
|
|
1390
|
-
): EditorError {
|
|
1391
|
-
if (
|
|
1392
|
-
typeof error === "object" &&
|
|
1393
|
-
error !== null &&
|
|
1394
|
-
"errorId" in error &&
|
|
1395
|
-
"code" in error &&
|
|
1396
|
-
"message" in error
|
|
1397
|
-
) {
|
|
1398
|
-
return error as EditorError;
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
return {
|
|
1402
|
-
errorId:
|
|
1403
|
-
fallback.source === "host"
|
|
1404
|
-
? "word-review-editor-host"
|
|
1405
|
-
: "word-review-editor-datastore",
|
|
1406
|
-
code: "datastore_failed",
|
|
1407
|
-
message: error instanceof Error ? error.message : fallback.message,
|
|
1408
|
-
isFatal: false,
|
|
1409
|
-
source: fallback.source === "host" ? "host" : "datastore",
|
|
1410
|
-
details: fallback.details,
|
|
1411
|
-
};
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
function normalizeExportError(
|
|
1415
|
-
error: unknown,
|
|
1416
|
-
documentId: string,
|
|
1417
|
-
options?: ExportDocxOptions,
|
|
1418
|
-
): EditorError {
|
|
1419
|
-
if (
|
|
1420
|
-
typeof error === "object" &&
|
|
1421
|
-
error !== null &&
|
|
1422
|
-
"errorId" in error &&
|
|
1423
|
-
"code" in error &&
|
|
1424
|
-
"message" in error
|
|
1425
|
-
) {
|
|
1426
|
-
return error as EditorError;
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
return {
|
|
1430
|
-
errorId: `${documentId}:export:failed`,
|
|
1431
|
-
code: "export_failed",
|
|
1432
|
-
message:
|
|
1433
|
-
error instanceof Error ? error.message : "DOCX export failed for an unknown reason.",
|
|
1434
|
-
isFatal: false,
|
|
1435
|
-
source: "export",
|
|
1436
|
-
details: {
|
|
1437
|
-
requestedOptions: options ?? {},
|
|
1438
|
-
},
|
|
1439
|
-
};
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
function collapsedSelection(): RuntimeRenderSnapshot["selection"] {
|
|
1443
|
-
return {
|
|
1444
|
-
anchor: 0,
|
|
1445
|
-
head: 0,
|
|
1446
|
-
isCollapsed: true,
|
|
1447
|
-
activeRange: {
|
|
1448
|
-
kind: "range",
|
|
1449
|
-
from: 0,
|
|
1450
|
-
to: 0,
|
|
1451
|
-
assoc: {
|
|
1452
|
-
start: -1,
|
|
1453
|
-
end: 1,
|
|
1454
|
-
},
|
|
1455
|
-
},
|
|
1456
|
-
};
|
|
1457
|
-
}
|