@stll/folio-core 0.75.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/ai-edits/headless.d.ts +8 -5
  2. package/dist/ai-edits/headless.js +49 -26
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +13 -3
  5. package/dist/ai-edits/read.js +33 -4
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/ai-edits/types.d.ts +9 -4
  8. package/dist/canonical/batchCommentReferences.js +2 -1
  9. package/dist/canonical/canonicalBatchReview.js +5 -8
  10. package/dist/canonical/canonicalComments.js +8 -2
  11. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  12. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  13. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  14. package/dist/canonical/canonicalInlineProjection.js +2 -2
  15. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  16. package/dist/canonical/canonicalPublicOperations.js +214 -107
  17. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  18. package/dist/canonical/canonicalSeedContent.js +28 -15
  19. package/dist/canonical/canonicalSession.d.ts +22 -12
  20. package/dist/canonical/canonicalSession.js +181 -187
  21. package/dist/controller/canonicalClipboard.d.ts +3 -2
  22. package/dist/controller/canonicalClipboard.js +377 -58
  23. package/dist/controller/canonicalComposition.js +67 -14
  24. package/dist/controller/canonicalContentControlValue.js +7 -7
  25. package/dist/controller/canonicalReview.d.ts +21 -0
  26. package/dist/controller/canonicalReview.js +44 -9
  27. package/dist/controller/canonicalStoryEditor.js +2 -0
  28. package/dist/controller/canonicalStructure.d.ts +1 -2
  29. package/dist/controller/canonicalStructure.js +51 -24
  30. package/dist/controller/fontReadiness.js +50 -23
  31. package/dist/controller/hiddenEditorManager.js +7 -20
  32. package/dist/docx/bulletMarkers.d.ts +8 -0
  33. package/dist/docx/bulletMarkers.js +9 -1
  34. package/dist/docx/canonicalSessionInput.js +25 -11
  35. package/dist/docx/ensureParaIds.d.ts +31 -0
  36. package/dist/docx/ensureParaIds.js +57 -32
  37. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  38. package/dist/docx/ensureUniqueControlIds.js +47 -29
  39. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  40. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  41. package/dist/docx/importedIdCollisions.js +29 -4
  42. package/dist/docx/server/templatePlan/apply.js +108 -9
  43. package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
  44. package/dist/docx/server/templatePlan/blocks.js +281 -14
  45. package/dist/docx/server/templatePlan/builders.d.ts +22 -1
  46. package/dist/docx/server/templatePlan/builders.js +37 -3
  47. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  48. package/dist/docx/server/templatePlan/effects.js +188 -0
  49. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  50. package/dist/docx/server/templatePlan/emit.js +152 -8
  51. package/dist/docx/server/templatePlan/inspect.js +21 -1
  52. package/dist/docx/server/templatePlan/labels.js +16 -1
  53. package/dist/docx/server/templatePlan/plan.d.ts +35 -3
  54. package/dist/docx/server/templatePlan/plan.js +197 -20
  55. package/dist/docx/server/templatePlan/planShape.js +58 -22
  56. package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
  57. package/dist/docx/server/templatePlan/revisions.js +681 -0
  58. package/dist/docx/server/templatePlan/story.d.ts +61 -2
  59. package/dist/docx/server/templatePlan/story.js +175 -13
  60. package/dist/docx/server/templatePlan/types.d.ts +313 -1
  61. package/dist/docx/server/templatePlan/verify.js +175 -12
  62. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  63. package/dist/docx/server/templatePlan/xml.js +4 -1
  64. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  65. package/dist/docx/tableGridXml.d.ts +3 -7
  66. package/dist/docx/tableGridXml.js +5 -13
  67. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  68. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  69. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  70. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  71. package/dist/prosemirror/canonicalTableCommands.js +1 -3
  72. package/dist/prosemirror/commands/comments.d.ts +6 -234
  73. package/dist/prosemirror/commands/comments.js +5 -2464
  74. package/dist/prosemirror/commands/index.d.ts +4 -2
  75. package/dist/prosemirror/commands/index.js +4 -2
  76. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  77. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  78. package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
  79. package/dist/prosemirror/conversion/toProseDoc.js +31 -14
  80. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  81. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  82. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  83. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  84. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  85. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  86. package/dist/prosemirror/markupViewNotes.js +24 -27
  87. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  88. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  89. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  90. package/dist/prosemirror/markupViewProjection.js +90 -17
  91. package/dist/prosemirror/paraIds.d.ts +1 -14
  92. package/dist/prosemirror/paraIds.js +1 -14
  93. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  94. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  95. package/dist/prosemirror/projectionReview.d.ts +49 -0
  96. package/dist/prosemirror/projectionReview.js +292 -0
  97. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  98. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  99. package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
  100. package/dist/prosemirror/replacedAnnotations.js +11 -203
  101. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  102. package/dist/prosemirror/revisionCarriers.js +15 -1
  103. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  104. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  105. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  106. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  107. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  108. package/dist/prosemirror/styles/styleResolver.js +4 -1
  109. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  110. package/dist/prosemirror/suggestionQueries.js +320 -0
  111. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  112. package/dist/prosemirror/tableGridMutation.js +1 -78
  113. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  114. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  115. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  116. package/dist/server.d.ts +2 -2
  117. package/dist/types/canonicalCapabilities.d.ts +4 -35
  118. package/dist/types/canonicalCapabilities.js +4 -33
  119. package/package.json +2 -2
  120. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  121. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
  122. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  123. package/dist/internal/revisionResolutionEdits.js +0 -18
  124. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  125. package/dist/internal/revisionResolutionInline.js +0 -302
  126. package/dist/internal/revisionResolutionStep.d.ts +0 -32
  127. package/dist/internal/revisionResolutionStep.js +0 -282
  128. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  129. package/dist/internal/revisionResolutionTracking.js +0 -124
  130. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  131. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  132. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  133. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  134. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  135. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  136. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
  137. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
  138. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  139. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  140. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  141. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  142. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  143. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -1,4 +1,4 @@
