@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
@@ -1,8 +1,10 @@
1
+ import { document_d_exports } from "../types/document.js";
1
2
  import { NumberingIdsInUse } from "../docx/numberingIds.js";
2
3
  import { FolioContentStatedNumbering } from "../compare/content-types.js";
3
4
  import { ListKind } from "../docx/listNumberingInstances.js";
4
- import { FolioAIEditOperation, FolioAIListNumbering, FolioAINewListReference, FolioAIResolvedEditOperation } from "./types.js";
5
+ import { FolioAIEditOperation, FolioAIListKind, FolioAIListNumbering, FolioAINewListReference, FolioAIResolvedEditOperation } from "./types.js";
5
6
  import { NumberingMap } from "../docx/numberingParser.js";
7
+ import { NewListInstance } from "@stll/docx-core/ops";
6
8
  /** Whether `numbering` asks for a new list rather than naming an instance. */
7
9
  export declare const isFolioAINewListReference: (numbering: FolioAIListNumbering) => numbering is FolioAINewListReference;
8
10
  type ResolvedNewLists = {
@@ -28,4 +30,15 @@ export declare const stageNewListOperations: (operations: readonly FolioAIEditOp
28
30
  * minted instance takes.
29
31
  */
30
32
  export declare const resolveNewListOperations: (operations: readonly FolioAIStagedEditOperation[], numbering: NumberingMap | null, elsewhere: NumberingIdsInUse) => ResolvedNewLists;
33
+ /** A list one operation starts: its instance id and the definitions it adds. */
34
+ export type MintedList = {
35
+ numId: number;
36
+ newList: NewListInstance;
37
+ };
38
+ /**
39
+ * Mints new lists for one batch of a canonical session, each after the ones
40
+ * before it. The document is read at the first mint, so a batch that starts
41
+ * no list never reads it.
42
+ */
43
+ export declare const createBatchListMinter: (document: () => document_d_exports.Document) => (format: FolioAIListKind) => MintedList;
31
44
  export {};
@@ -1,4 +1,5 @@
1
1
  import { mintListInstance } from "../docx/listNumberingInstances.js";
2
+ import { NO_NUMBERING_IDS_IN_USE } from "../docx/numberingIds.js";
2
3
  import { createNumberingMap } from "../docx/numberingParser.js";
3
4
  import { paragraphNumberingReference } from "../docx/numberingReference.js";
4
5
  import { panic } from "better-result";
@@ -150,4 +151,26 @@ const resolveNewListOperations = (operations, numbering, elsewhere) => {
150
151
  numbering: minted && definitions ? createNumberingMap(definitions) : numbering
151
152
  };
152
153
  };
153
- export { assertNewListsAllocated, isFolioAINewListReference, resolveNewListOperations, stageNewListOperations };
154
+ /**
155
+ * Mints new lists for one batch of a canonical session, each after the ones
156
+ * before it. The document is read at the first mint, so a batch that starts
157
+ * no list never reads it.
158
+ */
159
+ const createBatchListMinter = (document) => {
160
+ let definitions = null;
161
+ return (format) => {
162
+ definitions ??= document().package.numbering;
163
+ const minted = mintListInstance(definitions, { kind: format }, NO_NUMBERING_IDS_IN_USE);
164
+ definitions = minted.definitions;
165
+ const num = minted.definitions.nums.find(({ numId }) => numId === minted.numId) ?? panic("A minted list is missing its instance.");
166
+ const abstractNum = minted.definitions.abstractNums.find(({ abstractNumId }) => abstractNumId === num.abstractNumId);
167
+ return {
168
+ numId: minted.numId,
169
+ newList: {
170
+ num,
171
+ ...abstractNum === void 0 ? {} : { abstractNum }
172
+ }
173
+ };
174
+ };
175
+ };
176
+ export { assertNewListsAllocated, createBatchListMinter, isFolioAINewListReference, resolveNewListOperations, stageNewListOperations };
@@ -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 };
@@ -82,7 +82,7 @@ const parseRecord = (value) => {
82
82
  return null;
83
83
  }
