@beyondwork/docx-react-component 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
- package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
- package/dist/chunk-2FJS5GZM.js +763 -0
- package/dist/chunk-2FJS5GZM.js.map +1 -0
- package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
- package/dist/chunk-2OQBZS3F.js.map +1 -0
- package/dist/chunk-2S7W4KFO.js +127 -0
- package/dist/chunk-2S7W4KFO.js.map +1 -0
- package/dist/chunk-2TG72QSW.js +3874 -0
- package/dist/chunk-2TG72QSW.js.map +1 -0
- package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
- package/dist/chunk-36QNIZBO.js.map +1 -0
- package/dist/chunk-4AQOYAW4.js +3069 -0
- package/dist/chunk-4AQOYAW4.js.map +1 -0
- package/dist/chunk-4D5EWJ3P.js +77 -0
- package/dist/chunk-4D5EWJ3P.js.map +1 -0
- package/dist/chunk-5FN54NDH.js +2257 -0
- package/dist/chunk-5FN54NDH.js.map +1 -0
- package/dist/chunk-BOYGQYRQ.js +7306 -0
- package/dist/chunk-BOYGQYRQ.js.map +1 -0
- package/dist/chunk-CN3XMECL.js +212 -0
- package/dist/chunk-CN3XMECL.js.map +1 -0
- package/dist/chunk-EBI3BX6U.js +164 -0
- package/dist/chunk-EBI3BX6U.js.map +1 -0
- package/dist/chunk-EILUG3VB.js +1275 -0
- package/dist/chunk-EILUG3VB.js.map +1 -0
- package/dist/chunk-FUDY333O.js +70 -0
- package/dist/chunk-FUDY333O.js.map +1 -0
- package/dist/chunk-GBVOWFIK.js +1237 -0
- package/dist/chunk-GBVOWFIK.js.map +1 -0
- package/dist/chunk-H4TQ3H3Y.js +262 -0
- package/dist/chunk-H4TQ3H3Y.js.map +1 -0
- package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
- package/dist/chunk-JGB3IXZO.js.map +1 -0
- package/dist/chunk-KD2QRQPY.js +4342 -0
- package/dist/chunk-KD2QRQPY.js.map +1 -0
- package/dist/chunk-KLMXQVYK.js +369 -0
- package/dist/chunk-KLMXQVYK.js.map +1 -0
- package/dist/chunk-KZUG5KFQ.js +214 -0
- package/dist/chunk-KZUG5KFQ.js.map +1 -0
- package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
- package/dist/chunk-QDAQ4CJU.js.map +1 -0
- package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
- package/dist/chunk-RMH72RZI.js.map +1 -0
- package/dist/chunk-SWKWQZXM.js +117 -0
- package/dist/chunk-SWKWQZXM.js.map +1 -0
- package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
- package/dist/chunk-TJBP2K4T.js.map +1 -0
- package/dist/chunk-TLCEAQDQ.js +542 -0
- package/dist/chunk-TLCEAQDQ.js.map +1 -0
- package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
- package/dist/chunk-UZXBISGO.js.map +1 -0
- package/dist/chunk-WGBAKP3Q.js +3220 -0
- package/dist/chunk-WGBAKP3Q.js.map +1 -0
- package/dist/compare/index.cjs +5475 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +114 -0
- package/dist/compare/index.d.ts +114 -0
- package/dist/compare/index.js +731 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/core/commands/formatting-commands.cjs +828 -0
- package/dist/core/commands/formatting-commands.cjs.map +1 -0
- package/dist/core/commands/formatting-commands.d.cts +63 -0
- package/dist/core/commands/formatting-commands.d.ts +63 -0
- package/dist/core/commands/formatting-commands.js +37 -0
- package/dist/core/commands/formatting-commands.js.map +1 -0
- package/dist/core/commands/image-commands.cjs +2023 -0
- package/dist/core/commands/image-commands.cjs.map +1 -0
- package/dist/core/commands/image-commands.d.cts +58 -0
- package/dist/core/commands/image-commands.d.ts +58 -0
- package/dist/core/commands/image-commands.js +18 -0
- package/dist/core/commands/image-commands.js.map +1 -0
- package/dist/core/commands/section-layout-commands.cjs +477 -0
- package/dist/core/commands/section-layout-commands.cjs.map +1 -0
- package/dist/core/commands/section-layout-commands.d.cts +62 -0
- package/dist/core/commands/section-layout-commands.d.ts +62 -0
- package/dist/core/commands/section-layout-commands.js +21 -0
- package/dist/core/commands/section-layout-commands.js.map +1 -0
- package/dist/core/commands/style-commands.cjs +214 -0
- package/dist/core/commands/style-commands.cjs.map +1 -0
- package/dist/core/commands/style-commands.d.cts +13 -0
- package/dist/core/commands/style-commands.d.ts +13 -0
- package/dist/core/commands/style-commands.js +9 -0
- package/dist/core/commands/style-commands.js.map +1 -0
- package/dist/core/commands/table-structure-commands.cjs +1883 -0
- package/dist/core/commands/table-structure-commands.cjs.map +1 -0
- package/dist/core/commands/table-structure-commands.d.cts +59 -0
- package/dist/core/commands/table-structure-commands.d.ts +59 -0
- package/dist/core/commands/table-structure-commands.js +12 -0
- package/dist/core/commands/table-structure-commands.js.map +1 -0
- package/dist/core/commands/text-commands.cjs +2391 -0
- package/dist/core/commands/text-commands.cjs.map +1 -0
- package/dist/core/commands/text-commands.d.cts +24 -0
- package/dist/core/commands/text-commands.d.ts +24 -0
- package/dist/core/commands/text-commands.js +28 -0
- package/dist/core/commands/text-commands.js.map +1 -0
- package/dist/core/selection/mapping.cjs +200 -0
- package/dist/core/selection/mapping.cjs.map +1 -0
- package/dist/core/selection/mapping.d.cts +2 -0
- package/dist/core/selection/mapping.d.ts +2 -0
- package/dist/core/selection/mapping.js +31 -0
- package/dist/core/selection/mapping.js.map +1 -0
- package/dist/core/state/editor-state.cjs +2278 -0
- package/dist/core/state/editor-state.cjs.map +1 -0
- package/dist/core/state/editor-state.d.cts +2 -0
- package/dist/core/state/editor-state.d.ts +2 -0
- package/dist/core/state/editor-state.js +26 -0
- package/dist/core/state/editor-state.js.map +1 -0
- package/dist/index.cjs +38553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7856 -0
- package/dist/index.js.map +1 -0
- package/dist/io/docx-session.cjs +16236 -0
- package/dist/io/docx-session.cjs.map +1 -0
- package/dist/io/docx-session.d.cts +21 -0
- package/dist/io/docx-session.d.ts +21 -0
- package/dist/io/docx-session.js +18 -0
- package/dist/io/docx-session.js.map +1 -0
- package/dist/legal/index.cjs +3900 -0
- package/dist/legal/index.cjs.map +1 -0
- package/dist/legal/index.d.cts +86 -0
- package/dist/legal/index.d.ts +86 -0
- package/dist/legal/index.js +616 -0
- package/dist/legal/index.js.map +1 -0
- package/dist/public-types-7ZL_94cz.d.ts +1573 -0
- package/dist/public-types-CeMaDueh.d.cts +1573 -0
- package/dist/public-types.cjs +19 -0
- package/dist/public-types.cjs.map +1 -0
- package/dist/public-types.d.cts +2 -0
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.js +1 -0
- package/dist/public-types.js.map +1 -0
- package/dist/runtime/document-runtime.cjs +11140 -0
- package/dist/runtime/document-runtime.cjs.map +1 -0
- package/dist/runtime/document-runtime.d.cts +231 -0
- package/dist/runtime/document-runtime.d.ts +231 -0
- package/dist/runtime/document-runtime.js +21 -0
- package/dist/runtime/document-runtime.js.map +1 -0
- package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
- package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
- package/dist/ui-tailwind/index.cjs +4833 -0
- package/dist/ui-tailwind/index.cjs.map +1 -0
- package/dist/ui-tailwind/index.d.cts +617 -0
- package/dist/ui-tailwind/index.d.ts +617 -0
- package/dist/ui-tailwind/index.js +575 -0
- package/dist/ui-tailwind/index.js.map +1 -0
- package/package.json +64 -54
- package/src/README.md +0 -85
- package/src/api/README.md +0 -26
- package/src/api/public-types.ts +0 -1418
- package/src/api/session-state.ts +0 -60
- package/src/compare/diff-engine.ts +0 -623
- package/src/compare/export-redlines.ts +0 -280
- package/src/compare/index.ts +0 -25
- package/src/compare/snapshot.ts +0 -97
- package/src/component-inventory.md +0 -99
- package/src/core/README.md +0 -10
- package/src/core/commands/README.md +0 -3
- package/src/core/commands/image-commands.ts +0 -373
- package/src/core/commands/index.ts +0 -1757
- package/src/core/commands/list-commands.ts +0 -565
- package/src/core/commands/paragraph-layout-commands.ts +0 -339
- package/src/core/commands/review-commands.ts +0 -108
- package/src/core/commands/structural-helpers.ts +0 -309
- package/src/core/schema/README.md +0 -3
- package/src/core/schema/text-schema.ts +0 -516
- package/src/core/search/search-text.ts +0 -357
- package/src/core/selection/README.md +0 -3
- package/src/core/selection/mapping.ts +0 -289
- package/src/core/selection/review-anchors.ts +0 -183
- package/src/core/state/README.md +0 -3
- package/src/core/state/editor-state.ts +0 -892
- package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
- package/src/formats/xlsx/io/parse-sheet.ts +0 -459
- package/src/formats/xlsx/io/parse-styles.ts +0 -59
- package/src/formats/xlsx/io/parse-workbook.ts +0 -75
- package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
- package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
- package/src/formats/xlsx/io/serialize-styles.ts +0 -98
- package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
- package/src/formats/xlsx/io/xlsx-session.ts +0 -314
- package/src/formats/xlsx/model/cell.ts +0 -189
- package/src/formats/xlsx/model/sheet.ts +0 -326
- package/src/formats/xlsx/model/styles.ts +0 -118
- package/src/formats/xlsx/model/workbook.ts +0 -453
- package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
- package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
- package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
- package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
- package/src/index.ts +0 -101
- package/src/io/README.md +0 -10
- package/src/io/docx-session.ts +0 -2882
- package/src/io/export/README.md +0 -3
- package/src/io/export/export-session.ts +0 -220
- package/src/io/export/minimal-docx.ts +0 -115
- package/src/io/export/reattach-preserved-parts.ts +0 -54
- package/src/io/export/serialize-comments.ts +0 -947
- package/src/io/export/serialize-footnotes.ts +0 -399
- package/src/io/export/serialize-headers-footers.ts +0 -372
- package/src/io/export/serialize-main-document.ts +0 -1376
- package/src/io/export/serialize-numbering.ts +0 -118
- package/src/io/export/serialize-revisions.ts +0 -389
- package/src/io/export/serialize-runtime-revisions.ts +0 -269
- package/src/io/export/serialize-tables.ts +0 -174
- package/src/io/export/split-review-boundaries.ts +0 -356
- package/src/io/normalize/README.md +0 -3
- package/src/io/normalize/normalize-text.ts +0 -639
- package/src/io/ooxml/README.md +0 -3
- package/src/io/ooxml/highlight-colors.ts +0 -39
- package/src/io/ooxml/numbering-sentinels.ts +0 -44
- package/src/io/ooxml/parse-comments.ts +0 -846
- package/src/io/ooxml/parse-complex-content.ts +0 -287
- package/src/io/ooxml/parse-fields.ts +0 -834
- package/src/io/ooxml/parse-footnotes.ts +0 -896
- package/src/io/ooxml/parse-headers-footers.ts +0 -1169
- package/src/io/ooxml/parse-inline-media.ts +0 -461
- package/src/io/ooxml/parse-main-document.ts +0 -2877
- package/src/io/ooxml/parse-numbering.ts +0 -432
- package/src/io/ooxml/parse-revisions.ts +0 -931
- package/src/io/ooxml/parse-settings.ts +0 -184
- package/src/io/ooxml/parse-shapes.ts +0 -296
- package/src/io/ooxml/parse-styles.ts +0 -463
- package/src/io/ooxml/parse-tables.ts +0 -618
- package/src/io/ooxml/parse-theme.ts +0 -346
- package/src/io/ooxml/part-manifest.ts +0 -136
- package/src/io/ooxml/revision-boundaries.ts +0 -351
- package/src/io/opc/README.md +0 -3
- package/src/io/opc/corrupt-package.ts +0 -166
- package/src/io/opc/docx-package.ts +0 -74
- package/src/io/opc/package-reader.ts +0 -325
- package/src/io/opc/package-writer.ts +0 -273
- package/src/io/source-package-provenance.ts +0 -241
- package/src/legal/cross-references.ts +0 -414
- package/src/legal/defined-terms.ts +0 -203
- package/src/legal/index.ts +0 -32
- package/src/legal/signature-blocks.ts +0 -259
- package/src/model/README.md +0 -3
- package/src/model/canonical-document.ts +0 -2632
- package/src/model/cds-1.0.0.ts +0 -212
- package/src/model/snapshot.ts +0 -649
- package/src/preservation/README.md +0 -3
- package/src/preservation/markup-compatibility.ts +0 -48
- package/src/preservation/opaque-fragment-store.ts +0 -89
- package/src/preservation/opaque-region.ts +0 -233
- package/src/preservation/package-preservation.ts +0 -113
- package/src/preservation/preserved-part-manifest.ts +0 -56
- package/src/preservation/relationship-retention.ts +0 -57
- package/src/preservation/store.ts +0 -185
- package/src/review/README.md +0 -16
- package/src/review/store/README.md +0 -3
- package/src/review/store/comment-anchors.ts +0 -70
- package/src/review/store/comment-remapping.ts +0 -154
- package/src/review/store/comment-store.ts +0 -331
- package/src/review/store/comment-thread.ts +0 -109
- package/src/review/store/revision-actions.ts +0 -394
- package/src/review/store/revision-store.ts +0 -312
- package/src/review/store/revision-types.ts +0 -171
- package/src/review/store/runtime-comment-store.ts +0 -43
- package/src/runtime/README.md +0 -3
- package/src/runtime/ai-action-policy.ts +0 -764
- package/src/runtime/collab-review-sync.ts +0 -254
- package/src/runtime/document-layout.ts +0 -332
- package/src/runtime/document-navigation.ts +0 -603
- package/src/runtime/document-runtime.ts +0 -3159
- package/src/runtime/document-search.ts +0 -145
- package/src/runtime/numbering-prefix.ts +0 -216
- package/src/runtime/page-layout-estimation.ts +0 -212
- package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
- package/src/runtime/review-runtime.ts +0 -44
- package/src/runtime/revision-runtime.ts +0 -107
- package/src/runtime/session-capabilities.ts +0 -192
- package/src/runtime/story-context.ts +0 -164
- package/src/runtime/story-targeting.ts +0 -162
- package/src/runtime/surface-projection.ts +0 -1357
- package/src/runtime/table-commands.ts +0 -173
- package/src/runtime/table-schema.ts +0 -309
- package/src/runtime/view-state.ts +0 -477
- package/src/runtime/virtualized-rendering.ts +0 -258
- package/src/runtime/workflow-markup.ts +0 -353
- package/src/ui/README.md +0 -30
- package/src/ui/WordReviewEditor.tsx +0 -4097
- package/src/ui/browser-export.ts +0 -52
- package/src/ui/comments/README.md +0 -3
- package/src/ui/compatibility/README.md +0 -3
- package/src/ui/editor-command-bag.ts +0 -120
- package/src/ui/editor-runtime-boundary.ts +0 -1457
- package/src/ui/editor-shell-view.tsx +0 -142
- package/src/ui/editor-surface/README.md +0 -3
- package/src/ui/editor-surface-controller.tsx +0 -63
- package/src/ui/headless/comment-decoration-model.ts +0 -124
- package/src/ui/headless/preserve-editor-selection.ts +0 -5
- package/src/ui/headless/revision-decoration-model.ts +0 -128
- package/src/ui/headless/selection-helpers.ts +0 -54
- package/src/ui/headless/selection-toolbar-model.ts +0 -34
- package/src/ui/headless/use-editor-keyboard.ts +0 -103
- package/src/ui/review/README.md +0 -3
- package/src/ui/runtime-snapshot-selectors.ts +0 -197
- package/src/ui/shared/revision-filters.ts +0 -31
- package/src/ui/status/README.md +0 -3
- package/src/ui/theme/README.md +0 -3
- package/src/ui/toolbar/README.md +0 -3
- package/src/ui/workflow-surface-blocked-rails.ts +0 -94
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
- package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
- package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
- package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
- package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
- package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
- package/src/ui-tailwind/index.ts +0 -62
- package/src/ui-tailwind/page-chrome-model.ts +0 -27
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
- package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
- package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
- package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
- package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
- package/src/validation/README.md +0 -3
- package/src/validation/compatibility-engine.ts +0 -634
- package/src/validation/compatibility-report.ts +0 -161
- package/src/validation/diagnostics.ts +0 -204
- package/src/validation/docx-comment-proof.ts +0 -707
- package/src/validation/import-diagnostics.ts +0 -128
- package/src/validation/low-priority-word-surfaces.ts +0 -373
- /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
|
@@ -1,99 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
* ProseMirror formatting commands for the editor surface schema.
|
|
3
|
-
*
|
|
4
|
-
* Each command follows the standard ProseMirror command signature:
|
|
5
|
-
* (state, dispatch?) => boolean
|
|
6
|
-
*
|
|
7
|
-
* Toggle commands use the ProseMirror toggleMark helper.
|
|
8
|
-
* Set commands for value-bearing marks (font, size, color) apply the mark
|
|
9
|
-
* over the current selection, or remove it when the value is null.
|
|
10
|
-
* The setAlignment command sets the `alignment` attr on paragraph nodes
|
|
11
|
-
* that intersect the current selection.
|
|
12
|
-
*
|
|
13
|
-
* These commands operate on the `editorSchema` live surface. In the
|
|
14
|
-
* current architecture the runtime is the canonical document authority;
|
|
15
|
-
* these commands are designed to be used with the PM view's `dispatch`
|
|
16
|
-
* so that mark changes are reflected on the live surface immediately.
|
|
17
|
-
*/
|
|
18
|
-
|
|
1
|
+
// src/core/commands/formatting-commands.ts
|
|
19
2
|
import { toggleMark } from "prosemirror-commands";
|
|
20
|
-
|
|
21
|
-
import type { MarkType, Schema } from "prosemirror-model";
|
|
22
|
-
|
|
23
|
-
import type {
|
|
24
|
-
FormattingBreadcrumbItem,
|
|
25
|
-
FormattingAlignment,
|
|
26
|
-
FormattingStateSnapshot,
|
|
27
|
-
PersistedEditorSnapshot,
|
|
28
|
-
RuntimeRenderSnapshot,
|
|
29
|
-
SurfaceBlockSnapshot,
|
|
30
|
-
SurfaceInlineSegment,
|
|
31
|
-
SurfaceTableCellSnapshot,
|
|
32
|
-
} from "../../api/public-types";
|
|
33
|
-
import type {
|
|
34
|
-
BlockNode,
|
|
35
|
-
DocumentRootNode,
|
|
36
|
-
InlineNode,
|
|
37
|
-
ParagraphNode,
|
|
38
|
-
TextMark,
|
|
39
|
-
TextNode,
|
|
40
|
-
} from "../../model/canonical-document.ts";
|
|
41
|
-
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// Toggle commands (boolean marks – no attrs)
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
export function makeToggleBold(schema: Schema): Command {
|
|
3
|
+
function makeToggleBold(schema) {
|
|
47
4
|
return toggleMark(schema.marks.bold);
|
|
48
5
|
}
|
|
49
|
-
|
|
50
|
-
export function makeToggleItalic(schema: Schema): Command {
|
|
6
|
+
function makeToggleItalic(schema) {
|
|
51
7
|
return toggleMark(schema.marks.italic);
|
|
52
8
|
}
|
|
53
|
-
|
|
54
|
-
export function makeToggleUnderline(schema: Schema): Command {
|
|
9
|
+
function makeToggleUnderline(schema) {
|
|
55
10
|
return toggleMark(schema.marks.underline);
|
|
56
11
|
}
|
|
57
|
-
|
|
58
|
-
export function makeToggleStrikethrough(schema: Schema): Command {
|
|
12
|
+
function makeToggleStrikethrough(schema) {
|
|
59
13
|
return toggleMark(schema.marks.strikethrough);
|
|
60
14
|
}
|
|
61
|
-
|
|
62
|
-
export function makeToggleSuperscript(schema: Schema): Command {
|
|
15
|
+
function makeToggleSuperscript(schema) {
|
|
63
16
|
return toggleMark(schema.marks.superscript);
|
|
64
17
|
}
|
|
65
|
-
|
|
66
|
-
export function makeToggleSubscript(schema: Schema): Command {
|
|
18
|
+
function makeToggleSubscript(schema) {
|
|
67
19
|
return toggleMark(schema.marks.subscript);
|
|
68
20
|
}
|
|
69
|
-
|
|
70
|
-
export function makeToggleSmallCaps(schema: Schema): Command {
|
|
21
|
+
function makeToggleSmallCaps(schema) {
|
|
71
22
|
return toggleMark(schema.marks.small_caps);
|
|
72
23
|
}
|
|
73
|
-
|
|
74
|
-
export function makeToggleAllCaps(schema: Schema): Command {
|
|
24
|
+
function makeToggleAllCaps(schema) {
|
|
75
25
|
return toggleMark(schema.marks.all_caps);
|
|
76
26
|
}
|
|
77
|
-
|
|
78
|
-
// ---------------------------------------------------------------------------
|
|
79
|
-
// Set commands (value-bearing marks)
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Apply or remove a value-bearing mark over the current selection.
|
|
84
|
-
* When `value` is null the mark is removed; otherwise it is added with the
|
|
85
|
-
* given attribute key set to `value`.
|
|
86
|
-
*/
|
|
87
|
-
function makeSetValueMark(
|
|
88
|
-
markType: MarkType,
|
|
89
|
-
attrKey: string,
|
|
90
|
-
value: string | number | null,
|
|
91
|
-
): Command {
|
|
27
|
+
function makeSetValueMark(markType, attrKey, value) {
|
|
92
28
|
return (state, dispatch) => {
|
|
93
29
|
const { from, to, empty } = state.selection;
|
|
94
30
|
if (empty) return false;
|
|
95
31
|
if (!dispatch) return true;
|
|
96
|
-
|
|
97
32
|
const tr = state.tr;
|
|
98
33
|
if (value === null) {
|
|
99
34
|
tr.removeMark(from, to, markType);
|
|
@@ -105,70 +40,42 @@ function makeSetValueMark(
|
|
|
105
40
|
return true;
|
|
106
41
|
};
|
|
107
42
|
}
|
|
108
|
-
|
|
109
|
-
export function makeSetFontFamily(schema: Schema, family: string | null): Command {
|
|
43
|
+
function makeSetFontFamily(schema, family) {
|
|
110
44
|
return makeSetValueMark(schema.marks.font_family, "family", family);
|
|
111
45
|
}
|
|
112
|
-
|
|
113
|
-
export function makeSetFontSize(schema: Schema, size: number | null): Command {
|
|
46
|
+
function makeSetFontSize(schema, size) {
|
|
114
47
|
return makeSetValueMark(schema.marks.font_size, "size", size);
|
|
115
48
|
}
|
|
116
|
-
|
|
117
|
-
export function makeSetTextColor(schema: Schema, color: string | null): Command {
|
|
49
|
+
function makeSetTextColor(schema, color) {
|
|
118
50
|
return makeSetValueMark(schema.marks.text_color, "color", color);
|
|
119
51
|
}
|
|
120
|
-
|
|
121
|
-
export function makeSetHighlight(schema: Schema, color: string | null): Command {
|
|
52
|
+
function makeSetHighlight(schema, color) {
|
|
122
53
|
return makeSetValueMark(schema.marks.highlight, "color", color);
|
|
123
54
|
}
|
|
124
|
-
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Paragraph alignment
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
|
|
129
|
-
export type Alignment = "left" | "center" | "right" | "justify";
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Set the `alignment` attribute on every paragraph node that intersects
|
|
133
|
-
* the current selection. Pass `null` to clear the alignment.
|
|
134
|
-
*/
|
|
135
|
-
export function makeSetAlignment(schema: Schema, alignment: Alignment | null): Command {
|
|
55
|
+
function makeSetAlignment(schema, alignment) {
|
|
136
56
|
return (state, dispatch) => {
|
|
137
57
|
const { from, to } = state.selection;
|
|
138
58
|
if (!dispatch) return true;
|
|
139
|
-
|
|
140
59
|
const tr = state.tr;
|
|
141
60
|
let applied = false;
|
|
142
61
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
143
62
|
if (node.type === schema.nodes.paragraph) {
|
|
144
|
-
tr.setNodeMarkup(pos,
|
|
63
|
+
tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment });
|
|
145
64
|
applied = true;
|
|
146
65
|
}
|
|
147
66
|
});
|
|
148
|
-
|
|
149
67
|
if (!applied) return false;
|
|
150
68
|
dispatch(tr);
|
|
151
69
|
return true;
|
|
152
70
|
};
|
|
153
71
|
}
|
|
154
|
-
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// Mark query helpers
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Returns true if every character in the selection has the given mark active.
|
|
161
|
-
* When the selection is collapsed, checks the stored marks at the cursor.
|
|
162
|
-
*/
|
|
163
|
-
export function isMarkActive(schema: Schema, markName: keyof typeof schema.marks, state: import("prosemirror-state").EditorState): boolean {
|
|
72
|
+
function isMarkActive(schema, markName, state) {
|
|
164
73
|
const markType = schema.marks[markName];
|
|
165
74
|
if (!markType) return false;
|
|
166
|
-
|
|
167
75
|
const { from, to, empty } = state.selection;
|
|
168
76
|
if (empty) {
|
|
169
77
|
return Boolean(markType.isInSet(state.storedMarks ?? state.selection.$from.marks()));
|
|
170
78
|
}
|
|
171
|
-
|
|
172
79
|
let active = true;
|
|
173
80
|
state.doc.nodesBetween(from, to, (node) => {
|
|
174
81
|
if (node.isText && !markType.isInSet(node.marks)) {
|
|
@@ -178,180 +85,116 @@ export function isMarkActive(schema: Schema, markName: keyof typeof schema.marks
|
|
|
178
85
|
});
|
|
179
86
|
return active;
|
|
180
87
|
}
|
|
181
|
-
|
|
182
|
-
type CanonicalDocumentEnvelope = PersistedEditorSnapshot["canonicalDocument"];
|
|
183
|
-
type ParagraphSurfaceBlock = Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>;
|
|
184
|
-
type ToggleFormattingMark =
|
|
185
|
-
| "bold"
|
|
186
|
-
| "italic"
|
|
187
|
-
| "underline"
|
|
188
|
-
| "strikethrough"
|
|
189
|
-
| "superscript"
|
|
190
|
-
| "subscript";
|
|
191
|
-
type FormattingOperation =
|
|
192
|
-
| { type: "toggle"; mark: ToggleFormattingMark }
|
|
193
|
-
| { type: "set-font-family"; fontFamily: string | null }
|
|
194
|
-
| { type: "set-font-size"; size: number | null }
|
|
195
|
-
| { type: "set-text-color"; color: string | null }
|
|
196
|
-
| { type: "set-highlight-color"; color: string | null }
|
|
197
|
-
| { type: "set-alignment"; alignment: FormattingAlignment }
|
|
198
|
-
| { type: "indent" }
|
|
199
|
-
| { type: "outdent" };
|
|
200
|
-
|
|
201
|
-
export interface FormattingMutationResult {
|
|
202
|
-
document: CanonicalDocumentEnvelope;
|
|
203
|
-
selection: RuntimeRenderSnapshot["selection"];
|
|
204
|
-
changed: boolean;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const DEFAULT_FORMATTING_STATE: FormattingStateSnapshot = {
|
|
88
|
+
var DEFAULT_FORMATTING_STATE = {
|
|
208
89
|
bold: false,
|
|
209
90
|
italic: false,
|
|
210
91
|
underline: false,
|
|
211
92
|
strikethrough: false,
|
|
212
93
|
superscript: false,
|
|
213
94
|
subscript: false,
|
|
214
|
-
breadcrumb: []
|
|
95
|
+
breadcrumb: []
|
|
215
96
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
export function getFormattingStateFromRenderSnapshot(
|
|
220
|
-
snapshot: RuntimeRenderSnapshot,
|
|
221
|
-
): FormattingStateSnapshot {
|
|
97
|
+
var INDENT_STEP_TWIPS = 720;
|
|
98
|
+
function getFormattingStateFromRenderSnapshot(snapshot) {
|
|
222
99
|
const surface = snapshot.surface;
|
|
223
100
|
if (!surface) {
|
|
224
101
|
return { ...DEFAULT_FORMATTING_STATE };
|
|
225
102
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
selectionTouchesRange(
|
|
103
|
+
const paragraphs = collectParagraphSurfaces(surface.blocks).filter(
|
|
104
|
+
(paragraph) => selectionTouchesRange(
|
|
229
105
|
snapshot.selection.anchor,
|
|
230
106
|
snapshot.selection.head,
|
|
231
107
|
paragraph.from,
|
|
232
|
-
paragraph.to
|
|
233
|
-
)
|
|
108
|
+
paragraph.to
|
|
109
|
+
)
|
|
234
110
|
);
|
|
235
111
|
const textSegments = collectFormattingTextSegments(paragraphs, snapshot.selection);
|
|
236
|
-
|
|
237
112
|
return {
|
|
238
|
-
bold: textSegments.length > 0
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
underline: textSegments.length > 0
|
|
245
|
-
? textSegments.every((segment) => segmentHasMark(segment, "underline"))
|
|
246
|
-
: false,
|
|
247
|
-
strikethrough: textSegments.length > 0
|
|
248
|
-
? textSegments.every((segment) => segmentHasMark(segment, "strikethrough"))
|
|
249
|
-
: false,
|
|
250
|
-
superscript: textSegments.length > 0
|
|
251
|
-
? textSegments.every((segment) => segmentHasMark(segment, "superscript"))
|
|
252
|
-
: false,
|
|
253
|
-
subscript: textSegments.length > 0
|
|
254
|
-
? textSegments.every((segment) => segmentHasMark(segment, "subscript"))
|
|
255
|
-
: false,
|
|
113
|
+
bold: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "bold")) : false,
|
|
114
|
+
italic: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "italic")) : false,
|
|
115
|
+
underline: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "underline")) : false,
|
|
116
|
+
strikethrough: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "strikethrough")) : false,
|
|
117
|
+
superscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "superscript")) : false,
|
|
118
|
+
subscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "subscript")) : false,
|
|
256
119
|
fontFamily: getConsistentValue(textSegments, (segment) => segment.markAttrs?.fontFamily),
|
|
257
120
|
fontSize: getConsistentValue(textSegments, (segment) => {
|
|
258
121
|
const size = segment.markAttrs?.fontSize;
|
|
259
|
-
return typeof size === "number" ? size / 2 :
|
|
122
|
+
return typeof size === "number" ? size / 2 : void 0;
|
|
260
123
|
}),
|
|
261
|
-
textColor: getConsistentValue(
|
|
262
|
-
|
|
124
|
+
textColor: getConsistentValue(
|
|
125
|
+
textSegments,
|
|
126
|
+
(segment) => toPublicColor(segment.markAttrs?.textColor)
|
|
263
127
|
),
|
|
264
128
|
highlightColor: getConsistentValue(
|
|
265
129
|
textSegments,
|
|
266
130
|
(segment) => toPublicColor(segment.markAttrs?.backgroundColor) ?? null,
|
|
267
131
|
{
|
|
268
|
-
emptyFallback: null
|
|
269
|
-
}
|
|
132
|
+
emptyFallback: null
|
|
133
|
+
}
|
|
270
134
|
),
|
|
271
|
-
alignment: getConsistentValue(
|
|
272
|
-
|
|
135
|
+
alignment: getConsistentValue(
|
|
136
|
+
paragraphs,
|
|
137
|
+
(paragraph) => toPublicAlignment(paragraph.alignment)
|
|
273
138
|
),
|
|
274
139
|
paragraphStyleId: getConsistentValue(paragraphs, (paragraph) => paragraph.styleId),
|
|
275
|
-
breadcrumb: getSelectionBreadcrumb(surface.blocks, snapshot.selection)
|
|
140
|
+
breadcrumb: getSelectionBreadcrumb(surface.blocks, snapshot.selection)
|
|
276
141
|
};
|
|
277
142
|
}
|
|
278
|
-
|
|
279
|
-
function getSelectionBreadcrumb(
|
|
280
|
-
blocks: SurfaceBlockSnapshot[],
|
|
281
|
-
selection: RuntimeRenderSnapshot["selection"],
|
|
282
|
-
): FormattingBreadcrumbItem[] {
|
|
143
|
+
function getSelectionBreadcrumb(blocks, selection) {
|
|
283
144
|
const paths = collectSelectionBreadcrumbPaths(blocks, selection);
|
|
284
145
|
if (paths.length === 0) {
|
|
285
146
|
return [];
|
|
286
147
|
}
|
|
287
|
-
|
|
288
148
|
let commonLength = paths[0]?.length ?? 0;
|
|
289
149
|
for (let pathIndex = 1; pathIndex < paths.length; pathIndex += 1) {
|
|
290
150
|
const currentPath = paths[pathIndex] ?? [];
|
|
291
151
|
commonLength = Math.min(commonLength, currentPath.length);
|
|
292
|
-
|
|
293
152
|
let compareIndex = 0;
|
|
294
|
-
while (
|
|
295
|
-
compareIndex < commonLength &&
|
|
296
|
-
breadcrumbItemsEqual(paths[0]![compareIndex]!, currentPath[compareIndex]!)
|
|
297
|
-
) {
|
|
153
|
+
while (compareIndex < commonLength && breadcrumbItemsEqual(paths[0][compareIndex], currentPath[compareIndex])) {
|
|
298
154
|
compareIndex += 1;
|
|
299
155
|
}
|
|
300
156
|
commonLength = compareIndex;
|
|
301
157
|
}
|
|
302
|
-
|
|
303
|
-
return paths[0]!.slice(0, commonLength);
|
|
158
|
+
return paths[0].slice(0, commonLength);
|
|
304
159
|
}
|
|
305
|
-
|
|
306
|
-
function collectSelectionBreadcrumbPaths(
|
|
307
|
-
blocks: SurfaceBlockSnapshot[],
|
|
308
|
-
selection: RuntimeRenderSnapshot["selection"],
|
|
309
|
-
path: FormattingBreadcrumbItem[] = [],
|
|
310
|
-
output: FormattingBreadcrumbItem[][] = [],
|
|
311
|
-
): FormattingBreadcrumbItem[][] {
|
|
160
|
+
function collectSelectionBreadcrumbPaths(blocks, selection, path = [], output = []) {
|
|
312
161
|
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
|
|
313
162
|
const block = blocks[blockIndex];
|
|
314
163
|
if (!block) {
|
|
315
164
|
continue;
|
|
316
165
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
block.to,
|
|
324
|
-
)
|
|
325
|
-
) {
|
|
166
|
+
if (!selectionTouchesRange(
|
|
167
|
+
selection.anchor,
|
|
168
|
+
selection.head,
|
|
169
|
+
block.from,
|
|
170
|
+
block.to
|
|
171
|
+
)) {
|
|
326
172
|
continue;
|
|
327
173
|
}
|
|
328
|
-
|
|
329
174
|
if (block.kind === "paragraph") {
|
|
330
175
|
output.push([
|
|
331
176
|
...path,
|
|
332
177
|
{
|
|
333
|
-
kind: "paragraph"
|
|
178
|
+
kind: "paragraph",
|
|
334
179
|
label: block.styleId ? `Paragraph (${block.styleId})` : "Paragraph",
|
|
335
180
|
from: block.from,
|
|
336
|
-
to: block.to
|
|
337
|
-
}
|
|
181
|
+
to: block.to
|
|
182
|
+
}
|
|
338
183
|
]);
|
|
339
184
|
continue;
|
|
340
185
|
}
|
|
341
|
-
|
|
342
186
|
if (block.kind === "opaque_block") {
|
|
343
187
|
output.push([
|
|
344
188
|
...path,
|
|
345
189
|
{
|
|
346
|
-
kind: "opaque_block"
|
|
190
|
+
kind: "opaque_block",
|
|
347
191
|
label: block.label,
|
|
348
192
|
from: block.from,
|
|
349
|
-
to: block.to
|
|
350
|
-
}
|
|
193
|
+
to: block.to
|
|
194
|
+
}
|
|
351
195
|
]);
|
|
352
196
|
continue;
|
|
353
197
|
}
|
|
354
|
-
|
|
355
198
|
if (block.kind === "sdt_block") {
|
|
356
199
|
collectSelectionBreadcrumbPaths(
|
|
357
200
|
block.children,
|
|
@@ -359,72 +202,63 @@ function collectSelectionBreadcrumbPaths(
|
|
|
359
202
|
[
|
|
360
203
|
...path,
|
|
361
204
|
{
|
|
362
|
-
kind: "sdt_block"
|
|
205
|
+
kind: "sdt_block",
|
|
363
206
|
label: block.alias ?? block.tag ?? block.sdtType ?? "Content control",
|
|
364
207
|
from: block.from,
|
|
365
|
-
to: block.to
|
|
366
|
-
}
|
|
208
|
+
to: block.to
|
|
209
|
+
}
|
|
367
210
|
],
|
|
368
|
-
output
|
|
211
|
+
output
|
|
369
212
|
);
|
|
370
213
|
continue;
|
|
371
214
|
}
|
|
372
|
-
|
|
373
215
|
if (block.kind === "table") {
|
|
374
216
|
const tablePath = [
|
|
375
217
|
...path,
|
|
376
218
|
{
|
|
377
|
-
kind: "table"
|
|
219
|
+
kind: "table",
|
|
378
220
|
label: block.styleId ? `Table (${block.styleId})` : "Table",
|
|
379
221
|
from: block.from,
|
|
380
|
-
to: block.to
|
|
381
|
-
}
|
|
222
|
+
to: block.to
|
|
223
|
+
}
|
|
382
224
|
];
|
|
383
|
-
|
|
384
225
|
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
|
|
385
226
|
const row = block.rows[rowIndex];
|
|
386
227
|
if (!row) {
|
|
387
228
|
continue;
|
|
388
229
|
}
|
|
389
230
|
const rowRange = getTableRowRange(block, row);
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
)
|
|
397
|
-
) {
|
|
231
|
+
if (!selectionTouchesRange(
|
|
232
|
+
selection.anchor,
|
|
233
|
+
selection.head,
|
|
234
|
+
rowRange.from,
|
|
235
|
+
rowRange.to
|
|
236
|
+
)) {
|
|
398
237
|
continue;
|
|
399
238
|
}
|
|
400
|
-
|
|
401
239
|
const rowPath = [
|
|
402
240
|
...tablePath,
|
|
403
241
|
{
|
|
404
|
-
kind: "table_row"
|
|
242
|
+
kind: "table_row",
|
|
405
243
|
label: `Row ${rowIndex + 1}`,
|
|
406
244
|
from: rowRange.from,
|
|
407
|
-
to: rowRange.to
|
|
408
|
-
}
|
|
245
|
+
to: rowRange.to
|
|
246
|
+
}
|
|
409
247
|
];
|
|
410
|
-
|
|
411
248
|
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
412
249
|
const cell = row.cells[cellIndex];
|
|
413
250
|
if (!cell) {
|
|
414
251
|
continue;
|
|
415
252
|
}
|
|
416
253
|
const cellRange = getTableCellRange(block, cell);
|
|
417
|
-
if (
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
)
|
|
424
|
-
) {
|
|
254
|
+
if (!selectionTouchesRange(
|
|
255
|
+
selection.anchor,
|
|
256
|
+
selection.head,
|
|
257
|
+
cellRange.from,
|
|
258
|
+
cellRange.to
|
|
259
|
+
)) {
|
|
425
260
|
continue;
|
|
426
261
|
}
|
|
427
|
-
|
|
428
262
|
collectSelectionBreadcrumbPaths(
|
|
429
263
|
cell.content,
|
|
430
264
|
selection,
|
|
@@ -434,169 +268,113 @@ function collectSelectionBreadcrumbPaths(
|
|
|
434
268
|
kind: "table_cell",
|
|
435
269
|
label: `Cell ${cellIndex + 1}`,
|
|
436
270
|
from: cellRange.from,
|
|
437
|
-
to: cellRange.to
|
|
438
|
-
}
|
|
271
|
+
to: cellRange.to
|
|
272
|
+
}
|
|
439
273
|
],
|
|
440
|
-
output
|
|
274
|
+
output
|
|
441
275
|
);
|
|
442
276
|
}
|
|
443
277
|
}
|
|
444
278
|
}
|
|
445
279
|
}
|
|
446
|
-
|
|
447
280
|
return output;
|
|
448
281
|
}
|
|
449
|
-
|
|
450
|
-
function getTableRowRange(
|
|
451
|
-
table: Extract<SurfaceBlockSnapshot, { kind: "table" }>,
|
|
452
|
-
row: (typeof table.rows)[number],
|
|
453
|
-
): { from: number; to: number } {
|
|
282
|
+
function getTableRowRange(table, row) {
|
|
454
283
|
let from = Number.POSITIVE_INFINITY;
|
|
455
284
|
let to = Number.NEGATIVE_INFINITY;
|
|
456
|
-
|
|
457
285
|
for (const cell of row.cells) {
|
|
458
286
|
const range = getTableCellRange(table, cell);
|
|
459
287
|
from = Math.min(from, range.from);
|
|
460
288
|
to = Math.max(to, range.to);
|
|
461
289
|
}
|
|
462
|
-
|
|
463
|
-
return Number.isFinite(from) && Number.isFinite(to)
|
|
464
|
-
? { from, to }
|
|
465
|
-
: { from: table.from, to: table.to };
|
|
290
|
+
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
466
291
|
}
|
|
467
|
-
|
|
468
|
-
function getTableCellRange(
|
|
469
|
-
table: Extract<SurfaceBlockSnapshot, { kind: "table" }>,
|
|
470
|
-
cell: SurfaceTableCellSnapshot,
|
|
471
|
-
): { from: number; to: number } {
|
|
292
|
+
function getTableCellRange(table, cell) {
|
|
472
293
|
if (cell.content.length === 0) {
|
|
473
294
|
return { from: table.from, to: table.to };
|
|
474
295
|
}
|
|
475
|
-
|
|
476
296
|
let from = Number.POSITIVE_INFINITY;
|
|
477
297
|
let to = Number.NEGATIVE_INFINITY;
|
|
478
298
|
for (const child of cell.content) {
|
|
479
299
|
from = Math.min(from, child.from);
|
|
480
300
|
to = Math.max(to, child.to);
|
|
481
301
|
}
|
|
482
|
-
|
|
483
|
-
return Number.isFinite(from) && Number.isFinite(to)
|
|
484
|
-
? { from, to }
|
|
485
|
-
: { from: table.from, to: table.to };
|
|
302
|
+
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
486
303
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
left: FormattingBreadcrumbItem,
|
|
490
|
-
right: FormattingBreadcrumbItem,
|
|
491
|
-
): boolean {
|
|
492
|
-
return (
|
|
493
|
-
left.kind === right.kind &&
|
|
494
|
-
left.label === right.label &&
|
|
495
|
-
left.from === right.from &&
|
|
496
|
-
left.to === right.to
|
|
497
|
-
);
|
|
304
|
+
function breadcrumbItemsEqual(left, right) {
|
|
305
|
+
return left.kind === right.kind && left.label === right.label && left.from === right.from && left.to === right.to;
|
|
498
306
|
}
|
|
499
|
-
|
|
500
|
-
export function applyFormattingOperationToDocument(
|
|
501
|
-
document: CanonicalDocumentEnvelope,
|
|
502
|
-
snapshot: RuntimeRenderSnapshot,
|
|
503
|
-
operation: FormattingOperation,
|
|
504
|
-
): FormattingMutationResult {
|
|
307
|
+
function applyFormattingOperationToDocument(document, snapshot, operation) {
|
|
505
308
|
const surface = snapshot.surface;
|
|
506
309
|
if (!surface) {
|
|
507
310
|
return {
|
|
508
311
|
document,
|
|
509
312
|
selection: snapshot.selection,
|
|
510
|
-
changed: false
|
|
313
|
+
changed: false
|
|
511
314
|
};
|
|
512
315
|
}
|
|
513
|
-
|
|
514
316
|
const nextDocument = structuredClone(document);
|
|
515
|
-
const root = nextDocument.content
|
|
317
|
+
const root = nextDocument.content;
|
|
516
318
|
let changed = false;
|
|
517
319
|
const selectionFrom = Math.min(snapshot.selection.anchor, snapshot.selection.head);
|
|
518
320
|
const selectionTo = Math.max(snapshot.selection.anchor, snapshot.selection.head);
|
|
519
|
-
|
|
520
321
|
if (operation.type === "set-alignment" || operation.type === "indent" || operation.type === "outdent") {
|
|
521
322
|
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
)
|
|
529
|
-
) {
|
|
323
|
+
if (!selectionTouchesRange(
|
|
324
|
+
snapshot.selection.anchor,
|
|
325
|
+
snapshot.selection.head,
|
|
326
|
+
paragraphSurface.from,
|
|
327
|
+
paragraphSurface.to
|
|
328
|
+
)) {
|
|
530
329
|
return;
|
|
531
330
|
}
|
|
532
|
-
|
|
533
|
-
const paragraphChanged =
|
|
534
|
-
operation.type === "set-alignment"
|
|
535
|
-
? applyAlignment(paragraph, operation.alignment)
|
|
536
|
-
: applyIndentation(paragraph, operation.type === "indent" ? 1 : -1);
|
|
331
|
+
const paragraphChanged = operation.type === "set-alignment" ? applyAlignment(paragraph, operation.alignment) : applyIndentation(paragraph, operation.type === "indent" ? 1 : -1);
|
|
537
332
|
changed = changed || paragraphChanged;
|
|
538
333
|
});
|
|
539
|
-
|
|
540
334
|
return {
|
|
541
335
|
document: changed ? nextDocument : document,
|
|
542
336
|
selection: snapshot.selection,
|
|
543
|
-
changed
|
|
337
|
+
changed
|
|
544
338
|
};
|
|
545
339
|
}
|
|
546
|
-
|
|
547
340
|
if (selectionFrom === selectionTo) {
|
|
548
341
|
return {
|
|
549
342
|
document,
|
|
550
343
|
selection: snapshot.selection,
|
|
551
|
-
changed: false
|
|
344
|
+
changed: false
|
|
552
345
|
};
|
|
553
346
|
}
|
|
554
|
-
|
|
555
347
|
const nextMarks = resolveMarkUpdater(snapshot, operation);
|
|
556
|
-
|
|
557
348
|
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
)
|
|
565
|
-
) {
|
|
349
|
+
if (!rangesOverlap(
|
|
350
|
+
selectionFrom,
|
|
351
|
+
selectionTo,
|
|
352
|
+
paragraphSurface.from,
|
|
353
|
+
paragraphSurface.to
|
|
354
|
+
)) {
|
|
566
355
|
return;
|
|
567
356
|
}
|
|
568
|
-
|
|
569
357
|
const transformed = transformInlineNodes(
|
|
570
358
|
paragraph.children,
|
|
571
359
|
paragraphSurface.from,
|
|
572
360
|
selectionFrom,
|
|
573
361
|
selectionTo,
|
|
574
|
-
nextMarks
|
|
362
|
+
nextMarks
|
|
575
363
|
);
|
|
576
364
|
if (!transformed.changed) {
|
|
577
365
|
return;
|
|
578
366
|
}
|
|
579
|
-
|
|
580
367
|
paragraph.children = transformed.nodes;
|
|
581
368
|
changed = true;
|
|
582
369
|
});
|
|
583
|
-
|
|
584
370
|
return {
|
|
585
371
|
document: changed ? nextDocument : document,
|
|
586
372
|
selection: snapshot.selection,
|
|
587
|
-
changed
|
|
373
|
+
changed
|
|
588
374
|
};
|
|
589
375
|
}
|
|
590
|
-
|
|
591
|
-
function resolveMarkUpdater(
|
|
592
|
-
snapshot: RuntimeRenderSnapshot,
|
|
593
|
-
operation: Exclude<
|
|
594
|
-
FormattingOperation,
|
|
595
|
-
{ type: "set-alignment" } | { type: "indent" } | { type: "outdent" }
|
|
596
|
-
>,
|
|
597
|
-
): (marks?: TextMark[]) => TextMark[] | undefined {
|
|
376
|
+
function resolveMarkUpdater(snapshot, operation) {
|
|
598
377
|
const formatting = getFormattingStateFromRenderSnapshot(snapshot);
|
|
599
|
-
|
|
600
378
|
switch (operation.type) {
|
|
601
379
|
case "toggle":
|
|
602
380
|
return (marks) => toggleMarks(marks, operation.mark, !formatting[operation.mark]);
|
|
@@ -610,65 +388,49 @@ function resolveMarkUpdater(
|
|
|
610
388
|
return (marks) => setMarkValue(marks, "backgroundColor", sanitizeColor(operation.color));
|
|
611
389
|
}
|
|
612
390
|
}
|
|
613
|
-
|
|
614
|
-
function applyAlignment(
|
|
615
|
-
paragraph: ParagraphNode,
|
|
616
|
-
alignment: FormattingAlignment,
|
|
617
|
-
): boolean {
|
|
391
|
+
function applyAlignment(paragraph, alignment) {
|
|
618
392
|
const nextAlignment = alignment === "justify" ? "both" : alignment;
|
|
619
393
|
if (paragraph.alignment === nextAlignment) {
|
|
620
394
|
return false;
|
|
621
395
|
}
|
|
622
|
-
|
|
623
396
|
paragraph.alignment = nextAlignment;
|
|
624
397
|
return true;
|
|
625
398
|
}
|
|
626
|
-
|
|
627
|
-
function applyIndentation(paragraph: ParagraphNode, delta: -1 | 1): boolean {
|
|
399
|
+
function applyIndentation(paragraph, delta) {
|
|
628
400
|
if (paragraph.numbering) {
|
|
629
401
|
const nextLevel = clamp(paragraph.numbering.level + delta, 0, 8);
|
|
630
402
|
if (nextLevel === paragraph.numbering.level) {
|
|
631
403
|
return false;
|
|
632
404
|
}
|
|
633
|
-
|
|
634
405
|
paragraph.numbering = {
|
|
635
406
|
...paragraph.numbering,
|
|
636
|
-
level: nextLevel
|
|
407
|
+
level: nextLevel
|
|
637
408
|
};
|
|
638
409
|
return true;
|
|
639
410
|
}
|
|
640
|
-
|
|
641
411
|
const currentLeft = paragraph.indentation?.left ?? 0;
|
|
642
412
|
const nextLeft = Math.max(0, currentLeft + delta * INDENT_STEP_TWIPS);
|
|
643
413
|
if (nextLeft === currentLeft) {
|
|
644
414
|
return false;
|
|
645
415
|
}
|
|
646
|
-
|
|
647
416
|
const nextIndentation = {
|
|
648
|
-
...
|
|
417
|
+
...paragraph.indentation ?? {}
|
|
649
418
|
};
|
|
650
419
|
if (nextLeft > 0) {
|
|
651
420
|
nextIndentation.left = nextLeft;
|
|
652
421
|
paragraph.indentation = nextIndentation;
|
|
653
422
|
} else if (paragraph.indentation) {
|
|
654
423
|
delete nextIndentation.left;
|
|
655
|
-
paragraph.indentation =
|
|
656
|
-
Object.keys(nextIndentation).length > 0 ? nextIndentation : undefined;
|
|
424
|
+
paragraph.indentation = Object.keys(nextIndentation).length > 0 ? nextIndentation : void 0;
|
|
657
425
|
}
|
|
658
|
-
|
|
659
426
|
return true;
|
|
660
427
|
}
|
|
661
|
-
|
|
662
|
-
function collectParagraphSurfaces(
|
|
663
|
-
blocks: SurfaceBlockSnapshot[],
|
|
664
|
-
output: ParagraphSurfaceBlock[] = [],
|
|
665
|
-
): ParagraphSurfaceBlock[] {
|
|
428
|
+
function collectParagraphSurfaces(blocks, output = []) {
|
|
666
429
|
for (const block of blocks) {
|
|
667
430
|
if (block.kind === "paragraph") {
|
|
668
431
|
output.push(block);
|
|
669
432
|
continue;
|
|
670
433
|
}
|
|
671
|
-
|
|
672
434
|
if (block.kind === "table") {
|
|
673
435
|
for (const row of block.rows) {
|
|
674
436
|
for (const cell of row.cells) {
|
|
@@ -677,72 +439,45 @@ function collectParagraphSurfaces(
|
|
|
677
439
|
}
|
|
678
440
|
continue;
|
|
679
441
|
}
|
|
680
|
-
|
|
681
442
|
if (block.kind === "sdt_block") {
|
|
682
443
|
collectParagraphSurfaces(block.children, output);
|
|
683
444
|
}
|
|
684
445
|
}
|
|
685
|
-
|
|
686
446
|
return output;
|
|
687
447
|
}
|
|
688
|
-
|
|
689
|
-
function collectFormattingTextSegments(
|
|
690
|
-
paragraphs: ParagraphSurfaceBlock[],
|
|
691
|
-
selection: RuntimeRenderSnapshot["selection"],
|
|
692
|
-
): Array<Extract<SurfaceInlineSegment, { kind: "text" }>> {
|
|
448
|
+
function collectFormattingTextSegments(paragraphs, selection) {
|
|
693
449
|
const caret = selection.anchor;
|
|
694
450
|
const isCollapsed = selection.isCollapsed;
|
|
695
451
|
const selectionFrom = Math.min(selection.anchor, selection.head);
|
|
696
452
|
const selectionTo = Math.max(selection.anchor, selection.head);
|
|
697
|
-
const segments
|
|
698
|
-
|
|
453
|
+
const segments = [];
|
|
699
454
|
for (const paragraph of paragraphs) {
|
|
700
455
|
for (const segment of paragraph.segments) {
|
|
701
456
|
if (segment.kind !== "text") {
|
|
702
457
|
continue;
|
|
703
458
|
}
|
|
704
|
-
|
|
705
|
-
if (
|
|
706
|
-
isCollapsed
|
|
707
|
-
? segmentContainsCaret(segment, caret)
|
|
708
|
-
: rangesOverlap(selectionFrom, selectionTo, segment.from, segment.to)
|
|
709
|
-
) {
|
|
459
|
+
if (isCollapsed ? segmentContainsCaret(segment, caret) : rangesOverlap(selectionFrom, selectionTo, segment.from, segment.to)) {
|
|
710
460
|
segments.push(segment);
|
|
711
461
|
}
|
|
712
462
|
}
|
|
713
463
|
}
|
|
714
|
-
|
|
715
464
|
if (!isCollapsed || segments.length > 0) {
|
|
716
465
|
return segments;
|
|
717
466
|
}
|
|
718
|
-
|
|
719
467
|
for (const paragraph of paragraphs) {
|
|
720
468
|
const fallback = paragraph.segments.find(
|
|
721
|
-
(segment)
|
|
722
|
-
segment.kind === "text" && segment.to === caret,
|
|
469
|
+
(segment) => segment.kind === "text" && segment.to === caret
|
|
723
470
|
);
|
|
724
471
|
if (fallback) {
|
|
725
472
|
return [fallback];
|
|
726
473
|
}
|
|
727
474
|
}
|
|
728
|
-
|
|
729
475
|
return [];
|
|
730
476
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
segment: Extract<SurfaceInlineSegment, { kind: "text" }>,
|
|
734
|
-
caret: number,
|
|
735
|
-
): boolean {
|
|
736
|
-
return (
|
|
737
|
-
segment.from <= caret &&
|
|
738
|
-
(caret < segment.to || (segment.to === caret && segment.to > segment.from))
|
|
739
|
-
);
|
|
477
|
+
function segmentContainsCaret(segment, caret) {
|
|
478
|
+
return segment.from <= caret && (caret < segment.to || segment.to === caret && segment.to > segment.from);
|
|
740
479
|
}
|
|
741
|
-
|
|
742
|
-
function segmentHasMark(
|
|
743
|
-
segment: Extract<SurfaceInlineSegment, { kind: "text" }>,
|
|
744
|
-
mark: ToggleFormattingMark,
|
|
745
|
-
): boolean {
|
|
480
|
+
function segmentHasMark(segment, mark) {
|
|
746
481
|
const marks = segment.marks ?? [];
|
|
747
482
|
if (mark === "superscript") {
|
|
748
483
|
return marks.includes("superscript");
|
|
@@ -752,21 +487,12 @@ function segmentHasMark(
|
|
|
752
487
|
}
|
|
753
488
|
return marks.includes(mark);
|
|
754
489
|
}
|
|
755
|
-
|
|
756
|
-
function getConsistentValue<TItem, TValue>(
|
|
757
|
-
items: readonly TItem[],
|
|
758
|
-
getter: (item: TItem) => TValue,
|
|
759
|
-
options: {
|
|
760
|
-
emptyFallback?: TValue;
|
|
761
|
-
} = {},
|
|
762
|
-
): TValue | undefined {
|
|
490
|
+
function getConsistentValue(items, getter, options = {}) {
|
|
763
491
|
if (items.length === 0) {
|
|
764
492
|
return options.emptyFallback;
|
|
765
493
|
}
|
|
766
|
-
|
|
767
|
-
let value: TValue | undefined = undefined;
|
|
494
|
+
let value = void 0;
|
|
768
495
|
let initialized = false;
|
|
769
|
-
|
|
770
496
|
for (const item of items) {
|
|
771
497
|
const next = getter(item);
|
|
772
498
|
if (!initialized) {
|
|
@@ -774,32 +500,23 @@ function getConsistentValue<TItem, TValue>(
|
|
|
774
500
|
initialized = true;
|
|
775
501
|
continue;
|
|
776
502
|
}
|
|
777
|
-
|
|
778
503
|
if (next !== value) {
|
|
779
|
-
return
|
|
504
|
+
return void 0;
|
|
780
505
|
}
|
|
781
506
|
}
|
|
782
|
-
|
|
783
507
|
return value;
|
|
784
508
|
}
|
|
785
|
-
|
|
786
|
-
function visitParagraphBindings(
|
|
787
|
-
blocks: BlockNode[],
|
|
788
|
-
surfaceBlocks: SurfaceBlockSnapshot[],
|
|
789
|
-
visitor: (paragraph: ParagraphNode, surface: ParagraphSurfaceBlock) => void,
|
|
790
|
-
): void {
|
|
509
|
+
function visitParagraphBindings(blocks, surfaceBlocks, visitor) {
|
|
791
510
|
for (let index = 0; index < Math.min(blocks.length, surfaceBlocks.length); index += 1) {
|
|
792
511
|
const block = blocks[index];
|
|
793
512
|
const surface = surfaceBlocks[index];
|
|
794
513
|
if (!block || !surface) {
|
|
795
514
|
continue;
|
|
796
515
|
}
|
|
797
|
-
|
|
798
516
|
if (block.type === "paragraph" && surface.kind === "paragraph") {
|
|
799
517
|
visitor(block, surface);
|
|
800
518
|
continue;
|
|
801
519
|
}
|
|
802
|
-
|
|
803
520
|
if (block.type === "table" && surface.kind === "table") {
|
|
804
521
|
for (let rowIndex = 0; rowIndex < Math.min(block.rows.length, surface.rows.length); rowIndex += 1) {
|
|
805
522
|
const row = block.rows[rowIndex];
|
|
@@ -807,41 +524,26 @@ function visitParagraphBindings(
|
|
|
807
524
|
if (!row || !surfaceRow) {
|
|
808
525
|
continue;
|
|
809
526
|
}
|
|
810
|
-
|
|
811
|
-
for (
|
|
812
|
-
let cellIndex = 0;
|
|
813
|
-
cellIndex < Math.min(row.cells.length, surfaceRow.cells.length);
|
|
814
|
-
cellIndex += 1
|
|
815
|
-
) {
|
|
527
|
+
for (let cellIndex = 0; cellIndex < Math.min(row.cells.length, surfaceRow.cells.length); cellIndex += 1) {
|
|
816
528
|
const cell = row.cells[cellIndex];
|
|
817
529
|
const surfaceCell = surfaceRow.cells[cellIndex];
|
|
818
530
|
if (!cell || !surfaceCell) {
|
|
819
531
|
continue;
|
|
820
532
|
}
|
|
821
|
-
|
|
822
533
|
visitParagraphBindings(cell.children, surfaceCell.content, visitor);
|
|
823
534
|
}
|
|
824
535
|
}
|
|
825
536
|
continue;
|
|
826
537
|
}
|
|
827
|
-
|
|
828
538
|
if (block.type === "sdt" && surface.kind === "sdt_block") {
|
|
829
539
|
visitParagraphBindings(block.children, surface.children, visitor);
|
|
830
540
|
}
|
|
831
541
|
}
|
|
832
542
|
}
|
|
833
|
-
|
|
834
|
-
function transformInlineNodes(
|
|
835
|
-
nodes: InlineNode[],
|
|
836
|
-
start: number,
|
|
837
|
-
selectionFrom: number,
|
|
838
|
-
selectionTo: number,
|
|
839
|
-
updateMarks: (marks?: TextMark[]) => TextMark[] | undefined,
|
|
840
|
-
): { nodes: InlineNode[]; changed: boolean; nextPosition: number } {
|
|
543
|
+
function transformInlineNodes(nodes, start, selectionFrom, selectionTo, updateMarks) {
|
|
841
544
|
let changed = false;
|
|
842
545
|
let position = start;
|
|
843
|
-
const nextNodes
|
|
844
|
-
|
|
546
|
+
const nextNodes = [];
|
|
845
547
|
for (const node of nodes) {
|
|
846
548
|
if (node.type === "text") {
|
|
847
549
|
const transformed = transformTextNode(
|
|
@@ -849,178 +551,141 @@ function transformInlineNodes(
|
|
|
849
551
|
position,
|
|
850
552
|
selectionFrom,
|
|
851
553
|
selectionTo,
|
|
852
|
-
updateMarks
|
|
554
|
+
updateMarks
|
|
853
555
|
);
|
|
854
556
|
nextNodes.push(...transformed.nodes);
|
|
855
557
|
position = transformed.nextPosition;
|
|
856
558
|
changed = changed || transformed.changed;
|
|
857
559
|
continue;
|
|
858
560
|
}
|
|
859
|
-
|
|
860
561
|
if (node.type === "hyperlink") {
|
|
861
562
|
const transformed = transformInlineNodes(
|
|
862
|
-
node.children
|
|
563
|
+
node.children,
|
|
863
564
|
position,
|
|
864
565
|
selectionFrom,
|
|
865
566
|
selectionTo,
|
|
866
|
-
updateMarks
|
|
567
|
+
updateMarks
|
|
867
568
|
);
|
|
868
569
|
nextNodes.push(
|
|
869
|
-
transformed.changed
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}
|
|
874
|
-
: node,
|
|
570
|
+
transformed.changed ? {
|
|
571
|
+
...node,
|
|
572
|
+
children: transformed.nodes
|
|
573
|
+
} : node
|
|
875
574
|
);
|
|
876
575
|
position = transformed.nextPosition;
|
|
877
576
|
changed = changed || transformed.changed;
|
|
878
577
|
continue;
|
|
879
578
|
}
|
|
880
|
-
|
|
881
579
|
nextNodes.push(node);
|
|
882
580
|
position += inlineNodeLength(node);
|
|
883
581
|
}
|
|
884
|
-
|
|
885
582
|
return {
|
|
886
583
|
nodes: nextNodes,
|
|
887
584
|
changed,
|
|
888
|
-
nextPosition: position
|
|
585
|
+
nextPosition: position
|
|
889
586
|
};
|
|
890
587
|
}
|
|
891
|
-
|
|
892
|
-
function transformTextNode(
|
|
893
|
-
node: TextNode,
|
|
894
|
-
start: number,
|
|
895
|
-
selectionFrom: number,
|
|
896
|
-
selectionTo: number,
|
|
897
|
-
updateMarks: (marks?: TextMark[]) => TextMark[] | undefined,
|
|
898
|
-
): { nodes: TextNode[]; changed: boolean; nextPosition: number } {
|
|
588
|
+
function transformTextNode(node, start, selectionFrom, selectionTo, updateMarks) {
|
|
899
589
|
const characters = Array.from(node.text);
|
|
900
590
|
const end = start + characters.length;
|
|
901
591
|
const overlapFrom = Math.max(selectionFrom, start);
|
|
902
592
|
const overlapTo = Math.min(selectionTo, end);
|
|
903
|
-
|
|
904
593
|
if (overlapFrom >= overlapTo) {
|
|
905
594
|
return {
|
|
906
595
|
nodes: [node],
|
|
907
596
|
changed: false,
|
|
908
|
-
nextPosition: end
|
|
597
|
+
nextPosition: end
|
|
909
598
|
};
|
|
910
599
|
}
|
|
911
|
-
|
|
912
600
|
const localFrom = overlapFrom - start;
|
|
913
601
|
const localTo = overlapTo - start;
|
|
914
|
-
const nextNodes
|
|
915
|
-
|
|
602
|
+
const nextNodes = [];
|
|
916
603
|
if (localFrom > 0) {
|
|
917
604
|
nextNodes.push(createTextNode(characters.slice(0, localFrom).join(""), node.marks));
|
|
918
605
|
}
|
|
919
|
-
|
|
920
606
|
const transformedMarks = updateMarks(node.marks);
|
|
921
607
|
nextNodes.push(
|
|
922
|
-
createTextNode(characters.slice(localFrom, localTo).join(""), transformedMarks)
|
|
608
|
+
createTextNode(characters.slice(localFrom, localTo).join(""), transformedMarks)
|
|
923
609
|
);
|
|
924
|
-
|
|
925
610
|
if (localTo < characters.length) {
|
|
926
611
|
nextNodes.push(createTextNode(characters.slice(localTo).join(""), node.marks));
|
|
927
612
|
}
|
|
928
|
-
|
|
929
613
|
return {
|
|
930
614
|
nodes: nextNodes.filter((candidate) => candidate.text.length > 0),
|
|
931
615
|
changed: !marksEqual(node.marks, transformedMarks) || localFrom > 0 || localTo < characters.length,
|
|
932
|
-
nextPosition: end
|
|
616
|
+
nextPosition: end
|
|
933
617
|
};
|
|
934
618
|
}
|
|
935
|
-
|
|
936
|
-
function createTextNode(text: string, marks?: TextMark[]): TextNode {
|
|
619
|
+
function createTextNode(text, marks) {
|
|
937
620
|
return {
|
|
938
621
|
type: "text",
|
|
939
622
|
text,
|
|
940
|
-
...
|
|
623
|
+
...marks && marks.length > 0 ? { marks: cloneMarks(marks) } : {}
|
|
941
624
|
};
|
|
942
625
|
}
|
|
943
|
-
|
|
944
|
-
function toggleMarks(
|
|
945
|
-
marks: TextMark[] | undefined,
|
|
946
|
-
mark: ToggleFormattingMark,
|
|
947
|
-
enabled: boolean,
|
|
948
|
-
): TextMark[] | undefined {
|
|
626
|
+
function toggleMarks(marks, mark, enabled) {
|
|
949
627
|
const nextMarks = cloneMarks(marks);
|
|
950
|
-
|
|
951
628
|
if (mark === "superscript" || mark === "subscript") {
|
|
952
|
-
const
|
|
629
|
+
const filtered2 = nextMarks.filter((candidate) => candidate.type !== "position");
|
|
953
630
|
if (enabled) {
|
|
954
|
-
|
|
631
|
+
filtered2.push({
|
|
955
632
|
type: "position",
|
|
956
|
-
val: mark === "superscript" ? 1 : -1
|
|
633
|
+
val: mark === "superscript" ? 1 : -1
|
|
957
634
|
});
|
|
958
635
|
}
|
|
959
|
-
return
|
|
636
|
+
return filtered2.length > 0 ? filtered2 : void 0;
|
|
960
637
|
}
|
|
961
|
-
|
|
962
638
|
const filtered = nextMarks.filter((candidate) => candidate.type !== mark);
|
|
963
639
|
if (enabled) {
|
|
964
640
|
filtered.push({ type: mark });
|
|
965
641
|
}
|
|
966
|
-
return filtered.length > 0 ? filtered :
|
|
642
|
+
return filtered.length > 0 ? filtered : void 0;
|
|
967
643
|
}
|
|
968
|
-
|
|
969
|
-
function setMarkValue(
|
|
970
|
-
marks: TextMark[] | undefined,
|
|
971
|
-
markType: "fontFamily" | "fontSize" | "textColor" | "backgroundColor",
|
|
972
|
-
value: string | number | null,
|
|
973
|
-
): TextMark[] | undefined {
|
|
644
|
+
function setMarkValue(marks, markType, value) {
|
|
974
645
|
const nextMarks = cloneMarks(marks).filter((candidate) => {
|
|
975
646
|
if (markType === "backgroundColor") {
|
|
976
647
|
return candidate.type !== "backgroundColor" && candidate.type !== "highlight";
|
|
977
648
|
}
|
|
978
649
|
return candidate.type !== markType;
|
|
979
650
|
});
|
|
980
|
-
|
|
981
651
|
if (value !== null) {
|
|
982
652
|
switch (markType) {
|
|
983
653
|
case "fontFamily":
|
|
984
|
-
nextMarks.push({ type: "fontFamily", val: value
|
|
654
|
+
nextMarks.push({ type: "fontFamily", val: value });
|
|
985
655
|
break;
|
|
986
656
|
case "fontSize":
|
|
987
|
-
nextMarks.push({ type: "fontSize", val: value
|
|
657
|
+
nextMarks.push({ type: "fontSize", val: value });
|
|
988
658
|
break;
|
|
989
659
|
case "textColor":
|
|
990
|
-
nextMarks.push({ type: "textColor", color: value
|
|
660
|
+
nextMarks.push({ type: "textColor", color: value });
|
|
991
661
|
break;
|
|
992
662
|
case "backgroundColor":
|
|
993
|
-
nextMarks.push({ type: "backgroundColor", color: value
|
|
663
|
+
nextMarks.push({ type: "backgroundColor", color: value });
|
|
994
664
|
break;
|
|
995
665
|
}
|
|
996
666
|
}
|
|
997
|
-
|
|
998
|
-
return nextMarks.length > 0 ? nextMarks : undefined;
|
|
667
|
+
return nextMarks.length > 0 ? nextMarks : void 0;
|
|
999
668
|
}
|
|
1000
|
-
|
|
1001
|
-
function cloneMarks(marks?: TextMark[]): TextMark[] {
|
|
669
|
+
function cloneMarks(marks) {
|
|
1002
670
|
return marks ? marks.map((mark) => ({ ...mark })) : [];
|
|
1003
671
|
}
|
|
1004
|
-
|
|
1005
|
-
function marksEqual(left?: TextMark[], right?: TextMark[]): boolean {
|
|
672
|
+
function marksEqual(left, right) {
|
|
1006
673
|
if (!left?.length && !right?.length) {
|
|
1007
674
|
return true;
|
|
1008
675
|
}
|
|
1009
676
|
if (!left || !right || left.length !== right.length) {
|
|
1010
677
|
return false;
|
|
1011
678
|
}
|
|
1012
|
-
|
|
1013
679
|
return left.every((mark, index) => JSON.stringify(mark) === JSON.stringify(right[index]));
|
|
1014
680
|
}
|
|
1015
|
-
|
|
1016
|
-
function inlineNodeLength(node: InlineNode): number {
|
|
681
|
+
function inlineNodeLength(node) {
|
|
1017
682
|
switch (node.type) {
|
|
1018
683
|
case "text":
|
|
1019
684
|
return Array.from(node.text).length;
|
|
1020
685
|
case "hyperlink":
|
|
1021
|
-
return node.children.reduce
|
|
1022
|
-
(total, child) => total + inlineNodeLength(child
|
|
1023
|
-
0
|
|
686
|
+
return node.children.reduce(
|
|
687
|
+
(total, child) => total + inlineNodeLength(child),
|
|
688
|
+
0
|
|
1024
689
|
);
|
|
1025
690
|
case "hard_break":
|
|
1026
691
|
case "column_break":
|
|
@@ -1036,19 +701,16 @@ function inlineNodeLength(node: InlineNode): number {
|
|
|
1036
701
|
case "vml_shape":
|
|
1037
702
|
return 1;
|
|
1038
703
|
case "field":
|
|
1039
|
-
return node.children.reduce
|
|
1040
|
-
(total, child) => total + inlineNodeLength(child
|
|
1041
|
-
0
|
|
704
|
+
return node.children.reduce(
|
|
705
|
+
(total, child) => total + inlineNodeLength(child),
|
|
706
|
+
0
|
|
1042
707
|
);
|
|
1043
708
|
case "bookmark_start":
|
|
1044
709
|
case "bookmark_end":
|
|
1045
710
|
return 0;
|
|
1046
711
|
}
|
|
1047
712
|
}
|
|
1048
|
-
|
|
1049
|
-
function toPublicAlignment(
|
|
1050
|
-
alignment: ParagraphNode["alignment"] | undefined,
|
|
1051
|
-
): FormattingAlignment | undefined {
|
|
713
|
+
function toPublicAlignment(alignment) {
|
|
1052
714
|
switch (alignment) {
|
|
1053
715
|
case "both":
|
|
1054
716
|
case "distribute":
|
|
@@ -1058,49 +720,34 @@ function toPublicAlignment(
|
|
|
1058
720
|
case "right":
|
|
1059
721
|
return alignment;
|
|
1060
722
|
default:
|
|
1061
|
-
return
|
|
723
|
+
return void 0;
|
|
1062
724
|
}
|
|
1063
725
|
}
|
|
1064
|
-
|
|
1065
|
-
function toPublicColor(color: string | undefined): string | undefined {
|
|
726
|
+
function toPublicColor(color) {
|
|
1066
727
|
if (!color) {
|
|
1067
|
-
return
|
|
728
|
+
return void 0;
|
|
1068
729
|
}
|
|
1069
|
-
|
|
1070
|
-
return /^[0-9A-F]{3,8}$/iu.test(color)
|
|
1071
|
-
? `#${color.toUpperCase()}`
|
|
1072
|
-
: color;
|
|
730
|
+
return /^[0-9A-F]{3,8}$/iu.test(color) ? `#${color.toUpperCase()}` : color;
|
|
1073
731
|
}
|
|
1074
|
-
|
|
1075
|
-
function sanitizeFontFamily(fontFamily: string | null): string | null {
|
|
732
|
+
function sanitizeFontFamily(fontFamily) {
|
|
1076
733
|
const normalized = fontFamily?.trim();
|
|
1077
734
|
return normalized ? normalized : null;
|
|
1078
735
|
}
|
|
1079
|
-
|
|
1080
|
-
function sanitizeFontSize(size: number | null): number | null {
|
|
736
|
+
function sanitizeFontSize(size) {
|
|
1081
737
|
if (typeof size !== "number" || !Number.isFinite(size) || size <= 0) {
|
|
1082
738
|
return null;
|
|
1083
739
|
}
|
|
1084
|
-
|
|
1085
740
|
return Math.round(size * 2);
|
|
1086
741
|
}
|
|
1087
|
-
|
|
1088
|
-
function sanitizeColor(color: string | null): string | null {
|
|
742
|
+
function sanitizeColor(color) {
|
|
1089
743
|
const normalized = color?.trim();
|
|
1090
744
|
if (!normalized) {
|
|
1091
745
|
return null;
|
|
1092
746
|
}
|
|
1093
|
-
|
|
1094
747
|
const raw = normalized.startsWith("#") ? normalized.slice(1) : normalized;
|
|
1095
748
|
return /^[0-9A-F]{3,8}$/iu.test(raw) ? raw.toUpperCase() : null;
|
|
1096
749
|
}
|
|
1097
|
-
|
|
1098
|
-
function selectionTouchesRange(
|
|
1099
|
-
anchor: number,
|
|
1100
|
-
head: number,
|
|
1101
|
-
rangeFrom: number,
|
|
1102
|
-
rangeTo: number,
|
|
1103
|
-
): boolean {
|
|
750
|
+
function selectionTouchesRange(anchor, head, rangeFrom, rangeTo) {
|
|
1104
751
|
const selectionFrom = Math.min(anchor, head);
|
|
1105
752
|
const selectionTo = Math.max(anchor, head);
|
|
1106
753
|
if (selectionFrom === selectionTo) {
|
|
@@ -1108,13 +755,7 @@ function selectionTouchesRange(
|
|
|
1108
755
|
}
|
|
1109
756
|
return rangesOverlap(selectionFrom, selectionTo, rangeFrom, rangeTo);
|
|
1110
757
|
}
|
|
1111
|
-
|
|
1112
|
-
function rangesOverlap(
|
|
1113
|
-
leftFrom: number,
|
|
1114
|
-
leftTo: number,
|
|
1115
|
-
rightFrom: number,
|
|
1116
|
-
rightTo: number,
|
|
1117
|
-
): boolean {
|
|
758
|
+
function rangesOverlap(leftFrom, leftTo, rightFrom, rightTo) {
|
|
1118
759
|
if (leftFrom === leftTo) {
|
|
1119
760
|
return leftFrom >= rightFrom && leftFrom <= rightTo;
|
|
1120
761
|
}
|
|
@@ -1123,7 +764,26 @@ function rangesOverlap(
|
|
|
1123
764
|
}
|
|
1124
765
|
return leftFrom < rightTo && leftTo > rightFrom;
|
|
1125
766
|
}
|
|
1126
|
-
|
|
1127
|
-
function clamp(value: number, min: number, max: number): number {
|
|
767
|
+
function clamp(value, min, max) {
|
|
1128
768
|
return Math.min(max, Math.max(min, value));
|
|
1129
769
|
}
|
|
770
|
+
|
|
771
|
+
export {
|
|
772
|
+
makeToggleBold,
|
|
773
|
+
makeToggleItalic,
|
|
774
|
+
makeToggleUnderline,
|
|
775
|
+
makeToggleStrikethrough,
|
|
776
|
+
makeToggleSuperscript,
|
|
777
|
+
makeToggleSubscript,
|
|
778
|
+
makeToggleSmallCaps,
|
|
779
|
+
makeToggleAllCaps,
|
|
780
|
+
makeSetFontFamily,
|
|
781
|
+
makeSetFontSize,
|
|
782
|
+
makeSetTextColor,
|
|
783
|
+
makeSetHighlight,
|
|
784
|
+
makeSetAlignment,
|
|
785
|
+
isMarkActive,
|
|
786
|
+
getFormattingStateFromRenderSnapshot,
|
|
787
|
+
applyFormattingOperationToDocument
|
|
788
|
+
};
|
|
789
|
+
//# sourceMappingURL=chunk-TJBP2K4T.js.map
|