editate 0.6.3 → 0.6.4

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
@@ -29,10 +29,10 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
29
29
  let r = 0;
30
30
  for (const n of e) r += k(t, 0, n), 0 !== n && r++, t = t.children[n];
31
31
  return r + n;
32
- }, v = (t, e) => {
33
- const n = I(t, e);
32
+ }, w = (t, e) => {
33
+ const n = A(t, e);
34
34
  return [ n.t, n.o ];
35
- }, w = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ v(t, e), v(t, n) ], E = (t, e = 0, n = t.length - 1) => {
35
+ }, v = (t, [e, n]) => [ m(t, e), m(t, n) ], M = (t, [e, n]) => [ w(t, e), w(t, n) ], S = (t, e = 0, n = t.length - 1) => {
36
36
  let r = e + 1;
37
37
  for (;r <= n; ) {
38
38
  const e = t[r - 1], o = t[r];
@@ -45,21 +45,21 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
45
45
  const e = t[r];
46
46
  y(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
47
47
  }
48
- }, S = (t, e = 0, n = t.length - 1) => {
48
+ }, E = (t, e = 0, n = t.length - 1) => {
49
49
  let r = e + 1;
50
50
  for (;r <= n; ) {
51
51
  const e = t[r - 1], o = t[r];
52
- t[r - 1] = O(e, o), t.splice(r, 1), n--;
52
+ t[r - 1] = D(e, o), t.splice(r, 1), n--;
53
53
  }
54
- }, D = (t, e, n) => {
54
+ }, O = (t, e, n) => {
55
55
  if (e.length) {
56
56
  const r = t.length;
57
57
  t.push(...e), r && n(t, r - 1, r);
58
58
  }
59
- }, O = (...t) => ({
59
+ }, D = (...t) => ({
60
60
  ...t[0],
61
- children: t.reduce((t, e) => (D(t, e.children, E), t), [])
62
- }), A = ({children: t}, e) => {
61
+ children: t.reduce((t, e) => (O(t, e.children, S), t), [])
62
+ }), P = ({children: t}, e) => {
63
63
  const n = t.length;
64
64
  for (let r = 0; r < n; r++) {
65
65
  const n = t[r];
@@ -72,10 +72,10 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
72
72
  e -= o;
73
73
  }
74
74
  return null;
75
- }, I = (t, e) => {
75
+ }, A = (t, e) => {
76
76
  const n = [];
77
77
  for (;t; ) {
78
- const r = A(t, e);
78
+ const r = P(t, e);
79
79
  if (!r) break;
80
80
  const o = r.i;
81
81
  if (!x(o)) break;
@@ -86,12 +86,12 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
86
86
  t: n,
87
87
  o: e
88
88
  };
89
- }, P = (t, e) => {
90
- const n = t.children, r = A(t, e);
89
+ }, I = (t, e) => {
90
+ const n = t.children, r = P(t, e);
91
91
  if (r) {
92
92
  const {i: e, o, l: s} = r;
93
93
  if (x(e)) {
94
- const [r, c] = P(e, o), i = n.slice(0, s), a = n.slice(s + 1);
94
+ const [r, c] = I(e, o), i = n.slice(0, s), a = n.slice(s + 1);
95
95
  return i.push(r), a.unshift(c), [ {
96
96
  ...t,
97
97
  children: i
@@ -141,13 +141,13 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
141
141
  })(t, o, o, [ C(t.children[o], e, n, r + 1) ]);
142
142
  }
143
143
  return n;
144
- }, H = (t, e, n, r) => {
145
- const [o, s] = P(t, e), c = e < n ? P(t, n)[1] : s, i = o.children.slice();
146
- return D(i, r, S), D(i, c.children, S), {
144
+ }, R = (t, e, n, r) => {
145
+ const [o, s] = I(t, e), c = e < n ? I(t, n)[1] : s, i = o.children.slice();
146
+ return O(i, r, E), O(i, c.children, E), {
147
147
  ...t,
148
148
  children: i
149
149
  };
150
- }, R = (t, e, n) => e >= n ? [] : P(P(t, n)[0], e)[1].children, T = (t, e) => e >= 0 && e <= b(t), B = (t, e) => e.reduce((t, e) => L(t, e), t), L = (t, e) => {
150
+ }, T = (t, e, n) => e >= n ? [] : I(I(t, n)[0], e)[1].children, L = (t, e) => e >= 0 && e <= b(t), H = (t, e) => e.reduce((t, e) => B(t, e), t), B = (t, e) => {
151
151
  switch (e.type) {
152
152
  case f:
153
153
  {
@@ -173,7 +173,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
173
173
  }
174
174
  }
175
175
  return t;
176
- }, N = ([t, e], n) => [ L(t, n), L(e, n) ];
176
+ }, N = ([t, e], n) => [ B(t, n), B(e, n) ];
177
177
 
178
178
  function V(t, e) {
179
179
  t.apply({
@@ -186,109 +186,112 @@ function V(t, e) {
186
186
  });
187
187
  }
188
188
 
189
- let F = null, W = null, q = null, J = null, U = null;
189
+ let F = null, U = null, W = null, q = null, G = null;
190
190
 
191
- const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = () => {
192
- const t = X();
193
- return 1 === t ? W.data.length : 2 === t ? 1 : 0;
191
+ const J = t => 1 === t.nodeType, Y = t => 8 === t.nodeType, Z = () => U, j = () => {
192
+ const t = z();
193
+ return 1 === t ? U.data.length : 2 === t ? 1 : 0;
194
+ }, z = () => {
195
+ if (null != W) return W;
196
+ if (U) if ((t => 3 === t.nodeType)(U)) {
197
+ const t = U.data;
198
+ if (t) return W = "\n" === t ? et() ? 3 : 5 : 1;
199
+ } else if (J(U)) {
200
+ if ("BR" === U.tagName) return W = et() ? 3 : 5;
201
+ if (tt(U)) return W = 6;
202
+ if (q.u(U)) return W = 2;
203
+ if (q.p(U)) return W = 4;
204
+ }
205
+ return W = 0;
194
206
  }, X = () => {
195
- if (null != q) return q;
196
- if (W) if ((t => 3 === t.nodeType)(W)) {
197
- const t = W.data;
198
- if (t) return q = "\n" === t ? tt() ? 3 : 5 : 1;
199
- } else if (G(W)) {
200
- if ("BR" === W.tagName) return q = tt() ? 3 : 5;
201
- if ($(W)) return q = 6;
202
- if (J.u(W)) return q = 2;
203
- if (J.p(W)) return q = 4;
207
+ const t = z();
208
+ if (W = null, 2 === t || 6 === t) {
209
+ const t = U;
210
+ if (U = F.nextSibling(), !U) for (;(U = F.nextNode()) && t.contains(U); ) ;
211
+ return U;
204
212
  }
205
- return q = 0;
206
- }, Y = () => (q = null, W = F.nextNode()), K = () => {
207
- for (;(q = null) || (W = F.nextSibling()); ) if (4 === X()) return;
213
+ return U = F.nextNode();
214
+ }, K = () => {
215
+ for (;(W = null) || (U = F.nextSibling()); ) if (4 === z()) return;
208
216
  }, Q = () => {
209
- for (;(q = null) || (W = F.parentNode()); ) if (4 === X()) return;
210
- }, $ = t => "TEMPLATE" === t.tagName, tt = () => {
211
- const t = W.parentNode;
212
- return U(() => {
213
- for (;Y(); ) {
214
- if (X()) return !0;
215
- if (!t.contains(W)) break;
217
+ for (;(W = null) || (U = F.parentNode()); ) if (4 === z()) return;
218
+ }, $ = new Set([ "TEMPLATE", "STYLE", "SCRIPT", "COLGROUP" ]), tt = t => $.has(t.tagName), et = () => {
219
+ const t = U.parentNode;
220
+ return G(() => {
221
+ for (W = 0; X(); ) {
222
+ if (z()) return !0;
223
+ if (!t.contains(U)) break;
216
224
  }
217
225
  return !1;
218
226
  });
219
- }, et = () => {
220
- for (;;) {
221
- if (2 === X()) {
222
- const t = W;
223
- for (;Y() && t.contains(W); ) ;
224
- } else Y();
225
- if (!W) break;
226
- const t = X();
227
+ }, nt = () => {
228
+ for (;X(); ) {
229
+ const t = z();
227
230
  if (t && 6 !== t) return t;
228
231
  }
229
- }, nt = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), rt = t => nt.has(t.tagName), ot = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), st = t => "false" === t.contentEditable || ot.has(t.tagName), ct = (t, e) => t.compareDocumentPosition(e), it = t => t.ownerDocument, at = t => it(t).getSelection(), lt = (t, e) => {
232
+ }, rt = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), ot = t => rt.has(t.tagName), st = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), ct = t => "false" === t.contentEditable || st.has(t.tagName), it = (t, e) => t.compareDocumentPosition(e), at = t => t.ownerDocument, lt = t => at(t).getSelection(), ft = (t, e) => {
230
233
  if (t.rangeCount) {
231
234
  const n = t.getRangeAt(0);
232
235
  if (e.contains(n.commonAncestorContainer)) return n;
233
236
  }
234
- }, ft = (t, e, n, r) => {
235
- const o = at(t);
236
- (n || lt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
237
+ }, ut = (t, e, n, r) => {
238
+ const o = lt(t);
239
+ (n || ft(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
237
240
  o.extend(e.startContainer, e.startOffset)));
238
- }, ut = (t, e, [n, r], o, s, c) => {
241
+ }, dt = (t, e, [n, r], o, s, c) => {
239
242
  const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
240
243
  if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
241
244
  const n = t.createRange();
242
- return n.setStart(e, 0), n.setEnd(e, 0), ft(e, n, c);
245
+ return n.setStart(e, 0), n.setEnd(e, 0), ut(e, n, c);
243
246
  }
244
- const u = dt(e, l, s);
247
+ const u = pt(e, l, s);
245
248
  if (!u) return;
246
- const d = i ? u : dt(e, f, s);
249
+ const d = i ? u : pt(e, f, s);
247
250
  if (!d) return;
248
251
  const p = t.createRange(), [h, y] = u, [x, g] = d;
249
- G(h) ? y < 1 ? p.setStartBefore(h) : p.setStartAfter(h) : p.setStart(h, y), G(x) ? g < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, g),
250
- ft(e, p, c, a);
251
- }, dt = (t, [e, n], r) => r(() => {
252
+ J(h) ? y < 1 ? p.setStartBefore(h) : p.setStartAfter(h) : p.setStart(h, y), J(x) ? g < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, g),
253
+ ut(e, p, c, a);
254
+ }, pt = (t, [e, n], r) => r(() => {
252
255
  let t, r = 0;
253
- for (;t = et(); ) if (4 === t) {
256
+ for (;t = nt(); ) if (4 === t) {
254
257
  if (r < e.length) for (let t = e[r++]; t > 0; t--) K();
255
258
  } else {
256
- const t = z();
257
- if (n <= t) return [ j(), n ];
259
+ const t = j();
260
+ if (n <= t) return [ Z(), n ];
258
261
  n -= t;
259
262
  }
260
- }, t), pt = (t, e, r, o) => {
263
+ }, t), ht = (t, e, r, o) => {
261
264
  let s = !0;
262
265
  if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
263
- if (G(e) && e.hasChildNodes()) {
266
+ if (J(e) && e.hasChildNodes()) {
264
267
  const t = n(r, e.childNodes.length - 1);
265
268
  e = e.childNodes[t], s = t === r, r = 0;
266
269
  }
267
270
  return o(() => {
268
- 4 !== X() && Q();
271
+ 4 !== z() && Q();
269
272
  const n = o(() => {
270
273
  const e = [];
271
274
  let n;
272
- for (;(n = j()) && n !== t; ) e.unshift(n), Q();
275
+ for (;(n = Z()) && n !== t; ) e.unshift(n), Q();
273
276
  if (!e.length) return [ 0 ];
274
277
  let r = 0, o = e[e.length - 1];
275
- for (;o = o.previousElementSibling; ) $(o) || r++;
278
+ for (;o = o.previousElementSibling; ) tt(o) || r++;
276
279
  return [ r ];
277
280
  });
278
281
  let c = 0;
279
- for (;et(); ) {
280
- const t = ct(e, j());
282
+ for (;nt(); ) {
283
+ const t = it(e, Z());
281
284
  if (0 === t || 16 & t) {
282
285
  if (s) break;
283
286
  } else if (4 & t) break;
284
- c += z();
287
+ c += j();
285
288
  }
286
289
  return [ n, c + r ];
287
290
  }, t, e);
288
- }, ht = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
289
- const c = pt(t, r, n, e);
290
- return [ c, r === s && n === o ? c : pt(t, s, o, e) ];
291
- }, yt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), xt = (t, e) => {
291
+ }, yt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
292
+ const c = ht(t, r, n, e);
293
+ return [ c, r === s && n === o ? c : ht(t, s, o, e) ];
294
+ }, xt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), gt = (t, e) => {
292
295
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), s = "Space" === o ? " " : o.toLowerCase();
293
296
  let c = !1, i = !1, a = !1, l = !1;
294
297
  return r.forEach(t => {
@@ -302,7 +305,7 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
302
305
  break;
303
306
 
304
307
  case "Mod":
305
- yt ? a = !0 : i = !0;
308
+ xt ? a = !0 : i = !0;
306
309
  break;
307
310
 
308
311
  case "Alt":
@@ -318,7 +321,7 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
318
321
  };
319
322
  };
320
323
 
321
- function gt(t) {
324
+ function _t(t) {
322
325
  let e = 0, n = 0, r = !1;
323
326
  const s = Date.now, c = [ [ t.doc, t.selection, [] ] ], i = () => c[e], a = () => e > 0, l = () => e < c.length - 1, f = () => {
324
327
  if (a()) {
@@ -331,7 +334,7 @@ function gt(t) {
331
334
  if (l()) {
332
335
  e++;
333
336
  const [n, s, c] = i(), a = t.doc;
334
- r = !0, t.exec(V, n.children), r = !1, o(a, t.doc) || (t.selection = [ B(s[0], c), B(s[1], c) ]);
337
+ r = !0, t.exec(V, n.children), r = !1, o(a, t.doc) || (t.selection = [ H(s[0], c), H(s[1], c) ]);
335
338
  }
336
339
  };
337
340
  t.hook("apply", (i, a) => {
@@ -348,8 +351,8 @@ function gt(t) {
348
351
  }
349
352
  n = t, c[e][0] = u, c[e][2].push(i), c.splice(e + 1), e > 500 && (e--, c.shift());
350
353
  }
351
- }), t.hook("keyboard", xt("Mod+Z", f)), t.hook("keyboard", xt("Shift+Mod+Z", u)),
352
- t.set(gt, {
354
+ }), t.hook("keyboard", gt("Mod+Z", f)), t.hook("keyboard", gt("Shift+Mod+Z", u)),
355
+ t.set(_t, {
353
356
  undo: f,
354
357
  redo: u,
355
358
  undoable: a,
@@ -357,9 +360,9 @@ function gt(t) {
357
360
  });
358
361
  }
359
362
 
360
- const _t = [], kt = () => {}, bt = t => {
363
+ const kt = [], bt = () => {}, mt = t => {
361
364
  throw Error(t);
362
- }, mt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = rt, onWarn: g = console.warn, onError: _ = bt}) => {
365
+ }, wt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = ot, onWarn: g = console.warn, onError: _ = mt}) => {
363
366
  let k = [ 0, 0 ];
364
367
  const b = t => {
365
368
  if (!a) return g("An unsafe operation was detected. We recommend using schema option."),
@@ -372,18 +375,18 @@ const _t = [], kt = () => {}, bt = t => {
372
375
  return !1;
373
376
  };
374
377
  a && !b(n) && _("Invalid document");
375
- const v = new Map, E = new WeakMap, S = t => v.get(t) || _t, D = new Map, O = t => {
376
- const e = D.get(t);
377
- e && !e[1] && (e[1] = !0, i(() => {
378
- e[1] = !1, e[0].forEach(t => {
378
+ const w = new Map, S = new WeakMap, E = t => w.get(t) || kt, O = new Map, D = [], I = t => {
379
+ const e = O.get(t);
380
+ e && (D.length || i(() => {
381
+ D.forEach(t => {
379
382
  t();
380
- });
381
- }));
382
- }, P = t => {
383
- if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
384
- return G;
385
- }, L = t => {
386
- const e = n, r = S("apply"), s = r.length;
383
+ }), D.splice(0);
384
+ }), D.push(...e));
385
+ }, B = t => {
386
+ if (!r) if (Array.isArray(t)) for (const e of t) V(e); else V(t);
387
+ return Y;
388
+ }, V = t => {
389
+ const e = n, r = E("apply"), s = r.length;
387
390
  let c = 0;
388
391
  const i = () => {
389
392
  if (c < s) {
@@ -397,21 +400,21 @@ const _t = [], kt = () => {}, bt = t => {
397
400
  case f:
398
401
  {
399
402
  const [r, o] = n.range;
400
- T(t, r) && T(t, o) && r < o && (t = H(t, r, o, []), e = N(e, n));
403
+ L(t, r) && L(t, o) && r < o && (t = R(t, r, o, []), e = N(e, n));
401
404
  break;
402
405
  }
403
406
 
404
407
  case u:
405
408
  {
406
409
  const {at: r, text: o} = n;
407
- if (T(t, r) && o) {
408
- const {i: s, o: c} = I(t, r), i = A(s, c - 1);
410
+ if (L(t, r) && o) {
411
+ const {i: s, o: c} = A(t, r), i = P(s, c - 1);
409
412
  let a;
410
413
  if (i) {
411
414
  const t = i.i;
412
415
  y(t) && (a = t);
413
416
  }
414
- t = H(t, r, r, l(o, a, s)), e = N(e, n);
417
+ t = R(t, r, r, l(o, a, s)), e = N(e, n);
415
418
  }
416
419
  break;
417
420
  }
@@ -419,15 +422,15 @@ const _t = [], kt = () => {}, bt = t => {
419
422
  case d:
420
423
  {
421
424
  const {at: r, fragment: o} = n;
422
- T(t, r) && o.length && (t = H(t, r, r, o), e = N(e, n));
425
+ L(t, r) && o.length && (t = R(t, r, r, o), e = N(e, n));
423
426
  break;
424
427
  }
425
428
 
426
429
  case p:
427
430
  {
428
431
  const {range: [e, r], key: o, value: s} = n;
429
- if (T(t, e) && T(t, r) && e <= r) if (e === r) {
430
- const {i: {children: n}, t: r} = I(t, e);
432
+ if (L(t, e) && L(t, r) && e <= r) if (e === r) {
433
+ const {i: {children: n}, t: r} = A(t, e);
431
434
  if (1 === n.length) {
432
435
  const e = n[0];
433
436
  y(e) && !e.text && (t = C(t, [ ...r, 0 ], {
@@ -435,7 +438,7 @@ const _t = [], kt = () => {}, bt = t => {
435
438
  [o]: s
436
439
  }));
437
440
  }
438
- } else t = H(t, e, r, R(t, e, r).map(t => ({
441
+ } else t = R(t, e, r, T(t, e, r).map(t => ({
439
442
  ...t,
440
443
  children: t.children.map(t => y(t) ? {
441
444
  ...t,
@@ -468,11 +471,11 @@ const _t = [], kt = () => {}, bt = t => {
468
471
  }, a = e => {
469
472
  e && (t = e), c++, i();
470
473
  };
471
- i(), o(e, n) || O("change");
472
- }, V = t => {
473
- !((t, [e, n]) => T(t, e) && T(t, n))(n, t) || k[0] === t[0] && k[1] === t[1] || (k = t,
474
- O("selectionchange"));
475
- }, G = {
474
+ i(), o(e, n) || I("change");
475
+ }, J = t => {
476
+ !((t, [e, n]) => L(t, e) && L(t, n))(n, t) || k[0] === t[0] && k[1] === t[1] || (k = t,
477
+ I("selectionchange"));
478
+ }, Y = {
476
479
  get doc() {
477
480
  return n;
478
481
  },
@@ -480,74 +483,72 @@ const _t = [], kt = () => {}, bt = t => {
480
483
  return k;
481
484
  },
482
485
  set selection(t) {
483
- V(t);
486
+ J(t);
484
487
  },
485
488
  get readonly() {
486
489
  return r;
487
490
  },
488
491
  set readonly(t) {
489
- r = t, O("readonly");
492
+ r = t, I("readonly");
490
493
  },
491
- apply: P,
494
+ apply: B,
492
495
  on: (t, e) => {
493
- let n = D.get(t);
494
- n || D.set(t, n = [ new Set, !1 ]);
495
- const r = n[0];
496
- return r.add(e), () => {
497
- r.delete(e);
496
+ let n = O.get(t);
497
+ return n || O.set(t, n = new Set), n.add(e), () => {
498
+ n.delete(e);
498
499
  };
499
500
  },
500
501
  hook: (t, e) => {
501
- let n = v.get(t);
502
- return n || v.set(t, n = []), n.push(e), () => {
502
+ let n = w.get(t);
503
+ return n || w.set(t, n = []), n.push(e), () => {
503
504
  const t = n.indexOf(e);
504
505
  -1 !== t && n.splice(t, 1);
505
506
  };
506
507
  },
507
508
  exec: (t, ...e) => {
508
- const n = t(G, ...e);
509
- return void 0 === n ? G : n;
509
+ const n = t(Y, ...e);
510
+ return void 0 === n ? Y : n;
510
511
  },
511
- get: t => (E.has(t) || _("No value found for key"), E.get(t)),
512
- set: (t, e) => (E.set(t, e), G),
512
+ get: t => (S.has(t) || _("No value found for key"), S.get(t)),
513
+ set: (t, e) => (S.set(t, e), Y),
513
514
  input: o => {
514
515
  if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return g("beforeinput event is not supported."),
515
- kt;
516
+ bt;
516
517
  const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
517
518
  o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
518
519
  let d = !1, p = null, h = !1, y = !1, _ = !1;
519
- const b = it(o), v = (t => {
520
+ const b = at(o), w = (t => {
520
521
  const e = (n, r, o) => {
521
- const s = J, c = U, i = F, a = W, l = q;
522
+ const s = q, c = G, i = F, a = U, l = W;
522
523
  try {
523
- return F || (J = t, U = e, F = J.h.createTreeWalker(r, 5)), o && (F.currentNode = W = o),
524
+ return F || (q = t, G = e, F = q.h.createTreeWalker(r, 5)), o && (F.currentNode = U = o),
524
525
  n();
525
526
  } finally {
526
- J = s, U = c, F = i, W = a, q = l, F && a && (F.currentNode = a);
527
+ q = s, G = c, F = i, U = a, W = l, F && a && (F.currentNode = a);
527
528
  }
528
529
  };
529
530
  return e;
530
531
  })({
531
532
  h: b,
532
533
  p: x,
533
- u: st
534
- }), E = () => {
534
+ u: ct
535
+ }), S = () => {
535
536
  o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
536
537
  };
537
- E();
538
- const D = G.on("change", () => {
538
+ S();
539
+ const O = Y.on("change", () => {
539
540
  y || requestAnimationFrame(() => {
540
541
  y || o.focus({
541
542
  preventScroll: !0
542
543
  });
543
544
  });
544
- }), O = G.on("readonly", E), A = t => {
545
- for (const e of S("paste")) {
546
- const n = e(t, v);
545
+ }), D = Y.on("readonly", S), P = t => {
546
+ for (const e of E("paste")) {
547
+ const n = e(t, w);
547
548
  if (n) return n;
548
549
  }
549
550
  g("failed to serialize pasted data");
550
- }, I = ((t, e) => {
551
+ }, A = ((t, e) => {
551
552
  let n = !1;
552
553
  const r = [], o = t => {
553
554
  n && r.push(...t);
@@ -580,31 +581,31 @@ const _t = [], kt = () => {}, bt = t => {
580
581
  }
581
582
  };
582
583
  })(o, () => {
583
- ut(b, o, M(n, k), k[0] - k[1], v);
584
- }), C = () => {
585
- V(w(n, ((t, e) => {
586
- const n = at(t), r = lt(n, t);
584
+ dt(b, o, M(n, k), k[0] - k[1], w);
585
+ }), I = () => {
586
+ J(v(n, ((t, e) => {
587
+ const n = lt(t), r = ft(n, t);
587
588
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
588
- const o = ht(t, e, r), s = ct(n.anchorNode, n.focusNode);
589
+ const o = yt(t, e, r), s = it(n.anchorNode, n.focusNode);
589
590
  return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
590
- })(o, v)));
591
- }, H = () => {
592
- const t = I.m();
593
- I.k(!1), t.length && (I._(t), b.removeEventListener("selectionchange", X), ut(b, o, M(n, k), k[0] - k[1], v, !0),
594
- b.addEventListener("selectionchange", X)), p && (V(p[1]), P(p[0]), p = null), h = !1;
591
+ })(o, w)));
592
+ }, C = () => {
593
+ const t = A.m();
594
+ A.k(!1), t.length && (A._(t), b.removeEventListener("selectionchange", z), dt(b, o, M(n, k), k[0] - k[1], w, !0),
595
+ b.addEventListener("selectionchange", z)), p && (J(p[1]), B(p[0]), p = null), h = !1;
595
596
  }, R = t => {
596
- if (!h) for (const e of S("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
597
+ if (!h) for (const e of E("keyboard")) if (e(t)) return t.preventDefault(), void A.k(!1);
597
598
  }, T = () => {
598
- h || H();
599
+ h || C();
599
600
  }, L = t => {
600
601
  t.preventDefault();
601
602
  const r = t.inputType;
602
603
  if (r.startsWith("format")) return;
603
604
  if ("historyUndo" === r || "historyRedo" === r) return;
604
- h ? I.k(!0) : C();
605
+ h ? A.k(!0) : I();
605
606
  const s = t.getTargetRanges()[0];
606
607
  if (s) {
607
- const c = w(n, ht(o, v, s));
608
+ const c = v(n, yt(o, w, s));
608
609
  let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
609
610
  if (null == a) {
610
611
  const e = t.dataTransfer;
@@ -619,29 +620,29 @@ const _t = [], kt = () => {}, bt = t => {
619
620
  text: a
620
621
  });
621
622
  }
622
- h || H();
623
+ h || C();
623
624
  }, N = () => {
624
- h || C(), h = !0;
625
+ h || I(), h = !0;
626
+ }, V = () => {
627
+ C();
625
628
  }, Z = () => {
626
- H();
629
+ y = !0, I();
627
630
  }, j = () => {
628
- y = !0, C();
629
- }, z = () => {
630
631
  y = !1;
631
- }, X = () => {
632
- !y || h || _ || C();
633
- }, Y = t => {
634
- if (C(), !e(k)) for (const e of S("copy")) e(t);
632
+ }, z = () => {
633
+ !y || h || _ || I();
634
+ }, X = t => {
635
+ if (I(), !e(k)) for (const e of E("copy")) e(t);
635
636
  }, K = t => {
636
- t.preventDefault(), Y(t.clipboardData);
637
+ t.preventDefault(), X(t.clipboardData);
637
638
  }, Q = e => {
638
- e.preventDefault(), r || (Y(e.clipboardData), P({
639
+ e.preventDefault(), r || (X(e.clipboardData), B({
639
640
  type: "delete",
640
641
  range: t(k)
641
642
  }));
642
643
  }, $ = e => {
643
644
  e.preventDefault();
644
- const n = A(e.clipboardData);
645
+ const n = P(e.clipboardData);
645
646
  if (n) {
646
647
  const e = t(k), r = e[0], o = [ {
647
648
  type: "delete",
@@ -655,19 +656,19 @@ const _t = [], kt = () => {}, bt = t => {
655
656
  type: "insert_node",
656
657
  at: r,
657
658
  fragment: n
658
- }), P(o);
659
+ }), B(o);
659
660
  }
660
661
  }, tt = e => {
661
662
  e.preventDefault();
662
663
  const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}, o) => {
663
664
  if (t.caretPositionFromPoint) {
664
665
  const s = t.caretPositionFromPoint(n, r);
665
- if (s) return pt(e, s.offsetNode, s.offset, o);
666
+ if (s) return ht(e, s.offsetNode, s.offset, o);
666
667
  } else if (t.caretRangeFromPoint) {
667
668
  const s = t.caretRangeFromPoint(n, r);
668
- if (s) return pt(e, s.startContainer, s.startOffset, o);
669
+ if (s) return ht(e, s.startContainer, s.startOffset, o);
669
670
  }
670
- })(b, o, e, v);
671
+ })(b, o, e, w);
671
672
  if (r && c) {
672
673
  let e;
673
674
  const o = [];
@@ -675,9 +676,9 @@ const _t = [], kt = () => {}, bt = t => {
675
676
  type: "delete",
676
677
  range: t(k)
677
678
  });
678
- const i = A(r);
679
+ const i = P(r);
679
680
  if (i) {
680
- const t = m(n, c), r = B(t, o);
681
+ const t = m(n, c), r = H(t, o);
681
682
  o.push(s(i) ? {
682
683
  type: "insert_text",
683
684
  at: r,
@@ -686,30 +687,30 @@ const _t = [], kt = () => {}, bt = t => {
686
687
  type: "insert_node",
687
688
  at: r,
688
689
  fragment: i
689
- }), e = [ r, B(t, o) ];
690
+ }), e = [ r, H(t, o) ];
690
691
  }
691
- P(o), e && V(e);
692
+ B(o), e && J(e);
692
693
  }
693
694
  }, et = t => {
694
- _ = !0, Y(t.dataTransfer);
695
+ _ = !0, X(t.dataTransfer);
695
696
  }, nt = () => {
696
697
  _ = !1;
697
698
  };
698
- b.addEventListener("selectionchange", X), o.addEventListener("keydown", R), o.addEventListener("input", T),
699
+ b.addEventListener("selectionchange", z), o.addEventListener("keydown", R), o.addEventListener("input", T),
699
700
  o.addEventListener("beforeinput", L), o.addEventListener("compositionstart", N),
700
- o.addEventListener("compositionend", Z), o.addEventListener("focus", j), o.addEventListener("blur", z),
701
+ o.addEventListener("compositionend", V), o.addEventListener("focus", Z), o.addEventListener("blur", j),
701
702
  o.addEventListener("copy", K), o.addEventListener("cut", Q), o.addEventListener("paste", $),
702
703
  o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
703
704
  const rt = [];
704
- return S("mount").forEach(t => {
705
+ return E("mount").forEach(t => {
705
706
  const e = t(o);
706
707
  e && rt.push(e);
707
708
  }), () => {
708
- d || (d = !0, D(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
709
- o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), b.removeEventListener("selectionchange", X),
709
+ d || (d = !0, O(), D(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
710
+ o.ariaReadOnly = f, o.style.whiteSpace = u, A.v(), b.removeEventListener("selectionchange", z),
710
711
  o.removeEventListener("keydown", R), o.removeEventListener("input", T), o.removeEventListener("beforeinput", L),
711
- o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", Z),
712
- o.removeEventListener("focus", j), o.removeEventListener("blur", z), o.removeEventListener("copy", K),
712
+ o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", V),
713
+ o.removeEventListener("focus", Z), o.removeEventListener("blur", j), o.removeEventListener("copy", K),
713
714
  o.removeEventListener("cut", Q), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
714
715
  o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
715
716
  t();
@@ -717,21 +718,21 @@ const _t = [], kt = () => {}, bt = t => {
717
718
  };
718
719
  }
719
720
  };
720
- return G.exec(gt), G;
721
+ return Y.exec(_t), Y;
721
722
  };
722
723
 
723
724
  function vt(e, n) {
724
725
  const r = n && n.serializer;
725
726
  e.hook("copy", n => {
726
727
  n.setData("text/plain", a({
727
- children: R(e.doc, ...t(e.selection))
728
+ children: T(e.doc, ...t(e.selection))
728
729
  }, r));
729
730
  }), e.hook("paste", t => t.getData("text/plain"));
730
731
  }
731
732
 
732
- const wt = "application/x-editate-editor";
733
+ const Mt = "application/x-editate-editor";
733
734
 
734
- function Mt(t) {
735
+ function St(t) {
735
736
  t.hook("mount", t => {
736
737
  t.ariaMultiLine = null;
737
738
  }), t.hook("apply", (t, e) => {
@@ -740,7 +741,7 @@ function Mt(t) {
740
741
  text: t.text.replaceAll("\n", "")
741
742
  } : "insert_node" === t.type && (t = {
742
743
  ...t,
743
- fragment: [ O(...t.fragment) ]
744
+ fragment: [ D(...t.fragment) ]
744
745
  }), e(t);
745
746
  });
746
747
  }
@@ -772,9 +773,9 @@ exports.Delete = function(e, n = t(e.selection)) {
772
773
  text: e
773
774
  });
774
775
  }, exports.Redo = function(t) {
775
- t.get(gt).redo();
776
+ t.get(_t).redo();
776
777
  }, exports.Redoable = function(t) {
777
- return t.get(gt).redoable();
778
+ return t.get(_t).redoable();
778
779
  }, exports.ReplaceDoc = V, exports.ReplaceText = function(e, n) {
779
780
  const r = t(e.selection);
780
781
  e.apply({
@@ -786,7 +787,7 @@ exports.Delete = function(e, n = t(e.selection)) {
786
787
  text: n
787
788
  });
788
789
  }, exports.SetBlockAttr = function(t, e, n, r = t.selection[0]) {
789
- const {t: o} = I(t.doc, r);
790
+ const {t: o} = A(t.doc, r);
790
791
  t.apply({
791
792
  type: "set_node_attr",
792
793
  path: o,
@@ -794,7 +795,7 @@ exports.Delete = function(e, n = t(e.selection)) {
794
795
  value: n
795
796
  });
796
797
  }, exports.ToggleBlockAttr = function(t, e, n, r, o = t.selection[0]) {
797
- const {i: s, t: c} = I(t.doc, o);
798
+ const {i: s, t: c} = A(t.doc, o);
798
799
  t.apply({
799
800
  type: "set_node_attr",
800
801
  path: c,
@@ -805,12 +806,12 @@ exports.Delete = function(e, n = t(e.selection)) {
805
806
  let s;
806
807
  if (e(o)) {
807
808
  const t = ((t, e) => {
808
- const n = I(t, e);
809
- return A(n.i, n.o);
809
+ const n = A(t, e);
810
+ return P(n.i, n.o);
810
811
  })(n.doc, o[0]);
811
812
  if (!t) return;
812
813
  s = [ t.i ];
813
- } else s = R(n.doc, ...o).flatMap(t => t.children);
814
+ } else s = T(n.doc, ...o).flatMap(t => t.children);
814
815
  const c = s.filter(y);
815
816
  c.length && n.apply({
816
817
  type: "set_attr",
@@ -819,11 +820,11 @@ exports.Delete = function(e, n = t(e.selection)) {
819
820
  value: !!c.some(t => !t[r])
820
821
  });
821
822
  }, exports.Undo = function(t) {
822
- t.get(gt).undo();
823
+ t.get(_t).undo();
823
824
  }, exports.Undoable = function(t) {
824
- return t.get(gt).undoable();
825
- }, exports.createEditor = mt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
826
- const o = mt({
825
+ return t.get(_t).undoable();
826
+ }, exports.createEditor = wt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
827
+ const o = wt({
827
828
  ...r,
828
829
  doc: {
829
830
  children: l(t)
@@ -831,7 +832,7 @@ exports.Delete = function(e, n = t(e.selection)) {
831
832
  }).exec(vt);
832
833
  return o.on("change", () => {
833
834
  n(a(o.doc));
834
- }), e && o.exec(Mt), o;
835
+ }), e && o.exec(St), o;
835
836
  }, exports.debugPlugin = function(t) {
836
837
  t.hook("apply", t => {
837
838
  console.log("apply", t);
@@ -860,12 +861,12 @@ exports.Delete = function(e, n = t(e.selection)) {
860
861
  })), t.hook("copy", t => {
861
862
  if (!n) return;
862
863
  const e = document.createElement("div");
863
- e.appendChild(lt(at(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
864
+ e.appendChild(ft(lt(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
864
865
  }), t.hook("paste", ((t, e = []) => (n, r) => {
865
866
  const o = n.getData("text/html");
866
867
  if (o) {
867
868
  let n = (new DOMParser).parseFromString(o, "text/html").body, s = !1;
868
- for (const t of [ ...n.childNodes ]) Z(t) ? "StartFragment" === t.data ? (s = !0,
869
+ for (const t of [ ...n.childNodes ]) Y(t) ? "StartFragment" === t.data ? (s = !0,
869
870
  n = new DocumentFragment) : "EndFragment" === t.data && (s = !1) : s && n.appendChild(t);
870
871
  return ((t, e, n, r) => e(() => {
871
872
  let t, e = null, o = "", s = !1;
@@ -876,9 +877,9 @@ exports.Delete = function(e, n = t(e.selection)) {
876
877
  children: e
877
878
  }), e = null, s = !1;
878
879
  };
879
- for (;t = et(); ) if (4 === t) a(); else if (s = !0, 1 === t) o += j().data; else if (2 === t) {
880
+ for (;t = nt(); ) if (4 === t) a(); else if (s = !0, 1 === t) o += Z().data; else if (2 === t) {
880
881
  i();
881
- const t = r(j());
882
+ const t = r(Z());
882
883
  t && e.push(t);
883
884
  } else 3 === t && a();
884
885
  return a(), c.length || c.push({
@@ -895,10 +896,10 @@ exports.Delete = function(e, n = t(e.selection)) {
895
896
  })(e.serializeText, e.serializers));
896
897
  }, exports.internalTranferPlugin = function(e) {
897
898
  e.hook("copy", n => {
898
- n.setData(wt, JSON.stringify(R(e.doc, ...t(e.selection))));
899
+ n.setData(Mt, JSON.stringify(T(e.doc, ...t(e.selection))));
899
900
  }), e.hook("paste", t => {
900
901
  try {
901
- return JSON.parse(t.getData(wt));
902
+ return JSON.parse(t.getData(Mt));
902
903
  } catch (t) {
903
904
  return null;
904
905
  }
@@ -906,9 +907,9 @@ exports.Delete = function(e, n = t(e.selection)) {
906
907
  }, exports.keymapPlugin = function(t, e) {
907
908
  r(e).forEach(n => {
908
909
  const r = e[n];
909
- t.hook("keyboard", xt(n, () => {
910
+ t.hook("keyboard", gt(n, () => {
910
911
  r();
911
912
  }));
912
913
  });
913
- }, exports.plainTransferPlugin = vt, exports.singlelinePlugin = Mt;
914
+ }, exports.plainTransferPlugin = vt, exports.singlelinePlugin = St;
914
915
  //# sourceMappingURL=index.cjs.map