@stll/folio-core 0.73.0 → 0.75.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/clean-text.d.ts +4 -1
- package/dist/ai-edits/clean-text.js +21 -7
- package/dist/ai-edits/headless.d.ts +5 -2
- package/dist/ai-edits/headless.js +20 -14
- package/dist/ai-edits/note-references.d.ts +1 -1
- package/dist/ai-edits/note-references.js +1 -1
- package/dist/ai-edits/pending-suggestions.d.ts +9 -7
- package/dist/ai-edits/pending-suggestions.js +134 -88
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +12 -3
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
- package/dist/ai-edits/retired-comment-receipts.js +3 -18
- package/dist/ai-edits/snapshot.js +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
- package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +32 -14
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +8 -4
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +6 -28
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +99 -36
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +129 -141
- package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
- package/dist/compare/inline-atoms.d.ts +35 -41
- package/dist/compare/inline-atoms.js +2 -465
- package/dist/compare/section-boundary-properties.d.ts +3 -30
- package/dist/compare/section-boundary-properties.js +4 -72
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.js +45 -44
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +6 -6
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +34 -17
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -2
- package/dist/controller/canonicalStructure.js +140 -43
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
- package/dist/controller/deferredDisplayListPainter.js +34 -0
- package/dist/controller/folioEditor.js +4 -2
- package/dist/controller/headerFooterEditorManager.js +3 -17
- package/dist/controller/hiddenEditorApi.d.ts +24 -3
- package/dist/controller/hiddenEditorApi.js +4 -17
- package/dist/controller/hiddenEditorManager.js +136 -197
- package/dist/controller/layoutPipeline.d.ts +4 -86
- package/dist/controller/layoutPipeline.js +8 -727
- package/dist/controller/layoutPipelineExecution.d.ts +94 -0
- package/dist/controller/layoutPipelineExecution.js +730 -0
- package/dist/controller/noteEditorManager.js +3 -16
- package/dist/document-operations.js +1 -1
- package/dist/docx/blockContentParser.d.ts +1 -3
- package/dist/docx/blockContentParser.js +3 -10
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +1 -1
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +36 -10
- package/dist/docx/selectiveSave.js +13 -5
- 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 +1 -1
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.js +107 -14
- package/dist/docx/server/templatePlan/blocks.d.ts +16 -1
- package/dist/docx/server/templatePlan/blocks.js +93 -7
- package/dist/docx/server/templatePlan/builders.d.ts +37 -2
- package/dist/docx/server/templatePlan/builders.js +196 -5
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +2 -0
- package/dist/docx/server/templatePlan/inspect.js +81 -61
- package/dist/docx/server/templatePlan/labels.d.ts +16 -2
- package/dist/docx/server/templatePlan/labels.js +131 -20
- package/dist/docx/server/templatePlan/plan.d.ts +15 -1
- package/dist/docx/server/templatePlan/plan.js +62 -13
- package/dist/docx/server/templatePlan/planShape.js +52 -4
- package/dist/docx/server/templatePlan/story.d.ts +8 -0
- package/dist/docx/server/templatePlan/story.js +11 -1
- package/dist/docx/server/templatePlan/types.d.ts +176 -18
- package/dist/docx/server/templatePlan/types.js +1 -0
- package/dist/docx/server/templatePlan/verify.js +60 -11
- package/dist/docx/server/templatePlan/xml.d.ts +5 -0
- package/dist/docx/server/templatePlan/xml.js +7 -1
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/xmlParser.js +1 -1
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +2 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -1
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -2
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +42 -93
- package/dist/types/canonicalCapabilities.js +53 -91
- package/dist/types/canonicalComments.d.ts +2 -2
- package/dist/types/canonicalSections.d.ts +2 -2
- package/dist/utils/clipboard.d.ts +2 -28
- package/dist/utils/clipboard.js +1 -96
- package/dist/utils/clipboardFiles.d.ts +27 -0
- package/dist/utils/clipboardFiles.js +98 -0
- package/dist/utils/rulerControl.d.ts +1 -0
- package/dist/utils/rulerControl.js +2 -1
- package/package.json +2 -2
- package/dist/ai-edits/apply.d.ts +0 -94
- package/dist/ai-edits/apply.js +0 -6637
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/document-operations-apply.d.ts +0 -15
- package/dist/document-operations-apply.js +0 -280
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/canonical/canonicalInlineGaps.ts
|
|
2
|
+
const SLOTS = 4;
|
|
3
|
+
const POSITION = 0;
|
|
4
|
+
const ZERO_WIDTH_BEFORE = 1;
|
|
5
|
+
const FIRST = 2;
|
|
6
|
+
const LAST = 3;
|
|
7
|
+
/** No gap at this offset yet. Positions are never negative. */
|
|
8
|
+
const EMPTY = -1;
|
|
9
|
+
var CanonicalInlineGaps = class {
|
|
10
|
+
/** The first gap of each offset: position, zeroWidthBefore, first, last. */
|
|
11
|
+
flat;
|
|
12
|
+
/** The second and later gaps of an offset, in the order they were added. */
|
|
13
|
+
more = /* @__PURE__ */ new Map();
|
|
14
|
+
/** Room for `offsets` offsets (`text.length + 1`), none holding a gap yet. */
|
|
15
|
+
constructor(offsets) {
|
|
16
|
+
this.flat = new Int32Array(offsets * SLOTS).fill(EMPTY);
|
|
17
|
+
}
|
|
18
|
+
/** How many offsets the table holds: the text's length plus one. */
|
|
19
|
+
get offsets() {
|
|
20
|
+
return this.flat.length / SLOTS;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Record a gap at `offset`. A gap at an editor position the offset already
|
|
24
|
+
* has widens that gap's seam to the ordinal, and the gap then names the
|
|
25
|
+
* ordinal of the two that is nearer to `preferred()` (asked only then); a
|
|
26
|
+
* tie keeps the earlier one. Returns false when the offset is outside the
|
|
27
|
+
* text.
|
|
28
|
+
*/
|
|
29
|
+
add(offset, position, zeroWidthBefore, preferred) {
|
|
30
|
+
if (!Number.isInteger(offset) || offset < 0 || offset >= this.offsets) return false;
|
|
31
|
+
const at = offset * SLOTS;
|
|
32
|
+
const flat = this.flat;
|
|
33
|
+
if (flat[at + POSITION] === EMPTY) {
|
|
34
|
+
flat[at + POSITION] = position;
|
|
35
|
+
flat[at + ZERO_WIDTH_BEFORE] = zeroWidthBefore;
|
|
36
|
+
flat[at + FIRST] = zeroWidthBefore;
|
|
37
|
+
flat[at + LAST] = zeroWidthBefore;
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (flat[at + POSITION] === position) {
|
|
41
|
+
flat[at + FIRST] = Math.min(flat[at + FIRST] ?? 0, zeroWidthBefore);
|
|
42
|
+
flat[at + LAST] = Math.max(flat[at + LAST] ?? 0, zeroWidthBefore);
|
|
43
|
+
const kept = flat[at + ZERO_WIDTH_BEFORE] ?? 0;
|
|
44
|
+
const target = preferred();
|
|
45
|
+
if (Math.abs(zeroWidthBefore - target) < Math.abs(kept - target)) flat[at + ZERO_WIDTH_BEFORE] = zeroWidthBefore;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const more = this.more.get(offset);
|
|
49
|
+
const known = more?.find((entry) => entry.position === position);
|
|
50
|
+
if (known === void 0) {
|
|
51
|
+
const entry = {
|
|
52
|
+
position,
|
|
53
|
+
zeroWidthBefore,
|
|
54
|
+
first: zeroWidthBefore,
|
|
55
|
+
last: zeroWidthBefore
|
|
56
|
+
};
|
|
57
|
+
if (more === void 0) this.more.set(offset, [entry]);
|
|
58
|
+
else more.push(entry);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
known.first = Math.min(known.first, zeroWidthBefore);
|
|
62
|
+
known.last = Math.max(known.last, zeroWidthBefore);
|
|
63
|
+
const target = preferred();
|
|
64
|
+
if (Math.abs(zeroWidthBefore - target) < Math.abs(known.zeroWidthBefore - target)) known.zeroWidthBefore = zeroWidthBefore;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/** Whether some offset has no gap. */
|
|
68
|
+
hasEmptyOffset() {
|
|
69
|
+
for (let offset = 0; offset < this.offsets; offset += 1) if (this.flat[offset * SLOTS + POSITION] === EMPTY) return true;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
/** The gaps at `offset` with their seams, in order; undefined outside the text. */
|
|
73
|
+
at(offset) {
|
|
74
|
+
if (!Number.isInteger(offset) || offset < 0 || offset >= this.offsets) return void 0;
|
|
75
|
+
const at = offset * SLOTS;
|
|
76
|
+
const flat = this.flat;
|
|
77
|
+
const position = flat[at + POSITION] ?? EMPTY;
|
|
78
|
+
if (position === EMPTY) return [];
|
|
79
|
+
const head = {
|
|
80
|
+
position,
|
|
81
|
+
zeroWidthBefore: flat[at + ZERO_WIDTH_BEFORE] ?? 0,
|
|
82
|
+
first: flat[at + FIRST] ?? 0,
|
|
83
|
+
last: flat[at + LAST] ?? 0
|
|
84
|
+
};
|
|
85
|
+
const more = this.more.get(offset);
|
|
86
|
+
return more === void 0 ? [head] : [head, ...more.map((entry) => ({
|
|
87
|
+
position: entry.position,
|
|
88
|
+
zeroWidthBefore: entry.zeroWidthBefore,
|
|
89
|
+
first: entry.first,
|
|
90
|
+
last: entry.last
|
|
91
|
+
}))];
|
|
92
|
+
}
|
|
93
|
+
/** The first offset with a gap at editor `position`, or -1. */
|
|
94
|
+
offsetOf(position) {
|
|
95
|
+
const flat = this.flat;
|
|
96
|
+
const hasMore = this.more.size > 0;
|
|
97
|
+
for (let offset = 0; offset < this.offsets; offset += 1) {
|
|
98
|
+
if (flat[offset * SLOTS + POSITION] === position) return offset;
|
|
99
|
+
if (hasMore && this.more.get(offset)?.some((entry) => entry.position === position)) return offset;
|
|
100
|
+
}
|
|
101
|
+
return -1;
|
|
102
|
+
}
|
|
103
|
+
/** Every offset's gaps, without their seams. */
|
|
104
|
+
toBoundaries() {
|
|
105
|
+
return Array.from({ length: this.offsets }, (_, offset) => (this.at(offset) ?? []).map(({ position, zeroWidthBefore }) => ({
|
|
106
|
+
position,
|
|
107
|
+
zeroWidthBefore
|
|
108
|
+
})));
|
|
109
|
+
}
|
|
110
|
+
/** Every offset's seams, parallel to {@link toBoundaries}. */
|
|
111
|
+
toSeams() {
|
|
112
|
+
return Array.from({ length: this.offsets }, (_, offset) => (this.at(offset) ?? []).map(({ first, last }) => ({
|
|
113
|
+
first,
|
|
114
|
+
last
|
|
115
|
+
})));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
export { CanonicalInlineGaps };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { CanonicalGapEntry, CanonicalInlineGap, CanonicalInlineGaps, CanonicalSeamExtent } from "./canonicalInlineGaps.js";
|
|
2
3
|
import { Result, TaggedErrorClass } from "better-result";
|
|
3
4
|
import { Node } from "prosemirror-model";
|
|
4
5
|
export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
|
|
@@ -94,20 +95,10 @@ type NativeCell = {
|
|
|
94
95
|
};
|
|
95
96
|
/** Native positions and deletion geometry read the same inline-cell classification. */
|
|
96
97
|
export declare const canonicalNativeCells: (paragraph: Node) => Result<NativeCell[], InlineProjectionError>;
|
|
97
|
-
export type CanonicalInlineGap = {
|
|
98
|
-
position: number;
|
|
99
|
-
zeroWidthBefore: number;
|
|
100
|
-
};
|
|
101
|
-
/** The source ordinals one editor position stands for: from `first` to `last`. */
|
|
102
|
-
export type CanonicalSeamExtent = {
|
|
103
|
-
first: number;
|
|
104
|
-
last: number;
|
|
105
|
-
};
|
|
106
98
|
type InlineProjection = {
|
|
107
99
|
text: string;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
seams: CanonicalSeamExtent[][];
|
|
100
|
+
/** Each offset's editor positions and the seams they stand for. */
|
|
101
|
+
gaps: CanonicalInlineGaps;
|
|
111
102
|
};
|
|
112
103
|
/** Whether a story holds an id: all a paragraph's projection asks of a story id set. */
|
|
113
104
|
export type StoryIdMembership = Pick<ReadonlySet<number>, "has">;
|
|
@@ -139,4 +130,4 @@ export declare class InlineProjectionCache {
|
|
|
139
130
|
private paragraphs;
|
|
140
131
|
project(args: CanonicalInlineProjectionArgs): Result<InlineProjection, InlineProjectionError>;
|
|
141
132
|
}
|
|
142
|
-
export {};
|
|
133
|
+
export type { CanonicalGapEntry, CanonicalInlineGap, CanonicalSeamExtent };
|
|
@@ -10,9 +10,10 @@ import { readMoveRangeBoundaryAttrs } from "../prosemirror/moveRangeBoundaryAttr
|
|
|
10
10
|
import { readRangeAnchorAttrs } from "../prosemirror/rangeAnchorAttrs.js";
|
|
11
11
|
import { PRESERVED_XML_LEVELS } from "../prosemirror/schema/nodes.js";
|
|
12
12
|
import { itemBefore } from "../utils/listItems.js";
|
|
13
|
+
import { CanonicalInlineGaps } from "./canonicalInlineGaps.js";
|
|
13
14
|
import { Result, TaggedError, panic } from "better-result";
|
|
14
|
-
import { defaultInsertionGap, inlineLeafSpans, paragraphLogicalText } from "@stll/docx-core/ops";
|
|
15
15
|
import { hasIllegalXmlCharacters } from "@stll/docx-core";
|
|
16
|
+
import { defaultInsertionGap, inlineLeafSpans, paragraphLogicalText } from "@stll/docx-core/ops";
|
|
16
17
|
// src/canonical/canonicalInlineProjection.ts
|
|
17
18
|
const CANONICAL_SOURCE_INLINE_POLICIES = {
|
|
18
19
|
run: "container",
|
|
@@ -450,7 +451,7 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
|
|
|
450
451
|
if (!(offsets?.start !== void 0 && offsets.end !== void 0 && offsets.start === offsets.end) && markedCommentIds.has(node.id) && !explicitCommentIds.has(node.id)) erasedCommentMarkers.add(node);
|
|
451
452
|
}
|
|
452
453
|
const text = paragraphLogicalText(source);
|
|
453
|
-
const
|
|
454
|
+
const gaps = new CanonicalInlineGaps(text.length + 1);
|
|
454
455
|
let index = 0;
|
|
455
456
|
let consumed = 0;
|
|
456
457
|
const insertionOrdinals = /* @__PURE__ */ new Map();
|
|
@@ -461,30 +462,8 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
|
|
|
461
462
|
insertionOrdinals.set(offset, ordinal);
|
|
462
463
|
return ordinal;
|
|
463
464
|
};
|
|
464
|
-
const seams = Array.from({ length: text.length + 1 }, () => []);
|
|
465
465
|
const addGap = (position, gap) => {
|
|
466
|
-
|
|
467
|
-
const extents = seams.at(gap.offset);
|
|
468
|
-
if (!gaps || !extents) panic(`Source leaf offset ${gap.offset} exceeds paragraph ${source.paraId}.`);
|
|
469
|
-
const existing = gaps.findIndex((entry) => entry.position === position);
|
|
470
|
-
const entry = {
|
|
471
|
-
position,
|
|
472
|
-
zeroWidthBefore: gap.zeroWidthBefore
|
|
473
|
-
};
|
|
474
|
-
if (existing < 0) {
|
|
475
|
-
gaps.push(entry);
|
|
476
|
-
extents.push({
|
|
477
|
-
first: gap.zeroWidthBefore,
|
|
478
|
-
last: gap.zeroWidthBefore
|
|
479
|
-
});
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
const extent = extents[existing] ?? panic("Missing canonical seam extent");
|
|
483
|
-
extent.first = Math.min(extent.first, gap.zeroWidthBefore);
|
|
484
|
-
extent.last = Math.max(extent.last, gap.zeroWidthBefore);
|
|
485
|
-
const preferred = insertionOrdinalAt(gap.offset);
|
|
486
|
-
const kept = gaps[existing] ?? panic("Missing canonical seam gap");
|
|
487
|
-
if (Math.abs(entry.zeroWidthBefore - preferred) < Math.abs(kept.zeroWidthBefore - preferred)) gaps[existing] = entry;
|
|
466
|
+
if (!gaps.add(gap.offset, position, gap.zeroWidthBefore, () => insertionOrdinalAt(gap.offset))) panic(`Source leaf offset ${gap.offset} exceeds paragraph ${source.paraId}.`);
|
|
488
467
|
};
|
|
489
468
|
const consumeErasedLeaves = (position) => {
|
|
490
469
|
while (consumed === 0) {
|
|
@@ -586,11 +565,10 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
|
|
|
586
565
|
if ([...comments.value.values()].some(({ starts, ends }) => starts.size > 0 || ends.size > 0)) return refuse("Canonical editing cannot attribute a comment mark transition to its source.");
|
|
587
566
|
const missing = spans.at(index);
|
|
588
567
|
if (missing || consumed !== 0) return refuse(`Canonical editing cannot display the source positions of ${missing?.node.type ?? "incomplete text"}.`);
|
|
589
|
-
if (
|
|
568
|
+
if (gaps.hasEmptyOffset()) return refuse("Canonical editing lost a source character boundary.");
|
|
590
569
|
return Result.ok({
|
|
591
570
|
text,
|
|
592
|
-
|
|
593
|
-
seams
|
|
571
|
+
gaps
|
|
594
572
|
});
|
|
595
573
|
};
|
|
596
574
|
/** A membership whose answers one paragraph's projection read, recorded to check later. */
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { ParagraphCommentMarkers } from "../docx/commentAnchorIndex.js";
|
|
12
12
|
import { document_d_exports } from "../types/document.js";
|
|
13
|
-
import {
|
|
13
|
+
import { CanonicalInlineGaps } from "./canonicalInlineGaps.js";
|
|
14
14
|
import { Node } from "prosemirror-model";
|
|
15
15
|
export type ParagraphAddress = {
|
|
16
16
|
blockId: string;
|
|
17
17
|
container: readonly document_d_exports.BlockContent[];
|
|
18
18
|
start: number;
|
|
19
19
|
text: string;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** Each offset's editor positions and the seams they stand for. */
|
|
21
|
+
gaps: CanonicalInlineGaps;
|
|
22
22
|
node: Node;
|
|
23
23
|
source: document_d_exports.Paragraph;
|
|
24
24
|
};
|
|
@@ -29,7 +29,7 @@ export type BlockParagraph = {
|
|
|
29
29
|
container: readonly document_d_exports.BlockContent[] | undefined;
|
|
30
30
|
/** From the start of the top-level node holding it. */
|
|
31
31
|
offset: number;
|
|
32
|
-
inline: Pick<ParagraphAddress, "text" | "
|
|
32
|
+
inline: Pick<ParagraphAddress, "text" | "gaps">;
|
|
33
33
|
node: Node;
|
|
34
34
|
source: document_d_exports.Paragraph;
|
|
35
35
|
};
|
|
@@ -34,7 +34,7 @@ import { forEachAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js"
|
|
|
34
34
|
import { preservesReplacementCommentAlignment, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
|
|
35
35
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
36
36
|
import { insertedColumnWidth, omittedSlotTakingColumn } from "../prosemirror/tableGridMutation.js";
|
|
37
|
-
import { paragraphGoes } from "../prosemirror/tableRunIn.js";
|
|
37
|
+
import { paragraphGoes, tableGoes } from "../prosemirror/tableRunIn.js";
|
|
38
38
|
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
39
39
|
import { readModel } from "../types/documentModel.js";
|
|
40
40
|
import { batchCommentReferenceShift, mapIntentPositions } from "./batchCommentReferences.js";
|
|
@@ -53,12 +53,12 @@ import { controlEdgesAt } from "./controlEdges.js";
|
|
|
53
53
|
import { indentationAsRead, spacingSidesAsRead } from "./paragraphPatchAsRead.js";
|
|
54
54
|
import { replacementRunSources } from "./replacementRunSources.js";
|
|
55
55
|
import { Result, TaggedError, panic } from "better-result";
|
|
56
|
-
import {
|
|
57
|
-
import { TableMap } from "prosemirror-tables";
|
|
56
|
+
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
58
57
|
import { CONTENT_CONTROL_LOCK, MAX_REVISION_ID, lockedControlMessage, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
59
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";
|
|
60
|
-
import { commentAuthorIssue, trackedChangeAuthorIssue } from "@stll/docx-core";
|
|
61
59
|
import { EditorState } from "prosemirror-state";
|
|
60
|
+
import { TableMap } from "prosemirror-tables";
|
|
61
|
+
import { Mark } from "prosemirror-model";
|
|
62
62
|
// src/canonical/canonicalPublicOperations.ts
|
|
63
63
|
/** Public batches compile against the read projection; only the canonical journal publishes. */
|
|
64
64
|
const tableLineRemovalKey = ({ axis, tablePosition, index }) => `${axis}:${tablePosition}:${index}`;
|
|
@@ -423,7 +423,25 @@ const removedTableParagraphs = (doc, type, block) => {
|
|
|
423
423
|
return blocks;
|
|
424
424
|
};
|
|
425
425
|
const orderCanonicalBatch = ({ items, doc, mode }) => {
|
|
426
|
-
const deletionOf = new Map(
|
|
426
|
+
const deletionOf = /* @__PURE__ */ new Map();
|
|
427
|
+
const directTableDeletionOf = /* @__PURE__ */ new Map();
|
|
428
|
+
for (const item of items) {
|
|
429
|
+
const { claim, block } = item.plan;
|
|
430
|
+
if (claim.type === "deleteBlock") deletionOf.set(block, item);
|
|
431
|
+
if (mode === "direct" && claim.type === "tableRemoval" && claim.axis === "table") directTableDeletionOf.set(claim.table, item);
|
|
432
|
+
}
|
|
433
|
+
const precedingTableDeletionOf = /* @__PURE__ */ new Map();
|
|
434
|
+
if (directTableDeletionOf.size > 0) for (const item of deletionOf.values()) {
|
|
435
|
+
if (!item.removesParagraphBeforeBlock) continue;
|
|
436
|
+
const at = doc.resolve(item.plan.block);
|
|
437
|
+
let position = at.pos;
|
|
438
|
+
for (let index = at.index() - 1; index >= 0; index--) {
|
|
439
|
+
position -= at.parent.child(index).nodeSize;
|
|
440
|
+
const tableDeletion = directTableDeletionOf.get(position);
|
|
441
|
+
if (tableDeletion === void 0) break;
|
|
442
|
+
precedingTableDeletionOf.set(item, tableDeletion);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
427
445
|
const deleted = new Set(deletionOf.keys());
|
|
428
446
|
const joinedAway = new Set(items.flatMap(({ plan }) => plan.claim.type === "merge" && plan.claim.joinsNow ? [plan.block] : []));
|
|
429
447
|
const deletedSplits = new Set(items.flatMap(({ operation, plan }) => {
|
|
@@ -476,6 +494,8 @@ const orderCanonicalBatch = ({ items, doc, mode }) => {
|
|
|
476
494
|
rank: before.rank + steps
|
|
477
495
|
} : planned;
|
|
478
496
|
};
|
|
497
|
+
const precedingTableDeletion = precedingTableDeletionOf.get(item);
|
|
498
|
+
if (precedingTableDeletion !== void 0) return following(precedingTableDeletion, 1);
|
|
479
499
|
const deletion = plan.claim.type === "merge" && plan.claim.joinsNow ? deletionOf.get(plan.claim.next) : void 0;
|
|
480
500
|
if (deletion !== void 0) return following(deletion, 2);
|
|
481
501
|
const run = operation.type === "deleteBlock" ? deletedRunBeforeBlock(plan.block, item.retiresRunBreak !== void 0) : void 0;
|
|
@@ -731,12 +751,12 @@ const lastPutAfterIsTable = (placed) => {
|
|
|
731
751
|
const last = placed.findLast((operation) => placementSide(operation) === "after");
|
|
732
752
|
return last !== void 0 && placesTable(last);
|
|
733
753
|
};
|
|
734
|
-
const deletedParagraphPlacement = ({ beside, tableBefore,
|
|
754
|
+
const deletedParagraphPlacement = ({ beside, tableBefore, tableAfter, after }) => {
|
|
735
755
|
const before = beside.filter((operation) => placementSide(operation) === "before");
|
|
736
756
|
const last = before.at(-1);
|
|
737
757
|
const firstAfter = beside.find((operation) => placementSide(operation) === "after");
|
|
738
758
|
const precededByTable = last === void 0 ? tableBefore : placesTable(last);
|
|
739
|
-
const followedByTable = firstAfter === void 0 ?
|
|
759
|
+
const followedByTable = firstAfter === void 0 ? tableAfter : placesTable(firstAfter);
|
|
740
760
|
if (precededByTable && followedByTable) return { type: "keepsTablesApart" };
|
|
741
761
|
if (after === null || after.type.name === "paragraph") return { type: "inPlace" };
|
|
742
762
|
const firstParagraph = before.findIndex((operation) => operation.type === "insertBeforeBlock");
|
|
@@ -1760,7 +1780,15 @@ const resolveTableInsertion = ({ operation, listStart, paragraph, projection, st
|
|
|
1760
1780
|
noteReferences
|
|
1761
1781
|
});
|
|
1762
1782
|
const pendingJoinRefusal = () => refusal(PENDING_JOIN_INSERTION_REFUSAL.reason, PENDING_JOIN_INSERTION_REFUSAL.message);
|
|
1763
|
-
const followsDeletedBreak = (
|
|
1783
|
+
const followsDeletedBreak = (position) => {
|
|
1784
|
+
const $position = projection.doc.resolve(position);
|
|
1785
|
+
for (let index = $position.index() - 1; index >= 0; index--) {
|
|
1786
|
+
const previous = $position.parent.child(index);
|
|
1787
|
+
if (previous.type.name !== "paragraph" || !isDeletedPPrMark(previous.attrs["pPrMark"])) return false;
|
|
1788
|
+
if (!paragraphGoes(previous, "accept")) return true;
|
|
1789
|
+
}
|
|
1790
|
+
return false;
|
|
1791
|
+
};
|
|
1764
1792
|
const pendingBreakRefusal = () => refusal(PENDING_BREAK_TABLE_REFUSAL.reason, PENDING_BREAK_TABLE_REFUSAL.message);
|
|
1765
1793
|
const outer = findOutermostTableBoundary(projection.doc, paragraph.start - 1);
|
|
1766
1794
|
if (outer !== null) {
|
|
@@ -1783,7 +1811,7 @@ const resolveTableInsertion = ({ operation, listStart, paragraph, projection, st
|
|
|
1783
1811
|
const neighbour = $place.parent.maybeChild($place.index() + (side === "after" ? 1 : -1));
|
|
1784
1812
|
const gap = side === "after" ? place.start - 1 + place.node.nodeSize : place.start - 1;
|
|
1785
1813
|
if (stopsPendingJoin(gap)) return pendingJoinRefusal();
|
|
1786
|
-
if (side === "after" && followsDeletedBreak(
|
|
1814
|
+
if (side === "after" && followsDeletedBreak(gap)) return pendingBreakRefusal();
|
|
1787
1815
|
if (side === "before") {
|
|
1788
1816
|
const start = insertionGap(projection.doc, gap, side);
|
|
1789
1817
|
const pending = start < gap ? projection.doc.nodeAt(start) : null;
|
|
@@ -1794,7 +1822,7 @@ const resolveTableInsertion = ({ operation, listStart, paragraph, projection, st
|
|
|
1794
1822
|
});
|
|
1795
1823
|
if (address !== void 0) {
|
|
1796
1824
|
if (stopsPendingJoin(start)) return pendingJoinRefusal();
|
|
1797
|
-
if (followsDeletedBreak(
|
|
1825
|
+
if (followsDeletedBreak(start)) return pendingBreakRefusal();
|
|
1798
1826
|
return besideTable(address, start);
|
|
1799
1827
|
}
|
|
1800
1828
|
}
|
|
@@ -3812,17 +3840,17 @@ var CanonicalPublicOperations = class {
|
|
|
3812
3840
|
})]
|
|
3813
3841
|
};
|
|
3814
3842
|
}
|
|
3815
|
-
const
|
|
3816
|
-
if (
|
|
3843
|
+
const declinedLayoutChanges = new Set(batch.atomic ? [] : batch.operations.flatMap((operation) => placesBlock(operation) && declinedAsRun.has(operation.id) || operation.type === "deleteTable" && !appliedById.has(operation.id) && besideDeletions.deleted.size > 0 ? [operation.id] : []));
|
|
3844
|
+
if (declinedLayoutChanges.size > 0 && batch.operations.some(({ type }) => type === "deleteBlock" || type === "mergeBlockWithNext")) {
|
|
3817
3845
|
const rest = this.apply({
|
|
3818
3846
|
...options,
|
|
3819
3847
|
batch: {
|
|
3820
3848
|
...batch,
|
|
3821
|
-
operations: batch.operations.filter(({ id }) => !
|
|
3849
|
+
operations: batch.operations.filter(({ id }) => !declinedLayoutChanges.has(id))
|
|
3822
3850
|
}
|
|
3823
3851
|
});
|
|
3824
3852
|
const declinedSkips = skipped.flatMap((failure) => {
|
|
3825
|
-
if (!
|
|
3853
|
+
if (!declinedLayoutChanges.has(failure.id)) return [];
|
|
3826
3854
|
const canonicalRefusal = refusals.get(failure.id);
|
|
3827
3855
|
return [canonicalRefusal ? {
|
|
3828
3856
|
...failure,
|
|
@@ -3996,7 +4024,7 @@ var CanonicalPublicOperations = class {
|
|
|
3996
4024
|
* paragraph before it, whose mark then ends the list. Tracked, the text and
|
|
3997
4025
|
* the mark are marked deleted.
|
|
3998
4026
|
*/
|
|
3999
|
-
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, keepsTablesApart, followsInsertedTable, precedesInsertedTable,
|
|
4027
|
+
resolveBlockDeletion({ operation, paragraph, projection, projectionStory, doc, tracked, deletesJoinedWords, gainsFollower, keepsTablesApart, followsInsertedTable, precedesInsertedTable, bordersRemovedTable, previousGainsFollower, tableBeforeGainsFollower, endsOnceAccepted, deletedRun, deletedByBatch, refusal }) {
|
|
4000
4028
|
if (operation.comment !== void 0 && !tracked) return refusal("unsupportedBlock");
|
|
4001
4029
|
if (tracked && goesWholeOnAcceptance(paragraph.node)) return refusal("noopOperation");
|
|
4002
4030
|
const end = paragraph.start + paragraph.node.content.size;
|
|
@@ -4033,7 +4061,7 @@ var CanonicalPublicOperations = class {
|
|
|
4033
4061
|
paragraph.node.descendants((node) => {
|
|
4034
4062
|
if (node.isText && !node.marks.some(({ type }) => type.name === "insertion" || type.name === "deletion")) holdsOriginalWords = true;
|
|
4035
4063
|
});
|
|
4036
|
-
if (operation.moveId === void 0 && !gainsFollower && (keepsTablesApart || tracked && (after?.type.name === "table" || precedesInsertedTable) && isInsertedPPrMark(paragraph.node.attrs["pPrMark"]) && holdsOriginalWords)) {
|
|
4064
|
+
if (operation.moveId === void 0 && !gainsFollower && (keepsTablesApart || tracked && (after?.type.name === "table" || precedesInsertedTable) && isInsertedPPrMark(paragraph.node.attrs["pPrMark"]) && holdsOriginalWords && joinedWordsStart === void 0)) {
|
|
4037
4065
|
if (paragraph.start === end) return refusal("noopOperation");
|
|
4038
4066
|
const start = keepsTablesApart ? paragraph.start : joinedWordsStart ?? paragraph.start;
|
|
4039
4067
|
const from = projection.addressAt(start);
|
|
@@ -4079,7 +4107,7 @@ var CanonicalPublicOperations = class {
|
|
|
4079
4107
|
}
|
|
4080
4108
|
let range;
|
|
4081
4109
|
if (!tracked) {
|
|
4082
|
-
if (after !== null && !followsInsertedTable && (before === null || (before.type.name === "paragraph" ||
|
|
4110
|
+
if (after !== null && !followsInsertedTable && (before === null || (before.type.name === "paragraph" || bordersRemovedTable) && paragraph.node.attrs["_sectionProperties"] == null)) return tracking({
|
|
4083
4111
|
intents: [{
|
|
4084
4112
|
type: "deleteParagraphs",
|
|
4085
4113
|
story: projectionStory,
|
|
@@ -4336,7 +4364,7 @@ var CanonicalPublicOperations = class {
|
|
|
4336
4364
|
const projection = this.options.session.projectStory(story);
|
|
4337
4365
|
if (!anchor || projection.isErr()) return refusal("missingBlock");
|
|
4338
4366
|
const paragraph = projection.value.paragraph(blockId);
|
|
4339
|
-
if (!paragraph) return holdsParagraph(state.doc, blockId) ? refusal("unsupportedBlock", "The canonical session holds no address in this paragraph
|
|
4367
|
+
if (!paragraph) return holdsParagraph(state.doc, blockId) ? refusal("unsupportedBlock", "The canonical session holds no address in this paragraph.") : refusal("missingBlock");
|
|
4340
4368
|
if ((operation.type === "insertTable" || operation.type === "insertSignatureTable") && !supportsTableInsertionMode(operation.type, options.batch.mode ?? "tracked-changes")) return refusal("unsupportedMode");
|
|
4341
4369
|
const noteReferences = collectNoteReferenceLabels(state.doc);
|
|
4342
4370
|
const clean = buildCleanBlockText(paragraph.node, paragraph.start - 1, {
|
|
@@ -4364,12 +4392,32 @@ var CanonicalPublicOperations = class {
|
|
|
4364
4392
|
const followed = blockAfter?.type.name === "paragraph";
|
|
4365
4393
|
const blockBefore = state.doc.resolve(paragraph.start - 1).nodeBefore;
|
|
4366
4394
|
const previousId = blockBefore?.type.name === "paragraph" ? blockBefore.attrs["paraId"] : void 0;
|
|
4367
|
-
const
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4395
|
+
const batchRemovesTable = (block) => besideDeletions.tables.deleted.size > 0 && tableParagraphIds(block).some((id) => besideDeletions.tables.deleted.has(id));
|
|
4396
|
+
const tableWillBeRemoved = (block) => block.type.name === "table" && (tracked && tableGoes(block, "accept") || batchRemovesTable(block));
|
|
4397
|
+
const resolveDeletedPlacement = () => {
|
|
4398
|
+
let beforePos = paragraph.start - 1;
|
|
4399
|
+
let afterPos = beforePos + paragraph.node.nodeSize;
|
|
4400
|
+
let before = blockBefore;
|
|
4401
|
+
let after = blockAfter;
|
|
4402
|
+
while (before !== null && tableWillBeRemoved(before)) {
|
|
4403
|
+
beforePos -= before.nodeSize;
|
|
4404
|
+
before = state.doc.resolve(beforePos).nodeBefore;
|
|
4405
|
+
}
|
|
4406
|
+
while (after !== null && tableWillBeRemoved(after)) {
|
|
4407
|
+
const beyond = state.doc.resolve(afterPos + after.nodeSize).nodeAfter;
|
|
4408
|
+
if (!batchRemovesTable(after) && beyond?.type.name === "paragraph" && typeof beyond.attrs["paraId"] === "string" && besideDeletions.deleted.has(beyond.attrs["paraId"])) break;
|
|
4409
|
+
afterPos += after.nodeSize;
|
|
4410
|
+
after = beyond;
|
|
4411
|
+
}
|
|
4412
|
+
const precedingId = before?.type.name === "paragraph" ? before.attrs["paraId"] : void 0;
|
|
4413
|
+
return deletedParagraphPlacement({
|
|
4414
|
+
beside: besideDeletions.placedBeside(blockId),
|
|
4415
|
+
tableBefore: before?.type.name === "table" || typeof precedingId === "string" && lastPutAfterIsTable(besideDeletions.placedBeside(precedingId)),
|
|
4416
|
+
tableAfter: after?.type.name === "table",
|
|
4417
|
+
after: blockAfter
|
|
4418
|
+
});
|
|
4419
|
+
};
|
|
4420
|
+
const besideDeleted = besideDeletions.deleted.has(blockId) ? resolveDeletedPlacement() : void 0;
|
|
4373
4421
|
const keepsTablesApart = besideDeleted?.type === "keepsTablesApart";
|
|
4374
4422
|
if (isTableStructureOperation(operation)) return resolveTableStructure({
|
|
4375
4423
|
operation,
|
|
@@ -4486,7 +4534,7 @@ var CanonicalPublicOperations = class {
|
|
|
4486
4534
|
keepsTablesApart,
|
|
4487
4535
|
followsInsertedTable,
|
|
4488
4536
|
precedesInsertedTable: besideDeletions.tables.after.has(blockId) && !besideDeletions.paragraphsAfter.has(blockId),
|
|
4489
|
-
|
|
4537
|
+
bordersRemovedTable: before !== null && tableWillBeRemoved(before) || after !== null && tableWillBeRemoved(after),
|
|
4490
4538
|
previousGainsFollower: (!followed || endsOnceAccepted) && typeof previousId === "string" && (besideDeletions.paragraphsAfter.has(previousId) || besideDeletions.deleted.has(previousId)),
|
|
4491
4539
|
tableBeforeGainsFollower,
|
|
4492
4540
|
endsOnceAccepted,
|
|
@@ -4587,13 +4635,16 @@ var CanonicalPublicOperations = class {
|
|
|
4587
4635
|
from: from.value,
|
|
4588
4636
|
to: to.value
|
|
4589
4637
|
});
|
|
4590
|
-
if (operation.type === "commentOnBlock" || operation.type === "commentOnRange")
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4638
|
+
if (operation.type === "commentOnBlock" || operation.type === "commentOnRange") {
|
|
4639
|
+
if (options.batch.mode === "suggested" && start === end) return refusal("emptyOperation", "A proposed comment needs words of the paragraph to cover.");
|
|
4640
|
+
return Result.ok({
|
|
4641
|
+
...resolvedComment,
|
|
4642
|
+
intents: [],
|
|
4643
|
+
normalizations: [],
|
|
4644
|
+
from: range.from,
|
|
4645
|
+
to: range.to
|
|
4646
|
+
});
|
|
4647
|
+
}
|
|
4597
4648
|
const restyle = restyles && operation.type === "replaceBlock" && operation.styleId !== void 0 ? statedPropertiesIntents({
|
|
4598
4649
|
story,
|
|
4599
4650
|
blockId: paragraph.blockId,
|
|
@@ -4690,16 +4741,28 @@ var CanonicalPublicOperations = class {
|
|
|
4690
4741
|
...tracked ? { keepFieldsOf: planTextChanges } : {}
|
|
4691
4742
|
});
|
|
4692
4743
|
const addedComments = tracked ? batchCommentSpans(batchComments, blockId, clean.text) : [];
|
|
4693
|
-
const
|
|
4694
|
-
|
|
4744
|
+
const commentedAt = (index) => {
|
|
4745
|
+
const position = clean.offsets[index];
|
|
4746
|
+
return position !== void 0 && paragraph.node.nodeAt(position - paragraph.start)?.marks.some((mark) => mark.type.name === "comment") === true;
|
|
4747
|
+
};
|
|
4748
|
+
const commentTouchesGap = (gap) => commentedAt(gap - 1) || commentedAt(gap) || addedComments.some((span) => span.start <= gap && gap <= span.end);
|
|
4749
|
+
const touchesComment = (changes) => changes?.some((change) => {
|
|
4750
|
+
const changeStart = start + change.start;
|
|
4751
|
+
const changeEnd = start + change.end;
|
|
4752
|
+
for (let index = changeStart; index < changeEnd; index++) if (commentedAt(index)) return true;
|
|
4753
|
+
if (changeEnd > changeStart && addedComments.some((span) => span.start < changeEnd && changeStart < span.end)) return true;
|
|
4754
|
+
return change.text.length > 0 && (commentTouchesGap(changeStart) || commentTouchesGap(changeEnd));
|
|
4755
|
+
}) === true;
|
|
4756
|
+
if (tracked && touchesComment([{
|
|
4695
4757
|
start: 0,
|
|
4696
|
-
end: end - start
|
|
4758
|
+
end: end - start,
|
|
4759
|
+
text
|
|
4697
4760
|
}])) {
|
|
4698
4761
|
const directCuts = planReplacementChanges({
|
|
4699
4762
|
...replacementSource,
|
|
4700
4763
|
planChanges: planTextChanges
|
|
4701
4764
|
});
|
|
4702
|
-
if (
|
|
4765
|
+
if (touchesComment(planned) || touchesComment(directCuts)) planned = directCuts;
|
|
4703
4766
|
}
|
|
4704
4767
|
if (planned === null) return panic("A replacement's planned changes must reproduce it.");
|
|
4705
4768
|
const changes = cutAroundRepeatedSeparators(replacementSource.source, planned).map((change) => ({
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
2
|
+
import { DocumentOpRefusalReason } from "@stll/docx-core/ops";
|
|
3
|
+
/** The refusal ground a document operation refused for `reason` reports. */
|
|
4
|
+
export declare const groundForDocumentOpRefusal: (reason: DocumentOpRefusalReason) => CanonicalRefusalGround;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CANONICAL_CONDITION, CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
2
|
+
// src/canonical/canonicalRefusalGrounds.ts
|
|
3
|
+
const STALE = { condition: CANONICAL_CONDITION.stale };
|
|
4
|
+
const INVALID_REQUEST = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
5
|
+
/**
|
|
6
|
+
* The ground of every document operation refusal: a moved-on document is
|
|
7
|
+
* stale, an exhausted id space names it, a link suggestion review records
|
|
8
|
+
* cannot hold is the document's rule, content the tracked-change records
|
|
9
|
+
* cannot express is a gap, and every other reason describes a request the
|
|
10
|
+
* document does not allow.
|
|
11
|
+
*/
|
|
12
|
+
const DOCUMENT_OP_REFUSAL_GROUNDS = {
|
|
13
|
+
unsupportedSchema: INVALID_REQUEST,
|
|
14
|
+
blockNotFound: INVALID_REQUEST,
|
|
15
|
+
invalidOperation: INVALID_REQUEST,
|
|
16
|
+
noChange: INVALID_REQUEST,
|
|
17
|
+
dependentRecords: INVALID_REQUEST,
|
|
18
|
+
invalidOffset: INVALID_REQUEST,
|
|
19
|
+
crossBlockRange: INVALID_REQUEST,
|
|
20
|
+
splitsSurrogatePair: INVALID_REQUEST,
|
|
21
|
+
invalidText: INVALID_REQUEST,
|
|
22
|
+
invalidBlockId: INVALID_REQUEST,
|
|
23
|
+
idCollision: INVALID_REQUEST,
|
|
24
|
+
notAdjacent: INVALID_REQUEST,
|
|
25
|
+
sectionBoundary: INVALID_REQUEST,
|
|
26
|
+
insideTrackedDeletion: INVALID_REQUEST,
|
|
27
|
+
needsNewIds: { condition: CANONICAL_CONDITION.idSpace },
|
|
28
|
+
invalidNewId: INVALID_REQUEST,
|
|
29
|
+
sharedId: INVALID_REQUEST,
|
|
30
|
+
stale: STALE,
|
|
31
|
+
structureMismatch: INVALID_REQUEST,
|
|
32
|
+
emptyContent: INVALID_REQUEST,
|
|
33
|
+
emptyBlockList: INVALID_REQUEST,
|
|
34
|
+
revisionConflict: INVALID_REQUEST,
|
|
35
|
+
pendingTableChange: INVALID_REQUEST,
|
|
36
|
+
pendingRunPropertyChange: INVALID_REQUEST,
|
|
37
|
+
pendingParagraphPropertyChange: INVALID_REQUEST,
|
|
38
|
+
joinIntoPendingTable: INVALID_REQUEST,
|
|
39
|
+
containerFinalMark: INVALID_REQUEST,
|
|
40
|
+
insideInlineControl: INVALID_REQUEST,
|
|
41
|
+
untrackable: { gap: CANONICAL_GAP.trackedChangeRecords },
|
|
42
|
+
pendingBreakTakeover: INVALID_REQUEST,
|
|
43
|
+
pendingParagraphMarkDeletion: INVALID_REQUEST,
|
|
44
|
+
pendingParagraphMarkInsertion: INVALID_REQUEST,
|
|
45
|
+
pendingParagraphJoin: INVALID_REQUEST,
|
|
46
|
+
pendingGridChange: INVALID_REQUEST,
|
|
47
|
+
unrecordableLinkSuggestion: { rule: CANONICAL_RULE.linkSuggestionShape },
|
|
48
|
+
missingBlockId: INVALID_REQUEST,
|
|
49
|
+
duplicateBlockId: INVALID_REQUEST,
|
|
50
|
+
duplicateRecordId: INVALID_REQUEST,
|
|
51
|
+
sectionsOutOfStep: STALE,
|
|
52
|
+
emptyRecord: INVALID_REQUEST
|
|
53
|
+
};
|
|
54
|
+
/** The refusal ground a document operation refused for `reason` reports. */
|
|
55
|
+
const groundForDocumentOpRefusal = (reason) => DOCUMENT_OP_REFUSAL_GROUNDS[reason];
|
|
56
|
+
export { groundForDocumentOpRefusal };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { panic } from "better-result";
|
|
2
|
-
import { CellSelection } from "prosemirror-tables";
|
|
3
2
|
import { AllSelection, NodeSelection, TextSelection } from "prosemirror-state";
|
|
3
|
+
import { CellSelection } from "prosemirror-tables";
|
|
4
4
|
// src/canonical/canonicalSelection.ts
|
|
5
5
|
/** Restore the admitted selection kind after a canonical projection changes. */
|
|
6
6
|
const restoreCanonicalSelection = ({ transaction, projection, selection, unavailable }) => {
|
|
@@ -113,9 +113,11 @@ declare class CanonicalProjection {
|
|
|
113
113
|
*/
|
|
114
114
|
heldAs(doc: Node): CanonicalProjection;
|
|
115
115
|
private addressOf;
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
/**
|
|
117
|
+
* The paragraph whose content holds `position`, its ends included: a
|
|
118
|
+
* story paragraph, or one in a text box the story draws, which the
|
|
119
|
+
* projection lists after its host as the story's own.
|
|
120
|
+
*/
|
|
119
121
|
private paragraphAround;
|
|
120
122
|
addressAt(position: number, edge?: CanonicalAddressEdge): Result<TextPosition, CanonicalSessionError>;
|
|
121
123
|
/**
|
|
@@ -422,9 +424,11 @@ declare class CanonicalSession {
|
|
|
422
424
|
* the edit happens at the start of the first, as the editor's own command
|
|
423
425
|
* does over a cell selection. One commit, so one undo step.
|
|
424
426
|
*/
|
|
425
|
-
prepareCellSelectionStructure(state: EditorState, structure: (at: TextPosition) => EditorIntent, { resourceOps, semantic }?: {
|
|
427
|
+
prepareCellSelectionStructure(state: EditorState, structure: (at: TextPosition) => EditorIntent, { resourceOps, semantic, story }?: {
|
|
426
428
|
resourceOps?: readonly DocumentOp[];
|
|
427
429
|
semantic?: CanonicalInputSemantic;
|
|
430
|
+
/** The story whose editor holds the cell selection. */
|
|
431
|
+
story?: OpStory;
|
|
428
432
|
}): Result<CanonicalCommit, CanonicalSessionError>;
|
|
429
433
|
prepareIntent(state: EditorState, intent: EditorIntent): Result<CanonicalCommit, CanonicalSessionError>;
|
|
430
434
|
prepareIntents(state: EditorState, { intents, resourceOps, semantic }: {
|
|
@@ -448,8 +452,10 @@ declare class CanonicalSession {
|
|
|
448
452
|
* the edit undoes both. Refused when no local edit is open.
|
|
449
453
|
*/
|
|
450
454
|
prepareDerivedUpdate(state: EditorState, ops: readonly DocumentOp[]): Result<CanonicalCommit, CanonicalSessionError>;
|
|
451
|
-
|
|
452
|
-
|
|
455
|
+
/** Split the paragraph at the selection of the editor showing `story`. */
|
|
456
|
+
prepareSplit(state: EditorState, story?: OpStory): Result<CanonicalCommit, CanonicalSessionError>;
|
|
457
|
+
/** Join the paragraph at the caret of the editor showing `story` with its neighbour. */
|
|
458
|
+
prepareJoin(state: EditorState, direction: "backward" | "forward", story?: OpStory): Result<CanonicalCommit, CanonicalSessionError>;
|
|
453
459
|
prepareResolve(state: EditorState, { revisionIds, resolution, before }: {
|
|
454
460
|
revisionIds: readonly number[];
|
|
455
461
|
resolution: "accept" | "reject";
|