@clevertask/scribe 0.1.4 → 0.1.5

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 (85) hide show
  1. package/README.md +3 -0
  2. package/dist/BarMenu-V1uRL3bt.js +272 -0
  3. package/dist/assets/index.css +1 -1
  4. package/dist/components/Menu/BarMenu.d.ts.map +1 -1
  5. package/dist/components/Menu/BarMenu.js +2 -10
  6. package/dist/components/Menu/BubbleMenu.d.ts.map +1 -1
  7. package/dist/components/Menu/BubbleMenu.js +165 -1023
  8. package/dist/components/Menu/LinkBubbleMenu.d.ts +8 -0
  9. package/dist/components/Menu/LinkBubbleMenu.d.ts.map +1 -0
  10. package/dist/components/Menu/LinkBubbleMenu.js +78 -0
  11. package/dist/components/Menu/LinkEditor.d.ts +14 -0
  12. package/dist/components/Menu/LinkEditor.d.ts.map +1 -0
  13. package/dist/components/Menu/LinkEditor.js +140 -0
  14. package/dist/components/Menu/Mobile/ListOptionBar.d.ts.map +1 -1
  15. package/dist/components/Menu/Mobile/ListOptionBar.js +38 -44
  16. package/dist/components/Menu/linkBubbleMenuPlugin.d.ts +5 -0
  17. package/dist/components/Menu/linkBubbleMenuPlugin.d.ts.map +1 -0
  18. package/dist/components/Menu/linkBubbleMenuPlugin.js +7 -0
  19. package/dist/components/Menu/linkUrl.d.ts +2 -0
  20. package/dist/components/Menu/linkUrl.d.ts.map +1 -0
  21. package/dist/components/Menu/linkUrl.js +21 -0
  22. package/dist/components/Scribe/extension/emoji/EmojiList.js +58 -45
  23. package/dist/components/Scribe/extension/emoji/suggest.d.ts +2 -2
  24. package/dist/components/Scribe/extension/emoji/suggest.d.ts.map +1 -1
  25. package/dist/components/Scribe/extension/emoji/suggest.js +39 -43
  26. package/dist/components/Scribe/extension/extension-link.d.ts.map +1 -1
  27. package/dist/components/Scribe/extension/extension-link.js +2 -4
  28. package/dist/components/Scribe/extension/extension-markdown-paste.d.ts.map +1 -1
  29. package/dist/components/Scribe/extension/extension-markdown-paste.js +50 -45
  30. package/dist/components/Scribe/extension/extension-selectedText.d.ts.map +1 -1
  31. package/dist/components/Scribe/extension/extension-selectedText.js +10 -12
  32. package/dist/components/Scribe/extension/getPopupMountTarget.d.ts.map +1 -1
  33. package/dist/components/Scribe/extension/getPopupMountTarget.js +12 -15
  34. package/dist/components/Scribe/extension/index.d.ts +4 -4
  35. package/dist/components/Scribe/extension/index.d.ts.map +1 -1
  36. package/dist/components/Scribe/extension/index.js +2 -39521
  37. package/dist/components/Scribe/extension/slashCommand/SlashCommandList.js +3369 -3731
  38. package/dist/components/Scribe/extension/slashCommand/index.js +2 -6
  39. package/dist/components/Scribe/extension/slashCommand/items.d.ts.map +1 -1
  40. package/dist/components/Scribe/extension/slashCommand/items.js +177 -176
  41. package/dist/components/Scribe/extension/slashCommand/renderItems.d.ts.map +1 -1
  42. package/dist/components/Scribe/extension/slashCommand/renderItems.js +35 -41
  43. package/dist/components/Scribe/extension/tableOfContents.js +153 -180
  44. package/dist/components/Scribe/index.d.ts.map +1 -1
  45. package/dist/components/Scribe/index.js +113 -153
  46. package/dist/dist-BQjH-i-q.js +7016 -0
  47. package/dist/dist-CnXCIcnl.js +3506 -0
  48. package/dist/dist-RuuEA1GJ.js +686 -0
  49. package/dist/extension-CZOsheCI.js +56236 -0
  50. package/dist/extension-link-DZID_SYl.js +908 -0
  51. package/dist/floating-ui.dom-rih69525.js +928 -0
  52. package/dist/html-to-markdown-CrNOkSye.js +497 -0
  53. package/dist/icons/ToolbarIcons.d.ts.map +1 -1
  54. package/dist/icons/ToolbarIcons.js +76 -135
  55. package/dist/main.css +10 -0
  56. package/dist/main.js +7 -15
  57. package/dist/markdown-to-html-DEczPfuq.js +1458 -0
  58. package/dist/menus-CzX7kyXn.js +633 -0
  59. package/dist/purify.es-DF9CW1cl.js +767 -0
  60. package/dist/rolldown-runtime-B8UxIWdF.js +7 -0
  61. package/dist/slashCommand-B7CRIaKG.js +429 -0
  62. package/dist/tables-CjOC70rm.js +1345 -0
  63. package/dist/tippy.esm-D9LL2xiE.js +1713 -0
  64. package/dist/utils/convert-legacy-math-delimiters.d.ts.map +1 -1
  65. package/dist/utils/convert-legacy-math-delimiters.js +7 -13
  66. package/dist/utils/create-scribe-editor.js +2 -31
  67. package/dist/utils/html-to-markdown.d.ts.map +1 -1
  68. package/dist/utils/html-to-markdown.js +2 -600
  69. package/dist/utils/index.js +24 -12
  70. package/dist/utils/is-in-viewport.d.ts.map +1 -1
  71. package/dist/utils/is-in-viewport.js +6 -6
  72. package/dist/utils/markdown-to-html.d.ts.map +1 -1
  73. package/dist/utils/markdown-to-html.js +2 -5
  74. package/dist/vite-env.d.js +0 -1
  75. package/package.json +36 -34
  76. package/dist/BarMenu-BNk2I0zi.js +0 -327
  77. package/dist/extension-link-P1rro4zO.js +0 -1059
  78. package/dist/floating-ui.dom-ZRy7FSVk.js +0 -1246
  79. package/dist/index-BMISMQrG.js +0 -855
  80. package/dist/index-ByyiiYsp.js +0 -1410
  81. package/dist/index-CnKS-BY2.js +0 -13834
  82. package/dist/index-CnQHDObA.js +0 -539
  83. package/dist/markdown-to-html-Bw9L43K6.js +0 -1135
  84. package/dist/purify.es-DC1iJOxX.js +0 -864
  85. package/dist/tippy.esm-DLHdsnfG.js +0 -1711
