@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.
Files changed (174) hide show
  1. package/dist/ai-edits/clean-text.d.ts +4 -1
  2. package/dist/ai-edits/clean-text.js +21 -7
  3. package/dist/ai-edits/headless.d.ts +7 -3
  4. package/dist/ai-edits/headless.js +36 -21
  5. package/dist/ai-edits/note-references.d.ts +1 -1
  6. package/dist/ai-edits/note-references.js +1 -1
  7. package/dist/ai-edits/pending-suggestions.d.ts +9 -7
  8. package/dist/ai-edits/pending-suggestions.js +135 -90
  9. package/dist/ai-edits/pendingJoin.d.ts +5 -1
  10. package/dist/ai-edits/pendingJoin.js +6 -2
  11. package/dist/ai-edits/read.js +9 -3
  12. package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
  13. package/dist/ai-edits/retired-comment-receipts.js +3 -18
  14. package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
  15. package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
  16. package/dist/ai-edits/types.d.ts +9 -4
  17. package/dist/canonical/batchCommentReferences.js +2 -1
  18. package/dist/canonical/canonicalBatchReview.d.ts +4 -1
  19. package/dist/canonical/canonicalBatchReview.js +37 -22
  20. package/dist/canonical/canonicalComments.d.ts +6 -2
  21. package/dist/canonical/canonicalComments.js +16 -6
  22. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  23. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  24. package/dist/canonical/canonicalPublicOperations.js +231 -79
  25. package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
  26. package/dist/canonical/canonicalRefusalGrounds.js +56 -0
  27. package/dist/canonical/canonicalSession.d.ts +12 -6
  28. package/dist/canonical/canonicalSession.js +119 -122
  29. package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
  30. package/dist/compare/inline-atoms.d.ts +35 -41
  31. package/dist/compare/inline-atoms.js +2 -465
  32. package/dist/compare/section-boundary-properties.d.ts +3 -30
  33. package/dist/compare/section-boundary-properties.js +4 -72
  34. package/dist/controller/canonicalClipboard.d.ts +1 -1
  35. package/dist/controller/canonicalClipboard.js +110 -55
  36. package/dist/controller/canonicalComposition.d.ts +1 -1
  37. package/dist/controller/canonicalComposition.js +5 -5
  38. package/dist/controller/canonicalContentControlValue.js +7 -7
  39. package/dist/controller/canonicalInput.d.ts +4 -2
  40. package/dist/controller/canonicalInput.js +33 -16
  41. package/dist/controller/canonicalReview.d.ts +21 -0
  42. package/dist/controller/canonicalReview.js +44 -9
  43. package/dist/controller/canonicalStoryEditor.d.ts +2 -3
  44. package/dist/controller/canonicalStoryEditor.js +43 -25
  45. package/dist/controller/canonicalStructure.d.ts +19 -3
  46. package/dist/controller/canonicalStructure.js +182 -58
  47. package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
  48. package/dist/controller/deferredDisplayListPainter.js +34 -0
  49. package/dist/controller/folioEditor.js +4 -2
  50. package/dist/controller/fontReadiness.js +50 -23
  51. package/dist/controller/headerFooterEditorManager.js +3 -17
  52. package/dist/controller/hiddenEditorApi.d.ts +24 -3
  53. package/dist/controller/hiddenEditorApi.js +2 -0
  54. package/dist/controller/hiddenEditorManager.js +135 -207
  55. package/dist/controller/layoutPipeline.d.ts +4 -86
  56. package/dist/controller/layoutPipeline.js +8 -727
  57. package/dist/controller/layoutPipelineExecution.d.ts +94 -0
  58. package/dist/controller/layoutPipelineExecution.js +730 -0
  59. package/dist/controller/noteEditorManager.js +3 -16
  60. package/dist/docx/blockContentParser.d.ts +1 -3
  61. package/dist/docx/blockContentParser.js +3 -10
  62. package/dist/docx/bulletMarkers.d.ts +8 -0
  63. package/dist/docx/bulletMarkers.js +9 -1
  64. package/dist/docx/canonicalSave.d.ts +4 -3
  65. package/dist/docx/canonicalSave.js +4 -3
  66. package/dist/docx/canonicalSessionInput.js +25 -11
  67. package/dist/docx/ensureParaIds.d.ts +31 -0
  68. package/dist/docx/ensureParaIds.js +57 -32
  69. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  70. package/dist/docx/ensureUniqueControlIds.js +47 -29
  71. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  72. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  73. package/dist/docx/listMarkerComputation.d.ts +24 -17
  74. package/dist/docx/listMarkerComputation.js +31 -60
  75. package/dist/docx/listModelNormalization.js +8 -15
  76. package/dist/docx/rezip.d.ts +16 -3
  77. package/dist/docx/rezip.js +35 -9
  78. package/dist/docx/selectiveSave.js +13 -5
  79. package/dist/docx/server/templatePlan/apply.js +96 -7
  80. package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
  81. package/dist/docx/server/templatePlan/blocks.js +272 -10
  82. package/dist/docx/server/templatePlan/builders.d.ts +52 -2
  83. package/dist/docx/server/templatePlan/builders.js +224 -5
  84. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  85. package/dist/docx/server/templatePlan/effects.js +188 -0
  86. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  87. package/dist/docx/server/templatePlan/emit.js +46 -2
  88. package/dist/docx/server/templatePlan/inspect.js +39 -52
  89. package/dist/docx/server/templatePlan/labels.d.ts +7 -2
  90. package/dist/docx/server/templatePlan/labels.js +120 -23
  91. package/dist/docx/server/templatePlan/plan.d.ts +24 -3
  92. package/dist/docx/server/templatePlan/plan.js +54 -15
  93. package/dist/docx/server/templatePlan/planShape.js +76 -22
  94. package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
  95. package/dist/docx/server/templatePlan/revisions.js +407 -0
  96. package/dist/docx/server/templatePlan/story.d.ts +23 -1
  97. package/dist/docx/server/templatePlan/story.js +60 -2
  98. package/dist/docx/server/templatePlan/types.d.ts +354 -16
  99. package/dist/docx/server/templatePlan/verify.js +164 -14
  100. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  101. package/dist/docx/server/templatePlan/xml.js +4 -1
  102. package/dist/i18n/messages/ar.gen.js +1 -0
  103. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  104. package/dist/i18n/messages/catalogs.gen.js +17 -0
  105. package/dist/i18n/messages/cs.gen.js +1 -0
  106. package/dist/i18n/messages/de.gen.js +1 -0
  107. package/dist/i18n/messages/en.gen.js +1 -0
  108. package/dist/i18n/messages/es.gen.js +1 -0
  109. package/dist/i18n/messages/et.gen.js +1 -0
  110. package/dist/i18n/messages/fr.gen.js +1 -0
  111. package/dist/i18n/messages/he.gen.js +1 -0
  112. package/dist/i18n/messages/hi.gen.js +1 -0
  113. package/dist/i18n/messages/hu.gen.js +1 -0
  114. package/dist/i18n/messages/lt.gen.js +1 -0
  115. package/dist/i18n/messages/lv.gen.js +1 -0
  116. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  117. package/dist/i18n/messages/pl.gen.js +1 -0
  118. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  119. package/dist/i18n/messages/sk.gen.js +1 -0
  120. package/dist/i18n/messages/tr.gen.js +1 -0
  121. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  122. package/dist/internal/revisionResolutionStep.d.ts +2 -31
  123. package/dist/internal/revisionResolutionStep.js +2 -171
  124. package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
  125. package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
  126. package/dist/prosemirror/commands/comments.d.ts +6 -234
  127. package/dist/prosemirror/commands/comments.js +5 -2464
  128. package/dist/prosemirror/commands/index.d.ts +4 -2
  129. package/dist/prosemirror/commands/index.js +4 -2
  130. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
  131. package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
  132. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
  133. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  134. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  135. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  136. package/dist/prosemirror/listMarker.d.ts +1 -6
  137. package/dist/prosemirror/listMarker.js +4 -56
  138. package/dist/prosemirror/paraIds.d.ts +1 -14
  139. package/dist/prosemirror/paraIds.js +1 -14
  140. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  141. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  142. package/dist/prosemirror/projectionReview.d.ts +49 -0
  143. package/dist/prosemirror/projectionReview.js +292 -0
  144. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  145. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  146. package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
  147. package/dist/prosemirror/replacedAnnotations.js +1 -10
  148. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  149. package/dist/prosemirror/revisionCarriers.js +15 -1
  150. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  151. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  152. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  153. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  154. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  155. package/dist/prosemirror/suggestionQueries.js +320 -0
  156. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  157. package/dist/prosemirror/tableGridMutation.js +1 -78
  158. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  159. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  160. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  161. package/dist/server.d.ts +2 -2
  162. package/dist/types/canonicalCapabilities.d.ts +40 -69
  163. package/dist/types/canonicalCapabilities.js +51 -65
  164. package/dist/types/canonicalComments.d.ts +2 -2
  165. package/dist/types/canonicalSections.d.ts +2 -2
  166. package/dist/utils/clipboard.d.ts +2 -28
  167. package/dist/utils/clipboard.js +1 -96
  168. package/dist/utils/clipboardFiles.d.ts +27 -0
  169. package/dist/utils/clipboardFiles.js +98 -0
  170. package/dist/utils/rulerControl.d.ts +1 -0
  171. package/dist/utils/rulerControl.js +2 -1
  172. package/package.json +2 -2
  173. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  174. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
