@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,11 +1,13 @@
1
1
  import { expectTableAttrs, expectTableCellAttrs, mergeTableAttrs, mergeTableCellAttrs } from "./attrs/index.js";
2
+ import { withCanonicalTableAttributeCommand } from "./canonicalTableCommands.js";
2
3
  import { panic } from "better-result";
3
4
  // src/prosemirror/tableResize.ts
4
5
  /**
5
- * Table-resize commit + width-read helpers shared by the React and Vue
6
- * adapters. Pure `(view, …) → result` over the PM doc — the gesture state
7
- * machines (which DOM handle is grabbed, pixel deltas, listener wiring) stay
8
- * in each adapter.
6
+ * Table-resize commands and width-read helpers shared by the React and Vue
7
+ * adapters. A resize is a command the adapter runs through the editor, so the
8
+ * canonical session applies it as table edits; the gesture state machines
9
+ * (which DOM handle is grabbed, pixel deltas, listener wiring) stay in each
10
+ * adapter.
9
11
  *
10
12
  * Widths and heights are stored in twips (1/20 of a point) on the PM doc,
11
13
  * matching OOXML's `w:tblGrid` and `w:tcW` units.
@@ -20,9 +22,9 @@ function clampRowResizeDelta({ currentHeight, delta, minimumHeight }) {
20
22
  return Math.max(minimumHeight - currentHeight, delta);
21
23
  }
22
24
  /** Walk up from `pmStart + 1` to find the enclosing table node. */
