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