@stll/folio-core 0.45.0 → 0.47.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 (451) hide show
  1. package/dist/ai-edits/apply.js +85 -43
  2. package/dist/ai-edits/headless.js +2 -2
  3. package/dist/ai-edits/read.d.ts +1 -0
  4. package/dist/ai-edits/read.js +1 -0
  5. package/dist/ai-edits/snapshot.js +32 -27
  6. package/dist/ai-edits/table-cell-mutations.js +15 -7
  7. package/dist/ai-edits/table-geometry.js +21 -18
  8. package/dist/ai-edits/table-template.js +2 -2
  9. package/dist/compare/compare.js +2 -5
  10. package/dist/compare/content-alignment.js +108 -12
  11. package/dist/compare/content-types.d.ts +8 -2
  12. package/dist/compare/content.js +2 -11
  13. package/dist/compare/plan.js +7 -4
  14. package/dist/compare/scenario.js +2 -5
  15. package/dist/compare/section-boundary-properties.js +1 -2
  16. package/dist/compare/types.d.ts +9 -1
  17. package/dist/compare/types.js +12 -1
  18. package/dist/compat/eigenpal.d.ts +2 -1
  19. package/dist/compat/eigenpal.js +2 -1
  20. package/dist/content-controls/checkboxDisplay.d.ts +17 -0
  21. package/dist/content-controls/checkboxDisplay.js +46 -0
  22. package/dist/content-controls/findContentControls.js +3 -1
  23. package/dist/content-controls/mutateContentControls.js +57 -43
  24. package/dist/controller/contentControlWidgetController.d.ts +1 -0
  25. package/dist/controller/contentControlWidgetController.js +3 -0
  26. package/dist/controller/hiddenEditorApi.js +3 -1
  27. package/dist/controller/hiddenEditorManager.d.ts +1 -1
  28. package/dist/controller/hiddenEditorManager.js +6 -3
  29. package/dist/controller/layoutPipeline.js +8 -3
  30. package/dist/display-list/build/buildDisplayList.js +20 -1
  31. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  32. package/dist/display-list/build/imagePrimitives.js +38 -18
  33. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  34. package/dist/display-list/build/paragraphPrimitives.js +113 -14
  35. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  36. package/dist/display-list/build/previewPrimitives.js +89 -0
  37. package/dist/display-list/build/strokes.d.ts +177 -8
  38. package/dist/display-list/build/strokes.js +167 -47
  39. package/dist/display-list/build/tablePrimitives.js +4 -2
  40. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  41. package/dist/display-list/build/textDecorations.d.ts +15 -1
  42. package/dist/display-list/build/textDecorations.js +15 -1
  43. package/dist/display-list/dom/renderDisplayListToDom.js +11 -21
  44. package/dist/display-list/primitives.d.ts +13 -2
  45. package/dist/display-list/primitives.js +36 -1
  46. package/dist/display-list/types.d.ts +17 -0
  47. package/dist/document-operations.js +2 -1
  48. package/dist/docx/attributeRemainder.d.ts +76 -0
  49. package/dist/docx/attributeRemainder.js +111 -0
  50. package/dist/docx/blockContentParser.d.ts +3 -1
  51. package/dist/docx/blockContentParser.js +102 -106
  52. package/dist/docx/blockPlainText.d.ts +3 -4
  53. package/dist/docx/blockPlainText.js +3 -0
  54. package/dist/docx/borderParser.js +26 -11
  55. package/dist/docx/builtInStyles.d.ts +8 -16
  56. package/dist/docx/builtInStyles.js +54 -17
  57. package/dist/docx/commentAnchorIndex.d.ts +30 -0
  58. package/dist/docx/commentAnchorIndex.js +50 -0
  59. package/dist/docx/commentParser.d.ts +1 -1
  60. package/dist/docx/commentParser.js +56 -39
  61. package/dist/docx/commentRangeIntegrity.d.ts +16 -1
  62. package/dist/docx/commentRangeIntegrity.js +42 -1
  63. package/dist/docx/commentRangeJoin.d.ts +9 -0
  64. package/dist/docx/commentRangeJoin.js +33 -0
  65. package/dist/docx/commentReferenceCompletion.d.ts +9 -0
  66. package/dist/docx/commentReferenceCompletion.js +47 -0
  67. package/dist/docx/commentReferenceNormalization.js +3 -1
  68. package/dist/docx/commentReplyMarkers.js +11 -19
  69. package/dist/docx/compatibility.js +56 -41
  70. package/dist/docx/containerChildren.d.ts +208 -0
  71. package/dist/docx/containerChildren.gen.d.ts +43 -0
  72. package/dist/docx/containerChildren.gen.js +263 -0
  73. package/dist/docx/containerChildren.js +153 -0
  74. package/dist/docx/diagramPreview.d.ts +14 -2
  75. package/dist/docx/diagramPreview.js +81 -169
  76. package/dist/docx/documentParser.d.ts +1 -1
  77. package/dist/docx/documentParser.js +7 -4
  78. package/dist/docx/drawingAnchor.d.ts +87 -0
  79. package/dist/docx/drawingAnchor.js +201 -0
  80. package/dist/docx/drawingUtils.d.ts +43 -38
  81. package/dist/docx/drawingUtils.js +205 -118
  82. package/dist/docx/ensureParaIds.js +17 -7
  83. package/dist/docx/fieldParser.d.ts +1 -1
  84. package/dist/docx/fieldParser.js +4 -4
  85. package/dist/docx/fieldState.d.ts +26 -0
  86. package/dist/docx/fieldState.js +53 -0
  87. package/dist/docx/fontTableParser.js +102 -41
  88. package/dist/docx/footnoteParser.d.ts +1 -1
  89. package/dist/docx/footnoteParser.js +10 -6
  90. package/dist/docx/graphicFrameLocks.d.ts +16 -4
  91. package/dist/docx/graphicFrameLocks.js +19 -6
  92. package/dist/docx/groupDrawingParser.js +4 -3
  93. package/dist/docx/headerFooterParser.js +1 -1
  94. package/dist/docx/headerFooterReferenceNormalization.js +1 -0
  95. package/dist/docx/hyperlinkParser.d.ts +66 -9
  96. package/dist/docx/hyperlinkParser.js +153 -26
  97. package/dist/docx/imageParser.js +160 -115
  98. package/dist/docx/index.d.ts +2 -1
  99. package/dist/docx/index.js +2 -1
  100. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  101. package/dist/docx/inlineContentRemovals.js +46 -0
  102. package/dist/docx/inlineWrapperContent.d.ts +166 -0
  103. package/dist/docx/inlineWrapperContent.js +165 -0
  104. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  105. package/dist/docx/inlineWrapperParser.js +60 -0
  106. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  107. package/dist/docx/normalizeBaseDirection.js +12 -1
  108. package/dist/docx/numberingParser.d.ts +25 -2
  109. package/dist/docx/numberingParser.js +264 -361
  110. package/dist/docx/numberingReference.d.ts +9 -16
  111. package/dist/docx/numberingReference.js +17 -16
  112. package/dist/docx/numberingReferenceNormalization.js +7 -7
  113. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  114. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  115. package/dist/docx/paraIdAttribute.d.ts +111 -0
  116. package/dist/docx/paraIdAttribute.js +142 -0
  117. package/dist/docx/paragraphParser.d.ts +10 -25
  118. package/dist/docx/paragraphParser.js +421 -496
  119. package/dist/docx/paragraphProperties.d.ts +23 -0
  120. package/dist/docx/paragraphProperties.js +279 -0
  121. package/dist/docx/paragraphPropertySource.js +7 -1
  122. package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
  123. package/dist/docx/paragraphTextBoxEnrichment.js +20 -59
  124. package/dist/docx/paragraphTraversal.d.ts +14 -10
  125. package/dist/docx/paragraphTraversal.js +53 -52
  126. package/dist/docx/parseWarningMessage.js +5 -1
  127. package/dist/docx/parserEnums.d.ts +6 -8
  128. package/dist/docx/parserEnums.js +4 -6
  129. package/dist/docx/preservedRunContent.d.ts +32 -0
  130. package/dist/docx/preservedRunContent.js +96 -0
  131. package/dist/docx/previewBudget.d.ts +44 -23
  132. package/dist/docx/previewBudget.js +61 -30
  133. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  134. package/dist/docx/propertyElementAttributes.js +114 -0
  135. package/dist/docx/renderedPageBreakNormalization.js +4 -6
  136. package/dist/docx/rezip.d.ts +28 -2
  137. package/dist/docx/rezip.js +152 -27
  138. package/dist/docx/runConsolidator.d.ts +42 -2
  139. package/dist/docx/runConsolidator.js +60 -6
  140. package/dist/docx/runParser.d.ts +55 -19
  141. package/dist/docx/runParser.js +394 -306
  142. package/dist/docx/runPayload.d.ts +5 -0
  143. package/dist/docx/runPayload.js +4 -0
  144. package/dist/docx/sdtProperties.d.ts +39 -5
  145. package/dist/docx/sdtProperties.js +205 -84
  146. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  147. package/dist/docx/sdtPropertiesPatch.js +68 -112
  148. package/dist/docx/sectionParser.d.ts +1 -2
  149. package/dist/docx/sectionParser.js +241 -238
  150. package/dist/docx/selectiveSave.js +3 -2
  151. package/dist/docx/selectiveXmlPatch.d.ts +66 -3
  152. package/dist/docx/selectiveXmlPatch.js +276 -133
  153. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  154. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  155. package/dist/docx/serializer/borderSerializer.js +12 -10
  156. package/dist/docx/serializer/commentSerializer.js +5 -7
  157. package/dist/docx/serializer/documentSerializer.js +11 -11
  158. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  159. package/dist/docx/serializer/headerFooterSerializer.js +10 -9
  160. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  161. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  162. package/dist/docx/serializer/noteSerializer.js +11 -8
  163. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  164. package/dist/docx/serializer/numberingSerializer.js +81 -79
  165. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  166. package/dist/docx/serializer/paragraphSerializer.js +156 -236
  167. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  168. package/dist/docx/serializer/runSerializer.js +134 -75
  169. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  170. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  171. package/dist/docx/serializer/sectionPropertiesSerializer.js +42 -49
  172. package/dist/docx/serializer/settingsSerializer.js +6 -4
  173. package/dist/docx/serializer/stylesSerializer.js +8 -11
  174. package/dist/docx/serializer/tableSerializer.js +283 -105
  175. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  176. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  177. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  178. package/dist/docx/serializer/xmlUtils.js +1 -1
  179. package/dist/docx/server/createBilingualDocument.js +20 -16
  180. package/dist/docx/server/materializeYjsDocx.d.ts +1 -1
  181. package/dist/docx/server/materializeYjsDocx.js +9 -1
  182. package/dist/docx/server/migrateYjsAttrSchema.d.ts +55 -0
  183. package/dist/docx/server/migrateYjsAttrSchema.js +95 -0
  184. package/dist/docx/settingsParser.js +7 -4
  185. package/dist/docx/shadingParser.d.ts +2 -1
  186. package/dist/docx/shadingParser.js +43 -7
  187. package/dist/docx/shapeParser.js +13 -8
  188. package/dist/docx/strictNames.d.ts +11 -0
  189. package/dist/docx/strictNames.gen.d.ts +45 -0
  190. package/dist/docx/strictNames.gen.js +50 -0
  191. package/dist/docx/strictNames.js +43 -0
  192. package/dist/docx/strictValueEncodings.gen.js +133 -131
  193. package/dist/docx/styleParser.js +17 -349
  194. package/dist/docx/tableParser.d.ts +11 -2
  195. package/dist/docx/tableParser.js +665 -220
  196. package/dist/docx/textBoxParser.d.ts +28 -3
  197. package/dist/docx/textBoxParser.js +69 -9
  198. package/dist/docx/themeColorAttribute.d.ts +13 -0
  199. package/dist/docx/themeColorAttribute.js +24 -0
  200. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  201. package/dist/docx/unzip.js +5 -4
  202. package/dist/docx/vmlImageParser.d.ts +30 -5
  203. package/dist/docx/vmlImageParser.js +91 -32
  204. package/dist/docx/vmlPreview.js +2 -2
  205. package/dist/docx/wrapPolygon.d.ts +30 -0
  206. package/dist/docx/wrapPolygon.js +70 -0
  207. package/dist/docx/xmlEncoding.d.ts +5 -0
  208. package/dist/docx/xmlEncoding.js +12 -0
  209. package/dist/docx/xmlParser.d.ts +23 -1
  210. package/dist/docx/xmlParser.js +31 -2
  211. package/dist/fonts/embeddedFonts.js +3 -3
  212. package/dist/headless-layout.js +12 -1
  213. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  214. package/dist/i18n/messages/catalogs.gen.js +102 -34
  215. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  216. package/dist/index.d.ts +2 -1
  217. package/dist/index.js +2 -1
  218. package/dist/internal/headlessRevisionResolution.js +9 -0
  219. package/dist/internal/pageBreakRunSourceDescendantIndex.js +7 -2
  220. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  221. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  222. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  223. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  224. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  225. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  226. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  227. package/dist/layout-bridge/convert/toFlowBlocks.js +267 -101
  228. package/dist/layout-engine/index.d.ts +2 -2
  229. package/dist/layout-engine/index.js +53 -17
  230. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  231. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  232. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  233. package/dist/layout-engine/measure/tableCellFloating.js +2 -0
  234. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  235. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  236. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  237. package/dist/layout-engine/paragraphSequence.js +3 -2
  238. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  239. package/dist/layout-engine/section-breaks.d.ts +49 -2
  240. package/dist/layout-engine/section-breaks.js +55 -4
  241. package/dist/layout-engine/types.d.ts +69 -17
  242. package/dist/layout-engine/types.js +16 -1
  243. package/dist/layout-painter/borderStroke.d.ts +18 -4
  244. package/dist/layout-painter/renderImage.d.ts +5 -1
  245. package/dist/layout-painter/renderImage.js +10 -3
  246. package/dist/layout-painter/renderPage.d.ts +2 -0
  247. package/dist/layout-painter/renderPage.js +10 -4
  248. package/dist/layout-painter/renderParagraph.d.ts +14 -1
  249. package/dist/layout-painter/renderParagraph.js +34 -28
  250. package/dist/layout-painter/renderTable.d.ts +4 -1
  251. package/dist/layout-painter/renderTable.js +22 -22
  252. package/dist/layout-painter/renderTextBox.js +5 -3
  253. package/dist/managers/autoSaveCodec.d.ts +9 -1
  254. package/dist/managers/autoSaveCodec.js +12 -4
  255. package/dist/markdown/renderBlock.js +3 -0
  256. package/dist/markdown/renderRuns.d.ts +1 -1
  257. package/dist/markdown/renderRuns.js +34 -6
  258. package/dist/markdown/renderTable.js +24 -6
  259. package/dist/markdown/trailers.js +4 -1
  260. package/dist/model.d.ts +3 -3
  261. package/dist/model.js +2 -2
  262. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  263. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  264. package/dist/pdf/images.js +142 -6
  265. package/dist/prosemirror/attrs/index.d.ts +34 -5
  266. package/dist/prosemirror/attrs/index.js +639 -48
  267. package/dist/prosemirror/authoredTransformAttrs.d.ts +28 -0
  268. package/dist/prosemirror/authoredTransformAttrs.js +64 -0
  269. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  270. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  271. package/dist/prosemirror/commands/comments.js +68 -53
  272. package/dist/prosemirror/commands/contentControls.js +33 -20
  273. package/dist/prosemirror/commands/image.d.ts +10 -3
  274. package/dist/prosemirror/commands/image.js +46 -29
  275. package/dist/prosemirror/commands/pageBreak.js +1 -1
  276. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  277. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  278. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  279. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  280. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  281. package/dist/prosemirror/commentReferenceAttrs.d.ts +8 -0
  282. package/dist/prosemirror/commentReferenceAttrs.js +33 -0
  283. package/dist/prosemirror/commentReferenceIntegrity.d.ts +47 -0
  284. package/dist/prosemirror/commentReferenceIntegrity.js +43 -0
  285. package/dist/prosemirror/conversion/fromProseDoc.d.ts +17 -12
  286. package/dist/prosemirror/conversion/fromProseDoc.js +553 -207
  287. package/dist/prosemirror/conversion/index.d.ts +2 -2
  288. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  289. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  290. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  291. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  292. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  293. package/dist/prosemirror/conversion/toProseDoc.d.ts +7 -9
  294. package/dist/prosemirror/conversion/toProseDoc.js +801 -411
  295. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  296. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  297. package/dist/prosemirror/extensions/StarterKit.js +14 -58
  298. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  299. package/dist/prosemirror/extensions/core/ParagraphExtension.js +21 -16
  300. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +48 -29
  301. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -1
  302. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +5 -3
  303. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  304. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +1 -0
  305. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  306. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  307. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  308. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  309. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  310. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  311. package/dist/prosemirror/extensions/markRegistry.d.ts +65 -0
  312. package/dist/prosemirror/extensions/markRegistry.js +138 -0
  313. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +18 -0
  314. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +77 -0
  315. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  316. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  317. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  318. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  319. package/dist/prosemirror/extensions/marks/markUtils.d.ts +2 -1
  320. package/dist/prosemirror/extensions/marks/markUtils.js +49 -5
  321. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  322. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  323. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  324. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  325. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  326. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +11 -0
  327. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +97 -0
  328. package/dist/prosemirror/extensions/nodes/FieldExtension.js +9 -7
  329. package/dist/prosemirror/extensions/nodes/ImageExtension.js +24 -1
  330. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  331. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  332. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +32 -0
  333. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +67 -0
  334. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +16 -0
  335. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +60 -0
  336. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  337. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  338. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  339. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  340. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +7 -0
  341. package/dist/prosemirror/extensions/nodes/TableExtension.js +142 -123
  342. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +9 -1
  343. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  344. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  345. package/dist/prosemirror/extensions/types.d.ts +12 -3
  346. package/dist/prosemirror/index.d.ts +4 -2
  347. package/dist/prosemirror/index.js +2 -1
  348. package/dist/prosemirror/inlineWrapperStack.d.ts +39 -0
  349. package/dist/prosemirror/inlineWrapperStack.js +92 -0
  350. package/dist/prosemirror/listMarker.d.ts +2 -2
  351. package/dist/prosemirror/listMarker.js +7 -8
  352. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  353. package/dist/prosemirror/listState.d.ts +62 -0
  354. package/dist/prosemirror/listState.js +49 -0
  355. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  356. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  357. package/dist/prosemirror/numberedRefFields.js +4 -4
  358. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  359. package/dist/prosemirror/numberingAttr.js +74 -0
  360. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  361. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  362. package/dist/prosemirror/pageBreakRunProjection.d.ts +17 -7
  363. package/dist/prosemirror/pageBreakRunProjection.js +19 -9
  364. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  365. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  366. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  367. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  368. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  369. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  370. package/dist/prosemirror/replacedAnnotations.d.ts +59 -0
  371. package/dist/prosemirror/replacedAnnotations.js +183 -0
  372. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  373. package/dist/prosemirror/revisionCarriers.js +86 -60
  374. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +5 -1
  375. package/dist/prosemirror/runFormattingInlineCarriers.js +7 -1
  376. package/dist/prosemirror/runIdentity.d.ts +28 -0
  377. package/dist/prosemirror/runIdentity.js +36 -0
  378. package/dist/prosemirror/runStyleFormatting.js +1 -1
  379. package/dist/prosemirror/schema/index.d.ts +3 -3
  380. package/dist/prosemirror/schema/marks.d.ts +47 -4
  381. package/dist/prosemirror/schema/nodes.d.ts +309 -26
  382. package/dist/prosemirror/schema/nodes.js +16 -1
  383. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  384. package/dist/prosemirror/sectionCarrier.js +40 -0
  385. package/dist/prosemirror/selectionState.d.ts +3 -0
  386. package/dist/prosemirror/selectionState.js +4 -1
  387. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  388. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  389. package/dist/prosemirror/tableResize.js +5 -6
  390. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +4 -0
  391. package/dist/prosemirror/trackedRunInlineAtoms.js +4 -0
  392. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  393. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  394. package/dist/prosemirror/validation.js +31 -6
  395. package/dist/prosemirror/yjsDocumentMetadata.d.ts +73 -0
  396. package/dist/prosemirror/yjsDocumentMetadata.js +592 -0
  397. package/dist/prosemirror/zeroWidthAnchors.js +6 -0
  398. package/dist/render-dom/commentAnchorAttributes.d.ts +37 -0
  399. package/dist/render-dom/commentAnchorAttributes.js +54 -0
  400. package/dist/server.d.ts +3 -1
  401. package/dist/server.js +3 -1
  402. package/dist/style-sets/extract.js +4 -4
  403. package/dist/style-sets/stellaStyle.js +36 -23
  404. package/dist/types/colors.d.ts +2 -2
  405. package/dist/types/content.d.ts +2 -2
  406. package/dist/types/documentEnumValues.d.ts +53 -26
  407. package/dist/types/documentEnumValues.js +72 -174
  408. package/dist/types/formatting.d.ts +2 -2
  409. package/dist/types/index.d.ts +9 -2
  410. package/dist/utils/borderCss.d.ts +246 -0
  411. package/dist/utils/borderCss.js +325 -0
  412. package/dist/utils/clipboard.d.ts +9 -1
  413. package/dist/utils/clipboard.js +27 -1
  414. package/dist/utils/colorResolver.d.ts +4 -3
  415. package/dist/utils/colorResolver.js +45 -76
  416. package/dist/utils/createDocument.js +24 -6
  417. package/dist/utils/findReplace.js +52 -10
  418. package/dist/utils/formatToStyle.d.ts +84 -2
  419. package/dist/utils/formatToStyle.js +133 -52
  420. package/dist/utils/headingCollector.js +3 -2
  421. package/dist/utils/imageLuminance.d.ts +15 -0
  422. package/dist/utils/imageLuminance.js +32 -0
  423. package/dist/utils/mergeDocumentContent.js +12 -20
  424. package/dist/utils/paragraphFormattingMerge.js +27 -6
  425. package/dist/utils/replaceText.js +1 -0
  426. package/dist/utils/tableOperations.d.ts +5 -3
  427. package/dist/utils/tableOperations.js +14 -1
  428. package/dist/utils/tablePlacement.d.ts +7 -0
  429. package/dist/utils/tablePlacement.js +14 -0
  430. package/dist/utils/textDirectionFlow.d.ts +15 -0
  431. package/dist/utils/textDirectionFlow.js +38 -0
  432. package/dist/utils/textFormattingMerge.js +16 -4
  433. package/package.json +10 -10
  434. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  435. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  436. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  437. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  438. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  439. package/dist/compare/__fixtures__/nested-table.js +0 -50
  440. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  441. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  442. package/dist/docx/blockRangeMarkers.d.ts +0 -36
  443. package/dist/docx/blockRangeMarkers.js +0 -59
  444. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  445. package/dist/docx/bookmarkPlacement.js +0 -50
  446. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  447. package/dist/fonts/embeddedFontTable.js +0 -80
  448. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  449. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
  450. package/dist/prosemirror/yjsParagraphSourceContract.d.ts +0 -9
  451. package/dist/prosemirror/yjsParagraphSourceContract.js +0 -26
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { SectionBreakType } from "../sectionCarrier.js";
2
3
  import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId } from "../extensions/core/ParagraphExtension.js";
