@stll/folio-core 0.67.0 → 0.68.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 (251) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +104 -34
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/note-references.d.ts +6 -0
  7. package/dist/ai-edits/note-references.js +7 -1
  8. package/dist/ai-edits/read.d.ts +19 -0
  9. package/dist/ai-edits/snapshot.d.ts +6 -0
  10. package/dist/ai-edits/snapshot.js +8 -3
  11. package/dist/ai-edits/types.d.ts +9 -1
  12. package/dist/ai-suggestions/apply.js +13 -4
  13. package/dist/compare/compare.js +2 -1
  14. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  15. package/dist/compare/inserted-resource-snapshot.js +7 -3
  16. package/dist/controller/canonicalClipboard.js +29 -12
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  19. package/dist/controller/canonicalInlineProjection.js +192 -28
  20. package/dist/controller/canonicalInput.d.ts +2 -1
  21. package/dist/controller/canonicalInput.js +28 -1
  22. package/dist/controller/canonicalListRendering.d.ts +2 -1
  23. package/dist/controller/canonicalListRendering.js +1 -1
  24. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  25. package/dist/controller/canonicalLockGuard.js +88 -0
  26. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  27. package/dist/controller/canonicalPublicOperations.js +274 -20
  28. package/dist/controller/canonicalSession.d.ts +87 -7
  29. package/dist/controller/canonicalSession.js +327 -73
  30. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  31. package/dist/controller/canonicalStoryEditor.js +4 -3
  32. package/dist/controller/canonicalStructure.d.ts +2 -1
  33. package/dist/controller/canonicalStructure.js +129 -7
  34. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  35. package/dist/controller/contentControlWidgetController.js +13 -1
  36. package/dist/controller/folioEditor.js +1 -0
  37. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  38. package/dist/controller/headerFooterEditorManager.js +5 -5
  39. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  40. package/dist/controller/hiddenEditorApi.js +1 -0
  41. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  42. package/dist/controller/hiddenEditorManager.js +91 -37
  43. package/dist/controller/layoutPipeline.js +48 -15
  44. package/dist/controller/noteEditorManager.d.ts +2 -2
  45. package/dist/controller/noteEditorManager.js +5 -5
  46. package/dist/display-list/build/pageFurniture.js +41 -19
  47. package/dist/display-list/build/tablePrimitives.js +23 -4
  48. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  49. package/dist/document-operations.d.ts +8 -0
  50. package/dist/document-operations.js +4 -3
  51. package/dist/docx/blockContentParser.d.ts +7 -3
  52. package/dist/docx/blockContentParser.js +2 -3
  53. package/dist/docx/blockPlainText.js +2 -0
  54. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  55. package/dist/docx/bookmarkRangeJoin.js +43 -0
  56. package/dist/docx/canonicalSave.js +5 -1
  57. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  58. package/dist/docx/canonicalSessionInput.js +7 -2
  59. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  60. package/dist/docx/commentAnchorIndex.js +39 -11
  61. package/dist/docx/commentRangeIntegrity.js +30 -24
  62. package/dist/docx/commentRangeJoin.d.ts +4 -0
  63. package/dist/docx/commentRangeJoin.js +26 -12
  64. package/dist/docx/commentReferenceCompletion.js +5 -4
  65. package/dist/docx/commentReferenceNormalization.js +40 -18
  66. package/dist/docx/compatibility.js +9 -2
  67. package/dist/docx/containerChildren.js +22 -1
  68. package/dist/docx/encryption/compoundFile.js +9 -1
  69. package/dist/docx/encryption/encryptionInfo.js +16 -2
  70. package/dist/docx/ensureParaIds.js +46 -7
  71. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  72. package/dist/docx/ensureUniqueControlIds.js +110 -0
  73. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  74. package/dist/docx/headerFooterVerbatim.js +13 -2
  75. package/dist/docx/hostCommentThreads.d.ts +17 -0
  76. package/dist/docx/hostCommentThreads.js +49 -0
  77. package/dist/docx/hyperlinkParser.js +9 -2
  78. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  79. package/dist/docx/inlineWrapperContent.js +9 -2
  80. package/dist/docx/listMarkerComputation.d.ts +35 -1
  81. package/dist/docx/listMarkerComputation.js +39 -1
  82. package/dist/docx/listModelNormalization.d.ts +44 -1
  83. package/dist/docx/listModelNormalization.js +227 -96
  84. package/dist/docx/markupRangeMarker.d.ts +14 -0
  85. package/dist/docx/markupRangeMarker.js +15 -1
  86. package/dist/docx/metadataPrivacy.js +43 -22
  87. package/dist/docx/normalizeBaseDirection.js +3 -1
  88. package/dist/docx/paragraphParser.js +159 -48
  89. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  90. package/dist/docx/paragraphPropertySource.js +22 -1
  91. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  92. package/dist/docx/paragraphTraversal.js +2 -0
  93. package/dist/docx/parseWarningMessage.js +2 -1
  94. package/dist/docx/parser.js +6 -0
  95. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  96. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  97. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  98. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  99. package/dist/docx/reviewResolutionProvenance.js +110 -25
  100. package/dist/docx/rezip.d.ts +6 -0
  101. package/dist/docx/rezip.js +38 -21
  102. package/dist/docx/selectiveSave.js +6 -10
  103. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  104. package/dist/docx/selectiveXmlPatch.js +11 -7
  105. package/dist/docx/serializer/documentSerializer.js +3 -1
  106. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  107. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  108. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  109. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  110. package/dist/docx/serializer/noteSerializer.js +23 -16
  111. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  112. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  113. package/dist/docx/serializer/runSerializer.js +2 -2
  114. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  115. package/dist/docx/serializer/tableSerializer.js +4 -2
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  117. package/dist/docx/server/createBilingualDocument.js +27 -5
  118. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  119. package/dist/docx/sessionListPruning.d.ts +2 -0
  120. package/dist/docx/sessionListPruning.js +50 -0
  121. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  122. package/dist/docx/splitRevisionPieces.js +14 -0
  123. package/dist/docx/storyBlockReplay.js +4 -0
  124. package/dist/docx/structuralXmlPatch.js +19 -7
  125. package/dist/docx/tableParser.d.ts +6 -2
  126. package/dist/docx/tableParser.js +2 -3
  127. package/dist/docx/textBoxContentParser.d.ts +11 -0
  128. package/dist/docx/textBoxContentParser.js +51 -0
  129. package/dist/docx/textBoxParser.d.ts +0 -5
  130. package/dist/docx/textBoxParser.js +1 -23
  131. package/dist/docx/verticalMergeProjection.js +1 -1
  132. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  133. package/dist/fonts/fontsourceFaces.js +1 -7
  134. package/dist/i18n/messages/ar.gen.js +2 -0
  135. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  136. package/dist/i18n/messages/catalogs.gen.js +34 -0
  137. package/dist/i18n/messages/cs.gen.js +2 -0
  138. package/dist/i18n/messages/de.gen.js +2 -0
  139. package/dist/i18n/messages/en.gen.js +2 -0
  140. package/dist/i18n/messages/es.gen.js +2 -0
  141. package/dist/i18n/messages/et.gen.js +2 -0
  142. package/dist/i18n/messages/fr.gen.js +2 -0
  143. package/dist/i18n/messages/he.gen.js +2 -0
  144. package/dist/i18n/messages/hi.gen.js +2 -0
  145. package/dist/i18n/messages/hu.gen.js +2 -0
  146. package/dist/i18n/messages/lt.gen.js +2 -0
  147. package/dist/i18n/messages/lv.gen.js +2 -0
  148. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  149. package/dist/i18n/messages/pl.gen.js +2 -0
  150. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  151. package/dist/i18n/messages/sk.gen.js +2 -0
  152. package/dist/i18n/messages/tr.gen.js +2 -0
  153. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  154. package/dist/internal/acceptedBlockProjection.js +2 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  156. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  157. package/dist/internal/revisionResolutionInline.js +1 -2
  158. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  159. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  160. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  161. package/dist/layout-bridge/engine/hitTest.js +9 -10
  162. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  163. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  164. package/dist/layout-engine/footnoteContinuation.js +210 -0
  165. package/dist/layout-engine/index.d.ts +2 -2
  166. package/dist/layout-engine/index.js +7 -2
  167. package/dist/layout-engine/measure/cache.js +10 -5
  168. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  169. package/dist/layout-engine/tableLayout.js +29 -5
  170. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  171. package/dist/layout-engine/tableRowBreak.js +43 -1
  172. package/dist/layout-engine/types.d.ts +36 -1
  173. package/dist/layout-painter/renderPage.d.ts +4 -4
  174. package/dist/layout-painter/renderPage.js +46 -17
  175. package/dist/layout-painter/renderTable.js +7 -4
  176. package/dist/managers/AutoSaveManager.d.ts +5 -1
  177. package/dist/managers/FindReplaceManager.js +3 -10
  178. package/dist/markdown/escape.d.ts +20 -1
  179. package/dist/markdown/escape.js +43 -1
  180. package/dist/markdown/renderBlock.js +4 -1
  181. package/dist/markdown/renderParagraph.js +13 -27
  182. package/dist/markdown/renderTable.js +6 -2
  183. package/dist/markdown/trailers.js +1 -0
  184. package/dist/pdf/images.d.ts +17 -1
  185. package/dist/pdf/images.js +22 -4
  186. package/dist/pdf/writePdf.js +4 -2
  187. package/dist/prosemirror/attrs/index.js +1 -0
  188. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  189. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  190. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  191. package/dist/prosemirror/commands/comments.d.ts +25 -0
  192. package/dist/prosemirror/commands/comments.js +102 -11
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +1 -1
  195. package/dist/prosemirror/commentIdAllocator.js +2 -2
  196. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  197. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  198. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  199. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  200. package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
  201. package/dist/prosemirror/conversion/index.d.ts +1 -1
  202. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  203. package/dist/prosemirror/conversion/toProseDoc.js +319 -51
  204. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  205. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  206. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  207. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  208. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  209. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  210. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  211. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  212. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  213. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  214. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  215. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  216. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  217. package/dist/prosemirror/index.d.ts +2 -2
  218. package/dist/prosemirror/listLabels.js +3 -2
  219. package/dist/prosemirror/listNumbering.d.ts +6 -0
  220. package/dist/prosemirror/listNumbering.js +12 -9
  221. package/dist/prosemirror/lockedControls.d.ts +13 -0
  222. package/dist/prosemirror/lockedControls.js +106 -0
  223. package/dist/prosemirror/markupViewProjection.js +1 -1
  224. package/dist/prosemirror/noteReferenceReview.js +2 -2
  225. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  226. package/dist/prosemirror/plugins/suggestionMode.js +20 -9
  227. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  228. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  229. package/dist/prosemirror/replacedAnnotations.js +1 -0
  230. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  231. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  232. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  233. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  234. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  235. package/dist/prosemirror/runStyleFormatting.js +16 -13
  236. package/dist/prosemirror/schema/marks.d.ts +6 -0
  237. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  238. package/dist/prosemirror/validation.js +1 -0
  239. package/dist/redline.js +23 -9
  240. package/dist/server.d.ts +2 -2
  241. package/dist/style-sets/extract.js +2 -2
  242. package/dist/types/canonicalCapabilities.d.ts +29 -8
  243. package/dist/types/canonicalCapabilities.js +13 -9
  244. package/dist/utils/cssString.d.ts +7 -0
  245. package/dist/utils/cssString.js +9 -0
  246. package/dist/utils/fontResolver.js +4 -1
  247. package/dist/utils/replaceText.d.ts +11 -0
  248. package/dist/utils/replaceText.js +39 -7
  249. package/dist/version-comparison.d.ts +9 -1
  250. package/dist/version-comparison.js +11 -5
  251. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { NumberingIdsInUse } from "../docx/numberingIds.js";
