reactjs-tiptap-editor 0.4.2 → 1.0.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 (338) hide show
  1. package/lib/ActionMenuButton-BKOg7hkq.js +38 -0
  2. package/lib/ActionMenuButton-DLQyd_gx.cjs +1 -0
  3. package/lib/Attachment.cjs +2 -2
  4. package/lib/Attachment.d.cts +32 -44
  5. package/lib/Attachment.d.ts +32 -44
  6. package/lib/Attachment.js +129 -99
  7. package/lib/Blockquote.cjs +3 -3
  8. package/lib/Blockquote.d.cts +32 -44
  9. package/lib/Blockquote.d.ts +32 -44
  10. package/lib/Blockquote.js +50 -22
  11. package/lib/Bold.cjs +1 -1
  12. package/lib/Bold.d.cts +32 -44
  13. package/lib/Bold.d.ts +32 -44
  14. package/lib/Bold.js +48 -20
  15. package/lib/BulletList.cjs +1 -1
  16. package/lib/BulletList.d.cts +32 -44
  17. package/lib/BulletList.d.ts +32 -44
  18. package/lib/BulletList.js +38 -9
  19. package/lib/Clear.cjs +1 -1
  20. package/lib/Clear.d.cts +32 -44
  21. package/lib/Clear.d.ts +32 -44
  22. package/lib/Clear.js +32 -6
  23. package/lib/Code.cjs +1 -1
  24. package/lib/Code.d.cts +32 -44
  25. package/lib/Code.d.ts +32 -44
  26. package/lib/Code.js +53 -25
  27. package/lib/CodeBlock.cjs +35 -35
  28. package/lib/CodeBlock.d.cts +32 -44
  29. package/lib/CodeBlock.d.ts +32 -44
  30. package/lib/CodeBlock.js +605 -590
  31. package/lib/CodeView.cjs +1 -1
  32. package/lib/CodeView.d.cts +33 -45
  33. package/lib/CodeView.d.ts +33 -45
  34. package/lib/CodeView.js +49 -21
  35. package/lib/Color.cjs +1 -1
  36. package/lib/Color.d.cts +36 -44
  37. package/lib/Color.d.ts +36 -44
  38. package/lib/Color.js +123 -79
  39. package/lib/Column.cjs +1 -0
  40. package/lib/{Document.d.cts → Column.d.cts} +38 -47
  41. package/lib/{Document.d.ts → Column.d.ts} +38 -47
  42. package/lib/Column.js +217 -0
  43. package/lib/{Drawer-CaAfmqNo.js → Drawer-DZ5jvmrX.js} +404 -394
  44. package/lib/Drawer-SRhwOc6T.cjs +1 -0
  45. package/lib/Drawer.cjs +1 -1
  46. package/lib/Drawer.d.cts +32 -44
  47. package/lib/Drawer.d.ts +32 -44
  48. package/lib/Drawer.js +6 -5
  49. package/lib/Emoji.cjs +1 -1
  50. package/lib/Emoji.d.cts +32 -49
  51. package/lib/Emoji.d.ts +32 -49
  52. package/lib/Emoji.js +377 -392
  53. package/lib/Excalidraw-DwBRXEtC.js +345 -0
  54. package/lib/Excalidraw-ZN3DQvDC.cjs +1 -0
  55. package/lib/Excalidraw.cjs +1 -1
  56. package/lib/Excalidraw.d.cts +32 -44
  57. package/lib/Excalidraw.d.ts +32 -44
  58. package/lib/Excalidraw.js +6 -4
  59. package/lib/ExportPdf.cjs +5 -5
  60. package/lib/ExportPdf.d.cts +32 -44
  61. package/lib/ExportPdf.d.ts +32 -44
  62. package/lib/ExportPdf.js +60 -32
  63. package/lib/ExportWord.cjs +1 -1
  64. package/lib/ExportWord.d.cts +33 -45
  65. package/lib/ExportWord.d.ts +33 -45
  66. package/lib/ExportWord.js +84 -21
  67. package/lib/FontFamily.cjs +1 -1
  68. package/lib/FontFamily.d.cts +46 -47
  69. package/lib/FontFamily.d.ts +46 -47
  70. package/lib/FontFamily.js +72 -74
  71. package/lib/FontSize.cjs +1 -1
  72. package/lib/FontSize.d.cts +43 -47
  73. package/lib/FontSize.d.ts +43 -47
  74. package/lib/FontSize.js +72 -64
  75. package/lib/Heading.cjs +1 -1
  76. package/lib/Heading.d.cts +46 -44
  77. package/lib/Heading.d.ts +46 -44
  78. package/lib/Heading.js +91 -73
  79. package/lib/Highlight.cjs +1 -1
  80. package/lib/Highlight.d.cts +36 -44
  81. package/lib/Highlight.d.ts +36 -44
  82. package/lib/Highlight.js +152 -21
  83. package/lib/History.cjs +1 -1
  84. package/lib/History.d.cts +34 -44
  85. package/lib/History.d.ts +34 -44
  86. package/lib/History.js +976 -53
  87. package/lib/HorizontalRule.cjs +1 -1
  88. package/lib/HorizontalRule.d.cts +32 -44
  89. package/lib/HorizontalRule.d.ts +32 -44
  90. package/lib/HorizontalRule.js +97 -17
  91. package/lib/Icon-DUpv2cI6.cjs +1 -0
  92. package/lib/Icon-jKs8Hr6p.js +11 -0
  93. package/lib/Iframe-CmXkEqOd.js +431 -0
  94. package/lib/Iframe-Cvca2G7X.cjs +1 -0
  95. package/lib/Iframe.cjs +1 -1
  96. package/lib/Iframe.d.cts +31 -50
  97. package/lib/Iframe.d.ts +31 -50
  98. package/lib/Iframe.js +6 -4
  99. package/lib/Image.cjs +1 -1
  100. package/lib/Image.d.cts +32 -45
  101. package/lib/Image.d.ts +32 -45
  102. package/lib/Image.js +848 -5
  103. package/lib/ImageGif.cjs +1 -1
  104. package/lib/ImageGif.d.cts +33 -47
  105. package/lib/ImageGif.d.ts +33 -47
  106. package/lib/ImageGif.js +424 -5
  107. package/lib/ImportWord.cjs +48 -48
  108. package/lib/ImportWord.d.cts +33 -45
  109. package/lib/ImportWord.d.ts +33 -45
  110. package/lib/ImportWord.js +2596 -2588
  111. package/lib/Indent.cjs +1 -1
  112. package/lib/Indent.d.cts +32 -44
  113. package/lib/Indent.d.ts +32 -44
  114. package/lib/Indent.js +97 -27
  115. package/lib/Italic.cjs +1 -1
  116. package/lib/Italic.d.cts +32 -44
  117. package/lib/Italic.d.ts +32 -44
  118. package/lib/Italic.js +47 -19
  119. package/lib/Katex-DsYXsjSS.js +2740 -0
  120. package/lib/Katex-XfrNne6U.cjs +4 -0
  121. package/lib/Katex.cjs +1 -1
  122. package/lib/Katex.d.cts +32 -44
  123. package/lib/Katex.d.ts +32 -44
  124. package/lib/Katex.js +5 -196
  125. package/lib/LineHeight.cjs +1 -1
  126. package/lib/LineHeight.d.cts +34 -50
  127. package/lib/LineHeight.d.ts +34 -50
  128. package/lib/LineHeight.js +71 -112
  129. package/lib/Link.cjs +1 -1
  130. package/lib/Link.d.cts +33 -47
  131. package/lib/Link.d.ts +33 -47
  132. package/lib/Link.js +3 -3
  133. package/lib/LinkEditBlock-BZenZq-Z.cjs +5 -0
  134. package/lib/LinkEditBlock-CB8yIffE.js +1241 -0
  135. package/lib/Mention.cjs +1 -1
  136. package/lib/Mention.d.cts +29 -44
  137. package/lib/Mention.d.ts +29 -44
  138. package/lib/Mention.js +112 -124
  139. package/lib/Mermaid.cjs +2 -2
  140. package/lib/Mermaid.d.cts +32 -44
  141. package/lib/Mermaid.d.ts +32 -44
  142. package/lib/Mermaid.js +177 -165
  143. package/lib/MoreMark.cjs +1 -1
  144. package/lib/MoreMark.d.cts +47 -46
  145. package/lib/MoreMark.d.ts +47 -46
  146. package/lib/MoreMark.js +125 -55
  147. package/lib/OrderedList.cjs +1 -1
  148. package/lib/OrderedList.d.cts +32 -44
  149. package/lib/OrderedList.d.ts +32 -44
  150. package/lib/OrderedList.js +37 -9
  151. package/lib/SearchAndReplace.cjs +1 -1
  152. package/lib/SearchAndReplace.d.cts +32 -47
  153. package/lib/SearchAndReplace.d.ts +32 -47
  154. package/lib/SearchAndReplace.js +221 -197
  155. package/lib/SlashCommand.cjs +1 -1
  156. package/lib/SlashCommand.d.cts +44 -51
  157. package/lib/SlashCommand.d.ts +44 -51
  158. package/lib/SlashCommand.js +235 -249
  159. package/lib/Strike.cjs +1 -1
  160. package/lib/Strike.d.cts +32 -44
  161. package/lib/Strike.d.ts +32 -44
  162. package/lib/Strike.js +39 -11
  163. package/lib/Table-B1j1Ebmh.cjs +9 -0
  164. package/lib/Table-Db8TcQX8.js +1984 -0
  165. package/lib/Table.cjs +1 -9
  166. package/lib/Table.d.cts +33 -47
  167. package/lib/Table.d.ts +33 -47
  168. package/lib/Table.js +3 -558
  169. package/lib/TaskList.cjs +1 -1
  170. package/lib/TaskList.d.cts +32 -44
  171. package/lib/TaskList.d.ts +32 -44
  172. package/lib/TaskList.js +38 -10
  173. package/lib/TextAlign.cjs +1 -1
  174. package/lib/TextAlign.d.cts +45 -44
  175. package/lib/TextAlign.d.ts +45 -44
  176. package/lib/TextAlign.js +108 -101
  177. package/lib/TextDirection.cjs +1 -1
  178. package/lib/TextDirection.d.cts +61 -44
  179. package/lib/TextDirection.d.ts +61 -44
  180. package/lib/TextDirection.js +105 -112
  181. package/lib/TextUnderline.cjs +1 -1
  182. package/lib/TextUnderline.d.cts +32 -44
  183. package/lib/TextUnderline.d.ts +32 -44
  184. package/lib/TextUnderline.js +46 -18
  185. package/lib/{Twitter-BFULyqdR.js → Twitter-CXmmjz9R.js} +536 -498
  186. package/lib/Twitter-CtVTIWJW.cjs +1 -0
  187. package/lib/Twitter.cjs +1 -1
  188. package/lib/Twitter.d.cts +32 -44
  189. package/lib/Twitter.d.ts +32 -44
  190. package/lib/Twitter.js +5 -4
  191. package/lib/Video.cjs +1 -1
  192. package/lib/Video.d.cts +32 -44
  193. package/lib/Video.d.ts +32 -44
  194. package/lib/Video.js +261 -4
  195. package/lib/_commonjsHelpers-BItOPCY9.js +28 -0
  196. package/lib/_commonjsHelpers-BTDuMlIz.cjs +1 -0
  197. package/lib/bubble.cjs +2 -0
  198. package/lib/{bubble-extra.d.cts → bubble.d.cts} +58 -59
  199. package/lib/{bubble-extra.d.ts → bubble.d.ts} +58 -59
  200. package/lib/bubble.js +1925 -0
  201. package/lib/button-B12K7BJ4.cjs +1 -0
  202. package/lib/button-DXMsXUEn.js +43 -0
  203. package/lib/clsx-C11secjj.cjs +1 -0
  204. package/lib/clsx-OuTLNxxd.js +16 -0
  205. package/lib/delete-node-CosiBes5.cjs +1 -0
  206. package/lib/delete-node-IyVmiRbI.js +22 -0
  207. package/lib/dialog-CaCS-W5S.cjs +1 -0
  208. package/lib/dialog-PtQivpHS.js +100 -0
  209. package/lib/dom-dataset-BqoJhJXt.cjs +1 -0
  210. package/lib/dom-dataset-CIEeltF6.js +47 -0
  211. package/lib/dropdown-menu-BPp2Z_U-.js +136 -0
  212. package/lib/dropdown-menu-CdSm4emp.cjs +1 -0
  213. package/lib/file-BLas99n7.js +43 -0
  214. package/lib/file-i7e4nQY2.cjs +1 -0
  215. package/lib/floating-ui.dom-U1vPFQ5f.js +1151 -0
  216. package/lib/floating-ui.dom-VCrc58uF.cjs +1 -0
  217. package/lib/icons-Cllpys39.js +362 -0
  218. package/lib/icons-CqHjeW5T.cjs +1 -0
  219. package/lib/index-BH4bc3jN.cjs +33 -0
  220. package/lib/index-BPfVXs5_.js +2380 -0
  221. package/lib/index-Bnmd0WvY.js +1631 -0
  222. package/lib/{index-Ch6dBBad.js → index-CBce_TWY.js} +40 -42
  223. package/lib/{index-5iBZLua9.cjs → index-D-5U8dY8.cjs} +8 -8
  224. package/lib/{index-ByurDDMv.js → index-D2TUfKkC.js} +2 -2
  225. package/lib/index-DV5kbgRU.cjs +1 -0
  226. package/lib/{index-LmrOdnen.js → index-DYkucCoF.js} +396 -495
  227. package/lib/index-Dfmm6FTT.cjs +1 -0
  228. package/lib/index-DnWWK9F_.js +6374 -0
  229. package/lib/index-DzcKxutn.js +632 -0
  230. package/lib/index-DzvuNTxo.cjs +4 -0
  231. package/lib/{index-BeCTd5v2.cjs → index-N--9MohJ.cjs} +1 -1
  232. package/lib/index-RfTlOzIr.cjs +22 -0
  233. package/lib/index.cjs +132 -1
  234. package/lib/index.d.cts +34 -285
  235. package/lib/index.d.ts +34 -285
  236. package/lib/index.js +243 -2
  237. package/lib/input-_ECRfn3Y.cjs +1 -0
  238. package/lib/input-wJ9PDEzZ.js +21 -0
  239. package/lib/isNumber-ClPupm7P.cjs +1 -0
  240. package/lib/isNumber-fpLGS0AZ.js +15 -0
  241. package/lib/label-BkgAe7IY.cjs +1 -0
  242. package/lib/label-CGdLYWv7.js +19 -0
  243. package/lib/locale-bundle.cjs +1 -1
  244. package/lib/locale-bundle.d.cts +5410 -62
  245. package/lib/locale-bundle.d.ts +5410 -62
  246. package/lib/locale-bundle.js +9 -7
  247. package/lib/popover-BgmUNMHj.cjs +1 -0
  248. package/lib/popover-CAuEW0Mr.js +23 -0
  249. package/lib/separator-CuBW_w98.js +328 -0
  250. package/lib/separator-DRIrVZ2N.cjs +1 -0
  251. package/lib/store-DX599H5W.js +10 -0
  252. package/lib/store-WStcMOiW.cjs +1 -0
  253. package/lib/style.css +1 -1
  254. package/lib/switch-CnLJ7Y-b.cjs +1 -0
  255. package/lib/switch-Coix_FA1.js +27 -0
  256. package/lib/tabs-B5mVSN1I.js +46 -0
  257. package/lib/tabs-BoLCMcCI.cjs +1 -0
  258. package/lib/textarea-B-6zTKQz.cjs +1 -0
  259. package/lib/{textarea-aPtytkDx.js → textarea-DUUM1jZd.js} +1 -1
  260. package/lib/theme-B7aAsK_T.js +15 -0
  261. package/lib/theme-D8_cxGqB.cjs +1 -0
  262. package/lib/throttle-CdwDrFpn.js +249 -0
  263. package/lib/throttle-qX7Yjtsg.cjs +1 -0
  264. package/lib/toggle-Cdp4IT2U.js +85 -0
  265. package/lib/toggle-D41PzQLJ.cjs +1 -0
  266. package/lib/tooltip-BuEiE96N.cjs +1 -0
  267. package/lib/tooltip-CopwsU8q.js +23 -0
  268. package/lib/updatePosition-8Sdem5jb.cjs +1 -0
  269. package/lib/updatePosition-BPmcE0YD.js +215 -0
  270. package/lib/use-toast-Bz3QCOtE.cjs +1 -0
  271. package/lib/use-toast-Crf7-q5H.js +98 -0
  272. package/lib/useButtonProps-BsEd4zYM.js +141 -0
  273. package/lib/useButtonProps-C6Vpn190.cjs +1 -0
  274. package/package.json +22 -105
  275. package/lib/ActionMenuButton-CYdM1xx5.cjs +0 -1
  276. package/lib/ActionMenuButton-DKRF6oa0.js +0 -33
  277. package/lib/BaseKit.cjs +0 -3
  278. package/lib/BaseKit.d.cts +0 -481
  279. package/lib/BaseKit.d.ts +0 -481
  280. package/lib/BaseKit.js +0 -132
  281. package/lib/Document.cjs +0 -1
  282. package/lib/Document.js +0 -9
  283. package/lib/Drawer-CdvCMSzN.cjs +0 -1
  284. package/lib/Excalidraw-BbMQhNvs.cjs +0 -1
  285. package/lib/Excalidraw-CVWz2Vyn.js +0 -290
  286. package/lib/FormatPainter.cjs +0 -1
  287. package/lib/FormatPainter.d.cts +0 -372
  288. package/lib/FormatPainter.d.ts +0 -372
  289. package/lib/FormatPainter.js +0 -76
  290. package/lib/ListItem.cjs +0 -1
  291. package/lib/ListItem.d.cts +0 -290
  292. package/lib/ListItem.d.ts +0 -290
  293. package/lib/ListItem.js +0 -7
  294. package/lib/MultiColumn.cjs +0 -1
  295. package/lib/MultiColumn.d.cts +0 -294
  296. package/lib/MultiColumn.d.ts +0 -294
  297. package/lib/MultiColumn.js +0 -8
  298. package/lib/RichTextEditor-CxvwGvQG.cjs +0 -142
  299. package/lib/RichTextEditor-DGcKEUGr.js +0 -22166
  300. package/lib/Selection.cjs +0 -1
  301. package/lib/Selection.d.cts +0 -289
  302. package/lib/Selection.d.ts +0 -289
  303. package/lib/Selection.js +0 -25
  304. package/lib/SubAndSuperScript.cjs +0 -1
  305. package/lib/SubAndSuperScript.d.cts +0 -377
  306. package/lib/SubAndSuperScript.d.ts +0 -377
  307. package/lib/SubAndSuperScript.js +0 -43
  308. package/lib/TableOfContent.cjs +0 -1
  309. package/lib/TableOfContent.d.cts +0 -291
  310. package/lib/TableOfContent.d.ts +0 -291
  311. package/lib/TableOfContent.js +0 -185
  312. package/lib/TextBubble.cjs +0 -1
  313. package/lib/TextBubble.d.cts +0 -362
  314. package/lib/TextBubble.d.ts +0 -362
  315. package/lib/TextBubble.js +0 -133
  316. package/lib/TrailingNode.cjs +0 -1
  317. package/lib/TrailingNode.d.cts +0 -297
  318. package/lib/TrailingNode.d.ts +0 -297
  319. package/lib/TrailingNode.js +0 -41
  320. package/lib/Twitter-Cutpkh3h.cjs +0 -1
  321. package/lib/bubble-extra.cjs +0 -2
  322. package/lib/bubble-extra.js +0 -631
  323. package/lib/dom-dataset-_6-diIRQ.cjs +0 -33
  324. package/lib/dom-dataset-lYeH6gfI.js +0 -2361
  325. package/lib/index-6D1J-A-o.cjs +0 -1
  326. package/lib/index-B96Cclrj.cjs +0 -3
  327. package/lib/index-BBz7Nmv9.js +0 -55
  328. package/lib/index-CUogRI7j.cjs +0 -1
  329. package/lib/index-DF2Lp4HZ.cjs +0 -100
  330. package/lib/index-D_L6n8O8.js +0 -76
  331. package/lib/index-Dbvi-Bvh.cjs +0 -1
  332. package/lib/index-DpCrt7xs.cjs +0 -1
  333. package/lib/index-DsAX1Vq8.cjs +0 -1
  334. package/lib/index-Dy4DlW9o.js +0 -12
  335. package/lib/index-J3jHHZ4d.js +0 -200
  336. package/lib/index-VvXaaKe3.js +0 -898
  337. package/lib/index-kbO3iWqL.js +0 -13432
  338. package/lib/textarea-DFo_aXnj.cjs +0 -1