1
- import { commentAnchorIdsForNode, isCommentAnchorCarrier } from "../ai-edits/comment-lifecycle.js";
1
+ import { isCommentAnchorCarrier } from "../ai-edits/comment-lifecycle.js";
2
2
  import { minOf } from "../utils/extremes.js";
3
3
  import { expectParagraphAttrs, expectTableCellAttrs, expectTableRowAttrs } from "./attrs/index.js";
4
4
  import { expectCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
@@ -11,8 +11,7 @@ import { TEXT_BOX_ANCHOR_NODE_NAME } from "./extensions/nodes/TextBoxAnchorExten
11
11
  import { readMoveRangeBoundaryAttrs } from "./moveRangeBoundaryAttrs.js";
12
12
  import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
13
13
  import { isZeroWidthAnchor } from "./zeroWidthAnchors.js";
14
- import { panic } from "better-result";
15
- import { isCommentExhausted, withoutCommentThreads } from "@stll/docx-core/ops";
14
+ import { isCommentExhausted } from "@stll/docx-core/ops";
16
15
  import { Fragment, Mark } from "prosemirror-model";
17
16
  // src/prosemirror/replacedAnnotations.ts
18
17
  /**
@@ -34,9 +33,9 @@ import { Fragment, Mark } from "prosemirror-model";
34
33
  * span. It can propose a point at the replacement start for an emptied range;
35
34
  * downstream ranged-comment exhaustion may retire that comment. The applier
36
35
  * decides alignment once for direct and tracked edits.
37
- * Canonical replacements accept only coverage the source anchors already
38
- * express. Pure deletion follows ranged-comment exhaustion; unproven point
39
- * transitions refuse before mutation.
36
+ * Canonical replacements place comment anchors by the docx-core policy
37
+ * beside `rangeEndAfterDeletion`: markers inside the replaced words stay,
38
+ * in order, before the new words, and a range left covering nothing goes.
40
39
  *
41
40
  * - `comment` mark: carried over its aligned replacement span.
42
41
  * - `hyperlink` mark: the replacement carries the first link the span held, so
@@ -76,8 +75,7 @@ import { Fragment, Mark } from "prosemirror-model";
76
75
  * already gives the replacement the formatting of the text it replaces.
77
76
  *
78
77
  * Removing the owning block removes its comment. Point anchors proposed by
79
- * the alignment helper do not override ranged-comment retirement; the
80
- * canonical guard refuses point transitions whose outcome is not proven.
78
+ * the alignment helper do not override ranged-comment retirement.
81
79
  */
82
80
  /**
83
81
  * What a replacement does with each mark the schema declares
@@ -173,15 +171,6 @@ const createResolvedCommentPointCollector = ({ removes, retiresStructure }) => {
173
171
  finish
174
172
  };
175
173
  };
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
174
  /** Anchors an edit must put back, and where relative to the replacement. */
186
175
  const ANCHOR_PLACEMENT = {
187
176
  [COMMENT_REFERENCE_NODE_NAME]: "after",
@@ -212,7 +201,7 @@ const lendsMarks = (node, content) => {
212
201
  default: throw new Error(`Unhandled replaced content ${String(content)}`);
213
202
  }
214
203
  };
215
- const surveyAnnotations = (doc, { from, to, content, containers }) => {
204
+ const surveyAnnotations = (doc, { from, to, content }) => {
216
205
  if (to <= from) return NOTHING_REPLACED;
217
206
  const carried = [];
218
207
  const leading = [];
@@ -221,7 +210,7 @@ const surveyAnnotations = (doc, { from, to, content, containers }) => {
221
210
  if (!node.isInline) return true;
222
211
  for (const mark of lendsMarks(node, content) ? node.marks : []) if (isCarried(mark) && !alreadyCarried(mark, carried)) carried.push(mark);
223
212
  const placement = anchorPlacement(node);
224
- if (placement === void 0 || position < from || position + node.nodeSize > to) return containers === "descend" && !node.isLeaf && lendsMarks(node, content);
213
+ if (placement === void 0 || position < from || position + node.nodeSize > to) return false;
225
214
  (opensRange(node, placement) ? leading : trailing).push(node);
226
215
  return false;
227
216
  });
@@ -239,8 +228,7 @@ const surveyAnnotations = (doc, { from, to, content, containers }) => {
239
228
  const surveyReplacedAnnotations = (doc, from, to) => surveyAnnotations(doc, {
240
229
  from,
241
230
  to,
242
- content: "asWritten",
243
- containers: "preserve"
231
+ content: "asWritten"
244
232
  });
245
233
  /**
246
234
  * {@link surveyReplacedAnnotations} over the span as it reads once accepted:
@@ -250,189 +238,9 @@ const surveyReplacedAnnotations = (doc, from, to) => surveyAnnotations(doc, {
250
238
  const surveyAcceptedReplacedAnnotations = (doc, from, to) => surveyAnnotations(doc, {
251
239
  from,
252
240
  to,
253
- content: "asAccepted",
254
- containers: "preserve"
241
+ content: "asAccepted"
255
242
  });
256
243
  /**
257
- * A walker over the accepted leaves that carry words, handing each one's
258
- * ranged comment ids and extent to `visit`.
259
- */
260
- const rangedCommentLeaves = (visit) => (node, position) => {
261
- if (!node.isInline) return true;
262
- if (!node.isLeaf) return lendsMarks(node, "asAccepted");
263
- if (isZeroWidthAnchor(node) || !lendsMarks(node, "asAccepted")) return false;
264
- const ids = [];
265
- for (const mark of node.marks) {
266
- const id = mark.attrs["commentId"];
267
- if (mark.type.name === "comment" && mark.attrs["point"] !== true && typeof id === "number") ids.push(id);
268
- }
269
- visit(ids, position, position + node.nodeSize);
270
- return false;
271
- };
272
- /**
273
- * Whether every word each of `ids` covers lies inside a change, so that
274
- * accepting the tracked replacement leaves those comments nothing to cover.
275
- */
276
- const coveredOnlyInside = ({ doc, changes, ids }) => {
277
- let outside = false;
278
- doc.descendants(rangedCommentLeaves((leafIds, from, to) => {
279
- if (!changes.some((change) => change.from <= from && to <= change.to) && leafIds.some((id) => ids.has(id))) outside = true;
280
- }));
281
- return !outside;
282
- };
283
- /**
284
- * The comment threads a direct replacement takes with its words: each root
285
- * whose every accepted covered word lies inside a change, with its replies.
286
- * Accepting the tracked replacement leaves such a root nothing to cover, so
287
- * it drops the same threads.
288
- */
289
- const threadsTakenBy = ({ doc, changes, comments }) => {
290
- const inside = (from, to) => changes.some((change) => change.from <= from && to <= change.to);
291
- const candidates = /* @__PURE__ */ new Set();
292
- for (const change of changes) doc.nodesBetween(change.from, change.to, rangedCommentLeaves((ids, from, to) => {
293
- if (inside(from, to)) for (const id of ids) candidates.add(id);
294
- }));
295
- if (candidates.size === 0) return candidates;
296
- const surviving = /* @__PURE__ */ new Set();
297
- doc.descendants(rangedCommentLeaves((ids, from, to) => {
298
- if (!inside(from, to)) for (const id of ids) surviving.add(id);
299
- }));
300
- const roots = new Set(comments.filter(({ id, parentId }) => parentId === void 0 && candidates.has(id) && !surviving.has(id)).map(({ id }) => id));
301
- if (roots.size === 0) return roots;
302
- const kept = new Set(withoutCommentThreads(comments, roots).map(({ id }) => id));
303
- return new Set(comments.filter(({ id }) => !kept.has(id)).map(({ id }) => id));
304
- };
305
- /**
306
- * A direct replacement's changes cut at each boundary of a comment it keeps
307
- * that stands inside a changed stretch: the words before the boundary go, and
308
- * the new words follow every such boundary, where accepting the tracked
309
- * replacement leaves them. A range ending in the stretch ends before the new
310
- * words; one starting in it holds them.
311
- */
312
- const splitAtKeptCommentBoundaries = ({ doc, changes, comments }) => {
313
- const retired = threadsTakenBy({
314
- doc,
315
- changes,
316
- comments
317
- });
318
- const split = [];
319
- for (const change of changes) {
320
- const cuts = [];
321
- doc.nodesBetween(change.from, change.to, (node, position) => {
322
- if (isCommentAnchorCarrier(node) && change.from < position && position < change.to && commentAnchorIdsForNode(node).some((id) => !retired.has(id)) && cuts.at(-1) !== position) cuts.push(position);
323
- return !node.isLeaf && lendsMarks(node, "asAccepted");
324
- });
325
- let from = change.from;
326
- for (const cut of cuts) {
327
- split.push({
328
- ...change,
329
- from,
330
- to: cut,
331
- text: ""
332
- });
333
- from = cut;
334
- }
335
- split.push({
336
- ...change,
337
- from
338
- });
339
- }
340
- return {
341
- changes: split,
342
- retiredCommentIds: retired
343
- };
344
- };
345
- /**
346
- * Whether source boundaries already express the replacement's aligned ranges.
347
- * A changed stretch lends no comment to its replacement: the new words go
348
- * past the end of every range the stretch reaches, and a direct replacement
349
- * takes every thread it leaves nothing to cover. Pure deletions within
350
- * surviving source content follow the ranged-comment exhaustion owner; other
351
- * collapses need a point policy. Decide over the whole replacement, before
352
- * any of its fragments are applied.
353
- */
354
- const preservesReplacementCommentAlignment = ({ doc, source, changes, retiredCommentIds, removal }) => {
355
- let previousEnd = source.from;
356
- for (const change of changes) {
357
- if (change.from < previousEnd || change.to < change.from || change.to > source.to) panic("Replacement changes must be ordered inside their source coverage.");
358
- previousEnd = change.to;
359
- }
360
- const retired = new Set(retiredCommentIds);
361
- if (removal.type === "direct") for (const id of threadsTakenBy({
362
- doc,
363
- changes,
364
- comments: removal.comments
365
- })) retired.add(id);
366
- const collapsing = [];
367
- const continued = [];
368
- for (const change of changes) {
369
- const comments = surveyAnnotations(doc, {
370
- from: change.from,
371
- to: change.to,
372
- content: "asAccepted",
373
- containers: "descend"
374
- }).carried.filter((mark) => mark.type.name === "comment" && !retired.has(mark.attrs["commentId"]));
375
- if (comments.some((mark) => mark.attrs["point"] === true)) return false;
376
- if (change.markers === "selected" && comments.length > 0 && (removal.type === "direct" || !doc.resolve(change.from).sameParent(doc.resolve(change.to)) || !coveredOnlyInside({
377
- doc,
378
- changes,
379
- ids: new Set(comments.map((mark) => Number(mark.attrs["commentId"])))
380
- }))) return false;
381
- if (removal.type === "tracked") continue;
382
- let internalCarrier = false;
383
- doc.nodesBetween(change.from, change.to, (node, position) => {
384
- if (isCommentAnchorCarrier(node) && change.from < position && position < change.to) {
385
- const ids = commentAnchorIdsForNode(node);
386
- if (ids.length === 0 || ids.some((id) => !retired.has(id))) internalCarrier = true;
387
- }
388
- return !node.isLeaf && lendsMarks(node, "asAccepted");
389
- });
390
- if (internalCarrier) return false;
391
- if (change.text === "") {
392
- for (const mark of comments) if (!mark.isInSet(collapsing)) collapsing.push(mark);
393
- continue;
394
- }
395
- for (const mark of comments) if (!mark.isInSet(continued)) continued.push(mark);
396
- }
397
- const candidates = collapsing.filter((mark) => !mark.isInSet(continued));
398
- if (candidates.length === 0) return true;
399
- const retained = [];
400
- let sourceContentSurvives = false;
401
- let changeIndex = 0;
402
- doc.descendants((node, position) => {
403
- if (!node.isInline) return true;
404
- if (!node.isLeaf) return lendsMarks(node, "asAccepted");
405
- if (isZeroWidthAnchor(node) || !lendsMarks(node, "asAccepted")) return false;
406
- const from = position;
407
- const to = position + node.nodeSize;
408
- const sourceFrom = Math.max(source.from, from);
409
- const sourceTo = Math.min(source.to, to);
410
- while ((changes[changeIndex]?.to ?? 1e400) <= from) changeIndex++;
411
- let removed = 0;
412
- let sourceRemoved = 0;
413
- for (let index = changeIndex; index < changes.length; index++) {
414
- const change = changes[index];
415
- if (change === void 0 || change.from >= to) break;
416
- removed += Math.max(0, Math.min(to, change.to) - Math.max(from, change.from));
417
- sourceRemoved += Math.max(0, Math.min(sourceTo, change.to) - Math.max(sourceFrom, change.from));
418
- }
419
- if (sourceFrom < sourceTo && sourceRemoved < sourceTo - sourceFrom) sourceContentSurvives = true;
420
- if (removed < to - from) {
421
- for (const mark of candidates) if (mark.isInSet(node.marks) && !mark.isInSet(retained)) retained.push(mark);
422
- }
423
- return false;
424
- });
425
- const deletesOnly = changes.every(({ text }) => text === "");
426
- return candidates.every((mark) => {
427
- const survivingNonCarrierContent = mark.isInSet(retained);
428
- return survivingNonCarrierContent || deletesOnly && sourceContentSurvives && isCommentExhausted({
429
- type: "coverage",
430
- anchorKind: "range",
431
- survivingNonCarrierContent
432
- });
433
- });
434
- };
435
- /**
436
244
  * Whether the span already contributed this mark, or one the mark would evict.
437
245
  * Comments do not exclude each other, so every comment is collected; a
438
246
  * hyperlink excludes its own type, so the first address in the span wins
@@ -712,4 +520,4 @@ const inheritedReplacementMarks = (doc, from, to) => {
712
520
  const $from = doc.resolve(from);
713
521
  return (to === from ? $from.marks() : $from.marksAcross(doc.resolve(to))) ?? Mark.none;
714
522
  };
715
- export { NON_INCLUSIVE_MARK_DISPOSITION, addCarriedMarks, annotatedReplacement, commentPoint, commentsAcrossBlockBoundary, commentsForTrackedInsertion, commentsSpanningInsertion, createResolvedCommentPointCollector, hasReplacedAnnotations, inheritedReplacementMarks, joinCommentStretches, nonInclusiveMarkNames, placeTrackedInsertion, preservesReplacementCommentAlignment, resolvedCommentPoints, splitAtKeptCommentBoundaries, surveyAcceptedReplacedAnnotations, surveyReplacedAnnotations };
523
+ export { NON_INCLUSIVE_MARK_DISPOSITION, addCarriedMarks, annotatedReplacement, commentPoint, commentsAcrossBlockBoundary, commentsForTrackedInsertion, commentsSpanningInsertion, createResolvedCommentPointCollector, hasReplacedAnnotations, inheritedReplacementMarks, joinCommentStretches, nonInclusiveMarkNames, placeTrackedInsertion, 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.
@@ -47,6 +47,7 @@ export type ReadonlyTextFormatting = DeepReadonly<document_d_exports.TextFormatt
47
47
  * projection is modeled end to end.
48
48
  */
49
49
  export type TableCellParagraphSpacingOverlay = DeepReadonly<Pick<document_d_exports.ParagraphFormatting, "spaceBefore" | "spaceAfter" | "lineSpacing" | "lineSpacingRule" | "contextualSpacing" | "frame">>;
50
+ export declare const styleResolverSource: (resolver: StyleResolver) => DeepReadonly<document_d_exports.StyleDefinitions> | undefined;
50
51
  /**
51
52
  * StyleResolver provides efficient access to resolved style properties
52
53
  */
@@ -41,6 +41,8 @@ const BUILTIN_NORMAL_STYLE = {
41
41
  default: true,
42
42
  pPr: BUILT_IN_DEFAULT_PARAGRAPH_FORMATTING
43
43
  };
44
+ const sourceDefinitions = /* @__PURE__ */ new WeakMap();
45
+ const styleResolverSource = (resolver) => sourceDefinitions.get(resolver);
44
46
  /**
45
47
  * StyleResolver provides efficient access to resolved style properties
46
48
  */
@@ -52,6 +54,7 @@ var StyleResolver = class {
52
54
  defaultCharacterStyle;
53
55
  defaultTableStyle;
54
56
  constructor(styleDefinitions) {
57
+ if (styleDefinitions !== void 0) sourceDefinitions.set(this, styleDefinitions);
55
58
  this.stylesById = /* @__PURE__ */ new Map();
56
59
  this.docDefaults = styleDefinitions?.docDefaults;
57
60
  if (styleDefinitions?.styles) {
@@ -270,4 +273,4 @@ const resolveStyleParagraphNumbering = (resolver, styleId) => {
270
273
  for (const layer of paragraphNumberingLayers(resolver, styleId)) numbering = mergeParagraphNumbering(numbering, layer?.numPr);
271
274
  return numbering;
272
275
  };
273
- export { StyleResolver, createStyleResolver, resolveStyleParagraphNumbering };
276
+ export { StyleResolver, createStyleResolver, resolveStyleParagraphNumbering, styleResolverSource };
@@ -0,0 +1,114 @@
1
+ import { ParagraphPropertyChangeAttrs } from "./schema/nodes.js";
2
+ import { EditorState } from "prosemirror-state";
3
+ import { ParagraphMarkChange } from "@stll/docx-core/model";
4
+ import { Mark, Node } from "prosemirror-model";
5
+ export declare const isSuggestionMark: (mark: Mark) => boolean;
6
+ /**
7
+ * The suggestion a comment mark belongs to: a comment a suggestion proposed
8
+ * is pending with it, never saved, accepted and rejected with it.
9
+ */
10
+ export declare const suggestedCommentOf: (mark: Mark) => string | null;
11
+ /** The ids of the comments a pending suggestion proposes. */
12
+ export declare function suggestionCommentIds(state: EditorState, suggestionId: string): number[];
13
+ export type SuggestionKind = "insertion" | "deletion" | "formatting" | "insertBlock" | "insertTable" | "insertRow" | "deleteRow" | "insertColumn" | "deleteColumn" | "comment";
14
+ /**
15
+ * How a suggestion is applied when accepted:
16
+ * - `"tracked"` — converts to a normal OOXML tracked change (`w:ins`/`w:del`,
17
+ * paragraph-mark `w:ins`, row/cell `w:ins`/`w:del`);
18
+ * - `"direct"` — no OOXML tracked representation exists (a whole inserted
19
+ * table), so accepting applies it directly; a suggestion that only
20
+ * proposes a comment is accepted as an ordinary comment;
21
+ * - `"mixed"` — a heterogeneous group (one `suggestionId` spanning a whole
22
+ * inserted table AND other edits) whose parts apply both ways. Accept still
23
+ * resolves the whole group in one transaction; this flag lets the host
24
+ * message that some parts landed directly.
25
+ */
26
+ export type SuggestionAppliedAs = "tracked" | "direct" | "mixed";
27
+ export type FolioSuggestion = {
28
+ suggestionId: string;
29
+ /** Contiguous document ranges the suggestion covers, in document order. */
30
+ ranges: readonly {
31
+ from: number;
32
+ to: number;
33
+ }[];
34
+ /** Which kinds of change the suggestion contains (deduped, in a stable order). */
35
+ kinds: readonly SuggestionKind[];
36
+ /** How accepting this suggestion applies it (see {@link SuggestionAppliedAs}). */
37
+ appliedAs: SuggestionAppliedAs;
38
+ };
39
+ /**
40
+ * A node-attr (block/table) suggestion read off a single node: a whole-node
41
+ * `_suggestedInsert`, or a suggested `trIns`/`trDel`/`cellMarker`.
42
+ */
43
+ type StructuralSuggestion = {
44
+ suggestionId: string;
45
+ revisionId: number;
46
+ kind: SuggestionKind;
47
+ /** True for a whole-node insert (paragraph/table): rejected by node deletion. */
48
+ isNodeInsert: boolean;
49
+ };
50
+ export declare const readSuggestedMarker: (marker: unknown) => {
51
+ suggestionId: string;
52
+ revisionId: number;
53
+ } | null;
54
+ export declare const readSuggestedParagraphPropertyChange: (change: ParagraphPropertyChangeAttrs) => {
55
+ suggestionId: string;
56
+ revisionId: number;
57
+ } | null;
58
+ type SuggestedParagraphMark = {
59
+ suggestionId: string;
60
+ revisionId: number;
61
+ kind: SuggestionKind;
62
+ };
63
+ /** The suggestion one paragraph-mark record belongs to, read off its info. */
64
+ export declare const suggestionIdOfMarkRecord: (info: ParagraphMarkChange["info"]) => string | null;
65
+ /** The suggestion the paragraph mark's own record, its break's, belongs to. */
66
+ export declare const readSuggestedParagraphMark: (node: Node) => SuggestedParagraphMark | null;
67
+ export declare const readStructuralSuggestion: (node: Node) => StructuralSuggestion | null;
68
+ type SuggestionAccumulator = {
69
+ segments: {
70
+ from: number;
71
+ to: number;
72
+ }[];
73
+ kinds: Set<SuggestionKind>;
74
+ revisionIds: Set<number>;
75
+ /** The comments the suggestion proposes. */
76
+ commentIds: Set<number>;
77
+ };
78
+ export declare const collectSuggestions: (state: EditorState) => Map<string, SuggestionAccumulator>;
79
+ /** Merge sorted, possibly adjacent/overlapping segments into contiguous ranges. */
80
+ export declare const mergeSegments: (segments: readonly {
81
+ from: number;
82
+ to: number;
83
+ }[]) => {
84
+ from: number;
85
+ to: number;
86
+ }[];
87
+ /**
88
+ * List every suggestion in the document for host consumption: its id, the
89
+ * contiguous ranges it covers, which kinds of change it contains, and how
90
+ * accepting it applies (tracked vs direct).
91
+ */
92
+ export declare function getSuggestions(state: EditorState): FolioSuggestion[];
93
+ /** The disjoint projected ranges a single pending suggestion covers. */
94
+ export declare const getSuggestionRanges: (state: EditorState, suggestionId: string) => {
95
+ from: number;
96
+ to: number;
97
+ }[];
98
+ /** Physical revision IDs of every pending suggestion, in one document walk. */
99
+ export declare const pendingSuggestionRevisionIds: (state: EditorState) => ReadonlySet<number>;
100
+ /** The first owning suggestion for each physical revision, in source order. */
101
+ export declare const suggestionOwnersByRevision: (state: EditorState) => ReadonlyMap<number, string>;
102
+ /** The suggestion a revision belongs to, or `null` for an ordinary tracked change. */
103
+ export declare function suggestionIdOfRevision(state: EditorState, revisionId: number): string | null;
104
+ /**
105
+ * The document range covering every mark belonging to `suggestionId`, plus the
106
+ * revision ids those marks carry. Returns null when the suggestion is absent
107
+ * (already accepted/rejected, or never existed).
108
+ */
109
+ export declare function findSuggestionRange(state: EditorState, suggestionId: string): {
110
+ from: number;
111
+ to: number;
112
+ revisionIds: number[];
113
+ } | null;
114
+ export {};