@unicom-cloud/rich-text 0.1.1
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/index.js +4928 -0
- package/package.json +1 -0
- package/style.css +2 -0
package/index.js
ADDED
|
@@ -0,0 +1,4928 @@
|
|
|
1
|
+
/* 潘启宝 2026-07-03 17:08:34 星期五 山东省济南市 */
|
|
2
|
+
import { RICH_TEXT_COMPONENT_INFO as e } from "@unicom-cloud/ui/utils/names";
|
|
3
|
+
import t, { AttributeMap as n, AttributeMap as r, Op as i, Op as a, OpIterator as o, default as s } from "@unicom-cloud/utils/delta";
|
|
4
|
+
import { createContext as c, forwardRef as l, useContext as u, useEffect as d, useImperativeHandle as ee, useRef as f } from "react";
|
|
5
|
+
import { Emitter as p } from "@unicom-cloud/ui/utils/emitter.js";
|
|
6
|
+
import te from "@unicom-cloud/ui/utils/findRootElement.js";
|
|
7
|
+
import { isArray as m, isBoolean as ne, isElementByInstanceof as h, isEqual as g, isFunction as _, isNull as v, isNumber as y, isObjectLike as b, isPresent as re, isString as x, isUndefined as S } from "@unicom-cloud/utils/is";
|
|
8
|
+
import C from "lodash/merge";
|
|
9
|
+
import { UI_PC_PREFIX as w } from "@unicom-cloud/utils/constants/ui";
|
|
10
|
+
import T from "lodash/cloneDeep";
|
|
11
|
+
import ie from "@unicom-cloud/ui/config-provider/ConfigProvider";
|
|
12
|
+
import ae from "@unicom-cloud/ui/config-provider/context";
|
|
13
|
+
import { FormContext as oe, FormItemContext as se } from "@unicom-cloud/ui/form/context";
|
|
14
|
+
import ce from "@unicom-cloud/ui/hooks/use-fullscreen";
|
|
15
|
+
import le from "@unicom-cloud/ui/hooks/use-merge-props";
|
|
16
|
+
import ue from "@unicom-cloud/ui/hooks/use-set-state";
|
|
17
|
+
import de from "@unicom-cloud/ui/input";
|
|
18
|
+
import fe from "@unicom-cloud/ui/modal";
|
|
19
|
+
import pe from "@unicom-cloud/ui/utils/className";
|
|
20
|
+
import { getBodyContainer as me } from "@unicom-cloud/ui/utils/dom";
|
|
21
|
+
import { merge as he } from "@unicom-cloud/ui/utils/lodash";
|
|
22
|
+
import { HYPHEN as ge } from "@unicom-cloud/ui/utils/string";
|
|
23
|
+
import _e from "lodash/defaultsDeep";
|
|
24
|
+
import { isMacOS as ve, isWindowsOS as E } from "@unicom-cloud/utils/constants/platform";
|
|
25
|
+
import ye from "@unicom-cloud/ui/utils/fileToDataURL.js";
|
|
26
|
+
import be from "@unicom-cloud/icons/IconUiAlignCenter";
|
|
27
|
+
import D from "@unicom-cloud/icons/IconUiAlignJustify";
|
|
28
|
+
import xe from "@unicom-cloud/icons/IconUiAlignLeft";
|
|
29
|
+
import Se from "@unicom-cloud/icons/IconUiAlignRight";
|
|
30
|
+
import Ce from "@unicom-cloud/icons/IconUiBgColors";
|
|
31
|
+
import we from "@unicom-cloud/icons/IconUiBold";
|
|
32
|
+
import Te from "@unicom-cloud/icons/IconUiCode";
|
|
33
|
+
import Ee from "@unicom-cloud/icons/IconUiCodeSquare";
|
|
34
|
+
import De from "@unicom-cloud/icons/IconUiEraser";
|
|
35
|
+
import Oe from "@unicom-cloud/icons/IconUiFaceSmileFill";
|
|
36
|
+
import ke from "@unicom-cloud/icons/IconUiFontColors";
|
|
37
|
+
import "@unicom-cloud/icons/IconUiFormula";
|
|
38
|
+
import Ae from "@unicom-cloud/icons/IconUiFullscreen";
|
|
39
|
+
import je from "@unicom-cloud/icons/IconUiFullscreenExit";
|
|
40
|
+
import Me from "@unicom-cloud/icons/IconUiImage";
|
|
41
|
+
import Ne from "@unicom-cloud/icons/IconUiItalic";
|
|
42
|
+
import Pe from "@unicom-cloud/icons/IconUiLink";
|
|
43
|
+
import Fe from "@unicom-cloud/icons/IconUiMenuFold";
|
|
44
|
+
import Ie from "@unicom-cloud/icons/IconUiMenuUnfold";
|
|
45
|
+
import Le from "@unicom-cloud/icons/IconUiMinus";
|
|
46
|
+
import Re from "@unicom-cloud/icons/IconUiOrderedList";
|
|
47
|
+
import ze from "@unicom-cloud/icons/IconUiQuote";
|
|
48
|
+
import Be from "@unicom-cloud/icons/IconUiRedo";
|
|
49
|
+
import Ve from "@unicom-cloud/icons/IconUiStrikethrough";
|
|
50
|
+
import He from "@unicom-cloud/icons/IconUiStrokeDasharray";
|
|
51
|
+
import "@unicom-cloud/icons/IconUiTable";
|
|
52
|
+
import Ue from "@unicom-cloud/icons/IconUiToLeft";
|
|
53
|
+
import We from "@unicom-cloud/icons/IconUiToRight";
|
|
54
|
+
import Ge from "@unicom-cloud/icons/IconUiUnderline";
|
|
55
|
+
import Ke from "@unicom-cloud/icons/IconUiUndo";
|
|
56
|
+
import qe from "@unicom-cloud/icons/IconUiUnorderedList";
|
|
57
|
+
import Je from "@unicom-cloud/icons/IconUiYoutube";
|
|
58
|
+
import O from "@unicom-cloud/ui/button";
|
|
59
|
+
import Ye from "@unicom-cloud/ui/color-picker";
|
|
60
|
+
import Xe from "@unicom-cloud/ui/flex";
|
|
61
|
+
import Ze from "@unicom-cloud/ui/popover";
|
|
62
|
+
import Qe from "@unicom-cloud/ui/select";
|
|
63
|
+
import { isEmoji as $e } from "@unicom-cloud/utils/emoji";
|
|
64
|
+
import et from "@unicom-cloud/utils/emoji/emojis";
|
|
65
|
+
import { Fragment as k, jsx as A, jsxs as j } from "react/jsx-runtime";
|
|
66
|
+
//#region \0rolldown/runtime.js
|
|
67
|
+
var tt = Object.defineProperty, nt = (e, t) => {
|
|
68
|
+
let n = {};
|
|
69
|
+
for (var r in e) tt(n, r, {
|
|
70
|
+
get: e[r],
|
|
71
|
+
enumerable: !0
|
|
72
|
+
});
|
|
73
|
+
return t || tt(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
74
|
+
}, rt = { bordered: !0 }, it = c({}), at = [
|
|
75
|
+
"error",
|
|
76
|
+
"warn",
|
|
77
|
+
"log",
|
|
78
|
+
"info"
|
|
79
|
+
], ot = "warn";
|
|
80
|
+
function st(e, ...t) {
|
|
81
|
+
ot && at.indexOf(e) <= at.indexOf(ot) && console[e](...t);
|
|
82
|
+
}
|
|
83
|
+
function M(e) {
|
|
84
|
+
return at.reduce((t, n) => (t[n] = st.bind(console, n, e), t), {});
|
|
85
|
+
}
|
|
86
|
+
M.level = (e) => {
|
|
87
|
+
ot = e;
|
|
88
|
+
}, st.level = M.level;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region libs/rich-text/core/emitter.ts
|
|
91
|
+
var ct = M("rich:events"), N = class extends p {
|
|
92
|
+
static events = {
|
|
93
|
+
EDITOR_CHANGE: "editor-change",
|
|
94
|
+
SCROLL_BEFORE_UPDATE: "scroll-before-update",
|
|
95
|
+
SCROLL_BLOT_MOUNT: "scroll-blot-mount",
|
|
96
|
+
SCROLL_BLOT_UNMOUNT: "scroll-blot-unmount",
|
|
97
|
+
SCROLL_OPTIMIZE: "scroll-optimize",
|
|
98
|
+
SCROLL_UPDATE: "scroll-update",
|
|
99
|
+
SCROLL_EMBED_UPDATE: "scroll-embed-update",
|
|
100
|
+
SELECTION_CHANGE: "selection-change",
|
|
101
|
+
TEXT_CHANGE: "text-change",
|
|
102
|
+
COMPOSITION_BEFORE_START: "composition-before-start",
|
|
103
|
+
COMPOSITION_START: "composition-start",
|
|
104
|
+
COMPOSITION_BEFORE_END: "composition-before-end",
|
|
105
|
+
COMPOSITION_END: "composition-end"
|
|
106
|
+
};
|
|
107
|
+
static sources = {
|
|
108
|
+
API: "api",
|
|
109
|
+
SILENT: "silent",
|
|
110
|
+
USER: "user"
|
|
111
|
+
};
|
|
112
|
+
domListeners = {};
|
|
113
|
+
constructor() {
|
|
114
|
+
super(), this.domListeners = {}, this.on("error", ct.error);
|
|
115
|
+
}
|
|
116
|
+
on = (...e) => super.on(...e);
|
|
117
|
+
once = (...e) => super.once(...e);
|
|
118
|
+
emit = (...e) => (ct.log.call(ct, ...e), super.emit(...e));
|
|
119
|
+
off = (...e) => super.off(...e);
|
|
120
|
+
offAll = (...e) => super.offAll(...e);
|
|
121
|
+
handleDOM = (e, ...t) => {
|
|
122
|
+
(this.domListeners[e.type] || []).forEach(({ node: n, handler: r }) => {
|
|
123
|
+
(e.target === n || n.contains(e.target)) && r(e, ...t);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
listenDOM = (e, t, n) => {
|
|
127
|
+
this.domListeners[e] || (this.domListeners[e] = []), this.domListeners[e].push({
|
|
128
|
+
node: t,
|
|
129
|
+
handler: n
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
destroy = () => {
|
|
133
|
+
super.destroy(), this.off("error", ct.error), this.offAll();
|
|
134
|
+
};
|
|
135
|
+
}, P = class {
|
|
136
|
+
rich;
|
|
137
|
+
options;
|
|
138
|
+
static DEFAULTS = {};
|
|
139
|
+
constructor(e, t = {}) {
|
|
140
|
+
this.rich = e, this.options = t;
|
|
141
|
+
}
|
|
142
|
+
destroy() {}
|
|
143
|
+
}, F = `${w}-rich-text`, I = /* @__PURE__ */ function(e) {
|
|
144
|
+
return e[e.TYPE = 3] = "TYPE", e[e.LEVEL = 12] = "LEVEL", e[e.ATTRIBUTE = 13] = "ATTRIBUTE", e[e.BLOT = 14] = "BLOT", e[e.INLINE = 7] = "INLINE", e[e.BLOCK = 11] = "BLOCK", e[e.BLOCK_BLOT = 10] = "BLOCK_BLOT", e[e.INLINE_BLOT = 6] = "INLINE_BLOT", e[e.BLOCK_ATTRIBUTE = 9] = "BLOCK_ATTRIBUTE", e[e.INLINE_ATTRIBUTE = 5] = "INLINE_ATTRIBUTE", e[e.ANY = 15] = "ANY", e;
|
|
145
|
+
}(I || {}), lt = class {
|
|
146
|
+
head;
|
|
147
|
+
tail;
|
|
148
|
+
length;
|
|
149
|
+
constructor() {
|
|
150
|
+
this.head = null, this.tail = null, this.length = 0;
|
|
151
|
+
}
|
|
152
|
+
append(...e) {
|
|
153
|
+
if (this.insertBefore(e[0], null), e.length > 1) {
|
|
154
|
+
let t = e.slice(1);
|
|
155
|
+
this.append(...t);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
at(e) {
|
|
159
|
+
let t = this.iterator(), n = t();
|
|
160
|
+
for (; n && e > 0;) --e, n = t();
|
|
161
|
+
return n;
|
|
162
|
+
}
|
|
163
|
+
contains(e) {
|
|
164
|
+
let t = this.iterator(), n = t();
|
|
165
|
+
for (; n;) {
|
|
166
|
+
if (n === e) return !0;
|
|
167
|
+
n = t();
|
|
168
|
+
}
|
|
169
|
+
return !1;
|
|
170
|
+
}
|
|
171
|
+
indexOf(e) {
|
|
172
|
+
let t = this.iterator(), n = t(), r = 0;
|
|
173
|
+
for (; n;) {
|
|
174
|
+
if (n === e) return r;
|
|
175
|
+
r += 1, n = t();
|
|
176
|
+
}
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
insertBefore(e, t) {
|
|
180
|
+
e != null && (this.remove(e), e.next = t, t == null ? this.tail == null ? (e.prev = null, this.head = this.tail = e) : (this.tail.next = e, e.prev = this.tail, this.tail = e) : (e.prev = t.prev, t.prev != null && (t.prev.next = e), t.prev = e, t === this.head && (this.head = e)), this.length += 1);
|
|
181
|
+
}
|
|
182
|
+
offset(e) {
|
|
183
|
+
let t = 0, n = this.head;
|
|
184
|
+
for (; n != null;) {
|
|
185
|
+
if (n === e) return t;
|
|
186
|
+
t += n.length(), n = n.next;
|
|
187
|
+
}
|
|
188
|
+
return -1;
|
|
189
|
+
}
|
|
190
|
+
remove(e) {
|
|
191
|
+
this.contains(e) && (e.prev != null && (e.prev.next = e.next), e.next != null && (e.next.prev = e.prev), e === this.head && (this.head = e.next), e === this.tail && (this.tail = e.prev), --this.length);
|
|
192
|
+
}
|
|
193
|
+
iterator(e = this.head) {
|
|
194
|
+
return () => {
|
|
195
|
+
let t = e;
|
|
196
|
+
return e != null && (e = e.next), t;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
find(e, t = !1) {
|
|
200
|
+
let n = this.iterator(), r = n();
|
|
201
|
+
for (; r;) {
|
|
202
|
+
let i = r.length();
|
|
203
|
+
if (e < i || t && e === i && (r.next == null || r.next.length() !== 0)) return [r, e];
|
|
204
|
+
e -= i, r = n();
|
|
205
|
+
}
|
|
206
|
+
return [null, 0];
|
|
207
|
+
}
|
|
208
|
+
forEach(e) {
|
|
209
|
+
let t = this.iterator(), n = t();
|
|
210
|
+
for (; n;) e(n), n = t();
|
|
211
|
+
}
|
|
212
|
+
forEachAt(e, t, n) {
|
|
213
|
+
if (t <= 0) return;
|
|
214
|
+
let [r, i] = this.find(e), a = e - i, o = this.iterator(r), s = o();
|
|
215
|
+
for (; s && a < e + t;) {
|
|
216
|
+
let r = s.length();
|
|
217
|
+
e > a ? n(s, e - a, Math.min(t, a + r - e)) : n(s, 0, Math.min(r, e + t - a)), a += r, s = o();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
map(e) {
|
|
221
|
+
return this.reduce((t, n) => (t.push(e(n)), t), []);
|
|
222
|
+
}
|
|
223
|
+
reduce(e, t) {
|
|
224
|
+
let n = this.iterator(), r = n();
|
|
225
|
+
for (; r;) t = e(t, r), r = n();
|
|
226
|
+
return t;
|
|
227
|
+
}
|
|
228
|
+
}, ut = class extends Error {
|
|
229
|
+
message;
|
|
230
|
+
name;
|
|
231
|
+
stack;
|
|
232
|
+
constructor(e) {
|
|
233
|
+
e = "[Parchment] " + e, super(e), this.message = e, this.name = this.constructor.name;
|
|
234
|
+
}
|
|
235
|
+
}, dt = class e {
|
|
236
|
+
static blots = /* @__PURE__ */ new WeakMap();
|
|
237
|
+
static find(e, t = !1) {
|
|
238
|
+
if (e == null) return null;
|
|
239
|
+
if (this.blots.has(e)) return this.blots.get(e) || null;
|
|
240
|
+
if (t) {
|
|
241
|
+
let n = null;
|
|
242
|
+
try {
|
|
243
|
+
n = e.parentNode;
|
|
244
|
+
} catch {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return this.find(n, t);
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
#e = {};
|
|
252
|
+
#t = {};
|
|
253
|
+
#n = {};
|
|
254
|
+
#r = {};
|
|
255
|
+
create(t, n, r) {
|
|
256
|
+
let i = this.query(n);
|
|
257
|
+
if (i == null) throw new ut(`Unable to create ${n} blot`);
|
|
258
|
+
let a = i, o = new a(t, n instanceof Node || n.nodeType === Node.TEXT_NODE ? n : a.create(r), r);
|
|
259
|
+
return e.blots.set(o.domNode, o), o;
|
|
260
|
+
}
|
|
261
|
+
find(t, n = !1) {
|
|
262
|
+
return e.find(t, n);
|
|
263
|
+
}
|
|
264
|
+
query(e, t = I.ANY) {
|
|
265
|
+
let n;
|
|
266
|
+
return x(e) ? n = this.#r[e] || this.#e[e] : e instanceof Text || e.nodeType === Node.TEXT_NODE ? n = this.#r.text : y(e) ? e & I.LEVEL & I.BLOCK ? n = this.#r.block : e & I.LEVEL & I.INLINE && (n = this.#r.inline) : h(e) && ((e.getAttribute("class") || "").split(/\s+/).some((e) => (n = this.#t[e], !!n)), n ||= this.#n[e.tagName]), n == null ? null : "scope" in n && t & I.LEVEL & n.scope && t & I.TYPE & n.scope ? n : null;
|
|
267
|
+
}
|
|
268
|
+
register(...e) {
|
|
269
|
+
return e.map((e) => {
|
|
270
|
+
let t = "blotName" in e, n = "attrName" in e;
|
|
271
|
+
if (!t && !n) throw new ut("Invalid definition");
|
|
272
|
+
if (t && e.blotName === "abstract") throw new ut("Cannot register abstract class");
|
|
273
|
+
let r = t ? e.blotName : n ? e.attrName : void 0;
|
|
274
|
+
return this.#r[r] = e, n ? x(e.keyName) && (this.#e[e.keyName] = e) : t && (e.className && (this.#t[e.className] = e), e.tagName && (m(e.tagName) ? e.tagName = e.tagName.map((e) => e.toUpperCase()) : e.tagName = e.tagName.toUpperCase(), (m(e.tagName) ? e.tagName : [e.tagName]).forEach((t) => {
|
|
275
|
+
(this.#n[t] == null || e.className == null) && (this.#n[t] = e);
|
|
276
|
+
}))), e;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}, ft = class {
|
|
280
|
+
scroll;
|
|
281
|
+
domNode;
|
|
282
|
+
static blotName = "abstract";
|
|
283
|
+
static className;
|
|
284
|
+
static requiredContainer;
|
|
285
|
+
static scope;
|
|
286
|
+
static tagName;
|
|
287
|
+
static create(e) {
|
|
288
|
+
if (this.tagName == null) throw new ut("Blot definition missing tagName");
|
|
289
|
+
let t, n;
|
|
290
|
+
return m(this.tagName) ? (x(e) ? (n = e.toUpperCase(), parseInt(n, 10).toString() === n && (n = parseInt(n, 10))) : y(e) && (n = e), t = y(n) ? document.createElement(this.tagName[n - 1]) : n && this.tagName.includes(n) ? document.createElement(n) : document.createElement(this.tagName[0])) : t = document.createElement(this.tagName), this.className && t.classList.add(this.className), t;
|
|
291
|
+
}
|
|
292
|
+
prev;
|
|
293
|
+
next;
|
|
294
|
+
parent;
|
|
295
|
+
get statics() {
|
|
296
|
+
return this.constructor;
|
|
297
|
+
}
|
|
298
|
+
constructor(e, t) {
|
|
299
|
+
this.scroll = e, this.domNode = t, dt.blots.set(t, this), this.prev = null, this.next = null;
|
|
300
|
+
}
|
|
301
|
+
attach() {}
|
|
302
|
+
clone() {
|
|
303
|
+
let e = this.domNode.cloneNode(!1);
|
|
304
|
+
return this.scroll.create(e);
|
|
305
|
+
}
|
|
306
|
+
detach() {
|
|
307
|
+
this.parent != null && this.parent.removeChild(this), dt.blots.delete(this.domNode);
|
|
308
|
+
}
|
|
309
|
+
deleteAt(e, t) {
|
|
310
|
+
this.isolate(e, t).remove();
|
|
311
|
+
}
|
|
312
|
+
formatAt(e, t, n, r) {
|
|
313
|
+
let i = this.isolate(e, t);
|
|
314
|
+
if (this.scroll.query(n, I.BLOT) != null && r) i.wrap(n, r);
|
|
315
|
+
else if (this.scroll.query(n, I.ATTRIBUTE) != null) {
|
|
316
|
+
let e = this.scroll.create(this.statics.scope);
|
|
317
|
+
i.wrap(e), e.format(n, r);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
insertAt(e, t, n) {
|
|
321
|
+
let r = n == null ? this.scroll.create("text", t) : this.scroll.create(t, n), i = this.split(e);
|
|
322
|
+
this.parent.insertBefore(r, i || void 0);
|
|
323
|
+
}
|
|
324
|
+
isolate(e, t) {
|
|
325
|
+
let n = this.split(e);
|
|
326
|
+
if (n == null) throw Error("Attempt to isolate at end");
|
|
327
|
+
return n.split(t), n;
|
|
328
|
+
}
|
|
329
|
+
length() {
|
|
330
|
+
return 1;
|
|
331
|
+
}
|
|
332
|
+
offset(e = this.parent) {
|
|
333
|
+
return this.parent == null || this === e ? 0 : this.parent.children.offset(this) + this.parent.offset(e);
|
|
334
|
+
}
|
|
335
|
+
optimize(e) {
|
|
336
|
+
this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer) && this.wrap(this.statics.requiredContainer.blotName);
|
|
337
|
+
}
|
|
338
|
+
remove() {
|
|
339
|
+
this.domNode.parentNode != null && this.domNode.parentNode.removeChild(this.domNode), this.detach();
|
|
340
|
+
}
|
|
341
|
+
replaceWith(e, t) {
|
|
342
|
+
let n = x(e) ? this.scroll.create(e, t) : e;
|
|
343
|
+
return this.parent != null && (this.parent.insertBefore(n, this.next || void 0), this.remove()), n;
|
|
344
|
+
}
|
|
345
|
+
split(e, t) {
|
|
346
|
+
return e === 0 ? this : this.next;
|
|
347
|
+
}
|
|
348
|
+
update(e, t) {}
|
|
349
|
+
wrap(e, t) {
|
|
350
|
+
let n = x(e) ? this.scroll.create(e, t) : e;
|
|
351
|
+
if (this.parent != null && this.parent.insertBefore(n, this.next || void 0), !_(n.appendChild)) throw new ut(`Cannot wrap ${e}`);
|
|
352
|
+
return n.appendChild(this), n;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region libs/rich-text/parchment/blot/abstract/parent.ts
|
|
357
|
+
function pt(e, t) {
|
|
358
|
+
let n = t.find(e);
|
|
359
|
+
if (n) return n;
|
|
360
|
+
try {
|
|
361
|
+
return t.create(e);
|
|
362
|
+
} catch {
|
|
363
|
+
let n = t.create(I.INLINE);
|
|
364
|
+
return Array.from(e.childNodes).forEach((e) => {
|
|
365
|
+
n.domNode.appendChild(e);
|
|
366
|
+
}), e.parentNode && e.parentNode.replaceChild(n.domNode, e), n.attach(), n;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
var L = class e extends ft {
|
|
370
|
+
static allowedChildren;
|
|
371
|
+
static defaultChild;
|
|
372
|
+
static uiClass = "";
|
|
373
|
+
children;
|
|
374
|
+
domNode;
|
|
375
|
+
uiNode = null;
|
|
376
|
+
constructor(e, t) {
|
|
377
|
+
super(e, t), this.build();
|
|
378
|
+
}
|
|
379
|
+
appendChild(e) {
|
|
380
|
+
this.insertBefore(e);
|
|
381
|
+
}
|
|
382
|
+
attach() {
|
|
383
|
+
super.attach(), this.children.forEach((e) => {
|
|
384
|
+
e.attach();
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
attachUI(t) {
|
|
388
|
+
this.uiNode != null && this.uiNode.remove(), this.uiNode = t, e.uiClass && this.uiNode.classList.add(e.uiClass), this.uiNode.setAttribute("contenteditable", "false"), this.domNode.insertBefore(this.uiNode, this.domNode.firstChild);
|
|
389
|
+
}
|
|
390
|
+
build() {
|
|
391
|
+
this.children = new lt(), Array.from(this.domNode.childNodes).filter((e) => e !== this.uiNode).reverse().forEach((e) => {
|
|
392
|
+
try {
|
|
393
|
+
let t = pt(e, this.scroll);
|
|
394
|
+
this.insertBefore(t, this.children.head || void 0);
|
|
395
|
+
} catch (e) {
|
|
396
|
+
if (e instanceof ut) return;
|
|
397
|
+
throw e;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
deleteAt(e, t) {
|
|
402
|
+
if (e === 0 && t === this.length()) return this.remove();
|
|
403
|
+
this.children.forEachAt(e, t, (e, t, n) => {
|
|
404
|
+
e.deleteAt(t, n);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
descendant(t, n = 0) {
|
|
408
|
+
let [r, i] = this.children.find(n);
|
|
409
|
+
return t.blotName == null && t(r) || t.blotName != null && r instanceof t ? [r, i] : r instanceof e ? r.descendant(t, i) : [null, -1];
|
|
410
|
+
}
|
|
411
|
+
descendants(t, n = 0, r = Number.MAX_VALUE) {
|
|
412
|
+
let i = [], a = r;
|
|
413
|
+
return this.children.forEachAt(n, r, (n, r, o) => {
|
|
414
|
+
(t.blotName == null && t(n) || t.blotName != null && n instanceof t) && i.push(n), n instanceof e && (i = i.concat(n.descendants(t, r, a))), a -= o;
|
|
415
|
+
}), i;
|
|
416
|
+
}
|
|
417
|
+
detach() {
|
|
418
|
+
this.children.forEach((e) => {
|
|
419
|
+
e.detach();
|
|
420
|
+
}), super.detach();
|
|
421
|
+
}
|
|
422
|
+
enforceAllowedChildren() {
|
|
423
|
+
let t = !1;
|
|
424
|
+
this.children.forEach((n) => {
|
|
425
|
+
t || this.statics.allowedChildren.some((e) => n instanceof e) || (n.statics.scope === I.BLOCK_BLOT ? (n.next != null && this.splitAfter(n), n.prev != null && this.splitAfter(n.prev), n.parent.unwrap(), t = !0) : n instanceof e ? n.unwrap() : n.remove());
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
formatAt(e, t, n, r) {
|
|
429
|
+
this.children.forEachAt(e, t, (e, t, i) => {
|
|
430
|
+
e.formatAt(t, i, n, r);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
insertAt(e, t, n) {
|
|
434
|
+
let [r, i] = this.children.find(e);
|
|
435
|
+
if (r) r.insertAt(i, t, n);
|
|
436
|
+
else {
|
|
437
|
+
let e = n == null ? this.scroll.create("text", t) : this.scroll.create(t, n);
|
|
438
|
+
this.appendChild(e);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
insertBefore(e, t) {
|
|
442
|
+
e.parent != null && e.parent.children.remove(e);
|
|
443
|
+
let n = null;
|
|
444
|
+
this.children.insertBefore(e, t || null), e.parent = this, t != null && (n = t.domNode), (this.domNode.parentNode !== e.domNode || this.domNode.nextSibling !== n) && this.domNode.insertBefore(e.domNode, n), e.attach();
|
|
445
|
+
}
|
|
446
|
+
length() {
|
|
447
|
+
return this.children.reduce((e, t) => e + t.length(), 0);
|
|
448
|
+
}
|
|
449
|
+
moveChildren(e, t) {
|
|
450
|
+
this.children.forEach((n) => {
|
|
451
|
+
e.insertBefore(n, t);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
optimize(e) {
|
|
455
|
+
if (super.optimize(e), this.enforceAllowedChildren(), this.uiNode != null && this.uiNode !== this.domNode.firstChild && this.domNode.insertBefore(this.uiNode, this.domNode.firstChild), this.children.length === 0) if (this.statics.defaultChild != null) {
|
|
456
|
+
let e = this.scroll.create(this.statics.defaultChild.blotName);
|
|
457
|
+
this.appendChild(e);
|
|
458
|
+
} else this.remove();
|
|
459
|
+
}
|
|
460
|
+
path(t, n = !1) {
|
|
461
|
+
let [r, i] = this.children.find(t, n), a = [[this, t]];
|
|
462
|
+
return r instanceof e ? a.concat(r.path(i, n)) : (r != null && a.push([r, i]), a);
|
|
463
|
+
}
|
|
464
|
+
removeChild(e) {
|
|
465
|
+
this.children.remove(e);
|
|
466
|
+
}
|
|
467
|
+
replaceWith(t, n) {
|
|
468
|
+
let r = x(t) ? this.scroll.create(t, n) : t;
|
|
469
|
+
return r instanceof e && this.moveChildren(r), super.replaceWith(r);
|
|
470
|
+
}
|
|
471
|
+
split(e, t = !1) {
|
|
472
|
+
if (!t) {
|
|
473
|
+
if (e === 0) return this;
|
|
474
|
+
if (e === this.length()) return this.next;
|
|
475
|
+
}
|
|
476
|
+
let n = this.clone();
|
|
477
|
+
return this.parent && this.parent.insertBefore(n, this.next || void 0), this.children.forEachAt(e, this.length(), (e, r, i) => {
|
|
478
|
+
let a = e.split(r, t);
|
|
479
|
+
a != null && n.appendChild(a);
|
|
480
|
+
}), n;
|
|
481
|
+
}
|
|
482
|
+
splitAfter(e) {
|
|
483
|
+
let t = this.clone();
|
|
484
|
+
for (; e.next != null;) t.appendChild(e.next);
|
|
485
|
+
return this.parent && this.parent.insertBefore(t, this.next || void 0), t;
|
|
486
|
+
}
|
|
487
|
+
unwrap() {
|
|
488
|
+
this.parent && this.moveChildren(this.parent, this.next || void 0), this.remove();
|
|
489
|
+
}
|
|
490
|
+
update(e, t) {
|
|
491
|
+
let n = [], r = [];
|
|
492
|
+
e.forEach((e) => {
|
|
493
|
+
e.target === this.domNode && e.type === "childList" && (n.push(...e.addedNodes), r.push(...e.removedNodes));
|
|
494
|
+
}), r.forEach((e) => {
|
|
495
|
+
if (e.parentNode != null && e.tagName !== "IFRAME" && document.body.compareDocumentPosition(e) & Node.DOCUMENT_POSITION_CONTAINED_BY) return;
|
|
496
|
+
let t = this.scroll.find(e);
|
|
497
|
+
t != null && (t.domNode.parentNode == null || t.domNode.parentNode === this.domNode) && t.detach();
|
|
498
|
+
}), n.filter((e) => e.parentNode === this.domNode && e !== this.uiNode).sort((e, t) => e === t ? 0 : e.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING ? 1 : -1).forEach((e) => {
|
|
499
|
+
let t = null;
|
|
500
|
+
e.nextSibling != null && (t = this.scroll.find(e.nextSibling));
|
|
501
|
+
let n = pt(e, this.scroll);
|
|
502
|
+
(n.next !== t || n.next == null) && (n.parent != null && n.parent.removeChild(this), this.insertBefore(n, t || void 0));
|
|
503
|
+
}), this.enforceAllowedChildren();
|
|
504
|
+
}
|
|
505
|
+
}, mt = class extends L {
|
|
506
|
+
static blotName = "container";
|
|
507
|
+
static scope = I.BLOCK_BLOT;
|
|
508
|
+
static tagName;
|
|
509
|
+
prev;
|
|
510
|
+
next;
|
|
511
|
+
checkMerge() {
|
|
512
|
+
return !v(this.next) && this.next.statics.blotName === this.statics.blotName;
|
|
513
|
+
}
|
|
514
|
+
deleteAt(e, t) {
|
|
515
|
+
super.deleteAt(e, t), this.enforceAllowedChildren();
|
|
516
|
+
}
|
|
517
|
+
formatAt(e, t, n, r) {
|
|
518
|
+
super.formatAt(e, t, n, r), this.enforceAllowedChildren();
|
|
519
|
+
}
|
|
520
|
+
insertAt(e, t, n) {
|
|
521
|
+
super.insertAt(e, t, n), this.enforceAllowedChildren();
|
|
522
|
+
}
|
|
523
|
+
optimize(e) {
|
|
524
|
+
super.optimize(e), this.children.length > 0 && this.next != null && this.checkMerge() && (this.next.moveChildren(this), this.next.remove());
|
|
525
|
+
}
|
|
526
|
+
}, R = class extends ft {
|
|
527
|
+
static scope = I.INLINE_BLOT;
|
|
528
|
+
static value(e) {
|
|
529
|
+
return !0;
|
|
530
|
+
}
|
|
531
|
+
index(e, t) {
|
|
532
|
+
return this.domNode === e || this.domNode.compareDocumentPosition(e) & Node.DOCUMENT_POSITION_CONTAINED_BY ? Math.min(t, 1) : -1;
|
|
533
|
+
}
|
|
534
|
+
position(e, t) {
|
|
535
|
+
let n = Array.from(this.parent.domNode.childNodes).indexOf(this.domNode);
|
|
536
|
+
return e > 0 && (n += 1), [this.parent.domNode, n];
|
|
537
|
+
}
|
|
538
|
+
value() {
|
|
539
|
+
return { [this.statics.blotName]: this.statics.value(this.domNode) || !0 };
|
|
540
|
+
}
|
|
541
|
+
}, z = class {
|
|
542
|
+
attrName;
|
|
543
|
+
keyName;
|
|
544
|
+
static keys(e) {
|
|
545
|
+
return Array.from(e.attributes).map((e) => e.name);
|
|
546
|
+
}
|
|
547
|
+
scope;
|
|
548
|
+
whitelist;
|
|
549
|
+
constructor(e, t, n = {}) {
|
|
550
|
+
this.attrName = e, this.keyName = t;
|
|
551
|
+
let r = I.TYPE & I.ATTRIBUTE;
|
|
552
|
+
this.scope = n.scope == null ? I.ATTRIBUTE : n.scope & I.LEVEL | r, n.whitelist != null && (this.whitelist = n.whitelist);
|
|
553
|
+
}
|
|
554
|
+
add(e, t) {
|
|
555
|
+
return this.canAdd(e, t) ? (e.setAttribute(this.keyName, t), !0) : !1;
|
|
556
|
+
}
|
|
557
|
+
canAdd(e, t) {
|
|
558
|
+
return this.whitelist == null ? !0 : x(t) ? this.whitelist.includes(t.replace(/["']/g, "")) : this.whitelist.includes(t);
|
|
559
|
+
}
|
|
560
|
+
remove(e) {
|
|
561
|
+
e.removeAttribute(this.keyName);
|
|
562
|
+
}
|
|
563
|
+
value(e) {
|
|
564
|
+
let t = e.getAttribute(this.keyName);
|
|
565
|
+
return this.canAdd(e, t) && t ? t : "";
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region libs/rich-text/parchment/attributor/class.ts
|
|
570
|
+
function ht(e, t) {
|
|
571
|
+
return (e.getAttribute("class") || "").split(/\s+/).filter((e) => e.startsWith(`${t}-`));
|
|
572
|
+
}
|
|
573
|
+
var B = class extends z {
|
|
574
|
+
static keys(e) {
|
|
575
|
+
return (e.getAttribute("class") || "").split(/\s+/).map((e) => e.split("-").slice(0, -1).join("-"));
|
|
576
|
+
}
|
|
577
|
+
add(e, t) {
|
|
578
|
+
return this.canAdd(e, t) ? (this.remove(e), e.classList.add(`${this.keyName}-${t}`), !0) : !1;
|
|
579
|
+
}
|
|
580
|
+
remove(e) {
|
|
581
|
+
ht(e, this.keyName).forEach((t) => {
|
|
582
|
+
e.classList.remove(t);
|
|
583
|
+
}), e.classList.length === 0 && e.removeAttribute("class");
|
|
584
|
+
}
|
|
585
|
+
value(e) {
|
|
586
|
+
let t = (ht(e, this.keyName)[0] || "").slice(this.keyName.length + 1);
|
|
587
|
+
return this.canAdd(e, t) ? t : "";
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region libs/rich-text/parchment/attributor/style.ts
|
|
592
|
+
function gt(e) {
|
|
593
|
+
let t = e.split("-"), n = t.slice(1).map((e) => e[0].toUpperCase() + e.slice(1)).join("");
|
|
594
|
+
return t[0] + n;
|
|
595
|
+
}
|
|
596
|
+
var _t = class extends z {
|
|
597
|
+
static keys(e) {
|
|
598
|
+
return (e.getAttribute("style") || "").split(";").map((e) => e.split(":")[0].trim());
|
|
599
|
+
}
|
|
600
|
+
add(e, t) {
|
|
601
|
+
return this.canAdd(e, t) ? (e.style[gt(this.keyName)] = t, !0) : !1;
|
|
602
|
+
}
|
|
603
|
+
remove(e) {
|
|
604
|
+
e.style[gt(this.keyName)] = "", e.getAttribute("style") || e.removeAttribute("style");
|
|
605
|
+
}
|
|
606
|
+
value(e) {
|
|
607
|
+
let t = e.style[gt(this.keyName)];
|
|
608
|
+
return this.canAdd(e, t) ? t : "";
|
|
609
|
+
}
|
|
610
|
+
}, vt = class {
|
|
611
|
+
#e = {};
|
|
612
|
+
#t;
|
|
613
|
+
constructor(e) {
|
|
614
|
+
this.#t = e, this.build();
|
|
615
|
+
}
|
|
616
|
+
attribute(e, t) {
|
|
617
|
+
t ? e.add(this.#t, t) && (e.value(this.#t) == null ? delete this.#e[e.attrName] : this.#e[e.attrName] = e) : (e.remove(this.#t), delete this.#e[e.attrName]);
|
|
618
|
+
}
|
|
619
|
+
build() {
|
|
620
|
+
this.#e = {};
|
|
621
|
+
let e = dt.find(this.#t);
|
|
622
|
+
if (e == null) return;
|
|
623
|
+
let t = z.keys(this.#t), n = B.keys(this.#t), r = _t.keys(this.#t);
|
|
624
|
+
t.concat(n).concat(r).forEach((t) => {
|
|
625
|
+
let n = e.scroll.query(t, I.ATTRIBUTE);
|
|
626
|
+
n instanceof z && (this.#e[n.attrName] = n);
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
copy(e) {
|
|
630
|
+
Object.keys(this.#e).forEach((t) => {
|
|
631
|
+
let n = this.#e[t].value(this.#t);
|
|
632
|
+
e.format(t, n);
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
move(e) {
|
|
636
|
+
this.copy(e), Object.keys(this.#e).forEach((e) => {
|
|
637
|
+
this.#e[e].remove(this.#t);
|
|
638
|
+
}), this.#e = {};
|
|
639
|
+
}
|
|
640
|
+
values() {
|
|
641
|
+
return Object.keys(this.#e).reduce((e, t) => (e[t] = this.#e[t].value(this.#t), e), {});
|
|
642
|
+
}
|
|
643
|
+
}, yt = class e extends L {
|
|
644
|
+
static allowedChildren = [e, R];
|
|
645
|
+
static blotName = "inline";
|
|
646
|
+
static scope = I.INLINE_BLOT;
|
|
647
|
+
static tagName = "SPAN";
|
|
648
|
+
static create(e) {
|
|
649
|
+
return super.create(e);
|
|
650
|
+
}
|
|
651
|
+
static formats(t, n) {
|
|
652
|
+
let r = n.query(e.blotName);
|
|
653
|
+
if (!(r != null && t.tagName === r.tagName)) {
|
|
654
|
+
if (x(this.tagName)) return !0;
|
|
655
|
+
if (m(this.tagName)) return t.tagName.toLowerCase();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
attributes;
|
|
659
|
+
constructor(e, t) {
|
|
660
|
+
super(e, t), this.attributes = new vt(this.domNode);
|
|
661
|
+
}
|
|
662
|
+
format(t, n) {
|
|
663
|
+
if (t === this.statics.blotName && !n) this.children.forEach((t) => {
|
|
664
|
+
t instanceof e || (t = t.wrap(e.blotName, !0)), this.attributes.copy(t);
|
|
665
|
+
}), this.unwrap();
|
|
666
|
+
else {
|
|
667
|
+
let e = this.scroll.query(t, I.INLINE);
|
|
668
|
+
if (e == null) return;
|
|
669
|
+
e instanceof z ? this.attributes.attribute(e, n) : n && (t !== this.statics.blotName || this.formats()[t] !== n) && this.replaceWith(t, n);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
formats() {
|
|
673
|
+
let e = this.attributes.values(), t = this.statics.formats(this.domNode, this.scroll);
|
|
674
|
+
return t != null && (e[this.statics.blotName] = t), e;
|
|
675
|
+
}
|
|
676
|
+
formatAt(e, t, n, r) {
|
|
677
|
+
this.formats()[n] != null || this.scroll.query(n, I.ATTRIBUTE) ? this.isolate(e, t).format(n, r) : super.formatAt(e, t, n, r);
|
|
678
|
+
}
|
|
679
|
+
optimize(t) {
|
|
680
|
+
super.optimize(t);
|
|
681
|
+
let n = this.formats();
|
|
682
|
+
if (Object.keys(n).length === 0) return this.unwrap();
|
|
683
|
+
let r = this.next;
|
|
684
|
+
r instanceof e && r.prev === this && g(n, r.formats()) && (r.moveChildren(this), r.remove());
|
|
685
|
+
}
|
|
686
|
+
replaceWith(e, t) {
|
|
687
|
+
let n = super.replaceWith(e, t);
|
|
688
|
+
return this.attributes.copy(n), n;
|
|
689
|
+
}
|
|
690
|
+
update(e, t) {
|
|
691
|
+
super.update(e, t), e.some((e) => e.target === this.domNode && e.type === "attributes") && this.attributes.build();
|
|
692
|
+
}
|
|
693
|
+
wrap(t, n) {
|
|
694
|
+
let r = super.wrap(t, n);
|
|
695
|
+
return r instanceof e && this.attributes.move(r), r;
|
|
696
|
+
}
|
|
697
|
+
}, bt = class e extends L {
|
|
698
|
+
static blotName = "block";
|
|
699
|
+
static scope = I.BLOCK_BLOT;
|
|
700
|
+
static tagName = "P";
|
|
701
|
+
static allowedChildren = [
|
|
702
|
+
yt,
|
|
703
|
+
e,
|
|
704
|
+
R
|
|
705
|
+
];
|
|
706
|
+
static create(e) {
|
|
707
|
+
return super.create(e);
|
|
708
|
+
}
|
|
709
|
+
static formats(t, n) {
|
|
710
|
+
let r = n.query(e.blotName);
|
|
711
|
+
if (!(r != null && t.tagName === r.tagName)) {
|
|
712
|
+
if (x(this.tagName)) return !0;
|
|
713
|
+
if (m(this.tagName)) return t.tagName.toLowerCase();
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
attributes;
|
|
717
|
+
constructor(e, t) {
|
|
718
|
+
super(e, t), this.attributes = new vt(this.domNode);
|
|
719
|
+
}
|
|
720
|
+
format(t, n) {
|
|
721
|
+
let r = this.scroll.query(t, I.BLOCK);
|
|
722
|
+
r != null && (r instanceof z ? this.attributes.attribute(r, n) : t === this.statics.blotName && !n ? this.replaceWith(e.blotName) : n && (t !== this.statics.blotName || this.formats()[t] !== n) && this.replaceWith(t, n));
|
|
723
|
+
}
|
|
724
|
+
formats() {
|
|
725
|
+
let e = this.attributes.values(), t = this.statics.formats(this.domNode, this.scroll);
|
|
726
|
+
return t != null && (e[this.statics.blotName] = t), e;
|
|
727
|
+
}
|
|
728
|
+
formatAt(e, t, n, r) {
|
|
729
|
+
this.scroll.query(n, I.BLOCK) == null ? super.formatAt(e, t, n, r) : this.format(n, r);
|
|
730
|
+
}
|
|
731
|
+
insertAt(e, t, n) {
|
|
732
|
+
if (n == null || this.scroll.query(t, I.INLINE) != null) super.insertAt(e, t, n);
|
|
733
|
+
else {
|
|
734
|
+
let r = this.split(e);
|
|
735
|
+
if (r != null) {
|
|
736
|
+
let e = this.scroll.create(t, n);
|
|
737
|
+
r.parent.insertBefore(e, r);
|
|
738
|
+
} else throw Error("Attempt to insertAt after block boundaries");
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
replaceWith(e, t) {
|
|
742
|
+
let n = super.replaceWith(e, t);
|
|
743
|
+
return this.attributes.copy(n), n;
|
|
744
|
+
}
|
|
745
|
+
update(e, t) {
|
|
746
|
+
super.update(e, t), e.some((e) => e.target === this.domNode && e.type === "attributes") && this.attributes.build();
|
|
747
|
+
}
|
|
748
|
+
}, V = class extends R {
|
|
749
|
+
static formats(e, t) {}
|
|
750
|
+
format(e, t) {
|
|
751
|
+
super.formatAt(0, this.length(), e, t);
|
|
752
|
+
}
|
|
753
|
+
formatAt(e, t, n, r) {
|
|
754
|
+
e === 0 && t === this.length() ? this.format(n, r) : super.formatAt(e, t, n, r);
|
|
755
|
+
}
|
|
756
|
+
formats() {
|
|
757
|
+
return this.statics.formats(this.domNode, this.scroll);
|
|
758
|
+
}
|
|
759
|
+
}, xt = {
|
|
760
|
+
attributes: !0,
|
|
761
|
+
characterData: !0,
|
|
762
|
+
characterDataOldValue: !0,
|
|
763
|
+
childList: !0,
|
|
764
|
+
subtree: !0
|
|
765
|
+
}, St = 100, Ct = class extends L {
|
|
766
|
+
registry;
|
|
767
|
+
static blotName = "scroll";
|
|
768
|
+
static defaultChild = bt;
|
|
769
|
+
static allowedChildren = [bt, mt];
|
|
770
|
+
static scope = I.BLOCK_BLOT;
|
|
771
|
+
static tagName = "DIV";
|
|
772
|
+
observer;
|
|
773
|
+
constructor(e, t) {
|
|
774
|
+
super(null, t), this.registry = e, this.scroll = this, this.build(), this.observer = new MutationObserver((e) => {
|
|
775
|
+
this.update(e);
|
|
776
|
+
}), this.observer.observe(this.domNode, xt), this.attach();
|
|
777
|
+
}
|
|
778
|
+
create(e, t) {
|
|
779
|
+
return this.registry.create(this, e, t);
|
|
780
|
+
}
|
|
781
|
+
find(e, t = !1) {
|
|
782
|
+
let n = this.registry.find(e, t);
|
|
783
|
+
return n ? n.scroll === this ? n : t ? this.find(n.scroll.domNode.parentNode, !0) : null : null;
|
|
784
|
+
}
|
|
785
|
+
query(e, t = I.ANY) {
|
|
786
|
+
return this.registry.query(e, t);
|
|
787
|
+
}
|
|
788
|
+
register(...e) {
|
|
789
|
+
return this.registry.register(...e);
|
|
790
|
+
}
|
|
791
|
+
build() {
|
|
792
|
+
this.scroll != null && super.build();
|
|
793
|
+
}
|
|
794
|
+
detach() {
|
|
795
|
+
super.detach(), this.observer.disconnect();
|
|
796
|
+
}
|
|
797
|
+
deleteAt(e, t) {
|
|
798
|
+
this.update(), e === 0 && t === this.length() ? this.children.forEach((e) => {
|
|
799
|
+
e.remove();
|
|
800
|
+
}) : super.deleteAt(e, t);
|
|
801
|
+
}
|
|
802
|
+
formatAt(e, t, n, r) {
|
|
803
|
+
this.update(), super.formatAt(e, t, n, r);
|
|
804
|
+
}
|
|
805
|
+
insertAt(e, t, n) {
|
|
806
|
+
this.update(), super.insertAt(e, t, n);
|
|
807
|
+
}
|
|
808
|
+
optimize(e = [], t = {}) {
|
|
809
|
+
super.optimize(t);
|
|
810
|
+
let n = t.mutationsMap || /* @__PURE__ */ new WeakMap(), r = Array.from(this.observer.takeRecords());
|
|
811
|
+
for (; r.length > 0;) e.push(r.pop());
|
|
812
|
+
let i = (e, t = !0) => {
|
|
813
|
+
e == null || e === this || e.domNode.parentNode != null && (n.has(e.domNode) || n.set(e.domNode, []), t && i(e.parent));
|
|
814
|
+
}, a = (e) => {
|
|
815
|
+
n.has(e.domNode) && (e instanceof L && e.children.forEach(a), n.delete(e.domNode), e.optimize(t));
|
|
816
|
+
}, o = e;
|
|
817
|
+
for (let t = 0; o.length > 0; t += 1) {
|
|
818
|
+
if (t >= St) throw Error("[Parchment] Maximum optimize iterations reached");
|
|
819
|
+
for (o.forEach((e) => {
|
|
820
|
+
let t = this.find(e.target, !0);
|
|
821
|
+
t != null && (t.domNode === e.target && (e.type === "childList" ? (i(this.find(e.previousSibling, !1)), Array.from(e.addedNodes).forEach((e) => {
|
|
822
|
+
let t = this.find(e, !1);
|
|
823
|
+
i(t, !1), t instanceof L && t.children.forEach((e) => {
|
|
824
|
+
i(e, !1);
|
|
825
|
+
});
|
|
826
|
+
})) : e.type === "attributes" && i(t.prev)), i(t));
|
|
827
|
+
}), this.children.forEach(a), o = Array.from(this.observer.takeRecords()), r = o.slice(); r.length > 0;) e.push(r.pop());
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
update(e, t = {}) {
|
|
831
|
+
e ||= this.observer.takeRecords();
|
|
832
|
+
let n = /* @__PURE__ */ new WeakMap();
|
|
833
|
+
e.map((e) => {
|
|
834
|
+
let t = this.find(e.target, !0);
|
|
835
|
+
return t == null ? null : n.has(t.domNode) ? (n.get(t.domNode).push(e), null) : (n.set(t.domNode, [e]), t);
|
|
836
|
+
}).forEach((e) => {
|
|
837
|
+
e != null && e !== this && n.has(e.domNode) && e.update(n.get(e.domNode) || [], t);
|
|
838
|
+
}), t.mutationsMap = n, n.has(this.domNode) && super.update(n.get(this.domNode), t), this.optimize(e, t);
|
|
839
|
+
}
|
|
840
|
+
}, wt = class e extends R {
|
|
841
|
+
static blotName = "text";
|
|
842
|
+
static scope = I.INLINE_BLOT;
|
|
843
|
+
static create(e) {
|
|
844
|
+
return document.createTextNode(e);
|
|
845
|
+
}
|
|
846
|
+
static value(e) {
|
|
847
|
+
return e.data;
|
|
848
|
+
}
|
|
849
|
+
domNode;
|
|
850
|
+
text;
|
|
851
|
+
constructor(e, t) {
|
|
852
|
+
super(e, t), this.text = this.statics.value(this.domNode);
|
|
853
|
+
}
|
|
854
|
+
deleteAt(e, t) {
|
|
855
|
+
this.domNode.data = this.text = this.text.slice(0, e) + this.text.slice(e + t);
|
|
856
|
+
}
|
|
857
|
+
index(e, t) {
|
|
858
|
+
return this.domNode === e ? t : -1;
|
|
859
|
+
}
|
|
860
|
+
insertAt(e, t, n) {
|
|
861
|
+
n == null ? (this.text = this.text.slice(0, e) + t + this.text.slice(e), this.domNode.data = this.text) : super.insertAt(e, t, n);
|
|
862
|
+
}
|
|
863
|
+
length() {
|
|
864
|
+
return this.text.length;
|
|
865
|
+
}
|
|
866
|
+
optimize(t) {
|
|
867
|
+
super.optimize(t), this.text = this.statics.value(this.domNode), this.text.length === 0 ? this.remove() : this.next instanceof e && this.next.prev === this && (this.insertAt(this.length(), this.next.value()), this.next.remove());
|
|
868
|
+
}
|
|
869
|
+
position(e, t = !1) {
|
|
870
|
+
return [this.domNode, e];
|
|
871
|
+
}
|
|
872
|
+
split(e, t = !1) {
|
|
873
|
+
if (!t) {
|
|
874
|
+
if (e === 0) return this;
|
|
875
|
+
if (e === this.length()) return this.next;
|
|
876
|
+
}
|
|
877
|
+
let n = this.scroll.create(this.domNode.splitText(e));
|
|
878
|
+
return this.parent.insertBefore(n, this.next || void 0), this.text = this.statics.value(this.domNode), n;
|
|
879
|
+
}
|
|
880
|
+
update(e, t) {
|
|
881
|
+
e.some((e) => e.type === "characterData" && e.target === this.domNode) && (this.text = this.statics.value(this.domNode));
|
|
882
|
+
}
|
|
883
|
+
value() {
|
|
884
|
+
return this.text;
|
|
885
|
+
}
|
|
886
|
+
}, Tt = /* @__PURE__ */ nt({
|
|
887
|
+
Attributor: () => z,
|
|
888
|
+
AttributorStore: () => vt,
|
|
889
|
+
BlockBlot: () => bt,
|
|
890
|
+
ClassAttributor: () => B,
|
|
891
|
+
ContainerBlot: () => mt,
|
|
892
|
+
EmbedBlot: () => V,
|
|
893
|
+
InlineBlot: () => yt,
|
|
894
|
+
LeafBlot: () => R,
|
|
895
|
+
ParentBlot: () => L,
|
|
896
|
+
Registry: () => dt,
|
|
897
|
+
Scope: () => I,
|
|
898
|
+
ScrollBlot: () => Ct,
|
|
899
|
+
StyleAttributor: () => _t,
|
|
900
|
+
TextBlot: () => wt
|
|
901
|
+
}), H = class extends wt {}, Et = {
|
|
902
|
+
"&": "&",
|
|
903
|
+
"<": "<",
|
|
904
|
+
">": ">",
|
|
905
|
+
"\"": """,
|
|
906
|
+
"'": "'"
|
|
907
|
+
};
|
|
908
|
+
function Dt(e) {
|
|
909
|
+
return e.replace(/[&<>"']/g, (e) => Et[e]);
|
|
910
|
+
}
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region libs/rich-text/blots/embed.ts
|
|
913
|
+
var Ot = "", kt = class extends V {
|
|
914
|
+
contentNode;
|
|
915
|
+
leftGuard;
|
|
916
|
+
rightGuard;
|
|
917
|
+
constructor(e, t) {
|
|
918
|
+
super(e, t), this.contentNode = document.createElement("span"), this.contentNode.setAttribute("contenteditable", "false"), Array.from(this.domNode.childNodes).forEach((e) => {
|
|
919
|
+
this.contentNode.appendChild(e);
|
|
920
|
+
}), this.leftGuard = document.createTextNode(Ot), this.rightGuard = document.createTextNode(Ot), this.domNode.appendChild(this.leftGuard), this.domNode.appendChild(this.contentNode), this.domNode.appendChild(this.rightGuard);
|
|
921
|
+
}
|
|
922
|
+
index(e, t) {
|
|
923
|
+
return e === this.leftGuard ? 0 : e === this.rightGuard ? 1 : super.index(e, t);
|
|
924
|
+
}
|
|
925
|
+
restore(e) {
|
|
926
|
+
let t = null, n, r = e.data.split(Ot).join("");
|
|
927
|
+
if (e === this.leftGuard) if (this.prev instanceof H) {
|
|
928
|
+
let e = this.prev.length();
|
|
929
|
+
this.prev.insertAt(e, r), t = {
|
|
930
|
+
startNode: this.prev.domNode,
|
|
931
|
+
startOffset: e + r.length
|
|
932
|
+
};
|
|
933
|
+
} else n = document.createTextNode(r), this.parent.insertBefore(this.scroll.create(n), this), t = {
|
|
934
|
+
startNode: n,
|
|
935
|
+
startOffset: r.length
|
|
936
|
+
};
|
|
937
|
+
else e === this.rightGuard && (this.next instanceof H ? (this.next.insertAt(0, r), t = {
|
|
938
|
+
startNode: this.next.domNode,
|
|
939
|
+
startOffset: r.length
|
|
940
|
+
}) : (n = document.createTextNode(r), this.parent.insertBefore(this.scroll.create(n), this.next), t = {
|
|
941
|
+
startNode: n,
|
|
942
|
+
startOffset: r.length
|
|
943
|
+
}));
|
|
944
|
+
return e.data = Ot, t;
|
|
945
|
+
}
|
|
946
|
+
update(e, t) {
|
|
947
|
+
e.forEach((e) => {
|
|
948
|
+
if (e.type === "characterData" && (e.target === this.leftGuard || e.target === this.rightGuard)) {
|
|
949
|
+
let n = this.restore(e.target);
|
|
950
|
+
n && (t.range = n);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}, At = class {
|
|
955
|
+
isComposing = !1;
|
|
956
|
+
#e;
|
|
957
|
+
#t;
|
|
958
|
+
constructor(e, t) {
|
|
959
|
+
this.#e = e, this.#t = t, this.#n();
|
|
960
|
+
}
|
|
961
|
+
#n() {
|
|
962
|
+
this.#e.domNode.addEventListener("compositionstart", this.#r), this.#e.domNode.addEventListener("compositionend", this.#i);
|
|
963
|
+
}
|
|
964
|
+
#r = (e) => {
|
|
965
|
+
this.isComposing || this.#o(e);
|
|
966
|
+
};
|
|
967
|
+
#i = (e) => {
|
|
968
|
+
this.isComposing && queueMicrotask(() => {
|
|
969
|
+
this.#s(e);
|
|
970
|
+
});
|
|
971
|
+
};
|
|
972
|
+
#a() {
|
|
973
|
+
this.#e.domNode.removeEventListener("compositionstart", this.#r), this.#e.domNode.removeEventListener("compositionend", this.#i);
|
|
974
|
+
}
|
|
975
|
+
destroy() {
|
|
976
|
+
this.#a();
|
|
977
|
+
}
|
|
978
|
+
#o(e) {
|
|
979
|
+
let t = e.target instanceof Node ? this.#e.find(e.target, !0) : null;
|
|
980
|
+
t && !(t instanceof kt) && (this.#t.emit(N.events.COMPOSITION_BEFORE_START, e), this.#e.batchStart(), this.#t.emit(N.events.COMPOSITION_START, e), this.isComposing = !0);
|
|
981
|
+
}
|
|
982
|
+
#s(e) {
|
|
983
|
+
this.#t.emit(N.events.COMPOSITION_BEFORE_END, e), this.#e.batchEnd(), this.#t.emit(N.events.COMPOSITION_END, e), this.isComposing = !1;
|
|
984
|
+
}
|
|
985
|
+
}, U = class extends V {
|
|
986
|
+
static value() {}
|
|
987
|
+
optimize() {
|
|
988
|
+
(this.prev || this.next) && this.remove();
|
|
989
|
+
}
|
|
990
|
+
length() {
|
|
991
|
+
return 0;
|
|
992
|
+
}
|
|
993
|
+
value() {
|
|
994
|
+
return "";
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
U.blotName = "break", U.tagName = "BR";
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region libs/rich-text/blots/inline.ts
|
|
1000
|
+
var jt = class e extends yt {
|
|
1001
|
+
static allowedChildren = [
|
|
1002
|
+
e,
|
|
1003
|
+
U,
|
|
1004
|
+
V,
|
|
1005
|
+
H
|
|
1006
|
+
];
|
|
1007
|
+
static order = [
|
|
1008
|
+
"cursor",
|
|
1009
|
+
"inline",
|
|
1010
|
+
"link",
|
|
1011
|
+
"underline",
|
|
1012
|
+
"strike",
|
|
1013
|
+
"italic",
|
|
1014
|
+
"bold",
|
|
1015
|
+
"script",
|
|
1016
|
+
"code"
|
|
1017
|
+
];
|
|
1018
|
+
static compare(t, n) {
|
|
1019
|
+
let r = e.order.indexOf(t), i = e.order.indexOf(n);
|
|
1020
|
+
return r >= 0 || i >= 0 ? r - i : t === n ? 0 : t < n ? -1 : 1;
|
|
1021
|
+
}
|
|
1022
|
+
formatAt(t, n, r, i) {
|
|
1023
|
+
if (e.compare(this.statics.blotName, r) < 0 && this.scroll.query(r, I.BLOT)) {
|
|
1024
|
+
let e = this.isolate(t, n);
|
|
1025
|
+
i && e.wrap(r, i);
|
|
1026
|
+
} else super.formatAt(t, n, r, i);
|
|
1027
|
+
}
|
|
1028
|
+
optimize(t) {
|
|
1029
|
+
if (super.optimize(t), this.parent instanceof e && e.compare(this.statics.blotName, this.parent.statics.blotName) > 0) {
|
|
1030
|
+
let e = this.parent.isolate(this.offset(), this.length());
|
|
1031
|
+
this.moveChildren(e), e.wrap(this);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}, Mt = 1, W = class extends bt {
|
|
1035
|
+
cache = {};
|
|
1036
|
+
delta() {
|
|
1037
|
+
return this.cache.delta ?? (this.cache.delta = Nt(this)), this.cache.delta;
|
|
1038
|
+
}
|
|
1039
|
+
deleteAt(e, t) {
|
|
1040
|
+
super.deleteAt(e, t), this.cache = {};
|
|
1041
|
+
}
|
|
1042
|
+
formatAt(e, t, n, r) {
|
|
1043
|
+
t <= 0 || (this.scroll.query(n, I.BLOCK) ? e + t === this.length() && this.format(n, r) : super.formatAt(e, Math.min(t, this.length() - e - 1), n, r), this.cache = {});
|
|
1044
|
+
}
|
|
1045
|
+
insertAt(e, t, n) {
|
|
1046
|
+
if (n != null) {
|
|
1047
|
+
super.insertAt(e, t, n), this.cache = {};
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
if (t.length === 0) return;
|
|
1051
|
+
let r = t.split("\n"), i = r.shift();
|
|
1052
|
+
i.length > 0 && (e < this.length() - 1 || this.children.tail == null ? super.insertAt(Math.min(e, this.length() - 1), i) : this.children.tail.insertAt(this.children.tail.length(), i), this.cache = {});
|
|
1053
|
+
let a = this;
|
|
1054
|
+
r.reduce((e, t) => (a = a.split(e, !0), a.insertAt(0, t), t.length), e + i.length);
|
|
1055
|
+
}
|
|
1056
|
+
insertBefore(e, t) {
|
|
1057
|
+
let { head: n } = this.children;
|
|
1058
|
+
super.insertBefore(e, t), n instanceof U && n.remove(), this.cache = {};
|
|
1059
|
+
}
|
|
1060
|
+
length() {
|
|
1061
|
+
return this.cache.length ?? (this.cache.length = super.length() + Mt), this.cache.length;
|
|
1062
|
+
}
|
|
1063
|
+
moveChildren(e, t) {
|
|
1064
|
+
super.moveChildren(e, t), this.cache = {};
|
|
1065
|
+
}
|
|
1066
|
+
optimize(e) {
|
|
1067
|
+
super.optimize(e), this.cache = {};
|
|
1068
|
+
}
|
|
1069
|
+
path(e) {
|
|
1070
|
+
return super.path(e, !0);
|
|
1071
|
+
}
|
|
1072
|
+
removeChild(e) {
|
|
1073
|
+
super.removeChild(e), this.cache = {};
|
|
1074
|
+
}
|
|
1075
|
+
split(e, t = !1) {
|
|
1076
|
+
if (t && (e === 0 || e >= this.length() - Mt)) {
|
|
1077
|
+
let t = this.clone();
|
|
1078
|
+
return e === 0 ? (this.parent.insertBefore(t, this), this) : (this.parent.insertBefore(t, this.next), t);
|
|
1079
|
+
}
|
|
1080
|
+
let n = super.split(e, t);
|
|
1081
|
+
return this.cache = {}, n;
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
W.blotName = "block", W.tagName = "P", W.defaultChild = U, W.allowedChildren = [
|
|
1085
|
+
U,
|
|
1086
|
+
jt,
|
|
1087
|
+
V,
|
|
1088
|
+
H
|
|
1089
|
+
];
|
|
1090
|
+
var G = class extends V {
|
|
1091
|
+
attributes;
|
|
1092
|
+
domNode;
|
|
1093
|
+
attach() {
|
|
1094
|
+
super.attach(), this.attributes = new vt(this.domNode);
|
|
1095
|
+
}
|
|
1096
|
+
delta() {
|
|
1097
|
+
return new s().insert(this.value(), {
|
|
1098
|
+
...this.formats(),
|
|
1099
|
+
...this.attributes.values()
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
format(e, t) {
|
|
1103
|
+
let n = this.scroll.query(e, I.BLOCK_ATTRIBUTE);
|
|
1104
|
+
n != null && this.attributes.attribute(n, t);
|
|
1105
|
+
}
|
|
1106
|
+
formatAt(e, t, n, r) {
|
|
1107
|
+
this.format(n, r);
|
|
1108
|
+
}
|
|
1109
|
+
insertAt(e, t, n) {
|
|
1110
|
+
if (n != null) {
|
|
1111
|
+
super.insertAt(e, t, n);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
let r = t.split("\n"), i = r.pop(), a = r.map((e) => {
|
|
1115
|
+
let t = this.scroll.create(W.blotName);
|
|
1116
|
+
return t.insertAt(0, e), t;
|
|
1117
|
+
}), o = this.split(e);
|
|
1118
|
+
a.forEach((e) => {
|
|
1119
|
+
this.parent.insertBefore(e, o);
|
|
1120
|
+
}), i && this.parent.insertBefore(this.scroll.create("text", i), o);
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
G.scope = I.BLOCK_BLOT;
|
|
1124
|
+
function Nt(e, t = !0) {
|
|
1125
|
+
return e.descendants(R).reduce((e, n) => n.length() === 0 ? e : e.insert(n.value(), K(n, {}, t)), new s()).insert("\n", K(e));
|
|
1126
|
+
}
|
|
1127
|
+
function K(e, t = {}, n = !0) {
|
|
1128
|
+
return e == null || ("formats" in e && _(e.formats) && (t = {
|
|
1129
|
+
...t,
|
|
1130
|
+
...e.formats()
|
|
1131
|
+
}, n && delete t["code-token"]), e.parent == null || e.parent.statics.blotName === "scroll" || e.parent.statics.scope !== e.statics.scope) ? t : K(e.parent, t, n);
|
|
1132
|
+
}
|
|
1133
|
+
//#endregion
|
|
1134
|
+
//#region libs/rich-text/blots/cursor.ts
|
|
1135
|
+
var Pt = class e extends V {
|
|
1136
|
+
static blotName = "cursor";
|
|
1137
|
+
static className = `${F}-cursor`;
|
|
1138
|
+
static tagName = "span";
|
|
1139
|
+
static CONTENTS = "";
|
|
1140
|
+
static value() {}
|
|
1141
|
+
selection;
|
|
1142
|
+
textNode;
|
|
1143
|
+
savedLength;
|
|
1144
|
+
constructor(t, n, r) {
|
|
1145
|
+
super(t, n), this.selection = r, this.textNode = document.createTextNode(e.CONTENTS), this.domNode.appendChild(this.textNode), this.savedLength = 0;
|
|
1146
|
+
}
|
|
1147
|
+
detach() {
|
|
1148
|
+
this.parent != null && this.parent.removeChild(this);
|
|
1149
|
+
}
|
|
1150
|
+
format(t, n) {
|
|
1151
|
+
if (this.savedLength !== 0) {
|
|
1152
|
+
super.format(t, n);
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
let r = this, i = 0;
|
|
1156
|
+
for (; r != null && r.statics.scope !== I.BLOCK_BLOT;) i += r.offset(r.parent), r = r.parent;
|
|
1157
|
+
r != null && (this.savedLength = e.CONTENTS.length, r.optimize(), r.formatAt(i, e.CONTENTS.length, t, n), this.savedLength = 0);
|
|
1158
|
+
}
|
|
1159
|
+
index(e, t) {
|
|
1160
|
+
return e === this.textNode ? 0 : super.index(e, t);
|
|
1161
|
+
}
|
|
1162
|
+
length() {
|
|
1163
|
+
return this.savedLength;
|
|
1164
|
+
}
|
|
1165
|
+
position() {
|
|
1166
|
+
return [this.textNode, this.textNode.data.length];
|
|
1167
|
+
}
|
|
1168
|
+
remove() {
|
|
1169
|
+
super.remove(), this.parent = null;
|
|
1170
|
+
}
|
|
1171
|
+
restore() {
|
|
1172
|
+
if (this.selection.composing || this.parent == null) return null;
|
|
1173
|
+
let t = this.selection.getNativeRange();
|
|
1174
|
+
for (; this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode;) this.domNode.parentNode.insertBefore(this.domNode.lastChild, this.domNode);
|
|
1175
|
+
let n = this.prev instanceof H ? this.prev : null, r = n ? n.length() : 0, i = this.next instanceof H ? this.next : null, a = i ? i.text : "", { textNode: o } = this, s = o.data.split(e.CONTENTS).join("");
|
|
1176
|
+
o.data = e.CONTENTS;
|
|
1177
|
+
let c;
|
|
1178
|
+
if (n) c = n, (s || i) && (n.insertAt(n.length(), s + a), i && i.remove());
|
|
1179
|
+
else if (i) c = i, i.insertAt(0, s);
|
|
1180
|
+
else {
|
|
1181
|
+
let e = document.createTextNode(s);
|
|
1182
|
+
c = this.scroll.create(e), this.parent.insertBefore(c, this);
|
|
1183
|
+
}
|
|
1184
|
+
if (this.remove(), t) {
|
|
1185
|
+
let e = (e, t) => n && e === n.domNode ? t : e === o ? r + t - 1 : i && e === i.domNode ? r + s.length + t : null, a = e(t.start.node, t.start.offset), l = e(t.end.node, t.end.offset);
|
|
1186
|
+
if (!v(a) && !v(l)) return {
|
|
1187
|
+
startNode: c.domNode,
|
|
1188
|
+
startOffset: a,
|
|
1189
|
+
endNode: c.domNode,
|
|
1190
|
+
endOffset: l
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
return null;
|
|
1194
|
+
}
|
|
1195
|
+
update(e, t) {
|
|
1196
|
+
if (e.some((e) => e.type === "characterData" && e.target === this.textNode)) {
|
|
1197
|
+
let e = this.restore();
|
|
1198
|
+
e && (t.range = e);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
optimize(t) {
|
|
1202
|
+
super.optimize(t);
|
|
1203
|
+
let { parent: n } = this;
|
|
1204
|
+
for (; n;) {
|
|
1205
|
+
if (n.domNode.tagName === "A") {
|
|
1206
|
+
this.savedLength = e.CONTENTS.length, n.isolate(this.offset(n), this.length()).unwrap(), this.savedLength = 0;
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
n = n.parent;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
value() {
|
|
1213
|
+
return "";
|
|
1214
|
+
}
|
|
1215
|
+
}, Ft = M("rich:selection"), It = class {
|
|
1216
|
+
index;
|
|
1217
|
+
length;
|
|
1218
|
+
constructor(e, t = 0) {
|
|
1219
|
+
this.index = e, this.length = t;
|
|
1220
|
+
}
|
|
1221
|
+
}, Lt = class {
|
|
1222
|
+
scroll;
|
|
1223
|
+
emitter;
|
|
1224
|
+
composing;
|
|
1225
|
+
mouseDown;
|
|
1226
|
+
root;
|
|
1227
|
+
cursor;
|
|
1228
|
+
savedRange;
|
|
1229
|
+
lastRange;
|
|
1230
|
+
lastNative;
|
|
1231
|
+
constructor(e, t) {
|
|
1232
|
+
this.emitter = t, this.scroll = e, this.composing = !1, this.mouseDown = !1, this.root = this.scroll.domNode, this.cursor = this.scroll.create("cursor", this), this.savedRange = new It(0, 0), this.lastRange = this.savedRange, this.lastNative = null, this.handleComposition(), this.handleDragging(), this.emitter.listenDOM("selectionchange", document, () => {
|
|
1233
|
+
!this.mouseDown && !this.composing && setTimeout(this.update.bind(this, N.sources.USER), 1);
|
|
1234
|
+
}), this.emitter.on(N.events.SCROLL_BEFORE_UPDATE, this.#e), this.emitter.on(N.events.SCROLL_OPTIMIZE, this.#t), this.update(N.sources.SILENT);
|
|
1235
|
+
}
|
|
1236
|
+
#e = () => {
|
|
1237
|
+
if (!this.hasFocus()) return;
|
|
1238
|
+
let e = this.getNativeRange();
|
|
1239
|
+
e != null && e.start.node !== this.cursor.textNode && this.emitter.once(N.events.SCROLL_UPDATE, (t, n) => {
|
|
1240
|
+
try {
|
|
1241
|
+
this.root.contains(e.start.node) && this.root.contains(e.end.node) && this.setNativeRange(e.start.node, e.start.offset, e.end.node, e.end.offset);
|
|
1242
|
+
let r = n.some((e) => e.type === "characterData" || e.type === "childList" || e.type === "attributes" && e.target === this.root);
|
|
1243
|
+
this.update(r ? N.sources.SILENT : t);
|
|
1244
|
+
} catch {}
|
|
1245
|
+
});
|
|
1246
|
+
};
|
|
1247
|
+
#t = (e, t) => {
|
|
1248
|
+
if (t.range) {
|
|
1249
|
+
let { startNode: e, startOffset: n, endNode: r, endOffset: i } = t.range;
|
|
1250
|
+
this.setNativeRange(e, n, r, i), this.update(N.sources.SILENT);
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
handleComposition() {
|
|
1254
|
+
this.emitter.on(N.events.COMPOSITION_BEFORE_START, this.#n), this.emitter.on(N.events.COMPOSITION_END, this.#r);
|
|
1255
|
+
}
|
|
1256
|
+
#n = () => {
|
|
1257
|
+
this.composing = !0;
|
|
1258
|
+
};
|
|
1259
|
+
#r = () => {
|
|
1260
|
+
if (this.composing = !1, this.cursor.parent) {
|
|
1261
|
+
let e = this.cursor.restore();
|
|
1262
|
+
if (!e) return;
|
|
1263
|
+
setTimeout(() => {
|
|
1264
|
+
this.setNativeRange(e.startNode, e.startOffset, e.endNode, e.endOffset);
|
|
1265
|
+
}, 1);
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
handleDragging() {
|
|
1269
|
+
this.emitter.listenDOM("mousedown", document.body, () => {
|
|
1270
|
+
this.mouseDown = !0;
|
|
1271
|
+
}), this.emitter.listenDOM("mouseup", document.body, () => {
|
|
1272
|
+
this.mouseDown = !1, this.update(N.sources.USER);
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
focus() {
|
|
1276
|
+
this.hasFocus() || (this.root.focus({ preventScroll: !0 }), this.setRange(this.savedRange));
|
|
1277
|
+
}
|
|
1278
|
+
blur() {
|
|
1279
|
+
this.root.blur();
|
|
1280
|
+
}
|
|
1281
|
+
format(e, t) {
|
|
1282
|
+
this.scroll.update();
|
|
1283
|
+
let n = this.getNativeRange();
|
|
1284
|
+
if (!(n == null || !n.native.collapsed || this.scroll.query(e, I.BLOCK))) {
|
|
1285
|
+
if (n.start.node !== this.cursor.textNode) {
|
|
1286
|
+
let e = this.scroll.find(n.start.node, !1);
|
|
1287
|
+
if (e == null) return;
|
|
1288
|
+
if (e instanceof R) {
|
|
1289
|
+
let t = e.split(n.start.offset);
|
|
1290
|
+
e.parent.insertBefore(this.cursor, t);
|
|
1291
|
+
} else e.insertBefore(this.cursor, n.start.node);
|
|
1292
|
+
this.cursor.attach();
|
|
1293
|
+
}
|
|
1294
|
+
this.cursor.format(e, t), this.scroll.optimize(), this.setNativeRange(this.cursor.textNode, this.cursor.textNode.data.length), this.update();
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
getBounds(e, t = 0) {
|
|
1298
|
+
let n = this.scroll.length();
|
|
1299
|
+
e = Math.min(e, n - 1), t = Math.min(e + t, n - 1) - e;
|
|
1300
|
+
let r, [i, a] = this.scroll.leaf(e);
|
|
1301
|
+
if (i == null) return null;
|
|
1302
|
+
if (t > 0 && a === i.length()) {
|
|
1303
|
+
let [t] = this.scroll.leaf(e + 1);
|
|
1304
|
+
if (t) {
|
|
1305
|
+
let [n] = this.scroll.line(e), [r] = this.scroll.line(e + 1);
|
|
1306
|
+
n === r && (i = t, a = 0);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
[r, a] = i.position(a, !0);
|
|
1310
|
+
let o = document.createRange();
|
|
1311
|
+
if (t > 0) return o.setStart(r, a), [i, a] = this.scroll.leaf(e + t), i == null ? null : ([r, a] = i.position(a, !0), o.setEnd(r, a), o.getBoundingClientRect());
|
|
1312
|
+
let s = "left", c;
|
|
1313
|
+
if (r instanceof Text) {
|
|
1314
|
+
if (!r.data.length) return null;
|
|
1315
|
+
a < r.data.length ? (o.setStart(r, a), o.setEnd(r, a + 1)) : (o.setStart(r, a - 1), o.setEnd(r, a), s = "right"), c = o.getBoundingClientRect();
|
|
1316
|
+
} else {
|
|
1317
|
+
if (!h(i.domNode)) return null;
|
|
1318
|
+
c = i.domNode.getBoundingClientRect(), a > 0 && (s = "right");
|
|
1319
|
+
}
|
|
1320
|
+
return {
|
|
1321
|
+
bottom: c.top + c.height,
|
|
1322
|
+
height: c.height,
|
|
1323
|
+
left: c[s],
|
|
1324
|
+
right: c[s],
|
|
1325
|
+
top: c.top,
|
|
1326
|
+
width: 0
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
getNativeRange() {
|
|
1330
|
+
let e = window.getSelection();
|
|
1331
|
+
if (e == null || e.rangeCount <= 0) return null;
|
|
1332
|
+
let t = e.getRangeAt(0);
|
|
1333
|
+
if (t == null) return null;
|
|
1334
|
+
let n = this.normalizeNative(t);
|
|
1335
|
+
return Ft.info("getNativeRange", n), n;
|
|
1336
|
+
}
|
|
1337
|
+
getRange() {
|
|
1338
|
+
let e = this.scroll.domNode;
|
|
1339
|
+
if ("isConnected" in e && !e.isConnected) return [null, null];
|
|
1340
|
+
let t = this.getNativeRange();
|
|
1341
|
+
return t == null ? [null, null] : [this.normalizedToRange(t), t];
|
|
1342
|
+
}
|
|
1343
|
+
hasFocus() {
|
|
1344
|
+
return document.activeElement === this.root || document.activeElement != null && Rt(this.root, document.activeElement);
|
|
1345
|
+
}
|
|
1346
|
+
normalizedToRange(e) {
|
|
1347
|
+
let t = [[e.start.node, e.start.offset]];
|
|
1348
|
+
e.native.collapsed || t.push([e.end.node, e.end.offset]);
|
|
1349
|
+
let n = t.map((e) => {
|
|
1350
|
+
let [t, n] = e, r = this.scroll.find(t, !0), i = r.offset(this.scroll);
|
|
1351
|
+
return n === 0 ? i : r instanceof R ? i + r.index(t, n) : i + r.length();
|
|
1352
|
+
}), r = Math.min(Math.max(...n), this.scroll.length() - 1), i = Math.min(r, ...n);
|
|
1353
|
+
return new It(i, r - i);
|
|
1354
|
+
}
|
|
1355
|
+
normalizeNative(e) {
|
|
1356
|
+
if (!Rt(this.root, e.startContainer) || !e.collapsed && !Rt(this.root, e.endContainer)) return null;
|
|
1357
|
+
let t = {
|
|
1358
|
+
start: {
|
|
1359
|
+
node: e.startContainer,
|
|
1360
|
+
offset: e.startOffset
|
|
1361
|
+
},
|
|
1362
|
+
end: {
|
|
1363
|
+
node: e.endContainer,
|
|
1364
|
+
offset: e.endOffset
|
|
1365
|
+
},
|
|
1366
|
+
native: e
|
|
1367
|
+
};
|
|
1368
|
+
return [t.start, t.end].forEach((e) => {
|
|
1369
|
+
let { node: t, offset: n } = e;
|
|
1370
|
+
for (; !(t instanceof Text) && t.childNodes.length > 0;) if (t.childNodes.length > n) t = t.childNodes[n], n = 0;
|
|
1371
|
+
else if (t.childNodes.length === n) t = t.lastChild, n = t instanceof Text ? t.data.length : t.childNodes.length > 0 ? t.childNodes.length : t.childNodes.length + 1;
|
|
1372
|
+
else break;
|
|
1373
|
+
e.node = t, e.offset = n;
|
|
1374
|
+
}), t;
|
|
1375
|
+
}
|
|
1376
|
+
rangeToNative(e) {
|
|
1377
|
+
let t = this.scroll.length(), n = (e, n) => {
|
|
1378
|
+
e = Math.min(t - 1, e);
|
|
1379
|
+
let [r, i] = this.scroll.leaf(e);
|
|
1380
|
+
return r ? r.position(i, n) : [null, -1];
|
|
1381
|
+
};
|
|
1382
|
+
return [...n(e.index, !1), ...n(e.index + e.length, !0)];
|
|
1383
|
+
}
|
|
1384
|
+
setSelectionByNode(e) {
|
|
1385
|
+
let t = window.getSelection(), n = document.createRange();
|
|
1386
|
+
n.selectNode(e), t.removeAllRanges(), t.addRange(n);
|
|
1387
|
+
}
|
|
1388
|
+
setNativeRange(e, t, n = e, r = t, i = !1) {
|
|
1389
|
+
if (Ft.info("setNativeRange", e, t, n, r), e != null && (this.root.parentNode == null || e.parentNode == null || n.parentNode == null)) return;
|
|
1390
|
+
let a = window.getSelection();
|
|
1391
|
+
if (a != null) if (e != null) {
|
|
1392
|
+
this.hasFocus() || this.root.focus({ preventScroll: !0 });
|
|
1393
|
+
let { native: o } = this.getNativeRange() || {};
|
|
1394
|
+
if (o == null || i || e !== o.startContainer || t !== o.startOffset || n !== o.endContainer || r !== o.endOffset) {
|
|
1395
|
+
h(e) && e.tagName === "BR" && (t = Array.from(e.parentNode.childNodes).indexOf(e), e = e.parentNode), h(n) && n.tagName === "BR" && (r = Array.from(n.parentNode.childNodes).indexOf(n), n = n.parentNode);
|
|
1396
|
+
let i = document.createRange();
|
|
1397
|
+
i.setStart(e, t), i.setEnd(n, r), a.removeAllRanges(), a.addRange(i);
|
|
1398
|
+
}
|
|
1399
|
+
} else a.removeAllRanges(), this.root.blur();
|
|
1400
|
+
}
|
|
1401
|
+
setRange(e, t = !1, n = N.sources.API) {
|
|
1402
|
+
if (x(t) && (n = t, t = !1), Ft.info("setRange", e), e != null) {
|
|
1403
|
+
let n = this.rangeToNative(e);
|
|
1404
|
+
this.setNativeRange(...n, t);
|
|
1405
|
+
} else this.setNativeRange(null);
|
|
1406
|
+
this.update(n);
|
|
1407
|
+
}
|
|
1408
|
+
update(e = N.sources.USER) {
|
|
1409
|
+
let t = this.lastRange, [n, r] = this.getRange();
|
|
1410
|
+
if (this.lastRange = n, this.lastNative = r, this.lastRange != null && (this.savedRange = this.lastRange), !g(t, this.lastRange)) {
|
|
1411
|
+
if (!this.composing && r != null && r.native.collapsed && r.start.node !== this.cursor.textNode) {
|
|
1412
|
+
let e = this.cursor.restore();
|
|
1413
|
+
e && this.setNativeRange(e.startNode, e.startOffset, e.endNode, e.endOffset);
|
|
1414
|
+
}
|
|
1415
|
+
let n = [
|
|
1416
|
+
N.events.SELECTION_CHANGE,
|
|
1417
|
+
T(this.lastRange),
|
|
1418
|
+
T(t),
|
|
1419
|
+
e
|
|
1420
|
+
];
|
|
1421
|
+
this.emitter.emit(N.events.EDITOR_CHANGE, ...n), e !== N.sources.SILENT && this.emitter.emit(...n);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
destroy() {
|
|
1425
|
+
this.emitter.off(N.events.SCROLL_BEFORE_UPDATE, this.#e), this.emitter.off(N.events.SCROLL_OPTIMIZE, this.#t), this.emitter.off(N.events.COMPOSITION_BEFORE_START, this.#n), this.emitter.off(N.events.COMPOSITION_END, this.#r);
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
function Rt(e, t) {
|
|
1429
|
+
try {
|
|
1430
|
+
t.parentNode;
|
|
1431
|
+
} catch {
|
|
1432
|
+
return !1;
|
|
1433
|
+
}
|
|
1434
|
+
return e.contains(t);
|
|
1435
|
+
}
|
|
1436
|
+
//#endregion
|
|
1437
|
+
//#region libs/rich-text/core/editor.ts
|
|
1438
|
+
var zt = /^[ -~]*$/, Bt = class {
|
|
1439
|
+
scroll;
|
|
1440
|
+
delta;
|
|
1441
|
+
constructor(e) {
|
|
1442
|
+
this.scroll = e, this.delta = this.getDelta();
|
|
1443
|
+
}
|
|
1444
|
+
applyDelta(e) {
|
|
1445
|
+
this.scroll.update();
|
|
1446
|
+
let t = this.scroll.length();
|
|
1447
|
+
this.scroll.batchStart();
|
|
1448
|
+
let n = Gt(e), i = new s();
|
|
1449
|
+
return qt(n.ops.slice()).reduce((e, n) => {
|
|
1450
|
+
let o = a.length(n), s = n.attributes || {}, c = !1, l = !1;
|
|
1451
|
+
if (n.insert != null) {
|
|
1452
|
+
if (i.retain(o), x(n.insert)) {
|
|
1453
|
+
let i = n.insert;
|
|
1454
|
+
l = !i.endsWith("\n") && (t <= e || !!this.scroll.descendant(G, e)[0]), this.scroll.insertAt(e, i);
|
|
1455
|
+
let [a, o] = this.scroll.line(e), c = C({}, K(a));
|
|
1456
|
+
if (a instanceof W) {
|
|
1457
|
+
let [e] = a.descendant(R, o);
|
|
1458
|
+
e && (c = C(c, K(e)));
|
|
1459
|
+
}
|
|
1460
|
+
s = r.diff(c, s) || {};
|
|
1461
|
+
} else if (b(n.insert)) {
|
|
1462
|
+
let i = Object.keys(n.insert)[0];
|
|
1463
|
+
if (i == null) return e;
|
|
1464
|
+
let a = this.scroll.query(i, I.INLINE) != null;
|
|
1465
|
+
if (a) (t <= e || this.scroll.descendant(G, e)[0]) && (l = !0);
|
|
1466
|
+
else if (e > 0) {
|
|
1467
|
+
let [t, n] = this.scroll.descendant(R, e - 1);
|
|
1468
|
+
t instanceof H ? t.value()[n] !== "\n" && (c = !0) : t instanceof V && t.statics.scope === I.INLINE_BLOT && (c = !0);
|
|
1469
|
+
}
|
|
1470
|
+
if (this.scroll.insertAt(e, i, n.insert[i]), a) {
|
|
1471
|
+
let [t] = this.scroll.descendant(R, e);
|
|
1472
|
+
if (t) {
|
|
1473
|
+
let e = C({}, K(t));
|
|
1474
|
+
s = r.diff(e, s) || {};
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
t += o;
|
|
1479
|
+
} else if (i.push(n), b(n.retain)) {
|
|
1480
|
+
let t = Object.keys(n.retain)[0];
|
|
1481
|
+
if (t == null) return e;
|
|
1482
|
+
this.scroll.updateEmbedAt(e, t, n.retain[t]);
|
|
1483
|
+
}
|
|
1484
|
+
Object.keys(s).forEach((t) => {
|
|
1485
|
+
this.scroll.formatAt(e, o, t, s[t]);
|
|
1486
|
+
});
|
|
1487
|
+
let u = +!!c, d = +!!l;
|
|
1488
|
+
return t += u + d, i.retain(u), i.delete(d), e + o + u + d;
|
|
1489
|
+
}, 0), i.reduce((e, t) => y(t.delete) ? (this.scroll.deleteAt(e, t.delete), e) : e + a.length(t), 0), this.scroll.batchEnd(), this.scroll.optimize(), this.update(n);
|
|
1490
|
+
}
|
|
1491
|
+
deleteText(e, t) {
|
|
1492
|
+
return this.scroll.deleteAt(e, t), this.update(new s().retain(e).delete(t));
|
|
1493
|
+
}
|
|
1494
|
+
formatLine(e, t, n = {}) {
|
|
1495
|
+
this.scroll.update(), Object.keys(n).forEach((r) => {
|
|
1496
|
+
this.scroll.lines(e, Math.max(t, 1)).forEach((e) => {
|
|
1497
|
+
e.format(r, n[r]);
|
|
1498
|
+
});
|
|
1499
|
+
}), this.scroll.optimize();
|
|
1500
|
+
let r = new s().retain(e).retain(t, T(n));
|
|
1501
|
+
return this.update(r);
|
|
1502
|
+
}
|
|
1503
|
+
formatText(e, t, n = {}) {
|
|
1504
|
+
Object.keys(n).forEach((r) => {
|
|
1505
|
+
this.scroll.formatAt(e, t, r, n[r]);
|
|
1506
|
+
});
|
|
1507
|
+
let r = new s().retain(e).retain(t, T(n));
|
|
1508
|
+
return this.update(r);
|
|
1509
|
+
}
|
|
1510
|
+
getContents(e, t) {
|
|
1511
|
+
return this.delta.slice(e, e + t);
|
|
1512
|
+
}
|
|
1513
|
+
getDelta() {
|
|
1514
|
+
return this.scroll.lines().reduce((e, t) => e.concat(t.delta()), new s());
|
|
1515
|
+
}
|
|
1516
|
+
getFormat(e, t = 0) {
|
|
1517
|
+
let n = [], r = [];
|
|
1518
|
+
t === 0 ? this.scroll.path(e).forEach((e) => {
|
|
1519
|
+
let [t] = e;
|
|
1520
|
+
t instanceof W ? n.push(t) : t instanceof R && r.push(t);
|
|
1521
|
+
}) : (n = this.scroll.lines(e, t), r = this.scroll.descendants(R, e, t));
|
|
1522
|
+
let [i, a] = [n, r].map((e) => {
|
|
1523
|
+
let t = e.shift();
|
|
1524
|
+
if (t == null) return {};
|
|
1525
|
+
let n = K(t);
|
|
1526
|
+
for (; Object.keys(n).length > 0;) {
|
|
1527
|
+
let t = e.shift();
|
|
1528
|
+
if (t == null) return n;
|
|
1529
|
+
n = Ut(K(t), n);
|
|
1530
|
+
}
|
|
1531
|
+
return n;
|
|
1532
|
+
});
|
|
1533
|
+
return {
|
|
1534
|
+
...i,
|
|
1535
|
+
...a
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
getHTML(e, t) {
|
|
1539
|
+
let [n, r] = this.scroll.line(e);
|
|
1540
|
+
if (n) {
|
|
1541
|
+
let i = n.length();
|
|
1542
|
+
return n.length() >= r + t && !(r === 0 && t === i) ? Ht(n, r, t, !0) : Ht(this.scroll, e, t, !0);
|
|
1543
|
+
}
|
|
1544
|
+
return "";
|
|
1545
|
+
}
|
|
1546
|
+
getText(e, t) {
|
|
1547
|
+
return this.getContents(e, t).filter((e) => x(e.insert)).map((e) => e.insert).join("");
|
|
1548
|
+
}
|
|
1549
|
+
insertContents(e, t) {
|
|
1550
|
+
let n = Gt(t), r = new s().retain(e).concat(n);
|
|
1551
|
+
return this.scroll.insertContents(e, n), this.update(r);
|
|
1552
|
+
}
|
|
1553
|
+
insertEmbed(e, t, n) {
|
|
1554
|
+
return this.scroll.insertAt(e, t, n), this.update(new s().retain(e).insert({ [t]: n }));
|
|
1555
|
+
}
|
|
1556
|
+
insertText(e, t, n = {}) {
|
|
1557
|
+
return t = t.replace(/\r\n/g, "\n").replace(/\r/g, "\n"), this.scroll.insertAt(e, t), Object.keys(n).forEach((r) => {
|
|
1558
|
+
this.scroll.formatAt(e, t.length, r, n[r]);
|
|
1559
|
+
}), this.update(new s().retain(e).insert(t, T(n)));
|
|
1560
|
+
}
|
|
1561
|
+
isBlank() {
|
|
1562
|
+
if (this.scroll.children.length === 0) return !0;
|
|
1563
|
+
if (this.scroll.children.length > 1) return !1;
|
|
1564
|
+
let e = this.scroll.children.head;
|
|
1565
|
+
if (e?.statics?.blotName !== W.blotName) return !1;
|
|
1566
|
+
let t = e;
|
|
1567
|
+
return t.children.length > 1 ? !1 : t.children.head instanceof U;
|
|
1568
|
+
}
|
|
1569
|
+
removeFormat(e, t) {
|
|
1570
|
+
let n = this.getText(e, t), [r, i] = this.scroll.line(e + t), a = 0, o = new s();
|
|
1571
|
+
r != null && (a = r.length() - i, o = r.delta().slice(i, i + a - 1).insert("\n"));
|
|
1572
|
+
let c = this.getContents(e, t + a).diff(new s().insert(n).concat(o)), l = new s().retain(e).concat(c);
|
|
1573
|
+
return this.applyDelta(l);
|
|
1574
|
+
}
|
|
1575
|
+
update(e, t = [], n = void 0) {
|
|
1576
|
+
let r = this.delta;
|
|
1577
|
+
if (t.length === 1 && t[0].type === "characterData" && t[0].target.data.match(zt) && this.scroll.find(t[0].target)) {
|
|
1578
|
+
let i = this.scroll.find(t[0].target), a = K(i), o = i.offset(this.scroll), c = t[0].oldValue.replace(Pt.CONTENTS, ""), l = new s().insert(c), u = new s().insert(i.value()), d = n && {
|
|
1579
|
+
oldRange: Kt(n.oldRange, -o),
|
|
1580
|
+
newRange: Kt(n.newRange, -o)
|
|
1581
|
+
};
|
|
1582
|
+
e = new s().retain(o).concat(l.diff(u, d)).reduce((e, t) => t.insert ? e.insert(t.insert, a) : e.push(t), new s()), this.delta = r.compose(e);
|
|
1583
|
+
} else this.delta = this.getDelta(), (!e || !g(r.compose(e), this.delta)) && (e = r.diff(this.delta, n));
|
|
1584
|
+
return e;
|
|
1585
|
+
}
|
|
1586
|
+
destroy() {}
|
|
1587
|
+
};
|
|
1588
|
+
function Vt(e, t, n) {
|
|
1589
|
+
if (e.length === 0) {
|
|
1590
|
+
let [e] = Wt(n.pop());
|
|
1591
|
+
return t <= 0 ? `</li></${e}>` : `</li></${e}>${Vt([], t - 1, n)}`;
|
|
1592
|
+
}
|
|
1593
|
+
let [{ child: r, offset: i, length: a, indent: o, type: s }, ...c] = e, [l, u] = Wt(s);
|
|
1594
|
+
if (o > t) return n.push(s), o === t + 1 ? `<${l}><li${u}>${Ht(r, i, a)}${Vt(c, o, n)}` : `<${l}><li>${Vt(e, t + 1, n)}`;
|
|
1595
|
+
let d = n[n.length - 1];
|
|
1596
|
+
if (o === t && s === d) return `</li><li${u}>${Ht(r, i, a)}${Vt(c, o, n)}`;
|
|
1597
|
+
let [ee] = Wt(n.pop());
|
|
1598
|
+
return `</li></${ee}>${Vt(e, t - 1, n)}`;
|
|
1599
|
+
}
|
|
1600
|
+
function Ht(e, t, n, r = !1) {
|
|
1601
|
+
if ("html" in e && _(e.html)) return e.html(t, n);
|
|
1602
|
+
if (e instanceof H) return Dt(e.value().slice(t, t + n)).replaceAll(" ", " ");
|
|
1603
|
+
if (e instanceof L) {
|
|
1604
|
+
if (e.statics.blotName, e.statics.blotName, e.statics.blotName === "list-container") {
|
|
1605
|
+
let r = [];
|
|
1606
|
+
return e.children.forEachAt(t, n, (e, t, n) => {
|
|
1607
|
+
let i = "formats" in e && _(e.formats) ? e.formats() : {};
|
|
1608
|
+
r.push({
|
|
1609
|
+
child: e,
|
|
1610
|
+
offset: t,
|
|
1611
|
+
length: n,
|
|
1612
|
+
indent: i.indent || 0,
|
|
1613
|
+
type: i.list
|
|
1614
|
+
});
|
|
1615
|
+
}), Vt(r, -1, []);
|
|
1616
|
+
}
|
|
1617
|
+
let i = [];
|
|
1618
|
+
if (e.children.forEachAt(t, n, (e, t, n) => {
|
|
1619
|
+
i.push(Ht(e, t, n));
|
|
1620
|
+
}), r || e.statics.blotName === "list") return i.join("");
|
|
1621
|
+
let { outerHTML: a, innerHTML: o } = e.domNode, [s, c] = a.split(`>${o}<`);
|
|
1622
|
+
return s === "<table" ? `<table style="border: 1px solid #000;">${i.join("")}<${c}` : `${s}>${i.join("")}<${c}`;
|
|
1623
|
+
}
|
|
1624
|
+
return h(e.domNode) ? e.domNode.outerHTML : "";
|
|
1625
|
+
}
|
|
1626
|
+
function Ut(e, t) {
|
|
1627
|
+
return Object.keys(t).reduce((n, r) => {
|
|
1628
|
+
if (e[r] == null) return n;
|
|
1629
|
+
let i = t[r];
|
|
1630
|
+
return i === e[r] ? n[r] = i : m(i) ? i.indexOf(e[r]) < 0 ? n[r] = i.concat([e[r]]) : n[r] = i : n[r] = [i, e[r]], n;
|
|
1631
|
+
}, {});
|
|
1632
|
+
}
|
|
1633
|
+
function Wt(e) {
|
|
1634
|
+
let t = e === "ordered" ? "ol" : "ul";
|
|
1635
|
+
switch (e) {
|
|
1636
|
+
case "checked": return [t, " data-list=\"checked\""];
|
|
1637
|
+
case "unchecked": return [t, " data-list=\"unchecked\""];
|
|
1638
|
+
default: return [t, ""];
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function Gt(e) {
|
|
1642
|
+
return e.reduce((e, t) => {
|
|
1643
|
+
if (x(t.insert)) {
|
|
1644
|
+
let n = t.insert.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1645
|
+
return e.insert(n, t.attributes);
|
|
1646
|
+
}
|
|
1647
|
+
return e.push(t);
|
|
1648
|
+
}, new s());
|
|
1649
|
+
}
|
|
1650
|
+
function Kt({ index: e, length: t }, n) {
|
|
1651
|
+
return new It(e + n, t);
|
|
1652
|
+
}
|
|
1653
|
+
function qt(e) {
|
|
1654
|
+
let t = [];
|
|
1655
|
+
return e.forEach((e) => {
|
|
1656
|
+
x(e.insert) ? e.insert.split("\n").forEach((n, r) => {
|
|
1657
|
+
r && t.push({
|
|
1658
|
+
insert: "\n",
|
|
1659
|
+
attributes: e.attributes
|
|
1660
|
+
}), n && t.push({
|
|
1661
|
+
insert: n,
|
|
1662
|
+
attributes: e.attributes
|
|
1663
|
+
});
|
|
1664
|
+
}) : t.push(e);
|
|
1665
|
+
}), t;
|
|
1666
|
+
}
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region libs/rich-text/core/theme.ts
|
|
1669
|
+
var Jt = class e {
|
|
1670
|
+
rich;
|
|
1671
|
+
options;
|
|
1672
|
+
static DEFAULTS = { modules: {} };
|
|
1673
|
+
static themes = { default: e };
|
|
1674
|
+
modules = {};
|
|
1675
|
+
constructor(e, t) {
|
|
1676
|
+
this.rich = e, this.options = t;
|
|
1677
|
+
}
|
|
1678
|
+
init() {
|
|
1679
|
+
Object.keys(this.options.modules).forEach((e) => {
|
|
1680
|
+
this.modules[e] ?? this.addModule(e);
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
addModule(e) {
|
|
1684
|
+
let t = q.import(`modules/${e}`);
|
|
1685
|
+
return this.modules[e] = new t(this.rich, this.options.modules[e] || {}), this.modules[e];
|
|
1686
|
+
}
|
|
1687
|
+
destroy() {
|
|
1688
|
+
Object.entries(this.modules).forEach(([e, t], n, r) => {
|
|
1689
|
+
t.destroy();
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
}, Yt = 100, Xt = [
|
|
1693
|
+
"block",
|
|
1694
|
+
"break",
|
|
1695
|
+
"cursor",
|
|
1696
|
+
"inline",
|
|
1697
|
+
"scroll",
|
|
1698
|
+
"text"
|
|
1699
|
+
], Zt = (e, t, n) => {
|
|
1700
|
+
let r = new dt();
|
|
1701
|
+
return Xt.forEach((e) => {
|
|
1702
|
+
let n = t.query(e);
|
|
1703
|
+
n && r.register(n);
|
|
1704
|
+
}), e.forEach((e) => {
|
|
1705
|
+
let i = t.query(e);
|
|
1706
|
+
i || n.error(`Cannot register "${e}" specified in "formats" config. Are you sure it was registered?`);
|
|
1707
|
+
let a = 0;
|
|
1708
|
+
for (; i;) if (r.register(i), i = "blotName" in i ? i.requiredContainer ?? null : null, a += 1, a > Yt) {
|
|
1709
|
+
n.error(`Cycle detected in registering blot requiredContainer: "${e}"`);
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
}), r;
|
|
1713
|
+
}, Qt = (e) => e.parentElement || e.getRootNode().host || null, $t = (e) => {
|
|
1714
|
+
let t = e.getBoundingClientRect(), n = "offsetWidth" in e && Math.abs(t.width) / e.offsetWidth || 1, r = "offsetHeight" in e && Math.abs(t.height) / e.offsetHeight || 1;
|
|
1715
|
+
return {
|
|
1716
|
+
top: t.top,
|
|
1717
|
+
right: t.left + e.clientWidth * n,
|
|
1718
|
+
bottom: t.top + e.clientHeight * r,
|
|
1719
|
+
left: t.left
|
|
1720
|
+
};
|
|
1721
|
+
}, en = (e) => {
|
|
1722
|
+
let t = parseInt(e, 10);
|
|
1723
|
+
return Number.isNaN(t) ? 0 : t;
|
|
1724
|
+
}, tn = (e, t, n, r, i, a) => e < n && t > r ? 0 : e < n ? -(n - e + i) : t > r ? t - e > r - n ? e + i - n : t - r + a : 0, nn = (e, t, n = {}) => {
|
|
1725
|
+
let r = e.ownerDocument, i = t, a = [], o = e;
|
|
1726
|
+
for (; o;) {
|
|
1727
|
+
let e = o === r.body, t = e ? {
|
|
1728
|
+
top: 0,
|
|
1729
|
+
right: window.visualViewport?.width ?? r.documentElement.clientWidth,
|
|
1730
|
+
bottom: window.visualViewport?.height ?? r.documentElement.clientHeight,
|
|
1731
|
+
left: 0
|
|
1732
|
+
} : $t(o), n = getComputedStyle(o), s = tn(i.left, i.right, t.left, t.right, en(n.scrollPaddingLeft), en(n.scrollPaddingRight)), c = tn(i.top, i.bottom, t.top, t.bottom, en(n.scrollPaddingTop), en(n.scrollPaddingBottom));
|
|
1733
|
+
if (s || c) if (e) r.defaultView && (a.push({
|
|
1734
|
+
element: r.defaultView,
|
|
1735
|
+
left: s,
|
|
1736
|
+
top: c
|
|
1737
|
+
}), r.defaultView.scrollBy(s, c));
|
|
1738
|
+
else {
|
|
1739
|
+
let { scrollLeft: e, scrollTop: t } = o;
|
|
1740
|
+
c && (o.scrollTop += c), s && (o.scrollLeft += s), a.push({
|
|
1741
|
+
element: o,
|
|
1742
|
+
left: s,
|
|
1743
|
+
top: c
|
|
1744
|
+
});
|
|
1745
|
+
let n = o.scrollLeft - e, r = o.scrollTop - t;
|
|
1746
|
+
i = {
|
|
1747
|
+
left: i.left - n,
|
|
1748
|
+
top: i.top - r,
|
|
1749
|
+
right: i.right - n,
|
|
1750
|
+
bottom: i.bottom - r
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
o = e || n.position === "fixed" ? null : Qt(o);
|
|
1754
|
+
}
|
|
1755
|
+
n.smooth && a.forEach(({ element: e, top: t, left: n }) => {
|
|
1756
|
+
e.scrollBy({
|
|
1757
|
+
top: -t,
|
|
1758
|
+
left: -n,
|
|
1759
|
+
behavior: "instant"
|
|
1760
|
+
}), e.scrollBy({
|
|
1761
|
+
top: t,
|
|
1762
|
+
left: n,
|
|
1763
|
+
behavior: "smooth"
|
|
1764
|
+
});
|
|
1765
|
+
});
|
|
1766
|
+
}, rn = M("rich"), an = /* @__PURE__ */ new WeakMap(), on = [
|
|
1767
|
+
"selectionchange",
|
|
1768
|
+
"mousedown",
|
|
1769
|
+
"mouseup",
|
|
1770
|
+
"click"
|
|
1771
|
+
];
|
|
1772
|
+
function sn(...e) {
|
|
1773
|
+
let t = document.querySelectorAll(`.${F}-container`);
|
|
1774
|
+
Array.from(t).forEach((t) => {
|
|
1775
|
+
let n = an.get(t);
|
|
1776
|
+
n?.emitter && n.emitter.handleDOM(...e);
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
function cn() {
|
|
1780
|
+
on.forEach((e) => {
|
|
1781
|
+
document.addEventListener(e, sn);
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
function ln() {
|
|
1785
|
+
on.forEach((e) => {
|
|
1786
|
+
document.removeEventListener(e, sn);
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
var un = new dt();
|
|
1790
|
+
L.uiClass = `${F}-ui`;
|
|
1791
|
+
var q = class e {
|
|
1792
|
+
static DEFAULTS = {
|
|
1793
|
+
bounds: null,
|
|
1794
|
+
modules: {
|
|
1795
|
+
clipboard: !0,
|
|
1796
|
+
keyboard: !0,
|
|
1797
|
+
history: !0,
|
|
1798
|
+
uploader: !0
|
|
1799
|
+
},
|
|
1800
|
+
placeholder: "",
|
|
1801
|
+
readOnly: !1,
|
|
1802
|
+
registry: un,
|
|
1803
|
+
theme: "default"
|
|
1804
|
+
};
|
|
1805
|
+
static events = N.events;
|
|
1806
|
+
static sources = N.sources;
|
|
1807
|
+
static imports = {
|
|
1808
|
+
delta: s,
|
|
1809
|
+
parchment: Tt,
|
|
1810
|
+
"core/module": P,
|
|
1811
|
+
"core/theme": Jt
|
|
1812
|
+
};
|
|
1813
|
+
static debug(e) {
|
|
1814
|
+
e === !0 && (e = "log"), M.level(e);
|
|
1815
|
+
}
|
|
1816
|
+
static find(e, t = !1) {
|
|
1817
|
+
return an.get(e) || un.find(e, t);
|
|
1818
|
+
}
|
|
1819
|
+
static import(e) {
|
|
1820
|
+
return this.imports[e] || rn.error(`Cannot import ${e}. Are you sure it was registered?`), this.imports[e];
|
|
1821
|
+
}
|
|
1822
|
+
static register(...e) {
|
|
1823
|
+
if (x(e[0])) {
|
|
1824
|
+
let t = e[0], n = e[1], r = !!e[2];
|
|
1825
|
+
this.imports[t] != null && !r && rn.warn(`Overwriting ${t} with`, n), this.imports[t] = n, ["blots/", "formats/"].some((e) => t.startsWith(e)) && n && !ne(n) && n.blotName !== "abstract" && un.register(n), _(n.register) && n.register(un);
|
|
1826
|
+
} else {
|
|
1827
|
+
let t = e[0], n = !!e[1], r = "attrName" in t ? t.attrName : t.blotName;
|
|
1828
|
+
x(r) ? this.register(`formats/${r}`, t, n) : Object.entries(t).forEach(([e, t], r, i) => {
|
|
1829
|
+
this.register(e, t, n);
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
elements;
|
|
1834
|
+
container;
|
|
1835
|
+
root;
|
|
1836
|
+
scroll;
|
|
1837
|
+
emitter;
|
|
1838
|
+
allowReadOnlyEdits;
|
|
1839
|
+
editor;
|
|
1840
|
+
composition;
|
|
1841
|
+
selection;
|
|
1842
|
+
theme;
|
|
1843
|
+
keyboard;
|
|
1844
|
+
clipboard;
|
|
1845
|
+
history;
|
|
1846
|
+
uploader;
|
|
1847
|
+
options;
|
|
1848
|
+
constructor(t, n = {}) {
|
|
1849
|
+
if (ln(), cn(), this.elements = t, this.options = mn(te(this.elements?.container), n), this.container = this.options.container, this.container == null) {
|
|
1850
|
+
rn.error("Invalid Rich container", this.container);
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
this.options.debug && e.debug(this.options.debug);
|
|
1854
|
+
let r = this.container.innerHTML.trim();
|
|
1855
|
+
this.container.classList.add(`${F}-container`), this.container.innerHTML = "", an.set(this.container, this), this.root = this.addContainer(`${F}-editor`), this.root.classList.add(`${F}-blank`), this.emitter = new N();
|
|
1856
|
+
let i = Ct.blotName, a = this.options.registry.query(i);
|
|
1857
|
+
if (!a || !("blotName" in a)) throw Error(`Cannot initialize Rich without "${i}" blot`);
|
|
1858
|
+
if (this.scroll = new a(this.options.registry, this.root, { emitter: this.emitter }), this.editor = new Bt(this.scroll), this.selection = new Lt(this.scroll, this.emitter), this.options.readOnly || (this.composition = new At(this.scroll, this.emitter), this.theme = new this.options.theme(this, this.options), this.keyboard = this.theme.addModule("keyboard"), this.clipboard = this.theme.addModule("clipboard"), this.history = this.theme.addModule("history"), this.uploader = this.theme.addModule("uploader"), this.theme.addModule("input"), this.theme.addModule("uiNode"), this.theme.init(), this.emitter.on(N.events.EDITOR_CHANGE, this.#e), this.emitter.on(N.events.SCROLL_UPDATE, this.#t), this.emitter.on(N.events.SCROLL_EMBED_UPDATE, this.#n)), r && this.clipboard) {
|
|
1859
|
+
let e = this.clipboard.convert({
|
|
1860
|
+
html: `${r}<p><br></p>`,
|
|
1861
|
+
text: "\n"
|
|
1862
|
+
});
|
|
1863
|
+
this.setContents(e);
|
|
1864
|
+
}
|
|
1865
|
+
this.history && this.history.clear(), this.options.placeholder && this.root.setAttribute("data-placeholder", this.options.placeholder), this.options.readOnly && this.disable(), this.allowReadOnlyEdits = !1;
|
|
1866
|
+
}
|
|
1867
|
+
#e = (e) => {
|
|
1868
|
+
e === N.events.TEXT_CHANGE && this.root.classList.toggle(`${F}-blank`, this.editor.isBlank());
|
|
1869
|
+
};
|
|
1870
|
+
#t = (e, t) => {
|
|
1871
|
+
let n = this.selection.lastRange, [r] = this.selection.getRange(), i = n && r ? {
|
|
1872
|
+
oldRange: n,
|
|
1873
|
+
newRange: r
|
|
1874
|
+
} : void 0;
|
|
1875
|
+
J.call(this, () => this.editor.update(null, t, i), e);
|
|
1876
|
+
};
|
|
1877
|
+
#n = (t, n) => {
|
|
1878
|
+
let r = this.selection.lastRange, [i] = this.selection.getRange(), a = r && i ? {
|
|
1879
|
+
oldRange: r,
|
|
1880
|
+
newRange: i
|
|
1881
|
+
} : void 0;
|
|
1882
|
+
J.call(this, () => {
|
|
1883
|
+
let e = new s().retain(t.offset(this)).retain({ [t.statics.blotName]: n });
|
|
1884
|
+
return this.editor.update(e, [], a);
|
|
1885
|
+
}, e.sources.USER);
|
|
1886
|
+
};
|
|
1887
|
+
addContainer(e, t = null, n) {
|
|
1888
|
+
if (x(e)) {
|
|
1889
|
+
let t = e;
|
|
1890
|
+
e = document.createElement("div"), e.classList.add(t);
|
|
1891
|
+
}
|
|
1892
|
+
return n instanceof HTMLElement ? n.appendChild(e) : this.container.insertBefore(e, t), e;
|
|
1893
|
+
}
|
|
1894
|
+
blur() {
|
|
1895
|
+
this.selection.setRange(null);
|
|
1896
|
+
}
|
|
1897
|
+
deleteText(e, t, n) {
|
|
1898
|
+
return [e, t, , n] = hn(e, t, n), J.call(this, () => this.editor.deleteText(e, t), n, e, -1 * t);
|
|
1899
|
+
}
|
|
1900
|
+
disable() {
|
|
1901
|
+
this.enable(!1);
|
|
1902
|
+
}
|
|
1903
|
+
editReadOnly(e) {
|
|
1904
|
+
this.allowReadOnlyEdits = !0;
|
|
1905
|
+
let t = e();
|
|
1906
|
+
return this.allowReadOnlyEdits = !1, t;
|
|
1907
|
+
}
|
|
1908
|
+
enable(e = !0) {
|
|
1909
|
+
this.scroll.enable(e), this.container.classList.toggle(`${F}-disabled`, !e);
|
|
1910
|
+
}
|
|
1911
|
+
focus(e = {}) {
|
|
1912
|
+
this.selection.focus(), e.preventScroll || this.scrollSelectionIntoView();
|
|
1913
|
+
}
|
|
1914
|
+
format(e, t, n = N.sources.API) {
|
|
1915
|
+
return J.call(this, () => {
|
|
1916
|
+
let n = this.getSelection(!0), r = new s();
|
|
1917
|
+
if (n == null) return r;
|
|
1918
|
+
if (this.scroll.query(e, I.BLOCK)) r = this.editor.formatLine(n.index, n.length, { [e]: t });
|
|
1919
|
+
else if (n.length === 0) return this.selection.format(e, t), r;
|
|
1920
|
+
else r = this.editor.formatText(n.index, n.length, { [e]: t });
|
|
1921
|
+
return this.setSelection(n, N.sources.SILENT), r;
|
|
1922
|
+
}, n);
|
|
1923
|
+
}
|
|
1924
|
+
formatLine(e, t, n, r, i) {
|
|
1925
|
+
let a;
|
|
1926
|
+
return [e, t, a, i] = hn(e, t, n, r, i), J.call(this, () => this.editor.formatLine(e, t, a), i, e, 0);
|
|
1927
|
+
}
|
|
1928
|
+
formatText(e, t, n, r, i) {
|
|
1929
|
+
let a;
|
|
1930
|
+
return [e, t, a, i] = hn(e, t, n, r, i), J.call(this, () => this.editor.formatText(e, t, a), i, e, 0);
|
|
1931
|
+
}
|
|
1932
|
+
getBounds(e, t = 0) {
|
|
1933
|
+
let n = null;
|
|
1934
|
+
if (n = y(e) ? this.selection.getBounds(e, t) : this.selection.getBounds(e.index, e.length), !n) return null;
|
|
1935
|
+
let r = this.container.getBoundingClientRect();
|
|
1936
|
+
return {
|
|
1937
|
+
bottom: n.bottom - r.top,
|
|
1938
|
+
height: n.height,
|
|
1939
|
+
left: n.left - r.left,
|
|
1940
|
+
right: n.right - r.left,
|
|
1941
|
+
top: n.top - r.top,
|
|
1942
|
+
width: n.width
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
getContents(e = 0, t = this.getLength() - e) {
|
|
1946
|
+
return [e, t] = hn(e, t), this.editor.getContents(e, t);
|
|
1947
|
+
}
|
|
1948
|
+
getFormat(e = this.getSelection(!0), t = 0) {
|
|
1949
|
+
return y(e) ? this.editor.getFormat(e, t) : this.editor.getFormat(e.index, e.length);
|
|
1950
|
+
}
|
|
1951
|
+
getIndex(e) {
|
|
1952
|
+
return e.offset(this.scroll);
|
|
1953
|
+
}
|
|
1954
|
+
getLength() {
|
|
1955
|
+
return this.scroll.length();
|
|
1956
|
+
}
|
|
1957
|
+
getLeaf(e) {
|
|
1958
|
+
return this.scroll.leaf(e);
|
|
1959
|
+
}
|
|
1960
|
+
getLine(e) {
|
|
1961
|
+
return this.scroll.line(e);
|
|
1962
|
+
}
|
|
1963
|
+
getLines(e = 0, t = Number.MAX_VALUE) {
|
|
1964
|
+
return y(e) ? this.scroll.lines(e, t) : this.scroll.lines(e.index, e.length);
|
|
1965
|
+
}
|
|
1966
|
+
getModule(e) {
|
|
1967
|
+
return this.theme.modules[e];
|
|
1968
|
+
}
|
|
1969
|
+
getSelection(e = !1) {
|
|
1970
|
+
return e && this.focus(), this.update(), this.selection.getRange()[0];
|
|
1971
|
+
}
|
|
1972
|
+
getSemanticHTML(e = 0, t) {
|
|
1973
|
+
return y(e) && (t ??= this.getLength() - e), [e, t] = hn(e, t), this.editor.getHTML(e, t);
|
|
1974
|
+
}
|
|
1975
|
+
getText(e = 0, t) {
|
|
1976
|
+
return y(e) && (t ??= this.getLength() - e), [e, t] = hn(e, t), this.editor.getText(e, t);
|
|
1977
|
+
}
|
|
1978
|
+
isBlank = () => this.editor.isBlank();
|
|
1979
|
+
hasFocus() {
|
|
1980
|
+
return this.selection.hasFocus();
|
|
1981
|
+
}
|
|
1982
|
+
insertEmbed(t, n, r, i = e.sources.API) {
|
|
1983
|
+
return J.call(this, () => this.editor.insertEmbed(t, n, r), i, t);
|
|
1984
|
+
}
|
|
1985
|
+
insertText(e, t, n, r, i) {
|
|
1986
|
+
let a;
|
|
1987
|
+
return [e, , a, i] = hn(e, 0, n, r, i), J.call(this, () => this.editor.insertText(e, t, a), i, e, t.length);
|
|
1988
|
+
}
|
|
1989
|
+
isEnabled() {
|
|
1990
|
+
return this.scroll.isEnabled();
|
|
1991
|
+
}
|
|
1992
|
+
on(...e) {
|
|
1993
|
+
return this.emitter.on(...e);
|
|
1994
|
+
}
|
|
1995
|
+
once(...e) {
|
|
1996
|
+
return this.emitter.once(...e);
|
|
1997
|
+
}
|
|
1998
|
+
off(...e) {
|
|
1999
|
+
return this.emitter.off(...e);
|
|
2000
|
+
}
|
|
2001
|
+
offAll() {
|
|
2002
|
+
return this.emitter.offAll();
|
|
2003
|
+
}
|
|
2004
|
+
removeFormat(e, t, n) {
|
|
2005
|
+
return [e, t, , n] = hn(e, t, n), J.call(this, () => this.editor.removeFormat(e, t), n, e);
|
|
2006
|
+
}
|
|
2007
|
+
scrollRectIntoView(e, t = {}) {
|
|
2008
|
+
nn(this.root, e, t);
|
|
2009
|
+
}
|
|
2010
|
+
scrollIntoView() {
|
|
2011
|
+
console.warn("Rich#scrollIntoView() has been deprecated and will be removed in the near future. Please use Rich#scrollSelectionIntoView() instead."), this.scrollSelectionIntoView();
|
|
2012
|
+
}
|
|
2013
|
+
scrollSelectionIntoView(e = {}) {
|
|
2014
|
+
let t = this.selection.lastRange, n = t && this.selection.getBounds(t.index, t.length);
|
|
2015
|
+
n && this.scrollRectIntoView(n, e);
|
|
2016
|
+
}
|
|
2017
|
+
setContents(e, t = N.sources.API) {
|
|
2018
|
+
return J.call(this, () => {
|
|
2019
|
+
e = new s(e);
|
|
2020
|
+
let t = this.getLength(), n = this.editor.deleteText(0, t), r = this.editor.insertContents(0, e), i = this.editor.deleteText(this.getLength() - 1, 1);
|
|
2021
|
+
return n.compose(r).compose(i);
|
|
2022
|
+
}, t);
|
|
2023
|
+
}
|
|
2024
|
+
setSelection(t, n, r) {
|
|
2025
|
+
t == null ? this.selection.setRange(null, n || e.sources.API) : ([t, n, , r] = hn(t, n, r), this.selection.setRange(new It(Math.max(0, t), n), r), r !== N.sources.SILENT && this.scrollSelectionIntoView());
|
|
2026
|
+
}
|
|
2027
|
+
setText(e, t = N.sources.API) {
|
|
2028
|
+
let n = new s().insert(e);
|
|
2029
|
+
return this.setContents(n, t);
|
|
2030
|
+
}
|
|
2031
|
+
update(e = N.sources.USER) {
|
|
2032
|
+
let t = this.scroll.update(e);
|
|
2033
|
+
return this.selection.update(e), t;
|
|
2034
|
+
}
|
|
2035
|
+
updateContents(e, t = N.sources.API) {
|
|
2036
|
+
return J.call(this, () => (e = new s(e), this.editor.applyDelta(e)), t, !0);
|
|
2037
|
+
}
|
|
2038
|
+
destroy() {
|
|
2039
|
+
this.scroll && this.scroll.destroy(), this.editor && this.editor.destroy(), this.selection && this.selection.destroy(), this.composition && this.composition.destroy(), this.theme && this.theme.destroy(), this.keyboard && this.keyboard.destroy(), this.clipboard && this.clipboard.destroy(), this.history && this.history.destroy(), this.uploader && this.uploader.destroy(), this.options.readOnly, this.emitter.off(N.events.EDITOR_CHANGE, this.#e), this.emitter.off(N.events.SCROLL_UPDATE, this.#t), this.emitter.off(N.events.SCROLL_EMBED_UPDATE, this.#n), this.emitter.destroy(), this.offAll(), setTimeout(() => {
|
|
2040
|
+
let e = document.querySelectorAll(`.${F}-container`);
|
|
2041
|
+
Array.from(e).length || ln();
|
|
2042
|
+
}, 27), an.delete(this.container);
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
function dn(e) {
|
|
2046
|
+
return x(e) ? document.querySelector(e) : e;
|
|
2047
|
+
}
|
|
2048
|
+
function fn(e) {
|
|
2049
|
+
return Object.entries(e ?? {}).reduce((e, [t, n]) => ({
|
|
2050
|
+
...e,
|
|
2051
|
+
[t]: n === !0 ? {} : n
|
|
2052
|
+
}), {});
|
|
2053
|
+
}
|
|
2054
|
+
function pn(e) {
|
|
2055
|
+
return Object.fromEntries(Object.entries(e).filter((e) => !S(e[1])));
|
|
2056
|
+
}
|
|
2057
|
+
function mn(e, t) {
|
|
2058
|
+
let n = dn(e);
|
|
2059
|
+
if (!n) throw Error("Invalid Rich container");
|
|
2060
|
+
let r = !t.theme || t.theme === q.DEFAULTS.theme ? q.import("themes/default") ?? Jt : q.import(`themes/${t.theme}`);
|
|
2061
|
+
if (!r) throw Error(`Invalid theme ${t.theme}. Did you register it?`);
|
|
2062
|
+
let { modules: i, ...a } = q.DEFAULTS, { modules: o, ...s } = r.DEFAULTS;
|
|
2063
|
+
i.clipboard = i.uploader = i.history = i.keyboard = !t.readOnly;
|
|
2064
|
+
let c = fn(t.modules);
|
|
2065
|
+
c != null && c.toolbar && c.toolbar.constructor !== Object && (c = {
|
|
2066
|
+
...c,
|
|
2067
|
+
toolbar: { container: c.toolbar }
|
|
2068
|
+
});
|
|
2069
|
+
let l = C({}, fn(i), fn(o), c), u = {
|
|
2070
|
+
...a,
|
|
2071
|
+
...pn(s),
|
|
2072
|
+
...pn(t)
|
|
2073
|
+
}, d = t.registry;
|
|
2074
|
+
return d ? t.formats && rn.warn("Ignoring \"formats\" option because \"registry\" is specified") : d = t.formats ? Zt(t.formats, u.registry, rn) : u.registry, {
|
|
2075
|
+
...u,
|
|
2076
|
+
registry: d,
|
|
2077
|
+
container: n,
|
|
2078
|
+
theme: r,
|
|
2079
|
+
modules: Object.entries(l).reduce((e, [t, n]) => {
|
|
2080
|
+
if (!n) return e;
|
|
2081
|
+
let r = q.import(`modules/${t}`);
|
|
2082
|
+
return r == null ? (rn.error(`Cannot load ${t} module. Are you sure you registered it?`), e) : {
|
|
2083
|
+
...e,
|
|
2084
|
+
[t]: C({}, r.DEFAULTS || {}, n)
|
|
2085
|
+
};
|
|
2086
|
+
}, {}),
|
|
2087
|
+
bounds: dn(u.bounds)
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
function J(e, t, n, r) {
|
|
2091
|
+
if (!this.isEnabled() && t === N.sources.USER && !this.allowReadOnlyEdits) return new s();
|
|
2092
|
+
let i = n == null ? null : this.getSelection(), a = this.editor.delta, o = e();
|
|
2093
|
+
if (i != null && (n === !0 && (n = i.index), r == null ? i = gn(i, o, t) : r !== 0 && (i = gn(i, n, r, t)), this.setSelection(i, N.sources.SILENT)), o.length() > 0) {
|
|
2094
|
+
let e = [
|
|
2095
|
+
N.events.TEXT_CHANGE,
|
|
2096
|
+
o,
|
|
2097
|
+
a,
|
|
2098
|
+
t
|
|
2099
|
+
];
|
|
2100
|
+
this.emitter.emit(N.events.EDITOR_CHANGE, ...e), t !== N.sources.SILENT && this.emitter.emit(...e);
|
|
2101
|
+
}
|
|
2102
|
+
return o;
|
|
2103
|
+
}
|
|
2104
|
+
function hn(e, t, n, r, i) {
|
|
2105
|
+
let a = {};
|
|
2106
|
+
return y(e.index) && y(e.length) ? y(t) ? (t = e.length, e = e.index) : (i = r, r = n, n = t, t = e.length, e = e.index) : y(t) || (i = r, r = n, n = t, t = 0), b(n) ? (a = n, i = r) : x(n) && (r == null ? i = n : a[n] = r), i ||= N.sources.API, [
|
|
2107
|
+
e,
|
|
2108
|
+
t,
|
|
2109
|
+
a,
|
|
2110
|
+
i
|
|
2111
|
+
];
|
|
2112
|
+
}
|
|
2113
|
+
function gn(e, t, n, r) {
|
|
2114
|
+
let i = y(n) ? n : 0;
|
|
2115
|
+
if (e == null) return null;
|
|
2116
|
+
let a, o;
|
|
2117
|
+
return t && _(t.transformPosition) ? [a, o] = [e.index, e.index + e.length].map((e) => t.transformPosition(e, r !== N.sources.USER)) : [a, o] = [e.index, e.index + e.length].map((e) => e < t || e === t && r === N.sources.USER ? e : i >= 0 ? e + i : Math.max(t, e + i)), new It(a, o - a);
|
|
2118
|
+
}
|
|
2119
|
+
//#endregion
|
|
2120
|
+
//#region libs/rich-text/formats/align.ts
|
|
2121
|
+
var _n = {
|
|
2122
|
+
scope: I.BLOCK,
|
|
2123
|
+
whitelist: [
|
|
2124
|
+
"left",
|
|
2125
|
+
"right",
|
|
2126
|
+
"center",
|
|
2127
|
+
"justify"
|
|
2128
|
+
]
|
|
2129
|
+
}, Y = "align", vn = new z(Y, "align", _n), yn = new B(Y, `${F}-align`, _n), bn = new _t(Y, "text-align", _n), xn = {
|
|
2130
|
+
scope: I.BLOCK,
|
|
2131
|
+
whitelist: ["rtl"]
|
|
2132
|
+
}, Sn = "direction", Cn = new z(Sn, "dir", xn), wn = new B(Sn, `${F}-direction`, xn), Tn = new _t(Sn, "direction", xn), En = class extends jt {
|
|
2133
|
+
static blotName = "emoji";
|
|
2134
|
+
static tagName = "span";
|
|
2135
|
+
static create(e) {
|
|
2136
|
+
let t = super.create(e);
|
|
2137
|
+
return t.innerText = e, t;
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
En.className = `${F}-emoji`;
|
|
2141
|
+
//#endregion
|
|
2142
|
+
//#region libs/rich-text/formats/formula.ts
|
|
2143
|
+
var Dn = class extends kt {
|
|
2144
|
+
static blotName = "formula";
|
|
2145
|
+
static className = `${F}-formula`;
|
|
2146
|
+
static tagName = "SPAN";
|
|
2147
|
+
static create(e) {
|
|
2148
|
+
if (!("katex" in window && window.katex && b(window.katex))) throw Error("Formula module requires KaTeX.");
|
|
2149
|
+
let t = super.create(e);
|
|
2150
|
+
return x(e) && "render" in window.katex && _(window.katex.render) && (window.katex.render(e, t, {
|
|
2151
|
+
throwOnError: !1,
|
|
2152
|
+
errorColor: "#f00"
|
|
2153
|
+
}), t.setAttribute("data-value", e)), t;
|
|
2154
|
+
}
|
|
2155
|
+
static value(e) {
|
|
2156
|
+
return e.getAttribute("data-value");
|
|
2157
|
+
}
|
|
2158
|
+
html() {
|
|
2159
|
+
let { formula: e } = this.value();
|
|
2160
|
+
return `<span>${e}</span>`;
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
Dn.className = `${F}-formula`;
|
|
2164
|
+
//#endregion
|
|
2165
|
+
//#region libs/rich-text/formats/hr.ts
|
|
2166
|
+
var On = class extends G {
|
|
2167
|
+
static create(e) {
|
|
2168
|
+
let t = super.create(e);
|
|
2169
|
+
return x(e) && t.classList.add(e), b(e) && Object.assign(t.style, e), t;
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
On.blotName = "hr", On.tagName = "hr", On.className = `${F}-hr`;
|
|
2173
|
+
var kn = class extends On {};
|
|
2174
|
+
kn.blotName = "hr-dashed", kn.tagName = "hr", kn.className = `${F}-hr-dashed`;
|
|
2175
|
+
//#endregion
|
|
2176
|
+
//#region libs/rich-text/formats/link.ts
|
|
2177
|
+
var X = class extends jt {
|
|
2178
|
+
static blotName = "link";
|
|
2179
|
+
static tagName = "A";
|
|
2180
|
+
static SANITIZED_URL = "about:blank";
|
|
2181
|
+
static PROTOCOL_WHITELIST = [
|
|
2182
|
+
"http",
|
|
2183
|
+
"https",
|
|
2184
|
+
"mailto",
|
|
2185
|
+
"tel",
|
|
2186
|
+
"sms"
|
|
2187
|
+
];
|
|
2188
|
+
static create(e) {
|
|
2189
|
+
let t = super.create(e);
|
|
2190
|
+
return t.setAttribute("href", this.sanitize(e)), t.setAttribute("rel", "noopener noreferrer"), t.setAttribute("target", "_blank"), t;
|
|
2191
|
+
}
|
|
2192
|
+
static formats(e) {
|
|
2193
|
+
return e.getAttribute("href");
|
|
2194
|
+
}
|
|
2195
|
+
static sanitize(e) {
|
|
2196
|
+
return An(e, this.PROTOCOL_WHITELIST) ? e : this.SANITIZED_URL;
|
|
2197
|
+
}
|
|
2198
|
+
format(e, t) {
|
|
2199
|
+
e !== this.statics.blotName || !t ? super.format(e, t) : this.domNode.setAttribute("href", this.constructor.sanitize(t));
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
X.className = `${F}-link`;
|
|
2203
|
+
function An(e, t) {
|
|
2204
|
+
let n = document.createElement("a");
|
|
2205
|
+
n.href = e;
|
|
2206
|
+
let r = n.href.slice(0, n.href.indexOf(":"));
|
|
2207
|
+
return t.includes(r);
|
|
2208
|
+
}
|
|
2209
|
+
//#endregion
|
|
2210
|
+
//#region libs/rich-text/formats/image.ts
|
|
2211
|
+
var jn = [
|
|
2212
|
+
"alt",
|
|
2213
|
+
"height",
|
|
2214
|
+
"width"
|
|
2215
|
+
], Mn = class extends V {
|
|
2216
|
+
static blotName = "image";
|
|
2217
|
+
static tagName = "IMG";
|
|
2218
|
+
static create(e) {
|
|
2219
|
+
let t = super.create(e);
|
|
2220
|
+
return x(e) && t.setAttribute("src", this.sanitize(e)), t;
|
|
2221
|
+
}
|
|
2222
|
+
static formats(e) {
|
|
2223
|
+
return jn.reduce((t, n) => (e.hasAttribute(n) && (t[n] = e.getAttribute(n)), t), {});
|
|
2224
|
+
}
|
|
2225
|
+
static match(e) {
|
|
2226
|
+
return /\.(jpe?g|gif|png)$/.test(e) || /^data:image\/.+;base64/.test(e);
|
|
2227
|
+
}
|
|
2228
|
+
static sanitize(e) {
|
|
2229
|
+
return An(e, [
|
|
2230
|
+
"http",
|
|
2231
|
+
"https",
|
|
2232
|
+
"data"
|
|
2233
|
+
]) ? e : "//:0";
|
|
2234
|
+
}
|
|
2235
|
+
static value(e) {
|
|
2236
|
+
return e.getAttribute("src");
|
|
2237
|
+
}
|
|
2238
|
+
domNode;
|
|
2239
|
+
format(e, t) {
|
|
2240
|
+
jn.includes(e) ? t ? this.domNode.setAttribute(e, t) : this.domNode.removeAttribute(e) : super.format(e, t);
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
Mn.className = `${F}-image`;
|
|
2244
|
+
//#endregion
|
|
2245
|
+
//#region libs/rich-text/formats/indent.ts
|
|
2246
|
+
var Nn = class extends B {
|
|
2247
|
+
add(e, t) {
|
|
2248
|
+
let n = 0;
|
|
2249
|
+
if (t === "+1" || t === "-1") {
|
|
2250
|
+
let r = this.value(e) || 0;
|
|
2251
|
+
n = t === "+1" ? r + 1 : r - 1;
|
|
2252
|
+
} else y(t) && (n = t);
|
|
2253
|
+
return n === 0 ? (this.remove(e), !0) : super.add(e, n.toString());
|
|
2254
|
+
}
|
|
2255
|
+
canAdd(e, t) {
|
|
2256
|
+
return super.canAdd(e, t) || super.canAdd(e, parseInt(t, 10));
|
|
2257
|
+
}
|
|
2258
|
+
value(e) {
|
|
2259
|
+
return parseInt(super.value(e), 10) || void 0;
|
|
2260
|
+
}
|
|
2261
|
+
}, Pn = "indent", Fn = new Nn(Pn, `${F}-indent`, {
|
|
2262
|
+
scope: I.BLOCK,
|
|
2263
|
+
whitelist: [
|
|
2264
|
+
1,
|
|
2265
|
+
2,
|
|
2266
|
+
3,
|
|
2267
|
+
4,
|
|
2268
|
+
5,
|
|
2269
|
+
6,
|
|
2270
|
+
7,
|
|
2271
|
+
8
|
|
2272
|
+
]
|
|
2273
|
+
}), In = class extends mt {}, Ln = class extends In {
|
|
2274
|
+
static create(e) {
|
|
2275
|
+
return super.create();
|
|
2276
|
+
}
|
|
2277
|
+
};
|
|
2278
|
+
Ln.blotName = "list-container", Ln.tagName = "OL", Ln.className = `${F}-ol`;
|
|
2279
|
+
var Z = class extends W {
|
|
2280
|
+
static create(e) {
|
|
2281
|
+
let t = super.create();
|
|
2282
|
+
return t.setAttribute("data-list", e), t;
|
|
2283
|
+
}
|
|
2284
|
+
static formats(e) {
|
|
2285
|
+
return e.getAttribute("data-list") || void 0;
|
|
2286
|
+
}
|
|
2287
|
+
static register() {
|
|
2288
|
+
q.register(Ln);
|
|
2289
|
+
}
|
|
2290
|
+
constructor(e, t) {
|
|
2291
|
+
super(e, t);
|
|
2292
|
+
let n = t.ownerDocument.createElement("span");
|
|
2293
|
+
this.attachUI(n);
|
|
2294
|
+
}
|
|
2295
|
+
format(e, t) {
|
|
2296
|
+
e === this.statics.blotName && t ? this.domNode.setAttribute("data-list", t) : super.format(e, t);
|
|
2297
|
+
}
|
|
2298
|
+
destroy() {}
|
|
2299
|
+
};
|
|
2300
|
+
Z.blotName = "list", Z.tagName = "LI", Z.className = `${F}-li`, Ln.allowedChildren = [Z], Z.requiredContainer = Ln;
|
|
2301
|
+
//#endregion
|
|
2302
|
+
//#region libs/rich-text/formats/video.ts
|
|
2303
|
+
var Rn = ["height", "width"], zn = class extends G {
|
|
2304
|
+
static blotName = "video";
|
|
2305
|
+
static className = `${F}-video`;
|
|
2306
|
+
static tagName = "IFRAME";
|
|
2307
|
+
static create(e) {
|
|
2308
|
+
let t = super.create(e);
|
|
2309
|
+
return t.setAttribute("frameborder", "0"), t.setAttribute("allowfullscreen", "true"), t.setAttribute("src", this.sanitize(e)), t;
|
|
2310
|
+
}
|
|
2311
|
+
static formats(e) {
|
|
2312
|
+
return Rn.reduce((t, n) => (e.hasAttribute(n) && (t[n] = e.getAttribute(n)), t), {});
|
|
2313
|
+
}
|
|
2314
|
+
static sanitize(e) {
|
|
2315
|
+
return X.sanitize(e);
|
|
2316
|
+
}
|
|
2317
|
+
static value(e) {
|
|
2318
|
+
return e.getAttribute("src");
|
|
2319
|
+
}
|
|
2320
|
+
domNode;
|
|
2321
|
+
format(e, t) {
|
|
2322
|
+
Rn.includes(e) ? t ? this.domNode.setAttribute(e, t) : this.domNode.removeAttribute(e) : super.format(e, t);
|
|
2323
|
+
}
|
|
2324
|
+
html() {
|
|
2325
|
+
let { video: e } = this.value();
|
|
2326
|
+
return `<a href="${e}">${e}</a>`;
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
zn.className = `${F}-video`;
|
|
2330
|
+
//#endregion
|
|
2331
|
+
//#region libs/rich-text/blots/scroll.ts
|
|
2332
|
+
function Bn(e) {
|
|
2333
|
+
return e instanceof W || e instanceof G;
|
|
2334
|
+
}
|
|
2335
|
+
function Vn(e) {
|
|
2336
|
+
return _(e.updateContent);
|
|
2337
|
+
}
|
|
2338
|
+
var Hn = class extends Ct {
|
|
2339
|
+
static blotName = "scroll";
|
|
2340
|
+
static className = `${F}-editor`;
|
|
2341
|
+
static tagName = "DIV";
|
|
2342
|
+
static defaultChild = W;
|
|
2343
|
+
static allowedChildren = [
|
|
2344
|
+
W,
|
|
2345
|
+
G,
|
|
2346
|
+
In
|
|
2347
|
+
];
|
|
2348
|
+
emitter;
|
|
2349
|
+
batch;
|
|
2350
|
+
constructor(e, t, { emitter: n }) {
|
|
2351
|
+
super(e, t), this.emitter = n, this.batch = !1, this.optimize(), this.enable(), this.domNode.addEventListener("dragstart", this.handleDragStart);
|
|
2352
|
+
}
|
|
2353
|
+
batchStart() {
|
|
2354
|
+
m(this.batch) || (this.batch = []);
|
|
2355
|
+
}
|
|
2356
|
+
batchEnd() {
|
|
2357
|
+
if (!this.batch) return;
|
|
2358
|
+
let e = this.batch;
|
|
2359
|
+
this.batch = !1, this.update(e);
|
|
2360
|
+
}
|
|
2361
|
+
emitMount(e) {
|
|
2362
|
+
this.emitter.emit(N.events.SCROLL_BLOT_MOUNT, e);
|
|
2363
|
+
}
|
|
2364
|
+
emitUnmount(e) {
|
|
2365
|
+
this.emitter.emit(N.events.SCROLL_BLOT_UNMOUNT, e);
|
|
2366
|
+
}
|
|
2367
|
+
emitEmbedUpdate(e, t) {
|
|
2368
|
+
this.emitter.emit(N.events.SCROLL_EMBED_UPDATE, e, t);
|
|
2369
|
+
}
|
|
2370
|
+
deleteAt(e, t) {
|
|
2371
|
+
let [n, r] = this.line(e), [i] = this.line(e + t);
|
|
2372
|
+
if (super.deleteAt(e, t), i != null && n !== i && r > 0) {
|
|
2373
|
+
if (n instanceof G || i instanceof G) {
|
|
2374
|
+
this.optimize();
|
|
2375
|
+
return;
|
|
2376
|
+
}
|
|
2377
|
+
let e = i.children.head instanceof U ? null : i.children.head;
|
|
2378
|
+
n.moveChildren(i, e), n.remove();
|
|
2379
|
+
}
|
|
2380
|
+
this.optimize();
|
|
2381
|
+
}
|
|
2382
|
+
enable(e = !0) {
|
|
2383
|
+
this.domNode.setAttribute("contenteditable", e ? "true" : "false");
|
|
2384
|
+
}
|
|
2385
|
+
formatAt(e, t, n, r) {
|
|
2386
|
+
super.formatAt(e, t, n, r), this.optimize();
|
|
2387
|
+
}
|
|
2388
|
+
insertAt(e, t, n) {
|
|
2389
|
+
if (e >= this.length()) if (n == null || this.scroll.query(t, I.BLOCK) == null) {
|
|
2390
|
+
let e = this.scroll.create(this.statics.defaultChild.blotName);
|
|
2391
|
+
this.appendChild(e), n == null && t.endsWith("\n") ? e.insertAt(0, t.slice(0, -1), n) : e.insertAt(0, t, n);
|
|
2392
|
+
} else {
|
|
2393
|
+
let e = this.scroll.create(t, n);
|
|
2394
|
+
this.appendChild(e);
|
|
2395
|
+
}
|
|
2396
|
+
else super.insertAt(e, t, n);
|
|
2397
|
+
this.optimize();
|
|
2398
|
+
}
|
|
2399
|
+
insertBefore(e, t) {
|
|
2400
|
+
if (e.statics.scope === I.INLINE_BLOT) {
|
|
2401
|
+
let n = this.scroll.create(this.statics.defaultChild.blotName);
|
|
2402
|
+
n.appendChild(e), super.insertBefore(n, t);
|
|
2403
|
+
} else super.insertBefore(e, t);
|
|
2404
|
+
}
|
|
2405
|
+
insertContents(e, t) {
|
|
2406
|
+
let n = this.#e(t.concat(new s().insert("\n"))), i = n.pop();
|
|
2407
|
+
if (i == null) return;
|
|
2408
|
+
this.batchStart();
|
|
2409
|
+
let a = n.shift();
|
|
2410
|
+
if (a) {
|
|
2411
|
+
let t = a.type === "block" && (a.delta.length() === 0 || !this.descendant(G, e)[0] && e < this.length()), n = a.type === "block" ? a.delta : new s().insert({ [a.key]: a.value });
|
|
2412
|
+
Un(this, e, n);
|
|
2413
|
+
let i = +(a.type === "block"), o = e + n.length() + i;
|
|
2414
|
+
t && this.insertAt(o - 1, "\n");
|
|
2415
|
+
let c = K(this.line(e)[0]), l = r.diff(c, a.attributes) || {};
|
|
2416
|
+
Object.keys(l).forEach((e) => {
|
|
2417
|
+
this.formatAt(o - 1, 1, e, l[e]);
|
|
2418
|
+
}), e = o;
|
|
2419
|
+
}
|
|
2420
|
+
let [o, c] = this.children.find(e);
|
|
2421
|
+
if (n.length && (o && (o = o.split(c), c = 0), n.forEach((e) => {
|
|
2422
|
+
if (e.type === "block") Un(this.#t(e.attributes, o || void 0), 0, e.delta);
|
|
2423
|
+
else {
|
|
2424
|
+
let t = this.create(e.key, e.value);
|
|
2425
|
+
this.insertBefore(t, o || void 0), Object.keys(e.attributes).forEach((n) => {
|
|
2426
|
+
t.format(n, e.attributes[n]);
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
})), i.type === "block" && i.delta.length()) {
|
|
2430
|
+
let e = o ? o.offset(o.scroll) + c : this.length();
|
|
2431
|
+
Un(this, e, i.delta);
|
|
2432
|
+
}
|
|
2433
|
+
this.batchEnd(), this.optimize();
|
|
2434
|
+
}
|
|
2435
|
+
isEnabled() {
|
|
2436
|
+
return this.domNode.getAttribute("contenteditable") === "true";
|
|
2437
|
+
}
|
|
2438
|
+
leaf(e) {
|
|
2439
|
+
let t = this.path(e).pop();
|
|
2440
|
+
if (!t) return [null, -1];
|
|
2441
|
+
let [n, r] = t;
|
|
2442
|
+
return n instanceof R ? [n, r] : [null, -1];
|
|
2443
|
+
}
|
|
2444
|
+
line(e) {
|
|
2445
|
+
return e === this.length() ? this.line(e - 1) : this.descendant(Bn, e);
|
|
2446
|
+
}
|
|
2447
|
+
lines(e = 0, t = Number.MAX_VALUE) {
|
|
2448
|
+
let n = (e, t, r) => {
|
|
2449
|
+
let i = [], a = r;
|
|
2450
|
+
return e.children.forEachAt(t, r, (e, t, r) => {
|
|
2451
|
+
Bn(e) ? i.push(e) : e instanceof mt && (i = i.concat(n(e, t, a))), a -= r;
|
|
2452
|
+
}), i;
|
|
2453
|
+
};
|
|
2454
|
+
return n(this, e, t);
|
|
2455
|
+
}
|
|
2456
|
+
optimize(e = [], t = {}) {
|
|
2457
|
+
this.batch || (super.optimize(e, t), e.length > 0 && this.emitter.emit(N.events.SCROLL_OPTIMIZE, e, t));
|
|
2458
|
+
}
|
|
2459
|
+
path(e) {
|
|
2460
|
+
return super.path(e).slice(1);
|
|
2461
|
+
}
|
|
2462
|
+
remove() {}
|
|
2463
|
+
update(e) {
|
|
2464
|
+
if (this.batch) {
|
|
2465
|
+
m(e) && (this.batch = this.batch.concat(e));
|
|
2466
|
+
return;
|
|
2467
|
+
}
|
|
2468
|
+
let t = N.sources.USER;
|
|
2469
|
+
x(e) && (t = e), m(e) || (e = this.observer.takeRecords()), e = e.filter(({ target: e }) => {
|
|
2470
|
+
let t = this.find(e, !0);
|
|
2471
|
+
return t && !Vn(t);
|
|
2472
|
+
}), e.length > 0 && this.emitter.emit(N.events.SCROLL_BEFORE_UPDATE, t, e), super.update(e.concat([])), e.length > 0 && this.emitter.emit(N.events.SCROLL_UPDATE, t, e);
|
|
2473
|
+
}
|
|
2474
|
+
updateEmbedAt(e, t, n) {
|
|
2475
|
+
let [r] = this.descendant((e) => e instanceof G, e);
|
|
2476
|
+
r?.statics?.blotName === t && Vn(r) && r.updateContent(n);
|
|
2477
|
+
}
|
|
2478
|
+
handleDragStart = (e) => {
|
|
2479
|
+
e.preventDefault();
|
|
2480
|
+
};
|
|
2481
|
+
#e(e) {
|
|
2482
|
+
let t = [], n = new s();
|
|
2483
|
+
return e.forEach((e) => {
|
|
2484
|
+
let r = e?.insert;
|
|
2485
|
+
if (r) if (x(r)) {
|
|
2486
|
+
let i = r.split("\n");
|
|
2487
|
+
i.slice(0, -1).forEach((r) => {
|
|
2488
|
+
n.insert(r, e.attributes), t.push({
|
|
2489
|
+
type: "block",
|
|
2490
|
+
delta: n,
|
|
2491
|
+
attributes: e.attributes ?? {}
|
|
2492
|
+
}), n = new s();
|
|
2493
|
+
});
|
|
2494
|
+
let a = i[i.length - 1];
|
|
2495
|
+
a && n.insert(a, e.attributes);
|
|
2496
|
+
} else {
|
|
2497
|
+
let i = Object.keys(r)[0];
|
|
2498
|
+
if (!i) return;
|
|
2499
|
+
this.query(i, I.INLINE) ? n.push(e) : (n.length() && t.push({
|
|
2500
|
+
type: "block",
|
|
2501
|
+
delta: n,
|
|
2502
|
+
attributes: {}
|
|
2503
|
+
}), n = new s(), t.push({
|
|
2504
|
+
type: "blockEmbed",
|
|
2505
|
+
key: i,
|
|
2506
|
+
value: r[i],
|
|
2507
|
+
attributes: e.attributes ?? {}
|
|
2508
|
+
}));
|
|
2509
|
+
}
|
|
2510
|
+
}), n.length() && t.push({
|
|
2511
|
+
type: "block",
|
|
2512
|
+
delta: n,
|
|
2513
|
+
attributes: {}
|
|
2514
|
+
}), t;
|
|
2515
|
+
}
|
|
2516
|
+
#t(e, t) {
|
|
2517
|
+
let n, r = {};
|
|
2518
|
+
Object.entries(e).forEach(([e, t]) => {
|
|
2519
|
+
this.query(e, I.BLOCK & I.BLOT) == null ? r[e] = t : n = e;
|
|
2520
|
+
});
|
|
2521
|
+
let i = this.create(n || this.statics.defaultChild.blotName, n ? e[n] : void 0);
|
|
2522
|
+
this.insertBefore(i, t || void 0);
|
|
2523
|
+
let a = i.length();
|
|
2524
|
+
return Object.entries(r).forEach(([e, t]) => {
|
|
2525
|
+
i.formatAt(0, a, e, t);
|
|
2526
|
+
}), i;
|
|
2527
|
+
}
|
|
2528
|
+
destroy() {
|
|
2529
|
+
this.domNode.removeEventListener("dragstart", this.handleDragStart);
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
function Un(e, t, n) {
|
|
2533
|
+
n.reduce((t, n) => {
|
|
2534
|
+
let i = a.length(n), o = n.attributes || {};
|
|
2535
|
+
if (n.insert != null) {
|
|
2536
|
+
if (x(n.insert)) {
|
|
2537
|
+
let i = n.insert;
|
|
2538
|
+
e.insertAt(t, i);
|
|
2539
|
+
let [a] = e.descendant(R, t), s = K(a);
|
|
2540
|
+
o = r.diff(s, o) || {};
|
|
2541
|
+
} else if (b(n.insert)) {
|
|
2542
|
+
let i = Object.keys(n.insert)[0];
|
|
2543
|
+
if (i == null) return t;
|
|
2544
|
+
if (e.insertAt(t, i, n.insert[i]), e.scroll.query(i, I.INLINE) != null) {
|
|
2545
|
+
let [n] = e.descendant(R, t), i = K(n);
|
|
2546
|
+
o = r.diff(i, o) || {};
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
return Object.keys(o).forEach((n) => {
|
|
2551
|
+
e.formatAt(t, i, n, o[n]);
|
|
2552
|
+
}), t + i;
|
|
2553
|
+
}, t);
|
|
2554
|
+
}
|
|
2555
|
+
//#endregion
|
|
2556
|
+
//#region libs/rich-text/formats/color.ts
|
|
2557
|
+
var Wn = "color", Gn = class extends _t {
|
|
2558
|
+
value(e) {
|
|
2559
|
+
let t = super.value(e);
|
|
2560
|
+
return t.startsWith("rgb(") ? (t = t.replace(/^[^\d]+/, "").replace(/[^\d]+$/, ""), `#${t.split(",").map((e) => `00${parseInt(e, 10).toString(16)}`.slice(-2)).join("")}`) : t;
|
|
2561
|
+
}
|
|
2562
|
+
}, Kn = new B(Wn, `${F}-color`, { scope: I.INLINE }), qn = new Gn(Wn, "color", { scope: I.INLINE }), Jn = "background", Yn = new B(Jn, `${F}-bg`, { scope: I.INLINE }), Xn = new Gn(Jn, "background-color", { scope: I.INLINE }), Zn = class extends W {
|
|
2563
|
+
static blotName = "blockquote";
|
|
2564
|
+
static tagName = "blockquote";
|
|
2565
|
+
};
|
|
2566
|
+
Zn.className = `${F}-blockquote`;
|
|
2567
|
+
//#endregion
|
|
2568
|
+
//#region libs/rich-text/formats/bold.ts
|
|
2569
|
+
var Qn = class extends jt {
|
|
2570
|
+
static blotName = "bold";
|
|
2571
|
+
static tagName = ["B", "STRONG"];
|
|
2572
|
+
static create() {
|
|
2573
|
+
return super.create();
|
|
2574
|
+
}
|
|
2575
|
+
static formats() {
|
|
2576
|
+
return !0;
|
|
2577
|
+
}
|
|
2578
|
+
optimize(e) {
|
|
2579
|
+
super.optimize(e), this.domNode.tagName !== this.statics.tagName[0] && this.replaceWith(this.statics.blotName);
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
Qn.className = `${F}-bold`;
|
|
2583
|
+
//#endregion
|
|
2584
|
+
//#region libs/rich-text/formats/code.ts
|
|
2585
|
+
var $n = class extends In {
|
|
2586
|
+
static create(e) {
|
|
2587
|
+
let t = super.create(e);
|
|
2588
|
+
return t.setAttribute("spellcheck", "false"), t;
|
|
2589
|
+
}
|
|
2590
|
+
code(e, t) {
|
|
2591
|
+
return this.children.map((e) => e.length() <= 1 ? "" : e.domNode.innerText).join("\n").slice(e, e + t);
|
|
2592
|
+
}
|
|
2593
|
+
html(e, t) {
|
|
2594
|
+
return `<pre>\n${Dt(this.code(e, t))}\n</pre>`;
|
|
2595
|
+
}
|
|
2596
|
+
}, Q = class extends W {
|
|
2597
|
+
static TAB = " ";
|
|
2598
|
+
static register() {
|
|
2599
|
+
q.register($n);
|
|
2600
|
+
}
|
|
2601
|
+
}, er = class extends jt {};
|
|
2602
|
+
er.blotName = "code", er.tagName = "CODE", er.className = `${F}-code`, Q.blotName = "code-block", Q.className = `${F}-code-block`, Q.tagName = "DIV", $n.blotName = "code-block-container", $n.className = `${F}-code-block-container`, $n.tagName = "DIV", $n.allowedChildren = [Q], Q.allowedChildren = [
|
|
2603
|
+
H,
|
|
2604
|
+
U,
|
|
2605
|
+
Pt
|
|
2606
|
+
], Q.requiredContainer = $n;
|
|
2607
|
+
//#endregion
|
|
2608
|
+
//#region libs/rich-text/formats/font.ts
|
|
2609
|
+
var tr = [
|
|
2610
|
+
{
|
|
2611
|
+
label: "Serif",
|
|
2612
|
+
value: "serif"
|
|
2613
|
+
},
|
|
2614
|
+
{
|
|
2615
|
+
label: "Monospace",
|
|
2616
|
+
value: "monospace"
|
|
2617
|
+
},
|
|
2618
|
+
{
|
|
2619
|
+
label: "苹方",
|
|
2620
|
+
value: "pingfang-sc"
|
|
2621
|
+
},
|
|
2622
|
+
{
|
|
2623
|
+
label: "微软雅黑",
|
|
2624
|
+
value: "microsoft-yahei"
|
|
2625
|
+
},
|
|
2626
|
+
{
|
|
2627
|
+
label: "黑体",
|
|
2628
|
+
value: "simhei"
|
|
2629
|
+
},
|
|
2630
|
+
{
|
|
2631
|
+
label: "宋体",
|
|
2632
|
+
value: "simsun"
|
|
2633
|
+
},
|
|
2634
|
+
{
|
|
2635
|
+
label: "楷体",
|
|
2636
|
+
value: "kaiti"
|
|
2637
|
+
},
|
|
2638
|
+
{
|
|
2639
|
+
label: "仿宋",
|
|
2640
|
+
value: "fangsong"
|
|
2641
|
+
}
|
|
2642
|
+
], nr = {
|
|
2643
|
+
scope: I.INLINE,
|
|
2644
|
+
whitelist: tr.map((e) => e.value)
|
|
2645
|
+
}, rr = "font", ir = new B(rr, `${F}-font`, nr), ar = new class extends _t {
|
|
2646
|
+
value(e) {
|
|
2647
|
+
return String(super.value(e)).replace(/["']/g, "");
|
|
2648
|
+
}
|
|
2649
|
+
}(rr, "font-family", nr), or = Array.from({ length: 6 }, (e, t) => {
|
|
2650
|
+
let n = t + 1;
|
|
2651
|
+
return {
|
|
2652
|
+
label: `标题 ${n}`,
|
|
2653
|
+
value: n
|
|
2654
|
+
};
|
|
2655
|
+
}), sr = class extends W {
|
|
2656
|
+
static blotName = "header";
|
|
2657
|
+
static tagName = or.map((e) => `H${e.value}`);
|
|
2658
|
+
static formats(e) {
|
|
2659
|
+
return this.tagName.indexOf(e.tagName) + 1;
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
sr.className = `${F}-header`;
|
|
2663
|
+
//#endregion
|
|
2664
|
+
//#region libs/rich-text/formats/italic.ts
|
|
2665
|
+
var cr = class extends Qn {
|
|
2666
|
+
static blotName = "italic";
|
|
2667
|
+
static tagName = ["I", "EM"];
|
|
2668
|
+
};
|
|
2669
|
+
cr.className = `${F}-italic`;
|
|
2670
|
+
//#endregion
|
|
2671
|
+
//#region libs/rich-text/formats/lineHeight.ts
|
|
2672
|
+
var lr = [].concat(Array.from({ length: 9 }, (e, t) => (t * .5 + 1).toString())), ur = new _t("line-height", "line-height", {
|
|
2673
|
+
scope: I.INLINE,
|
|
2674
|
+
whitelist: [...lr]
|
|
2675
|
+
}), dr = class extends jt {
|
|
2676
|
+
static blotName = "script";
|
|
2677
|
+
static tagName = ["SUB", "SUP"];
|
|
2678
|
+
static create(e) {
|
|
2679
|
+
return e === "super" ? document.createElement("sup") : e === "sub" ? document.createElement("sub") : super.create(e);
|
|
2680
|
+
}
|
|
2681
|
+
static formats(e) {
|
|
2682
|
+
if (e.tagName === "SUB") return "sub";
|
|
2683
|
+
if (e.tagName === "SUP") return "super";
|
|
2684
|
+
}
|
|
2685
|
+
};
|
|
2686
|
+
dr.className = `${F}-script`;
|
|
2687
|
+
//#endregion
|
|
2688
|
+
//#region libs/rich-text/formats/size.ts
|
|
2689
|
+
var fr = [].concat(Array.from({ length: 10 }, (e, t) => 12 + t * 2), [
|
|
2690
|
+
36,
|
|
2691
|
+
48,
|
|
2692
|
+
72,
|
|
2693
|
+
100
|
|
2694
|
+
]).map((e) => `${e}px`), pr = "size", mr = new B(pr, `${F}-size`, {
|
|
2695
|
+
scope: I.INLINE,
|
|
2696
|
+
whitelist: [
|
|
2697
|
+
"small",
|
|
2698
|
+
"large",
|
|
2699
|
+
"huge",
|
|
2700
|
+
...fr
|
|
2701
|
+
]
|
|
2702
|
+
}), hr = new _t(pr, "font-size", {
|
|
2703
|
+
scope: I.INLINE,
|
|
2704
|
+
whitelist: [...fr]
|
|
2705
|
+
}), gr = class extends Qn {
|
|
2706
|
+
static blotName = "strike";
|
|
2707
|
+
static tagName = ["S", "STRIKE"];
|
|
2708
|
+
};
|
|
2709
|
+
gr.className = `${F}-strike`;
|
|
2710
|
+
//#endregion
|
|
2711
|
+
//#region libs/rich-text/formats/underline.ts
|
|
2712
|
+
var _r = class extends jt {
|
|
2713
|
+
static blotName = "underline";
|
|
2714
|
+
static tagName = "U";
|
|
2715
|
+
};
|
|
2716
|
+
_r.className = `${F}-underline`;
|
|
2717
|
+
//#endregion
|
|
2718
|
+
//#region libs/rich-text/modules/keyboard.ts
|
|
2719
|
+
var vr = M("rich:keyboard"), yr = ve ? "metaKey" : "ctrlKey", br = class e extends P {
|
|
2720
|
+
static DEFAULTS;
|
|
2721
|
+
static match(e, t) {
|
|
2722
|
+
return [
|
|
2723
|
+
"altKey",
|
|
2724
|
+
"ctrlKey",
|
|
2725
|
+
"metaKey",
|
|
2726
|
+
"shiftKey"
|
|
2727
|
+
].some((n) => !!t[n] !== e[n] && !v(t[n])) ? !1 : t.key === e.key || t.key === e.which;
|
|
2728
|
+
}
|
|
2729
|
+
bindings;
|
|
2730
|
+
constructor(e, t) {
|
|
2731
|
+
super(e, t), this.bindings = {}, Object.keys(this.options.bindings).forEach((e) => {
|
|
2732
|
+
this.options.bindings[e] && this.addBinding(this.options.bindings[e]);
|
|
2733
|
+
}), this.addBinding({
|
|
2734
|
+
key: "Enter",
|
|
2735
|
+
shiftKey: null
|
|
2736
|
+
}, this.handleEnter), this.addBinding({
|
|
2737
|
+
key: "Enter",
|
|
2738
|
+
metaKey: null,
|
|
2739
|
+
ctrlKey: null,
|
|
2740
|
+
altKey: null
|
|
2741
|
+
}, () => {}), /Firefox/i.test(navigator.userAgent) ? (this.addBinding({ key: "Backspace" }, { collapsed: !0 }, this.handleBackspace), this.addBinding({ key: "Delete" }, { collapsed: !0 }, this.handleDelete)) : (this.addBinding({ key: "Backspace" }, {
|
|
2742
|
+
collapsed: !0,
|
|
2743
|
+
prefix: /^.?$/
|
|
2744
|
+
}, this.handleBackspace), this.addBinding({ key: "Delete" }, {
|
|
2745
|
+
collapsed: !0,
|
|
2746
|
+
suffix: /^.?$/
|
|
2747
|
+
}, this.handleDelete)), this.addBinding({ key: "Backspace" }, { collapsed: !1 }, this.handleDeleteRange), this.addBinding({ key: "Delete" }, { collapsed: !1 }, this.handleDeleteRange), this.addBinding({
|
|
2748
|
+
key: "Backspace",
|
|
2749
|
+
altKey: null,
|
|
2750
|
+
ctrlKey: null,
|
|
2751
|
+
metaKey: null,
|
|
2752
|
+
shiftKey: null
|
|
2753
|
+
}, {
|
|
2754
|
+
collapsed: !0,
|
|
2755
|
+
offset: 0
|
|
2756
|
+
}, this.handleBackspace), this.listen();
|
|
2757
|
+
}
|
|
2758
|
+
addBinding(e, t = {}, n = {}) {
|
|
2759
|
+
let r = Tr(e);
|
|
2760
|
+
if (r == null) {
|
|
2761
|
+
vr.warn("Attempted to add invalid keyboard binding", r);
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
_(t) && (t = { handler: t }), _(n) && (n = { handler: n }), (m(r.key) ? r.key : [r.key]).forEach((e) => {
|
|
2765
|
+
let i = {
|
|
2766
|
+
...r,
|
|
2767
|
+
key: e,
|
|
2768
|
+
...t,
|
|
2769
|
+
...n
|
|
2770
|
+
};
|
|
2771
|
+
this.bindings[i.key] = this.bindings[i.key] || [], this.bindings[i.key].push(i);
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
listen() {
|
|
2775
|
+
this.rich.root.addEventListener("keydown", this.#e);
|
|
2776
|
+
}
|
|
2777
|
+
#e = (t) => {
|
|
2778
|
+
if (t.defaultPrevented || t.isComposing || t.keyCode === 229 && (t.key === "Enter" || t.key === "Backspace")) return;
|
|
2779
|
+
let n = (this.bindings[t.key] || []).concat(this.bindings[t.which] || []).filter((n) => e.match(t, n));
|
|
2780
|
+
if (n.length === 0) return;
|
|
2781
|
+
let r = q.find(t.target, !0);
|
|
2782
|
+
if (r && r.scroll !== this.rich.scroll) return;
|
|
2783
|
+
let i = this.rich.getSelection();
|
|
2784
|
+
if (i == null || !this.rich.hasFocus()) return;
|
|
2785
|
+
let [a, o] = this.rich.getLine(i.index), [s, c] = this.rich.getLeaf(i.index), [l, u] = i.length === 0 ? [s, c] : this.rich.getLeaf(i.index + i.length), d = s instanceof wt ? s.value().slice(0, c) : "", ee = l instanceof wt ? l.value().slice(u) : "", f = {
|
|
2786
|
+
collapsed: i.length === 0,
|
|
2787
|
+
empty: i.length === 0 && a.length() <= 1,
|
|
2788
|
+
format: this.rich.getFormat(i),
|
|
2789
|
+
line: a,
|
|
2790
|
+
offset: o,
|
|
2791
|
+
prefix: d,
|
|
2792
|
+
suffix: ee,
|
|
2793
|
+
event: t
|
|
2794
|
+
};
|
|
2795
|
+
n.some((e) => {
|
|
2796
|
+
if (e.collapsed != null && e.collapsed !== f.collapsed || e.empty != null && e.empty !== f.empty || e.offset != null && e.offset !== f.offset) return !1;
|
|
2797
|
+
if (m(e.format)) {
|
|
2798
|
+
if (e.format.every((e) => f.format[e] == null)) return !1;
|
|
2799
|
+
} else if (b(e.format) && !Object.keys(e.format).every((t) => e.format[t] === !0 ? f.format[t] != null : e.format[t] === !1 ? f.format[t] == null : g(e.format[t], f.format[t]))) return !1;
|
|
2800
|
+
return e.prefix != null && !e.prefix.test(f.prefix) || e.suffix != null && !e.suffix.test(f.suffix) ? !1 : e.handler.call(this, i, f, e) !== !0;
|
|
2801
|
+
}) && t.preventDefault();
|
|
2802
|
+
};
|
|
2803
|
+
destroy() {
|
|
2804
|
+
super.destroy(), this.rich.root.removeEventListener("keydown", this.#e);
|
|
2805
|
+
}
|
|
2806
|
+
handleBackspace(e, t) {
|
|
2807
|
+
let n = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(t.prefix) ? 2 : 1;
|
|
2808
|
+
if (e.index === 0 || this.rich.getLength() <= 1) return;
|
|
2809
|
+
let i = {}, [a] = this.rich.getLine(e.index), o = new s().retain(e.index - n).delete(n);
|
|
2810
|
+
if (t.offset === 0) {
|
|
2811
|
+
let [t] = this.rich.getLine(e.index - 1);
|
|
2812
|
+
if (t && !(t.statics.blotName === "block" && t.length() <= 1)) {
|
|
2813
|
+
let t = a.formats(), n = this.rich.getFormat(e.index - 1, 1);
|
|
2814
|
+
if (i = r.diff(t, n) || {}, Object.keys(i).length > 0) {
|
|
2815
|
+
let t = new s().retain(e.index + a.length() - 2).retain(1, i);
|
|
2816
|
+
o = o.compose(t);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
this.rich.updateContents(o, q.sources.USER), this.rich.focus();
|
|
2821
|
+
}
|
|
2822
|
+
handleDelete(e, t) {
|
|
2823
|
+
let n = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(t.suffix) ? 2 : 1;
|
|
2824
|
+
if (e.index >= this.rich.getLength() - n) return;
|
|
2825
|
+
let i = {}, [a] = this.rich.getLine(e.index), o = new s().retain(e.index).delete(n);
|
|
2826
|
+
if (t.offset >= a.length() - 1) {
|
|
2827
|
+
let [t] = this.rich.getLine(e.index + 1);
|
|
2828
|
+
if (t) {
|
|
2829
|
+
let n = a.formats(), s = this.rich.getFormat(e.index, 1);
|
|
2830
|
+
i = r.diff(n, s) || {}, Object.keys(i).length > 0 && (o = o.retain(t.length() - 1).retain(1, i));
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
this.rich.updateContents(o, q.sources.USER), this.rich.focus();
|
|
2834
|
+
}
|
|
2835
|
+
handleDeleteRange(e) {
|
|
2836
|
+
Er({
|
|
2837
|
+
range: e,
|
|
2838
|
+
rich: this.rich
|
|
2839
|
+
}), this.rich.focus();
|
|
2840
|
+
}
|
|
2841
|
+
handleEnter(e, t) {
|
|
2842
|
+
let n = Object.keys(t.format).reduce((e, n) => (this.rich.scroll.query(n, I.BLOCK) && !m(t.format[n]) && (e[n] = t.format[n]), e), {}), r = new s().retain(e.index).delete(e.length).insert("\n", n);
|
|
2843
|
+
this.rich.updateContents(r, q.sources.USER), this.rich.setSelection(e.index + 1, q.sources.SILENT), this.rich.focus();
|
|
2844
|
+
}
|
|
2845
|
+
};
|
|
2846
|
+
br.DEFAULTS = { bindings: {
|
|
2847
|
+
bold: Cr("bold"),
|
|
2848
|
+
italic: Cr("italic"),
|
|
2849
|
+
underline: Cr("underline"),
|
|
2850
|
+
indent: {
|
|
2851
|
+
key: "Tab",
|
|
2852
|
+
format: [
|
|
2853
|
+
"blockquote",
|
|
2854
|
+
"indent",
|
|
2855
|
+
"list"
|
|
2856
|
+
],
|
|
2857
|
+
handler(e, t) {
|
|
2858
|
+
return t.collapsed && t.offset !== 0 ? !0 : (this.rich.format("indent", "+1", q.sources.USER), !1);
|
|
2859
|
+
}
|
|
2860
|
+
},
|
|
2861
|
+
outdent: {
|
|
2862
|
+
key: "Tab",
|
|
2863
|
+
shiftKey: !0,
|
|
2864
|
+
format: [
|
|
2865
|
+
"blockquote",
|
|
2866
|
+
"indent",
|
|
2867
|
+
"list"
|
|
2868
|
+
],
|
|
2869
|
+
handler(e, t) {
|
|
2870
|
+
return t.collapsed && t.offset !== 0 ? !0 : (this.rich.format("indent", "-1", q.sources.USER), !1);
|
|
2871
|
+
}
|
|
2872
|
+
},
|
|
2873
|
+
"outdent backspace": {
|
|
2874
|
+
key: "Backspace",
|
|
2875
|
+
collapsed: !0,
|
|
2876
|
+
shiftKey: null,
|
|
2877
|
+
metaKey: null,
|
|
2878
|
+
ctrlKey: null,
|
|
2879
|
+
altKey: null,
|
|
2880
|
+
format: ["indent", "list"],
|
|
2881
|
+
offset: 0,
|
|
2882
|
+
handler(e, t) {
|
|
2883
|
+
t.format.indent == null ? t.format.list == null ? t.format["li-ol"] ?? t.format["li-ul"] : this.rich.format("list", !1, q.sources.USER) : this.rich.format("indent", "-1", q.sources.USER);
|
|
2884
|
+
}
|
|
2885
|
+
},
|
|
2886
|
+
"indent code-block": xr(!0),
|
|
2887
|
+
"outdent code-block": xr(!1),
|
|
2888
|
+
"remove tab": {
|
|
2889
|
+
key: "Tab",
|
|
2890
|
+
shiftKey: !0,
|
|
2891
|
+
collapsed: !0,
|
|
2892
|
+
prefix: /\t$/,
|
|
2893
|
+
handler(e) {
|
|
2894
|
+
this.rich.deleteText(e.index - 1, 1, q.sources.USER);
|
|
2895
|
+
}
|
|
2896
|
+
},
|
|
2897
|
+
tab: {
|
|
2898
|
+
key: "Tab",
|
|
2899
|
+
handler(e, t) {
|
|
2900
|
+
if (t.format.table) return !0;
|
|
2901
|
+
this.rich.history.cutoff();
|
|
2902
|
+
let n = new s().retain(e.index).delete(e.length).insert(" ");
|
|
2903
|
+
return this.rich.updateContents(n, q.sources.USER), this.rich.history.cutoff(), this.rich.setSelection(e.index + 1, q.sources.SILENT), !1;
|
|
2904
|
+
}
|
|
2905
|
+
},
|
|
2906
|
+
"blockquote empty enter": {
|
|
2907
|
+
key: "Enter",
|
|
2908
|
+
collapsed: !0,
|
|
2909
|
+
format: ["blockquote"],
|
|
2910
|
+
empty: !0,
|
|
2911
|
+
handler() {
|
|
2912
|
+
this.rich.format("blockquote", !1, q.sources.USER);
|
|
2913
|
+
}
|
|
2914
|
+
},
|
|
2915
|
+
"list empty enter": {
|
|
2916
|
+
key: "Enter",
|
|
2917
|
+
collapsed: !0,
|
|
2918
|
+
format: ["list"],
|
|
2919
|
+
empty: !0,
|
|
2920
|
+
handler(e, t) {
|
|
2921
|
+
let n = { list: !1 };
|
|
2922
|
+
t.format.indent && (n.indent = !1), this.rich.formatLine(e.index, e.length, n, q.sources.USER);
|
|
2923
|
+
}
|
|
2924
|
+
},
|
|
2925
|
+
"checklist enter": {
|
|
2926
|
+
key: "Enter",
|
|
2927
|
+
collapsed: !0,
|
|
2928
|
+
format: { list: "checked" },
|
|
2929
|
+
handler(e) {
|
|
2930
|
+
let [t, n] = this.rich.getLine(e.index), r = {
|
|
2931
|
+
...t.formats(),
|
|
2932
|
+
list: "checked"
|
|
2933
|
+
}, i = new s().retain(e.index).insert("\n", r).retain(t.length() - n - 1).retain(1, { list: "unchecked" });
|
|
2934
|
+
this.rich.updateContents(i, q.sources.USER), this.rich.setSelection(e.index + 1, q.sources.SILENT), this.rich.scrollSelectionIntoView();
|
|
2935
|
+
}
|
|
2936
|
+
},
|
|
2937
|
+
"header enter": {
|
|
2938
|
+
key: "Enter",
|
|
2939
|
+
collapsed: !0,
|
|
2940
|
+
format: ["header"],
|
|
2941
|
+
suffix: /^$/,
|
|
2942
|
+
handler(e, t) {
|
|
2943
|
+
let [n, r] = this.rich.getLine(e.index), i = new s().retain(e.index).insert("\n", t.format).retain(n.length() - r - 1).retain(1, { header: null });
|
|
2944
|
+
this.rich.updateContents(i, q.sources.USER), this.rich.setSelection(e.index + 1, q.sources.SILENT), this.rich.scrollSelectionIntoView();
|
|
2945
|
+
}
|
|
2946
|
+
},
|
|
2947
|
+
"table backspace": {
|
|
2948
|
+
key: "Backspace",
|
|
2949
|
+
format: ["table"],
|
|
2950
|
+
collapsed: !0,
|
|
2951
|
+
offset: 0,
|
|
2952
|
+
handler() {}
|
|
2953
|
+
},
|
|
2954
|
+
"table delete": {
|
|
2955
|
+
key: "Delete",
|
|
2956
|
+
format: ["table"],
|
|
2957
|
+
collapsed: !0,
|
|
2958
|
+
suffix: /^$/,
|
|
2959
|
+
handler() {}
|
|
2960
|
+
},
|
|
2961
|
+
"table enter": {
|
|
2962
|
+
key: "Enter",
|
|
2963
|
+
shiftKey: null,
|
|
2964
|
+
format: ["table"],
|
|
2965
|
+
handler(e) {
|
|
2966
|
+
let t = this.rich.getModule("table");
|
|
2967
|
+
if (t) {
|
|
2968
|
+
let [n, r, i, a] = t.getTable(e), o = Dr(n, r, i, a);
|
|
2969
|
+
if (o == null) return;
|
|
2970
|
+
let c = n.offset();
|
|
2971
|
+
if (o < 0) {
|
|
2972
|
+
let t = new s().retain(c).insert("\n");
|
|
2973
|
+
this.rich.updateContents(t, q.sources.USER), this.rich.setSelection(e.index + 1, e.length, q.sources.SILENT);
|
|
2974
|
+
} else if (o > 0) {
|
|
2975
|
+
c += n.length();
|
|
2976
|
+
let e = new s().retain(c).insert("\n");
|
|
2977
|
+
this.rich.updateContents(e, q.sources.USER), this.rich.setSelection(c, q.sources.USER);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
},
|
|
2982
|
+
"table tab": {
|
|
2983
|
+
key: "Tab",
|
|
2984
|
+
shiftKey: null,
|
|
2985
|
+
format: ["table"],
|
|
2986
|
+
handler(e, t) {
|
|
2987
|
+
let { event: n, line: r } = t, i = r.offset(this.rich.scroll);
|
|
2988
|
+
n.shiftKey ? this.rich.setSelection(i - 1, q.sources.USER) : this.rich.setSelection(i + r.length(), q.sources.USER);
|
|
2989
|
+
}
|
|
2990
|
+
},
|
|
2991
|
+
"list autofill": {
|
|
2992
|
+
key: " ",
|
|
2993
|
+
shiftKey: null,
|
|
2994
|
+
collapsed: !0,
|
|
2995
|
+
format: {
|
|
2996
|
+
"code-block": !1,
|
|
2997
|
+
blockquote: !1,
|
|
2998
|
+
table: !1
|
|
2999
|
+
},
|
|
3000
|
+
prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/,
|
|
3001
|
+
handler(e, t) {
|
|
3002
|
+
if (this.rich.scroll.query("list") == null) return !0;
|
|
3003
|
+
let { length: n } = t.prefix, [r, i] = this.rich.getLine(e.index);
|
|
3004
|
+
if (i > n) return !0;
|
|
3005
|
+
let a;
|
|
3006
|
+
switch (t.prefix.trim()) {
|
|
3007
|
+
case "[]":
|
|
3008
|
+
case "[ ]":
|
|
3009
|
+
a = "unchecked";
|
|
3010
|
+
break;
|
|
3011
|
+
case "[x]":
|
|
3012
|
+
a = "checked";
|
|
3013
|
+
break;
|
|
3014
|
+
case "-":
|
|
3015
|
+
case "*":
|
|
3016
|
+
a = "bullet";
|
|
3017
|
+
break;
|
|
3018
|
+
default: a = "ordered";
|
|
3019
|
+
}
|
|
3020
|
+
this.rich.insertText(e.index, " ", q.sources.USER), this.rich.history.cutoff();
|
|
3021
|
+
let o = new s().retain(e.index - i).delete(n + 1).retain(r.length() - 2 - i).retain(1, { list: a });
|
|
3022
|
+
return this.rich.updateContents(o, q.sources.USER), this.rich.history.cutoff(), this.rich.setSelection(e.index - n, q.sources.SILENT), !1;
|
|
3023
|
+
}
|
|
3024
|
+
},
|
|
3025
|
+
"code exit": {
|
|
3026
|
+
key: "Enter",
|
|
3027
|
+
collapsed: !0,
|
|
3028
|
+
format: ["code-block"],
|
|
3029
|
+
prefix: /^$/,
|
|
3030
|
+
suffix: /^\s*$/,
|
|
3031
|
+
handler(e) {
|
|
3032
|
+
let [t, n] = this.rich.getLine(e.index), r = 2, i = t;
|
|
3033
|
+
for (; i != null && i.length() <= 1 && i.formats()["code-block"];) if (i = i.prev, --r, r <= 0) {
|
|
3034
|
+
let r = new s().retain(e.index + t.length() - n - 2).retain(1, { "code-block": null }).delete(1);
|
|
3035
|
+
return this.rich.updateContents(r, q.sources.USER), this.rich.setSelection(e.index - 1, q.sources.SILENT), !1;
|
|
3036
|
+
}
|
|
3037
|
+
return !0;
|
|
3038
|
+
}
|
|
3039
|
+
},
|
|
3040
|
+
"embed left": Sr("ArrowLeft", !1),
|
|
3041
|
+
"embed left shift": Sr("ArrowLeft", !0),
|
|
3042
|
+
"embed right": Sr("ArrowRight", !1),
|
|
3043
|
+
"embed right shift": Sr("ArrowRight", !0),
|
|
3044
|
+
"table down": wr(!1),
|
|
3045
|
+
"table up": wr(!0)
|
|
3046
|
+
} };
|
|
3047
|
+
function xr(e) {
|
|
3048
|
+
return {
|
|
3049
|
+
key: "Tab",
|
|
3050
|
+
shiftKey: !e,
|
|
3051
|
+
format: { "code-block": !0 },
|
|
3052
|
+
handler(t, { event: n }) {
|
|
3053
|
+
let { TAB: r } = this.rich.scroll.query("code-block");
|
|
3054
|
+
if (t.length === 0 && !n.shiftKey) {
|
|
3055
|
+
this.rich.insertText(t.index, r, q.sources.USER), this.rich.setSelection(t.index + r.length, q.sources.SILENT);
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
let i = t.length === 0 ? this.rich.getLines(t.index, 1) : this.rich.getLines(t), { index: a, length: o } = t;
|
|
3059
|
+
i.forEach((t, n) => {
|
|
3060
|
+
e ? (t.insertAt(0, r), n === 0 ? a += r.length : o += r.length) : t.domNode.textContent.startsWith(r) && (t.deleteAt(0, r.length), n === 0 ? a -= r.length : o -= r.length);
|
|
3061
|
+
}), this.rich.update(q.sources.USER), this.rich.setSelection(a, o, q.sources.SILENT);
|
|
3062
|
+
}
|
|
3063
|
+
};
|
|
3064
|
+
}
|
|
3065
|
+
function Sr(e, t) {
|
|
3066
|
+
return {
|
|
3067
|
+
key: e,
|
|
3068
|
+
shiftKey: t,
|
|
3069
|
+
altKey: null,
|
|
3070
|
+
[e === "ArrowLeft" ? "prefix" : "suffix"]: /^$/,
|
|
3071
|
+
handler(n) {
|
|
3072
|
+
let { index: r } = n;
|
|
3073
|
+
e === "ArrowRight" && (r += n.length + 1);
|
|
3074
|
+
let [i] = this.rich.getLeaf(r);
|
|
3075
|
+
return i instanceof V ? (e === "ArrowLeft" ? t ? this.rich.setSelection(n.index - 1, n.length + 1, q.sources.USER) : this.rich.setSelection(n.index - 1, q.sources.USER) : t ? this.rich.setSelection(n.index, n.length + 1, q.sources.USER) : this.rich.setSelection(n.index + n.length + 1, q.sources.USER), !1) : !0;
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
}
|
|
3079
|
+
function Cr(e) {
|
|
3080
|
+
return {
|
|
3081
|
+
key: e[0],
|
|
3082
|
+
shortKey: !0,
|
|
3083
|
+
handler(t, n) {
|
|
3084
|
+
this.rich.format(e, !n.format[e], q.sources.USER);
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
function wr(e) {
|
|
3089
|
+
return {
|
|
3090
|
+
key: e ? "ArrowUp" : "ArrowDown",
|
|
3091
|
+
collapsed: !0,
|
|
3092
|
+
format: ["table"],
|
|
3093
|
+
handler(t, n) {
|
|
3094
|
+
let r = e ? "prev" : "next", i = n.line, a = i.parent[r];
|
|
3095
|
+
if (a != null) {
|
|
3096
|
+
if (a.statics.blotName === "table-row") {
|
|
3097
|
+
let e = a.children.head, t = i;
|
|
3098
|
+
for (; t.prev != null;) t = t.prev, e = e.next;
|
|
3099
|
+
let r = e.offset(this.rich.scroll) + Math.min(n.offset, e.length() - 1);
|
|
3100
|
+
this.rich.setSelection(r, 0, q.sources.USER);
|
|
3101
|
+
}
|
|
3102
|
+
} else {
|
|
3103
|
+
let t = i.table()[r];
|
|
3104
|
+
t != null && (e ? this.rich.setSelection(t.offset(this.rich.scroll) + t.length() - 1, 0, q.sources.USER) : this.rich.setSelection(t.offset(this.rich.scroll), 0, q.sources.USER));
|
|
3105
|
+
}
|
|
3106
|
+
return !1;
|
|
3107
|
+
}
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
function Tr(e) {
|
|
3111
|
+
if (x(e) || y(e)) e = { key: e };
|
|
3112
|
+
else if (b(e)) e = T(e);
|
|
3113
|
+
else return null;
|
|
3114
|
+
return e.shortKey && (e[yr] = e.shortKey, delete e.shortKey), e;
|
|
3115
|
+
}
|
|
3116
|
+
function Er({ rich: e, range: t }) {
|
|
3117
|
+
let n = e.getLines(t), i = {};
|
|
3118
|
+
if (n.length > 1) {
|
|
3119
|
+
let e = n[0].formats(), t = n[n.length - 1].formats();
|
|
3120
|
+
i = r.diff(t, e) || {};
|
|
3121
|
+
}
|
|
3122
|
+
e.deleteText(t, q.sources.USER), Object.keys(i).length > 0 && e.formatLine(t.index, 1, i, q.sources.USER), e.setSelection(t.index, q.sources.SILENT);
|
|
3123
|
+
}
|
|
3124
|
+
function Dr(e, t, n, r) {
|
|
3125
|
+
return t.prev == null && t.next == null ? n.prev == null && n.next == null ? r === 0 ? -1 : 1 : n.prev == null ? -1 : 1 : t.prev == null ? -1 : t.next == null ? 1 : null;
|
|
3126
|
+
}
|
|
3127
|
+
//#endregion
|
|
3128
|
+
//#region libs/rich-text/modules/normalize-external-html/normalizers/googleDocs.ts
|
|
3129
|
+
var Or = /font-weight:\s*normal/, kr = [
|
|
3130
|
+
"P",
|
|
3131
|
+
"OL",
|
|
3132
|
+
"UL"
|
|
3133
|
+
], Ar = (e) => e && kr.includes(e.tagName), jr = (e) => {
|
|
3134
|
+
Array.from(e.querySelectorAll("br")).filter((e) => Ar(e.previousElementSibling) && Ar(e.nextElementSibling)).forEach((e) => {
|
|
3135
|
+
e.parentNode?.removeChild?.(e);
|
|
3136
|
+
});
|
|
3137
|
+
}, Mr = (e) => {
|
|
3138
|
+
Array.from(e.querySelectorAll("b[style*=\"font-weight\"]")).filter((e) => e.getAttribute("style")?.match?.(Or)).forEach((t) => {
|
|
3139
|
+
let n = e.createDocumentFragment();
|
|
3140
|
+
n.append(...t.childNodes), t.parentNode?.replaceChild?.(n, t);
|
|
3141
|
+
});
|
|
3142
|
+
};
|
|
3143
|
+
function Nr(e) {
|
|
3144
|
+
e.querySelector("[id^=\"docs-internal-guid-\"]") && (Mr(e), jr(e));
|
|
3145
|
+
}
|
|
3146
|
+
//#endregion
|
|
3147
|
+
//#region libs/rich-text/modules/normalize-external-html/normalizers/msWord.ts
|
|
3148
|
+
var Pr = /\bmso-list:[^;]*ignore/i, Fr = /\bmso-list:[^;]*\bl(\d+)/i, Ir = /\bmso-list:[^;]*\blevel(\d+)/i, Lr = (e, t) => {
|
|
3149
|
+
let n = e.getAttribute("style"), r = n?.match?.(Fr);
|
|
3150
|
+
if (!r) return null;
|
|
3151
|
+
let i = Number(r[1]), a = n?.match?.(Ir), o = a ? Number(a[1]) : 1, s = RegExp(`@list l${i}:level${o}\\s*\\{[^\\}]*mso-level-number-format:\\s*([\\w-]+)`, "i"), c = t.match(s);
|
|
3152
|
+
return {
|
|
3153
|
+
id: i,
|
|
3154
|
+
indent: o,
|
|
3155
|
+
type: c && c[1] === "bullet" ? "bullet" : "ordered",
|
|
3156
|
+
element: e
|
|
3157
|
+
};
|
|
3158
|
+
}, Rr = (e) => {
|
|
3159
|
+
let t = Array.from(e.querySelectorAll("[style*=mso-list]")), n = [], r = [];
|
|
3160
|
+
t.forEach((e) => {
|
|
3161
|
+
(e.getAttribute("style") || "").match(Pr) ? n.push(e) : r.push(e);
|
|
3162
|
+
}), n.forEach((e) => e.parentNode?.removeChild?.(e));
|
|
3163
|
+
let i = e.documentElement.innerHTML, a = r.map((e) => Lr(e, i)).filter((e) => e);
|
|
3164
|
+
for (; a.length;) {
|
|
3165
|
+
let e = [], t = a.shift();
|
|
3166
|
+
for (; t;) e.push(t), t = a.length && a[0]?.element === t.element.nextElementSibling && a[0].id === t.id ? a.shift() : null;
|
|
3167
|
+
let n = document.createElement("ul");
|
|
3168
|
+
e.forEach((e) => {
|
|
3169
|
+
let t = document.createElement("li");
|
|
3170
|
+
t.setAttribute("data-list", e.type), e.indent > 1 && t.setAttribute("class", `${F}-indent-${e.indent - 1}`), t.innerHTML = e.element.innerHTML, n.appendChild(t);
|
|
3171
|
+
});
|
|
3172
|
+
let r = e[0]?.element, { parentNode: i } = r ?? {};
|
|
3173
|
+
r && i?.replaceChild?.(n, r), e.slice(1).forEach(({ element: e }) => {
|
|
3174
|
+
i?.removeChild?.(e);
|
|
3175
|
+
});
|
|
3176
|
+
}
|
|
3177
|
+
};
|
|
3178
|
+
function zr(e) {
|
|
3179
|
+
e.documentElement.getAttribute("xmlns:w") === "urn:schemas-microsoft-com:office:word" && Rr(e);
|
|
3180
|
+
}
|
|
3181
|
+
//#endregion
|
|
3182
|
+
//#region libs/rich-text/modules/normalize-external-html/index.ts
|
|
3183
|
+
var Br = [zr, Nr], Vr = (e) => {
|
|
3184
|
+
e.documentElement && Br.forEach((t) => {
|
|
3185
|
+
t(e);
|
|
3186
|
+
});
|
|
3187
|
+
}, Hr = M("rich:clipboard"), Ur = [
|
|
3188
|
+
[Node.TEXT_NODE, di],
|
|
3189
|
+
[Node.TEXT_NODE, ci],
|
|
3190
|
+
["br", ri],
|
|
3191
|
+
[Node.ELEMENT_NODE, ci],
|
|
3192
|
+
[Node.ELEMENT_NODE, ni],
|
|
3193
|
+
[Node.ELEMENT_NODE, ti],
|
|
3194
|
+
[Node.ELEMENT_NODE, li],
|
|
3195
|
+
["li", oi],
|
|
3196
|
+
["ol, ul", si],
|
|
3197
|
+
["pre", ii],
|
|
3198
|
+
["tr", ui],
|
|
3199
|
+
["b", ei("bold")],
|
|
3200
|
+
["i", ei("italic")],
|
|
3201
|
+
["strike", ei("strike")],
|
|
3202
|
+
["style", ai]
|
|
3203
|
+
], Wr = [vn, Cn].reduce((e, t) => (e[t.keyName] = t, e), {}), Gr = [
|
|
3204
|
+
bn,
|
|
3205
|
+
Xn,
|
|
3206
|
+
qn,
|
|
3207
|
+
Tn,
|
|
3208
|
+
ar,
|
|
3209
|
+
hr,
|
|
3210
|
+
ur
|
|
3211
|
+
].reduce((e, t) => (e[t.keyName] = t, e), {}), Kr = class extends P {
|
|
3212
|
+
static DEFAULTS = { matchers: [] };
|
|
3213
|
+
matchers;
|
|
3214
|
+
constructor(e, t) {
|
|
3215
|
+
super(e, t), this.rich.root.addEventListener("copy", this.#e), this.rich.root.addEventListener("cut", this.#t), this.rich.root.addEventListener("paste", this.#n), this.matchers = [], Ur.concat(this.options.matchers ?? []).forEach(([e, t]) => {
|
|
3216
|
+
this.addMatcher(e, t);
|
|
3217
|
+
});
|
|
3218
|
+
}
|
|
3219
|
+
#e = (e) => {
|
|
3220
|
+
this.onCaptureCopy(e, !1);
|
|
3221
|
+
};
|
|
3222
|
+
#t = (e) => {
|
|
3223
|
+
this.onCaptureCopy(e, !0);
|
|
3224
|
+
};
|
|
3225
|
+
#n = (e) => {
|
|
3226
|
+
this.onCapturePaste(e);
|
|
3227
|
+
};
|
|
3228
|
+
destroy() {
|
|
3229
|
+
super.destroy(), this.rich.root.removeEventListener("copy", this.#e), this.rich.root.removeEventListener("cut", this.#t), this.rich.root.removeEventListener("paste", this.#n);
|
|
3230
|
+
}
|
|
3231
|
+
addMatcher(e, t) {
|
|
3232
|
+
this.matchers.push([e, t]);
|
|
3233
|
+
}
|
|
3234
|
+
convert({ html: e, text: t }, n = {}) {
|
|
3235
|
+
if (n[Q.blotName]) return new s().insert(t || "", { [Q.blotName]: n[Q.blotName] });
|
|
3236
|
+
if (!e) return new s().insert(t || "", n);
|
|
3237
|
+
let r = this.convertHTML(e);
|
|
3238
|
+
return Jr(r, "\n") && (r.ops[r.ops.length - 1].attributes == null || n.table) ? r.compose(new s().retain(r.length() - 1).delete(1)) : r;
|
|
3239
|
+
}
|
|
3240
|
+
normalizeHTML(e) {
|
|
3241
|
+
Vr(e);
|
|
3242
|
+
}
|
|
3243
|
+
convertHTML(e) {
|
|
3244
|
+
let t = new DOMParser().parseFromString(e, "text/html");
|
|
3245
|
+
this.normalizeHTML(t);
|
|
3246
|
+
let n = t.body, r = /* @__PURE__ */ new WeakMap(), [i, a] = this.prepareMatching(n, r);
|
|
3247
|
+
return $r(this.rich.scroll, n, i, a, r);
|
|
3248
|
+
}
|
|
3249
|
+
dangerouslyPasteHTML(e, t, n = q.sources.API) {
|
|
3250
|
+
if (x(e)) {
|
|
3251
|
+
let n = this.convert({
|
|
3252
|
+
html: e,
|
|
3253
|
+
text: ""
|
|
3254
|
+
});
|
|
3255
|
+
this.rich.setContents(n, t), this.rich.setSelection(0, q.sources.SILENT);
|
|
3256
|
+
} else {
|
|
3257
|
+
let r = this.convert({
|
|
3258
|
+
html: t,
|
|
3259
|
+
text: ""
|
|
3260
|
+
});
|
|
3261
|
+
this.rich.updateContents(new s().retain(e).concat(r), n), this.rich.setSelection(e + r.length(), q.sources.SILENT);
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
onCaptureCopy(e, t = !1) {
|
|
3265
|
+
if (e.defaultPrevented) return;
|
|
3266
|
+
e.preventDefault();
|
|
3267
|
+
let [n] = this.rich.selection.getRange();
|
|
3268
|
+
if (n == null) return;
|
|
3269
|
+
let { html: r, text: i } = this.onCopy(n, t);
|
|
3270
|
+
e.clipboardData?.setData?.("text/plain", i), e.clipboardData?.setData?.("text/html", r), t && Er({
|
|
3271
|
+
range: n,
|
|
3272
|
+
rich: this.rich
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
#r(e) {
|
|
3276
|
+
return e.split(/\r?\n/).filter((e) => e[0] !== "#").join("\n");
|
|
3277
|
+
}
|
|
3278
|
+
onCapturePaste(e) {
|
|
3279
|
+
if (e.defaultPrevented || !this.rich.isEnabled()) return;
|
|
3280
|
+
e.preventDefault();
|
|
3281
|
+
let t = this.rich.getSelection(!0);
|
|
3282
|
+
if (t == null) return;
|
|
3283
|
+
let n = e.clipboardData?.getData?.("text/html"), r = e.clipboardData?.getData?.("text/plain");
|
|
3284
|
+
if (!n && !r) {
|
|
3285
|
+
let t = e.clipboardData?.getData?.("text/uri-list");
|
|
3286
|
+
t && (r = this.#r(t));
|
|
3287
|
+
}
|
|
3288
|
+
let i = Array.from(e.clipboardData?.files || []);
|
|
3289
|
+
if (!n && i.length > 0) {
|
|
3290
|
+
this.rich.uploader.upload(t, i);
|
|
3291
|
+
return;
|
|
3292
|
+
}
|
|
3293
|
+
if (n && i.length > 0) {
|
|
3294
|
+
let e = new DOMParser().parseFromString(n, "text/html");
|
|
3295
|
+
if (e.body.childElementCount === 1 && e.body.firstElementChild?.tagName === "IMG") {
|
|
3296
|
+
this.rich.uploader.upload(t, i);
|
|
3297
|
+
return;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
this.onPaste(t, {
|
|
3301
|
+
html: n,
|
|
3302
|
+
text: r
|
|
3303
|
+
});
|
|
3304
|
+
}
|
|
3305
|
+
onCopy(e) {
|
|
3306
|
+
let t = this.rich.getText(e);
|
|
3307
|
+
return {
|
|
3308
|
+
html: this.rich.getSemanticHTML(e),
|
|
3309
|
+
text: t
|
|
3310
|
+
};
|
|
3311
|
+
}
|
|
3312
|
+
onPaste(e, { text: t, html: n }) {
|
|
3313
|
+
let r = this.rich.getFormat(e.index), i = this.convert({
|
|
3314
|
+
text: t,
|
|
3315
|
+
html: n
|
|
3316
|
+
}, r);
|
|
3317
|
+
Hr.log("onPaste", i, {
|
|
3318
|
+
text: t,
|
|
3319
|
+
html: n
|
|
3320
|
+
});
|
|
3321
|
+
let a = new s().retain(e.index).delete(e.length).concat(i);
|
|
3322
|
+
this.rich.updateContents(a, q.sources.USER), this.rich.setSelection(a.length() - e.length, q.sources.SILENT), this.rich.scrollSelectionIntoView();
|
|
3323
|
+
}
|
|
3324
|
+
prepareMatching(e, t) {
|
|
3325
|
+
let n = [], r = [];
|
|
3326
|
+
return this.matchers.forEach((i) => {
|
|
3327
|
+
let [a, o] = i;
|
|
3328
|
+
switch (a) {
|
|
3329
|
+
case Node.TEXT_NODE:
|
|
3330
|
+
r.push(o);
|
|
3331
|
+
break;
|
|
3332
|
+
case Node.ELEMENT_NODE:
|
|
3333
|
+
n.push(o);
|
|
3334
|
+
break;
|
|
3335
|
+
default:
|
|
3336
|
+
Array.from(e.querySelectorAll(a)).forEach((e) => {
|
|
3337
|
+
t.has(e) ? t.get(e)?.push?.(o) : t.set(e, [o]);
|
|
3338
|
+
});
|
|
3339
|
+
break;
|
|
3340
|
+
}
|
|
3341
|
+
}), [n, r];
|
|
3342
|
+
}
|
|
3343
|
+
};
|
|
3344
|
+
function qr(e, t, n, r) {
|
|
3345
|
+
return r.query(t) ? e.reduce((e, r) => {
|
|
3346
|
+
if (!r.insert) return e;
|
|
3347
|
+
if (r.attributes && r.attributes[t]) return e.push(r);
|
|
3348
|
+
let i = n ? { [t]: n } : {};
|
|
3349
|
+
return e.insert(r.insert, {
|
|
3350
|
+
...i,
|
|
3351
|
+
...r.attributes
|
|
3352
|
+
});
|
|
3353
|
+
}, new s()) : e;
|
|
3354
|
+
}
|
|
3355
|
+
function Jr(e, t) {
|
|
3356
|
+
let n = "";
|
|
3357
|
+
for (let r = e.ops.length - 1; r >= 0 && n.length < t.length; --r) {
|
|
3358
|
+
let t = e.ops[r];
|
|
3359
|
+
if (!x(t.insert)) break;
|
|
3360
|
+
n = t.insert + n;
|
|
3361
|
+
}
|
|
3362
|
+
return n.slice(-1 * t.length) === t;
|
|
3363
|
+
}
|
|
3364
|
+
function Yr(e, t) {
|
|
3365
|
+
return !h(e) || t.query(e)?.prototype instanceof V ? !1 : (/* @__PURE__ */ "address.article.blockquote.canvas.dd.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.iframe.li.main.nav.ol.output.p.pre.section.table.td.tr.ul.video".split(".")).includes(e.tagName.toLowerCase());
|
|
3366
|
+
}
|
|
3367
|
+
function Xr(e, t) {
|
|
3368
|
+
return e.previousElementSibling && e.nextElementSibling && !Yr(e.previousElementSibling, t) && !Yr(e.nextElementSibling, t);
|
|
3369
|
+
}
|
|
3370
|
+
var Zr = /* @__PURE__ */ new WeakMap();
|
|
3371
|
+
function Qr(e) {
|
|
3372
|
+
return e == null ? !1 : (Zr.has(e) || (e.tagName === "PRE" ? Zr.set(e, !0) : Zr.set(e, Qr(e.parentNode))), Zr.get(e));
|
|
3373
|
+
}
|
|
3374
|
+
function $r(e, t, n, r, i) {
|
|
3375
|
+
return t.nodeType === t.TEXT_NODE ? r.reduce((n, r) => r(t, n, e), new s()) : t.nodeType === t.ELEMENT_NODE ? Array.from(t.childNodes || []).reduce((a, o) => {
|
|
3376
|
+
let s = $r(e, o, n, r, i);
|
|
3377
|
+
return o.nodeType === t.ELEMENT_NODE && (s = n.reduce((t, n) => n(o, t, e), s), s = (i.get(o) || []).reduce((t, n) => n(o, t, e), s)), a.concat(s);
|
|
3378
|
+
}, new s()) : new s();
|
|
3379
|
+
}
|
|
3380
|
+
function ei(e) {
|
|
3381
|
+
return (t, n, r) => qr(n, e, !0, r);
|
|
3382
|
+
}
|
|
3383
|
+
function ti(e, t, n) {
|
|
3384
|
+
let r = z.keys(e), i = B.keys(e), a = _t.keys(e), o = {};
|
|
3385
|
+
return r.concat(i).concat(a).forEach((t) => {
|
|
3386
|
+
let r = n.query(t, I.ATTRIBUTE);
|
|
3387
|
+
r != null && (o[r.attrName] = r.value(e), o[r.attrName]) || (r = Wr[t], r != null && (r.attrName === t || r.keyName === t) && (o[r.attrName] = r.value(e) || void 0), r = Gr[t], r != null && (r.attrName === t || r.keyName === t) && (r = Gr[t], o[r.attrName] = r.value(e) || void 0));
|
|
3388
|
+
}), Object.entries(o).reduce((e, [t, r]) => qr(e, t, r, n), t);
|
|
3389
|
+
}
|
|
3390
|
+
function ni(e, t, n) {
|
|
3391
|
+
let r = n.query(e);
|
|
3392
|
+
if (r == null) return t;
|
|
3393
|
+
if (r.prototype instanceof V) {
|
|
3394
|
+
let t = {}, i = r.value(e);
|
|
3395
|
+
if (i != null) return t[r.blotName] = i, new s().insert(t, r.formats(e, n));
|
|
3396
|
+
} else if (r.prototype instanceof bt && !Jr(t, "\n") && t.insert("\n"), "blotName" in r && "formats" in r && _(r.formats)) return qr(t, r.blotName, r.formats(e, n), n);
|
|
3397
|
+
return t;
|
|
3398
|
+
}
|
|
3399
|
+
function ri(e, t) {
|
|
3400
|
+
return Jr(t, "\n") || t.insert("\n"), t;
|
|
3401
|
+
}
|
|
3402
|
+
function ii(e, t, n) {
|
|
3403
|
+
let r = n.query("code-block");
|
|
3404
|
+
return qr(t, "code-block", r && "formats" in r && _(r.formats) ? r.formats(e, n) : !0, n);
|
|
3405
|
+
}
|
|
3406
|
+
function ai() {
|
|
3407
|
+
return new s();
|
|
3408
|
+
}
|
|
3409
|
+
function oi(e, t, n) {
|
|
3410
|
+
let r = n.query(e);
|
|
3411
|
+
if (r == null || r.blotName !== "list" || !Jr(t, "\n")) return t;
|
|
3412
|
+
let i = -1, a = e.parentNode;
|
|
3413
|
+
for (; a != null;) ["OL", "UL"].includes(a.tagName) && (i += 1), a = a.parentNode;
|
|
3414
|
+
return i <= 0 ? t : t.reduce((e, t) => t.insert ? t.attributes && y(t.attributes.indent) ? e.push(t) : e.insert(t.insert, {
|
|
3415
|
+
indent: i,
|
|
3416
|
+
...t.attributes || {}
|
|
3417
|
+
}) : e, new s());
|
|
3418
|
+
}
|
|
3419
|
+
function si(e, t, n) {
|
|
3420
|
+
let r = e, i = r.tagName === "OL" ? "ordered" : "bullet", a = r.getAttribute("data-checked");
|
|
3421
|
+
return a && (i = a === "true" ? "checked" : "unchecked"), qr(t, "list", i, n);
|
|
3422
|
+
}
|
|
3423
|
+
function ci(e, t, n) {
|
|
3424
|
+
if (!Jr(t, "\n")) {
|
|
3425
|
+
if (Yr(e, n) && (e.childNodes.length > 0 || e instanceof HTMLParagraphElement)) return t.insert("\n");
|
|
3426
|
+
if (t.length() > 0 && e.nextSibling) {
|
|
3427
|
+
let r = e.nextSibling;
|
|
3428
|
+
for (; r != null;) {
|
|
3429
|
+
if (Yr(r, n) || n.query(r)?.prototype instanceof G) return t.insert("\n");
|
|
3430
|
+
r = r.firstChild;
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
return t;
|
|
3435
|
+
}
|
|
3436
|
+
function li(e, t, n) {
|
|
3437
|
+
let r = {}, i = e.style || {};
|
|
3438
|
+
return i.fontStyle === "italic" && (r.italic = !0), i.textDecoration === "underline" && (r.underline = !0), i.textDecoration === "line-through" && (r.strike = !0), (i.fontWeight?.startsWith?.("bold") || parseInt(i.fontWeight, 10) >= 700) && (r.bold = !0), t = Object.entries(r).reduce((e, [t, r]) => qr(e, t, r, n), t), parseFloat(i.textIndent || 0) > 0 ? new s().insert(" ").concat(t) : t;
|
|
3439
|
+
}
|
|
3440
|
+
function ui(e, t, n) {
|
|
3441
|
+
let r = e.parentElement?.tagName === "TABLE" ? e.parentElement : e.parentElement?.parentElement;
|
|
3442
|
+
return r == null ? t : qr(t, "table", Array.from(r.querySelectorAll("tr")).indexOf(e) + 1, n);
|
|
3443
|
+
}
|
|
3444
|
+
function di(e, t, n) {
|
|
3445
|
+
let r = e.data;
|
|
3446
|
+
if (e.parentElement?.tagName === "O:P") return t.insert(r.trim());
|
|
3447
|
+
if (!Qr(e)) {
|
|
3448
|
+
if (r.trim().length === 0 && r.includes("\n") && !Xr(e, n)) return t;
|
|
3449
|
+
r = r.replace(/[^\S\u00a0]/g, " "), r = r.replace(/ {2,}/g, " "), (e.previousSibling == null && e.parentElement != null && Yr(e.parentElement, n) || h(e.previousSibling) && Yr(e.previousSibling, n)) && (r = r.replace(/^ /, "")), (e.nextSibling == null && e.parentElement != null && Yr(e.parentElement, n) || h(e.nextSibling) && Yr(e.nextSibling, n)) && (r = r.replace(/ $/, "")), r = r.replaceAll("\xA0", " ");
|
|
3450
|
+
}
|
|
3451
|
+
return t.insert(r);
|
|
3452
|
+
}
|
|
3453
|
+
//#endregion
|
|
3454
|
+
//#region libs/rich-text/modules/history.ts
|
|
3455
|
+
var fi = class extends P {
|
|
3456
|
+
static DEFAULTS = {
|
|
3457
|
+
delay: 1e3,
|
|
3458
|
+
maxStack: 100,
|
|
3459
|
+
userOnly: !1
|
|
3460
|
+
};
|
|
3461
|
+
lastRecorded = 0;
|
|
3462
|
+
ignoreChange = !1;
|
|
3463
|
+
stack = {
|
|
3464
|
+
undo: [],
|
|
3465
|
+
redo: []
|
|
3466
|
+
};
|
|
3467
|
+
currentRange = null;
|
|
3468
|
+
constructor(e, t) {
|
|
3469
|
+
super(e, t), this.rich.on(q.events.EDITOR_CHANGE, this.#e), this.rich.keyboard.addBinding({
|
|
3470
|
+
key: "z",
|
|
3471
|
+
shortKey: !0
|
|
3472
|
+
}, this.undo.bind(this)), this.rich.keyboard.addBinding({
|
|
3473
|
+
key: ["z", "Z"],
|
|
3474
|
+
shortKey: !0,
|
|
3475
|
+
shiftKey: !0
|
|
3476
|
+
}, this.redo.bind(this)), E && this.rich.keyboard.addBinding({
|
|
3477
|
+
key: "y",
|
|
3478
|
+
shortKey: !0
|
|
3479
|
+
}, this.redo.bind(this)), this.rich.root.addEventListener("beforeinput", this.#t);
|
|
3480
|
+
}
|
|
3481
|
+
#e = (e, t, n, r) => {
|
|
3482
|
+
e === q.events.SELECTION_CHANGE ? t && r !== q.sources.SILENT && (this.currentRange = t) : e === q.events.TEXT_CHANGE && (this.ignoreChange || (!this.options.userOnly || r === q.sources.USER ? this.record(t, n) : this.transform(t)), this.currentRange = gi(this.currentRange, t));
|
|
3483
|
+
};
|
|
3484
|
+
#t = (e) => {
|
|
3485
|
+
e.inputType === "historyUndo" ? (this.undo(), e.preventDefault()) : e.inputType === "historyRedo" && (this.redo(), e.preventDefault());
|
|
3486
|
+
};
|
|
3487
|
+
destroy() {
|
|
3488
|
+
super.destroy(), this.clear(), this.rich.off(q.events.EDITOR_CHANGE, this.#e), this.rich.root.removeEventListener("beforeinput", this.#t);
|
|
3489
|
+
}
|
|
3490
|
+
change(e, t) {
|
|
3491
|
+
if (this.stack[e].length === 0) return;
|
|
3492
|
+
let n = this.stack[e].pop();
|
|
3493
|
+
if (!n) return;
|
|
3494
|
+
let r = this.rich.getContents(), i = n.delta.invert(r);
|
|
3495
|
+
this.stack[t].push({
|
|
3496
|
+
delta: i,
|
|
3497
|
+
range: gi(n.range, i)
|
|
3498
|
+
}), this.lastRecorded = 0, this.ignoreChange = !0, this.rich.updateContents(n.delta, q.sources.USER), this.ignoreChange = !1, this.restoreSelection(n);
|
|
3499
|
+
}
|
|
3500
|
+
clear() {
|
|
3501
|
+
this.stack = {
|
|
3502
|
+
undo: [],
|
|
3503
|
+
redo: []
|
|
3504
|
+
};
|
|
3505
|
+
}
|
|
3506
|
+
cutoff() {
|
|
3507
|
+
this.lastRecorded = 0;
|
|
3508
|
+
}
|
|
3509
|
+
record(e, t) {
|
|
3510
|
+
if (e.ops.length === 0) return;
|
|
3511
|
+
this.stack.redo = [];
|
|
3512
|
+
let n = e.invert(t), r = this.currentRange, i = Date.now();
|
|
3513
|
+
if (this.lastRecorded + this.options.delay > i && this.stack.undo.length > 0) {
|
|
3514
|
+
let e = this.stack.undo.pop();
|
|
3515
|
+
e && (n = n.compose(e.delta), r = e.range);
|
|
3516
|
+
} else this.lastRecorded = i;
|
|
3517
|
+
n.length() !== 0 && (this.stack.undo.push({
|
|
3518
|
+
delta: n,
|
|
3519
|
+
range: r
|
|
3520
|
+
}), this.stack.undo.length > this.options.maxStack && this.stack.undo.shift());
|
|
3521
|
+
}
|
|
3522
|
+
redo() {
|
|
3523
|
+
this.change("redo", "undo");
|
|
3524
|
+
}
|
|
3525
|
+
transform(e) {
|
|
3526
|
+
pi(this.stack.undo, e), pi(this.stack.redo, e);
|
|
3527
|
+
}
|
|
3528
|
+
undo() {
|
|
3529
|
+
this.change("undo", "redo");
|
|
3530
|
+
}
|
|
3531
|
+
restoreSelection(e) {
|
|
3532
|
+
if (e.range) this.rich.setSelection(e.range, q.sources.USER);
|
|
3533
|
+
else {
|
|
3534
|
+
let t = hi(this.rich.scroll, e.delta);
|
|
3535
|
+
this.rich.setSelection(t, q.sources.USER);
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
};
|
|
3539
|
+
function pi(e, t) {
|
|
3540
|
+
let n = t;
|
|
3541
|
+
for (let t = e.length - 1; t >= 0; --t) {
|
|
3542
|
+
let r = e[t];
|
|
3543
|
+
e[t] = {
|
|
3544
|
+
delta: n.transform(r.delta, !0),
|
|
3545
|
+
range: r.range && gi(r.range, n)
|
|
3546
|
+
}, n = r.delta.transform(n), e[t].delta.length() === 0 && e.splice(t, 1);
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
function mi(e, t) {
|
|
3550
|
+
let n = t.ops[t.ops.length - 1];
|
|
3551
|
+
return n == null ? !1 : x(n?.insert) ? `${n.insert}`.endsWith("\n") : n.attributes == null ? !1 : Object.keys(n.attributes).some((t) => e.query(t, I.BLOCK) != null);
|
|
3552
|
+
}
|
|
3553
|
+
function hi(e, t) {
|
|
3554
|
+
let n = t.reduce((e, t) => e + (t.delete || 0), 0), r = t.length() - n;
|
|
3555
|
+
return mi(e, t) && --r, r;
|
|
3556
|
+
}
|
|
3557
|
+
function gi(e, t) {
|
|
3558
|
+
if (!e) return e;
|
|
3559
|
+
let n = t.transformPosition(e.index);
|
|
3560
|
+
return {
|
|
3561
|
+
index: n,
|
|
3562
|
+
length: t.transformPosition(e.index + e.length) - n
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
//#endregion
|
|
3566
|
+
//#region libs/rich-text/modules/image-resize/modules/Base.js
|
|
3567
|
+
var _i = class {
|
|
3568
|
+
constructor(e) {
|
|
3569
|
+
this.overlay = e.overlay, this.img = e.img, this.options = e.options, this.requestUpdate = e.onUpdate;
|
|
3570
|
+
}
|
|
3571
|
+
onCreate = () => {};
|
|
3572
|
+
onDestroy = () => {};
|
|
3573
|
+
onUpdate = () => {};
|
|
3574
|
+
destroy() {}
|
|
3575
|
+
}, vi = class extends _i {
|
|
3576
|
+
onCreate = () => {
|
|
3577
|
+
this.display = document.createElement("div"), this.display.classList.add(`${F}-image-resize-size-display`), Object.assign(this.display.style, this.options.displayStyles), this.overlay.appendChild(this.display);
|
|
3578
|
+
};
|
|
3579
|
+
onDestroy = () => {};
|
|
3580
|
+
destroy() {
|
|
3581
|
+
super.destroy();
|
|
3582
|
+
}
|
|
3583
|
+
onUpdate = () => {
|
|
3584
|
+
if (!this.display || !this.img) return;
|
|
3585
|
+
let e = this.getCurrentSize();
|
|
3586
|
+
if (this.display.innerHTML = e.join(" × "), e[0] > 120 && e[1] > 30) Object.assign(this.display.style, {
|
|
3587
|
+
right: "4px",
|
|
3588
|
+
bottom: "4px",
|
|
3589
|
+
left: "auto"
|
|
3590
|
+
});
|
|
3591
|
+
else if (this.img.style.float == "right") {
|
|
3592
|
+
let e = this.display.getBoundingClientRect();
|
|
3593
|
+
Object.assign(this.display.style, {
|
|
3594
|
+
right: "auto",
|
|
3595
|
+
bottom: `-${e.height + 4}px`,
|
|
3596
|
+
left: `-${e.width + 4}px`
|
|
3597
|
+
});
|
|
3598
|
+
} else {
|
|
3599
|
+
let e = this.display.getBoundingClientRect();
|
|
3600
|
+
Object.assign(this.display.style, {
|
|
3601
|
+
right: `-${e.width + 4}px`,
|
|
3602
|
+
bottom: `-${e.height + 4}px`,
|
|
3603
|
+
left: "auto"
|
|
3604
|
+
});
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
getCurrentSize = () => [this.img.width, Math.round(this.img.width / this.img.naturalWidth * this.img.naturalHeight)];
|
|
3608
|
+
}, yi = class extends _i {
|
|
3609
|
+
onCreate = () => {
|
|
3610
|
+
this.boxes = [], this.addBox("nwse-resize"), this.addBox("nesw-resize"), this.addBox("nwse-resize"), this.addBox("nesw-resize"), this.positionBoxes();
|
|
3611
|
+
};
|
|
3612
|
+
onDestroy = () => {
|
|
3613
|
+
this.setCursor(""), this.destroy();
|
|
3614
|
+
};
|
|
3615
|
+
positionBoxes = () => {
|
|
3616
|
+
[
|
|
3617
|
+
{
|
|
3618
|
+
left: 0,
|
|
3619
|
+
top: 0
|
|
3620
|
+
},
|
|
3621
|
+
{
|
|
3622
|
+
right: 0,
|
|
3623
|
+
top: 0
|
|
3624
|
+
},
|
|
3625
|
+
{
|
|
3626
|
+
right: 0,
|
|
3627
|
+
bottom: 0
|
|
3628
|
+
},
|
|
3629
|
+
{
|
|
3630
|
+
left: 0,
|
|
3631
|
+
bottom: 0
|
|
3632
|
+
}
|
|
3633
|
+
].forEach((e, t) => {
|
|
3634
|
+
Object.assign(this.boxes[t].style, e);
|
|
3635
|
+
});
|
|
3636
|
+
};
|
|
3637
|
+
addBox = (e) => {
|
|
3638
|
+
let t = document.createElement("div");
|
|
3639
|
+
t.classList.add(`${F}-image-resize-handle`), t.style.cursor = e, t.addEventListener("mousedown", this.handleMousedown, !1), this.overlay.appendChild(t), this.boxes.push(t);
|
|
3640
|
+
};
|
|
3641
|
+
destroy() {
|
|
3642
|
+
super.destroy(), this.boxes.forEach((e) => {
|
|
3643
|
+
e.removeEventListener("mousedown", this.handleMousedown, !1);
|
|
3644
|
+
});
|
|
3645
|
+
}
|
|
3646
|
+
handleMousedown = (e) => {
|
|
3647
|
+
this.dragBox = e.target, this.dragStartX = e.clientX, this.preDragWidth = this.img.width || this.img.naturalWidth, this.setCursor(this.dragBox.style.cursor), document.addEventListener("mousemove", this.handleDrag, !1), document.addEventListener("mouseup", this.handleMouseup, !1);
|
|
3648
|
+
};
|
|
3649
|
+
handleMouseup = () => {
|
|
3650
|
+
this.setCursor(""), document.removeEventListener("mousemove", this.handleDrag), document.removeEventListener("mouseup", this.handleMouseup);
|
|
3651
|
+
};
|
|
3652
|
+
handleDrag = (e) => {
|
|
3653
|
+
if (!this.img) return;
|
|
3654
|
+
let t = e.clientX - this.dragStartX;
|
|
3655
|
+
this.dragBox === this.boxes[0] || this.dragBox === this.boxes[3] ? this.img.width = Math.round(this.preDragWidth - t) : this.img.width = Math.round(this.preDragWidth + t), this.requestUpdate();
|
|
3656
|
+
};
|
|
3657
|
+
setCursor = (e) => {
|
|
3658
|
+
[document.body, this.img].forEach((t) => {
|
|
3659
|
+
t.style.cursor = e;
|
|
3660
|
+
});
|
|
3661
|
+
};
|
|
3662
|
+
}, bi = {
|
|
3663
|
+
modules: ["DisplaySize", "Resize"],
|
|
3664
|
+
overlayStyles: {},
|
|
3665
|
+
handleStyles: {},
|
|
3666
|
+
displayStyles: {}
|
|
3667
|
+
}, xi = {
|
|
3668
|
+
DisplaySize: vi,
|
|
3669
|
+
Resize: yi
|
|
3670
|
+
}, Si = class extends P {
|
|
3671
|
+
constructor(e, t = {}) {
|
|
3672
|
+
super(e, t);
|
|
3673
|
+
let n = !1;
|
|
3674
|
+
t.modules && (n = t.modules.slice()), this.options = _e({}, t, bi), n !== !1 && (this.options.modules = n), this.rich.root.addEventListener("click", this.handleClick, !1), this.rich.root.parentNode.style.position = this.rich.root.parentNode.style.position || "relative", this.moduleClasses = this.options.modules, console.log("this.options.modules", this.options.modules), this.modules = [];
|
|
3675
|
+
}
|
|
3676
|
+
initializeModules = () => {
|
|
3677
|
+
this.removeModules(), this.modules = this.moduleClasses.map((e) => new (xi[e] || e)(this)), this.modules.forEach((e) => {
|
|
3678
|
+
e.onCreate();
|
|
3679
|
+
}), this.onUpdate();
|
|
3680
|
+
};
|
|
3681
|
+
onUpdate = () => {
|
|
3682
|
+
this.repositionElements(), this.modules.forEach((e) => {
|
|
3683
|
+
e.onUpdate();
|
|
3684
|
+
});
|
|
3685
|
+
};
|
|
3686
|
+
removeModules = () => {
|
|
3687
|
+
this.modules.forEach((e) => {
|
|
3688
|
+
e.onDestroy(), e.destroy();
|
|
3689
|
+
}), this.modules = [];
|
|
3690
|
+
};
|
|
3691
|
+
handleClick = (e) => {
|
|
3692
|
+
if (e?.target?.tagName?.toUpperCase?.() === "IMG") {
|
|
3693
|
+
if (this.img === e.target) return;
|
|
3694
|
+
this.img && this.hide(), this.show(e.target);
|
|
3695
|
+
} else this.img && this.hide();
|
|
3696
|
+
};
|
|
3697
|
+
show = (e) => {
|
|
3698
|
+
this.img = e, this.showOverlay(), this.initializeModules(), this.setSelectionByNode();
|
|
3699
|
+
};
|
|
3700
|
+
setSelectionByNode = () => {
|
|
3701
|
+
this.rich.selection.setSelectionByNode(this.img);
|
|
3702
|
+
};
|
|
3703
|
+
showOverlay = () => {
|
|
3704
|
+
this.overlay && this.hideOverlay(), document.addEventListener("keyup", this.checkImage, !0), this.rich.root.addEventListener("input", this.checkImage, !0), this.overlay = document.createElement("div"), this.overlay.addEventListener("click", this.overlayClickHanlder, !0), this.overlay.classList.add(`${F}-image-resize-overlay`), Object.assign(this.overlay.style, this.options.overlayStyles), this.rich.root.addEventListener("scroll", this.rootScroll), this.rich.root.parentNode.appendChild(this.overlay), this.repositionElements();
|
|
3705
|
+
};
|
|
3706
|
+
overlayClickHanlder = () => {
|
|
3707
|
+
this.setSelectionByNode();
|
|
3708
|
+
};
|
|
3709
|
+
hideOverlay = () => {
|
|
3710
|
+
this.overlay &&= (document.removeEventListener("keyup", this.checkImage), this.rich.root.removeEventListener("input", this.checkImage), this.overlay.removeEventListener("click", this.overlayClickHanlder, !0), this.rich.root.parentNode.removeChild(this.overlay), this.rich.root.removeEventListener("scroll", this.rootScroll), void 0);
|
|
3711
|
+
};
|
|
3712
|
+
repositionElements = () => {
|
|
3713
|
+
if (!this.overlay || !this.img) return;
|
|
3714
|
+
let e = this.rich.root.parentNode, t = this.img.getBoundingClientRect(), n = e.getBoundingClientRect();
|
|
3715
|
+
Object.assign(this.overlay.style, {
|
|
3716
|
+
left: `${t.left - n.left + e.scrollLeft}px`,
|
|
3717
|
+
top: `${t.top - n.top + e.scrollTop}px`,
|
|
3718
|
+
width: `${t.width}px`,
|
|
3719
|
+
height: `${t.height}px`
|
|
3720
|
+
});
|
|
3721
|
+
};
|
|
3722
|
+
hide = () => {
|
|
3723
|
+
this.hideOverlay(), this.removeModules(), this.img = void 0;
|
|
3724
|
+
};
|
|
3725
|
+
destroy = () => {
|
|
3726
|
+
this.hideOverlay(), this.removeModules(), this.rich.root.removeEventListener("click", this.handleClick, !1);
|
|
3727
|
+
};
|
|
3728
|
+
checkImage = (e) => {
|
|
3729
|
+
this.img && ((e.keyCode == 46 || e.keyCode == 8) && q.find(this.img).deleteAt(0), this.hide());
|
|
3730
|
+
};
|
|
3731
|
+
rootScroll = (e) => {
|
|
3732
|
+
this.repositionElements();
|
|
3733
|
+
};
|
|
3734
|
+
}, Ci = ["insertText", "insertReplacementText"], wi = class extends P {
|
|
3735
|
+
constructor(e, t) {
|
|
3736
|
+
super(e, t), this.rich.root.addEventListener("beforeinput", this.#t), /Android/i.test(navigator.userAgent) || this.rich.on(q.events.COMPOSITION_BEFORE_START, this.#e);
|
|
3737
|
+
}
|
|
3738
|
+
#e = () => {
|
|
3739
|
+
this.#a();
|
|
3740
|
+
};
|
|
3741
|
+
#t = (e) => {
|
|
3742
|
+
this.#i(e);
|
|
3743
|
+
};
|
|
3744
|
+
destroy() {
|
|
3745
|
+
super.destroy(), this.rich.off(q.events.COMPOSITION_BEFORE_START, this.#e), this.rich.root.removeEventListener("beforeinput", this.#t);
|
|
3746
|
+
}
|
|
3747
|
+
#n(e) {
|
|
3748
|
+
Er({
|
|
3749
|
+
range: e,
|
|
3750
|
+
rich: this.rich
|
|
3751
|
+
});
|
|
3752
|
+
}
|
|
3753
|
+
#r(e, t = "") {
|
|
3754
|
+
if (e.length === 0) return !1;
|
|
3755
|
+
if (t) {
|
|
3756
|
+
let n = this.rich.getFormat(e.index, 1);
|
|
3757
|
+
this.#n(e), this.rich.updateContents(new s().retain(e.index).insert(t, n), q.sources.USER);
|
|
3758
|
+
} else this.#n(e);
|
|
3759
|
+
return this.rich.setSelection(e.index + t.length, 0, q.sources.SILENT), !0;
|
|
3760
|
+
}
|
|
3761
|
+
#i(e) {
|
|
3762
|
+
if (this.rich.composition.isComposing || e.defaultPrevented || !Ci.includes(e.inputType)) return;
|
|
3763
|
+
let t = e.getTargetRanges ? e.getTargetRanges()[0] : null;
|
|
3764
|
+
if (!t || t.collapsed === !0) return;
|
|
3765
|
+
let n = Ti(e);
|
|
3766
|
+
if (n == null) return;
|
|
3767
|
+
let r = this.rich.selection.normalizeNative(t), i = r ? this.rich.selection.normalizedToRange(r) : null;
|
|
3768
|
+
i && this.#r(i, n) && e.preventDefault();
|
|
3769
|
+
}
|
|
3770
|
+
#a() {
|
|
3771
|
+
let e = this.rich.getSelection();
|
|
3772
|
+
e && this.#r(e);
|
|
3773
|
+
}
|
|
3774
|
+
};
|
|
3775
|
+
function Ti(e) {
|
|
3776
|
+
return x(e.data) ? e.data : e.dataTransfer?.types?.includes?.("text/plain") ? e.dataTransfer.getData("text/plain") : null;
|
|
3777
|
+
}
|
|
3778
|
+
//#endregion
|
|
3779
|
+
//#region libs/rich-text/formats/table.ts
|
|
3780
|
+
var $ = class e extends W {
|
|
3781
|
+
static blotName = "table";
|
|
3782
|
+
static tagName = "TD";
|
|
3783
|
+
static create(e) {
|
|
3784
|
+
let t = super.create();
|
|
3785
|
+
return e ? t.setAttribute("data-row", e) : t.setAttribute("data-row", ki()), t;
|
|
3786
|
+
}
|
|
3787
|
+
static formats(e) {
|
|
3788
|
+
if (e.hasAttribute("data-row")) return e.getAttribute("data-row");
|
|
3789
|
+
}
|
|
3790
|
+
next;
|
|
3791
|
+
cellOffset() {
|
|
3792
|
+
return this.parent ? this.parent.children.indexOf(this) : -1;
|
|
3793
|
+
}
|
|
3794
|
+
format(t, n) {
|
|
3795
|
+
t === e.blotName && n ? this.domNode.setAttribute("data-row", n) : super.format(t, n);
|
|
3796
|
+
}
|
|
3797
|
+
row() {
|
|
3798
|
+
return this.parent;
|
|
3799
|
+
}
|
|
3800
|
+
rowOffset() {
|
|
3801
|
+
return this.row() ? this.row().rowOffset() : -1;
|
|
3802
|
+
}
|
|
3803
|
+
table() {
|
|
3804
|
+
return this.row()?.table();
|
|
3805
|
+
}
|
|
3806
|
+
};
|
|
3807
|
+
$.className = `${F}-table-cell`;
|
|
3808
|
+
var Ei = class extends In {
|
|
3809
|
+
static blotName = "table-row";
|
|
3810
|
+
static tagName = "TR";
|
|
3811
|
+
children;
|
|
3812
|
+
next;
|
|
3813
|
+
checkMerge() {
|
|
3814
|
+
if (super.checkMerge() && this.next.children.head != null) {
|
|
3815
|
+
let e = this.children.head.formats(), t = this.children.tail.formats(), n = this.next.children.head.formats(), r = this.next.children.tail.formats();
|
|
3816
|
+
return e.table === t.table && e.table === n.table && e.table === r.table;
|
|
3817
|
+
}
|
|
3818
|
+
return !1;
|
|
3819
|
+
}
|
|
3820
|
+
optimize(e) {
|
|
3821
|
+
super.optimize(e), this.children.forEach((e) => {
|
|
3822
|
+
if (e.next == null) return;
|
|
3823
|
+
let t = e.formats(), n = e.next.formats();
|
|
3824
|
+
if (t.table !== n.table) {
|
|
3825
|
+
let t = this.splitAfter(e);
|
|
3826
|
+
t && t.optimize(), this.prev && this.prev.optimize();
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
}
|
|
3830
|
+
rowOffset() {
|
|
3831
|
+
return this.parent ? this.parent.children.indexOf(this) : -1;
|
|
3832
|
+
}
|
|
3833
|
+
table() {
|
|
3834
|
+
return this.parent?.parent;
|
|
3835
|
+
}
|
|
3836
|
+
};
|
|
3837
|
+
Ei.className = `${F}-table-row`;
|
|
3838
|
+
var Di = class extends In {
|
|
3839
|
+
static blotName = "table-body";
|
|
3840
|
+
static tagName = "TBODY";
|
|
3841
|
+
children;
|
|
3842
|
+
};
|
|
3843
|
+
Di.className = `${F}-table-body`;
|
|
3844
|
+
var Oi = class extends In {
|
|
3845
|
+
static blotName = "table-container";
|
|
3846
|
+
static tagName = "TABLE";
|
|
3847
|
+
children;
|
|
3848
|
+
balanceCells() {
|
|
3849
|
+
let e = this.descendants(Ei), t = e.reduce((e, t) => Math.max(t.children.length, e), 0);
|
|
3850
|
+
e.forEach((e) => {
|
|
3851
|
+
Array(t - e.children.length).fill(0).forEach(() => {
|
|
3852
|
+
let t;
|
|
3853
|
+
e.children.head != null && (t = $.formats(e.children.head.domNode));
|
|
3854
|
+
let n = this.scroll.create($.blotName, t);
|
|
3855
|
+
e.appendChild(n), n.optimize();
|
|
3856
|
+
});
|
|
3857
|
+
});
|
|
3858
|
+
}
|
|
3859
|
+
cells(e) {
|
|
3860
|
+
return this.rows().map((t) => t.children.at(e));
|
|
3861
|
+
}
|
|
3862
|
+
deleteColumn(e) {
|
|
3863
|
+
let [t] = this.descendant(Di);
|
|
3864
|
+
t == null || t.children.head == null || t.children.forEach((t) => {
|
|
3865
|
+
t.children.at(e)?.remove();
|
|
3866
|
+
});
|
|
3867
|
+
}
|
|
3868
|
+
insertColumn(e) {
|
|
3869
|
+
let [t] = this.descendant(Di);
|
|
3870
|
+
t == null || t.children.head == null || t.children.forEach((t) => {
|
|
3871
|
+
let n = t.children.at(e), r = $.formats(t.children.head.domNode), i = this.scroll.create($.blotName, r);
|
|
3872
|
+
t.insertBefore(i, n);
|
|
3873
|
+
});
|
|
3874
|
+
}
|
|
3875
|
+
insertRow(e) {
|
|
3876
|
+
let [t] = this.descendant(Di);
|
|
3877
|
+
if (t == null || t.children.head == null) return;
|
|
3878
|
+
let n = ki(), r = this.scroll.create(Ei.blotName);
|
|
3879
|
+
t.children.head.children.forEach(() => {
|
|
3880
|
+
let e = this.scroll.create($.blotName, n);
|
|
3881
|
+
r.appendChild(e);
|
|
3882
|
+
});
|
|
3883
|
+
let i = t.children.at(e);
|
|
3884
|
+
t.insertBefore(r, i);
|
|
3885
|
+
}
|
|
3886
|
+
rows() {
|
|
3887
|
+
let e = this.children.head;
|
|
3888
|
+
return e == null ? [] : e.children.map((e) => e);
|
|
3889
|
+
}
|
|
3890
|
+
};
|
|
3891
|
+
Oi.className = `${F}-table-container`, Oi.allowedChildren = [Di], Di.requiredContainer = Oi, Di.allowedChildren = [Ei], Ei.requiredContainer = Di, Ei.allowedChildren = [$], $.requiredContainer = Ei;
|
|
3892
|
+
function ki() {
|
|
3893
|
+
return `row-${Math.random().toString(36).slice(2, 6)}`;
|
|
3894
|
+
}
|
|
3895
|
+
//#endregion
|
|
3896
|
+
//#region libs/rich-text/modules/table.ts
|
|
3897
|
+
var Ai = class extends P {
|
|
3898
|
+
static register() {
|
|
3899
|
+
q.register($), q.register(Ei), q.register(Di), q.register(Oi);
|
|
3900
|
+
}
|
|
3901
|
+
constructor(...e) {
|
|
3902
|
+
super(...e), this.listenBalanceCells();
|
|
3903
|
+
}
|
|
3904
|
+
balanceTables() {
|
|
3905
|
+
this.rich.scroll.descendants(Oi).forEach((e) => {
|
|
3906
|
+
e.balanceCells();
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
deleteColumn() {
|
|
3910
|
+
let [e, , t] = this.getTable();
|
|
3911
|
+
t != null && (e.deleteColumn(t.cellOffset()), this.rich.update(q.sources.USER));
|
|
3912
|
+
}
|
|
3913
|
+
deleteRow() {
|
|
3914
|
+
let [, e] = this.getTable();
|
|
3915
|
+
e != null && (e.remove(), this.rich.update(q.sources.USER));
|
|
3916
|
+
}
|
|
3917
|
+
deleteTable() {
|
|
3918
|
+
let [e] = this.getTable();
|
|
3919
|
+
if (e == null) return;
|
|
3920
|
+
let t = e.offset();
|
|
3921
|
+
e.remove(), this.rich.update(q.sources.USER), this.rich.setSelection(t, q.sources.SILENT);
|
|
3922
|
+
}
|
|
3923
|
+
getTable(e = this.rich.getSelection()) {
|
|
3924
|
+
if (e == null) return [
|
|
3925
|
+
null,
|
|
3926
|
+
null,
|
|
3927
|
+
null,
|
|
3928
|
+
-1
|
|
3929
|
+
];
|
|
3930
|
+
let [t, n] = this.rich.getLine(e.index);
|
|
3931
|
+
if (t == null || t.statics.blotName !== $.blotName) return [
|
|
3932
|
+
null,
|
|
3933
|
+
null,
|
|
3934
|
+
null,
|
|
3935
|
+
-1
|
|
3936
|
+
];
|
|
3937
|
+
let r = t.parent;
|
|
3938
|
+
return [
|
|
3939
|
+
r.parent.parent,
|
|
3940
|
+
r,
|
|
3941
|
+
t,
|
|
3942
|
+
n
|
|
3943
|
+
];
|
|
3944
|
+
}
|
|
3945
|
+
insertColumn(e) {
|
|
3946
|
+
let t = this.rich.getSelection();
|
|
3947
|
+
if (!t) return;
|
|
3948
|
+
let [n, r, i] = this.getTable(t);
|
|
3949
|
+
if (i == null) return;
|
|
3950
|
+
let a = i.cellOffset();
|
|
3951
|
+
n.insertColumn(a + e), this.rich.update(q.sources.USER);
|
|
3952
|
+
let o = r.rowOffset();
|
|
3953
|
+
e === 0 && (o += 1), this.rich.setSelection(t.index + o, t.length, q.sources.SILENT);
|
|
3954
|
+
}
|
|
3955
|
+
insertColumnLeft() {
|
|
3956
|
+
this.insertColumn(0);
|
|
3957
|
+
}
|
|
3958
|
+
insertColumnRight() {
|
|
3959
|
+
this.insertColumn(1);
|
|
3960
|
+
}
|
|
3961
|
+
insertRow(e) {
|
|
3962
|
+
let t = this.rich.getSelection();
|
|
3963
|
+
if (!t) return;
|
|
3964
|
+
let [n, r, i] = this.getTable(t);
|
|
3965
|
+
if (i == null) return;
|
|
3966
|
+
let a = r.rowOffset();
|
|
3967
|
+
n.insertRow(a + e), this.rich.update(q.sources.USER), e > 0 ? this.rich.setSelection(t, q.sources.SILENT) : this.rich.setSelection(t.index + r.children.length, t.length, q.sources.SILENT);
|
|
3968
|
+
}
|
|
3969
|
+
insertRowAbove() {
|
|
3970
|
+
this.insertRow(0);
|
|
3971
|
+
}
|
|
3972
|
+
insertRowBelow() {
|
|
3973
|
+
this.insertRow(1);
|
|
3974
|
+
}
|
|
3975
|
+
insertTable(e, t) {
|
|
3976
|
+
let n = this.rich.getSelection();
|
|
3977
|
+
if (n == null) return;
|
|
3978
|
+
let r = Array(e).fill(0).reduce((e) => {
|
|
3979
|
+
let n = Array(t).fill("\n").join("");
|
|
3980
|
+
return e.insert(n, { table: ki() });
|
|
3981
|
+
}, new s().retain(n.index));
|
|
3982
|
+
this.rich.updateContents(r, q.sources.USER), this.rich.setSelection(n.index, q.sources.SILENT), this.balanceTables();
|
|
3983
|
+
}
|
|
3984
|
+
listenBalanceCells() {
|
|
3985
|
+
this.rich.on(q.events.SCROLL_OPTIMIZE, this.#e);
|
|
3986
|
+
}
|
|
3987
|
+
#e = (e) => {
|
|
3988
|
+
e.some((e) => [
|
|
3989
|
+
"TD",
|
|
3990
|
+
"TR",
|
|
3991
|
+
"TBODY",
|
|
3992
|
+
"TABLE"
|
|
3993
|
+
].includes(e.target.tagName) ? (this.rich.once(q.events.TEXT_CHANGE, (e, t, n) => {
|
|
3994
|
+
n === q.sources.USER && this.balanceTables();
|
|
3995
|
+
}), !0) : !1);
|
|
3996
|
+
};
|
|
3997
|
+
destroy() {
|
|
3998
|
+
super.destroy(), this.rich.off(q.events.SCROLL_OPTIMIZE, this.#e);
|
|
3999
|
+
}
|
|
4000
|
+
};
|
|
4001
|
+
//#endregion
|
|
4002
|
+
//#region libs/rich-text/modules/toolbar.ts
|
|
4003
|
+
M("rich:toolbar");
|
|
4004
|
+
var ji = class extends P {
|
|
4005
|
+
static DEFAULTS;
|
|
4006
|
+
constructor(e, t) {
|
|
4007
|
+
super(e, t);
|
|
4008
|
+
}
|
|
4009
|
+
destroy() {
|
|
4010
|
+
super.destroy();
|
|
4011
|
+
}
|
|
4012
|
+
};
|
|
4013
|
+
ji.DEFAULTS = {};
|
|
4014
|
+
//#endregion
|
|
4015
|
+
//#region libs/rich-text/modules/uiNode.ts
|
|
4016
|
+
var Mi = ve, Ni = (e) => !!(e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Home" || Mi && e.key === "a" && e.ctrlKey === !0), Pi = class extends P {
|
|
4017
|
+
isListening = !1;
|
|
4018
|
+
selectionChangeDeadline = 0;
|
|
4019
|
+
constructor(e, t) {
|
|
4020
|
+
super(e, t), this.#e(), this.#t();
|
|
4021
|
+
}
|
|
4022
|
+
#e() {
|
|
4023
|
+
this.rich.keyboard.addBinding({
|
|
4024
|
+
key: ["ArrowLeft", "ArrowRight"],
|
|
4025
|
+
offset: 0,
|
|
4026
|
+
shiftKey: null,
|
|
4027
|
+
handler(e, { line: t, event: n }) {
|
|
4028
|
+
if (!(t instanceof L) || !t.uiNode) return !0;
|
|
4029
|
+
let r = getComputedStyle(t.domNode).direction === "rtl";
|
|
4030
|
+
return r && n.key !== "ArrowRight" || !r && n.key !== "ArrowLeft" ? !0 : (this.rich.setSelection(e.index - 1, e.length + +!!n.shiftKey, q.sources.USER), !1);
|
|
4031
|
+
}
|
|
4032
|
+
});
|
|
4033
|
+
}
|
|
4034
|
+
#t() {
|
|
4035
|
+
this.rich.root.addEventListener("keydown", this.#n);
|
|
4036
|
+
}
|
|
4037
|
+
#n = (e) => {
|
|
4038
|
+
!e.defaultPrevented && Ni(e) && this.#r();
|
|
4039
|
+
};
|
|
4040
|
+
destroy() {
|
|
4041
|
+
super.destroy(), this.rich.root.removeEventListener("keydown", this.#n), document.removeEventListener("selectionchange", this.#i);
|
|
4042
|
+
}
|
|
4043
|
+
#r() {
|
|
4044
|
+
this.selectionChangeDeadline = Date.now() + 100, !this.isListening && (this.isListening = !0, document.addEventListener("selectionchange", this.#i, { once: !0 }));
|
|
4045
|
+
}
|
|
4046
|
+
#i() {
|
|
4047
|
+
this.isListening = !1, Date.now() <= this.selectionChangeDeadline && this.#a();
|
|
4048
|
+
}
|
|
4049
|
+
#a() {
|
|
4050
|
+
let e = window.getSelection();
|
|
4051
|
+
if (!e) return;
|
|
4052
|
+
let t = e.getRangeAt(0);
|
|
4053
|
+
if (t.collapsed !== !0 || t.startOffset !== 0) return;
|
|
4054
|
+
let n = this.rich.scroll.find(t.startContainer);
|
|
4055
|
+
if (!(n instanceof L) || !n.uiNode) return;
|
|
4056
|
+
let r = document.createRange();
|
|
4057
|
+
r.setStartAfter(n.uiNode), r.setEndAfter(n.uiNode), e.removeAllRanges(), e.addRange(r);
|
|
4058
|
+
}
|
|
4059
|
+
}, Fi = class extends P {
|
|
4060
|
+
static DEFAULTS;
|
|
4061
|
+
constructor(e, t) {
|
|
4062
|
+
super(e, t), e.root.addEventListener("drop", this.#e);
|
|
4063
|
+
}
|
|
4064
|
+
#e = (e) => {
|
|
4065
|
+
e.preventDefault();
|
|
4066
|
+
let t = null;
|
|
4067
|
+
if (document.caretRangeFromPoint) t = document.caretRangeFromPoint(e.clientX, e.clientY);
|
|
4068
|
+
else if (document.caretPositionFromPoint) {
|
|
4069
|
+
let n = document.caretPositionFromPoint(e.clientX, e.clientY);
|
|
4070
|
+
t = document.createRange(), t.setStart(n.offsetNode, n.offset), t.setEnd(n.offsetNode, n.offset);
|
|
4071
|
+
}
|
|
4072
|
+
let n = t && this.rich.selection.normalizeNative(t);
|
|
4073
|
+
if (n) {
|
|
4074
|
+
let t = this.rich.selection.normalizedToRange(n);
|
|
4075
|
+
e.dataTransfer?.files && this.upload(t, e.dataTransfer.files);
|
|
4076
|
+
}
|
|
4077
|
+
};
|
|
4078
|
+
destroy() {
|
|
4079
|
+
super.destroy(), this.rich.root.removeEventListener("drop", this.#e);
|
|
4080
|
+
}
|
|
4081
|
+
upload(e, t) {
|
|
4082
|
+
let n = Array.from(t).filter((e) => e && this.options.mimetypes?.includes?.(e.type));
|
|
4083
|
+
n.length > 0 && this.options.handler.call(this, e, n);
|
|
4084
|
+
}
|
|
4085
|
+
};
|
|
4086
|
+
Fi.DEFAULTS = {
|
|
4087
|
+
mimetypes: ["image/png", "image/jpeg"],
|
|
4088
|
+
handler(e, t) {
|
|
4089
|
+
if (!this.rich.scroll.query("image")) return;
|
|
4090
|
+
let n = t.map((e) => ye(e));
|
|
4091
|
+
Promise.all(n).then((t) => {
|
|
4092
|
+
let n = t.reduce((e, t) => e.insert({ image: t }), new s().retain(e.index).delete(e.length));
|
|
4093
|
+
this.rich.updateContents(n, N.sources.USER), this.rich.setSelection(e.index + t.length, N.sources.SILENT);
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
4096
|
+
}, q.register({
|
|
4097
|
+
"blots/block": W,
|
|
4098
|
+
"blots/block/embed": G,
|
|
4099
|
+
"blots/break": U,
|
|
4100
|
+
"blots/container": In,
|
|
4101
|
+
"blots/cursor": Pt,
|
|
4102
|
+
"blots/embed": kt,
|
|
4103
|
+
"blots/inline": jt,
|
|
4104
|
+
"blots/scroll": Hn,
|
|
4105
|
+
"blots/text": H,
|
|
4106
|
+
"modules/clipboard": Kr,
|
|
4107
|
+
"modules/history": fi,
|
|
4108
|
+
"modules/keyboard": br,
|
|
4109
|
+
"modules/uploader": Fi,
|
|
4110
|
+
"modules/input": wi,
|
|
4111
|
+
"modules/uiNode": Pi
|
|
4112
|
+
}), q.register({
|
|
4113
|
+
"attributors/attribute/direction": Cn,
|
|
4114
|
+
"attributors/class/align": yn,
|
|
4115
|
+
"attributors/class/background": Yn,
|
|
4116
|
+
"attributors/class/color": Kn,
|
|
4117
|
+
"attributors/class/direction": wn,
|
|
4118
|
+
"attributors/class/font": ir,
|
|
4119
|
+
"attributors/class/size": mr,
|
|
4120
|
+
"attributors/style/align": bn,
|
|
4121
|
+
"attributors/style/background": Xn,
|
|
4122
|
+
"attributors/style/color": qn,
|
|
4123
|
+
"attributors/style/direction": Tn,
|
|
4124
|
+
"attributors/style/font": ar,
|
|
4125
|
+
"attributors/style/size": hr,
|
|
4126
|
+
"attributors/style/line-height": ur
|
|
4127
|
+
}, !0), q.register({
|
|
4128
|
+
"formats/align": yn,
|
|
4129
|
+
"formats/direction": wn,
|
|
4130
|
+
"formats/indent": Fn,
|
|
4131
|
+
"formats/background": Xn,
|
|
4132
|
+
"formats/color": qn,
|
|
4133
|
+
"formats/font": ir,
|
|
4134
|
+
"formats/size": hr,
|
|
4135
|
+
"formats/line-height": ur,
|
|
4136
|
+
"formats/blockquote": Zn,
|
|
4137
|
+
"formats/code-block": Q,
|
|
4138
|
+
"formats/header": sr,
|
|
4139
|
+
"formats/list": Z,
|
|
4140
|
+
"formats/bold": Qn,
|
|
4141
|
+
"formats/code": er,
|
|
4142
|
+
"formats/italic": cr,
|
|
4143
|
+
"formats/link": X,
|
|
4144
|
+
"formats/script": dr,
|
|
4145
|
+
"formats/strike": gr,
|
|
4146
|
+
"formats/underline": _r,
|
|
4147
|
+
"formats/hr": On,
|
|
4148
|
+
"formats/hr-dashed": kn,
|
|
4149
|
+
"formats/emoji": En,
|
|
4150
|
+
"formats/formula": Dn,
|
|
4151
|
+
"formats/image": Mn,
|
|
4152
|
+
"formats/video": zn,
|
|
4153
|
+
"modules/table": Ai,
|
|
4154
|
+
"modules/toolbar": ji,
|
|
4155
|
+
"modules/imageResize": Si,
|
|
4156
|
+
"themes/default": Jt
|
|
4157
|
+
}, !0);
|
|
4158
|
+
//#endregion
|
|
4159
|
+
//#region libs/rich-text/Toolbar.tsx
|
|
4160
|
+
function Ii(e, t) {
|
|
4161
|
+
let n = {}, { getPrefixCls: r, componentConfig: i, rtl: a } = u(ae), o = u(oe), s = u(se), c = le(e, i?.RichText, n), l = r?.("rich-text-toolbar"), { style: p, className: te, defaultValue: m, value: ne, readOnly: h = s?.readOnly ?? o?.readOnly, options: g, ..._ } = c;
|
|
4162
|
+
"defaultValue" in c, "value" in c;
|
|
4163
|
+
let [v, y] = ue({
|
|
4164
|
+
disabled: !0,
|
|
4165
|
+
isFullscreen: !1,
|
|
4166
|
+
formats: {}
|
|
4167
|
+
}), b = f(null);
|
|
4168
|
+
console.log("toolbarState", v);
|
|
4169
|
+
let { disabled: re, isFullscreen: x, formats: S } = v, C = { allowClear: !0 }, w = "mini";
|
|
4170
|
+
function T(e) {
|
|
4171
|
+
return e ? "primary" : "secondary";
|
|
4172
|
+
}
|
|
4173
|
+
function ie(e, t, n) {
|
|
4174
|
+
y({ disabled: !e?.length });
|
|
4175
|
+
}
|
|
4176
|
+
function ce(e) {
|
|
4177
|
+
y({ isFullscreen: e });
|
|
4178
|
+
}
|
|
4179
|
+
function de(e) {
|
|
4180
|
+
y({ formats: e });
|
|
4181
|
+
}
|
|
4182
|
+
function fe(e) {
|
|
4183
|
+
y({ history: e });
|
|
4184
|
+
}
|
|
4185
|
+
return d(() => () => {}, []), ee(t, () => ({
|
|
4186
|
+
setFormats: de,
|
|
4187
|
+
setSelection: ie,
|
|
4188
|
+
setIsFullscreen: ce,
|
|
4189
|
+
setHistory: fe,
|
|
4190
|
+
getRootElement() {
|
|
4191
|
+
return b.current;
|
|
4192
|
+
}
|
|
4193
|
+
})), /* @__PURE__ */ A("div", {
|
|
4194
|
+
ref: b,
|
|
4195
|
+
style: { ...p },
|
|
4196
|
+
className: pe(l, te),
|
|
4197
|
+
children: /* @__PURE__ */ j(Xe, {
|
|
4198
|
+
inline: !0,
|
|
4199
|
+
wrap: !0,
|
|
4200
|
+
children: [
|
|
4201
|
+
/* @__PURE__ */ j(k, { children: [
|
|
4202
|
+
/* @__PURE__ */ A(Qe, {
|
|
4203
|
+
style: { width: 120 },
|
|
4204
|
+
...C,
|
|
4205
|
+
size: w,
|
|
4206
|
+
value: S[rr],
|
|
4207
|
+
placeholder: "默认字体",
|
|
4208
|
+
options: [...tr],
|
|
4209
|
+
onChange: (e) => {
|
|
4210
|
+
c.onChange({
|
|
4211
|
+
format: rr,
|
|
4212
|
+
value: e
|
|
4213
|
+
});
|
|
4214
|
+
}
|
|
4215
|
+
}),
|
|
4216
|
+
/* @__PURE__ */ A(Qe, {
|
|
4217
|
+
style: { width: 120 },
|
|
4218
|
+
...C,
|
|
4219
|
+
size: w,
|
|
4220
|
+
value: S[pr],
|
|
4221
|
+
placeholder: "默认字号",
|
|
4222
|
+
options: [...fr],
|
|
4223
|
+
onChange: (e) => {
|
|
4224
|
+
c.onChange({
|
|
4225
|
+
format: pr,
|
|
4226
|
+
value: e
|
|
4227
|
+
});
|
|
4228
|
+
}
|
|
4229
|
+
}),
|
|
4230
|
+
/* @__PURE__ */ A(Qe, {
|
|
4231
|
+
style: { width: 120 },
|
|
4232
|
+
...C,
|
|
4233
|
+
size: w,
|
|
4234
|
+
value: S[ur.attrName],
|
|
4235
|
+
placeholder: "默认行高",
|
|
4236
|
+
options: [...lr],
|
|
4237
|
+
onChange: (e) => {
|
|
4238
|
+
c.onChange({
|
|
4239
|
+
format: ur.attrName,
|
|
4240
|
+
value: e
|
|
4241
|
+
});
|
|
4242
|
+
}
|
|
4243
|
+
}),
|
|
4244
|
+
/* @__PURE__ */ A(Qe, {
|
|
4245
|
+
style: { width: 120 },
|
|
4246
|
+
...C,
|
|
4247
|
+
size: w,
|
|
4248
|
+
value: S[sr.blotName],
|
|
4249
|
+
placeholder: "正文",
|
|
4250
|
+
options: [...or],
|
|
4251
|
+
onChange: (e) => {
|
|
4252
|
+
c.onChange({
|
|
4253
|
+
format: sr.blotName,
|
|
4254
|
+
value: e
|
|
4255
|
+
});
|
|
4256
|
+
}
|
|
4257
|
+
})
|
|
4258
|
+
] }),
|
|
4259
|
+
/* @__PURE__ */ j(k, { children: [
|
|
4260
|
+
/* @__PURE__ */ A(O, {
|
|
4261
|
+
size: w,
|
|
4262
|
+
type: T(S[Qn.blotName]),
|
|
4263
|
+
icon: /* @__PURE__ */ A(we, {}),
|
|
4264
|
+
onClick: (e) => {
|
|
4265
|
+
c.onChange({
|
|
4266
|
+
format: Qn.blotName,
|
|
4267
|
+
value: !S[Qn.blotName]
|
|
4268
|
+
});
|
|
4269
|
+
}
|
|
4270
|
+
}),
|
|
4271
|
+
/* @__PURE__ */ A(O, {
|
|
4272
|
+
size: w,
|
|
4273
|
+
type: T(S[cr.blotName]),
|
|
4274
|
+
icon: /* @__PURE__ */ A(Ne, {}),
|
|
4275
|
+
onClick: (e) => {
|
|
4276
|
+
c.onChange({
|
|
4277
|
+
format: cr.blotName,
|
|
4278
|
+
value: !S[cr.blotName]
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
}),
|
|
4282
|
+
/* @__PURE__ */ A(O, {
|
|
4283
|
+
size: w,
|
|
4284
|
+
type: T(S[_r.blotName]),
|
|
4285
|
+
icon: /* @__PURE__ */ A(Ge, {}),
|
|
4286
|
+
onClick: (e) => {
|
|
4287
|
+
c.onChange({
|
|
4288
|
+
format: _r.blotName,
|
|
4289
|
+
value: !S[_r.blotName]
|
|
4290
|
+
});
|
|
4291
|
+
}
|
|
4292
|
+
}),
|
|
4293
|
+
/* @__PURE__ */ A(O, {
|
|
4294
|
+
size: w,
|
|
4295
|
+
type: T(S[gr.blotName]),
|
|
4296
|
+
icon: /* @__PURE__ */ A(Ve, {}),
|
|
4297
|
+
onClick: (e) => {
|
|
4298
|
+
c.onChange({
|
|
4299
|
+
format: gr.blotName,
|
|
4300
|
+
value: !S[gr.blotName]
|
|
4301
|
+
});
|
|
4302
|
+
}
|
|
4303
|
+
})
|
|
4304
|
+
] }),
|
|
4305
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(Ye, {
|
|
4306
|
+
defaultValue: "#fff",
|
|
4307
|
+
value: S[Wn],
|
|
4308
|
+
triggerElement: ({ value: e }) => /* @__PURE__ */ A(O, {
|
|
4309
|
+
style: { color: S[Wn] },
|
|
4310
|
+
size: w,
|
|
4311
|
+
type: T(!1),
|
|
4312
|
+
icon: /* @__PURE__ */ A(ke, {})
|
|
4313
|
+
}),
|
|
4314
|
+
onChange: (e) => {
|
|
4315
|
+
c.onChange({
|
|
4316
|
+
format: Wn,
|
|
4317
|
+
value: e
|
|
4318
|
+
});
|
|
4319
|
+
}
|
|
4320
|
+
}), /* @__PURE__ */ A(Ye, {
|
|
4321
|
+
defaultValue: "#fff",
|
|
4322
|
+
value: S[Jn],
|
|
4323
|
+
triggerElement: ({ value: e }) => /* @__PURE__ */ A(O, {
|
|
4324
|
+
style: { backgroundColor: S[Jn] },
|
|
4325
|
+
size: w,
|
|
4326
|
+
type: T(!1),
|
|
4327
|
+
icon: /* @__PURE__ */ A(Ce, {})
|
|
4328
|
+
}),
|
|
4329
|
+
onChange: (e) => {
|
|
4330
|
+
c.onChange({
|
|
4331
|
+
format: Jn,
|
|
4332
|
+
value: e
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
})] }),
|
|
4336
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(O, {
|
|
4337
|
+
size: w,
|
|
4338
|
+
type: T(S[dr.blotName] === "sub"),
|
|
4339
|
+
icon: /* @__PURE__ */ j("div", { children: [/* @__PURE__ */ A("span", { children: "X" }), /* @__PURE__ */ A("sub", { children: "2" })] }),
|
|
4340
|
+
onClick: (e) => {
|
|
4341
|
+
c.onChange({
|
|
4342
|
+
format: dr.blotName,
|
|
4343
|
+
value: S[dr.blotName] === "sub" ? !1 : "sub"
|
|
4344
|
+
});
|
|
4345
|
+
}
|
|
4346
|
+
}), /* @__PURE__ */ A(O, {
|
|
4347
|
+
size: w,
|
|
4348
|
+
type: T(S[dr.blotName] === "super"),
|
|
4349
|
+
icon: /* @__PURE__ */ j("div", { children: [/* @__PURE__ */ A("span", { children: "X" }), /* @__PURE__ */ A("sup", { children: "2" })] }),
|
|
4350
|
+
onClick: (e) => {
|
|
4351
|
+
c.onChange({
|
|
4352
|
+
format: dr.blotName,
|
|
4353
|
+
value: S[dr.blotName] === "super" ? !1 : "super"
|
|
4354
|
+
});
|
|
4355
|
+
}
|
|
4356
|
+
})] }),
|
|
4357
|
+
/* @__PURE__ */ j(k, { children: [
|
|
4358
|
+
/* @__PURE__ */ A(O, {
|
|
4359
|
+
size: w,
|
|
4360
|
+
type: T(!S[Y]),
|
|
4361
|
+
icon: /* @__PURE__ */ A(xe, {}),
|
|
4362
|
+
onClick: (e) => {
|
|
4363
|
+
c.onChange({
|
|
4364
|
+
format: Y,
|
|
4365
|
+
value: !1
|
|
4366
|
+
});
|
|
4367
|
+
}
|
|
4368
|
+
}),
|
|
4369
|
+
/* @__PURE__ */ A(O, {
|
|
4370
|
+
size: w,
|
|
4371
|
+
type: T(S[Y] === "center"),
|
|
4372
|
+
icon: /* @__PURE__ */ A(be, {}),
|
|
4373
|
+
onClick: (e) => {
|
|
4374
|
+
c.onChange({
|
|
4375
|
+
format: Y,
|
|
4376
|
+
value: S.align === "center" ? !1 : "center"
|
|
4377
|
+
});
|
|
4378
|
+
}
|
|
4379
|
+
}),
|
|
4380
|
+
/* @__PURE__ */ A(O, {
|
|
4381
|
+
size: w,
|
|
4382
|
+
type: T(S[Y] === "right"),
|
|
4383
|
+
icon: /* @__PURE__ */ A(Se, {}),
|
|
4384
|
+
onClick: (e) => {
|
|
4385
|
+
c.onChange({
|
|
4386
|
+
format: Y,
|
|
4387
|
+
value: S.align === "right" ? !1 : "right"
|
|
4388
|
+
});
|
|
4389
|
+
}
|
|
4390
|
+
}),
|
|
4391
|
+
/* @__PURE__ */ A(O, {
|
|
4392
|
+
size: w,
|
|
4393
|
+
type: T(S[Y] === "justify"),
|
|
4394
|
+
icon: /* @__PURE__ */ A(D, {}),
|
|
4395
|
+
onClick: (e) => {
|
|
4396
|
+
c.onChange({
|
|
4397
|
+
format: Y,
|
|
4398
|
+
value: S.align === "justify" ? !1 : "justify"
|
|
4399
|
+
});
|
|
4400
|
+
}
|
|
4401
|
+
})
|
|
4402
|
+
] }),
|
|
4403
|
+
/* @__PURE__ */ j(k, { children: [
|
|
4404
|
+
/* @__PURE__ */ A(O, {
|
|
4405
|
+
size: w,
|
|
4406
|
+
type: T(S[Zn.blotName]),
|
|
4407
|
+
icon: /* @__PURE__ */ A(ze, {}),
|
|
4408
|
+
onClick: (e) => {
|
|
4409
|
+
c.onChange({
|
|
4410
|
+
format: Zn.blotName,
|
|
4411
|
+
value: !S[Zn.blotName]
|
|
4412
|
+
});
|
|
4413
|
+
}
|
|
4414
|
+
}),
|
|
4415
|
+
/* @__PURE__ */ A(O, {
|
|
4416
|
+
size: w,
|
|
4417
|
+
type: T(S[er.blotName]),
|
|
4418
|
+
icon: /* @__PURE__ */ A(Te, {}),
|
|
4419
|
+
onClick: (e) => {
|
|
4420
|
+
c.onChange({
|
|
4421
|
+
format: er.blotName,
|
|
4422
|
+
value: !S[er.blotName]
|
|
4423
|
+
});
|
|
4424
|
+
}
|
|
4425
|
+
}),
|
|
4426
|
+
/* @__PURE__ */ A(O, {
|
|
4427
|
+
size: w,
|
|
4428
|
+
type: T(S[Q.blotName]),
|
|
4429
|
+
icon: /* @__PURE__ */ A(Ee, {}),
|
|
4430
|
+
onClick: (e) => {
|
|
4431
|
+
c.onChange({
|
|
4432
|
+
format: Q.blotName,
|
|
4433
|
+
value: !S[Q.blotName]
|
|
4434
|
+
});
|
|
4435
|
+
}
|
|
4436
|
+
})
|
|
4437
|
+
] }),
|
|
4438
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(O, {
|
|
4439
|
+
size: w,
|
|
4440
|
+
type: T(S[Z.blotName] === "ordered"),
|
|
4441
|
+
icon: /* @__PURE__ */ A(Re, {}),
|
|
4442
|
+
onClick: (e) => {
|
|
4443
|
+
c.onChange({
|
|
4444
|
+
format: Z.blotName,
|
|
4445
|
+
value: S[Z.blotName] === "ordered" ? !1 : "ordered"
|
|
4446
|
+
});
|
|
4447
|
+
}
|
|
4448
|
+
}), /* @__PURE__ */ A(O, {
|
|
4449
|
+
size: w,
|
|
4450
|
+
type: T(S[Z.blotName] === "bullet"),
|
|
4451
|
+
icon: /* @__PURE__ */ A(qe, {}),
|
|
4452
|
+
onClick: (e) => {
|
|
4453
|
+
c.onChange({
|
|
4454
|
+
format: Z.blotName,
|
|
4455
|
+
value: S[Z.blotName] === "bullet" ? !1 : "bullet"
|
|
4456
|
+
});
|
|
4457
|
+
}
|
|
4458
|
+
})] }),
|
|
4459
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(O, {
|
|
4460
|
+
size: w,
|
|
4461
|
+
type: T(!1),
|
|
4462
|
+
icon: /* @__PURE__ */ A(Ie, {}),
|
|
4463
|
+
onClick: (e) => {
|
|
4464
|
+
c.onChange({
|
|
4465
|
+
format: Pn,
|
|
4466
|
+
value: "+1"
|
|
4467
|
+
});
|
|
4468
|
+
}
|
|
4469
|
+
}), /* @__PURE__ */ A(O, {
|
|
4470
|
+
size: w,
|
|
4471
|
+
type: T(!1),
|
|
4472
|
+
icon: /* @__PURE__ */ A(Fe, {}),
|
|
4473
|
+
onClick: (e) => {
|
|
4474
|
+
c.onChange({
|
|
4475
|
+
format: Pn,
|
|
4476
|
+
value: "-1"
|
|
4477
|
+
});
|
|
4478
|
+
}
|
|
4479
|
+
})] }),
|
|
4480
|
+
/* @__PURE__ */ A(k, { children: /* @__PURE__ */ A(O, {
|
|
4481
|
+
size: w,
|
|
4482
|
+
type: T(!1),
|
|
4483
|
+
icon: S.direction === "rtl" ? /* @__PURE__ */ A(Ue, {}) : /* @__PURE__ */ A(We, {}),
|
|
4484
|
+
onClick: (e) => {
|
|
4485
|
+
c.onChange({
|
|
4486
|
+
format: Sn,
|
|
4487
|
+
value: S.direction === "rtl" ? !1 : "rtl"
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
}) }),
|
|
4491
|
+
/* @__PURE__ */ j(k, { children: [
|
|
4492
|
+
/* @__PURE__ */ A(O, {
|
|
4493
|
+
size: w,
|
|
4494
|
+
type: T(S[X.blotName]),
|
|
4495
|
+
icon: /* @__PURE__ */ A(Pe, {}),
|
|
4496
|
+
onClick: (e) => {
|
|
4497
|
+
c.onChange({
|
|
4498
|
+
format: X.blotName,
|
|
4499
|
+
value: S[X.blotName]
|
|
4500
|
+
});
|
|
4501
|
+
}
|
|
4502
|
+
}),
|
|
4503
|
+
/* @__PURE__ */ A(O, {
|
|
4504
|
+
size: w,
|
|
4505
|
+
type: T(S[Mn.blotName]),
|
|
4506
|
+
icon: /* @__PURE__ */ A(Me, {}),
|
|
4507
|
+
onClick: (e) => {
|
|
4508
|
+
c.onChange({
|
|
4509
|
+
format: Mn.blotName,
|
|
4510
|
+
value: !0
|
|
4511
|
+
});
|
|
4512
|
+
}
|
|
4513
|
+
}),
|
|
4514
|
+
/* @__PURE__ */ A(O, {
|
|
4515
|
+
size: w,
|
|
4516
|
+
type: T(S[zn.blotName]),
|
|
4517
|
+
icon: /* @__PURE__ */ A(Je, {}),
|
|
4518
|
+
onClick: (e) => {
|
|
4519
|
+
c.onChange({
|
|
4520
|
+
format: zn.blotName,
|
|
4521
|
+
value: !0
|
|
4522
|
+
});
|
|
4523
|
+
}
|
|
4524
|
+
}),
|
|
4525
|
+
!1,
|
|
4526
|
+
!1,
|
|
4527
|
+
/* @__PURE__ */ A(O, {
|
|
4528
|
+
size: w,
|
|
4529
|
+
type: T(!1),
|
|
4530
|
+
icon: /* @__PURE__ */ A(Le, {}),
|
|
4531
|
+
onClick: (e) => {
|
|
4532
|
+
c.onChange({
|
|
4533
|
+
format: On.blotName,
|
|
4534
|
+
value: !0
|
|
4535
|
+
});
|
|
4536
|
+
}
|
|
4537
|
+
}),
|
|
4538
|
+
/* @__PURE__ */ A(O, {
|
|
4539
|
+
size: w,
|
|
4540
|
+
type: T(!1),
|
|
4541
|
+
icon: /* @__PURE__ */ A(He, {}),
|
|
4542
|
+
onClick: (e) => {
|
|
4543
|
+
c.onChange({
|
|
4544
|
+
format: kn.blotName,
|
|
4545
|
+
value: !0
|
|
4546
|
+
});
|
|
4547
|
+
}
|
|
4548
|
+
}),
|
|
4549
|
+
/* @__PURE__ */ A(Ze, {
|
|
4550
|
+
trigger: "click",
|
|
4551
|
+
triggerProps: { className: `${l}-emoji` },
|
|
4552
|
+
content: /* @__PURE__ */ A(Xe, {
|
|
4553
|
+
wrap: !0,
|
|
4554
|
+
inline: !0,
|
|
4555
|
+
justifyContent: "flex-start",
|
|
4556
|
+
alignItems: "flex-start",
|
|
4557
|
+
onClick: (e) => {
|
|
4558
|
+
let t = e.target, n = t.innerText;
|
|
4559
|
+
t.tagName === "SPAN" && $e(n) && c.onChange({
|
|
4560
|
+
format: En.blotName,
|
|
4561
|
+
value: n
|
|
4562
|
+
});
|
|
4563
|
+
},
|
|
4564
|
+
children: et.map((e, t, n) => /* @__PURE__ */ A("span", {
|
|
4565
|
+
className: `${l}-emoji-item`,
|
|
4566
|
+
children: e
|
|
4567
|
+
}, t))
|
|
4568
|
+
}),
|
|
4569
|
+
children: /* @__PURE__ */ A(O, {
|
|
4570
|
+
size: w,
|
|
4571
|
+
type: T(!1),
|
|
4572
|
+
icon: /* @__PURE__ */ A(Oe, {})
|
|
4573
|
+
})
|
|
4574
|
+
})
|
|
4575
|
+
] }),
|
|
4576
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(O, {
|
|
4577
|
+
size: w,
|
|
4578
|
+
type: T(!1),
|
|
4579
|
+
icon: /* @__PURE__ */ A(Ke, {}),
|
|
4580
|
+
disabled: !v.history?.stack?.undo?.length,
|
|
4581
|
+
onClick: (e) => {
|
|
4582
|
+
c.onChange({
|
|
4583
|
+
format: "undo",
|
|
4584
|
+
value: !0
|
|
4585
|
+
});
|
|
4586
|
+
}
|
|
4587
|
+
}), /* @__PURE__ */ A(O, {
|
|
4588
|
+
size: w,
|
|
4589
|
+
type: T(!1),
|
|
4590
|
+
icon: /* @__PURE__ */ A(Be, {}),
|
|
4591
|
+
disabled: !v.history?.stack?.redo?.length,
|
|
4592
|
+
onClick: (e) => {
|
|
4593
|
+
c.onChange({
|
|
4594
|
+
format: "redo",
|
|
4595
|
+
value: !0
|
|
4596
|
+
});
|
|
4597
|
+
}
|
|
4598
|
+
})] }),
|
|
4599
|
+
/* @__PURE__ */ j(k, { children: [/* @__PURE__ */ A(O, {
|
|
4600
|
+
size: w,
|
|
4601
|
+
type: T(!1),
|
|
4602
|
+
icon: /* @__PURE__ */ A(De, {}),
|
|
4603
|
+
onClick: (e) => {
|
|
4604
|
+
c.onChange({
|
|
4605
|
+
format: "clean",
|
|
4606
|
+
value: !0
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
}), /* @__PURE__ */ A(O, {
|
|
4610
|
+
size: w,
|
|
4611
|
+
type: T(x),
|
|
4612
|
+
icon: A(x ? je : Ae, {}),
|
|
4613
|
+
onClick: (e) => {
|
|
4614
|
+
c.onChange({
|
|
4615
|
+
format: "fullscreen",
|
|
4616
|
+
value: !0
|
|
4617
|
+
});
|
|
4618
|
+
}
|
|
4619
|
+
})] })
|
|
4620
|
+
]
|
|
4621
|
+
})
|
|
4622
|
+
});
|
|
4623
|
+
}
|
|
4624
|
+
var Li = l(Ii);
|
|
4625
|
+
Object.assign(Li, {}), q.import("delta"), q.import("attributors/style/size"), q.import("formats/font");
|
|
4626
|
+
function Ri(e, t) {
|
|
4627
|
+
let { getPrefixCls: n, componentConfig: r, rtl: i } = u(ae), a = u(it), o = u(oe), c = u(se), l = le(e, {
|
|
4628
|
+
...r?.RichText,
|
|
4629
|
+
...a
|
|
4630
|
+
}, rt), p = n?.("rich-text"), { style: te, className: m, defaultValue: ne, value: h, readOnly: g = c?.readOnly ?? o?.readOnly, options: v, bordered: y, placeholder: b = "请输入富文本内容", ...x } = l, S = g ? ge : b;
|
|
4631
|
+
"defaultValue" in l, "value" in l, "readOnly" in l;
|
|
4632
|
+
let C = h || ne, [w, T] = ue({ modal: {} }), ve = f(null), E = f(void 0), ye = f(null), be = f(void 0);
|
|
4633
|
+
function D() {
|
|
4634
|
+
return be.current;
|
|
4635
|
+
}
|
|
4636
|
+
let [xe, { enterFullscreen: Se, exitFullscreen: Ce, toggleFullscreen: we }] = ce(g ? null : ve, {
|
|
4637
|
+
onExit() {
|
|
4638
|
+
_(E.current?.setIsFullscreen), E.current.setIsFullscreen(!1);
|
|
4639
|
+
},
|
|
4640
|
+
onEnter() {
|
|
4641
|
+
E.current.setIsFullscreen(!0);
|
|
4642
|
+
}
|
|
4643
|
+
});
|
|
4644
|
+
function Te(e, t) {
|
|
4645
|
+
let n = D();
|
|
4646
|
+
if (!n) return;
|
|
4647
|
+
let r = n.getSelection();
|
|
4648
|
+
n.setContents(e ?? C, t), r && n.setSelection(r);
|
|
4649
|
+
}
|
|
4650
|
+
function Ee(...e) {
|
|
4651
|
+
let t = D();
|
|
4652
|
+
if (!t) return;
|
|
4653
|
+
let [n] = t.selection.getRange(), r = n == null ? {} : t.getFormat(n);
|
|
4654
|
+
E.current.setFormats({ ...r });
|
|
4655
|
+
}
|
|
4656
|
+
d(() => {
|
|
4657
|
+
ve.current;
|
|
4658
|
+
let e = { readOnly: !!g };
|
|
4659
|
+
g || (e = {
|
|
4660
|
+
...e,
|
|
4661
|
+
theme: "default",
|
|
4662
|
+
modules: {
|
|
4663
|
+
toolbar: {
|
|
4664
|
+
custom: !0,
|
|
4665
|
+
container: [],
|
|
4666
|
+
handlers: {
|
|
4667
|
+
[Sn](e) {
|
|
4668
|
+
let t = D();
|
|
4669
|
+
if (!t) return;
|
|
4670
|
+
let { align: n } = t.getFormat();
|
|
4671
|
+
e === "rtl" && n == null ? t.format(Y, "right", q.sources.USER) : !e && n === "right" && t.format(Y, !1, q.sources.USER), t.format(Sn, e, q.sources.USER);
|
|
4672
|
+
},
|
|
4673
|
+
[Pn](e) {
|
|
4674
|
+
let t = D();
|
|
4675
|
+
if (!t) return;
|
|
4676
|
+
let n = t.getSelection(), r = t.getFormat(n), i = parseInt(r.indent || "0", 10);
|
|
4677
|
+
if (e === "+1" || e === "-1") {
|
|
4678
|
+
let n = e === "+1" ? 1 : -1;
|
|
4679
|
+
r.direction === "rtl" && (n *= -1), t.format(Pn, i + n, q.sources.USER);
|
|
4680
|
+
}
|
|
4681
|
+
},
|
|
4682
|
+
[Z.blotName](e) {
|
|
4683
|
+
let t = D();
|
|
4684
|
+
if (!t) return;
|
|
4685
|
+
let n = t.getSelection(), r = t.getFormat(n);
|
|
4686
|
+
e === "check" ? r.list === "checked" || r.list === "unchecked" ? t.format(Z.blotName, !1, q.sources.USER) : t.format(Z.blotName, "unchecked", q.sources.USER) : t.format(Z.blotName, e, q.sources.USER), t.format(Z.blotName, e, q.sources.USER);
|
|
4687
|
+
},
|
|
4688
|
+
[Dn.blotName]() {
|
|
4689
|
+
D();
|
|
4690
|
+
},
|
|
4691
|
+
[Mn.blotName]() {
|
|
4692
|
+
D() && T({ modal: {
|
|
4693
|
+
visible: !0,
|
|
4694
|
+
type: Mn.blotName
|
|
4695
|
+
} });
|
|
4696
|
+
},
|
|
4697
|
+
[zn.blotName]() {
|
|
4698
|
+
T({ modal: {
|
|
4699
|
+
visible: !0,
|
|
4700
|
+
type: zn.blotName
|
|
4701
|
+
} });
|
|
4702
|
+
},
|
|
4703
|
+
[X.blotName](e) {
|
|
4704
|
+
let t = D();
|
|
4705
|
+
t && t.getSelection(!0)?.length && T({ modal: {
|
|
4706
|
+
visible: !0,
|
|
4707
|
+
type: X.blotName,
|
|
4708
|
+
value: e
|
|
4709
|
+
} });
|
|
4710
|
+
},
|
|
4711
|
+
[On.blotName](e, t) {
|
|
4712
|
+
let n = D();
|
|
4713
|
+
if (!n) return;
|
|
4714
|
+
let r = n.getSelection(!0);
|
|
4715
|
+
r && n.insertEmbed(r.index, On.blotName, e, q.sources.USER);
|
|
4716
|
+
},
|
|
4717
|
+
[kn.blotName](e, t) {
|
|
4718
|
+
let n = D();
|
|
4719
|
+
if (!n) return;
|
|
4720
|
+
let r = n.getSelection(!0);
|
|
4721
|
+
r && n.insertEmbed(r.index, kn.blotName, {}, q.sources.USER);
|
|
4722
|
+
},
|
|
4723
|
+
[En.blotName](e, t) {
|
|
4724
|
+
let n = D();
|
|
4725
|
+
if (!n) return;
|
|
4726
|
+
let r = n.getSelection(!0);
|
|
4727
|
+
r && (n.insertEmbed(r.index, En.blotName, e, q.sources.USER), n.setSelection(r.index + e.length));
|
|
4728
|
+
},
|
|
4729
|
+
redo() {
|
|
4730
|
+
let e = D();
|
|
4731
|
+
e && e.history.redo();
|
|
4732
|
+
},
|
|
4733
|
+
undo() {
|
|
4734
|
+
let e = D();
|
|
4735
|
+
e && e.history.undo();
|
|
4736
|
+
},
|
|
4737
|
+
clean() {
|
|
4738
|
+
let e = D();
|
|
4739
|
+
if (!e) return;
|
|
4740
|
+
let t = e.getSelection();
|
|
4741
|
+
if (t != null) if (t.length === 0) {
|
|
4742
|
+
let t = e.getFormat();
|
|
4743
|
+
Object.keys(t).forEach((t) => {
|
|
4744
|
+
re(e.scroll.query(t, I.INLINE)) && e.format(t, !1, q.sources.USER);
|
|
4745
|
+
});
|
|
4746
|
+
} else e.removeFormat(t.index, t.length, q.sources.USER);
|
|
4747
|
+
},
|
|
4748
|
+
fullscreen(e) {
|
|
4749
|
+
we();
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
},
|
|
4753
|
+
history: !0,
|
|
4754
|
+
table: !0,
|
|
4755
|
+
imageResize: !0
|
|
4756
|
+
},
|
|
4757
|
+
placeholder: S
|
|
4758
|
+
}), be.current = new q({
|
|
4759
|
+
root: ve.current,
|
|
4760
|
+
toolbar: E.current,
|
|
4761
|
+
container: ye.current
|
|
4762
|
+
}, _e(v, e)), console.log("new Rich", D());
|
|
4763
|
+
function t(e, t, n) {
|
|
4764
|
+
let r = D();
|
|
4765
|
+
if (r && n === q.sources.USER) {
|
|
4766
|
+
let i = r.isBlank() ? void 0 : r.getContents(), a = l.onChangeCallback;
|
|
4767
|
+
_(a) && (i = a(i) ?? i), l.onChange?.(i, e, t, n), l.onTextChange?.(e, t, n), E.current.setHistory(r.history);
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
function n(...e) {
|
|
4771
|
+
E.current.setSelection(...e), l.onSelectionChange?.(...e);
|
|
4772
|
+
}
|
|
4773
|
+
function r(...e) {
|
|
4774
|
+
Ee(...e), l.onEditorChange?.(...e);
|
|
4775
|
+
}
|
|
4776
|
+
let i = D();
|
|
4777
|
+
return g || (i.on(q.events.TEXT_CHANGE, t), i.on(q.events.SELECTION_CHANGE, n), i.on(q.events.EDITOR_CHANGE, r)), i.enable(!g), () => {
|
|
4778
|
+
i.off(q.events.TEXT_CHANGE, t), i.off(q.events.SELECTION_CHANGE, n), i.off(q.events.EDITOR_CHANGE, r), i.destroy();
|
|
4779
|
+
};
|
|
4780
|
+
}, [g]), d(() => (Te(C, N.sources.API), () => {}), [C]), ee(t, () => ({
|
|
4781
|
+
get rich() {
|
|
4782
|
+
return D();
|
|
4783
|
+
},
|
|
4784
|
+
get contents() {
|
|
4785
|
+
return D().getContents();
|
|
4786
|
+
},
|
|
4787
|
+
setContents: Te,
|
|
4788
|
+
Rich: q,
|
|
4789
|
+
getContainerElement() {
|
|
4790
|
+
return ye.current;
|
|
4791
|
+
},
|
|
4792
|
+
getRootElement() {
|
|
4793
|
+
return ve.current;
|
|
4794
|
+
}
|
|
4795
|
+
}));
|
|
4796
|
+
function De(e) {
|
|
4797
|
+
return /* @__PURE__ */ A(k, { children: /* @__PURE__ */ j("div", {
|
|
4798
|
+
ref: ve,
|
|
4799
|
+
style: te,
|
|
4800
|
+
className: pe(p, m, { [`${p}-rtl`]: i }, g && `${p}-readonly`, y && `${p}-bordered`, w.focus && `${p}-focus`, w.blur && `${p}-blur`),
|
|
4801
|
+
children: [e, /* @__PURE__ */ A("div", {
|
|
4802
|
+
ref: ye,
|
|
4803
|
+
className: pe(`${p}-container`),
|
|
4804
|
+
onFocus: (e) => {
|
|
4805
|
+
T({
|
|
4806
|
+
focus: !0,
|
|
4807
|
+
blur: !1
|
|
4808
|
+
});
|
|
4809
|
+
},
|
|
4810
|
+
onBlur: (e) => {
|
|
4811
|
+
T({
|
|
4812
|
+
focus: !1,
|
|
4813
|
+
blur: !0
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
})]
|
|
4817
|
+
}) });
|
|
4818
|
+
}
|
|
4819
|
+
let Oe;
|
|
4820
|
+
if (g) Oe = De();
|
|
4821
|
+
else {
|
|
4822
|
+
let e = xe ? () => ve.current : me, t = { getPopupContainer: e };
|
|
4823
|
+
Oe = De(/* @__PURE__ */ j(ie, {
|
|
4824
|
+
componentConfig: he({}, r, {
|
|
4825
|
+
ColorPicker: {
|
|
4826
|
+
triggerProps: {
|
|
4827
|
+
className: `${F}-trigger-color-picker`,
|
|
4828
|
+
...t
|
|
4829
|
+
},
|
|
4830
|
+
...t
|
|
4831
|
+
},
|
|
4832
|
+
Modal: {
|
|
4833
|
+
...t,
|
|
4834
|
+
getChildrenPopupContainer: e
|
|
4835
|
+
},
|
|
4836
|
+
Select: {
|
|
4837
|
+
triggerProps: {
|
|
4838
|
+
className: `${F}-trigger-select`,
|
|
4839
|
+
...t
|
|
4840
|
+
},
|
|
4841
|
+
...t
|
|
4842
|
+
},
|
|
4843
|
+
Tooltip: {
|
|
4844
|
+
triggerProps: { ...t },
|
|
4845
|
+
...t
|
|
4846
|
+
},
|
|
4847
|
+
Trigger: {
|
|
4848
|
+
className: `${F}-trigger`,
|
|
4849
|
+
...t
|
|
4850
|
+
}
|
|
4851
|
+
}),
|
|
4852
|
+
children: [/* @__PURE__ */ A(Li, {
|
|
4853
|
+
ref: E,
|
|
4854
|
+
onChange: (e) => {
|
|
4855
|
+
let t = D();
|
|
4856
|
+
if (!t) return;
|
|
4857
|
+
let { format: n, value: r } = e ?? {};
|
|
4858
|
+
t.focus();
|
|
4859
|
+
let i = t.options.modules.toolbar.handlers[n];
|
|
4860
|
+
if (_(i)) i.call(t.theme.modules.toolbar, r);
|
|
4861
|
+
else if (t.scroll.query(n).prototype instanceof V) {
|
|
4862
|
+
let e = prompt(`Enter ${n}`);
|
|
4863
|
+
if (!e) return;
|
|
4864
|
+
let [r] = t.selection.getRange();
|
|
4865
|
+
t.updateContents(new s().retain(r.index).delete(r.length).insert({ [n]: e }), q.sources.USER);
|
|
4866
|
+
} else t.format(n, r, q.sources.USER);
|
|
4867
|
+
}
|
|
4868
|
+
}), /* @__PURE__ */ A(fe, {
|
|
4869
|
+
title: "输入地址",
|
|
4870
|
+
visible: w.modal.visible,
|
|
4871
|
+
unmountOnExit: !0,
|
|
4872
|
+
onCancel: () => {
|
|
4873
|
+
T({ modal: { visible: !1 } });
|
|
4874
|
+
},
|
|
4875
|
+
onOk: () => {
|
|
4876
|
+
T({ modal: {
|
|
4877
|
+
...w.modal,
|
|
4878
|
+
visible: !1
|
|
4879
|
+
} });
|
|
4880
|
+
},
|
|
4881
|
+
afterClose: () => {
|
|
4882
|
+
let e = D();
|
|
4883
|
+
if (!e) return;
|
|
4884
|
+
let t = e.getSelection(!0);
|
|
4885
|
+
if (t && w.modal.url) {
|
|
4886
|
+
if (w.modal.type === Mn.blotName) e.insertEmbed(t.index, Mn.blotName, w.modal.url, q.sources.USER), e.setSelection(t.index + 1);
|
|
4887
|
+
else if (w.modal.type === zn.blotName) e.format(zn.blotName, w.modal.url, q.sources.USER);
|
|
4888
|
+
else if (w.modal.type === X.blotName) {
|
|
4889
|
+
if (t == null || t.length === 0) return;
|
|
4890
|
+
e.format(X.blotName, w.modal.url, q.sources.USER);
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
},
|
|
4894
|
+
children: /* @__PURE__ */ A(de, {
|
|
4895
|
+
defaultValue: w.modal.value,
|
|
4896
|
+
addBefore: "URL",
|
|
4897
|
+
onChange: (e) => {
|
|
4898
|
+
T({ modal: {
|
|
4899
|
+
...w.modal,
|
|
4900
|
+
url: e
|
|
4901
|
+
} });
|
|
4902
|
+
}
|
|
4903
|
+
}, w.modal.visible)
|
|
4904
|
+
})]
|
|
4905
|
+
}));
|
|
4906
|
+
}
|
|
4907
|
+
return Oe;
|
|
4908
|
+
}
|
|
4909
|
+
var zi = l(Ri);
|
|
4910
|
+
Object.assign(zi, { ...e });
|
|
4911
|
+
//#endregion
|
|
4912
|
+
//#region libs/rich-text/index.ts
|
|
4913
|
+
var Bi = Object.assign(zi, q, {
|
|
4914
|
+
...e,
|
|
4915
|
+
PropsContext: it,
|
|
4916
|
+
AttributeMap: n,
|
|
4917
|
+
Delta: t,
|
|
4918
|
+
Emitter: N,
|
|
4919
|
+
Module: P,
|
|
4920
|
+
Op: i,
|
|
4921
|
+
OpIterator: o,
|
|
4922
|
+
Parchment: Tt,
|
|
4923
|
+
Range: It,
|
|
4924
|
+
Rich: q
|
|
4925
|
+
});
|
|
4926
|
+
//#endregion
|
|
4927
|
+
export { q as Rich, n as RichTextAttributeMap, t as RichTextDelta, N as RichTextEmitter, P as RichTextModule, i as RichTextOp, o as RichTextOpIterator, Tt as RichTextParchment, It as RichTextRange, Bi as default };
|
|
4928
|
+
/* 独立思考,明辨是非 */
|