@stll/folio-core 0.67.0 → 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 +94 -8
- 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/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 +29 -12
- package/dist/controller/canonicalComposition.js +1 -1
- 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 +28 -1
- 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 +327 -73
- 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 +4 -3
- package/dist/controller/hiddenEditorManager.js +91 -37
- package/dist/controller/layoutPipeline.js +48 -15
- 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.js +23 -4
- 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/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/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/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/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 +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 +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/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/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 +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
- package/dist/i18n/messages/catalogs.gen.js +34 -0
- package/dist/i18n/messages/cs.gen.js +2 -0
- package/dist/i18n/messages/de.gen.js +2 -0
- package/dist/i18n/messages/en.gen.js +2 -0
- package/dist/i18n/messages/es.gen.js +2 -0
- package/dist/i18n/messages/et.gen.js +2 -0
- package/dist/i18n/messages/fr.gen.js +2 -0
- package/dist/i18n/messages/he.gen.js +2 -0
- package/dist/i18n/messages/hi.gen.js +2 -0
- package/dist/i18n/messages/hu.gen.js +2 -0
- package/dist/i18n/messages/lt.gen.js +2 -0
- package/dist/i18n/messages/lv.gen.js +2 -0
- package/dist/i18n/messages/messages.gen.d.ts +2 -0
- package/dist/i18n/messages/pl.gen.js +2 -0
- package/dist/i18n/messages/pt-BR.gen.js +2 -0
- package/dist/i18n/messages/sk.gen.js +2 -0
- package/dist/i18n/messages/tr.gen.js +2 -0
- package/dist/i18n/messages/zh-CN.gen.js +2 -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/layout-bridge/convert/tableConversion.js +19 -8
- 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-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/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 +36 -1
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +46 -17
- package/dist/layout-painter/renderTable.js +7 -4
- 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/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 +102 -11
- 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/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +319 -51
- 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 +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -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/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 +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.js +20 -9
- 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/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/validation.js +1 -0
- 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
|
}));
|
|
@@ -980,30 +1177,41 @@ var CanonicalSession = class {
|
|
|
980
1177
|
if (checked.isErr()) return checked;
|
|
981
1178
|
const preSelection = this.projection.selectionAt(state);
|
|
982
1179
|
if (preSelection.isErr()) return preSelection;
|
|
983
|
-
const
|
|
1180
|
+
const resolve = (ids) => [{
|
|
984
1181
|
type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
|
|
985
1182
|
story: OP_STORIES.MAIN,
|
|
986
|
-
revisionIds,
|
|
1183
|
+
revisionIds: ids,
|
|
987
1184
|
decision: resolution
|
|
988
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)));
|
|
989
1196
|
const applied = applyDocumentOps(this.currentDocument, ops);
|
|
990
1197
|
if (applied.isErr()) return refuse(applied.error.message);
|
|
991
1198
|
const projected = project({
|
|
992
1199
|
document: applied.value.document,
|
|
993
|
-
styles: this.styles
|
|
1200
|
+
styles: this.styles,
|
|
1201
|
+
caches: this.caches
|
|
994
1202
|
});
|
|
995
1203
|
if (projected.isErr()) return projected;
|
|
996
1204
|
const surviving = projected.value.paragraph(preSelection.value.head.blockId);
|
|
997
|
-
const first =
|
|
998
|
-
if (first
|
|
1205
|
+
const first = projected.value.firstParagraph;
|
|
1206
|
+
if (first === void 0) return refuse("Resolution left no paragraph.");
|
|
999
1207
|
let offset = surviving ? Math.min(preSelection.value.head.offset, surviving.text.length) : 0;
|
|
1000
1208
|
if (surviving && splitsSurrogatePair(surviving.text, offset)) offset -= 1;
|
|
1001
1209
|
const caret = {
|
|
1002
1210
|
story: OP_STORIES.MAIN,
|
|
1003
|
-
blockId: surviving?.blockId ?? first.
|
|
1211
|
+
blockId: surviving?.blockId ?? first.blockId,
|
|
1004
1212
|
offset
|
|
1005
1213
|
};
|
|
1006
|
-
|
|
1214
|
+
const prepared = this.prepareJournalledOps({
|
|
1007
1215
|
state,
|
|
1008
1216
|
ops,
|
|
1009
1217
|
postSelection: {
|
|
@@ -1013,6 +1221,41 @@ var CanonicalSession = class {
|
|
|
1013
1221
|
},
|
|
1014
1222
|
stagedApplied: applied.value
|
|
1015
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
|
+
});
|
|
1016
1259
|
}
|
|
1017
1260
|
projectStory(story) {
|
|
1018
1261
|
if (story === OP_STORIES.MAIN) return Result.ok(this.projection);
|
|
@@ -1028,6 +1271,7 @@ var CanonicalSession = class {
|
|
|
1028
1271
|
const projected = project({
|
|
1029
1272
|
document: this.currentDocument,
|
|
1030
1273
|
styles: this.styles,
|
|
1274
|
+
caches: this.caches,
|
|
1031
1275
|
story
|
|
1032
1276
|
});
|
|
1033
1277
|
if (projected.isOk()) this.storyProjections.set(key, {
|
|
@@ -1186,12 +1430,14 @@ var CanonicalSession = class {
|
|
|
1186
1430
|
const applied = stagedApplied === void 0 ? applyDocumentOps(this.currentDocument, ops) : Result.ok(stagedApplied);
|
|
1187
1431
|
if (applied.isErr()) return refuse(applied.error.message);
|
|
1188
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);
|
|
1189
1435
|
if (propertySourceDocument !== void 0) preservePropertySources({
|
|
1190
1436
|
target: applied.value.document,
|
|
1191
1437
|
source: propertySourceDocument,
|
|
1192
1438
|
indentation: "restore"
|
|
1193
1439
|
});
|
|
1194
|
-
const normalized = normalizeCanonicalListRendering(applied.value.document);
|
|
1440
|
+
const normalized = normalizeCanonicalListRendering(applied.value.document, this.caches.lists);
|
|
1195
1441
|
applied.value.document = normalized.document;
|
|
1196
1442
|
applied.value.inverse = normalized.inverse.concat(applied.value.inverse);
|
|
1197
1443
|
const changed = changedStories({
|
|
@@ -1199,7 +1445,7 @@ var CanonicalSession = class {
|
|
|
1199
1445
|
previous: this.currentDocument
|
|
1200
1446
|
});
|
|
1201
1447
|
if (unsupportedSeedReason(applied.value.document, changed) !== null) return Result.err(new CanonicalSessionError({
|
|
1202
|
-
gap: CANONICAL_GAP.storyContentProjection,
|
|
1448
|
+
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
1203
1449
|
reason: "refused",
|
|
1204
1450
|
message: "The operations produce unsupported canonical story content."
|
|
1205
1451
|
}));
|
|
@@ -1222,6 +1468,7 @@ var CanonicalSession = class {
|
|
|
1222
1468
|
const projected = project({
|
|
1223
1469
|
document: applied.value.document,
|
|
1224
1470
|
styles: this.styles,
|
|
1471
|
+
caches: this.caches,
|
|
1225
1472
|
story: projectedStory
|
|
1226
1473
|
});
|
|
1227
1474
|
if (projected.isErr()) return projected;
|
|
@@ -1229,7 +1476,8 @@ var CanonicalSession = class {
|
|
|
1229
1476
|
if (sameStory(projectedStory, OP_STORIES.MAIN)) return projected;
|
|
1230
1477
|
if (ops.some(operationChangesBodyProjection)) return project({
|
|
1231
1478
|
document: applied.value.document,
|
|
1232
|
-
styles: this.styles
|
|
1479
|
+
styles: this.styles,
|
|
1480
|
+
caches: this.caches
|
|
1233
1481
|
});
|
|
1234
1482
|
return Result.ok(this.currentProjection);
|
|
1235
1483
|
})();
|
|
@@ -1257,6 +1505,7 @@ var CanonicalSession = class {
|
|
|
1257
1505
|
transaction.replaceWith(from, to, Fragment.fromArray(replacement));
|
|
1258
1506
|
}
|
|
1259
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);
|
|
1260
1509
|
if (sameStory(selection.anchor.story, projectedStory) && sameStory(selection.head.story, projectedStory)) {
|
|
1261
1510
|
if (!restoreCanonicalSelection({
|
|
1262
1511
|
transaction,
|
|
@@ -1268,6 +1517,8 @@ var CanonicalSession = class {
|
|
|
1268
1517
|
}
|
|
1269
1518
|
})) return refuse("Canonical history cannot restore the selected inline atom.");
|
|
1270
1519
|
}
|
|
1520
|
+
const held = projected.value.heldAs(transaction.doc);
|
|
1521
|
+
const heldBody = bodyProjection.value === projected.value ? held : bodyProjection.value;
|
|
1271
1522
|
transaction.setMeta(CANONICAL_PROJECTION_META, {
|
|
1272
1523
|
type: "canonical",
|
|
1273
1524
|
origin,
|
|
@@ -1285,8 +1536,8 @@ var CanonicalSession = class {
|
|
|
1285
1536
|
return Result.ok({
|
|
1286
1537
|
transaction,
|
|
1287
1538
|
document: applied.value.document,
|
|
1288
|
-
projection:
|
|
1289
|
-
bodyProjection:
|
|
1539
|
+
projection: held,
|
|
1540
|
+
bodyProjection: heldBody,
|
|
1290
1541
|
selection,
|
|
1291
1542
|
touched: applied.value.touched,
|
|
1292
1543
|
version: baseVersion + 1,
|
|
@@ -1308,12 +1559,12 @@ var CanonicalSession = class {
|
|
|
1308
1559
|
this.storyProjections.set(storyProjectionKey(projectedStory), {
|
|
1309
1560
|
content: body.content,
|
|
1310
1561
|
theme: applied.value.document.package.theme,
|
|
1311
|
-
projection:
|
|
1562
|
+
projection: held
|
|
1312
1563
|
});
|
|
1313
1564
|
}
|
|
1314
1565
|
this.currentSelection = selection;
|
|
1315
1566
|
this.currentDocument = applied.value.document;
|
|
1316
|
-
this.currentProjection =
|
|
1567
|
+
this.currentProjection = heldBody;
|
|
1317
1568
|
for (const ids of [
|
|
1318
1569
|
applied.value.touched.modified,
|
|
1319
1570
|
applied.value.touched.inserted,
|
|
@@ -1339,20 +1590,23 @@ const createCanonicalSession = (document, styles) => {
|
|
|
1339
1590
|
});
|
|
1340
1591
|
const validated = validateOpsDocument(identified);
|
|
1341
1592
|
if (validated.isErr()) return refuse(validated.error.message);
|
|
1342
|
-
const
|
|
1593
|
+
const caches = newStoryProjectionCaches();
|
|
1594
|
+
const normalized = normalizeCanonicalListRendering(identified, caches.lists).document;
|
|
1343
1595
|
preservePropertySources({
|
|
1344
1596
|
target: normalized,
|
|
1345
1597
|
source: owned
|
|
1346
1598
|
});
|
|
1347
1599
|
const projected = project({
|
|
1348
1600
|
document: normalized,
|
|
1349
|
-
styles
|
|
1601
|
+
styles,
|
|
1602
|
+
caches
|
|
1350
1603
|
});
|
|
1351
1604
|
if (projected.isErr()) return projected;
|
|
1352
1605
|
return Result.ok(new CanonicalSession({
|
|
1353
1606
|
document: normalized,
|
|
1354
1607
|
projection: projected.value,
|
|
1355
|
-
styles
|
|
1608
|
+
styles,
|
|
1609
|
+
caches
|
|
1356
1610
|
}));
|
|
1357
1611
|
};
|
|
1358
1612
|
const hasDeletedParagraphMark = (node) => {
|
|
@@ -1382,7 +1636,7 @@ const visibleDeletionContext = (state) => {
|
|
|
1382
1636
|
const native = canonicalNativeCells(paragraph);
|
|
1383
1637
|
if (native.isErr()) {
|
|
1384
1638
|
issue = new CanonicalSessionError({
|
|
1385
|
-
gap: CANONICAL_GAP.dispatch,
|
|
1639
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
1386
1640
|
reason: "refused",
|
|
1387
1641
|
message: native.error.message
|
|
1388
1642
|
});
|
|
@@ -1395,7 +1649,7 @@ const visibleDeletionContext = (state) => {
|
|
|
1395
1649
|
const to = containerStart + paragraphOffset + 1 + cell.to;
|
|
1396
1650
|
if (cell.type !== "text" && selection.from > from && selection.from < to) {
|
|
1397
1651
|
issue = new CanonicalSessionError({
|
|
1398
|
-
gap: CANONICAL_GAP.dispatch,
|
|
1652
|
+
ground: { gap: CANONICAL_GAP.dispatch },
|
|
1399
1653
|
reason: "refused",
|
|
1400
1654
|
message: "Character deletion cannot start inside an inline atom."
|
|
1401
1655
|
});
|
|
@@ -1460,4 +1714,4 @@ const deletionRange = (state, direction) => {
|
|
|
1460
1714
|
to
|
|
1461
1715
|
});
|
|
1462
1716
|
};
|
|
1463
|
-
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 };
|