@stll/folio-core 0.67.0 → 0.69.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/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +106 -36
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +31 -14
- package/dist/controller/canonicalComposition.js +35 -6
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +32 -7
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +23 -0
- package/dist/controller/canonicalLockGuard.js +133 -0
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +676 -46
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +133 -21
- package/dist/controller/canonicalSession.js +738 -205
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +4 -3
- package/dist/controller/canonicalStoryEditor.js +20 -15
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +4 -0
- package/dist/controller/headerFooterEditorManager.d.ts +7 -2
- package/dist/controller/headerFooterEditorManager.js +11 -6
- package/dist/controller/hiddenEditorApi.d.ts +17 -2
- package/dist/controller/hiddenEditorApi.js +4 -0
- package/dist/controller/hiddenEditorManager.d.ts +11 -3
- package/dist/controller/hiddenEditorManager.js +157 -48
- package/dist/controller/layoutPipeline.js +50 -16
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +7 -2
- package/dist/controller/noteEditorManager.js +11 -6
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
- package/dist/document-operations.d.ts +9 -1
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +11 -2
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +40 -5
- package/dist/docx/commentAnchorIndex.js +94 -12
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +27 -0
- package/dist/docx/hostCommentThreads.js +72 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +226 -96
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +29 -0
- package/dist/docx/paragraphPropertySource.js +106 -16
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +8 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +171 -33
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +5 -2
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +19 -2
- package/dist/docx/structuralXmlPatch.js +44 -11
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +3 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
- package/dist/i18n/messages/catalogs.gen.js +51 -0
- package/dist/i18n/messages/cs.gen.js +3 -0
- package/dist/i18n/messages/de.gen.js +3 -0
- package/dist/i18n/messages/en.gen.js +3 -0
- package/dist/i18n/messages/es.gen.js +3 -0
- package/dist/i18n/messages/et.gen.js +3 -0
- package/dist/i18n/messages/fr.gen.js +3 -0
- package/dist/i18n/messages/he.gen.js +3 -0
- package/dist/i18n/messages/hi.gen.js +3 -0
- package/dist/i18n/messages/hu.gen.js +3 -0
- package/dist/i18n/messages/lt.gen.js +3 -0
- package/dist/i18n/messages/lv.gen.js +3 -0
- package/dist/i18n/messages/messages.gen.d.ts +3 -0
- package/dist/i18n/messages/pl.gen.js +3 -0
- package/dist/i18n/messages/pt-BR.gen.js +3 -0
- package/dist/i18n/messages/sk.gen.js +3 -0
- package/dist/i18n/messages/tr.gen.js +3 -0
- package/dist/i18n/messages/zh-CN.gen.js +3 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +16 -6
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +42 -1
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +54 -46
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +16 -16
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +2 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +30 -2
- package/dist/prosemirror/commands/comments.js +189 -18
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
- package/dist/prosemirror/conversion/toProseDoc.js +432 -76
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +37 -15
- package/dist/prosemirror/plugins/suggestionMode.js +33 -10
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +13 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +79 -5
- package/dist/redline.js +23 -9
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +38 -16
- package/dist/types/canonicalCapabilities.js +21 -18
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -3
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { SUGGESTED_SUPPORTED_OPERATION_TYPES } from "../ai-edits/apply.js";
|
|
1
2
|
import { splitsGraphemeCluster, splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
|
|
2
3
|
import { buildCleanBlockText, resolveCleanTextRange } from "../ai-edits/clean-text.js";
|
|
3
4
|
import { stripInlineEmphasisMarkers } from "../ai-edits/inline-emphasis.js";
|
|
4
|
-
import {
|
|
5
|
+
import { createBatchListMinter } from "../ai-edits/newListNumbering.js";
|
|
6
|
+
import { collectNoteReferenceLabels, hashFolioAIBlockContent, hashFolioAIBlockText } from "../ai-edits/snapshot.js";
|
|
7
|
+
import { findOutermostTableBoundary } from "../ai-edits/table-targets.js";
|
|
5
8
|
import { wordDiffSessionFromOptions } from "../ai-edits/word-diff.js";
|
|
6
|
-
import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch } from "../document-operations.js";
|
|
9
|
+
import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch, withDistinctSuggestionIds } from "../document-operations.js";
|
|
7
10
|
import { maxAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js";
|
|
8
11
|
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
9
12
|
import { canonicalCommentBody, compileCanonicalComments } from "./canonicalComments.js";
|
|
13
|
+
import { lockViolationBetween } from "./canonicalLockGuard.js";
|
|
10
14
|
import { Result, TaggedError, panic } from "better-result";
|
|
15
|
+
import { CONTENT_CONTROL_LOCK, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
11
16
|
import { Mark } from "prosemirror-model";
|
|
12
|
-
import {
|
|
17
|
+
import { applyDocumentOps, compileEditorIntent, createEditorIntentIdAllocator, documentStories, findStoryBody, freshCommentId, paragraphLength, pendingSuggestionIdsIn, revisionSpan, storyParagraphs } from "@stll/docx-core/ops";
|
|
13
18
|
// src/controller/canonicalPublicOperations.ts
|
|
14
19
|
/** Public batches compile against the read projection; only the canonical journal publishes. */
|
|
15
20
|
/** A new public kind cannot bypass a canonical compiler/refusal decision. */
|
|
@@ -20,10 +25,10 @@ const CANONICAL_PUBLIC_OPERATION_DISPOSITIONS = {
|
|
|
20
25
|
splitBlock: "compile",
|
|
21
26
|
formatRange: "compile",
|
|
22
27
|
mergeBlockWithNext: "compile",
|
|
23
|
-
setBlockParagraphProperties:
|
|
24
|
-
insertAfterBlock:
|
|
25
|
-
insertBeforeBlock:
|
|
26
|
-
deleteBlock:
|
|
28
|
+
setBlockParagraphProperties: "compile",
|
|
29
|
+
insertAfterBlock: "compile",
|
|
30
|
+
insertBeforeBlock: "compile",
|
|
31
|
+
deleteBlock: "compile",
|
|
27
32
|
commentOnBlock: "compile",
|
|
28
33
|
commentOnRange: "compile",
|
|
29
34
|
insertTable: CANONICAL_GAP.publicTableStructure,
|
|
@@ -51,29 +56,294 @@ const resolveComment = ({ operation, from, to }) => {
|
|
|
51
56
|
operation
|
|
52
57
|
};
|
|
53
58
|
};
|
|
54
|
-
const
|
|
59
|
+
const SPACING_FIELDS = [
|
|
60
|
+
"spaceBefore",
|
|
61
|
+
"spaceAfter",
|
|
62
|
+
"lineSpacing",
|
|
63
|
+
"lineSpacingRule",
|
|
64
|
+
"beforeAutospacing",
|
|
65
|
+
"afterAutospacing"
|
|
66
|
+
];
|
|
67
|
+
const INDENTATION_FIELDS = [
|
|
68
|
+
"indentLeft",
|
|
69
|
+
"indentRight",
|
|
70
|
+
"indentFirstLine",
|
|
71
|
+
"hangingIndent"
|
|
72
|
+
];
|
|
73
|
+
/**
|
|
74
|
+
* The stated paragraph properties an operation writes: each given property
|
|
75
|
+
* as it says, a spacing or indentation object as the whole direct child, so
|
|
76
|
+
* an attribute it leaves out is removed, and `null` clears a property back
|
|
77
|
+
* to what the style gives.
|
|
78
|
+
*/
|
|
79
|
+
const statedParagraphPatch = (properties) => {
|
|
80
|
+
const patch = {};
|
|
81
|
+
if (properties.styleId !== void 0) patch["styleId"] = properties.styleId;
|
|
82
|
+
if (properties.outlineLevel !== void 0) patch["outlineLevel"] = properties.outlineLevel;
|
|
83
|
+
if (properties.alignment !== void 0) patch["alignment"] = properties.alignment;
|
|
84
|
+
const { numbering } = properties;
|
|
85
|
+
if (numbering !== void 0 && numbering.kind !== "newList") patch["numPr"] = numbering.kind === "inherit" ? null : numbering;
|
|
86
|
+
const { spacing, indentation } = properties;
|
|
87
|
+
if (spacing !== void 0) for (const field of SPACING_FIELDS) patch[field] = spacing === null ? null : spacing[field] ?? null;
|
|
88
|
+
if (indentation !== void 0) for (const field of INDENTATION_FIELDS) patch[field] = indentation === null ? null : indentation[field] ?? null;
|
|
89
|
+
return patch;
|
|
90
|
+
};
|
|
91
|
+
const resolveParagraphProperties = ({ operation, paragraph, projection, mintList, refusal }) => {
|
|
92
|
+
const requested = operation.properties.numbering;
|
|
93
|
+
const stated = statedNumbering(requested, mintList);
|
|
94
|
+
const patch = statedParagraphPatch({
|
|
95
|
+
...operation.properties,
|
|
96
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
97
|
+
});
|
|
98
|
+
if (Object.keys(patch).length === 0) return refusal("emptyOperation");
|
|
99
|
+
const at = projection.addressAt(paragraph.start);
|
|
100
|
+
if (at.isErr()) return refusal("unsupportedBlock");
|
|
101
|
+
const intents = [{
|
|
102
|
+
type: "formatParagraph",
|
|
103
|
+
at: at.value,
|
|
104
|
+
patch,
|
|
105
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
106
|
+
}];
|
|
107
|
+
return Result.ok({
|
|
108
|
+
type: "plain",
|
|
109
|
+
operation,
|
|
110
|
+
intents,
|
|
111
|
+
normalizations: [],
|
|
112
|
+
from: paragraph.start,
|
|
113
|
+
to: paragraph.start + paragraph.node.content.size
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The intent that states `properties` on one paragraph by its identity,
|
|
118
|
+
* none when they state nothing.
|
|
119
|
+
*/
|
|
120
|
+
const statedPropertiesIntents = ({ story, blockId, properties, mintList }) => {
|
|
121
|
+
if (properties === void 0) return [];
|
|
122
|
+
const stated = statedNumbering(properties.numbering, mintList);
|
|
123
|
+
const patch = statedParagraphPatch({
|
|
124
|
+
...properties,
|
|
125
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
126
|
+
});
|
|
127
|
+
if (Object.keys(patch).length === 0) return [];
|
|
128
|
+
return [{
|
|
129
|
+
type: "formatParagraph",
|
|
130
|
+
at: {
|
|
131
|
+
story,
|
|
132
|
+
blockId,
|
|
133
|
+
offset: 0
|
|
134
|
+
},
|
|
135
|
+
patch,
|
|
136
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
137
|
+
}];
|
|
138
|
+
};
|
|
139
|
+
const isBlockInsertion = (operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock";
|
|
140
|
+
/**
|
|
141
|
+
* Where an insertion beside `paragraph` goes: beside the paragraph, or, for a
|
|
142
|
+
* paragraph in a table cell, beside the outermost table, as the default
|
|
143
|
+
* engine places it. The point names the paragraph on the far side of the
|
|
144
|
+
* table; none stands there when the table starts or ends its container.
|
|
145
|
+
*/
|
|
146
|
+
const blockInsertionPlace = (operation, paragraph, projection) => {
|
|
147
|
+
const side = operation.type === "insertAfterBlock" ? "after" : "before";
|
|
148
|
+
const table = findOutermostTableBoundary(projection.doc, paragraph.start - 1);
|
|
149
|
+
if (table === null) return {
|
|
150
|
+
at: {
|
|
151
|
+
type: side,
|
|
152
|
+
blockId: paragraph.blockId
|
|
153
|
+
},
|
|
154
|
+
position: side === "after" ? paragraph.start + paragraph.node.content.size : paragraph.start
|
|
155
|
+
};
|
|
156
|
+
const position = table[side];
|
|
157
|
+
const resolved = projection.doc.resolve(position);
|
|
158
|
+
const beside = side === "after" ? resolved.nodeAfter : resolved.nodeBefore;
|
|
159
|
+
if (beside?.type.name !== "paragraph") return void 0;
|
|
160
|
+
const neighbour = projection.paragraphStartingAt(side === "after" ? position : position - beside.nodeSize);
|
|
161
|
+
if (neighbour === void 0) return void 0;
|
|
162
|
+
return {
|
|
163
|
+
at: {
|
|
164
|
+
type: side === "after" ? "before" : "after",
|
|
165
|
+
blockId: neighbour.blockId
|
|
166
|
+
},
|
|
167
|
+
position
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* One new paragraph beside the anchor, as the default engine writes it: the
|
|
172
|
+
* anchor's stated paragraph properties unless `inheritFormatting` is false,
|
|
173
|
+
* with the operation's own on top, holding the text as one plain run.
|
|
174
|
+
*/
|
|
175
|
+
const resolveBlockInsertion = ({ operation, paragraph, projection, story, mintList, refusal }) => {
|
|
176
|
+
const requested = operation.numbering;
|
|
177
|
+
const stated = statedNumbering(requested, mintList);
|
|
178
|
+
const { text } = operation;
|
|
179
|
+
if (stripInlineEmphasisMarkers(text) !== text) return refusal("unsupportedBlock", "Canonical public emphasis replacements are unavailable.");
|
|
180
|
+
const inline = operation.lineBreakMode === "inline";
|
|
181
|
+
if (/\[\^(?:e)?\d+\]/u.test(text)) return refusal("unsupportedBlock", "Canonical block insertion requires plain text.");
|
|
182
|
+
const split = !inline && LINE_BREAK_PATTERN.test(text);
|
|
183
|
+
const lines = split ? text.split(LINE_BREAK_PATTERN).filter((line) => line.trim().length > 0) : [text];
|
|
184
|
+
const texts = lines.length === 0 ? [""] : lines;
|
|
185
|
+
const formatting = operation.inheritFormatting === false ? {} : { ...paragraph.source.formatting };
|
|
186
|
+
for (const [key, value] of Object.entries(statedParagraphPatch({
|
|
187
|
+
...operation.styleId === void 0 ? {} : { styleId: operation.styleId },
|
|
188
|
+
...operation.outlineLevel === void 0 ? {} : { outlineLevel: operation.outlineLevel },
|
|
189
|
+
...operation.alignment === void 0 ? {} : { alignment: operation.alignment },
|
|
190
|
+
...operation.spacing === void 0 ? {} : { spacing: operation.spacing },
|
|
191
|
+
...operation.indentation === void 0 ? {} : { indentation: operation.indentation },
|
|
192
|
+
...stated.numbering === void 0 ? {} : { numbering: stated.numbering }
|
|
193
|
+
}))) if (value === null) Reflect.deleteProperty(formatting, key);
|
|
194
|
+
else formatting[key] = value;
|
|
195
|
+
const everyParagraph = operation.formattingScope === "allParagraphs";
|
|
196
|
+
const paragraphs = texts.map((line, index) => {
|
|
197
|
+
const own = index === 0 || everyParagraph ? { ...formatting } : {};
|
|
198
|
+
if (index === 0 && operation.pageBreakBefore === true) own["pageBreakBefore"] = true;
|
|
199
|
+
const pageBreak = index === 0 ? operation.hardPageBreak : void 0;
|
|
200
|
+
let content = [];
|
|
201
|
+
if (pageBreak !== void 0) content = [{
|
|
202
|
+
type: "run",
|
|
203
|
+
content: [{
|
|
204
|
+
type: "break",
|
|
205
|
+
breakType: "page",
|
|
206
|
+
...pageBreak.clear === void 0 ? {} : { clear: pageBreak.clear }
|
|
207
|
+
}]
|
|
208
|
+
}];
|
|
209
|
+
else if (line !== "") content = [{
|
|
210
|
+
type: "run",
|
|
211
|
+
content: inlineText(line)
|
|
212
|
+
}];
|
|
213
|
+
return {
|
|
214
|
+
type: "paragraph",
|
|
215
|
+
content,
|
|
216
|
+
...Object.keys(own).length === 0 ? {} : { formatting: own }
|
|
217
|
+
};
|
|
218
|
+
});
|
|
219
|
+
const place = blockInsertionPlace(operation, paragraph, projection);
|
|
220
|
+
if (place === void 0) return refusal("unsupportedBlock", "Canonical insertion beside a table needs a paragraph on that side of it.");
|
|
221
|
+
const intents = [{
|
|
222
|
+
type: "insertParagraphs",
|
|
223
|
+
story,
|
|
224
|
+
at: place.at,
|
|
225
|
+
paragraphs,
|
|
226
|
+
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
227
|
+
}];
|
|
228
|
+
const { position } = place;
|
|
229
|
+
if (operation.comment !== void 0 && texts.every((line) => line.length === 0)) return refusal("unsupportedBlock");
|
|
230
|
+
const resolved = {
|
|
231
|
+
intents,
|
|
232
|
+
normalizations: split ? [{
|
|
233
|
+
id: operation.id,
|
|
234
|
+
code: "splitMultilineText",
|
|
235
|
+
paragraphCount: texts.length
|
|
236
|
+
}] : [],
|
|
237
|
+
from: position,
|
|
238
|
+
to: position
|
|
239
|
+
};
|
|
240
|
+
if (operation.comment === void 0) return Result.ok({
|
|
241
|
+
type: "plain",
|
|
242
|
+
operation,
|
|
243
|
+
...resolved
|
|
244
|
+
});
|
|
245
|
+
const anchor = {
|
|
246
|
+
story,
|
|
247
|
+
blockId: place.at.blockId,
|
|
248
|
+
offset: 0
|
|
249
|
+
};
|
|
250
|
+
return Result.ok({
|
|
251
|
+
type: "commented",
|
|
252
|
+
operation,
|
|
253
|
+
comment: {
|
|
254
|
+
text: operation.comment.text,
|
|
255
|
+
from: anchor,
|
|
256
|
+
to: anchor,
|
|
257
|
+
inserted: true
|
|
258
|
+
},
|
|
259
|
+
...resolved
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
const LINE_BREAK_PATTERN = /\r\n|\r|\n/u;
|
|
263
|
+
/**
|
|
264
|
+
* The operations a canonical suggestion can carry: the default engine's;
|
|
265
|
+
* splits and merges, which the canonical session records as tracked paragraph
|
|
266
|
+
* marks stamped with the suggestion; and comments, which it holds as proposed
|
|
267
|
+
* by the suggestion until it is accepted or rejected.
|
|
268
|
+
*/
|
|
269
|
+
const CANONICAL_SUGGESTED_OPERATION_TYPES = /* @__PURE__ */ new Set([
|
|
270
|
+
...SUGGESTED_SUPPORTED_OPERATION_TYPES,
|
|
271
|
+
"splitBlock",
|
|
272
|
+
"mergeBlockWithNext",
|
|
273
|
+
"commentOnRange",
|
|
274
|
+
"commentOnBlock"
|
|
275
|
+
]);
|
|
276
|
+
/**
|
|
277
|
+
* Whether one of two resolved operations inserts beside the paragraph the
|
|
278
|
+
* other deletes by identity: they touch only at that paragraph's edge, and
|
|
279
|
+
* both apply, as in the default engine. A deletion of a paragraph that ends
|
|
280
|
+
* its container still refuses the insertion beside it.
|
|
281
|
+
*/
|
|
282
|
+
const besideItsDeletion = (left, right) => {
|
|
283
|
+
const pair = ({ operation: insertion }, { operation: deletion, removesParagraphBeforeBlock }) => (insertion.type === "insertAfterBlock" || insertion.type === "insertBeforeBlock") && deletion.type === "deleteBlock" && removesParagraphBeforeBlock === true && insertion.blockId === deletion.blockId;
|
|
284
|
+
return pair(left, right) || pair(right, left);
|
|
285
|
+
};
|
|
286
|
+
/** A block operation without the move it names: a plain insertion or deletion. */
|
|
287
|
+
const withoutMove = (operation) => {
|
|
288
|
+
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock") return operation;
|
|
289
|
+
const { moveId: _moveId, ...plain } = operation;
|
|
290
|
+
return plain;
|
|
291
|
+
};
|
|
292
|
+
/** The move a block operation names, if it is a half of one. */
|
|
293
|
+
const blockMoveId = (operation) => operation.type === "deleteBlock" || operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock" ? operation.moveId : void 0;
|
|
294
|
+
/**
|
|
295
|
+
* A line's text with each tab and line break as the element it is; CRLF, CR
|
|
296
|
+
* and LF are each one line break.
|
|
297
|
+
*/
|
|
298
|
+
const inlineText = (line) => line.split(/(\t|\r\n|\r|\n)/u).flatMap((part) => {
|
|
299
|
+
if (part === " ") return [{ type: "tab" }];
|
|
300
|
+
if (LINE_BREAK_PATTERN.test(part)) return [{ type: "break" }];
|
|
301
|
+
return part === "" ? [] : [{
|
|
302
|
+
type: "text",
|
|
303
|
+
text: part
|
|
304
|
+
}];
|
|
305
|
+
});
|
|
306
|
+
const compilePublicIntents = ({ document, intents, mode, author, date, suggestionId, nextRevisionId, allocate, reservedBlockIds }) => {
|
|
55
307
|
const ops = [];
|
|
56
308
|
const revisions = [];
|
|
309
|
+
const allocated = /* @__PURE__ */ new Map();
|
|
57
310
|
for (const sourceIntent of intents) {
|
|
58
311
|
const ids = allocate(document, sourceIntent);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
312
|
+
let intent = sourceIntent;
|
|
313
|
+
if (sourceIntent.type === "splitParagraph") {
|
|
314
|
+
allocated.set(sourceIntent.newBlockId, ids.newBlockId);
|
|
315
|
+
intent = {
|
|
316
|
+
type: "splitParagraph",
|
|
317
|
+
at: sourceIntent.at,
|
|
318
|
+
...sourceIntent.to === void 0 ? {} : { to: sourceIntent.to },
|
|
319
|
+
...sourceIntent.newHalf === void 0 ? {} : { newHalf: sourceIntent.newHalf },
|
|
320
|
+
newBlockId: ids.newBlockId
|
|
321
|
+
};
|
|
322
|
+
} else if (sourceIntent.type === "formatParagraph") {
|
|
323
|
+
const blockId = allocated.get(sourceIntent.at.blockId);
|
|
324
|
+
if (blockId !== void 0) intent = {
|
|
325
|
+
...sourceIntent,
|
|
326
|
+
at: {
|
|
327
|
+
...sourceIntent.at,
|
|
328
|
+
blockId
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
65
332
|
const firstRevisionId = nextRevisionId;
|
|
66
333
|
const compiled = compileEditorIntent(document, {
|
|
67
334
|
intent,
|
|
68
335
|
mode: mode === "direct" ? {
|
|
69
336
|
type: "editing",
|
|
70
|
-
newIds: ids.newIds
|
|
337
|
+
newIds: ids.newIds,
|
|
338
|
+
reservedBlockIds
|
|
71
339
|
} : {
|
|
72
340
|
type: "suggesting",
|
|
341
|
+
reservedBlockIds,
|
|
73
342
|
revision: {
|
|
74
343
|
id: firstRevisionId,
|
|
75
344
|
author,
|
|
76
|
-
date
|
|
345
|
+
date,
|
|
346
|
+
...suggestionId === void 0 ? {} : { suggestionId }
|
|
77
347
|
},
|
|
78
348
|
newIds: {
|
|
79
349
|
control: ids.newIds.control,
|
|
@@ -98,6 +368,22 @@ const compilePublicIntents = ({ document, intents, mode, author, date, nextRevis
|
|
|
98
368
|
};
|
|
99
369
|
const CanonicalPublicOperationResolutionErrorBase = TaggedError("CanonicalPublicOperationResolutionError");
|
|
100
370
|
var CanonicalPublicOperationResolutionError = class extends CanonicalPublicOperationResolutionErrorBase {};
|
|
371
|
+
/**
|
|
372
|
+
* The stated numbering a request names, minting its new list once for the
|
|
373
|
+
* operation, as the default engine allocates one instance per operation.
|
|
374
|
+
*/
|
|
375
|
+
const statedNumbering = (numbering, mint) => {
|
|
376
|
+
if (numbering === void 0) return {};
|
|
377
|
+
if (numbering.kind !== "newList") return { numbering };
|
|
378
|
+
const minted = mint(numbering.format);
|
|
379
|
+
return {
|
|
380
|
+
numbering: paragraphNumberingReference({
|
|
381
|
+
numId: minted.numId,
|
|
382
|
+
ilvl: numbering.level ?? 0
|
|
383
|
+
}),
|
|
384
|
+
newList: minted.newList
|
|
385
|
+
};
|
|
386
|
+
};
|
|
101
387
|
const canonicalPublicStory = (story) => {
|
|
102
388
|
if (story === "main") return story;
|
|
103
389
|
switch (story.type) {
|
|
@@ -129,8 +415,9 @@ var CanonicalPublicOperations = class {
|
|
|
129
415
|
this.options = options;
|
|
130
416
|
}
|
|
131
417
|
apply(options) {
|
|
132
|
-
const batch = parseFolioDocumentOperationBatch(options.batch);
|
|
133
418
|
const { session } = this.options;
|
|
419
|
+
const parsed = parseFolioDocumentOperationBatch(options.batch);
|
|
420
|
+
const batch = parsed.mode !== "suggested" || options.restagesSuggestions === true || session.isComposing ? parsed : withDistinctSuggestionIds(parsed, /* @__PURE__ */ new Set([...pendingSuggestionIdsIn(session.document), ...options.pendingSuggestionIds ?? []]));
|
|
134
421
|
const publicStory = options.story ?? "main";
|
|
135
422
|
const story = canonicalPublicStory(publicStory);
|
|
136
423
|
const state = this.options.getState(story);
|
|
@@ -139,6 +426,7 @@ var CanonicalPublicOperations = class {
|
|
|
139
426
|
const normalizations = [];
|
|
140
427
|
const refusals = /* @__PURE__ */ new Map();
|
|
141
428
|
const resolved = [];
|
|
429
|
+
const mintList = createBatchListMinter(() => session.document);
|
|
142
430
|
const { diff } = wordDiffSessionFromOptions(options.wordDiff);
|
|
143
431
|
let nextRevisionId = options.revisionStamp?.idSeed ?? 1;
|
|
144
432
|
if (!session.isComposing && options.revisionStamp === void 0) for (const currentStory of documentStories(session.document)) {
|
|
@@ -179,19 +467,18 @@ var CanonicalPublicOperations = class {
|
|
|
179
467
|
...normalizations.length === 0 ? {} : { normalizations }
|
|
180
468
|
};
|
|
181
469
|
};
|
|
470
|
+
const besideDeletions = {
|
|
471
|
+
deleted: new Set(batch.operations.flatMap((operation) => operation.type === "deleteBlock" ? [operation.blockId] : [])),
|
|
472
|
+
insertedBeside: new Set(batch.operations.flatMap((operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock" ? [operation.blockId] : []))
|
|
473
|
+
};
|
|
474
|
+
const overlapsResolved = (candidate) => resolved.some((earlier) => earlier !== candidate && !besideItsDeletion(earlier, candidate) && (candidate.from < earlier.to && candidate.to > earlier.from || earlier.from === earlier.to && candidate.from <= earlier.from && candidate.to >= earlier.from || candidate.from === candidate.to && candidate.from >= earlier.from && candidate.from <= earlier.to));
|
|
182
475
|
for (const operation of batch.operations) {
|
|
183
|
-
if (story !== OP_STORIES.MAIN) {
|
|
184
|
-
refusals.set(operation.id, { gap: CANONICAL_GAP.publicSecondaryStories });
|
|
185
|
-
skip(operation.id, "unsupportedBlock", "Canonical public secondary-story routing is unavailable.");
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
476
|
if (!state || projected.isErr() || session.isComposing) {
|
|
189
477
|
skip(operation.id, "documentNotEditable");
|
|
190
478
|
continue;
|
|
191
479
|
}
|
|
192
|
-
if (batch.mode === "suggested") {
|
|
193
|
-
|
|
194
|
-
skip(operation.id, "unsupportedMode", "Canonical pending suggestions are unavailable.");
|
|
480
|
+
if (batch.mode === "suggested" && !CANONICAL_SUGGESTED_OPERATION_TYPES.has(operation.type)) {
|
|
481
|
+
skip(operation.id, "unsupportedMode");
|
|
195
482
|
continue;
|
|
196
483
|
}
|
|
197
484
|
if (options.tableTemplates !== void 0 || options.undefinedReferences === "keep") {
|
|
@@ -210,38 +497,107 @@ var CanonicalPublicOperations = class {
|
|
|
210
497
|
options,
|
|
211
498
|
state,
|
|
212
499
|
story,
|
|
213
|
-
diff
|
|
500
|
+
diff,
|
|
501
|
+
tracked: batch.mode !== "direct",
|
|
502
|
+
mintList,
|
|
503
|
+
besideDeletions
|
|
214
504
|
});
|
|
215
505
|
if (compiled.isErr()) {
|
|
216
506
|
if (compiled.error.reason === "unsupportedBlock") refusals.set(operation.id, { gap: CANONICAL_GAP.publicUnsupportedInline });
|
|
217
507
|
skip(operation.id, compiled.error.reason, compiled.error.message);
|
|
218
508
|
continue;
|
|
219
509
|
}
|
|
220
|
-
if (
|
|
510
|
+
if (overlapsResolved(compiled.value)) {
|
|
221
511
|
skip(operation.id, "overlappingOperation");
|
|
222
512
|
continue;
|
|
223
513
|
}
|
|
224
514
|
resolved.push(compiled.value);
|
|
225
515
|
}
|
|
516
|
+
for (const item of [...resolved]) {
|
|
517
|
+
if (item.besideDeletion !== true || !state) continue;
|
|
518
|
+
const { operation } = item;
|
|
519
|
+
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock") continue;
|
|
520
|
+
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;
|
|
521
|
+
resolved.splice(resolved.indexOf(item), 1);
|
|
522
|
+
const alone = this.resolve({
|
|
523
|
+
operation,
|
|
524
|
+
options,
|
|
525
|
+
state,
|
|
526
|
+
story,
|
|
527
|
+
diff,
|
|
528
|
+
tracked: batch.mode !== "direct",
|
|
529
|
+
mintList,
|
|
530
|
+
besideDeletions: {
|
|
531
|
+
deleted: /* @__PURE__ */ new Set(),
|
|
532
|
+
insertedBeside: /* @__PURE__ */ new Set()
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
if (alone.isErr()) {
|
|
536
|
+
skip(operation.id, alone.error.reason, alone.error.message);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (overlapsResolved(alone.value)) {
|
|
540
|
+
skip(operation.id, "overlappingOperation");
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
resolved.push(alone.value);
|
|
544
|
+
}
|
|
545
|
+
const moveSides = /* @__PURE__ */ new Map();
|
|
546
|
+
for (const { operation } of resolved) {
|
|
547
|
+
const moveId = blockMoveId(operation);
|
|
548
|
+
if (moveId === void 0) continue;
|
|
549
|
+
const sides = moveSides.get(moveId) ?? {
|
|
550
|
+
from: 0,
|
|
551
|
+
to: 0
|
|
552
|
+
};
|
|
553
|
+
if (operation.type === "deleteBlock") sides.from += 1;
|
|
554
|
+
else sides.to += 1;
|
|
555
|
+
moveSides.set(moveId, sides);
|
|
556
|
+
}
|
|
557
|
+
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] : []) : []);
|
|
558
|
+
const paired = (moveId) => !unpairable.has(moveId) && moveSides.get(moveId)?.from === 1 && moveSides.get(moveId)?.to === 1;
|
|
559
|
+
const pairedMoves = /* @__PURE__ */ new Set();
|
|
560
|
+
for (const [index, item] of resolved.entries()) {
|
|
561
|
+
const moveId = blockMoveId(item.operation);
|
|
562
|
+
if (moveId === void 0) continue;
|
|
563
|
+
if (!paired(moveId)) {
|
|
564
|
+
normalizations.push({
|
|
565
|
+
id: item.operation.id,
|
|
566
|
+
code: "unpairedMove",
|
|
567
|
+
moveId
|
|
568
|
+
});
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
pairedMoves.add(moveId);
|
|
572
|
+
const intents = [];
|
|
573
|
+
for (const intent of item.intents) intents.push(intent.type === "insertParagraphs" || intent.type === "deleteParagraphs" ? Object.assign({}, intent, { move: true }) : intent);
|
|
574
|
+
resolved[index] = {
|
|
575
|
+
...item,
|
|
576
|
+
intents
|
|
577
|
+
};
|
|
578
|
+
}
|
|
226
579
|
if (batch.atomic && skipped.length > 0) {
|
|
227
580
|
for (const { operation } of resolved) skip(operation.id, "atomicBatchRejected");
|
|
228
581
|
return result([], null);
|
|
229
582
|
}
|
|
230
583
|
if (!state || projected.isErr() || session.isComposing) return result([], null);
|
|
231
|
-
resolved.sort((left, right) => right.from - left.from);
|
|
584
|
+
resolved.sort((left, right) => right.from - left.from || left.to - left.from - (right.to - right.from));
|
|
232
585
|
let document = session.document;
|
|
233
586
|
const ops = [];
|
|
234
587
|
const appliedById = /* @__PURE__ */ new Map();
|
|
235
|
-
const allocate = createEditorIntentIdAllocator();
|
|
588
|
+
const allocate = createEditorIntentIdAllocator({ reservedBlockIds: session.reservedBlockIds });
|
|
236
589
|
const date = options.revisionStamp?.date ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
237
590
|
for (const resolvedOperation of resolved) {
|
|
238
591
|
const { operation, intents, normalizations: adjustments } = resolvedOperation;
|
|
592
|
+
const suggestionId = batch.mode === "suggested" ? ("suggestionId" in operation ? operation.suggestionId : void 0) ?? operation.id : void 0;
|
|
239
593
|
const compiled = compilePublicIntents({
|
|
240
594
|
document,
|
|
241
595
|
intents,
|
|
242
596
|
allocate,
|
|
597
|
+
reservedBlockIds: session.reservedBlockIds,
|
|
243
598
|
nextRevisionId,
|
|
244
599
|
mode: batch.mode === "direct" ? "direct" : "tracked-changes",
|
|
600
|
+
suggestionId,
|
|
245
601
|
author: options.author ?? "AI",
|
|
246
602
|
date
|
|
247
603
|
});
|
|
@@ -258,16 +614,77 @@ var CanonicalPublicOperations = class {
|
|
|
258
614
|
case "commented": {
|
|
259
615
|
const { comment } = resolvedOperation;
|
|
260
616
|
const id = freshCommentId(nextDocument);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
617
|
+
const proposedBy = suggestionId === void 0 ? {} : { suggestionId };
|
|
618
|
+
if (comment.inserted === true) {
|
|
619
|
+
const paragraphsIn = (current) => {
|
|
620
|
+
const body = findStoryBody(current, story);
|
|
621
|
+
return body === void 0 ? [] : storyParagraphs(body).map(({ paragraph }) => paragraph);
|
|
622
|
+
};
|
|
623
|
+
const known = new Set(paragraphsIn(document).flatMap(({ paraId }) => paraId === void 0 ? [] : [paraId]));
|
|
624
|
+
const added = paragraphsIn(nextDocument).filter(({ paraId }) => paraId !== void 0 && !known.has(paraId));
|
|
625
|
+
const firstAdded = added.at(0);
|
|
626
|
+
const lastAdded = added.at(-1);
|
|
627
|
+
const commented = id.isErr() || firstAdded?.paraId === void 0 || lastAdded?.paraId === void 0 ? void 0 : compileCanonicalComments({
|
|
628
|
+
document: nextDocument,
|
|
629
|
+
command: {
|
|
630
|
+
type: "create",
|
|
631
|
+
comment: {
|
|
632
|
+
id: id.value,
|
|
633
|
+
author: options.author ?? "AI",
|
|
634
|
+
date,
|
|
635
|
+
done: false,
|
|
636
|
+
content: canonicalCommentBody(nextDocument, comment.text),
|
|
637
|
+
...proposedBy
|
|
638
|
+
},
|
|
639
|
+
anchor: {
|
|
640
|
+
kind: "range",
|
|
641
|
+
from: {
|
|
642
|
+
story,
|
|
643
|
+
blockId: firstAdded.paraId,
|
|
644
|
+
offset: 0
|
|
645
|
+
},
|
|
646
|
+
to: {
|
|
647
|
+
story,
|
|
648
|
+
blockId: lastAdded.paraId,
|
|
649
|
+
offset: paragraphLength(lastAdded)
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
if (commented === void 0 || commented.isErr() || id.isErr()) {
|
|
655
|
+
refusals.set(operation.id, { gap: CANONICAL_GAP.publicComments });
|
|
656
|
+
skip(operation.id, "unsupportedBlock", commented?.isErr() === true ? commented.error.message : "The inserted paragraphs cannot carry the comment.");
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
nextDocument = commented.value.document;
|
|
660
|
+
operationOps.push(...commented.value.ops);
|
|
661
|
+
commentId = id.value;
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
const anchorIn = (current) => {
|
|
665
|
+
const body = findStoryBody(current, story);
|
|
666
|
+
return body === void 0 ? void 0 : storyParagraphs(body).find(({ paragraph }) => paragraph.paraId === comment.from.blockId)?.paragraph;
|
|
667
|
+
};
|
|
668
|
+
const before = anchorIn(document);
|
|
669
|
+
const after = anchorIn(nextDocument);
|
|
670
|
+
if (id.isErr() || before === void 0 || after === void 0) {
|
|
264
671
|
refusals.set(operation.id, { gap: CANONICAL_GAP.publicComments });
|
|
265
672
|
skip(operation.id, "unsupportedBlock", id.isErr() ? id.error.message : "The comment anchor no longer exists.");
|
|
266
673
|
continue;
|
|
267
674
|
}
|
|
268
|
-
const
|
|
675
|
+
const changed = batch.mode === "direct" ? void 0 : revisionSpan(after.content, new Set(compiled.value.revisions));
|
|
676
|
+
const from = changed === void 0 ? comment.from : {
|
|
677
|
+
story: comment.from.story,
|
|
678
|
+
blockId: comment.from.blockId,
|
|
679
|
+
offset: changed.from
|
|
680
|
+
};
|
|
681
|
+
const to = changed === void 0 ? {
|
|
269
682
|
...comment.to,
|
|
270
683
|
offset: comment.to.offset + paragraphLength(after) - paragraphLength(before)
|
|
684
|
+
} : {
|
|
685
|
+
story: comment.from.story,
|
|
686
|
+
blockId: comment.from.blockId,
|
|
687
|
+
offset: changed.to
|
|
271
688
|
};
|
|
272
689
|
const commented = compileCanonicalComments({
|
|
273
690
|
document: nextDocument,
|
|
@@ -278,14 +695,15 @@ var CanonicalPublicOperations = class {
|
|
|
278
695
|
author: options.author ?? "AI",
|
|
279
696
|
date,
|
|
280
697
|
done: false,
|
|
281
|
-
content: canonicalCommentBody(nextDocument, comment.text)
|
|
698
|
+
content: canonicalCommentBody(nextDocument, comment.text),
|
|
699
|
+
...proposedBy
|
|
282
700
|
},
|
|
283
|
-
anchor: to.offset ===
|
|
701
|
+
anchor: to.offset === from.offset ? {
|
|
284
702
|
kind: "point",
|
|
285
|
-
at:
|
|
703
|
+
at: from
|
|
286
704
|
} : {
|
|
287
705
|
kind: "range",
|
|
288
|
-
from
|
|
706
|
+
from,
|
|
289
707
|
to
|
|
290
708
|
}
|
|
291
709
|
}
|
|
@@ -306,6 +724,11 @@ var CanonicalPublicOperations = class {
|
|
|
306
724
|
skip(operation.id, "noopOperation");
|
|
307
725
|
continue;
|
|
308
726
|
}
|
|
727
|
+
const locked = lockViolationBetween(document, nextDocument);
|
|
728
|
+
if (locked !== null) {
|
|
729
|
+
skip(operation.id, CONTENT_CONTROL_LOCK, `Refused: ${lockedControlMessage(locked)}`);
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
309
732
|
normalizations.push(...adjustments);
|
|
310
733
|
document = nextDocument;
|
|
311
734
|
ops.push(...operationOps);
|
|
@@ -318,8 +741,40 @@ var CanonicalPublicOperations = class {
|
|
|
318
741
|
...revisionId === void 0 ? {} : {
|
|
319
742
|
revisionId,
|
|
320
743
|
revisionIds
|
|
744
|
+
},
|
|
745
|
+
...suggestionId === void 0 ? {} : { suggestionId }
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
const applyingHalves = /* @__PURE__ */ new Map();
|
|
749
|
+
for (const { operation } of resolved) {
|
|
750
|
+
const moveId = blockMoveId(operation);
|
|
751
|
+
if (moveId !== void 0 && appliedById.has(operation.id)) applyingHalves.set(moveId, (applyingHalves.get(moveId) ?? 0) + 1);
|
|
752
|
+
}
|
|
753
|
+
const orphaned = new Set([...pairedMoves].filter((moveId) => applyingHalves.get(moveId) === 1));
|
|
754
|
+
if (orphaned.size > 0) {
|
|
755
|
+
const orphanedMove = (operation) => {
|
|
756
|
+
const moveId = blockMoveId(operation);
|
|
757
|
+
return moveId !== void 0 && orphaned.has(moveId);
|
|
758
|
+
};
|
|
759
|
+
const plain = this.apply({
|
|
760
|
+
...options,
|
|
761
|
+
batch: {
|
|
762
|
+
...batch,
|
|
763
|
+
operations: batch.operations.map((operation) => orphanedMove(operation) ? withoutMove(operation) : operation)
|
|
321
764
|
}
|
|
322
765
|
});
|
|
766
|
+
const appliedIds = new Set(plain.applied.map(({ id }) => id));
|
|
767
|
+
return {
|
|
768
|
+
...plain,
|
|
769
|
+
normalizations: [...plain.normalizations ?? [], ...batch.operations.flatMap((operation) => {
|
|
770
|
+
const moveId = blockMoveId(operation);
|
|
771
|
+
return moveId !== void 0 && orphaned.has(moveId) && appliedIds.has(operation.id) ? [{
|
|
772
|
+
id: operation.id,
|
|
773
|
+
code: "unpairedMove",
|
|
774
|
+
moveId
|
|
775
|
+
}] : [];
|
|
776
|
+
})]
|
|
777
|
+
};
|
|
323
778
|
}
|
|
324
779
|
if (batch.atomic && skipped.length > 0) {
|
|
325
780
|
for (const { id } of appliedById.values()) skip(id, "atomicBatchRejected");
|
|
@@ -394,7 +849,104 @@ var CanonicalPublicOperations = class {
|
|
|
394
849
|
undoHandle: handle
|
|
395
850
|
};
|
|
396
851
|
}
|
|
397
|
-
|
|
852
|
+
/**
|
|
853
|
+
* A whole paragraph removed as the editor removes a selection of it with
|
|
854
|
+
* its paragraph mark: from its start to the start of the paragraph after
|
|
855
|
+
* it, or, for the paragraph that ends its block list, from the end of the
|
|
856
|
+
* paragraph before it, whose mark then ends the list. Tracked, the text and
|
|
857
|
+
* the mark are marked deleted.
|
|
858
|
+
*/
|
|
859
|
+
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, gainsFollower, refusal }) {
|
|
860
|
+
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock");
|
|
861
|
+
const end = paragraph.start + paragraph.node.content.size;
|
|
862
|
+
const after = doc.resolve(end + 1).nodeAfter;
|
|
863
|
+
const before = doc.resolve(paragraph.start - 1).nodeBefore;
|
|
864
|
+
const neighbour = (node) => {
|
|
865
|
+
const id = node?.attrs["paraId"];
|
|
866
|
+
return node?.type.name === "paragraph" && typeof id === "string" ? projection.paragraph(id) : void 0;
|
|
867
|
+
};
|
|
868
|
+
const next = neighbour(after);
|
|
869
|
+
const previous = neighbour(before);
|
|
870
|
+
const commentFrom = projection.addressAt(paragraph.start);
|
|
871
|
+
const commentTo = projection.addressAt(end);
|
|
872
|
+
if (commentFrom.isErr() || commentTo.isErr()) return refusal("unsupportedBlock");
|
|
873
|
+
const tracking = (resolved) => Result.ok(operation.comment === void 0 ? {
|
|
874
|
+
type: "plain",
|
|
875
|
+
operation,
|
|
876
|
+
...resolved
|
|
877
|
+
} : {
|
|
878
|
+
type: "commented",
|
|
879
|
+
operation,
|
|
880
|
+
comment: {
|
|
881
|
+
text: operation.comment.text,
|
|
882
|
+
from: commentFrom.value,
|
|
883
|
+
to: commentTo.value
|
|
884
|
+
},
|
|
885
|
+
...resolved
|
|
886
|
+
});
|
|
887
|
+
if (next !== void 0 || gainsFollower || tracked && (after !== null || operation.moveId !== void 0)) return tracking({
|
|
888
|
+
intents: [{
|
|
889
|
+
type: "deleteParagraphs",
|
|
890
|
+
story: projectionStory,
|
|
891
|
+
blockIds: [paragraph.blockId]
|
|
892
|
+
}],
|
|
893
|
+
normalizations: [],
|
|
894
|
+
from: paragraph.start,
|
|
895
|
+
to: end,
|
|
896
|
+
...after === null && !gainsFollower ? {} : { removesParagraphBeforeBlock: true }
|
|
897
|
+
});
|
|
898
|
+
let range;
|
|
899
|
+
if (!tracked) {
|
|
900
|
+
const own = (from, to) => {
|
|
901
|
+
const start = projection.addressAt(from);
|
|
902
|
+
const stop = projection.addressAt(to);
|
|
903
|
+
return start.isErr() || stop.isErr() ? refusal("unsupportedBlock") : Result.ok(from === to ? [] : [{
|
|
904
|
+
type: "replaceText",
|
|
905
|
+
from: start.value,
|
|
906
|
+
to: stop.value,
|
|
907
|
+
text: ""
|
|
908
|
+
}]);
|
|
909
|
+
};
|
|
910
|
+
const cleared = own(paragraph.start, end);
|
|
911
|
+
if (cleared.isErr()) return cleared;
|
|
912
|
+
const intents = [...cleared.value];
|
|
913
|
+
if (previous !== void 0) intents.push({
|
|
914
|
+
type: "joinParagraphs",
|
|
915
|
+
story: projectionStory,
|
|
916
|
+
blockId: previous.blockId,
|
|
917
|
+
nextBlockId: paragraph.blockId,
|
|
918
|
+
survivor: "first"
|
|
919
|
+
});
|
|
920
|
+
if (intents.length === 0) return refusal("noopOperation");
|
|
921
|
+
return Result.ok({
|
|
922
|
+
type: "plain",
|
|
923
|
+
operation,
|
|
924
|
+
intents,
|
|
925
|
+
normalizations: [],
|
|
926
|
+
from: previous === void 0 ? paragraph.start : previous.start,
|
|
927
|
+
to: end
|
|
928
|
+
});
|
|
929
|
+
} else if (previous !== void 0) range = {
|
|
930
|
+
from: previous.start + previous.node.content.size,
|
|
931
|
+
to: end
|
|
932
|
+
};
|
|
933
|
+
if (range === void 0) return refusal("unsupportedBlock", "Canonical deletion of the only paragraph in its container is unavailable.");
|
|
934
|
+
const from = projection.addressAt(range.from);
|
|
935
|
+
const to = projection.addressAt(range.to);
|
|
936
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
937
|
+
return tracking({
|
|
938
|
+
intents: [{
|
|
939
|
+
type: "replaceText",
|
|
940
|
+
from: from.value,
|
|
941
|
+
to: to.value,
|
|
942
|
+
text: ""
|
|
943
|
+
}],
|
|
944
|
+
normalizations: [],
|
|
945
|
+
from: Math.min(range.from, paragraph.start),
|
|
946
|
+
to: Math.max(range.to, end)
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
resolve({ operation, options, state, story, diff, tracked, mintList, besideDeletions }) {
|
|
398
950
|
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
399
951
|
reason,
|
|
400
952
|
message: message ?? `The operation was refused: ${reason}.`
|
|
@@ -407,7 +959,11 @@ var CanonicalPublicOperations = class {
|
|
|
407
959
|
case "formatRange":
|
|
408
960
|
case "mergeBlockWithNext":
|
|
409
961
|
case "commentOnRange":
|
|
410
|
-
case "commentOnBlock":
|
|
962
|
+
case "commentOnBlock":
|
|
963
|
+
case "deleteBlock":
|
|
964
|
+
case "setBlockParagraphProperties":
|
|
965
|
+
case "insertAfterBlock":
|
|
966
|
+
case "insertBeforeBlock": break;
|
|
411
967
|
default: return refusal("unsupportedBlock", `Canonical public operation ${operation.type} is unavailable.`);
|
|
412
968
|
}
|
|
413
969
|
const blockId = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range.blockId : operation.blockId;
|
|
@@ -421,9 +977,52 @@ var CanonicalPublicOperations = class {
|
|
|
421
977
|
fieldResults: "text",
|
|
422
978
|
noteReferences: collectNoteReferenceLabels(state.doc)
|
|
423
979
|
});
|
|
424
|
-
const hash =
|
|
980
|
+
const hash = hashFolioAIBlockContent(clean.text);
|
|
425
981
|
if (operation.precondition && hash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
426
982
|
if (hash !== anchor.textHash) return refusal("changedBlock");
|
|
983
|
+
const followed = state.doc.resolve(paragraph.start + paragraph.node.content.size + 1).nodeAfter?.type.name === "paragraph";
|
|
984
|
+
if (isBlockInsertion(operation)) {
|
|
985
|
+
const besideDeletion = !tracked && operation.type === "insertBeforeBlock" && !followed && besideDeletions.deleted.has(blockId);
|
|
986
|
+
const inserted = resolveBlockInsertion({
|
|
987
|
+
operation: besideDeletion ? {
|
|
988
|
+
...operation,
|
|
989
|
+
type: "insertAfterBlock"
|
|
990
|
+
} : operation,
|
|
991
|
+
paragraph,
|
|
992
|
+
projection: projection.value,
|
|
993
|
+
story,
|
|
994
|
+
mintList,
|
|
995
|
+
refusal
|
|
996
|
+
});
|
|
997
|
+
return besideDeletion && inserted.isOk() ? Result.ok({
|
|
998
|
+
...inserted.value,
|
|
999
|
+
besideDeletion: true
|
|
1000
|
+
}) : inserted;
|
|
1001
|
+
}
|
|
1002
|
+
if (operation.type === "setBlockParagraphProperties") return resolveParagraphProperties({
|
|
1003
|
+
operation,
|
|
1004
|
+
paragraph,
|
|
1005
|
+
projection: projection.value,
|
|
1006
|
+
mintList,
|
|
1007
|
+
refusal
|
|
1008
|
+
});
|
|
1009
|
+
if (operation.type === "deleteBlock") {
|
|
1010
|
+
const gainsFollower = !followed && besideDeletions.insertedBeside.has(blockId);
|
|
1011
|
+
const deleted = this.resolveBlockDeletion({
|
|
1012
|
+
operation,
|
|
1013
|
+
paragraph,
|
|
1014
|
+
projection: projection.value,
|
|
1015
|
+
projectionStory: story,
|
|
1016
|
+
doc: state.doc,
|
|
1017
|
+
tracked,
|
|
1018
|
+
gainsFollower,
|
|
1019
|
+
refusal
|
|
1020
|
+
});
|
|
1021
|
+
return gainsFollower && deleted.isOk() ? Result.ok({
|
|
1022
|
+
...deleted.value,
|
|
1023
|
+
besideDeletion: true
|
|
1024
|
+
}) : deleted;
|
|
1025
|
+
}
|
|
427
1026
|
let start = 0;
|
|
428
1027
|
let end = clean.text.length;
|
|
429
1028
|
let text = "";
|
|
@@ -457,13 +1056,12 @@ var CanonicalPublicOperations = class {
|
|
|
457
1056
|
text = operation.text;
|
|
458
1057
|
break;
|
|
459
1058
|
case "splitBlock":
|
|
460
|
-
if (operation.firstParagraphProperties || operation.secondParagraphProperties) return refusal("unsupportedBlock", "Canonical split paragraph properties are unavailable.");
|
|
461
1059
|
start = operation.offset;
|
|
462
1060
|
end = start + (operation.separator?.length ?? 0);
|
|
463
1061
|
if (start <= 0 || start >= clean.text.length || clean.text.slice(start, end) !== (operation.separator ?? "")) return refusal("staleRange");
|
|
464
1062
|
break;
|
|
465
1063
|
case "mergeBlockWithNext":
|
|
466
|
-
if (operation.
|
|
1064
|
+
if (/[\t\r\n]/u.test(operation.separator ?? "")) return refusal("unsupportedBlock", "Canonical public join separators require plain text.");
|
|
467
1065
|
start = clean.text.length;
|
|
468
1066
|
end = start;
|
|
469
1067
|
break;
|
|
@@ -502,7 +1100,8 @@ var CanonicalPublicOperations = class {
|
|
|
502
1100
|
type: "splitParagraph",
|
|
503
1101
|
at: from.value,
|
|
504
1102
|
to: to.value,
|
|
505
|
-
|
|
1103
|
+
newHalf: "second",
|
|
1104
|
+
newBlockId: createEditorIntentIdAllocator({ reservedBlockIds: this.options.session.reservedBlockIds })(this.options.session.document, {
|
|
506
1105
|
type: "splitParagraph",
|
|
507
1106
|
at: from.value,
|
|
508
1107
|
to: to.value
|
|
@@ -516,7 +1115,8 @@ var CanonicalPublicOperations = class {
|
|
|
516
1115
|
type: "joinParagraphs",
|
|
517
1116
|
story,
|
|
518
1117
|
blockId,
|
|
519
|
-
nextBlockId: next.blockId
|
|
1118
|
+
nextBlockId: next.blockId,
|
|
1119
|
+
survivor: "first"
|
|
520
1120
|
};
|
|
521
1121
|
break;
|
|
522
1122
|
}
|
|
@@ -617,8 +1217,11 @@ var CanonicalPublicOperations = class {
|
|
|
617
1217
|
code: "uniformReplacementFormatting"
|
|
618
1218
|
});
|
|
619
1219
|
}
|
|
620
|
-
const
|
|
621
|
-
const
|
|
1220
|
+
const lastCharacter = change.end > change.start ? clean.offsets[change.end - 1] : void 0;
|
|
1221
|
+
const changeEnd = lastCharacter === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, lastCharacter + 1));
|
|
1222
|
+
const edges = gap.from < changeEnd ? projection.value.rangeEdgesAt(gap.from, changeEnd) : void 0;
|
|
1223
|
+
const changeFrom = projection.value.addressAt(gap.from, edges?.start);
|
|
1224
|
+
const changeTo = projection.value.addressAt(changeEnd, edges?.end);
|
|
622
1225
|
if (changeFrom.isErr() || changeTo.isErr()) return refusal("unsupportedBlock");
|
|
623
1226
|
intents.push({
|
|
624
1227
|
type: "replaceText",
|
|
@@ -628,6 +1231,33 @@ var CanonicalPublicOperations = class {
|
|
|
628
1231
|
...intent.runPropsPatch === void 0 ? {} : { runPropsPatch: intent.runPropsPatch }
|
|
629
1232
|
});
|
|
630
1233
|
}
|
|
1234
|
+
} else if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs") {
|
|
1235
|
+
const separator = operation.separator ?? "";
|
|
1236
|
+
if (separator !== "") {
|
|
1237
|
+
const at = projection.value.addressAt(paragraph.start + paragraph.node.content.size);
|
|
1238
|
+
if (at.isErr()) return refusal("unsupportedBlock");
|
|
1239
|
+
intents.push({
|
|
1240
|
+
type: "replaceText",
|
|
1241
|
+
from: at.value,
|
|
1242
|
+
to: at.value,
|
|
1243
|
+
text: separator
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
intents.push(intent);
|
|
1247
|
+
intents.push(...statedPropertiesIntents({
|
|
1248
|
+
story,
|
|
1249
|
+
blockId: tracked ? intent.nextBlockId : intent.blockId,
|
|
1250
|
+
properties: operation.mergedParagraphProperties,
|
|
1251
|
+
mintList
|
|
1252
|
+
}));
|
|
1253
|
+
} else if (operation.type === "splitBlock" && intent.type === "splitParagraph") {
|
|
1254
|
+
intents.push(intent);
|
|
1255
|
+
for (const [half, properties] of [[paragraph.blockId, operation.firstParagraphProperties], [intent.newBlockId, operation.secondParagraphProperties]]) intents.push(...statedPropertiesIntents({
|
|
1256
|
+
story,
|
|
1257
|
+
blockId: half,
|
|
1258
|
+
properties,
|
|
1259
|
+
mintList
|
|
1260
|
+
}));
|
|
631
1261
|
} else intents.push(intent);
|
|
632
1262
|
const structural = operation.type === "splitBlock" || operation.type === "mergeBlockWithNext";
|
|
633
1263
|
const nextParagraph = operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" ? projection.value.paragraph(intent.nextBlockId) : void 0;
|