editate 0.6.20 → 0.6.22

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.
package/lib/index.cjs CHANGED
@@ -2,32 +2,32 @@ Object.defineProperty(exports, Symbol.toStringTag, {
2
2
  value: "Module"
3
3
  });
4
4
 
5
- var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typeof t, s = t => "function" == typeof t, c = s(queueMicrotask) ? queueMicrotask : t => {
5
+ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typeof t, c = t => "function" == typeof t, s = c(queueMicrotask) ? queueMicrotask : t => {
6
6
  Promise.resolve().then(t);
7
- }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), f = new WeakMap, u = ({children: t}, e = 0, n = t.length) => {
7
+ }, i = t => "text" in t, l = t => "children" in t, a = t => t.some(l), u = new WeakMap, f = ({children: t}, e = 0, n = t.length) => {
8
8
  let r = 0, o = 0;
9
- for (let s = e; s < n; s++) {
10
- const e = t[s];
9
+ for (let c = e; c < n; c++) {
10
+ const e = t[c];
11
11
  r += p(e), 0 !== o && l(e) && r++, o++;
12
12
  }
13
13
  return r;
14
14
  }, p = t => {
15
15
  if (l(t)) {
16
- let e = f.get(t);
17
- return null == e && f.set(t, e = u(t)), e;
16
+ let e = u.get(t);
17
+ return null == e && u.set(t, e = f(t)), e;
18
18
  }
19
19
  return i(t) ? t.text.length : 1;
20
20
  }, d = ({children: t}, e, n) => {
21
21
  const r = t.length;
22
22
  for (let o = 0; o < r; o++) {
23
- const r = t[o], s = l(r);
24
- let c = p(r);
25
- const i = 0 === c;
26
- if (s && c++, c > e || c === e && !s && (n || i)) return [ r, e, o ];
27
- e -= c;
23
+ const r = t[o], c = l(r);
24
+ let s = p(r);
25
+ const i = 0 === s;
26
+ if (c && s++, s > e || s === e && !c && (n || i)) return [ r, e, o ];
27
+ e -= s;
28
28
  }
29
29
  return null;
30
- }, x = (t, e) => {
30
+ }, h = (t, e) => {
31
31
  const n = [];
32
32
  for (;t; ) {
33
33
  const r = d(t, e);
@@ -38,15 +38,15 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
38
38
  }
39
39
  return [ t, e, n ];
40
40
  }, y = (t, e, n) => {
41
- const [r, o, s] = x(t, e), c = d(r, o, n);
42
- return c ? (s.push(c[2]), [ c[0], c[1], s ]) : null;
43
- }, h = (t, e) => {
41
+ const [r, o, c] = h(t, e), s = d(r, o, n);
42
+ return s ? (c.push(s[2]), [ s[0], s[1], c ]) : null;
43
+ }, x = (t, e) => {
44
44
  const n = t.children, r = d(t, e);
45
45
  if (r) {
46
- const [e, o, s] = r;
46
+ const [e, o, c] = r;
47
47
  if (l(e)) {
48
- const [r, c] = h(e, o), i = n.slice(0, s), l = n.slice(s + 1);
49
- return i.push(r), l.unshift(c), [ {
48
+ const [r, s] = x(e, o), i = n.slice(0, c), l = n.slice(c + 1);
49
+ return i.push(r), l.unshift(s), [ {
50
50
  ...t,
51
51
  children: i
52
52
  }, {
@@ -55,23 +55,23 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
55
55
  } ];
56
56
  }
57
57
  {
58
- const r = n.slice(0, s), c = n.slice(s + 1);
58
+ const r = n.slice(0, c), s = n.slice(c + 1);
59
59
  if (i(e)) {
60
60
  const t = e.text.slice(0, o), n = e.text.slice(o);
61
61
  !t && r.length || r.push({
62
62
  ...e,
63
63
  text: t
64
- }), !n && c.length || c.unshift({
64
+ }), !n && s.length || s.unshift({
65
65
  ...e,
66
66
  text: n
67
67
  });
68
- } else c.unshift(e);
68
+ } else s.unshift(e);
69
69
  return [ {
70
70
  ...t,
71
71
  children: r
72
72
  }, {
73
73
  ...t,
74
- children: c
74
+ children: s
75
75
  } ];
76
76
  }
77
77
  }
@@ -85,145 +85,77 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
85
85
  } ];
86
86
  }, k = (t, [e, n]) => {
87
87
  let r = 0;
88
- for (const o of e) r += u(t, 0, o), 0 !== o && r++, t = t.children[o];
88
+ for (const o of e) r += f(t, 0, o), 0 !== o && r++, t = t.children[o];
89
89
  return r + n;
90
- }, g = (t, e) => {
91
- const [, n, r] = x(t, e);
90
+ }, m = (t, e) => {
91
+ const [, n, r] = h(t, e);
92
92
  return [ r, n ];
93
- }, m = (t, [e, n]) => [ k(t, e), k(t, n) ];
93
+ }, g = (t, [e, n]) => [ k(t, e), k(t, n) ];
94
94
 