@@ -1,9 +1,6 @@
1
- import { PARAGRAPH_SOURCE_JOIN_RULES, getProseParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
1
+ import { PARAGRAPH_SOURCE_JOIN_RULES } from "../docx/paragraphPropertySource.js";
2
2
  import { expectParagraphAttrs } from "./attrs/index.js";
3
- import { paragraphJoinAfter } from "./commands/paragraphBookmarkJoin.js";
4
- import { JOINED_RUNS_RESTYLED_META } from "./extensions/features/JoinedRunStyleExtension.js";
5
- import { rebaseParagraphRuns } from "./rebaseParagraphRunFormatting.js";
6
- import { paragraphRunStyleContext, resolveParagraphInheritedRunFormatting } from "./runStyleFormatting.js";
3
+ import { resolveParagraphInheritedRunFormatting } from "./runStyleFormatting.js";
7
4
  import { panic } from "better-result";
8
5
  // src/prosemirror/paragraphMarkJoin.ts
9
6
  /**
@@ -185,44 +182,4 @@ const joinedParagraphAttrs = ({ paragraph, next, between = 0, styleResolver }) =
185
182
  }
186
183
  return changed ? attrs : next.attrs;
187
184
  };
188
- const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver }) => {
189
- const boundary = paragraphPos + paragraph.nodeSize;
190
- const join = paragraphJoinAfter(tr.doc, boundary);
191
- if (!join || join.next !== next) panic("A paragraph-mark join lost its next paragraph");
192
- if (join.inlineBookmarks.length > 0) {
193
- const leftToken = getProseParagraphPropertySourceToken(paragraph);
194
- const rightToken = getProseParagraphPropertySourceToken(next);
195
- tr.replaceWith(boundary - 1, join.nextPosition + 1, join.inlineBookmarks);
196
- tr.setNodeMarkup(paragraphPos, void 0, joinedParagraphAttrs({
197
- paragraph,
198
- next,
199
- between: join.inlineBookmarks.reduce((size, node) => size + node.nodeSize, 0),
200
- styleResolver
201
- }));
202
- markParagraphPropertySourceTransfers(tr, [{
203
- displacedToken: typeof leftToken === "string" ? leftToken : null,
204
- selectedToken: typeof rightToken === "string" ? rightToken : null
205
- }]);
206
- } else joinProseParagraphsWithRightPropertySource({
207
- attrs: joinedParagraphAttrs({
208
- paragraph,
209
- next,
210
- styleResolver
211
- }),
212
- pos: boundary,
213
- transaction: tr
214
- });
215
- if (!styleResolver) return;
216
- if (paragraph.content.size > 0) rebaseParagraphRuns({
217
- previousContext: paragraphRunStyleContext(paragraph, styleResolver),
218
- paragraphPosition: paragraphPos,
219
- range: {
220
- from: 0,
221
- to: paragraph.content.size
222
- },
223
- styleResolver,
224
- tr
225
- });
226
- tr.setMeta(JOINED_RUNS_RESTYLED_META, true);
227
- };
228
- export { JOINED_PARAGRAPH_ATTR_NAMES, joinAtParagraphMark, joinedParagraphAttrs };
185
+ export { JOINED_PARAGRAPH_ATTR_NAMES, joinedParagraphAttrs };
@@ -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
- type RebaseParagraphRunFormattingOptions = {
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 };
@@ -87,18 +87,15 @@ export declare const NON_INCLUSIVE_MARK_DISPOSITION: {
87
87
  export declare const nonInclusiveMarkNames: (schema: Schema) => string[];
88
88
  /** One typed anchor for a comment authored as a point. */
89
89
  export declare const commentPoint: (schema: Schema, id: number) => Node;
90
- type ResolvedCommentPointsOptions = {
91
- doc: Node;
90
+ type ResolvedCommentPointCollectorOptions = {
92
91
  removes: (node: Node, position: number) => boolean;
93
92
  retiresStructure: (node: Node, position: number) => boolean;
94
93
  };
95
94
  /** The same collector serves standalone commands and the existing bulk walk. */
96
- export declare const createResolvedCommentPointCollector: ({ removes, retiresStructure }: Omit<ResolvedCommentPointsOptions, "doc">) => {
95
+ export declare const createResolvedCommentPointCollector: ({ removes, retiresStructure }: ResolvedCommentPointCollectorOptions) => {
97
96
  visit: (node: Node, position: number, previous?: Node) => boolean;
98
97
  finish: () => Map<number, number>;
99
98
  };
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
99
  export type ReplacedAnnotations = {
103
100
  /** Marks the replacement must carry, in document order. */
104
101
  carried: readonly Mark[];
@@ -173,15 +173,6 @@ const createResolvedCommentPointCollector = ({ removes, retiresStructure }) => {
173
173
  finish
174
174
  };
175
175
  };
176
- /** Ranged comments whose covered non-carrier content is removed by a resolution. */
177
- const resolvedCommentPoints = ({ doc, removes, retiresStructure }) => {
178
- const collector = createResolvedCommentPointCollector({
179
- removes,
180
- retiresStructure
181
- });
182
- doc.descendants((node, position, parent, index) => collector.visit(node, position, index > 0 ? parent?.maybeChild(index - 1) ?? void 0 : void 0));
183
- return collector.finish();
184
- };
185
176
  /** Anchors an edit must put back, and where relative to the replacement. */
186
177
  const ANCHOR_PLACEMENT = {
187
178
  [COMMENT_REFERENCE_NODE_NAME]: "after",
@@ -712,4 +703,4 @@ const inheritedReplacementMarks = (doc, from, to) => {
712
703
  const $from = doc.resolve(from);
713
704
  return (to === from ? $from.marks() : $from.marksAcross(doc.resolve(to))) ?? Mark.none;
714
705
  };
715
- export { NON_INCLUSIVE_MARK_DISPOSITION, addCarriedMarks, annotatedReplacement, commentPoint, commentsAcrossBlockBoundary, commentsForTrackedInsertion, commentsSpanningInsertion, createResolvedCommentPointCollector, hasReplacedAnnotations, inheritedReplacementMarks, joinCommentStretches, nonInclusiveMarkNames, placeTrackedInsertion, preservesReplacementCommentAlignment, resolvedCommentPoints, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations, surveyReplacedAnnotations };
706
+ export { NON_INCLUSIVE_MARK_DISPOSITION, addCarriedMarks, annotatedReplacement, commentPoint, commentsAcrossBlockBoundary, commentsForTrackedInsertion, commentsSpanningInsertion, createResolvedCommentPointCollector, hasReplacedAnnotations, inheritedReplacementMarks, joinCommentStretches, nonInclusiveMarkNames, placeTrackedInsertion, preservesReplacementCommentAlignment, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations, surveyReplacedAnnotations };
@@ -1,5 +1,13 @@
1
- import { PropertyRevisionKind } from "@stll/docx-core/model";
1
+ import { ParagraphMarkChange, ParagraphMarkChangeKind, PropertyRevisionKind } from "@stll/docx-core/model";
2
2
  import { Node } from "prosemirror-model";
3
+ export declare function isPPrMarkAttr(value: unknown): value is ParagraphMarkChange;
4
+ /**
5
+ * Whether the mark says the paragraph break was ADDED. A relocation's
6
+ * destination break was added exactly as an insertion's was, and its source
7
+ * break went exactly as a deletion's did; the kinds differ so a reader is told
8
+ * the two ends belong together, not because they resolve differently.
9
+ */
10
+ export declare const paragraphMarkWasAdded: (kind: ParagraphMarkChangeKind) => boolean;
3
11
  export declare const PROPERTY_REVISION_SITES: {
4
12
  readonly runPropertyChange: {
5
13
  readonly kind: "runPropertyChange";
@@ -1,5 +1,19 @@
1
1
  import { PARAGRAPH_MARK_CHANGE_KINDS } from "@stll/docx-core/model";
2
2
  // src/prosemirror/revisionCarriers.ts
3
+ function isPPrMarkAttr(value) {
4
+ if (typeof value !== "object" || value === null || !("kind" in value) || !("info" in value)) return false;
5
+ const { kind, info } = value;
6
+ if (!isParagraphMarkChangeKind(kind)) return false;
7
+ if (typeof info !== "object" || info === null) return false;
8
+ return "id" in info && typeof info.id === "number";
9
+ }
10
+ /**
11
+ * Whether the mark says the paragraph break was ADDED. A relocation's
12
+ * destination break was added exactly as an insertion's was, and its source
13
+ * break went exactly as a deletion's did; the kinds differ so a reader is told
14
+ * the two ends belong together, not because they resolve differently.
15
+ */
16
+ const paragraphMarkWasAdded = (kind) => kind === "ins" || kind === "moveTo";
3
17
  const PROPERTY_REVISION_SITES = {
4
18
  runPropertyChange: {
5
19
  kind: "runPropertyChange",
@@ -155,4 +169,4 @@ const getFolioNodeRevisionCarriers = (node, nodePos) => {
155
169
  }
156
170
  return carriers;
157
171
  };
158
- export { PROPERTY_REVISION_SITES, getFolioNodeRevisionCarriers, nodePropertyRevisionSites, propertyRevisionMetadata, propertyRevisionRecords };
172
+ export { PROPERTY_REVISION_SITES, getFolioNodeRevisionCarriers, isPPrMarkAttr, nodePropertyRevisionSites, paragraphMarkWasAdded, propertyRevisionMetadata, propertyRevisionRecords };
@@ -0,0 +1,32 @@
1
+ import { EditorState } from "prosemirror-state";
2
+ export type TableRowRevisionAttr = {
3
+ revisionId: number;
4
+ author?: string;
5
+ date?: string | null;
6
+ };
7
+ type TableCellRevisionAttr = {
8
+ kind: "ins" | "del";
9
+ info: {
10
+ revisionId: number;
11
+ };
12
+ } | {
13
+ kind: "merge";
14
+ info: {
15
+ revisionId: number;
16
+ };
17
+ verticalMerge?: "continue" | "rest";
18
+ verticalMergeOriginal?: "continue" | "rest";
19
+ };
20
+ export declare function isTableRowRevisionAttr(value: unknown): value is TableRowRevisionAttr;
21
+ export declare function isTableCellRevisionAttr(value: unknown): value is TableCellRevisionAttr;
22
+ /**
23
+ * Find the document range covered by all revision carriers with any of the
24
+ * given ids. Returns null when none are present (already accepted/rejected, or
25
+ * never existed). A replace operation typically passes two ids; standalone
26
+ * text, formatting, paragraph, section, and table revisions pass a single id.
27
+ */
28
+ export declare function findAIEditRevisionRange(state: EditorState, revisionIds: number | readonly number[]): {
29
+ from: number;
30
+ to: number;
31
+ } | null;
32
+ export {};
@@ -0,0 +1,76 @@
1
+ import { expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "./attrs/index.js";
2
+ import { enclosingRevisionIds } from "./contentControlRevisions.js";
3
+ import "./extensions/nodes/SdtExtension.js";
4
+ import { getFolioNodeRevisionCarriers } from "./revisionCarriers.js";
5
+ import { getTableCellMergeChange } from "./tableCellMergeRevision.js";
6
+ // src/prosemirror/revisionRangeQueries.ts
7
+ function isTableRowRevisionAttr(value) {
8
+ return typeof value === "object" && value !== null && "revisionId" in value && typeof value.revisionId === "number";
9
+ }
10
+ function isTableCellRevisionAttr(value) {
11
+ if (typeof value !== "object" || value === null || !("kind" in value) || !("info" in value)) return false;
12
+ if (value.kind !== "ins" && value.kind !== "del" && value.kind !== "merge") return false;
13
+ const info = value.info;
14
+ return typeof info === "object" && info !== null && "revisionId" in info && typeof info.revisionId === "number";
15
+ }
16
+ /**
17
+ * Find the document range covered by all revision carriers with any of the
18
+ * given ids. Returns null when none are present (already accepted/rejected, or
19
+ * never existed). A replace operation typically passes two ids; standalone
20
+ * text, formatting, paragraph, section, and table revisions pass a single id.
21
+ */
22
+ function findAIEditRevisionRange(state, revisionIds) {
23
+ const insertionType = state.schema.marks["insertion"];
24
+ const deletionType = state.schema.marks["deletion"];
25
+ const runPropertyChangeType = state.schema.marks["runPropertyChange"];
26
+ const idSet = new Set(typeof revisionIds === "number" ? [revisionIds] : revisionIds);
27
+ const range = {
28
+ from: null,
29
+ to: null
30
+ };
31
+ const includeRange = (from, to) => {
32
+ if (range.from === null || from < range.from) range.from = from;
33
+ if (range.to === null || to > range.to) range.to = to;
34
+ };
35
+ state.doc.descendants((node, pos) => {
36
+ for (const carrier of getFolioNodeRevisionCarriers(node, pos)) if (idSet.has(carrier.id)) includeRange(carrier.from, carrier.to);
37
+ if (node.type.name === "sdt" && enclosingRevisionIds(node).some((id) => idSet.has(id))) includeRange(pos, pos + node.nodeSize);
38
+ if (node.type.name === "tableRow") for (const attrName of ["trIns", "trDel"]) {
39
+ const marker = node.attrs[attrName];
40
+ if (isTableRowRevisionAttr(marker) && idSet.has(marker.revisionId)) {
41
+ includeRange(pos, pos + node.nodeSize);
42
+ return false;
43
+ }
44
+ }
45
+ if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
46
+ const marker = node.attrs["cellMarker"];
47
+ const hasDirectRevision = isTableCellRevisionAttr(marker) && idSet.has(marker.info.revisionId);
48
+ const continuationCells = node.attrs["_docxVMergeContinuationCells"];
49
+ const hasCollapsedRevision = Array.isArray(continuationCells) && continuationCells.some((cell) => {
50
+ const change = getTableCellMergeChange(cell);
51
+ return change !== null && idSet.has(change.info.id);
52
+ });
53
+ if (hasDirectRevision || hasCollapsedRevision) {
54
+ includeRange(pos, pos + node.nodeSize);
55
+ return false;
56
+ }
57
+ }
58
+ if (!node.isInline) return;
59
+ for (const mark of node.marks) {
60
+ if (mark.type === runPropertyChangeType && expectRunPropertyChangeMarkAttrs(mark).changes.some((change) => idSet.has(change.info.id))) {
61
+ includeRange(pos, pos + node.nodeSize);
62
+ break;
63
+ }
64
+ if ((mark.type === insertionType || mark.type === deletionType) && (idSet.has(expectTrackedChangeMarkAttrs(mark).revisionId) || (expectTrackedChangeMarkAttrs(mark)._docxRevisionAncestors ?? []).some((ancestor) => idSet.has(ancestor.revisionId)))) {
65
+ includeRange(pos, pos + node.nodeSize);
66
+ break;
67
+ }
68
+ }
69
+ });
70
+ if (range.from === null || range.to === null) return null;
71
+ return {
72
+ from: range.from,
73
+ to: range.to
74
+ };
75
+ }
76
+ export { findAIEditRevisionRange, isTableCellRevisionAttr, isTableRowRevisionAttr };
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Single source of truth shared by every place that must swap a run's live
5
5
  * formatting back to a previously recorded set: rejecting a `runPropertyChange`
6
- * (commands/comments.ts) and stripping a *suggested* `runPropertyChange` at the
6
+ * (the reference editor) and stripping a *suggested* `runPropertyChange` at the
7
7
  * serialization boundary (conversion/fromProseDoc.ts). Keeping one list makes
8
8
  * it structurally impossible for the two paths to drift and let a formatting
9
9
  * mark survive a revert.
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Single source of truth shared by every place that must swap a run's live
6
6
  * formatting back to a previously recorded set: rejecting a `runPropertyChange`
7
- * (commands/comments.ts) and stripping a *suggested* `runPropertyChange` at the
7
+ * (the reference editor) and stripping a *suggested* `runPropertyChange` at the
8
8
  * serialization boundary (conversion/fromProseDoc.ts). Keeping one list makes
9
9
  * it structurally impossible for the two paths to drift and let a formatting
10
10
  * mark survive a revert.