editate 0.7.1 → 0.7.2
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 +122 -95
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +241 -212
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/restoreSelection.d.ts +5 -0
- package/lib/plugins/transfer/htmlTransfer.d.ts +2 -0
- package/lib/plugins/transfer/internalTransfer.d.ts +2 -0
- package/package.json +2 -1
package/lib/index.cjs
CHANGED
|
@@ -121,13 +121,13 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
121
121
|
}
|
|
122
122
|
for (let i = t(r, u(e)) - c; i > 0; i--) s += "\n";
|
|
123
123
|
return s;
|
|
124
|
-
}, T = (t, e, n) => e >= n ? [] : h(h(t, n)[0], e)[1].children,
|
|
124
|
+
}, T = (t, e, n) => e >= n ? [] : h(h(t, n)[0], e)[1].children, M = ([t, e]) => t > e ? [ e, t ] : [ t, e ], E = ([t, e]) => t === e, S = ([t, e], n) => n ? t < e : t <= e, A = (t, e, n) => t.split("\n").map(t => ({
|
|
125
125
|
...n,
|
|
126
126
|
children: [ {
|
|
127
127
|
...e,
|
|
128
128
|
text: t
|
|
129
129
|
} ]
|
|
130
|
-
})), O = "delete", R = "insert_text",
|
|
130
|
+
})), O = "delete", R = "insert_text", L = "insert_node", B = "format", D = ({type: t}) => t !== R && t !== O, I = (t, e) => {
|
|
131
131
|
const o = n(t);
|
|
132
132
|
return o.length === n(e).length && o.every(n => n in e && ("text" === n || r(t[n], e[n])));
|
|
133
133
|
}, P = t => {
|
|
@@ -136,7 +136,7 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
136
136
|
for (let r of t) {
|
|
137
137
|
if (i(r)) {
|
|
138
138
|
if (!r.text) continue;
|
|
139
|
-
n && i(n) &&
|
|
139
|
+
n && i(n) && I(n, r) && (r = {
|
|
140
140
|
...n,
|
|
141
141
|
text: n.text + r.text
|
|
142
142
|
}, e.pop());
|
|
@@ -144,23 +144,23 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
144
144
|
e.push(n = r);
|
|
145
145
|
}
|
|
146
146
|
return e.length ? e : t.slice(-1);
|
|
147
|
-
},
|
|
147
|
+
}, H = (t, e) => {
|
|
148
148
|
const n = t.length - 1, r = t.concat(e);
|
|
149
149
|
if (n >= 0 && e.length) {
|
|
150
150
|
const e = l(r[n]);
|
|
151
151
|
if (e === l(r[n + 1])) {
|
|
152
152
|
if (!e) return t.slice(0, n).concat(P(r.slice(n)));
|
|
153
|
-
r.splice(n, 2,
|
|
153
|
+
r.splice(n, 2, N(r.slice(n, n + 2)));
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
return r.length || r.push({
|
|
157
157
|
text: ""
|
|
158
158
|
}), r;
|
|
159
|
-
},
|
|
159
|
+
}, N = t => ({
|
|
160
160
|
...t[0],
|
|
161
|
-
children: t.reduce((t, e) =>
|
|
162
|
-
}),
|
|
163
|
-
const o =
|
|
161
|
+
children: t.reduce((t, e) => H(t, e.children), [])
|
|
162
|
+
}), W = (t, {range: e, depth: n = -1}, r) => {
|
|
163
|
+
const o = E(e), s = (t, e) => n < 0 ? !!(t & 1 << -n - 1) : n === e, c = (t, e, n, a) => {
|
|
164
164
|
let f = 0, p = !1, d = 0, y = 0;
|
|
165
165
|
const x = [];
|
|
166
166
|
for (const [g, m, k, b] of v(t, e)) {
|
|
@@ -198,11 +198,11 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
198
198
|
return c(t, e, 0, 0)[0];
|
|
199
199
|
}, C = (t, e, n, r) => {
|
|
200
200
|
const o = !r.length, [s, c] = h(t, e, o), i = e < n ? h(t, n, o)[1] : c, l = a(r);
|
|
201
|
-
return l !== a(t.children) && (r = l ?
|
|
201
|
+
return l !== a(t.children) && (r = l ? N(r).children : [ {
|
|
202
202
|
children: r
|
|
203
203
|
} ]), {
|
|
204
204
|
...t,
|
|
205
|
-
children:
|
|
205
|
+
children: H(H(s.children, r), i.children)
|
|
206
206
|
};
|
|
207
207
|
}, F = (t, e) => e >= 0 && e <= u(t), U = (t, e) => e.reduce((t, e) => q(t, e), t), q = (t, e, n) => {
|
|
208
208
|
switch (e.type) {
|
|
@@ -214,7 +214,7 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
case R:
|
|
217
|
-
case
|
|
217
|
+
case L:
|
|
218
218
|
{
|
|
219
219
|
const {at: r} = e;
|
|
220
220
|
if (n ? t > r : t >= r) return t + (e.type === R ? e.text.length : u({
|
|
@@ -243,7 +243,7 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
243
243
|
break;
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
case
|
|
246
|
+
case L:
|
|
247
247
|
{
|
|
248
248
|
const {at: r, fragment: o} = n;
|
|
249
249
|
F(t, r) && o.length && (t = C(t, r, r, o), e = z(e, n));
|
|
@@ -253,7 +253,7 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
253
253
|
case B:
|
|
254
254
|
{
|
|
255
255
|
const {range: e, key: r, value: o, depth: s} = n;
|
|
256
|
-
"text" !== r && ("children" !== r || 0 === s) && V(t, e) && e[0] <= e[1] && (t =
|
|
256
|
+
"text" !== r && ("children" !== r || 0 === s) && V(t, e) && e[0] <= e[1] && (t = W(t, n, t => {
|
|
257
257
|
if (void 0 !== o) return {
|
|
258
258
|
...t,
|
|
259
259
|
[r]: o
|
|
@@ -271,21 +271,21 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
271
271
|
{
|
|
272
272
|
const {range: n} = e;
|
|
273
273
|
return [ {
|
|
274
|
-
type:
|
|
274
|
+
type: L,
|
|
275
275
|
at: n[0],
|
|
276
276
|
fragment: T(t, ...n)
|
|
277
277
|
} ];
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
case R:
|
|
281
|
-
case
|
|
281
|
+
case L:
|
|
282
282
|
{
|
|
283
283
|
const {at: n} = e, r = [ {
|
|
284
284
|
type: O,
|
|
285
285
|
range: [ n, q(n, e) ]
|
|
286
286
|
} ], [o] = d(t, n);
|
|
287
287
|
return u(o) || r.push({
|
|
288
|
-
type:
|
|
288
|
+
type: L,
|
|
289
289
|
at: n,
|
|
290
290
|
fragment: o.children
|
|
291
291
|
}), r;
|
|
@@ -295,7 +295,7 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
295
295
|
{
|
|
296
296
|
const {key: n} = e, o = [];
|
|
297
297
|
let s;
|
|
298
|
-
return
|
|
298
|
+
return W(t, e, (t, e, c) => {
|
|
299
299
|
const i = t[n];
|
|
300
300
|
return s && s.depth === e && r(s.value, i) && c[0] - s.range[1] <= 1 && (c = [ s.range[0], c[1] ],
|
|
301
301
|
o.pop()), s = {
|
|
@@ -313,16 +313,16 @@ var w = (e, n = 0, r = 1 / 0, o) => {
|
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
-
function* j(t, e =
|
|
317
|
-
if (
|
|
316
|
+
function* j(t, e = M(t.selection)) {
|
|
317
|
+
if (E(e)) {
|
|
318
318
|
const n = y(t.doc, e[0])?.[0];
|
|
319
319
|
n && (yield n);
|
|
320
320
|
} else for (const [n, , r] of _(t.doc, e)) S(r, u(n)) && (yield n);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
function* X(t, e =
|
|
323
|
+
function* X(t, e = M(t.selection)) {
|
|
324
324
|
const n = t.doc;
|
|
325
|
-
if (
|
|
325
|
+
if (E(e)) {
|
|
326
326
|
const [t, r] = d(n, e[0]);
|
|
327
327
|
yield [ t, e[0] - r, [ r, r ] ];
|
|
328
328
|
} else for (const r of b(n, e)) S(r[2], u(r[0])) && (yield r);
|
|
@@ -342,7 +342,7 @@ var Z = t => 1 === t.nodeType, K = t => 8 === t.nodeType, Q = new Map([ [ "BR",
|
|
|
342
342
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
343
343
|
}
|
|
344
344
|
}, st = (t, e, n, r) => {
|
|
345
|
-
const [o, s] = ((t, [e, n]) => [ m(t, e), m(t, n) ])(n, r), c = nt(t), i =
|
|
345
|
+
const [o, s] = ((t, [e, n]) => [ m(t, e), m(t, n) ])(n, r), c = nt(t), i = E(r), l = r[0] - r[1] > 0, a = l ? o : s, f = it(t, e, l ? s : o), u = i ? f : it(t, e, a), p = c.createRange(), [d, y] = f, [x, h] = u;
|
|
346
346
|
return Z(d) && t !== d ? y < 1 ? p.setStartBefore(d) : p.setStartAfter(d) : p.setStart(d, y),
|
|
347
347
|
Z(x) && t !== x ? h < 1 ? p.setEndBefore(x) : p.setEndAfter(x) : p.setEnd(x, h),
|
|
348
348
|
p;
|
|
@@ -460,9 +460,9 @@ function pt(t) {
|
|
|
460
460
|
});
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
var dt = [],
|
|
463
|
+
var dt, yt = [], xt = () => {}, ht = t => {
|
|
464
464
|
throw Error(t);
|
|
465
|
-
},
|
|
465
|
+
}, gt = ({doc: t, readonly: e = !1, schema: n, isBlock: r = tt, onWarn: i = console.warn, onError: l = ht}) => {
|
|
466
466
|
let a = [ 0, 0 ];
|
|
467
467
|
const f = t => {
|
|
468
468
|
if (!n) return i("An unsafe operation was detected. We recommend using schema option."),
|
|
@@ -475,7 +475,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
475
475
|
return !1;
|
|
476
476
|
};
|
|
477
477
|
n && !f(t) && l("Invalid document");
|
|
478
|
-
const u = new Map, p = new WeakMap, d = t => u.get(t) ||
|
|
478
|
+
const u = new Map, p = new WeakMap, d = t => u.get(t) || yt, y = new Map;
|
|
479
479
|
let x = new Set;
|
|
480
480
|
const h = t => {
|
|
481
481
|
const e = y.get(t);
|
|
@@ -503,7 +503,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
503
503
|
n++;
|
|
504
504
|
try {
|
|
505
505
|
const [e, n] = G(t, a, s);
|
|
506
|
-
t = e, v(n), c = s,
|
|
506
|
+
t = e, v(n), c = s, D(s) && (o = !0);
|
|
507
507
|
} catch (l) {
|
|
508
508
|
i("rollback operation: " + l);
|
|
509
509
|
}
|
|
@@ -558,7 +558,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
558
558
|
set: (t, e) => (p.set(t, e), b),
|
|
559
559
|
input: n => {
|
|
560
560
|
if (!window.InputEvent || !s(InputEvent.prototype.getTargetRanges)) return i("beforeinput event is not supported."),
|
|
561
|
-
|
|
561
|
+
xt;
|
|
562
562
|
const {contentEditable: c, role: l, ariaMultiLine: f, ariaReadOnly: u} = n, p = n.style.whiteSpace;
|
|
563
563
|
n.role = "textbox", n.style.whiteSpace = "pre-wrap", n.ariaMultiLine = "true";
|
|
564
564
|
let y = !1, x = null, h = !1, _ = !1, w = !1, T = a, S = null;
|
|
@@ -640,19 +640,19 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
640
640
|
n.contentEditable = e ? "false" : "true", n.ariaReadOnly = e ? "true" : null;
|
|
641
641
|
};
|
|
642
642
|
R();
|
|
643
|
-
const
|
|
643
|
+
const L = () => {
|
|
644
644
|
_ || (ct(n, O, t, a, !0), T = a, n.focus({
|
|
645
645
|
preventScroll: !0
|
|
646
646
|
}));
|
|
647
647
|
}, B = () => {
|
|
648
648
|
S = null, a[0] === T[0] && a[1] === T[1] || (ct(n, O, t, a), T = a);
|
|
649
|
-
},
|
|
649
|
+
}, D = () => {
|
|
650
650
|
null != S && clearTimeout(S);
|
|
651
|
-
},
|
|
652
|
-
_ || requestAnimationFrame(
|
|
651
|
+
}, I = b.on("change", () => {
|
|
652
|
+
_ || requestAnimationFrame(L);
|
|
653
653
|
}), P = b.on("selectionchange", () => {
|
|
654
|
-
a[0] === T[0] && a[1] === T[1] || (
|
|
655
|
-
}),
|
|
654
|
+
a[0] === T[0] && a[1] === T[1] || (D(), S = setTimeout(B, 50));
|
|
655
|
+
}), H = b.on("readonly", R), N = t => {
|
|
656
656
|
for (const e of d("paste")) {
|
|
657
657
|
const n = e(t);
|
|
658
658
|
if (n) {
|
|
@@ -661,7 +661,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
i("failed to serialize pasted data");
|
|
664
|
-
},
|
|
664
|
+
}, W = ((t, e) => {
|
|
665
665
|
let n = !1, r = [];
|
|
666
666
|
const o = t => {
|
|
667
667
|
n && r.push(...t);
|
|
@@ -698,7 +698,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
698
698
|
}
|
|
699
699
|
};
|
|
700
700
|
})(n, () => {
|
|
701
|
-
|
|
701
|
+
D(), ct(n, O, t, a);
|
|
702
702
|
}), C = () => {
|
|
703
703
|
v(T = k(t, ((t, e) => {
|
|
704
704
|
const n = rt(t), r = ot(n, t);
|
|
@@ -707,11 +707,11 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
707
707
|
return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
|
|
708
708
|
})(n, O)));
|
|
709
709
|
}, F = () => {
|
|
710
|
-
const e =
|
|
711
|
-
|
|
710
|
+
const e = W._();
|
|
711
|
+
W.v(!1), e.length && (W.k(e), A.removeEventListener("selectionchange", Y), ct(n, O, t, a, !0),
|
|
712
712
|
A.addEventListener("selectionchange", Y)), x && (v(x[1]), m(x[0]), x = null), h = !1;
|
|
713
713
|
}, q = t => {
|
|
714
|
-
if (!h) for (const e of d("keyboard")) if (e(t)) return t.preventDefault(), void
|
|
714
|
+
if (!h) for (const e of d("keyboard")) if (e(t)) return t.preventDefault(), void W.v(!1);
|
|
715
715
|
}, z = () => {
|
|
716
716
|
h || F();
|
|
717
717
|
}, V = e => {
|
|
@@ -719,7 +719,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
719
719
|
const r = e.inputType;
|
|
720
720
|
if (r.startsWith("format")) return;
|
|
721
721
|
if ("historyUndo" === r || "historyRedo" === r) return;
|
|
722
|
-
h ?
|
|
722
|
+
h ? W.v(!0) : C();
|
|
723
723
|
const o = e.getTargetRanges()[0];
|
|
724
724
|
if (o) {
|
|
725
725
|
let s = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : e.data;
|
|
@@ -729,7 +729,7 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
729
729
|
}
|
|
730
730
|
x || (x = [ [], a ]);
|
|
731
731
|
const c = x[0], i = k(t, at(n, O, o));
|
|
732
|
-
|
|
732
|
+
E(i) || c.push({
|
|
733
733
|
type: "delete",
|
|
734
734
|
range: i
|
|
735
735
|
}), s && c.push({
|
|
@@ -750,19 +750,19 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
750
750
|
}, Y = () => {
|
|
751
751
|
!_ || h || w || C();
|
|
752
752
|
}, K = t => {
|
|
753
|
-
if (C(), !
|
|
753
|
+
if (C(), !E(a)) for (const e of d("copy")) e(t);
|
|
754
754
|
}, $ = t => {
|
|
755
755
|
t.preventDefault(), K(t.clipboardData);
|
|
756
756
|
}, tt = t => {
|
|
757
757
|
t.preventDefault(), e || (K(t.clipboardData), m({
|
|
758
758
|
type: "delete",
|
|
759
|
-
range:
|
|
759
|
+
range: M(a)
|
|
760
760
|
}));
|
|
761
761
|
}, st = t => {
|
|
762
762
|
t.preventDefault();
|
|
763
|
-
const e =
|
|
763
|
+
const e = N(t.clipboardData);
|
|
764
764
|
if (e) {
|
|
765
|
-
const t =
|
|
765
|
+
const t = M(a), n = t[0], r = [ {
|
|
766
766
|
type: "delete",
|
|
767
767
|
range: t
|
|
768
768
|
} ];
|
|
@@ -793,9 +793,9 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
793
793
|
const n = [];
|
|
794
794
|
w && n.push({
|
|
795
795
|
type: "delete",
|
|
796
|
-
range:
|
|
796
|
+
range: M(a)
|
|
797
797
|
});
|
|
798
|
-
const c =
|
|
798
|
+
const c = N(r);
|
|
799
799
|
if (c) {
|
|
800
800
|
const r = g(t, s), i = U(r, n);
|
|
801
801
|
n.push(o(c) ? {
|
|
@@ -826,8 +826,8 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
826
826
|
const e = t(n, O);
|
|
827
827
|
e && pt.push(e);
|
|
828
828
|
}), () => {
|
|
829
|
-
y || (y = !0,
|
|
830
|
-
n.ariaReadOnly = u, n.style.whiteSpace = p,
|
|
829
|
+
y || (y = !0, I(), P(), H(), n.contentEditable = c, n.role = l, n.ariaMultiLine = f,
|
|
830
|
+
n.ariaReadOnly = u, n.style.whiteSpace = p, W.T(), A.removeEventListener("selectionchange", Y),
|
|
831
831
|
n.removeEventListener("keydown", q), n.removeEventListener("input", z), n.removeEventListener("beforeinput", V),
|
|
832
832
|
n.removeEventListener("compositionstart", G), n.removeEventListener("compositionend", J),
|
|
833
833
|
n.removeEventListener("focus", j), n.removeEventListener("blur", X), n.removeEventListener("copy", $),
|
|
@@ -841,40 +841,40 @@ var dt = [], yt = () => {}, xt = t => {
|
|
|
841
841
|
return b.exec(pt), b;
|
|
842
842
|
};
|
|
843
843
|
|
|
844
|
-
function
|
|
844
|
+
function mt(t, e) {
|
|
845
845
|
const n = e && e.voidToString;
|
|
846
846
|
t.hook("copy", e => {
|
|
847
|
-
e.setData("text/plain", w(t.doc, ...
|
|
847
|
+
e.setData("text/plain", w(t.doc, ...M(t.selection), n));
|
|
848
848
|
}), t.hook("paste", t => t.getData("text/plain"));
|
|
849
849
|
}
|
|
850
850
|
|
|
851
|
-
function
|
|
851
|
+
function kt(t, e) {
|
|
852
852
|
const n = e.isLocked, r = e => {
|
|
853
853
|
for (const [r] of b(t.doc, e)) if (n(r)) return !0;
|
|
854
854
|
return !1;
|
|
855
855
|
};
|
|
856
856
|
t.hook("apply", (e, o) => {
|
|
857
857
|
o((e => {
|
|
858
|
-
if ("format" !== e.type) return r("delete" === e.type ?
|
|
859
|
-
const o = t.doc, s = 0 === e.depth ? [ 0, u(o) ] :
|
|
858
|
+
if ("format" !== e.type) return r("delete" === e.type ? M(e.range) : [ e.at, e.at ]);
|
|
859
|
+
const o = t.doc, s = 0 === e.depth ? [ 0, u(o) ] : M(e.range), c = b(G(o, t.selection, e)[0], s);
|
|
860
860
|
for (const [t] of b(o, s)) {
|
|
861
861
|
const e = c.next().value?.[0];
|
|
862
862
|
if (e && t !== e && n(t) && n(e)) return !0;
|
|
863
863
|
}
|
|
864
864
|
return !1;
|
|
865
865
|
})(e) ? null : e);
|
|
866
|
-
}), t.set(
|
|
866
|
+
}), t.set(kt, {
|
|
867
867
|
locked: r
|
|
868
868
|
});
|
|
869
869
|
}
|
|
870
870
|
|
|
871
|
-
var
|
|
871
|
+
var vt = (t, e) => {
|
|
872
872
|
const n = parseFloat(t);
|
|
873
873
|
return n ? t.endsWith("%") ? n / 100 * e : n : 0;
|
|
874
|
-
},
|
|
874
|
+
}, bt = (t, e, n, r) => [ t + vt(n, e), t + e - vt(r, e) ], _t = t => "auto" === t || "scroll" === t || "overlay" === t, wt = (t, e, [n, r]) => t < n ? t - n : e > r ? e - r : 0, Tt = (n, r, o, s) => {
|
|
875
875
|
const c = s ? -o : 0;
|
|
876
876
|
return e(c - r, t(n, c + o - r));
|
|
877
|
-
},
|
|
877
|
+
}, Mt = (t, e, n) => {
|
|
878
878
|
(n || e) && t.scrollBy({
|
|
879
879
|
top: n,
|
|
880
880
|
left: e,
|
|
@@ -886,7 +886,7 @@ var kt = (t, e) => {
|
|
|
886
886
|
return r;
|
|
887
887
|
};
|
|
888
888
|
|
|
889
|
-
function
|
|
889
|
+
function St(t) {
|
|
890
890
|
let e = 0, n = t.doc;
|
|
891
891
|
const r = new WeakMap, o = (t, e) => {
|
|
892
892
|
if (t === e) return;
|
|
@@ -901,7 +901,7 @@ function Mt(t) {
|
|
|
901
901
|
null != y && (r.delete(p), r.set(d, y)), l(p) && l(d) && o(p.children, d.children);
|
|
902
902
|
}
|
|
903
903
|
};
|
|
904
|
-
t.set(
|
|
904
|
+
t.set(St, {
|
|
905
905
|
id: s => {
|
|
906
906
|
const c = t.doc;
|
|
907
907
|
if (c !== n) {
|
|
@@ -914,7 +914,7 @@ function Mt(t) {
|
|
|
914
914
|
});
|
|
915
915
|
}
|
|
916
916
|
|
|
917
|
-
function
|
|
917
|
+
function At(t) {
|
|
918
918
|
t.hook("mount", t => {
|
|
919
919
|
t.ariaMultiLine = null;
|
|
920
920
|
}), t.hook("apply", (t, e) => {
|
|
@@ -925,7 +925,7 @@ function St(t) {
|
|
|
925
925
|
const e = t.fragment;
|
|
926
926
|
t = {
|
|
927
927
|
...t,
|
|
928
|
-
fragment: a(e) ? [
|
|
928
|
+
fragment: a(e) ? [ N(e) ] : e
|
|
929
929
|
};
|
|
930
930
|
}
|
|
931
931
|
e(t);
|
|
@@ -935,12 +935,12 @@ function St(t) {
|
|
|
935
935
|
exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
936
936
|
const {stack: e} = t.get(pt);
|
|
937
937
|
e().length = 0, e(!0).length = 0;
|
|
938
|
-
}, exports.Delete = function(t, e =
|
|
938
|
+
}, exports.Delete = function(t, e = M(t.selection)) {
|
|
939
939
|
t.apply({
|
|
940
940
|
type: "delete",
|
|
941
941
|
range: e
|
|
942
942
|
});
|
|
943
|
-
}, exports.Format = function(t, e, n, r =
|
|
943
|
+
}, exports.Format = function(t, e, n, r = M(t.selection)) {
|
|
944
944
|
for (const o of Y(t, r)) t.apply({
|
|
945
945
|
type: "format",
|
|
946
946
|
range: o,
|
|
@@ -961,10 +961,10 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
961
961
|
at: n,
|
|
962
962
|
text: e
|
|
963
963
|
});
|
|
964
|
-
}, exports.LeavesInRange = j, exports.LockedInRange = function(t, e =
|
|
965
|
-
return t.get(
|
|
964
|
+
}, exports.LeavesInRange = j, exports.LockedInRange = function(t, e = M(t.selection)) {
|
|
965
|
+
return t.get(kt).locked(e);
|
|
966
966
|
}, exports.NodeId = function(t, e) {
|
|
967
|
-
return t.get(
|
|
967
|
+
return t.get(St).id(e);
|
|
968
968
|
}, exports.Redo = function(t) {
|
|
969
969
|
t.get(pt).redo();
|
|
970
970
|
}, exports.Redoable = function(t) {
|
|
@@ -977,7 +977,7 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
977
977
|
value: e,
|
|
978
978
|
depth: 0
|
|
979
979
|
});
|
|
980
|
-
}, exports.ReplaceText = function(t, e, n =
|
|
980
|
+
}, exports.ReplaceText = function(t, e, n = M(t.selection)) {
|
|
981
981
|
t.apply([ {
|
|
982
982
|
type: "delete",
|
|
983
983
|
range: n
|
|
@@ -986,7 +986,7 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
986
986
|
at: n[0],
|
|
987
987
|
text: e
|
|
988
988
|
} ]);
|
|
989
|
-
}, exports.SetBlockAttr = function(t, e, n, r =
|
|
989
|
+
}, exports.SetBlockAttr = function(t, e, n, r = M(t.selection)) {
|
|
990
990
|
t.apply({
|
|
991
991
|
type: "format",
|
|
992
992
|
range: r,
|
|
@@ -1005,7 +1005,7 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
1005
1005
|
value: n
|
|
1006
1006
|
});
|
|
1007
1007
|
}
|
|
1008
|
-
}, exports.ToggleBlockAttr = function(t, e, n, r, o =
|
|
1008
|
+
}, exports.ToggleBlockAttr = function(t, e, n, r, o = M(t.selection)) {
|
|
1009
1009
|
let s = !1;
|
|
1010
1010
|
for (const [c] of t.exec(X, o)) if (c[e] !== n) {
|
|
1011
1011
|
s = !0;
|
|
@@ -1018,7 +1018,7 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
1018
1018
|
value: s ? n : r,
|
|
1019
1019
|
depth: -2
|
|
1020
1020
|
});
|
|
1021
|
-
}, exports.ToggleFormat = function(t, e, n =
|
|
1021
|
+
}, exports.ToggleFormat = function(t, e, n = M(t.selection)) {
|
|
1022
1022
|
let r = !1, o = !1;
|
|
1023
1023
|
for (const s of t.exec(j, n)) if (i(s) && (o = !0, !s[e])) {
|
|
1024
1024
|
r = !0;
|
|
@@ -1034,14 +1034,14 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
1034
1034
|
t.get(pt).undo();
|
|
1035
1035
|
}, exports.Undoable = function(t) {
|
|
1036
1036
|
return !!t.get(pt).stack().length;
|
|
1037
|
-
}, exports.blockLockPlugin =
|
|
1038
|
-
const o =
|
|
1037
|
+
}, exports.blockLockPlugin = kt, exports.createEditor = gt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
1038
|
+
const o = gt({
|
|
1039
1039
|
...r,
|
|
1040
1040
|
doc: {
|
|
1041
1041
|
children: A(t)
|
|
1042
1042
|
}
|
|
1043
|
-
}).exec(
|
|
1044
|
-
return e && o.exec(
|
|
1043
|
+
}).exec(mt);
|
|
1044
|
+
return e && o.exec(At), o.on("change", () => {
|
|
1045
1045
|
n(w(o.doc));
|
|
1046
1046
|
}), o;
|
|
1047
1047
|
}, exports.debugPlugin = function(t) {
|
|
@@ -1056,16 +1056,15 @@ exports.BlocksInRange = X, exports.ClearHistory = function(t) {
|
|
|
1056
1056
|
});
|
|
1057
1057
|
}, exports.fileTransferPlugin = (t, e) => {
|
|
1058
1058
|
t.hook("paste", t => {
|
|
1059
|
-
|
|
1060
|
-
|
|
1059
|
+
const n = [];
|
|
1060
|
+
for (const r of t.items) if ("file" === r.kind) {
|
|
1061
|
+
const t = e[r.type];
|
|
1061
1062
|
if (t) {
|
|
1062
|
-
const e =
|
|
1063
|
-
|
|
1064
|
-
children: [ t(e) ]
|
|
1065
|
-
} ];
|
|
1063
|
+
const e = r.getAsFile();
|
|
1064
|
+
e && n.push(t(e));
|
|
1066
1065
|
}
|
|
1067
1066
|
}
|
|
1068
|
-
return null;
|
|
1067
|
+
return n.length ? n : null;
|
|
1069
1068
|
});
|
|
1070
1069
|
}, exports.getChildAt = p, exports.getLeafAt = y, exports.getLeafBlockAt = d, exports.getNodeOffset = x,
|
|
1071
1070
|
exports.getNodeSize = u, exports.htmlTransferPlugin = function(t, e) {
|
|
@@ -1087,9 +1086,20 @@ exports.getNodeSize = u, exports.htmlTransferPlugin = function(t, e) {
|
|
|
1087
1086
|
if (n) return n;
|
|
1088
1087
|
}
|
|
1089
1088
|
};
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1089
|
+
if (!dt) {
|
|
1090
|
+
const t = {
|
|
1091
|
+
createHTML: t => t
|
|
1092
|
+
};
|
|
1093
|
+
dt = t;
|
|
1094
|
+
try {
|
|
1095
|
+
const e = window.trustedTypes;
|
|
1096
|
+
e && (dt = e.createPolicy("editate", t));
|
|
1097
|
+
} catch {}
|
|
1098
|
+
}
|
|
1099
|
+
const s = (new DOMParser).parseFromString(dt.createHTML(t), "text/html");
|
|
1100
|
+
let c = s.body, i = !1;
|
|
1101
|
+
for (const l of [ ...c.childNodes ]) K(l) ? "StartFragment" === l.data ? (i = !0,
|
|
1102
|
+
c = s.createDocumentFragment()) : "EndFragment" === l.data && (i = !1) : i && c.appendChild(l);
|
|
1093
1103
|
return e(({t, i: e}) => {
|
|
1094
1104
|
let n, s = null, c = "", i = !1;
|
|
1095
1105
|
const l = [], a = () => {
|
|
@@ -1107,13 +1117,13 @@ exports.getNodeSize = u, exports.htmlTransferPlugin = function(t, e) {
|
|
|
1107
1117
|
return f(), l.length || l.push({
|
|
1108
1118
|
children: []
|
|
1109
1119
|
}), l;
|
|
1110
|
-
},
|
|
1120
|
+
}, c);
|
|
1111
1121
|
})(r, n[1], e.serializers) : null;
|
|
1112
1122
|
});
|
|
1113
1123
|
}, exports.internalTransferPlugin = function(t, e) {
|
|
1114
1124
|
const n = e && e.mime || "application/x-editate-editor";
|
|
1115
1125
|
t.hook("copy", e => {
|
|
1116
|
-
e.setData(n, JSON.stringify(T(t.doc, ...
|
|
1126
|
+
e.setData(n, JSON.stringify(T(t.doc, ...M(t.selection))));
|
|
1117
1127
|
}), t.hook("paste", t => {
|
|
1118
1128
|
try {
|
|
1119
1129
|
return JSON.parse(t.getData(n));
|
|
@@ -1126,14 +1136,31 @@ exports.getNodeSize = u, exports.htmlTransferPlugin = function(t, e) {
|
|
|
1126
1136
|
const r = e[n];
|
|
1127
1137
|
t.hook("keyboard", ut(n, r));
|
|
1128
1138
|
});
|
|
1129
|
-
}, exports.mapPosition = q, exports.nodeIdPlugin =
|
|
1130
|
-
exports.
|
|
1139
|
+
}, exports.mapPosition = q, exports.nodeIdPlugin = St, exports.plainTransferPlugin = mt,
|
|
1140
|
+
exports.restoreSelectionPlugin = function(t) {
|
|
1141
|
+
t.hook("mount", (e, n) => {
|
|
1142
|
+
let r = !1, o = 0, s = 0;
|
|
1143
|
+
const c = () => {
|
|
1144
|
+
r = !e.matches(":focus");
|
|
1145
|
+
}, i = () => {
|
|
1146
|
+
o = e.scrollTop, s = e.scrollLeft;
|
|
1147
|
+
}, l = () => {
|
|
1148
|
+
r || (ct(e, n, t.doc, t.selection, !0), e.scrollTop || e.scrollLeft || (e.scrollTop = o,
|
|
1149
|
+
e.scrollLeft = s)), r = !1;
|
|
1150
|
+
};
|
|
1151
|
+
return e.addEventListener("mousedown", c, !0), e.addEventListener("focus", l, !0),
|
|
1152
|
+
e.addEventListener("scroll", i), () => {
|
|
1153
|
+
e.removeEventListener("mousedown", c, !0), e.removeEventListener("focus", l, !0),
|
|
1154
|
+
e.removeEventListener("scroll", i);
|
|
1155
|
+
};
|
|
1156
|
+
});
|
|
1157
|
+
}, exports.scrollToSelectionPlugin = t => {
|
|
1131
1158
|
t.hook("mount", (e, n) => {
|
|
1132
1159
|
const r = nt(e), o = r.defaultView, {body: s, documentElement: c} = r;
|
|
1133
1160
|
let i, l;
|
|
1134
1161
|
for (let t = e; t && t !== s && t !== c; t = t.parentElement) {
|
|
1135
1162
|
const e = o.getComputedStyle(t);
|
|
1136
|
-
if (
|
|
1163
|
+
if (_t(e.overflowX) || _t(e.overflowY)) {
|
|
1137
1164
|
i = t, l = e;
|
|
1138
1165
|
break;
|
|
1139
1166
|
}
|
|
@@ -1166,11 +1193,11 @@ exports.scrollToSelectionPlugin = t => {
|
|
|
1166
1193
|
case "sideways-lr":
|
|
1167
1194
|
x = !1, h = !y;
|
|
1168
1195
|
}
|
|
1169
|
-
p = wt(
|
|
1170
|
-
u = wt(
|
|
1196
|
+
p = Tt(wt(s.top, s.bottom, bt(d.top + c, f, l.scrollPaddingTop, l.scrollPaddingBottom)), e, r - f, h),
|
|
1197
|
+
u = Tt(wt(s.left, s.right, bt(d.left + o, a, l.scrollPaddingLeft, l.scrollPaddingRight)), t, n - a, x);
|
|
1171
1198
|
}
|
|
1172
|
-
const {clientWidth: d, clientHeight: y} = c, x =
|
|
1173
|
-
i &&
|
|
1199
|
+
const {clientWidth: d, clientHeight: y} = c, x = wt(s.top - p, s.bottom - p, bt(0, y, a.scrollPaddingTop, a.scrollPaddingBottom)), h = wt(s.left - u, s.right - u, bt(0, d, a.scrollPaddingLeft, a.scrollPaddingRight));
|
|
1200
|
+
i && Mt(i, u, p), Mt(o, h, x);
|
|
1174
1201
|
}, 50));
|
|
1175
1202
|
});
|
|
1176
1203
|
return () => {
|
|
@@ -1189,5 +1216,5 @@ exports.scrollToSelectionPlugin = t => {
|
|
|
1189
1216
|
o = !1, c();
|
|
1190
1217
|
};
|
|
1191
1218
|
});
|
|
1192
|
-
}, exports.singlelinePlugin =
|
|
1219
|
+
}, exports.singlelinePlugin = At, exports.sliceText = w;
|
|
1193
1220
|
//# sourceMappingURL=index.cjs.map
|