@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,29 +1,30 @@
1
1
  import { parseFolioDocumentOperationBatch } from "../document-operations.js";
2
2
  import { expectParagraphAttrs, expectTrackedChangeMarkAttrs } from "../prosemirror/attrs/index.js";
3
- import { getSuggestions, rejectEverySuggestion, rejectEverySuggestionMapped } from "../prosemirror/commands/comments.js";
3
+ import { storyConversionOptions } from "../prosemirror/conversion/storyConversionOptions.js";
4
+ import { toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
4
5
  import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
6
+ import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
7
+ import { getSuggestionRanges } from "../prosemirror/suggestionQueries.js";
5
8
  import { getFolioParaIdFromBlockId } from "../types/block-id.js";
6
9
  import { canonicalJson } from "../utils/canonicalJson.js";
7
10
  import { persistedBlock } from "./block-identity.js";
8
- import { buildCleanBlockText, isOmittedFromCleanView } from "./clean-text.js";
11
+ import { buildCleanBlockText, isOmittedFromSavedSuggestionText } from "./clean-text.js";
9
12
  import { noteReferenceOf } from "./note-references.js";
10
13
  import { createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, hashFolioAIBlockText, sourceDocumentOf } from "./snapshot.js";
11
14
  import { panic } from "better-result";
15
+ import { withoutPendingSuggestions } from "@stll/docx-core/ops";
12
16
  // src/ai-edits/pending-suggestions.ts
13
17
  const FOLIO_PENDING_SUGGESTION_VERSION = 1;
14
- /** Drop only comments attached to proposals that have not been accepted. */
15
- const withoutPendingSuggestionCommentMarks = (state, commentIds) => {
16
- if (commentIds.size === 0) return state;
17
- let transaction = state.tr;
18
- state.doc.descendants((node, position) => {
19
- for (const mark of node.marks) if (mark.type.name === "comment" && commentIds.has(mark.attrs["commentId"])) transaction = transaction.removeMark(position, position + node.nodeSize, mark);
20
- });
21
- return transaction.docChanged ? state.apply(transaction) : state;
22
- };
23
- /** The saved package's story, with all pending proposals removed. */
24
- const createPendingSuggestionSourceSnapshot = (state, commentIds) => {
25
- const source = withoutPendingSuggestionCommentMarks(rejectEverySuggestion(state), commentIds);
26
- return createFolioAIEditSnapshotWithStyleResolver(source.doc, getDocumentStyleResolver(source));
18
+ /** The main story a save writes, with pending proposals and their comments removed. */
19
+ const createPendingSuggestionSourceSnapshot = (document, commentIds) => {
20
+ const saved = withoutPendingSuggestions(document, { commentIds }).unwrap();
21
+ const { styles, theme, numbering } = saved.package;
22
+ const doc = toProseDoc(saved, storyConversionOptions({
23
+ styles,
24
+ theme,
25
+ numbering
26
+ }));
27
+ return createFolioAIEditSnapshotWithStyleResolver(doc, styles === void 0 ? null : createStyleResolver(styles));
27
28
  };
28
29
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29
30
  const operationBlockId = (operation) => {
@@ -129,28 +130,76 @@ const containerKey = ({ containerPath = [], table }) => canonicalJson({
129
130
  ]
130
131
  });
131
132
  const suggestionSnapshot = (state) => createFolioAIEditSnapshotWithStyleResolver(state.doc, getDocumentStyleResolver(state));
132
- /** `rejected` read as a snapshot, its paragraphs in the order a save lists them. */
133
- const settledSnapshot = ({ state }) => createFolioAIEditSnapshotWithStyleResolver(state.doc, getDocumentStyleResolver(state));
134
133
  /**
135
- * The paragraph at `paragraphStart` of the rejected story, as a save names
136
- * it: the saved package may name the paragraphs otherwise, and both read
137
- * alike. `null` when the save reads other text there.
134
+ * Native review names each surviving paragraph. Read its source segments in
135
+ * authored order and count what the saved story keeps. Verify the complete
136
+ * text against the saved projection before using offsets from any segment.
138
137
  */
139
- const savedParagraphAt = ({ rejected, settled, saved, paragraphStart }) => {
140
- const paragraph = rejected.state.doc.nodeAt(paragraphStart);
141
- const index = settled.blocks.findIndex(({ id }) => settled.anchors[id]?.from === paragraphStart);
142
- const block = index < 0 ? void 0 : saved.blocks[index];
143
- const anchor = block === void 0 ? void 0 : saved.anchors[block.id];
144
- if (paragraph === null || block === void 0 || anchor === void 0) return null;
145
- const clean = buildCleanBlockText(paragraph, paragraphStart, { fieldResults: "text" });
146
- if (anchor.text !== clean.text) return null;
147
- return {
148
- block,
149
- anchor,
150
- offsetAt: (position) => {
151
- const offset = clean.offsets.findIndex((at) => at >= position);
152
- return offset < 0 ? clean.text.length : offset;
138
+ const savedPositionMap = ({ state, saved, absorptions }) => {
139
+ const savedDoc = sourceDocumentOf(saved);
140
+ const owners = /* @__PURE__ */ new Map();
141
+ for (const block of saved.blocks) {
142
+ const anchor = saved.anchors[block.id];
143
+ if (anchor === void 0) continue;
144
+ const node = savedDoc.nodeAt(anchor.from);
145
+ if (node?.type.name !== "paragraph") continue;
146
+ const paraId = expectParagraphAttrs(node).paraId?.toUpperCase();
147
+ if (paraId) owners.set(paraId, owners.has(paraId) ? null : {
148
+ block,
149
+ anchor
150
+ });
151
+ }
152
+ const survivors = new Map(absorptions.map(({ absorbed, survivor }) => [absorbed.toUpperCase(), survivor.toUpperCase()]));
153
+ const segments = /* @__PURE__ */ new Map();
154
+ state.doc.descendants((node, start) => {
155
+ if (node.type.name !== "paragraph") return true;
156
+ const paraId = expectParagraphAttrs(node).paraId?.toUpperCase();
157
+ if (!paraId) return true;
158
+ const survivor = finalSurvivor(survivors, paraId);
159
+ if (!owners.get(survivor)) return true;
160
+ const { text, offsets } = buildCleanBlockText(node, start, {
161
+ fieldResults: "text",
162
+ view: "saved-without-suggestions"
163
+ });
164
+ const segment = {
165
+ start,
166
+ text,
167
+ offsets
168
+ };
169
+ const group = segments.get(survivor);
170
+ if (group === void 0) segments.set(survivor, [segment]);
171
+ else group.push(segment);
172
+ return true;
173
+ });
174
+ const verified = /* @__PURE__ */ new Map();
175
+ for (const [id, group] of segments) {
176
+ const paragraph = owners.get(id);
177
+ if (!paragraph || group.map(({ text }) => text).join("") !== paragraph.anchor.text) continue;
178
+ let offset = 0;
179
+ for (const segment of group) {
180
+ verified.set(segment.start, {
181
+ ...paragraph,
182
+ offset,
183
+ segment
184
+ });
185
+ offset += segment.text.length;
186
+ }
187
+ }
188
+ return (position) => {
189
+ const at = state.doc.resolve(position);
190
+ for (let depth = at.depth; depth > 0; depth--) {
191
+ if (at.node(depth).type.name !== "paragraph") continue;
192
+ const mapped = verified.get(at.before(depth));
193
+ if (mapped === void 0) return null;
194
+ const { segment, offset, block, anchor } = mapped;
195
+ const index = segment.offsets.findIndex((source) => source >= position);
196
+ return {
197
+ block,
198
+ anchor,
199
+ offset: offset + (index < 0 ? segment.text.length : index)
200
+ };
153
201
  }
202
+ return null;
154
203
  };
155
204
  };
156
205
  /**
@@ -161,7 +210,7 @@ const savedParagraphAt = ({ rejected, settled, saved, paragraphStart }) => {
161
210
  * `null` when the mark is gone, or stands in no saved paragraph or at its
162
211
  * edge.
163
212
  */
164
- const currentSplitRecord = ({ record, state, saved }) => {
213
+ const currentSplitRecord = ({ record, state, savedPosition }) => {
165
214
  const { operation, suggestionId, splitRevisionId } = record;
166
215
  if (operation.type !== "splitBlock" || splitRevisionId === void 0) return null;
167
216
  const ends = [];
@@ -174,19 +223,9 @@ const currentSplitRecord = ({ record, state, saved }) => {
174
223
  });
175
224
  const end = ends.at(0);
176
225
  if (end === void 0) return null;
177
- const rejected = rejectEverySuggestionMapped(state);
178
- const at = rejected.mapping.map(end, -1);
179
- const $at = rejected.state.doc.resolve(at);
180
- if ($at.parent.type.name !== "paragraph") return null;
181
- const paragraph = savedParagraphAt({
182
- rejected,
183
- settled: settledSnapshot(rejected),
184
- saved,
185
- paragraphStart: $at.before()
186
- });
226
+ const paragraph = savedPosition(end);
187
227
  if (paragraph === null) return null;
188
- const { block, anchor, offsetAt } = paragraph;
189
- const offset = offsetAt(at);
228
+ const { block, anchor, offset } = paragraph;
190
229
  if (offset === 0 || offset >= anchor.text.length) return null;
191
230
  return {
192
231
  ...record,
@@ -273,16 +312,10 @@ const proposedComment = (operation) => operation.type === "replaceBlock" || oper
273
312
  * `null` when the suggestion proposes something else too, or when its marks
274
313
  * are no ranges of text a save holds.
275
314
  */
276
- const currentTextRecords = ({ records, state, saved }) => {
315
+ const currentTextRecords = ({ records, state, savedPosition }) => {
277
316
  const [record] = records;
278
317
  if (record === void 0 || !records.every(({ operation }) => proposesText(operation))) return null;
279
318
  const { suggestionId } = record;
280
- const rejected = rejectEverySuggestionMapped(state);
281
- /** What a saved package holds of the node at `from` to `to`. */
282
- const savedNode = (from, to) => {
283
- const at = rejected.mapping.map(from, 1);
284
- return at < rejected.mapping.map(to, -1) ? rejected.state.doc.nodeAt(at) : null;
285
- };
286
319
  const pieces = [];
287
320
  state.doc.descendants((node, from) => {
288
321
  if (!node.isInline) return true;
@@ -301,22 +334,19 @@ const currentTextRecords = ({ records, state, saved }) => {
301
334
  });
302
335
  return false;
303
336
  });
304
- /** Where a piece starts once every proposal is rejected. */
305
- const savedStart = ({ from, owner }) => rejected.mapping.map(from, owner === "insertion" ? -1 : 1);
306
337
  /** The first and last of the suggestion's pieces in each saved paragraph. */
307
338
  const spans = /* @__PURE__ */ new Map();
308
339
  for (const [index, piece] of pieces.entries()) {
309
340
  if (piece.owner === null) continue;
310
- const $at = rejected.state.doc.resolve(savedStart(piece));
311
- if ($at.parent.type.name !== "paragraph") return null;
312
- const span = spans.get($at.before());
313
- if (span === void 0) spans.set($at.before(), {
341
+ const at = savedPosition(piece.from);
342
+ if (at === null) return null;
343
+ const span = spans.get(at.block.id);
344
+ if (span === void 0) spans.set(at.block.id, {
314
345
  first: index,
315
346
  last: index
316
347
  });
317
348
  else span.last = index;
318
349
  }
319
- const settled = settledSnapshot(rejected);
320
350
  const ids = records.map(({ operation }) => operation.id);
321
351
  const nextId = (position) => {
322
352
  const known = ids[position];
@@ -328,25 +358,22 @@ const currentTextRecords = ({ records, state, saved }) => {
328
358
  return id;
329
359
  };
330
360
  const current = [];
331
- for (const [paragraphStart, { first, last }] of spans) {
361
+ for (const { first, last } of spans.values()) {
332
362
  const start = pieces[first];
333
363
  const end = pieces[last];
334
- const paragraph = savedParagraphAt({
335
- rejected,
336
- settled,
337
- saved,
338
- paragraphStart
339
- });
340
- if (start === void 0 || end === void 0 || paragraph === null) return null;
341
- const { block, anchor, offsetAt } = paragraph;
342
- const from = offsetAt(savedStart(start));
343
- const to = Math.max(from, offsetAt(rejected.mapping.map(end.to, -1)));
364
+ if (start === void 0 || end === void 0) return null;
365
+ const fromPosition = savedPosition(start.from);
366
+ const toPosition = savedPosition(end.to);
367
+ if (fromPosition === null || toPosition === null || fromPosition.block.id !== toPosition.block.id) return null;
368
+ const { block, anchor, offset: from } = fromPosition;
369
+ const to = Math.max(from, toPosition.offset);
344
370
  let replace = "";
345
371
  for (const piece of pieces.slice(first, last + 1)) {
346
372
  if (piece.owner === "insertion") replace += piece.text;
347
373
  if (piece.owner !== null) continue;
348
- const kept = savedNode(piece.from, piece.to);
349
- if (kept === null || isOmittedFromCleanView(kept)) continue;
374
+ const kept = state.doc.nodeAt(piece.from);
375
+ if (kept === null || isOmittedFromSavedSuggestionText(kept)) continue;
376
+ if (savedPosition(piece.from)?.block.id !== block.id) continue;
350
377
  if (!kept.isText || noteReferenceOf(kept) !== null) return null;
351
378
  replace += piece.text;
352
379
  }
@@ -543,7 +570,7 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
543
570
  * places is retired ({@link retiredRecord}): no record restages on a
544
571
  * removed or absorbed paragraph. Run after the change publishes.
545
572
  */
546
- placeRemovedAnchors({ activeSuggestionIds, stateForStory, savedSource }) {
573
+ placeRemovedAnchors({ activeSuggestionIds, stateForStory, savedSource, absorptionsForStory }) {
547
574
  const views = /* @__PURE__ */ new Map();
548
575
  for (const [key, record] of Array.from(this.records)) {
549
576
  const { suggestionId, story, anchor } = record;
@@ -559,13 +586,18 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
559
586
  views.set(storyKey, view);
560
587
  }
561
588
  if (view === null || view.live.anchors[anchor.paraId] !== void 0) continue;
562
- if (view.saved === void 0) view.saved = savedSource?.(story) ?? null;
589
+ if (view.saved === void 0) view.saved = savedSource(story);
563
590
  const saved = view.saved;
564
591
  if (saved !== null && (record.splitRevisionId !== void 0 || proposesText(record.operation))) {
592
+ const savedPosition = view.savedPosition ??= savedPositionMap({
593
+ state: view.state,
594
+ saved,
595
+ absorptions: absorptionsForStory?.(story) ?? []
596
+ });
565
597
  const split = currentSplitRecord({
566
598
  record,
567
599
  state: view.state,
568
- saved
600
+ savedPosition
569
601
  });
570
602
  if (split !== null) {
571
603
  this.records.set(key, split);
@@ -575,7 +607,7 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
575
607
  const texts = currentTextRecords({
576
608
  records: entries.map(([, other]) => other),
577
609
  state: view.state,
578
- saved
610
+ savedPosition
579
611
  });
580
612
  if (texts !== null) {
581
613
  for (const [other] of entries) this.records.delete(other);
@@ -583,12 +615,11 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
583
615
  continue;
584
616
  }
585
617
  }
586
- const ranges = getSuggestions(view.state).find((entry) => entry.suggestionId === suggestionId)?.ranges ?? [];
587
- const placed = placedRecord({
618
+ const placed = saved === null ? null : placedRecord({
588
619
  record,
589
620
  live: view.live,
590
- saved: saved ?? createPendingSuggestionSourceSnapshot(view.state, /* @__PURE__ */ new Set()),
591
- ranges
621
+ saved,
622
+ ranges: getSuggestionRanges(view.state, suggestionId)
592
623
  });
593
624
  this.records.set(key, placed ?? retiredRecord(record));
594
625
  }
@@ -690,10 +721,11 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
690
721
  activeSuggestionIds
691
722
  });
692
723
  }
693
- exportPendingSuggestions({ activeSuggestionIds, snapshotForStory, stateForStory }) {
724
+ exportPendingSuggestions({ activeSuggestionIds, snapshotForStory, stateForStory, absorptionsForStory }) {
694
725
  const pending = [];
695
726
  const savedStories = /* @__PURE__ */ new Map();
696
727
  const liveStories = /* @__PURE__ */ new Map();
728
+ const savedPositions = /* @__PURE__ */ new Map();
697
729
  const commentIdsByStory = /* @__PURE__ */ new Map();
698
730
  for (const record of this.records.values()) {
699
731
  if (!activeSuggestionIds.has(record.suggestionId) || record.commentId === void 0) continue;
@@ -725,7 +757,8 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
725
757
  if (stateForStory !== void 0) this.placeRemovedAnchors({
726
758
  activeSuggestionIds,
727
759
  stateForStory: liveStateOf,
728
- savedSource: (story) => savedStoryOf(story)?.snapshot ?? null
760
+ savedSource: (story) => savedStoryOf(story)?.snapshot ?? null,
761
+ ...absorptionsForStory === void 0 ? {} : { absorptionsForStory }
729
762
  });
730
763
  for (const [key, record] of this.records) if (activeSuggestionIds.has(record.suggestionId)) {
731
764
  const saved = savedStoryOf(record.story);
@@ -733,11 +766,23 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
733
766
  let updated = record;
734
767
  if (record.splitRevisionId !== void 0) {
735
768
  const state = liveStateOf(record.story);
736
- if (state !== null) updated = currentSplitRecord({
737
- record,
738
- state,
739
- saved: saved.snapshot
740
- }) ?? record;
769
+ if (state !== null) {
770
+ const storyKey = canonicalJson(record.story);
771
+ let savedPosition = savedPositions.get(storyKey);
772
+ if (savedPosition === void 0) {
773
+ savedPosition = savedPositionMap({
774
+ state,
775
+ saved: saved.snapshot,
776
+ absorptions: absorptionsForStory?.(record.story) ?? []
777
+ });
778
+ savedPositions.set(storyKey, savedPosition);
779
+ }
780
+ updated = currentSplitRecord({
781
+ record,
782
+ state,
783
+ savedPosition
784
+ }) ?? record;
785
+ }
741
786
  }
742
787
  const current = {
743
788
  ...updated,
@@ -860,4 +905,4 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
860
905
  });
861
906
  }
862
907
  };
863
- export { FOLIO_PENDING_SUGGESTION_VERSION, FolioPendingSuggestionRegistry, createPendingSuggestionSourceSnapshot, withoutPendingSuggestionCommentMarks };
908
+ export { FOLIO_PENDING_SUGGESTION_VERSION, FolioPendingSuggestionRegistry, createPendingSuggestionSourceSnapshot };
@@ -158,7 +158,11 @@ export type PendingMarkEditOptions = {
158
158
  /** The paragraph's accepted reading. */
159
159
  cleanText: string;
160
160
  };
161
- /** The shared property boundary, independent of the paragraph's representation. */
161
+ /**
162
+ * The shared property boundary, independent of the paragraph's
163
+ * representation: any mark accepting removes, including one added and then
164
+ * deleted by another author, takes the edited properties with it.
165
+ */
162
166
  export declare const pendingParagraphPropertiesRefusal: (mark: unknown) => PendingRefusal | undefined;
163
167
  /**
164
168
  * The refusal an operation that places no block meets on a paragraph whose
@@ -262,8 +262,12 @@ const pendingMarkEditOf = (type) => {
262
262
  if (type === "replaceBlock") return "wholeText";
263
263
  return "inline";
264
264
  };
265
- /** The shared property boundary, independent of the paragraph's representation. */
266
- const pendingParagraphPropertiesRefusal = (mark) => isDeletedPPrMark(mark) ? PENDING_PARAGRAPH_MARK_PROPERTY_REFUSAL : void 0;
265
+ /**
266
+ * The shared property boundary, independent of the paragraph's
267
+ * representation: any mark accepting removes, including one added and then
268
+ * deleted by another author, takes the edited properties with it.
269
+ */
270
+ const pendingParagraphPropertiesRefusal = (mark) => markGoesWhenAccepted(mark) ? PENDING_PARAGRAPH_MARK_PROPERTY_REFUSAL : void 0;
267
271
  /**
268
272
  * The refusal an operation that places no block meets on a paragraph whose
269
273
  * mark is pending deletion, by the rules the default engine applies: its
@@ -2,6 +2,7 @@ import { expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedCh
2
2
  import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
3
3
  import { expandRunFormattingCarrier, runFormattingCarrierReviewText, runFormattingInlineAtomCleanText, runFormattingInlineAtomDisposition, runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
4
4
  import { getTableCellMergeChange } from "../prosemirror/tableCellMergeRevision.js";
5
+ import { isTableRowRevisionCompanion } from "../prosemirror/tableRowRevisionOwnership.js";
5
6
  import { enclosingInsertionAncestors, trackedRevisionLayerOf } from "../prosemirror/trackedRevisionPath.js";
6
7
  import { commentAnchorIdsForNode } from "./comment-lifecycle.js";
7
8
  import { readerTextOf } from "./note-references.js";
@@ -64,7 +65,6 @@ const firstBlockIdWithin = ({ node, nodePos, blockStarts }) => {
64
65
  });
65
66
  return blockId;
66
67
  };
67
- const belongsToRowRevision = (scope, revision) => revision.id === scope.change.id || revision.author === scope.change.author && revision.date === scope.change.date;
68
68
  /**
69
69
  * The paragraph-mark revision a marked row writes on its cells' paragraphs:
70
70
  * a row deletion deletes each cell paragraph's mark with it, an insertion
@@ -207,7 +207,10 @@ const getTrackedChangeGroupsFromProjectedDoc = (doc, blockStarts, revisionRanges
207
207
  to: carrier.to
208
208
  });
209
209
  const rowScope = rowRevisionScopes.at(-1);
210
- if (rowScope !== void 0 && ROW_PARAGRAPH_MARK_CARRIERS[rowScope.kind] === carrier.type && belongsToRowRevision(rowScope, carrier)) {
210
+ if (rowScope !== void 0 && ROW_PARAGRAPH_MARK_CARRIERS[rowScope.kind] === carrier.type && isTableRowRevisionCompanion({
211
+ row: rowScope.change,
212
+ candidate: carrier
213
+ })) {
211
214
  fold(rowScope.key, [carrier.id]);
212
215
  return;
213
216
  }
@@ -430,7 +433,10 @@ const getTrackedChangeGroupsFromProjectedDoc = (doc, blockStarts, revisionRanges
430
433
  for (const [layerIndex, { kind: layerKind, revision }] of layers.entries()) {
431
434
  if (deletedFieldScopes.some(({ layers: enclosingLayers }) => enclosingLayers.some((layer) => layer.kind === layerKind && layer.revision.id === revision.id))) continue;
432
435
  const rowScope = rowRevisionScopes.at(-1);
433
- if (rowScope?.kind === layerKind && belongsToRowRevision(rowScope, revision)) {
436
+ if (rowScope?.kind === layerKind && isTableRowRevisionCompanion({
437
+ row: rowScope.change,
438
+ candidate: revision
439
+ })) {
434
440
  fold(rowScope.key, [revision.id]);
435
441
  continue;
436
442
  }
@@ -12,8 +12,8 @@ type RetiredCommentReceiptsOptions = {
12
12
  operations: readonly Pick<FolioAIEditOperation, "id" | "type">[];
13
13
  /** Canonical inline changes can relocate markers before later steps run. */
14
14
  sourceRanges?: ReadonlyMap<string, readonly TextSpan[]>;
15
- /** Canonical review can supply its accepted package projection. */
16
- acceptedCommentIds?: (side: "before" | "after") => ReadonlySet<number> | null;
15
+ /** Anchors in the accepted story on either side of the batch. */
16
+ acceptedCommentIds: (side: "before" | "after") => ReadonlySet<number> | null;
17
17
  };
18
18
  /** Report full anchor removal only where one operation owns the deletion. */
19
19
  export declare const addRetiredCommentReceipts: ({ before, after, applied, operations, sourceRanges, acceptedCommentIds }: RetiredCommentReceiptsOptions) => void;
@@ -1,11 +1,6 @@
1
- import { acceptAllChanges, rejectEverySuggestion } from "../prosemirror/commands/comments.js";
2
- import { createDocumentNumberingPlugin, getStatedDocumentNumbering } from "../prosemirror/plugins/documentNumbering.js";
3
- import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
4
- import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documentStyles.js";
5
1
  import { isZeroWidthAnchor } from "../prosemirror/zeroWidthAnchors.js";
6
- import { anchoredCommentIdsInProseDoc, commentAnchorIdsForNode, coveredCommentIdsInProseDoc, isCommentAnchorCarrier } from "./comment-lifecycle.js";
2
+ import { commentAnchorIdsForNode, coveredCommentIdsInProseDoc, isCommentAnchorCarrier } from "./comment-lifecycle.js";
7
3
  import { comparisonApplying } from "./note-references.js";
8
- import { EditorState } from "prosemirror-state";
9
4
  // src/ai-edits/retired-comment-receipts.ts
10
5
  const deletionOperations = /* @__PURE__ */ new Set([
11
6
  "deleteBlock",
@@ -26,16 +21,6 @@ const deletedParagraphMark = (node) => {
26
21
  const marker = node.attrs["pPrMark"];
27
22
  return objectAttr(marker, "kind") === "del" ? objectAttr(marker, "info") : void 0;
28
23
  };
29
- const acceptedComments = (before, doc) => {
30
- const state = rejectEverySuggestion(EditorState.create({
31
- doc,
32
- plugins: [createDocumentNumberingPlugin(getStatedDocumentNumbering(before)), createDocumentStyleContextPlugin(getDocumentStyleResolver(before))]
33
- }));
34
- let accepted = state.doc;
35
- return acceptAllChanges()(state, (transaction) => {
36
- accepted = transaction.doc;
37
- }) ? anchoredCommentIdsInProseDoc(accepted) : null;
38
- };
39
24
  const candidatesOf = (coverage) => [...coverage].flatMap(([commentId, owner]) => owner === null ? [] : [{
40
25
  commentId,
41
26
  owner
@@ -147,8 +132,8 @@ const addRetiredCommentReceipts = ({ before, after, applied, operations, sourceR
147
132
  const covering = candidates.filter(({ commentId, owner }) => ownsOriginalCoverage(commentId, owner));
148
133
  const owned = covering.filter(({ commentId }) => !foldedComments.has(commentId) || covering.filter((candidate) => candidate.commentId === commentId).length === 1);
149
134
  if (owned.length === 0) return;
150
- const originallyAccepted = acceptedCommentIds ? acceptedCommentIds("before") : acceptedComments(before, before.doc);
151
- const finallyAccepted = acceptedCommentIds ? acceptedCommentIds("after") : acceptedComments(before, after);
135
+ const originallyAccepted = acceptedCommentIds("before");
136
+ const finallyAccepted = acceptedCommentIds("after");
152
137
  if (originallyAccepted === null || finallyAccepted === null) return;
153
138
  const byOperation = /* @__PURE__ */ new Map();
154
139
  for (const { commentId, owner } of owned) {
@@ -1,15 +1,13 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { EditorState } from "prosemirror-state";
3
- import { Node } from "prosemirror-model";
4
- type TrackedBatchFidelityOptions = {
5
- before: EditorState;
6
- after: Node;
7
- createdCommentIds: readonly number[];
8
- retiredCommentIds?: readonly number[];
9
- };
10
2
  declare const protectionKinds: readonly ["note", "drawing", "field", "comment"];
11
3
  type ProtectionKind = (typeof protectionKinds)[number];
12
4
  export type Inventory = Record<ProtectionKind, Map<string, number>>;
5
+ /**
6
+ * The protected content `after` holds as a pending deletion and `before` did
7
+ * not: an edit the reviewer sees as deleted, which Accept All may remove.
8
+ */
9
+ export declare const newlyDeletedProtectedContent: (before: Inventory, after: Inventory) => Inventory;
10
+ export declare const missingProtectedContent: (expected: Inventory, actual: Inventory, retiredCommentIds: readonly number[], deleted?: Inventory) => ProtectionKind | null;
13
11
  export declare const sameOriginalBlocks: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[], addedCommentIds: ReadonlySet<number>) => boolean;
14
12
  /**
15
13
  * The protected content the edited blocks hold as a new tracked deletion,
@@ -18,6 +16,4 @@ export declare const sameOriginalBlocks: (before: readonly document_d_exports.Bl
18
16
  export declare const newlyDeletedProtectedBlocks: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[]) => Inventory;
19
17
  /** The kind of protected content missing from the accepted blocks. */
20
18
  export declare const missingProtectedBlockKind: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[], retiredCommentIds?: readonly number[], deleted?: Inventory) => ProtectionKind | null;
21
- /** Check both clean readings before any tracked batch can publish its changes. */
22
- export declare const trackedBatchFidelityError: (options: TrackedBatchFidelityOptions) => string | null;
23
19
  export {};