editate 0.6.4 → 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 +25 -27
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +26 -28
- package/lib/index.js.map +1 -1
- package/lib/keyboard.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -29,10 +29,10 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
29
29
|
let r = 0;
|
|
30
30
|
for (const n of e) r += k(t, 0, n), 0 !== n && r++, t = t.children[n];
|
|
31
31
|
return r + n;
|
|
32
|
-
},
|
|
32
|
+
}, v = (t, e) => {
|
|
33
33
|
const n = A(t, e);
|
|
34
34
|
return [ n.t, n.o ];
|
|
35
|
-
},
|
|
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];
|
|
@@ -177,12 +177,10 @@ const t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
|
177
177
|
|
|
178
178
|
function V(t, e) {
|
|
179
179
|
t.apply({
|
|
180
|
-
type: "
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
|
@@ -362,7 +360,7 @@ function _t(t) {
|
|
|
362
360
|
|
|
363
361
|
const kt = [], bt = () => {}, mt = t => {
|
|
364
362
|
throw Error(t);
|
|
365
|
-
},
|
|
363
|
+
}, vt = ({doc: n, readonly: r = !1, schema: a, isBlock: x = ot, onWarn: g = console.warn, onError: _ = mt}) => {
|
|
366
364
|
let k = [ 0, 0 ];
|
|
367
365
|
const b = t => {
|
|
368
366
|
if (!a) return g("An unsafe operation was detected. We recommend using schema option."),
|
|
@@ -375,7 +373,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
375
373
|
return !1;
|
|
376
374
|
};
|
|
377
375
|
a && !b(n) && _("Invalid document");
|
|
378
|
-
const
|
|
376
|
+
const v = new Map, S = new WeakMap, E = t => v.get(t) || kt, O = new Map, D = [], I = t => {
|
|
379
377
|
const e = O.get(t);
|
|
380
378
|
e && (D.length || i(() => {
|
|
381
379
|
D.forEach(t => {
|
|
@@ -499,8 +497,8 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
499
497
|
};
|
|
500
498
|
},
|
|
501
499
|
hook: (t, e) => {
|
|
502
|
-
let n =
|
|
503
|
-
return n ||
|
|
500
|
+
let n = v.get(t);
|
|
501
|
+
return n || v.set(t, n = []), n.push(e), () => {
|
|
504
502
|
const t = n.indexOf(e);
|
|
505
503
|
-1 !== t && n.splice(t, 1);
|
|
506
504
|
};
|
|
@@ -517,7 +515,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
517
515
|
const {contentEditable: i, role: a, ariaMultiLine: l, ariaReadOnly: f} = o, u = o.style.whiteSpace;
|
|
518
516
|
o.role = "textbox", o.style.whiteSpace = "pre-wrap", o.ariaMultiLine = "true";
|
|
519
517
|
let d = !1, p = null, h = !1, y = !1, _ = !1;
|
|
520
|
-
const b = at(o),
|
|
518
|
+
const b = at(o), v = (t => {
|
|
521
519
|
const e = (n, r, o) => {
|
|
522
520
|
const s = q, c = G, i = F, a = U, l = W;
|
|
523
521
|
try {
|
|
@@ -544,7 +542,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
544
542
|
});
|
|
545
543
|
}), D = Y.on("readonly", S), P = t => {
|
|
546
544
|
for (const e of E("paste")) {
|
|
547
|
-
const n = e(t,
|
|
545
|
+
const n = e(t, v);
|
|
548
546
|
if (n) return n;
|
|
549
547
|
}
|
|
550
548
|
g("failed to serialize pasted data");
|
|
@@ -581,17 +579,17 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
581
579
|
}
|
|
582
580
|
};
|
|
583
581
|
})(o, () => {
|
|
584
|
-
dt(b, o, M(n, k), k[0] - k[1],
|
|
582
|
+
dt(b, o, M(n, k), k[0] - k[1], v);
|
|
585
583
|
}), I = () => {
|
|
586
|
-
J(
|
|
584
|
+
J(w(n, ((t, e) => {
|
|
587
585
|
const n = lt(t), r = ft(n, t);
|
|
588
586
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
589
587
|
const o = yt(t, e, r), s = it(n.anchorNode, n.focusNode);
|
|
590
588
|
return (0 === s ? n.anchorOffset > n.focusOffset : 2 & s) ? [ o[1], o[0] ] : o;
|
|
591
|
-
})(o,
|
|
589
|
+
})(o, v)));
|
|
592
590
|
}, C = () => {
|
|
593
591
|
const t = A.m();
|
|
594
|
-
A.k(!1), t.length && (A._(t), b.removeEventListener("selectionchange", z), dt(b, o, M(n, k), k[0] - k[1],
|
|
592
|
+
A.k(!1), t.length && (A._(t), b.removeEventListener("selectionchange", z), dt(b, o, M(n, k), k[0] - k[1], v, !0),
|
|
595
593
|
b.addEventListener("selectionchange", z)), p && (J(p[1]), B(p[0]), p = null), h = !1;
|
|
596
594
|
}, R = t => {
|
|
597
595
|
if (!h) for (const e of E("keyboard")) if (e(t)) return t.preventDefault(), void A.k(!1);
|
|
@@ -605,7 +603,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
605
603
|
h ? A.k(!0) : I();
|
|
606
604
|
const s = t.getTargetRanges()[0];
|
|
607
605
|
if (s) {
|
|
608
|
-
const c =
|
|
606
|
+
const c = w(n, yt(o, v, s));
|
|
609
607
|
let i, a = "insertParagraph" === r || "insertLineBreak" === r ? "\n" : t.data;
|
|
610
608
|
if (null == a) {
|
|
611
609
|
const e = t.dataTransfer;
|
|
@@ -668,7 +666,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
668
666
|
const s = t.caretRangeFromPoint(n, r);
|
|
669
667
|
if (s) return ht(e, s.startContainer, s.startOffset, o);
|
|
670
668
|
}
|
|
671
|
-
})(b, o, e,
|
|
669
|
+
})(b, o, e, v);
|
|
672
670
|
if (r && c) {
|
|
673
671
|
let e;
|
|
674
672
|
const o = [];
|
|
@@ -721,7 +719,7 @@ const kt = [], bt = () => {}, mt = t => {
|
|
|
721
719
|
return Y.exec(_t), Y;
|
|
722
720
|
};
|
|
723
721
|
|
|
724
|
-
function
|
|
722
|
+
function wt(e, n) {
|
|
725
723
|
const r = n && n.serializer;
|
|
726
724
|
e.hook("copy", n => {
|
|
727
725
|
n.setData("text/plain", a({
|
|
@@ -823,16 +821,16 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
823
821
|
t.get(_t).undo();
|
|
824
822
|
}, exports.Undoable = function(t) {
|
|
825
823
|
return t.get(_t).undoable();
|
|
826
|
-
}, exports.createEditor =
|
|
827
|
-
const o =
|
|
824
|
+
}, exports.createEditor = vt, exports.createPlainEditor = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
825
|
+
const o = vt({
|
|
828
826
|
...r,
|
|
829
827
|
doc: {
|
|
830
828
|
children: l(t)
|
|
831
829
|
}
|
|
832
|
-
}).exec(
|
|
833
|
-
return o.on("change", () => {
|
|
830
|
+
}).exec(wt);
|
|
831
|
+
return e && o.exec(St), o.on("change", () => {
|
|
834
832
|
n(a(o.doc));
|
|
835
|
-
}),
|
|
833
|
+
}), o;
|
|
836
834
|
}, exports.debugPlugin = function(t) {
|
|
837
835
|
t.hook("apply", t => {
|
|
838
836
|
console.log("apply", t);
|
|
@@ -911,5 +909,5 @@ exports.Delete = function(e, n = t(e.selection)) {
|
|
|
911
909
|
r();
|
|
912
910
|
}));
|
|
913
911
|
});
|
|
914
|
-
}, exports.plainTransferPlugin =
|
|
912
|
+
}, exports.plainTransferPlugin = wt, exports.singlelinePlugin = St;
|
|
915
913
|
//# sourceMappingURL=index.cjs.map
|