@stll/folio-core 0.67.0 → 0.69.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 (350) 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 +106 -36
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  7. package/dist/ai-edits/newListNumbering.js +24 -1
  8. package/dist/ai-edits/note-references.d.ts +6 -0
  9. package/dist/ai-edits/note-references.js +7 -1
  10. package/dist/ai-edits/pending-suggestions.js +2 -2
  11. package/dist/ai-edits/read.d.ts +19 -0
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +8 -3
  14. package/dist/ai-edits/types.d.ts +9 -1
  15. package/dist/ai-suggestions/apply.js +13 -4
  16. package/dist/compare/compare.js +2 -1
  17. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  18. package/dist/compare/inserted-resource-snapshot.js +7 -3
  19. package/dist/controller/canonicalClipboard.js +31 -14
  20. package/dist/controller/canonicalComposition.js +35 -6
  21. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  22. package/dist/controller/canonicalInlineProjection.js +192 -28
  23. package/dist/controller/canonicalInput.d.ts +2 -1
  24. package/dist/controller/canonicalInput.js +32 -7
  25. package/dist/controller/canonicalListRendering.d.ts +2 -1
  26. package/dist/controller/canonicalListRendering.js +1 -1
  27. package/dist/controller/canonicalLockGuard.d.ts +23 -0
  28. package/dist/controller/canonicalLockGuard.js +133 -0
  29. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  30. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  31. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  32. package/dist/controller/canonicalPublicOperations.js +676 -46
  33. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  34. package/dist/controller/canonicalSeedContent.js +131 -0
  35. package/dist/controller/canonicalSession.d.ts +133 -21
  36. package/dist/controller/canonicalSession.js +738 -205
  37. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  38. package/dist/controller/canonicalSourceNormalization.js +148 -0
  39. package/dist/controller/canonicalStoryEditor.d.ts +4 -3
  40. package/dist/controller/canonicalStoryEditor.js +20 -15
  41. package/dist/controller/canonicalStructure.d.ts +2 -1
  42. package/dist/controller/canonicalStructure.js +129 -7
  43. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  44. package/dist/controller/contentControlWidgetController.js +13 -1
  45. package/dist/controller/folioEditor.js +4 -0
  46. package/dist/controller/headerFooterEditorManager.d.ts +7 -2
  47. package/dist/controller/headerFooterEditorManager.js +11 -6
  48. package/dist/controller/hiddenEditorApi.d.ts +17 -2
  49. package/dist/controller/hiddenEditorApi.js +4 -0
  50. package/dist/controller/hiddenEditorManager.d.ts +11 -3
  51. package/dist/controller/hiddenEditorManager.js +157 -48
  52. package/dist/controller/layoutPipeline.js +50 -16
  53. package/dist/controller/layoutSession.d.ts +3 -0
  54. package/dist/controller/layoutSession.js +3 -1
  55. package/dist/controller/noteEditorManager.d.ts +7 -2
  56. package/dist/controller/noteEditorManager.js +11 -6
  57. package/dist/display-list/build/pageFurniture.js +41 -19
  58. package/dist/display-list/build/tablePrimitives.js +23 -4
  59. package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
  60. package/dist/document-operations.d.ts +9 -1
  61. package/dist/document-operations.js +4 -3
  62. package/dist/docx/blockContentParser.d.ts +7 -3
  63. package/dist/docx/blockContentParser.js +2 -3
  64. package/dist/docx/blockPlainText.js +2 -0
  65. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  66. package/dist/docx/bookmarkRangeJoin.js +43 -0
  67. package/dist/docx/canonicalSave.js +11 -2
  68. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  69. package/dist/docx/canonicalSessionInput.js +7 -2
  70. package/dist/docx/commentAnchorIndex.d.ts +40 -5
  71. package/dist/docx/commentAnchorIndex.js +94 -12
  72. package/dist/docx/commentRangeIntegrity.js +30 -24
  73. package/dist/docx/commentRangeJoin.d.ts +4 -0
  74. package/dist/docx/commentRangeJoin.js +26 -12
  75. package/dist/docx/commentReferenceCompletion.js +5 -4
  76. package/dist/docx/commentReferenceNormalization.js +40 -18
  77. package/dist/docx/compatibility.js +9 -2
  78. package/dist/docx/containerChildren.js +22 -1
  79. package/dist/docx/contentTypeRegistry.js +1 -1
  80. package/dist/docx/encryption/compoundFile.js +9 -1
  81. package/dist/docx/encryption/encryptionInfo.js +16 -2
  82. package/dist/docx/ensureParaIds.js +46 -7
  83. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  84. package/dist/docx/ensureUniqueControlIds.js +110 -0
  85. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  86. package/dist/docx/headerFooterVerbatim.js +13 -2
  87. package/dist/docx/hostCommentThreads.d.ts +27 -0
  88. package/dist/docx/hostCommentThreads.js +72 -0
  89. package/dist/docx/hyperlinkParser.js +9 -2
  90. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  91. package/dist/docx/inlineWrapperContent.js +9 -2
  92. package/dist/docx/listMarkerComputation.d.ts +35 -1
  93. package/dist/docx/listMarkerComputation.js +39 -1
  94. package/dist/docx/listModelNormalization.d.ts +44 -1
  95. package/dist/docx/listModelNormalization.js +226 -96
  96. package/dist/docx/listNumberingInstances.d.ts +1 -1
  97. package/dist/docx/listNumberingInstances.js +2 -2
  98. package/dist/docx/markupRangeMarker.d.ts +14 -0
  99. package/dist/docx/markupRangeMarker.js +15 -1
  100. package/dist/docx/metadataPrivacy.js +43 -22
  101. package/dist/docx/normalizeBaseDirection.js +3 -1
  102. package/dist/docx/numberingIds.d.ts +6 -0
  103. package/dist/docx/numberingIds.js +6 -1
  104. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  105. package/dist/docx/numberingReferenceNormalization.js +12 -2
  106. package/dist/docx/paragraphParser.js +159 -48
  107. package/dist/docx/paragraphPropertySource.d.ts +29 -0
  108. package/dist/docx/paragraphPropertySource.js +106 -16
  109. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  110. package/dist/docx/paragraphTraversal.js +2 -0
  111. package/dist/docx/parseWarningMessage.js +2 -1
  112. package/dist/docx/parser.js +8 -0
  113. package/dist/docx/removeHeaderFooterParts.js +1 -1
  114. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  115. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  116. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  117. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  118. package/dist/docx/reviewResolutionProvenance.js +171 -33
  119. package/dist/docx/rezip.d.ts +6 -0
  120. package/dist/docx/rezip.js +38 -21
  121. package/dist/docx/selectiveSave.js +6 -10
  122. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  123. package/dist/docx/selectiveXmlPatch.js +11 -7
  124. package/dist/docx/serializer/documentSerializer.js +5 -2
  125. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  126. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  127. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  128. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  129. package/dist/docx/serializer/noteSerializer.js +23 -16
  130. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  131. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  132. package/dist/docx/serializer/partNamespaces.js +1 -1
  133. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  134. package/dist/docx/serializer/runSerializer.js +2 -2
  135. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  136. package/dist/docx/serializer/tableSerializer.js +4 -2
  137. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  138. package/dist/docx/server/build.d.ts +1 -1
  139. package/dist/docx/server/createBilingualDocument.js +27 -5
  140. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  141. package/dist/docx/sessionListPruning.d.ts +2 -0
  142. package/dist/docx/sessionListPruning.js +50 -0
  143. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  144. package/dist/docx/splitRevisionPieces.js +14 -0
  145. package/dist/docx/storyBlockReplay.js +19 -2
  146. package/dist/docx/structuralXmlPatch.js +44 -11
  147. package/dist/docx/tableParser.d.ts +6 -2
  148. package/dist/docx/tableParser.js +2 -3
  149. package/dist/docx/textBoxContentParser.d.ts +11 -0
  150. package/dist/docx/textBoxContentParser.js +51 -0
  151. package/dist/docx/textBoxParser.d.ts +0 -5
  152. package/dist/docx/textBoxParser.js +1 -23
  153. package/dist/docx/verticalMergeProjection.js +1 -1
  154. package/dist/docx/xmlParser.d.ts +1 -1
  155. package/dist/docx/xmlParser.js +2 -3
  156. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  157. package/dist/fonts/fontsourceFaces.js +1 -7
  158. package/dist/i18n/messages/ar.gen.js +3 -0
  159. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  160. package/dist/i18n/messages/catalogs.gen.js +51 -0
  161. package/dist/i18n/messages/cs.gen.js +3 -0
  162. package/dist/i18n/messages/de.gen.js +3 -0
  163. package/dist/i18n/messages/en.gen.js +3 -0
  164. package/dist/i18n/messages/es.gen.js +3 -0
  165. package/dist/i18n/messages/et.gen.js +3 -0
  166. package/dist/i18n/messages/fr.gen.js +3 -0
  167. package/dist/i18n/messages/he.gen.js +3 -0
  168. package/dist/i18n/messages/hi.gen.js +3 -0
  169. package/dist/i18n/messages/hu.gen.js +3 -0
  170. package/dist/i18n/messages/lt.gen.js +3 -0
  171. package/dist/i18n/messages/lv.gen.js +3 -0
  172. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  173. package/dist/i18n/messages/pl.gen.js +3 -0
  174. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  175. package/dist/i18n/messages/sk.gen.js +3 -0
  176. package/dist/i18n/messages/tr.gen.js +3 -0
  177. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  178. package/dist/internal/acceptedBlockProjection.js +2 -0
  179. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  180. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  181. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  182. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  183. package/dist/internal/revisionResolutionInline.js +1 -2
  184. package/dist/internal/subtreeHolds.d.ts +12 -0
  185. package/dist/internal/subtreeHolds.js +25 -0
  186. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  187. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  188. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  189. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  190. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  191. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  192. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  193. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  194. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  195. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  196. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  197. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  198. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  199. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  200. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  201. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  202. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  203. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  204. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  205. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  206. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  207. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  208. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  209. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  210. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  211. package/dist/layout-bridge/engine/hitTest.js +9 -10
  212. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  213. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  214. package/dist/layout-bridge/tableInsertHover.js +2 -1
  215. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  216. package/dist/layout-engine/footnoteContinuation.js +210 -0
  217. package/dist/layout-engine/index.d.ts +2 -2
  218. package/dist/layout-engine/index.js +7 -2
  219. package/dist/layout-engine/measure/cache.d.ts +2 -0
  220. package/dist/layout-engine/measure/cache.js +16 -6
  221. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  222. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  223. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  224. package/dist/layout-engine/tableLayout.js +29 -5
  225. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  226. package/dist/layout-engine/tableRowBreak.js +43 -1
  227. package/dist/layout-engine/types.d.ts +42 -1
  228. package/dist/layout-painter/imageLayout.js +2 -1
  229. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  230. package/dist/layout-painter/pageShellStyles.js +32 -0
  231. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  232. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  233. package/dist/layout-painter/renderFragment.js +4 -6
  234. package/dist/layout-painter/renderImage.js +2 -2
  235. package/dist/layout-painter/renderPage.d.ts +4 -4
  236. package/dist/layout-painter/renderPage.js +54 -46
  237. package/dist/layout-painter/renderParagraph.js +3 -3
  238. package/dist/layout-painter/renderTable.js +16 -16
  239. package/dist/layout-painter/renderTextBox.js +2 -2
  240. package/dist/layout-painter/sdtBoundary.js +3 -2
  241. package/dist/managers/AutoSaveManager.d.ts +5 -1
  242. package/dist/managers/FindReplaceManager.js +3 -10
  243. package/dist/markdown/escape.d.ts +20 -1
  244. package/dist/markdown/escape.js +43 -1
  245. package/dist/markdown/renderBlock.js +4 -1
  246. package/dist/markdown/renderParagraph.js +13 -27
  247. package/dist/markdown/renderTable.js +6 -2
  248. package/dist/markdown/trailers.js +1 -0
  249. package/dist/paged-layout/blockGeometry.js +3 -2
  250. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  251. package/dist/paged-layout/editorScrollRoot.js +10 -1
  252. package/dist/paged-layout/rangeProjection.js +5 -4
  253. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  254. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  255. package/dist/paged-layout/selectionViewportRect.js +8 -2
  256. package/dist/pdf/images.d.ts +17 -1
  257. package/dist/pdf/images.js +22 -4
  258. package/dist/pdf/writePdf.js +4 -2
  259. package/dist/prosemirror/attrs/index.js +2 -0
  260. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  261. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  262. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  263. package/dist/prosemirror/commands/comments.d.ts +30 -2
  264. package/dist/prosemirror/commands/comments.js +189 -18
  265. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  266. package/dist/prosemirror/commands/index.d.ts +1 -1
  267. package/dist/prosemirror/commentIdAllocator.js +2 -2
  268. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  269. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  270. package/dist/prosemirror/commentRecords.d.ts +137 -0
  271. package/dist/prosemirror/commentRecords.js +400 -0
  272. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  273. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  274. package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
  275. package/dist/prosemirror/conversion/index.d.ts +2 -2
  276. package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
  277. package/dist/prosemirror/conversion/toProseDoc.js +432 -76
  278. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  279. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  280. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  281. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  282. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  283. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
  284. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  285. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  286. package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
  287. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  288. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  289. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  290. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  291. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  292. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  293. package/dist/prosemirror/index.d.ts +3 -3
  294. package/dist/prosemirror/listLabels.js +3 -2
  295. package/dist/prosemirror/listNumbering.d.ts +6 -0
  296. package/dist/prosemirror/listNumbering.js +12 -9
  297. package/dist/prosemirror/lockedControls.d.ts +13 -0
  298. package/dist/prosemirror/lockedControls.js +106 -0
  299. package/dist/prosemirror/markupViewProjection.js +1 -1
  300. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  301. package/dist/prosemirror/nativeSelection.js +74 -0
  302. package/dist/prosemirror/noteReferenceReview.js +2 -2
  303. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  304. package/dist/prosemirror/numberedRefFields.js +16 -5
  305. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  306. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  307. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  308. package/dist/prosemirror/plugins/documentNumbering.js +37 -15
  309. package/dist/prosemirror/plugins/suggestionMode.js +33 -10
  310. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  311. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  312. package/dist/prosemirror/replacedAnnotations.js +1 -0
  313. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  314. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  315. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  316. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  317. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  318. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  319. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  320. package/dist/prosemirror/runStyleFormatting.js +16 -13
  321. package/dist/prosemirror/schema/marks.d.ts +13 -1
  322. package/dist/prosemirror/storyListNumbering.js +7 -2
  323. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  324. package/dist/prosemirror/tableResize.d.ts +10 -9
  325. package/dist/prosemirror/tableResize.js +60 -49
  326. package/dist/prosemirror/textInput.d.ts +30 -1
  327. package/dist/prosemirror/textInput.js +144 -17
  328. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  329. package/dist/prosemirror/validation.d.ts +19 -0
  330. package/dist/prosemirror/validation.js +79 -5
  331. package/dist/redline.js +23 -9
  332. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  333. package/dist/render-dom/RenderedDomContext.js +7 -6
  334. package/dist/server.d.ts +2 -2
  335. package/dist/style-sets/extract.js +2 -2
  336. package/dist/types/canonicalCapabilities.d.ts +38 -16
  337. package/dist/types/canonicalCapabilities.js +21 -18
  338. package/dist/utils/cssString.d.ts +7 -0
  339. package/dist/utils/cssString.js +9 -0
  340. package/dist/utils/findMatchView.js +4 -3
  341. package/dist/utils/fontResolver.js +4 -1
  342. package/dist/utils/formatToStyle.d.ts +1 -1
  343. package/dist/utils/mergeDocumentContent.js +2 -2
  344. package/dist/utils/paintedPositions.d.ts +60 -0
  345. package/dist/utils/paintedPositions.js +101 -0
  346. package/dist/utils/replaceText.d.ts +11 -0
  347. package/dist/utils/replaceText.js +39 -7
  348. package/dist/version-comparison.d.ts +9 -1
  349. package/dist/version-comparison.js +11 -5
  350. package/package.json +2 -3
