reactjs-tiptap-editor 1.0.22 → 1.0.24

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