95
95
  function* _(t, [e, n]) {
96
96
  if (e >= n) return;
97
97
  if (!l(t)) return;
98
98
  const r = d(t, e);
99
99
  if (r) {
100
- let o = e - r[1], s = r[2];
101
- const c = t.children, i = c.length;
102
- for (;o <= n && s < i; ) {
103
- const t = c[s];
104
- yield [ t, o ], s++, o += p(t), l(t) && o++;
100
+ let o = e - r[1], c = r[2];
101
+ const s = t.children, i = s.length;
102
+ for (;o <= n && c < i; ) {
103
+ const t = s[c];
104
+ yield [ t, o ], c++, o += p(t), l(t) && o++;
105
105
  }
106
106
  }
107
107
  }
108
108
 
109
109
  function* b(t, e) {
110
- if (l(t)) for (const [n, r] of _(t, e)) for (const t of b(n, [ 0, p(n) ])) t[1] += r,
111
- yield t; else yield [ t, 0 ];
110
+ if (!l(t) || a(t.children)) for (const n of _(t, e)) {
111
+ const [t, e] = n;
112
+ for (const n of b(t, [ 0, p(t) ])) n[1] += e, yield n;
113
+ } else yield [ t, 0 ];
112
114
  }
113
115
 
114
- var v = (n, r = 0, o = 1 / 0, s) => {
115
- let c = "", l = r;
116
- for (const [a, f] of b(n, [ r, o ])) {
117
- for (let t = f - l; t > 0; t--) c += "\n";
118
- const n = p(a), u = f + n;
119
- if (i(a)) {
120
- const s = e(f, r) - f, i = t(u, o) - f;
121
- c += 0 === s && i === n ? a.text : a.text.slice(s, i);
122
- } else s && (c += s(a));
123
- l = u;
124
- }
125
- for (let e = t(o, p(n)) - l; e > 0; e--) c += "\n";
126
- return c;
127
- }, T = (t, e, n) => e >= n ? [] : h(h(t, n)[0], e)[1].children, E = ([t, e]) => t > e ? [ e, t ] : [ t, e ], M = ([t, e]) => t === e, S = ([t, e], [n, r]) => t < r && n < e;
128
-
129
- function* w(t, e = E(t.selection)) {
130
- if (M(e)) {
131
- const n = y(t.doc, e[0])?.[0];
132
- n && (yield n);
133
- } else for (const [n, r] of b(t.doc, e)) S(e, [ r, r + p(n) ]) && (yield n);
134
- }
135
-
136
- function A(t, e) {
137
- t.apply({
138
- type: "patch_node",
139
- path: [],
140
- key: "children",
141
- value: e
142
- });
116
+ function* v(t, e) {
117
+ if (l(t)) for (const [n, r] of _(t, e)) for (const t of v(n, [ 0, p(n) ])) t[1] += r,
118
+ yield t; else yield [ t, 0 ];
143
119
  }
144
120
 
145
- var O = t => 1 === t.nodeType, R = t => 8 === t.nodeType, D = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), B = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), I = t => B.has(t.tagName), P = (t, e) => t.compareDocumentPosition(e), N = t => t.ownerDocument, L = t => N(t).getSelection(), C = (t, e) => {
146
- if (t.rangeCount) {
147
- const n = t.getRangeAt(0);
148
- if (e.contains(n.commonAncestorContainer)) return n;
149
- }
150
- }, H = (t, e, n, r) => {
151
- const [o, s] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), c = N(t), i = M(r), l = r[0] - r[1] > 0, a = l ? o : s, f = U(t, e, l ? s : o), u = i ? f : U(t, e, a), p = c.createRange(), [d, x] = f, [y, h] = u;
152
- return O(d) && t !== d ? x < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, x),
153
- O(y) && t !== y ? h < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, h),
154
- p;
155
- }, F = (t, e, n, r, o) => {
156
- const s = L(t);
157
- if (o || C(s, t)) {
158
- const o = H(t, e, n, r), c = r[0] - r[1] > 0;
159
- s.removeAllRanges(), s.addRange(o), c && (s.collapseToEnd(), s.extend(o.startContainer, o.startOffset));
160
- }
161
- }, U = (t, e, [n, r]) => e(({t: e, o, i: s, l: c}) => {
162
- let i, l = 0;
163
- for (;i = e(); ) if (4 === i) {
164
- if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
165
- } else {
166
- const t = c();
167
- if (r <= t) return [ s(), r ];
168
- r -= t;
169
- }
170
- return [ t, 0 ];
171
- }, t), V = (e, n, r, o) => {
172
- let s = !0;
173
- if (e === r && !r.hasChildNodes()) return [ [], 0 ];
174
- if (O(r) && r.hasChildNodes()) {
175
- const e = t(o, r.childNodes.length - 1);
176
- r = r.childNodes[e], s = e === o, o = 0;
121
+ var T = (n, r = 0, o = 1 / 0, c) => {
122
+ let s = "", l = r;
123
+ for (const [a, u] of v(n, [ r, o ])) {
124
+ for (let t = u - l; t > 0; t--) s += "\n";
125
+ const n = p(a), f = u + n;
126
+ if (i(a)) {
127
+ const c = e(u, r) - u, i = t(f, o) - u;
128
+ s += 0 === c && i === n ? a.text : a.text.slice(c, i);
129
+ } else c && (s += c(a));
130
+ l = f;
177
131
  }
178
- return n(({t, u: c, p: i, h: l, i: a, l: f, k: u}) => {
179
- c(r), 4 !== u() && i();
180
- const p = n(() => {
181
- const t = [];
182
- for (;u() && a() !== e; ) {
183
- let e = 0;
184
- for (;l(), u(); ) e++;
185
- t.unshift(e), i();
186
- }
187
- return t;
188
- });
189
- let d = 0;
190
- for (;t(); ) {
191
- const t = P(r, a());
192
- if (0 === t || 16 & t) {
193
- if (s) break;
194
- } else if (4 & t) break;
195
- d += f();
196
- }
197
- return [ p, d + o ];
198
- }, e);
199
- }, W = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
200
- const c = V(t, e, r, n);
201
- return [ c, r === s && n === o ? c : V(t, e, s, o) ];
202
- }, q = (t, e, n) => t.split("\n").map(t => ({
132
+ for (let e = t(o, p(n)) - l; e > 0; e--) s += "\n";
133
+ return s;
134
+ }, E = (t, e, n) => e >= n ? [] : x(x(t, n)[0], e)[1].children, M = (t, e, n) => t.split("\n").map(t => ({
203
135
  ...n,
204
136
  children: [ {
205
137
  ...e,
206
138
  text: t
207
139
  } ]
208
- })), z = "delete", G = "insert_text", J = "insert_node", j = (t, e) => {
140
+ })), S = "delete", w = "insert_text", A = "insert_node", O = (t, e) => {
209
141
  const o = n(t);
210
142
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
211
- }, X = (t, e) => {
143
+ }, R = (t, e) => {
212
144
  if (e.length) {
213
145
  const n = t.length;
214
146
  if (t.push(...e), n) {
215
- const e = t[n - 1], r = t[n], o = l(e), s = l(r);
216
- o ? s && ((t, e = 0, n = t.length - 1) => {
147
+ const e = t[n - 1], r = t[n], o = l(e), c = l(r);
148
+ o ? c && ((t, e = 0, n = t.length - 1) => {
217
149
  let r = e + 1;
218
150
  for (;r <= n; ) {
219
151
  const e = t[r - 1], o = t[r];
220
- t[r - 1] = Y(e, o), t.splice(r, 1), n--;
152
+ t[r - 1] = D(e, o), t.splice(r, 1), n--;
221
153
  }
222
- })(t, n - 1, n) : o || s || ((t, e = 0, n = t.length - 1) => {
154
+ })(t, n - 1, n) : o || c || ((t, e = 0, n = t.length - 1) => {
223
155
  let r = e + 1;
224
156
  for (;r <= n; ) {
225
157
  const e = t[r - 1], o = t[r];
226
- i(e) && i(o) && j(e, o) ? (t[r - 1] = {
158
+ i(e) && i(o) && O(e, o) ? (t[r - 1] = {
227
159
  ...e,
228
160
  text: e.text + o.text
229
161
  }, t.splice(r, 1), n--) : r++;
@@ -238,60 +170,132 @@ var O = t => 1 === t.nodeType, R = t => 8 === t.nodeType, D = new Map([ [ "BR",
238
170
  t.length || t.push({
239
171
  text: ""
240
172
  });
241
- }, Y = (...t) => ({
173
+ }, D = (...t) => ({
242
174
  ...t[0],
243
- children: t.reduce((t, e) => (X(t, e.children), t), [])
244
- }), Z = (t, e, n, r = 0) => {
175
+ children: t.reduce((t, e) => (R(t, e.children), t), [])
176
+ }), B = (t, e, n, r = 0) => {
245
177
  if (r < e.length) {
246
- const o = e[r];
247
- return ((t, e, n, r) => {
248
- const o = t.children.slice();
249
- return o.splice(e, n - e + 1, ...r), {
250
- ...t,
251
- children: o
252
- };
253
- })(t, o, o, [ Z(t.children[o], e, n, r + 1) ]);
178
+ const o = e[r], c = t.children, s = c.slice();
179
+ return s.splice(o, 1, B(c[o], e, n, r + 1)), {
180
+ ...t,
181
+ children: s
182
+ };
254
183
  }
255
184
  return n;
256
- }, K = (t, e, n, r) => {
257
- const [o, s] = h(t, e), c = e < n ? h(t, n)[1] : s, i = a(t.children);
258
- a(r) ? i || (r = Y(...r).children) : i && (r = [ {
185
+ }, I = (t, e, n, r) => {
186
+ const [o, c] = x(t, e), s = e < n ? x(t, n)[1] : c, i = a(t.children);
187
+ a(r) ? i || (r = D(...r).children) : i && (r = [ {
259
188
  children: r
260
189
  } ]);
261
190
  const l = o.children.slice();
262
- return X(l, r), X(l, c.children), {
191
+ return R(l, r), R(l, s.children), {
263
192
  ...t,
264
193
  children: l
265
194
  };
266
- }, Q = (t, e) => e >= 0 && e <= p(t), $ = (t, e) => e.reduce((t, e) => tt(t, e), t), tt = (t, e) => {
195
+ }, L = (t, e) => e >= 0 && e <= p(t), P = (t, e) => e.reduce((t, e) => H(t, e), t), H = (t, e, n) => {
267
196
  switch (e.type) {
268
- case z:
197
+ case S:
269
198
  {
270
199
  const [n, r] = e.range;
271
200
  if (t >= n) return r >= t ? n : t + n - r;
272
201
  break;
273
202
  }
274
203
 
275
- case G:
204
+ case w:
276
205
  {
277
- const {at: n, text: r} = e;
278
- if (t >= n) return t + r.length;
206
+ const {at: r, text: o} = e;
207
+ if (n ? t > r : t >= r) return t + o.length;
279
208
  break;
280
209
  }
281
210
 
282
- case J:
211
+ case A:
283
212
  {
284
- const {at: n, fragment: r} = e;
285
- if (t >= n) return t + p({
286
- children: r
213
+ const {at: r, fragment: o} = e;
214
+ if (n ? t > r : t >= r) return t + p({
215
+ children: o
287
216
  });
288
217
  break;
289
218
  }
290
219
  }
291
220
  return t;
292
- }, et = ([t, e], n) => [ tt(t, n), tt(e, n) ], nt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), rt = (t, e) => {
293
- const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), s = "Space" === o ? " " : o.toLowerCase();
294
- let c = !1, i = !1, l = !1, a = !1;
221
+ }, N = ([t, e], n) => [ H(t, n), H(e, n) ], C = ([t, e]) => t > e ? [ e, t ] : [ t, e ], W = ([t, e]) => t === e, F = ([t, e], [n, r]) => t < r && n < e;
222
+
223
+ function* U(t, e = C(t.selection)) {
224
+ if (W(e)) {
225
+ const n = y(t.doc, e[0])?.[0];
226
+ n && (yield n);
227
+ } else for (const [n, r] of v(t.doc, e)) F(e, [ r, r + p(n) ]) && (yield n);
228
+ }
229
+
230
+ function V(t, e) {
231
+ t.apply({
232
+ type: "patch_node",
233
+ path: [],
234
+ key: "children",
235
+ value: e
236
+ });
237
+ }
238
+
239
+ var q = t => 1 === t.nodeType, z = t => 8 === t.nodeType, G = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), J = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), Y = t => J.has(t.tagName), j = (t, e) => t.compareDocumentPosition(e), X = t => t.ownerDocument, Z = t => X(t).getSelection(), K = (t, e) => {
240
+ if (t.rangeCount) {
241
+ const n = t.getRangeAt(0);
242
+ if (e.contains(n.commonAncestorContainer)) return n;
243
+ }
244
+ }, Q = (t, e, n, r) => {
245
+ const [o, c] = ((t, [e, n]) => [ m(t, e), m(t, n) ])(n, r), s = X(t), i = W(r), l = r[0] - r[1] > 0, a = l ? o : c, u = tt(t, e, l ? c : o), f = i ? u : tt(t, e, a), p = s.createRange(), [d, h] = u, [y, x] = f;
246
+ return q(d) && t !== d ? h < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, h),
247
+ q(y) && t !== y ? x < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, x),
248
+ p;
249
+ }, $ = (t, e, n, r, o) => {
250
+ const c = Z(t);
251
+ if (o || K(c, t)) {
252
+ const o = Q(t, e, n, r), s = r[0] - r[1] > 0;
253
+ c.removeAllRanges(), c.addRange(o), s && (c.collapseToEnd(), c.extend(o.startContainer, o.startOffset));
254
+ }
255
+ }, tt = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
256
+ let i, l = 0;
257
+ for (;i = e(); ) if (4 === i) {
258
+ if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
259
+ } else {
260
+ const t = s();
261
+ if (r <= t) return [ c(), r ];
262
+ r -= t;
263
+ }
264
+ return [ t, 0 ];
265
+ }, t), et = (e, n, r, o) => {
266
+ let c = !0;
267
+ if (e === r && !r.hasChildNodes()) return [ [], 0 ];
268
+ if (q(r) && r.hasChildNodes()) {
269
+ const e = t(o, r.childNodes.length - 1);
270
+ r = r.childNodes[e], c = e === o, o = 0;
271
+ }
272
+ return n(({t, u: s, p: i, h: l, i: a, l: u, k: f}) => {
273
+ s(r), 4 !== f() && i();
274
+ const p = n(() => {
275
+ const t = [];
276
+ for (;f() && a() !== e; ) {
277
+ let e = 0;
278
+ for (;l(), f(); ) e++;
279
+ t.unshift(e), i();
280
+ }
281
+ return t;
282
+ });
283
+ let d = 0;
284
+ for (;t(); ) {
285
+ const t = j(r, a());
286
+ if (0 === t || 16 & t) {
287
+ if (c) break;
288
+ } else if (4 & t) break;
289
+ d += u();
290
+ }
291
+ return [ p, d + o ];
292
+ }, e);
293
+ }, nt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
294
+ const s = et(t, e, r, n);
295
+ return [ s, r === c && n === o ? s : et(t, e, c, o) ];
296
+ }, rt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), ot = (t, e) => {
297
+ const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
298
+ let s = !1, i = !1, l = !1, a = !1;
295
299
  return r.forEach(t => {
296
300
  switch (t) {
297
301
  case "Ctrl":
@@ -303,7 +307,7 @@ var O = t => 1 === t.nodeType, R = t => 8 === t.nodeType, D = new Map([ [ "BR",
303
307
  break;
304
308
 
305
309
  case "Mod":
306
- nt ? l = !0 : i = !0;
310
+ rt ? l = !0 : i = !0;
307
311
  break;
308
312
 
309
313
  case "Alt":
@@ -311,131 +315,146 @@ var O = t => 1 === t.nodeType, R = t => 8 === t.nodeType, D = new Map([ [ "BR",
311
315
  break;
312
316
 
313
317
  case "Shift":
314
- c = !0;
318
+ s = !0;
315
319
  }
316
320
  }), t => {
317
- if (t.key.toLowerCase() === s && i === t.ctrlKey && l === t.metaKey && c === t.shiftKey && a === t.altKey) return !1 !== e(t);
321
+ if (t.key.toLowerCase() === c && i === t.ctrlKey && l === t.metaKey && s === t.shiftKey && a === t.altKey) return !1 !== e(t);
318
322
  };
319
323
  };
320
324
 
321
- function ot(t) {
322
- let e = 0, n = 0, r = !1;
323
- const o = Date.now, s = [ [ t.doc, t.selection, [] ] ], c = () => s[e], i = () => e > 0, l = () => e < s.length - 1, a = () => {
324
- if (i()) {
325
- const n = c()[1];
326
- e--;
327
- const o = t.doc;
328
- r = !0, t.exec(A, c()[0].children), r = !1, o !== t.doc && (t.selection = n);
329
- }
325
+ function ct(t) {
326
+ let e = 0, r = 0, o = !1;
327
+ const c = Date.now, s = [ [ t.doc, t.selection, [] ] ], i = () => s[e], l = () => e > 0, a = () => e < s.length - 1, u = e => {
328
+ t.exec(V, e.children);
329
+ const r = e, o = t.doc;
330
+ for (const c of n(r)) "children" !== c && o[c] !== r[c] && t.apply({
331
+ type: "patch_node",
332
+ path: [],
333
+ key: c,
334
+ value: r[c]
335
+ });
336
+ for (const c of n(o)) "children" === c || c in r || t.apply({
337
+ type: "patch_node",
338
+ path: [],
339
+ key: c,
340
+ value: void 0
341
+ });
330
342
  }, f = () => {
331
343
  if (l()) {
344
+ const n = i()[1];
345
+ e--;
346
+ const r = t.doc;
347
+ o = !0, u(i()[0]), o = !1, r !== t.doc && (t.selection = n);
348
+ }
349
+ }, p = () => {
350
+ if (a()) {
332
351
  e++;
333
- const [n, o, s] = c(), i = t.doc;
334
- r = !0, t.exec(A, n.children), r = !1, i !== t.doc && (t.selection = [ $(o[0], s), $(o[1], s) ]);
352
+ const [n, r, c] = i(), s = t.doc;
353
+ o = !0, u(n), o = !1, s !== t.doc && (t.selection = [ P(r[0], c), P(r[1], c) ]);
335
354
  }
336
355
  };
337
- t.hook("apply", (c, i) => {
338
- if (r) return;
356
+ t.hook("apply", (n, i) => {
357
+ if (o) return;
339
358
  const l = t.doc, a = t.selection;
340
- i(c);
341
- const f = t.doc;
342
- if (l !== f) {
343
- const t = o();
344
- if (0 === e || t - n >= 500) {
359
+ i(n);
360
+ const u = t.doc;
361
+ if (l !== u) {
362
+ const t = c();
363
+ if (0 === e || t - r >= 500) {
345
364
  e++;
346
365
  const t = [ l, a, [] ];
347
366
  e >= s.length ? s.push(t) : s[e] = t;
348
367
  }
349
- n = t, s[e][0] = f, s[e][2].push(c), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
368
+ r = t, s[e][0] = u, s[e][2].push(n), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
350
369
  s.shift());
351
370
  }
352
- }), t.hook("keyboard", rt("Mod+Z", a)), t.hook("keyboard", rt("Shift+Mod+Z", f)),
353
- t.set(ot, {
354
- undo: a,
355
- redo: f,
356
- undoable: i,
357
- redoable: l
371
+ }), t.hook("keyboard", ot("Mod+Z", f)), t.hook("keyboard", ot("Shift+Mod+Z", p)),
372
+ t.set(ct, {
373
+ undo: f,
374
+ redo: p,
375
+ undoable: l,
376
+ redoable: a
358
377
  });
359
378
  }
360
379
 
361
- var st = [], ct = () => {}, it = t => {
380
+ var st = [], it = () => {}, lt = t => {
362
381
  throw Error(t);
363
- }, lt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = I, onWarn: a = console.warn, onError: f = it}) => {
364
- let u = [ 0, 0 ];
382
+ }, at = ({doc: t, readonly: e = !1, schema: n, isBlock: r = Y, onWarn: a = console.warn, onError: u = lt}) => {
383
+ let f = [ 0, 0 ];
365
384
  const p = t => {
366
385
  if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
367
386
  !0;
368
387
  const e = n["~standard"].validate(t);
369
- if (e instanceof Promise) f("async validate is not supported"); else {
388
+ if (e instanceof Promise) u("async validate is not supported"); else {
370
389
  if (!e.issues) return !0;
371
390
  a(e.issues.map(t => t.message).join("\n"));
372
391
  }
373
392
  return !1;
374
393
  };
375
- n && !p(t) && f("Invalid document");
376
- const y = new Map, h = new WeakMap, g = t => y.get(t) || st, _ = new Map, b = new Set, v = t => {
394
+ n && !p(t) && u("Invalid document");
395
+ const y = new Map, x = new WeakMap, m = t => y.get(t) || st, _ = new Map, b = new Set, v = t => {
377
396
  const e = _.get(t);
378
- e && (b.size || c(() => {
397
+ e && (b.size || s(() => {
379
398
  b.forEach(t => {
380
399
  t();
381
400
  }), b.clear();
382
401
  }), e.forEach(t => {
383
402
  b.add(t);
384
403
  }));
385
- }, S = t => {
386
- if (!e) if (Array.isArray(t)) for (const e of t) w(e); else w(t);
387
- return R;
388
- }, w = e => {
389
- const n = t, r = g("apply"), o = r.length;
390
- let s = 0;
391
- const c = () => {
392
- if (s < o) {
393
- const t = s;
394
- r[s](e, f), t === s && f();
395
- } else if (s === o) {
396
- s++;
404
+ }, T = t => {
405
+ if (!e) if (Array.isArray(t)) for (const e of t) O(e); else O(t);
406
+ return D;
407
+ }, O = e => {
408
+ const n = t, r = m("apply"), o = r.length;
409
+ let c = 0;
410
+ const s = () => {
411
+ if (c < o) {
412
+ const t = c;
413
+ r[c](e, u), t === c && u(e);
414
+ } else if (c === o) {
415
+ c++;
397
416
  try {
398
417
  const [n, r] = ((t, e, n) => {
399
418
  switch (n.type) {
400
- case z:
419
+ case S:
401
420
  {
402
421
  const [r, o] = n.range;
403
- Q(t, r) && Q(t, o) && r < o && (t = K(t, r, o, []), e = et(e, n));
422
+ L(t, r) && L(t, o) && r < o && (t = I(t, r, o, []), e = N(e, n));
404
423
  break;
405
424
  }
406
425
 
407
- case G:
426
+ case w:
408
427
  {
409
428
  const {at: r, text: o} = n;
410
- if (Q(t, r) && o) {
411
- const [s, c] = x(t, r), l = d(s, c, !0);
429
+ if (L(t, r) && o) {
430
+ const [c, s] = h(t, r), l = d(c, s, !0);
412
431
  let a;
413
432
  if (l) {
414
433
  const t = l[0];
415
434
  i(t) && (a = t);
416
435
  }
417
- t = K(t, r, r, q(o, a, s)), e = et(e, n);
436
+ t = I(t, r, r, M(o, a, c)), e = N(e, n);
418
437
  }
419
438
  break;
420
439
  }
421
440
 
422
- case J:
441
+ case A:
423
442
  {
424
443
  const {at: r, fragment: o} = n;
425
- Q(t, r) && o.length && (t = K(t, r, r, o), e = et(e, n));
444
+ L(t, r) && o.length && (t = I(t, r, r, o), e = N(e, n));
426
445
  break;
427
446
  }
428
447
 
429
448
  case "format":
430
449
  {
431
- const {range: [e, r], key: o, value: s} = n;
432
- if (Q(t, e) && Q(t, r) && e <= r) if (e === r) {
433
- const [{children: n}, , r] = x(t, e);
450
+ const {range: [e, r], key: o, value: c} = n;
451
+ if (L(t, e) && L(t, r) && e <= r) if (e === r) {
452
+ const [{children: n}, , r] = h(t, e);
434
453
  if (1 === n.length) {
435
454
  const e = n[0];
436
- i(e) && !e.text && (t = Z(t, [ ...r, 0 ], {
455
+ i(e) && !e.text && (t = B(t, [ ...r, 0 ], {
437
456
  ...e,
438
- [o]: s
457
+ [o]: c
439
458
  }));
440
459
  }
441
460
  } else {
@@ -444,49 +463,49 @@ var st = [], ct = () => {}, it = t => {
444
463
  children: t.children.map(n)
445
464
  } : i(t) ? {
446
465
  ...t,
447
- [o]: s
466
+ [o]: c
448
467
  } : t;
449
- t = K(t, e, r, T(t, e, r).map(n));
468
+ t = I(t, e, r, E(t, e, r).map(n));
450
469
  }
451
470
  break;
452
471
  }
453
472
 
454
473
  case "patch_node":
455
474
  {
456
- const {path: e, key: r, value: o} = n, s = ((t, e) => {
475
+ const {path: e, key: r, value: o} = n, c = ((t, e) => {
457
476
  for (let n = 0; n < e.length; n++) t = t.children[e[n]];
458
477
  return t;
459
478
  })(t, e);
460
- s && (t = Z(t, e, {
461
- ...s,
479
+ c && (t = B(t, e, {
480
+ ...c,
462
481
  [r]: o
463
482
  }));
464
483
  break;
465
484
  }
466
485
  }
467
486
  return [ t, e ];
468
- })(t, u, e);
469
- (({type: t}) => t !== G && t !== z)(e) && !p(n) || (t = n, A(r));
487
+ })(t, f, e);
488
+ (({type: t}) => t !== w && t !== S)(e) && !p(n) || (t = n, R(r));
470
489
  } catch (n) {
471
490
  a("rollback operation: " + n);
472
491
  }
473
492
  }
474
- }, f = t => {
475
- t && (e = t), s++, c();
493
+ }, u = t => {
494
+ null != t ? (e = t, c++, s()) : c = o + 1;
476
495
  };
477
- c(), n !== t && v("change");
478
- }, A = e => {
479
- !((t, [e, n]) => Q(t, e) && Q(t, n))(t, e) || u[0] === e[0] && u[1] === e[1] || (u = e,
496
+ s(), n !== t && v("change");
497
+ }, R = e => {
498
+ !((t, [e, n]) => L(t, e) && L(t, n))(t, e) || f[0] === e[0] && f[1] === e[1] || (f = e,
480
499
  v("selectionchange"));
481
- }, R = {
500
+ }, D = {
482
501
  get doc() {
483
502
  return t;
484
503
  },
485
504
  get selection() {
486
- return u;
505
+ return f;
487
506
  },
488
507
  set selection(t) {
489
- A(t);
508
+ R(t);
490
509
  },
491
510
  get readonly() {
492
511
  return e;
@@ -494,7 +513,7 @@ var st = [], ct = () => {}, it = t => {
494
513
  set readonly(t) {
495
514
  e = t, v("readonly");
496
515
  },
497
- apply: S,
516
+ apply: T,
498
517
  on: (t, e) => {
499
518
  let n = _.get(t);
500
519
  return n || _.set(t, n = new Set), n.add(e), () => {
@@ -509,35 +528,35 @@ var st = [], ct = () => {}, it = t => {
509
528
  };
510
529
  },
511
530
  exec: (t, ...e) => {
512
- const n = t(R, ...e);
513
- return void 0 === n ? R : n;
531
+ const n = t(D, ...e);
532
+ return void 0 === n ? D : n;
514
533
  },
515
- get: t => (h.has(t) || f("No value found for key"), h.get(t)),
516
- set: (t, e) => (h.set(t, e), R),
534
+ get: t => (x.has(t) || u("No value found for key"), x.get(t)),
535
+ set: (t, e) => (x.set(t, e), D),
517
536
  input: n => {
518
- if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
519
- ct;
520
- const {contentEditable: c, role: i, ariaMultiLine: l, ariaReadOnly: f} = n, p = n.style.whiteSpace;
537
+ if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
538
+ it;
539
+ const {contentEditable: s, role: i, ariaMultiLine: l, ariaReadOnly: u} = n, p = n.style.whiteSpace;
521
540
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
522
- let d = !1, x = null, y = !1, h = !1, _ = !1, b = u, v = null;
523
- const T = N(n), w = ((t, e) => {
541
+ let d = !1, h = null, y = !1, x = !1, _ = !1, b = f, v = null;
542
+ const E = X(n), M = ((t, e) => {
524
543
  let n = null, r = null, o = null;
525
- const s = () => {
544
+ const c = () => {
526
545
  if (null != o) return o;
527
546
  if (r) if ((t => 3 === t.nodeType)(r)) {
528
547
  const t = r.data;
529
548
  if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
530
- } else if (O(r)) {
549
+ } else if (q(r)) {
531
550
  if ("false" === r.contentEditable) return o = 2;
532
551
  {
533
- const t = D.get(r.tagName);
552
+ const t = G.get(r.tagName);
534
553
  if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
535
554
  if (e(r)) return o = 4;
536
555
  }
537
556
  } else if (!(t => 11 === t.nodeType)(r)) return o = 6;
538
557
  return o = 0;
539
- }, c = () => {
540
- const t = s();
558
+ }, s = () => {
559
+ const t = c();
541
560
  if (o = null, 2 === t || 6 === t) {
542
561
  const t = r;
543
562
  if (r = n.nextSibling(), !r) for (;(r = n.nextNode()) && t.contains(r); ) ;
@@ -547,82 +566,82 @@ var st = [], ct = () => {}, it = t => {
547
566
  }, i = () => {
548
567
  const t = r.parentNode;
549
568
  return a(() => {
550
- for (o = 0; c(); ) {
551
- if (s()) return !0;
569
+ for (o = 0; s(); ) {
570
+ if (c()) return !0;
552
571
  if (!t.contains(r)) break;
553
572
  }
554
573
  return !1;
555
574
  });
556
575
  }, l = {
557
576
  t: () => {
558
- for (;c(); ) {
559
- const t = s();
577
+ for (;s(); ) {
578
+ const t = c();
560
579
  if (t && 6 !== t) return t;
561
580
  }
562
581
  },
563
- k: s,
582
+ k: c,
564
583
  i: () => r,
565
584
  l: () => {
566
- const t = s();
585
+ const t = c();
567
586
  return 1 === t ? r.data.length : 2 === t ? 1 : 0;
568
587
  },
569
588
  u: t => {
570
589
  o = null, n.currentNode = r = t;
571
590
  },
572
591
  h: () => {
573
- for (;(o = null) || (r = n.previousSibling()); ) if (4 === s()) return;
592
+ for (;(o = null) || (r = n.previousSibling()); ) if (4 === c()) return;
574
593
  },
575
594
  o: () => {
576
- for (;(o = null) || (r = n.nextSibling()); ) if (4 === s()) return;
595
+ for (;(o = null) || (r = n.nextSibling()); ) if (4 === c()) return;
577
596
  },
578
597
  p: () => {
579
- for (;(o = null) || (r = n.parentNode()); ) if (4 === s()) return;
598
+ for (;(o = null) || (r = n.parentNode()); ) if (4 === c()) return;
580
599
  }
581
- }, a = (e, s) => {
582
- const c = n, i = r, a = o;
600
+ }, a = (e, c) => {
601
+ const s = n, i = r, a = o;
583
602
  try {
584
- return n || (n = t.createTreeWalker(r = s, 5)), e(l);
603
+ return n || (n = t.createTreeWalker(r = c, 5)), e(l);
585
604
  } finally {
586
- n = c, r = i, o = a, n && i && (n.currentNode = i);
605
+ n = s, r = i, o = a, n && i && (n.currentNode = i);
587
606
  }
588
607
  };
589
608
  return a;
590
- })(T, r), B = () => {
609
+ })(E, r), S = () => {
591
610
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
592
611
  };
593
- B();
594
- const I = () => {
595
- h || n.focus({
612
+ S();
613
+ const w = () => {
614
+ x || n.focus({
596
615
  preventScroll: !0
597
616
  });
598
- }, H = () => {
599
- v = null, u[0] === b[0] && u[1] === b[1] || (F(n, w, t, u), b = u);
600
- }, U = () => {
617
+ }, A = () => {
618
+ v = null, f[0] === b[0] && f[1] === b[1] || ($(n, M, t, f), b = f);
619
+ }, O = () => {
601
620
  null != v && clearTimeout(v);
602
- }, q = R.on("change", () => {
603
- h || requestAnimationFrame(I);
604
- }), z = R.on("selectionchange", () => {
605
- u[0] === b[0] && u[1] === b[1] || (U(), v = setTimeout(H, 50));
606
- }), G = R.on("readonly", B), J = t => {
607
- for (const e of g("paste")) {
621
+ }, B = D.on("change", () => {
622
+ x || requestAnimationFrame(w);
623
+ }), I = D.on("selectionchange", () => {
624
+ f[0] === b[0] && f[1] === b[1] || (O(), v = setTimeout(A, 50));
625
+ }), L = D.on("readonly", S), H = t => {
626
+ for (const e of m("paste")) {
608
627
  const n = e(t);
609
628
  if (n) return n;
610
629
  }
611
630
  a("failed to serialize pasted data");
612
- }, j = ((t, e) => {
631
+ }, N = ((t, e) => {
613
632
  let n = !1, r = [];
614
633
  const o = t => {
615
634
  n && r.push(...t);
616
- }, s = new MutationObserver(t => {
635
+ }, c = new MutationObserver(t => {
617
636
  o(t), n || e();
618
- }), c = () => {
619
- o(s.takeRecords());
637
+ }), s = () => {
638
+ o(c.takeRecords());
620
639
  }, i = () => {
621
- c();
640
+ s();
622
641
  const t = r;
623
642
  return r = [], t;
624
643
  };
625
- return s.observe(t, {
644
+ return c.observe(t, {
626
645
  characterData: !0,
627
646
  characterDataOldValue: !0,
628
647
  childList: !0,
@@ -638,79 +657,79 @@ var st = [], ct = () => {}, it = t => {
638
657
  i();
639
658
  },
640
659
  _: t => {
641
- !n && t && c(), n = t;
660
+ !n && t && s(), n = t;
642
661
  },
643
662
  v: i,
644
663
  T: () => {
645
- r.length = 0, s.disconnect();
664
+ r.length = 0, c.disconnect();
646
665
  }
647
666
  };
648
667
  })(n, () => {
649
- U(), F(n, w, t, u);
650
- }), X = () => {
651
- A(b = m(t, ((t, e) => {
652
- const n = L(t), r = C(n, t);
668
+ O(), $(n, M, t, f);
669
+ }), F = () => {
670
+ R(b = g(t, ((t, e) => {
671
+ const n = Z(t), r = K(n, t);
653
672
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
654
- const o = W(t, e, r), s = P(n.anchorNode, n.focusNode);
655
- return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
656
- })(n, w)));
657
- }, Y = () => {
658
- const e = j.v();
659
- j._(!1), e.length && (j.m(e), T.removeEventListener("selectionchange", ot), F(n, w, t, u, !0),
660
- T.addEventListener("selectionchange", ot)), x && (A(x[1]), S(x[0]), x = null), y = !1;
661
- }, Z = t => {
662
- if (!y) for (const e of g("keyboard")) if (e(t)) return t.preventDefault(), void j._(!1);
663
- }, K = () => {
664
- y || Y();
665
- }, Q = e => {
673
+ const o = nt(t, e, r), c = j(n.anchorNode, n.focusNode);
674
+ return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
675
+ })(n, M)));
676
+ }, U = () => {
677
+ const e = N.v();
678
+ N._(!1), e.length && (N.m(e), E.removeEventListener("selectionchange", ot), $(n, M, t, f, !0),
679
+ E.addEventListener("selectionchange", ot)), h && (R(h[1]), T(h[0]), h = null), y = !1;
680
+ }, V = t => {
681
+ if (!y) for (const e of m("keyboard")) if (e(t)) return t.preventDefault(), void N._(!1);
682
+ }, z = () => {
683
+ y || U();
684
+ }, J = e => {
666
685
  e.preventDefault();
667
686
  const r = e.inputType;
668
687
  if (r.startsWith("format")) return;
669
688
  if ("historyUndo" === r || "historyRedo" === r) return;
670
- y ? j._(!0) : X();
689
+ y ? N._(!0) : F();
671
690
  const o = e.getTargetRanges()[0];
672
691
  if (o) {
673
- let s = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
674
- if (null == s) {
692
+ let c = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
693
+ if (null == c) {
675
694
  const t = e.dataTransfer;
676
- t && (s = t.getData("text/plain"));
695
+ t && (c = t.getData("text/plain"));
677
696
  }
678
- x || (x = [ [], u ]);
679
- const c = x[0], i = m(t, W(n, w, o));
680
- M(i) || c.push({
697
+ h || (h = [ [], f ]);
698
+ const s = h[0], i = g(t, nt(n, M, o));
699
+ W(i) || s.push({
681
700
  type: "delete",
682
701
  range: i
683
- }), s && c.push({
702
+ }), c && s.push({
684
703
  type: "insert_text",
685
704
  at: i[0],
686
- text: s
705
+ text: c
687
706
  });
688
707
  }
689
- y || Y();
708
+ y || U();
709
+ }, Y = () => {
710
+ y || F(), y = !0;
711
+ }, Q = () => {
712
+ U();
690
713
  }, tt = () => {
691
- y || X(), y = !0;
692
- }, et = () => {
693
- Y();
694
- }, nt = () => {
695
- h = !0, X();
714
+ x = !0, F();
696
715
  }, rt = () => {
697
- h = !1;
716
+ x = !1;
698
717
  }, ot = () => {
699
- !h || y || _ || X();
718
+ !x || y || _ || F();
719
+ }, ct = t => {
720
+ if (F(), !W(f)) for (const e of m("copy")) e(t);
700
721
  }, st = t => {
701
- if (X(), !M(u)) for (const e of g("copy")) e(t);
702
- }, it = t => {
703
- t.preventDefault(), st(t.clipboardData);
722
+ t.preventDefault(), ct(t.clipboardData);
704
723
  }, lt = t => {
705
- t.preventDefault(), e || (st(t.clipboardData), S({
724
+ t.preventDefault(), e || (ct(t.clipboardData), T({
706
725
  type: "delete",
707
- range: E(u)
726
+ range: C(f)
708
727
  }));
709
728
  }, at = t => {
710
729
  t.preventDefault();
711
- const e = J(t.clipboardData);
730
+ const e = H(t.clipboardData);
712
731
  if (e) {
713
- const t = E(u), n = t[0], r = [ {
732
+ const t = C(f), n = t[0], r = [ {
714
733
  type: "delete",
715
734
  range: t
716
735
  } ];
@@ -722,83 +741,141 @@ var st = [], ct = () => {}, it = t => {
722
741
  type: "insert_node",
723
742
  at: n,
724
743
  fragment: e
725
- }), S(r);
744
+ }), T(r);
726
745
  }
727
- }, ft = e => {
746
+ }, ut = e => {
728
747
  e.preventDefault();
729
- const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}) => {
730
- const o = N(t);
748
+ const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
749
+ const o = X(t);
731
750
  if (o.caretPositionFromPoint) {
732
- const s = o.caretPositionFromPoint(n, r);
733
- if (s) return V(t, e, s.offsetNode, s.offset);
751
+ const c = o.caretPositionFromPoint(n, r);
752
+ if (c) return et(t, e, c.offsetNode, c.offset);
734
753
  } else if (o.caretRangeFromPoint) {
735
- const s = o.caretRangeFromPoint(n, r);
736
- if (s) return V(t, e, s.startContainer, s.startOffset);
754
+ const c = o.caretRangeFromPoint(n, r);
755
+ if (c) return et(t, e, c.startContainer, c.startOffset);
737
756
  }
738
- })(n, w, e);
739
- if (r && s) {
757
+ })(n, M, e);
758
+ if (r && c) {
740
759
  let e;
741
760
  const n = [];
742
761
  _ && n.push({
743
762
  type: "delete",
744
- range: E(u)
763
+ range: C(f)
745
764
  });
746
- const c = J(r);
747
- if (c) {
748
- const r = k(t, s), i = $(r, n);
749
- n.push(o(c) ? {
765
+ const s = H(r);
766
+ if (s) {
767
+ const r = k(t, c), i = P(r, n);
768
+ n.push(o(s) ? {
750
769
  type: "insert_text",
751
770
  at: i,
752
- text: c
771
+ text: s
753
772
  } : {
754
773
  type: "insert_node",
755
774
  at: i,
756
- fragment: c
757
- }), e = [ i, $(r, n) ];
775
+ fragment: s
776
+ }), e = [ i, P(r, n) ];
758
777
  }
759
- S(n), e && A(e);
778
+ T(n), e && R(e);
760
779
  }
761
780
  _ = !1;
762
- }, ut = t => {
763
- _ = !0, st(t.dataTransfer);
781
+ }, ft = t => {
782
+ _ = !0, ct(t.dataTransfer);
764
783
  }, pt = () => {
765
784
  _ = !1;
766
785
  };
767
- T.addEventListener("selectionchange", ot), n.addEventListener("keydown", Z), n.addEventListener("input", K),
768
- n.addEventListener("beforeinput", Q), n.addEventListener("compositionstart", tt),
769
- n.addEventListener("compositionend", et), n.addEventListener("focus", nt), n.addEventListener("blur", rt),
770
- n.addEventListener("copy", it), n.addEventListener("cut", lt), n.addEventListener("paste", at),
771
- n.addEventListener("drop", ft), n.addEventListener("dragstart", ut), n.addEventListener("dragend", pt);
786
+ E.addEventListener("selectionchange", ot), n.addEventListener("keydown", V), n.addEventListener("input", z),
787
+ n.addEventListener("beforeinput", J), n.addEventListener("compositionstart", Y),
788
+ n.addEventListener("compositionend", Q), n.addEventListener("focus", tt), n.addEventListener("blur", rt),
789
+ n.addEventListener("copy", st), n.addEventListener("cut", lt), n.addEventListener("paste", at),
790
+ n.addEventListener("drop", ut), n.addEventListener("dragstart", ft), n.addEventListener("dragend", pt);
772
791
  const dt = [];
773
- return g("mount").forEach(t => {
774
- const e = t(n, w);
792
+ return m("mount").forEach(t => {
793
+ const e = t(n, M);
775
794
  e && dt.push(e);
776
795
  }), () => {
777
- d || (d = !0, q(), z(), G(), n.contentEditable = c, n.role = i, n.ariaMultiLine = l,
778
- n.ariaReadOnly = f, n.style.whiteSpace = p, j.T(), T.removeEventListener("selectionchange", ot),
779
- n.removeEventListener("keydown", Z), n.removeEventListener("input", K), n.removeEventListener("beforeinput", Q),
780
- n.removeEventListener("compositionstart", tt), n.removeEventListener("compositionend", et),
781
- n.removeEventListener("focus", nt), n.removeEventListener("blur", rt), n.removeEventListener("copy", it),
782
- n.removeEventListener("cut", lt), n.removeEventListener("paste", at), n.removeEventListener("drop", ft),
783
- n.removeEventListener("dragstart", ut), n.removeEventListener("dragend", pt), dt.forEach(t => {
796
+ d || (d = !0, B(), I(), L(), n.contentEditable = s, n.role = i, n.ariaMultiLine = l,
797
+ n.ariaReadOnly = u, n.style.whiteSpace = p, N.T(), E.removeEventListener("selectionchange", ot),
798
+ n.removeEventListener("keydown", V), n.removeEventListener("input", z), n.removeEventListener("beforeinput", J),
799
+ n.removeEventListener("compositionstart", Y), n.removeEventListener("compositionend", Q),
800
+ n.removeEventListener("focus", tt), n.removeEventListener("blur", rt), n.removeEventListener("copy", st),
801
+ n.removeEventListener("cut", lt), n.removeEventListener("paste", at), n.removeEventListener("drop", ut),
802
+ n.removeEventListener("dragstart", ft), n.removeEventListener("dragend", pt), dt.forEach(t => {
784
803
  t();
785
804
  }));
786
805
  };
787
806
  }
788
807
  };
789
- return R.exec(ot), R;
808
+ return D.exec(ct), D;
790
809
  };
791
810
 
792
- function at(t, e) {
811
+ function ut(t, e) {
793
812
  const n = e && e.voidToString;
794
813
  t.hook("copy", e => {
795
- e.setData("text/plain", v(t.doc, ...E(t.selection), n));
814
+ e.setData("text/plain", T(t.doc, ...C(t.selection), n));
796
815
  }), t.hook("paste", t => t.getData("text/plain"));
797
816
  }
798
817
 
799
818
  var ft = "application/x-editate-editor";
800
819
 
801
- function ut(t) {
820
+ function pt(t, e) {
821
+ const n = e.isLocked, r = e => n(h(t.doc, e)[0]), o = (e, r) => {
822
+ const [o, c] = e;
823
+ for (const [s, i] of b(t.doc, e)) {
824
+ const t = i + p(s);
825
+ if ((r ? c >= i && o <= t : c > i && o < t) && n(s)) return !0;
826
+ }
827
+ return !1;
828
+ };
829
+ let c = !1;
830
+ t.hook("apply", (e, i) => {
831
+ const a = c;
832
+ switch (c = !1, e.type) {
833
+ case "delete":
834
+ if (o(C(e.range), !0)) return c = !0, s(() => {
835
+ c = !1;
836
+ }), i(null);
837
+ break;
838
+
839
+ case "insert_text":
840
+ case "insert_node":
841
+ if (a || r(e.at)) return i(null);
842
+ break;
843
+
844
+ case "format":
845
+ {
846
+ const t = C(e.range);
847
+ if (W(t) ? r(t[0]) : o(t, !1)) return i(null);
848
+ break;
849
+ }
850
+
851
+ case "patch_node":
852
+ {
853
+ const r = e.path;
854
+ let o = t.doc;
855
+ for (let t = 0; t < r.length; t++) {
856
+ const e = o.children?.[r[t]];
857
+ if (!e) break;
858
+ if (o = e, t < r.length - 1 && l(o) && n(o)) return i(null);
859
+ }
860
+ if (o !== t.doc && l(o) && n(o) && n({
861
+ ...o,
862
+ [e.key]: e.value
863
+ })) return i(null);
864
+ break;
865
+ }
866
+ }
867
+ i(e);
868
+ }), t.set(pt, {
869
+ locked: t => W(t) ? r(t[0]) : o(t, !0)
870
+ });
871
+ }
872
+
873
+ var dt = (t, e) => {
874
+ const n = parseFloat(t);
875
+ return n ? t.endsWith("%") ? n / 100 * e : n : 0;
876
+ }, ht = (t, e, n, r) => [ t + dt(n, e), t + e - dt(r, e) ], yt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, xt = (t, e, n) => Math.max(-e, Math.min(t, n - e));
877
+
878
+ function kt(t) {
802
879
  t.hook("mount", t => {
803
880
  t.ariaMultiLine = null;
804
881
  }), t.hook("apply", (t, e) => {
@@ -809,19 +886,19 @@ function ut(t) {
809
886
  const e = t.fragment;
810
887
  t = {
811
888
  ...t,
812
- fragment: a(e) ? [ Y(...e) ] : e
889
+ fragment: a(e) ? [ D(...e) ] : e
813
890
  };
814
891
  }
815
892
  e(t);
816
893
  });
817
894
  }
818
895
 
819
- exports.Delete = function(t, e = E(t.selection)) {
896
+ exports.Delete = function(t, e = C(t.selection)) {
820
897
  t.apply({
821
898
  type: "delete",
822
899
  range: e
823
900
  });
824
- }, exports.Format = function(t, e, n, r = E(t.selection)) {
901
+ }, exports.Format = function(t, e, n, r = C(t.selection)) {
825
902
  t.apply({
826
903
  type: "format",
827
904
  range: r,
@@ -842,11 +919,13 @@ exports.Delete = function(t, e = E(t.selection)) {
842
919
  at: n,
843
920
  text: e
844
921
  });
845
- }, exports.LeavesInRange = w, exports.Redo = function(t) {
846
- t.get(ot).redo();
922
+ }, exports.LeavesInRange = U, exports.LockedInRange = function(t, e = C(t.selection)) {
923
+ return t.get(pt).locked(e);
924
+ }, exports.Redo = function(t) {
925
+ t.get(ct).redo();
847
926
  }, exports.Redoable = function(t) {
848
- return t.get(ot).redoable();
849
- }, exports.ReplaceDoc = A, exports.ReplaceText = function(t, e, n = E(t.selection)) {
927
+ return t.get(ct).redoable();
928
+ }, exports.ReplaceDoc = V, exports.ReplaceText = function(t, e, n = C(t.selection)) {
850
929
  t.apply({
851
930
  type: "delete",
852
931
  range: n
@@ -856,7 +935,7 @@ exports.Delete = function(t, e = E(t.selection)) {
856
935
  text: e
857
936
  });
858
937
  }, exports.SetBlockAttr = function(t, e, n, r = t.selection[0]) {
859
- const o = x(t.doc, r)[2];
938
+ const o = h(t.doc, r)[2];
860
939
  t.apply({
861
940
  type: "patch_node",
862
941
  path: o,
@@ -872,16 +951,16 @@ exports.Delete = function(t, e = E(t.selection)) {
872
951
  value: n
873
952
  });
874
953
  }, exports.ToggleBlockAttr = function(t, e, n, r, o = t.selection[0]) {
875
- const [s, , c] = x(t.doc, o);
954
+ const [c, , s] = h(t.doc, o);
876
955
  t.apply({
877
956
  type: "patch_node",
878
- path: c,
957
+ path: s,
879
958
  key: e,
880
- value: s[e] === n ? r : n
959
+ value: c[e] === n ? r : n
881
960
  });
882
- }, exports.ToggleFormat = function(t, e, n = E(t.selection)) {
961
+ }, exports.ToggleFormat = function(t, e, n = C(t.selection)) {
883
962
  let r = !1, o = !1;
884
- for (const s of t.exec(w, n)) if (i(s) && (o = !0, !s[e])) {
963
+ for (const c of t.exec(U, n)) if (i(c) && (o = !0, !c[e])) {
885
964
  r = !0;
886
965
  break;
887
966
  }
@@ -892,18 +971,18 @@ exports.Delete = function(t, e = E(t.selection)) {
892
971
  value: r
893
972
  });
894
973
  }, exports.Undo = function(t) {
895
- t.get(ot).undo();
974
+ t.get(ct).undo();
896
975
  }, exports.Undoable = function(t) {
897
- return t.get(ot).undoable();
898
- }, exports.createEditor = lt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
899
- const o = lt({
976
+ return t.get(ct).undoable();
977
+ }, exports.blockLockPlugin = pt, exports.createEditor = at, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
978
+ const o = at({
900
979
  ...r,
901
980
  doc: {
902
- children: q(t)
981
+ children: M(t)
903
982
  }
904
- }).exec(at);
905
- return e && o.exec(ut), o.on("change", () => {
906
- n(v(o.doc));
983
+ }).exec(ut);
984
+ return e && o.exec(kt), o.on("change", () => {
985
+ n(T(o.doc));
907
986
  }), o;
908
987
  }, exports.debugPlugin = function(t) {
909
988
  t.hook("apply", t => {
@@ -926,13 +1005,13 @@ exports.Delete = function(t, e = E(t.selection)) {
926
1005
  }
927
1006
  return null;
928
1007
  });
929
- }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = x, exports.getNodeSize = p,
1008
+ }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = h, exports.getNodeSize = p,
930
1009
  exports.htmlTransferPlugin = function(t, e) {
931
1010
  t.hook("mount", (n, r) => {
932
1011
  const o = t.hook("copy", t => {
933
1012
  const e = document.createElement("div");
934
- e.appendChild(C(L(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
935
- }), s = t.hook("paste", t => {
1013
+ e.appendChild(K(Z(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
1014
+ }), c = t.hook("paste", t => {
936
1015
  const n = t.getData("text/html");
937
1016
  return n ? ((t, e, n) => {
938
1017
  const r = n.text, o = t => {
@@ -942,36 +1021,36 @@ exports.htmlTransferPlugin = function(t, e) {
942
1021
  if (n) return n;
943
1022
  }
944
1023
  };
945
- let s = (new DOMParser).parseFromString(t, "text/html").body, c = !1;
946
- for (const i of [ ...s.childNodes ]) R(i) ? "StartFragment" === i.data ? (c = !0,
947
- s = new DocumentFragment) : "EndFragment" === i.data && (c = !1) : c && s.appendChild(i);
1024
+ let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
1025
+ for (const i of [ ...c.childNodes ]) z(i) ? "StartFragment" === i.data ? (s = !0,
1026
+ c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
948
1027
  return e(({t, i: e}) => {
949
- let n, s = null, c = "", i = !1;
1028
+ let n, c = null, s = "", i = !1;
950
1029
  const l = [], a = () => {
951
- c && (s || (s = []), s.push(r(c)), c = "");
952
- }, f = () => {
953
- a(), !s && i && (s = []), s && l.push({
954
- children: s
955
- }), s = null, i = !1;
1030
+ s && (c || (c = []), c.push(r(s)), s = "");
1031
+ }, u = () => {
1032
+ a(), !c && i && (c = []), c && l.push({
1033
+ children: c
1034
+ }), c = null, i = !1;
956
1035
  };
957
- for (;n = t(); ) if (4 === n) f(); else if (i = !0, 1 === n) c += e().data; else if (2 === n) {
1036
+ for (;n = t(); ) if (4 === n) u(); else if (i = !0, 1 === n) s += e().data; else if (2 === n) {
958
1037
  a();
959
1038
  const t = o(e());
960
- t && s.push(t);
961
- } else 3 === n && f();
962
- return f(), l.length || l.push({
1039
+ t && c.push(t);
1040
+ } else 3 === n && u();
1041
+ return u(), l.length || l.push({
963
1042
  children: []
964
1043
  }), l;
965
- }, s);
1044
+ }, c);
966
1045
  })(n, r, e.serializers) : null;
967
1046
  });
968
1047
  return () => {
969
- o(), s();
1048
+ o(), c();
970
1049
  };
971
1050
  });
972
1051
  }, exports.internalTranferPlugin = function(t) {
973
1052
  t.hook("copy", e => {
974
- e.setData(ft, JSON.stringify(T(t.doc, ...E(t.selection))));
1053
+ e.setData(ft, JSON.stringify(E(t.doc, ...C(t.selection))));
975
1054
  }), t.hook("paste", t => {
976
1055
  try {
977
1056
  return JSON.parse(t.getData(ft));
@@ -979,30 +1058,70 @@ exports.htmlTransferPlugin = function(t, e) {
979
1058
  return null;
980
1059
  }
981
1060
  });
982
- }, exports.iterLeafBlocks = function* t(e, n) {
983
- if (!l(e) || a(e.children)) for (const r of _(e, n)) {
984
- const [e, n] = r;
985
- for (const r of t(e, [ 0, p(e) ])) r[1] += n, yield r;
986
- } else yield [ e, 0 ];
987
- }, exports.iterLeaves = b, exports.keymapPlugin = function(t, e) {
1061
+ }, exports.iterLeafBlocks = b, exports.iterLeaves = v, exports.keymapPlugin = function(t, e) {
988
1062
  n(e).forEach(n => {
989
1063
  const r = e[n];
990
- t.hook("keyboard", rt(n, r));
1064
+ t.hook("keyboard", ot(n, r));
1065
+ });
1066
+ }, exports.mapPosition = H, exports.plainTransferPlugin = ut, exports.scrollToSelectionPlugin = t => {
1067
+ const e = "auto";
1068
+ t.hook("mount", (n, r) => {
1069
+ const o = X(n), c = o.defaultView, s = ((t, e, n) => {
1070
+ const {body: r, documentElement: o} = e;
1071
+ let c = t;
1072
+ for (;c && c !== r && c !== o; ) {
1073
+ const {overflowY: t} = n.getComputedStyle(c);
1074
+ if ("auto" === t || "scroll" === t || "overlay" === t) return c;
1075
+ c = c.parentElement;
1076
+ }
1077
+ return null;
1078
+ })(n, o, c);
1079
+ let i = null;
1080
+ const l = t.on("change", () => {
1081
+ null == i && (i = setTimeout(() => {
1082
+ i = null;
1083
+ const o = Q(n, r, t.doc, t.selection);
1084
+ let l = o.getBoundingClientRect();
1085
+ if (!l.height) {
1086
+ const t = o.startContainer, e = q(t) ? t : t.parentElement;
1087
+ e && (l = e.getBoundingClientRect());
1088
+ }
1089
+ const a = s ? ((t, e, n, r) => {
1090
+ const {scrollLeft: o, scrollTop: c, scrollWidth: s, scrollHeight: i, clientLeft: l, clientTop: a, clientWidth: u, clientHeight: f} = e, p = e.getBoundingClientRect(), d = t.getComputedStyle(e), h = xt(yt(n.top, n.bottom, ht(p.top + a, f, d.scrollPaddingTop, d.scrollPaddingBottom)), c, i - f), y = xt(yt(n.left, n.right, ht(p.left + l, u, d.scrollPaddingLeft, d.scrollPaddingRight)), o, s - u);
1091
+ return (h || y) && e.scrollBy({
1092
+ top: h,
1093
+ left: y,
1094
+ behavior: r
1095
+ }), [ y, h ];
1096
+ })(c, s, l, e) : [ 0, 0 ];
1097
+ ((t, e, [n, r], o) => {
1098
+ const {documentElement: c} = t.document, {clientWidth: s, clientHeight: i} = c, l = t.getComputedStyle(c), a = yt(e.top - r, e.bottom - r, ht(0, i, l.scrollPaddingTop, l.scrollPaddingBottom)), u = yt(e.left - n, e.right - n, ht(0, s, l.scrollPaddingLeft, l.scrollPaddingRight));
1099
+ (a || u) && t.scrollBy({
1100
+ top: a,
1101
+ left: u,
1102
+ behavior: o
1103
+ });
1104
+ })(c, l, a, e);
1105
+ }, 50));
1106
+ });
1107
+ return () => {
1108
+ null != i && clearTimeout(i), l();
1109
+ };
991
1110
  });
992
- }, exports.plainTransferPlugin = at, exports.selectionRectPlugin = function(t, e) {
1111
+ }, exports.selectionRectPlugin = function(t, e) {
993
1112
  t.hook("mount", (n, r) => {
994
- let o = !0, s = !1;
995
- const c = t.on("selectionchange", () => {
996
- s || (s = !0, requestAnimationFrame(() => {
997
- s = !1, o && e(() => {
1113
+ let o = !0, c = !1;
1114
+ const s = t.on("selectionchange", () => {
1115
+ c || (c = !0, requestAnimationFrame(() => {
1116
+ c = !1, o && e(() => {
998
1117
  const e = t.selection;
999
- return H(n, r, t.doc, e).getBoundingClientRect();
1118
+ return Q(n, r, t.doc, e).getBoundingClientRect();
1000
1119
  });
1001
1120
  }));
1002
1121
  });
1003
1122
  return () => {
1004
- o = !1, c();
1123
+ o = !1, s();
1005
1124
  };
1006
1125
  });
1007
- }, exports.singlelinePlugin = ut, exports.sliceText = v;
1126
+ }, exports.singlelinePlugin = kt, exports.sliceText = T;
1008
1127
  //# sourceMappingURL=index.cjs.map