@stll/folio-core 0.52.0 → 0.54.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 (389) hide show
  1. package/README.md +23 -0
  2. package/dist/ai-edits/apply.d.ts +26 -1
  3. package/dist/ai-edits/apply.js +1779 -141
  4. package/dist/ai-edits/batch-claims.d.ts +145 -0
  5. package/dist/ai-edits/batch-claims.js +275 -0
  6. package/dist/ai-edits/blockRange.js +9 -3
  7. package/dist/ai-edits/character-boundaries.d.ts +43 -0
  8. package/dist/ai-edits/character-boundaries.js +95 -0
  9. package/dist/ai-edits/clean-text.d.ts +33 -3
  10. package/dist/ai-edits/clean-text.js +52 -6
  11. package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
  12. package/dist/ai-edits/comment-lifecycle.js +52 -0
  13. package/dist/ai-edits/headless.d.ts +91 -7
  14. package/dist/ai-edits/headless.js +520 -51
  15. package/dist/ai-edits/index.d.ts +2 -1
  16. package/dist/ai-edits/index.js +2 -1
  17. package/dist/ai-edits/minimal-replacement.d.ts +21 -6
  18. package/dist/ai-edits/minimal-replacement.js +134 -15
  19. package/dist/ai-edits/newListNumbering.d.ts +23 -0
  20. package/dist/ai-edits/newListNumbering.js +94 -0
  21. package/dist/ai-edits/note-references.d.ts +96 -0
  22. package/dist/ai-edits/note-references.js +139 -0
  23. package/dist/ai-edits/pending-suggestions.d.ts +79 -0
  24. package/dist/ai-edits/pending-suggestions.js +306 -0
  25. package/dist/ai-edits/read.d.ts +6 -4
  26. package/dist/ai-edits/read.js +113 -50
  27. package/dist/ai-edits/result-validation.d.ts +29 -0
  28. package/dist/ai-edits/result-validation.js +164 -0
  29. package/dist/ai-edits/revisionStretches.d.ts +17 -0
  30. package/dist/ai-edits/revisionStretches.js +80 -0
  31. package/dist/ai-edits/snapshot.d.ts +36 -3
  32. package/dist/ai-edits/snapshot.js +180 -25
  33. package/dist/ai-edits/table-cell-mutations.d.ts +4 -2
  34. package/dist/ai-edits/table-cell-mutations.js +6 -2
  35. package/dist/ai-edits/table-geometry.d.ts +1 -1
  36. package/dist/ai-edits/table-row-column-mutations.d.ts +44 -17
  37. package/dist/ai-edits/table-row-column-mutations.js +86 -34
  38. package/dist/ai-edits/types.d.ts +155 -16
  39. package/dist/compare/compare.d.ts +1 -1
  40. package/dist/compare/compare.js +65 -16
  41. package/dist/compare/content-alignment.d.ts +5 -1
  42. package/dist/compare/content-alignment.js +52 -34
  43. package/dist/compare/content-types.d.ts +7 -0
  44. package/dist/compare/content.d.ts +4 -1
  45. package/dist/compare/content.js +6 -1
  46. package/dist/compare/formatting.js +2 -1
  47. package/dist/compare/inline-atoms.d.ts +21 -4
  48. package/dist/compare/inline-atoms.js +138 -16
  49. package/dist/compare/inline-provenance.js +1 -1
  50. package/dist/compare/plan.js +10 -5
  51. package/dist/compare/scenario.js +14 -3
  52. package/dist/compare/section-boundary-properties.js +1 -1
  53. package/dist/compare/types.d.ts +4 -2
  54. package/dist/compare/types.js +2 -1
  55. package/dist/compare/verification.d.ts +1 -1
  56. package/dist/compare/verification.js +15 -3
  57. package/dist/controller/committedLayoutDiff.d.ts +25 -0
  58. package/dist/controller/committedLayoutDiff.js +71 -0
  59. package/dist/controller/contentControlWidgetController.d.ts +1 -1
  60. package/dist/controller/folioEditor.d.ts +1 -1
  61. package/dist/controller/fontReadiness.d.ts +70 -3
  62. package/dist/controller/fontReadiness.js +100 -10
  63. package/dist/controller/headerFooterEditorManager.js +6 -1
  64. package/dist/controller/layoutPipeline.d.ts +12 -10
  65. package/dist/controller/layoutPipeline.js +65 -11
  66. package/dist/controller/layoutRunOptions.d.ts +24 -0
  67. package/dist/controller/layoutRunOptions.js +17 -0
  68. package/dist/controller/layoutScheduler.d.ts +19 -14
  69. package/dist/controller/layoutScheduler.js +15 -12
  70. package/dist/controller/layoutSession.d.ts +26 -2
  71. package/dist/controller/layoutSession.js +1 -1
  72. package/dist/controller/noteEditorManager.js +8 -3
  73. package/dist/document-operations.d.ts +11 -2
  74. package/dist/document-operations.js +230 -21
  75. package/dist/docx/altChunk.d.ts +8 -0
  76. package/dist/docx/altChunk.js +17 -0
  77. package/dist/docx/archiveInflation.d.ts +127 -0
  78. package/dist/docx/archiveInflation.js +181 -0
  79. package/dist/docx/attributeRemainder.d.ts +1 -1
  80. package/dist/docx/blockContentParser.d.ts +64 -1
  81. package/dist/docx/blockContentParser.js +17 -4
  82. package/dist/docx/blockCustomXmlShell.d.ts +7 -0
  83. package/dist/docx/blockCustomXmlShell.js +14 -0
  84. package/dist/docx/blockPlainText.js +7 -0
  85. package/dist/docx/commentAnchorIndex.js +1 -1
  86. package/dist/docx/commentRangeIntegrity.js +8 -3
  87. package/dist/docx/commentReferenceNormalization.js +1 -1
  88. package/dist/docx/commentReplyMarkers.js +20 -1
  89. package/dist/docx/compatibility.d.ts +1 -1
  90. package/dist/docx/compatibility.js +34 -13
  91. package/dist/docx/containerChildren.gen.d.ts +1 -1
  92. package/dist/docx/containerChildren.gen.js +1 -0
  93. package/dist/docx/documentParser.js +12 -12
  94. package/dist/docx/drawingIdNormalization.d.ts +3 -1
  95. package/dist/docx/drawingIdNormalization.js +6 -1
  96. package/dist/docx/ensureParaIds.js +119 -97
  97. package/dist/docx/footnoteParser.js +8 -4
  98. package/dist/docx/headerFooterParser.js +3 -3
  99. package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
  100. package/dist/docx/headerFooterReferenceNormalization.js +52 -27
  101. package/dist/docx/hyperlinkParser.d.ts +1 -1
  102. package/dist/docx/index.d.ts +1 -1
  103. package/dist/docx/listNumberingInstances.d.ts +59 -0
  104. package/dist/docx/listNumberingInstances.js +249 -0
  105. package/dist/docx/metadataPrivacy.js +24 -1
  106. package/dist/docx/normalizeBaseDirection.js +2 -1
  107. package/dist/docx/noteReferenceMark.d.ts +15 -0
  108. package/dist/docx/noteReferenceMark.js +48 -0
  109. package/dist/docx/opaqueCarrier.d.ts +7 -0
  110. package/dist/docx/opaqueCarrier.js +38 -0
  111. package/dist/docx/packageParts.js +4 -1
  112. package/dist/docx/paragraphParser.js +96 -27
  113. package/dist/docx/paragraphPropertySource.d.ts +4 -2
  114. package/dist/docx/paragraphPropertySource.js +10 -2
  115. package/dist/docx/paragraphTraversal.js +1 -0
  116. package/dist/docx/parseWarningMessage.js +4 -1
  117. package/dist/docx/parser.js +175 -22
  118. package/dist/docx/rezip.js +31 -7
  119. package/dist/docx/sdtProperties.js +1 -1
  120. package/dist/docx/sdtPropertiesPatch.js +3 -0
  121. package/dist/docx/selectiveSave.js +16 -9
  122. package/dist/docx/selectiveXmlPatch.d.ts +3 -1
  123. package/dist/docx/selectiveXmlPatch.js +186 -39
  124. package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
  125. package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
  126. package/dist/docx/serializer/documentSerializer.js +2 -0
  127. package/dist/docx/serializer/headerFooterSerializer.js +2 -0
  128. package/dist/docx/serializer/noteSerializer.js +3 -1
  129. package/dist/docx/serializer/paragraphSerializer.js +33 -9
  130. package/dist/docx/serializer/tableSerializer.js +25 -38
  131. package/dist/docx/server/boundedArchive.d.ts +8 -13
  132. package/dist/docx/server/boundedArchive.js +70 -59
  133. package/dist/docx/server/createBilingualDocument.js +3 -3
  134. package/dist/docx/server/extractDocxText.d.ts +8 -2
  135. package/dist/docx/server/extractDocxText.js +2 -2
  136. package/dist/docx/server/validateDocxConformance.d.ts +1 -1
  137. package/dist/docx/server/validateDocxConformance.js +1 -0
  138. package/dist/docx/tableParser.d.ts +157 -1
  139. package/dist/docx/tableParser.js +89 -10
  140. package/dist/docx/textBoxParser.js +1 -1
  141. package/dist/docx/unzip.d.ts +20 -2
  142. package/dist/docx/unzip.js +136 -25
  143. package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
  144. package/dist/docx/wordprocessingPrefixes.js +286 -0
  145. package/dist/fonts/embeddedFonts.js +1 -1
  146. package/dist/i18n/messages/catalogs.gen.d.ts +170 -34
  147. package/dist/i18n/messages/catalogs.gen.js +187 -51
  148. package/dist/i18n/messages/messages.gen.d.ts +10 -2
  149. package/dist/internal/compare/inline-presentation.d.ts +2 -1
  150. package/dist/internal/compare/inline-presentation.js +11 -10
  151. package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
  152. package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
  153. package/dist/internal/indexedPositionMap.d.ts +11 -0
  154. package/dist/internal/indexedPositionMap.js +42 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
  156. package/dist/internal/revisionResolutionEdits.d.ts +13 -0
  157. package/dist/internal/revisionResolutionEdits.js +19 -0
  158. package/dist/internal/revisionResolutionInline.d.ts +24 -0
  159. package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
  160. package/dist/internal/revisionResolutionStep.d.ts +34 -0
  161. package/dist/internal/revisionResolutionStep.js +282 -0
  162. package/dist/internal/revisionResolutionTracking.d.ts +11 -0
  163. package/dist/internal/revisionResolutionTracking.js +124 -0
  164. package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
  165. package/dist/internal/wholeStoryRevisionResolution.js +600 -0
  166. package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
  167. package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
  168. package/dist/layout-bridge/convert/tableConversion.js +1 -1
  169. package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
  170. package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
  171. package/dist/layout-engine/layoutInstrumentation.js +4 -1
  172. package/dist/layout-engine/measure/cache.d.ts +18 -1
  173. package/dist/layout-engine/measure/cache.js +31 -1
  174. package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
  175. package/dist/layout-engine/measure/measureContainer.js +7 -47
  176. package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
  177. package/dist/layout-engine/measure/measureHelpers.js +22 -2
  178. package/dist/layout-engine/measure/measureParagraph.js +2 -2
  179. package/dist/layout-engine/measure/measureWorker.js +2 -3
  180. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
  181. package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
  182. package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
  183. package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
  184. package/dist/layout-engine/types.d.ts +6 -0
  185. package/dist/layout-painter/renderPage.js +1 -0
  186. package/dist/layout-painter/renderParagraph.js +1 -1
  187. package/dist/managers/ContextMenuManager.js +5 -2
  188. package/dist/managers/types.d.ts +3 -0
  189. package/dist/markdown/escape.d.ts +2 -2
  190. package/dist/markdown/escape.js +4 -5
  191. package/dist/markdown/fromMarkdown.js +2 -1
  192. package/dist/markdown/internals.d.ts +11 -1
  193. package/dist/markdown/internals.js +24 -3
  194. package/dist/markdown/renderBlock.js +121 -25
  195. package/dist/markdown/renderParagraph.d.ts +13 -1
  196. package/dist/markdown/renderParagraph.js +85 -38
  197. package/dist/markdown/renderRuns.d.ts +10 -1
  198. package/dist/markdown/renderRuns.js +323 -69
  199. package/dist/markdown/renderTable.js +24 -12
  200. package/dist/markdown/trailers.js +2 -2
  201. package/dist/markdown/types.d.ts +29 -7
  202. package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
  203. package/dist/paged-layout/incrementalMeasure.js +1 -9
  204. package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
  205. package/dist/paged-layout/transactionDirtyRange.js +29 -41
  206. package/dist/panel-layout.d.ts +83 -0
  207. package/dist/panel-layout.js +96 -0
  208. package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
  209. package/dist/prosemirror/anchoredTextBoxes.js +156 -0
  210. package/dist/prosemirror/attrs/index.d.ts +6 -2
  211. package/dist/prosemirror/attrs/index.js +172 -1
  212. package/dist/prosemirror/clearRunColor.d.ts +6 -0
  213. package/dist/prosemirror/clearRunColor.js +46 -0
  214. package/dist/prosemirror/commands/comments.d.ts +7 -8
  215. package/dist/prosemirror/commands/comments.js +281 -212
  216. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  217. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  218. package/dist/prosemirror/commands/formatPainter.js +1 -1
  219. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  220. package/dist/prosemirror/commands/hyperlink.js +2 -1
  221. package/dist/prosemirror/commands/index.d.ts +2 -2
  222. package/dist/prosemirror/commands/index.js +2 -2
  223. package/dist/prosemirror/commands/paragraph.d.ts +7 -1
  224. package/dist/prosemirror/commands/paragraph.js +9 -1
  225. package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
  226. package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
  227. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  228. package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
  229. package/dist/prosemirror/commands/propertyChangeScope.js +24 -3
  230. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
  231. package/dist/prosemirror/commands/resolveAllTableChanges.js +620 -0
  232. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
  233. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
  234. package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
  235. package/dist/prosemirror/commands/resolveParagraphProperties.js +73 -0
  236. package/dist/prosemirror/commands/sectionBreak.js +2 -1
  237. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +15 -2
  238. package/dist/prosemirror/commands/tableCellMergeResolution.js +23 -7
  239. package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
  240. package/dist/prosemirror/containerFinalParagraph.js +7 -6
  241. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  242. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
  243. package/dist/prosemirror/conversion/fromProseDoc.js +177 -605
  244. package/dist/prosemirror/conversion/toProseDoc.d.ts +4 -11
  245. package/dist/prosemirror/conversion/toProseDoc.js +70 -154
  246. package/dist/prosemirror/documentSchema.d.ts +8 -0
  247. package/dist/prosemirror/documentSchema.js +18 -0
  248. package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
  249. package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
  250. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  251. package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
  252. package/dist/prosemirror/extensions/StarterKit.js +5 -1
  253. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  254. package/dist/prosemirror/extensions/core/ParagraphExtension.js +116 -63
  255. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +4 -1
  256. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
  257. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
  258. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
  259. package/dist/prosemirror/extensions/features/ListExtension.js +167 -128
  260. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
  261. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
  262. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
  263. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
  264. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
  265. package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
  266. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  267. package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
  268. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +124 -0
  269. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +33 -11
  270. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
  271. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
  272. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
  273. package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
  274. package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
  275. package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
  276. package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
  277. package/dist/prosemirror/extensions/marks/markUtils.d.ts +15 -8
  278. package/dist/prosemirror/extensions/marks/markUtils.js +25 -10
  279. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +12 -0
  280. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +46 -0
  281. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
  282. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
  283. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
  284. package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
  285. package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
  286. package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
  287. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
  288. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  289. package/dist/prosemirror/extensions/nodes/TableExtension.js +121 -226
  290. package/dist/prosemirror/extensions/types.d.ts +11 -1
  291. package/dist/prosemirror/findReplaceSelection.js +1 -1
  292. package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
  293. package/dist/prosemirror/hyperlinkRemoval.js +129 -0
  294. package/dist/prosemirror/index.d.ts +5 -3
  295. package/dist/prosemirror/index.js +5 -3
  296. package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
  297. package/dist/prosemirror/indexedNodeLookup.js +103 -0
  298. package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
  299. package/dist/prosemirror/listAutoformatMarkers.js +98 -0
  300. package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
  301. package/dist/prosemirror/listInstanceReferences.js +72 -0
  302. package/dist/prosemirror/listLabels.d.ts +24 -0
  303. package/dist/prosemirror/listLabels.js +111 -0
  304. package/dist/prosemirror/listNumbering.d.ts +92 -0
  305. package/dist/prosemirror/listNumbering.js +330 -0
  306. package/dist/prosemirror/listRendering.d.ts +27 -0
  307. package/dist/prosemirror/listRendering.js +27 -0
  308. package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
  309. package/dist/prosemirror/listRenderingAttrs.js +8 -1
  310. package/dist/prosemirror/markupViewNotes.d.ts +8 -0
  311. package/dist/prosemirror/markupViewNotes.js +49 -0
  312. package/dist/prosemirror/markupViewProjection.d.ts +97 -0
  313. package/dist/prosemirror/markupViewProjection.js +88 -0
  314. package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
  315. package/dist/prosemirror/noteReferenceReview.js +332 -0
  316. package/dist/prosemirror/numberingAttr.d.ts +9 -1
  317. package/dist/prosemirror/numberingAttr.js +9 -1
  318. package/dist/prosemirror/outlineLevelAttr.js +1 -1
  319. package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
  320. package/dist/prosemirror/paragraphIndentation.js +32 -7
  321. package/dist/prosemirror/paragraphMarkJoin.d.ts +21 -0
  322. package/dist/prosemirror/paragraphMarkJoin.js +26 -0
  323. package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
  324. package/dist/prosemirror/paragraphPropertyCarry.js +158 -0
  325. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  326. package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
  327. package/dist/prosemirror/plugins/documentNumbering.js +97 -11
  328. package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
  329. package/dist/prosemirror/plugins/documentStyleState.js +32 -0
  330. package/dist/prosemirror/plugins/documentStyles.d.ts +3 -13
  331. package/dist/prosemirror/plugins/documentStyles.js +67 -17
  332. package/dist/prosemirror/plugins/index.d.ts +2 -1
  333. package/dist/prosemirror/plugins/index.js +2 -1
  334. package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
  335. package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
  336. package/dist/prosemirror/plugins/suggestionMode.d.ts +27 -3
  337. package/dist/prosemirror/plugins/suggestionMode.js +490 -63
  338. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  339. package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
  340. package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
  341. package/dist/prosemirror/positionSweep.d.ts +24 -0
  342. package/dist/prosemirror/positionSweep.js +222 -0
  343. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +23 -3
  344. package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
  345. package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
  346. package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
  347. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  348. package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
  349. package/dist/prosemirror/replacedAnnotations.js +170 -1
  350. package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
  351. package/dist/prosemirror/runFormattingFromMarks.js +567 -0
  352. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  353. package/dist/prosemirror/runFormattingReconciliation.js +10 -9
  354. package/dist/prosemirror/schema/index.d.ts +2 -2
  355. package/dist/prosemirror/schema/index.js +3 -0
  356. package/dist/prosemirror/schema/nodes.d.ts +44 -11
  357. package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
  358. package/dist/prosemirror/sectionMarkEdits.js +59 -0
  359. package/dist/prosemirror/storyListNumbering.d.ts +17 -0
  360. package/dist/prosemirror/storyListNumbering.js +102 -0
  361. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
  362. package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
  363. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
  364. package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
  365. package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
  366. package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
  367. package/dist/prosemirror/tableCellPaste.d.ts +74 -0
  368. package/dist/prosemirror/tableCellPaste.js +525 -0
  369. package/dist/prosemirror/tableGridMutation.d.ts +87 -2
  370. package/dist/prosemirror/tableGridMutation.js +255 -2
  371. package/dist/prosemirror/tableRunIn.d.ts +51 -0
  372. package/dist/prosemirror/tableRunIn.js +165 -0
  373. package/dist/prosemirror/textInput.js +11 -2
  374. package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
  375. package/dist/prosemirror/trackedRevisionPath.js +32 -0
  376. package/dist/prosemirror/validation.js +5 -1
  377. package/dist/redline.js +93 -9
  378. package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
  379. package/dist/render-dom/BodySelectionOverlay.js +3 -2
  380. package/dist/server.d.ts +2 -2
  381. package/dist/utils/findReplace.js +2 -2
  382. package/dist/utils/mergeDocumentContent.js +1 -1
  383. package/dist/utils/noteReferenceLabels.d.ts +36 -0
  384. package/dist/utils/noteReferenceLabels.js +32 -0
  385. package/dist/utils/replaceText.js +1 -1
  386. package/dist/version-comparison.d.ts +1 -0
  387. package/dist/version-comparison.js +1 -0
  388. package/package.json +6 -5
  389. package/dist/internal/headlessRevisionResolution.d.ts +0 -23
