editate 0.6.3 → 0.6.5

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