3
4
  import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
4
5
  import { Command } from "prosemirror-state";
@@ -26,7 +27,7 @@ declare function setSpaceBefore(twips: number): Command;
26
27
  declare function setSpaceAfter(twips: number): Command;
27
28
  declare function applyStyle(styleId: string, resolvedAttrs?: ResolvedStyleAttrs): Command;
28
29
  declare const clearStyle: Command;
29
- declare function insertSectionBreak(breakType: "nextPage" | "continuous" | "oddPage" | "evenPage"): Command;
30
+ declare function insertSectionBreak(breakType: SectionBreakType): Command;
30
31
  declare const removeSectionBreak: Command;
31
32
  declare function addTabStop(position: number, alignment?: document_d_exports.TabStopAlignment, leader?: document_d_exports.TabLeader): Command;
32
33
  declare function removeTabStop(position: number): Command;
@@ -32,9 +32,9 @@ declare const removeParagraphPropertyChanges: (changes: readonly ParagraphProper
32
32
  * stored record resets to the schema default (`null`).
33
33
  *
34
34
  * Deliberately OUT of scope (preserved across a reject):
35
- * - identity/structure: `paraId`, `textId`, `sectionBreakType`,
36
- * `_sectionProperties`, `_propertyChanges`, `pPrMark`, `bookmarks`,
37
- * `_emptyHyperlinks`, `renderedPageBreakBefore`
35
+ * - identity/structure: `paraId`, `textId`, `_sectionProperties`,
36
+ * `_propertyChanges`, `pPrMark`, `bookmarks`, `_emptyHyperlinks`,
37
+ * `renderedPageBreakBefore`
38
38
  * - paragraph-mark run properties — `pPr/rPr` is CT_PPr-only, not part of the
39
39
  * CT_PPrBase payload a pPrChange stores: `defaultTextFormatting`,
40
40
  * `runInWithNext` (`w:specVanish` lives in that rPr)
@@ -83,6 +83,14 @@ declare function sectionRejectProperties({ live, previousProperties, previousRef
83
83
  * and is untouched.
84
84
  */
85
85
  declare function tableRejectAttrPatch(previousFormatting: document_d_exports.TableFormatting | undefined): AttrPatch;
86
+ /**
87
+ * Attr patch for rejecting a `w:tblPrExChange`: the stored old `w:tblPrEx`
88
+ * wholesale. The exceptions ride the row node whole rather than as attrs (the
89
+ * editor surfaces none of the nine properties), so restoring the previous set
90
+ * is restoring that one attr — and a record with no stored set says the row
91
+ * overrode nothing, which is the element's absence, not an empty one.
92
+ */
93
+ declare function tablePropertyExceptionsRejectAttrPatch(previousFormatting: document_d_exports.TablePropertyExceptionFormatting | undefined): AttrPatch;
86
94
  /** Attr patch for rejecting a `w:trPrChange`: the stored old trPr wholesale. */
87
95
  declare function tableRowRejectAttrPatch(previousFormatting: document_d_exports.TableRowFormatting | undefined): AttrPatch;
88
96
  /**
@@ -96,4 +104,4 @@ declare function tableRowRejectAttrPatch(previousFormatting: document_d_exports.
96
104
  */
97
105
  declare function tableCellRejectAttrPatch(previousFormatting: document_d_exports.TableCellFormatting | undefined, liveOriginalFormatting: document_d_exports.TableCellFormatting | null | undefined): AttrPatch;
98
106
  //#endregion
99
- export { PPR_CHANGE_SCOPED_ATTR_KEYS, ParagraphPropertyChangeRemoval, hasSerializableParagraphPropertyChange, paragraphPropertiesSnapshot, paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges, sectionRejectProperties, tableCellRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch };
107
+ export { PPR_CHANGE_SCOPED_ATTR_KEYS, ParagraphPropertyChangeRemoval, hasSerializableParagraphPropertyChange, paragraphPropertiesSnapshot, paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges, sectionRejectProperties, tableCellRejectAttrPatch, tablePropertyExceptionsRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch };
@@ -1,4 +1,5 @@
1
1
  import { expectParagraphAttrs } from "../attrs/index.js";
2
+ import { readParagraphNumberingAttr } from "../numberingAttr.js";
2
3
  import { directParagraphAlignment } from "../paragraphAlignment.js";
3
4
  import { directionFromBidi } from "../paragraphDirection.js";
4
5
  import { directParagraphSpacing, paragraphSpacingAttrPatch, paragraphSpacingFromFormatting } from "../paragraphSpacing.js";
@@ -56,9 +57,9 @@ const removeParagraphPropertyChanges = (changes, shouldRemove) => {
56
57
  * stored record resets to the schema default (`null`).
57
58
  *
58
59
  * Deliberately OUT of scope (preserved across a reject):
59
- * - identity/structure: `paraId`, `textId`, `sectionBreakType`,
60
- * `_sectionProperties`, `_propertyChanges`, `pPrMark`, `bookmarks`,
61
- * `_emptyHyperlinks`, `renderedPageBreakBefore`
60
+ * - identity/structure: `paraId`, `textId`, `_sectionProperties`,
61
+ * `_propertyChanges`, `pPrMark`, `bookmarks`, `_emptyHyperlinks`,
62
+ * `renderedPageBreakBefore`
62
63
  * - paragraph-mark run properties — `pPr/rPr` is CT_PPr-only, not part of the
63
64
  * CT_PPrBase payload a pPrChange stores: `defaultTextFormatting`,
64
65
  * `runInWithNext` (`w:specVanish` lives in that rPr)
@@ -214,6 +215,9 @@ function paragraphRejectOriginalFormatting(previousFormatting, liveOriginal) {
214
215
  const value = Object.hasOwn(prev, key) ? prev[key] : void 0;
215
216
  if (value != null) Object.assign(result, { [key]: value });
216
217
  }
218
+ const numbering = readParagraphNumberingAttr(prev.numPr);
219
+ if (numbering === null) Reflect.deleteProperty(result, "numPr");
220
+ else result.numPr = numbering;
217
221
  const live = isRecord(liveOriginal) ? liveOriginal : {};
218
222
  if (live["runProperties"] != null) Object.assign(result, { runProperties: live["runProperties"] });
219
223
  if (live["runInWithNext"] != null) Object.assign(result, { runInWithNext: live["runInWithNext"] });
@@ -249,6 +253,16 @@ function tableRejectAttrPatch(previousFormatting) {
249
253
  _originalFormatting: previousFormatting ?? null
250
254
  };
251
255
  }
256
+ /**
257
+ * Attr patch for rejecting a `w:tblPrExChange`: the stored old `w:tblPrEx`
258
+ * wholesale. The exceptions ride the row node whole rather than as attrs (the
259
+ * editor surfaces none of the nine properties), so restoring the previous set
260
+ * is restoring that one attr — and a record with no stored set says the row
261
+ * overrode nothing, which is the element's absence, not an empty one.
262
+ */
263
+ function tablePropertyExceptionsRejectAttrPatch(previousFormatting) {
264
+ return { _tablePropertyExceptions: previousFormatting ?? null };
265
+ }
252
266
  /** Attr patch for rejecting a `w:trPrChange`: the stored old trPr wholesale. */
253
267
  function tableRowRejectAttrPatch(previousFormatting) {
254
268
  return {
@@ -277,6 +291,10 @@ function tableCellRejectAttrPatch(previousFormatting, liveOriginalFormatting) {
277
291
  return {
278
292
  width: previousFormatting?.width?.value ?? null,
279
293
  widthType: previousFormatting?.width?.type ?? null,
294
+ _authoredWidth: previousFormatting?.width ? {
295
+ value: previousFormatting.width.value,
296
+ type: previousFormatting.width.type
297
+ } : null,
280
298
  verticalAlign: previousFormatting?.verticalAlign ?? null,
281
299
  backgroundColor: previousFormatting?.shading?.fill?.rgb ?? null,
282
300
  textDirection: previousFormatting?.textDirection ?? null,
@@ -306,4 +324,4 @@ function isRecord(value) {
306
324
  return typeof value === "object" && value !== null && !Array.isArray(value);
307
325
  }
308
326
  //#endregion
309
- export { PPR_CHANGE_SCOPED_ATTR_KEYS, hasSerializableParagraphPropertyChange, paragraphPropertiesSnapshot, paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges, sectionRejectProperties, tableCellRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch };
327
+ export { PPR_CHANGE_SCOPED_ATTR_KEYS, hasSerializableParagraphPropertyChange, paragraphPropertiesSnapshot, paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges, sectionRejectProperties, tableCellRejectAttrPatch, tablePropertyExceptionsRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch };
@@ -1,5 +1,37 @@
1
+ import { SectionBreakType } from "../sectionCarrier.js";
1
2
  import { Command } from "prosemirror-state";
2
3
  //#region src/prosemirror/commands/sectionBreak.d.ts
4
+ /**
5
+ * Run a command, keeping every section break on the paragraph whose mark
6
+ * survived it.
7
+ *
8
+ * A section break is a property of a paragraph *mark*. The transfer is keyed on
9
+ * the mark's position surviving the transaction, not on which command ran, so
10
+ * deleting a section-ending paragraph outright still removes its section: that
11
+ * mark is gone, and nothing inherits it.
12
+ */
13
+ declare const keepSectionBreaksOnSurvivingMarks: (command: Command) => Command;
14
+ /**
15
+ * End the selection's sections with `breakType`.
16
+ *
17
+ * A paragraph that already ends a section keeps its page size, margins,
18
+ * columns and header references and changes only `w:type` (§17.6.22), which is
19
+ * the one field the type names; a paragraph that ends none mints a record
20
+ * stating that type alone, and inherits the rest from the section that follows
21
+ * it.
22
+ */
23
+ declare const setSectionBreakType: (breakType: SectionBreakType) => Command;
24
+ /**
25
+ * Remove the section break the selection's paragraphs carry.
26
+ *
27
+ * The record goes, and with it the section boundary: the paragraphs it
28
+ * governed become part of the section that follows, whose `w:sectPr` governs
29
+ * them from then on. That is Word's own rule for deleting a section break, and
30
+ * it is what §17.6.18 says a paragraph with no `w:sectPr` means — nothing has
31
+ * to be merged into the following record, because the following record already
32
+ * states the whole of the section it heads.
33
+ */
34
+ declare const removeSectionBreakAtSelection: Command;
3
35
  /**
4
36
  * Insert a "next page" section break at the cursor — starts a new section on a
5
37
  * new page.
@@ -11,4 +43,4 @@ declare const insertSectionBreakNextPage: Command;
11
43
  */
12
44
  declare const insertSectionBreakContinuous: Command;
13
45
  //#endregion
14
- export { insertSectionBreakContinuous, insertSectionBreakNextPage };
46
+ export { insertSectionBreakContinuous, insertSectionBreakNextPage, keepSectionBreaksOnSurvivingMarks, removeSectionBreakAtSelection, setSectionBreakType };
@@ -1,14 +1,192 @@
1
+ import { mintSectionProperties, sectionPropertiesOf } from "../sectionCarrier.js";
1
2
  import { TextSelection } from "prosemirror-state";
2
3
  //#region src/prosemirror/commands/sectionBreak.ts
4
+ const sectionEndingMarks = (doc) => {
5
+ const marks = [];
6
+ doc.descendants((node, position) => {
7
+ if (node.type.name !== "paragraph") return true;
8
+ const properties = sectionPropertiesOf(node);
9
+ if (properties) marks.push({
10
+ markPosition: position + node.nodeSize - 1,
11
+ properties
12
+ });
13
+ return false;
14
+ });
15
+ return marks;
16
+ };
17
+ const withSectionProperties = (attrs, properties) => {
18
+ const next = { ...attrs };
19
+ if (properties === null) {
20
+ delete next["_sectionProperties"];
21
+ return next;
22
+ }
23
+ next["_sectionProperties"] = properties;
24
+ return next;
25
+ };
26
+ /**
27
+ * Restate, over the whole document, which paragraph marks end a section.
28
+ *
29
+ * The rule is total in both directions, because a join is: it consumes one
30
+ * paragraph mark and keeps the other, so exactly the marks that survived the
31
+ * transaction still end the sections they ended before. ProseMirror keeps the
32
+ * *first* node's attrs when it joins, which gets both halves of the rule wrong
33
+ * on its own — the mark that survived a backward join loses a break it still
34
+ * owns, and the node that absorbed a section-ending predecessor keeps a break
35
+ * whose mark is gone.
36
+ *
37
+ * Word deletes the section break in the second case: with the caret at the
38
+ * start of the paragraph *after* a break, Backspace removes the break, and the
39
+ * paragraphs it governed join the following section, whose `w:sectPr` then
40
+ * governs them (ECMA-376 Part 1 §17.6.18: a paragraph's `w:sectPr` states the
41
+ * properties of the section ending at that paragraph, so content with no
42
+ * `w:sectPr` before it belongs to the next one).
43
+ */
44
+ const reconcileSectionEndingMarks = (transaction, marks) => {
45
+ const survivors = /* @__PURE__ */ new Map();
46
+ for (const { markPosition, properties } of marks) {
47
+ const mapped = transaction.mapping.mapResult(markPosition, 1);
48
+ if (!mapped.deleted) survivors.set(mapped.pos, properties);
49
+ }
50
+ const corrections = [];
51
+ transaction.doc.descendants((node, position) => {
52
+ if (node.type.name !== "paragraph") return true;
53
+ const survived = survivors.get(position + node.nodeSize - 1) ?? null;
54
+ if (survived !== sectionPropertiesOf(node)) corrections.push({
55
+ position,
56
+ properties: survived
57
+ });
58
+ return false;
59
+ });
60
+ for (const { position, properties } of corrections) {
61
+ const paragraph = transaction.doc.nodeAt(position);
62
+ if (paragraph) transaction.setNodeMarkup(position, void 0, withSectionProperties(paragraph.attrs, properties));
63
+ }
64
+ };
65
+ /**
66
+ * Run a command, keeping every section break on the paragraph whose mark
67
+ * survived it.
68
+ *
69
+ * A section break is a property of a paragraph *mark*. The transfer is keyed on
70
+ * the mark's position surviving the transaction, not on which command ran, so
71
+ * deleting a section-ending paragraph outright still removes its section: that
72
+ * mark is gone, and nothing inherits it.
73
+ */
74
+ const keepSectionBreaksOnSurvivingMarks = (command) => (state, dispatch, view) => {
75
+ if (!dispatch) return command(state, void 0, view);
76
+ const marks = sectionEndingMarks(state.doc);
77
+ if (marks.length === 0) return command(state, dispatch, view);
78
+ let captured = null;
79
+ const capture = (transaction) => {
80
+ captured = transaction;
81
+ };
82
+ if (!command(state, capture, view)) return false;
83
+ const transaction = captured;
84
+ if (transaction === null) return true;
85
+ reconcileSectionEndingMarks(transaction, marks);
86
+ dispatch(transaction);
87
+ return true;
88
+ };
89
+ const selectedParagraphs = (state) => {
90
+ const paragraphs = [];
91
+ const { $from, $to } = state.selection;
92
+ state.doc.nodesBetween($from.pos, $to.pos, (node, position) => {
93
+ if (node.type.name !== "paragraph") return true;
94
+ paragraphs.push({
95
+ position,
96
+ node
97
+ });
98
+ return false;
99
+ });
100
+ return paragraphs;
101
+ };
102
+ /**
103
+ * Rewrite the section record of every paragraph the selection touches.
104
+ *
105
+ * A record is rewritten once and the replacement applied to every paragraph
106
+ * holding it, wherever in the document it sits. A split leaves two halves over
107
+ * one object until the save leg decides which of them ends the section;
108
+ * rewriting them apart would turn that one section into two, and leaving a
109
+ * sharer outside the selection behind would do the same.
110
+ *
111
+ * A paragraph that holds no record is asked on its own, so two break-less
112
+ * paragraphs in one selection author two sections rather than share one.
113
+ */
114
+ const rewriteSelectedSectionRecords = (rewrite) => (state, dispatch) => {
115
+ const selected = selectedParagraphs(state);
116
+ if (selected.length === 0) return false;
117
+ const replacements = /* @__PURE__ */ new Map();
118
+ for (const { node } of selected) {
119
+ const current = sectionPropertiesOf(node);
120
+ if (current !== null && !replacements.has(current)) replacements.set(current, rewrite(current));
121
+ }
122
+ const selectedPositions = new Set(selected.map(({ position }) => position));
123
+ const corrections = [];
124
+ state.doc.descendants((node, position) => {
125
+ if (node.type.name !== "paragraph") return true;
126
+ const current = sectionPropertiesOf(node);
127
+ if (current === null) {
128
+ if (selectedPositions.has(position)) {
129
+ const minted = rewrite(null);
130
+ if (minted !== null) corrections.push({
131
+ position,
132
+ properties: minted
133
+ });
134
+ }
135
+ return false;
136
+ }
137
+ if (replacements.has(current)) {
138
+ const replacement = replacements.get(current) ?? null;
139
+ if (replacement !== current) corrections.push({
140
+ position,
141
+ properties: replacement
142
+ });
143
+ }
144
+ return false;
145
+ });
146
+ if (corrections.length === 0) return false;
147
+ if (dispatch) {
148
+ const transaction = state.tr;
149
+ for (const { position, properties } of corrections) {
150
+ const paragraph = transaction.doc.nodeAt(position);
151
+ if (paragraph) transaction.setNodeMarkup(position, void 0, withSectionProperties(paragraph.attrs, properties));
152
+ }
153
+ dispatch(transaction.scrollIntoView());
154
+ }
155
+ return true;
156
+ };
157
+ /**
158
+ * End the selection's sections with `breakType`.
159
+ *
160
+ * A paragraph that already ends a section keeps its page size, margins,
161
+ * columns and header references and changes only `w:type` (§17.6.22), which is
162
+ * the one field the type names; a paragraph that ends none mints a record
163
+ * stating that type alone, and inherits the rest from the section that follows
164
+ * it.
165
+ */
166
+ const setSectionBreakType = (breakType) => rewriteSelectedSectionRecords((current) => current === null ? mintSectionProperties(breakType) : {
167
+ ...current,
168
+ sectionStart: breakType
169
+ });
170
+ /**
171
+ * Remove the section break the selection's paragraphs carry.
172
+ *
173
+ * The record goes, and with it the section boundary: the paragraphs it
174
+ * governed become part of the section that follows, whose `w:sectPr` governs
175
+ * them from then on. That is Word's own rule for deleting a section break, and
176
+ * it is what §17.6.18 says a paragraph with no `w:sectPr` means — nothing has
177
+ * to be merged into the following record, because the following record already
178
+ * states the whole of the section it heads.
179
+ */
180
+ const removeSectionBreakAtSelection = rewriteSelectedSectionRecords(() => null);
3
181
  /**
4
182
  * Insert a section break at the current cursor position.
5
183
  *
6
184
  * In OOXML a section break is the `sectPr` carried by the *last* paragraph of a
7
- * section. So we split the current paragraph at the cursor, mark the first half
8
- * with `sectionBreakType` (it becomes the section end), and leave the cursor in
9
- * the second half (the first paragraph of the new section). Content after the
10
- * cursor therefore flows into the new section — onto a new page for `nextPage`,
11
- * or in place for `continuous`.
185
+ * section (§17.6.18). So we split the current paragraph at the cursor, give the
186
+ * first half the one record this insertion mints (it becomes the section end),
187
+ * and leave the cursor in the second half (the first paragraph of the new
188
+ * section). Content after the cursor therefore flows into the new section —
189
+ * onto a new page for `nextPage`, or in place for `continuous`.
12
190
  */
13
191
  function insertSectionBreakAtCursor(breakType) {
14
192
  return (state, dispatch) => {
@@ -19,19 +197,17 @@ function insertSectionBreakAtCursor(breakType) {
19
197
  if (!($from.parent.isTextblock ? state.doc.resolve($from.before()).depth === 0 : $from.depth === 0)) return false;
20
198
  if (dispatch) {
21
199
  const tr = state.tr;
200
+ const sectionProperties = mintSectionProperties(breakType);
22
201
  let cursorPos;
23
202
  if ($from.parent.isTextblock) {
24
203
  const paraPos = $from.before();
25
204
  tr.split($from.pos);
26
205
  const firstPara = tr.doc.nodeAt(paraPos);
27
- if (firstPara) tr.setNodeMarkup(paraPos, void 0, {
28
- ...firstPara.attrs,
29
- sectionBreakType: breakType
30
- });
206
+ if (firstPara) tr.setNodeMarkup(paraPos, void 0, withSectionProperties(firstPara.attrs, sectionProperties));
31
207
  cursorPos = tr.mapping.map($from.pos);
32
208
  } else {
33
209
  const pos = $from.pos;
34
- tr.insert(pos, paragraphType.create({ sectionBreakType: breakType }));
210
+ tr.insert(pos, paragraphType.create({ _sectionProperties: sectionProperties }));
35
211
  cursorPos = pos + 1;
36
212
  }
37
213
  tr.setSelection(TextSelection.create(tr.doc, cursorPos));
@@ -51,4 +227,4 @@ const insertSectionBreakNextPage = insertSectionBreakAtCursor("nextPage");
51
227
  */
52
228
  const insertSectionBreakContinuous = insertSectionBreakAtCursor("continuous");
53
229
  //#endregion
54
- export { insertSectionBreakContinuous, insertSectionBreakNextPage };
230
+ export { insertSectionBreakContinuous, insertSectionBreakNextPage, keepSectionBreaksOnSurvivingMarks, removeSectionBreakAtSelection, setSectionBreakType };
@@ -0,0 +1,8 @@
1
+ import { CommentReferenceAttrs } from "./schema/nodes.js";
2
+ import { ReadProseMirrorAttrsResult } from "./attrs/index.js";
3
+ import { Node } from "prosemirror-model";
4
+ //#region src/prosemirror/commentReferenceAttrs.d.ts
5
+ declare const readCommentReferenceAttrs: (node: Node) => ReadProseMirrorAttrsResult<CommentReferenceAttrs>;
6
+ declare const expectCommentReferenceAttrs: (node: Node) => CommentReferenceAttrs;
7
+ //#endregion
8
+ export { expectCommentReferenceAttrs, readCommentReferenceAttrs };
@@ -0,0 +1,33 @@
1
+ import { panic } from "better-result";
2
+ //#region src/prosemirror/commentReferenceAttrs.ts
3
+ const attrsCache = /* @__PURE__ */ new WeakMap();
4
+ const readCommentReferenceAttrs = (node) => {
5
+ const issues = [];
6
+ if (node.type.name !== "commentReference") issues.push({
7
+ path: "commentReference.type.name",
8
+ message: `Expected commentReference, got ${node.type.name}.`
9
+ });
10
+ const commentId = node.attrs["commentId"];
11
+ if (typeof commentId !== "number" || !Number.isInteger(commentId) || commentId < 0) issues.push({
12
+ path: "commentReference.attrs.commentId",
13
+ message: "Expected a non-negative integer."
14
+ });
15
+ if (issues.length > 0 || typeof commentId !== "number") return {
16
+ ok: false,
17
+ issues
18
+ };
19
+ return {
20
+ ok: true,
21
+ value: { commentId }
22
+ };
23
+ };
24
+ const expectCommentReferenceAttrs = (node) => {
25
+ const cached = attrsCache.get(node);
26
+ if (cached) return cached;
27
+ const result = readCommentReferenceAttrs(node);
28
+ if (!result.ok) panic(`Invalid ProseMirror comment reference attrs:\n${result.issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n")}`);
29
+ attrsCache.set(node, result.value);
30
+ return result.value;
31
+ };
32
+ //#endregion
33
+ export { expectCommentReferenceAttrs, readCommentReferenceAttrs };
@@ -0,0 +1,47 @@
1
+ //#region src/prosemirror/commentReferenceIntegrity.d.ts
2
+ /**
3
+ * What a document must hold for every comment: exactly one `commentReference`
4
+ * node, after the last position its `comment` mark covers.
5
+ *
6
+ * The reference is the run Word paints the visible comment mark with, so a
7
+ * comment without one is invisible in Word and a duplicate paints the mark
8
+ * twice. Editing cannot be trusted to keep that true — a paste duplicates a
9
+ * reference, deleting the commented text orphans one, and a command that adds
10
+ * a comment mark creates none — so the repair is computed here and applied by
11
+ * the extension's `appendTransaction`, rather than left to each call site.
12
+ */
13
+ type CommentReferenceOccurrence = {
14
+ commentId: number;
15
+ position: number;
16
+ /** Node size, so a caller can delete the node without re-reading it. */
17
+ size: number;
18
+ malformed: boolean;
19
+ };
20
+ /** Where a comment's mark last covers content, and how far that content runs. */
21
+ type CommentMarkExtent = {
22
+ commentId: number;
23
+ /** Document position just past the last inline node carrying the mark. */
24
+ end: number;
25
+ };
26
+ type CommentReferenceRepair = {
27
+ type: "delete";
28
+ position: number;
29
+ size: number;
30
+ } | {
31
+ type: "insert";
32
+ position: number;
33
+ commentId: number;
34
+ };
35
+ type CommentReferenceRepairInput = {
36
+ references: readonly CommentReferenceOccurrence[];
37
+ markExtents: readonly CommentMarkExtent[];
38
+ };
39
+ /**
40
+ * The repairs that make a document total, as positions in the document they
41
+ * were read from. Deletions come first, last-first, so they apply in sequence
42
+ * without mapping; the insertions that follow still carry pre-repair positions
43
+ * and the applier maps them through the transaction.
44
+ */
45
+ declare const planCommentReferenceRepairs: ({ references, markExtents }: CommentReferenceRepairInput) => readonly CommentReferenceRepair[];
46
+ //#endregion
47
+ export { CommentMarkExtent, CommentReferenceOccurrence, CommentReferenceRepair, planCommentReferenceRepairs };
@@ -0,0 +1,43 @@
1
+ //#region src/prosemirror/commentReferenceIntegrity.ts
2
+ /**
3
+ * The repairs that make a document total, as positions in the document they
4
+ * were read from. Deletions come first, last-first, so they apply in sequence
5
+ * without mapping; the insertions that follow still carry pre-repair positions
6
+ * and the applier maps them through the transaction.
7
+ */
8
+ const planCommentReferenceRepairs = ({ references, markExtents }) => {
9
+ const markedIds = new Set(markExtents.map(({ commentId }) => commentId));
10
+ const deletions = [];
11
+ const keptIds = /* @__PURE__ */ new Set();
12
+ for (const reference of references) {
13
+ if (reference.malformed || !markedIds.has(reference.commentId)) {
14
+ deletions.push({
15
+ type: "delete",
16
+ position: reference.position,
17
+ size: reference.size
18
+ });
19
+ continue;
20
+ }
21
+ if (keptIds.has(reference.commentId)) {
22
+ deletions.push({
23
+ type: "delete",
24
+ position: reference.position,
25
+ size: reference.size
26
+ });
27
+ continue;
28
+ }
29
+ keptIds.add(reference.commentId);
30
+ }
31
+ const insertions = [];
32
+ for (const { commentId, end } of markExtents) {
33
+ if (keptIds.has(commentId)) continue;
34
+ insertions.push({
35
+ type: "insert",
36
+ position: end,
37
+ commentId
38
+ });
39
+ }
40
+ return [...deletions.toSorted((first, second) => second.position - first.position), ...insertions.toSorted((first, second) => second.position - first.position)];
41
+ };
42
+ //#endregion
43
+ export { planCommentReferenceRepairs };
@@ -3,16 +3,24 @@ import { TableAttrs, TableCellAttrs, TableRowAttrs } from "../schema/nodes.js";
3
3
  import { RunStyleResolver } from "../runStyleFormatting.js";
4
4
  import { Mark, Node } from "prosemirror-model";
5
5
  //#region src/prosemirror/conversion/fromProseDoc.d.ts
6
- /** Convert a ProseMirror document to the document model. */
7
- declare function fromProseDoc(pmDoc: Node, baseDocument?: document_d_exports.Document): document_d_exports.Document;
8
6
  /**
9
- * What a field carrying no stored result reports.
7
+ * Whether a record the editor did not change may come back from the base
8
+ * document by reference.
10
9
  *
11
- * `serializerFallback` writes the visible page number a save has always given a
12
- * result-less PAGE/NUMPAGES field; `authored` reports the result the document
13
- * actually holds, so a text read of a story reads the same loaded and unloaded.
10
+ * `"none"` rebuilds every record out of ProseMirror, which is what folio does
11
+ * today. `"matched"` is the merge against a matched base record; it is declared
12
+ * here because the measurement that tells the two apart has to exist before the
13
+ * merge does, and it panics until it is implemented. An accepted-but-inert
14
+ * value would let a caller believe it had asked for a merge and get a rebuild.
14
15
  */
15
- type EmptyFieldResultMode = "serializerFallback" | "authored";
16
+ type ProjectionReuse = "none" | "matched";
17
+ /** How the conversion treats records the editor did not change. */
18
+ type FromProseDocOptions = {
19
+ /** Defaults to `"none"`, the only value implemented. */
20
+ reuse?: ProjectionReuse;
21
+ };
22
+ /** Convert a ProseMirror document to the document model. */
23
+ declare function fromProseDoc(pmDoc: Node, baseDocument?: document_d_exports.Document, { reuse }?: FromProseDocOptions): document_d_exports.Document;
16
24
  /**
17
25
  * Convert ProseMirror marks to TextFormatting
18
26
  */
@@ -36,9 +44,6 @@ declare function tableCellAttrsToFormatting(attrs: TableCellAttrs): document_d_e
36
44
  * Preserves all non-content parts of the original document
37
45
  */
38
46
  declare function updateDocumentContent(originalDocument: document_d_exports.Document, pmDoc: Node): document_d_exports.Document;
39
- type ProseDocToBlocksOptions = {
40
- emptyFieldResult?: EmptyFieldResultMode;
41
- };
42
47
  /**
43
48
  * Convert a ProseMirror document back to an array of `BlockContent` blocks
44
49
  * (paragraphs, tables, and block-level content controls).
@@ -46,6 +51,6 @@ type ProseDocToBlocksOptions = {
46
51
  * Used for converting edited header/footer PM content back to the document
47
52
  * model.
48
53
  */
49
- declare function proseDocToBlocks(pmDoc: Node, baseContent?: document_d_exports.BlockContent[], styles?: NonNullable<document_d_exports.Document["package"]>["styles"], options?: ProseDocToBlocksOptions): document_d_exports.BlockContent[];
54
+ declare function proseDocToBlocks(pmDoc: Node, baseContent?: document_d_exports.BlockContent[], styles?: NonNullable<document_d_exports.Document["package"]>["styles"]): document_d_exports.BlockContent[];
50
55
  //#endregion
51
- export { EmptyFieldResultMode, ProseDocToBlocksOptions, fromProseDoc, marksToTextFormatting, proseDocToBlocks, standaloneTableCellFromProseMirror, tableAttrsToFormatting, tableCellAttrsToFormatting, tableRowAttrsToFormatting, updateDocumentContent };
56
+ export { FromProseDocOptions, ProjectionReuse, fromProseDoc, marksToTextFormatting, proseDocToBlocks, standaloneTableCellFromProseMirror, tableAttrsToFormatting, tableCellAttrsToFormatting, tableRowAttrsToFormatting, updateDocumentContent };