@stll/folio-core 0.66.2 → 0.68.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 +138 -17
- package/dist/ai-edits/batch-claims.js +5 -3
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +32 -17
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- 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 +29 -12
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +77 -19
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -2
- package/dist/controller/canonicalInput.js +47 -2
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +328 -75
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- 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 +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +10 -3
- package/dist/controller/hiddenEditorManager.js +94 -38
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +55 -18
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +49 -14
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- 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 +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- 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/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 +17 -0
- package/dist/docx/hostCommentThreads.js +49 -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 +227 -96
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- 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/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- 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 +6 -0
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -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 +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +42 -25
- 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 +3 -1
- 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/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/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/shapeAlternateContent.js +19 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- 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/unzip.js +2 -0
- package/dist/docx/verticalMergeProjection.js +1 -1
- 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/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/wholeStoryRevisionResolution.js +57 -12
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/tableConversion.js +25 -10
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- 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.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +34 -7
- package/dist/layout-engine/tableRowBreak.d.ts +46 -0
- package/dist/layout-engine/tableRowBreak.js +193 -36
- package/dist/layout-engine/types.d.ts +43 -3
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +5 -4
- package/dist/layout-painter/renderPage.js +52 -20
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +39 -22
- 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/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/attrs/index.js +1 -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 +25 -0
- package/dist/prosemirror/commands/comments.js +122 -18
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- 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/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +22 -8
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +115 -35
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +325 -55
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +119 -38
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/index.d.ts +2 -2
- 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/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +195 -30
- 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/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -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/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 +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/validation.js +2 -1
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- 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 -2
|
@@ -1,33 +1,44 @@
|
|
|
1
1
|
import { splitsGraphemeCluster, splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
|
|
2
2
|
import { rangedCommentIds, visitCommentMarkers } from "../docx/commentAnchorIndex.js";
|
|
3
|
+
import { ListNormalizationCache } from "../docx/listModelNormalization.js";
|
|
3
4
|
import { cloneDocumentWithParagraphPropertySources, copyDocumentParagraphPropertySourceContract, copyParagraphPropertySource, restoreParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
|
|
5
|
+
import { visitInlineContentSlots } from "../docx/paragraphTraversal.js";
|
|
4
6
|
import { isCellMergeContinuation } from "../docx/tableParser.js";
|
|
5
7
|
import { calculateRowSpans } from "../docx/verticalMergeProjection.js";
|
|
6
8
|
import { canonicalCellSelectionRanges, canonicalContentPosition, canonicalSelectionRange } from "../prosemirror/canonicalSelectionRange.js";
|
|
7
|
-
import {
|
|
9
|
+
import { expectCommentRangeBoundaryAttrs } from "../prosemirror/commentRangeBoundaryAttrs.js";
|
|
10
|
+
import { ProjectionBlockCache, collectPairedBookmarkIds, footnoteToProseDoc, headerFooterToProseDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
|
|
8
11
|
import { markPackageChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
|
|
9
12
|
import { runFormattingPatchFromMarks } from "../prosemirror/runFormattingFromMarks.js";
|
|
10
|
-
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
11
|
-
import { canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline } from "./canonicalInlineProjection.js";
|
|
13
|
+
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
14
|
+
import { InlineProjectionCache, canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline } from "./canonicalInlineProjection.js";
|
|
12
15
|
import { normalizeCanonicalListRendering } from "./canonicalListRendering.js";
|
|
16
|
+
import { lockViolationBetween } from "./canonicalLockGuard.js";
|
|
13
17
|
import { restoreCanonicalSelection } from "./canonicalSelection.js";
|
|
14
18
|
import { mapTocSelection } from "./canonicalTocSelection.js";
|
|
15
19
|
import { Result, TaggedError, panic } from "better-result";
|
|
16
20
|
import { hasIllegalXmlCharacters } from "@stll/docx-core";
|
|
21
|
+
import { lockedControlMessage } from "@stll/docx-core/model";
|
|
17
22
|
import { Fragment } from "prosemirror-model";
|
|
18
23
|
import { CellSelection } from "prosemirror-tables";
|
|
19
|
-
import { DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_TYPES, OP_STORIES, applyDocumentOp, applyDocumentOps, combineEdits, commentDocumentIssue, compileEditorIntent, createEditorIntentIdAllocator, documentStories, editorParagraphGroups, findStoryBody, normalizeForOps, packageParagraphIds, paragraphIdsIn, sameStory, survivingComments, validateOpsDocument } from "@stll/docx-core/ops";
|
|
24
|
+
import { DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_TYPES, OP_STORIES, applyDocumentOp, applyDocumentOps, combineEdits, commentDocumentIssue, compileEditorIntent, createEditorIntentIdAllocator, documentStories, editorParagraphGroups, findStoryBody, normalizeForOps, packageParagraphIds, paragraphIdsIn, sameStory, suggestionRevisionInfos, survivingComments, validateOpsDocument } from "@stll/docx-core/ops";
|
|
20
25
|
import { AllSelection, NodeSelection, Selection, TextSelection } from "prosemirror-state";
|
|
21
26
|
// src/controller/canonicalSession.ts
|
|
22
27
|
const CanonicalSessionErrorBase = TaggedError("CanonicalSessionError");
|
|
23
28
|
var CanonicalSessionError = class extends CanonicalSessionErrorBase {};
|
|
24
29
|
const refuse = (message) => Result.err(new CanonicalSessionError({
|
|
25
|
-
gap: CANONICAL_GAP.dispatch,
|
|
30
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
26
31
|
message,
|
|
27
32
|
reason: "refused"
|
|
28
33
|
}));
|
|
34
|
+
/** A change a content control's lock forbids: the document's rule, not a gap. */
|
|
35
|
+
const lockRefusal = (violation) => Result.err(new CanonicalSessionError({
|
|
36
|
+
ground: { rule: CANONICAL_RULE.contentControlLock },
|
|
37
|
+
message: `Refused: ${lockedControlMessage(violation)}`,
|
|
38
|
+
reason: "refused"
|
|
39
|
+
}));
|
|
29
40
|
const noChange = (message) => Result.err(new CanonicalSessionError({
|
|
30
|
-
gap: CANONICAL_GAP.dispatch,
|
|
41
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
31
42
|
message,
|
|
32
43
|
reason: "noChange"
|
|
33
44
|
}));
|
|
@@ -80,7 +91,12 @@ const operationChangesStructure = (op) => {
|
|
|
80
91
|
case DOCUMENT_OP_TYPES.MERGE_CELLS:
|
|
81
92
|
case DOCUMENT_OP_TYPES.SPLIT_CELL:
|
|
82
93
|
case DOCUMENT_OP_TYPES.SET_TABLE:
|
|
83
|
-
case DOCUMENT_OP_TYPES.RESOLVE_REVISION:
|
|
94
|
+
case DOCUMENT_OP_TYPES.RESOLVE_REVISION:
|
|
95
|
+
case DOCUMENT_OP_TYPES.SET_TABLE_GRID:
|
|
96
|
+
case DOCUMENT_OP_TYPES.SET_CELL_PROPS:
|
|
97
|
+
case DOCUMENT_OP_TYPES.SET_ROW_PROPS:
|
|
98
|
+
case DOCUMENT_OP_TYPES.SET_TABLE_PROPS:
|
|
99
|
+
case DOCUMENT_OP_TYPES.SET_REVISION_INFO: return true;
|
|
84
100
|
case DOCUMENT_OP_TYPES.CREATE_HEADER_FOOTER:
|
|
85
101
|
case DOCUMENT_OP_TYPES.REMOVE_HEADER_FOOTER:
|
|
86
102
|
case DOCUMENT_OP_TYPES.ADD_NOTE:
|
|
@@ -100,10 +116,6 @@ const operationChangesStructure = (op) => {
|
|
|
100
116
|
case DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS:
|
|
101
117
|
case DOCUMENT_OP_TYPES.SET_PARAGRAPH_REVIEW:
|
|
102
118
|
case DOCUMENT_OP_TYPES.REPLACE_INLINE:
|
|
103
|
-
case DOCUMENT_OP_TYPES.SET_TABLE_GRID:
|
|
104
|
-
case DOCUMENT_OP_TYPES.SET_CELL_PROPS:
|
|
105
|
-
case DOCUMENT_OP_TYPES.SET_ROW_PROPS:
|
|
106
|
-
case DOCUMENT_OP_TYPES.SET_TABLE_PROPS:
|
|
107
119
|
case DOCUMENT_OP_TYPES.CREATE_COMMENT:
|
|
108
120
|
case DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT:
|
|
109
121
|
case DOCUMENT_OP_TYPES.SET_COMMENT_RESOLUTION:
|
|
@@ -138,7 +150,7 @@ const operationChangesBodyProjection = (op) => {
|
|
|
138
150
|
};
|
|
139
151
|
const CANONICAL_PROJECTION_META = "folioCanonicalProjection";
|
|
140
152
|
/** Paragraph gaps bind logical units and source zero-width ordinals to PM positions. */
|
|
141
|
-
var CanonicalProjection = class {
|
|
153
|
+
var CanonicalProjection = class CanonicalProjection {
|
|
142
154
|
doc;
|
|
143
155
|
story;
|
|
144
156
|
paragraphs;
|
|
@@ -149,7 +161,20 @@ var CanonicalProjection = class {
|
|
|
149
161
|
this.paragraphs = paragraphs;
|
|
150
162
|
this.paragraphsById = new Map(paragraphs.map((paragraph) => [paragraph.blockId, paragraph]));
|
|
151
163
|
}
|
|
152
|
-
|
|
164
|
+
/**
|
|
165
|
+
* The same projection held as `doc`, a document equal to this one's. A
|
|
166
|
+
* commit's transaction ends on a document equal to the projection it staged,
|
|
167
|
+
* sharing the blocks it left; holding that document lets the next commit see
|
|
168
|
+
* the state it was given is the projection without comparing every node.
|
|
169
|
+
*/
|
|
170
|
+
heldAs(doc) {
|
|
171
|
+
return new CanonicalProjection({
|
|
172
|
+
doc,
|
|
173
|
+
paragraphs: this.paragraphs,
|
|
174
|
+
story: this.story
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
addressAt(position, edge = "caret") {
|
|
153
178
|
if (!Number.isInteger(position)) return refuse("The input position is not an integer.");
|
|
154
179
|
position = canonicalContentPosition(this.doc, position);
|
|
155
180
|
const paragraph = this.paragraphs.find(({ start, node }) => position >= start && position <= start + node.content.size);
|
|
@@ -159,32 +184,67 @@ var CanonicalProjection = class {
|
|
|
159
184
|
if (offset < 0) return refuse("The input splits an indivisible inline element.");
|
|
160
185
|
if (splitsSurrogatePair(paragraph.text, offset)) return refuse("The input would split a surrogate pair.");
|
|
161
186
|
const gaps = paragraph.boundaries.at(offset) ?? panic("Missing canonical boundary");
|
|
162
|
-
const
|
|
187
|
+
const index = gaps.findIndex((entry) => entry.position === relative);
|
|
188
|
+
const gap = gaps[index] ?? panic("Missing canonical native gap");
|
|
189
|
+
const seam = paragraph.seams.at(offset)?.[index] ?? panic("Missing canonical seam");
|
|
190
|
+
let ordinal = gap.zeroWidthBefore;
|
|
191
|
+
if (edge === "afterMarkers") ordinal = seam.last;
|
|
192
|
+
if (edge === "beforeMarkers") ordinal = seam.first;
|
|
163
193
|
return Result.ok({
|
|
164
194
|
story: this.story,
|
|
165
195
|
blockId: paragraph.blockId,
|
|
166
196
|
offset,
|
|
167
|
-
...gaps.length > 1 ||
|
|
197
|
+
...gaps.length > 1 || ordinal > 0 || seam.first !== seam.last ? { zeroWidthBefore: ordinal } : {}
|
|
168
198
|
});
|
|
169
199
|
}
|
|
170
|
-
|
|
171
|
-
|
|
200
|
+
/**
|
|
201
|
+
* The source gaps a selection from `from` to `to` replaces between. Its
|
|
202
|
+
* edges stay inside the markers beside them, so replacing exactly the
|
|
203
|
+
* words a comment covers keeps the comment on the new text. A selection of
|
|
204
|
+
* a paragraph's whole text takes that paragraph's markers with it: an edge
|
|
205
|
+
* at the very start of a paragraph whose text the selection covers to its
|
|
206
|
+
* end reaches before the markers there, and an edge at the very end of a
|
|
207
|
+
* paragraph the selection covers from its start reaches after them, so a
|
|
208
|
+
* comment on nothing but the replaced text is emptied, as removing the
|
|
209
|
+
* text would empty it.
|
|
210
|
+
*/
|
|
211
|
+
rangeEdgesAt(from, to) {
|
|
212
|
+
const paragraphOf = (position) => {
|
|
213
|
+
const content = canonicalContentPosition(this.doc, position);
|
|
214
|
+
return this.paragraphs.find(({ start, node }) => content >= start && content <= start + node.content.size);
|
|
215
|
+
};
|
|
216
|
+
const first = paragraphOf(from);
|
|
217
|
+
const last = paragraphOf(to);
|
|
218
|
+
const startsWhole = first !== void 0 && canonicalContentPosition(this.doc, from) === first.start && canonicalContentPosition(this.doc, to) >= first.start + first.node.content.size;
|
|
219
|
+
const endsWhole = last !== void 0 && canonicalContentPosition(this.doc, to) === last.start + last.node.content.size && canonicalContentPosition(this.doc, from) <= last.start;
|
|
220
|
+
return {
|
|
221
|
+
start: startsWhole ? "beforeMarkers" : "afterMarkers",
|
|
222
|
+
end: endsWhole ? "afterMarkers" : "beforeMarkers"
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
inputAddressAt(position, edge = "caret") {
|
|
226
|
+
const address = this.addressAt(position, edge);
|
|
172
227
|
if (address.isErr()) return address;
|
|
173
228
|
const paragraph = this.paragraph(address.value.blockId);
|
|
174
229
|
if (paragraph === void 0) panic("Input lost its paragraph.");
|
|
175
230
|
let destination = position;
|
|
176
231
|
paragraph.node.forEach((node, start) => {
|
|
177
|
-
if (node.marks.some((mark) => mark.type.name === "deletion") && destination
|
|
232
|
+
if (node.marks.some((mark) => mark.type.name === "deletion") && destination > paragraph.start + start && destination < paragraph.start + start + node.nodeSize) destination = paragraph.start + start + node.nodeSize;
|
|
178
233
|
});
|
|
179
|
-
return destination === position ? address : this.addressAt(destination);
|
|
234
|
+
return destination === position ? address : this.addressAt(destination, edge);
|
|
180
235
|
}
|
|
181
236
|
positionAt(address) {
|
|
182
237
|
const paragraph = this.paragraph(address.blockId);
|
|
183
238
|
if (!sameStory(address.story, this.story) || paragraph === void 0 || !Number.isInteger(address.offset) || address.offset < 0 || address.offset > paragraph.text.length || splitsSurrogatePair(paragraph.text, address.offset)) return refuse("The canonical selection is outside a plain paragraph.");
|
|
184
239
|
const gaps = paragraph.boundaries.at(address.offset) ?? panic("Missing canonical boundary");
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
240
|
+
const seams = paragraph.seams.at(address.offset) ?? panic("Missing canonical seams");
|
|
241
|
+
const lastOrdinal = (seams.at(-1) ?? panic("Missing canonical seam")).last;
|
|
242
|
+
const ordinal = address.zeroWidthBefore ?? lastOrdinal;
|
|
243
|
+
const gap = gaps.find(({ zeroWidthBefore }) => zeroWidthBefore === ordinal) ?? gaps.find((_, index) => {
|
|
244
|
+
const seam = seams[index];
|
|
245
|
+
return seam !== void 0 && seam.first <= ordinal && ordinal <= seam.last;
|
|
246
|
+
});
|
|
247
|
+
if (!Number.isInteger(ordinal) || ordinal < 0 || ordinal > lastOrdinal) return refuse("The canonical selection is outside a paragraph gap.");
|
|
188
248
|
if (gap === void 0) return refuse("This source gap is inside a collapsed or erased inline boundary and has no editor position.");
|
|
189
249
|
return Result.ok(paragraph.start + gap.position);
|
|
190
250
|
}
|
|
@@ -215,6 +275,10 @@ var CanonicalProjection = class {
|
|
|
215
275
|
head: head.value
|
|
216
276
|
});
|
|
217
277
|
}
|
|
278
|
+
/** The first paragraph the projection addresses, in document order. */
|
|
279
|
+
get firstParagraph() {
|
|
280
|
+
return this.paragraphs.at(0);
|
|
281
|
+
}
|
|
218
282
|
paragraph(blockId) {
|
|
219
283
|
return this.paragraphsById.get(blockId);
|
|
220
284
|
}
|
|
@@ -305,6 +369,13 @@ const unsupportedSeedReason = (document, stories = documentStories(document)) =>
|
|
|
305
369
|
paragraphs.push(block);
|
|
306
370
|
continue;
|
|
307
371
|
}
|
|
372
|
+
if (block.type === "commentRangeStart" || block.type === "commentRangeEnd" || block.type === "bookmarkStart" || block.type === "bookmarkEnd" || block.type === "moveFromRangeStart" || block.type === "moveFromRangeEnd" || block.type === "moveToRangeStart" || block.type === "moveToRangeEnd") continue;
|
|
373
|
+
if (block.type === "preservedBlock") continue;
|
|
374
|
+
if (block.type === "blockSdt") {
|
|
375
|
+
const issue = collect(block.content);
|
|
376
|
+
if (issue !== null) return issue;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
308
379
|
if (block.type !== "table") return "Canonical sessions currently require paragraphs, tables and supported inline atoms.";
|
|
309
380
|
for (const row of block.rows) for (const cell of row.cells) {
|
|
310
381
|
const issue = collect(cell.content);
|
|
@@ -323,7 +394,20 @@ const unsupportedSeedReason = (document, stories = documentStories(document)) =>
|
|
|
323
394
|
}
|
|
324
395
|
return null;
|
|
325
396
|
};
|
|
326
|
-
const
|
|
397
|
+
const newStoryProjectionCaches = () => ({
|
|
398
|
+
blocks: new ProjectionBlockCache(),
|
|
399
|
+
inline: new InlineProjectionCache(),
|
|
400
|
+
lists: new ListNormalizationCache()
|
|
401
|
+
});
|
|
402
|
+
/** Whether a paragraph anchors a text box, which converts to a block of its own. */
|
|
403
|
+
const holdsTextBox = (paragraph) => {
|
|
404
|
+
let found = false;
|
|
405
|
+
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
406
|
+
if (item.type === "run" && item.content.some((content) => content.type === "shape" && content.shape.textBody !== void 0)) found = true;
|
|
407
|
+
});
|
|
408
|
+
return found;
|
|
409
|
+
};
|
|
410
|
+
const project = ({ document, styles, story = OP_STORIES.MAIN, caches }) => {
|
|
327
411
|
const body = findStoryBody(document, story);
|
|
328
412
|
if (!body) return refuse("The canonical story no longer exists.");
|
|
329
413
|
const currentStyles = Object.hasOwn(document.package, "styles") ? document.package.styles : styles;
|
|
@@ -333,12 +417,15 @@ const project = ({ document, styles, story = OP_STORIES.MAIN }) => {
|
|
|
333
417
|
};
|
|
334
418
|
const converted = Result.try({
|
|
335
419
|
try: () => {
|
|
336
|
-
if (story === OP_STORIES.MAIN) return toProseDoc(document, options
|
|
420
|
+
if (story === OP_STORIES.MAIN) return toProseDoc(document, caches === void 0 ? options : {
|
|
421
|
+
...options,
|
|
422
|
+
blockCache: caches.blocks
|
|
423
|
+
});
|
|
337
424
|
if (story.kind === "header" || story.kind === "footer") return headerFooterToProseDoc(body.content, options);
|
|
338
425
|
return footnoteToProseDoc(body.content, options);
|
|
339
426
|
},
|
|
340
427
|
catch: (cause) => new CanonicalSessionError({
|
|
341
|
-
gap: CANONICAL_GAP.dispatch,
|
|
428
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
342
429
|
reason: "refused",
|
|
343
430
|
message: `Canonical projection failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
344
431
|
})
|
|
@@ -367,6 +454,10 @@ const project = ({ document, styles, story = OP_STORIES.MAIN }) => {
|
|
|
367
454
|
});
|
|
368
455
|
continue;
|
|
369
456
|
}
|
|
457
|
+
if (block.type === "blockSdt") {
|
|
458
|
+
collectSources(block.content, insideSkippedContinuation);
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
370
461
|
if (block.type !== "table") continue;
|
|
371
462
|
const rowSpans = calculateRowSpans(block);
|
|
372
463
|
for (const [rowIndex, row] of block.rows.entries()) {
|
|
@@ -382,43 +473,77 @@ const project = ({ document, styles, story = OP_STORIES.MAIN }) => {
|
|
|
382
473
|
collectSources(body.content);
|
|
383
474
|
const paragraphs = [];
|
|
384
475
|
const projectedSources = /* @__PURE__ */ new Set();
|
|
476
|
+
const orderedSources = [...allSources];
|
|
477
|
+
const sourceOrder = new Map(orderedSources.map((source, index) => [source, index]));
|
|
478
|
+
const textBoxHosts = /* @__PURE__ */ new Set();
|
|
479
|
+
let nextSource = 0;
|
|
480
|
+
const claimTextBoxHost = () => {
|
|
481
|
+
let index = nextSource;
|
|
482
|
+
while (index < orderedSources.length && continuationSources.has(orderedSources[index] ?? panic("No source"))) index += 1;
|
|
483
|
+
const host = orderedSources[index];
|
|
484
|
+
if (host === void 0 || !holdsTextBox(host)) return false;
|
|
485
|
+
textBoxHosts.add(host);
|
|
486
|
+
nextSource = index + 1;
|
|
487
|
+
visitCommentMarkers([host], ({ item }) => {
|
|
488
|
+
if (item.type === "commentRangeStart") commentContext.openIds.add(item.id);
|
|
489
|
+
if (item.type === "commentRangeEnd") commentContext.openIds.delete(item.id);
|
|
490
|
+
});
|
|
491
|
+
return true;
|
|
492
|
+
};
|
|
385
493
|
let failure;
|
|
386
|
-
converted.value.descendants((node, offset) => {
|
|
387
|
-
if (failure !== void 0) return;
|
|
388
|
-
if (node.type.name
|
|
494
|
+
converted.value.descendants((node, offset, parent) => {
|
|
495
|
+
if (failure !== void 0) return false;
|
|
496
|
+
if (node.type.name === "textBox") {
|
|
497
|
+
if (node.attrs["_docxPlacement"] === "standalone" && node.attrs["_docxHostParagraph"] != null && !claimTextBoxHost()) failure = new CanonicalSessionError({
|
|
498
|
+
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
499
|
+
reason: "refused",
|
|
500
|
+
message: "The projection changed paragraph structure."
|
|
501
|
+
});
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
if (node.type.name === "blockCommentRangeBoundary") {
|
|
505
|
+
const { marker } = expectCommentRangeBoundaryAttrs(node);
|
|
506
|
+
if (marker.type === "commentRangeStart") commentContext.openIds.add(marker.id);
|
|
507
|
+
else commentContext.openIds.delete(marker.id);
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
if (node.type.name !== "paragraph") return true;
|
|
511
|
+
if (parent?.attrs["_omittedGridSlot"] != null) return false;
|
|
389
512
|
const paraId = node.attrs["paraId"];
|
|
390
513
|
const located = typeof paraId === "string" ? sources.get(paraId) : void 0;
|
|
391
514
|
if (typeof paraId !== "string" || located === void 0) {
|
|
392
515
|
failure = new CanonicalSessionError({
|
|
393
|
-
gap: CANONICAL_GAP.storyContentProjection,
|
|
516
|
+
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
394
517
|
reason: "refused",
|
|
395
518
|
message: "The projection changed paragraph structure."
|
|
396
519
|
});
|
|
397
|
-
return;
|
|
520
|
+
return false;
|
|
398
521
|
}
|
|
399
522
|
const { source, container } = located;
|
|
400
523
|
if (projectedSources.has(source)) {
|
|
401
524
|
failure = new CanonicalSessionError({
|
|
402
|
-
gap: CANONICAL_GAP.storyContentProjection,
|
|
525
|
+
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
403
526
|
reason: "refused",
|
|
404
527
|
message: "The projection changed paragraph structure."
|
|
405
528
|
});
|
|
406
|
-
return;
|
|
529
|
+
return false;
|
|
407
530
|
}
|
|
408
531
|
projectedSources.add(source);
|
|
409
|
-
|
|
532
|
+
nextSource = (sourceOrder.get(source) ?? panic("Unordered source")) + 1;
|
|
533
|
+
const inlineArgs = {
|
|
410
534
|
source,
|
|
411
535
|
paragraph: node,
|
|
412
536
|
pairedBookmarkIds,
|
|
413
537
|
commentContext
|
|
414
|
-
}
|
|
538
|
+
};
|
|
539
|
+
const inline = caches === void 0 ? projectCanonicalInline(inlineArgs) : caches.inline.project(inlineArgs);
|
|
415
540
|
if (inline.isErr()) {
|
|
416
541
|
failure = new CanonicalSessionError({
|
|
417
|
-
gap: CANONICAL_GAP.dispatch,
|
|
542
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
418
543
|
reason: "refused",
|
|
419
544
|
message: inline.error.message
|
|
420
545
|
});
|
|
421
|
-
return;
|
|
546
|
+
return false;
|
|
422
547
|
}
|
|
423
548
|
paragraphs.push({
|
|
424
549
|
blockId: paraId,
|
|
@@ -432,9 +557,10 @@ const project = ({ document, styles, story = OP_STORIES.MAIN }) => {
|
|
|
432
557
|
if (item.type === "commentRangeStart") commentContext.openIds.add(item.id);
|
|
433
558
|
if (item.type === "commentRangeEnd") commentContext.openIds.delete(item.id);
|
|
434
559
|
});
|
|
560
|
+
return false;
|
|
435
561
|
});
|
|
436
562
|
if (failure !== void 0) return Result.err(failure);
|
|
437
|
-
if (projectedSources.size + continuationSources.size !== allSources.size || [...projectedSources].some((source) => continuationSources.has(source))) return refuse("The projection changed paragraph structure.");
|
|
563
|
+
if (projectedSources.size + continuationSources.size + textBoxHosts.size !== allSources.size || [...projectedSources].some((source) => continuationSources.has(source) || textBoxHosts.has(source)) || [...textBoxHosts].some((source) => continuationSources.has(source))) return refuse("The projection changed paragraph structure.");
|
|
438
564
|
return Result.ok(new CanonicalProjection({
|
|
439
565
|
doc: converted.value,
|
|
440
566
|
paragraphs,
|
|
@@ -455,8 +581,11 @@ const intentStory = (intent) => {
|
|
|
455
581
|
case "splitParagraph":
|
|
456
582
|
case "formatParagraph": return intent.at.story;
|
|
457
583
|
case "setList": return intent.items.at(0)?.at.story ?? panic("A list intent requires a paragraph.");
|
|
458
|
-
case "joinParagraphs":
|
|
459
|
-
case "
|
|
584
|
+
case "joinParagraphs":
|
|
585
|
+
case "insertParagraphs": return intent.story;
|
|
586
|
+
case "table":
|
|
587
|
+
case "tableRow":
|
|
588
|
+
case "tableBlock": return intent.operation.story;
|
|
460
589
|
default: return intent;
|
|
461
590
|
}
|
|
462
591
|
};
|
|
@@ -490,7 +619,7 @@ const publishCanonicalProjection = ({ state, commit, session }) => {
|
|
|
490
619
|
const applied = Result.try({
|
|
491
620
|
try: () => state.applyTransaction(commit.transaction),
|
|
492
621
|
catch: (cause) => new CanonicalSessionError({
|
|
493
|
-
gap: CANONICAL_GAP.dispatch,
|
|
622
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
494
623
|
reason: "refused",
|
|
495
624
|
message: `Canonical plugin staging failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
496
625
|
})
|
|
@@ -531,7 +660,10 @@ var CanonicalSession = class {
|
|
|
531
660
|
lifecycle = { type: "committed" };
|
|
532
661
|
undone = [];
|
|
533
662
|
styles;
|
|
534
|
-
|
|
663
|
+
/** What earlier projections converted, reused by every later one. */
|
|
664
|
+
caches;
|
|
665
|
+
constructor({ document, projection, styles, caches }) {
|
|
666
|
+
this.caches = caches;
|
|
535
667
|
this.currentDocument = document;
|
|
536
668
|
this.currentProjection = projection;
|
|
537
669
|
this.sourceBlockIds = new Set(packageParagraphIds(document.package));
|
|
@@ -606,7 +738,10 @@ var CanonicalSession = class {
|
|
|
606
738
|
intentNeedsIdentityIds(document, intent) {
|
|
607
739
|
let blockIds;
|
|
608
740
|
switch (intent.type) {
|
|
609
|
-
case "table":
|
|
741
|
+
case "table":
|
|
742
|
+
case "tableRow":
|
|
743
|
+
case "tableBlock":
|
|
744
|
+
case "insertParagraphs": return true;
|
|
610
745
|
case "generateTOC":
|
|
611
746
|
case "setList":
|
|
612
747
|
case "formatParagraph": return false;
|
|
@@ -647,7 +782,7 @@ var CanonicalSession = class {
|
|
|
647
782
|
}
|
|
648
783
|
get document() {
|
|
649
784
|
if (this.isComposing) throw new CanonicalSessionError({
|
|
650
|
-
gap: CANONICAL_GAP.dispatch,
|
|
785
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
651
786
|
reason: "refused",
|
|
652
787
|
message: "Composition must finish before taking a snapshot."
|
|
653
788
|
});
|
|
@@ -655,7 +790,7 @@ var CanonicalSession = class {
|
|
|
655
790
|
}
|
|
656
791
|
captureSaveSnapshot() {
|
|
657
792
|
if (this.isComposing) throw new CanonicalSessionError({
|
|
658
|
-
gap: CANONICAL_GAP.save,
|
|
793
|
+
ground: { gap: CANONICAL_GAP.save },
|
|
659
794
|
reason: "refused",
|
|
660
795
|
message: "Composition must finish before saving the canonical document."
|
|
661
796
|
});
|
|
@@ -670,6 +805,13 @@ var CanonicalSession = class {
|
|
|
670
805
|
get projection() {
|
|
671
806
|
return this.currentProjection;
|
|
672
807
|
}
|
|
808
|
+
/** The caret the last published edit returned, when the editor shows it at `position`. */
|
|
809
|
+
editCaretAt(projection, position) {
|
|
810
|
+
const caret = this.currentSelection;
|
|
811
|
+
if (caret === null || caret.type !== "text" || caret.anchor.offset !== caret.head.offset || caret.anchor.blockId !== caret.head.blockId || (caret.anchor.zeroWidthBefore ?? null) !== (caret.head.zeroWidthBefore ?? null) || !sameStory(caret.head.story, projection.story)) return void 0;
|
|
812
|
+
const shown = projection.positionAt(caret.head);
|
|
813
|
+
return shown.isOk() && shown.value === position ? caret.head : void 0;
|
|
814
|
+
}
|
|
673
815
|
get selection() {
|
|
674
816
|
return this.currentSelection;
|
|
675
817
|
}
|
|
@@ -700,7 +842,7 @@ var CanonicalSession = class {
|
|
|
700
842
|
}
|
|
701
843
|
checkState(state, projection = this.projection) {
|
|
702
844
|
if (this.isComposing) return refuse("Composition must finish before committing another edit.");
|
|
703
|
-
if (!state.doc.eq(projection.doc)) return refuse("The input uses a stale canonical projection.");
|
|
845
|
+
if (state.doc !== projection.doc && !state.doc.eq(projection.doc)) return refuse("The input uses a stale canonical projection.");
|
|
704
846
|
return Result.ok(void 0);
|
|
705
847
|
}
|
|
706
848
|
prepareReplace(state, { from, to, text, story = OP_STORIES.MAIN, semantic = "replacement", compositionPhase, time = Date.now() }) {
|
|
@@ -715,19 +857,21 @@ var CanonicalSession = class {
|
|
|
715
857
|
const replacesStructuralSelection = state.selection instanceof AllSelection && from === state.selection.from && to === state.selection.to;
|
|
716
858
|
if (state.selection instanceof CellSelection) {
|
|
717
859
|
if (from !== state.selection.from || to !== state.selection.to) return refuse("A replacement range cannot partially address a cell selection.");
|
|
718
|
-
if (text.length > 0) return refuse("Replacing a cell selection requires a per-cell replacement.");
|
|
719
860
|
const intents = [];
|
|
861
|
+
let first = true;
|
|
720
862
|
for (const range of canonicalCellSelectionRanges(state.selection)) {
|
|
721
|
-
const
|
|
863
|
+
const edges = projection.rangeEdgesAt(range.from, range.to);
|
|
864
|
+
const cellFrom = projection.inputAddressAt(range.from, edges.start);
|
|
722
865
|
if (cellFrom.isErr()) return cellFrom;
|
|
723
|
-
const cellTo = projection.inputAddressAt(range.to);
|
|
866
|
+
const cellTo = projection.inputAddressAt(range.to, edges.end);
|
|
724
867
|
if (cellTo.isErr()) return cellTo;
|
|
725
868
|
intents.push({
|
|
726
869
|
type: "replaceText",
|
|
727
870
|
from: cellFrom.value,
|
|
728
871
|
to: cellTo.value,
|
|
729
|
-
text: ""
|
|
872
|
+
text: first ? text : ""
|
|
730
873
|
});
|
|
874
|
+
first = false;
|
|
731
875
|
}
|
|
732
876
|
return this.prepareIntents(state, {
|
|
733
877
|
intents,
|
|
@@ -737,17 +881,32 @@ var CanonicalSession = class {
|
|
|
737
881
|
const range = canonicalSelectionRange(state);
|
|
738
882
|
const inputFrom = replacesStructuralSelection ? range.from : from;
|
|
739
883
|
const inputTo = replacesStructuralSelection ? range.to : to;
|
|
740
|
-
const
|
|
884
|
+
const edges = inputFrom === inputTo ? {
|
|
885
|
+
start: "caret",
|
|
886
|
+
end: "caret"
|
|
887
|
+
} : projection.rangeEdgesAt(inputFrom, inputTo);
|
|
888
|
+
const editCaret = this.editCaretAt(projection, inputFrom);
|
|
889
|
+
const start = inputFrom === inputTo && editCaret !== void 0 ? Result.ok(editCaret) : projection.inputAddressAt(inputFrom, edges.start);
|
|
741
890
|
if (start.isErr()) return start;
|
|
742
|
-
const end = projection.inputAddressAt(inputTo);
|
|
891
|
+
const end = inputFrom === inputTo && editCaret !== void 0 ? Result.ok(editCaret) : projection.inputAddressAt(inputTo, edges.end);
|
|
743
892
|
if (end.isErr()) return end;
|
|
744
893
|
const preSelection = projection.selectionAt(state);
|
|
745
894
|
if (preSelection.isErr()) return preSelection;
|
|
895
|
+
const innerEdge = (position, side) => {
|
|
896
|
+
const resolved = state.doc.resolve(position);
|
|
897
|
+
return resolved.parent.type.name === "sdt" && resolved.parentOffset === (side === "start" ? 0 : resolved.parent.content.size);
|
|
898
|
+
};
|
|
899
|
+
const inside = {
|
|
900
|
+
...innerEdge(inputFrom, "start") ? { start: true } : {},
|
|
901
|
+
...innerEdge(inputTo, "end") ? { end: true } : {}
|
|
902
|
+
};
|
|
903
|
+
if (this.mode.type === "suggesting" && text.length > 0 && inside.start === true && inside.end === true && state.doc.resolve(inputFrom).parent === state.doc.resolve(inputTo).parent) return refuse("A suggestion over a content control's whole text is unavailable in this session.");
|
|
746
904
|
const intent = {
|
|
747
905
|
type: "replaceText",
|
|
748
906
|
from: start.value,
|
|
749
907
|
to: end.value,
|
|
750
908
|
text,
|
|
909
|
+
...Object.keys(inside).length === 0 ? {} : { inside },
|
|
751
910
|
...state.storedMarks === null ? {} : { runPropsPatch: runFormattingPatchFromMarks(state.selection.$from.marks(), state.storedMarks) }
|
|
752
911
|
};
|
|
753
912
|
const compiled = compileEditorIntent(this.currentDocument, {
|
|
@@ -802,6 +961,44 @@ var CanonicalSession = class {
|
|
|
802
961
|
}
|
|
803
962
|
});
|
|
804
963
|
}
|
|
964
|
+
/**
|
|
965
|
+
* A structural edit over selected cells: each selected cell is cleared and
|
|
966
|
+
* the edit happens at the start of the first, as the editor's own command
|
|
967
|
+
* does over a cell selection. One commit, so one undo step.
|
|
968
|
+
*/
|
|
969
|
+
prepareCellSelectionStructure(state, structure, { resourceOps = [], semantic = "structure" } = {}) {
|
|
970
|
+
if (!(state.selection instanceof CellSelection)) return refuse("The structural edit needs a cell selection.");
|
|
971
|
+
const projected = this.projectStory(OP_STORIES.MAIN);
|
|
972
|
+
if (projected.isErr()) return projected;
|
|
973
|
+
const projection = projected.value;
|
|
974
|
+
const intents = [];
|
|
975
|
+
let first;
|
|
976
|
+
for (const range of canonicalCellSelectionRanges(state.selection)) {
|
|
977
|
+
const edges = projection.rangeEdgesAt(range.from, range.to);
|
|
978
|
+
const cellFrom = projection.inputAddressAt(range.from, edges.start);
|
|
979
|
+
if (cellFrom.isErr()) return cellFrom;
|
|
980
|
+
const cellTo = projection.inputAddressAt(range.to, edges.end);
|
|
981
|
+
if (cellTo.isErr()) return cellTo;
|
|
982
|
+
first ??= cellFrom.value;
|
|
983
|
+
if (cellFrom.value.blockId !== cellTo.value.blockId || cellFrom.value.offset !== cellTo.value.offset) intents.push({
|
|
984
|
+
type: "replaceText",
|
|
985
|
+
from: cellFrom.value,
|
|
986
|
+
to: cellTo.value,
|
|
987
|
+
text: ""
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
if (first === void 0) return refuse("The cell selection is empty.");
|
|
991
|
+
intents.push(structure({
|
|
992
|
+
...first,
|
|
993
|
+
offset: 0,
|
|
994
|
+
zeroWidthBefore: 0
|
|
995
|
+
}));
|
|
996
|
+
return this.prepareIntents(state, {
|
|
997
|
+
intents,
|
|
998
|
+
resourceOps,
|
|
999
|
+
semantic
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
805
1002
|
prepareIntent(state, intent) {
|
|
806
1003
|
return this.prepareIntents(state, { intents: [intent] });
|
|
807
1004
|
}
|
|
@@ -828,7 +1025,7 @@ var CanonicalSession = class {
|
|
|
828
1025
|
}
|
|
829
1026
|
for (const intent of intents) {
|
|
830
1027
|
if (this.mode.type === "suggesting" && (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink" || intent.type === "generateTOC")) return Result.err(new CanonicalSessionError({
|
|
831
|
-
gap: CANONICAL_GAP.trackedHyperlinkResolution,
|
|
1028
|
+
ground: { gap: CANONICAL_GAP.trackedHyperlinkResolution },
|
|
832
1029
|
reason: "refused",
|
|
833
1030
|
message: "Hyperlink and TOC suggestions require serializable wrapper review provenance."
|
|
834
1031
|
}));
|
|
@@ -840,7 +1037,7 @@ var CanonicalSession = class {
|
|
|
840
1037
|
if (compiled.isErr()) {
|
|
841
1038
|
if (compiled.error.reason === DOCUMENT_OP_REFUSAL_REASONS.NO_CHANGE) return noChange(compiled.error.message);
|
|
842
1039
|
if (compiled.error.reason === DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE && (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink")) return Result.err(new CanonicalSessionError({
|
|
843
|
-
gap: CANONICAL_GAP.trackedHyperlinkResolution,
|
|
1040
|
+
ground: { gap: CANONICAL_GAP.trackedHyperlinkResolution },
|
|
844
1041
|
reason: "refused",
|
|
845
1042
|
message: compiled.error.message
|
|
846
1043
|
}));
|
|
@@ -967,8 +1164,7 @@ var CanonicalSession = class {
|
|
|
967
1164
|
const second = secondGroup?.paragraphs.at(0);
|
|
968
1165
|
if (!first?.paraId || !second?.paraId) return noChange("There is no adjacent paragraph to join.");
|
|
969
1166
|
if (this.projection.paragraph(first.paraId)?.container !== this.projection.paragraph(second.paraId)?.container) return noChange("There is no adjacent paragraph to join.");
|
|
970
|
-
|
|
971
|
-
if (current === void 0 || at.value.offset !== (direction === "backward" ? 0 : current.text.length)) return refuse("Join requires a caret at a paragraph boundary.");
|
|
1167
|
+
if (!isCanonicalJoinBoundary(state, direction)) return refuse("Join requires a caret at a paragraph boundary.");
|
|
972
1168
|
return this.prepareIntent(state, {
|
|
973
1169
|
type: "joinParagraphs",
|
|
974
1170
|
story: at.value.story,
|
|
@@ -981,30 +1177,41 @@ var CanonicalSession = class {
|
|
|
981
1177
|
if (checked.isErr()) return checked;
|
|
982
1178
|
const preSelection = this.projection.selectionAt(state);
|
|
983
1179
|
if (preSelection.isErr()) return preSelection;
|
|
984
|
-
const
|
|
1180
|
+
const resolve = (ids) => [{
|
|
985
1181
|
type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
|
|
986
1182
|
story: OP_STORIES.MAIN,
|
|
987
|
-
revisionIds,
|
|
1183
|
+
revisionIds: ids,
|
|
988
1184
|
decision: resolution
|
|
989
1185
|
}];
|
|
1186
|
+
let firstHeld = null;
|
|
1187
|
+
const lockHeld = revisionIds.filter((id) => {
|
|
1188
|
+
const alone = applyDocumentOps(this.currentDocument, resolve([id]));
|
|
1189
|
+
if (alone.isErr()) return false;
|
|
1190
|
+
const violation = lockViolationBetween(this.currentDocument, alone.value.document);
|
|
1191
|
+
firstHeld ??= violation;
|
|
1192
|
+
return violation !== null;
|
|
1193
|
+
});
|
|
1194
|
+
if (firstHeld !== null && lockHeld.length === revisionIds.length) return lockRefusal(firstHeld);
|
|
1195
|
+
const ops = resolve(revisionIds.filter((id) => !lockHeld.includes(id)));
|
|
990
1196
|
const applied = applyDocumentOps(this.currentDocument, ops);
|
|
991
1197
|
if (applied.isErr()) return refuse(applied.error.message);
|
|
992
1198
|
const projected = project({
|
|
993
1199
|
document: applied.value.document,
|
|
994
|
-
styles: this.styles
|
|
1200
|
+
styles: this.styles,
|
|
1201
|
+
caches: this.caches
|
|
995
1202
|
});
|
|
996
1203
|
if (projected.isErr()) return projected;
|
|
997
1204
|
const surviving = projected.value.paragraph(preSelection.value.head.blockId);
|
|
998
|
-
const first =
|
|
999
|
-
if (first
|
|
1205
|
+
const first = projected.value.firstParagraph;
|
|
1206
|
+
if (first === void 0) return refuse("Resolution left no paragraph.");
|
|
1000
1207
|
let offset = surviving ? Math.min(preSelection.value.head.offset, surviving.text.length) : 0;
|
|
1001
1208
|
if (surviving && splitsSurrogatePair(surviving.text, offset)) offset -= 1;
|
|
1002
1209
|
const caret = {
|
|
1003
1210
|
story: OP_STORIES.MAIN,
|
|
1004
|
-
blockId: surviving?.blockId ?? first.
|
|
1211
|
+
blockId: surviving?.blockId ?? first.blockId,
|
|
1005
1212
|
offset
|
|
1006
1213
|
};
|
|
1007
|
-
|
|
1214
|
+
const prepared = this.prepareJournalledOps({
|
|
1008
1215
|
state,
|
|
1009
1216
|
ops,
|
|
1010
1217
|
postSelection: {
|
|
@@ -1014,6 +1221,41 @@ var CanonicalSession = class {
|
|
|
1014
1221
|
},
|
|
1015
1222
|
stagedApplied: applied.value
|
|
1016
1223
|
});
|
|
1224
|
+
return prepared.isOk() && lockHeld.length > 0 ? Result.ok({
|
|
1225
|
+
...prepared.value,
|
|
1226
|
+
lockHeld
|
|
1227
|
+
}) : prepared;
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Accept or reject one pending suggestion. Rejecting it rejects its
|
|
1231
|
+
* revisions. Accepting it adopts them as ordinary tracked changes by
|
|
1232
|
+
* `author`, keeping their ids, as the editor does: the change then waits
|
|
1233
|
+
* for review like any other.
|
|
1234
|
+
*/
|
|
1235
|
+
prepareSuggestion(state, { suggestionId, resolution, author, date }) {
|
|
1236
|
+
const infos = suggestionRevisionInfos(this.currentDocument, OP_STORIES.MAIN, suggestionId);
|
|
1237
|
+
if (infos.length === 0) return noChange(`No pending suggestion ${suggestionId}.`);
|
|
1238
|
+
if (resolution === "reject") return this.prepareResolve(state, {
|
|
1239
|
+
revisionIds: infos.map(({ id }) => id),
|
|
1240
|
+
resolution: "reject"
|
|
1241
|
+
});
|
|
1242
|
+
const checked = this.checkState(state);
|
|
1243
|
+
if (checked.isErr()) return checked;
|
|
1244
|
+
const selection = this.projection.selectionAt(state);
|
|
1245
|
+
if (selection.isErr()) return selection;
|
|
1246
|
+
return this.prepareJournalledOps({
|
|
1247
|
+
state,
|
|
1248
|
+
ops: [{
|
|
1249
|
+
type: DOCUMENT_OP_TYPES.SET_REVISION_INFO,
|
|
1250
|
+
story: OP_STORIES.MAIN,
|
|
1251
|
+
infos: infos.map(({ id }) => ({
|
|
1252
|
+
id,
|
|
1253
|
+
author,
|
|
1254
|
+
date
|
|
1255
|
+
}))
|
|
1256
|
+
}],
|
|
1257
|
+
postSelection: selection.value
|
|
1258
|
+
});
|
|
1017
1259
|
}
|
|
1018
1260
|
projectStory(story) {
|
|
1019
1261
|
if (story === OP_STORIES.MAIN) return Result.ok(this.projection);
|
|
@@ -1029,6 +1271,7 @@ var CanonicalSession = class {
|
|
|
1029
1271
|
const projected = project({
|
|
1030
1272
|
document: this.currentDocument,
|
|
1031
1273
|
styles: this.styles,
|
|
1274
|
+
caches: this.caches,
|
|
1032
1275
|
story
|
|
1033
1276
|
});
|
|
1034
1277
|
if (projected.isOk()) this.storyProjections.set(key, {
|
|
@@ -1187,12 +1430,14 @@ var CanonicalSession = class {
|
|
|
1187
1430
|
const applied = stagedApplied === void 0 ? applyDocumentOps(this.currentDocument, ops) : Result.ok(stagedApplied);
|
|
1188
1431
|
if (applied.isErr()) return refuse(applied.error.message);
|
|
1189
1432
|
if (applied.value.inverse.length === 0) return noChange("The intent makes no document change.");
|
|
1433
|
+
const locked = lockViolationBetween(this.currentDocument, applied.value.document);
|
|
1434
|
+
if (locked !== null) return lockRefusal(locked);
|
|
1190
1435
|
if (propertySourceDocument !== void 0) preservePropertySources({
|
|
1191
1436
|
target: applied.value.document,
|
|
1192
1437
|
source: propertySourceDocument,
|
|
1193
1438
|
indentation: "restore"
|
|
1194
1439
|
});
|
|
1195
|
-
const normalized = normalizeCanonicalListRendering(applied.value.document);
|
|
1440
|
+
const normalized = normalizeCanonicalListRendering(applied.value.document, this.caches.lists);
|
|
1196
1441
|
applied.value.document = normalized.document;
|
|
1197
1442
|
applied.value.inverse = normalized.inverse.concat(applied.value.inverse);
|
|
1198
1443
|
const changed = changedStories({
|
|
@@ -1200,7 +1445,7 @@ var CanonicalSession = class {
|
|
|
1200
1445
|
previous: this.currentDocument
|
|
1201
1446
|
});
|
|
1202
1447
|
if (unsupportedSeedReason(applied.value.document, changed) !== null) return Result.err(new CanonicalSessionError({
|
|
1203
|
-
gap: CANONICAL_GAP.storyContentProjection,
|
|
1448
|
+
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
1204
1449
|
reason: "refused",
|
|
1205
1450
|
message: "The operations produce unsupported canonical story content."
|
|
1206
1451
|
}));
|
|
@@ -1223,6 +1468,7 @@ var CanonicalSession = class {
|
|
|
1223
1468
|
const projected = project({
|
|
1224
1469
|
document: applied.value.document,
|
|
1225
1470
|
styles: this.styles,
|
|
1471
|
+
caches: this.caches,
|
|
1226
1472
|
story: projectedStory
|
|
1227
1473
|
});
|
|
1228
1474
|
if (projected.isErr()) return projected;
|
|
@@ -1230,7 +1476,8 @@ var CanonicalSession = class {
|
|
|
1230
1476
|
if (sameStory(projectedStory, OP_STORIES.MAIN)) return projected;
|
|
1231
1477
|
if (ops.some(operationChangesBodyProjection)) return project({
|
|
1232
1478
|
document: applied.value.document,
|
|
1233
|
-
styles: this.styles
|
|
1479
|
+
styles: this.styles,
|
|
1480
|
+
caches: this.caches
|
|
1234
1481
|
});
|
|
1235
1482
|
return Result.ok(this.currentProjection);
|
|
1236
1483
|
})();
|
|
@@ -1258,6 +1505,7 @@ var CanonicalSession = class {
|
|
|
1258
1505
|
transaction.replaceWith(from, to, Fragment.fromArray(replacement));
|
|
1259
1506
|
}
|
|
1260
1507
|
if (!transaction.doc.eq(projected.value.doc)) transaction.replaceWith(0, transaction.doc.content.size, projected.value.doc.content);
|
|
1508
|
+
for (const [name, value] of Object.entries(projected.value.doc.attrs)) if (transaction.doc.attrs[name] !== value) transaction.setDocAttribute(name, value);
|
|
1261
1509
|
if (sameStory(selection.anchor.story, projectedStory) && sameStory(selection.head.story, projectedStory)) {
|
|
1262
1510
|
if (!restoreCanonicalSelection({
|
|
1263
1511
|
transaction,
|
|
@@ -1269,6 +1517,8 @@ var CanonicalSession = class {
|
|
|
1269
1517
|
}
|
|
1270
1518
|
})) return refuse("Canonical history cannot restore the selected inline atom.");
|
|
1271
1519
|
}
|
|
1520
|
+
const held = projected.value.heldAs(transaction.doc);
|
|
1521
|
+
const heldBody = bodyProjection.value === projected.value ? held : bodyProjection.value;
|
|
1272
1522
|
transaction.setMeta(CANONICAL_PROJECTION_META, {
|
|
1273
1523
|
type: "canonical",
|
|
1274
1524
|
origin,
|
|
@@ -1286,8 +1536,8 @@ var CanonicalSession = class {
|
|
|
1286
1536
|
return Result.ok({
|
|
1287
1537
|
transaction,
|
|
1288
1538
|
document: applied.value.document,
|
|
1289
|
-
projection:
|
|
1290
|
-
bodyProjection:
|
|
1539
|
+
projection: held,
|
|
1540
|
+
bodyProjection: heldBody,
|
|
1291
1541
|
selection,
|
|
1292
1542
|
touched: applied.value.touched,
|
|
1293
1543
|
version: baseVersion + 1,
|
|
@@ -1309,12 +1559,12 @@ var CanonicalSession = class {
|
|
|
1309
1559
|
this.storyProjections.set(storyProjectionKey(projectedStory), {
|
|
1310
1560
|
content: body.content,
|
|
1311
1561
|
theme: applied.value.document.package.theme,
|
|
1312
|
-
projection:
|
|
1562
|
+
projection: held
|
|
1313
1563
|
});
|
|
1314
1564
|
}
|
|
1315
1565
|
this.currentSelection = selection;
|
|
1316
1566
|
this.currentDocument = applied.value.document;
|
|
1317
|
-
this.currentProjection =
|
|
1567
|
+
this.currentProjection = heldBody;
|
|
1318
1568
|
for (const ids of [
|
|
1319
1569
|
applied.value.touched.modified,
|
|
1320
1570
|
applied.value.touched.inserted,
|
|
@@ -1340,20 +1590,23 @@ const createCanonicalSession = (document, styles) => {
|
|
|
1340
1590
|
});
|
|
1341
1591
|
const validated = validateOpsDocument(identified);
|
|
1342
1592
|
if (validated.isErr()) return refuse(validated.error.message);
|
|
1343
|
-
const
|
|
1593
|
+
const caches = newStoryProjectionCaches();
|
|
1594
|
+
const normalized = normalizeCanonicalListRendering(identified, caches.lists).document;
|
|
1344
1595
|
preservePropertySources({
|
|
1345
1596
|
target: normalized,
|
|
1346
1597
|
source: owned
|
|
1347
1598
|
});
|
|
1348
1599
|
const projected = project({
|
|
1349
1600
|
document: normalized,
|
|
1350
|
-
styles
|
|
1601
|
+
styles,
|
|
1602
|
+
caches
|
|
1351
1603
|
});
|
|
1352
1604
|
if (projected.isErr()) return projected;
|
|
1353
1605
|
return Result.ok(new CanonicalSession({
|
|
1354
1606
|
document: normalized,
|
|
1355
1607
|
projection: projected.value,
|
|
1356
|
-
styles
|
|
1608
|
+
styles,
|
|
1609
|
+
caches
|
|
1357
1610
|
}));
|
|
1358
1611
|
};
|
|
1359
1612
|
const hasDeletedParagraphMark = (node) => {
|
|
@@ -1383,7 +1636,7 @@ const visibleDeletionContext = (state) => {
|
|
|
1383
1636
|
const native = canonicalNativeCells(paragraph);
|
|
1384
1637
|
if (native.isErr()) {
|
|
1385
1638
|
issue = new CanonicalSessionError({
|
|
1386
|
-
gap: CANONICAL_GAP.dispatch,
|
|
1639
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
1387
1640
|
reason: "refused",
|
|
1388
1641
|
message: native.error.message
|
|
1389
1642
|
});
|
|
@@ -1396,7 +1649,7 @@ const visibleDeletionContext = (state) => {
|
|
|
1396
1649
|
const to = containerStart + paragraphOffset + 1 + cell.to;
|
|
1397
1650
|
if (cell.type !== "text" && selection.from > from && selection.from < to) {
|
|
1398
1651
|
issue = new CanonicalSessionError({
|
|
1399
|
-
gap: CANONICAL_GAP.dispatch,
|
|
1652
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
1400
1653
|
reason: "refused",
|
|
1401
1654
|
message: "Character deletion cannot start inside an inline atom."
|
|
1402
1655
|
});
|
|
@@ -1461,4 +1714,4 @@ const deletionRange = (state, direction) => {
|
|
|
1461
1714
|
to
|
|
1462
1715
|
});
|
|
1463
1716
|
};
|
|
1464
|
-
export { CANONICAL_PROJECTION_META, CanonicalSessionError, createCanonicalSession, deletionRange, isCanonicalJoinBoundary, isCanonicalProjectionTransaction, publishCanonicalProjection };
|
|
1717
|
+
export { CANONICAL_PROJECTION_META, CanonicalSessionError, createCanonicalSession, deletionRange, isCanonicalJoinBoundary, isCanonicalProjectionTransaction, newStoryProjectionCaches, project as projectCanonicalStory, publishCanonicalProjection };
|