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