@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,73 @@
1
+ import { Node } from "prosemirror-model";
2
+ import { Result } from "better-result";
3
+ import * as Y from "yjs";
4
+ //#region src/prosemirror/yjsDocumentMetadata.d.ts
5
+ /**
6
+ * Carry a snapshot written under `version` forward to the next version,
7
+ * rewriting the fragment in place and answering how many paragraphs changed.
8
+ */
9
+ type AttrSchemaMigrationStep = (fragment: Y.XmlFragment) => number;
10
+ /** Every attr-schema version this build reads, oldest first, with no gaps. */
11
+ declare const FOLIO_YJS_ATTR_SCHEMA_VERSIONS: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
12
+ /** An attr-schema version this build can read. */
13
+ type FolioYjsAttrSchemaVersion = (typeof FOLIO_YJS_ATTR_SCHEMA_VERSIONS)[number];
14
+ /**
15
+ * The attr-schema version this build writes. Derived against the migration map
16
+ * so the constant and the map cannot disagree.
17
+ */
18
+ declare const FOLIO_YJS_ATTR_SCHEMA_VERSION = 11;
19
+ /**
20
+ * The steps that carry a snapshot written under `fromVersion` up to
21
+ * {@link FOLIO_YJS_ATTR_SCHEMA_VERSION}, in order. Empty when the snapshot is
22
+ * already current.
23
+ */
24
+ declare const attrSchemaMigrationSteps: (fromVersion: FolioYjsAttrSchemaVersion) => readonly AttrSchemaMigrationStep[];
25
+ /**
26
+ * Carry a fragment this build is about to read or write up to the attr shape
27
+ * this build writes, and stamp the marker.
28
+ *
29
+ * Every entry point that hands a fragment to `initProseMirrorDoc` calls this,
30
+ * for two reasons that are the same reason. A step that rewrites values has to
31
+ * run before a node is built from them, or the build reads the old shape as
32
+ * the new one. And the marker has to say what the fragment may now hold before
33
+ * the first edit writes an attr of this build's shape into it, because an
34
+ * older build reading an unmarked snapshot drops what it does not know without
35
+ * a trace.
36
+ *
37
+ * Returns how many elements the steps rewrote.
38
+ */
39
+ declare const applyAttrSchemaMigrations: (ydoc: Y.Doc, fragment: Y.XmlFragment, fromVersion: FolioYjsAttrSchemaVersion) => number;
40
+ declare const FolioYjsAttrSchemaVersionError_base: import("better-result").TaggedErrorClass<"FolioYjsAttrSchemaVersionError">;
41
+ /** Raised when a snapshot's attr-schema marker is ahead of the running code. */
42
+ declare class FolioYjsAttrSchemaVersionError extends FolioYjsAttrSchemaVersionError_base<{
43
+ message: string;
44
+ /** The marker exactly as stored, so the host can log what it refused. */
45
+ marker: unknown;
46
+ /** The newest attr-schema version this build understands. */
47
+ supportedVersion: FolioYjsAttrSchemaVersion;
48
+ }> {}
49
+ /**
50
+ * The attr-schema version a collaboration document was written under.
51
+ *
52
+ * An absent marker is version 0: every snapshot predates the marker, so no
53
+ * backfill is needed to classify one. An older version loads, because
54
+ * {@link attrSchemaMigrationSteps} says what it means. A marker this
55
+ * build does not know is a snapshot written by newer code, and reading it would
56
+ * be a silent misread: ProseMirror copies unknown attr values into the node
57
+ * verbatim and drops unknown keys without a trace. It fails instead.
58
+ */
59
+ declare const readYjsAttrSchemaVersion: (ydoc: Y.Doc) => Result<FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError>;
60
+ declare const proseDocumentParagraphSourceContract: (document: Node) => string | null;
61
+ /** Stamp the attr-schema version of the build that wrote the current fragment. */
62
+ declare const writeYjsAttrSchemaVersion: (ydoc: Y.Doc) => void;
63
+ /**
64
+ * Write both metadata bindings for a freshly seeded collaboration document.
65
+ * The attr-schema version is written unconditionally; the paragraph-source
66
+ * contract only when the seeding document carries one, because a document
67
+ * built in memory rather than parsed from a package has no source to bind to.
68
+ */
69
+ declare const writeYjsDocumentMetadata: (ydoc: Y.Doc, document: Node) => void;
70
+ declare const readYjsParagraphSourceContract: (ydoc: Y.Doc) => string | null;
71
+ declare const withParagraphSourceContract: (document: Node, contract: string) => Node;
72
+ //#endregion
73
+ export { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError, applyAttrSchemaMigrations, attrSchemaMigrationSteps, proseDocumentParagraphSourceContract, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract, writeYjsAttrSchemaVersion, writeYjsDocumentMetadata };
@@ -0,0 +1,592 @@
1
+ import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, getProseDocumentParagraphPropertySourceContract } from "../docx/paragraphPropertySource.js";
2
+ import { mintSectionProperties, parseSectionBreakType } from "./sectionCarrier.js";
3
+ import { Result, TaggedError, panic } from "better-result";
4
+ import { DRAWING_RAW_XML_MODES, outlineLevelFromStatedValue, paragraphNumberingFromSlots } from "@stll/docx-core/model";
5
+ //#region src/prosemirror/yjsDocumentMetadata.ts
6
+ /**
7
+ * Folio's own keys inside a collaboration document: one map, two independent
8
+ * bindings.
9
+ *
10
+ * `paragraphSourceContract` binds the snapshot to the exact bytes of the DOCX
11
+ * it was seeded from. `attrSchemaVersion` binds it to the shape of the node
12
+ * attrs Folio persists. A snapshot can be current on one and stale on the
13
+ * other, so neither key may be derived from the other.
14
+ */
15
+ const FOLIO_YJS_METADATA_MAP_NAME = "folio:document-metadata";
16
+ const PARAGRAPH_SOURCE_CONTRACT_KEY = "paragraphSourceContract";
17
+ const ATTR_SCHEMA_VERSION_KEY = "attrSchemaVersion";
18
+ /**
19
+ * Version 0 is every snapshot written before the marker existed. The marker
20
+ * shipped without changing a single attr, so carrying a v0 snapshot to v1 is
21
+ * the identity: it only stamps the key.
22
+ */
23
+ const stampMarkerOnly = () => 0;
24
+ const isRecord = (value) => typeof value === "object" && value !== null;
25
+ /** A shared text node, identified structurally to keep Yjs a type-only import. */
26
+ const isXmlText = (child) => "toDelta" in child;
27
+ /** The node types whose `fldLock` and `dirty` attrs version 2 rewrites. */
28
+ const FIELD_ELEMENT_NAMES = /* @__PURE__ */ new Set(["field", "structuredField"]);
29
+ const STATED_FLAG_ATTRS = ["fldLock", "dirty"];
30
+ /**
31
+ * Version 1 stored `fldLock` and `dirty` as booleans defaulting to `false`,
32
+ * because the reader that filled them tested `=== true`. A field that authored
33
+ * an explicit `w:fldLock="0"` and one that authored nothing were both stored as
34
+ * `false`, so `false` never meant an explicit off and cannot be kept as one now
35
+ * that `null` is the absence: a v1 snapshot's `false` would start writing an
36
+ * attribute the document never carried.
37
+ */
38
+ const dropUnstatedFieldFlags = (fragment) => {
39
+ let rewritten = 0;
40
+ const visit = (node) => {
41
+ if ("nodeName" in node && FIELD_ELEMENT_NAMES.has(node.nodeName)) {
42
+ const attributes = node.getAttributes();
43
+ let changed = false;
44
+ for (const attr of STATED_FLAG_ATTRS) if (attributes[attr] === false) {
45
+ node.removeAttribute(attr);
46
+ changed = true;
47
+ }
48
+ if (changed) rewritten += 1;
49
+ }
50
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
51
+ };
52
+ visit(fragment);
53
+ return rewritten;
54
+ };
55
+ /** The node type whose `outlineLevel` attrs version 7 rewrites. */
56
+ const PARAGRAPH_ELEMENT_NAME = "paragraph";
57
+ /** A stored outline level, or the absence of one in this carrier. */
58
+ const versionSixOutlineLevel = (value) => {
59
+ if (typeof value !== "number") return;
60
+ return outlineLevelFromStatedValue(value) ?? null;
61
+ };
62
+ /** Rewrite one persisted paragraph-formatting carrier when it stores a v6 number. */
63
+ const versionSixFormatting = (value) => {
64
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
65
+ const outlineLevel = versionSixOutlineLevel(Reflect.get(value, "outlineLevel"));
66
+ if (outlineLevel === void 0) return null;
67
+ const migrated = { ...value };
68
+ if (outlineLevel === null) Reflect.deleteProperty(migrated, "outlineLevel");
69
+ else migrated["outlineLevel"] = outlineLevel;
70
+ return migrated;
71
+ };
72
+ /** Rewrite outline levels in paragraph-property-change formatting carriers. */
73
+ const versionSixPropertyChanges = (value) => {
74
+ if (!Array.isArray(value)) return null;
75
+ const changes = [];
76
+ let changed = false;
77
+ for (const change of value) {
78
+ if (typeof change !== "object" || change === null || Array.isArray(change)) return null;
79
+ const migrated = { ...change };
80
+ for (const tier of ["previousFormatting", "currentFormatting"]) {
81
+ const formatting = versionSixFormatting(change[tier]);
82
+ if (formatting !== null) {
83
+ migrated[tier] = formatting;
84
+ changed = true;
85
+ }
86
+ }
87
+ changes.push(migrated);
88
+ }
89
+ return changed ? changes : null;
90
+ };
91
+ /**
92
+ * Version 6 stored `outlineLevel` as the `w:outlineLvl w:val` number, with 9
93
+ * meaning body text and every consumer deciding that for itself. Version 7
94
+ * stores `OutlineLevel`, so the number has to be mapped: 0..8 become the
95
+ * heading arm, 9 becomes the body-text arm, and anything else is dropped,
96
+ * matching the parse boundary. It cannot be left alone and read lazily,
97
+ * because ProseMirror copies a stored attr into the node without validating
98
+ * and the strict validator would then panic on the first read of an untouched
99
+ * room.
100
+ */
101
+ const outlineLevelBecomesAUnion = (fragment) => {
102
+ let rewritten = 0;
103
+ const visit = (node) => {
104
+ if ("nodeName" in node && node.nodeName === PARAGRAPH_ELEMENT_NAME) {
105
+ const attributes = node.getAttributes();
106
+ let changed = false;
107
+ const outlineLevel = versionSixOutlineLevel(attributes["outlineLevel"]);
108
+ if (outlineLevel !== void 0) {
109
+ if (outlineLevel === null) node.removeAttribute("outlineLevel");
110
+ else node.setAttribute("outlineLevel", outlineLevel);
111
+ changed = true;
112
+ }
113
+ for (const attr of ["_originalFormatting", "_resolvedFormatting"]) {
114
+ const formatting = versionSixFormatting(attributes[attr]);
115
+ if (formatting !== null) {
116
+ node.setAttribute(attr, formatting);
117
+ changed = true;
118
+ }
119
+ }
120
+ const propertyChanges = versionSixPropertyChanges(attributes["_propertyChanges"]);
121
+ if (propertyChanges !== null) {
122
+ node.setAttribute("_propertyChanges", propertyChanges);
123
+ changed = true;
124
+ }
125
+ if (changed) rewritten += 1;
126
+ }
127
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
128
+ };
129
+ visit(fragment);
130
+ return rewritten;
131
+ };
132
+ /**
133
+ * Version 3 adds `docxRotation`, `docxFlipH` and `docxFlipV` to the drawing
134
+ * nodes. A v2 snapshot states none of them, and `readAuthoredTransform` reads
135
+ * such a node from its `transform` CSS, which is the only record it ever had,
136
+ * so nothing has to be rewritten. The marker still moves: a v3 snapshot read
137
+ * by a v2 build would have the three attrs dropped without a trace.
138
+ */
139
+ const drawingTransformAttrsAreAdditive = () => 0;
140
+ /** The node type whose relationship and raw-XML attrs version 4 rewrites. */
141
+ const IMAGE_ELEMENT_NAME = "image";
142
+ /**
143
+ * Stands in for the capture marker a node migrated to `previewOnly` never had.
144
+ *
145
+ * `drawingFromImageAttrs` reads the marker's presence and never its value: the
146
+ * editor projection is lossy, so a value compared against the image rebuilt
147
+ * from it would report an untouched round trip as an edit. What the marker has
148
+ * to say here is that the node still holds the capture it was projected with,
149
+ * which is exactly the condition the step selects on.
150
+ */
151
+ const CARRIED_PREVIEW_CAPTURE = "carriedPreviewCapture";
152
+ /** Rewrite one stored image node, answering whether anything changed. */
153
+ const migrateImageNode = (node) => {
154
+ const attributes = node.getAttributes();
155
+ const rId = attributes["rId"];
156
+ const dropsEmptyId = rId === "";
157
+ const classifies = !(typeof rId === "string" && rId.length > 0) && typeof attributes["_docxRawXml"] === "string" && attributes["_docxRawXmlMode"] === void 0;
158
+ if (dropsEmptyId) node.removeAttribute("rId");
159
+ if (classifies) {
160
+ node.setAttribute("_docxRawXmlMode", DRAWING_RAW_XML_MODES.PREVIEW_ONLY);
161
+ node.setAttribute("_docxRawImageFingerprint", CARRIED_PREVIEW_CAPTURE);
162
+ }
163
+ return dropsEmptyId || classifies;
164
+ };
165
+ /**
166
+ * Version 3 spelled "this drawing carries no relationship" two ways.
167
+ *
168
+ * `rId: ""` is not a key any relationship answers to, so an image that stated
169
+ * it was a drawing with no relationship saying it had one: it reached a save
170
+ * as `r:embed=""`, and only the lookups that knew to ask about both spellings
171
+ * read it as the absence it was. The model has one spelling now, so the attr
172
+ * loses the other.
173
+ *
174
+ * The same pass classifies the drawings that spelling hid. A VML shape folio
175
+ * cannot project is carried as a render of its markup, and version 3 projected
176
+ * that render as an ordinary editable picture: an edit dropped the capture, and
177
+ * the save wrote the render into the package as a picture in place of the
178
+ * shape. An image node that holds a capture, names no relationship and states
179
+ * no mode is exactly that drawing, because every other captured drawing either
180
+ * names a relationship or states its mode. Still holding the capture is what
181
+ * says the node has not been edited, which is what the stamped marker means.
182
+ */
183
+ const classifyUnrelatedCapturedDrawings = (fragment) => {
184
+ let rewritten = 0;
185
+ const visit = (node) => {
186
+ if ("nodeName" in node && node.nodeName === IMAGE_ELEMENT_NAME && migrateImageNode(node)) rewritten += 1;
187
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
188
+ };
189
+ visit(fragment);
190
+ return rewritten;
191
+ };
192
+ /** The node types whose stated cell width version 5 backfills. */
193
+ const TABLE_CELL_ELEMENT_NAMES = /* @__PURE__ */ new Set(["tableCell", "tableHeader"]);
194
+ /** Write a node attribute the binding stores as JSON. */
195
+ const setJsonAttribute = (node, name, value) => {
196
+ node.setAttribute(name, value);
197
+ };
198
+ const statedWidthOf = (attributes) => {
199
+ const original = attributes["_originalFormatting"];
200
+ if (typeof original !== "object" || original === null || !("width" in original)) return;
201
+ const { width } = original;
202
+ if (typeof width !== "object" || width === null) return;
203
+ const value = attributes["width"];
204
+ return typeof value === "number" ? {
205
+ value,
206
+ type: attributes["widthType"] ?? Reflect.get(width, "type")
207
+ } : width;
208
+ };
209
+ /**
210
+ * Version 5 adds `_authoredWidth` to table cells. Version 4 wrote `w:tcW`
211
+ * from the resolved cell width, including cells that stated no preferred
212
+ * width. `_originalFormatting.width` records which cells authored one, so
213
+ * only those cells receive the new attr.
214
+ */
215
+ const backfillStatedCellWidths = (fragment) => {
216
+ let rewritten = 0;
217
+ const visit = (node) => {
218
+ if ("nodeName" in node && TABLE_CELL_ELEMENT_NAMES.has(node.nodeName)) {
219
+ const attributes = node.getAttributes();
220
+ const stated = statedWidthOf(attributes);
221
+ if (stated !== void 0) {
222
+ setJsonAttribute(node, "_authoredWidth", stated);
223
+ rewritten += 1;
224
+ }
225
+ }
226
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
227
+ };
228
+ visit(fragment);
229
+ return rewritten;
230
+ };
231
+ /**
232
+ * Version 6 gives `tableRow`'s `hidden` attr the `null` default the other
233
+ * tri-states carry. Up to version 5 it defaulted to `false`, and the reader
234
+ * that filled it took only an explicit on, so a row that authored
235
+ * `<w:hidden w:val="0"/>` and one that authored nothing were both stored as
236
+ * `false`. `false` therefore never meant an explicit off and cannot be kept as
237
+ * one: a version-5 snapshot's `false` would start writing an element the
238
+ * document never carried. The explicit offs it does hold travelled as captured
239
+ * bytes on `_originalFormatting`, which the step leaves alone.
240
+ */
241
+ const dropUnstatedRowHidden = (fragment) => {
242
+ let rewritten = 0;
243
+ const visit = (node) => {
244
+ if ("nodeName" in node && node.nodeName === "tableRow") {
245
+ if (node.getAttributes()["hidden"] === false) {
246
+ node.removeAttribute("hidden");
247
+ rewritten += 1;
248
+ }
249
+ }
250
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
251
+ };
252
+ visit(fragment);
253
+ return rewritten;
254
+ };
255
+ /**
256
+ * The `_propertyChanges` entries a paragraph carries, as a version-7 snapshot
257
+ * stored them: an array of records whose `previousFormatting` may carry the
258
+ * numbering the paragraph had before a `w:pPrChange`.
259
+ */
260
+ const versionSevenPropertyChanges = (value) => {
261
+ if (!Array.isArray(value)) return null;
262
+ const changes = [];
263
+ for (const change of value) {
264
+ if (typeof change !== "object" || change === null || Array.isArray(change)) return null;
265
+ changes.push(change);
266
+ }
267
+ return changes;
268
+ };
269
+ /** The two paragraph attrs, and the two formatting fields, that state numbering. */
270
+ const NUMBERING_ATTR_KEYS = ["numPr", "numPrFromStyle"];
271
+ /**
272
+ * One stored two-slot value, as the union. `null` is an object that stated
273
+ * neither slot, which stated nothing; `undefined` is a value this step must
274
+ * leave exactly as it found it.
275
+ *
276
+ * A value that already carries a `kind` is one of those. Version 7 wrote the
277
+ * model's union into `_originalFormatting` and into a recorded
278
+ * `currentFormatting` while the `numPr` attr beside them still held the two
279
+ * slots, so a version-7 paragraph can hold both spellings at once: that
280
+ * divergence is what version 8 exists to end.
281
+ */
282
+ const versionSevenNumbering = (value) => {
283
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
284
+ if (typeof Reflect.get(value, "kind") === "string") return;
285
+ const numId = Reflect.get(value, "numId");
286
+ const ilvl = Reflect.get(value, "ilvl");
287
+ return paragraphNumberingFromSlots({
288
+ ilvl: typeof ilvl === "number" ? ilvl : void 0,
289
+ numId: typeof numId === "number" ? numId : void 0
290
+ }) ?? null;
291
+ };
292
+ /**
293
+ * A stored formatting record with its numbering keys carried forward, or
294
+ * `null` when it holds nothing this step rewrites. `null` inside the record
295
+ * survives: in `previousFormatting` it is the tombstone for "the paragraph
296
+ * carried no numbering before the change".
297
+ */
298
+ const versionSevenFormatting = (value) => {
299
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
300
+ const stored = { ...value };
301
+ let changed = false;
302
+ for (const key of NUMBERING_ATTR_KEYS) {
303
+ const migrated = versionSevenNumbering(stored[key]);
304
+ if (migrated === void 0) continue;
305
+ changed = true;
306
+ if (migrated === null) Reflect.deleteProperty(stored, key);
307
+ else stored[key] = migrated;
308
+ }
309
+ return changed ? stored : null;
310
+ };
311
+ /**
312
+ * Version 7 stored `numPr` as the two `<w:numPr>` slots, with the reserved
313
+ * `numId` 0 for a cancellation and a bare `ilvl` for a level stated without an
314
+ * id. Version 8 stores the model's union, so the pair has to be mapped:
315
+ * `numId` 0 becomes `none` whatever level sat beside it (a cancellation names
316
+ * no id for a level to belong to), an `ilvl` without a `numId` becomes
317
+ * `levelOnly`, the two together become `reference`, and an object stating
318
+ * neither slot stated nothing is dropped. An absent attr stays absent.
319
+ *
320
+ * Like the version-7 step it cannot be left to a lazy read: ProseMirror copies
321
+ * a stored attr into the node without validating, and
322
+ * `optionalParagraphNumbering` would then refuse the first read of an
323
+ * untouched room.
324
+ */
325
+ const numberingBecomesAUnion = (fragment) => {
326
+ let rewritten = 0;
327
+ const visit = (node) => {
328
+ if ("nodeName" in node && node.nodeName === PARAGRAPH_ELEMENT_NAME) {
329
+ const attributes = node.getAttributes();
330
+ let changed = false;
331
+ for (const attr of NUMBERING_ATTR_KEYS) {
332
+ const migrated = versionSevenNumbering(attributes[attr]);
333
+ if (migrated === void 0) continue;
334
+ changed = true;
335
+ if (migrated === null) node.removeAttribute(attr);
336
+ else node.setAttribute(attr, migrated);
337
+ }
338
+ const originalFormatting = versionSevenFormatting(attributes["_originalFormatting"]);
339
+ if (originalFormatting !== null) {
340
+ changed = true;
341
+ node.setAttribute("_originalFormatting", originalFormatting);
342
+ }
343
+ const changes = versionSevenPropertyChanges(attributes["_propertyChanges"]);
344
+ if (changes !== null) {
345
+ let changesChanged = false;
346
+ const migratedChanges = [];
347
+ for (const change of changes) {
348
+ const migrated = Object.assign({}, change);
349
+ for (const tier of ["previousFormatting", "currentFormatting"]) {
350
+ const formatting = versionSevenFormatting(change[tier]);
351
+ if (formatting !== null) {
352
+ migrated[tier] = formatting;
353
+ changesChanged = true;
354
+ }
355
+ }
356
+ migratedChanges.push(migrated);
357
+ }
358
+ if (changesChanged) {
359
+ changed = true;
360
+ node.setAttribute("_propertyChanges", migratedChanges);
361
+ }
362
+ }
363
+ if (changed) rewritten += 1;
364
+ }
365
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
366
+ };
367
+ visit(fragment);
368
+ return rewritten;
369
+ };
370
+ /**
371
+ * Version 9 makes `_sectionProperties` the one carrier of a section break.
372
+ * Earlier snapshots could state `sectionBreakType` instead, and the save leg
373
+ * minted a `SectionProperties` from it. The attr is gone from the schema, so
374
+ * the migration must mint that record before ProseMirror drops the old key.
375
+ * A paragraph that already has the record keeps it as the authority.
376
+ */
377
+ const SECTION_BREAK_TYPE_ATTR = "sectionBreakType";
378
+ const SECTION_PROPERTIES_ATTR = "_sectionProperties";
379
+ const mintSectionPropertiesFromBreakType = (fragment) => {
380
+ let rewritten = 0;
381
+ const visit = (node) => {
382
+ if ("nodeName" in node && node.nodeName === PARAGRAPH_ELEMENT_NAME) {
383
+ const attributes = node.getAttributes();
384
+ if (SECTION_BREAK_TYPE_ATTR in attributes) {
385
+ const breakType = parseSectionBreakType(attributes[SECTION_BREAK_TYPE_ATTR]);
386
+ if (breakType !== null && attributes[SECTION_PROPERTIES_ATTR] == null) node.setAttribute(SECTION_PROPERTIES_ATTR, mintSectionProperties(breakType));
387
+ node.removeAttribute(SECTION_BREAK_TYPE_ATTR);
388
+ rewritten += 1;
389
+ }
390
+ }
391
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
392
+ };
393
+ visit(fragment);
394
+ return rewritten;
395
+ };
396
+ /** The node types whose `showingPlaceholder` attr version 10 rewrites. */
397
+ const SDT_ELEMENT_NAMES = /* @__PURE__ */ new Set(["sdt", "blockSdt"]);
398
+ /**
399
+ * Version 9 stored `showingPlaceholder` as a boolean defaulting to `false`.
400
+ * A control that authored an explicit off and one that authored nothing were
401
+ * both stored as `false`, so the old false cannot become a newly authored
402
+ * `<w:showingPlcHdr w:val="0"/>` when the absence is now `null`.
403
+ */
404
+ const dropUnstatedPlaceholderFlags = (fragment) => {
405
+ let rewritten = 0;
406
+ const visit = (node) => {
407
+ if ("nodeName" in node && SDT_ELEMENT_NAMES.has(node.nodeName)) {
408
+ if (node.getAttributes()["showingPlaceholder"] === false) {
409
+ node.removeAttribute("showingPlaceholder");
410
+ rewritten += 1;
411
+ }
412
+ }
413
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
414
+ };
415
+ visit(fragment);
416
+ return rewritten;
417
+ };
418
+ /**
419
+ * Version 11 renames the persisted `pageBreakRunOwner` mark to `runIdentity`.
420
+ * Unknown mark names make y-prosemirror delete their covered text, so the
421
+ * Y.Text delta must be rewritten before the ProseMirror document is built.
422
+ */
423
+ const renamePageBreakRunOwnerMarkAttr = (fragment) => {
424
+ const OLD_MARK_NAME = "pageBreakRunOwner";
425
+ const NEW_MARK_NAME = "runIdentity";
426
+ let rewritten = 0;
427
+ const rewriteText = (sharedText) => {
428
+ let index = 0;
429
+ const ranges = [];
430
+ for (const op of sharedText.toDelta()) {
431
+ const insert = op.insert;
432
+ const length = typeof insert === "string" ? insert.length : 1;
433
+ const attributes = op.attributes;
434
+ if (isRecord(attributes) && OLD_MARK_NAME in attributes) ranges.push({
435
+ at: index,
436
+ length,
437
+ owner: attributes[OLD_MARK_NAME]
438
+ });
439
+ index += length;
440
+ }
441
+ for (const { at, length, owner } of ranges) {
442
+ const identity = isRecord(owner) && typeof owner["id"] === "number" ? { id: owner["id"] } : {};
443
+ sharedText.format(at, length, {
444
+ [OLD_MARK_NAME]: null,
445
+ [NEW_MARK_NAME]: identity
446
+ });
447
+ rewritten += 1;
448
+ }
449
+ };
450
+ const visit = (node) => {
451
+ for (const child of node.toArray()) {
452
+ if (typeof child === "string") continue;
453
+ if (isXmlText(child)) {
454
+ rewriteText(child);
455
+ continue;
456
+ }
457
+ if ("toArray" in child) visit(child);
458
+ }
459
+ };
460
+ visit(fragment);
461
+ return rewritten;
462
+ };
463
+ /** Every attr-schema version this build reads, oldest first, with no gaps. */
464
+ const FOLIO_YJS_ATTR_SCHEMA_VERSIONS = [
465
+ 0,
466
+ 1,
467
+ 2,
468
+ 3,
469
+ 4,
470
+ 5,
471
+ 6,
472
+ 7,
473
+ 8,
474
+ 9,
475
+ 10,
476
+ 11
477
+ ];
478
+ /**
479
+ * The one place a persisted attr-shape change is decided.
480
+ *
481
+ * Changing the shape of any node or mark attr Folio persists means: append the
482
+ * new version to {@link FOLIO_YJS_ATTR_SCHEMA_VERSIONS}, map the previous
483
+ * version to the step that rewrites it, and map the new version to `"current"`.
484
+ * The map is total over the version union, so a version added without a
485
+ * decision does not compile, and `migrateFolioYjsSnapshot` picks the new step
486
+ * up without being touched.
487
+ */
488
+ const ATTR_SCHEMA_MIGRATIONS = {
489
+ 0: stampMarkerOnly,
490
+ 1: dropUnstatedFieldFlags,
491
+ 2: drawingTransformAttrsAreAdditive,
492
+ 3: classifyUnrelatedCapturedDrawings,
493
+ 4: backfillStatedCellWidths,
494
+ 5: dropUnstatedRowHidden,
495
+ 6: outlineLevelBecomesAUnion,
496
+ 7: numberingBecomesAUnion,
497
+ 8: mintSectionPropertiesFromBreakType,
498
+ 9: dropUnstatedPlaceholderFlags,
499
+ 10: renamePageBreakRunOwnerMarkAttr,
500
+ 11: "current"
501
+ };
502
+ /**
503
+ * The attr-schema version this build writes. Derived against the migration map
504
+ * so the constant and the map cannot disagree.
505
+ */
506
+ const FOLIO_YJS_ATTR_SCHEMA_VERSION = 11;
507
+ /**
508
+ * The steps that carry a snapshot written under `fromVersion` up to
509
+ * {@link FOLIO_YJS_ATTR_SCHEMA_VERSION}, in order. Empty when the snapshot is
510
+ * already current.
511
+ */
512
+ const attrSchemaMigrationSteps = (fromVersion) => FOLIO_YJS_ATTR_SCHEMA_VERSIONS.filter((version) => version >= fromVersion).flatMap((version) => {
513
+ const step = ATTR_SCHEMA_MIGRATIONS[version];
514
+ return step === "current" ? [] : [step];
515
+ });
516
+ /**
517
+ * Carry a fragment this build is about to read or write up to the attr shape
518
+ * this build writes, and stamp the marker.
519
+ *
520
+ * Every entry point that hands a fragment to `initProseMirrorDoc` calls this,
521
+ * for two reasons that are the same reason. A step that rewrites values has to
522
+ * run before a node is built from them, or the build reads the old shape as
523
+ * the new one. And the marker has to say what the fragment may now hold before
524
+ * the first edit writes an attr of this build's shape into it, because an
525
+ * older build reading an unmarked snapshot drops what it does not know without
526
+ * a trace.
527
+ *
528
+ * Returns how many elements the steps rewrote.
529
+ */
530
+ const applyAttrSchemaMigrations = (ydoc, fragment, fromVersion) => {
531
+ if (fromVersion === 11) return 0;
532
+ let rewritten = 0;
533
+ ydoc.transact(() => {
534
+ for (const step of attrSchemaMigrationSteps(fromVersion)) rewritten += step(fragment);
535
+ writeYjsAttrSchemaVersion(ydoc);
536
+ });
537
+ return rewritten;
538
+ };
539
+ /** Raised when a snapshot's attr-schema marker is ahead of the running code. */
540
+ var FolioYjsAttrSchemaVersionError = class extends TaggedError("FolioYjsAttrSchemaVersionError") {};
541
+ const isReadableVersion = (marker) => typeof marker === "number" && Number.isInteger(marker) && marker >= 0 && marker <= 11;
542
+ /**
543
+ * The attr-schema version a collaboration document was written under.
544
+ *
545
+ * An absent marker is version 0: every snapshot predates the marker, so no
546
+ * backfill is needed to classify one. An older version loads, because
547
+ * {@link attrSchemaMigrationSteps} says what it means. A marker this
548
+ * build does not know is a snapshot written by newer code, and reading it would
549
+ * be a silent misread: ProseMirror copies unknown attr values into the node
550
+ * verbatim and drops unknown keys without a trace. It fails instead.
551
+ */
552
+ const readYjsAttrSchemaVersion = (ydoc) => {
553
+ const marker = ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).get(ATTR_SCHEMA_VERSION_KEY);
554
+ if (marker === void 0) return Result.ok(0);
555
+ if (isReadableVersion(marker)) return Result.ok(marker);
556
+ return Result.err(new FolioYjsAttrSchemaVersionError({
557
+ marker,
558
+ message: "The collaboration snapshot was written by a newer Folio attr schema than this build reads.",
559
+ supportedVersion: 11
560
+ }));
561
+ };
562
+ const proseDocumentParagraphSourceContract = (document) => {
563
+ return getProseDocumentParagraphPropertySourceContract(document);
564
+ };
565
+ /** Stamp the attr-schema version of the build that wrote the current fragment. */
566
+ const writeYjsAttrSchemaVersion = (ydoc) => {
567
+ ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).set(ATTR_SCHEMA_VERSION_KEY, 11);
568
+ };
569
+ /**
570
+ * Write both metadata bindings for a freshly seeded collaboration document.
571
+ * The attr-schema version is written unconditionally; the paragraph-source
572
+ * contract only when the seeding document carries one, because a document
573
+ * built in memory rather than parsed from a package has no source to bind to.
574
+ */
575
+ const writeYjsDocumentMetadata = (ydoc, document) => {
576
+ writeYjsAttrSchemaVersion(ydoc);
577
+ const contract = proseDocumentParagraphSourceContract(document);
578
+ if (contract) ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).set(PARAGRAPH_SOURCE_CONTRACT_KEY, contract);
579
+ };
580
+ const readYjsParagraphSourceContract = (ydoc) => {
581
+ const contract = ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).get(PARAGRAPH_SOURCE_CONTRACT_KEY);
582
+ return typeof contract === "string" ? contract : null;
583
+ };
584
+ const withParagraphSourceContract = (document, contract) => {
585
+ if (document.type.name !== "doc") panic("A paragraph-property source contract can only attach to a document node");
586
+ return document.type.create({
587
+ ...document.attrs,
588
+ [PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR]: contract
589
+ }, document.content, document.marks);
590
+ };
591
+ //#endregion
592
+ export { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersionError, applyAttrSchemaMigrations, attrSchemaMigrationSteps, proseDocumentParagraphSourceContract, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract, writeYjsAttrSchemaVersion, writeYjsDocumentMetadata };
@@ -1,9 +1,15 @@
1
1
  import { BOOKMARK_BOUNDARY_NODE_NAME } from "./extensions/nodes/BookmarkBoundaryExtension.js";
