@stll/folio-core 0.75.0 → 0.77.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/headless.d.ts +8 -5
- package/dist/ai-edits/headless.js +49 -26
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +13 -3
- package/dist/ai-edits/read.js +33 -4
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.js +5 -8
- package/dist/canonical/canonicalComments.js +8 -2
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +214 -107
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +181 -187
- package/dist/controller/canonicalClipboard.d.ts +3 -2
- package/dist/controller/canonicalClipboard.js +377 -58
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/canonicalStructure.d.ts +1 -2
- package/dist/controller/canonicalStructure.js +51 -24
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/hiddenEditorManager.js +7 -20
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +108 -9
- package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
- package/dist/docx/server/templatePlan/blocks.js +281 -14
- package/dist/docx/server/templatePlan/builders.d.ts +22 -1
- package/dist/docx/server/templatePlan/builders.js +37 -3
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +152 -8
- package/dist/docx/server/templatePlan/inspect.js +21 -1
- package/dist/docx/server/templatePlan/labels.js +16 -1
- package/dist/docx/server/templatePlan/plan.d.ts +35 -3
- package/dist/docx/server/templatePlan/plan.js +197 -20
- package/dist/docx/server/templatePlan/planShape.js +58 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
- package/dist/docx/server/templatePlan/revisions.js +681 -0
- package/dist/docx/server/templatePlan/story.d.ts +61 -2
- package/dist/docx/server/templatePlan/story.js +175 -13
- package/dist/docx/server/templatePlan/types.d.ts +313 -1
- package/dist/docx/server/templatePlan/verify.js +175 -12
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
- package/dist/prosemirror/replacedAnnotations.js +11 -203
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +4 -35
- package/dist/types/canonicalCapabilities.js +4 -33
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -32
- package/dist/internal/revisionResolutionStep.js +0 -282
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -4,7 +4,7 @@ import { describeCharacterSplit } from "../ai-edits/character-boundaries.js";
|
|
|
4
4
|
import { buildCleanBlockText, resolveCleanTextRange } from "../ai-edits/clean-text.js";
|
|
5
5
|
import { directJoinSurvivor, directJoinTakes } from "../ai-edits/directJoin.js";
|
|
6
6
|
import { EXISTING_REVISION_CONFLICT_MESSAGE, createExistingRevisionGuard } from "../ai-edits/existingRevisions.js";
|
|
7
|
-
import { parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "../ai-edits/inline-emphasis.js";
|
|
7
|
+
import { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "../ai-edits/inline-emphasis.js";
|
|
8
8
|
import { compileMarkdownInsertion } from "../ai-edits/markdownInsertion.js";
|
|
9
9
|
import { BACKGROUND_MARK_NAMES, changesFromSegments, cutAroundRepeatedSeparators, planReplacementChanges, planTextChanges, touchedBackgroundStretches } from "../ai-edits/minimal-replacement.js";
|
|
10
10
|
import { createBatchListMinter } from "../ai-edits/newListNumbering.js";
|
|
@@ -31,11 +31,11 @@ import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting } from "../p
|
|
|
31
31
|
import { insertionGap } from "../prosemirror/insertionGaps.js";
|
|
32
32
|
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
33
33
|
import { forEachAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js";
|
|
34
|
-
import {
|
|
34
|
+
import { surveyAcceptedReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
|
|
35
35
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
36
36
|
import { insertedColumnWidth, omittedSlotTakingColumn } from "../prosemirror/tableGridMutation.js";
|
|
37
37
|
import { paragraphGoes, tableGoes } from "../prosemirror/tableRunIn.js";
|
|
38
|
-
import {
|
|
38
|
+
import { CANONICAL_CONDITION, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
39
39
|
import { readModel } from "../types/documentModel.js";
|
|
40
40
|
import { batchCommentReferenceShift, mapIntentPositions } from "./batchCommentReferences.js";
|
|
41
41
|
import { createCanonicalBatchReview } from "./canonicalBatchReview.js";
|
|
@@ -45,6 +45,7 @@ import { insertedCommentRange, plainInsertedParagraphIds } from "./canonicalInse
|
|
|
45
45
|
import { planReplayParagraphIds, startParagraphAdmissionCursor } from "./canonicalInsertionReplayIds.js";
|
|
46
46
|
import { addJoinedParagraphReceipts } from "./canonicalJoinedReceipts.js";
|
|
47
47
|
import { lockViolationBetween } from "./canonicalLockGuard.js";
|
|
48
|
+
import { groundForDocumentOpRefusal } from "./canonicalRefusalGrounds.js";
|
|
48
49
|
import { keepStandingRevisionReceipts } from "./canonicalRevisionReceipts.js";
|
|
49
50
|
import { CANONICAL_ADMISSION } from "./canonicalSession.js";
|
|
50
51
|
import { canonicalTrackedBatchFidelityError } from "./canonicalTrackedBatchFidelity.js";
|
|
@@ -55,7 +56,7 @@ import { replacementRunSources } from "./replacementRunSources.js";
|
|
|
55
56
|
import { Result, TaggedError, panic } from "better-result";
|
|
56
57
|
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
57
58
|
import { CONTENT_CONTROL_LOCK, MAX_REVISION_ID, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
58
|
-
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";
|
|
59
|
+
import { BATCH_ANNOTATION_KINDS, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_TYPES, DocumentOpRefusal, 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";
|
|
59
60
|
import { EditorState } from "prosemirror-state";
|
|
60
61
|
import { TableMap } from "prosemirror-tables";
|
|
61
62
|
import { Mark } from "prosemirror-model";
|
|
@@ -604,6 +605,28 @@ const CANONICAL_PUBLIC_OPERATION_DISPOSITIONS = {
|
|
|
604
605
|
mergeTableCells: "compile",
|
|
605
606
|
splitTableCell: "compile"
|
|
606
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* A request the operation vocabulary does not take, or names a place the
|
|
610
|
+
* document has no address for: refused as the request, not as a capability
|
|
611
|
+
* the session lacks.
|
|
612
|
+
*/
|
|
613
|
+
const INVALID_REQUEST = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
614
|
+
/** A place the operation named that an earlier change of its batch moved on. */
|
|
615
|
+
const STALE = { condition: CANONICAL_CONDITION.stale };
|
|
616
|
+
/** A shape the session built itself and then could not read back: a defect. */
|
|
617
|
+
const INTERNAL = { condition: CANONICAL_CONDITION.internal };
|
|
618
|
+
/**
|
|
619
|
+
* The public reason a batch the session refused to stage reports: a no-op
|
|
620
|
+
* for one that changes nothing, a content control's lock as the lock, a
|
|
621
|
+
* document that moved on as a stale range, and any other refusal as a block
|
|
622
|
+
* the session does not take, under the session's own ground.
|
|
623
|
+
*/
|
|
624
|
+
const stagingRefusalReason = (reason, ground) => {
|
|
625
|
+
if (reason === "noChange") return "noopOperation";
|
|
626
|
+
if (ground.rule === CANONICAL_RULE.contentControlLock) return "contentControlLock";
|
|
627
|
+
if (ground.condition === CANONICAL_CONDITION.stale) return "staleRange";
|
|
628
|
+
return "unsupportedBlock";
|
|
629
|
+
};
|
|
607
630
|
const resolveComment = ({ operation, from, to }) => {
|
|
608
631
|
if ("comment" in operation && operation.comment !== void 0) return {
|
|
609
632
|
type: "commented",
|
|
@@ -690,7 +713,7 @@ const resolveParagraphProperties = ({ operation, paragraph, projection, mintList
|
|
|
690
713
|
});
|
|
691
714
|
if (Object.keys(patch).length === 0) return refusal("emptyOperation");
|
|
692
715
|
const at = projection.addressAt(paragraph.start);
|
|
693
|
-
if (at.isErr()) return refusal("unsupportedBlock");
|
|
716
|
+
if (at.isErr()) return refusal("unsupportedBlock", void 0, at.error.ground);
|
|
694
717
|
const intents = [{
|
|
695
718
|
type: "formatParagraph",
|
|
696
719
|
at: at.value,
|
|
@@ -1017,7 +1040,7 @@ const resolveBlockInsertion = ({ operation, listStart, paragraph, named, formatt
|
|
|
1017
1040
|
};
|
|
1018
1041
|
const stated = statedNumbering(requested, mintList);
|
|
1019
1042
|
const inline = operation.lineBreakMode === "inline";
|
|
1020
|
-
if (markdown === void 0 && !noteReferenceEditsAllowed() && /\[\^(?:e)?\d+\]/u.test(text)) return refusal("
|
|
1043
|
+
if (markdown === void 0 && !noteReferenceEditsAllowed() && /\[\^(?:e)?\d+\]/u.test(text)) return refusal("protectedReference", "An insertion writes no note marker of its own.");
|
|
1021
1044
|
const split = markdown === void 0 && !inline && LINE_BREAK_PATTERN.test(text);
|
|
1022
1045
|
const lines = split ? text.split(LINE_BREAK_PATTERN).filter((line) => line.trim().length > 0) : [text];
|
|
1023
1046
|
const texts = lines.length === 0 ? [""] : lines;
|
|
@@ -1081,7 +1104,7 @@ const resolveBlockInsertion = ({ operation, listStart, paragraph, named, formatt
|
|
|
1081
1104
|
},
|
|
1082
1105
|
position: listStart.position
|
|
1083
1106
|
};
|
|
1084
|
-
if (place === void 0) return refusal("unsupportedBlock", "Canonical insertion beside a table needs a paragraph on that side of it.");
|
|
1107
|
+
if (place === void 0) return refusal("unsupportedBlock", "Canonical insertion beside a table needs a paragraph on that side of it.", INVALID_REQUEST);
|
|
1085
1108
|
const intents = [{
|
|
1086
1109
|
type: "insertParagraphs",
|
|
1087
1110
|
story,
|
|
@@ -1090,7 +1113,7 @@ const resolveBlockInsertion = ({ operation, listStart, paragraph, named, formatt
|
|
|
1090
1113
|
...stated.newList === void 0 ? {} : { newList: stated.newList }
|
|
1091
1114
|
}];
|
|
1092
1115
|
const { position } = place;
|
|
1093
|
-
if (operation.comment !== void 0 && texts.every((line) => line.length === 0)) return refusal("unsupportedBlock");
|
|
1116
|
+
if (operation.comment !== void 0 && texts.every((line) => line.length === 0)) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
1094
1117
|
const resolved = {
|
|
1095
1118
|
intents,
|
|
1096
1119
|
normalizations: split ? [{
|
|
@@ -1118,13 +1141,17 @@ const resolveBlockInsertion = ({ operation, listStart, paragraph, named, formatt
|
|
|
1118
1141
|
blockId: place.at.blockId,
|
|
1119
1142
|
offset: 0
|
|
1120
1143
|
};
|
|
1144
|
+
const beside = place.at.type === "after" ? projection.paragraph(place.at.blockId) : void 0;
|
|
1121
1145
|
return Result.ok({
|
|
1122
1146
|
type: "commented",
|
|
1123
1147
|
operation,
|
|
1124
1148
|
comment: {
|
|
1125
1149
|
text: operation.comment.text,
|
|
1126
1150
|
from: anchor,
|
|
1127
|
-
to: anchor
|
|
1151
|
+
to: beside === void 0 ? anchor : {
|
|
1152
|
+
...anchor,
|
|
1153
|
+
offset: paragraphLength(beside.source)
|
|
1154
|
+
},
|
|
1128
1155
|
inserted: true
|
|
1129
1156
|
},
|
|
1130
1157
|
...resolved
|
|
@@ -1705,7 +1732,7 @@ const resolveTableInsertion = ({ operation, listStart, paragraph, projection, st
|
|
|
1705
1732
|
parties: operation.parties
|
|
1706
1733
|
});
|
|
1707
1734
|
}
|
|
1708
|
-
if (node === null) return refusal("unsupportedBlock");
|
|
1735
|
+
if (node === null) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
1709
1736
|
const attrs = expectTableAttrs(node);
|
|
1710
1737
|
const formatting = tableAttrsToFormatting(attrs);
|
|
1711
1738
|
const table = {
|
|
@@ -1798,7 +1825,7 @@ const resolveTableInsertion = ({ operation, listStart, paragraph, projection, st
|
|
|
1798
1825
|
table: outerTable,
|
|
1799
1826
|
tableStart: outer.before + 1
|
|
1800
1827
|
});
|
|
1801
|
-
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
1828
|
+
if (blockId === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
1802
1829
|
return besideTable(blockId, outer[side]);
|
|
1803
1830
|
}
|
|
1804
1831
|
const { place } = besidePendingJoin({
|
|
@@ -2080,10 +2107,14 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2080
2107
|
left: cell.leftColumnIndex,
|
|
2081
2108
|
right: cell.leftColumnIndex + 1
|
|
2082
2109
|
};
|
|
2083
|
-
if (tracked
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2110
|
+
if (tracked) {
|
|
2111
|
+
const spans = Array.from({ length: map.height }, (_, rowIndex) => {
|
|
2112
|
+
const position = map.map[rowIndex * map.width + column.left];
|
|
2113
|
+
const node = position === void 0 ? null : row.table.nodeAt(position);
|
|
2114
|
+
return node === null || node.attrs["_omittedGridSlot"] != null ? 0 : Number(node.attrs["colspan"] ?? 1);
|
|
2115
|
+
});
|
|
2116
|
+
if (spans.includes(1) && spans.some((span) => span > 1)) return skipTracked("A suggested column deletion cannot narrow a cell that spans other columns.");
|
|
2117
|
+
}
|
|
2087
2118
|
const at = tableAnchor({
|
|
2088
2119
|
map,
|
|
2089
2120
|
table: row.table,
|
|
@@ -2093,7 +2124,7 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2093
2124
|
bottom: 0
|
|
2094
2125
|
}, column);
|
|
2095
2126
|
const addressed = at === void 0 ? void 0 : projection.addressAt(at);
|
|
2096
|
-
if (addressed === void 0 || addressed.isErr()) return refusal("unsupportedBlock");
|
|
2127
|
+
if (addressed === void 0 || addressed.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
2097
2128
|
const address = addressed.value;
|
|
2098
2129
|
const blockId = deleted.has(address.blockId) ? keptTableAddress({
|
|
2099
2130
|
projection,
|
|
@@ -2102,7 +2133,7 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2102
2133
|
deleted,
|
|
2103
2134
|
skipsCell: (cellPosition) => {
|
|
2104
2135
|
const rect = map.findCell(cellPosition - row.tableStart);
|
|
2105
|
-
return rect.left
|
|
2136
|
+
return rect.left >= column.left && rect.right <= column.right;
|
|
2106
2137
|
}
|
|
2107
2138
|
}) ?? address.blockId : address.blockId;
|
|
2108
2139
|
return resolved({
|
|
@@ -2131,7 +2162,7 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2131
2162
|
if (overflow !== null) return refusal("payloadDoesNotFit", overflow);
|
|
2132
2163
|
if (tracked && columnInsertionWidensCell(row.table, insertion.columnIndex)) return skipTracked("A suggested column cannot widen a cell that spans other columns.");
|
|
2133
2164
|
const blockId = tableBlockAddress(projection, row, deleted);
|
|
2134
|
-
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
2165
|
+
if (blockId === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
2135
2166
|
return resolved({
|
|
2136
2167
|
type: "table",
|
|
2137
2168
|
operation: {
|
|
@@ -2175,7 +2206,7 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2175
2206
|
if (new Set(cellsIn(map, rectangle)).size < 2) return skipAlike("unsupportedBlock", "The merge covers a single merged cell.");
|
|
2176
2207
|
if (tracked && !mergesDownOverEmptyCells(row.table, map, rectangle)) return skipTracked("A suggested merge takes one column over empty cells.");
|
|
2177
2208
|
const blockId = tableBlockAddress(projection, row, deleted);
|
|
2178
|
-
if (blockId === void 0) return refusal("unsupportedBlock");
|
|
2209
|
+
if (blockId === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
2179
2210
|
return resolved({
|
|
2180
2211
|
type: "table",
|
|
2181
2212
|
operation: {
|
|
@@ -2221,12 +2252,12 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2221
2252
|
revision: null,
|
|
2222
2253
|
...template === void 0 ? {} : { template }
|
|
2223
2254
|
});
|
|
2224
|
-
if (built.type !== "applied") return refusal("unsupportedBlock");
|
|
2255
|
+
if (built.type !== "applied") return refusal("unsupportedBlock", void 0, INTERNAL);
|
|
2225
2256
|
const table = built.transaction.doc.nodeAt(built.transaction.mapping.map(row.tablePosition, -1));
|
|
2226
|
-
if (table === null || table.type.name !== "table") return refusal("unsupportedBlock");
|
|
2257
|
+
if (table === null || table.type.name !== "table") return refusal("unsupportedBlock", void 0, INTERNAL);
|
|
2227
2258
|
const index = side === "before" ? row.rowIndex : row.rowIndex + 1;
|
|
2228
2259
|
const inserted = standaloneTableRowsFromProseMirror(table)[index];
|
|
2229
|
-
if (inserted === void 0) return refusal("unsupportedBlock");
|
|
2260
|
+
if (inserted === void 0) return refusal("unsupportedBlock", void 0, INTERNAL);
|
|
2230
2261
|
const { structuralChange: _structuralChange, propertyChanges: _propertyChanges, ...plain } = inserted;
|
|
2231
2262
|
return resolved({
|
|
2232
2263
|
type: "tableRow",
|
|
@@ -2294,6 +2325,49 @@ const emphasisRuns = (line) => parseInlineEmphasisRuns(line).flatMap(({ text, bo
|
|
|
2294
2325
|
}
|
|
2295
2326
|
}];
|
|
2296
2327
|
});
|
|
2328
|
+
/**
|
|
2329
|
+
* The spans of the words a replacement writes that its paired `**bold**` and
|
|
2330
|
+
* `***bold italic***` markers mark, and the emphasis each states.
|
|
2331
|
+
*/
|
|
2332
|
+
const emphasizedSpans = (emphasis) => {
|
|
2333
|
+
const spans = [];
|
|
2334
|
+
let offset = 0;
|
|
2335
|
+
for (const { text, bold, italic } of emphasis ?? []) {
|
|
2336
|
+
const end = offset + text.length;
|
|
2337
|
+
if (end > offset && (bold || italic)) spans.push({
|
|
2338
|
+
start: offset,
|
|
2339
|
+
end,
|
|
2340
|
+
patch: {
|
|
2341
|
+
...bold ? { bold: true } : {},
|
|
2342
|
+
...italic ? { italic: true } : {}
|
|
2343
|
+
}
|
|
2344
|
+
});
|
|
2345
|
+
offset = end;
|
|
2346
|
+
}
|
|
2347
|
+
return spans;
|
|
2348
|
+
};
|
|
2349
|
+
/** A plan that replaces the whole match, its words standing together. */
|
|
2350
|
+
const rewriteWhole = (source, target) => [{
|
|
2351
|
+
start: 0,
|
|
2352
|
+
end: source.length,
|
|
2353
|
+
text: target
|
|
2354
|
+
}];
|
|
2355
|
+
/**
|
|
2356
|
+
* Paragraph properties kept by a replacement that drops the paragraph's
|
|
2357
|
+
* formatting: the review records of its numbering, which only resolving
|
|
2358
|
+
* them retires.
|
|
2359
|
+
*/
|
|
2360
|
+
const NUMBERING_REVIEW_RECORDS = /* @__PURE__ */ new Set(["numberingChangeXml", "numberingInsertionXml"]);
|
|
2361
|
+
/**
|
|
2362
|
+
* The patch a replacement that drops the paragraph's formatting writes:
|
|
2363
|
+
* every property the paragraph states goes, as the default engine writes a
|
|
2364
|
+
* fresh paragraph, save the review records of its numbering.
|
|
2365
|
+
*/
|
|
2366
|
+
const droppedParagraphFormatting = (formatting) => {
|
|
2367
|
+
const patch = {};
|
|
2368
|
+
for (const key of Object.keys(formatting ?? {})) if (!NUMBERING_REVIEW_RECORDS.has(key)) patch[key] = null;
|
|
2369
|
+
return patch;
|
|
2370
|
+
};
|
|
2297
2371
|
const inlineText = (line) => line.split(/(\t|\r\n|\r|\n)/u).flatMap((part) => {
|
|
2298
2372
|
if (part === " ") return [{ type: "tab" }];
|
|
2299
2373
|
if (LINE_BREAK_PATTERN.test(part)) return [{ type: "break" }];
|
|
@@ -2302,6 +2376,15 @@ const inlineText = (line) => line.split(/(\t|\r\n|\r|\n)/u).flatMap((part) => {
|
|
|
2302
2376
|
text: part
|
|
2303
2377
|
}];
|
|
2304
2378
|
});
|
|
2379
|
+
const PROPERTY_FOLDING_INTENTS = /* @__PURE__ */ new Set([
|
|
2380
|
+
"joinParagraphs",
|
|
2381
|
+
"splitParagraph",
|
|
2382
|
+
"formatParagraph",
|
|
2383
|
+
"setList",
|
|
2384
|
+
"deleteParagraphs"
|
|
2385
|
+
]);
|
|
2386
|
+
/** Each paragraph property change of the story, by revision id. */
|
|
2387
|
+
const propertyChangesById = (document, story) => new Map(paragraphsThroughTextBoxes(document, story).flatMap(({ paragraph }) => paragraph.propertyChanges?.map((change) => [change.info.id, change]) ?? []));
|
|
2305
2388
|
/**
|
|
2306
2389
|
* Room past the highest revision or annotation id below which a batch draws
|
|
2307
2390
|
* its revision ids from the free ones instead: more than any one batch asks.
|
|
@@ -2359,12 +2442,13 @@ const primaryRevisionId = ({ operation, intents, document, revisionIds }) => {
|
|
|
2359
2442
|
const deletion = mark?.kind === "del" ? mark.info.id : mark?.deletion?.info.id;
|
|
2360
2443
|
return deletion !== void 0 && revisionIds.includes(deletion) ? deletion : revisionIds.at(0);
|
|
2361
2444
|
};
|
|
2362
|
-
const compilePublicIntents = ({ document, intents, mode, author, date, suggestionId, nextRevisionId, allocate, reservedBlockIds, idLease, paragraphAllocationLease, allocations: admittedAllocations, verifyOperation }) => {
|
|
2445
|
+
const compilePublicIntents = ({ document, intents, mode, author, date, suggestionId, nextRevisionId, allocate, reservedBlockIds, idLease, paragraphAllocationLease, allocations: admittedAllocations, verifyOperation, story }) => {
|
|
2363
2446
|
const ops = [];
|
|
2364
2447
|
const recorded = [];
|
|
2365
2448
|
let verifiedOperation;
|
|
2366
2449
|
const absorbed = [];
|
|
2367
2450
|
const source = document;
|
|
2451
|
+
const standing = mode === "direct" || !intents.some((intent) => PROPERTY_FOLDING_INTENTS.has(intent.type)) ? [] : [...propertyChangesById(source, story)].flatMap(([id, change]) => change.resolvesWith !== void 0 && change.info.author === author && change.info.date === date && change.info.suggestionId === suggestionId ? [[id, JSON.stringify(change)]] : []);
|
|
2368
2452
|
const joinedInto = /* @__PURE__ */ new Map();
|
|
2369
2453
|
const allocated = /* @__PURE__ */ new Map();
|
|
2370
2454
|
const allocations = [];
|
|
@@ -2460,6 +2544,12 @@ const compilePublicIntents = ({ document, intents, mode, author, date, suggestio
|
|
|
2460
2544
|
appliedRevisions.push(...notes.revisions);
|
|
2461
2545
|
}
|
|
2462
2546
|
document = after;
|
|
2547
|
+
const now = standing.length === 0 ? void 0 : propertyChangesById(after, story);
|
|
2548
|
+
if (now !== void 0 && standing.some(([id, change]) => JSON.stringify(now.get(id)) !== change)) return Result.err(new DocumentOpRefusal({
|
|
2549
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.PENDING_PARAGRAPH_PROPERTY_CHANGE,
|
|
2550
|
+
message: "Resolve the pending paragraph join before tracking a different change to its properties.",
|
|
2551
|
+
opType: void 0
|
|
2552
|
+
}));
|
|
2463
2553
|
ops.push(...compiled.value.ops, ...notes?.ops ?? []);
|
|
2464
2554
|
recorded.push({
|
|
2465
2555
|
revisions: appliedRevisions,
|
|
@@ -2939,8 +3029,7 @@ var CanonicalPublicOperations = class {
|
|
|
2939
3029
|
});
|
|
2940
3030
|
};
|
|
2941
3031
|
const refuseResolution = (id, error) => {
|
|
2942
|
-
|
|
2943
|
-
if (gap !== void 0) refusals.set(id, { gap });
|
|
3032
|
+
if (error.ground !== void 0) refusals.set(id, error.ground);
|
|
2944
3033
|
skip(id, error.reason, error.detail);
|
|
2945
3034
|
};
|
|
2946
3035
|
const result = (applied, undoHandle, disposition = "normal") => {
|
|
@@ -3054,12 +3143,6 @@ var CanonicalPublicOperations = class {
|
|
|
3054
3143
|
skip(operation.id, undefinedReference.reason, undefinedReference.message);
|
|
3055
3144
|
continue;
|
|
3056
3145
|
}
|
|
3057
|
-
const disposition = CANONICAL_PUBLIC_OPERATION_DISPOSITIONS[operation.type];
|
|
3058
|
-
if (disposition !== "compile") {
|
|
3059
|
-
refusals.set(operation.id, { gap: disposition });
|
|
3060
|
-
skip(operation.id, "unsupportedBlock");
|
|
3061
|
-
continue;
|
|
3062
|
-
}
|
|
3063
3146
|
const compiled = this.resolve({
|
|
3064
3147
|
operation,
|
|
3065
3148
|
options,
|
|
@@ -3315,6 +3398,7 @@ var CanonicalPublicOperations = class {
|
|
|
3315
3398
|
};
|
|
3316
3399
|
const compiled = compilePublicIntents({
|
|
3317
3400
|
document: withHeadings,
|
|
3401
|
+
story,
|
|
3318
3402
|
intents: mappedIntents,
|
|
3319
3403
|
allocate,
|
|
3320
3404
|
reservedBlockIds,
|
|
@@ -3359,8 +3443,13 @@ var CanonicalPublicOperations = class {
|
|
|
3359
3443
|
story,
|
|
3360
3444
|
ops: compiled.value.ops
|
|
3361
3445
|
});
|
|
3446
|
+
if (id.isErr()) return declined({
|
|
3447
|
+
reason: "unsupportedBlock",
|
|
3448
|
+
message: id.error.message,
|
|
3449
|
+
refusal: groundForDocumentOpRefusal(id.error.reason)
|
|
3450
|
+
});
|
|
3362
3451
|
const commentContent = admittedComment?.content ?? canonicalCommentBody(nextDocument, comment.text, commentLease);
|
|
3363
|
-
const commented =
|
|
3452
|
+
const commented = compileCanonicalComments({
|
|
3364
3453
|
document: nextDocument,
|
|
3365
3454
|
idLease,
|
|
3366
3455
|
command: {
|
|
@@ -3373,7 +3462,10 @@ var CanonicalPublicOperations = class {
|
|
|
3373
3462
|
content: commentContent,
|
|
3374
3463
|
...proposedBy
|
|
3375
3464
|
},
|
|
3376
|
-
anchor: {
|
|
3465
|
+
anchor: firstAdded?.paraId === void 0 || lastAdded?.paraId === void 0 ? {
|
|
3466
|
+
kind: "point",
|
|
3467
|
+
at: comment.to
|
|
3468
|
+
} : {
|
|
3377
3469
|
kind: "range",
|
|
3378
3470
|
from: {
|
|
3379
3471
|
story,
|
|
@@ -3388,10 +3480,10 @@ var CanonicalPublicOperations = class {
|
|
|
3388
3480
|
}
|
|
3389
3481
|
}
|
|
3390
3482
|
});
|
|
3391
|
-
if (commented
|
|
3483
|
+
if (commented.isErr()) return declined({
|
|
3392
3484
|
reason: "unsupportedBlock",
|
|
3393
|
-
message: commented
|
|
3394
|
-
refusal:
|
|
3485
|
+
message: commented.error.message,
|
|
3486
|
+
refusal: commented.error.ground
|
|
3395
3487
|
});
|
|
3396
3488
|
nextDocument = commented.value.document;
|
|
3397
3489
|
operationOps.push(...commented.value.ops);
|
|
@@ -3409,10 +3501,15 @@ var CanonicalPublicOperations = class {
|
|
|
3409
3501
|
});
|
|
3410
3502
|
const before = anchorIn(sourceDocument);
|
|
3411
3503
|
const after = anchorIn(nextDocument);
|
|
3412
|
-
if (id.isErr()
|
|
3504
|
+
if (id.isErr()) return declined({
|
|
3413
3505
|
reason: "unsupportedBlock",
|
|
3414
|
-
message: id.
|
|
3415
|
-
refusal:
|
|
3506
|
+
message: id.error.message,
|
|
3507
|
+
refusal: groundForDocumentOpRefusal(id.error.reason)
|
|
3508
|
+
});
|
|
3509
|
+
if (before === void 0 || after === void 0) return declined({
|
|
3510
|
+
reason: "missingBlock",
|
|
3511
|
+
message: "The comment anchor no longer exists.",
|
|
3512
|
+
refusal: STALE
|
|
3416
3513
|
});
|
|
3417
3514
|
const changed = batch.mode === "direct" ? void 0 : revisionSpan(after.content, new Set(compiled.value.revisions));
|
|
3418
3515
|
const from = changed === void 0 ? shift(comment.from) : {
|
|
@@ -3455,7 +3552,7 @@ var CanonicalPublicOperations = class {
|
|
|
3455
3552
|
if (commented.isErr()) return declined({
|
|
3456
3553
|
reason: "unsupportedBlock",
|
|
3457
3554
|
message: commented.error.message,
|
|
3458
|
-
refusal:
|
|
3555
|
+
refusal: commented.error.ground
|
|
3459
3556
|
});
|
|
3460
3557
|
nextDocument = commented.value.document;
|
|
3461
3558
|
operationOps.push(...commented.value.ops);
|
|
@@ -3876,10 +3973,11 @@ var CanonicalPublicOperations = class {
|
|
|
3876
3973
|
if (ops.length === 0) return result([], null);
|
|
3877
3974
|
const prepared = projected.value.selectionAt(state).andThen((selection) => reuseStaging ? operationStaging.prepare(state, selection) : operationStaging.prepareOps(state, ops, selection));
|
|
3878
3975
|
if (prepared.isErr()) {
|
|
3879
|
-
const
|
|
3976
|
+
const { reason, ground, message } = prepared.error;
|
|
3977
|
+
const skipReason = stagingRefusalReason(reason, ground);
|
|
3880
3978
|
for (const { id } of appliedById.values()) {
|
|
3881
|
-
if (
|
|
3882
|
-
skip(id,
|
|
3979
|
+
if (reason !== "noChange") refusals.set(id, ground);
|
|
3980
|
+
skip(id, skipReason, message);
|
|
3883
3981
|
}
|
|
3884
3982
|
return result([], null);
|
|
3885
3983
|
}
|
|
@@ -4025,7 +4123,7 @@ var CanonicalPublicOperations = class {
|
|
|
4025
4123
|
* the mark are marked deleted.
|
|
4026
4124
|
*/
|
|
4027
4125
|
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, keepsTablesApart, followsInsertedTable, precedesInsertedTable, bordersRemovedTable, previousGainsFollower, tableBeforeGainsFollower, endsOnceAccepted, deletedRun, deletedByBatch, refusal }) {
|
|
4028
|
-
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock");
|
|
4126
|
+
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4029
4127
|
if (tracked && goesWholeOnAcceptance(paragraph.node)) return refusal("noopOperation");
|
|
4030
4128
|
const end = paragraph.start + paragraph.node.content.size;
|
|
4031
4129
|
const after = doc.resolve(end + 1).nodeAfter;
|
|
@@ -4038,7 +4136,7 @@ var CanonicalPublicOperations = class {
|
|
|
4038
4136
|
const previous = followsInsertedTable ? void 0 : neighbour(before);
|
|
4039
4137
|
const commentFrom = projection.addressAt(paragraph.start);
|
|
4040
4138
|
const commentTo = projection.addressAt(end);
|
|
4041
|
-
if (commentFrom.isErr() || commentTo.isErr()) return refusal("unsupportedBlock");
|
|
4139
|
+
if (commentFrom.isErr() || commentTo.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4042
4140
|
const tracking = (resolved) => Result.ok(operation.comment === void 0 ? {
|
|
4043
4141
|
type: "plain",
|
|
4044
4142
|
operation,
|
|
@@ -4066,7 +4164,7 @@ var CanonicalPublicOperations = class {
|
|
|
4066
4164
|
const start = keepsTablesApart ? paragraph.start : joinedWordsStart ?? paragraph.start;
|
|
4067
4165
|
const from = projection.addressAt(start);
|
|
4068
4166
|
const to = projection.addressAt(end);
|
|
4069
|
-
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4167
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4070
4168
|
return tracking({
|
|
4071
4169
|
intents: [{
|
|
4072
4170
|
type: "replaceText",
|
|
@@ -4121,7 +4219,7 @@ var CanonicalPublicOperations = class {
|
|
|
4121
4219
|
const own = (from, to) => {
|
|
4122
4220
|
const start = projection.addressAt(from);
|
|
4123
4221
|
const stop = projection.addressAt(to);
|
|
4124
|
-
return start.isErr() || stop.isErr() ? refusal("unsupportedBlock") : Result.ok(from === to ? [] : [{
|
|
4222
|
+
return start.isErr() || stop.isErr() ? refusal("unsupportedBlock", void 0, INVALID_REQUEST) : Result.ok(from === to ? [] : [{
|
|
4125
4223
|
type: "replaceText",
|
|
4126
4224
|
from: start.value,
|
|
4127
4225
|
to: stop.value,
|
|
@@ -4210,7 +4308,7 @@ var CanonicalPublicOperations = class {
|
|
|
4210
4308
|
if (previousGainsFollower && noDeletedRunBefore(deletedRun)) {
|
|
4211
4309
|
const from = projection.addressAt(range.from);
|
|
4212
4310
|
const to = projection.addressAt(end);
|
|
4213
|
-
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4311
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4214
4312
|
return tracking({
|
|
4215
4313
|
intents: [{
|
|
4216
4314
|
type: "replaceText",
|
|
@@ -4228,7 +4326,7 @@ var CanonicalPublicOperations = class {
|
|
|
4228
4326
|
if (after === null && tableBeforeGainsFollower) {
|
|
4229
4327
|
const from = projection.addressAt(paragraph.start);
|
|
4230
4328
|
const to = projection.addressAt(end);
|
|
4231
|
-
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4329
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4232
4330
|
return tracking({
|
|
4233
4331
|
intents: [{
|
|
4234
4332
|
type: "replaceText",
|
|
@@ -4251,7 +4349,7 @@ var CanonicalPublicOperations = class {
|
|
|
4251
4349
|
}
|
|
4252
4350
|
const from = projection.addressAt(range.from);
|
|
4253
4351
|
const to = projection.addressAt(range.to);
|
|
4254
|
-
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4352
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4255
4353
|
return tracking({
|
|
4256
4354
|
intents: [{
|
|
4257
4355
|
type: "replaceText",
|
|
@@ -4292,10 +4390,11 @@ var CanonicalPublicOperations = class {
|
|
|
4292
4390
|
if (anchor === void 0 || projection.isErr() || projection.value.paragraph(blockId) !== void 0) return Result.ok({ operation });
|
|
4293
4391
|
const control = emptyControlOfFiller(state.doc, blockId);
|
|
4294
4392
|
if (control === void 0) return Result.ok({ operation });
|
|
4295
|
-
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4393
|
+
const refusal = (reason, message, ground) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4296
4394
|
reason,
|
|
4297
4395
|
message: message ?? `The operation was refused: ${reason}.`,
|
|
4298
|
-
detail: message
|
|
4396
|
+
detail: message,
|
|
4397
|
+
...ground === void 0 ? {} : { ground }
|
|
4299
4398
|
}));
|
|
4300
4399
|
const fillerHash = hashFolioAIBlockContent("");
|
|
4301
4400
|
if (operation.precondition && fillerHash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
@@ -4306,7 +4405,7 @@ var CanonicalPublicOperations = class {
|
|
|
4306
4405
|
projection: projection.value
|
|
4307
4406
|
});
|
|
4308
4407
|
switch (beside.type) {
|
|
4309
|
-
case "refused": return refusal("unsupportedBlock", beside.message);
|
|
4408
|
+
case "refused": return refusal("unsupportedBlock", beside.message, INVALID_REQUEST);
|
|
4310
4409
|
case "beside": return Result.ok({ operation: beside.operation });
|
|
4311
4410
|
case "listStart": return Result.ok({
|
|
4312
4411
|
operation: beside.operation,
|
|
@@ -4316,22 +4415,21 @@ var CanonicalPublicOperations = class {
|
|
|
4316
4415
|
}
|
|
4317
4416
|
}
|
|
4318
4417
|
resolveOperation({ operation, listStart, options, state, story, diff, tracked, suggested, mintList, besideDeletions, batchComments }) {
|
|
4319
|
-
const refusal = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4418
|
+
const refusal = (reason, message, ground) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4320
4419
|
reason,
|
|
4321
4420
|
message: message ?? `The operation was refused: ${reason}.`,
|
|
4322
|
-
detail: message
|
|
4421
|
+
detail: message,
|
|
4422
|
+
...ground === void 0 ? {} : { ground }
|
|
4323
4423
|
}));
|
|
4324
4424
|
const skipAlike = (reason, message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4325
4425
|
reason,
|
|
4326
4426
|
message,
|
|
4327
|
-
detail: message
|
|
4328
|
-
gap: null
|
|
4427
|
+
detail: message
|
|
4329
4428
|
}));
|
|
4330
4429
|
const skipTracked = (message) => Result.err(new CanonicalPublicOperationResolutionError({
|
|
4331
4430
|
reason: "unsupportedBlock",
|
|
4332
4431
|
message,
|
|
4333
4432
|
detail: message,
|
|
4334
|
-
gap: null,
|
|
4335
4433
|
refusedIn: "trackedMode"
|
|
4336
4434
|
}));
|
|
4337
4435
|
const notInTable = () => skipAlike("unsupportedBlock", "The block is not in a table.");
|
|
@@ -4364,7 +4462,7 @@ var CanonicalPublicOperations = class {
|
|
|
4364
4462
|
const projection = this.options.session.projectStory(story);
|
|
4365
4463
|
if (!anchor || projection.isErr()) return refusal("missingBlock");
|
|
4366
4464
|
const paragraph = projection.value.paragraph(blockId);
|
|
4367
|
-
if (!paragraph) return holdsParagraph(state.doc, blockId) ? refusal("unsupportedBlock", "The canonical session holds no address in this paragraph.") : refusal("missingBlock");
|
|
4465
|
+
if (!paragraph) return holdsParagraph(state.doc, blockId) ? refusal("unsupportedBlock", "The canonical session holds no address in this paragraph.", INVALID_REQUEST) : refusal("missingBlock");
|
|
4368
4466
|
if ((operation.type === "insertTable" || operation.type === "insertSignatureTable") && !supportsTableInsertionMode(operation.type, options.batch.mode ?? "tracked-changes")) return refusal("unsupportedMode");
|
|
4369
4467
|
const noteReferences = collectNoteReferenceLabels(state.doc);
|
|
4370
4468
|
const clean = buildCleanBlockText(paragraph.node, paragraph.start - 1, {
|
|
@@ -4383,7 +4481,7 @@ var CanonicalPublicOperations = class {
|
|
|
4383
4481
|
reason: pendingRefusal.reason,
|
|
4384
4482
|
message: pendingRefusal.message ?? `The operation was refused: ${pendingRefusal.reason}.`,
|
|
4385
4483
|
detail: pendingRefusal.message,
|
|
4386
|
-
...pendingRefusal.canonicalRefusal === void 0 ? {} : {
|
|
4484
|
+
...pendingRefusal.canonicalRefusal === void 0 ? {} : { ground: pendingRefusal.canonicalRefusal }
|
|
4387
4485
|
}));
|
|
4388
4486
|
const hash = hashFolioAIBlockContent(clean.text);
|
|
4389
4487
|
if (operation.precondition && hash !== operation.precondition.blockTextHash) return refusal("preconditionFailed");
|
|
@@ -4589,7 +4687,7 @@ var CanonicalPublicOperations = class {
|
|
|
4589
4687
|
if (start <= 0 || start >= clean.text.length || clean.text.slice(start, end) !== (operation.separator ?? "")) return refusal("staleRange");
|
|
4590
4688
|
break;
|
|
4591
4689
|
case "mergeBlockWithNext":
|
|
4592
|
-
if (
|
|
4690
|
+
if (/\r/u.test(operation.separator ?? "")) return refusal("unsupportedBlock", "Canonical public join separators hold no carriage return.", INVALID_REQUEST);
|
|
4593
4691
|
start = clean.text.length;
|
|
4594
4692
|
end = start;
|
|
4595
4693
|
break;
|
|
@@ -4608,12 +4706,15 @@ var CanonicalPublicOperations = class {
|
|
|
4608
4706
|
if (!range) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4609
4707
|
reason: "unsupportedBlock",
|
|
4610
4708
|
message: "The range begins or ends inside a field result or holds a page-break run.",
|
|
4611
|
-
detail: void 0
|
|
4612
|
-
gap: null
|
|
4709
|
+
detail: void 0
|
|
4613
4710
|
}));
|
|
4614
4711
|
const dropsFormatting = operation.type === "replaceBlock" && operation.preserveFormatting === false;
|
|
4615
|
-
|
|
4616
|
-
if (
|
|
4712
|
+
const emphasis = replacesText && hasInlineEmphasis(text) ? parseInlineEmphasisRuns(text) : void 0;
|
|
4713
|
+
if (replacesText && references.length > 0 && (dropsFormatting || emphasis !== void 0)) return refusal("protectedReference");
|
|
4714
|
+
if (emphasis !== void 0) text = stripInlineEmphasisMarkers(text);
|
|
4715
|
+
const rebuilds = !tracked && dropsFormatting;
|
|
4716
|
+
const emphasized = tracked ? [] : emphasizedSpans(emphasis);
|
|
4717
|
+
const rewritesWhole = rebuilds || emphasized.length > 0;
|
|
4617
4718
|
const kept = segmentsAroundNoteReferences(clean.text.slice(start, end), replacesText ? text : clean.text.slice(start, end), references);
|
|
4618
4719
|
const editsReferences = kept === null && replacesText && noteReferenceEditsAllowed();
|
|
4619
4720
|
const segments = editsReferences ? {
|
|
@@ -4625,11 +4726,11 @@ var CanonicalPublicOperations = class {
|
|
|
4625
4726
|
} : kept;
|
|
4626
4727
|
if (segments === null) return refusal("protectedReference");
|
|
4627
4728
|
const prose = replacesText ? segments.replacement.join("") : "";
|
|
4628
|
-
if (
|
|
4629
|
-
if (
|
|
4729
|
+
if (!editsReferences && /\[\^(?:e)?\d+\]/u.test(prose)) return refusal("protectedReference", "A replacement writes no note marker of its own.");
|
|
4730
|
+
if (/\r/u.test(prose)) return refusal("unsupportedBlock", "Canonical public replacements require plain text.", INVALID_REQUEST);
|
|
4630
4731
|
const from = projection.value.addressAt(range.from);
|
|
4631
4732
|
const to = projection.value.addressAt(range.to);
|
|
4632
|
-
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock");
|
|
4733
|
+
if (from.isErr() || to.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4633
4734
|
const resolvedComment = resolveComment({
|
|
4634
4735
|
operation,
|
|
4635
4736
|
from: from.value,
|
|
@@ -4651,7 +4752,7 @@ var CanonicalPublicOperations = class {
|
|
|
4651
4752
|
properties: { styleId: operation.styleId },
|
|
4652
4753
|
mintList
|
|
4653
4754
|
}) : [];
|
|
4654
|
-
if (resolvedComment.type === "plain" && operation.type !== "splitBlock" && operation.type !== "formatRange" && operation.type !== "mergeBlockWithNext" && restyle.length === 0 && clean.text.slice(start, end) === text) return refusal("noopOperation");
|
|
4755
|
+
if (resolvedComment.type === "plain" && operation.type !== "splitBlock" && operation.type !== "formatRange" && operation.type !== "mergeBlockWithNext" && restyle.length === 0 && !rewritesWhole && clean.text.slice(start, end) === text) return refusal("noopOperation");
|
|
4655
4756
|
let intent;
|
|
4656
4757
|
switch (operation.type) {
|
|
4657
4758
|
case "splitBlock":
|
|
@@ -4735,9 +4836,12 @@ var CanonicalPublicOperations = class {
|
|
|
4735
4836
|
length: boundary.length
|
|
4736
4837
|
}] : [])
|
|
4737
4838
|
};
|
|
4839
|
+
let planChanges = planTextChanges;
|
|
4840
|
+
if (tracked) planChanges = (source, target) => changesFromSegments(diff(source, target));
|
|
4841
|
+
if (rewritesWhole) planChanges = rewriteWhole;
|
|
4738
4842
|
let planned = planReplacementChanges({
|
|
4739
4843
|
...replacementSource,
|
|
4740
|
-
planChanges
|
|
4844
|
+
planChanges,
|
|
4741
4845
|
...tracked ? { keepFieldsOf: planTextChanges } : {}
|
|
4742
4846
|
});
|
|
4743
4847
|
const addedComments = tracked ? batchCommentSpans(batchComments, blockId, clean.text) : [];
|
|
@@ -4785,15 +4889,14 @@ var CanonicalPublicOperations = class {
|
|
|
4785
4889
|
placed.push({
|
|
4786
4890
|
...change,
|
|
4787
4891
|
from: gap.from,
|
|
4788
|
-
to: afterLast === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, afterLast))
|
|
4789
|
-
markers: "retained"
|
|
4892
|
+
to: afterLast === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, afterLast))
|
|
4790
4893
|
});
|
|
4791
4894
|
}
|
|
4792
4895
|
return placed;
|
|
4793
4896
|
};
|
|
4794
4897
|
const addressable = (placed) => placed.every(({ from: changeFrom, to: changeTo }) => projection.value.addressAt(changeFrom, changeFrom < changeTo ? "afterMarkers" : void 0).isOk() && projection.value.addressAt(changeTo, changeFrom < changeTo ? "beforeMarkers" : void 0).isOk());
|
|
4795
4898
|
let replacementChanges = placeChanges(changes);
|
|
4796
|
-
if (replacementChanges === void 0) return refusal("unsupportedBlock");
|
|
4899
|
+
if (replacementChanges === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4797
4900
|
if (!addressable(replacementChanges)) {
|
|
4798
4901
|
const whole = placeChanges(segments.source.flatMap((piece, index) => {
|
|
4799
4902
|
const replacement = segments.replacement[index] ?? "";
|
|
@@ -4805,38 +4908,9 @@ var CanonicalPublicOperations = class {
|
|
|
4805
4908
|
text: replacement
|
|
4806
4909
|
}];
|
|
4807
4910
|
}));
|
|
4808
|
-
if (whole === void 0) return refusal("unsupportedBlock");
|
|
4911
|
+
if (whole === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4809
4912
|
replacementChanges = whole;
|
|
4810
4913
|
}
|
|
4811
|
-
const comments = readModel(this.options.session.document).package.document.comments ?? [];
|
|
4812
|
-
let retiredCommentIds;
|
|
4813
|
-
if (!tracked) {
|
|
4814
|
-
const split = splitAtKeptCommentBoundaries({
|
|
4815
|
-
doc: state.doc,
|
|
4816
|
-
changes: replacementChanges,
|
|
4817
|
-
comments
|
|
4818
|
-
});
|
|
4819
|
-
replacementChanges = split.changes;
|
|
4820
|
-
retiredCommentIds = split.retiredCommentIds;
|
|
4821
|
-
}
|
|
4822
|
-
if (!preservesReplacementCommentAlignment({
|
|
4823
|
-
doc: state.doc,
|
|
4824
|
-
source: {
|
|
4825
|
-
from: paragraph.start,
|
|
4826
|
-
to: paragraph.start + paragraph.node.content.size
|
|
4827
|
-
},
|
|
4828
|
-
changes: replacementChanges,
|
|
4829
|
-
retiredCommentIds,
|
|
4830
|
-
removal: tracked ? { type: suggested ? "suggested" : "tracked" } : {
|
|
4831
|
-
type: "direct",
|
|
4832
|
-
comments
|
|
4833
|
-
}
|
|
4834
|
-
})) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4835
|
-
reason: "unsupportedBlock",
|
|
4836
|
-
gap: CANONICAL_GAP.commentReplacementAlignment,
|
|
4837
|
-
message: "Canonical replacement cannot preserve the aligned comment ranges.",
|
|
4838
|
-
detail: "Canonical replacement cannot preserve the aligned comment ranges."
|
|
4839
|
-
}));
|
|
4840
4914
|
if (tracked && !suggested) deletionSpans = replacementChanges.filter((span) => span.from < span.to);
|
|
4841
4915
|
if (intent.runPropsPatch !== void 0) {
|
|
4842
4916
|
const nodeAtCharacter = (index) => {
|
|
@@ -4870,7 +4944,7 @@ var CanonicalPublicOperations = class {
|
|
|
4870
4944
|
});
|
|
4871
4945
|
const clearedFrom = cleared && projection.value.addressAt(cleared.from, "afterMarkers");
|
|
4872
4946
|
const clearedTo = cleared && projection.value.addressAt(cleared.to, "beforeMarkers");
|
|
4873
|
-
if (!clearedFrom || !clearedTo || clearedFrom.isErr() || clearedTo.isErr()) return refusal("unsupportedBlock");
|
|
4947
|
+
if (!clearedFrom || !clearedTo || clearedFrom.isErr() || clearedTo.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4874
4948
|
intents.push({
|
|
4875
4949
|
type: "formatRun",
|
|
4876
4950
|
from: clearedFrom.value,
|
|
@@ -4919,6 +4993,7 @@ var CanonicalPublicOperations = class {
|
|
|
4919
4993
|
});
|
|
4920
4994
|
}
|
|
4921
4995
|
}
|
|
4996
|
+
let wordsStart;
|
|
4922
4997
|
for (const [index, change] of [...replacementChanges.entries()].reverse()) {
|
|
4923
4998
|
let gap = {
|
|
4924
4999
|
from: change.from,
|
|
@@ -4931,7 +5006,7 @@ var CanonicalPublicOperations = class {
|
|
|
4931
5006
|
const tailStart = sourceHolder.after();
|
|
4932
5007
|
const tailFrom = projection.value.addressAt(tailStart, "afterMarkers");
|
|
4933
5008
|
const tailTo = projection.value.addressAt(gap.to, "beforeMarkers");
|
|
4934
|
-
if (tailFrom.isErr() || tailTo.isErr()) return refusal("unsupportedBlock");
|
|
5009
|
+
if (tailFrom.isErr() || tailTo.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4935
5010
|
intents.push({
|
|
4936
5011
|
type: "replaceText",
|
|
4937
5012
|
from: tailFrom.value,
|
|
@@ -4951,7 +5026,7 @@ var CanonicalPublicOperations = class {
|
|
|
4951
5026
|
} : void 0;
|
|
4952
5027
|
const changeFrom = projection.value.addressAt(gap.from, edges?.start);
|
|
4953
5028
|
const changeTo = projection.value.addressAt(gap.to, edges?.end);
|
|
4954
|
-
if (changeFrom.isErr() || changeTo.isErr()) return refusal("unsupportedBlock");
|
|
5029
|
+
if (changeFrom.isErr() || changeTo.isErr()) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4955
5030
|
let inside = controlEdgesAt(projection.value.doc, gap.from, gap.to);
|
|
4956
5031
|
if (gap.from === gap.to && (inside.start === true || inside.end === true)) {
|
|
4957
5032
|
const edge = projection.value.doc.resolve(gap.from);
|
|
@@ -4961,6 +5036,7 @@ var CanonicalPublicOperations = class {
|
|
|
4961
5036
|
...inside,
|
|
4962
5037
|
...change.start === start ? { start: true } : { end: true }
|
|
4963
5038
|
};
|
|
5039
|
+
if (index === 0) wordsStart = changeFrom.value;
|
|
4964
5040
|
intents.push({
|
|
4965
5041
|
type: "replaceText",
|
|
4966
5042
|
from: changeFrom.value,
|
|
@@ -4968,15 +5044,45 @@ var CanonicalPublicOperations = class {
|
|
|
4968
5044
|
text: change.text,
|
|
4969
5045
|
...sources === void 0 ? {} : { formattingSources: sources },
|
|
4970
5046
|
...Object.keys(inside).length === 0 ? {} : { inside },
|
|
5047
|
+
...rebuilds ? { runProps: {} } : {},
|
|
4971
5048
|
...intent.runPropsPatch === void 0 ? {} : { runPropsPatch: intent.runPropsPatch }
|
|
4972
5049
|
});
|
|
4973
5050
|
}
|
|
5051
|
+
if (wordsStart !== void 0) for (const { start: spanStart, end: spanEnd, patch } of emphasized) {
|
|
5052
|
+
const { story: wordsStory, blockId: wordsBlockId } = wordsStart;
|
|
5053
|
+
intents.push({
|
|
5054
|
+
type: "formatRun",
|
|
5055
|
+
from: spanStart === 0 ? wordsStart : {
|
|
5056
|
+
story: wordsStory,
|
|
5057
|
+
blockId: wordsBlockId,
|
|
5058
|
+
offset: wordsStart.offset + spanStart
|
|
5059
|
+
},
|
|
5060
|
+
to: {
|
|
5061
|
+
story: wordsStory,
|
|
5062
|
+
blockId: wordsBlockId,
|
|
5063
|
+
offset: wordsStart.offset + spanEnd
|
|
5064
|
+
},
|
|
5065
|
+
patch
|
|
5066
|
+
});
|
|
5067
|
+
}
|
|
5068
|
+
if (rebuilds) {
|
|
5069
|
+
const patch = droppedParagraphFormatting(paragraph.source.formatting);
|
|
5070
|
+
if (Object.keys(patch).length > 0) intents.push({
|
|
5071
|
+
type: "formatParagraph",
|
|
5072
|
+
at: {
|
|
5073
|
+
story,
|
|
5074
|
+
blockId: paragraph.blockId,
|
|
5075
|
+
offset: 0
|
|
5076
|
+
},
|
|
5077
|
+
patch
|
|
5078
|
+
});
|
|
5079
|
+
}
|
|
4974
5080
|
intents.push(...restyle);
|
|
4975
5081
|
} else if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs") {
|
|
4976
5082
|
const separator = operation.separator ?? "";
|
|
4977
5083
|
if (separator !== "") {
|
|
4978
5084
|
const at = projection.value.addressAt(paragraph.start + paragraph.node.content.size);
|
|
4979
|
-
if (at.isErr()) return refusal("unsupportedBlock");
|
|
5085
|
+
if (at.isErr()) return refusal("unsupportedBlock", void 0, at.error.ground);
|
|
4980
5086
|
intents.push({
|
|
4981
5087
|
type: "replaceText",
|
|
4982
5088
|
from: at.value,
|
|
@@ -5002,6 +5108,7 @@ var CanonicalPublicOperations = class {
|
|
|
5002
5108
|
}));
|
|
5003
5109
|
} else intents.push(intent);
|
|
5004
5110
|
const nextParagraph = operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" ? projection.value.paragraph(intent.nextBlockId) : void 0;
|
|
5111
|
+
if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" && nextParagraph === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
5005
5112
|
let claimedTo = range.to;
|
|
5006
5113
|
if (operation.type === "mergeBlockWithNext") claimedTo = paragraph.start + paragraph.node.content.size;
|
|
5007
5114
|
if (nextParagraph) claimedTo = nextParagraph.start + nextParagraph.node.content.size;
|