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