@beyondwork/docx-react-component 1.0.29 → 1.0.30
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/package.json +65 -96
- package/src/README.md +85 -0
- package/src/api/README.md +26 -0
- package/src/api/public-types.ts +1952 -0
- package/src/api/session-state.ts +62 -0
- package/src/compare/diff-engine.ts +623 -0
- package/src/compare/export-redlines.ts +280 -0
- package/src/compare/index.ts +25 -0
- package/src/compare/snapshot.ts +97 -0
- package/src/component-inventory.md +99 -0
- package/src/core/README.md +10 -0
- package/src/core/commands/README.md +3 -0
- package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
- package/src/core/commands/image-commands.ts +373 -0
- package/src/core/commands/index.ts +1879 -0
- package/src/core/commands/list-commands.ts +565 -0
- package/src/core/commands/paragraph-layout-commands.ts +339 -0
- package/src/core/commands/review-commands.ts +108 -0
- package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
- package/src/core/commands/structural-helpers.ts +309 -0
- package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
- package/src/core/commands/table-structure-commands.ts +854 -0
- package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
- package/src/core/schema/README.md +3 -0
- package/src/core/schema/text-schema.ts +516 -0
- package/src/core/search/search-text.ts +357 -0
- package/src/core/selection/README.md +3 -0
- package/src/core/selection/mapping.ts +289 -0
- package/src/core/selection/review-anchors.ts +183 -0
- package/src/core/state/README.md +3 -0
- package/src/core/state/editor-state.ts +892 -0
- package/src/core/state/text-transaction.ts +869 -0
- package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
- package/src/formats/xlsx/io/parse-sheet.ts +459 -0
- package/src/formats/xlsx/io/parse-styles.ts +59 -0
- package/src/formats/xlsx/io/parse-workbook.ts +75 -0
- package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
- package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
- package/src/formats/xlsx/io/serialize-styles.ts +98 -0
- package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
- package/src/formats/xlsx/io/xlsx-session.ts +314 -0
- package/src/formats/xlsx/model/cell.ts +189 -0
- package/src/formats/xlsx/model/sheet.ts +326 -0
- package/src/formats/xlsx/model/styles.ts +118 -0
- package/src/formats/xlsx/model/workbook.ts +453 -0
- package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
- package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
- package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
- package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
- package/src/index.ts +142 -0
- package/src/io/README.md +10 -0
- package/src/io/docx-session.ts +3175 -0
- package/src/io/export/README.md +3 -0
- package/src/io/export/export-session.ts +220 -0
- package/src/io/export/minimal-docx.ts +115 -0
- package/src/io/export/reattach-preserved-parts.ts +54 -0
- package/src/io/export/serialize-comments.ts +947 -0
- package/src/io/export/serialize-footnotes.ts +394 -0
- package/src/io/export/serialize-headers-footers.ts +368 -0
- package/src/io/export/serialize-main-document.ts +1342 -0
- package/src/io/export/serialize-numbering.ts +218 -0
- package/src/io/export/serialize-revisions.ts +389 -0
- package/src/io/export/serialize-runtime-revisions.ts +463 -0
- package/src/io/export/serialize-tables.ts +174 -0
- package/src/io/export/split-review-boundaries.ts +356 -0
- package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
- package/src/io/export/table-properties-xml.ts +318 -0
- package/src/io/normalize/README.md +3 -0
- package/src/io/normalize/normalize-text.ts +670 -0
- package/src/io/ooxml/README.md +3 -0
- package/src/io/ooxml/highlight-colors.ts +39 -0
- package/src/io/ooxml/numbering-sentinels.ts +44 -0
- package/src/io/ooxml/parse-comments.ts +852 -0
- package/src/io/ooxml/parse-complex-content.ts +287 -0
- package/src/io/ooxml/parse-fields.ts +834 -0
- package/src/io/ooxml/parse-footnotes.ts +952 -0
- package/src/io/ooxml/parse-headers-footers.ts +1212 -0
- package/src/io/ooxml/parse-inline-media.ts +461 -0
- package/src/io/ooxml/parse-main-document.ts +2947 -0
- package/src/io/ooxml/parse-numbering.ts +747 -0
- package/src/io/ooxml/parse-revisions.ts +1045 -0
- package/src/io/ooxml/parse-settings.ts +184 -0
- package/src/io/ooxml/parse-shapes.ts +296 -0
- package/src/io/ooxml/parse-styles.ts +639 -0
- package/src/io/ooxml/parse-tables.ts +627 -0
- package/src/io/ooxml/parse-theme.ts +346 -0
- package/src/io/ooxml/part-manifest.ts +136 -0
- package/src/io/ooxml/revision-boundaries.ts +475 -0
- package/src/io/ooxml/workflow-payload.ts +544 -0
- package/src/io/opc/README.md +3 -0
- package/src/io/opc/corrupt-package.ts +166 -0
- package/src/io/opc/docx-package.ts +74 -0
- package/src/io/opc/package-reader.ts +325 -0
- package/src/io/opc/package-writer.ts +273 -0
- package/src/io/source-package-provenance.ts +241 -0
- package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
- package/src/legal/cross-references.ts +414 -0
- package/src/legal/defined-terms.ts +203 -0
- package/src/legal/index.ts +32 -0
- package/src/legal/signature-blocks.ts +259 -0
- package/src/model/README.md +3 -0
- package/src/model/canonical-document.ts +2722 -0
- package/src/model/cds-1.0.0.ts +212 -0
- package/src/model/snapshot.ts +760 -0
- package/src/preservation/README.md +3 -0
- package/src/preservation/markup-compatibility.ts +48 -0
- package/src/preservation/opaque-fragment-store.ts +89 -0
- package/src/preservation/opaque-region.ts +233 -0
- package/src/preservation/package-preservation.ts +113 -0
- package/src/preservation/preserved-part-manifest.ts +56 -0
- package/src/preservation/relationship-retention.ts +57 -0
- package/src/preservation/store.ts +255 -0
- package/src/review/README.md +16 -0
- package/src/review/store/README.md +3 -0
- package/src/review/store/comment-anchors.ts +70 -0
- package/src/review/store/comment-remapping.ts +154 -0
- package/src/review/store/comment-store.ts +349 -0
- package/src/review/store/comment-thread.ts +109 -0
- package/src/review/store/revision-actions.ts +423 -0
- package/src/review/store/revision-store.ts +323 -0
- package/src/review/store/revision-types.ts +182 -0
- package/src/review/store/runtime-comment-store.ts +43 -0
- package/src/runtime/README.md +3 -0
- package/src/runtime/ai-action-policy.ts +764 -0
- package/src/runtime/context-analytics.ts +824 -0
- package/src/runtime/document-layout.ts +332 -0
- package/src/runtime/document-locations.ts +521 -0
- package/src/runtime/document-navigation.ts +616 -0
- package/src/runtime/document-outline.ts +440 -0
- package/src/runtime/document-runtime.ts +4055 -0
- package/src/runtime/document-search.ts +145 -0
- package/src/runtime/event-refresh-hints.ts +137 -0
- package/src/runtime/numbering-prefix.ts +244 -0
- package/src/runtime/page-layout-estimation.ts +305 -0
- package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
- package/src/runtime/resolved-numbering-geometry.ts +293 -0
- package/src/runtime/review-runtime.ts +44 -0
- package/src/runtime/revision-runtime.ts +107 -0
- package/src/runtime/session-capabilities.ts +192 -0
- package/src/runtime/story-context.ts +164 -0
- package/src/runtime/story-targeting.ts +162 -0
- package/src/runtime/suggestions-snapshot.ts +137 -0
- package/src/runtime/surface-projection.ts +1553 -0
- package/src/runtime/table-commands.ts +173 -0
- package/src/runtime/table-schema.ts +309 -0
- package/src/runtime/table-style-resolver.ts +409 -0
- package/src/runtime/view-state.ts +493 -0
- package/src/runtime/virtualized-rendering.ts +258 -0
- package/src/runtime/workflow-markup.ts +393 -0
- package/src/ui/README.md +30 -0
- package/src/ui/WordReviewEditor.tsx +5268 -0
- package/src/ui/browser-export.ts +52 -0
- package/src/ui/comments/README.md +3 -0
- package/src/ui/compatibility/README.md +3 -0
- package/src/ui/editor-command-bag.ts +127 -0
- package/src/ui/editor-runtime-boundary.ts +1558 -0
- package/src/ui/editor-shell-view.tsx +144 -0
- package/src/ui/editor-surface/README.md +3 -0
- package/src/ui/editor-surface-controller.tsx +66 -0
- package/src/ui/headless/comment-decoration-model.ts +124 -0
- package/src/ui/headless/preserve-editor-selection.ts +5 -0
- package/src/ui/headless/revision-decoration-model.ts +128 -0
- package/src/ui/headless/selection-helpers.ts +54 -0
- package/src/ui/headless/selection-tool-context.ts +19 -0
- package/src/ui/headless/selection-tool-resolver.ts +752 -0
- package/src/ui/headless/selection-tool-types.ts +129 -0
- package/src/ui/headless/selection-toolbar-model.ts +11 -0
- package/src/ui/headless/use-editor-keyboard.ts +103 -0
- package/src/ui/review/README.md +3 -0
- package/src/ui/runtime-shortcut-dispatch.ts +365 -0
- package/src/ui/runtime-snapshot-selectors.ts +197 -0
- package/src/ui/shared/revision-filters.ts +31 -0
- package/src/ui/status/README.md +3 -0
- package/src/ui/theme/README.md +3 -0
- package/src/ui/toolbar/README.md +3 -0
- package/src/ui/workflow-surface-blocked-rails.ts +94 -0
- package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
- package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
- package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
- package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +298 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
- package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +200 -0
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
- package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
- package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
- package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
- package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +65 -0
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
- package/src/ui-tailwind/index.ts +62 -0
- package/src/ui-tailwind/page-chrome-model.ts +27 -0
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
- package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
- package/src/ui-tailwind/review/tw-review-rail.tsx +122 -0
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
- package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
- package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1133 -0
- package/src/ui-tailwind/tw-review-workspace.tsx +1460 -0
- package/src/validation/README.md +3 -0
- package/src/validation/compatibility-engine.ts +878 -0
- package/src/validation/compatibility-report.ts +161 -0
- package/src/validation/diagnostics.ts +204 -0
- package/src/validation/docx-comment-proof.ts +720 -0
- package/src/validation/import-diagnostics.ts +128 -0
- package/src/validation/low-priority-word-surfaces.ts +373 -0
- package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
- package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
- package/dist/chunk-2FJS5GZM.js +0 -763
- package/dist/chunk-2FJS5GZM.js.map +0 -1
- package/dist/chunk-2OQBZS3F.js +0 -446
- package/dist/chunk-2OQBZS3F.js.map +0 -1
- package/dist/chunk-2S7W4KFO.js +0 -127
- package/dist/chunk-2S7W4KFO.js.map +0 -1
- package/dist/chunk-2TG72QSW.js +0 -3874
- package/dist/chunk-2TG72QSW.js.map +0 -1
- package/dist/chunk-36QNIZBO.js +0 -532
- package/dist/chunk-36QNIZBO.js.map +0 -1
- package/dist/chunk-4AQOYAW4.js +0 -3069
- package/dist/chunk-4AQOYAW4.js.map +0 -1
- package/dist/chunk-4D5EWJ3P.js +0 -77
- package/dist/chunk-4D5EWJ3P.js.map +0 -1
- package/dist/chunk-5FN54NDH.js +0 -2257
- package/dist/chunk-5FN54NDH.js.map +0 -1
- package/dist/chunk-BOYGQYRQ.js +0 -7306
- package/dist/chunk-BOYGQYRQ.js.map +0 -1
- package/dist/chunk-CN3XMECL.js +0 -212
- package/dist/chunk-CN3XMECL.js.map +0 -1
- package/dist/chunk-EBI3BX6U.js +0 -164
- package/dist/chunk-EBI3BX6U.js.map +0 -1
- package/dist/chunk-EILUG3VB.js +0 -1275
- package/dist/chunk-EILUG3VB.js.map +0 -1
- package/dist/chunk-FUDY333O.js +0 -70
- package/dist/chunk-FUDY333O.js.map +0 -1
- package/dist/chunk-GBVOWFIK.js +0 -1237
- package/dist/chunk-GBVOWFIK.js.map +0 -1
- package/dist/chunk-H4TQ3H3Y.js +0 -262
- package/dist/chunk-H4TQ3H3Y.js.map +0 -1
- package/dist/chunk-JGB3IXZO.js +0 -189
- package/dist/chunk-JGB3IXZO.js.map +0 -1
- package/dist/chunk-KD2QRQPY.js +0 -4342
- package/dist/chunk-KD2QRQPY.js.map +0 -1
- package/dist/chunk-KLMXQVYK.js +0 -369
- package/dist/chunk-KLMXQVYK.js.map +0 -1
- package/dist/chunk-KZUG5KFQ.js +0 -214
- package/dist/chunk-KZUG5KFQ.js.map +0 -1
- package/dist/chunk-QDAQ4CJU.js +0 -345
- package/dist/chunk-QDAQ4CJU.js.map +0 -1
- package/dist/chunk-RMH72RZI.js.map +0 -1
- package/dist/chunk-SWKWQZXM.js +0 -117
- package/dist/chunk-SWKWQZXM.js.map +0 -1
- package/dist/chunk-TJBP2K4T.js.map +0 -1
- package/dist/chunk-TLCEAQDQ.js +0 -542
- package/dist/chunk-TLCEAQDQ.js.map +0 -1
- package/dist/chunk-UZXBISGO.js.map +0 -1
- package/dist/chunk-WGBAKP3Q.js +0 -3220
- package/dist/chunk-WGBAKP3Q.js.map +0 -1
- package/dist/compare/index.cjs +0 -5475
- package/dist/compare/index.cjs.map +0 -1
- package/dist/compare/index.d.cts +0 -114
- package/dist/compare/index.d.ts +0 -114
- package/dist/compare/index.js +0 -731
- package/dist/compare/index.js.map +0 -1
- package/dist/core/commands/formatting-commands.cjs +0 -828
- package/dist/core/commands/formatting-commands.cjs.map +0 -1
- package/dist/core/commands/formatting-commands.d.cts +0 -63
- package/dist/core/commands/formatting-commands.d.ts +0 -63
- package/dist/core/commands/formatting-commands.js +0 -37
- package/dist/core/commands/formatting-commands.js.map +0 -1
- package/dist/core/commands/image-commands.cjs +0 -2023
- package/dist/core/commands/image-commands.cjs.map +0 -1
- package/dist/core/commands/image-commands.d.cts +0 -58
- package/dist/core/commands/image-commands.d.ts +0 -58
- package/dist/core/commands/image-commands.js +0 -18
- package/dist/core/commands/image-commands.js.map +0 -1
- package/dist/core/commands/section-layout-commands.cjs.map +0 -1
- package/dist/core/commands/section-layout-commands.d.cts +0 -62
- package/dist/core/commands/section-layout-commands.d.ts +0 -62
- package/dist/core/commands/section-layout-commands.js +0 -21
- package/dist/core/commands/section-layout-commands.js.map +0 -1
- package/dist/core/commands/style-commands.cjs.map +0 -1
- package/dist/core/commands/style-commands.d.cts +0 -13
- package/dist/core/commands/style-commands.d.ts +0 -13
- package/dist/core/commands/style-commands.js +0 -9
- package/dist/core/commands/style-commands.js.map +0 -1
- package/dist/core/commands/table-structure-commands.cjs +0 -1883
- package/dist/core/commands/table-structure-commands.cjs.map +0 -1
- package/dist/core/commands/table-structure-commands.d.cts +0 -59
- package/dist/core/commands/table-structure-commands.d.ts +0 -59
- package/dist/core/commands/table-structure-commands.js +0 -12
- package/dist/core/commands/table-structure-commands.js.map +0 -1
- package/dist/core/commands/text-commands.cjs +0 -2391
- package/dist/core/commands/text-commands.cjs.map +0 -1
- package/dist/core/commands/text-commands.d.cts +0 -24
- package/dist/core/commands/text-commands.d.ts +0 -24
- package/dist/core/commands/text-commands.js +0 -28
- package/dist/core/commands/text-commands.js.map +0 -1
- package/dist/core/selection/mapping.cjs +0 -200
- package/dist/core/selection/mapping.cjs.map +0 -1
- package/dist/core/selection/mapping.d.cts +0 -2
- package/dist/core/selection/mapping.d.ts +0 -2
- package/dist/core/selection/mapping.js +0 -31
- package/dist/core/selection/mapping.js.map +0 -1
- package/dist/core/state/editor-state.cjs +0 -2278
- package/dist/core/state/editor-state.cjs.map +0 -1
- package/dist/core/state/editor-state.d.cts +0 -2
- package/dist/core/state/editor-state.d.ts +0 -2
- package/dist/core/state/editor-state.js +0 -26
- package/dist/core/state/editor-state.js.map +0 -1
- package/dist/index.cjs +0 -38553
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -15
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -7856
- package/dist/index.js.map +0 -1
- package/dist/io/docx-session.cjs +0 -16236
- package/dist/io/docx-session.cjs.map +0 -1
- package/dist/io/docx-session.d.cts +0 -21
- package/dist/io/docx-session.d.ts +0 -21
- package/dist/io/docx-session.js +0 -18
- package/dist/io/docx-session.js.map +0 -1
- package/dist/legal/index.cjs +0 -3900
- package/dist/legal/index.cjs.map +0 -1
- package/dist/legal/index.d.cts +0 -86
- package/dist/legal/index.d.ts +0 -86
- package/dist/legal/index.js +0 -616
- package/dist/legal/index.js.map +0 -1
- package/dist/public-types-7ZL_94cz.d.ts +0 -1573
- package/dist/public-types-CeMaDueh.d.cts +0 -1573
- package/dist/public-types.cjs +0 -19
- package/dist/public-types.cjs.map +0 -1
- package/dist/public-types.d.cts +0 -2
- package/dist/public-types.d.ts +0 -2
- package/dist/public-types.js +0 -1
- package/dist/public-types.js.map +0 -1
- package/dist/runtime/document-runtime.cjs +0 -11140
- package/dist/runtime/document-runtime.cjs.map +0 -1
- package/dist/runtime/document-runtime.d.cts +0 -231
- package/dist/runtime/document-runtime.d.ts +0 -231
- package/dist/runtime/document-runtime.js +0 -21
- package/dist/runtime/document-runtime.js.map +0 -1
- package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
- package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
- package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
- package/dist/ui-tailwind/index.cjs +0 -4833
- package/dist/ui-tailwind/index.cjs.map +0 -1
- package/dist/ui-tailwind/index.d.cts +0 -617
- package/dist/ui-tailwind/index.d.ts +0 -617
- package/dist/ui-tailwind/index.js +0 -575
- package/dist/ui-tailwind/index.js.map +0 -1
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_BOUNDARY_ASSOC,
|
|
3
|
+
createDetachedAnchor,
|
|
4
|
+
createNodeAnchor,
|
|
5
|
+
createRangeAnchor,
|
|
6
|
+
type EditorAnchorProjection,
|
|
7
|
+
} from "../selection/mapping.ts";
|
|
8
|
+
import { isUuid } from "../../model/cds-1.0.0.ts";
|
|
9
|
+
import {
|
|
10
|
+
assertPersistedEditorSnapshot as assertModelPersistedEditorSnapshot,
|
|
11
|
+
createPersistedEditorSnapshot as createModelPersistedEditorSnapshot,
|
|
12
|
+
validatePersistedEditorSnapshot as validateModelPersistedEditorSnapshot,
|
|
13
|
+
type ProtectionSnapshotRecord as ModelProtectionSnapshotRecord,
|
|
14
|
+
type PersistedEditorSnapshot as ModelPersistedEditorSnapshot,
|
|
15
|
+
} from "../../model/snapshot.ts";
|
|
16
|
+
import {
|
|
17
|
+
assertCanonicalDocument,
|
|
18
|
+
type CanonicalDocument,
|
|
19
|
+
type CommentEntry as ModelCommentEntry,
|
|
20
|
+
type CommentResolution as ModelCommentResolution,
|
|
21
|
+
type CommentThread as ModelCommentThread,
|
|
22
|
+
type RevisionMetadataRecord as ModelRevisionMetadataRecord,
|
|
23
|
+
type RevisionRecord as ModelRevisionRecord,
|
|
24
|
+
} from "../../model/canonical-document.ts";
|
|
25
|
+
|
|
26
|
+
export type RuntimePhase = "loading" | "ready" | "error";
|
|
27
|
+
export type EditorWarningCode =
|
|
28
|
+
| "unsupported_ooxml_preserved"
|
|
29
|
+
| "unsupported_ooxml_locked"
|
|
30
|
+
| "import_normalized"
|
|
31
|
+
| "export_roundtrip_risk"
|
|
32
|
+
| "comment_anchor_detached"
|
|
33
|
+
| "revision_anchor_detached"
|
|
34
|
+
| "large_document_degraded"
|
|
35
|
+
| "font_substitution"
|
|
36
|
+
| "image_missing";
|
|
37
|
+
|
|
38
|
+
export interface EditorWarning {
|
|
39
|
+
warningId: string;
|
|
40
|
+
code: EditorWarningCode;
|
|
41
|
+
severity: "info" | "warning";
|
|
42
|
+
message: string;
|
|
43
|
+
source:
|
|
44
|
+
| "import"
|
|
45
|
+
| "runtime"
|
|
46
|
+
| "review"
|
|
47
|
+
| "preservation"
|
|
48
|
+
| "validation"
|
|
49
|
+
| "export";
|
|
50
|
+
affectedAnchor?: EditorAnchorProjection;
|
|
51
|
+
featureEntryId?: string;
|
|
52
|
+
details?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface EditorError {
|
|
56
|
+
errorId: string;
|
|
57
|
+
code:
|
|
58
|
+
| "import_failed"
|
|
59
|
+
| "export_failed"
|
|
60
|
+
| "package_corrupt"
|
|
61
|
+
| "validation_failed"
|
|
62
|
+
| "datastore_failed"
|
|
63
|
+
| "internal_invariant";
|
|
64
|
+
message: string;
|
|
65
|
+
isFatal: boolean;
|
|
66
|
+
source: "import" | "runtime" | "validation" | "datastore" | "host" | "export";
|
|
67
|
+
details?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type CompatibilityFeatureClass =
|
|
71
|
+
| "supported-roundtrip"
|
|
72
|
+
| "preserve-only"
|
|
73
|
+
| "unsupported-fatal";
|
|
74
|
+
|
|
75
|
+
export interface CompatibilityFeatureEntry {
|
|
76
|
+
featureEntryId: string;
|
|
77
|
+
featureKey: string;
|
|
78
|
+
featureClass: CompatibilityFeatureClass;
|
|
79
|
+
message: string;
|
|
80
|
+
affectedAnchor?: EditorAnchorProjection;
|
|
81
|
+
details?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface CompatibilityReport {
|
|
85
|
+
reportVersion: "compatibility-report/1";
|
|
86
|
+
generatedAt: string;
|
|
87
|
+
blockExport: boolean;
|
|
88
|
+
featureEntries: CompatibilityFeatureEntry[];
|
|
89
|
+
warnings: EditorWarning[];
|
|
90
|
+
errors: EditorError[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type CommentEntryRecord = ModelCommentEntry;
|
|
94
|
+
export type CommentResolutionRecord = ModelCommentResolution;
|
|
95
|
+
export type CommentThreadRecord = ModelCommentThread;
|
|
96
|
+
export type RevisionMetadataRecord = ModelRevisionMetadataRecord;
|
|
97
|
+
export type RevisionRecord = ModelRevisionRecord;
|
|
98
|
+
export type ReviewStore = CanonicalDocument["review"];
|
|
99
|
+
export type CanonicalDocumentEnvelope = CanonicalDocument;
|
|
100
|
+
|
|
101
|
+
export interface SelectionSnapshot {
|
|
102
|
+
anchor: number;
|
|
103
|
+
head: number;
|
|
104
|
+
isCollapsed: boolean;
|
|
105
|
+
activeRange: EditorAnchorProjection;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface DocumentStats {
|
|
109
|
+
paragraphCount: number;
|
|
110
|
+
wordCount: number;
|
|
111
|
+
characterCount: number;
|
|
112
|
+
commentCount: number;
|
|
113
|
+
revisionCount: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CommentSidebarSnapshot {
|
|
117
|
+
activeCommentId?: string;
|
|
118
|
+
openThreadCount: number;
|
|
119
|
+
resolvedThreadCount: number;
|
|
120
|
+
threads: CommentThreadRecord[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface TrackedChangesSnapshot {
|
|
124
|
+
totalCount: number;
|
|
125
|
+
pendingCount: number;
|
|
126
|
+
acceptedCount: number;
|
|
127
|
+
rejectedCount: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface CompatibilityPanelSnapshot {
|
|
131
|
+
report: CompatibilityReport;
|
|
132
|
+
blockExport: boolean;
|
|
133
|
+
totalEntries: number;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface CommandStateSnapshot {
|
|
137
|
+
canUndo: boolean;
|
|
138
|
+
canRedo: boolean;
|
|
139
|
+
canAddComment: boolean;
|
|
140
|
+
canAcceptAllChanges: boolean;
|
|
141
|
+
canRejectAllChanges: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface RuntimeRenderSnapshot {
|
|
145
|
+
documentId: string;
|
|
146
|
+
sessionId: string;
|
|
147
|
+
sourceLabel?: string;
|
|
148
|
+
revisionToken: string;
|
|
149
|
+
isReady: boolean;
|
|
150
|
+
isDirty: boolean;
|
|
151
|
+
readOnly: boolean;
|
|
152
|
+
selection: SelectionSnapshot;
|
|
153
|
+
documentStats: DocumentStats;
|
|
154
|
+
comments: CommentSidebarSnapshot;
|
|
155
|
+
trackedChanges: TrackedChangesSnapshot;
|
|
156
|
+
compatibility: CompatibilityPanelSnapshot;
|
|
157
|
+
warnings: EditorWarning[];
|
|
158
|
+
fatalError?: EditorError;
|
|
159
|
+
commandState: CommandStateSnapshot;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface PersistedEditorSnapshot
|
|
163
|
+
extends Omit<
|
|
164
|
+
ModelPersistedEditorSnapshot,
|
|
165
|
+
"canonicalDocument" | "compatibility" | "warningLog"
|
|
166
|
+
> {
|
|
167
|
+
canonicalDocument: CanonicalDocumentEnvelope;
|
|
168
|
+
compatibility: CompatibilityReport;
|
|
169
|
+
warningLog: EditorWarning[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface EditorRuntimeState {
|
|
173
|
+
hasFocus: boolean;
|
|
174
|
+
activeCommentId?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface EditorState {
|
|
178
|
+
phase: RuntimePhase;
|
|
179
|
+
documentId: string;
|
|
180
|
+
sessionId: string;
|
|
181
|
+
sourceLabel?: string;
|
|
182
|
+
sourcePackage?: ModelPersistedEditorSnapshot["sourcePackage"];
|
|
183
|
+
revision: number;
|
|
184
|
+
revisionToken: string;
|
|
185
|
+
isDirty: boolean;
|
|
186
|
+
readOnly: boolean;
|
|
187
|
+
document: CanonicalDocumentEnvelope;
|
|
188
|
+
selection: SelectionSnapshot;
|
|
189
|
+
warnings: EditorWarning[];
|
|
190
|
+
compatibility: CompatibilityReport;
|
|
191
|
+
fatalError?: EditorError;
|
|
192
|
+
runtime: EditorRuntimeState;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface CreateEditorStateOptions {
|
|
196
|
+
documentId: string;
|
|
197
|
+
sessionId: string;
|
|
198
|
+
sourceLabel?: string;
|
|
199
|
+
readOnly?: boolean;
|
|
200
|
+
canonicalDocument?: CanonicalDocumentEnvelope;
|
|
201
|
+
persistedSnapshot?: PersistedEditorSnapshot;
|
|
202
|
+
compatibility?: CompatibilityReport;
|
|
203
|
+
warnings?: EditorWarning[];
|
|
204
|
+
fatalError?: EditorError;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function createEmptyReviewStore(): ReviewStore {
|
|
208
|
+
return {
|
|
209
|
+
comments: {},
|
|
210
|
+
revisions: {},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function createDefaultCanonicalDocument(
|
|
215
|
+
documentId: string,
|
|
216
|
+
timestamp: string,
|
|
217
|
+
): CanonicalDocumentEnvelope {
|
|
218
|
+
return {
|
|
219
|
+
schemaVersion: "cds/1.0.0",
|
|
220
|
+
docId: createCanonicalDocumentId(documentId),
|
|
221
|
+
createdAt: timestamp,
|
|
222
|
+
updatedAt: timestamp,
|
|
223
|
+
metadata: {
|
|
224
|
+
customProperties: {},
|
|
225
|
+
},
|
|
226
|
+
styles: {
|
|
227
|
+
paragraphs: {},
|
|
228
|
+
characters: {},
|
|
229
|
+
tables: {},
|
|
230
|
+
},
|
|
231
|
+
numbering: {
|
|
232
|
+
abstractDefinitions: {},
|
|
233
|
+
instances: {},
|
|
234
|
+
},
|
|
235
|
+
media: {
|
|
236
|
+
items: {},
|
|
237
|
+
},
|
|
238
|
+
content: {
|
|
239
|
+
type: "doc",
|
|
240
|
+
children: [{ type: "paragraph", children: [] }],
|
|
241
|
+
},
|
|
242
|
+
review: createEmptyReviewStore(),
|
|
243
|
+
preservation: {
|
|
244
|
+
opaqueFragments: {},
|
|
245
|
+
packageParts: {},
|
|
246
|
+
},
|
|
247
|
+
diagnostics: {
|
|
248
|
+
warnings: [],
|
|
249
|
+
errors: [],
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function createSelectionSnapshot(anchor = 0, head = anchor): SelectionSnapshot {
|
|
255
|
+
return {
|
|
256
|
+
anchor,
|
|
257
|
+
head,
|
|
258
|
+
isCollapsed: anchor === head,
|
|
259
|
+
activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function createEmptyCompatibilityReport(generatedAt: string): CompatibilityReport {
|
|
264
|
+
return {
|
|
265
|
+
reportVersion: "compatibility-report/1",
|
|
266
|
+
generatedAt,
|
|
267
|
+
blockExport: false,
|
|
268
|
+
featureEntries: [],
|
|
269
|
+
warnings: [],
|
|
270
|
+
errors: [],
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function createEditorState(options: CreateEditorStateOptions): EditorState {
|
|
275
|
+
const timestamp = new Date(0).toISOString();
|
|
276
|
+
const normalizedSnapshot = options.persistedSnapshot
|
|
277
|
+
? normalizePersistedSnapshotForRuntime(options.persistedSnapshot, options.documentId, timestamp)
|
|
278
|
+
: undefined;
|
|
279
|
+
if (options.canonicalDocument) {
|
|
280
|
+
assertCanonicalDocument(options.canonicalDocument as unknown);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const normalizedDocument = normalizedSnapshot
|
|
284
|
+
? structuredClone(normalizedSnapshot.canonicalDocument)
|
|
285
|
+
: options.canonicalDocument
|
|
286
|
+
? structuredClone(options.canonicalDocument)
|
|
287
|
+
: createDefaultCanonicalDocument(options.documentId, timestamp);
|
|
288
|
+
const warnings = normalizedSnapshot
|
|
289
|
+
? normalizeWarningLog(normalizedSnapshot.warningLog)
|
|
290
|
+
: options.warnings ?? [];
|
|
291
|
+
const compatibility =
|
|
292
|
+
normalizedSnapshot
|
|
293
|
+
? normalizeCompatibilityReport(normalizedSnapshot.compatibility)
|
|
294
|
+
: options.compatibility ?? createEmptyCompatibilityReport(normalizedDocument.updatedAt);
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
phase: options.fatalError ? "error" : "ready",
|
|
298
|
+
documentId: options.documentId,
|
|
299
|
+
sessionId: options.sessionId,
|
|
300
|
+
sourceLabel: options.sourceLabel,
|
|
301
|
+
sourcePackage: normalizedSnapshot?.sourcePackage,
|
|
302
|
+
revision: 0,
|
|
303
|
+
revisionToken: `${options.sessionId}:0`,
|
|
304
|
+
isDirty: false,
|
|
305
|
+
readOnly: options.readOnly ?? false,
|
|
306
|
+
document: normalizedDocument,
|
|
307
|
+
selection: createSelectionSnapshot(),
|
|
308
|
+
warnings,
|
|
309
|
+
compatibility,
|
|
310
|
+
fatalError: options.fatalError,
|
|
311
|
+
runtime: {
|
|
312
|
+
hasFocus: false,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function normalizePersistedSnapshotForRuntime(
|
|
318
|
+
snapshot: PersistedEditorSnapshot,
|
|
319
|
+
documentId: string,
|
|
320
|
+
timestamp: string,
|
|
321
|
+
): PersistedEditorSnapshot {
|
|
322
|
+
const issues = validateModelPersistedEditorSnapshot(snapshot as unknown);
|
|
323
|
+
if (issues.length === 0) {
|
|
324
|
+
return snapshot;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!isRecord(snapshot) || !isRecord(snapshot.canonicalDocument)) {
|
|
328
|
+
assertModelPersistedEditorSnapshot(snapshot as unknown);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const normalizedDocument = normalizeCanonicalDocumentEnvelope(
|
|
332
|
+
snapshot.canonicalDocument,
|
|
333
|
+
documentId,
|
|
334
|
+
timestamp,
|
|
335
|
+
);
|
|
336
|
+
try {
|
|
337
|
+
assertCanonicalDocument(normalizedDocument as unknown);
|
|
338
|
+
} catch {
|
|
339
|
+
assertModelPersistedEditorSnapshot(snapshot as unknown);
|
|
340
|
+
}
|
|
341
|
+
const repairWarning = createSnapshotRepairWarning(issues.length);
|
|
342
|
+
const compatibility = coerceCompatibilityReport(
|
|
343
|
+
snapshot.compatibility,
|
|
344
|
+
normalizedDocument.updatedAt,
|
|
345
|
+
repairWarning,
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
snapshotVersion:
|
|
350
|
+
snapshot.snapshotVersion === "persisted-editor-snapshot/1" ||
|
|
351
|
+
snapshot.snapshotVersion === "persisted-editor-snapshot/2"
|
|
352
|
+
? snapshot.snapshotVersion
|
|
353
|
+
: "persisted-editor-snapshot/2",
|
|
354
|
+
schemaVersion: "cds/1.0.0",
|
|
355
|
+
documentId:
|
|
356
|
+
typeof snapshot.documentId === "string" && snapshot.documentId.length > 0
|
|
357
|
+
? snapshot.documentId
|
|
358
|
+
: documentId,
|
|
359
|
+
docId: normalizedDocument.docId,
|
|
360
|
+
createdAt: normalizedDocument.createdAt,
|
|
361
|
+
updatedAt: normalizedDocument.updatedAt,
|
|
362
|
+
savedAt:
|
|
363
|
+
typeof snapshot.savedAt === "string" && snapshot.savedAt.length > 0
|
|
364
|
+
? snapshot.savedAt
|
|
365
|
+
: normalizedDocument.updatedAt,
|
|
366
|
+
editorBuild:
|
|
367
|
+
typeof snapshot.editorBuild === "string" && snapshot.editorBuild.length > 0
|
|
368
|
+
? snapshot.editorBuild
|
|
369
|
+
: "dev",
|
|
370
|
+
canonicalDocument: normalizedDocument,
|
|
371
|
+
compatibility,
|
|
372
|
+
warningLog: dedupeWarnings([
|
|
373
|
+
...coerceWarnings(snapshot.warningLog),
|
|
374
|
+
repairWarning,
|
|
375
|
+
]),
|
|
376
|
+
sourcePackage: snapshot.sourcePackage,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function normalizeCanonicalDocumentEnvelope(
|
|
381
|
+
value: unknown,
|
|
382
|
+
documentId: string,
|
|
383
|
+
timestamp: string,
|
|
384
|
+
): CanonicalDocumentEnvelope {
|
|
385
|
+
const base = createDefaultCanonicalDocument(documentId, timestamp);
|
|
386
|
+
const record = isRecord(value) ? value : {};
|
|
387
|
+
const metadata = isRecord(record.metadata) ? record.metadata : {};
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
...base,
|
|
391
|
+
...record,
|
|
392
|
+
schemaVersion: "cds/1.0.0",
|
|
393
|
+
docId: isUuid(record.docId) ? record.docId : createCanonicalDocumentId(documentId),
|
|
394
|
+
createdAt:
|
|
395
|
+
typeof record.createdAt === "string" && record.createdAt.length > 0
|
|
396
|
+
? record.createdAt
|
|
397
|
+
: base.createdAt,
|
|
398
|
+
updatedAt:
|
|
399
|
+
typeof record.updatedAt === "string" && record.updatedAt.length > 0
|
|
400
|
+
? record.updatedAt
|
|
401
|
+
: base.updatedAt,
|
|
402
|
+
metadata: {
|
|
403
|
+
...base.metadata,
|
|
404
|
+
...metadata,
|
|
405
|
+
customProperties: isRecord(metadata.customProperties)
|
|
406
|
+
? (Object.fromEntries(
|
|
407
|
+
Object.entries(metadata.customProperties).filter(([, entry]) => typeof entry === "string"),
|
|
408
|
+
) as Record<string, string>)
|
|
409
|
+
: {},
|
|
410
|
+
},
|
|
411
|
+
styles:
|
|
412
|
+
record.styles === undefined
|
|
413
|
+
? base.styles
|
|
414
|
+
: (record.styles as CanonicalDocumentEnvelope["styles"]),
|
|
415
|
+
numbering:
|
|
416
|
+
record.numbering === undefined
|
|
417
|
+
? base.numbering
|
|
418
|
+
: (record.numbering as CanonicalDocumentEnvelope["numbering"]),
|
|
419
|
+
media:
|
|
420
|
+
record.media === undefined
|
|
421
|
+
? base.media
|
|
422
|
+
: (record.media as CanonicalDocumentEnvelope["media"]),
|
|
423
|
+
content: isRecord(record.content)
|
|
424
|
+
? (record.content as unknown as CanonicalDocumentEnvelope["content"])
|
|
425
|
+
: base.content,
|
|
426
|
+
review:
|
|
427
|
+
record.review === undefined
|
|
428
|
+
? base.review
|
|
429
|
+
: (record.review as CanonicalDocumentEnvelope["review"]),
|
|
430
|
+
preservation:
|
|
431
|
+
record.preservation === undefined
|
|
432
|
+
? base.preservation
|
|
433
|
+
: (record.preservation as CanonicalDocumentEnvelope["preservation"]),
|
|
434
|
+
diagnostics:
|
|
435
|
+
record.diagnostics === undefined
|
|
436
|
+
? base.diagnostics
|
|
437
|
+
: (record.diagnostics as CanonicalDocumentEnvelope["diagnostics"]),
|
|
438
|
+
...(isRecord(record.subParts)
|
|
439
|
+
? { subParts: record.subParts as unknown as CanonicalDocumentEnvelope["subParts"] }
|
|
440
|
+
: {}),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function coerceCompatibilityReport(
|
|
445
|
+
value: unknown,
|
|
446
|
+
generatedAt: string,
|
|
447
|
+
repairWarning: EditorWarning,
|
|
448
|
+
): CompatibilityReport {
|
|
449
|
+
const record = isRecord(value) ? value : {};
|
|
450
|
+
const warnings = dedupeWarnings([
|
|
451
|
+
...coerceWarnings(record.warnings),
|
|
452
|
+
repairWarning,
|
|
453
|
+
]);
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
reportVersion: "compatibility-report/1",
|
|
457
|
+
generatedAt:
|
|
458
|
+
typeof record.generatedAt === "string" && record.generatedAt.length > 0
|
|
459
|
+
? record.generatedAt
|
|
460
|
+
: generatedAt,
|
|
461
|
+
blockExport: typeof record.blockExport === "boolean" ? record.blockExport : false,
|
|
462
|
+
featureEntries: Array.isArray(record.featureEntries)
|
|
463
|
+
? record.featureEntries.flatMap((entry) => {
|
|
464
|
+
if (!isRecord(entry)) {
|
|
465
|
+
return [];
|
|
466
|
+
}
|
|
467
|
+
if (
|
|
468
|
+
typeof entry.featureEntryId !== "string" ||
|
|
469
|
+
typeof entry.featureKey !== "string" ||
|
|
470
|
+
typeof entry.featureClass !== "string" ||
|
|
471
|
+
typeof entry.message !== "string"
|
|
472
|
+
) {
|
|
473
|
+
return [];
|
|
474
|
+
}
|
|
475
|
+
return [{
|
|
476
|
+
featureEntryId: entry.featureEntryId,
|
|
477
|
+
featureKey: entry.featureKey,
|
|
478
|
+
featureClass: entry.featureClass as CompatibilityFeatureEntry["featureClass"],
|
|
479
|
+
message: entry.message,
|
|
480
|
+
...(entry.affectedAnchor && isRecord(entry.affectedAnchor)
|
|
481
|
+
? { affectedAnchor: entry.affectedAnchor as unknown as EditorAnchorProjection }
|
|
482
|
+
: {}),
|
|
483
|
+
...(isRecord(entry.details) ? { details: entry.details } : {}),
|
|
484
|
+
}];
|
|
485
|
+
})
|
|
486
|
+
: [],
|
|
487
|
+
warnings,
|
|
488
|
+
errors: Array.isArray(record.errors)
|
|
489
|
+
? record.errors.flatMap((entry) => {
|
|
490
|
+
if (!isRecord(entry)) {
|
|
491
|
+
return [];
|
|
492
|
+
}
|
|
493
|
+
if (
|
|
494
|
+
typeof entry.errorId !== "string" ||
|
|
495
|
+
typeof entry.code !== "string" ||
|
|
496
|
+
typeof entry.message !== "string" ||
|
|
497
|
+
typeof entry.source !== "string" ||
|
|
498
|
+
typeof entry.isFatal !== "boolean"
|
|
499
|
+
) {
|
|
500
|
+
return [];
|
|
501
|
+
}
|
|
502
|
+
return [{
|
|
503
|
+
errorId: entry.errorId,
|
|
504
|
+
code: entry.code as EditorError["code"],
|
|
505
|
+
message: entry.message,
|
|
506
|
+
source: entry.source as EditorError["source"],
|
|
507
|
+
isFatal: entry.isFatal,
|
|
508
|
+
...(isRecord(entry.details) ? { details: entry.details } : {}),
|
|
509
|
+
}];
|
|
510
|
+
})
|
|
511
|
+
: [],
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function coerceWarnings(value: unknown): EditorWarning[] {
|
|
516
|
+
if (!Array.isArray(value)) {
|
|
517
|
+
return [];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return value.flatMap((warning) => {
|
|
521
|
+
if (!isRecord(warning)) {
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
if (
|
|
525
|
+
typeof warning.warningId !== "string" ||
|
|
526
|
+
typeof warning.code !== "string" ||
|
|
527
|
+
typeof warning.severity !== "string" ||
|
|
528
|
+
typeof warning.message !== "string" ||
|
|
529
|
+
typeof warning.source !== "string"
|
|
530
|
+
) {
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return [{
|
|
535
|
+
warningId: warning.warningId,
|
|
536
|
+
code: warning.code as EditorWarning["code"],
|
|
537
|
+
severity: warning.severity as EditorWarning["severity"],
|
|
538
|
+
message: warning.message,
|
|
539
|
+
source: warning.source as EditorWarning["source"],
|
|
540
|
+
...(warning.affectedAnchor && isRecord(warning.affectedAnchor)
|
|
541
|
+
? { affectedAnchor: warning.affectedAnchor as unknown as EditorAnchorProjection }
|
|
542
|
+
: {}),
|
|
543
|
+
...(typeof warning.featureEntryId === "string"
|
|
544
|
+
? { featureEntryId: warning.featureEntryId }
|
|
545
|
+
: {}),
|
|
546
|
+
...(isRecord(warning.details) ? { details: warning.details } : {}),
|
|
547
|
+
}];
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function createSnapshotRepairWarning(issueCount: number): EditorWarning {
|
|
552
|
+
return {
|
|
553
|
+
warningId: `warning:snapshot-repair:${issueCount}`,
|
|
554
|
+
code: "import_normalized",
|
|
555
|
+
severity: "warning",
|
|
556
|
+
message: `Loaded a persisted snapshot after repairing ${issueCount} validation issue${issueCount === 1 ? "" : "s"}.`,
|
|
557
|
+
source: "validation",
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function dedupeWarnings(warnings: EditorWarning[]): EditorWarning[] {
|
|
562
|
+
const seen = new Set<string>();
|
|
563
|
+
const result: EditorWarning[] = [];
|
|
564
|
+
|
|
565
|
+
for (const warning of warnings) {
|
|
566
|
+
if (!warning.warningId || seen.has(warning.warningId)) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
seen.add(warning.warningId);
|
|
570
|
+
result.push(warning);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export function deriveDocumentStats(state: Pick<EditorState, "document">): DocumentStats {
|
|
577
|
+
const serializedContent = extractText(state.document.content);
|
|
578
|
+
|
|
579
|
+
return {
|
|
580
|
+
paragraphCount: estimateParagraphCount(state.document.content),
|
|
581
|
+
wordCount: serializedContent.trim().length === 0 ? 0 : serializedContent.trim().split(/\s+/u).length,
|
|
582
|
+
characterCount: Array.from(serializedContent).length,
|
|
583
|
+
commentCount: Object.keys(state.document.review.comments).length,
|
|
584
|
+
revisionCount: Object.keys(state.document.review.revisions).length,
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export function deriveRenderSnapshot(
|
|
589
|
+
state: EditorState,
|
|
590
|
+
history: { canUndo: boolean; canRedo: boolean },
|
|
591
|
+
): RuntimeRenderSnapshot {
|
|
592
|
+
const comments = Object.values(state.document.review.comments).sort((left, right) =>
|
|
593
|
+
left.createdAt.localeCompare(right.createdAt),
|
|
594
|
+
);
|
|
595
|
+
const revisions = Object.values(state.document.review.revisions);
|
|
596
|
+
|
|
597
|
+
return {
|
|
598
|
+
documentId: state.documentId,
|
|
599
|
+
sessionId: state.sessionId,
|
|
600
|
+
sourceLabel: state.sourceLabel,
|
|
601
|
+
revisionToken: state.revisionToken,
|
|
602
|
+
isReady: state.phase === "ready",
|
|
603
|
+
isDirty: state.isDirty,
|
|
604
|
+
readOnly: state.readOnly,
|
|
605
|
+
selection: state.selection,
|
|
606
|
+
documentStats: deriveDocumentStats(state),
|
|
607
|
+
comments: {
|
|
608
|
+
activeCommentId: state.runtime.activeCommentId,
|
|
609
|
+
openThreadCount: comments.filter((comment) => comment.status === "open").length,
|
|
610
|
+
resolvedThreadCount: comments.filter((comment) => comment.status === "resolved").length,
|
|
611
|
+
threads: comments,
|
|
612
|
+
},
|
|
613
|
+
trackedChanges: {
|
|
614
|
+
totalCount: revisions.length,
|
|
615
|
+
pendingCount: revisions.filter((revision) => revision.status === "open").length,
|
|
616
|
+
acceptedCount: revisions.filter((revision) => revision.status === "accepted").length,
|
|
617
|
+
rejectedCount: revisions.filter((revision) => revision.status === "rejected").length,
|
|
618
|
+
},
|
|
619
|
+
compatibility: {
|
|
620
|
+
report: state.compatibility,
|
|
621
|
+
blockExport: state.compatibility.blockExport,
|
|
622
|
+
totalEntries: state.compatibility.featureEntries.length,
|
|
623
|
+
},
|
|
624
|
+
warnings: state.warnings,
|
|
625
|
+
fatalError: state.fatalError,
|
|
626
|
+
commandState: {
|
|
627
|
+
canUndo: history.canUndo,
|
|
628
|
+
canRedo: history.canRedo,
|
|
629
|
+
canAddComment: !state.readOnly,
|
|
630
|
+
canAcceptAllChanges: revisions.some((revision) => revision.status === "open"),
|
|
631
|
+
canRejectAllChanges: revisions.some((revision) => revision.status === "open"),
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export function createPersistedEditorSnapshot(
|
|
637
|
+
state: EditorState,
|
|
638
|
+
options: {
|
|
639
|
+
editorBuild: string;
|
|
640
|
+
savedAt: string;
|
|
641
|
+
compatibility?: CompatibilityReport;
|
|
642
|
+
protectionSnapshot?: ModelProtectionSnapshotRecord;
|
|
643
|
+
},
|
|
644
|
+
): PersistedEditorSnapshot {
|
|
645
|
+
const snapshot = createModelPersistedEditorSnapshot({
|
|
646
|
+
documentId: state.documentId,
|
|
647
|
+
savedAt: options.savedAt,
|
|
648
|
+
editorBuild: options.editorBuild,
|
|
649
|
+
canonicalDocument: state.document,
|
|
650
|
+
compatibility: (options.compatibility ?? state.compatibility) as never,
|
|
651
|
+
warningLog: state.warnings as never,
|
|
652
|
+
protectionSnapshot: options.protectionSnapshot,
|
|
653
|
+
sourcePackage: state.sourcePackage,
|
|
654
|
+
});
|
|
655
|
+
return snapshot as PersistedEditorSnapshot;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function estimateParagraphCount(content: unknown): number {
|
|
659
|
+
if (Array.isArray(content)) {
|
|
660
|
+
return content.length;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (content && typeof content === "object" && Array.isArray((content as { blocks?: unknown[] }).blocks)) {
|
|
664
|
+
return ((content as { blocks: unknown[] }).blocks).length;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
return extractText(content).length > 0 ? 1 : 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function normalizeWarningLog(warnings: EditorWarning[]): EditorWarning[] {
|
|
671
|
+
return warnings.map((warning) => ({
|
|
672
|
+
...warning,
|
|
673
|
+
affectedAnchor: warning.affectedAnchor
|
|
674
|
+
? normalizeAnchorProjection(warning.affectedAnchor)
|
|
675
|
+
: undefined,
|
|
676
|
+
}));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function normalizeCompatibilityReport(report: CompatibilityReport): CompatibilityReport {
|
|
680
|
+
return {
|
|
681
|
+
...report,
|
|
682
|
+
featureEntries: report.featureEntries.map((entry) => ({
|
|
683
|
+
...entry,
|
|
684
|
+
affectedAnchor: entry.affectedAnchor
|
|
685
|
+
? normalizeAnchorProjection(entry.affectedAnchor)
|
|
686
|
+
: undefined,
|
|
687
|
+
})),
|
|
688
|
+
warnings: normalizeWarningLog(report.warnings),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function normalizeAnchorProjection(anchor: EditorAnchorProjection): EditorAnchorProjection {
|
|
693
|
+
switch (anchor.kind) {
|
|
694
|
+
case "range": {
|
|
695
|
+
const rangeAnchor = anchor as EditorAnchorProjection & {
|
|
696
|
+
range?: { from: number; to: number };
|
|
697
|
+
from?: number;
|
|
698
|
+
to?: number;
|
|
699
|
+
assoc: { start: -1 | 1; end: -1 | 1 };
|
|
700
|
+
};
|
|
701
|
+
return rangeAnchor.range
|
|
702
|
+
? createRangeAnchor(rangeAnchor.range.from, rangeAnchor.range.to, rangeAnchor.assoc)
|
|
703
|
+
: createRangeAnchor(rangeAnchor.from ?? 0, rangeAnchor.to ?? 0, rangeAnchor.assoc);
|
|
704
|
+
}
|
|
705
|
+
case "node":
|
|
706
|
+
return createNodeAnchor(anchor.at, anchor.assoc);
|
|
707
|
+
case "detached":
|
|
708
|
+
return createDetachedAnchor(anchor.lastKnownRange, anchor.reason);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function extractText(value: unknown): string {
|
|
713
|
+
if (typeof value === "string") {
|
|
714
|
+
return value;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (Array.isArray(value)) {
|
|
718
|
+
return value.map((item) => extractText(item)).join(" ");
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (!value || typeof value !== "object") {
|
|
722
|
+
return "";
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
return Object.values(value as Record<string, unknown>)
|
|
726
|
+
.map((item) => extractText(item))
|
|
727
|
+
.filter(Boolean)
|
|
728
|
+
.join(" ");
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
732
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export function createCanonicalDocumentId(documentId: string): string {
|
|
736
|
+
const hashWord = (seed: string): string => {
|
|
737
|
+
let hash = 0x811c9dc5;
|
|
738
|
+
for (const char of seed) {
|
|
739
|
+
hash ^= char.charCodeAt(0);
|
|
740
|
+
hash = Math.imul(hash, 0x01000193);
|
|
741
|
+
}
|
|
742
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const raw =
|
|
746
|
+
hashWord(`${documentId}:0`) +
|
|
747
|
+
hashWord(`${documentId}:1`) +
|
|
748
|
+
hashWord(`${documentId}:2`) +
|
|
749
|
+
hashWord(`${documentId}:3`);
|
|
750
|
+
|
|
751
|
+
return [
|
|
752
|
+
raw.slice(0, 8),
|
|
753
|
+
raw.slice(8, 12),
|
|
754
|
+
`4${raw.slice(13, 16)}`,
|
|
755
|
+
`8${raw.slice(17, 20)}`,
|
|
756
|
+
raw.slice(20, 32),
|
|
757
|
+
].join("-");
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export function normalizeCommentThreadRecord(value: unknown): CommentThreadRecord {
|
|
761
|
+
const record = isRecord(value) ? value : {};
|
|
762
|
+
const authorId =
|
|
763
|
+
typeof record.createdBy === "string" && record.createdBy.length > 0
|
|
764
|
+
? record.createdBy
|
|
765
|
+
: typeof record.authorId === "string" && record.authorId.length > 0
|
|
766
|
+
? record.authorId
|
|
767
|
+
: "unknown";
|
|
768
|
+
const createdAt =
|
|
769
|
+
typeof record.createdAt === "string" && record.createdAt.length > 0
|
|
770
|
+
? record.createdAt
|
|
771
|
+
: new Date(0).toISOString();
|
|
772
|
+
const entries = Array.isArray(record.entries)
|
|
773
|
+
? record.entries
|
|
774
|
+
.filter((entry): entry is Record<string, unknown> => isRecord(entry))
|
|
775
|
+
.map((entry, index) => ({
|
|
776
|
+
entryId:
|
|
777
|
+
typeof entry.entryId === "string" && entry.entryId.length > 0
|
|
778
|
+
? entry.entryId
|
|
779
|
+
: `${String(record.commentId ?? "comment")}-entry-${index + 1}`,
|
|
780
|
+
authorId:
|
|
781
|
+
typeof entry.authorId === "string" && entry.authorId.length > 0
|
|
782
|
+
? entry.authorId
|
|
783
|
+
: authorId,
|
|
784
|
+
body: typeof entry.body === "string" ? entry.body : "",
|
|
785
|
+
createdAt:
|
|
786
|
+
typeof entry.createdAt === "string" && entry.createdAt.length > 0
|
|
787
|
+
? entry.createdAt
|
|
788
|
+
: createdAt,
|
|
789
|
+
metadata: isRecord(entry.metadata)
|
|
790
|
+
? {
|
|
791
|
+
ooxmlCommentId:
|
|
792
|
+
typeof entry.metadata.ooxmlCommentId === "string"
|
|
793
|
+
? entry.metadata.ooxmlCommentId
|
|
794
|
+
: undefined,
|
|
795
|
+
paraId:
|
|
796
|
+
typeof entry.metadata.paraId === "string"
|
|
797
|
+
? entry.metadata.paraId
|
|
798
|
+
: undefined,
|
|
799
|
+
parentParaId:
|
|
800
|
+
typeof entry.metadata.parentParaId === "string"
|
|
801
|
+
? entry.metadata.parentParaId
|
|
802
|
+
: undefined,
|
|
803
|
+
durableId:
|
|
804
|
+
typeof entry.metadata.durableId === "string"
|
|
805
|
+
? entry.metadata.durableId
|
|
806
|
+
: undefined,
|
|
807
|
+
initials:
|
|
808
|
+
typeof entry.metadata.initials === "string"
|
|
809
|
+
? entry.metadata.initials
|
|
810
|
+
: undefined,
|
|
811
|
+
}
|
|
812
|
+
: undefined,
|
|
813
|
+
}))
|
|
814
|
+
: [
|
|
815
|
+
{
|
|
816
|
+
entryId: `${String(record.commentId ?? "comment")}-entry-1`,
|
|
817
|
+
authorId,
|
|
818
|
+
body: typeof record.body === "string" ? record.body : "",
|
|
819
|
+
createdAt,
|
|
820
|
+
},
|
|
821
|
+
];
|
|
822
|
+
const resolution = isRecord(record.resolution)
|
|
823
|
+
? {
|
|
824
|
+
resolvedAt:
|
|
825
|
+
typeof record.resolution.resolvedAt === "string"
|
|
826
|
+
? record.resolution.resolvedAt
|
|
827
|
+
: typeof record.resolvedAt === "string"
|
|
828
|
+
? record.resolvedAt
|
|
829
|
+
: createdAt,
|
|
830
|
+
resolvedBy:
|
|
831
|
+
typeof record.resolution.resolvedBy === "string" &&
|
|
832
|
+
record.resolution.resolvedBy.length > 0
|
|
833
|
+
? record.resolution.resolvedBy
|
|
834
|
+
: authorId,
|
|
835
|
+
}
|
|
836
|
+
: typeof record.resolvedAt === "string"
|
|
837
|
+
? {
|
|
838
|
+
resolvedAt: record.resolvedAt,
|
|
839
|
+
resolvedBy: authorId,
|
|
840
|
+
}
|
|
841
|
+
: undefined;
|
|
842
|
+
const normalizedStatus =
|
|
843
|
+
typeof record.status === "string"
|
|
844
|
+
? record.status
|
|
845
|
+
: record.anchor && isRecord(record.anchor) && record.anchor.kind === "detached"
|
|
846
|
+
? "detached"
|
|
847
|
+
: resolution || record.isResolved
|
|
848
|
+
? "resolved"
|
|
849
|
+
: "open";
|
|
850
|
+
|
|
851
|
+
return {
|
|
852
|
+
commentId:
|
|
853
|
+
typeof record.commentId === "string" && record.commentId.length > 0
|
|
854
|
+
? record.commentId
|
|
855
|
+
: "comment-generated",
|
|
856
|
+
anchor:
|
|
857
|
+
isRecord(record.anchor) && typeof record.anchor.kind === "string"
|
|
858
|
+
? (record.anchor as unknown as EditorAnchorProjection)
|
|
859
|
+
: createDetachedAnchor({ from: 0, to: 0 }, "importAmbiguity"),
|
|
860
|
+
createdAt,
|
|
861
|
+
createdBy: authorId,
|
|
862
|
+
authorId,
|
|
863
|
+
body: entries.map((entry) => entry.body).join("\n"),
|
|
864
|
+
entries,
|
|
865
|
+
status:
|
|
866
|
+
normalizedStatus === "resolved" || normalizedStatus === "detached"
|
|
867
|
+
? normalizedStatus
|
|
868
|
+
: "open",
|
|
869
|
+
resolution,
|
|
870
|
+
resolvedAt: resolution?.resolvedAt,
|
|
871
|
+
warningIds: Array.isArray(record.warningIds)
|
|
872
|
+
? record.warningIds.filter((warningId): warningId is string => typeof warningId === "string")
|
|
873
|
+
: [],
|
|
874
|
+
isResolved: normalizedStatus === "resolved",
|
|
875
|
+
metadata: isRecord(record.metadata)
|
|
876
|
+
? {
|
|
877
|
+
source:
|
|
878
|
+
record.metadata.source === "import" || record.metadata.source === "runtime"
|
|
879
|
+
? record.metadata.source
|
|
880
|
+
: undefined,
|
|
881
|
+
rootOoxmlCommentId:
|
|
882
|
+
typeof record.metadata.rootOoxmlCommentId === "string"
|
|
883
|
+
? record.metadata.rootOoxmlCommentId
|
|
884
|
+
: undefined,
|
|
885
|
+
rootParaId:
|
|
886
|
+
typeof record.metadata.rootParaId === "string"
|
|
887
|
+
? record.metadata.rootParaId
|
|
888
|
+
: undefined,
|
|
889
|
+
}
|
|
890
|
+
: undefined,
|
|
891
|
+
};
|
|
892
|
+
}
|