@beyondwork/docx-react-component 1.0.29 → 1.0.31
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/responsive-chrome.ts +46 -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 +303 -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 +250 -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 +63 -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 +130 -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/toolbar-layout.ts +47 -0
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1478 -0
- package/src/ui-tailwind/tw-review-workspace.tsx +1587 -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,567 @@
|
|
|
1
|
+
import { Fragment, type Node as PMNode } from "prosemirror-model";
|
|
2
|
+
import { EditorState, NodeSelection, type Plugin, Selection, TextSelection } from "prosemirror-state";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
EditorSurfaceSnapshot,
|
|
6
|
+
SelectionSnapshot,
|
|
7
|
+
SurfaceBlockSnapshot,
|
|
8
|
+
SurfaceInlineSegment,
|
|
9
|
+
SurfaceTableRowSnapshot,
|
|
10
|
+
SurfaceTableCellSnapshot,
|
|
11
|
+
} from "../../api/public-types";
|
|
12
|
+
import { editorSchema } from "./pm-schema";
|
|
13
|
+
import { buildPositionMap, type PositionMap } from "./pm-position-map";
|
|
14
|
+
|
|
15
|
+
export interface PMStateResult {
|
|
16
|
+
state: EditorState;
|
|
17
|
+
positionMap: PositionMap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MediaPreviewDescriptor {
|
|
21
|
+
src: string;
|
|
22
|
+
widthEmu?: number;
|
|
23
|
+
heightEmu?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create a ProseMirror EditorState from a runtime surface snapshot.
|
|
28
|
+
*
|
|
29
|
+
* The PM document mirrors the snapshot for rendering and input.
|
|
30
|
+
* It is NOT the canonical source — the runtime owns that.
|
|
31
|
+
*/
|
|
32
|
+
export function createPMStateFromSnapshot(
|
|
33
|
+
surface: EditorSurfaceSnapshot,
|
|
34
|
+
selection: SelectionSnapshot,
|
|
35
|
+
plugins: Plugin[],
|
|
36
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor> = {},
|
|
37
|
+
showUnsupportedObjectPreviews = false,
|
|
38
|
+
): PMStateResult {
|
|
39
|
+
const doc = buildPMDoc(surface, mediaPreviews, showUnsupportedObjectPreviews);
|
|
40
|
+
const positionMap = buildPositionMap(surface);
|
|
41
|
+
const pmSelection = createPMSelectionFromSnapshot(doc, positionMap, selection);
|
|
42
|
+
|
|
43
|
+
const state = EditorState.create({
|
|
44
|
+
doc,
|
|
45
|
+
selection: pmSelection,
|
|
46
|
+
plugins,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return { state, positionMap };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createPMSelectionFromSnapshot(
|
|
53
|
+
doc: PMNode,
|
|
54
|
+
positionMap: PositionMap,
|
|
55
|
+
selection: SelectionSnapshot,
|
|
56
|
+
): Selection {
|
|
57
|
+
const pmAnchor = clamp(positionMap.runtimeToPm(selection.anchor), 1, positionMap.pmDocSize - 1);
|
|
58
|
+
const pmHead = clamp(positionMap.runtimeToPm(selection.head), 1, positionMap.pmDocSize - 1);
|
|
59
|
+
try {
|
|
60
|
+
if (selection.activeRange.kind === "node") {
|
|
61
|
+
const pmNodePos = clamp(pmAnchor - 1, 0, positionMap.pmDocSize - 2);
|
|
62
|
+
return NodeSelection.create(doc, pmNodePos);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const forward = selection.head >= selection.anchor;
|
|
66
|
+
const resolvedAnchor = resolveInlineBoundary(doc, pmAnchor, forward ? 1 : -1);
|
|
67
|
+
const resolvedHead = resolveInlineBoundary(doc, pmHead, forward ? -1 : 1);
|
|
68
|
+
if (resolvedAnchor !== null && resolvedHead !== null) {
|
|
69
|
+
return TextSelection.create(doc, resolvedAnchor, resolvedHead);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const $anchor = doc.resolve(pmAnchor);
|
|
73
|
+
const $head = doc.resolve(pmHead);
|
|
74
|
+
return (
|
|
75
|
+
Selection.findFrom($anchor, 1, true) ??
|
|
76
|
+
Selection.findFrom($anchor, -1, true) ??
|
|
77
|
+
Selection.findFrom($head, 1, true) ??
|
|
78
|
+
Selection.findFrom($head, -1, true) ??
|
|
79
|
+
Selection.near($anchor, 1)
|
|
80
|
+
);
|
|
81
|
+
} catch {
|
|
82
|
+
// If the mapped runtime selection is invalid or lands in a non-text block,
|
|
83
|
+
// let ProseMirror choose the nearest valid starting selection.
|
|
84
|
+
return Selection.atStart(doc);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function resolveInlineBoundary(
|
|
89
|
+
doc: PMNode,
|
|
90
|
+
pos: number,
|
|
91
|
+
bias: -1 | 1,
|
|
92
|
+
): number | null {
|
|
93
|
+
const $pos = doc.resolve(pos);
|
|
94
|
+
if ($pos.parent.inlineContent) {
|
|
95
|
+
return pos;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const candidate =
|
|
99
|
+
Selection.findFrom($pos, bias, true) ??
|
|
100
|
+
Selection.findFrom($pos, -bias, true) ??
|
|
101
|
+
Selection.near($pos, bias);
|
|
102
|
+
|
|
103
|
+
if (candidate.$from.parent.inlineContent || candidate.$to.parent.inlineContent) {
|
|
104
|
+
return bias < 0 ? candidate.to : candidate.from;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildPMDoc(
|
|
111
|
+
surface: EditorSurfaceSnapshot,
|
|
112
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
113
|
+
showUnsupportedObjectPreviews: boolean,
|
|
114
|
+
): PMNode {
|
|
115
|
+
const blocks = buildPMBlocks(surface.blocks, mediaPreviews, showUnsupportedObjectPreviews);
|
|
116
|
+
|
|
117
|
+
// Ensure at least one block (PM requires non-empty doc)
|
|
118
|
+
if (blocks.length === 0) {
|
|
119
|
+
blocks.push(editorSchema.nodes.paragraph.create());
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return editorSchema.nodes.doc.create(null, Fragment.from(blocks));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildPMBlocks(
|
|
126
|
+
blocks: SurfaceBlockSnapshot[],
|
|
127
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
128
|
+
showUnsupportedObjectPreviews: boolean,
|
|
129
|
+
): PMNode[] {
|
|
130
|
+
const nodes: PMNode[] = [];
|
|
131
|
+
|
|
132
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
133
|
+
const block = blocks[index];
|
|
134
|
+
const previousBlock = index > 0 ? blocks[index - 1] : null;
|
|
135
|
+
const nextBlock = blocks[index + 1];
|
|
136
|
+
const previousParagraph = previousBlock?.kind === "paragraph" ? previousBlock : null;
|
|
137
|
+
const nextParagraph = nextBlock?.kind === "paragraph" ? nextBlock : null;
|
|
138
|
+
|
|
139
|
+
if (block.kind === "paragraph") {
|
|
140
|
+
nodes.push(
|
|
141
|
+
buildParagraph(
|
|
142
|
+
block,
|
|
143
|
+
previousParagraph,
|
|
144
|
+
nextParagraph,
|
|
145
|
+
mediaPreviews,
|
|
146
|
+
showUnsupportedObjectPreviews,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
} else if (block.kind === "table") {
|
|
150
|
+
nodes.push(buildTable(block, mediaPreviews, showUnsupportedObjectPreviews));
|
|
151
|
+
} else if (block.kind === "sdt_block") {
|
|
152
|
+
nodes.push(buildSdtBlock(block, mediaPreviews, showUnsupportedObjectPreviews));
|
|
153
|
+
} else {
|
|
154
|
+
nodes.push(buildOpaqueBlock(block));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return nodes;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function buildParagraph(
|
|
162
|
+
block: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>,
|
|
163
|
+
previousParagraph: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }> | null,
|
|
164
|
+
nextParagraph: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }> | null,
|
|
165
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
166
|
+
showUnsupportedObjectPreviews: boolean,
|
|
167
|
+
): PMNode {
|
|
168
|
+
const content: PMNode[] = [];
|
|
169
|
+
const paragraphLayout = resolveParagraphLayout(block);
|
|
170
|
+
const tabStops = paragraphLayout.tabStops;
|
|
171
|
+
let tabIndex = 0;
|
|
172
|
+
const textSegments = block.segments.filter(
|
|
173
|
+
(segment): segment is Extract<SurfaceInlineSegment, { kind: "text" }> => segment.kind === "text",
|
|
174
|
+
);
|
|
175
|
+
const fullyVanishedParagraph =
|
|
176
|
+
textSegments.length > 0 &&
|
|
177
|
+
textSegments.every((segment) => segment.marks?.includes("vanish")) &&
|
|
178
|
+
block.segments.every((segment) => segment.kind === "text");
|
|
179
|
+
|
|
180
|
+
if (fullyVanishedParagraph) {
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
for (const segment of block.segments) {
|
|
184
|
+
if (segment.kind === "tab" && tabIndex < tabStops.length) {
|
|
185
|
+
const stop = tabStops[tabIndex];
|
|
186
|
+
const stopPos = (stop as { pos?: number }).pos ?? (stop as { position?: number }).position ?? 0;
|
|
187
|
+
const prevStop = tabIndex > 0 ? tabStops[tabIndex - 1] : null;
|
|
188
|
+
const prevPos = prevStop
|
|
189
|
+
? ((prevStop as { pos?: number }).pos ?? (prevStop as { position?: number }).position ?? 0)
|
|
190
|
+
: 0;
|
|
191
|
+
const widthPx = Math.round((stopPos - prevPos) / 15);
|
|
192
|
+
const leader = (stop as { leader?: string }).leader ?? null;
|
|
193
|
+
const align = (stop as { val?: string }).val ?? null;
|
|
194
|
+
content.push(
|
|
195
|
+
editorSchema.nodes.tab_char.create({
|
|
196
|
+
tabWidth: widthPx > 8 ? widthPx : null,
|
|
197
|
+
leader,
|
|
198
|
+
align,
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
tabIndex++;
|
|
202
|
+
} else {
|
|
203
|
+
const nodes = buildInlineContent(segment, mediaPreviews, showUnsupportedObjectPreviews);
|
|
204
|
+
content.push(...nodes);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const listContinuation = Boolean(
|
|
209
|
+
block.numbering &&
|
|
210
|
+
nextParagraph?.numbering &&
|
|
211
|
+
nextParagraph.numbering.numberingInstanceId === block.numbering.numberingInstanceId &&
|
|
212
|
+
nextParagraph.numbering.level === block.numbering.level,
|
|
213
|
+
);
|
|
214
|
+
const contextualSpacingAfter = Boolean(
|
|
215
|
+
block.contextualSpacing &&
|
|
216
|
+
nextParagraph?.contextualSpacing &&
|
|
217
|
+
(nextParagraph.styleId ?? "__default__") === (block.styleId ?? "__default__"),
|
|
218
|
+
);
|
|
219
|
+
const contextualSpacingBefore = Boolean(
|
|
220
|
+
block.contextualSpacing &&
|
|
221
|
+
previousParagraph?.contextualSpacing &&
|
|
222
|
+
(previousParagraph.styleId ?? "__default__") === (block.styleId ?? "__default__"),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
return editorSchema.nodes.paragraph.create(
|
|
226
|
+
{
|
|
227
|
+
styleId: block.styleId ?? null,
|
|
228
|
+
numberingInstanceId: block.numbering?.numberingInstanceId ?? null,
|
|
229
|
+
numberingLevel: block.numbering?.level ?? null,
|
|
230
|
+
numberingPrefix:
|
|
231
|
+
(block as typeof block & { numberingPrefix?: string }).numberingPrefix ??
|
|
232
|
+
null,
|
|
233
|
+
numberingSuffix:
|
|
234
|
+
(block as typeof block & { numberingSuffix?: string }).numberingSuffix ??
|
|
235
|
+
null,
|
|
236
|
+
alignment: block.alignment ?? null,
|
|
237
|
+
spacingBefore: paragraphLayout.spacing?.before ?? null,
|
|
238
|
+
spacingAfter: paragraphLayout.spacing?.after ?? null,
|
|
239
|
+
lineSpacing: paragraphLayout.spacing?.line ?? null,
|
|
240
|
+
lineRule: paragraphLayout.spacing?.lineRule ?? null,
|
|
241
|
+
contextualSpacing: block.contextualSpacing ?? null,
|
|
242
|
+
listContinuation: listContinuation || null,
|
|
243
|
+
contextualSpacingBefore: contextualSpacingBefore || null,
|
|
244
|
+
contextualSpacingAfter: contextualSpacingAfter || null,
|
|
245
|
+
indentLeft: paragraphLayout.indentation?.left ?? null,
|
|
246
|
+
indentRight: paragraphLayout.indentation?.right ?? null,
|
|
247
|
+
indentFirstLine: paragraphLayout.indentation?.firstLine ?? null,
|
|
248
|
+
indentHanging: paragraphLayout.indentation?.hanging ?? null,
|
|
249
|
+
numberingMarkerWidth: paragraphLayout.markerLane?.width ?? null,
|
|
250
|
+
numberingMarkerJustification: paragraphLayout.markerJustification ?? null,
|
|
251
|
+
shadingFill: block.shading?.fill ?? null,
|
|
252
|
+
borderTop: (block.borders as Record<string, unknown>)?.top ?? null,
|
|
253
|
+
borderBottom: (block.borders as Record<string, unknown>)?.bottom ?? null,
|
|
254
|
+
borderLeft: (block.borders as Record<string, unknown>)?.left ?? null,
|
|
255
|
+
borderRight: (block.borders as Record<string, unknown>)?.right ?? null,
|
|
256
|
+
outlineLevel: block.outlineLevel ?? null,
|
|
257
|
+
bidi: block.bidi ?? null,
|
|
258
|
+
pageBreakBefore: block.pageBreakBefore ?? null,
|
|
259
|
+
hiddenTextOnly: fullyVanishedParagraph || null,
|
|
260
|
+
},
|
|
261
|
+
content.length > 0 ? Fragment.from(content) : undefined,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function resolveParagraphLayout(
|
|
266
|
+
block: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>,
|
|
267
|
+
): {
|
|
268
|
+
spacing: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["spacing"];
|
|
269
|
+
indentation: Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["indentation"];
|
|
270
|
+
tabStops: Array<{ pos: number; val?: string; leader?: string }>;
|
|
271
|
+
markerLane: NonNullable<
|
|
272
|
+
NonNullable<Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["resolvedNumbering"]>["geometry"]["markerLane"]
|
|
273
|
+
> | undefined;
|
|
274
|
+
markerJustification: NonNullable<
|
|
275
|
+
NonNullable<Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["resolvedNumbering"]>["geometry"]["markerJustification"]
|
|
276
|
+
> | undefined;
|
|
277
|
+
} {
|
|
278
|
+
return {
|
|
279
|
+
spacing: block.resolvedNumbering?.geometry.spacing ?? block.spacing,
|
|
280
|
+
indentation: block.resolvedNumbering?.geometry.indentation ?? block.indentation,
|
|
281
|
+
tabStops: block.resolvedNumbering?.geometry.tabStops ?? block.tabStops ?? [],
|
|
282
|
+
markerLane: block.resolvedNumbering?.geometry.markerLane,
|
|
283
|
+
markerJustification: block.resolvedNumbering?.geometry.markerJustification,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function buildInlineContent(
|
|
288
|
+
segment: SurfaceInlineSegment,
|
|
289
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
290
|
+
showUnsupportedObjectPreviews: boolean,
|
|
291
|
+
): PMNode[] {
|
|
292
|
+
switch (segment.kind) {
|
|
293
|
+
case "text": {
|
|
294
|
+
if (!segment.text) return [];
|
|
295
|
+
|
|
296
|
+
// Build PM marks from segment marks
|
|
297
|
+
let marks = editorSchema.marks.bold.isInSet([])
|
|
298
|
+
? [] // shouldn't happen, just type safety
|
|
299
|
+
: [];
|
|
300
|
+
|
|
301
|
+
const pmMarks = [];
|
|
302
|
+
if (segment.marks) {
|
|
303
|
+
for (const mark of segment.marks) {
|
|
304
|
+
// Map surface mark names that differ from PM schema mark names
|
|
305
|
+
if (mark === "smallCaps") {
|
|
306
|
+
pmMarks.push(editorSchema.marks.small_caps.create());
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (mark === "allCaps") {
|
|
310
|
+
pmMarks.push(editorSchema.marks.all_caps.create());
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const pmMark = editorSchema.marks[mark];
|
|
314
|
+
if (pmMark) {
|
|
315
|
+
pmMarks.push(pmMark.create());
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (segment.kind === "text" && segment.markAttrs) {
|
|
320
|
+
if (segment.markAttrs.backgroundColor) {
|
|
321
|
+
pmMarks.push(editorSchema.marks.highlight.create({ color: `#${segment.markAttrs.backgroundColor}` }));
|
|
322
|
+
}
|
|
323
|
+
if (segment.markAttrs.fontFamily) {
|
|
324
|
+
pmMarks.push(editorSchema.marks.font_family.create({ family: segment.markAttrs.fontFamily }));
|
|
325
|
+
}
|
|
326
|
+
if (segment.markAttrs.fontSize) {
|
|
327
|
+
pmMarks.push(editorSchema.marks.font_size.create({ size: segment.markAttrs.fontSize / 2 }));
|
|
328
|
+
}
|
|
329
|
+
if (segment.markAttrs.textColor) {
|
|
330
|
+
pmMarks.push(editorSchema.marks.text_color.create({ color: `#${segment.markAttrs.textColor}` }));
|
|
331
|
+
}
|
|
332
|
+
if (segment.markAttrs.charSpacing) {
|
|
333
|
+
pmMarks.push(editorSchema.marks.char_spacing.create({ value: segment.markAttrs.charSpacing }));
|
|
334
|
+
}
|
|
335
|
+
if (segment.markAttrs.kerning) {
|
|
336
|
+
pmMarks.push(editorSchema.marks.font_kerning.create({ threshold: segment.markAttrs.kerning }));
|
|
337
|
+
}
|
|
338
|
+
if (segment.markAttrs.textFill && !segment.markAttrs.textColor) {
|
|
339
|
+
const colorMatch = segment.markAttrs.textFill.match(/\bval="([0-9A-Fa-f]{6})"/);
|
|
340
|
+
if (colorMatch) {
|
|
341
|
+
pmMarks.push(editorSchema.marks.text_color.create({ color: `#${colorMatch[1]}` }));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (segment.hyperlinkHref) {
|
|
346
|
+
pmMarks.push(editorSchema.marks.link.create({ href: segment.hyperlinkHref }));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return [editorSchema.text(segment.text, pmMarks.length > 0 ? pmMarks : undefined)];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
case "hard_break":
|
|
353
|
+
return [editorSchema.nodes.hard_break.create()];
|
|
354
|
+
|
|
355
|
+
case "tab":
|
|
356
|
+
return [editorSchema.nodes.tab_char.create()];
|
|
357
|
+
|
|
358
|
+
case "image":
|
|
359
|
+
{
|
|
360
|
+
const preview = mediaPreviews[segment.mediaId];
|
|
361
|
+
return [
|
|
362
|
+
editorSchema.nodes.image_atom.create({
|
|
363
|
+
mediaId: segment.mediaId,
|
|
364
|
+
altText: segment.altText ?? null,
|
|
365
|
+
state: segment.state,
|
|
366
|
+
display: segment.display ?? "inline",
|
|
367
|
+
detail: segment.detail ?? null,
|
|
368
|
+
src: preview?.src ?? null,
|
|
369
|
+
widthEmu: preview?.widthEmu ?? null,
|
|
370
|
+
heightEmu: preview?.heightEmu ?? null,
|
|
371
|
+
}),
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
case "opaque_inline":
|
|
376
|
+
return [buildOpaqueInlineOrComplexAtom(segment, showUnsupportedObjectPreviews)];
|
|
377
|
+
|
|
378
|
+
case "note_ref": {
|
|
379
|
+
const text = editorSchema.text(
|
|
380
|
+
segment.label,
|
|
381
|
+
[editorSchema.marks.superscript.create()],
|
|
382
|
+
);
|
|
383
|
+
return [text];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
case "field_ref":
|
|
387
|
+
return [
|
|
388
|
+
editorSchema.nodes.field_ref_atom.create({
|
|
389
|
+
fieldFamily: segment.fieldFamily,
|
|
390
|
+
fieldTarget: segment.fieldTarget ?? null,
|
|
391
|
+
instruction: segment.instruction,
|
|
392
|
+
refreshStatus: segment.refreshStatus,
|
|
393
|
+
label: segment.label,
|
|
394
|
+
}),
|
|
395
|
+
];
|
|
396
|
+
|
|
397
|
+
default:
|
|
398
|
+
return [];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function buildTable(
|
|
403
|
+
block: Extract<SurfaceBlockSnapshot, { kind: "table" }>,
|
|
404
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
405
|
+
showUnsupportedObjectPreviews: boolean,
|
|
406
|
+
): PMNode {
|
|
407
|
+
const rows: PMNode[] = [];
|
|
408
|
+
for (const row of block.rows) {
|
|
409
|
+
const cells: PMNode[] = [];
|
|
410
|
+
for (const cell of row.cells) {
|
|
411
|
+
const cellContent = buildPMBlocks(
|
|
412
|
+
cell.content,
|
|
413
|
+
mediaPreviews,
|
|
414
|
+
showUnsupportedObjectPreviews,
|
|
415
|
+
);
|
|
416
|
+
// Ensure at least one paragraph in cell (PM requires non-empty)
|
|
417
|
+
if (cellContent.length === 0) {
|
|
418
|
+
cellContent.push(editorSchema.nodes.paragraph.create());
|
|
419
|
+
}
|
|
420
|
+
const cellNodeType = row.isHeader
|
|
421
|
+
? editorSchema.nodes.table_header_cell
|
|
422
|
+
: editorSchema.nodes.table_cell;
|
|
423
|
+
cells.push(
|
|
424
|
+
cellNodeType.create(
|
|
425
|
+
{
|
|
426
|
+
colspan: cell.colspan,
|
|
427
|
+
rowspan: cell.rowspan,
|
|
428
|
+
gridSpan: cell.gridSpan,
|
|
429
|
+
verticalMerge: cell.verticalMerge,
|
|
430
|
+
backgroundColor: cell.backgroundColor ?? null,
|
|
431
|
+
verticalAlign: cell.verticalAlign ?? null,
|
|
432
|
+
borderTop: cell.borderTop ?? null,
|
|
433
|
+
borderRight: cell.borderRight ?? null,
|
|
434
|
+
borderBottom: cell.borderBottom ?? null,
|
|
435
|
+
borderLeft: cell.borderLeft ?? null,
|
|
436
|
+
},
|
|
437
|
+
Fragment.from(cellContent),
|
|
438
|
+
),
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
rows.push(editorSchema.nodes.table_row.create(
|
|
442
|
+
{
|
|
443
|
+
gridBefore: row.gridBefore ?? 0,
|
|
444
|
+
gridAfter: row.gridAfter ?? 0,
|
|
445
|
+
height: row.height ?? null,
|
|
446
|
+
heightRule: row.heightRule ?? null,
|
|
447
|
+
isHeader: row.isHeader ?? false,
|
|
448
|
+
},
|
|
449
|
+
Fragment.from(cells),
|
|
450
|
+
));
|
|
451
|
+
}
|
|
452
|
+
return editorSchema.nodes.table.create(
|
|
453
|
+
{
|
|
454
|
+
styleId: block.styleId ?? null,
|
|
455
|
+
gridColumns: block.gridColumns,
|
|
456
|
+
alignment: block.alignment ?? null,
|
|
457
|
+
tblLookFirstRow: block.tblLook?.firstRow ?? false,
|
|
458
|
+
tblLookLastRow: block.tblLook?.lastRow ?? false,
|
|
459
|
+
tblLookFirstColumn: block.tblLook?.firstColumn ?? false,
|
|
460
|
+
tblLookLastColumn: block.tblLook?.lastColumn ?? false,
|
|
461
|
+
tblLookNoHBand: block.tblLook?.noHBand ?? false,
|
|
462
|
+
tblLookNoVBand: block.tblLook?.noVBand ?? false,
|
|
463
|
+
},
|
|
464
|
+
Fragment.from(rows),
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function buildSdtBlock(
|
|
469
|
+
block: Extract<SurfaceBlockSnapshot, { kind: "sdt_block" }>,
|
|
470
|
+
mediaPreviews: Record<string, MediaPreviewDescriptor>,
|
|
471
|
+
showUnsupportedObjectPreviews: boolean,
|
|
472
|
+
): PMNode {
|
|
473
|
+
const children = buildPMBlocks(
|
|
474
|
+
block.children,
|
|
475
|
+
mediaPreviews,
|
|
476
|
+
showUnsupportedObjectPreviews,
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
if (children.length === 0) {
|
|
480
|
+
children.push(editorSchema.nodes.paragraph.create());
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return editorSchema.nodes.sdt_block.create(
|
|
484
|
+
{
|
|
485
|
+
sdtType: block.sdtType ?? null,
|
|
486
|
+
alias: block.alias ?? null,
|
|
487
|
+
tag: block.tag ?? null,
|
|
488
|
+
lock: block.lock ?? null,
|
|
489
|
+
checkboxChecked: block.checkboxChecked ?? null,
|
|
490
|
+
dateValue: block.dateValue ?? null,
|
|
491
|
+
dropdownItems: block.dropdownItems ?? null,
|
|
492
|
+
comboBoxItems: block.comboBoxItems ?? null,
|
|
493
|
+
showingPlcHdr: block.showingPlcHdr ?? false,
|
|
494
|
+
},
|
|
495
|
+
Fragment.from(children),
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Map an opaque_inline surface segment to a dedicated complex-rendering PM atom
|
|
501
|
+
* node when the label identifies a known complex content type, or fall back to
|
|
502
|
+
* the generic opaque_inline node.
|
|
503
|
+
*/
|
|
504
|
+
function buildOpaqueInlineOrComplexAtom(
|
|
505
|
+
segment: Extract<import("../../api/public-types").SurfaceInlineSegment, { kind: "opaque_inline" }>,
|
|
506
|
+
showUnsupportedObjectPreviews: boolean,
|
|
507
|
+
): PMNode {
|
|
508
|
+
const label = segment.label;
|
|
509
|
+
const detail = segment.detail;
|
|
510
|
+
|
|
511
|
+
if (showUnsupportedObjectPreviews && label === "Embedded chart") {
|
|
512
|
+
return editorSchema.nodes.chart_atom.create({ detail });
|
|
513
|
+
}
|
|
514
|
+
if (showUnsupportedObjectPreviews && label === "SmartArt diagram") {
|
|
515
|
+
return editorSchema.nodes.smartart_atom.create({ detail });
|
|
516
|
+
}
|
|
517
|
+
if (showUnsupportedObjectPreviews && (label === "Drawing shape" || label === "Text box")) {
|
|
518
|
+
const textMatch = /(?:Text content|Content): "([^"]+)"/.exec(detail);
|
|
519
|
+
const geometryMatch = /Geometry: ([^.]+)\./.exec(detail);
|
|
520
|
+
return editorSchema.nodes.shape_atom.create({
|
|
521
|
+
text: textMatch ? textMatch[1] : null,
|
|
522
|
+
geometry: geometryMatch ? geometryMatch[1] : null,
|
|
523
|
+
detail,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
if (showUnsupportedObjectPreviews && label === "WordArt") {
|
|
527
|
+
const textMatch = /Text: "([^"]+)"/.exec(detail);
|
|
528
|
+
const effectMatch = /Effect: ([^.]+)\./.exec(detail);
|
|
529
|
+
return editorSchema.nodes.wordart_atom.create({
|
|
530
|
+
text: textMatch ? textMatch[1] : "",
|
|
531
|
+
geometry: effectMatch ? effectMatch[1] : null,
|
|
532
|
+
detail,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
if (showUnsupportedObjectPreviews && label === "Legacy VML drawing") {
|
|
536
|
+
const textMatch = /Text content: "([^"]+)"/.exec(detail);
|
|
537
|
+
const typeMatch = /Type: ([^.]+)\./.exec(detail);
|
|
538
|
+
return editorSchema.nodes.vml_atom.create({
|
|
539
|
+
text: textMatch ? textMatch[1] : null,
|
|
540
|
+
shapeType: typeMatch ? typeMatch[1] : null,
|
|
541
|
+
detail,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return editorSchema.nodes.opaque_inline.create({
|
|
546
|
+
fragmentId: segment.fragmentId,
|
|
547
|
+
warningId: segment.warningId,
|
|
548
|
+
label,
|
|
549
|
+
detail,
|
|
550
|
+
presentation: segment.presentation ?? "inline-chip",
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function buildOpaqueBlock(
|
|
555
|
+
block: Extract<SurfaceBlockSnapshot, { kind: "opaque_block" }>,
|
|
556
|
+
): PMNode {
|
|
557
|
+
return editorSchema.nodes.opaque_block.create({
|
|
558
|
+
fragmentId: block.fragmentId,
|
|
559
|
+
warningId: block.warningId,
|
|
560
|
+
label: block.label,
|
|
561
|
+
detail: block.detail,
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function clamp(value: number, min: number, max: number): number {
|
|
566
|
+
return Math.max(min, Math.min(max, value));
|
|
567
|
+
}
|