@@ -1,6 +1,54 @@
1
- import { Transaction } from "prosemirror-state";
2
1
  import { Node } from "prosemirror-model";
2
+ import { Transaction } from "prosemirror-state";
3
+ import { TableMap } from "prosemirror-tables";
3
4
  //#region src/prosemirror/tableGridMutation.d.ts
5
+ type RemoveTableRowOptions = {
6
+ map: TableMap;
7
+ table: Node;
8
+ tableStart: number;
9
+ };
10
+ /**
11
+ * Remove one row, keeping every vertical merge that touches it whole: a merge
12
+ * reaching through the row from above closes one row sooner, and a cell that
13
+ * starts in the row and spans down moves into the row below, one row shorter.
14
+ *
15
+ * `prosemirror-tables` exports the same operation as `removeRow`, but its walk
16
+ * across the row skips a cell's extra columns without moving its map index
17
+ * along with them, so after a cell wider than one column it reads the wrong
18
+ * slots: a merge reaching through the row further right is never shortened,
19
+ * and the table is left one row shorter than that merge.
20
+ */
21
+ declare const removeTableRow: (tr: Transaction, { map, table, tableStart }: RemoveTableRowOptions, row: number) => void;
22
+ /** Whether a batch of structural deletions may have emptied rows. */
23
+ type RowsEmptiedInBatch = {
24
+ pending: boolean;
25
+ };
26
+ type MarkRowEmptiedInBatchOptions = {
27
+ tr: Transaction;
28
+ rowPosition: number;
29
+ emptied: RowsEmptiedInBatch;
30
+ };
31
+ /** A transient row attribute follows node moves; conversion never serializes it. */
32
+ declare const markRowEmptiedInBatch: ({ tr, rowPosition, emptied }: MarkRowEmptiedInBatchOptions) => void;
33
+ type MarkRowsEmptiedInBatchOptions = {
34
+ tr: Transaction;
35
+ tablePosition: number;
36
+ previousTable: Node;
37
+ emptied: RowsEmptiedInBatch;
38
+ };
39
+ /** Column removal keeps row indices stable: mark only newly cell-less rows. */
40
+ declare const markRowsEmptiedInBatch: ({ tr, tablePosition, previousTable, emptied }: MarkRowsEmptiedInBatchOptions) => void;
41
+ /** Sweep current tables in reverse so moves cannot invalidate cleanup targets. */
42
+ declare const removeRowsWithoutCellsAfterBatch: (tr: Transaction, emptied: RowsEmptiedInBatch) => void;
43
+ type RemoveRowsWithoutCellsInRangeOptions = {
44
+ tr: Transaction;
45
+ from: number;
46
+ to: number;
47
+ };
48
+ /** Close marked rows before their owning cell is captured into a continuation payload. */
49
+ declare const removeRowsWithoutCellsInRange: ({ tr, from, to }: RemoveRowsWithoutCellsInRangeOptions) => void;
50
+ /** Close all cell-less rows after an immediate structural edit. */
51
+ declare const removeRowsWithoutCells: (tr: Transaction, tablePosition: number) => void;
4
52
  type ReconcileTableGridAfterColumnRemovalOptions = {
5
53
  tr: Transaction;
6
54
  tablePosition: number;
@@ -16,5 +64,42 @@ type ReconcileTableGridAfterColumnRemovalOptions = {
16
64
  * the old grid; reopening then has to interpret surviving cells as spans.
17
65
  */
18
66
  declare const reconcileTableGridAfterColumnRemoval: ({ tr, tablePosition, previousTable, removedColumn }: ReconcileTableGridAfterColumnRemovalOptions) => void;
67
+ type ReconcileTableGridAfterColumnInsertionOptions = {
68
+ tr: Transaction;
69
+ tablePosition: number;
70
+ previousTable: Node;
71
+ insertedColumn: number;
72
+ };
73
+ /**
74
+ * The same for a physical column insertion: the new grid column takes the
75
+ * width of the column beside it, and the table grows by it.
76
+ *
77
+ * Without it the table keeps the grid it had, so every row spans one column
78
+ * more than `w:tblGrid` declares.
79
+ */
80
+ declare const reconcileTableGridAfterColumnInsertion: ({ tr, tablePosition, previousTable, insertedColumn }: ReconcileTableGridAfterColumnInsertionOptions) => void;
81
+ type InsertTableColumnOptions = {
82
+ tr: Transaction;
83
+ tablePosition: number;
84
+ /** The grid column the new column takes; the columns from it on move right. */
85
+ column: number;
86
+ /** The grid column whose cells the new cells copy their formatting from. */
87
+ templateColumn: number;
88
+ /** A new, empty cell shaped after `template`, the row's cell in the template column. */
89
+ createCell: (template: Node | null) => Node;
90
+ };
91
+ /**
92
+ * Insert a grid column, walking the table map: each row gains a cell at the
93
+ * column's place in the grid (after any cell a merge from a row above holds
94
+ * there), a cell merged across that place widens instead, and `w:tblGrid`
95
+ * gains the column.
96
+ */
97
+ declare const insertTableColumn: ({ tr, tablePosition, column, templateColumn, createCell }: InsertTableColumnOptions) => void;
98
+ /**
99
+ * Remove grid columns [`left`, `right`), walking the table map: a cell only
100
+ * in them goes, a cell merged across them narrows, `w:tblGrid` loses them,
101
+ * and a row left without a cell of its own goes too.
102
+ */
103
+ declare const removeTableColumns: (tr: Transaction, tablePosition: number, left: number, right: number) => void;
19
104
  //#endregion
20
- export { reconcileTableGridAfterColumnRemoval };
105
+ export { RowsEmptiedInBatch, insertTableColumn, markRowEmptiedInBatch, markRowsEmptiedInBatch, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeRowsWithoutCellsAfterBatch, removeRowsWithoutCellsInRange, removeTableColumns, removeTableRow };
@@ -1,7 +1,124 @@
1
1
  import { expectTableAttrs, mergeTableAttrs } from "./attrs/index.js";
2
- import { TableMap } from "prosemirror-tables";
2
+ import { panic } from "better-result";
3
+ import { TableMap, removeColumn } from "prosemirror-tables";
3
4
  //#region src/prosemirror/tableGridMutation.ts
4
5
  /**
6
+ * Remove one row, keeping every vertical merge that touches it whole: a merge
7
+ * reaching through the row from above closes one row sooner, and a cell that
8
+ * starts in the row and spans down moves into the row below, one row shorter.
9
+ *
10
+ * `prosemirror-tables` exports the same operation as `removeRow`, but its walk
11
+ * across the row skips a cell's extra columns without moving its map index
12
+ * along with them, so after a cell wider than one column it reads the wrong
13
+ * slots: a merge reaching through the row further right is never shortened,
14
+ * and the table is left one row shorter than that merge.
15
+ */
16
+ const removeTableRow = (tr, { map, table, tableStart }, row) => {
17
+ let rowPosition = 0;
18
+ for (let index = 0; index < row; index++) rowPosition += table.child(index).nodeSize;
19
+ const nextRow = rowPosition + table.child(row).nodeSize;
20
+ const mapFrom = tr.mapping.maps.length;
21
+ tr.delete(tableStart + rowPosition, tableStart + nextRow);
22
+ for (let column = 0; column < map.width;) {
23
+ const index = row * map.width + column;
24
+ const position = map.map[index];
25
+ const cell = position === void 0 ? null : table.nodeAt(position);
26
+ if (position === void 0 || !cell) {
27
+ column += 1;
28
+ continue;
29
+ }
30
+ const colspan = Math.max(1, Number(cell.attrs["colspan"]) || 1);
31
+ const rowspan = Math.max(1, Number(cell.attrs["rowspan"]) || 1);
32
+ if (row > 0 && position === map.map[index - map.width]) tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(tableStart + position), null, {
33
+ ...cell.attrs,
34
+ rowspan: rowspan - 1
35
+ });
36
+ else if (row + 1 < map.height && position === map.map[index + map.width]) {
37
+ const moved = cell.type.create({
38
+ ...cell.attrs,
39
+ rowspan: rowspan - 1
40
+ }, cell.content);
41
+ const below = map.positionAt(row + 1, column, table);
42
+ tr.insert(tr.mapping.slice(mapFrom).map(tableStart + below), moved);
43
+ }
44
+ column += colspan;
45
+ }
46
+ };
47
+ const ROW_CLEANUP_PENDING = "pending";
48
+ /** A transient row attribute follows node moves; conversion never serializes it. */
49
+ const markRowEmptiedInBatch = ({ tr, rowPosition, emptied }) => {
50
+ const row = tr.doc.nodeAt(rowPosition);
51
+ if (!row || row.type.spec.attrs?.["_batchRowCleanup"] === void 0) panic("Batch row cleanup requires the table row cleanup attribute");
52
+ tr.setNodeAttribute(rowPosition, "_batchRowCleanup", ROW_CLEANUP_PENDING);
53
+ emptied.pending = true;
54
+ };
55
+ /** Column removal keeps row indices stable: mark only newly cell-less rows. */
56
+ const markRowsEmptiedInBatch = ({ tr, tablePosition, previousTable, emptied }) => {
57
+ const table = tr.doc.nodeAt(tablePosition);
58
+ if (!table || table.type.spec["tableRole"] !== "table") return;
59
+ table.forEach((row, offset, index) => {
60
+ if (row.childCount === 0 && previousTable.child(index).childCount > 0) markRowEmptiedInBatch({
61
+ tr,
62
+ rowPosition: tablePosition + 1 + offset,
63
+ emptied
64
+ });
65
+ });
66
+ };
67
+ const removeEmptyRows = ({ tr, tablePosition, shouldRemove }) => {
68
+ for (;;) {
69
+ const table = tr.doc.nodeAt(tablePosition);
70
+ if (!table || table.type.spec["tableRole"] !== "table" || table.childCount < 2) return;
71
+ let emptyRow = -1;
72
+ table.forEach((row, _offset, index) => {
73
+ if (emptyRow === -1 && row.childCount === 0 && shouldRemove(row)) emptyRow = index;
74
+ });
75
+ if (emptyRow === -1) return;
76
+ removeTableRow(tr, {
77
+ map: TableMap.get(table),
78
+ table,
79
+ tableStart: tablePosition + 1
80
+ }, emptyRow);
81
+ }
82
+ };
83
+ /** Remove only rows emptied by deletions in this transaction, then clear remaining markers. */
84
+ const removeBatchRows = (tr, tablePosition) => {
85
+ removeEmptyRows({
86
+ tr,
87
+ tablePosition,
88
+ shouldRemove: (row) => row.attrs["_batchRowCleanup"] === ROW_CLEANUP_PENDING
89
+ });
90
+ tr.doc.nodeAt(tablePosition)?.forEach((row, offset) => {
91
+ if (row.attrs["_batchRowCleanup"] === ROW_CLEANUP_PENDING) tr.setNodeAttribute(tablePosition + 1 + offset, "_batchRowCleanup", null);
92
+ });
93
+ };
94
+ /** Sweep current tables in reverse so moves cannot invalidate cleanup targets. */
95
+ const removeRowsWithoutCellsAfterBatch = (tr, emptied) => {
96
+ if (!emptied.pending) return;
97
+ const tables = [];
98
+ tr.doc.descendants((node, position) => {
99
+ if (node.type.spec["tableRole"] === "table") tables.push(position);
100
+ return !node.isTextblock;
101
+ });
102
+ for (const position of tables.toReversed()) removeBatchRows(tr, position);
103
+ };
104
+ /** Close marked rows before their owning cell is captured into a continuation payload. */
105
+ const removeRowsWithoutCellsInRange = ({ tr, from, to }) => {
106
+ const tables = [];
107
+ tr.doc.nodesBetween(from, to, (node, position) => {
108
+ if (position >= from && node.type.spec["tableRole"] === "table") tables.push(position);
109
+ return !node.isTextblock;
110
+ });
111
+ for (const position of tables.toReversed()) removeBatchRows(tr, position);
112
+ };
113
+ /** Close all cell-less rows after an immediate structural edit. */
114
+ const removeRowsWithoutCells = (tr, tablePosition) => {
115
+ removeEmptyRows({
116
+ tr,
117
+ tablePosition,
118
+ shouldRemove: () => true
119
+ });
120
+ };
121
+ /**
5
122
  * Keep the editable table grid aligned with a physical column removal.
6
123
  *
7
124
  * `prosemirror-tables` owns cell topology, but Folio separately retains the
@@ -18,6 +135,63 @@ const reconcileTableGridAfterColumnRemoval = ({ tr, tablePosition, previousTable
18
135
  const removedColumnCount = previousColumnCount - columnCount;
19
136
  const previousWidths = expectTableAttrs(previousTable).columnWidths;
20
137
  const columnWidths = previousWidths?.length === previousColumnCount ? previousWidths.toSpliced(removedColumn, removedColumnCount) : void 0;
138
+ setTableGrid({
139
+ tr,
140
+ tablePosition,
141
+ table,
142
+ columnWidths,
143
+ columnCount
144
+ });
145
+ };
146
+ /**
147
+ * The same for a physical column insertion: the new grid column takes the
148
+ * width of the column beside it, and the table grows by it.
149
+ *
150
+ * Without it the table keeps the grid it had, so every row spans one column
151
+ * more than `w:tblGrid` declares.
152
+ */
153
+ const reconcileTableGridAfterColumnInsertion = ({ tr, tablePosition, previousTable, insertedColumn }) => {
154
+ const previousColumnCount = TableMap.get(previousTable).width;
155
+ const table = tr.doc.nodeAt(tablePosition);
156
+ if (!table || table.type.spec["tableRole"] !== "table") return;
157
+ const columnCount = TableMap.get(table).width;
158
+ if (columnCount <= previousColumnCount) return;
159
+ const insertedColumnCount = columnCount - previousColumnCount;
160
+ const previousWidths = expectTableAttrs(previousTable).columnWidths;
161
+ const neighbourWidth = insertedColumnWidth(previousTable, insertedColumn);
162
+ const columnWidths = previousWidths?.length === previousColumnCount && neighbourWidth !== void 0 ? previousWidths.toSpliced(insertedColumn, 0, ...Array.from({ length: insertedColumnCount }, () => neighbourWidth)) : void 0;
163
+ setTableGrid({
164
+ tr,
165
+ tablePosition,
166
+ table,
167
+ columnWidths,
168
+ columnCount
169
+ });
170
+ };
171
+ /** The width a column inserted at `insertedColumn` takes: its left neighbour's, when the grid is known. */
172
+ const insertedColumnWidth = (table, insertedColumn) => {
173
+ const columnCount = TableMap.get(table).width;
174
+ const widths = expectTableAttrs(table).columnWidths;
175
+ if (widths?.length !== columnCount) return;
176
+ return widths[Math.max(0, Math.min(insertedColumn, columnCount) - 1)] ?? widths[0];
177
+ };
178
+ /**
179
+ * Give a cell whose span grew or shrank the matching rendered width: its
180
+ * resolved twips width moves by `delta`. Layout falls back to cell widths
181
+ * when the grid is unknown, so a merged cell must not keep its old one. A
182
+ * percentage width, and the authored `w:tcW` kept beside it, stay as they are.
183
+ */
184
+ const resizeCellWidth = (tr, position, delta) => {
185
+ const cell = tr.doc.nodeAt(position);
186
+ const width = cell?.attrs["width"];
187
+ const widthType = cell?.attrs["widthType"];
188
+ if (!cell || delta === 0 || typeof width !== "number" || widthType !== null && widthType !== void 0 && widthType !== "dxa") return;
189
+ tr.setNodeMarkup(position, null, {
190
+ ...cell.attrs,
191
+ width: Math.max(1, width + delta)
192
+ });
193
+ };
194
+ const setTableGrid = ({ tr, tablePosition, table, columnWidths, columnCount }) => {
21
195
  const formatting = expectTableAttrs(table)._originalFormatting;
22
196
  const originalFormatting = formatting ? { ...formatting } : void 0;
23
197
  if (originalFormatting) delete originalFormatting.gridSourceXml;
@@ -26,5 +200,84 @@ const reconcileTableGridAfterColumnRemoval = ({ tr, tablePosition, previousTable
26
200
  _originalFormatting: originalFormatting
27
201
  }));
28
202
  };
