@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
@@ -0,0 +1,23 @@
1
+ import { Node } from "prosemirror-model";
2
+ //#region src/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts
3
+ declare const bookmarkBoundaryAttrSpec: {
4
+ type: {};
5
+ id: {};
6
+ name: {
7
+ default: null;
8
+ };
9
+ colFirst: {
10
+ default: null;
11
+ };
12
+ colLast: {
13
+ default: null;
14
+ };
15
+ displacedByCustomXml: {
16
+ default: null;
17
+ };
18
+ };
19
+ /** `false` when the element does not describe a boundary ProseMirror can hold. */
20
+ declare const parseBookmarkBoundaryDom: (dom: HTMLElement | string) => Record<string, unknown> | false;
21
+ declare const bookmarkBoundaryDomAttributes: (node: Node, internalClipboardToken?: string) => Record<string, string>;
22
+ //#endregion
23
+ export { bookmarkBoundaryAttrSpec, bookmarkBoundaryDomAttributes, parseBookmarkBoundaryDom };
@@ -0,0 +1,57 @@
1
+ import { expectBookmarkBoundaryAttrs, isDisplacedByCustomXml } from "../../bookmarkBoundaryAttrs.js";
2
+ //#region src/prosemirror/extensions/nodes/bookmarkBoundaryDom.ts
3
+ const readNonnegativeInteger = (value) => {
4
+ if (value === null || !/^(?:0|[1-9]\d*)$/.test(value)) return false;
5
+ const parsed = Number(value);
6
+ return Number.isSafeInteger(parsed) ? parsed : false;
7
+ };
8
+ const readOptionalColumn = (dom, attribute) => {
9
+ const value = dom.getAttribute(attribute);
10
+ return value === null ? void 0 : readNonnegativeInteger(value);
11
+ };
12
+ const bookmarkBoundaryAttrSpec = {
13
+ type: {},
14
+ id: {},
15
+ name: { default: null },
16
+ colFirst: { default: null },
17
+ colLast: { default: null },
18
+ displacedByCustomXml: { default: null }
19
+ };
20
+ /** `false` when the element does not describe a boundary ProseMirror can hold. */
21
+ const parseBookmarkBoundaryDom = (dom) => {
22
+ if (typeof dom === "string") return false;
23
+ const type = dom.getAttribute("data-docx-bookmark-boundary");
24
+ const id = readNonnegativeInteger(dom.getAttribute("data-docx-bookmark-id"));
25
+ if (type !== "start" && type !== "end" || id === false) return false;
26
+ const name = dom.getAttribute("data-docx-bookmark-name");
27
+ if (type === "start" && !name) return false;
28
+ const colFirst = readOptionalColumn(dom, "data-docx-bookmark-col-first");
29
+ const colLast = readOptionalColumn(dom, "data-docx-bookmark-col-last");
30
+ if (colFirst === false || colLast === false) return false;
31
+ const displaced = dom.getAttribute("data-docx-bookmark-displaced");
32
+ return {
33
+ type,
34
+ id,
35
+ ...name ? { name } : {},
36
+ ...colFirst !== void 0 ? { colFirst } : {},
37
+ ...colLast !== void 0 ? { colLast } : {},
38
+ ...isDisplacedByCustomXml(displaced) ? { displacedByCustomXml: displaced } : {}
39
+ };
40
+ };
41
+ const bookmarkBoundaryDomAttributes = (node, internalClipboardToken) => {
42
+ const attrs = expectBookmarkBoundaryAttrs(node);
43
+ return {
44
+ "data-docx-bookmark-boundary": attrs.type,
45
+ "data-docx-bookmark-id": String(attrs.id),
46
+ ...attrs.type === "start" ? { "data-docx-bookmark-name": attrs.name } : {},
47
+ ...attrs.type === "start" && attrs.colFirst !== void 0 ? { "data-docx-bookmark-col-first": String(attrs.colFirst) } : {},
48
+ ...attrs.type === "start" && attrs.colLast !== void 0 ? { "data-docx-bookmark-col-last": String(attrs.colLast) } : {},
49
+ ...attrs.displacedByCustomXml !== void 0 ? { "data-docx-bookmark-displaced": attrs.displacedByCustomXml } : {},
50
+ "aria-hidden": "true",
51
+ contenteditable: "false",
52
+ style: "display: none;",
53
+ ...internalClipboardToken === void 0 ? {} : { "data-docx-internal-clipboard": internalClipboardToken }
54
+ };
55
+ };
56
+ //#endregion
57
+ export { bookmarkBoundaryAttrSpec, bookmarkBoundaryDomAttributes, parseBookmarkBoundaryDom };
@@ -2,20 +2,29 @@ import { document_d_exports } from "../../types/document.js";
2
2
  import { TextColorAttrs } from "../schema/marks.js";
