editate 0.6.19 → 0.6.21

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