@@ -1,1410 +0,0 @@
1
- import { P as Z, S as M, k as ye, T as E, c as Se, F as R, d as z, b as fe, D as X, e as q, N as Ae, f as Re } from "./index-CnKS-BY2.js";
2
- let U, J;
3
- if (typeof WeakMap < "u") {
4
- let t = /* @__PURE__ */ new WeakMap();
5
- U = (e) => t.get(e), J = (e, o) => (t.set(e, o), o);
6
- } else {
7
- const t = [];
8
- let o = 0;
9
- U = (n) => {
10
- for (let l = 0; l < t.length; l += 2) if (t[l] == n) return t[l + 1];
11
- }, J = (n, l) => (o == 10 && (o = 0), t[o++] = n, t[o++] = l);
12
- }
13
- var C = class {
14
- constructor(t, e, o, n) {
15
- this.width = t, this.height = e, this.map = o, this.problems = n;
16
- }
17
- findCell(t) {
18
- for (let e = 0; e < this.map.length; e++) {
19
- const o = this.map[e];
20
- if (o != t) continue;
21
- const n = e % this.width, l = e / this.width | 0;
22
- let s = n + 1, r = l + 1;
23
- for (let c = 1; s < this.width && this.map[e + c] == o; c++) s++;
24
- for (let c = 1; r < this.height && this.map[e + this.width * c] == o; c++) r++;
25
- return {
26
- left: n,
27
- top: l,
28
- right: s,
29
- bottom: r
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, o) {
39
- const { left: n, right: l, top: s, bottom: r } = this.findCell(t);
40
- return e == "horiz" ? (o < 0 ? n == 0 : l == this.width) ? null : this.map[s * this.width + (o < 0 ? n - 1 : l)] : (o < 0 ? s == 0 : r == this.height) ? null : this.map[n + this.width * (o < 0 ? s - 1 : r)];
41
- }
42
- rectBetween(t, e) {
43
- const { left: o, right: n, top: l, bottom: s } = this.findCell(t), { left: r, right: c, top: i, bottom: a } = this.findCell(e);
44
- return {
45
- left: Math.min(o, r),
46
- top: Math.min(l, i),
47
- right: Math.max(n, c),
48
- bottom: Math.max(s, a)
49
- };
50
- }
51
- cellsInRect(t) {
52
- const e = [], o = {};
53
- for (let n = t.top; n < t.bottom; n++) for (let l = t.left; l < t.right; l++) {
54
- const s = n * this.width + l, r = this.map[s];
55
- o[r] || (o[r] = !0, !(l == t.left && l && this.map[s - 1] == r || n == t.top && n && this.map[s - this.width] == r) && e.push(r));
56
- }
57
- return e;
58
- }
59
- positionAt(t, e, o) {
60
- for (let n = 0, l = 0; ; n++) {
61
- const s = l + o.child(n).nodeSize;
62
- if (n == t) {
63
- let r = e + t * this.width;
64
- const c = (t + 1) * this.width;
65
- for (; r < c && this.map[r] < l; ) r++;
66
- return r == c ? s - 1 : this.map[r];
67
- }
68
- l = s;
69
- }
70
- }
71
- static get(t) {
72
- return U(t) || J(t, xe(t));
73
- }
74
- };
75
- function xe(t) {
76
- if (t.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + t.type.name);
77
- const e = ve(t), o = t.childCount, n = [];
78
- let l = 0, s = null;
79
- const r = [];
80
- for (let a = 0, d = e * o; a < d; a++) n[a] = 0;
81
- for (let a = 0, d = 0; a < o; a++) {
82
- const f = t.child(a);
83
- d++;
84
- for (let p = 0; ; p++) {
85
- for (; l < n.length && n[l] != 0; ) l++;
86
- if (p == f.childCount) break;
87
- const m = f.child(p), { colspan: g, rowspan: b, colwidth: B } = m.attrs;
88
- for (let H = 0; H < b; H++) {
89
- if (H + a >= o) {
90
- (s || (s = [])).push({
91
- type: "overlong_rowspan",
92
- pos: d,
93
- n: b - H
94
- });
95
- break;
96
- }
97
- const _ = l + H * e;
98
- for (let k = 0; k < g; k++) {
99
- n[_ + k] == 0 ? n[_ + k] = d : (s || (s = [])).push({
100
- type: "collision",
101
- row: a,
102
- pos: d,
103
- n: g - k
104
- });
105
- const $ = B && B[k];
106
- if ($) {
107
- const L = (_ + k) % e * 2, K = r[L];
108
- K == null || K != $ && r[L + 1] == 1 ? (r[L] = $, r[L + 1] = 1) : K == $ && r[L + 1]++;
109
- }
110
- }
111
- }
112
- l += g, d += m.nodeSize;
113
- }
114
- const u = (a + 1) * e;
115
- let h = 0;
116
- for (; l < u; ) n[l++] == 0 && h++;
117
- h && (s || (s = [])).push({
118
- type: "missing",
119
- row: a,
120
- n: h
121
- }), d++;
122
- }
123
- (e === 0 || o === 0) && (s || (s = [])).push({ type: "zero_sized" });
124
- const c = new C(e, o, n, s);
125
- let i = !1;
126
- for (let a = 0; !i && a < r.length; a += 2) r[a] != null && r[a + 1] < o && (i = !0);
127
- return i && Me(c, r, t), c;
128
- }
129
- function ve(t) {
130
- let e = -1, o = !1;
131
- for (let n = 0; n < t.childCount; n++) {
132
- const l = t.child(n);
133
- let s = 0;
134
- if (o) for (let r = 0; r < n; r++) {
135
- const c = t.child(r);
136
- for (let i = 0; i < c.childCount; i++) {
137
- const a = c.child(i);
138
- r + a.attrs.rowspan > n && (s += a.attrs.colspan);
139
- }
140
- }
141
- for (let r = 0; r < l.childCount; r++) {
142
- const c = l.child(r);
143
- s += c.attrs.colspan, c.attrs.rowspan > 1 && (o = !0);
144
- }
145
- e == -1 ? e = s : e != s && (e = Math.max(e, s));
146
- }
147
- return e;
148
- }
149
- function Me(t, e, o) {
150
- t.problems || (t.problems = []);
151
- const n = {};
152
- for (let l = 0; l < t.map.length; l++) {
153
- const s = t.map[l];
154
- if (n[s]) continue;
155
- n[s] = !0;
156
- const r = o.nodeAt(s);
157
- if (!r) throw new RangeError(`No cell with offset ${s} found`);
158
- let c = null;
159
- const i = r.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 = Ne(i)))[a] = d);
163
- }
164
- c && t.problems.unshift({
165
- type: "colwidth mismatch",
166
- pos: s,
167
- colwidth: c
168
- });
169
- }
170
- }
171
- function Ne(t) {
172
- if (t.colwidth) return t.colwidth.slice();
173
- const e = [];
174
- for (let o = 0; o < t.colspan; o++) e.push(0);
175
- return e;
176
- }
177
- function y(t) {
178
- let e = t.cached.tableNodeTypes;
179
- if (!e) {
180
- e = t.cached.tableNodeTypes = {};
181
- for (const o in t.nodes) {
182
- const n = t.nodes[o], l = n.spec.tableRole;
183
- l && (e[l] = n);
184
- }
185
- }
186
- return e;
187
- }
188
- const N = new Z("selectingCells");
189
- function T(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 ze(t) {
194
- for (let e = t.depth; e > 0; e--) {
195
- const o = t.node(e).type.spec.tableRole;
196
- if (o === "cell" || o === "header_cell") return t.node(e);
197
- }
198
- return null;
199
- }
200
- function A(t) {
201
- const e = t.selection.$head;
202
- for (let o = e.depth; o > 0; o--) if (e.node(o).type.spec.tableRole == "row") return !0;
203
- return !1;
204
- }
205
- function O(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 o = T(e.$head) || ke(e.$head);
210
- if (o) return o;
211
- throw new RangeError(`No cell found around position ${e.head}`);
212
- }
213
- function ke(t) {
214
- for (let e = t.nodeAfter, o = t.pos; e; e = e.firstChild, o++) {
215
- const n = e.type.spec.tableRole;
216
- if (n == "cell" || n == "header_cell") return t.doc.resolve(o);
217
- }
218
- for (let e = t.nodeBefore, o = t.pos; e; e = e.lastChild, o--) {
219
- const n = e.type.spec.tableRole;
220
- if (n == "cell" || n == "header_cell") return t.doc.resolve(o - e.nodeSize);
221
- }
222
- }
223
- function Y(t) {
224
- return t.parent.type.spec.tableRole == "row" && !!t.nodeAfter;
225
- }
226
- function Ee(t) {
227
- return t.node(0).resolve(t.pos + t.nodeAfter.nodeSize);
228
- }
229
- function ee(t, e) {
230
- return t.depth == e.depth && t.pos >= e.start(-1) && t.pos <= e.end(-1);
231
- }
232
- function ue(t, e, o) {
233
- const n = t.node(-1), l = C.get(n), s = t.start(-1), r = l.nextCell(t.pos - s, e, o);
234
- return r == null ? null : t.node(0).resolve(s + r);
235
- }
236
- function D(t, e, o = 1) {
237
- const n = {
238
- ...t,
239
- colspan: t.colspan - o
240
- };
241
- return n.colwidth && (n.colwidth = n.colwidth.slice(), n.colwidth.splice(e, o), n.colwidth.some((l) => l > 0) || (n.colwidth = null)), n;
242
- }
243
- function he(t, e, o = 1) {
244
- const n = {
245
- ...t,
246
- colspan: t.colspan + o
247
- };
248
- if (n.colwidth) {
249
- n.colwidth = n.colwidth.slice();
250
- for (let l = 0; l < o; l++) n.colwidth.splice(e, 0, 0);
251
- }
252
- return n;
253
- }
254
- function Te(t, e, o) {
255
- const n = y(e.type.schema).header_cell;
256
- for (let l = 0; l < t.height; l++) if (e.nodeAt(t.map[o + l * t.width]).type != n) return !1;
257
- return !0;
258
- }
259
- var w = class v extends M {
260
- constructor(e, o = e) {
261
- const n = e.node(-1), l = C.get(n), s = e.start(-1), r = l.rectBetween(e.pos - s, o.pos - s), c = e.node(0), i = l.cellsInRect(r).filter((d) => d != o.pos - s);
262
- i.unshift(o.pos - s);
263
- const a = i.map((d) => {
264
- const f = n.nodeAt(d);
265
- if (!f) throw new RangeError(`No cell with offset ${d} found`);
266
- const u = s + d + 1;
267
- return new Se(c.resolve(u), c.resolve(u + f.content.size));
268
- });
269
- super(a[0].$from, a[0].$to, a), this.$anchorCell = e, this.$headCell = o;
270
- }
271
- map(e, o) {
272
- const n = e.resolve(o.map(this.$anchorCell.pos)), l = e.resolve(o.map(this.$headCell.pos));
273
- if (Y(n) && Y(l) && ee(n, l)) {
274
- const s = this.$anchorCell.node(-1) != n.node(-1);
275
- return s && this.isRowSelection() ? v.rowSelection(n, l) : s && this.isColSelection() ? v.colSelection(n, l) : new v(n, l);
276
- }
277
- return E.between(n, l);
278
- }
279
- content() {
280
- const e = this.$anchorCell.node(-1), o = C.get(e), n = this.$anchorCell.start(-1), l = o.rectBetween(this.$anchorCell.pos - n, this.$headCell.pos - n), s = {}, r = [];
281
- for (let i = l.top; i < l.bottom; i++) {
282
- const a = [];
283
- for (let d = i * o.width + l.left, f = l.left; f < l.right; f++, d++) {
284
- const u = o.map[d];
285
- if (s[u]) continue;
286
- s[u] = !0;
287
- const h = o.findCell(u);
288
- let p = e.nodeAt(u);
289
- if (!p) throw new RangeError(`No cell with offset ${u} found`);
290
- const m = l.left - h.left, g = h.right - l.right;
291
- if (m > 0 || g > 0) {
292
- let b = p.attrs;
293
- if (m > 0 && (b = D(b, 0, m)), g > 0 && (b = D(b, b.colspan - g, g)), h.left < l.left) {
294
- if (p = p.type.createAndFill(b), !p) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`);
295
- } else p = p.type.create(b, p.content);
296
- }
297
- if (h.top < l.top || h.bottom > l.bottom) {
298
- const b = {
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(b) : p = p.type.create(b, p.content);
303
- }
304
- a.push(p);
305
- }
306
- r.push(e.child(i).copy(R.from(a)));
307
- }
308
- const c = this.isColSelection() && this.isRowSelection() ? e : r;
309
- return new z(R.from(c), 1, 1);
310
- }
311
- replace(e, o = z.empty) {
312
- const n = e.steps.length, l = this.ranges;
313
- for (let r = 0; r < l.length; r++) {
314
- const { $from: c, $to: i } = l[r], a = e.mapping.slice(n);
315
- e.replace(a.map(c.pos), a.map(i.pos), r ? z.empty : o);
316
- }
317
- const s = M.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)), -1);
318
- s && e.setSelection(s);
319
- }
320
- replaceWith(e, o) {
321
- this.replace(e, new z(R.from(o), 0, 0));
322
- }
323
- forEachCell(e) {
324
- const o = this.$anchorCell.node(-1), n = C.get(o), l = this.$anchorCell.start(-1), s = n.cellsInRect(n.rectBetween(this.$anchorCell.pos - l, this.$headCell.pos - l));
325
- for (let r = 0; r < s.length; r++) e(o.nodeAt(s[r]), l + s[r]);
326
- }
327
- isColSelection() {
328
- const e = this.$anchorCell.index(-1), o = this.$headCell.index(-1);
329
- if (Math.min(e, o) > 0) return !1;
330
- const n = e + this.$anchorCell.nodeAfter.attrs.rowspan, l = o + this.$headCell.nodeAfter.attrs.rowspan;
331
- return Math.max(n, l) == this.$headCell.node(-1).childCount;
332
- }
333
- static colSelection(e, o = e) {
334
- const n = e.node(-1), l = C.get(n), s = e.start(-1), r = l.findCell(e.pos - s), c = l.findCell(o.pos - s), i = e.node(0);
335
- return r.top <= c.top ? (r.top > 0 && (e = i.resolve(s + l.map[r.left])), c.bottom < l.height && (o = i.resolve(s + l.map[l.width * (l.height - 1) + c.right - 1]))) : (c.top > 0 && (o = i.resolve(s + l.map[c.left])), r.bottom < l.height && (e = i.resolve(s + l.map[l.width * (l.height - 1) + r.right - 1]))), new v(e, o);
336
- }
337
- isRowSelection() {
338
- const e = this.$anchorCell.node(-1), o = C.get(e), n = this.$anchorCell.start(-1), l = o.colCount(this.$anchorCell.pos - n), s = o.colCount(this.$headCell.pos - n);
339
- if (Math.min(l, s) > 0) return !1;
340
- const r = l + this.$anchorCell.nodeAfter.attrs.colspan, c = s + this.$headCell.nodeAfter.attrs.colspan;
341
- return Math.max(r, c) == o.width;
342
- }
343
- eq(e) {
344
- return e instanceof v && e.$anchorCell.pos == this.$anchorCell.pos && e.$headCell.pos == this.$headCell.pos;
345
- }
346
- static rowSelection(e, o = e) {
347
- const n = e.node(-1), l = C.get(n), s = e.start(-1), r = l.findCell(e.pos - s), c = l.findCell(o.pos - s), i = e.node(0);
348
- return r.left <= c.left ? (r.left > 0 && (e = i.resolve(s + l.map[r.top * l.width])), c.right < l.width && (o = i.resolve(s + l.map[l.width * (c.top + 1) - 1]))) : (c.left > 0 && (o = i.resolve(s + l.map[c.top * l.width])), r.right < l.width && (e = i.resolve(s + l.map[l.width * (r.top + 1) - 1]))), new v(e, o);
349
- }
350
- toJSON() {
351
- return {
352
- type: "cell",
353
- anchor: this.$anchorCell.pos,
354
- head: this.$headCell.pos
355
- };
356
- }
357
- static fromJSON(e, o) {
358
- return new v(e.resolve(o.anchor), e.resolve(o.head));
359
- }
360
- static create(e, o, n = o) {
361
- return new v(e.resolve(o), e.resolve(n));
362
- }
363
- getBookmark() {
364
- return new De(this.$anchorCell.pos, this.$headCell.pos);
365
- }
366
- };
367
- w.prototype.visible = !1;
368
- M.jsonID("cell", w);
369
- var De = class pe {
370
- constructor(e, o) {
371
- this.anchor = e, this.head = o;
372
- }
373
- map(e) {
374
- return new pe(e.map(this.anchor), e.map(this.head));
375
- }
376
- resolve(e) {
377
- const o = e.resolve(this.anchor), n = e.resolve(this.head);
378
- return o.parent.type.spec.tableRole == "row" && n.parent.type.spec.tableRole == "row" && o.index() < o.parent.childCount && n.index() < n.parent.childCount && ee(o, n) ? new w(o, n) : M.near(n, 1);
379
- }
380
- };
381
- function Be(t) {
382
- if (!(t.selection instanceof w)) return null;
383
- const e = [];
384
- return t.selection.forEachCell((o, n) => {
385
- e.push(q.node(n, n + o.nodeSize, { class: "selectedCell" }));
386
- }), X.create(t.doc, e);
387
- }
388
- function He({ $from: t, $to: e }) {
389
- if (t.pos == e.pos || t.pos < e.pos - 6) return !1;
390
- let o = t.pos, n = e.pos, l = t.depth;
391
- for (; l >= 0 && !(t.after(l + 1) < t.end(l)); l--, o++) ;
392
- for (let s = e.depth; s >= 0 && !(e.before(s + 1) > e.start(s)); s--, n--) ;
393
- return o == n && /row|table/.test(t.node(l).type.spec.tableRole);
394
- }
395
- function Le({ $from: t, $to: e }) {
396
- let o, n;
397
- for (let l = t.depth; l > 0; l--) {
398
- const s = t.node(l);
399
- if (s.type.spec.tableRole === "cell" || s.type.spec.tableRole === "header_cell") {
400
- o = s;
401
- break;
402
- }
403
- }
404
- for (let l = e.depth; l > 0; l--) {
405
- const s = e.node(l);
406
- if (s.type.spec.tableRole === "cell" || s.type.spec.tableRole === "header_cell") {
407
- n = s;
408
- break;
409
- }
410
- }
411
- return o !== n && e.parentOffset === 0;
412
- }
413
- function $e(t, e, o) {
414
- const n = (e || t).selection, l = (e || t).doc;
415
- let s, r;
416
- if (n instanceof Ae && (r = n.node.type.spec.tableRole)) {
417
- if (r == "cell" || r == "header_cell") s = w.create(l, n.from);
418
- else if (r == "row") {
419
- const c = l.resolve(n.from + 1);
420
- s = w.rowSelection(c, c);
421
- } else if (!o) {
422
- const c = C.get(n.node), i = n.from + 1, a = i + c.map[c.width * c.height - 1];
423
- s = w.create(l, i + 1, a);
424
- }
425
- } else n instanceof E && He(n) ? s = E.create(l, n.from) : n instanceof E && Le(n) && (s = E.create(l, n.$from.start(), n.$from.end()));
426
- return s && (e || (e = t.tr)).setSelection(s), e;
427
- }
428
- const Fe = new Z("fix-tables");
429
- function me(t, e, o, n) {
430
- const l = t.childCount, s = e.childCount;
431
- e: for (let r = 0, c = 0; r < s; r++) {
432
- const i = e.child(r);
433
- for (let a = c, d = Math.min(l, r + 3); a < d; a++) if (t.child(a) == i) {
434
- c = a + 1, o += i.nodeSize;
435
- continue e;
436
- }
437
- n(i, o), c < l && t.child(c).sameMarkup(i) ? me(t.child(c), i, o + 1, n) : i.nodesBetween(0, i.content.size, n, o + 1), o += i.nodeSize;
438
- }
439
- }
440
- function Pe(t, e) {
441
- let o;
442
- const n = (l, s) => {
443
- l.type.spec.tableRole == "table" && (o = We(t, l, s, o));
444
- };
445
- return e ? e.doc != t.doc && me(e.doc, t.doc, 0, n) : t.doc.descendants(n), o;
446
- }
447
- function We(t, e, o, n) {
448
- const l = C.get(e);
449
- if (!l.problems) return n;
450
- n || (n = t.tr);
451
- const s = [];
452
- for (let i = 0; i < l.height; i++) s.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++) s[a.row + u] += a.n;
460
- n.setNodeMarkup(n.mapping.map(o + 1 + a.pos), null, D(f, f.colspan - a.n, a.n));
461
- } else if (a.type == "missing") s[a.row] += a.n;
462
- else if (a.type == "overlong_rowspan") {
463
- const d = e.nodeAt(a.pos);
464
- if (!d) continue;
465
- n.setNodeMarkup(n.mapping.map(o + 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
- n.setNodeMarkup(n.mapping.map(o + 1 + a.pos), null, {
473
- ...d.attrs,
474
- colwidth: a.colwidth
475
- });
476
- } else if (a.type == "zero_sized") {
477
- const d = n.mapping.map(o);
478
- n.delete(d, d + e.nodeSize);
479
- }
480
- }
481
- let r, c;
482
- for (let i = 0; i < s.length; i++) s[i] && (r == null && (r = i), c = i);
483
- for (let i = 0, a = o + 1; i < l.height; i++) {
484
- const d = e.child(i), f = a + d.nodeSize, u = s[i];
485
- if (u > 0) {
486
- let h = "cell";
487
- d.firstChild && (h = d.firstChild.type.spec.tableRole);
488
- const p = [];
489
- for (let g = 0; g < u; g++) {
490
- const b = y(t.schema)[h].createAndFill();
491
- b && p.push(b);
492
- }
493
- const m = (i == 0 || r == i - 1) && c == i ? a + 1 : f - 1;
494
- n.insert(n.mapping.map(m), p);
495
- }
496
- a = f;
497
- }
498
- return n.setMeta(Fe, { fixTables: !0 });
499
- }
500
- function x(t) {
501
- const e = t.selection, o = O(t), n = o.node(-1), l = o.start(-1), s = C.get(n);
502
- return {
503
- ...e instanceof w ? s.rectBetween(e.$anchorCell.pos - l, e.$headCell.pos - l) : s.findCell(o.pos - l),
504
- tableStart: l,
505
- map: s,
506
- table: n
507
- };
508
- }
509
- function ge(t, { map: e, tableStart: o, table: n }, l) {
510
- let s = l > 0 ? -1 : 0;
511
- Te(e, n, l + s) && (s = l == 0 || l == e.width ? null : 0);
512
- for (let r = 0; r < e.height; r++) {
513
- const c = r * e.width + l;
514
- if (l > 0 && l < e.width && e.map[c - 1] == e.map[c]) {
515
- const i = e.map[c], a = n.nodeAt(i);
516
- t.setNodeMarkup(t.mapping.map(o + i), null, he(a.attrs, l - e.colCount(i))), r += a.attrs.rowspan - 1;
517
- } else {
518
- const i = s == null ? y(n.type.schema).cell : n.nodeAt(e.map[c + s]).type, a = e.positionAt(r, l, n);
519
- t.insert(t.mapping.map(o + a), i.createAndFill());
520
- }
521
- }
522
- return t;
523
- }
524
- function ut(t, e) {
525
- if (!A(t)) return !1;
526
- if (e) {
527
- const o = x(t);
528
- e(ge(t.tr, o, o.left));
529
- }
530
- return !0;
531
- }
532
- function ht(t, e) {
533
- if (!A(t)) return !1;
534
- if (e) {
535
- const o = x(t);
536
- e(ge(t.tr, o, o.right));
537
- }
538
- return !0;
539
- }
540
- function Ie(t, { map: e, table: o, tableStart: n }, l) {
541
- const s = t.mapping.maps.length;
542
- for (let r = 0; r < e.height; ) {
543
- const c = r * e.width + l, i = e.map[c], a = o.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(s).map(n + i), null, D(d, l - e.colCount(i)));
545
- else {
546
- const f = t.mapping.slice(s).map(n + i);
547
- t.delete(f, f + a.nodeSize);
548
- }
549
- r += d.rowspan;
550
- }
551
- }
552
- function pt(t, e) {
553
- if (!A(t)) return !1;
554
- if (e) {
555
- const o = x(t), n = t.tr;
556
- if (o.left == 0 && o.right == o.map.width) return !1;
557
- for (let l = o.right - 1; Ie(n, o, l), l != o.left; l--) {
558
- const s = o.tableStart ? n.doc.nodeAt(o.tableStart - 1) : n.doc;
559
- if (!s) throw new RangeError("No table found");
560
- o.table = s, o.map = C.get(s);
561
- }
562
- e(n);
563
- }
564
- return !0;
565
- }
566
- function je(t, e, o) {
567
- var n;
568
- const l = y(e.type.schema).header_cell;
569
- for (let s = 0; s < t.width; s++) if (((n = e.nodeAt(t.map[s + o * t.width])) === null || n === void 0 ? void 0 : n.type) != l) return !1;
570
- return !0;
571
- }
572
- function we(t, { map: e, tableStart: o, table: n }, l) {
573
- let s = o;
574
- for (let a = 0; a < l; a++) s += n.child(a).nodeSize;
575
- const r = [];
576
- let c = l > 0 ? -1 : 0;
577
- je(e, n, 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 = n.nodeAt(f).attrs;
580
- t.setNodeMarkup(o + f, null, {
581
- ...u,
582
- rowspan: u.rowspan + 1
583
- }), a += u.colspan - 1;
584
- } else {
585
- var i;
586
- const f = c == null ? y(n.type.schema).cell : (i = n.nodeAt(e.map[d + c * e.width])) === null || i === void 0 ? void 0 : i.type, u = f?.createAndFill();
587
- u && r.push(u);
588
- }
589
- return t.insert(s, y(n.type.schema).row.create(null, r)), t;
590
- }
591
- function mt(t, e) {
592
- if (!A(t)) return !1;
593
- if (e) {
594
- const o = x(t);
595
- e(we(t.tr, o, o.top));
596
- }
597
- return !0;
598
- }
599
- function gt(t, e) {
600
- if (!A(t)) return !1;
601
- if (e) {
602
- const o = x(t);
603
- e(we(t.tr, o, o.bottom));
604
- }
605
- return !0;
606
- }
607
- function Oe(t, { map: e, table: o, tableStart: n }, l) {
608
- let s = 0;
609
- for (let a = 0; a < l; a++) s += o.child(a).nodeSize;
610
- const r = s + o.child(l).nodeSize, c = t.mapping.maps.length;
611
- t.delete(s + n, r + n);
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 = o.nodeAt(f).attrs;
618
- t.setNodeMarkup(t.mapping.slice(c).map(f + n), 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 = o.nodeAt(f), h = u.attrs, p = u.type.create({
624
- ...h,
625
- rowspan: u.attrs.rowspan - 1
626
- }, u.content), m = e.positionAt(l + 1, a, o);
627
- t.insert(t.mapping.slice(c).map(n + m), p), a += h.colspan - 1;
628
- }
629
- }
630
- }
631
- }
632
- function wt(t, e) {
633
- if (!A(t)) return !1;
634
- if (e) {
635
- const o = x(t), n = t.tr;
636
- if (o.top == 0 && o.bottom == o.map.height) return !1;
637
- for (let l = o.bottom - 1; Oe(n, o, l), l != o.top; l--) {
638
- const s = o.tableStart ? n.doc.nodeAt(o.tableStart - 1) : n.doc;
639
- if (!s) throw new RangeError("No table found");
640
- o.table = s, o.map = C.get(o.table);
641
- }
642
- e(n);
643
- }
644
- return !0;
645
- }
646
- function oe(t) {
647
- const e = t.content;
648
- return e.childCount == 1 && e.child(0).isTextblock && e.child(0).childCount == 0;
649
- }
650
- function _e({ width: t, height: e, map: o }, n) {
651
- let l = n.top * t + n.left, s = l, r = (n.bottom - 1) * t + n.left, c = l + (n.right - n.left - 1);
652
- for (let i = n.top; i < n.bottom; i++) {
653
- if (n.left > 0 && o[s] == o[s - 1] || n.right < t && o[c] == o[c + 1]) return !0;
654
- s += t, c += t;
655
- }
656
- for (let i = n.left; i < n.right; i++) {
657
- if (n.top > 0 && o[l] == o[l - t] || n.bottom < e && o[r] == o[r + t]) return !0;
658
- l++, r++;
659
- }
660
- return !1;
661
- }
662
- function Ct(t, e) {
663
- const o = t.selection;
664
- if (!(o instanceof w) || o.$anchorCell.pos == o.$headCell.pos) return !1;
665
- const n = x(t), { map: l } = n;
666
- if (_e(l, n)) return !1;
667
- if (e) {
668
- const s = t.tr, r = {};
669
- let c = R.empty, i, a;
670
- for (let d = n.top; d < n.bottom; d++) for (let f = n.left; f < n.right; f++) {
671
- const u = l.map[d * l.width + f], h = n.table.nodeAt(u);
672
- if (!(r[u] || !h))
673
- if (r[u] = !0, i == null)
674
- i = u, a = h;
675
- else {
676
- oe(h) || (c = c.append(h.content));
677
- const p = s.mapping.map(u + n.tableStart);
678
- s.delete(p, p + h.nodeSize);
679
- }
680
- }
681
- if (i == null || a == null) return !0;
682
- if (s.setNodeMarkup(i + n.tableStart, null, {
683
- ...he(a.attrs, a.attrs.colspan, n.right - n.left - a.attrs.colspan),
684
- rowspan: n.bottom - n.top
685
- }), c.size > 0) {
686
- const d = i + 1 + a.content.size, f = oe(a) ? i + 1 : d;
687
- s.replaceWith(f + n.tableStart, d + n.tableStart, c);
688
- }
689
- s.setSelection(new w(s.doc.resolve(i + n.tableStart))), e(s);
690
- }
691
- return !0;
692
- }
693
- function bt(t, e) {
694
- const o = y(t.schema);
695
- return Ke(({ node: n }) => o[n.type.spec.tableRole])(t, e);
696
- }
697
- function Ke(t) {
698
- return (e, o) => {
699
- const n = e.selection;
700
- let l, s;
701
- if (n instanceof w) {
702
- if (n.$anchorCell.pos != n.$headCell.pos) return !1;
703
- l = n.$anchorCell.nodeAfter, s = n.$anchorCell.pos;
704
- } else {
705
- var r;
706
- if (l = ze(n.$from), !l) return !1;
707
- s = (r = T(n.$from)) === null || r === void 0 ? void 0 : r.pos;
708
- }
709
- if (l == null || s == null || l.attrs.colspan == 1 && l.attrs.rowspan == 1) return !1;
710
- if (o) {
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 = x(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 m = d.left, g = 0; m < d.right; m++, g++)
730
- m == d.left && h == d.top || f.insert(u = f.mapping.map(p + d.tableStart, 1), t({
731
- node: l,
732
- row: h,
733
- col: m
734
- }).createAndFill(i[g]));
735
- }
736
- f.setNodeMarkup(s, t({
737
- node: l,
738
- row: d.top,
739
- col: d.left
740
- }), i[0]), n instanceof w && f.setSelection(new w(f.doc.resolve(n.$anchorCell.pos), u ? f.doc.resolve(u) : void 0)), o(f);
741
- }
742
- return !0;
743
- };
744
- }
745
- function yt(t, e) {
746
- return function(o, n) {
747
- if (!A(o)) return !1;
748
- const l = O(o);
749
- if (l.nodeAfter.attrs[t] === e) return !1;
750
- if (n) {
751
- const s = o.tr;
752
- o.selection instanceof w ? o.selection.forEachCell((r, c) => {
753
- r.attrs[t] !== e && s.setNodeMarkup(c, null, {
754
- ...r.attrs,
755
- [t]: e
756
- });
757
- }) : s.setNodeMarkup(l.pos, null, {
758
- ...l.nodeAfter.attrs,
759
- [t]: e
760
- }), n(s);
761
- }
762
- return !0;
763
- };
764
- }
765
- function Ve(t) {
766
- return function(e, o) {
767
- if (!A(e)) return !1;
768
- if (o) {
769
- const n = y(e.schema), l = x(e), s = e.tr, r = 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 = r.map((i) => l.table.nodeAt(i));
780
- for (let i = 0; i < r.length; i++) c[i].type == n.header_cell && s.setNodeMarkup(l.tableStart + r[i], n.cell, c[i].attrs);
781
- if (s.steps.length === 0) for (let i = 0; i < r.length; i++) s.setNodeMarkup(l.tableStart + r[i], n.header_cell, c[i].attrs);
782
- o(s);
783
- }
784
- return !0;
785
- };
786
- }
787
- function ne(t, e, o) {
788
- const n = 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 < n.length; l++) {
795
- const s = e.table.nodeAt(n[l]);
796
- if (s && s.type !== o.header_cell) return !1;
797
- }
798
- return !0;
799
- }
800
- function te(t, e) {
801
- return e = e || { useDeprecatedLogic: !1 }, e.useDeprecatedLogic ? Ve(t) : function(o, n) {
802
- if (!A(o)) return !1;
803
- if (n) {
804
- const l = y(o.schema), s = x(o), r = o.tr, c = ne("row", s, l), i = ne("column", s, l), a = (t === "column" ? c : t === "row" && i) ? 1 : 0, d = t == "column" ? {
805
- left: 0,
806
- top: a,
807
- right: 1,
808
- bottom: s.map.height
809
- } : t == "row" ? {
810
- left: a,
811
- top: 0,
812
- right: s.map.width,
813
- bottom: 1
814
- } : s, f = t == "column" ? i ? l.cell : l.header_cell : t == "row" ? c ? l.cell : l.header_cell : l.cell;
815
- s.map.cellsInRect(d).forEach((u) => {
816
- const h = u + s.tableStart, p = r.doc.nodeAt(h);
817
- p && r.setNodeMarkup(h, f, p.attrs);
818
- }), n(r);
819
- }
820
- return !0;
821
- };
822
- }
823
- te("row", { useDeprecatedLogic: !0 });
824
- te("column", { useDeprecatedLogic: !0 });
825
- const St = te("cell", { useDeprecatedLogic: !0 });
826
- function Xe(t, e) {
827
- if (e < 0) {
828
- const o = t.nodeBefore;
829
- if (o) return t.pos - o.nodeSize;
830
- for (let n = t.index(-1) - 1, l = t.before(); n >= 0; n--) {
831
- const s = t.node(-1).child(n), r = s.lastChild;
832
- if (r) return l - 1 - r.nodeSize;
833
- l -= s.nodeSize;
834
- }
835
- } else {
836
- if (t.index() < t.parent.childCount - 1) return t.pos + t.nodeAfter.nodeSize;
837
- const o = t.node(-1);
838
- for (let n = t.indexAfter(-1), l = t.after(); n < o.childCount; n++) {
839
- const s = o.child(n);
840
- if (s.childCount) return l + 1;
841
- l += s.nodeSize;
842
- }
843
- }
844
- return null;
845
- }
846
- function At(t) {
847
- return function(e, o) {
848
- if (!A(e)) return !1;
849
- const n = Xe(O(e), t);
850
- if (n == null) return !1;
851
- if (o) {
852
- const l = e.doc.resolve(n);
853
- o(e.tr.setSelection(E.between(l, Ee(l))).scrollIntoView());
854
- }
855
- return !0;
856
- };
857
- }
858
- function Rt(t, e) {
859
- const o = t.selection.$anchor;
860
- for (let n = o.depth; n > 0; n--) if (o.node(n).type.spec.tableRole == "table")
861
- return e && e(t.tr.delete(o.before(n), o.after(n)).scrollIntoView()), !0;
862
- return !1;
863
- }
864
- function F(t, e) {
865
- const o = t.selection;
866
- if (!(o instanceof w)) return !1;
867
- if (e) {
868
- const n = t.tr, l = y(t.schema).cell.createAndFill().content;
869
- o.forEachCell((s, r) => {
870
- s.content.eq(l) || n.replace(n.mapping.map(r + 1), n.mapping.map(r + s.nodeSize - 1), new z(l, 0, 0));
871
- }), n.docChanged && e(n);
872
- }
873
- return !0;
874
- }
875
- function qe(t) {
876
- if (t.size === 0) return null;
877
- let { content: e, openStart: o, openEnd: n } = t;
878
- for (; e.childCount == 1 && (o > 0 && n > 0 || e.child(0).type.spec.tableRole == "table"); )
879
- o--, n--, e = e.child(0).content;
880
- const l = e.child(0), s = l.type.spec.tableRole, r = l.type.schema, c = [];
881
- if (s == "row") for (let i = 0; i < e.childCount; i++) {
882
- let a = e.child(i).content;
883
- const d = i ? 0 : Math.max(0, o - 1), f = i < e.childCount - 1 ? 0 : Math.max(0, n - 1);
884
- (d || f) && (a = G(y(r).row, new z(a, d, f)).content), c.push(a);
885
- }
886
- else if (s == "cell" || s == "header_cell") c.push(o || n ? G(y(r).row, new z(e, o, n)).content : e);
887
- else return null;
888
- return Ue(r, c);
889
- }
890
- function Ue(t, e) {
891
- const o = [];
892
- for (let l = 0; l < e.length; l++) {
893
- const s = e[l];
894
- for (let r = s.childCount - 1; r >= 0; r--) {
895
- const { rowspan: c, colspan: i } = s.child(r).attrs;
896
- for (let a = l; a < l + c; a++) o[a] = (o[a] || 0) + i;
897
- }
898
- }
899
- let n = 0;
900
- for (let l = 0; l < o.length; l++) n = Math.max(n, o[l]);
901
- for (let l = 0; l < o.length; l++)
902
- if (l >= e.length && e.push(R.empty), o[l] < n) {
903
- const s = y(t).cell.createAndFill(), r = [];
904
- for (let c = o[l]; c < n; c++) r.push(s);
905
- e[l] = e[l].append(R.from(r));
906
- }
907
- return {
908
- height: e.length,
909
- width: n,
910
- rows: e
911
- };
912
- }
913
- function G(t, e) {
914
- const o = t.createAndFill();
915
- return new Re(o).replace(0, o.content.size, e).doc;
916
- }
917
- function Je({ width: t, height: e, rows: o }, n, l) {
918
- if (t != n) {
919
- const s = [], r = [];
920
- for (let c = 0; c < o.length; c++) {
921
- const i = o[c], a = [];
922
- for (let d = s[c] || 0, f = 0; d < n; f++) {
923
- let u = i.child(f % i.childCount);
924
- d + u.attrs.colspan > n && (u = u.type.createChecked(D(u.attrs, u.attrs.colspan, d + u.attrs.colspan - n), u.content)), a.push(u), d += u.attrs.colspan;
925
- for (let h = 1; h < u.attrs.rowspan; h++) s[c + h] = (s[c + h] || 0) + u.attrs.colspan;
926
- }
927
- r.push(R.from(a));
928
- }
929
- o = r, t = n;
930
- }
931
- if (e != l) {
932
- const s = [];
933
- for (let r = 0, c = 0; r < l; r++, c++) {
934
- const i = [], a = o[c % e];
935
- for (let d = 0; d < a.childCount; d++) {
936
- let f = a.child(d);
937
- r + 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
- s.push(R.from(i));
943
- }
944
- o = s, e = l;
945
- }
946
- return {
947
- width: t,
948
- height: e,
949
- rows: o
950
- };
951
- }
952
- function Ye(t, e, o, n, l, s, r) {
953
- const c = t.doc.type.schema, i = y(c);
954
- let a, d;
955
- if (l > e.width) for (let f = 0, u = 0; f < e.height; f++) {
956
- const h = o.child(f);
957
- u += h.nodeSize;
958
- const p = [];
959
- let m;
960
- h.lastChild == null || h.lastChild.type == i.cell ? m = a || (a = i.cell.createAndFill()) : m = d || (d = i.header_cell.createAndFill());
961
- for (let g = e.width; g < l; g++) p.push(m);
962
- t.insert(t.mapping.slice(r).map(u - 1 + n), p);
963
- }
964
- if (s > e.height) {
965
- const f = [];
966
- for (let p = 0, m = (e.height - 1) * e.width; p < Math.max(e.width, l); p++) {
967
- const g = p >= e.width ? !1 : o.nodeAt(e.map[m + p]).type == i.header_cell;
968
- f.push(g ? d || (d = i.header_cell.createAndFill()) : a || (a = i.cell.createAndFill()));
969
- }
970
- const u = i.row.create(null, R.from(f)), h = [];
971
- for (let p = e.height; p < s; p++) h.push(u);
972
- t.insert(t.mapping.slice(r).map(n + o.nodeSize - 2), h);
973
- }
974
- return !!(a || d);
975
- }
976
- function le(t, e, o, n, l, s, r, c) {
977
- if (r == 0 || r == e.height) return !1;
978
- let i = !1;
979
- for (let a = l; a < s; a++) {
980
- const d = r * e.width + a, f = e.map[d];
981
- if (e.map[d - e.width] == f) {
982
- i = !0;
983
- const u = o.nodeAt(f), { top: h, left: p } = e.findCell(f);
984
- t.setNodeMarkup(t.mapping.slice(c).map(f + n), null, {
985
- ...u.attrs,
986
- rowspan: r - h
987
- }), t.insert(t.mapping.slice(c).map(e.positionAt(r, p, o)), u.type.createAndFill({
988
- ...u.attrs,
989
- rowspan: h + u.attrs.rowspan - r
990
- })), a += u.attrs.colspan - 1;
991
- }
992
- }
993
- return i;
994
- }
995
- function se(t, e, o, n, l, s, r, c) {
996
- if (r == 0 || r == e.width) return !1;
997
- let i = !1;
998
- for (let a = l; a < s; a++) {
999
- const d = a * e.width + r, f = e.map[d];
1000
- if (e.map[d - 1] == f) {
1001
- i = !0;
1002
- const u = o.nodeAt(f), h = e.colCount(f), p = t.mapping.slice(c).map(f + n);
1003
- t.setNodeMarkup(p, null, D(u.attrs, r - h, u.attrs.colspan - (r - h))), t.insert(p + u.nodeSize, u.type.createAndFill(D(u.attrs, 0, r - h))), a += u.attrs.rowspan - 1;
1004
- }
1005
- }
1006
- return i;
1007
- }
1008
- function re(t, e, o, n, l) {
1009
- let s = o ? t.doc.nodeAt(o - 1) : t.doc;
1010
- if (!s) throw new Error("No table found");
1011
- let r = C.get(s);
1012
- const { top: c, left: i } = n, a = i + l.width, d = c + l.height, f = t.tr;
1013
- let u = 0;
1014
- function h() {
1015
- if (s = o ? f.doc.nodeAt(o - 1) : f.doc, !s) throw new Error("No table found");
1016
- r = C.get(s), u = f.mapping.maps.length;
1017
- }
1018
- Ye(f, r, s, o, a, d, u) && h(), le(f, r, s, o, i, a, c, u) && h(), le(f, r, s, o, i, a, d, u) && h(), se(f, r, s, o, c, d, i, u) && h(), se(f, r, s, o, c, d, a, u) && h();
1019
- for (let p = c; p < d; p++) {
1020
- const m = r.positionAt(p, i, s), g = r.positionAt(p, a, s);
1021
- f.replace(f.mapping.slice(u).map(m + o), f.mapping.slice(u).map(g + o), new z(l.rows[p - c], 0, 0));
1022
- }
1023
- h(), f.setSelection(new w(f.doc.resolve(o + r.positionAt(c, i, s)), f.doc.resolve(o + r.positionAt(d - 1, a - 1, s)))), e(f);
1024
- }
1025
- const Ge = ye({
1026
- ArrowLeft: P("horiz", -1),
1027
- ArrowRight: P("horiz", 1),
1028
- ArrowUp: P("vert", -1),
1029
- ArrowDown: P("vert", 1),
1030
- "Shift-ArrowLeft": W("horiz", -1),
1031
- "Shift-ArrowRight": W("horiz", 1),
1032
- "Shift-ArrowUp": W("vert", -1),
1033
- "Shift-ArrowDown": W("vert", 1),
1034
- Backspace: F,
1035
- "Mod-Backspace": F,
1036
- Delete: F,
1037
- "Mod-Delete": F
1038
- });
1039
- function I(t, e, o) {
1040
- return o.eq(t.selection) ? !1 : (e && e(t.tr.setSelection(o).scrollIntoView()), !0);
1041
- }
1042
- function P(t, e) {
1043
- return (o, n, l) => {
1044
- if (!l) return !1;
1045
- const s = o.selection;
1046
- if (s instanceof w) return I(o, n, M.near(s.$headCell, e));
1047
- if (t != "horiz" && !s.empty) return !1;
1048
- const r = Ce(l, t, e);
1049
- if (r == null) return !1;
1050
- if (t == "horiz") return I(o, n, M.near(o.doc.resolve(s.head + e), e));
1051
- {
1052
- const c = o.doc.resolve(r), i = ue(c, t, e);
1053
- let a;
1054
- return i ? a = M.near(i, 1) : e < 0 ? a = M.near(o.doc.resolve(c.before(-1)), -1) : a = M.near(o.doc.resolve(c.after(-1)), 1), I(o, n, a);
1055
- }
1056
- };
1057
- }
1058
- function W(t, e) {
1059
- return (o, n, l) => {
1060
- if (!l) return !1;
1061
- const s = o.selection;
1062
- let r;
1063
- if (s instanceof w) r = s;
1064
- else {
1065
- const i = Ce(l, t, e);
1066
- if (i == null) return !1;
1067
- r = new w(o.doc.resolve(i));
1068
- }
1069
- const c = ue(r.$headCell, t, e);
1070
- return c ? I(o, n, new w(r.$anchorCell, c)) : !1;
1071
- };
1072
- }
1073
- function Qe(t, e) {
1074
- const o = t.state.doc, n = T(o.resolve(e));
1075
- return n ? (t.dispatch(t.state.tr.setSelection(new w(n))), !0) : !1;
1076
- }
1077
- function Ze(t, e, o) {
1078
- if (!A(t.state)) return !1;
1079
- let n = qe(o);
1080
- const l = t.state.selection;
1081
- if (l instanceof w) {
1082
- n || (n = {
1083
- width: 1,
1084
- height: 1,
1085
- rows: [R.from(G(y(t.state.schema).cell, o))]
1086
- });
1087
- const s = l.$anchorCell.node(-1), r = l.$anchorCell.start(-1), c = C.get(s).rectBetween(l.$anchorCell.pos - r, l.$headCell.pos - r);
1088
- return n = Je(n, c.right - c.left, c.bottom - c.top), re(t.state, t.dispatch, r, c, n), !0;
1089
- } else if (n) {
1090
- const s = O(t.state), r = s.start(-1);
1091
- return re(t.state, t.dispatch, r, C.get(s.node(-1)).findCell(s.pos - r), n), !0;
1092
- } else return !1;
1093
- }
1094
- function et(t, e) {
1095
- var o;
1096
- if (e.button != 0 || e.ctrlKey || e.metaKey) return;
1097
- const n = ie(t, e.target);
1098
- let l;
1099
- if (e.shiftKey && t.state.selection instanceof w)
1100
- s(t.state.selection.$anchorCell, e), e.preventDefault();
1101
- else if (e.shiftKey && n && (l = T(t.state.selection.$anchor)) != null && ((o = V(t, e)) === null || o === void 0 ? void 0 : o.pos) != l.pos)
1102
- s(l, e), e.preventDefault();
1103
- else if (!n) return;
1104
- function s(i, a) {
1105
- let d = V(t, a);
1106
- const f = N.getState(t.state) == null;
1107
- if (!d || !ee(i, d)) if (f) d = i;
1108
- else return;
1109
- const u = new w(i, d);
1110
- if (f || !t.state.selection.eq(u)) {
1111
- const h = t.state.tr.setSelection(u);
1112
- f && h.setMeta(N, i.pos), t.dispatch(h);
1113
- }
1114
- }
1115
- function r() {
1116
- t.root.removeEventListener("mouseup", r), t.root.removeEventListener("dragstart", r), t.root.removeEventListener("mousemove", c), N.getState(t.state) != null && t.dispatch(t.state.tr.setMeta(N, -1));
1117
- }
1118
- function c(i) {
1119
- const a = i, d = N.getState(t.state);
1120
- let f;
1121
- if (d != null) f = t.state.doc.resolve(d);
1122
- else if (ie(t, a.target) != n && (f = V(t, e), !f))
1123
- return r();
1124
- f && s(f, a);
1125
- }
1126
- t.root.addEventListener("mouseup", r), t.root.addEventListener("dragstart", r), t.root.addEventListener("mousemove", c);
1127
- }
1128
- function Ce(t, e, o) {
1129
- if (!(t.state.selection instanceof E)) return null;
1130
- const { $head: n } = t.state.selection;
1131
- for (let l = n.depth - 1; l >= 0; l--) {
1132
- const s = n.node(l);
1133
- if ((o < 0 ? n.index(l) : n.indexAfter(l)) != (o < 0 ? 0 : s.childCount)) return null;
1134
- if (s.type.spec.tableRole == "cell" || s.type.spec.tableRole == "header_cell") {
1135
- const r = n.before(l), c = e == "vert" ? o > 0 ? "down" : "up" : o > 0 ? "right" : "left";
1136
- return t.endOfTextblock(c) ? r : null;
1137
- }
1138
- }
1139
- return null;
1140
- }
1141
- function ie(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 V(t, e) {
1146
- const o = t.posAtCoords({
1147
- left: e.clientX,
1148
- top: e.clientY
1149
- });
1150
- if (!o) return null;
1151
- let { inside: n, pos: l } = o;
1152
- return n >= 0 && T(t.state.doc.resolve(n)) || T(t.state.doc.resolve(l));
1153
- }
1154
- var tt = class {
1155
- constructor(t, e) {
1156
- this.node = t, this.defaultCellMinWidth = e, 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", `${e}px`), this.colgroup = this.table.appendChild(document.createElement("colgroup")), Q(t, this.colgroup, this.table, e), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1157
- }
1158
- update(t) {
1159
- return t.type != this.node.type ? !1 : (this.node = t, Q(t, this.colgroup, this.table, this.defaultCellMinWidth), !0);
1160
- }
1161
- ignoreMutation(t) {
1162
- return t.type == "attributes" && (t.target == this.table || this.colgroup.contains(t.target));
1163
- }
1164
- };
1165
- function Q(t, e, o, n, l, s) {
1166
- let r = 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 m = 0; m < h; m++, u++) {
1172
- const g = l == u ? s : p && p[m], b = g ? g + "px" : "";
1173
- if (r += g || n, g || (c = !1), i)
1174
- i.style.width != b && (i.style.width = b), i = i.nextSibling;
1175
- else {
1176
- const B = document.createElement("col");
1177
- B.style.width = b, e.appendChild(B);
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 ? (o.style.width = r + "px", o.style.minWidth = "") : (o.style.width = "", o.style.minWidth = r + "px");
1187
- }
1188
- }
1189
- const S = new Z("tableColumnResizing");
1190
- function xt({ handleWidth: t = 5, cellMinWidth: e = 25, defaultCellMinWidth: o = 100, View: n = tt, lastColumnResizable: l = !0 } = {}) {
1191
- const s = new fe({
1192
- key: S,
1193
- state: {
1194
- init(r, c) {
1195
- var i;
1196
- const a = (i = s.spec) === null || i === void 0 || (i = i.props) === null || i === void 0 ? void 0 : i.nodeViews, d = y(c.schema).table.name;
1197
- return n && a && (a[d] = (f, u) => new n(f, o, u)), new ot(-1, !1);
1198
- },
1199
- apply(r, c) {
1200
- return c.apply(r);
1201
- }
1202
- },
1203
- props: {
1204
- attributes: (r) => {
1205
- const c = S.getState(r);
1206
- return c && c.activeHandle > -1 ? { class: "resize-cursor" } : {};
1207
- },
1208
- handleDOMEvents: {
1209
- mousemove: (r, c) => {
1210
- nt(r, c, t, l);
1211
- },
1212
- mouseleave: (r) => {
1213
- lt(r);
1214
- },
1215
- mousedown: (r, c) => {
1216
- st(r, c, e, o);
1217
- }
1218
- },
1219
- decorations: (r) => {
1220
- const c = S.getState(r);
1221
- if (c && c.activeHandle > -1) return dt(r, c.activeHandle);
1222
- },
1223
- nodeViews: {}
1224
- }
1225
- });
1226
- return s;
1227
- }
1228
- var ot = class j {
1229
- constructor(e, o) {
1230
- this.activeHandle = e, this.dragging = o;
1231
- }
1232
- apply(e) {
1233
- const o = this, n = e.getMeta(S);
1234
- if (n && n.setHandle != null) return new j(n.setHandle, !1);
1235
- if (n && n.setDragging !== void 0) return new j(o.activeHandle, n.setDragging);
1236
- if (o.activeHandle > -1 && e.docChanged) {
1237
- let l = e.mapping.map(o.activeHandle, -1);
1238
- return Y(e.doc.resolve(l)) || (l = -1), new j(l, o.dragging);
1239
- }
1240
- return o;
1241
- }
1242
- };
1243
- function nt(t, e, o, n) {
1244
- if (!t.editable) return;
1245
- const l = S.getState(t.state);
1246
- if (l && !l.dragging) {
1247
- const s = it(e.target);
1248
- let r = -1;
1249
- if (s) {
1250
- const { left: c, right: i } = s.getBoundingClientRect();
1251
- e.clientX - c <= o ? r = ce(t, e, "left", o) : i - e.clientX <= o && (r = ce(t, e, "right", o));
1252
- }
1253
- if (r != l.activeHandle) {
1254
- if (!n && r !== -1) {
1255
- const c = t.state.doc.resolve(r), 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
- be(t, r);
1259
- }
1260
- }
1261
- }
1262
- function lt(t) {
1263
- if (!t.editable) return;
1264
- const e = S.getState(t.state);
1265
- e && e.activeHandle > -1 && !e.dragging && be(t, -1);
1266
- }
1267
- function st(t, e, o, n) {
1268
- var l;
1269
- if (!t.editable) return !1;
1270
- const s = (l = t.dom.ownerDocument.defaultView) !== null && l !== void 0 ? l : window, r = S.getState(t.state);
1271
- if (!r || r.activeHandle == -1 || r.dragging) return !1;
1272
- const c = t.state.doc.nodeAt(r.activeHandle), i = rt(t, r.activeHandle, c.attrs);
1273
- t.dispatch(t.state.tr.setMeta(S, { setDragging: {
1274
- startX: e.clientX,
1275
- startWidth: i
1276
- } }));
1277
- function a(f) {
1278
- s.removeEventListener("mouseup", a), s.removeEventListener("mousemove", d);
1279
- const u = S.getState(t.state);
1280
- u?.dragging && (ct(t, u.activeHandle, ae(u.dragging, f, o)), t.dispatch(t.state.tr.setMeta(S, { setDragging: null })));
1281
- }
1282
- function d(f) {
1283
- if (!f.which) return a(f);
1284
- const u = S.getState(t.state);
1285
- if (u && u.dragging) {
1286
- const h = ae(u.dragging, f, o);
1287
- de(t, u.activeHandle, h, n);
1288
- }
1289
- }
1290
- return de(t, r.activeHandle, i, n), s.addEventListener("mouseup", a), s.addEventListener("mousemove", d), e.preventDefault(), !0;
1291
- }
1292
- function rt(t, e, { colspan: o, colwidth: n }) {
1293
- const l = n && n[n.length - 1];
1294
- if (l) return l;
1295
- const s = t.domAtPos(e);
1296
- let r = s.node.childNodes[s.offset].offsetWidth, c = o;
1297
- if (n)
1298
- for (let i = 0; i < o; i++) n[i] && (r -= n[i], c--);
1299
- return r / c;
1300
- }
1301
- function it(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 ce(t, e, o, n) {
1306
- const l = o == "right" ? -n : n, s = t.posAtCoords({
1307
- left: e.clientX + l,
1308
- top: e.clientY
1309
- });
1310
- if (!s) return -1;
1311
- const { pos: r } = s, c = T(t.state.doc.resolve(r));
1312
- if (!c) return -1;
1313
- if (o == "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 ae(t, e, o) {
1318
- const n = e.clientX - t.startX;
1319
- return Math.max(o, t.startWidth + n);
1320
- }
1321
- function be(t, e) {
1322
- t.dispatch(t.state.tr.setMeta(S, { setHandle: e }));
1323
- }
1324
- function ct(t, e, o) {
1325
- const n = t.state.doc.resolve(e), l = n.node(-1), s = C.get(l), r = n.start(-1), c = s.colCount(n.pos - r) + n.nodeAfter.attrs.colspan - 1, i = t.state.tr;
1326
- for (let a = 0; a < s.height; a++) {
1327
- const d = a * s.width + c;
1328
- if (a && s.map[d] == s.map[d - s.width]) continue;
1329
- const f = s.map[d], u = l.nodeAt(f).attrs, h = u.colspan == 1 ? 0 : c - s.colCount(f);
1330
- if (u.colwidth && u.colwidth[h] == o) continue;
1331
- const p = u.colwidth ? u.colwidth.slice() : at(u.colspan);
1332
- p[h] = o, i.setNodeMarkup(r + f, null, {
1333
- ...u,
1334
- colwidth: p
1335
- });
1336
- }
1337
- i.docChanged && t.dispatch(i);
1338
- }
1339
- function de(t, e, o, n) {
1340
- const l = t.state.doc.resolve(e), s = l.node(-1), r = l.start(-1), c = C.get(s).colCount(l.pos - r) + 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 && Q(s, i.firstChild, i, n, c, o);
1344
- }
1345
- function at(t) {
1346
- return Array(t).fill(0);
1347
- }
1348
- function dt(t, e) {
1349
- const o = [], n = t.doc.resolve(e), l = n.node(-1);
1350
- if (!l) return X.empty;
1351
- const s = C.get(l), r = n.start(-1), c = s.colCount(n.pos - r) + n.nodeAfter.attrs.colspan - 1;
1352
- for (let a = 0; a < s.height; a++) {
1353
- const d = c + a * s.width;
1354
- if ((c == s.width - 1 || s.map[d] != s.map[d + 1]) && (a == 0 || s.map[d] != s.map[d - s.width])) {
1355
- var i;
1356
- const f = s.map[d], u = r + f + l.nodeAt(f).nodeSize - 1, h = document.createElement("div");
1357
- h.className = "column-resize-handle", !((i = S.getState(t)) === null || i === void 0) && i.dragging && o.push(q.node(r + f, r + f + l.nodeAt(f).nodeSize, { class: "column-resize-dragging" })), o.push(q.widget(u, h));
1358
- }
1359
- }
1360
- return X.create(t.doc, o);
1361
- }
1362
- function vt({ allowTableNodeSelection: t = !1 } = {}) {
1363
- return new fe({
1364
- key: N,
1365
- state: {
1366
- init() {
1367
- return null;
1368
- },
1369
- apply(e, o) {
1370
- const n = e.getMeta(N);
1371
- if (n != null) return n == -1 ? null : n;
1372
- if (o == null || !e.docChanged) return o;
1373
- const { deleted: l, pos: s } = e.mapping.mapResult(o);
1374
- return l ? null : s;
1375
- }
1376
- },
1377
- props: {
1378
- decorations: Be,
1379
- handleDOMEvents: { mousedown: et },
1380
- createSelectionBetween(e) {
1381
- return N.getState(e.state) != null ? e.state.selection : null;
1382
- },
1383
- handleTripleClick: Qe,
1384
- handleKeyDown: Ge,
1385
- handlePaste: Ze
1386
- },
1387
- appendTransaction(e, o, n) {
1388
- return $e(n, Pe(n, o), t);
1389
- }
1390
- });
1391
- }
1392
- export {
1393
- w as C,
1394
- bt as a,
1395
- St as b,
1396
- xt as c,
1397
- te as d,
1398
- Rt as e,
1399
- Pe as f,
1400
- At as g,
1401
- wt as h,
1402
- gt as i,
1403
- mt as j,
1404
- pt as k,
1405
- ht as l,
1406
- Ct as m,
1407
- ut as n,
1408
- yt as s,
1409
- vt as t
1410
- };