3
3
  import "../schema/index.js";
4
4
  import { TablePropertiesCommand } from "../../utils/tableOperations.js";
5
+ import { SectionBreakType } from "../sectionCarrier.js";
5
6
  import { GenerateTableOfContentsOptions, ResolvedStyleAttrs } from "./core/ParagraphExtension.js";
6
7
  import { BorderPreset, TableBorderPreset } from "./nodes/TableExtension.js";
7
8
  import { Command, Plugin } from "prosemirror-state";
8
9
  import { MarkSpec, NodeSpec, Schema } from "prosemirror-model";
9
10
  //#region src/prosemirror/extensions/types.d.ts
11
+ /**
12
+ * A border a host asks folio to apply.
13
+ *
14
+ * `style` is what the model holds, not a narrower authoring union: a table
15
+ * style preset is built by reading a parsed `w:tblBorders` and handing it
16
+ * back, so a token the schema does not declare has to survive the round trip
17
+ * rather than be refused at the command.
18
+ */
10
19
  type TableCellBorderCommandSpec = {
11
- style: string;
20
+ style: document_d_exports.BorderStyleValue;
12
21
  size?: number;
13
22
  color?: {
14
23
  rgb: string;
15
24
  };
16
25
  };
17
26
  type TableBorderCommandSpec = {
18
- style: string;
27
+ style: document_d_exports.BorderStyleValue;
19
28
  size: number;
20
29
  color: {
21
30
  rgb: string;
@@ -98,7 +107,7 @@ type FolioCommandArguments = {
98
107
  setSpaceAfter: [twips: number];
99
108
  applyStyle: [styleId: string, resolvedAttrs?: ResolvedStyleAttrs];
100
109
  clearStyle: [];
101
- insertSectionBreak: [breakType: "nextPage" | "continuous" | "oddPage" | "evenPage"];
110
+ insertSectionBreak: [breakType: SectionBreakType];
102
111
  removeSectionBreak: [];
103
112
  addTabStop: [position: number, alignment?: document_d_exports.TabStopAlignment, leader?: document_d_exports.TabLeader];
104
113
  removeTabStop: [position: number];
@@ -4,6 +4,7 @@ import { ResolvedParagraphStyle, StyleResolver, createStyleResolver } from "./st
4
4
  import { schema, singletonManager } from "./schema/index.js";
5
5
  import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
6
6
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
7
+ import { TableBorderCommandSpec, TableCellBorderCommandSpec } from "./extensions/types.js";
7
8
  import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./commands/formatPainter.js";
8
9
  import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
9
10
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensions/marks/HyperlinkExtension.js";
@@ -14,10 +15,11 @@ import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyl
14
15
  import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, insertTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap } from "./commands/table.js";
15
16
  import { insertPageBreak } from "./commands/pageBreak.js";
16
17
  import "./commands/index.js";
17
- import { fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.js";
18
+ import { FromProseDocOptions, ProjectionReuse, fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.js";
18
19
  import { ToProseDocOptions, createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
19
20
  import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
20
21
  import "./conversion/index.js";
22
+ import { ActiveListState, ListState, ListType, NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
21
23
  import { SelectionChangeCallback, SelectionContext, createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./plugins/selectionTracker.js";
22
24
  import { ensureParaIdsInState } from "./extensions/features/ParaIdAllocatorExtension.js";
23
25
  import "./styles/index.js";
@@ -26,4 +28,4 @@ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles
26
28
  import "./plugins/index.js";
27
29
  import { insertPageBreakInView, insertTableInView, insertTableOfContentsInView } from "./insertOperations.js";
28
30
  import { TextSelection } from "prosemirror-state";
29
- export { type BorderPreset, type CapturedTextFormatting, type FontFamilyAttrs, type FontSizeAttrs, type HyperlinkAttrs, type ImageAttrs, PAINTABLE_MARK_NAMES, type ParagraphAttrs, type ProseMirrorDocumentValidationIssue, type ResolvedParagraphStyle, type SelectionChangeCallback, type SelectionContext, type SelectionState, StyleResolver, type TableBorderPreset, type TableContextInfo, type TextColorAttrs, TextSelection, type ToProseDocOptions, type UnderlineAttrs, type ValidateProseMirrorDocumentResult, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTableOfContents, getDocumentBuiltInStyles, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
31
+ export { type ActiveListState, type BorderPreset, type CapturedTextFormatting, type FontFamilyAttrs, type FontSizeAttrs, type FromProseDocOptions, type HyperlinkAttrs, type ImageAttrs, type ListState, type ListType, NO_LIST_STATE, PAINTABLE_MARK_NAMES, type ParagraphAttrs, type ProjectionReuse, type ProseMirrorDocumentValidationIssue, type ResolvedParagraphStyle, type SelectionChangeCallback, type SelectionContext, type SelectionState, StyleResolver, type TableBorderCommandSpec, type TableBorderPreset, type TableCellBorderCommandSpec, type TableContextInfo, type TextColorAttrs, TextSelection, type ToProseDocOptions, type UnderlineAttrs, type ValidateProseMirrorDocumentResult, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTableOfContents, getDocumentBuiltInStyles, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInListState, isInTableCell as isInTable, isMarkActive, listStateLevel, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, resolveListState, sameListState, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
@@ -13,6 +13,7 @@ import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensi
13
13
  import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
14
14
  import { getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
15
15
  import { insertPageBreakInView, insertTableInView, insertTableOfContentsInView } from "./insertOperations.js";
16
+ import { NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
16
17
  import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./plugins/documentStyles.js";
17
18
  import { createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./plugins/selectionTracker.js";
18
19
  import { schema, singletonManager } from "./schema/index.js";
@@ -20,4 +21,4 @@ import { extractSelectionState } from "./selectionState.js";
20
21
  import { StyleResolver, createStyleResolver } from "./styles/styleResolver.js";
21
22
  import { assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
22
23
  import { TextSelection } from "prosemirror-state";
23
- export { PAINTABLE_MARK_NAMES, StyleResolver, TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTableOfContents, getDocumentBuiltInStyles, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
24
+ export { NO_LIST_STATE, PAINTABLE_MARK_NAMES, StyleResolver, TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTableOfContents, getDocumentBuiltInStyles, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInListState, isInTableCell as isInTable, isMarkActive, listStateLevel, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, resolveListState, sameListState, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
@@ -0,0 +1,39 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { InlineWrapperLayer } from "./schema/marks.js";
3
+ //#region src/prosemirror/inlineWrapperStack.d.ts
4
+ /** The DOM attribute that carries a serialised stack through copy and paste. */
5
+ declare const INLINE_WRAPPER_STACK_ATTRIBUTE = "data-inline-wrapper";
6
+ /** A layer with its keys in canonical order, absent fields left absent. */
7
+ declare const inlineWrapperLayer: (layer: InlineWrapperLayer) => InlineWrapperLayer;
8
+ /**
9
+ * The model member a layer describes, holding `content`.
10
+ *
11
+ * The inverse of the `WrapperLayer` projection: `toProseDoc` takes the model
12
+ * member apart into a layer and its content, and the save leg puts one back
13
+ * together. Both directions live here so a wrapper kind is spelled once.
14
+ */
15
+ declare const inlineWrapperMember: (layer: InlineWrapperLayer, content: document_d_exports.InlineWrapper["content"]) => document_d_exports.InlineWrapper;
16
+ /** `layers` in canonical form, or `null` when there is no wrapper to record. */
17
+ declare const inlineWrapperStack: (layers: readonly InlineWrapperLayer[]) => readonly InlineWrapperLayer[] | null;
18
+ declare const serializeInlineWrapperStack: (stack: readonly InlineWrapperLayer[]) => string;
19
+ /**
20
+ * The key two stacks share exactly when they are the same nest of wrappers.
21
+ *
22
+ * The save leg groups adjacent inline leaves by it, so it has to be the
23
+ * factory's canonical spelling rather than whatever order an attrs object
24
+ * happens to carry: two leaves inside one `w:bdo` that keyed differently would
25
+ * be written as two `w:bdo` elements. The empty stack keys as the empty string,
26
+ * which is what "inside no wrapper" compares as.
27
+ */
28
+ declare const inlineWrapperStackKey: (stack: readonly InlineWrapperLayer[]) => string;
29
+ /**
30
+ * A stack read back from the DOM, or `null` when the markup carries none.
31
+ *
32
+ * Paste from outside the editor is the ordinary case: the attribute is absent,
33
+ * so the pasted leaf carries no wrapper. Markup that states the attribute but
34
+ * not a stack this build validates is read the same way — the text is what
35
+ * matters, and inventing a wrapper around it would change the document.
36
+ */
37
+ declare const parseInlineWrapperStack: (serialized: string | null | undefined) => readonly InlineWrapperLayer[] | null;
38
+ //#endregion
39
+ export { INLINE_WRAPPER_STACK_ATTRIBUTE, inlineWrapperLayer, inlineWrapperMember, inlineWrapperStack, inlineWrapperStackKey, parseInlineWrapperStack, serializeInlineWrapperStack };
@@ -0,0 +1,92 @@
1
+ import { readInlineWrapperStack } from "./attrs/index.js";
2
+ import { Result, panic } from "better-result";
3
+ //#region src/prosemirror/inlineWrapperStack.ts
4
+ /**
5
+ * The one place an inline-wrapper layer is built, and the codec that carries a
6
+ * stack through the DOM.
7
+ *
8
+ * Two layers describing the same wrapper have to be the same value, because
9
+ * `fromProseDoc` groups inline leaves into runs by `JSON.stringify` over their
10
+ * mark attrs: one wrapper spelled with its keys in two orders would split one
11
+ * run into two. Object key order is insertion order in JavaScript, so the
12
+ * factory fixes it and every construction site goes through the factory —
13
+ * including the one that reads a stack back out of the DOM, where `JSON.parse`
14
+ * preserves whatever order the markup happened to carry.
15
+ */
16
+ /** The DOM attribute that carries a serialised stack through copy and paste. */
17
+ const INLINE_WRAPPER_STACK_ATTRIBUTE = "data-inline-wrapper";
18
+ /**
19
+ * A tagged layer's keys in canonical order.
20
+ *
21
+ * `propertiesXml` is part of the layer, so it is part of the stack key the
22
+ * save leg groups by: two adjacent smart tags whose properties differ are two
23
+ * wrappers, and folding them into one would attribute the second tag's text to
24
+ * the first tag's properties.
25
+ */
26
+ const taggedLayer = (kind, layer) => {
27
+ const canonical = {
28
+ kind,
29
+ element: layer.element
30
+ };
31
+ if (layer.uri !== void 0) canonical.uri = layer.uri;
32
+ if (layer.propertiesXml !== void 0) canonical.propertiesXml = layer.propertiesXml;
33
+ return canonical;
34
+ };
35
+ /** A layer with its keys in canonical order, absent fields left absent. */
36
+ const inlineWrapperLayer = (layer) => {
37
+ switch (layer.kind) {
38
+ case "bidi": return layer.direction === void 0 ? {
39
+ kind: "bidi",
40
+ control: layer.control
41
+ } : {
42
+ kind: "bidi",
43
+ control: layer.control,
44
+ direction: layer.direction
45
+ };
46
+ case "smartTag": return taggedLayer("smartTag", layer);
47
+ case "customXml": return taggedLayer("customXml", layer);
48
+ default: panic(`Unsupported inline wrapper layer: ${JSON.stringify(layer)}`);
49
+ }
50
+ };
51
+ /**
52
+ * The model member a layer describes, holding `content`.
53
+ *
54
+ * The inverse of the `WrapperLayer` projection: `toProseDoc` takes the model
55
+ * member apart into a layer and its content, and the save leg puts one back
56
+ * together. Both directions live here so a wrapper kind is spelled once.
57
+ */
58
+ const inlineWrapperMember = (layer, content) => ({
59
+ ...inlineWrapperLayer(layer),
60
+ type: "inlineWrapper",
61
+ content
62
+ });
63
+ /** `layers` in canonical form, or `null` when there is no wrapper to record. */
64
+ const inlineWrapperStack = (layers) => layers.length === 0 ? null : layers.map(inlineWrapperLayer);
65
+ const serializeInlineWrapperStack = (stack) => JSON.stringify(stack);
66
+ /**
67
+ * The key two stacks share exactly when they are the same nest of wrappers.
68
+ *
69
+ * The save leg groups adjacent inline leaves by it, so it has to be the
70
+ * factory's canonical spelling rather than whatever order an attrs object
71
+ * happens to carry: two leaves inside one `w:bdo` that keyed differently would
72
+ * be written as two `w:bdo` elements. The empty stack keys as the empty string,
73
+ * which is what "inside no wrapper" compares as.
74
+ */
75
+ const inlineWrapperStackKey = (stack) => stack.length === 0 ? "" : serializeInlineWrapperStack(stack.map(inlineWrapperLayer));
76
+ /**
77
+ * A stack read back from the DOM, or `null` when the markup carries none.
78
+ *
79
+ * Paste from outside the editor is the ordinary case: the attribute is absent,
80
+ * so the pasted leaf carries no wrapper. Markup that states the attribute but
81
+ * not a stack this build validates is read the same way — the text is what
82
+ * matters, and inventing a wrapper around it would change the document.
83
+ */
84
+ const parseInlineWrapperStack = (serialized) => {
85
+ if (!serialized) return null;
86
+ const parsed = Result.try(() => JSON.parse(serialized));
87
+ if (parsed.isErr()) return null;
88
+ const stack = readInlineWrapperStack(parsed.value);
89
+ return stack.ok ? stack.value.map(inlineWrapperLayer) : null;
90
+ };
91
+ //#endregion
92
+ export { INLINE_WRAPPER_STACK_ATTRIBUTE, inlineWrapperLayer, inlineWrapperMember, inlineWrapperStack, inlineWrapperStackKey, parseInlineWrapperStack, serializeInlineWrapperStack };
@@ -69,11 +69,11 @@ declare function cloneListCounterState(state: ListCounterState): ListCounterStat
69
69
  * paragraphs advance only the document view in which they exist.
70
70
  */
71
71
  declare function advanceVisibleListMarker(attrs: ParagraphAttrs, streams: ListCounterStreams): VisibleListMarker;
72
- declare function formatCounter(value: number, format: document_d_exports.NumberFormat | undefined): string;
72
+ declare function formatCounter(value: number, format: document_d_exports.CounterFormat | undefined): string;
73
73
  type ResolveListTemplateOptions = {
74
74
  template: string;
75
75
  counters: number[];
76
- levelFormats?: document_d_exports.NumberFormat[] | undefined;
76
+ levelFormats?: document_d_exports.CounterFormat[] | undefined;
77
77
  forceDecimal?: boolean | undefined;
78
78
  };
79
79
  declare function resolveListTemplate(options: ResolveListTemplateOptions): string;
@@ -1,6 +1,7 @@
1
1
  import { convertBulletToUnicode } from "../docx/bulletMarkers.js";
2
- import { isNumberingReference } from "../docx/numberingReference.js";
2
+ import { paragraphNumberingLevel, paragraphNumberingReferenceId, sameStatedParagraphNumbering } from "../docx/numberingReference.js";
3
3
  import { formatOoxmlCounter } from "../docx/ooxmlCounterFormatter.js";
4
+ import { isListNumPr } from "../layout-engine/types.js";
4
5
  import { LIST_RENDERING_ATTR_KEYS } from "./listRenderingAttrs.js";
5
6
  //#region src/prosemirror/listMarker.ts
6
7
  const MAX_LIST_LEVEL = 8;
@@ -61,12 +62,10 @@ function cloneListCounterState(state) {
61
62
  ...state.lastAdvancedNumId !== void 0 ? { lastAdvancedNumId: state.lastAdvancedNumId } : {}
62
63
  };
63
64
  }
64
- const isListNumPr = (value) => value !== void 0 && value !== null;
65
- const sameListNumPr = (left, right) => left.numId === right.numId && left.ilvl === right.ilvl;
66
65
  function previousListAttrs(attrs) {
67
66
  const previous = (attrs._propertyChanges?.find(({ previousFormatting }) => {
68
67
  const previousNumPr = previousFormatting?.numPr;
69
- return isListNumPr(previousNumPr) && (!attrs.numPr || !sameListNumPr(previousNumPr, attrs.numPr));
68
+ return isListNumPr(previousNumPr) && (!attrs.numPr || !sameStatedParagraphNumbering(previousNumPr, attrs.numPr));
70
69
  }))?.previousFormatting;
71
70
  if (!previous || !isListNumPr(previous.numPr)) return null;
72
71
  return {
@@ -117,7 +116,7 @@ function advanceVisibleListMarker(attrs, streams) {
117
116
  advances
118
117
  };
119
118
  const numberingWasAdded = attrs._propertyChanges?.some(({ previousFormatting }) => previousFormatting && Object.hasOwn(previousFormatting, "numPr") && previousFormatting.numPr == null);
120
- const numberingChanged = previous?.numPr !== void 0 && !sameListNumPr(previous.numPr, attrs.numPr);
119
+ const numberingChanged = previous?.numPr !== void 0 && !sameStatedParagraphNumbering(previous.numPr, attrs.numPr);
121
120
  const visible = advance(attrs, "final");
122
121
  if (attrs.pPrMark?.kind !== "ins" && !numberingWasAdded && !numberingChanged) advance(attrs, "original");
123
122
  else if (numberingChanged && previous) advance(previous, "original");
@@ -177,10 +176,10 @@ function formatNumberedMarker(counters, level) {
177
176
  }
178
177
  function advanceListMarker(attrs, state) {
179
178
  const markerTemplate = attrs.listMarkerTemplate ?? attrs.listMarker;
180
- const level = attrs.numPr?.ilvl ?? 0;
179
+ const level = paragraphNumberingLevel(attrs.numPr) ?? 0;
181
180
  if (!Number.isInteger(level) || level < 0 || level > 8) return null;
182
- const numId = attrs.numPr?.numId;
183
- if (!isNumberingReference(numId)) {
181
+ const numId = paragraphNumberingReferenceId(attrs.numPr);
182
+ if (numId === void 0) {
184
183
  let marker = null;
185
184
  if (markerTemplate?.includes("%") && !attrs.listIsBullet) {
186
185
  const counters = getLastListCounters(state);
@@ -1,4 +1,14 @@
1
+ import { paragraphNumberingLevel } from "@stll/docx-core/model";
1
2
  //#region src/prosemirror/listRenderingAttrs.ts
3
+ /**
4
+ * The one table that ties `Paragraph.listRendering` to the editor's `list*`
5
+ * attrs. Both projections (model → attrs in `toProseDoc`, attrs → model in
6
+ * `fromProseDoc`) and the cleared-attr set derive from it, so a field added
7
+ * to `ListRendering` without a projection fails to compile instead of being
8
+ * silently dropped on the way out of the editor.
9
+ *
10
+ * `level` and `numId` are not here: they travel in `numPr`.
11
+ */
2
12
  const LIST_RENDERING_ATTR_BY_FIELD = {
3
13
  marker: "listMarker",
4
14
  markerTemplate: "listMarkerTemplate",
@@ -70,7 +80,7 @@ const listRenderingFromAttrs = ({ attrs, numId }) => {
70
80
  };
71
81
  return {
72
82
  marker: attrs.listMarker ?? "",
73
- level: attrs.numPr?.ilvl ?? 0,
83
+ level: paragraphNumberingLevel(attrs.numPr) ?? 0,
74
84
  numId,
75
85
  isBullet: attrs.listIsBullet ?? false,
76
86
  ...definedFields(optional)
@@ -0,0 +1,62 @@
1
+ import { NumberingMap } from "../docx/numberingParser.js";
2
+ import { ParagraphNumberingOverride } from "@stll/docx-core/model";
3
+ //#region src/prosemirror/listState.d.ts
4
+ /**
5
+ * Which list the selection sits in, for a toolbar.
6
+ *
7
+ * One union, in core, for both adapters. There used to be three declarations
8
+ * of this — React's `ui/ListButtons`, Vue's `utils/listState`, and a third in
9
+ * Vue's editor types whose `type` had widened to `string` — none importing
10
+ * another and none covered by a parity gate, so they drifted without anything
11
+ * able to see it.
12
+ *
13
+ * The union also retires the `isInList` flag, which restated `type !== "none"`,
14
+ * and the `numId` that was meaningful only when it was set: a state such as
15
+ * `{ type: "none", isInList: true, numId: 7, level: -1 }` was representable and
16
+ * meant nothing.
17
+ */
18
+ type ListState = {
19
+ readonly type: "none";
20
+ } | {
21
+ readonly type: "bullet";
22
+ readonly level: number;
23
+ readonly numId?: number;
24
+ } | {
25
+ readonly type: "numbered";
26
+ readonly level: number;
27
+ readonly numId?: number;
28
+ };
29
+ /** The kinds of list a toolbar distinguishes. */
30
+ type ListType = ListState["type"];
31
+ /** The selection is in no list. */
32
+ declare const NO_LIST_STATE: {
33
+ readonly type: "none";
34
+ };
35
+ /** A selection that is in a list, so it has a level. */
36
+ type ActiveListState = Exclude<ListState, {
37
+ type: "none";
38
+ }>;
39
+ /**
40
+ * Whether the selection is in a list at all: the one reader over the
41
+ * discriminator, so no consumer spells the empty arm itself.
42
+ */
43
+ declare const isInListState: (state: ListState | undefined) => state is ActiveListState;
44
+ /** The list level the selection sits at, zero when it is in no list. */
45
+ declare const listStateLevel: (state: ListState | undefined) => number;
46
+ /**
47
+ * The toolbar's view of a paragraph's stated numbering.
48
+ *
49
+ * Which kind of list it is comes from the numbering definitions, through the
50
+ * registry's own reader: a level whose `w:numFmt` is `bullet` is a bullet list
51
+ * and anything else is a numbered one. The adapters used to decide it from the
52
+ * id — `numId === 1` meant bullets — which was true only of documents Folio
53
+ * had created itself, and read a hundred-item bulleted import as numbered.
54
+ *
55
+ * A cancellation and a level with no resolved id are not lists. Callers that
56
+ * have a style tier must merge it before asking for toolbar state.
57
+ */
58
+ declare const resolveListState: (numbering: NumberingMap | null | undefined, numPr: ParagraphNumberingOverride | undefined) => ListState;
59
+ /** Whether two toolbar list states say the same thing. */
60
+ declare const sameListState: (left: ListState | undefined, right: ListState | undefined) => boolean;
61
+ //#endregion
62
+ export { ActiveListState, ListState, ListType, NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState };
@@ -0,0 +1,49 @@
1
+ import { isBulletLevel } from "../docx/numberingParser.js";
2
+ import { panic } from "better-result";
3
+ import { resolveParagraphNumbering } from "@stll/docx-core/model";
4
+ //#region src/prosemirror/listState.ts
5
+ /** The selection is in no list. */
6
+ const NO_LIST_STATE = { type: "none" };
7
+ /**
8
+ * Whether the selection is in a list at all: the one reader over the
9
+ * discriminator, so no consumer spells the empty arm itself.
10
+ */
11
+ const isInListState = (state) => state !== void 0 && state.type !== "none";
12
+ /** The list level the selection sits at, zero when it is in no list. */
13
+ const listStateLevel = (state) => isInListState(state) ? state.level : 0;
14
+ /**
15
+ * The toolbar's view of a paragraph's stated numbering.
16
+ *
17
+ * Which kind of list it is comes from the numbering definitions, through the
18
+ * registry's own reader: a level whose `w:numFmt` is `bullet` is a bullet list
19
+ * and anything else is a numbered one. The adapters used to decide it from the
20
+ * id — `numId === 1` meant bullets — which was true only of documents Folio
21
+ * had created itself, and read a hundred-item bulleted import as numbered.
22
+ *
23
+ * A cancellation and a level with no resolved id are not lists. Callers that
24
+ * have a style tier must merge it before asking for toolbar state.
25
+ */
26
+ const resolveListState = (numbering, numPr) => {
27
+ if (numPr === void 0) return NO_LIST_STATE;
28
+ const resolved = resolveParagraphNumbering(numPr);
29
+ if (resolved.kind === "none") return NO_LIST_STATE;
30
+ const { numId, ilvl: level } = resolved;
31
+ const definition = numbering?.getLevel(numId, level) ?? null;
32
+ return {
33
+ type: definition !== null && isBulletLevel(definition) ? "bullet" : "numbered",
34
+ level,
35
+ numId
36
+ };
37
+ };
38
+ /** Whether two toolbar list states say the same thing. */
39
+ const sameListState = (left, right) => {
40
+ if (left === void 0 || right === void 0) return left === right;
41
+ switch (left.type) {
42
+ case "none": return right.type === left.type;
43
+ case "bullet":
44
+ case "numbered": return left.type === right.type && left.level === right.level && left.numId === right.numId;
45
+ default: return panic(`Unhandled list state ${JSON.stringify(left)}`);
46
+ }
47
+ };
48
+ //#endregion
49
+ export { NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState };
@@ -0,0 +1,13 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { ReadProseMirrorAttrsResult } from "./attrs/index.js";
3
+ import { Node } from "prosemirror-model";
4
+ //#region src/prosemirror/moveRangeBoundaryAttrs.d.ts
5
+ type MoveRangeMarker = Extract<document_d_exports.ParagraphContent, {
6
+ type: "moveFromRangeStart" | "moveFromRangeEnd" | "moveToRangeStart" | "moveToRangeEnd";
7
+ }>;
8
+ /** Read one hidden move-range boundary from an untyped editor or clipboard attribute. */
9
+ declare const readMoveRangeMarker: (value: unknown, path?: string) => ReadProseMirrorAttrsResult<MoveRangeMarker>;
10
+ declare const readMoveRangeBoundaryAttrs: (node: Node) => ReadProseMirrorAttrsResult<MoveRangeMarker>;
11
+ declare const expectMoveRangeBoundaryAttrs: (node: Node) => MoveRangeMarker;
12
+ //#endregion
13
+ export { MoveRangeMarker, expectMoveRangeBoundaryAttrs, readMoveRangeBoundaryAttrs, readMoveRangeMarker };
@@ -0,0 +1,114 @@
1
+ import { panic } from "better-result";
2
+ //#region src/prosemirror/moveRangeBoundaryAttrs.ts
3
+ const MOVE_RANGE_START_TYPES = /* @__PURE__ */ new Set(["moveFromRangeStart", "moveToRangeStart"]);
4
+ const MOVE_RANGE_END_TYPES = /* @__PURE__ */ new Set(["moveFromRangeEnd", "moveToRangeEnd"]);
5
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
+ const isNonNegativeSafeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
7
+ const displacementOf = (value) => value === "next" || value === "prev" ? value : void 0;
8
+ /** Read one hidden move-range boundary from an untyped editor or clipboard attribute. */
9
+ const readMoveRangeMarker = (value, path = "moveRangeBoundary.attrs.marker") => {
10
+ const issues = [];
11
+ if (!isRecord(value)) return {
12
+ ok: false,
13
+ issues: [{
14
+ path,
15
+ message: "Expected a move range marker object."
16
+ }]
17
+ };
18
+ const type = value["type"];
19
+ const isStart = typeof type === "string" && MOVE_RANGE_START_TYPES.has(type);
20
+ const isEnd = typeof type === "string" && MOVE_RANGE_END_TYPES.has(type);
21
+ if (!isStart && !isEnd) issues.push({
22
+ path: `${path}.type`,
23
+ message: "Expected a move range marker type."
24
+ });
25
+ const id = value["id"];
26
+ if (!isNonNegativeSafeInteger(id)) issues.push({
27
+ path: `${path}.id`,
28
+ message: "Expected a non-negative safe integer."
29
+ });
30
+ const displacedByCustomXml = displacementOf(value["displacedByCustomXml"]);
31
+ if (value["displacedByCustomXml"] !== void 0 && displacedByCustomXml === void 0) issues.push({
32
+ path: `${path}.displacedByCustomXml`,
33
+ message: "Expected \"next\" or \"prev\"."
34
+ });
35
+ const name = value["name"];
36
+ const author = value["author"];
37
+ const date = value["date"];
38
+ const colFirst = value["colFirst"];
39
+ const colLast = value["colLast"];
40
+ if (isStart) {
41
+ if (typeof name !== "string" || name.trim().length === 0) issues.push({
42
+ path: `${path}.name`,
43
+ message: "Expected a non-empty string."
44
+ });
45
+ if (typeof author !== "string" || author.trim().length === 0) issues.push({
46
+ path: `${path}.author`,
47
+ message: "Expected a non-empty string."
48
+ });
49
+ if (date !== void 0 && typeof date !== "string") issues.push({
50
+ path: `${path}.date`,
51
+ message: "Expected a string."
52
+ });
53
+ for (const [key, column] of [["colFirst", colFirst], ["colLast", colLast]]) if (column !== void 0 && !isNonNegativeSafeInteger(column)) issues.push({
54
+ path: `${path}.${key}`,
55
+ message: "Expected a non-negative safe integer."
56
+ });
57
+ }
58
+ if (issues.length > 0 || !isNonNegativeSafeInteger(id) || !isStart && !isEnd) return {
59
+ ok: false,
60
+ issues
61
+ };
62
+ const displacement = displacedByCustomXml === void 0 ? {} : { displacedByCustomXml };
63
+ if (type === "moveFromRangeEnd" || type === "moveToRangeEnd") return {
64
+ ok: true,
65
+ value: {
66
+ type,
67
+ id,
68
+ ...displacement
69
+ }
70
+ };
71
+ if (type !== "moveFromRangeStart" && type !== "moveToRangeStart" || typeof name !== "string" || typeof author !== "string") return {
72
+ ok: false,
73
+ issues
74
+ };
75
+ return {
76
+ ok: true,
77
+ value: {
78
+ type,
79
+ id,
80
+ name,
81
+ author,
82
+ ...typeof date === "string" ? { date } : {},
83
+ ...typeof colFirst === "number" ? { colFirst } : {},
84
+ ...typeof colLast === "number" ? { colLast } : {},
85
+ ...displacement
86
+ }
87
+ };
88
+ };
89
+ const attrsCache = /* @__PURE__ */ new WeakMap();
90
+ const readMoveRangeBoundaryAttrs = (node) => {
91
+ const result = readMoveRangeMarker(node.attrs["marker"]);
92
+ if (node.type.name === "moveRangeBoundary") return result;
93
+ const issue = {
94
+ path: "moveRangeBoundary.type.name",
95
+ message: `Expected moveRangeBoundary, got ${node.type.name}.`
96
+ };
97
+ return result.ok ? {
98
+ ok: false,
99
+ issues: [issue]
100
+ } : {
101
+ ok: false,
102
+ issues: [issue, ...result.issues]
103
+ };
104
+ };
105
+ const expectMoveRangeBoundaryAttrs = (node) => {
106
+ const cached = attrsCache.get(node);
107
+ if (cached) return cached;
108
+ const result = readMoveRangeBoundaryAttrs(node);
109
+ if (!result.ok) panic(`Invalid ProseMirror move range boundary attrs:\n${result.issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n")}`);
110
+ attrsCache.set(node, result.value);
111
+ return result.value;
112
+ };
113
+ //#endregion
114
+ export { expectMoveRangeBoundaryAttrs, readMoveRangeBoundaryAttrs, readMoveRangeMarker };