@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
@@ -0,0 +1,106 @@
1
+ import { contentControlLockAllows, firstLockedControlViolation } from "@stll/docx-core/model";
2
+ // src/prosemirror/lockedControls.ts
3
+ /** The node types that carry a content control's `w:lock`. */
4
+ const CONTROL_NODE_NAMES = /* @__PURE__ */ new Set(["sdt", "blockSdt"]);
5
+ const lockOf = (node) => {
6
+ if (!CONTROL_NODE_NAMES.has(node.type.name)) return null;
7
+ const lock = node.attrs["lock"];
8
+ switch (lock) {
9
+ case "contentLocked":
10
+ case "sdtContentLocked":
11
+ case "sdtLocked": return lock;
12
+ default: return null;
13
+ }
14
+ };
15
+ /** Every control of `doc` whose lock forbids something, outermost first. */
16
+ const spansByDoc = /* @__PURE__ */ new WeakMap();
17
+ const lockedControlSpans = (doc) => {
18
+ const known = spansByDoc.get(doc);
19
+ if (known !== void 0) return known;
20
+ const spans = [];
21
+ doc.descendants((node, pos) => {
22
+ const lock = lockOf(node);
23
+ if (lock !== null) spans.push({
24
+ lock,
25
+ from: pos,
26
+ to: pos + node.nodeSize,
27
+ contentFrom: pos + 1,
28
+ contentTo: pos + node.nodeSize - 1
29
+ });
30
+ return true;
31
+ });
32
+ spansByDoc.set(doc, spans);
33
+ return spans;
34
+ };
35
+ /** What the locks of `doc` say about `touches`: `null` when they permit them all. */
36
+ const lockedControlViolationIn = (doc, touches) => touches.length === 0 ? null : firstLockedControlViolation(lockedControlSpans(doc), touches);
37
+ /** Marks that annotate content without being part of it. */
38
+ const ANNOTATION_MARKS = /* @__PURE__ */ new Set(["comment", "runIdentity"]);
39
+ /** Attributes that identify a node without being part of its content. */
40
+ const IDENTITY_ATTRS = /* @__PURE__ */ new Set(["paraId", "textId"]);
41
+ const sameAttrs = (left, right) => {
42
+ const keys = /* @__PURE__ */ new Set([...Object.keys(left.attrs), ...Object.keys(right.attrs)]);
43
+ for (const key of keys) {
44
+ if (IDENTITY_ATTRS.has(key)) continue;
45
+ if (JSON.stringify(left.attrs[key]) !== JSON.stringify(right.attrs[key])) return false;
46
+ }
47
+ return true;
48
+ };
49
+ const contentMarks = (node) => node.marks.filter((mark) => !ANNOTATION_MARKS.has(mark.type.name));
50
+ /** Whether two nodes hold the same content, annotations and identities aside. */
51
+ const sameLockedContent = (left, right) => {
52
+ if (left.type !== right.type) return false;
53
+ if (left.isText && left.text !== right.text) return false;
54
+ if (!sameAttrs(left, right)) return false;
55
+ const leftMarks = contentMarks(left);
56
+ const rightMarks = contentMarks(right);
57
+ if (leftMarks.length !== rightMarks.length || leftMarks.some((mark, index) => {
58
+ const other = rightMarks[index];
59
+ return other === void 0 || !mark.eq(other);
60
+ })) return false;
61
+ return sameLockedChildren(left, right);
62
+ };
63
+ /** Whether two nodes' children hold the same content (their own attributes aside). */
64
+ function sameLockedChildren(left, right) {
65
+ if (left.childCount !== right.childCount) return false;
66
+ for (let index = 0; index < left.childCount; index += 1) if (!sameLockedContent(left.child(index), right.child(index))) return false;
67
+ return true;
68
+ }
69
+ /**
70
+ * The node `span`'s control is in `transform`'s result, or `null` when it is
71
+ * gone. A step may rewrite the stretch around a control with a copy of it, so
72
+ * the control is looked for at either side of where its ends map to.
73
+ */
74
+ const survivorOf = (transform, span, before) => {
75
+ const { mapping, doc } = transform;
76
+ for (const startSide of [1, -1]) for (const endSide of [-1, 1]) {
77
+ const start = mapping.map(span.from, startSide);
78
+ const end = mapping.map(span.to, endSide);
79
+ const after = doc.nodeAt(start);
80
+ if (after?.type === before.type && start + after.nodeSize === end) return after;
81
+ }
82
+ return null;
83
+ };
84
+ /**
85
+ * What the locks of `transform`'s starting document say about its result: a
86
+ * control whose content is locked must come through with the same content,
87
+ * and one locked against removal must come through at all. Read from the
88
+ * result rather than the steps, so it holds for any step a command takes.
89
+ */
90
+ const lockedControlViolationOfTransform = (transform) => {
91
+ if (!transform.docChanged) return null;
92
+ for (const span of lockedControlSpans(transform.before)) {
93
+ const before = transform.before.nodeAt(span.from);
94
+ if (before === null) continue;
95
+ const after = survivorOf(transform, span, before);
96
+ let change = null;
97
+ if (after === null) change = "removeControl";
98
+ else if (!sameLockedChildren(before, after)) change = "editContent";
99
+ if (change !== null && !contentControlLockAllows(span.lock, change)) return {
100
+ lock: span.lock,
101
+ change
102
+ };
103
+ }
104
+ return null;
105
+ };
106
+ export { lockedControlSpans, lockedControlViolationIn, lockedControlViolationOfTransform };
@@ -93,7 +93,7 @@ const projectStoryMarkupView = ({ doc, markupView, styles, numbering }) => {
93
93
  if (cached && cached.styles === styles && cached.numbering === numbering) return projectMarkupView(cached.state, markupView);
94
94
  const state = EditorState.create({
95
95
  doc,
96
- plugins: [createDocumentStyleContextPlugin(styles), createDocumentNumberingPlugin(numbering)]
96
+ plugins: [createDocumentNumberingPlugin(numbering), createDocumentStyleContextPlugin(styles)]
97
97
  });
98
98
  storyProjectionStates.set(doc, {
99
99
  styles,
@@ -0,0 +1,33 @@
1
+ import { Plugin } from "prosemirror-state";
2
+ import { EditorView } from "prosemirror-view";
3
+ /** Take the caret the browser shows into the editor state before input. */
4
+ export declare const adoptNativeSelection: (view: EditorView) => void;
5
+ /** Whether a keydown belongs to an input method composition. */
6
+ export declare const isCompositionKeyDown: (event: KeyboardEvent) => boolean;
7
+ /**
8
+ * Where a browser caret for the editor's collapsed selection belongs: in the
9
+ * text before it, or at a paragraph's start in the first text. ProseMirror
10
+ * treats the end of one text node and the start of the next run as one
11
+ * position, but the browser types and composes into the node it holds.
12
+ * `null` when the selection is not a caret in text.
13
+ */
14
+ export declare const textCaretOf: (view: EditorView) => {
15
+ node: Node;
16
+ offset: number;
17
+ } | null;
18
+ /**
19
+ * Sets the browser's selection again after an update that changed the
20
+ * document, unless it was just set where it belongs.
21
+ *
22
+ * ProseMirror leaves a DOM selection it reads as the same position, such as
23
+ * the start of the next run instead of the end of the previous one, or a
24
+ * caret beside a redrawn paragraph. Chromium's input method then resolves the
25
+ * next composition's start from the start of the editable content, and it
26
+ * picks the text node to compose into before `compositionstart`, so the
27
+ * text in progress shows elsewhere. A caret goes into the text before it,
28
+ * where a composition continues the run it follows.
29
+ *
30
+ * A selection the browser or ProseMirror set since the last update has a new
31
+ * range; one left alone keeps its range and is set again.
32
+ */
33
+ export declare const createNativeSelectionRefreshPlugin: () => Plugin;
@@ -0,0 +1,74 @@
1
+ import { Plugin, TextSelection } from "prosemirror-state";
2
+ // src/prosemirror/nativeSelection.ts
3
+ /** Take the caret the browser shows into the editor state before input. */
4
+ const adoptNativeSelection = (view) => {
5
+ if (view.composing || view.isDestroyed) return;
6
+ const { selection } = view.state;
7
+ const native = view.dom.ownerDocument.getSelection();
8
+ if (!(selection instanceof TextSelection || native?.isCollapsed === true) || !native?.anchorNode || !native.focusNode || !view.dom.contains(native.anchorNode) || !view.dom.contains(native.focusNode)) return;
9
+ const anchor = view.posAtDOM(native.anchorNode, native.anchorOffset);
10
+ const head = view.posAtDOM(native.focusNode, native.focusOffset);
11
+ if (anchor === selection.anchor && head === selection.head) return;
12
+ const { doc } = view.state;
13
+ if (!doc.resolve(anchor).parent.inlineContent || !doc.resolve(head).parent.inlineContent) return;
14
+ view.dispatch(view.state.tr.setSelection(TextSelection.create(doc, anchor, head)));
15
+ };
16
+ /** Whether a keydown belongs to an input method composition. */
17
+ const isCompositionKeyDown = (event) => event.isComposing || event.key === "Process";
18
+ const nativeRange = (view) => {
19
+ const native = view.dom.ownerDocument.getSelection();
20
+ return native !== null && native.rangeCount > 0 ? native.getRangeAt(0) : null;
21
+ };
22
+ /**
23
+ * Where a browser caret for the editor's collapsed selection belongs: in the
24
+ * text before it, or at a paragraph's start in the first text. ProseMirror
25
+ * treats the end of one text node and the start of the next run as one
26
+ * position, but the browser types and composes into the node it holds.
27
+ * `null` when the selection is not a caret in text.
28
+ */
29
+ const textCaretOf = (view) => {
30
+ const { selection } = view.state;
31
+ if (!selection.empty) return null;
32
+ const before = view.domAtPos(selection.from, -1);
33
+ const { node, offset } = before.node.nodeType === before.node.TEXT_NODE ? before : view.domAtPos(selection.from, 1);
34
+ return node.nodeType === node.TEXT_NODE ? {
35
+ node,
36
+ offset
37
+ } : null;
38
+ };
39
+ /**
40
+ * Sets the browser's selection again after an update that changed the
41
+ * document, unless it was just set where it belongs.
42
+ *
43
+ * ProseMirror leaves a DOM selection it reads as the same position, such as
44
+ * the start of the next run instead of the end of the previous one, or a
45
+ * caret beside a redrawn paragraph. Chromium's input method then resolves the
46
+ * next composition's start from the start of the editable content, and it
47
+ * picks the text node to compose into before `compositionstart`, so the
48
+ * text in progress shows elsewhere. A caret goes into the text before it,
49
+ * where a composition continues the run it follows.
50
+ *
51
+ * A selection the browser or ProseMirror set since the last update has a new
52
+ * range; one left alone keeps its range and is set again.
53
+ */
54
+ const createNativeSelectionRefreshPlugin = () => new Plugin({ view: (view) => {
55
+ let held = nativeRange(view);
56
+ return { update: (current, previous) => {
57
+ const native = current.dom.ownerDocument.getSelection();
58
+ const range = nativeRange(current);
59
+ if (native !== null && range !== null && current.state.doc !== previous.doc && !current.composing && current.hasFocus() && current.dom.contains(range.startContainer) && current.dom.contains(range.endContainer)) {
60
+ const stale = range === held;
61
+ const caret = native.isCollapsed ? textCaretOf(current) : null;
62
+ const { anchorNode, anchorOffset, focusNode, focusOffset } = native;
63
+ if (caret !== null && (stale || anchorNode !== caret.node || anchorOffset !== caret.offset)) {
64
+ native.removeAllRanges();
65
+ native.collapse(caret.node, caret.offset);
66
+ } else if (caret === null && stale && anchorNode && focusNode) {
67
+ native.removeAllRanges();
68
+ native.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
69
+ }
70
+ }
71
+ held = nativeRange(current);
72
+ } };
73
+ } });
74
+ export { adoptNativeSelection, createNativeSelectionRefreshPlugin, isCompositionKeyDown, textCaretOf };
@@ -75,9 +75,9 @@ const restoredNote = (note, document, reference) => {
75
75
  schema,
76
76
  doc,
77
77
  plugins: [
78
+ createDocumentNumberingPlugin(numbering),
78
79
  ...pluginsForHeadlessRevisionResolution(singletonManager.getPlugins()),
79
- createDocumentStylesPlugin(styles),
80
- createDocumentNumberingPlugin(numbering)
80
+ createDocumentStylesPlugin(styles)
81
81
  ]
82
82
  });
83
83
  rejectAIEditRevision(revisions)(state, (transaction) => {
@@ -19,4 +19,6 @@ export declare function stampNumberedRefFieldBaselines(doc: Node): Node;
19
19
  * Unsupported or uncalibrated fields are absent from the returned map and retain their cache.
20
20
  */
21
21
  export declare function resolveNumberedRefFields(doc: Node, options?: NumberedRefResolutionOptions): ReadonlyMap<Node, string>;
22
+ /** The resolution visiting every node, skipping none: the reference for the skip. */
23
+ export declare function resolveNumberedRefFieldsVisitingEveryNode(doc: Node, options?: NumberedRefResolutionOptions): ReadonlyMap<Node, string>;
22
24
  export {};
@@ -1,4 +1,5 @@
1
1
  import { resolveListTemplateWithComponents } from "../docx/listTemplate.js";
2
+ import { subtreeHolds } from "../internal/subtreeHolds.js";
2
3
  import { expectFieldAttrs, expectParagraphAttrs } from "./attrs/index.js";
3
4
  import { expectBookmarkBoundaryAttrs } from "./bookmarkBoundaryAttrs.js";
4
5
  import { advanceVisibleListMarker, createListCounterState } from "./listMarker.js";
@@ -164,10 +165,13 @@ function relativeNumber(target, source) {
164
165
  function normalizeCachedResult(value) {
165
166
  return value.replaceAll("\xA0", " ").replace(/\s+/gu, " ").trim();
166
167
  }
167
- function collectNumberedRefCandidates(doc, options) {
168
+ const isFieldNode = (node) => node.type.name === "field" || node.type.name === "structuredField";
169
+ const holdsField = subtreeHolds(isFieldNode);
170
+ function collectNumberedRefCandidates(doc, options, skip) {
168
171
  const fields = [];
169
172
  doc.descendants((node) => {
170
- if (node.type.name !== "field" && node.type.name !== "structuredField") return true;
173
+ if (skip(node)) return false;
174
+ if (!isFieldNode(node)) return true;
171
175
  if (fields.length >= MAX_NUMBERED_REF_FIELDS) return false;
172
176
  const attrs = expectFieldAttrs(node);
173
177
  if (attrs.fieldType !== "REF" || attrs.fldLock) return false;
@@ -254,7 +258,7 @@ const mapDocument = (node, transform) => {
254
258
  function stampNumberedRefFieldBaselines(doc) {
255
259
  const baselines = /* @__PURE__ */ new WeakMap();
256
260
  let hasBaselines = false;
257
- for (const candidate of collectNumberedRefCandidates(doc, {})) if (isCalibratedCandidate(candidate)) {
261
+ for (const candidate of collectNumberedRefCandidates(doc, {}, (node) => !holdsField(node))) if (isCalibratedCandidate(candidate)) {
258
262
  baselines.set(candidate.node, candidate.cached);
259
263
  hasBaselines = true;
260
264
  }
@@ -273,8 +277,15 @@ function stampNumberedRefFieldBaselines(doc) {
273
277
  * Unsupported or uncalibrated fields are absent from the returned map and retain their cache.
274
278
  */
275
279
  function resolveNumberedRefFields(doc, options = {}) {
280
+ return resolveCandidates(collectNumberedRefCandidates(doc, options, (node) => !holdsField(node)));
281
+ }
282
+ /** The resolution visiting every node, skipping none: the reference for the skip. */
283
+ function resolveNumberedRefFieldsVisitingEveryNode(doc, options = {}) {
284
+ return resolveCandidates(collectNumberedRefCandidates(doc, options, () => false));
285
+ }
286
+ function resolveCandidates(candidates) {
276
287
  const results = /* @__PURE__ */ new Map();
277
- for (const candidate of collectNumberedRefCandidates(doc, options)) if (isCalibratedCandidate(candidate)) results.set(candidate.node, candidate.value);
288
+ for (const candidate of candidates) if (isCalibratedCandidate(candidate)) results.set(candidate.node, candidate.value);
278
289
  return results;
279
290
  }
280
- export { parseNumberedRefInstruction, resolveNumberedRefFields, stampNumberedRefFieldBaselines };
291
+ export { parseNumberedRefInstruction, resolveNumberedRefFields, resolveNumberedRefFieldsVisitingEveryNode, stampNumberedRefFieldBaselines };
@@ -1,16 +1,14 @@
1
1
  import { RunStyleResolver } from "./runStyleFormatting.js";
2
2
  import { Node } from "prosemirror-model";
3
3
  import { Transaction } from "prosemirror-state";
4
+ /** The attributes a join decides, for a check that the schema adds none undecided. */
5
+ export declare const JOINED_PARAGRAPH_ATTR_NAMES: readonly string[];
4
6
  /**
5
- * The attrs the paragraph a join leaves takes: `next`'s, less the editing
6
- * sessions (`w:rsid*` attributes) it shares with the removed `paragraph`.
7
- *
8
- * A split copies the paragraph's attrs onto both halves, and a save writes
9
- * the sessions on the first half only, the first record in document order.
10
- * Rejecting the split removes that first half, so the paragraph left names
11
- * none of them, live as after a save.
7
+ * The attrs of the paragraph a join leaves, each by its rule in
8
+ * `JOINED_PARAGRAPH_ATTRS`. `between` is the inline size the join places
9
+ * between the two paragraphs' content.
12
10
  */
13
- export declare const joinedParagraphAttrs: (paragraph: Node, next: Node) => Node["attrs"];
11
+ export declare const joinedParagraphAttrs: (paragraph: Node, next: Node, between?: number) => Node["attrs"];
14
12
  type JoinAtParagraphMarkOptions = {
15
13
  tr: Transaction;
16
14
  /** Position of the paragraph whose mark goes. */
@@ -1,4 +1,4 @@
1
- import { getProseParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
1
+ import { PARAGRAPH_SOURCE_JOIN_RULES, getProseParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
2
2
  import { paragraphJoinAfter } from "./commands/paragraphBookmarkJoin.js";
3
3
  import { JOINED_RUNS_RESTYLED_META } from "./extensions/features/JoinedRunStyleExtension.js";
4
4
  import { rebaseParagraphRuns } from "./rebaseParagraphRunFormatting.js";
@@ -20,21 +20,160 @@ import { panic } from "better-result";
20
20
  * The first paragraph's runs keep their direct formatting; what its style
21
21
  * lent them is re-read in the next paragraph's style.
22
22
  */
23
+ const nextValue = (key) => (sides) => sides.next.attrs[key];
24
+ /** The paragraph-level records each side holds, in document order. */
25
+ const bothSides = (key, shift) => ({ paragraph, next, between }) => {
26
+ const left = paragraph.attrs[key];
27
+ const right = next.attrs[key];
28
+ const items = [...Array.isArray(left) ? left : [], ...Array.isArray(right) ? right.map((item) => shift(item, paragraph.content.size + between)) : []];
29
+ return items.length === 0 ? right : items;
30
+ };
31
+ /** The suggestion a paragraph's whole-paragraph insert marker names, if any. */
32
+ const suggestedInsertOf = (node) => {
33
+ const marker = node.attrs["_suggestedInsert"];
34
+ return typeof marker === "object" && marker !== null && typeof marker.suggestionId === "string" && typeof marker.revisionId === "number" ? marker : null;
35
+ };
23
36
  /**
24
- * The attrs the paragraph a join leaves takes: `next`'s, less the editing
25
- * sessions (`w:rsid*` attributes) it shares with the removed `paragraph`.
26
- *
27
- * A split copies the paragraph's attrs onto both halves, and a save writes
28
- * the sessions on the first half only, the first record in document order.
29
- * Rejecting the split removes that first half, so the paragraph left names
30
- * none of them, live as after a save.
37
+ * Whether the joined paragraph is still all one suggestion's insertion: only
38
+ * when both paragraphs were. A paragraph that held other words is not, so it
39
+ * keeps no whole-paragraph marker; the mark it ends with records the next
40
+ * paragraph's suggested insertion instead (`pPrMark`).
41
+ */
42
+ const stillWhollySuggested = ({ paragraph, next }) => {
43
+ const left = suggestedInsertOf(paragraph);
44
+ const right = suggestedInsertOf(next);
45
+ return left !== null && right !== null && left.suggestionId === right.suggestionId;
46
+ };
47
+ /**
48
+ * Every attribute of the joined paragraph, decided one by one. The mark that
49
+ * stays is the next paragraph's, so most come from it; what the paragraph
50
+ * holds as content (boundary bookmarks, empty hyperlinks) comes from both,
51
+ * and a suggestion's whole-paragraph marker survives only where the whole
52
+ * joined paragraph is still that suggestion's.
53
+ */
54
+ const JOINED_PARAGRAPH_ATTRS = {
55
+ paraId: "next",
56
+ textId: "next",
57
+ idStability: "next",
58
+ ...PARAGRAPH_SOURCE_JOIN_RULES,
59
+ reviewCarrier: "next",
60
+ alignment: "next",
61
+ alignmentFromStyle: "next",
62
+ kinsoku: "next",
63
+ autoSpaceDE: "next",
64
+ autoSpaceDN: "next",
65
+ overflowPunctuation: "next",
66
+ suppressAutoHyphens: "next",
67
+ spaceBefore: "next",
68
+ spaceAfter: "next",
69
+ lineSpacing: "next",
70
+ lineSpacingRule: "next",
71
+ lineSpacingExplicit: "next",
72
+ snapToGrid: "next",
73
+ spacingExplicit: "next",
74
+ spacingFromDocDefaults: "next",
75
+ spacingFromImplicitDefaultStyle: "next",
76
+ indentLeft: "next",
77
+ indentRight: "next",
78
+ indentFirstLine: "next",
79
+ hangingIndent: "next",
80
+ numPr: "next",
81
+ _pastedHtmlList: "next",
82
+ numPrFromStyle: "next",
83
+ listNumFmt: "next",
84
+ listIsBullet: "next",
85
+ listIsLegal: "next",
86
+ listMarker: "next",
87
+ listMarkerTemplate: "next",
88
+ listMarkerHidden: "next",
89
+ listMarkerFormatting: "next",
90
+ listMarkerAlignment: "next",
91
+ listMarkerSuffix: "next",
92
+ listMarkerAllCaps: "next",
93
+ listImplicitChildLevelAdvances: "next",
94
+ listFoldedMarkerSuffix: "next",
95
+ listMarkerSecondSlotOffsetTwips: "next",
96
+ listLevelNumFmts: "next",
97
+ listLevelStarts: "next",
98
+ listLevelTabs: "next",
99
+ listAbstractNumId: "next",
100
+ listStartOverride: "next",
101
+ styleId: "next",
102
+ _tableOfContentsLevel: "next",
103
+ borders: "next",
104
+ shading: "next",
105
+ tabs: "next",
106
+ pageBreakBefore: "next",
107
+ renderedPageBreakBefore: "next",
108
+ keepNext: "next",
109
+ keepLines: "next",
110
+ widowControl: "next",
111
+ contextualSpacing: "next",
112
+ runInWithNext: "next",
113
+ defaultTextFormatting: "next",
114
+ _tableRunFormatting: "next",
115
+ direction: "next",
116
+ outlineLevel: "next",
117
+ _originalFormatting: "next",
118
+ _resolvedFormatting: "next",
119
+ _styleResolvedFormatting: "next",
120
+ _autospacingBase: "next",
121
+ _detachedWatermarkHost: "next",
122
+ _sectionProperties: "next",
123
+ _propertyChanges: "next",
124
+ _trailingPageBreak: "next",
125
+ _pageBreakCarrier: (sides) => sides.paragraph.content.size === 0 ? sides.next.attrs["_pageBreakCarrier"] : null,
126
+ bookmarks: bothSides("bookmarks", (item) => item),
127
+ _emptyHyperlinks: bothSides("_emptyHyperlinks", (item, by) => typeof item === "object" && item !== null && "offset" in item ? {
128
+ ...item,
129
+ offset: Number(item.offset) + by
130
+ } : item),
131
+ _preservedAttributes: ({ paragraph, next }) => {
132
+ const sessions = next.attrs["_preservedAttributes"];
133
+ return typeof sessions === "object" && sessions !== null && sessions === paragraph.attrs["_preservedAttributes"] ? null : sessions;
134
+ },
135
+ pPrMark: (sides) => {
136
+ const own = sides.next.attrs["pPrMark"];
137
+ if (own != null || stillWhollySuggested(sides)) return own;
138
+ const suggested = suggestedInsertOf(sides.next);
139
+ return suggested === null ? own : {
140
+ kind: "ins",
141
+ info: {
142
+ id: suggested.revisionId,
143
+ author: suggested.author,
144
+ ...suggested.date == null ? {} : { date: suggested.date },
145
+ ...typeof suggested.initials === "string" ? { initials: suggested.initials } : {},
146
+ provenance: "suggested",
147
+ suggestionId: suggested.suggestionId
148
+ }
149
+ };
150
+ },
151
+ _suggestedInsert: (sides) => stillWhollySuggested(sides) ? sides.next.attrs["_suggestedInsert"] : null
152
+ };
153
+ /** The attributes a join decides, for a check that the schema adds none undecided. */
154
+ const JOINED_PARAGRAPH_ATTR_NAMES = Object.keys(JOINED_PARAGRAPH_ATTRS);
155
+ /**
156
+ * The attrs of the paragraph a join leaves, each by its rule in
157
+ * `JOINED_PARAGRAPH_ATTRS`. `between` is the inline size the join places
158
+ * between the two paragraphs' content.
31
159
  */
32
- const joinedParagraphAttrs = (paragraph, next) => {
33
- const sessions = next.attrs["_preservedAttributes"];
34
- return typeof sessions === "object" && sessions !== null && sessions === paragraph.attrs["_preservedAttributes"] ? {
35
- ...next.attrs,
36
- _preservedAttributes: null
37
- } : next.attrs;
160
+ const joinedParagraphAttrs = (paragraph, next, between = 0) => {
161
+ const sides = {
162
+ paragraph,
163
+ next,
164
+ between
165
+ };
166
+ const rules = JOINED_PARAGRAPH_ATTRS;
167
+ const attrs = {};
168
+ let changed = false;
169
+ for (const key of Object.keys(next.attrs)) {
170
+ const rule = rules[key];
171
+ if (rule === void 0) panic(`A paragraph attribute has no join rule: ${key}`);
172
+ const value = (rule === "next" ? nextValue(key) : rule)(sides);
173
+ attrs[key] = value;
174
+ if (value !== next.attrs[key]) changed = true;
175
+ }
176
+ return changed ? attrs : next.attrs;
38
177
  };
39
178
  const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver }) => {
40
179
  const boundary = paragraphPos + paragraph.nodeSize;
@@ -44,7 +183,7 @@ const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver
44
183
  const leftToken = getProseParagraphPropertySourceToken(paragraph);
45
184
  const rightToken = getProseParagraphPropertySourceToken(next);
46
185
  tr.replaceWith(boundary - 1, join.nextPosition + 1, join.inlineBookmarks);
47
- tr.setNodeMarkup(paragraphPos, void 0, joinedParagraphAttrs(paragraph, next));
186
+ tr.setNodeMarkup(paragraphPos, void 0, joinedParagraphAttrs(paragraph, next, join.inlineBookmarks.reduce((size, node) => size + node.nodeSize, 0)));
48
187
  markParagraphPropertySourceTransfers(tr, [{
49
188
  displacedToken: typeof leftToken === "string" ? leftToken : null,
50
189
  selectedToken: typeof rightToken === "string" ? rightToken : null
@@ -67,4 +206,4 @@ const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver
67
206
  });
68
207
  tr.setMeta(JOINED_RUNS_RESTYLED_META, true);
69
208
  };
70
- export { joinAtParagraphMark, joinedParagraphAttrs };
209
+ export { JOINED_PARAGRAPH_ATTR_NAMES, joinAtParagraphMark, joinedParagraphAttrs };
@@ -1,4 +1,5 @@
1
1
  import { ContentControlBoundError, ContentControlLockedError, ContentControlTypeError } from "../../content-controls/errors.js";
2
+ import { readPaintedContentControlKey } from "../../utils/paintedPositions.js";
2
3
  import { findBlockSdtMatch, setContentControlValueTr } from "../commands/contentControls.js";
3
4
  import { createPluginKeyOwner } from "../pluginKeyOwner.js";
4
5
  import { selectLockedInlineControl } from "./lockedControlKeyHandling.js";
@@ -32,7 +33,6 @@ const CONTENT_CONTROL_WIDGET_EVENT_NAME = "folio:content-control-widget";
32
33
  const SDT_DATASET_KEY = {
33
34
  checked: "sdtChecked",
34
35
  listItems: "sdtListItems",
35
- pmPos: "sdtPmPos",
36
36
  tag: "sdtTag",
37
37
  type: "sdtType"
38
38
  };
@@ -65,7 +65,7 @@ const handleContentControlWidgetClick = ({ event, onEvent, view }) => {
65
65
  if (!anchor) return false;
66
66
  const tag = anchor.dataset[SDT_DATASET_KEY.tag] ?? "";
67
67
  const sdtType = anchor.dataset[SDT_DATASET_KEY.type];
68
- const pmPosRaw = anchor.dataset[SDT_DATASET_KEY.pmPos];
68
+ const pmPosRaw = readPaintedContentControlKey(anchor);
69
69
  const pmPos = pmPosRaw ? Number.parseInt(pmPosRaw, 10) : NaN;
70
70
  if (!sdtType || Number.isNaN(pmPos)) return false;
71
71
  try {
@@ -1,9 +1,11 @@
1
1
  import { getCachedNumberingMap } from "../../docx/numberingParser.js";
2
2
  import { completeNumberingForDoc, paragraphListReferences } from "../listInstanceReferences.js";
3
3
  import { createPluginKeyOwner } from "../pluginKeyOwner.js";
4
+ import { panic } from "better-result";
4
5
  import { AddMarkStep, DocAttrStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
5
6
  import { Plugin } from "prosemirror-state";
6
7
  // src/prosemirror/plugins/documentNumbering.ts
8
+ /** Document-scoped numbering definitions for list-editing commands. */
7
9
  const documentNumberingKey = createPluginKeyOwner("documentNumbering");
8
10
  const completedState = (definitions, doc) => {
9
11
  const completed = completeNumberingForDoc(definitions ?? void 0, doc);
@@ -14,43 +16,62 @@ const completedState = (definitions, doc) => {
14
16
  };
15
17
  const isReplace = (step) => step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
16
18
  const leavesNumberingUnchanged = (step) => step instanceof AddMarkStep || step instanceof RemoveMarkStep || step instanceof DocAttrStep;
17
- const containsNumberedParagraph = (node, from, to) => {
19
+ /** The instances a package's numbering part defines, by its definitions object. */
20
+ const definedInstances = /* @__PURE__ */ new WeakMap();
21
+ const instancesDefinedBy = (definitions) => {
22
+ if (definitions === null) return /* @__PURE__ */ new Set();
23
+ let defined = definedInstances.get(definitions);
24
+ if (defined === void 0) {
25
+ defined = new Set((definitions.nums ?? []).map(({ numId }) => numId));
26
+ definedInstances.set(definitions, defined);
27
+ }
28
+ return defined;
29
+ };
30
+ /**
31
+ * Whether a paragraph names an instance the package does not define: only
32
+ * those reach the completed numbering, which adds an instance for each.
33
+ */
34
+ const namesUndefinedInstance = (node, defined) => paragraphListReferences(node).some((numId) => !defined.has(numId));
35
+ const containsUndefinedReference = (node, from, to, defined) => {
18
36
  let found = false;
19
37
  node.nodesBetween(from, to, (child, pos) => {
20
- if (child.type.name !== "paragraph" || pos < from || pos + child.nodeSize > to || paragraphListReferences(child).length === 0) return !found;
38
+ if (child.type.name !== "paragraph" || pos < from || pos + child.nodeSize > to || !namesUndefinedInstance(child, defined)) return !found;
21
39
  found = true;
22
40
  return false;
23
41
  });
24
42
  return found;
25
43
  };
26
44
  /**
27
- * Whether a transaction can change a paragraph-level numbering source. Text
28
- * and mark edits do not; paragraph attrs and structural replacements do. The
29
- * latter are inspected in the step-local document rather than by walking the
30
- * completed document.
45
+ * Whether a transaction can change the completed numbering: the instances the
46
+ * document names that the package does not define. Text and mark edits do
47
+ * not; paragraph attrs can. A structural replacement can only when a
48
+ * paragraph it inserts, removes or joins names such an instance, so typing in
49
+ * a list whose instances the package defines leaves the numbering as it is.
50
+ * Replacements are inspected in the step-local document rather than by
51
+ * walking the completed document.
31
52
  */
32
- const changesNumberingInputs = (tr) => tr.steps.some((step, index) => {
53
+ const changesNumberingInputs = (tr, defined) => tr.steps.some((step, index) => {
33
54
  if (leavesNumberingUnchanged(step)) return false;
34
55
  if (!isReplace(step)) return true;
35
- let insertsNumberedParagraph = false;
56
+ let insertsUndefinedReference = false;
36
57
  step.slice.content.descendants((node) => {
37
- if (paragraphListReferences(node).length === 0) return !insertsNumberedParagraph;
38
- insertsNumberedParagraph = true;
58
+ if (!namesUndefinedInstance(node, defined)) return !insertsUndefinedReference;
59
+ insertsUndefinedReference = true;
39
60
  return false;
40
61
  });
41
- if (insertsNumberedParagraph) return true;
62
+ if (insertsUndefinedReference) return true;
42
63
  const before = tr.docs[index];
43
64
  if (before === void 0) return true;
44
65
  const fromParent = before.resolve(step.from).parent;
45
66
  const toParent = before.resolve(step.to).parent;
46
- if (fromParent !== toParent && (paragraphListReferences(fromParent).length > 0 || paragraphListReferences(toParent).length > 0)) return true;
47
- return containsNumberedParagraph(before, step.from, step.to);
67
+ if (fromParent !== toParent && (namesUndefinedInstance(fromParent, defined) || namesUndefinedInstance(toParent, defined))) return true;
68
+ return containsUndefinedReference(before, step.from, step.to, defined);
48
69
  });
49
70
  const createDocumentNumberingPlugin = (definitions) => new Plugin({
50
71
  key: documentNumberingKey.createKey(),
51
72
  state: {
52
73
  init: (_config, state) => completedState(definitions ?? null, state.doc),
53
- apply: (tr, current, _oldState, state) => tr.docChanged && changesNumberingInputs(tr) ? completedState(current.definitions, state.doc) : current
74
+ apply: (tr, current, _oldState, state) => tr.docChanged && changesNumberingInputs(tr, instancesDefinedBy(current.definitions)) ? completedState(current.definitions, state.doc) : current
54
75
  }
55
76
  });
56
77
  /** Numbering for states without the plugin, one per document node. */
@@ -73,6 +94,7 @@ const getDocumentNumberingForDoc = (doc) => {
73
94
  const getDocumentNumbering = (state) => {
74
95
  const tracked = documentNumberingKey.getState(state);
75
96
  if (tracked) return tracked.map;
97
+ if (documentNumberingKey.get(state) !== void 0) panic("Document numbering was read before its plugin applied: place the numbering plugin before the plugins that read it.");
76
98
  return getDocumentNumberingForDoc(state.doc);
77
99
  };
78
100
  /** The package's own definitions, without the instances the document defines. */
@@ -106,6 +128,6 @@ const getDocumentNumberingInstanceIds = (state) => {
106
128
  const withDocumentNumbering = (state, definitions) => {
107
129
  const previous = documentNumberingKey.get(state);
108
130
  const retained = state.plugins.filter((plugin) => plugin !== previous);
109
- return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [...retained, createDocumentNumberingPlugin(definitions)] });
131
+ return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [createDocumentNumberingPlugin(definitions), ...retained] });
110
132
  };
111
133
  export { createDocumentNumberingPlugin, getDocumentNumbering, getDocumentNumberingForDoc, getDocumentNumberingInstanceIds, getPackageNumberingDefinitions, getStatedDocumentNumbering, hasDocumentNumbering, withDocumentNumbering };