@prosekit/extensions 0.11.4 → 0.11.6

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 (384) hide show
  1. package/dist/commit/style.css +2 -0
  2. package/dist/commit/style.css.map +1 -0
  3. package/dist/commit/style.js +1 -0
  4. package/dist/drop-indicator-E7nCfdnR.js +58 -0
  5. package/dist/drop-indicator-E7nCfdnR.js.map +1 -0
  6. package/dist/enter-rule-RdhEA900.js +2 -1
  7. package/dist/enter-rule-RdhEA900.js.map +1 -0
  8. package/dist/file-DVUhe5KJ.js +134 -0
  9. package/dist/file-DVUhe5KJ.js.map +1 -0
  10. package/dist/gap-cursor/style.css +2 -0
  11. package/dist/gap-cursor/style.css.map +1 -0
  12. package/dist/gap-cursor/style.js +1 -0
  13. package/dist/index-DY6lIIYV.d.ts +134 -0
  14. package/dist/index-DY6lIIYV.d.ts.map +1 -0
  15. package/dist/{input-rule-Gji4N7Oe.js → input-rule-B17tpW4m.js} +3 -3
  16. package/dist/input-rule-B17tpW4m.js.map +1 -0
  17. package/dist/list/style.css +2 -0
  18. package/dist/list/style.css.map +1 -0
  19. package/dist/list/style.js +1 -0
  20. package/dist/loro/style.css +2 -0
  21. package/dist/loro/style.css.map +1 -0
  22. package/dist/loro/style.js +1 -0
  23. package/dist/{mark-rule-D7zaa32n.js → mark-rule-CGmswjQ_.js} +3 -3
  24. package/dist/mark-rule-CGmswjQ_.js.map +1 -0
  25. package/dist/{paste-rule-Cca3n5TA.js → paste-rule-BIztzELg.js} +5 -15
  26. package/dist/paste-rule-BIztzELg.js.map +1 -0
  27. package/dist/placeholder/style.css +2 -0
  28. package/dist/placeholder/style.css.map +1 -0
  29. package/dist/placeholder/style.js +1 -0
  30. package/dist/prosekit-extensions-autocomplete.d.ts +2 -1
  31. package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -0
  32. package/dist/prosekit-extensions-autocomplete.js +2 -9
  33. package/dist/prosekit-extensions-autocomplete.js.map +1 -0
  34. package/dist/prosekit-extensions-blockquote.d.ts +2 -1
  35. package/dist/prosekit-extensions-blockquote.d.ts.map +1 -0
  36. package/dist/prosekit-extensions-blockquote.js +4 -4
  37. package/dist/prosekit-extensions-blockquote.js.map +1 -0
  38. package/dist/prosekit-extensions-bold.d.ts +2 -1
  39. package/dist/prosekit-extensions-bold.d.ts.map +1 -0
  40. package/dist/prosekit-extensions-bold.js +3 -2
  41. package/dist/prosekit-extensions-bold.js.map +1 -0
  42. package/dist/prosekit-extensions-code-block.d.ts +3 -2
  43. package/dist/prosekit-extensions-code-block.d.ts.map +1 -0
  44. package/dist/prosekit-extensions-code-block.js +5 -6
  45. package/dist/prosekit-extensions-code-block.js.map +1 -0
  46. package/dist/prosekit-extensions-code.d.ts +2 -1
  47. package/dist/prosekit-extensions-code.d.ts.map +1 -0
  48. package/dist/prosekit-extensions-code.js +3 -2
  49. package/dist/prosekit-extensions-code.js.map +1 -0
  50. package/dist/prosekit-extensions-commit.d.ts +2 -1
  51. package/dist/prosekit-extensions-commit.d.ts.map +1 -0
  52. package/dist/prosekit-extensions-commit.js +11 -13
  53. package/dist/prosekit-extensions-commit.js.map +1 -0
  54. package/dist/prosekit-extensions-doc.d.ts +2 -1
  55. package/dist/prosekit-extensions-doc.d.ts.map +1 -0
  56. package/dist/prosekit-extensions-doc.js +2 -1
  57. package/dist/prosekit-extensions-doc.js.map +1 -0
  58. package/dist/prosekit-extensions-drop-cursor.d.ts +2 -1
  59. package/dist/prosekit-extensions-drop-cursor.d.ts.map +1 -0
  60. package/dist/prosekit-extensions-drop-cursor.js +2 -1
  61. package/dist/prosekit-extensions-drop-cursor.js.map +1 -0
  62. package/dist/prosekit-extensions-drop-indicator.d.ts +5 -107
  63. package/dist/prosekit-extensions-drop-indicator.d.ts.map +1 -0
  64. package/dist/prosekit-extensions-drop-indicator.js +1 -1
  65. package/dist/prosekit-extensions-enter-rule.d.ts +2 -1
  66. package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -0
  67. package/dist/prosekit-extensions-file.d.ts +2 -125
  68. package/dist/prosekit-extensions-file.js +1 -139
  69. package/dist/prosekit-extensions-gap-cursor.d.ts +2 -2
  70. package/dist/prosekit-extensions-gap-cursor.d.ts.map +1 -0
  71. package/dist/prosekit-extensions-gap-cursor.js +2 -1
  72. package/dist/prosekit-extensions-gap-cursor.js.map +1 -0
  73. package/dist/prosekit-extensions-hard-break.d.ts +2 -5
  74. package/dist/prosekit-extensions-hard-break.d.ts.map +1 -0
  75. package/dist/prosekit-extensions-hard-break.js +2 -1
  76. package/dist/prosekit-extensions-hard-break.js.map +1 -0
  77. package/dist/prosekit-extensions-heading.d.ts +2 -1
  78. package/dist/prosekit-extensions-heading.d.ts.map +1 -0
  79. package/dist/prosekit-extensions-heading.js +5 -6
  80. package/dist/prosekit-extensions-heading.js.map +1 -0
  81. package/dist/prosekit-extensions-horizontal-rule.d.ts +2 -1
  82. package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -0
  83. package/dist/prosekit-extensions-horizontal-rule.js +5 -6
  84. package/dist/prosekit-extensions-horizontal-rule.js.map +1 -0
  85. package/dist/prosekit-extensions-image.d.ts +80 -3
  86. package/dist/prosekit-extensions-image.d.ts.map +1 -0
  87. package/dist/prosekit-extensions-image.js +90 -10
  88. package/dist/prosekit-extensions-image.js.map +1 -0
  89. package/dist/prosekit-extensions-input-rule.d.ts +2 -1
  90. package/dist/prosekit-extensions-input-rule.d.ts.map +1 -0
  91. package/dist/prosekit-extensions-input-rule.js +1 -1
  92. package/dist/prosekit-extensions-italic.d.ts +2 -1
  93. package/dist/prosekit-extensions-italic.d.ts.map +1 -0
  94. package/dist/prosekit-extensions-italic.js +3 -2
  95. package/dist/prosekit-extensions-italic.js.map +1 -0
  96. package/dist/prosekit-extensions-link.d.ts +2 -1
  97. package/dist/prosekit-extensions-link.d.ts.map +1 -0
  98. package/dist/prosekit-extensions-link.js +6 -5
  99. package/dist/prosekit-extensions-link.js.map +1 -0
  100. package/dist/prosekit-extensions-list.d.ts +22 -21
  101. package/dist/prosekit-extensions-list.d.ts.map +1 -0
  102. package/dist/prosekit-extensions-list.js +7 -8
  103. package/dist/prosekit-extensions-list.js.map +1 -0
  104. package/dist/prosekit-extensions-loro.d.ts +14 -13
  105. package/dist/prosekit-extensions-loro.d.ts.map +1 -0
  106. package/dist/prosekit-extensions-loro.js +2 -1
  107. package/dist/prosekit-extensions-loro.js.map +1 -0
  108. package/dist/prosekit-extensions-mark-rule.d.ts +2 -1
  109. package/dist/prosekit-extensions-mark-rule.d.ts.map +1 -0
  110. package/dist/prosekit-extensions-mark-rule.js +1 -1
  111. package/dist/prosekit-extensions-mention.d.ts +2 -1
  112. package/dist/prosekit-extensions-mention.d.ts.map +1 -0
  113. package/dist/prosekit-extensions-mention.js +2 -1
  114. package/dist/prosekit-extensions-mention.js.map +1 -0
  115. package/dist/prosekit-extensions-mod-click-prevention.d.ts +2 -1
  116. package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +1 -0
  117. package/dist/prosekit-extensions-mod-click-prevention.js +2 -1
  118. package/dist/prosekit-extensions-mod-click-prevention.js.map +1 -0
  119. package/dist/prosekit-extensions-paragraph.d.ts +2 -5
  120. package/dist/prosekit-extensions-paragraph.d.ts.map +1 -0
  121. package/dist/prosekit-extensions-paragraph.js +2 -1
  122. package/dist/prosekit-extensions-paragraph.js.map +1 -0
  123. package/dist/prosekit-extensions-paste-rule.d.ts +2 -1
  124. package/dist/prosekit-extensions-paste-rule.d.ts.map +1 -0
  125. package/dist/prosekit-extensions-paste-rule.js +1 -1
  126. package/dist/prosekit-extensions-placeholder.d.ts +2 -1
  127. package/dist/prosekit-extensions-placeholder.d.ts.map +1 -0
  128. package/dist/prosekit-extensions-placeholder.js +5 -5
  129. package/dist/prosekit-extensions-placeholder.js.map +1 -0
  130. package/dist/prosekit-extensions-readonly.d.ts +2 -1
  131. package/dist/prosekit-extensions-readonly.d.ts.map +1 -0
  132. package/dist/prosekit-extensions-readonly.js +2 -1
  133. package/dist/prosekit-extensions-readonly.js.map +1 -0
  134. package/dist/prosekit-extensions-search.d.ts +2 -1
  135. package/dist/prosekit-extensions-search.d.ts.map +1 -0
  136. package/dist/prosekit-extensions-search.js +3 -3
  137. package/dist/prosekit-extensions-search.js.map +1 -0
  138. package/dist/prosekit-extensions-strike.d.ts +2 -1
  139. package/dist/prosekit-extensions-strike.d.ts.map +1 -0
  140. package/dist/prosekit-extensions-strike.js +3 -2
  141. package/dist/prosekit-extensions-strike.js.map +1 -0
  142. package/dist/prosekit-extensions-table.d.ts +47 -114
  143. package/dist/prosekit-extensions-table.d.ts.map +1 -0
  144. package/dist/prosekit-extensions-table.js +2 -2
  145. package/dist/prosekit-extensions-text-align.d.ts +2 -1
  146. package/dist/prosekit-extensions-text-align.d.ts.map +1 -0
  147. package/dist/prosekit-extensions-text-align.js +2 -1
  148. package/dist/prosekit-extensions-text-align.js.map +1 -0
  149. package/dist/prosekit-extensions-text.d.ts +2 -1
  150. package/dist/prosekit-extensions-text.d.ts.map +1 -0
  151. package/dist/prosekit-extensions-text.js +2 -1
  152. package/dist/prosekit-extensions-text.js.map +1 -0
  153. package/dist/prosekit-extensions-underline.d.ts +2 -1
  154. package/dist/prosekit-extensions-underline.d.ts.map +1 -0
  155. package/dist/prosekit-extensions-underline.js +2 -1
  156. package/dist/prosekit-extensions-underline.js.map +1 -0
  157. package/dist/prosekit-extensions-virtual-selection.d.ts +2 -1
  158. package/dist/prosekit-extensions-virtual-selection.d.ts.map +1 -0
  159. package/dist/prosekit-extensions-virtual-selection.js +3 -3
  160. package/dist/prosekit-extensions-virtual-selection.js.map +1 -0
  161. package/dist/prosekit-extensions-yjs.d.ts +2 -1
  162. package/dist/prosekit-extensions-yjs.d.ts.map +1 -0
  163. package/dist/prosekit-extensions-yjs.js +2 -1
  164. package/dist/prosekit-extensions-yjs.js.map +1 -0
  165. package/dist/prosekit-extensions.js +1 -0
  166. package/dist/search/style.css +2 -0
  167. package/dist/search/style.css.map +1 -0
  168. package/dist/search/style.js +1 -0
  169. package/dist/{shiki-highlighter-chunk-DSPM0T27.d.ts → shiki-highlighter-chunk-Cwu1Jr9o.d.ts} +2 -1
  170. package/dist/shiki-highlighter-chunk-Cwu1Jr9o.d.ts.map +1 -0
  171. package/dist/shiki-highlighter-chunk.d.ts +1 -1
  172. package/dist/shiki-highlighter-chunk.js +3 -5
  173. package/dist/shiki-highlighter-chunk.js.map +1 -0
  174. package/dist/table/style.css +2 -0
  175. package/dist/table/style.css.map +1 -0
  176. package/dist/table/style.js +1 -0
  177. package/dist/table-BNwuK7xg.js +297 -0
  178. package/dist/table-BNwuK7xg.js.map +1 -0
  179. package/dist/virtual-selection/style.css +2 -0
  180. package/dist/virtual-selection/style.css.map +1 -0
  181. package/dist/virtual-selection/style.js +1 -0
  182. package/dist/yjs/style.css +2 -0
  183. package/dist/yjs/style.css.map +1 -0
  184. package/dist/yjs/style.js +1 -0
  185. package/package.json +12 -10
  186. package/src/autocomplete/autocomplete-helpers.ts +74 -0
  187. package/src/autocomplete/autocomplete-plugin.ts +186 -0
  188. package/src/autocomplete/autocomplete-rule.ts +117 -0
  189. package/src/autocomplete/autocomplete.spec.ts +132 -0
  190. package/src/autocomplete/autocomplete.ts +29 -0
  191. package/src/autocomplete/index.ts +9 -0
  192. package/src/blockquote/blockquote-commands.ts +32 -0
  193. package/src/blockquote/blockquote-input-rule.ts +14 -0
  194. package/src/blockquote/blockquote-keymap.spec.ts +45 -0
  195. package/src/blockquote/blockquote-keymap.ts +31 -0
  196. package/src/blockquote/blockquote-spec.ts +24 -0
  197. package/src/blockquote/blockquote.ts +34 -0
  198. package/src/blockquote/index.ts +14 -0
  199. package/src/bold/bold-commands.ts +23 -0
  200. package/src/bold/bold-input-rule.spec.ts +51 -0
  201. package/src/bold/bold-input-rule.ts +18 -0
  202. package/src/bold/bold-keymap.ts +14 -0
  203. package/src/bold/bold-spec.ts +53 -0
  204. package/src/bold/bold.ts +32 -0
  205. package/src/bold/index.ts +14 -0
  206. package/src/code/code-commands.ts +23 -0
  207. package/src/code/code-input-rule.ts +18 -0
  208. package/src/code/code-keymap.ts +14 -0
  209. package/src/code/code-spec.ts +28 -0
  210. package/src/code/code.ts +32 -0
  211. package/src/code/index.ts +14 -0
  212. package/src/code-block/code-block-commands.ts +44 -0
  213. package/src/code-block/code-block-highlight.ts +40 -0
  214. package/src/code-block/code-block-input-rule.ts +36 -0
  215. package/src/code-block/code-block-keymap.ts +61 -0
  216. package/src/code-block/code-block-shiki.ts +58 -0
  217. package/src/code-block/code-block-spec.spec.ts +164 -0
  218. package/src/code-block/code-block-spec.ts +71 -0
  219. package/src/code-block/code-block-types.ts +8 -0
  220. package/src/code-block/code-block.ts +46 -0
  221. package/src/code-block/index.ts +32 -0
  222. package/src/code-block/shiki-bundle.ts +8 -0
  223. package/src/code-block/shiki-highlighter-chunk.ts +84 -0
  224. package/src/code-block/shiki-highlighter.ts +22 -0
  225. package/src/code-block/shiki-parser.ts +36 -0
  226. package/src/commit/index.ts +330 -0
  227. package/src/commit/style.css +7 -0
  228. package/src/doc/index.ts +21 -0
  229. package/src/drop-cursor/drop-cursor.ts +46 -0
  230. package/src/drop-cursor/index.ts +5 -0
  231. package/src/drop-indicator/drop-indicator-facet.ts +62 -0
  232. package/src/drop-indicator/drop-indicator.ts +35 -0
  233. package/src/drop-indicator/index.ts +14 -0
  234. package/src/enter-rule/index.ts +241 -0
  235. package/src/file/file-drop-handler.ts +75 -0
  236. package/src/file/file-paste-handler.spec.ts +95 -0
  237. package/src/file/file-paste-handler.ts +59 -0
  238. package/src/file/file-upload.ts +140 -0
  239. package/src/file/helpers.ts +39 -0
  240. package/src/file/index.ts +16 -0
  241. package/src/gap-cursor/gap-cursor.ts +28 -0
  242. package/src/gap-cursor/index.ts +4 -0
  243. package/src/gap-cursor/style.css +25 -0
  244. package/src/hard-break/hard-break-commands.ts +31 -0
  245. package/src/hard-break/hard-break-keymap.spec.ts +45 -0
  246. package/src/hard-break/hard-break-keymap.ts +16 -0
  247. package/src/hard-break/hard-break-spec.ts +31 -0
  248. package/src/hard-break/hard-break.ts +32 -0
  249. package/src/hard-break/index.ts +13 -0
  250. package/src/heading/heading-commands.ts +37 -0
  251. package/src/heading/heading-input-rule.ts +22 -0
  252. package/src/heading/heading-keymap.spec.ts +53 -0
  253. package/src/heading/heading-keymap.ts +40 -0
  254. package/src/heading/heading-spec.ts +39 -0
  255. package/src/heading/heading-types.ts +3 -0
  256. package/src/heading/heading.ts +34 -0
  257. package/src/heading/index.ts +15 -0
  258. package/src/horizontal-rule/horizontal-rule-commands.spec.ts +61 -0
  259. package/src/horizontal-rule/horizontal-rule-commands.ts +37 -0
  260. package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +61 -0
  261. package/src/horizontal-rule/horizontal-rule-input-rule.ts +26 -0
  262. package/src/horizontal-rule/horizontal-rule-spec.ts +21 -0
  263. package/src/horizontal-rule/horizontal-rule.ts +29 -0
  264. package/src/horizontal-rule/index.ts +14 -0
  265. package/src/image/image-commands.ts +36 -0
  266. package/src/image/image-spec.ts +72 -0
  267. package/src/image/image-upload-handler.ts +156 -0
  268. package/src/image/image.ts +25 -0
  269. package/src/image/index.ts +22 -0
  270. package/src/index.ts +1 -0
  271. package/src/input-rule/index.ts +237 -0
  272. package/src/italic/index.ts +14 -0
  273. package/src/italic/italic-commands.spec.ts +75 -0
  274. package/src/italic/italic-commands.ts +23 -0
  275. package/src/italic/italic-input-rule.spec.ts +25 -0
  276. package/src/italic/italic-input-rule.ts +18 -0
  277. package/src/italic/italic-keymap.ts +14 -0
  278. package/src/italic/italic-spec.ts +35 -0
  279. package/src/italic/italic.ts +34 -0
  280. package/src/link/index.spec.ts +88 -0
  281. package/src/link/index.ts +156 -0
  282. package/src/link/link-paste-rule.spec.ts +194 -0
  283. package/src/link/link-paste-rule.ts +22 -0
  284. package/src/link/link-regex.spec.ts +82 -0
  285. package/src/link/link-regex.ts +79 -0
  286. package/src/link/link-types.ts +8 -0
  287. package/src/list/index.ts +25 -0
  288. package/src/list/list-commands.ts +61 -0
  289. package/src/list/list-drop-indicator.ts +37 -0
  290. package/src/list/list-input-rules.ts +14 -0
  291. package/src/list/list-keymap.spec.ts +39 -0
  292. package/src/list/list-keymap.ts +48 -0
  293. package/src/list/list-plugins.ts +35 -0
  294. package/src/list/list-serializer.ts +38 -0
  295. package/src/list/list-spec.ts +60 -0
  296. package/src/list/list-types.spec.ts +10 -0
  297. package/src/list/list-types.ts +23 -0
  298. package/src/list/list.spec.ts +134 -0
  299. package/src/list/list.ts +38 -0
  300. package/src/list/style.css +128 -0
  301. package/src/loro/index.ts +17 -0
  302. package/src/loro/loro-commands.ts +27 -0
  303. package/src/loro/loro-cursor-plugin.ts +28 -0
  304. package/src/loro/loro-keymap.ts +23 -0
  305. package/src/loro/loro-sync-plugin.ts +14 -0
  306. package/src/loro/loro-undo-plugin.ts +12 -0
  307. package/src/loro/loro.ts +75 -0
  308. package/src/loro/style.css +33 -0
  309. package/src/mark-rule/apply.ts +129 -0
  310. package/src/mark-rule/index.ts +2 -0
  311. package/src/mark-rule/mark-rule.spec.ts +123 -0
  312. package/src/mark-rule/mark-rule.ts +48 -0
  313. package/src/mark-rule/range.ts +107 -0
  314. package/src/mark-rule/types.ts +30 -0
  315. package/src/mention/index.ts +90 -0
  316. package/src/mod-click-prevention/index.ts +35 -0
  317. package/src/paragraph/index.ts +7 -0
  318. package/src/paragraph/paragraph-commands.ts +29 -0
  319. package/src/paragraph/paragraph-keymap.ts +15 -0
  320. package/src/paragraph/paragraph-spec.ts +31 -0
  321. package/src/paragraph/paragraph.ts +37 -0
  322. package/src/paste-rule/index.ts +10 -0
  323. package/src/paste-rule/mark-paste-rule.spec.ts +112 -0
  324. package/src/paste-rule/mark-paste-rule.ts +194 -0
  325. package/src/paste-rule/paste-rule-plugin.ts +53 -0
  326. package/src/paste-rule/paste-rule.spec.ts +96 -0
  327. package/src/paste-rule/paste-rule.ts +60 -0
  328. package/src/paste-rule/split-text-by-regex.spec.ts +97 -0
  329. package/src/paste-rule/split-text-by-regex.ts +44 -0
  330. package/src/placeholder/index.ts +113 -0
  331. package/src/placeholder/style.css +7 -0
  332. package/src/readonly/index.ts +22 -0
  333. package/src/search/index.ts +140 -0
  334. package/src/search/style.css +13 -0
  335. package/src/strike/index.ts +101 -0
  336. package/src/table/index.ts +53 -0
  337. package/src/table/style.css +42 -0
  338. package/src/table/table-commands/delete-cell-selection.spec.ts +41 -0
  339. package/src/table/table-commands/delete-cell-selection.ts +1 -0
  340. package/src/table/table-commands/exit-table.spec.ts +45 -0
  341. package/src/table/table-commands/exit-table.ts +49 -0
  342. package/src/table/table-commands/insert-table.spec.ts +39 -0
  343. package/src/table/table-commands/insert-table.ts +80 -0
  344. package/src/table/table-commands/move-table-column.spec.ts +618 -0
  345. package/src/table/table-commands/move-table-column.ts +4 -0
  346. package/src/table/table-commands/move-table-row.spec.ts +380 -0
  347. package/src/table/table-commands/move-table-row.ts +4 -0
  348. package/src/table/table-commands/select-table-cell.spec.ts +34 -0
  349. package/src/table/table-commands/select-table-cell.ts +35 -0
  350. package/src/table/table-commands/select-table-column.spec.ts +33 -0
  351. package/src/table/table-commands/select-table-column.ts +39 -0
  352. package/src/table/table-commands/select-table-row.spec.ts +32 -0
  353. package/src/table/table-commands/select-table-row.ts +39 -0
  354. package/src/table/table-commands/select-table.spec.ts +36 -0
  355. package/src/table/table-commands/select-table.ts +50 -0
  356. package/src/table/table-commands.ts +110 -0
  357. package/src/table/table-drop-indicator.ts +40 -0
  358. package/src/table/table-plugins.ts +15 -0
  359. package/src/table/table-spec.spec.ts +113 -0
  360. package/src/table/table-spec.ts +109 -0
  361. package/src/table/table-utils.ts +16 -0
  362. package/src/table/table.ts +49 -0
  363. package/src/table/test-utils.ts +28 -0
  364. package/src/testing/clipboard.ts +58 -0
  365. package/src/testing/format-html.ts +5 -0
  366. package/src/testing/index.ts +161 -0
  367. package/src/testing/keyboard.ts +36 -0
  368. package/src/testing/markdown.ts +23 -0
  369. package/src/text/index.ts +24 -0
  370. package/src/text-align/index.ts +133 -0
  371. package/src/types/assert-type-equal.ts +8 -0
  372. package/src/underline/index.ts +83 -0
  373. package/src/virtual-selection/index.ts +100 -0
  374. package/src/virtual-selection/style.css +5 -0
  375. package/src/yjs/index.ts +22 -0
  376. package/src/yjs/style.css +31 -0
  377. package/src/yjs/yjs-commands.ts +27 -0
  378. package/src/yjs/yjs-cursor-plugin.ts +25 -0
  379. package/src/yjs/yjs-keymap.ts +23 -0
  380. package/src/yjs/yjs-sync-plugin.ts +23 -0
  381. package/src/yjs/yjs-undo-plugin.ts +87 -0
  382. package/src/yjs/yjs.ts +84 -0
  383. package/dist/drop-indicator-dB9rZn8e.js +0 -267
  384. package/dist/table-CPI9ZxbK.js +0 -760