203
+ /**
204
+ * Insert a grid column, walking the table map: each row gains a cell at the
205
+ * column's place in the grid (after any cell a merge from a row above holds
206
+ * there), a cell merged across that place widens instead, and `w:tblGrid`
207
+ * gains the column.
208
+ */
209
+ const insertTableColumn = ({ tr, tablePosition, column, templateColumn, createCell }) => {
210
+ const table = tr.doc.nodeAt(tablePosition);
211
+ if (!table || table.type.spec["tableRole"] !== "table") return;
212
+ const map = TableMap.get(table);
213
+ const tableStart = tablePosition + 1;
214
+ const mapFrom = tr.mapping.maps.length;
215
+ const addedWidth = insertedColumnWidth(table, column) ?? 0;
216
+ for (let row = 0; row < map.height; row++) {
217
+ const index = row * map.width + column;
218
+ const position = map.map[index];
219
+ const straddling = column > 0 && column < map.width && position !== void 0 && map.map[index - 1] === position ? table.nodeAt(position) : null;
220
+ if (straddling && position !== void 0) {
221
+ const offset = column - map.colCount(position);
222
+ const colwidth = straddling.attrs["colwidth"];
223
+ const mapped = tr.mapping.slice(mapFrom).map(tableStart + position);
224
+ tr.setNodeMarkup(mapped, null, {
225
+ ...straddling.attrs,
226
+ colspan: (Number(straddling.attrs["colspan"]) || 1) + 1,
227
+ colwidth: Array.isArray(colwidth) ? colwidth.toSpliced(offset, 0, 0) : colwidth
228
+ });
229
+ resizeCellWidth(tr, mapped, addedWidth);
230
+ row += (Number(straddling.attrs["rowspan"]) || 1) - 1;
231
+ continue;
232
+ }
233
+ const templatePosition = map.map[row * map.width + templateColumn];
234
+ const template = templatePosition === void 0 ? null : table.nodeAt(templatePosition);
235
+ tr.insert(tr.mapping.slice(mapFrom).map(tableStart + map.positionAt(row, column, table)), createCell(template));
236
+ }
237
+ reconcileTableGridAfterColumnInsertion({
238
+ tr,
239
+ tablePosition,
240
+ previousTable: table,
241
+ insertedColumn: column
242
+ });
243
+ };
244
+ /**
245
+ * Remove grid columns [`left`, `right`), walking the table map: a cell only
246
+ * in them goes, a cell merged across them narrows, `w:tblGrid` loses them,
247
+ * and a row left without a cell of its own goes too.
248
+ */
249
+ const removeTableColumns = (tr, tablePosition, left, right) => {
250
+ for (let column = right - 1; column >= left; column--) {
251
+ const table = tr.doc.nodeAt(tablePosition);
252
+ if (!table || table.type.spec["tableRole"] !== "table") return;
253
+ const map = TableMap.get(table);
254
+ const widths = expectTableAttrs(table).columnWidths;
255
+ const removedWidth = widths?.length === map.width ? widths[column] ?? 0 : 0;
256
+ const narrowed = /* @__PURE__ */ new Set();
257
+ for (let row = 0; row < map.height; row++) {
258
+ const index = row * map.width + column;
259
+ const position = map.map[index];
260
+ if (position !== void 0 && (column > 0 && map.map[index - 1] === position || column < map.width - 1 && map.map[index + 1] === position)) narrowed.add(position);
261
+ }
262
+ const mapFrom = tr.mapping.maps.length;
263
+ removeColumn(tr, {
264
+ map,
265
+ table,
266
+ tableStart: tablePosition + 1,
267
+ left: column,
268
+ right: column + 1,
269
+ top: 0,
270
+ bottom: map.height
271
+ }, column);
272
+ for (const position of narrowed) resizeCellWidth(tr, tr.mapping.slice(mapFrom).map(tablePosition + 1 + position), -removedWidth);
273
+ reconcileTableGridAfterColumnRemoval({
274
+ tr,
275
+ tablePosition,
276
+ previousTable: table,
277
+ removedColumn: column
278
+ });
279
+ }
280
+ removeRowsWithoutCells(tr, tablePosition);
281
+ };
29
282
  //#endregion
