editate 0.6.2 → 0.6.3

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
@@ -1,6 +1,6 @@
1
1
  const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n = Math.min, {keys: r, is: o} = Object, s = t => "string" == typeof t, c = t => "function" == typeof t, i = c(queueMicrotask) ? queueMicrotask : t => {
2
2
  Promise.resolve().then(t);
3
- }, a = (t, e = t => h(t) ? t.text : "") => t.children.reduce((t, n, r) => {
3
+ }, a = (t, e = t => y(t) ? t.text : "") => t.children.reduce((t, n, r) => {
4
4
  const o = x(n);
5
5
  return 0 !== r && o && (t += "\n"), t + (o ? n.children.reduce((t, n) => t + e(n), "") : "");
6
6
  }, ""), l = (t, e, n) => t.split("\n").map(t => ({
@@ -9,7 +9,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
9
9
  ...e,
10
10
  text: t
11
11
  } ]
12
- })), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", y = "set_node_attr", h = t => "text" in t, x = t => "children" in t, g = (t, e) => {
12
+ })), f = "delete", u = "insert_text", d = "insert_node", p = "set_attr", h = "set_node_attr", y = t => "text" in t, x = t => "children" in t, g = (t, e) => {
13
13
  const n = r(t);
14
14
  return n.length === r(e).length && n.every(n => n in e && ("text" === n || o(t[n], e[n])));
15
15
  }, _ = new WeakMap, k = ({children: t}, e = 0, n = t.length) => {
@@ -24,7 +24,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
24
24
  let e = _.get(t);
25
25
  return null == e && _.set(t, e = k(t)), e;
26
26
  }
27
- return h(t) ? t.text.length : 1;
27
+ return y(t) ? t.text.length : 1;
28
28
  }, m = (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];
@@ -32,40 +32,41 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
32
32
  }, v = (t, e) => {
33
33
  const n = I(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) ], S = (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) ], E = (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];