@@ -1,760 +0,0 @@
1
- import { defineDropIndicator } from "./drop-indicator-dB9rZn8e.js";
2
- import { defaultBlockAt, defineCommands, defineNodeSpec, definePlugin, findParentNode, getNodeType, insertNode, union } from "@prosekit/core";
3
- import { TextSelection } from "@prosekit/pm/state";
4
- import { CellSelection, TableMap, addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, cellAround, cellNear, columnResizing, deleteCellSelection, deleteColumn, deleteRow, deleteTable, inSameTable, mergeCells, splitCell, tableEditing, tableNodes } from "prosemirror-tables";
5
-
6
- //#region src/table/table-utils/convert-array-of-rows-to-table-node.ts
7
- /**
8
- * Convert an array of rows to a table node.
9
- *
10
- * @internal
11
- */
12
- function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
13
- const rowsPM = [];
14
- const map = TableMap.get(tableNode);
15
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
16
- const row = tableNode.child(rowIndex);
17
- const rowCells = [];
18
- for (let colIndex = 0; colIndex < map.width; colIndex++) {
19
- if (!arrayOfNodes[rowIndex][colIndex]) continue;
20
- const cellPos = map.map[rowIndex * map.width + colIndex];
21
- const cell = arrayOfNodes[rowIndex][colIndex];
22
- const oldCell = tableNode.nodeAt(cellPos);
23
- const newCell = oldCell.type.createChecked(Object.assign({}, cell.attrs), cell.content, cell.marks);
24
- rowCells.push(newCell);
25
- }
26
- rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks));
27
- }
28
- const newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks);
29
- return newTable;
30
- }
31
-
32
- //#endregion
33
- //#region src/table/table-utils/convert-table-node-to-array-of-rows.ts
34
- /**
35
- * This function will transform the table node into a matrix of rows and columns
36
- * respecting merged cells, for example this table:
37
- *
38
- * ```
39
- * ┌──────┬──────┬─────────────┐
40
- * │ A1 │ B1 │ C1 │
41
- * ├──────┼──────┴──────┬──────┤
42
- * │ A2 │ B2 │ │
43
- * ├──────┼─────────────┤ D1 │
44
- * │ A3 │ B3 │ C3 │ │
45
- * └──────┴──────┴──────┴──────┘
46
- * ```
47
- *
48
- * will be converted to the below:
49
- *
50
- * ```javascript
51
- * [
52
- * [A1, B1, C1, null],
53
- * [A2, B2, null, D1],
54
- * [A3, B3, C3, null],
55
- * ]
56
- * ```
57
- * @internal
58
- */
59
- function convertTableNodeToArrayOfRows(tableNode) {
60
- const map = TableMap.get(tableNode);
61
- const rows = [];
62
- const rowCount = map.height;
63
- const colCount = map.width;
64
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
65
- const row = [];
66
- for (let colIndex = 0; colIndex < colCount; colIndex++) {
67
- let cellIndex = rowIndex * colCount + colIndex;
68
- let cellPos = map.map[cellIndex];
69
- if (rowIndex > 0) {
70
- const topCellIndex = cellIndex - colCount;
71
- const topCellPos = map.map[topCellIndex];
72
- if (cellPos === topCellPos) {
73
- row.push(null);
74
- continue;
75
- }
76
- }
77
- if (colIndex > 0) {
78
- const leftCellIndex = cellIndex - 1;
79
- const leftCellPos = map.map[leftCellIndex];
80
- if (cellPos === leftCellPos) {
81
- row.push(null);
82
- continue;
83
- }
84
- }
85
- row.push(tableNode.nodeAt(cellPos));
86
- }
87
- rows.push(row);
88
- }
89
- return rows;
90
- }
91
-
92
- //#endregion
93
- //#region src/table/table-utils/query.ts
94
- /**
95
- * Checks if the given object is a `CellSelection` instance.
96
- *
97
- * @public
98
- */
99
- function isCellSelection(value) {
100
- return value instanceof CellSelection;
101
- }
102
- /**
103
- * Find the closest table node.
104
- *
105
- * @internal
106
- */
107
- function findTable($pos) {
108
- return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
109
- }
110
- /**
111
- * Try to find the anchor and head cell in the same table by using the given
112
- * anchor and head as hit points, or fallback to the selection's anchor and
113
- * head.
114
- *
115
- * @internal
116
- */
117
- function findCellRange(selection, anchorHit, headHit) {
118
- if (anchorHit == null && headHit == null && isCellSelection(selection)) return [selection.$anchorCell, selection.$headCell];
119
- const anchor = anchorHit ?? headHit ?? selection.anchor;
120
- const head = headHit ?? anchorHit ?? selection.head;
121
- const doc = selection.$head.doc;
122
- const $anchorCell = findCellPos(doc, anchor);
123
- const $headCell = findCellPos(doc, head);
124
- if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) return [$anchorCell, $headCell];
125
- }
126
- /**
127
- * Try to find a resolved pos of a cell by using the given pos as a hit point.
128
- *
129
- * @internal
130
- */
131
- function findCellPos(doc, pos) {
132
- const $pos = doc.resolve(pos);
133
- return cellAround($pos) || cellNear($pos);
134
- }
135
-
136
- //#endregion
137
- //#region src/table/table-utils/get-cells-in-column.ts
138
- /**
139
- * Returns an array of cells in a column(s), where `columnIndex` could be a column index or an array of column indexes.
140
- *
141
- * @internal
142
- */
143
- function getCellsInColumn(columnIndexes, selection) {
144
- const table = findTable(selection.$from);
145
- if (!table) return;
146
- const map = TableMap.get(table.node);
147
- const indexes = Array.isArray(columnIndexes) ? columnIndexes : [columnIndexes];
148
- return indexes.filter((index) => index >= 0 && index <= map.width - 1).flatMap((index) => {
149
- const cells = map.cellsInRect({
150
- left: index,
151
- right: index + 1,
152
- top: 0,
153
- bottom: map.height
154
- });
155
- return cells.map((nodePos) => {
156
- const node = table.node.nodeAt(nodePos);
157
- const pos = nodePos + table.start;
158
- return {
159
- pos,
160
- start: pos + 1,
161
- node,
162
- depth: table.depth + 2
163
- };
164
- });
165
- });
166
- }
167
-
168
- //#endregion
169
- //#region src/table/table-utils/get-cells-in-row.ts
170
- /**
171
- * Returns an array of cells in a row(s), where `rowIndex` could be a row index or an array of row indexes.
172
- *
173
- * @internal
174
- */
175
- function getCellsInRow(rowIndex, selection) {
176
- const table = findTable(selection.$from);
177
- if (!table) return;
178
- const map = TableMap.get(table.node);
179
- const indexes = Array.isArray(rowIndex) ? rowIndex : [rowIndex];
180
- return indexes.filter((index) => index >= 0 && index <= map.height - 1).flatMap((index) => {
181
- const cells = map.cellsInRect({
182
- left: 0,
183
- right: map.width,
184
- top: index,
185
- bottom: index + 1
186
- });
187
- return cells.map((nodePos) => {
188
- const node = table.node.nodeAt(nodePos);
189
- const pos = nodePos + table.start;
190
- return {
191
- pos,
192
- start: pos + 1,
193
- node,
194
- depth: table.depth + 2
195
- };
196
- });
197
- });
198
- }
199
-
200
- //#endregion
201
- //#region src/table/table-utils/get-selection-range-in-column.ts
202
- /**
203
- * Returns a range of rectangular selection spanning all merged cells around a
204
- * column at index `columnIndex`.
205
- *
206
- * Original implementation from Atlassian (Apache License 2.0)
207
- *
208
- * https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-column.ts#editor/editor-tables/src/utils/get-selection-range-in-column.ts
209
- *
210
- * @internal
211
- */
212
- function getSelectionRangeInColumn(tr, startColIndex, endColIndex = startColIndex) {
213
- let startIndex = startColIndex;
214
- let endIndex = endColIndex;
215
- for (let i = startColIndex; i >= 0; i--) {
216
- const cells = getCellsInColumn(i, tr.selection);
217
- if (cells) cells.forEach((cell) => {
218
- const maybeEndIndex = cell.node.attrs.colspan + i - 1;
219
- if (maybeEndIndex >= startIndex) startIndex = i;
220
- if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
221
- });
222
- }
223
- for (let i = startColIndex; i <= endIndex; i++) {
224
- const cells = getCellsInColumn(i, tr.selection);
225
- if (cells) cells.forEach((cell) => {
226
- const maybeEndIndex = cell.node.attrs.colspan + i - 1;
227
- if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;
228
- });
229
- }
230
- const indexes = [];
231
- for (let i = startIndex; i <= endIndex; i++) {
232
- const maybeCells = getCellsInColumn(i, tr.selection);
233
- if (maybeCells && maybeCells.length > 0) indexes.push(i);
234
- }
235
- startIndex = indexes[0];
236
- endIndex = indexes[indexes.length - 1];
237
- const firstSelectedColumnCells = getCellsInColumn(startIndex, tr.selection);
238
- const firstRowCells = getCellsInRow(0, tr.selection);
239
- if (!firstSelectedColumnCells || !firstRowCells) return;
240
- const $anchor = tr.doc.resolve(firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos);
241
- let headCell;
242
- for (let i = endIndex; i >= startIndex; i--) {
243
- const columnCells = getCellsInColumn(i, tr.selection);
244
- if (columnCells && columnCells.length > 0) {
245
- for (let j = firstRowCells.length - 1; j >= 0; j--) if (firstRowCells[j].pos === columnCells[0].pos) {
246
- headCell = columnCells[0];
247
- break;
248
- }
249
- if (headCell) break;
250
- }
251
- }
252
- if (!headCell) return;
253
- const $head = tr.doc.resolve(headCell.pos);
254
- return {
255
- $anchor,
256
- $head,
257
- indexes
258
- };
259
- }
260
-
261
- //#endregion
262
- //#region src/table/table-utils/move-row-in-array-of-rows.ts
263
- /**
264
- * Move a row in an array of rows.
265
- *
266
- * @internal
267
- */
268
- function moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) {
269
- const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
270
- const rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length);
271
- const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
272
- let target;
273
- if (directionOverride === -1 && direction === 1) target = indexesTarget[0] - 1;
274
- else if (directionOverride === 1 && direction === -1) target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1;
275
- else target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;
276
- rows.splice(target, 0, ...rowsExtracted);
277
- return rows;
278
- }
279
-
280
- //#endregion
281
- //#region src/table/table-utils/transpose.ts
282
- /**
283
- * Transposes a 2D array by flipping columns to rows.
284
- *
285
- * Transposition is a familiar algebra concept where the matrix is flipped
286
- * along its diagonal. For more details, see:
287
- * https://en.wikipedia.org/wiki/Transpose
288
- *
289
- * @example
290
- * ```javascript
291
- * const arr = [
292
- * ['a1', 'a2', 'a3'],
293
- * ['b1', 'b2', 'b3'],
294
- * ['c1', 'c2', 'c3'],
295
- * ['d1', 'd2', 'd3'],
296
- * ];
297
- *
298
- * const result = transpose(arr);
299
- * result === [
300
- * ['a1', 'b1', 'c1', 'd1'],
301
- * ['a2', 'b2', 'c2', 'd2'],
302
- * ['a3', 'b3', 'c3', 'd3'],
303
- * ]
304
- * ```
305
- */
306
- function transpose(array) {
307
- return array[0].map((_, i) => {
308
- return array.map((column) => column[i]);
309
- });
310
- }
311
-
312
- //#endregion
313
- //#region src/table/table-utils/move-column.ts
314
- /**
315
- * Move a column from index `origin` to index `target`.
316
- *
317
- * @internal
318
- */
319
- function moveColumn(moveColParams) {
320
- const { tr, originIndex, targetIndex, select, pos } = moveColParams;
321
- const $pos = tr.doc.resolve(pos);
322
- const table = findTable($pos);
323
- if (!table) return false;
324
- const indexesOriginColumn = getSelectionRangeInColumn(tr, originIndex)?.indexes;
325
- const indexesTargetColumn = getSelectionRangeInColumn(tr, targetIndex)?.indexes;
326
- if (!indexesOriginColumn || !indexesTargetColumn) return false;
327
- if (indexesOriginColumn.includes(targetIndex)) return false;
328
- const newTable = moveTableColumn$1(table.node, indexesOriginColumn, indexesTargetColumn, 0);
329
- tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
330
- if (!select) return true;
331
- const map = TableMap.get(newTable);
332
- const start = table.start;
333
- const index = targetIndex;
334
- const lastCell = map.positionAt(map.height - 1, index, newTable);
335
- const $lastCell = tr.doc.resolve(start + lastCell);
336
- const firstCell = map.positionAt(0, index, newTable);
337
- const $firstCell = tr.doc.resolve(start + firstCell);
338
- tr.setSelection(CellSelection.colSelection($lastCell, $firstCell));
339
- return true;
340
- }
341
- function moveTableColumn$1(table, indexesOrigin, indexesTarget, direction) {
342
- let rows = transpose(convertTableNodeToArrayOfRows(table));
343
- rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
344
- rows = transpose(rows);
345
- return convertArrayOfRowsToTableNode(table, rows);
346
- }
347
-
348
- //#endregion
349
- //#region src/table/table-utils/get-selection-range-in-row.ts
350
- /**
351
- * Returns a range of rectangular selection spanning all merged cells around a
352
- * row at index `rowIndex`.
353
- *
354
- * Original implementation from Atlassian (Apache License 2.0)
355
- *
356
- * https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-row.ts#editor/editor-tables/src/utils/get-selection-range-in-row.ts
357
- *
358
- * @internal
359
- */
360
- function getSelectionRangeInRow(tr, startRowIndex, endRowIndex = startRowIndex) {
361
- let startIndex = startRowIndex;
362
- let endIndex = endRowIndex;
363
- for (let i = startRowIndex; i >= 0; i--) {
364
- const cells = getCellsInRow(i, tr.selection);
365
- if (cells) cells.forEach((cell) => {
366
- const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
367
- if (maybeEndIndex >= startIndex) startIndex = i;
368
- if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
369
- });
370
- }
371
- for (let i = startRowIndex; i <= endIndex; i++) {
372
- const cells = getCellsInRow(i, tr.selection);
373
- if (cells) cells.forEach((cell) => {
374
- const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
375
- if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;
376
- });
377
- }
378
- const indexes = [];
379
- for (let i = startIndex; i <= endIndex; i++) {
380
- const maybeCells = getCellsInRow(i, tr.selection);
381
- if (maybeCells && maybeCells.length > 0) indexes.push(i);
382
- }
383
- startIndex = indexes[0];
384
- endIndex = indexes[indexes.length - 1];
385
- const firstSelectedRowCells = getCellsInRow(startIndex, tr.selection);
386
- const firstColumnCells = getCellsInColumn(0, tr.selection);
387
- if (!firstSelectedRowCells || !firstColumnCells) return;
388
- const $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1].pos);
389
- let headCell;
390
- for (let i = endIndex; i >= startIndex; i--) {
391
- const rowCells = getCellsInRow(i, tr.selection);
392
- if (rowCells && rowCells.length > 0) {
393
- for (let j = firstColumnCells.length - 1; j >= 0; j--) if (firstColumnCells[j].pos === rowCells[0].pos) {
394
- headCell = rowCells[0];
395
- break;
396
- }
397
- if (headCell) break;
398
- }
399
- }
400
- if (!headCell) return;
401
- const $head = tr.doc.resolve(headCell.pos);
402
- return {
403
- $anchor,
404
- $head,
405
- indexes
406
- };
407
- }
408
-
409
- //#endregion
410
- //#region src/table/table-utils/move-row.ts
411
- /**
412
- * Move a row from index `origin` to index `target`.
413
- *
414
- * @internal
415
- */
416
- function moveRow(moveRowParams) {
417
- const { tr, originIndex, targetIndex, select, pos } = moveRowParams;
418
- const $pos = tr.doc.resolve(pos);
419
- const table = findTable($pos);
420
- if (!table) return false;
421
- const indexesOriginRow = getSelectionRangeInRow(tr, originIndex)?.indexes;
422
- const indexesTargetRow = getSelectionRangeInRow(tr, targetIndex)?.indexes;
423
- if (!indexesOriginRow || !indexesTargetRow) return false;
424
- if (indexesOriginRow.includes(targetIndex)) return false;
425
- const newTable = moveTableRow$1(table.node, indexesOriginRow, indexesTargetRow, 0);
426
- tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
427
- if (!select) return true;
428
- const map = TableMap.get(newTable);
429
- const start = table.start;
430
- const index = targetIndex;
431
- const lastCell = map.positionAt(index, map.width - 1, newTable);
432
- const $lastCell = tr.doc.resolve(start + lastCell);
433
- const firstCell = map.positionAt(index, 0, newTable);
434
- const $firstCell = tr.doc.resolve(start + firstCell);
435
- tr.setSelection(CellSelection.rowSelection($lastCell, $firstCell));
436
- return true;
437
- }
438
- function moveTableRow$1(table, indexesOrigin, indexesTarget, direction) {
439
- let rows = convertTableNodeToArrayOfRows(table);
440
- rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
441
- return convertArrayOfRowsToTableNode(table, rows);
442
- }
443
-
444
- //#endregion
445
- //#region src/table/table-commands/move-table-column.ts
446
- /**
447
- * Move a table column from index `origin` to index `target`.
448
- *
449
- * @public
450
- */
451
- function moveTableColumn(options) {
452
- return (state, dispatch) => {
453
- const { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;
454
- const tr = state.tr;
455
- if (moveColumn({
456
- tr,
457
- originIndex,
458
- targetIndex,
459
- select,
460
- pos
461
- })) {
462
- dispatch?.(tr);
463
- return true;
464
- }
465
- return false;
466
- };
467
- }
468
-
469
- //#endregion
470
- //#region src/table/table-commands/move-table-row.ts
471
- /**
472
- * Move a table row from index `origin` to index `target`.
473
- *
474
- * @public
475
- */
476
- function moveTableRow(options) {
477
- return (state, dispatch) => {
478
- const { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;
479
- const tr = state.tr;
480
- if (moveRow({
481
- tr,
482
- originIndex,
483
- targetIndex,
484
- select,
485
- pos
486
- })) {
487
- dispatch?.(tr);
488
- return true;
489
- }
490
- return false;
491
- };
492
- }
493
-
494
- //#endregion
495
- //#region src/table/table-commands.ts
496
- function createEmptyTable(schema, row, col, header) {
497
- const tableType = getNodeType(schema, "table");
498
- const tableRowType = getNodeType(schema, "tableRow");
499
- const tableCellType = getNodeType(schema, "tableCell");
500
- const tableHeaderCellType = getNodeType(schema, "tableHeaderCell");
501
- if (header) {
502
- const headerCell = tableHeaderCellType.createAndFill();
503
- const headerCells = repeat(headerCell, col);
504
- const headerRow = tableRowType.createAndFill(null, headerCells);
505
- const bodyCell = tableCellType.createAndFill();
506
- const bodyCells = repeat(bodyCell, col);
507
- const bodyRow = tableRowType.createAndFill(null, bodyCells);
508
- const bodyRows = repeat(bodyRow, row - 1);
509
- return tableType.createAndFill(null, [headerRow, ...bodyRows]);
510
- } else {
511
- const bodyCell = tableCellType.createAndFill();
512
- const bodyCells = repeat(bodyCell, col);
513
- const bodyRow = tableRowType.createAndFill(null, bodyCells);
514
- const bodyRows = repeat(bodyRow, row);
515
- return tableType.createAndFill(null, bodyRows);
516
- }
517
- }
518
- function repeat(node, length) {
519
- return Array(length).fill(node);
520
- }
521
- /**
522
- * Insert a table node with the given number of rows and columns, and optionally
523
- * a header row.
524
- *
525
- * @param options
526
- *
527
- * @public
528
- */
529
- function insertTable(options) {
530
- return (state, dispatch, view) => {
531
- const { row, col, header = false } = options;
532
- const table = createEmptyTable(state.schema, row, col, header);
533
- return insertNode({ node: table })(state, dispatch, view);
534
- };
535
- }
536
- /**
537
- * When the selection is in a table node, create a default block after the table
538
- * table, and move the cursor there.
539
- *
540
- * @public
541
- */
542
- const exitTable = (state, dispatch) => {
543
- const { $head, $anchor } = state.selection;
544
- if (!$head.sameParent($anchor)) return false;
545
- let tableStart = -1;
546
- let tableDepth = -1;
547
- for (let depth = $head.depth; depth >= 0; depth--) {
548
- const node$1 = $head.node(depth);
549
- if (node$1.type.spec.tableRole === "table") {
550
- tableStart = $head.before(depth);
551
- tableDepth = depth;
552
- }
553
- }
554
- if (tableStart < 0 || tableDepth <= 0) return false;
555
- const above = $head.node(tableDepth - 1);
556
- const after = $head.indexAfter(tableDepth - 1);
557
- const type = defaultBlockAt(above.contentMatchAt(after));
558
- const node = type?.createAndFill();
559
- if (!type || !node || !above.canReplaceWith(after, after, type)) return false;
560
- if (dispatch) {
561
- const pos = $head.after(tableDepth);
562
- const tr = state.tr.replaceWith(pos, pos, node);
563
- tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
564
- dispatch(tr.scrollIntoView());
565
- }
566
- return true;
567
- };
568
- /**
569
- * @public
570
- */
571
- function selectTableColumn(options) {
572
- return (state, dispatch) => {
573
- const range = findCellRange(state.selection, options?.anchor, options?.head);
574
- if (!range) return false;
575
- if (dispatch) {
576
- const [$anchorCell, $headCell] = range;
577
- const selection = CellSelection.colSelection($anchorCell, $headCell);
578
- dispatch(state.tr.setSelection(selection));
579
- }
580
- return true;
581
- };
582
- }
583
- /**
584
- * @public
585
- */
586
- function selectTableRow(options) {
587
- return (state, dispatch) => {
588
- const range = findCellRange(state.selection, options?.anchor, options?.head);
589
- if (!range) return false;
590
- if (dispatch) {
591
- const [$anchorCell, $headCell] = range;
592
- const selection = CellSelection.rowSelection($anchorCell, $headCell);
593
- dispatch(state.tr.setSelection(selection));
594
- }
595
- return true;
596
- };
597
- }
598
- /**
599
- * @public
600
- */
601
- function selectTableCell(options) {
602
- return (state, dispatch) => {
603
- const $cellPos = findCellPos(state.doc, options?.pos ?? state.selection.anchor);
604
- if (!$cellPos) return false;
605
- if (dispatch) {
606
- const selection = new CellSelection($cellPos);
607
- dispatch(state.tr.setSelection(selection));
608
- }
609
- return true;
610
- };
611
- }
612
- /**
613
- * @public
614
- */
615
- function selectTable(options) {
616
- return (state, dispatch) => {
617
- const $pos = options?.pos ? state.doc.resolve(options.pos) : state.selection.$anchor;
618
- const table = findTable($pos);
619
- if (!table) return false;
620
- const map = TableMap.get(table.node);
621
- if (map.map.length === 0) return false;
622
- if (dispatch) {
623
- let tr = state.tr;
624
- const firstCellPosInTable = map.map[0];
625
- const lastCellPosInTable = map.map[map.map.length - 1];
626
- const firstCellPos = table.pos + firstCellPosInTable + 1;
627
- const lastCellPos = table.pos + lastCellPosInTable + 1;
628
- const $firstCellPos = tr.doc.resolve(firstCellPos);
629
- const $lastCellPos = tr.doc.resolve(lastCellPos);
630
- const selection = new CellSelection($firstCellPos, $lastCellPos);
631
- tr = tr.setSelection(selection);
632
- dispatch?.(tr);
633
- }
634
- return true;
635
- };
636
- }
637
- /**
638
- * Adds commands for working with `table` nodes.
639
- *
640
- * @public
641
- */
642
- function defineTableCommands() {
643
- return defineCommands({
644
- insertTable,
645
- exitTable: () => exitTable,
646
- selectTable,
647
- selectTableCell,
648
- selectTableColumn,
649
- selectTableRow,
650
- addTableColumnBefore: () => addColumnBefore,
651
- addTableColumnAfter: () => addColumnAfter,
652
- addTableRowAbove: () => addRowBefore,
653
- addTableRowBelow: () => addRowAfter,
654
- deleteTable: () => deleteTable,
655
- deleteTableColumn: () => deleteColumn,
656
- deleteTableRow: () => deleteRow,
657
- deleteCellSelection: () => deleteCellSelection,
658
- mergeTableCells: () => mergeCells,
659
- splitTableCell: () => splitCell,
660
- moveTableRow,
661
- moveTableColumn
662
- });
663
- }
664
-
665
- //#endregion
666
- //#region src/table/table-drop-indicator.ts
667
- /**
668
- * Hides the drop indicator when dragging a table column or row by using the
669
- * table handle.
670
- *
671
- * @internal
672
- */
673
- function defineTableDropIndicator() {
674
- return defineDropIndicator({ onDrag });
675
- }
676
- const matchMap = /* @__PURE__ */ new WeakMap();
677
- const onDrag = ({ event }) => {
678
- const dataTransfer = event.dataTransfer;
679
- if (!dataTransfer) return true;
680
- let match;
681
- if (matchMap.has(dataTransfer)) match = matchMap.get(dataTransfer);
682
- else {
683
- const types = dataTransfer.types;
684
- match = types.includes("application/x-prosekit-table-handle-drag");
685
- matchMap.set(dataTransfer, match);
686
- }
687
- return !match;
688
- };
689
-
690
- //#endregion
691
- //#region src/table/table-plugins.ts
692
- /**
693
- * @public
694
- */
695
- function defineTablePlugins() {
696
- return definePlugin([tableEditing(), columnResizing()]);
697
- }
698
-
699
- //#endregion
700
- //#region src/table/table-spec.ts
701
- const cellContent = "block+";
702
- const cellAttrs = {
703
- colspan: { default: 1 },
704
- rowspan: { default: 1 },
705
- colwidth: { default: null }
706
- };
707
- const specs = tableNodes({
708
- tableGroup: "block",
709
- cellContent,
710
- cellAttributes: {}
711
- });
712
- /**
713
- * @internal
714
- */
715
- function defineTableSpec() {
716
- return defineNodeSpec({
717
- ...specs["table"],
718
- content: "tableRow+",
719
- name: "table"
720
- });
721
- }
722
- /**
723
- * @internal
724
- */
725
- function defineTableRowSpec() {
726
- return defineNodeSpec({
727
- ...specs["table_row"],
728
- content: "(tableCell | tableHeaderCell)*",
729
- name: "tableRow"
730
- });
731
- }
732
- /**
733
- * @internal
734
- */
735
- function defineTableCellSpec() {
736
- return defineNodeSpec({
737
- ...specs["table_cell"],
738
- name: "tableCell",
739
- attrs: cellAttrs
740
- });
741
- }
742
- function defineTableHeaderCellSpec() {
743
- return defineNodeSpec({
744
- ...specs["table_header"],
745
- name: "tableHeaderCell",
746
- attrs: cellAttrs
747
- });
748
- }
749
-
750
- //#endregion
751
- //#region src/table/table.ts
752
- /**
753
- * @public
754
- */
755
- function defineTable() {
756
- return union(defineTableSpec(), defineTableRowSpec(), defineTableCellSpec(), defineTableHeaderCellSpec(), defineTablePlugins(), defineTableCommands(), defineTableDropIndicator());
757
- }
758
-
759
- //#endregion
760
- export { defineTable, defineTableCellSpec, defineTableCommands, defineTableDropIndicator, defineTableHeaderCellSpec, defineTablePlugins, defineTableRowSpec, defineTableSpec, exitTable, findTable, insertTable, isCellSelection, moveTableColumn, moveTableRow, selectTable, selectTableCell, selectTableColumn, selectTableRow };