2
2
  import { FolioTableTemplates } from "./table-template.js";
3
- import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot } from "./types.js";
3
+ import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioAIResolvedEditOperation } from "./types.js";
4
4
  import { WordDiffGranularity } from "./word-diff.js";
5
5
  import { Node } from "prosemirror-model";
6
6
  import { EditorState, Transaction } from "prosemirror-state";
@@ -124,6 +124,14 @@ export type FolioAIEditApplyOutcome = FolioAIEditApplyResult & {
124
124
  */
125
125
  nextRevisionId: number;
126
126
  };
127
+ /**
128
+ * Operation types applied in `"suggested"` mode. Every produced revision — an
129
+ * inline mark, a whole-node `_suggestedInsert` marker, or a suggested
130
+ * `trIns`/`trDel`/`cellMarker` — is stripped from serialized DOCX until
131
+ * accepted. Cell merge/split (not row/column ops) and comment ops stay
132
+ * `unsupportedMode`.
133
+ */
134
+ export declare const SUGGESTED_SUPPORTED_OPERATION_TYPES: ReadonlySet<FolioAIResolvedEditOperation["type"]>;
127
135
  export declare const applyFolioAIEditOperations: (options: ApplyFolioAIEditOperationsOptions) => FolioAIEditApplyOutcome;
128
136
  /** {@link applyFolioAIEditOperations} for a caller holding every story. Internal. */
129
137
  export declare const applyFolioAIEditOperationsInPackage: (options: ApplyFolioAIEditOperationsInPackageOptions) => FolioAIEditApplyOutcome;
@@ -16,6 +16,7 @@ import { markStructuralChange } from "../prosemirror/extensions/features/Paragra
16
16
  import "../prosemirror/extensions/nodes/TextBoxAnchorExtension.js";
17
17
  import { blockBoundariesOf, carriesCommentAnchor, inlineBoundariesOf, isBlockBoundaryNode, removeResolvedSubtree } from "../prosemirror/keptRangeBoundaries.js";
18
18
  import { CLEARED_LIST_RENDERING_ATTRS } from "../prosemirror/listMarker.js";
19
+ import { lockedControlSpans } from "../prosemirror/lockedControls.js";
19
20
  import { effectiveParagraphNumbering, paragraphNumberingAttr, paragraphNumberingSourcesFromBoundary, readParagraphNumberingAttr, removedNumberingAttr } from "../prosemirror/numberingAttr.js";
