@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
|
@@ -1,161 +1,270 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Section layout authoring commands.
|
|
3
|
+
*
|
|
4
|
+
* Supports inserting and deleting section breaks, bounded section layout
|
|
5
|
+
* updates (page size, margins, gutter, orientation, columns, first-page /
|
|
6
|
+
* odd-even variants, page-numbering restart / format), and section break
|
|
7
|
+
* deletion with following-section merge semantics.
|
|
8
|
+
*
|
|
9
|
+
* All mutations are command-backed and export-safe.
|
|
10
|
+
*/
|
|
11
|
+
import type {
|
|
12
|
+
RuntimeRenderSnapshot,
|
|
13
|
+
SelectionSnapshot,
|
|
14
|
+
} from "../../api/public-types";
|
|
15
|
+
import type {
|
|
16
|
+
CanonicalDocument as CanonicalDocumentEnvelope,
|
|
17
|
+
ColumnProperties,
|
|
18
|
+
PageMargins,
|
|
19
|
+
PageNumbering,
|
|
20
|
+
PageSize,
|
|
21
|
+
SectionBreakNode,
|
|
22
|
+
SectionProperties,
|
|
23
|
+
} from "../../model/canonical-document.ts";
|
|
24
|
+
|
|
25
|
+
// ---- Public types ----
|
|
26
|
+
|
|
27
|
+
export interface SectionLayoutCommandContext {
|
|
28
|
+
timestamp: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SectionLayoutMutationResult {
|
|
32
|
+
document: CanonicalDocumentEnvelope;
|
|
33
|
+
selection: SelectionSnapshot;
|
|
34
|
+
changed: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type SectionBreakType =
|
|
38
|
+
| "nextPage"
|
|
39
|
+
| "continuous"
|
|
40
|
+
| "evenPage"
|
|
41
|
+
| "oddPage"
|
|
42
|
+
| "nextColumn";
|
|
43
|
+
|
|
44
|
+
export interface SectionLayoutPatch {
|
|
45
|
+
pageSize?: Partial<PageSize>;
|
|
46
|
+
pageMargins?: Partial<PageMargins>;
|
|
47
|
+
columns?: Partial<ColumnProperties>;
|
|
48
|
+
pageNumbering?: Partial<PageNumbering>;
|
|
49
|
+
titlePage?: boolean;
|
|
50
|
+
sectionType?: SectionBreakType;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SectionLinkPatch {
|
|
54
|
+
kind: "header" | "footer";
|
|
55
|
+
variant: "default" | "first" | "even";
|
|
56
|
+
linkToPrevious: boolean;
|
|
57
|
+
relationshipId?: string | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---- Insert section break ----
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Insert a section break at the current selection position.
|
|
64
|
+
* The new section inherits properties from the section that contained the
|
|
65
|
+
* insertion point (the *following* section keeps its own properties).
|
|
66
|
+
*/
|
|
67
|
+
export function insertSectionBreak(
|
|
68
|
+
document: CanonicalDocumentEnvelope,
|
|
69
|
+
snapshot: RuntimeRenderSnapshot,
|
|
70
|
+
breakType: SectionBreakType,
|
|
71
|
+
_context: SectionLayoutCommandContext,
|
|
72
|
+
): SectionLayoutMutationResult {
|
|
73
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
35
74
|
const surface = snapshot.surface;
|
|
75
|
+
|
|
36
76
|
if (!surface) {
|
|
37
77
|
return noopResult(document, snapshot.selection);
|
|
38
78
|
}
|
|
79
|
+
|
|
39
80
|
const position = snapshot.selection.head;
|
|
40
81
|
const blockIndex = resolveBlockIndexForPosition(surface.blocks, position);
|
|
82
|
+
|
|
41
83
|
if (blockIndex < 0) {
|
|
42
84
|
return noopResult(document, snapshot.selection);
|
|
43
85
|
}
|
|
86
|
+
|
|
44
87
|
const sectionTarget = resolveSectionTarget(cloned, surface.blocks, position);
|
|
45
88
|
const inheritedProperties = cloneSectionProperties(sectionTarget?.properties);
|
|
46
|
-
const sectionBreak = {
|
|
89
|
+
const sectionBreak: SectionBreakNode = {
|
|
47
90
|
type: "section_break",
|
|
48
91
|
sectionProperties: {
|
|
49
92
|
...inheritedProperties,
|
|
50
|
-
sectionType: breakType
|
|
51
|
-
}
|
|
93
|
+
sectionType: breakType,
|
|
94
|
+
},
|
|
52
95
|
};
|
|
96
|
+
|
|
53
97
|
cloned.content.children.splice(blockIndex + 1, 0, sectionBreak);
|
|
54
98
|
cloned.updatedAt = _context.timestamp;
|
|
99
|
+
|
|
55
100
|
return {
|
|
56
101
|
document: cloned,
|
|
57
102
|
selection: snapshot.selection,
|
|
58
|
-
changed: true
|
|
103
|
+
changed: true,
|
|
59
104
|
};
|
|
60
105
|
}
|
|
61
|
-
|
|
62
|
-
|
|
106
|
+
|
|
107
|
+
export function insertSectionBreakAfterSectionIndex(
|
|
108
|
+
document: CanonicalDocumentEnvelope,
|
|
109
|
+
sectionIndex: number,
|
|
110
|
+
breakType: SectionBreakType,
|
|
111
|
+
context: SectionLayoutCommandContext,
|
|
112
|
+
): SectionLayoutMutationResult {
|
|
113
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
63
114
|
const insertionIndex = findSectionInsertionIndex(cloned, sectionIndex);
|
|
64
115
|
if (insertionIndex < 0) {
|
|
65
116
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
66
117
|
}
|
|
118
|
+
|
|
67
119
|
const inheritedProperties = cloneSectionProperties(
|
|
68
|
-
getSectionPropertiesAtIndex(cloned, sectionIndex)
|
|
120
|
+
getSectionPropertiesAtIndex(cloned, sectionIndex),
|
|
69
121
|
);
|
|
70
|
-
const sectionBreak = {
|
|
122
|
+
const sectionBreak: SectionBreakNode = {
|
|
71
123
|
type: "section_break",
|
|
72
124
|
sectionProperties: {
|
|
73
125
|
...inheritedProperties,
|
|
74
|
-
sectionType: breakType
|
|
75
|
-
}
|
|
126
|
+
sectionType: breakType,
|
|
127
|
+
},
|
|
76
128
|
};
|
|
129
|
+
|
|
77
130
|
cloned.content.children.splice(insertionIndex, 0, sectionBreak);
|
|
78
131
|
cloned.updatedAt = context.timestamp;
|
|
132
|
+
|
|
79
133
|
return {
|
|
80
134
|
document: cloned,
|
|
81
135
|
selection: createSelectionSnapshot(0, 0),
|
|
82
|
-
changed: true
|
|
136
|
+
changed: true,
|
|
83
137
|
};
|
|
84
138
|
}
|
|
85
|
-
|
|
86
|
-
|
|
139
|
+
|
|
140
|
+
// ---- Delete section break ----
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Delete the section break at or nearest to the current selection position.
|
|
144
|
+
* On deletion the *following* section's formatting and header/footer linkage
|
|
145
|
+
* are adopted (Word merge semantics).
|
|
146
|
+
*/
|
|
147
|
+
export function deleteSectionBreak(
|
|
148
|
+
document: CanonicalDocumentEnvelope,
|
|
149
|
+
snapshot: RuntimeRenderSnapshot,
|
|
150
|
+
_context: SectionLayoutCommandContext,
|
|
151
|
+
): SectionLayoutMutationResult {
|
|
152
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
153
|
+
|
|
87
154
|
const breakIndex = findNearestSectionBreak(cloned, snapshot);
|
|
88
155
|
if (breakIndex < 0) {
|
|
89
156
|
return noopResult(document, snapshot.selection);
|
|
90
157
|
}
|
|
158
|
+
|
|
91
159
|
const breakNode = cloned.content.children[breakIndex];
|
|
92
160
|
if (!breakNode || breakNode.type !== "section_break") {
|
|
93
161
|
return noopResult(document, snapshot.selection);
|
|
94
162
|
}
|
|
163
|
+
|
|
164
|
+
// Remove the section break node
|
|
95
165
|
cloned.content.children.splice(breakIndex, 1);
|
|
166
|
+
|
|
96
167
|
cloned.updatedAt = _context.timestamp;
|
|
168
|
+
|
|
97
169
|
return {
|
|
98
170
|
document: cloned,
|
|
99
171
|
selection: snapshot.selection,
|
|
100
|
-
changed: true
|
|
172
|
+
changed: true,
|
|
101
173
|
};
|
|
102
174
|
}
|
|
103
|
-
|
|
175
|
+
|
|
176
|
+
export function deleteSectionBreakAtSectionIndex(
|
|
177
|
+
document: CanonicalDocumentEnvelope,
|
|
178
|
+
sectionIndex: number,
|
|
179
|
+
context: SectionLayoutCommandContext,
|
|
180
|
+
): SectionLayoutMutationResult {
|
|
104
181
|
if (sectionIndex <= 0) {
|
|
105
182
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
106
183
|
}
|
|
107
|
-
|
|
184
|
+
|
|
185
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
108
186
|
const breakIndex = findSectionBreakNodeIndexForSection(cloned, sectionIndex);
|
|
109
187
|
if (breakIndex < 0) {
|
|
110
188
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
111
189
|
}
|
|
190
|
+
|
|
112
191
|
cloned.content.children.splice(breakIndex, 1);
|
|
113
192
|
cloned.updatedAt = context.timestamp;
|
|
193
|
+
|
|
114
194
|
return {
|
|
115
195
|
document: cloned,
|
|
116
196
|
selection: createSelectionSnapshot(0, 0),
|
|
117
|
-
changed: true
|
|
197
|
+
changed: true,
|
|
118
198
|
};
|
|
119
199
|
}
|
|
120
|
-
|
|
121
|
-
|
|
200
|
+
|
|
201
|
+
// ---- Update section layout ----
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Apply a bounded layout patch to the section containing the current selection.
|
|
205
|
+
* Supports: page size, margins, gutter, orientation, columns,
|
|
206
|
+
* first-page / odd-even variants, page-numbering restart / format.
|
|
207
|
+
*/
|
|
208
|
+
export function updateSectionLayout(
|
|
209
|
+
document: CanonicalDocumentEnvelope,
|
|
210
|
+
snapshot: RuntimeRenderSnapshot,
|
|
211
|
+
patch: SectionLayoutPatch,
|
|
212
|
+
_context: SectionLayoutCommandContext,
|
|
213
|
+
): SectionLayoutMutationResult {
|
|
214
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
122
215
|
const surface = snapshot.surface;
|
|
216
|
+
|
|
123
217
|
if (!surface) {
|
|
124
218
|
return noopResult(document, snapshot.selection);
|
|
125
219
|
}
|
|
220
|
+
|
|
126
221
|
const position = snapshot.selection.head;
|
|
127
222
|
const sectionTarget = resolveSectionTarget(cloned, surface.blocks, position);
|
|
223
|
+
|
|
128
224
|
if (!sectionTarget) {
|
|
129
225
|
return noopResult(document, snapshot.selection);
|
|
130
226
|
}
|
|
227
|
+
|
|
131
228
|
const existing = sectionTarget.properties ?? {};
|
|
132
229
|
const updated = applySectionLayoutPatch(existing, patch);
|
|
230
|
+
|
|
133
231
|
if (sectionTarget.kind === "inline") {
|
|
134
232
|
const breakNode = cloned.content.children[sectionTarget.blockIndex];
|
|
135
233
|
if (breakNode && breakNode.type === "section_break") {
|
|
136
234
|
breakNode.sectionProperties = updated;
|
|
235
|
+
// Clear raw XML so the structured properties are used on export
|
|
137
236
|
delete breakNode.sectionPropertiesXml;
|
|
138
237
|
delete breakNode.propertiesXml;
|
|
139
238
|
}
|
|
140
239
|
} else {
|
|
240
|
+
// Final section: update subParts.finalSectionProperties
|
|
141
241
|
if (!cloned.subParts) {
|
|
142
242
|
return noopResult(document, snapshot.selection);
|
|
143
243
|
}
|
|
144
244
|
cloned.subParts.finalSectionProperties = updated;
|
|
145
245
|
}
|
|
246
|
+
|
|
146
247
|
cloned.updatedAt = _context.timestamp;
|
|
248
|
+
|
|
147
249
|
return {
|
|
148
250
|
document: cloned,
|
|
149
251
|
selection: snapshot.selection,
|
|
150
|
-
changed: true
|
|
252
|
+
changed: true,
|
|
151
253
|
};
|
|
152
254
|
}
|
|
153
|
-
|
|
154
|
-
|
|
255
|
+
|
|
256
|
+
export function updateSectionLayoutAtSectionIndex(
|
|
257
|
+
document: CanonicalDocumentEnvelope,
|
|
258
|
+
sectionIndex: number,
|
|
259
|
+
patch: SectionLayoutPatch,
|
|
260
|
+
context: SectionLayoutCommandContext,
|
|
261
|
+
): SectionLayoutMutationResult {
|
|
262
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
155
263
|
const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
|
|
156
264
|
if (!target) {
|
|
157
265
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
158
266
|
}
|
|
267
|
+
|
|
159
268
|
const updated = applySectionLayoutPatch(target.properties ?? {}, patch);
|
|
160
269
|
if (target.kind === "inline") {
|
|
161
270
|
const breakNode = cloned.content.children[target.blockIndex];
|
|
@@ -166,35 +275,44 @@ function updateSectionLayoutAtSectionIndex(document, sectionIndex, patch, contex
|
|
|
166
275
|
}
|
|
167
276
|
} else {
|
|
168
277
|
cloned.subParts = {
|
|
169
|
-
...cloned.subParts ?? {
|
|
278
|
+
...(cloned.subParts ?? {
|
|
170
279
|
headers: [],
|
|
171
|
-
footers: []
|
|
172
|
-
},
|
|
173
|
-
finalSectionProperties: updated
|
|
280
|
+
footers: [],
|
|
281
|
+
}),
|
|
282
|
+
finalSectionProperties: updated,
|
|
174
283
|
};
|
|
175
284
|
}
|
|
285
|
+
|
|
176
286
|
cloned.updatedAt = context.timestamp;
|
|
177
287
|
return {
|
|
178
288
|
document: cloned,
|
|
179
289
|
selection: createSelectionSnapshot(0, 0),
|
|
180
|
-
changed: true
|
|
290
|
+
changed: true,
|
|
181
291
|
};
|
|
182
292
|
}
|
|
183
|
-
|
|
184
|
-
|
|
293
|
+
|
|
294
|
+
export function setSectionPageNumberingAtSectionIndex(
|
|
295
|
+
document: CanonicalDocumentEnvelope,
|
|
296
|
+
sectionIndex: number,
|
|
297
|
+
pageNumbering: Partial<PageNumbering> | null,
|
|
298
|
+
context: SectionLayoutCommandContext,
|
|
299
|
+
): SectionLayoutMutationResult {
|
|
300
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
185
301
|
const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
|
|
186
302
|
if (!target) {
|
|
187
303
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
188
304
|
}
|
|
305
|
+
|
|
189
306
|
const nextProperties = cloneSectionProperties(target.properties);
|
|
190
307
|
if (pageNumbering === null) {
|
|
191
308
|
delete nextProperties.pageNumbering;
|
|
192
309
|
} else {
|
|
193
310
|
nextProperties.pageNumbering = {
|
|
194
|
-
...target.properties?.pageNumbering ?? {},
|
|
195
|
-
...pageNumbering
|
|
311
|
+
...(target.properties?.pageNumbering ?? {}),
|
|
312
|
+
...pageNumbering,
|
|
196
313
|
};
|
|
197
314
|
}
|
|
315
|
+
|
|
198
316
|
if (target.kind === "inline") {
|
|
199
317
|
const breakNode = cloned.content.children[target.blockIndex];
|
|
200
318
|
if (breakNode && breakNode.type === "section_break") {
|
|
@@ -204,44 +322,59 @@ function setSectionPageNumberingAtSectionIndex(document, sectionIndex, pageNumbe
|
|
|
204
322
|
}
|
|
205
323
|
} else {
|
|
206
324
|
cloned.subParts = {
|
|
207
|
-
...cloned.subParts ?? {
|
|
325
|
+
...(cloned.subParts ?? {
|
|
208
326
|
headers: [],
|
|
209
|
-
footers: []
|
|
210
|
-
},
|
|
211
|
-
finalSectionProperties: nextProperties
|
|
327
|
+
footers: [],
|
|
328
|
+
}),
|
|
329
|
+
finalSectionProperties: nextProperties,
|
|
212
330
|
};
|
|
213
331
|
}
|
|
332
|
+
|
|
214
333
|
cloned.updatedAt = context.timestamp;
|
|
215
334
|
return {
|
|
216
335
|
document: cloned,
|
|
217
336
|
selection: createSelectionSnapshot(0, 0),
|
|
218
|
-
changed: true
|
|
337
|
+
changed: true,
|
|
219
338
|
};
|
|
220
339
|
}
|
|
221
|
-
|
|
222
|
-
|
|
340
|
+
|
|
341
|
+
export function setHeaderFooterLinkAtSectionIndex(
|
|
342
|
+
document: CanonicalDocumentEnvelope,
|
|
343
|
+
sectionIndex: number,
|
|
344
|
+
patch: SectionLinkPatch,
|
|
345
|
+
context: SectionLayoutCommandContext,
|
|
346
|
+
): SectionLayoutMutationResult {
|
|
347
|
+
const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
|
|
223
348
|
const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
|
|
224
349
|
if (!target) {
|
|
225
350
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
226
351
|
}
|
|
227
|
-
|
|
352
|
+
|
|
353
|
+
const referencesKey =
|
|
354
|
+
patch.kind === "header" ? "headerReferences" : "footerReferences";
|
|
228
355
|
const currentProperties = cloneSectionProperties(target.properties);
|
|
229
|
-
const currentReferences = [...currentProperties?.[referencesKey] ?? []];
|
|
356
|
+
const currentReferences = [...(currentProperties?.[referencesKey] ?? [])];
|
|
230
357
|
const nextReferences = currentReferences.filter((entry) => entry.variant !== patch.variant);
|
|
358
|
+
|
|
231
359
|
if (!patch.linkToPrevious) {
|
|
232
|
-
const relationshipId =
|
|
360
|
+
const relationshipId =
|
|
361
|
+
normalizeRelationshipId(patch.relationshipId) ??
|
|
362
|
+
resolveInheritedRelationshipId(cloned, sectionIndex, patch.kind, patch.variant);
|
|
233
363
|
if (!relationshipId) {
|
|
234
364
|
return noopResult(document, createSelectionSnapshot(0, 0));
|
|
235
365
|
}
|
|
366
|
+
|
|
236
367
|
nextReferences.push({
|
|
237
368
|
variant: patch.variant,
|
|
238
|
-
relationshipId
|
|
369
|
+
relationshipId,
|
|
239
370
|
});
|
|
240
371
|
}
|
|
372
|
+
|
|
241
373
|
const nextProperties = {
|
|
242
|
-
...currentProperties ?? {},
|
|
243
|
-
[referencesKey]: nextReferences.length > 0 ? nextReferences :
|
|
374
|
+
...(currentProperties ?? {}),
|
|
375
|
+
[referencesKey]: nextReferences.length > 0 ? nextReferences : undefined,
|
|
244
376
|
};
|
|
377
|
+
|
|
245
378
|
if (target.kind === "inline") {
|
|
246
379
|
const breakNode = cloned.content.children[target.blockIndex];
|
|
247
380
|
if (breakNode && breakNode.type === "section_break") {
|
|
@@ -251,24 +384,32 @@ function setHeaderFooterLinkAtSectionIndex(document, sectionIndex, patch, contex
|
|
|
251
384
|
}
|
|
252
385
|
} else {
|
|
253
386
|
cloned.subParts = {
|
|
254
|
-
...cloned.subParts ?? {
|
|
387
|
+
...(cloned.subParts ?? {
|
|
255
388
|
headers: [],
|
|
256
|
-
footers: []
|
|
257
|
-
},
|
|
258
|
-
finalSectionProperties: nextProperties
|
|
389
|
+
footers: [],
|
|
390
|
+
}),
|
|
391
|
+
finalSectionProperties: nextProperties,
|
|
259
392
|
};
|
|
260
393
|
}
|
|
394
|
+
|
|
261
395
|
cloned.updatedAt = context.timestamp;
|
|
262
396
|
return {
|
|
263
397
|
document: cloned,
|
|
264
398
|
selection: createSelectionSnapshot(0, 0),
|
|
265
|
-
changed: true
|
|
399
|
+
changed: true,
|
|
266
400
|
};
|
|
267
401
|
}
|
|
268
|
-
|
|
402
|
+
|
|
403
|
+
// ---- Helpers ----
|
|
404
|
+
|
|
405
|
+
function noopResult(
|
|
406
|
+
document: CanonicalDocumentEnvelope,
|
|
407
|
+
selection: SelectionSnapshot,
|
|
408
|
+
): SectionLayoutMutationResult {
|
|
269
409
|
return { document, selection, changed: false };
|
|
270
410
|
}
|
|
271
|
-
|
|
411
|
+
|
|
412
|
+
function createSelectionSnapshot(anchor: number, head: number): SelectionSnapshot {
|
|
272
413
|
return {
|
|
273
414
|
anchor,
|
|
274
415
|
head,
|
|
@@ -279,12 +420,16 @@ function createSelectionSnapshot(anchor, head) {
|
|
|
279
420
|
to: Math.max(anchor, head),
|
|
280
421
|
assoc: {
|
|
281
422
|
start: -1,
|
|
282
|
-
end: 1
|
|
283
|
-
}
|
|
284
|
-
}
|
|
423
|
+
end: 1,
|
|
424
|
+
},
|
|
425
|
+
},
|
|
285
426
|
};
|
|
286
427
|
}
|
|
287
|
-
|
|
428
|
+
|
|
429
|
+
function resolveBlockIndexForPosition(
|
|
430
|
+
blocks: ReadonlyArray<{ from: number; to: number }>,
|
|
431
|
+
position: number,
|
|
432
|
+
): number {
|
|
288
433
|
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
289
434
|
const block = blocks[i];
|
|
290
435
|
if (block && position >= block.from) {
|
|
@@ -293,10 +438,21 @@ function resolveBlockIndexForPosition(blocks, position) {
|
|
|
293
438
|
}
|
|
294
439
|
return blocks.length > 0 ? 0 : -1;
|
|
295
440
|
}
|
|
296
|
-
|
|
441
|
+
|
|
442
|
+
interface SectionTarget {
|
|
443
|
+
kind: "inline" | "final";
|
|
444
|
+
blockIndex: number;
|
|
445
|
+
properties?: SectionProperties;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function findSectionBreakNodeIndexForSection(
|
|
449
|
+
document: CanonicalDocumentEnvelope,
|
|
450
|
+
sectionIndex: number,
|
|
451
|
+
): number {
|
|
297
452
|
if (sectionIndex <= 0) {
|
|
298
453
|
return -1;
|
|
299
454
|
}
|
|
455
|
+
|
|
300
456
|
let currentSection = 0;
|
|
301
457
|
for (let index = 0; index < document.content.children.length; index += 1) {
|
|
302
458
|
const block = document.content.children[index];
|
|
@@ -308,9 +464,14 @@ function findSectionBreakNodeIndexForSection(document, sectionIndex) {
|
|
|
308
464
|
return index;
|
|
309
465
|
}
|
|
310
466
|
}
|
|
467
|
+
|
|
311
468
|
return -1;
|
|
312
469
|
}
|
|
313
|
-
|
|
470
|
+
|
|
471
|
+
function findSectionInsertionIndex(
|
|
472
|
+
document: CanonicalDocumentEnvelope,
|
|
473
|
+
sectionIndex: number,
|
|
474
|
+
): number {
|
|
314
475
|
let currentSection = 0;
|
|
315
476
|
for (let index = 0; index < document.content.children.length; index += 1) {
|
|
316
477
|
const block = document.content.children[index];
|
|
@@ -322,16 +483,26 @@ function findSectionInsertionIndex(document, sectionIndex) {
|
|
|
322
483
|
}
|
|
323
484
|
currentSection += 1;
|
|
324
485
|
}
|
|
486
|
+
|
|
325
487
|
return sectionIndex === currentSection ? document.content.children.length : -1;
|
|
326
488
|
}
|
|
327
|
-
|
|
489
|
+
|
|
490
|
+
function getSectionPropertiesAtIndex(
|
|
491
|
+
document: CanonicalDocumentEnvelope,
|
|
492
|
+
sectionIndex: number,
|
|
493
|
+
): SectionProperties | undefined {
|
|
328
494
|
const target = resolveSectionPropertiesOwner(document, sectionIndex);
|
|
329
495
|
return target?.properties;
|
|
330
496
|
}
|
|
331
|
-
|
|
497
|
+
|
|
498
|
+
function resolveSectionPropertiesOwner(
|
|
499
|
+
document: CanonicalDocumentEnvelope,
|
|
500
|
+
sectionIndex: number,
|
|
501
|
+
): SectionTarget | null {
|
|
332
502
|
if (sectionIndex < 0) {
|
|
333
503
|
return null;
|
|
334
504
|
}
|
|
505
|
+
|
|
335
506
|
let currentSection = 0;
|
|
336
507
|
for (let index = 0; index < document.content.children.length; index += 1) {
|
|
337
508
|
const block = document.content.children[index];
|
|
@@ -342,65 +513,94 @@ function resolveSectionPropertiesOwner(document, sectionIndex) {
|
|
|
342
513
|
return {
|
|
343
514
|
kind: "inline",
|
|
344
515
|
blockIndex: index,
|
|
345
|
-
properties: block.sectionProperties
|
|
516
|
+
properties: block.sectionProperties,
|
|
346
517
|
};
|
|
347
518
|
}
|
|
348
519
|
currentSection += 1;
|
|
349
520
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
521
|
+
|
|
522
|
+
return currentSection === sectionIndex
|
|
523
|
+
? {
|
|
524
|
+
kind: "final",
|
|
525
|
+
blockIndex: document.content.children.length - 1,
|
|
526
|
+
properties: document.subParts?.finalSectionProperties,
|
|
527
|
+
}
|
|
528
|
+
: null;
|
|
355
529
|
}
|
|
356
|
-
|
|
530
|
+
|
|
531
|
+
function normalizeRelationshipId(value: string | null | undefined): string | undefined {
|
|
357
532
|
if (typeof value !== "string") {
|
|
358
|
-
return
|
|
533
|
+
return undefined;
|
|
359
534
|
}
|
|
360
535
|
const trimmed = value.trim();
|
|
361
|
-
return trimmed.length > 0 ? trimmed :
|
|
536
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
362
537
|
}
|
|
363
|
-
|
|
538
|
+
|
|
539
|
+
function resolveInheritedRelationshipId(
|
|
540
|
+
document: CanonicalDocumentEnvelope,
|
|
541
|
+
sectionIndex: number,
|
|
542
|
+
kind: "header" | "footer",
|
|
543
|
+
variant: "default" | "first" | "even",
|
|
544
|
+
): string | undefined {
|
|
364
545
|
for (let candidateIndex = sectionIndex - 1; candidateIndex >= 0; candidateIndex -= 1) {
|
|
365
546
|
const properties = getSectionPropertiesAtIndex(document, candidateIndex);
|
|
366
|
-
const references =
|
|
547
|
+
const references =
|
|
548
|
+
kind === "header" ? properties?.headerReferences : properties?.footerReferences;
|
|
367
549
|
const directMatch = references?.find((entry) => entry.variant === variant);
|
|
368
550
|
if (directMatch?.relationshipId) {
|
|
369
551
|
return directMatch.relationshipId;
|
|
370
552
|
}
|
|
371
553
|
}
|
|
372
|
-
|
|
554
|
+
|
|
555
|
+
const documents = kind === "header"
|
|
556
|
+
? document.subParts?.headers ?? []
|
|
557
|
+
: document.subParts?.footers ?? [];
|
|
373
558
|
return documents.find((entry) => entry.variant === variant)?.relationshipId;
|
|
374
559
|
}
|
|
375
|
-
|
|
560
|
+
|
|
561
|
+
function resolveSectionTarget(
|
|
562
|
+
document: CanonicalDocumentEnvelope,
|
|
563
|
+
blocks: ReadonlyArray<{ from: number; to: number }>,
|
|
564
|
+
position: number,
|
|
565
|
+
): SectionTarget | null {
|
|
376
566
|
const blockIndex = resolveBlockIndexForPosition(blocks, position);
|
|
377
567
|
if (blockIndex < 0) {
|
|
378
568
|
return null;
|
|
379
569
|
}
|
|
570
|
+
|
|
571
|
+
// Walk forward from the resolved block to find the next section break
|
|
380
572
|
for (let i = blockIndex; i < document.content.children.length; i++) {
|
|
381
573
|
const block = document.content.children[i];
|
|
382
574
|
if (block && block.type === "section_break") {
|
|
383
575
|
return {
|
|
384
576
|
kind: "inline",
|
|
385
577
|
blockIndex: i,
|
|
386
|
-
properties: block.sectionProperties
|
|
578
|
+
properties: block.sectionProperties,
|
|
387
579
|
};
|
|
388
580
|
}
|
|
389
581
|
}
|
|
582
|
+
|
|
583
|
+
// No section break found; this is the final section
|
|
390
584
|
return {
|
|
391
585
|
kind: "final",
|
|
392
586
|
blockIndex: document.content.children.length - 1,
|
|
393
|
-
properties: document.subParts?.finalSectionProperties
|
|
587
|
+
properties: document.subParts?.finalSectionProperties,
|
|
394
588
|
};
|
|
395
589
|
}
|
|
396
|
-
|
|
590
|
+
|
|
591
|
+
function findNearestSectionBreak(
|
|
592
|
+
document: CanonicalDocumentEnvelope,
|
|
593
|
+
snapshot: RuntimeRenderSnapshot,
|
|
594
|
+
): number {
|
|
397
595
|
const surface = snapshot.surface;
|
|
398
596
|
if (!surface) {
|
|
399
597
|
return -1;
|
|
400
598
|
}
|
|
599
|
+
|
|
401
600
|
const position = snapshot.selection.head;
|
|
402
601
|
let bestIndex = -1;
|
|
403
602
|
let bestDistance = Number.POSITIVE_INFINITY;
|
|
603
|
+
|
|
404
604
|
for (let i = 0; i < document.content.children.length; i++) {
|
|
405
605
|
const block = document.content.children[i];
|
|
406
606
|
if (!block || block.type !== "section_break") {
|
|
@@ -412,66 +612,69 @@ function findNearestSectionBreak(document, snapshot) {
|
|
|
412
612
|
}
|
|
413
613
|
const distance = Math.min(
|
|
414
614
|
Math.abs(position - surfaceBlock.from),
|
|
415
|
-
Math.abs(position - surfaceBlock.to)
|
|
615
|
+
Math.abs(position - surfaceBlock.to),
|
|
416
616
|
);
|
|
417
617
|
if (distance < bestDistance) {
|
|
418
618
|
bestDistance = distance;
|
|
419
619
|
bestIndex = i;
|
|
420
620
|
}
|
|
421
621
|
}
|
|
622
|
+
|
|
422
623
|
return bestIndex;
|
|
423
624
|
}
|
|
424
|
-
|
|
425
|
-
|
|
625
|
+
|
|
626
|
+
function applySectionLayoutPatch(
|
|
627
|
+
existing: SectionProperties,
|
|
628
|
+
patch: SectionLayoutPatch,
|
|
629
|
+
): SectionProperties {
|
|
630
|
+
const result: SectionProperties = { ...existing };
|
|
631
|
+
|
|
426
632
|
if (patch.pageSize) {
|
|
427
633
|
result.pageSize = {
|
|
428
|
-
...existing.pageSize ?? { width: 12240, height: 15840 },
|
|
429
|
-
...patch.pageSize
|
|
634
|
+
...(existing.pageSize ?? { width: 12240, height: 15840 }),
|
|
635
|
+
...patch.pageSize,
|
|
430
636
|
};
|
|
431
637
|
}
|
|
638
|
+
|
|
432
639
|
if (patch.pageMargins) {
|
|
433
640
|
result.pageMargins = {
|
|
434
|
-
...existing.pageMargins ?? {
|
|
641
|
+
...(existing.pageMargins ?? {
|
|
435
642
|
top: 1440,
|
|
436
643
|
right: 1440,
|
|
437
644
|
bottom: 1440,
|
|
438
|
-
left: 1440
|
|
439
|
-
},
|
|
440
|
-
...patch.pageMargins
|
|
645
|
+
left: 1440,
|
|
646
|
+
}),
|
|
647
|
+
...patch.pageMargins,
|
|
441
648
|
};
|
|
442
649
|
}
|
|
650
|
+
|
|
443
651
|
if (patch.columns) {
|
|
444
652
|
result.columns = {
|
|
445
|
-
...existing.columns ?? {},
|
|
446
|
-
...patch.columns
|
|
653
|
+
...(existing.columns ?? {}),
|
|
654
|
+
...patch.columns,
|
|
447
655
|
};
|
|
448
656
|
}
|
|
657
|
+
|
|
449
658
|
if (patch.pageNumbering) {
|
|
450
659
|
result.pageNumbering = {
|
|
451
|
-
...existing.pageNumbering ?? {},
|
|
452
|
-
...patch.pageNumbering
|
|
660
|
+
...(existing.pageNumbering ?? {}),
|
|
661
|
+
...patch.pageNumbering,
|
|
453
662
|
};
|
|
454
663
|
}
|
|
455
|
-
|
|
664
|
+
|
|
665
|
+
if (patch.titlePage !== undefined) {
|
|
456
666
|
result.titlePage = patch.titlePage;
|
|
457
667
|
}
|
|
458
|
-
|
|
668
|
+
|
|
669
|
+
if (patch.sectionType !== undefined) {
|
|
459
670
|
result.sectionType = patch.sectionType;
|
|
460
671
|
}
|
|
672
|
+
|
|
461
673
|
return result;
|
|
462
674
|
}
|
|
463
|
-
|
|
675
|
+
|
|
676
|
+
function cloneSectionProperties(
|
|
677
|
+
properties: SectionProperties | undefined,
|
|
678
|
+
): SectionProperties {
|
|
464
679
|
return properties ? structuredClone(properties) : {};
|
|
465
680
|
}
|
|
466
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
467
|
-
0 && (module.exports = {
|
|
468
|
-
deleteSectionBreak,
|
|
469
|
-
deleteSectionBreakAtSectionIndex,
|
|
470
|
-
insertSectionBreak,
|
|
471
|
-
insertSectionBreakAfterSectionIndex,
|
|
472
|
-
setHeaderFooterLinkAtSectionIndex,
|
|
473
|
-
setSectionPageNumberingAtSectionIndex,
|
|
474
|
-
updateSectionLayout,
|
|
475
|
-
updateSectionLayoutAtSectionIndex
|
|
476
|
-
});
|
|
477
|
-
//# sourceMappingURL=section-layout-commands.cjs.map
|