@stll/folio-core 0.74.0 → 0.76.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 +7 -3
- package/dist/ai-edits/headless.js +36 -21
- 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 +135 -90
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +6 -2
- package/dist/ai-edits/read.js +9 -3
- 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/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +37 -22
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +16 -6
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalPublicOperations.js +231 -79
- 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 +119 -122
- 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.d.ts +1 -1
- package/dist/controller/canonicalClipboard.js +110 -55
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -3
- package/dist/controller/canonicalStructure.js +182 -58
- 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/fontReadiness.js +50 -23
- 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 +135 -207
- 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/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- 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/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 +96 -7
- package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
- package/dist/docx/server/templatePlan/blocks.js +272 -10
- package/dist/docx/server/templatePlan/builders.d.ts +52 -2
- package/dist/docx/server/templatePlan/builders.js +224 -5
- 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 +46 -2
- package/dist/docx/server/templatePlan/inspect.js +39 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +120 -23
- package/dist/docx/server/templatePlan/plan.d.ts +24 -3
- package/dist/docx/server/templatePlan/plan.js +54 -15
- package/dist/docx/server/templatePlan/planShape.js +76 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
- package/dist/docx/server/templatePlan/revisions.js +407 -0
- package/dist/docx/server/templatePlan/story.d.ts +23 -1
- package/dist/docx/server/templatePlan/story.js +60 -2
- package/dist/docx/server/templatePlan/types.d.ts +354 -16
- package/dist/docx/server/templatePlan/verify.js +164 -14
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- 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/internal/revisionResolutionStep.d.ts +2 -31
- package/dist/internal/revisionResolutionStep.js +2 -171
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- 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/commands/tableCellMergeResolution.d.ts +1 -11
- package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- 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/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- 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 +2 -5
- package/dist/prosemirror/replacedAnnotations.js +1 -10
- 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/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 +40 -69
- package/dist/types/canonicalCapabilities.js +51 -65
- 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/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
|
@@ -4,92 +4,8 @@ import { BLOCK_TREE_DESCENT, visitBlockTreeRecords, visitInlineContentSlots, vis
|
|
|
4
4
|
import { consolidateParagraphContent, formattingEquals } from "../docx/runConsolidator.js";
|
|
5
5
|
import { serializeDocumentPart } from "../docx/serializer/documentSerializer.js";
|
|
6
6
|
import { WORDPROCESSINGML_NAMESPACE_URIS } from "../docx/xmlParser.js";
|
|
7
|
-
import { pluginsForHeadlessRevisionResolution } from "../internal/headlessRevisionResolutionGuard.js";
|
|
8
|
-
import { getSuggestions, projectAllChangesInHeadlessState, rejectEverySuggestion } from "../prosemirror/commands/comments.js";
|
|
9
|
-
import { proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
|
|
10
|
-
import { isBlockBoundaryNode } from "../prosemirror/keptRangeBoundaries.js";
|
|
11
|
-
import { readRangeAnchorAttrs } from "../prosemirror/rangeAnchorAttrs.js";
|
|
12
|
-
import { commentAnchorIdsForNode, ownCommentAnchorIds } from "./comment-lifecycle.js";
|
|
13
|
-
import { comparisonApplying, noteReferenceOf } from "./note-references.js";
|
|
14
|
-
import { changedTopLevelWindow } from "./result-validation.js";
|
|
15
|
-
import { Result } from "better-result";
|
|
16
7
|
import { mergeRunContent } from "@stll/docx-core/ops";
|
|
17
|
-
import { EditorState } from "prosemirror-state";
|
|
18
|
-
import { Fragment } from "prosemirror-model";
|
|
19
8
|
// src/ai-edits/tracked-batch-fidelity.ts
|
|
20
|
-
const copyRange = (doc, from, to) => {
|
|
21
|
-
if (from === 0 && to === doc.childCount) return doc;
|
|
22
|
-
const nodes = [];
|
|
23
|
-
for (let index = from; index < to; index++) nodes.push(doc.child(index));
|
|
24
|
-
return doc.copy(Fragment.fromArray(nodes));
|
|
25
|
-
};
|
|
26
|
-
const hasStoryBoundary = (doc) => {
|
|
27
|
-
let found = false;
|
|
28
|
-
doc.descendants((node) => {
|
|
29
|
-
found ||= isBlockBoundaryNode(node) || node.type.name === "rangeAnchor" || node.type.name === "bookmarkBoundary" || node.type.name === "moveRangeBoundary" || node.attrs["_sectionProperties"] != null || noteReferenceOf(node) !== null || commentAnchorIdsForNode(node).length > 0;
|
|
30
|
-
return !found;
|
|
31
|
-
});
|
|
32
|
-
return found;
|
|
33
|
-
};
|
|
34
|
-
const isStableBoundary = (node) => node.type.name === "paragraph" && node.attrs["pPrMark"] == null;
|
|
35
|
-
const hasParagraphMark = (node) => node.type.name === "paragraph" && node.attrs["pPrMark"] != null;
|
|
36
|
-
/** Include the neighbors a paragraph join or boundary relocation may reach. */
|
|
37
|
-
const resolutionWindow = (before, after) => {
|
|
38
|
-
const window = changedTopLevelWindow(before, after);
|
|
39
|
-
if (window === null) return null;
|
|
40
|
-
let { from, beforeTo, afterTo } = window;
|
|
41
|
-
while (from > 0) {
|
|
42
|
-
from--;
|
|
43
|
-
if (isStableBoundary(before.child(from))) {
|
|
44
|
-
const predecessor = before.maybeChild(from - 1);
|
|
45
|
-
if (predecessor === null || !hasParagraphMark(predecessor) && !isBlockBoundaryNode(predecessor)) break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
while (beforeTo < before.childCount && afterTo < after.childCount) {
|
|
49
|
-
const boundary = before.child(beforeTo);
|
|
50
|
-
beforeTo++;
|
|
51
|
-
afterTo++;
|
|
52
|
-
if (isStableBoundary(boundary)) break;
|
|
53
|
-
}
|
|
54
|
-
const beforeWindow = copyRange(before, from, beforeTo);
|
|
55
|
-
const afterWindow = copyRange(after, from, afterTo);
|
|
56
|
-
if (hasStoryBoundary(beforeWindow) || hasStoryBoundary(afterWindow)) return {
|
|
57
|
-
before,
|
|
58
|
-
after
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
before: beforeWindow,
|
|
62
|
-
after: afterWindow
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Comments added by an edit batch also exist outside its tracked revisions.
|
|
67
|
-
* Only the added comments' own anchors go; an older comment's reference
|
|
68
|
-
* inside an added comment's range stays, without the added comment's mark.
|
|
69
|
-
*/
|
|
70
|
-
const withoutAddedComments = (node, added) => {
|
|
71
|
-
const name = node.type.name;
|
|
72
|
-
if ((name === "commentReference" || name === "commentRangeBoundary") && ownCommentAnchorIds(node).some((id) => added.has(id))) return null;
|
|
73
|
-
if (name === "rangeAnchor") {
|
|
74
|
-
const parsed = readRangeAnchorAttrs(node);
|
|
75
|
-
if (parsed.ok) {
|
|
76
|
-
const markers = parsed.value.markers.filter((marker) => marker.type !== "commentRangeStart" && marker.type !== "commentRangeEnd" || !added.has(marker.id));
|
|
77
|
-
if (markers.length === 0) return null;
|
|
78
|
-
if (markers.length !== parsed.value.markers.length) return node.type.create({
|
|
79
|
-
...node.attrs,
|
|
80
|
-
markers
|
|
81
|
-
}, null, node.marks);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const marks = node.marks.filter((mark) => mark.type.name !== "comment" || !added.has(mark.attrs["commentId"]));
|
|
85
|
-
if (node.isLeaf) return node.mark(marks);
|
|
86
|
-
const children = [];
|
|
87
|
-
node.forEach((child) => {
|
|
88
|
-
const kept = withoutAddedComments(child, added);
|
|
89
|
-
if (kept !== null) children.push(kept);
|
|
90
|
-
});
|
|
91
|
-
return node.copy(Fragment.fromArray(children)).mark(marks);
|
|
92
|
-
};
|
|
93
9
|
const protectionKinds = [
|
|
94
10
|
"note",
|
|
95
11
|
"drawing",
|
|
@@ -99,61 +15,11 @@ const protectionKinds = [
|
|
|
99
15
|
const add = (items, key) => {
|
|
100
16
|
items.set(key, (items.get(key) ?? 0) + 1);
|
|
101
17
|
};
|
|
102
|
-
const isTrackedDeletion = (node) => node.marks.some(({ type }) => type.name === "deletion");
|
|
103
|
-
/**
|
|
104
|
-
* The protected content of `doc`; with `deletedOnly`, only the notes,
|
|
105
|
-
* drawings and fields that are themselves pending deletion, which Accept All
|
|
106
|
-
* removes as the reviewer sees it.
|
|
107
|
-
*/
|
|
108
|
-
const protectedContent = (doc, deletedOnly = false) => {
|
|
109
|
-
const inventory = {
|
|
110
|
-
note: /* @__PURE__ */ new Map(),
|
|
111
|
-
drawing: /* @__PURE__ */ new Map(),
|
|
112
|
-
field: /* @__PURE__ */ new Map(),
|
|
113
|
-
comment: /* @__PURE__ */ new Map()
|
|
114
|
-
};
|
|
115
|
-
const comments = /* @__PURE__ */ new Set();
|
|
116
|
-
let hasComment = false;
|
|
117
|
-
doc.descendants((node) => {
|
|
118
|
-
if (deletedOnly && !isTrackedDeletion(node)) return true;
|
|
119
|
-
if (deletedOnly && node.type.name === "textBoxAnchor") add(inventory.drawing, JSON.stringify(["textBox", node.attrs["anchorId"]]));
|
|
120
|
-
const note = noteReferenceOf(node);
|
|
121
|
-
if (note !== null) inventory.note.set(JSON.stringify([note.noteType, note.noteId]), 1);
|
|
122
|
-
switch (node.type.name) {
|
|
123
|
-
case "image":
|
|
124
|
-
add(inventory.drawing, JSON.stringify([
|
|
125
|
-
"image",
|
|
126
|
-
node.attrs["rId"] ?? node.attrs["src"],
|
|
127
|
-
node.attrs["docPrId"]
|
|
128
|
-
]));
|
|
129
|
-
break;
|
|
130
|
-
case "shape":
|
|
131
|
-
add(inventory.drawing, JSON.stringify(["shape", node.attrs["shapeId"]]));
|
|
132
|
-
break;
|
|
133
|
-
case "textBox":
|
|
134
|
-
add(inventory.drawing, JSON.stringify(["textBox", node.attrs["_docxAnchorId"]]));
|
|
135
|
-
break;
|
|
136
|
-
case "field":
|
|
137
|
-
case "structuredField": add(inventory.field, String(node.attrs["instruction"]));
|
|
138
|
-
}
|
|
139
|
-
if (deletedOnly) return true;
|
|
140
|
-
for (const id of commentAnchorIdsForNode(node)) {
|
|
141
|
-
comments.add(id);
|
|
142
|
-
hasComment = true;
|
|
143
|
-
}
|
|
144
|
-
return true;
|
|
145
|
-
});
|
|
146
|
-
for (const id of comments) add(inventory.comment, String(id));
|
|
147
|
-
if (hasComment) visitCommentMarkers(proseDocToBlocks(doc, []), ({ item }) => {
|
|
148
|
-
if (item.type === "commentReference") add(inventory.comment, `reference:${String(item.id)}`);
|
|
149
|
-
});
|
|
150
|
-
return inventory;
|
|
151
|
-
};
|
|
152
18
|
/**
|
|
153
19
|
* The protected content `after` holds as a pending deletion and `before` did
|
|
154
20
|
* not: an edit the reviewer sees as deleted, which Accept All may remove.
|
|
155
21
|
*/
|
|
156
|
-
const
|
|
22
|
+
const newlyDeletedProtectedContent = (before, after) => {
|
|
157
23
|
const inventory = {
|
|
158
24
|
note: /* @__PURE__ */ new Map(),
|
|
159
25
|
drawing: /* @__PURE__ */ new Map(),
|
|
@@ -240,7 +106,6 @@ const sameOriginalBlocks = (before, after, addedCommentIds) => {
|
|
|
240
106
|
return other !== void 0 && (block === other || authoredBlock(block) === authoredBlock(other));
|
|
241
107
|
});
|
|
242
108
|
};
|
|
243
|
-
const sameOriginal = (before, after) => before.content.eq(after.content) || sameOriginalBlocks(proseDocToBlocks(before, []), proseDocToBlocks(after, []), /* @__PURE__ */ new Set());
|
|
244
109
|
const modelInventory = (blocks) => {
|
|
245
110
|
const inventory = {
|
|
246
111
|
note: /* @__PURE__ */ new Map(),
|
|
@@ -307,51 +172,7 @@ const deletedModelInventory = (blocks) => {
|
|
|
307
172
|
* The protected content the edited blocks hold as a new tracked deletion,
|
|
308
173
|
* which Accept All removes as the reviewer sees it.
|
|
309
174
|
*/
|
|
310
|
-
const newlyDeletedProtectedBlocks = (before, after) =>
|
|
175
|
+
const newlyDeletedProtectedBlocks = (before, after) => newlyDeletedProtectedContent(deletedModelInventory(before), deletedModelInventory(after));
|
|
311
176
|
/** The kind of protected content missing from the accepted blocks. */
|
|
312
177
|
const missingProtectedBlockKind = (before, after, retiredCommentIds = [], deleted) => missingProtectedContent(modelInventory(before), modelInventory(after), retiredCommentIds, deleted);
|
|
313
|
-
|
|
314
|
-
if (comparisonApplying()) return null;
|
|
315
|
-
const window = resolutionWindow(before.doc, after);
|
|
316
|
-
if (window === null) return null;
|
|
317
|
-
const plugins = pluginsForHeadlessRevisionResolution(before.plugins);
|
|
318
|
-
let original = EditorState.create({
|
|
319
|
-
doc: window.before,
|
|
320
|
-
plugins
|
|
321
|
-
});
|
|
322
|
-
let candidate = EditorState.create({
|
|
323
|
-
doc: window.after,
|
|
324
|
-
plugins
|
|
325
|
-
});
|
|
326
|
-
if (window.before !== before.doc && (getSuggestions(original).length > 0 || getSuggestions(candidate).length > 0)) {
|
|
327
|
-
original = EditorState.create({
|
|
328
|
-
doc: before.doc,
|
|
329
|
-
plugins
|
|
330
|
-
});
|
|
331
|
-
candidate = EditorState.create({
|
|
332
|
-
doc: after,
|
|
333
|
-
plugins
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
original = rejectEverySuggestion(original);
|
|
337
|
-
candidate = rejectEverySuggestion(candidate);
|
|
338
|
-
const rejectedBefore = projectAllChangesInHeadlessState(original, "reject");
|
|
339
|
-
const rejectedAfter = projectAllChangesInHeadlessState(candidate, "reject");
|
|
340
|
-
if (rejectedBefore === null || rejectedAfter === null) return "Reject All could not resolve the tracked result.";
|
|
341
|
-
const rejected = createdCommentIds.length === 0 ? rejectedAfter.doc : withoutAddedComments(rejectedAfter.doc, new Set(createdCommentIds));
|
|
342
|
-
if (rejected === null || !sameOriginal(rejectedBefore.doc, rejected)) return "Reject All would change the original content or formatting.";
|
|
343
|
-
const acceptedBefore = projectAllChangesInHeadlessState(original, "accept");
|
|
344
|
-
const acceptedAfter = projectAllChangesInHeadlessState(candidate, "accept");
|
|
345
|
-
if (acceptedBefore === null || acceptedAfter === null) return "Accept All could not resolve the tracked result.";
|
|
346
|
-
const lost = missingProtectedContent(protectedContent(acceptedBefore.doc), protectedContent(acceptedAfter.doc), retiredCommentIds, newlyDeleted(protectedContent(original.doc, true), protectedContent(candidate.doc, true)));
|
|
347
|
-
return lost === null ? null : `Accept All would lose a ${lost}.`;
|
|
348
|
-
};
|
|
349
|
-
/** Check both clean readings before any tracked batch can publish its changes. */
|
|
350
|
-
const trackedBatchFidelityError = (options) => {
|
|
351
|
-
const verdict = Result.try({
|
|
352
|
-
try: () => checkTrackedBatchFidelity(options),
|
|
353
|
-
catch: () => "The tracked result could not be verified."
|
|
354
|
-
});
|
|
355
|
-
return verdict.isOk() ? verdict.value : verdict.error;
|
|
356
|
-
};
|
|
357
|
-
export { missingProtectedBlockKind, newlyDeletedProtectedBlocks, sameOriginalBlocks, trackedBatchFidelityError };
|
|
178
|
+
export { missingProtectedBlockKind, missingProtectedContent, newlyDeletedProtectedBlocks, newlyDeletedProtectedContent, sameOriginalBlocks };
|
package/dist/ai-edits/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FolioContentBlock, FolioContentBlockIdentity, FolioContentInlineBooleanProperty, FolioContentInlineFormatting, FolioContentInlineFormattingPatch, FolioContentListReference, FolioContentParagraphIndentation, FolioContentParagraphKind, FolioContentParagraphSpacing, FolioContentRun, FolioContentSnapshot, FolioContentStatedNumbering, FolioContentTableLocation } from "../compare/content-types.js";
|
|
2
2
|
import { ListKind } from "../docx/listNumberingInstances.js";
|
|
3
|
-
import {
|
|
3
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
4
4
|
import { document_d_exports } from "../types/document.js";
|
|
5
5
|
export type FolioAIBlockKind = FolioContentParagraphKind | "diagnostic";
|
|
6
6
|
/** Boolean run properties supported by snapshots and range-formatting mutations. */
|
|
@@ -762,9 +762,14 @@ export type FolioAIEditParagraphIdentity = {
|
|
|
762
762
|
export type FolioAIEditSkippedOperation = {
|
|
763
763
|
id: string;
|
|
764
764
|
reason: FolioAIEditSkipReason;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
765
|
+
/**
|
|
766
|
+
* Why the canonical session refused it: a capability it does not have yet
|
|
767
|
+
* (`gap`), a rule the document states (`rule`), or a condition of the
|
|
768
|
+
* session or the request (`condition`), as `canonicalRefusalNotice` reads
|
|
769
|
+
* them. Absent where the reason alone says it, as the default engine
|
|
770
|
+
* reports the skip.
|
|
771
|
+
*/
|
|
772
|
+
canonicalRefusal?: CanonicalRefusalGround;
|
|
768
773
|
/**
|
|
769
774
|
* What exactly was wrong when the reason alone does not say: the values a
|
|
770
775
|
* `payloadDoesNotFit` skip could not place, the earlier operation an
|
|
@@ -19,7 +19,10 @@ export declare const createCanonicalBatchReview: ({ before, after, story }: Cano
|
|
|
19
19
|
original: readonly document_d_exports.BlockContent[];
|
|
20
20
|
edited: readonly document_d_exports.BlockContent[];
|
|
21
21
|
} | null;
|
|
22
|
-
reject
|
|
22
|
+
reject: () => {
|
|
23
|
+
original: readonly document_d_exports.BlockContent[];
|
|
24
|
+
edited: readonly document_d_exports.BlockContent[];
|
|
25
|
+
} | null;
|
|
23
26
|
acceptedCommentIds(side: "before" | "after"): Set<number> | null;
|
|
24
27
|
};
|
|
25
28
|
export {};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { anchoredCommentIdsInBlocks } from "../ai-edits/comment-lifecycle.js";
|
|
2
2
|
import { getTrackedChangeGroupsForIds, getTrackedChangeStatsFromDoc } from "../ai-edits/read.js";
|
|
3
|
-
import { pendingSuggestionRevisionIds } from "../prosemirror/commands/comments.js";
|
|
4
3
|
import { lockedControlSpans } from "../prosemirror/lockedControls.js";
|
|
5
4
|
import { lockViolationBetween } from "./canonicalLockGuard.js";
|
|
6
5
|
import { canonicalRevisionLocks } from "./canonicalRevisionLocks.js";
|
|
7
6
|
import { preservePropertySources } from "./propertySourcePreservation.js";
|
|
8
|
-
import { DOCUMENT_OP_TYPES, applyDocumentOps, findStoryBody } from "@stll/docx-core/ops";
|
|
9
|
-
import { EditorState } from "prosemirror-state";
|
|
7
|
+
import { DOCUMENT_OP_TYPES, applyDocumentOps, findStoryBody, suggestionOwnersInStory } from "@stll/docx-core/ops";
|
|
10
8
|
// src/canonical/canonicalBatchReview.ts
|
|
11
|
-
const revisionIdsOf = (
|
|
12
|
-
const { ids } = getTrackedChangeStatsFromDoc(
|
|
9
|
+
const revisionIdsOf = (version, story) => {
|
|
10
|
+
const { ids } = getTrackedChangeStatsFromDoc(version.projection);
|
|
13
11
|
if (ids.length === 0) return {
|
|
14
12
|
all: ids,
|
|
15
13
|
ordinary: ids
|
|
16
14
|
};
|
|
17
|
-
const
|
|
18
|
-
const suggested = pendingSuggestionRevisionIds(state);
|
|
15
|
+
const suggested = suggestionOwnersInStory(version.document, story);
|
|
19
16
|
return {
|
|
20
17
|
all: ids,
|
|
21
18
|
ordinary: suggested.size === 0 ? ids : ids.filter((id) => !suggested.has(id))
|
|
@@ -60,7 +57,14 @@ const resolveStory = ({ version: { document, projection }, story, ids, decision,
|
|
|
60
57
|
indentation: "restore"
|
|
61
58
|
}));
|
|
62
59
|
};
|
|
63
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Both sides of a batch resolved the same way. A revision the document held
|
|
62
|
+
* before the batch that blocks its own resolution, alone and the same way on
|
|
63
|
+
* both sides, stays pending on both: the proof is about what the batch
|
|
64
|
+
* changes, and a blocker the batch did not make must not refuse every edit
|
|
65
|
+
* of a document that holds one.
|
|
66
|
+
*/
|
|
67
|
+
const resolveStoryPair = ({ before, after, story, decision, restores }) => {
|
|
64
68
|
let beforeIds = before.ids;
|
|
65
69
|
let afterIds = after.ids;
|
|
66
70
|
while (true) {
|
|
@@ -68,13 +72,14 @@ const acceptStoryPair = ({ before, after, story }) => {
|
|
|
68
72
|
version: before.version,
|
|
69
73
|
story,
|
|
70
74
|
ids: beforeIds,
|
|
71
|
-
decision
|
|
75
|
+
decision
|
|
72
76
|
});
|
|
73
77
|
const edited = resolveStory({
|
|
74
78
|
version: after.version,
|
|
75
79
|
story,
|
|
76
80
|
ids: afterIds,
|
|
77
|
-
decision
|
|
81
|
+
decision,
|
|
82
|
+
...restores === void 0 ? {} : { restores }
|
|
78
83
|
});
|
|
79
84
|
if (original?.type === "resolved" && edited?.type === "resolved") return {
|
|
80
85
|
original: original.content,
|
|
@@ -91,12 +96,13 @@ const acceptStoryPair = ({ before, after, story }) => {
|
|
|
91
96
|
const createCanonicalBatchReview = ({ before, after, story }) => {
|
|
92
97
|
let beforeIds;
|
|
93
98
|
let afterIds;
|
|
94
|
-
const revisions = (side) => side === "before" ? beforeIds ??= revisionIdsOf(before
|
|
99
|
+
const revisions = (side) => side === "before" ? beforeIds ??= revisionIdsOf(before, story) : afterIds ??= revisionIdsOf(after, story);
|
|
95
100
|
let accepted;
|
|
96
101
|
const accept = () => {
|
|
97
102
|
if (accepted !== void 0) return accepted;
|
|
98
|
-
accepted =
|
|
103
|
+
accepted = resolveStoryPair({
|
|
99
104
|
story,
|
|
105
|
+
decision: "accept",
|
|
100
106
|
before: {
|
|
101
107
|
version: before,
|
|
102
108
|
ids: revisions("before").ordinary
|
|
@@ -108,21 +114,30 @@ const createCanonicalBatchReview = ({ before, after, story }) => {
|
|
|
108
114
|
}) ?? null;
|
|
109
115
|
return accepted;
|
|
110
116
|
};
|
|
117
|
+
let rejected;
|
|
118
|
+
const reject = () => {
|
|
119
|
+
if (rejected !== void 0) return rejected;
|
|
120
|
+
rejected = resolveStoryPair({
|
|
121
|
+
story,
|
|
122
|
+
decision: "reject",
|
|
123
|
+
before: {
|
|
124
|
+
version: before,
|
|
125
|
+
ids: revisions("before").all
|
|
126
|
+
},
|
|
127
|
+
after: {
|
|
128
|
+
version: after,
|
|
129
|
+
ids: revisions("after").all
|
|
130
|
+
},
|
|
131
|
+
restores: before.document
|
|
132
|
+
}) ?? null;
|
|
133
|
+
return rejected;
|
|
134
|
+
};
|
|
111
135
|
return {
|
|
112
136
|
story,
|
|
113
137
|
before: before.document,
|
|
114
138
|
after: after.document,
|
|
115
139
|
accept,
|
|
116
|
-
reject
|
|
117
|
-
const rejected = resolveStory({
|
|
118
|
-
version: side === "before" ? before : after,
|
|
119
|
-
story,
|
|
120
|
-
ids: revisions(side).all,
|
|
121
|
-
decision: "reject",
|
|
122
|
-
...side === "after" ? { restores: before.document } : {}
|
|
123
|
-
});
|
|
124
|
-
return rejected?.type === "resolved" ? rejected.content : void 0;
|
|
125
|
-
},
|
|
140
|
+
reject,
|
|
126
141
|
acceptedCommentIds(side) {
|
|
127
142
|
const pair = accept();
|
|
128
143
|
return pair === null ? null : anchoredCommentIdsInBlocks(side === "before" ? pair.original : pair.edited);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/** The one semantic compiler for canonical sidebar, controlled and public comments. */
|
|
2
|
-
import {
|
|
2
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
3
3
|
import { Comment } from "../types/content.js";
|
|
4
4
|
import { document_d_exports } from "../types/document.js";
|
|
5
5
|
import { Err, Ok, TaggedErrorClass } from "better-result";
|
|
6
6
|
import { CreateCommentOp, DocumentOp, IdLease } from "@stll/docx-core/ops";
|
|
7
7
|
declare const CanonicalCommentErrorBase: TaggedErrorClass<"CanonicalCommentError">;
|
|
8
|
+
/**
|
|
9
|
+
* A comment command the document does not allow, such as a reply to a missing
|
|
10
|
+
* thread, or one no id is left to mint for.
|
|
11
|
+
*/
|
|
8
12
|
export declare class CanonicalCommentError extends CanonicalCommentErrorBase<{
|
|
9
13
|
message: string;
|
|
10
|
-
|
|
14
|
+
ground: CanonicalRefusalGround;
|
|
11
15
|
}> {}
|
|
12
16
|
export type CanonicalCommentCommand = {
|
|
13
17
|
type: "create";
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { commentThreadParaId } from "../docx/commentThreadKey.js";
|
|
2
2
|
import { cloneParagraphWithPropertySource } from "../docx/paragraphPropertySource.js";
|
|
3
3
|
import { threadedCommentIds } from "../docx/serializer/commentSerializer.js";
|
|
4
|
-
import {
|
|
4
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
5
5
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
6
|
+
import { groundForDocumentOpRefusal } from "./canonicalRefusalGrounds.js";
|
|
6
7
|
import { Result, TaggedError } from "better-result";
|
|
7
8
|
import { DOCUMENT_OP_TYPES, ID_KIND_LIMITS, ID_LEASE_KINDS, allocateCommentAnchorIds, applyDocumentOps, formatParaId, freshLeasedIds, packageParagraphIds } from "@stll/docx-core/ops";
|
|
8
9
|
// src/canonical/canonicalComments.ts
|
|
9
10
|
/** The one semantic compiler for canonical sidebar, controlled and public comments. */
|
|
10
11
|
const CanonicalCommentErrorBase = TaggedError("CanonicalCommentError");
|
|
12
|
+
/**
|
|
13
|
+
* A comment command the document does not allow, such as a reply to a missing
|
|
14
|
+
* thread, or one no id is left to mint for.
|
|
15
|
+
*/
|
|
11
16
|
var CanonicalCommentError = class extends CanonicalCommentErrorBase {};
|
|
12
|
-
const refuse = (message) => Result.err(new CanonicalCommentError({
|
|
17
|
+
const refuse = (message, condition = CANONICAL_CONDITION.invalidRequest) => Result.err(new CanonicalCommentError({
|
|
13
18
|
message,
|
|
14
|
-
|
|
19
|
+
ground: { condition }
|
|
20
|
+
}));
|
|
21
|
+
/** A refusal the document operations stated, under its reason's ground. */
|
|
22
|
+
const refuseOp = ({ reason, message }) => Result.err(new CanonicalCommentError({
|
|
23
|
+
message,
|
|
24
|
+
ground: groundForDocumentOpRefusal(reason)
|
|
15
25
|
}));
|
|
16
26
|
const compileCanonicalComments = ({ document, command, idLease }) => {
|
|
17
27
|
const current = document.package.document.comments ?? [];
|
|
@@ -127,9 +137,9 @@ const compileCanonicalComments = ({ document, command, idLease }) => {
|
|
|
127
137
|
newIds: allocation.value
|
|
128
138
|
});
|
|
129
139
|
})();
|
|
130
|
-
if (materialized.isErr()) return
|
|
140
|
+
if (materialized.isErr()) return refuseOp(materialized.error);
|
|
131
141
|
const applied = applyDocumentOps(draft, [materialized.value]);
|
|
132
|
-
if (applied.isErr()) return
|
|
142
|
+
if (applied.isErr()) return refuseOp(applied.error);
|
|
133
143
|
compiled.push(materialized.value);
|
|
134
144
|
draft = applied.value.document;
|
|
135
145
|
}
|
|
@@ -139,7 +149,7 @@ const compileCanonicalComments = ({ document, command, idLease }) => {
|
|
|
139
149
|
const last = content.at(-1);
|
|
140
150
|
if (!threaded.has(comment.id) || last === void 0 || commentThreadParaId(content.map(({ paraId }) => paraId)) !== void 0) continue;
|
|
141
151
|
const paraId = canonicalCommentBody(draft, "", idLease).at(0)?.paraId;
|
|
142
|
-
if (paraId === void 0) return refuse("No paragraph id is free.");
|
|
152
|
+
if (paraId === void 0) return refuse("No paragraph id is free.", CANONICAL_CONDITION.idSpace);
|
|
143
153
|
const op = {
|
|
144
154
|
type: DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT,
|
|
145
155
|
id: comment.id,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { FolioAIEditSkipReason } from "../ai-edits/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
3
3
|
import { DocumentOpRefusal } from "@stll/docx-core/ops";
|
|
4
4
|
type CompilerRefusalSkip = {
|
|
5
5
|
reason: FolioAIEditSkipReason;
|
|
6
6
|
message: string;
|
|
7
|
-
refusal?:
|
|
8
|
-
gap: CanonicalGap;
|
|
9
|
-
};
|
|
7
|
+
refusal?: CanonicalRefusalGround;
|
|
10
8
|
};
|
|
11
9
|
/** The skip a refused compilation reports. */
|
|
12
10
|
export declare const compilerRefusalSkip: ({ reason, message }: DocumentOpRefusal) => CompilerRefusalSkip;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { groundForDocumentOpRefusal } from "./canonicalRefusalGrounds.js";
|
|
2
2
|
import { DOCUMENT_OP_REFUSAL_REASONS } from "@stll/docx-core/ops";
|
|
3
3
|
// src/canonical/canonicalCompilerRefusal.ts
|
|
4
4
|
const typed = (reason) => ({
|
|
5
5
|
type: "typed",
|
|
6
6
|
reason
|
|
7
7
|
});
|
|
8
|
-
const
|
|
8
|
+
const grounded = (reason) => ({
|
|
9
|
+
type: "grounded",
|
|
10
|
+
reason
|
|
11
|
+
});
|
|
12
|
+
const UNSUPPORTED = grounded("unsupportedBlock");
|
|
9
13
|
const R = DOCUMENT_OP_REFUSAL_REASONS;
|
|
10
14
|
/**
|
|
11
15
|
* Every compiler refusal reason's public disposition. A deliberate refusal
|
|
12
|
-
* names its own reason, as the legacy engine reports one
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* names its own reason, as the legacy engine reports one, and so does a
|
|
17
|
+
* change that would change nothing. A document that moved on is a stale
|
|
18
|
+
* range, and an offset inside a character splits it. Every other reason
|
|
19
|
+
* reports its ground besides: `untrackable` the shapes the tracked-change
|
|
20
|
+
* records do not express yet, `unrecordableLinkSuggestion` the rule the
|
|
21
|
+
* review records state, and the rest a request the document does not allow.
|
|
16
22
|
*/
|
|
17
23
|
const COMPILER_REFUSAL_DISPOSITIONS = {
|
|
18
24
|
[R.PENDING_RUN_PROPERTY_CHANGE]: typed("pendingRunPropertyChange"),
|
|
@@ -25,13 +31,13 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
|
|
|
25
31
|
[R.PENDING_PARAGRAPH_MARK_INSERTION]: typed("pendingParagraphMarkInsertion"),
|
|
26
32
|
[R.PENDING_PARAGRAPH_JOIN]: typed("pendingParagraphMarkDeletion"),
|
|
27
33
|
[R.UNSUPPORTED_SCHEMA]: UNSUPPORTED,
|
|
28
|
-
[R.BLOCK_NOT_FOUND]:
|
|
34
|
+
[R.BLOCK_NOT_FOUND]: grounded("missingBlock"),
|
|
29
35
|
[R.INVALID_OPERATION]: UNSUPPORTED,
|
|
30
|
-
[R.NO_CHANGE]:
|
|
36
|
+
[R.NO_CHANGE]: typed("noopOperation"),
|
|
31
37
|
[R.DEPENDENT_RECORDS]: UNSUPPORTED,
|
|
32
38
|
[R.INVALID_OFFSET]: UNSUPPORTED,
|
|
33
39
|
[R.CROSS_BLOCK_RANGE]: UNSUPPORTED,
|
|
34
|
-
[R.SPLITS_SURROGATE_PAIR]:
|
|
40
|
+
[R.SPLITS_SURROGATE_PAIR]: grounded("splitsCharacter"),
|
|
35
41
|
[R.INVALID_TEXT]: UNSUPPORTED,
|
|
36
42
|
[R.INVALID_BLOCK_ID]: UNSUPPORTED,
|
|
37
43
|
[R.ID_COLLISION]: UNSUPPORTED,
|
|
@@ -41,7 +47,7 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
|
|
|
41
47
|
[R.NEEDS_NEW_IDS]: UNSUPPORTED,
|
|
42
48
|
[R.INVALID_NEW_ID]: UNSUPPORTED,
|
|
43
49
|
[R.SHARED_ID]: UNSUPPORTED,
|
|
44
|
-
[R.STALE]:
|
|
50
|
+
[R.STALE]: grounded("staleRange"),
|
|
45
51
|
[R.STRUCTURE_MISMATCH]: UNSUPPORTED,
|
|
46
52
|
[R.EMPTY_CONTENT]: UNSUPPORTED,
|
|
47
53
|
[R.EMPTY_BLOCK_LIST]: UNSUPPORTED,
|
|
@@ -53,7 +59,7 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
|
|
|
53
59
|
[R.MISSING_BLOCK_ID]: UNSUPPORTED,
|
|
54
60
|
[R.DUPLICATE_BLOCK_ID]: UNSUPPORTED,
|
|
55
61
|
[R.DUPLICATE_RECORD_ID]: UNSUPPORTED,
|
|
56
|
-
[R.SECTIONS_OUT_OF_STEP]:
|
|
62
|
+
[R.SECTIONS_OUT_OF_STEP]: grounded("staleRange"),
|
|
57
63
|
[R.EMPTY_RECORD]: UNSUPPORTED
|
|
58
64
|
};
|
|
59
65
|
/** The skip a refused compilation reports. */
|
|
@@ -64,10 +70,10 @@ const compilerRefusalSkip = ({ reason, message }) => {
|
|
|
64
70
|
reason: disposition.reason,
|
|
65
71
|
message
|
|
66
72
|
};
|
|
67
|
-
case "
|
|
68
|
-
reason:
|
|
73
|
+
case "grounded": return {
|
|
74
|
+
reason: disposition.reason,
|
|
69
75
|
message,
|
|
70
|
-
refusal:
|
|
76
|
+
refusal: groundForDocumentOpRefusal(reason)
|
|
71
77
|
};
|
|
72
78
|
default: return disposition;
|
|
73
79
|
}
|