@stll/folio-core 0.51.0 → 0.53.0
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/README.md +23 -0
- package/dist/ai-edits/apply.d.ts +26 -1
- package/dist/ai-edits/apply.js +1519 -105
- package/dist/ai-edits/batch-claims.d.ts +130 -0
- package/dist/ai-edits/batch-claims.js +244 -0
- package/dist/ai-edits/blockRange.js +9 -3
- package/dist/ai-edits/character-boundaries.d.ts +43 -0
- package/dist/ai-edits/character-boundaries.js +95 -0
- package/dist/ai-edits/clean-text.d.ts +33 -3
- package/dist/ai-edits/clean-text.js +52 -6
- package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
- package/dist/ai-edits/comment-lifecycle.js +52 -0
- package/dist/ai-edits/headless.d.ts +71 -7
- package/dist/ai-edits/headless.js +381 -41
- package/dist/ai-edits/index.d.ts +2 -1
- package/dist/ai-edits/index.js +2 -1
- package/dist/ai-edits/minimal-replacement.d.ts +21 -6
- package/dist/ai-edits/minimal-replacement.js +134 -15
- package/dist/ai-edits/newListNumbering.d.ts +23 -0
- package/dist/ai-edits/newListNumbering.js +94 -0
- package/dist/ai-edits/note-references.d.ts +96 -0
- package/dist/ai-edits/note-references.js +139 -0
- package/dist/ai-edits/pending-suggestions.d.ts +79 -0
- package/dist/ai-edits/pending-suggestions.js +306 -0
- package/dist/ai-edits/read.d.ts +1 -1
- package/dist/ai-edits/read.js +56 -43
- package/dist/ai-edits/result-validation.d.ts +29 -0
- package/dist/ai-edits/result-validation.js +164 -0
- package/dist/ai-edits/snapshot.d.ts +36 -3
- package/dist/ai-edits/snapshot.js +177 -23
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +4 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +38 -16
- package/dist/ai-edits/table-row-column-mutations.js +61 -26
- package/dist/ai-edits/types.d.ts +155 -16
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/compare.js +65 -16
- package/dist/compare/content-alignment.js +13 -2
- package/dist/compare/content-types.d.ts +7 -0
- package/dist/compare/content.d.ts +4 -1
- package/dist/compare/content.js +6 -1
- package/dist/compare/formatting.js +2 -1
- package/dist/compare/inline-atoms.d.ts +21 -4
- package/dist/compare/inline-atoms.js +138 -16
- package/dist/compare/inline-provenance.js +18 -22
- package/dist/compare/plan.js +10 -5
- package/dist/compare/scenario.js +14 -3
- package/dist/compare/section-boundary-properties.js +14 -1
- package/dist/compare/types.d.ts +4 -2
- package/dist/compare/types.js +2 -1
- package/dist/compare/verification.d.ts +1 -1
- package/dist/compare/verification.js +15 -3
- package/dist/controller/committedLayoutDiff.d.ts +25 -0
- package/dist/controller/committedLayoutDiff.js +71 -0
- package/dist/controller/contentControlWidgetController.d.ts +1 -1
- package/dist/controller/folioEditor.d.ts +1 -1
- package/dist/controller/fontReadiness.d.ts +70 -3
- package/dist/controller/fontReadiness.js +100 -10
- package/dist/controller/headerFooterEditorManager.js +6 -1
- package/dist/controller/layoutPipeline.d.ts +12 -10
- package/dist/controller/layoutPipeline.js +62 -9
- package/dist/controller/layoutRunOptions.d.ts +24 -0
- package/dist/controller/layoutRunOptions.js +17 -0
- package/dist/controller/layoutScheduler.d.ts +19 -14
- package/dist/controller/layoutScheduler.js +15 -12
- package/dist/controller/layoutSession.d.ts +26 -2
- package/dist/controller/layoutSession.js +1 -1
- package/dist/controller/noteEditorManager.js +8 -3
- package/dist/document-operations.d.ts +11 -2
- package/dist/document-operations.js +230 -21
- package/dist/docx/altChunk.d.ts +8 -0
- package/dist/docx/altChunk.js +17 -0
- package/dist/docx/attributeRemainder.d.ts +1 -1
- package/dist/docx/blockContentParser.d.ts +64 -1
- package/dist/docx/blockContentParser.js +17 -4
- package/dist/docx/blockCustomXmlShell.d.ts +7 -0
- package/dist/docx/blockCustomXmlShell.js +14 -0
- package/dist/docx/blockPlainText.js +7 -0
- package/dist/docx/commentAnchorIndex.js +1 -1
- package/dist/docx/commentRangeIntegrity.js +8 -3
- package/dist/docx/commentReferenceNormalization.js +1 -1
- package/dist/docx/commentReplyMarkers.js +20 -1
- package/dist/docx/compatibility.d.ts +1 -1
- package/dist/docx/compatibility.js +34 -13
- package/dist/docx/containerChildren.gen.d.ts +1 -1
- package/dist/docx/containerChildren.gen.js +1 -0
- package/dist/docx/documentParser.js +12 -12
- package/dist/docx/drawingIdNormalization.d.ts +3 -1
- package/dist/docx/drawingIdNormalization.js +6 -1
- package/dist/docx/ensureParaIds.js +119 -97
- package/dist/docx/footnoteParser.js +8 -4
- package/dist/docx/headerFooterParser.js +3 -3
- package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
- package/dist/docx/headerFooterReferenceNormalization.js +52 -27
- package/dist/docx/hyperlinkParser.d.ts +1 -1
- package/dist/docx/index.d.ts +1 -1
- package/dist/docx/listNumberingInstances.d.ts +59 -0
- package/dist/docx/listNumberingInstances.js +249 -0
- package/dist/docx/normalizeBaseDirection.js +2 -1
- package/dist/docx/opaqueCarrier.d.ts +7 -0
- package/dist/docx/opaqueCarrier.js +38 -0
- package/dist/docx/packageParts.js +4 -1
- package/dist/docx/paragraphParser.js +91 -24
- package/dist/docx/paragraphPropertySource.d.ts +4 -2
- package/dist/docx/paragraphPropertySource.js +7 -1
- package/dist/docx/paragraphTraversal.js +1 -0
- package/dist/docx/parseWarningMessage.js +4 -1
- package/dist/docx/parser.js +173 -20
- package/dist/docx/rezip.js +27 -5
- package/dist/docx/sdtProperties.js +1 -1
- package/dist/docx/sdtPropertiesPatch.js +3 -0
- package/dist/docx/selectiveSave.js +16 -9
- package/dist/docx/selectiveXmlPatch.js +106 -37
- package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
- package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
- package/dist/docx/serializer/documentSerializer.js +2 -0
- package/dist/docx/serializer/headerFooterSerializer.js +2 -0
- package/dist/docx/serializer/noteSerializer.js +3 -1
- package/dist/docx/serializer/paragraphSerializer.js +33 -9
- package/dist/docx/serializer/tableSerializer.js +25 -38
- package/dist/docx/server/createBilingualDocument.js +3 -3
- package/dist/docx/tableParser.d.ts +157 -1
- package/dist/docx/tableParser.js +89 -10
- package/dist/docx/textBoxParser.js +1 -1
- package/dist/docx/unzip.d.ts +2 -1
- package/dist/docx/unzip.js +1 -1
- package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
- package/dist/docx/wordprocessingPrefixes.js +286 -0
- package/dist/generated/text_shaper.js +26 -0
- package/dist/generated/text_shaper_bg.wasm +0 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +136 -0
- package/dist/i18n/messages/catalogs.gen.js +153 -17
- package/dist/i18n/messages/messages.gen.d.ts +8 -0
- package/dist/internal/compare/inline-presentation.d.ts +2 -1
- package/dist/internal/compare/inline-presentation.js +11 -10
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
- package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
- package/dist/internal/indexedPositionMap.d.ts +11 -0
- package/dist/internal/indexedPositionMap.js +42 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/revisionResolutionEdits.d.ts +13 -0
- package/dist/internal/revisionResolutionEdits.js +19 -0
- package/dist/internal/revisionResolutionInline.d.ts +24 -0
- package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
- package/dist/internal/revisionResolutionStep.d.ts +34 -0
- package/dist/internal/revisionResolutionStep.js +282 -0
- package/dist/internal/revisionResolutionTracking.d.ts +11 -0
- package/dist/internal/revisionResolutionTracking.js +124 -0
- package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
- package/dist/internal/wholeStoryRevisionResolution.js +530 -0
- package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
- package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
- package/dist/layout-bridge/convert/tableConversion.js +1 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
- package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
- package/dist/layout-engine/layoutInstrumentation.js +4 -1
- package/dist/layout-engine/measure/cache.d.ts +18 -1
- package/dist/layout-engine/measure/cache.js +31 -1
- package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
- package/dist/layout-engine/measure/measureContainer.js +7 -47
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
- package/dist/layout-engine/measure/measureHelpers.js +22 -2
- package/dist/layout-engine/measure/measureWorker.js +2 -3
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
- package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/renderPage.js +1 -0
- package/dist/layout-painter/renderParagraph.js +1 -1
- package/dist/managers/ContextMenuManager.js +5 -2
- package/dist/managers/types.d.ts +3 -0
- package/dist/markdown/fromMarkdown.js +2 -1
- package/dist/markdown/internals.d.ts +11 -1
- package/dist/markdown/internals.js +24 -3
- package/dist/markdown/renderBlock.js +39 -9
- package/dist/markdown/renderParagraph.d.ts +13 -1
- package/dist/markdown/renderParagraph.js +85 -38
- package/dist/markdown/renderRuns.js +3 -10
- package/dist/markdown/renderTable.js +24 -12
- package/dist/markdown/trailers.js +2 -2
- package/dist/markdown/types.d.ts +29 -7
- package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
- package/dist/paged-layout/incrementalMeasure.js +1 -9
- package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
- package/dist/paged-layout/transactionDirtyRange.js +29 -41
- package/dist/panel-layout.d.ts +83 -0
- package/dist/panel-layout.js +96 -0
- package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
- package/dist/prosemirror/anchoredTextBoxes.js +156 -0
- package/dist/prosemirror/attrs/index.d.ts +6 -2
- package/dist/prosemirror/attrs/index.js +172 -1
- package/dist/prosemirror/commands/comments.d.ts +7 -8
- package/dist/prosemirror/commands/comments.js +241 -207
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +2 -2
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +7 -1
- package/dist/prosemirror/commands/paragraph.js +9 -1
- package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
- package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
- package/dist/prosemirror/commands/resolveAllTableChanges.js +615 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.js +59 -0
- package/dist/prosemirror/commands/sectionBreak.js +2 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +8 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.js +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +181 -31
- package/dist/prosemirror/conversion/toProseDoc.js +39 -4
- package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
- package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
- package/dist/prosemirror/extensions/StarterKit.js +3 -1
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +12 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +161 -123
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
- package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +126 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +21 -5
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +7 -2
- package/dist/prosemirror/extensions/marks/markUtils.js +8 -2
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +35 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +19 -18
- package/dist/prosemirror/extensions/types.d.ts +4 -1
- package/dist/prosemirror/findReplaceSelection.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -2
- package/dist/prosemirror/index.js +3 -2
- package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
- package/dist/prosemirror/indexedNodeLookup.js +103 -0
- package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
- package/dist/prosemirror/listAutoformatMarkers.js +98 -0
- package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
- package/dist/prosemirror/listInstanceReferences.js +72 -0
- package/dist/prosemirror/listLabels.d.ts +24 -0
- package/dist/prosemirror/listLabels.js +111 -0
- package/dist/prosemirror/listNumbering.d.ts +110 -0
- package/dist/prosemirror/listNumbering.js +345 -0
- package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
- package/dist/prosemirror/listRenderingAttrs.js +8 -1
- package/dist/prosemirror/markupViewProjection.d.ts +95 -0
- package/dist/prosemirror/markupViewProjection.js +83 -0
- package/dist/prosemirror/numberingAttr.d.ts +9 -1
- package/dist/prosemirror/numberingAttr.js +9 -1
- package/dist/prosemirror/outlineLevelAttr.js +1 -1
- package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
- package/dist/prosemirror/paragraphIndentation.js +29 -7
- package/dist/prosemirror/paragraphMarkJoin.d.ts +19 -0
- package/dist/prosemirror/paragraphMarkJoin.js +24 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
- package/dist/prosemirror/plugins/documentNumbering.js +97 -11
- package/dist/prosemirror/plugins/documentStyles.d.ts +10 -1
- package/dist/prosemirror/plugins/documentStyles.js +14 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +16 -2
- package/dist/prosemirror/plugins/suggestionMode.js +116 -52
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
- package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
- package/dist/prosemirror/positionSweep.d.ts +24 -0
- package/dist/prosemirror/positionSweep.js +222 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
- package/dist/prosemirror/replacedAnnotations.js +170 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/runStyleFormatting.d.ts +7 -1
- package/dist/prosemirror/runStyleFormatting.js +13 -7
- package/dist/prosemirror/schema/index.d.ts +2 -2
- package/dist/prosemirror/schema/index.js +3 -0
- package/dist/prosemirror/schema/nodes.d.ts +42 -11
- package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
- package/dist/prosemirror/sectionMarkEdits.js +59 -0
- package/dist/prosemirror/storyListNumbering.d.ts +17 -0
- package/dist/prosemirror/storyListNumbering.js +102 -0
- package/dist/prosemirror/tableGridMutation.d.ts +48 -2
- package/dist/prosemirror/tableGridMutation.js +106 -1
- package/dist/prosemirror/validation.js +5 -1
- package/dist/redline.js +93 -9
- package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
- package/dist/render-dom/BodySelectionOverlay.js +3 -2
- package/dist/shaping/shaper.d.ts +47 -4
- package/dist/shaping/shaper.js +46 -15
- package/dist/text-shaping.d.ts +4 -0
- package/dist/text-shaping.js +4 -0
- package/dist/utils/findReplace.js +2 -2
- package/dist/utils/mergeDocumentContent.js +1 -1
- package/dist/utils/noteReferenceLabels.d.ts +36 -0
- package/dist/utils/noteReferenceLabels.js +32 -0
- package/dist/utils/replaceText.js +1 -1
- package/dist/version-comparison.d.ts +1 -0
- package/dist/version-comparison.js +1 -0
- package/package.json +8 -2
- package/dist/internal/headlessRevisionResolution.d.ts +0 -23
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { getProseParagraphPropertySourceToken, recreateProseNodeWithParagraphPropertySource } from "../docx/paragraphPropertySource.js";
|
|
2
|
+
import { anchoredTextBoxId, droppedTextBoxAnchorIds } from "../prosemirror/anchoredTextBoxes.js";
|
|
3
|
+
import { expectParagraphAttrs } from "../prosemirror/attrs/index.js";
|
|
4
|
+
import { inlineBookmarksOf } from "../prosemirror/commands/paragraphBookmarkJoin.js";
|
|
5
|
+
import { resolveAllTableChanges } from "../prosemirror/commands/resolveAllTableChanges.js";
|
|
6
|
+
import { resolveAllNodePropertyChangeAttrs } from "../prosemirror/commands/resolveNodePropertyChangeAttrs.js";
|
|
7
|
+
import { resolveParagraphChangeAttrs } from "../prosemirror/commands/resolveParagraphProperties.js";
|
|
8
|
+
import { expandRunFormattingCarrier } from "../prosemirror/runFormattingInlineCarriers.js";
|
|
9
|
+
import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "../prosemirror/runFormattingReconciliation.js";
|
|
10
|
+
import { paragraphRunStyleContext } from "../prosemirror/runStyleFormatting.js";
|
|
11
|
+
import { holdsNoContent } from "../prosemirror/zeroWidthAnchors.js";
|
|
12
|
+
import { recordNodeResolution } from "./revisionResolutionEdits.js";
|
|
13
|
+
import { resolveInlineRevisions } from "./revisionResolutionInline.js";
|
|
14
|
+
import { composeRevisionResolutionMaps } from "./revisionResolutionStep.js";
|
|
15
|
+
import { REVIEW_CARRIERS } from "@stll/docx-core/model";
|
|
16
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
17
|
+
import { Mapping, ReplaceStep, StepMap } from "prosemirror-transform";
|
|
18
|
+
//#region src/internal/wholeStoryRevisionResolution.ts
|
|
19
|
+
const resolveProperties = ({ doc, mode, styleResolver, numbering, steps, changedRanges }) => {
|
|
20
|
+
let structural = false;
|
|
21
|
+
const walk = (node, position) => {
|
|
22
|
+
if (node.isText) return node;
|
|
23
|
+
const nextAttrs = node.type.name === "paragraph" ? resolveParagraphChangeAttrs({
|
|
24
|
+
node,
|
|
25
|
+
mode,
|
|
26
|
+
boundaryCovered: true,
|
|
27
|
+
revisionSet: null,
|
|
28
|
+
styleResolver,
|
|
29
|
+
numbering
|
|
30
|
+
}) : null;
|
|
31
|
+
let resolved = node;
|
|
32
|
+
if (nextAttrs) resolved = recreateProseNodeWithParagraphPropertySource(node, { attrs: nextAttrs });
|
|
33
|
+
else if (node.type.name !== "paragraph") resolved = resolveAllNodePropertyChangeAttrs(node, mode);
|
|
34
|
+
if (resolved !== node) {
|
|
35
|
+
if (node.type.name === "paragraph") changedRanges.push({
|
|
36
|
+
from: position,
|
|
37
|
+
to: position + node.nodeSize
|
|
38
|
+
});
|
|
39
|
+
structural ||= node.type.name !== "paragraph";
|
|
40
|
+
}
|
|
41
|
+
if (position >= 0) recordNodeResolution({
|
|
42
|
+
before: node,
|
|
43
|
+
after: resolved,
|
|
44
|
+
position,
|
|
45
|
+
steps
|
|
46
|
+
});
|
|
47
|
+
const rebased = /* @__PURE__ */ new Map();
|
|
48
|
+
if (node.type.name === "paragraph" && styleResolver && nextAttrs && nextAttrs["styleId"] !== node.attrs["styleId"]) {
|
|
49
|
+
const previousContext = paragraphRunStyleContext(node, styleResolver);
|
|
50
|
+
const nextContext = paragraphRunStyleContext(resolved, styleResolver);
|
|
51
|
+
node.descendants((inline, pos) => {
|
|
52
|
+
if (!inline.isInline) return true;
|
|
53
|
+
const carrier = expandRunFormattingCarrier(inline, pos);
|
|
54
|
+
if (!carrier) return !inline.isAtom;
|
|
55
|
+
for (const { node: representation } of carrier.representations) {
|
|
56
|
+
if (mode === "reject" && representation.marks.some(({ type }) => type.name === "deletion") && representation.marks.some(({ type }) => type.name === "runFormattingOverride")) continue;
|
|
57
|
+
const marks = reconcileRunFormattingMarks({
|
|
58
|
+
authoredFormatting: readAuthoredRunFormatting({
|
|
59
|
+
context: previousContext,
|
|
60
|
+
marks: representation.marks,
|
|
61
|
+
styleResolver
|
|
62
|
+
}),
|
|
63
|
+
context: nextContext,
|
|
64
|
+
node: representation,
|
|
65
|
+
styleResolver
|
|
66
|
+
});
|
|
67
|
+
rebased.set(representation, representation.mark(marks));
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const children = [];
|
|
73
|
+
let changed = false;
|
|
74
|
+
const visitChild = (child, childPosition) => {
|
|
75
|
+
const replacement = rebased.get(child) ?? child;
|
|
76
|
+
if (rebased.size === 0) return walk(replacement, childPosition);
|
|
77
|
+
recordNodeResolution({
|
|
78
|
+
before: child,
|
|
79
|
+
after: replacement,
|
|
80
|
+
position: childPosition,
|
|
81
|
+
steps
|
|
82
|
+
});
|
|
83
|
+
if (replacement.isLeaf) return replacement;
|
|
84
|
+
const nested = [];
|
|
85
|
+
replacement.forEach((inner, offset) => nested.push(visitChild(inner, childPosition + 1 + offset)));
|
|
86
|
+
return recreateProseNodeWithParagraphPropertySource(replacement, { content: nested });
|
|
87
|
+
};
|
|
88
|
+
resolved.forEach((child, offset) => {
|
|
89
|
+
const result = visitChild(child, position + 1 + offset);
|
|
90
|
+
children.push(result);
|
|
91
|
+
changed ||= result !== child;
|
|
92
|
+
});
|
|
93
|
+
return changed ? recreateProseNodeWithParagraphPropertySource(resolved, { content: children }) : resolved;
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
resolved: walk(doc, -1),
|
|
97
|
+
structural
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const structuralReplacementMap = ({ replacements, tables, bookmarkJoins, origin }) => {
|
|
101
|
+
const tablesByPosition = new Map(tables.map((table) => [table.position, table]));
|
|
102
|
+
const bookmarkJoinsByPosition = new Map(bookmarkJoins.map((join) => [join.from, join]));
|
|
103
|
+
const ranges = [];
|
|
104
|
+
const mapFor = ({ from, to, slice }) => {
|
|
105
|
+
const table = tablesByPosition.get(from);
|
|
106
|
+
if (table && table.sourceNodeSize === to - from) {
|
|
107
|
+
const tableRanges = [];
|
|
108
|
+
table.positionMap.forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
109
|
+
tableRanges.push(from - origin + oldStart, oldEnd - oldStart, newEnd - newStart);
|
|
110
|
+
});
|
|
111
|
+
return new StepMap(tableRanges);
|
|
112
|
+
}
|
|
113
|
+
const bookmarkJoin = bookmarkJoinsByPosition.get(from);
|
|
114
|
+
if (bookmarkJoin?.to === to) {
|
|
115
|
+
const joinRanges = [];
|
|
116
|
+
bookmarkJoin.positionMap.forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
117
|
+
joinRanges.push(from - origin + oldStart, oldEnd - oldStart, newEnd - newStart);
|
|
118
|
+
});
|
|
119
|
+
return new StepMap(joinRanges);
|
|
120
|
+
}
|
|
121
|
+
return new StepMap([
|
|
122
|
+
from - origin,
|
|
123
|
+
to - from,
|
|
124
|
+
slice.size
|
|
125
|
+
]);
|
|
126
|
+
};
|
|
127
|
+
const isDeletion = ({ from, to, slice }) => slice.size === 0 && !tablesByPosition.has(from) && to > from;
|
|
128
|
+
const groupMap = (group) => {
|
|
129
|
+
if (group.every(isDeletion)) {
|
|
130
|
+
const first = group.at(0);
|
|
131
|
+
if (!first) return StepMap.empty;
|
|
132
|
+
let end = first.to;
|
|
133
|
+
for (const replacement of group.slice(1)) end += replacement.to - replacement.from;
|
|
134
|
+
return new StepMap([
|
|
135
|
+
first.from - origin,
|
|
136
|
+
end - first.from,
|
|
137
|
+
0
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
let maps = group.toReversed().map(mapFor);
|
|
141
|
+
while (maps.length > 1) {
|
|
142
|
+
const combined = [];
|
|
143
|
+
for (let index = 0; index < maps.length; index += 2) {
|
|
144
|
+
const first = maps.at(index);
|
|
145
|
+
const second = maps.at(index + 1);
|
|
146
|
+
if (!first) break;
|
|
147
|
+
combined.push(second ? composeRevisionResolutionMaps(first, second) : first);
|
|
148
|
+
}
|
|
149
|
+
maps = combined;
|
|
150
|
+
}
|
|
151
|
+
return maps.at(0) ?? StepMap.empty;
|
|
152
|
+
};
|
|
153
|
+
let group = [];
|
|
154
|
+
let influenceEnd = -1;
|
|
155
|
+
const flush = () => {
|
|
156
|
+
groupMap(group).forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
157
|
+
const last = ranges.length - 3;
|
|
158
|
+
const previousStart = ranges.at(last);
|
|
159
|
+
const previousOldSize = ranges.at(last + 1);
|
|
160
|
+
if (last >= 0 && previousStart !== void 0 && previousOldSize !== void 0 && ranges.at(last + 2) === 0 && newEnd === newStart && previousStart + previousOldSize === oldStart) {
|
|
161
|
+
ranges[last + 1] = previousOldSize + oldEnd - oldStart;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
ranges.push(oldStart, oldEnd - oldStart, newEnd - newStart);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
for (const replacement of replacements) {
|
|
168
|
+
if (group.length > 0 && replacement.from >= influenceEnd) {
|
|
169
|
+
flush();
|
|
170
|
+
group = [];
|
|
171
|
+
}
|
|
172
|
+
if (group.length === 0) {
|
|
173
|
+
group.push(replacement);
|
|
174
|
+
influenceEnd = replacement.to;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
group.push(replacement);
|
|
178
|
+
influenceEnd += replacement.to - replacement.from;
|
|
179
|
+
}
|
|
180
|
+
if (group.length > 0) flush();
|
|
181
|
+
return new StepMap(ranges);
|
|
182
|
+
};
|
|
183
|
+
const removedEndpoint = (node, context) => {
|
|
184
|
+
const properties = expectParagraphAttrs(node)._sectionProperties;
|
|
185
|
+
if (properties === void 0) return;
|
|
186
|
+
context.removedEndpointCount++;
|
|
187
|
+
for (const { type, rId } of properties?.headerReferences ?? []) context.removedReferences.push({
|
|
188
|
+
part: "header",
|
|
189
|
+
type,
|
|
190
|
+
relationshipId: rId
|
|
191
|
+
});
|
|
192
|
+
for (const { type, rId } of properties?.footerReferences ?? []) context.removedReferences.push({
|
|
193
|
+
part: "footer",
|
|
194
|
+
type,
|
|
195
|
+
relationshipId: rId
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
const resolveStructure = ({ node, position, context }) => {
|
|
199
|
+
if (node.isLeaf) return node;
|
|
200
|
+
const textBoxAnchor = anchoredTextBoxId(node);
|
|
201
|
+
if (textBoxAnchor !== void 0 && context.droppedTextBoxAnchors.has(textBoxAnchor)) {
|
|
202
|
+
context.structural = true;
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const structuralStart = {
|
|
206
|
+
steps: context.steps.length,
|
|
207
|
+
deleted: context.deleted.length,
|
|
208
|
+
replacements: context.replacements.length,
|
|
209
|
+
tableRanges: context.tableRanges.length,
|
|
210
|
+
bookmarkJoins: context.bookmarkJoins.length
|
|
211
|
+
};
|
|
212
|
+
const entries = [];
|
|
213
|
+
node.forEach((child, offset) => entries.push({
|
|
214
|
+
node: resolveStructure({
|
|
215
|
+
node: child,
|
|
216
|
+
position: position + 1 + offset,
|
|
217
|
+
context
|
|
218
|
+
}),
|
|
219
|
+
original: child,
|
|
220
|
+
position: position + 1 + offset
|
|
221
|
+
}));
|
|
222
|
+
const reversed = [];
|
|
223
|
+
let chain = null;
|
|
224
|
+
let pendingBookmarks = [];
|
|
225
|
+
let followingContainerChild = false;
|
|
226
|
+
const flush = () => {
|
|
227
|
+
if (!chain) return;
|
|
228
|
+
let final = chain.node;
|
|
229
|
+
if (chain.chunks.length > 1) {
|
|
230
|
+
const children = [];
|
|
231
|
+
for (let index = chain.chunks.length - 1; index >= 0; index--) chain.chunks[index]?.forEach((child) => children.push(child));
|
|
232
|
+
final = recreateProseNodeWithParagraphPropertySource(chain.node, { content: Fragment.fromArray(children) });
|
|
233
|
+
}
|
|
234
|
+
if (!chain.before.sameMarkup(final)) context.changedRanges.push({
|
|
235
|
+
from: chain.position,
|
|
236
|
+
to: chain.position + chain.before.nodeSize
|
|
237
|
+
});
|
|
238
|
+
recordNodeResolution({
|
|
239
|
+
before: chain.before,
|
|
240
|
+
after: final,
|
|
241
|
+
position: chain.position,
|
|
242
|
+
steps: context.steps
|
|
243
|
+
});
|
|
244
|
+
for (const { closing, bookmarks } of chain.joinBoundaries) {
|
|
245
|
+
if (bookmarks.size === 0) {
|
|
246
|
+
context.deleted.push({
|
|
247
|
+
from: closing,
|
|
248
|
+
to: closing + 2
|
|
249
|
+
});
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const to = closing + bookmarks.size + 2;
|
|
253
|
+
context.replacements.push({
|
|
254
|
+
from: closing,
|
|
255
|
+
to,
|
|
256
|
+
slice: new Slice(bookmarks, 0, 0)
|
|
257
|
+
});
|
|
258
|
+
context.bookmarkJoins.push({
|
|
259
|
+
from: closing,
|
|
260
|
+
to,
|
|
261
|
+
positionMap: new StepMap([
|
|
262
|
+
0,
|
|
263
|
+
1,
|
|
264
|
+
0,
|
|
265
|
+
bookmarks.size + 1,
|
|
266
|
+
1,
|
|
267
|
+
0
|
|
268
|
+
])
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
reversed.push(chain.chunks.length === 1 && final.eq(chain.before) ? chain.before : final);
|
|
272
|
+
chain = null;
|
|
273
|
+
};
|
|
274
|
+
const flushBookmarks = () => {
|
|
275
|
+
flush();
|
|
276
|
+
for (const bookmark of pendingBookmarks) reversed.push(bookmark);
|
|
277
|
+
pendingBookmarks = [];
|
|
278
|
+
};
|
|
279
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
280
|
+
const entry = entries[index];
|
|
281
|
+
if (!entry) continue;
|
|
282
|
+
let paragraph = entry.node;
|
|
283
|
+
if (paragraph === null) {
|
|
284
|
+
const filler = index + reversed.length + pendingBookmarks.length + (chain ? 1 : 0) > 0 ? null : node.type.schema.nodes["paragraph"]?.createAndFill();
|
|
285
|
+
context.replacements.push({
|
|
286
|
+
from: entry.position,
|
|
287
|
+
to: entry.position + entry.original.nodeSize,
|
|
288
|
+
slice: filler ? new Slice(Fragment.from(filler), 0, 0) : Slice.empty
|
|
289
|
+
});
|
|
290
|
+
if (!filler) continue;
|
|
291
|
+
paragraph = filler;
|
|
292
|
+
}
|
|
293
|
+
if (paragraph.type.name !== "paragraph") {
|
|
294
|
+
if (paragraph.type.name === "blockBookmarkBoundary") {
|
|
295
|
+
pendingBookmarks.push(paragraph);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
flushBookmarks();
|
|
299
|
+
reversed.push(paragraph);
|
|
300
|
+
followingContainerChild ||= paragraph.type.spec["tableRole"] === "table";
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const marker = expectParagraphAttrs(paragraph).pPrMark;
|
|
304
|
+
const markWasAdded = marker?.kind === "ins" || marker?.kind === "moveTo";
|
|
305
|
+
const joins = marker && markWasAdded !== (context.mode === "accept");
|
|
306
|
+
if (joins && chain) {
|
|
307
|
+
const boundaries = pendingBookmarks.toReversed();
|
|
308
|
+
let bookmarks = Fragment.empty;
|
|
309
|
+
if (boundaries.length > 0) {
|
|
310
|
+
const inline = inlineBookmarksOf(boundaries);
|
|
311
|
+
if (!inline) {
|
|
312
|
+
context.failed = true;
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
bookmarks = Fragment.fromArray(inline);
|
|
316
|
+
chain.chunks.push(bookmarks);
|
|
317
|
+
pendingBookmarks = [];
|
|
318
|
+
}
|
|
319
|
+
const empty = holdsNoContent(paragraph);
|
|
320
|
+
const owner = empty ? chain.node : paragraph;
|
|
321
|
+
const next = chain.node;
|
|
322
|
+
if (empty) {
|
|
323
|
+
const displacedToken = getProseParagraphPropertySourceToken(paragraph);
|
|
324
|
+
const selectedToken = getProseParagraphPropertySourceToken(next);
|
|
325
|
+
context.transfers.push({
|
|
326
|
+
displacedToken: typeof displacedToken === "string" ? displacedToken : null,
|
|
327
|
+
selectedToken: typeof selectedToken === "string" ? selectedToken : null
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
chain.node = recreateProseNodeWithParagraphPropertySource(owner, { attrs: {
|
|
331
|
+
...owner.attrs,
|
|
332
|
+
pPrMark: next.attrs["pPrMark"],
|
|
333
|
+
_sectionProperties: next.attrs["_sectionProperties"]
|
|
334
|
+
} });
|
|
335
|
+
chain.chunks.push(paragraph.content);
|
|
336
|
+
chain.position = entry.position;
|
|
337
|
+
chain.before = paragraph;
|
|
338
|
+
chain.joinBoundaries.push({
|
|
339
|
+
closing: entry.position + paragraph.nodeSize - 1,
|
|
340
|
+
bookmarks
|
|
341
|
+
});
|
|
342
|
+
removedEndpoint(paragraph, context);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
flushBookmarks();
|
|
346
|
+
if (joins && holdsNoContent(paragraph) && (markWasAdded || followingContainerChild) && index + reversed.length + 1 > 1) {
|
|
347
|
+
context.deleted.push({
|
|
348
|
+
from: entry.position,
|
|
349
|
+
to: entry.position + paragraph.nodeSize
|
|
350
|
+
});
|
|
351
|
+
removedEndpoint(paragraph, context);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const resolved = marker ? recreateProseNodeWithParagraphPropertySource(paragraph, { attrs: {
|
|
355
|
+
...paragraph.attrs,
|
|
356
|
+
pPrMark: null
|
|
357
|
+
} }) : paragraph;
|
|
358
|
+
chain = {
|
|
359
|
+
node: resolved,
|
|
360
|
+
chunks: [resolved.content],
|
|
361
|
+
position: entry.position,
|
|
362
|
+
before: paragraph,
|
|
363
|
+
joinBoundaries: []
|
|
364
|
+
};
|
|
365
|
+
followingContainerChild = true;
|
|
366
|
+
}
|
|
367
|
+
flushBookmarks();
|
|
368
|
+
reversed.reverse();
|
|
369
|
+
if (node.type.name === "doc") {
|
|
370
|
+
const carrier = reversed.at(-1);
|
|
371
|
+
if (carrier?.type.name === "paragraph" && carrier.attrs["reviewCarrier"] === REVIEW_CARRIERS.TERMINAL_TABLE) {
|
|
372
|
+
const table = reversed.findLast((child) => child.type.name === "table");
|
|
373
|
+
let pending = false;
|
|
374
|
+
table?.descendants((child) => {
|
|
375
|
+
pending ||= child.type.name === "tableRow" && child.attrs["trDel"] !== null && typeof child.attrs["trDel"] === "object" || child.type.name !== "tableRow" && child.marks.some((mark) => mark.type.name === "deletion");
|
|
376
|
+
return !pending;
|
|
377
|
+
});
|
|
378
|
+
const entry = entries.at(-1);
|
|
379
|
+
if (!pending && entry) if (context.mode === "accept") {
|
|
380
|
+
const cleared = recreateProseNodeWithParagraphPropertySource(carrier, { attrs: {
|
|
381
|
+
...carrier.attrs,
|
|
382
|
+
reviewCarrier: void 0
|
|
383
|
+
} });
|
|
384
|
+
recordNodeResolution({
|
|
385
|
+
before: carrier,
|
|
386
|
+
after: cleared,
|
|
387
|
+
position: entry.position,
|
|
388
|
+
steps: context.steps
|
|
389
|
+
});
|
|
390
|
+
context.changedRanges.push({
|
|
391
|
+
from: entry.position,
|
|
392
|
+
to: entry.position + carrier.nodeSize
|
|
393
|
+
});
|
|
394
|
+
reversed[reversed.length - 1] = cleared;
|
|
395
|
+
} else if (reversed.length > 1) {
|
|
396
|
+
reversed.pop();
|
|
397
|
+
context.deleted.push({
|
|
398
|
+
from: entry.position,
|
|
399
|
+
to: entry.position + carrier.nodeSize
|
|
400
|
+
});
|
|
401
|
+
} else {
|
|
402
|
+
const filler = node.type.schema.nodes["paragraph"]?.createAndFill();
|
|
403
|
+
if (filler) {
|
|
404
|
+
reversed[0] = filler;
|
|
405
|
+
context.replacements.push({
|
|
406
|
+
from: entry.position,
|
|
407
|
+
to: entry.position + carrier.nodeSize,
|
|
408
|
+
slice: new Slice(Fragment.from(filler), 0, 0)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const rebuilt = reversed.length === node.childCount && reversed.every((child, index) => child === node.child(index)) ? node : recreateProseNodeWithParagraphPropertySource(node, { content: reversed });
|
|
415
|
+
if (node.type.spec["tableRole"] !== "table") return rebuilt;
|
|
416
|
+
const tableResult = resolveAllTableChanges({
|
|
417
|
+
table: rebuilt,
|
|
418
|
+
mode: context.mode
|
|
419
|
+
});
|
|
420
|
+
context.structural ||= tableResult.structural;
|
|
421
|
+
context.failed ||= tableResult.failed;
|
|
422
|
+
const final = tableResult.node;
|
|
423
|
+
if (final) {
|
|
424
|
+
const inside = [...context.replacements.slice(structuralStart.replacements), ...context.deleted.slice(structuralStart.deleted).map(({ from, to }) => ({
|
|
425
|
+
from,
|
|
426
|
+
to,
|
|
427
|
+
slice: Slice.empty
|
|
428
|
+
}))].sort((a, b) => a.from - b.from);
|
|
429
|
+
const inputMap = structuralReplacementMap({
|
|
430
|
+
replacements: inside,
|
|
431
|
+
tables: context.tableRanges.slice(structuralStart.tableRanges),
|
|
432
|
+
bookmarkJoins: context.bookmarkJoins.slice(structuralStart.bookmarkJoins),
|
|
433
|
+
origin: position
|
|
434
|
+
});
|
|
435
|
+
const positionMap = composeRevisionResolutionMaps(inputMap, tableResult.positionMap);
|
|
436
|
+
context.tableRanges.push({
|
|
437
|
+
node: final,
|
|
438
|
+
inputNode: rebuilt,
|
|
439
|
+
sourceNodeSize: node.nodeSize,
|
|
440
|
+
position,
|
|
441
|
+
inputMap,
|
|
442
|
+
positionMap,
|
|
443
|
+
ranges: tableResult.changedParagraphRanges,
|
|
444
|
+
paragraphOffsets: tableResult.paragraphOffsets
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
context.steps.length = structuralStart.steps;
|
|
448
|
+
context.deleted.length = structuralStart.deleted;
|
|
449
|
+
context.replacements.length = structuralStart.replacements;
|
|
450
|
+
context.bookmarkJoins.length = structuralStart.bookmarkJoins;
|
|
451
|
+
if (final && !node.eq(final)) context.replacements.push({
|
|
452
|
+
from: position,
|
|
453
|
+
to: position + node.nodeSize,
|
|
454
|
+
slice: new Slice(Fragment.from(final), 0, 0)
|
|
455
|
+
});
|
|
456
|
+
return final;
|
|
457
|
+
};
|
|
458
|
+
const resolveWholeStory = ({ doc, mode, styleResolver, numbering }) => {
|
|
459
|
+
const steps = [];
|
|
460
|
+
const propertyRanges = [];
|
|
461
|
+
const propertyResult = resolveProperties({
|
|
462
|
+
doc,
|
|
463
|
+
mode,
|
|
464
|
+
styleResolver,
|
|
465
|
+
numbering,
|
|
466
|
+
steps,
|
|
467
|
+
changedRanges: propertyRanges
|
|
468
|
+
});
|
|
469
|
+
const properties = propertyResult.resolved;
|
|
470
|
+
const inline = resolveInlineRevisions({
|
|
471
|
+
doc: properties,
|
|
472
|
+
mode,
|
|
473
|
+
styleResolver,
|
|
474
|
+
keepType: doc.type.schema.marks[mode === "accept" ? "insertion" : "deletion"],
|
|
475
|
+
removeType: doc.type.schema.marks[mode === "accept" ? "deletion" : "insertion"]
|
|
476
|
+
});
|
|
477
|
+
const context = {
|
|
478
|
+
mode,
|
|
479
|
+
steps: [],
|
|
480
|
+
changedRanges: [],
|
|
481
|
+
deleted: [],
|
|
482
|
+
replacements: [],
|
|
483
|
+
transfers: [],
|
|
484
|
+
tableRanges: [],
|
|
485
|
+
bookmarkJoins: [],
|
|
486
|
+
structural: propertyResult.structural,
|
|
487
|
+
failed: false,
|
|
488
|
+
removedEndpointCount: 0,
|
|
489
|
+
removedReferences: [],
|
|
490
|
+
droppedTextBoxAnchors: inline ? droppedTextBoxAnchorIds(properties, inline.resolved) : /* @__PURE__ */ new Set()
|
|
491
|
+
};
|
|
492
|
+
const resolved = resolveStructure({
|
|
493
|
+
node: inline?.resolved ?? properties,
|
|
494
|
+
position: -1,
|
|
495
|
+
context
|
|
496
|
+
}) ?? doc;
|
|
497
|
+
if (inline) steps.push(...inline.steps);
|
|
498
|
+
steps.push(...context.steps);
|
|
499
|
+
const replacements = [...context.replacements, ...context.deleted.map(({ from, to }) => ({
|
|
500
|
+
from,
|
|
501
|
+
to,
|
|
502
|
+
slice: Slice.empty
|
|
503
|
+
}))].sort((a, b) => a.from - b.from);
|
|
504
|
+
const structuralMap = structuralReplacementMap({
|
|
505
|
+
replacements,
|
|
506
|
+
tables: context.tableRanges,
|
|
507
|
+
bookmarkJoins: context.bookmarkJoins,
|
|
508
|
+
origin: 0
|
|
509
|
+
});
|
|
510
|
+
for (const { from, to, slice } of replacements.toReversed()) steps.push(new ReplaceStep(from, to, slice));
|
|
511
|
+
const positionMap = composeRevisionResolutionMaps(inline?.positionMap ?? StepMap.empty, structuralMap);
|
|
512
|
+
return {
|
|
513
|
+
resolved,
|
|
514
|
+
mapping: new Mapping([positionMap]),
|
|
515
|
+
positionMap,
|
|
516
|
+
steps,
|
|
517
|
+
changedRanges: [...propertyRanges, ...inline?.ranges ?? []],
|
|
518
|
+
inlineMap: inline?.positionMap ?? StepMap.empty,
|
|
519
|
+
tableRanges: context.tableRanges,
|
|
520
|
+
transfers: context.transfers,
|
|
521
|
+
structuralRanges: context.changedRanges,
|
|
522
|
+
structuralMap,
|
|
523
|
+
structural: context.structural,
|
|
524
|
+
failed: context.failed,
|
|
525
|
+
removedEndpointCount: context.removedEndpointCount,
|
|
526
|
+
removedReferences: context.removedReferences
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
//#endregion
|
|
530
|
+
export { resolveWholeStory };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FlowBlock } from "../../layout-engine/types.js";
|
|
2
|
+
import { StepMap } from "prosemirror-transform";
|
|
3
|
+
//#region src/layout-bridge/convert/markupViewFlow.d.ts
|
|
4
|
+
type PositionRange = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
8
|
+
type MarkupViewFlowOptions = {
|
|
9
|
+
/** Authored (editor) positions to the positions the blocks were built with. */
|
|
10
|
+
positionMap: StepMap;
|
|
11
|
+
/** Ranges, in the blocks' positions, whose paragraphs show a change bar. */
|
|
12
|
+
changeBarRanges: readonly PositionRange[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Re-address blocks built from a view projection in editor positions, and mark
|
|
16
|
+
* the paragraphs the view flags with a change bar.
|
|
17
|
+
*/
|
|
18
|
+
declare function remapMarkupViewBlocks(blocks: readonly FlowBlock[], { positionMap, changeBarRanges }: MarkupViewFlowOptions): FlowBlock[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { MarkupViewFlowOptions, remapMarkupViewBlocks };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { indexedPositionMap } from "../../internal/indexedPositionMap.js";
|
|
2
|
+
//#region src/layout-bridge/convert/markupViewFlow.ts
|
|
3
|
+
/**
|
|
4
|
+
* Re-address blocks built from a view projection in editor positions, and mark
|
|
5
|
+
* the paragraphs the view flags with a change bar.
|
|
6
|
+
*/
|
|
7
|
+
function remapMarkupViewBlocks(blocks, { positionMap, changeBarRanges }) {
|
|
8
|
+
const inverse = positionMap.invert();
|
|
9
|
+
const cutSet = /* @__PURE__ */ new Set();
|
|
10
|
+
inverse.forEach((oldStart, oldEnd) => {
|
|
11
|
+
cutSet.add(oldStart);
|
|
12
|
+
cutSet.add(oldEnd);
|
|
13
|
+
});
|
|
14
|
+
const context = {
|
|
15
|
+
toSource: indexedPositionMap(inverse),
|
|
16
|
+
cuts: [...cutSet].sort((left, right) => left - right),
|
|
17
|
+
changeBarRanges
|
|
18
|
+
};
|
|
19
|
+
return blocks.map((block) => remapBlock(block, context));
|
|
20
|
+
}
|
|
21
|
+
const touchesChangeBar = (block, ranges) => {
|
|
22
|
+
const { pmStart, pmEnd } = block;
|
|
23
|
+
if (pmStart === void 0 || pmEnd === void 0) return false;
|
|
24
|
+
return ranges.some((range) => range.from < pmEnd && range.to > pmStart);
|
|
25
|
+
};
|
|
26
|
+
/** A node's own positions: its start after any hidden content before it, its end before any after. */
|
|
27
|
+
const remapNodeRange = (range, toSource) => {
|
|
28
|
+
if (range.pmStart === void 0 || range.pmEnd === void 0) return {};
|
|
29
|
+
const pmStart = toSource(range.pmStart, 1);
|
|
30
|
+
return {
|
|
31
|
+
pmStart,
|
|
32
|
+
pmEnd: Math.max(pmStart, toSource(range.pmEnd, -1))
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const remapSdtGroups = (groups, toSource) => groups === void 0 ? {} : { sdtGroups: groups.map((group) => ({
|
|
36
|
+
...group,
|
|
37
|
+
pmPos: toSource(group.pmPos, 1)
|
|
38
|
+
})) };
|
|
39
|
+
function remapBlock(block, context) {
|
|
40
|
+
switch (block.kind) {
|
|
41
|
+
case "paragraph": return remapParagraph(block, context);
|
|
42
|
+
case "table": return remapTable(block, context);
|
|
43
|
+
case "image":
|
|
44
|
+
case "pageBreak":
|
|
45
|
+
case "columnBreak": return {
|
|
46
|
+
...block,
|
|
47
|
+
...remapNodeRange(block, context.toSource)
|
|
48
|
+
};
|
|
49
|
+
case "textBox": return {
|
|
50
|
+
...block,
|
|
51
|
+
...remapNodeRange(block, context.toSource),
|
|
52
|
+
content: block.content.map((contentBlock) => contentBlock.kind === "table" ? remapTable(contentBlock, context) : remapParagraph(contentBlock, context))
|
|
53
|
+
};
|
|
54
|
+
case "sectionBreak": return block;
|
|
55
|
+
default: return block;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function remapTable(block, context) {
|
|
59
|
+
return {
|
|
60
|
+
...block,
|
|
61
|
+
...remapNodeRange(block, context.toSource),
|
|
62
|
+
...remapSdtGroups(block.sdtGroups, context.toSource),
|
|
63
|
+
rows: block.rows.map((row) => ({
|
|
64
|
+
...row,
|
|
65
|
+
cells: row.cells.map((cell) => ({
|
|
66
|
+
...cell,
|
|
67
|
+
blocks: cell.blocks.map((cellBlock) => remapBlock(cellBlock, context))
|
|
68
|
+
}))
|
|
69
|
+
}))
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function remapParagraph(block, context) {
|
|
73
|
+
const runs = [];
|
|
74
|
+
for (const run of block.runs) pushRemappedRun(run, context, runs);
|
|
75
|
+
return {
|
|
76
|
+
...block,
|
|
77
|
+
...remapNodeRange(block, context.toSource),
|
|
78
|
+
...remapSdtGroups(block.sdtGroups, context.toSource),
|
|
79
|
+
...touchesChangeBar(block, context.changeBarRanges) ? { reviewIndicator: "change-bar" } : {},
|
|
80
|
+
runs
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Index of the first cut strictly after `position`. */
|
|
84
|
+
const firstCutAfter = (cuts, position) => {
|
|
85
|
+
let low = 0;
|
|
86
|
+
let high = cuts.length;
|
|
87
|
+
while (low < high) {
|
|
88
|
+
const middle = Math.floor((low + high) / 2);
|
|
89
|
+
const cut = cuts.at(middle);
|
|
90
|
+
if (cut !== void 0 && cut <= position) low = middle + 1;
|
|
91
|
+
else high = middle;
|
|
92
|
+
}
|
|
93
|
+
return low;
|
|
94
|
+
};
|
|
95
|
+
/** Whether each character of the run occupies exactly one position. */
|
|
96
|
+
const addressesPerCharacter = (run) => run.pmStart !== void 0 && run.pmEnd !== void 0 && run.templatePreview === void 0 && run.text.length === run.pmEnd - run.pmStart;
|
|
97
|
+
function pushRemappedRun(run, context, out) {
|
|
98
|
+
if (run.kind !== "text" || !addressesPerCharacter(run)) {
|
|
99
|
+
out.push({
|
|
100
|
+
...run,
|
|
101
|
+
...remapNodeRange(run, context.toSource)
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const { pmStart, pmEnd } = run;
|
|
106
|
+
let pieceStart = pmStart;
|
|
107
|
+
for (let index = firstCutAfter(context.cuts, pmStart);; index++) {
|
|
108
|
+
const cut = context.cuts.at(index);
|
|
109
|
+
const pieceEnd = cut === void 0 || cut >= pmEnd ? pmEnd : cut;
|
|
110
|
+
out.push({
|
|
111
|
+
...run,
|
|
112
|
+
text: run.text.slice(pieceStart - pmStart, pieceEnd - pmStart),
|
|
113
|
+
...remapNodeRange({
|
|
114
|
+
pmStart: pieceStart,
|
|
115
|
+
pmEnd: pieceEnd
|
|
116
|
+
}, context.toSource)
|
|
117
|
+
});
|
|
118
|
+
if (pieceEnd === pmEnd) return;
|
|
119
|
+
pieceStart = pieceEnd;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { remapMarkupViewBlocks };
|
|
@@ -65,7 +65,7 @@ function convertTableCell(node, startPos, options, tableCellMargins) {
|
|
|
65
65
|
blocks.push(block);
|
|
66
66
|
} else if (child.type.name === "table") blocks.push(convertTable(child, childStart, options));
|
|
67
67
|
else if (child.type.name === "textBox") blocks.push(convertTextBoxNode(child, childStart, options));
|
|
68
|
-
else if (child.type.name === "blockSdt") {
|
|
68
|
+
else if (child.type.name === "blockSdt" || child.type.name === "blockCustomXml") {
|
|
69
69
|
let sdtChildStart = childStart + 1;
|
|
70
70
|
child.forEach((sdtChild) => {
|
|
71
71
|
convertCellChild(sdtChild, sdtChildStart);
|