@stll/folio-core 0.66.2 → 0.68.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 (323) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +138 -17
  3. package/dist/ai-edits/batch-claims.js +5 -3
  4. package/dist/ai-edits/clean-text.js +4 -1
  5. package/dist/ai-edits/headless.d.ts +36 -21
  6. package/dist/ai-edits/headless.js +104 -34
  7. package/dist/ai-edits/index.d.ts +2 -2
  8. package/dist/ai-edits/note-references.d.ts +6 -0
  9. package/dist/ai-edits/note-references.js +7 -1
  10. package/dist/ai-edits/read.d.ts +19 -0
  11. package/dist/ai-edits/read.js +6 -4
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +32 -17
  14. package/dist/ai-edits/table-cell-mutations.js +3 -2
  15. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  16. package/dist/ai-edits/types.d.ts +9 -1
  17. package/dist/ai-suggestions/apply.js +13 -4
  18. package/dist/compare/compare.js +2 -1
  19. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  20. package/dist/compare/inserted-resource-snapshot.js +7 -3
  21. package/dist/controller/canonicalClipboard.js +29 -12
  22. package/dist/controller/canonicalComposition.d.ts +1 -1
  23. package/dist/controller/canonicalComposition.js +77 -19
  24. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  25. package/dist/controller/canonicalInlineProjection.js +192 -28
  26. package/dist/controller/canonicalInput.d.ts +2 -2
  27. package/dist/controller/canonicalInput.js +47 -2
  28. package/dist/controller/canonicalListRendering.d.ts +2 -1
  29. package/dist/controller/canonicalListRendering.js +1 -1
  30. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  31. package/dist/controller/canonicalLockGuard.js +88 -0
  32. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  33. package/dist/controller/canonicalPublicOperations.js +274 -20
  34. package/dist/controller/canonicalSession.d.ts +87 -7
  35. package/dist/controller/canonicalSession.js +328 -75
  36. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  37. package/dist/controller/canonicalStoryEditor.js +4 -3
  38. package/dist/controller/canonicalStructure.d.ts +2 -1
  39. package/dist/controller/canonicalStructure.js +129 -7
  40. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  41. package/dist/controller/contentControlWidgetController.js +13 -1
  42. package/dist/controller/folioEditor.js +1 -0
  43. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  44. package/dist/controller/headerFooterEditorManager.js +5 -5
  45. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  46. package/dist/controller/hiddenEditorApi.js +1 -0
  47. package/dist/controller/hiddenEditorManager.d.ts +10 -3
  48. package/dist/controller/hiddenEditorManager.js +94 -38
  49. package/dist/controller/layoutPipeline.d.ts +2 -0
  50. package/dist/controller/layoutPipeline.js +55 -18
  51. package/dist/controller/layoutSession.d.ts +1 -0
  52. package/dist/controller/noteEditorManager.d.ts +2 -2
  53. package/dist/controller/noteEditorManager.js +5 -5
  54. package/dist/display-list/build/pageFurniture.js +41 -19
  55. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  56. package/dist/display-list/build/tablePrimitives.js +49 -14
  57. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  58. package/dist/document-operations.d.ts +8 -0
  59. package/dist/document-operations.js +4 -3
  60. package/dist/docx/blockContentParser.d.ts +7 -3
  61. package/dist/docx/blockContentParser.js +2 -3
  62. package/dist/docx/blockPlainText.js +2 -0
  63. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  64. package/dist/docx/bookmarkRangeJoin.js +43 -0
  65. package/dist/docx/canonicalSave.js +5 -1
  66. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  67. package/dist/docx/canonicalSessionInput.js +7 -2
  68. package/dist/docx/chartPreview.d.ts +4 -1
  69. package/dist/docx/chartPreview.js +26 -15
  70. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  71. package/dist/docx/commentAnchorIndex.js +39 -11
  72. package/dist/docx/commentRangeIntegrity.js +30 -24
  73. package/dist/docx/commentRangeJoin.d.ts +4 -0
  74. package/dist/docx/commentRangeJoin.js +26 -12
  75. package/dist/docx/commentReferenceCompletion.js +5 -4
  76. package/dist/docx/commentReferenceNormalization.js +40 -18
  77. package/dist/docx/compatibility.js +9 -2
  78. package/dist/docx/containerChildren.js +22 -1
  79. package/dist/docx/encryption/compoundFile.js +9 -1
  80. package/dist/docx/encryption/encryptionInfo.js +16 -2
  81. package/dist/docx/ensureParaIds.js +46 -7
  82. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  83. package/dist/docx/ensureUniqueControlIds.js +110 -0
  84. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  85. package/dist/docx/headerFooterVerbatim.js +13 -2
  86. package/dist/docx/hostCommentThreads.d.ts +17 -0
  87. package/dist/docx/hostCommentThreads.js +49 -0
  88. package/dist/docx/hyperlinkParser.js +9 -2
  89. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  90. package/dist/docx/inlineWrapperContent.js +9 -2
  91. package/dist/docx/listMarkerComputation.d.ts +35 -1
  92. package/dist/docx/listMarkerComputation.js +39 -1
  93. package/dist/docx/listModelNormalization.d.ts +44 -1
  94. package/dist/docx/listModelNormalization.js +227 -96
  95. package/dist/docx/mainDocumentPart.d.ts +6 -0
  96. package/dist/docx/mainDocumentPart.js +65 -0
  97. package/dist/docx/markupRangeMarker.d.ts +14 -0
  98. package/dist/docx/markupRangeMarker.js +15 -1
  99. package/dist/docx/metadataPrivacy.js +43 -22
  100. package/dist/docx/normalizeBaseDirection.js +3 -1
  101. package/dist/docx/packageParts.d.ts +1 -1
  102. package/dist/docx/packageParts.js +10 -4
  103. package/dist/docx/paragraphParser.js +159 -48
  104. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  105. package/dist/docx/paragraphPropertySource.js +22 -1
  106. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  107. package/dist/docx/paragraphTraversal.js +2 -0
  108. package/dist/docx/parseWarningMessage.js +2 -1
  109. package/dist/docx/parser.js +6 -0
  110. package/dist/docx/previewBudget.d.ts +6 -0
  111. package/dist/docx/previewBudget.js +7 -1
  112. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  113. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  114. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  115. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  116. package/dist/docx/reviewResolutionProvenance.js +110 -25
  117. package/dist/docx/rezip.d.ts +6 -0
  118. package/dist/docx/rezip.js +42 -25
  119. package/dist/docx/selectiveSave.js +6 -10
  120. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  121. package/dist/docx/selectiveXmlPatch.js +11 -7
  122. package/dist/docx/serializer/documentSerializer.js +3 -1
  123. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  124. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  125. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  126. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  127. package/dist/docx/serializer/noteSerializer.js +23 -16
  128. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  129. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  130. package/dist/docx/serializer/runSerializer.js +2 -2
  131. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  132. package/dist/docx/serializer/tableSerializer.js +4 -2
  133. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  134. package/dist/docx/server/createBilingualDocument.js +27 -5
  135. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  136. package/dist/docx/sessionListPruning.d.ts +2 -0
  137. package/dist/docx/sessionListPruning.js +50 -0
  138. package/dist/docx/shapeAlternateContent.js +19 -0
  139. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  140. package/dist/docx/splitRevisionPieces.js +14 -0
  141. package/dist/docx/storyBlockReplay.js +4 -0
  142. package/dist/docx/structuralXmlPatch.js +19 -7
  143. package/dist/docx/tableParser.d.ts +6 -2
  144. package/dist/docx/tableParser.js +2 -3
  145. package/dist/docx/textBoxContentParser.d.ts +11 -0
  146. package/dist/docx/textBoxContentParser.js +51 -0
  147. package/dist/docx/textBoxParser.d.ts +0 -5
  148. package/dist/docx/textBoxParser.js +1 -23
  149. package/dist/docx/unzip.js +2 -0
  150. package/dist/docx/verticalMergeProjection.js +1 -1
  151. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  152. package/dist/fonts/fontsourceFaces.js +1 -7
  153. package/dist/i18n/messages/ar.gen.js +3 -0
  154. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  155. package/dist/i18n/messages/catalogs.gen.js +51 -0
  156. package/dist/i18n/messages/cs.gen.js +3 -0
  157. package/dist/i18n/messages/de.gen.js +3 -0
  158. package/dist/i18n/messages/en.gen.js +3 -0
  159. package/dist/i18n/messages/es.gen.js +3 -0
  160. package/dist/i18n/messages/et.gen.js +3 -0
  161. package/dist/i18n/messages/fr.gen.js +3 -0
  162. package/dist/i18n/messages/he.gen.js +3 -0
  163. package/dist/i18n/messages/hi.gen.js +3 -0
  164. package/dist/i18n/messages/hu.gen.js +3 -0
  165. package/dist/i18n/messages/lt.gen.js +3 -0
  166. package/dist/i18n/messages/lv.gen.js +3 -0
  167. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  168. package/dist/i18n/messages/pl.gen.js +3 -0
  169. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  170. package/dist/i18n/messages/sk.gen.js +3 -0
  171. package/dist/i18n/messages/tr.gen.js +3 -0
  172. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  173. package/dist/internal/acceptedBlockProjection.js +2 -0
  174. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  175. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  176. package/dist/internal/revisionResolutionInline.js +1 -2
  177. package/dist/internal/wholeStoryRevisionResolution.js +57 -12
  178. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  179. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  180. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  181. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  182. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  183. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  184. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  185. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  186. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  187. package/dist/layout-bridge/convert/tableConversion.js +25 -10
  188. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  189. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  190. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  191. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  192. package/dist/layout-bridge/engine/hitTest.js +9 -10
  193. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  194. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  195. package/dist/layout-engine/footnoteContinuation.js +210 -0
  196. package/dist/layout-engine/index.d.ts +2 -2
  197. package/dist/layout-engine/index.js +7 -2
  198. package/dist/layout-engine/measure/cache.js +10 -5
  199. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  200. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  201. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  202. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  203. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  204. package/dist/layout-engine/tableLayout.js +34 -7
  205. package/dist/layout-engine/tableRowBreak.d.ts +46 -0
  206. package/dist/layout-engine/tableRowBreak.js +193 -36
  207. package/dist/layout-engine/types.d.ts +43 -3
  208. package/dist/layout-painter/previewSvg.d.ts +8 -0
  209. package/dist/layout-painter/previewSvg.js +47 -0
  210. package/dist/layout-painter/renderImage.js +2 -1
  211. package/dist/layout-painter/renderPage.d.ts +5 -4
  212. package/dist/layout-painter/renderPage.js +52 -20
  213. package/dist/layout-painter/renderParagraph.js +3 -2
  214. package/dist/layout-painter/renderTable.d.ts +5 -2
  215. package/dist/layout-painter/renderTable.js +39 -22
  216. package/dist/managers/AutoSaveManager.d.ts +5 -1
  217. package/dist/managers/FindReplaceManager.js +3 -10
  218. package/dist/markdown/escape.d.ts +20 -1
  219. package/dist/markdown/escape.js +43 -1
  220. package/dist/markdown/renderBlock.js +4 -1
  221. package/dist/markdown/renderParagraph.js +13 -27
  222. package/dist/markdown/renderTable.js +6 -2
  223. package/dist/markdown/trailers.js +1 -0
  224. package/dist/pdf/images.d.ts +17 -1
  225. package/dist/pdf/images.js +22 -4
  226. package/dist/pdf/writePdf.js +4 -2
  227. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  228. package/dist/prosemirror/attrs/index.js +1 -0
  229. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  230. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  231. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  232. package/dist/prosemirror/commands/comments.d.ts +25 -0
  233. package/dist/prosemirror/commands/comments.js +122 -18
  234. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  235. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  236. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  237. package/dist/prosemirror/commands/index.d.ts +1 -1
  238. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  239. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  240. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  241. package/dist/prosemirror/commentIdAllocator.js +2 -2
  242. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  243. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  244. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  245. package/dist/prosemirror/commentReferenceIntegrity.js +22 -8
  246. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  247. package/dist/prosemirror/conversion/fromProseDoc.js +115 -35
  248. package/dist/prosemirror/conversion/index.d.ts +1 -1
  249. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  250. package/dist/prosemirror/conversion/toProseDoc.js +325 -55
  251. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  252. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  253. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  254. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  255. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  256. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  257. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  258. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  259. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  260. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  261. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  262. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  263. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  264. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  265. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  266. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  267. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  268. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  269. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  270. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  271. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  272. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  273. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  274. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  275. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  276. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  277. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  278. package/dist/prosemirror/extensions/nodes/TableExtension.js +119 -38
  279. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  280. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  281. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  282. package/dist/prosemirror/index.d.ts +2 -2
  283. package/dist/prosemirror/listLabels.js +3 -2
  284. package/dist/prosemirror/listNumbering.d.ts +6 -0
  285. package/dist/prosemirror/listNumbering.js +12 -9
  286. package/dist/prosemirror/lockedControls.d.ts +13 -0
  287. package/dist/prosemirror/lockedControls.js +106 -0
  288. package/dist/prosemirror/markupViewProjection.js +1 -1
  289. package/dist/prosemirror/noteReferenceReview.js +2 -2
  290. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  291. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  292. package/dist/prosemirror/plugins/suggestionMode.js +195 -30
  293. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  294. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  295. package/dist/prosemirror/replacedAnnotations.js +1 -0
  296. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  297. package/dist/prosemirror/rowGridOmissions.js +21 -0
  298. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  299. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  300. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  301. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  302. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  303. package/dist/prosemirror/runStyleFormatting.js +16 -13
  304. package/dist/prosemirror/schema/marks.d.ts +6 -0
  305. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  306. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  307. package/dist/prosemirror/tableGridMutation.js +118 -15
  308. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  309. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  310. package/dist/prosemirror/validation.js +2 -1
  311. package/dist/redline.js +23 -9
  312. package/dist/server.d.ts +2 -2
  313. package/dist/style-sets/extract.js +2 -2
  314. package/dist/types/canonicalCapabilities.d.ts +29 -8
  315. package/dist/types/canonicalCapabilities.js +13 -9
  316. package/dist/utils/cssString.d.ts +7 -0
  317. package/dist/utils/cssString.js +9 -0
  318. package/dist/utils/fontResolver.js +4 -1
  319. package/dist/utils/replaceText.d.ts +11 -0
  320. package/dist/utils/replaceText.js +39 -7
  321. package/dist/version-comparison.d.ts +9 -1
  322. package/dist/version-comparison.js +11 -5
  323. package/package.json +2 -2