20
21
  import { directParagraphAlignment } from "../prosemirror/paragraphAlignment.js";
21
22
  import { styleResolvedParagraphFormatting } from "../prosemirror/paragraphFormattingProvenance.js";
@@ -46,11 +47,11 @@ import { buildCleanBlockText, resolveCleanTextRange } from "./clean-text.js";
46
47
  import { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "./inline-emphasis.js";
47
48
  import { applyTextChanges, changesFromSegments, keepAtomicSpans, planTextChanges, widenChangesToAtomicSpans } from "./minimal-replacement.js";
48
49
  import { assertNewListsAllocated, resolveNewListOperations, stageNewListOperations } from "./newListNumbering.js";
49
- import { cutsIntoNoteReference, noteReferenceEditsAllowed, noteReferenceOf, noteReferenceSpansWithin, planChangesAroundNoteReferences, segmentsAroundNoteReferences } from "./note-references.js";
50
+ import { comparisonApplying, cutsIntoNoteReference, noteReferenceEditsAllowed, noteReferenceOf, noteReferenceSpansWithin, planChangesAroundNoteReferences, segmentsAroundNoteReferences } from "./note-references.js";
50
51
  import { classifyResourceReference } from "./referenceClassification.js";
51
52
  import { getFolioDocumentOperationRemovedBlockIds, getTrackedFolioDocumentOperationCarrierBlockId, getTrackedFolioDocumentOperationRemovedBlockIds } from "./removed-blocks.js";
52
53
  import { separateRevisionStretches } from "./revisionStretches.js";
53
- import { collectNoteReferenceLabels, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isHiddenTableRow, normalizeFolioAIBlockText } from "./snapshot.js";
54
+ import { collectNoteReferenceLabels, hashFolioAIBlockContent, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isHiddenTableRow } from "./snapshot.js";
54
55
  import { isEmptyTableCell, mergeTableRectangle, mergeTrackedVerticalTableCells, splitTableRectangle, splitTrackedVerticalTableCell } from "./table-cell-mutations.js";
55
56
  import { planTableMutations } from "./table-mutation-plan.js";
56
57
  import { applyTableColumnDeletion, applyTableColumnInsertion, applyTableRowDeletion, applyTableRowInsertion, describeUnplacedCellTexts, findTableColumnInsertion, findTableRowInsertion, getTableColumnCoordinateKey, markTableRowContent, splitCellParagraphTexts } from "./table-row-column-mutations.js";
@@ -58,7 +59,7 @@ import { findEnclosingTableCell, findEnclosingTableRow, findOutermostTableBounda
58
59
  import { tableFromTemplate } from "./table-template.js";
59
60
  import { wordDiffSessionFromOptions } from "./word-diff.js";
60
61
  import { panic } from "better-result";
61
- import { REVIEW_CARRIERS } from "@stll/docx-core/model";
62
+ import { CONTENT_CONTROL_LOCK, REVIEW_CARRIERS, firstLockedControlViolation, lockedControlMessage } from "@stll/docx-core/model";
62
63
  import { Fragment, Mark } from "prosemirror-model";
63
64
  import { TableMap } from "prosemirror-tables";
64
65
  import { canSplit } from "prosemirror-transform";
@@ -561,8 +562,7 @@ const applyBlockParagraphProperties = ({ tr, position, node, properties, styleRe
561
562
  const OPERATION_TEXT_CONTEXT = {
562
563
  baseParagraphFormatting: void 0,
563
564
  paragraphFormatting: void 0,
564
- paragraphMarkFormatting: void 0,
565
- paragraphMarkPrecedesStyle: false
565
+ paragraphMarkFormatting: void 0
566
566
  };
567
567
  const applyReplaceBlockStyleId = ({ item, tr, styleResolver, revisionInfo }) => {
568
568
  if (item.operation.type !== "replaceBlock" || item.operation.styleId === void 0) return {
@@ -912,7 +912,7 @@ const collectLiveBlocksByHash = (doc) => {
912
912
  fieldResults: "text",
913
913
  noteReferences
914
914
  }).text;
915
- const hash = hashFolioAIBlockText(normalizeFolioAIBlockText(cleanText));
915
+ const hash = hashFolioAIBlockContent(cleanText);
916
916
  const bucket = byHash.get(hash) ?? [];
917
917
  bucket.push({
918
918
  from: pos,
@@ -1195,6 +1195,75 @@ const batchClaimOf = ({ item, doc, producesTrackedChanges }) => {
1195
1195
  }
1196
1196
  };
1197
1197
  /**
1198
+ * The stretches an operation changes, for the content-control lock rule
1199
+ * (`lockedControlViolation`), read off the claim the batch already makes for
1200
+ * it. A comment changes nothing a lock guards, so it touches nothing.
1201
+ */
1202
+ const lockTouchesOf = (item, claim) => {
1203
+ switch (claim.type) {
1204
+ case "text":
1205
+ case "split": return [{
1206
+ from: claim.from,
1207
+ to: claim.to,
1208
+ effect: "edit"
1209
+ }];
1210
+ case "annotation": return item.operation.type === "formatRange" ? [{
1211
+ from: claim.from,
1212
+ to: claim.to,
1213
+ effect: "edit"
1214
+ }] : [];
1215
+ case "rewriteBlock": {
1216
+ const content = {
1217
+ from: claim.block + 1,
1218
+ to: item.blockTo - 1
1219
+ };
1220
+ return [{
1221
+ ...content,
1222
+ effect: "remove"
1223
+ }, {
1224
+ ...content,
1225
+ effect: "edit"
1226
+ }];
1227
+ }
1228
+ case "paragraphProperties": return [{
1229
+ from: claim.block,
1230
+ to: claim.block,
1231
+ effect: "edit"
1232
+ }];
1233
+ case "deleteBlock": return [{
1234
+ from: claim.block,
1235
+ to: claim.end,
1236
+ effect: "remove"
1237
+ }];
1238
+ case "merge": return [{
1239
+ from: claim.next - 1,
1240
+ to: claim.next + 1,
1241
+ effect: "remove"
1242
+ }];
1243
+ case "insertion": return [{
1244
+ from: claim.at,
1245
+ to: claim.at,
1246
+ effect: "edit"
1247
+ }];
1248
+ case "tableRemoval": return claim.ranges.map(({ from, to }) => ({
1249
+ from,
1250
+ to,
1251
+ effect: "remove"
1252
+ }));
1253
+ case "tableStructure": return [{
1254
+ from: claim.table,
1255
+ to: claim.table,
1256
+ effect: "edit"
1257
+ }, ...claim.folded.map(({ from, to }) => ({
1258
+ from,
1259
+ to,
1260
+ effect: "remove"
1261
+ }))];
1262
+ case "unclaimed": return [];
1263
+ default: return panic("Unhandled batch claim", { claim });
1264
+ }
1265
+ };
1266
+ /**
1198
1267
  * The snapshot recorded an `hashOccurrenceCount` per anchor but
1199
1268
  * not which ordinal within that bucket the block was — recompute
1200
1269
  * on demand from the snapshot's anchor map. Stable iteration
@@ -2814,6 +2883,7 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
2814
2883
  const claimedTableRows = /* @__PURE__ */ new Set();
2815
2884
  const claimedTableColumns = /* @__PURE__ */ new Set();
2816
2885
  const batchClaims = new BatchClaims();
2886
+ const lockedControls = () => lockedControlSpans(view.state.doc);
2817
2887
  const removedBlocksBy = /* @__PURE__ */ new Map();
2818
2888
  const diffText = wordDiffMode === "coarse" ? coarseWordDiff : wordDiffSessionFromOptions(wordDiff).diff;
2819
2889
  const producesTrackedChanges = mode !== "direct";
@@ -2941,6 +3011,15 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
2941
3011
  doc: view.state.doc,
2942
3012
  producesTrackedChanges
2943
3013
  });
3014
+ const lockViolation = comparisonApplying() ? null : firstLockedControlViolation(lockedControls(), lockTouchesOf(resolution.operation, claim));
3015
+ if (lockViolation !== null) {
3016
+ skipped.push({
3017
+ id: operation.id,
3018
+ reason: CONTENT_CONTROL_LOCK,
3019
+ message: lockedControlMessage(lockViolation)
3020
+ });
3021
+ continue;
3022
+ }
2944
3023
  const claimedBy = batchClaims.conflictOf(claim);
2945
3024
  if (claimedBy !== null) {
2946
3025
  skipped.push({
@@ -4276,6 +4355,13 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
4276
4355
  });
4277
4356
  continue;
4278
4357
  }
4358
+ if (tr.doc.resolve(item.from).parent !== tr.doc.nodeAt(item.blockFrom)) {
4359
+ skipped.push({
4360
+ id: item.operation.id,
4361
+ reason: "unsupportedBlock"
4362
+ });
4363
+ continue;
4364
+ }
4279
4365
  allocateNewLists({
4280
4366
  status: "willApply",
4281
4367
  items: [item]
@@ -5561,7 +5647,7 @@ const resolveStableBlock = ({ snapshot, blockId, liveBlocks, liveBlocksByParaId,
5561
5647
  noteReferences
5562
5648
  });
5563
5649
  const currentText = cleanBlock.text;
5564
- const currentTextHash = hashFolioAIBlockText(normalizeFolioAIBlockText(currentText));
5650
+ const currentTextHash = hashFolioAIBlockContent(currentText);
5565
5651
  const structuralBoundaryHash = hashFolioAIBlockStructuralBoundaries(cleanBlock);
5566
5652
  if (currentTextHash !== anchor.textHash || structuralBoundaryHash !== anchor.structuralBoundaryHash) return {
5567
5653
  type: "skip",
@@ -6379,4 +6465,4 @@ const getOperationQuote = (operation) => {
6379
6465
  if (operation.type === "replaceInBlock") return operation.find;
6380
6466
  if (operation.type === "commentOnBlock") return operation.quote;
6381
6467
  };
6382
- export { applyFolioAIEditOperations, applyFolioAIEditOperationsInPackage, insertCleanText, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
6468
+ export { SUGGESTED_SUPPORTED_OPERATION_TYPES, applyFolioAIEditOperations, applyFolioAIEditOperationsInPackage, insertCleanText, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
@@ -7,11 +7,17 @@ import { InlineProvenanceTargetOptions } from "../compare/inline-provenance.js";
7
7
  import { ImportReferencedStyleDefinitionsResult } from "../compare/style-resources.js";
8
8
  import { FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult } from "../document-operations.js";
9
9
  import { FolioPendingSuggestionLoadResult, FolioPendingSuggestionRecord } from "./pending-suggestions.js";
10
- import { FolioReviewChange, FolioReviewChangeKind } from "./read.js";
10
+ import { FolioReviewChange, FolioReviewChangeKind, FolioReviewResolution, FolioReviewResolutionSkip } from "./read.js";
11
11
  import { FolioStoryTable } from "./snapshot.js";
12
12
  import { TableGeometryPairing } from "./table-geometry.js";
13
13
  import { Node } from "prosemirror-model";
14
14
  import { TaggedErrorClass } from "better-result";
15
+ /**
16
+ * How many document-operation batches a reviewer can step back through.
17
+ * Each entry holds the story's state before and after its batch; older
18
+ * entries are dropped, as an editor's undo history drops its oldest steps.
19
+ */
20
+ export declare const FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT = 100;
15
21
  /** Options for {@link FolioDocxReviewer.fromBuffer}. */
16
22
  export type FolioDocxReviewerOptions = {
17
23
  /** Default author for tracked changes and comments. (default: `"AI"`) */
@@ -319,21 +325,6 @@ export type FolioReviewCommentFilter = {
319
325
  author?: string;
320
326
  done?: boolean;
321
327
  };
322
- /**
323
- * Headless `.docx` reviewer. Parse a buffer, read blocks, apply
324
- * `FolioAIEditOperation`s against the document model, and write the reviewed
325
- * `.docx` back out — no editor instance, no DOM.
326
- *
327
- * @example
328
- * ```ts
329
- * const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { author: "AI" });
330
- * const { blocks } = reviewer.snapshot();
331
- * reviewer.applyOperations([
332
- * { id: "1", type: "replaceInBlock", blockId: blocks[0].id, find: "$50k", replace: "$500k" },
333
- * ], { undefinedReferences: "refuse" });
334
- * const reviewed = await reviewer.toBuffer();
335
- * ```
336
- */
337
328
  export declare class FolioDocxReviewer {
338
329
  /** Default author for tracked changes and comments. */
339
330
  readonly author: string;
@@ -405,8 +396,14 @@ export declare class FolioDocxReviewer {
405
396
  * renumbered — which is right for an insertion that renumbers the items
406
397
  * below it, and wrong for a list whose FORMAT changed. Sorted so two
407
398
  * packages can be compared entry by entry.
399
+ *
400
+ * Read for one story (the main one by default): a header, footer or note
401
+ * starts its lists against the package alone, so the lists it started are
402
+ * defined in its own reading, as its labels are, and in no other story's.
408
403
  */
409
404
  readNumberingDefinitions(): FolioNumberingLevel[];
405
+ /** `null` when the document has no such story. */
406
+ readNumberingDefinitions(story: FolioEditableDocumentStoryHandle): FolioNumberingLevel[] | null;
410
407
  /** Return parsed package metadata without exposing the mutable document model. */
411
408
  getDocumentProperties(): Readonly<NonNullable<document_d_exports.Document["package"]["properties"]>> | null;
412
409
  /** Snapshot one editable story into stable, operation-ready blocks. */
@@ -459,7 +456,11 @@ export declare class FolioDocxReviewer {
459
456
  /** Apply a batch; the notes whose references it deletes or removes follow them. */
460
457
  private applyDocumentOperationsInternal;
461
458
  private applyDocumentOperationsToStoryState;
462
- /** Undo the latest unchanged document-operation batch and its created comments. */
459
+ /**
460
+ * Undo the latest unchanged document-operation batch and its created
461
+ * comments. Only the last {@link FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT}
462
+ * batches are kept; an older handle is `unknownHandle`.
463
+ */
463
464
  undoDocumentOperations(undoHandle: FolioDocumentOperationUndoHandle): FolioDocumentOperationUndoResult;
464
465
  /**
465
466
  * The body blocks with their stable ids, in document order — the same
@@ -551,7 +552,10 @@ export declare class FolioDocxReviewer {
551
552
  * redline. Pass a {@link FolioReviewChange} from {@link getChanges} or its
552
553
  * revision id. Reuses the editor's own accept command headlessly, so the
553
554
  * resolved state persists on {@link toBuffer}. Returns `false` when the
554
- * revision is no longer present (already resolved, or never existed).
555
+ * revision is no longer present (already resolved, or never existed), or
556
+ * when a content control's lock holds it: accepting would change a
557
+ * content-locked control's content or remove a control locked against
558
+ * removal. A held change stays pending as it is.
555
559
  */
556
560
  acceptChange(target: FolioReviewChange | number): boolean;
557
561
  private acceptChangeInternal;
@@ -575,10 +579,15 @@ export declare class FolioDocxReviewer {
575
579
  * Every story, not just the body: a revision in a header or a footnote is
576
580
  * one a reviewer meant to resolve, and leaving it behind means an accepted
577
581
  * document still carries a redline nobody can see from the body.
582
+ *
583
+ * A change a content control's lock holds (see {@link acceptChange}) stays
584
+ * pending as it is and is listed in `skipped`; `resolved` counts the
585
+ * ordinary changes resolved.
578
586
  */
579
- acceptAll(): number;
587
+ acceptAll(): FolioReviewResolution;
580
588
  /** Reject every tracked change in the package. See {@link acceptAll}. */
581
- rejectAll(): number;
589
+ rejectAll(): FolioReviewResolution;
590
+ private resolveAll;
582
591
  private resolveWithSectionReferenceHistory;
583
592
  private resolveEveryFinalSectionChange;
584
593
  private resolveEveryStory;
@@ -598,6 +607,12 @@ export declare class FolioDocxReviewer {
598
607
  */
599
608
  private noteKeysReferencedOutsideBody;
600
609
  private resolveEveryStoryOnce;
610
+ /**
611
+ * Resolve each change of a story a content control's lock does not hold, on
612
+ * its own: the one-pass resolver takes the whole story or nothing. The held
613
+ * changes stay pending as they are and are reported in `skipped`.
614
+ */
615
+ private resolveStoryAroundHeldChanges;
601
616
  private acceptOrdinaryChangesWithSuggestions;
602
617
  /** Resolve ordinary revisions on a detached in-memory document. */
603
618
  toResolvedDocument(decision: "accept" | "reject"): document_d_exports.Document;
@@ -711,4 +726,4 @@ export type ApplyFolioAIEditsToBufferResult = FolioAIEditApplyResult & {
711
726
  * operations to run.
712
727
  */
713
728
  export declare const applyFolioAIEditsToBuffer: (buffer: ArrayBuffer, operations: FolioAIEditOperation[], options?: ApplyFolioAIEditsToBufferOptions) => Promise<ApplyFolioAIEditsToBufferResult>;
714
- export type { FolioReviewChange, FolioReviewChangeKind, FolioRevisionStamp };
729
+ export type { FolioReviewChange, FolioReviewChangeKind, FolioReviewResolution, FolioReviewResolutionSkip, FolioRevisionStamp };
@@ -23,7 +23,7 @@ import { pluginsForHeadlessRevisionResolution } from "../internal/headlessRevisi
23
23
  import { withTrackedSectionEndpointRemoval } from "../internal/sectionEndpointResolution.js";
24
24
  import { captureSectionReferenceInventory, resolvedSectionReferenceLosses, withSectionReferenceResolution } from "../internal/sectionReferenceResolution.js";
25
25
  import { expectCharacterStyleMarkAttrs, expectFootnoteRefMarkAttrs } from "../prosemirror/attrs/index.js";
26
- import { acceptAIEditRevision, acceptSuggestion, getSuggestions, rejectAIEditRevision, rejectAllSuggestions, rejectSuggestion, resolveAllChangesInHeadlessState, suggestionIdOfRevision } from "../prosemirror/commands/comments.js";
26
+ import { acceptAIEditRevision, acceptSuggestion, getSuggestions, rejectAIEditRevision, rejectAllSuggestions, rejectSuggestion, resolveAllChangesInHeadlessState, revisionResolutionLockViolation, suggestionIdOfRevision } from "../prosemirror/commands/comments.js";
27
27
  import { sectionRejectProperties } from "../prosemirror/commands/propertyChangeScope.js";
28
28
  import { allocateCommentId, createCommentIdAllocator, seedCommentAllocator } from "../prosemirror/commentIdAllocator.js";
29
29
  import { fromProseDoc, proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
@@ -33,6 +33,7 @@ import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAll
33
33
  import { getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
34
34
  import { completeNumberingForDoc } from "../prosemirror/listInstanceReferences.js";
35
35
  import "../prosemirror/listMarker.js";
36
+ import { lockedControlSpans } from "../prosemirror/lockedControls.js";
36
37
  import { deleteNoteWithReference, noteDeletionRevisions, noteKeysReferencedIn, noteReferenceStates, noteReferencesRestored, referenceDeletions, referencedNotes } from "../prosemirror/noteReferenceReview.js";
37
38
  import { createDocumentNumberingPlugin, getDocumentNumbering, withDocumentNumbering } from "../prosemirror/plugins/documentNumbering.js";
38
39
  import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
@@ -53,7 +54,7 @@ import { collectNoteReferenceLabels, createFolioAIEditSnapshotWithStyleResolver,
53
54
  import { matchTableGeometry } from "./table-geometry.js";
54
55
  import { tableTemplateCanCrossPackageLosslessly } from "./table-template.js";
55
56
  import { TaggedError, panic } from "better-result";
56
- import { REVIEW_CARRIERS, finalizeParagraphFormatting, numberingLevelEntries, setDocumentBodyComments } from "@stll/docx-core/model";
57
+ import { CONTENT_CONTROL_LOCK, REVIEW_CARRIERS, finalizeParagraphFormatting, lockedControlMessage, numberingLevelEntries, setDocumentBodyComments } from "@stll/docx-core/model";
57
58
  import { reconcileDocumentPartRelationships } from "@stll/docx-core/ops";
58
59
  import { EditorState } from "prosemirror-state";
59
60
  import { ZipArchive } from "@stll/docx-core/zip";
@@ -85,6 +86,12 @@ const createReviewerComment = ({ id, text, author, date }) => ({
85
86
  date: date ?? (/* @__PURE__ */ new Date()).toISOString(),
86
87
  content: [commentTextParagraph(text)]
87
88
  });
89
+ /**
90
+ * How many document-operation batches a reviewer can step back through.
91
+ * Each entry holds the story's state before and after its batch; older
92
+ * entries are dropped, as an editor's undo history drops its oldest steps.
93
+ */
94
+ const FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT = 100;
88
95
  const FOLIO_REVIEWED_VIEWS = Object.freeze([
89
96
  "original",
90
97
  "current-markup",
@@ -238,9 +245,9 @@ const rejectSuggestions = (state) => {
238
245
  return settled;
239
246
  };
240
247
  const createHeadlessPlugins = (styles, numbering) => [
248
+ createDocumentNumberingPlugin(numbering),
241
249
  ...pluginsForHeadlessRevisionResolution(singletonManager.getPlugins()),
242
- createDocumentStylesPlugin(styles),
243
- createDocumentNumberingPlugin(numbering)
250
+ createDocumentStylesPlugin(styles)
244
251
  ];
245
252
  const createStateSnapshot = (state) => createFolioAIEditSnapshotWithStyleResolver(state.doc, getDocumentStyleResolver(state), getDocumentNumbering(state));
246
253
  const formatStorySnapshotForLLM = (snapshot, annotated) => {
@@ -310,6 +317,22 @@ const paragraphPlainText = (paragraph) => {
310
317
  * const reviewed = await reviewer.toBuffer();
311
318
  * ```
312
319
  */
320
+ /**
321
+ * The changes of a story, by revision id, that a content control's lock keeps
322
+ * from being resolved in `mode`: every physical revision of one change is
323
+ * resolved together, so the change is held when resolving them would break a
324
+ * lock. Empty without a locked control.
325
+ */
326
+ const lockHeldChanges = (state, mode) => {
327
+ const held = /* @__PURE__ */ new Map();
328
+ if (lockedControlSpans(state.doc).length === 0) return held;
329
+ for (const { id } of getTrackedChangesFromDoc(state.doc)) {
330
+ const ids = getTrackedChangeGroupIdsFromDoc(state.doc, id);
331
+ const violation = revisionResolutionLockViolation(state, ids, mode);
332
+ if (violation !== null) held.set(id, violation);
333
+ }
334
+ return held;
335
+ };
313
336
  var FolioDocxReviewer = class FolioDocxReviewer {
314
337
  /** Default author for tracked changes and comments. */
315
338
  author;
@@ -692,19 +715,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
692
715
  }
693
716
  });
694
717
  }
695
- /**
696
- * The package's numbering, flattened to what a reader sees: one entry per
697
- * numbering instance and level, with the format and level text that produce
698
- * its labels.
699
- *
700
- * Labels are rendered from these definitions rather than stored on the
701
- * paragraphs, so nothing in a block projection changes when a list is
702
- * renumbered — which is right for an insertion that renumbers the items
703
- * below it, and wrong for a list whose FORMAT changed. Sorted so two
704
- * packages can be compared entry by entry.
705
- */
706
- readNumberingDefinitions() {
707
- return numberingLevelsOf(completeNumberingForDoc(this.baseDocument.package.numbering, this.state.doc)).toSorted((left, right) => left.numId - right.numId || left.level - right.level);
718
+ readNumberingDefinitions(story = MAIN_STORY) {
719
+ const doc = story.type === "main" ? this.state.doc : this.readSecondaryStoryDoc(story);
720
+ if (!doc) return null;
721
+ return numberingLevelsOf(completeNumberingForDoc(this.baseDocument.package.numbering, doc)).toSorted((left, right) => left.numId - right.numId || left.level - right.level);
708
722
  }
709
723
  /** Return parsed package metadata without exposing the mutable document model. */
710
724
  getDocumentProperties() {
@@ -969,17 +983,25 @@ var FolioDocxReviewer = class FolioDocxReviewer {
969
983
  activeSuggestionIds
970
984
  });
971
985
  }
972
- if (result.undoHandle !== null) this.documentOperationUndoEntries.push({
973
- undoHandle: result.undoHandle,
974
- story,
975
- beforeState,
976
- afterState: view.state,
977
- createdCommentsLengthBefore,
978
- createdCommentsLengthAfter: this.createdComments.length
979
- });
986
+ if (result.undoHandle !== null) {
987
+ this.documentOperationUndoEntries.push({
988
+ undoHandle: result.undoHandle,
989
+ story,
990
+ beforeState,
991
+ afterState: view.state,
992
+ createdCommentsLengthBefore,
993
+ createdCommentsLengthAfter: this.createdComments.length
994
+ });
995
+ const excess = this.documentOperationUndoEntries.length - 100;
996
+ if (excess > 0) this.documentOperationUndoEntries.splice(0, excess);
997
+ }
980
998
  return result;
981
999
  }
982
- /** Undo the latest unchanged document-operation batch and its created comments. */
1000
+ /**
1001
+ * Undo the latest unchanged document-operation batch and its created
1002
+ * comments. Only the last {@link FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT}
1003
+ * batches are kept; an older handle is `unknownHandle`.
1004
+ */
983
1005
  undoDocumentOperations(undoHandle) {
984
1006
  const entryIndex = this.documentOperationUndoEntries.findIndex((entry) => entry.undoHandle.type === undoHandle.type && entry.undoHandle.id === undoHandle.id);
985
1007
  if (entryIndex === -1) return {
@@ -1376,7 +1398,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1376
1398
  * redline. Pass a {@link FolioReviewChange} from {@link getChanges} or its
1377
1399
  * revision id. Reuses the editor's own accept command headlessly, so the
1378
1400
  * resolved state persists on {@link toBuffer}. Returns `false` when the
1379
- * revision is no longer present (already resolved, or never existed).
1401
+ * revision is no longer present (already resolved, or never existed), or
1402
+ * when a content control's lock holds it: accepting would change a
1403
+ * content-locked control's content or remove a control locked against
1404
+ * removal. A held change stays pending as it is.
1380
1405
  */
1381
1406
  acceptChange(target) {
1382
1407
  return this.resolveWithSectionReferenceHistory(() => this.withNotesFollowingReferences(() => this.acceptChangeInternal(target)));
@@ -1384,6 +1409,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1384
1409
  acceptChangeInternal(target) {
1385
1410
  const id = revisionIdOf(target);
1386
1411
  const ids = getTrackedChangeGroupIdsFromDoc(this.state.doc, id);
1412
+ if (revisionResolutionLockViolation(this.state, ids, "accept") !== null) return false;
1387
1413
  const suggestionId = suggestionIdOfRevision(this.state, id);
1388
1414
  if (suggestionId !== null && !this.runCommand(acceptSuggestion(suggestionId, { author: this.author }))) return false;
1389
1415
  let bodyChanged = false;
@@ -1401,6 +1427,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1401
1427
  rejectChangeInternal(target) {
1402
1428
  const id = revisionIdOf(target);
1403
1429
  const ids = getTrackedChangeGroupIdsFromDoc(this.state.doc, id);
1430
+ if (revisionResolutionLockViolation(this.state, ids, "reject") !== null) return false;
1404
1431
  const suggestionId = suggestionIdOfRevision(this.state, id);
1405
1432
  if (suggestionId !== null && this.runCommand(rejectSuggestion(suggestionId))) return true;
1406
1433
  let bodyChanged = false;
@@ -1440,13 +1467,26 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1440
1467
  * Every story, not just the body: a revision in a header or a footnote is
1441
1468
  * one a reviewer meant to resolve, and leaving it behind means an accepted
1442
1469
  * document still carries a redline nobody can see from the body.
1470
+ *
1471
+ * A change a content control's lock holds (see {@link acceptChange}) stays
1472
+ * pending as it is and is listed in `skipped`; `resolved` counts the
1473
+ * ordinary changes resolved.
1443
1474
  */
1444
1475
  acceptAll() {
1445
- return this.resolveWithSectionReferenceHistory(() => this.resolveEveryStory("accept") + this.resolveEveryFinalSectionChange("accept"));
1476
+ return this.resolveAll("accept");
1446
1477
  }
1447
1478
  /** Reject every tracked change in the package. See {@link acceptAll}. */
1448
1479
  rejectAll() {
1449
- return this.resolveWithSectionReferenceHistory(() => this.resolveEveryStory("reject") + this.resolveEveryFinalSectionChange("reject"));
1480
+ return this.resolveAll("reject");
1481
+ }
1482
+ resolveAll(mode) {
1483
+ return this.resolveWithSectionReferenceHistory(() => {
1484
+ const skipped = [];
1485
+ return {
1486
+ resolved: this.resolveEveryStory(mode, skipped) + this.resolveEveryFinalSectionChange(mode),
1487
+ skipped
1488
+ };
1489
+ });
1450
1490
  }
1451
1491
  resolveWithSectionReferenceHistory(resolve) {
1452
1492
  const before = captureSectionReferenceInventory(this.state.doc, this.currentFinalSectionProperties());
@@ -1482,8 +1522,8 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1482
1522
  });
1483
1523
  return propertyChanges?.length ?? 0;
1484
1524
  }
1485
- resolveEveryStory(mode) {
1486
- return this.withNotesFollowingReferences(() => this.resolveEveryStoryOnce(mode));
1525
+ resolveEveryStory(mode, skipped) {
1526
+ return this.withNotesFollowingReferences(() => this.resolveEveryStoryOnce(mode, skipped));
1487
1527
  }
1488
1528
  /**
1489
1529
  * Change the body the way a note follows its reference: a note whose
@@ -1553,13 +1593,18 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1553
1593
  }
1554
1594
  return keys;
1555
1595
  }
1556
- resolveEveryStoryOnce(mode) {
1596
+ resolveEveryStoryOnce(mode, skipped) {
1557
1597
  let count = 0;
1558
1598
  const resolvedStories = [];
1559
1599
  const refreshes = [];
1560
1600
  for (const handle of this.listStoryHandlesInternal()) {
1561
1601
  const state = this.getEditableStoryState(handle);
1562
1602
  if (!state) continue;
1603
+ const held = lockHeldChanges(state, mode);
1604
+ if (held.size > 0) {
1605
+ count += this.resolveStoryAroundHeldChanges(handle, mode, held, skipped);
1606
+ continue;
1607
+ }
1563
1608
  const ordinaryCount = getTrackedChangesFromDoc(state.doc).filter(({ id }) => mode === "reject" || suggestionIdOfRevision(state, id) === null).length;
1564
1609
  count += ordinaryCount;
1565
1610
  const withSuggestions = mode === "accept" && ordinaryCount > 0 && getSuggestions(state).length > 0 ? this.acceptOrdinaryChangesWithSuggestions(state, handle) : null;
@@ -1580,6 +1625,31 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1580
1625
  }
1581
1626
  return count;
1582
1627
  }
1628
+ /**
1629
+ * Resolve each change of a story a content control's lock does not hold, on
1630
+ * its own: the one-pass resolver takes the whole story or nothing. The held
1631
+ * changes stay pending as they are and are reported in `skipped`.
1632
+ */
1633
+ resolveStoryAroundHeldChanges(handle, mode, held, skipped) {
1634
+ for (const [id, violation] of held) skipped.push({
1635
+ id,
1636
+ reason: CONTENT_CONTROL_LOCK,
1637
+ message: lockedControlMessage(violation)
1638
+ });
1639
+ const state = this.getEditableStoryState(handle);
1640
+ if (!state) return 0;
1641
+ let resolved = 0;
1642
+ for (const { id } of getTrackedChangesFromDoc(state.doc).toReversed()) {
1643
+ if (held.has(id)) continue;
1644
+ const current = this.getEditableStoryState(handle);
1645
+ if (!current) break;
1646
+ const ids = getTrackedChangeGroupIdsFromDoc(current.doc, id);
1647
+ if (ids.length === 0) continue;
1648
+ const resolveOne = mode === "accept" ? acceptAIEditRevision(ids) : rejectAIEditRevision(ids);
1649
+ if (this.runStoryCommand(resolveOne, handle)) resolved += 1;
1650
+ }
1651
+ return resolved;
1652
+ }
1583
1653
  acceptOrdinaryChangesWithSuggestions(state, story) {
1584
1654
  const originalSuggestions = getSuggestions(state);
1585
1655
  const records = this.exportPendingSuggestions().filter((record) => editableStoryKey(record.story) === editableStoryKey(story));
@@ -1775,7 +1845,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1775
1845
  }));
1776
1846
  }
1777
1847
  if (kept.length !== definitions.length || snapshot.createdComments.length > 0 || snapshot.resolvedOverrides.size > 0) setDocumentBodyComments(document.package.document, this.withResolvedOverrides(kept, snapshot.resolvedOverrides));
1778
- const normalized = normalizeListModelRendering(reconcileDocumentPartRelationships(document)).document;
1848
+ const normalized = normalizeListModelRendering(reconcileDocumentPartRelationships(document), { inverse: "omit" }).document;
1779
1849
  visitDocxParagraphs({
1780
1850
  documentBody: normalized.package.document,
1781
1851
  headers: normalized.package.headers,
@@ -2310,4 +2380,4 @@ const applyFolioAIEditsToBuffer = async (buffer, operations, options = {}) => {
2310
2380
  skipped
2311
2381
  };
2312
2382
  };
2313
- export { FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FolioDocumentStoryNotFoundError, FolioDocxReviewer, UnsupportedFolioReviewedViewError, applyFolioAIEditsToBuffer, getFolioDocxComparisonAccess, isFolioResolvedReviewedView, isFolioReviewedView };
2383
+ export { FOLIO_DOCUMENT_OPERATION_UNDO_LIMIT, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FolioDocumentStoryNotFoundError, FolioDocxReviewer, UnsupportedFolioReviewedViewError, applyFolioAIEditsToBuffer, getFolioDocxComparisonAccess, isFolioResolvedReviewedView, isFolioReviewedView };
@@ -6,10 +6,10 @@ import { DocPositionRange, clampRangeToDocSize, resolveFolioAIBlockRange, resolv
6
6
  import { buildAnnotatedBlockText } from "./clean-text.js";
7
7
  import { ApplyFolioDocumentOperationsOptions, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationResultBase, FolioDocumentOperationStatus, FolioDocumentOperationStory, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "../document-operations.js";
8
8
  import { FOLIO_PENDING_SUGGESTION_VERSION, FolioPendingSuggestionLoadResult, FolioPendingSuggestionRecord, FolioPendingSuggestionRegistry, FolioPendingSuggestionStaleReason, createPendingSuggestionSourceSnapshot } from "./pending-suggestions.js";
9
- import { FolioCommentAnchor, FolioReviewChange, FolioReviewChangeKind, getCommentAnchorsFromDoc, getTrackedChangesFromDoc } from "./read.js";
9
+ import { FolioCommentAnchor, FolioReviewChange, FolioReviewChangeKind, FolioReviewResolution, FolioReviewResolutionSkip, getCommentAnchorsFromDoc, getTrackedChangesFromDoc } from "./read.js";
10
10
  import { createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, hashFolioAIBlockText, isFolioAIContentBlock, normalizeFolioAIBlockText } from "./snapshot.js";
11
11
  import { FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FolioApplyDocumentOperationsToStoryOptions, FolioDocumentStory, FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, FolioEditableDocumentStoryHandle, FolioReadReviewedStoryOptions, FolioResolveReviewedStoryOptions, FolioResolvedReviewedView, FolioReviewedStory, FolioReviewedView, UnsupportedFolioReviewedViewError, isFolioResolvedReviewedView, isFolioReviewedView } from "./headless.js";
12
12
  import { getFolioDocumentOutline, readFolioDocumentSection } from "./scoped-reading.js";
13
13
  import { getFolioDocumentOperationRemovedBlockIds } from "./removed-blocks.js";
14
14
  import { getFolioParaIdFromBlockId } from "../types/block-id.js";
15
- export { type ApplyFolioDocumentOperationsOptions, type DocPositionRange, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_PENDING_SUGGESTION_VERSION, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIBlockTableLocation, type FolioAIComment, type FolioAIDiagnosticBlock, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyOutcome, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAIEditView, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIInsertFormattingScope, type FolioAIParagraphBlock, type FolioAIParagraphSpacing, type FolioAISignatureParty, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsToStoryOptions, type FolioCommentAnchor, type FolioContentParagraphKind, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, type FolioEditableDocumentStoryHandle, type FolioPendingSuggestionLoadResult, type FolioPendingSuggestionRecord, FolioPendingSuggestionRegistry, type FolioPendingSuggestionStaleReason, type FolioReadReviewedStoryOptions, type FolioResolveReviewedStoryOptions, type FolioResolvedReviewedView, type FolioReviewChange, type FolioReviewChangeKind, type FolioReviewedStory, type FolioReviewedView, type FolioRevisionStamp, type FolioUndefinedReferencePolicy, type FolioWordDiffOptions, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioReviewedViewError, WORD_DIFF_GRANULARITIES, type WordDiffGranularity, type WordDiffNormalization, type WordDiffOptions, type WordDiffSegment, applyFolioAIEditOperations, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, buildAnnotatedBlockText, clampRangeToDocSize, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, createPendingSuggestionSourceSnapshot, diffWordSegments, getCommentAnchorsFromDoc, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOperationRemovedBlockIds, getFolioDocumentOutline, getFolioParaIdFromBlockId, getTrackedChangesFromDoc, hashFolioAIBlockText, isFolioAIContentBlock, isFolioDocumentOperationModeSupported, isFolioResolvedReviewedView, isFolioReviewedView, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, readFolioDocumentSection, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange };
15
+ export { type ApplyFolioDocumentOperationsOptions, type DocPositionRange, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_PENDING_SUGGESTION_VERSION, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIBlockTableLocation, type FolioAIComment, type FolioAIDiagnosticBlock, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyOutcome, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAIEditView, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIInsertFormattingScope, type FolioAIParagraphBlock, type FolioAIParagraphSpacing, type FolioAISignatureParty, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsToStoryOptions, type FolioCommentAnchor, type FolioContentParagraphKind, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, type FolioEditableDocumentStoryHandle, type FolioPendingSuggestionLoadResult, type FolioPendingSuggestionRecord, FolioPendingSuggestionRegistry, type FolioPendingSuggestionStaleReason, type FolioReadReviewedStoryOptions, type FolioResolveReviewedStoryOptions, type FolioResolvedReviewedView, type FolioReviewChange, type FolioReviewChangeKind, type FolioReviewResolution, type FolioReviewResolutionSkip, type FolioReviewedStory, type FolioReviewedView, type FolioRevisionStamp, type FolioUndefinedReferencePolicy, type FolioWordDiffOptions, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioReviewedViewError, WORD_DIFF_GRANULARITIES, type WordDiffGranularity, type WordDiffNormalization, type WordDiffOptions, type WordDiffSegment, applyFolioAIEditOperations, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, buildAnnotatedBlockText, clampRangeToDocSize, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, createPendingSuggestionSourceSnapshot, diffWordSegments, getCommentAnchorsFromDoc, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOperationRemovedBlockIds, getFolioDocumentOutline, getFolioParaIdFromBlockId, getTrackedChangesFromDoc, hashFolioAIBlockText, isFolioAIContentBlock, isFolioDocumentOperationModeSupported, isFolioResolvedReviewedView, isFolioReviewedView, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, readFolioDocumentSection, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange };
@@ -63,6 +63,12 @@ export declare const cutsIntoNoteReference: ({ structuralBoundaries }: Structura
63
63
  export declare const withComparisonNoteReferenceEdits: <T>(apply: () => T) => T;
64
64
  /** @internal Whether the running apply belongs to a comparison (see above). */
65
65
  export declare const noteReferenceEditsAllowed: () => boolean;
66
+ /**
67
+ * @internal Whether the running apply belongs to a comparison. Its operations
68
+ * describe differences two documents already hold, so the content-control
69
+ * locks, which guard editing a document, do not refuse them.
70
+ */
71
+ export declare const comparisonApplying: () => boolean;
66
72
  /** The pieces of a replacement between the markers it has to keep. */
67
73
  type NoteReferenceSegments = {
68
74
  /** The source text between markers, with its offset in the source. */
@@ -78,6 +78,12 @@ const withComparisonNoteReferenceEdits = (apply) => {
78
78
  };
79
79
  /** @internal Whether the running apply belongs to a comparison (see above). */
80
80
  const noteReferenceEditsAllowed = () => comparisonEditsNoteReferences;
81
+ /**
82
+ * @internal Whether the running apply belongs to a comparison. Its operations
83
+ * describe differences two documents already hold, so the content-control
84
+ * locks, which guard editing a document, do not refuse them.
85
+ */
86
+ const comparisonApplying = () => comparisonEditsNoteReferences;
81
87
  const NOTE_MARKER_PATTERN = /\[\^e?[1-9]\d*\]/gu;
82
88
  const markerCount = (text) => text.match(NOTE_MARKER_PATTERN)?.length ?? 0;
83
89
  /**
@@ -135,4 +141,4 @@ const planChangesAroundNoteReferences = (source, replacement, spans, planChanges
135
141
  text: change.text
136
142
  })));
137
143
  };
138
- export { createNoteReferenceLabeler, cutsIntoNoteReference, noteReferenceEditsAllowed, noteReferenceOf, noteReferenceSpansWithin, planChangesAroundNoteReferences, readerTextOf, segmentsAroundNoteReferences, withComparisonNoteReferenceEdits };
144
+ export { comparisonApplying, createNoteReferenceLabeler, cutsIntoNoteReference, noteReferenceEditsAllowed, noteReferenceOf, noteReferenceSpansWithin, planChangesAroundNoteReferences, readerTextOf, segmentsAroundNoteReferences, withComparisonNoteReferenceEdits };