@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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TrackedChangeEntry } from "./utils/extractTrackedChanges.js";
|
|
2
|
+
import { Command, EditorState } from "prosemirror-state";
|
|
3
|
+
/**
|
|
4
|
+
* Add a comment mark to the current selection.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addCommentMark(commentId: number): Command;
|
|
7
|
+
/**
|
|
8
|
+
* Remove a comment mark by ID from the entire document.
|
|
9
|
+
*/
|
|
10
|
+
export declare function removeCommentMark(commentId: number): Command;
|
|
11
|
+
export type ParagraphBoundaryChange = {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
type: "insertion" | "deletion";
|
|
15
|
+
author?: string;
|
|
16
|
+
date?: string;
|
|
17
|
+
revisionId?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function findParagraphBoundaryChangeAtPosition(state: EditorState, pos: number): ParagraphBoundaryChange | null;
|
|
20
|
+
/** Every revision id one sidebar entry stands for. */
|
|
21
|
+
export declare const trackedChangeEntryRevisionIds: (entry: TrackedChangeEntry) => number[];
|
|
22
|
+
type ChangeRange = {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
type: "insertion" | "deletion";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Find the tracked change mark range at a given cursor position.
|
|
29
|
+
* If the cursor is inside a tracked change, returns the full extent
|
|
30
|
+
* of that mark (expanding to cover all adjacent nodes with the same
|
|
31
|
+
* revision ID). If from !== to (range selection), returns {from, to}.
|
|
32
|
+
*/
|
|
33
|
+
export declare function findChangeAtPosition(state: EditorState, from: number, to: number): {
|
|
34
|
+
from: number;
|
|
35
|
+
to: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Find the next tracked change after the given position. Returns the full
|
|
39
|
+
* range of the change (including adjacent text nodes that share the same
|
|
40
|
+
* insertion/deletion mark instance), not just the first text node.
|
|
41
|
+
*/
|
|
42
|
+
export declare function findNextChange(state: EditorState, startPos: number): ChangeRange | null;
|
|
43
|
+
/**
|
|
44
|
+
* Find the previous tracked change before the given position. Returns the
|
|
45
|
+
* full range of the change (including adjacent text nodes that share the
|
|
46
|
+
* same insertion/deletion mark instance), not just the last text node.
|
|
47
|
+
*/
|
|
48
|
+
export declare function findPreviousChange(state: EditorState, startPos: number): ChangeRange | null;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { sameStatedParagraphNumbering } from "../docx/numberingReference.js";
|
|
2
|
+
import { expectParagraphAttrs } from "./attrs/index.js";
|
|
3
|
+
import { enclosingRevisionIds } from "./contentControlRevisions.js";
|
|
4
|
+
import "./extensions/nodes/SdtExtension.js";
|
|
5
|
+
import { isPPrMarkAttr, paragraphMarkWasAdded } from "./revisionCarriers.js";
|
|
6
|
+
import { extractTrackedChanges } from "./utils/extractTrackedChanges.js";
|
|
7
|
+
import "prosemirror-model";
|
|
8
|
+
// src/prosemirror/projectionReview.ts
|
|
9
|
+
/**
|
|
10
|
+
* Add a comment mark to the current selection.
|
|
11
|
+
*/
|
|
12
|
+
function addCommentMark(commentId) {
|
|
13
|
+
return (state, dispatch) => {
|
|
14
|
+
const { from, to, empty } = state.selection;
|
|
15
|
+
if (empty) return false;
|
|
16
|
+
const commentType = state.schema.marks["comment"];
|
|
17
|
+
if (!commentType) return false;
|
|
18
|
+
if (dispatch) dispatch(state.tr.addMark(from, to, commentType.create({ commentId })));
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Remove a comment mark by ID from the entire document.
|
|
24
|
+
*/
|
|
25
|
+
function removeCommentMark(commentId) {
|
|
26
|
+
return (state, dispatch) => {
|
|
27
|
+
const commentType = state.schema.marks["comment"];
|
|
28
|
+
if (!commentType) return false;
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
const tr = state.tr;
|
|
31
|
+
state.doc.descendants((node, pos) => {
|
|
32
|
+
if (node.isText) {
|
|
33
|
+
for (const mark of node.marks) if (mark.type === commentType && mark.attrs["commentId"] === commentId) tr.removeMark(pos, pos + node.nodeSize, mark);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (tr.steps.length > 0) dispatch(tr);
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function readRevisionInfo(info) {
|
|
42
|
+
const revision = {};
|
|
43
|
+
if (typeof info?.author === "string") revision.author = info.author;
|
|
44
|
+
if (typeof info?.date === "string") revision.date = info.date;
|
|
45
|
+
if (typeof info?.id === "number") revision.revisionId = info.id;
|
|
46
|
+
return revision;
|
|
47
|
+
}
|
|
48
|
+
function getListPropertyChangeType(node, change) {
|
|
49
|
+
const previousFormatting = change.previousFormatting;
|
|
50
|
+
if (previousFormatting == null || !Object.hasOwn(previousFormatting, "numPr")) return null;
|
|
51
|
+
const current = expectParagraphAttrs(node).numPr;
|
|
52
|
+
const previous = previousFormatting["numPr"] ?? void 0;
|
|
53
|
+
if (sameStatedParagraphNumbering(previous, current)) return null;
|
|
54
|
+
return current === void 0 ? "deletion" : "insertion";
|
|
55
|
+
}
|
|
56
|
+
function toParagraphBoundaryChange(node, pos, type, info) {
|
|
57
|
+
return {
|
|
58
|
+
from: pos + node.nodeSize - 1,
|
|
59
|
+
to: pos + node.nodeSize,
|
|
60
|
+
type,
|
|
61
|
+
...readRevisionInfo(info)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function findParagraphBoundaryChangeAtPosition(state, pos) {
|
|
65
|
+
const $pos = state.doc.resolve(pos);
|
|
66
|
+
const node = $pos.parent;
|
|
67
|
+
if (node.type.name !== "paragraph") return null;
|
|
68
|
+
const paragraphPos = $pos.before($pos.depth);
|
|
69
|
+
const pPrMark = node.attrs["pPrMark"];
|
|
70
|
+
if (isPPrMarkAttr(pPrMark)) return toParagraphBoundaryChange(node, paragraphPos, paragraphMarkWasAdded(pPrMark.kind) ? "insertion" : "deletion", pPrMark.info);
|
|
71
|
+
const propertyChanges = expectParagraphAttrs(node)._propertyChanges;
|
|
72
|
+
if (!Array.isArray(propertyChanges)) return null;
|
|
73
|
+
for (const change of propertyChanges) {
|
|
74
|
+
const type = getListPropertyChangeType(node, change);
|
|
75
|
+
if (type) return toParagraphBoundaryChange(node, paragraphPos, type, change.info);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/** Every revision id one sidebar entry stands for. */
|
|
80
|
+
const trackedChangeEntryRevisionIds = (entry) => [.../* @__PURE__ */ new Set([
|
|
81
|
+
entry.revisionId,
|
|
82
|
+
...entry.insertionRevisionId === void 0 ? [] : [entry.insertionRevisionId],
|
|
83
|
+
...entry.coalescedRevisionIds ?? []
|
|
84
|
+
])];
|
|
85
|
+
const pairedReplacementRangesByDoc = /* @__PURE__ */ new WeakMap();
|
|
86
|
+
const pairedReplacementRanges = (state) => {
|
|
87
|
+
const cached = pairedReplacementRangesByDoc.get(state.doc);
|
|
88
|
+
if (cached) return cached;
|
|
89
|
+
const ranges = [];
|
|
90
|
+
const { entries } = extractTrackedChanges(state);
|
|
91
|
+
for (const entry of entries) {
|
|
92
|
+
if (entry.type !== "replacement" || entry.insertionRevisionId === void 0) continue;
|
|
93
|
+
ranges.push({
|
|
94
|
+
from: entry.from,
|
|
95
|
+
to: entry.to
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
pairedReplacementRangesByDoc.set(state.doc, ranges);
|
|
99
|
+
return ranges;
|
|
100
|
+
};
|
|
101
|
+
const pairedReplacementRangeAt = ({ ranges, from, to }) => {
|
|
102
|
+
let low = 0;
|
|
103
|
+
let high = ranges.length;
|
|
104
|
+
while (low < high) {
|
|
105
|
+
const middle = Math.floor((low + high) / 2);
|
|
106
|
+
if (ranges[middle].from <= from) low = middle + 1;
|
|
107
|
+
else high = middle;
|
|
108
|
+
}
|
|
109
|
+
const candidate = ranges[low - 1];
|
|
110
|
+
return candidate && from >= candidate.from && to <= candidate.to ? candidate : void 0;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Find the tracked change mark range at a given cursor position.
|
|
114
|
+
* If the cursor is inside a tracked change, returns the full extent
|
|
115
|
+
* of that mark (expanding to cover all adjacent nodes with the same
|
|
116
|
+
* revision ID). If from !== to (range selection), returns {from, to}.
|
|
117
|
+
*/
|
|
118
|
+
function findChangeAtPosition(state, from, to) {
|
|
119
|
+
if (from !== to) return {
|
|
120
|
+
from,
|
|
121
|
+
to
|
|
122
|
+
};
|
|
123
|
+
const insertionType = state.schema.marks["insertion"];
|
|
124
|
+
const deletionType = state.schema.marks["deletion"];
|
|
125
|
+
if (!insertionType && !deletionType) return {
|
|
126
|
+
from,
|
|
127
|
+
to
|
|
128
|
+
};
|
|
129
|
+
const $pos = state.doc.resolve(from);
|
|
130
|
+
const node = $pos.parent;
|
|
131
|
+
if (!node.inlineContent) return {
|
|
132
|
+
from,
|
|
133
|
+
to
|
|
134
|
+
};
|
|
135
|
+
let markStart = from;
|
|
136
|
+
let markEnd = from;
|
|
137
|
+
let foundMark;
|
|
138
|
+
node.forEach((child, offset) => {
|
|
139
|
+
const childStart = $pos.start() + offset;
|
|
140
|
+
const childEnd = childStart + child.nodeSize;
|
|
141
|
+
if (from >= childStart && from <= childEnd && child.isText) {
|
|
142
|
+
for (const mark of child.marks) if (mark.type === insertionType || mark.type === deletionType) {
|
|
143
|
+
foundMark = mark;
|
|
144
|
+
markStart = childStart;
|
|
145
|
+
markEnd = childEnd;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
if (foundMark === void 0) {
|
|
150
|
+
const paragraphChange = findParagraphBoundaryChangeAtPosition(state, from);
|
|
151
|
+
return paragraphChange ? {
|
|
152
|
+
from: paragraphChange.from,
|
|
153
|
+
to: paragraphChange.to
|
|
154
|
+
} : {
|
|
155
|
+
from,
|
|
156
|
+
to
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const sameMark = foundMark;
|
|
160
|
+
const children = [];
|
|
161
|
+
node.forEach((child, offset) => {
|
|
162
|
+
if (!child.isText) return;
|
|
163
|
+
const childStart = $pos.start() + offset;
|
|
164
|
+
children.push({
|
|
165
|
+
childStart,
|
|
166
|
+
childEnd: childStart + child.nodeSize,
|
|
167
|
+
marks: child.marks
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
let extended = true;
|
|
171
|
+
while (extended) {
|
|
172
|
+
extended = false;
|
|
173
|
+
for (const child of children) {
|
|
174
|
+
if (!child.marks.some((m) => m.eq(sameMark))) continue;
|
|
175
|
+
if (child.childEnd === markStart) {
|
|
176
|
+
markStart = child.childStart;
|
|
177
|
+
extended = true;
|
|
178
|
+
}
|
|
179
|
+
if (child.childStart === markEnd) {
|
|
180
|
+
markEnd = child.childEnd;
|
|
181
|
+
extended = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
from: markStart,
|
|
187
|
+
to: markEnd
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Walk outward from `[fromHint, toHint]` and return the full extent of the
|
|
192
|
+
* tracked-change span carrying `mark` (matched via `Mark.eq`, so attrs like
|
|
193
|
+
* `revisionId` distinguish adjacent changes). Used to keep the
|
|
194
|
+
* navigation/scroll helpers honest when a tracked-change span is split
|
|
195
|
+
* across multiple text nodes due to inline formatting (e.g., a bold word
|
|
196
|
+
* inside an insertion).
|
|
197
|
+
*/
|
|
198
|
+
function expandTrackedChangeRange(state, mark, fromHint, toHint) {
|
|
199
|
+
const carriesSameInlineMark = (node) => node?.isInline === true && node.marks.some((m) => m.eq(mark));
|
|
200
|
+
let from = fromHint;
|
|
201
|
+
let to = toHint;
|
|
202
|
+
const revisionId = mark.attrs["revisionId"];
|
|
203
|
+
for (;;) {
|
|
204
|
+
let $from = state.doc.resolve(from);
|
|
205
|
+
let nodeBefore = $from.nodeBefore;
|
|
206
|
+
while (carriesSameInlineMark(nodeBefore)) {
|
|
207
|
+
from -= nodeBefore.nodeSize;
|
|
208
|
+
$from = state.doc.resolve(from);
|
|
209
|
+
nodeBefore = $from.nodeBefore;
|
|
210
|
+
}
|
|
211
|
+
let $to = state.doc.resolve(to);
|
|
212
|
+
let nodeAfter = $to.nodeAfter;
|
|
213
|
+
while (carriesSameInlineMark(nodeAfter)) {
|
|
214
|
+
to += nodeAfter.nodeSize;
|
|
215
|
+
$to = state.doc.resolve(to);
|
|
216
|
+
nodeAfter = $to.nodeAfter;
|
|
217
|
+
}
|
|
218
|
+
const control = $from.parent;
|
|
219
|
+
if (control.type.name !== "sdt" || typeof revisionId !== "number" || !enclosingRevisionIds(control).includes(revisionId) || from !== $from.start() || to !== $from.end()) return {
|
|
220
|
+
from,
|
|
221
|
+
to
|
|
222
|
+
};
|
|
223
|
+
from = $from.before();
|
|
224
|
+
to = $from.after();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Find the next tracked change after the given position. Returns the full
|
|
229
|
+
* range of the change (including adjacent text nodes that share the same
|
|
230
|
+
* insertion/deletion mark instance), not just the first text node.
|
|
231
|
+
*/
|
|
232
|
+
function findNextChange(state, startPos) {
|
|
233
|
+
const insertionType = state.schema.marks["insertion"];
|
|
234
|
+
const deletionType = state.schema.marks["deletion"];
|
|
235
|
+
if (!insertionType && !deletionType) return null;
|
|
236
|
+
const replacementRanges = pairedReplacementRanges(state);
|
|
237
|
+
const result = { value: null };
|
|
238
|
+
state.doc.descendants((node, pos) => {
|
|
239
|
+
if (result.value) return false;
|
|
240
|
+
if (!node.isInline) return;
|
|
241
|
+
if (pos + node.nodeSize <= startPos) return;
|
|
242
|
+
for (const mark of node.marks) if (mark.type === insertionType || mark.type === deletionType) {
|
|
243
|
+
const expanded = pairedReplacementRangeAt({
|
|
244
|
+
ranges: replacementRanges,
|
|
245
|
+
from: pos,
|
|
246
|
+
to: pos + node.nodeSize
|
|
247
|
+
}) ?? expandTrackedChangeRange(state, mark, pos, pos + node.nodeSize);
|
|
248
|
+
result.value = {
|
|
249
|
+
from: expanded.from,
|
|
250
|
+
to: expanded.to,
|
|
251
|
+
type: mark.type === insertionType ? "insertion" : "deletion"
|
|
252
|
+
};
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (result.value === null && startPos > 0) return findNextChange(state, 0);
|
|
257
|
+
return result.value;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Find the previous tracked change before the given position. Returns the
|
|
261
|
+
* full range of the change (including adjacent text nodes that share the
|
|
262
|
+
* same insertion/deletion mark instance), not just the last text node.
|
|
263
|
+
*/
|
|
264
|
+
function findPreviousChange(state, startPos) {
|
|
265
|
+
const insertionType = state.schema.marks["insertion"];
|
|
266
|
+
const deletionType = state.schema.marks["deletion"];
|
|
267
|
+
if (!insertionType && !deletionType) return null;
|
|
268
|
+
const replacementRanges = pairedReplacementRanges(state);
|
|
269
|
+
const result = { value: null };
|
|
270
|
+
let resultMark = null;
|
|
271
|
+
state.doc.descendants((node, pos) => {
|
|
272
|
+
if (!node.isInline) return;
|
|
273
|
+
if (pos >= startPos) return false;
|
|
274
|
+
if (result.value && resultMark && pos < result.value.to && node.marks.every((m) => m.type !== insertionType && m.type !== deletionType || m.eq(resultMark))) return;
|
|
275
|
+
for (const mark of node.marks) if (mark.type === insertionType || mark.type === deletionType) {
|
|
276
|
+
const expanded = pairedReplacementRangeAt({
|
|
277
|
+
ranges: replacementRanges,
|
|
278
|
+
from: pos,
|
|
279
|
+
to: pos + node.nodeSize
|
|
280
|
+
}) ?? expandTrackedChangeRange(state, mark, pos, pos + node.nodeSize);
|
|
281
|
+
result.value = {
|
|
282
|
+
from: expanded.from,
|
|
283
|
+
to: expanded.to,
|
|
284
|
+
type: mark.type === insertionType ? "insertion" : "deletion"
|
|
285
|
+
};
|
|
286
|
+
resultMark = mark;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
if (result.value === null && startPos < state.doc.content.size) return findPreviousChange(state, state.doc.content.size);
|
|
290
|
+
return result.value;
|
|
291
|
+
}
|
|
292
|
+
export { addCommentMark, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, removeCommentMark, trackedChangeEntryRevisionIds };
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
-
import { Transaction } from "prosemirror-state";
|
|
3
2
|
import { Node } from "prosemirror-model";
|
|
4
3
|
import { Transform } from "prosemirror-transform";
|
|
5
|
-
|
|
6
|
-
nextAttrs: Record<string, unknown>;
|
|
7
|
-
paragraphPosition: number;
|
|
8
|
-
shouldRebase?: (node: Node) => boolean;
|
|
9
|
-
styleResolver: RunStyleResolver;
|
|
10
|
-
tr: Transaction;
|
|
11
|
-
};
|
|
4
|
+
export declare const paragraphAt: (tr: Transform, paragraphPosition: number) => Node;
|
|
12
5
|
type RebaseParagraphRunsOptions<T extends Transform> = {
|
|
13
6
|
/** The style context the runs' marks were resolved in. */
|
|
14
7
|
previousContext: ParagraphRunStyleContext;
|
|
@@ -28,9 +21,4 @@ type RebaseParagraphRunsOptions<T extends Transform> = {
|
|
|
28
21
|
* the old context lent the runs goes with it.
|
|
29
22
|
*/
|
|
30
23
|
export declare const rebaseParagraphRuns: <T extends Transform>({ previousContext, paragraphPosition, range, shouldRebase, styleResolver, tr }: RebaseParagraphRunsOptions<T>) => T;
|
|
31
|
-
/**
|
|
32
|
-
* Change paragraph attrs and re-resolve inherited run marks in the new style
|
|
33
|
-
* context without turning the old rendered style into direct run formatting.
|
|
34
|
-
*/
|
|
35
|
-
export declare const setParagraphAttrsWithRebasedRunFormatting: ({ nextAttrs, paragraphPosition, shouldRebase, styleResolver, tr }: RebaseParagraphRunFormattingOptions) => Transaction;
|
|
36
24
|
export {};
|
|
@@ -70,19 +70,4 @@ const rebaseParagraphRuns = ({ previousContext, paragraphPosition, range, should
|
|
|
70
70
|
}
|
|
71
71
|
return tr;
|
|
72
72
|
};
|
|
73
|
-
|
|
74
|
-
* Change paragraph attrs and re-resolve inherited run marks in the new style
|
|
75
|
-
* context without turning the old rendered style into direct run formatting.
|
|
76
|
-
*/
|
|
77
|
-
const setParagraphAttrsWithRebasedRunFormatting = ({ nextAttrs, paragraphPosition, shouldRebase, styleResolver, tr }) => {
|
|
78
|
-
const previousContext = paragraphRunStyleContext(paragraphAt(tr, paragraphPosition), styleResolver);
|
|
79
|
-
tr = tr.setNodeMarkup(paragraphPosition, void 0, nextAttrs);
|
|
80
|
-
return rebaseParagraphRuns({
|
|
81
|
-
previousContext,
|
|
82
|
-
paragraphPosition,
|
|
83
|
-
...shouldRebase ? { shouldRebase } : {},
|
|
84
|
-
styleResolver,
|
|
85
|
-
tr
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
export { rebaseParagraphRuns, setParagraphAttrsWithRebasedRunFormatting };
|
|
73
|
+
export { paragraphAt, rebaseParagraphRuns };
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* span. It can propose a point at the replacement start for an emptied range;
|
|
18
18
|
* downstream ranged-comment exhaustion may retire that comment. The applier
|
|
19
19
|
* decides alignment once for direct and tracked edits.
|
|
20
|
-
* Canonical replacements
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Canonical replacements place comment anchors by the docx-core policy
|
|
21
|
+
* beside `rangeEndAfterDeletion`: markers inside the replaced words stay,
|
|
22
|
+
* in order, before the new words, and a range left covering nothing goes.
|
|
23
23
|
*
|
|
24
24
|
* - `comment` mark: carried over its aligned replacement span.
|
|
25
25
|
* - `hyperlink` mark: the replacement carries the first link the span held, so
|
|
@@ -59,10 +59,8 @@
|
|
|
59
59
|
* already gives the replacement the formatting of the text it replaces.
|
|
60
60
|
*
|
|
61
61
|
* Removing the owning block removes its comment. Point anchors proposed by
|
|
62
|
-
* the alignment helper do not override ranged-comment retirement
|
|
63
|
-
* canonical guard refuses point transitions whose outcome is not proven.
|
|
62
|
+
* the alignment helper do not override ranged-comment retirement.
|
|
64
63
|
*/
|
|
65
|
-
import { document_d_exports } from "../types/document.js";
|
|
66
64
|
import { Transaction } from "prosemirror-state";
|
|
67
65
|
import { Fragment, Mark, Node, Schema } from "prosemirror-model";
|
|
68
66
|
/**
|
|
@@ -87,18 +85,15 @@ export declare const NON_INCLUSIVE_MARK_DISPOSITION: {
|
|
|
87
85
|
export declare const nonInclusiveMarkNames: (schema: Schema) => string[];
|
|
88
86
|
/** One typed anchor for a comment authored as a point. */
|
|
89
87
|
export declare const commentPoint: (schema: Schema, id: number) => Node;
|
|
90
|
-
type
|
|
91
|
-
doc: Node;
|
|
88
|
+
type ResolvedCommentPointCollectorOptions = {
|
|
92
89
|
removes: (node: Node, position: number) => boolean;
|
|
93
90
|
retiresStructure: (node: Node, position: number) => boolean;
|
|
94
91
|
};
|
|
95
92
|
/** The same collector serves standalone commands and the existing bulk walk. */
|
|
96
|
-
export declare const createResolvedCommentPointCollector: ({ removes, retiresStructure }:
|
|
93
|
+
export declare const createResolvedCommentPointCollector: ({ removes, retiresStructure }: ResolvedCommentPointCollectorOptions) => {
|
|
97
94
|
visit: (node: Node, position: number, previous?: Node) => boolean;
|
|
98
95
|
finish: () => Map<number, number>;
|
|
99
96
|
};
|
|
100
|
-
/** Ranged comments whose covered non-carrier content is removed by a resolution. */
|
|
101
|
-
export declare const resolvedCommentPoints: ({ doc, removes, retiresStructure }: ResolvedCommentPointsOptions) => Map<number, number>;
|
|
102
97
|
export type ReplacedAnnotations = {
|
|
103
98
|
/** Marks the replacement must carry, in document order. */
|
|
104
99
|
carried: readonly Mark[];
|
|
@@ -120,78 +115,6 @@ export declare const surveyReplacedAnnotations: (doc: Node, from: number, to: nu
|
|
|
120
115
|
* carries too.
|
|
121
116
|
*/
|
|
122
117
|
export declare const surveyAcceptedReplacedAnnotations: (doc: Node, from: number, to: number) => ReplacedAnnotations;
|
|
123
|
-
/**
|
|
124
|
-
* How a replacement removes the words it changes, which decides what becomes
|
|
125
|
-
* of a comment on them.
|
|
126
|
-
*/
|
|
127
|
-
export type ReplacementRemoval = {
|
|
128
|
-
/**
|
|
129
|
-
* Removed outright: a thread whose root keeps no accepted word outside
|
|
130
|
-
* the changes goes with its words, markers and replies, as the direct
|
|
131
|
-
* edit retires every thread it exhausts, so its markers need no
|
|
132
|
-
* alignment.
|
|
133
|
-
*/
|
|
134
|
-
type: "direct";
|
|
135
|
-
comments: readonly document_d_exports.Comment[];
|
|
136
|
-
} | {
|
|
137
|
-
/**
|
|
138
|
-
* Tracked: the deleted words keep their comment ranges, so rejecting
|
|
139
|
-
* gives every range back and accepting drops a comment whose words all
|
|
140
|
-
* went. Only a point comment or a selected marker still needs the
|
|
141
|
-
* comment to move.
|
|
142
|
-
*/
|
|
143
|
-
type: "tracked";
|
|
144
|
-
} | {
|
|
145
|
-
/**
|
|
146
|
-
* Recorded as a suggestion: its changes neither keep a comment on the
|
|
147
|
-
* words they remove nor retire one, so every comment they reach must
|
|
148
|
-
* already align.
|
|
149
|
-
*/
|
|
150
|
-
type: "suggested";
|
|
151
|
-
};
|
|
152
|
-
type ReplacementChange = {
|
|
153
|
-
from: number;
|
|
154
|
-
to: number;
|
|
155
|
-
text: string;
|
|
156
|
-
markers: "retained" | "selected";
|
|
157
|
-
};
|
|
158
|
-
type ReplacementCommentAlignmentOptions = {
|
|
159
|
-
doc: Node;
|
|
160
|
-
source: {
|
|
161
|
-
from: number;
|
|
162
|
-
to: number;
|
|
163
|
-
};
|
|
164
|
-
retiredCommentIds?: ReadonlySet<number> | undefined;
|
|
165
|
-
removal: ReplacementRemoval;
|
|
166
|
-
changes: readonly ReplacementChange[];
|
|
167
|
-
};
|
|
168
|
-
type DirectReplacementSplit<Change extends ReplacementChange> = {
|
|
169
|
-
changes: Change[];
|
|
170
|
-
/** Threads the unsplit replacement takes whole. */
|
|
171
|
-
retiredCommentIds: ReadonlySet<number>;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* A direct replacement's changes cut at each boundary of a comment it keeps
|
|
175
|
-
* that stands inside a changed stretch: the words before the boundary go, and
|
|
176
|
-
* the new words follow every such boundary, where accepting the tracked
|
|
177
|
-
* replacement leaves them. A range ending in the stretch ends before the new
|
|
178
|
-
* words; one starting in it holds them.
|
|
179
|
-
*/
|
|
180
|
-
export declare const splitAtKeptCommentBoundaries: <Change extends ReplacementChange>({ doc, changes, comments }: {
|
|
181
|
-
doc: Node;
|
|
182
|
-
changes: readonly Change[];
|
|
183
|
-
comments: readonly document_d_exports.Comment[];
|
|
184
|
-
}) => DirectReplacementSplit<Change>;
|
|
185
|
-
/**
|
|
186
|
-
* Whether source boundaries already express the replacement's aligned ranges.
|
|
187
|
-
* A changed stretch lends no comment to its replacement: the new words go
|
|
188
|
-
* past the end of every range the stretch reaches, and a direct replacement
|
|
189
|
-
* takes every thread it leaves nothing to cover. Pure deletions within
|
|
190
|
-
* surviving source content follow the ranged-comment exhaustion owner; other
|
|
191
|
-
* collapses need a point policy. Decide over the whole replacement, before
|
|
192
|
-
* any of its fragments are applied.
|
|
193
|
-
*/
|
|
194
|
-
export declare const preservesReplacementCommentAlignment: ({ doc, source, changes, retiredCommentIds, removal }: ReplacementCommentAlignmentOptions) => boolean;
|
|
195
118
|
type AnnotatedReplacementOptions = {
|
|
196
119
|
annotations: ReplacedAnnotations;
|
|
197
120
|
/** The replacement's own inline content, already carrying its formatting. */
|