2
+ import { COMMENT_REFERENCE_NODE_NAME } from "./extensions/nodes/CommentReferenceExtension.js";
3
+ import { MOVE_RANGE_BOUNDARY_NODE_NAME } from "./extensions/nodes/MoveRangeBoundaryExtension.js";
4
+ import { RANGE_ANCHOR_NODE_NAME } from "./extensions/nodes/RangeAnchorExtension.js";
2
5
  import { RENDERED_PAGE_BREAK_NODE_NAME } from "./extensions/nodes/RenderedPageBreakExtension.js";
3
6
  import { TEXT_BOX_ANCHOR_NODE_NAME } from "./extensions/nodes/TextBoxAnchorExtension.js";
4
7
  //#region src/prosemirror/zeroWidthAnchors.ts
5
8
  const ZERO_WIDTH_ANCHOR_NODE_NAMES = /* @__PURE__ */ new Set([
6
9
  BOOKMARK_BOUNDARY_NODE_NAME,
10
+ COMMENT_REFERENCE_NODE_NAME,
11
+ MOVE_RANGE_BOUNDARY_NODE_NAME,
12
+ RANGE_ANCHOR_NODE_NAME,
7
13
  RENDERED_PAGE_BREAK_NODE_NAME,
8
14
  TEXT_BOX_ANCHOR_NODE_NAME
9
15
  ]);