84
84
  if (operationBlockId(operation) !== anchor["blockId"] || (operation.suggestionId ?? operation.id) !== value["suggestionId"] || getFolioParaIdFromBlockId(anchor["blockId"]) !== anchor["paraId"]) return null;
85
- if (operation.type === "replaceRange" || operation.type === "formatRange") {
85
+ if (operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange") {
86
86
  if (anchor["selectedTextHash"] !== operation.range.selectedTextHash || anchor["startOffset"] !== operation.range.startOffset || anchor["endOffset"] !== operation.range.endOffset) return null;
87
87
  }
88
88
  return {
@@ -126,7 +126,7 @@ var FolioPendingSuggestionRegistry = class {
126
126
  const blockId = operationBlockId(operation);
127
127
  const anchor = snapshot.anchors[blockId];
128
128
  if (!anchor) continue;
129
- const range = operation.type === "replaceRange" || operation.type === "formatRange" ? operation.range : null;
129
+ const range = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range : null;
130
130
  const recorded = outcome.suggestionId === (operation.suggestionId ?? operation.id) ? operation : {
131
131
  ...operation,
132
132
  suggestionId: outcome.suggestionId
@@ -49,6 +49,25 @@ export type FolioReviewChange = {
49
49
  */
50
50
  blockId: string | null;
51
51
  };
52
+ /** A tracked change an accept-all or reject-all left pending, and why. */
53
+ export type FolioReviewResolutionSkip = {
54
+ /** The change's revision id, as {@link FolioReviewChange.id}. */
55
+ id: number;
56
+ /**
57
+ * `contentControlLock`: resolving it would change the content of a content
58
+ * control whose `w:lock` is `contentLocked` or `sdtContentLocked`, or remove
59
+ * one whose lock is `sdtLocked` or `sdtContentLocked`.
60
+ */
61
+ reason: "contentControlLock";
62
+ message: string;
63
+ };
64
+ /** What an accept-all or reject-all did. */
65
+ export type FolioReviewResolution = {
66
+ /** The ordinary tracked changes it resolved. */
67
+ resolved: number;
68
+ /** The changes it left pending, each as it was. */
69
+ skipped: FolioReviewResolutionSkip[];
70
+ };
52
71
  /** A comment anchor (the ranged text a comment marks) discovered in the body. */
53
72
  export type FolioCommentAnchor = {
54
73
  commentId: number;
@@ -67,6 +67,12 @@ export declare const isFolioAIContentBlock: ({ text }: Pick<FolioAIBlock, "text"
67
67
  */
68
68
  export declare const trailingBodyBlockId: ({ blocks }: FolioAIEditSnapshot) => string | null;
69
69
  export declare const hashFolioAIBlockText: (text: string) => string;
70
+ /**
71
+ * The identity of a block's text: what a snapshot anchor records, and what an
72
+ * engine compares an anchor or a precondition against. Whitespace runs collapse
73
+ * and the ends trim, so a block reads the same however its spaces were typed.
74
+ */
75
+ export declare const hashFolioAIBlockContent: (text: string) => string;
70
76
  /**
71
77
  * Canonical public projection of the clean view's inline structure.
72
78
  *
@@ -241,6 +241,12 @@ const hashFolioAIBlockText = (text) => {
241
241
  for (const character of text) hash = (hash * 33 + (character.codePointAt(0) ?? 0)) % 2147483647;
242
242
  return `h${hash.toString(36)}`;
243
243
  };
244
+ /**
245
+ * The identity of a block's text: what a snapshot anchor records, and what an
246
+ * engine compares an anchor or a precondition against. Whitespace runs collapse
247
+ * and the ends trim, so a block reads the same however its spaces were typed.
248
+ */
249
+ const hashFolioAIBlockContent = (text) => hashFolioAIBlockText(normalizeFolioAIBlockText(text));
244
250
  const EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARIES = Object.freeze([]);
245
251
  const EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARY_HASH = hashFolioAIBlockText(JSON.stringify(EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARIES));
246
252
  /**
@@ -508,7 +514,7 @@ const createFolioAIEditSnapshotInternal = (doc, styleResolver, noteReferenceLabe
508
514
  const structuralBoundaries = projectFolioAIBlockStructuralBoundaries(cleanBlock);
509
515
  const structuralBoundaryHash = hashFolioAIBlockStructuralBoundaryProjection(structuralBoundaries);
510
516
  const normalizedText = normalizeFolioAIBlockText(text);
511
- const textHash = hashFolioAIBlockText(normalizedText);
517
+ const textHash = hashFolioAIBlockContent(text);
512
518
  hashCounts.set(textHash, (hashCounts.get(textHash) ?? 0) + 1);
513
519
  const paraIdAttr = node.attrs["paraId"];
514
520
  const paraId = typeof paraIdAttr === "string" && paraIdAttr.length > 0 ? paraIdAttr : null;
@@ -715,7 +721,6 @@ const getPreviewRuns = ({ node, nodeFrom, cleanBlock, styleResolver }) => {
715
721
  baseParagraphFormatting: paragraphStyleContext.baseParagraphFormatting,
716
722
  inheritedFormatting: paragraphStyleContext.paragraphFormatting,
717
723
  paragraphMarkFormatting: paragraphStyleContext.paragraphMarkFormatting,
718
- paragraphMarkPrecedesStyle: paragraphStyleContext.paragraphMarkPrecedesStyle,
719
724
  styleResolver
720
725
  });
721
726
  directFormatting = getDirectPreviewRunStyle(child.marks, directTextFormatting, styleResolver);
@@ -894,4 +899,4 @@ const samePreviewRunStyle = (run, style) => run.bold === style.bold && run.itali
894
899
  const isEmptyPreviewRunStyle = ({ bold, italic, underline, strike, fontFamily, fontSizePt, color }) => bold === void 0 && italic === void 0 && underline === void 0 && strike === void 0 && fontFamily === void 0 && fontSizePt === void 0 && color === void 0;
895
900
  const sameDirectFormatting = (left, right) => left === void 0 && isEmptyPreviewRunStyle(right) || left !== void 0 && left.bold === right.bold && left.italic === right.italic && left.underline === right.underline && left.strike === right.strike && left.fontFamily === right.fontFamily && left.fontSizePt === right.fontSizePt && left.color === right.color;
896
901
  const isUnstyledPreviewRun = ({ directFormatting, ...style }) => isEmptyPreviewRunStyle(style) && (directFormatting === void 0 || isEmptyPreviewRunStyle(directFormatting));
897
- export { alignedNoteReferenceLabels, collectNoteReferenceLabels, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isFolioAIContentBlock, isHiddenTableRow, normalizeFolioAIBlockText, numberingReferenceKeysOf, projectFolioAIBlockStructuralBoundaries, relabelFolioAIEditSnapshotNoteReferences, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf, styleResolverOf, trailingBodyBlockId };
902
+ export { alignedNoteReferenceLabels, collectNoteReferenceLabels, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, hashFolioAIBlockContent, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isFolioAIContentBlock, isHiddenTableRow, normalizeFolioAIBlockText, numberingReferenceKeysOf, projectFolioAIBlockStructuralBoundaries, relabelFolioAIEditSnapshotNoteReferences, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf, styleResolverOf, trailingBodyBlockId };
@@ -564,7 +564,15 @@ export type FolioAIResolvedEditOperation = FolioAIEditOperation<FolioContentStat
564
564
  * `unsupportedMode`.
565
565
  */
566
566
  export type FolioAIEditApplyMode = "direct" | "tracked-changes" | "suggested";
567
- export type FolioAIEditSkipReason = "missingBlock" | "changedBlock" | "ambiguousFind" | "missingFind" | "unsupportedBlock" | "unsupportedMode" | "atomicBatchRejected" | "preconditionFailed" | "staleRange" | "emptyOperation" |
567
+ export type FolioAIEditSkipReason =
568
+ /**
569
+ * A content control's `w:lock` forbids the change: it reaches inside a
570
+ * control whose content is locked (`contentLocked`, `sdtContentLocked`), or
571
+ * removes one that may not be removed (`sdtLocked`, `sdtContentLocked`),
572
+ * also by deleting the paragraph or text that holds it. Nothing was
573
+ * applied; `message` names the lock.
574
+ */
575
+ "contentControlLock" | "missingBlock" | "changedBlock" | "ambiguousFind" | "missingFind" | "unsupportedBlock" | "unsupportedMode" | "atomicBatchRejected" | "preconditionFailed" | "staleRange" | "emptyOperation" |
568
576
  /** The paragraph already owns the one `w:pPrChange` OOXML permits. */
569
577
  "pendingParagraphPropertyChange" |
570
578
  /** The affected run already owns the one `w:rPrChange` OOXML permits. */
@@ -27,9 +27,18 @@ function applySuggestions(options) {
27
27
  applied,
28
28
  stale
29
29
  };
30
- resolved.sort((a, b) => b.from - a.from);
30
+ resolved.sort((a, b) => b.from - a.from || b.to - a.to);
31
+ const accepted = [];
32
+ for (const entry of resolved) {
33
+ const following = accepted.at(-1);
34
+ if (following !== void 0 && entry.to > following.from) {
35
+ stale.push(entry.suggestion.id);
36
+ continue;
37
+ }
38
+ accepted.push(entry);
39
+ }
31
40
  const tr = view.state.tr;
32
- if (mode === "direct") for (const { suggestion, from, to } of resolved) {
41
+ if (mode === "direct") for (const { suggestion, from, to } of accepted) {
33
42
  tr.insertText(suggestion.suggestedText, from, to);
34
43
  applied.push(suggestion.id);
35
44
  }
@@ -38,11 +47,11 @@ function applySuggestions(options) {
38
47
  const deletionType = view.state.schema.marks["deletion"];
39
48
  if (!insertionType || !deletionType) return {
40
49
  applied,
41
- stale: [...stale, ...resolved.map((r) => r.suggestion.id)]
50
+ stale: [...stale, ...accepted.map((r) => r.suggestion.id)]
42
51
  };
43
52
  const date = (/* @__PURE__ */ new Date()).toISOString();
44
53
  seedRevisionIdsFromDoc(view.state.doc);
45
- for (const { suggestion, from, to } of resolved) {
54
+ for (const { suggestion, from, to } of accepted) {
46
55
  const attrs = {
47
56
  revisionId: mintRevisionId(),
48
57
  author,
@@ -497,7 +497,8 @@ const COMPARE_SKIP_DISPOSITION = {
497
497
  missingStyle: "fatal",
498
498
  missingNumbering: "fatal",
499
499
  invalidResult: "fatal",
500
- pendingDeletion: "unwritable"
500
+ pendingDeletion: "unwritable",
501
+ contentControlLock: "fatal"
501
502
  };
502
503
  const getCompareSkipDisposition = (reason) => COMPARE_SKIP_DISPOSITION[reason];
503
504
  /**
@@ -1,10 +1,13 @@
1
1
  import { FolioAIBlock, FolioAIEditSnapshot } from "../ai-edits/types.js";
2
+ import { FolioContentAlignmentWorkSession } from "./content-alignment.js";
2
3
  type CreateInsertedResourceProjectionOptions = {
3
4
  base: FolioAIEditSnapshot;
4
5
  revised: FolioAIEditSnapshot;
6
+ /** The comparison's alignment allowance; the projection's work is charged to it. */
7
+ alignmentSession: FolioContentAlignmentWorkSession;
5
8
  };
6
9
  /** Select resource nodes with their identities from the full revised snapshot. */
7
- export declare const createInsertedResourceProjection: ({ base, revised }: CreateInsertedResourceProjectionOptions) => {
10
+ export declare const createInsertedResourceProjection: ({ base, revised, alignmentSession }: CreateInsertedResourceProjectionOptions) => {
8
11
  snapshot: FolioAIEditSnapshot;
9
12
  revisedBlockIds: string[];
10
13
  };
@@ -1,12 +1,16 @@
1
1
  import { createFolioAIEditSnapshotWithStyleResolver, sourceDocumentOf, styleResolverOf } from "../ai-edits/snapshot.js";
2
- import { alignFolioBlocks } from "../version-comparison.js";
2
+ import { alignFolioBlocksInSession } from "../version-comparison.js";
3
3
  import { panic } from "better-result";
4
4
  import { Fragment } from "prosemirror-model";
5
5
  // src/compare/inserted-resource-snapshot.ts
6
6
  /** Select resource nodes with their identities from the full revised snapshot. */
7
- const createInsertedResourceProjection = ({ base, revised }) => {
7
+ const createInsertedResourceProjection = ({ base, revised, alignmentSession }) => {
8
8
  const document = sourceDocumentOf(revised);
9
- const insertions = alignFolioBlocks(base.blocks, revised.blocks).flatMap((event) => {
9
+ const insertions = alignFolioBlocksInSession({
10
+ baseBlocks: base.blocks,
11
+ revisedBlocks: revised.blocks,
12
+ workSession: alignmentSession
13
+ }).flatMap((event) => {
10
14
  if (event.type === "pair" || event.type === "baseOnly") return [];
11
15
  const anchor = revised.anchors[event.block.id] ?? panic("An inserted block lost its source anchor");
12
16
  const node = document.nodeAt(anchor.from) ?? panic("An inserted block lost its source paragraph");
@@ -1,4 +1,4 @@
1
- import { createNumberingIdAllocator } from "../docx/numberingIds.js";
1
+ import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
2
2
  import { copyParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
3
3
  import { visitInlineContentSlots, visitParagraphRuns } from "../docx/paragraphTraversal.js";
4
4
  import { captureVerbatimXml } from "../docx/verbatimCapture.js";
@@ -19,7 +19,7 @@ import { CellSelection } from "prosemirror-tables";
19
19
  import { packageResourcesOpOf } from "@stll/docx-core/ops";
20
20
  // src/controller/canonicalClipboard.ts
21
21
  const refuse = (message) => Result.err(new CanonicalSessionError({
22
- gap: CANONICAL_GAP.dispatch,
22
+ ground: { gap: CANONICAL_GAP.dispatch },
23
23
  message,
24
24
  reason: "refused"
25
25
  }));
@@ -97,7 +97,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
97
97
  ...rendering.markerHidden === void 0 ? {} : { hidden: rendering.markerHidden }
98
98
  };
99
99
  }
100
- const numAllocator = createNumberingIdAllocator("num", (destination?.nums ?? []).map(({ numId }) => numId));
100
+ const numAllocator = createNumberingIdAllocator("num", numberingNumIdsTaken(destination));
101
101
  const abstractAllocator = createNumberingIdAllocator("abstract", (destination?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId));
102
102
  const nums = new Map(source.nums.map(({ numId }) => [numId, numAllocator.next()]));
103
103
  const abstracts = new Map(source.abstractNums.map(({ abstractNumId }) => [abstractNumId, abstractAllocator.next()]));
@@ -188,7 +188,7 @@ const canonicalClipboardStoryPartRefusal = (paragraph) => {
188
188
  });
189
189
  if (!requiresStory) return void 0;
190
190
  return new CanonicalSessionError({
191
- gap: CANONICAL_GAP.dispatch,
191
+ ground: { gap: CANONICAL_GAP.dispatch },
192
192
  reason: "refused",
193
193
  message: "Clipboard comments and note references require importing their source story parts."
194
194
  });
@@ -196,7 +196,7 @@ const canonicalClipboardStoryPartRefusal = (paragraph) => {
196
196
  const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
197
197
  if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
198
198
  if (slice.content.size === 0) return Result.err(new CanonicalSessionError({
199
- gap: CANONICAL_GAP.dispatch,
199
+ ground: { gap: CANONICAL_GAP.dispatch },
200
200
  message: "The clipboard contains no content.",
201
201
  reason: "noChange"
202
202
  }));
@@ -214,7 +214,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
214
214
  const converted = Result.try({
215
215
  try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
216
216
  catch: (cause) => new CanonicalSessionError({
217
- gap: CANONICAL_GAP.dispatch,
217
+ ground: { gap: CANONICAL_GAP.dispatch },
218
218
  reason: "refused",
219
219
  message: `Clipboard normalization failed: ${cause instanceof Error ? cause.message : String(cause)}`
220
220
  })
@@ -231,11 +231,15 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
231
231
  paragraphs.push(paragraph);
232
232
  }
233
233
  if (moveTarget === void 0 && (plain || sourceDocument === void 0)) flattenClipboardStyleReferences(paragraphs);
234
- if (state.selection instanceof CellSelection) return refuse("Pasting over selected cells requires a per-cell paste operation.");
235
- const selectionRange = canonicalSelectionRange(state);
236
- const from = session.projection.addressAt(pasteTarget ?? moveSource?.from ?? selectionRange.from);
234
+ const overCells = state.selection instanceof CellSelection && pasteTarget === void 0 && moveSource === void 0 && moveTarget === void 0;
235
+ if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.");
236
+ const selectionRange = overCells ? {
237
+ from: state.selection.from,
238
+ to: state.selection.to
239
+ } : canonicalSelectionRange(state);
240
+ const from = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.from ?? selectionRange.from);
237
241
  if (from.isErr()) return from;
238
- const to = session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
242
+ const to = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
239
243
  if (to.isErr()) return to;
240
244
  let styles = session.document.package.styles;
241
245
  let styleIds;
@@ -304,7 +308,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
304
308
  const parsed = Result.try({
305
309
  try: () => parseXml(xml, OOXML_NAMESPACE_SCOPE),
306
310
  catch: () => new CanonicalSessionError({
307
- gap: CANONICAL_GAP.dispatch,
311
+ ground: { gap: CANONICAL_GAP.dispatch },
308
312
  reason: "refused",
309
313
  message: "The clipboard hyperlink metadata is malformed."
310
314
  })
@@ -412,7 +416,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
412
416
  const decoded = Result.try({
413
417
  try: () => base64ToBytes(payload),
414
418
  catch: () => new CanonicalSessionError({
415
- gap: CANONICAL_GAP.dispatch,
419
+ ground: { gap: CANONICAL_GAP.dispatch },
416
420
  message: "The clipboard image data is malformed.",
417
421
  reason: "refused"
418
422
  })
@@ -466,12 +470,25 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
466
470
  after: imported
467
471
  }));
468
472
  }
473
+ const openStart = importedSlice.openStart === 0 ? 0 : 1;
474
+ const openEnd = importedSlice.openEnd === 0 ? 0 : 1;
475
+ if (from.value === void 0 || to.value === void 0) return session.prepareCellSelectionStructure(state, (at) => ({
476
+ type: "replaceFragment",
477
+ from: at,
478
+ to: at,
479
+ paragraphs,
480
+ openStart,
481
+ openEnd
482
+ }), {
483
+ resourceOps,
484
+ semantic: "paste"
485
+ });
469
486
  const fragment = {
470
487
  from: from.value,
471
488
  to: to.value,
472
489
  paragraphs,
473
- openStart: importedSlice.openStart === 0 ? 0 : 1,
474
- openEnd: importedSlice.openEnd === 0 ? 0 : 1
490
+ openStart,
491
+ openEnd
475
492
  };
476
493
  if (moveTarget === void 0) return session.prepareIntents(state, {
477
494
  intents: [{
@@ -3,16 +3,40 @@ import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
3
3
  import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
4
4
  import { CanonicalSessionError } from "./canonicalSession.js";
5
5
  import { Result } from "better-result";
6
+ import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
6
7
  import { EditorState, TextSelection } from "prosemirror-state";
7
8
  // src/controller/canonicalComposition.ts
8
9
  const REVIEW_MARK_NAMES = /* @__PURE__ */ new Set(["insertion", "deletion"]);
10
+ const readBackCache = /* @__PURE__ */ new WeakMap();
11
+ /**
12
+ * The mark a DOM read rebuilds from the mark's own rendering: `null` when no
13
+ * rule reads it back, `undefined` with no document to render into. A read
14
+ * keeps only what the rendering carries, so this is all a reread can say.
15
+ */
16
+ const readBack = (mark) => {
17
+ const cached = readBackCache.get(mark);
18
+ if (cached !== void 0) return cached;
19
+ if (typeof document === "undefined") return void 0;
20
+ const { schema } = mark.type;
21
+ const container = document.createElement("div");
22
+ container.append(DOMSerializer.fromSchema(schema).serializeFragment(Fragment.from(schema.text("x", [mark])), { document }));
23
+ const texts = [];
24
+ DOMParser.fromSchema(schema).parseSlice(container).content.descendants((node) => {
25
+ if (node.isText) texts.push(node);
26
+ return texts.length === 0;
27
+ });
28
+ const read = mark.type.isInSet(texts.at(0)?.marks ?? []) ?? null;
29
+ readBackCache.set(mark, read);
30
+ return read;
31
+ };
9
32
  /**
10
33
  * Whether a native proposal is one plain replacement. The commit is a text
11
34
  * replacement over the captured model, so this only has to tell DOM noise from a
12
- * real change. Reading the DOM back can lose a mark with no parse rule or, through
13
- * `insertText`, a non-inclusive one. It rebuilds a review mark from fewer attributes,
14
- * and composed text sits in the DOM wrapper of the tracked run beside it. Gaining
15
- * any other mark, losing an inclusive one, or another revision is a real change.
35
+ * real change. Reading the DOM back can lose a mark no rule reads back or, through
36
+ * `insertText`, a non-inclusive one. It rebuilds any mark from what its rendering
37
+ * carries, a review mark from fewer attributes, and composed text sits in the DOM
38
+ * wrapper of the tracked run beside it. Gaining any other mark, losing or changing
39
+ * one the rendering carries, or another revision is a real change.
16
40
  * So is a selected paragraph boundary that does not disappear exactly.
17
41
  */
18
42
  const matchesNativeReplacement = ({ baseline, proposed, from, to, text }) => {
@@ -48,7 +72,12 @@ const matchesNativeReplacement = ({ baseline, proposed, from, to, text }) => {
48
72
  const held = type.isInSet(authored.marks);
49
73
  const read = type.isInSet(node.marks);
50
74
  if (held && !read) {
51
- if (type.spec.inclusive === false || (type.spec.parseDOM ?? []).length === 0) corrections.push(() => expected.removeMark(rangeFrom, rangeTo, type));
75
+ const rebuilt = readBack(held);
76
+ if (type.spec.inclusive === false || rebuilt === null || rebuilt === void 0 && (type.spec.parseDOM ?? []).length === 0) corrections.push(() => expected.removeMark(rangeFrom, rangeTo, type));
77
+ continue;
78
+ }
79
+ if (held && read && !held.eq(read) && !REVIEW_MARK_NAMES.has(type.name)) {
80
+ if (readBack(held)?.eq(read)) corrections.push(() => expected.addMark(rangeFrom, rangeTo, read));
52
81
  continue;
53
82
  }
54
83
  if (!read || !REVIEW_MARK_NAMES.has(type.name)) continue;
@@ -197,7 +226,7 @@ const createCanonicalComposition = (options) => {
197
226
  const applyNative = (view, transaction) => Result.try({
198
227
  try: () => view.state.applyTransaction(transaction),
199
228
  catch: (cause) => new CanonicalSessionError({
200
- gap: CANONICAL_GAP.dispatch,
229
+ ground: { gap: CANONICAL_GAP.dispatch },
201
230
  reason: "refused",
202
231
  message: `Composition projection failed: ${String(cause)}`
203
232
  })
@@ -9,7 +9,7 @@ export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
9
9
  readonly moveFrom: "container";
10
10
  readonly moveTo: "container";
11
11
  readonly inlineWrapper: "container";
12
- readonly inlineSdt: "control";
12
+ readonly inlineSdt: "container";
13
13
  readonly simpleField: "leaf";
14
14
  readonly complexField: "leaf";
15
15
  readonly mathEquation: "leaf";
@@ -34,7 +34,7 @@ export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
34
34
  readonly instrText: "rawField";
35
35
  readonly softHyphen: "leaf";
36
36
  readonly noBreakHyphen: "leaf";
37
- readonly renderedPageBreak: "layout";
37
+ readonly renderedPageBreak: "leaf";
38
38
  readonly preservedXml: "leaf";
39
39
  readonly drawing: "leaf";
40
40
  readonly shape: "leaf";
@@ -58,8 +58,8 @@ export declare const CANONICAL_NATIVE_INLINE_POLICIES: {
58
58
  readonly tab: "unit";
59
59
  readonly textBoxAnchor: "unit";
60
60
  readonly commentReference: "unit";
61
- readonly renderedPageBreak: "refused";
62
- readonly sdt: "refused";
61
+ readonly renderedPageBreak: "markers";
62
+ readonly sdt: "control";
63
63
  };
64
64
  declare const InlineProjectionErrorBase: TaggedErrorClass<"InlineProjectionError">;
65
65
  declare class InlineProjectionError extends InlineProjectionErrorBase<{
@@ -98,20 +98,45 @@ export type CanonicalInlineGap = {
98
98
  position: number;
99
99
  zeroWidthBefore: number;
100
100
  };
101
+ /** The source ordinals one editor position stands for: from `first` to `last`. */
102
+ export type CanonicalSeamExtent = {
103
+ first: number;
104
+ last: number;
105
+ };
101
106
  type InlineProjection = {
102
107
  text: string;
103
108
  boundaries: CanonicalInlineGap[][];
109
+ /** Parallel to `boundaries`: each gap's whole seam. */
110
+ seams: CanonicalSeamExtent[][];
111
+ };
112
+ /** Whether a story holds an id: all a paragraph's projection asks of a story id set. */
113
+ export type StoryIdMembership = Pick<ReadonlySet<number>, "has">;
114
+ /** The story's comments as one paragraph's projection reads them. */
115
+ export type CanonicalInlineCommentContext = {
116
+ rangedIds: StoryIdMembership;
117
+ pointIds: StoryIdMembership;
118
+ /** The comment ranges open where the paragraph starts. */
119
+ openIds: ReadonlySet<number>;
104
120
  };
105
121
  type CanonicalInlineProjectionArgs = {
106
122
  source: document_d_exports.Paragraph;
107
123
  paragraph: Node;
108
- pairedBookmarkIds: ReadonlySet<number>;
109
- commentContext?: {
110
- rangedIds: ReadonlySet<number>;
111
- pointIds: ReadonlySet<number>;
112
- openIds: ReadonlySet<number>;
113
- };
124
+ pairedBookmarkIds: StoryIdMembership;
125
+ commentContext?: CanonicalInlineCommentContext;
114
126
  };
115
127
  /** Bind rendered gaps to the operation owner's source leaf ordinals, including collapsed pairs. */
116
128
  export declare const projectCanonicalInline: ({ source, paragraph, pairedBookmarkIds, commentContext }: CanonicalInlineProjectionArgs) => Result<InlineProjection, InlineProjectionError>;
129
+ /**
130
+ * Paragraph projections kept across projections of a story.
131
+ *
132
+ * A paragraph an edit left keeps its source records, and the block cache
133
+ * keeps its editor node, so its gaps can be reused where the story facts its
134
+ * projection read are the same: the comments open at its start and the
135
+ * comment and bookmark ids it asked about. Gap positions are relative to the
136
+ * paragraph, so a reused projection holds wherever the paragraph now starts.
137
+ */
138
+ export declare class InlineProjectionCache {
139
+ private paragraphs;
140
+ project(args: CanonicalInlineProjectionArgs): Result<InlineProjection, InlineProjectionError>;
141
+ }
117
142
  export {};