@@ -0,0 +1,36 @@
1
+ import { isInlineAnchor } from "../extensions/nodes/inlineAnchorDom.js";
2
+ import { EditorState, TextSelection } from "prosemirror-state";
3
+ // src/prosemirror/commands/deleteBesideInlineAnchor.ts
4
+ /** The length of the first or last user-perceived character of `text`. */
5
+ const characterLength = (text, backward) => {
6
+ const segments = [...new Intl.Segmenter().segment(text)];
7
+ return (backward ? segments.at(-1) : segments.at(0))?.segment.length ?? 1;
8
+ };
9
+ /**
10
+ * Delete what the caret reaches past the inline anchors beside it.
11
+ *
12
+ * Left to the browser, the key removes the anchor's element, and the next DOM
13
+ * read loses the node: a bookmark or comment range, with the other half of its
14
+ * pair, while the text stays. Suggesting mode tracks the key before it gets here.
15
+ */
16
+ const deleteBesideInlineAnchor = (join, direction) => (state, dispatch, view) => {
17
+ const { selection, doc } = state;
18
+ if (!(selection instanceof TextSelection) || !selection.empty) return false;
19
+ const backward = direction === "backward";
20
+ const adjacent = (position) => {
21
+ const $position = doc.resolve(position);
22
+ return backward ? $position.nodeBefore : $position.nodeAfter;
23
+ };
24
+ let cursor = selection.from;
25
+ for (let node = adjacent(cursor); node && isInlineAnchor(node); node = adjacent(cursor)) cursor += backward ? -node.nodeSize : node.nodeSize;
26
+ if (cursor === selection.from) return false;
27
+ const next = adjacent(cursor);
28
+ if (!next) return join(EditorState.create({
29
+ doc,
30
+ selection: TextSelection.create(doc, cursor)
31
+ }), dispatch, view);
32
+ const size = next.isText ? characterLength(next.text ?? "", backward) : next.nodeSize;
33
+ dispatch?.(state.tr.delete(backward ? cursor - size : cursor, backward ? cursor : cursor + size).scrollIntoView());
34
+ return true;
35
+ };
36
+ export { deleteBesideInlineAnchor };
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
2
  import { TextColorAttrs } from "../schema/marks.js";
