@stll/folio-core 0.72.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/ai-edits/apply.d.ts +6 -114
- package/dist/ai-edits/apply.js +9 -131
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +213 -1634
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineProjection.js +1 -1
- package/dist/canonical/canonicalPublicOperations.js +228 -64
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +95 -15
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +185 -49
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +75 -15
- package/dist/document-operations-apply.d.ts +15 -0
- package/dist/document-operations-apply.js +280 -0
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +2 -279
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +32 -9
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +5 -37
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +600 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +177 -0
- package/dist/docx/server/templatePlan/labels.d.ts +36 -0
- package/dist/docx/server/templatePlan/labels.js +126 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +143 -0
- package/dist/docx/server/templatePlan/plan.js +841 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +161 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +406 -0
- package/dist/docx/server/templatePlan/types.js +28 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +968 -0
- package/dist/docx/server/templatePlan/xml.d.ts +69 -0
- package/dist/docx/server/templatePlan/xml.js +119 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/docx/xmlParser.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +2 -2
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
- package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/index.js +1 -1
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceReview.js +1 -1
- package/dist/prosemirror/paraIds.d.ts +46 -0
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +16 -1
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +8 -41
- package/dist/types/canonicalCapabilities.js +6 -34
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SUGGESTED_SUPPORTED_OPERATION_TYPES
|
|
1
|
+
import { SUGGESTED_SUPPORTED_OPERATION_TYPES } from "../ai-edits/applyTypes.js";
|
|
2
2
|
import { BatchClaims } from "../ai-edits/batch-claims.js";
|
|
3
3
|
import { describeCharacterSplit } from "../ai-edits/character-boundaries.js";
|
|
4
4
|
import { buildCleanBlockText, resolveCleanTextRange } from "../ai-edits/clean-text.js";
|
|
@@ -12,12 +12,13 @@ import { cutsIntoNoteReference, endsWithNoteReference, noteReferenceEditsAllowed
|
|
|
12
12
|
import { PENDING_BREAK_TABLE_REFUSAL, PENDING_JOIN_INSERTION_REFUSAL, firstParagraphJoiningTable, insertionAfterPendingBreak, isDeletedPPrMark, joinStopsAtTableAfter, pendingJoinParagraphs, pendingMarkEditOf, pendingMarkEditRefusal, pendingParagraphPropertiesRefusal } from "../ai-edits/pendingJoin.js";
|
|
13
13
|
import { addRetiredCommentReceipts } from "../ai-edits/retired-comment-receipts.js";
|
|
14
14
|
import { collectNoteReferenceLabels, hashFolioAIBlockContent, hashFolioAIBlockText } from "../ai-edits/snapshot.js";
|
|
15
|
-
import {
|
|
15
|
+
import { isInsertedPPrMark, snapshotBatchClaim } from "../ai-edits/snapshotBatchFacts.js";
|
|
16
16
|
import { mergesRemoveRow } from "../ai-edits/table-mutation-plan.js";
|
|
17
17
|
import { applyTableRowInsertion, describeUnplacedCellTexts, findTableColumnInsertion, findTableRowInsertion, getInsertedPhysicalColumnRows, getTableColumnCoordinateKey, splitCellParagraphTexts } from "../ai-edits/table-row-column-mutations.js";
|
|
18
18
|
import { findEnclosingTableCell, findEnclosingTableRow, findOutermostTableBoundary, tableRectangleCutsMergedCell } from "../ai-edits/table-targets.js";
|
|
19
19
|
import { tableFromTemplate } from "../ai-edits/table-template.js";
|
|
20
20
|
import { supportsTableInsertionMode } from "../ai-edits/tableInsertionModes.js";
|
|
21
|
+
import { buildSignatureTableNode, buildTableNode } from "../ai-edits/tableNodes.js";
|
|
21
22
|
import { createOperationHeadingStyles, findUndefinedOperationReference, styleDefinitionLookup } from "../ai-edits/undefinedReferences.js";
|
|
22
23
|
import { wordDiffSessionFromOptions } from "../ai-edits/word-diff.js";
|
|
23
24
|
import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch, withDistinctSuggestionIds } from "../document-operations.js";
|
|
@@ -27,8 +28,8 @@ import { expectRunPropertyChangeMarkAttrs, expectTableAttrs } from "../prosemirr
|
|
|
27
28
|
import { tableAnchor } from "../prosemirror/canonicalTableCommands.js";
|
|
28
29
|
import { paragraphEndsItsContainer } from "../prosemirror/containerFinalParagraph.js";
|
|
29
30
|
import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting } from "../prosemirror/conversion/fromProseDoc.js";
|
|
30
|
-
import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
|
|
31
31
|
import { insertionGap } from "../prosemirror/insertionGaps.js";
|
|
32
|
+
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
32
33
|
import { forEachAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js";
|
|
33
34
|
import { preservesReplacementCommentAlignment, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
|
|
34
35
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
@@ -52,11 +53,11 @@ import { controlEdgesAt } from "./controlEdges.js";
|
|
|
52
53
|
import { indentationAsRead, spacingSidesAsRead } from "./paragraphPatchAsRead.js";
|
|
53
54
|
import { replacementRunSources } from "./replacementRunSources.js";
|
|
54
55
|
import { Result, TaggedError, panic } from "better-result";
|
|
55
|
-
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
56
|
-
import { CONTENT_CONTROL_LOCK, MAX_REVISION_ID, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
57
56
|
import { Mark } from "prosemirror-model";
|
|
58
57
|
import { TableMap } from "prosemirror-tables";
|
|
59
|
-
import {
|
|
58
|
+
import { CONTENT_CONTROL_LOCK, MAX_REVISION_ID, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
59
|
+
import { BATCH_ANNOTATION_KINDS, DOCUMENT_OP_TYPES, ID_KIND_LIMITS, ID_LEASE_KINDS, OP_STORIES, SPLIT_HALVES, TYPED_TEXT_FORMATTING, applyDocumentOps, combineRecordedRevisions, compileEditorIntent, contentRank, createEditorIntentIdAllocator, deletionRemovesBlock, documentStories, finalBreakCarrier, findStoryBody, formatParaId, freshCommentId, groupInsertionRuns, idKey, introducedDocumentIds, isBlockBoundary, isCommentAnchorCarrierType, joinPropertyChangeLink, leasedIdCensus, locateParagraphThroughTextBoxes, noteDeletionOps, orderAddressingBeforeRemoval, orderBatchOperations, packageResourcesOpOf, paragraphHoldsContent, paragraphHoldsContentOnceAccepted, paragraphLength, paragraphsThroughTextBoxes, pendingSuggestionIdsIn, revisionSpan } from "@stll/docx-core/ops";
|
|
60
|
+
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
60
61
|
import { EditorState } from "prosemirror-state";
|
|
61
62
|
// src/canonical/canonicalPublicOperations.ts
|
|
62
63
|
/** Public batches compile against the read projection; only the canonical journal publishes. */
|
|
@@ -384,6 +385,15 @@ const rowClosingCellShapes = ({ items, doc }) => {
|
|
|
384
385
|
return refused;
|
|
385
386
|
};
|
|
386
387
|
/**
|
|
388
|
+
* Whether a deletion of a paragraph that a pending join runs words into
|
|
389
|
+
* takes those words too (`joinedWords`): tracked it does, as the joined
|
|
390
|
+
* paragraph carries the deleted one's id; a suggestion stays rejectable on
|
|
391
|
+
* its own and takes only the paragraph's own words. The deletion and the
|
|
392
|
+
* batch order both read this rule, so an edit of the joined words runs
|
|
393
|
+
* before the deletion only when the deletion takes them.
|
|
394
|
+
*/
|
|
395
|
+
const deletionTakesJoinedWords = (mode) => mode === "tracked-changes";
|
|
396
|
+
/**
|
|
387
397
|
* A paragraph's mark, as a block an operation addresses or removes: no
|
|
388
398
|
* block position is negative.
|
|
389
399
|
*/
|
|
@@ -531,7 +541,7 @@ const orderCanonicalBatch = ({ items, doc, mode }) => {
|
|
|
531
541
|
});
|
|
532
542
|
const takesCarrierMark = !prepended && carrier.type === "kept" && plan.address.type === "content" && plan.address.position < plan.block;
|
|
533
543
|
const joined = [];
|
|
534
|
-
if (mode
|
|
544
|
+
if (deletionTakesJoinedWords(mode) && !isDeletedPPrMark(paragraph.attrs["pPrMark"])) for (const { paragraph: previous } of before) {
|
|
535
545
|
if (!isDeletedPPrMark(doc.nodeAt(previous)?.attrs["pPrMark"])) break;
|
|
536
546
|
joined.push(previous);
|
|
537
547
|
}
|
|
@@ -701,6 +711,40 @@ const statedPropertiesIntents = ({ story, blockId, properties, mintList }) => {
|
|
|
701
711
|
};
|
|
702
712
|
const isBlockInsertion = (operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock";
|
|
703
713
|
const placesBlock = (operation) => isBlockInsertion(operation) || operation.type === "insertTable" || operation.type === "insertSignatureTable";
|
|
714
|
+
/** The side of the block it names that an insertion puts its block on. */
|
|
715
|
+
const placementSide = (operation) => {
|
|
716
|
+
switch (operation.type) {
|
|
717
|
+
case "insertBeforeBlock": return "before";
|
|
718
|
+
case "insertAfterBlock": return "after";
|
|
719
|
+
case "insertTable":
|
|
720
|
+
case "insertSignatureTable": return operation.position ?? "after";
|
|
721
|
+
default: return operation;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const placesTable = (operation) => operation.type === "insertTable" || operation.type === "insertSignatureTable";
|
|
725
|
+
/**
|
|
726
|
+
* Whether the last of the blocks a batch puts after a block, of `placed`
|
|
727
|
+
* beside it in input order, is a table: those land in that order, so it is
|
|
728
|
+
* the one right before the block after.
|
|
729
|
+
*/
|
|
730
|
+
const lastPutAfterIsTable = (placed) => {
|
|
731
|
+
const last = placed.findLast((operation) => placementSide(operation) === "after");
|
|
732
|
+
return last !== void 0 && placesTable(last);
|
|
733
|
+
};
|
|
734
|
+
const deletedParagraphPlacement = ({ beside, tableBefore, after, afterDeleted }) => {
|
|
735
|
+
const before = beside.filter((operation) => placementSide(operation) === "before");
|
|
736
|
+
const last = before.at(-1);
|
|
737
|
+
const firstAfter = beside.find((operation) => placementSide(operation) === "after");
|
|
738
|
+
const precededByTable = last === void 0 ? tableBefore : placesTable(last);
|
|
739
|
+
const followedByTable = firstAfter === void 0 ? after?.type.name === "table" && !afterDeleted : placesTable(firstAfter);
|
|
740
|
+
if (precededByTable && followedByTable) return { type: "keepsTablesApart" };
|
|
741
|
+
if (after === null || after.type.name === "paragraph") return { type: "inPlace" };
|
|
742
|
+
const firstParagraph = before.findIndex((operation) => operation.type === "insertBeforeBlock");
|
|
743
|
+
return {
|
|
744
|
+
type: "placedAfter",
|
|
745
|
+
operationIds: new Set(firstParagraph < 0 ? [] : before.slice(firstParagraph).map(({ id }) => id))
|
|
746
|
+
};
|
|
747
|
+
};
|
|
704
748
|
/**
|
|
705
749
|
* Where an insertion beside `paragraph` goes: beside the paragraph, or, for a
|
|
706
750
|
* paragraph in a table cell, beside the outermost table, as the default
|
|
@@ -1298,11 +1342,29 @@ const commentsRetiredBetween = (before, after) => {
|
|
|
1298
1342
|
return (before.package.document.comments ?? []).flatMap(({ id, parentId }) => parentId === void 0 && !kept.has(id) ? [id] : []);
|
|
1299
1343
|
};
|
|
1300
1344
|
/**
|
|
1345
|
+
* Whether only paragraphs accepting removes whole stand in `blocks`, one of
|
|
1346
|
+
* them at least pending removal: a join before them, once accepted, has no
|
|
1347
|
+
* words after it to separate. Range boundaries among them hold nothing.
|
|
1348
|
+
*/
|
|
1349
|
+
const onlyRemovedParagraphsFollow = (blocks) => {
|
|
1350
|
+
let removes = false;
|
|
1351
|
+
for (const block of blocks) {
|
|
1352
|
+
if (isBlockBoundary(block)) continue;
|
|
1353
|
+
if (block.type !== "paragraph" || paragraphHoldsContentOnceAccepted(block)) return false;
|
|
1354
|
+
removes ||= paragraphHoldsContent(block) || block.pPrMark?.kind === "del";
|
|
1355
|
+
}
|
|
1356
|
+
return removes;
|
|
1357
|
+
};
|
|
1358
|
+
/**
|
|
1301
1359
|
* A merge's intents as the batch stands in `document` when the merge runs.
|
|
1302
1360
|
* The separator goes in at the first paragraph's end as it now stands: an
|
|
1303
1361
|
* edit of that paragraph the batch ran first, a comment's reference among
|
|
1304
|
-
* them, may have changed its length.
|
|
1305
|
-
*
|
|
1362
|
+
* them, may have changed its length. Where only paragraphs accepting removes
|
|
1363
|
+
* whole follow it, deletions the batch made first among them, it goes in not
|
|
1364
|
+
* at all: accepting leaves no words after it to separate, as the legacy
|
|
1365
|
+
* engine reads the document as the merge runs. A deletion the batch refuses,
|
|
1366
|
+
* or makes after the merge, has not taken them. Direct, the join also binds
|
|
1367
|
+
* to the paragraph that now follows: a paragraph the batch deleted first is no
|
|
1306
1368
|
* longer there, so the merge joins across it, as merging after that deletion
|
|
1307
1369
|
* does; `undefined` when no paragraph follows any more. Tracked, a deleted
|
|
1308
1370
|
* paragraph stays, and the join keeps it, unless an earlier operation joined
|
|
@@ -1319,21 +1381,29 @@ const mergeIntentsAsItRuns = ({ document, story, intents, mode }) => {
|
|
|
1319
1381
|
const bindsToNext = mode === "direct" || !locations.some(({ paragraph }) => idKey(paragraph.paraId ?? "") === was);
|
|
1320
1382
|
if (here === void 0) return bindsToNext ? void 0 : intents;
|
|
1321
1383
|
const end = paragraphLength(here.paragraph);
|
|
1384
|
+
const siblings = locateParagraphThroughTextBoxes(document, story, join.blockId)?.blocks;
|
|
1385
|
+
const separates = siblings === void 0 || !onlyRemovedParagraphsFollow(siblings.slice(here.index + 1));
|
|
1322
1386
|
const separatorAtEnd = [];
|
|
1323
|
-
for (const intent of intents)
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
offset: end
|
|
1328
|
-
},
|
|
1329
|
-
to: {
|
|
1330
|
-
...intent.to,
|
|
1331
|
-
offset: end
|
|
1387
|
+
for (const intent of intents) {
|
|
1388
|
+
if (intent.type !== "replaceText" || idKey(intent.from.blockId) !== key || intent.from.offset !== intent.to.offset) {
|
|
1389
|
+
separatorAtEnd.push(intent);
|
|
1390
|
+
continue;
|
|
1332
1391
|
}
|
|
1333
|
-
|
|
1392
|
+
if (separates) separatorAtEnd.push({
|
|
1393
|
+
...intent,
|
|
1394
|
+
from: {
|
|
1395
|
+
...intent.from,
|
|
1396
|
+
offset: end
|
|
1397
|
+
},
|
|
1398
|
+
to: {
|
|
1399
|
+
...intent.to,
|
|
1400
|
+
offset: end
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1334
1404
|
if (!bindsToNext) return separatorAtEnd;
|
|
1335
1405
|
const next = locations[at + 1];
|
|
1336
|
-
const between =
|
|
1406
|
+
const between = siblings?.slice(here.index + 1, next?.index ?? here.index + 1);
|
|
1337
1407
|
const nextId = next !== void 0 && JSON.stringify(here.list) === JSON.stringify(next.list) && (here.index + 1 === next.index || here.paragraph.sectionProperties === void 0 && between !== void 0 && between.length === next.index - here.index - 1 && between.every(isBlockBoundary)) ? next.paragraph.paraId : void 0;
|
|
1338
1408
|
if (nextId === void 0) return void 0;
|
|
1339
1409
|
const boundToNext = (intent) => {
|
|
@@ -2457,6 +2527,36 @@ const mapColumnDeletionIntents = ({ intents, columnIndex, inserted, insertedAfte
|
|
|
2457
2527
|
return intent;
|
|
2458
2528
|
});
|
|
2459
2529
|
};
|
|
2530
|
+
/**
|
|
2531
|
+
* The words of `blockId` the batch's comments cover, in its clean text: a
|
|
2532
|
+
* batch's comments run before its edits, so an edit there meets them as it
|
|
2533
|
+
* meets the comments the paragraph already holds. A comment whose target no
|
|
2534
|
+
* longer matches covers nothing; its own resolution refuses it.
|
|
2535
|
+
*/
|
|
2536
|
+
const batchCommentSpans = (comments, blockId, text) => comments.flatMap((comment) => {
|
|
2537
|
+
switch (comment.type) {
|
|
2538
|
+
case "commentOnRange": {
|
|
2539
|
+
const { range } = comment;
|
|
2540
|
+
return range.blockId === blockId && hashFolioAIBlockText(text.slice(range.startOffset, range.endOffset)) === range.selectedTextHash ? [{
|
|
2541
|
+
start: range.startOffset,
|
|
2542
|
+
end: range.endOffset
|
|
2543
|
+
}] : [];
|
|
2544
|
+
}
|
|
2545
|
+
case "commentOnBlock": {
|
|
2546
|
+
if (comment.blockId !== blockId) return [];
|
|
2547
|
+
if (comment.quote === void 0) return [{
|
|
2548
|
+
start: 0,
|
|
2549
|
+
end: text.length
|
|
2550
|
+
}];
|
|
2551
|
+
const start = text.indexOf(comment.quote);
|
|
2552
|
+
return start < 0 || comment.quote === "" ? [] : [{
|
|
2553
|
+
start,
|
|
2554
|
+
end: start + comment.quote.length
|
|
2555
|
+
}];
|
|
2556
|
+
}
|
|
2557
|
+
default: return comment;
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2460
2560
|
/** Whether the batch deletes none of the paragraphs right before. */
|
|
2461
2561
|
const noDeletedRunBefore = ({ type }) => {
|
|
2462
2562
|
switch (type) {
|
|
@@ -2535,7 +2635,8 @@ const NO_BESIDE_DELETIONS = {
|
|
|
2535
2635
|
deleted: /* @__PURE__ */ new Set()
|
|
2536
2636
|
},
|
|
2537
2637
|
paragraphsAfter: /* @__PURE__ */ new Set(),
|
|
2538
|
-
paragraphsAfterEarlier: () => /* @__PURE__ */ new Set()
|
|
2638
|
+
paragraphsAfterEarlier: () => /* @__PURE__ */ new Set(),
|
|
2639
|
+
placedBeside: () => []
|
|
2539
2640
|
};
|
|
2540
2641
|
/**
|
|
2541
2642
|
* The stated numbering a request names, minting its new list once for the
|
|
@@ -2841,6 +2942,7 @@ var CanonicalPublicOperations = class {
|
|
|
2841
2942
|
...normalizations.length === 0 ? {} : { normalizations }
|
|
2842
2943
|
};
|
|
2843
2944
|
};
|
|
2945
|
+
const batchComments = batch.operations.filter((operation) => operation.type === "commentOnBlock" || operation.type === "commentOnRange");
|
|
2844
2946
|
const besideDeletions = {
|
|
2845
2947
|
deleted: new Set(batch.operations.flatMap((operation) => operation.type === "deleteBlock" ? [operation.blockId] : [])),
|
|
2846
2948
|
insertedBeside: new Set(batch.operations.flatMap((operation) => operation.type === "insertAfterBlock" || operation.type === "insertBeforeBlock" ? [operation.blockId] : [])),
|
|
@@ -2853,7 +2955,8 @@ var CanonicalPublicOperations = class {
|
|
|
2853
2955
|
paragraphsAfterEarlier: (operationId) => {
|
|
2854
2956
|
const index = batch.operations.findIndex(({ id }) => id === operationId);
|
|
2855
2957
|
return new Set(batch.operations.slice(0, Math.max(index, 0)).flatMap((operation) => operation.type === "insertAfterBlock" ? [operation.blockId] : []));
|
|
2856
|
-
}
|
|
2958
|
+
},
|
|
2959
|
+
placedBeside: (blockId) => batch.operations.filter((operation) => placesBlock(operation) && operation.blockId === blockId)
|
|
2857
2960
|
};
|
|
2858
2961
|
const inputIndices = new Map(batch.operations.map(({ id }, index) => [id, index]));
|
|
2859
2962
|
const planned = (item) => {
|
|
@@ -2938,7 +3041,8 @@ var CanonicalPublicOperations = class {
|
|
|
2938
3041
|
tracked: batch.mode !== "direct",
|
|
2939
3042
|
suggested: batch.mode === "suggested",
|
|
2940
3043
|
mintList,
|
|
2941
|
-
besideDeletions
|
|
3044
|
+
besideDeletions,
|
|
3045
|
+
batchComments
|
|
2942
3046
|
});
|
|
2943
3047
|
if (compiled.isErr()) {
|
|
2944
3048
|
const direct = compiled.error.refusedIn === "trackedMode" ? this.resolve({
|
|
@@ -2950,7 +3054,8 @@ var CanonicalPublicOperations = class {
|
|
|
2950
3054
|
tracked: false,
|
|
2951
3055
|
suggested: false,
|
|
2952
3056
|
mintList,
|
|
2953
|
-
besideDeletions
|
|
3057
|
+
besideDeletions,
|
|
3058
|
+
batchComments
|
|
2954
3059
|
}) : void 0;
|
|
2955
3060
|
if (direct?.isOk()) {
|
|
2956
3061
|
const candidate = planned(direct.value);
|
|
@@ -2971,8 +3076,8 @@ var CanonicalPublicOperations = class {
|
|
|
2971
3076
|
}
|
|
2972
3077
|
for (const item of [...resolved]) {
|
|
2973
3078
|
if (item.besideDeletion !== true || !state) continue;
|
|
2974
|
-
const {
|
|
2975
|
-
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock") continue;
|
|
3079
|
+
const operation = batch.operations.find(({ id }) => id === item.operation.id) ?? panic("A resolved operation lost its request.");
|
|
3080
|
+
if (operation.type !== "deleteBlock" && operation.type !== "insertAfterBlock" && operation.type !== "insertBeforeBlock" && operation.type !== "insertTable" && operation.type !== "insertSignatureTable") continue;
|
|
2976
3081
|
if (resolved.some(({ operation: other }) => operation.type === "deleteBlock" ? (other.type === "insertAfterBlock" || other.type === "insertBeforeBlock") && other.blockId === operation.blockId : other.type === "deleteBlock" && other.blockId === operation.blockId)) continue;
|
|
2977
3082
|
resolved.splice(resolved.indexOf(item), 1);
|
|
2978
3083
|
claims = new BatchClaims();
|
|
@@ -2986,7 +3091,8 @@ var CanonicalPublicOperations = class {
|
|
|
2986
3091
|
tracked: batch.mode !== "direct",
|
|
2987
3092
|
suggested: batch.mode === "suggested",
|
|
2988
3093
|
mintList,
|
|
2989
|
-
besideDeletions: NO_BESIDE_DELETIONS
|
|
3094
|
+
besideDeletions: NO_BESIDE_DELETIONS,
|
|
3095
|
+
batchComments
|
|
2990
3096
|
});
|
|
2991
3097
|
if (alone.isErr()) {
|
|
2992
3098
|
refuseResolution(operation.id, alone.error);
|
|
@@ -3118,7 +3224,7 @@ var CanonicalPublicOperations = class {
|
|
|
3118
3224
|
const retired = resolvedOperation.retiresBreakBefore === true ? retiredBreakAsItRuns(sourceDocument, story, rebound) : rebound;
|
|
3119
3225
|
const deleting = resolvedOperation.mayEndContainer === true ? finalDeletionIntentsAsItRuns(sourceDocument, story, retired) : retired;
|
|
3120
3226
|
const suggestionId = batch.mode === "suggested" ? ("suggestionId" in operation ? operation.suggestionId : void 0) ?? operation.id : void 0;
|
|
3121
|
-
const retracting = operation.type === "deleteBlock" && batch.mode !== "direct" && operation.moveId === void 0 ? takenOverBreakRetractionAsItRuns({
|
|
3227
|
+
const retracting = operation.type === "deleteBlock" && batch.mode !== "direct" && operation.moveId === void 0 && resolvedOperation.keepsTablesApart !== true ? takenOverBreakRetractionAsItRuns({
|
|
3122
3228
|
document: sourceDocument,
|
|
3123
3229
|
story,
|
|
3124
3230
|
blockId: operation.blockId,
|
|
@@ -3359,11 +3465,14 @@ var CanonicalPublicOperations = class {
|
|
|
3359
3465
|
verifiedOperation: compiled.value.verifiedOperation
|
|
3360
3466
|
};
|
|
3361
3467
|
};
|
|
3468
|
+
/** The operations that resolved but were declined as they ran. */
|
|
3469
|
+
const declinedAsRun = /* @__PURE__ */ new Set();
|
|
3362
3470
|
const commitOperation = (resolvedOperation, prepared) => {
|
|
3363
3471
|
const { operation, normalizations: adjustments } = resolvedOperation;
|
|
3364
3472
|
if (prepared.type === "declined") {
|
|
3365
3473
|
if (prepared.refusal !== void 0) refusals.set(operation.id, prepared.refusal);
|
|
3366
3474
|
skip(operation.id, prepared.reason, prepared.message);
|
|
3475
|
+
declinedAsRun.add(operation.id);
|
|
3367
3476
|
return;
|
|
3368
3477
|
}
|
|
3369
3478
|
const survivorMaps = operation.type === "deleteBlock" ? [survivorOf, deletionSurvivorOf] : [survivorOf];
|
|
@@ -3420,10 +3529,10 @@ var CanonicalPublicOperations = class {
|
|
|
3420
3529
|
};
|
|
3421
3530
|
/**
|
|
3422
3531
|
* Where an insertion stands among those at its gap: in batch order, but a
|
|
3423
|
-
*
|
|
3424
|
-
*
|
|
3532
|
+
* block put before one the direct batch deletes, placed after it instead
|
|
3533
|
+
* (`besideDeletion`), still goes ahead of the blocks put after it.
|
|
3425
3534
|
*/
|
|
3426
|
-
const placementOrderOf = (member) => member.besideDeletion === true && member.operation.
|
|
3535
|
+
const placementOrderOf = (member) => member.besideDeletion === true && placesBlock(member.operation) && placementSide(member.operation) === "after" ? orderOf(member) - batch.operations.length : orderOf(member);
|
|
3427
3536
|
const gaps = /* @__PURE__ */ new Map();
|
|
3428
3537
|
for (const member of executionOrder) {
|
|
3429
3538
|
if (!placesBlock(member.operation)) continue;
|
|
@@ -3703,6 +3812,35 @@ var CanonicalPublicOperations = class {
|
|
|
3703
3812
|
})]
|
|
3704
3813
|
};
|
|
3705
3814
|
}
|
|
3815
|
+
const unplaced = new Set(batch.atomic ? [] : batch.operations.flatMap((operation) => placesBlock(operation) && declinedAsRun.has(operation.id) ? [operation.id] : []));
|
|
3816
|
+
if (unplaced.size > 0 && batch.operations.some(({ type }) => type === "deleteBlock" || type === "mergeBlockWithNext")) {
|
|
3817
|
+
const rest = this.apply({
|
|
3818
|
+
...options,
|
|
3819
|
+
batch: {
|
|
3820
|
+
...batch,
|
|
3821
|
+
operations: batch.operations.filter(({ id }) => !unplaced.has(id))
|
|
3822
|
+
}
|
|
3823
|
+
});
|
|
3824
|
+
const declinedSkips = skipped.flatMap((failure) => {
|
|
3825
|
+
if (!unplaced.has(failure.id)) return [];
|
|
3826
|
+
const canonicalRefusal = refusals.get(failure.id);
|
|
3827
|
+
return [canonicalRefusal ? {
|
|
3828
|
+
...failure,
|
|
3829
|
+
canonicalRefusal
|
|
3830
|
+
} : failure];
|
|
3831
|
+
});
|
|
3832
|
+
const allSkipped = [...rest.skipped, ...declinedSkips].toSorted((left, right) => (inputOrder.get(left.id) ?? 0) - (inputOrder.get(right.id) ?? 0));
|
|
3833
|
+
return {
|
|
3834
|
+
...rest,
|
|
3835
|
+
skipped: allSkipped,
|
|
3836
|
+
issues: getFolioDocumentOperationIssues(batch.operations, allSkipped),
|
|
3837
|
+
receipts: getFolioDocumentOperationReceiptsForStory({
|
|
3838
|
+
operations: batch.operations,
|
|
3839
|
+
applied: rest.applied,
|
|
3840
|
+
story: publicStory
|
|
3841
|
+
})
|
|
3842
|
+
};
|
|
3843
|
+
}
|
|
3706
3844
|
if (batch.atomic && skipped.length > 0) {
|
|
3707
3845
|
for (const { id } of appliedById.values()) skip(id, "atomicBatchRejected");
|
|
3708
3846
|
return result([], null);
|
|
@@ -3858,7 +3996,7 @@ var CanonicalPublicOperations = class {
|
|
|
3858
3996
|
* paragraph before it, whose mark then ends the list. Tracked, the text and
|
|
3859
3997
|
* the mark are marked deleted.
|
|
3860
3998
|
*/
|
|
3861
|
-
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, followsInsertedTable, precedesInsertedTable, precedesDeletedTable, previousGainsFollower, tableBeforeGainsFollower, endsOnceAccepted, deletedRun, deletedByBatch, refusal }) {
|
|
3999
|
+
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, keepsTablesApart, followsInsertedTable, precedesInsertedTable, precedesDeletedTable, previousGainsFollower, tableBeforeGainsFollower, endsOnceAccepted, deletedRun, deletedByBatch, refusal }) {
|
|
3862
4000
|
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock");
|
|
3863
4001
|
if (tracked && goesWholeOnAcceptance(paragraph.node)) return refusal("noopOperation");
|
|
3864
4002
|
const end = paragraph.start + paragraph.node.content.size;
|
|
@@ -3887,7 +4025,6 @@ var CanonicalPublicOperations = class {
|
|
|
3887
4025
|
},
|
|
3888
4026
|
...resolved
|
|
3889
4027
|
});
|
|
3890
|
-
const keepsTablesApart = after?.type.name === "table" && (before?.type.name === "table" || followsInsertedTable) && !precedesDeletedTable;
|
|
3891
4028
|
const joined = deletesJoinedWords ? joinedBefore(doc, paragraph.start - 1) : [];
|
|
3892
4029
|
const takesJoinedWords = deletesJoinedWords && !joined.some((id) => deletedByBatch.has(id));
|
|
3893
4030
|
const opening = takesJoinedWords ? joined.at(-1) : void 0;
|
|
@@ -3896,9 +4033,9 @@ var CanonicalPublicOperations = class {
|
|
|
3896
4033
|
paragraph.node.descendants((node) => {
|
|
3897
4034
|
if (node.isText && !node.marks.some(({ type }) => type.name === "insertion" || type.name === "deletion")) holdsOriginalWords = true;
|
|
3898
4035
|
});
|
|
3899
|
-
if (
|
|
4036
|
+
if (operation.moveId === void 0 && !gainsFollower && (keepsTablesApart || tracked && (after?.type.name === "table" || precedesInsertedTable) && isInsertedPPrMark(paragraph.node.attrs["pPrMark"]) && holdsOriginalWords)) {
|
|
3900
4037
|
if (paragraph.start === end) return refusal("noopOperation");
|
|
3901
|
-
const start = joinedWordsStart ?? paragraph.start;
|
|
4038
|
+
const start = keepsTablesApart ? paragraph.start : joinedWordsStart ?? paragraph.start;
|
|
3902
4039
|
const from = projection.addressAt(start);
|
|
3903
4040
|
const to = projection.addressAt(end);
|
|
3904
4041
|
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
@@ -3911,7 +4048,8 @@ var CanonicalPublicOperations = class {
|
|
|
3911
4048
|
}],
|
|
3912
4049
|
normalizations: [],
|
|
3913
4050
|
from: start,
|
|
3914
|
-
to: end
|
|
4051
|
+
to: end,
|
|
4052
|
+
...keepsTablesApart ? { keepsTablesApart: true } : {}
|
|
3915
4053
|
});
|
|
3916
4054
|
}
|
|
3917
4055
|
const keepsSectionBreakBeforeBlock = tracked && after !== null && after.type.name !== "paragraph" && paragraph.node.attrs["_sectionProperties"] != null && previous !== void 0 && previous.node.attrs["_sectionProperties"] == null && operation.moveId === void 0 && !gainsFollower && !previousGainsFollower && noDeletedRunBefore(deletedRun);
|
|
@@ -4149,7 +4287,7 @@ var CanonicalPublicOperations = class {
|
|
|
4149
4287
|
default: return beside;
|
|
4150
4288
|
}
|
|
4151
4289
|
}
|
|
4152
|
-
resolveOperation({ operation, listStart, options, state, story, diff, tracked, suggested, mintList, besideDeletions }) {
|
|
4290
|
+
resolveOperation({ operation, listStart, options, state, story, diff, tracked, suggested, mintList, besideDeletions, batchComments }) {
|
|
4153
4291
|
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4154
4292
|
reason,
|
|
4155
4293
|
message: message ?? `The operation was refused: ${reason}.`,
|
|
@@ -4222,7 +4360,17 @@ var CanonicalPublicOperations = class {
|
|
|
4222
4360
|
const hash = hashFolioAIBlockContent(clean.text);
|
|
4223
4361
|
if (operation.precondition && hash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
4224
4362
|
if (hash !== anchor.textHash) return refusal("changedBlock");
|
|
4225
|
-
const
|
|
4363
|
+
const blockAfter = state.doc.resolve(paragraph.start + paragraph.node.content.size + 1).nodeAfter;
|
|
4364
|
+
const followed = blockAfter?.type.name === "paragraph";
|
|
4365
|
+
const blockBefore = state.doc.resolve(paragraph.start - 1).nodeBefore;
|
|
4366
|
+
const previousId = blockBefore?.type.name === "paragraph" ? blockBefore.attrs["paraId"] : void 0;
|
|
4367
|
+
const besideDeleted = besideDeletions.deleted.has(blockId) ? deletedParagraphPlacement({
|
|
4368
|
+
beside: besideDeletions.placedBeside(blockId),
|
|
4369
|
+
tableBefore: blockBefore?.type.name === "table" || typeof previousId === "string" && lastPutAfterIsTable(besideDeletions.placedBeside(previousId)),
|
|
4370
|
+
after: blockAfter,
|
|
4371
|
+
afterDeleted: blockAfter?.type.name === "table" && tableParagraphIds(blockAfter).some((id) => besideDeletions.tables.deleted.has(id))
|
|
4372
|
+
}) : void 0;
|
|
4373
|
+
const keepsTablesApart = besideDeleted?.type === "keepsTablesApart";
|
|
4226
4374
|
if (isTableStructureOperation(operation)) return resolveTableStructure({
|
|
4227
4375
|
operation,
|
|
4228
4376
|
paragraph,
|
|
@@ -4237,17 +4385,27 @@ var CanonicalPublicOperations = class {
|
|
|
4237
4385
|
deleted: besideDeletions.deleted,
|
|
4238
4386
|
template: options.tableTemplates?.get(operation.id)
|
|
4239
4387
|
});
|
|
4240
|
-
if (operation.type === "insertTable" || operation.type === "insertSignatureTable")
|
|
4241
|
-
operation
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4388
|
+
if (operation.type === "insertTable" || operation.type === "insertSignatureTable") {
|
|
4389
|
+
const besideDeletion = !tracked && listStart === void 0 && besideDeleted?.type === "placedAfter" && besideDeleted.operationIds.has(operation.id);
|
|
4390
|
+
const inserted = resolveTableInsertion({
|
|
4391
|
+
operation: besideDeletion ? {
|
|
4392
|
+
...operation,
|
|
4393
|
+
position: "after"
|
|
4394
|
+
} : operation,
|
|
4395
|
+
...listStart === void 0 ? {} : { listStart },
|
|
4396
|
+
paragraph,
|
|
4397
|
+
projection: projection.value,
|
|
4398
|
+
story,
|
|
4399
|
+
noteReferences,
|
|
4400
|
+
refusal,
|
|
4401
|
+
skipAlike,
|
|
4402
|
+
template: options.tableTemplates?.get(operation.id)
|
|
4403
|
+
});
|
|
4404
|
+
return besideDeletion && inserted.isOk() ? Result.ok({
|
|
4405
|
+
...inserted.value,
|
|
4406
|
+
besideDeletion: true
|
|
4407
|
+
}) : inserted;
|
|
4408
|
+
}
|
|
4251
4409
|
if (isBlockInsertion(operation) && listStart !== void 0) return resolveBlockInsertion({
|
|
4252
4410
|
operation,
|
|
4253
4411
|
listStart,
|
|
@@ -4262,9 +4420,8 @@ var CanonicalPublicOperations = class {
|
|
|
4262
4420
|
skipAlike
|
|
4263
4421
|
});
|
|
4264
4422
|
if (isBlockInsertion(operation)) {
|
|
4265
|
-
const besideDeletion = !tracked && operation.type === "insertBeforeBlock" && !followed && besideDeletions.deleted.has(blockId);
|
|
4266
|
-
const
|
|
4267
|
-
const insertion = besideDeletion && after !== null ? {
|
|
4423
|
+
const besideDeletion = !tracked && operation.type === "insertBeforeBlock" && !followed && besideDeletions.deleted.has(blockId) && !keepsTablesApart;
|
|
4424
|
+
const insertion = besideDeletion && blockAfter !== null ? {
|
|
4268
4425
|
...operation,
|
|
4269
4426
|
type: "insertAfterBlock"
|
|
4270
4427
|
} : operation;
|
|
@@ -4311,12 +4468,11 @@ var CanonicalPublicOperations = class {
|
|
|
4311
4468
|
refusal
|
|
4312
4469
|
});
|
|
4313
4470
|
if (operation.type === "deleteBlock") {
|
|
4314
|
-
const gainsFollower = !followed && besideDeletions.insertedBeside.has(blockId);
|
|
4315
|
-
const before =
|
|
4316
|
-
const after =
|
|
4471
|
+
const gainsFollower = !followed && besideDeletions.insertedBeside.has(blockId) && !keepsTablesApart;
|
|
4472
|
+
const before = blockBefore;
|
|
4473
|
+
const after = blockAfter;
|
|
4317
4474
|
const endsOnceAccepted = tracked && operation.moveId === void 0 && followersGoOnAcceptance(state.doc, paragraph.start + paragraph.node.content.size + 1);
|
|
4318
|
-
const
|
|
4319
|
-
const followsInsertedTable = !followed && (besideDeletions.tables.before.has(blockId) || typeof previousId === "string" && besideDeletions.tables.after.has(previousId));
|
|
4475
|
+
const followsInsertedTable = keepsTablesApart || !followed && (besideDeletions.tables.before.has(blockId) || typeof previousId === "string" && besideDeletions.tables.after.has(previousId));
|
|
4320
4476
|
const tableBeforeGainsFollower = !followed && before !== null && before.type.name !== "paragraph" && paragraphIdsIn(before).some((id) => besideDeletions.paragraphsAfter.has(id));
|
|
4321
4477
|
const deleted = this.resolveBlockDeletion({
|
|
4322
4478
|
operation,
|
|
@@ -4325,8 +4481,9 @@ var CanonicalPublicOperations = class {
|
|
|
4325
4481
|
projectionStory: story,
|
|
4326
4482
|
doc: state.doc,
|
|
4327
4483
|
tracked,
|
|
4328
|
-
deletesJoinedWords:
|
|
4484
|
+
deletesJoinedWords: deletionTakesJoinedWords(options.batch.mode ?? "tracked-changes"),
|
|
4329
4485
|
gainsFollower,
|
|
4486
|
+
keepsTablesApart,
|
|
4330
4487
|
followsInsertedTable,
|
|
4331
4488
|
precedesInsertedTable: besideDeletions.tables.after.has(blockId) && !besideDeletions.paragraphsAfter.has(blockId),
|
|
4332
4489
|
precedesDeletedTable: after?.type.name === "table" && tableParagraphIds(after).some((id) => besideDeletions.tables.deleted.has(id)),
|
|
@@ -4532,10 +4689,18 @@ var CanonicalPublicOperations = class {
|
|
|
4532
4689
|
planChanges: tracked ? (source, target) => changesFromSegments(diff(source, target)) : planTextChanges,
|
|
4533
4690
|
...tracked ? { keepFieldsOf: planTextChanges } : {}
|
|
4534
4691
|
});
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4692
|
+
const addedComments = tracked ? batchCommentSpans(batchComments, blockId, clean.text) : [];
|
|
4693
|
+
const changesCommentedWords = (changes) => changes?.some((change) => clean.offsets.slice(start + change.start, start + change.end).some((position) => paragraph.node.nodeAt(position - paragraph.start)?.marks.some((mark) => mark.type.name === "comment")) || change.end > change.start && addedComments.some((span) => span.start < start + change.end && start + change.start < span.end)) === true;
|
|
4694
|
+
if (tracked && changesCommentedWords([{
|
|
4695
|
+
start: 0,
|
|
4696
|
+
end: end - start
|
|
4697
|
+
}])) {
|
|
4698
|
+
const directCuts = planReplacementChanges({
|
|
4699
|
+
...replacementSource,
|
|
4700
|
+
planChanges: planTextChanges
|
|
4701
|
+
});
|
|
4702
|
+
if (changesCommentedWords(planned) || changesCommentedWords(directCuts)) planned = directCuts;
|
|
4703
|
+
}
|
|
4539
4704
|
if (planned === null) return panic("A replacement's planned changes must reproduce it.");
|
|
4540
4705
|
const changes = cutAroundRepeatedSeparators(replacementSource.source, planned).map((change) => ({
|
|
4541
4706
|
start: start + change.start,
|
|
@@ -4745,8 +4910,7 @@ var CanonicalPublicOperations = class {
|
|
|
4745
4910
|
}
|
|
4746
4911
|
intents.push(...restyle);
|
|
4747
4912
|
} else if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs") {
|
|
4748
|
-
const
|
|
4749
|
-
const separator = followedOnlyByDeletedParagraphs(projection.value.doc, paragraph.start - 1 + paragraph.node.nodeSize, vanishing) ? "" : operation.separator ?? "";
|
|
4913
|
+
const separator = operation.separator ?? "";
|
|
4750
4914
|
if (separator !== "") {
|
|
4751
4915
|
const at = projection.value.addressAt(paragraph.start + paragraph.node.content.size);
|
|
4752
4916
|
if (at.isErr()) return refusal("unsupportedBlock");
|
|
@@ -9,8 +9,8 @@ import { InlineProjectionCache } from "./canonicalInlineProjection.js";
|
|
|
9
9
|
import { ParagraphAddress, ParagraphIdIndex, ProjectedBlock, StoryProjectionFacts } from "./canonicalProjectionBlocks.js";
|
|
10
10
|
import { CanonicalSourceRestore } from "./canonicalSourceNormalization.js";
|
|
11
11
|
import { Err, Ok, Result, TaggedErrorClass } from "better-result";
|
|
12
|
-
import { Node } from "prosemirror-model";
|
|
13
12
|
import { EditorState, Transaction } from "prosemirror-state";
|
|
13
|
+
import { Node } from "prosemirror-model";
|
|
14
14
|
import { ClientDocumentChange, DocumentOp, DocumentOpRefusal, EditorIntent, IdLease, InsertBlocksOp, InsertContentOp, InsertTextOp, OP_STORIES, OpStory, TextPosition, TouchedBlocks } from "@stll/docx-core/ops";
|
|
15
15
|
declare const CanonicalSessionErrorBase: TaggedErrorClass<"CanonicalSessionError">;
|
|
16
16
|
export declare class CanonicalSessionError extends CanonicalSessionErrorBase<{
|
|
@@ -319,6 +319,14 @@ declare class CanonicalSession {
|
|
|
319
319
|
setMode(mode: CanonicalSessionMode): void;
|
|
320
320
|
hasStyle(styleId: string): boolean;
|
|
321
321
|
/** How a replacement in the current mode removes the words it changes. */
|
|
322
|
+
/**
|
|
323
|
+
* A replacement cut into pieces at the comment boundaries it keeps, within
|
|
324
|
+
* one paragraph: the last piece takes the text, the others are cleared, and
|
|
325
|
+
* each is compiled after the ones behind it, so no earlier address moves.
|
|
326
|
+
* The caret follows the new text, moved back by what the pieces before it
|
|
327
|
+
* cleared.
|
|
328
|
+
*/
|
|
329
|
+
private compileReplacementPieces;
|
|
322
330
|
private replacementRemoval;
|
|
323
331
|
private advanceBlockId;
|
|
324
332
|
private freshBlockId;
|