30
- export { reconcileTableGridAfterColumnRemoval };
283
+ export { insertTableColumn, markRowEmptiedInBatch, markRowsEmptiedInBatch, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeRowsWithoutCellsAfterBatch, removeRowsWithoutCellsInRange, removeTableColumns, removeTableRow };
@@ -0,0 +1,51 @@
1
+ import { RunStyleResolver } from "./runStyleFormatting.js";
2
+ import { ParagraphPropertySourceTransfer } from "../docx/paragraphPropertySource.js";
3
+ import { MarkType, Node } from "prosemirror-model";
4
+ import { StepMap, Transform } from "prosemirror-transform";
5
+ //#region src/prosemirror/tableRunIn.d.ts
6
+ /**
7
+ * Whether the cell a paragraph's words would run into is itself pending: its
8
+ * row or the cell (through nested tables' first cells) is inserted, deleted
9
+ * or merged, so resolving may not keep it. Pending rows or cells elsewhere in
10
+ * the table leave that cell where it is.
11
+ */
12
+ declare const runInCellPending: (table: Node) => boolean;
13
+ type RunParagraphIntoTableOptions = {
14
+ tr: Transform;
15
+ paragraphPos: number;
16
+ styleResolver: RunStyleResolver | null;
17
+ /** Content a resolution in progress removes: it does not count as words left. */
18
+ removedMark?: MarkType | undefined;
19
+ };
20
+ /**
21
+ * Run the paragraph at `paragraphPos` on into the table right after it.
22
+ * Returns where the paragraph that took its words now starts and the
23
+ * paragraph-property source it hands over, or null when it did not run in and
24
+ * the caller keeps its own handling.
25
+ */
26
+ declare const runParagraphIntoTable: ({ tr, paragraphPos, styleResolver, removedMark }: RunParagraphIntoTableOptions) => {
27
+ position: number;
28
+ map: StepMap;
29
+ transfer: ParagraphPropertySourceTransfer;
30
+ } | null;
31
+ /**
32
+ * Whether resolving every change in `mode` runs `paragraph` on into `next`:
33
+ * its mark goes and `next` is a table.
34
+ */
35
+ declare const runsIntoFollowingTable: (paragraph: Node, next: Node | null | undefined, mode: "accept" | "reject") => boolean;
36
+ /**
37
+ * Before every change in a story is resolved: run each paragraph whose mark
38
+ * goes and that sits right before a table on into that table. Returns each
39
+ * paragraph that took words (its position after the step count given) and
40
+ * the paragraph-property sources handed over.
41
+ */
42
+ declare const runParagraphsIntoTables: (tr: Transform, mode: "accept" | "reject", styleResolver: RunStyleResolver | null) => {
43
+ targets: {
44
+ position: number;
45
+ step: number;
46
+ }[];
47
+ maps: StepMap[];
48
+ transfers: ParagraphPropertySourceTransfer[];
49
+ };
50
+ //#endregion
51
+ export { runInCellPending, runParagraphIntoTable, runParagraphsIntoTables, runsIntoFollowingTable };
@@ -0,0 +1,165 @@
1
+ import { getProseParagraphPropertySourceToken, recreateProseNodeWithParagraphPropertySource } from "../docx/paragraphPropertySource.js";
2
+ import { expectParagraphAttrs } from "./attrs/index.js";
3
+ import { rebaseParagraphRuns } from "./rebaseParagraphRunFormatting.js";
4
+ import { paragraphRunStyleContext } from "./runStyleFormatting.js";
5
+ import { holdsNoContent } from "./zeroWidthAnchors.js";
6
+ import { Fragment, Slice } from "prosemirror-model";
7
+ import { ReplaceAroundStep, StepMap } from "prosemirror-transform";
8
+ //#region src/prosemirror/tableRunIn.ts
9
+ /**
10
+ * A paragraph whose mark goes, right before a table.
11
+ *
12
+ * With its mark gone a paragraph runs on into what follows it. When that is a
13
+ * table, its words run on into the table's first cell: they lead that cell's
14
+ * first paragraph, which is the paragraph left, with its identity and
15
+ * properties. What the removed paragraph's style lent its runs is re-read in
16
+ * that paragraph's style, as in any join.
17
+ *
18
+ * A paragraph with nothing left to carry is simply removed by the resolvers;
19
+ * one that ends a section keeps its place, as does one before a table whose
20
+ * rows or cells are themselves pending.
21
+ */
22
+ /**
23
+ * Whether the cell a paragraph's words would run into is itself pending: its
24
+ * row or the cell (through nested tables' first cells) is inserted, deleted
25
+ * or merged, so resolving may not keep it. Pending rows or cells elsewhere in
26
+ * the table leave that cell where it is.
27
+ */
28
+ const runInCellPending = (table) => {
29
+ let node = table;
30
+ while (node?.type.spec["tableRole"] === "table") {
31
+ const row = node.firstChild;
32
+ if (!row) return false;
33
+ if (row.attrs["trIns"] != null || row.attrs["trDel"] != null) return true;
34
+ const cell = row.firstChild;
35
+ if (!cell) return false;
36
+ if (cell.attrs["cellMarker"] != null) return true;
37
+ node = cell.firstChild;
38
+ }
39
+ return false;
40
+ };
41
+ /** The first paragraph of a table's first cell, descending into nested tables. */
42
+ const runInTarget = (doc, tablePos) => {
43
+ let node = doc.nodeAt(tablePos);
44
+ let pos = tablePos;
45
+ const table = node;
46
+ const firstRow = table?.firstChild;
47
+ if (!table || table.type.spec["tableRole"] !== "table" || !firstRow) return null;
48
+ if (runInCellPending(table)) return null;
49
+ while (node && node.type.name !== "paragraph") {
50
+ const child = node.firstChild;
51
+ if (!child || child.isInline) return null;
52
+ pos += 1;
53
+ node = child;
54
+ }
55
+ return node ? {
56
+ pos,
57
+ node
58
+ } : null;
59
+ };
60
+ /**
61
+ * Run the paragraph at `paragraphPos` on into the table right after it.
62
+ * Returns where the paragraph that took its words now starts and the
63
+ * paragraph-property source it hands over, or null when it did not run in and
64
+ * the caller keeps its own handling.
65
+ */
66
+ const runParagraphIntoTable = ({ tr, paragraphPos, styleResolver, removedMark }) => {
67
+ const paragraph = tr.doc.nodeAt(paragraphPos);
68
+ if (paragraph?.type.name !== "paragraph") return null;
69
+ if (expectParagraphAttrs(paragraph)._sectionProperties !== void 0) return null;
70
+ if (holdsNoContent(removedMark ? paragraph.copy(Fragment.fromArray(paragraph.children.filter((child) => !removedMark.isInSet(child.marks)))) : paragraph)) return null;
71
+ const tablePos = paragraphPos + paragraph.nodeSize;
72
+ const target = runInTarget(tr.doc, tablePos);
73
+ if (!target) return null;
74
+ const $target = tr.doc.resolve(target.pos + 1);
75
+ const containerDepth = tr.doc.resolve(paragraphPos).depth;
76
+ let opening = Fragment.empty;
77
+ for (let depth = $target.depth; depth > containerDepth; depth--) opening = Fragment.from(recreateProseNodeWithParagraphPropertySource($target.node(depth), { content: opening }));
78
+ const levels = $target.depth - containerDepth;
79
+ tr.step(new ReplaceAroundStep(paragraphPos, target.pos + 1, paragraphPos + 1, paragraphPos + paragraph.nodeSize - 1, new Slice(opening, 0, levels), levels, true));
80
+ const position = paragraphPos + levels - 1;
81
+ if (styleResolver && paragraph.content.size > 0) rebaseParagraphRuns({
82
+ previousContext: paragraphRunStyleContext(paragraph, styleResolver),
83
+ paragraphPosition: position,
84
+ range: {
85
+ from: 0,
86
+ to: paragraph.content.size
87
+ },
88
+ styleResolver,
89
+ tr
90
+ });
91
+ const displaced = getProseParagraphPropertySourceToken(paragraph);
92
+ const selected = getProseParagraphPropertySourceToken(target.node);
93
+ const closing = paragraphPos + paragraph.nodeSize - 1;
94
+ return {
95
+ position,
96
+ map: new StepMap([
97
+ paragraphPos,
98
+ 0,
99
+ levels - 1,
100
+ closing,
101
+ target.pos + 1 - closing,
102
+ 0
103
+ ]),
104
+ transfer: {
105
+ displacedToken: typeof displaced === "string" ? displaced : null,
106
+ selectedToken: typeof selected === "string" ? selected : null
107
+ }
108
+ };
109
+ };
110
+ /** Whether resolving every change in `mode` removes this paragraph's mark. */
111
+ const markGoes = (paragraph, mode) => {
112
+ const mark = expectParagraphAttrs(paragraph).pPrMark;
113
+ if (!mark) return false;
114
+ return (mark.kind === "ins" || mark.kind === "moveTo") !== (mode === "accept");
115
+ };
116
+ /**
117
+ * Whether resolving every change in `mode` runs `paragraph` on into `next`:
118
+ * its mark goes and `next` is a table.
119
+ */
120
+ const runsIntoFollowingTable = (paragraph, next, mode) => paragraph.type.name === "paragraph" && next?.type.spec["tableRole"] === "table" && markGoes(paragraph, mode);
121
+ /**
122
+ * Before every change in a story is resolved: run each paragraph whose mark
123
+ * goes and that sits right before a table on into that table. Returns each
124
+ * paragraph that took words (its position after the step count given) and
125
+ * the paragraph-property sources handed over.
126
+ */
127
+ const runParagraphsIntoTables = (tr, mode, styleResolver) => {
128
+ const removedMark = tr.doc.type.schema.marks[mode === "accept" ? "deletion" : "insertion"];
129
+ const tried = /* @__PURE__ */ new Set();
130
+ const targets = [];
131
+ const transfers = [];
132
+ const maps = [];
133
+ for (;;) {
134
+ let candidate = null;
135
+ tr.doc.descendants((node, pos, parent, index) => {
136
+ if (node.type.name !== "paragraph") return !node.isTextblock;
137
+ const next = parent?.maybeChild(index + 1);
138
+ if (runsIntoFollowingTable(node, next, mode) && !tried.has(pos)) candidate = pos;
139
+ return false;
140
+ });
141
+ if (candidate === null) return {
142
+ targets,
143
+ maps,
144
+ transfers
145
+ };
146
+ tried.add(candidate);
147
+ const ranIn = runParagraphIntoTable({
148
+ tr,
149
+ paragraphPos: candidate,
150
+ styleResolver,
151
+ removedMark
152
+ });
153
+ if (ranIn !== null) {
154
+ targets.push({
155
+ position: ranIn.position,
156
+ step: tr.steps.length
157
+ });
158
+ transfers.push(ranIn.transfer);
159
+ maps.push(ranIn.map);
160
+ tried.clear();
161
+ }
162
+ }
163
+ };
164
+ //#endregion
165
+ export { runInCellPending, runParagraphIntoTable, runParagraphsIntoTables, runsIntoFollowingTable };
@@ -1,9 +1,18 @@
1
- import { Plugin } from "prosemirror-state";
1
+ import { AllSelection, Plugin, Selection, TextSelection } from "prosemirror-state";
2
2
  //#region src/prosemirror/textInput.ts
