zt-react-milkdown 0.1.7 → 0.1.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.
Files changed (67) hide show
  1. package/README.md +4 -0
  2. package/dist/index.cjs +88 -36
  3. package/dist/index.mjs +24647 -4893
  4. package/dist/src/core/createEditor.d.ts +44 -3
  5. package/dist/src/core/createEditor.d.ts.map +1 -1
  6. package/dist/src/index.d.ts +1 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/plugins/custom/block-transform/block-transform.d.ts.map +1 -1
  9. package/dist/src/plugins/custom/code-block/code-block-language-picker.d.ts.map +1 -1
  10. package/dist/src/plugins/custom/image/image-resizable-schema.d.ts.map +1 -1
  11. package/dist/src/plugins/custom/image/image-upload-dialog/index.d.ts.map +1 -1
  12. package/dist/src/plugins/custom/selection-tooltip/index.d.ts.map +1 -1
  13. package/dist/src/plugins/custom/selection-tooltip/tooltip-view.d.ts +2 -0
  14. package/dist/src/plugins/custom/selection-tooltip/tooltip-view.d.ts.map +1 -1
  15. package/dist/src/plugins/custom/selection-tooltip/types.d.ts +2 -0
  16. package/dist/src/plugins/custom/selection-tooltip/types.d.ts.map +1 -1
  17. package/dist/src/plugins/custom/slash-menu/slash-menu-commands.d.ts.map +1 -1
  18. package/dist/src/plugins/custom/slash-menu/slash-menu.d.ts +1 -1
  19. package/dist/src/plugins/custom/slash-menu/slash-menu.d.ts.map +1 -1
  20. package/dist/src/plugins/custom/table/table-focus-actions.d.ts.map +1 -1
  21. package/dist/src/plugins/custom/table/table-more-actions.d.ts +2 -0
  22. package/dist/src/plugins/custom/table/table-more-actions.d.ts.map +1 -1
  23. package/dist/src/react/components/MilkdownEditor.d.ts.map +1 -1
  24. package/dist/src/react/hooks/useMilkdownEditor.d.ts +3 -3
  25. package/dist/src/react/hooks/useMilkdownEditor.d.ts.map +1 -1
  26. package/dist/src/types/editor.d.ts +0 -34
  27. package/dist/src/types/editor.d.ts.map +1 -1
  28. package/dist/style.css +1 -1
  29. package/package.json +1 -1
  30. package/dist/commands-BJpevWrH.js +0 -409
  31. package/dist/commands-BmZHd6RL.js +0 -2
  32. package/dist/commands-CM7IuhpT.cjs +0 -2
  33. package/dist/commands-f4yOm8DQ.cjs +0 -1
  34. package/dist/debounce-C_TNzOFT.cjs +0 -1
  35. package/dist/debounce-Z8-khnlZ.js +0 -118
  36. package/dist/dist-BjfIurm0.js +0 -1584
  37. package/dist/dist-CLTsQjPD.js +0 -3500
  38. package/dist/dist-D7LE16E1.cjs +0 -1
  39. package/dist/dist-DQnWlYyo.cjs +0 -5
  40. package/dist/floating-ui.dom-B_oXwL6O.cjs +0 -1
  41. package/dist/floating-ui.dom-Cm9Ov61_.js +0 -883
  42. package/dist/lib-5lx86j_L.js +0 -21
  43. package/dist/lib-72N1aRae.js +0 -1884
  44. package/dist/lib-BIxqp3lX.js +0 -387
  45. package/dist/lib-BLTQkf4j.cjs +0 -39
  46. package/dist/lib-BzlEyehQ.cjs +0 -5
  47. package/dist/lib-C61-3fwS.cjs +0 -1
  48. package/dist/lib-C82poHMJ.cjs +0 -1
  49. package/dist/lib-CDhjYvDm.js +0 -74
  50. package/dist/lib-CHQUpMrL.cjs +0 -3
  51. package/dist/lib-CYWwNE4c.js +0 -8673
  52. package/dist/lib-Cixz93sP.js +0 -2222
  53. package/dist/lib-CqJFV3ME.cjs +0 -1
  54. package/dist/lib-D7VWCO2M.cjs +0 -4
  55. package/dist/lib-DaPs62nF.js +0 -28
  56. package/dist/lib-Dka_BhhQ.cjs +0 -1
  57. package/dist/lib-DrllUeuK.cjs +0 -1
  58. package/dist/lib-wpjVX5Vf.js +0 -80
  59. package/dist/lib-z6CKD87x.js +0 -331
  60. package/dist/schema-list-CFEw5DQ8.cjs +0 -1
  61. package/dist/schema-list-CiFfAlj-.js +0 -110
  62. package/dist/src/react/hooks/useCloseOnGlobalScroll.d.ts +0 -5
  63. package/dist/src/react/hooks/useCloseOnGlobalScroll.d.ts.map +0 -1
  64. package/dist/state-BC1dqWPQ.cjs +0 -1
  65. package/dist/state-BvRk9kiK.cjs +0 -0
  66. package/dist/state-BvRk9kiK.js +0 -0
  67. package/dist/state-rTW_1XVf.js +0 -3