39
- h(e) && h(o) && g(e, o) ? (t[r - 1] = {
39
+ y(e) && y(o) && g(e, o) ? (t[r - 1] = {
40
40
  ...e,
41
41
  text: e.text + o.text
42
42
  }, t.splice(r, 1), n--) : r++;
43
43
  }
44
44
  for (r = e; r <= n; ) {
45
45
  const e = t[r];
46
- h(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
46
+ y(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
47
47
  }
48
- }, D = (t, e = 0, n = t.length - 1) => {
48
+ }, S = (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
52
  t[r - 1] = O(e, o), t.splice(r, 1), n--;
53
53
  }
54
- }, E = (t, e, n) => {
54
+ }, D = (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
59
  }, O = (...t) => ({
60
60
  ...t[0],
61
- children: t.reduce((t, e) => (E(t, e.children, S), t), [])
61
+ children: t.reduce((t, e) => (D(t, e.children, E), t), [])
62
62
  }), A = ({children: t}, e) => {
63
- for (let n = 0; n < t.length; n++) {
64
- const r = t[n];
65
- let o = b(r);
66
- if (x(r) && o++, o > e) return {
67
- i: r,
68
- l: n,
63
+ const n = t.length;
64
+ for (let r = 0; r < n; r++) {
65
+ const n = t[r];
66
+ let o = b(n);
67
+ if (x(n) && o++, o > e || o === e && y(n) && !n.text) return {
68
+ i: n,
69
+ l: r,
69
70
  o: e
70
71
  };
71
72
  e -= o;
@@ -101,7 +102,7 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
101
102
  }
102
103
  {
103
104
  const r = n.slice(0, s), c = n.slice(s + 1);
104
- if (h(e)) {
105
+ if (y(e)) {
105
106
  const t = e.text.slice(0, o), n = e.text.slice(o);
106
107
  !t && r.length || r.push({
107
108
  ...e,
@@ -120,9 +121,13 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
120
121
  } ];
121
122
  }
122
123
  }
124
+ const o = n[n.length - 1];
123
125
  return [ t, {
124
126
  ...t,
125
- children: []
127
+ children: y(o) ? [ {
128
+ ...o,
129
+ text: ""
130
+ } ] : []
126
131
  } ];
127
132
  }, C = (t, e, n, r = 0) => {
128
133
  if (r < e.length) {
@@ -138,11 +143,11 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
138
143
  return n;
139
144
  }, H = (t, e, n, r) => {
140
145
  const [o, s] = P(t, e), c = e < n ? P(t, n)[1] : s, i = o.children.slice();
141
- return E(i, r, D), E(i, c.children, D), {
146
+ return D(i, r, S), D(i, c.children, S), {
142
147
  ...t,
143
148
  children: i
144
149
  };
145
- }, R = (t, e, n) => e >= n ? [] : P(P(t, n)[0], e)[1].children, B = (t, e) => e >= 0 && e <= b(t), N = (t, e) => e.reduce((t, e) => V(t, e), t), V = (t, e) => {
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) => {
146
151
  switch (e.type) {
147
152
  case f:
148
153
  {
@@ -168,9 +173,9 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
168
173
  }
169
174
  }
170
175
  return t;
171
- }, F = ([t, e], n) => [ V(t, n), V(e, n) ];
176
+ }, N = ([t, e], n) => [ L(t, n), L(e, n) ];
172
177
 
173
- function L(t, e) {
178
+ function V(t, e) {
174
179
  t.apply({
175
180
  type: "delete",
176
181
  range: [ 0, b(t.doc) ]
@@ -181,7 +186,7 @@ function L(t, e) {
181
186
  });
182
187
  }
183
188
 
184
- let T = null, W = null, q = null, J = null, U = null;
189
+ let F = null, W = null, q = null, J = null, U = null;
185
190
 
186
191
  const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = () => {
187
192
  const t = X();
@@ -190,18 +195,19 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
190
195
  if (null != q) return q;
191
196
  if (W) if ((t => 3 === t.nodeType)(W)) {
192
197
  const t = W.data;
193
- if (t) return q = "\n" === t ? $() ? 3 : 6 : 1;
198
+ if (t) return q = "\n" === t ? tt() ? 3 : 5 : 1;
194
199
  } else if (G(W)) {
195
- if ("BR" === W.tagName) return q = $() ? 3 : 5;
200
+ if ("BR" === W.tagName) return q = tt() ? 3 : 5;
201
+ if ($(W)) return q = 6;
196
202
  if (J.u(W)) return q = 2;
197
203
  if (J.p(W)) return q = 4;
198
204
  }
199
205
  return q = 0;
200
- }, Y = () => (q = null, W = T.nextNode()), K = () => {
201
- for (;(q = null) || (W = T.nextSibling()); ) if (4 === X()) return;
206
+ }, Y = () => (q = null, W = F.nextNode()), K = () => {
207
+ for (;(q = null) || (W = F.nextSibling()); ) if (4 === X()) return;
202
208
  }, Q = () => {
203
- for (;(q = null) || (W = T.parentNode()); ) if (4 === X()) return;
204
- }, $ = () => {
209
+ for (;(q = null) || (W = F.parentNode()); ) if (4 === X()) return;
210
+ }, $ = t => "TEMPLATE" === t.tagName, tt = () => {
205
211
  const t = W.parentNode;
206
212
  return U(() => {
207
213
  for (;Y(); ) {
@@ -210,7 +216,7 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
210
216
  }
211
217
  return !1;
212
218
  });
213
- }, tt = () => {
219
+ }, et = () => {
214
220
  for (;;) {
215
221
  if (2 === X()) {
216
222
  const t = W;
@@ -218,40 +224,40 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
218
224
  } else Y();
219
225
  if (!W) break;
220
226
  const t = X();
221
- if (t) return t;
227
+ if (t && 6 !== t) return t;
222
228
  }
223
- }, et = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TR" ]), nt = t => et.has(t.tagName), rt = new Set([ "EMBED", "IMG", "PICTURE", "AUDIO", "VIDEO", "SVG", "CANVAS", "MATH", "IFRAME", "OBJECT" ]), ot = t => "false" === t.contentEditable || rt.has(t.tagName), st = (t, e) => t.compareDocumentPosition(e), ct = t => t.ownerDocument, it = t => ct(t).getSelection(), at = (t, e) => {
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) => {
224
230
  if (t.rangeCount) {
225
231
  const n = t.getRangeAt(0);
226
232
  if (e.contains(n.commonAncestorContainer)) return n;
227
233
  }
228
- }, lt = (t, e, n, r) => {
229
- const o = it(t);
230
- (n || at(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
234
+ }, ft = (t, e, n, r) => {
235
+ const o = at(t);
236
+ (n || lt(o, t)) && (o.removeAllRanges(), o.addRange(e), r && (o.collapseToEnd(),
231
237
  o.extend(e.startContainer, e.startOffset)));
232
- }, ft = (t, e, [n, r], o, s, c) => {
238
+ }, ut = (t, e, [n, r], o, s, c) => {
233
239
  const i = 0 === o, a = o > 0, l = a ? r : n, f = a ? n : r;
234
240
  if (0 === l[0].length && 0 === l[1] && i && !e.hasChildNodes()) {
235
241
  const n = t.createRange();
236
- return n.setStart(e, 0), n.setEnd(e, 0), lt(e, n, c);
242
+ return n.setStart(e, 0), n.setEnd(e, 0), ft(e, n, c);
237
243
  }
238
- const u = ut(e, l, s);
244
+ const u = dt(e, l, s);
239
245
  if (!u) return;
240
- const d = i ? u : ut(e, f, s);
246
+ const d = i ? u : dt(e, f, s);
241
247
  if (!d) return;
242
- const p = t.createRange(), [y, h] = u, [x, g] = d;
243
- G(y) ? h < 1 ? p.setStartBefore(y) : p.setStartAfter(y) : p.setStart(y, h), G(x) ? g < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, g),
244
- lt(e, p, c, a);
245
- }, ut = (t, [e, n], r) => r(() => {
248
+ 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(() => {
246
252
  let t, r = 0;
247
- for (;t = tt(); ) if (4 === t) {
253
+ for (;t = et(); ) if (4 === t) {
248
254
  if (r < e.length) for (let t = e[r++]; t > 0; t--) K();
249
255
  } else {
250
256
  const t = z();
251
257
  if (n <= t) return [ j(), n ];
252
258
  n -= t;
253
259
  }
254
- }, t), dt = (t, e, r, o) => {
260
+ }, t), pt = (t, e, r, o) => {
255
261
  let s = !0;
256
262
  if (t === e && !e.hasChildNodes()) return [ [ 0 ], 0 ];
257
263
  if (G(e) && e.hasChildNodes()) {
@@ -266,12 +272,12 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
266
272
  for (;(n = j()) && n !== t; ) e.unshift(n), Q();
267
273
  if (!e.length) return [ 0 ];
268
274
  let r = 0, o = e[e.length - 1];
269
- for (;o = o.previousElementSibling; ) r++;
275
+ for (;o = o.previousElementSibling; ) $(o) || r++;
270
276
  return [ r ];
271
277
  });
272
278
  let c = 0;
273
- for (;tt(); ) {
274
- const t = st(e, j());
279
+ for (;et(); ) {
280
+ const t = ct(e, j());
275
281
  if (0 === t || 16 & t) {
276
282
  if (s) break;
277
283
  } else if (4 & t) break;
@@ -279,10 +285,10 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
279
285
  }
280
286
  return [ n, c + r ];
281
287
  }, t, e);
282
- }, pt = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
283
- const c = dt(t, r, n, e);
284
- return [ c, r === s && n === o ? c : dt(t, s, o, e) ];
285
- }, yt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), ht = (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) => {
286
292
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), s = "Space" === o ? " " : o.toLowerCase();
287
293
  let c = !1, i = !1, a = !1, l = !1;
288
294
  return r.forEach(t => {
@@ -312,20 +318,20 @@ const G = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = () => W, z = ()
312
318
  };
313
319
  };
314
320
 
315
- function xt(t) {
321
+ function gt(t) {
316
322
  let e = 0, n = 0, r = !1;
317
323
  const s = Date.now, c = [ [ t.doc, t.selection, [] ] ], i = () => c[e], a = () => e > 0, l = () => e < c.length - 1, f = () => {
318
324
  if (a()) {
319
325
  const n = i()[1];
320
326
  e--;
321
327
  const s = t.doc;
322
- r = !0, t.exec(L, i()[0].children), r = !1, o(s, t.doc) || (t.selection = n);
328
+ r = !0, t.exec(V, i()[0].children), r = !1, o(s, t.doc) || (t.selection = n);
323
329
  }
324
330
  }, u = () => {
325
331
  if (l()) {
326
332
  e++;
327
333
  const [n, s, c] = i(), a = t.doc;
328
- r = !0, t.exec(L, n.children), r = !1, o(a, t.doc) || (t.selection = [ N(s[0], c), N(s[1], c) ]);
334
+ r = !0, t.exec(V, n.children), r = !1, o(a, t.doc) || (t.selection = [ B(s[0], c), B(s[1], c) ]);
329
335
  }
330
336
  };
331
337
  t.hook("apply", (i, a) => {
@@ -342,8 +348,8 @@ function xt(t) {
342
348
  }
343
349
  n = t, c[e][0] = u, c[e][2].push(i), c.splice(e + 1), e > 500 && (e--, c.shift());
344
350
  }
345
- }), t.hook("keyboard", ht("Mod+Z", f)), t.hook("keyboard", ht("Shift+Mod+Z", u)),
346
- t.set(xt, {
351
+ }), t.hook("keyboard", xt("Mod+Z", f)), t.hook("keyboard", xt("Shift+Mod+Z", u)),
352
+ t.set(gt, {
347
353
  undo: f,
348
354
  redo: u,
349
355
  undoable: a,
@@ -351,9 +357,9 @@ function xt(t) {
351
357
  });
352
358
  }
353
359
 
354
- const gt = [], _t = () => {}, kt = t => {
360
+ const _t = [], kt = () => {}, bt = t => {
355
361
  throw Error(t);
356
- }, bt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = nt, onWarn: g = console.warn, onError: _ = kt}) => {
362
+ }, mt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = rt, onWarn: g = console.warn, onError: _ = bt}) => {
357
363
  let k = [ 0, 0 ];
358
364
  const b = t => {
359
365
  if (!a) return g("An unsafe operation was detected. We recommend using schema option."),
@@ -366,18 +372,18 @@ const gt = [], _t = () => {}, kt = t => {
366
372
  return !1;
367
373
  };
368
374
  a && !b(n) && _("Invalid document");
369
- const v = new Map, S = new WeakMap, D = t => v.get(t) || gt, E = new Map, O = t => {
370
- const e = E.get(t);
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);
371
377
  e && !e[1] && (e[1] = !0, i(() => {
372
378
  e[1] = !1, e[0].forEach(t => {
373
379
  t();
374
380
  });
375
381
  }));
376
382
  }, P = t => {
377
- if (!r) if (Array.isArray(t)) for (const e of t) V(e); else V(t);
383
+ if (!r) if (Array.isArray(t)) for (const e of t) L(e); else L(t);
378
384
  return G;
379
- }, V = t => {
380
- const e = n, r = D("apply"), s = r.length;
385
+ }, L = t => {
386
+ const e = n, r = S("apply"), s = r.length;
381
387
  let c = 0;
382
388
  const i = () => {
383
389
  if (c < s) {
@@ -391,21 +397,21 @@ const gt = [], _t = () => {}, kt = t => {
391
397
  case f:
392
398
  {
393
399
  const [r, o] = n.range;
394
- B(t, r) && B(t, o) && r < o && (t = H(t, r, o, []), e = F(e, n));
400
+ T(t, r) && T(t, o) && r < o && (t = H(t, r, o, []), e = N(e, n));
395
401
  break;
396
402
  }
397
403
 
398
404
  case u:
399
405
  {
400
406
  const {at: r, text: o} = n;
401
- if (B(t, r) && o) {
407
+ if (T(t, r) && o) {
402
408
  const {i: s, o: c} = I(t, r), i = A(s, c - 1);
403
409
  let a;
404
410
  if (i) {
405
411
  const t = i.i;
406
- h(t) && (a = t);
412
+ y(t) && (a = t);
407
413
  }
408
- t = H(t, r, r, l(o, a, s)), e = F(e, n);
414
+ t = H(t, r, r, l(o, a, s)), e = N(e, n);
409
415
  }
410
416
  break;
411
417
  }
@@ -413,24 +419,33 @@ const gt = [], _t = () => {}, kt = t => {
413
419
  case d:
414
420
  {
415
421
  const {at: r, fragment: o} = n;
416
- B(t, r) && o.length && (t = H(t, r, r, o), e = F(e, n));
422
+ T(t, r) && o.length && (t = H(t, r, r, o), e = N(e, n));
417
423
  break;
418
424
  }
419
425
 
420
426
  case p:
421
427
  {
422
428
  const {range: [e, r], key: o, value: s} = n;
423
- B(t, e) && B(t, r) && e < r && (t = H(t, e, r, R(t, e, r).map(t => ({
429
+ if (T(t, e) && T(t, r) && e <= r) if (e === r) {
430
+ const {i: {children: n}, t: r} = I(t, e);
431
+ if (1 === n.length) {
432
+ const e = n[0];
433
+ y(e) && !e.text && (t = C(t, [ ...r, 0 ], {
434
+ ...e,
435
+ [o]: s
436
+ }));
437
+ }
438
+ } else t = H(t, e, r, R(t, e, r).map(t => ({
424
439
  ...t,
425
- children: t.children.map(t => h(t) ? {
440
+ children: t.children.map(t => y(t) ? {
426
441
  ...t,
427
442
  [o]: s
428
443
  } : t)
429
- }))));
444
+ })));
430
445
  break;
431
446
  }
432
447
 
433
- case y:
448
+ case h:
434
449
  {
435
450
  const {path: e, key: r, value: o} = n, s = ((t, e) => {
436
451
  for (let n = 0; n < e.length; n++) t = t.children[e[n]];
@@ -445,7 +460,7 @@ const gt = [], _t = () => {}, kt = t => {
445
460
  }
446
461
  return [ t, e ];
447
462
  })(n, k, t);
448
- (({type: t}) => t === d || t === p || t === y)(t) && !b(e) || (n = e, k = r);
463
+ (({type: t}) => t === d || t === p || t === h)(t) && !b(e) || (n = e, k = r);
449
464
  } catch (t) {
450
465
  g("rollback operation: " + t);
451
466
  }
@@ -454,8 +469,8 @@ const gt = [], _t = () => {}, kt = t => {
454
469
  e && (t = e), c++, i();
455
470
  };
456
471
  i(), o(e, n) || O("change");
457
- }, L = t => {
458
- !((t, [e, n]) => B(t, e) && B(t, n))(n, t) || k[0] === t[0] && k[1] === t[1] || (k = t,
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,
459
474
  O("selectionchange"));
460
475
  }, G = {
461
476
  get doc() {
@@ -465,7 +480,7 @@ const gt = [], _t = () => {}, kt = t => {
465
480
  return k;
466
481
  },
467
482
  set selection(t) {
468
- L(t);
483
+ V(t);
469
484
  },
470
485
  get readonly() {
471
486
  return r;
@@ -475,8 +490,8 @@ const gt = [], _t = () => {}, kt = t => {
475
490
  },
476
491
  apply: P,
477
492
  on: (t, e) => {
478
- let n = E.get(t);
479
- n || E.set(t, n = [ new Set, !1 ]);
493
+ let n = D.get(t);
494
+ n || D.set(t, n = [ new Set, !1 ]);
480
495
  const r = n[0];
481
496
  return r.add(e), () => {
482
497
  r.delete(e);
@@ -493,41 +508,41 @@ const gt = [], _t = () => {}, kt = t => {
493
508
  const n = t(G, ...e);
494
509
  return void 0 === n ? G : n;
495
510
  },
496
- get: t => (S.has(t) || _("No value found for key"), S.get(t)),
497
- set: (t, e) => (S.set(t, e), G),
511
+ get: t => (E.has(t) || _("No value found for key"), E.get(t)),
512
+ set: (t, e) => (E.set(t, e), G),
498
513
  input: o => {
499
514
  if (!window.InputEvent || !c(InputEvent.prototype.getTargetRanges)) return g("beforeinput event is not supported."),
500
- _t;
515
+ kt;
501
516
  const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
502
517
  o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
503
- let d = !1, p = null, y = !1, h = !1, _ = !1;
504
- const b = ct(o), v = (t => {
518
+ let d = !1, p = null, h = !1, y = !1, _ = !1;
519
+ const b = it(o), v = (t => {
505
520
  const e = (n, r, o) => {
506
- const s = J, c = U, i = T, a = W, l = q;
521
+ const s = J, c = U, i = F, a = W, l = q;
507
522
  try {
508
- return T || (J = t, U = e, T = J.h.createTreeWalker(r, 5)), o && (T.currentNode = W = o),
523
+ return F || (J = t, U = e, F = J.h.createTreeWalker(r, 5)), o && (F.currentNode = W = o),
509
524
  n();
510
525
  } finally {
511
- J = s, U = c, T = i, W = a, q = l, T && a && (T.currentNode = a);
526
+ J = s, U = c, F = i, W = a, q = l, F && a && (F.currentNode = a);
512
527
  }
513
528
  };
514
529
  return e;
515
530
  })({
516
531
  h: b,
517
532
  p: x,
518
- u: ot
519
- }), S = () => {
533
+ u: st
534
+ }), E = () => {
520
535
  o.contentEditable = r ? "false" : "true", o.ariaReadOnly = r ? "true" : null;
521
536
  };
522
- S();
523
- const E = G.on("change", () => {
524
- h || requestAnimationFrame(() => {
525
- h || o.focus({
537
+ E();
538
+ const D = G.on("change", () => {
539
+ y || requestAnimationFrame(() => {
540
+ y || o.focus({
526
541
  preventScroll: !0
527
542
  });
528
543
  });
529
- }), O = G.on("readonly", S), A = t => {
530
- for (const e of D("paste")) {
544
+ }), O = G.on("readonly", E), A = t => {
545
+ for (const e of S("paste")) {
531
546
  const n = e(t, v);
532
547
  if (n) return n;
533
548
  }
@@ -565,31 +580,31 @@ const gt = [], _t = () => {}, kt = t => {
565
580
  }
566
581
  };
567
582
  })(o, () => {
568
- ft(b, o, M(n, k), k[0] - k[1], v);
583
+ ut(b, o, M(n, k), k[0] - k[1], v);
569
584
  }), C = () => {
570
- L(w(n, ((t, e) => {
571
- const n = it(t), r = at(n, t);
585
+ V(w(n, ((t, e) => {
586
+ const n = at(t), r = lt(n, t);
572
587
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
573
- const o = pt(t, e, r), s = st(n.anchorNode, n.focusNode);
588
+ const o = ht(t, e, r), s = ct(n.anchorNode, n.focusNode);
574
589
  return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
575
590
  })(o, v)));
576
591
  }, H = () => {
577
592
  const t = I.m();
578
- I.k(!1), t.length && (I._(t), b.removeEventListener("selectionchange", X), ft(b, o, M(n, k), k[0] - k[1], v, !0),
579
- b.addEventListener("selectionchange", X)), p && (L(p[1]), P(p[0]), p = null), y = !1;
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;
580
595
  }, R = t => {
581
- if (!y) for (const e of D("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
582
- }, B = () => {
583
- y || H();
584
- }, V = t => {
596
+ if (!h) for (const e of S("keyboard")) if (e(t)) return t.preventDefault(), void I.k(!1);
597
+ }, T = () => {
598
+ h || H();
599
+ }, L = t => {
585
600
  t.preventDefault();
586
601
  const r = t.inputType;
587
602
  if (r.startsWith("format")) return;
588
603
  if ("historyUndo" === r || "historyRedo" === r) return;
589
- y ? I.k(!0) : C();
604
+ h ? I.k(!0) : C();
590
605
  const s = t.getTargetRanges()[0];
591
606
  if (s) {
592
- const c = w(n, pt(o, v, s));
607
+ const c = w(n, ht(o, v, s));
593
608
  let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
594
609
  if (null == a) {
595
610
  const e = t.dataTransfer;
@@ -604,19 +619,19 @@ const gt = [], _t = () => {}, kt = t => {
604
619
  text: a
605
620
  });
606
621
  }
607
- y || H();
608
- }, F = () => {
609
- y || C(), y = !0;
622
+ h || H();
623
+ }, N = () => {
624
+ h || C(), h = !0;
610
625
  }, Z = () => {
611
626
  H();
612
627
  }, j = () => {
613
- h = !0, C();
628
+ y = !0, C();
614
629
  }, z = () => {
615
- h = !1;
630
+ y = !1;
616
631
  }, X = () => {
617
- !h || y || _ || C();
632
+ !y || h || _ || C();
618
633
  }, Y = t => {
619
- if (C(), !e(k)) for (const e of D("copy")) e(t);
634
+ if (C(), !e(k)) for (const e of S("copy")) e(t);
620
635
  }, K = t => {
621
636
  t.preventDefault(), Y(t.clipboardData);
622
637
  }, Q = e => {
@@ -647,10 +662,10 @@ const gt = [], _t = () => {}, kt = t => {
647
662
  const r = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}, o) => {
648
663
  if (t.caretPositionFromPoint) {
649
664
  const s = t.caretPositionFromPoint(n, r);
650
- if (s) return dt(e, s.offsetNode, s.offset, o);
665
+ if (s) return pt(e, s.offsetNode, s.offset, o);
651
666
  } else if (t.caretRangeFromPoint) {
652
667
  const s = t.caretRangeFromPoint(n, r);
653
- if (s) return dt(e, s.startContainer, s.startOffset, o);
668
+ if (s) return pt(e, s.startContainer, s.startOffset, o);
654
669
  }
655
670
  })(b, o, e, v);
656
671
  if (r && c) {
@@ -662,7 +677,7 @@ const gt = [], _t = () => {}, kt = t => {
662
677
  });
663
678
  const i = A(r);
664
679
  if (i) {
665
- const t = m(n, c), r = N(t, o);
680
+ const t = m(n, c), r = B(t, o);
666
681
  o.push(s(i) ? {
667
682
  type: "insert_text",
668
683
  at: r,
@@ -671,29 +686,29 @@ const gt = [], _t = () => {}, kt = t => {
671
686
  type: "insert_node",
672
687
  at: r,
673
688
  fragment: i
674
- }), e = [ r, N(t, o) ];
689
+ }), e = [ r, B(t, o) ];
675
690
  }
676
- P(o), e && L(e);
691
+ P(o), e && V(e);
677
692
  }
678
693
  }, et = t => {
679
694
  _ = !0, Y(t.dataTransfer);
680
695
  }, nt = () => {
681
696
  _ = !1;
682
697
  };
683
- b.addEventListener("selectionchange", X), o.addEventListener("keydown", R), o.addEventListener("input", B),
684
- o.addEventListener("beforeinput", V), o.addEventListener("compositionstart", F),
698
+ b.addEventListener("selectionchange", X), o.addEventListener("keydown", R), o.addEventListener("input", T),
699
+ o.addEventListener("beforeinput", L), o.addEventListener("compositionstart", N),
685
700
  o.addEventListener("compositionend", Z), o.addEventListener("focus", j), o.addEventListener("blur", z),
686
701
  o.addEventListener("copy", K), o.addEventListener("cut", Q), o.addEventListener("paste", $),
687
702
  o.addEventListener("drop", tt), o.addEventListener("dragstart", et), o.addEventListener("dragend", nt);
688
703
  const rt = [];
689
- return D("mount").forEach(t => {
704
+ return S("mount").forEach(t => {
690
705
  const e = t(o);
691
706
  e && rt.push(e);
692
707
  }), () => {
693
- d || (d = !0, E(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
708
+ d || (d = !0, D(), O(), o.contentEditable = i, o.role = a, o.ariaMultiLine = l,
694
709
  o.ariaReadOnly = f, o.style.whiteSpace = u, I.v(), b.removeEventListener("selectionchange", X),
695
- o.removeEventListener("keydown", R), o.removeEventListener("input", B), o.removeEventListener("beforeinput", V),
696
- o.removeEventListener("compositionstart", F), o.removeEventListener("compositionend", Z),
710
+ o.removeEventListener("keydown", R), o.removeEventListener("input", T), o.removeEventListener("beforeinput", L),
711
+ o.removeEventListener("compositionstart", N), o.removeEventListener("compositionend", Z),
697
712
  o.removeEventListener("focus", j), o.removeEventListener("blur", z), o.removeEventListener("copy", K),
698
713
  o.removeEventListener("cut", Q), o.removeEventListener("paste", $), o.removeEventListener("drop", tt),
699
714
  o.removeEventListener("dragstart", et), o.removeEventListener("dragend", nt), rt.forEach(t => {
@@ -702,10 +717,10 @@ const gt = [], _t = () => {}, kt = t => {
702
717
  };
703
718
  }
704
719
  };
705
- return G.exec(xt), G;
720
+ return G.exec(gt), G;
706
721
  };
707
722
 
708
- function mt(e, n) {
723
+ function vt(e, n) {
709
724
  const r = n && n.serializer;
710
725
  e.hook("copy", n => {
711
726
  n.setData("text/plain", a({
@@ -714,9 +729,9 @@ function mt(e, n) {
714
729
  }), e.hook("paste", t => t.getData("text/plain"));
715
730
  }
716
731
 
717
- const vt = "application/x-editate-editor";
732
+ const wt = "application/x-editate-editor";
718
733
 
719
- function wt(t) {
734
+ function Mt(t) {
720
735
  t.hook("mount", t => {
721
736
  t.ariaMultiLine = null;
722
737
  }), t.hook("apply", (t, e) => {
@@ -757,10 +772,10 @@ exports.Delete = function(e, n = t(e.selection)) {
757
772
  text: e
758
773
  });
759
774
  }, exports.Redo = function(t) {
760
- t.get(xt).redo();
775
+ t.get(gt).redo();
761
776
  }, exports.Redoable = function(t) {
762
- return t.get(xt).redoable();
763
- }, exports.ReplaceDoc = L, exports.ReplaceText = function(e, n) {
777
+ return t.get(gt).redoable();
778
+ }, exports.ReplaceDoc = V, exports.ReplaceText = function(e, n) {
764
779
  const r = t(e.selection);
765
780
  e.apply({
766
781
  type: "delete",
@@ -786,28 +801,37 @@ exports.Delete = function(e, n = t(e.selection)) {
786
801
  key: e,
787
802
  value: s[e] === n ? r : n
788
803
  });
789
- }, exports.ToggleFormat = function(e, n, r = t(e.selection)) {
790
- const o = R(e.doc, ...r).flatMap(t => t.children.filter(h));
791
- o.length && e.apply({
804
+ }, exports.ToggleFormat = function(n, r, o = t(n.selection)) {
805
+ let s;
806
+ if (e(o)) {
807
+ const t = ((t, e) => {
808
+ const n = I(t, e);
809
+ return A(n.i, n.o);
810
+ })(n.doc, o[0]);
811
+ if (!t) return;
812
+ s = [ t.i ];
813
+ } else s = R(n.doc, ...o).flatMap(t => t.children);
814
+ const c = s.filter(y);
815
+ c.length && n.apply({
792
816
  type: "set_attr",
793
- range: r,
794
- key: n,
795
- value: !!o.some(t => !t[n])
817
+ range: o,
818
+ key: r,
819
+ value: !!c.some(t => !t[r])
796
820
  });
797
821
  }, exports.Undo = function(t) {
798
- t.get(xt).undo();
822
+ t.get(gt).undo();
799
823
  }, exports.Undoable = function(t) {
800
- return t.get(xt).undoable();
801
- }, exports.createEditor = bt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
802
- const o = bt({
824
+ return t.get(gt).undoable();
825
+ }, exports.createEditor = mt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
826
+ const o = mt({
803
827
  ...r,
804
828
  doc: {
805
829
  children: l(t)
806
830
  }
807
- }).exec(mt);
831
+ }).exec(vt);
808
832
  return o.on("change", () => {
809
833
  n(a(o.doc));
810
- }), e && o.exec(wt), o;
834
+ }), e && o.exec(Mt), o;
811
835
  }, exports.debugPlugin = function(t) {
812
836
  t.hook("apply", t => {
813
837
  console.log("apply", t);
@@ -836,7 +860,7 @@ exports.Delete = function(e, n = t(e.selection)) {
836
860
  })), t.hook("copy", t => {
837
861
  if (!n) return;
838
862
  const e = document.createElement("div");
839
- e.appendChild(at(it(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
863
+ e.appendChild(lt(at(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
840
864
  }), t.hook("paste", ((t, e = []) => (n, r) => {
841
865
  const o = n.getData("text/html");
842
866
  if (o) {
@@ -852,7 +876,7 @@ exports.Delete = function(e, n = t(e.selection)) {
852
876
  children: e
853
877
  }), e = null, s = !1;
854
878
  };
855
- for (;t = tt(); ) if (4 === t) a(); else if (s = !0, 1 === t) o += j().data; else if (2 === t) {
879
+ for (;t = et(); ) if (4 === t) a(); else if (s = !0, 1 === t) o += j().data; else if (2 === t) {
856
880
  i();
857
881
  const t = r(j());
858
882
  t && e.push(t);
@@ -871,10 +895,10 @@ exports.Delete = function(e, n = t(e.selection)) {
871
895
  })(e.serializeText, e.serializers));
872
896
  }, exports.internalTranferPlugin = function(e) {
873
897
  e.hook("copy", n => {
874
- n.setData(vt, JSON.stringify(R(e.doc, ...t(e.selection))));
898
+ n.setData(wt, JSON.stringify(R(e.doc, ...t(e.selection))));
875
899
  }), e.hook("paste", t => {
876
900
  try {
877
- return JSON.parse(t.getData(vt));
901
+ return JSON.parse(t.getData(wt));
878
902
  } catch (t) {
879
903
  return null;
880
904
  }
@@ -882,9 +906,9 @@ exports.Delete = function(e, n = t(e.selection)) {
882
906
  }, exports.keymapPlugin = function(t, e) {
883
907
  r(e).forEach(n => {
884
908
  const r = e[n];
885
- t.hook("keyboard", ht(n, () => {
909
+ t.hook("keyboard", xt(n, () => {
886
910
  r();
887
911
  }));
888
912
  });
889
- }, exports.plainTransferPlugin = mt, exports.singlelinePlugin = wt;
913
+ }, exports.plainTransferPlugin = vt, exports.singlelinePlugin = Mt;
890
914
  //# sourceMappingURL=index.cjs.map