3
3
  const dispatchEditorTextInput = (view, input) => {
4
4
  const { from, to } = typeof input === "string" ? view.state.selection : input;
5
5
  const text = typeof input === "string" ? input : input.text;
6
- const defaultTransaction = () => view.state.tr.insertText(text, from, to);
6
+ const defaultTransaction = () => {
7
+ if (!(view.state.selection instanceof AllSelection)) return view.state.tr.insertText(text, from, to);
8
+ const start = Selection.atStart(view.state.doc);
9
+ const end = Selection.atEnd(view.state.doc);
10
+ const last = end.$to.parent;
11
+ const tr = view.state.tr.insertText(text, start.from, end.to);
12
+ const $typed = tr.doc.resolve(start.from);
13
+ if (start.$from.parent.type.name === "paragraph" && last.type.name === "paragraph" && $typed.parent.type.name === "paragraph" && start.$from.parent !== last) tr.setNodeMarkup($typed.before(), void 0, last.attrs);
14
+ return tr.setSelection(TextSelection.create(tr.doc, start.from + text.length));
15
+ };
7
16
  if (!view.someProp("handleTextInput", (handler) => handler(view, from, to, text, defaultTransaction))) view.dispatch(defaultTransaction());
8
17
  };
9
18
  const replacementSelection = (view, event) => {
@@ -0,0 +1,17 @@
1
+ import { InlineWrapperLayer, TrackedRevisionAncestor } from "./schema/marks.js";
2
+ import { Mark, Node } from "prosemirror-model";
3
+ //#region src/prosemirror/trackedRevisionPath.d.ts
4
+ /** The wrappers `node` sits inside, outermost first; empty when it sits in none. */
5
+ declare const inlineWrapperStackOf: (node: Node) => readonly InlineWrapperLayer[];
6
+ /** One layer of the path used to write and enumerate a tracked run. */
7
+ declare const trackedRevisionLayerOf: (mark: Mark, node: Node) => TrackedRevisionAncestor;
8
+ type EnclosingInsertionAncestorsOptions = {
9
+ /** The insertion a deletion mark shares its text with, if any. */
10
+ insertionMark: Mark | undefined;
11
+ ancestors: readonly TrackedRevisionAncestor[];
12
+ node: Node;
13
+ };
14
+ /** The deletion's ancestor path, with the insertion it sits in as the outermost layer. */
15
+ declare const enclosingInsertionAncestors: ({ insertionMark, ancestors, node }: EnclosingInsertionAncestorsOptions) => readonly TrackedRevisionAncestor[];
16
+ //#endregion
17
+ export { enclosingInsertionAncestors, inlineWrapperStackOf, trackedRevisionLayerOf };
@@ -0,0 +1,32 @@
1
+ import { expectInlineWrapperMarkAttrs, expectTrackedChangeMarkAttrs } from "./attrs/index.js";
2
+ import { INLINE_WRAPPER_MARK_NAME } from "./extensions/marks/InlineWrapperExtension.js";
3
+ //#region src/prosemirror/trackedRevisionPath.ts
4
+ /** The wrappers `node` sits inside, outermost first; empty when it sits in none. */
5
+ const inlineWrapperStackOf = (node) => {
6
+ const mark = node.marks.find((candidate) => candidate.type.name === INLINE_WRAPPER_MARK_NAME);
7
+ return mark ? expectInlineWrapperMarkAttrs(mark).stack : [];
8
+ };
9
+ /** One layer of the path used to write and enumerate a tracked run. */
10
+ const trackedRevisionLayerOf = (mark, node) => {
11
+ const attrs = expectTrackedChangeMarkAttrs(mark);
12
+ const type = mark.type.name === "insertion" ? "insertion" : "deletion";
13
+ const moveType = type === "insertion" ? "moveTo" : "moveFrom";
14
+ return {
15
+ type: attrs.moveKind === moveType ? moveType : type,
16
+ revisionId: attrs.revisionId,
17
+ author: attrs.author || "Unknown",
18
+ ...attrs.date ? { date: attrs.date } : {},
19
+ ...attrs.utcDate ? { utcDate: attrs.utcDate } : {},
20
+ ...attrs.initials ? { initials: attrs.initials } : {},
21
+ outerWrapperCount: attrs._docxOuterWrapperCount ?? inlineWrapperStackOf(node).length
22
+ };
23
+ };
24
+ /** The deletion's ancestor path, with the insertion it sits in as the outermost layer. */
25
+ const enclosingInsertionAncestors = ({ insertionMark, ancestors, node }) => {
26
+ if (!insertionMark) return ancestors;
27
+ const attrs = expectTrackedChangeMarkAttrs(insertionMark);
28
+ if (ancestors.some(({ revisionId }) => revisionId === attrs.revisionId)) return ancestors;
29
+ return [trackedRevisionLayerOf(insertionMark, node), ...ancestors];
30
+ };
31
+ //#endregion
32
+ export { enclosingInsertionAncestors, inlineWrapperStackOf, trackedRevisionLayerOf };