okno 1.0.0-alpha.2 → 1.0.0-alpha.21

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