@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,828 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/core/commands/formatting-commands.ts
|
|
21
|
-
var formatting_commands_exports = {};
|
|
22
|
-
__export(formatting_commands_exports, {
|
|
23
|
-
applyFormattingOperationToDocument: () => applyFormattingOperationToDocument,
|
|
24
|
-
getFormattingStateFromRenderSnapshot: () => getFormattingStateFromRenderSnapshot,
|
|
25
|
-
isMarkActive: () => isMarkActive,
|
|
26
|
-
makeSetAlignment: () => makeSetAlignment,
|
|
27
|
-
makeSetFontFamily: () => makeSetFontFamily,
|
|
28
|
-
makeSetFontSize: () => makeSetFontSize,
|
|
29
|
-
makeSetHighlight: () => makeSetHighlight,
|
|
30
|
-
makeSetTextColor: () => makeSetTextColor,
|
|
31
|
-
makeToggleAllCaps: () => makeToggleAllCaps,
|
|
32
|
-
makeToggleBold: () => makeToggleBold,
|
|
33
|
-
makeToggleItalic: () => makeToggleItalic,
|
|
34
|
-
makeToggleSmallCaps: () => makeToggleSmallCaps,
|
|
35
|
-
makeToggleStrikethrough: () => makeToggleStrikethrough,
|
|
36
|
-
makeToggleSubscript: () => makeToggleSubscript,
|
|
37
|
-
makeToggleSuperscript: () => makeToggleSuperscript,
|
|
38
|
-
makeToggleUnderline: () => makeToggleUnderline
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(formatting_commands_exports);
|
|
41
|
-
var import_prosemirror_commands = require("prosemirror-commands");
|
|
42
|
-
function makeToggleBold(schema) {
|
|
43
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.bold);
|
|
44
|
-
}
|
|
45
|
-
function makeToggleItalic(schema) {
|
|
46
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.italic);
|
|
47
|
-
}
|
|
48
|
-
function makeToggleUnderline(schema) {
|
|
49
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.underline);
|
|
50
|
-
}
|
|
51
|
-
function makeToggleStrikethrough(schema) {
|
|
52
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.strikethrough);
|
|
53
|
-
}
|
|
54
|
-
function makeToggleSuperscript(schema) {
|
|
55
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.superscript);
|
|
56
|
-
}
|
|
57
|
-
function makeToggleSubscript(schema) {
|
|
58
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.subscript);
|
|
59
|
-
}
|
|
60
|
-
function makeToggleSmallCaps(schema) {
|
|
61
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.small_caps);
|
|
62
|
-
}
|
|
63
|
-
function makeToggleAllCaps(schema) {
|
|
64
|
-
return (0, import_prosemirror_commands.toggleMark)(schema.marks.all_caps);
|
|
65
|
-
}
|
|
66
|
-
function makeSetValueMark(markType, attrKey, value) {
|
|
67
|
-
return (state, dispatch) => {
|
|
68
|
-
const { from, to, empty } = state.selection;
|
|
69
|
-
if (empty) return false;
|
|
70
|
-
if (!dispatch) return true;
|
|
71
|
-
const tr = state.tr;
|
|
72
|
-
if (value === null) {
|
|
73
|
-
tr.removeMark(from, to, markType);
|
|
74
|
-
} else {
|
|
75
|
-
const mark = markType.create({ [attrKey]: value });
|
|
76
|
-
tr.addMark(from, to, mark);
|
|
77
|
-
}
|
|
78
|
-
dispatch(tr);
|
|
79
|
-
return true;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function makeSetFontFamily(schema, family) {
|
|
83
|
-
return makeSetValueMark(schema.marks.font_family, "family", family);
|
|
84
|
-
}
|
|
85
|
-
function makeSetFontSize(schema, size) {
|
|
86
|
-
return makeSetValueMark(schema.marks.font_size, "size", size);
|
|
87
|
-
}
|
|
88
|
-
function makeSetTextColor(schema, color) {
|
|
89
|
-
return makeSetValueMark(schema.marks.text_color, "color", color);
|
|
90
|
-
}
|
|
91
|
-
function makeSetHighlight(schema, color) {
|
|
92
|
-
return makeSetValueMark(schema.marks.highlight, "color", color);
|
|
93
|
-
}
|
|
94
|
-
function makeSetAlignment(schema, alignment) {
|
|
95
|
-
return (state, dispatch) => {
|
|
96
|
-
const { from, to } = state.selection;
|
|
97
|
-
if (!dispatch) return true;
|
|
98
|
-
const tr = state.tr;
|
|
99
|
-
let applied = false;
|
|
100
|
-
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
101
|
-
if (node.type === schema.nodes.paragraph) {
|
|
102
|
-
tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment });
|
|
103
|
-
applied = true;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
if (!applied) return false;
|
|
107
|
-
dispatch(tr);
|
|
108
|
-
return true;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function isMarkActive(schema, markName, state) {
|
|
112
|
-
const markType = schema.marks[markName];
|
|
113
|
-
if (!markType) return false;
|
|
114
|
-
const { from, to, empty } = state.selection;
|
|
115
|
-
if (empty) {
|
|
116
|
-
return Boolean(markType.isInSet(state.storedMarks ?? state.selection.$from.marks()));
|
|
117
|
-
}
|
|
118
|
-
let active = true;
|
|
119
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
120
|
-
if (node.isText && !markType.isInSet(node.marks)) {
|
|
121
|
-
active = false;
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return active;
|
|
126
|
-
}
|
|
127
|
-
var DEFAULT_FORMATTING_STATE = {
|
|
128
|
-
bold: false,
|
|
129
|
-
italic: false,
|
|
130
|
-
underline: false,
|
|
131
|
-
strikethrough: false,
|
|
132
|
-
superscript: false,
|
|
133
|
-
subscript: false,
|
|
134
|
-
breadcrumb: []
|
|
135
|
-
};
|
|
136
|
-
var INDENT_STEP_TWIPS = 720;
|
|
137
|
-
function getFormattingStateFromRenderSnapshot(snapshot) {
|
|
138
|
-
const surface = snapshot.surface;
|
|
139
|
-
if (!surface) {
|
|
140
|
-
return { ...DEFAULT_FORMATTING_STATE };
|
|
141
|
-
}
|
|
142
|
-
const paragraphs = collectParagraphSurfaces(surface.blocks).filter(
|
|
143
|
-
(paragraph) => selectionTouchesRange(
|
|
144
|
-
snapshot.selection.anchor,
|
|
145
|
-
snapshot.selection.head,
|
|
146
|
-
paragraph.from,
|
|
147
|
-
paragraph.to
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
const textSegments = collectFormattingTextSegments(paragraphs, snapshot.selection);
|
|
151
|
-
return {
|
|
152
|
-
bold: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "bold")) : false,
|
|
153
|
-
italic: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "italic")) : false,
|
|
154
|
-
underline: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "underline")) : false,
|
|
155
|
-
strikethrough: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "strikethrough")) : false,
|
|
156
|
-
superscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "superscript")) : false,
|
|
157
|
-
subscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "subscript")) : false,
|
|
158
|
-
fontFamily: getConsistentValue(textSegments, (segment) => segment.markAttrs?.fontFamily),
|
|
159
|
-
fontSize: getConsistentValue(textSegments, (segment) => {
|
|
160
|
-
const size = segment.markAttrs?.fontSize;
|
|
161
|
-
return typeof size === "number" ? size / 2 : void 0;
|
|
162
|
-
}),
|
|
163
|
-
textColor: getConsistentValue(
|
|
164
|
-
textSegments,
|
|
165
|
-
(segment) => toPublicColor(segment.markAttrs?.textColor)
|
|
166
|
-
),
|
|
167
|
-
highlightColor: getConsistentValue(
|
|
168
|
-
textSegments,
|
|
169
|
-
(segment) => toPublicColor(segment.markAttrs?.backgroundColor) ?? null,
|
|
170
|
-
{
|
|
171
|
-
emptyFallback: null
|
|
172
|
-
}
|
|
173
|
-
),
|
|
174
|
-
alignment: getConsistentValue(
|
|
175
|
-
paragraphs,
|
|
176
|
-
(paragraph) => toPublicAlignment(paragraph.alignment)
|
|
177
|
-
),
|
|
178
|
-
paragraphStyleId: getConsistentValue(paragraphs, (paragraph) => paragraph.styleId),
|
|
179
|
-
breadcrumb: getSelectionBreadcrumb(surface.blocks, snapshot.selection)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function getSelectionBreadcrumb(blocks, selection) {
|
|
183
|
-
const paths = collectSelectionBreadcrumbPaths(blocks, selection);
|
|
184
|
-
if (paths.length === 0) {
|
|
185
|
-
return [];
|
|
186
|
-
}
|
|
187
|
-
let commonLength = paths[0]?.length ?? 0;
|
|
188
|
-
for (let pathIndex = 1; pathIndex < paths.length; pathIndex += 1) {
|
|
189
|
-
const currentPath = paths[pathIndex] ?? [];
|
|
190
|
-
commonLength = Math.min(commonLength, currentPath.length);
|
|
191
|
-
let compareIndex = 0;
|
|
192
|
-
while (compareIndex < commonLength && breadcrumbItemsEqual(paths[0][compareIndex], currentPath[compareIndex])) {
|
|
193
|
-
compareIndex += 1;
|
|
194
|
-
}
|
|
195
|
-
commonLength = compareIndex;
|
|
196
|
-
}
|
|
197
|
-
return paths[0].slice(0, commonLength);
|
|
198
|
-
}
|
|
199
|
-
function collectSelectionBreadcrumbPaths(blocks, selection, path = [], output = []) {
|
|
200
|
-
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
|
|
201
|
-
const block = blocks[blockIndex];
|
|
202
|
-
if (!block) {
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
if (!selectionTouchesRange(
|
|
206
|
-
selection.anchor,
|
|
207
|
-
selection.head,
|
|
208
|
-
block.from,
|
|
209
|
-
block.to
|
|
210
|
-
)) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
if (block.kind === "paragraph") {
|
|
214
|
-
output.push([
|
|
215
|
-
...path,
|
|
216
|
-
{
|
|
217
|
-
kind: "paragraph",
|
|
218
|
-
label: block.styleId ? `Paragraph (${block.styleId})` : "Paragraph",
|
|
219
|
-
from: block.from,
|
|
220
|
-
to: block.to
|
|
221
|
-
}
|
|
222
|
-
]);
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if (block.kind === "opaque_block") {
|
|
226
|
-
output.push([
|
|
227
|
-
...path,
|
|
228
|
-
{
|
|
229
|
-
kind: "opaque_block",
|
|
230
|
-
label: block.label,
|
|
231
|
-
from: block.from,
|
|
232
|
-
to: block.to
|
|
233
|
-
}
|
|
234
|
-
]);
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (block.kind === "sdt_block") {
|
|
238
|
-
collectSelectionBreadcrumbPaths(
|
|
239
|
-
block.children,
|
|
240
|
-
selection,
|
|
241
|
-
[
|
|
242
|
-
...path,
|
|
243
|
-
{
|
|
244
|
-
kind: "sdt_block",
|
|
245
|
-
label: block.alias ?? block.tag ?? block.sdtType ?? "Content control",
|
|
246
|
-
from: block.from,
|
|
247
|
-
to: block.to
|
|
248
|
-
}
|
|
249
|
-
],
|
|
250
|
-
output
|
|
251
|
-
);
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (block.kind === "table") {
|
|
255
|
-
const tablePath = [
|
|
256
|
-
...path,
|
|
257
|
-
{
|
|
258
|
-
kind: "table",
|
|
259
|
-
label: block.styleId ? `Table (${block.styleId})` : "Table",
|
|
260
|
-
from: block.from,
|
|
261
|
-
to: block.to
|
|
262
|
-
}
|
|
263
|
-
];
|
|
264
|
-
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
|
|
265
|
-
const row = block.rows[rowIndex];
|
|
266
|
-
if (!row) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
const rowRange = getTableRowRange(block, row);
|
|
270
|
-
if (!selectionTouchesRange(
|
|
271
|
-
selection.anchor,
|
|
272
|
-
selection.head,
|
|
273
|
-
rowRange.from,
|
|
274
|
-
rowRange.to
|
|
275
|
-
)) {
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
const rowPath = [
|
|
279
|
-
...tablePath,
|
|
280
|
-
{
|
|
281
|
-
kind: "table_row",
|
|
282
|
-
label: `Row ${rowIndex + 1}`,
|
|
283
|
-
from: rowRange.from,
|
|
284
|
-
to: rowRange.to
|
|
285
|
-
}
|
|
286
|
-
];
|
|
287
|
-
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
288
|
-
const cell = row.cells[cellIndex];
|
|
289
|
-
if (!cell) {
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
const cellRange = getTableCellRange(block, cell);
|
|
293
|
-
if (!selectionTouchesRange(
|
|
294
|
-
selection.anchor,
|
|
295
|
-
selection.head,
|
|
296
|
-
cellRange.from,
|
|
297
|
-
cellRange.to
|
|
298
|
-
)) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
collectSelectionBreadcrumbPaths(
|
|
302
|
-
cell.content,
|
|
303
|
-
selection,
|
|
304
|
-
[
|
|
305
|
-
...rowPath,
|
|
306
|
-
{
|
|
307
|
-
kind: "table_cell",
|
|
308
|
-
label: `Cell ${cellIndex + 1}`,
|
|
309
|
-
from: cellRange.from,
|
|
310
|
-
to: cellRange.to
|
|
311
|
-
}
|
|
312
|
-
],
|
|
313
|
-
output
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return output;
|
|
320
|
-
}
|
|
321
|
-
function getTableRowRange(table, row) {
|
|
322
|
-
let from = Number.POSITIVE_INFINITY;
|
|
323
|
-
let to = Number.NEGATIVE_INFINITY;
|
|
324
|
-
for (const cell of row.cells) {
|
|
325
|
-
const range = getTableCellRange(table, cell);
|
|
326
|
-
from = Math.min(from, range.from);
|
|
327
|
-
to = Math.max(to, range.to);
|
|
328
|
-
}
|
|
329
|
-
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
330
|
-
}
|
|
331
|
-
function getTableCellRange(table, cell) {
|
|
332
|
-
if (cell.content.length === 0) {
|
|
333
|
-
return { from: table.from, to: table.to };
|
|
334
|
-
}
|
|
335
|
-
let from = Number.POSITIVE_INFINITY;
|
|
336
|
-
let to = Number.NEGATIVE_INFINITY;
|
|
337
|
-
for (const child of cell.content) {
|
|
338
|
-
from = Math.min(from, child.from);
|
|
339
|
-
to = Math.max(to, child.to);
|
|
340
|
-
}
|
|
341
|
-
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
342
|
-
}
|
|
343
|
-
function breadcrumbItemsEqual(left, right) {
|
|
344
|
-
return left.kind === right.kind && left.label === right.label && left.from === right.from && left.to === right.to;
|
|
345
|
-
}
|
|
346
|
-
function applyFormattingOperationToDocument(document, snapshot, operation) {
|
|
347
|
-
const surface = snapshot.surface;
|
|
348
|
-
if (!surface) {
|
|
349
|
-
return {
|
|
350
|
-
document,
|
|
351
|
-
selection: snapshot.selection,
|
|
352
|
-
changed: false
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
const nextDocument = structuredClone(document);
|
|
356
|
-
const root = nextDocument.content;
|
|
357
|
-
let changed = false;
|
|
358
|
-
const selectionFrom = Math.min(snapshot.selection.anchor, snapshot.selection.head);
|
|
359
|
-
const selectionTo = Math.max(snapshot.selection.anchor, snapshot.selection.head);
|
|
360
|
-
if (operation.type === "set-alignment" || operation.type === "indent" || operation.type === "outdent") {
|
|
361
|
-
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
362
|
-
if (!selectionTouchesRange(
|
|
363
|
-
snapshot.selection.anchor,
|
|
364
|
-
snapshot.selection.head,
|
|
365
|
-
paragraphSurface.from,
|
|
366
|
-
paragraphSurface.to
|
|
367
|
-
)) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
const paragraphChanged = operation.type === "set-alignment" ? applyAlignment(paragraph, operation.alignment) : applyIndentation(paragraph, operation.type === "indent" ? 1 : -1);
|
|
371
|
-
changed = changed || paragraphChanged;
|
|
372
|
-
});
|
|
373
|
-
return {
|
|
374
|
-
document: changed ? nextDocument : document,
|
|
375
|
-
selection: snapshot.selection,
|
|
376
|
-
changed
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
if (selectionFrom === selectionTo) {
|
|
380
|
-
return {
|
|
381
|
-
document,
|
|
382
|
-
selection: snapshot.selection,
|
|
383
|
-
changed: false
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
const nextMarks = resolveMarkUpdater(snapshot, operation);
|
|
387
|
-
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
388
|
-
if (!rangesOverlap(
|
|
389
|
-
selectionFrom,
|
|
390
|
-
selectionTo,
|
|
391
|
-
paragraphSurface.from,
|
|
392
|
-
paragraphSurface.to
|
|
393
|
-
)) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const transformed = transformInlineNodes(
|
|
397
|
-
paragraph.children,
|
|
398
|
-
paragraphSurface.from,
|
|
399
|
-
selectionFrom,
|
|
400
|
-
selectionTo,
|
|
401
|
-
nextMarks
|
|
402
|
-
);
|
|
403
|
-
if (!transformed.changed) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
paragraph.children = transformed.nodes;
|
|
407
|
-
changed = true;
|
|
408
|
-
});
|
|
409
|
-
return {
|
|
410
|
-
document: changed ? nextDocument : document,
|
|
411
|
-
selection: snapshot.selection,
|
|
412
|
-
changed
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function resolveMarkUpdater(snapshot, operation) {
|
|
416
|
-
const formatting = getFormattingStateFromRenderSnapshot(snapshot);
|
|
417
|
-
switch (operation.type) {
|
|
418
|
-
case "toggle":
|
|
419
|
-
return (marks) => toggleMarks(marks, operation.mark, !formatting[operation.mark]);
|
|
420
|
-
case "set-font-family":
|
|
421
|
-
return (marks) => setMarkValue(marks, "fontFamily", sanitizeFontFamily(operation.fontFamily));
|
|
422
|
-
case "set-font-size":
|
|
423
|
-
return (marks) => setMarkValue(marks, "fontSize", sanitizeFontSize(operation.size));
|
|
424
|
-
case "set-text-color":
|
|
425
|
-
return (marks) => setMarkValue(marks, "textColor", sanitizeColor(operation.color));
|
|
426
|
-
case "set-highlight-color":
|
|
427
|
-
return (marks) => setMarkValue(marks, "backgroundColor", sanitizeColor(operation.color));
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function applyAlignment(paragraph, alignment) {
|
|
431
|
-
const nextAlignment = alignment === "justify" ? "both" : alignment;
|
|
432
|
-
if (paragraph.alignment === nextAlignment) {
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
paragraph.alignment = nextAlignment;
|
|
436
|
-
return true;
|
|
437
|
-
}
|
|
438
|
-
function applyIndentation(paragraph, delta) {
|
|
439
|
-
if (paragraph.numbering) {
|
|
440
|
-
const nextLevel = clamp(paragraph.numbering.level + delta, 0, 8);
|
|
441
|
-
if (nextLevel === paragraph.numbering.level) {
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
paragraph.numbering = {
|
|
445
|
-
...paragraph.numbering,
|
|
446
|
-
level: nextLevel
|
|
447
|
-
};
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
const currentLeft = paragraph.indentation?.left ?? 0;
|
|
451
|
-
const nextLeft = Math.max(0, currentLeft + delta * INDENT_STEP_TWIPS);
|
|
452
|
-
if (nextLeft === currentLeft) {
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
const nextIndentation = {
|
|
456
|
-
...paragraph.indentation ?? {}
|
|
457
|
-
};
|
|
458
|
-
if (nextLeft > 0) {
|
|
459
|
-
nextIndentation.left = nextLeft;
|
|
460
|
-
paragraph.indentation = nextIndentation;
|
|
461
|
-
} else if (paragraph.indentation) {
|
|
462
|
-
delete nextIndentation.left;
|
|
463
|
-
paragraph.indentation = Object.keys(nextIndentation).length > 0 ? nextIndentation : void 0;
|
|
464
|
-
}
|
|
465
|
-
return true;
|
|
466
|
-
}
|
|
467
|
-
function collectParagraphSurfaces(blocks, output = []) {
|
|
468
|
-
for (const block of blocks) {
|
|
469
|
-
if (block.kind === "paragraph") {
|
|
470
|
-
output.push(block);
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
if (block.kind === "table") {
|
|
474
|
-
for (const row of block.rows) {
|
|
475
|
-
for (const cell of row.cells) {
|
|
476
|
-
collectParagraphSurfaces(cell.content, output);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
if (block.kind === "sdt_block") {
|
|
482
|
-
collectParagraphSurfaces(block.children, output);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
return output;
|
|
486
|
-
}
|
|
487
|
-
function collectFormattingTextSegments(paragraphs, selection) {
|
|
488
|
-
const caret = selection.anchor;
|
|
489
|
-
const isCollapsed = selection.isCollapsed;
|
|
490
|
-
const selectionFrom = Math.min(selection.anchor, selection.head);
|
|
491
|
-
const selectionTo = Math.max(selection.anchor, selection.head);
|
|
492
|
-
const segments = [];
|
|
493
|
-
for (const paragraph of paragraphs) {
|
|
494
|
-
for (const segment of paragraph.segments) {
|
|
495
|
-
if (segment.kind !== "text") {
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
if (isCollapsed ? segmentContainsCaret(segment, caret) : rangesOverlap(selectionFrom, selectionTo, segment.from, segment.to)) {
|
|
499
|
-
segments.push(segment);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
if (!isCollapsed || segments.length > 0) {
|
|
504
|
-
return segments;
|
|
505
|
-
}
|
|
506
|
-
for (const paragraph of paragraphs) {
|
|
507
|
-
const fallback = paragraph.segments.find(
|
|
508
|
-
(segment) => segment.kind === "text" && segment.to === caret
|
|
509
|
-
);
|
|
510
|
-
if (fallback) {
|
|
511
|
-
return [fallback];
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return [];
|
|
515
|
-
}
|
|
516
|
-
function segmentContainsCaret(segment, caret) {
|
|
517
|
-
return segment.from <= caret && (caret < segment.to || segment.to === caret && segment.to > segment.from);
|
|
518
|
-
}
|
|
519
|
-
function segmentHasMark(segment, mark) {
|
|
520
|
-
const marks = segment.marks ?? [];
|
|
521
|
-
if (mark === "superscript") {
|
|
522
|
-
return marks.includes("superscript");
|
|
523
|
-
}
|
|
524
|
-
if (mark === "subscript") {
|
|
525
|
-
return marks.includes("subscript");
|
|
526
|
-
}
|
|
527
|
-
return marks.includes(mark);
|
|
528
|
-
}
|
|
529
|
-
function getConsistentValue(items, getter, options = {}) {
|
|
530
|
-
if (items.length === 0) {
|
|
531
|
-
return options.emptyFallback;
|
|
532
|
-
}
|
|
533
|
-
let value = void 0;
|
|
534
|
-
let initialized = false;
|
|
535
|
-
for (const item of items) {
|
|
536
|
-
const next = getter(item);
|
|
537
|
-
if (!initialized) {
|
|
538
|
-
value = next;
|
|
539
|
-
initialized = true;
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
if (next !== value) {
|
|
543
|
-
return void 0;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return value;
|
|
547
|
-
}
|
|
548
|
-
function visitParagraphBindings(blocks, surfaceBlocks, visitor) {
|
|
549
|
-
for (let index = 0; index < Math.min(blocks.length, surfaceBlocks.length); index += 1) {
|
|
550
|
-
const block = blocks[index];
|
|
551
|
-
const surface = surfaceBlocks[index];
|
|
552
|
-
if (!block || !surface) {
|
|
553
|
-
continue;
|
|
554
|
-
}
|
|
555
|
-
if (block.type === "paragraph" && surface.kind === "paragraph") {
|
|
556
|
-
visitor(block, surface);
|
|
557
|
-
continue;
|
|
558
|
-
}
|
|
559
|
-
if (block.type === "table" && surface.kind === "table") {
|
|
560
|
-
for (let rowIndex = 0; rowIndex < Math.min(block.rows.length, surface.rows.length); rowIndex += 1) {
|
|
561
|
-
const row = block.rows[rowIndex];
|
|
562
|
-
const surfaceRow = surface.rows[rowIndex];
|
|
563
|
-
if (!row || !surfaceRow) {
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
for (let cellIndex = 0; cellIndex < Math.min(row.cells.length, surfaceRow.cells.length); cellIndex += 1) {
|
|
567
|
-
const cell = row.cells[cellIndex];
|
|
568
|
-
const surfaceCell = surfaceRow.cells[cellIndex];
|
|
569
|
-
if (!cell || !surfaceCell) {
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
visitParagraphBindings(cell.children, surfaceCell.content, visitor);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
if (block.type === "sdt" && surface.kind === "sdt_block") {
|
|
578
|
-
visitParagraphBindings(block.children, surface.children, visitor);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function transformInlineNodes(nodes, start, selectionFrom, selectionTo, updateMarks) {
|
|
583
|
-
let changed = false;
|
|
584
|
-
let position = start;
|
|
585
|
-
const nextNodes = [];
|
|
586
|
-
for (const node of nodes) {
|
|
587
|
-
if (node.type === "text") {
|
|
588
|
-
const transformed = transformTextNode(
|
|
589
|
-
node,
|
|
590
|
-
position,
|
|
591
|
-
selectionFrom,
|
|
592
|
-
selectionTo,
|
|
593
|
-
updateMarks
|
|
594
|
-
);
|
|
595
|
-
nextNodes.push(...transformed.nodes);
|
|
596
|
-
position = transformed.nextPosition;
|
|
597
|
-
changed = changed || transformed.changed;
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
if (node.type === "hyperlink") {
|
|
601
|
-
const transformed = transformInlineNodes(
|
|
602
|
-
node.children,
|
|
603
|
-
position,
|
|
604
|
-
selectionFrom,
|
|
605
|
-
selectionTo,
|
|
606
|
-
updateMarks
|
|
607
|
-
);
|
|
608
|
-
nextNodes.push(
|
|
609
|
-
transformed.changed ? {
|
|
610
|
-
...node,
|
|
611
|
-
children: transformed.nodes
|
|
612
|
-
} : node
|
|
613
|
-
);
|
|
614
|
-
position = transformed.nextPosition;
|
|
615
|
-
changed = changed || transformed.changed;
|
|
616
|
-
continue;
|
|
617
|
-
}
|
|
618
|
-
nextNodes.push(node);
|
|
619
|
-
position += inlineNodeLength(node);
|
|
620
|
-
}
|
|
621
|
-
return {
|
|
622
|
-
nodes: nextNodes,
|
|
623
|
-
changed,
|
|
624
|
-
nextPosition: position
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function transformTextNode(node, start, selectionFrom, selectionTo, updateMarks) {
|
|
628
|
-
const characters = Array.from(node.text);
|
|
629
|
-
const end = start + characters.length;
|
|
630
|
-
const overlapFrom = Math.max(selectionFrom, start);
|
|
631
|
-
const overlapTo = Math.min(selectionTo, end);
|
|
632
|
-
if (overlapFrom >= overlapTo) {
|
|
633
|
-
return {
|
|
634
|
-
nodes: [node],
|
|
635
|
-
changed: false,
|
|
636
|
-
nextPosition: end
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
const localFrom = overlapFrom - start;
|
|
640
|
-
const localTo = overlapTo - start;
|
|
641
|
-
const nextNodes = [];
|
|
642
|
-
if (localFrom > 0) {
|
|
643
|
-
nextNodes.push(createTextNode(characters.slice(0, localFrom).join(""), node.marks));
|
|
644
|
-
}
|
|
645
|
-
const transformedMarks = updateMarks(node.marks);
|
|
646
|
-
nextNodes.push(
|
|
647
|
-
createTextNode(characters.slice(localFrom, localTo).join(""), transformedMarks)
|
|
648
|
-
);
|
|
649
|
-
if (localTo < characters.length) {
|
|
650
|
-
nextNodes.push(createTextNode(characters.slice(localTo).join(""), node.marks));
|
|
651
|
-
}
|
|
652
|
-
return {
|
|
653
|
-
nodes: nextNodes.filter((candidate) => candidate.text.length > 0),
|
|
654
|
-
changed: !marksEqual(node.marks, transformedMarks) || localFrom > 0 || localTo < characters.length,
|
|
655
|
-
nextPosition: end
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
function createTextNode(text, marks) {
|
|
659
|
-
return {
|
|
660
|
-
type: "text",
|
|
661
|
-
text,
|
|
662
|
-
...marks && marks.length > 0 ? { marks: cloneMarks(marks) } : {}
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
function toggleMarks(marks, mark, enabled) {
|
|
666
|
-
const nextMarks = cloneMarks(marks);
|
|
667
|
-
if (mark === "superscript" || mark === "subscript") {
|
|
668
|
-
const filtered2 = nextMarks.filter((candidate) => candidate.type !== "position");
|
|
669
|
-
if (enabled) {
|
|
670
|
-
filtered2.push({
|
|
671
|
-
type: "position",
|
|
672
|
-
val: mark === "superscript" ? 1 : -1
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
return filtered2.length > 0 ? filtered2 : void 0;
|
|
676
|
-
}
|
|
677
|
-
const filtered = nextMarks.filter((candidate) => candidate.type !== mark);
|
|
678
|
-
if (enabled) {
|
|
679
|
-
filtered.push({ type: mark });
|
|
680
|
-
}
|
|
681
|
-
return filtered.length > 0 ? filtered : void 0;
|
|
682
|
-
}
|
|
683
|
-
function setMarkValue(marks, markType, value) {
|
|
684
|
-
const nextMarks = cloneMarks(marks).filter((candidate) => {
|
|
685
|
-
if (markType === "backgroundColor") {
|
|
686
|
-
return candidate.type !== "backgroundColor" && candidate.type !== "highlight";
|
|
687
|
-
}
|
|
688
|
-
return candidate.type !== markType;
|
|
689
|
-
});
|
|
690
|
-
if (value !== null) {
|
|
691
|
-
switch (markType) {
|
|
692
|
-
case "fontFamily":
|
|
693
|
-
nextMarks.push({ type: "fontFamily", val: value });
|
|
694
|
-
break;
|
|
695
|
-
case "fontSize":
|
|
696
|
-
nextMarks.push({ type: "fontSize", val: value });
|
|
697
|
-
break;
|
|
698
|
-
case "textColor":
|
|
699
|
-
nextMarks.push({ type: "textColor", color: value });
|
|
700
|
-
break;
|
|
701
|
-
case "backgroundColor":
|
|
702
|
-
nextMarks.push({ type: "backgroundColor", color: value });
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
return nextMarks.length > 0 ? nextMarks : void 0;
|
|
707
|
-
}
|
|
708
|
-
function cloneMarks(marks) {
|
|
709
|
-
return marks ? marks.map((mark) => ({ ...mark })) : [];
|
|
710
|
-
}
|
|
711
|
-
function marksEqual(left, right) {
|
|
712
|
-
if (!left?.length && !right?.length) {
|
|
713
|
-
return true;
|
|
714
|
-
}
|
|
715
|
-
if (!left || !right || left.length !== right.length) {
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
|
-
return left.every((mark, index) => JSON.stringify(mark) === JSON.stringify(right[index]));
|
|
719
|
-
}
|
|
720
|
-
function inlineNodeLength(node) {
|
|
721
|
-
switch (node.type) {
|
|
722
|
-
case "text":
|
|
723
|
-
return Array.from(node.text).length;
|
|
724
|
-
case "hyperlink":
|
|
725
|
-
return node.children.reduce(
|
|
726
|
-
(total, child) => total + inlineNodeLength(child),
|
|
727
|
-
0
|
|
728
|
-
);
|
|
729
|
-
case "hard_break":
|
|
730
|
-
case "column_break":
|
|
731
|
-
case "tab":
|
|
732
|
-
case "symbol":
|
|
733
|
-
case "image":
|
|
734
|
-
case "opaque_inline":
|
|
735
|
-
case "footnote_ref":
|
|
736
|
-
case "chart_preview":
|
|
737
|
-
case "smartart_preview":
|
|
738
|
-
case "shape":
|
|
739
|
-
case "wordart":
|
|
740
|
-
case "vml_shape":
|
|
741
|
-
return 1;
|
|
742
|
-
case "field":
|
|
743
|
-
return node.children.reduce(
|
|
744
|
-
(total, child) => total + inlineNodeLength(child),
|
|
745
|
-
0
|
|
746
|
-
);
|
|
747
|
-
case "bookmark_start":
|
|
748
|
-
case "bookmark_end":
|
|
749
|
-
return 0;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
function toPublicAlignment(alignment) {
|
|
753
|
-
switch (alignment) {
|
|
754
|
-
case "both":
|
|
755
|
-
case "distribute":
|
|
756
|
-
return "justify";
|
|
757
|
-
case "left":
|
|
758
|
-
case "center":
|
|
759
|
-
case "right":
|
|
760
|
-
return alignment;
|
|
761
|
-
default:
|
|
762
|
-
return void 0;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
function toPublicColor(color) {
|
|
766
|
-
if (!color) {
|
|
767
|
-
return void 0;
|
|
768
|
-
}
|
|
769
|
-
return /^[0-9A-F]{3,8}$/iu.test(color) ? `#${color.toUpperCase()}` : color;
|
|
770
|
-
}
|
|
771
|
-
function sanitizeFontFamily(fontFamily) {
|
|
772
|
-
const normalized = fontFamily?.trim();
|
|
773
|
-
return normalized ? normalized : null;
|
|
774
|
-
}
|
|
775
|
-
function sanitizeFontSize(size) {
|
|
776
|
-
if (typeof size !== "number" || !Number.isFinite(size) || size <= 0) {
|
|
777
|
-
return null;
|
|
778
|
-
}
|
|
779
|
-
return Math.round(size * 2);
|
|
780
|
-
}
|
|
781
|
-
function sanitizeColor(color) {
|
|
782
|
-
const normalized = color?.trim();
|
|
783
|
-
if (!normalized) {
|
|
784
|
-
return null;
|
|
785
|
-
}
|
|
786
|
-
const raw = normalized.startsWith("#") ? normalized.slice(1) : normalized;
|
|
787
|
-
return /^[0-9A-F]{3,8}$/iu.test(raw) ? raw.toUpperCase() : null;
|
|
788
|
-
}
|
|
789
|
-
function selectionTouchesRange(anchor, head, rangeFrom, rangeTo) {
|
|
790
|
-
const selectionFrom = Math.min(anchor, head);
|
|
791
|
-
const selectionTo = Math.max(anchor, head);
|
|
792
|
-
if (selectionFrom === selectionTo) {
|
|
793
|
-
return selectionFrom >= rangeFrom && selectionFrom <= rangeTo;
|
|
794
|
-
}
|
|
795
|
-
return rangesOverlap(selectionFrom, selectionTo, rangeFrom, rangeTo);
|
|
796
|
-
}
|
|
797
|
-
function rangesOverlap(leftFrom, leftTo, rightFrom, rightTo) {
|
|
798
|
-
if (leftFrom === leftTo) {
|
|
799
|
-
return leftFrom >= rightFrom && leftFrom <= rightTo;
|
|
800
|
-
}
|
|
801
|
-
if (rightFrom === rightTo) {
|
|
802
|
-
return rightFrom >= leftFrom && rightFrom <= leftTo;
|
|
803
|
-
}
|
|
804
|
-
return leftFrom < rightTo && leftTo > rightFrom;
|
|
805
|
-
}
|
|
806
|
-
function clamp(value, min, max) {
|
|
807
|
-
return Math.min(max, Math.max(min, value));
|
|
808
|
-
}
|
|
809
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
810
|
-
0 && (module.exports = {
|
|
811
|
-
applyFormattingOperationToDocument,
|
|
812
|
-
getFormattingStateFromRenderSnapshot,
|
|
813
|
-
isMarkActive,
|
|
814
|
-
makeSetAlignment,
|
|
815
|
-
makeSetFontFamily,
|
|
816
|
-
makeSetFontSize,
|
|
817
|
-
makeSetHighlight,
|
|
818
|
-
makeSetTextColor,
|
|
819
|
-
makeToggleAllCaps,
|
|
820
|
-
makeToggleBold,
|
|
821
|
-
makeToggleItalic,
|
|
822
|
-
makeToggleSmallCaps,
|
|
823
|
-
makeToggleStrikethrough,
|
|
824
|
-
makeToggleSubscript,
|
|
825
|
-
makeToggleSuperscript,
|
|
826
|
-
makeToggleUnderline
|
|
827
|
-
});
|
|
828
|
-
//# sourceMappingURL=formatting-commands.cjs.map
|