@stll/folio-core 0.69.0 → 0.70.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/dist/_virtual/_rolldown/runtime.js +4 -4
- package/dist/ai-edits/apply.d.ts +39 -16
- package/dist/ai-edits/apply.js +1014 -723
- package/dist/ai-edits/block-identity.d.ts +6 -0
- package/dist/ai-edits/block-identity.js +11 -1
- package/dist/ai-edits/blockRange.d.ts +9 -0
- package/dist/ai-edits/clean-text.d.ts +2 -0
- package/dist/ai-edits/clean-text.js +2 -1
- package/dist/ai-edits/comment-lifecycle.d.ts +24 -0
- package/dist/ai-edits/comment-lifecycle.js +17 -8
- package/dist/ai-edits/directJoin.d.ts +30 -0
- package/dist/ai-edits/directJoin.js +30 -0
- package/dist/ai-edits/existingRevisions.d.ts +9 -0
- package/dist/ai-edits/existingRevisions.js +30 -0
- package/dist/ai-edits/finalSectionReview.d.ts +11 -0
- package/dist/ai-edits/finalSectionReview.js +26 -0
- package/dist/ai-edits/headless.d.ts +275 -14
- package/dist/ai-edits/headless.js +1595 -193
- package/dist/ai-edits/index.d.ts +11 -10
- package/dist/ai-edits/index.js +2 -2
- package/dist/ai-edits/markdownInsertion.d.ts +25 -0
- package/dist/ai-edits/markdownInsertion.js +67 -0
- package/dist/ai-edits/minimal-replacement.d.ts +120 -1
- package/dist/ai-edits/minimal-replacement.js +81 -1
- package/dist/ai-edits/newListNumbering.d.ts +20 -9
- package/dist/ai-edits/newListNumbering.js +25 -10
- package/dist/ai-edits/note-references.d.ts +19 -1
- package/dist/ai-edits/note-references.js +3 -1
- package/dist/ai-edits/pending-suggestions.d.ts +44 -2
- package/dist/ai-edits/pending-suggestions.js +481 -20
- package/dist/ai-edits/pendingJoin.d.ts +170 -0
- package/dist/ai-edits/pendingJoin.js +272 -0
- package/dist/ai-edits/read.d.ts +57 -4
- package/dist/ai-edits/read.js +317 -40
- package/dist/ai-edits/removed-blocks.d.ts +1 -1
- package/dist/ai-edits/result-validation.d.ts +36 -1
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +20 -0
- package/dist/ai-edits/retired-comment-receipts.js +165 -0
- package/dist/ai-edits/revisionStretches.d.ts +17 -0
- package/dist/ai-edits/snapshot.d.ts +12 -3
- package/dist/ai-edits/snapshot.js +9 -7
- package/dist/ai-edits/snapshotBatchFacts.d.ts +52 -0
- package/dist/ai-edits/snapshotBatchFacts.js +184 -0
- package/dist/ai-edits/table-geometry.d.ts +45 -11
- package/dist/ai-edits/table-geometry.js +141 -26
- package/dist/ai-edits/table-mutation-plan.d.ts +12 -0
- package/dist/ai-edits/table-mutation-plan.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +26 -3
- package/dist/ai-edits/table-row-column-mutations.js +90 -11
- package/dist/ai-edits/table-template.d.ts +21 -0
- package/dist/ai-edits/tableInsertionModes.d.ts +10 -0
- package/dist/ai-edits/tableInsertionModes.js +8 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +23 -0
- package/dist/ai-edits/tracked-batch-fidelity.js +357 -0
- package/dist/ai-edits/types.d.ts +81 -15
- package/dist/ai-edits/undefinedReferences.d.ts +49 -0
- package/dist/ai-edits/undefinedReferences.js +234 -0
- package/dist/ai-suggestions/apply.d.ts +12 -0
- package/dist/ai-suggestions/conflict.d.ts +9 -0
- package/dist/ai-suggestions/text-positions.d.ts +13 -0
- package/dist/canonical/batchCommentReferences.d.ts +20 -0
- package/dist/canonical/batchCommentReferences.js +93 -0
- package/dist/canonical/canonicalBatchReview.d.ts +25 -0
- package/dist/canonical/canonicalBatchReview.js +132 -0
- package/dist/{controller → canonical}/canonicalComments.d.ts +7 -4
- package/dist/{controller → canonical}/canonicalComments.js +36 -9
- package/dist/canonical/canonicalCompilerRefusal.d.ts +13 -0
- package/dist/canonical/canonicalCompilerRefusal.js +75 -0
- package/dist/canonical/canonicalIdLease.d.ts +40 -0
- package/dist/canonical/canonicalIdLease.js +96 -0
- package/dist/{controller → canonical}/canonicalInlineProjection.d.ts +1 -1
- package/dist/{controller → canonical}/canonicalInlineProjection.js +40 -20
- package/dist/canonical/canonicalInsertedCommentRange.d.ts +15 -0
- package/dist/canonical/canonicalInsertedCommentRange.js +43 -0
- package/dist/canonical/canonicalInsertionReplayIds.d.ts +40 -0
- package/dist/canonical/canonicalInsertionReplayIds.js +73 -0
- package/dist/canonical/canonicalJoinedReceipts.d.ts +11 -0
- package/dist/canonical/canonicalJoinedReceipts.js +22 -0
- package/dist/{controller → canonical}/canonicalListRendering.js +1 -1
- package/dist/{controller → canonical}/canonicalLockGuard.d.ts +12 -1
- package/dist/{controller → canonical}/canonicalLockGuard.js +96 -21
- package/dist/{controller → canonical}/canonicalOperations.js +1 -1
- package/dist/{controller → canonical}/canonicalProjectionBlocks.d.ts +11 -1
- package/dist/{controller → canonical}/canonicalProjectionBlocks.js +8 -4
- package/dist/{controller → canonical}/canonicalPublicOperations.d.ts +24 -9
- package/dist/canonical/canonicalPublicOperations.js +4791 -0
- package/dist/canonical/canonicalRemoteHistory.d.ts +48 -0
- package/dist/canonical/canonicalRemoteHistory.js +176 -0
- package/dist/canonical/canonicalRevisionLocks.d.ts +18 -0
- package/dist/canonical/canonicalRevisionLocks.js +30 -0
- package/dist/canonical/canonicalRevisionReceipts.d.ts +15 -0
- package/dist/canonical/canonicalRevisionReceipts.js +25 -0
- package/dist/canonical/canonicalRoomBase.d.ts +23 -0
- package/dist/canonical/canonicalRoomBase.js +38 -0
- package/dist/canonical/canonicalSeedContent.d.ts +36 -0
- package/dist/{controller → canonical}/canonicalSeedContent.js +53 -5
- package/dist/{controller → canonical}/canonicalSelection.js +1 -1
- package/dist/{controller → canonical}/canonicalSession.d.ts +239 -12
- package/dist/{controller → canonical}/canonicalSession.js +1069 -173
- package/dist/canonical/canonicalSourceNormalization.d.ts +42 -0
- package/dist/{controller → canonical}/canonicalSourceNormalization.js +41 -23
- package/dist/{controller → canonical}/canonicalTocSelection.js +1 -1
- package/dist/canonical/canonicalTrackedBatchFidelity.d.ts +9 -0
- package/dist/canonical/canonicalTrackedBatchFidelity.js +125 -0
- package/dist/canonical/canonicalWholeTextFidelity.d.ts +21 -0
- package/dist/canonical/canonicalWholeTextFidelity.js +88 -0
- package/dist/canonical/commentAnchorParagraph.d.ts +10 -0
- package/dist/canonical/commentAnchorParagraph.js +11 -0
- package/dist/canonical/controlEdges.d.ts +12 -0
- package/dist/canonical/controlEdges.js +17 -0
- package/dist/canonical/paragraphPatchAsRead.d.ts +19 -0
- package/dist/canonical/paragraphPatchAsRead.js +32 -0
- package/dist/canonical/propertySourcePreservation.d.ts +38 -0
- package/dist/canonical/propertySourcePreservation.js +129 -0
- package/dist/canonical/replacementRunSources.d.ts +29 -0
- package/dist/canonical/replacementRunSources.js +78 -0
- package/dist/compare/compare.d.ts +8 -6
- package/dist/compare/compare.js +37 -8
- package/dist/compare/content-alignment.d.ts +10 -1
- package/dist/compare/content-alignment.js +188 -27
- package/dist/compare/content.d.ts +9 -1
- package/dist/compare/content.js +2 -2
- package/dist/compare/formatting.d.ts +1 -0
- package/dist/compare/import-style-closure.d.ts +1 -1
- package/dist/compare/inline-atom-alignment.d.ts +83 -0
- package/dist/compare/inline-atom-alignment.js +173 -0
- package/dist/compare/inline-atoms-model.d.ts +65 -0
- package/dist/compare/inline-atoms-model.js +1131 -0
- package/dist/compare/inline-atoms.d.ts +4 -4
- package/dist/compare/inline-atoms.js +28 -139
- package/dist/compare/inline-provenance-model.d.ts +37 -0
- package/dist/compare/inline-provenance-model.js +138 -0
- package/dist/compare/inline-provenance.d.ts +52 -4
- package/dist/compare/inline-provenance.js +40 -7
- package/dist/compare/plan.d.ts +38 -4
- package/dist/compare/plan.js +22 -8
- package/dist/compare/scenario.d.ts +22 -1
- package/dist/compare/section-boundary-properties.d.ts +38 -5
- package/dist/compare/section-boundary-properties.js +164 -48
- package/dist/compare/style-resources.d.ts +3 -2
- package/dist/compare/style-resources.js +5 -4
- package/dist/compare/types.d.ts +5 -2
- package/dist/compare/verification.d.ts +24 -3
- package/dist/compare/verification.js +25 -18
- package/dist/compat/eigenpal.d.ts +32 -31
- package/dist/compat/eigenpal.js +3 -5
- package/dist/content-controls/findContentControls.d.ts +9 -0
- package/dist/content-controls/index.d.ts +8 -0
- package/dist/content-controls/mutateContentControls.d.ts +9 -0
- package/dist/controller/activeEditorStory.d.ts +1 -0
- package/dist/controller/anonymizationHighlights.d.ts +56 -0
- package/dist/controller/anonymizationHighlights.js +148 -0
- package/dist/controller/autocompleteSuggestion.d.ts +85 -0
- package/dist/controller/autocompleteSuggestion.js +213 -0
- package/dist/controller/canonicalClipboard.d.ts +2 -2
- package/dist/controller/canonicalClipboard.js +34 -14
- package/dist/controller/canonicalClipboardResources.js +9 -4
- package/dist/controller/canonicalCollaboration.d.ts +147 -0
- package/dist/controller/canonicalCollaboration.js +360 -0
- package/dist/controller/canonicalComposition.d.ts +7 -1
- package/dist/controller/canonicalComposition.js +14 -8
- package/dist/controller/canonicalContentControlValue.d.ts +17 -0
- package/dist/controller/canonicalContentControlValue.js +72 -0
- package/dist/controller/canonicalIndexedDbJournal.d.ts +6 -0
- package/dist/controller/canonicalIndexedDbJournal.js +80 -0
- package/dist/controller/canonicalInput.d.ts +13 -2
- package/dist/controller/canonicalInput.js +96 -11
- package/dist/controller/canonicalPresence.d.ts +63 -0
- package/dist/controller/canonicalPresence.js +125 -0
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalRoomAuthority.d.ts +66 -0
- package/dist/controller/canonicalRoomAuthority.js +119 -0
- package/dist/controller/canonicalRoomEditor.d.ts +87 -0
- package/dist/controller/canonicalRoomEditor.js +98 -0
- package/dist/controller/canonicalRoomTransport.d.ts +79 -0
- package/dist/controller/canonicalRoomTransport.js +104 -0
- package/dist/controller/canonicalRoomWire.d.ts +80 -0
- package/dist/controller/canonicalRoomWire.js +155 -0
- package/dist/controller/canonicalStoryEditor.d.ts +12 -0
- package/dist/controller/canonicalStoryEditor.js +39 -7
- package/dist/controller/canonicalStructure.d.ts +15 -5
- package/dist/controller/canonicalStructure.js +95 -34
- package/dist/controller/canonicalTabRoom.d.ts +91 -0
- package/dist/controller/canonicalTabRoom.js +553 -0
- package/dist/controller/canonicalYjsRoom.d.ts +102 -0
- package/dist/controller/canonicalYjsRoom.js +454 -0
- package/dist/controller/contentControlWidgetController.d.ts +16 -0
- package/dist/controller/contentControlWidgetController.js +7 -1
- package/dist/controller/documentChangeNotification.d.ts +5 -0
- package/dist/controller/documentChangeNotification.js +7 -0
- package/dist/controller/folioEditor.d.ts +12 -4
- package/dist/controller/folioEditor.js +18 -1
- package/dist/controller/folioEditorEvents.d.ts +1 -1
- package/dist/controller/fontReadiness.d.ts +14 -1
- package/dist/controller/fontReadiness.js +4 -4
- package/dist/controller/headerFooterEditorManager.d.ts +13 -7
- package/dist/controller/headerFooterEditorManager.js +24 -25
- package/dist/controller/hiddenEditorApi.d.ts +87 -13
- package/dist/controller/hiddenEditorApi.js +41 -3
- package/dist/controller/hiddenEditorManager.d.ts +62 -17
- package/dist/controller/hiddenEditorManager.js +378 -78
- package/dist/controller/hyphenationReadiness.d.ts +10 -0
- package/dist/controller/layoutPipeline.d.ts +14 -12
- package/dist/controller/layoutPipeline.js +64 -53
- package/dist/controller/layoutSession.d.ts +7 -6
- package/dist/controller/legacyTextAddress.d.ts +9 -0
- package/dist/controller/legacyTextAddress.js +52 -0
- package/dist/controller/noteEditorManager.d.ts +14 -7
- package/dist/controller/noteEditorManager.js +33 -32
- package/dist/controller/textPositionLookup.d.ts +24 -0
- package/dist/controller/textPositionLookup.js +78 -0
- package/dist/display-list/build/buildContext.d.ts +11 -0
- package/dist/display-list/build/buildDisplayList.d.ts +14 -1
- package/dist/display-list/build/colors.d.ts +8 -0
- package/dist/display-list/build/floatingImages.d.ts +10 -0
- package/dist/display-list/build/fontTable.d.ts +8 -0
- package/dist/display-list/build/furniture.d.ts +14 -2
- package/dist/display-list/build/glyphs.d.ts +7 -0
- package/dist/display-list/build/headerFooterPrimitives.d.ts +13 -0
- package/dist/display-list/build/imagePrimitives.d.ts +10 -0
- package/dist/display-list/build/pageBorderPrimitives.d.ts +16 -2
- package/dist/display-list/build/pageFurniture.d.ts +13 -0
- package/dist/display-list/build/paragraphPrimitives.d.ts +18 -0
- package/dist/display-list/build/paragraphPrimitives.js +17 -5
- package/dist/display-list/build/previewPrimitives.d.ts +14 -0
- package/dist/display-list/build/regions.d.ts +14 -0
- package/dist/display-list/build/storyPrimitives.d.ts +16 -0
- package/dist/display-list/build/strokes.d.ts +21 -3
- package/dist/display-list/build/strokes.js +2 -3
- package/dist/display-list/build/tablePrimitives.d.ts +15 -1
- package/dist/display-list/build/tablePrimitives.js +92 -55
- package/dist/display-list/build/textBoxPrimitives.d.ts +6 -0
- package/dist/display-list/build/unsupported.d.ts +10 -0
- package/dist/display-list/build/watermarkPrimitives.d.ts +15 -1
- package/dist/display-list/dom/renderDisplayListToDom.d.ts +33 -0
- package/dist/display-list/dom/renderDisplayListToDom.js +12 -4
- package/dist/display-list/editor/displayListPagePainter.d.ts +29 -1
- package/dist/display-list/editor/pageRenderer.d.ts +7 -0
- package/dist/display-list/html/renderDisplayListToHtml.d.ts +10 -0
- package/dist/display-list/primitives.d.ts +12 -1
- package/dist/display-list/selectDisplayPages.d.ts +8 -0
- package/dist/display-list/types.d.ts +11 -0
- package/dist/document-operations.d.ts +35 -5
- package/dist/document-operations.js +178 -40
- package/dist/docx/attributeRemainder.d.ts +35 -1
- package/dist/docx/automaticNoteMarkImport.d.ts +12 -0
- package/dist/docx/automaticNoteMarkImport.js +41 -0
- package/dist/docx/blockContentParser.d.ts +14 -5
- package/dist/docx/blockContentParser.js +19 -0
- package/dist/docx/blockPlainText.d.ts +14 -0
- package/dist/docx/blockPlainText.js +55 -4
- package/dist/docx/bookmarkParser.d.ts +17 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +14 -0
- package/dist/docx/borderParser.d.ts +11 -0
- package/dist/docx/builtInStyles.d.ts +44 -1
- package/dist/docx/canonicalSave.d.ts +14 -4
- package/dist/docx/canonicalSave.js +128 -30
- package/dist/docx/canonicalSessionInput.d.ts +59 -4
- package/dist/docx/canonicalSessionInput.js +147 -6
- package/dist/docx/canonicalStoryRepack.d.ts +1 -0
- package/dist/docx/canonicalStoryRepack.js +2 -2
- package/dist/docx/chartPreview.js +10 -9
- package/dist/docx/commentAnchorIndex.d.ts +33 -7
- package/dist/docx/commentAnchorIndex.js +162 -36
- package/dist/docx/commentIdNormalization.d.ts +14 -0
- package/dist/docx/commentParagraphIds.d.ts +17 -0
- package/dist/docx/commentParagraphIds.js +79 -0
- package/dist/docx/commentParser.d.ts +20 -1
- package/dist/docx/commentParser.js +5 -0
- package/dist/docx/commentRangeIntegrity.js +27 -11
- package/dist/docx/commentRangeJoin.d.ts +21 -1
- package/dist/docx/commentRangeJoin.js +5 -1
- package/dist/docx/commentReferenceCompletion.d.ts +29 -2
- package/dist/docx/commentReferenceCompletion.js +4 -3
- package/dist/docx/commentReferenceNormalization.d.ts +17 -0
- package/dist/docx/commentReferenceNormalization.js +484 -49
- package/dist/docx/commentReplyMarkers.d.ts +22 -0
- package/dist/docx/compatibility.d.ts +10 -0
- package/dist/docx/containerChildren.d.ts +26 -1
- package/dist/docx/containerChildren.js +29 -3
- package/dist/docx/contentTypeRegistry.d.ts +16 -0
- package/dist/docx/contentTypeRegistry.js +48 -20
- package/dist/docx/danglingRelationshipReferences.d.ts +13 -0
- package/dist/docx/defaultParagraphStyle.d.ts +14 -1
- package/dist/docx/documentClone.d.ts +3 -2
- package/dist/docx/documentClone.js +1 -1
- package/dist/docx/documentParser.d.ts +28 -3
- package/dist/docx/documentParser.js +71 -4
- package/dist/docx/drawingAnchor.d.ts +17 -0
- package/dist/docx/drawingGroupChildren.d.ts +12 -0
- package/dist/docx/drawingIdNormalization.d.ts +8 -0
- package/dist/docx/drawingIdNormalization.js +46 -1
- package/dist/docx/drawingUtils.d.ts +6 -0
- package/dist/docx/drawingUtils.js +2 -2
- package/dist/docx/encryption/agileDecryption.d.ts +7 -0
- package/dist/docx/ensureParaIds.d.ts +73 -0
- package/dist/docx/ensureParaIds.js +299 -59
- package/dist/docx/ensureUniqueControlIds.js +10 -3
- package/dist/docx/ensureUniqueRevisionIds.d.ts +28 -0
- package/dist/docx/ensureUniqueRevisionIds.js +140 -0
- package/dist/docx/fieldParser.d.ts +27 -2
- package/dist/docx/fieldState.d.ts +15 -0
- package/dist/docx/fieldWrapperCaptures.d.ts +18 -0
- package/dist/docx/fieldWrapperCaptures.js +117 -0
- package/dist/docx/foldedListNumberFields.d.ts +14 -0
- package/dist/docx/fontTableParser.d.ts +11 -0
- package/dist/docx/footnoteParser.d.ts +24 -3
- package/dist/docx/footnoteParser.js +29 -6
- package/dist/docx/graphicFrameLocks.d.ts +9 -1
- package/dist/docx/groupDrawingParser.d.ts +2 -2
- package/dist/docx/headerFooterParser.d.ts +37 -5
- package/dist/docx/headerFooterParser.js +18 -4
- package/dist/docx/headerFooterRefParser.d.ts +7 -0
- package/dist/docx/hostCommentThreads.d.ts +10 -1
- package/dist/docx/hyperlinkParser.d.ts +20 -3
- package/dist/docx/hyperlinkParser.js +19 -24
- package/dist/docx/imageParser.d.ts +27 -0
- package/dist/docx/index.d.ts +3 -3
- package/dist/docx/inlineContentRemovals.d.ts +8 -0
- package/dist/docx/inlineWrapperContent.d.ts +33 -1
- package/dist/docx/inlineWrapperContent.js +145 -1
- package/dist/docx/inlineWrapperParser.d.ts +14 -0
- package/dist/docx/listMarkerComputation.d.ts +37 -6
- package/dist/docx/listMarkerComputation.js +77 -28
- package/dist/docx/listModelNormalization.d.ts +24 -8
- package/dist/docx/listModelNormalization.js +426 -142
- package/dist/docx/listNumberingInstances.d.ts +38 -8
- package/dist/docx/listNumberingInstances.js +89 -42
- package/dist/docx/mainDocumentPart.d.ts +22 -1
- package/dist/docx/mainDocumentPart.js +51 -12
- package/dist/docx/markupRangeMarker.d.ts +16 -0
- package/dist/docx/markupRangeMarker.js +11 -2
- package/dist/docx/mathToMathml.d.ts +28 -0
- package/dist/docx/mergePropertyChangeLinks.d.ts +11 -0
- package/dist/docx/mergePropertyChangeLinks.js +30 -0
- package/dist/docx/nonVisualDrawingProps.d.ts +6 -0
- package/dist/docx/normalizeBaseDirection.d.ts +17 -0
- package/dist/docx/normalizedSourceParts.d.ts +21 -0
- package/dist/docx/normalizedSourceParts.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +7 -0
- package/dist/docx/noteReferenceMark.d.ts +9 -0
- package/dist/docx/noteReferenceStyles.d.ts +13 -0
- package/dist/docx/numberingParser.d.ts +12 -0
- package/dist/docx/numberingReference.d.ts +10 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +15 -0
- package/dist/docx/packageRelationshipsRoot.d.ts +24 -0
- package/dist/docx/packageRelationshipsRoot.js +28 -0
- package/dist/docx/packageUnnamedParagraphIds.d.ts +18 -0
- package/dist/docx/packageUnnamedParagraphIds.js +78 -0
- package/dist/docx/paraIdAttribute.d.ts +15 -0
- package/dist/docx/paragraphParser.d.ts +15 -3
- package/dist/docx/paragraphParser.js +126 -140
- package/dist/docx/paragraphProperties.d.ts +15 -1
- package/dist/docx/paragraphProperties.js +3 -5
- package/dist/docx/paragraphPropertySource.d.ts +55 -21
- package/dist/docx/paragraphPropertySource.js +183 -40
- package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
- package/dist/docx/paragraphTraversal.d.ts +39 -4
- package/dist/docx/paragraphTraversal.js +158 -42
- package/dist/docx/parseContext.d.ts +15 -0
- package/dist/docx/parseWarningMessage.d.ts +9 -0
- package/dist/docx/parseWarningMessage.js +7 -0
- package/dist/docx/parser.d.ts +1 -1
- package/dist/docx/parser.js +103 -29
- package/dist/docx/parserEnums.d.ts +21 -0
- package/dist/docx/partRelationships.d.ts +15 -0
- package/dist/docx/partRelationships.js +58 -0
- package/dist/docx/preservedRunContent.d.ts +2 -1
- package/dist/docx/preservedRunContent.js +40 -1
- package/dist/docx/previewBudget.d.ts +31 -0
- package/dist/docx/relsParser.d.ts +23 -0
- package/dist/docx/removeHeaderFooterParts.d.ts +1 -1
- package/dist/docx/replyToComment.d.ts +22 -1
- package/dist/docx/replyToComment.js +25 -21
- package/dist/docx/reviewResolutionProvenance.d.ts +32 -5
- package/dist/docx/reviewResolutionProvenance.js +229 -38
- package/dist/docx/rezip.d.ts +58 -11
- package/dist/docx/rezip.js +367 -101
- package/dist/docx/runConsolidator.d.ts +13 -0
- package/dist/docx/runParser.d.ts +4 -3
- package/dist/docx/runParser.js +27 -6
- package/dist/docx/runPayload.d.ts +29 -0
- package/dist/docx/saveDiagnostics.d.ts +3 -5
- package/dist/docx/sdtProperties.d.ts +17 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +14 -0
- package/dist/docx/sectionParser.d.ts +21 -0
- package/dist/docx/sectionParser.js +1 -6
- package/dist/docx/selectiveSave.js +271 -80
- package/dist/docx/selectiveXmlPatch.d.ts +36 -1
- package/dist/docx/selectiveXmlPatch.js +342 -78
- package/dist/docx/serializer/blockSdtSerializer.d.ts +10 -0
- package/dist/docx/serializer/borderSerializer.d.ts +8 -0
- package/dist/docx/serializer/commentSerializer.d.ts +12 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.d.ts +21 -3
- package/dist/docx/serializer/documentSerializer.js +44 -6
- package/dist/docx/serializer/groupTextBoxWriteBack.d.ts +14 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +11 -0
- package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
- package/dist/docx/serializer/markupRangeAttributes.js +3 -1
- package/dist/docx/serializer/noteSerializer.d.ts +21 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +14 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +11 -0
- package/dist/docx/serializer/paragraphSerializer.js +21 -9
- package/dist/docx/serializer/partNamespaces.d.ts +2 -0
- package/dist/docx/serializer/partNamespaces.js +3 -1
- package/dist/docx/serializer/runSerializer.js +12 -3
- package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +15 -0
- package/dist/docx/serializer/stylesSerializer.d.ts +26 -1
- package/dist/docx/serializer/stylesSerializer.js +111 -23
- package/dist/docx/serializer/tableSerializer.js +9 -7
- package/dist/docx/serializer/themeSerializer.d.ts +2 -1
- package/dist/docx/server/applyDocxXmlPatchProposal.js +1 -1
- package/dist/docx/server/build.d.ts +2 -2
- package/dist/docx/server/changeListFormat.d.ts +20 -0
- package/dist/docx/server/changeListFormat.js +102 -0
- package/dist/docx/server/createBilingualDocument.d.ts +21 -0
- package/dist/docx/server/materializeYjsDocx.js +2 -2
- package/dist/docx/server/migrateYjsAttrSchema.js +5 -5
- package/dist/docx/sessionListPruning.d.ts +11 -0
- package/dist/docx/settingsParser.d.ts +10 -0
- package/dist/docx/shadingParser.d.ts +10 -0
- package/dist/docx/shapeAlternateContent.js +9 -2
- package/dist/docx/shapeParser.d.ts +27 -0
- package/dist/docx/splitRevisionPieces.d.ts +1 -1
- package/dist/docx/storyBlockReplay.d.ts +37 -3
- package/dist/docx/storyBlockReplay.js +277 -68
- package/dist/docx/strictNames.d.ts +12 -1
- package/dist/docx/strictValueEncodings.gen.d.ts +9 -0
- package/dist/docx/structuralXmlPatch.d.ts +19 -3
- package/dist/docx/structuralXmlPatch.js +136 -53
- package/dist/docx/styleParser.d.ts +20 -3
- package/dist/docx/styleParser.js +3 -2
- package/dist/docx/tableLook.d.ts +15 -1
- package/dist/docx/tableParser.d.ts +17 -6
- package/dist/docx/tableParser.js +10 -5
- package/dist/docx/textBoxContentParser.d.ts +3 -2
- package/dist/docx/textBoxParser.d.ts +30 -3
- package/dist/docx/themeColorAttribute.d.ts +11 -0
- package/dist/docx/themeParser.d.ts +17 -5
- package/dist/docx/trackedMoveRangeNormalization.d.ts +9 -0
- package/dist/docx/trackedMoveRangeNormalization.js +40 -16
- package/dist/docx/transitionalSpelling.d.ts +9 -0
- package/dist/docx/unnamedParagraphIds.d.ts +33 -0
- package/dist/docx/unnamedParagraphIds.js +43 -0
- package/dist/docx/unreferencedHeaderFooters.d.ts +27 -0
- package/dist/docx/unreferencedHeaderFooters.js +130 -0
- package/dist/docx/unzip.d.ts +25 -0
- package/dist/docx/verbatimCapture.d.ts +18 -0
- package/dist/docx/verbatimCapture.js +76 -9
- package/dist/docx/vmlImageParser.d.ts +32 -1
- package/dist/docx/watermarkParser.d.ts +21 -0
- package/dist/docx/wrapPolygon.d.ts +11 -0
- package/dist/docx/wrapTypes.d.ts +6 -0
- package/dist/docx/xmlParser.d.ts +22 -18
- package/dist/docx/xmlParser.js +1 -18
- package/dist/docx/xmlRootInsertion.d.ts +8 -0
- package/dist/docx/xmlRootInsertion.js +28 -0
- package/dist/docx/xmlSafety.d.ts +1 -0
- package/dist/docx/xmlSafety.js +7 -11
- package/dist/export-pdf.d.ts +24 -1
- package/dist/fields/resolveFieldValues.js +2 -1
- package/dist/fonts/fontsourceFaces.d.ts +2 -2
- package/dist/fonts/headlessMeasure.d.ts +16 -0
- package/dist/generated/text_shaper.js +71 -59
- package/dist/generated/text_shaper_bg.wasm +0 -0
- package/dist/headless-layout.d.ts +36 -5
- package/dist/headless-layout.js +19 -4
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/index.d.ts +33 -31
- package/dist/index.js +3 -4
- package/dist/internal/canonicalOperationStaging.d.ts +2 -0
- package/dist/internal/canonicalOperationStaging.js +4 -0
- package/dist/internal/canonicalTyping.d.ts +9 -0
- package/dist/internal/canonicalTyping.js +7 -0
- package/dist/internal/compare/inline-presentation.d.ts +8 -0
- package/dist/internal/indexedPositionMap.js +2 -1
- package/dist/internal/revisionResolutionInline.js +13 -13
- package/dist/internal/revisionResolutionStep.js +1 -0
- package/dist/internal/revisionResolutionTracking.js +2 -1
- package/dist/internal/wholeStoryRevisionResolution.d.ts +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +57 -66
- package/dist/layout-bridge/cellSelectionHighlight.d.ts +8 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +7 -0
- package/dist/layout-bridge/convert/editingFont.d.ts +26 -0
- package/dist/layout-bridge/convert/editingFont.js +42 -0
- package/dist/layout-bridge/convert/endnoteLayout.d.ts +19 -1
- package/dist/layout-bridge/convert/flowBlockPostprocessing.d.ts +5 -0
- package/dist/layout-bridge/convert/flowBorders.d.ts +10 -4
- package/dist/layout-bridge/convert/flowBorders.js +13 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +27 -12
- package/dist/layout-bridge/convert/flowConversionShared.js +36 -11
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +12 -4
- package/dist/layout-bridge/convert/footnoteLayout.js +3 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +25 -5
- package/dist/layout-bridge/convert/imageConversion.d.ts +5 -1
- package/dist/layout-bridge/convert/listMarkers.d.ts +12 -7
- package/dist/layout-bridge/convert/markupViewFlow.d.ts +21 -0
- package/dist/layout-bridge/convert/markupViewFlow.js +4 -1
- package/dist/layout-bridge/convert/noteReferences.d.ts +4 -0
- package/dist/layout-bridge/convert/pageBreakSplitting.d.ts +4 -0
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +13 -8
- package/dist/layout-bridge/convert/paragraphAttrs.js +1 -1
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +10 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +3 -10
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +8 -4
- package/dist/layout-bridge/convert/paragraphFrames.d.ts +2 -4
- package/dist/layout-bridge/convert/paragraphFrames.js +4 -4
- package/dist/layout-bridge/convert/paragraphMarkFormatting.d.ts +13 -4
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +5 -0
- package/dist/layout-bridge/convert/paragraphRuns.js +18 -4
- package/dist/layout-bridge/convert/runFormattingMerge.d.ts +10 -4
- package/dist/layout-bridge/convert/runMarkFormatting.d.ts +8 -3
- package/dist/layout-bridge/convert/runMarkFormatting.js +3 -5
- package/dist/layout-bridge/convert/sectionBoundaries.d.ts +4 -0
- package/dist/layout-bridge/convert/tableConversion.d.ts +15 -5
- package/dist/layout-bridge/convert/tableConversion.js +40 -19
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +38 -1
- package/dist/layout-bridge/convert/textBoxFill.d.ts +7 -2
- package/dist/layout-bridge/convert/textFormattingConversion.d.ts +18 -12
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +8 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +67 -14
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +26 -4
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +10 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +4 -4
- package/dist/layout-bridge/dom/noteStoryDom.d.ts +1 -0
- package/dist/layout-bridge/engine/blockIndex.d.ts +3 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +9 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +6 -0
- package/dist/layout-bridge/engine/hitTest.js +3 -3
- package/dist/layout-bridge/engine/measuring/index.d.ts +20 -8
- package/dist/layout-bridge/engine/selectionRects.d.ts +9 -0
- package/dist/layout-bridge/headerFooterLayout.d.ts +12 -0
- package/dist/layout-bridge/headerFooterLayout.js +3 -3
- package/dist/layout-bridge/sectionColumns.d.ts +10 -1
- package/dist/layout-engine/footnoteContinuation.d.ts +8 -0
- package/dist/layout-engine/imageLayout.d.ts +4 -1
- package/dist/layout-engine/index.d.ts +10 -5
- package/dist/layout-engine/index.js +9 -3
- package/dist/layout-engine/keep-together.d.ts +6 -0
- package/dist/layout-engine/layoutFlowShared.d.ts +4 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +40 -1
- package/dist/layout-engine/layoutInstrumentation.js +26 -4
- package/dist/layout-engine/lineFlow.d.ts +1 -0
- package/dist/layout-engine/lineFlow.js +4 -1
- package/dist/layout-engine/measure/advanceComposition.d.ts +14 -1
- package/dist/layout-engine/measure/automaticTextSpacing.d.ts +1 -1
- package/dist/layout-engine/measure/cache.d.ts +6 -0
- package/dist/layout-engine/measure/cache.js +3 -0
- package/dist/layout-engine/measure/crossRunWords.d.ts +1 -1
- package/dist/layout-engine/measure/floatingLineClearance.d.ts +4 -0
- package/dist/layout-engine/measure/floatingTablePosition.d.ts +32 -1
- package/dist/layout-engine/measure/floatingTablePosition.js +49 -1
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +16 -0
- package/dist/layout-engine/measure/hyphenationDictionaries.d.ts +18 -0
- package/dist/layout-engine/measure/hyphenationPreload.d.ts +4 -0
- package/dist/layout-engine/measure/index.d.ts +18 -8
- package/dist/layout-engine/measure/index.js +2 -1
- package/dist/layout-engine/measure/inlineObjectMetrics.d.ts +4 -0
- package/dist/layout-engine/measure/justification.d.ts +5 -1
- package/dist/layout-engine/measure/lineFitting.d.ts +6 -1
- package/dist/layout-engine/measure/lineTypography.d.ts +6 -1
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +16 -1
- package/dist/layout-engine/measure/measureBlocks.d.ts +4 -1
- package/dist/layout-engine/measure/measureBlocks.js +127 -102
- package/dist/layout-engine/measure/measureContainer.d.ts +17 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +10 -1
- package/dist/layout-engine/measure/measureParagraph.d.ts +7 -1
- package/dist/layout-engine/measure/measureParagraph.js +51 -21
- package/dist/layout-engine/measure/measureProvider.d.ts +10 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +8 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +30 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +14 -0
- package/dist/layout-engine/measure/measuresHoldNoPositions.d.ts +40 -0
- package/dist/layout-engine/measure/measuresHoldNoPositions.js +14 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +12 -0
- package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +21 -2
- package/dist/layout-engine/measure/paragraphMeasureShared.js +20 -1
- package/dist/layout-engine/measure/paragraphTabs.d.ts +4 -0
- package/dist/layout-engine/measure/raisedTableWrap.d.ts +16 -0
- package/dist/layout-engine/measure/raisedTableWrap.js +105 -0
- package/dist/layout-engine/measure/tableBorderBands.d.ts +35 -0
- package/dist/layout-engine/measure/tableBorderBands.js +251 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -1
- package/dist/layout-engine/measure/tableCellFlow.d.ts +4 -4
- package/dist/layout-engine/measure/tableCellFlow.js +7 -10
- package/dist/layout-engine/measure/tableCellGrid.d.ts +4 -1
- package/dist/layout-engine/measure/tableCellGrid.js +30 -3
- package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
- package/dist/layout-engine/measure/tableMeasureMemo.d.ts +23 -0
- package/dist/layout-engine/measure/tableMeasureMemo.js +40 -0
- package/dist/layout-engine/measure/tableNoWrapWidths.d.ts +12 -0
- package/dist/layout-engine/measure/tableNoWrapWidths.js +73 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +6 -0
- package/dist/layout-engine/measure/textMeasurementPolicy.d.ts +7 -1
- package/dist/layout-engine/noteAreaFlow.d.ts +10 -1
- package/dist/layout-engine/paginator.d.ts +6 -0
- package/dist/layout-engine/paginator.js +6 -5
- package/dist/layout-engine/paragraphLayout.d.ts +5 -1
- package/dist/layout-engine/paragraphSpacing.d.ts +17 -2
- package/dist/layout-engine/paragraphSpacing.js +103 -15
- package/dist/layout-engine/pmPageIndex.d.ts +14 -1
- package/dist/layout-engine/pmPageIndex.js +10 -1
- package/dist/layout-engine/section-breaks.d.ts +6 -0
- package/dist/layout-engine/sectionLayout.d.ts +6 -1
- package/dist/layout-engine/sectionVerticalAlignment.js +2 -1
- package/dist/layout-engine/tableHeaderCompatibility.d.ts +3 -0
- package/dist/layout-engine/tableHeaderCompatibility.js +5 -0
- package/dist/layout-engine/tableLayout.d.ts +17 -6
- package/dist/layout-engine/tableLayout.js +36 -25
- package/dist/layout-engine/tableRowBreak.d.ts +16 -0
- package/dist/layout-engine/tableRowBreak.js +2 -1
- package/dist/layout-engine/textBoxFlow.d.ts +9 -0
- package/dist/layout-engine/textBoxLayout.d.ts +5 -1
- package/dist/layout-engine/types.d.ts +35 -2
- package/dist/layout-engine/types.js +77 -27
- package/dist/layout-painter/borderStroke.d.ts +1 -1
- package/dist/layout-painter/characterFillBand.d.ts +14 -0
- package/dist/layout-painter/characterFillBand.js +79 -0
- package/dist/layout-painter/imageLayout.d.ts +11 -2
- package/dist/layout-painter/index.d.ts +12 -6
- package/dist/layout-painter/pageShellStyles.d.ts +9 -0
- package/dist/layout-painter/previewSvg.d.ts +7 -0
- package/dist/layout-painter/reconcileRenderedContent.js +3 -1
- package/dist/layout-painter/registry/modules/image.d.ts +7 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +8 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +3 -0
- package/dist/layout-painter/registry/modules.d.ts +10 -0
- package/dist/layout-painter/registry/registry.d.ts +8 -0
- package/dist/layout-painter/registry/types.d.ts +11 -0
- package/dist/layout-painter/renderFragment.d.ts +6 -0
- package/dist/layout-painter/renderImage.d.ts +8 -0
- package/dist/layout-painter/renderPage.d.ts +10 -3
- package/dist/layout-painter/renderPage.js +23 -4
- package/dist/layout-painter/renderParagraph.d.ts +6 -0
- package/dist/layout-painter/renderParagraph.js +33 -16
- package/dist/layout-painter/renderTable.d.ts +10 -1
- package/dist/layout-painter/renderTable.js +112 -24
- package/dist/layout-painter/renderTextBox.d.ts +9 -0
- package/dist/layout-painter/renderUtils.d.ts +5 -1
- package/dist/layout-painter/renderWatermark.d.ts +11 -1
- package/dist/layout-painter/sdtBoundary.d.ts +10 -0
- package/dist/managers/ClipboardManager.d.ts +13 -0
- package/dist/managers/ContextMenuManager.d.ts +16 -4
- package/dist/managers/ContextMenuManager.js +3 -3
- package/dist/managers/DocumentLoaderManager.d.ts +19 -5
- package/dist/managers/DocumentLoaderManager.js +48 -13
- package/dist/managers/EditorModeManager.d.ts +11 -0
- package/dist/managers/ErrorManager.d.ts +11 -0
- package/dist/managers/FindReplaceManager.d.ts +14 -27
- package/dist/managers/FindReplaceManager.js +0 -49
- package/dist/managers/HistoryManager.d.ts +18 -0
- package/dist/managers/TableSelectionManager.d.ts +18 -4
- package/dist/managers/TableSelectionManager.js +22 -5
- package/dist/managers/editorShortcuts.d.ts +14 -2
- package/dist/managers/editorShortcuts.js +5 -3
- package/dist/managers/types.d.ts +15 -1
- package/dist/markdown/annotations.d.ts +9 -0
- package/dist/markdown/countParagraphList.d.ts +8 -0
- package/dist/markdown/escape.d.ts +6 -4
- package/dist/markdown/escape.js +17 -8
- package/dist/markdown/images.d.ts +11 -0
- package/dist/markdown/index.d.ts +24 -1
- package/dist/markdown/index.js +18 -1
- package/dist/markdown/internals.d.ts +7 -0
- package/dist/markdown/renderBlock.d.ts +5 -0
- package/dist/markdown/renderBlock.js +2 -7
- package/dist/markdown/renderParagraph.d.ts +22 -2
- package/dist/markdown/renderParagraph.js +11 -9
- package/dist/markdown/renderRuns.d.ts +10 -0
- package/dist/markdown/renderRuns.js +36 -3
- package/dist/markdown/renderTable.d.ts +7 -0
- package/dist/markdown/renderTable.js +2 -2
- package/dist/markdown/trailers.d.ts +7 -0
- package/dist/markdown/types.d.ts +9 -2
- package/dist/model.d.ts +25 -3
- package/dist/paged-layout/pageText.d.ts +1 -1
- package/dist/paged-layout/paragraphFlash.d.ts +3 -0
- package/dist/paged-layout/rangeProjection.d.ts +20 -1
- package/dist/paged-layout/rangeProjection.js +22 -4
- package/dist/paged-layout/scrollToPmPosition.d.ts +15 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +2 -2
- package/dist/paged-layout/sectionGeometry.d.ts +4 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +13 -0
- package/dist/panel-layout.d.ts +18 -1
- package/dist/panel-layout.js +36 -2
- package/dist/pdf/contentStream.d.ts +12 -0
- package/dist/pdf/fonts.d.ts +19 -0
- package/dist/pdf/paint.d.ts +9 -1
- package/dist/pdf/paint.js +51 -0
- package/dist/prosemirror/acceptedBlockNeighbours.d.ts +50 -0
- package/dist/prosemirror/acceptedBlockNeighbours.js +63 -0
- package/dist/prosemirror/alternateContentAttrs.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +20 -0
- package/dist/prosemirror/attrs/index.d.ts +2 -2
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/authoredTransformAttrs.d.ts +14 -0
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -2
- package/dist/prosemirror/canonicalCommands.d.ts +26 -1
- package/dist/prosemirror/canonicalCommands.js +12 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +14 -0
- package/dist/prosemirror/canonicalTableCommands.js +18 -6
- package/dist/prosemirror/cellDragSelection.d.ts +9 -0
- package/dist/prosemirror/commands/comments.d.ts +22 -0
- package/dist/prosemirror/commands/comments.js +374 -154
- package/dist/prosemirror/commands/contentControls.d.ts +20 -3
- package/dist/prosemirror/commands/contentControls.js +18 -1
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +11 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +10 -0
- package/dist/prosemirror/commands/formatPainter.js +0 -1
- package/dist/prosemirror/commands/formatting.d.ts +9 -2
- package/dist/prosemirror/commands/hyperlink.d.ts +12 -0
- package/dist/prosemirror/commands/image.d.ts +12 -0
- package/dist/prosemirror/commands/index.d.ts +10 -5
- package/dist/prosemirror/commands/pageBreak.d.ts +3 -0
- package/dist/prosemirror/commands/paragraph.d.ts +8 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +8 -0
- package/dist/prosemirror/commands/pastePlainText.js +1 -1
- package/dist/prosemirror/commands/propertyChangeScope.d.ts +28 -15
- package/dist/prosemirror/commands/propertyChangeScope.js +5 -12
- package/dist/prosemirror/commands/replaceRangeText.d.ts +22 -0
- package/dist/prosemirror/commands/replaceRangeText.js +44 -0
- package/dist/prosemirror/commands/resolveAllTableChanges.js +3 -2
- package/dist/prosemirror/commands/resolveParagraphProperties.js +4 -8
- package/dist/prosemirror/commands/rulerParagraph.d.ts +25 -0
- package/dist/prosemirror/commands/rulerParagraph.js +18 -0
- package/dist/prosemirror/commands/sectionBreak.d.ts +5 -0
- package/dist/prosemirror/commands/table.d.ts +7 -0
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.d.ts +12 -6
- package/dist/prosemirror/commentIdAllocator.js +38 -29
- package/dist/prosemirror/commentOps.d.ts +7 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +1 -1
- package/dist/prosemirror/commentRangeInlineAtoms.d.ts +4 -3
- package/dist/prosemirror/commentRangeInlineAtoms.js +1 -1
- package/dist/prosemirror/commentRecords.d.ts +17 -0
- package/dist/prosemirror/commentRecords.js +132 -5
- package/dist/prosemirror/commentReferenceAttrs.d.ts +1 -1
- package/dist/prosemirror/commentReferenceIntegrity.js +93 -14
- package/dist/prosemirror/containerFinalParagraph.d.ts +2 -0
- package/dist/prosemirror/containerFinalParagraph.js +3 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +14 -0
- package/dist/prosemirror/conversion/effectiveTableCellFormatting.d.ts +5 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +72 -58
- package/dist/prosemirror/conversion/index.d.ts +6 -1
- package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +21 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +13 -1
- package/dist/prosemirror/conversion/storyConversionOptions.d.ts +16 -0
- package/dist/prosemirror/conversion/storyConversionOptions.js +13 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +35 -10
- package/dist/prosemirror/conversion/toProseDoc.js +197 -136
- package/dist/prosemirror/copyOriginResolution.js +23 -10
- package/dist/prosemirror/documentSchema.d.ts +12 -0
- package/dist/prosemirror/emptyRangeAnchor.d.ts +39 -8
- package/dist/prosemirror/emptyRangeAnchor.js +63 -10
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +7 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +2 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +11 -2
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +3 -2
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +13 -4
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +5 -3
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/create.d.ts +6 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +5 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -3
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +20 -23
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +38 -21
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +8 -3
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +5 -14
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +17 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +7 -3
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +4 -1
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +32 -3
- package/dist/prosemirror/extensions/features/pasteCleanup.js +23 -3
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +22 -0
- package/dist/prosemirror/extensions/features/pastedCellSections.js +78 -0
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +22 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +1 -0
- package/dist/prosemirror/extensions/markRegistry.d.ts +14 -1
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +4 -6
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +5 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +17 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -2
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +2 -1
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +7 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +10 -3
- package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/BlockMoveRangeBoundaryExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +17 -0
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.d.ts +1 -0
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +38 -4
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +2 -1
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +7 -0
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +1 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/nodes/PageBreakRunExtension.d.ts +1 -0
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +1 -0
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +7 -19
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.d.ts +1 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +3 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +8 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +6 -6
- package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.d.ts +7 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +7 -0
- package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +9 -0
- package/dist/prosemirror/extensions/types.d.ts +10 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +13 -1
- package/dist/prosemirror/imageCommit.d.ts +10 -0
- package/dist/prosemirror/index.d.ts +30 -20
- package/dist/prosemirror/indexedNodeLookup.d.ts +11 -0
- package/dist/prosemirror/inlineWrapperStack.d.ts +12 -0
- package/dist/prosemirror/insertOperations.d.ts +10 -1
- package/dist/prosemirror/insertOperations.js +2 -2
- package/dist/prosemirror/insertionGaps.d.ts +21 -0
- package/dist/prosemirror/insertionGaps.js +86 -0
- package/dist/prosemirror/keptRangeBoundaries.d.ts +16 -12
- package/dist/prosemirror/keptRangeBoundaries.js +28 -34
- package/dist/prosemirror/listAutoformatMarkers.d.ts +11 -0
- package/dist/prosemirror/listInstanceReferences.d.ts +5 -0
- package/dist/prosemirror/listLabels.d.ts +16 -3
- package/dist/prosemirror/listLabels.js +0 -6
- package/dist/prosemirror/listMarker.d.ts +2 -2
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/listRendering.d.ts +2 -2
- package/dist/prosemirror/listRenderingAttrs.d.ts +10 -1
- package/dist/prosemirror/lockedControls.d.ts +6 -0
- package/dist/prosemirror/markupViewNotes.d.ts +11 -1
- package/dist/prosemirror/markupViewProjection.d.ts +21 -4
- package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +21 -3
- package/dist/prosemirror/nativeSelection.js +69 -19
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +17 -3
- package/dist/prosemirror/noteReferenceReview.js +26 -5
- package/dist/prosemirror/pageBreakRunProjection.d.ts +2 -1
- package/dist/prosemirror/paraText.d.ts +14 -0
- package/dist/prosemirror/paragraphFormattingProvenance.d.ts +13 -1
- package/dist/prosemirror/paragraphIndentation.d.ts +6 -3
- package/dist/prosemirror/paragraphIndentation.js +2 -3
- package/dist/prosemirror/paragraphList.d.ts +1 -1
- package/dist/prosemirror/paragraphMarkJoin.d.ts +29 -1
- package/dist/prosemirror/paragraphMarkJoin.js +25 -6
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +15 -1
- package/dist/prosemirror/paragraphPropertyCarry.js +5 -3
- package/dist/prosemirror/paragraphSpacing.d.ts +1 -1
- package/dist/prosemirror/pastePlacement.d.ts +17 -0
- package/dist/prosemirror/pastePlacement.js +22 -0
- package/dist/prosemirror/pastedCommentCopies.d.ts +87 -0
- package/dist/prosemirror/pastedCommentCopies.js +379 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +12 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +14 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +15 -9
- package/dist/prosemirror/plugins/contentControlWidgets.js +22 -28
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +17 -0
- package/dist/prosemirror/plugins/documentNumbering.d.ts +2 -1
- package/dist/prosemirror/plugins/documentStyleState.d.ts +3 -4
- package/dist/prosemirror/plugins/documentStyles.d.ts +20 -3
- package/dist/prosemirror/plugins/index.d.ts +7 -1
- package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +18 -1
- package/dist/prosemirror/plugins/paragraphStyleResolution.js +12 -2
- package/dist/prosemirror/plugins/pmTextScan.d.ts +18 -0
- package/dist/prosemirror/plugins/pmTextScan.js +42 -33
- package/dist/prosemirror/plugins/revisionIds.d.ts +14 -1
- package/dist/prosemirror/plugins/revisionIds.js +5 -1
- package/dist/prosemirror/plugins/selectionTracker.d.ts +12 -2
- package/dist/prosemirror/plugins/suggestionMode.d.ts +14 -11
- package/dist/prosemirror/plugins/suggestionMode.js +212 -34
- package/dist/prosemirror/plugins/templateDirectives.d.ts +17 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +23 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +19 -0
- package/dist/prosemirror/plugins/transactionInvariants.d.ts +19 -0
- package/dist/prosemirror/positionSweep.d.ts +21 -0
- package/dist/prosemirror/queries.d.ts +9 -0
- package/dist/prosemirror/queries.js +2 -2
- package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -2
- package/dist/prosemirror/rangeAnchorAttrs.js +55 -33
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +17 -0
- package/dist/prosemirror/replaceFindMatches.d.ts +20 -0
- package/dist/prosemirror/replaceFindMatches.js +33 -0
- package/dist/prosemirror/replacedAnnotations.d.ts +143 -0
- package/dist/prosemirror/replacedAnnotations.js +223 -26
- package/dist/prosemirror/revisionCarriers.js +9 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +3 -3
- package/dist/prosemirror/runFormattingFromMarks.js +10 -51
- package/dist/prosemirror/runFormattingProvenance.d.ts +2 -1
- package/dist/prosemirror/runFormattingProvenance.js +2 -1
- package/dist/prosemirror/runFormattingReconciliation.js +3 -12
- package/dist/prosemirror/runIdentity.d.ts +14 -0
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +7 -0
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +5 -13
- package/dist/prosemirror/runPropertyChangeResolution.js +13 -30
- package/dist/prosemirror/runStyleFormatting.d.ts +42 -113
- package/dist/prosemirror/runStyleFormatting.js +17 -74
- package/dist/prosemirror/schema/index.d.ts +8 -1
- package/dist/prosemirror/schema/marks.d.ts +16 -2
- package/dist/prosemirror/schema/nodes.d.ts +15 -14
- package/dist/prosemirror/sectionCarrier.d.ts +21 -0
- package/dist/prosemirror/sectionMarkEdits.d.ts +18 -0
- package/dist/prosemirror/selectionState.d.ts +10 -4
- package/dist/prosemirror/storyListNumbering.d.ts +10 -0
- package/dist/prosemirror/styles/index.d.ts +3 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +20 -18
- package/dist/prosemirror/styles/paragraphStyleCascade.js +10 -19
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +4 -3
- package/dist/prosemirror/styles/styleResolver.d.ts +40 -15
- package/dist/prosemirror/styles/styleResolver.js +6 -6
- package/dist/prosemirror/styles/styleToggleCascade.d.ts +18 -11
- package/dist/prosemirror/styles/styleToggleCascade.js +2 -11
- package/dist/prosemirror/styles/tableStyleRegions.d.ts +20 -7
- package/dist/prosemirror/styles/tableStyleRegions.js +14 -13
- package/dist/prosemirror/tableCellPaste.d.ts +21 -0
- package/dist/prosemirror/tableCellPaste.js +32 -2
- package/dist/prosemirror/tableGridMutation.d.ts +9 -0
- package/dist/prosemirror/tableGridMutation.js +34 -2
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +6 -0
- package/dist/prosemirror/tableResize.d.ts +10 -0
- package/dist/prosemirror/tableRunIn.d.ts +26 -1
- package/dist/prosemirror/tableRunIn.js +39 -11
- package/dist/prosemirror/textBoxAnchorAttrs.d.ts +1 -1
- package/dist/prosemirror/textBoxHostCollapse.d.ts +11 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +5 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +6 -0
- package/dist/prosemirror/utils/visualLineNavigation.js +1 -1
- package/dist/prosemirror/validation.js +6 -11
- package/dist/prosemirror/yjsDocumentMetadata.d.ts +9 -3
- package/dist/prosemirror/yjsDocumentMetadata.js +49 -10
- package/dist/prosemirror/zeroWidthAnchors.d.ts +18 -0
- package/dist/redline.d.ts +4 -1
- package/dist/redline.js +21 -13
- package/dist/render-dom/BodySelectionOverlay.d.ts +5 -0
- package/dist/render-dom/RemoteSelectionOverlay.js +3 -3
- package/dist/server.d.ts +30 -18
- package/dist/server.js +4 -3
- package/dist/shaping/placeRun.d.ts +8 -0
- package/dist/shaping/shaper.d.ts +19 -0
- package/dist/style-engine/index.d.ts +5 -0
- package/dist/style-engine/styleEngine.d.ts +32 -13
- package/dist/style-sets/extract.d.ts +1 -1
- package/dist/style-sets/styleSetNormalization.d.ts +20 -1
- package/dist/text-shaping.d.ts +9 -1
- package/dist/types/anonymization.d.ts +17 -0
- package/dist/types/anonymization.js +0 -0
- package/dist/types/autocomplete.d.ts +46 -0
- package/dist/types/autocomplete.js +0 -0
- package/dist/types/canonicalCapabilities.d.ts +40 -42
- package/dist/types/canonicalCapabilities.js +43 -44
- package/dist/types/canonicalSave.d.ts +36 -0
- package/dist/types/documentModel.d.ts +37 -0
- package/dist/types/documentModel.js +24 -0
- package/dist/types/docxSerialization.d.ts +10 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/remote-selection.d.ts +2 -1
- package/dist/types/selectiveSaveDecline.d.ts +44 -0
- package/dist/types/selectiveSaveDecline.js +0 -0
- package/dist/types/tableWidthKind.d.ts +2 -0
- package/dist/types/tableWidthKind.js +9 -0
- package/dist/utils/base64.d.ts +20 -0
- package/dist/utils/borderCss.d.ts +18 -1
- package/dist/utils/colorResolver.d.ts +12 -11
- package/dist/utils/createDocument.d.ts +8 -1
- package/dist/utils/createDocument.js +20 -2
- package/dist/utils/diagonalHatch.d.ts +2 -0
- package/dist/utils/diagonalHatch.js +16 -0
- package/dist/utils/extremes.d.ts +4 -0
- package/dist/utils/extremes.js +14 -0
- package/dist/utils/findMatchView.d.ts +2 -2
- package/dist/utils/findReplace.d.ts +2 -2
- package/dist/utils/findReplace.js +3 -2
- package/dist/utils/fontFamilyMerge.d.ts +2 -1
- package/dist/utils/fontResolver.d.ts +11 -2
- package/dist/utils/formatToStyle.d.ts +22 -8
- package/dist/utils/headerFooter.d.ts +16 -2
- package/dist/utils/headerFooter.js +2 -6
- package/dist/utils/imageResize.js +1 -1
- package/dist/utils/listItems.d.ts +7 -0
- package/dist/utils/listItems.js +9 -0
- package/dist/utils/mergeDocumentContent.d.ts +7 -0
- package/dist/utils/outlineHeadings.d.ts +1 -1
- package/dist/utils/paragraphFormattingMerge.d.ts +11 -3
- package/dist/utils/paragraphFormattingMerge.js +0 -8
- package/dist/utils/paragraphInlineLayout.js +2 -1
- package/dist/utils/repeatingStrokeGradient.d.ts +8 -0
- package/dist/utils/repeatingStrokeGradient.js +13 -0
- package/dist/utils/rotationBoundingBox.d.ts +8 -0
- package/dist/utils/rulerControl.d.ts +71 -0
- package/dist/utils/rulerControl.js +94 -0
- package/dist/utils/tableOperations.d.ts +20 -4
- package/dist/utils/tableOperations.js +1 -0
- package/dist/utils/textDirectionFlow.d.ts +10 -0
- package/dist/utils/textFormattingMerge.d.ts +18 -2
- package/dist/utils/textFormattingMerge.js +0 -20
- package/dist/utils/units.d.ts +2 -0
- package/dist/utils/units.js +3 -1
- package/dist/version-comparison.d.ts +63 -1
- package/dist/version-comparison.js +2 -1
- package/dist/watermark/index.d.ts +11 -0
- package/dist/watermark/index.js +0 -5
- package/package.json +7 -7
- package/dist/controller/canonicalPublicOperations.js +0 -1276
- package/dist/controller/canonicalSeedContent.d.ts +0 -12
- package/dist/controller/canonicalSourceNormalization.d.ts +0 -21
- package/dist/docx/canonicalResourceSave.d.ts +0 -15
- package/dist/docx/canonicalResourceSave.js +0 -27
- package/dist/internal/acceptedBlockProjection.d.ts +0 -9
- package/dist/internal/acceptedBlockProjection.js +0 -50
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +0 -60
- package/dist/prosemirror/plugins/anonymizationDecorations.js +0 -111
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +0 -127
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +0 -282
- package/dist/utils/replaceText.d.ts +0 -25
- package/dist/utils/replaceText.js +0 -242
- /package/dist/{controller → canonical}/canonicalListRendering.d.ts +0 -0
- /package/dist/{controller → canonical}/canonicalOperations.d.ts +0 -0
- /package/dist/{controller → canonical}/canonicalSelection.d.ts +0 -0
- /package/dist/{controller → canonical}/canonicalTocSelection.d.ts +0 -0
|
@@ -0,0 +1,4791 @@
|
|
|
1
|
+
import { SUGGESTED_SUPPORTED_OPERATION_TYPES, buildSignatureTableNode, buildTableNode } from "../ai-edits/apply.js";
|
|
2
|
+
import { BatchClaims } from "../ai-edits/batch-claims.js";
|
|
3
|
+
import { describeCharacterSplit } from "../ai-edits/character-boundaries.js";
|
|
4
|
+
import { buildCleanBlockText, resolveCleanTextRange } from "../ai-edits/clean-text.js";
|
|
5
|
+
import { directJoinSurvivor, directJoinTakes } from "../ai-edits/directJoin.js";
|
|
6
|
+
import { EXISTING_REVISION_CONFLICT_MESSAGE, createExistingRevisionGuard } from "../ai-edits/existingRevisions.js";
|
|
7
|
+
import { parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "../ai-edits/inline-emphasis.js";
|
|
8
|
+
import { compileMarkdownInsertion } from "../ai-edits/markdownInsertion.js";
|
|
9
|
+
import { BACKGROUND_MARK_NAMES, changesFromSegments, cutAroundRepeatedSeparators, planReplacementChanges, planTextChanges, touchedBackgroundStretches } from "../ai-edits/minimal-replacement.js";
|
|
10
|
+
import { createBatchListMinter } from "../ai-edits/newListNumbering.js";
|
|
11
|
+
import { cutsIntoNoteReference, endsWithNoteReference, noteReferenceEditsAllowed, noteReferenceSpansWithin, segmentsAroundNoteReferences } from "../ai-edits/note-references.js";
|
|
12
|
+
import { PENDING_BREAK_TABLE_REFUSAL, PENDING_JOIN_INSERTION_REFUSAL, firstParagraphJoiningTable, insertionAfterPendingBreak, isDeletedPPrMark, joinStopsAtTableAfter, pendingJoinParagraphs, pendingMarkEditOf, pendingMarkEditRefusal, pendingParagraphPropertiesRefusal } from "../ai-edits/pendingJoin.js";
|
|
13
|
+
import { addRetiredCommentReceipts } from "../ai-edits/retired-comment-receipts.js";
|
|
14
|
+
import { collectNoteReferenceLabels, hashFolioAIBlockContent, hashFolioAIBlockText } from "../ai-edits/snapshot.js";
|
|
15
|
+
import { followedOnlyByDeletedParagraphs, isInsertedPPrMark, snapshotBatchClaim } from "../ai-edits/snapshotBatchFacts.js";
|
|
16
|
+
import { mergesRemoveRow } from "../ai-edits/table-mutation-plan.js";
|
|
17
|
+
import { applyTableRowInsertion, describeUnplacedCellTexts, findTableColumnInsertion, findTableRowInsertion, getInsertedPhysicalColumnRows, getTableColumnCoordinateKey, splitCellParagraphTexts } from "../ai-edits/table-row-column-mutations.js";
|
|
18
|
+
import { findEnclosingTableCell, findEnclosingTableRow, findOutermostTableBoundary, tableRectangleCutsMergedCell } from "../ai-edits/table-targets.js";
|
|
19
|
+
import { tableFromTemplate } from "../ai-edits/table-template.js";
|
|
20
|
+
import { supportsTableInsertionMode } from "../ai-edits/tableInsertionModes.js";
|
|
21
|
+
import { createOperationHeadingStyles, findUndefinedOperationReference, styleDefinitionLookup } from "../ai-edits/undefinedReferences.js";
|
|
22
|
+
import { wordDiffSessionFromOptions } from "../ai-edits/word-diff.js";
|
|
23
|
+
import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch, withDistinctSuggestionIds } from "../document-operations.js";
|
|
24
|
+
import { paragraphFormattingWithAuthoredIndentation } from "../docx/paragraphPropertySource.js";
|
|
25
|
+
import { canonicalOperationStagingAccess } from "../internal/canonicalOperationStaging.js";
|
|
26
|
+
import { expectRunPropertyChangeMarkAttrs, expectTableAttrs } from "../prosemirror/attrs/index.js";
|
|
27
|
+
import { tableAnchor } from "../prosemirror/canonicalTableCommands.js";
|
|
28
|
+
import { paragraphEndsItsContainer } from "../prosemirror/containerFinalParagraph.js";
|
|
29
|
+
import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting } from "../prosemirror/conversion/fromProseDoc.js";
|
|
30
|
+
import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
|
|
31
|
+
import { insertionGap } from "../prosemirror/insertionGaps.js";
|
|
32
|
+
import { forEachAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js";
|
|
33
|
+
import { preservesReplacementCommentAlignment, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
|
|
34
|
+
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
35
|
+
import { insertedColumnWidth, omittedSlotTakingColumn } from "../prosemirror/tableGridMutation.js";
|
|
36
|
+
import { paragraphGoes } from "../prosemirror/tableRunIn.js";
|
|
37
|
+
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
38
|
+
import { readModel } from "../types/documentModel.js";
|
|
39
|
+
import { batchCommentReferenceShift, mapIntentPositions } from "./batchCommentReferences.js";
|
|
40
|
+
import { createCanonicalBatchReview } from "./canonicalBatchReview.js";
|
|
41
|
+
import { canonicalCommentBody, compileCanonicalComments } from "./canonicalComments.js";
|
|
42
|
+
import { compilerRefusalSkip } from "./canonicalCompilerRefusal.js";
|
|
43
|
+
import { insertedCommentRange, plainInsertedParagraphIds } from "./canonicalInsertedCommentRange.js";
|
|
44
|
+
import { planReplayParagraphIds, startParagraphAdmissionCursor } from "./canonicalInsertionReplayIds.js";
|
|
45
|
+
import { addJoinedParagraphReceipts } from "./canonicalJoinedReceipts.js";
|
|
46
|
+
import { lockViolationBetween } from "./canonicalLockGuard.js";
|
|
47
|
+
import { keepStandingRevisionReceipts } from "./canonicalRevisionReceipts.js";
|
|
48
|
+
import { CANONICAL_ADMISSION } from "./canonicalSession.js";
|
|
49
|
+
import { canonicalTrackedBatchFidelityError } from "./canonicalTrackedBatchFidelity.js";
|
|
50
|
+
import { findCommentAnchorParagraph } from "./commentAnchorParagraph.js";
|
|
51
|
+
import { controlEdgesAt } from "./controlEdges.js";
|
|
52
|
+
import { indentationAsRead, spacingSidesAsRead } from "./paragraphPatchAsRead.js";
|
|
53
|
+
import { replacementRunSources } from "./replacementRunSources.js";
|
|
54
|
+
import { Result, TaggedError, panic } from "better-result";
|
|
55
|
+
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
56
|
+
import { CONTENT_CONTROL_LOCK, MAX_REVISION_ID, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
57
|
+
import { Mark } from "prosemirror-model";
|
|
58
|
+
import { TableMap } from "prosemirror-tables";
|
|
59
|
+
import { BATCH_ANNOTATION_KINDS, DOCUMENT_OP_TYPES, ID_KIND_LIMITS, ID_LEASE_KINDS, OP_STORIES, SPLIT_HALVES, TYPED_TEXT_FORMATTING, applyDocumentOps, combineRecordedRevisions, compileEditorIntent, contentRank, createEditorIntentIdAllocator, deletionRemovesBlock, documentStories, finalBreakCarrier, findStoryBody, formatParaId, freshCommentId, groupInsertionRuns, idKey, introducedDocumentIds, isBlockBoundary, isCommentAnchorCarrierType, joinPropertyChangeLink, leasedIdCensus, locateParagraphThroughTextBoxes, noteDeletionOps, orderAddressingBeforeRemoval, orderBatchOperations, packageResourcesOpOf, paragraphLength, paragraphsThroughTextBoxes, pendingSuggestionIdsIn, revisionSpan } from "@stll/docx-core/ops";
|
|
60
|
+
import { EditorState } from "prosemirror-state";
|
|
61
|
+
// src/canonical/canonicalPublicOperations.ts
|
|
62
|
+
/** Public batches compile against the read projection; only the canonical journal publishes. */
|
|
63
|
+
const tableLineRemovalKey = ({ axis, tablePosition, index }) => `${axis}:${tablePosition}:${index}`;
|
|
64
|
+
const canonicalBatchPlan = ({ operation, intents, from, to, projection, tracked, inputIndex }) => {
|
|
65
|
+
const blockId = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range.blockId : operation.blockId;
|
|
66
|
+
const paragraph = projection.paragraph(blockId) ?? panic("A resolved batch operation lost its source paragraph", { id: operation.id });
|
|
67
|
+
const doc = projection.doc;
|
|
68
|
+
const block = paragraph.start - 1;
|
|
69
|
+
const claim = (item) => snapshotBatchClaim({
|
|
70
|
+
item,
|
|
71
|
+
doc,
|
|
72
|
+
producesTrackedChanges: tracked
|
|
73
|
+
});
|
|
74
|
+
const content = (item, position = from) => ({
|
|
75
|
+
claim: claim(item),
|
|
76
|
+
block,
|
|
77
|
+
placedAgainst: block,
|
|
78
|
+
address: {
|
|
79
|
+
type: "content",
|
|
80
|
+
position,
|
|
81
|
+
rank: 1,
|
|
82
|
+
inputIndex
|
|
83
|
+
},
|
|
84
|
+
removes: null,
|
|
85
|
+
insertionRun: null
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* The block gap an insertion at `from` lands in, as every other claim names
|
|
89
|
+
* block boundaries: past the paragraph's node, or before it, when `from` is
|
|
90
|
+
* a text position at its end or start.
|
|
91
|
+
*/
|
|
92
|
+
const gapAt = (side) => {
|
|
93
|
+
const $from = doc.resolve(from);
|
|
94
|
+
if (!$from.parent.isTextblock) return from;
|
|
95
|
+
return side === "after" ? $from.after() : $from.before();
|
|
96
|
+
};
|
|
97
|
+
const row = () => findEnclosingTableRow(doc, block) ?? panic("A resolved table operation lost its source row", { id: operation.id });
|
|
98
|
+
const insertionAnchor = (anchorId) => {
|
|
99
|
+
const anchor = projection.paragraph(anchorId);
|
|
100
|
+
if (anchor === void 0) return panic("An insertion lost its placement paragraph");
|
|
101
|
+
return anchor.start - 1;
|
|
102
|
+
};
|
|
103
|
+
const cell = () => findEnclosingTableCell(doc, block) ?? panic("A resolved cell operation lost its source cell", { id: operation.id });
|
|
104
|
+
switch (operation.type) {
|
|
105
|
+
case "replaceInBlock":
|
|
106
|
+
case "replaceRange": return content({
|
|
107
|
+
type: "text",
|
|
108
|
+
block,
|
|
109
|
+
from,
|
|
110
|
+
to
|
|
111
|
+
});
|
|
112
|
+
case "splitBlock": return content({
|
|
113
|
+
type: "split",
|
|
114
|
+
block,
|
|
115
|
+
from,
|
|
116
|
+
to
|
|
117
|
+
});
|
|
118
|
+
case "formatRange":
|
|
119
|
+
case "commentOnRange":
|
|
120
|
+
case "commentOnBlock": return {
|
|
121
|
+
claim: claim({
|
|
122
|
+
type: "annotation",
|
|
123
|
+
block,
|
|
124
|
+
from,
|
|
125
|
+
to
|
|
126
|
+
}),
|
|
127
|
+
block,
|
|
128
|
+
placedAgainst: block,
|
|
129
|
+
address: {
|
|
130
|
+
type: "annotation",
|
|
131
|
+
kind: operation.type === "formatRange" ? BATCH_ANNOTATION_KINDS.FORMATTING : BATCH_ANNOTATION_KINDS.COMMENT,
|
|
132
|
+
position: from,
|
|
133
|
+
inputIndex
|
|
134
|
+
},
|
|
135
|
+
removes: null,
|
|
136
|
+
insertionRun: null
|
|
137
|
+
};
|
|
138
|
+
case "replaceBlock": return content(intents.some((intent) => intent.type === "replaceText") ? {
|
|
139
|
+
type: "rewriteBlock",
|
|
140
|
+
block
|
|
141
|
+
} : {
|
|
142
|
+
type: "paragraphProperties",
|
|
143
|
+
block
|
|
144
|
+
});
|
|
145
|
+
case "setBlockParagraphProperties": return content({
|
|
146
|
+
type: "paragraphProperties",
|
|
147
|
+
block
|
|
148
|
+
});
|
|
149
|
+
case "mergeBlockWithNext": {
|
|
150
|
+
const join = intents.find((intent) => intent.type === "joinParagraphs") ?? panic("A resolved merge lost its join intent");
|
|
151
|
+
return content({
|
|
152
|
+
type: "merge",
|
|
153
|
+
block,
|
|
154
|
+
next: (projection.paragraph(join.nextBlockId) ?? panic("A resolved merge lost its second paragraph")).start - 1,
|
|
155
|
+
joinsNow: !tracked,
|
|
156
|
+
setsProperties: operation.mergedParagraphProperties !== void 0
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
case "deleteBlock": return content({
|
|
160
|
+
type: "deleteBlock",
|
|
161
|
+
block,
|
|
162
|
+
end: block + paragraph.node.nodeSize,
|
|
163
|
+
node: paragraph.node
|
|
164
|
+
});
|
|
165
|
+
case "insertBeforeBlock":
|
|
166
|
+
case "insertAfterBlock": {
|
|
167
|
+
const plan = content({
|
|
168
|
+
type: "insertion",
|
|
169
|
+
at: gapAt(operation.type === "insertAfterBlock" ? "after" : "before")
|
|
170
|
+
});
|
|
171
|
+
const hasComment = operation.comment !== void 0;
|
|
172
|
+
const emptyPageBreak = tracked && operation.pageBreakBefore === true && operation.text === "";
|
|
173
|
+
const placement = intents.find((intent) => intent.type === "insertParagraphs")?.at;
|
|
174
|
+
return {
|
|
175
|
+
...plan,
|
|
176
|
+
placedAgainst: placement?.type === "before" || placement?.type === "after" || placement?.type === "beforeTable" || placement?.type === "afterTable" ? insertionAnchor(placement.blockId) : block,
|
|
177
|
+
insertionRun: hasComment || emptyPageBreak ? null : from
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
case "insertTable":
|
|
181
|
+
case "insertSignatureTable": {
|
|
182
|
+
const plan = content({
|
|
183
|
+
type: "insertion",
|
|
184
|
+
at: gapAt(operation.position ?? "after")
|
|
185
|
+
});
|
|
186
|
+
const insertion = intents.find((intent) => intent.type === "tableBlock")?.operation;
|
|
187
|
+
return insertion?.type === DOCUMENT_OP_TYPES.INSERT_TABLE && insertion.anchor === "table" ? {
|
|
188
|
+
...plan,
|
|
189
|
+
placedAgainst: insertionAnchor(insertion.blockId)
|
|
190
|
+
} : plan;
|
|
191
|
+
}
|
|
192
|
+
case "deleteTable": {
|
|
193
|
+
const target = row();
|
|
194
|
+
return content({
|
|
195
|
+
type: "deleteTable",
|
|
196
|
+
position: target.tablePosition,
|
|
197
|
+
node: target.table
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
case "deleteTableRow": {
|
|
201
|
+
const target = row();
|
|
202
|
+
return {
|
|
203
|
+
...content({
|
|
204
|
+
type: "deleteTableRow",
|
|
205
|
+
deletion: target,
|
|
206
|
+
row: target.table.child(target.rowIndex),
|
|
207
|
+
table: target.table
|
|
208
|
+
}),
|
|
209
|
+
removes: {
|
|
210
|
+
axis: "row",
|
|
211
|
+
tablePosition: target.tablePosition,
|
|
212
|
+
index: target.rowIndex
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
case "deleteTableColumn": {
|
|
217
|
+
const target = row();
|
|
218
|
+
const column = cell().leftColumnIndex;
|
|
219
|
+
return {
|
|
220
|
+
...content({
|
|
221
|
+
type: "deleteTableColumn",
|
|
222
|
+
deletion: {
|
|
223
|
+
tablePosition: target.tablePosition,
|
|
224
|
+
columnIndex: column
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
address: {
|
|
228
|
+
type: "column",
|
|
229
|
+
tablePosition: target.tablePosition,
|
|
230
|
+
columnIndex: column,
|
|
231
|
+
insertion: false,
|
|
232
|
+
inputIndex
|
|
233
|
+
},
|
|
234
|
+
removes: {
|
|
235
|
+
axis: "column",
|
|
236
|
+
tablePosition: target.tablePosition,
|
|
237
|
+
index: column
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
case "insertTableColumn": {
|
|
242
|
+
const insertion = findTableColumnInsertion({
|
|
243
|
+
doc,
|
|
244
|
+
blockFrom: block,
|
|
245
|
+
position: operation.position ?? "after"
|
|
246
|
+
}) ?? panic("A resolved column insertion lost its source gap");
|
|
247
|
+
return {
|
|
248
|
+
...content({
|
|
249
|
+
type: "tableStructure",
|
|
250
|
+
axis: "column",
|
|
251
|
+
target: {
|
|
252
|
+
type: "tableStructure",
|
|
253
|
+
tablePosition: insertion.tablePosition
|
|
254
|
+
}
|
|
255
|
+
}),
|
|
256
|
+
address: {
|
|
257
|
+
type: "column",
|
|
258
|
+
tablePosition: insertion.tablePosition,
|
|
259
|
+
columnIndex: insertion.columnIndex,
|
|
260
|
+
insertion: true,
|
|
261
|
+
inputIndex
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
case "insertTableRow": return content({
|
|
266
|
+
type: "tableStructure",
|
|
267
|
+
axis: "row",
|
|
268
|
+
target: {
|
|
269
|
+
type: "tableStructure",
|
|
270
|
+
tablePosition: row().tablePosition
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
case "mergeTableCells":
|
|
274
|
+
case "splitTableCell": {
|
|
275
|
+
const target = row();
|
|
276
|
+
const source = cell();
|
|
277
|
+
const merge = intents.find((intent) => intent.type === "table" && intent.operation.type === DOCUMENT_OP_TYPES.MERGE_CELLS);
|
|
278
|
+
const rectangleOfMerge = () => {
|
|
279
|
+
if (merge?.type !== "table" || merge.operation.type !== DOCUMENT_OP_TYPES.MERGE_CELLS) return panic("A resolved cell merge lost its rectangle");
|
|
280
|
+
return merge.operation;
|
|
281
|
+
};
|
|
282
|
+
const rectangle = operation.type === "mergeTableCells" ? rectangleOfMerge() : {
|
|
283
|
+
left: source.leftColumnIndex,
|
|
284
|
+
top: source.topRowIndex,
|
|
285
|
+
right: source.rightColumnIndex,
|
|
286
|
+
bottom: source.bottomRowIndex
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
...content({
|
|
290
|
+
type: "tableStructure",
|
|
291
|
+
axis: "cell",
|
|
292
|
+
target: {
|
|
293
|
+
type: operation.type === "mergeTableCells" ? "mergeCells" : "splitCell",
|
|
294
|
+
tablePosition: target.tablePosition,
|
|
295
|
+
rectangle
|
|
296
|
+
}
|
|
297
|
+
}),
|
|
298
|
+
address: {
|
|
299
|
+
type: "cell",
|
|
300
|
+
tablePosition: target.tablePosition,
|
|
301
|
+
bottom: rectangle.bottom,
|
|
302
|
+
right: rectangle.right,
|
|
303
|
+
inputIndex
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
default: return operation;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const ROW_SHIFTED_CELL_SHAPE = "The batch inserts a row above the last row of the cells this merges or splits.";
|
|
311
|
+
/**
|
|
312
|
+
* The merges and splits whose cells a row the batch inserts in their table
|
|
313
|
+
* would shift or cut, whatever their order in the request. A merge or split
|
|
314
|
+
* names its cells by row as the batch read the table, and runs after the
|
|
315
|
+
* batch's row insertions, so a row inserted above its last row would move
|
|
316
|
+
* the cells it names.
|
|
317
|
+
*/
|
|
318
|
+
const rowShiftedCellShapes = (items) => {
|
|
319
|
+
const boundaries = items.flatMap(({ plan: { claim }, intents }) => claim.type === "tableStructure" && claim.axis === "row" ? intents.flatMap((intent) => intent.type === "tableRow" && intent.operation.type === DOCUMENT_OP_TYPES.INSERT_ROW ? [{
|
|
320
|
+
table: claim.table,
|
|
321
|
+
at: intent.operation.at
|
|
322
|
+
}] : []) : []);
|
|
323
|
+
return items.filter(({ plan: { address } }) => address.type === "cell" ? boundaries.some(({ table, at }) => table === address.tablePosition && at < address.bottom) : false);
|
|
324
|
+
};
|
|
325
|
+
const COLUMN_EDITED_CELL_SHAPE = "The batch inserts or deletes a column in the table this merges or splits.";
|
|
326
|
+
/**
|
|
327
|
+
* The merges and splits in a table the batch inserts or deletes a column of,
|
|
328
|
+
* whatever their order in the request. They name their cells by grid column
|
|
329
|
+
* as the batch read the table, and a column edit moves every column after it
|
|
330
|
+
* and the cells it runs through, so, as `planTableMutations` refuses them on
|
|
331
|
+
* the legacy engine, they are refused in either mode.
|
|
332
|
+
*/
|
|
333
|
+
const columnEditedCellShapes = (items) => {
|
|
334
|
+
const tables = new Set(items.flatMap(({ plan: { claim } }) => claim.type === "tableStructure" && claim.axis === "column" ? [claim.table] : []));
|
|
335
|
+
if (tables.size === 0) return [];
|
|
336
|
+
return items.filter(({ operation, plan: { address } }) => (operation.type === "mergeTableCells" || operation.type === "splitTableCell") && address.type === "cell" && tables.has(address.tablePosition));
|
|
337
|
+
};
|
|
338
|
+
const ROW_CLOSING_CELL_SHAPE = "Another merge the batch makes in this table removes a row, which would move the cells this merges or splits.";
|
|
339
|
+
/**
|
|
340
|
+
* The merges and splits whose cells a merge of the batch in their table
|
|
341
|
+
* would move. A merge that leaves a row nothing it starts removes the row,
|
|
342
|
+
* and the batch names every merge and split by row as it read the table, so
|
|
343
|
+
* as `planTableMutations` does: the first merge stays, a later one whose
|
|
344
|
+
* cells and the earlier ones' would empty a row is refused, and so is a
|
|
345
|
+
* split in a table whose merges empty a row, whatever the order.
|
|
346
|
+
*/
|
|
347
|
+
const rowClosingCellShapes = ({ items, doc }) => {
|
|
348
|
+
const kept = /* @__PURE__ */ new Map();
|
|
349
|
+
const refused = [];
|
|
350
|
+
for (const item of items) {
|
|
351
|
+
const { operation, intents, plan } = item;
|
|
352
|
+
if (operation.type !== "mergeTableCells" || plan.address.type !== "cell") continue;
|
|
353
|
+
const merge = intents.find((intent) => intent.type === "table" && intent.operation.type === DOCUMENT_OP_TYPES.MERGE_CELLS);
|
|
354
|
+
if (merge?.type !== "table" || merge.operation.type !== DOCUMENT_OP_TYPES.MERGE_CELLS) return panic("A resolved cell merge lost its rectangle");
|
|
355
|
+
const { left, top, right, bottom } = merge.operation;
|
|
356
|
+
const table = plan.address.tablePosition;
|
|
357
|
+
const earlier = kept.get(table) ?? [];
|
|
358
|
+
const rectangles = [...earlier, {
|
|
359
|
+
left,
|
|
360
|
+
top,
|
|
361
|
+
right,
|
|
362
|
+
bottom
|
|
363
|
+
}];
|
|
364
|
+
if (earlier.length > 0 && mergesRemoveRow({
|
|
365
|
+
doc,
|
|
366
|
+
tablePosition: table,
|
|
367
|
+
rectangles
|
|
368
|
+
})) {
|
|
369
|
+
refused.push(item);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
kept.set(table, rectangles);
|
|
373
|
+
}
|
|
374
|
+
for (const item of items) {
|
|
375
|
+
const { address } = item.plan;
|
|
376
|
+
if (item.operation.type !== "splitTableCell" || address.type !== "cell") continue;
|
|
377
|
+
const merges = kept.get(address.tablePosition);
|
|
378
|
+
if (merges !== void 0 && mergesRemoveRow({
|
|
379
|
+
doc,
|
|
380
|
+
tablePosition: address.tablePosition,
|
|
381
|
+
rectangles: merges
|
|
382
|
+
})) refused.push(item);
|
|
383
|
+
}
|
|
384
|
+
return refused;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* A paragraph's mark, as a block an operation addresses or removes: no
|
|
388
|
+
* block position is negative.
|
|
389
|
+
*/
|
|
390
|
+
const markOf = (block) => -block - 1;
|
|
391
|
+
/** Below every `contentRank`, so it runs first at its position. */
|
|
392
|
+
const RUN_START_COLLAPSE_RANK = -1;
|
|
393
|
+
/**
|
|
394
|
+
* The paragraphs that go with the row or table a deletion naming the one at
|
|
395
|
+
* `block` removes, those of its nested tables included.
|
|
396
|
+
*/
|
|
397
|
+
const removedTableParagraphs = (doc, type, block) => {
|
|
398
|
+
const row = findEnclosingTableRow(doc, block);
|
|
399
|
+
if (row === null) return panic("A planned table deletion lost its row");
|
|
400
|
+
const removed = type === "deleteTable" ? {
|
|
401
|
+
node: row.table,
|
|
402
|
+
position: row.tablePosition
|
|
403
|
+
} : {
|
|
404
|
+
node: row.table.child(row.rowIndex),
|
|
405
|
+
position: row.rowPosition
|
|
406
|
+
};
|
|
407
|
+
const blocks = [];
|
|
408
|
+
removed.node.descendants((child, offset) => {
|
|
409
|
+
if (child.type.name !== "paragraph") return true;
|
|
410
|
+
blocks.push(removed.position + 1 + offset);
|
|
411
|
+
return false;
|
|
412
|
+
});
|
|
413
|
+
return blocks;
|
|
414
|
+
};
|
|
415
|
+
const orderCanonicalBatch = ({ items, doc, mode }) => {
|
|
416
|
+
const deletionOf = new Map(items.flatMap((item) => item.operation.type === "deleteBlock" ? [[item.plan.block, item]] : []));
|
|
417
|
+
const deleted = new Set(deletionOf.keys());
|
|
418
|
+
const joinedAway = new Set(items.flatMap(({ plan }) => plan.claim.type === "merge" && plan.claim.joinsNow ? [plan.block] : []));
|
|
419
|
+
const deletedSplits = new Set(items.flatMap(({ operation, plan }) => {
|
|
420
|
+
if (operation.type !== "deleteBlock" || !isInsertedPPrMark(doc.nodeAt(plan.block)?.attrs["pPrMark"])) return [];
|
|
421
|
+
const at = doc.resolve(plan.block);
|
|
422
|
+
if (at.parent.maybeChild(at.index() + 1)?.type.name !== "paragraph") return [];
|
|
423
|
+
return items.some(({ operation: other, plan: otherPlan }) => other.type === "insertTable" && other.position !== "before" && otherPlan.block === plan.block && otherPlan.claim.type === "insertion" && otherPlan.claim.at === plan.block + (doc.nodeAt(plan.block)?.nodeSize ?? 0)) ? [plan.block] : [];
|
|
424
|
+
}));
|
|
425
|
+
/**
|
|
426
|
+
* The batch's deletion of the first of the paragraphs it deletes in a row
|
|
427
|
+
* right before the paragraph at `block`, if it deletes the one before it,
|
|
428
|
+
* and what precedes the run, as `finalBreakCarrier` reads it: `kept` when
|
|
429
|
+
* a paragraph the batch keeps stands there to take the break, `runStart`
|
|
430
|
+
* at the container's start or another block. Tracked, a paragraph a
|
|
431
|
+
* pending deletion already takes whole stands in the run.
|
|
432
|
+
*/
|
|
433
|
+
const deletedRunBeforeBlock = (block, tracked) => {
|
|
434
|
+
const at = doc.resolve(block);
|
|
435
|
+
let position = block;
|
|
436
|
+
let first;
|
|
437
|
+
for (let index = at.index() - 1; index >= 0; index--) {
|
|
438
|
+
const previous = at.parent.child(index);
|
|
439
|
+
position -= previous.nodeSize;
|
|
440
|
+
const deletion = deletionOf.get(position);
|
|
441
|
+
if (deletion === void 0 && tracked && goesWholeOnAcceptance(previous)) continue;
|
|
442
|
+
if (deletion === void 0) {
|
|
443
|
+
if (first === void 0) return void 0;
|
|
444
|
+
return {
|
|
445
|
+
first,
|
|
446
|
+
carrier: previous.type.name === "paragraph" ? "kept" : "runStart"
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
first = deletion;
|
|
450
|
+
}
|
|
451
|
+
return first === void 0 ? void 0 : {
|
|
452
|
+
first,
|
|
453
|
+
carrier: "runStart"
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
const address = (item) => {
|
|
457
|
+
const { operation, plan } = item;
|
|
458
|
+
if (plan.address.type !== "content") return plan.address;
|
|
459
|
+
const planned = plan.address;
|
|
460
|
+
/** This operation's address right after `deletion`, `steps` ranks on. */
|
|
461
|
+
const following = (deletion, steps) => {
|
|
462
|
+
const before = address(deletion);
|
|
463
|
+
return before.type === "content" ? {
|
|
464
|
+
...planned,
|
|
465
|
+
position: before.position,
|
|
466
|
+
rank: before.rank + steps
|
|
467
|
+
} : planned;
|
|
468
|
+
};
|
|
469
|
+
const deletion = plan.claim.type === "merge" && plan.claim.joinsNow ? deletionOf.get(plan.claim.next) : void 0;
|
|
470
|
+
if (deletion !== void 0) return following(deletion, 2);
|
|
471
|
+
const run = operation.type === "deleteBlock" ? deletedRunBeforeBlock(plan.block, item.retiresRunBreak !== void 0) : void 0;
|
|
472
|
+
if (run?.carrier === "kept" && (item.joinsParagraphBefore === true || item.retiresRunBreak === "kept")) return following(run.first, 1);
|
|
473
|
+
if (run?.carrier === "runStart" && item.retiresRunBreak === "runStart") return following(run.first, -1);
|
|
474
|
+
if (item.collapsesRunStart === true) return {
|
|
475
|
+
...planned,
|
|
476
|
+
rank: RUN_START_COLLAPSE_RANK
|
|
477
|
+
};
|
|
478
|
+
const hasDeletedSplit = deletedSplits.has(plan.block);
|
|
479
|
+
return {
|
|
480
|
+
...plan.address,
|
|
481
|
+
position: hasDeletedSplit && operation.type === "deleteBlock" && plan.claim.type === "deleteBlock" ? plan.claim.end : plan.address.position,
|
|
482
|
+
rank: contentRank(operation, { hasDeletedSplit })
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
const access = (item) => {
|
|
486
|
+
const { operation, plan } = item;
|
|
487
|
+
const claim = plan.claim;
|
|
488
|
+
if (claim.type === "merge") return {
|
|
489
|
+
addresses: [plan.block],
|
|
490
|
+
removes: claim.joinsNow ? directJoinTakes(plan.block, claim.next) : [claim.next]
|
|
491
|
+
};
|
|
492
|
+
if (operation.type === "deleteTable" || operation.type === "deleteTableRow") return {
|
|
493
|
+
addresses: [],
|
|
494
|
+
removes: removedTableParagraphs(doc, operation.type, plan.block)
|
|
495
|
+
};
|
|
496
|
+
if (plan.address.type === "column" || plan.address.type === "cell") return {
|
|
497
|
+
addresses: [],
|
|
498
|
+
removes: []
|
|
499
|
+
};
|
|
500
|
+
if (operation.type === "insertBeforeBlock" && joinedAway.has(plan.block)) return {
|
|
501
|
+
addresses: [],
|
|
502
|
+
removes: []
|
|
503
|
+
};
|
|
504
|
+
if (claim.type === "paragraphProperties") return {
|
|
505
|
+
addresses: [plan.block, markOf(plan.block)],
|
|
506
|
+
removes: []
|
|
507
|
+
};
|
|
508
|
+
if (claim.type !== "deleteBlock") return {
|
|
509
|
+
addresses: plan.placedAgainst === plan.block ? [plan.block] : [plan.block, plan.placedAgainst],
|
|
510
|
+
removes: []
|
|
511
|
+
};
|
|
512
|
+
const at = doc.resolve(plan.block);
|
|
513
|
+
const paragraph = doc.nodeAt(plan.block) ?? panic("A planned deletion lost its source paragraph");
|
|
514
|
+
const before = [];
|
|
515
|
+
let position = plan.block;
|
|
516
|
+
for (let index = at.index() - 1; index >= 0; index--) {
|
|
517
|
+
const previous = at.parent.child(index);
|
|
518
|
+
position -= previous.nodeSize;
|
|
519
|
+
if (previous.type !== paragraph.type) break;
|
|
520
|
+
before.push({
|
|
521
|
+
paragraph: position,
|
|
522
|
+
deleted: deleted.has(position)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
const appended = items.some(({ operation: other, plan: otherPlan }) => otherPlan.block === plan.block && (other.type === "insertAfterBlock" || other.type === "insertTable" && other.position !== "before"));
|
|
526
|
+
const prepended = items.some(({ operation: other, plan: otherPlan }) => otherPlan.block === plan.block && other.type === "insertBeforeBlock");
|
|
527
|
+
const carrier = finalBreakCarrier(before);
|
|
528
|
+
const removes = deletionRemovesBlock({
|
|
529
|
+
endsContainer: !appended && paragraphEndsItsContainer(at, paragraph.type.name),
|
|
530
|
+
carrier: prepended ? "kept" : carrier.type
|
|
531
|
+
});
|
|
532
|
+
const takesCarrierMark = !prepended && carrier.type === "kept" && plan.address.type === "content" && plan.address.position < plan.block;
|
|
533
|
+
const joined = [];
|
|
534
|
+
if (mode !== "direct" && !isDeletedPPrMark(paragraph.attrs["pPrMark"])) for (const { paragraph: previous } of before) {
|
|
535
|
+
if (!isDeletedPPrMark(doc.nodeAt(previous)?.attrs["pPrMark"])) break;
|
|
536
|
+
joined.push(previous);
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
addresses: [],
|
|
540
|
+
removes: [
|
|
541
|
+
...removes || item.followsTableInsertion === true ? [plan.block] : [],
|
|
542
|
+
...takesCarrierMark ? [markOf(carrier.paragraph)] : [],
|
|
543
|
+
...joined
|
|
544
|
+
]
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
const runs = groupInsertionRuns(orderBatchOperations(items, address), ({ plan }) => plan.insertionRun, ({ operation }) => operation.type === "setBlockParagraphProperties");
|
|
548
|
+
return orderAddressingBeforeRemoval(runs, (run) => ({
|
|
549
|
+
addresses: run.flatMap((item) => access(item).addresses),
|
|
550
|
+
removes: run.flatMap((item) => access(item).removes)
|
|
551
|
+
})).flat();
|
|
552
|
+
};
|
|
553
|
+
/** A new public kind cannot bypass a canonical compiler/refusal decision. */
|
|
554
|
+
const CANONICAL_PUBLIC_OPERATION_DISPOSITIONS = {
|
|
555
|
+
replaceInBlock: "compile",
|
|
556
|
+
replaceRange: "compile",
|
|
557
|
+
replaceBlock: "compile",
|
|
558
|
+
splitBlock: "compile",
|
|
559
|
+
formatRange: "compile",
|
|
560
|
+
mergeBlockWithNext: "compile",
|
|
561
|
+
setBlockParagraphProperties: "compile",
|
|
562
|
+
insertAfterBlock: "compile",
|
|
563
|
+
insertBeforeBlock: "compile",
|
|
564
|
+
deleteBlock: "compile",
|
|
565
|
+
commentOnBlock: "compile",
|
|
566
|
+
commentOnRange: "compile",
|
|
567
|
+
insertTable: "compile",
|
|
568
|
+
insertSignatureTable: "compile",
|
|
569
|
+
deleteTable: "compile",
|
|
570
|
+
insertTableRow: "compile",
|
|
571
|
+
deleteTableRow: "compile",
|
|
572
|
+
insertTableColumn: "compile",
|
|
573
|
+
deleteTableColumn: "compile",
|
|
574
|
+
mergeTableCells: "compile",
|
|
575
|
+
splitTableCell: "compile"
|
|
576
|
+
};
|
|
577
|
+
const resolveComment = ({ operation, from, to }) => {
|
|
578
|
+
if ("comment" in operation && operation.comment !== void 0) return {
|
|
579
|
+
type: "commented",
|
|
580
|
+
operation,
|
|
581
|
+
comment: {
|
|
582
|
+
text: operation.comment.text,
|
|
583
|
+
from,
|
|
584
|
+
to
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
return {
|
|
588
|
+
type: "plain",
|
|
589
|
+
operation
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* The two paragraphs a direct operation's intents join, if one paragraph's
|
|
594
|
+
* content ends up in another: a deletion that keeps the paragraph before it
|
|
595
|
+
* leaves nothing of the deleted paragraph there, and joins nothing.
|
|
596
|
+
*/
|
|
597
|
+
const joinedParagraphsOf = (operationType, intents) => {
|
|
598
|
+
const join = intents.find((intent) => intent.type === "joinParagraphs");
|
|
599
|
+
if (join === void 0) return void 0;
|
|
600
|
+
if (operationType === "deleteBlock" && join.survivor === "first") return void 0;
|
|
601
|
+
return join.survivor === "first" ? {
|
|
602
|
+
type: "joined",
|
|
603
|
+
blockId: join.blockId,
|
|
604
|
+
retiredBlockId: join.nextBlockId
|
|
605
|
+
} : {
|
|
606
|
+
type: "joined",
|
|
607
|
+
blockId: join.nextBlockId,
|
|
608
|
+
retiredBlockId: join.blockId
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
const SPACING_FIELDS = [
|
|
612
|
+
"spaceBefore",
|
|
613
|
+
"spaceAfter",
|
|
614
|
+
"lineSpacing",
|
|
615
|
+
"lineSpacingRule",
|
|
616
|
+
"beforeAutospacing",
|
|
617
|
+
"afterAutospacing"
|
|
618
|
+
];
|
|
619
|
+
const INDENTATION_FIELDS = [
|
|
620
|
+
"indentLeft",
|
|
621
|
+
"indentRight",
|
|
622
|
+
"indentFirstLine",
|
|
623
|
+
"hangingIndent"
|
|
624
|
+
];
|
|
625
|
+
/**
|
|
626
|
+
* The stated paragraph properties an operation writes: each given property
|
|
627
|
+
* as it says, a spacing or indentation object as the whole direct child, so
|
|
628
|
+
* an attribute it leaves out is removed, and `null` clears a property back
|
|
629
|
+
* to what the style gives. The patch states the paragraph as the parser reads
|
|
630
|
+
* the saved file back: the spacing sides the paragraph states are marked
|
|
631
|
+
* explicit by the parser's own rule, and an indentation is held as read.
|
|
632
|
+
*/
|
|
633
|
+
const statedParagraphPatch = (properties) => {
|
|
634
|
+
const patch = {};
|
|
635
|
+
if (properties.styleId !== void 0) {
|
|
636
|
+
patch["styleId"] = properties.styleId;
|
|
637
|
+
patch["numPrFromStyle"] = null;
|
|
638
|
+
}
|
|
639
|
+
if (properties.outlineLevel !== void 0) patch["outlineLevel"] = properties.outlineLevel;
|
|
640
|
+
if (properties.alignment !== void 0) patch["alignment"] = properties.alignment;
|
|
641
|
+
const { numbering } = properties;
|
|
642
|
+
if (numbering !== void 0 && numbering.kind !== "newList") patch["numPr"] = numbering.kind === "inherit" ? null : numbering;
|
|
643
|
+
const { spacing, indentation } = properties;
|
|
644
|
+
if (spacing !== void 0) {
|
|
645
|
+
for (const field of SPACING_FIELDS) patch[field] = spacing === null ? null : spacing[field] ?? null;
|
|
646
|
+
patch["spacingExplicit"] = spacing === null ? null : spacingSidesAsRead(spacing) ?? null;
|
|
647
|
+
}
|
|
648
|
+
if (indentation !== void 0) {
|
|
649
|
+
const read = indentation === null ? null : indentationAsRead(indentation);
|
|
650
|
+
for (const field of INDENTATION_FIELDS) patch[field] = read === null ? null : read[field] ?? null;
|
|
651
|
+
}
|
|
652
|
+
return patch;
|
|
653
|
+
};
|
|
654
|
+
const resolveParagraphProperties = ({ operation, paragraph, projection, mintList, refusal }) => {
|
|
655
|
+
const requested = operation.properties.numbering;
|
|
656
|
+
const stated = statedNumbering(requested, mintList);
|
|
657
|
+
const patch = statedParagraphPatch({
|
|
658
|
+
...operation.properties,
|
|
659
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
660
|
+
});
|
|
661
|
+
if (Object.keys(patch).length === 0) return refusal("emptyOperation");
|
|
662
|
+
const at = projection.addressAt(paragraph.start);
|
|
663
|
+
if (at.isErr()) return refusal("unsupportedBlock");
|
|
664
|
+
const intents = [{
|
|
665
|
+
type: "formatParagraph",
|
|
666
|
+
at: at.value,
|
|
667
|
+
patch,
|
|
668
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
669
|
+
}];
|
|
670
|
+
return Result.ok({
|
|
671
|
+
type: "plain",
|
|
672
|
+
operation,
|
|
673
|
+
intents,
|
|
674
|
+
normalizations: [],
|
|
675
|
+
from: paragraph.start,
|
|
676
|
+
to: paragraph.start + paragraph.node.content.size
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
/**
|
|
680
|
+
* The intent that states `properties` on one paragraph by its identity,
|
|
681
|
+
* none when they state nothing.
|
|
682
|
+
*/
|
|
683
|
+
const statedPropertiesIntents = ({ story, blockId, properties, mintList }) => {
|
|
684
|
+
if (properties === void 0) return [];
|
|
685
|
+
const stated = statedNumbering(properties.numbering, mintList);
|
|
686
|
+
const patch = statedParagraphPatch({
|
|
687
|
+
...properties,
|
|
688
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
689
|
+
});
|
|
690
|
+
if (Object.keys(patch).length === 0) return [];
|
|
691
|
+
return [{
|
|
692
|
+
type: "formatParagraph",
|
|
693
|
+
at: {
|
|
694
|
+
story,
|
|
695
|
+
blockId,
|
|
696
|
+
offset: 0
|
|
697
|
+
},
|
|
698
|
+
patch,
|
|
699
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
700
|
+
}];
|
|
701
|
+
};
|
|
702
|
+
const isBlockInsertion = (operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock";
|
|
703
|
+
const placesBlock = (operation) => isBlockInsertion(operation) || operation.type === "insertTable" || operation.type === "insertSignatureTable";
|
|
704
|
+
/**
|
|
705
|
+
* Where an insertion beside `paragraph` goes: beside the paragraph, or, for a
|
|
706
|
+
* paragraph in a table cell, beside the outermost table, as the default
|
|
707
|
+
* engine places it. The point names the paragraph on the far side of the
|
|
708
|
+
* table; where none stands there (the table starts its container, or a table
|
|
709
|
+
* or control stands beside it), it names the table itself.
|
|
710
|
+
*/
|
|
711
|
+
const blockInsertionPlace = (operation, paragraph, projection, noteReferences) => {
|
|
712
|
+
const side = operation.type === "insertAfterBlock" ? "after" : "before";
|
|
713
|
+
const table = findOutermostTableBoundary(projection.doc, paragraph.start - 1);
|
|
714
|
+
if (table === null && side === "before") {
|
|
715
|
+
const gap = insertionGap(projection.doc, paragraph.start - 1, "before");
|
|
716
|
+
if (gap < paragraph.start - 1) {
|
|
717
|
+
const $gap = projection.doc.resolve(gap);
|
|
718
|
+
const first = $gap.nodeAfter;
|
|
719
|
+
const previous = $gap.nodeBefore;
|
|
720
|
+
const end = previous?.type.name === "paragraph" ? projection.paragraphStartingAt(gap - previous.nodeSize) : void 0;
|
|
721
|
+
if (end !== void 0) return {
|
|
722
|
+
at: {
|
|
723
|
+
type: "after",
|
|
724
|
+
blockId: end.blockId
|
|
725
|
+
},
|
|
726
|
+
position: paragraph.start
|
|
727
|
+
};
|
|
728
|
+
if (first?.type.name === "table") {
|
|
729
|
+
const blockId = tableBlockAddress(projection, {
|
|
730
|
+
table: first,
|
|
731
|
+
tableStart: gap + 1
|
|
732
|
+
});
|
|
733
|
+
if (blockId !== void 0) return {
|
|
734
|
+
at: {
|
|
735
|
+
type: "beforeTable",
|
|
736
|
+
blockId
|
|
737
|
+
},
|
|
738
|
+
position: paragraph.start
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
const start = first?.type.name === "paragraph" ? projection.paragraphStartingAt(gap) : void 0;
|
|
742
|
+
if (start !== void 0) return {
|
|
743
|
+
at: {
|
|
744
|
+
type: "before",
|
|
745
|
+
blockId: start.blockId
|
|
746
|
+
},
|
|
747
|
+
position: paragraph.start
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (table === null) return {
|
|
752
|
+
at: {
|
|
753
|
+
type: side,
|
|
754
|
+
blockId: paragraph.blockId
|
|
755
|
+
},
|
|
756
|
+
position: side === "after" ? paragraph.start + paragraph.node.content.size : paragraph.start
|
|
757
|
+
};
|
|
758
|
+
const joining = side === "before" ? firstParagraphJoiningTable({
|
|
759
|
+
doc: projection.doc,
|
|
760
|
+
paragraphPos: table.before,
|
|
761
|
+
noteReferences
|
|
762
|
+
}) : null;
|
|
763
|
+
const joined = joining === null ? void 0 : projection.paragraphStartingAt(joining);
|
|
764
|
+
if (joined !== void 0) return {
|
|
765
|
+
at: {
|
|
766
|
+
type: "before",
|
|
767
|
+
blockId: joined.blockId
|
|
768
|
+
},
|
|
769
|
+
position: joined.start
|
|
770
|
+
};
|
|
771
|
+
const position = table[side];
|
|
772
|
+
const resolved = projection.doc.resolve(position);
|
|
773
|
+
const beside = side === "after" ? resolved.nodeAfter : resolved.nodeBefore;
|
|
774
|
+
const neighbour = beside?.type.name === "paragraph" ? projection.paragraphStartingAt(side === "after" ? position : position - beside.nodeSize) : void 0;
|
|
775
|
+
if (neighbour !== void 0) return {
|
|
776
|
+
at: {
|
|
777
|
+
type: side === "after" ? "before" : "after",
|
|
778
|
+
blockId: neighbour.blockId
|
|
779
|
+
},
|
|
780
|
+
position
|
|
781
|
+
};
|
|
782
|
+
const outerTable = projection.doc.nodeAt(table.before);
|
|
783
|
+
const blockId = outerTable === null ? void 0 : tableBlockAddress(projection, {
|
|
784
|
+
table: outerTable,
|
|
785
|
+
tableStart: table.before + 1
|
|
786
|
+
});
|
|
787
|
+
if (blockId === void 0) return void 0;
|
|
788
|
+
return {
|
|
789
|
+
at: {
|
|
790
|
+
type: side === "after" ? "afterTable" : "beforeTable",
|
|
791
|
+
blockId
|
|
792
|
+
},
|
|
793
|
+
position
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
/** Beside the paragraph an insertion names as it stands, with its properties. */
|
|
797
|
+
const besideAsItStands = (paragraph) => ({
|
|
798
|
+
place: paragraph,
|
|
799
|
+
formattingSource: paragraph
|
|
800
|
+
});
|
|
801
|
+
/**
|
|
802
|
+
* Where a paragraph put after `paragraph` goes (`insertionAfterPendingBreak`):
|
|
803
|
+
* right after it, or after the paragraph its pending join leaves, in every
|
|
804
|
+
* mode, so a suggestion lands where the same tracked insertion does.
|
|
805
|
+
*/
|
|
806
|
+
const placeAfter = ({ paragraph, projection, noteReferences }) => {
|
|
807
|
+
const rule = insertionAfterPendingBreak({
|
|
808
|
+
doc: projection.doc,
|
|
809
|
+
paragraphPos: paragraph.start - 1,
|
|
810
|
+
noteReferences
|
|
811
|
+
});
|
|
812
|
+
switch (rule.type) {
|
|
813
|
+
case "afterParagraph": return besideAsItStands(paragraph);
|
|
814
|
+
case "afterJoin": {
|
|
815
|
+
const survivor = projection.paragraphStartingAt(rule.survivor) ?? panic("A pending join names a paragraph the projection lacks.");
|
|
816
|
+
return besideAsItStands(survivor);
|
|
817
|
+
}
|
|
818
|
+
default: return rule;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* A pending join as the batch reads it once its earlier operations ran: a
|
|
823
|
+
* paragraph one of them puts right after a paragraph of the join, taking its
|
|
824
|
+
* words, ends the join there, so the join a later block put before reads
|
|
825
|
+
* starts past it, as it does applied one at a time.
|
|
826
|
+
*/
|
|
827
|
+
const joinAsTheBatchRuns = ({ join, before, doc, noteReferences }) => {
|
|
828
|
+
if (before === void 0 || before.size === 0) return join;
|
|
829
|
+
const at = doc.resolve(join.first);
|
|
830
|
+
let first = join.first;
|
|
831
|
+
let position = join.first;
|
|
832
|
+
for (let index = at.index(); index < at.parent.childCount; index++) {
|
|
833
|
+
const node = at.parent.child(index);
|
|
834
|
+
const next = position + node.nodeSize;
|
|
835
|
+
if (next > join.last) break;
|
|
836
|
+
const id = node.attrs["paraId"];
|
|
837
|
+
if (node.type.name === "paragraph" && typeof id === "string" && before.has(id) && insertionAfterPendingBreak({
|
|
838
|
+
doc,
|
|
839
|
+
paragraphPos: position,
|
|
840
|
+
noteReferences
|
|
841
|
+
}).type === "afterParagraph") first = next;
|
|
842
|
+
position = next;
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
first,
|
|
846
|
+
last: join.last
|
|
847
|
+
};
|
|
848
|
+
};
|
|
849
|
+
/** Whether `paragraph` holds anything no pending deletion takes. */
|
|
850
|
+
const holdsStandingContent = (paragraph) => {
|
|
851
|
+
let standing = false;
|
|
852
|
+
paragraph.descendants((node) => {
|
|
853
|
+
if (standing) return false;
|
|
854
|
+
if (node.isInline && !node.marks.some(({ type }) => type.name === "deletion")) standing = true;
|
|
855
|
+
return !standing;
|
|
856
|
+
});
|
|
857
|
+
return standing;
|
|
858
|
+
};
|
|
859
|
+
/** `formatting` with no numbering of its own or from its style. */
|
|
860
|
+
const withoutNumbering = ({ numPr: _numPr, numPrFromStyle: _numPrFromStyle, ...formatting }) => formatting;
|
|
861
|
+
/**
|
|
862
|
+
* Whether accepting every pending change takes the paragraph whole: its break
|
|
863
|
+
* goes (deleted, or inserted and deleted since), and every record it holds is
|
|
864
|
+
* deleted or moved away.
|
|
865
|
+
*/
|
|
866
|
+
const isTakenWholeOnAcceptance = ({ pPrMark, content }) => (pPrMark?.kind === "del" || pPrMark?.kind === "moveFrom" || pPrMark?.deletion !== void 0) && content.every(({ type }) => type === "deletion" || type === "moveFrom");
|
|
867
|
+
/**
|
|
868
|
+
* The properties an inserted paragraph copies from `source`. A paragraph a
|
|
869
|
+
* pending join reaches, which a pending deletion takes whole, lends no
|
|
870
|
+
* numbering: once accepted, the list item it was is gone. A paragraph the
|
|
871
|
+
* operation names lends all of them, as the default engine copies them.
|
|
872
|
+
*/
|
|
873
|
+
const lentFormatting = ({ formatting, source, namesSource }) => formatting !== void 0 && !namesSource && isTakenWholeOnAcceptance(source) ? withoutNumbering(formatting) : formatting;
|
|
874
|
+
/**
|
|
875
|
+
* The ids of the paragraphs right before the one at `paragraphPos` whose
|
|
876
|
+
* marks are pending deletion: a pending join runs them into it.
|
|
877
|
+
*/
|
|
878
|
+
const joinedBefore = (doc, paragraphPos) => {
|
|
879
|
+
const at = doc.resolve(paragraphPos);
|
|
880
|
+
const ids = [];
|
|
881
|
+
for (let index = at.index() - 1; index >= 0; index--) {
|
|
882
|
+
const previous = at.parent.child(index);
|
|
883
|
+
const id = previous.attrs["paraId"];
|
|
884
|
+
if (previous.type.name !== "paragraph" || !isDeletedPPrMark(previous.attrs["pPrMark"]) || typeof id !== "string") break;
|
|
885
|
+
ids.push(id);
|
|
886
|
+
}
|
|
887
|
+
return ids;
|
|
888
|
+
};
|
|
889
|
+
/** Whether a pending deletion already takes `paragraph` whole, mark and words. */
|
|
890
|
+
const goesWholeOnAcceptance = (paragraph) => paragraph.type.name === "paragraph" && isDeletedPPrMark(paragraph.attrs["pPrMark"]) && !holdsStandingContent(paragraph);
|
|
891
|
+
/**
|
|
892
|
+
* Whether the blocks after `position` in its container are paragraphs that
|
|
893
|
+
* hold nothing once accepted, each before the last with its break pending
|
|
894
|
+
* deletion, and no section break among them, as the docx-core block deletion
|
|
895
|
+
* reads a container's end.
|
|
896
|
+
*/
|
|
897
|
+
const followersGoOnAcceptance = (doc, position) => {
|
|
898
|
+
const at = doc.resolve(position);
|
|
899
|
+
const { parent } = at;
|
|
900
|
+
for (let index = at.index(); index < parent.childCount; index += 1) {
|
|
901
|
+
const block = parent.child(index);
|
|
902
|
+
if (block.type.name !== "paragraph" || block.attrs["_sectionProperties"] != null || holdsStandingContent(block) || index < parent.childCount - 1 && !goesWholeOnAcceptance(block)) return false;
|
|
903
|
+
}
|
|
904
|
+
return at.index() < parent.childCount;
|
|
905
|
+
};
|
|
906
|
+
/**
|
|
907
|
+
* Where an insertion beside `paragraph` goes, read as the joined paragraph a
|
|
908
|
+
* pending join makes of it in the document the batch read
|
|
909
|
+
* (`pendingJoinParagraphs`, which the legacy engine places by too): after
|
|
910
|
+
* the join's last paragraph, or before its first, copying the properties of
|
|
911
|
+
* the paragraph the join leaves, which the joined paragraph has. The batch's
|
|
912
|
+
* other operations do not move it: a split of the paragraph the join leaves
|
|
913
|
+
* puts the block after both halves, as one put after that paragraph goes.
|
|
914
|
+
* Where no join reads the paragraph, `pendingJoinParagraphs` names the
|
|
915
|
+
* paragraph itself on that side, so the block goes beside it: one place
|
|
916
|
+
* decides, so a paragraph going whole that earlier words run into is placed
|
|
917
|
+
* before those words, as every other paragraph of the join is.
|
|
918
|
+
*/
|
|
919
|
+
const besidePendingJoin = ({ side, paragraph, projection, noteReferences, paragraphsAfterEarlier }) => {
|
|
920
|
+
const options = {
|
|
921
|
+
doc: projection.doc,
|
|
922
|
+
paragraphPos: paragraph.start - 1,
|
|
923
|
+
noteReferences
|
|
924
|
+
};
|
|
925
|
+
const join = joinAsTheBatchRuns({
|
|
926
|
+
join: pendingJoinParagraphs(options),
|
|
927
|
+
before: side === "before" ? paragraphsAfterEarlier : void 0,
|
|
928
|
+
doc: projection.doc,
|
|
929
|
+
noteReferences
|
|
930
|
+
});
|
|
931
|
+
const after = side === "after";
|
|
932
|
+
const at = (position) => position === options.paragraphPos ? paragraph : projection.paragraphStartingAt(position);
|
|
933
|
+
const place = at(after ? join.last : join.first);
|
|
934
|
+
const formattingSource = at(join.last);
|
|
935
|
+
if (place === void 0 || formattingSource === void 0) return panic("A pending join names a paragraph the projection lacks.");
|
|
936
|
+
return {
|
|
937
|
+
place,
|
|
938
|
+
formattingSource
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
* One new paragraph beside the anchor, as the legacy engine writes it: the
|
|
943
|
+
* anchor's stated paragraph properties unless `inheritFormatting` is false,
|
|
944
|
+
* with the operation's own on top, holding the text as one plain run.
|
|
945
|
+
*/
|
|
946
|
+
const resolveBlockInsertion = ({ operation, listStart, paragraph, named, formattingSource, projection, noteReferences, story, mintList, refusal, skipAlike }) => {
|
|
947
|
+
const { text } = operation;
|
|
948
|
+
const markdown = operation.textFormat === "markdown" ? compileMarkdownInsertion(text) : void 0;
|
|
949
|
+
if (markdown?.type === "unsupported") return skipAlike("unsupportedBlock", markdown.message);
|
|
950
|
+
const requested = markdown?.listKind === void 0 ? operation.numbering : {
|
|
951
|
+
kind: "newList",
|
|
952
|
+
format: markdown.listKind
|
|
953
|
+
};
|
|
954
|
+
const stated = statedNumbering(requested, mintList);
|
|
955
|
+
const inline = operation.lineBreakMode === "inline";
|
|
956
|
+
if (markdown === void 0 && !noteReferenceEditsAllowed() && /\[\^(?:e)?\d+\]/u.test(text)) return refusal("unsupportedBlock", "Canonical block insertion requires plain text.");
|
|
957
|
+
const split = markdown === void 0 && !inline && LINE_BREAK_PATTERN.test(text);
|
|
958
|
+
const lines = split ? text.split(LINE_BREAK_PATTERN).filter((line) => line.trim().length > 0) : [text];
|
|
959
|
+
const texts = lines.length === 0 ? [""] : lines;
|
|
960
|
+
const ownPatch = Object.entries(statedParagraphPatch({
|
|
961
|
+
...operation.styleId === void 0 ? {} : { styleId: operation.styleId },
|
|
962
|
+
...operation.outlineLevel === void 0 ? {} : { outlineLevel: operation.outlineLevel },
|
|
963
|
+
...operation.alignment === void 0 ? {} : { alignment: operation.alignment },
|
|
964
|
+
...operation.spacing === void 0 ? {} : { spacing: operation.spacing },
|
|
965
|
+
...operation.indentation === void 0 ? {} : { indentation: operation.indentation },
|
|
966
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
967
|
+
}));
|
|
968
|
+
const everyParagraph = operation.formattingScope === "allParagraphs";
|
|
969
|
+
const markdownNumbering = stated.numbering?.kind === "reference" ? stated.numbering : void 0;
|
|
970
|
+
let markdownParagraphs;
|
|
971
|
+
if (markdown !== void 0) {
|
|
972
|
+
markdownParagraphs = [];
|
|
973
|
+
for (const { listRendering: _listRendering, ...item } of markdown.paragraphs) {
|
|
974
|
+
if (markdownNumbering !== void 0) item.formatting = {
|
|
975
|
+
...item.formatting,
|
|
976
|
+
numPr: markdownNumbering
|
|
977
|
+
};
|
|
978
|
+
markdownParagraphs.push(item);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const paragraphsFrom = (source) => {
|
|
982
|
+
const formatting = operation.inheritFormatting === false ? {} : { ...source };
|
|
983
|
+
for (const [key, value] of ownPatch) if (value === null) Reflect.deleteProperty(formatting, key);
|
|
984
|
+
else formatting[key] = value;
|
|
985
|
+
return texts.map((line, index) => {
|
|
986
|
+
const own = index === 0 || everyParagraph ? { ...formatting } : {};
|
|
987
|
+
if (index === 0 && operation.pageBreakBefore === true) own["pageBreakBefore"] = true;
|
|
988
|
+
const pageBreak = index === 0 ? operation.hardPageBreak : void 0;
|
|
989
|
+
let content = [];
|
|
990
|
+
if (pageBreak !== void 0) content = [{
|
|
991
|
+
type: "run",
|
|
992
|
+
content: [{
|
|
993
|
+
type: "break",
|
|
994
|
+
breakType: "page",
|
|
995
|
+
...pageBreak.clear === void 0 ? {} : { clear: pageBreak.clear }
|
|
996
|
+
}]
|
|
997
|
+
}];
|
|
998
|
+
else if (line !== "") content = emphasisRuns(line);
|
|
999
|
+
return {
|
|
1000
|
+
type: "paragraph",
|
|
1001
|
+
content,
|
|
1002
|
+
...Object.keys(own).length === 0 ? {} : { formatting: own }
|
|
1003
|
+
};
|
|
1004
|
+
});
|
|
1005
|
+
};
|
|
1006
|
+
const sourceFormatting = paragraphFormattingWithAuthoredIndentation(formattingSource.source);
|
|
1007
|
+
const namesSource = formattingSource.blockId === named.blockId;
|
|
1008
|
+
const paragraphs = markdownParagraphs ?? paragraphsFrom(lentFormatting({
|
|
1009
|
+
formatting: sourceFormatting,
|
|
1010
|
+
source: formattingSource.source,
|
|
1011
|
+
namesSource
|
|
1012
|
+
}));
|
|
1013
|
+
const place = listStart === void 0 ? blockInsertionPlace(operation, paragraph, projection, noteReferences) : {
|
|
1014
|
+
at: {
|
|
1015
|
+
type: "containerStart",
|
|
1016
|
+
blockId: listStart.blockId
|
|
1017
|
+
},
|
|
1018
|
+
position: listStart.position
|
|
1019
|
+
};
|
|
1020
|
+
if (place === void 0) return refusal("unsupportedBlock", "Canonical insertion beside a table needs a paragraph on that side of it.");
|
|
1021
|
+
const intents = [{
|
|
1022
|
+
type: "insertParagraphs",
|
|
1023
|
+
story,
|
|
1024
|
+
at: place.at,
|
|
1025
|
+
paragraphs,
|
|
1026
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
1027
|
+
}];
|
|
1028
|
+
const { position } = place;
|
|
1029
|
+
if (operation.comment !== void 0 && texts.every((line) => line.length === 0)) return refusal("unsupportedBlock");
|
|
1030
|
+
const resolved = {
|
|
1031
|
+
intents,
|
|
1032
|
+
normalizations: split ? [{
|
|
1033
|
+
id: operation.id,
|
|
1034
|
+
code: "splitMultilineText",
|
|
1035
|
+
paragraphCount: texts.length
|
|
1036
|
+
}] : [],
|
|
1037
|
+
from: position,
|
|
1038
|
+
to: position,
|
|
1039
|
+
...markdownParagraphs === void 0 && operation.inheritFormatting !== false ? { inheritsFrom: {
|
|
1040
|
+
blockId: formattingSource.blockId,
|
|
1041
|
+
markDeleted: isDeletedPPrMark(formattingSource.node.attrs["pPrMark"]),
|
|
1042
|
+
followsAnchor: operation.type === "insertAfterBlock" && formattingSource.blockId === paragraph.blockId,
|
|
1043
|
+
namesSource,
|
|
1044
|
+
paragraphs: paragraphsFrom
|
|
1045
|
+
} } : {}
|
|
1046
|
+
};
|
|
1047
|
+
if (operation.comment === void 0) return Result.ok({
|
|
1048
|
+
type: "plain",
|
|
1049
|
+
operation,
|
|
1050
|
+
...resolved
|
|
1051
|
+
});
|
|
1052
|
+
const anchor = {
|
|
1053
|
+
story,
|
|
1054
|
+
blockId: place.at.blockId,
|
|
1055
|
+
offset: 0
|
|
1056
|
+
};
|
|
1057
|
+
return Result.ok({
|
|
1058
|
+
type: "commented",
|
|
1059
|
+
operation,
|
|
1060
|
+
comment: {
|
|
1061
|
+
text: operation.comment.text,
|
|
1062
|
+
from: anchor,
|
|
1063
|
+
to: anchor,
|
|
1064
|
+
inserted: true
|
|
1065
|
+
},
|
|
1066
|
+
...resolved
|
|
1067
|
+
});
|
|
1068
|
+
};
|
|
1069
|
+
/**
|
|
1070
|
+
* A tracked deletion of the paragraph that ends its block list, retiring the
|
|
1071
|
+
* break of the paragraph before it in `document`, the batch as it stands
|
|
1072
|
+
* when the deletion runs: an insertion the order ran first, right before the
|
|
1073
|
+
* deleted paragraph, is the paragraph whose break it retires, as deleting it
|
|
1074
|
+
* after that insertion does.
|
|
1075
|
+
*/
|
|
1076
|
+
const retiredBreakAsItRuns = (document, story, intents) => {
|
|
1077
|
+
return intents.map((intent) => {
|
|
1078
|
+
if (intent.type !== "replaceText") return intent;
|
|
1079
|
+
const here = locateParagraphThroughTextBoxes(document, story, intent.to.blockId);
|
|
1080
|
+
const before = here?.blocks[here.index - 1];
|
|
1081
|
+
if (before?.type !== "paragraph" || before.paraId === void 0 || idKey(before.paraId) === idKey(intent.from.blockId)) return intent;
|
|
1082
|
+
return {
|
|
1083
|
+
...intent,
|
|
1084
|
+
from: {
|
|
1085
|
+
story: intent.from.story,
|
|
1086
|
+
blockId: before.paraId,
|
|
1087
|
+
offset: paragraphLength(before)
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* A direct deletion's join with the paragraph before it, bound to the
|
|
1094
|
+
* paragraph before it in `document`, the batch as it stands when the
|
|
1095
|
+
* deletion runs: an insertion the order ran first, right before the deleted
|
|
1096
|
+
* paragraph, is the paragraph it joins, as deleting it after that insertion
|
|
1097
|
+
* joins it.
|
|
1098
|
+
*/
|
|
1099
|
+
const deletionIntentsAsItRuns = (document, story, intents) => {
|
|
1100
|
+
return intents.map((intent) => {
|
|
1101
|
+
if (intent.type !== "joinParagraphs") return intent;
|
|
1102
|
+
const here = locateParagraphThroughTextBoxes(document, story, intent.nextBlockId);
|
|
1103
|
+
const before = here?.blocks[here.index - 1];
|
|
1104
|
+
if (before?.type !== "paragraph" || before.paraId === void 0 || idKey(before.paraId) === idKey(intent.blockId)) return intent;
|
|
1105
|
+
return {
|
|
1106
|
+
...intent,
|
|
1107
|
+
blockId: before.paraId
|
|
1108
|
+
};
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* A direct paragraph deletion as it runs in `document`: a paragraph the
|
|
1113
|
+
* batch's earlier operations left last in its container is deleted as a
|
|
1114
|
+
* final one is. It loses its words and joins the paragraph before it, which
|
|
1115
|
+
* keeps its identity and properties; with none before it, it only loses its
|
|
1116
|
+
* words, as the container keeps a paragraph.
|
|
1117
|
+
*/
|
|
1118
|
+
const finalDeletionIntentsAsItRuns = (document, story, intents) => {
|
|
1119
|
+
const [deletion, ...rest] = intents;
|
|
1120
|
+
if (deletion?.type !== "deleteParagraphs" || deletion.move === true || rest.length > 0 || deletion.blockIds.length !== 1) return intents;
|
|
1121
|
+
const blockId = deletion.blockIds.at(0);
|
|
1122
|
+
if (blockId === void 0) return intents;
|
|
1123
|
+
const here = locateParagraphThroughTextBoxes(document, story, blockId);
|
|
1124
|
+
if (here === void 0 || here.index !== here.blocks.length - 1) return intents;
|
|
1125
|
+
const length = paragraphLength(here.paragraph);
|
|
1126
|
+
const cleared = length === 0 ? [] : [{
|
|
1127
|
+
type: "replaceText",
|
|
1128
|
+
from: {
|
|
1129
|
+
story,
|
|
1130
|
+
blockId,
|
|
1131
|
+
offset: 0
|
|
1132
|
+
},
|
|
1133
|
+
to: {
|
|
1134
|
+
story,
|
|
1135
|
+
blockId,
|
|
1136
|
+
offset: length
|
|
1137
|
+
},
|
|
1138
|
+
text: ""
|
|
1139
|
+
}];
|
|
1140
|
+
const before = here.blocks[here.index - 1];
|
|
1141
|
+
if (before?.type !== "paragraph" || before.paraId === void 0) return cleared;
|
|
1142
|
+
return [...cleared, {
|
|
1143
|
+
type: "joinParagraphs",
|
|
1144
|
+
story,
|
|
1145
|
+
blockId: before.paraId,
|
|
1146
|
+
nextBlockId: blockId,
|
|
1147
|
+
survivor: SPLIT_HALVES.FIRST
|
|
1148
|
+
}];
|
|
1149
|
+
};
|
|
1150
|
+
/**
|
|
1151
|
+
* Paragraph property edits, tables and paragraph insertions beside a
|
|
1152
|
+
* paragraph, bound to the paragraph as the batch stands when they run: one
|
|
1153
|
+
* an earlier operation joined away, such as the first half of a split whose
|
|
1154
|
+
* retraction joins it to the second, a paragraph a direct deletion of the
|
|
1155
|
+
* paragraphs after it joined into the last one, or a paragraph that took the
|
|
1156
|
+
* mark of the run a block deletion of the batch deleted after it, is edited,
|
|
1157
|
+
* or has its table or insertion beside it, in the paragraph that now holds
|
|
1158
|
+
* it; a join's absorbed half keeps its own place for an insertion, except
|
|
1159
|
+
* that a paragraph put before it goes before the paragraph its words open,
|
|
1160
|
+
* as a merge into the next paragraph leaves them. A table after it then
|
|
1161
|
+
* writes the empty paragraph the container ends with when that paragraph
|
|
1162
|
+
* ends its block list.
|
|
1163
|
+
*/
|
|
1164
|
+
const formattingIntentsAsItRuns = ({ document, story, survivorOf, openingSurvivorOf, deletionSurvivorOf, intents }) => {
|
|
1165
|
+
if (survivorOf.size === 0) return intents;
|
|
1166
|
+
const present = new Set(paragraphsThroughTextBoxes(document, story).map(({ paragraph }) => idKey(paragraph.paraId ?? "")));
|
|
1167
|
+
const bound = (at, survivors = survivorOf) => {
|
|
1168
|
+
const survivor = survivors.get(idKey(at.blockId));
|
|
1169
|
+
return survivor === void 0 || present.has(idKey(at.blockId)) ? at : {
|
|
1170
|
+
story: at.story,
|
|
1171
|
+
blockId: survivor,
|
|
1172
|
+
offset: 0
|
|
1173
|
+
};
|
|
1174
|
+
};
|
|
1175
|
+
return intents.map((intent) => {
|
|
1176
|
+
switch (intent.type) {
|
|
1177
|
+
case "tableBlock": {
|
|
1178
|
+
const { operation } = intent;
|
|
1179
|
+
if (operation.type !== DOCUMENT_OP_TYPES.INSERT_TABLE || operation.anchor !== "paragraph") return intent;
|
|
1180
|
+
const { blockId } = bound({
|
|
1181
|
+
story: operation.story,
|
|
1182
|
+
blockId: operation.blockId,
|
|
1183
|
+
offset: 0
|
|
1184
|
+
});
|
|
1185
|
+
if (blockId === operation.blockId) return intent;
|
|
1186
|
+
const here = locateParagraphThroughTextBoxes(document, story, blockId);
|
|
1187
|
+
const ends = here !== void 0 && here.index === here.blocks.length - 1;
|
|
1188
|
+
return {
|
|
1189
|
+
...intent,
|
|
1190
|
+
operation: {
|
|
1191
|
+
...operation,
|
|
1192
|
+
blockId,
|
|
1193
|
+
...operation.side === "after" && ends ? { paragraphAfter: "empty" } : {}
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
case "formatParagraph": return {
|
|
1198
|
+
...intent,
|
|
1199
|
+
at: bound(intent.at)
|
|
1200
|
+
};
|
|
1201
|
+
case "setList": return {
|
|
1202
|
+
...intent,
|
|
1203
|
+
items: intent.items.map((item) => ({
|
|
1204
|
+
...item,
|
|
1205
|
+
at: bound(item.at)
|
|
1206
|
+
}))
|
|
1207
|
+
};
|
|
1208
|
+
case "insertParagraphs": {
|
|
1209
|
+
const { at } = intent;
|
|
1210
|
+
if (at.type !== "before" && at.type !== "after") return intent;
|
|
1211
|
+
if (present.has(idKey(at.blockId))) return intent;
|
|
1212
|
+
const opening = at.type === "before" ? openingSurvivorOf.get(idKey(at.blockId)) : void 0;
|
|
1213
|
+
if (opening !== void 0) return {
|
|
1214
|
+
...intent,
|
|
1215
|
+
at: {
|
|
1216
|
+
type: "before",
|
|
1217
|
+
blockId: opening
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
const { blockId } = bound({
|
|
1221
|
+
story,
|
|
1222
|
+
blockId: at.blockId,
|
|
1223
|
+
offset: 0
|
|
1224
|
+
}, deletionSurvivorOf);
|
|
1225
|
+
return blockId === at.blockId ? intent : {
|
|
1226
|
+
...intent,
|
|
1227
|
+
at: {
|
|
1228
|
+
type: at.type,
|
|
1229
|
+
blockId
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
default: return intent;
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
};
|
|
1237
|
+
/**
|
|
1238
|
+
* Whether the absorbed paragraph's words open the survivor: it stood
|
|
1239
|
+
* before it in the same block list.
|
|
1240
|
+
*/
|
|
1241
|
+
const opensSurvivor = ({ document, story, absorption: { absorbed, survivor } }) => {
|
|
1242
|
+
const gone = locateParagraphThroughTextBoxes(document, story, absorbed);
|
|
1243
|
+
const kept = locateParagraphThroughTextBoxes(document, story, survivor);
|
|
1244
|
+
return gone !== void 0 && kept !== void 0 && gone.blocks === kept.blocks && gone.index < kept.index;
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* A tracked deletion of a body paragraph whose break is `author`'s own
|
|
1248
|
+
* pending insertion, right before a table whose rows are all pending
|
|
1249
|
+
* insertion, as the batch stands when it runs: the block deletion records
|
|
1250
|
+
* the deletion beside that insertion and takes the words, so accepting
|
|
1251
|
+
* removes the paragraph as the direct deletion does. Read as it runs, it is
|
|
1252
|
+
* the same whether that table, or that insertion, came before the batch or
|
|
1253
|
+
* from it.
|
|
1254
|
+
*/
|
|
1255
|
+
const ownMarkBeforeInsertedTableAsItRuns = ({ document, story, blockId, author, gainsFollower, intents }) => {
|
|
1256
|
+
const blocks = findStoryBody(document, story)?.content ?? [];
|
|
1257
|
+
const index = blocks.findIndex((block) => block.type === "paragraph" && idKey(block.paraId ?? "") === idKey(blockId));
|
|
1258
|
+
const paragraph = blocks[index];
|
|
1259
|
+
const following = blocks[index + 1];
|
|
1260
|
+
const previous = blocks[index - 1];
|
|
1261
|
+
if (previous?.type === "paragraph" && !gainsFollower(previous.paraId ?? "") && (previous.pPrMark?.kind === "del" || previous.pPrMark?.kind === "moveFrom" || previous.pPrMark?.deletion !== void 0) || paragraph?.type !== "paragraph" || paragraph.paraId === void 0 || paragraph.pPrMark?.kind !== "ins" || paragraph.pPrMark.deletion !== void 0 || paragraph.pPrMark.info.author !== author || following?.type !== "table" || following.rows.length === 0 || !following.rows.every((row) => row.structuralChange?.type === "tableRowInsertion")) return intents;
|
|
1262
|
+
return [{
|
|
1263
|
+
type: "deleteParagraphs",
|
|
1264
|
+
story,
|
|
1265
|
+
blockIds: [paragraph.paraId]
|
|
1266
|
+
}];
|
|
1267
|
+
};
|
|
1268
|
+
/**
|
|
1269
|
+
* A tracked deletion of the body's last paragraph, as the batch stands when
|
|
1270
|
+
* it runs, that takes back this owner's (`author`, and `suggestionId` in a
|
|
1271
|
+
* suggestion) insertion after the paragraph before it: that paragraph holds
|
|
1272
|
+
* the insertion's new break (`survivor: "first"`) and the last one only its
|
|
1273
|
+
* words, and the anchors of comments on them, under the former mark it took
|
|
1274
|
+
* over. The block deletion rejects that insertion, so the paragraph before
|
|
1275
|
+
* keeps its identity and gets its mark and properties back, and the comments
|
|
1276
|
+
* it leaves nothing of retire; a text range over the break would retire its
|
|
1277
|
+
* identity.
|
|
1278
|
+
*/
|
|
1279
|
+
const takenOverBreakRetractionAsItRuns = ({ document, story, blockId, author, suggestionId, intents }) => {
|
|
1280
|
+
const blocks = findStoryBody(document, story)?.content ?? [];
|
|
1281
|
+
const paragraph = blocks.at(-1);
|
|
1282
|
+
const previous = blocks.at(-2);
|
|
1283
|
+
const owns = (info) => info.author === author && info.suggestionId === suggestionId;
|
|
1284
|
+
if (paragraph?.type !== "paragraph" || paragraph.paraId === void 0 || idKey(paragraph.paraId) !== idKey(blockId) || !paragraph.content.every((item) => item.type === "insertion" && owns(item.info) || isCommentAnchorCarrierType(item.type)) || previous?.type !== "paragraph" || previous.pPrMark?.kind !== "ins" || previous.pPrMark.deletion !== void 0 || previous.pPrMark.survivor !== "first" || !owns(previous.pPrMark.info)) return intents;
|
|
1285
|
+
return [{
|
|
1286
|
+
type: "deleteParagraphs",
|
|
1287
|
+
story,
|
|
1288
|
+
blockIds: [paragraph.paraId]
|
|
1289
|
+
}];
|
|
1290
|
+
};
|
|
1291
|
+
/**
|
|
1292
|
+
* The comment threads `before` holds that `after` no longer does: a tracked
|
|
1293
|
+
* operation that takes back its own insertion retires the comments it leaves
|
|
1294
|
+
* nothing of outright, as a direct deletion does.
|
|
1295
|
+
*/
|
|
1296
|
+
const commentsRetiredBetween = (before, after) => {
|
|
1297
|
+
const kept = new Set((after.package.document.comments ?? []).map(({ id }) => id));
|
|
1298
|
+
return (before.package.document.comments ?? []).flatMap(({ id, parentId }) => parentId === void 0 && !kept.has(id) ? [id] : []);
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* A merge's intents as the batch stands in `document` when the merge runs.
|
|
1302
|
+
* The separator goes in at the first paragraph's end as it now stands: an
|
|
1303
|
+
* edit of that paragraph the batch ran first, a comment's reference among
|
|
1304
|
+
* them, may have changed its length. Direct, the join also binds to the
|
|
1305
|
+
* paragraph that now follows: a paragraph the batch deleted first is no
|
|
1306
|
+
* longer there, so the merge joins across it, as merging after that deletion
|
|
1307
|
+
* does; `undefined` when no paragraph follows any more. Tracked, a deleted
|
|
1308
|
+
* paragraph stays, and the join keeps it, unless an earlier operation joined
|
|
1309
|
+
* that paragraph away.
|
|
1310
|
+
*/
|
|
1311
|
+
const mergeIntentsAsItRuns = ({ document, story, intents, mode }) => {
|
|
1312
|
+
const join = intents.find((intent) => intent.type === "joinParagraphs");
|
|
1313
|
+
if (join === void 0 || findStoryBody(document, story) === void 0) return intents;
|
|
1314
|
+
const locations = paragraphsThroughTextBoxes(document, story);
|
|
1315
|
+
const key = idKey(join.blockId);
|
|
1316
|
+
const at = locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === key);
|
|
1317
|
+
const here = locations[at];
|
|
1318
|
+
const was = idKey(join.nextBlockId);
|
|
1319
|
+
const bindsToNext = mode === "direct" || !locations.some(({ paragraph }) => idKey(paragraph.paraId ?? "") === was);
|
|
1320
|
+
if (here === void 0) return bindsToNext ? void 0 : intents;
|
|
1321
|
+
const end = paragraphLength(here.paragraph);
|
|
1322
|
+
const separatorAtEnd = [];
|
|
1323
|
+
for (const intent of intents) separatorAtEnd.push(intent.type === "replaceText" && idKey(intent.from.blockId) === key && intent.from.offset === intent.to.offset ? {
|
|
1324
|
+
...intent,
|
|
1325
|
+
from: {
|
|
1326
|
+
...intent.from,
|
|
1327
|
+
offset: end
|
|
1328
|
+
},
|
|
1329
|
+
to: {
|
|
1330
|
+
...intent.to,
|
|
1331
|
+
offset: end
|
|
1332
|
+
}
|
|
1333
|
+
} : intent);
|
|
1334
|
+
if (!bindsToNext) return separatorAtEnd;
|
|
1335
|
+
const next = locations[at + 1];
|
|
1336
|
+
const between = locateParagraphThroughTextBoxes(document, story, join.blockId)?.blocks.slice(here.index + 1, next?.index ?? here.index + 1);
|
|
1337
|
+
const nextId = next !== void 0 && JSON.stringify(here.list) === JSON.stringify(next.list) && (here.index + 1 === next.index || here.paragraph.sectionProperties === void 0 && between !== void 0 && between.length === next.index - here.index - 1 && between.every(isBlockBoundary)) ? next.paragraph.paraId : void 0;
|
|
1338
|
+
if (nextId === void 0) return void 0;
|
|
1339
|
+
const boundToNext = (intent) => {
|
|
1340
|
+
switch (intent.type) {
|
|
1341
|
+
case "joinParagraphs": return idKey(intent.nextBlockId) === was ? {
|
|
1342
|
+
...intent,
|
|
1343
|
+
nextBlockId: nextId
|
|
1344
|
+
} : intent;
|
|
1345
|
+
case "formatParagraph": return idKey(intent.at.blockId) === was ? {
|
|
1346
|
+
...intent,
|
|
1347
|
+
at: {
|
|
1348
|
+
...intent.at,
|
|
1349
|
+
blockId: nextId
|
|
1350
|
+
}
|
|
1351
|
+
} : intent;
|
|
1352
|
+
case "setList": return {
|
|
1353
|
+
...intent,
|
|
1354
|
+
items: intent.items.map((item) => idKey(item.at.blockId) === was ? {
|
|
1355
|
+
...item,
|
|
1356
|
+
at: {
|
|
1357
|
+
...item.at,
|
|
1358
|
+
blockId: nextId
|
|
1359
|
+
}
|
|
1360
|
+
} : item)
|
|
1361
|
+
};
|
|
1362
|
+
default: return intent;
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
return separatorAtEnd.map(boundToNext);
|
|
1366
|
+
};
|
|
1367
|
+
/**
|
|
1368
|
+
* A block insertion's intents with the properties it copies read from
|
|
1369
|
+
* `document`, the batch as it stands when the insertion runs: an edit of
|
|
1370
|
+
* the copied paragraph the batch order runs first is in the copy, as the
|
|
1371
|
+
* legacy engine copies it, and a paragraph the batch joined away is copied
|
|
1372
|
+
* as the paragraph that now holds it.
|
|
1373
|
+
*/
|
|
1374
|
+
const insertionIntentsAsItRuns = ({ document, story, survivorOf, resolvedOperation }) => {
|
|
1375
|
+
const { intents, inheritsFrom } = resolvedOperation;
|
|
1376
|
+
if (inheritsFrom === void 0) return intents;
|
|
1377
|
+
const locate = (blockId) => locateParagraphThroughTextBoxes(document, story, blockId);
|
|
1378
|
+
const survivor = survivorOf.get(idKey(inheritsFrom.blockId));
|
|
1379
|
+
const at = locate(inheritsFrom.blockId) ?? (survivor === void 0 ? void 0 : locate(survivor));
|
|
1380
|
+
if (at === void 0) return intents;
|
|
1381
|
+
let source = at.paragraph;
|
|
1382
|
+
if (!inheritsFrom.markDeleted && !inheritsFrom.followsAnchor) {
|
|
1383
|
+
let index = at.index;
|
|
1384
|
+
while (isDeletedPPrMark(source.pPrMark)) {
|
|
1385
|
+
const next = at.blocks[++index];
|
|
1386
|
+
if (next?.type !== "paragraph") break;
|
|
1387
|
+
source = next;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const lent = lentFormatting({
|
|
1391
|
+
formatting: paragraphFormattingWithAuthoredIndentation(source),
|
|
1392
|
+
source,
|
|
1393
|
+
namesSource: inheritsFrom.namesSource && source === at.paragraph
|
|
1394
|
+
});
|
|
1395
|
+
const copied = [];
|
|
1396
|
+
for (const intent of intents) copied.push(intent.type === "insertParagraphs" ? Object.assign({}, intent, { paragraphs: inheritsFrom.paragraphs(lent) }) : intent);
|
|
1397
|
+
return copied;
|
|
1398
|
+
};
|
|
1399
|
+
/**
|
|
1400
|
+
* An insertion after a paragraph, as one before the paragraph that follows
|
|
1401
|
+
* it and stays: a follower the batch removes is gone by the time the
|
|
1402
|
+
* insertion replays. With no paragraph staying after it, the anchor is kept.
|
|
1403
|
+
*/
|
|
1404
|
+
const gapAnchorBeforeFollower = ({ anchor, projection, removedBlockIds }) => {
|
|
1405
|
+
if (anchor.type !== "paragraph" || anchor.at.type !== "after") return anchor;
|
|
1406
|
+
const paragraph = projection.paragraph(anchor.at.blockId);
|
|
1407
|
+
if (paragraph === void 0) return panic("An insertion anchor is missing from the projection.");
|
|
1408
|
+
let position = paragraph.start - 1 + paragraph.node.nodeSize;
|
|
1409
|
+
for (;;) {
|
|
1410
|
+
const next = projection.doc.resolve(position).nodeAfter;
|
|
1411
|
+
if (next?.type.name !== "paragraph") return anchor;
|
|
1412
|
+
const follower = projection.paragraphStartingAt(position);
|
|
1413
|
+
if (follower === void 0) return panic("A following paragraph is missing from the projection.");
|
|
1414
|
+
if (!removedBlockIds.has(follower.blockId)) return {
|
|
1415
|
+
type: "paragraph",
|
|
1416
|
+
at: {
|
|
1417
|
+
type: "before",
|
|
1418
|
+
blockId: follower.blockId
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
position += next.nodeSize;
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
/** The physical anchor and accepted source gap, before this batch inserts. */
|
|
1425
|
+
const canonicalInsertionGap = ({ operation, intents, projection }) => {
|
|
1426
|
+
const intent = intents.at(0);
|
|
1427
|
+
let anchor;
|
|
1428
|
+
if (intent?.type === "insertParagraphs") switch (intent.at.type) {
|
|
1429
|
+
case "before":
|
|
1430
|
+
case "after":
|
|
1431
|
+
anchor = {
|
|
1432
|
+
type: "paragraph",
|
|
1433
|
+
at: intent.at
|
|
1434
|
+
};
|
|
1435
|
+
break;
|
|
1436
|
+
case "beforeTable":
|
|
1437
|
+
case "afterTable":
|
|
1438
|
+
anchor = {
|
|
1439
|
+
type: "table",
|
|
1440
|
+
at: {
|
|
1441
|
+
type: intent.at.type === "beforeTable" ? "before" : "after",
|
|
1442
|
+
blockId: intent.at.blockId
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
break;
|
|
1446
|
+
case "containerStart":
|
|
1447
|
+
anchor = {
|
|
1448
|
+
type: "containerStart",
|
|
1449
|
+
at: {
|
|
1450
|
+
type: "after",
|
|
1451
|
+
blockId: intent.at.blockId
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
break;
|
|
1455
|
+
default: return intent.at;
|
|
1456
|
+
}
|
|
1457
|
+
else if (intent?.type === "tableBlock" && intent.operation.type === DOCUMENT_OP_TYPES.INSERT_TABLE) {
|
|
1458
|
+
const { anchor: type, side, blockId } = intent.operation;
|
|
1459
|
+
if (type === "containerStart") anchor = {
|
|
1460
|
+
type,
|
|
1461
|
+
at: {
|
|
1462
|
+
type: "after",
|
|
1463
|
+
blockId
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
else if (type === void 0 || side === void 0) return panic("A resolved table insertion needs an explicit anchor and side.");
|
|
1467
|
+
else anchor = {
|
|
1468
|
+
type,
|
|
1469
|
+
at: {
|
|
1470
|
+
type: side,
|
|
1471
|
+
blockId
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
} else return void 0;
|
|
1475
|
+
const paragraph = projection.paragraph(anchor.at.blockId);
|
|
1476
|
+
if (paragraph === void 0) panic("A resolved insertion lost its source anchor.");
|
|
1477
|
+
const outer = anchor.type === "table" ? findOutermostTableBoundary(projection.doc, paragraph.start - 1) : null;
|
|
1478
|
+
if (anchor.type === "table" && outer === null) panic("A resolved table insertion lost its source table.");
|
|
1479
|
+
let boundary;
|
|
1480
|
+
if (anchor.type === "containerStart") boundary = projection.doc.resolve(paragraph.start - 1).start();
|
|
1481
|
+
else boundary = outer === null ? paragraph.start - 1 + (anchor.at.type === "after" ? paragraph.node.nodeSize : 0) : outer[anchor.at.type];
|
|
1482
|
+
if (!placesBlock(operation)) return void 0;
|
|
1483
|
+
const source = projection.paragraph(operation.blockId);
|
|
1484
|
+
if (source === void 0) panic("A resolved insertion lost its requested source block.");
|
|
1485
|
+
const sourceTable = findOutermostTableBoundary(projection.doc, source.start - 1);
|
|
1486
|
+
const blockSide = operation.type === "insertBeforeBlock" ? "before" : "after";
|
|
1487
|
+
const requestedSide = isBlockInsertion(operation) ? blockSide : operation.position ?? "after";
|
|
1488
|
+
return {
|
|
1489
|
+
anchor,
|
|
1490
|
+
boundary,
|
|
1491
|
+
gap: sourceTable === null ? insertionGap(projection.doc, boundary, anchor.at.type) : insertionGap(projection.doc, sourceTable[requestedSide], requestedSide)
|
|
1492
|
+
};
|
|
1493
|
+
};
|
|
1494
|
+
/** Placement changes; authored formatting, lists and operation ownership stay put. */
|
|
1495
|
+
const placeInsertionIntents = ({ intents, anchor, placement }) => intents.map((intent) => {
|
|
1496
|
+
if (intent.type === "insertParagraphs") switch (anchor.type) {
|
|
1497
|
+
case "paragraph": return {
|
|
1498
|
+
...intent,
|
|
1499
|
+
at: anchor.at
|
|
1500
|
+
};
|
|
1501
|
+
case "table": return {
|
|
1502
|
+
...intent,
|
|
1503
|
+
at: {
|
|
1504
|
+
type: anchor.at.type === "before" ? "beforeTable" : "afterTable",
|
|
1505
|
+
blockId: anchor.at.blockId
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
case "containerStart": return {
|
|
1509
|
+
...intent,
|
|
1510
|
+
at: {
|
|
1511
|
+
type: "containerStart",
|
|
1512
|
+
blockId: anchor.at.blockId
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
default: return anchor;
|
|
1516
|
+
}
|
|
1517
|
+
if (intent.type !== "tableBlock" || intent.operation.type !== DOCUMENT_OP_TYPES.INSERT_TABLE) return intent;
|
|
1518
|
+
const { operation } = intent;
|
|
1519
|
+
if (anchor.type === "containerStart") return {
|
|
1520
|
+
type: "tableBlock",
|
|
1521
|
+
operation: {
|
|
1522
|
+
type: operation.type,
|
|
1523
|
+
story: operation.story,
|
|
1524
|
+
table: operation.table,
|
|
1525
|
+
blockId: anchor.at.blockId,
|
|
1526
|
+
anchor: "containerStart"
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
if (anchor.type === "table") return {
|
|
1530
|
+
type: "tableBlock",
|
|
1531
|
+
operation: {
|
|
1532
|
+
type: operation.type,
|
|
1533
|
+
story: operation.story,
|
|
1534
|
+
table: operation.table,
|
|
1535
|
+
blockId: anchor.at.blockId,
|
|
1536
|
+
anchor: "table",
|
|
1537
|
+
side: anchor.at.type
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
return {
|
|
1541
|
+
type: "tableBlock",
|
|
1542
|
+
operation: {
|
|
1543
|
+
type: operation.type,
|
|
1544
|
+
story: operation.story,
|
|
1545
|
+
table: operation.table,
|
|
1546
|
+
blockId: anchor.at.blockId,
|
|
1547
|
+
anchor: "paragraph",
|
|
1548
|
+
side: anchor.at.type,
|
|
1549
|
+
...operation.anchor === "paragraph" && operation.separated !== void 0 ? { separated: operation.separated } : {},
|
|
1550
|
+
paragraphAfter: placement === "first" && operation.anchor === "paragraph" ? operation.paragraphAfter ?? "empty" : "none"
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
});
|
|
1554
|
+
/** The table compiler emits its leading/trailing carriers before its table. */
|
|
1555
|
+
const droppedInsertionCarrier = ({ admitted, replayed, ops }) => {
|
|
1556
|
+
const before = admitted.at(0), after = replayed.at(0);
|
|
1557
|
+
if (before?.type !== "tableBlock" || before.operation.type !== DOCUMENT_OP_TYPES.INSERT_TABLE || before.operation.anchor !== "paragraph" || before.operation.paragraphAfter === "none" || after?.type !== "tableBlock" || after.operation.type !== DOCUMENT_OP_TYPES.INSERT_TABLE || after.operation.anchor !== "paragraph" || after.operation.paragraphAfter !== "none") return void 0;
|
|
1558
|
+
const carrier = ops.find((op) => op.type === DOCUMENT_OP_TYPES.INSERT_BLOCKS)?.blocks.at(-1);
|
|
1559
|
+
if (carrier?.type !== "paragraph" || carrier.paraId === void 0) panic("A compiled table lost its trailing carrier allocation.");
|
|
1560
|
+
return carrier.paraId;
|
|
1561
|
+
};
|
|
1562
|
+
const isPlainInsertion = ({ type, operation, intents }) => {
|
|
1563
|
+
const intent = intents.at(0);
|
|
1564
|
+
return type === "plain" && (operation.type === "insertBeforeBlock" || operation.type === "insertAfterBlock") && operation.moveId === void 0 && intents.length === 1 && intent?.type === "insertParagraphs" && intent.story === OP_STORIES.MAIN && (intent.at.type === "before" || intent.at.type === "after") && intent.move === void 0 && intent.newList === void 0 && intent.paragraphs.length === 1 && intent.paragraphs.every((paragraph) => paragraph.sectionProperties === void 0 && paragraph.content.every((node) => node.type === "run" && node.content.every(({ type: leaf }) => leaf === "text")));
|
|
1565
|
+
};
|
|
1566
|
+
/** A replay cannot spend identities admitted to another operation. */
|
|
1567
|
+
const insertionMemberIdLease = ({ lease, siblings }) => {
|
|
1568
|
+
const blocks = [];
|
|
1569
|
+
for (const block of lease.blocks) {
|
|
1570
|
+
const excluded = siblings.flatMap((ids) => ids.filter(({ kind, id }) => kind === block.kind && id >= block.start && id < block.end).map(({ id }) => id)).toSorted((left, right) => left - right);
|
|
1571
|
+
let start = block.start;
|
|
1572
|
+
for (const id of excluded) {
|
|
1573
|
+
if (start < id) blocks.push({
|
|
1574
|
+
kind: block.kind,
|
|
1575
|
+
start,
|
|
1576
|
+
end: id
|
|
1577
|
+
});
|
|
1578
|
+
start = id + 1;
|
|
1579
|
+
}
|
|
1580
|
+
if (start < block.end) blocks.push({
|
|
1581
|
+
kind: block.kind,
|
|
1582
|
+
start,
|
|
1583
|
+
end: block.end
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
return { blocks };
|
|
1587
|
+
};
|
|
1588
|
+
const LINE_BREAK_PATTERN = /\r\n|\r|\n/u;
|
|
1589
|
+
/**
|
|
1590
|
+
* A table beside the anchor, built as the legacy engine builds it (from the
|
|
1591
|
+
* cell texts, `buildTableNode`, or the parties, `buildSignatureTableNode`)
|
|
1592
|
+
* and placed where it places it. Beside a paragraph it goes as a paragraph
|
|
1593
|
+
* beside the anchor does (`besidePendingJoin`), or beside the paragraph as
|
|
1594
|
+
* it stands where no pending join reads that side: between the paragraph and
|
|
1595
|
+
* the block next to it, and after a container's last paragraph with the
|
|
1596
|
+
* empty paragraph the container ends with. From inside a table it goes
|
|
1597
|
+
* beside the outermost one, touching it.
|
|
1598
|
+
*/
|
|
1599
|
+
const resolveTableInsertion = ({ operation, listStart, paragraph, projection, story, noteReferences, refusal, skipAlike, template }) => {
|
|
1600
|
+
const side = operation.position ?? "after";
|
|
1601
|
+
const { schema } = projection.doc.type;
|
|
1602
|
+
let node;
|
|
1603
|
+
if (operation.type === "insertTable") node = (template === void 0 ? null : tableFromTemplate({
|
|
1604
|
+
schema,
|
|
1605
|
+
template
|
|
1606
|
+
})) ?? buildTableNode({
|
|
1607
|
+
schema,
|
|
1608
|
+
rows: operation.rows
|
|
1609
|
+
});
|
|
1610
|
+
else {
|
|
1611
|
+
if (operation.parties.length === 0) return skipAlike("emptyOperation", "A signature table needs a party.");
|
|
1612
|
+
if (operation.comment !== void 0) return skipAlike("unsupportedBlock", "A signature table takes no comment.");
|
|
1613
|
+
node = buildSignatureTableNode({
|
|
1614
|
+
schema,
|
|
1615
|
+
parties: operation.parties
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
if (node === null) return refusal("unsupportedBlock");
|
|
1619
|
+
const attrs = expectTableAttrs(node);
|
|
1620
|
+
const formatting = tableAttrsToFormatting(attrs);
|
|
1621
|
+
const table = {
|
|
1622
|
+
type: "table",
|
|
1623
|
+
...formatting === void 0 ? {} : { formatting },
|
|
1624
|
+
...attrs.columnWidths === void 0 ? {} : { columnWidths: [...attrs.columnWidths] },
|
|
1625
|
+
rows: standaloneTableRowsFromProseMirror(node)
|
|
1626
|
+
};
|
|
1627
|
+
const inserted = ({ place, side: placeSide, paragraphAfter }) => {
|
|
1628
|
+
const position = placeSide === "after" ? place.start + place.node.content.size : place.start;
|
|
1629
|
+
const intent = {
|
|
1630
|
+
type: "tableBlock",
|
|
1631
|
+
operation: {
|
|
1632
|
+
type: DOCUMENT_OP_TYPES.INSERT_TABLE,
|
|
1633
|
+
story,
|
|
1634
|
+
blockId: place.blockId,
|
|
1635
|
+
table,
|
|
1636
|
+
anchor: "paragraph",
|
|
1637
|
+
side: placeSide,
|
|
1638
|
+
paragraphAfter
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
return Result.ok({
|
|
1642
|
+
type: "plain",
|
|
1643
|
+
operation,
|
|
1644
|
+
intents: [intent],
|
|
1645
|
+
normalizations: [],
|
|
1646
|
+
from: position,
|
|
1647
|
+
to: position
|
|
1648
|
+
});
|
|
1649
|
+
};
|
|
1650
|
+
const besideTable = (blockId, position) => Result.ok({
|
|
1651
|
+
type: "plain",
|
|
1652
|
+
operation,
|
|
1653
|
+
intents: [{
|
|
1654
|
+
type: "tableBlock",
|
|
1655
|
+
operation: {
|
|
1656
|
+
type: DOCUMENT_OP_TYPES.INSERT_TABLE,
|
|
1657
|
+
story,
|
|
1658
|
+
blockId,
|
|
1659
|
+
table,
|
|
1660
|
+
anchor: "table",
|
|
1661
|
+
side
|
|
1662
|
+
}
|
|
1663
|
+
}],
|
|
1664
|
+
normalizations: [],
|
|
1665
|
+
from: position,
|
|
1666
|
+
to: position
|
|
1667
|
+
});
|
|
1668
|
+
if (listStart !== void 0) return Result.ok({
|
|
1669
|
+
type: "plain",
|
|
1670
|
+
operation,
|
|
1671
|
+
intents: [{
|
|
1672
|
+
type: "tableBlock",
|
|
1673
|
+
operation: {
|
|
1674
|
+
type: DOCUMENT_OP_TYPES.INSERT_TABLE,
|
|
1675
|
+
story,
|
|
1676
|
+
blockId: listStart.blockId,
|
|
1677
|
+
table,
|
|
1678
|
+
anchor: "containerStart"
|
|
1679
|
+
}
|
|
1680
|
+
}],
|
|
1681
|
+
normalizations: [],
|
|
1682
|
+
from: listStart.position,
|
|
1683
|
+
to: listStart.position
|
|
1684
|
+
});
|
|
1685
|
+
const stopsPendingJoin = (paragraphPos) => joinStopsAtTableAfter({
|
|
1686
|
+
insertedBlock: "table",
|
|
1687
|
+
joinBeforeTable: "runsIntoFirstCell",
|
|
1688
|
+
doc: projection.doc,
|
|
1689
|
+
paragraphPos,
|
|
1690
|
+
noteReferences
|
|
1691
|
+
});
|
|
1692
|
+
const pendingJoinRefusal = () => refusal(PENDING_JOIN_INSERTION_REFUSAL.reason, PENDING_JOIN_INSERTION_REFUSAL.message);
|
|
1693
|
+
const followsDeletedBreak = (previous) => previous?.type.name === "paragraph" && isDeletedPPrMark(previous.attrs["pPrMark"]) && !paragraphGoes(previous, "accept");
|
|
1694
|
+
const pendingBreakRefusal = () => refusal(PENDING_BREAK_TABLE_REFUSAL.reason, PENDING_BREAK_TABLE_REFUSAL.message);
|
|
1695
|
+
const outer = findOutermostTableBoundary(projection.doc, paragraph.start - 1);
|
|
1696
|
+
if (outer !== null) {
|
|
1697
|
+
if (stopsPendingJoin(outer[side])) return pendingJoinRefusal();
|
|
1698
|
+
const outerTable = projection.doc.nodeAt(outer.before);
|
|
1699
|
+
const blockId = outerTable === null ? void 0 : tableBlockAddress(projection, {
|
|
1700
|
+
table: outerTable,
|
|
1701
|
+
tableStart: outer.before + 1
|
|
1702
|
+
});
|
|
1703
|
+
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
1704
|
+
return besideTable(blockId, outer[side]);
|
|
1705
|
+
}
|
|
1706
|
+
const { place } = besidePendingJoin({
|
|
1707
|
+
side,
|
|
1708
|
+
paragraph,
|
|
1709
|
+
projection,
|
|
1710
|
+
noteReferences
|
|
1711
|
+
});
|
|
1712
|
+
const $place = projection.doc.resolve(place.start - 1);
|
|
1713
|
+
const neighbour = $place.parent.maybeChild($place.index() + (side === "after" ? 1 : -1));
|
|
1714
|
+
const gap = side === "after" ? place.start - 1 + place.node.nodeSize : place.start - 1;
|
|
1715
|
+
if (stopsPendingJoin(gap)) return pendingJoinRefusal();
|
|
1716
|
+
if (side === "after" && followsDeletedBreak(place.node)) return pendingBreakRefusal();
|
|
1717
|
+
if (side === "before") {
|
|
1718
|
+
const start = insertionGap(projection.doc, gap, side);
|
|
1719
|
+
const pending = start < gap ? projection.doc.nodeAt(start) : null;
|
|
1720
|
+
if (pending?.type.name === "table") {
|
|
1721
|
+
const address = tableBlockAddress(projection, {
|
|
1722
|
+
table: pending,
|
|
1723
|
+
tableStart: start + 1
|
|
1724
|
+
});
|
|
1725
|
+
if (address !== void 0) {
|
|
1726
|
+
if (stopsPendingJoin(start)) return pendingJoinRefusal();
|
|
1727
|
+
if (followsDeletedBreak(projection.doc.resolve(start).nodeBefore)) return pendingBreakRefusal();
|
|
1728
|
+
return besideTable(address, start);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
return inserted({
|
|
1733
|
+
place,
|
|
1734
|
+
side,
|
|
1735
|
+
paragraphAfter: side === "after" && neighbour === null ? "empty" : "none"
|
|
1736
|
+
});
|
|
1737
|
+
};
|
|
1738
|
+
/**
|
|
1739
|
+
* The first paragraph standing directly in the cells of `scope` that the
|
|
1740
|
+
* batch keeps: a table, row or cell edit addressed by a paragraph the batch
|
|
1741
|
+
* deletes would find no paragraph once that deletion has run.
|
|
1742
|
+
*/
|
|
1743
|
+
const keptTableAddress = ({ projection, scope, scopePosition, deleted, skipsCell = () => false }) => {
|
|
1744
|
+
const cells = [];
|
|
1745
|
+
const collectCells = (row, rowPosition) => row.forEach((cell, offset) => cells.push({
|
|
1746
|
+
cell,
|
|
1747
|
+
position: rowPosition + 1 + offset
|
|
1748
|
+
}));
|
|
1749
|
+
switch (scope.type.spec["tableRole"]) {
|
|
1750
|
+
case "cell":
|
|
1751
|
+
cells.push({
|
|
1752
|
+
cell: scope,
|
|
1753
|
+
position: scopePosition
|
|
1754
|
+
});
|
|
1755
|
+
break;
|
|
1756
|
+
case "row":
|
|
1757
|
+
collectCells(scope, scopePosition);
|
|
1758
|
+
break;
|
|
1759
|
+
default: scope.forEach((row, offset) => {
|
|
1760
|
+
if (row.type.spec["tableRole"] === "row") collectCells(row, scopePosition + 1 + offset);
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
const starts = [];
|
|
1764
|
+
for (const { cell, position } of cells) {
|
|
1765
|
+
if (skipsCell(position)) continue;
|
|
1766
|
+
cell.forEach((child, childOffset) => {
|
|
1767
|
+
if (child.type.name === "paragraph") starts.push(position + 1 + childOffset + 1);
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
for (const start of starts) {
|
|
1771
|
+
const addressed = projection.addressAt(start);
|
|
1772
|
+
if (addressed.isOk() && !deleted.has(addressed.value.blockId)) return addressed.value.blockId;
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
/**
|
|
1776
|
+
* A table edit's intents, addressed by a paragraph that stands when it runs:
|
|
1777
|
+
* an earlier operation of the batch may have removed the one it was addressed
|
|
1778
|
+
* by, with the column or cell holding it. Any other paragraph of the table as
|
|
1779
|
+
* the batch read it names the same table; one a column deletion removes
|
|
1780
|
+
* itself only where no other stands.
|
|
1781
|
+
*/
|
|
1782
|
+
const tableIntentsAsItRuns = ({ document, story, projection, plan: { address }, intents }) => {
|
|
1783
|
+
if (address.type !== "column" && address.type !== "cell") return intents;
|
|
1784
|
+
const stands = (blockId) => locateParagraphThroughTextBoxes(document, story, blockId) !== void 0;
|
|
1785
|
+
return intents.map((intent) => {
|
|
1786
|
+
if (intent.type !== "table" || stands(intent.operation.blockId)) return intent;
|
|
1787
|
+
const table = projection.doc.nodeAt(address.tablePosition);
|
|
1788
|
+
if (table === null) return intent;
|
|
1789
|
+
const map = TableMap.get(table);
|
|
1790
|
+
const standing = (skipsCell) => keptTableAddress({
|
|
1791
|
+
projection,
|
|
1792
|
+
scope: table,
|
|
1793
|
+
scopePosition: address.tablePosition,
|
|
1794
|
+
deleted: { has: (blockId) => !stands(blockId) },
|
|
1795
|
+
...skipsCell === void 0 ? {} : { skipsCell }
|
|
1796
|
+
});
|
|
1797
|
+
const { operation } = intent;
|
|
1798
|
+
const blockId = operation.type === DOCUMENT_OP_TYPES.DELETE_COLUMN && address.type === "column" ? standing((cellPosition) => {
|
|
1799
|
+
const rect = map.findCell(cellPosition - address.tablePosition - 1);
|
|
1800
|
+
return rect.left <= address.columnIndex && address.columnIndex < rect.right;
|
|
1801
|
+
}) ?? standing() : standing();
|
|
1802
|
+
return blockId === void 0 ? intent : {
|
|
1803
|
+
...intent,
|
|
1804
|
+
operation: {
|
|
1805
|
+
...operation,
|
|
1806
|
+
blockId
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
});
|
|
1810
|
+
};
|
|
1811
|
+
const tableBlockAddress = (projection, row, deleted = /* @__PURE__ */ new Set()) => {
|
|
1812
|
+
const at = tableAnchor({
|
|
1813
|
+
map: TableMap.get(row.table),
|
|
1814
|
+
table: row.table,
|
|
1815
|
+
tableStart: row.tableStart,
|
|
1816
|
+
left: 0,
|
|
1817
|
+
right: 0,
|
|
1818
|
+
top: 0,
|
|
1819
|
+
bottom: 0
|
|
1820
|
+
});
|
|
1821
|
+
const addressed = at === void 0 ? void 0 : projection.addressAt(at);
|
|
1822
|
+
if (addressed === void 0 || addressed.isErr()) return void 0;
|
|
1823
|
+
return deleted.has(addressed.value.blockId) ? keptTableAddress({
|
|
1824
|
+
projection,
|
|
1825
|
+
scope: row.table,
|
|
1826
|
+
scopePosition: row.tableStart - 1,
|
|
1827
|
+
deleted
|
|
1828
|
+
}) ?? addressed.value.blockId : addressed.value.blockId;
|
|
1829
|
+
};
|
|
1830
|
+
/**
|
|
1831
|
+
* A new cell's paragraphs from its text: a line break starts a new
|
|
1832
|
+
* paragraph, as in a new row's cells.
|
|
1833
|
+
*/
|
|
1834
|
+
const cellParagraphs = (text) => splitCellParagraphTexts(text).map((line) => ({
|
|
1835
|
+
type: "paragraph",
|
|
1836
|
+
content: line === "" ? [] : [{
|
|
1837
|
+
type: "run",
|
|
1838
|
+
content: inlineText(line)
|
|
1839
|
+
}]
|
|
1840
|
+
}));
|
|
1841
|
+
/** The table offsets of the cells the rectangle covers, a merged one once per slot. */
|
|
1842
|
+
const cellsIn = (map, rectangle) => {
|
|
1843
|
+
const cells = [];
|
|
1844
|
+
for (let row = rectangle.top; row < rectangle.bottom; row += 1) for (let column = rectangle.left; column < rectangle.right; column += 1) {
|
|
1845
|
+
const offset = map.map[row * map.width + column];
|
|
1846
|
+
if (offset !== void 0) cells.push(offset);
|
|
1847
|
+
}
|
|
1848
|
+
return cells;
|
|
1849
|
+
};
|
|
1850
|
+
/** Whether a cell the rectangle covers is a slot its row omits. */
|
|
1851
|
+
const holdsOmittedSlot = (table, map, rectangle) => {
|
|
1852
|
+
for (let row = rectangle.top; row < rectangle.bottom; row += 1) for (let column = rectangle.left; column < rectangle.right; column += 1) {
|
|
1853
|
+
const offset = map.map[row * map.width + column];
|
|
1854
|
+
const cell = offset === void 0 ? null : table.nodeAt(offset);
|
|
1855
|
+
if (cell === null || cell.attrs["_omittedGridSlot"] != null) return true;
|
|
1856
|
+
}
|
|
1857
|
+
return false;
|
|
1858
|
+
};
|
|
1859
|
+
/**
|
|
1860
|
+
* Whether a column inserted at the grid index runs through a cell spanning
|
|
1861
|
+
* both its sides, so that the cell would widen; a slot a row omits grows
|
|
1862
|
+
* instead, as the legacy engine grows it.
|
|
1863
|
+
*/
|
|
1864
|
+
const columnInsertionWidensCell = (table, columnIndex) => {
|
|
1865
|
+
const map = TableMap.get(table);
|
|
1866
|
+
if (columnIndex <= 0 || columnIndex >= map.width) return false;
|
|
1867
|
+
for (let row = 0; row < map.height; row += 1) {
|
|
1868
|
+
const index = row * map.width + columnIndex;
|
|
1869
|
+
if (omittedSlotTakingColumn(map, table, row, columnIndex) === null && map.map[index - 1] === map.map[index]) return true;
|
|
1870
|
+
}
|
|
1871
|
+
return false;
|
|
1872
|
+
};
|
|
1873
|
+
/**
|
|
1874
|
+
* Whether the rectangle is one column of one-cell rows, every cell below
|
|
1875
|
+
* the first holding nothing but empty paragraphs: the merge a suggestion
|
|
1876
|
+
* records, as merge state alone.
|
|
1877
|
+
*/
|
|
1878
|
+
const mergesDownOverEmptyCells = (table, map, rectangle) => {
|
|
1879
|
+
if (rectangle.right - rectangle.left !== 1) return false;
|
|
1880
|
+
for (let row = rectangle.top; row < rectangle.bottom; row += 1) {
|
|
1881
|
+
const offset = map.map[row * map.width + rectangle.left];
|
|
1882
|
+
const cell = offset === void 0 ? null : table.nodeAt(offset);
|
|
1883
|
+
if (offset === void 0 || cell === null) return false;
|
|
1884
|
+
const rect = map.findCell(offset);
|
|
1885
|
+
if (rect.top !== row || rect.bottom !== row + 1) return false;
|
|
1886
|
+
if (row === rectangle.top) continue;
|
|
1887
|
+
let empty = true;
|
|
1888
|
+
cell.forEach((child) => {
|
|
1889
|
+
if (!child.isTextblock || child.content.size > 0) empty = false;
|
|
1890
|
+
});
|
|
1891
|
+
if (!empty) return false;
|
|
1892
|
+
}
|
|
1893
|
+
return true;
|
|
1894
|
+
};
|
|
1895
|
+
const isTableStructureOperation = (operation) => operation.type === "deleteTable" || operation.type === "insertTableRow" || operation.type === "deleteTableRow" || operation.type === "insertTableColumn" || operation.type === "deleteTableColumn" || operation.type === "mergeTableCells" || operation.type === "splitTableCell";
|
|
1896
|
+
/**
|
|
1897
|
+
* A table, row or column change, addressed through the paragraph the
|
|
1898
|
+
* operation names, as the table edit the editor's own command lowers to. The
|
|
1899
|
+
* table it acts on is the innermost one holding that paragraph, as in the
|
|
1900
|
+
* legacy engine. A new row is the row the legacy engine builds
|
|
1901
|
+
* (`applyTableRowInsertion`, from the row beside it and the cell texts),
|
|
1902
|
+
* read off the table it leaves; the engine records it, tracked or not.
|
|
1903
|
+
*/
|
|
1904
|
+
const resolveTableStructure = ({ operation, paragraph, projection, story, refusal, tracked, paragraphOf, notInTable, skipAlike, skipTracked, deleted, template }) => {
|
|
1905
|
+
const { doc } = projection;
|
|
1906
|
+
const blockFrom = paragraph.start - 1;
|
|
1907
|
+
const row = findEnclosingTableRow(doc, blockFrom);
|
|
1908
|
+
if (row === null) return notInTable();
|
|
1909
|
+
const scopeOf = (scope) => {
|
|
1910
|
+
switch (scope) {
|
|
1911
|
+
case "table": return {
|
|
1912
|
+
scope: row.table,
|
|
1913
|
+
scopePosition: row.tablePosition
|
|
1914
|
+
};
|
|
1915
|
+
case "row": return {
|
|
1916
|
+
scope: row.table.child(row.rowIndex),
|
|
1917
|
+
scopePosition: row.rowPosition
|
|
1918
|
+
};
|
|
1919
|
+
case "cell": {
|
|
1920
|
+
const cell = findEnclosingTableCell(doc, blockFrom);
|
|
1921
|
+
const node = cell === null ? null : doc.nodeAt(cell.cellPosition);
|
|
1922
|
+
return cell === null || node === null ? void 0 : {
|
|
1923
|
+
scope: node,
|
|
1924
|
+
scopePosition: cell.cellPosition
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
default: return scope;
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
/** The operation's own paragraph, unless the batch deletes it first. */
|
|
1931
|
+
const keptAddress = (scope) => {
|
|
1932
|
+
if (!deleted.has(paragraph.blockId)) return paragraph.blockId;
|
|
1933
|
+
const within = scopeOf(scope);
|
|
1934
|
+
return (within && keptTableAddress({
|
|
1935
|
+
projection,
|
|
1936
|
+
...within,
|
|
1937
|
+
deleted
|
|
1938
|
+
})) ?? paragraph.blockId;
|
|
1939
|
+
};
|
|
1940
|
+
const resolved = (intent, from, to) => Result.ok({
|
|
1941
|
+
type: "plain",
|
|
1942
|
+
operation,
|
|
1943
|
+
intents: [intent],
|
|
1944
|
+
normalizations: [],
|
|
1945
|
+
from,
|
|
1946
|
+
to
|
|
1947
|
+
});
|
|
1948
|
+
switch (operation.type) {
|
|
1949
|
+
case "deleteTable": return resolved({
|
|
1950
|
+
type: "tableBlock",
|
|
1951
|
+
operation: {
|
|
1952
|
+
type: DOCUMENT_OP_TYPES.DELETE_TABLE,
|
|
1953
|
+
story,
|
|
1954
|
+
blockId: keptAddress("table")
|
|
1955
|
+
}
|
|
1956
|
+
}, row.tablePosition, row.tablePosition + row.table.nodeSize);
|
|
1957
|
+
case "deleteTableRow": return resolved({
|
|
1958
|
+
type: "tableRow",
|
|
1959
|
+
operation: {
|
|
1960
|
+
type: DOCUMENT_OP_TYPES.DELETE_ROW,
|
|
1961
|
+
story,
|
|
1962
|
+
blockId: keptAddress("row")
|
|
1963
|
+
}
|
|
1964
|
+
}, row.rowPosition, row.rowPosition + row.table.child(row.rowIndex).nodeSize);
|
|
1965
|
+
case "deleteTableColumn": {
|
|
1966
|
+
const cell = findEnclosingTableCell(doc, blockFrom);
|
|
1967
|
+
if (cell === null) return notInTable();
|
|
1968
|
+
const map = TableMap.get(row.table);
|
|
1969
|
+
const table = {
|
|
1970
|
+
from: row.tablePosition,
|
|
1971
|
+
to: row.tablePosition + row.table.nodeSize
|
|
1972
|
+
};
|
|
1973
|
+
if (map.width === 1) return resolved({
|
|
1974
|
+
type: "tableBlock",
|
|
1975
|
+
operation: {
|
|
1976
|
+
type: DOCUMENT_OP_TYPES.DELETE_TABLE,
|
|
1977
|
+
story,
|
|
1978
|
+
blockId: keptAddress("table")
|
|
1979
|
+
}
|
|
1980
|
+
}, table.from, table.to);
|
|
1981
|
+
const column = {
|
|
1982
|
+
left: cell.leftColumnIndex,
|
|
1983
|
+
right: cell.leftColumnIndex + 1
|
|
1984
|
+
};
|
|
1985
|
+
if (tracked && Array.from({ length: map.height }, (_, rowIndex) => {
|
|
1986
|
+
const position = map.map[rowIndex * map.width + column.left];
|
|
1987
|
+
return position === void 0 ? null : row.table.nodeAt(position);
|
|
1988
|
+
}).some((node) => node?.attrs["_omittedGridSlot"] == null && Number(node?.attrs["colspan"] ?? 1) !== 1)) return skipTracked("A suggested column deletion cannot narrow a cell that spans other columns.");
|
|
1989
|
+
const at = tableAnchor({
|
|
1990
|
+
map,
|
|
1991
|
+
table: row.table,
|
|
1992
|
+
tableStart: row.tableStart,
|
|
1993
|
+
...column,
|
|
1994
|
+
top: 0,
|
|
1995
|
+
bottom: 0
|
|
1996
|
+
}, column);
|
|
1997
|
+
const addressed = at === void 0 ? void 0 : projection.addressAt(at);
|
|
1998
|
+
if (addressed === void 0 || addressed.isErr()) return refusal("unsupportedBlock");
|
|
1999
|
+
const address = addressed.value;
|
|
2000
|
+
const blockId = deleted.has(address.blockId) ? keptTableAddress({
|
|
2001
|
+
projection,
|
|
2002
|
+
scope: row.table,
|
|
2003
|
+
scopePosition: row.tablePosition,
|
|
2004
|
+
deleted,
|
|
2005
|
+
skipsCell: (cellPosition) => {
|
|
2006
|
+
const rect = map.findCell(cellPosition - row.tableStart);
|
|
2007
|
+
return rect.left <= column.left && column.left < rect.right;
|
|
2008
|
+
}
|
|
2009
|
+
}) ?? address.blockId : address.blockId;
|
|
2010
|
+
return resolved({
|
|
2011
|
+
type: "table",
|
|
2012
|
+
operation: {
|
|
2013
|
+
type: DOCUMENT_OP_TYPES.DELETE_COLUMN,
|
|
2014
|
+
story,
|
|
2015
|
+
blockId,
|
|
2016
|
+
column: cell.leftColumnIndex
|
|
2017
|
+
}
|
|
2018
|
+
}, table.from, table.to);
|
|
2019
|
+
}
|
|
2020
|
+
case "insertTableColumn": {
|
|
2021
|
+
const insertion = findTableColumnInsertion({
|
|
2022
|
+
doc,
|
|
2023
|
+
blockFrom,
|
|
2024
|
+
position: operation.position ?? "after"
|
|
2025
|
+
});
|
|
2026
|
+
if (insertion === null) return notInTable();
|
|
2027
|
+
const columnCount = operation.columnCount ?? 1;
|
|
2028
|
+
const overflow = describeUnplacedCellTexts({
|
|
2029
|
+
cellTexts: operation.cellTexts,
|
|
2030
|
+
capacity: getInsertedPhysicalColumnRows(TableMap.get(row.table), row.table, insertion.columnIndex).length * columnCount,
|
|
2031
|
+
target: "column"
|
|
2032
|
+
});
|
|
2033
|
+
if (overflow !== null) return refusal("payloadDoesNotFit", overflow);
|
|
2034
|
+
if (tracked && columnInsertionWidensCell(row.table, insertion.columnIndex)) return skipTracked("A suggested column cannot widen a cell that spans other columns.");
|
|
2035
|
+
const blockId = tableBlockAddress(projection, row, deleted);
|
|
2036
|
+
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
2037
|
+
return resolved({
|
|
2038
|
+
type: "table",
|
|
2039
|
+
operation: {
|
|
2040
|
+
type: DOCUMENT_OP_TYPES.INSERT_COLUMN,
|
|
2041
|
+
story,
|
|
2042
|
+
blockId,
|
|
2043
|
+
column: insertion.columnIndex,
|
|
2044
|
+
width: insertedColumnWidth(row.table, insertion.columnIndex) ?? 1,
|
|
2045
|
+
...columnCount === 1 ? {} : { count: columnCount }
|
|
2046
|
+
},
|
|
2047
|
+
...operation.cellTexts === void 0 ? {} : { cellContent: operation.cellTexts.map(cellParagraphs) }
|
|
2048
|
+
}, row.tablePosition, row.tablePosition + row.table.nodeSize);
|
|
2049
|
+
}
|
|
2050
|
+
case "mergeTableCells": {
|
|
2051
|
+
const start = findEnclosingTableCell(doc, blockFrom);
|
|
2052
|
+
if (start === null) return notInTable();
|
|
2053
|
+
const map = TableMap.get(row.table);
|
|
2054
|
+
let rectangle;
|
|
2055
|
+
if (operation.rowCount === void 0) {
|
|
2056
|
+
const end = paragraphOf(operation.endBlockId);
|
|
2057
|
+
if (end === void 0) return refusal("missingBlock");
|
|
2058
|
+
const corner = findEnclosingTableCell(doc, end.start - 1);
|
|
2059
|
+
if (corner === null || corner.tablePosition !== start.tablePosition) return skipAlike("unsupportedBlock", "The merge's corners are not in one table.");
|
|
2060
|
+
rectangle = {
|
|
2061
|
+
left: Math.min(start.leftColumnIndex, corner.leftColumnIndex),
|
|
2062
|
+
top: Math.min(start.topRowIndex, corner.topRowIndex),
|
|
2063
|
+
right: Math.max(start.rightColumnIndex, corner.rightColumnIndex),
|
|
2064
|
+
bottom: Math.max(start.bottomRowIndex, corner.bottomRowIndex)
|
|
2065
|
+
};
|
|
2066
|
+
} else {
|
|
2067
|
+
rectangle = {
|
|
2068
|
+
left: start.leftColumnIndex,
|
|
2069
|
+
top: start.topRowIndex,
|
|
2070
|
+
right: start.rightColumnIndex,
|
|
2071
|
+
bottom: start.topRowIndex + operation.rowCount
|
|
2072
|
+
};
|
|
2073
|
+
if (rectangle.right - rectangle.left !== 1 || rectangle.bottom > map.height || operation.rowCount < 2) return skipAlike("unsupportedBlock", "A merge down takes one column and rows the table has.");
|
|
2074
|
+
}
|
|
2075
|
+
if (rectangle.right - rectangle.left === 1 && rectangle.bottom - rectangle.top === 1) return skipAlike("noopOperation", "A merge of one cell changes nothing.");
|
|
2076
|
+
if (tableRectangleCutsMergedCell(map, rectangle) || holdsOmittedSlot(row.table, map, rectangle)) return skipAlike("unsupportedBlock", "The merge would cut a merged cell or a slot its row omits.");
|
|
2077
|
+
if (new Set(cellsIn(map, rectangle)).size < 2) return skipAlike("unsupportedBlock", "The merge covers a single merged cell.");
|
|
2078
|
+
if (tracked && !mergesDownOverEmptyCells(row.table, map, rectangle)) return skipTracked("A suggested merge takes one column over empty cells.");
|
|
2079
|
+
const blockId = tableBlockAddress(projection, row, deleted);
|
|
2080
|
+
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
2081
|
+
return resolved({
|
|
2082
|
+
type: "table",
|
|
2083
|
+
operation: {
|
|
2084
|
+
type: DOCUMENT_OP_TYPES.MERGE_CELLS,
|
|
2085
|
+
story,
|
|
2086
|
+
blockId,
|
|
2087
|
+
...rectangle
|
|
2088
|
+
}
|
|
2089
|
+
}, row.tablePosition, row.tablePosition + row.table.nodeSize);
|
|
2090
|
+
}
|
|
2091
|
+
case "splitTableCell": {
|
|
2092
|
+
const cell = findEnclosingTableCell(doc, blockFrom);
|
|
2093
|
+
if (cell === null) return notInTable();
|
|
2094
|
+
if (cell.rightColumnIndex - cell.leftColumnIndex === 1 && cell.bottomRowIndex - cell.topRowIndex === 1) return skipAlike("noopOperation", "A one-row, one-column cell has nothing to split.");
|
|
2095
|
+
if (tracked && cell.rightColumnIndex - cell.leftColumnIndex !== 1) return skipTracked("A suggested split takes a cell merged down one column.");
|
|
2096
|
+
return resolved({
|
|
2097
|
+
type: "table",
|
|
2098
|
+
operation: {
|
|
2099
|
+
type: DOCUMENT_OP_TYPES.SPLIT_CELL,
|
|
2100
|
+
story,
|
|
2101
|
+
blockId: keptAddress("cell")
|
|
2102
|
+
}
|
|
2103
|
+
}, row.tablePosition, row.tablePosition + row.table.nodeSize);
|
|
2104
|
+
}
|
|
2105
|
+
case "insertTableRow": {
|
|
2106
|
+
const side = operation.position ?? "after";
|
|
2107
|
+
const insertion = findTableRowInsertion({
|
|
2108
|
+
doc,
|
|
2109
|
+
blockFrom,
|
|
2110
|
+
position: side
|
|
2111
|
+
});
|
|
2112
|
+
if (insertion === null) return notInTable();
|
|
2113
|
+
const overflow = describeUnplacedCellTexts({
|
|
2114
|
+
cellTexts: operation.cellTexts,
|
|
2115
|
+
capacity: insertion.cells.length,
|
|
2116
|
+
target: "row"
|
|
2117
|
+
});
|
|
2118
|
+
if (overflow !== null) return refusal("payloadDoesNotFit", overflow);
|
|
2119
|
+
const built = applyTableRowInsertion({
|
|
2120
|
+
tr: EditorState.create({ doc }).tr,
|
|
2121
|
+
insertion,
|
|
2122
|
+
cellTexts: operation.cellTexts,
|
|
2123
|
+
revision: null,
|
|
2124
|
+
...template === void 0 ? {} : { template }
|
|
2125
|
+
});
|
|
2126
|
+
if (built.type !== "applied") return refusal("unsupportedBlock");
|
|
2127
|
+
const table = built.transaction.doc.nodeAt(built.transaction.mapping.map(row.tablePosition, -1));
|
|
2128
|
+
if (table === null || table.type.name !== "table") return refusal("unsupportedBlock");
|
|
2129
|
+
const index = side === "before" ? row.rowIndex : row.rowIndex + 1;
|
|
2130
|
+
const inserted = standaloneTableRowsFromProseMirror(table)[index];
|
|
2131
|
+
if (inserted === void 0) return refusal("unsupportedBlock");
|
|
2132
|
+
const { structuralChange: _structuralChange, propertyChanges: _propertyChanges, ...plain } = inserted;
|
|
2133
|
+
return resolved({
|
|
2134
|
+
type: "tableRow",
|
|
2135
|
+
operation: {
|
|
2136
|
+
type: DOCUMENT_OP_TYPES.INSERT_ROW,
|
|
2137
|
+
story,
|
|
2138
|
+
blockId: keptAddress("row"),
|
|
2139
|
+
at: index,
|
|
2140
|
+
row: plain
|
|
2141
|
+
}
|
|
2142
|
+
}, insertion.rowPosition, insertion.rowPosition);
|
|
2143
|
+
}
|
|
2144
|
+
default: return operation;
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
/**
|
|
2148
|
+
* The operations a canonical suggestion can carry: the legacy engine's;
|
|
2149
|
+
* splits and merges, which the canonical session records as tracked paragraph
|
|
2150
|
+
* marks stamped with the suggestion; and comments, which it holds as proposed
|
|
2151
|
+
* by the suggestion until it is accepted or rejected.
|
|
2152
|
+
*/
|
|
2153
|
+
const CANONICAL_SUGGESTED_OPERATION_TYPES = /* @__PURE__ */ new Set([
|
|
2154
|
+
...SUGGESTED_SUPPORTED_OPERATION_TYPES,
|
|
2155
|
+
"splitBlock",
|
|
2156
|
+
"mergeBlockWithNext",
|
|
2157
|
+
"commentOnRange",
|
|
2158
|
+
"commentOnBlock"
|
|
2159
|
+
]);
|
|
2160
|
+
/** The operations that only add marks over text: formatting and comments. */
|
|
2161
|
+
const ANNOTATING_OPERATION_TYPES = /* @__PURE__ */ new Set([
|
|
2162
|
+
"formatRange",
|
|
2163
|
+
"commentOnRange",
|
|
2164
|
+
"commentOnBlock"
|
|
2165
|
+
]);
|
|
2166
|
+
/** A block operation without the move it names: a plain insertion or deletion. */
|
|
2167
|
+
const withoutMove = (operation) => {
|
|
2168
|
+
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock") return operation;
|
|
2169
|
+
const { moveId: _moveId, ...plain } = operation;
|
|
2170
|
+
return plain;
|
|
2171
|
+
};
|
|
2172
|
+
/** The move a block operation names, if it is a half of one. */
|
|
2173
|
+
const blockMoveId = (operation) => operation.type === "deleteBlock" || operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock" ? operation.moveId : void 0;
|
|
2174
|
+
/**
|
|
2175
|
+
* A line's text with each tab and line break as the element it is; CRLF, CR
|
|
2176
|
+
* and LF are each one line break.
|
|
2177
|
+
*/
|
|
2178
|
+
/**
|
|
2179
|
+
* A line as runs: paired `**bold**` and `***bold italic***` markers state
|
|
2180
|
+
* that emphasis on their words, as the default engine reads them; the rest
|
|
2181
|
+
* states no run property, so the paragraph's style formats it.
|
|
2182
|
+
*/
|
|
2183
|
+
const emphasisRuns = (line) => parseInlineEmphasisRuns(line).flatMap(({ text, bold, italic }) => {
|
|
2184
|
+
const content = inlineText(text);
|
|
2185
|
+
if (content.length === 0) return [];
|
|
2186
|
+
if (!bold && !italic) return [{
|
|
2187
|
+
type: "run",
|
|
2188
|
+
content
|
|
2189
|
+
}];
|
|
2190
|
+
return [{
|
|
2191
|
+
type: "run",
|
|
2192
|
+
content,
|
|
2193
|
+
formatting: {
|
|
2194
|
+
...bold ? { bold } : {},
|
|
2195
|
+
...italic ? { italic } : {}
|
|
2196
|
+
}
|
|
2197
|
+
}];
|
|
2198
|
+
});
|
|
2199
|
+
const inlineText = (line) => line.split(/(\t|\r\n|\r|\n)/u).flatMap((part) => {
|
|
2200
|
+
if (part === " ") return [{ type: "tab" }];
|
|
2201
|
+
if (LINE_BREAK_PATTERN.test(part)) return [{ type: "break" }];
|
|
2202
|
+
return part === "" ? [] : [{
|
|
2203
|
+
type: "text",
|
|
2204
|
+
text: part
|
|
2205
|
+
}];
|
|
2206
|
+
});
|
|
2207
|
+
/**
|
|
2208
|
+
* Room past the highest revision or annotation id below which a batch draws
|
|
2209
|
+
* its revision ids from the free ones instead: more than any one batch asks.
|
|
2210
|
+
*/
|
|
2211
|
+
const REVISION_ID_WRAP_HEADROOM = 65536;
|
|
2212
|
+
/**
|
|
2213
|
+
* A lease of every id, but for revisions only the ones no revision record or
|
|
2214
|
+
* annotation holds, lowest first.
|
|
2215
|
+
*/
|
|
2216
|
+
const wrappedRevisionLease = (taken) => {
|
|
2217
|
+
const blocks = Object.values(ID_LEASE_KINDS).filter((kind) => kind !== ID_LEASE_KINDS.REVISION).map((kind) => ({
|
|
2218
|
+
kind,
|
|
2219
|
+
start: 1,
|
|
2220
|
+
end: ID_KIND_LIMITS[kind]
|
|
2221
|
+
}));
|
|
2222
|
+
let start = 1;
|
|
2223
|
+
for (const id of [...taken].toSorted((left, right) => left - right)) {
|
|
2224
|
+
if (id < start) continue;
|
|
2225
|
+
if (id > start) blocks.push({
|
|
2226
|
+
kind: ID_LEASE_KINDS.REVISION,
|
|
2227
|
+
start,
|
|
2228
|
+
end: id
|
|
2229
|
+
});
|
|
2230
|
+
start = id + 1;
|
|
2231
|
+
}
|
|
2232
|
+
const end = ID_KIND_LIMITS[ID_LEASE_KINDS.REVISION];
|
|
2233
|
+
if (start < end) blocks.push({
|
|
2234
|
+
kind: ID_LEASE_KINDS.REVISION,
|
|
2235
|
+
start,
|
|
2236
|
+
end
|
|
2237
|
+
});
|
|
2238
|
+
return { blocks };
|
|
2239
|
+
};
|
|
2240
|
+
const allocatorLeaseForParagraphs = (paragraphLease) => paragraphLease === void 0 ? void 0 : { blocks: [
|
|
2241
|
+
...paragraphLease.blocks,
|
|
2242
|
+
{
|
|
2243
|
+
kind: ID_LEASE_KINDS.REVISION,
|
|
2244
|
+
start: 1,
|
|
2245
|
+
end: ID_KIND_LIMITS.revision
|
|
2246
|
+
},
|
|
2247
|
+
{
|
|
2248
|
+
kind: ID_LEASE_KINDS.CONTROL,
|
|
2249
|
+
start: 1,
|
|
2250
|
+
end: ID_KIND_LIMITS.control
|
|
2251
|
+
}
|
|
2252
|
+
] };
|
|
2253
|
+
/**
|
|
2254
|
+
* The revision an applied operation names as its own: a tracked merge's is
|
|
2255
|
+
* the paragraph-mark deletion that is the merge, not the separator it types;
|
|
2256
|
+
* any other operation's is its first record.
|
|
2257
|
+
*/
|
|
2258
|
+
const primaryRevisionId = ({ operation, intents, document, revisionIds }) => {
|
|
2259
|
+
const join = operation.type === "mergeBlockWithNext" ? intents.find((intent) => intent.type === "joinParagraphs") : void 0;
|
|
2260
|
+
const mark = join === void 0 ? void 0 : locateParagraphThroughTextBoxes(document, join.story, join.blockId)?.paragraph.pPrMark;
|
|
2261
|
+
const deletion = mark?.kind === "del" ? mark.info.id : mark?.deletion?.info.id;
|
|
2262
|
+
return deletion !== void 0 && revisionIds.includes(deletion) ? deletion : revisionIds.at(0);
|
|
2263
|
+
};
|
|
2264
|
+
const compilePublicIntents = ({ document, intents, mode, author, date, suggestionId, nextRevisionId, allocate, reservedBlockIds, idLease, paragraphAllocationLease, allocations: admittedAllocations, verifyOperation }) => {
|
|
2265
|
+
const ops = [];
|
|
2266
|
+
const recorded = [];
|
|
2267
|
+
let verifiedOperation;
|
|
2268
|
+
const absorbed = [];
|
|
2269
|
+
const source = document;
|
|
2270
|
+
const joinedInto = /* @__PURE__ */ new Map();
|
|
2271
|
+
const allocated = /* @__PURE__ */ new Map();
|
|
2272
|
+
const allocations = [];
|
|
2273
|
+
for (const [intentIndex, sourceIntent] of intents.entries()) {
|
|
2274
|
+
const paragraphLease = sourceIntent.type === "insertParagraphs" ? paragraphAllocationLease : void 0;
|
|
2275
|
+
const ids = admittedAllocations === void 0 ? allocate(document, sourceIntent, idLease ?? allocatorLeaseForParagraphs(paragraphLease)) : admittedAllocations.at(intentIndex);
|
|
2276
|
+
if (ids === void 0) panic("An admitted intent lost its allocation.");
|
|
2277
|
+
allocations.push(ids);
|
|
2278
|
+
const compilerLease = idLease ?? paragraphLease;
|
|
2279
|
+
const leased = compilerLease === void 0 ? {} : { idLease: compilerLease };
|
|
2280
|
+
let intent = sourceIntent;
|
|
2281
|
+
if (sourceIntent.type === "splitParagraph") {
|
|
2282
|
+
allocated.set(sourceIntent.newBlockId, ids.newBlockId);
|
|
2283
|
+
intent = {
|
|
2284
|
+
type: "splitParagraph",
|
|
2285
|
+
at: sourceIntent.at,
|
|
2286
|
+
...sourceIntent.to === void 0 ? {} : { to: sourceIntent.to },
|
|
2287
|
+
...sourceIntent.newHalf === void 0 ? {} : { newHalf: sourceIntent.newHalf },
|
|
2288
|
+
newBlockId: ids.newBlockId
|
|
2289
|
+
};
|
|
2290
|
+
} else if (sourceIntent.type === "formatParagraph") {
|
|
2291
|
+
const blockId = allocated.get(sourceIntent.at.blockId);
|
|
2292
|
+
if (blockId !== void 0) intent = {
|
|
2293
|
+
...sourceIntent,
|
|
2294
|
+
at: {
|
|
2295
|
+
...sourceIntent.at,
|
|
2296
|
+
blockId
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
const firstRevisionId = nextRevisionId;
|
|
2301
|
+
const revisionIds = idLease === void 0 ? ids.newIds.revision.map((_, index) => firstRevisionId + index + 1) : ids.newIds.revision;
|
|
2302
|
+
const compiled = compileEditorIntent(document, {
|
|
2303
|
+
intent,
|
|
2304
|
+
...intent.type === "replaceText" && intent.formattingSources !== void 0 ? { replacementFormattingDocument: source } : {},
|
|
2305
|
+
typedFormatting: TYPED_TEXT_FORMATTING.BODY_TEXT,
|
|
2306
|
+
mode: mode === "direct" ? {
|
|
2307
|
+
type: "editing",
|
|
2308
|
+
newIds: ids.newIds,
|
|
2309
|
+
reservedBlockIds,
|
|
2310
|
+
...leased
|
|
2311
|
+
} : {
|
|
2312
|
+
type: "suggesting",
|
|
2313
|
+
reservedBlockIds,
|
|
2314
|
+
...leased,
|
|
2315
|
+
revision: {
|
|
2316
|
+
id: idLease === void 0 ? firstRevisionId : ids.revisionId,
|
|
2317
|
+
author,
|
|
2318
|
+
date,
|
|
2319
|
+
...suggestionId === void 0 ? {} : { suggestionId }
|
|
2320
|
+
},
|
|
2321
|
+
newIds: {
|
|
2322
|
+
control: ids.newIds.control,
|
|
2323
|
+
revision: revisionIds
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
if (compiled.isErr()) return Result.err(compiled.error);
|
|
2328
|
+
const [only] = compiled.value.ops;
|
|
2329
|
+
const verified = verifyOperation !== void 0 && intents.length === 1 && compiled.value.ops.length === 1 && (sourceIntent.type === "insertParagraphs" && only?.type === DOCUMENT_OP_TYPES.INSERT_BLOCKS || sourceIntent.type === "replaceText" && (only?.type === DOCUMENT_OP_TYPES.INSERT_CONTENT || only?.type === DOCUMENT_OP_TYPES.INSERT_TEXT)) ? verifyOperation(document, only) : void 0;
|
|
2330
|
+
let applied;
|
|
2331
|
+
if (verified === void 0) {
|
|
2332
|
+
const unverified = applyDocumentOps(document, compiled.value.ops);
|
|
2333
|
+
if (unverified.isErr()) return Result.err(unverified.error);
|
|
2334
|
+
absorbed.push(...unverified.value.touched.absorbed ?? []);
|
|
2335
|
+
applied = unverified.value;
|
|
2336
|
+
} else {
|
|
2337
|
+
if (verified.isErr()) return Result.err(verified.error);
|
|
2338
|
+
verifiedOperation = verified.value;
|
|
2339
|
+
applied = verified.value;
|
|
2340
|
+
}
|
|
2341
|
+
if (applied.document === document) continue;
|
|
2342
|
+
let after = readModel(applied.document);
|
|
2343
|
+
const noteDeletion = mode === "direct" || noteReferenceEditsAllowed() ? void 0 : noteDeletionOps({
|
|
2344
|
+
before: document,
|
|
2345
|
+
after,
|
|
2346
|
+
stamp: {
|
|
2347
|
+
id: idLease === void 0 ? firstRevisionId : ids.revisionId,
|
|
2348
|
+
author,
|
|
2349
|
+
date,
|
|
2350
|
+
...suggestionId === void 0 ? {} : { suggestionId }
|
|
2351
|
+
},
|
|
2352
|
+
revisionIds
|
|
2353
|
+
});
|
|
2354
|
+
if (noteDeletion?.isErr() === true) return Result.err(noteDeletion.error);
|
|
2355
|
+
const notes = noteDeletion?.unwrap();
|
|
2356
|
+
const appliedRevisions = [...applied.revisions];
|
|
2357
|
+
if (notes !== void 0 && notes.ops.length > 0) {
|
|
2358
|
+
const noted = applyDocumentOps(after, notes.ops);
|
|
2359
|
+
if (noted.isErr()) return Result.err(noted.error);
|
|
2360
|
+
verifiedOperation = void 0;
|
|
2361
|
+
after = noted.value.document;
|
|
2362
|
+
appliedRevisions.push(...notes.revisions);
|
|
2363
|
+
}
|
|
2364
|
+
document = after;
|
|
2365
|
+
ops.push(...compiled.value.ops, ...notes?.ops ?? []);
|
|
2366
|
+
recorded.push({
|
|
2367
|
+
revisions: appliedRevisions,
|
|
2368
|
+
folded: applied.folded
|
|
2369
|
+
});
|
|
2370
|
+
for (const id of appliedRevisions) nextRevisionId = Math.max(nextRevisionId, id + 1);
|
|
2371
|
+
if (mode === "direct") continue;
|
|
2372
|
+
if (sourceIntent.type === "joinParagraphs") joinedInto.set(idKey(sourceIntent.nextBlockId), sourceIntent.blockId);
|
|
2373
|
+
if (intent.type !== "formatParagraph") continue;
|
|
2374
|
+
const joined = joinedInto.get(idKey(intent.at.blockId));
|
|
2375
|
+
if (joined === void 0) continue;
|
|
2376
|
+
const link = joinPropertyChangeLink({
|
|
2377
|
+
before: source,
|
|
2378
|
+
after: document,
|
|
2379
|
+
story: intent.at.story,
|
|
2380
|
+
blockId: joined,
|
|
2381
|
+
propertiesBlockId: intent.at.blockId
|
|
2382
|
+
});
|
|
2383
|
+
if (link === void 0) continue;
|
|
2384
|
+
const linked = applyDocumentOps(document, [link]);
|
|
2385
|
+
if (linked.isErr()) return Result.err(linked.error);
|
|
2386
|
+
document = readModel(linked.value.document);
|
|
2387
|
+
ops.push(link);
|
|
2388
|
+
}
|
|
2389
|
+
return Result.ok({
|
|
2390
|
+
document,
|
|
2391
|
+
ops,
|
|
2392
|
+
...combineRecordedRevisions(recorded),
|
|
2393
|
+
nextRevisionId,
|
|
2394
|
+
allocations,
|
|
2395
|
+
verifiedOperation,
|
|
2396
|
+
absorbed
|
|
2397
|
+
});
|
|
2398
|
+
};
|
|
2399
|
+
const CanonicalPublicOperationResolutionErrorBase = TaggedError("CanonicalPublicOperationResolutionError");
|
|
2400
|
+
var CanonicalPublicOperationResolutionError = class extends CanonicalPublicOperationResolutionErrorBase {};
|
|
2401
|
+
/** Both the tracked join and a subsequent property alignment may write the survivor. */
|
|
2402
|
+
const overwritesForeignMergeFormatting = ({ before, after, story, ops, author }) => {
|
|
2403
|
+
const targets = /* @__PURE__ */ new Set();
|
|
2404
|
+
for (const op of ops) {
|
|
2405
|
+
if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS) targets.add(op.nextBlockId);
|
|
2406
|
+
if (op.type === DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS) targets.add(op.blockId);
|
|
2407
|
+
}
|
|
2408
|
+
const foreignChanges = (paragraph) => paragraph.propertyChanges?.filter(({ info }) => info.author !== author) ?? [];
|
|
2409
|
+
const pending = paragraphsThroughTextBoxes(before, story).flatMap(({ paragraph }) => {
|
|
2410
|
+
if (paragraph.paraId === void 0 || !targets.has(paragraph.paraId)) return [];
|
|
2411
|
+
const changes = foreignChanges(paragraph);
|
|
2412
|
+
return changes.length === 0 ? [] : [[paragraph.paraId, changes]];
|
|
2413
|
+
});
|
|
2414
|
+
if (pending.length === 0) return false;
|
|
2415
|
+
const survivors = new Map(paragraphsThroughTextBoxes(after, story).map(({ paragraph }) => [paragraph.paraId, paragraph]));
|
|
2416
|
+
return pending.some(([id, revisions]) => {
|
|
2417
|
+
const survivor = survivors.get(id);
|
|
2418
|
+
return survivor === void 0 || JSON.stringify(revisions) !== JSON.stringify(foreignChanges(survivor));
|
|
2419
|
+
});
|
|
2420
|
+
};
|
|
2421
|
+
/** Recheck the native property boundary after earlier operations of this batch. */
|
|
2422
|
+
const batchPropertyRefusal = ({ document, story, operation }) => {
|
|
2423
|
+
switch (operation.type) {
|
|
2424
|
+
case "setBlockParagraphProperties": break;
|
|
2425
|
+
case "replaceBlock":
|
|
2426
|
+
if (operation.styleId === void 0) return void 0;
|
|
2427
|
+
break;
|
|
2428
|
+
default: return;
|
|
2429
|
+
}
|
|
2430
|
+
const paragraph = paragraphsThroughTextBoxes(document, story).find((entry) => entry.paragraph.paraId === operation.blockId)?.paragraph;
|
|
2431
|
+
if (operation.type === "replaceBlock" && operation.styleId === (paragraph?.formatting?.styleId ?? null)) return void 0;
|
|
2432
|
+
return pendingParagraphPropertiesRefusal(paragraph?.pPrMark);
|
|
2433
|
+
};
|
|
2434
|
+
/**
|
|
2435
|
+
* The native column applier uses the same successful same-gap insertion
|
|
2436
|
+
* count; a column inserted on either side keeps a one-column table standing.
|
|
2437
|
+
*/
|
|
2438
|
+
const mapColumnDeletionIntents = ({ intents, columnIndex, inserted, insertedAfter }) => {
|
|
2439
|
+
if (inserted === 0 && insertedAfter === 0) return intents;
|
|
2440
|
+
return intents.map((intent) => {
|
|
2441
|
+
if (intent.type === "table" && intent.operation.type === DOCUMENT_OP_TYPES.DELETE_COLUMN) return inserted === 0 ? intent : {
|
|
2442
|
+
type: "table",
|
|
2443
|
+
operation: {
|
|
2444
|
+
...intent.operation,
|
|
2445
|
+
column: columnIndex + inserted
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
if (intent.type === "tableBlock" && intent.operation.type === DOCUMENT_OP_TYPES.DELETE_TABLE) return {
|
|
2449
|
+
type: "table",
|
|
2450
|
+
operation: {
|
|
2451
|
+
type: DOCUMENT_OP_TYPES.DELETE_COLUMN,
|
|
2452
|
+
story: intent.operation.story,
|
|
2453
|
+
blockId: intent.operation.blockId,
|
|
2454
|
+
column: columnIndex + inserted
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
return intent;
|
|
2458
|
+
});
|
|
2459
|
+
};
|
|
2460
|
+
/** Whether the batch deletes none of the paragraphs right before. */
|
|
2461
|
+
const noDeletedRunBefore = ({ type }) => {
|
|
2462
|
+
switch (type) {
|
|
2463
|
+
case "none": return true;
|
|
2464
|
+
case "kept":
|
|
2465
|
+
case "runStart":
|
|
2466
|
+
case "bounded": return false;
|
|
2467
|
+
default: return type;
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
/**
|
|
2471
|
+
* The paragraphs right before the one starting at `paragraphStart` that the
|
|
2472
|
+
* batch deletes, putting nothing beside them, as `finalBreakCarrier` reads
|
|
2473
|
+
* them: `kept` when a paragraph the batch keeps precedes them, `runStart`
|
|
2474
|
+
* when they reach back to the container's start or another block, `none`
|
|
2475
|
+
* when the batch keeps the paragraph right before it.
|
|
2476
|
+
*/
|
|
2477
|
+
const deletedRunBefore = ({ doc, paragraphStart, besideDeletions, tracked }) => {
|
|
2478
|
+
const at = doc.resolve(paragraphStart - 1);
|
|
2479
|
+
let deleted = 0;
|
|
2480
|
+
let position = paragraphStart - 1;
|
|
2481
|
+
for (let index = at.index() - 1; index >= 0; index--) {
|
|
2482
|
+
const previous = at.parent.child(index);
|
|
2483
|
+
position -= previous.nodeSize;
|
|
2484
|
+
if (previous.type.name !== "paragraph") break;
|
|
2485
|
+
if (tracked && goesWholeOnAcceptance(previous)) continue;
|
|
2486
|
+
const id = previous.attrs["paraId"];
|
|
2487
|
+
if (typeof id !== "string") return { type: deleted === 0 ? "none" : "kept" };
|
|
2488
|
+
const blockAfter = besideDeletions.paragraphsAfter.has(id) || besideDeletions.tables.after.has(id);
|
|
2489
|
+
if (!besideDeletions.deleted.has(id) && blockAfter) return tracked && deleted > 0 ? {
|
|
2490
|
+
type: "bounded",
|
|
2491
|
+
claimFrom: position + 1
|
|
2492
|
+
} : { type: "none" };
|
|
2493
|
+
const blockBefore = !blockAfter && (besideDeletions.insertedBeside.has(id) || besideDeletions.tables.before.has(id));
|
|
2494
|
+
if (tracked && besideDeletions.deleted.has(id) && blockBefore) return {
|
|
2495
|
+
type: "bounded",
|
|
2496
|
+
claimFrom: position
|
|
2497
|
+
};
|
|
2498
|
+
if (!besideDeletions.deleted.has(id) || besideDeletions.insertedBeside.has(id) || besideDeletions.tables.after.has(id) || besideDeletions.tables.before.has(id)) return { type: deleted === 0 ? "none" : "kept" };
|
|
2499
|
+
deleted += 1;
|
|
2500
|
+
}
|
|
2501
|
+
return { type: deleted === 0 ? "none" : "runStart" };
|
|
2502
|
+
};
|
|
2503
|
+
/** The ids of the paragraphs `block` holds, at any depth. */
|
|
2504
|
+
const paragraphIdsIn = (block) => {
|
|
2505
|
+
const ids = [];
|
|
2506
|
+
block.descendants((node) => {
|
|
2507
|
+
const id = node.attrs["paraId"];
|
|
2508
|
+
if (node.type.name === "paragraph" && typeof id === "string") ids.push(id);
|
|
2509
|
+
return node.type.name !== "paragraph";
|
|
2510
|
+
});
|
|
2511
|
+
return ids;
|
|
2512
|
+
};
|
|
2513
|
+
/**
|
|
2514
|
+
* The ids of the paragraphs a table's own cells hold, which name it: a
|
|
2515
|
+
* nested table's paragraphs name that one instead.
|
|
2516
|
+
*/
|
|
2517
|
+
const tableParagraphIds = (table) => {
|
|
2518
|
+
const ids = [];
|
|
2519
|
+
table.descendants((node) => {
|
|
2520
|
+
if (node.type.name === "table") return false;
|
|
2521
|
+
const id = node.attrs["paraId"];
|
|
2522
|
+
if (node.type.name === "paragraph" && typeof id === "string") ids.push(id);
|
|
2523
|
+
return node.type.name !== "paragraph";
|
|
2524
|
+
});
|
|
2525
|
+
return ids;
|
|
2526
|
+
};
|
|
2527
|
+
/** The blocks a batch's table insertions name, on `side` of them. */
|
|
2528
|
+
const tableAnchors = (operations, side) => new Set(operations.flatMap((operation) => (operation.type === "insertTable" || operation.type === "insertSignatureTable") && (operation.position ?? "after") === side ? [operation.blockId] : []));
|
|
2529
|
+
const NO_BESIDE_DELETIONS = {
|
|
2530
|
+
deleted: /* @__PURE__ */ new Set(),
|
|
2531
|
+
insertedBeside: /* @__PURE__ */ new Set(),
|
|
2532
|
+
tables: {
|
|
2533
|
+
after: /* @__PURE__ */ new Set(),
|
|
2534
|
+
before: /* @__PURE__ */ new Set(),
|
|
2535
|
+
deleted: /* @__PURE__ */ new Set()
|
|
2536
|
+
},
|
|
2537
|
+
paragraphsAfter: /* @__PURE__ */ new Set(),
|
|
2538
|
+
paragraphsAfterEarlier: () => /* @__PURE__ */ new Set()
|
|
2539
|
+
};
|
|
2540
|
+
/**
|
|
2541
|
+
* The stated numbering a request names, minting its new list once for the
|
|
2542
|
+
* operation, as the legacy engine allocates one instance per operation.
|
|
2543
|
+
*/
|
|
2544
|
+
const statedNumbering = (numbering, mint) => {
|
|
2545
|
+
if (numbering === void 0) return {};
|
|
2546
|
+
if (numbering.kind !== "newList") return { numbering };
|
|
2547
|
+
const minted = mint(numbering);
|
|
2548
|
+
return {
|
|
2549
|
+
numbering: paragraphNumberingReference({
|
|
2550
|
+
numId: minted.numId,
|
|
2551
|
+
ilvl: numbering.level ?? 0
|
|
2552
|
+
}),
|
|
2553
|
+
newList: minted.newList
|
|
2554
|
+
};
|
|
2555
|
+
};
|
|
2556
|
+
/**
|
|
2557
|
+
* Whether the story's editor document holds the paragraph `blockId`. One the
|
|
2558
|
+
* session's projection does not address still exists: a text box's
|
|
2559
|
+
* paragraphs belong to its shape, not to the story, so no story operation
|
|
2560
|
+
* reaches them.
|
|
2561
|
+
*/
|
|
2562
|
+
const holdsParagraph = (doc, blockId) => {
|
|
2563
|
+
let found = false;
|
|
2564
|
+
doc.descendants((node) => {
|
|
2565
|
+
if (found) return false;
|
|
2566
|
+
if (node.type.name === "paragraph" && node.attrs["paraId"] === blockId) found = true;
|
|
2567
|
+
return !found && !node.isTextblock;
|
|
2568
|
+
});
|
|
2569
|
+
return found;
|
|
2570
|
+
};
|
|
2571
|
+
/**
|
|
2572
|
+
* The content control or custom XML element the source leaves empty whose
|
|
2573
|
+
* filler paragraph `blockId` names, or `undefined`. The filler has no source
|
|
2574
|
+
* and no id of its own: a snapshot names it by the positional id the legacy
|
|
2575
|
+
* engine mints for it (`ensureParaIdsInDoc`), and positions in that copy are
|
|
2576
|
+
* the document's.
|
|
2577
|
+
*/
|
|
2578
|
+
const emptyControlOfFiller = (doc, blockId) => {
|
|
2579
|
+
const minted = ensureParaIdsInDoc(doc);
|
|
2580
|
+
if (minted === doc) return void 0;
|
|
2581
|
+
let filler;
|
|
2582
|
+
minted.descendants((node, position) => {
|
|
2583
|
+
if (filler !== void 0) return false;
|
|
2584
|
+
if (node.type.name !== "paragraph") return true;
|
|
2585
|
+
if (node.attrs["paraId"] === blockId) filler = position;
|
|
2586
|
+
return false;
|
|
2587
|
+
});
|
|
2588
|
+
if (filler === void 0 || doc.nodeAt(filler)?.attrs["paraId"] != null) return void 0;
|
|
2589
|
+
const $filler = doc.resolve(filler);
|
|
2590
|
+
const control = $filler.parent;
|
|
2591
|
+
if (control.type.name !== "blockSdt" && control.type.name !== "blockCustomXml" || control.attrs["_originallyEmpty"] !== true) return void 0;
|
|
2592
|
+
return {
|
|
2593
|
+
before: $filler.before(),
|
|
2594
|
+
after: $filler.after()
|
|
2595
|
+
};
|
|
2596
|
+
};
|
|
2597
|
+
/**
|
|
2598
|
+
* An operation on the filler of a block the source leaves empty, restated
|
|
2599
|
+
* beside the block: the paragraph or table it inserts goes in the gap before
|
|
2600
|
+
* or after the block, named by the paragraph or table on that side of it,
|
|
2601
|
+
* or, before a block that starts its list, by the start of that list; the
|
|
2602
|
+
* block stays as the source wrote it. Inside a table the insertion goes
|
|
2603
|
+
* beside the outermost table, as beside any paragraph of a cell. The
|
|
2604
|
+
* filler's properties are none, so an inserted paragraph inherits none.
|
|
2605
|
+
* Every other operation would edit the filler, which holds nothing to edit.
|
|
2606
|
+
*/
|
|
2607
|
+
const besideEmptyControl = ({ operation, control, projection }) => {
|
|
2608
|
+
const { doc } = projection;
|
|
2609
|
+
const tableAddress = (before) => {
|
|
2610
|
+
const table = doc.nodeAt(before);
|
|
2611
|
+
return table === null ? void 0 : tableBlockAddress(projection, {
|
|
2612
|
+
table,
|
|
2613
|
+
tableStart: before + 1
|
|
2614
|
+
});
|
|
2615
|
+
};
|
|
2616
|
+
const outer = findOutermostTableBoundary(doc, control.before);
|
|
2617
|
+
const sideOf = (side) => {
|
|
2618
|
+
const $gap = doc.resolve(control[side]);
|
|
2619
|
+
const beside = side === "after" ? $gap.nodeAfter : $gap.nodeBefore;
|
|
2620
|
+
const at = side === "after" ? control.after : control.before;
|
|
2621
|
+
const besideAt = side === "after" ? at : at - (beside?.nodeSize ?? 0);
|
|
2622
|
+
if (beside?.type.name === "paragraph") {
|
|
2623
|
+
const paragraph = projection.paragraphStartingAt(besideAt);
|
|
2624
|
+
return paragraph === void 0 ? { type: "none" } : {
|
|
2625
|
+
type: "paragraph",
|
|
2626
|
+
blockId: paragraph.blockId
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
if (beside?.type.name === "table") {
|
|
2630
|
+
const blockId = tableAddress(besideAt);
|
|
2631
|
+
return blockId === void 0 ? { type: "none" } : {
|
|
2632
|
+
type: "table",
|
|
2633
|
+
blockId
|
|
2634
|
+
};
|
|
2635
|
+
}
|
|
2636
|
+
if (beside !== null) return { type: "none" };
|
|
2637
|
+
let named;
|
|
2638
|
+
$gap.parent.forEach((child, offset) => {
|
|
2639
|
+
if (named !== void 0 || child.type.name !== "paragraph") return;
|
|
2640
|
+
named = projection.paragraphStartingAt($gap.start() + offset)?.blockId;
|
|
2641
|
+
});
|
|
2642
|
+
return named === void 0 ? { type: "none" } : {
|
|
2643
|
+
type: "listStart",
|
|
2644
|
+
listStart: {
|
|
2645
|
+
blockId: named,
|
|
2646
|
+
position: at
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
};
|
|
2650
|
+
const noNeighbour = {
|
|
2651
|
+
type: "refused",
|
|
2652
|
+
message: "Canonical insertion beside an empty content control needs a paragraph or table on that side of it."
|
|
2653
|
+
};
|
|
2654
|
+
const placed = ({ side, beside }) => {
|
|
2655
|
+
const facing = side === "after" ? "before" : "after";
|
|
2656
|
+
if (outer !== null) {
|
|
2657
|
+
const blockId = tableAddress(outer.before);
|
|
2658
|
+
return blockId === void 0 ? noNeighbour : {
|
|
2659
|
+
type: "beside",
|
|
2660
|
+
operation: beside(blockId, side)
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
const standing = sideOf(side);
|
|
2664
|
+
switch (standing.type) {
|
|
2665
|
+
case "paragraph":
|
|
2666
|
+
case "table": return {
|
|
2667
|
+
type: "beside",
|
|
2668
|
+
operation: beside(standing.blockId, facing)
|
|
2669
|
+
};
|
|
2670
|
+
case "listStart": return {
|
|
2671
|
+
type: "listStart",
|
|
2672
|
+
operation: beside(standing.listStart.blockId, side),
|
|
2673
|
+
listStart: standing.listStart
|
|
2674
|
+
};
|
|
2675
|
+
case "none": return noNeighbour;
|
|
2676
|
+
default: return standing;
|
|
2677
|
+
}
|
|
2678
|
+
};
|
|
2679
|
+
switch (operation.type) {
|
|
2680
|
+
case "insertAfterBlock":
|
|
2681
|
+
case "insertBeforeBlock": {
|
|
2682
|
+
const { precondition: _precondition, ...rest } = operation;
|
|
2683
|
+
return placed({
|
|
2684
|
+
side: operation.type === "insertAfterBlock" ? "after" : "before",
|
|
2685
|
+
beside: (blockId, side) => ({
|
|
2686
|
+
...rest,
|
|
2687
|
+
type: side === "after" ? "insertAfterBlock" : "insertBeforeBlock",
|
|
2688
|
+
blockId,
|
|
2689
|
+
inheritFormatting: false
|
|
2690
|
+
})
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
case "insertTable":
|
|
2694
|
+
case "insertSignatureTable": {
|
|
2695
|
+
const { precondition: _precondition, ...rest } = operation;
|
|
2696
|
+
return placed({
|
|
2697
|
+
side: operation.position ?? "after",
|
|
2698
|
+
beside: (blockId, side) => ({
|
|
2699
|
+
...rest,
|
|
2700
|
+
blockId,
|
|
2701
|
+
position: side
|
|
2702
|
+
})
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
case "replaceInBlock":
|
|
2706
|
+
case "replaceRange":
|
|
2707
|
+
case "replaceBlock":
|
|
2708
|
+
case "splitBlock":
|
|
2709
|
+
case "formatRange":
|
|
2710
|
+
case "mergeBlockWithNext":
|
|
2711
|
+
case "commentOnRange":
|
|
2712
|
+
case "commentOnBlock":
|
|
2713
|
+
case "deleteBlock":
|
|
2714
|
+
case "setBlockParagraphProperties":
|
|
2715
|
+
case "deleteTable":
|
|
2716
|
+
case "insertTableRow":
|
|
2717
|
+
case "deleteTableRow":
|
|
2718
|
+
case "insertTableColumn":
|
|
2719
|
+
case "deleteTableColumn":
|
|
2720
|
+
case "mergeTableCells":
|
|
2721
|
+
case "splitTableCell": return {
|
|
2722
|
+
type: "refused",
|
|
2723
|
+
message: "The paragraph shown in an empty content control is not part of the document; insert a block before or after the control instead."
|
|
2724
|
+
};
|
|
2725
|
+
default: return operation;
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
const canonicalPublicStory = (story) => {
|
|
2729
|
+
if (story === "main") return story;
|
|
2730
|
+
switch (story.type) {
|
|
2731
|
+
case "header":
|
|
2732
|
+
case "footer": return {
|
|
2733
|
+
kind: story.type,
|
|
2734
|
+
rId: story.relationshipId
|
|
2735
|
+
};
|
|
2736
|
+
case "footnote":
|
|
2737
|
+
case "endnote": return {
|
|
2738
|
+
kind: story.type,
|
|
2739
|
+
id: story.noteId
|
|
2740
|
+
};
|
|
2741
|
+
default: return panic(`Unknown public operation story ${story}`);
|
|
2742
|
+
}
|
|
2743
|
+
};
|
|
2744
|
+
const batchStatus = (batch, skippedCount) => {
|
|
2745
|
+
if (batch.dryRun) return "previewed";
|
|
2746
|
+
if (batch.atomic && skippedCount > 0) return "rejected";
|
|
2747
|
+
return "committed";
|
|
2748
|
+
};
|
|
2749
|
+
/** Handles address isolated journal groups; no second document or PM history is retained. */
|
|
2750
|
+
var CanonicalPublicOperations = class {
|
|
2751
|
+
options;
|
|
2752
|
+
handles = [];
|
|
2753
|
+
nextHandle = 1;
|
|
2754
|
+
handleNamespace = crypto.randomUUID();
|
|
2755
|
+
constructor(options) {
|
|
2756
|
+
this.options = options;
|
|
2757
|
+
}
|
|
2758
|
+
apply(options) {
|
|
2759
|
+
const { session } = this.options;
|
|
2760
|
+
const parsed = parseFolioDocumentOperationBatch(options.batch);
|
|
2761
|
+
if (options.restagesSuggestions === true && parsed.mode !== "suggested") panic("Only a suggested batch restages pending suggestions.");
|
|
2762
|
+
const lockAdmission = options.restagesSuggestions === true ? CANONICAL_ADMISSION.restage : CANONICAL_ADMISSION.edit;
|
|
2763
|
+
const batch = parsed.mode !== "suggested" || options.restagesSuggestions === true || session.isComposing ? parsed : withDistinctSuggestionIds(parsed, /* @__PURE__ */ new Set([...pendingSuggestionIdsIn(readModel(session.document)), ...options.pendingSuggestionIds ?? []]));
|
|
2764
|
+
const publicStory = options.story ?? "main";
|
|
2765
|
+
const story = canonicalPublicStory(publicStory);
|
|
2766
|
+
const state = this.options.getState(story);
|
|
2767
|
+
const projected = session.projectStory(story);
|
|
2768
|
+
const skipped = [];
|
|
2769
|
+
const normalizations = [];
|
|
2770
|
+
const refusals = /* @__PURE__ */ new Map();
|
|
2771
|
+
const resolved = [];
|
|
2772
|
+
let definedReferences;
|
|
2773
|
+
const references = () => {
|
|
2774
|
+
if (definedReferences !== void 0) return definedReferences;
|
|
2775
|
+
const model = readModel(session.document);
|
|
2776
|
+
definedReferences = {
|
|
2777
|
+
definitions: model.package.styles,
|
|
2778
|
+
styles: styleDefinitionLookup(createStyleResolver(model.package.styles)),
|
|
2779
|
+
numberingInstanceIds: new Set(model.package.numbering?.nums.map(({ numId }) => numId) ?? [])
|
|
2780
|
+
};
|
|
2781
|
+
return definedReferences;
|
|
2782
|
+
};
|
|
2783
|
+
const headingStyles = createOperationHeadingStyles();
|
|
2784
|
+
const headingLookups = /* @__PURE__ */ new WeakMap();
|
|
2785
|
+
const headingLookup = (definitions) => {
|
|
2786
|
+
const existing = headingLookups.get(definitions);
|
|
2787
|
+
if (existing !== void 0) return existing;
|
|
2788
|
+
const lookup = styleDefinitionLookup(createStyleResolver(definitions));
|
|
2789
|
+
headingLookups.set(definitions, lookup);
|
|
2790
|
+
return lookup;
|
|
2791
|
+
};
|
|
2792
|
+
const mintList = createBatchListMinter(() => readModel(session.document));
|
|
2793
|
+
const { diff } = wordDiffSessionFromOptions(options.wordDiff);
|
|
2794
|
+
let nextRevisionId = options.revisionStamp?.idSeed ?? 1;
|
|
2795
|
+
let batchLease = session.idLease;
|
|
2796
|
+
if (!session.isComposing && options.revisionStamp === void 0) {
|
|
2797
|
+
const taken = new Set(leasedIdCensus(readModel(session.document)).revision);
|
|
2798
|
+
for (const currentStory of documentStories(readModel(session.document))) {
|
|
2799
|
+
const currentProjection = session.projectStory(currentStory);
|
|
2800
|
+
if (currentProjection.isOk()) forEachAnnotationIdInDoc(currentProjection.value.doc, (id) => taken.add(id));
|
|
2801
|
+
}
|
|
2802
|
+
for (const id of taken) nextRevisionId = Math.max(nextRevisionId, id + 1);
|
|
2803
|
+
if (batchLease === void 0 && MAX_REVISION_ID + 1 - nextRevisionId < REVISION_ID_WRAP_HEADROOM) batchLease = wrappedRevisionLease(taken);
|
|
2804
|
+
}
|
|
2805
|
+
const skip = (id, reason, message) => {
|
|
2806
|
+
skipped.push({
|
|
2807
|
+
id,
|
|
2808
|
+
reason,
|
|
2809
|
+
...message === void 0 ? {} : { message }
|
|
2810
|
+
});
|
|
2811
|
+
};
|
|
2812
|
+
const refuseResolution = (id, error) => {
|
|
2813
|
+
const gap = error.gap === null ? void 0 : error.gap ?? (error.reason === "unsupportedBlock" ? CANONICAL_GAP.publicUnsupportedInline : void 0);
|
|
2814
|
+
if (gap !== void 0) refusals.set(id, { gap });
|
|
2815
|
+
skip(id, error.reason, error.detail);
|
|
2816
|
+
};
|
|
2817
|
+
const result = (applied, undoHandle, disposition = "normal") => {
|
|
2818
|
+
const failures = new Map(skipped.map((item) => [item.id, item]));
|
|
2819
|
+
const ordered = batch.operations.flatMap(({ id }) => {
|
|
2820
|
+
const failure = failures.get(id);
|
|
2821
|
+
if (!failure) return [];
|
|
2822
|
+
const canonicalRefusal = refusals.get(id);
|
|
2823
|
+
return [canonicalRefusal ? {
|
|
2824
|
+
...failure,
|
|
2825
|
+
canonicalRefusal
|
|
2826
|
+
} : failure];
|
|
2827
|
+
});
|
|
2828
|
+
return {
|
|
2829
|
+
version: 1,
|
|
2830
|
+
status: disposition === "refused" && !batch.dryRun ? "rejected" : batchStatus(batch, ordered.length),
|
|
2831
|
+
applied,
|
|
2832
|
+
skipped: ordered,
|
|
2833
|
+
issues: getFolioDocumentOperationIssues(batch.operations, ordered),
|
|
2834
|
+
receipts: getFolioDocumentOperationReceiptsForStory({
|
|
2835
|
+
operations: batch.operations,
|
|
2836
|
+
applied,
|
|
2837
|
+
story: publicStory
|
|
2838
|
+
}),
|
|
2839
|
+
undoHandle,
|
|
2840
|
+
nextRevisionId,
|
|
2841
|
+
...normalizations.length === 0 ? {} : { normalizations }
|
|
2842
|
+
};
|
|
2843
|
+
};
|
|
2844
|
+
const besideDeletions = {
|
|
2845
|
+
deleted: new Set(batch.operations.flatMap((operation) => operation.type === "deleteBlock" ? [operation.blockId] : [])),
|
|
2846
|
+
insertedBeside: new Set(batch.operations.flatMap((operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock" ? [operation.blockId] : [])),
|
|
2847
|
+
tables: {
|
|
2848
|
+
after: tableAnchors(batch.operations, "after"),
|
|
2849
|
+
before: tableAnchors(batch.operations, "before"),
|
|
2850
|
+
deleted: new Set(batch.operations.flatMap((operation) => operation.type === "deleteTable" ? [operation.blockId] : []))
|
|
2851
|
+
},
|
|
2852
|
+
paragraphsAfter: new Set(batch.operations.flatMap((operation) => operation.type === "insertAfterBlock" ? [operation.blockId] : [])),
|
|
2853
|
+
paragraphsAfterEarlier: (operationId) => {
|
|
2854
|
+
const index = batch.operations.findIndex(({ id }) => id === operationId);
|
|
2855
|
+
return new Set(batch.operations.slice(0, Math.max(index, 0)).flatMap((operation) => operation.type === "insertAfterBlock" ? [operation.blockId] : []));
|
|
2856
|
+
}
|
|
2857
|
+
};
|
|
2858
|
+
const inputIndices = new Map(batch.operations.map(({ id }, index) => [id, index]));
|
|
2859
|
+
const planned = (item) => {
|
|
2860
|
+
if (projected.isErr()) return panic("A resolved batch lost its read projection");
|
|
2861
|
+
const inputIndex = inputIndices.get(item.operation.id) ?? panic("A resolved operation lost its input position");
|
|
2862
|
+
return {
|
|
2863
|
+
...item,
|
|
2864
|
+
plan: canonicalBatchPlan({
|
|
2865
|
+
...item,
|
|
2866
|
+
projection: projected.value,
|
|
2867
|
+
tracked: batch.mode !== "direct",
|
|
2868
|
+
inputIndex
|
|
2869
|
+
})
|
|
2870
|
+
};
|
|
2871
|
+
};
|
|
2872
|
+
let claims = new BatchClaims();
|
|
2873
|
+
const conflictsWithRevision = batch.mode !== "direct" && batch.existingRevisions === "refuse-cross-author" && projected.isOk() ? createExistingRevisionGuard({
|
|
2874
|
+
doc: projected.value.doc,
|
|
2875
|
+
author: options.author ?? "AI"
|
|
2876
|
+
}) : void 0;
|
|
2877
|
+
const refusesExistingRevision = ({ operation, plan }) => {
|
|
2878
|
+
if (operation.type === "commentOnBlock" || operation.type === "commentOnRange" || !conflictsWithRevision?.(plan.claim)) return false;
|
|
2879
|
+
skip(operation.id, "existingRevisionConflict", EXISTING_REVISION_CONFLICT_MESSAGE);
|
|
2880
|
+
return true;
|
|
2881
|
+
};
|
|
2882
|
+
/** Skip a candidate an earlier operation of the batch already claims. */
|
|
2883
|
+
const skipsOverlap = (candidate) => {
|
|
2884
|
+
const claimedBy = claims.conflictOf(candidate.plan.claim);
|
|
2885
|
+
if (claimedBy === null) return false;
|
|
2886
|
+
skip(candidate.operation.id, "overlappingOperation", `operation ${JSON.stringify(claimedBy)}, earlier in this batch, already claims its target.`);
|
|
2887
|
+
return true;
|
|
2888
|
+
};
|
|
2889
|
+
const removedLines = /* @__PURE__ */ new Set();
|
|
2890
|
+
/** Skip a row or column deletion an earlier one of the batch already makes. */
|
|
2891
|
+
const skipsRepeatedRemoval = (candidate) => {
|
|
2892
|
+
const { removes } = candidate.plan;
|
|
2893
|
+
if (removes === null || !removedLines.has(tableLineRemovalKey(removes))) return false;
|
|
2894
|
+
skip(candidate.operation.id, "noopOperation");
|
|
2895
|
+
return true;
|
|
2896
|
+
};
|
|
2897
|
+
const admit = (candidate) => {
|
|
2898
|
+
claims.add(candidate.operation.id, candidate.plan.claim);
|
|
2899
|
+
const { removes } = candidate.plan;
|
|
2900
|
+
if (removes !== null) removedLines.add(tableLineRemovalKey(removes));
|
|
2901
|
+
resolved.push(candidate);
|
|
2902
|
+
};
|
|
2903
|
+
/** Refused, but claiming the target their direct form would. */
|
|
2904
|
+
const claimedUnapplied = [];
|
|
2905
|
+
for (const operation of batch.operations) {
|
|
2906
|
+
if (!state || projected.isErr() || session.isComposing) {
|
|
2907
|
+
skip(operation.id, "documentNotEditable");
|
|
2908
|
+
continue;
|
|
2909
|
+
}
|
|
2910
|
+
if (batch.mode === "suggested" && !CANONICAL_SUGGESTED_OPERATION_TYPES.has(operation.type)) {
|
|
2911
|
+
skip(operation.id, "unsupportedMode");
|
|
2912
|
+
continue;
|
|
2913
|
+
}
|
|
2914
|
+
const referenceSet = references();
|
|
2915
|
+
const headings = options.undefinedReferences === "keep" ? referenceSet.definitions : headingStyles(referenceSet.definitions, operation);
|
|
2916
|
+
const undefinedReference = findUndefinedOperationReference({
|
|
2917
|
+
operation,
|
|
2918
|
+
numberingInstanceIds: referenceSet.numberingInstanceIds,
|
|
2919
|
+
styles: headings === void 0 || headings === referenceSet.definitions ? referenceSet.styles : headingLookup(headings),
|
|
2920
|
+
undefinedReferences: options.undefinedReferences
|
|
2921
|
+
});
|
|
2922
|
+
if (undefinedReference !== void 0) {
|
|
2923
|
+
skip(operation.id, undefinedReference.reason, undefinedReference.message);
|
|
2924
|
+
continue;
|
|
2925
|
+
}
|
|
2926
|
+
const disposition = CANONICAL_PUBLIC_OPERATION_DISPOSITIONS[operation.type];
|
|
2927
|
+
if (disposition !== "compile") {
|
|
2928
|
+
refusals.set(operation.id, { gap: disposition });
|
|
2929
|
+
skip(operation.id, "unsupportedBlock");
|
|
2930
|
+
continue;
|
|
2931
|
+
}
|
|
2932
|
+
const compiled = this.resolve({
|
|
2933
|
+
operation,
|
|
2934
|
+
options,
|
|
2935
|
+
state,
|
|
2936
|
+
story,
|
|
2937
|
+
diff,
|
|
2938
|
+
tracked: batch.mode !== "direct",
|
|
2939
|
+
suggested: batch.mode === "suggested",
|
|
2940
|
+
mintList,
|
|
2941
|
+
besideDeletions
|
|
2942
|
+
});
|
|
2943
|
+
if (compiled.isErr()) {
|
|
2944
|
+
const direct = compiled.error.refusedIn === "trackedMode" ? this.resolve({
|
|
2945
|
+
operation,
|
|
2946
|
+
options,
|
|
2947
|
+
state,
|
|
2948
|
+
story,
|
|
2949
|
+
diff,
|
|
2950
|
+
tracked: false,
|
|
2951
|
+
suggested: false,
|
|
2952
|
+
mintList,
|
|
2953
|
+
besideDeletions
|
|
2954
|
+
}) : void 0;
|
|
2955
|
+
if (direct?.isOk()) {
|
|
2956
|
+
const candidate = planned(direct.value);
|
|
2957
|
+
if (skipsRepeatedRemoval(candidate)) continue;
|
|
2958
|
+
if (refusesExistingRevision(candidate)) continue;
|
|
2959
|
+
if (skipsOverlap(candidate)) continue;
|
|
2960
|
+
claims.add(operation.id, candidate.plan.claim);
|
|
2961
|
+
claimedUnapplied.push(candidate);
|
|
2962
|
+
}
|
|
2963
|
+
refuseResolution(operation.id, compiled.error);
|
|
2964
|
+
continue;
|
|
2965
|
+
}
|
|
2966
|
+
const candidate = planned(compiled.value);
|
|
2967
|
+
if (skipsRepeatedRemoval(candidate)) continue;
|
|
2968
|
+
if (refusesExistingRevision(candidate)) continue;
|
|
2969
|
+
if (skipsOverlap(candidate)) continue;
|
|
2970
|
+
admit(candidate);
|
|
2971
|
+
}
|
|
2972
|
+
for (const item of [...resolved]) {
|
|
2973
|
+
if (item.besideDeletion !== true || !state) continue;
|
|
2974
|
+
const { operation } = item;
|
|
2975
|
+
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock") continue;
|
|
2976
|
+
if (resolved.some(({ operation: other }) => operation.type === "deleteBlock" ? (other.type === "insertAfterBlock" || other.type === "insertBeforeBlock") && other.blockId === operation.blockId : other.type === "deleteBlock" && other.blockId === operation.blockId)) continue;
|
|
2977
|
+
resolved.splice(resolved.indexOf(item), 1);
|
|
2978
|
+
claims = new BatchClaims();
|
|
2979
|
+
for (const earlier of [...resolved, ...claimedUnapplied]) claims.add(earlier.operation.id, earlier.plan.claim);
|
|
2980
|
+
const alone = this.resolve({
|
|
2981
|
+
operation,
|
|
2982
|
+
options,
|
|
2983
|
+
state,
|
|
2984
|
+
story,
|
|
2985
|
+
diff,
|
|
2986
|
+
tracked: batch.mode !== "direct",
|
|
2987
|
+
suggested: batch.mode === "suggested",
|
|
2988
|
+
mintList,
|
|
2989
|
+
besideDeletions: NO_BESIDE_DELETIONS
|
|
2990
|
+
});
|
|
2991
|
+
if (alone.isErr()) {
|
|
2992
|
+
refuseResolution(operation.id, alone.error);
|
|
2993
|
+
continue;
|
|
2994
|
+
}
|
|
2995
|
+
const candidate = planned(alone.value);
|
|
2996
|
+
if (refusesExistingRevision(candidate)) continue;
|
|
2997
|
+
if (skipsOverlap(candidate)) continue;
|
|
2998
|
+
admit(candidate);
|
|
2999
|
+
}
|
|
3000
|
+
const moveSides = /* @__PURE__ */ new Map();
|
|
3001
|
+
for (const { operation } of resolved) {
|
|
3002
|
+
const moveId = blockMoveId(operation);
|
|
3003
|
+
if (moveId === void 0) continue;
|
|
3004
|
+
const sides = moveSides.get(moveId) ?? {
|
|
3005
|
+
from: 0,
|
|
3006
|
+
to: 0
|
|
3007
|
+
};
|
|
3008
|
+
if (operation.type === "deleteBlock") sides.from += 1;
|
|
3009
|
+
else sides.to += 1;
|
|
3010
|
+
moveSides.set(moveId, sides);
|
|
3011
|
+
}
|
|
3012
|
+
const unpairable = new Set(batch.mode === "suggested" ? resolved.flatMap(({ operation }) => operation.type === "insertBeforeBlock" && operation.moveId !== void 0 && resolved.some((candidate) => candidate.operation.type === "deleteBlock" && candidate.operation.moveId === operation.moveId && candidate.operation.blockId === operation.blockId) ? [operation.moveId] : []) : []);
|
|
3013
|
+
const paired = (moveId) => !unpairable.has(moveId) && moveSides.get(moveId)?.from === 1 && moveSides.get(moveId)?.to === 1;
|
|
3014
|
+
const pairedMoves = /* @__PURE__ */ new Set();
|
|
3015
|
+
for (const [index, item] of resolved.entries()) {
|
|
3016
|
+
const moveId = blockMoveId(item.operation);
|
|
3017
|
+
if (moveId === void 0) continue;
|
|
3018
|
+
if (!paired(moveId)) {
|
|
3019
|
+
normalizations.push({
|
|
3020
|
+
id: item.operation.id,
|
|
3021
|
+
code: "unpairedMove",
|
|
3022
|
+
moveId
|
|
3023
|
+
});
|
|
3024
|
+
continue;
|
|
3025
|
+
}
|
|
3026
|
+
pairedMoves.add(moveId);
|
|
3027
|
+
const intents = [];
|
|
3028
|
+
for (const intent of item.intents) intents.push(intent.type === "insertParagraphs" || intent.type === "deleteParagraphs" ? Object.assign({}, intent, { move: true }) : intent);
|
|
3029
|
+
resolved[index] = {
|
|
3030
|
+
...item,
|
|
3031
|
+
intents
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
const shaping = [...resolved, ...claimedUnapplied].toSorted((left, right) => (inputIndices.get(left.operation.id) ?? 0) - (inputIndices.get(right.operation.id) ?? 0));
|
|
3035
|
+
const refuseShapes = (items, message) => {
|
|
3036
|
+
for (const item of items) {
|
|
3037
|
+
shaping.splice(shaping.indexOf(item), 1);
|
|
3038
|
+
const index = resolved.indexOf(item);
|
|
3039
|
+
if (index < 0) continue;
|
|
3040
|
+
resolved.splice(index, 1);
|
|
3041
|
+
skip(item.operation.id, "unsupportedBlock", message);
|
|
3042
|
+
}
|
|
3043
|
+
};
|
|
3044
|
+
refuseShapes(rowShiftedCellShapes(shaping), ROW_SHIFTED_CELL_SHAPE);
|
|
3045
|
+
refuseShapes(columnEditedCellShapes(shaping), COLUMN_EDITED_CELL_SHAPE);
|
|
3046
|
+
if (projected.isOk()) refuseShapes(rowClosingCellShapes({
|
|
3047
|
+
items: shaping,
|
|
3048
|
+
doc: projected.value.doc
|
|
3049
|
+
}), ROW_CLOSING_CELL_SHAPE);
|
|
3050
|
+
if (batch.atomic && skipped.length > 0) {
|
|
3051
|
+
for (const { operation } of resolved) skip(operation.id, "atomicBatchRejected");
|
|
3052
|
+
return result([], null);
|
|
3053
|
+
}
|
|
3054
|
+
if (!state || projected.isErr() || session.isComposing) return result([], null);
|
|
3055
|
+
const executionOrder = orderCanonicalBatch({
|
|
3056
|
+
items: resolved,
|
|
3057
|
+
doc: projected.value.doc,
|
|
3058
|
+
mode: batch.mode ?? "tracked-changes"
|
|
3059
|
+
});
|
|
3060
|
+
let document = readModel(session.document);
|
|
3061
|
+
const beforeBatch = document;
|
|
3062
|
+
let annotated;
|
|
3063
|
+
const ops = [];
|
|
3064
|
+
const operationStaging = session.beginVerifiedOperationStaging(canonicalOperationStagingAccess, lockAdmission);
|
|
3065
|
+
let reuseStaging = true;
|
|
3066
|
+
const appliedById = /* @__PURE__ */ new Map();
|
|
3067
|
+
const allocate = createEditorIntentIdAllocator({ reservedBlockIds: session.reservedBlockIds });
|
|
3068
|
+
const date = options.revisionStamp?.date ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
3069
|
+
const insertedColumnCounts = /* @__PURE__ */ new Map();
|
|
3070
|
+
const recordColumnInsertion = (member, counts) => {
|
|
3071
|
+
const column = member.plan.address;
|
|
3072
|
+
if (column.type !== "column" || !column.insertion) return;
|
|
3073
|
+
const key = getTableColumnCoordinateKey(column);
|
|
3074
|
+
const added = member.operation.type === "insertTableColumn" ? member.operation.columnCount ?? 1 : 1;
|
|
3075
|
+
counts.set(key, (counts.get(key) ?? 0) + added);
|
|
3076
|
+
};
|
|
3077
|
+
const declined = ({ reason, message, refusal }) => ({
|
|
3078
|
+
type: "declined",
|
|
3079
|
+
reason,
|
|
3080
|
+
message,
|
|
3081
|
+
refusal
|
|
3082
|
+
});
|
|
3083
|
+
/**
|
|
3084
|
+
* The paragraph each paragraph an earlier operation of the batch joined
|
|
3085
|
+
* away now lives in: an edit of its properties edits that one, as it
|
|
3086
|
+
* does one at a time after that operation.
|
|
3087
|
+
*/
|
|
3088
|
+
const survivorOf = /* @__PURE__ */ new Map();
|
|
3089
|
+
/** Those whose words open the paragraph they now live in. */
|
|
3090
|
+
const openingSurvivorOf = /* @__PURE__ */ new Map();
|
|
3091
|
+
const deletionSurvivorOf = /* @__PURE__ */ new Map();
|
|
3092
|
+
const prepareOperation = ({ document: sourceDocument, resolvedOperation, columnInsertions, nextRevisionId: firstRevisionId, idLease = batchLease, paragraphAllocationLease, allocations, reservedBlockIds = session.reservedBlockIds, verifyOperation, commentAllocation: admittedComment }) => {
|
|
3093
|
+
const { operation } = resolvedOperation;
|
|
3094
|
+
const authorIssue = (batch.mode === "direct" ? void 0 : trackedChangeAuthorIssue(options.author ?? "AI")) ?? (resolvedOperation.type === "commented" ? commentAuthorIssue(options.author ?? "AI") : void 0);
|
|
3095
|
+
if (authorIssue !== void 0) return declined({
|
|
3096
|
+
reason: "invalidResult",
|
|
3097
|
+
message: authorIssue
|
|
3098
|
+
});
|
|
3099
|
+
const inserting = formattingIntentsAsItRuns({
|
|
3100
|
+
document: sourceDocument,
|
|
3101
|
+
story,
|
|
3102
|
+
survivorOf,
|
|
3103
|
+
openingSurvivorOf,
|
|
3104
|
+
deletionSurvivorOf,
|
|
3105
|
+
intents: insertionIntentsAsItRuns({
|
|
3106
|
+
document: sourceDocument,
|
|
3107
|
+
story,
|
|
3108
|
+
survivorOf,
|
|
3109
|
+
resolvedOperation
|
|
3110
|
+
})
|
|
3111
|
+
});
|
|
3112
|
+
const shift = batchCommentReferenceShift({
|
|
3113
|
+
before: beforeBatch,
|
|
3114
|
+
commented: resolvedOperation.plan.address.type === "annotation" ? sourceDocument : annotated ?? sourceDocument
|
|
3115
|
+
});
|
|
3116
|
+
const shifted = inserting.map((intent) => mapIntentPositions(intent, shift));
|
|
3117
|
+
const rebound = resolvedOperation.joinsParagraphBefore === true ? deletionIntentsAsItRuns(sourceDocument, story, shifted) : shifted;
|
|
3118
|
+
const retired = resolvedOperation.retiresBreakBefore === true ? retiredBreakAsItRuns(sourceDocument, story, rebound) : rebound;
|
|
3119
|
+
const deleting = resolvedOperation.mayEndContainer === true ? finalDeletionIntentsAsItRuns(sourceDocument, story, retired) : retired;
|
|
3120
|
+
const suggestionId = batch.mode === "suggested" ? ("suggestionId" in operation ? operation.suggestionId : void 0) ?? operation.id : void 0;
|
|
3121
|
+
const retracting = operation.type === "deleteBlock" && batch.mode !== "direct" && operation.moveId === void 0 ? takenOverBreakRetractionAsItRuns({
|
|
3122
|
+
document: sourceDocument,
|
|
3123
|
+
story,
|
|
3124
|
+
blockId: operation.blockId,
|
|
3125
|
+
author: options.author ?? "AI",
|
|
3126
|
+
suggestionId,
|
|
3127
|
+
intents: ownMarkBeforeInsertedTableAsItRuns({
|
|
3128
|
+
document: sourceDocument,
|
|
3129
|
+
story,
|
|
3130
|
+
blockId: operation.blockId,
|
|
3131
|
+
author: options.author ?? "AI",
|
|
3132
|
+
gainsFollower: (id) => besideDeletions.tables.after.has(id) || besideDeletions.paragraphsAfter.has(id),
|
|
3133
|
+
intents: deleting
|
|
3134
|
+
})
|
|
3135
|
+
}) : deleting;
|
|
3136
|
+
const joining = operation.type === "mergeBlockWithNext" ? mergeIntentsAsItRuns({
|
|
3137
|
+
document: sourceDocument,
|
|
3138
|
+
story,
|
|
3139
|
+
intents: retracting,
|
|
3140
|
+
mode: batch.mode
|
|
3141
|
+
}) : retracting;
|
|
3142
|
+
if (joining === void 0) return declined({
|
|
3143
|
+
reason: "missingBlock",
|
|
3144
|
+
message: "No paragraph follows the paragraph to join once the batch's deletions are made."
|
|
3145
|
+
});
|
|
3146
|
+
const intents = joining;
|
|
3147
|
+
const livePropertyRefusal = batchPropertyRefusal({
|
|
3148
|
+
document: sourceDocument,
|
|
3149
|
+
story,
|
|
3150
|
+
operation
|
|
3151
|
+
});
|
|
3152
|
+
if (livePropertyRefusal !== void 0) return declined({
|
|
3153
|
+
reason: livePropertyRefusal.reason,
|
|
3154
|
+
message: livePropertyRefusal.message,
|
|
3155
|
+
refusal: livePropertyRefusal.canonicalRefusal
|
|
3156
|
+
});
|
|
3157
|
+
const column = resolvedOperation.plan.address;
|
|
3158
|
+
const columnIntents = column.type === "column" && operation.type === "deleteTableColumn" ? mapColumnDeletionIntents({
|
|
3159
|
+
intents,
|
|
3160
|
+
columnIndex: column.columnIndex,
|
|
3161
|
+
inserted: columnInsertions.get(getTableColumnCoordinateKey(column)) ?? 0,
|
|
3162
|
+
insertedAfter: columnInsertions.get(getTableColumnCoordinateKey({
|
|
3163
|
+
...column,
|
|
3164
|
+
columnIndex: column.columnIndex + 1
|
|
3165
|
+
})) ?? 0
|
|
3166
|
+
}) : intents;
|
|
3167
|
+
const mappedIntents = tableIntentsAsItRuns({
|
|
3168
|
+
document: sourceDocument,
|
|
3169
|
+
story,
|
|
3170
|
+
projection: projected.value,
|
|
3171
|
+
plan: resolvedOperation.plan,
|
|
3172
|
+
intents: columnIntents
|
|
3173
|
+
});
|
|
3174
|
+
const headings = options.undefinedReferences === "keep" ? sourceDocument.package.styles : headingStyles(sourceDocument.package.styles, operation);
|
|
3175
|
+
const withHeadings = headings === void 0 || headings === sourceDocument.package.styles ? sourceDocument : {
|
|
3176
|
+
...sourceDocument,
|
|
3177
|
+
package: {
|
|
3178
|
+
...sourceDocument.package,
|
|
3179
|
+
styles: headings
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
const compiled = compilePublicIntents({
|
|
3183
|
+
document: withHeadings,
|
|
3184
|
+
intents: mappedIntents,
|
|
3185
|
+
allocate,
|
|
3186
|
+
reservedBlockIds,
|
|
3187
|
+
idLease,
|
|
3188
|
+
...paragraphAllocationLease === void 0 ? {} : { paragraphAllocationLease },
|
|
3189
|
+
nextRevisionId: firstRevisionId,
|
|
3190
|
+
mode: batch.mode === "direct" ? "direct" : "tracked-changes",
|
|
3191
|
+
suggestionId,
|
|
3192
|
+
author: options.author ?? "AI",
|
|
3193
|
+
date,
|
|
3194
|
+
...allocations === void 0 ? {} : { allocations },
|
|
3195
|
+
...withHeadings === sourceDocument && resolvedOperation.type === "plain" && verifyOperation !== void 0 ? { verifyOperation } : {}
|
|
3196
|
+
});
|
|
3197
|
+
if (compiled.isErr()) return declined(compilerRefusalSkip(compiled.error));
|
|
3198
|
+
let nextDocument = compiled.value.document;
|
|
3199
|
+
const operationOps = [...compiled.value.ops];
|
|
3200
|
+
if (operation.type === "mergeBlockWithNext" && conflictsWithRevision !== void 0) {
|
|
3201
|
+
if (overwritesForeignMergeFormatting({
|
|
3202
|
+
before: sourceDocument,
|
|
3203
|
+
after: nextDocument,
|
|
3204
|
+
story,
|
|
3205
|
+
ops: operationOps,
|
|
3206
|
+
author: options.author ?? "AI"
|
|
3207
|
+
})) return declined({
|
|
3208
|
+
reason: "existingRevisionConflict",
|
|
3209
|
+
message: EXISTING_REVISION_CONFLICT_MESSAGE
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
let commentId;
|
|
3213
|
+
let commentAllocation;
|
|
3214
|
+
const commentLease = session.idLease === void 0 ? void 0 : idLease;
|
|
3215
|
+
switch (resolvedOperation.type) {
|
|
3216
|
+
case "plain": break;
|
|
3217
|
+
case "commented": {
|
|
3218
|
+
const { comment } = resolvedOperation;
|
|
3219
|
+
const id = admittedComment === void 0 ? freshCommentId(nextDocument, commentLease) : Result.ok(admittedComment.id);
|
|
3220
|
+
const proposedBy = suggestionId === void 0 ? {} : { suggestionId };
|
|
3221
|
+
if (comment.inserted === true) {
|
|
3222
|
+
const { firstAdded, lastAdded } = insertedCommentRange({
|
|
3223
|
+
before: sourceDocument,
|
|
3224
|
+
after: nextDocument,
|
|
3225
|
+
story,
|
|
3226
|
+
ops: compiled.value.ops
|
|
3227
|
+
});
|
|
3228
|
+
const commentContent = admittedComment?.content ?? canonicalCommentBody(nextDocument, comment.text, commentLease);
|
|
3229
|
+
const commented = id.isErr() || firstAdded?.paraId === void 0 || lastAdded?.paraId === void 0 ? void 0 : compileCanonicalComments({
|
|
3230
|
+
document: nextDocument,
|
|
3231
|
+
idLease,
|
|
3232
|
+
command: {
|
|
3233
|
+
type: "create",
|
|
3234
|
+
comment: {
|
|
3235
|
+
id: id.value,
|
|
3236
|
+
author: options.author ?? "AI",
|
|
3237
|
+
date,
|
|
3238
|
+
done: false,
|
|
3239
|
+
content: commentContent,
|
|
3240
|
+
...proposedBy
|
|
3241
|
+
},
|
|
3242
|
+
anchor: {
|
|
3243
|
+
kind: "range",
|
|
3244
|
+
from: {
|
|
3245
|
+
story,
|
|
3246
|
+
blockId: firstAdded.paraId,
|
|
3247
|
+
offset: 0
|
|
3248
|
+
},
|
|
3249
|
+
to: {
|
|
3250
|
+
story,
|
|
3251
|
+
blockId: lastAdded.paraId,
|
|
3252
|
+
offset: paragraphLength(lastAdded)
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
});
|
|
3257
|
+
if (commented === void 0 || commented.isErr() || id.isErr()) return declined({
|
|
3258
|
+
reason: "unsupportedBlock",
|
|
3259
|
+
message: commented?.isErr() === true ? commented.error.message : "The inserted paragraphs cannot carry the comment.",
|
|
3260
|
+
refusal: { gap: CANONICAL_GAP.publicComments }
|
|
3261
|
+
});
|
|
3262
|
+
nextDocument = commented.value.document;
|
|
3263
|
+
operationOps.push(...commented.value.ops);
|
|
3264
|
+
commentId = id.value;
|
|
3265
|
+
commentAllocation = {
|
|
3266
|
+
id: id.value,
|
|
3267
|
+
content: commentContent
|
|
3268
|
+
};
|
|
3269
|
+
break;
|
|
3270
|
+
}
|
|
3271
|
+
const anchorIn = (current) => findCommentAnchorParagraph({
|
|
3272
|
+
document: current,
|
|
3273
|
+
story,
|
|
3274
|
+
blockId: comment.from.blockId
|
|
3275
|
+
});
|
|
3276
|
+
const before = anchorIn(sourceDocument);
|
|
3277
|
+
const after = anchorIn(nextDocument);
|
|
3278
|
+
if (id.isErr() || before === void 0 || after === void 0) return declined({
|
|
3279
|
+
reason: "unsupportedBlock",
|
|
3280
|
+
message: id.isErr() ? id.error.message : "The comment anchor no longer exists.",
|
|
3281
|
+
refusal: { gap: CANONICAL_GAP.publicComments }
|
|
3282
|
+
});
|
|
3283
|
+
const changed = batch.mode === "direct" ? void 0 : revisionSpan(after.content, new Set(compiled.value.revisions));
|
|
3284
|
+
const from = changed === void 0 ? shift(comment.from) : {
|
|
3285
|
+
story: comment.from.story,
|
|
3286
|
+
blockId: comment.from.blockId,
|
|
3287
|
+
offset: changed.from
|
|
3288
|
+
};
|
|
3289
|
+
const to = changed === void 0 ? {
|
|
3290
|
+
...comment.to,
|
|
3291
|
+
offset: shift(comment.to).offset + paragraphLength(after) - paragraphLength(before)
|
|
3292
|
+
} : {
|
|
3293
|
+
story: comment.from.story,
|
|
3294
|
+
blockId: comment.from.blockId,
|
|
3295
|
+
offset: changed.to
|
|
3296
|
+
};
|
|
3297
|
+
const commentContent = admittedComment?.content ?? canonicalCommentBody(nextDocument, comment.text, commentLease);
|
|
3298
|
+
const commented = compileCanonicalComments({
|
|
3299
|
+
document: nextDocument,
|
|
3300
|
+
idLease,
|
|
3301
|
+
command: {
|
|
3302
|
+
type: "create",
|
|
3303
|
+
comment: {
|
|
3304
|
+
id: id.value,
|
|
3305
|
+
author: options.author ?? "AI",
|
|
3306
|
+
date,
|
|
3307
|
+
done: false,
|
|
3308
|
+
content: commentContent,
|
|
3309
|
+
...proposedBy
|
|
3310
|
+
},
|
|
3311
|
+
anchor: to.offset === from.offset ? {
|
|
3312
|
+
kind: "point",
|
|
3313
|
+
at: from
|
|
3314
|
+
} : {
|
|
3315
|
+
kind: "range",
|
|
3316
|
+
from,
|
|
3317
|
+
to
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
if (commented.isErr()) return declined({
|
|
3322
|
+
reason: "unsupportedBlock",
|
|
3323
|
+
message: commented.error.message,
|
|
3324
|
+
refusal: { gap: CANONICAL_GAP.publicComments }
|
|
3325
|
+
});
|
|
3326
|
+
nextDocument = commented.value.document;
|
|
3327
|
+
operationOps.push(...commented.value.ops);
|
|
3328
|
+
commentId = id.value;
|
|
3329
|
+
commentAllocation = {
|
|
3330
|
+
id: id.value,
|
|
3331
|
+
content: commentContent
|
|
3332
|
+
};
|
|
3333
|
+
break;
|
|
3334
|
+
}
|
|
3335
|
+
default: panic(`Unknown resolved operation ${resolvedOperation}`);
|
|
3336
|
+
}
|
|
3337
|
+
if (operationOps.length === 0) return declined({ reason: "noopOperation" });
|
|
3338
|
+
const locked = lockAdmission === CANONICAL_ADMISSION.restage ? null : lockViolationBetween(sourceDocument, nextDocument);
|
|
3339
|
+
if (locked !== null) return declined({
|
|
3340
|
+
reason: CONTENT_CONTROL_LOCK,
|
|
3341
|
+
message: `Refused: ${lockedControlMessage(locked)}`
|
|
3342
|
+
});
|
|
3343
|
+
return {
|
|
3344
|
+
type: "prepared",
|
|
3345
|
+
retiredCommentIds: batch.mode === "direct" ? [] : commentsRetiredBetween(sourceDocument, nextDocument),
|
|
3346
|
+
intents: mappedIntents,
|
|
3347
|
+
document: nextDocument,
|
|
3348
|
+
ops: withHeadings === sourceDocument ? operationOps : [packageResourcesOpOf({
|
|
3349
|
+
before: sourceDocument,
|
|
3350
|
+
after: withHeadings
|
|
3351
|
+
}), ...operationOps],
|
|
3352
|
+
nextRevisionId: Math.max(compiled.value.nextRevisionId, (commentId ?? -1) + 1),
|
|
3353
|
+
revisionIds: [...compiled.value.revisions, ...compiled.value.folded],
|
|
3354
|
+
absorbed: compiled.value.absorbed,
|
|
3355
|
+
commentId,
|
|
3356
|
+
suggestionId,
|
|
3357
|
+
allocations: compiled.value.allocations,
|
|
3358
|
+
commentAllocation,
|
|
3359
|
+
verifiedOperation: compiled.value.verifiedOperation
|
|
3360
|
+
};
|
|
3361
|
+
};
|
|
3362
|
+
const commitOperation = (resolvedOperation, prepared) => {
|
|
3363
|
+
const { operation, normalizations: adjustments } = resolvedOperation;
|
|
3364
|
+
if (prepared.type === "declined") {
|
|
3365
|
+
if (prepared.refusal !== void 0) refusals.set(operation.id, prepared.refusal);
|
|
3366
|
+
skip(operation.id, prepared.reason, prepared.message);
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
const survivorMaps = operation.type === "deleteBlock" ? [survivorOf, deletionSurvivorOf] : [survivorOf];
|
|
3370
|
+
for (const absorption of prepared.absorbed) {
|
|
3371
|
+
const { absorbed, survivor } = absorption;
|
|
3372
|
+
const opens = opensSurvivor({
|
|
3373
|
+
document,
|
|
3374
|
+
story,
|
|
3375
|
+
absorption
|
|
3376
|
+
});
|
|
3377
|
+
for (const survivors of survivorMaps) {
|
|
3378
|
+
for (const [gone, kept] of survivors) if (kept === idKey(absorbed)) survivors.set(gone, idKey(survivor));
|
|
3379
|
+
survivors.set(idKey(absorbed), idKey(survivor));
|
|
3380
|
+
}
|
|
3381
|
+
for (const [gone, kept] of openingSurvivorOf) {
|
|
3382
|
+
if (kept !== idKey(absorbed)) continue;
|
|
3383
|
+
if (opens) openingSurvivorOf.set(gone, idKey(survivor));
|
|
3384
|
+
else openingSurvivorOf.delete(gone);
|
|
3385
|
+
}
|
|
3386
|
+
if (opens) openingSurvivorOf.set(idKey(absorbed), idKey(survivor));
|
|
3387
|
+
}
|
|
3388
|
+
const { commentId, suggestionId, revisionIds, retiredCommentIds } = prepared;
|
|
3389
|
+
normalizations.push(...adjustments);
|
|
3390
|
+
recordColumnInsertion(resolvedOperation, insertedColumnCounts);
|
|
3391
|
+
document = prepared.document;
|
|
3392
|
+
ops.push(...prepared.ops);
|
|
3393
|
+
if (reuseStaging) reuseStaging = prepared.verifiedOperation !== void 0 && operationStaging.append(prepared.verifiedOperation);
|
|
3394
|
+
nextRevisionId = Math.max(nextRevisionId, prepared.nextRevisionId);
|
|
3395
|
+
const revisionId = primaryRevisionId({
|
|
3396
|
+
operation,
|
|
3397
|
+
intents: prepared.intents,
|
|
3398
|
+
document: prepared.document,
|
|
3399
|
+
revisionIds
|
|
3400
|
+
});
|
|
3401
|
+
const joined = batch.mode === "direct" ? joinedParagraphsOf(operation.type, prepared.intents) : void 0;
|
|
3402
|
+
appliedById.set(operation.id, {
|
|
3403
|
+
id: operation.id,
|
|
3404
|
+
...commentId === void 0 ? {} : { commentId },
|
|
3405
|
+
...joined === void 0 ? {} : { paragraphIdentity: joined },
|
|
3406
|
+
...revisionId === void 0 ? {} : {
|
|
3407
|
+
revisionId,
|
|
3408
|
+
revisionIds
|
|
3409
|
+
},
|
|
3410
|
+
...suggestionId === void 0 ? {} : { suggestionId },
|
|
3411
|
+
...retiredCommentIds.length === 0 ? {} : { retiredCommentIds }
|
|
3412
|
+
});
|
|
3413
|
+
};
|
|
3414
|
+
const inputOrder = new Map(batch.operations.map(({ id }, index) => [id, index]));
|
|
3415
|
+
const batchRemovedBlockIds = new Set(batch.mode === "direct" ? resolved.flatMap(({ operation }) => operation.type === "deleteBlock" ? [operation.blockId] : []) : []);
|
|
3416
|
+
const orderOf = ({ operation }) => {
|
|
3417
|
+
const order = inputOrder.get(operation.id);
|
|
3418
|
+
if (order === void 0) panic("A resolved insertion lost its batch order.");
|
|
3419
|
+
return order;
|
|
3420
|
+
};
|
|
3421
|
+
/**
|
|
3422
|
+
* Where an insertion stands among those at its gap: in batch order, but a
|
|
3423
|
+
* paragraph put before one the direct batch deletes, placed after it
|
|
3424
|
+
* instead (`besideDeletion`), still goes ahead of the blocks put after it.
|
|
3425
|
+
*/
|
|
3426
|
+
const placementOrderOf = (member) => member.besideDeletion === true && member.operation.type === "insertAfterBlock" ? orderOf(member) - batch.operations.length : orderOf(member);
|
|
3427
|
+
const gaps = /* @__PURE__ */ new Map();
|
|
3428
|
+
for (const member of executionOrder) {
|
|
3429
|
+
if (!placesBlock(member.operation)) continue;
|
|
3430
|
+
const place = canonicalInsertionGap({
|
|
3431
|
+
operation: member.operation,
|
|
3432
|
+
intents: member.intents,
|
|
3433
|
+
projection: projected.value
|
|
3434
|
+
});
|
|
3435
|
+
if (place === void 0) panic("A resolved block insertion lost its placement.");
|
|
3436
|
+
const members = gaps.get(place.gap) ?? [];
|
|
3437
|
+
members.push(member);
|
|
3438
|
+
gaps.set(place.gap, members);
|
|
3439
|
+
}
|
|
3440
|
+
const indices = new Map(executionOrder.map((member, index) => [member, index]));
|
|
3441
|
+
const intervals = [];
|
|
3442
|
+
const groupOf = /* @__PURE__ */ new Map();
|
|
3443
|
+
for (const members of gaps.values()) {
|
|
3444
|
+
if (members.length < 2) continue;
|
|
3445
|
+
const first = members.at(0), last = members.at(-1);
|
|
3446
|
+
const from = first === void 0 ? void 0 : indices.get(first);
|
|
3447
|
+
const to = last === void 0 ? void 0 : indices.get(last);
|
|
3448
|
+
if (from === void 0 || to === void 0) panic("An insertion group lost its execution interval.");
|
|
3449
|
+
intervals.push({
|
|
3450
|
+
first: from,
|
|
3451
|
+
last: to
|
|
3452
|
+
});
|
|
3453
|
+
for (const member of members) groupOf.set(member, members);
|
|
3454
|
+
}
|
|
3455
|
+
const merged = [];
|
|
3456
|
+
for (const interval of intervals.toSorted((left, right) => left.first - right.first)) {
|
|
3457
|
+
const previous = merged.at(-1);
|
|
3458
|
+
if (previous !== void 0 && interval.first <= previous.last) previous.last = Math.max(previous.last, interval.last);
|
|
3459
|
+
else merged.push({ ...interval });
|
|
3460
|
+
}
|
|
3461
|
+
const alreadyInReplayOrder = (window) => {
|
|
3462
|
+
const first = window.at(0);
|
|
3463
|
+
const initial = first?.intents.at(0);
|
|
3464
|
+
if (first === void 0 || initial?.type !== "insertParagraphs" || initial.at.type !== "before" && initial.at.type !== "after") return false;
|
|
3465
|
+
const group = groupOf.get(first);
|
|
3466
|
+
if (group?.length !== window.length) return false;
|
|
3467
|
+
const { type: side, blockId } = initial.at;
|
|
3468
|
+
const { at: replayAt } = gapAnchorBeforeFollower({
|
|
3469
|
+
anchor: {
|
|
3470
|
+
type: "paragraph",
|
|
3471
|
+
at: initial.at
|
|
3472
|
+
},
|
|
3473
|
+
projection: projected.value,
|
|
3474
|
+
removedBlockIds: batchRemovedBlockIds
|
|
3475
|
+
});
|
|
3476
|
+
if (replayAt.type !== side || replayAt.blockId !== blockId) return false;
|
|
3477
|
+
let previousOrder;
|
|
3478
|
+
for (const member of window) {
|
|
3479
|
+
const { operation, intents } = member;
|
|
3480
|
+
const intent = intents.at(0);
|
|
3481
|
+
if (groupOf.get(member) !== group || member.type !== "plain" || !isBlockInsertion(operation) || operation.moveId !== void 0 || intents.length !== 1 || intent?.type !== "insertParagraphs" || intent.move !== void 0 || intent.newList !== void 0 || intent.at.type !== side || intent.at.blockId !== blockId) return false;
|
|
3482
|
+
const order = placementOrderOf(member);
|
|
3483
|
+
if (previousOrder !== void 0 && (side === "before" ? order <= previousOrder : order >= previousOrder)) return false;
|
|
3484
|
+
previousOrder = order;
|
|
3485
|
+
}
|
|
3486
|
+
return true;
|
|
3487
|
+
};
|
|
3488
|
+
const windows = /* @__PURE__ */ new Map();
|
|
3489
|
+
for (const interval of merged) {
|
|
3490
|
+
const first = executionOrder.at(interval.first);
|
|
3491
|
+
if (first === void 0) panic("An insertion admission window lost its first operation.");
|
|
3492
|
+
const window = executionOrder.slice(interval.first, interval.last + 1);
|
|
3493
|
+
if (batchLease === void 0 && batch.mode !== "suggested" && alreadyInReplayOrder(window)) continue;
|
|
3494
|
+
windows.set(first, window);
|
|
3495
|
+
}
|
|
3496
|
+
const completed = /* @__PURE__ */ new Set();
|
|
3497
|
+
for (const resolvedOperation of executionOrder) {
|
|
3498
|
+
if (completed.has(resolvedOperation.operation.id)) continue;
|
|
3499
|
+
if (resolvedOperation.plan.address.type !== "annotation") annotated ??= document;
|
|
3500
|
+
const window = windows.get(resolvedOperation);
|
|
3501
|
+
if (window === void 0) {
|
|
3502
|
+
commitOperation(resolvedOperation, prepareOperation({
|
|
3503
|
+
document,
|
|
3504
|
+
resolvedOperation,
|
|
3505
|
+
nextRevisionId,
|
|
3506
|
+
columnInsertions: insertedColumnCounts,
|
|
3507
|
+
...reuseStaging ? { verifyOperation: operationStaging.apply } : {}
|
|
3508
|
+
}));
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
const admitted = [];
|
|
3512
|
+
const declinedMembers = [];
|
|
3513
|
+
const admissionColumns = new Map(insertedColumnCounts);
|
|
3514
|
+
let admissionDocument = document;
|
|
3515
|
+
let admissionRevisionId = nextRevisionId;
|
|
3516
|
+
let admissionCensus = batchLease === void 0 ? {
|
|
3517
|
+
type: "paragraphs",
|
|
3518
|
+
ids: void 0
|
|
3519
|
+
} : { type: "package" };
|
|
3520
|
+
const rejectParagraphWindow = () => {
|
|
3521
|
+
if (batchLease !== void 0) return "lease";
|
|
3522
|
+
if (batch.mode === "suggested") return "suggestion";
|
|
3523
|
+
if (!window.every(isPlainInsertion)) return "windowShape";
|
|
3524
|
+
};
|
|
3525
|
+
const paragraphWindowRejection = rejectParagraphWindow();
|
|
3526
|
+
const cursor = startParagraphAdmissionCursor(paragraphWindowRejection);
|
|
3527
|
+
for (const member of window) {
|
|
3528
|
+
completed.add(member.operation.id);
|
|
3529
|
+
const admissionOptions = {
|
|
3530
|
+
document: admissionDocument,
|
|
3531
|
+
columnInsertions: admissionColumns,
|
|
3532
|
+
resolvedOperation: member,
|
|
3533
|
+
nextRevisionId: admissionRevisionId
|
|
3534
|
+
};
|
|
3535
|
+
const nextLease = cursor.nextLease();
|
|
3536
|
+
let prepared = prepareOperation({
|
|
3537
|
+
...admissionOptions,
|
|
3538
|
+
...nextLease.type === "bounded" ? { paragraphAllocationLease: nextLease.lease } : {}
|
|
3539
|
+
});
|
|
3540
|
+
if (nextLease.type === "bounded" && prepared.type === "declined") prepared = prepareOperation(admissionOptions);
|
|
3541
|
+
if (prepared.type === "declined") {
|
|
3542
|
+
declinedMembers.push({
|
|
3543
|
+
resolvedOperation: member,
|
|
3544
|
+
prepared
|
|
3545
|
+
});
|
|
3546
|
+
continue;
|
|
3547
|
+
}
|
|
3548
|
+
recordColumnInsertion(member, admissionColumns);
|
|
3549
|
+
const paragraphs = admissionCensus.type === "paragraphs" ? plainInsertedParagraphIds(prepared.ops) : void 0;
|
|
3550
|
+
cursor.commit(paragraphs);
|
|
3551
|
+
let ids;
|
|
3552
|
+
if (admissionCensus.type === "paragraphs" && paragraphs !== void 0) {
|
|
3553
|
+
admissionCensus.ids ??= new Set(leasedIdCensus(admissionDocument).paragraph);
|
|
3554
|
+
ids = [];
|
|
3555
|
+
for (const id of paragraphs) {
|
|
3556
|
+
if (admissionCensus.ids.has(id)) continue;
|
|
3557
|
+
admissionCensus.ids.add(id);
|
|
3558
|
+
ids.push({
|
|
3559
|
+
kind: ID_LEASE_KINDS.PARAGRAPH,
|
|
3560
|
+
id
|
|
3561
|
+
});
|
|
3562
|
+
}
|
|
3563
|
+
} else {
|
|
3564
|
+
ids = introducedDocumentIds({
|
|
3565
|
+
before: admissionDocument,
|
|
3566
|
+
after: prepared.document
|
|
3567
|
+
});
|
|
3568
|
+
admissionCensus = { type: "package" };
|
|
3569
|
+
}
|
|
3570
|
+
admitted.push({
|
|
3571
|
+
resolvedOperation: member,
|
|
3572
|
+
firstRevisionId: admissionRevisionId,
|
|
3573
|
+
allocations: prepared.allocations,
|
|
3574
|
+
ops: prepared.ops,
|
|
3575
|
+
commentAllocation: prepared.commentAllocation,
|
|
3576
|
+
ids
|
|
3577
|
+
});
|
|
3578
|
+
admissionDocument = prepared.document;
|
|
3579
|
+
admissionRevisionId = prepared.nextRevisionId;
|
|
3580
|
+
}
|
|
3581
|
+
const admissionOf = new Map(admitted.map((member) => [member.resolvedOperation, member]));
|
|
3582
|
+
const ordered = [];
|
|
3583
|
+
const scheduled = /* @__PURE__ */ new Set();
|
|
3584
|
+
for (const member of admitted) {
|
|
3585
|
+
if (scheduled.has(member.resolvedOperation)) continue;
|
|
3586
|
+
const group = groupOf.get(member.resolvedOperation);
|
|
3587
|
+
const partners = group === void 0 ? [] : group.flatMap((sourceMember) => {
|
|
3588
|
+
const admission = admissionOf.get(sourceMember);
|
|
3589
|
+
return admission === void 0 ? [] : [admission];
|
|
3590
|
+
});
|
|
3591
|
+
const first = partners.at(0);
|
|
3592
|
+
if (first === void 0 || partners.length === 1) {
|
|
3593
|
+
scheduled.add(member.resolvedOperation);
|
|
3594
|
+
ordered.push({
|
|
3595
|
+
member,
|
|
3596
|
+
operation: member.resolvedOperation
|
|
3597
|
+
});
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
const firstPlace = canonicalInsertionGap({
|
|
3601
|
+
operation: first.resolvedOperation.operation,
|
|
3602
|
+
intents: first.resolvedOperation.intents,
|
|
3603
|
+
projection: projected.value
|
|
3604
|
+
});
|
|
3605
|
+
if (firstPlace === void 0) panic("An admitted insertion lost its source placement.");
|
|
3606
|
+
const anchor = gapAnchorBeforeFollower({
|
|
3607
|
+
anchor: firstPlace.anchor,
|
|
3608
|
+
projection: projected.value,
|
|
3609
|
+
removedBlockIds: batchRemovedBlockIds
|
|
3610
|
+
});
|
|
3611
|
+
const placed = partners.toSorted((left, right) => (placementOrderOf(left.resolvedOperation) - placementOrderOf(right.resolvedOperation)) * (anchor.at.type === "before" ? 1 : -1));
|
|
3612
|
+
for (const [index, partner] of placed.entries()) {
|
|
3613
|
+
scheduled.add(partner.resolvedOperation);
|
|
3614
|
+
ordered.push({
|
|
3615
|
+
member: partner,
|
|
3616
|
+
operation: {
|
|
3617
|
+
...partner.resolvedOperation,
|
|
3618
|
+
intents: placeInsertionIntents({
|
|
3619
|
+
intents: partner.resolvedOperation.intents,
|
|
3620
|
+
anchor,
|
|
3621
|
+
placement: index === 0 ? "first" : "following"
|
|
3622
|
+
})
|
|
3623
|
+
}
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
const paragraphRejection = paragraphWindowRejection ?? (ordered.every(({ operation }) => isPlainInsertion(operation)) ? void 0 : "windowShape");
|
|
3628
|
+
const paragraphReplay = planReplayParagraphIds(paragraphRejection, paragraphRejection === void 0 ? ordered.map(({ member, operation }) => ({
|
|
3629
|
+
id: operation.operation.id,
|
|
3630
|
+
ops: member.ops,
|
|
3631
|
+
ids: member.ids
|
|
3632
|
+
})) : []);
|
|
3633
|
+
for (const declinedMember of declinedMembers) commitOperation(declinedMember.resolvedOperation, declinedMember.prepared);
|
|
3634
|
+
for (const { member, operation: replayOperation } of ordered) {
|
|
3635
|
+
const idLease = batchLease === void 0 ? void 0 : insertionMemberIdLease({
|
|
3636
|
+
lease: batchLease,
|
|
3637
|
+
siblings: admitted.filter((other) => other !== member).map(({ ids }) => ids)
|
|
3638
|
+
});
|
|
3639
|
+
let reservedBlockIds = session.reservedBlockIds;
|
|
3640
|
+
let paragraphAllocationLease;
|
|
3641
|
+
if (paragraphReplay.type === "admitted") {
|
|
3642
|
+
paragraphAllocationLease = paragraphReplay.leases.get(replayOperation.operation.id);
|
|
3643
|
+
if (paragraphAllocationLease === void 0) panic("An admitted insertion lost its paragraph replay lease.");
|
|
3644
|
+
} else {
|
|
3645
|
+
const reserved = new Set(session.reservedBlockIds);
|
|
3646
|
+
for (const other of admitted) {
|
|
3647
|
+
if (other === member) continue;
|
|
3648
|
+
for (const { kind, id } of other.ids) if (kind === "paragraph") reserved.add(formatParaId(id));
|
|
3649
|
+
}
|
|
3650
|
+
const droppedCarrier = droppedInsertionCarrier({
|
|
3651
|
+
admitted: member.resolvedOperation.intents,
|
|
3652
|
+
replayed: replayOperation.intents,
|
|
3653
|
+
ops: member.ops
|
|
3654
|
+
});
|
|
3655
|
+
if (droppedCarrier !== void 0) reserved.add(droppedCarrier);
|
|
3656
|
+
reservedBlockIds = reserved;
|
|
3657
|
+
}
|
|
3658
|
+
const prepared = prepareOperation({
|
|
3659
|
+
document,
|
|
3660
|
+
columnInsertions: insertedColumnCounts,
|
|
3661
|
+
resolvedOperation: replayOperation,
|
|
3662
|
+
nextRevisionId: member.firstRevisionId,
|
|
3663
|
+
reservedBlockIds,
|
|
3664
|
+
...paragraphAllocationLease === void 0 ? {} : { paragraphAllocationLease },
|
|
3665
|
+
allocations: member.allocations,
|
|
3666
|
+
...reuseStaging ? { verifyOperation: operationStaging.apply } : {},
|
|
3667
|
+
...member.commentAllocation === void 0 ? {} : { commentAllocation: member.commentAllocation },
|
|
3668
|
+
...idLease === void 0 ? {} : { idLease }
|
|
3669
|
+
});
|
|
3670
|
+
if (prepared.type === "declined") panic(`Admitted insertion failed when ordered: ${prepared.message}`);
|
|
3671
|
+
commitOperation(replayOperation, prepared);
|
|
3672
|
+
}
|
|
3673
|
+
nextRevisionId = Math.max(nextRevisionId, admissionRevisionId);
|
|
3674
|
+
}
|
|
3675
|
+
const applyingHalves = /* @__PURE__ */ new Map();
|
|
3676
|
+
for (const { operation } of resolved) {
|
|
3677
|
+
const moveId = blockMoveId(operation);
|
|
3678
|
+
if (moveId !== void 0 && appliedById.has(operation.id)) applyingHalves.set(moveId, (applyingHalves.get(moveId) ?? 0) + 1);
|
|
3679
|
+
}
|
|
3680
|
+
const orphaned = new Set([...pairedMoves].filter((moveId) => applyingHalves.get(moveId) === 1));
|
|
3681
|
+
if (orphaned.size > 0) {
|
|
3682
|
+
const orphanedMove = (operation) => {
|
|
3683
|
+
const moveId = blockMoveId(operation);
|
|
3684
|
+
return moveId !== void 0 && orphaned.has(moveId);
|
|
3685
|
+
};
|
|
3686
|
+
const plain = this.apply({
|
|
3687
|
+
...options,
|
|
3688
|
+
batch: {
|
|
3689
|
+
...batch,
|
|
3690
|
+
operations: batch.operations.map((operation) => orphanedMove(operation) ? withoutMove(operation) : operation)
|
|
3691
|
+
}
|
|
3692
|
+
});
|
|
3693
|
+
const appliedIds = new Set(plain.applied.map(({ id }) => id));
|
|
3694
|
+
return {
|
|
3695
|
+
...plain,
|
|
3696
|
+
normalizations: [...plain.normalizations ?? [], ...batch.operations.flatMap((operation) => {
|
|
3697
|
+
const moveId = blockMoveId(operation);
|
|
3698
|
+
return moveId !== void 0 && orphaned.has(moveId) && appliedIds.has(operation.id) ? [{
|
|
3699
|
+
id: operation.id,
|
|
3700
|
+
code: "unpairedMove",
|
|
3701
|
+
moveId
|
|
3702
|
+
}] : [];
|
|
3703
|
+
})]
|
|
3704
|
+
};
|
|
3705
|
+
}
|
|
3706
|
+
if (batch.atomic && skipped.length > 0) {
|
|
3707
|
+
for (const { id } of appliedById.values()) skip(id, "atomicBatchRejected");
|
|
3708
|
+
return result([], null);
|
|
3709
|
+
}
|
|
3710
|
+
if (ops.length === 0) return result([], null);
|
|
3711
|
+
const prepared = projected.value.selectionAt(state).andThen((selection) => reuseStaging ? operationStaging.prepare(state, selection) : operationStaging.prepareOps(state, ops, selection));
|
|
3712
|
+
if (prepared.isErr()) {
|
|
3713
|
+
const noChange = prepared.error.reason === "noChange";
|
|
3714
|
+
for (const { id } of appliedById.values()) {
|
|
3715
|
+
if (!noChange) refusals.set(id, { gap: CANONICAL_GAP.publicUnsupportedInline });
|
|
3716
|
+
skip(id, noChange ? "noopOperation" : "unsupportedBlock", prepared.error.message);
|
|
3717
|
+
}
|
|
3718
|
+
return result([], null);
|
|
3719
|
+
}
|
|
3720
|
+
addJoinedParagraphReceipts({
|
|
3721
|
+
absorptions: prepared.value.touched.absorbed,
|
|
3722
|
+
operations: batch.operations,
|
|
3723
|
+
applied: appliedById
|
|
3724
|
+
});
|
|
3725
|
+
if (batch.mode === "direct") {
|
|
3726
|
+
if (findStoryBody(prepared.value.document, story) === void 0) panic("A committed public operation lost its story.");
|
|
3727
|
+
const finalIds = new Set(paragraphsThroughTextBoxes(prepared.value.document, story).map(({ paragraph }) => paragraph.paraId));
|
|
3728
|
+
for (const operation of batch.operations) {
|
|
3729
|
+
const entry = appliedById.get(operation.id);
|
|
3730
|
+
if (entry === void 0) continue;
|
|
3731
|
+
const identity = entry.paragraphIdentity;
|
|
3732
|
+
if (identity?.type === "joined") {
|
|
3733
|
+
if (finalIds.has(identity.retiredBlockId) && finalIds.has(identity.blockId)) entry.paragraphIdentity = {
|
|
3734
|
+
type: "retained",
|
|
3735
|
+
blockId: identity.blockId
|
|
3736
|
+
};
|
|
3737
|
+
continue;
|
|
3738
|
+
}
|
|
3739
|
+
if (operation.type === "deleteBlock" && finalIds.has(operation.blockId)) entry.paragraphIdentity = {
|
|
3740
|
+
type: "retained",
|
|
3741
|
+
blockId: operation.blockId
|
|
3742
|
+
};
|
|
3743
|
+
}
|
|
3744
|
+
} else if (batch.mode !== "suggested") {
|
|
3745
|
+
const trackedOperations = [...appliedById.values()];
|
|
3746
|
+
const originalDocument = readModel(session.document);
|
|
3747
|
+
const review = createCanonicalBatchReview({
|
|
3748
|
+
story,
|
|
3749
|
+
before: {
|
|
3750
|
+
document: originalDocument,
|
|
3751
|
+
projection: state.doc
|
|
3752
|
+
},
|
|
3753
|
+
after: {
|
|
3754
|
+
document: prepared.value.document,
|
|
3755
|
+
projection: prepared.value.projection.doc
|
|
3756
|
+
}
|
|
3757
|
+
});
|
|
3758
|
+
addRetiredCommentReceipts({
|
|
3759
|
+
before: state,
|
|
3760
|
+
after: prepared.value.projection.doc,
|
|
3761
|
+
applied: trackedOperations,
|
|
3762
|
+
operations: batch.operations.filter((operation) => operation.type !== "deleteBlock" || operation.moveId === void 0 || !pairedMoves.has(operation.moveId)),
|
|
3763
|
+
sourceRanges: new Map(resolved.flatMap(({ operation, deletionSpans }) => deletionSpans === void 0 ? [] : [[operation.id, deletionSpans]])),
|
|
3764
|
+
acceptedCommentIds: review.acceptedCommentIds
|
|
3765
|
+
});
|
|
3766
|
+
const message = canonicalTrackedBatchFidelityError({
|
|
3767
|
+
review,
|
|
3768
|
+
createdCommentIds: new Set(trackedOperations.flatMap(({ commentId }) => commentId === void 0 ? [] : [commentId])),
|
|
3769
|
+
retiredCommentIds: trackedOperations.flatMap(({ retiredCommentIds }) => retiredCommentIds ?? [])
|
|
3770
|
+
});
|
|
3771
|
+
if (message !== null) {
|
|
3772
|
+
for (const { id } of trackedOperations) skip(id, "invalidResult", message);
|
|
3773
|
+
return result([], null, "refused");
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
keepStandingRevisionReceipts({
|
|
3777
|
+
document: prepared.value.document,
|
|
3778
|
+
applied: appliedById
|
|
3779
|
+
});
|
|
3780
|
+
const applied = batch.operations.flatMap(({ id }) => {
|
|
3781
|
+
const entry = appliedById.get(id);
|
|
3782
|
+
if (entry === void 0) return [];
|
|
3783
|
+
return [batch.dryRun ? {
|
|
3784
|
+
id,
|
|
3785
|
+
...entry.paragraphIdentity === void 0 ? {} : { paragraphIdentity: entry.paragraphIdentity },
|
|
3786
|
+
...entry.retiredCommentIds === void 0 ? {} : { retiredCommentIds: entry.retiredCommentIds }
|
|
3787
|
+
} : entry];
|
|
3788
|
+
});
|
|
3789
|
+
if (batch.dryRun) return result(applied, null);
|
|
3790
|
+
const startVersion = session.version;
|
|
3791
|
+
if (!this.options.publish(prepared.value)) {
|
|
3792
|
+
for (const { id } of applied) skip(id, "documentNotEditable");
|
|
3793
|
+
return result([], null);
|
|
3794
|
+
}
|
|
3795
|
+
const handle = {
|
|
3796
|
+
type: "documentOperationUndo",
|
|
3797
|
+
id: `canonical-${this.handleNamespace}-${String(this.nextHandle++)}`
|
|
3798
|
+
};
|
|
3799
|
+
this.handles.push({
|
|
3800
|
+
handle,
|
|
3801
|
+
version: session.version,
|
|
3802
|
+
startVersion,
|
|
3803
|
+
story
|
|
3804
|
+
});
|
|
3805
|
+
const excess = this.handles.length - this.options.undoLimit;
|
|
3806
|
+
if (excess > 0) this.handles.splice(0, excess);
|
|
3807
|
+
return result(applied, handle);
|
|
3808
|
+
}
|
|
3809
|
+
undo(handle) {
|
|
3810
|
+
const index = this.handles.findIndex(({ handle: existing }) => existing.id === handle.id && existing.type === handle.type);
|
|
3811
|
+
if (index < 0) return {
|
|
3812
|
+
status: "rejected",
|
|
3813
|
+
undoHandle: handle,
|
|
3814
|
+
reason: "unknownHandle"
|
|
3815
|
+
};
|
|
3816
|
+
if (index !== this.handles.length - 1) return {
|
|
3817
|
+
status: "rejected",
|
|
3818
|
+
undoHandle: handle,
|
|
3819
|
+
reason: "notLatest"
|
|
3820
|
+
};
|
|
3821
|
+
const entry = this.handles.at(-1);
|
|
3822
|
+
const { session } = this.options;
|
|
3823
|
+
if (!entry || entry.version !== session.version) return {
|
|
3824
|
+
status: "rejected",
|
|
3825
|
+
undoHandle: handle,
|
|
3826
|
+
reason: "documentChanged"
|
|
3827
|
+
};
|
|
3828
|
+
const state = this.options.getState(entry.story);
|
|
3829
|
+
if (!state) return {
|
|
3830
|
+
status: "rejected",
|
|
3831
|
+
undoHandle: handle,
|
|
3832
|
+
reason: "storyUnavailable"
|
|
3833
|
+
};
|
|
3834
|
+
const prepared = session.prepareUndo(state, entry.story);
|
|
3835
|
+
if (prepared.isErr()) return {
|
|
3836
|
+
status: "rejected",
|
|
3837
|
+
undoHandle: handle,
|
|
3838
|
+
reason: "inverseRefused",
|
|
3839
|
+
message: prepared.error.message
|
|
3840
|
+
};
|
|
3841
|
+
if (!this.options.publish(prepared.value)) return {
|
|
3842
|
+
status: "rejected",
|
|
3843
|
+
undoHandle: handle,
|
|
3844
|
+
reason: "documentNotEditable"
|
|
3845
|
+
};
|
|
3846
|
+
this.handles.pop();
|
|
3847
|
+
const previous = this.handles.at(-1);
|
|
3848
|
+
if (previous && previous.version === entry.startVersion) previous.version = session.version;
|
|
3849
|
+
return {
|
|
3850
|
+
status: "undone",
|
|
3851
|
+
undoHandle: handle
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
/**
|
|
3855
|
+
* A whole paragraph removed as the editor removes a selection of it with
|
|
3856
|
+
* its paragraph mark: from its start to the start of the paragraph after
|
|
3857
|
+
* it, or, for the paragraph that ends its block list, from the end of the
|
|
3858
|
+
* paragraph before it, whose mark then ends the list. Tracked, the text and
|
|
3859
|
+
* the mark are marked deleted.
|
|
3860
|
+
*/
|
|
3861
|
+
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, followsInsertedTable, precedesInsertedTable, precedesDeletedTable, previousGainsFollower, tableBeforeGainsFollower, endsOnceAccepted, deletedRun, deletedByBatch, refusal }) {
|
|
3862
|
+
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock");
|
|
3863
|
+
if (tracked && goesWholeOnAcceptance(paragraph.node)) return refusal("noopOperation");
|
|
3864
|
+
const end = paragraph.start + paragraph.node.content.size;
|
|
3865
|
+
const after = doc.resolve(end + 1).nodeAfter;
|
|
3866
|
+
const before = doc.resolve(paragraph.start - 1).nodeBefore;
|
|
3867
|
+
const neighbour = (node) => {
|
|
3868
|
+
const id = node?.attrs["paraId"];
|
|
3869
|
+
return node?.type.name === "paragraph" && typeof id === "string" ? projection.paragraph(id) : void 0;
|
|
3870
|
+
};
|
|
3871
|
+
const next = neighbour(after);
|
|
3872
|
+
const previous = followsInsertedTable ? void 0 : neighbour(before);
|
|
3873
|
+
const commentFrom = projection.addressAt(paragraph.start);
|
|
3874
|
+
const commentTo = projection.addressAt(end);
|
|
3875
|
+
if (commentFrom.isErr() || commentTo.isErr()) return refusal("unsupportedBlock");
|
|
3876
|
+
const tracking = (resolved) => Result.ok(operation.comment === void 0 ? {
|
|
3877
|
+
type: "plain",
|
|
3878
|
+
operation,
|
|
3879
|
+
...resolved
|
|
3880
|
+
} : {
|
|
3881
|
+
type: "commented",
|
|
3882
|
+
operation,
|
|
3883
|
+
comment: {
|
|
3884
|
+
text: operation.comment.text,
|
|
3885
|
+
from: commentFrom.value,
|
|
3886
|
+
to: commentTo.value
|
|
3887
|
+
},
|
|
3888
|
+
...resolved
|
|
3889
|
+
});
|
|
3890
|
+
const keepsTablesApart = after?.type.name === "table" && (before?.type.name === "table" || followsInsertedTable) && !precedesDeletedTable;
|
|
3891
|
+
const joined = deletesJoinedWords ? joinedBefore(doc, paragraph.start - 1) : [];
|
|
3892
|
+
const takesJoinedWords = deletesJoinedWords && !joined.some((id) => deletedByBatch.has(id));
|
|
3893
|
+
const opening = takesJoinedWords ? joined.at(-1) : void 0;
|
|
3894
|
+
const joinedWordsStart = opening === void 0 ? void 0 : projection.paragraph(opening)?.start;
|
|
3895
|
+
let holdsOriginalWords = false;
|
|
3896
|
+
paragraph.node.descendants((node) => {
|
|
3897
|
+
if (node.isText && !node.marks.some(({ type }) => type.name === "insertion" || type.name === "deletion")) holdsOriginalWords = true;
|
|
3898
|
+
});
|
|
3899
|
+
if (tracked && operation.moveId === void 0 && !gainsFollower && (keepsTablesApart || (after?.type.name === "table" || precedesInsertedTable) && isInsertedPPrMark(paragraph.node.attrs["pPrMark"]) && holdsOriginalWords)) {
|
|
3900
|
+
if (paragraph.start === end) return refusal("noopOperation");
|
|
3901
|
+
const start = joinedWordsStart ?? paragraph.start;
|
|
3902
|
+
const from = projection.addressAt(start);
|
|
3903
|
+
const to = projection.addressAt(end);
|
|
3904
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
3905
|
+
return tracking({
|
|
3906
|
+
intents: [{
|
|
3907
|
+
type: "replaceText",
|
|
3908
|
+
from: from.value,
|
|
3909
|
+
to: to.value,
|
|
3910
|
+
text: ""
|
|
3911
|
+
}],
|
|
3912
|
+
normalizations: [],
|
|
3913
|
+
from: start,
|
|
3914
|
+
to: end
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3917
|
+
const keepsSectionBreakBeforeBlock = tracked && after !== null && after.type.name !== "paragraph" && paragraph.node.attrs["_sectionProperties"] != null && previous !== void 0 && previous.node.attrs["_sectionProperties"] == null && operation.moveId === void 0 && !gainsFollower && !previousGainsFollower && noDeletedRunBefore(deletedRun);
|
|
3918
|
+
const deletesFinalJoin = after === null && takesJoinedWords && previous?.source.pPrMark?.kind === "del" && !isDeletedPPrMark(paragraph.node.attrs["pPrMark"]) && !previousGainsFollower && noDeletedRunBefore(deletedRun);
|
|
3919
|
+
if (!keepsSectionBreakBeforeBlock && (next !== void 0 || gainsFollower || deletesFinalJoin || tracked && (after !== null || operation.moveId !== void 0))) {
|
|
3920
|
+
const intents = [{
|
|
3921
|
+
type: "deleteParagraphs",
|
|
3922
|
+
story: projectionStory,
|
|
3923
|
+
blockIds: [paragraph.blockId],
|
|
3924
|
+
...takesJoinedWords ? { joinedWords: "deleted" } : {}
|
|
3925
|
+
}];
|
|
3926
|
+
const retiresBefore = tracked && (operation.moveId !== void 0 && next === void 0 && after === null || endsOnceAccepted) && !gainsFollower && previous !== void 0;
|
|
3927
|
+
const retiresRun = retiresBefore && !noDeletedRunBefore(deletedRun);
|
|
3928
|
+
let from = paragraph.start;
|
|
3929
|
+
if (retiresRun) from = deletedRun.type === "bounded" ? deletedRun.claimFrom : previous.start;
|
|
3930
|
+
else if (retiresBefore && endsOnceAccepted && previousGainsFollower) from = previous.start;
|
|
3931
|
+
const runCarrier = retiresRun && (deletedRun.type === "kept" || deletedRun.type === "runStart") ? deletedRun.type : void 0;
|
|
3932
|
+
return tracking({
|
|
3933
|
+
intents,
|
|
3934
|
+
normalizations: [],
|
|
3935
|
+
from,
|
|
3936
|
+
to: end,
|
|
3937
|
+
...runCarrier === void 0 ? {} : { retiresRunBreak: runCarrier },
|
|
3938
|
+
...after === null && !gainsFollower ? {} : { removesParagraphBeforeBlock: true },
|
|
3939
|
+
...!tracked && next !== void 0 && !gainsFollower ? { mayEndContainer: true } : {}
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
let range;
|
|
3943
|
+
if (!tracked) {
|
|
3944
|
+
if (after !== null && !followsInsertedTable && (before === null || (before.type.name === "paragraph" || precedesDeletedTable) && paragraph.node.attrs["_sectionProperties"] == null)) return tracking({
|
|
3945
|
+
intents: [{
|
|
3946
|
+
type: "deleteParagraphs",
|
|
3947
|
+
story: projectionStory,
|
|
3948
|
+
blockIds: [paragraph.blockId]
|
|
3949
|
+
}],
|
|
3950
|
+
normalizations: [],
|
|
3951
|
+
from: paragraph.start,
|
|
3952
|
+
to: end,
|
|
3953
|
+
removesParagraphBeforeBlock: true
|
|
3954
|
+
});
|
|
3955
|
+
const own = (from, to) => {
|
|
3956
|
+
const start = projection.addressAt(from);
|
|
3957
|
+
const stop = projection.addressAt(to);
|
|
3958
|
+
return start.isErr() || stop.isErr() ? refusal("unsupportedBlock") : Result.ok(from === to ? [] : [{
|
|
3959
|
+
type: "replaceText",
|
|
3960
|
+
from: start.value,
|
|
3961
|
+
to: stop.value,
|
|
3962
|
+
text: ""
|
|
3963
|
+
}]);
|
|
3964
|
+
};
|
|
3965
|
+
if (previous === void 0 && after === null && tableBeforeGainsFollower) return tracking({
|
|
3966
|
+
intents: [{
|
|
3967
|
+
type: "deleteParagraphs",
|
|
3968
|
+
story: projectionStory,
|
|
3969
|
+
blockIds: [paragraph.blockId]
|
|
3970
|
+
}],
|
|
3971
|
+
normalizations: [],
|
|
3972
|
+
from: paragraph.start,
|
|
3973
|
+
to: end,
|
|
3974
|
+
mayEndContainer: true,
|
|
3975
|
+
followsTableInsertion: true
|
|
3976
|
+
});
|
|
3977
|
+
const cleared = own(paragraph.start, end);
|
|
3978
|
+
if (cleared.isErr()) return cleared;
|
|
3979
|
+
const intents = [...cleared.value];
|
|
3980
|
+
const collapsesRunStart = previous !== void 0 && deletedRun.type === "runStart";
|
|
3981
|
+
if (previous !== void 0) intents.push({
|
|
3982
|
+
type: "joinParagraphs",
|
|
3983
|
+
story: projectionStory,
|
|
3984
|
+
blockId: previous.blockId,
|
|
3985
|
+
nextBlockId: paragraph.blockId,
|
|
3986
|
+
survivor: collapsesRunStart ? SPLIT_HALVES.FIRST : directJoinSurvivor({ laterMarkRemains: after === null || paragraph.node.attrs["_sectionProperties"] != null })
|
|
3987
|
+
});
|
|
3988
|
+
if (intents.length === 0) return refusal("noopOperation");
|
|
3989
|
+
let joinOrder = {};
|
|
3990
|
+
if (collapsesRunStart) joinOrder = { collapsesRunStart: true };
|
|
3991
|
+
else if (previous !== void 0 && previousGainsFollower) joinOrder = { joinsParagraphBefore: true };
|
|
3992
|
+
return Result.ok({
|
|
3993
|
+
type: "plain",
|
|
3994
|
+
operation,
|
|
3995
|
+
intents,
|
|
3996
|
+
normalizations: [],
|
|
3997
|
+
from: previous === void 0 ? paragraph.start : previous.start,
|
|
3998
|
+
to: end,
|
|
3999
|
+
...joinOrder
|
|
4000
|
+
});
|
|
4001
|
+
} else if (previous !== void 0 && deletedRun.type === "bounded") return tracking({
|
|
4002
|
+
intents: [{
|
|
4003
|
+
type: "deleteParagraphs",
|
|
4004
|
+
story: projectionStory,
|
|
4005
|
+
blockIds: [paragraph.blockId]
|
|
4006
|
+
}],
|
|
4007
|
+
normalizations: [],
|
|
4008
|
+
from: deletedRun.claimFrom,
|
|
4009
|
+
to: end
|
|
4010
|
+
});
|
|
4011
|
+
else if (previous !== void 0 && (deletedRun.type === "kept" || deletedRun.type === "runStart")) return tracking({
|
|
4012
|
+
intents: [{
|
|
4013
|
+
type: "deleteParagraphs",
|
|
4014
|
+
story: projectionStory,
|
|
4015
|
+
blockIds: [paragraph.blockId]
|
|
4016
|
+
}],
|
|
4017
|
+
normalizations: [],
|
|
4018
|
+
from: previous.start,
|
|
4019
|
+
to: end,
|
|
4020
|
+
retiresRunBreak: deletedRun.type
|
|
4021
|
+
});
|
|
4022
|
+
else if (previous !== void 0) {
|
|
4023
|
+
let retiring = previous;
|
|
4024
|
+
for (;;) {
|
|
4025
|
+
if (!isDeletedPPrMark(retiring.node.attrs["pPrMark"]) || holdsStandingContent(retiring.node)) break;
|
|
4026
|
+
const earlier = neighbour(doc.resolve(retiring.start - 1).nodeBefore);
|
|
4027
|
+
if (earlier === void 0) break;
|
|
4028
|
+
retiring = earlier;
|
|
4029
|
+
}
|
|
4030
|
+
if (retiring !== previous) return tracking({
|
|
4031
|
+
intents: [{
|
|
4032
|
+
type: "deleteParagraphs",
|
|
4033
|
+
story: projectionStory,
|
|
4034
|
+
blockIds: [paragraph.blockId]
|
|
4035
|
+
}],
|
|
4036
|
+
normalizations: [],
|
|
4037
|
+
from: retiring.start,
|
|
4038
|
+
to: end
|
|
4039
|
+
});
|
|
4040
|
+
range = {
|
|
4041
|
+
from: previous.start + previous.node.content.size,
|
|
4042
|
+
to: end
|
|
4043
|
+
};
|
|
4044
|
+
if (previousGainsFollower && noDeletedRunBefore(deletedRun)) {
|
|
4045
|
+
const from = projection.addressAt(range.from);
|
|
4046
|
+
const to = projection.addressAt(end);
|
|
4047
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4048
|
+
return tracking({
|
|
4049
|
+
intents: [{
|
|
4050
|
+
type: "replaceText",
|
|
4051
|
+
from: from.value,
|
|
4052
|
+
to: to.value,
|
|
4053
|
+
text: ""
|
|
4054
|
+
}],
|
|
4055
|
+
normalizations: [],
|
|
4056
|
+
from: previous.start,
|
|
4057
|
+
to: end,
|
|
4058
|
+
retiresBreakBefore: true
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
} else {
|
|
4062
|
+
if (after === null && tableBeforeGainsFollower) {
|
|
4063
|
+
const from = projection.addressAt(paragraph.start);
|
|
4064
|
+
const to = projection.addressAt(end);
|
|
4065
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4066
|
+
return tracking({
|
|
4067
|
+
intents: [{
|
|
4068
|
+
type: "replaceText",
|
|
4069
|
+
from: from.value,
|
|
4070
|
+
to: to.value,
|
|
4071
|
+
text: ""
|
|
4072
|
+
}],
|
|
4073
|
+
normalizations: [],
|
|
4074
|
+
from: paragraph.start,
|
|
4075
|
+
to: end,
|
|
4076
|
+
retiresBreakBefore: true,
|
|
4077
|
+
followsTableInsertion: true
|
|
4078
|
+
});
|
|
4079
|
+
}
|
|
4080
|
+
if (paragraph.node.content.size === 0) return refusal("noopOperation");
|
|
4081
|
+
range = {
|
|
4082
|
+
from: paragraph.start,
|
|
4083
|
+
to: end
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
const from = projection.addressAt(range.from);
|
|
4087
|
+
const to = projection.addressAt(range.to);
|
|
4088
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4089
|
+
return tracking({
|
|
4090
|
+
intents: [{
|
|
4091
|
+
type: "replaceText",
|
|
4092
|
+
from: from.value,
|
|
4093
|
+
to: to.value,
|
|
4094
|
+
text: ""
|
|
4095
|
+
}],
|
|
4096
|
+
normalizations: [],
|
|
4097
|
+
from: Math.min(range.from, paragraph.start),
|
|
4098
|
+
to: Math.max(range.to, end)
|
|
4099
|
+
});
|
|
4100
|
+
}
|
|
4101
|
+
/**
|
|
4102
|
+
* An operation resolved against its story. One naming the filler of a
|
|
4103
|
+
* block the source leaves empty is first restated beside that block.
|
|
4104
|
+
*/
|
|
4105
|
+
resolve(options) {
|
|
4106
|
+
const restated = this.restatedBesideEmptyControl(options);
|
|
4107
|
+
if (restated.isErr()) return Result.err(restated.error);
|
|
4108
|
+
const { operation, listStart } = restated.value;
|
|
4109
|
+
return this.resolveOperation({
|
|
4110
|
+
...options,
|
|
4111
|
+
operation,
|
|
4112
|
+
...listStart === void 0 ? {} : { listStart }
|
|
4113
|
+
});
|
|
4114
|
+
}
|
|
4115
|
+
/**
|
|
4116
|
+
* `operation`, or, where it names the filler of a block the source leaves
|
|
4117
|
+
* empty (`emptyControlOfFiller`), the same insertion beside that block,
|
|
4118
|
+
* with the start of its list where that is where it goes; any other
|
|
4119
|
+
* operation on the filler is refused, as is one whose precondition the
|
|
4120
|
+
* filler, which holds no words, does not meet.
|
|
4121
|
+
*/
|
|
4122
|
+
restatedBesideEmptyControl({ operation, options, state, story }) {
|
|
4123
|
+
const blockId = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range.blockId : operation.blockId;
|
|
4124
|
+
const anchor = Object.hasOwn(options.snapshot.anchors, blockId) ? options.snapshot.anchors[blockId] : void 0;
|
|
4125
|
+
const projection = this.options.session.projectStory(story);
|
|
4126
|
+
if (anchor === void 0 || projection.isErr() || projection.value.paragraph(blockId) !== void 0) return Result.ok({ operation });
|
|
4127
|
+
const control = emptyControlOfFiller(state.doc, blockId);
|
|
4128
|
+
if (control === void 0) return Result.ok({ operation });
|
|
4129
|
+
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4130
|
+
reason,
|
|
4131
|
+
message: message ?? `The operation was refused: ${reason}.`,
|
|
4132
|
+
detail: message
|
|
4133
|
+
}));
|
|
4134
|
+
const fillerHash = hashFolioAIBlockContent("");
|
|
4135
|
+
if (operation.precondition && fillerHash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
4136
|
+
if (fillerHash !== anchor.textHash) return refusal("changedBlock");
|
|
4137
|
+
const beside = besideEmptyControl({
|
|
4138
|
+
operation,
|
|
4139
|
+
control,
|
|
4140
|
+
projection: projection.value
|
|
4141
|
+
});
|
|
4142
|
+
switch (beside.type) {
|
|
4143
|
+
case "refused": return refusal("unsupportedBlock", beside.message);
|
|
4144
|
+
case "beside": return Result.ok({ operation: beside.operation });
|
|
4145
|
+
case "listStart": return Result.ok({
|
|
4146
|
+
operation: beside.operation,
|
|
4147
|
+
listStart: beside.listStart
|
|
4148
|
+
});
|
|
4149
|
+
default: return beside;
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
resolveOperation({ operation, listStart, options, state, story, diff, tracked, suggested, mintList, besideDeletions }) {
|
|
4153
|
+
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4154
|
+
reason,
|
|
4155
|
+
message: message ?? `The operation was refused: ${reason}.`,
|
|
4156
|
+
detail: message
|
|
4157
|
+
}));
|
|
4158
|
+
const skipAlike = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4159
|
+
reason,
|
|
4160
|
+
message,
|
|
4161
|
+
detail: message,
|
|
4162
|
+
gap: null
|
|
4163
|
+
}));
|
|
4164
|
+
const skipTracked = (message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4165
|
+
reason: "unsupportedBlock",
|
|
4166
|
+
message,
|
|
4167
|
+
detail: message,
|
|
4168
|
+
gap: null,
|
|
4169
|
+
refusedIn: "trackedMode"
|
|
4170
|
+
}));
|
|
4171
|
+
const notInTable = () => skipAlike("unsupportedBlock", "The block is not in a table.");
|
|
4172
|
+
switch (operation.type) {
|
|
4173
|
+
case "replaceInBlock":
|
|
4174
|
+
case "replaceRange":
|
|
4175
|
+
case "replaceBlock":
|
|
4176
|
+
case "splitBlock":
|
|
4177
|
+
case "formatRange":
|
|
4178
|
+
case "mergeBlockWithNext":
|
|
4179
|
+
case "commentOnRange":
|
|
4180
|
+
case "commentOnBlock":
|
|
4181
|
+
case "deleteBlock":
|
|
4182
|
+
case "setBlockParagraphProperties":
|
|
4183
|
+
case "insertAfterBlock":
|
|
4184
|
+
case "insertBeforeBlock":
|
|
4185
|
+
case "insertTable":
|
|
4186
|
+
case "insertSignatureTable":
|
|
4187
|
+
case "deleteTable":
|
|
4188
|
+
case "insertTableRow":
|
|
4189
|
+
case "deleteTableRow":
|
|
4190
|
+
case "insertTableColumn":
|
|
4191
|
+
case "deleteTableColumn":
|
|
4192
|
+
case "mergeTableCells":
|
|
4193
|
+
case "splitTableCell": break;
|
|
4194
|
+
default: return operation;
|
|
4195
|
+
}
|
|
4196
|
+
const blockId = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range.blockId : operation.blockId;
|
|
4197
|
+
const anchor = Object.hasOwn(options.snapshot.anchors, blockId) ? options.snapshot.anchors[blockId] : void 0;
|
|
4198
|
+
const projection = this.options.session.projectStory(story);
|
|
4199
|
+
if (!anchor || projection.isErr()) return refusal("missingBlock");
|
|
4200
|
+
const paragraph = projection.value.paragraph(blockId);
|
|
4201
|
+
if (!paragraph) return holdsParagraph(state.doc, blockId) ? refusal("unsupportedBlock", "The canonical session holds no address in this paragraph, such as one in a text box.") : refusal("missingBlock");
|
|
4202
|
+
if ((operation.type === "insertTable" || operation.type === "insertSignatureTable") && !supportsTableInsertionMode(operation.type, options.batch.mode ?? "tracked-changes")) return refusal("unsupportedMode");
|
|
4203
|
+
const noteReferences = collectNoteReferenceLabels(state.doc);
|
|
4204
|
+
const clean = buildCleanBlockText(paragraph.node, paragraph.start - 1, {
|
|
4205
|
+
fieldResults: "text",
|
|
4206
|
+
noteReferences
|
|
4207
|
+
});
|
|
4208
|
+
const restyles = operation.type === "replaceBlock" && operation.styleId !== void 0 && operation.styleId !== (paragraph.source.formatting?.styleId ?? null);
|
|
4209
|
+
const pendingRefusal = [pendingMarkEditOf(operation.type), ...restyles ? ["paragraphProperties"] : []].map((edit) => pendingMarkEditRefusal({
|
|
4210
|
+
edit,
|
|
4211
|
+
doc: state.doc,
|
|
4212
|
+
paragraphPos: paragraph.start - 1,
|
|
4213
|
+
paragraph: paragraph.node,
|
|
4214
|
+
cleanText: clean.text
|
|
4215
|
+
})).find((refused) => refused !== void 0);
|
|
4216
|
+
if (pendingRefusal !== void 0) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4217
|
+
reason: pendingRefusal.reason,
|
|
4218
|
+
message: pendingRefusal.message ?? `The operation was refused: ${pendingRefusal.reason}.`,
|
|
4219
|
+
detail: pendingRefusal.message,
|
|
4220
|
+
...pendingRefusal.canonicalRefusal === void 0 ? {} : { gap: pendingRefusal.canonicalRefusal.gap }
|
|
4221
|
+
}));
|
|
4222
|
+
const hash = hashFolioAIBlockContent(clean.text);
|
|
4223
|
+
if (operation.precondition && hash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
4224
|
+
if (hash !== anchor.textHash) return refusal("changedBlock");
|
|
4225
|
+
const followed = state.doc.resolve(paragraph.start + paragraph.node.content.size + 1).nodeAfter?.type.name === "paragraph";
|
|
4226
|
+
if (isTableStructureOperation(operation)) return resolveTableStructure({
|
|
4227
|
+
operation,
|
|
4228
|
+
paragraph,
|
|
4229
|
+
projection: projection.value,
|
|
4230
|
+
story,
|
|
4231
|
+
refusal,
|
|
4232
|
+
tracked,
|
|
4233
|
+
paragraphOf: (id) => Object.hasOwn(options.snapshot.anchors, id) ? projection.value.paragraph(id) : void 0,
|
|
4234
|
+
notInTable,
|
|
4235
|
+
skipAlike,
|
|
4236
|
+
skipTracked,
|
|
4237
|
+
deleted: besideDeletions.deleted,
|
|
4238
|
+
template: options.tableTemplates?.get(operation.id)
|
|
4239
|
+
});
|
|
4240
|
+
if (operation.type === "insertTable" || operation.type === "insertSignatureTable") return resolveTableInsertion({
|
|
4241
|
+
operation,
|
|
4242
|
+
...listStart === void 0 ? {} : { listStart },
|
|
4243
|
+
paragraph,
|
|
4244
|
+
projection: projection.value,
|
|
4245
|
+
story,
|
|
4246
|
+
noteReferences,
|
|
4247
|
+
refusal,
|
|
4248
|
+
skipAlike,
|
|
4249
|
+
template: options.tableTemplates?.get(operation.id)
|
|
4250
|
+
});
|
|
4251
|
+
if (isBlockInsertion(operation) && listStart !== void 0) return resolveBlockInsertion({
|
|
4252
|
+
operation,
|
|
4253
|
+
listStart,
|
|
4254
|
+
paragraph,
|
|
4255
|
+
named: paragraph,
|
|
4256
|
+
formattingSource: paragraph,
|
|
4257
|
+
projection: projection.value,
|
|
4258
|
+
noteReferences,
|
|
4259
|
+
story,
|
|
4260
|
+
mintList,
|
|
4261
|
+
refusal,
|
|
4262
|
+
skipAlike
|
|
4263
|
+
});
|
|
4264
|
+
if (isBlockInsertion(operation)) {
|
|
4265
|
+
const besideDeletion = !tracked && operation.type === "insertBeforeBlock" && !followed && besideDeletions.deleted.has(blockId);
|
|
4266
|
+
const after = state.doc.resolve(paragraph.start - 1 + paragraph.node.nodeSize).nodeAfter;
|
|
4267
|
+
const insertion = besideDeletion && after !== null ? {
|
|
4268
|
+
...operation,
|
|
4269
|
+
type: "insertAfterBlock"
|
|
4270
|
+
} : operation;
|
|
4271
|
+
const placed = insertion.type === "insertAfterBlock" ? placeAfter({
|
|
4272
|
+
paragraph,
|
|
4273
|
+
projection: projection.value,
|
|
4274
|
+
noteReferences
|
|
4275
|
+
}) : besidePendingJoin({
|
|
4276
|
+
side: "before",
|
|
4277
|
+
paragraph,
|
|
4278
|
+
projection: projection.value,
|
|
4279
|
+
noteReferences,
|
|
4280
|
+
paragraphsAfterEarlier: besideDeletions.paragraphsAfterEarlier(operation.id)
|
|
4281
|
+
});
|
|
4282
|
+
const gap = insertion.type === "insertAfterBlock" ? placed.place.start - 1 + placed.place.node.nodeSize : placed.place.start - 1;
|
|
4283
|
+
if (joinStopsAtTableAfter({
|
|
4284
|
+
insertedBlock: "paragraph",
|
|
4285
|
+
doc: projection.value.doc,
|
|
4286
|
+
paragraphPos: gap,
|
|
4287
|
+
noteReferences
|
|
4288
|
+
})) return refusal(PENDING_JOIN_INSERTION_REFUSAL.reason, PENDING_JOIN_INSERTION_REFUSAL.message);
|
|
4289
|
+
const inserted = resolveBlockInsertion({
|
|
4290
|
+
operation: insertion,
|
|
4291
|
+
paragraph: placed.place,
|
|
4292
|
+
named: paragraph,
|
|
4293
|
+
formattingSource: placed.formattingSource,
|
|
4294
|
+
projection: projection.value,
|
|
4295
|
+
noteReferences,
|
|
4296
|
+
story,
|
|
4297
|
+
mintList,
|
|
4298
|
+
refusal,
|
|
4299
|
+
skipAlike
|
|
4300
|
+
});
|
|
4301
|
+
return besideDeletion && inserted.isOk() ? Result.ok({
|
|
4302
|
+
...inserted.value,
|
|
4303
|
+
besideDeletion: true
|
|
4304
|
+
}) : inserted;
|
|
4305
|
+
}
|
|
4306
|
+
if (operation.type === "setBlockParagraphProperties") return resolveParagraphProperties({
|
|
4307
|
+
operation,
|
|
4308
|
+
paragraph,
|
|
4309
|
+
projection: projection.value,
|
|
4310
|
+
mintList,
|
|
4311
|
+
refusal
|
|
4312
|
+
});
|
|
4313
|
+
if (operation.type === "deleteBlock") {
|
|
4314
|
+
const gainsFollower = !followed && besideDeletions.insertedBeside.has(blockId);
|
|
4315
|
+
const before = state.doc.resolve(paragraph.start - 1).nodeBefore;
|
|
4316
|
+
const after = state.doc.resolve(paragraph.start + paragraph.node.content.size + 1).nodeAfter;
|
|
4317
|
+
const endsOnceAccepted = tracked && operation.moveId === void 0 && followersGoOnAcceptance(state.doc, paragraph.start + paragraph.node.content.size + 1);
|
|
4318
|
+
const previousId = before?.type.name === "paragraph" ? before.attrs["paraId"] : void 0;
|
|
4319
|
+
const followsInsertedTable = !followed && (besideDeletions.tables.before.has(blockId) || typeof previousId === "string" && besideDeletions.tables.after.has(previousId));
|
|
4320
|
+
const tableBeforeGainsFollower = !followed && before !== null && before.type.name !== "paragraph" && paragraphIdsIn(before).some((id) => besideDeletions.paragraphsAfter.has(id));
|
|
4321
|
+
const deleted = this.resolveBlockDeletion({
|
|
4322
|
+
operation,
|
|
4323
|
+
paragraph,
|
|
4324
|
+
projection: projection.value,
|
|
4325
|
+
projectionStory: story,
|
|
4326
|
+
doc: state.doc,
|
|
4327
|
+
tracked,
|
|
4328
|
+
deletesJoinedWords: tracked && !suggested,
|
|
4329
|
+
gainsFollower,
|
|
4330
|
+
followsInsertedTable,
|
|
4331
|
+
precedesInsertedTable: besideDeletions.tables.after.has(blockId) && !besideDeletions.paragraphsAfter.has(blockId),
|
|
4332
|
+
precedesDeletedTable: after?.type.name === "table" && tableParagraphIds(after).some((id) => besideDeletions.tables.deleted.has(id)),
|
|
4333
|
+
previousGainsFollower: (!followed || endsOnceAccepted) && typeof previousId === "string" && (besideDeletions.paragraphsAfter.has(previousId) || besideDeletions.deleted.has(previousId)),
|
|
4334
|
+
tableBeforeGainsFollower,
|
|
4335
|
+
endsOnceAccepted,
|
|
4336
|
+
deletedByBatch: besideDeletions.deleted,
|
|
4337
|
+
deletedRun: followed && !endsOnceAccepted ? { type: "none" } : deletedRunBefore({
|
|
4338
|
+
doc: state.doc,
|
|
4339
|
+
paragraphStart: paragraph.start,
|
|
4340
|
+
besideDeletions,
|
|
4341
|
+
tracked
|
|
4342
|
+
}),
|
|
4343
|
+
refusal
|
|
4344
|
+
});
|
|
4345
|
+
return gainsFollower && deleted.isOk() ? Result.ok({
|
|
4346
|
+
...deleted.value,
|
|
4347
|
+
besideDeletion: true
|
|
4348
|
+
}) : deleted;
|
|
4349
|
+
}
|
|
4350
|
+
let start = 0;
|
|
4351
|
+
let end = clean.text.length;
|
|
4352
|
+
let text = "";
|
|
4353
|
+
switch (operation.type) {
|
|
4354
|
+
case "replaceInBlock":
|
|
4355
|
+
if (operation.find === "") return refusal("emptyOperation");
|
|
4356
|
+
start = clean.text.indexOf(operation.find);
|
|
4357
|
+
if (start < 0) return refusal("missingFind");
|
|
4358
|
+
if (clean.text.indexOf(operation.find, start + 1) >= 0) return refusal("ambiguousFind");
|
|
4359
|
+
end = start + operation.find.length;
|
|
4360
|
+
text = operation.replace;
|
|
4361
|
+
break;
|
|
4362
|
+
case "commentOnBlock":
|
|
4363
|
+
if (operation.quote !== void 0) {
|
|
4364
|
+
start = clean.text.indexOf(operation.quote);
|
|
4365
|
+
if (start < 0) return refusal("missingFind");
|
|
4366
|
+
if (clean.text.indexOf(operation.quote, start + 1) >= 0) return refusal("ambiguousFind");
|
|
4367
|
+
end = start + operation.quote.length;
|
|
4368
|
+
}
|
|
4369
|
+
break;
|
|
4370
|
+
case "replaceRange":
|
|
4371
|
+
case "formatRange":
|
|
4372
|
+
case "commentOnRange":
|
|
4373
|
+
start = operation.range.startOffset;
|
|
4374
|
+
end = operation.range.endOffset;
|
|
4375
|
+
if (hashFolioAIBlockText(clean.text.slice(start, end)) !== operation.range.selectedTextHash) return refusal("staleRange");
|
|
4376
|
+
text = operation.type === "replaceRange" ? operation.replace : "";
|
|
4377
|
+
break;
|
|
4378
|
+
case "replaceBlock":
|
|
4379
|
+
text = operation.text;
|
|
4380
|
+
break;
|
|
4381
|
+
case "splitBlock":
|
|
4382
|
+
start = operation.offset;
|
|
4383
|
+
end = start + (operation.separator?.length ?? 0);
|
|
4384
|
+
if (start <= 0 || start >= clean.text.length || clean.text.slice(start, end) !== (operation.separator ?? "")) return refusal("staleRange");
|
|
4385
|
+
break;
|
|
4386
|
+
case "mergeBlockWithNext":
|
|
4387
|
+
if (/[\t\r\n]/u.test(operation.separator ?? "")) return refusal("unsupportedBlock", "Canonical public join separators require plain text.");
|
|
4388
|
+
start = clean.text.length;
|
|
4389
|
+
end = start;
|
|
4390
|
+
break;
|
|
4391
|
+
default: return operation;
|
|
4392
|
+
}
|
|
4393
|
+
const characterSplit = describeCharacterSplit(clean.text, [start, end], ANNOTATING_OPERATION_TYPES.has(operation.type) ? "codePoint" : "grapheme");
|
|
4394
|
+
if (characterSplit !== null) return refusal("splitsCharacter", characterSplit);
|
|
4395
|
+
const replacesText = operation.type === "replaceInBlock" || operation.type === "replaceRange" || operation.type === "replaceBlock";
|
|
4396
|
+
const references = noteReferenceSpansWithin(clean, start, end);
|
|
4397
|
+
if (cutsIntoNoteReference(clean, start, end)) return refusal("protectedReference");
|
|
4398
|
+
const range = resolveCleanTextRange({
|
|
4399
|
+
cleanBlock: clean,
|
|
4400
|
+
startOffset: start,
|
|
4401
|
+
endOffset: end
|
|
4402
|
+
});
|
|
4403
|
+
if (!range) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4404
|
+
reason: "unsupportedBlock",
|
|
4405
|
+
message: "The range begins or ends inside a field result or holds a page-break run.",
|
|
4406
|
+
detail: void 0,
|
|
4407
|
+
gap: null
|
|
4408
|
+
}));
|
|
4409
|
+
const dropsFormatting = operation.type === "replaceBlock" && operation.preserveFormatting === false;
|
|
4410
|
+
if (replacesText && references.length > 0 && (dropsFormatting || stripInlineEmphasisMarkers(text) !== text)) return refusal("protectedReference");
|
|
4411
|
+
if (dropsFormatting) return refusal("unsupportedBlock", "Canonical replacements that drop the paragraph's formatting are unavailable.");
|
|
4412
|
+
const kept = segmentsAroundNoteReferences(clean.text.slice(start, end), replacesText ? text : clean.text.slice(start, end), references);
|
|
4413
|
+
const editsReferences = kept === null && replacesText && noteReferenceEditsAllowed();
|
|
4414
|
+
const segments = editsReferences ? {
|
|
4415
|
+
source: [{
|
|
4416
|
+
offset: 0,
|
|
4417
|
+
text: clean.text.slice(start, end)
|
|
4418
|
+
}],
|
|
4419
|
+
replacement: [text]
|
|
4420
|
+
} : kept;
|
|
4421
|
+
if (segments === null) return refusal("protectedReference");
|
|
4422
|
+
const prose = replacesText ? segments.replacement.join("") : "";
|
|
4423
|
+
if (stripInlineEmphasisMarkers(text) !== text) return refusal("unsupportedBlock", "Canonical public emphasis replacements are unavailable.");
|
|
4424
|
+
if (!editsReferences && /\[\^(?:e)?\d+\]/u.test(prose) || /\r/u.test(prose)) return refusal("unsupportedBlock", "Canonical public replacements require plain text.");
|
|
4425
|
+
const from = projection.value.addressAt(range.from);
|
|
4426
|
+
const to = projection.value.addressAt(range.to);
|
|
4427
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4428
|
+
const resolvedComment = resolveComment({
|
|
4429
|
+
operation,
|
|
4430
|
+
from: from.value,
|
|
4431
|
+
to: to.value
|
|
4432
|
+
});
|
|
4433
|
+
if (operation.type === "commentOnBlock" || operation.type === "commentOnRange") return Result.ok({
|
|
4434
|
+
...resolvedComment,
|
|
4435
|
+
intents: [],
|
|
4436
|
+
normalizations: [],
|
|
4437
|
+
from: range.from,
|
|
4438
|
+
to: range.to
|
|
4439
|
+
});
|
|
4440
|
+
const restyle = restyles && operation.type === "replaceBlock" && operation.styleId !== void 0 ? statedPropertiesIntents({
|
|
4441
|
+
story,
|
|
4442
|
+
blockId: paragraph.blockId,
|
|
4443
|
+
properties: { styleId: operation.styleId },
|
|
4444
|
+
mintList
|
|
4445
|
+
}) : [];
|
|
4446
|
+
if (resolvedComment.type === "plain" && operation.type !== "splitBlock" && operation.type !== "formatRange" && operation.type !== "mergeBlockWithNext" && restyle.length === 0 && clean.text.slice(start, end) === text) return refusal("noopOperation");
|
|
4447
|
+
let intent;
|
|
4448
|
+
switch (operation.type) {
|
|
4449
|
+
case "splitBlock":
|
|
4450
|
+
intent = {
|
|
4451
|
+
type: "splitParagraph",
|
|
4452
|
+
at: from.value,
|
|
4453
|
+
to: to.value,
|
|
4454
|
+
newHalf: "second",
|
|
4455
|
+
newBlockId: createEditorIntentIdAllocator({ reservedBlockIds: this.options.session.reservedBlockIds })(readModel(this.options.session.document), {
|
|
4456
|
+
type: "splitParagraph",
|
|
4457
|
+
at: from.value,
|
|
4458
|
+
to: to.value
|
|
4459
|
+
}, this.options.session.idLease).newBlockId
|
|
4460
|
+
};
|
|
4461
|
+
break;
|
|
4462
|
+
case "mergeBlockWithNext": {
|
|
4463
|
+
const next = projection.value.nextParagraphInContainer(blockId);
|
|
4464
|
+
if (next === void 0) return skipAlike("unsupportedBlock", "The block ends its container; no paragraph follows it there.");
|
|
4465
|
+
intent = {
|
|
4466
|
+
type: "joinParagraphs",
|
|
4467
|
+
story,
|
|
4468
|
+
blockId,
|
|
4469
|
+
nextBlockId: next.blockId,
|
|
4470
|
+
survivor: directJoinSurvivor()
|
|
4471
|
+
};
|
|
4472
|
+
break;
|
|
4473
|
+
}
|
|
4474
|
+
case "formatRange": {
|
|
4475
|
+
const formatting = operation.formatting;
|
|
4476
|
+
const patch = {
|
|
4477
|
+
...formatting.bold === void 0 ? {} : { bold: formatting.bold },
|
|
4478
|
+
...formatting.italic === void 0 ? {} : { italic: formatting.italic },
|
|
4479
|
+
...formatting.underline === void 0 ? {} : { underline: formatting.underline === null ? null : { style: formatting.underline ? "single" : "none" } },
|
|
4480
|
+
...formatting.strike === void 0 ? {} : {
|
|
4481
|
+
strike: formatting.strike,
|
|
4482
|
+
doubleStrike: null
|
|
4483
|
+
},
|
|
4484
|
+
...formatting.fontSizePt === void 0 ? {} : { fontSize: formatting.fontSizePt === null ? null : formatting.fontSizePt * 2 },
|
|
4485
|
+
...formatting.fontFamily === void 0 ? {} : { fontFamily: formatting.fontFamily === null ? null : {
|
|
4486
|
+
ascii: formatting.fontFamily,
|
|
4487
|
+
hAnsi: formatting.fontFamily
|
|
4488
|
+
} },
|
|
4489
|
+
...formatting.highlight === void 0 ? {} : { highlight: formatting.highlight },
|
|
4490
|
+
...formatting.color === void 0 ? {} : { color: formatting.color === null ? null : { rgb: formatting.color.replace(/^#/u, "").toUpperCase() } }
|
|
4491
|
+
};
|
|
4492
|
+
intent = {
|
|
4493
|
+
type: "formatRun",
|
|
4494
|
+
from: from.value,
|
|
4495
|
+
to: to.value,
|
|
4496
|
+
patch
|
|
4497
|
+
};
|
|
4498
|
+
break;
|
|
4499
|
+
}
|
|
4500
|
+
case "replaceInBlock":
|
|
4501
|
+
case "replaceRange":
|
|
4502
|
+
case "replaceBlock":
|
|
4503
|
+
intent = {
|
|
4504
|
+
type: "replaceText",
|
|
4505
|
+
from: from.value,
|
|
4506
|
+
to: to.value,
|
|
4507
|
+
text,
|
|
4508
|
+
...options.replacementBackground === "keep" ? {} : { runPropsPatch: {
|
|
4509
|
+
highlight: null,
|
|
4510
|
+
shading: null
|
|
4511
|
+
} }
|
|
4512
|
+
};
|
|
4513
|
+
break;
|
|
4514
|
+
default: return panic(`Unknown canonical public operation ${operation}`);
|
|
4515
|
+
}
|
|
4516
|
+
const intents = [];
|
|
4517
|
+
const normalizations = [];
|
|
4518
|
+
let deletionSpans;
|
|
4519
|
+
if (intent.type === "replaceText") {
|
|
4520
|
+
const replacementSource = {
|
|
4521
|
+
source: clean.text.slice(start, end),
|
|
4522
|
+
replacement: text,
|
|
4523
|
+
noteReferences: references,
|
|
4524
|
+
editsReferences,
|
|
4525
|
+
fields: clean.structuralBoundaries.flatMap((boundary) => boundary.type === "field" ? [{
|
|
4526
|
+
offset: boundary.offset - start,
|
|
4527
|
+
length: boundary.length
|
|
4528
|
+
}] : [])
|
|
4529
|
+
};
|
|
4530
|
+
let planned = planReplacementChanges({
|
|
4531
|
+
...replacementSource,
|
|
4532
|
+
planChanges: tracked ? (source, target) => changesFromSegments(diff(source, target)) : planTextChanges,
|
|
4533
|
+
...tracked ? { keepFieldsOf: planTextChanges } : {}
|
|
4534
|
+
});
|
|
4535
|
+
if (tracked && planned?.some((change) => clean.offsets.slice(start + change.start, start + change.end).some((position) => paragraph.node.nodeAt(position - paragraph.start)?.marks.some((mark) => mark.type.name === "comment")))) planned = planReplacementChanges({
|
|
4536
|
+
...replacementSource,
|
|
4537
|
+
planChanges: planTextChanges
|
|
4538
|
+
});
|
|
4539
|
+
if (planned === null) return panic("A replacement's planned changes must reproduce it.");
|
|
4540
|
+
const changes = cutAroundRepeatedSeparators(replacementSource.source, planned).map((change) => ({
|
|
4541
|
+
start: start + change.start,
|
|
4542
|
+
end: start + change.end,
|
|
4543
|
+
text: change.text
|
|
4544
|
+
}));
|
|
4545
|
+
const placeChanges = (pieces) => {
|
|
4546
|
+
const placed = [];
|
|
4547
|
+
for (const change of pieces) {
|
|
4548
|
+
const gap = resolveCleanTextRange({
|
|
4549
|
+
cleanBlock: clean,
|
|
4550
|
+
startOffset: change.start,
|
|
4551
|
+
endOffset: change.end
|
|
4552
|
+
});
|
|
4553
|
+
if (!gap) return void 0;
|
|
4554
|
+
const lastCharacter = change.end > change.start && !endsWithNoteReference(clean, change.start, change.end) ? clean.offsets[change.end - 1] : void 0;
|
|
4555
|
+
const lastHolder = lastCharacter === void 0 ? null : paragraph.node.nodeAt(lastCharacter - paragraph.start);
|
|
4556
|
+
const afterLast = lastCharacter === void 0 ? void 0 : lastCharacter + (lastHolder === null || lastHolder.isText ? 1 : lastHolder.nodeSize);
|
|
4557
|
+
placed.push({
|
|
4558
|
+
...change,
|
|
4559
|
+
from: gap.from,
|
|
4560
|
+
to: afterLast === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, afterLast)),
|
|
4561
|
+
markers: "retained"
|
|
4562
|
+
});
|
|
4563
|
+
}
|
|
4564
|
+
return placed;
|
|
4565
|
+
};
|
|
4566
|
+
const addressable = (placed) => placed.every(({ from: changeFrom, to: changeTo }) => projection.value.addressAt(changeFrom, changeFrom < changeTo ? "afterMarkers" : void 0).isOk() && projection.value.addressAt(changeTo, changeFrom < changeTo ? "beforeMarkers" : void 0).isOk());
|
|
4567
|
+
let replacementChanges = placeChanges(changes);
|
|
4568
|
+
if (replacementChanges === void 0) return refusal("unsupportedBlock");
|
|
4569
|
+
if (!addressable(replacementChanges)) {
|
|
4570
|
+
const whole = placeChanges(segments.source.flatMap((piece, index) => {
|
|
4571
|
+
const replacement = segments.replacement[index] ?? "";
|
|
4572
|
+
if (replacement === piece.text) return [];
|
|
4573
|
+
const pieceStart = start + piece.offset;
|
|
4574
|
+
return [{
|
|
4575
|
+
start: pieceStart,
|
|
4576
|
+
end: pieceStart + piece.text.length,
|
|
4577
|
+
text: replacement
|
|
4578
|
+
}];
|
|
4579
|
+
}));
|
|
4580
|
+
if (whole === void 0) return refusal("unsupportedBlock");
|
|
4581
|
+
replacementChanges = whole;
|
|
4582
|
+
}
|
|
4583
|
+
const comments = readModel(this.options.session.document).package.document.comments ?? [];
|
|
4584
|
+
let retiredCommentIds;
|
|
4585
|
+
if (!tracked) {
|
|
4586
|
+
const split = splitAtKeptCommentBoundaries({
|
|
4587
|
+
doc: state.doc,
|
|
4588
|
+
changes: replacementChanges,
|
|
4589
|
+
comments
|
|
4590
|
+
});
|
|
4591
|
+
replacementChanges = split.changes;
|
|
4592
|
+
retiredCommentIds = split.retiredCommentIds;
|
|
4593
|
+
}
|
|
4594
|
+
if (!preservesReplacementCommentAlignment({
|
|
4595
|
+
doc: state.doc,
|
|
4596
|
+
source: {
|
|
4597
|
+
from: paragraph.start,
|
|
4598
|
+
to: paragraph.start + paragraph.node.content.size
|
|
4599
|
+
},
|
|
4600
|
+
changes: replacementChanges,
|
|
4601
|
+
retiredCommentIds,
|
|
4602
|
+
removal: tracked ? { type: suggested ? "suggested" : "tracked" } : {
|
|
4603
|
+
type: "direct",
|
|
4604
|
+
comments
|
|
4605
|
+
}
|
|
4606
|
+
})) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4607
|
+
reason: "unsupportedBlock",
|
|
4608
|
+
gap: CANONICAL_GAP.commentReplacementAlignment,
|
|
4609
|
+
message: "Canonical replacement cannot preserve the aligned comment ranges.",
|
|
4610
|
+
detail: "Canonical replacement cannot preserve the aligned comment ranges."
|
|
4611
|
+
}));
|
|
4612
|
+
if (tracked && !suggested) deletionSpans = replacementChanges.filter((span) => span.from < span.to);
|
|
4613
|
+
if (intent.runPropsPatch !== void 0) {
|
|
4614
|
+
const nodeAtCharacter = (index) => {
|
|
4615
|
+
const position = clean.offsets[start + index];
|
|
4616
|
+
return position === void 0 ? null : paragraph.node.nodeAt(position - paragraph.start);
|
|
4617
|
+
};
|
|
4618
|
+
const local = replacementChanges.map((change) => ({
|
|
4619
|
+
start: change.start - start,
|
|
4620
|
+
end: change.end - start,
|
|
4621
|
+
text: change.text
|
|
4622
|
+
}));
|
|
4623
|
+
const keptTouched = [...touchedBackgroundStretches(local, {
|
|
4624
|
+
length: end - start,
|
|
4625
|
+
hasBackground: (index) => nodeAtCharacter(index)?.marks.some((mark) => BACKGROUND_MARK_NAMES.has(mark.type.name)) ?? false
|
|
4626
|
+
})].filter((index) => local.every((change) => index < change.start || index >= change.end)).toSorted((left, right) => left - right);
|
|
4627
|
+
if (tracked && keptTouched.some((index) => nodeAtCharacter(index)?.marks.some((mark) => mark.type.name === "runPropertyChange" && expectRunPropertyChangeMarkAttrs(mark).changes.length > 0))) return refusal("pendingRunPropertyChange");
|
|
4628
|
+
const stretches = [];
|
|
4629
|
+
for (const index of keptTouched) {
|
|
4630
|
+
const last = stretches.at(-1);
|
|
4631
|
+
if (last !== void 0 && last.end === index) last.end = index + 1;
|
|
4632
|
+
else stretches.push({
|
|
4633
|
+
start: index,
|
|
4634
|
+
end: index + 1
|
|
4635
|
+
});
|
|
4636
|
+
}
|
|
4637
|
+
for (const stretch of stretches) {
|
|
4638
|
+
const cleared = resolveCleanTextRange({
|
|
4639
|
+
cleanBlock: clean,
|
|
4640
|
+
startOffset: start + stretch.start,
|
|
4641
|
+
endOffset: start + stretch.end
|
|
4642
|
+
});
|
|
4643
|
+
const clearedFrom = cleared && projection.value.addressAt(cleared.from, "afterMarkers");
|
|
4644
|
+
const clearedTo = cleared && projection.value.addressAt(cleared.to, "beforeMarkers");
|
|
4645
|
+
if (!clearedFrom || !clearedTo || clearedFrom.isErr() || clearedTo.isErr()) return refusal("unsupportedBlock");
|
|
4646
|
+
intents.push({
|
|
4647
|
+
type: "formatRun",
|
|
4648
|
+
from: clearedFrom.value,
|
|
4649
|
+
to: clearedTo.value,
|
|
4650
|
+
patch: intent.runPropsPatch
|
|
4651
|
+
});
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
const directPlan = tracked ? planReplacementChanges({
|
|
4655
|
+
...replacementSource,
|
|
4656
|
+
planChanges: planTextChanges
|
|
4657
|
+
}) : null;
|
|
4658
|
+
const directChanges = directPlan === null ? void 0 : placeChanges(cutAroundRepeatedSeparators(replacementSource.source, directPlan).map(({ start: localStart, end: localEnd, text: replacement }) => ({
|
|
4659
|
+
start: start + localStart,
|
|
4660
|
+
end: start + localEnd,
|
|
4661
|
+
text: replacement
|
|
4662
|
+
})));
|
|
4663
|
+
const addressedDirectChanges = directChanges !== void 0 && addressable(directChanges) ? directChanges : void 0;
|
|
4664
|
+
const formattingSources = addressedDirectChanges === void 0 ? void 0 : replacementRunSources({
|
|
4665
|
+
paragraph: paragraph.node,
|
|
4666
|
+
paragraphStart: paragraph.start,
|
|
4667
|
+
offsets: clean.offsets,
|
|
4668
|
+
start,
|
|
4669
|
+
end,
|
|
4670
|
+
direct: addressedDirectChanges,
|
|
4671
|
+
tracked: replacementChanges,
|
|
4672
|
+
projection: projection.value
|
|
4673
|
+
});
|
|
4674
|
+
for (const change of addressedDirectChanges ?? replacementChanges) {
|
|
4675
|
+
const gap = {
|
|
4676
|
+
from: change.from,
|
|
4677
|
+
to: change.to
|
|
4678
|
+
};
|
|
4679
|
+
if (change.text.length > 0 && gap.from < gap.to) {
|
|
4680
|
+
let first = null;
|
|
4681
|
+
let uniform = true;
|
|
4682
|
+
paragraph.node.nodesBetween(gap.from - paragraph.start, gap.to - paragraph.start, (node) => {
|
|
4683
|
+
if (!node.isText || node.marks.some((mark) => mark.type.name === "deletion")) return;
|
|
4684
|
+
const marks = node.marks.filter((mark) => mark.type.name !== "insertion");
|
|
4685
|
+
if (first === null) first = marks;
|
|
4686
|
+
else if (!Mark.sameSet(first, marks)) uniform = false;
|
|
4687
|
+
});
|
|
4688
|
+
if (!uniform && normalizations.length === 0) normalizations.push({
|
|
4689
|
+
id: operation.id,
|
|
4690
|
+
code: "uniformReplacementFormatting"
|
|
4691
|
+
});
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
for (const [index, change] of [...replacementChanges.entries()].reverse()) {
|
|
4695
|
+
let gap = {
|
|
4696
|
+
from: change.from,
|
|
4697
|
+
to: change.to
|
|
4698
|
+
};
|
|
4699
|
+
const sources = formattingSources?.[index];
|
|
4700
|
+
if (!tracked && change.text !== "" && gap.from < gap.to) {
|
|
4701
|
+
const sourceHolder = projection.value.doc.resolve(gap.from);
|
|
4702
|
+
if (sourceHolder.parent.type.name === "sdt" && gap.to > sourceHolder.after()) {
|
|
4703
|
+
const tailStart = sourceHolder.after();
|
|
4704
|
+
const tailFrom = projection.value.addressAt(tailStart, "afterMarkers");
|
|
4705
|
+
const tailTo = projection.value.addressAt(gap.to, "beforeMarkers");
|
|
4706
|
+
if (tailFrom.isErr() || tailTo.isErr()) return refusal("unsupportedBlock");
|
|
4707
|
+
intents.push({
|
|
4708
|
+
type: "replaceText",
|
|
4709
|
+
from: tailFrom.value,
|
|
4710
|
+
to: tailTo.value,
|
|
4711
|
+
text: "",
|
|
4712
|
+
inside: controlEdgesAt(projection.value.doc, tailStart, gap.to)
|
|
4713
|
+
});
|
|
4714
|
+
gap = {
|
|
4715
|
+
from: gap.from,
|
|
4716
|
+
to: sourceHolder.end()
|
|
4717
|
+
};
|
|
4718
|
+
}
|
|
4719
|
+
}
|
|
4720
|
+
const edges = gap.from < gap.to ? {
|
|
4721
|
+
start: "afterMarkers",
|
|
4722
|
+
end: "beforeMarkers"
|
|
4723
|
+
} : void 0;
|
|
4724
|
+
const changeFrom = projection.value.addressAt(gap.from, edges?.start);
|
|
4725
|
+
const changeTo = projection.value.addressAt(gap.to, edges?.end);
|
|
4726
|
+
if (changeFrom.isErr() || changeTo.isErr()) return refusal("unsupportedBlock");
|
|
4727
|
+
let inside = controlEdgesAt(projection.value.doc, gap.from, gap.to);
|
|
4728
|
+
if (gap.from === gap.to && (inside.start === true || inside.end === true)) {
|
|
4729
|
+
const edge = projection.value.doc.resolve(gap.from);
|
|
4730
|
+
if (range.from < edge.start() || range.to > edge.end()) inside = {};
|
|
4731
|
+
}
|
|
4732
|
+
if (gap.from === gap.to && (change.start === start || change.start === end) && surveyAcceptedReplacedAnnotations(state.doc, range.from, range.to).carried.some((mark) => mark.type.name === "hyperlink")) inside = {
|
|
4733
|
+
...inside,
|
|
4734
|
+
...change.start === start ? { start: true } : { end: true }
|
|
4735
|
+
};
|
|
4736
|
+
intents.push({
|
|
4737
|
+
type: "replaceText",
|
|
4738
|
+
from: changeFrom.value,
|
|
4739
|
+
to: changeTo.value,
|
|
4740
|
+
text: change.text,
|
|
4741
|
+
...sources === void 0 ? {} : { formattingSources: sources },
|
|
4742
|
+
...Object.keys(inside).length === 0 ? {} : { inside },
|
|
4743
|
+
...intent.runPropsPatch === void 0 ? {} : { runPropsPatch: intent.runPropsPatch }
|
|
4744
|
+
});
|
|
4745
|
+
}
|
|
4746
|
+
intents.push(...restyle);
|
|
4747
|
+
} else if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs") {
|
|
4748
|
+
const vanishing = new Set([...besideDeletions.deleted].filter((id) => !besideDeletions.insertedBeside.has(id) && !besideDeletions.paragraphsAfter.has(id) && !besideDeletions.tables.after.has(id) && !besideDeletions.tables.before.has(id)));
|
|
4749
|
+
const separator = followedOnlyByDeletedParagraphs(projection.value.doc, paragraph.start - 1 + paragraph.node.nodeSize, vanishing) ? "" : operation.separator ?? "";
|
|
4750
|
+
if (separator !== "") {
|
|
4751
|
+
const at = projection.value.addressAt(paragraph.start + paragraph.node.content.size);
|
|
4752
|
+
if (at.isErr()) return refusal("unsupportedBlock");
|
|
4753
|
+
intents.push({
|
|
4754
|
+
type: "replaceText",
|
|
4755
|
+
from: at.value,
|
|
4756
|
+
to: at.value,
|
|
4757
|
+
text: separator
|
|
4758
|
+
});
|
|
4759
|
+
}
|
|
4760
|
+
intents.push(intent);
|
|
4761
|
+
intents.push(...statedPropertiesIntents({
|
|
4762
|
+
story,
|
|
4763
|
+
blockId: !tracked && intent.survivor === "first" ? intent.blockId : intent.nextBlockId,
|
|
4764
|
+
properties: operation.mergedParagraphProperties,
|
|
4765
|
+
mintList
|
|
4766
|
+
}));
|
|
4767
|
+
} else if (operation.type === "splitBlock" && intent.type === "splitParagraph") {
|
|
4768
|
+
if (tracked && !suggested && end > start) deletionSpans = [range];
|
|
4769
|
+
intents.push(intent);
|
|
4770
|
+
for (const [half, properties] of [[paragraph.blockId, operation.firstParagraphProperties], [intent.newBlockId, operation.secondParagraphProperties]]) intents.push(...statedPropertiesIntents({
|
|
4771
|
+
story,
|
|
4772
|
+
blockId: half,
|
|
4773
|
+
properties,
|
|
4774
|
+
mintList
|
|
4775
|
+
}));
|
|
4776
|
+
} else intents.push(intent);
|
|
4777
|
+
const nextParagraph = operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" ? projection.value.paragraph(intent.nextBlockId) : void 0;
|
|
4778
|
+
let claimedTo = range.to;
|
|
4779
|
+
if (operation.type === "mergeBlockWithNext") claimedTo = paragraph.start + paragraph.node.content.size;
|
|
4780
|
+
if (nextParagraph) claimedTo = nextParagraph.start + nextParagraph.node.content.size;
|
|
4781
|
+
return Result.ok({
|
|
4782
|
+
...resolvedComment,
|
|
4783
|
+
intents,
|
|
4784
|
+
normalizations,
|
|
4785
|
+
from: range.from,
|
|
4786
|
+
to: claimedTo,
|
|
4787
|
+
...deletionSpans !== void 0 && { deletionSpans }
|
|
4788
|
+
});
|
|
4789
|
+
}
|
|
4790
|
+
};
|
|
4791
|
+
export { CANONICAL_PUBLIC_OPERATION_DISPOSITIONS, CanonicalPublicOperations };
|