@stll/folio-core 0.74.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 +18 -9
- 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 +6 -2
- 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/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/canonicalPublicOperations.js +29 -9
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +116 -121
- 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/canonicalClipboard.js +43 -42
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- 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 +139 -42
- 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 +2 -0
- package/dist/controller/hiddenEditorManager.js +132 -189
- 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/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/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +35 -9
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/server/templatePlan/apply.js +38 -3
- 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 +19 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +104 -22
- package/dist/docx/server/templatePlan/plan.d.ts +13 -1
- package/dist/docx/server/templatePlan/plan.js +22 -7
- package/dist/docx/server/templatePlan/planShape.js +31 -2
- 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 +138 -16
- package/dist/docx/server/templatePlan/verify.js +50 -9
- 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/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +40 -45
- package/dist/types/canonicalCapabilities.js +51 -43
- 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
|
@@ -100,9 +100,9 @@ const checkCanonicalTrackedBatchFidelity = ({ createdCommentIds, retiredCommentI
|
|
|
100
100
|
if (verdict !== void 0) return verdict;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const rejected = review.reject();
|
|
104
|
+
if (rejected === null) return "Reject All could not resolve the tracked result.";
|
|
105
|
+
const { original: rejectedBefore, edited: rejectedAfter } = rejected;
|
|
106
106
|
if (rejectedBefore !== rejectedAfter && !sameOriginalBlocks(rejectedBefore, rejectedAfter, createdCommentIds)) return "Reject All would change the original content or formatting.";
|
|
107
107
|
const accepted = review.accept();
|
|
108
108
|
if (accepted === null) return "Accept All could not resolve the tracked result.";
|
|
@@ -1,49 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NoteReferenceLabels } from "../ai-edits/note-references.js";
|
|
3
|
-
import {
|
|
4
|
-
import { MISSING_NOTE_DETAIL } from "./inline-atom-alignment.js";
|
|
5
|
-
import { EditorState, Transaction } from "prosemirror-state";
|
|
1
|
+
import { BuildCleanBlockTextOptions } from "../ai-edits/clean-text.js";
|
|
2
|
+
import { NoteReferenceIdentity, NoteReferenceLabels } from "../ai-edits/note-references.js";
|
|
3
|
+
import { AlignableAtom, MISSING_NOTE_DETAIL } from "./inline-atom-alignment.js";
|
|
6
4
|
import { Node } from "prosemirror-model";
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
revisionStamp: FolioRevisionStamp;
|
|
11
|
-
/** First id reserved for this comparison, before planned operations allocated ids. */
|
|
12
|
-
originalRevisionIdSeed: number;
|
|
13
|
-
author: string;
|
|
14
|
-
maxRanges: number;
|
|
15
|
-
/**
|
|
16
|
-
* The markers the comparison's operations wrote note references as.
|
|
17
|
-
* Defaults to the target story's own numbering.
|
|
18
|
-
*/
|
|
19
|
-
noteReferenceLabels?: NoteReferenceLabels;
|
|
20
|
-
/**
|
|
21
|
-
* The notes the base package defines, as `footnote:<id>` / `endnote:<id>`.
|
|
22
|
-
* A reference the comparison writes may only name one of them. Defaults to
|
|
23
|
-
* the notes the story already references.
|
|
24
|
-
*/
|
|
25
|
-
baseNotes?: ReadonlySet<string>;
|
|
5
|
+
export type TextBlock = {
|
|
6
|
+
node: Node;
|
|
7
|
+
from: number;
|
|
26
8
|
};
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
9
|
+
export type InlineAtom = AlignableAtom & {
|
|
10
|
+
node: Node;
|
|
11
|
+
from: number;
|
|
12
|
+
};
|
|
13
|
+
/** A footnote or endnote reference read as its marker, over `length` clean-text characters. */
|
|
14
|
+
type NoteReferenceAt = NoteReferenceIdentity & {
|
|
15
|
+
offset: number;
|
|
16
|
+
length: number;
|
|
17
|
+
from: number;
|
|
18
|
+
};
|
|
19
|
+
export type AtomBlock = TextBlock & {
|
|
20
|
+
blockType: string;
|
|
21
|
+
cleanText: string;
|
|
22
|
+
offsets: readonly number[];
|
|
23
|
+
supported: readonly InlineAtom[];
|
|
24
|
+
unsupportedTopology: readonly {
|
|
25
|
+
offset: number;
|
|
26
|
+
key: string;
|
|
27
|
+
}[];
|
|
28
|
+
/** Empty unless the block was read with note reference labels. */
|
|
29
|
+
noteReferences: readonly NoteReferenceAt[];
|
|
39
30
|
};
|
|
40
31
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* paragraph correspondence: paragraph-mark deletions can merge paragraphs.
|
|
32
|
+
* How a block's note references read. `"sourceText"` is the editor's own text
|
|
33
|
+
* for a reference (its package id); labels read it as the marker (`[^1]`) the
|
|
34
|
+
* comparison planned in, which is the text its operations write for one.
|
|
45
35
|
*/
|
|
46
|
-
export
|
|
36
|
+
export type NoteReferenceReading = NoteReferenceLabels | "sourceText";
|
|
37
|
+
export declare const isSupportedAtom: (node: Node) => boolean;
|
|
38
|
+
export declare const hasSupportedAtom: (doc: Node) => boolean;
|
|
39
|
+
export declare const textBlocksOf: (doc: Node) => TextBlock[];
|
|
40
|
+
export declare const atomBlocksOf: (doc: Node, fieldResults: BuildCleanBlockTextOptions["fieldResults"], noteReferences?: NoteReferenceReading) => AtomBlock[];
|
|
47
41
|
/** Compare supported inline atom identity after accept or reject projection. */
|
|
48
42
|
export declare const sameInlineAtoms: (leftDocument: Node, rightDocument: Node) => boolean;
|
|
49
43
|
export { MISSING_NOTE_DETAIL };
|
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import { buildCleanBlockText } from "../ai-edits/clean-text.js";
|
|
2
|
-
import { noteReferenceOf } from "../ai-edits/note-references.js";
|
|
3
|
-
import { collectNoteReferenceLabels, sourceDocumentOf } from "../ai-edits/snapshot.js";
|
|
4
2
|
import { drawingXmlWithoutIdentity } from "../docx/drawingIdNormalization.js";
|
|
5
|
-
import { addTrackedDeletionMark } from "../prosemirror/addTrackedDeletionMark.js";
|
|
6
|
-
import { resolveAllChangesInHeadlessStateWithMapping } from "../prosemirror/commands/comments.js";
|
|
7
|
-
import { mintNoteReferenceOccurrenceId } from "../prosemirror/noteReferenceOccurrences.js";
|
|
8
3
|
import { runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
|
|
9
4
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
10
|
-
import { MISSING_NOTE_DETAIL,
|
|
5
|
+
import { MISSING_NOTE_DETAIL, sameSupportedAtoms } from "./inline-atom-alignment.js";
|
|
11
6
|
import { prepareTargetInlineAtom } from "./inline-atom-resources.js";
|
|
12
7
|
// src/compare/inline-atoms.ts
|
|
13
|
-
const actionRangeCount = (action) => {
|
|
14
|
-
switch (action.kind) {
|
|
15
|
-
case "replace-text": return atomActionRangeCount(action.textDisposition);
|
|
16
|
-
case "replace-atom": return atomActionRangeCount(action.atomDisposition);
|
|
17
|
-
case "insert":
|
|
18
|
-
case "delete":
|
|
19
|
-
case "note-reference": return atomActionRangeCount(null);
|
|
20
|
-
default: return action;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
8
|
const isSupportedAtom = (node) => node.isInline && node.isAtom && (node.type.name === "field" || node.type.name === "image" || node.type.name === "pageBreakRun");
|
|
24
9
|
const hasSupportedAtom = (doc) => {
|
|
25
10
|
let found = false;
|
|
@@ -154,455 +139,7 @@ const atomBlockOf = ({ node, from }, fieldResults, noteReferences) => {
|
|
|
154
139
|
noteReferences: references
|
|
155
140
|
};
|
|
156
141
|
};
|
|
157
|
-
const targetBlockIdLookup = (snapshot) => {
|
|
158
|
-
const anchors = Object.values(snapshot.anchors).toSorted((left, right) => left.from - right.from || right.to - left.to);
|
|
159
|
-
return (position) => {
|
|
160
|
-
let low = 0;
|
|
161
|
-
let high = anchors.length;
|
|
162
|
-
while (low < high) {
|
|
163
|
-
const middle = Math.floor((low + high) / 2);
|
|
164
|
-
if ((anchors[middle]?.from ?? Number.POSITIVE_INFINITY) <= position) low = middle + 1;
|
|
165
|
-
else high = middle;
|
|
166
|
-
}
|
|
167
|
-
let owner;
|
|
168
|
-
for (let index = low - 1; index >= 0; index--) {
|
|
169
|
-
const anchor = anchors[index];
|
|
170
|
-
if (!anchor || anchor.to <= position) continue;
|
|
171
|
-
if (!owner || anchor.to - anchor.from < owner.to - owner.from) owner = anchor;
|
|
172
|
-
}
|
|
173
|
-
return owner?.id;
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
142
|
const atomBlocksOf = (doc, fieldResults, noteReferences = "sourceText") => textBlocksOf(doc).map((block) => atomBlockOf(block, fieldResults, noteReferences));
|
|
177
|
-
const noteReferenceKey = ({ noteType, noteId }) => `${noteType}:${noteId}`;
|
|
178
|
-
/** Every note a story references, tracked-deleted references included. */
|
|
179
|
-
const referencedNotesOf = (doc) => {
|
|
180
|
-
const notes = /* @__PURE__ */ new Set();
|
|
181
|
-
doc.descendants((node) => {
|
|
182
|
-
const reference = noteReferenceOf(node);
|
|
183
|
-
if (reference) notes.add(noteReferenceKey(reference));
|
|
184
|
-
return !node.isText;
|
|
185
|
-
});
|
|
186
|
-
return notes;
|
|
187
|
-
};
|
|
188
|
-
const hasNoteReference = (doc) => {
|
|
189
|
-
let found = false;
|
|
190
|
-
doc.descendants((node) => {
|
|
191
|
-
if (found) return false;
|
|
192
|
-
if (noteReferenceOf(node)) found = true;
|
|
193
|
-
return !node.isText;
|
|
194
|
-
});
|
|
195
|
-
return found;
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* Whether this comparison inserted text that may stand for a note reference.
|
|
199
|
-
* Operations carry clean text, where a reference reads as its marker, so an
|
|
200
|
-
* operation that brings a reference writes the marker as text.
|
|
201
|
-
*/
|
|
202
|
-
const wroteNoteReferenceMarker = (doc, originalRevisionIdSeed) => {
|
|
203
|
-
let found = false;
|
|
204
|
-
doc.descendants((node) => {
|
|
205
|
-
if (found) return false;
|
|
206
|
-
if (!node.isText) return true;
|
|
207
|
-
if (!node.text?.includes("[^") || noteReferenceOf(node)) return false;
|
|
208
|
-
const revisionId = node.marks.find(({ type }) => type.name === "insertion")?.attrs["revisionId"];
|
|
209
|
-
if (typeof revisionId === "number" && revisionId >= originalRevisionIdSeed) found = true;
|
|
210
|
-
return false;
|
|
211
|
-
});
|
|
212
|
-
return found;
|
|
213
|
-
};
|
|
214
|
-
const mappedSourcePosition = ({ mapping, position }) => {
|
|
215
|
-
const inverse = mapping.invert();
|
|
216
|
-
const right = inverse.mapResult(position, 1);
|
|
217
|
-
if (!right.deleted) return right.pos;
|
|
218
|
-
const left = inverse.mapResult(position, -1);
|
|
219
|
-
return left.deleted ? null : left.pos;
|
|
220
|
-
};
|
|
221
|
-
const sourceTextBlockIds = (source) => {
|
|
222
|
-
const blocks = /* @__PURE__ */ new Map();
|
|
223
|
-
for (const block of textBlocksOf(source)) {
|
|
224
|
-
const paraId = block.node.attrs["paraId"];
|
|
225
|
-
if (typeof paraId !== "string" || paraId.length === 0) continue;
|
|
226
|
-
blocks.set(paraId, blocks.has(paraId) ? null : block);
|
|
227
|
-
}
|
|
228
|
-
return blocks;
|
|
229
|
-
};
|
|
230
|
-
const sameParagraphSourcePosition = ({ sourceBlocks, reviewed, offset, fieldResults, noteReferences }) => {
|
|
231
|
-
const paraId = reviewed.node.attrs["paraId"];
|
|
232
|
-
if (typeof paraId !== "string" || paraId.length === 0) return null;
|
|
233
|
-
const source = sourceBlocks.get(paraId);
|
|
234
|
-
if (!source || source.node.type !== reviewed.node.type) return null;
|
|
235
|
-
const clean = buildCleanBlockText(source.node, source.from, {
|
|
236
|
-
fieldResults,
|
|
237
|
-
noteReferences
|
|
238
|
-
});
|
|
239
|
-
return clean.text === reviewed.cleanText ? clean.offsets[offset] ?? null : null;
|
|
240
|
-
};
|
|
241
|
-
const textRangeDisposition = ({ doc, from, to, expectedText, originalRevisionIdSeed }) => {
|
|
242
|
-
if (from >= to || doc.textBetween(from, to) !== expectedText) return null;
|
|
243
|
-
let disposition;
|
|
244
|
-
let covered = 0;
|
|
245
|
-
let invalid = false;
|
|
246
|
-
doc.nodesBetween(from, to, (node, position) => {
|
|
247
|
-
if (!node.isText) {
|
|
248
|
-
if (position > from && position < to) invalid = true;
|
|
249
|
-
return !invalid;
|
|
250
|
-
}
|
|
251
|
-
const overlapFrom = Math.max(from, position);
|
|
252
|
-
const overlapTo = Math.min(to, position + node.nodeSize);
|
|
253
|
-
if (overlapFrom >= overlapTo) return false;
|
|
254
|
-
covered += overlapTo - overlapFrom;
|
|
255
|
-
if (node.marks.some(({ type }) => type.name === "deletion")) {
|
|
256
|
-
invalid = true;
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
const insertion = node.marks.find(({ type }) => type.name === "insertion");
|
|
260
|
-
let current = "retained";
|
|
261
|
-
if (insertion) {
|
|
262
|
-
const revisionId = insertion.attrs["revisionId"];
|
|
263
|
-
if (typeof revisionId !== "number" || revisionId < originalRevisionIdSeed) {
|
|
264
|
-
invalid = true;
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
current = "inserted";
|
|
268
|
-
}
|
|
269
|
-
if (disposition !== void 0 && disposition !== current) {
|
|
270
|
-
invalid = true;
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
disposition = current;
|
|
274
|
-
return false;
|
|
275
|
-
});
|
|
276
|
-
return !invalid && covered === to - from ? disposition ?? null : null;
|
|
277
|
-
};
|
|
278
|
-
const atomDisposition = ({ atom, originalRevisionIdSeed }) => {
|
|
279
|
-
if (atom.node.marks.some(({ type }) => type.name === "deletion")) return null;
|
|
280
|
-
const insertion = atom.node.marks.find(({ type }) => type.name === "insertion");
|
|
281
|
-
if (!insertion) return "retained";
|
|
282
|
-
const revisionId = insertion.attrs["revisionId"];
|
|
283
|
-
return typeof revisionId === "number" && revisionId >= originalRevisionIdSeed ? "inserted" : null;
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* Restore field, image, and page-break atoms omitted by text-only comparison
|
|
287
|
-
* operations, and the note references whose markers they wrote as text.
|
|
288
|
-
* Positions come from the legacy review resolver's mapping, never a guessed
|
|
289
|
-
* paragraph correspondence: paragraph-mark deletions can merge paragraphs.
|
|
290
|
-
*/
|
|
291
|
-
const matchInlineAtoms = ({ state, targetSnapshot, revisionStamp, originalRevisionIdSeed, author, maxRanges, noteReferenceLabels, baseNotes }) => {
|
|
292
|
-
if (!Number.isSafeInteger(maxRanges) || maxRanges < 0) return { status: "budget-exceeded" };
|
|
293
|
-
const targetDocument = sourceDocumentOf(targetSnapshot);
|
|
294
|
-
const restoresNoteReferences = wroteNoteReferenceMarker(state.doc, originalRevisionIdSeed) && hasNoteReference(targetDocument);
|
|
295
|
-
const noteReferences = restoresNoteReferences ? noteReferenceLabels ?? collectNoteReferenceLabels(targetDocument) : "sourceText";
|
|
296
|
-
if (!restoresNoteReferences && !hasSupportedAtom(state.doc) && !hasSupportedAtom(targetDocument)) return {
|
|
297
|
-
status: "matched",
|
|
298
|
-
transaction: state.tr,
|
|
299
|
-
nextRevisionId: revisionStamp.idSeed,
|
|
300
|
-
changedTargetBlockIds: [],
|
|
301
|
-
rangeCount: 0
|
|
302
|
-
};
|
|
303
|
-
const reviewed = resolveAllChangesInHeadlessStateWithMapping(state, "accept");
|
|
304
|
-
const targetBlockIdAt = targetBlockIdLookup(targetSnapshot);
|
|
305
|
-
let sourceBlocks;
|
|
306
|
-
const liveBlocks = atomBlocksOf(reviewed.state.doc, "text", noteReferences);
|
|
307
|
-
const targetBlocks = atomBlocksOf(targetDocument, "text", noteReferences);
|
|
308
|
-
if (liveBlocks.length !== targetBlocks.length) return { status: "unalignable" };
|
|
309
|
-
const actions = [];
|
|
310
|
-
let rangeCount = 0;
|
|
311
|
-
const planAction = (action) => {
|
|
312
|
-
const nextRangeCount = rangeCount + actionRangeCount(action);
|
|
313
|
-
if (nextRangeCount > maxRanges) return false;
|
|
314
|
-
rangeCount = nextRangeCount;
|
|
315
|
-
actions.push(action);
|
|
316
|
-
return true;
|
|
317
|
-
};
|
|
318
|
-
let referencedNotes;
|
|
319
|
-
let omittedLiveBlocks;
|
|
320
|
-
let omittedTargetBlocks;
|
|
321
|
-
for (const [index, fullLive] of liveBlocks.entries()) {
|
|
322
|
-
const fullTarget = targetBlocks[index];
|
|
323
|
-
if (!fullTarget) return { status: "unalignable" };
|
|
324
|
-
if ((fullLive.noteReferences.length > 0 || fullTarget.noteReferences.length > 0) && fullLive.cleanText === fullTarget.cleanText) {
|
|
325
|
-
const kept = new Map(fullLive.noteReferences.map((reference) => [reference.offset, reference]));
|
|
326
|
-
for (const reference of fullTarget.noteReferences) {
|
|
327
|
-
const live = kept.get(reference.offset);
|
|
328
|
-
if (live) {
|
|
329
|
-
kept.delete(reference.offset);
|
|
330
|
-
if (noteReferenceKey(live) !== noteReferenceKey(reference) || live.length !== reference.length) return { status: "unalignable" };
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
referencedNotes ??= baseNotes ?? referencedNotesOf(state.doc);
|
|
334
|
-
if (!referencedNotes.has(noteReferenceKey(reference))) return {
|
|
335
|
-
status: "unalignable",
|
|
336
|
-
detail: MISSING_NOTE_DETAIL
|
|
337
|
-
};
|
|
338
|
-
const node = targetDocument.nodeAt(reference.from);
|
|
339
|
-
const reviewedFrom = fullLive.offsets[reference.offset];
|
|
340
|
-
const reviewedLast = fullLive.offsets[reference.offset + reference.length - 1];
|
|
341
|
-
if (!node || !noteReferenceOf(node) || reviewedFrom === void 0 || reviewedLast === void 0) return { status: "unalignable" };
|
|
342
|
-
const from = mappedSourcePosition({
|
|
343
|
-
mapping: reviewed.mapping,
|
|
344
|
-
position: reviewedFrom
|
|
345
|
-
});
|
|
346
|
-
const to = mappedSourcePosition({
|
|
347
|
-
mapping: reviewed.mapping,
|
|
348
|
-
position: reviewedLast + 1
|
|
349
|
-
});
|
|
350
|
-
if (from === null || to === null || textRangeDisposition({
|
|
351
|
-
doc: state.doc,
|
|
352
|
-
from,
|
|
353
|
-
to,
|
|
354
|
-
expectedText: fullTarget.cleanText.slice(reference.offset, reference.offset + reference.length),
|
|
355
|
-
originalRevisionIdSeed
|
|
356
|
-
}) !== "inserted") return { status: "unalignable" };
|
|
357
|
-
if (!planAction({
|
|
358
|
-
kind: "note-reference",
|
|
359
|
-
from,
|
|
360
|
-
to,
|
|
361
|
-
node,
|
|
362
|
-
targetBlockId: targetBlockIdAt(fullTarget.from)
|
|
363
|
-
})) return { status: "budget-exceeded" };
|
|
364
|
-
}
|
|
365
|
-
if (kept.size > 0) return { status: "unalignable" };
|
|
366
|
-
}
|
|
367
|
-
if (fullLive.supported.length === 0 && fullTarget.supported.length === 0) continue;
|
|
368
|
-
if (sameSupportedAtoms(fullLive, fullTarget)) continue;
|
|
369
|
-
let live = fullLive;
|
|
370
|
-
let target = fullTarget;
|
|
371
|
-
let fieldResults = "text";
|
|
372
|
-
if (!sameBlockTopology(live, target)) {
|
|
373
|
-
omittedLiveBlocks ??= atomBlocksOf(reviewed.state.doc, "omitted", noteReferences);
|
|
374
|
-
omittedTargetBlocks ??= atomBlocksOf(targetDocument, "omitted", noteReferences);
|
|
375
|
-
const omittedLive = omittedLiveBlocks[index];
|
|
376
|
-
const omittedTarget = omittedTargetBlocks[index];
|
|
377
|
-
if (!omittedLive || !omittedTarget || !sameBlockTopology(omittedLive, omittedTarget)) return { status: "unalignable" };
|
|
378
|
-
live = omittedLive;
|
|
379
|
-
target = omittedTarget;
|
|
380
|
-
fieldResults = "omitted";
|
|
381
|
-
}
|
|
382
|
-
const matches = matchingAtoms({
|
|
383
|
-
live: live.supported,
|
|
384
|
-
target: target.supported
|
|
385
|
-
});
|
|
386
|
-
const matchedLive = new Set(matches.map(([liveIndex]) => liveIndex));
|
|
387
|
-
const matchedTarget = new Set(matches.map(([, targetIndex]) => targetIndex));
|
|
388
|
-
const anchors = insertionAnchors({
|
|
389
|
-
live: live.supported,
|
|
390
|
-
target: target.supported,
|
|
391
|
-
matches
|
|
392
|
-
});
|
|
393
|
-
const liveFieldResultOwnership = fieldResultOwnershipOf(live.supported);
|
|
394
|
-
const targetFieldResultOwnership = fieldResultOwnershipOf(target.supported);
|
|
395
|
-
for (const [liveIndex, atom] of live.supported.entries()) {
|
|
396
|
-
if (matchedLive.has(liveIndex)) continue;
|
|
397
|
-
const from = mappedSourcePosition({
|
|
398
|
-
mapping: reviewed.mapping,
|
|
399
|
-
position: atom.from
|
|
400
|
-
});
|
|
401
|
-
if (from === null) return { status: "unalignable" };
|
|
402
|
-
const { resultText } = atom;
|
|
403
|
-
if (fieldResults === "text" && resultText && !ownsFieldResult({
|
|
404
|
-
ownership: targetFieldResultOwnership,
|
|
405
|
-
offset: atom.offset,
|
|
406
|
-
resultText
|
|
407
|
-
})) {
|
|
408
|
-
const disposition = atomDisposition({
|
|
409
|
-
atom,
|
|
410
|
-
originalRevisionIdSeed
|
|
411
|
-
});
|
|
412
|
-
if (disposition === null) return { status: "unalignable" };
|
|
413
|
-
if (!planAction({
|
|
414
|
-
kind: "replace-atom",
|
|
415
|
-
from,
|
|
416
|
-
to: from + atom.node.nodeSize,
|
|
417
|
-
text: resultText,
|
|
418
|
-
atomDisposition: disposition,
|
|
419
|
-
marks: atom.node.marks,
|
|
420
|
-
targetBlockId: targetBlockIdAt(target.from)
|
|
421
|
-
})) return { status: "budget-exceeded" };
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
if (!planAction({
|
|
425
|
-
kind: "delete",
|
|
426
|
-
from,
|
|
427
|
-
to: from + atom.node.nodeSize,
|
|
428
|
-
targetBlockId: targetBlockIdAt(target.from)
|
|
429
|
-
})) return { status: "budget-exceeded" };
|
|
430
|
-
}
|
|
431
|
-
for (const [targetIndex, atom] of target.supported.entries()) {
|
|
432
|
-
if (matchedTarget.has(targetIndex)) continue;
|
|
433
|
-
const anchor = anchors.get(targetIndex);
|
|
434
|
-
const anchorAtom = anchor === void 0 ? void 0 : live.supported[anchor.liveIndex];
|
|
435
|
-
let position;
|
|
436
|
-
if (anchor === void 0 || anchorAtom === void 0) position = live.offsets[atom.offset];
|
|
437
|
-
else position = anchor.side === "before" ? anchorAtom.from : anchorAtom.from + anchorAtom.node.nodeSize;
|
|
438
|
-
if (position === void 0) return { status: "unalignable" };
|
|
439
|
-
const from = mappedSourcePosition({
|
|
440
|
-
mapping: reviewed.mapping,
|
|
441
|
-
position
|
|
442
|
-
}) ?? sameParagraphSourcePosition({
|
|
443
|
-
sourceBlocks: sourceBlocks ??= sourceTextBlockIds(state.doc),
|
|
444
|
-
reviewed: live,
|
|
445
|
-
offset: atom.offset,
|
|
446
|
-
fieldResults,
|
|
447
|
-
noteReferences
|
|
448
|
-
});
|
|
449
|
-
if (from === null) return { status: "unalignable" };
|
|
450
|
-
const { resultText } = atom;
|
|
451
|
-
if (fieldResults === "text" && resultText && !ownsFieldResult({
|
|
452
|
-
ownership: liveFieldResultOwnership,
|
|
453
|
-
offset: atom.offset,
|
|
454
|
-
resultText
|
|
455
|
-
})) {
|
|
456
|
-
const reviewedLast = live.offsets[atom.offset + resultText.length - 1];
|
|
457
|
-
const to = reviewedLast === void 0 ? null : mappedSourcePosition({
|
|
458
|
-
mapping: reviewed.mapping,
|
|
459
|
-
position: reviewedLast + 1
|
|
460
|
-
});
|
|
461
|
-
if (to === null) return { status: "unalignable" };
|
|
462
|
-
const textDisposition = textRangeDisposition({
|
|
463
|
-
doc: state.doc,
|
|
464
|
-
from,
|
|
465
|
-
to,
|
|
466
|
-
expectedText: resultText,
|
|
467
|
-
originalRevisionIdSeed
|
|
468
|
-
});
|
|
469
|
-
if (textDisposition === null) return { status: "unalignable" };
|
|
470
|
-
if (!planAction({
|
|
471
|
-
kind: "replace-text",
|
|
472
|
-
from,
|
|
473
|
-
to,
|
|
474
|
-
node: atom.node,
|
|
475
|
-
textDisposition,
|
|
476
|
-
targetBlockId: targetBlockIdAt(target.from)
|
|
477
|
-
})) return { status: "budget-exceeded" };
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
if (!planAction({
|
|
481
|
-
kind: "insert",
|
|
482
|
-
from,
|
|
483
|
-
node: atom.node,
|
|
484
|
-
targetBlockId: targetBlockIdAt(target.from)
|
|
485
|
-
})) return { status: "budget-exceeded" };
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
const insertionType = state.schema.marks["insertion"];
|
|
489
|
-
const deletionType = state.schema.marks["deletion"];
|
|
490
|
-
if (!insertionType || !deletionType) return { status: "unalignable" };
|
|
491
|
-
const transaction = state.tr;
|
|
492
|
-
let nextRevisionId = revisionStamp.idSeed;
|
|
493
|
-
const changedTargetBlockIds = /* @__PURE__ */ new Set();
|
|
494
|
-
const ordered = actions.toSorted((left, right) => right.from - left.from || atomActionTieRank(left.kind) - atomActionTieRank(right.kind));
|
|
495
|
-
for (const action of ordered) {
|
|
496
|
-
if (action.kind === "insert") {
|
|
497
|
-
const at = transaction.mapping.map(action.from, 1);
|
|
498
|
-
const marked = action.node.mark(insertionType.create({
|
|
499
|
-
revisionId: nextRevisionId++,
|
|
500
|
-
author,
|
|
501
|
-
date: revisionStamp.date
|
|
502
|
-
}).addToSet(action.node.marks));
|
|
503
|
-
transaction.insert(at, marked);
|
|
504
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
if (action.kind === "replace-text") {
|
|
508
|
-
const from = transaction.mapping.map(action.from, 1);
|
|
509
|
-
const to = transaction.mapping.map(action.to, -1);
|
|
510
|
-
if (from >= to) return { status: "unalignable" };
|
|
511
|
-
if (action.textDisposition === "inserted") transaction.delete(from, to);
|
|
512
|
-
else addTrackedDeletionMark({
|
|
513
|
-
insertionPolicy: "preserve-pending",
|
|
514
|
-
tr: transaction,
|
|
515
|
-
from,
|
|
516
|
-
to,
|
|
517
|
-
mark: deletionType.create({
|
|
518
|
-
revisionId: nextRevisionId++,
|
|
519
|
-
author,
|
|
520
|
-
date: revisionStamp.date
|
|
521
|
-
})
|
|
522
|
-
});
|
|
523
|
-
const at = transaction.mapping.map(action.from, 1);
|
|
524
|
-
transaction.insert(at, action.node.mark(insertionType.create({
|
|
525
|
-
revisionId: nextRevisionId++,
|
|
526
|
-
author,
|
|
527
|
-
date: revisionStamp.date
|
|
528
|
-
}).addToSet(action.node.marks)));
|
|
529
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
if (action.kind === "note-reference") {
|
|
533
|
-
const from = transaction.mapping.map(action.from, 1);
|
|
534
|
-
const to = transaction.mapping.map(action.to, -1);
|
|
535
|
-
const written = transaction.doc.nodeAt(from);
|
|
536
|
-
const noteMark = action.node.marks.find(({ type }) => type.name === "footnoteRef");
|
|
537
|
-
if (from >= to || !written?.isText || !noteMark) return { status: "unalignable" };
|
|
538
|
-
const restoredNoteMark = noteMark.type.create({
|
|
539
|
-
...noteMark.attrs,
|
|
540
|
-
occurrenceId: mintNoteReferenceOccurrenceId()
|
|
541
|
-
});
|
|
542
|
-
transaction.replaceWith(from, to, state.schema.text(action.node.text ?? "", restoredNoteMark.addToSet(written.marks)));
|
|
543
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
544
|
-
continue;
|
|
545
|
-
}
|
|
546
|
-
if (action.kind === "replace-atom") {
|
|
547
|
-
const from = transaction.mapping.map(action.from, 1);
|
|
548
|
-
const to = transaction.mapping.map(action.to, -1);
|
|
549
|
-
const node = transaction.doc.nodeAt(from);
|
|
550
|
-
if (!node || node.nodeSize !== to - from || node.type.name !== "field") return { status: "unalignable" };
|
|
551
|
-
if (action.atomDisposition === "inserted") transaction.delete(from, to);
|
|
552
|
-
else addTrackedDeletionMark({
|
|
553
|
-
insertionPolicy: "preserve-pending",
|
|
554
|
-
tr: transaction,
|
|
555
|
-
from,
|
|
556
|
-
to,
|
|
557
|
-
mark: deletionType.create({
|
|
558
|
-
revisionId: nextRevisionId++,
|
|
559
|
-
author,
|
|
560
|
-
date: revisionStamp.date
|
|
561
|
-
})
|
|
562
|
-
});
|
|
563
|
-
const at = transaction.mapping.map(action.from, 1);
|
|
564
|
-
transaction.insert(at, state.schema.text(action.text, insertionType.create({
|
|
565
|
-
revisionId: nextRevisionId++,
|
|
566
|
-
author,
|
|
567
|
-
date: revisionStamp.date
|
|
568
|
-
}).addToSet(action.marks)));
|
|
569
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
const from = transaction.mapping.map(action.from, 1);
|
|
573
|
-
const to = transaction.mapping.map(action.to, -1);
|
|
574
|
-
const node = transaction.doc.nodeAt(from);
|
|
575
|
-
if (!node || node.nodeSize !== to - from || !isSupportedAtom(node)) return { status: "unalignable" };
|
|
576
|
-
const insertion = node.marks.find(({ type }) => type === insertionType);
|
|
577
|
-
if (insertion) {
|
|
578
|
-
const revisionId = insertion.attrs["revisionId"];
|
|
579
|
-
if (typeof revisionId !== "number" || revisionId < originalRevisionIdSeed) return { status: "unalignable" };
|
|
580
|
-
transaction.delete(from, to);
|
|
581
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
582
|
-
continue;
|
|
583
|
-
}
|
|
584
|
-
if (node.marks.some(({ type }) => type === deletionType)) return { status: "unalignable" };
|
|
585
|
-
addTrackedDeletionMark({
|
|
586
|
-
insertionPolicy: "preserve-pending",
|
|
587
|
-
tr: transaction,
|
|
588
|
-
from,
|
|
589
|
-
to,
|
|
590
|
-
mark: deletionType.create({
|
|
591
|
-
revisionId: nextRevisionId++,
|
|
592
|
-
author,
|
|
593
|
-
date: revisionStamp.date
|
|
594
|
-
})
|
|
595
|
-
});
|
|
596
|
-
if (action.targetBlockId) changedTargetBlockIds.add(action.targetBlockId);
|
|
597
|
-
}
|
|
598
|
-
return {
|
|
599
|
-
status: "matched",
|
|
600
|
-
transaction,
|
|
601
|
-
nextRevisionId,
|
|
602
|
-
changedTargetBlockIds: [...changedTargetBlockIds],
|
|
603
|
-
rangeCount
|
|
604
|
-
};
|
|
605
|
-
};
|
|
606
143
|
/** Compare supported inline atom identity after accept or reject projection. */
|
|
607
144
|
const sameInlineAtoms = (leftDocument, rightDocument) => {
|
|
608
145
|
if (!hasSupportedAtom(leftDocument) && !hasSupportedAtom(rightDocument)) return true;
|
|
@@ -615,4 +152,4 @@ const sameInlineAtoms = (leftDocument, rightDocument) => {
|
|
|
615
152
|
return right !== void 0 && left.cleanText === right.cleanText && sameSupportedAtoms(left, right);
|
|
616
153
|
});
|
|
617
154
|
};
|
|
618
|
-
export { MISSING_NOTE_DETAIL,
|
|
155
|
+
export { MISSING_NOTE_DETAIL, atomBlocksOf, hasSupportedAtom, isSupportedAtom, sameInlineAtoms, textBlocksOf };
|
|
@@ -36,30 +36,6 @@ type MapTargetProperties = (args: {
|
|
|
36
36
|
current: document_d_exports.SectionProperties | undefined;
|
|
37
37
|
target: document_d_exports.SectionProperties;
|
|
38
38
|
}) => MappedSectionBoundaryProperties | null;
|
|
39
|
-
export type StageSectionBoundaryPropertiesResult = {
|
|
40
|
-
status: "matched";
|
|
41
|
-
transaction: import("prosemirror-state").Transaction;
|
|
42
|
-
nextRevisionId: number;
|
|
43
|
-
rangeCount: number;
|
|
44
|
-
} | {
|
|
45
|
-
status: "unalignable";
|
|
46
|
-
detail: string;
|
|
47
|
-
} | {
|
|
48
|
-
status: "budget-exceeded";
|
|
49
|
-
};
|
|
50
|
-
/** Stage section deltas after document operations, against the accepted projection. */
|
|
51
|
-
export declare const stageSectionBoundaryProperties: ({ state, target, originalRevisionIdSeed, revisionStamp, author, maxRanges, mapTargetProperties }: {
|
|
52
|
-
state: import("prosemirror-state").EditorState;
|
|
53
|
-
target: Node;
|
|
54
|
-
originalRevisionIdSeed: number;
|
|
55
|
-
revisionStamp: {
|
|
56
|
-
idSeed: number;
|
|
57
|
-
date: string;
|
|
58
|
-
};
|
|
59
|
-
author: string;
|
|
60
|
-
maxRanges: number;
|
|
61
|
-
mapTargetProperties: MapTargetProperties;
|
|
62
|
-
}) => StageSectionBoundaryPropertiesResult;
|
|
63
39
|
type StageSectionBoundaryOperationsResult = {
|
|
64
40
|
status: "matched";
|
|
65
41
|
operations: readonly SetSectionEndpointOp[];
|
|
@@ -71,12 +47,9 @@ type StageSectionBoundaryOperationsResult = {
|
|
|
71
47
|
status: "budget-exceeded";
|
|
72
48
|
};
|
|
73
49
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* `document` by its paragraph id. One section-endpoint operation per
|
|
78
|
-
* endpoint, revision ids given from the last endpoint back as the
|
|
79
|
-
* transaction gives them.
|
|
50
|
+
* Plan section deltas on the accepted projection of `document` and find each
|
|
51
|
+
* boundary in the authored document by paragraph id. Emit one operation per
|
|
52
|
+
* endpoint, assigning revision ids from the last endpoint back.
|
|
80
53
|
*/
|
|
81
54
|
export declare const stageSectionBoundaryOperations: ({ document, accepted, target, originalRevisionIdSeed, revisionStamp, author, maxRanges, mapTargetProperties }: {
|
|
82
55
|
document: document_d_exports.Document;
|