3
- import "../schema/index.js";
4
3
  import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
4
+ import "../schema/index.js";
5
5
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
6
6
  import { Mark } from "prosemirror-model";
7
7
  import { Command } from "prosemirror-state";
@@ -1,8 +1,8 @@
1
+ import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
1
2
  import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getStyleId } from "../extensions/core/ParagraphExtension.js";
2
3
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
3
4
  import { AcceptSuggestionOptions, FolioSuggestion, SuggestionAppliedAs, SuggestionKind, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
4
5
  import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
5
- import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
6
6
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
7
7
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
8
8
  import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
@@ -1,5 +1,6 @@
1
1
  import { Schema, Slice } from "prosemirror-model";
2
2
  import { Command } from "prosemirror-state";
3
+ import { EditorView } from "prosemirror-view";
3
4
  /**
4
5
  * Dispatched on the editor view DOM when the clipboard read behind a
5
6
  * "paste without formatting" keystroke fails (e.g. clipboard-read permission
@@ -18,6 +19,11 @@ export declare const CLIPBOARD_READ_ERROR_EVENT = "folio:clipboard-read-error";
18
19
  * editor's default text paste flows into the current line.
19
20
  */
20
21
  export declare function buildPlainTextSlice(text: string, schema: Schema): Slice;
22
+ /**
23
+ * Put plain text in place of the selection: through the session that owns the
24
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
25
+ */
26
+ export declare const pastePlainTextSlice: (view: EditorView, slice: Slice) => void;
21
27
  /**
22
28
  * Read the clipboard and insert it as unformatted text at the current selection.
23
29
  *
@@ -1,4 +1,5 @@
1
1
  import { dispatchClipboardIntent } from "../clipboardIntent.js";
2
+ import { handleSuggestionPaste, suggestionModeKey } from "../plugins/suggestionMode.js";
2
3
  import { Fragment, Slice } from "prosemirror-model";
3
4
  // src/prosemirror/commands/pastePlainText.ts
4
5
  /**
@@ -34,6 +35,16 @@ function buildPlainTextSlice(text, schema) {
34
35
  return Slice.maxOpen(Fragment.fromArray(paragraphs));
35
36
  }
36
37
  /**
38
+ * Put plain text in place of the selection: through the session that owns the
39
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
40
+ */
41
+ const pastePlainTextSlice = (view, slice) => {
42
+ if (dispatchClipboardIntent(view, slice) !== void 0) return;
43
+ const suggesting = suggestionModeKey.getState(view.state);
44
+ if (suggesting?.active && handleSuggestionPaste(view, slice, suggesting)) return;
45
+ view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
46
+ };
47
+ /**
37
48
  * Read the clipboard and insert it as unformatted text at the current selection.
38
49
  *
39
50
  * Dry-runnable per the ProseMirror command convention: applicability does not
@@ -54,8 +65,7 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
54
65
  const { schema } = state;
55
66
  navigator.clipboard.readText().then((text) => {
56
67
  if (!text || view.isDestroyed) return;
57
- const slice = buildPlainTextSlice(text, schema);
58
- if (dispatchClipboardIntent(view, slice) === void 0) view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
68
+ pastePlainTextSlice(view, buildPlainTextSlice(text, schema));
59
69
  }).catch((error) => {
60
70
  if (typeof CustomEvent === "function" && !view.isDestroyed) view.dom.dispatchEvent(new CustomEvent(CLIPBOARD_READ_ERROR_EVENT, {
61
71
  detail: { error },
@@ -64,4 +74,4 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
64
74
  });
65
75
  return true;
66
76
  };
67
- export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting };
77
+ export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pastePlainTextSlice, pasteWithoutFormatting };
@@ -376,6 +376,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
376
376
  const widthRemovals = [];
377
377
  let currentWidth = map.width;
378
378
  let removedCell = false;
379
+ const removedColumns = [];
379
380
  const deletedRows = /* @__PURE__ */ new Set();
380
381
  const byPosition = /* @__PURE__ */ new Map();
381
382
  const ordered = [];
@@ -387,7 +388,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
387
388
  const node = row.child(cellIndex);
388
389
  const rectangle = cellRectangle(cellOffset);
389
390
  const left = rectangle.left;
390
- for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
+ for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom && !node.attrs["_omittedGridSlot"]; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
392
  const initial = elementAt(elementAt(rowMetadata, rowIndex).cells, cellIndex);
392
393
  const entry = {
393
394
  node: mergeDecisions.origins.has(cellOffset) ? node.type.create(resolvedTableMergeOriginAttrs(node), node.content, node.marks) : node,
@@ -407,6 +408,9 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
407
408
  rowOffset += row.nodeSize;
408
409
  }
409
410
  for (const width of rowOccupancy) widthCounts.set(width, (widthCounts.get(width) ?? 0) + 1);
411
+ const spanOf = ({ node }) => Number(node.attrs["colspan"]) || 1;
412
+ const omittedIn = (rowIndex) => [...elementAt(rowCells, rowIndex).values()].filter(({ node }) => node.attrs["_omittedGridSlot"] != null);
413
+ currentWidth = Math.max(0, ...rowOccupancy);
410
414
  const changeRowWidth = (rowIndex, nextWidth) => {
411
415
  if (!elementAt(activeRows, rowIndex)) return;
412
416
  const previous = elementAt(rowOccupancy, rowIndex);
@@ -427,12 +431,13 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
427
431
  }, entry.node.content, entry.node.marks);
