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