@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
@@ -91,6 +91,8 @@ export declare const resolveCleanTextRange: ({ cleanBlock, startOffset, endOffse
91
91
  } | null;
92
92
  /** Whether the clean view leaves out an inline node. */
93
93
  export declare const isOmittedFromCleanView: (node: Node) => boolean;
94
+ /** Read inline text the way the saved story reads it, with proposals rejected. */
95
+ export declare const isOmittedFromSavedSuggestionText: (node: Node) => boolean;
94
96
  export type BuildCleanBlockTextOptions = {
95
97
  /**
96
98
  * `"text"` reads a field as the result Word shows, which is the view a reader
@@ -107,8 +109,9 @@ export type BuildCleanBlockTextOptions = {
107
109
  * documents' editor text wants.
108
110
  */
109
111
  noteReferences?: NoteReferenceLabels | "sourceText";
112
+ view?: "saved-without-suggestions";
110
113
  };
111
- export declare const buildCleanBlockText: (blockNode: Node, blockFrom: number, { fieldResults, noteReferences }?: BuildCleanBlockTextOptions) => CleanBlockText;
114
+ export declare const buildCleanBlockText: (blockNode: Node, blockFrom: number, { fieldResults, noteReferences, view }?: BuildCleanBlockTextOptions) => CleanBlockText;
112
115
  /**
113
116
  * A "redline-aware" view of a textblock: the same left-to-right traversal as
114
117
  * {@link buildCleanBlockText}, but every tracked change and comment anchor is
@@ -1,4 +1,4 @@
1
- import { expectPageBreakRunAttrs } from "../prosemirror/attrs/index.js";
1
+ import { expectPageBreakRunAttrs, expectTrackedChangeMarkAttrs } from "../prosemirror/attrs/index.js";
2
2
  import { runFormattingInlineAtomCleanText, runFormattingInlineControlCharacter, runFormattingInlineControlNodeName } from "../prosemirror/runFormattingInlineCarriers.js";
3
3
  import { createNoteReferenceNumbering, noteReferenceMarker } from "../utils/noteReferenceLabels.js";
4
4
  import { noteReferenceOf } from "./note-references.js";
@@ -50,6 +50,19 @@ const COMMENT_MARK = "comment";
50
50
  const HIDDEN_MARK = "hidden";
51
51
  /** Whether the clean view leaves out an inline node. */
52
52
  const isOmittedFromCleanView = (node) => node.marks.some((mark) => mark.type.name === DELETION_MARK || mark.type.name === HIDDEN_MARK);
53
+ /** Read inline text the way the saved story reads it, with proposals rejected. */
54
+ const isOmittedFromSavedSuggestionText = (node) => node.marks.some((mark) => {
55
+ const name = mark.type.name;
56
+ if (name === HIDDEN_MARK) return true;
57
+ if (name !== INSERTION_MARK && name !== DELETION_MARK) return false;
58
+ const attrs = expectTrackedChangeMarkAttrs(mark);
59
+ const ancestors = attrs._docxRevisionAncestors ?? [];
60
+ if (ancestors.some(({ type, suggestionId }) => suggestionId !== void 0 && (type === "insertion" || type === "moveTo"))) return true;
61
+ if (attrs.suggestionId === void 0) return name === DELETION_MARK;
62
+ if (name === INSERTION_MARK) return true;
63
+ const kept = ancestors.findLast(({ suggestionId }) => suggestionId === void 0);
64
+ return kept?.type === "deletion" || kept?.type === "moveFrom";
65
+ });
53
66
  const DEFAULT_BUILD_CLEAN_BLOCK_TEXT_OPTIONS = { fieldResults: "text" };
54
67
  /**
55
68
  * The marker a reference reads as: the story's number when the labels know
@@ -63,7 +76,8 @@ const noteReferenceLabelFor = (node, labels, local) => {
63
76
  const { displayNumber } = local().next(reference.noteType, reference.noteId);
64
77
  return noteReferenceMarker(reference.noteType, displayNumber);
65
78
  };
66
- const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReferences } = DEFAULT_BUILD_CLEAN_BLOCK_TEXT_OPTIONS) => {
79
+ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReferences, view } = DEFAULT_BUILD_CLEAN_BLOCK_TEXT_OPTIONS) => {
80
+ const omitted = view === "saved-without-suggestions" ? isOmittedFromSavedSuggestionText : isOmittedFromCleanView;
67
81
  let text = "";
68
82
  const offsets = [];
69
83
  let structuralBoundaries;
@@ -72,7 +86,7 @@ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReference
72
86
  let localNumbering;
73
87
  const local = () => localNumbering ??= createNoteReferenceNumbering();
74
88
  blockNode.descendants((node, pos) => {
75
- if (noteReferences !== "sourceText" && node.isText && !isOmittedFromCleanView(node)) {
89
+ if (noteReferences !== "sourceText" && node.isText && !omitted(node)) {
76
90
  const reference = noteReferenceOf(node);
77
91
  const label = reference === null ? null : noteReferenceLabelFor(node, labels, local);
78
92
  if (reference !== null && label !== null) {
@@ -102,7 +116,7 @@ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReference
102
116
  from,
103
117
  to: from + node.nodeSize,
104
118
  ...clear !== void 0 ? { clear } : {},
105
- presentInCleanView: !node.marks.some(({ type }) => type.name === DELETION_MARK)
119
+ presentInCleanView: view === "saved-without-suggestions" ? !omitted(node) : !node.marks.some(({ type }) => type.name === DELETION_MARK)
106
120
  });
107
121
  return false;
108
122
  }
@@ -111,7 +125,7 @@ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReference
111
125
  else if (node.type.name === "structuredField") atomText = node.textContent;
112
126
  else atomText = runFormattingInlineAtomCleanText(node);
113
127
  if (atomText !== null) {
114
- if (isOmittedFromCleanView(node)) return false;
128
+ if (omitted(node)) return false;
115
129
  const startPos = blockFrom + 1 + pos;
116
130
  if (atomText.length > 1) (structuralBoundaries ??= []).push({
117
131
  type: "field",
@@ -126,7 +140,7 @@ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReference
126
140
  return false;
127
141
  }
128
142
  if (!node.isText || node.text === void 0) return true;
129
- if (isOmittedFromCleanView(node)) return false;
143
+ if (omitted(node)) return false;
130
144
  const startPos = blockFrom + 1 + pos;
131
145
  for (let i = 0; i < node.text.length; i++) offsets.push(startPos + i);
132
146
  text += node.text;
@@ -235,4 +249,4 @@ const cleanTextInlineNodes = ({ schema, text, marks = [] }) => {
235
249
  if (trailing.length > 0) nodes.push(schema.text(trailing, marks));
236
250
  return nodes;
237
251
  };
238
- export { buildAnnotatedBlockText, buildAnnotatedBlockTextWithNoteReferences, buildCleanBlockText, cleanTextInlineNodes, isOmittedFromCleanView, resolveCleanTextRange };
252
+ export { buildAnnotatedBlockText, buildAnnotatedBlockTextWithNoteReferences, buildCleanBlockText, cleanTextInlineNodes, isOmittedFromCleanView, isOmittedFromSavedSuggestionText, resolveCleanTextRange };
@@ -1,5 +1,5 @@
1
1
  import { CanonicalRoomBase } from "../canonical/canonicalRoomBase.js";
2
- import { MatchInlineAtomsOptions } from "../compare/inline-atoms.js";
2
+ import { matchInlineAtomsOnModel } from "../compare/inline-atoms-model.js";
3
3
  import { InlineProvenanceTargetOptions } from "../compare/inline-provenance.js";
4
4
  import { ImportReferencedStyleDefinitionsResult } from "../compare/style-resources.js";
5
5
  import { FolioDocumentOperationBatchInput, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult } from "../document-operations.js";
@@ -221,7 +221,9 @@ type StoryInlineProvenanceResult = {
221
221
  } | {
222
222
  status: "budget-exceeded";
223
223
  };
224
- type MatchStoryInlineAtomsOptions = Omit<MatchInlineAtomsOptions, "state" | "author"> & {
224
+ type ModelInlineAtomOptions = Parameters<typeof matchInlineAtomsOnModel>[0];
225
+ type MatchStoryInlineAtomsOptions = Omit<ModelInlineAtomOptions, "document" | "story" | "target" | "author" | "noteReferenceLabels"> & Partial<Pick<ModelInlineAtomOptions, "noteReferenceLabels">> & {
226
+ targetSnapshot: FolioAIEditSnapshot;
225
227
  story: FolioEditableDocumentStoryHandle;
226
228
  targetReviewer: FolioDocxReviewer;
227
229
  targetStory: FolioEditableDocumentStoryHandle;
@@ -475,7 +477,8 @@ export declare class FolioDocxReviewer {
475
477
  * the anchor map the apply layer resolves operations against.
476
478
  */
477
479
  snapshot(): FolioAIEditSnapshot;
478
- /** Every suggestion id the document's stories still carry. */
480
+ private pendingSuggestionIdsForStory;
481
+ /** Every suggestion id the document's editable stories still carry. */
479
482
  private activeSuggestionIds;
480
483
  /** Export staged AI operations for storage by the host, outside the DOCX. */
481
484
  exportPendingSuggestions(): FolioPendingSuggestionRecord[];
@@ -772,6 +775,7 @@ export declare class FolioDocxReviewer {
772
775
  private resolveStoryOnSession;
773
776
  /** The current document model with edits merged back in. */
774
777
  toDocument(): document_d_exports.Document;
778
+ private savedDocument;
775
779
  /**
776
780
  * Serialise the reviewed document to a new `.docx` buffer. Tries a selective
777
781
  * patch first (only changed paragraphs are rewritten; every other byte of the
@@ -18,7 +18,6 @@ import { getCachedNumberingMap } from "../docx/numberingParser.js";
18
18
  import { cloneDocumentWithParagraphPropertySources } from "../docx/paragraphPropertySource.js";
19
19
  import { getEndnoteText, getFootnoteText, getHeaderFooterText } from "../docx/storyPlainText.js";
20
20
  import { expectCharacterStyleMarkAttrs } from "../prosemirror/attrs/index.js";
21
- import { getSuggestions, suggestionIdOfRevision, suggestionOwnersByRevision } from "../prosemirror/commands/comments.js";
22
21
  import { createCommentIdAllocator, seedCommentAllocator } from "../prosemirror/commentIdAllocator.js";
23
22
  import { commentThreadIds } from "../prosemirror/commentRecords.js";
24
23
  import { paragraphListReferences } from "../prosemirror/listInstanceReferences.js";
@@ -31,21 +30,22 @@ import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documen
31
30
  import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
32
31
  import { schema } from "../prosemirror/schema/index.js";
33
32
  import { sectionPropertiesOf } from "../prosemirror/sectionCarrier.js";
33
+ import { getSuggestions } from "../prosemirror/suggestionQueries.js";
34
34
  import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
35
35
  import { readModel } from "../types/documentModel.js";
36
36
  import { canonicalJson } from "../utils/canonicalJson.js";
37
37
  import { buildAnnotatedBlockTextWithNoteReferences } from "./clean-text.js";
38
38
  import { anchoredCommentIdsInBlocks, anchoredCommentIdsInProseDoc, coveredCommentIdsInProseDoc, withoutLostCommentThreads } from "./comment-lifecycle.js";
39
39
  import { stagedFinalSectionProperties } from "./finalSectionReview.js";
40
- import { FolioPendingSuggestionRegistry, createPendingSuggestionSourceSnapshot } from "./pending-suggestions.js";
40
+ import { FolioPendingSuggestionRegistry } from "./pending-suggestions.js";
41
41
  import { getCommentAnchorsFromDoc, getTrackedChangeStatsFromDoc, getTrackedChangesFromDoc, getTrackedChangesFromSnapshot, listedRevisionGroups } from "./read.js";
42
42
  import { classifyResourceReference } from "./referenceClassification.js";
43
- import { collectNoteReferenceLabels, createReviewerSnapshot, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, isFolioAIContentBlock, normalizeFolioAIBlockText, sourceDocumentOf } from "./snapshot.js";
43
+ import { collectNoteReferenceLabels, createFolioAIEditSnapshotWithStyleResolver, createReviewerSnapshot, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, isFolioAIContentBlock, normalizeFolioAIBlockText, sourceDocumentOf } from "./snapshot.js";
44
44
  import { matchTableGeometryOperations } from "./table-geometry.js";
45
45
  import { tableTemplateCanCrossPackageLosslessly } from "./table-template.js";
46
46
  import { TaggedError, panic } from "better-result";
47
47
  import { CONTENT_CONTROL_LOCK, lockedControlMessage, numberingLevelEntries } from "@stll/docx-core/model";
48
- import { DOCUMENT_OP_TYPES, OP_STORIES, captureStoryParts, freshCommentId, packageResourcesOpOf, pendingSuggestionIdsIn, reconcileDocumentPartRelationships, resolveSectionChange, resolveSectionChanges, sectionResolutionPatch, withoutPendingSuggestions } from "@stll/docx-core/ops";
48
+ import { DOCUMENT_OP_TYPES, OP_STORIES, captureStoryParts, freshCommentId, packageResourcesOpOf, pendingSuggestionIdsIn, reconcileDocumentPartRelationships, resolveSectionChange, resolveSectionChanges, sectionResolutionPatch, suggestionOwnersInStory, withoutPendingSuggestions } from "@stll/docx-core/ops";
49
49
  import { ZipArchive } from "@stll/docx-core/zip";
50
50
  import { EditorState, Selection, TextSelection } from "prosemirror-state";
51
51
  // src/ai-edits/headless.ts
@@ -873,7 +873,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
873
873
  for (const handle of handles) {
874
874
  const state = copy.getEditableStoryState(handle);
875
875
  if (!state) continue;
876
- if (getSuggestions(state).length > 0) throw canonicalReviewerRefusal("project a story holding a suggestion the session will not accept");
876
+ if (copy.pendingSuggestionIdsForStory(handle, state).size > 0) throw canonicalReviewerRefusal("project a story holding a suggestion the session will not accept");
877
877
  if (mode === "with-revision-census") {
878
878
  const stats = getTrackedChangeStatsFromDoc(state.doc);
879
879
  for (const id of stats.ids) ids.add(id);
@@ -1007,10 +1007,12 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1007
1007
  sourceSnapshotForStory,
1008
1008
  activeSuggestionIds: this.activeSuggestionIds()
1009
1009
  });
1010
+ const savedAbsorptions = /* @__PURE__ */ new Map();
1010
1011
  this.pendingSuggestions.placeRemovedAnchors({
1011
1012
  activeSuggestionIds: this.activeSuggestionIds(),
1012
1013
  stateForStory: (story) => this.getEditableStoryState(story),
1013
- savedSource: sourceSnapshotForStory
1014
+ savedSource: (story) => this.pendingSuggestionSource(story, savedAbsorptions),
1015
+ absorptionsForStory: (story) => savedAbsorptions.get(canonicalJson(canonicalOpStory(story))) ?? []
1014
1016
  });
1015
1017
  return {
1016
1018
  resolved: true,
@@ -1039,7 +1041,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1039
1041
  const story = canonicalOpStory(handle);
1040
1042
  const listed = listedRevisionGroups(state.doc);
1041
1043
  if (listed.length === 0) return [];
1042
- const owners = suggestionOwnersByRevision(state);
1044
+ const owners = suggestionOwnersInStory(this.baseDocument, story);
1043
1045
  const changes = listed.flatMap(({ id, groupIds }) => {
1044
1046
  const suggestionId = owners.get(id) ?? null;
1045
1047
  return resolution === "accept" && suggestionId !== null ? [] : [{
@@ -1163,23 +1165,31 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1163
1165
  snapshot() {
1164
1166
  return this.snapshotOf(this.state);
1165
1167
  }
1166
- /** Every suggestion id the document's stories still carry. */
1168
+ pendingSuggestionIdsForStory(story, state) {
1169
+ const ids = new Set(getSuggestions(state).map(({ suggestionId }) => suggestionId));
1170
+ for (const suggestionId of suggestionOwnersInStory(this.baseDocument, canonicalOpStory(story)).values()) ids.add(suggestionId);
1171
+ return ids;
1172
+ }
1173
+ /** Every suggestion id the document's editable stories still carry. */
1167
1174
  activeSuggestionIds() {
1168
- const active = new Set(getSuggestions(this.state).map(({ suggestionId }) => suggestionId));
1175
+ const active = /* @__PURE__ */ new Set();
1176
+ if (pendingSuggestionIdsIn(this.baseDocument).size === 0) return active;
1169
1177
  for (const handle of this.listStoryHandlesInternal()) {
1170
- if (handle.type === "main") continue;
1171
1178
  const state = this.getEditableStoryState(handle);
1172
- for (const { suggestionId } of state ? getSuggestions(state) : []) active.add(suggestionId);
1179
+ if (state === null) continue;
1180
+ for (const id of this.pendingSuggestionIdsForStory(handle, state)) active.add(id);
1173
1181
  }
1174
1182
  return active;
1175
1183
  }
1176
1184
  /** Export staged AI operations for storage by the host, outside the DOCX. */
1177
1185
  exportPendingSuggestions() {
1178
1186
  const active = this.activeSuggestionIds();
1187
+ const savedAbsorptions = /* @__PURE__ */ new Map();
1179
1188
  return this.pendingSuggestions.exportPendingSuggestions({
1180
1189
  activeSuggestionIds: active,
1181
- snapshotForStory: (story) => this.pendingSuggestionSource(story),
1182
- stateForStory: (story) => this.getEditableStoryState(story)
1190
+ snapshotForStory: (story) => this.pendingSuggestionSource(story, savedAbsorptions),
1191
+ stateForStory: (story) => this.getEditableStoryState(story),
1192
+ absorptionsForStory: (story) => savedAbsorptions.get(canonicalJson(canonicalOpStory(story))) ?? []
1183
1193
  });
1184
1194
  }
1185
1195
  /**
@@ -1188,9 +1198,11 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1188
1198
  * the document the save writes, so a reviewer reopened on the saved package
1189
1199
  * reads the same story.
1190
1200
  */
1191
- pendingSuggestionSource(story) {
1201
+ pendingSuggestionSource(story, absorptions) {
1192
1202
  if (!this.getEditableStoryState(story)) return null;
1193
- const document = this.toDocument();
1203
+ const document = this.savedDocument(absorptions === void 0 ? void 0 : { onAbsorptions: (resolvedStory, absorbed) => {
1204
+ absorptions.set(canonicalJson(resolvedStory), absorbed);
1205
+ } });
1194
1206
  const created = createCanonicalSession(document, document.package.styles);
1195
1207
  if (created.isErr()) throw created.error;
1196
1208
  const saved = new FolioDocxReviewer({
@@ -1204,7 +1216,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1204
1216
  },
1205
1217
  positionalParaIds: this.positionalParaIds
1206
1218
  }).getEditableStoryState(story);
1207
- return saved ? createPendingSuggestionSourceSnapshot(saved, /* @__PURE__ */ new Set()) : null;
1219
+ return saved ? createFolioAIEditSnapshotWithStyleResolver(saved.doc, getDocumentStyleResolver(saved)) : null;
1208
1220
  }
1209
1221
  /** Validate saved proposals against this document before restaging them. */
1210
1222
  loadPendingSuggestions(records) {
@@ -1807,7 +1819,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1807
1819
  resolveChangeOnSession(target, resolution) {
1808
1820
  const { session } = this.engine;
1809
1821
  const id = revisionIdOf(target);
1810
- const suggestionId = suggestionIdOfRevision(this.state, id);
1822
+ const suggestionId = suggestionOwnersInStory(this.baseDocument, OP_STORIES.MAIN).get(id) ?? null;
1811
1823
  if (suggestionId !== null) {
1812
1824
  const adopted = this.resolveSuggestionOnSession(session, suggestionId, resolution, this.author);
1813
1825
  if (!adopted || resolution === "reject") return adopted;
@@ -1978,7 +1990,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1978
1990
  for (const handle of this.listStoryHandlesInternal()) {
1979
1991
  if (editableStoryKey(handle) === key) continue;
1980
1992
  const other = this.getEditableStoryState(handle);
1981
- if (other && getSuggestions(other).some(({ suggestionId }) => staged.has(suggestionId))) throw canonicalReviewerRefusal("resolve one story of a suggestion that reaches another");
1993
+ if (other && [...this.pendingSuggestionIdsForStory(handle, other)].some((suggestionId) => staged.has(suggestionId))) throw canonicalReviewerRefusal("resolve one story of a suggestion that reaches another");
1982
1994
  }
1983
1995
  const copy = this.fork();
1984
1996
  const { session } = copy.engine;
@@ -1988,7 +2000,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1988
2000
  try {
1989
2001
  for (const suggestionId of staged) copy.resolveSuggestionOnSession(session, suggestionId, view === "final" ? "accept" : "reject", this.author);
1990
2002
  const after = copy.getEditableStoryState(story);
1991
- if (after && getSuggestions(after).length > 0) throw canonicalReviewerRefusal("resolve a story holding a suggestion the session will not resolve");
2003
+ if (after && copy.pendingSuggestionIdsForStory(story, after).size > 0) throw canonicalReviewerRefusal("resolve a story holding a suggestion the session will not resolve");
1992
2004
  resolved = copy.resolveStoryOnSession(session, story, view);
1993
2005
  } finally {
1994
2006
  unsubscribe();
@@ -2007,7 +2019,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2007
2019
  });
2008
2020
  const state = this.getEditableStoryState(story);
2009
2021
  if (!state) return false;
2010
- const staged = new Set(getSuggestions(state).map(({ suggestionId }) => suggestionId));
2022
+ const staged = this.pendingSuggestionIdsForStory(story, state);
2011
2023
  if (staged.size > 0) return this.resolveStoryWithSuggestions({
2012
2024
  story,
2013
2025
  view,
@@ -2053,7 +2065,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2053
2065
  }
2054
2066
  /** The current document model with edits merged back in. */
2055
2067
  toDocument() {
2056
- const model = withoutPendingSuggestions(this.engine.session.captureSaveSnapshot().document);
2068
+ return this.savedDocument();
2069
+ }
2070
+ savedDocument(options) {
2071
+ const model = withoutPendingSuggestions(this.engine.session.captureSaveSnapshot().document, options);
2057
2072
  if (model.isErr()) throw model.error;
2058
2073
  return cloneDocumentWithParagraphPropertySources(reconcileDocumentPartRelationships(model.value));
2059
2074
  }
@@ -74,7 +74,7 @@ export declare const endsWithNoteReference: ({ structuralBoundaries }: Structura
74
74
  * Only a document comparison does this. Its operations come from a revised
75
75
  * document that adds and removes references, so refusing them would drop the
76
76
  * edit; each marker it writes is turned back into the reference the revised
77
- * document holds once the operations land (`compare/inline-atoms.ts`), and a
77
+ * document holds once the operations land (`compare/inline-atoms-model.ts`), and a
78
78
  * removed reference is a tracked deletion of the reference itself. Every other
79
79
  * caller keeps the protection. The scope is synchronous, like the applier.
80
80
  */
@@ -65,7 +65,7 @@ let comparisonEditsNoteReferences = false;
65
65
  * Only a document comparison does this. Its operations come from a revised
66
66
  * document that adds and removes references, so refusing them would drop the
67
67
  * edit; each marker it writes is turned back into the reference the revised
68
- * document holds once the operations land (`compare/inline-atoms.ts`), and a
68
+ * document holds once the operations land (`compare/inline-atoms-model.ts`), and a
69
69
  * removed reference is a tracked deletion of the reference itself. Every other
70
70
  * caller keeps the protection. The scope is synchronous, like the applier.
71
71
  */
@@ -1,6 +1,8 @@
1
+ import { document_d_exports } from "../types/document.js";
1
2
  import { FolioDocumentStoryHandle } from "./headless.js";
2
3
  import { FolioAIEditAppliedOperation, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot } from "./types.js";
3
4
  import { EditorState } from "prosemirror-state";
5
+ import { ParagraphAbsorption } from "@stll/docx-core/ops";
4
6
  export declare const FOLIO_PENDING_SUGGESTION_VERSION: 1;
5
7
  /** A host-owned, JSON-serializable proposal. It is never written into the DOCX. */
6
8
  export type FolioPendingSuggestionRecord = {
@@ -77,17 +79,17 @@ type AbsorptionStep = (options: AbsorptionStepOptions) => void;
77
79
  type PlaceRemovedAnchorsOptions = {
78
80
  activeSuggestionIds: ReadonlySet<string>;
79
81
  stateForStory: (story: FolioDocumentStoryHandle) => EditorState | null;
80
- savedSource?: (story: FolioDocumentStoryHandle) => FolioAIEditSnapshot | null;
82
+ savedSource: (story: FolioDocumentStoryHandle) => FolioAIEditSnapshot | null;
83
+ absorptionsForStory?: (story: FolioDocumentStoryHandle) => readonly ParagraphAbsorption[];
81
84
  };
82
85
  type ExportPendingSuggestionsOptions = {
83
86
  activeSuggestionIds: ReadonlySet<string>;
84
87
  stateForStory?: PlaceRemovedAnchorsOptions["stateForStory"];
88
+ absorptionsForStory?: PlaceRemovedAnchorsOptions["absorptionsForStory"];
85
89
  snapshotForStory: (story: FolioDocumentStoryHandle, commentIds: ReadonlySet<number>) => FolioAIEditSnapshot | null;
86
90
  };
87
- /** Drop only comments attached to proposals that have not been accepted. */
88
- export declare const withoutPendingSuggestionCommentMarks: (state: EditorState, commentIds: ReadonlySet<number>) => EditorState;
89
- /** The saved package's story, with all pending proposals removed. */
90
- export declare const createPendingSuggestionSourceSnapshot: (state: EditorState, commentIds: ReadonlySet<number>) => FolioAIEditSnapshot;
91
+ /** The main story a save writes, with pending proposals and their comments removed. */
92
+ export declare const createPendingSuggestionSourceSnapshot: (document: document_d_exports.Document, commentIds: ReadonlySet<number>) => FolioAIEditSnapshot;
91
93
  /** Tracks only operations that successfully staged in `suggested` mode. */
92
94
  export declare class FolioPendingSuggestionRegistry {
93
95
  private readonly records;
@@ -106,7 +108,7 @@ export declare class FolioPendingSuggestionRegistry {
106
108
  * places is retired ({@link retiredRecord}): no record restages on a
107
109
  * removed or absorbed paragraph. Run after the change publishes.
108
110
  */
109
- placeRemovedAnchors({ activeSuggestionIds, stateForStory, savedSource }: PlaceRemovedAnchorsOptions): void;
111
+ placeRemovedAnchors({ activeSuggestionIds, stateForStory, savedSource, absorptionsForStory }: PlaceRemovedAnchorsOptions): void;
110
112
  /**
111
113
  * Prepare re-anchoring for a resolution that absorbs paragraphs: a live
112
114
  * proposal anchored to an absorbed paragraph now lives in the survivor, so
@@ -123,7 +125,7 @@ export declare class FolioPendingSuggestionRegistry {
123
125
  recordApplied({ snapshot, story, operations, applied, author, activeSuggestionIds }: RecordAppliedOptions): void;
124
126
  /** Rebase records after ordinary revisions change their source story. */
125
127
  replaceRestagedStory({ story, restaged, activeSuggestionIds }: ReplaceRestagedStoryOptions): void;
126
- exportPendingSuggestions({ activeSuggestionIds, snapshotForStory, stateForStory }: ExportPendingSuggestionsOptions): FolioPendingSuggestionRecord[];
128
+ exportPendingSuggestions({ activeSuggestionIds, snapshotForStory, stateForStory, absorptionsForStory }: ExportPendingSuggestionsOptions): FolioPendingSuggestionRecord[];
127
129
  loadPendingSuggestions({ records, snapshotForStory, sourceSnapshotForStory, apply, activeSuggestionIds }: LoadPendingSuggestionsOptions): FolioPendingSuggestionLoadResult[];
128
130
  }
129
131
  export {};