428
432
  } else {
429
433
  removedCell = true;
434
+ removedColumns.push(entry.left);
430
435
  const previousWidth = currentWidth;
431
436
  const rectangle = cellRectangle(entry.position);
432
437
  const colspan = rectangle.right - rectangle.left;
433
438
  for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) changeRowWidth(coveredRow, elementAt(rowOccupancy, coveredRow) - colspan);
434
439
  elementAt(rowCells, entry.row).delete(entry.left);
435
- if (elementAt(rowCells, entry.row).size === 0) {
440
+ if ([...elementAt(rowCells, entry.row).values()].every(({ node }) => node.attrs["_omittedGridSlot"] != null)) {
436
441
  deletedRows.add(entry.row);
437
442
  activeRows[entry.row] = false;
438
443
  const rowWidth = elementAt(rowOccupancy, entry.row);
@@ -530,6 +535,29 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
530
535
  _docxVMergeContinuationCells: remaining.length > 0 ? remaining : null
531
536
  }, entry.node.content, entry.node.marks);
532
537
  }
538
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
539
+ if (deletedRows.has(rowIndex)) continue;
540
+ const slots = omittedIn(rowIndex);
541
+ let excess = elementAt(rowOccupancy, rowIndex) + slots.reduce((total, slot) => total + spanOf(slot), 0) - currentWidth;
542
+ const atRemoval = ({ left, node }) => removedColumns.some((column) => column >= left && column < left + (Number(node.attrs["colspan"]) || 1));
543
+ const order = [...slots.filter(atRemoval), ...slots.filter((slot) => !atRemoval(slot)).toReversed()];
544
+ for (const slot of order) {
545
+ if (excess <= 0) break;
546
+ const span = spanOf(slot);
547
+ if (span <= excess) {
548
+ elementAt(rowCells, rowIndex).delete(slot.left);
549
+ removedCell = true;
550
+ excess -= span;
551
+ continue;
552
+ }
553
+ slot.touched = true;
554
+ slot.node = slot.node.type.create({
555
+ ...slot.node.attrs,
556
+ colspan: span - excess
557
+ }, slot.node.content, slot.node.marks);
558
+ excess = 0;
559
+ }
560
+ }
533
561
  if (deletedRows.size === rows.length) return {
534
562
  node: null,
535
563
  changed: true,
@@ -1,4 +1,4 @@
1
- import { expectCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
1
+ import { expectCommentRangeBoundaryAttrs, isCommentRangeBoundaryNode } from "./commentRangeBoundaryAttrs.js";
2
2
  import { maxAnnotationIdInDoc, seedRevisionIdsAbove } from "./plugins/revisionIds.js";
3
3
  import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
4
4
  import { TaggedError } from "better-result";
@@ -57,7 +57,7 @@ function seedCommentAllocator(allocator, comments, view) {
57
57
  const attrs = readRangeAnchorAttrs(node);
58
58
  if (attrs.ok && attrs.value.start.type === "commentRangeStart") allocator.seedAbove(attrs.value.start.id);
59
59
  }
60
- if (node.type.name === "commentRangeBoundary") allocator.seedAbove(expectCommentRangeBoundaryAttrs(node).marker.id);
60
+ if (isCommentRangeBoundaryNode(node)) allocator.seedAbove(expectCommentRangeBoundaryAttrs(node).marker.id);
61
61
  });
