editate 0.6.8 → 0.6.10
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/commands.d.ts +5 -4
- package/lib/doc/node.d.ts +3 -0
- package/lib/doc/{edit.d.ts → operation.d.ts} +1 -3
- package/lib/doc/types-infer.d.ts +11 -0
- package/lib/doc/types.d.ts +0 -9
- package/lib/editor.d.ts +3 -3
- package/lib/index.cjs +628 -605
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +463 -440
- package/lib/index.js.map +1 -1
- package/lib/plugins/transfer/htmlTransfer.d.ts +2 -1
- package/lib/plugins/transfer/plainTransfer.d.ts +2 -1
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -1,188 +1,118 @@
|
|
|
1
|
-
var t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}, ""), l = (t, e, n) => t.split("\n").map(t => ({
|
|
7
|
-
...n,
|
|
8
|
-
children: [ {
|
|
9
|
-
...e,
|
|
10
|
-
text: t
|
|
11
|
-
} ]
|
|
12
|
-
})), f = "delete", u = "insert_text", d = "insert_node", p = "format", h = "set_node_attr", y = t => "text" in t, _ = t => "children" in t, k = (t, e) => {
|
|
13
|
-
const n = r(t);
|
|
14
|
-
return n.length === r(e).length && n.every(n => n in e && ("text" === n || o(t[n], e[n])));
|
|
15
|
-
}, g = /* @__PURE__ */ new WeakMap, x = ({children: t}, e = 0, n = t.length) => {
|
|
16
|
-
let r = 0, o = 0;
|
|
17
|
-
for (let c = e; c < n; c++) {
|
|
18
|
-
const e = t[c];
|
|
19
|
-
r += m(e), 0 !== o && _(e) && r++, o++;
|
|
1
|
+
var t = ([t, e]) => t > e ? [ e, t ] : [ t, e ], e = ([t, e]) => t === e, n = ([t, e], [n, r]) => t < r && n < e, r = t => "text" in t, o = t => "children" in t, c = /* @__PURE__ */ new WeakMap, s = ({children: t}, e = 0, n = t.length) => {
|
|
2
|
+
let r = 0, c = 0;
|
|
3
|
+
for (let s = e; s < n; s++) {
|
|
4
|
+
const e = t[s];
|
|
5
|
+
r += i(e), 0 !== c && o(e) && r++, c++;
|
|
20
6
|
}
|
|
21
7
|
return r;
|
|
22
|
-
},
|
|
23
|
-
if (
|
|
24
|
-
let e =
|
|
25
|
-
return null == e &&
|
|
8
|
+
}, i = t => {
|
|
9
|
+
if (o(t)) {
|
|
10
|
+
let e = c.get(t);
|
|
11
|
+
return null == e && c.set(t, e = s(t)), e;
|
|
26
12
|
}
|
|
27
|
-
return
|
|
28
|
-
},
|
|
29
|
-
let r = 0;
|
|
30
|
-
for (const o of e) r += x(t, 0, o), 0 !== o && r++, t = t.children[o];
|
|
31
|
-
return r + n;
|
|
32
|
-
}, v = (t, e) => {
|
|
33
|
-
const n = R(t, e);
|
|
34
|
-
return [ n.t, n.o ];
|
|
35
|
-
}, E = (t, [e, n]) => [ b(t, e), b(t, n) ], T = (t, [e, n]) => [ v(t, e), v(t, n) ], M = (t, e = 0, n = t.length - 1) => {
|
|
36
|
-
let r = e + 1;
|
|
37
|
-
for (;r <= n; ) {
|
|
38
|
-
const e = t[r - 1], o = t[r];
|
|
39
|
-
y(e) && y(o) && k(e, o) ? (t[r - 1] = {
|
|
40
|
-
...e,
|
|
41
|
-
text: e.text + o.text
|
|
42
|
-
}, t.splice(r, 1), n--) : r++;
|
|
43
|
-
}
|
|
44
|
-
for (r = e; r <= n; ) {
|
|
45
|
-
const e = t[r];
|
|
46
|
-
y(e) && !e.text && t.length > 1 ? (t.splice(r, 1), n--) : r++;
|
|
47
|
-
}
|
|
48
|
-
}, S = (t, e = 0, n = t.length - 1) => {
|
|
49
|
-
let r = e + 1;
|
|
50
|
-
for (;r <= n; ) {
|
|
51
|
-
const e = t[r - 1], o = t[r];
|
|
52
|
-
t[r - 1] = A(e, o), t.splice(r, 1), n--;
|
|
53
|
-
}
|
|
54
|
-
}, w = (t, e, n) => {
|
|
55
|
-
if (e.length) {
|
|
56
|
-
const r = t.length;
|
|
57
|
-
t.push(...e), r && n(t, r - 1, r);
|
|
58
|
-
}
|
|
59
|
-
}, A = (...t) => ({
|
|
60
|
-
...t[0],
|
|
61
|
-
children: t.reduce((t, e) => (w(t, e.children, M), t), [])
|
|
62
|
-
}), O = ({children: t}, e) => {
|
|
13
|
+
return r(t) ? t.text.length : 1;
|
|
14
|
+
}, a = ({children: t}, e) => {
|
|
63
15
|
const n = t.length;
|
|
64
|
-
for (let
|
|
65
|
-
const n = t[
|
|
66
|
-
let
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
l: r,
|
|
70
|
-
o: e
|
|
71
|
-
};
|
|
72
|
-
e -= o;
|
|
16
|
+
for (let c = 0; c < n; c++) {
|
|
17
|
+
const n = t[c];
|
|
18
|
+
let s = i(n);
|
|
19
|
+
if (o(n) && s++, s > e || s === e && r(n) && !n.text) return [ n, e, c ];
|
|
20
|
+
e -= s;
|
|
73
21
|
}
|
|
74
22
|
return null;
|
|
75
|
-
},
|
|
23
|
+
}, l = (t, e) => {
|
|
76
24
|
const n = [];
|
|
77
25
|
for (;t; ) {
|
|
78
|
-
const r =
|
|
26
|
+
const r = a(t, e);
|
|
79
27
|
if (!r) break;
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
e = r
|
|
28
|
+
const c = r[0];
|
|
29
|
+
if (!o(c)) break;
|
|
30
|
+
e = r[1], t = c, n.push(r[2]);
|
|
83
31
|
}
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const {i: e, o, l: c} = r;
|
|
93
|
-
if (_(e)) {
|
|
94
|
-
const [r, s] = D(e, o), i = n.slice(0, c), a = n.slice(c + 1);
|
|
95
|
-
return i.push(r), a.unshift(s), [ {
|
|
32
|
+
return [ t, e, n ];
|
|
33
|
+
}, f = (t, e) => {
|
|
34
|
+
const n = t.children, c = a(t, e);
|
|
35
|
+
if (c) {
|
|
36
|
+
const [e, s, i] = c;
|
|
37
|
+
if (o(e)) {
|
|
38
|
+
const [r, o] = f(e, s), c = n.slice(0, i), a = n.slice(i + 1);
|
|
39
|
+
return c.push(r), a.unshift(o), [ {
|
|
96
40
|
...t,
|
|
97
|
-
children:
|
|
41
|
+
children: c
|
|
98
42
|
}, {
|
|
99
43
|
...t,
|
|
100
44
|
children: a
|
|
101
45
|
} ];
|
|
102
46
|
}
|
|
103
47
|
{
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
const t = e.text.slice(0,
|
|
107
|
-
!t &&
|
|
48
|
+
const o = n.slice(0, i), c = n.slice(i + 1);
|
|
49
|
+
if (r(e)) {
|
|
50
|
+
const t = e.text.slice(0, s), n = e.text.slice(s);
|
|
51
|
+
!t && o.length || o.push({
|
|
108
52
|
...e,
|
|
109
53
|
text: t
|
|
110
|
-
}), !n &&
|
|
54
|
+
}), !n && c.length || c.unshift({
|
|
111
55
|
...e,
|
|
112
56
|
text: n
|
|
113
57
|
});
|
|
114
|
-
} else
|
|
58
|
+
} else c.unshift(e);
|
|
115
59
|
return [ {
|
|
116
60
|
...t,
|
|
117
|
-
children:
|
|
61
|
+
children: o
|
|
118
62
|
}, {
|
|
119
63
|
...t,
|
|
120
|
-
children:
|
|
64
|
+
children: c
|
|
121
65
|
} ];
|
|
122
66
|
}
|
|
123
67
|
}
|
|
124
|
-
const
|
|
68
|
+
const s = n[n.length - 1];
|
|
125
69
|
return [ t, {
|
|
126
70
|
...t,
|
|
127
|
-
children:
|
|
128
|
-
...
|
|
71
|
+
children: r(s) ? [ {
|
|
72
|
+
...s,
|
|
129
73
|
text: ""
|
|
130
74
|
} ] : []
|
|
131
75
|
} ];
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const [n, r] = e.range;
|
|
155
|
-
if (t >= n) return r >= t ? n : t + n - r;
|
|
156
|
-
break;
|
|
76
|
+
}, u = (t, [e, n]) => {
|
|
77
|
+
let r = 0;
|
|
78
|
+
for (const o of e) r += s(t, 0, o), 0 !== o && r++, t = t.children[o];
|
|
79
|
+
return r + n;
|
|
80
|
+
}, d = (t, e) => {
|
|
81
|
+
const [, n, r] = l(t, e);
|
|
82
|
+
return [ r, n ];
|
|
83
|
+
}, p = (t, [e, n]) => [ u(t, e), u(t, n) ], y = (t, [e, n]) => [ d(t, e), d(t, n) ];
|
|
84
|
+
|
|
85
|
+
function* h(t, e, n) {
|
|
86
|
+
if (e >= n) return;
|
|
87
|
+
if (!o(t)) return;
|
|
88
|
+
const r = a(t, e);
|
|
89
|
+
if (r) {
|
|
90
|
+
let c = e - r[1], s = r[2];
|
|
91
|
+
const a = t.children, l = a.length;
|
|
92
|
+
for (;c <= n && s < l; ) {
|
|
93
|
+
const t = a[s];
|
|
94
|
+
yield [ t, c ];
|
|
95
|
+
const e = i(t);
|
|
96
|
+
for (const n of h(t, 0, e)) yield [ n[0], n[1] + c ];
|
|
97
|
+
s++, c += e, o(t) && c++;
|
|
157
98
|
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
158
101
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (t >= n) return t + r.length;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
102
|
+
function* k(t, e, n) {
|
|
103
|
+
for (const r of h(t, e, n)) o(r[0]) || (yield r);
|
|
104
|
+
}
|
|
165
105
|
|
|
166
|
-
|
|
167
|
-
{
|
|
168
|
-
const {at: n, fragment: r} = e;
|
|
169
|
-
if (t >= n) return t + m({
|
|
170
|
-
children: r
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return t;
|
|
176
|
-
}, H = ([t, e], n) => [ C(t, n), C(e, n) ];
|
|
106
|
+
var g = (t, e, n) => e >= n ? [] : f(f(t, n)[0], e)[1].children;
|
|
177
107
|
|
|
178
|
-
function
|
|
108
|
+
function _(e, n = t(e.selection)) {
|
|
179
109
|
e.apply({
|
|
180
110
|
type: "delete",
|
|
181
111
|
range: n
|
|
182
112
|
});
|
|
183
113
|
}
|
|
184
114
|
|
|
185
|
-
function
|
|
115
|
+
function m(t, e, n = t.selection[0]) {
|
|
186
116
|
t.apply({
|
|
187
117
|
type: "insert_text",
|
|
188
118
|
at: n,
|
|
@@ -190,7 +120,7 @@ function F(t, e, n = t.selection[0]) {
|
|
|
190
120
|
});
|
|
191
121
|
}
|
|
192
122
|
|
|
193
|
-
function
|
|
123
|
+
function x(t, e, n = t.selection[0]) {
|
|
194
124
|
t.apply({
|
|
195
125
|
type: "insert_node",
|
|
196
126
|
at: n,
|
|
@@ -200,7 +130,7 @@ function V(t, e, n = t.selection[0]) {
|
|
|
200
130
|
});
|
|
201
131
|
}
|
|
202
132
|
|
|
203
|
-
function
|
|
133
|
+
function b(e, n) {
|
|
204
134
|
const r = t(e.selection);
|
|
205
135
|
e.apply({
|
|
206
136
|
type: "delete",
|
|
@@ -212,7 +142,7 @@ function W(e, n) {
|
|
|
212
142
|
});
|
|
213
143
|
}
|
|
214
144
|
|
|
215
|
-
function
|
|
145
|
+
function v(t, e) {
|
|
216
146
|
t.apply({
|
|
217
147
|
type: "set_node_attr",
|
|
218
148
|
path: [],
|
|
@@ -221,7 +151,7 @@ function z(t, e) {
|
|
|
221
151
|
});
|
|
222
152
|
}
|
|
223
153
|
|
|
224
|
-
function
|
|
154
|
+
function E(e, n, r, o = t(e.selection)) {
|
|
225
155
|
e.apply({
|
|
226
156
|
type: "format",
|
|
227
157
|
range: o,
|
|
@@ -230,27 +160,34 @@ function G(e, n, r, o = t(e.selection)) {
|
|
|
230
160
|
});
|
|
231
161
|
}
|
|
232
162
|
|
|
233
|
-
function
|
|
234
|
-
let
|
|
235
|
-
if (e(
|
|
163
|
+
function T(o, c, s = t(o.selection)) {
|
|
164
|
+
let f = !1;
|
|
165
|
+
if (e(s)) {
|
|
236
166
|
const t = ((t, e) => {
|
|
237
|
-
const n =
|
|
238
|
-
return
|
|
239
|
-
})(
|
|
167
|
+
const [n, r] = l(t, e), o = a(n, r);
|
|
168
|
+
return o ? [ o[0], o[1] ] : null;
|
|
169
|
+
})(o.doc, s[0])?.[0];
|
|
170
|
+
if (!t || !r(t)) return;
|
|
171
|
+
f = !t[c];
|
|
172
|
+
} else {
|
|
173
|
+
let t = !1;
|
|
174
|
+
for (const [e, a] of k(o.doc, ...s)) if (n(s, [ a, a + i(e) ]) && r(e) && (t = !0,
|
|
175
|
+
!e[c])) {
|
|
176
|
+
f = !0;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
240
179
|
if (!t) return;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const s = c.filter(y);
|
|
244
|
-
s.length && n.apply({
|
|
180
|
+
}
|
|
181
|
+
o.apply({
|
|
245
182
|
type: "format",
|
|
246
|
-
range:
|
|
247
|
-
key:
|
|
248
|
-
value:
|
|
183
|
+
range: s,
|
|
184
|
+
key: c,
|
|
185
|
+
value: f
|
|
249
186
|
});
|
|
250
187
|
}
|
|
251
188
|
|
|
252
|
-
function
|
|
253
|
-
const
|
|
189
|
+
function M(t, e, n, r = t.selection[0]) {
|
|
190
|
+
const o = l(t.doc, r)[2];
|
|
254
191
|
t.apply({
|
|
255
192
|
type: "set_node_attr",
|
|
256
193
|
path: o,
|
|
@@ -259,8 +196,8 @@ function J(t, e, n, r = t.selection[0]) {
|
|
|
259
196
|
});
|
|
260
197
|
}
|
|
261
198
|
|
|
262
|
-
function
|
|
263
|
-
const
|
|
199
|
+
function S(t, e, n, r, o = t.selection[0]) {
|
|
200
|
+
const [c, , s] = l(t.doc, o);
|
|
264
201
|
t.apply({
|
|
265
202
|
type: "set_node_attr",
|
|
266
203
|
path: s,
|
|
@@ -269,20 +206,22 @@ function X(t, e, n, r, o = t.selection[0]) {
|
|
|
269
206
|
});
|
|
270
207
|
}
|
|
271
208
|
|
|
272
|
-
var
|
|
209
|
+
var w = t => 1 === t.nodeType, A = t => 8 === t.nodeType, O = 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 ] ]), R = Math.min, {keys: D, is: B} = Object, I = t => "string" == typeof t, P = t => "function" == typeof t, N = P(queueMicrotask) ? queueMicrotask : t => {
|
|
210
|
+
Promise.resolve().then(t);
|
|
211
|
+
}, L = new Set([ "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "LI", "DT", "DD", "TH", "TD" ]), C = t => L.has(t.tagName), H = (t, e) => t.compareDocumentPosition(e), U = t => t.ownerDocument, F = t => U(t).getSelection(), V = (t, e) => {
|
|
273
212
|
if (t.rangeCount) {
|
|
274
213
|
const n = t.getRangeAt(0);
|
|
275
214
|
if (e.contains(n.commonAncestorContainer)) return n;
|
|
276
215
|
}
|
|
277
|
-
},
|
|
278
|
-
const i =
|
|
279
|
-
if (s ||
|
|
280
|
-
const s = 0 === c, a = c > 0, l = a ? r : o, f =
|
|
281
|
-
|
|
282
|
-
|
|
216
|
+
}, W = (t, e, n, [r, o], c, s) => {
|
|
217
|
+
const i = F(e);
|
|
218
|
+
if (s || V(i, e)) {
|
|
219
|
+
const s = 0 === c, a = c > 0, l = a ? r : o, f = z(e, n, a ? o : r), u = s ? f : z(e, n, l), d = t.createRange(), [p, y] = f, [h, k] = u;
|
|
220
|
+
w(p) && e !== p ? y < 1 ? d.setStartBefore(p) : d.setStartAfter(p) : d.setStart(p, y),
|
|
221
|
+
w(h) && e !== h ? k < 1 ? d.setEndBefore(h) : d.setEndAfter(h) : d.setEnd(h, k),
|
|
283
222
|
i.removeAllRanges(), i.addRange(d), a && (i.collapseToEnd(), i.extend(d.startContainer, d.startOffset));
|
|
284
223
|
}
|
|
285
|
-
},
|
|
224
|
+
}, z = (t, e, [n, r]) => e(({t: e, o, i: c, l: s}) => {
|
|
286
225
|
let i, a = 0;
|
|
287
226
|
for (;i = e(); ) if (4 === i) {
|
|
288
227
|
if (a < n.length) for (let t = n[a++]; t > 0; t--) o();
|
|
@@ -292,15 +231,15 @@ var Y = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = new Map([ [ "BR",
|
|
|
292
231
|
r -= t;
|
|
293
232
|
}
|
|
294
233
|
return [ t, 0 ];
|
|
295
|
-
}, t),
|
|
296
|
-
let
|
|
297
|
-
if (t ===
|
|
298
|
-
if (
|
|
299
|
-
const t =
|
|
300
|
-
|
|
234
|
+
}, t), G = (t, e, n, r) => {
|
|
235
|
+
let o = !0;
|
|
236
|
+
if (t === n && !n.hasChildNodes()) return [ [ 0 ], 0 ];
|
|
237
|
+
if (w(n) && n.hasChildNodes()) {
|
|
238
|
+
const t = R(r, n.childNodes.length - 1);
|
|
239
|
+
n = n.childNodes[t], o = t === r, r = 0;
|
|
301
240
|
}
|
|
302
|
-
return e(({
|
|
303
|
-
s(
|
|
241
|
+
return e(({t: c, u: s, p: i, h: a, i: l, l: f, k: u}) => {
|
|
242
|
+
s(n), 4 !== u() && i();
|
|
304
243
|
const d = e(() => {
|
|
305
244
|
const e = [];
|
|
306
245
|
for (;u() && l() !== t; ) {
|
|
@@ -311,19 +250,102 @@ var Y = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = new Map([ [ "BR",
|
|
|
311
250
|
return e.length ? e : [ 0 ];
|
|
312
251
|
});
|
|
313
252
|
let p = 0;
|
|
314
|
-
for (;
|
|
315
|
-
const t =
|
|
253
|
+
for (;c(); ) {
|
|
254
|
+
const t = H(n, l());
|
|
316
255
|
if (0 === t || 16 & t) {
|
|
317
|
-
if (
|
|
256
|
+
if (o) break;
|
|
318
257
|
} else if (4 & t) break;
|
|
319
258
|
p += f();
|
|
320
259
|
}
|
|
321
|
-
return [ d, p +
|
|
260
|
+
return [ d, p + r ];
|
|
322
261
|
}, t);
|
|
323
|
-
},
|
|
324
|
-
const s =
|
|
325
|
-
return [ s, r === c && n === o ? s :
|
|
326
|
-
},
|
|
262
|
+
}, q = (t, e, {startOffset: n, startContainer: r, endOffset: o, endContainer: c}) => {
|
|
263
|
+
const s = G(t, e, r, n);
|
|
264
|
+
return [ s, r === c && n === o ? s : G(t, e, c, o) ];
|
|
265
|
+
}, J = (t, e = t => r(t) ? t.text : "") => t.children.reduce((t, n, r) => {
|
|
266
|
+
const c = o(n);
|
|
267
|
+
return 0 !== r && c && (t += "\n"), t + (c ? n.children.reduce((t, n) => t + e(n), "") : "");
|
|
268
|
+
}, ""), X = (t, e, n) => t.split("\n").map(t => ({
|
|
269
|
+
...n,
|
|
270
|
+
children: [ {
|
|
271
|
+
...e,
|
|
272
|
+
text: t
|
|
273
|
+
} ]
|
|
274
|
+
})), Y = "delete", Z = "insert_text", j = "insert_node", K = "format", Q = "set_node_attr", $ = (t, e) => {
|
|
275
|
+
const n = D(t);
|
|
276
|
+
return n.length === D(e).length && n.every(n => n in e && ("text" === n || B(t[n], e[n])));
|
|
277
|
+
}, tt = (t, e = 0, n = t.length - 1) => {
|
|
278
|
+
let o = e + 1;
|
|
279
|
+
for (;o <= n; ) {
|
|
280
|
+
const e = t[o - 1], c = t[o];
|
|
281
|
+
r(e) && r(c) && $(e, c) ? (t[o - 1] = {
|
|
282
|
+
...e,
|
|
283
|
+
text: e.text + c.text
|
|
284
|
+
}, t.splice(o, 1), n--) : o++;
|
|
285
|
+
}
|
|
286
|
+
for (o = e; o <= n; ) {
|
|
287
|
+
const e = t[o];
|
|
288
|
+
r(e) && !e.text && t.length > 1 ? (t.splice(o, 1), n--) : o++;
|
|
289
|
+
}
|
|
290
|
+
}, et = (t, e = 0, n = t.length - 1) => {
|
|
291
|
+
let r = e + 1;
|
|
292
|
+
for (;r <= n; ) {
|
|
293
|
+
const e = t[r - 1], o = t[r];
|
|
294
|
+
t[r - 1] = rt(e, o), t.splice(r, 1), n--;
|
|
295
|
+
}
|
|
296
|
+
}, nt = (t, e, n) => {
|
|
297
|
+
if (e.length) {
|
|
298
|
+
const r = t.length;
|
|
299
|
+
t.push(...e), r && n(t, r - 1, r);
|
|
300
|
+
}
|
|
301
|
+
}, rt = (...t) => ({
|
|
302
|
+
...t[0],
|
|
303
|
+
children: t.reduce((t, e) => (nt(t, e.children, tt), t), [])
|
|
304
|
+
}), ot = (t, e, n, r = 0) => {
|
|
305
|
+
if (r < e.length) {
|
|
306
|
+
const o = e[r];
|
|
307
|
+
return ((t, e, n, r) => {
|
|
308
|
+
const o = t.children.slice();
|
|
309
|
+
return o.splice(e, n - e + 1, ...r), {
|
|
310
|
+
...t,
|
|
311
|
+
children: o
|
|
312
|
+
};
|
|
313
|
+
})(t, o, o, [ ot(t.children[o], e, n, r + 1) ]);
|
|
314
|
+
}
|
|
315
|
+
return n;
|
|
316
|
+
}, ct = (t, e, n, r) => {
|
|
317
|
+
const [o, c] = f(t, e), s = e < n ? f(t, n)[1] : c, i = o.children.slice();
|
|
318
|
+
return nt(i, r, et), nt(i, s.children, et), {
|
|
319
|
+
...t,
|
|
320
|
+
children: i
|
|
321
|
+
};
|
|
322
|
+
}, st = (t, e) => e >= 0 && e <= i(t), it = (t, e) => e.reduce((t, e) => at(t, e), t), at = (t, e) => {
|
|
323
|
+
switch (e.type) {
|
|
324
|
+
case Y:
|
|
325
|
+
{
|
|
326
|
+
const [n, r] = e.range;
|
|
327
|
+
if (t >= n) return r >= t ? n : t + n - r;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
case Z:
|
|
332
|
+
{
|
|
333
|
+
const {at: n, text: r} = e;
|
|
334
|
+
if (t >= n) return t + r.length;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
case j:
|
|
339
|
+
{
|
|
340
|
+
const {at: n, fragment: r} = e;
|
|
341
|
+
if (t >= n) return t + i({
|
|
342
|
+
children: r
|
|
343
|
+
});
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return t;
|
|
348
|
+
}, lt = ([t, e], n) => [ at(t, n), at(e, n) ], ft = "undefined" != typeof navigator && /Mac|iP(hone|od|ad)/.test(navigator.platform), ut = (t, e) => {
|
|
327
349
|
const n = t.endsWith("+"), r = (n ? t.slice(0, -2) : t).split("+"), o = n ? "+" : r.pop(), c = "Space" === o ? " " : o.toLowerCase();
|
|
328
350
|
let s = !1, i = !1, a = !1, l = !1;
|
|
329
351
|
return r.forEach(t => {
|
|
@@ -337,7 +359,7 @@ var Y = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = new Map([ [ "BR",
|
|
|
337
359
|
break;
|
|
338
360
|
|
|
339
361
|
case "Mod":
|
|
340
|
-
|
|
362
|
+
ft ? a = !0 : i = !0;
|
|
341
363
|
break;
|
|
342
364
|
|
|
343
365
|
case "Alt":
|
|
@@ -353,159 +375,159 @@ var Y = t => 1 === t.nodeType, Z = t => 8 === t.nodeType, j = new Map([ [ "BR",
|
|
|
353
375
|
};
|
|
354
376
|
};
|
|
355
377
|
|
|
356
|
-
function
|
|
378
|
+
function dt(t) {
|
|
357
379
|
let e = 0, n = 0, r = !1;
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
const n =
|
|
380
|
+
const o = Date.now, c = [ [ t.doc, t.selection, [] ] ], s = () => c[e], i = () => e > 0, a = () => e < c.length - 1, l = () => {
|
|
381
|
+
if (i()) {
|
|
382
|
+
const n = s()[1];
|
|
361
383
|
e--;
|
|
362
|
-
const
|
|
363
|
-
r = !0, t.exec(
|
|
384
|
+
const o = t.doc;
|
|
385
|
+
r = !0, t.exec(v, s()[0].children), r = !1, B(o, t.doc) || (t.selection = n);
|
|
364
386
|
}
|
|
365
|
-
},
|
|
366
|
-
if (
|
|
387
|
+
}, f = () => {
|
|
388
|
+
if (a()) {
|
|
367
389
|
e++;
|
|
368
|
-
const [n,
|
|
369
|
-
r = !0, t.exec(
|
|
390
|
+
const [n, o, c] = s(), i = t.doc;
|
|
391
|
+
r = !0, t.exec(v, n.children), r = !1, B(i, t.doc) || (t.selection = [ it(o[0], c), it(o[1], c) ]);
|
|
370
392
|
}
|
|
371
393
|
};
|
|
372
|
-
t.hook("apply", (
|
|
394
|
+
t.hook("apply", (s, i) => {
|
|
373
395
|
if (r) return;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
378
|
-
const t =
|
|
396
|
+
const a = t.doc, l = t.selection;
|
|
397
|
+
i(s);
|
|
398
|
+
const f = t.doc;
|
|
399
|
+
if (!B(a, f)) {
|
|
400
|
+
const t = o();
|
|
379
401
|
if (0 === e || t - n >= 500) {
|
|
380
402
|
e++;
|
|
381
|
-
const t = [
|
|
382
|
-
e >=
|
|
403
|
+
const t = [ a, l, [] ];
|
|
404
|
+
e >= c.length ? c.push(t) : c[e] = t;
|
|
383
405
|
}
|
|
384
|
-
n = t,
|
|
385
|
-
|
|
406
|
+
n = t, c[e][0] = f, c[e][2].push(s), c.length > e + 1 && (c.length = e + 1), e > 500 && (e--,
|
|
407
|
+
c.shift());
|
|
386
408
|
}
|
|
387
|
-
}), t.hook("keyboard",
|
|
388
|
-
t.set(
|
|
389
|
-
undo:
|
|
390
|
-
redo:
|
|
391
|
-
undoable:
|
|
392
|
-
redoable:
|
|
409
|
+
}), t.hook("keyboard", ut("Mod+Z", l)), t.hook("keyboard", ut("Shift+Mod+Z", f)),
|
|
410
|
+
t.set(dt, {
|
|
411
|
+
undo: l,
|
|
412
|
+
redo: f,
|
|
413
|
+
undoable: i,
|
|
414
|
+
redoable: a
|
|
393
415
|
});
|
|
394
416
|
}
|
|
395
417
|
|
|
396
|
-
function
|
|
397
|
-
t.get(
|
|
418
|
+
function pt(t) {
|
|
419
|
+
t.get(dt).undo();
|
|
398
420
|
}
|
|
399
421
|
|
|
400
|
-
function
|
|
401
|
-
t.get(
|
|
422
|
+
function yt(t) {
|
|
423
|
+
t.get(dt).redo();
|
|
402
424
|
}
|
|
403
425
|
|
|
404
|
-
function
|
|
405
|
-
return t.get(
|
|
426
|
+
function ht(t) {
|
|
427
|
+
return t.get(dt).undoable();
|
|
406
428
|
}
|
|
407
429
|
|
|
408
|
-
function
|
|
409
|
-
return t.get(
|
|
430
|
+
function kt(t) {
|
|
431
|
+
return t.get(dt).redoable();
|
|
410
432
|
}
|
|
411
433
|
|
|
412
|
-
var
|
|
434
|
+
var gt = [], _t = () => {}, mt = t => {
|
|
413
435
|
throw Error(t);
|
|
414
|
-
},
|
|
415
|
-
let
|
|
416
|
-
const
|
|
417
|
-
if (!
|
|
436
|
+
}, xt = ({doc: n, readonly: o = !1, schema: c, isBlock: s = C, onWarn: i = console.warn, onError: f = mt}) => {
|
|
437
|
+
let d = [ 0, 0 ];
|
|
438
|
+
const h = t => {
|
|
439
|
+
if (!c) return i("An unsafe operation was detected. We recommend using schema option."),
|
|
418
440
|
!0;
|
|
419
|
-
const e =
|
|
420
|
-
if (e instanceof Promise)
|
|
441
|
+
const e = c["~standard"].validate(t);
|
|
442
|
+
if (e instanceof Promise) f("async validate is not supported"); else {
|
|
421
443
|
if (!e.issues) return !0;
|
|
422
|
-
|
|
444
|
+
i(e.issues.map(t => t.message).join("\n"));
|
|
423
445
|
}
|
|
424
446
|
return !1;
|
|
425
447
|
};
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
const e =
|
|
429
|
-
e && (
|
|
430
|
-
|
|
448
|
+
c && !h(n) && f("Invalid document");
|
|
449
|
+
const k = /* @__PURE__ */ new Map, _ = /* @__PURE__ */ new WeakMap, m = t => k.get(t) || gt, x = /* @__PURE__ */ new Map, b = /* @__PURE__ */ new Set, v = t => {
|
|
450
|
+
const e = x.get(t);
|
|
451
|
+
e && (b.size || N(() => {
|
|
452
|
+
b.forEach(t => {
|
|
431
453
|
t();
|
|
432
|
-
}),
|
|
454
|
+
}), b.clear();
|
|
433
455
|
}), e.forEach(t => {
|
|
434
|
-
|
|
456
|
+
b.add(t);
|
|
435
457
|
}));
|
|
436
|
-
},
|
|
437
|
-
if (!
|
|
438
|
-
return
|
|
439
|
-
},
|
|
440
|
-
const e = n,
|
|
458
|
+
}, E = t => {
|
|
459
|
+
if (!o) if (Array.isArray(t)) for (const e of t) T(e); else T(t);
|
|
460
|
+
return S;
|
|
461
|
+
}, T = t => {
|
|
462
|
+
const e = n, o = m("apply"), c = o.length;
|
|
441
463
|
let s = 0;
|
|
442
|
-
const
|
|
464
|
+
const f = () => {
|
|
443
465
|
if (s < c) {
|
|
444
466
|
const e = s;
|
|
445
|
-
|
|
467
|
+
o[s](t, u), e === s && u();
|
|
446
468
|
} else if (s === c) {
|
|
447
469
|
s++;
|
|
448
470
|
try {
|
|
449
|
-
const [e,
|
|
471
|
+
const [e, o] = ((t, e, n) => {
|
|
450
472
|
switch (n.type) {
|
|
451
|
-
case
|
|
473
|
+
case Y:
|
|
452
474
|
{
|
|
453
475
|
const [r, o] = n.range;
|
|
454
|
-
|
|
476
|
+
st(t, r) && st(t, o) && r < o && (t = ct(t, r, o, []), e = lt(e, n));
|
|
455
477
|
break;
|
|
456
478
|
}
|
|
457
479
|
|
|
458
|
-
case
|
|
480
|
+
case Z:
|
|
459
481
|
{
|
|
460
|
-
const {at:
|
|
461
|
-
if (
|
|
462
|
-
const
|
|
463
|
-
let
|
|
464
|
-
if (
|
|
465
|
-
const t =
|
|
466
|
-
|
|
482
|
+
const {at: o, text: c} = n;
|
|
483
|
+
if (st(t, o) && c) {
|
|
484
|
+
const [s, i] = l(t, o), f = a(s, i - 1);
|
|
485
|
+
let u;
|
|
486
|
+
if (f) {
|
|
487
|
+
const t = f[0];
|
|
488
|
+
r(t) && (u = t);
|
|
467
489
|
}
|
|
468
|
-
t =
|
|
490
|
+
t = ct(t, o, o, X(c, u, s)), e = lt(e, n);
|
|
469
491
|
}
|
|
470
492
|
break;
|
|
471
493
|
}
|
|
472
494
|
|
|
473
|
-
case
|
|
495
|
+
case j:
|
|
474
496
|
{
|
|
475
497
|
const {at: r, fragment: o} = n;
|
|
476
|
-
|
|
498
|
+
st(t, r) && o.length && (t = ct(t, r, r, o), e = lt(e, n));
|
|
477
499
|
break;
|
|
478
500
|
}
|
|
479
501
|
|
|
480
|
-
case
|
|
502
|
+
case K:
|
|
481
503
|
{
|
|
482
|
-
const {range: [e,
|
|
483
|
-
if (
|
|
484
|
-
const {
|
|
504
|
+
const {range: [e, o], key: c, value: s} = n;
|
|
505
|
+
if (st(t, e) && st(t, o) && e <= o) if (e === o) {
|
|
506
|
+
const [{children: n}, , o] = l(t, e);
|
|
485
507
|
if (1 === n.length) {
|
|
486
508
|
const e = n[0];
|
|
487
|
-
|
|
509
|
+
r(e) && !e.text && (t = ot(t, [ ...o, 0 ], {
|
|
488
510
|
...e,
|
|
489
|
-
[
|
|
511
|
+
[c]: s
|
|
490
512
|
}));
|
|
491
513
|
}
|
|
492
|
-
} else t =
|
|
514
|
+
} else t = ct(t, e, o, g(t, e, o).map(t => ({
|
|
493
515
|
...t,
|
|
494
|
-
children: t.children.map(t =>
|
|
516
|
+
children: t.children.map(t => r(t) ? {
|
|
495
517
|
...t,
|
|
496
|
-
[
|
|
518
|
+
[c]: s
|
|
497
519
|
} : t)
|
|
498
520
|
})));
|
|
499
521
|
break;
|
|
500
522
|
}
|
|
501
523
|
|
|
502
|
-
case
|
|
524
|
+
case Q:
|
|
503
525
|
{
|
|
504
526
|
const {path: e, key: r, value: o} = n, c = ((t, e) => {
|
|
505
527
|
for (let n = 0; n < e.length; n++) t = t.children[e[n]];
|
|
506
528
|
return t;
|
|
507
529
|
})(t, e);
|
|
508
|
-
c && (t =
|
|
530
|
+
c && (t = ot(t, e, {
|
|
509
531
|
...c,
|
|
510
532
|
[r]: o
|
|
511
533
|
}));
|
|
@@ -513,72 +535,72 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
513
535
|
}
|
|
514
536
|
}
|
|
515
537
|
return [ t, e ];
|
|
516
|
-
})(n,
|
|
517
|
-
(({type: t}) => t ===
|
|
538
|
+
})(n, d, t);
|
|
539
|
+
(({type: t}) => t === j || t === K || t === Q)(t) && !h(e) || (n = e, M(o));
|
|
518
540
|
} catch (e) {
|
|
519
|
-
|
|
541
|
+
i("rollback operation: " + e);
|
|
520
542
|
}
|
|
521
543
|
}
|
|
522
|
-
},
|
|
523
|
-
e && (t = e), s++,
|
|
544
|
+
}, u = e => {
|
|
545
|
+
e && (t = e), s++, f();
|
|
524
546
|
};
|
|
525
|
-
|
|
526
|
-
},
|
|
527
|
-
!((t, [e, n]) =>
|
|
528
|
-
|
|
529
|
-
},
|
|
547
|
+
f(), B(e, n) || v("change");
|
|
548
|
+
}, M = t => {
|
|
549
|
+
!((t, [e, n]) => st(t, e) && st(t, n))(n, t) || d[0] === t[0] && d[1] === t[1] || (d = t,
|
|
550
|
+
v("selectionchange"));
|
|
551
|
+
}, S = {
|
|
530
552
|
get doc() {
|
|
531
553
|
return n;
|
|
532
554
|
},
|
|
533
555
|
get selection() {
|
|
534
|
-
return
|
|
556
|
+
return d;
|
|
535
557
|
},
|
|
536
558
|
set selection(t) {
|
|
537
|
-
|
|
559
|
+
M(t);
|
|
538
560
|
},
|
|
539
561
|
get readonly() {
|
|
540
|
-
return
|
|
562
|
+
return o;
|
|
541
563
|
},
|
|
542
564
|
set readonly(t) {
|
|
543
|
-
|
|
565
|
+
o = t, v("readonly");
|
|
544
566
|
},
|
|
545
|
-
apply:
|
|
567
|
+
apply: E,
|
|
546
568
|
on: (t, e) => {
|
|
547
|
-
let n =
|
|
548
|
-
return n ||
|
|
569
|
+
let n = x.get(t);
|
|
570
|
+
return n || x.set(t, n = /* @__PURE__ */ new Set), n.add(e), () => {
|
|
549
571
|
n.delete(e);
|
|
550
572
|
};
|
|
551
573
|
},
|
|
552
574
|
hook: (t, e) => {
|
|
553
|
-
let n =
|
|
554
|
-
return n ||
|
|
575
|
+
let n = k.get(t);
|
|
576
|
+
return n || k.set(t, n = []), n.push(e), () => {
|
|
555
577
|
const t = n.indexOf(e);
|
|
556
578
|
-1 !== t && n.splice(t, 1);
|
|
557
579
|
};
|
|
558
580
|
},
|
|
559
581
|
exec: (t, ...e) => {
|
|
560
|
-
const n = t(
|
|
561
|
-
return void 0 === n ?
|
|
582
|
+
const n = t(S, ...e);
|
|
583
|
+
return void 0 === n ? S : n;
|
|
562
584
|
},
|
|
563
|
-
get: t => (
|
|
564
|
-
set: (t, e) => (
|
|
565
|
-
input:
|
|
566
|
-
if (!window.InputEvent || !
|
|
567
|
-
|
|
568
|
-
const {contentEditable:
|
|
569
|
-
|
|
570
|
-
let
|
|
571
|
-
const
|
|
585
|
+
get: t => (_.has(t) || f("No value found for key"), _.get(t)),
|
|
586
|
+
set: (t, e) => (_.set(t, e), S),
|
|
587
|
+
input: r => {
|
|
588
|
+
if (!window.InputEvent || !P(InputEvent.prototype.getTargetRanges)) return i("beforeinput event is not supported."),
|
|
589
|
+
_t;
|
|
590
|
+
const {contentEditable: c, role: a, ariaMultiLine: l, ariaReadOnly: f} = r, h = r.style.whiteSpace;
|
|
591
|
+
r.role = "textbox", r.style.whiteSpace = "pre-wrap", r.ariaMultiLine = "true";
|
|
592
|
+
let k = !1, g = null, _ = !1, x = !1, b = !1;
|
|
593
|
+
const v = U(r), T = ((t, e) => {
|
|
572
594
|
let n = null, r = null, o = null;
|
|
573
595
|
const c = () => {
|
|
574
596
|
if (null != o) return o;
|
|
575
597
|
if (r) if ((t => 3 === t.nodeType)(r)) {
|
|
576
598
|
const t = r.data;
|
|
577
599
|
if (t) return o = "\n" === t ? i() ? 3 : 5 : 1;
|
|
578
|
-
} else if (
|
|
600
|
+
} else if (w(r)) {
|
|
579
601
|
if ("false" === r.contentEditable) return o = 2;
|
|
580
602
|
{
|
|
581
|
-
const t =
|
|
603
|
+
const t = O.get(r.tagName);
|
|
582
604
|
if (null != t) return o = 1 === t ? i() ? 3 : 5 : 3 === t ? 2 : 6;
|
|
583
605
|
if (e(r)) return o = 4;
|
|
584
606
|
}
|
|
@@ -602,28 +624,28 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
602
624
|
return !1;
|
|
603
625
|
});
|
|
604
626
|
}, a = {
|
|
605
|
-
|
|
627
|
+
t: () => {
|
|
606
628
|
for (;s(); ) {
|
|
607
629
|
const t = c();
|
|
608
630
|
if (t && 6 !== t) return t;
|
|
609
631
|
}
|
|
610
632
|
},
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
633
|
+
k: c,
|
|
634
|
+
i: () => r,
|
|
635
|
+
l: () => {
|
|
614
636
|
const t = c();
|
|
615
637
|
return 1 === t ? r.data.length : 2 === t ? 1 : 0;
|
|
616
638
|
},
|
|
617
|
-
|
|
639
|
+
u: t => {
|
|
618
640
|
o = null, n.currentNode = r = t;
|
|
619
641
|
},
|
|
620
|
-
|
|
642
|
+
h: () => {
|
|
621
643
|
for (;(o = null) || (r = n.previousSibling()); ) if (4 === c()) return;
|
|
622
644
|
},
|
|
623
|
-
|
|
645
|
+
o: () => {
|
|
624
646
|
for (;(o = null) || (r = n.nextSibling()); ) if (4 === c()) return;
|
|
625
647
|
},
|
|
626
|
-
|
|
648
|
+
p: () => {
|
|
627
649
|
for (;(o = null) || (r = n.parentNode()); ) if (4 === c()) return;
|
|
628
650
|
}
|
|
629
651
|
}, l = (e, c) => {
|
|
@@ -635,23 +657,23 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
635
657
|
}
|
|
636
658
|
};
|
|
637
659
|
return l;
|
|
638
|
-
})(
|
|
639
|
-
|
|
660
|
+
})(v, s), A = () => {
|
|
661
|
+
r.contentEditable = o ? "false" : "true", r.ariaReadOnly = o ? "true" : null;
|
|
640
662
|
};
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
663
|
+
A();
|
|
664
|
+
const R = S.on("change", () => {
|
|
665
|
+
x || requestAnimationFrame(() => {
|
|
666
|
+
x || r.focus({
|
|
645
667
|
preventScroll: !0
|
|
646
668
|
});
|
|
647
669
|
});
|
|
648
|
-
}),
|
|
649
|
-
for (const e of
|
|
670
|
+
}), D = S.on("readonly", A), B = t => {
|
|
671
|
+
for (const e of m("paste")) {
|
|
650
672
|
const n = e(t);
|
|
651
673
|
if (n) return n;
|
|
652
674
|
}
|
|
653
|
-
|
|
654
|
-
},
|
|
675
|
+
i("failed to serialize pasted data");
|
|
676
|
+
}, N = ((t, e) => {
|
|
655
677
|
let n = !1, r = [];
|
|
656
678
|
const o = t => {
|
|
657
679
|
n && r.push(...t);
|
|
@@ -670,7 +692,7 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
670
692
|
childList: !0,
|
|
671
693
|
subtree: !0
|
|
672
694
|
}), {
|
|
673
|
-
|
|
695
|
+
_: t => {
|
|
674
696
|
let e;
|
|
675
697
|
for (;e = t.pop(); ) if ("childList" === e.type) {
|
|
676
698
|
const {target: t, removedNodes: n, addedNodes: r, nextSibling: o} = e;
|
|
@@ -679,83 +701,84 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
679
701
|
} else e.target.data = e.oldValue;
|
|
680
702
|
i();
|
|
681
703
|
},
|
|
682
|
-
|
|
704
|
+
m: t => {
|
|
683
705
|
!n && t && s(), n = t;
|
|
684
706
|
},
|
|
685
|
-
|
|
686
|
-
|
|
707
|
+
v: i,
|
|
708
|
+
T: () => {
|
|
687
709
|
r.length = 0, c.disconnect();
|
|
688
710
|
}
|
|
689
711
|
};
|
|
690
|
-
})(
|
|
691
|
-
|
|
692
|
-
}),
|
|
693
|
-
|
|
694
|
-
const n =
|
|
712
|
+
})(r, () => {
|
|
713
|
+
W(v, r, T, y(n, d), d[0] - d[1]);
|
|
714
|
+
}), L = () => {
|
|
715
|
+
M(p(n, ((t, e) => {
|
|
716
|
+
const n = F(t), r = V(n, t);
|
|
695
717
|
if (!r) return [ [ [ 0 ], 0 ], [ [ 0 ], 0 ] ];
|
|
696
|
-
const o =
|
|
718
|
+
const o = q(t, e, r), c = H(n.anchorNode, n.focusNode);
|
|
697
719
|
return (0 === c ? n.anchorOffset > n.focusOffset : 2 & c) ? [ o[1], o[0] ] : o;
|
|
698
|
-
})(
|
|
699
|
-
},
|
|
700
|
-
const t =
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
},
|
|
704
|
-
if (!
|
|
705
|
-
},
|
|
706
|
-
|
|
707
|
-
},
|
|
720
|
+
})(r, T)));
|
|
721
|
+
}, C = () => {
|
|
722
|
+
const t = N.v();
|
|
723
|
+
N.m(!1), t.length && (N._(t), v.removeEventListener("selectionchange", Q), W(v, r, T, y(n, d), d[0] - d[1], !0),
|
|
724
|
+
v.addEventListener("selectionchange", Q)), g && (M(g[1]), E(g[0]), g = null), _ = !1;
|
|
725
|
+
}, z = t => {
|
|
726
|
+
if (!_) for (const e of m("keyboard")) if (e(t)) return t.preventDefault(), void N.m(!1);
|
|
727
|
+
}, J = () => {
|
|
728
|
+
_ || C();
|
|
729
|
+
}, X = t => {
|
|
708
730
|
t.preventDefault();
|
|
709
|
-
const
|
|
710
|
-
if (
|
|
711
|
-
if ("historyUndo" ===
|
|
712
|
-
|
|
731
|
+
const o = t.inputType;
|
|
732
|
+
if (o.startsWith("format")) return;
|
|
733
|
+
if ("historyUndo" === o || "historyRedo" === o) return;
|
|
734
|
+
_ ? N.m(!0) : L();
|
|
713
735
|
const c = t.getTargetRanges()[0];
|
|
714
736
|
if (c) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
if (null == a) {
|
|
737
|
+
let s = "insertParagraph" === o || "insertLineBreak" === o ? "\n" : t.data;
|
|
738
|
+
if (null == s) {
|
|
718
739
|
const e = t.dataTransfer;
|
|
719
|
-
e && (
|
|
740
|
+
e && (s = e.getData("text/plain"));
|
|
720
741
|
}
|
|
721
|
-
|
|
742
|
+
g || (g = [ [], d ]);
|
|
743
|
+
const i = g[0], a = p(n, q(r, T, c));
|
|
744
|
+
e(a) || i.push({
|
|
722
745
|
type: "delete",
|
|
723
|
-
range:
|
|
724
|
-
}),
|
|
746
|
+
range: a
|
|
747
|
+
}), s && i.push({
|
|
725
748
|
type: "insert_text",
|
|
726
|
-
at:
|
|
727
|
-
text:
|
|
749
|
+
at: a[0],
|
|
750
|
+
text: s
|
|
728
751
|
});
|
|
729
752
|
}
|
|
730
|
-
|
|
731
|
-
},
|
|
732
|
-
|
|
733
|
-
},
|
|
734
|
-
|
|
735
|
-
},
|
|
736
|
-
|
|
737
|
-
},
|
|
738
|
-
|
|
739
|
-
},
|
|
740
|
-
|
|
741
|
-
},
|
|
742
|
-
if (
|
|
743
|
-
},
|
|
744
|
-
t.preventDefault(),
|
|
745
|
-
},
|
|
746
|
-
e.preventDefault(),
|
|
753
|
+
_ || C();
|
|
754
|
+
}, Y = () => {
|
|
755
|
+
_ || L(), _ = !0;
|
|
756
|
+
}, Z = () => {
|
|
757
|
+
C();
|
|
758
|
+
}, j = () => {
|
|
759
|
+
x = !0, L();
|
|
760
|
+
}, K = () => {
|
|
761
|
+
x = !1;
|
|
762
|
+
}, Q = () => {
|
|
763
|
+
x && !b && L();
|
|
764
|
+
}, $ = t => {
|
|
765
|
+
if (L(), !e(d)) for (const e of m("copy")) e(t);
|
|
766
|
+
}, tt = t => {
|
|
767
|
+
t.preventDefault(), $(t.clipboardData);
|
|
768
|
+
}, et = e => {
|
|
769
|
+
e.preventDefault(), o || ($(e.clipboardData), E({
|
|
747
770
|
type: "delete",
|
|
748
|
-
range: t(
|
|
771
|
+
range: t(d)
|
|
749
772
|
}));
|
|
750
|
-
},
|
|
773
|
+
}, nt = e => {
|
|
751
774
|
e.preventDefault();
|
|
752
|
-
const n =
|
|
775
|
+
const n = B(e.clipboardData);
|
|
753
776
|
if (n) {
|
|
754
|
-
const e = t(
|
|
777
|
+
const e = t(d), r = e[0], o = [ {
|
|
755
778
|
type: "delete",
|
|
756
779
|
range: e
|
|
757
780
|
} ];
|
|
758
|
-
o.push(
|
|
781
|
+
o.push(I(n) ? {
|
|
759
782
|
type: "insert_text",
|
|
760
783
|
at: r,
|
|
761
784
|
text: n
|
|
@@ -763,71 +786,71 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
763
786
|
type: "insert_node",
|
|
764
787
|
at: r,
|
|
765
788
|
fragment: n
|
|
766
|
-
}),
|
|
789
|
+
}), E(o);
|
|
767
790
|
}
|
|
768
|
-
},
|
|
791
|
+
}, rt = e => {
|
|
769
792
|
e.preventDefault();
|
|
770
|
-
const
|
|
771
|
-
const o =
|
|
793
|
+
const o = e.dataTransfer, c = ((t, e, {clientX: n, clientY: r}) => {
|
|
794
|
+
const o = U(t);
|
|
772
795
|
if (o.caretPositionFromPoint) {
|
|
773
796
|
const c = o.caretPositionFromPoint(n, r);
|
|
774
|
-
if (c) return
|
|
797
|
+
if (c) return G(t, e, c.offsetNode, c.offset);
|
|
775
798
|
} else if (o.caretRangeFromPoint) {
|
|
776
799
|
const c = o.caretRangeFromPoint(n, r);
|
|
777
|
-
if (c) return
|
|
800
|
+
if (c) return G(t, e, c.startContainer, c.startOffset);
|
|
778
801
|
}
|
|
779
|
-
})(
|
|
780
|
-
if (
|
|
802
|
+
})(r, T, e);
|
|
803
|
+
if (o && c) {
|
|
781
804
|
let e;
|
|
782
|
-
const
|
|
783
|
-
|
|
805
|
+
const r = [];
|
|
806
|
+
b && r.push({
|
|
784
807
|
type: "delete",
|
|
785
|
-
range: t(
|
|
808
|
+
range: t(d)
|
|
786
809
|
});
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
789
|
-
const t =
|
|
790
|
-
|
|
810
|
+
const s = B(o);
|
|
811
|
+
if (s) {
|
|
812
|
+
const t = u(n, c), o = it(t, r);
|
|
813
|
+
r.push(I(s) ? {
|
|
791
814
|
type: "insert_text",
|
|
792
|
-
at:
|
|
793
|
-
text:
|
|
815
|
+
at: o,
|
|
816
|
+
text: s
|
|
794
817
|
} : {
|
|
795
818
|
type: "insert_node",
|
|
796
|
-
at:
|
|
797
|
-
fragment:
|
|
798
|
-
}), e = [
|
|
819
|
+
at: o,
|
|
820
|
+
fragment: s
|
|
821
|
+
}), e = [ o, it(t, r) ];
|
|
799
822
|
}
|
|
800
|
-
|
|
823
|
+
E(r), e && M(e);
|
|
801
824
|
}
|
|
802
|
-
},
|
|
803
|
-
|
|
804
|
-
},
|
|
805
|
-
|
|
825
|
+
}, ot = t => {
|
|
826
|
+
b = !0, $(t.dataTransfer);
|
|
827
|
+
}, ct = () => {
|
|
828
|
+
b = !1;
|
|
806
829
|
};
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const
|
|
813
|
-
return
|
|
814
|
-
const e = t(
|
|
815
|
-
e &&
|
|
830
|
+
v.addEventListener("selectionchange", Q), r.addEventListener("keydown", z), r.addEventListener("input", J),
|
|
831
|
+
r.addEventListener("beforeinput", X), r.addEventListener("compositionstart", Y),
|
|
832
|
+
r.addEventListener("compositionend", Z), r.addEventListener("focus", j), r.addEventListener("blur", K),
|
|
833
|
+
r.addEventListener("copy", tt), r.addEventListener("cut", et), r.addEventListener("paste", nt),
|
|
834
|
+
r.addEventListener("drop", rt), r.addEventListener("dragstart", ot), r.addEventListener("dragend", ct);
|
|
835
|
+
const st = [];
|
|
836
|
+
return m("mount").forEach(t => {
|
|
837
|
+
const e = t(r, T);
|
|
838
|
+
e && st.push(e);
|
|
816
839
|
}), () => {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
840
|
+
k || (k = !0, R(), D(), r.contentEditable = c, r.role = a, r.ariaMultiLine = l,
|
|
841
|
+
r.ariaReadOnly = f, r.style.whiteSpace = h, N.T(), v.removeEventListener("selectionchange", Q),
|
|
842
|
+
r.removeEventListener("keydown", z), r.removeEventListener("input", J), r.removeEventListener("beforeinput", X),
|
|
843
|
+
r.removeEventListener("compositionstart", Y), r.removeEventListener("compositionend", Z),
|
|
844
|
+
r.removeEventListener("focus", j), r.removeEventListener("blur", K), r.removeEventListener("copy", tt),
|
|
845
|
+
r.removeEventListener("cut", et), r.removeEventListener("paste", nt), r.removeEventListener("drop", rt),
|
|
846
|
+
r.removeEventListener("dragstart", ot), r.removeEventListener("dragend", ct), st.forEach(t => {
|
|
824
847
|
t();
|
|
825
848
|
}));
|
|
826
849
|
};
|
|
827
850
|
}
|
|
828
851
|
};
|
|
829
|
-
return
|
|
830
|
-
},
|
|
852
|
+
return S.exec(dt), S;
|
|
853
|
+
}, bt = (t, e) => {
|
|
831
854
|
t.hook("paste", t => {
|
|
832
855
|
for (const n of t.items) if ("file" === n.kind) {
|
|
833
856
|
const t = e[n.type];
|
|
@@ -842,20 +865,20 @@ var ht = [], yt = () => {}, _t = t => {
|
|
|
842
865
|
});
|
|
843
866
|
};
|
|
844
867
|
|
|
845
|
-
function
|
|
868
|
+
function vt(e, n) {
|
|
846
869
|
const r = n && n.serializer;
|
|
847
870
|
e.hook("copy", n => {
|
|
848
|
-
n.setData("text/plain",
|
|
849
|
-
children:
|
|
871
|
+
n.setData("text/plain", J({
|
|
872
|
+
children: g(e.doc, ...t(e.selection))
|
|
850
873
|
}, r));
|
|
851
874
|
}), e.hook("paste", t => t.getData("text/plain"));
|
|
852
875
|
}
|
|
853
876
|
|
|
854
|
-
function
|
|
877
|
+
function Et(t, e) {
|
|
855
878
|
t.hook("mount", (n, r) => {
|
|
856
879
|
const o = t.hook("copy", t => {
|
|
857
880
|
const e = document.createElement("div");
|
|
858
|
-
e.appendChild(
|
|
881
|
+
e.appendChild(V(F(n), n).cloneContents()), t.setData("text/html", e.innerHTML);
|
|
859
882
|
}), c = t.hook("paste", t => {
|
|
860
883
|
const n = t.getData("text/html");
|
|
861
884
|
return n ? ((t, e, n) => {
|
|
@@ -867,9 +890,9 @@ function mt(t, e) {
|
|
|
867
890
|
}
|
|
868
891
|
};
|
|
869
892
|
let c = (new DOMParser).parseFromString(t, "text/html").body, s = !1;
|
|
870
|
-
for (const i of [ ...c.childNodes ])
|
|
893
|
+
for (const i of [ ...c.childNodes ]) A(i) ? "StartFragment" === i.data ? (s = !0,
|
|
871
894
|
c = new DocumentFragment) : "EndFragment" === i.data && (s = !1) : s && c.appendChild(i);
|
|
872
|
-
return e(({
|
|
895
|
+
return e(({t, i: e}) => {
|
|
873
896
|
let n, c = null, s = "", i = !1;
|
|
874
897
|
const a = [], l = () => {
|
|
875
898
|
s && (c || (c = []), c.push(r(s)), s = "");
|
|
@@ -895,21 +918,21 @@ function mt(t, e) {
|
|
|
895
918
|
});
|
|
896
919
|
}
|
|
897
920
|
|
|
898
|
-
var
|
|
921
|
+
var Tt = "application/x-editate-editor";
|
|
899
922
|
|
|
900
|
-
function
|
|
923
|
+
function Mt(e) {
|
|
901
924
|
e.hook("copy", n => {
|
|
902
|
-
n.setData(
|
|
925
|
+
n.setData(Tt, JSON.stringify(g(e.doc, ...t(e.selection))));
|
|
903
926
|
}), e.hook("paste", t => {
|
|
904
927
|
try {
|
|
905
|
-
return JSON.parse(t.getData(
|
|
928
|
+
return JSON.parse(t.getData(Tt));
|
|
906
929
|
} catch (e) {
|
|
907
930
|
return null;
|
|
908
931
|
}
|
|
909
932
|
});
|
|
910
933
|
}
|
|
911
934
|
|
|
912
|
-
function
|
|
935
|
+
function St(t) {
|
|
913
936
|
t.hook("apply", t => {
|
|
914
937
|
console.log("apply", t);
|
|
915
938
|
}), t.on("change", () => {
|
|
@@ -919,16 +942,16 @@ function Et(t) {
|
|
|
919
942
|
});
|
|
920
943
|
}
|
|
921
944
|
|
|
922
|
-
function
|
|
923
|
-
|
|
945
|
+
function wt(t, e) {
|
|
946
|
+
D(e).forEach(n => {
|
|
924
947
|
const r = e[n];
|
|
925
|
-
t.hook("keyboard",
|
|
948
|
+
t.hook("keyboard", ut(n, () => {
|
|
926
949
|
r();
|
|
927
950
|
}));
|
|
928
951
|
});
|
|
929
952
|
}
|
|
930
953
|
|
|
931
|
-
function
|
|
954
|
+
function At(t) {
|
|
932
955
|
t.hook("mount", t => {
|
|
933
956
|
t.ariaMultiLine = null;
|
|
934
957
|
}), t.hook("apply", (t, e) => {
|
|
@@ -937,22 +960,22 @@ function Mt(t) {
|
|
|
937
960
|
text: t.text.replaceAll("\n", "")
|
|
938
961
|
} : "insert_node" === t.type && (t = {
|
|
939
962
|
...t,
|
|
940
|
-
fragment: [
|
|
963
|
+
fragment: [ rt(...t.fragment) ]
|
|
941
964
|
}), e(t);
|
|
942
965
|
});
|
|
943
966
|
}
|
|
944
967
|
|
|
945
|
-
var
|
|
946
|
-
const o =
|
|
968
|
+
var Ot = ({text: t, singleline: e, onChange: n, ...r}) => {
|
|
969
|
+
const o = xt({
|
|
947
970
|
...r,
|
|
948
971
|
doc: {
|
|
949
|
-
children:
|
|
972
|
+
children: X(t)
|
|
950
973
|
}
|
|
951
|
-
}).exec(
|
|
952
|
-
return e && o.exec(
|
|
953
|
-
n(
|
|
974
|
+
}).exec(vt);
|
|
975
|
+
return e && o.exec(At), o.on("change", () => {
|
|
976
|
+
n(J(o.doc));
|
|
954
977
|
}), o;
|
|
955
978
|
};
|
|
956
979
|
|
|
957
|
-
export {
|
|
980
|
+
export { _ as Delete, E as Format, x as InsertNode, m as InsertText, yt as Redo, kt as Redoable, v as ReplaceDoc, b as ReplaceText, M as SetBlockAttr, S as ToggleBlockAttr, T as ToggleFormat, pt as Undo, ht as Undoable, xt as createEditor, Ot as createPlainEditor, St as debugPlugin, bt as fileTransferPlugin, Et as htmlTransferPlugin, Mt as internalTranferPlugin, wt as keymapPlugin, vt as plainTransferPlugin, At as singlelinePlugin };
|
|
958
981
|
//# sourceMappingURL=index.js.map
|