@@ -1,3500 +0,0 @@
1
- //#region node_modules/.pnpm/orderedmap@2.1.1/node_modules/orderedmap/dist/index.js
2
- function e(e) {
3
- this.content = e;
4
- }
5
- e.prototype = {
6
- constructor: e,
7
- find: function(e) {
8
- for (var t = 0; t < this.content.length; t += 2) if (this.content[t] === e) return t;
9
- return -1;
10
- },
11
- get: function(e) {
12
- var t = this.find(e);
13
- return t == -1 ? void 0 : this.content[t + 1];
14
- },
15
- update: function(t, n, r) {
16
- var i = r && r != t ? this.remove(r) : this, a = i.find(t), o = i.content.slice();
17
- return a == -1 ? o.push(r || t, n) : (o[a + 1] = n, r && (o[a] = r)), new e(o);
18
- },
19
- remove: function(t) {
20
- var n = this.find(t);
21
- if (n == -1) return this;
22
- var r = this.content.slice();
23
- return r.splice(n, 2), new e(r);
24
- },
25
- addToStart: function(t, n) {
26
- return new e([t, n].concat(this.remove(t).content));
27
- },
28
- addToEnd: function(t, n) {
29
- var r = this.remove(t).content.slice();
30
- return r.push(t, n), new e(r);
31
- },
32
- addBefore: function(t, n, r) {
33
- var i = this.remove(n), a = i.content.slice(), o = i.find(t);
34
- return a.splice(o == -1 ? a.length : o, 0, n, r), new e(a);
35
- },
36
- forEach: function(e) {
37
- for (var t = 0; t < this.content.length; t += 2) e(this.content[t], this.content[t + 1]);
38
- },
39
- prepend: function(t) {
40
- return t = e.from(t), t.size ? new e(t.content.concat(this.subtract(t).content)) : this;
41
- },
42
- append: function(t) {
43
- return t = e.from(t), t.size ? new e(this.subtract(t).content.concat(t.content)) : this;
44
- },
45
- subtract: function(t) {
46
- var n = this;
47
- t = e.from(t);
48
- for (var r = 0; r < t.content.length; r += 2) n = n.remove(t.content[r]);
49
- return n;
50
- },
51
- toObject: function() {
52
- var e = {};
53
- return this.forEach(function(t, n) {
54
- e[t] = n;
55
- }), e;
56
- },
57
- get size() {
58
- return this.content.length >> 1;
59
- }
60
- }, e.from = function(t) {
61
- if (t instanceof e) return t;
62
- var n = [];
63
- if (t) for (var r in t) n.push(r, t[r]);
64
- return new e(n);
65
- };
66
- //#endregion
67
- //#region node_modules/.pnpm/prosemirror-model@1.25.7/node_modules/prosemirror-model/dist/index.js
68
- function t(e, n, r) {
69
- for (let i = 0;; i++) {
70
- if (i == e.childCount || i == n.childCount) return e.childCount == n.childCount ? null : r;
71
- let a = e.child(i), o = n.child(i);
72
- if (a == o) {
73
- r += a.nodeSize;
74
- continue;
75
- }
76
- if (!a.sameMarkup(o)) return r;
77
- if (a.isText && a.text != o.text) {
78
- for (let e = 0; a.text[e] == o.text[e]; e++) r++;
79
- return r;
80
- }
81
- if (a.content.size || o.content.size) {
82
- let e = t(a.content, o.content, r + 1);
83
- if (e != null) return e;
84
- }
85
- r += a.nodeSize;
86
- }
87
- }
88
- function n(e, t, r, i) {
89
- for (let a = e.childCount, o = t.childCount;;) {
90
- if (a == 0 || o == 0) return a == o ? null : {
91
- a: r,
92
- b: i
93
- };
94
- let s = e.child(--a), c = t.child(--o), l = s.nodeSize;
95
- if (s == c) {
96
- r -= l, i -= l;
97
- continue;
98
- }
99
- if (!s.sameMarkup(c)) return {
100
- a: r,
101
- b: i
102
- };
103
- if (s.isText && s.text != c.text) {
104
- let e = 0, t = Math.min(s.text.length, c.text.length);
105
- for (; e < t && s.text[s.text.length - e - 1] == c.text[c.text.length - e - 1];) e++, r--, i--;
106
- return {
107
- a: r,
108
- b: i
109
- };
110
- }
111
- if (s.content.size || c.content.size) {
112
- let e = n(s.content, c.content, r - 1, i - 1);
113
- if (e) return e;
114
- }
115
- r -= l, i -= l;
116
- }
117
- }
118
- var r = class e {
119
- constructor(e, t) {
120
- if (this.content = e, this.size = t || 0, t == null) for (let t = 0; t < e.length; t++) this.size += e[t].nodeSize;
121
- }
122
- nodesBetween(e, t, n, r = 0, i) {
123
- for (let a = 0, o = 0; o < t; a++) {
124
- let s = this.content[a], c = o + s.nodeSize;
125
- if (c > e && n(s, r + o, i || null, a) !== !1 && s.content.size) {
126
- let i = o + 1;
127
- s.nodesBetween(Math.max(0, e - i), Math.min(s.content.size, t - i), n, r + i);
128
- }
129
- o = c;
130
- }
131
- }
132
- descendants(e) {
133
- this.nodesBetween(0, this.size, e);
134
- }
135
- textBetween(e, t, n, r) {
136
- let i = "", a = !0;
137
- return this.nodesBetween(e, t, (o, s) => {
138
- let c = o.isText ? o.text.slice(Math.max(e, s) - s, t - s) : o.isLeaf ? r ? typeof r == "function" ? r(o) : r : o.type.spec.leafText ? o.type.spec.leafText(o) : "" : "";
139
- o.isBlock && (o.isLeaf && c || o.isTextblock) && n && (a ? a = !1 : i += n), i += c;
140
- }, 0), i;
141
- }
142
- append(t) {
143
- if (!t.size) return this;
144
- if (!this.size) return t;
145
- let n = this.lastChild, r = t.firstChild, i = this.content.slice(), a = 0;
146
- for (n.isText && n.sameMarkup(r) && (i[i.length - 1] = n.withText(n.text + r.text), a = 1); a < t.content.length; a++) i.push(t.content[a]);
147
- return new e(i, this.size + t.size);
148
- }
149
- cut(t, n = this.size) {
150
- if (t == 0 && n == this.size) return this;
151
- let r = [], i = 0;
152
- if (n > t) for (let e = 0, a = 0; a < n; e++) {
153
- let o = this.content[e], s = a + o.nodeSize;
154
- s > t && ((a < t || s > n) && (o = o.isText ? o.cut(Math.max(0, t - a), Math.min(o.text.length, n - a)) : o.cut(Math.max(0, t - a - 1), Math.min(o.content.size, n - a - 1))), r.push(o), i += o.nodeSize), a = s;
155
- }
156
- return new e(r, i);
157
- }
158
- cutByIndex(t, n) {
159
- return t == n ? e.empty : t == 0 && n == this.content.length ? this : new e(this.content.slice(t, n));
160
- }
161
- replaceChild(t, n) {
162
- let r = this.content[t];
163
- if (r == n) return this;
164
- let i = this.content.slice(), a = this.size + n.nodeSize - r.nodeSize;
165
- return i[t] = n, new e(i, a);
166
- }
167
- addToStart(t) {
168
- return new e([t].concat(this.content), this.size + t.nodeSize);
169
- }
170
- addToEnd(t) {
171
- return new e(this.content.concat(t), this.size + t.nodeSize);
172
- }
173
- eq(e) {
174
- if (this.content.length != e.content.length) return !1;
175
- for (let t = 0; t < this.content.length; t++) if (!this.content[t].eq(e.content[t])) return !1;
176
- return !0;
177
- }
178
- get firstChild() {
179
- return this.content.length ? this.content[0] : null;
180
- }
181
- get lastChild() {
182
- return this.content.length ? this.content[this.content.length - 1] : null;
183
- }
184
- get childCount() {
185
- return this.content.length;
186
- }
187
- child(e) {
188
- let t = this.content[e];
189
- if (!t) throw RangeError("Index " + e + " out of range for " + this);
190
- return t;
191
- }
192
- maybeChild(e) {
193
- return this.content[e] || null;
194
- }
195
- forEach(e) {
196
- for (let t = 0, n = 0; t < this.content.length; t++) {
197
- let r = this.content[t];
198
- e(r, n, t), n += r.nodeSize;
199
- }
200
- }
201
- findDiffStart(e, n = 0) {
202
- return t(this, e, n);
203
- }
204
- findDiffEnd(e, t = this.size, r = e.size) {
205
- return n(this, e, t, r);
206
- }
207
- findIndex(e) {
208
- if (e == 0) return a(0, e);
209
- if (e == this.size) return a(this.content.length, e);
210
- if (e > this.size || e < 0) throw RangeError(`Position ${e} outside of fragment (${this})`);
211
- for (let t = 0, n = 0;; t++) {
212
- let r = this.child(t), i = n + r.nodeSize;
213
- if (i >= e) return i == e ? a(t + 1, i) : a(t, n);
214
- n = i;
215
- }
216
- }
217
- toString() {
218
- return "<" + this.toStringInner() + ">";
219
- }
220
- toStringInner() {
221
- return this.content.join(", ");
222
- }
223
- toJSON() {
224
- return this.content.length ? this.content.map((e) => e.toJSON()) : null;
225
- }
226
- static fromJSON(t, n) {
227
- if (!n) return e.empty;
228
- if (!Array.isArray(n)) throw RangeError("Invalid input for Fragment.fromJSON");
229
- return e.fromArray(n.map(t.nodeFromJSON));
230
- }
231
- static fromArray(t) {
232
- if (!t.length) return e.empty;
233
- let n, r = 0;
234
- for (let e = 0; e < t.length; e++) {
235
- let i = t[e];
236
- r += i.nodeSize, e && i.isText && t[e - 1].sameMarkup(i) ? (n ||= t.slice(0, e), n[n.length - 1] = i.withText(n[n.length - 1].text + i.text)) : n && n.push(i);
237
- }
238
- return new e(n || t, r);
239
- }
240
- static from(t) {
241
- if (!t) return e.empty;
242
- if (t instanceof e) return t;
243
- if (Array.isArray(t)) return this.fromArray(t);
244
- if (t.attrs) return new e([t], t.nodeSize);
245
- throw RangeError("Can not convert " + t + " to a Fragment" + (t.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
246
- }
247
- };
248
- r.empty = new r([], 0);
249
- var i = {
250
- index: 0,
251
- offset: 0
252
- };
253
- function a(e, t) {
254
- return i.index = e, i.offset = t, i;
255
- }
256
- function o(e, t) {
257
- if (e === t) return !0;
258
- if (!(e && typeof e == "object") || !(t && typeof t == "object")) return !1;
259
- let n = Array.isArray(e);
260
- if (Array.isArray(t) != n) return !1;
261
- if (n) {
262
- if (e.length != t.length) return !1;
263
- for (let n = 0; n < e.length; n++) if (!o(e[n], t[n])) return !1;
264
- } else {
265
- for (let n in e) if (!(n in t) || !o(e[n], t[n])) return !1;
266
- for (let n in t) if (!(n in e)) return !1;
267
- }
268
- return !0;
269
- }
270
- var s = class e {
271
- constructor(e, t) {
272
- this.type = e, this.attrs = t;
273
- }
274
- addToSet(e) {
275
- let t, n = !1;
276
- for (let r = 0; r < e.length; r++) {
277
- let i = e[r];
278
- if (this.eq(i)) return e;
279
- if (this.type.excludes(i.type)) t ||= e.slice(0, r);
280
- else if (i.type.excludes(this.type)) return e;
281
- else !n && i.type.rank > this.type.rank && (t ||= e.slice(0, r), t.push(this), n = !0), t && t.push(i);
282
- }
283
- return t ||= e.slice(), n || t.push(this), t;
284
- }
285
- removeFromSet(e) {
286
- for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return e.slice(0, t).concat(e.slice(t + 1));
287
- return e;
288
- }
289
- isInSet(e) {
290
- for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return !0;
291
- return !1;
292
- }
293
- eq(e) {
294
- return this == e || this.type == e.type && o(this.attrs, e.attrs);
295
- }
296
- toJSON() {
297
- let e = { type: this.type.name };
298
- for (let t in this.attrs) {
299
- e.attrs = this.attrs;
300
- break;
301
- }
302
- return e;
303
- }
304
- static fromJSON(e, t) {
305
- if (!t) throw RangeError("Invalid input for Mark.fromJSON");
306
- let n = e.marks[t.type];
307
- if (!n) throw RangeError(`There is no mark type ${t.type} in this schema`);
308
- let r = n.create(t.attrs);
309
- return n.checkAttrs(r.attrs), r;
310
- }
311
- static sameSet(e, t) {
312
- if (e == t) return !0;
313
- if (e.length != t.length) return !1;
314
- for (let n = 0; n < e.length; n++) if (!e[n].eq(t[n])) return !1;
315
- return !0;
316
- }
317
- static setFrom(t) {
318
- if (!t || Array.isArray(t) && t.length == 0) return e.none;
319
- if (t instanceof e) return [t];
320
- let n = t.slice();
321
- return n.sort((e, t) => e.type.rank - t.type.rank), n;
322
- }
323
- };
324
- s.none = [];
325
- var c = class extends Error {}, l = class e {
326
- constructor(e, t, n) {
327
- this.content = e, this.openStart = t, this.openEnd = n;
328
- }
329
- get size() {
330
- return this.content.size - this.openStart - this.openEnd;
331
- }
332
- insertAt(t, n) {
333
- let r = d(this.content, t + this.openStart, n, this.openStart + 1, this.openEnd + 1);
334
- return r && new e(r, this.openStart, this.openEnd);
335
- }
336
- removeBetween(t, n) {
337
- return new e(u(this.content, t + this.openStart, n + this.openStart), this.openStart, this.openEnd);
338
- }
339
- eq(e) {
340
- return this.content.eq(e.content) && this.openStart == e.openStart && this.openEnd == e.openEnd;
341
- }
342
- toString() {
343
- return this.content + "(" + this.openStart + "," + this.openEnd + ")";
344
- }
345
- toJSON() {
346
- if (!this.content.size) return null;
347
- let e = { content: this.content.toJSON() };
348
- return this.openStart > 0 && (e.openStart = this.openStart), this.openEnd > 0 && (e.openEnd = this.openEnd), e;
349
- }
350
- static fromJSON(t, n) {
351
- if (!n) return e.empty;
352
- let i = n.openStart || 0, a = n.openEnd || 0;
353
- if (typeof i != "number" || typeof a != "number") throw RangeError("Invalid input for Slice.fromJSON");
354
- return new e(r.fromJSON(t, n.content), i, a);
355
- }
356
- static maxOpen(t, n = !0) {
357
- let r = 0, i = 0;
358
- for (let e = t.firstChild; e && !e.isLeaf && (n || !e.type.spec.isolating); e = e.firstChild) r++;
359
- for (let e = t.lastChild; e && !e.isLeaf && (n || !e.type.spec.isolating); e = e.lastChild) i++;
360
- return new e(t, r, i);
361
- }
362
- };
363
- l.empty = new l(r.empty, 0, 0);
364
- function u(e, t, n) {
365
- let { index: r, offset: i } = e.findIndex(t), a = e.maybeChild(r), { index: o, offset: s } = e.findIndex(n);
366
- if (i == t || a.isText) {
367
- if (s != n && !e.child(o).isText) throw RangeError("Removing non-flat range");
368
- return e.cut(0, t).append(e.cut(n));
369
- }
370
- if (r != o) throw RangeError("Removing non-flat range");
371
- return e.replaceChild(r, a.copy(u(a.content, t - i - 1, n - i - 1)));
372
- }
373
- function d(e, t, n, r, i, a) {
374
- let { index: o, offset: s } = e.findIndex(t), c = e.maybeChild(o);
375
- if (s == t || c.isText) return a && r <= 0 && i <= 0 && !a.canReplace(o, o, n) ? null : e.cut(0, t).append(n).append(e.cut(t));
376
- let l = d(c.content, t - s - 1, n, o == 0 ? r - 1 : 0, o == e.childCount - 1 ? i - 1 : 0, c);
377
- return l && e.replaceChild(o, c.copy(l));
378
- }
379
- function f(e, t, n) {
380
- if (n.openStart > e.depth) throw new c("Inserted content deeper than insertion position");
381
- if (e.depth - n.openStart != t.depth - n.openEnd) throw new c("Inconsistent open depths");
382
- return p(e, t, n, 0);
383
- }
384
- function p(e, t, n, r) {
385
- let i = e.index(r), a = e.node(r);
386
- if (i == t.index(r) && r < e.depth - n.openStart) {
387
- let o = p(e, t, n, r + 1);
388
- return a.copy(a.content.replaceChild(i, o));
389
- } else if (!n.content.size) return v(a, y(e, t, r));
390
- else if (!n.openStart && !n.openEnd && e.depth == r && t.depth == r) {
391
- let r = e.parent, i = r.content;
392
- return v(r, i.cut(0, e.parentOffset).append(n.content).append(i.cut(t.parentOffset)));
393
- } else {
394
- let { start: i, end: o } = te(n, e);
395
- return v(a, ee(e, i, o, t, r));
396
- }
397
- }
398
- function m(e, t) {
399
- if (!t.type.compatibleContent(e.type)) throw new c("Cannot join " + t.type.name + " onto " + e.type.name);
400
- }
401
- function h(e, t, n) {
402
- let r = e.node(n);
403
- return m(r, t.node(n)), r;
404
- }
405
- function g(e, t) {
406
- let n = t.length - 1;
407
- n >= 0 && e.isText && e.sameMarkup(t[n]) ? t[n] = e.withText(t[n].text + e.text) : t.push(e);
408
- }
409
- function _(e, t, n, r) {
410
- let i = (t || e).node(n), a = 0, o = t ? t.index(n) : i.childCount;
411
- e && (a = e.index(n), e.depth > n ? a++ : e.textOffset && (g(e.nodeAfter, r), a++));
412
- for (let e = a; e < o; e++) g(i.child(e), r);
413
- t && t.depth == n && t.textOffset && g(t.nodeBefore, r);
414
- }
415
- function v(e, t) {
416
- return e.type.checkContent(t), e.copy(t);
417
- }
418
- function ee(e, t, n, i, a) {
419
- let o = e.depth > a && h(e, t, a + 1), s = i.depth > a && h(n, i, a + 1), c = [];
420
- return _(null, e, a, c), o && s && t.index(a) == n.index(a) ? (m(o, s), g(v(o, ee(e, t, n, i, a + 1)), c)) : (o && g(v(o, y(e, t, a + 1)), c), _(t, n, a, c), s && g(v(s, y(n, i, a + 1)), c)), _(i, null, a, c), new r(c);
421
- }
422
- function y(e, t, n) {
423
- let i = [];
424
- return _(null, e, n, i), e.depth > n && g(v(h(e, t, n + 1), y(e, t, n + 1)), i), _(t, null, n, i), new r(i);
425
- }
426
- function te(e, t) {
427
- let n = t.depth - e.openStart, i = t.node(n).copy(e.content);
428
- for (let e = n - 1; e >= 0; e--) i = t.node(e).copy(r.from(i));
429
- return {
430
- start: i.resolveNoCache(e.openStart + n),
431
- end: i.resolveNoCache(i.content.size - e.openEnd - n)
432
- };
433
- }
434
- var ne = class e {
435
- constructor(e, t, n) {
436
- this.pos = e, this.path = t, this.parentOffset = n, this.depth = t.length / 3 - 1;
437
- }
438
- resolveDepth(e) {
439
- return e == null ? this.depth : e < 0 ? this.depth + e : e;
440
- }
441
- get parent() {
442
- return this.node(this.depth);
443
- }
444
- get doc() {
445
- return this.node(0);
446
- }
447
- node(e) {
448
- return this.path[this.resolveDepth(e) * 3];
449
- }
450
- index(e) {
451
- return this.path[this.resolveDepth(e) * 3 + 1];
452
- }
453
- indexAfter(e) {
454
- return e = this.resolveDepth(e), this.index(e) + (e == this.depth && !this.textOffset ? 0 : 1);
455
- }
456
- start(e) {
457
- return e = this.resolveDepth(e), e == 0 ? 0 : this.path[e * 3 - 1] + 1;
458
- }
459
- end(e) {
460
- return e = this.resolveDepth(e), this.start(e) + this.node(e).content.size;
461
- }
462
- before(e) {
463
- if (e = this.resolveDepth(e), !e) throw RangeError("There is no position before the top-level node");
464
- return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1];
465
- }
466
- after(e) {
467
- if (e = this.resolveDepth(e), !e) throw RangeError("There is no position after the top-level node");
468
- return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1] + this.path[e * 3].nodeSize;
469
- }
470
- get textOffset() {
471
- return this.pos - this.path[this.path.length - 1];
472
- }
473
- get nodeAfter() {
474
- let e = this.parent, t = this.index(this.depth);
475
- if (t == e.childCount) return null;
476
- let n = this.pos - this.path[this.path.length - 1], r = e.child(t);
477
- return n ? e.child(t).cut(n) : r;
478
- }
479
- get nodeBefore() {
480
- let e = this.index(this.depth), t = this.pos - this.path[this.path.length - 1];
481
- return t ? this.parent.child(e).cut(0, t) : e == 0 ? null : this.parent.child(e - 1);
482
- }
483
- posAtIndex(e, t) {
484
- t = this.resolveDepth(t);
485
- let n = this.path[t * 3], r = t == 0 ? 0 : this.path[t * 3 - 1] + 1;
486
- for (let t = 0; t < e; t++) r += n.child(t).nodeSize;
487
- return r;
488
- }
489
- marks() {
490
- let e = this.parent, t = this.index();
491
- if (e.content.size == 0) return s.none;
492
- if (this.textOffset) return e.child(t).marks;
493
- let n = e.maybeChild(t - 1), r = e.maybeChild(t);
494
- if (!n) {
495
- let e = n;
496
- n = r, r = e;
497
- }
498
- let i = n.marks;
499
- for (var a = 0; a < i.length; a++) i[a].type.spec.inclusive === !1 && (!r || !i[a].isInSet(r.marks)) && (i = i[a--].removeFromSet(i));
500
- return i;
501
- }
502
- marksAcross(e) {
503
- let t = this.parent.maybeChild(this.index());
504
- if (!t || !t.isInline) return null;
505
- let n = t.marks, r = e.parent.maybeChild(e.index());
506
- for (var i = 0; i < n.length; i++) n[i].type.spec.inclusive === !1 && (!r || !n[i].isInSet(r.marks)) && (n = n[i--].removeFromSet(n));
507
- return n;
508
- }
509
- sharedDepth(e) {
510
- for (let t = this.depth; t > 0; t--) if (this.start(t) <= e && this.end(t) >= e) return t;
511
- return 0;
512
- }
513
- blockRange(e = this, t) {
514
- if (e.pos < this.pos) return e.blockRange(this);
515
- for (let n = this.depth - (this.parent.inlineContent || this.pos == e.pos ? 1 : 0); n >= 0; n--) if (e.pos <= this.end(n) && (!t || t(this.node(n)))) return new oe(this, e, n);
516
- return null;
517
- }
518
- sameParent(e) {
519
- return this.pos - this.parentOffset == e.pos - e.parentOffset;
520
- }
521
- max(e) {
522
- return e.pos > this.pos ? e : this;
523
- }
524
- min(e) {
525
- return e.pos < this.pos ? e : this;
526
- }
527
- toString() {
528
- let e = "";
529
- for (let t = 1; t <= this.depth; t++) e += (e ? "/" : "") + this.node(t).type.name + "_" + this.index(t - 1);
530
- return e + ":" + this.parentOffset;
531
- }
532
- static resolve(t, n) {
533
- if (!(n >= 0 && n <= t.content.size)) throw RangeError("Position " + n + " out of range");
534
- let r = [], i = 0, a = n;
535
- for (let e = t;;) {
536
- let { index: t, offset: n } = e.content.findIndex(a), o = a - n;
537
- if (r.push(e, t, i + n), !o || (e = e.child(t), e.isText)) break;
538
- a = o - 1, i += n + 1;
539
- }
540
- return new e(n, r, a);
541
- }
542
- static resolveCached(t, n) {
543
- let r = ae.get(t);
544
- if (r) for (let e = 0; e < r.elts.length; e++) {
545
- let t = r.elts[e];
546
- if (t.pos == n) return t;
547
- }
548
- else ae.set(t, r = new re());
549
- let i = r.elts[r.i] = e.resolve(t, n);
550
- return r.i = (r.i + 1) % ie, i;
551
- }
552
- }, re = class {
553
- constructor() {
554
- this.elts = [], this.i = 0;
555
- }
556
- }, ie = 12, ae = /* @__PURE__ */ new WeakMap(), oe = class {
557
- constructor(e, t, n) {
558
- this.$from = e, this.$to = t, this.depth = n;
559
- }
560
- get start() {
561
- return this.$from.before(this.depth + 1);
562
- }
563
- get end() {
564
- return this.$to.after(this.depth + 1);
565
- }
566
- get parent() {
567
- return this.$from.node(this.depth);
568
- }
569
- get startIndex() {
570
- return this.$from.index(this.depth);
571
- }
572
- get endIndex() {
573
- return this.$to.indexAfter(this.depth);
574
- }
575
- }, se = Object.create(null), b = class e {
576
- constructor(e, t, n, i = s.none) {
577
- this.type = e, this.attrs = t, this.marks = i, this.content = n || r.empty;
578
- }
579
- get children() {
580
- return this.content.content;
581
- }
582
- get nodeSize() {
583
- return this.isLeaf ? 1 : 2 + this.content.size;
584
- }
585
- get childCount() {
586
- return this.content.childCount;
587
- }
588
- child(e) {
589
- return this.content.child(e);
590
- }
591
- maybeChild(e) {
592
- return this.content.maybeChild(e);
593
- }
594
- forEach(e) {
595
- this.content.forEach(e);
596
- }
597
- nodesBetween(e, t, n, r = 0) {
598
- this.content.nodesBetween(e, t, n, r, this);
599
- }
600
- descendants(e) {
601
- this.nodesBetween(0, this.content.size, e);
602
- }
603
- get textContent() {
604
- return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
605
- }
606
- textBetween(e, t, n, r) {
607
- return this.content.textBetween(e, t, n, r);
608
- }
609
- get firstChild() {
610
- return this.content.firstChild;
611
- }
612
- get lastChild() {
613
- return this.content.lastChild;
614
- }
615
- eq(e) {
616
- return this == e || this.sameMarkup(e) && this.content.eq(e.content);
617
- }
618
- sameMarkup(e) {
619
- return this.hasMarkup(e.type, e.attrs, e.marks);
620
- }
621
- hasMarkup(e, t, n) {
622
- return this.type == e && o(this.attrs, t || e.defaultAttrs || se) && s.sameSet(this.marks, n || s.none);
623
- }
624
- copy(t = null) {
625
- return t == this.content ? this : new e(this.type, this.attrs, t, this.marks);
626
- }
627
- mark(t) {
628
- return t == this.marks ? this : new e(this.type, this.attrs, this.content, t);
629
- }
630
- cut(e, t = this.content.size) {
631
- return e == 0 && t == this.content.size ? this : this.copy(this.content.cut(e, t));
632
- }
633
- slice(e, t = this.content.size, n = !1) {
634
- if (e == t) return l.empty;
635
- let r = this.resolve(e), i = this.resolve(t), a = n ? 0 : r.sharedDepth(t), o = r.start(a);
636
- return new l(r.node(a).content.cut(r.pos - o, i.pos - o), r.depth - a, i.depth - a);
637
- }
638
- replace(e, t, n) {
639
- return f(this.resolve(e), this.resolve(t), n);
640
- }
641
- nodeAt(e) {
642
- for (let t = this;;) {
643
- let { index: n, offset: r } = t.content.findIndex(e);
644
- if (t = t.maybeChild(n), !t) return null;
645
- if (r == e || t.isText) return t;
646
- e -= r + 1;
647
- }
648
- }
649
- childAfter(e) {
650
- let { index: t, offset: n } = this.content.findIndex(e);
651
- return {
652
- node: this.content.maybeChild(t),
653
- index: t,
654
- offset: n
655
- };
656
- }
657
- childBefore(e) {
658
- if (e == 0) return {
659
- node: null,
660
- index: 0,
661
- offset: 0
662
- };
663
- let { index: t, offset: n } = this.content.findIndex(e);
664
- if (n < e) return {
665
- node: this.content.child(t),
666
- index: t,
667
- offset: n
668
- };
669
- let r = this.content.child(t - 1);
670
- return {
671
- node: r,
672
- index: t - 1,
673
- offset: n - r.nodeSize
674
- };
675
- }
676
- resolve(e) {
677
- return ne.resolveCached(this, e);
678
- }
679
- resolveNoCache(e) {
680
- return ne.resolve(this, e);
681
- }
682
- rangeHasMark(e, t, n) {
683
- let r = !1;
684
- return t > e && this.nodesBetween(e, t, (e) => (n.isInSet(e.marks) && (r = !0), !r)), r;
685
- }
686
- get isBlock() {
687
- return this.type.isBlock;
688
- }
689
- get isTextblock() {
690
- return this.type.isTextblock;
691
- }
692
- get inlineContent() {
693
- return this.type.inlineContent;
694
- }
695
- get isInline() {
696
- return this.type.isInline;
697
- }
698
- get isText() {
699
- return this.type.isText;
700
- }
701
- get isLeaf() {
702
- return this.type.isLeaf;
703
- }
704
- get isAtom() {
705
- return this.type.isAtom;
706
- }
707
- toString() {
708
- if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this);
709
- let e = this.type.name;
710
- return this.content.size && (e += "(" + this.content.toStringInner() + ")"), le(this.marks, e);
711
- }
712
- contentMatchAt(e) {
713
- let t = this.type.contentMatch.matchFragment(this.content, 0, e);
714
- if (!t) throw Error("Called contentMatchAt on a node with invalid content");
715
- return t;
716
- }
717
- canReplace(e, t, n = r.empty, i = 0, a = n.childCount) {
718
- let o = this.contentMatchAt(e).matchFragment(n, i, a), s = o && o.matchFragment(this.content, t);
719
- if (!s || !s.validEnd) return !1;
720
- for (let e = i; e < a; e++) if (!this.type.allowsMarks(n.child(e).marks)) return !1;
721
- return !0;
722
- }
723
- canReplaceWith(e, t, n, r) {
724
- if (r && !this.type.allowsMarks(r)) return !1;
725
- let i = this.contentMatchAt(e).matchType(n), a = i && i.matchFragment(this.content, t);
726
- return a ? a.validEnd : !1;
727
- }
728
- canAppend(e) {
729
- return e.content.size ? this.canReplace(this.childCount, this.childCount, e.content) : this.type.compatibleContent(e.type);
730
- }
731
- check() {
732
- this.type.checkContent(this.content), this.type.checkAttrs(this.attrs);
733
- let e = s.none;
734
- for (let t = 0; t < this.marks.length; t++) {
735
- let n = this.marks[t];
736
- n.type.checkAttrs(n.attrs), e = n.addToSet(e);
737
- }
738
- if (!s.sameSet(e, this.marks)) throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((e) => e.type.name)}`);
739
- this.content.forEach((e) => e.check());
740
- }
741
- toJSON() {
742
- let e = { type: this.type.name };
743
- for (let t in this.attrs) {
744
- e.attrs = this.attrs;
745
- break;
746
- }
747
- return this.content.size && (e.content = this.content.toJSON()), this.marks.length && (e.marks = this.marks.map((e) => e.toJSON())), e;
748
- }
749
- static fromJSON(e, t) {
750
- if (!t) throw RangeError("Invalid input for Node.fromJSON");
751
- let n;
752
- if (t.marks) {
753
- if (!Array.isArray(t.marks)) throw RangeError("Invalid mark data for Node.fromJSON");
754
- n = t.marks.map(e.markFromJSON);
755
- }
756
- if (t.type == "text") {
757
- if (typeof t.text != "string") throw RangeError("Invalid text node in JSON");
758
- return e.text(t.text, n);
759
- }
760
- let i = r.fromJSON(e, t.content), a = e.nodeType(t.type).create(t.attrs, i, n);
761
- return a.type.checkAttrs(a.attrs), a;
762
- }
763
- };
764
- b.prototype.text = void 0;
765
- var ce = class e extends b {
766
- constructor(e, t, n, r) {
767
- if (super(e, t, null, r), !n) throw RangeError("Empty text nodes are not allowed");
768
- this.text = n;
769
- }
770
- toString() {
771
- return this.type.spec.toDebugString ? this.type.spec.toDebugString(this) : le(this.marks, JSON.stringify(this.text));
772
- }
773
- get textContent() {
774
- return this.text;
775
- }
776
- textBetween(e, t) {
777
- return this.text.slice(e, t);
778
- }
779
- get nodeSize() {
780
- return this.text.length;
781
- }
782
- mark(t) {
783
- return t == this.marks ? this : new e(this.type, this.attrs, this.text, t);
784
- }
785
- withText(t) {
786
- return t == this.text ? this : new e(this.type, this.attrs, t, this.marks);
787
- }
788
- cut(e = 0, t = this.text.length) {
789
- return e == 0 && t == this.text.length ? this : this.withText(this.text.slice(e, t));
790
- }
791
- eq(e) {
792
- return this.sameMarkup(e) && this.text == e.text;
793
- }
794
- toJSON() {
795
- let e = super.toJSON();
796
- return e.text = this.text, e;
797
- }
798
- };
799
- function le(e, t) {
800
- for (let n = e.length - 1; n >= 0; n--) t = e[n].type.name + "(" + t + ")";
801
- return t;
802
- }
803
- var x = class e {
804
- constructor(e) {
805
- this.validEnd = e, this.next = [], this.wrapCache = [];
806
- }
807
- static parse(t, n) {
808
- let r = new ue(t, n);
809
- if (r.next == null) return e.empty;
810
- let i = de(r);
811
- r.next && r.err("Unexpected trailing text");
812
- let a = xe(ve(i));
813
- return Se(a, r), a;
814
- }
815
- matchType(e) {
816
- for (let t = 0; t < this.next.length; t++) if (this.next[t].type == e) return this.next[t].next;
817
- return null;
818
- }
819
- matchFragment(e, t = 0, n = e.childCount) {
820
- let r = this;
821
- for (let i = t; r && i < n; i++) r = r.matchType(e.child(i).type);
822
- return r;
823
- }
824
- get inlineContent() {
825
- return this.next.length != 0 && this.next[0].type.isInline;
826
- }
827
- get defaultType() {
828
- for (let e = 0; e < this.next.length; e++) {
829
- let { type: t } = this.next[e];
830
- if (!(t.isText || t.hasRequiredAttrs())) return t;
831
- }
832
- return null;
833
- }
834
- compatible(e) {
835
- for (let t = 0; t < this.next.length; t++) for (let n = 0; n < e.next.length; n++) if (this.next[t].type == e.next[n].type) return !0;
836
- return !1;
837
- }
838
- fillBefore(e, t = !1, n = 0) {
839
- let i = [this];
840
- function a(o, s) {
841
- let c = o.matchFragment(e, n);
842
- if (c && (!t || c.validEnd)) return r.from(s.map((e) => e.createAndFill()));
843
- for (let e = 0; e < o.next.length; e++) {
844
- let { type: t, next: n } = o.next[e];
845
- if (!(t.isText || t.hasRequiredAttrs()) && i.indexOf(n) == -1) {
846
- i.push(n);
847
- let e = a(n, s.concat(t));
848
- if (e) return e;
849
- }
850
- }
851
- return null;
852
- }
853
- return a(this, []);
854
- }
855
- findWrapping(e) {
856
- for (let t = 0; t < this.wrapCache.length; t += 2) if (this.wrapCache[t] == e) return this.wrapCache[t + 1];
857
- let t = this.computeWrapping(e);
858
- return this.wrapCache.push(e, t), t;
859
- }
860
- computeWrapping(e) {
861
- let t = Object.create(null), n = [{
862
- match: this,
863
- type: null,
864
- via: null
865
- }];
866
- for (; n.length;) {
867
- let r = n.shift(), i = r.match;
868
- if (i.matchType(e)) {
869
- let e = [];
870
- for (let t = r; t.type; t = t.via) e.push(t.type);
871
- return e.reverse();
872
- }
873
- for (let e = 0; e < i.next.length; e++) {
874
- let { type: a, next: o } = i.next[e];
875
- !a.isLeaf && !a.hasRequiredAttrs() && !(a.name in t) && (!r.type || o.validEnd) && (n.push({
876
- match: a.contentMatch,
877
- type: a,
878
- via: r
879
- }), t[a.name] = !0);
880
- }
881
- }
882
- return null;
883
- }
884
- get edgeCount() {
885
- return this.next.length;
886
- }
887
- edge(e) {
888
- if (e >= this.next.length) throw RangeError(`There's no ${e}th edge in this content match`);
889
- return this.next[e];
890
- }
891
- toString() {
892
- let e = [];
893
- function t(n) {
894
- e.push(n);
895
- for (let r = 0; r < n.next.length; r++) e.indexOf(n.next[r].next) == -1 && t(n.next[r].next);
896
- }
897
- return t(this), e.map((t, n) => {
898
- let r = n + (t.validEnd ? "*" : " ") + " ";
899
- for (let n = 0; n < t.next.length; n++) r += (n ? ", " : "") + t.next[n].type.name + "->" + e.indexOf(t.next[n].next);
900
- return r;
901
- }).join("\n");
902
- }
903
- };
904
- x.empty = new x(!0);
905
- var ue = class {
906
- constructor(e, t) {
907
- this.string = e, this.nodeTypes = t, this.inline = null, this.pos = 0, this.tokens = e.split(/\s*(?=\b|\W|$)/), this.tokens[this.tokens.length - 1] == "" && this.tokens.pop(), this.tokens[0] == "" && this.tokens.shift();
908
- }
909
- get next() {
910
- return this.tokens[this.pos];
911
- }
912
- eat(e) {
913
- return this.next == e && (this.pos++ || !0);
914
- }
915
- err(e) {
916
- throw SyntaxError(e + " (in content expression '" + this.string + "')");
917
- }
918
- };
919
- function de(e) {
920
- let t = [];
921
- do
922
- t.push(fe(e));
923
- while (e.eat("|"));
924
- return t.length == 1 ? t[0] : {
925
- type: "choice",
926
- exprs: t
927
- };
928
- }
929
- function fe(e) {
930
- let t = [];
931
- do
932
- t.push(pe(e));
933
- while (e.next && e.next != ")" && e.next != "|");
934
- return t.length == 1 ? t[0] : {
935
- type: "seq",
936
- exprs: t
937
- };
938
- }
939
- function pe(e) {
940
- let t = _e(e);
941
- for (;;) if (e.eat("+")) t = {
942
- type: "plus",
943
- expr: t
944
- };
945
- else if (e.eat("*")) t = {
946
- type: "star",
947
- expr: t
948
- };
949
- else if (e.eat("?")) t = {
950
- type: "opt",
951
- expr: t
952
- };
953
- else if (e.eat("{")) t = he(e, t);
954
- else break;
955
- return t;
956
- }
957
- function me(e) {
958
- /\D/.test(e.next) && e.err("Expected number, got '" + e.next + "'");
959
- let t = Number(e.next);
960
- return e.pos++, t;
961
- }
962
- function he(e, t) {
963
- let n = me(e), r = n;
964
- return e.eat(",") && (r = e.next == "}" ? -1 : me(e)), e.eat("}") || e.err("Unclosed braced range"), {
965
- type: "range",
966
- min: n,
967
- max: r,
968
- expr: t
969
- };
970
- }
971
- function ge(e, t) {
972
- let n = e.nodeTypes, r = n[t];
973
- if (r) return [r];
974
- let i = [];
975
- for (let e in n) {
976
- let r = n[e];
977
- r.isInGroup(t) && i.push(r);
978
- }
979
- return i.length == 0 && e.err("No node type or group '" + t + "' found"), i;
980
- }
981
- function _e(e) {
982
- if (e.eat("(")) {
983
- let t = de(e);
984
- return e.eat(")") || e.err("Missing closing paren"), t;
985
- } else if (/\W/.test(e.next)) e.err("Unexpected token '" + e.next + "'");
986
- else {
987
- let t = ge(e, e.next).map((t) => (e.inline == null ? e.inline = t.isInline : e.inline != t.isInline && e.err("Mixing inline and block content"), {
988
- type: "name",
989
- value: t
990
- }));
991
- return e.pos++, t.length == 1 ? t[0] : {
992
- type: "choice",
993
- exprs: t
994
- };
995
- }
996
- }
997
- function ve(e) {
998
- let t = [[]];
999
- return i(a(e, 0), n()), t;
1000
- function n() {
1001
- return t.push([]) - 1;
1002
- }
1003
- function r(e, n, r) {
1004
- let i = {
1005
- term: r,
1006
- to: n
1007
- };
1008
- return t[e].push(i), i;
1009
- }
1010
- function i(e, t) {
1011
- e.forEach((e) => e.to = t);
1012
- }
1013
- function a(e, t) {
1014
- if (e.type == "choice") return e.exprs.reduce((e, n) => e.concat(a(n, t)), []);
1015
- if (e.type == "seq") for (let r = 0;; r++) {
1016
- let o = a(e.exprs[r], t);
1017
- if (r == e.exprs.length - 1) return o;
1018
- i(o, t = n());
1019
- }
1020
- else if (e.type == "star") {
1021
- let o = n();
1022
- return r(t, o), i(a(e.expr, o), o), [r(o)];
1023
- } else if (e.type == "plus") {
1024
- let o = n();
1025
- return i(a(e.expr, t), o), i(a(e.expr, o), o), [r(o)];
1026
- } else if (e.type == "opt") return [r(t)].concat(a(e.expr, t));
1027
- else if (e.type == "range") {
1028
- let o = t;
1029
- for (let t = 0; t < e.min; t++) {
1030
- let t = n();
1031
- i(a(e.expr, o), t), o = t;
1032
- }
1033
- if (e.max == -1) i(a(e.expr, o), o);
1034
- else for (let t = e.min; t < e.max; t++) {
1035
- let t = n();
1036
- r(o, t), i(a(e.expr, o), t), o = t;
1037
- }
1038
- return [r(o)];
1039
- } else if (e.type == "name") return [r(t, void 0, e.value)];
1040
- else throw Error("Unknown expr type");
1041
- }
1042
- }
1043
- function ye(e, t) {
1044
- return t - e;
1045
- }
1046
- function be(e, t) {
1047
- let n = [];
1048
- return r(t), n.sort(ye);
1049
- function r(t) {
1050
- let i = e[t];
1051
- if (i.length == 1 && !i[0].term) return r(i[0].to);
1052
- n.push(t);
1053
- for (let e = 0; e < i.length; e++) {
1054
- let { term: t, to: a } = i[e];
1055
- !t && n.indexOf(a) == -1 && r(a);
1056
- }
1057
- }
1058
- }
1059
- function xe(e) {
1060
- let t = Object.create(null);
1061
- return n(be(e, 0));
1062
- function n(r) {
1063
- let i = [];
1064
- r.forEach((t) => {
1065
- e[t].forEach(({ term: t, to: n }) => {
1066
- if (!t) return;
1067
- let r;
1068
- for (let e = 0; e < i.length; e++) i[e][0] == t && (r = i[e][1]);
1069
- be(e, n).forEach((e) => {
1070
- r || i.push([t, r = []]), r.indexOf(e) == -1 && r.push(e);
1071
- });
1072
- });
1073
- });
1074
- let a = t[r.join(",")] = new x(r.indexOf(e.length - 1) > -1);
1075
- for (let e = 0; e < i.length; e++) {
1076
- let r = i[e][1].sort(ye);
1077
- a.next.push({
1078
- type: i[e][0],
1079
- next: t[r.join(",")] || n(r)
1080
- });
1081
- }
1082
- return a;
1083
- }
1084
- }
1085
- function Se(e, t) {
1086
- for (let n = 0, r = [e]; n < r.length; n++) {
1087
- let e = r[n], i = !e.validEnd, a = [];
1088
- for (let t = 0; t < e.next.length; t++) {
1089
- let { type: n, next: o } = e.next[t];
1090
- a.push(n.name), i && !(n.isText || n.hasRequiredAttrs()) && (i = !1), r.indexOf(o) == -1 && r.push(o);
1091
- }
1092
- i && t.err("Only non-generatable nodes (" + a.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
1093
- }
1094
- }
1095
- function Ce(e) {
1096
- let t = Object.create(null);
1097
- for (let n in e) {
1098
- let r = e[n];
1099
- if (!r.hasDefault) return null;
1100
- t[n] = r.default;
1101
- }
1102
- return t;
1103
- }
1104
- function we(e, t) {
1105
- let n = Object.create(null);
1106
- for (let r in e) {
1107
- let i = t && t[r];
1108
- if (i === void 0) {
1109
- let t = e[r];
1110
- if (t.hasDefault) i = t.default;
1111
- else throw RangeError("No value supplied for attribute " + r);
1112
- }
1113
- n[r] = i;
1114
- }
1115
- return n;
1116
- }
1117
- function Te(e, t, n, r) {
1118
- for (let r in t) if (!(r in e)) throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);
1119
- for (let n in e) {
1120
- let r = e[n];
1121
- r.validate && r.validate(t[n]);
1122
- }
1123
- }
1124
- function Ee(e, t) {
1125
- let n = Object.create(null);
1126
- if (t) for (let r in t) n[r] = new ke(e, r, t[r]);
1127
- return n;
1128
- }
1129
- var De = class e {
1130
- constructor(e, t, n) {
1131
- this.name = e, this.schema = t, this.spec = n, this.markSet = null, this.groups = n.group ? n.group.split(" ") : [], this.attrs = Ee(e, n.attrs), this.defaultAttrs = Ce(this.attrs), this.contentMatch = null, this.inlineContent = null, this.isBlock = !(n.inline || e == "text"), this.isText = e == "text";
1132
- }
1133
- get isInline() {
1134
- return !this.isBlock;
1135
- }
1136
- get isTextblock() {
1137
- return this.isBlock && this.inlineContent;
1138
- }
1139
- get isLeaf() {
1140
- return this.contentMatch == x.empty;
1141
- }
1142
- get isAtom() {
1143
- return this.isLeaf || !!this.spec.atom;
1144
- }
1145
- isInGroup(e) {
1146
- return this.groups.indexOf(e) > -1;
1147
- }
1148
- get whitespace() {
1149
- return this.spec.whitespace || (this.spec.code ? "pre" : "normal");
1150
- }
1151
- hasRequiredAttrs() {
1152
- for (let e in this.attrs) if (this.attrs[e].isRequired) return !0;
1153
- return !1;
1154
- }
1155
- compatibleContent(e) {
1156
- return this == e || this.contentMatch.compatible(e.contentMatch);
1157
- }
1158
- computeAttrs(e) {
1159
- return !e && this.defaultAttrs ? this.defaultAttrs : we(this.attrs, e);
1160
- }
1161
- create(e = null, t, n) {
1162
- if (this.isText) throw Error("NodeType.create can't construct text nodes");
1163
- return new b(this, this.computeAttrs(e), r.from(t), s.setFrom(n));
1164
- }
1165
- createChecked(e = null, t, n) {
1166
- return t = r.from(t), this.checkContent(t), new b(this, this.computeAttrs(e), t, s.setFrom(n));
1167
- }
1168
- createAndFill(e = null, t, n) {
1169
- if (e = this.computeAttrs(e), t = r.from(t), t.size) {
1170
- let e = this.contentMatch.fillBefore(t);
1171
- if (!e) return null;
1172
- t = e.append(t);
1173
- }
1174
- let i = this.contentMatch.matchFragment(t), a = i && i.fillBefore(r.empty, !0);
1175
- return a ? new b(this, e, t.append(a), s.setFrom(n)) : null;
1176
- }
1177
- validContent(e) {
1178
- let t = this.contentMatch.matchFragment(e);
1179
- if (!t || !t.validEnd) return !1;
1180
- for (let t = 0; t < e.childCount; t++) if (!this.allowsMarks(e.child(t).marks)) return !1;
1181
- return !0;
1182
- }
1183
- checkContent(e) {
1184
- if (!this.validContent(e)) throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0, 50)}`);
1185
- }
1186
- checkAttrs(e) {
1187
- Te(this.attrs, e, "node", this.name);
1188
- }
1189
- allowsMarkType(e) {
1190
- return this.markSet == null || this.markSet.indexOf(e) > -1;
1191
- }
1192
- allowsMarks(e) {
1193
- if (this.markSet == null) return !0;
1194
- for (let t = 0; t < e.length; t++) if (!this.allowsMarkType(e[t].type)) return !1;
1195
- return !0;
1196
- }
1197
- allowedMarks(e) {
1198
- if (this.markSet == null) return e;
1199
- let t;
1200
- for (let n = 0; n < e.length; n++) this.allowsMarkType(e[n].type) ? t && t.push(e[n]) : t ||= e.slice(0, n);
1201
- return t ? t.length ? t : s.none : e;
1202
- }
1203
- static compile(t, n) {
1204
- let r = Object.create(null);
1205
- t.forEach((t, i) => r[t] = new e(t, n, i));
1206
- let i = n.spec.topNode || "doc";
1207
- if (!r[i]) throw RangeError("Schema is missing its top node type ('" + i + "')");
1208
- if (!r.text) throw RangeError("Every schema needs a 'text' type");
1209
- for (let e in r.text.attrs) throw RangeError("The text node type should not have attributes");
1210
- return r;
1211
- }
1212
- };
1213
- function Oe(e, t, n) {
1214
- let r = n.split("|");
1215
- return (n) => {
1216
- let i = n === null ? "null" : typeof n;
1217
- if (r.indexOf(i) < 0) throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`);
1218
- };
1219
- }
1220
- var ke = class {
1221
- constructor(e, t, n) {
1222
- this.hasDefault = Object.prototype.hasOwnProperty.call(n, "default"), this.default = n.default, this.validate = typeof n.validate == "string" ? Oe(e, t, n.validate) : n.validate;
1223
- }
1224
- get isRequired() {
1225
- return !this.hasDefault;
1226
- }
1227
- }, Ae = class e {
1228
- constructor(e, t, n, r) {
1229
- this.name = e, this.rank = t, this.schema = n, this.spec = r, this.attrs = Ee(e, r.attrs), this.excluded = null;
1230
- let i = Ce(this.attrs);
1231
- this.instance = i ? new s(this, i) : null;
1232
- }
1233
- create(e = null) {
1234
- return !e && this.instance ? this.instance : new s(this, we(this.attrs, e));
1235
- }
1236
- static compile(t, n) {
1237
- let r = Object.create(null), i = 0;
1238
- return t.forEach((t, a) => r[t] = new e(t, i++, n, a)), r;
1239
- }
1240
- removeFromSet(e) {
1241
- for (var t = 0; t < e.length; t++) e[t].type == this && (e = e.slice(0, t).concat(e.slice(t + 1)), t--);
1242
- return e;
1243
- }
1244
- isInSet(e) {
1245
- for (let t = 0; t < e.length; t++) if (e[t].type == this) return e[t];
1246
- }
1247
- checkAttrs(e) {
1248
- Te(this.attrs, e, "mark", this.name);
1249
- }
1250
- excludes(e) {
1251
- return this.excluded.indexOf(e) > -1;
1252
- }
1253
- }, je = class {
1254
- constructor(t) {
1255
- this.linebreakReplacement = null, this.cached = Object.create(null);
1256
- let n = this.spec = {};
1257
- for (let e in t) n[e] = t[e];
1258
- n.nodes = e.from(t.nodes), n.marks = e.from(t.marks || {}), this.nodes = De.compile(this.spec.nodes, this), this.marks = Ae.compile(this.spec.marks, this);
1259
- let r = Object.create(null);
1260
- for (let e in this.nodes) {
1261
- if (e in this.marks) throw RangeError(e + " can not be both a node and a mark");
1262
- let t = this.nodes[e], n = t.spec.content || "", i = t.spec.marks;
1263
- if (t.contentMatch = r[n] || (r[n] = x.parse(n, this.nodes)), t.inlineContent = t.contentMatch.inlineContent, t.spec.linebreakReplacement) {
1264
- if (this.linebreakReplacement) throw RangeError("Multiple linebreak nodes defined");
1265
- if (!t.isInline || !t.isLeaf) throw RangeError("Linebreak replacement nodes must be inline leaf nodes");
1266
- this.linebreakReplacement = t;
1267
- }
1268
- t.markSet = i == "_" ? null : i ? Me(this, i.split(" ")) : i == "" || !t.inlineContent ? [] : null;
1269
- }
1270
- for (let e in this.marks) {
1271
- let t = this.marks[e], n = t.spec.excludes;
1272
- t.excluded = n == null ? [t] : n == "" ? [] : Me(this, n.split(" "));
1273
- }
1274
- this.nodeFromJSON = (e) => b.fromJSON(this, e), this.markFromJSON = (e) => s.fromJSON(this, e), this.topNodeType = this.nodes[this.spec.topNode || "doc"], this.cached.wrappings = Object.create(null);
1275
- }
1276
- node(e, t = null, n, r) {
1277
- if (typeof e == "string") e = this.nodeType(e);
1278
- else if (!(e instanceof De)) throw RangeError("Invalid node type: " + e);
1279
- else if (e.schema != this) throw RangeError("Node type from different schema used (" + e.name + ")");
1280
- return e.createChecked(t, n, r);
1281
- }
1282
- text(e, t) {
1283
- let n = this.nodes.text;
1284
- return new ce(n, n.defaultAttrs, e, s.setFrom(t));
1285
- }
1286
- mark(e, t) {
1287
- return typeof e == "string" && (e = this.marks[e]), e.create(t);
1288
- }
1289
- nodeType(e) {
1290
- let t = this.nodes[e];
1291
- if (!t) throw RangeError("Unknown node type: " + e);
1292
- return t;
1293
- }
1294
- };
1295
- function Me(e, t) {
1296
- let n = [];
1297
- for (let r = 0; r < t.length; r++) {
1298
- let i = t[r], a = e.marks[i], o = a;
1299
- if (a) n.push(a);
1300
- else for (let t in e.marks) {
1301
- let r = e.marks[t];
1302
- (i == "_" || r.spec.group && r.spec.group.split(" ").indexOf(i) > -1) && n.push(o = r);
1303
- }
1304
- if (!o) throw SyntaxError("Unknown mark type: '" + t[r] + "'");
1305
- }
1306
- return n;
1307
- }
1308
- function Ne(e) {
1309
- return e.tag != null;
1310
- }
1311
- function Pe(e) {
1312
- return e.style != null;
1313
- }
1314
- var Fe = class e {
1315
- constructor(e, t) {
1316
- this.schema = e, this.rules = t, this.tags = [], this.styles = [];
1317
- let n = this.matchedStyles = [];
1318
- t.forEach((e) => {
1319
- if (Ne(e)) this.tags.push(e);
1320
- else if (Pe(e)) {
1321
- let t = /[^=]*/.exec(e.style)[0];
1322
- n.indexOf(t) < 0 && n.push(t), this.styles.push(e);
1323
- }
1324
- }), this.normalizeLists = !this.tags.some((t) => {
1325
- if (!/^(ul|ol)\b/.test(t.tag) || !t.node) return !1;
1326
- let n = e.nodes[t.node];
1327
- return n.contentMatch.matchType(n);
1328
- });
1329
- }
1330
- parse(e, t = {}) {
1331
- let n = new Ve(this, t, !1);
1332
- return n.addAll(e, s.none, t.from, t.to), n.finish();
1333
- }
1334
- parseSlice(e, t = {}) {
1335
- let n = new Ve(this, t, !0);
1336
- return n.addAll(e, s.none, t.from, t.to), l.maxOpen(n.finish());
1337
- }
1338
- matchTag(e, t, n) {
1339
- for (let r = n ? this.tags.indexOf(n) + 1 : 0; r < this.tags.length; r++) {
1340
- let n = this.tags[r];
1341
- if (Ue(e, n.tag) && (n.namespace === void 0 || e.namespaceURI == n.namespace) && (!n.context || t.matchesContext(n.context))) {
1342
- if (n.getAttrs) {
1343
- let t = n.getAttrs(e);
1344
- if (t === !1) continue;
1345
- n.attrs = t || void 0;
1346
- }
1347
- return n;
1348
- }
1349
- }
1350
- }
1351
- matchStyle(e, t, n, r) {
1352
- for (let i = r ? this.styles.indexOf(r) + 1 : 0; i < this.styles.length; i++) {
1353
- let r = this.styles[i], a = r.style;
1354
- if (!(a.indexOf(e) != 0 || r.context && !n.matchesContext(r.context) || a.length > e.length && (a.charCodeAt(e.length) != 61 || a.slice(e.length + 1) != t))) {
1355
- if (r.getAttrs) {
1356
- let e = r.getAttrs(t);
1357
- if (e === !1) continue;
1358
- r.attrs = e || void 0;
1359
- }
1360
- return r;
1361
- }
1362
- }
1363
- }
1364
- static schemaRules(e) {
1365
- let t = [];
1366
- function n(e) {
1367
- let n = e.priority == null ? 50 : e.priority, r = 0;
1368
- for (; r < t.length; r++) {
1369
- let e = t[r];
1370
- if ((e.priority == null ? 50 : e.priority) < n) break;
1371
- }
1372
- t.splice(r, 0, e);
1373
- }
1374
- for (let t in e.marks) {
1375
- let r = e.marks[t].spec.parseDOM;
1376
- r && r.forEach((e) => {
1377
- n(e = We(e)), e.mark || e.ignore || e.clearMark || (e.mark = t);
1378
- });
1379
- }
1380
- for (let t in e.nodes) {
1381
- let r = e.nodes[t].spec.parseDOM;
1382
- r && r.forEach((e) => {
1383
- n(e = We(e)), e.node || e.ignore || e.mark || (e.node = t);
1384
- });
1385
- }
1386
- return t;
1387
- }
1388
- static fromSchema(t) {
1389
- return t.cached.domParser || (t.cached.domParser = new e(t, e.schemaRules(t)));
1390
- }
1391
- }, Ie = {
1392
- address: !0,
1393
- article: !0,
1394
- aside: !0,
1395
- blockquote: !0,
1396
- canvas: !0,
1397
- dd: !0,
1398
- div: !0,
1399
- dl: !0,
1400
- fieldset: !0,
1401
- figcaption: !0,
1402
- figure: !0,
1403
- footer: !0,
1404
- form: !0,
1405
- h1: !0,
1406
- h2: !0,
1407
- h3: !0,
1408
- h4: !0,
1409
- h5: !0,
1410
- h6: !0,
1411
- header: !0,
1412
- hgroup: !0,
1413
- hr: !0,
1414
- li: !0,
1415
- noscript: !0,
1416
- ol: !0,
1417
- output: !0,
1418
- p: !0,
1419
- pre: !0,
1420
- section: !0,
1421
- table: !0,
1422
- tfoot: !0,
1423
- ul: !0
1424
- }, Le = {
1425
- head: !0,
1426
- noscript: !0,
1427
- object: !0,
1428
- script: !0,
1429
- style: !0,
1430
- title: !0
1431
- }, Re = {
1432
- ol: !0,
1433
- ul: !0
1434
- }, S = 1, ze = 2, C = 4;
1435
- function Be(e, t, n) {
1436
- return t == null ? e && e.whitespace == "pre" ? 3 : n & -5 : (t ? S : 0) | (t === "full" ? ze : 0);
1437
- }
1438
- var w = class {
1439
- constructor(e, t, n, r, i, a) {
1440
- this.type = e, this.attrs = t, this.marks = n, this.solid = r, this.options = a, this.content = [], this.activeMarks = s.none, this.match = i || (a & C ? null : e.contentMatch);
1441
- }
1442
- findWrapping(e) {
1443
- if (!this.match) {
1444
- if (!this.type) return [];
1445
- let t = this.type.contentMatch.fillBefore(r.from(e));
1446
- if (t) this.match = this.type.contentMatch.matchFragment(t);
1447
- else {
1448
- let t = this.type.contentMatch, n;
1449
- return (n = t.findWrapping(e.type)) ? (this.match = t, n) : null;
1450
- }
1451
- }
1452
- return this.match.findWrapping(e.type);
1453
- }
1454
- finish(e) {
1455
- if (!(this.options & S)) {
1456
- let e = this.content[this.content.length - 1], t;
1457
- if (e && e.isText && (t = /[ \t\r\n\u000c]+$/.exec(e.text))) {
1458
- let n = e;
1459
- e.text.length == t[0].length ? this.content.pop() : this.content[this.content.length - 1] = n.withText(n.text.slice(0, n.text.length - t[0].length));
1460
- }
1461
- }
1462
- let t = r.from(this.content);
1463
- return !e && this.match && (t = t.append(this.match.fillBefore(r.empty, !0))), this.type ? this.type.create(this.attrs, t, this.marks) : t;
1464
- }
1465
- inlineContext(e) {
1466
- return this.type ? this.type.inlineContent : this.content.length ? this.content[0].isInline : e.parentNode && !Ie.hasOwnProperty(e.parentNode.nodeName.toLowerCase());
1467
- }
1468
- }, Ve = class {
1469
- constructor(e, t, n) {
1470
- this.parser = e, this.options = t, this.isOpen = n, this.open = 0, this.localPreserveWS = !1;
1471
- let r = t.topNode, i, a = Be(null, t.preserveWhitespace, 0) | (n ? C : 0);
1472
- i = r ? new w(r.type, r.attrs, s.none, !0, t.topMatch || r.type.contentMatch, a) : n ? new w(null, null, s.none, !0, null, a) : new w(e.schema.topNodeType, null, s.none, !0, null, a), this.nodes = [i], this.find = t.findPositions, this.needsBlock = !1;
1473
- }
1474
- get top() {
1475
- return this.nodes[this.open];
1476
- }
1477
- addDOM(e, t) {
1478
- e.nodeType == 3 ? this.addTextNode(e, t) : e.nodeType == 1 && this.addElement(e, t);
1479
- }
1480
- addTextNode(e, t) {
1481
- let n = e.nodeValue, r = this.top, i = r.options & ze ? "full" : this.localPreserveWS || (r.options & S) > 0, { schema: a } = this.parser;
1482
- if (i === "full" || r.inlineContext(e) || /[^ \t\r\n\u000c]/.test(n)) {
1483
- if (!i) {
1484
- if (n = n.replace(/[ \t\r\n\u000c]+/g, " "), /^[ \t\r\n\u000c]/.test(n) && this.open == this.nodes.length - 1) {
1485
- let t = r.content[r.content.length - 1], i = e.previousSibling;
1486
- (!t || i && i.nodeName == "BR" || t.isText && /[ \t\r\n\u000c]$/.test(t.text)) && (n = n.slice(1));
1487
- }
1488
- } else if (i === "full") n = n.replace(/\r\n?/g, "\n");
1489
- else if (a.linebreakReplacement && /[\r\n]/.test(n) && this.top.findWrapping(a.linebreakReplacement.create())) {
1490
- let e = n.split(/\r?\n|\r/);
1491
- for (let n = 0; n < e.length; n++) n && this.insertNode(a.linebreakReplacement.create(), t, !0), e[n] && this.insertNode(a.text(e[n]), t, !/\S/.test(e[n]));
1492
- n = "";
1493
- } else n = n.replace(/\r?\n|\r/g, " ");
1494
- n && this.insertNode(a.text(n), t, !/\S/.test(n)), this.findInText(e);
1495
- } else this.findInside(e);
1496
- }
1497
- addElement(e, t, n) {
1498
- let r = this.localPreserveWS, i = this.top;
1499
- (e.tagName == "PRE" || /pre/.test(e.style && e.style.whiteSpace)) && (this.localPreserveWS = !0);
1500
- let a = e.nodeName.toLowerCase(), o;
1501
- Re.hasOwnProperty(a) && this.parser.normalizeLists && He(e);
1502
- let s = this.options.ruleFromNode && this.options.ruleFromNode(e) || (o = this.parser.matchTag(e, this, n));
1503
- out: if (s ? s.ignore : Le.hasOwnProperty(a)) this.findInside(e), this.ignoreFallback(e, t);
1504
- else if (!s || s.skip || s.closeParent) {
1505
- s && s.closeParent ? this.open = Math.max(0, this.open - 1) : s && s.skip.nodeType && (e = s.skip);
1506
- let n, r = this.needsBlock;
1507
- if (Ie.hasOwnProperty(a)) i.content.length && i.content[0].isInline && this.open && (this.open--, i = this.top), n = !0, i.type || (this.needsBlock = !0);
1508
- else if (!e.firstChild) {
1509
- this.leafFallback(e, t);
1510
- break out;
1511
- }
1512
- let o = s && s.skip ? t : this.readStyles(e, t);
1513
- o && this.addAll(e, o), n && this.sync(i), this.needsBlock = r;
1514
- } else {
1515
- let n = this.readStyles(e, t);
1516
- n && this.addElementByRule(e, s, n, s.consuming === !1 ? o : void 0);
1517
- }
1518
- this.localPreserveWS = r;
1519
- }
1520
- leafFallback(e, t) {
1521
- e.nodeName == "BR" && this.top.type && this.top.type.inlineContent && this.addTextNode(e.ownerDocument.createTextNode("\n"), t);
1522
- }
1523
- ignoreFallback(e, t) {
1524
- e.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent) && this.findPlace(this.parser.schema.text("-"), t, !0);
1525
- }
1526
- readStyles(e, t) {
1527
- let n = e.style;
1528
- if (n && n.length) for (let e = 0; e < this.parser.matchedStyles.length; e++) {
1529
- let r = this.parser.matchedStyles[e], i = n.getPropertyValue(r);
1530
- if (i) for (let e;;) {
1531
- let n = this.parser.matchStyle(r, i, this, e);
1532
- if (!n) break;
1533
- if (n.ignore) return null;
1534
- if (t = n.clearMark ? t.filter((e) => !n.clearMark(e)) : t.concat(this.parser.schema.marks[n.mark].create(n.attrs)), n.consuming === !1) e = n;
1535
- else break;
1536
- }
1537
- }
1538
- return t;
1539
- }
1540
- addElementByRule(e, t, n, r) {
1541
- let i, a;
1542
- if (t.node) if (a = this.parser.schema.nodes[t.node], a.isLeaf) this.insertNode(a.create(t.attrs), n, e.nodeName == "BR") || this.leafFallback(e, n);
1543
- else {
1544
- let e = this.enter(a, t.attrs || null, n, t.preserveWhitespace);
1545
- e && (i = !0, n = e);
1546
- }
1547
- else {
1548
- let e = this.parser.schema.marks[t.mark];
1549
- n = n.concat(e.create(t.attrs));
1550
- }
1551
- let o = this.top;
1552
- if (a && a.isLeaf) this.findInside(e);
1553
- else if (r) this.addElement(e, n, r);
1554
- else if (t.getContent) this.findInside(e), t.getContent(e, this.parser.schema).forEach((e) => this.insertNode(e, n, !1));
1555
- else {
1556
- let r = e;
1557
- typeof t.contentElement == "string" ? r = e.querySelector(t.contentElement) : typeof t.contentElement == "function" ? r = t.contentElement(e) : t.contentElement && (r = t.contentElement), this.findAround(e, r, !0), this.addAll(r, n), this.findAround(e, r, !1);
1558
- }
1559
- i && this.sync(o) && this.open--;
1560
- }
1561
- addAll(e, t, n, r) {
1562
- let i = n || 0;
1563
- for (let a = n ? e.childNodes[n] : e.firstChild, o = r == null ? null : e.childNodes[r]; a != o; a = a.nextSibling, ++i) this.findAtPoint(e, i), this.addDOM(a, t);
1564
- this.findAtPoint(e, i);
1565
- }
1566
- findPlace(e, t, n) {
1567
- let r, i;
1568
- for (let t = this.open, a = 0; t >= 0; t--) {
1569
- let o = this.nodes[t], s = o.findWrapping(e);
1570
- if (s && (!r || r.length > s.length + a) && (r = s, i = o, !s.length)) break;
1571
- if (o.solid) {
1572
- if (n) break;
1573
- a += 2;
1574
- }
1575
- }
1576
- if (!r) return null;
1577
- this.sync(i);
1578
- for (let e = 0; e < r.length; e++) t = this.enterInner(r[e], null, t, !1);
1579
- return t;
1580
- }
1581
- insertNode(e, t, n) {
1582
- if (e.isInline && this.needsBlock && !this.top.type) {
1583
- let e = this.textblockFromContext();
1584
- e && (t = this.enterInner(e, null, t));
1585
- }
1586
- let r = this.findPlace(e, t, n);
1587
- if (r) {
1588
- this.closeExtra();
1589
- let t = this.top;
1590
- t.match &&= t.match.matchType(e.type);
1591
- let n = s.none;
1592
- for (let i of r.concat(e.marks)) (t.type ? t.type.allowsMarkType(i.type) : Ge(i.type, e.type)) && (n = i.addToSet(n));
1593
- return t.content.push(e.mark(n)), !0;
1594
- }
1595
- return !1;
1596
- }
1597
- enter(e, t, n, r) {
1598
- let i = this.findPlace(e.create(t), n, !1);
1599
- return i &&= this.enterInner(e, t, n, !0, r), i;
1600
- }
1601
- enterInner(e, t, n, r = !1, i) {
1602
- this.closeExtra();
1603
- let a = this.top;
1604
- a.match = a.match && a.match.matchType(e);
1605
- let o = Be(e, i, a.options);
1606
- a.options & C && a.content.length == 0 && (o |= C);
1607
- let c = s.none;
1608
- return n = n.filter((t) => (a.type ? a.type.allowsMarkType(t.type) : Ge(t.type, e)) ? (c = t.addToSet(c), !1) : !0), this.nodes.push(new w(e, t, c, r, null, o)), this.open++, n;
1609
- }
1610
- closeExtra(e = !1) {
1611
- let t = this.nodes.length - 1;
1612
- if (t > this.open) {
1613
- for (; t > this.open; t--) this.nodes[t - 1].content.push(this.nodes[t].finish(e));
1614
- this.nodes.length = this.open + 1;
1615
- }
1616
- }
1617
- finish() {
1618
- return this.open = 0, this.closeExtra(this.isOpen), this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));
1619
- }
1620
- sync(e) {
1621
- for (let t = this.open; t >= 0; t--) if (this.nodes[t] == e) return this.open = t, !0;
1622
- else this.localPreserveWS && (this.nodes[t].options |= S);
1623
- return !1;
1624
- }
1625
- get currentPos() {
1626
- this.closeExtra();
1627
- let e = 0;
1628
- for (let t = this.open; t >= 0; t--) {
1629
- let n = this.nodes[t].content;
1630
- for (let t = n.length - 1; t >= 0; t--) e += n[t].nodeSize;
1631
- t && e++;
1632
- }
1633
- return e;
1634
- }
1635
- findAtPoint(e, t) {
1636
- if (this.find) for (let n = 0; n < this.find.length; n++) this.find[n].node == e && this.find[n].offset == t && (this.find[n].pos = this.currentPos);
1637
- }
1638
- findInside(e) {
1639
- if (this.find) for (let t = 0; t < this.find.length; t++) this.find[t].pos == null && e.nodeType == 1 && e.contains(this.find[t].node) && (this.find[t].pos = this.currentPos);
1640
- }
1641
- findAround(e, t, n) {
1642
- if (e != t && this.find) for (let r = 0; r < this.find.length; r++) this.find[r].pos == null && e.nodeType == 1 && e.contains(this.find[r].node) && t.compareDocumentPosition(this.find[r].node) & (n ? 2 : 4) && (this.find[r].pos = this.currentPos);
1643
- }
1644
- findInText(e) {
1645
- if (this.find) for (let t = 0; t < this.find.length; t++) this.find[t].node == e && (this.find[t].pos = this.currentPos - (e.nodeValue.length - this.find[t].offset));
1646
- }
1647
- matchesContext(e) {
1648
- if (e.indexOf("|") > -1) return e.split(/\s*\|\s*/).some(this.matchesContext, this);
1649
- let t = e.split("/"), n = this.options.context, r = !this.isOpen && (!n || n.parent.type == this.nodes[0].type), i = -(n ? n.depth + 1 : 0) + +!r, a = (e, o) => {
1650
- for (; e >= 0; e--) {
1651
- let s = t[e];
1652
- if (s == "") {
1653
- if (e == t.length - 1 || e == 0) continue;
1654
- for (; o >= i; o--) if (a(e - 1, o)) return !0;
1655
- return !1;
1656
- } else {
1657
- let e = o > 0 || o == 0 && r ? this.nodes[o].type : n && o >= i ? n.node(o - i).type : null;
1658
- if (!e || e.name != s && !e.isInGroup(s)) return !1;
1659
- o--;
1660
- }
1661
- }
1662
- return !0;
1663
- };
1664
- return a(t.length - 1, this.open);
1665
- }
1666
- textblockFromContext() {
1667
- let e = this.options.context;
1668
- if (e) for (let t = e.depth; t >= 0; t--) {
1669
- let n = e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;
1670
- if (n && n.isTextblock && n.defaultAttrs) return n;
1671
- }
1672
- for (let e in this.parser.schema.nodes) {
1673
- let t = this.parser.schema.nodes[e];
1674
- if (t.isTextblock && t.defaultAttrs) return t;
1675
- }
1676
- }
1677
- };
1678
- function He(e) {
1679
- for (let t = e.firstChild, n = null; t; t = t.nextSibling) {
1680
- let e = t.nodeType == 1 ? t.nodeName.toLowerCase() : null;
1681
- e && Re.hasOwnProperty(e) && n ? (n.appendChild(t), t = n) : e == "li" ? n = t : e && (n = null);
1682
- }
1683
- }
1684
- function Ue(e, t) {
1685
- return (e.matches || e.msMatchesSelector || e.webkitMatchesSelector || e.mozMatchesSelector).call(e, t);
1686
- }
1687
- function We(e) {
1688
- let t = {};
1689
- for (let n in e) t[n] = e[n];
1690
- return t;
1691
- }
1692
- function Ge(e, t) {
1693
- let n = t.schema.nodes;
1694
- for (let r in n) {
1695
- let i = n[r];
1696
- if (!i.allowsMarkType(e)) continue;
1697
- let a = [], o = (e) => {
1698
- a.push(e);
1699
- for (let n = 0; n < e.edgeCount; n++) {
1700
- let { type: r, next: i } = e.edge(n);
1701
- if (r == t || a.indexOf(i) < 0 && o(i)) return !0;
1702
- }
1703
- };
1704
- if (o(i.contentMatch)) return !0;
1705
- }
1706
- }
1707
- var Ke = class e {
1708
- constructor(e, t) {
1709
- this.nodes = e, this.marks = t;
1710
- }
1711
- serializeFragment(e, t = {}, n) {
1712
- n ||= T(t).createDocumentFragment();
1713
- let r = n, i = [];
1714
- return e.forEach((e) => {
1715
- if (i.length || e.marks.length) {
1716
- let n = 0, a = 0;
1717
- for (; n < i.length && a < e.marks.length;) {
1718
- let t = e.marks[a];
1719
- if (!this.marks[t.type.name]) {
1720
- a++;
1721
- continue;
1722
- }
1723
- if (!t.eq(i[n][0]) || t.type.spec.spanning === !1) break;
1724
- n++, a++;
1725
- }
1726
- for (; n < i.length;) r = i.pop()[1];
1727
- for (; a < e.marks.length;) {
1728
- let n = e.marks[a++], o = this.serializeMark(n, e.isInline, t);
1729
- o && (i.push([n, r]), r.appendChild(o.dom), r = o.contentDOM || o.dom);
1730
- }
1731
- }
1732
- r.appendChild(this.serializeNodeInner(e, t));
1733
- }), n;
1734
- }
1735
- serializeNodeInner(e, t) {
1736
- if (e.isText) return T(t).createTextNode(e.text);
1737
- let { dom: n, contentDOM: r } = E(T(t), this.nodes[e.type.name](e), null, e.attrs);
1738
- if (r) {
1739
- if (e.isLeaf) throw RangeError("Content hole not allowed in a leaf node spec");
1740
- this.serializeFragment(e.content, t, r);
1741
- }
1742
- return n;
1743
- }
1744
- serializeNode(e, t = {}) {
1745
- let n = this.serializeNodeInner(e, t);
1746
- for (let r = e.marks.length - 1; r >= 0; r--) {
1747
- let i = this.serializeMark(e.marks[r], e.isInline, t);
1748
- i && ((i.contentDOM || i.dom).appendChild(n), n = i.dom);
1749
- }
1750
- return n;
1751
- }
1752
- serializeMark(e, t, n = {}) {
1753
- let r = this.marks[e.type.name];
1754
- return r && E(T(n), r(e, t), null, e.attrs);
1755
- }
1756
- static renderSpec(e, t, n = null, r) {
1757
- return typeof t == "string" ? { dom: e.createTextNode(t) } : E(e, t, n, r);
1758
- }
1759
- static fromSchema(t) {
1760
- return t.cached.domSerializer || (t.cached.domSerializer = new e(this.nodesFromSchema(t), this.marksFromSchema(t)));
1761
- }
1762
- static nodesFromSchema(e) {
1763
- let t = qe(e.nodes);
1764
- return t.text ||= (e) => e.text, t;
1765
- }
1766
- static marksFromSchema(e) {
1767
- return qe(e.marks);
1768
- }
1769
- };
1770
- function qe(e) {
1771
- let t = {};
1772
- for (let n in e) {
1773
- let r = e[n].spec.toDOM;
1774
- r && (t[n] = r);
1775
- }
1776
- return t;
1777
- }
1778
- function T(e) {
1779
- return e.document || window.document;
1780
- }
1781
- var Je = /* @__PURE__ */ new WeakMap();
1782
- function Ye(e) {
1783
- let t = Je.get(e);
1784
- return t === void 0 && Je.set(e, t = Xe(e)), t;
1785
- }
1786
- function Xe(e) {
1787
- let t = null;
1788
- function n(e) {
1789
- if (e && typeof e == "object") if (Array.isArray(e)) if (typeof e[0] == "string") t ||= [], t.push(e);
1790
- else for (let t = 0; t < e.length; t++) n(e[t]);
1791
- else for (let t in e) n(e[t]);
1792
- }
1793
- return n(e), t;
1794
- }
1795
- function E(e, t, n, r) {
1796
- if (t.nodeType == 1) return { dom: t };
1797
- if (t.dom && t.dom.nodeType == 1) return t;
1798
- let i = t[0], a;
1799
- if (typeof i != "string") throw RangeError("Invalid array passed to renderSpec");
1800
- if (r && (a = Ye(r)) && a.indexOf(t) > -1) throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
1801
- let o = i.indexOf(" ");
1802
- o > 0 && (n = i.slice(0, o), i = i.slice(o + 1));
1803
- let s, c = n ? e.createElementNS(n, i) : e.createElement(i), l = t[1], u = 1;
1804
- if (l && typeof l == "object" && l.nodeType == null && !Array.isArray(l)) {
1805
- u = 2;
1806
- for (let e in l) if (l[e] != null) {
1807
- let t = e.indexOf(" ");
1808
- t > 0 ? c.setAttributeNS(e.slice(0, t), e.slice(t + 1), l[e]) : e == "style" && c.style ? c.style.cssText = l[e] : c.setAttribute(e, l[e]);
1809
- }
1810
- }
1811
- for (let i = u; i < t.length; i++) {
1812
- let a = t[i];
1813
- if (a === 0) {
1814
- if (i < t.length - 1 || i > u) throw RangeError("Content hole must be the only child of its parent node");
1815
- return {
1816
- dom: c,
1817
- contentDOM: c
1818
- };
1819
- } else if (typeof a == "string") c.appendChild(e.createTextNode(a));
1820
- else {
1821
- let { dom: t, contentDOM: i } = E(e, a, n, r);
1822
- if (c.appendChild(t), i) {
1823
- if (s) throw RangeError("Multiple content holes");
1824
- s = i;
1825
- }
1826
- }
1827
- }
1828
- return {
1829
- dom: c,
1830
- contentDOM: s
1831
- };
1832
- }
1833
- //#endregion
1834
- //#region node_modules/.pnpm/prosemirror-transform@1.12.0/node_modules/prosemirror-transform/dist/index.js
1835
- var Ze = 65535, Qe = 2 ** 16;
1836
- function $e(e, t) {
1837
- return e + t * Qe;
1838
- }
1839
- function et(e) {
1840
- return e & Ze;
1841
- }
1842
- function tt(e) {
1843
- return (e - (e & Ze)) / Qe;
1844
- }
1845
- var nt = 1, rt = 2, it = 4, at = 8, D = class {
1846
- constructor(e, t, n) {
1847
- this.pos = e, this.delInfo = t, this.recover = n;
1848
- }
1849
- get deleted() {
1850
- return (this.delInfo & at) > 0;
1851
- }
1852
- get deletedBefore() {
1853
- return (this.delInfo & 5) > 0;
1854
- }
1855
- get deletedAfter() {
1856
- return (this.delInfo & 6) > 0;
1857
- }
1858
- get deletedAcross() {
1859
- return (this.delInfo & it) > 0;
1860
- }
1861
- }, O = class e {
1862
- constructor(t, n = !1) {
1863
- if (this.ranges = t, this.inverted = n, !t.length && e.empty) return e.empty;
1864
- }
1865
- recover(e) {
1866
- let t = 0, n = et(e);
1867
- if (!this.inverted) for (let e = 0; e < n; e++) t += this.ranges[e * 3 + 2] - this.ranges[e * 3 + 1];
1868
- return this.ranges[n * 3] + t + tt(e);
1869
- }
1870
- mapResult(e, t = 1) {
1871
- return this._map(e, t, !1);
1872
- }
1873
- map(e, t = 1) {
1874
- return this._map(e, t, !0);
1875
- }
1876
- _map(e, t, n) {
1877
- let r = 0, i = this.inverted ? 2 : 1, a = this.inverted ? 1 : 2;
1878
- for (let o = 0; o < this.ranges.length; o += 3) {
1879
- let s = this.ranges[o] - (this.inverted ? r : 0);
1880
- if (s > e) break;
1881
- let c = this.ranges[o + i], l = this.ranges[o + a], u = s + c;
1882
- if (e <= u) {
1883
- let i = c ? e == s ? -1 : e == u ? 1 : t : t, a = s + r + (i < 0 ? 0 : l);
1884
- if (n) return a;
1885
- let d = e == (t < 0 ? s : u) ? null : $e(o / 3, e - s), f = e == s ? rt : e == u ? nt : it;
1886
- return (t < 0 ? e != s : e != u) && (f |= at), new D(a, f, d);
1887
- }
1888
- r += l - c;
1889
- }
1890
- return n ? e + r : new D(e + r, 0, null);
1891
- }
1892
- touches(e, t) {
1893
- let n = 0, r = et(t), i = this.inverted ? 2 : 1, a = this.inverted ? 1 : 2;
1894
- for (let t = 0; t < this.ranges.length; t += 3) {
1895
- let o = this.ranges[t] - (this.inverted ? n : 0);
1896
- if (o > e) break;
1897
- let s = this.ranges[t + i];
1898
- if (e <= o + s && t == r * 3) return !0;
1899
- n += this.ranges[t + a] - s;
1900
- }
1901
- return !1;
1902
- }
1903
- forEach(e) {
1904
- let t = this.inverted ? 2 : 1, n = this.inverted ? 1 : 2;
1905
- for (let r = 0, i = 0; r < this.ranges.length; r += 3) {
1906
- let a = this.ranges[r], o = a - (this.inverted ? i : 0), s = a + (this.inverted ? 0 : i), c = this.ranges[r + t], l = this.ranges[r + n];
1907
- e(o, o + c, s, s + l), i += l - c;
1908
- }
1909
- }
1910
- invert() {
1911
- return new e(this.ranges, !this.inverted);
1912
- }
1913
- toString() {
1914
- return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
1915
- }
1916
- static offset(t) {
1917
- return t == 0 ? e.empty : new e(t < 0 ? [
1918
- 0,
1919
- -t,
1920
- 0
1921
- ] : [
1922
- 0,
1923
- 0,
1924
- t
1925
- ]);
1926
- }
1927
- };
1928
- O.empty = new O([]);
1929
- var ot = class e {
1930
- constructor(e, t, n = 0, r = e ? e.length : 0) {
1931
- this.mirror = t, this.from = n, this.to = r, this._maps = e || [], this.ownData = !(e || t);
1932
- }
1933
- get maps() {
1934
- return this._maps;
1935
- }
1936
- slice(t = 0, n = this.maps.length) {
1937
- return new e(this._maps, this.mirror, t, n);
1938
- }
1939
- appendMap(e, t) {
1940
- this.ownData ||= (this._maps = this._maps.slice(), this.mirror = this.mirror && this.mirror.slice(), !0), this.to = this._maps.push(e), t != null && this.setMirror(this._maps.length - 1, t);
1941
- }
1942
- appendMapping(e) {
1943
- for (let t = 0, n = this._maps.length; t < e._maps.length; t++) {
1944
- let r = e.getMirror(t);
1945
- this.appendMap(e._maps[t], r != null && r < t ? n + r : void 0);
1946
- }
1947
- }
1948
- getMirror(e) {
1949
- if (this.mirror) {
1950
- for (let t = 0; t < this.mirror.length; t++) if (this.mirror[t] == e) return this.mirror[t + (t % 2 ? -1 : 1)];
1951
- }
1952
- }
1953
- setMirror(e, t) {
1954
- this.mirror ||= [], this.mirror.push(e, t);
1955
- }
1956
- appendMappingInverted(e) {
1957
- for (let t = e.maps.length - 1, n = this._maps.length + e._maps.length; t >= 0; t--) {
1958
- let r = e.getMirror(t);
1959
- this.appendMap(e._maps[t].invert(), r != null && r > t ? n - r - 1 : void 0);
1960
- }
1961
- }
1962
- invert() {
1963
- let t = new e();
1964
- return t.appendMappingInverted(this), t;
1965
- }
1966
- map(e, t = 1) {
1967
- if (this.mirror) return this._map(e, t, !0);
1968
- for (let n = this.from; n < this.to; n++) e = this._maps[n].map(e, t);
1969
- return e;
1970
- }
1971
- mapResult(e, t = 1) {
1972
- return this._map(e, t, !1);
1973
- }
1974
- _map(e, t, n) {
1975
- let r = 0;
1976
- for (let n = this.from; n < this.to; n++) {
1977
- let i = this._maps[n].mapResult(e, t);
1978
- if (i.recover != null) {
1979
- let t = this.getMirror(n);
1980
- if (t != null && t > n && t < this.to) {
1981
- n = t, e = this._maps[t].recover(i.recover);
1982
- continue;
1983
- }
1984
- }
1985
- r |= i.delInfo, e = i.pos;
1986
- }
1987
- return n ? e : new D(e, r, null);
1988
- }
1989
- }, k = Object.create(null), A = class {
1990
- getMap() {
1991
- return O.empty;
1992
- }
1993
- merge(e) {
1994
- return null;
1995
- }
1996
- static fromJSON(e, t) {
1997
- if (!t || !t.stepType) throw RangeError("Invalid input for Step.fromJSON");
1998
- let n = k[t.stepType];
1999
- if (!n) throw RangeError(`No step type ${t.stepType} defined`);
2000
- return n.fromJSON(e, t);
2001
- }
2002
- static jsonID(e, t) {
2003
- if (e in k) throw RangeError("Duplicate use of step JSON ID " + e);
2004
- return k[e] = t, t.prototype.jsonID = e, t;
2005
- }
2006
- }, j = class e {
2007
- constructor(e, t) {
2008
- this.doc = e, this.failed = t;
2009
- }
2010
- static ok(t) {
2011
- return new e(t, null);
2012
- }
2013
- static fail(t) {
2014
- return new e(null, t);
2015
- }
2016
- static fromReplace(t, n, r, i) {
2017
- try {
2018
- return e.ok(t.replace(n, r, i));
2019
- } catch (t) {
2020
- if (t instanceof c) return e.fail(t.message);
2021
- throw t;
2022
- }
2023
- }
2024
- };
2025
- function M(e, t, n) {
2026
- let i = [];
2027
- for (let r = 0; r < e.childCount; r++) {
2028
- let a = e.child(r);
2029
- a.content.size && (a = a.copy(M(a.content, t, a))), a.isInline && (a = t(a, n, r)), i.push(a);
2030
- }
2031
- return r.fromArray(i);
2032
- }
2033
- var N = class e extends A {
2034
- constructor(e, t, n) {
2035
- super(), this.from = e, this.to = t, this.mark = n;
2036
- }
2037
- apply(e) {
2038
- let t = e.slice(this.from, this.to), n = e.resolve(this.from), r = n.node(n.sharedDepth(this.to)), i = new l(M(t.content, (e, t) => !e.isAtom || !t.type.allowsMarkType(this.mark.type) ? e : e.mark(this.mark.addToSet(e.marks)), r), t.openStart, t.openEnd);
2039
- return j.fromReplace(e, this.from, this.to, i);
2040
- }
2041
- invert() {
2042
- return new P(this.from, this.to, this.mark);
2043
- }
2044
- map(t) {
2045
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1);
2046
- return n.deleted && r.deleted || n.pos >= r.pos ? null : new e(n.pos, r.pos, this.mark);
2047
- }
2048
- merge(t) {
2049
- return t instanceof e && t.mark.eq(this.mark) && this.from <= t.to && this.to >= t.from ? new e(Math.min(this.from, t.from), Math.max(this.to, t.to), this.mark) : null;
2050
- }
2051
- toJSON() {
2052
- return {
2053
- stepType: "addMark",
2054
- mark: this.mark.toJSON(),
2055
- from: this.from,
2056
- to: this.to
2057
- };
2058
- }
2059
- static fromJSON(t, n) {
2060
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for AddMarkStep.fromJSON");
2061
- return new e(n.from, n.to, t.markFromJSON(n.mark));
2062
- }
2063
- };
2064
- A.jsonID("addMark", N);
2065
- var P = class e extends A {
2066
- constructor(e, t, n) {
2067
- super(), this.from = e, this.to = t, this.mark = n;
2068
- }
2069
- apply(e) {
2070
- let t = e.slice(this.from, this.to), n = new l(M(t.content, (e) => e.mark(this.mark.removeFromSet(e.marks)), e), t.openStart, t.openEnd);
2071
- return j.fromReplace(e, this.from, this.to, n);
2072
- }
2073
- invert() {
2074
- return new N(this.from, this.to, this.mark);
2075
- }
2076
- map(t) {
2077
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1);
2078
- return n.deleted && r.deleted || n.pos >= r.pos ? null : new e(n.pos, r.pos, this.mark);
2079
- }
2080
- merge(t) {
2081
- return t instanceof e && t.mark.eq(this.mark) && this.from <= t.to && this.to >= t.from ? new e(Math.min(this.from, t.from), Math.max(this.to, t.to), this.mark) : null;
2082
- }
2083
- toJSON() {
2084
- return {
2085
- stepType: "removeMark",
2086
- mark: this.mark.toJSON(),
2087
- from: this.from,
2088
- to: this.to
2089
- };
2090
- }
2091
- static fromJSON(t, n) {
2092
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for RemoveMarkStep.fromJSON");
2093
- return new e(n.from, n.to, t.markFromJSON(n.mark));
2094
- }
2095
- };
2096
- A.jsonID("removeMark", P);
2097
- var F = class e extends A {
2098
- constructor(e, t) {
2099
- super(), this.pos = e, this.mark = t;
2100
- }
2101
- apply(e) {
2102
- let t = e.nodeAt(this.pos);
2103
- if (!t) return j.fail("No node at mark step's position");
2104
- let n = t.type.create(t.attrs, null, this.mark.addToSet(t.marks));
2105
- return j.fromReplace(e, this.pos, this.pos + 1, new l(r.from(n), 0, +!t.isLeaf));
2106
- }
2107
- invert(t) {
2108
- let n = t.nodeAt(this.pos);
2109
- if (n) {
2110
- let t = this.mark.addToSet(n.marks);
2111
- if (t.length == n.marks.length) {
2112
- for (let r = 0; r < n.marks.length; r++) if (!n.marks[r].isInSet(t)) return new e(this.pos, n.marks[r]);
2113
- return new e(this.pos, this.mark);
2114
- }
2115
- }
2116
- return new I(this.pos, this.mark);
2117
- }
2118
- map(t) {
2119
- let n = t.mapResult(this.pos, 1);
2120
- return n.deletedAfter ? null : new e(n.pos, this.mark);
2121
- }
2122
- toJSON() {
2123
- return {
2124
- stepType: "addNodeMark",
2125
- pos: this.pos,
2126
- mark: this.mark.toJSON()
2127
- };
2128
- }
2129
- static fromJSON(t, n) {
2130
- if (typeof n.pos != "number") throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");
2131
- return new e(n.pos, t.markFromJSON(n.mark));
2132
- }
2133
- };
2134
- A.jsonID("addNodeMark", F);
2135
- var I = class e extends A {
2136
- constructor(e, t) {
2137
- super(), this.pos = e, this.mark = t;
2138
- }
2139
- apply(e) {
2140
- let t = e.nodeAt(this.pos);
2141
- if (!t) return j.fail("No node at mark step's position");
2142
- let n = t.type.create(t.attrs, null, this.mark.removeFromSet(t.marks));
2143
- return j.fromReplace(e, this.pos, this.pos + 1, new l(r.from(n), 0, +!t.isLeaf));
2144
- }
2145
- invert(e) {
2146
- let t = e.nodeAt(this.pos);
2147
- return !t || !this.mark.isInSet(t.marks) ? this : new F(this.pos, this.mark);
2148
- }
2149
- map(t) {
2150
- let n = t.mapResult(this.pos, 1);
2151
- return n.deletedAfter ? null : new e(n.pos, this.mark);
2152
- }
2153
- toJSON() {
2154
- return {
2155
- stepType: "removeNodeMark",
2156
- pos: this.pos,
2157
- mark: this.mark.toJSON()
2158
- };
2159
- }
2160
- static fromJSON(t, n) {
2161
- if (typeof n.pos != "number") throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
2162
- return new e(n.pos, t.markFromJSON(n.mark));
2163
- }
2164
- };
2165
- A.jsonID("removeNodeMark", I);
2166
- var L = class e extends A {
2167
- constructor(e, t, n, r = !1) {
2168
- super(), this.from = e, this.to = t, this.slice = n, this.structure = r;
2169
- }
2170
- apply(e) {
2171
- return this.structure && z(e, this.from, this.to) ? j.fail("Structure replace would overwrite content") : j.fromReplace(e, this.from, this.to, this.slice);
2172
- }
2173
- getMap() {
2174
- return new O([
2175
- this.from,
2176
- this.to - this.from,
2177
- this.slice.size
2178
- ]);
2179
- }
2180
- invert(t) {
2181
- return new e(this.from, this.from + this.slice.size, t.slice(this.from, this.to));
2182
- }
2183
- map(t) {
2184
- let n = t.mapResult(this.to, -1), r = this.from == this.to && e.MAP_BIAS < 0 ? n : t.mapResult(this.from, 1);
2185
- return r.deletedAcross && n.deletedAcross ? null : new e(r.pos, Math.max(r.pos, n.pos), this.slice, this.structure);
2186
- }
2187
- merge(t) {
2188
- if (!(t instanceof e) || t.structure || this.structure) return null;
2189
- if (this.from + this.slice.size == t.from && !this.slice.openEnd && !t.slice.openStart) {
2190
- let n = this.slice.size + t.slice.size == 0 ? l.empty : new l(this.slice.content.append(t.slice.content), this.slice.openStart, t.slice.openEnd);
2191
- return new e(this.from, this.to + (t.to - t.from), n, this.structure);
2192
- } else if (t.to == this.from && !this.slice.openStart && !t.slice.openEnd) {
2193
- let n = this.slice.size + t.slice.size == 0 ? l.empty : new l(t.slice.content.append(this.slice.content), t.slice.openStart, this.slice.openEnd);
2194
- return new e(t.from, this.to, n, this.structure);
2195
- } else return null;
2196
- }
2197
- toJSON() {
2198
- let e = {
2199
- stepType: "replace",
2200
- from: this.from,
2201
- to: this.to
2202
- };
2203
- return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
2204
- }
2205
- static fromJSON(t, n) {
2206
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for ReplaceStep.fromJSON");
2207
- return new e(n.from, n.to, l.fromJSON(t, n.slice), !!n.structure);
2208
- }
2209
- };
2210
- L.MAP_BIAS = 1, A.jsonID("replace", L);
2211
- var R = class e extends A {
2212
- constructor(e, t, n, r, i, a, o = !1) {
2213
- super(), this.from = e, this.to = t, this.gapFrom = n, this.gapTo = r, this.slice = i, this.insert = a, this.structure = o;
2214
- }
2215
- apply(e) {
2216
- if (this.structure && (z(e, this.from, this.gapFrom) || z(e, this.gapTo, this.to))) return j.fail("Structure gap-replace would overwrite content");
2217
- let t = e.slice(this.gapFrom, this.gapTo);
2218
- if (t.openStart || t.openEnd) return j.fail("Gap is not a flat range");
2219
- let n = this.slice.insertAt(this.insert, t.content);
2220
- return n ? j.fromReplace(e, this.from, this.to, n) : j.fail("Content does not fit in gap");
2221
- }
2222
- getMap() {
2223
- return new O([
2224
- this.from,
2225
- this.gapFrom - this.from,
2226
- this.insert,
2227
- this.gapTo,
2228
- this.to - this.gapTo,
2229
- this.slice.size - this.insert
2230
- ]);
2231
- }
2232
- invert(t) {
2233
- let n = this.gapTo - this.gapFrom;
2234
- return new e(this.from, this.from + this.slice.size + n, this.from + this.insert, this.from + this.insert + n, t.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
2235
- }
2236
- map(t) {
2237
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1), i = this.from == this.gapFrom ? n.pos : t.map(this.gapFrom, -1), a = this.to == this.gapTo ? r.pos : t.map(this.gapTo, 1);
2238
- return n.deletedAcross && r.deletedAcross || i < n.pos || a > r.pos ? null : new e(n.pos, r.pos, i, a, this.slice, this.insert, this.structure);
2239
- }
2240
- toJSON() {
2241
- let e = {
2242
- stepType: "replaceAround",
2243
- from: this.from,
2244
- to: this.to,
2245
- gapFrom: this.gapFrom,
2246
- gapTo: this.gapTo,
2247
- insert: this.insert
2248
- };
2249
- return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
2250
- }
2251
- static fromJSON(t, n) {
2252
- if (typeof n.from != "number" || typeof n.to != "number" || typeof n.gapFrom != "number" || typeof n.gapTo != "number" || typeof n.insert != "number") throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");
2253
- return new e(n.from, n.to, n.gapFrom, n.gapTo, l.fromJSON(t, n.slice), n.insert, !!n.structure);
2254
- }
2255
- };
2256
- A.jsonID("replaceAround", R);
2257
- function z(e, t, n) {
2258
- let r = e.resolve(t), i = n - t, a = r.depth;
2259
- for (; i > 0 && a > 0 && r.indexAfter(a) == r.node(a).childCount;) a--, i--;
2260
- if (i > 0) {
2261
- let e = r.node(a).maybeChild(r.indexAfter(a));
2262
- for (; i > 0;) {
2263
- if (!e || e.isLeaf) return !0;
2264
- e = e.firstChild, i--;
2265
- }
2266
- }
2267
- return !1;
2268
- }
2269
- function st(e, t, n, r) {
2270
- let i = [], a = [], o, s;
2271
- e.doc.nodesBetween(t, n, (e, c, l) => {
2272
- if (!e.isInline) return;
2273
- let u = e.marks;
2274
- if (!r.isInSet(u) && l.type.allowsMarkType(r.type)) {
2275
- let l = Math.max(c, t), d = Math.min(c + e.nodeSize, n), f = r.addToSet(u);
2276
- for (let e = 0; e < u.length; e++) u[e].isInSet(f) || (o && o.to == l && o.mark.eq(u[e]) ? o.to = d : i.push(o = new P(l, d, u[e])));
2277
- s && s.to == l ? s.to = d : a.push(s = new N(l, d, r));
2278
- }
2279
- }), i.forEach((t) => e.step(t)), a.forEach((t) => e.step(t));
2280
- }
2281
- function ct(e, t, n, r) {
2282
- let i = [], a = 0;
2283
- e.doc.nodesBetween(t, n, (e, o) => {
2284
- if (!e.isInline) return;
2285
- a++;
2286
- let s = null;
2287
- if (r instanceof Ae) {
2288
- let t = e.marks, n;
2289
- for (; n = r.isInSet(t);) (s ||= []).push(n), t = n.removeFromSet(t);
2290
- } else r ? r.isInSet(e.marks) && (s = [r]) : s = e.marks;
2291
- if (s && s.length) {
2292
- let r = Math.min(o + e.nodeSize, n);
2293
- for (let e = 0; e < s.length; e++) {
2294
- let n = s[e], c;
2295
- for (let e = 0; e < i.length; e++) {
2296
- let t = i[e];
2297
- t.step == a - 1 && n.eq(i[e].style) && (c = t);
2298
- }
2299
- c ? (c.to = r, c.step = a) : i.push({
2300
- style: n,
2301
- from: Math.max(o, t),
2302
- to: r,
2303
- step: a
2304
- });
2305
- }
2306
- }
2307
- }), i.forEach((t) => e.step(new P(t.from, t.to, t.style)));
2308
- }
2309
- function B(e, t, n, i = n.contentMatch, a = !0) {
2310
- let o = e.doc.nodeAt(t), s = [], c = t + 1;
2311
- for (let t = 0; t < o.childCount; t++) {
2312
- let u = o.child(t), d = c + u.nodeSize, f = i.matchType(u.type);
2313
- if (!f) s.push(new L(c, d, l.empty));
2314
- else {
2315
- i = f;
2316
- for (let t = 0; t < u.marks.length; t++) n.allowsMarkType(u.marks[t].type) || e.step(new P(c, d, u.marks[t]));
2317
- if (a && u.isText && n.whitespace != "pre") {
2318
- let e, t = /\r?\n|\r/g, i;
2319
- for (; e = t.exec(u.text);) i ||= new l(r.from(n.schema.text(" ", n.allowedMarks(u.marks))), 0, 0), s.push(new L(c + e.index, c + e.index + e[0].length, i));
2320
- }
2321
- }
2322
- c = d;
2323
- }
2324
- if (!i.validEnd) {
2325
- let t = i.fillBefore(r.empty, !0);
2326
- e.replace(c, c, new l(t, 0, 0));
2327
- }
2328
- for (let t = s.length - 1; t >= 0; t--) e.step(s[t]);
2329
- }
2330
- function lt(e, t, n) {
2331
- return (t == 0 || e.canReplace(t, e.childCount)) && (n == e.childCount || e.canReplace(0, n));
2332
- }
2333
- function ut(e) {
2334
- let t = e.parent.content.cutByIndex(e.startIndex, e.endIndex);
2335
- for (let n = e.depth, r = 0, i = 0;; --n) {
2336
- let a = e.$from.node(n), o = e.$from.index(n) + r, s = e.$to.indexAfter(n) - i;
2337
- if (n < e.depth && a.canReplace(o, s, t)) return n;
2338
- if (n == 0 || a.type.spec.isolating || !lt(a, o, s)) break;
2339
- o && (r = 1), s < a.childCount && (i = 1);
2340
- }
2341
- return null;
2342
- }
2343
- function dt(e, t, n) {
2344
- let { $from: i, $to: a, depth: o } = t, s = i.before(o + 1), c = a.after(o + 1), u = s, d = c, f = r.empty, p = 0;
2345
- for (let e = o, t = !1; e > n; e--) t || i.index(e) > 0 ? (t = !0, f = r.from(i.node(e).copy(f)), p++) : u--;
2346
- let m = r.empty, h = 0;
2347
- for (let e = o, t = !1; e > n; e--) t || a.after(e + 1) < a.end(e) ? (t = !0, m = r.from(a.node(e).copy(m)), h++) : d++;
2348
- e.step(new R(u, d, s, c, new l(f.append(m), p, h), f.size - p, !0));
2349
- }
2350
- function ft(e, t, n = null, r = e) {
2351
- let i = mt(e, t), a = i && ht(r, t);
2352
- return a ? i.map(pt).concat({
2353
- type: t,
2354
- attrs: n
2355
- }).concat(a.map(pt)) : null;
2356
- }
2357
- function pt(e) {
2358
- return {
2359
- type: e,
2360
- attrs: null
2361
- };
2362
- }
2363
- function mt(e, t) {
2364
- let { parent: n, startIndex: r, endIndex: i } = e, a = n.contentMatchAt(r).findWrapping(t);
2365
- if (!a) return null;
2366
- let o = a.length ? a[0] : t;
2367
- return n.canReplaceWith(r, i, o) ? a : null;
2368
- }
2369
- function ht(e, t) {
2370
- let { parent: n, startIndex: r, endIndex: i } = e, a = n.child(r), o = t.contentMatch.findWrapping(a.type);
2371
- if (!o) return null;
2372
- let s = (o.length ? o[o.length - 1] : t).contentMatch;
2373
- for (let e = r; s && e < i; e++) s = s.matchType(n.child(e).type);
2374
- return !s || !s.validEnd ? null : o;
2375
- }
2376
- function gt(e, t, n) {
2377
- let i = r.empty;
2378
- for (let e = n.length - 1; e >= 0; e--) {
2379
- if (i.size) {
2380
- let t = n[e].type.contentMatch.matchFragment(i);
2381
- if (!t || !t.validEnd) throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
2382
- }
2383
- i = r.from(n[e].type.create(n[e].attrs, i));
2384
- }
2385
- let a = t.start, o = t.end;
2386
- e.step(new R(a, o, a, o, new l(i, 0, 0), n.length, !0));
2387
- }
2388
- function _t(e, t, n, i, a) {
2389
- if (!i.isTextblock) throw RangeError("Type given to setBlockType should be a textblock");
2390
- let o = e.steps.length;
2391
- e.doc.nodesBetween(t, n, (t, n) => {
2392
- let s = typeof a == "function" ? a(t) : a;
2393
- if (t.isTextblock && !t.hasMarkup(i, s) && bt(e.doc, e.mapping.slice(o).map(n), i)) {
2394
- let a = null;
2395
- if (i.schema.linebreakReplacement) {
2396
- let e = i.whitespace == "pre", t = !!i.contentMatch.matchType(i.schema.linebreakReplacement);
2397
- e && !t ? a = !1 : !e && t && (a = !0);
2398
- }
2399
- a === !1 && yt(e, t, n, o), B(e, e.mapping.slice(o).map(n, 1), i, void 0, a === null);
2400
- let c = e.mapping.slice(o), u = c.map(n, 1), d = c.map(n + t.nodeSize, 1);
2401
- return e.step(new R(u, d, u + 1, d - 1, new l(r.from(i.create(s, null, t.marks)), 0, 0), 1, !0)), a === !0 && vt(e, t, n, o), !1;
2402
- }
2403
- });
2404
- }
2405
- function vt(e, t, n, r) {
2406
- t.forEach((i, a) => {
2407
- if (i.isText) {
2408
- let o, s = /\r?\n|\r/g;
2409
- for (; o = s.exec(i.text);) {
2410
- let i = e.mapping.slice(r).map(n + 1 + a + o.index);
2411
- e.replaceWith(i, i + 1, t.type.schema.linebreakReplacement.create());
2412
- }
2413
- }
2414
- });
2415
- }
2416
- function yt(e, t, n, r) {
2417
- t.forEach((i, a) => {
2418
- if (i.type == i.type.schema.linebreakReplacement) {
2419
- let i = e.mapping.slice(r).map(n + 1 + a);
2420
- e.replaceWith(i, i + 1, t.type.schema.text("\n"));
2421
- }
2422
- });
2423
- }
2424
- function bt(e, t, n) {
2425
- let r = e.resolve(t), i = r.index();
2426
- return r.parent.canReplaceWith(i, i + 1, n);
2427
- }
2428
- function xt(e, t, n, i, a) {
2429
- let o = e.doc.nodeAt(t);
2430
- if (!o) throw RangeError("No node at given position");
2431
- n ||= o.type;
2432
- let s = n.create(i, null, a || o.marks);
2433
- if (o.isLeaf) return e.replaceWith(t, t + o.nodeSize, s);
2434
- if (!n.validContent(o.content)) throw RangeError("Invalid content for node type " + n.name);
2435
- e.step(new R(t, t + o.nodeSize, t + 1, t + o.nodeSize - 1, new l(r.from(s), 0, 0), 1, !0));
2436
- }
2437
- function St(e, t, n = 1, r) {
2438
- let i = e.resolve(t), a = i.depth - n, o = r && r[r.length - 1] || i.parent;
2439
- if (a < 0 || i.parent.type.spec.isolating || !i.parent.canReplace(i.index(), i.parent.childCount) || !o.type.validContent(i.parent.content.cutByIndex(i.index(), i.parent.childCount))) return !1;
2440
- for (let e = i.depth - 1, t = n - 2; e > a; e--, t--) {
2441
- let n = i.node(e), a = i.index(e);
2442
- if (n.type.spec.isolating) return !1;
2443
- let o = n.content.cutByIndex(a, n.childCount), s = r && r[t + 1];
2444
- s && (o = o.replaceChild(0, s.type.create(s.attrs)));
2445
- let c = r && r[t] || n;
2446
- if (!n.canReplace(a + 1, n.childCount) || !c.type.validContent(o)) return !1;
2447
- }
2448
- let s = i.indexAfter(a), c = r && r[0];
2449
- return i.node(a).canReplaceWith(s, s, c ? c.type : i.node(a + 1).type);
2450
- }
2451
- function Ct(e, t, n = 1, i) {
2452
- let a = e.doc.resolve(t), o = r.empty, s = r.empty;
2453
- for (let e = a.depth, t = a.depth - n, c = n - 1; e > t; e--, c--) {
2454
- o = r.from(a.node(e).copy(o));
2455
- let t = i && i[c];
2456
- s = r.from(t ? t.type.create(t.attrs, s) : a.node(e).copy(s));
2457
- }
2458
- e.step(new L(t, t, new l(o.append(s), n, n), !0));
2459
- }
2460
- function wt(e, t) {
2461
- let n = e.resolve(t), r = n.index();
2462
- return Et(n.nodeBefore, n.nodeAfter) && n.parent.canReplace(r, r + 1);
2463
- }
2464
- function Tt(e, t) {
2465
- t.content.size || e.type.compatibleContent(t.type);
2466
- let n = e.contentMatchAt(e.childCount), { linebreakReplacement: r } = e.type.schema;
2467
- for (let i = 0; i < t.childCount; i++) {
2468
- let a = t.child(i), o = a.type == r ? e.type.schema.nodes.text : a.type;
2469
- if (n = n.matchType(o), !n || !e.type.allowsMarks(a.marks)) return !1;
2470
- }
2471
- return n.validEnd;
2472
- }
2473
- function Et(e, t) {
2474
- return !!(e && t && !e.isLeaf && Tt(e, t));
2475
- }
2476
- function Dt(e, t, n = -1) {
2477
- let r = e.resolve(t);
2478
- for (let e = r.depth;; e--) {
2479
- let i, a, o = r.index(e);
2480
- if (e == r.depth ? (i = r.nodeBefore, a = r.nodeAfter) : n > 0 ? (i = r.node(e + 1), o++, a = r.node(e).maybeChild(o)) : (i = r.node(e).maybeChild(o - 1), a = r.node(e + 1)), i && !i.isTextblock && Et(i, a) && r.node(e).canReplace(o, o + 1)) return t;
2481
- if (e == 0) break;
2482
- t = n < 0 ? r.before(e) : r.after(e);
2483
- }
2484
- }
2485
- function Ot(e, t, n) {
2486
- let r = null, { linebreakReplacement: i } = e.doc.type.schema, a = e.doc.resolve(t - n), o = a.node().type;
2487
- if (i && o.inlineContent) {
2488
- let e = o.whitespace == "pre", t = !!o.contentMatch.matchType(i);
2489
- e && !t ? r = !1 : !e && t && (r = !0);
2490
- }
2491
- let s = e.steps.length;
2492
- if (r === !1) {
2493
- let r = e.doc.resolve(t + n);
2494
- yt(e, r.node(), r.before(), s);
2495
- }
2496
- o.inlineContent && B(e, t + n - 1, o, a.node().contentMatchAt(a.index()), r == null);
2497
- let c = e.mapping.slice(s), u = c.map(t - n);
2498
- if (e.step(new L(u, c.map(t + n, -1), l.empty, !0)), r === !0) {
2499
- let t = e.doc.resolve(u);
2500
- vt(e, t.node(), t.before(), e.steps.length);
2501
- }
2502
- return e;
2503
- }
2504
- function kt(e, t, n) {
2505
- let r = e.resolve(t);
2506
- if (r.parent.canReplaceWith(r.index(), r.index(), n)) return t;
2507
- if (r.parentOffset == 0) for (let e = r.depth - 1; e >= 0; e--) {
2508
- let t = r.index(e);
2509
- if (r.node(e).canReplaceWith(t, t, n)) return r.before(e + 1);
2510
- if (t > 0) return null;
2511
- }
2512
- if (r.parentOffset == r.parent.content.size) for (let e = r.depth - 1; e >= 0; e--) {
2513
- let t = r.indexAfter(e);
2514
- if (r.node(e).canReplaceWith(t, t, n)) return r.after(e + 1);
2515
- if (t < r.node(e).childCount) return null;
2516
- }
2517
- return null;
2518
- }
2519
- function At(e, t, n) {
2520
- let r = e.resolve(t);
2521
- if (!n.content.size) return t;
2522
- let i = n.content;
2523
- for (let e = 0; e < n.openStart; e++) i = i.firstChild.content;
2524
- for (let e = 1; e <= (n.openStart == 0 && n.size ? 2 : 1); e++) for (let t = r.depth; t >= 0; t--) {
2525
- let n = t == r.depth ? 0 : r.pos <= (r.start(t + 1) + r.end(t + 1)) / 2 ? -1 : 1, a = r.index(t) + +(n > 0), o = r.node(t), s = !1;
2526
- if (e == 1) s = o.canReplace(a, a, i);
2527
- else {
2528
- let e = o.contentMatchAt(a).findWrapping(i.firstChild.type);
2529
- s = e && o.canReplaceWith(a, a, e[0]);
2530
- }
2531
- if (s) return n == 0 ? r.pos : n < 0 ? r.before(t + 1) : r.after(t + 1);
2532
- }
2533
- return null;
2534
- }
2535
- function jt(e, t, n = t, r = l.empty) {
2536
- if (t == n && !r.size) return null;
2537
- let i = e.resolve(t), a = e.resolve(n);
2538
- return Mt(i, a, r) ? new L(t, n, r) : new Nt(i, a, r).fit();
2539
- }
2540
- function Mt(e, t, n) {
2541
- return !n.openStart && !n.openEnd && e.start() == t.start() && e.parent.canReplace(e.index(), t.index(), n.content);
2542
- }
2543
- var Nt = class {
2544
- constructor(e, t, n) {
2545
- this.$from = e, this.$to = t, this.unplaced = n, this.frontier = [], this.placed = r.empty;
2546
- for (let t = 0; t <= e.depth; t++) {
2547
- let n = e.node(t);
2548
- this.frontier.push({
2549
- type: n.type,
2550
- match: n.contentMatchAt(e.indexAfter(t))
2551
- });
2552
- }
2553
- for (let t = e.depth; t > 0; t--) this.placed = r.from(e.node(t).copy(this.placed));
2554
- }
2555
- get depth() {
2556
- return this.frontier.length - 1;
2557
- }
2558
- fit() {
2559
- for (; this.unplaced.size;) {
2560
- let e = this.findFittable();
2561
- e ? this.placeNodes(e) : this.openMore() || this.dropNode();
2562
- }
2563
- let e = this.mustMoveInline(), t = this.placed.size - this.depth - this.$from.depth, n = this.$from, r = this.close(e < 0 ? this.$to : n.doc.resolve(e));
2564
- if (!r) return null;
2565
- let i = this.placed, a = n.depth, o = r.depth;
2566
- for (; a && o && i.childCount == 1;) i = i.firstChild.content, a--, o--;
2567
- let s = new l(i, a, o);
2568
- return e > -1 ? new R(n.pos, e, this.$to.pos, this.$to.end(), s, t) : s.size || n.pos != this.$to.pos ? new L(n.pos, r.pos, s) : null;
2569
- }
2570
- findFittable() {
2571
- let e = this.unplaced.openStart;
2572
- for (let t = this.unplaced.content, n = 0, r = this.unplaced.openEnd; n < e; n++) {
2573
- let i = t.firstChild;
2574
- if (t.childCount > 1 && (r = 0), i.type.spec.isolating && r <= n) {
2575
- e = n;
2576
- break;
2577
- }
2578
- t = i.content;
2579
- }
2580
- for (let t = 1; t <= 2; t++) for (let n = t == 1 ? e : this.unplaced.openStart; n >= 0; n--) {
2581
- let e, i = null;
2582
- n ? (i = U(this.unplaced.content, n - 1).firstChild, e = i.content) : e = this.unplaced.content;
2583
- let a = e.firstChild;
2584
- for (let e = this.depth; e >= 0; e--) {
2585
- let { type: o, match: s } = this.frontier[e], c, l = null;
2586
- if (t == 1 && (a ? s.matchType(a.type) || (l = s.fillBefore(r.from(a), !1)) : i && o.compatibleContent(i.type))) return {
2587
- sliceDepth: n,
2588
- frontierDepth: e,
2589
- parent: i,
2590
- inject: l
2591
- };
2592
- if (t == 2 && a && (c = s.findWrapping(a.type))) return {
2593
- sliceDepth: n,
2594
- frontierDepth: e,
2595
- parent: i,
2596
- wrap: c
2597
- };
2598
- if (i && s.matchType(i.type)) break;
2599
- }
2600
- }
2601
- }
2602
- openMore() {
2603
- let { content: e, openStart: t, openEnd: n } = this.unplaced, r = U(e, t);
2604
- return !r.childCount || r.firstChild.isLeaf ? !1 : (this.unplaced = new l(e, t + 1, Math.max(n, r.size + t >= e.size - n ? t + 1 : 0)), !0);
2605
- }
2606
- dropNode() {
2607
- let { content: e, openStart: t, openEnd: n } = this.unplaced, r = U(e, t);
2608
- if (r.childCount <= 1 && t > 0) {
2609
- let i = e.size - t <= t + r.size;
2610
- this.unplaced = new l(V(e, t - 1, 1), t - 1, i ? t - 1 : n);
2611
- } else this.unplaced = new l(V(e, t, 1), t, n);
2612
- }
2613
- placeNodes({ sliceDepth: e, frontierDepth: t, parent: n, inject: i, wrap: a }) {
2614
- for (; this.depth > t;) this.closeFrontierNode();
2615
- if (a) for (let e = 0; e < a.length; e++) this.openFrontierNode(a[e]);
2616
- let o = this.unplaced, s = n ? n.content : o.content, c = o.openStart - e, u = 0, d = [], { match: f, type: p } = this.frontier[t];
2617
- if (i) {
2618
- for (let e = 0; e < i.childCount; e++) d.push(i.child(e));
2619
- f = f.matchFragment(i);
2620
- }
2621
- let m = s.size + e - (o.content.size - o.openEnd);
2622
- for (; u < s.childCount;) {
2623
- let e = s.child(u), t = f.matchType(e.type);
2624
- if (!t) break;
2625
- u++, (u > 1 || c == 0 || e.content.size) && (f = t, d.push(Pt(e.mark(p.allowedMarks(e.marks)), u == 1 ? c : 0, u == s.childCount ? m : -1)));
2626
- }
2627
- let h = u == s.childCount;
2628
- h || (m = -1), this.placed = H(this.placed, t, r.from(d)), this.frontier[t].match = f, h && m < 0 && n && n.type == this.frontier[this.depth].type && this.frontier.length > 1 && this.closeFrontierNode();
2629
- for (let e = 0, t = s; e < m; e++) {
2630
- let e = t.lastChild;
2631
- this.frontier.push({
2632
- type: e.type,
2633
- match: e.contentMatchAt(e.childCount)
2634
- }), t = e.content;
2635
- }
2636
- this.unplaced = h ? e == 0 ? l.empty : new l(V(o.content, e - 1, 1), e - 1, m < 0 ? o.openEnd : e - 1) : new l(V(o.content, e, u), o.openStart, o.openEnd);
2637
- }
2638
- mustMoveInline() {
2639
- if (!this.$to.parent.isTextblock) return -1;
2640
- let e = this.frontier[this.depth], t;
2641
- if (!e.type.isTextblock || !W(this.$to, this.$to.depth, e.type, e.match, !1) || this.$to.depth == this.depth && (t = this.findCloseLevel(this.$to)) && t.depth == this.depth) return -1;
2642
- let { depth: n } = this.$to, r = this.$to.after(n);
2643
- for (; n > 1 && r == this.$to.end(--n);) ++r;
2644
- return r;
2645
- }
2646
- findCloseLevel(e) {
2647
- scan: for (let t = Math.min(this.depth, e.depth); t >= 0; t--) {
2648
- let { match: n, type: r } = this.frontier[t], i = t < e.depth && e.end(t + 1) == e.pos + (e.depth - (t + 1)), a = W(e, t, r, n, i);
2649
- if (a) {
2650
- for (let n = t - 1; n >= 0; n--) {
2651
- let { match: t, type: r } = this.frontier[n], i = W(e, n, r, t, !0);
2652
- if (!i || i.childCount) continue scan;
2653
- }
2654
- return {
2655
- depth: t,
2656
- fit: a,
2657
- move: i ? e.doc.resolve(e.after(t + 1)) : e
2658
- };
2659
- }
2660
- }
2661
- }
2662
- close(e) {
2663
- let t = this.findCloseLevel(e);
2664
- if (!t) return null;
2665
- for (; this.depth > t.depth;) this.closeFrontierNode();
2666
- t.fit.childCount && (this.placed = H(this.placed, t.depth, t.fit)), e = t.move;
2667
- for (let n = t.depth + 1; n <= e.depth; n++) {
2668
- let t = e.node(n), r = t.type.contentMatch.fillBefore(t.content, !0, e.index(n));
2669
- this.openFrontierNode(t.type, t.attrs, r);
2670
- }
2671
- return e;
2672
- }
2673
- openFrontierNode(e, t = null, n) {
2674
- let i = this.frontier[this.depth];
2675
- i.match = i.match.matchType(e), this.placed = H(this.placed, this.depth, r.from(e.create(t, n))), this.frontier.push({
2676
- type: e,
2677
- match: e.contentMatch
2678
- });
2679
- }
2680
- closeFrontierNode() {
2681
- let e = this.frontier.pop().match.fillBefore(r.empty, !0);
2682
- e.childCount && (this.placed = H(this.placed, this.frontier.length, e));
2683
- }
2684
- };
2685
- function V(e, t, n) {
2686
- return t == 0 ? e.cutByIndex(n, e.childCount) : e.replaceChild(0, e.firstChild.copy(V(e.firstChild.content, t - 1, n)));
2687
- }
2688
- function H(e, t, n) {
2689
- return t == 0 ? e.append(n) : e.replaceChild(e.childCount - 1, e.lastChild.copy(H(e.lastChild.content, t - 1, n)));
2690
- }
2691
- function U(e, t) {
2692
- for (let n = 0; n < t; n++) e = e.firstChild.content;
2693
- return e;
2694
- }
2695
- function Pt(e, t, n) {
2696
- if (t <= 0) return e;
2697
- let i = e.content;
2698
- return t > 1 && (i = i.replaceChild(0, Pt(i.firstChild, t - 1, i.childCount == 1 ? n - 1 : 0))), t > 0 && (i = e.type.contentMatch.fillBefore(i).append(i), n <= 0 && (i = i.append(e.type.contentMatch.matchFragment(i).fillBefore(r.empty, !0)))), e.copy(i);
2699
- }
2700
- function W(e, t, n, r, i) {
2701
- let a = e.node(t), o = i ? e.indexAfter(t) : e.index(t);
2702
- if (o == a.childCount && !n.compatibleContent(a.type)) return null;
2703
- let s = r.fillBefore(a.content, !0, o);
2704
- return s && !Ft(n, a.content, o) ? s : null;
2705
- }
2706
- function Ft(e, t, n) {
2707
- for (let r = n; r < t.childCount; r++) if (!e.allowsMarks(t.child(r).marks)) return !0;
2708
- return !1;
2709
- }
2710
- function It(e) {
2711
- return e.spec.defining || e.spec.definingForContent;
2712
- }
2713
- function Lt(e, t, n, r) {
2714
- if (!r.size) return e.deleteRange(t, n);
2715
- let i = e.doc.resolve(t), a = e.doc.resolve(n);
2716
- if (Mt(i, a, r)) return e.step(new L(t, n, r));
2717
- let o = Vt(i, a);
2718
- o[o.length - 1] == 0 && o.pop();
2719
- let s = -(i.depth + 1);
2720
- o.unshift(s);
2721
- for (let e = i.depth, t = i.pos - 1; e > 0; e--, t--) {
2722
- let n = i.node(e).type.spec;
2723
- if (n.defining || n.definingAsContext || n.isolating) break;
2724
- o.indexOf(e) > -1 ? s = e : i.before(e) == t && o.splice(1, 0, -e);
2725
- }
2726
- let c = o.indexOf(s), u = [], d = r.openStart;
2727
- for (let e = r.content, t = 0;; t++) {
2728
- let n = e.firstChild;
2729
- if (u.push(n), t == r.openStart) break;
2730
- e = n.content;
2731
- }
2732
- for (let e = d - 1; e >= 0; e--) {
2733
- let t = u[e], n = It(t.type);
2734
- if (n && !t.sameMarkup(i.node(Math.abs(s) - 1))) d = e;
2735
- else if (n || !t.type.isTextblock) break;
2736
- }
2737
- for (let t = r.openStart; t >= 0; t--) {
2738
- let s = (t + d + 1) % (r.openStart + 1), f = u[s];
2739
- if (f) for (let t = 0; t < o.length; t++) {
2740
- let u = o[(t + c) % o.length], d = !0;
2741
- u < 0 && (d = !1, u = -u);
2742
- let p = i.node(u - 1), m = i.index(u - 1);
2743
- if (p.canReplaceWith(m, m, f.type, f.marks)) return e.replace(i.before(u), d ? a.after(u) : n, new l(Rt(r.content, 0, r.openStart, s), s, r.openEnd));
2744
- }
2745
- }
2746
- let f = e.steps.length;
2747
- for (let s = o.length - 1; s >= 0 && (e.replace(t, n, r), !(e.steps.length > f)); s--) {
2748
- let e = o[s];
2749
- e < 0 || (t = i.before(e), n = a.after(e));
2750
- }
2751
- }
2752
- function Rt(e, t, n, i, a) {
2753
- if (t < n) {
2754
- let r = e.firstChild;
2755
- e = e.replaceChild(0, r.copy(Rt(r.content, t + 1, n, i, r)));
2756
- }
2757
- if (t > i) {
2758
- let t = a.contentMatchAt(0), n = t.fillBefore(e).append(e);
2759
- e = n.append(t.matchFragment(n).fillBefore(r.empty, !0));
2760
- }
2761
- return e;
2762
- }
2763
- function zt(e, t, n, i) {
2764
- if (!i.isInline && t == n && e.doc.resolve(t).parent.content.size) {
2765
- let r = kt(e.doc, t, i.type);
2766
- r != null && (t = n = r);
2767
- }
2768
- e.replaceRange(t, n, new l(r.from(i), 0, 0));
2769
- }
2770
- function Bt(e, t, n) {
2771
- let r = e.doc.resolve(t), i = e.doc.resolve(n);
2772
- if (r.parent.isTextblock && i.parent.isTextblock && r.start() != i.start() && r.parentOffset == 0 && i.parentOffset == 0) {
2773
- let a = r.sharedDepth(n), o = !1;
2774
- for (let e = r.depth; e > a; e--) r.node(e).type.spec.isolating && (o = !0);
2775
- for (let e = i.depth; e > a; e--) i.node(e).type.spec.isolating && (o = !0);
2776
- if (!o) {
2777
- for (let e = r.depth; e > 0 && t == r.start(e); e--) t = r.before(e);
2778
- for (let e = i.depth; e > 0 && n == i.start(e); e--) n = i.before(e);
2779
- r = e.doc.resolve(t), i = e.doc.resolve(n);
2780
- }
2781
- }
2782
- let a = Vt(r, i);
2783
- for (let t = 0; t < a.length; t++) {
2784
- let n = a[t], o = t == a.length - 1;
2785
- if (o && n == 0 || r.node(n).type.contentMatch.validEnd) return e.delete(r.start(n), i.end(n));
2786
- if (n > 0 && (o || r.node(n - 1).canReplace(r.index(n - 1), i.indexAfter(n - 1)))) return e.delete(r.before(n), i.after(n));
2787
- }
2788
- for (let a = 1; a <= r.depth && a <= i.depth; a++) if (t - r.start(a) == r.depth - a && n > r.end(a) && i.end(a) - n != i.depth - a && r.start(a - 1) == i.start(a - 1) && r.node(a - 1).canReplace(r.index(a - 1), i.index(a - 1))) return e.delete(r.before(a), n);
2789
- e.delete(t, n);
2790
- }
2791
- function Vt(e, t) {
2792
- let n = [], r = Math.min(e.depth, t.depth);
2793
- for (let i = r; i >= 0; i--) {
2794
- let r = e.start(i);
2795
- if (r < e.pos - (e.depth - i) || t.end(i) > t.pos + (t.depth - i) || e.node(i).type.spec.isolating || t.node(i).type.spec.isolating) break;
2796
- (r == t.start(i) || i == e.depth && i == t.depth && e.parent.inlineContent && t.parent.inlineContent && i && t.start(i - 1) == r - 1) && n.push(i);
2797
- }
2798
- return n;
2799
- }
2800
- var Ht = class e extends A {
2801
- constructor(e, t, n) {
2802
- super(), this.pos = e, this.attr = t, this.value = n;
2803
- }
2804
- apply(e) {
2805
- let t = e.nodeAt(this.pos);
2806
- if (!t) return j.fail("No node at attribute step's position");
2807
- let n = Object.create(null);
2808
- for (let e in t.attrs) n[e] = t.attrs[e];
2809
- n[this.attr] = this.value;
2810
- let i = t.type.create(n, null, t.marks);
2811
- return j.fromReplace(e, this.pos, this.pos + 1, new l(r.from(i), 0, +!t.isLeaf));
2812
- }
2813
- getMap() {
2814
- return O.empty;
2815
- }
2816
- invert(t) {
2817
- return new e(this.pos, this.attr, t.nodeAt(this.pos).attrs[this.attr]);
2818
- }
2819
- map(t) {
2820
- let n = t.mapResult(this.pos, 1);
2821
- return n.deletedAfter ? null : new e(n.pos, this.attr, this.value);
2822
- }
2823
- toJSON() {
2824
- return {
2825
- stepType: "attr",
2826
- pos: this.pos,
2827
- attr: this.attr,
2828
- value: this.value
2829
- };
2830
- }
2831
- static fromJSON(t, n) {
2832
- if (typeof n.pos != "number" || typeof n.attr != "string") throw RangeError("Invalid input for AttrStep.fromJSON");
2833
- return new e(n.pos, n.attr, n.value);
2834
- }
2835
- };
2836
- A.jsonID("attr", Ht);
2837
- var Ut = class e extends A {
2838
- constructor(e, t) {
2839
- super(), this.attr = e, this.value = t;
2840
- }
2841
- apply(e) {
2842
- let t = Object.create(null);
2843
- for (let n in e.attrs) t[n] = e.attrs[n];
2844
- t[this.attr] = this.value;
2845
- let n = e.type.create(t, e.content, e.marks);
2846
- return j.ok(n);
2847
- }
2848
- getMap() {
2849
- return O.empty;
2850
- }
2851
- invert(t) {
2852
- return new e(this.attr, t.attrs[this.attr]);
2853
- }
2854
- map(e) {
2855
- return this;
2856
- }
2857
- toJSON() {
2858
- return {
2859
- stepType: "docAttr",
2860
- attr: this.attr,
2861
- value: this.value
2862
- };
2863
- }
2864
- static fromJSON(t, n) {
2865
- if (typeof n.attr != "string") throw RangeError("Invalid input for DocAttrStep.fromJSON");
2866
- return new e(n.attr, n.value);
2867
- }
2868
- };
2869
- A.jsonID("docAttr", Ut);
2870
- var G = class extends Error {};
2871
- G = function e(t) {
2872
- let n = Error.call(this, t);
2873
- return n.__proto__ = e.prototype, n;
2874
- }, G.prototype = Object.create(Error.prototype), G.prototype.constructor = G, G.prototype.name = "TransformError";
2875
- var Wt = class {
2876
- constructor(e) {
2877
- this.doc = e, this.steps = [], this.docs = [], this.mapping = new ot();
2878
- }
2879
- get before() {
2880
- return this.docs.length ? this.docs[0] : this.doc;
2881
- }
2882
- step(e) {
2883
- let t = this.maybeStep(e);
2884
- if (t.failed) throw new G(t.failed);
2885
- return this;
2886
- }
2887
- maybeStep(e) {
2888
- let t = e.apply(this.doc);
2889
- return t.failed || this.addStep(e, t.doc), t;
2890
- }
2891
- get docChanged() {
2892
- return this.steps.length > 0;
2893
- }
2894
- changedRange() {
2895
- let e = 1e9, t = -1e9;
2896
- for (let n = 0; n < this.mapping.maps.length; n++) {
2897
- let r = this.mapping.maps[n];
2898
- n && (e = r.map(e, 1), t = r.map(t, -1)), r.forEach((n, r, i, a) => {
2899
- e = Math.min(e, i), t = Math.max(t, a);
2900
- });
2901
- }
2902
- return e == 1e9 ? null : {
2903
- from: e,
2904
- to: t
2905
- };
2906
- }
2907
- addStep(e, t) {
2908
- this.docs.push(this.doc), this.steps.push(e), this.mapping.appendMap(e.getMap()), this.doc = t;
2909
- }
2910
- replace(e, t = e, n = l.empty) {
2911
- let r = jt(this.doc, e, t, n);
2912
- return r && this.step(r), this;
2913
- }
2914
- replaceWith(e, t, n) {
2915
- return this.replace(e, t, new l(r.from(n), 0, 0));
2916
- }
2917
- delete(e, t) {
2918
- return this.replace(e, t, l.empty);
2919
- }
2920
- insert(e, t) {
2921
- return this.replaceWith(e, e, t);
2922
- }
2923
- replaceRange(e, t, n) {
2924
- return Lt(this, e, t, n), this;
2925
- }
2926
- replaceRangeWith(e, t, n) {
2927
- return zt(this, e, t, n), this;
2928
- }
2929
- deleteRange(e, t) {
2930
- return Bt(this, e, t), this;
2931
- }
2932
- lift(e, t) {
2933
- return dt(this, e, t), this;
2934
- }
2935
- join(e, t = 1) {
2936
- return Ot(this, e, t), this;
2937
- }
2938
- wrap(e, t) {
2939
- return gt(this, e, t), this;
2940
- }
2941
- setBlockType(e, t = e, n, r = null) {
2942
- return _t(this, e, t, n, r), this;
2943
- }
2944
- setNodeMarkup(e, t, n = null, r) {
2945
- return xt(this, e, t, n, r), this;
2946
- }
2947
- setNodeAttribute(e, t, n) {
2948
- return this.step(new Ht(e, t, n)), this;
2949
- }
2950
- setDocAttribute(e, t) {
2951
- return this.step(new Ut(e, t)), this;
2952
- }
2953
- addNodeMark(e, t) {
2954
- return this.step(new F(e, t)), this;
2955
- }
2956
- removeNodeMark(e, t) {
2957
- let n = this.doc.nodeAt(e);
2958
- if (!n) throw RangeError("No node at position " + e);
2959
- if (t instanceof s) t.isInSet(n.marks) && this.step(new I(e, t));
2960
- else {
2961
- let r = n.marks, i, a = [];
2962
- for (; i = t.isInSet(r);) a.push(new I(e, i)), r = i.removeFromSet(r);
2963
- for (let e = a.length - 1; e >= 0; e--) this.step(a[e]);
2964
- }
2965
- return this;
2966
- }
2967
- split(e, t = 1, n) {
2968
- return Ct(this, e, t, n), this;
2969
- }
2970
- addMark(e, t, n) {
2971
- return st(this, e, t, n), this;
2972
- }
2973
- removeMark(e, t, n) {
2974
- return ct(this, e, t, n), this;
2975
- }
2976
- clearIncompatible(e, t, n) {
2977
- return B(this, e, t, n), this;
2978
- }
2979
- }, K = Object.create(null), q = class {
2980
- constructor(e, t, n) {
2981
- this.$anchor = e, this.$head = t, this.ranges = n || [new Gt(e.min(t), e.max(t))];
2982
- }
2983
- get anchor() {
2984
- return this.$anchor.pos;
2985
- }
2986
- get head() {
2987
- return this.$head.pos;
2988
- }
2989
- get from() {
2990
- return this.$from.pos;
2991
- }
2992
- get to() {
2993
- return this.$to.pos;
2994
- }
2995
- get $from() {
2996
- return this.ranges[0].$from;
2997
- }
2998
- get $to() {
2999
- return this.ranges[0].$to;
3000
- }
3001
- get empty() {
3002
- let e = this.ranges;
3003
- for (let t = 0; t < e.length; t++) if (e[t].$from.pos != e[t].$to.pos) return !1;
3004
- return !0;
3005
- }
3006
- content() {
3007
- return this.$from.doc.slice(this.from, this.to, !0);
3008
- }
3009
- replace(e, t = l.empty) {
3010
- let n = t.content.lastChild, r = null;
3011
- for (let e = 0; e < t.openEnd; e++) r = n, n = n.lastChild;
3012
- let i = e.steps.length, a = this.ranges;
3013
- for (let o = 0; o < a.length; o++) {
3014
- let { $from: s, $to: c } = a[o], u = e.mapping.slice(i);
3015
- e.replaceRange(u.map(s.pos), u.map(c.pos), o ? l.empty : t), o == 0 && Zt(e, i, (n ? n.isInline : r && r.isTextblock) ? -1 : 1);
3016
- }
3017
- }
3018
- replaceWith(e, t) {
3019
- let n = e.steps.length, r = this.ranges;
3020
- for (let i = 0; i < r.length; i++) {
3021
- let { $from: a, $to: o } = r[i], s = e.mapping.slice(n), c = s.map(a.pos), l = s.map(o.pos);
3022
- i ? e.deleteRange(c, l) : (e.replaceRangeWith(c, l, t), Zt(e, n, t.isInline ? -1 : 1));
3023
- }
3024
- }
3025
- static findFrom(e, t, n = !1) {
3026
- let r = e.parent.inlineContent ? new J(e) : Z(e.node(0), e.parent, e.pos, e.index(), t, n);
3027
- if (r) return r;
3028
- for (let r = e.depth - 1; r >= 0; r--) {
3029
- let i = t < 0 ? Z(e.node(0), e.node(r), e.before(r + 1), e.index(r), t, n) : Z(e.node(0), e.node(r), e.after(r + 1), e.index(r) + 1, t, n);
3030
- if (i) return i;
3031
- }
3032
- return null;
3033
- }
3034
- static near(e, t = 1) {
3035
- return this.findFrom(e, t) || this.findFrom(e, -t) || new X(e.node(0));
3036
- }
3037
- static atStart(e) {
3038
- return Z(e, e, 0, 0, 1) || new X(e);
3039
- }
3040
- static atEnd(e) {
3041
- return Z(e, e, e.content.size, e.childCount, -1) || new X(e);
3042
- }
3043
- static fromJSON(e, t) {
3044
- if (!t || !t.type) throw RangeError("Invalid input for Selection.fromJSON");
3045
- let n = K[t.type];
3046
- if (!n) throw RangeError(`No selection type ${t.type} defined`);
3047
- return n.fromJSON(e, t);
3048
- }
3049
- static jsonID(e, t) {
3050
- if (e in K) throw RangeError("Duplicate use of selection JSON ID " + e);
3051
- return K[e] = t, t.prototype.jsonID = e, t;
3052
- }
3053
- getBookmark() {
3054
- return J.between(this.$anchor, this.$head).getBookmark();
3055
- }
3056
- };
3057
- q.prototype.visible = !0;
3058
- var Gt = class {
3059
- constructor(e, t) {
3060
- this.$from = e, this.$to = t;
3061
- }
3062
- }, Kt = !1;
3063
- function qt(e) {
3064
- !Kt && !e.parent.inlineContent && (Kt = !0, console.warn("TextSelection endpoint not pointing into a node with inline content (" + e.parent.type.name + ")"));
3065
- }
3066
- var J = class e extends q {
3067
- constructor(e, t = e) {
3068
- qt(e), qt(t), super(e, t);
3069
- }
3070
- get $cursor() {
3071
- return this.$anchor.pos == this.$head.pos ? this.$head : null;
3072
- }
3073
- map(t, n) {
3074
- let r = t.resolve(n.map(this.head));
3075
- if (!r.parent.inlineContent) return q.near(r);
3076
- let i = t.resolve(n.map(this.anchor));
3077
- return new e(i.parent.inlineContent ? i : r, r);
3078
- }
3079
- replace(e, t = l.empty) {
3080
- if (super.replace(e, t), t == l.empty) {
3081
- let t = this.$from.marksAcross(this.$to);
3082
- t && e.ensureMarks(t);
3083
- }
3084
- }
3085
- eq(t) {
3086
- return t instanceof e && t.anchor == this.anchor && t.head == this.head;
3087
- }
3088
- getBookmark() {
3089
- return new Jt(this.anchor, this.head);
3090
- }
3091
- toJSON() {
3092
- return {
3093
- type: "text",
3094
- anchor: this.anchor,
3095
- head: this.head
3096
- };
3097
- }
3098
- static fromJSON(t, n) {
3099
- if (typeof n.anchor != "number" || typeof n.head != "number") throw RangeError("Invalid input for TextSelection.fromJSON");
3100
- return new e(t.resolve(n.anchor), t.resolve(n.head));
3101
- }
3102
- static create(e, t, n = t) {
3103
- let r = e.resolve(t);
3104
- return new this(r, n == t ? r : e.resolve(n));
3105
- }
3106
- static between(t, n, r) {
3107
- let i = t.pos - n.pos;
3108
- if ((!r || i) && (r = i >= 0 ? 1 : -1), !n.parent.inlineContent) {
3109
- let e = q.findFrom(n, r, !0) || q.findFrom(n, -r, !0);
3110
- if (e) n = e.$head;
3111
- else return q.near(n, r);
3112
- }
3113
- return t.parent.inlineContent || (i == 0 ? t = n : (t = (q.findFrom(t, -r, !0) || q.findFrom(t, r, !0)).$anchor, t.pos < n.pos != i < 0 && (t = n))), new e(t, n);
3114
- }
3115
- };
3116
- q.jsonID("text", J);
3117
- var Jt = class e {
3118
- constructor(e, t) {
3119
- this.anchor = e, this.head = t;
3120
- }
3121
- map(t) {
3122
- return new e(t.map(this.anchor), t.map(this.head));
3123
- }
3124
- resolve(e) {
3125
- return J.between(e.resolve(this.anchor), e.resolve(this.head));
3126
- }
3127
- }, Y = class e extends q {
3128
- constructor(e) {
3129
- let t = e.nodeAfter, n = e.node(0).resolve(e.pos + t.nodeSize);
3130
- super(e, n), this.node = t;
3131
- }
3132
- map(t, n) {
3133
- let { deleted: r, pos: i } = n.mapResult(this.anchor), a = t.resolve(i);
3134
- return r ? q.near(a) : new e(a);
3135
- }
3136
- content() {
3137
- return new l(r.from(this.node), 0, 0);
3138
- }
3139
- eq(t) {
3140
- return t instanceof e && t.anchor == this.anchor;
3141
- }
3142
- toJSON() {
3143
- return {
3144
- type: "node",
3145
- anchor: this.anchor
3146
- };
3147
- }
3148
- getBookmark() {
3149
- return new Yt(this.anchor);
3150
- }
3151
- static fromJSON(t, n) {
3152
- if (typeof n.anchor != "number") throw RangeError("Invalid input for NodeSelection.fromJSON");
3153
- return new e(t.resolve(n.anchor));
3154
- }
3155
- static create(t, n) {
3156
- return new e(t.resolve(n));
3157
- }
3158
- static isSelectable(e) {
3159
- return !e.isText && e.type.spec.selectable !== !1;
3160
- }
3161
- };
3162
- Y.prototype.visible = !1, q.jsonID("node", Y);
3163
- var Yt = class e {
3164
- constructor(e) {
3165
- this.anchor = e;
3166
- }
3167
- map(t) {
3168
- let { deleted: n, pos: r } = t.mapResult(this.anchor);
3169
- return n ? new Jt(r, r) : new e(r);
3170
- }
3171
- resolve(e) {
3172
- let t = e.resolve(this.anchor), n = t.nodeAfter;
3173
- return n && Y.isSelectable(n) ? new Y(t) : q.near(t);
3174
- }
3175
- }, X = class e extends q {
3176
- constructor(e) {
3177
- super(e.resolve(0), e.resolve(e.content.size));
3178
- }
3179
- replace(e, t = l.empty) {
3180
- if (t == l.empty) {
3181
- e.delete(0, e.doc.content.size);
3182
- let t = q.atStart(e.doc);
3183
- t.eq(e.selection) || e.setSelection(t);
3184
- } else super.replace(e, t);
3185
- }
3186
- toJSON() {
3187
- return { type: "all" };
3188
- }
3189
- static fromJSON(t) {
3190
- return new e(t);
3191
- }
3192
- map(t) {
3193
- return new e(t);
3194
- }
3195
- eq(t) {
3196
- return t instanceof e;
3197
- }
3198
- getBookmark() {
3199
- return Xt;
3200
- }
3201
- };
3202
- q.jsonID("all", X);
3203
- var Xt = {
3204
- map() {
3205
- return this;
3206
- },
3207
- resolve(e) {
3208
- return new X(e);
3209
- }
3210
- };
3211
- function Z(e, t, n, r, i, a = !1) {
3212
- if (t.inlineContent) return J.create(e, n);
3213
- for (let o = r - (i > 0 ? 0 : 1); i > 0 ? o < t.childCount : o >= 0; o += i) {
3214
- let r = t.child(o);
3215
- if (!r.isAtom) {
3216
- let t = Z(e, r, n + i, i < 0 ? r.childCount : 0, i, a);
3217
- if (t) return t;
3218
- } else if (!a && Y.isSelectable(r)) return Y.create(e, n - (i < 0 ? r.nodeSize : 0));
3219
- n += r.nodeSize * i;
3220
- }
3221
- return null;
3222
- }
3223
- function Zt(e, t, n) {
3224
- let r = e.steps.length - 1;
3225
- if (r < t) return;
3226
- let i = e.steps[r];
3227
- if (!(i instanceof L || i instanceof R)) return;
3228
- let a = e.mapping.maps[r], o;
3229
- a.forEach((e, t, n, r) => {
3230
- o ??= r;
3231
- }), e.setSelection(q.near(e.doc.resolve(o), n));
3232
- }
3233
- var Qt = 1, $t = 2, en = 4, tn = class extends Wt {
3234
- constructor(e) {
3235
- super(e.doc), this.curSelectionFor = 0, this.updated = 0, this.meta = Object.create(null), this.time = Date.now(), this.curSelection = e.selection, this.storedMarks = e.storedMarks;
3236
- }
3237
- get selection() {
3238
- return this.curSelectionFor < this.steps.length && (this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)), this.curSelectionFor = this.steps.length), this.curSelection;
3239
- }
3240
- setSelection(e) {
3241
- if (e.$from.doc != this.doc) throw RangeError("Selection passed to setSelection must point at the current document");
3242
- return this.curSelection = e, this.curSelectionFor = this.steps.length, this.updated = (this.updated | Qt) & -3, this.storedMarks = null, this;
3243
- }
3244
- get selectionSet() {
3245
- return (this.updated & Qt) > 0;
3246
- }
3247
- setStoredMarks(e) {
3248
- return this.storedMarks = e, this.updated |= $t, this;
3249
- }
3250
- ensureMarks(e) {
3251
- return s.sameSet(this.storedMarks || this.selection.$from.marks(), e) || this.setStoredMarks(e), this;
3252
- }
3253
- addStoredMark(e) {
3254
- return this.ensureMarks(e.addToSet(this.storedMarks || this.selection.$head.marks()));
3255
- }
3256
- removeStoredMark(e) {
3257
- return this.ensureMarks(e.removeFromSet(this.storedMarks || this.selection.$head.marks()));
3258
- }
3259
- get storedMarksSet() {
3260
- return (this.updated & $t) > 0;
3261
- }
3262
- addStep(e, t) {
3263
- super.addStep(e, t), this.updated &= -3, this.storedMarks = null;
3264
- }
3265
- setTime(e) {
3266
- return this.time = e, this;
3267
- }
3268
- replaceSelection(e) {
3269
- return this.selection.replace(this, e), this;
3270
- }
3271
- replaceSelectionWith(e, t = !0) {
3272
- let n = this.selection;
3273
- return t && (e = e.mark(this.storedMarks || (n.empty ? n.$from.marks() : n.$from.marksAcross(n.$to) || s.none))), n.replaceWith(this, e), this;
3274
- }
3275
- deleteSelection() {
3276
- return this.selection.replace(this), this;
3277
- }
3278
- insertText(e, t, n) {
3279
- let r = this.doc.type.schema;
3280
- if (t == null) return e ? this.replaceSelectionWith(r.text(e), !0) : this.deleteSelection();
3281
- {
3282
- if (n ??= t, !e) return this.deleteRange(t, n);
3283
- let i = this.storedMarks;
3284
- if (!i) {
3285
- let e = this.doc.resolve(t);
3286
- i = n == t ? e.marks() : e.marksAcross(this.doc.resolve(n));
3287
- }
3288
- return this.replaceRangeWith(t, n, r.text(e, i)), !this.selection.empty && this.selection.to == t + e.length && this.setSelection(q.near(this.selection.$to)), this;
3289
- }
3290
- }
3291
- setMeta(e, t) {
3292
- return this.meta[typeof e == "string" ? e : e.key] = t, this;
3293
- }
3294
- getMeta(e) {
3295
- return this.meta[typeof e == "string" ? e : e.key];
3296
- }
3297
- get isGeneric() {
3298
- for (let e in this.meta) return !1;
3299
- return !0;
3300
- }
3301
- scrollIntoView() {
3302
- return this.updated |= en, this;
3303
- }
3304
- get scrolledIntoView() {
3305
- return (this.updated & en) > 0;
3306
- }
3307
- };
3308
- function nn(e, t) {
3309
- return !t || !e ? e : e.bind(t);
3310
- }
3311
- var Q = class {
3312
- constructor(e, t, n) {
3313
- this.name = e, this.init = nn(t.init, n), this.apply = nn(t.apply, n);
3314
- }
3315
- }, rn = [
3316
- new Q("doc", {
3317
- init(e) {
3318
- return e.doc || e.schema.topNodeType.createAndFill();
3319
- },
3320
- apply(e) {
3321
- return e.doc;
3322
- }
3323
- }),
3324
- new Q("selection", {
3325
- init(e, t) {
3326
- return e.selection || q.atStart(t.doc);
3327
- },
3328
- apply(e) {
3329
- return e.selection;
3330
- }
3331
- }),
3332
- new Q("storedMarks", {
3333
- init(e) {
3334
- return e.storedMarks || null;
3335
- },
3336
- apply(e, t, n, r) {
3337
- return r.selection.$cursor ? e.storedMarks : null;
3338
- }
3339
- }),
3340
- new Q("scrollToSelection", {
3341
- init() {
3342
- return 0;
3343
- },
3344
- apply(e, t) {
3345
- return e.scrolledIntoView ? t + 1 : t;
3346
- }
3347
- })
3348
- ], an = class {
3349
- constructor(e, t) {
3350
- this.schema = e, this.plugins = [], this.pluginsByKey = Object.create(null), this.fields = rn.slice(), t && t.forEach((e) => {
3351
- if (this.pluginsByKey[e.key]) throw RangeError("Adding different instances of a keyed plugin (" + e.key + ")");
3352
- this.plugins.push(e), this.pluginsByKey[e.key] = e, e.spec.state && this.fields.push(new Q(e.key, e.spec.state, e));
3353
- });
3354
- }
3355
- }, on = class e {
3356
- constructor(e) {
3357
- this.config = e;
3358
- }
3359
- get schema() {
3360
- return this.config.schema;
3361
- }
3362
- get plugins() {
3363
- return this.config.plugins;
3364
- }
3365
- apply(e) {
3366
- return this.applyTransaction(e).state;
3367
- }
3368
- filterTransaction(e, t = -1) {
3369
- for (let n = 0; n < this.config.plugins.length; n++) if (n != t) {
3370
- let t = this.config.plugins[n];
3371
- if (t.spec.filterTransaction && !t.spec.filterTransaction.call(t, e, this)) return !1;
3372
- }
3373
- return !0;
3374
- }
3375
- applyTransaction(e) {
3376
- if (!this.filterTransaction(e)) return {
3377
- state: this,
3378
- transactions: []
3379
- };
3380
- let t = [e], n = this.applyInner(e), r = null;
3381
- for (;;) {
3382
- let i = !1;
3383
- for (let a = 0; a < this.config.plugins.length; a++) {
3384
- let o = this.config.plugins[a];
3385
- if (o.spec.appendTransaction) {
3386
- let s = r ? r[a].n : 0, c = r ? r[a].state : this, l = s < t.length && o.spec.appendTransaction.call(o, s ? t.slice(s) : t, c, n);
3387
- if (l && n.filterTransaction(l, a)) {
3388
- if (l.setMeta("appendedTransaction", e), !r) {
3389
- r = [];
3390
- for (let e = 0; e < this.config.plugins.length; e++) r.push(e < a ? {
3391
- state: n,
3392
- n: t.length
3393
- } : {
3394
- state: this,
3395
- n: 0
3396
- });
3397
- }
3398
- t.push(l), n = n.applyInner(l), i = !0;
3399
- }
3400
- r && (r[a] = {
3401
- state: n,
3402
- n: t.length
3403
- });
3404
- }
3405
- }
3406
- if (!i) return {
3407
- state: n,
3408
- transactions: t
3409
- };
3410
- }
3411
- }
3412
- applyInner(t) {
3413
- if (!t.before.eq(this.doc)) throw RangeError("Applying a mismatched transaction");
3414
- let n = new e(this.config), r = this.config.fields;
3415
- for (let e = 0; e < r.length; e++) {
3416
- let i = r[e];
3417
- n[i.name] = i.apply(t, this[i.name], this, n);
3418
- }
3419
- return n;
3420
- }
3421
- get tr() {
3422
- return new tn(this);
3423
- }
3424
- static create(t) {
3425
- let n = new an(t.doc ? t.doc.type.schema : t.schema, t.plugins), r = new e(n);
3426
- for (let e = 0; e < n.fields.length; e++) r[n.fields[e].name] = n.fields[e].init(t, r);
3427
- return r;
3428
- }
3429
- reconfigure(t) {
3430
- let n = new an(this.schema, t.plugins), r = n.fields, i = new e(n);
3431
- for (let e = 0; e < r.length; e++) {
3432
- let n = r[e].name;
3433
- i[n] = this.hasOwnProperty(n) ? this[n] : r[e].init(t, i);
3434
- }
3435
- return i;
3436
- }
3437
- toJSON(e) {
3438
- let t = {
3439
- doc: this.doc.toJSON(),
3440
- selection: this.selection.toJSON()
3441
- };
3442
- if (this.storedMarks && (t.storedMarks = this.storedMarks.map((e) => e.toJSON())), e && typeof e == "object") for (let n in e) {
3443
- if (n == "doc" || n == "selection") throw RangeError("The JSON fields `doc` and `selection` are reserved");
3444
- let r = e[n], i = r.spec.state;
3445
- i && i.toJSON && (t[n] = i.toJSON.call(r, this[r.key]));
3446
- }
3447
- return t;
3448
- }
3449
- static fromJSON(t, n, r) {
3450
- if (!n) throw RangeError("Invalid input for EditorState.fromJSON");
3451
- if (!t.schema) throw RangeError("Required config field 'schema' missing");
3452
- let i = new an(t.schema, t.plugins), a = new e(i);
3453
- return i.fields.forEach((e) => {
3454
- if (e.name == "doc") a.doc = b.fromJSON(t.schema, n.doc);
3455
- else if (e.name == "selection") a.selection = q.fromJSON(a.doc, n.selection);
3456
- else if (e.name == "storedMarks") n.storedMarks && (a.storedMarks = n.storedMarks.map(t.schema.markFromJSON));
3457
- else {
3458
- if (r) for (let i in r) {
3459
- let o = r[i], s = o.spec.state;
3460
- if (o.key == e.name && s && s.fromJSON && Object.prototype.hasOwnProperty.call(n, i)) {
3461
- a[e.name] = s.fromJSON.call(o, t, n[i], a);
3462
- return;
3463
- }
3464
- }
3465
- a[e.name] = e.init(t, a);
3466
- }
3467
- }), a;
3468
- }
3469
- };
3470
- function sn(e, t, n) {
3471
- for (let r in e) {
3472
- let i = e[r];
3473
- i instanceof Function ? i = i.bind(t) : r == "handleDOMEvents" && (i = sn(i, t, {})), n[r] = i;
3474
- }
3475
- return n;
3476
- }
3477
- var cn = class {
3478
- constructor(e) {
3479
- this.spec = e, this.props = {}, e.props && sn(e.props, this, this.props), this.key = e.key ? e.key.key : ln("plugin");
3480
- }
3481
- getState(e) {
3482
- return e[this.key];
3483
- }
3484
- }, $ = Object.create(null);
3485
- function ln(e) {
3486
- return e in $ ? e + "$" + ++$[e] : ($[e] = 0, e + "$");
3487
- }
3488
- var un = class {
3489
- constructor(e = "key") {
3490
- this.key = ln(e);
3491
- }
3492
- get(e) {
3493
- return e.config.pluginsByKey[this.key];
3494
- }
3495
- getState(e) {
3496
- return e[this.key];
3497
- }
3498
- };
3499
- //#endregion
3500
- export { l as A, Ke as C, oe as D, b as E, De as O, Fe as S, s as T, At as _, un as a, ut as b, J as c, ot as d, R as f, St as g, wt as h, cn as i, je as k, tn as l, Wt as m, on as n, q as o, L as p, Y as r, Gt as s, X as t, N as u, ft as v, r as w, jt as x, Dt as y };