editate 0.6.19 → 0.6.20

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
@@ -92,25 +92,28 @@ var {min: t, max: e} = Math, {keys: n, is: r} = Object, o = t => "string" == typ
92
92
  return [ r, n ];
93
93
  }, m = (t, [e, n]) => [ k(t, e), k(t, n) ];
94
94
 
95
- function* _(t, e) {
96
- if (l(t)) for (const [n, r] of function*(t, [e, n]) {
97
- if (e >= n) return;
98
- if (!l(t)) return;
99
- const r = d(t, e);
100
- if (r) {
101
- let o = e - r[1], s = r[2];
102
- const c = t.children, i = c.length;
103
- for (;o <= n && s < i; ) {
104
- const t = c[s];
105
- yield [ t, o ], s++, o += p(t), l(t) && o++;
106
- }
95
+ function* _(t, [e, n]) {
96
+ if (e >= n) return;
97
+ if (!l(t)) return;
98
+ const r = d(t, e);
99
+ if (r) {
100
+ let o = e - r[1], s = r[2];
101
+ const c = t.children, i = c.length;
102
+ for (;o <= n && s < i; ) {
103
+ const t = c[s];
104
+ yield [ t, o ], s++, o += p(t), l(t) && o++;
107
105
  }
108
- }(t, e)) for (const t of _(n, [ 0, p(n) ])) t[1] += r, yield t; else yield [ t, 0 ];
106
+ }
109
107
  }
110
108
 
111
- var b = (n, r = 0, o = 1 / 0, s) => {
109
+ function* b(t, e) {
110
+ if (l(t)) for (const [n, r] of _(t, e)) for (const t of b(n, [ 0, p(n) ])) t[1] += r,
111
+ yield t; else yield [ t, 0 ];
112
+ }
113
+
114
+ var v = (n, r = 0, o = 1 / 0, s) => {
112
115
  let c = "", l = r;
113
- for (const [a, f] of _(n, [ r, o ])) {
116
+ for (const [a, f] of b(n, [ r, o ])) {
114
117
  for (let t = f - l; t > 0; t--) c += "\n";
115
118
  const n = p(a), u = f + n;
116
119
  if (i(a)) {
@@ -121,16 +124,16 @@ var b = (n, r = 0, o = 1 / 0, s) => {
121
124
  }
122
125
  for (let e = t(o, p(n)) - l; e > 0; e--) c += "\n";
123
126
  return c;
124
- }, v = (t, e, n) => e >= n ? [] : h(h(t, n)[0], e)[1].children, T = ([t, e]) => t > e ? [ e, t ] : [ t, e ], E = ([t, e]) => t === e, M = ([t, e], [n, r]) => t < r && n < e;
127
+ }, T = (t, e, n) => e >= n ? [] : h(h(t, n)[0], e)[1].children, E = ([t, e]) => t > e ? [ e, t ] : [ t, e ], M = ([t, e]) => t === e, S = ([t, e], [n, r]) => t < r && n < e;
125
128
 
126
- function* S(t, e = T(t.selection)) {
127
- if (E(e)) {
129
+ function* w(t, e = E(t.selection)) {
130
+ if (M(e)) {
128
131
  const n = y(t.doc, e[0])?.[0];
129
132
  n && (yield n);
130
- } else for (const [n, r] of _(t.doc, e)) M(e, [ r, r + p(n) ]) && (yield n);
133
+ } else for (const [n, r] of b(t.doc, e)) S(e, [ r, r + p(n) ]) && (yield n);
131
134
  }
132
135
 
133
- function w(t, e) {
136
+ function A(t, e) {
134
137
  t.apply({
135
138
  type: "patch_node",
136
139
  path: [],
@@ -139,23 +142,23 @@ function w(t, e) {
139
142
  });
140
143
  }
141
144
 
142
- var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), D = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), B = t => D.has(t.tagName), I = (t, e) => t.compareDocumentPosition(e), P = t => t.ownerDocument, N = t => P(t).getSelection(), L = (t, e) => {
145
+ var O = t => 1 === t.nodeType, R = t => 8 === t.nodeType, D = new Map([ [ "BR", 1 ], [ "WBR", 1 ], [ "AREA", 2 ], [ "BASE", 2 ], [ "DATALIST", 2 ], [ "HEAD", 2 ], [ "LINK", 2 ], [ "META", 2 ], [ "RP", 2 ], [ "SCRIPT", 2 ], [ "STYLE", 2 ], [ "TEMPLATE", 2 ], [ "TITLE", 2 ], [ "COLGROUP", 2 ], [ "HR", 3 ], [ "AUDIO", 3 ], [ "CANVAS", 3 ], [ "EMBED", 3 ], [ "IFRAME", 3 ], [ "IMG", 3 ], [ "OBJECT", 3 ], [ "PICTURE", 3 ], [ "VIDEO", 3 ], [ "SVG", 3 ], [ "MATH", 3 ], [ "BUTTON", 3 ], [ "INPUT", 3 ], [ "METER", 3 ], [ "PROGRESS", 3 ], [ "SELECT", 3 ], [ "TEXTAREA", 3 ] ]), B = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), I = t => B.has(t.tagName), P = (t, e) => t.compareDocumentPosition(e), N = t => t.ownerDocument, L = t => N(t).getSelection(), C = (t, e) => {
143
146
  if (t.rangeCount) {
144
147
  const n = t.getRangeAt(0);
145
148
  if (e.contains(n.commonAncestorContainer)) return n;
146
149
  }
147
- }, C = (t, e, n, r) => {
148
- const [o, s] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), c = P(t), i = E(r), l = r[0] - r[1] > 0, a = l ? o : s, f = F(t, e, l ? s : o), u = i ? f : F(t, e, a), p = c.createRange(), [d, x] = f, [y, h] = u;
149
- return A(d) && t !== d ? x < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, x),
150
- A(y) && t !== y ? h < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, h),
150
+ }, H = (t, e, n, r) => {
151
+ const [o, s] = ((t, [e, n]) => [ g(t, e), g(t, n) ])(n, r), c = N(t), i = M(r), l = r[0] - r[1] > 0, a = l ? o : s, f = U(t, e, l ? s : o), u = i ? f : U(t, e, a), p = c.createRange(), [d, x] = f, [y, h] = u;
152
+ return O(d) && t !== d ? x < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, x),
153
+ O(y) && t !== y ? h < 1 ? p.setEndBefore(y) : p.setEndAfter(y) : p.setEnd(y, h),
151
154
  p;
152
- }, H = (t, e, n, r, o) => {
153
- const s = N(t);
154
- if (o || L(s, t)) {
155
- const o = C(t, e, n, r), c = r[0] - r[1] > 0;
155
+ }, F = (t, e, n, r, o) => {
156
+ const s = L(t);
157
+ if (o || C(s, t)) {
158
+ const o = H(t, e, n, r), c = r[0] - r[1] > 0;
156
159
  s.removeAllRanges(), s.addRange(o), c && (s.collapseToEnd(), s.extend(o.startContainer, o.startOffset));
157
160
  }
158
- }, F = (t, e, [n, r]) => e(({t: e, o, i: s, l: c}) => {
161
+ }, U = (t, e, [n, r]) => e(({t: e, o, i: s, l: c}) => {
159
162
  let i, l = 0;
160
163
  for (;i = e(); ) if (4 === i) {
161
164
  if (l < n.length) for (let t = n[l++]; t > 0; t--) o();
@@ -165,10 +168,10 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
165
168
  r -= t;
166
169
  }
167
170
  return [ t, 0 ];
168
- }, t), U = (e, n, r, o) => {
171
+ }, t), V = (e, n, r, o) => {
169
172
  let s = !0;
170
173
  if (e === r && !r.hasChildNodes()) return [ [], 0 ];
171
- if (A(r) && r.hasChildNodes()) {
174
+ if (O(r) && r.hasChildNodes()) {
172
175
  const e = t(o, r.childNodes.length - 1);
173
176
  r = r.childNodes[e], s = e === o, o = 0;
174
177
  }
@@ -185,7 +188,7 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
185
188
  });
186
189
  let d = 0;
187
190
  for (;t(); ) {
188
- const t = I(r, a());
191
+ const t = P(r, a());
189
192
  if (0 === t || 16 & t) {
190
193
  if (s) break;
191
194
  } else if (4 & t) break;
@@ -193,19 +196,19 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
193
196
  }
194
197
  return [ p, d + o ];
195
198
  }, e);
196
- }, V = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
197
- const c = U(t, e, r, n);
198
- return [ c, r === s && n === o ? c : U(t, e, s, o) ];
199
- }, W = (t, e, n) => t.split("\n").map(t => ({
199
+ }, W = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: s}) => {
200
+ const c = V(t, e, r, n);
201
+ return [ c, r === s && n === o ? c : V(t, e, s, o) ];
202
+ }, q = (t, e, n) => t.split("\n").map(t => ({
200
203
  ...n,
201
204
  children: [ {
202
205
  ...e,
203
206
  text: t
204
207
  } ]
205
- })), q = "delete", z = "insert_text", G = "insert_node", J = (t, e) => {
208
+ })), z = "delete", G = "insert_text", J = "insert_node", j = (t, e) => {
206
209
  const o = n(t);
207
210
  return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
208
- }, j = (t, e) => {
211
+ }, X = (t, e) => {
209
212
  if (e.length) {
210
213
  const n = t.length;
211
214
  if (t.push(...e), n) {
@@ -214,13 +217,13 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
214
217
  let r = e + 1;
215
218
  for (;r <= n; ) {
216
219
  const e = t[r - 1], o = t[r];
217
- t[r - 1] = X(e, o), t.splice(r, 1), n--;
220
+ t[r - 1] = Y(e, o), t.splice(r, 1), n--;
218
221
  }
219
222
  })(t, n - 1, n) : o || s || ((t, e = 0, n = t.length - 1) => {
220
223
  let r = e + 1;
221
224
  for (;r <= n; ) {
222
225
  const e = t[r - 1], o = t[r];
223
- i(e) && i(o) && J(e, o) ? (t[r - 1] = {
226
+ i(e) && i(o) && j(e, o) ? (t[r - 1] = {
224
227
  ...e,
225
228
  text: e.text + o.text
226
229
  }, t.splice(r, 1), n--) : r++;
@@ -235,10 +238,10 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
235
238
  t.length || t.push({
236
239
  text: ""
237
240
  });
238
- }, X = (...t) => ({
241
+ }, Y = (...t) => ({
239
242
  ...t[0],
240
- children: t.reduce((t, e) => (j(t, e.children), t), [])
241
- }), Y = (t, e, n, r = 0) => {
243
+ children: t.reduce((t, e) => (X(t, e.children), t), [])
244
+ }), Z = (t, e, n, r = 0) => {
242
245
  if (r < e.length) {
243
246
  const o = e[r];
244
247
  return ((t, e, n, r) => {
@@ -247,36 +250,36 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
247
250
  ...t,
248
251
  children: o
249
252
  };
250
- })(t, o, o, [ Y(t.children[o], e, n, r + 1) ]);
253
+ })(t, o, o, [ Z(t.children[o], e, n, r + 1) ]);
251
254
  }
252
255
  return n;
253
- }, Z = (t, e, n, r) => {
256
+ }, K = (t, e, n, r) => {
254
257
  const [o, s] = h(t, e), c = e < n ? h(t, n)[1] : s, i = a(t.children);
255
- a(r) ? i || (r = X(...r).children) : i && (r = [ {
258
+ a(r) ? i || (r = Y(...r).children) : i && (r = [ {
256
259
  children: r
257
260
  } ]);
258
261
  const l = o.children.slice();
259
- return j(l, r), j(l, c.children), {
262
+ return X(l, r), X(l, c.children), {
260
263
  ...t,
261
264
  children: l
262
265
  };
263
- }, K = (t, e) => e >= 0 && e <= p(t), Q = (t, e) => e.reduce((t, e) => $(t, e), t), $ = (t, e) => {
266
+ }, Q = (t, e) => e >= 0 && e <= p(t), $ = (t, e) => e.reduce((t, e) => tt(t, e), t), tt = (t, e) => {
264
267
  switch (e.type) {
265
- case q:
268
+ case z:
266
269
  {
267
270
  const [n, r] = e.range;
268
271
  if (t >= n) return r >= t ? n : t + n - r;
269
272
  break;
270
273
  }
271
274
 
272
- case z:
275
+ case G:
273
276
  {
274
277
  const {at: n, text: r} = e;
275
278
  if (t >= n) return t + r.length;
276
279
  break;
277
280
  }
278
281
 
279
- case G:
282
+ case J:
280
283
  {
281
284
  const {at: n, fragment: r} = e;
282
285
  if (t >= n) return t + p({
@@ -286,7 +289,7 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
286
289
  }
287
290
  }
288
291
  return t;
289
- }, tt = ([t, e], n) => [ $(t, n), $(e, n) ], et = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), nt = (t, e) => {
292
+ }, et = ([t, e], n) => [ tt(t, n), tt(e, n) ], nt = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), rt = (t, e) => {
290
293
  const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), s = "Space" === o ? " " : o.toLowerCase();
291
294
  let c = !1, i = !1, l = !1, a = !1;
292
295
  return r.forEach(t => {
@@ -300,7 +303,7 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
300
303
  break;
301
304
 
302
305
  case "Mod":
303
- et ? l = !0 : i = !0;
306
+ nt ? l = !0 : i = !0;
304
307
  break;
305
308
 
306
309
  case "Alt":
@@ -315,20 +318,20 @@ var A = t => 1 === t.nodeType, O = t => 8 === t.nodeType, R = new Map([ [ "BR",
315
318
  };
316
319
  };
317
320
 
318
- function rt(t) {
321
+ function ot(t) {
319
322
  let e = 0, n = 0, r = !1;
320
323
  const o = Date.now, s = [ [ t.doc, t.selection, [] ] ], c = () => s[e], i = () => e > 0, l = () => e < s.length - 1, a = () => {
321
324
  if (i()) {
322
325
  const n = c()[1];
323
326
  e--;
324
327
  const o = t.doc;
325
- r = !0, t.exec(w, c()[0].children), r = !1, o !== t.doc && (t.selection = n);
328
+ r = !0, t.exec(A, c()[0].children), r = !1, o !== t.doc && (t.selection = n);
326
329
  }
327
330
  }, f = () => {
328
331
  if (l()) {
329
332
  e++;
330
333
  const [n, o, s] = c(), i = t.doc;
331
- r = !0, t.exec(w, n.children), r = !1, i !== t.doc && (t.selection = [ Q(o[0], s), Q(o[1], s) ]);
334
+ r = !0, t.exec(A, n.children), r = !1, i !== t.doc && (t.selection = [ $(o[0], s), $(o[1], s) ]);
332
335
  }
333
336
  };
334
337
  t.hook("apply", (c, i) => {
@@ -346,8 +349,8 @@ function rt(t) {
346
349
  n = t, s[e][0] = f, s[e][2].push(c), s.length > e + 1 && (s.length = e + 1), e > 500 && (e--,
347
350
  s.shift());
348
351
  }
349
- }), t.hook("keyboard", nt("Mod+Z", a)), t.hook("keyboard", nt("Shift+Mod+Z", f)),
350
- t.set(rt, {
352
+ }), t.hook("keyboard", rt("Mod+Z", a)), t.hook("keyboard", rt("Shift+Mod+Z", f)),
353
+ t.set(ot, {
351
354
  undo: a,
352
355
  redo: f,
353
356
  undoable: i,
@@ -355,9 +358,9 @@ function rt(t) {
355
358
  });
356
359
  }
357
360
 
358
- var ot = [], st = () => {}, ct = t => {
361
+ var st = [], ct = () => {}, it = t => {
359
362
  throw Error(t);
360
- }, it = ({doc: t, readonly: e = !1, schema: n, isBlock: r = B, onWarn: a = console.warn, onError: f = ct}) => {
363
+ }, lt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = I, onWarn: a = console.warn, onError: f = it}) => {
361
364
  let u = [ 0, 0 ];
362
365
  const p = t => {
363
366
  if (!n) return a("An unsafe operation was detected. We recommend using schema option."),
@@ -370,7 +373,7 @@ var ot = [], st = () => {}, ct = t => {
370
373
  return !1;
371
374
  };
372
375
  n && !p(t) && f("Invalid document");
373
- const y = new Map, h = new WeakMap, g = t => y.get(t) || ot, _ = new Map, b = new Set, M = t => {
376
+ const y = new Map, h = new WeakMap, g = t => y.get(t) || st, _ = new Map, b = new Set, v = t => {
374
377
  const e = _.get(t);
375
378
  e && (b.size || c(() => {
376
379
  b.forEach(t => {
@@ -381,7 +384,7 @@ var ot = [], st = () => {}, ct = t => {
381
384
  }));
382
385
  }, S = t => {
383
386
  if (!e) if (Array.isArray(t)) for (const e of t) w(e); else w(t);
384
- return D;
387
+ return R;
385
388
  }, w = e => {
386
389
  const n = t, r = g("apply"), o = r.length;
387
390
  let s = 0;
@@ -394,43 +397,43 @@ var ot = [], st = () => {}, ct = t => {
394
397
  try {
395
398
  const [n, r] = ((t, e, n) => {
396
399
  switch (n.type) {
397
- case q:
400
+ case z:
398
401
  {
399
402
  const [r, o] = n.range;
400
- K(t, r) && K(t, o) && r < o && (t = Z(t, r, o, []), e = tt(e, n));
403
+ Q(t, r) && Q(t, o) && r < o && (t = K(t, r, o, []), e = et(e, n));
401
404
  break;
402
405
  }
403
406
 
404
- case z:
407
+ case G:
405
408
  {
406
409
  const {at: r, text: o} = n;
407
- if (K(t, r) && o) {
410
+ if (Q(t, r) && o) {
408
411
  const [s, c] = x(t, r), l = d(s, c, !0);
409
412
  let a;
410
413
  if (l) {
411
414
  const t = l[0];
412
415
  i(t) && (a = t);
413
416
  }
414
- t = Z(t, r, r, W(o, a, s)), e = tt(e, n);
417
+ t = K(t, r, r, q(o, a, s)), e = et(e, n);
415
418
  }
416
419
  break;
417
420
  }
418
421
 
419
- case G:
422
+ case J:
420
423
  {
421
424
  const {at: r, fragment: o} = n;
422
- K(t, r) && o.length && (t = Z(t, r, r, o), e = tt(e, n));
425
+ Q(t, r) && o.length && (t = K(t, r, r, o), e = et(e, n));
423
426
  break;
424
427
  }
425
428
 
426
429
  case "format":
427
430
  {
428
431
  const {range: [e, r], key: o, value: s} = n;
429
- if (K(t, e) && K(t, r) && e <= r) if (e === r) {
432
+ if (Q(t, e) && Q(t, r) && e <= r) if (e === r) {
430
433
  const [{children: n}, , r] = x(t, e);
431
434
  if (1 === n.length) {
432
435
  const e = n[0];
433
- i(e) && !e.text && (t = Y(t, [ ...r, 0 ], {
436
+ i(e) && !e.text && (t = Z(t, [ ...r, 0 ], {
434
437
  ...e,
435
438
  [o]: s
436
439
  }));
@@ -443,7 +446,7 @@ var ot = [], st = () => {}, ct = t => {
443
446
  ...t,
444
447
  [o]: s
445
448
  } : t;
446
- t = Z(t, e, r, v(t, e, r).map(n));
449
+ t = K(t, e, r, T(t, e, r).map(n));
447
450
  }
448
451
  break;
449
452
  }
@@ -454,7 +457,7 @@ var ot = [], st = () => {}, ct = t => {
454
457
  for (let n = 0; n < e.length; n++) t = t.children[e[n]];
455
458
  return t;
456
459
  })(t, e);
457
- s && (t = Y(t, e, {
460
+ s && (t = Z(t, e, {
458
461
  ...s,
459
462
  [r]: o
460
463
  }));
@@ -463,7 +466,7 @@ var ot = [], st = () => {}, ct = t => {
463
466
  }
464
467
  return [ t, e ];
465
468
  })(t, u, e);
466
- (({type: t}) => t !== z && t !== q)(e) && !p(n) || (t = n, O(r));
469
+ (({type: t}) => t !== G && t !== z)(e) && !p(n) || (t = n, A(r));
467
470
  } catch (n) {
468
471
  a("rollback operation: " + n);
469
472
  }
@@ -471,11 +474,11 @@ var ot = [], st = () => {}, ct = t => {
471
474
  }, f = t => {
472
475
  t && (e = t), s++, c();
473
476
  };
474
- c(), n !== t && M("change");
475
- }, O = e => {
476
- !((t, [e, n]) => K(t, e) && K(t, n))(t, e) || u[0] === e[0] && u[1] === e[1] || (u = e,
477
- M("selectionchange"));
478
- }, D = {
477
+ c(), n !== t && v("change");
478
+ }, A = e => {
479
+ !((t, [e, n]) => Q(t, e) && Q(t, n))(t, e) || u[0] === e[0] && u[1] === e[1] || (u = e,
480
+ v("selectionchange"));
481
+ }, R = {
479
482
  get doc() {
480
483
  return t;
481
484
  },
@@ -483,13 +486,13 @@ var ot = [], st = () => {}, ct = t => {
483
486
  return u;
484
487
  },
485
488
  set selection(t) {
486
- O(t);
489
+ A(t);
487
490
  },
488
491
  get readonly() {
489
492
  return e;
490
493
  },
491
494
  set readonly(t) {
492
- e = t, M("readonly");
495
+ e = t, v("readonly");
493
496
  },
494
497
  apply: S,
495
498
  on: (t, e) => {
@@ -506,28 +509,28 @@ var ot = [], st = () => {}, ct = t => {
506
509
  };
507
510
  },
508
511
  exec: (t, ...e) => {
509
- const n = t(D, ...e);
510
- return void 0 === n ? D : n;
512
+ const n = t(R, ...e);
513
+ return void 0 === n ? R : n;
511
514
  },
512
515
  get: t => (h.has(t) || f("No value found for key"), h.get(t)),
513
- set: (t, e) => (h.set(t, e), D),
516
+ set: (t, e) => (h.set(t, e), R),
514
517
  input: n => {
515
518
  if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return a("beforeinput event is not supported."),
516
- st;
519
+ ct;
517
520
  const {contentEditable: c, role: i, ariaMultiLine: l, ariaReadOnly: f} = n, p = n.style.whiteSpace;
518
521
  n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
519
522
  let d = !1, x = null, y = !1, h = !1, _ = !1, b = u, v = null;
520
- const M = P(n), w = ((t, e) => {
523
+ const T = N(n), w = ((t, e) => {
521
524
  let n = null, r = null, o = null;
522
525
  const s = () => {
523
526
  if (null != o) return o;
524
527
  if (r) if ((t => 3 === t.nodeType)(r)) {
525
528
  const t = r.data;
526
529
  if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
527
- } else if (A(r)) {
530
+ } else if (O(r)) {
528
531
  if ("false" === r.contentEditable) return o = 2;
529
532
  {
530
- const t = R.get(r.tagName);
533
+ const t = D.get(r.tagName);
531
534
  if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
532
535
  if (e(r)) return o = 4;
533
536
  }
@@ -584,23 +587,23 @@ var ot = [], st = () => {}, ct = t => {
584
587
  }
585
588
  };
586
589
  return a;
587
- })(M, r), B = () => {
590
+ })(T, r), B = () => {
588
591
  n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
589
592
  };
590
593
  B();
591
- const C = () => {
594
+ const I = () => {
592
595
  h || n.focus({
593
596
  preventScroll: !0
594
597
  });
595
- }, F = () => {
596
- v = null, u[0] === b[0] && u[1] === b[1] || (H(n, w, t, u), b = u);
597
- }, W = () => {
598
+ }, H = () => {
599
+ v = null, u[0] === b[0] && u[1] === b[1] || (F(n, w, t, u), b = u);
600
+ }, U = () => {
598
601
  null != v && clearTimeout(v);
599
- }, q = D.on("change", () => {
600
- h || requestAnimationFrame(C);
601
- }), z = D.on("selectionchange", () => {
602
- u[0] === b[0] && u[1] === b[1] || (W(), v = setTimeout(F, 50));
603
- }), G = D.on("readonly", B), J = t => {
602
+ }, q = R.on("change", () => {
603
+ h || requestAnimationFrame(I);
604
+ }), z = R.on("selectionchange", () => {
605
+ u[0] === b[0] && u[1] === b[1] || (U(), v = setTimeout(H, 50));
606
+ }), G = R.on("readonly", B), J = t => {
604
607
  for (const e of g("paste")) {
605
608
  const n = e(t);
606
609
  if (n) return n;
@@ -643,23 +646,23 @@ var ot = [], st = () => {}, ct = t => {
643
646
  }
644
647
  };
645
648
  })(n, () => {
646
- W(), H(n, w, t, u);
649
+ U(), F(n, w, t, u);
647
650
  }), X = () => {
648
- O(b = m(t, ((t, e) => {
649
- const n = N(t), r = L(n, t);
651
+ A(b = m(t, ((t, e) => {
652
+ const n = L(t), r = C(n, t);
650
653
  if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
651
- const o = V(t, e, r), s = I(n.anchorNode, n.focusNode);
654
+ const o = W(t, e, r), s = P(n.anchorNode, n.focusNode);
652
655
  return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
653
656
  })(n, w)));
654
657
  }, Y = () => {
655
658
  const e = j.v();
656
- j._(!1), e.length && (j.m(e), M.removeEventListener("selectionchange", ot), H(n, w, t, u, !0),
657
- M.addEventListener("selectionchange", ot)), x && (O(x[1]), S(x[0]), x = null), y = !1;
659
+ j._(!1), e.length && (j.m(e), T.removeEventListener("selectionchange", ot), F(n, w, t, u, !0),
660
+ T.addEventListener("selectionchange", ot)), x && (A(x[1]), S(x[0]), x = null), y = !1;
658
661
  }, Z = t => {
659
662
  if (!y) for (const e of g("keyboard")) if (e(t)) return t.preventDefault(), void j._(!1);
660
663
  }, K = () => {
661
664
  y || Y();
662
- }, $ = e => {
665
+ }, Q = e => {
663
666
  e.preventDefault();
664
667
  const r = e.inputType;
665
668
  if (r.startsWith("format")) return;
@@ -673,8 +676,8 @@ var ot = [], st = () => {}, ct = t => {
673
676
  t && (s = t.getData("text/plain"));
674
677
  }
675
678
  x || (x = [ [], u ]);
676
- const c = x[0], i = m(t, V(n, w, o));
677
- E(i) || c.push({
679
+ const c = x[0], i = m(t, W(n, w, o));
680
+ M(i) || c.push({
678
681
  type: "delete",
679
682
  range: i
680
683
  }), s && c.push({
@@ -693,21 +696,21 @@ var ot = [], st = () => {}, ct = t => {
693
696
  }, rt = () => {
694
697
  h = !1;
695
698
  }, ot = () => {
696
- h && !_ && X();
697
- }, ct = t => {
698
- if (X(), !E(u)) for (const e of g("copy")) e(t);
699
+ !h || y || _ || X();
700
+ }, st = t => {
701
+ if (X(), !M(u)) for (const e of g("copy")) e(t);
699
702
  }, it = t => {
700
- t.preventDefault(), ct(t.clipboardData);
703
+ t.preventDefault(), st(t.clipboardData);
701
704
  }, lt = t => {
702
- t.preventDefault(), e || (ct(t.clipboardData), S({
705
+ t.preventDefault(), e || (st(t.clipboardData), S({
703
706
  type: "delete",
704
- range: T(u)
707
+ range: E(u)
705
708
  }));
706
709
  }, at = t => {
707
710
  t.preventDefault();
708
711
  const e = J(t.clipboardData);
709
712
  if (e) {
710
- const t = T(u), n = t[0], r = [ {
713
+ const t = E(u), n = t[0], r = [ {
711
714
  type: "delete",
712
715
  range: t
713
716
  } ];
@@ -724,13 +727,13 @@ var ot = [], st = () => {}, ct = t => {
724
727
  }, ft = e => {
725
728
  e.preventDefault();
726
729
  const r = e.dataTransfer, s = ((t, e, {clientX: n, clientY: r}) => {
727
- const o = P(t);
730
+ const o = N(t);
728
731
  if (o.caretPositionFromPoint) {
729
732
  const s = o.caretPositionFromPoint(n, r);
730
- if (s) return U(t, e, s.offsetNode, s.offset);
733
+ if (s) return V(t, e, s.offsetNode, s.offset);
731
734
  } else if (o.caretRangeFromPoint) {
732
735
  const s = o.caretRangeFromPoint(n, r);
733
- if (s) return U(t, e, s.startContainer, s.startOffset);
736
+ if (s) return V(t, e, s.startContainer, s.startOffset);
734
737
  }
735
738
  })(n, w, e);
736
739
  if (r && s) {
@@ -738,11 +741,11 @@ var ot = [], st = () => {}, ct = t => {
738
741
  const n = [];
739
742
  _ && n.push({
740
743
  type: "delete",
741
- range: T(u)
744
+ range: E(u)
742
745
  });
743
746
  const c = J(r);
744
747
  if (c) {
745
- const r = k(t, s), i = Q(r, n);
748
+ const r = k(t, s), i = $(r, n);
746
749
  n.push(o(c) ? {
747
750
  type: "insert_text",
748
751
  at: i,
@@ -751,18 +754,18 @@ var ot = [], st = () => {}, ct = t => {
751
754
  type: "insert_node",
752
755
  at: i,
753
756
  fragment: c
754
- }), e = [ i, Q(r, n) ];
757
+ }), e = [ i, $(r, n) ];
755
758
  }
756
- S(n), e && O(e);
759
+ S(n), e && A(e);
757
760
  }
758
761
  _ = !1;
759
762
  }, ut = t => {
760
- _ = !0, ct(t.dataTransfer);
763
+ _ = !0, st(t.dataTransfer);
761
764
  }, pt = () => {
762
765
  _ = !1;
763
766
  };
764
- M.addEventListener("selectionchange", ot), n.addEventListener("keydown", Z), n.addEventListener("input", K),
765
- n.addEventListener("beforeinput", $), n.addEventListener("compositionstart", tt),
767
+ T.addEventListener("selectionchange", ot), n.addEventListener("keydown", Z), n.addEventListener("input", K),
768
+ n.addEventListener("beforeinput", Q), n.addEventListener("compositionstart", tt),
766
769
  n.addEventListener("compositionend", et), n.addEventListener("focus", nt), n.addEventListener("blur", rt),
767
770
  n.addEventListener("copy", it), n.addEventListener("cut", lt), n.addEventListener("paste", at),
768
771
  n.addEventListener("drop", ft), n.addEventListener("dragstart", ut), n.addEventListener("dragend", pt);
@@ -772,8 +775,8 @@ var ot = [], st = () => {}, ct = t => {
772
775
  e && dt.push(e);
773
776
  }), () => {
774
777
  d || (d = !0, q(), z(), G(), n.contentEditable = c, n.role = i, n.ariaMultiLine = l,
775
- n.ariaReadOnly = f, n.style.whiteSpace = p, j.T(), M.removeEventListener("selectionchange", ot),
776
- n.removeEventListener("keydown", Z), n.removeEventListener("input", K), n.removeEventListener("beforeinput", $),
778
+ n.ariaReadOnly = f, n.style.whiteSpace = p, j.T(), T.removeEventListener("selectionchange", ot),
779
+ n.removeEventListener("keydown", Z), n.removeEventListener("input", K), n.removeEventListener("beforeinput", Q),
777
780
  n.removeEventListener("compositionstart", tt), n.removeEventListener("compositionend", et),
778
781
  n.removeEventListener("focus", nt), n.removeEventListener("blur", rt), n.removeEventListener("copy", it),
779
782
  n.removeEventListener("cut", lt), n.removeEventListener("paste", at), n.removeEventListener("drop", ft),
@@ -783,19 +786,19 @@ var ot = [], st = () => {}, ct = t => {
783
786
  };
784
787
  }
785
788
  };
786
- return D.exec(rt), D;
789
+ return R.exec(ot), R;
787
790
  };
788
791
 
789
- function lt(t, e) {
792
+ function at(t, e) {
790
793
  const n = e && e.voidToString;
791
794
  t.hook("copy", e => {
792
- e.setData("text/plain", b(t.doc, ...T(t.selection), n));
795
+ e.setData("text/plain", v(t.doc, ...E(t.selection), n));
793
796
  }), t.hook("paste", t => t.getData("text/plain"));
794
797
  }
795
798
 
796
- var at = "application/x-editate-editor";
799
+ var ft = "application/x-editate-editor";
797
800
 
798
- function ft(t) {
801
+ function ut(t) {
799
802
  t.hook("mount", t => {
800
803
  t.ariaMultiLine = null;
801
804
  }), t.hook("apply", (t, e) => {
@@ -806,19 +809,19 @@ function ft(t) {
806
809
  const e = t.fragment;
807
810
  t = {
808
811
  ...t,
809
- fragment: a(e) ? [ X(...e) ] : e
812
+ fragment: a(e) ? [ Y(...e) ] : e
810
813
  };
811
814
  }
812
815
  e(t);
813
816
  });
814
817
  }
815
818
 
816
- exports.Delete = function(t, e = T(t.selection)) {
819
+ exports.Delete = function(t, e = E(t.selection)) {
817
820
  t.apply({
818
821
  type: "delete",
819
822
  range: e
820
823
  });
821
- }, exports.Format = function(t, e, n, r = T(t.selection)) {
824
+ }, exports.Format = function(t, e, n, r = E(t.selection)) {
822
825
  t.apply({
823
826
  type: "format",
824
827
  range: r,
@@ -839,11 +842,11 @@ exports.Delete = function(t, e = T(t.selection)) {
839
842
  at: n,
840
843
  text: e
841
844
  });
842
- }, exports.LeavesInRange = S, exports.Redo = function(t) {
843
- t.get(rt).redo();
845
+ }, exports.LeavesInRange = w, exports.Redo = function(t) {
846
+ t.get(ot).redo();
844
847
  }, exports.Redoable = function(t) {
845
- return t.get(rt).redoable();
846
- }, exports.ReplaceDoc = w, exports.ReplaceText = function(t, e, n = T(t.selection)) {
848
+ return t.get(ot).redoable();
849
+ }, exports.ReplaceDoc = A, exports.ReplaceText = function(t, e, n = E(t.selection)) {
847
850
  t.apply({
848
851
  type: "delete",
849
852
  range: n
@@ -876,9 +879,9 @@ exports.Delete = function(t, e = T(t.selection)) {
876
879
  key: e,
877
880
  value: s[e] === n ? r : n
878
881
  });
879
- }, exports.ToggleFormat = function(t, e, n = T(t.selection)) {
882
+ }, exports.ToggleFormat = function(t, e, n = E(t.selection)) {
880
883
  let r = !1, o = !1;
881
- for (const s of t.exec(S, n)) if (i(s) && (o = !0, !s[e])) {
884
+ for (const s of t.exec(w, n)) if (i(s) && (o = !0, !s[e])) {
882
885
  r = !0;
883
886
  break;
884
887
  }
@@ -889,18 +892,18 @@ exports.Delete = function(t, e = T(t.selection)) {
889
892
  value: r
890
893
  });
891
894
  }, exports.Undo = function(t) {
892
- t.get(rt).undo();
895
+ t.get(ot).undo();
893
896
  }, exports.Undoable = function(t) {
894
- return t.get(rt).undoable();
895
- }, exports.createEditor = it, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
896
- const o = it({
897
+ return t.get(ot).undoable();
898
+ }, exports.createEditor = lt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
899
+ const o = lt({
897
900
  ...r,
898
901
  doc: {
899
- children: W(t)
902
+ children: q(t)
900
903
  }
901
- }).exec(lt);
902
- return e && o.exec(ft), o.on("change", () => {
903
- n(b(o.doc));
904
+ }).exec(at);
905
+ return e && o.exec(ut), o.on("change", () => {
906
+ n(v(o.doc));
904
907
  }), o;
905
908
  }, exports.debugPlugin = function(t) {
906
909
  t.hook("apply", t => {
@@ -923,12 +926,12 @@ exports.Delete = function(t, e = T(t.selection)) {
923
926
  }
924
927
  return null;
925
928
  });
926
- }, exports.getBlockAt = x, exports.getChildAt = d, exports.getLeafAt = y, exports.getNodeSize = p,
929
+ }, exports.getChildAt = d, exports.getLeafAt = y, exports.getLeafBlockAt = x, exports.getNodeSize = p,
927
930
  exports.htmlTransferPlugin = function(t, e) {
928
931
  t.hook("mount", (n, r) => {
929
932
  const o = t.hook("copy", t => {
930
933
  const e = document.createElement("div");
931
- e.appendChild(L(N(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
934
+ e.appendChild(C(L(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
932
935
  }), s = t.hook("paste", t => {
933
936
  const n = t.getData("text/html");
934
937
  return n ? ((t, e, n) => {
@@ -940,7 +943,7 @@ exports.htmlTransferPlugin = function(t, e) {
940
943
  }
941
944
  };
942
945
  let s = (new DOMParser).parseFromString(t, "text/html").body, c = !1;
943
- for (const i of [ ...s.childNodes ]) O(i) ? "StartFragment" === i.data ? (c = !0,
946
+ for (const i of [ ...s.childNodes ]) R(i) ? "StartFragment" === i.data ? (c = !0,
944
947
  s = new DocumentFragment) : "EndFragment" === i.data && (c = !1) : c && s.appendChild(i);
945
948
  return e(({t, i: e}) => {
946
949
  let n, s = null, c = "", i = !1;
@@ -968,27 +971,32 @@ exports.htmlTransferPlugin = function(t, e) {
968
971
  });
969
972
  }, exports.internalTranferPlugin = function(t) {
970
973
  t.hook("copy", e => {
971
- e.setData(at, JSON.stringify(v(t.doc, ...T(t.selection))));
974
+ e.setData(ft, JSON.stringify(T(t.doc, ...E(t.selection))));
972
975
  }), t.hook("paste", t => {
973
976
  try {
974
- return JSON.parse(t.getData(at));
977
+ return JSON.parse(t.getData(ft));
975
978
  } catch (e) {
976
979
  return null;
977
980
  }
978
981
  });
979
- }, exports.iterLeaves = _, exports.keymapPlugin = function(t, e) {
982
+ }, exports.iterLeafBlocks = function* t(e, n) {
983
+ if (!l(e) || a(e.children)) for (const r of _(e, n)) {
984
+ const [e, n] = r;
985
+ for (const r of t(e, [ 0, p(e) ])) r[1] += n, yield r;
986
+ } else yield [ e, 0 ];
987
+ }, exports.iterLeaves = b, exports.keymapPlugin = function(t, e) {
980
988
  n(e).forEach(n => {
981
989
  const r = e[n];
982
- t.hook("keyboard", nt(n, r));
990
+ t.hook("keyboard", rt(n, r));
983
991
  });
984
- }, exports.plainTransferPlugin = lt, exports.selectionRectPlugin = function(t, e) {
992
+ }, exports.plainTransferPlugin = at, exports.selectionRectPlugin = function(t, e) {
985
993
  t.hook("mount", (n, r) => {
986
994
  let o = !0, s = !1;
987
995
  const c = t.on("selectionchange", () => {
988
996
  s || (s = !0, requestAnimationFrame(() => {
989
997
  s = !1, o && e(() => {
990
998
  const e = t.selection;
991
- return C(n, r, t.doc, e).getBoundingClientRect();
999
+ return H(n, r, t.doc, e).getBoundingClientRect();
992
1000
  });
993
1001
  }));
994
1002
  });
@@ -996,5 +1004,5 @@ exports.htmlTransferPlugin = function(t, e) {
996
1004
  o = !1, c();
997
1005
  };
998
1006
  });
999
- }, exports.singlelinePlugin = ft, exports.sliceText = b;
1007
+ }, exports.singlelinePlugin = ut, exports.sliceText = v;
1000
1008
  //# sourceMappingURL=index.cjs.map