@clevertask/scribe 0.0.7 → 0.0.9

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.
@@ -1,3884 +1,59 @@
1
- import dt from "./extension-link.js";
2
- import { E as X, P as _, a as W, D as K, b as G, N as T, n as qe, m as M, S as v, k as Xe, j as ut, T as x, F as H, l as $, o as pe, p as pt, q as Ge, r as Je, s as ht, w as J, M as te, c as j, t as Q, u as we, v as ft, x as mt, y as gt, z as bt, A } from "../../../index-o3ZWOEgq.js";
3
- import { SlashCommand as wt } from "./slashCommand/index.js";
4
- import yt from "./extension-selectedText.js";
5
- import Ct from "./slashCommand/renderItems.js";
6
- import { getSuggestionItems as Mt } from "./slashCommand/items.js";
7
- import { LatexExtension as At } from "./math-extension.js";
8
- const kt = X.create({
9
- name: "focus",
10
- addOptions() {
11
- return {
12
- className: "has-focus",
13
- mode: "all"
14
- };
15
- },
16
- addProseMirrorPlugins() {
17
- return [
18
- new _({
19
- key: new W("focus"),
20
- props: {
21
- decorations: ({ doc: e, selection: t }) => {
22
- const { isEditable: n, isFocused: o } = this.editor, { anchor: s } = t, r = [];
23
- if (!n || !o)
24
- return K.create(e, []);
25
- let i = 0;
26
- this.options.mode === "deepest" && e.descendants((a, c) => {
27
- if (a.isText)
28
- return;
29
- if (!(s >= c && s <= c + a.nodeSize - 1))
30
- return !1;
31
- i += 1;
32
- });
33
- let l = 0;
34
- return e.descendants((a, c) => {
35
- if (a.isText || !(s >= c && s <= c + a.nodeSize - 1))
36
- return !1;
37
- if (l += 1, this.options.mode === "deepest" && i - l > 0 || this.options.mode === "shallowest" && l > 1)
38
- return this.options.mode === "deepest";
39
- r.push(G.node(c, c + a.nodeSize, {
40
- class: this.options.className
41
- }));
42
- }), K.create(e, r);
43
- }
44
- }
45
- })
46
- ];
47
- }
48
- }), Tt = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, St = T.create({
49
- name: "image",
50
- addOptions() {
51
- return {
52
- inline: !1,
53
- allowBase64: !1,
54
- HTMLAttributes: {}
55
- };
56
- },
57
- inline() {
58
- return this.options.inline;
59
- },
60
- group() {
61
- return this.options.inline ? "inline" : "block";
62
- },
63
- draggable: !0,
64
- addAttributes() {
65
- return {
66
- src: {
67
- default: null
68
- },
69
- alt: {
70
- default: null
71
- },
72
- title: {
73
- default: null
74
- }
75
- };
76
- },
77
- parseHTML() {
78
- return [
79
- {
80
- tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
81
- }
82
- ];
83
- },
84
- renderHTML({ HTMLAttributes: e }) {
85
- return ["img", M(this.options.HTMLAttributes, e)];
86
- },
87
- addCommands() {
88
- return {
89
- setImage: (e) => ({ commands: t }) => t.insertContent({
90
- type: this.name,
91
- attrs: e
92
- })
93
- };
94
- },
95
- addInputRules() {
96
- return [
97
- qe({
98
- find: Tt,
99
- type: this.type,
100
- getAttributes: (e) => {
101
- const [, , t, n, o] = e;
102
- return { src: n, alt: t, title: o };
103
- }
104
- })
105
- ];
106
- }
107
- });
108
- var ye, Ce;
109
- if (typeof WeakMap < "u") {
110
- let e = /* @__PURE__ */ new WeakMap();
111
- ye = (t) => e.get(t), Ce = (t, n) => (e.set(t, n), n);
112
- } else {
113
- const e = [];
114
- let n = 0;
115
- ye = (o) => {
116
- for (let s = 0; s < e.length; s += 2)
117
- if (e[s] == o) return e[s + 1];
118
- }, Ce = (o, s) => (n == 10 && (n = 0), e[n++] = o, e[n++] = s);
119
- }
120
- var C = class {
121
- constructor(e, t, n, o) {
122
- this.width = e, this.height = t, this.map = n, this.problems = o;
123
- }
124
- // Find the dimensions of the cell at the given position.
125
- findCell(e) {
126
- for (let t = 0; t < this.map.length; t++) {
127
- const n = this.map[t];
128
- if (n != e) continue;
129
- const o = t % this.width, s = t / this.width | 0;
130
- let r = o + 1, i = s + 1;
131
- for (let l = 1; r < this.width && this.map[t + l] == n; l++)
132
- r++;
133
- for (let l = 1; i < this.height && this.map[t + this.width * l] == n; l++)
134
- i++;
135
- return { left: o, top: s, right: r, bottom: i };
136
- }
137
- throw new RangeError(`No cell with offset ${e} found`);
138
- }
139
- // Find the left side of the cell at the given position.
140
- colCount(e) {
141
- for (let t = 0; t < this.map.length; t++)
142
- if (this.map[t] == e)
143
- return t % this.width;
144
- throw new RangeError(`No cell with offset ${e} found`);
145
- }
146
- // Find the next cell in the given direction, starting from the cell
147
- // at `pos`, if any.
148
- nextCell(e, t, n) {
149
- const { left: o, right: s, top: r, bottom: i } = this.findCell(e);
150
- return t == "horiz" ? (n < 0 ? o == 0 : s == this.width) ? null : this.map[r * this.width + (n < 0 ? o - 1 : s)] : (n < 0 ? r == 0 : i == this.height) ? null : this.map[o + this.width * (n < 0 ? r - 1 : i)];
151
- }
152
- // Get the rectangle spanning the two given cells.
153
- rectBetween(e, t) {
154
- const {
155
- left: n,
156
- right: o,
157
- top: s,
158
- bottom: r
159
- } = this.findCell(e), {
160
- left: i,
161
- right: l,
162
- top: a,
163
- bottom: c
164
- } = this.findCell(t);
165
- return {
166
- left: Math.min(n, i),
167
- top: Math.min(s, a),
168
- right: Math.max(o, l),
169
- bottom: Math.max(r, c)
170
- };
171
- }
172
- // Return the position of all cells that have the top left corner in
173
- // the given rectangle.
174
- cellsInRect(e) {
175
- const t = [], n = {};
176
- for (let o = e.top; o < e.bottom; o++)
177
- for (let s = e.left; s < e.right; s++) {
178
- const r = o * this.width + s, i = this.map[r];
179
- n[i] || (n[i] = !0, !(s == e.left && s && this.map[r - 1] == i || o == e.top && o && this.map[r - this.width] == i) && t.push(i));
180
- }
181
- return t;
182
- }
183
- // Return the position at which the cell at the given row and column
184
- // starts, or would start, if a cell started there.
185
- positionAt(e, t, n) {
186
- for (let o = 0, s = 0; ; o++) {
187
- const r = s + n.child(o).nodeSize;
188
- if (o == e) {
189
- let i = t + e * this.width;
190
- const l = (e + 1) * this.width;
191
- for (; i < l && this.map[i] < s; ) i++;
192
- return i == l ? r - 1 : this.map[i];
193
- }
194
- s = r;
195
- }
196
- }
197
- // Find the table map for the given table node.
198
- static get(e) {
199
- return ye(e) || Ce(e, vt(e));
200
- }
201
- };
202
- function vt(e) {
203
- if (e.type.spec.tableRole != "table")
204
- throw new RangeError("Not a table node: " + e.type.name);
205
- const t = xt(e), n = e.childCount, o = [];
206
- let s = 0, r = null;
207
- const i = [];
208
- for (let c = 0, u = t * n; c < u; c++) o[c] = 0;
209
- for (let c = 0, u = 0; c < n; c++) {
210
- const d = e.child(c);
211
- u++;
212
- for (let f = 0; ; f++) {
213
- for (; s < o.length && o[s] != 0; ) s++;
214
- if (f == d.childCount) break;
215
- const m = d.child(f), { colspan: g, rowspan: w, colwidth: R } = m.attrs;
216
- for (let z = 0; z < w; z++) {
217
- if (z + c >= n) {
218
- (r || (r = [])).push({
219
- type: "overlong_rowspan",
220
- pos: u,
221
- n: w - z
222
- });
223
- break;
224
- }
225
- const U = s + z * t;
226
- for (let V = 0; V < g; V++) {
227
- o[U + V] == 0 ? o[U + V] = u : (r || (r = [])).push({
228
- type: "collision",
229
- row: c,
230
- pos: u,
231
- n: g - V
232
- });
233
- const ne = R && R[V];
234
- if (ne) {
235
- const Z = (U + V) % t * 2, fe = i[Z];
236
- fe == null || fe != ne && i[Z + 1] == 1 ? (i[Z] = ne, i[Z + 1] = 1) : fe == ne && i[Z + 1]++;
237
- }
238
- }
239
- }
240
- s += g, u += m.nodeSize;
241
- }
242
- const p = (c + 1) * t;
243
- let h = 0;
244
- for (; s < p; ) o[s++] == 0 && h++;
245
- h && (r || (r = [])).push({ type: "missing", row: c, n: h }), u++;
246
- }
247
- (t === 0 || n === 0) && (r || (r = [])).push({ type: "zero_sized" });
248
- const l = new C(t, n, o, r);
249
- let a = !1;
250
- for (let c = 0; !a && c < i.length; c += 2)
251
- i[c] != null && i[c + 1] < n && (a = !0);
252
- return a && Lt(l, i, e), l;
253
- }
254
- function xt(e) {
255
- let t = -1, n = !1;
256
- for (let o = 0; o < e.childCount; o++) {
257
- const s = e.child(o);
258
- let r = 0;
259
- if (n)
260
- for (let i = 0; i < o; i++) {
261
- const l = e.child(i);
262
- for (let a = 0; a < l.childCount; a++) {
263
- const c = l.child(a);
264
- i + c.attrs.rowspan > o && (r += c.attrs.colspan);
265
- }
266
- }
267
- for (let i = 0; i < s.childCount; i++) {
268
- const l = s.child(i);
269
- r += l.attrs.colspan, l.attrs.rowspan > 1 && (n = !0);
270
- }
271
- t == -1 ? t = r : t != r && (t = Math.max(t, r));
272
- }
273
- return t;
274
- }
275
- function Lt(e, t, n) {
276
- e.problems || (e.problems = []);
277
- const o = {};
278
- for (let s = 0; s < e.map.length; s++) {
279
- const r = e.map[s];
280
- if (o[r]) continue;
281
- o[r] = !0;
282
- const i = n.nodeAt(r);
283
- if (!i)
284
- throw new RangeError(`No cell with offset ${r} found`);
285
- let l = null;
286
- const a = i.attrs;
287
- for (let c = 0; c < a.colspan; c++) {
288
- const u = (s + c) % e.width, d = t[u * 2];
289
- d != null && (!a.colwidth || a.colwidth[c] != d) && ((l || (l = Rt(a)))[c] = d);
290
- }
291
- l && e.problems.unshift({
292
- type: "colwidth mismatch",
293
- pos: r,
294
- colwidth: l
295
- });
296
- }
297
- }
298
- function Rt(e) {
299
- if (e.colwidth) return e.colwidth.slice();
300
- const t = [];
301
- for (let n = 0; n < e.colspan; n++) t.push(0);
302
- return t;
303
- }
304
- function S(e) {
305
- let t = e.cached.tableNodeTypes;
306
- if (!t) {
307
- t = e.cached.tableNodeTypes = {};
308
- for (const n in e.nodes) {
309
- const o = e.nodes[n], s = o.spec.tableRole;
310
- s && (t[s] = o);
311
- }
312
- }
313
- return t;
314
- }
315
- var B = new W("selectingCells");
316
- function Y(e) {
317
- for (let t = e.depth - 1; t > 0; t--)
318
- if (e.node(t).type.spec.tableRole == "row")
319
- return e.node(0).resolve(e.before(t + 1));
320
- return null;
321
- }
322
- function Ht(e) {
323
- for (let t = e.depth; t > 0; t--) {
324
- const n = e.node(t).type.spec.tableRole;
325
- if (n === "cell" || n === "header_cell") return e.node(t);
326
- }
327
- return null;
328
- }
329
- function I(e) {
330
- const t = e.selection.$head;
331
- for (let n = t.depth; n > 0; n--)
332
- if (t.node(n).type.spec.tableRole == "row") return !0;
333
- return !1;
334
- }
335
- function he(e) {
336
- const t = e.selection;
337
- if ("$anchorCell" in t && t.$anchorCell)
338
- return t.$anchorCell.pos > t.$headCell.pos ? t.$anchorCell : t.$headCell;
339
- if ("node" in t && t.node && t.node.type.spec.tableRole == "cell")
340
- return t.$anchor;
341
- const n = Y(t.$head) || Et(t.$head);
342
- if (n)
343
- return n;
344
- throw new RangeError(`No cell found around position ${t.head}`);
345
- }
346
- function Et(e) {
347
- for (let t = e.nodeAfter, n = e.pos; t; t = t.firstChild, n++) {
348
- const o = t.type.spec.tableRole;
349
- if (o == "cell" || o == "header_cell") return e.doc.resolve(n);
350
- }
351
- for (let t = e.nodeBefore, n = e.pos; t; t = t.lastChild, n--) {
352
- const o = t.type.spec.tableRole;
353
- if (o == "cell" || o == "header_cell")
354
- return e.doc.resolve(n - t.nodeSize);
355
- }
356
- }
357
- function Me(e) {
358
- return e.parent.type.spec.tableRole == "row" && !!e.nodeAfter;
359
- }
360
- function It(e) {
361
- return e.node(0).resolve(e.pos + e.nodeAfter.nodeSize);
362
- }
363
- function Se(e, t) {
364
- return e.depth == t.depth && e.pos >= t.start(-1) && e.pos <= t.end(-1);
365
- }
366
- function Ye(e, t, n) {
367
- const o = e.node(-1), s = C.get(o), r = e.start(-1), i = s.nextCell(e.pos - r, t, n);
368
- return i == null ? null : e.node(0).resolve(r + i);
369
- }
370
- function q(e, t, n = 1) {
371
- const o = { ...e, colspan: e.colspan - n };
372
- return o.colwidth && (o.colwidth = o.colwidth.slice(), o.colwidth.splice(t, n), o.colwidth.some((s) => s > 0) || (o.colwidth = null)), o;
373
- }
374
- function Ue(e, t, n = 1) {
375
- const o = { ...e, colspan: e.colspan + n };
376
- if (o.colwidth) {
377
- o.colwidth = o.colwidth.slice();
378
- for (let s = 0; s < n; s++) o.colwidth.splice(t, 0, 0);
379
- }
380
- return o;
381
- }
382
- function Nt(e, t, n) {
383
- const o = S(t.type.schema).header_cell;
384
- for (let s = 0; s < e.height; s++)
385
- if (t.nodeAt(e.map[n + s * e.width]).type != o)
386
- return !1;
387
- return !0;
388
- }
389
- var b = class P extends v {
390
- // A table selection is identified by its anchor and head cells. The
391
- // positions given to this constructor should point _before_ two
392
- // cells in the same table. They may be the same, to select a single
393
- // cell.
394
- constructor(t, n = t) {
395
- const o = t.node(-1), s = C.get(o), r = t.start(-1), i = s.rectBetween(
396
- t.pos - r,
397
- n.pos - r
398
- ), l = t.node(0), a = s.cellsInRect(i).filter((u) => u != n.pos - r);
399
- a.unshift(n.pos - r);
400
- const c = a.map((u) => {
401
- const d = o.nodeAt(u);
402
- if (!d)
403
- throw RangeError(`No cell with offset ${u} found`);
404
- const p = r + u + 1;
405
- return new ut(
406
- l.resolve(p),
407
- l.resolve(p + d.content.size)
408
- );
409
- });
410
- super(c[0].$from, c[0].$to, c), this.$anchorCell = t, this.$headCell = n;
411
- }
412
- map(t, n) {
413
- const o = t.resolve(n.map(this.$anchorCell.pos)), s = t.resolve(n.map(this.$headCell.pos));
414
- if (Me(o) && Me(s) && Se(o, s)) {
415
- const r = this.$anchorCell.node(-1) != o.node(-1);
416
- return r && this.isRowSelection() ? P.rowSelection(o, s) : r && this.isColSelection() ? P.colSelection(o, s) : new P(o, s);
417
- }
418
- return x.between(o, s);
419
- }
420
- // Returns a rectangular slice of table rows containing the selected
421
- // cells.
422
- content() {
423
- const t = this.$anchorCell.node(-1), n = C.get(t), o = this.$anchorCell.start(-1), s = n.rectBetween(
424
- this.$anchorCell.pos - o,
425
- this.$headCell.pos - o
426
- ), r = {}, i = [];
427
- for (let a = s.top; a < s.bottom; a++) {
428
- const c = [];
429
- for (let u = a * n.width + s.left, d = s.left; d < s.right; d++, u++) {
430
- const p = n.map[u];
431
- if (r[p]) continue;
432
- r[p] = !0;
433
- const h = n.findCell(p);
434
- let f = t.nodeAt(p);
435
- if (!f)
436
- throw RangeError(`No cell with offset ${p} found`);
437
- const m = s.left - h.left, g = h.right - s.right;
438
- if (m > 0 || g > 0) {
439
- let w = f.attrs;
440
- if (m > 0 && (w = q(w, 0, m)), g > 0 && (w = q(
441
- w,
442
- w.colspan - g,
443
- g
444
- )), h.left < s.left) {
445
- if (f = f.type.createAndFill(w), !f)
446
- throw RangeError(
447
- `Could not create cell with attrs ${JSON.stringify(w)}`
448
- );
449
- } else
450
- f = f.type.create(w, f.content);
451
- }
452
- if (h.top < s.top || h.bottom > s.bottom) {
453
- const w = {
454
- ...f.attrs,
455
- rowspan: Math.min(h.bottom, s.bottom) - Math.max(h.top, s.top)
456
- };
457
- h.top < s.top ? f = f.type.createAndFill(w) : f = f.type.create(w, f.content);
458
- }
459
- c.push(f);
460
- }
461
- i.push(t.child(a).copy(H.from(c)));
462
- }
463
- const l = this.isColSelection() && this.isRowSelection() ? t : i;
464
- return new $(H.from(l), 1, 1);
465
- }
466
- replace(t, n = $.empty) {
467
- const o = t.steps.length, s = this.ranges;
468
- for (let i = 0; i < s.length; i++) {
469
- const { $from: l, $to: a } = s[i], c = t.mapping.slice(o);
470
- t.replace(
471
- c.map(l.pos),
472
- c.map(a.pos),
473
- i ? $.empty : n
474
- );
475
- }
476
- const r = v.findFrom(
477
- t.doc.resolve(t.mapping.slice(o).map(this.to)),
478
- -1
479
- );
480
- r && t.setSelection(r);
481
- }
482
- replaceWith(t, n) {
483
- this.replace(t, new $(H.from(n), 0, 0));
484
- }
485
- forEachCell(t) {
486
- const n = this.$anchorCell.node(-1), o = C.get(n), s = this.$anchorCell.start(-1), r = o.cellsInRect(
487
- o.rectBetween(
488
- this.$anchorCell.pos - s,
489
- this.$headCell.pos - s
490
- )
491
- );
492
- for (let i = 0; i < r.length; i++)
493
- t(n.nodeAt(r[i]), s + r[i]);
494
- }
495
- // True if this selection goes all the way from the top to the
496
- // bottom of the table.
497
- isColSelection() {
498
- const t = this.$anchorCell.index(-1), n = this.$headCell.index(-1);
499
- if (Math.min(t, n) > 0) return !1;
500
- const o = t + this.$anchorCell.nodeAfter.attrs.rowspan, s = n + this.$headCell.nodeAfter.attrs.rowspan;
501
- return Math.max(o, s) == this.$headCell.node(-1).childCount;
502
- }
503
- // Returns the smallest column selection that covers the given anchor
504
- // and head cell.
505
- static colSelection(t, n = t) {
506
- const o = t.node(-1), s = C.get(o), r = t.start(-1), i = s.findCell(t.pos - r), l = s.findCell(n.pos - r), a = t.node(0);
507
- return i.top <= l.top ? (i.top > 0 && (t = a.resolve(r + s.map[i.left])), l.bottom < s.height && (n = a.resolve(
508
- r + s.map[s.width * (s.height - 1) + l.right - 1]
509
- ))) : (l.top > 0 && (n = a.resolve(r + s.map[l.left])), i.bottom < s.height && (t = a.resolve(
510
- r + s.map[s.width * (s.height - 1) + i.right - 1]
511
- ))), new P(t, n);
512
- }
513
- // True if this selection goes all the way from the left to the
514
- // right of the table.
515
- isRowSelection() {
516
- const t = this.$anchorCell.node(-1), n = C.get(t), o = this.$anchorCell.start(-1), s = n.colCount(this.$anchorCell.pos - o), r = n.colCount(this.$headCell.pos - o);
517
- if (Math.min(s, r) > 0) return !1;
518
- const i = s + this.$anchorCell.nodeAfter.attrs.colspan, l = r + this.$headCell.nodeAfter.attrs.colspan;
519
- return Math.max(i, l) == n.width;
520
- }
521
- eq(t) {
522
- return t instanceof P && t.$anchorCell.pos == this.$anchorCell.pos && t.$headCell.pos == this.$headCell.pos;
523
- }
524
- // Returns the smallest row selection that covers the given anchor
525
- // and head cell.
526
- static rowSelection(t, n = t) {
527
- const o = t.node(-1), s = C.get(o), r = t.start(-1), i = s.findCell(t.pos - r), l = s.findCell(n.pos - r), a = t.node(0);
528
- return i.left <= l.left ? (i.left > 0 && (t = a.resolve(
529
- r + s.map[i.top * s.width]
530
- )), l.right < s.width && (n = a.resolve(
531
- r + s.map[s.width * (l.top + 1) - 1]
532
- ))) : (l.left > 0 && (n = a.resolve(r + s.map[l.top * s.width])), i.right < s.width && (t = a.resolve(
533
- r + s.map[s.width * (i.top + 1) - 1]
534
- ))), new P(t, n);
535
- }
536
- toJSON() {
537
- return {
538
- type: "cell",
539
- anchor: this.$anchorCell.pos,
540
- head: this.$headCell.pos
541
- };
542
- }
543
- static fromJSON(t, n) {
544
- return new P(t.resolve(n.anchor), t.resolve(n.head));
545
- }
546
- static create(t, n, o = n) {
547
- return new P(t.resolve(n), t.resolve(o));
548
- }
549
- getBookmark() {
550
- return new $t(this.$anchorCell.pos, this.$headCell.pos);
551
- }
552
- };
553
- b.prototype.visible = !1;
554
- v.jsonID("cell", b);
555
- var $t = class Ze {
556
- constructor(t, n) {
557
- this.anchor = t, this.head = n;
558
- }
559
- map(t) {
560
- return new Ze(t.map(this.anchor), t.map(this.head));
561
- }
562
- resolve(t) {
563
- const n = t.resolve(this.anchor), o = t.resolve(this.head);
564
- return n.parent.type.spec.tableRole == "row" && o.parent.type.spec.tableRole == "row" && n.index() < n.parent.childCount && o.index() < o.parent.childCount && Se(n, o) ? new b(n, o) : v.near(o, 1);
565
- }
566
- };
567
- function Ot(e) {
568
- if (!(e.selection instanceof b)) return null;
569
- const t = [];
570
- return e.selection.forEachCell((n, o) => {
571
- t.push(
572
- G.node(o, o + n.nodeSize, { class: "selectedCell" })
573
- );
574
- }), K.create(e.doc, t);
575
- }
576
- function zt({ $from: e, $to: t }) {
577
- if (e.pos == t.pos || e.pos < t.pos - 6) return !1;
578
- let n = e.pos, o = t.pos, s = e.depth;
579
- for (; s >= 0 && !(e.after(s + 1) < e.end(s)); s--, n++)
580
- ;
581
- for (let r = t.depth; r >= 0 && !(t.before(r + 1) > t.start(r)); r--, o--)
582
- ;
583
- return n == o && /row|table/.test(e.node(s).type.spec.tableRole);
584
- }
585
- function Pt({ $from: e, $to: t }) {
586
- let n, o;
587
- for (let s = e.depth; s > 0; s--) {
588
- const r = e.node(s);
589
- if (r.type.spec.tableRole === "cell" || r.type.spec.tableRole === "header_cell") {
590
- n = r;
591
- break;
592
- }
593
- }
594
- for (let s = t.depth; s > 0; s--) {
595
- const r = t.node(s);
596
- if (r.type.spec.tableRole === "cell" || r.type.spec.tableRole === "header_cell") {
597
- o = r;
598
- break;
599
- }
600
- }
601
- return n !== o && t.parentOffset === 0;
602
- }
603
- function Dt(e, t, n) {
604
- const o = (t || e).selection, s = (t || e).doc;
605
- let r, i;
606
- if (o instanceof pe && (i = o.node.type.spec.tableRole)) {
607
- if (i == "cell" || i == "header_cell")
608
- r = b.create(s, o.from);
609
- else if (i == "row") {
610
- const l = s.resolve(o.from + 1);
611
- r = b.rowSelection(l, l);
612
- } else if (!n) {
613
- const l = C.get(o.node), a = o.from + 1, c = a + l.map[l.width * l.height - 1];
614
- r = b.create(s, a + 1, c);
615
- }
616
- } else o instanceof x && zt(o) ? r = x.create(s, o.from) : o instanceof x && Pt(o) && (r = x.create(s, o.$from.start(), o.$from.end()));
617
- return r && (t || (t = e.tr)).setSelection(r), t;
618
- }
619
- var Bt = new W("fix-tables");
620
- function et(e, t, n, o) {
621
- const s = e.childCount, r = t.childCount;
622
- e: for (let i = 0, l = 0; i < r; i++) {
623
- const a = t.child(i);
624
- for (let c = l, u = Math.min(s, i + 3); c < u; c++)
625
- if (e.child(c) == a) {
626
- l = c + 1, n += a.nodeSize;
627
- continue e;
628
- }
629
- o(a, n), l < s && e.child(l).sameMarkup(a) ? et(e.child(l), a, n + 1, o) : a.nodesBetween(0, a.content.size, o, n + 1), n += a.nodeSize;
630
- }
631
- }
632
- function tt(e, t) {
633
- let n;
634
- const o = (s, r) => {
635
- s.type.spec.tableRole == "table" && (n = _t(e, s, r, n));
636
- };
637
- return t ? t.doc != e.doc && et(t.doc, e.doc, 0, o) : e.doc.descendants(o), n;
638
- }
639
- function _t(e, t, n, o) {
640
- const s = C.get(t);
641
- if (!s.problems) return o;
642
- o || (o = e.tr);
643
- const r = [];
644
- for (let a = 0; a < s.height; a++) r.push(0);
645
- for (let a = 0; a < s.problems.length; a++) {
646
- const c = s.problems[a];
647
- if (c.type == "collision") {
648
- const u = t.nodeAt(c.pos);
649
- if (!u) continue;
650
- const d = u.attrs;
651
- for (let p = 0; p < d.rowspan; p++) r[c.row + p] += c.n;
652
- o.setNodeMarkup(
653
- o.mapping.map(n + 1 + c.pos),
654
- null,
655
- q(d, d.colspan - c.n, c.n)
656
- );
657
- } else if (c.type == "missing")
658
- r[c.row] += c.n;
659
- else if (c.type == "overlong_rowspan") {
660
- const u = t.nodeAt(c.pos);
661
- if (!u) continue;
662
- o.setNodeMarkup(o.mapping.map(n + 1 + c.pos), null, {
663
- ...u.attrs,
664
- rowspan: u.attrs.rowspan - c.n
665
- });
666
- } else if (c.type == "colwidth mismatch") {
667
- const u = t.nodeAt(c.pos);
668
- if (!u) continue;
669
- o.setNodeMarkup(o.mapping.map(n + 1 + c.pos), null, {
670
- ...u.attrs,
671
- colwidth: c.colwidth
672
- });
673
- } else if (c.type == "zero_sized") {
674
- const u = o.mapping.map(n);
675
- o.delete(u, u + t.nodeSize);
676
- }
677
- }
678
- let i, l;
679
- for (let a = 0; a < r.length; a++)
680
- r[a] && (i == null && (i = a), l = a);
681
- for (let a = 0, c = n + 1; a < s.height; a++) {
682
- const u = t.child(a), d = c + u.nodeSize, p = r[a];
683
- if (p > 0) {
684
- let h = "cell";
685
- u.firstChild && (h = u.firstChild.type.spec.tableRole);
686
- const f = [];
687
- for (let g = 0; g < p; g++) {
688
- const w = S(e.schema)[h].createAndFill();
689
- w && f.push(w);
690
- }
691
- const m = (a == 0 || i == a - 1) && l == a ? c + 1 : d - 1;
692
- o.insert(o.mapping.map(m), f);
693
- }
694
- c = d;
695
- }
696
- return o.setMeta(Bt, { fixTables: !0 });
697
- }
698
- function O(e) {
699
- const t = e.selection, n = he(e), o = n.node(-1), s = n.start(-1), r = C.get(o);
700
- return { ...t instanceof b ? r.rectBetween(
701
- t.$anchorCell.pos - s,
702
- t.$headCell.pos - s
703
- ) : r.findCell(n.pos - s), tableStart: s, map: r, table: o };
704
- }
705
- function nt(e, { map: t, tableStart: n, table: o }, s) {
706
- let r = s > 0 ? -1 : 0;
707
- Nt(t, o, s + r) && (r = s == 0 || s == t.width ? null : 0);
708
- for (let i = 0; i < t.height; i++) {
709
- const l = i * t.width + s;
710
- if (s > 0 && s < t.width && t.map[l - 1] == t.map[l]) {
711
- const a = t.map[l], c = o.nodeAt(a);
712
- e.setNodeMarkup(
713
- e.mapping.map(n + a),
714
- null,
715
- Ue(c.attrs, s - t.colCount(a))
716
- ), i += c.attrs.rowspan - 1;
717
- } else {
718
- const a = r == null ? S(o.type.schema).cell : o.nodeAt(t.map[l + r]).type, c = t.positionAt(i, s, o);
719
- e.insert(e.mapping.map(n + c), a.createAndFill());
720
- }
721
- }
722
- return e;
723
- }
724
- function Wt(e, t) {
725
- if (!I(e)) return !1;
726
- if (t) {
727
- const n = O(e);
728
- t(nt(e.tr, n, n.left));
729
- }
730
- return !0;
731
- }
732
- function Vt(e, t) {
733
- if (!I(e)) return !1;
734
- if (t) {
735
- const n = O(e);
736
- t(nt(e.tr, n, n.right));
737
- }
738
- return !0;
739
- }
740
- function Ft(e, { map: t, table: n, tableStart: o }, s) {
741
- const r = e.mapping.maps.length;
742
- for (let i = 0; i < t.height; ) {
743
- const l = i * t.width + s, a = t.map[l], c = n.nodeAt(a), u = c.attrs;
744
- if (s > 0 && t.map[l - 1] == a || s < t.width - 1 && t.map[l + 1] == a)
745
- e.setNodeMarkup(
746
- e.mapping.slice(r).map(o + a),
747
- null,
748
- q(u, s - t.colCount(a))
749
- );
750
- else {
751
- const d = e.mapping.slice(r).map(o + a);
752
- e.delete(d, d + c.nodeSize);
753
- }
754
- i += u.rowspan;
755
- }
756
- }
757
- function Kt(e, t) {
758
- if (!I(e)) return !1;
759
- if (t) {
760
- const n = O(e), o = e.tr;
761
- if (n.left == 0 && n.right == n.map.width) return !1;
762
- for (let s = n.right - 1; Ft(o, n, s), s != n.left; s--) {
763
- const r = n.tableStart ? o.doc.nodeAt(n.tableStart - 1) : o.doc;
764
- if (!r)
765
- throw RangeError("No table found");
766
- n.table = r, n.map = C.get(r);
767
- }
768
- t(o);
769
- }
770
- return !0;
771
- }
772
- function jt(e, t, n) {
773
- var o;
774
- const s = S(t.type.schema).header_cell;
775
- for (let r = 0; r < e.width; r++)
776
- if (((o = t.nodeAt(e.map[r + n * e.width])) == null ? void 0 : o.type) != s)
777
- return !1;
778
- return !0;
779
- }
780
- function ot(e, { map: t, tableStart: n, table: o }, s) {
781
- var r;
782
- let i = n;
783
- for (let c = 0; c < s; c++) i += o.child(c).nodeSize;
784
- const l = [];
785
- let a = s > 0 ? -1 : 0;
786
- jt(t, o, s + a) && (a = s == 0 || s == t.height ? null : 0);
787
- for (let c = 0, u = t.width * s; c < t.width; c++, u++)
788
- if (s > 0 && s < t.height && t.map[u] == t.map[u - t.width]) {
789
- const d = t.map[u], p = o.nodeAt(d).attrs;
790
- e.setNodeMarkup(n + d, null, {
791
- ...p,
792
- rowspan: p.rowspan + 1
793
- }), c += p.colspan - 1;
794
- } else {
795
- const d = a == null ? S(o.type.schema).cell : (r = o.nodeAt(t.map[u + a * t.width])) == null ? void 0 : r.type, p = d == null ? void 0 : d.createAndFill();
796
- p && l.push(p);
797
- }
798
- return e.insert(i, S(o.type.schema).row.create(null, l)), e;
799
- }
800
- function Qt(e, t) {
801
- if (!I(e)) return !1;
802
- if (t) {
803
- const n = O(e);
804
- t(ot(e.tr, n, n.top));
805
- }
806
- return !0;
807
- }
808
- function qt(e, t) {
809
- if (!I(e)) return !1;
810
- if (t) {
811
- const n = O(e);
812
- t(ot(e.tr, n, n.bottom));
813
- }
814
- return !0;
815
- }
816
- function Xt(e, { map: t, table: n, tableStart: o }, s) {
817
- let r = 0;
818
- for (let c = 0; c < s; c++) r += n.child(c).nodeSize;
819
- const i = r + n.child(s).nodeSize, l = e.mapping.maps.length;
820
- e.delete(r + o, i + o);
821
- const a = /* @__PURE__ */ new Set();
822
- for (let c = 0, u = s * t.width; c < t.width; c++, u++) {
823
- const d = t.map[u];
824
- if (!a.has(d)) {
825
- if (a.add(d), s > 0 && d == t.map[u - t.width]) {
826
- const p = n.nodeAt(d).attrs;
827
- e.setNodeMarkup(e.mapping.slice(l).map(d + o), null, {
828
- ...p,
829
- rowspan: p.rowspan - 1
830
- }), c += p.colspan - 1;
831
- } else if (s < t.height && d == t.map[u + t.width]) {
832
- const p = n.nodeAt(d), h = p.attrs, f = p.type.create(
833
- { ...h, rowspan: p.attrs.rowspan - 1 },
834
- p.content
835
- ), m = t.positionAt(s + 1, c, n);
836
- e.insert(e.mapping.slice(l).map(o + m), f), c += h.colspan - 1;
837
- }
838
- }
839
- }
840
- }
841
- function Gt(e, t) {
842
- if (!I(e)) return !1;
843
- if (t) {
844
- const n = O(e), o = e.tr;
845
- if (n.top == 0 && n.bottom == n.map.height) return !1;
846
- for (let s = n.bottom - 1; Xt(o, n, s), s != n.top; s--) {
847
- const r = n.tableStart ? o.doc.nodeAt(n.tableStart - 1) : o.doc;
848
- if (!r)
849
- throw RangeError("No table found");
850
- n.table = r, n.map = C.get(n.table);
851
- }
852
- t(o);
853
- }
854
- return !0;
855
- }
856
- function xe(e) {
857
- const t = e.content;
858
- return t.childCount == 1 && t.child(0).isTextblock && t.child(0).childCount == 0;
859
- }
860
- function Jt({ width: e, height: t, map: n }, o) {
861
- let s = o.top * e + o.left, r = s, i = (o.bottom - 1) * e + o.left, l = s + (o.right - o.left - 1);
862
- for (let a = o.top; a < o.bottom; a++) {
863
- if (o.left > 0 && n[r] == n[r - 1] || o.right < e && n[l] == n[l + 1])
864
- return !0;
865
- r += e, l += e;
866
- }
867
- for (let a = o.left; a < o.right; a++) {
868
- if (o.top > 0 && n[s] == n[s - e] || o.bottom < t && n[i] == n[i + e])
869
- return !0;
870
- s++, i++;
871
- }
872
- return !1;
873
- }
874
- function Le(e, t) {
875
- const n = e.selection;
876
- if (!(n instanceof b) || n.$anchorCell.pos == n.$headCell.pos)
877
- return !1;
878
- const o = O(e), { map: s } = o;
879
- if (Jt(s, o)) return !1;
880
- if (t) {
881
- const r = e.tr, i = {};
882
- let l = H.empty, a, c;
883
- for (let u = o.top; u < o.bottom; u++)
884
- for (let d = o.left; d < o.right; d++) {
885
- const p = s.map[u * s.width + d], h = o.table.nodeAt(p);
886
- if (!(i[p] || !h))
887
- if (i[p] = !0, a == null)
888
- a = p, c = h;
889
- else {
890
- xe(h) || (l = l.append(h.content));
891
- const f = r.mapping.map(p + o.tableStart);
892
- r.delete(f, f + h.nodeSize);
893
- }
894
- }
895
- if (a == null || c == null)
896
- return !0;
897
- if (r.setNodeMarkup(a + o.tableStart, null, {
898
- ...Ue(
899
- c.attrs,
900
- c.attrs.colspan,
901
- o.right - o.left - c.attrs.colspan
902
- ),
903
- rowspan: o.bottom - o.top
904
- }), l.size) {
905
- const u = a + 1 + c.content.size, d = xe(c) ? a + 1 : u;
906
- r.replaceWith(d + o.tableStart, u + o.tableStart, l);
907
- }
908
- r.setSelection(
909
- new b(r.doc.resolve(a + o.tableStart))
910
- ), t(r);
911
- }
912
- return !0;
913
- }
914
- function Re(e, t) {
915
- const n = S(e.schema);
916
- return Yt(({ node: o }) => n[o.type.spec.tableRole])(e, t);
917
- }
918
- function Yt(e) {
919
- return (t, n) => {
920
- var o;
921
- const s = t.selection;
922
- let r, i;
923
- if (s instanceof b) {
924
- if (s.$anchorCell.pos != s.$headCell.pos) return !1;
925
- r = s.$anchorCell.nodeAfter, i = s.$anchorCell.pos;
926
- } else {
927
- if (r = Ht(s.$from), !r) return !1;
928
- i = (o = Y(s.$from)) == null ? void 0 : o.pos;
929
- }
930
- if (r == null || i == null || r.attrs.colspan == 1 && r.attrs.rowspan == 1)
931
- return !1;
932
- if (n) {
933
- let l = r.attrs;
934
- const a = [], c = l.colwidth;
935
- l.rowspan > 1 && (l = { ...l, rowspan: 1 }), l.colspan > 1 && (l = { ...l, colspan: 1 });
936
- const u = O(t), d = t.tr;
937
- for (let h = 0; h < u.right - u.left; h++)
938
- a.push(
939
- c ? {
940
- ...l,
941
- colwidth: c && c[h] ? [c[h]] : null
942
- } : l
943
- );
944
- let p;
945
- for (let h = u.top; h < u.bottom; h++) {
946
- let f = u.map.positionAt(h, u.left, u.table);
947
- h == u.top && (f += r.nodeSize);
948
- for (let m = u.left, g = 0; m < u.right; m++, g++)
949
- m == u.left && h == u.top || d.insert(
950
- p = d.mapping.map(f + u.tableStart, 1),
951
- e({ node: r, row: h, col: m }).createAndFill(a[g])
952
- );
953
- }
954
- d.setNodeMarkup(
955
- i,
956
- e({ node: r, row: u.top, col: u.left }),
957
- a[0]
958
- ), s instanceof b && d.setSelection(
959
- new b(
960
- d.doc.resolve(s.$anchorCell.pos),
961
- p ? d.doc.resolve(p) : void 0
962
- )
963
- ), n(d);
964
- }
965
- return !0;
966
- };
967
- }
968
- function Ut(e, t) {
969
- return function(n, o) {
970
- if (!I(n)) return !1;
971
- const s = he(n);
972
- if (s.nodeAfter.attrs[e] === t) return !1;
973
- if (o) {
974
- const r = n.tr;
975
- n.selection instanceof b ? n.selection.forEachCell((i, l) => {
976
- i.attrs[e] !== t && r.setNodeMarkup(l, null, {
977
- ...i.attrs,
978
- [e]: t
979
- });
980
- }) : r.setNodeMarkup(s.pos, null, {
981
- ...s.nodeAfter.attrs,
982
- [e]: t
983
- }), o(r);
984
- }
985
- return !0;
986
- };
987
- }
988
- function Zt(e) {
989
- return function(t, n) {
990
- if (!I(t)) return !1;
991
- if (n) {
992
- const o = S(t.schema), s = O(t), r = t.tr, i = s.map.cellsInRect(
993
- e == "column" ? {
994
- left: s.left,
995
- top: 0,
996
- right: s.right,
997
- bottom: s.map.height
998
- } : e == "row" ? {
999
- left: 0,
1000
- top: s.top,
1001
- right: s.map.width,
1002
- bottom: s.bottom
1003
- } : s
1004
- ), l = i.map((a) => s.table.nodeAt(a));
1005
- for (let a = 0; a < i.length; a++)
1006
- l[a].type == o.header_cell && r.setNodeMarkup(
1007
- s.tableStart + i[a],
1008
- o.cell,
1009
- l[a].attrs
1010
- );
1011
- if (r.steps.length == 0)
1012
- for (let a = 0; a < i.length; a++)
1013
- r.setNodeMarkup(
1014
- s.tableStart + i[a],
1015
- o.header_cell,
1016
- l[a].attrs
1017
- );
1018
- n(r);
1019
- }
1020
- return !0;
1021
- };
1022
- }
1023
- function He(e, t, n) {
1024
- const o = t.map.cellsInRect({
1025
- left: 0,
1026
- top: 0,
1027
- right: e == "row" ? t.map.width : 1,
1028
- bottom: e == "column" ? t.map.height : 1
1029
- });
1030
- for (let s = 0; s < o.length; s++) {
1031
- const r = t.table.nodeAt(o[s]);
1032
- if (r && r.type !== n.header_cell)
1033
- return !1;
1034
- }
1035
- return !0;
1036
- }
1037
- function ee(e, t) {
1038
- return t = t || { useDeprecatedLogic: !1 }, t.useDeprecatedLogic ? Zt(e) : function(n, o) {
1039
- if (!I(n)) return !1;
1040
- if (o) {
1041
- const s = S(n.schema), r = O(n), i = n.tr, l = He("row", r, s), a = He(
1042
- "column",
1043
- r,
1044
- s
1045
- ), u = (e === "column" ? l : e === "row" ? a : !1) ? 1 : 0, d = e == "column" ? {
1046
- left: 0,
1047
- top: u,
1048
- right: 1,
1049
- bottom: r.map.height
1050
- } : e == "row" ? {
1051
- left: u,
1052
- top: 0,
1053
- right: r.map.width,
1054
- bottom: 1
1055
- } : r, p = e == "column" ? a ? s.cell : s.header_cell : e == "row" ? l ? s.cell : s.header_cell : s.cell;
1056
- r.map.cellsInRect(d).forEach((h) => {
1057
- const f = h + r.tableStart, m = i.doc.nodeAt(f);
1058
- m && i.setNodeMarkup(f, p, m.attrs);
1059
- }), o(i);
1060
- }
1061
- return !0;
1062
- };
1063
- }
1064
- ee("row", {
1065
- useDeprecatedLogic: !0
1066
- });
1067
- ee("column", {
1068
- useDeprecatedLogic: !0
1069
- });
1070
- var en = ee("cell", {
1071
- useDeprecatedLogic: !0
1072
- });
1073
- function tn(e, t) {
1074
- if (t < 0) {
1075
- const n = e.nodeBefore;
1076
- if (n) return e.pos - n.nodeSize;
1077
- for (let o = e.index(-1) - 1, s = e.before(); o >= 0; o--) {
1078
- const r = e.node(-1).child(o), i = r.lastChild;
1079
- if (i)
1080
- return s - 1 - i.nodeSize;
1081
- s -= r.nodeSize;
1082
- }
1083
- } else {
1084
- if (e.index() < e.parent.childCount - 1)
1085
- return e.pos + e.nodeAfter.nodeSize;
1086
- const n = e.node(-1);
1087
- for (let o = e.indexAfter(-1), s = e.after(); o < n.childCount; o++) {
1088
- const r = n.child(o);
1089
- if (r.childCount) return s + 1;
1090
- s += r.nodeSize;
1091
- }
1092
- }
1093
- return null;
1094
- }
1095
- function Ee(e) {
1096
- return function(t, n) {
1097
- if (!I(t)) return !1;
1098
- const o = tn(he(t), e);
1099
- if (o == null) return !1;
1100
- if (n) {
1101
- const s = t.doc.resolve(o);
1102
- n(
1103
- t.tr.setSelection(x.between(s, It(s))).scrollIntoView()
1104
- );
1105
- }
1106
- return !0;
1107
- };
1108
- }
1109
- function nn(e, t) {
1110
- const n = e.selection.$anchor;
1111
- for (let o = n.depth; o > 0; o--)
1112
- if (n.node(o).type.spec.tableRole == "table")
1113
- return t && t(
1114
- e.tr.delete(n.before(o), n.after(o)).scrollIntoView()
1115
- ), !0;
1116
- return !1;
1117
- }
1118
- function oe(e, t) {
1119
- const n = e.selection;
1120
- if (!(n instanceof b)) return !1;
1121
- if (t) {
1122
- const o = e.tr, s = S(e.schema).cell.createAndFill().content;
1123
- n.forEachCell((r, i) => {
1124
- r.content.eq(s) || o.replace(
1125
- o.mapping.map(i + 1),
1126
- o.mapping.map(i + r.nodeSize - 1),
1127
- new $(s, 0, 0)
1128
- );
1129
- }), o.docChanged && t(o);
1130
- }
1131
- return !0;
1132
- }
1133
- function on(e) {
1134
- if (!e.size) return null;
1135
- let { content: t, openStart: n, openEnd: o } = e;
1136
- for (; t.childCount == 1 && (n > 0 && o > 0 || t.child(0).type.spec.tableRole == "table"); )
1137
- n--, o--, t = t.child(0).content;
1138
- const s = t.child(0), r = s.type.spec.tableRole, i = s.type.schema, l = [];
1139
- if (r == "row")
1140
- for (let a = 0; a < t.childCount; a++) {
1141
- let c = t.child(a).content;
1142
- const u = a ? 0 : Math.max(0, n - 1), d = a < t.childCount - 1 ? 0 : Math.max(0, o - 1);
1143
- (u || d) && (c = Ae(
1144
- S(i).row,
1145
- new $(c, u, d)
1146
- ).content), l.push(c);
1147
- }
1148
- else if (r == "cell" || r == "header_cell")
1149
- l.push(
1150
- n || o ? Ae(
1151
- S(i).row,
1152
- new $(t, n, o)
1153
- ).content : t
1154
- );
1155
- else
1156
- return null;
1157
- return sn(i, l);
1158
- }
1159
- function sn(e, t) {
1160
- const n = [];
1161
- for (let s = 0; s < t.length; s++) {
1162
- const r = t[s];
1163
- for (let i = r.childCount - 1; i >= 0; i--) {
1164
- const { rowspan: l, colspan: a } = r.child(i).attrs;
1165
- for (let c = s; c < s + l; c++)
1166
- n[c] = (n[c] || 0) + a;
1167
- }
1168
- }
1169
- let o = 0;
1170
- for (let s = 0; s < n.length; s++) o = Math.max(o, n[s]);
1171
- for (let s = 0; s < n.length; s++)
1172
- if (s >= t.length && t.push(H.empty), n[s] < o) {
1173
- const r = S(e).cell.createAndFill(), i = [];
1174
- for (let l = n[s]; l < o; l++)
1175
- i.push(r);
1176
- t[s] = t[s].append(H.from(i));
1177
- }
1178
- return { height: t.length, width: o, rows: t };
1179
- }
1180
- function Ae(e, t) {
1181
- const n = e.createAndFill();
1182
- return new pt(n).replace(0, n.content.size, t).doc;
1183
- }
1184
- function rn({ width: e, height: t, rows: n }, o, s) {
1185
- if (e != o) {
1186
- const r = [], i = [];
1187
- for (let l = 0; l < n.length; l++) {
1188
- const a = n[l], c = [];
1189
- for (let u = r[l] || 0, d = 0; u < o; d++) {
1190
- let p = a.child(d % a.childCount);
1191
- u + p.attrs.colspan > o && (p = p.type.createChecked(
1192
- q(
1193
- p.attrs,
1194
- p.attrs.colspan,
1195
- u + p.attrs.colspan - o
1196
- ),
1197
- p.content
1198
- )), c.push(p), u += p.attrs.colspan;
1199
- for (let h = 1; h < p.attrs.rowspan; h++)
1200
- r[l + h] = (r[l + h] || 0) + p.attrs.colspan;
1201
- }
1202
- i.push(H.from(c));
1203
- }
1204
- n = i, e = o;
1205
- }
1206
- if (t != s) {
1207
- const r = [];
1208
- for (let i = 0, l = 0; i < s; i++, l++) {
1209
- const a = [], c = n[l % t];
1210
- for (let u = 0; u < c.childCount; u++) {
1211
- let d = c.child(u);
1212
- i + d.attrs.rowspan > s && (d = d.type.create(
1213
- {
1214
- ...d.attrs,
1215
- rowspan: Math.max(1, s - d.attrs.rowspan)
1216
- },
1217
- d.content
1218
- )), a.push(d);
1219
- }
1220
- r.push(H.from(a));
1221
- }
1222
- n = r, t = s;
1223
- }
1224
- return { width: e, height: t, rows: n };
1225
- }
1226
- function ln(e, t, n, o, s, r, i) {
1227
- const l = e.doc.type.schema, a = S(l);
1228
- let c, u;
1229
- if (s > t.width)
1230
- for (let d = 0, p = 0; d < t.height; d++) {
1231
- const h = n.child(d);
1232
- p += h.nodeSize;
1233
- const f = [];
1234
- let m;
1235
- h.lastChild == null || h.lastChild.type == a.cell ? m = c || (c = a.cell.createAndFill()) : m = u || (u = a.header_cell.createAndFill());
1236
- for (let g = t.width; g < s; g++) f.push(m);
1237
- e.insert(e.mapping.slice(i).map(p - 1 + o), f);
1238
- }
1239
- if (r > t.height) {
1240
- const d = [];
1241
- for (let f = 0, m = (t.height - 1) * t.width; f < Math.max(t.width, s); f++) {
1242
- const g = f >= t.width ? !1 : n.nodeAt(t.map[m + f]).type == a.header_cell;
1243
- d.push(
1244
- g ? u || (u = a.header_cell.createAndFill()) : c || (c = a.cell.createAndFill())
1245
- );
1246
- }
1247
- const p = a.row.create(null, H.from(d)), h = [];
1248
- for (let f = t.height; f < r; f++) h.push(p);
1249
- e.insert(e.mapping.slice(i).map(o + n.nodeSize - 2), h);
1250
- }
1251
- return !!(c || u);
1252
- }
1253
- function Ie(e, t, n, o, s, r, i, l) {
1254
- if (i == 0 || i == t.height) return !1;
1255
- let a = !1;
1256
- for (let c = s; c < r; c++) {
1257
- const u = i * t.width + c, d = t.map[u];
1258
- if (t.map[u - t.width] == d) {
1259
- a = !0;
1260
- const p = n.nodeAt(d), { top: h, left: f } = t.findCell(d);
1261
- e.setNodeMarkup(e.mapping.slice(l).map(d + o), null, {
1262
- ...p.attrs,
1263
- rowspan: i - h
1264
- }), e.insert(
1265
- e.mapping.slice(l).map(t.positionAt(i, f, n)),
1266
- p.type.createAndFill({
1267
- ...p.attrs,
1268
- rowspan: h + p.attrs.rowspan - i
1269
- })
1270
- ), c += p.attrs.colspan - 1;
1271
- }
1272
- }
1273
- return a;
1274
- }
1275
- function Ne(e, t, n, o, s, r, i, l) {
1276
- if (i == 0 || i == t.width) return !1;
1277
- let a = !1;
1278
- for (let c = s; c < r; c++) {
1279
- const u = c * t.width + i, d = t.map[u];
1280
- if (t.map[u - 1] == d) {
1281
- a = !0;
1282
- const p = n.nodeAt(d), h = t.colCount(d), f = e.mapping.slice(l).map(d + o);
1283
- e.setNodeMarkup(
1284
- f,
1285
- null,
1286
- q(
1287
- p.attrs,
1288
- i - h,
1289
- p.attrs.colspan - (i - h)
1290
- )
1291
- ), e.insert(
1292
- f + p.nodeSize,
1293
- p.type.createAndFill(
1294
- q(p.attrs, 0, i - h)
1295
- )
1296
- ), c += p.attrs.rowspan - 1;
1297
- }
1298
- }
1299
- return a;
1300
- }
1301
- function $e(e, t, n, o, s) {
1302
- let r = n ? e.doc.nodeAt(n - 1) : e.doc;
1303
- if (!r)
1304
- throw new Error("No table found");
1305
- let i = C.get(r);
1306
- const { top: l, left: a } = o, c = a + s.width, u = l + s.height, d = e.tr;
1307
- let p = 0;
1308
- function h() {
1309
- if (r = n ? d.doc.nodeAt(n - 1) : d.doc, !r)
1310
- throw new Error("No table found");
1311
- i = C.get(r), p = d.mapping.maps.length;
1312
- }
1313
- ln(d, i, r, n, c, u, p) && h(), Ie(d, i, r, n, a, c, l, p) && h(), Ie(d, i, r, n, a, c, u, p) && h(), Ne(d, i, r, n, l, u, a, p) && h(), Ne(d, i, r, n, l, u, c, p) && h();
1314
- for (let f = l; f < u; f++) {
1315
- const m = i.positionAt(f, a, r), g = i.positionAt(f, c, r);
1316
- d.replace(
1317
- d.mapping.slice(p).map(m + n),
1318
- d.mapping.slice(p).map(g + n),
1319
- new $(s.rows[f - l], 0, 0)
1320
- );
1321
- }
1322
- h(), d.setSelection(
1323
- new b(
1324
- d.doc.resolve(n + i.positionAt(l, a, r)),
1325
- d.doc.resolve(n + i.positionAt(u - 1, c - 1, r))
1326
- )
1327
- ), t(d);
1328
- }
1329
- var an = Xe({
1330
- ArrowLeft: se("horiz", -1),
1331
- ArrowRight: se("horiz", 1),
1332
- ArrowUp: se("vert", -1),
1333
- ArrowDown: se("vert", 1),
1334
- "Shift-ArrowLeft": re("horiz", -1),
1335
- "Shift-ArrowRight": re("horiz", 1),
1336
- "Shift-ArrowUp": re("vert", -1),
1337
- "Shift-ArrowDown": re("vert", 1),
1338
- Backspace: oe,
1339
- "Mod-Backspace": oe,
1340
- Delete: oe,
1341
- "Mod-Delete": oe
1342
- });
1343
- function ae(e, t, n) {
1344
- return n.eq(e.selection) ? !1 : (t && t(e.tr.setSelection(n).scrollIntoView()), !0);
1345
- }
1346
- function se(e, t) {
1347
- return (n, o, s) => {
1348
- if (!s) return !1;
1349
- const r = n.selection;
1350
- if (r instanceof b)
1351
- return ae(
1352
- n,
1353
- o,
1354
- v.near(r.$headCell, t)
1355
- );
1356
- if (e != "horiz" && !r.empty) return !1;
1357
- const i = st(s, e, t);
1358
- if (i == null) return !1;
1359
- if (e == "horiz")
1360
- return ae(
1361
- n,
1362
- o,
1363
- v.near(n.doc.resolve(r.head + t), t)
1364
- );
1365
- {
1366
- const l = n.doc.resolve(i), a = Ye(l, e, t);
1367
- let c;
1368
- return a ? c = v.near(a, 1) : t < 0 ? c = v.near(n.doc.resolve(l.before(-1)), -1) : c = v.near(n.doc.resolve(l.after(-1)), 1), ae(n, o, c);
1369
- }
1370
- };
1371
- }
1372
- function re(e, t) {
1373
- return (n, o, s) => {
1374
- if (!s) return !1;
1375
- const r = n.selection;
1376
- let i;
1377
- if (r instanceof b)
1378
- i = r;
1379
- else {
1380
- const a = st(s, e, t);
1381
- if (a == null) return !1;
1382
- i = new b(n.doc.resolve(a));
1383
- }
1384
- const l = Ye(i.$headCell, e, t);
1385
- return l ? ae(
1386
- n,
1387
- o,
1388
- new b(i.$anchorCell, l)
1389
- ) : !1;
1390
- };
1391
- }
1392
- function cn(e, t) {
1393
- const n = e.state.doc, o = Y(n.resolve(t));
1394
- return o ? (e.dispatch(e.state.tr.setSelection(new b(o))), !0) : !1;
1395
- }
1396
- function dn(e, t, n) {
1397
- if (!I(e.state)) return !1;
1398
- let o = on(n);
1399
- const s = e.state.selection;
1400
- if (s instanceof b) {
1401
- o || (o = {
1402
- width: 1,
1403
- height: 1,
1404
- rows: [
1405
- H.from(
1406
- Ae(S(e.state.schema).cell, n)
1407
- )
1408
- ]
1409
- });
1410
- const r = s.$anchorCell.node(-1), i = s.$anchorCell.start(-1), l = C.get(r).rectBetween(
1411
- s.$anchorCell.pos - i,
1412
- s.$headCell.pos - i
1413
- );
1414
- return o = rn(o, l.right - l.left, l.bottom - l.top), $e(e.state, e.dispatch, i, l, o), !0;
1415
- } else if (o) {
1416
- const r = he(e.state), i = r.start(-1);
1417
- return $e(
1418
- e.state,
1419
- e.dispatch,
1420
- i,
1421
- C.get(r.node(-1)).findCell(r.pos - i),
1422
- o
1423
- ), !0;
1424
- } else
1425
- return !1;
1426
- }
1427
- function un(e, t) {
1428
- var n;
1429
- if (t.ctrlKey || t.metaKey) return;
1430
- const o = Oe(e, t.target);
1431
- let s;
1432
- if (t.shiftKey && e.state.selection instanceof b)
1433
- r(e.state.selection.$anchorCell, t), t.preventDefault();
1434
- else if (t.shiftKey && o && (s = Y(e.state.selection.$anchor)) != null && ((n = me(e, t)) == null ? void 0 : n.pos) != s.pos)
1435
- r(s, t), t.preventDefault();
1436
- else if (!o)
1437
- return;
1438
- function r(a, c) {
1439
- let u = me(e, c);
1440
- const d = B.getState(e.state) == null;
1441
- if (!u || !Se(a, u))
1442
- if (d) u = a;
1443
- else return;
1444
- const p = new b(a, u);
1445
- if (d || !e.state.selection.eq(p)) {
1446
- const h = e.state.tr.setSelection(p);
1447
- d && h.setMeta(B, a.pos), e.dispatch(h);
1448
- }
1449
- }
1450
- function i() {
1451
- e.root.removeEventListener("mouseup", i), e.root.removeEventListener("dragstart", i), e.root.removeEventListener("mousemove", l), B.getState(e.state) != null && e.dispatch(e.state.tr.setMeta(B, -1));
1452
- }
1453
- function l(a) {
1454
- const c = a, u = B.getState(e.state);
1455
- let d;
1456
- if (u != null)
1457
- d = e.state.doc.resolve(u);
1458
- else if (Oe(e, c.target) != o && (d = me(e, t), !d))
1459
- return i();
1460
- d && r(d, c);
1461
- }
1462
- e.root.addEventListener("mouseup", i), e.root.addEventListener("dragstart", i), e.root.addEventListener("mousemove", l);
1463
- }
1464
- function st(e, t, n) {
1465
- if (!(e.state.selection instanceof x)) return null;
1466
- const { $head: o } = e.state.selection;
1467
- for (let s = o.depth - 1; s >= 0; s--) {
1468
- const r = o.node(s);
1469
- if ((n < 0 ? o.index(s) : o.indexAfter(s)) != (n < 0 ? 0 : r.childCount)) return null;
1470
- if (r.type.spec.tableRole == "cell" || r.type.spec.tableRole == "header_cell") {
1471
- const l = o.before(s), a = t == "vert" ? n > 0 ? "down" : "up" : n > 0 ? "right" : "left";
1472
- return e.endOfTextblock(a) ? l : null;
1473
- }
1474
- }
1475
- return null;
1476
- }
1477
- function Oe(e, t) {
1478
- for (; t && t != e.dom; t = t.parentNode)
1479
- if (t.nodeName == "TD" || t.nodeName == "TH")
1480
- return t;
1481
- return null;
1482
- }
1483
- function me(e, t) {
1484
- const n = e.posAtCoords({
1485
- left: t.clientX,
1486
- top: t.clientY
1487
- });
1488
- return n && n ? Y(e.state.doc.resolve(n.pos)) : null;
1489
- }
1490
- var pn = class {
1491
- constructor(t, n) {
1492
- this.node = t, this.defaultCellMinWidth = n, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), this.table.style.setProperty(
1493
- "--default-cell-min-width",
1494
- `${n}px`
1495
- ), this.colgroup = this.table.appendChild(document.createElement("colgroup")), ke(t, this.colgroup, this.table, n), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1496
- }
1497
- update(t) {
1498
- return t.type != this.node.type ? !1 : (this.node = t, ke(
1499
- t,
1500
- this.colgroup,
1501
- this.table,
1502
- this.defaultCellMinWidth
1503
- ), !0);
1504
- }
1505
- ignoreMutation(t) {
1506
- return t.type == "attributes" && (t.target == this.table || this.colgroup.contains(t.target));
1507
- }
1508
- };
1509
- function ke(e, t, n, o, s, r) {
1510
- var i;
1511
- let l = 0, a = !0, c = t.firstChild;
1512
- const u = e.firstChild;
1513
- if (u) {
1514
- for (let d = 0, p = 0; d < u.childCount; d++) {
1515
- const { colspan: h, colwidth: f } = u.child(d).attrs;
1516
- for (let m = 0; m < h; m++, p++) {
1517
- const g = s == p ? r : f && f[m], w = g ? g + "px" : "";
1518
- if (l += g || o, g || (a = !1), c)
1519
- c.style.width != w && (c.style.width = w), c = c.nextSibling;
1520
- else {
1521
- const R = document.createElement("col");
1522
- R.style.width = w, t.appendChild(R);
1523
- }
1524
- }
1525
- }
1526
- for (; c; ) {
1527
- const d = c.nextSibling;
1528
- (i = c.parentNode) == null || i.removeChild(c), c = d;
1529
- }
1530
- a ? (n.style.width = l + "px", n.style.minWidth = "") : (n.style.width = "", n.style.minWidth = l + "px");
1531
- }
1532
- }
1533
- var L = new W(
1534
- "tableColumnResizing"
1535
- );
1536
- function hn({
1537
- handleWidth: e = 5,
1538
- cellMinWidth: t = 25,
1539
- defaultCellMinWidth: n = 100,
1540
- View: o = pn,
1541
- lastColumnResizable: s = !0
1542
- } = {}) {
1543
- const r = new _({
1544
- key: L,
1545
- state: {
1546
- init(i, l) {
1547
- var a, c;
1548
- const u = (c = (a = r.spec) == null ? void 0 : a.props) == null ? void 0 : c.nodeViews, d = S(l.schema).table.name;
1549
- return o && u && (u[d] = (p, h) => new o(p, n, h)), new fn(-1, !1);
1550
- },
1551
- apply(i, l) {
1552
- return l.apply(i);
1553
- }
1554
- },
1555
- props: {
1556
- attributes: (i) => {
1557
- const l = L.getState(i);
1558
- return l && l.activeHandle > -1 ? { class: "resize-cursor" } : {};
1559
- },
1560
- handleDOMEvents: {
1561
- mousemove: (i, l) => {
1562
- mn(i, l, e, s);
1563
- },
1564
- mouseleave: (i) => {
1565
- gn(i);
1566
- },
1567
- mousedown: (i, l) => {
1568
- bn(i, l, t, n);
1569
- }
1570
- },
1571
- decorations: (i) => {
1572
- const l = L.getState(i);
1573
- if (l && l.activeHandle > -1)
1574
- return An(i, l.activeHandle);
1575
- },
1576
- nodeViews: {}
1577
- }
1578
- });
1579
- return r;
1580
- }
1581
- var fn = class ce {
1582
- constructor(t, n) {
1583
- this.activeHandle = t, this.dragging = n;
1584
- }
1585
- apply(t) {
1586
- const n = this, o = t.getMeta(L);
1587
- if (o && o.setHandle != null)
1588
- return new ce(o.setHandle, !1);
1589
- if (o && o.setDragging !== void 0)
1590
- return new ce(n.activeHandle, o.setDragging);
1591
- if (n.activeHandle > -1 && t.docChanged) {
1592
- let s = t.mapping.map(n.activeHandle, -1);
1593
- return Me(t.doc.resolve(s)) || (s = -1), new ce(s, n.dragging);
1594
- }
1595
- return n;
1596
- }
1597
- };
1598
- function mn(e, t, n, o) {
1599
- if (!e.editable) return;
1600
- const s = L.getState(e.state);
1601
- if (s && !s.dragging) {
1602
- const r = yn(t.target);
1603
- let i = -1;
1604
- if (r) {
1605
- const { left: l, right: a } = r.getBoundingClientRect();
1606
- t.clientX - l <= n ? i = ze(e, t, "left", n) : a - t.clientX <= n && (i = ze(e, t, "right", n));
1607
- }
1608
- if (i != s.activeHandle) {
1609
- if (!o && i !== -1) {
1610
- const l = e.state.doc.resolve(i), a = l.node(-1), c = C.get(a), u = l.start(-1);
1611
- if (c.colCount(l.pos - u) + l.nodeAfter.attrs.colspan - 1 == c.width - 1)
1612
- return;
1613
- }
1614
- rt(e, i);
1615
- }
1616
- }
1617
- }
1618
- function gn(e) {
1619
- if (!e.editable) return;
1620
- const t = L.getState(e.state);
1621
- t && t.activeHandle > -1 && !t.dragging && rt(e, -1);
1622
- }
1623
- function bn(e, t, n, o) {
1624
- var s;
1625
- if (!e.editable) return !1;
1626
- const r = (s = e.dom.ownerDocument.defaultView) != null ? s : window, i = L.getState(e.state);
1627
- if (!i || i.activeHandle == -1 || i.dragging)
1628
- return !1;
1629
- const l = e.state.doc.nodeAt(i.activeHandle), a = wn(e, i.activeHandle, l.attrs);
1630
- e.dispatch(
1631
- e.state.tr.setMeta(L, {
1632
- setDragging: { startX: t.clientX, startWidth: a }
1633
- })
1634
- );
1635
- function c(d) {
1636
- r.removeEventListener("mouseup", c), r.removeEventListener("mousemove", u);
1637
- const p = L.getState(e.state);
1638
- p != null && p.dragging && (Cn(
1639
- e,
1640
- p.activeHandle,
1641
- Pe(p.dragging, d, n)
1642
- ), e.dispatch(
1643
- e.state.tr.setMeta(L, { setDragging: null })
1644
- ));
1645
- }
1646
- function u(d) {
1647
- if (!d.which) return c(d);
1648
- const p = L.getState(e.state);
1649
- if (p && p.dragging) {
1650
- const h = Pe(p.dragging, d, n);
1651
- De(
1652
- e,
1653
- p.activeHandle,
1654
- h,
1655
- o
1656
- );
1657
- }
1658
- }
1659
- return De(
1660
- e,
1661
- i.activeHandle,
1662
- a,
1663
- o
1664
- ), r.addEventListener("mouseup", c), r.addEventListener("mousemove", u), t.preventDefault(), !0;
1665
- }
1666
- function wn(e, t, { colspan: n, colwidth: o }) {
1667
- const s = o && o[o.length - 1];
1668
- if (s) return s;
1669
- const r = e.domAtPos(t);
1670
- let l = r.node.childNodes[r.offset].offsetWidth, a = n;
1671
- if (o)
1672
- for (let c = 0; c < n; c++)
1673
- o[c] && (l -= o[c], a--);
1674
- return l / a;
1675
- }
1676
- function yn(e) {
1677
- for (; e && e.nodeName != "TD" && e.nodeName != "TH"; )
1678
- e = e.classList && e.classList.contains("ProseMirror") ? null : e.parentNode;
1679
- return e;
1680
- }
1681
- function ze(e, t, n, o) {
1682
- const s = n == "right" ? -o : o, r = e.posAtCoords({
1683
- left: t.clientX + s,
1684
- top: t.clientY
1685
- });
1686
- if (!r) return -1;
1687
- const { pos: i } = r, l = Y(e.state.doc.resolve(i));
1688
- if (!l) return -1;
1689
- if (n == "right") return l.pos;
1690
- const a = C.get(l.node(-1)), c = l.start(-1), u = a.map.indexOf(l.pos - c);
1691
- return u % a.width == 0 ? -1 : c + a.map[u - 1];
1692
- }
1693
- function Pe(e, t, n) {
1694
- const o = t.clientX - e.startX;
1695
- return Math.max(n, e.startWidth + o);
1696
- }
1697
- function rt(e, t) {
1698
- e.dispatch(
1699
- e.state.tr.setMeta(L, { setHandle: t })
1700
- );
1701
- }
1702
- function Cn(e, t, n) {
1703
- const o = e.state.doc.resolve(t), s = o.node(-1), r = C.get(s), i = o.start(-1), l = r.colCount(o.pos - i) + o.nodeAfter.attrs.colspan - 1, a = e.state.tr;
1704
- for (let c = 0; c < r.height; c++) {
1705
- const u = c * r.width + l;
1706
- if (c && r.map[u] == r.map[u - r.width]) continue;
1707
- const d = r.map[u], p = s.nodeAt(d).attrs, h = p.colspan == 1 ? 0 : l - r.colCount(d);
1708
- if (p.colwidth && p.colwidth[h] == n) continue;
1709
- const f = p.colwidth ? p.colwidth.slice() : Mn(p.colspan);
1710
- f[h] = n, a.setNodeMarkup(i + d, null, { ...p, colwidth: f });
1711
- }
1712
- a.docChanged && e.dispatch(a);
1713
- }
1714
- function De(e, t, n, o) {
1715
- const s = e.state.doc.resolve(t), r = s.node(-1), i = s.start(-1), l = C.get(r).colCount(s.pos - i) + s.nodeAfter.attrs.colspan - 1;
1716
- let a = e.domAtPos(s.start(-1)).node;
1717
- for (; a && a.nodeName != "TABLE"; )
1718
- a = a.parentNode;
1719
- a && ke(
1720
- r,
1721
- a.firstChild,
1722
- a,
1723
- o,
1724
- l,
1725
- n
1726
- );
1727
- }
1728
- function Mn(e) {
1729
- return Array(e).fill(0);
1730
- }
1731
- function An(e, t) {
1732
- var n;
1733
- const o = [], s = e.doc.resolve(t), r = s.node(-1);
1734
- if (!r)
1735
- return K.empty;
1736
- const i = C.get(r), l = s.start(-1), a = i.colCount(s.pos - l) + s.nodeAfter.attrs.colspan - 1;
1737
- for (let c = 0; c < i.height; c++) {
1738
- const u = a + c * i.width;
1739
- if ((a == i.width - 1 || i.map[u] != i.map[u + 1]) && (c == 0 || i.map[u] != i.map[u - i.width])) {
1740
- const d = i.map[u], p = l + d + r.nodeAt(d).nodeSize - 1, h = document.createElement("div");
1741
- h.className = "column-resize-handle", (n = L.getState(e)) != null && n.dragging && o.push(
1742
- G.node(
1743
- l + d,
1744
- l + d + r.nodeAt(d).nodeSize,
1745
- {
1746
- class: "column-resize-dragging"
1747
- }
1748
- )
1749
- ), o.push(G.widget(p, h));
1750
- }
1751
- }
1752
- return K.create(e.doc, o);
1753
- }
1754
- function kn({
1755
- allowTableNodeSelection: e = !1
1756
- } = {}) {
1757
- return new _({
1758
- key: B,
1759
- // This piece of state is used to remember when a mouse-drag
1760
- // cell-selection is happening, so that it can continue even as
1761
- // transactions (which might move its anchor cell) come in.
1762
- state: {
1763
- init() {
1764
- return null;
1765
- },
1766
- apply(t, n) {
1767
- const o = t.getMeta(B);
1768
- if (o != null) return o == -1 ? null : o;
1769
- if (n == null || !t.docChanged) return n;
1770
- const { deleted: s, pos: r } = t.mapping.mapResult(n);
1771
- return s ? null : r;
1772
- }
1773
- },
1774
- props: {
1775
- decorations: Ot,
1776
- handleDOMEvents: {
1777
- mousedown: un
1778
- },
1779
- createSelectionBetween(t) {
1780
- return B.getState(t.state) != null ? t.state.selection : null;
1781
- },
1782
- handleTripleClick: cn,
1783
- handleKeyDown: an,
1784
- handlePaste: dn
1785
- },
1786
- appendTransaction(t, n, o) {
1787
- return Dt(
1788
- o,
1789
- tt(o, n),
1790
- e
1791
- );
1792
- }
1793
- });
1794
- }
1795
- function Te(e, t) {
1796
- return t ? ["width", `${Math.max(t, e)}px`] : ["min-width", `${e}px`];
1797
- }
1798
- function Be(e, t, n, o, s, r) {
1799
- var i;
1800
- let l = 0, a = !0, c = t.firstChild;
1801
- const u = e.firstChild;
1802
- if (u !== null)
1803
- for (let d = 0, p = 0; d < u.childCount; d += 1) {
1804
- const { colspan: h, colwidth: f } = u.child(d).attrs;
1805
- for (let m = 0; m < h; m += 1, p += 1) {
1806
- const g = s === p ? r : f && f[m], w = g ? `${g}px` : "";
1807
- if (l += g || o, g || (a = !1), c) {
1808
- if (c.style.width !== w) {
1809
- const [R, z] = Te(o, g);
1810
- c.style.setProperty(R, z);
1811
- }
1812
- c = c.nextSibling;
1813
- } else {
1814
- const R = document.createElement("col"), [z, U] = Te(o, g);
1815
- R.style.setProperty(z, U), t.appendChild(R);
1816
- }
1817
- }
1818
- }
1819
- for (; c; ) {
1820
- const d = c.nextSibling;
1821
- (i = c.parentNode) === null || i === void 0 || i.removeChild(c), c = d;
1822
- }
1823
- a ? (n.style.width = `${l}px`, n.style.minWidth = "") : (n.style.width = "", n.style.minWidth = `${l}px`);
1824
- }
1825
- class Tn {
1826
- constructor(t, n) {
1827
- this.node = t, this.cellMinWidth = n, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), this.colgroup = this.table.appendChild(document.createElement("colgroup")), Be(t, this.colgroup, this.table, n), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1828
- }
1829
- update(t) {
1830
- return t.type !== this.node.type ? !1 : (this.node = t, Be(t, this.colgroup, this.table, this.cellMinWidth), !0);
1831
- }
1832
- ignoreMutation(t) {
1833
- return t.type === "attributes" && (t.target === this.table || this.colgroup.contains(t.target));
1834
- }
1835
- }
1836
- function Sn(e, t, n, o) {
1837
- let s = 0, r = !0;
1838
- const i = [], l = e.firstChild;
1839
- if (!l)
1840
- return {};
1841
- for (let d = 0, p = 0; d < l.childCount; d += 1) {
1842
- const { colspan: h, colwidth: f } = l.child(d).attrs;
1843
- for (let m = 0; m < h; m += 1, p += 1) {
1844
- const g = n === p ? o : f && f[m];
1845
- s += g || t, g || (r = !1);
1846
- const [w, R] = Te(t, g);
1847
- i.push([
1848
- "col",
1849
- { style: `${w}: ${R}` }
1850
- ]);
1851
- }
1852
- }
1853
- const a = r ? `${s}px` : "", c = r ? "" : `${s}px`;
1854
- return { colgroup: ["colgroup", {}, ...i], tableWidth: a, tableMinWidth: c };
1855
- }
1856
- function _e(e, t) {
1857
- return e.createAndFill();
1858
- }
1859
- function vn(e) {
1860
- if (e.cached.tableNodeTypes)
1861
- return e.cached.tableNodeTypes;
1862
- const t = {};
1863
- return Object.keys(e.nodes).forEach((n) => {
1864
- const o = e.nodes[n];
1865
- o.spec.tableRole && (t[o.spec.tableRole] = o);
1866
- }), e.cached.tableNodeTypes = t, t;
1867
- }
1868
- function xn(e, t, n, o, s) {
1869
- const r = vn(e), i = [], l = [];
1870
- for (let c = 0; c < n; c += 1) {
1871
- const u = _e(r.cell);
1872
- if (u && l.push(u), o) {
1873
- const d = _e(r.header_cell);
1874
- d && i.push(d);
1875
- }
1876
- }
1877
- const a = [];
1878
- for (let c = 0; c < t; c += 1)
1879
- a.push(r.row.createChecked(null, o && c === 0 ? i : l));
1880
- return r.table.createChecked(null, a);
1881
- }
1882
- function Ln(e) {
1883
- return e instanceof b;
1884
- }
1885
- const ie = ({ editor: e }) => {
1886
- const { selection: t } = e.state;
1887
- if (!Ln(t))
1888
- return !1;
1889
- let n = 0;
1890
- const o = ht(t.ranges[0].$from, (r) => r.type.name === "table");
1891
- return o == null || o.node.descendants((r) => {
1892
- if (r.type.name === "table")
1893
- return !1;
1894
- ["tableCell", "tableHeader"].includes(r.type.name) && (n += 1);
1895
- }), n === t.ranges.length ? (e.commands.deleteTable(), !0) : !1;
1896
- }, Rn = T.create({
1897
- name: "table",
1898
- // @ts-ignore
1899
- addOptions() {
1900
- return {
1901
- HTMLAttributes: {},
1902
- resizable: !1,
1903
- handleWidth: 5,
1904
- cellMinWidth: 25,
1905
- // TODO: fix
1906
- View: Tn,
1907
- lastColumnResizable: !0,
1908
- allowTableNodeSelection: !1
1909
- };
1910
- },
1911
- content: "tableRow+",
1912
- tableRole: "table",
1913
- isolating: !0,
1914
- group: "block",
1915
- parseHTML() {
1916
- return [{ tag: "table" }];
1917
- },
1918
- renderHTML({ node: e, HTMLAttributes: t }) {
1919
- const { colgroup: n, tableWidth: o, tableMinWidth: s } = Sn(e, this.options.cellMinWidth);
1920
- return [
1921
- "table",
1922
- M(this.options.HTMLAttributes, t, {
1923
- style: o ? `width: ${o}` : `min-width: ${s}`
1924
- }),
1925
- n,
1926
- ["tbody", 0]
1927
- ];
1928
- },
1929
- addCommands() {
1930
- return {
1931
- insertTable: ({ rows: e = 3, cols: t = 3, withHeaderRow: n = !0 } = {}) => ({ tr: o, dispatch: s, editor: r }) => {
1932
- const i = xn(r.schema, e, t, n);
1933
- if (s) {
1934
- const l = o.selection.from + 1;
1935
- o.replaceSelectionWith(i).scrollIntoView().setSelection(x.near(o.doc.resolve(l)));
1936
- }
1937
- return !0;
1938
- },
1939
- addColumnBefore: () => ({ state: e, dispatch: t }) => Wt(e, t),
1940
- addColumnAfter: () => ({ state: e, dispatch: t }) => Vt(e, t),
1941
- deleteColumn: () => ({ state: e, dispatch: t }) => Kt(e, t),
1942
- addRowBefore: () => ({ state: e, dispatch: t }) => Qt(e, t),
1943
- addRowAfter: () => ({ state: e, dispatch: t }) => qt(e, t),
1944
- deleteRow: () => ({ state: e, dispatch: t }) => Gt(e, t),
1945
- deleteTable: () => ({ state: e, dispatch: t }) => nn(e, t),
1946
- mergeCells: () => ({ state: e, dispatch: t }) => Le(e, t),
1947
- splitCell: () => ({ state: e, dispatch: t }) => Re(e, t),
1948
- toggleHeaderColumn: () => ({ state: e, dispatch: t }) => ee("column")(e, t),
1949
- toggleHeaderRow: () => ({ state: e, dispatch: t }) => ee("row")(e, t),
1950
- toggleHeaderCell: () => ({ state: e, dispatch: t }) => en(e, t),
1951
- mergeOrSplit: () => ({ state: e, dispatch: t }) => Le(e, t) ? !0 : Re(e, t),
1952
- setCellAttribute: (e, t) => ({ state: n, dispatch: o }) => Ut(e, t)(n, o),
1953
- goToNextCell: () => ({ state: e, dispatch: t }) => Ee(1)(e, t),
1954
- goToPreviousCell: () => ({ state: e, dispatch: t }) => Ee(-1)(e, t),
1955
- fixTables: () => ({ state: e, dispatch: t }) => (t && tt(e), !0),
1956
- setCellSelection: (e) => ({ tr: t, dispatch: n }) => {
1957
- if (n) {
1958
- const o = b.create(t.doc, e.anchorCell, e.headCell);
1959
- t.setSelection(o);
1960
- }
1961
- return !0;
1962
- }
1963
- };
1964
- },
1965
- addKeyboardShortcuts() {
1966
- return {
1967
- Tab: () => this.editor.commands.goToNextCell() ? !0 : this.editor.can().addRowAfter() ? this.editor.chain().addRowAfter().goToNextCell().run() : !1,
1968
- "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
1969
- Backspace: ie,
1970
- "Mod-Backspace": ie,
1971
- Delete: ie,
1972
- "Mod-Delete": ie
1973
- };
1974
- },
1975
- addProseMirrorPlugins() {
1976
- return [
1977
- ...this.options.resizable && this.editor.isEditable ? [
1978
- hn({
1979
- handleWidth: this.options.handleWidth,
1980
- cellMinWidth: this.options.cellMinWidth,
1981
- defaultCellMinWidth: this.options.cellMinWidth,
1982
- View: this.options.View,
1983
- lastColumnResizable: this.options.lastColumnResizable
1984
- })
1985
- ] : [],
1986
- kn({
1987
- allowTableNodeSelection: this.options.allowTableNodeSelection
1988
- })
1989
- ];
1990
- },
1991
- extendNodeSchema(e) {
1992
- const t = {
1993
- name: e.name,
1994
- options: e.options,
1995
- storage: e.storage
1996
- };
1997
- return {
1998
- tableRole: Ge(Je(e, "tableRole", t))
1999
- };
2000
- }
2001
- }), Hn = /^\s*>\s$/, En = T.create({
2002
- name: "blockquote",
2003
- addOptions() {
2004
- return {
2005
- HTMLAttributes: {}
2006
- };
2007
- },
2008
- content: "block+",
2009
- group: "block",
2010
- defining: !0,
2011
- parseHTML() {
2012
- return [
2013
- { tag: "blockquote" }
2014
- ];
2015
- },
2016
- renderHTML({ HTMLAttributes: e }) {
2017
- return ["blockquote", M(this.options.HTMLAttributes, e), 0];
2018
- },
2019
- addCommands() {
2020
- return {
2021
- setBlockquote: () => ({ commands: e }) => e.wrapIn(this.name),
2022
- toggleBlockquote: () => ({ commands: e }) => e.toggleWrap(this.name),
2023
- unsetBlockquote: () => ({ commands: e }) => e.lift(this.name)
2024
- };
2025
- },
2026
- addKeyboardShortcuts() {
2027
- return {
2028
- "Mod-Shift-b": () => this.editor.commands.toggleBlockquote()
2029
- };
2030
- },
2031
- addInputRules() {
2032
- return [
2033
- J({
2034
- find: Hn,
2035
- type: this.type
2036
- })
2037
- ];
2038
- }
2039
- }), In = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/, Nn = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g, $n = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/, On = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g, zn = te.create({
2040
- name: "bold",
2041
- addOptions() {
2042
- return {
2043
- HTMLAttributes: {}
2044
- };
2045
- },
2046
- parseHTML() {
2047
- return [
2048
- {
2049
- tag: "strong"
2050
- },
2051
- {
2052
- tag: "b",
2053
- getAttrs: (e) => e.style.fontWeight !== "normal" && null
2054
- },
2055
- {
2056
- style: "font-weight=400",
2057
- clearMark: (e) => e.type.name === this.name
2058
- },
2059
- {
2060
- style: "font-weight",
2061
- getAttrs: (e) => /^(bold(er)?|[5-9]\d{2,})$/.test(e) && null
2062
- }
2063
- ];
2064
- },
2065
- renderHTML({ HTMLAttributes: e }) {
2066
- return ["strong", M(this.options.HTMLAttributes, e), 0];
2067
- },
2068
- addCommands() {
2069
- return {
2070
- setBold: () => ({ commands: e }) => e.setMark(this.name),
2071
- toggleBold: () => ({ commands: e }) => e.toggleMark(this.name),
2072
- unsetBold: () => ({ commands: e }) => e.unsetMark(this.name)
2073
- };
2074
- },
2075
- addKeyboardShortcuts() {
2076
- return {
2077
- "Mod-b": () => this.editor.commands.toggleBold(),
2078
- "Mod-B": () => this.editor.commands.toggleBold()
2079
- };
2080
- },
2081
- addInputRules() {
2082
- return [
2083
- Q({
2084
- find: In,
2085
- type: this.type
2086
- }),
2087
- Q({
2088
- find: $n,
2089
- type: this.type
2090
- })
2091
- ];
2092
- },
2093
- addPasteRules() {
2094
- return [
2095
- j({
2096
- find: Nn,
2097
- type: this.type
2098
- }),
2099
- j({
2100
- find: On,
2101
- type: this.type
2102
- })
2103
- ];
2104
- }
2105
- }), Pn = "listItem", We = "textStyle", Ve = /^\s*([-+*])\s$/, Dn = T.create({
2106
- name: "bulletList",
2107
- addOptions() {
2108
- return {
2109
- itemTypeName: "listItem",
2110
- HTMLAttributes: {},
2111
- keepMarks: !1,
2112
- keepAttributes: !1
2113
- };
2114
- },
2115
- group: "block list",
2116
- content() {
2117
- return `${this.options.itemTypeName}+`;
2118
- },
2119
- parseHTML() {
2120
- return [
2121
- { tag: "ul" }
2122
- ];
2123
- },
2124
- renderHTML({ HTMLAttributes: e }) {
2125
- return ["ul", M(this.options.HTMLAttributes, e), 0];
2126
- },
2127
- addCommands() {
2128
- return {
2129
- toggleBulletList: () => ({ commands: e, chain: t }) => this.options.keepAttributes ? t().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(Pn, this.editor.getAttributes(We)).run() : e.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
2130
- };
2131
- },
2132
- addKeyboardShortcuts() {
2133
- return {
2134
- "Mod-Shift-8": () => this.editor.commands.toggleBulletList()
2135
- };
2136
- },
2137
- addInputRules() {
2138
- let e = J({
2139
- find: Ve,
2140
- type: this.type
2141
- });
2142
- return (this.options.keepMarks || this.options.keepAttributes) && (e = J({
2143
- find: Ve,
2144
- type: this.type,
2145
- keepMarks: this.options.keepMarks,
2146
- keepAttributes: this.options.keepAttributes,
2147
- getAttributes: () => this.editor.getAttributes(We),
2148
- editor: this.editor
2149
- })), [
2150
- e
2151
- ];
2152
- }
2153
- }), Bn = /(^|[^`])`([^`]+)`(?!`)/, _n = /(^|[^`])`([^`]+)`(?!`)/g, Wn = te.create({
2154
- name: "code",
2155
- addOptions() {
2156
- return {
2157
- HTMLAttributes: {}
2158
- };
2159
- },
2160
- excludes: "_",
2161
- code: !0,
2162
- exitable: !0,
2163
- parseHTML() {
2164
- return [
2165
- { tag: "code" }
2166
- ];
2167
- },
2168
- renderHTML({ HTMLAttributes: e }) {
2169
- return ["code", M(this.options.HTMLAttributes, e), 0];
2170
- },
2171
- addCommands() {
2172
- return {
2173
- setCode: () => ({ commands: e }) => e.setMark(this.name),
2174
- toggleCode: () => ({ commands: e }) => e.toggleMark(this.name),
2175
- unsetCode: () => ({ commands: e }) => e.unsetMark(this.name)
2176
- };
2177
- },
2178
- addKeyboardShortcuts() {
2179
- return {
2180
- "Mod-e": () => this.editor.commands.toggleCode()
2181
- };
2182
- },
2183
- addInputRules() {
2184
- return [
2185
- Q({
2186
- find: Bn,
2187
- type: this.type
2188
- })
2189
- ];
2190
- },
2191
- addPasteRules() {
2192
- return [
2193
- j({
2194
- find: _n,
2195
- type: this.type
2196
- })
2197
- ];
2198
- }
2199
- }), Vn = /^```([a-z]+)?[\s\n]$/, Fn = /^~~~([a-z]+)?[\s\n]$/, Kn = T.create({
2200
- name: "codeBlock",
2201
- addOptions() {
2202
- return {
2203
- languageClassPrefix: "language-",
2204
- exitOnTripleEnter: !0,
2205
- exitOnArrowDown: !0,
2206
- defaultLanguage: null,
2207
- HTMLAttributes: {}
2208
- };
2209
- },
2210
- content: "text*",
2211
- marks: "",
2212
- group: "block",
2213
- code: !0,
2214
- defining: !0,
2215
- addAttributes() {
2216
- return {
2217
- language: {
2218
- default: this.options.defaultLanguage,
2219
- parseHTML: (e) => {
2220
- var t;
2221
- const { languageClassPrefix: n } = this.options, r = [...((t = e.firstElementChild) === null || t === void 0 ? void 0 : t.classList) || []].filter((i) => i.startsWith(n)).map((i) => i.replace(n, ""))[0];
2222
- return r || null;
2223
- },
2224
- rendered: !1
2225
- }
2226
- };
2227
- },
2228
- parseHTML() {
2229
- return [
2230
- {
2231
- tag: "pre",
2232
- preserveWhitespace: "full"
2233
- }
2234
- ];
2235
- },
2236
- renderHTML({ node: e, HTMLAttributes: t }) {
2237
- return [
2238
- "pre",
2239
- M(this.options.HTMLAttributes, t),
2240
- [
2241
- "code",
2242
- {
2243
- class: e.attrs.language ? this.options.languageClassPrefix + e.attrs.language : null
2244
- },
2245
- 0
2246
- ]
2247
- ];
2248
- },
2249
- addCommands() {
2250
- return {
2251
- setCodeBlock: (e) => ({ commands: t }) => t.setNode(this.name, e),
2252
- toggleCodeBlock: (e) => ({ commands: t }) => t.toggleNode(this.name, "paragraph", e)
2253
- };
2254
- },
2255
- addKeyboardShortcuts() {
2256
- return {
2257
- "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
2258
- // remove code block when at start of document or code block is empty
2259
- Backspace: () => {
2260
- const { empty: e, $anchor: t } = this.editor.state.selection, n = t.pos === 1;
2261
- return !e || t.parent.type.name !== this.name ? !1 : n || !t.parent.textContent.length ? this.editor.commands.clearNodes() : !1;
2262
- },
2263
- // exit node on triple enter
2264
- Enter: ({ editor: e }) => {
2265
- if (!this.options.exitOnTripleEnter)
2266
- return !1;
2267
- const { state: t } = e, { selection: n } = t, { $from: o, empty: s } = n;
2268
- if (!s || o.parent.type !== this.type)
2269
- return !1;
2270
- const r = o.parentOffset === o.parent.nodeSize - 2, i = o.parent.textContent.endsWith(`
2271
-
2272
- `);
2273
- return !r || !i ? !1 : e.chain().command(({ tr: l }) => (l.delete(o.pos - 2, o.pos), !0)).exitCode().run();
2274
- },
2275
- // exit node on arrow down
2276
- ArrowDown: ({ editor: e }) => {
2277
- if (!this.options.exitOnArrowDown)
2278
- return !1;
2279
- const { state: t } = e, { selection: n, doc: o } = t, { $from: s, empty: r } = n;
2280
- if (!r || s.parent.type !== this.type || !(s.parentOffset === s.parent.nodeSize - 2))
2281
- return !1;
2282
- const l = s.after();
2283
- return l === void 0 ? !1 : o.nodeAt(l) ? e.commands.command(({ tr: c }) => (c.setSelection(v.near(o.resolve(l))), !0)) : e.commands.exitCode();
2284
- }
2285
- };
2286
- },
2287
- addInputRules() {
2288
- return [
2289
- we({
2290
- find: Vn,
2291
- type: this.type,
2292
- getAttributes: (e) => ({
2293
- language: e[1]
2294
- })
2295
- }),
2296
- we({
2297
- find: Fn,
2298
- type: this.type,
2299
- getAttributes: (e) => ({
2300
- language: e[1]
2301
- })
2302
- })
2303
- ];
2304
- },
2305
- addProseMirrorPlugins() {
2306
- return [
2307
- // this plugin creates a code block for pasted content from VS Code
2308
- // we can also detect the copied code language
2309
- new _({
2310
- key: new W("codeBlockVSCodeHandler"),
2311
- props: {
2312
- handlePaste: (e, t) => {
2313
- if (!t.clipboardData || this.editor.isActive(this.type.name))
2314
- return !1;
2315
- const n = t.clipboardData.getData("text/plain"), o = t.clipboardData.getData("vscode-editor-data"), s = o ? JSON.parse(o) : void 0, r = s == null ? void 0 : s.mode;
2316
- if (!n || !r)
2317
- return !1;
2318
- const { tr: i, schema: l } = e.state, a = l.text(n.replace(/\r\n?/g, `
2319
- `));
2320
- return i.replaceSelectionWith(this.type.create({ language: r }, a)), i.selection.$from.parent.type !== this.type && i.setSelection(x.near(i.doc.resolve(Math.max(0, i.selection.from - 2)))), i.setMeta("paste", !0), e.dispatch(i), !0;
2321
- }
2322
- }
2323
- })
2324
- ];
2325
- }
2326
- }), jn = T.create({
2327
- name: "doc",
2328
- topNode: !0,
2329
- content: "block+"
2330
- });
2331
- function Qn(e = {}) {
2332
- return new _({
2333
- view(t) {
2334
- return new qn(t, e);
2335
- }
2336
- });
2337
- }
2338
- class qn {
2339
- constructor(t, n) {
2340
- var o;
2341
- this.editorView = t, this.cursorPos = null, this.element = null, this.timeout = -1, this.width = (o = n.width) !== null && o !== void 0 ? o : 1, this.color = n.color === !1 ? void 0 : n.color || "black", this.class = n.class, this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((s) => {
2342
- let r = (i) => {
2343
- this[s](i);
2344
- };
2345
- return t.dom.addEventListener(s, r), { name: s, handler: r };
2346
- });
2347
- }
2348
- destroy() {
2349
- this.handlers.forEach(({ name: t, handler: n }) => this.editorView.dom.removeEventListener(t, n));
2350
- }
2351
- update(t, n) {
2352
- this.cursorPos != null && n.doc != t.state.doc && (this.cursorPos > t.state.doc.content.size ? this.setCursor(null) : this.updateOverlay());
2353
- }
2354
- setCursor(t) {
2355
- t != this.cursorPos && (this.cursorPos = t, t == null ? (this.element.parentNode.removeChild(this.element), this.element = null) : this.updateOverlay());
2356
- }
2357
- updateOverlay() {
2358
- let t = this.editorView.state.doc.resolve(this.cursorPos), n = !t.parent.inlineContent, o, s = this.editorView.dom, r = s.getBoundingClientRect(), i = r.width / s.offsetWidth, l = r.height / s.offsetHeight;
2359
- if (n) {
2360
- let d = t.nodeBefore, p = t.nodeAfter;
2361
- if (d || p) {
2362
- let h = this.editorView.nodeDOM(this.cursorPos - (d ? d.nodeSize : 0));
2363
- if (h) {
2364
- let f = h.getBoundingClientRect(), m = d ? f.bottom : f.top;
2365
- d && p && (m = (m + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2);
2366
- let g = this.width / 2 * l;
2367
- o = { left: f.left, right: f.right, top: m - g, bottom: m + g };
2368
- }
2369
- }
2370
- }
2371
- if (!o) {
2372
- let d = this.editorView.coordsAtPos(this.cursorPos), p = this.width / 2 * i;
2373
- o = { left: d.left - p, right: d.left + p, top: d.top, bottom: d.bottom };
2374
- }
2375
- let a = this.editorView.dom.offsetParent;
2376
- this.element || (this.element = a.appendChild(document.createElement("div")), this.class && (this.element.className = this.class), this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;", this.color && (this.element.style.backgroundColor = this.color)), this.element.classList.toggle("prosemirror-dropcursor-block", n), this.element.classList.toggle("prosemirror-dropcursor-inline", !n);
2377
- let c, u;
2378
- if (!a || a == document.body && getComputedStyle(a).position == "static")
2379
- c = -pageXOffset, u = -pageYOffset;
2380
- else {
2381
- let d = a.getBoundingClientRect(), p = d.width / a.offsetWidth, h = d.height / a.offsetHeight;
2382
- c = d.left - a.scrollLeft * p, u = d.top - a.scrollTop * h;
2383
- }
2384
- this.element.style.left = (o.left - c) / i + "px", this.element.style.top = (o.top - u) / l + "px", this.element.style.width = (o.right - o.left) / i + "px", this.element.style.height = (o.bottom - o.top) / l + "px";
2385
- }
2386
- scheduleRemoval(t) {
2387
- clearTimeout(this.timeout), this.timeout = setTimeout(() => this.setCursor(null), t);
2388
- }
2389
- dragover(t) {
2390
- if (!this.editorView.editable)
2391
- return;
2392
- let n = this.editorView.posAtCoords({ left: t.clientX, top: t.clientY }), o = n && n.inside >= 0 && this.editorView.state.doc.nodeAt(n.inside), s = o && o.type.spec.disableDropCursor, r = typeof s == "function" ? s(this.editorView, n, t) : s;
2393
- if (n && !r) {
2394
- let i = n.pos;
2395
- if (this.editorView.dragging && this.editorView.dragging.slice) {
2396
- let l = ft(this.editorView.state.doc, i, this.editorView.dragging.slice);
2397
- l != null && (i = l);
2398
- }
2399
- this.setCursor(i), this.scheduleRemoval(5e3);
2400
- }
2401
- }
2402
- dragend() {
2403
- this.scheduleRemoval(20);
2404
- }
2405
- drop() {
2406
- this.scheduleRemoval(20);
2407
- }
2408
- dragleave(t) {
2409
- this.editorView.dom.contains(t.relatedTarget) || this.setCursor(null);
2410
- }
2411
- }
2412
- const Xn = X.create({
2413
- name: "dropCursor",
2414
- addOptions() {
2415
- return {
2416
- color: "currentColor",
2417
- width: 1,
2418
- class: void 0
2419
- };
2420
- },
2421
- addProseMirrorPlugins() {
2422
- return [
2423
- Qn(this.options)
2424
- ];
2425
- }
2426
- });
2427
- class y extends v {
2428
- /**
2429
- Create a gap cursor.
2430
- */
2431
- constructor(t) {
2432
- super(t, t);
2433
- }
2434
- map(t, n) {
2435
- let o = t.resolve(n.map(this.head));
2436
- return y.valid(o) ? new y(o) : v.near(o);
2437
- }
2438
- content() {
2439
- return $.empty;
2440
- }
2441
- eq(t) {
2442
- return t instanceof y && t.head == this.head;
2443
- }
2444
- toJSON() {
2445
- return { type: "gapcursor", pos: this.head };
2446
- }
2447
- /**
2448
- @internal
2449
- */
2450
- static fromJSON(t, n) {
2451
- if (typeof n.pos != "number")
2452
- throw new RangeError("Invalid input for GapCursor.fromJSON");
2453
- return new y(t.resolve(n.pos));
2454
- }
2455
- /**
2456
- @internal
2457
- */
2458
- getBookmark() {
2459
- return new ve(this.anchor);
2460
- }
2461
- /**
2462
- @internal
2463
- */
2464
- static valid(t) {
2465
- let n = t.parent;
2466
- if (n.isTextblock || !Gn(t) || !Jn(t))
2467
- return !1;
2468
- let o = n.type.spec.allowGapCursor;
2469
- if (o != null)
2470
- return o;
2471
- let s = n.contentMatchAt(t.index()).defaultType;
2472
- return s && s.isTextblock;
2473
- }
2474
- /**
2475
- @internal
2476
- */
2477
- static findGapCursorFrom(t, n, o = !1) {
2478
- e: for (; ; ) {
2479
- if (!o && y.valid(t))
2480
- return t;
2481
- let s = t.pos, r = null;
2482
- for (let i = t.depth; ; i--) {
2483
- let l = t.node(i);
2484
- if (n > 0 ? t.indexAfter(i) < l.childCount : t.index(i) > 0) {
2485
- r = l.child(n > 0 ? t.indexAfter(i) : t.index(i) - 1);
2486
- break;
2487
- } else if (i == 0)
2488
- return null;
2489
- s += n;
2490
- let a = t.doc.resolve(s);
2491
- if (y.valid(a))
2492
- return a;
2493
- }
2494
- for (; ; ) {
2495
- let i = n > 0 ? r.firstChild : r.lastChild;
2496
- if (!i) {
2497
- if (r.isAtom && !r.isText && !pe.isSelectable(r)) {
2498
- t = t.doc.resolve(s + r.nodeSize * n), o = !1;
2499
- continue e;
2500
- }
2501
- break;
2502
- }
2503
- r = i, s += n;
2504
- let l = t.doc.resolve(s);
2505
- if (y.valid(l))
2506
- return l;
2507
- }
2508
- return null;
2509
- }
2510
- }
2511
- }
2512
- y.prototype.visible = !1;
2513
- y.findFrom = y.findGapCursorFrom;
2514
- v.jsonID("gapcursor", y);
2515
- class ve {
2516
- constructor(t) {
2517
- this.pos = t;
2518
- }
2519
- map(t) {
2520
- return new ve(t.map(this.pos));
2521
- }
2522
- resolve(t) {
2523
- let n = t.resolve(this.pos);
2524
- return y.valid(n) ? new y(n) : v.near(n);
2525
- }
2526
- }
2527
- function Gn(e) {
2528
- for (let t = e.depth; t >= 0; t--) {
2529
- let n = e.index(t), o = e.node(t);
2530
- if (n == 0) {
2531
- if (o.type.spec.isolating)
2532
- return !0;
2533
- continue;
2534
- }
2535
- for (let s = o.child(n - 1); ; s = s.lastChild) {
2536
- if (s.childCount == 0 && !s.inlineContent || s.isAtom || s.type.spec.isolating)
2537
- return !0;
2538
- if (s.inlineContent)
2539
- return !1;
2540
- }
2541
- }
2542
- return !0;
2543
- }
2544
- function Jn(e) {
2545
- for (let t = e.depth; t >= 0; t--) {
2546
- let n = e.indexAfter(t), o = e.node(t);
2547
- if (n == o.childCount) {
2548
- if (o.type.spec.isolating)
2549
- return !0;
2550
- continue;
2551
- }
2552
- for (let s = o.child(n); ; s = s.firstChild) {
2553
- if (s.childCount == 0 && !s.inlineContent || s.isAtom || s.type.spec.isolating)
2554
- return !0;
2555
- if (s.inlineContent)
2556
- return !1;
2557
- }
2558
- }
2559
- return !0;
2560
- }
2561
- function Yn() {
2562
- return new _({
2563
- props: {
2564
- decorations: to,
2565
- createSelectionBetween(e, t, n) {
2566
- return t.pos == n.pos && y.valid(n) ? new y(n) : null;
2567
- },
2568
- handleClick: Zn,
2569
- handleKeyDown: Un,
2570
- handleDOMEvents: { beforeinput: eo }
2571
- }
2572
- });
2573
- }
2574
- const Un = Xe({
2575
- ArrowLeft: le("horiz", -1),
2576
- ArrowRight: le("horiz", 1),
2577
- ArrowUp: le("vert", -1),
2578
- ArrowDown: le("vert", 1)
2579
- });
2580
- function le(e, t) {
2581
- const n = e == "vert" ? t > 0 ? "down" : "up" : t > 0 ? "right" : "left";
2582
- return function(o, s, r) {
2583
- let i = o.selection, l = t > 0 ? i.$to : i.$from, a = i.empty;
2584
- if (i instanceof x) {
2585
- if (!r.endOfTextblock(n) || l.depth == 0)
2586
- return !1;
2587
- a = !1, l = o.doc.resolve(t > 0 ? l.after() : l.before());
2588
- }
2589
- let c = y.findGapCursorFrom(l, t, a);
2590
- return c ? (s && s(o.tr.setSelection(new y(c))), !0) : !1;
2591
- };
2592
- }
2593
- function Zn(e, t, n) {
2594
- if (!e || !e.editable)
2595
- return !1;
2596
- let o = e.state.doc.resolve(t);
2597
- if (!y.valid(o))
2598
- return !1;
2599
- let s = e.posAtCoords({ left: n.clientX, top: n.clientY });
2600
- return s && s.inside > -1 && pe.isSelectable(e.state.doc.nodeAt(s.inside)) ? !1 : (e.dispatch(e.state.tr.setSelection(new y(o))), !0);
2601
- }
2602
- function eo(e, t) {
2603
- if (t.inputType != "insertCompositionText" || !(e.state.selection instanceof y))
2604
- return !1;
2605
- let { $from: n } = e.state.selection, o = n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);
2606
- if (!o)
2607
- return !1;
2608
- let s = H.empty;
2609
- for (let i = o.length - 1; i >= 0; i--)
2610
- s = H.from(o[i].createAndFill(null, s));
2611
- let r = e.state.tr.replace(n.pos, n.pos, new $(s, 0, 0));
2612
- return r.setSelection(x.near(r.doc.resolve(n.pos + 1))), e.dispatch(r), !1;
2613
- }
2614
- function to(e) {
2615
- if (!(e.selection instanceof y))
2616
- return null;
2617
- let t = document.createElement("div");
2618
- return t.className = "ProseMirror-gapcursor", K.create(e.doc, [G.widget(e.selection.head, t, { key: "gapcursor" })]);
2619
- }
2620
- const no = X.create({
2621
- name: "gapCursor",
2622
- addProseMirrorPlugins() {
2623
- return [
2624
- Yn()
2625
- ];
2626
- },
2627
- extendNodeSchema(e) {
2628
- var t;
2629
- const n = {
2630
- name: e.name,
2631
- options: e.options,
2632
- storage: e.storage
2633
- };
2634
- return {
2635
- allowGapCursor: (t = Ge(Je(e, "allowGapCursor", n))) !== null && t !== void 0 ? t : null
2636
- };
2637
- }
2638
- }), oo = T.create({
2639
- name: "hardBreak",
2640
- addOptions() {
2641
- return {
2642
- keepMarks: !0,
2643
- HTMLAttributes: {}
2644
- };
2645
- },
2646
- inline: !0,
2647
- group: "inline",
2648
- selectable: !1,
2649
- linebreakReplacement: !0,
2650
- parseHTML() {
2651
- return [
2652
- { tag: "br" }
2653
- ];
2654
- },
2655
- renderHTML({ HTMLAttributes: e }) {
2656
- return ["br", M(this.options.HTMLAttributes, e)];
2657
- },
2658
- renderText() {
2659
- return `
2660
- `;
2661
- },
2662
- addCommands() {
2663
- return {
2664
- setHardBreak: () => ({ commands: e, chain: t, state: n, editor: o }) => e.first([
2665
- () => e.exitCode(),
2666
- () => e.command(() => {
2667
- const { selection: s, storedMarks: r } = n;
2668
- if (s.$from.parent.type.spec.isolating)
2669
- return !1;
2670
- const { keepMarks: i } = this.options, { splittableMarks: l } = o.extensionManager, a = r || s.$to.parentOffset && s.$from.marks();
2671
- return t().insertContent({ type: this.name }).command(({ tr: c, dispatch: u }) => {
2672
- if (u && a && i) {
2673
- const d = a.filter((p) => l.includes(p.type.name));
2674
- c.ensureMarks(d);
2675
- }
2676
- return !0;
2677
- }).run();
2678
- })
2679
- ])
2680
- };
2681
- },
2682
- addKeyboardShortcuts() {
2683
- return {
2684
- "Mod-Enter": () => this.editor.commands.setHardBreak(),
2685
- "Shift-Enter": () => this.editor.commands.setHardBreak()
2686
- };
2687
- }
2688
- }), so = T.create({
2689
- name: "heading",
2690
- addOptions() {
2691
- return {
2692
- levels: [1, 2, 3, 4, 5, 6],
2693
- HTMLAttributes: {}
2694
- };
2695
- },
2696
- content: "inline*",
2697
- group: "block",
2698
- defining: !0,
2699
- addAttributes() {
2700
- return {
2701
- level: {
2702
- default: 1,
2703
- rendered: !1
2704
- }
2705
- };
2706
- },
2707
- parseHTML() {
2708
- return this.options.levels.map((e) => ({
2709
- tag: `h${e}`,
2710
- attrs: { level: e }
2711
- }));
2712
- },
2713
- renderHTML({ node: e, HTMLAttributes: t }) {
2714
- return [`h${this.options.levels.includes(e.attrs.level) ? e.attrs.level : this.options.levels[0]}`, M(this.options.HTMLAttributes, t), 0];
2715
- },
2716
- addCommands() {
2717
- return {
2718
- setHeading: (e) => ({ commands: t }) => this.options.levels.includes(e.level) ? t.setNode(this.name, e) : !1,
2719
- toggleHeading: (e) => ({ commands: t }) => this.options.levels.includes(e.level) ? t.toggleNode(this.name, "paragraph", e) : !1
2720
- };
2721
- },
2722
- addKeyboardShortcuts() {
2723
- return this.options.levels.reduce((e, t) => ({
2724
- ...e,
2725
- [`Mod-Alt-${t}`]: () => this.editor.commands.toggleHeading({ level: t })
2726
- }), {});
2727
- },
2728
- addInputRules() {
2729
- return this.options.levels.map((e) => we({
2730
- find: new RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),
2731
- type: this.type,
2732
- getAttributes: {
2733
- level: e
2734
- }
2735
- }));
2736
- }
2737
- });
2738
- var ue = 200, k = function() {
2739
- };
2740
- k.prototype.append = function(t) {
2741
- return t.length ? (t = k.from(t), !this.length && t || t.length < ue && this.leafAppend(t) || this.length < ue && t.leafPrepend(this) || this.appendInner(t)) : this;
2742
- };
2743
- k.prototype.prepend = function(t) {
2744
- return t.length ? k.from(t).append(this) : this;
2745
- };
2746
- k.prototype.appendInner = function(t) {
2747
- return new ro(this, t);
2748
- };
2749
- k.prototype.slice = function(t, n) {
2750
- return t === void 0 && (t = 0), n === void 0 && (n = this.length), t >= n ? k.empty : this.sliceInner(Math.max(0, t), Math.min(this.length, n));
2751
- };
2752
- k.prototype.get = function(t) {
2753
- if (!(t < 0 || t >= this.length))
2754
- return this.getInner(t);
2755
- };
2756
- k.prototype.forEach = function(t, n, o) {
2757
- n === void 0 && (n = 0), o === void 0 && (o = this.length), n <= o ? this.forEachInner(t, n, o, 0) : this.forEachInvertedInner(t, n, o, 0);
2758
- };
2759
- k.prototype.map = function(t, n, o) {
2760
- n === void 0 && (n = 0), o === void 0 && (o = this.length);
2761
- var s = [];
2762
- return this.forEach(function(r, i) {
2763
- return s.push(t(r, i));
2764
- }, n, o), s;
2765
- };
2766
- k.from = function(t) {
2767
- return t instanceof k ? t : t && t.length ? new it(t) : k.empty;
2768
- };
2769
- var it = /* @__PURE__ */ function(e) {
2770
- function t(o) {
2771
- e.call(this), this.values = o;
2772
- }
2773
- e && (t.__proto__ = e), t.prototype = Object.create(e && e.prototype), t.prototype.constructor = t;
2774
- var n = { length: { configurable: !0 }, depth: { configurable: !0 } };
2775
- return t.prototype.flatten = function() {
2776
- return this.values;
2777
- }, t.prototype.sliceInner = function(s, r) {
2778
- return s == 0 && r == this.length ? this : new t(this.values.slice(s, r));
2779
- }, t.prototype.getInner = function(s) {
2780
- return this.values[s];
2781
- }, t.prototype.forEachInner = function(s, r, i, l) {
2782
- for (var a = r; a < i; a++)
2783
- if (s(this.values[a], l + a) === !1)
2784
- return !1;
2785
- }, t.prototype.forEachInvertedInner = function(s, r, i, l) {
2786
- for (var a = r - 1; a >= i; a--)
2787
- if (s(this.values[a], l + a) === !1)
2788
- return !1;
2789
- }, t.prototype.leafAppend = function(s) {
2790
- if (this.length + s.length <= ue)
2791
- return new t(this.values.concat(s.flatten()));
2792
- }, t.prototype.leafPrepend = function(s) {
2793
- if (this.length + s.length <= ue)
2794
- return new t(s.flatten().concat(this.values));
2795
- }, n.length.get = function() {
2796
- return this.values.length;
2797
- }, n.depth.get = function() {
2798
- return 0;
2799
- }, Object.defineProperties(t.prototype, n), t;
2800
- }(k);
2801
- k.empty = new it([]);
2802
- var ro = /* @__PURE__ */ function(e) {
2803
- function t(n, o) {
2804
- e.call(this), this.left = n, this.right = o, this.length = n.length + o.length, this.depth = Math.max(n.depth, o.depth) + 1;
2805
- }
2806
- return e && (t.__proto__ = e), t.prototype = Object.create(e && e.prototype), t.prototype.constructor = t, t.prototype.flatten = function() {
2807
- return this.left.flatten().concat(this.right.flatten());
2808
- }, t.prototype.getInner = function(o) {
2809
- return o < this.left.length ? this.left.get(o) : this.right.get(o - this.left.length);
2810
- }, t.prototype.forEachInner = function(o, s, r, i) {
2811
- var l = this.left.length;
2812
- if (s < l && this.left.forEachInner(o, s, Math.min(r, l), i) === !1 || r > l && this.right.forEachInner(o, Math.max(s - l, 0), Math.min(this.length, r) - l, i + l) === !1)
2813
- return !1;
2814
- }, t.prototype.forEachInvertedInner = function(o, s, r, i) {
2815
- var l = this.left.length;
2816
- if (s > l && this.right.forEachInvertedInner(o, s - l, Math.max(r, l) - l, i + l) === !1 || r < l && this.left.forEachInvertedInner(o, Math.min(s, l), r, i) === !1)
2817
- return !1;
2818
- }, t.prototype.sliceInner = function(o, s) {
2819
- if (o == 0 && s == this.length)
2820
- return this;
2821
- var r = this.left.length;
2822
- return s <= r ? this.left.slice(o, s) : o >= r ? this.right.slice(o - r, s - r) : this.left.slice(o, r).append(this.right.slice(0, s - r));
2823
- }, t.prototype.leafAppend = function(o) {
2824
- var s = this.right.leafAppend(o);
2825
- if (s)
2826
- return new t(this.left, s);
2827
- }, t.prototype.leafPrepend = function(o) {
2828
- var s = this.left.leafPrepend(o);
2829
- if (s)
2830
- return new t(s, this.right);
2831
- }, t.prototype.appendInner = function(o) {
2832
- return this.left.depth >= Math.max(this.right.depth, o.depth) + 1 ? new t(this.left, new t(this.right, o)) : new t(this, o);
2833
- }, t;
2834
- }(k);
2835
- const io = 500;
2836
- class E {
2837
- constructor(t, n) {
2838
- this.items = t, this.eventCount = n;
2839
- }
2840
- // Pop the latest event off the branch's history and apply it
2841
- // to a document transform.
2842
- popEvent(t, n) {
2843
- if (this.eventCount == 0)
2844
- return null;
2845
- let o = this.items.length;
2846
- for (; ; o--)
2847
- if (this.items.get(o - 1).selection) {
2848
- --o;
2849
- break;
2850
- }
2851
- let s, r;
2852
- n && (s = this.remapping(o, this.items.length), r = s.maps.length);
2853
- let i = t.tr, l, a, c = [], u = [];
2854
- return this.items.forEach((d, p) => {
2855
- if (!d.step) {
2856
- s || (s = this.remapping(o, p + 1), r = s.maps.length), r--, u.push(d);
2857
- return;
2858
- }
2859
- if (s) {
2860
- u.push(new N(d.map));
2861
- let h = d.step.map(s.slice(r)), f;
2862
- h && i.maybeStep(h).doc && (f = i.mapping.maps[i.mapping.maps.length - 1], c.push(new N(f, void 0, void 0, c.length + u.length))), r--, f && s.appendMap(f, r);
2863
- } else
2864
- i.maybeStep(d.step);
2865
- if (d.selection)
2866
- return l = s ? d.selection.map(s.slice(r)) : d.selection, a = new E(this.items.slice(0, o).append(u.reverse().concat(c)), this.eventCount - 1), !1;
2867
- }, this.items.length, 0), { remaining: a, transform: i, selection: l };
2868
- }
2869
- // Create a new branch with the given transform added.
2870
- addTransform(t, n, o, s) {
2871
- let r = [], i = this.eventCount, l = this.items, a = !s && l.length ? l.get(l.length - 1) : null;
2872
- for (let u = 0; u < t.steps.length; u++) {
2873
- let d = t.steps[u].invert(t.docs[u]), p = new N(t.mapping.maps[u], d, n), h;
2874
- (h = a && a.merge(p)) && (p = h, u ? r.pop() : l = l.slice(0, l.length - 1)), r.push(p), n && (i++, n = void 0), s || (a = p);
2875
- }
2876
- let c = i - o.depth;
2877
- return c > ao && (l = lo(l, c), i -= c), new E(l.append(r), i);
2878
- }
2879
- remapping(t, n) {
2880
- let o = new mt();
2881
- return this.items.forEach((s, r) => {
2882
- let i = s.mirrorOffset != null && r - s.mirrorOffset >= t ? o.maps.length - s.mirrorOffset : void 0;
2883
- o.appendMap(s.map, i);
2884
- }, t, n), o;
2885
- }
2886
- addMaps(t) {
2887
- return this.eventCount == 0 ? this : new E(this.items.append(t.map((n) => new N(n))), this.eventCount);
2888
- }
2889
- // When the collab module receives remote changes, the history has
2890
- // to know about those, so that it can adjust the steps that were
2891
- // rebased on top of the remote changes, and include the position
2892
- // maps for the remote changes in its array of items.
2893
- rebased(t, n) {
2894
- if (!this.eventCount)
2895
- return this;
2896
- let o = [], s = Math.max(0, this.items.length - n), r = t.mapping, i = t.steps.length, l = this.eventCount;
2897
- this.items.forEach((p) => {
2898
- p.selection && l--;
2899
- }, s);
2900
- let a = n;
2901
- this.items.forEach((p) => {
2902
- let h = r.getMirror(--a);
2903
- if (h == null)
2904
- return;
2905
- i = Math.min(i, h);
2906
- let f = r.maps[h];
2907
- if (p.step) {
2908
- let m = t.steps[h].invert(t.docs[h]), g = p.selection && p.selection.map(r.slice(a + 1, h));
2909
- g && l++, o.push(new N(f, m, g));
2910
- } else
2911
- o.push(new N(f));
2912
- }, s);
2913
- let c = [];
2914
- for (let p = n; p < i; p++)
2915
- c.push(new N(r.maps[p]));
2916
- let u = this.items.slice(0, s).append(c).append(o), d = new E(u, l);
2917
- return d.emptyItemCount() > io && (d = d.compress(this.items.length - o.length)), d;
2918
- }
2919
- emptyItemCount() {
2920
- let t = 0;
2921
- return this.items.forEach((n) => {
2922
- n.step || t++;
2923
- }), t;
2924
- }
2925
- // Compressing a branch means rewriting it to push the air (map-only
2926
- // items) out. During collaboration, these naturally accumulate
2927
- // because each remote change adds one. The `upto` argument is used
2928
- // to ensure that only the items below a given level are compressed,
2929
- // because `rebased` relies on a clean, untouched set of items in
2930
- // order to associate old items with rebased steps.
2931
- compress(t = this.items.length) {
2932
- let n = this.remapping(0, t), o = n.maps.length, s = [], r = 0;
2933
- return this.items.forEach((i, l) => {
2934
- if (l >= t)
2935
- s.push(i), i.selection && r++;
2936
- else if (i.step) {
2937
- let a = i.step.map(n.slice(o)), c = a && a.getMap();
2938
- if (o--, c && n.appendMap(c, o), a) {
2939
- let u = i.selection && i.selection.map(n.slice(o));
2940
- u && r++;
2941
- let d = new N(c.invert(), a, u), p, h = s.length - 1;
2942
- (p = s.length && s[h].merge(d)) ? s[h] = p : s.push(d);
2943
- }
2944
- } else i.map && o--;
2945
- }, this.items.length, 0), new E(k.from(s.reverse()), r);
2946
- }
2947
- }
2948
- E.empty = new E(k.empty, 0);
2949
- function lo(e, t) {
2950
- let n;
2951
- return e.forEach((o, s) => {
2952
- if (o.selection && t-- == 0)
2953
- return n = s, !1;
2954
- }), e.slice(n);
2955
- }
2956
- class N {
2957
- constructor(t, n, o, s) {
2958
- this.map = t, this.step = n, this.selection = o, this.mirrorOffset = s;
2959
- }
2960
- merge(t) {
2961
- if (this.step && t.step && !t.selection) {
2962
- let n = t.step.merge(this.step);
2963
- if (n)
2964
- return new N(n.getMap().invert(), n, this.selection);
2965
- }
2966
- }
2967
- }
2968
- class D {
2969
- constructor(t, n, o, s, r) {
2970
- this.done = t, this.undone = n, this.prevRanges = o, this.prevTime = s, this.prevComposition = r;
2971
- }
2972
- }
2973
- const ao = 20;
2974
- function co(e, t, n, o) {
2975
- let s = n.getMeta(F), r;
2976
- if (s)
2977
- return s.historyState;
2978
- n.getMeta(ho) && (e = new D(e.done, e.undone, null, 0, -1));
2979
- let i = n.getMeta("appendedTransaction");
2980
- if (n.steps.length == 0)
2981
- return e;
2982
- if (i && i.getMeta(F))
2983
- return i.getMeta(F).redo ? new D(e.done.addTransform(n, void 0, o, de(t)), e.undone, Fe(n.mapping.maps), e.prevTime, e.prevComposition) : new D(e.done, e.undone.addTransform(n, void 0, o, de(t)), null, e.prevTime, e.prevComposition);
2984
- if (n.getMeta("addToHistory") !== !1 && !(i && i.getMeta("addToHistory") === !1)) {
2985
- let l = n.getMeta("composition"), a = e.prevTime == 0 || !i && e.prevComposition != l && (e.prevTime < (n.time || 0) - o.newGroupDelay || !uo(n, e.prevRanges)), c = i ? ge(e.prevRanges, n.mapping) : Fe(n.mapping.maps);
2986
- return new D(e.done.addTransform(n, a ? t.selection.getBookmark() : void 0, o, de(t)), E.empty, c, n.time, l ?? e.prevComposition);
2987
- } else return (r = n.getMeta("rebased")) ? new D(e.done.rebased(n, r), e.undone.rebased(n, r), ge(e.prevRanges, n.mapping), e.prevTime, e.prevComposition) : new D(e.done.addMaps(n.mapping.maps), e.undone.addMaps(n.mapping.maps), ge(e.prevRanges, n.mapping), e.prevTime, e.prevComposition);
2988
- }
2989
- function uo(e, t) {
2990
- if (!t)
2991
- return !1;
2992
- if (!e.docChanged)
2993
- return !0;
2994
- let n = !1;
2995
- return e.mapping.maps[0].forEach((o, s) => {
2996
- for (let r = 0; r < t.length; r += 2)
2997
- o <= t[r + 1] && s >= t[r] && (n = !0);
2998
- }), n;
2999
- }
3000
- function Fe(e) {
3001
- let t = [];
3002
- for (let n = e.length - 1; n >= 0 && t.length == 0; n--)
3003
- e[n].forEach((o, s, r, i) => t.push(r, i));
3004
- return t;
3005
- }
3006
- function ge(e, t) {
3007
- if (!e)
3008
- return null;
3009
- let n = [];
3010
- for (let o = 0; o < e.length; o += 2) {
3011
- let s = t.map(e[o], 1), r = t.map(e[o + 1], -1);
3012
- s <= r && n.push(s, r);
3013
- }
3014
- return n;
3015
- }
3016
- function po(e, t, n) {
3017
- let o = de(t), s = F.get(t).spec.config, r = (n ? e.undone : e.done).popEvent(t, o);
3018
- if (!r)
3019
- return null;
3020
- let i = r.selection.resolve(r.transform.doc), l = (n ? e.done : e.undone).addTransform(r.transform, t.selection.getBookmark(), s, o), a = new D(n ? l : r.remaining, n ? r.remaining : l, null, 0, -1);
3021
- return r.transform.setSelection(i).setMeta(F, { redo: n, historyState: a });
3022
- }
3023
- let be = !1, Ke = null;
3024
- function de(e) {
3025
- let t = e.plugins;
3026
- if (Ke != t) {
3027
- be = !1, Ke = t;
3028
- for (let n = 0; n < t.length; n++)
3029
- if (t[n].spec.historyPreserveItems) {
3030
- be = !0;
3031
- break;
3032
- }
3033
- }
3034
- return be;
3035
- }
3036
- const F = new W("history"), ho = new W("closeHistory");
3037
- function fo(e = {}) {
3038
- return e = {
3039
- depth: e.depth || 100,
3040
- newGroupDelay: e.newGroupDelay || 500
3041
- }, new _({
3042
- key: F,
3043
- state: {
3044
- init() {
3045
- return new D(E.empty, E.empty, null, 0, -1);
3046
- },
3047
- apply(t, n, o) {
3048
- return co(n, o, t, e);
3049
- }
3050
- },
3051
- config: e,
3052
- props: {
3053
- handleDOMEvents: {
3054
- beforeinput(t, n) {
3055
- let o = n.inputType, s = o == "historyUndo" ? at : o == "historyRedo" ? ct : null;
3056
- return s ? (n.preventDefault(), s(t.state, t.dispatch)) : !1;
3057
- }
3058
- }
3059
- }
3060
- });
3061
- }
3062
- function lt(e, t) {
3063
- return (n, o) => {
3064
- let s = F.getState(n);
3065
- if (!s || (e ? s.undone : s.done).eventCount == 0)
3066
- return !1;
3067
- if (o) {
3068
- let r = po(s, n, e);
3069
- r && o(t ? r.scrollIntoView() : r);
3070
- }
3071
- return !0;
3072
- };
3073
- }
3074
- const at = lt(!1, !0), ct = lt(!0, !0), mo = X.create({
3075
- name: "history",
3076
- addOptions() {
3077
- return {
3078
- depth: 100,
3079
- newGroupDelay: 500
3080
- };
3081
- },
3082
- addCommands() {
3083
- return {
3084
- undo: () => ({ state: e, dispatch: t }) => at(e, t),
3085
- redo: () => ({ state: e, dispatch: t }) => ct(e, t)
3086
- };
3087
- },
3088
- addProseMirrorPlugins() {
3089
- return [
3090
- fo(this.options)
3091
- ];
3092
- },
3093
- addKeyboardShortcuts() {
3094
- return {
3095
- "Mod-z": () => this.editor.commands.undo(),
3096
- "Shift-Mod-z": () => this.editor.commands.redo(),
3097
- "Mod-y": () => this.editor.commands.redo(),
3098
- // Russian keyboard layouts
3099
- "Mod-я": () => this.editor.commands.undo(),
3100
- "Shift-Mod-я": () => this.editor.commands.redo()
3101
- };
3102
- }
3103
- }), go = T.create({
3104
- name: "horizontalRule",
3105
- addOptions() {
3106
- return {
3107
- HTMLAttributes: {}
3108
- };
3109
- },
3110
- group: "block",
3111
- parseHTML() {
3112
- return [{ tag: "hr" }];
3113
- },
3114
- renderHTML({ HTMLAttributes: e }) {
3115
- return ["hr", M(this.options.HTMLAttributes, e)];
3116
- },
3117
- addCommands() {
3118
- return {
3119
- setHorizontalRule: () => ({ chain: e, state: t }) => {
3120
- const { selection: n } = t, { $from: o, $to: s } = n, r = e();
3121
- return o.parentOffset === 0 ? r.insertContentAt({
3122
- from: Math.max(o.pos - 1, 0),
3123
- to: s.pos
3124
- }, {
3125
- type: this.name
3126
- }) : gt(n) ? r.insertContentAt(s.pos, {
3127
- type: this.name
3128
- }) : r.insertContent({ type: this.name }), r.command(({ tr: i, dispatch: l }) => {
3129
- var a;
3130
- if (l) {
3131
- const { $to: c } = i.selection, u = c.end();
3132
- if (c.nodeAfter)
3133
- c.nodeAfter.isTextblock ? i.setSelection(x.create(i.doc, c.pos + 1)) : c.nodeAfter.isBlock ? i.setSelection(pe.create(i.doc, c.pos)) : i.setSelection(x.create(i.doc, c.pos));
3134
- else {
3135
- const d = (a = c.parent.type.contentMatch.defaultType) === null || a === void 0 ? void 0 : a.create();
3136
- d && (i.insert(u, d), i.setSelection(x.create(i.doc, u + 1)));
3137
- }
3138
- i.scrollIntoView();
3139
- }
3140
- return !0;
3141
- }).run();
3142
- }
3143
- };
3144
- },
3145
- addInputRules() {
3146
- return [
3147
- qe({
3148
- find: /^(?:---|—-|___\s|\*\*\*\s)$/,
3149
- type: this.type
3150
- })
3151
- ];
3152
- }
3153
- }), bo = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/, wo = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g, yo = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/, Co = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g, Mo = te.create({
3154
- name: "italic",
3155
- addOptions() {
3156
- return {
3157
- HTMLAttributes: {}
3158
- };
3159
- },
3160
- parseHTML() {
3161
- return [
3162
- {
3163
- tag: "em"
3164
- },
3165
- {
3166
- tag: "i",
3167
- getAttrs: (e) => e.style.fontStyle !== "normal" && null
3168
- },
3169
- {
3170
- style: "font-style=normal",
3171
- clearMark: (e) => e.type.name === this.name
3172
- },
3173
- {
3174
- style: "font-style=italic"
3175
- }
3176
- ];
3177
- },
3178
- renderHTML({ HTMLAttributes: e }) {
3179
- return ["em", M(this.options.HTMLAttributes, e), 0];
3180
- },
3181
- addCommands() {
3182
- return {
3183
- setItalic: () => ({ commands: e }) => e.setMark(this.name),
3184
- toggleItalic: () => ({ commands: e }) => e.toggleMark(this.name),
3185
- unsetItalic: () => ({ commands: e }) => e.unsetMark(this.name)
3186
- };
3187
- },
3188
- addKeyboardShortcuts() {
3189
- return {
3190
- "Mod-i": () => this.editor.commands.toggleItalic(),
3191
- "Mod-I": () => this.editor.commands.toggleItalic()
3192
- };
3193
- },
3194
- addInputRules() {
3195
- return [
3196
- Q({
3197
- find: bo,
3198
- type: this.type
3199
- }),
3200
- Q({
3201
- find: yo,
3202
- type: this.type
3203
- })
3204
- ];
3205
- },
3206
- addPasteRules() {
3207
- return [
3208
- j({
3209
- find: wo,
3210
- type: this.type
3211
- }),
3212
- j({
3213
- find: Co,
3214
- type: this.type
3215
- })
3216
- ];
3217
- }
3218
- }), Ao = T.create({
3219
- name: "listItem",
3220
- addOptions() {
3221
- return {
3222
- HTMLAttributes: {},
3223
- bulletListTypeName: "bulletList",
3224
- orderedListTypeName: "orderedList"
3225
- };
3226
- },
3227
- content: "paragraph block*",
3228
- defining: !0,
3229
- parseHTML() {
3230
- return [
3231
- {
3232
- tag: "li"
3233
- }
3234
- ];
3235
- },
3236
- renderHTML({ HTMLAttributes: e }) {
3237
- return ["li", M(this.options.HTMLAttributes, e), 0];
3238
- },
3239
- addKeyboardShortcuts() {
3240
- return {
3241
- Enter: () => this.editor.commands.splitListItem(this.name),
3242
- Tab: () => this.editor.commands.sinkListItem(this.name),
3243
- "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
3244
- };
3245
- }
3246
- }), ko = "listItem", je = "textStyle", Qe = /^(\d+)\.\s$/, To = T.create({
3247
- name: "orderedList",
3248
- addOptions() {
3249
- return {
3250
- itemTypeName: "listItem",
3251
- HTMLAttributes: {},
3252
- keepMarks: !1,
3253
- keepAttributes: !1
3254
- };
3255
- },
3256
- group: "block list",
3257
- content() {
3258
- return `${this.options.itemTypeName}+`;
3259
- },
3260
- addAttributes() {
3261
- return {
3262
- start: {
3263
- default: 1,
3264
- parseHTML: (e) => e.hasAttribute("start") ? parseInt(e.getAttribute("start") || "", 10) : 1
3265
- },
3266
- type: {
3267
- default: null,
3268
- parseHTML: (e) => e.getAttribute("type")
3269
- }
3270
- };
3271
- },
3272
- parseHTML() {
3273
- return [
3274
- {
3275
- tag: "ol"
3276
- }
3277
- ];
3278
- },
3279
- renderHTML({ HTMLAttributes: e }) {
3280
- const { start: t, ...n } = e;
3281
- return t === 1 ? ["ol", M(this.options.HTMLAttributes, n), 0] : ["ol", M(this.options.HTMLAttributes, e), 0];
3282
- },
3283
- addCommands() {
3284
- return {
3285
- toggleOrderedList: () => ({ commands: e, chain: t }) => this.options.keepAttributes ? t().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ko, this.editor.getAttributes(je)).run() : e.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
3286
- };
3287
- },
3288
- addKeyboardShortcuts() {
3289
- return {
3290
- "Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
3291
- };
3292
- },
3293
- addInputRules() {
3294
- let e = J({
3295
- find: Qe,
3296
- type: this.type,
3297
- getAttributes: (t) => ({ start: +t[1] }),
3298
- joinPredicate: (t, n) => n.childCount + n.attrs.start === +t[1]
3299
- });
3300
- return (this.options.keepMarks || this.options.keepAttributes) && (e = J({
3301
- find: Qe,
3302
- type: this.type,
3303
- keepMarks: this.options.keepMarks,
3304
- keepAttributes: this.options.keepAttributes,
3305
- getAttributes: (t) => ({ start: +t[1], ...this.editor.getAttributes(je) }),
3306
- joinPredicate: (t, n) => n.childCount + n.attrs.start === +t[1],
3307
- editor: this.editor
3308
- })), [
3309
- e
3310
- ];
3311
- }
3312
- }), So = T.create({
3313
- name: "paragraph",
3314
- priority: 1e3,
3315
- addOptions() {
3316
- return {
3317
- HTMLAttributes: {}
3318
- };
3319
- },
3320
- group: "block",
3321
- content: "inline*",
3322
- parseHTML() {
3323
- return [
3324
- { tag: "p" }
3325
- ];
3326
- },
3327
- renderHTML({ HTMLAttributes: e }) {
3328
- return ["p", M(this.options.HTMLAttributes, e), 0];
3329
- },
3330
- addCommands() {
3331
- return {
3332
- setParagraph: () => ({ commands: e }) => e.setNode(this.name)
3333
- };
3334
- },
3335
- addKeyboardShortcuts() {
3336
- return {
3337
- "Mod-Alt-0": () => this.editor.commands.setParagraph()
3338
- };
3339
- }
3340
- }), vo = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/, xo = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g, Lo = te.create({
3341
- name: "strike",
3342
- addOptions() {
3343
- return {
3344
- HTMLAttributes: {}
3345
- };
3346
- },
3347
- parseHTML() {
3348
- return [
3349
- {
3350
- tag: "s"
3351
- },
3352
- {
3353
- tag: "del"
3354
- },
3355
- {
3356
- tag: "strike"
3357
- },
3358
- {
3359
- style: "text-decoration",
3360
- consuming: !1,
3361
- getAttrs: (e) => e.includes("line-through") ? {} : !1
3362
- }
3363
- ];
3364
- },
3365
- renderHTML({ HTMLAttributes: e }) {
3366
- return ["s", M(this.options.HTMLAttributes, e), 0];
3367
- },
3368
- addCommands() {
3369
- return {
3370
- setStrike: () => ({ commands: e }) => e.setMark(this.name),
3371
- toggleStrike: () => ({ commands: e }) => e.toggleMark(this.name),
3372
- unsetStrike: () => ({ commands: e }) => e.unsetMark(this.name)
3373
- };
3374
- },
3375
- addKeyboardShortcuts() {
3376
- return {
3377
- "Mod-Shift-s": () => this.editor.commands.toggleStrike()
3378
- };
3379
- },
3380
- addInputRules() {
3381
- return [
3382
- Q({
3383
- find: vo,
3384
- type: this.type
3385
- })
3386
- ];
3387
- },
3388
- addPasteRules() {
3389
- return [
3390
- j({
3391
- find: xo,
3392
- type: this.type
3393
- })
3394
- ];
3395
- }
3396
- }), Ro = T.create({
3397
- name: "text",
3398
- group: "inline"
3399
- }), Ho = X.create({
3400
- name: "starterKit",
3401
- addExtensions() {
3402
- const e = [];
3403
- return this.options.bold !== !1 && e.push(zn.configure(this.options.bold)), this.options.blockquote !== !1 && e.push(En.configure(this.options.blockquote)), this.options.bulletList !== !1 && e.push(Dn.configure(this.options.bulletList)), this.options.code !== !1 && e.push(Wn.configure(this.options.code)), this.options.codeBlock !== !1 && e.push(Kn.configure(this.options.codeBlock)), this.options.document !== !1 && e.push(jn.configure(this.options.document)), this.options.dropcursor !== !1 && e.push(Xn.configure(this.options.dropcursor)), this.options.gapcursor !== !1 && e.push(no.configure(this.options.gapcursor)), this.options.hardBreak !== !1 && e.push(oo.configure(this.options.hardBreak)), this.options.heading !== !1 && e.push(so.configure(this.options.heading)), this.options.history !== !1 && e.push(mo.configure(this.options.history)), this.options.horizontalRule !== !1 && e.push(go.configure(this.options.horizontalRule)), this.options.italic !== !1 && e.push(Mo.configure(this.options.italic)), this.options.listItem !== !1 && e.push(Ao.configure(this.options.listItem)), this.options.orderedList !== !1 && e.push(To.configure(this.options.orderedList)), this.options.paragraph !== !1 && e.push(So.configure(this.options.paragraph)), this.options.strike !== !1 && e.push(Lo.configure(this.options.strike)), this.options.text !== !1 && e.push(Ro.configure(this.options.text)), e;
3404
- }
3405
- }), Eo = /^\s*(\[([( |x])?\])\s$/, Io = T.create({
3406
- name: "taskItem",
3407
- addOptions() {
3408
- return {
3409
- nested: !1,
3410
- HTMLAttributes: {},
3411
- taskListTypeName: "taskList"
3412
- };
3413
- },
3414
- content() {
3415
- return this.options.nested ? "paragraph block*" : "paragraph+";
3416
- },
3417
- defining: !0,
3418
- addAttributes() {
3419
- return {
3420
- checked: {
3421
- default: !1,
3422
- keepOnSplit: !1,
3423
- parseHTML: (e) => {
3424
- const t = e.getAttribute("data-checked");
3425
- return t === "" || t === "true";
3426
- },
3427
- renderHTML: (e) => ({
3428
- "data-checked": e.checked
3429
- })
3430
- }
3431
- };
3432
- },
3433
- parseHTML() {
3434
- return [
3435
- {
3436
- tag: `li[data-type="${this.name}"]`,
3437
- priority: 51
3438
- }
3439
- ];
3440
- },
3441
- renderHTML({ node: e, HTMLAttributes: t }) {
3442
- return [
3443
- "li",
3444
- M(this.options.HTMLAttributes, t, {
3445
- "data-type": this.name
3446
- }),
3447
- [
3448
- "label",
3449
- [
3450
- "input",
3451
- {
3452
- type: "checkbox",
3453
- checked: e.attrs.checked ? "checked" : null
3454
- }
3455
- ],
3456
- ["span"]
3457
- ],
3458
- ["div", 0]
3459
- ];
3460
- },
3461
- addKeyboardShortcuts() {
3462
- const e = {
3463
- Enter: () => this.editor.commands.splitListItem(this.name),
3464
- "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
3465
- };
3466
- return this.options.nested ? {
3467
- ...e,
3468
- Tab: () => this.editor.commands.sinkListItem(this.name)
3469
- } : e;
3470
- },
3471
- addNodeView() {
3472
- return ({ node: e, HTMLAttributes: t, getPos: n, editor: o }) => {
3473
- const s = document.createElement("li"), r = document.createElement("label"), i = document.createElement("span"), l = document.createElement("input"), a = document.createElement("div");
3474
- return r.contentEditable = "false", l.type = "checkbox", l.addEventListener("mousedown", (c) => c.preventDefault()), l.addEventListener("change", (c) => {
3475
- if (!o.isEditable && !this.options.onReadOnlyChecked) {
3476
- l.checked = !l.checked;
3477
- return;
3478
- }
3479
- const { checked: u } = c.target;
3480
- o.isEditable && typeof n == "function" && o.chain().focus(void 0, { scrollIntoView: !1 }).command(({ tr: d }) => {
3481
- const p = n();
3482
- if (typeof p != "number")
3483
- return !1;
3484
- const h = d.doc.nodeAt(p);
3485
- return d.setNodeMarkup(p, void 0, {
3486
- ...h == null ? void 0 : h.attrs,
3487
- checked: u
3488
- }), !0;
3489
- }).run(), !o.isEditable && this.options.onReadOnlyChecked && (this.options.onReadOnlyChecked(e, u) || (l.checked = !l.checked));
3490
- }), Object.entries(this.options.HTMLAttributes).forEach(([c, u]) => {
3491
- s.setAttribute(c, u);
3492
- }), s.dataset.checked = e.attrs.checked, l.checked = e.attrs.checked, r.append(l, i), s.append(r, a), Object.entries(t).forEach(([c, u]) => {
3493
- s.setAttribute(c, u);
3494
- }), {
3495
- dom: s,
3496
- contentDOM: a,
3497
- update: (c) => c.type !== this.type ? !1 : (s.dataset.checked = c.attrs.checked, l.checked = c.attrs.checked, !0)
3498
- };
3499
- };
3500
- },
3501
- addInputRules() {
3502
- return [
3503
- J({
3504
- find: Eo,
3505
- type: this.type,
3506
- getAttributes: (e) => ({
3507
- checked: e[e.length - 1] === "x"
3508
- })
3509
- })
3510
- ];
3511
- }
3512
- }), No = T.create({
3513
- name: "taskList",
3514
- addOptions() {
3515
- return {
3516
- itemTypeName: "taskItem",
3517
- HTMLAttributes: {}
3518
- };
3519
- },
3520
- group: "block list",
3521
- content() {
3522
- return `${this.options.itemTypeName}+`;
3523
- },
3524
- parseHTML() {
3525
- return [
3526
- {
3527
- tag: `ul[data-type="${this.name}"]`,
3528
- priority: 51
3529
- }
3530
- ];
3531
- },
3532
- renderHTML({ HTMLAttributes: e }) {
3533
- return ["ul", M(this.options.HTMLAttributes, e, { "data-type": this.name }), 0];
3534
- },
3535
- addCommands() {
3536
- return {
3537
- toggleTaskList: () => ({ commands: e }) => e.toggleList(this.name, this.options.itemTypeName)
3538
- };
3539
- },
3540
- addKeyboardShortcuts() {
3541
- return {
3542
- "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
3543
- };
3544
- }
3545
- }), $o = T.create({
3546
- name: "tableRow",
3547
- addOptions() {
3548
- return {
3549
- HTMLAttributes: {}
3550
- };
3551
- },
3552
- content: "(tableCell | tableHeader)*",
3553
- tableRole: "row",
3554
- parseHTML() {
3555
- return [
3556
- { tag: "tr" }
3557
- ];
3558
- },
3559
- renderHTML({ HTMLAttributes: e }) {
3560
- return ["tr", M(this.options.HTMLAttributes, e), 0];
3561
- }
3562
- }), Oo = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/, zo = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g, Po = te.create({
3563
- name: "highlight",
3564
- addOptions() {
3565
- return {
3566
- multicolor: !1,
3567
- HTMLAttributes: {}
3568
- };
3569
- },
3570
- addAttributes() {
3571
- return this.options.multicolor ? {
3572
- color: {
3573
- default: null,
3574
- parseHTML: (e) => e.getAttribute("data-color") || e.style.backgroundColor,
3575
- renderHTML: (e) => e.color ? {
3576
- "data-color": e.color,
3577
- style: `background-color: ${e.color}; color: inherit`
3578
- } : {}
3579
- }
3580
- } : {};
3581
- },
3582
- parseHTML() {
3583
- return [
3584
- {
3585
- tag: "mark"
3586
- }
3587
- ];
3588
- },
3589
- renderHTML({ HTMLAttributes: e }) {
3590
- return ["mark", M(this.options.HTMLAttributes, e), 0];
3591
- },
3592
- addCommands() {
3593
- return {
3594
- setHighlight: (e) => ({ commands: t }) => t.setMark(this.name, e),
3595
- toggleHighlight: (e) => ({ commands: t }) => t.toggleMark(this.name, e),
3596
- unsetHighlight: () => ({ commands: e }) => e.unsetMark(this.name)
3597
- };
3598
- },
3599
- addKeyboardShortcuts() {
3600
- return {
3601
- "Mod-Shift-h": () => this.editor.commands.toggleHighlight()
3602
- };
3603
- },
3604
- addInputRules() {
3605
- return [
3606
- Q({
3607
- find: Oo,
3608
- type: this.type
3609
- })
3610
- ];
3611
- },
3612
- addPasteRules() {
3613
- return [
3614
- j({
3615
- find: zo,
3616
- type: this.type
3617
- })
3618
- ];
3619
- }
3620
- }), Do = T.create({
3621
- name: "tableCell",
3622
- addOptions() {
3623
- return {
3624
- HTMLAttributes: {}
3625
- };
3626
- },
3627
- content: "block+",
3628
- addAttributes() {
3629
- return {
3630
- colspan: {
3631
- default: 1
3632
- },
3633
- rowspan: {
3634
- default: 1
3635
- },
3636
- colwidth: {
3637
- default: null,
3638
- parseHTML: (e) => {
3639
- const t = e.getAttribute("colwidth");
3640
- return t ? t.split(",").map((o) => parseInt(o, 10)) : null;
3641
- }
3642
- }
3643
- };
3644
- },
3645
- tableRole: "cell",
3646
- isolating: !0,
3647
- parseHTML() {
3648
- return [
3649
- { tag: "td" }
3650
- ];
3651
- },
3652
- renderHTML({ HTMLAttributes: e }) {
3653
- return ["td", M(this.options.HTMLAttributes, e), 0];
3654
- }
3655
- }), Bo = X.create({
3656
- name: "placeholder",
3657
- addOptions() {
3658
- return {
3659
- emptyEditorClass: "is-editor-empty",
3660
- emptyNodeClass: "is-empty",
3661
- placeholder: "Write something …",
3662
- showOnlyWhenEditable: !0,
3663
- showOnlyCurrent: !0,
3664
- includeChildren: !1
3665
- };
3666
- },
3667
- addProseMirrorPlugins() {
3668
- return [
3669
- new _({
3670
- key: new W("placeholder"),
3671
- props: {
3672
- decorations: ({ doc: e, selection: t }) => {
3673
- const n = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: o } = t, s = [];
3674
- if (!n)
3675
- return null;
3676
- const r = this.editor.isEmpty;
3677
- return e.descendants((i, l) => {
3678
- const a = o >= l && o <= l + i.nodeSize, c = !i.isLeaf && bt(i);
3679
- if ((a || !this.options.showOnlyCurrent) && c) {
3680
- const u = [this.options.emptyNodeClass];
3681
- r && u.push(this.options.emptyEditorClass);
3682
- const d = G.node(l, l + i.nodeSize, {
3683
- class: u.join(" "),
3684
- "data-placeholder": typeof this.options.placeholder == "function" ? this.options.placeholder({
3685
- editor: this.editor,
3686
- node: i,
3687
- pos: l,
3688
- hasAnchor: a
3689
- }) : this.options.placeholder
3690
- });
3691
- s.push(d);
3692
- }
3693
- return this.options.includeChildren;
3694
- }), K.create(e, s);
3695
- }
3696
- }
3697
- })
3698
- ];
3699
- }
3700
- }), _o = T.create({
3701
- name: "tableHeader",
3702
- addOptions() {
3703
- return {
3704
- HTMLAttributes: {}
3705
- };
3706
- },
3707
- content: "block+",
3708
- addAttributes() {
3709
- return {
3710
- colspan: {
3711
- default: 1
3712
- },
3713
- rowspan: {
3714
- default: 1
3715
- },
3716
- colwidth: {
3717
- default: null,
3718
- parseHTML: (e) => {
3719
- const t = e.getAttribute("colwidth");
3720
- return t ? t.split(",").map((o) => parseInt(o, 10)) : null;
3721
- }
3722
- }
3723
- };
3724
- },
3725
- tableRole: "header_cell",
3726
- isolating: !0,
3727
- parseHTML() {
3728
- return [
3729
- { tag: "th" }
3730
- ];
3731
- },
3732
- renderHTML({ HTMLAttributes: e }) {
3733
- return ["th", M(this.options.HTMLAttributes, e), 0];
3734
- }
3735
- }), Wo = (e) => A({
3736
- find: /--$/,
3737
- replace: e ?? "—"
3738
- }), Vo = (e) => A({
3739
- find: /\.\.\.$/,
3740
- replace: e ?? "…"
3741
- }), Fo = (e) => A({
3742
- find: /(?:^|[\s{[(<'"\u2018\u201C])(")$/,
3743
- replace: e ?? "“"
3744
- }), Ko = (e) => A({
3745
- find: /"$/,
3746
- replace: e ?? "”"
3747
- }), jo = (e) => A({
3748
- find: /(?:^|[\s{[(<'"\u2018\u201C])(')$/,
3749
- replace: e ?? "‘"
3750
- }), Qo = (e) => A({
3751
- find: /'$/,
3752
- replace: e ?? "’"
3753
- }), qo = (e) => A({
3754
- find: /<-$/,
3755
- replace: e ?? "←"
3756
- }), Xo = (e) => A({
3757
- find: /->$/,
3758
- replace: e ?? "→"
3759
- }), Go = (e) => A({
3760
- find: /\(c\)$/,
3761
- replace: e ?? "©"
3762
- }), Jo = (e) => A({
3763
- find: /\(tm\)$/,
3764
- replace: e ?? "™"
3765
- }), Yo = (e) => A({
3766
- find: /\(sm\)$/,
3767
- replace: e ?? "℠"
3768
- }), Uo = (e) => A({
3769
- find: /\(r\)$/,
3770
- replace: e ?? "®"
3771
- }), Zo = (e) => A({
3772
- find: /(?:^|\s)(1\/2)\s$/,
3773
- replace: e ?? "½"
3774
- }), es = (e) => A({
3775
- find: /\+\/-$/,
3776
- replace: e ?? "±"
3777
- }), ts = (e) => A({
3778
- find: /!=$/,
3779
- replace: e ?? "≠"
3780
- }), ns = (e) => A({
3781
- find: /<<$/,
3782
- replace: e ?? "«"
3783
- }), os = (e) => A({
3784
- find: />>$/,
3785
- replace: e ?? "»"
3786
- }), ss = (e) => A({
3787
- find: /\d+\s?([*x])\s?\d+$/,
3788
- replace: e ?? "×"
3789
- }), rs = (e) => A({
3790
- find: /\^2$/,
3791
- replace: e ?? "²"
3792
- }), is = (e) => A({
3793
- find: /\^3$/,
3794
- replace: e ?? "³"
3795
- }), ls = (e) => A({
3796
- find: /(?:^|\s)(1\/4)\s$/,
3797
- replace: e ?? "¼"
3798
- }), as = (e) => A({
3799
- find: /(?:^|\s)(3\/4)\s$/,
3800
- replace: e ?? "¾"
3801
- }), cs = X.create({
3802
- name: "typography",
3803
- addOptions() {
3804
- return {
3805
- closeDoubleQuote: "”",
3806
- closeSingleQuote: "’",
3807
- copyright: "©",
3808
- ellipsis: "…",
3809
- emDash: "—",
3810
- laquo: "«",
3811
- leftArrow: "←",
3812
- multiplication: "×",
3813
- notEqual: "≠",
3814
- oneHalf: "½",
3815
- oneQuarter: "¼",
3816
- openDoubleQuote: "“",
3817
- openSingleQuote: "‘",
3818
- plusMinus: "±",
3819
- raquo: "»",
3820
- registeredTrademark: "®",
3821
- rightArrow: "→",
3822
- servicemark: "℠",
3823
- superscriptThree: "³",
3824
- superscriptTwo: "²",
3825
- threeQuarters: "¾",
3826
- trademark: "™"
3827
- };
3828
- },
3829
- addInputRules() {
3830
- const e = [];
3831
- return this.options.emDash !== !1 && e.push(Wo(this.options.emDash)), this.options.ellipsis !== !1 && e.push(Vo(this.options.ellipsis)), this.options.openDoubleQuote !== !1 && e.push(Fo(this.options.openDoubleQuote)), this.options.closeDoubleQuote !== !1 && e.push(Ko(this.options.closeDoubleQuote)), this.options.openSingleQuote !== !1 && e.push(jo(this.options.openSingleQuote)), this.options.closeSingleQuote !== !1 && e.push(Qo(this.options.closeSingleQuote)), this.options.leftArrow !== !1 && e.push(qo(this.options.leftArrow)), this.options.rightArrow !== !1 && e.push(Xo(this.options.rightArrow)), this.options.copyright !== !1 && e.push(Go(this.options.copyright)), this.options.trademark !== !1 && e.push(Jo(this.options.trademark)), this.options.servicemark !== !1 && e.push(Yo(this.options.servicemark)), this.options.registeredTrademark !== !1 && e.push(Uo(this.options.registeredTrademark)), this.options.oneHalf !== !1 && e.push(Zo(this.options.oneHalf)), this.options.plusMinus !== !1 && e.push(es(this.options.plusMinus)), this.options.notEqual !== !1 && e.push(ts(this.options.notEqual)), this.options.laquo !== !1 && e.push(ns(this.options.laquo)), this.options.raquo !== !1 && e.push(os(this.options.raquo)), this.options.multiplication !== !1 && e.push(ss(this.options.multiplication)), this.options.superscriptTwo !== !1 && e.push(rs(this.options.superscriptTwo)), this.options.superscriptThree !== !1 && e.push(is(this.options.superscriptThree)), this.options.oneQuarter !== !1 && e.push(ls(this.options.oneQuarter)), this.options.threeQuarters !== !1 && e.push(as(this.options.threeQuarters)), e;
3832
- }
3833
- }), ws = (e) => [
3834
- Ho.configure({
1
+ import t from "./extension-link.js";
2
+ import { S as o, T as a, a as i, b as n, c as l, d as m, e as d, P as u, F as c, H as f, I as g, f as p } from "../../../index-NRgJVTH-.js";
3
+ import { SlashCommand as h } from "./slashCommand/index.js";
4
+ import T from "./extension-selectedText.js";
5
+ import b from "./slashCommand/renderItems.js";
6
+ import { getSuggestionItems as y } from "./slashCommand/items.js";
7
+ import { LatexExtension as C } from "./math-extension.js";
8
+ const E = (r) => [
9
+ o.configure({
3835
10
  dropcursor: {
3836
11
  width: 4,
3837
12
  color: "#ebf6fe"
3838
13
  }
3839
14
  }),
3840
- No.configure({
15
+ a.configure({
3841
16
  HTMLAttributes: {
3842
17
  class: "scribe-task-list"
3843
18
  }
3844
19
  }),
3845
- Io.configure({
20
+ i.configure({
3846
21
  nested: !0
3847
22
  }),
3848
- Rn.configure({
23
+ n.configure({
3849
24
  resizable: !0
3850
25
  }),
3851
- $o,
3852
- _o,
3853
- Do,
3854
- Bo.configure({
26
+ l,
27
+ m,
28
+ d,
29
+ u.configure({
3855
30
  showOnlyWhenEditable: !0,
3856
31
  includeChildren: !0,
3857
32
  showOnlyCurrent: !1,
3858
33
  emptyEditorClass: "is-editor-empty",
3859
34
  emptyNodeClass: "is-node-empty",
3860
- placeholder: ({ editor: t, node: n }) => t.isDestroyed ? "" : n.type.name === "heading" ? `Heading ${n.attrs.level}` : e.placeholderText || 'Type "/" for commands...'
35
+ placeholder: ({ editor: s, node: e }) => s.isDestroyed ? "" : e.type.name === "heading" ? `Heading ${e.attrs.level}` : r.placeholderText || 'Type "/" for commands...'
3861
36
  }),
3862
- kt.configure({ mode: "deepest", className: "has-focus" }),
3863
- wt.configure({
37
+ c.configure({ mode: "deepest", className: "has-focus" }),
38
+ h.configure({
3864
39
  slashSuggestion: {
3865
- items: Mt,
3866
- render: Ct
40
+ items: y,
41
+ render: b
3867
42
  }
3868
43
  }),
3869
- Po,
3870
- yt,
3871
- dt,
3872
- St.configure({
44
+ f,
45
+ T,
46
+ t,
47
+ g.configure({
3873
48
  inline: !0,
3874
49
  HTMLAttributes: {
3875
50
  class: "scribe-image-node"
3876
51
  },
3877
52
  allowBase64: !0
3878
53
  }),
3879
- At,
3880
- cs
54
+ C,
55
+ p
3881
56
  ];
3882
57
  export {
3883
- ws as initExtensions
58
+ E as initExtensions
3884
59
  };