@@ -3,8 +3,9 @@ import { markParagraphPropertySourceTransfers } from "../../docx/paragraphProper
3
3
  import { RevisionResolutionStep } from "../../internal/revisionResolutionStep.js";
4
4
  import { finalRevisionParagraphRanges } from "../../internal/revisionResolutionTracking.js";
5
5
  import { deleteTextBoxesAnchoredAt, droppedTextBoxAnchorIds, moveTextBoxesPastNextParagraph } from "../anchoredTextBoxes.js";
6
- import { expectFieldAttrs, expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
7
- import { readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
6
+ import { expectCommentMarkAttrs, expectFieldAttrs, expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
7
+ import { isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
8
+ import { retireThreadsResolvedAway } from "../commentRecords.js";
8
9
  import { addedBreakCarrierBefore, finalParagraphsOf } from "../containerFinalParagraph.js";
9
10
  import { enclosingRevisionIds, resolutionRemovesControl, withoutResolvedEnclosures } from "../contentControlRevisions.js";
10
11
  import { copyOriginBoundaryAttrsAfterResolution } from "../copyOriginResolution.js";
@@ -15,6 +16,7 @@ import { markChangedParagraphRanges, markStructuralChange, markTrackedSectionEnd
15
16
  import "../extensions/nodes/SdtExtension.js";
16
17
  import { canonicalFieldNode } from "../fieldRepresentation.js";
17
18
  import { isBlockBoundaryNode, normalizeKeptRangeBoundaries, paragraphRemainsOf, removeResolvedSubtree, revisionLayerRemovesContent } from "../keptRangeBoundaries.js";
19
+ import { lockedControlSpans, lockedControlViolationOfTransform } from "../lockedControls.js";
18
20
  import { resolveStateStory } from "../markupViewProjection.js";
19
21
  import { joinAtParagraphMark } from "../paragraphMarkJoin.js";
20
22
  import { carryParagraphProperties, paragraphLeftAfter } from "../paragraphPropertyCarry.js";
@@ -47,6 +49,7 @@ import { Fragment } from "prosemirror-model";
47
49
  import { TableMap } from "prosemirror-tables";
48
50
  import { Mapping } from "prosemirror-transform";
49
51
  import { paragraphMarkOutcome } from "@stll/docx-core/ops";
52
+ import { closeHistory } from "prosemirror-history";
50
53
  // src/prosemirror/commands/comments.ts
51
54
  /**
52
55
  * Comment and Track Changes Commands
@@ -85,8 +88,17 @@ function removeCommentMark(commentId) {
85
88
  return true;
86
89
  };
87
90
  }
91
+ /**
92
+ * What every review resolution does before it is dispatched: it retires the
93
+ * comment threads it left without an anchor, and it is an undo step of its
94
+ * own, never merged into the edit it resolves.
95
+ */
96
+ const finishResolution = (state, tr) => {
97
+ retireThreadsResolvedAway(state, tr);
98
+ closeHistory(tr);
99
+ };
88
100
  const keptIn = (range) => range.removals.flatMap(({ kept }) => kept);
89
- function resolveChange(from, to, mode, revisionIds) {
101
+ function resolveChangeUnguarded(from, to, mode, revisionIds) {
90
102
  return (state, dispatch) => {
91
103
  const insertionType = state.schema.marks["insertion"];
92
104
  const deletionType = state.schema.marks["deletion"];
@@ -522,7 +534,7 @@ function resolveChange(from, to, mode, revisionIds) {
522
534
  });
523
535
  return false;
524
536
  }
525
- if (node.type.name === "commentRangeBoundary") {
537
+ if (isCommentRangeBoundaryNode(node)) {
526
538
  const attrs = readCommentRangeBoundaryAttrs(node);
527
539
  if (attrs.ok && doomed.has(attrs.value.marker.id)) {
528
540
  carriers.push({
@@ -547,6 +559,7 @@ function resolveChange(from, to, mode, revisionIds) {
547
559
  for (const carrier of carriers.toReversed()) tr.delete(carrier.position, carrier.position + carrier.size);
548
560
  }
549
561
  normalizeKeptRangeBoundaries(tr, keptBoundaries);
562
+ finishResolution(state, tr);
550
563
  if (tr.steps.length > 0) dispatch(tr);
551
564
  }
552
565
  return true;
@@ -894,6 +907,50 @@ function findParagraphBoundaryChangeAtPosition(state, pos) {
894
907
  }
895
908
  return null;
896
909
  }
910
+ /** The transaction `command` would dispatch on `state`, or `null` when it would not apply. */
911
+ const attemptedTransaction = (command, state, view) => {
912
+ let attempted = null;
913
+ return command(state, (transaction) => {
914
+ attempted = transaction;
915
+ }, view) ? attempted : null;
916
+ };
917
+ /**
918
+ * `command`, refused when what it would do breaks a content control's lock
919
+ * (`lockedControlViolationOfTransform`). A document without a locked control
920
+ * runs it as it is.
921
+ */
922
+ const honouringContentControlLocks = (command) => (state, dispatch, view) => {
923
+ if (lockedControlSpans(state.doc).length === 0) return command(state, dispatch, view);
924
+ const attempted = attemptedTransaction(command, state, view);
925
+ if (attempted === null) return false;
926
+ if (lockedControlViolationOfTransform(attempted) !== null) return false;
927
+ dispatch?.(attempted);
928
+ return true;
929
+ };
930
+ function resolveChange(from, to, mode, revisionIds) {
931
+ return honouringContentControlLocks(resolveChangeUnguarded(from, to, mode, revisionIds));
932
+ }
933
+ /**
934
+ * What the content-control locks say about resolving the tracked changes
935
+ * between `from` and `to` (only those of `revisionIds`, when given): `null`
936
+ * when they allow it or there is nothing there to resolve. A revision whose
937
+ * resolution would change a content-locked control's content, or remove a
938
+ * control locked against removal, stays pending.
939
+ */
940
+ const changeResolutionLockViolation = (state, { from, to, mode, revisionIds }) => {
941
+ if (lockedControlSpans(state.doc).length === 0) return null;
942
+ const attempted = attemptedTransaction(resolveChangeUnguarded(from, to, mode, revisionIds), state);
943
+ return attempted === null ? null : lockedControlViolationOfTransform(attempted);
944
+ };
945
+ /** {@link changeResolutionLockViolation} for the revisions `revisionIds`, wherever they are. */
946
+ const revisionResolutionLockViolation = (state, revisionIds, mode) => {
947
+ const range = findAIEditRevisionRange(state, revisionIds);
948
+ return range === null ? null : changeResolutionLockViolation(state, {
949
+ ...range,
950
+ mode,
951
+ revisionIds: typeof revisionIds === "number" ? [revisionIds] : revisionIds
952
+ });
953
+ };
897
954
  /**
898
955
  * Accept a tracked change at the given range.
899
956
  * - Insertion: remove mark, keep text
@@ -936,6 +993,7 @@ const resolveAllChanges = (mode) => (state, dispatch) => {
936
993
  removedEndpointCount: result.removedEndpointCount,
937
994
  removedReferences: result.removedReferences
938
995
  });
996
+ finishResolution(state, tr);
939
997
  dispatch(tr);
940
998
  return true;
941
999
  };
@@ -944,19 +1002,65 @@ const resolveAllChanges = (mode) => (state, dispatch) => {
944
1002
  * suggestions are present because this command cannot restage them.
945
1003
  */
946
1004
  function acceptAllChanges() {
947
- const resolve = resolveAllChanges("accept");
948
- return (state, dispatch) => {
1005
+ const resolve = resolveAllChangesHonouringLocks("accept");
1006
+ return (state, dispatch, view) => {
949
1007
  if (getSuggestions(state).length > 0) return false;
950
- return resolve(state, dispatch);
1008
+ return resolve(state, dispatch, view);
951
1009
  };
952
1010
  }
953
1011
  /**
954
1012
  * Reject all tracked changes in the document.
955
1013
  */
956
1014
  function rejectAllChanges() {
957
- return resolveAllChanges("reject");
1015
+ return resolveAllChangesHonouringLocks("reject");
958
1016
  }
959
1017
  /**
1018
+ * The revisions of `state` that a content control's lock keeps from being
1019
+ * resolved in `mode`, each with the lock's verdict: see
1020
+ * {@link changeResolutionLockViolation}. Empty without a locked control.
1021
+ */
1022
+ const lockHeldRevisions = (state, mode) => {
1023
+ const held = /* @__PURE__ */ new Map();
1024
+ if (lockedControlSpans(state.doc).length === 0) return held;
1025
+ for (const id of new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds))) {
1026
+ const violation = revisionResolutionLockViolation(state, id, mode);
1027
+ if (violation !== null) held.set(id, violation);
1028
+ }
1029
+ return held;
1030
+ };
1031
+ /** Every revision id one sidebar entry stands for. */
1032
+ const trackedChangeEntryRevisionIds = (entry) => [.../* @__PURE__ */ new Set([
1033
+ entry.revisionId,
1034
+ ...entry.insertionRevisionId === void 0 ? [] : [entry.insertionRevisionId],
1035
+ ...entry.coalescedRevisionIds ?? []
1036
+ ])];
1037
+ /**
1038
+ * Resolve every tracked change a content control's lock allows. Without a
1039
+ * change the locks hold, the whole story resolves in one pass, as before;
1040
+ * otherwise each other change resolves on its own, in an editor view (a
1041
+ * transaction each), and the held ones stay pending as they are. Without a
1042
+ * view nothing resolves when any change is held.
1043
+ */
1044
+ const resolveAllChangesHonouringLocks = (mode) => (state, dispatch, view) => {
1045
+ const resolveAll = resolveAllChanges(mode);
1046
+ if (lockedControlSpans(state.doc).length === 0) return resolveAll(state, dispatch, view);
1047
+ const attempted = attemptedTransaction(resolveAll, state, view);
1048
+ if (attempted === null) return false;
1049
+ if (lockedControlViolationOfTransform(attempted) === null) {
1050
+ dispatch?.(attempted);
1051
+ return true;
1052
+ }
1053
+ if (!dispatch) return true;
1054
+ if (!view) return false;
1055
+ const held = lockHeldRevisions(state, mode);
1056
+ const ids = new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds));
1057
+ for (const id of [...ids].toReversed()) {
1058
+ if (held.has(id)) continue;
1059
+ (mode === "accept" ? acceptAIEditRevision(id) : rejectAIEditRevision(id))(view.state, view.dispatch, view);
1060
+ }
1061
+ return true;
1062
+ };
1063
+ /**
960
1064
  * Resolve a complete state synchronously for a headless reader or writer.
961
1065
  *
962
1066
  * Uses the same single-step resolver as the interactive editor command.
@@ -1086,6 +1190,46 @@ const SUGGESTION_MARK_NAMES = /* @__PURE__ */ new Set([
1086
1190
  "runPropertyChange"
1087
1191
  ]);
1088
1192
  const isSuggestionMark = (mark) => mark.attrs["provenance"] === "suggested" && SUGGESTION_MARK_NAMES.has(mark.type.name);
1193
+ /**
1194
+ * The suggestion a comment mark belongs to: a comment a suggestion proposed
1195
+ * is pending with it, never saved, accepted and rejected with it.
1196
+ */
1197
+ const suggestedCommentOf = (mark) => {
1198
+ if (mark.type.name !== "comment") return null;
1199
+ const suggestionId = mark.attrs["suggestionId"];
1200
+ return typeof suggestionId === "string" && suggestionId.length > 0 ? suggestionId : null;
1201
+ };
1202
+ /** The ids of the comments a pending suggestion proposes. */
1203
+ function suggestionCommentIds(state, suggestionId) {
1204
+ return [...collectSuggestions(state).get(suggestionId)?.commentIds ?? []];
1205
+ }
1206
+ /**
1207
+ * Remove the comment marks of the suggestions `matches` selects, or, with
1208
+ * `keep`, clear their suggestion so they stay as ordinary comments. Mark
1209
+ * steps do not shift positions.
1210
+ */
1211
+ const resolveSuggestedCommentMarks = (tr, matches, keep) => {
1212
+ const found = [];
1213
+ tr.doc.descendants((node, pos) => {
1214
+ if (!node.isInline) return void 0;
1215
+ for (const mark of node.marks) {
1216
+ const suggestionId = suggestedCommentOf(mark);
1217
+ if (suggestionId !== null && matches(suggestionId)) found.push({
1218
+ from: pos,
1219
+ to: pos + node.nodeSize,
1220
+ mark
1221
+ });
1222
+ }
1223
+ });
1224
+ for (const { from, to, mark } of found) {
1225
+ tr.removeMark(from, to, mark);
1226
+ if (keep) tr.addMark(from, to, mark.type.create({
1227
+ ...mark.attrs,
1228
+ suggestionId: null
1229
+ }));
1230
+ }
1231
+ return found.length > 0;
1232
+ };
1089
1233
  const suggestionKindOf = (mark) => {
1090
1234
  if (mark.type.name === "insertion") return "insertion";
1091
1235
  if (mark.type.name === "deletion") return "deletion";
@@ -1176,7 +1320,8 @@ const collectSuggestions = (state) => {
1176
1320
  const created = {
1177
1321
  segments: [],
1178
1322
  kinds: /* @__PURE__ */ new Set(),
1179
- revisionIds: /* @__PURE__ */ new Set()
1323
+ revisionIds: /* @__PURE__ */ new Set(),
1324
+ commentIds: /* @__PURE__ */ new Set()
1180
1325
  };
1181
1326
  bySuggestion.set(suggestionId, created);
1182
1327
  return created;
@@ -1218,6 +1363,17 @@ const collectSuggestions = (state) => {
1218
1363
  }
1219
1364
  if (!node.isInline) return;
1220
1365
  for (const mark of node.marks) {
1366
+ const commentSuggestion = suggestedCommentOf(mark);
1367
+ if (commentSuggestion !== null) {
1368
+ const entry = entryFor(commentSuggestion);
1369
+ entry.segments.push({
1370
+ from: pos,
1371
+ to: pos + node.nodeSize
1372
+ });
1373
+ entry.kinds.add("comment");
1374
+ entry.commentIds.add(expectCommentMarkAttrs(mark).commentId);
1375
+ continue;
1376
+ }
1221
1377
  if (!isSuggestionMark(mark)) continue;
1222
1378
  const suggestionId = mark.attrs["suggestionId"];
1223
1379
  if (typeof suggestionId !== "string" || suggestionId.length === 0) continue;
@@ -1240,8 +1396,10 @@ const collectSuggestions = (state) => {
1240
1396
  * operations with one `suggestionId`) is `"mixed"`.
1241
1397
  */
1242
1398
  const suggestionAppliedAs = (kinds) => {
1399
+ const changes = [...kinds].filter((kind) => kind !== "comment");
1400
+ if (changes.length === 0) return "direct";
1243
1401
  if (!kinds.has("insertTable")) return "tracked";
1244
- return [...kinds].some((kind) => kind !== "insertTable") ? "mixed" : "direct";
1402
+ return changes.some((kind) => kind !== "insertTable") ? "mixed" : "direct";
1245
1403
  };
1246
1404
  /** Merge sorted, possibly adjacent/overlapping segments into contiguous ranges. */
1247
1405
  const mergeSegments = (segments) => {
@@ -1266,7 +1424,8 @@ const SUGGESTION_KIND_ORDER = [
1266
1424
  "insertRow",
1267
1425
  "deleteRow",
1268
1426
  "insertColumn",
1269
- "deleteColumn"
1427
+ "deleteColumn",
1428
+ "comment"
1270
1429
  ];
1271
1430
  /**
1272
1431
  * List every suggestion in the document for host consumption: its id, the
@@ -1756,8 +1915,12 @@ const acceptSuggestions = (matchesSuggestion, options) => {
1756
1915
  shouldRotate: (_node, position) => directlyMarkedParagraphPositions.has(position),
1757
1916
  fallbackAuthor: options.author
1758
1917
  })) return false;
1918
+ if (resolveSuggestedCommentMarks(tr, matchesSuggestion, true)) changed = true;
1759
1919
  if (!changed) return false;
1760
- if (dispatch) dispatch(tr);
1920
+ if (dispatch) {
1921
+ finishResolution(state, tr);
1922
+ dispatch(tr);
1923
+ }
1761
1924
  return true;
1762
1925
  };
1763
1926
  };
@@ -1798,7 +1961,7 @@ function rejectSuggestion(suggestionId) {
1798
1961
  if (entry.revisionIds.size > 0) {
1799
1962
  const ranges = mergeSegments(entry.segments);
1800
1963
  const from = ranges[0]?.from ?? 0;
1801
- resolveChange(from, ranges.at(-1)?.to ?? from, "reject", [...entry.revisionIds])(state, (resolved) => {
1964
+ resolveChangeUnguarded(from, ranges.at(-1)?.to ?? from, "reject", [...entry.revisionIds])(state, (resolved) => {
1802
1965
  tr = resolved;
1803
1966
  });
1804
1967
  }
@@ -1820,8 +1983,12 @@ function rejectSuggestion(suggestionId) {
1820
1983
  tr: workingTr
1821
1984
  })
1822
1985
  })) return false;
1986
+ resolveSuggestedCommentMarks(workingTr, (id) => id === suggestionId, false);
1823
1987
  if (workingTr.steps.length === 0) return false;
1824
- if (dispatch) dispatch(workingTr);
1988
+ if (dispatch) {
1989
+ finishResolution(state, workingTr);
1990
+ dispatch(workingTr);
1991
+ }
1825
1992
  return true;
1826
1993
  };
1827
1994
  }
@@ -1838,7 +2005,7 @@ function rejectAllSuggestions() {
1838
2005
  }
1839
2006
  const rotationCandidates = removesWholeNode ? collectAddedBreakRotationCandidates(state.doc) : [];
1840
2007
  let tr = null;
1841
- if (revisionIds.size > 0) resolveChange(0, state.doc.content.size, "reject", [...revisionIds])(state, (resolved) => {
2008
+ if (revisionIds.size > 0) resolveChangeUnguarded(0, state.doc.content.size, "reject", [...revisionIds])(state, (resolved) => {
1842
2009
  tr = resolved;
1843
2010
  });
1844
2011
  const workingTr = tr ?? state.tr;
@@ -1858,8 +2025,12 @@ function rejectAllSuggestions() {
1858
2025
  tr: workingTr
1859
2026
  })
1860
2027
  })) return false;
2028
+ resolveSuggestedCommentMarks(workingTr, () => true, false);
1861
2029
  if (workingTr.steps.length === 0) return false;
1862
- if (dispatch) dispatch(workingTr);
2030
+ if (dispatch) {
2031
+ finishResolution(state, workingTr);
2032
+ dispatch(workingTr);
2033
+ }
1863
2034
  return true;
1864
2035
  };
1865
2036
  }
@@ -1909,7 +2080,7 @@ function findChangeAtPosition(state, from, to) {
1909
2080
  };
1910
2081
  const $pos = state.doc.resolve(from);
1911
2082
  const node = $pos.parent;
1912
- if (!node.isTextblock) return {
2083
+ if (!node.inlineContent) return {
1913
2084
  from,
1914
2085
  to
1915
2086
  };
@@ -2070,4 +2241,4 @@ function findPreviousChange(state, startPos) {
2070
2241
  if (result.value === null && startPos < state.doc.content.size) return findPreviousChange(state, state.doc.content.size);
2071
2242
  return result.value;
2072
2243
  }
2073
- export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, suggestionIdOfRevision };
2244
+ export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, changeResolutionLockViolation, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, lockHeldRevisions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, revisionResolutionLockViolation, suggestionCommentIds, suggestionIdOfRevision, trackedChangeEntryRevisionIds };
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
2
  import { TextColorAttrs } from "../schema/marks.js";
3
- import "../schema/index.js";
4
3
  import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
4
+ import "../schema/index.js";
5
5
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
6
6
  import { Mark } from "prosemirror-model";
7
7
  import { Command } from "prosemirror-state";
@@ -1,8 +1,8 @@
1
+ import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
1
2
  import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getStyleId } from "../extensions/core/ParagraphExtension.js";
2
3
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
3
4
  import { AcceptSuggestionOptions, FolioSuggestion, SuggestionAppliedAs, SuggestionKind, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
4
5
  import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
5
- import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
6
6
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
7
7
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
8
8
  import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
@@ -1,4 +1,4 @@
1
- import { expectCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
1
+ import { expectCommentRangeBoundaryAttrs, isCommentRangeBoundaryNode } from "./commentRangeBoundaryAttrs.js";
2
2
  import { maxAnnotationIdInDoc, seedRevisionIdsAbove } from "./plugins/revisionIds.js";
3
3
  import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
4
4
  import { TaggedError } from "better-result";
@@ -57,7 +57,7 @@ function seedCommentAllocator(allocator, comments, view) {
57
57
  const attrs = readRangeAnchorAttrs(node);
58
58
  if (attrs.ok && attrs.value.start.type === "commentRangeStart") allocator.seedAbove(attrs.value.start.id);
59
59
  }
60
- if (node.type.name === "commentRangeBoundary") allocator.seedAbove(expectCommentRangeBoundaryAttrs(node).marker.id);
60
+ if (isCommentRangeBoundaryNode(node)) allocator.seedAbove(expectCommentRangeBoundaryAttrs(node).marker.id);
61
61
  });
62
62
  max = Math.max(max, maxAnnotationIdInDoc(view.state.doc));
63
63
  }
@@ -8,6 +8,12 @@ type CommentRangeBoundaryMarker = Extract<ParagraphContent, {
8
8
  type CommentRangeBoundaryAttrs = {
9
9
  marker: CommentRangeBoundaryMarker;
10
10
  };
11
+ /**
12
+ * Whether a node is a comment range boundary, inside a paragraph or between
13
+ * blocks. Both carry the same marker, so every reader asks this rather than
14
+ * naming one of them.
15
+ */
16
+ export declare const isCommentRangeBoundaryNode: (node: Node) => boolean;
11
17
  export declare const readCommentRangeBoundaryMarker: (value: unknown) => CommentRangeBoundaryMarker | undefined;
12
18
  export declare const readCommentRangeBoundaryAttrs: (node: Node) => ReadProseMirrorAttrsResult<CommentRangeBoundaryAttrs>;
13
19
  export declare const expectCommentRangeBoundaryAttrs: (node: Node) => CommentRangeBoundaryAttrs;
@@ -2,6 +2,12 @@ import { isDisplacedByCustomXml } from "./bookmarkBoundaryAttrs.js";
2
2
  import { panic } from "better-result";
3
3
  // src/prosemirror/commentRangeBoundaryAttrs.ts
4
4
  const attrsCache = /* @__PURE__ */ new WeakMap();
5
+ /**
6
+ * Whether a node is a comment range boundary, inside a paragraph or between
7
+ * blocks. Both carry the same marker, so every reader asks this rather than
8
+ * naming one of them.
9
+ */
10
+ const isCommentRangeBoundaryNode = (node) => node.type.name === "commentRangeBoundary" || node.type.name === "blockCommentRangeBoundary";
5
11
  const isRecord = (value) => typeof value === "object" && value !== null;
6
12
  const readCommentRangeBoundaryMarker = (value) => {
7
13
  if (!isRecord(value)) return void 0;
@@ -18,9 +24,9 @@ const readCommentRangeBoundaryMarker = (value) => {
18
24
  };
19
25
  const readCommentRangeBoundaryAttrs = (node) => {
20
26
  const issues = [];
21
- if (node.type.name !== "commentRangeBoundary") issues.push({
27
+ if (!isCommentRangeBoundaryNode(node)) issues.push({
22
28
  path: "commentRangeBoundary.type.name",
23
- message: `Expected commentRangeBoundary, got ${node.type.name}.`
29
+ message: `Expected commentRangeBoundary or blockCommentRangeBoundary, got ${node.type.name}.`
24
30
  });
25
31
  const marker = readCommentRangeBoundaryMarker(node.attrs["marker"]);
26
32
  if (!marker) issues.push({
@@ -47,4 +53,4 @@ const expectCommentRangeBoundaryAttrs = (node) => {
47
53
  attrsCache.set(node, result.value);
48
54
  return result.value;
49
55
  };
50
- export { expectCommentRangeBoundaryAttrs, readCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker };
56
+ export { expectCommentRangeBoundaryAttrs, isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker };
@@ -0,0 +1,137 @@
1
+ import { Comment } from "../types/content.js";
2
+ import { Node, Schema } from "prosemirror-model";
3
+ import { EditorState, Plugin, Transaction } from "prosemirror-state";
4
+ import { EditorView } from "prosemirror-view";
5
+ import { Step, StepMap, StepResult } from "prosemirror-transform";
6
+ export type CommentRecords = readonly Comment[];
7
+ /**
8
+ * Replace the session's comment records. The document is unchanged, so the
9
+ * step maps nothing; its inverse puts back the records it replaced.
10
+ */
11
+ export declare class CommentRecordsStep extends Step {
12
+ readonly before: CommentRecords;
13
+ readonly after: CommentRecords;
14
+ constructor(before: CommentRecords, after: CommentRecords);
15
+ apply(doc: Node): StepResult;
16
+ getMap(): StepMap;
17
+ invert(): CommentRecordsStep;
18
+ map(): CommentRecordsStep;
19
+ merge(other: Step): CommentRecordsStep | null;
20
+ toJSON(): unknown;
21
+ static fromJSON(_schema: Schema, json: unknown): CommentRecordsStep;
22
+ }
23
+ /**
24
+ * Who changed the records: `edit` for user edits and history, which hosts
25
+ * report to their listeners; `sync` when a host wrote its own value in.
26
+ */
27
+ export type CommentRecordsOrigin = "edit" | "sync";
28
+ type CommentRecordsPluginState = {
29
+ records: CommentRecords;
30
+ origin: CommentRecordsOrigin;
31
+ };
32
+ /**
33
+ * Told the records after every change; `null` when the view's state stops
34
+ * holding records (another session took the view over, or it was destroyed).
35
+ */
36
+ type CommentRecordsListener = (records: CommentRecords | null, origin: CommentRecordsOrigin) => void;
37
+ /**
38
+ * The plugin that holds a session's comment records, starting from `initial`
39
+ * (the loaded document's comments).
40
+ */
41
+ export declare function createCommentRecordsPlugin(initial: CommentRecords): Plugin<CommentRecordsPluginState>;
42
+ /** The session's comment records, or `null` when the state holds none. */
43
+ export declare function commentRecordsOf(state: EditorState): CommentRecords | null;
44
+ /**
45
+ * Call `listener` whenever the view's comment records change, including a
46
+ * state the view is given for a newly loaded document. Returns the
47
+ * unsubscribe function.
48
+ */
49
+ export declare function subscribeCommentRecords(view: EditorView, listener: CommentRecordsListener): () => void;
50
+ /** The records a transaction ends on, given the state it started from. */
51
+ export declare function commentRecordsAfter(state: EditorState, transaction: Transaction): CommentRecords | null;
52
+ /**
53
+ * Add the step replacing the records `transaction` ends on with `next`.
54
+ * Returns false when the state holds no records.
55
+ */
56
+ export declare function stepCommentRecords(state: EditorState, transaction: Transaction, next: CommentRecords): boolean;
57
+ /**
58
+ * A transaction writing a host's value into the records: kept out of the
59
+ * undo history and reported as `sync`, so it is not echoed back to the host.
60
+ */
61
+ export declare function syncCommentRecords(state: EditorState, next: CommentRecords): Transaction | null;
62
+ /**
63
+ * Whether a transaction only writes a host's comment list in: no document
64
+ * content and no user edit changes, so it neither marks the document changed
65
+ * nor needs an editable document.
66
+ */
67
+ export declare function isCommentRecordsSync(transaction: Transaction): boolean;
68
+ /** A comment and every reply whose parent chain reaches it. */
69
+ export declare function commentThreadIds(records: CommentRecords, id: number): Set<number>;
70
+ /**
71
+ * An undoable edit replacing the records with `next`, for a host change that
72
+ * touches no anchor (a reply, a resolution, a list the host computed).
73
+ */
74
+ export declare function editCommentRecords(state: EditorState, next: CommentRecords): Transaction | null;
75
+ /** Append comments (new threads or replies) to the records. */
76
+ export declare function appendCommentRecords(state: EditorState, additions: readonly Comment[]): Transaction | null;
77
+ /** Mark one comment resolved or open again. */
78
+ export declare function setCommentResolved(state: EditorState, id: number, done: boolean): Transaction | null;
79
+ export type CommentRange = {
80
+ from: number;
81
+ to: number;
82
+ };
83
+ type DispatchingView = Pick<EditorView, "state" | "dispatch">;
84
+ /**
85
+ * Anchor a new thread on `range` and add its record, in one transaction.
86
+ * Returns null when the range is empty or out of the document.
87
+ */
88
+ export declare function addCommentThread(state: EditorState, range: CommentRange, comment: Comment): Transaction | null;
89
+ /**
90
+ * Show the add-comment flow's highlight on `range`. The highlight is not an
91
+ * edit: it stays out of the undo history, so undoing a comment never brings
92
+ * it back.
93
+ */
94
+ export declare function markPendingComment(view: DispatchingView, range: CommentRange, options?: {
95
+ selectEnd?: boolean;
96
+ }): boolean;
97
+ /** Remove the add-comment flow's highlight from `range`. */
98
+ export declare function clearPendingComment(view: DispatchingView, range: CommentRange): void;
99
+ /**
100
+ * The add-comment flow's commit: the highlight on `range` gives way to the
101
+ * new thread's mark, and the thread joins the records, as one undoable edit.
102
+ */
103
+ export declare function commitCommentThread(view: DispatchingView, range: CommentRange, comment: Comment): boolean;
104
+ /**
105
+ * Remove every anchor of the comments in `ids` from the transaction's
106
+ * document: their `comment` marks, references and range boundaries.
107
+ */
108
+ export declare function removeCommentAnchors(transaction: Transaction, ids: ReadonlySet<number>): void;
109
+ /** Delete a thread: its record, every reply under it, and its anchors. */
110
+ export declare function deleteCommentThread(state: EditorState, id: number): Transaction | null;
111
+ /**
112
+ * The comment ids a document names through a mark, reference or range
113
+ * boundary.
114
+ */
115
+ export declare function commentIdsNamedIn(doc: Node): Set<number>;
116
+ /**
117
+ * Remove the threads a review resolution left without any anchor: accepting
118
+ * the deletion of everything a comment covers, or rejecting the suggestion
119
+ * that inserted it, retires the comment with its replies, in the same
120
+ * transaction. Other edits keep records whose anchors are gone for now (a
121
+ * cut keeps the thread for the paste).
122
+ */
123
+ export declare function retireThreadsResolvedAway(state: EditorState, transaction: Transaction): void;
124
+ /**
125
+ * Add the records of `created` comments that `transaction`'s document names
126
+ * and the records lack, so comments a document operation anchors join the
127
+ * records in the operation's own transaction.
128
+ */
129
+ export declare function recordCreatedComments(state: EditorState, transaction: Transaction, created: readonly Comment[]): void;
130
+ /**
131
+ * `view` for a document operation: its dispatch adds the records of the
132
+ * `created` comments the operation anchors, in the operation's transaction.
133
+ */
134
+ export declare function recordingCommentsView(view: DispatchingView, created: readonly Comment[]): DispatchingView;
135
+ /** Panic unless the state holds records; for callers that require them. */
136
+ export declare function expectCommentRecords(state: EditorState): CommentRecords;
137
+ export {};