23
- function findTableAt(view, pmStart) {
25
+ function findTableAt(doc, pmStart) {
24
26
  try {
25
- const $pos = view.state.doc.resolve(pmStart + 1);
27
+ const $pos = doc.resolve(pmStart + 1);
26
28
  for (let d = $pos.depth; d >= 0; d--) {
27
29
  const node = $pos.node(d);
28
30
  if (node.type.name === "table") return {
@@ -35,7 +37,7 @@ function findTableAt(view, pmStart) {
35
37
  }
36
38
  /** Read the [left, right] column widths at `colIndex` in the table starting at `pmStart`. */
37
39
  function readColumnWidths(view, pmStart, colIndex) {
38
- const found = findTableAt(view, pmStart);
40
+ const found = findTableAt(view.state.doc, pmStart);
39
41
  if (!found) return null;
40
42
  const widths = found.node.attrs["columnWidths"];
41
43
  if (!widths) return null;
@@ -53,7 +55,7 @@ function readColumnWidths(view, pmStart, colIndex) {
53
55
  * can fall back to measuring the rendered DOM cell.
54
56
  */
55
57
  function readRowHeight(view, pmStart, rowIndex) {
56
- const found = findTableAt(view, pmStart);
58
+ const found = findTableAt(view.state.doc, pmStart);
57
59
  if (!found) return null;
58
60
  let rowHeight = null;
59
61
  let idx = 0;
@@ -68,7 +70,7 @@ function readRowHeight(view, pmStart, rowIndex) {
68
70
  }
69
71
  /** Read the last-column width (the one being resized from the table's right edge). */
70
72
  function readColumnWidthAt(view, pmStart, colIndex) {
71
- const found = findTableAt(view, pmStart);
73
+ const found = findTableAt(view.state.doc, pmStart);
72
74
  if (!found) return null;
73
75
  const widths = found.node.attrs["columnWidths"];
74
76
  if (!widths) return null;
@@ -76,8 +78,8 @@ function readColumnWidthAt(view, pmStart, colIndex) {
76
78
  if (width === void 0) return null;
77
79
  return width;
78
80
  }
79
- const commitGridResize = ({ view, table: { node, tablePos }, widths, firstColumn, lastColumn }) => {
80
- const tr = view.state.tr;
81
+ const gridResize = ({ state, table: { node, tablePos }, widths, firstColumn, lastColumn }) => {
82
+ const tr = state.tr;
81
83
  tr.setNodeMarkup(tablePos, void 0, mergeTableAttrs(node, {
82
84
  columnWidths: widths,
83
85
  _originalFormatting: {
@@ -111,61 +113,70 @@ const commitGridResize = ({ view, table: { node, tablePos }, widths, firstColumn
111
113
  });
112
114
  rowOffset += row.nodeSize;
113
115
  });
114
- view.dispatch(tr);
116
+ return tr;
115
117
  };
116
- /** Commit a column-pair resize, preserving each spanning cell's full grid width. */
117
- function commitColumnResize(view, opts) {
118
- const { pmStart, colIdx, newLeft, newRight } = opts;
119
- const found = findTableAt(view, pmStart);
120
- if (!found) return;
121
- const sourceWidths = expectTableAttrs(found.node).columnWidths;
122
- if (!sourceWidths || sourceWidths[colIdx] === void 0 || sourceWidths[colIdx + 1] === void 0) return;
118
+ /**
119
+ * A resize as a command over the table at `pmStart`. It changes only table,
120
+ * row and cell attributes, so the canonical session applies it as the grid
121
+ * and formatting edits it makes.
122
+ */
123
+ const resizeCommand = (pmStart, resize) => withCanonicalTableAttributeCommand((state, dispatch) => {
124
+ const found = findTableAt(state.doc, pmStart);
125
+ if (!found) return false;
126
+ const tr = resize(state, found);
127
+ if (tr === null) return false;
128
+ dispatch?.(tr);
129
+ return true;
130
+ });
131
+ /** A column-pair resize, preserving each spanning cell's full grid width. */
132
+ const columnResizeCommand = (opts) => resizeCommand(opts.pmStart, (state, table) => {
133
+ const { colIdx, newLeft, newRight } = opts;
134
+ const sourceWidths = expectTableAttrs(table.node).columnWidths;
135
+ if (!sourceWidths || sourceWidths[colIdx] === void 0 || sourceWidths[colIdx + 1] === void 0) return null;
123
136
  const widths = [...sourceWidths];
124
137
  widths[colIdx] = newLeft;
125
138
  widths[colIdx + 1] = newRight;
126
- commitGridResize({
127
- view,
128
- table: found,
139
+ return gridResize({
140
+ state,
141
+ table,
129
142
  widths,
130
143
  firstColumn: colIdx,
131
144
  lastColumn: colIdx + 1
132
145
  });
133
- }
134
- /** Bake a row-resize into the PM doc: update the target row's `height` + `heightRule`. */
135
- function commitRowResize(view, opts) {
136
- const { pmStart, rowIdx, newHeight } = opts;
137
- const found = findTableAt(view, pmStart);
138
- if (!found) return;
139
- const { node, tablePos } = found;
140
- const tr = view.state.tr;
146
+ });
147
+ /** A row resize: the row's `height`, at least that tall. */
148
+ const rowResizeCommand = (opts) => resizeCommand(opts.pmStart, (state, { node, tablePos }) => {
149
+ const tr = state.tr;
141
150
  let rowOffset = tablePos + 1;
142
151
  let idx = 0;
152
+ let found = false;
143
153
  node.forEach((row) => {
144
- if (idx === rowIdx) tr.setNodeMarkup(tr.mapping.map(rowOffset), void 0, {
145
- ...row.attrs,
146
- height: newHeight,
147
- heightRule: "atLeast"
148
- });
154
+ if (idx === opts.rowIdx) {
155
+ found = true;
156
+ tr.setNodeMarkup(tr.mapping.map(rowOffset), void 0, {
157
+ ...row.attrs,
158
+ height: opts.newHeight,
159
+ heightRule: "atLeast"
160
+ });
161
+ }
149
162
  rowOffset += row.nodeSize;
150
163
  idx++;
151
164
  });
152
- view.dispatch(tr);
153
- }
154
- /** Commit a right-edge resize, including cells that span the resized column. */
155
- function commitRightEdgeResize(view, opts) {
156
- const { pmStart, colIdx, newWidth } = opts;
157
- const found = findTableAt(view, pmStart);
158
- if (!found) return;
159
- const sourceWidths = expectTableAttrs(found.node).columnWidths;
160
- if (!sourceWidths || sourceWidths[colIdx] === void 0) return;
165
+ return found ? tr : null;
166
+ });
167
+ /** A right-edge resize, including cells that span the resized column. */
168
+ const rightEdgeResizeCommand = (opts) => resizeCommand(opts.pmStart, (state, table) => {
169
+ const { colIdx, newWidth } = opts;
170
+ const sourceWidths = expectTableAttrs(table.node).columnWidths;
171
+ if (!sourceWidths || sourceWidths[colIdx] === void 0) return null;
161
172
  const widths = [...sourceWidths];
162
173
  widths[colIdx] = newWidth;
163
- commitGridResize({
164
- view,
165
- table: found,
174
+ return gridResize({
175
+ state,
176
+ table,
166
177
  widths,
167
178
  firstColumn: colIdx,
168
179
  lastColumn: colIdx
169
180
  });
170
- }
171
- export { MIN_CELL_WIDTH_TWIPS, MIN_ROW_HEIGHT_TWIPS, TWIPS_PER_PIXEL, clampRowResizeDelta, commitColumnResize, commitRightEdgeResize, commitRowResize, readColumnWidthAt, readColumnWidths, readRowHeight };
181
+ });
182
+ export { MIN_CELL_WIDTH_TWIPS, MIN_ROW_HEIGHT_TWIPS, TWIPS_PER_PIXEL, clampRowResizeDelta, columnResizeCommand, readColumnWidthAt, readColumnWidths, readRowHeight, rightEdgeResizeCommand, rowResizeCommand };
@@ -1,4 +1,4 @@
1
- import { Mark } from "prosemirror-model";
1
+ import { Mark, Node } from "prosemirror-model";
2
2
  import { EditorState, Plugin, Transaction } from "prosemirror-state";
3
3
  import { EditorView } from "prosemirror-view";
4
4
  type TextInputHandler<TView> = (view: TView, from: number, to: number, text: string, defaultTransaction: () => Transaction) => unknown;
@@ -18,6 +18,35 @@ type FormattingMarksBesideLockedControlOptions = {
18
18
  to: number;
19
19
  };
20
20
  export declare const formattingMarksBesideLockedControl: ({ state, from, to }: FormattingMarksBesideLockedControlOptions) => Mark[] | undefined;
21
+ /**
22
+ * The comment marks every piece of content in `[from, to]` carries: the
23
+ * comments whose content typing over the range replaces. Anchors without
24
+ * content (comment references, range boundaries) do not decide it.
25
+ */
26
+ export declare const commentMarksCovering: (doc: Node, from: number, to: number) => readonly Mark[];
27
+ /**
28
+ * Keep typed text inside the comments it belongs to.
29
+ *
30
+ * Typing over a range keeps the comments that cover all of it on the typed
31
+ * text, and the caret stays inside them: the next characters typed at the
32
+ * caret join them, until the caret moves. Without this the text typed over a
33
+ * comment's whole range lands outside it, and the comment loses its text.
34
+ */
35
+ export declare const keepTypedTextInComments: ({ state, tr, replaced, typed }: {
36
+ /** The state the typing started from. */
37
+ state: EditorState;
38
+ tr: Transaction;
39
+ /** The range the typing replaced, in `state.doc`. */
40
+ replaced: {
41
+ from: number;
42
+ to: number;
43
+ };
44
+ /** The typed text, in `tr.doc`. */
45
+ typed: {
46
+ from: number;
47
+ to: number;
48
+ };
49
+ }) => void;
21
50
  export declare const dispatchEditorTextInput: <TView extends TextInputDispatchTarget<TView>>(view: TView, input: string | TextInput) => void;
22
51
  export declare const getEditorInputTargetRange: (view: EditorView, event: InputEvent) => {
23
52
  from: number;
@@ -1,4 +1,8 @@
1
+ import { adoptNativeSelection, isCompositionKeyDown } from "./nativeSelection.js";
2
+ import { createPluginKeyOwner } from "./pluginKeyOwner.js";
1
3
  import { RUN_FORMATTING_MARK_NAMES } from "./runFormattingMarkNames.js";
4
+ import { isZeroWidthAnchor } from "./zeroWidthAnchors.js";
5
+ import { Mapping } from "prosemirror-transform";
2
6
  import { AllSelection, Plugin, Selection, TextSelection } from "prosemirror-state";
3
7
  // src/prosemirror/textInput.ts
4
8
  const LOCKED_CONTROL_LOCKS = /* @__PURE__ */ new Set(["contentLocked", "sdtContentLocked"]);
@@ -17,6 +21,54 @@ const formattingMarksBesideLockedControl = ({ state, from, to }) => {
17
21
  if (!adjacent?.isText || adjacent.marks.some((mark) => mark.type.name === "deletion" || mark.type.name === "moveFrom")) return [];
18
22
  return adjacent.marks.filter((mark) => RUN_FORMATTING_MARK_NAMES.has(mark.type.name));
19
23
  };
24
+ const isCommentMark = (mark) => mark.type.name === "comment";
25
+ /**
26
+ * Whether `node` is content a comment can cover: text, or an inline leaf that
27
+ * shows something (an image, a field, a tab). Anchors that only hold a
28
+ * position (comment references, range and bookmark boundaries) are not.
29
+ */
30
+ const isCoverableContent = (node) => node.isText || node.isInline && (node.isLeaf || node.isAtom) && !isZeroWidthAnchor(node);
31
+ /**
32
+ * The comment marks every piece of content in `[from, to]` carries: the
33
+ * comments whose content typing over the range replaces. Anchors without
34
+ * content (comment references, range boundaries) do not decide it.
35
+ */
36
+ const commentMarksCovering = (doc, from, to) => {
37
+ let covering = null;
38
+ doc.nodesBetween(from, to, (node) => {
39
+ if (!isCoverableContent(node)) return true;
40
+ const comments = node.marks.filter(isCommentMark);
41
+ covering = covering === null ? comments : covering.filter((mark) => mark.isInSet(comments));
42
+ return false;
43
+ });
44
+ return covering ?? [];
45
+ };
46
+ const typingInCommentsOwner = createPluginKeyOwner("typingInComments");
47
+ /**
48
+ * Keep typed text inside the comments it belongs to.
49
+ *
50
+ * Typing over a range keeps the comments that cover all of it on the typed
51
+ * text, and the caret stays inside them: the next characters typed at the
52
+ * caret join them, until the caret moves. Without this the text typed over a
53
+ * comment's whole range lands outside it, and the comment loses its text.
54
+ */
55
+ const keepTypedTextInComments = ({ state, tr, replaced, typed }) => {
56
+ if (typed.from >= typed.to) return;
57
+ const carried = (() => {
58
+ if (replaced.from < replaced.to) return commentMarksCovering(state.doc, replaced.from, replaced.to);
59
+ const typing = typingInCommentsOwner.getState(state);
60
+ if (!typing || typing.at !== replaced.from) return [];
61
+ const before = state.doc.resolve(replaced.from).nodeBefore?.marks ?? [];
62
+ return typing.comments.filter((mark) => mark.isInSet(before));
63
+ })();
64
+ if (carried.length === 0) return;
65
+ for (const mark of carried) tr.removeMark(typed.from, typed.to, mark);
66
+ for (const mark of carried) tr.addMark(typed.from, typed.to, mark);
67
+ tr.setMeta(typingInCommentsOwner.key, {
68
+ comments: carried,
69
+ at: typed.to
70
+ });
71
+ };
20
72
  const dispatchEditorTextInput = (view, input) => {
21
73
  const { from, to } = typeof input === "string" ? view.state.selection : input;
22
74
  const text = typeof input === "string" ? input : input.text;
@@ -33,7 +85,20 @@ const dispatchEditorTextInput = (view, input) => {
33
85
  const typesOverSelection = !selection.empty && selection.from === from && selection.to === to;
34
86
  if (typesOverSelection && !selection.$from.parent.inlineContent) return tr.insertText(text);
35
87
  tr.insertText(text, from, to);
36
- return typesOverSelection ? tr.setSelection(TextSelection.create(tr.doc, from + text.length)) : tr;
88
+ if (typesOverSelection) tr.setSelection(TextSelection.create(tr.doc, from + text.length));
89
+ keepTypedTextInComments({
90
+ state: view.state,
91
+ tr,
92
+ replaced: {
93
+ from,
94
+ to
95
+ },
96
+ typed: {
97
+ from,
98
+ to: from + text.length
99
+ }
100
+ });
101
+ return tr;
37
102
  }
38
103
  const start = Selection.atStart(view.state.doc);
39
104
  const end = Selection.atEnd(view.state.doc);
@@ -41,7 +106,20 @@ const dispatchEditorTextInput = (view, input) => {
41
106
  const tr = view.state.tr.insertText(text, start.from, end.to);
42
107
  const $typed = tr.doc.resolve(start.from);
43
108
  if (start.$from.parent.type.name === "paragraph" && last.type.name === "paragraph" && $typed.parent.type.name === "paragraph" && start.$from.parent !== last) tr.setNodeMarkup($typed.before(), void 0, last.attrs);
44
- return tr.setSelection(TextSelection.create(tr.doc, start.from + text.length));
109
+ tr.setSelection(TextSelection.create(tr.doc, start.from + text.length));
110
+ keepTypedTextInComments({
111
+ state: view.state,
112
+ tr,
113
+ replaced: {
114
+ from: start.from,
115
+ to: end.to
116
+ },
117
+ typed: {
118
+ from: start.from,
119
+ to: start.from + text.length
120
+ }
121
+ });
122
+ return tr;
45
123
  };
46
124
  if (!view.someProp("handleTextInput", (handler) => handler(view, from, to, text, defaultTransaction))) view.dispatch(defaultTransaction());
47
125
  };
@@ -85,22 +163,71 @@ const afterNativeCompositionFlush = (callback) => {
85
163
  /** Route committed text through the model before the browser mutates mark spans. */
86
164
  const createTextInputPlugin = () => {
87
165
  const compositions = /* @__PURE__ */ new WeakMap();
88
- return new Plugin({ props: { handleDOMEvents: {
89
- compositionstart(view, event) {
90
- compositions.set(view, event);
91
- return false;
166
+ return new Plugin({
167
+ key: typingInCommentsOwner.createKey(),
168
+ state: {
169
+ init: () => null,
170
+ apply: (tr, value) => {
171
+ const typed = tr.getMeta(typingInCommentsOwner.key);
172
+ if (typed !== void 0) return typed;
173
+ if (!value) return null;
174
+ const at = tr.mapping.map(value.at, -1);
175
+ return tr.selection.empty && tr.selection.from === at ? {
176
+ comments: value.comments,
177
+ at
178
+ } : null;
179
+ }
92
180
  },
93
- compositionend(view, event) {
94
- compositions.set(view, event);
95
- afterNativeCompositionFlush(() => {
96
- if (compositions.get(view) === event) compositions.delete(view);
181
+ appendTransaction: (transactions, oldState, newState) => {
182
+ const typing = typingInCommentsOwner.getState(oldState);
183
+ if (!typing || !transactions.some((tr) => tr.docChanged) || transactions.some((tr) => tr.getMeta(typingInCommentsOwner.key) !== void 0)) return null;
184
+ const mapping = new Mapping();
185
+ for (const tr of transactions) mapping.appendMapping(tr.mapping);
186
+ const from = mapping.map(typing.at, -1);
187
+ const to = mapping.map(typing.at, 1);
188
+ const { selection, doc } = newState;
189
+ if (from >= to || !selection.empty || selection.from !== to) return null;
190
+ const $from = doc.resolve(from);
191
+ if (!$from.parent.inlineContent || !$from.sameParent(doc.resolve(to))) return null;
192
+ let textOnly = true;
193
+ doc.nodesBetween(from, to, (node) => {
194
+ if (node.isInline && !node.isText) textOnly = false;
195
+ return textOnly;
196
+ });
197
+ if (!textOnly) return null;
198
+ const before = oldState.doc.resolve(typing.at).nodeBefore?.marks ?? [];
199
+ const carried = typing.comments.filter((mark) => mark.isInSet(before));
200
+ if (carried.length === 0) return null;
201
+ const tr = newState.tr;
202
+ for (const mark of carried) tr.removeMark(from, to, mark);
203
+ for (const mark of carried) tr.addMark(from, to, mark);
204
+ return tr.setMeta(typingInCommentsOwner.key, {
205
+ comments: carried,
206
+ at: to
97
207
  });
98
- return false;
99
208
  },
100
- beforeinput(view, event) {
101
- if (compositions.has(view)) return false;
102
- return handleEditorBeforeInput(view, event);
103
- }
104
- } } });
209
+ props: { handleDOMEvents: {
210
+ compositionstart(view, event) {
211
+ compositions.set(view, event);
212
+ return false;
213
+ },
214
+ compositionend(view, event) {
215
+ compositions.set(view, event);
216
+ afterNativeCompositionFlush(() => {
217
+ if (compositions.get(view) === event) compositions.delete(view);
218
+ });
219
+ return false;
220
+ },
221
+ keydown(view, event) {
222
+ if (!compositions.has(view) && !isCompositionKeyDown(event)) adoptNativeSelection(view);
223
+ return false;
224
+ },
225
+ beforeinput(view, event) {
226
+ if (compositions.has(view)) return false;
227
+ adoptNativeSelection(view);
228
+ return handleEditorBeforeInput(view, event);
229
+ }
230
+ } }
231
+ });
105
232
  };
106
- export { afterNativeCompositionFlush, createTextInputPlugin, dispatchEditorTextInput, formattingMarksBesideLockedControl, getEditorInputTargetRange, handleEditorBeforeInput };
233
+ export { afterNativeCompositionFlush, commentMarksCovering, createTextInputPlugin, dispatchEditorTextInput, formattingMarksBesideLockedControl, getEditorInputTargetRange, handleEditorBeforeInput, keepTypedTextInComments };
@@ -2,10 +2,11 @@ import { findCollapsedLineEdgeCaretTarget } from "../../layout-bridge/dom/clickT
2
2
  import { findBodyEmptyRuns, findBodyPmSpans } from "../../layout-bridge/dom/findBodyPmSpans.js";
3
3
  import { createTextStreamRange, descendantTextNodes, totalTextLength } from "../../layout-bridge/dom/textStreamDom.js";
4
4
  import { scrollEditorElementIntoView } from "../../paged-layout/editorScrollRoot.js";
5
+ import { PAINTED_RANGE_SELECTOR, hasPaintedStart, readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
5
6
  import { Selection, TextSelection } from "prosemirror-state";
6
7
  // src/prosemirror/utils/visualLineNavigation.ts
7
8
  const CONTENT_LINE_SELECTOR = ".layout-page-content .layout-line";
8
- const PM_SPAN_SELECTOR = "span[data-pm-start][data-pm-end]";
9
+ const PM_SPAN_SELECTOR = `span${PAINTED_RANGE_SELECTOR}`;
9
10
  /** @internal */
10
11
  function createVisualLineState() {
11
12
  return { step: null };
@@ -23,8 +24,8 @@ function getCaretClientX(container, pmPos) {
23
24
  const collapsedTarget = findCollapsedLineEdgeCaretTarget(spans, pmPos);
24
25
  if (collapsedTarget) return collapsedTarget.geometry.left;
25
26
  for (const spanEl of spans) {
26
- const pmStart = Number(spanEl.dataset["pmStart"]);
27
- const pmEnd = Number(spanEl.dataset["pmEnd"]);
27
+ const pmStart = readPaintedStart(spanEl) ?? NaN;
28
+ const pmEnd = readPaintedEnd(spanEl) ?? NaN;
28
29
  if (spanEl.classList.contains("layout-run-tab")) {
29
30
  if (pmPos >= pmStart && pmPos < pmEnd) return spanEl.getBoundingClientRect().left;
30
31
  continue;
@@ -39,8 +40,8 @@ function getCaretClientX(container, pmPos) {
39
40
  for (const emptyRun of findBodyEmptyRuns(container)) {
40
41
  const paragraph = emptyRun.closest(".layout-paragraph");
41
42
  if (!paragraph) continue;
42
- const pmStart = Number(paragraph.dataset["pmStart"]);
43
- const pmEnd = Number(paragraph.dataset["pmEnd"]);
43
+ const pmStart = readPaintedStart(paragraph) ?? NaN;
44
+ const pmEnd = readPaintedEnd(paragraph) ?? NaN;
44
45
  if (pmPos >= pmStart && pmPos <= pmEnd) return emptyRun.getBoundingClientRect().left;
45
46
  }
46
47
  return null;
@@ -52,8 +53,8 @@ function getCaretClientX(container, pmPos) {
52
53
  */
53
54
  const lineCarriesPosition = (lineEl, pmPos) => {
54
55
  for (const span of Array.from(lineEl.querySelectorAll(PM_SPAN_SELECTOR))) {
55
- const start = Number(span.dataset["pmStart"]);
56
- const end = Number(span.dataset["pmEnd"]);
56
+ const start = readPaintedStart(span) ?? NaN;
57
+ const end = readPaintedEnd(span) ?? NaN;
57
58
  if (pmPos >= start && pmPos <= end) return true;
58
59
  }
59
60
  return false;
@@ -65,8 +66,8 @@ function findLineElementAtPosition(container, pmPos) {
65
66
  for (const lineEl of Array.from(allLines)) {
66
67
  const paragraph = lineEl.closest(".layout-paragraph");
67
68
  if (!paragraph) continue;
68
- const pStart = Number(paragraph.dataset["pmStart"]);
69
- const pEnd = Number(paragraph.dataset["pmEnd"]);
69
+ const pStart = readPaintedStart(paragraph) ?? NaN;
70
+ const pEnd = readPaintedEnd(paragraph) ?? NaN;
70
71
  if (pmPos >= pStart && pmPos <= pEnd) {
71
72
  if (paragraph.querySelector(".layout-line") === lineEl) return lineEl;
72
73
  }
@@ -75,24 +76,25 @@ function findLineElementAtPosition(container, pmPos) {
75
76
  }
76
77
  /** @internal */
77
78
  function findPositionOnLineAtClientX(lineEl, clientX) {
78
- const spans = lineEl.querySelectorAll("span[data-pm-start][data-pm-end]");
79
+ const spans = lineEl.querySelectorAll(`span${PAINTED_RANGE_SELECTOR}`);
79
80
  const emptyRun = lineEl.querySelector(".layout-empty-run");
80
81
  if (emptyRun) {
81
- const emptyRunStart = emptyRun.dataset["pmStart"];
82
- if (emptyRunStart !== void 0) return Number(emptyRunStart);
83
- const paragraphStart = emptyRun.closest(".layout-paragraph")?.dataset["pmStart"];
84
- return paragraphStart === void 0 ? null : Number(paragraphStart) + 1;
82
+ const emptyRunStart = readPaintedStart(emptyRun);
83
+ if (emptyRunStart !== void 0) return emptyRunStart;
84
+ const paragraph = emptyRun.closest(".layout-paragraph");
85
+ const paragraphStart = paragraph === null ? void 0 : readPaintedStart(paragraph);
86
+ return paragraphStart === void 0 ? null : paragraphStart + 1;
85
87
  }
86
88
  if (spans.length === 0) {
87
89
  const paragraph = lineEl.closest(".layout-paragraph");
88
- if (paragraph?.dataset["pmStart"]) return Number(paragraph.dataset["pmStart"]) + 1;
90
+ if (paragraph !== null && hasPaintedStart(paragraph)) return (readPaintedStart(paragraph) ?? NaN) + 1;
89
91
  return null;
90
92
  }
91
93
  for (const span of Array.from(spans)) {
92
94
  const spanEl = span;
93
95
  const rect = spanEl.getBoundingClientRect();
94
- const pmStart = Number(spanEl.dataset["pmStart"]);
95
- const pmEnd = Number(spanEl.dataset["pmEnd"]);
96
+ const pmStart = readPaintedStart(spanEl) ?? NaN;
97
+ const pmEnd = readPaintedEnd(spanEl) ?? NaN;
96
98
  if (spanEl.classList.contains("layout-run-tab")) {
97
99
  if (clientX >= rect.left && clientX <= rect.right) return clientX < (rect.left + rect.right) / 2 ? pmStart : pmEnd;
98
100
  continue;
@@ -133,7 +135,7 @@ function findPositionOnLineAtClientX(lineEl, clientX) {
133
135
  }
134
136
  }
135
137
  if (!closestSpan) return null;
136
- return clientX < closestSpan.getBoundingClientRect().left ? Number(closestSpan.dataset["pmStart"]) : Number(closestSpan.dataset["pmEnd"]);
138
+ return clientX < closestSpan.getBoundingClientRect().left ? readPaintedStart(closestSpan) ?? NaN : readPaintedEnd(closestSpan) ?? NaN;
137
139
  }
138
140
  /**
139
141
  * The step the next vertical move continues from: the remembered one while the
@@ -12,5 +12,24 @@ export declare class ProseMirrorDocumentValidationError extends Error {
12
12
  constructor(context: string, issues: ProseMirrorDocumentValidationIssue[]);
13
13
  }
14
14
  export declare const validateProseMirrorDocument: (doc: Node) => ValidateProseMirrorDocumentResult;
15
+ /** The pairing pass over every node, skipping none: the reference for the skip. */
16
+ export declare const bookmarkIssuesWalkingEveryNode: (doc: Node) => ProseMirrorDocumentValidationIssue[];
17
+ /** The pairing pass as validation runs it. */
18
+ export declare const bookmarkIssues: (doc: Node) => ProseMirrorDocumentValidationIssue[];
15
19
  export declare const assertValidProseMirrorDocument: (doc: Node, context: string) => void;
20
+ /** A story document that passed validation, as the next one is checked against it. */
21
+ export type ValidatedStory = {
22
+ doc: Node;
23
+ /** The indices of its children holding a bookmark boundary. */
24
+ holders: readonly number[];
25
+ };
26
+ /**
27
+ * {@link assertValidProseMirrorDocument} for a story document, checking only
28
+ * the top-level children that `previous`, the last document that passed,
29
+ * did not hold: the run of children from the start and the run to the end
30
+ * that are the very nodes `previous` held were valid there, and the bookmark
31
+ * pass visits the children holding a boundary, kept ones by their shifted
32
+ * index. Gives what the next document is checked against.
33
+ */
34
+ export declare const assertValidProseMirrorDocumentKeeping: (doc: Node, context: string, previous: ValidatedStory | undefined) => ValidatedStory;
16
35
  export declare const formatProseMirrorDocumentIssues: (issues: ProseMirrorDocumentValidationIssue[]) => string[];
@@ -1,4 +1,5 @@
1
1
  import { readNoteMarkerAttrs } from "../internal/noteMarkerAttrs.js";
2
+ import { subtreeHolds } from "../internal/subtreeHolds.js";
2
3
  import { readBlockCustomXmlAttrs, readBlockSdtAttrs, readCharacterSpacingMarkAttrs, readCharacterStyleMarkAttrs, readCommentMarkAttrs, readEmphasisMarkAttrs, readFieldAttrs, readFontFamilyMarkAttrs, readFontSizeMarkAttrs, readFootnoteRefMarkAttrs, readHardBreakAttrs, readHighlightMarkAttrs, readHyperlinkMarkAttrs, readImageAttrs, readInlineWrapperMarkAttrs, readLanguageMarkAttrs, readMathAttrs, readPageBreakRunAttrs, readParagraphAttrs, readPreservedBlockAttrs, readPreservedXmlAttrs, readRunFormattingOverrideMarkAttrs, readRunIdentityMarkAttrs, readRunPropertyChangeMarkAttrs, readRunShadingMarkAttrs, readSdtAttrs, readShapeAttrs, readStrikeMarkAttrs, readSymbolAttrs, readTabAttrs, readTableAttrs, readTableCellAttrs, readTableRowAttrs, readTextBoxAttrs, readTextColorMarkAttrs, readTextEffectMarkAttrs, readTrackedChangeMarkAttrs, readUnderlineMarkAttrs } from "./attrs/index.js";
3
4
  import { readBookmarkBoundaryAttrs } from "./bookmarkBoundaryAttrs.js";
4
5
  import { readCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
@@ -43,7 +44,7 @@ const validateProseMirrorDocument = (doc) => {
43
44
  message: `Expected doc, got ${doc.type.name}.`
44
45
  });
45
46
  validateNode(doc, "doc", issues);
46
- validateBookmarkBoundaryStructure(doc, issues);
47
+ validateBookmarkBoundaryStructure(doc, issues, holdsNoBookmarkBoundary);
47
48
  return {
48
49
  valid: issues.length === 0,
49
50
  issues
@@ -61,7 +62,40 @@ const describeParagraph = (attrs, path) => {
61
62
  return paraId !== void 0 && paraId.length > 0 ? `paragraph ${paraId}` : `paragraph at ${path}`;
62
63
  };
63
64
  const describeBookmark = (id, name) => name === null || name.length === 0 ? `Bookmark id ${id}` : `Bookmark "${name}" (id ${id})`;
64
- const validateBookmarkBoundaryStructure = (doc, issues) => {
65
+ const carriesBookmarkBoundary = (node) => {
66
+ switch (node.type.name) {
67
+ case "bookmarkBoundary":
68
+ case "blockBookmarkBoundary": return true;
69
+ case "paragraph": {
70
+ const attrs = readParagraphAttrs(node);
71
+ return !attrs.ok || (attrs.value.bookmarks?.length ?? 0) > 0;
72
+ }
73
+ case "table": {
74
+ const attrs = readTableAttrs(node);
75
+ return !attrs.ok || (attrs.value._bookmarks?.length ?? 0) > 0;
76
+ }
77
+ case "tableRow": {
78
+ const attrs = readTableRowAttrs(node);
79
+ return !attrs.ok || (attrs.value._bookmarks?.length ?? 0) > 0;
80
+ }
81
+ default: return false;
82
+ }
83
+ };
84
+ const holdsBookmarkBoundary = subtreeHolds(carriesBookmarkBoundary);
85
+ const holdsNoBookmarkBoundary = (node) => !holdsBookmarkBoundary(node);
86
+ /** The pairing pass over every node, skipping none: the reference for the skip. */
87
+ const bookmarkIssuesWalkingEveryNode = (doc) => {
88
+ const issues = [];
89
+ validateBookmarkBoundaryStructure(doc, issues, () => false);
90
+ return issues;
91
+ };
92
+ /** The pairing pass as validation runs it. */
93
+ const bookmarkIssues = (doc) => {
94
+ const issues = [];
95
+ validateBookmarkBoundaryStructure(doc, issues, holdsNoBookmarkBoundary);
96
+ return issues;
97
+ };
98
+ const validateBookmarkBoundaryStructure = (doc, issues, skip, holders) => {
65
99
  const open = /* @__PURE__ */ new Map();
66
100
  const startedBy = /* @__PURE__ */ new Map();
67
101
  /** Whether the boundary opened, and so needs a matching end registered later. */
@@ -161,9 +195,10 @@ const validateBookmarkBoundaryStructure = (doc, issues) => {
161
195
  });
162
196
  else if (open.has(marker.id)) registerEnd(marker.id, markerPath, enclosingParagraph);
163
197
  };
164
- node.forEach((child, _offset, index) => {
198
+ if (node === doc && holders !== void 0) for (const index of holders) visit(node.child(index), `${path}.content[${index}]`, enclosingParagraph);
199
+ else node.forEach((child, _offset, index) => {
165
200
  visitPositionedBookmarks(index);
166
- visit(child, `${path}.content[${index}]`, enclosingParagraph);
201
+ if (!skip(child)) visit(child, `${path}.content[${index}]`, enclosingParagraph);
167
202
  });
168
203
  visitPositionedBookmarks(node.childCount);
169
204
  for (const { id, path: bookmarkPath } of openedAttrBookmarks) registerEnd(id, bookmarkPath, enclosingParagraph);
@@ -186,6 +221,44 @@ const assertValidProseMirrorDocument = (doc, context) => {
186
221
  }
187
222
  throw new ProseMirrorDocumentValidationError(context, validation.issues);
188
223
  };
224
+ /**
225
+ * {@link assertValidProseMirrorDocument} for a story document, checking only
226
+ * the top-level children that `previous`, the last document that passed,
227
+ * did not hold: the run of children from the start and the run to the end
228
+ * that are the very nodes `previous` held were valid there, and the bookmark
229
+ * pass visits the children holding a boundary, kept ones by their shifted
230
+ * index. Gives what the next document is checked against.
231
+ */
232
+ const assertValidProseMirrorDocumentKeeping = (doc, context, previous) => {
233
+ const before = previous?.doc;
234
+ const count = doc.childCount;
235
+ const old = before?.childCount ?? 0;
236
+ let start = 0;
237
+ while (start < count && start < old && doc.child(start) === before?.child(start)) start += 1;
238
+ let after = 0;
239
+ while (after < count - start && after < old - start && doc.child(count - 1 - after) === before?.child(old - 1 - after)) after += 1;
240
+ const issues = [];
241
+ if (doc.type.name !== "doc") issues.push({
242
+ path: "doc.type.name",
243
+ message: `Expected doc, got ${doc.type.name}.`
244
+ });
245
+ validateNodeAttrs(doc, "doc", issues);
246
+ validateMarks(doc.marks, "doc", issues);
247
+ for (let index = start; index < count - after; index += 1) validateNode(doc.child(index), `doc.content[${index}]`, issues);
248
+ const shift = count - old;
249
+ const holders = [];
250
+ for (const index of previous?.holders ?? []) if (index < start) holders.push(index);
251
+ for (let index = start; index < count - after; index += 1) if (holdsBookmarkBoundary(doc.child(index))) holders.push(index);
252
+ for (const index of previous?.holders ?? []) if (index >= old - after) holders.push(index + shift);
253
+ validateBookmarkBoundaryStructure(doc, issues, holdsNoBookmarkBoundary, holders);
254
+ if (issues.length > 0) throw new ProseMirrorDocumentValidationError(context, issues);
255
+ validNodeCache.add(doc);
256
+ validDocumentCache.add(doc);
257
+ return {
258
+ doc,
259
+ holders
260
+ };
261
+ };
189
262
  const formatProseMirrorDocumentIssues = (issues) => issues.map((issue) => `ProseMirror document error at ${issue.path}: ${issue.message}`);
190
263
  const validateNode = (node, path, issues) => {
191
264
  if (validNodeCache.has(node)) return;
@@ -212,6 +285,7 @@ const validateNodeAttrs = (node, path, issues) => {
212
285
  appendAttrIssues(path, readCommentReferenceAttrs(node), issues);
213
286
  return;
214
287
  case "commentRangeBoundary":
288
+ case "blockCommentRangeBoundary":
215
289
  appendAttrIssues(path, readCommentRangeBoundaryAttrs(node), issues);
216
290
  return;
217
291
  case "rangeAnchor":
@@ -433,4 +507,4 @@ const withPathPrefix = (prefix, issue) => ({
433
507
  path: `${prefix}.${issue.path}`,
434
508
  message: issue.message
435
509
  });
436
- export { ProseMirrorDocumentValidationError, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument };
510
+ export { ProseMirrorDocumentValidationError, assertValidProseMirrorDocument, assertValidProseMirrorDocumentKeeping, bookmarkIssues, bookmarkIssuesWalkingEveryNode, formatProseMirrorDocumentIssues, validateProseMirrorDocument };