62
62
  max = Math.max(max, maxAnnotationIdInDoc(view.state.doc));
63
63
  }
@@ -8,6 +8,12 @@ type CommentRangeBoundaryMarker = Extract<ParagraphContent, {
8
8
  type CommentRangeBoundaryAttrs = {
9
9
  marker: CommentRangeBoundaryMarker;
10
10
  };
11
+ /**
12
+ * Whether a node is a comment range boundary, inside a paragraph or between
13
+ * blocks. Both carry the same marker, so every reader asks this rather than
14
+ * naming one of them.
15
+ */
16
+ export declare const isCommentRangeBoundaryNode: (node: Node) => boolean;
11
17
  export declare const readCommentRangeBoundaryMarker: (value: unknown) => CommentRangeBoundaryMarker | undefined;
12
18
  export declare const readCommentRangeBoundaryAttrs: (node: Node) => ReadProseMirrorAttrsResult<CommentRangeBoundaryAttrs>;
13
19
  export declare const expectCommentRangeBoundaryAttrs: (node: Node) => CommentRangeBoundaryAttrs;
@@ -2,6 +2,12 @@ import { isDisplacedByCustomXml } from "./bookmarkBoundaryAttrs.js";
2
2
  import { panic } from "better-result";
3
3
  // src/prosemirror/commentRangeBoundaryAttrs.ts
4
4
  const attrsCache = /* @__PURE__ */ new WeakMap();
5
+ /**
6
+ * Whether a node is a comment range boundary, inside a paragraph or between
7
+ * blocks. Both carry the same marker, so every reader asks this rather than
8
+ * naming one of them.
9
+ */
10
+ const isCommentRangeBoundaryNode = (node) => node.type.name === "commentRangeBoundary" || node.type.name === "blockCommentRangeBoundary";
5
11
  const isRecord = (value) => typeof value === "object" && value !== null;
6
12
  const readCommentRangeBoundaryMarker = (value) => {
7
13
  if (!isRecord(value)) return void 0;
@@ -18,9 +24,9 @@ const readCommentRangeBoundaryMarker = (value) => {
18
24
  };
19
25
  const readCommentRangeBoundaryAttrs = (node) => {
20
26
  const issues = [];
21
- if (node.type.name !== "commentRangeBoundary") issues.push({
27
+ if (!isCommentRangeBoundaryNode(node)) issues.push({
22
28
  path: "commentRangeBoundary.type.name",
23
- message: `Expected commentRangeBoundary, got ${node.type.name}.`
29
+ message: `Expected commentRangeBoundary or blockCommentRangeBoundary, got ${node.type.name}.`
24
30
  });
25
31
  const marker = readCommentRangeBoundaryMarker(node.attrs["marker"]);
26
32
  if (!marker) issues.push({
@@ -47,4 +53,4 @@ const expectCommentRangeBoundaryAttrs = (node) => {
47
53
  attrsCache.set(node, result.value);
48
54
  return result.value;
49
55
  };
50
- export { expectCommentRangeBoundaryAttrs, readCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker };
56
+ export { expectCommentRangeBoundaryAttrs, isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker };
@@ -40,6 +40,8 @@ export type CommentReferenceRepair = {
40
40
  type CommentReferenceRepairInput = {
41
41
  references: readonly CommentReferenceOccurrence[];
42
42
  markExtents: readonly CommentMarkExtent[];
43
+ /** Comments anchored by their reference alone, covering nothing before too. */
44
+ pointIds?: ReadonlySet<number>;
43
45
  };
44
46
  export declare const COMMENT_REFERENCE_NODE_NAME = "commentReference";
45
47
  /**
@@ -48,11 +50,15 @@ export declare const COMMENT_REFERENCE_NODE_NAME = "commentReference";
48
50
  * without mapping; the insertions that follow still carry pre-repair positions
49
51
  * and the applier maps them through the transaction.
50
52
  */
51
- export declare const planCommentReferenceRepairs: ({ references, markExtents }: CommentReferenceRepairInput) => readonly CommentReferenceRepair[];
53
+ export declare const planCommentReferenceRepairs: ({ references, markExtents, pointIds }: CommentReferenceRepairInput) => readonly CommentReferenceRepair[];
52
54
  type CommentReferenceResolution = {
53
55
  doc: Node;
54
56
  steps: Step[];
55
57
  positionMaps: readonly StepMap[];
56
58
  };
57
- export declare const resolveCommentReferences: (doc: Node) => CommentReferenceResolution | null;
59
+ /**
60
+ * Repair `doc`. `previous` is the document it was changed from: only a change
61
+ * can orphan a reference, so what stood alone there still stands.
62
+ */
63
+ export declare const resolveCommentReferences: (doc: Node, previous?: Node) => CommentReferenceResolution | null;
58
64
  export {};
@@ -1,7 +1,6 @@
1
- import { readCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
1
+ import { isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
2
2
  import { isCommentRangeInertAtom } from "./commentRangeInlineAtoms.js";
3
3
  import { readCommentReferenceAttrs } from "./commentReferenceAttrs.js";
4
- import "./extensions/nodes/CommentRangeBoundaryExtension.js";
5
4
  import "./extensions/nodes/RangeAnchorExtension.js";
6
5
  import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
7
6
  import { panic } from "better-result";
@@ -43,7 +42,7 @@ const surveyCommentReferences = (doc) => {
43
42
  }
44
43
  return false;
45
44
  }
46
- if (node.type.name === "commentRangeBoundary") {
45
+ if (isCommentRangeBoundaryNode(node)) {
47
46
  const attrs = readCommentRangeBoundaryAttrs(node);
48
47
  if (attrs.ok) {
49
48
  const { id } = attrs.value.marker;
@@ -54,7 +53,7 @@ const surveyCommentReferences = (doc) => {
54
53
  if (inert) return false;
55
54
  if (!node.isInline) return true;
56
55
  for (const mark of node.marks) {
57
- if (mark.type.name !== "comment") continue;
56
+ if (mark.type.name !== "comment" || mark.attrs["point"] === true) continue;
58
57
  const commentId = mark.attrs["commentId"];
59
58
  if (typeof commentId !== "number") continue;
60
59
  markEnds.set(commentId, Math.max(markEnds.get(commentId) ?? 0, position + node.nodeSize));
@@ -76,7 +75,7 @@ const surveyCommentReferences = (doc) => {
76
75
  * without mapping; the insertions that follow still carry pre-repair positions
77
76
  * and the applier maps them through the transaction.
78
77
  */
79
- const planCommentReferenceRepairs = ({ references, markExtents }) => {
78
+ const planCommentReferenceRepairs = ({ references, markExtents, pointIds }) => {
80
79
  const markedIds = new Set(markExtents.map(({ commentId }) => commentId));
81
80
  const deletions = [];
82
81
  const keptIds = /* @__PURE__ */ new Set();
@@ -89,7 +88,7 @@ const planCommentReferenceRepairs = ({ references, markExtents }) => {
89
88
  });
90
89
  continue;
91
90
  }
92
- if (!markedIds.has(reference.commentId)) {
91
+ if (!markedIds.has(reference.commentId) && !(pointIds?.has(reference.commentId) && !keptIds.has(reference.commentId))) {
93
92
  deletions.push({
94
93
  type: "delete",
95
94
  position: reference.position,
@@ -118,9 +117,24 @@ const planCommentReferenceRepairs = ({ references, markExtents }) => {
118
117
  }
119
118
  return [...deletions.toSorted((first, second) => second.position - first.position), ...insertions.toSorted((first, second) => second.position - first.position)];
120
119
  };
121
- const resolveCommentReferences = (doc) => {
120
+ /** Comments in `doc` with a reference and no content or range to cover. */
121
+ const pointCommentIds = ({ references, markExtents }) => {
122
+ const marked = new Set(markExtents.map(({ commentId }) => commentId));
123
+ const ids = /* @__PURE__ */ new Set();
124
+ for (const reference of references) if (reference.status === "valid" && !marked.has(reference.commentId)) ids.add(reference.commentId);
125
+ return ids;
126
+ };
127
+ /**
128
+ * Repair `doc`. `previous` is the document it was changed from: only a change
129
+ * can orphan a reference, so what stood alone there still stands.
130
+ */
131
+ const resolveCommentReferences = (doc, previous) => {
122
132
  const survey = surveyCommentReferences(doc);
123
- const repairs = planCommentReferenceRepairs(survey);
133
+ const orphans = pointCommentIds(survey);
134
+ const repairs = planCommentReferenceRepairs({
135
+ ...survey,
136
+ ...previous && orphans.size > 0 ? { pointIds: pointCommentIds(surveyCommentReferences(previous)) } : {}
137
+ });
124
138
  if (repairs.length === 0 && survey.unanchoredMarks.length === 0) return null;
125
139
  const transform = new Transform(doc);
126
140
  for (const { position, size, mark } of survey.unanchoredMarks) transform.removeMark(position, position + size, mark);
@@ -41,6 +41,8 @@ export declare function tableAttrsToFormatting(attrs: TableAttrs): document_d_ex
41
41
  */
42
42
  export declare function tableRowAttrsToFormatting(attrs: TableRowAttrs): document_d_exports.TableRowFormatting | undefined;
43
43
  export declare const standaloneTableCellFromProseMirror: (node: Node) => document_d_exports.TableCell;
44
+ /** A table node's rows as the save writes them, vertical merges included. */
45
+ export declare const standaloneTableRowsFromProseMirror: (node: Node) => document_d_exports.TableRow[];
44
46
  export declare function tableCellAttrsToFormatting(attrs: TableCellAttrs): document_d_exports.TableCellFormatting | undefined;
45
47
  /**
46
48
  * Update a Document with content from a ProseMirror document