@@ -0,0 +1,1984 @@
1
+ import { I as de, S as E, Q as Ve, T as $, F as v, u as L, P as ke, s as Ke, R as Xe, N as J, m as Z, K as Ue, L as Ge, E as Ee, U as qe } from "./index-DnWWK9F_.js";
2
+ import { TextSelection as Je } from "@tiptap/pm/state";
3
+ import { k as Ze, D as oe, a as ne } from "./index-Bnmd0WvY.js";
4
+ import { jsxs as ee, jsx as k, Fragment as Ye } from "react/jsx-runtime";
5
+ import { A as Qe } from "./toggle-Cdp4IT2U.js";
6
+ import { useState as _ } from "react";
7
+ import { a as et } from "./index-BPfVXs5_.js";
8
+ import { T as O, p as F, q as j } from "./index-DYkucCoF.js";
9
+ import { P as tt, a as ot, b as nt } from "./popover-CAuEW0Mr.js";
10
+ import { u as lt, a as rt } from "./useButtonProps-BsEd4zYM.js";
11
+ let le, re;
12
+ if (typeof WeakMap < "u") {
13
+ let t = /* @__PURE__ */ new WeakMap();
14
+ le = (e) => t.get(e), re = (e, o) => (t.set(e, o), o);
15
+ } else {
16
+ const t = [];
17
+ let o = 0;
18
+ le = (n) => {
19
+ for (let l = 0; l < t.length; l += 2) if (t[l] == n) return t[l + 1];
20
+ }, re = (n, l) => (o == 10 && (o = 0), t[o++] = n, t[o++] = l);
21
+ }
22
+ var C = class {
23
+ constructor(t, e, o, n) {
24
+ this.width = t, this.height = e, this.map = o, this.problems = n;
25
+ }
26
+ findCell(t) {
27
+ for (let e = 0; e < this.map.length; e++) {
28
+ const o = this.map[e];
29
+ if (o != t) continue;
30
+ const n = e % this.width, l = e / this.width | 0;
31
+ let r = n + 1, s = l + 1;
32
+ for (let i = 1; r < this.width && this.map[e + i] == o; i++) r++;
33
+ for (let i = 1; s < this.height && this.map[e + this.width * i] == o; i++) s++;
34
+ return {
35
+ left: n,
36
+ top: l,
37
+ right: r,
38
+ bottom: s
39
+ };
40
+ }
41
+ throw new RangeError(`No cell with offset ${t} found`);
42
+ }
43
+ colCount(t) {
44
+ for (let e = 0; e < this.map.length; e++) if (this.map[e] == t) return e % this.width;
45
+ throw new RangeError(`No cell with offset ${t} found`);
46
+ }
47
+ nextCell(t, e, o) {
48
+ const { left: n, right: l, top: r, bottom: s } = this.findCell(t);
49
+ return e == "horiz" ? (o < 0 ? n == 0 : l == this.width) ? null : this.map[r * this.width + (o < 0 ? n - 1 : l)] : (o < 0 ? r == 0 : s == this.height) ? null : this.map[n + this.width * (o < 0 ? r - 1 : s)];
50
+ }
51
+ rectBetween(t, e) {
52
+ const { left: o, right: n, top: l, bottom: r } = this.findCell(t), { left: s, right: i, top: c, bottom: a } = this.findCell(e);
53
+ return {
54
+ left: Math.min(o, s),
55
+ top: Math.min(l, c),
56
+ right: Math.max(n, i),
57
+ bottom: Math.max(r, a)
58
+ };
59
+ }
60
+ cellsInRect(t) {
61
+ const e = [], o = {};
62
+ for (let n = t.top; n < t.bottom; n++) for (let l = t.left; l < t.right; l++) {
63
+ const r = n * this.width + l, s = this.map[r];
64
+ o[s] || (o[s] = !0, !(l == t.left && l && this.map[r - 1] == s || n == t.top && n && this.map[r - this.width] == s) && e.push(s));
65
+ }
66
+ return e;
67
+ }
68
+ positionAt(t, e, o) {
69
+ for (let n = 0, l = 0; ; n++) {
70
+ const r = l + o.child(n).nodeSize;
71
+ if (n == t) {
72
+ let s = e + t * this.width;
73
+ const i = (t + 1) * this.width;
74
+ for (; s < i && this.map[s] < l; ) s++;
75
+ return s == i ? r - 1 : this.map[s];
76
+ }
77
+ l = r;
78
+ }
79
+ }
80
+ static get(t) {
81
+ return le(t) || re(t, st(t));
82
+ }
83
+ };
84
+ function st(t) {
85
+ if (t.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + t.type.name);
86
+ const e = it(t), o = t.childCount, n = [];
87
+ let l = 0, r = null;
88
+ const s = [];
89
+ for (let a = 0, d = e * o; a < d; a++) n[a] = 0;
90
+ for (let a = 0, d = 0; a < o; a++) {
91
+ const u = t.child(a);
92
+ d++;
93
+ for (let p = 0; ; p++) {
94
+ for (; l < n.length && n[l] != 0; ) l++;
95
+ if (p == u.childCount) break;
96
+ const m = u.child(p), { colspan: g, rowspan: b, colwidth: S } = m.attrs;
97
+ for (let A = 0; A < b; A++) {
98
+ if (A + a >= o) {
99
+ (r || (r = [])).push({
100
+ type: "overlong_rowspan",
101
+ pos: d,
102
+ n: b - A
103
+ });
104
+ break;
105
+ }
106
+ const z = l + A * e;
107
+ for (let T = 0; T < g; T++) {
108
+ n[z + T] == 0 ? n[z + T] = d : (r || (r = [])).push({
109
+ type: "collision",
110
+ row: a,
111
+ pos: d,
112
+ n: g - T
113
+ });
114
+ const P = S && S[T];
115
+ if (P) {
116
+ const B = (z + T) % e * 2, Q = s[B];
117
+ Q == null || Q != P && s[B + 1] == 1 ? (s[B] = P, s[B + 1] = 1) : Q == P && s[B + 1]++;
118
+ }
119
+ }
120
+ }
121
+ l += g, d += m.nodeSize;
122
+ }
123
+ const f = (a + 1) * e;
124
+ let h = 0;
125
+ for (; l < f; ) n[l++] == 0 && h++;
126
+ h && (r || (r = [])).push({
127
+ type: "missing",
128
+ row: a,
129
+ n: h
130
+ }), d++;
131
+ }
132
+ (e === 0 || o === 0) && (r || (r = [])).push({ type: "zero_sized" });
133
+ const i = new C(e, o, n, r);
134
+ let c = !1;
135
+ for (let a = 0; !c && a < s.length; a += 2) s[a] != null && s[a + 1] < o && (c = !0);
136
+ return c && ct(i, s, t), i;
137
+ }
138
+ function it(t) {
139
+ let e = -1, o = !1;
140
+ for (let n = 0; n < t.childCount; n++) {
141
+ const l = t.child(n);
142
+ let r = 0;
143
+ if (o) for (let s = 0; s < n; s++) {
144
+ const i = t.child(s);
145
+ for (let c = 0; c < i.childCount; c++) {
146
+ const a = i.child(c);
147
+ s + a.attrs.rowspan > n && (r += a.attrs.colspan);
148
+ }
149
+ }
150
+ for (let s = 0; s < l.childCount; s++) {
151
+ const i = l.child(s);
152
+ r += i.attrs.colspan, i.attrs.rowspan > 1 && (o = !0);
153
+ }
154
+ e == -1 ? e = r : e != r && (e = Math.max(e, r));
155
+ }
156
+ return e;
157
+ }
158
+ function ct(t, e, o) {
159
+ t.problems || (t.problems = []);
160
+ const n = {};
161
+ for (let l = 0; l < t.map.length; l++) {
162
+ const r = t.map[l];
163
+ if (n[r]) continue;
164
+ n[r] = !0;
165
+ const s = o.nodeAt(r);
166
+ if (!s) throw new RangeError(`No cell with offset ${r} found`);
167
+ let i = null;
168
+ const c = s.attrs;
169
+ for (let a = 0; a < c.colspan; a++) {
170
+ const d = e[(l + a) % t.width * 2];
171
+ d != null && (!c.colwidth || c.colwidth[a] != d) && ((i || (i = at(c)))[a] = d);
172
+ }
173
+ i && t.problems.unshift({
174
+ type: "colwidth mismatch",
175
+ pos: r,
176
+ colwidth: i
177
+ });
178
+ }
179
+ }
180
+ function at(t) {
181
+ if (t.colwidth) return t.colwidth.slice();
182
+ const e = [];
183
+ for (let o = 0; o < t.colspan; o++) e.push(0);
184
+ return e;
185
+ }
186
+ function y(t) {
187
+ let e = t.cached.tableNodeTypes;
188
+ if (!e) {
189
+ e = t.cached.tableNodeTypes = {};
190
+ for (const o in t.nodes) {
191
+ const n = t.nodes[o], l = n.spec.tableRole;
192
+ l && (e[l] = n);
193
+ }
194
+ }
195
+ return e;
196
+ }
197
+ const H = new de("selectingCells");
198
+ function D(t) {
199
+ for (let e = t.depth - 1; e > 0; e--) if (t.node(e).type.spec.tableRole == "row") return t.node(0).resolve(t.before(e + 1));
200
+ return null;
201
+ }
202
+ function dt(t) {
203
+ for (let e = t.depth; e > 0; e--) {
204
+ const o = t.node(e).type.spec.tableRole;
205
+ if (o === "cell" || o === "header_cell") return t.node(e);
206
+ }
207
+ return null;
208
+ }
209
+ function R(t) {
210
+ const e = t.selection.$head;
211
+ for (let o = e.depth; o > 0; o--) if (e.node(o).type.spec.tableRole == "row") return !0;
212
+ return !1;
213
+ }
214
+ function Y(t) {
215
+ const e = t.selection;
216
+ if ("$anchorCell" in e && e.$anchorCell) return e.$anchorCell.pos > e.$headCell.pos ? e.$anchorCell : e.$headCell;
217
+ if ("node" in e && e.node && e.node.type.spec.tableRole == "cell") return e.$anchor;
218
+ const o = D(e.$head) || ut(e.$head);
219
+ if (o) return o;
220
+ throw new RangeError(`No cell found around position ${e.head}`);
221
+ }
222
+ function ut(t) {
223
+ for (let e = t.nodeAfter, o = t.pos; e; e = e.firstChild, o++) {
224
+ const n = e.type.spec.tableRole;
225
+ if (n == "cell" || n == "header_cell") return t.doc.resolve(o);
226
+ }
227
+ for (let e = t.nodeBefore, o = t.pos; e; e = e.lastChild, o--) {
228
+ const n = e.type.spec.tableRole;
229
+ if (n == "cell" || n == "header_cell") return t.doc.resolve(o - e.nodeSize);
230
+ }
231
+ }
232
+ function se(t) {
233
+ return t.parent.type.spec.tableRole == "row" && !!t.nodeAfter;
234
+ }
235
+ function ft(t) {
236
+ return t.node(0).resolve(t.pos + t.nodeAfter.nodeSize);
237
+ }
238
+ function ue(t, e) {
239
+ return t.depth == e.depth && t.pos >= e.start(-1) && t.pos <= e.end(-1);
240
+ }
241
+ function ze(t, e, o) {
242
+ const n = t.node(-1), l = C.get(n), r = t.start(-1), s = l.nextCell(t.pos - r, e, o);
243
+ return s == null ? null : t.node(0).resolve(r + s);
244
+ }
245
+ function W(t, e, o = 1) {
246
+ const n = {
247
+ ...t,
248
+ colspan: t.colspan - o
249
+ };
250
+ return n.colwidth && (n.colwidth = n.colwidth.slice(), n.colwidth.splice(e, o), n.colwidth.some((l) => l > 0) || (n.colwidth = null)), n;
251
+ }
252
+ function He(t, e, o = 1) {
253
+ const n = {
254
+ ...t,
255
+ colspan: t.colspan + o
256
+ };
257
+ if (n.colwidth) {
258
+ n.colwidth = n.colwidth.slice();
259
+ for (let l = 0; l < o; l++) n.colwidth.splice(e, 0, 0);
260
+ }
261
+ return n;
262
+ }
263
+ function ht(t, e, o) {
264
+ const n = y(e.type.schema).header_cell;
265
+ for (let l = 0; l < t.height; l++) if (e.nodeAt(t.map[o + l * t.width]).type != n) return !1;
266
+ return !0;
267
+ }
268
+ var w = class N extends E {
269
+ constructor(e, o = e) {
270
+ const n = e.node(-1), l = C.get(n), r = e.start(-1), s = l.rectBetween(e.pos - r, o.pos - r), i = e.node(0), c = l.cellsInRect(s).filter((d) => d != o.pos - r);
271
+ c.unshift(o.pos - r);
272
+ const a = c.map((d) => {
273
+ const u = n.nodeAt(d);
274
+ if (!u) throw new RangeError(`No cell with offset ${d} found`);
275
+ const f = r + d + 1;
276
+ return new Ve(i.resolve(f), i.resolve(f + u.content.size));
277
+ });
278
+ super(a[0].$from, a[0].$to, a), this.$anchorCell = e, this.$headCell = o;
279
+ }
280
+ map(e, o) {
281
+ const n = e.resolve(o.map(this.$anchorCell.pos)), l = e.resolve(o.map(this.$headCell.pos));
282
+ if (se(n) && se(l) && ue(n, l)) {
283
+ const r = this.$anchorCell.node(-1) != n.node(-1);
284
+ return r && this.isRowSelection() ? N.rowSelection(n, l) : r && this.isColSelection() ? N.colSelection(n, l) : new N(n, l);
285
+ }
286
+ return $.between(n, l);
287
+ }
288
+ content() {
289
+ const e = this.$anchorCell.node(-1), o = C.get(e), n = this.$anchorCell.start(-1), l = o.rectBetween(this.$anchorCell.pos - n, this.$headCell.pos - n), r = {}, s = [];
290
+ for (let c = l.top; c < l.bottom; c++) {
291
+ const a = [];
292
+ for (let d = c * o.width + l.left, u = l.left; u < l.right; u++, d++) {
293
+ const f = o.map[d];
294
+ if (r[f]) continue;
295
+ r[f] = !0;
296
+ const h = o.findCell(f);
297
+ let p = e.nodeAt(f);
298
+ if (!p) throw new RangeError(`No cell with offset ${f} found`);
299
+ const m = l.left - h.left, g = h.right - l.right;
300
+ if (m > 0 || g > 0) {
301
+ let b = p.attrs;
302
+ if (m > 0 && (b = W(b, 0, m)), g > 0 && (b = W(b, b.colspan - g, g)), h.left < l.left) {
303
+ if (p = p.type.createAndFill(b), !p) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`);
304
+ } else p = p.type.create(b, p.content);
305
+ }
306
+ if (h.top < l.top || h.bottom > l.bottom) {
307
+ const b = {
308
+ ...p.attrs,
309
+ rowspan: Math.min(h.bottom, l.bottom) - Math.max(h.top, l.top)
310
+ };
311
+ h.top < l.top ? p = p.type.createAndFill(b) : p = p.type.create(b, p.content);
312
+ }
313
+ a.push(p);
314
+ }
315
+ s.push(e.child(c).copy(v.from(a)));
316
+ }
317
+ const i = this.isColSelection() && this.isRowSelection() ? e : s;
318
+ return new L(v.from(i), 1, 1);
319
+ }
320
+ replace(e, o = L.empty) {
321
+ const n = e.steps.length, l = this.ranges;
322
+ for (let s = 0; s < l.length; s++) {
323
+ const { $from: i, $to: c } = l[s], a = e.mapping.slice(n);
324
+ e.replace(a.map(i.pos), a.map(c.pos), s ? L.empty : o);
325
+ }
326
+ const r = E.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)), -1);
327
+ r && e.setSelection(r);
328
+ }
329
+ replaceWith(e, o) {
330
+ this.replace(e, new L(v.from(o), 0, 0));
331
+ }
332
+ forEachCell(e) {
333
+ const o = this.$anchorCell.node(-1), n = C.get(o), l = this.$anchorCell.start(-1), r = n.cellsInRect(n.rectBetween(this.$anchorCell.pos - l, this.$headCell.pos - l));
334
+ for (let s = 0; s < r.length; s++) e(o.nodeAt(r[s]), l + r[s]);
335
+ }
336
+ isColSelection() {
337
+ const e = this.$anchorCell.index(-1), o = this.$headCell.index(-1);
338
+ if (Math.min(e, o) > 0) return !1;
339
+ const n = e + this.$anchorCell.nodeAfter.attrs.rowspan, l = o + this.$headCell.nodeAfter.attrs.rowspan;
340
+ return Math.max(n, l) == this.$headCell.node(-1).childCount;
341
+ }
342
+ static colSelection(e, o = e) {
343
+ const n = e.node(-1), l = C.get(n), r = e.start(-1), s = l.findCell(e.pos - r), i = l.findCell(o.pos - r), c = e.node(0);
344
+ return s.top <= i.top ? (s.top > 0 && (e = c.resolve(r + l.map[s.left])), i.bottom < l.height && (o = c.resolve(r + l.map[l.width * (l.height - 1) + i.right - 1]))) : (i.top > 0 && (o = c.resolve(r + l.map[i.left])), s.bottom < l.height && (e = c.resolve(r + l.map[l.width * (l.height - 1) + s.right - 1]))), new N(e, o);
345
+ }
346
+ isRowSelection() {
347
+ const e = this.$anchorCell.node(-1), o = C.get(e), n = this.$anchorCell.start(-1), l = o.colCount(this.$anchorCell.pos - n), r = o.colCount(this.$headCell.pos - n);
348
+ if (Math.min(l, r) > 0) return !1;
349
+ const s = l + this.$anchorCell.nodeAfter.attrs.colspan, i = r + this.$headCell.nodeAfter.attrs.colspan;
350
+ return Math.max(s, i) == o.width;
351
+ }
352
+ eq(e) {
353
+ return e instanceof N && e.$anchorCell.pos == this.$anchorCell.pos && e.$headCell.pos == this.$headCell.pos;
354
+ }
355
+ static rowSelection(e, o = e) {
356
+ const n = e.node(-1), l = C.get(n), r = e.start(-1), s = l.findCell(e.pos - r), i = l.findCell(o.pos - r), c = e.node(0);
357
+ return s.left <= i.left ? (s.left > 0 && (e = c.resolve(r + l.map[s.top * l.width])), i.right < l.width && (o = c.resolve(r + l.map[l.width * (i.top + 1) - 1]))) : (i.left > 0 && (o = c.resolve(r + l.map[i.top * l.width])), s.right < l.width && (e = c.resolve(r + l.map[l.width * (s.top + 1) - 1]))), new N(e, o);
358
+ }
359
+ toJSON() {
360
+ return {
361
+ type: "cell",
362
+ anchor: this.$anchorCell.pos,
363
+ head: this.$headCell.pos
364
+ };
365
+ }
366
+ static fromJSON(e, o) {
367
+ return new N(e.resolve(o.anchor), e.resolve(o.head));
368
+ }
369
+ static create(e, o, n = o) {
370
+ return new N(e.resolve(o), e.resolve(n));
371
+ }
372
+ getBookmark() {
373
+ return new pt(this.$anchorCell.pos, this.$headCell.pos);
374
+ }
375
+ };
376
+ w.prototype.visible = !1;
377
+ E.jsonID("cell", w);
378
+ var pt = class Le {
379
+ constructor(e, o) {
380
+ this.anchor = e, this.head = o;
381
+ }
382
+ map(e) {
383
+ return new Le(e.map(this.anchor), e.map(this.head));
384
+ }
385
+ resolve(e) {
386
+ const o = e.resolve(this.anchor), n = e.resolve(this.head);
387
+ return o.parent.type.spec.tableRole == "row" && n.parent.type.spec.tableRole == "row" && o.index() < o.parent.childCount && n.index() < n.parent.childCount && ue(o, n) ? new w(o, n) : E.near(n, 1);
388
+ }
389
+ };
390
+ function mt(t) {
391
+ if (!(t.selection instanceof w)) return null;
392
+ const e = [];
393
+ return t.selection.forEachCell((o, n) => {
394
+ e.push(ne.node(n, n + o.nodeSize, { class: "selectedCell" }));
395
+ }), oe.create(t.doc, e);
396
+ }
397
+ function gt({ $from: t, $to: e }) {
398
+ if (t.pos == e.pos || t.pos < e.pos - 6) return !1;
399
+ let o = t.pos, n = e.pos, l = t.depth;
400
+ for (; l >= 0 && !(t.after(l + 1) < t.end(l)); l--, o++) ;
401
+ for (let r = e.depth; r >= 0 && !(e.before(r + 1) > e.start(r)); r--, n--) ;
402
+ return o == n && /row|table/.test(t.node(l).type.spec.tableRole);
403
+ }
404
+ function bt({ $from: t, $to: e }) {
405
+ let o, n;
406
+ for (let l = t.depth; l > 0; l--) {
407
+ const r = t.node(l);
408
+ if (r.type.spec.tableRole === "cell" || r.type.spec.tableRole === "header_cell") {
409
+ o = r;
410
+ break;
411
+ }
412
+ }
413
+ for (let l = e.depth; l > 0; l--) {
414
+ const r = e.node(l);
415
+ if (r.type.spec.tableRole === "cell" || r.type.spec.tableRole === "header_cell") {
416
+ n = r;
417
+ break;
418
+ }
419
+ }
420
+ return o !== n && e.parentOffset === 0;
421
+ }
422
+ function wt(t, e, o) {
423
+ const n = (e || t).selection, l = (e || t).doc;
424
+ let r, s;
425
+ if (n instanceof Ke && (s = n.node.type.spec.tableRole)) {
426
+ if (s == "cell" || s == "header_cell") r = w.create(l, n.from);
427
+ else if (s == "row") {
428
+ const i = l.resolve(n.from + 1);
429
+ r = w.rowSelection(i, i);
430
+ } else if (!o) {
431
+ const i = C.get(n.node), c = n.from + 1, a = c + i.map[i.width * i.height - 1];
432
+ r = w.create(l, c + 1, a);
433
+ }
434
+ } else n instanceof $ && gt(n) ? r = $.create(l, n.from) : n instanceof $ && bt(n) && (r = $.create(l, n.$from.start(), n.$from.end()));
435
+ return r && (e || (e = t.tr)).setSelection(r), e;
436
+ }
437
+ const Ct = new de("fix-tables");
438
+ function $e(t, e, o, n) {
439
+ const l = t.childCount, r = e.childCount;
440
+ e: for (let s = 0, i = 0; s < r; s++) {
441
+ const c = e.child(s);
442
+ for (let a = i, d = Math.min(l, s + 3); a < d; a++) if (t.child(a) == c) {
443
+ i = a + 1, o += c.nodeSize;
444
+ continue e;
445
+ }
446
+ n(c, o), i < l && t.child(i).sameMarkup(c) ? $e(t.child(i), c, o + 1, n) : c.nodesBetween(0, c.content.size, n, o + 1), o += c.nodeSize;
447
+ }
448
+ }
449
+ function We(t, e) {
450
+ let o;
451
+ const n = (l, r) => {
452
+ l.type.spec.tableRole == "table" && (o = yt(t, l, r, o));
453
+ };
454
+ return e ? e.doc != t.doc && $e(e.doc, t.doc, 0, n) : t.doc.descendants(n), o;
455
+ }
456
+ function yt(t, e, o, n) {
457
+ const l = C.get(e);
458
+ if (!l.problems) return n;
459
+ n || (n = t.tr);
460
+ const r = [];
461
+ for (let c = 0; c < l.height; c++) r.push(0);
462
+ for (let c = 0; c < l.problems.length; c++) {
463
+ const a = l.problems[c];
464
+ if (a.type == "collision") {
465
+ const d = e.nodeAt(a.pos);
466
+ if (!d) continue;
467
+ const u = d.attrs;
468
+ for (let f = 0; f < u.rowspan; f++) r[a.row + f] += a.n;
469
+ n.setNodeMarkup(n.mapping.map(o + 1 + a.pos), null, W(u, u.colspan - a.n, a.n));
470
+ } else if (a.type == "missing") r[a.row] += a.n;
471
+ else if (a.type == "overlong_rowspan") {
472
+ const d = e.nodeAt(a.pos);
473
+ if (!d) continue;
474
+ n.setNodeMarkup(n.mapping.map(o + 1 + a.pos), null, {
475
+ ...d.attrs,
476
+ rowspan: d.attrs.rowspan - a.n
477
+ });
478
+ } else if (a.type == "colwidth mismatch") {
479
+ const d = e.nodeAt(a.pos);
480
+ if (!d) continue;
481
+ n.setNodeMarkup(n.mapping.map(o + 1 + a.pos), null, {
482
+ ...d.attrs,
483
+ colwidth: a.colwidth
484
+ });
485
+ } else if (a.type == "zero_sized") {
486
+ const d = n.mapping.map(o);
487
+ n.delete(d, d + e.nodeSize);
488
+ }
489
+ }
490
+ let s, i;
491
+ for (let c = 0; c < r.length; c++) r[c] && (s == null && (s = c), i = c);
492
+ for (let c = 0, a = o + 1; c < l.height; c++) {
493
+ const d = e.child(c), u = a + d.nodeSize, f = r[c];
494
+ if (f > 0) {
495
+ let h = "cell";
496
+ d.firstChild && (h = d.firstChild.type.spec.tableRole);
497
+ const p = [];
498
+ for (let g = 0; g < f; g++) {
499
+ const b = y(t.schema)[h].createAndFill();
500
+ b && p.push(b);
501
+ }
502
+ const m = (c == 0 || s == c - 1) && i == c ? a + 1 : u - 1;
503
+ n.insert(n.mapping.map(m), p);
504
+ }
505
+ a = u;
506
+ }
507
+ return n.setMeta(Ct, { fixTables: !0 });
508
+ }
509
+ function M(t) {
510
+ const e = t.selection, o = Y(t), n = o.node(-1), l = o.start(-1), r = C.get(n);
511
+ return {
512
+ ...e instanceof w ? r.rectBetween(e.$anchorCell.pos - l, e.$headCell.pos - l) : r.findCell(o.pos - l),
513
+ tableStart: l,
514
+ map: r,
515
+ table: n
516
+ };
517
+ }
518
+ function De(t, { map: e, tableStart: o, table: n }, l) {
519
+ let r = l > 0 ? -1 : 0;
520
+ ht(e, n, l + r) && (r = l == 0 || l == e.width ? null : 0);
521
+ for (let s = 0; s < e.height; s++) {
522
+ const i = s * e.width + l;
523
+ if (l > 0 && l < e.width && e.map[i - 1] == e.map[i]) {
524
+ const c = e.map[i], a = n.nodeAt(c);
525
+ t.setNodeMarkup(t.mapping.map(o + c), null, He(a.attrs, l - e.colCount(c))), s += a.attrs.rowspan - 1;
526
+ } else {
527
+ const c = r == null ? y(n.type.schema).cell : n.nodeAt(e.map[i + r]).type, a = e.positionAt(s, l, n);
528
+ t.insert(t.mapping.map(o + a), c.createAndFill());
529
+ }
530
+ }
531
+ return t;
532
+ }
533
+ function St(t, e) {
534
+ if (!R(t)) return !1;
535
+ if (e) {
536
+ const o = M(t);
537
+ e(De(t.tr, o, o.left));
538
+ }
539
+ return !0;
540
+ }
541
+ function xt(t, e) {
542
+ if (!R(t)) return !1;
543
+ if (e) {
544
+ const o = M(t);
545
+ e(De(t.tr, o, o.right));
546
+ }
547
+ return !0;
548
+ }
549
+ function At(t, { map: e, table: o, tableStart: n }, l) {
550
+ const r = t.mapping.maps.length;
551
+ for (let s = 0; s < e.height; ) {
552
+ const i = s * e.width + l, c = e.map[i], a = o.nodeAt(c), d = a.attrs;
553
+ if (l > 0 && e.map[i - 1] == c || l < e.width - 1 && e.map[i + 1] == c) t.setNodeMarkup(t.mapping.slice(r).map(n + c), null, W(d, l - e.colCount(c)));
554
+ else {
555
+ const u = t.mapping.slice(r).map(n + c);
556
+ t.delete(u, u + a.nodeSize);
557
+ }
558
+ s += d.rowspan;
559
+ }
560
+ }
561
+ function Tt(t, e) {
562
+ if (!R(t)) return !1;
563
+ if (e) {
564
+ const o = M(t), n = t.tr;
565
+ if (o.left == 0 && o.right == o.map.width) return !1;
566
+ for (let l = o.right - 1; At(n, o, l), l != o.left; l--) {
567
+ const r = o.tableStart ? n.doc.nodeAt(o.tableStart - 1) : n.doc;
568
+ if (!r) throw new RangeError("No table found");
569
+ o.table = r, o.map = C.get(r);
570
+ }
571
+ e(n);
572
+ }
573
+ return !0;
574
+ }
575
+ function Rt(t, e, o) {
576
+ var n;
577
+ const l = y(e.type.schema).header_cell;
578
+ for (let r = 0; r < t.width; r++) if (((n = e.nodeAt(t.map[r + o * t.width])) === null || n === void 0 ? void 0 : n.type) != l) return !1;
579
+ return !0;
580
+ }
581
+ function Be(t, { map: e, tableStart: o, table: n }, l) {
582
+ let r = o;
583
+ for (let a = 0; a < l; a++) r += n.child(a).nodeSize;
584
+ const s = [];
585
+ let i = l > 0 ? -1 : 0;
586
+ Rt(e, n, l + i) && (i = l == 0 || l == e.height ? null : 0);
587
+ for (let a = 0, d = e.width * l; a < e.width; a++, d++) if (l > 0 && l < e.height && e.map[d] == e.map[d - e.width]) {
588
+ const u = e.map[d], f = n.nodeAt(u).attrs;
589
+ t.setNodeMarkup(o + u, null, {
590
+ ...f,
591
+ rowspan: f.rowspan + 1
592
+ }), a += f.colspan - 1;
593
+ } else {
594
+ var c;
595
+ const u = i == null ? y(n.type.schema).cell : (c = n.nodeAt(e.map[d + i * e.width])) === null || c === void 0 ? void 0 : c.type, f = u == null ? void 0 : u.createAndFill();
596
+ f && s.push(f);
597
+ }
598
+ return t.insert(r, y(n.type.schema).row.create(null, s)), t;
599
+ }
600
+ function vt(t, e) {
601
+ if (!R(t)) return !1;
602
+ if (e) {
603
+ const o = M(t);
604
+ e(Be(t.tr, o, o.top));
605
+ }
606
+ return !0;
607
+ }
608
+ function Mt(t, e) {
609
+ if (!R(t)) return !1;
610
+ if (e) {
611
+ const o = M(t);
612
+ e(Be(t.tr, o, o.bottom));
613
+ }
614
+ return !0;
615
+ }
616
+ function Nt(t, { map: e, table: o, tableStart: n }, l) {
617
+ let r = 0;
618
+ for (let a = 0; a < l; a++) r += o.child(a).nodeSize;
619
+ const s = r + o.child(l).nodeSize, i = t.mapping.maps.length;
620
+ t.delete(r + n, s + n);
621
+ const c = /* @__PURE__ */ new Set();
622
+ for (let a = 0, d = l * e.width; a < e.width; a++, d++) {
623
+ const u = e.map[d];
624
+ if (!c.has(u)) {
625
+ if (c.add(u), l > 0 && u == e.map[d - e.width]) {
626
+ const f = o.nodeAt(u).attrs;
627
+ t.setNodeMarkup(t.mapping.slice(i).map(u + n), null, {
628
+ ...f,
629
+ rowspan: f.rowspan - 1
630
+ }), a += f.colspan - 1;
631
+ } else if (l < e.height && u == e.map[d + e.width]) {
632
+ const f = o.nodeAt(u), h = f.attrs, p = f.type.create({
633
+ ...h,
634
+ rowspan: f.attrs.rowspan - 1
635
+ }, f.content), m = e.positionAt(l + 1, a, o);
636
+ t.insert(t.mapping.slice(i).map(n + m), p), a += h.colspan - 1;
637
+ }
638
+ }
639
+ }
640
+ }
641
+ function kt(t, e) {
642
+ if (!R(t)) return !1;
643
+ if (e) {
644
+ const o = M(t), n = t.tr;
645
+ if (o.top == 0 && o.bottom == o.map.height) return !1;
646
+ for (let l = o.bottom - 1; Nt(n, o, l), l != o.top; l--) {
647
+ const r = o.tableStart ? n.doc.nodeAt(o.tableStart - 1) : n.doc;
648
+ if (!r) throw new RangeError("No table found");
649
+ o.table = r, o.map = C.get(o.table);
650
+ }
651
+ e(n);
652
+ }
653
+ return !0;
654
+ }
655
+ function fe(t) {
656
+ const e = t.content;
657
+ return e.childCount == 1 && e.child(0).isTextblock && e.child(0).childCount == 0;
658
+ }
659
+ function Et({ width: t, height: e, map: o }, n) {
660
+ let l = n.top * t + n.left, r = l, s = (n.bottom - 1) * t + n.left, i = l + (n.right - n.left - 1);
661
+ for (let c = n.top; c < n.bottom; c++) {
662
+ if (n.left > 0 && o[r] == o[r - 1] || n.right < t && o[i] == o[i + 1]) return !0;
663
+ r += t, i += t;
664
+ }
665
+ for (let c = n.left; c < n.right; c++) {
666
+ if (n.top > 0 && o[l] == o[l - t] || n.bottom < e && o[s] == o[s + t]) return !0;
667
+ l++, s++;
668
+ }
669
+ return !1;
670
+ }
671
+ function he(t, e) {
672
+ const o = t.selection;
673
+ if (!(o instanceof w) || o.$anchorCell.pos == o.$headCell.pos) return !1;
674
+ const n = M(t), { map: l } = n;
675
+ if (Et(l, n)) return !1;
676
+ if (e) {
677
+ const r = t.tr, s = {};
678
+ let i = v.empty, c, a;
679
+ for (let d = n.top; d < n.bottom; d++) for (let u = n.left; u < n.right; u++) {
680
+ const f = l.map[d * l.width + u], h = n.table.nodeAt(f);
681
+ if (!(s[f] || !h))
682
+ if (s[f] = !0, c == null)
683
+ c = f, a = h;
684
+ else {
685
+ fe(h) || (i = i.append(h.content));
686
+ const p = r.mapping.map(f + n.tableStart);
687
+ r.delete(p, p + h.nodeSize);
688
+ }
689
+ }
690
+ if (c == null || a == null) return !0;
691
+ if (r.setNodeMarkup(c + n.tableStart, null, {
692
+ ...He(a.attrs, a.attrs.colspan, n.right - n.left - a.attrs.colspan),
693
+ rowspan: n.bottom - n.top
694
+ }), i.size > 0) {
695
+ const d = c + 1 + a.content.size, u = fe(a) ? c + 1 : d;
696
+ r.replaceWith(u + n.tableStart, d + n.tableStart, i);
697
+ }
698
+ r.setSelection(new w(r.doc.resolve(c + n.tableStart))), e(r);
699
+ }
700
+ return !0;
701
+ }
702
+ function pe(t, e) {
703
+ const o = y(t.schema);
704
+ return zt(({ node: n }) => o[n.type.spec.tableRole])(t, e);
705
+ }
706
+ function zt(t) {
707
+ return (e, o) => {
708
+ const n = e.selection;
709
+ let l, r;
710
+ if (n instanceof w) {
711
+ if (n.$anchorCell.pos != n.$headCell.pos) return !1;
712
+ l = n.$anchorCell.nodeAfter, r = n.$anchorCell.pos;
713
+ } else {
714
+ var s;
715
+ if (l = dt(n.$from), !l) return !1;
716
+ r = (s = D(n.$from)) === null || s === void 0 ? void 0 : s.pos;
717
+ }
718
+ if (l == null || r == null || l.attrs.colspan == 1 && l.attrs.rowspan == 1) return !1;
719
+ if (o) {
720
+ let i = l.attrs;
721
+ const c = [], a = i.colwidth;
722
+ i.rowspan > 1 && (i = {
723
+ ...i,
724
+ rowspan: 1
725
+ }), i.colspan > 1 && (i = {
726
+ ...i,
727
+ colspan: 1
728
+ });
729
+ const d = M(e), u = e.tr;
730
+ for (let h = 0; h < d.right - d.left; h++) c.push(a ? {
731
+ ...i,
732
+ colwidth: a && a[h] ? [a[h]] : null
733
+ } : i);
734
+ let f;
735
+ for (let h = d.top; h < d.bottom; h++) {
736
+ let p = d.map.positionAt(h, d.left, d.table);
737
+ h == d.top && (p += l.nodeSize);
738
+ for (let m = d.left, g = 0; m < d.right; m++, g++)
739
+ m == d.left && h == d.top || u.insert(f = u.mapping.map(p + d.tableStart, 1), t({
740
+ node: l,
741
+ row: h,
742
+ col: m
743
+ }).createAndFill(c[g]));
744
+ }
745
+ u.setNodeMarkup(r, t({
746
+ node: l,
747
+ row: d.top,
748
+ col: d.left
749
+ }), c[0]), n instanceof w && u.setSelection(new w(u.doc.resolve(n.$anchorCell.pos), f ? u.doc.resolve(f) : void 0)), o(u);
750
+ }
751
+ return !0;
752
+ };
753
+ }
754
+ function Ht(t, e) {
755
+ return function(o, n) {
756
+ if (!R(o)) return !1;
757
+ const l = Y(o);
758
+ if (l.nodeAfter.attrs[t] === e) return !1;
759
+ if (n) {
760
+ const r = o.tr;
761
+ o.selection instanceof w ? o.selection.forEachCell((s, i) => {
762
+ s.attrs[t] !== e && r.setNodeMarkup(i, null, {
763
+ ...s.attrs,
764
+ [t]: e
765
+ });
766
+ }) : r.setNodeMarkup(l.pos, null, {
767
+ ...l.nodeAfter.attrs,
768
+ [t]: e
769
+ }), n(r);
770
+ }
771
+ return !0;
772
+ };
773
+ }
774
+ function Lt(t) {
775
+ return function(e, o) {
776
+ if (!R(e)) return !1;
777
+ if (o) {
778
+ const n = y(e.schema), l = M(e), r = e.tr, s = l.map.cellsInRect(t == "column" ? {
779
+ left: l.left,
780
+ top: 0,
781
+ right: l.right,
782
+ bottom: l.map.height
783
+ } : t == "row" ? {
784
+ left: 0,
785
+ top: l.top,
786
+ right: l.map.width,
787
+ bottom: l.bottom
788
+ } : l), i = s.map((c) => l.table.nodeAt(c));
789
+ for (let c = 0; c < s.length; c++) i[c].type == n.header_cell && r.setNodeMarkup(l.tableStart + s[c], n.cell, i[c].attrs);
790
+ if (r.steps.length === 0) for (let c = 0; c < s.length; c++) r.setNodeMarkup(l.tableStart + s[c], n.header_cell, i[c].attrs);
791
+ o(r);
792
+ }
793
+ return !0;
794
+ };
795
+ }
796
+ function me(t, e, o) {
797
+ const n = e.map.cellsInRect({
798
+ left: 0,
799
+ top: 0,
800
+ right: t == "row" ? e.map.width : 1,
801
+ bottom: t == "column" ? e.map.height : 1
802
+ });
803
+ for (let l = 0; l < n.length; l++) {
804
+ const r = e.table.nodeAt(n[l]);
805
+ if (r && r.type !== o.header_cell) return !1;
806
+ }
807
+ return !0;
808
+ }
809
+ function I(t, e) {
810
+ return e = e || { useDeprecatedLogic: !1 }, e.useDeprecatedLogic ? Lt(t) : function(o, n) {
811
+ if (!R(o)) return !1;
812
+ if (n) {
813
+ const l = y(o.schema), r = M(o), s = o.tr, i = me("row", r, l), c = me("column", r, l), a = (t === "column" ? i : t === "row" && c) ? 1 : 0, d = t == "column" ? {
814
+ left: 0,
815
+ top: a,
816
+ right: 1,
817
+ bottom: r.map.height
818
+ } : t == "row" ? {
819
+ left: a,
820
+ top: 0,
821
+ right: r.map.width,
822
+ bottom: 1
823
+ } : r, u = t == "column" ? c ? l.cell : l.header_cell : t == "row" ? i ? l.cell : l.header_cell : l.cell;
824
+ r.map.cellsInRect(d).forEach((f) => {
825
+ const h = f + r.tableStart, p = s.doc.nodeAt(h);
826
+ p && s.setNodeMarkup(h, u, p.attrs);
827
+ }), n(s);
828
+ }
829
+ return !0;
830
+ };
831
+ }
832
+ I("row", { useDeprecatedLogic: !0 });
833
+ I("column", { useDeprecatedLogic: !0 });
834
+ const $t = I("cell", { useDeprecatedLogic: !0 });
835
+ function Wt(t, e) {
836
+ if (e < 0) {
837
+ const o = t.nodeBefore;
838
+ if (o) return t.pos - o.nodeSize;
839
+ for (let n = t.index(-1) - 1, l = t.before(); n >= 0; n--) {
840
+ const r = t.node(-1).child(n), s = r.lastChild;
841
+ if (s) return l - 1 - s.nodeSize;
842
+ l -= r.nodeSize;
843
+ }
844
+ } else {
845
+ if (t.index() < t.parent.childCount - 1) return t.pos + t.nodeAfter.nodeSize;
846
+ const o = t.node(-1);
847
+ for (let n = t.indexAfter(-1), l = t.after(); n < o.childCount; n++) {
848
+ const r = o.child(n);
849
+ if (r.childCount) return l + 1;
850
+ l += r.nodeSize;
851
+ }
852
+ }
853
+ return null;
854
+ }
855
+ function ge(t) {
856
+ return function(e, o) {
857
+ if (!R(e)) return !1;
858
+ const n = Wt(Y(e), t);
859
+ if (n == null) return !1;
860
+ if (o) {
861
+ const l = e.doc.resolve(n);
862
+ o(e.tr.setSelection($.between(l, ft(l))).scrollIntoView());
863
+ }
864
+ return !0;
865
+ };
866
+ }
867
+ function Dt(t, e) {
868
+ const o = t.selection.$anchor;
869
+ for (let n = o.depth; n > 0; n--) if (o.node(n).type.spec.tableRole == "table")
870
+ return e && e(t.tr.delete(o.before(n), o.after(n)).scrollIntoView()), !0;
871
+ return !1;
872
+ }
873
+ function V(t, e) {
874
+ const o = t.selection;
875
+ if (!(o instanceof w)) return !1;
876
+ if (e) {
877
+ const n = t.tr, l = y(t.schema).cell.createAndFill().content;
878
+ o.forEachCell((r, s) => {
879
+ r.content.eq(l) || n.replace(n.mapping.map(s + 1), n.mapping.map(s + r.nodeSize - 1), new L(l, 0, 0));
880
+ }), n.docChanged && e(n);
881
+ }
882
+ return !0;
883
+ }
884
+ function Bt(t) {
885
+ if (t.size === 0) return null;
886
+ let { content: e, openStart: o, openEnd: n } = t;
887
+ for (; e.childCount == 1 && (o > 0 && n > 0 || e.child(0).type.spec.tableRole == "table"); )
888
+ o--, n--, e = e.child(0).content;
889
+ const l = e.child(0), r = l.type.spec.tableRole, s = l.type.schema, i = [];
890
+ if (r == "row") for (let c = 0; c < e.childCount; c++) {
891
+ let a = e.child(c).content;
892
+ const d = c ? 0 : Math.max(0, o - 1), u = c < e.childCount - 1 ? 0 : Math.max(0, n - 1);
893
+ (d || u) && (a = ie(y(s).row, new L(a, d, u)).content), i.push(a);
894
+ }
895
+ else if (r == "cell" || r == "header_cell") i.push(o || n ? ie(y(s).row, new L(e, o, n)).content : e);
896
+ else return null;
897
+ return It(s, i);
898
+ }
899
+ function It(t, e) {
900
+ const o = [];
901
+ for (let l = 0; l < e.length; l++) {
902
+ const r = e[l];
903
+ for (let s = r.childCount - 1; s >= 0; s--) {
904
+ const { rowspan: i, colspan: c } = r.child(s).attrs;
905
+ for (let a = l; a < l + i; a++) o[a] = (o[a] || 0) + c;
906
+ }
907
+ }
908
+ let n = 0;
909
+ for (let l = 0; l < o.length; l++) n = Math.max(n, o[l]);
910
+ for (let l = 0; l < o.length; l++)
911
+ if (l >= e.length && e.push(v.empty), o[l] < n) {
912
+ const r = y(t).cell.createAndFill(), s = [];
913
+ for (let i = o[l]; i < n; i++) s.push(r);
914
+ e[l] = e[l].append(v.from(s));
915
+ }
916
+ return {
917
+ height: e.length,
918
+ width: n,
919
+ rows: e
920
+ };
921
+ }
922
+ function ie(t, e) {
923
+ const o = t.createAndFill();
924
+ return new Xe(o).replace(0, o.content.size, e).doc;
925
+ }
926
+ function Pt({ width: t, height: e, rows: o }, n, l) {
927
+ if (t != n) {
928
+ const r = [], s = [];
929
+ for (let i = 0; i < o.length; i++) {
930
+ const c = o[i], a = [];
931
+ for (let d = r[i] || 0, u = 0; d < n; u++) {
932
+ let f = c.child(u % c.childCount);
933
+ d + f.attrs.colspan > n && (f = f.type.createChecked(W(f.attrs, f.attrs.colspan, d + f.attrs.colspan - n), f.content)), a.push(f), d += f.attrs.colspan;
934
+ for (let h = 1; h < f.attrs.rowspan; h++) r[i + h] = (r[i + h] || 0) + f.attrs.colspan;
935
+ }
936
+ s.push(v.from(a));
937
+ }
938
+ o = s, t = n;
939
+ }
940
+ if (e != l) {
941
+ const r = [];
942
+ for (let s = 0, i = 0; s < l; s++, i++) {
943
+ const c = [], a = o[i % e];
944
+ for (let d = 0; d < a.childCount; d++) {
945
+ let u = a.child(d);
946
+ s + u.attrs.rowspan > l && (u = u.type.create({
947
+ ...u.attrs,
948
+ rowspan: Math.max(1, l - u.attrs.rowspan)
949
+ }, u.content)), c.push(u);
950
+ }
951
+ r.push(v.from(c));
952
+ }
953
+ o = r, e = l;
954
+ }
955
+ return {
956
+ width: t,
957
+ height: e,
958
+ rows: o
959
+ };
960
+ }
961
+ function _t(t, e, o, n, l, r, s) {
962
+ const i = t.doc.type.schema, c = y(i);
963
+ let a, d;
964
+ if (l > e.width) for (let u = 0, f = 0; u < e.height; u++) {
965
+ const h = o.child(u);
966
+ f += h.nodeSize;
967
+ const p = [];
968
+ let m;
969
+ h.lastChild == null || h.lastChild.type == c.cell ? m = a || (a = c.cell.createAndFill()) : m = d || (d = c.header_cell.createAndFill());
970
+ for (let g = e.width; g < l; g++) p.push(m);
971
+ t.insert(t.mapping.slice(s).map(f - 1 + n), p);
972
+ }
973
+ if (r > e.height) {
974
+ const u = [];
975
+ for (let p = 0, m = (e.height - 1) * e.width; p < Math.max(e.width, l); p++) {
976
+ const g = p >= e.width ? !1 : o.nodeAt(e.map[m + p]).type == c.header_cell;
977
+ u.push(g ? d || (d = c.header_cell.createAndFill()) : a || (a = c.cell.createAndFill()));
978
+ }
979
+ const f = c.row.create(null, v.from(u)), h = [];
980
+ for (let p = e.height; p < r; p++) h.push(f);
981
+ t.insert(t.mapping.slice(s).map(n + o.nodeSize - 2), h);
982
+ }
983
+ return !!(a || d);
984
+ }
985
+ function be(t, e, o, n, l, r, s, i) {
986
+ if (s == 0 || s == e.height) return !1;
987
+ let c = !1;
988
+ for (let a = l; a < r; a++) {
989
+ const d = s * e.width + a, u = e.map[d];
990
+ if (e.map[d - e.width] == u) {
991
+ c = !0;
992
+ const f = o.nodeAt(u), { top: h, left: p } = e.findCell(u);
993
+ t.setNodeMarkup(t.mapping.slice(i).map(u + n), null, {
994
+ ...f.attrs,
995
+ rowspan: s - h
996
+ }), t.insert(t.mapping.slice(i).map(e.positionAt(s, p, o)), f.type.createAndFill({
997
+ ...f.attrs,
998
+ rowspan: h + f.attrs.rowspan - s
999
+ })), a += f.attrs.colspan - 1;
1000
+ }
1001
+ }
1002
+ return c;
1003
+ }
1004
+ function we(t, e, o, n, l, r, s, i) {
1005
+ if (s == 0 || s == e.width) return !1;
1006
+ let c = !1;
1007
+ for (let a = l; a < r; a++) {
1008
+ const d = a * e.width + s, u = e.map[d];
1009
+ if (e.map[d - 1] == u) {
1010
+ c = !0;
1011
+ const f = o.nodeAt(u), h = e.colCount(u), p = t.mapping.slice(i).map(u + n);
1012
+ t.setNodeMarkup(p, null, W(f.attrs, s - h, f.attrs.colspan - (s - h))), t.insert(p + f.nodeSize, f.type.createAndFill(W(f.attrs, 0, s - h))), a += f.attrs.rowspan - 1;
1013
+ }
1014
+ }
1015
+ return c;
1016
+ }
1017
+ function Ce(t, e, o, n, l) {
1018
+ let r = o ? t.doc.nodeAt(o - 1) : t.doc;
1019
+ if (!r) throw new Error("No table found");
1020
+ let s = C.get(r);
1021
+ const { top: i, left: c } = n, a = c + l.width, d = i + l.height, u = t.tr;
1022
+ let f = 0;
1023
+ function h() {
1024
+ if (r = o ? u.doc.nodeAt(o - 1) : u.doc, !r) throw new Error("No table found");
1025
+ s = C.get(r), f = u.mapping.maps.length;
1026
+ }
1027
+ _t(u, s, r, o, a, d, f) && h(), be(u, s, r, o, c, a, i, f) && h(), be(u, s, r, o, c, a, d, f) && h(), we(u, s, r, o, i, d, c, f) && h(), we(u, s, r, o, i, d, a, f) && h();
1028
+ for (let p = i; p < d; p++) {
1029
+ const m = s.positionAt(p, c, r), g = s.positionAt(p, a, r);
1030
+ u.replace(u.mapping.slice(f).map(m + o), u.mapping.slice(f).map(g + o), new L(l.rows[p - i], 0, 0));
1031
+ }
1032
+ h(), u.setSelection(new w(u.doc.resolve(o + s.positionAt(i, c, r)), u.doc.resolve(o + s.positionAt(d - 1, a - 1, r)))), e(u);
1033
+ }
1034
+ const Ot = Ze({
1035
+ ArrowLeft: K("horiz", -1),
1036
+ ArrowRight: K("horiz", 1),
1037
+ ArrowUp: K("vert", -1),
1038
+ ArrowDown: K("vert", 1),
1039
+ "Shift-ArrowLeft": X("horiz", -1),
1040
+ "Shift-ArrowRight": X("horiz", 1),
1041
+ "Shift-ArrowUp": X("vert", -1),
1042
+ "Shift-ArrowDown": X("vert", 1),
1043
+ Backspace: V,
1044
+ "Mod-Backspace": V,
1045
+ Delete: V,
1046
+ "Mod-Delete": V
1047
+ });
1048
+ function G(t, e, o) {
1049
+ return o.eq(t.selection) ? !1 : (e && e(t.tr.setSelection(o).scrollIntoView()), !0);
1050
+ }
1051
+ function K(t, e) {
1052
+ return (o, n, l) => {
1053
+ if (!l) return !1;
1054
+ const r = o.selection;
1055
+ if (r instanceof w) return G(o, n, E.near(r.$headCell, e));
1056
+ if (t != "horiz" && !r.empty) return !1;
1057
+ const s = Ie(l, t, e);
1058
+ if (s == null) return !1;
1059
+ if (t == "horiz") return G(o, n, E.near(o.doc.resolve(r.head + e), e));
1060
+ {
1061
+ const i = o.doc.resolve(s), c = ze(i, t, e);
1062
+ let a;
1063
+ return c ? a = E.near(c, 1) : e < 0 ? a = E.near(o.doc.resolve(i.before(-1)), -1) : a = E.near(o.doc.resolve(i.after(-1)), 1), G(o, n, a);
1064
+ }
1065
+ };
1066
+ }
1067
+ function X(t, e) {
1068
+ return (o, n, l) => {
1069
+ if (!l) return !1;
1070
+ const r = o.selection;
1071
+ let s;
1072
+ if (r instanceof w) s = r;
1073
+ else {
1074
+ const c = Ie(l, t, e);
1075
+ if (c == null) return !1;
1076
+ s = new w(o.doc.resolve(c));
1077
+ }
1078
+ const i = ze(s.$headCell, t, e);
1079
+ return i ? G(o, n, new w(s.$anchorCell, i)) : !1;
1080
+ };
1081
+ }
1082
+ function Ft(t, e) {
1083
+ const o = t.state.doc, n = D(o.resolve(e));
1084
+ return n ? (t.dispatch(t.state.tr.setSelection(new w(n))), !0) : !1;
1085
+ }
1086
+ function jt(t, e, o) {
1087
+ if (!R(t.state)) return !1;
1088
+ let n = Bt(o);
1089
+ const l = t.state.selection;
1090
+ if (l instanceof w) {
1091
+ n || (n = {
1092
+ width: 1,
1093
+ height: 1,
1094
+ rows: [v.from(ie(y(t.state.schema).cell, o))]
1095
+ });
1096
+ const r = l.$anchorCell.node(-1), s = l.$anchorCell.start(-1), i = C.get(r).rectBetween(l.$anchorCell.pos - s, l.$headCell.pos - s);
1097
+ return n = Pt(n, i.right - i.left, i.bottom - i.top), Ce(t.state, t.dispatch, s, i, n), !0;
1098
+ } else if (n) {
1099
+ const r = Y(t.state), s = r.start(-1);
1100
+ return Ce(t.state, t.dispatch, s, C.get(r.node(-1)).findCell(r.pos - s), n), !0;
1101
+ } else return !1;
1102
+ }
1103
+ function Vt(t, e) {
1104
+ var o;
1105
+ if (e.ctrlKey || e.metaKey) return;
1106
+ const n = ye(t, e.target);
1107
+ let l;
1108
+ if (e.shiftKey && t.state.selection instanceof w)
1109
+ r(t.state.selection.$anchorCell, e), e.preventDefault();
1110
+ else if (e.shiftKey && n && (l = D(t.state.selection.$anchor)) != null && ((o = te(t, e)) === null || o === void 0 ? void 0 : o.pos) != l.pos)
1111
+ r(l, e), e.preventDefault();
1112
+ else if (!n) return;
1113
+ function r(c, a) {
1114
+ let d = te(t, a);
1115
+ const u = H.getState(t.state) == null;
1116
+ if (!d || !ue(c, d)) if (u) d = c;
1117
+ else return;
1118
+ const f = new w(c, d);
1119
+ if (u || !t.state.selection.eq(f)) {
1120
+ const h = t.state.tr.setSelection(f);
1121
+ u && h.setMeta(H, c.pos), t.dispatch(h);
1122
+ }
1123
+ }
1124
+ function s() {
1125
+ t.root.removeEventListener("mouseup", s), t.root.removeEventListener("dragstart", s), t.root.removeEventListener("mousemove", i), H.getState(t.state) != null && t.dispatch(t.state.tr.setMeta(H, -1));
1126
+ }
1127
+ function i(c) {
1128
+ const a = c, d = H.getState(t.state);
1129
+ let u;
1130
+ if (d != null) u = t.state.doc.resolve(d);
1131
+ else if (ye(t, a.target) != n && (u = te(t, e), !u))
1132
+ return s();
1133
+ u && r(u, a);
1134
+ }
1135
+ t.root.addEventListener("mouseup", s), t.root.addEventListener("dragstart", s), t.root.addEventListener("mousemove", i);
1136
+ }
1137
+ function Ie(t, e, o) {
1138
+ if (!(t.state.selection instanceof $)) return null;
1139
+ const { $head: n } = t.state.selection;
1140
+ for (let l = n.depth - 1; l >= 0; l--) {
1141
+ const r = n.node(l);
1142
+ if ((o < 0 ? n.index(l) : n.indexAfter(l)) != (o < 0 ? 0 : r.childCount)) return null;
1143
+ if (r.type.spec.tableRole == "cell" || r.type.spec.tableRole == "header_cell") {
1144
+ const s = n.before(l), i = e == "vert" ? o > 0 ? "down" : "up" : o > 0 ? "right" : "left";
1145
+ return t.endOfTextblock(i) ? s : null;
1146
+ }
1147
+ }
1148
+ return null;
1149
+ }
1150
+ function ye(t, e) {
1151
+ for (; e && e != t.dom; e = e.parentNode) if (e.nodeName == "TD" || e.nodeName == "TH") return e;
1152
+ return null;
1153
+ }
1154
+ function te(t, e) {
1155
+ const o = t.posAtCoords({
1156
+ left: e.clientX,
1157
+ top: e.clientY
1158
+ });
1159
+ if (!o) return null;
1160
+ const n = o.inside >= 0 ? o.inside : o.pos;
1161
+ return D(t.state.doc.resolve(n));
1162
+ }
1163
+ var Kt = class {
1164
+ constructor(e, o) {
1165
+ this.node = e, this.defaultCellMinWidth = o, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), this.table.style.setProperty("--default-cell-min-width", `${o}px`), this.colgroup = this.table.appendChild(document.createElement("colgroup")), ce(e, this.colgroup, this.table, o), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1166
+ }
1167
+ update(e) {
1168
+ return e.type != this.node.type ? !1 : (this.node = e, ce(e, this.colgroup, this.table, this.defaultCellMinWidth), !0);
1169
+ }
1170
+ ignoreMutation(e) {
1171
+ return e.type == "attributes" && (e.target == this.table || this.colgroup.contains(e.target));
1172
+ }
1173
+ };
1174
+ function ce(t, e, o, n, l, r) {
1175
+ let s = 0, i = !0, c = e.firstChild;
1176
+ const a = t.firstChild;
1177
+ if (a) {
1178
+ for (let u = 0, f = 0; u < a.childCount; u++) {
1179
+ const { colspan: h, colwidth: p } = a.child(u).attrs;
1180
+ for (let m = 0; m < h; m++, f++) {
1181
+ const g = l == f ? r : p && p[m], b = g ? g + "px" : "";
1182
+ if (s += g || n, g || (i = !1), c)
1183
+ c.style.width != b && (c.style.width = b), c = c.nextSibling;
1184
+ else {
1185
+ const S = document.createElement("col");
1186
+ S.style.width = b, e.appendChild(S);
1187
+ }
1188
+ }
1189
+ }
1190
+ for (; c; ) {
1191
+ var d;
1192
+ const u = c.nextSibling;
1193
+ (d = c.parentNode) === null || d === void 0 || d.removeChild(c), c = u;
1194
+ }
1195
+ i ? (o.style.width = s + "px", o.style.minWidth = "") : (o.style.width = "", o.style.minWidth = s + "px");
1196
+ }
1197
+ }
1198
+ const x = new de("tableColumnResizing");
1199
+ function Xt({ handleWidth: t = 5, cellMinWidth: e = 25, defaultCellMinWidth: o = 100, View: n = Kt, lastColumnResizable: l = !0 } = {}) {
1200
+ const r = new ke({
1201
+ key: x,
1202
+ state: {
1203
+ init(s, i) {
1204
+ var c;
1205
+ const a = (c = r.spec) === null || c === void 0 || (c = c.props) === null || c === void 0 ? void 0 : c.nodeViews, d = y(i.schema).table.name;
1206
+ return n && a && (a[d] = (u, f) => new n(u, o, f)), new Ut(-1, !1);
1207
+ },
1208
+ apply(s, i) {
1209
+ return i.apply(s);
1210
+ }
1211
+ },
1212
+ props: {
1213
+ attributes: (s) => {
1214
+ const i = x.getState(s);
1215
+ return i && i.activeHandle > -1 ? { class: "resize-cursor" } : {};
1216
+ },
1217
+ handleDOMEvents: {
1218
+ mousemove: (s, i) => {
1219
+ Gt(s, i, t, l);
1220
+ },
1221
+ mouseleave: (s) => {
1222
+ qt(s);
1223
+ },
1224
+ mousedown: (s, i) => {
1225
+ Jt(s, i, e, o);
1226
+ }
1227
+ },
1228
+ decorations: (s) => {
1229
+ const i = x.getState(s);
1230
+ if (i && i.activeHandle > -1) return to(s, i.activeHandle);
1231
+ },
1232
+ nodeViews: {}
1233
+ }
1234
+ });
1235
+ return r;
1236
+ }
1237
+ var Ut = class q {
1238
+ constructor(e, o) {
1239
+ this.activeHandle = e, this.dragging = o;
1240
+ }
1241
+ apply(e) {
1242
+ const o = this, n = e.getMeta(x);
1243
+ if (n && n.setHandle != null) return new q(n.setHandle, !1);
1244
+ if (n && n.setDragging !== void 0) return new q(o.activeHandle, n.setDragging);
1245
+ if (o.activeHandle > -1 && e.docChanged) {
1246
+ let l = e.mapping.map(o.activeHandle, -1);
1247
+ return se(e.doc.resolve(l)) || (l = -1), new q(l, o.dragging);
1248
+ }
1249
+ return o;
1250
+ }
1251
+ };
1252
+ function Gt(t, e, o, n) {
1253
+ if (!t.editable) return;
1254
+ const l = x.getState(t.state);
1255
+ if (l && !l.dragging) {
1256
+ const r = Yt(e.target);
1257
+ let s = -1;
1258
+ if (r) {
1259
+ const { left: i, right: c } = r.getBoundingClientRect();
1260
+ e.clientX - i <= o ? s = Se(t, e, "left", o) : c - e.clientX <= o && (s = Se(t, e, "right", o));
1261
+ }
1262
+ if (s != l.activeHandle) {
1263
+ if (!n && s !== -1) {
1264
+ const i = t.state.doc.resolve(s), c = i.node(-1), a = C.get(c), d = i.start(-1);
1265
+ if (a.colCount(i.pos - d) + i.nodeAfter.attrs.colspan - 1 == a.width - 1) return;
1266
+ }
1267
+ Pe(t, s);
1268
+ }
1269
+ }
1270
+ }
1271
+ function qt(t) {
1272
+ if (!t.editable) return;
1273
+ const e = x.getState(t.state);
1274
+ e && e.activeHandle > -1 && !e.dragging && Pe(t, -1);
1275
+ }
1276
+ function Jt(t, e, o, n) {
1277
+ var l;
1278
+ if (!t.editable) return !1;
1279
+ const r = (l = t.dom.ownerDocument.defaultView) !== null && l !== void 0 ? l : window, s = x.getState(t.state);
1280
+ if (!s || s.activeHandle == -1 || s.dragging) return !1;
1281
+ const i = t.state.doc.nodeAt(s.activeHandle), c = Zt(t, s.activeHandle, i.attrs);
1282
+ t.dispatch(t.state.tr.setMeta(x, { setDragging: {
1283
+ startX: e.clientX,
1284
+ startWidth: c
1285
+ } }));
1286
+ function a(u) {
1287
+ r.removeEventListener("mouseup", a), r.removeEventListener("mousemove", d);
1288
+ const f = x.getState(t.state);
1289
+ f != null && f.dragging && (Qt(t, f.activeHandle, xe(f.dragging, u, o)), t.dispatch(t.state.tr.setMeta(x, { setDragging: null })));
1290
+ }
1291
+ function d(u) {
1292
+ if (!u.which) return a(u);
1293
+ const f = x.getState(t.state);
1294
+ if (f && f.dragging) {
1295
+ const h = xe(f.dragging, u, o);
1296
+ Ae(t, f.activeHandle, h, n);
1297
+ }
1298
+ }
1299
+ return Ae(t, s.activeHandle, c, n), r.addEventListener("mouseup", a), r.addEventListener("mousemove", d), e.preventDefault(), !0;
1300
+ }
1301
+ function Zt(t, e, { colspan: o, colwidth: n }) {
1302
+ const l = n && n[n.length - 1];
1303
+ if (l) return l;
1304
+ const r = t.domAtPos(e);
1305
+ let s = r.node.childNodes[r.offset].offsetWidth, i = o;
1306
+ if (n)
1307
+ for (let c = 0; c < o; c++) n[c] && (s -= n[c], i--);
1308
+ return s / i;
1309
+ }
1310
+ function Yt(t) {
1311
+ for (; t && t.nodeName != "TD" && t.nodeName != "TH"; ) t = t.classList && t.classList.contains("ProseMirror") ? null : t.parentNode;
1312
+ return t;
1313
+ }
1314
+ function Se(t, e, o, n) {
1315
+ const l = o == "right" ? -n : n, r = t.posAtCoords({
1316
+ left: e.clientX + l,
1317
+ top: e.clientY
1318
+ });
1319
+ if (!r) return -1;
1320
+ const { pos: s } = r, i = D(t.state.doc.resolve(s));
1321
+ if (!i) return -1;
1322
+ if (o == "right") return i.pos;
1323
+ const c = C.get(i.node(-1)), a = i.start(-1), d = c.map.indexOf(i.pos - a);
1324
+ return d % c.width == 0 ? -1 : a + c.map[d - 1];
1325
+ }
1326
+ function xe(t, e, o) {
1327
+ const n = e.clientX - t.startX;
1328
+ return Math.max(o, t.startWidth + n);
1329
+ }
1330
+ function Pe(t, e) {
1331
+ t.dispatch(t.state.tr.setMeta(x, { setHandle: e }));
1332
+ }
1333
+ function Qt(t, e, o) {
1334
+ const n = t.state.doc.resolve(e), l = n.node(-1), r = C.get(l), s = n.start(-1), i = r.colCount(n.pos - s) + n.nodeAfter.attrs.colspan - 1, c = t.state.tr;
1335
+ for (let a = 0; a < r.height; a++) {
1336
+ const d = a * r.width + i;
1337
+ if (a && r.map[d] == r.map[d - r.width]) continue;
1338
+ const u = r.map[d], f = l.nodeAt(u).attrs, h = f.colspan == 1 ? 0 : i - r.colCount(u);
1339
+ if (f.colwidth && f.colwidth[h] == o) continue;
1340
+ const p = f.colwidth ? f.colwidth.slice() : eo(f.colspan);
1341
+ p[h] = o, c.setNodeMarkup(s + u, null, {
1342
+ ...f,
1343
+ colwidth: p
1344
+ });
1345
+ }
1346
+ c.docChanged && t.dispatch(c);
1347
+ }
1348
+ function Ae(t, e, o, n) {
1349
+ const l = t.state.doc.resolve(e), r = l.node(-1), s = l.start(-1), i = C.get(r).colCount(l.pos - s) + l.nodeAfter.attrs.colspan - 1;
1350
+ let c = t.domAtPos(l.start(-1)).node;
1351
+ for (; c && c.nodeName != "TABLE"; ) c = c.parentNode;
1352
+ c && ce(r, c.firstChild, c, n, i, o);
1353
+ }
1354
+ function eo(t) {
1355
+ return Array(t).fill(0);
1356
+ }
1357
+ function to(t, e) {
1358
+ const o = [], n = t.doc.resolve(e), l = n.node(-1);
1359
+ if (!l) return oe.empty;
1360
+ const r = C.get(l), s = n.start(-1), i = r.colCount(n.pos - s) + n.nodeAfter.attrs.colspan - 1;
1361
+ for (let a = 0; a < r.height; a++) {
1362
+ const d = i + a * r.width;
1363
+ if ((i == r.width - 1 || r.map[d] != r.map[d + 1]) && (a == 0 || r.map[d] != r.map[d - r.width])) {
1364
+ var c;
1365
+ const u = r.map[d], f = s + u + l.nodeAt(u).nodeSize - 1, h = document.createElement("div");
1366
+ h.className = "column-resize-handle", !((c = x.getState(t)) === null || c === void 0) && c.dragging && o.push(ne.node(s + u, s + u + l.nodeAt(u).nodeSize, { class: "column-resize-dragging" })), o.push(ne.widget(f, h));
1367
+ }
1368
+ }
1369
+ return oe.create(t.doc, o);
1370
+ }
1371
+ function oo({ allowTableNodeSelection: t = !1 } = {}) {
1372
+ return new ke({
1373
+ key: H,
1374
+ state: {
1375
+ init() {
1376
+ return null;
1377
+ },
1378
+ apply(e, o) {
1379
+ const n = e.getMeta(H);
1380
+ if (n != null) return n == -1 ? null : n;
1381
+ if (o == null || !e.docChanged) return o;
1382
+ const { deleted: l, pos: r } = e.mapping.mapResult(o);
1383
+ return l ? null : r;
1384
+ }
1385
+ },
1386
+ props: {
1387
+ decorations: mt,
1388
+ handleDOMEvents: { mousedown: Vt },
1389
+ createSelectionBetween(e) {
1390
+ return H.getState(e.state) != null ? e.state.selection : null;
1391
+ },
1392
+ handleTripleClick: Ft,
1393
+ handleKeyDown: Ot,
1394
+ handlePaste: jt
1395
+ },
1396
+ appendTransaction(e, o, n) {
1397
+ return wt(n, We(n, o), t);
1398
+ }
1399
+ });
1400
+ }
1401
+ var _e = J.create({
1402
+ name: "tableCell",
1403
+ addOptions() {
1404
+ return {
1405
+ HTMLAttributes: {}
1406
+ };
1407
+ },
1408
+ content: "block+",
1409
+ addAttributes() {
1410
+ return {
1411
+ colspan: {
1412
+ default: 1
1413
+ },
1414
+ rowspan: {
1415
+ default: 1
1416
+ },
1417
+ colwidth: {
1418
+ default: null,
1419
+ parseHTML: (t) => {
1420
+ var e, o;
1421
+ const n = t.getAttribute("colwidth"), l = n ? n.split(",").map((r) => parseInt(r, 10)) : null;
1422
+ if (!l) {
1423
+ const r = (e = t.closest("table")) == null ? void 0 : e.querySelectorAll("colgroup > col"), s = Array.from(((o = t.parentElement) == null ? void 0 : o.children) || []).indexOf(t);
1424
+ if (s && s > -1 && r && r[s]) {
1425
+ const i = r[s].getAttribute("width");
1426
+ return i ? [parseInt(i, 10)] : null;
1427
+ }
1428
+ }
1429
+ return l;
1430
+ }
1431
+ }
1432
+ };
1433
+ },
1434
+ tableRole: "cell",
1435
+ isolating: !0,
1436
+ parseHTML() {
1437
+ return [{ tag: "td" }];
1438
+ },
1439
+ renderHTML({ HTMLAttributes: t }) {
1440
+ return ["td", Z(this.options.HTMLAttributes, t), 0];
1441
+ }
1442
+ }), Oe = J.create({
1443
+ name: "tableHeader",
1444
+ addOptions() {
1445
+ return {
1446
+ HTMLAttributes: {}
1447
+ };
1448
+ },
1449
+ content: "block+",
1450
+ addAttributes() {
1451
+ return {
1452
+ colspan: {
1453
+ default: 1
1454
+ },
1455
+ rowspan: {
1456
+ default: 1
1457
+ },
1458
+ colwidth: {
1459
+ default: null,
1460
+ parseHTML: (t) => {
1461
+ const e = t.getAttribute("colwidth");
1462
+ return e ? e.split(",").map((n) => parseInt(n, 10)) : null;
1463
+ }
1464
+ }
1465
+ };
1466
+ },
1467
+ tableRole: "header_cell",
1468
+ isolating: !0,
1469
+ parseHTML() {
1470
+ return [{ tag: "th" }];
1471
+ },
1472
+ renderHTML({ HTMLAttributes: t }) {
1473
+ return ["th", Z(this.options.HTMLAttributes, t), 0];
1474
+ }
1475
+ }), Fe = J.create({
1476
+ name: "tableRow",
1477
+ addOptions() {
1478
+ return {
1479
+ HTMLAttributes: {}
1480
+ };
1481
+ },
1482
+ content: "(tableCell | tableHeader)*",
1483
+ tableRole: "row",
1484
+ parseHTML() {
1485
+ return [{ tag: "tr" }];
1486
+ },
1487
+ renderHTML({ HTMLAttributes: t }) {
1488
+ return ["tr", Z(this.options.HTMLAttributes, t), 0];
1489
+ }
1490
+ });
1491
+ function ae(t, e) {
1492
+ return e ? ["width", `${Math.max(e, t)}px`] : ["min-width", `${t}px`];
1493
+ }
1494
+ function Te(t, e, o, n, l, r) {
1495
+ var s;
1496
+ let i = 0, c = !0, a = e.firstChild;
1497
+ const d = t.firstChild;
1498
+ if (d !== null)
1499
+ for (let f = 0, h = 0; f < d.childCount; f += 1) {
1500
+ const { colspan: p, colwidth: m } = d.child(f).attrs;
1501
+ for (let g = 0; g < p; g += 1, h += 1) {
1502
+ const b = l === h ? r : m && m[g], S = b ? `${b}px` : "";
1503
+ if (i += b || n, b || (c = !1), a) {
1504
+ if (a.style.width !== S) {
1505
+ const [A, z] = ae(n, b);
1506
+ a.style.setProperty(A, z);
1507
+ }
1508
+ a = a.nextSibling;
1509
+ } else {
1510
+ const A = document.createElement("col"), [z, T] = ae(n, b);
1511
+ A.style.setProperty(z, T), e.appendChild(A);
1512
+ }
1513
+ }
1514
+ }
1515
+ for (; a; ) {
1516
+ const f = a.nextSibling;
1517
+ (s = a.parentNode) == null || s.removeChild(a), a = f;
1518
+ }
1519
+ const u = t.attrs.style && typeof t.attrs.style == "string" && /\bwidth\s*:/i.test(t.attrs.style);
1520
+ c && !u ? (o.style.width = `${i}px`, o.style.minWidth = "") : (o.style.width = "", o.style.minWidth = `${i}px`);
1521
+ }
1522
+ var no = class {
1523
+ constructor(t, e) {
1524
+ this.node = t, this.cellMinWidth = e, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), t.attrs.style && (this.table.style.cssText = t.attrs.style), this.colgroup = this.table.appendChild(document.createElement("colgroup")), Te(t, this.colgroup, this.table, e), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1525
+ }
1526
+ update(t) {
1527
+ return t.type !== this.node.type ? !1 : (this.node = t, Te(t, this.colgroup, this.table, this.cellMinWidth), !0);
1528
+ }
1529
+ ignoreMutation(t) {
1530
+ const e = t.target, o = this.dom.contains(e), n = this.contentDOM.contains(e);
1531
+ return !!(o && !n && (t.type === "attributes" || t.type === "childList" || t.type === "characterData"));
1532
+ }
1533
+ };
1534
+ function lo(t, e, o, n) {
1535
+ let l = 0, r = !0;
1536
+ const s = [], i = t.firstChild;
1537
+ if (!i)
1538
+ return {};
1539
+ for (let u = 0, f = 0; u < i.childCount; u += 1) {
1540
+ const { colspan: h, colwidth: p } = i.child(u).attrs;
1541
+ for (let m = 0; m < h; m += 1, f += 1) {
1542
+ const g = o === f ? n : p && p[m];
1543
+ l += g || e, g || (r = !1);
1544
+ const [b, S] = ae(e, g);
1545
+ s.push(["col", { style: `${b}: ${S}` }]);
1546
+ }
1547
+ }
1548
+ const c = r ? `${l}px` : "", a = r ? "" : `${l}px`;
1549
+ return { colgroup: ["colgroup", {}, ...s], tableWidth: c, tableMinWidth: a };
1550
+ }
1551
+ function Re(t, e) {
1552
+ return t.createAndFill();
1553
+ }
1554
+ function ro(t) {
1555
+ if (t.cached.tableNodeTypes)
1556
+ return t.cached.tableNodeTypes;
1557
+ const e = {};
1558
+ return Object.keys(t.nodes).forEach((o) => {
1559
+ const n = t.nodes[o];
1560
+ n.spec.tableRole && (e[n.spec.tableRole] = n);
1561
+ }), t.cached.tableNodeTypes = e, e;
1562
+ }
1563
+ function so(t, e, o, n, l) {
1564
+ const r = ro(t), s = [], i = [];
1565
+ for (let a = 0; a < o; a += 1) {
1566
+ const d = Re(r.cell);
1567
+ if (d && i.push(d), n) {
1568
+ const u = Re(r.header_cell);
1569
+ u && s.push(u);
1570
+ }
1571
+ }
1572
+ const c = [];
1573
+ for (let a = 0; a < e; a += 1)
1574
+ c.push(r.row.createChecked(null, n && a === 0 ? s : i));
1575
+ return r.table.createChecked(null, c);
1576
+ }
1577
+ function io(t) {
1578
+ return t instanceof w;
1579
+ }
1580
+ var U = ({ editor: t }) => {
1581
+ const { selection: e } = t.state;
1582
+ if (!io(e))
1583
+ return !1;
1584
+ let o = 0;
1585
+ const n = qe(e.ranges[0].$from, (r) => r.type.name === "table");
1586
+ return n == null || n.node.descendants((r) => {
1587
+ if (r.type.name === "table")
1588
+ return !1;
1589
+ ["tableCell", "tableHeader"].includes(r.type.name) && (o += 1);
1590
+ }), o === e.ranges.length ? (t.commands.deleteTable(), !0) : !1;
1591
+ }, co = "";
1592
+ function ao(t) {
1593
+ return (t || "").replace(/\s+/g, " ").trim();
1594
+ }
1595
+ function uo(t, e, o = {}) {
1596
+ var n;
1597
+ const l = (n = o.cellLineSeparator) != null ? n : co;
1598
+ if (!t || !t.content || t.content.length === 0)
1599
+ return "";
1600
+ const r = [];
1601
+ t.content.forEach((p) => {
1602
+ const m = [];
1603
+ p.content && p.content.forEach((g) => {
1604
+ let b = "";
1605
+ g.content && Array.isArray(g.content) && g.content.length > 1 ? b = g.content.map((T) => e.renderChildren(T)).join(l) : b = g.content ? e.renderChildren(g.content) : "";
1606
+ const S = ao(b), A = g.type === "tableHeader";
1607
+ m.push({ text: S, isHeader: A });
1608
+ }), r.push(m);
1609
+ });
1610
+ const s = r.reduce((p, m) => Math.max(p, m.length), 0);
1611
+ if (s === 0)
1612
+ return "";
1613
+ const i = new Array(s).fill(0);
1614
+ r.forEach((p) => {
1615
+ var m;
1616
+ for (let g = 0; g < s; g += 1) {
1617
+ const S = (((m = p[g]) == null ? void 0 : m.text) || "").length;
1618
+ S > i[g] && (i[g] = S), i[g] < 3 && (i[g] = 3);
1619
+ }
1620
+ });
1621
+ const c = (p, m) => p + " ".repeat(Math.max(0, m - p.length)), a = r[0], d = a.some((p) => p.isHeader);
1622
+ let u = `
1623
+ `;
1624
+ const f = new Array(s).fill(0).map((p, m) => d && a[m] && a[m].text || "");
1625
+ return u += `| ${f.map((p, m) => c(p, i[m])).join(" | ")} |
1626
+ `, u += `| ${i.map((p) => "-".repeat(Math.max(3, p))).join(" | ")} |
1627
+ `, (d ? r.slice(1) : r).forEach((p) => {
1628
+ u += `| ${new Array(s).fill(0).map((m, g) => c(p[g] && p[g].text || "", i[g])).join(" | ")} |
1629
+ `;
1630
+ }), u;
1631
+ }
1632
+ var fo = uo, je = J.create({
1633
+ name: "table",
1634
+ // @ts-ignore
1635
+ addOptions() {
1636
+ return {
1637
+ HTMLAttributes: {},
1638
+ resizable: !1,
1639
+ renderWrapper: !1,
1640
+ handleWidth: 5,
1641
+ cellMinWidth: 25,
1642
+ // TODO: fix
1643
+ View: no,
1644
+ lastColumnResizable: !0,
1645
+ allowTableNodeSelection: !1
1646
+ };
1647
+ },
1648
+ content: "tableRow+",
1649
+ tableRole: "table",
1650
+ isolating: !0,
1651
+ group: "block",
1652
+ parseHTML() {
1653
+ return [{ tag: "table" }];
1654
+ },
1655
+ renderHTML({ node: t, HTMLAttributes: e }) {
1656
+ const { colgroup: o, tableWidth: n, tableMinWidth: l } = lo(t, this.options.cellMinWidth), r = e.style;
1657
+ function s() {
1658
+ return r || (n ? `width: ${n}` : `min-width: ${l}`);
1659
+ }
1660
+ const i = [
1661
+ "table",
1662
+ Z(this.options.HTMLAttributes, e, {
1663
+ style: s()
1664
+ }),
1665
+ o,
1666
+ ["tbody", 0]
1667
+ ];
1668
+ return this.options.renderWrapper ? ["div", { class: "tableWrapper" }, i] : i;
1669
+ },
1670
+ parseMarkdown: (t, e) => {
1671
+ const o = [];
1672
+ if (t.header) {
1673
+ const n = [];
1674
+ t.header.forEach((l) => {
1675
+ n.push(e.createNode("tableHeader", {}, [{ type: "paragraph", content: e.parseInline(l.tokens) }]));
1676
+ }), o.push(e.createNode("tableRow", {}, n));
1677
+ }
1678
+ return t.rows && t.rows.forEach((n) => {
1679
+ const l = [];
1680
+ n.forEach((r) => {
1681
+ l.push(e.createNode("tableCell", {}, [{ type: "paragraph", content: e.parseInline(r.tokens) }]));
1682
+ }), o.push(e.createNode("tableRow", {}, l));
1683
+ }), e.createNode("table", void 0, o);
1684
+ },
1685
+ renderMarkdown: (t, e) => fo(t, e),
1686
+ addCommands() {
1687
+ return {
1688
+ insertTable: ({ rows: t = 3, cols: e = 3, withHeaderRow: o = !0 } = {}) => ({ tr: n, dispatch: l, editor: r }) => {
1689
+ const s = so(r.schema, t, e, o);
1690
+ if (l) {
1691
+ const i = n.selection.from + 1;
1692
+ n.replaceSelectionWith(s).scrollIntoView().setSelection(Je.near(n.doc.resolve(i)));
1693
+ }
1694
+ return !0;
1695
+ },
1696
+ addColumnBefore: () => ({ state: t, dispatch: e }) => St(t, e),
1697
+ addColumnAfter: () => ({ state: t, dispatch: e }) => xt(t, e),
1698
+ deleteColumn: () => ({ state: t, dispatch: e }) => Tt(t, e),
1699
+ addRowBefore: () => ({ state: t, dispatch: e }) => vt(t, e),
1700
+ addRowAfter: () => ({ state: t, dispatch: e }) => Mt(t, e),
1701
+ deleteRow: () => ({ state: t, dispatch: e }) => kt(t, e),
1702
+ deleteTable: () => ({ state: t, dispatch: e }) => Dt(t, e),
1703
+ mergeCells: () => ({ state: t, dispatch: e }) => he(t, e),
1704
+ splitCell: () => ({ state: t, dispatch: e }) => pe(t, e),
1705
+ toggleHeaderColumn: () => ({ state: t, dispatch: e }) => I("column")(t, e),
1706
+ toggleHeaderRow: () => ({ state: t, dispatch: e }) => I("row")(t, e),
1707
+ toggleHeaderCell: () => ({ state: t, dispatch: e }) => $t(t, e),
1708
+ mergeOrSplit: () => ({ state: t, dispatch: e }) => he(t, e) ? !0 : pe(t, e),
1709
+ setCellAttribute: (t, e) => ({ state: o, dispatch: n }) => Ht(t, e)(o, n),
1710
+ goToNextCell: () => ({ state: t, dispatch: e }) => ge(1)(t, e),
1711
+ goToPreviousCell: () => ({ state: t, dispatch: e }) => ge(-1)(t, e),
1712
+ fixTables: () => ({ state: t, dispatch: e }) => (e && We(t), !0),
1713
+ setCellSelection: (t) => ({ tr: e, dispatch: o }) => {
1714
+ if (o) {
1715
+ const n = w.create(e.doc, t.anchorCell, t.headCell);
1716
+ e.setSelection(n);
1717
+ }
1718
+ return !0;
1719
+ }
1720
+ };
1721
+ },
1722
+ addKeyboardShortcuts() {
1723
+ return {
1724
+ Tab: () => this.editor.commands.goToNextCell() ? !0 : this.editor.can().addRowAfter() ? this.editor.chain().addRowAfter().goToNextCell().run() : !1,
1725
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
1726
+ Backspace: U,
1727
+ "Mod-Backspace": U,
1728
+ Delete: U,
1729
+ "Mod-Delete": U
1730
+ };
1731
+ },
1732
+ addProseMirrorPlugins() {
1733
+ return [
1734
+ ...this.options.resizable && this.editor.isEditable ? [
1735
+ Xt({
1736
+ handleWidth: this.options.handleWidth,
1737
+ cellMinWidth: this.options.cellMinWidth,
1738
+ defaultCellMinWidth: this.options.cellMinWidth,
1739
+ View: this.options.View,
1740
+ lastColumnResizable: this.options.lastColumnResizable
1741
+ })
1742
+ ] : [],
1743
+ oo({
1744
+ allowTableNodeSelection: this.options.allowTableNodeSelection
1745
+ })
1746
+ ];
1747
+ },
1748
+ extendNodeSchema(t) {
1749
+ const e = {
1750
+ name: t.name,
1751
+ options: t.options,
1752
+ storage: t.storage
1753
+ };
1754
+ return {
1755
+ tableRole: Ue(Ge(t, "tableRole", e))
1756
+ };
1757
+ }
1758
+ });
1759
+ Ee.create({
1760
+ name: "tableKit",
1761
+ addExtensions() {
1762
+ const t = [];
1763
+ return this.options.table !== !1 && t.push(je.configure(this.options.table)), this.options.tableCell !== !1 && t.push(_e.configure(this.options.tableCell)), this.options.tableHeader !== !1 && t.push(Oe.configure(this.options.tableHeader)), this.options.tableRow !== !1 && t.push(Fe.configure(this.options.tableRow)), t;
1764
+ }
1765
+ });
1766
+ function ho(t, e, o) {
1767
+ if (!t.doc)
1768
+ return t;
1769
+ const n = t.doc.nodeAt(e);
1770
+ if (!n || o === n.attrs.backgroundColor)
1771
+ return t;
1772
+ const l = {
1773
+ ...n.attrs,
1774
+ backgroundColor: o
1775
+ };
1776
+ return t.setNodeMarkup(e, n.type, l, n.marks);
1777
+ }
1778
+ function po(t, e, o) {
1779
+ const { doc: n, selection: l } = t;
1780
+ return !n || !l || !(l instanceof w) || l.forEachCell((r, s) => {
1781
+ t = ho(t, s, o);
1782
+ }), t;
1783
+ }
1784
+ function ve(t, e) {
1785
+ return ({ tr: o, state: n, dispatch: l }) => {
1786
+ const { selection: r } = n;
1787
+ return o = o.setSelection(r), o = po(o, e, t), o.docChanged ? (l == null || l(o), !0) : !1;
1788
+ };
1789
+ }
1790
+ const mo = Ee.create({
1791
+ name: "tableCellBackground",
1792
+ addOptions() {
1793
+ return {
1794
+ types: ["tableCell"],
1795
+ HTMLAttributes: {}
1796
+ };
1797
+ },
1798
+ addGlobalAttributes() {
1799
+ return [
1800
+ {
1801
+ types: this.options.types,
1802
+ attributes: {
1803
+ backgroundColor: {
1804
+ parseHTML: (t) => t.style.backgroundColor || "",
1805
+ renderHTML: (t) => !t.backgroundColor || t.backgroundColor === "" ? {} : {
1806
+ style: `background-color: ${t.backgroundColor}`
1807
+ }
1808
+ }
1809
+ }
1810
+ }
1811
+ ];
1812
+ },
1813
+ addCommands() {
1814
+ return {
1815
+ setTableCellBackground: (t) => ve(t, this.options),
1816
+ unsetTableCellBackground: () => ve("", this.options)
1817
+ };
1818
+ }
1819
+ }), go = /(android|bb\d+|meego).+mobile|armv7l|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|samsungbrowser.*mobile|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i, bo = /CrOS/, wo = /android|ipad|playbook|silk/i;
1820
+ function Me(t = {}) {
1821
+ let e = t.ua || typeof navigator < "u" && navigator.userAgent;
1822
+ return e && typeof e == "object" && e.headers && typeof e.headers["user-agent"] == "string" && (e = e.headers["user-agent"]), typeof e != "string" ? !1 : !!(go.test(e) && !bo.test(e) || t.tablet && wo.test(e) || t.tablet && t.featureDetect && navigator && navigator.maxTouchPoints > 1 && e.includes("Macintosh") && e.includes("Safari"));
1823
+ }
1824
+ const Ne = (t) => Array.from({ length: t }).map((e, o) => o + 1);
1825
+ function Co(t) {
1826
+ var f;
1827
+ const [e, o] = _(!1), [n, l] = _(!0), [r, s] = _({
1828
+ rows: Me() ? O : F,
1829
+ cols: Me() ? O : F
1830
+ }), [i, c] = _({
1831
+ rows: j,
1832
+ cols: j
1833
+ });
1834
+ function a(h, p) {
1835
+ h === r.rows && s((m) => ({
1836
+ ...m,
1837
+ rows: Math.min(h + 1, O)
1838
+ })), p === r.cols && s((m) => ({
1839
+ ...m,
1840
+ cols: Math.min(p + 1, O)
1841
+ })), c({
1842
+ rows: h,
1843
+ cols: p
1844
+ });
1845
+ }
1846
+ function d(h, p) {
1847
+ t == null || t.createTable({ rows: h, cols: p, withHeaderRow: n }), u(), o(!1);
1848
+ }
1849
+ function u() {
1850
+ l(!1), s({
1851
+ rows: F,
1852
+ cols: F
1853
+ }), c({
1854
+ rows: j,
1855
+ cols: j
1856
+ });
1857
+ }
1858
+ return /* @__PURE__ */ ee(
1859
+ tt,
1860
+ {
1861
+ open: e,
1862
+ onOpenChange: o,
1863
+ modal: !0,
1864
+ children: [
1865
+ /* @__PURE__ */ k(
1866
+ ot,
1867
+ {
1868
+ "data-state": t != null && t.dataState ? "on" : "off",
1869
+ asChild: !0,
1870
+ children: t == null ? void 0 : t.children
1871
+ }
1872
+ ),
1873
+ /* @__PURE__ */ k(
1874
+ nt,
1875
+ {
1876
+ align: "start",
1877
+ className: "richtext-w-full !richtext-p-2",
1878
+ side: "bottom",
1879
+ children: /* @__PURE__ */ ee("div", { className: "table-grid-size-editor richtext-p-0", children: [
1880
+ /* @__PURE__ */ k("div", { className: "richtext-flex richtext-flex-col richtext-flex-wrap richtext-justify-between richtext-gap-1", children: (f = Ne(r == null ? void 0 : r.rows)) == null ? void 0 : f.map((h) => {
1881
+ var p;
1882
+ return /* @__PURE__ */ k(
1883
+ "div",
1884
+ {
1885
+ className: "richtext-flex richtext-gap-1",
1886
+ children: (p = Ne(r == null ? void 0 : r.cols)) == null ? void 0 : p.map((m) => /* @__PURE__ */ k(
1887
+ "div",
1888
+ {
1889
+ onMouseDown: () => d(h, m),
1890
+ onMouseOver: () => a(h, m),
1891
+ className: `richtext-cursor-pointer richtext-border-border ${m <= i.cols && h <= i.rows && "tableCellActive !richtext-bg-foreground"}`,
1892
+ children: /* @__PURE__ */ k("div", { className: "richtext-box-border richtext-size-4 richtext-rounded-[2px] !richtext-border richtext-border-solid !richtext-border-border richtext-p-1" })
1893
+ },
1894
+ `richtext-table-col-${m}`
1895
+ ))
1896
+ },
1897
+ `richtext-table-row-${h}`
1898
+ );
1899
+ }) }),
1900
+ /* @__PURE__ */ ee("div", { className: "richtext-mt-2 richtext-text-center richtext-text-sm richtext-text-zinc-600", children: [
1901
+ i.rows,
1902
+ "x",
1903
+ i.cols
1904
+ ] })
1905
+ ] })
1906
+ }
1907
+ )
1908
+ ]
1909
+ }
1910
+ );
1911
+ }
1912
+ function Ho() {
1913
+ const t = et(), e = lt(yo.name), {
1914
+ icon: o = void 0,
1915
+ tooltip: n = void 0,
1916
+ action: l = void 0,
1917
+ isActive: r = void 0,
1918
+ color: s
1919
+ } = (e == null ? void 0 : e.componentProps) ?? {}, { dataState: i, disabled: c } = rt(r);
1920
+ if (!e)
1921
+ return /* @__PURE__ */ k(Ye, {});
1922
+ function a(d) {
1923
+ t.chain().focus().insertTable({ ...d, withHeaderRow: !1 }).run();
1924
+ }
1925
+ return /* @__PURE__ */ k(
1926
+ Co,
1927
+ {
1928
+ createTable: a,
1929
+ dataState: i,
1930
+ children: /* @__PURE__ */ k(
1931
+ Qe,
1932
+ {
1933
+ action: l,
1934
+ color: s,
1935
+ dataState: i,
1936
+ icon: o,
1937
+ isActive: r,
1938
+ tooltip: n,
1939
+ disabled: c
1940
+ }
1941
+ )
1942
+ }
1943
+ );
1944
+ }
1945
+ const yo = /* @__PURE__ */ je.extend({
1946
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1947
+ //@ts-expect-error
1948
+ addOptions() {
1949
+ var t;
1950
+ return {
1951
+ ...(t = this.parent) == null ? void 0 : t.call(this),
1952
+ HTMLAttributes: {
1953
+ style: `
1954
+ border: 1px solid #000;
1955
+ border-collapse: collapse;
1956
+ width: 100%;
1957
+ `
1958
+ },
1959
+ resizable: !0,
1960
+ lastColumnResizable: !0,
1961
+ allowTableNodeSelection: !1,
1962
+ button: ({ editor: e, t: o }) => ({
1963
+ componentProps: {
1964
+ isActive: () => e.isActive("table"),
1965
+ icon: "Table",
1966
+ tooltip: o("editor.table.tooltip")
1967
+ }
1968
+ })
1969
+ };
1970
+ },
1971
+ addExtensions() {
1972
+ return [
1973
+ Fe.configure(this.options.tableRow),
1974
+ Oe.configure(this.options.tableHeader),
1975
+ _e.configure(this.options.tableCell),
1976
+ mo.configure(this.options.tableCellBackground)
1977
+ ];
1978
+ }
1979
+ });
1980
+ export {
1981
+ w as C,
1982
+ Ho as R,
1983
+ yo as T
1984
+ };