@vector-im/matrix-wysiwyg 2.38.5 → 2.40.0
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/dist/index.d.ts +3 -2
- package/dist/matrix-wysiwyg.js +484 -485
- package/dist/matrix-wysiwyg.umd.cjs +11 -11
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/package.json +2 -2
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg.d.ts +7 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.cjs +50 -9
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.js +40 -7
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm +0 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm.d.ts +3 -2
- package/package.json +13 -13
package/dist/matrix-wysiwyg.js
CHANGED
|
@@ -1,49 +1,60 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { initAsync as
|
|
3
|
-
function
|
|
1
|
+
import { useState as E, useRef as b, useEffect as h, useMemo as C, useCallback as A } from "react";
|
|
2
|
+
import { HtmlSource as H, initAsync as ae, new_composer_model_from_html as G, new_composer_model as w } from "@vector-im/matrix-wysiwyg-wasm";
|
|
3
|
+
function y(e) {
|
|
4
4
|
return "inputType" in e;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function V(e) {
|
|
7
7
|
return "clipboardData" in e;
|
|
8
8
|
}
|
|
9
|
-
function ae(e) {
|
|
10
|
-
return E(e) && e.inputType === "insertSuggestion";
|
|
11
|
-
}
|
|
12
9
|
function ce(e) {
|
|
13
|
-
return
|
|
10
|
+
return y(e) && e.inputType === "insertSuggestion";
|
|
14
11
|
}
|
|
15
12
|
function ue(e) {
|
|
16
|
-
return
|
|
13
|
+
return y(e) && e.inputType === "insertAtRoomSuggestion";
|
|
14
|
+
}
|
|
15
|
+
function le(e) {
|
|
16
|
+
return y(e) && e.inputType == "insertLink";
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function X(e, t, n, s) {
|
|
19
|
+
return s ? s(e, t, n) : e;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
const o = z(
|
|
21
|
+
function fe(e, t, n, s, r, i, c, l) {
|
|
22
|
+
const a = X(
|
|
24
23
|
e,
|
|
25
24
|
{
|
|
26
|
-
actions:
|
|
25
|
+
actions: s,
|
|
27
26
|
content: () => t.get_content_as_html(),
|
|
28
27
|
messageContent: () => t.get_content_as_message_html()
|
|
29
28
|
},
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
r,
|
|
30
|
+
c
|
|
32
31
|
);
|
|
33
|
-
if (!
|
|
32
|
+
if (!a)
|
|
34
33
|
return;
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
37
|
-
|
|
34
|
+
if (V(a)) {
|
|
35
|
+
const o = a.clipboardData, f = o?.getData("text/html"), m = o?.getData("text/plain") ?? "";
|
|
36
|
+
if (f && f !== m) {
|
|
37
|
+
const d = o?.types.includes(
|
|
38
|
+
"application/x-vnd.google-docs-document-slice-clip+wrapped"
|
|
39
|
+
) ? H.GoogleDoc : H.UnknownExternal;
|
|
40
|
+
return n(
|
|
41
|
+
t.replace_html(f, d),
|
|
42
|
+
"replace_html_paste"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return n(
|
|
46
|
+
t.replace_text(m),
|
|
47
|
+
"replace_text_paste"
|
|
48
|
+
);
|
|
38
49
|
}
|
|
39
|
-
switch (
|
|
50
|
+
switch (a.inputType) {
|
|
40
51
|
case "insertAtRoomSuggestion": {
|
|
41
|
-
if (i &&
|
|
42
|
-
const { attributes:
|
|
43
|
-
return
|
|
52
|
+
if (i && ue(a)) {
|
|
53
|
+
const { attributes: o } = a.data;
|
|
54
|
+
return o.has("data-mention-type") && o.delete("data-mention-type"), n(
|
|
44
55
|
t.insert_at_room_mention_at_suggestion(
|
|
45
56
|
i,
|
|
46
|
-
|
|
57
|
+
o
|
|
47
58
|
),
|
|
48
59
|
"insert_at_room_mention_at_suggestion"
|
|
49
60
|
);
|
|
@@ -51,30 +62,33 @@ function le(e, t, n, r, s, i, l, m) {
|
|
|
51
62
|
break;
|
|
52
63
|
}
|
|
53
64
|
case "insertSuggestion": {
|
|
54
|
-
if (i &&
|
|
55
|
-
const { text:
|
|
56
|
-
return
|
|
65
|
+
if (i && ce(a)) {
|
|
66
|
+
const { text: o, url: f, attributes: m } = a.data;
|
|
67
|
+
return m.has("data-mention-type") && m.delete("data-mention-type"), n(
|
|
57
68
|
t.insert_mention_at_suggestion(
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
f,
|
|
70
|
+
o,
|
|
60
71
|
i,
|
|
61
|
-
|
|
72
|
+
m
|
|
62
73
|
),
|
|
63
74
|
"insert_mention_at_suggestion"
|
|
64
75
|
);
|
|
65
76
|
}
|
|
66
77
|
break;
|
|
67
78
|
}
|
|
68
|
-
case "insertCommand":
|
|
69
|
-
|
|
79
|
+
case "insertCommand":
|
|
80
|
+
case "insertEmoji": {
|
|
81
|
+
if (i && a.data) {
|
|
82
|
+
const o = a.inputType === "insertCommand";
|
|
70
83
|
return n(
|
|
71
84
|
t.replace_text_suggestion(
|
|
72
|
-
|
|
85
|
+
a.data,
|
|
73
86
|
i,
|
|
74
|
-
|
|
87
|
+
o
|
|
75
88
|
),
|
|
76
89
|
"replace_text_suggestion"
|
|
77
90
|
);
|
|
91
|
+
}
|
|
78
92
|
break;
|
|
79
93
|
}
|
|
80
94
|
case "clear":
|
|
@@ -84,8 +98,8 @@ function le(e, t, n, r, s, i, l, m) {
|
|
|
84
98
|
case "deleteWordBackward":
|
|
85
99
|
return n(t.backspace_word(), "backspace_word");
|
|
86
100
|
case "deleteSoftLineBackward": {
|
|
87
|
-
const
|
|
88
|
-
return
|
|
101
|
+
const o = document.getSelection();
|
|
102
|
+
return o && (o.modify("extend", "backward", "lineboundary"), document.dispatchEvent(new CustomEvent("selectionchange"))), n(t.delete(), "backspace_line");
|
|
89
103
|
}
|
|
90
104
|
case "deleteContentForward":
|
|
91
105
|
return n(t.delete(), "delete");
|
|
@@ -117,43 +131,43 @@ function le(e, t, n, r, s, i, l, m) {
|
|
|
117
131
|
return n(t.ordered_list(), "ordered_list");
|
|
118
132
|
case "insertLineBreak":
|
|
119
133
|
case "insertParagraph":
|
|
120
|
-
return
|
|
134
|
+
return u(
|
|
121
135
|
t,
|
|
122
136
|
i,
|
|
123
|
-
|
|
137
|
+
l
|
|
124
138
|
), n(t.enter(), "enter");
|
|
125
139
|
case "insertReplacementText": {
|
|
126
|
-
const
|
|
140
|
+
const o = r.innerHTML.slice(
|
|
127
141
|
0,
|
|
128
|
-
|
|
142
|
+
r.innerHTML.length - 4
|
|
129
143
|
);
|
|
130
144
|
return n(
|
|
131
|
-
t.set_content_from_html(
|
|
145
|
+
t.set_content_from_html(o),
|
|
132
146
|
"set_content_from_html",
|
|
133
|
-
|
|
147
|
+
o
|
|
134
148
|
);
|
|
135
149
|
}
|
|
136
150
|
case "insertCompositionText":
|
|
137
151
|
case "insertFromComposition":
|
|
138
152
|
case "insertText":
|
|
139
|
-
if (
|
|
140
|
-
return
|
|
153
|
+
if (a.data)
|
|
154
|
+
return a.data == " " && u(
|
|
141
155
|
t,
|
|
142
156
|
i,
|
|
143
|
-
|
|
157
|
+
l
|
|
144
158
|
), n(
|
|
145
|
-
t.replace_text(
|
|
159
|
+
t.replace_text(a.data),
|
|
146
160
|
"replace_text",
|
|
147
|
-
|
|
161
|
+
a.data
|
|
148
162
|
);
|
|
149
163
|
break;
|
|
150
164
|
case "insertUnorderedList":
|
|
151
165
|
return n(t.unordered_list(), "unordered_list");
|
|
152
166
|
case "insertLink":
|
|
153
|
-
if (
|
|
154
|
-
const { text:
|
|
167
|
+
if (le(a)) {
|
|
168
|
+
const { text: o, url: f } = a.data;
|
|
155
169
|
return n(
|
|
156
|
-
|
|
170
|
+
o ? t.set_link_with_text(f, o, /* @__PURE__ */ new Map()) : t.set_link(f, /* @__PURE__ */ new Map()),
|
|
157
171
|
"insertLink"
|
|
158
172
|
);
|
|
159
173
|
}
|
|
@@ -167,216 +181,212 @@ function le(e, t, n, r, s, i, l, m) {
|
|
|
167
181
|
case "sendMessage":
|
|
168
182
|
return null;
|
|
169
183
|
default:
|
|
170
|
-
return console.error(`Unknown input type: ${
|
|
184
|
+
return console.error(`Unknown input type: ${a.inputType}`), console.error(e), null;
|
|
171
185
|
}
|
|
172
|
-
function
|
|
173
|
-
if (
|
|
174
|
-
const
|
|
175
|
-
|
|
186
|
+
function u(o, f, m) {
|
|
187
|
+
if (m && f && f.key.key_type == 3 && f.key.custom_key_value) {
|
|
188
|
+
const d = m.get(f.key.custom_key_value);
|
|
189
|
+
d && o.replace_text_suggestion(d, f, !1);
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
|
-
function
|
|
193
|
+
function de(e, t) {
|
|
180
194
|
e.innerHTML = "";
|
|
181
195
|
const n = t.document();
|
|
182
|
-
let
|
|
183
|
-
function
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
for (const [
|
|
187
|
-
const
|
|
188
|
-
|
|
196
|
+
let s = 0;
|
|
197
|
+
function r(c, l, a, u) {
|
|
198
|
+
const o = document.createElement(l);
|
|
199
|
+
if (a && (o.innerText = a.replace("", "~")), u)
|
|
200
|
+
for (const [f, m] of u.entries()) {
|
|
201
|
+
const d = document.createAttribute(f);
|
|
202
|
+
m !== null && (d.value = m), o.setAttributeNode(d);
|
|
189
203
|
}
|
|
190
|
-
return
|
|
204
|
+
return c.appendChild(o), o;
|
|
191
205
|
}
|
|
192
|
-
function i(
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
let
|
|
197
|
-
for (;
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
function i(c, l) {
|
|
207
|
+
const a = r(l, "ul");
|
|
208
|
+
a.className = `group_${s % 10}`;
|
|
209
|
+
const u = c.children(t);
|
|
210
|
+
let o;
|
|
211
|
+
for (; o = u.next_child(); ) {
|
|
212
|
+
const f = o.node_type(t);
|
|
213
|
+
if (f === "container") {
|
|
214
|
+
const d = `dom_${s}`;
|
|
215
|
+
s++;
|
|
216
|
+
const g = r(a, "li");
|
|
217
|
+
r(
|
|
218
|
+
g,
|
|
205
219
|
"input",
|
|
206
220
|
null,
|
|
207
221
|
/* @__PURE__ */ new Map([
|
|
208
222
|
["type", "checkbox"],
|
|
209
|
-
["id",
|
|
223
|
+
["id", d],
|
|
210
224
|
["checked", null]
|
|
211
225
|
])
|
|
212
|
-
),
|
|
213
|
-
|
|
226
|
+
), r(
|
|
227
|
+
g,
|
|
214
228
|
"label",
|
|
215
|
-
|
|
216
|
-
/* @__PURE__ */ new Map([["for",
|
|
217
|
-
), i(
|
|
218
|
-
} else if (
|
|
219
|
-
|
|
220
|
-
else if (
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
} else if (
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
o.tag(t),
|
|
230
|
+
/* @__PURE__ */ new Map([["for", d]])
|
|
231
|
+
), i(o, g);
|
|
232
|
+
} else if (f === "line_break")
|
|
233
|
+
r(a, "li", "br");
|
|
234
|
+
else if (f === "text") {
|
|
235
|
+
const m = r(a, "li");
|
|
236
|
+
r(m, "span", '"', /* @__PURE__ */ new Map([["class", "quote"]])), r(m, "span", `${o.text(t)}`), r(m, "span", '"', /* @__PURE__ */ new Map([["class", "quote"]]));
|
|
237
|
+
} else if (f === "mention") {
|
|
238
|
+
const m = r(a, "li");
|
|
239
|
+
r(
|
|
240
|
+
m,
|
|
227
241
|
"span",
|
|
228
242
|
'"Mention - ',
|
|
229
243
|
/* @__PURE__ */ new Map([["class", "quote"]])
|
|
230
|
-
),
|
|
244
|
+
), r(m, "span", `${o.text(t)}`), r(m, "span", '"', /* @__PURE__ */ new Map([["class", "quote"]]));
|
|
231
245
|
} else
|
|
232
|
-
console.error(`Unknown node type: ${
|
|
246
|
+
console.error(`Unknown node type: ${f}`);
|
|
233
247
|
}
|
|
234
248
|
}
|
|
235
249
|
i(n, e);
|
|
236
250
|
}
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
let
|
|
240
|
-
if (
|
|
241
|
-
const
|
|
242
|
-
if ((
|
|
251
|
+
function me(e, t, n) {
|
|
252
|
+
const s = document.createRange();
|
|
253
|
+
let r = I(e, t), i = I(e, n);
|
|
254
|
+
if (r.node && i.node) {
|
|
255
|
+
const l = r.node.compareDocumentPosition(i.node) & Node.DOCUMENT_POSITION_PRECEDING, a = r.node === i.node && i.offset < r.offset;
|
|
256
|
+
if ((l || a) && ([r, i] = [i, r], !r.node || !i.node))
|
|
243
257
|
throw new Error();
|
|
244
|
-
|
|
258
|
+
s.setStart(r.node, r.offset), s.setEnd(i.node, i.offset);
|
|
245
259
|
} else
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
function
|
|
251
|
-
e.innerHTML = t + "<br />",
|
|
252
|
-
}
|
|
253
|
-
function
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return h <= 1 ? h === 0 ? e.previousSibling ? {
|
|
260
|
+
s.selectNodeContents(e), s.collapse();
|
|
261
|
+
const c = document.getSelection();
|
|
262
|
+
c && (c.removeAllRanges(), c.addRange(s));
|
|
263
|
+
}
|
|
264
|
+
function z(e, t, n, s) {
|
|
265
|
+
e.innerHTML = t + "<br />", me(e, n, s);
|
|
266
|
+
}
|
|
267
|
+
function I(e, t, n) {
|
|
268
|
+
const s = e.nodeName === "LI" && !e.hasChildNodes(), r = e.nodeType === Node.TEXT_NODE;
|
|
269
|
+
if (r && e.parentElement?.hasAttribute("data-mention-type")) {
|
|
270
|
+
const l = L(e) ? 1 : 0, a = t - l;
|
|
271
|
+
return a <= 1 ? a === 0 ? e.previousSibling ? {
|
|
259
272
|
node: e.previousSibling,
|
|
260
|
-
offset:
|
|
273
|
+
offset: T(
|
|
261
274
|
e.previousSibling,
|
|
262
275
|
1 / 0
|
|
263
276
|
)
|
|
264
277
|
} : {
|
|
265
|
-
node:
|
|
278
|
+
node: e.parentNode?.parentNode ?? null,
|
|
266
279
|
offset: 0
|
|
267
|
-
} : { node: null, offset: 0 } : { node: null, offset: t -
|
|
268
|
-
} else if (
|
|
269
|
-
const
|
|
270
|
-
return Z(e) ? t === 0 ? { node: e, offset: t } : { node: null, offset: t -
|
|
280
|
+
} : { node: null, offset: 0 } : { node: null, offset: t - l - 1 };
|
|
281
|
+
} else if (r) {
|
|
282
|
+
const l = L(e) ? 1 : 0;
|
|
283
|
+
return Z(e) ? t === 0 ? { node: e, offset: t } : { node: null, offset: t - l } : t <= (e.textContent?.length || 0) ? { node: e, offset: t } : {
|
|
271
284
|
node: null,
|
|
272
|
-
offset: t - (
|
|
285
|
+
offset: t - (e.textContent?.length || 0) - l
|
|
273
286
|
};
|
|
274
287
|
} else {
|
|
275
|
-
if (
|
|
276
|
-
return t <= (
|
|
288
|
+
if (s)
|
|
289
|
+
return t <= (e.textContent?.length || 0) ? { node: e, offset: t } : {
|
|
277
290
|
node: null,
|
|
278
|
-
offset: t - (
|
|
291
|
+
offset: t - (e.textContent?.length || 0)
|
|
279
292
|
};
|
|
280
293
|
if (e.nodeName === "BR")
|
|
281
294
|
return t === 0 ? { node: e, offset: 0 } : {
|
|
282
295
|
node: null,
|
|
283
296
|
offset: t - 1
|
|
284
297
|
};
|
|
285
|
-
if (
|
|
298
|
+
if (ge(e) && t === 0)
|
|
286
299
|
return { node: e, offset: t };
|
|
287
|
-
for (const
|
|
288
|
-
const
|
|
289
|
-
|
|
300
|
+
for (const c of e.childNodes) {
|
|
301
|
+
const l = I(
|
|
302
|
+
c,
|
|
290
303
|
t
|
|
291
304
|
);
|
|
292
|
-
if (
|
|
293
|
-
return { node:
|
|
294
|
-
t =
|
|
305
|
+
if (l.node)
|
|
306
|
+
return { node: l.node, offset: l.offset };
|
|
307
|
+
t = l.offset;
|
|
295
308
|
}
|
|
296
309
|
return { node: null, offset: t };
|
|
297
310
|
}
|
|
298
311
|
}
|
|
299
|
-
function
|
|
300
|
-
|
|
301
|
-
const n = e.childNodes.length === 1 && ((i = e.firstChild) == null ? void 0 : i.nodeName) === "BR";
|
|
312
|
+
function Q(e, t) {
|
|
313
|
+
const n = e.childNodes.length === 1 && e.firstChild?.nodeName === "BR";
|
|
302
314
|
if (!t || n)
|
|
303
315
|
return [0, 0];
|
|
304
|
-
const
|
|
316
|
+
const s = t.anchorNode && F(
|
|
305
317
|
e,
|
|
306
318
|
t.anchorNode,
|
|
307
319
|
t.anchorOffset
|
|
308
|
-
) || 0,
|
|
320
|
+
) || 0, r = t.focusNode && F(
|
|
309
321
|
e,
|
|
310
322
|
t.focusNode,
|
|
311
323
|
t.focusOffset
|
|
312
324
|
) || 0;
|
|
313
|
-
return [
|
|
325
|
+
return [s, r];
|
|
314
326
|
}
|
|
315
|
-
function
|
|
316
|
-
var n;
|
|
327
|
+
function T(e, t) {
|
|
317
328
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
318
|
-
const s =
|
|
319
|
-
return (
|
|
329
|
+
const s = L(e) ? 1 : 0;
|
|
330
|
+
return (e.textContent?.length ?? 0) + s;
|
|
320
331
|
} else {
|
|
321
332
|
if (e.nodeName === "BR")
|
|
322
333
|
return t === 0 ? 0 : 1;
|
|
323
334
|
{
|
|
324
|
-
let
|
|
325
|
-
for (const
|
|
335
|
+
let n = 0, s = 0;
|
|
336
|
+
for (const r of e.childNodes) {
|
|
326
337
|
if (s === t)
|
|
327
338
|
break;
|
|
328
|
-
|
|
339
|
+
n += T(r, -1), s++;
|
|
329
340
|
}
|
|
330
|
-
return
|
|
341
|
+
return n;
|
|
331
342
|
}
|
|
332
343
|
}
|
|
333
344
|
}
|
|
334
345
|
function Y(e, t, n) {
|
|
335
|
-
|
|
336
|
-
const r = e.nodeType === Node.TEXT_NODE, s = (i = e.parentElement) == null ? void 0 : i.hasAttribute("data-mention-type");
|
|
346
|
+
const s = e.nodeType === Node.TEXT_NODE, r = e.parentElement?.hasAttribute("data-mention-type");
|
|
337
347
|
if (e === t)
|
|
338
|
-
return
|
|
339
|
-
if (
|
|
340
|
-
const c =
|
|
341
|
-
return Z(e) ? { found: !1, offset: c } :
|
|
348
|
+
return s ? n > (e.textContent?.length ?? 0) ? { found: !1, offset: 0 } : r ? { found: !0, offset: n === 0 ? 0 : 1 } : { found: !0, offset: n } : { found: !0, offset: T(e, n) };
|
|
349
|
+
if (s) {
|
|
350
|
+
const c = L(e) ? 1 : 0;
|
|
351
|
+
return Z(e) ? { found: !1, offset: c } : r ? { found: !1, offset: 1 + c } : {
|
|
342
352
|
found: !1,
|
|
343
|
-
offset: (
|
|
353
|
+
offset: (e.textContent?.length ?? 0) + c
|
|
344
354
|
};
|
|
345
355
|
} else {
|
|
346
356
|
if (e.nodeName === "BR")
|
|
347
357
|
return { found: !1, offset: 1 };
|
|
348
358
|
{
|
|
349
|
-
let
|
|
359
|
+
let i = 0;
|
|
350
360
|
for (const c of e.childNodes) {
|
|
351
|
-
const
|
|
352
|
-
if (
|
|
353
|
-
return { found: !0, offset:
|
|
354
|
-
|
|
361
|
+
const l = Y(c, t, n);
|
|
362
|
+
if (l.found)
|
|
363
|
+
return { found: !0, offset: i + l.offset };
|
|
364
|
+
i += l.offset;
|
|
355
365
|
}
|
|
356
|
-
return { found: !1, offset:
|
|
366
|
+
return { found: !1, offset: i };
|
|
357
367
|
}
|
|
358
368
|
}
|
|
359
369
|
}
|
|
360
370
|
function F(e, t, n) {
|
|
361
371
|
if (t === e && n === e.childNodes.length - 1)
|
|
362
|
-
return
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
372
|
+
return T(e, -1) - 1;
|
|
373
|
+
const s = new Range();
|
|
374
|
+
s.setStart(e, 0), s.setEnd(e, e.childNodes.length);
|
|
375
|
+
const r = s.comparePoint(t, 0);
|
|
376
|
+
if (r === -1)
|
|
367
377
|
return 0;
|
|
368
|
-
if (
|
|
369
|
-
return
|
|
378
|
+
if (r === 1)
|
|
379
|
+
return T(e, -1) - 1;
|
|
370
380
|
const i = Y(e, t, n);
|
|
371
381
|
return i.found ? i.offset : -1;
|
|
372
382
|
}
|
|
373
|
-
function
|
|
383
|
+
function L(e) {
|
|
374
384
|
if (e === null) return !1;
|
|
375
385
|
let t = e;
|
|
376
|
-
const n =
|
|
386
|
+
const n = P(t.parentNode);
|
|
377
387
|
for (; t; ) {
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
388
|
+
const s = t.nextSibling;
|
|
389
|
+
if (s && P(s) || n && s && !K(s) || s && s.nodeName === "BR")
|
|
380
390
|
break;
|
|
381
391
|
if (K(t))
|
|
382
392
|
return !0;
|
|
@@ -384,23 +394,21 @@ function N(e) {
|
|
|
384
394
|
}
|
|
385
395
|
return !1;
|
|
386
396
|
}
|
|
387
|
-
const J = ["EM", "U", "STRONG", "DEL", "CODE", "A"],
|
|
388
|
-
function
|
|
397
|
+
const J = ["EM", "U", "STRONG", "DEL", "CODE", "A"], _e = ["OL", "UL", "LI", "PRE", "BLOCKQUOTE", "P"];
|
|
398
|
+
function P(e) {
|
|
389
399
|
return e === null ? !1 : J.includes(e.nodeName || "");
|
|
390
400
|
}
|
|
391
401
|
function K(e) {
|
|
392
|
-
return
|
|
402
|
+
return _e.includes(e.nodeName || "");
|
|
393
403
|
}
|
|
394
|
-
function
|
|
395
|
-
|
|
396
|
-
return J.includes(e.nodeName) && ((t = e.textContent) == null ? void 0 : t.length) === 0;
|
|
404
|
+
function ge(e) {
|
|
405
|
+
return J.includes(e.nodeName) && e.textContent?.length === 0;
|
|
397
406
|
}
|
|
398
407
|
function Z(e) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
return n && t && r;
|
|
408
|
+
const t = e.parentNode?.childNodes.length === 1, n = e.parentNode?.nodeName === "P", s = e.textContent === " ";
|
|
409
|
+
return n && t && s;
|
|
402
410
|
}
|
|
403
|
-
const
|
|
411
|
+
const pe = [
|
|
404
412
|
"bold",
|
|
405
413
|
"italic",
|
|
406
414
|
"strikeThrough",
|
|
@@ -416,26 +424,26 @@ const he = [
|
|
|
416
424
|
"quote",
|
|
417
425
|
"indent",
|
|
418
426
|
"unindent"
|
|
419
|
-
],
|
|
420
|
-
function
|
|
421
|
-
return
|
|
427
|
+
], he = ["@", "#", "/", "", ":"];
|
|
428
|
+
function ye() {
|
|
429
|
+
return pe.reduce((e, t) => (e[t] = "enabled", e), {});
|
|
422
430
|
}
|
|
423
|
-
function
|
|
431
|
+
function M(e) {
|
|
424
432
|
const t = {};
|
|
425
|
-
for (const [n,
|
|
426
|
-
t[n.substring(0, 1).toLowerCase() + n.substring(1)] =
|
|
433
|
+
for (const [n, s] of e)
|
|
434
|
+
t[n.substring(0, 1).toLowerCase() + n.substring(1)] = s.toLowerCase();
|
|
427
435
|
return t;
|
|
428
436
|
}
|
|
429
437
|
function Ee() {
|
|
430
438
|
const e = navigator.userAgent.toLowerCase();
|
|
431
439
|
return e.includes("iphone") || e.includes("ipad") ? "iOS" : e.includes("android") ? "Android" : e.includes("win") ? "Windows" : e.includes("mac") ? "macOS" : e.includes("linux") ? "Linux" : null;
|
|
432
440
|
}
|
|
433
|
-
function
|
|
434
|
-
n
|
|
435
|
-
new CustomEvent("wysiwygInput", { detail: { blockType: t, data:
|
|
441
|
+
function ee(e, t, n, s) {
|
|
442
|
+
n?.preventDefault(), n?.stopPropagation(), e.dispatchEvent(
|
|
443
|
+
new CustomEvent("wysiwygInput", { detail: { blockType: t, data: s } })
|
|
436
444
|
);
|
|
437
445
|
}
|
|
438
|
-
function ke(e, t, n,
|
|
446
|
+
function ke(e, t, n, s, r) {
|
|
439
447
|
if (e.shiftKey && e.altKey)
|
|
440
448
|
switch (e.key) {
|
|
441
449
|
case "5":
|
|
@@ -468,358 +476,355 @@ function ke(e, t, n, r, s) {
|
|
|
468
476
|
case "Backspace":
|
|
469
477
|
return "deleteSoftLineBackward";
|
|
470
478
|
}
|
|
471
|
-
return
|
|
479
|
+
return X(
|
|
472
480
|
e,
|
|
473
481
|
{
|
|
474
482
|
actions: n,
|
|
475
483
|
content: () => t.get_content_as_html(),
|
|
476
484
|
messageContent: () => t.get_content_as_message_html()
|
|
477
485
|
},
|
|
478
|
-
|
|
479
|
-
|
|
486
|
+
s,
|
|
487
|
+
r
|
|
480
488
|
), null;
|
|
481
489
|
}
|
|
482
|
-
function
|
|
490
|
+
function xe(e, t, n, s, r) {
|
|
483
491
|
const i = ke(
|
|
484
492
|
e,
|
|
485
493
|
n,
|
|
486
|
-
|
|
494
|
+
s,
|
|
487
495
|
t,
|
|
488
|
-
|
|
496
|
+
r
|
|
489
497
|
);
|
|
490
|
-
i &&
|
|
498
|
+
i && ee(t, i, e);
|
|
491
499
|
}
|
|
492
|
-
function
|
|
493
|
-
return
|
|
500
|
+
function te(e) {
|
|
501
|
+
return M(e.action_states);
|
|
494
502
|
}
|
|
495
|
-
function
|
|
496
|
-
|
|
497
|
-
const c = le(
|
|
503
|
+
function Ce(e, t, n, s, r, i, c, l, a) {
|
|
504
|
+
const u = fe(
|
|
498
505
|
e,
|
|
499
506
|
n,
|
|
500
|
-
|
|
507
|
+
r.traceAction,
|
|
501
508
|
i,
|
|
502
509
|
t,
|
|
510
|
+
c,
|
|
503
511
|
l,
|
|
504
|
-
|
|
505
|
-
o
|
|
512
|
+
a
|
|
506
513
|
);
|
|
507
|
-
if (
|
|
508
|
-
const
|
|
509
|
-
|
|
514
|
+
if (u) {
|
|
515
|
+
const o = u.text_update().replace_all;
|
|
516
|
+
o && (z(
|
|
510
517
|
t,
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
),
|
|
515
|
-
const
|
|
518
|
+
o.replacement_html,
|
|
519
|
+
o.start_utf16_codeunit,
|
|
520
|
+
o.end_utf16_codeunit
|
|
521
|
+
), r.setEditorHtml(o.replacement_html)), t.focus(), s && de(s, n);
|
|
522
|
+
const f = u.menu_state().update(), m = u.menu_action().suggestion()?.suggestion_pattern, d = f ? te(f) : null, g = m || null;
|
|
516
523
|
return {
|
|
517
|
-
content:
|
|
518
|
-
actionStates:
|
|
519
|
-
suggestion:
|
|
524
|
+
content: o?.replacement_html,
|
|
525
|
+
actionStates: d,
|
|
526
|
+
suggestion: g
|
|
520
527
|
};
|
|
521
528
|
}
|
|
522
529
|
}
|
|
523
|
-
function Te(e, t, { traceAction: n, getSelectionAccordingToActions:
|
|
524
|
-
const [
|
|
525
|
-
if (
|
|
530
|
+
function Te(e, t, { traceAction: n, getSelectionAccordingToActions: s }) {
|
|
531
|
+
const [r, i] = Q(e, document.getSelection()), c = t.selection_start(), l = t.selection_end(), [a, u] = s();
|
|
532
|
+
if (r === c && r === a && i === l && i === u || r === l && r === u && i === c && i === a)
|
|
526
533
|
return;
|
|
527
|
-
const
|
|
528
|
-
n(null, "select",
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
531
|
-
return
|
|
532
|
-
}
|
|
533
|
-
function Se(e, t, n,
|
|
534
|
-
const [
|
|
534
|
+
const o = t.select(r, i);
|
|
535
|
+
n(null, "select", r, i);
|
|
536
|
+
const f = o.menu_state().update();
|
|
537
|
+
if (f)
|
|
538
|
+
return te(f);
|
|
539
|
+
}
|
|
540
|
+
function Se(e, t, n, s, r, i, c, l) {
|
|
541
|
+
const [a, u] = E({
|
|
535
542
|
content: null,
|
|
536
|
-
actionStates:
|
|
543
|
+
actionStates: ye(),
|
|
537
544
|
suggestion: null
|
|
538
|
-
}),
|
|
539
|
-
return
|
|
540
|
-
n && (
|
|
545
|
+
}), o = b(void 0), [f, m] = E(!1);
|
|
546
|
+
return h(() => {
|
|
547
|
+
n && (u({
|
|
541
548
|
content: n.get_content_as_html(),
|
|
542
|
-
actionStates:
|
|
549
|
+
actionStates: M(
|
|
543
550
|
n.action_states()
|
|
544
551
|
),
|
|
545
552
|
suggestion: null
|
|
546
|
-
}),
|
|
547
|
-
}, [n]),
|
|
548
|
-
const
|
|
549
|
-
if (!n || !
|
|
553
|
+
}), o.current = n.get_content_as_plain_text());
|
|
554
|
+
}, [n]), h(() => {
|
|
555
|
+
const d = e.current;
|
|
556
|
+
if (!n || !d)
|
|
550
557
|
return;
|
|
551
|
-
const
|
|
558
|
+
const g = (_) => {
|
|
552
559
|
try {
|
|
553
|
-
const
|
|
560
|
+
const p = Ce(
|
|
554
561
|
_,
|
|
555
|
-
|
|
562
|
+
d,
|
|
556
563
|
n,
|
|
557
564
|
t.current,
|
|
558
|
-
r,
|
|
559
565
|
s,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
566
|
+
r,
|
|
567
|
+
a.suggestion,
|
|
568
|
+
c,
|
|
569
|
+
l
|
|
563
570
|
);
|
|
564
|
-
|
|
565
|
-
const re =
|
|
571
|
+
p && (u((k) => {
|
|
572
|
+
const re = p.content !== void 0 ? p.content : k.content, ie = p.actionStates || k.actionStates, oe = p.suggestion;
|
|
566
573
|
return {
|
|
567
574
|
content: re,
|
|
568
|
-
actionStates:
|
|
569
|
-
suggestion:
|
|
575
|
+
actionStates: ie,
|
|
576
|
+
suggestion: oe
|
|
570
577
|
};
|
|
571
|
-
}),
|
|
578
|
+
}), o.current = n.get_content_as_plain_text());
|
|
572
579
|
} catch {
|
|
573
|
-
i(
|
|
580
|
+
i(o.current);
|
|
574
581
|
}
|
|
575
|
-
},
|
|
576
|
-
|
|
582
|
+
}, S = (_) => {
|
|
583
|
+
y(_) && !_.isComposing && g(_);
|
|
577
584
|
};
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
const
|
|
581
|
-
(
|
|
585
|
+
d.addEventListener("input", S);
|
|
586
|
+
const v = (_) => {
|
|
587
|
+
const p = y(_) && _.inputType === "insertFromPaste" && _.dataTransfer !== null;
|
|
588
|
+
(V(_) || p) && (_.preventDefault(), _.stopPropagation(), g(_));
|
|
582
589
|
};
|
|
583
|
-
|
|
584
|
-
const
|
|
585
|
-
|
|
590
|
+
d.addEventListener("paste", v);
|
|
591
|
+
const R = (_) => {
|
|
592
|
+
g({
|
|
586
593
|
inputType: _.detail.blockType,
|
|
587
594
|
data: _.detail.data
|
|
588
595
|
});
|
|
589
596
|
};
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
|
|
597
|
+
d.addEventListener("wysiwygInput", R);
|
|
598
|
+
const B = (_) => {
|
|
599
|
+
xe(
|
|
593
600
|
_,
|
|
594
|
-
|
|
601
|
+
d,
|
|
595
602
|
n,
|
|
596
|
-
|
|
597
|
-
|
|
603
|
+
r,
|
|
604
|
+
c
|
|
598
605
|
);
|
|
599
606
|
};
|
|
600
|
-
|
|
601
|
-
const
|
|
607
|
+
d.addEventListener("keydown", B);
|
|
608
|
+
const D = () => {
|
|
602
609
|
try {
|
|
603
610
|
const _ = Te(
|
|
604
|
-
|
|
611
|
+
d,
|
|
605
612
|
n,
|
|
606
|
-
|
|
613
|
+
s
|
|
607
614
|
);
|
|
608
|
-
_ &&
|
|
609
|
-
content:
|
|
615
|
+
_ && u(({ content: p, suggestion: k }) => ({
|
|
616
|
+
content: p,
|
|
610
617
|
actionStates: _,
|
|
611
|
-
suggestion:
|
|
612
|
-
})),
|
|
618
|
+
suggestion: k
|
|
619
|
+
})), o.current = n.get_content_as_plain_text();
|
|
613
620
|
} catch {
|
|
614
|
-
i(
|
|
621
|
+
i(o.current);
|
|
615
622
|
}
|
|
616
623
|
};
|
|
617
|
-
document.addEventListener("selectionchange",
|
|
618
|
-
const
|
|
619
|
-
if (!(
|
|
620
|
-
return
|
|
624
|
+
document.addEventListener("selectionchange", D);
|
|
625
|
+
const $ = (_) => {
|
|
626
|
+
if (!(y(_) && _.isComposing))
|
|
627
|
+
return v(_);
|
|
621
628
|
};
|
|
622
|
-
|
|
623
|
-
const
|
|
624
|
-
const
|
|
629
|
+
d.addEventListener("beforeinput", $);
|
|
630
|
+
const U = (_) => {
|
|
631
|
+
const p = new InputEvent("input", {
|
|
625
632
|
data: _.data,
|
|
626
633
|
inputType: "insertCompositionText"
|
|
627
634
|
});
|
|
628
|
-
|
|
635
|
+
S(p);
|
|
629
636
|
};
|
|
630
|
-
return
|
|
631
|
-
|
|
637
|
+
return d.addEventListener("compositionend", U), m(!0), () => {
|
|
638
|
+
m(!1), d.removeEventListener("input", S), d.removeEventListener("paste", v), d.removeEventListener("wysiwygInput", R), d.removeEventListener("keydown", B), d.removeEventListener("beforeinput", $), d.removeEventListener("compositionend", U), document.removeEventListener("selectionchange", D);
|
|
632
639
|
};
|
|
633
640
|
}, [
|
|
634
641
|
e,
|
|
635
|
-
|
|
642
|
+
l,
|
|
636
643
|
n,
|
|
637
|
-
s,
|
|
638
|
-
t,
|
|
639
644
|
r,
|
|
640
|
-
|
|
645
|
+
t,
|
|
646
|
+
s,
|
|
647
|
+
c,
|
|
641
648
|
i,
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
]), { areListenersReady:
|
|
649
|
+
o,
|
|
650
|
+
a.suggestion
|
|
651
|
+
]), { areListenersReady: f, ...a };
|
|
645
652
|
}
|
|
646
|
-
function
|
|
647
|
-
return
|
|
648
|
-
const
|
|
649
|
-
e.current &&
|
|
653
|
+
function we(e, t) {
|
|
654
|
+
return C(() => {
|
|
655
|
+
const s = (r, i) => {
|
|
656
|
+
e.current && ee(
|
|
650
657
|
e.current,
|
|
651
|
-
|
|
658
|
+
r,
|
|
652
659
|
void 0,
|
|
653
660
|
i
|
|
654
661
|
);
|
|
655
662
|
};
|
|
656
663
|
return {
|
|
657
|
-
bold: () =>
|
|
658
|
-
italic: () =>
|
|
659
|
-
strikeThrough: () =>
|
|
660
|
-
underline: () =>
|
|
661
|
-
undo: () =>
|
|
662
|
-
redo: () =>
|
|
663
|
-
orderedList: () =>
|
|
664
|
-
unorderedList: () =>
|
|
665
|
-
inlineCode: () =>
|
|
666
|
-
clear: () =>
|
|
667
|
-
insertText: (
|
|
668
|
-
link: (
|
|
669
|
-
removeLinks: () =>
|
|
670
|
-
getLink: () =>
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
command: (s) => r("insertCommand", s),
|
|
680
|
-
mentionAtRoom: (s) => r("insertAtRoomSuggestion", { attributes: s })
|
|
664
|
+
bold: () => s("formatBold"),
|
|
665
|
+
italic: () => s("formatItalic"),
|
|
666
|
+
strikeThrough: () => s("formatStrikeThrough"),
|
|
667
|
+
underline: () => s("formatUnderline"),
|
|
668
|
+
undo: () => s("historyUndo"),
|
|
669
|
+
redo: () => s("historyRedo"),
|
|
670
|
+
orderedList: () => s("insertOrderedList"),
|
|
671
|
+
unorderedList: () => s("insertUnorderedList"),
|
|
672
|
+
inlineCode: () => s("formatInlineCode"),
|
|
673
|
+
clear: () => s("clear"),
|
|
674
|
+
insertText: (r) => s("insertText", r),
|
|
675
|
+
link: (r, i) => s("insertLink", { url: r, text: i }),
|
|
676
|
+
removeLinks: () => s("removeLinks"),
|
|
677
|
+
getLink: () => t?.get_link_action()?.edit_link?.url || "",
|
|
678
|
+
codeBlock: () => s("insertCodeBlock"),
|
|
679
|
+
quote: () => s("insertQuote"),
|
|
680
|
+
indent: () => s("formatIndent"),
|
|
681
|
+
unindent: () => s("formatOutdent"),
|
|
682
|
+
mention: (r, i, c) => s("insertSuggestion", { url: r, text: i, attributes: c }),
|
|
683
|
+
command: (r) => s("insertCommand", r),
|
|
684
|
+
emoji: (r) => s("insertEmoji", r),
|
|
685
|
+
mentionAtRoom: (r) => s("insertAtRoomSuggestion", { attributes: r })
|
|
681
686
|
};
|
|
682
687
|
}, [e, t]);
|
|
683
688
|
}
|
|
684
|
-
let W = !1,
|
|
685
|
-
async function
|
|
686
|
-
if (
|
|
689
|
+
let W = !1, N = !1;
|
|
690
|
+
async function O() {
|
|
691
|
+
if (N)
|
|
687
692
|
return Promise.resolve();
|
|
688
693
|
if (W)
|
|
689
694
|
return new Promise((e) => {
|
|
690
695
|
function t() {
|
|
691
|
-
|
|
696
|
+
N && e(), setTimeout(t, 200);
|
|
692
697
|
}
|
|
693
698
|
t();
|
|
694
699
|
});
|
|
695
|
-
W = !0, await
|
|
700
|
+
W = !0, await ae(), N = !0;
|
|
696
701
|
}
|
|
697
|
-
function
|
|
698
|
-
const [
|
|
702
|
+
function Le(e, t, n) {
|
|
703
|
+
const [s, r] = E(
|
|
699
704
|
null
|
|
700
|
-
), i =
|
|
701
|
-
async (
|
|
702
|
-
await
|
|
703
|
-
let
|
|
704
|
-
if (
|
|
705
|
+
), i = A(
|
|
706
|
+
async (c) => {
|
|
707
|
+
await O();
|
|
708
|
+
let l;
|
|
709
|
+
if (c)
|
|
705
710
|
try {
|
|
706
|
-
const
|
|
707
|
-
|
|
711
|
+
const a = G(
|
|
712
|
+
c,
|
|
708
713
|
0,
|
|
709
|
-
|
|
714
|
+
c.length
|
|
710
715
|
);
|
|
711
|
-
if (
|
|
712
|
-
const
|
|
713
|
-
|
|
716
|
+
if (l = a, e.current) {
|
|
717
|
+
const u = a.get_content_as_html();
|
|
718
|
+
z(
|
|
714
719
|
e.current,
|
|
715
|
-
|
|
720
|
+
u,
|
|
716
721
|
0,
|
|
717
|
-
|
|
722
|
+
u.length
|
|
718
723
|
);
|
|
719
724
|
}
|
|
720
725
|
} catch {
|
|
721
|
-
|
|
726
|
+
l = w();
|
|
722
727
|
}
|
|
723
728
|
else
|
|
724
|
-
|
|
725
|
-
|
|
729
|
+
l = w();
|
|
730
|
+
r(l);
|
|
726
731
|
},
|
|
727
|
-
[
|
|
732
|
+
[r, e]
|
|
728
733
|
);
|
|
729
|
-
return
|
|
730
|
-
|
|
734
|
+
return h(() => {
|
|
735
|
+
s && n && s.set_custom_suggestion_patterns(
|
|
731
736
|
n
|
|
732
737
|
);
|
|
733
|
-
}, [
|
|
738
|
+
}, [s, n]), h(() => {
|
|
734
739
|
e.current && i(t);
|
|
735
|
-
}, [e, i, t]), { composerModel:
|
|
740
|
+
}, [e, i, t]), { composerModel: s, onError: i };
|
|
736
741
|
}
|
|
737
|
-
function
|
|
742
|
+
function ne(e) {
|
|
738
743
|
return e[0] === "select";
|
|
739
744
|
}
|
|
740
|
-
function
|
|
741
|
-
return (
|
|
745
|
+
function be(e, t, n) {
|
|
746
|
+
return (s, r, i, c) => (!e || !n || (console.debug(c !== void 0 ? `composer_model.${r}(${i}, ${c})` : i !== void 0 ? `composer_model.${r}(${i})` : `composer_model.${r}()`), t.push([r, i, c]), se(e, n, s, t)), s);
|
|
742
747
|
}
|
|
743
|
-
function
|
|
748
|
+
function ve(e) {
|
|
744
749
|
return () => {
|
|
745
750
|
for (let t = e.length - 1; t >= 0; t--) {
|
|
746
751
|
const n = e[t];
|
|
747
|
-
if (
|
|
752
|
+
if (ne(n))
|
|
748
753
|
return [n[1], n[2]];
|
|
749
754
|
}
|
|
750
755
|
return [-1, -1];
|
|
751
756
|
};
|
|
752
757
|
}
|
|
753
|
-
function
|
|
754
|
-
n && n.text_update(), e.innerText =
|
|
755
|
-
|
|
758
|
+
function se(e, t, n, s) {
|
|
759
|
+
n && n.text_update(), e.innerText = Ne(
|
|
760
|
+
s,
|
|
756
761
|
t.to_example_format()
|
|
757
762
|
), e.scrollTo(0, e.scrollHeight - e.clientHeight);
|
|
758
763
|
}
|
|
759
|
-
function
|
|
764
|
+
function Ne(e, t) {
|
|
760
765
|
let n = "";
|
|
761
|
-
function
|
|
762
|
-
|
|
763
|
-
` :
|
|
764
|
-
` :
|
|
765
|
-
` :
|
|
766
|
-
` : n += `model.${
|
|
766
|
+
function s(u, o, f) {
|
|
767
|
+
u === "select" ? n += `model.select(Location::from(${o}), Location::from(${f}));
|
|
768
|
+
` : f !== void 0 ? n += `model.${u}(${o ?? ""}, ${f});
|
|
769
|
+
` : u === "replace_text" ? n += `model.${u}("${o ?? ""}");
|
|
770
|
+
` : u === "send" ? n += `// Send: ${o ?? ""}
|
|
771
|
+
` : n += `model.${u}(${o ?? ""});
|
|
767
772
|
`;
|
|
768
773
|
}
|
|
769
|
-
function
|
|
770
|
-
const
|
|
771
|
-
n += `let mut model = cm("${
|
|
774
|
+
function r() {
|
|
775
|
+
const u = Ae(l, a[0], a[1]);
|
|
776
|
+
n += `let mut model = cm("${u}");
|
|
772
777
|
`;
|
|
773
778
|
}
|
|
774
|
-
let i = null,
|
|
775
|
-
for (const
|
|
776
|
-
const [
|
|
777
|
-
if (
|
|
778
|
-
|
|
779
|
-
else if (i === "select" &&
|
|
780
|
-
const
|
|
779
|
+
let i = null, c = !0, l = "", a = [0, 0];
|
|
780
|
+
for (const u of e) {
|
|
781
|
+
const [o, f, m] = u;
|
|
782
|
+
if (c)
|
|
783
|
+
o === "replace_text" ? l += Oe(f) : ne(u) ? a = [u[1], u[2]] : (c = !1, r(), s(o, f, m));
|
|
784
|
+
else if (i === "select" && o === "select") {
|
|
785
|
+
const d = n.lastIndexOf(`
|
|
781
786
|
`, n.length - 2);
|
|
782
|
-
|
|
783
|
-
`,
|
|
787
|
+
d > -1 && (n = n.substring(0, d) + `
|
|
788
|
+
`, s(o, f, m));
|
|
784
789
|
} else
|
|
785
|
-
|
|
786
|
-
i =
|
|
790
|
+
s(o, f, m);
|
|
791
|
+
i = o;
|
|
787
792
|
}
|
|
788
|
-
return
|
|
793
|
+
return c && r(), n += `assert_eq!(tx(&model), "${t}");
|
|
789
794
|
`, n;
|
|
790
795
|
}
|
|
791
|
-
function
|
|
792
|
-
const
|
|
793
|
-
return
|
|
796
|
+
function Ae(e, t, n) {
|
|
797
|
+
const s = G(e, -1, -1);
|
|
798
|
+
return s.select(t, n), s.to_example_format();
|
|
794
799
|
}
|
|
795
|
-
function
|
|
796
|
-
const [
|
|
797
|
-
["replace_text",
|
|
798
|
-
["select",
|
|
800
|
+
function Ie(e, t, n, s) {
|
|
801
|
+
const [r, i] = Q(e, document.getSelection()), c = [
|
|
802
|
+
["replace_text", s],
|
|
803
|
+
["select", r, i]
|
|
799
804
|
];
|
|
800
|
-
return
|
|
805
|
+
return se(t, n, null, c), c;
|
|
801
806
|
}
|
|
802
|
-
function
|
|
807
|
+
function Oe(e) {
|
|
803
808
|
if (!e)
|
|
804
809
|
return "";
|
|
805
810
|
const t = document.createElement("p");
|
|
806
811
|
return t.appendChild(document.createTextNode(e.toString())), t.innerHTML;
|
|
807
812
|
}
|
|
808
813
|
function Re(e, t) {
|
|
809
|
-
const n =
|
|
810
|
-
(
|
|
811
|
-
n.current &&
|
|
814
|
+
const n = b(null), [s, r] = E([]), [i, c] = E(""), l = A(
|
|
815
|
+
(m) => {
|
|
816
|
+
n.current && c(m);
|
|
812
817
|
},
|
|
813
818
|
[n]
|
|
814
|
-
),
|
|
815
|
-
() =>
|
|
816
|
-
[n,
|
|
817
|
-
),
|
|
818
|
-
() =>
|
|
819
|
-
[
|
|
820
|
-
),
|
|
821
|
-
() => e.current && n.current && t &&
|
|
822
|
-
|
|
819
|
+
), a = C(
|
|
820
|
+
() => be(n.current, s, t),
|
|
821
|
+
[n, s, t]
|
|
822
|
+
), u = C(
|
|
823
|
+
() => ve(s),
|
|
824
|
+
[s]
|
|
825
|
+
), o = A(
|
|
826
|
+
() => e.current && n.current && t && r(
|
|
827
|
+
Ie(
|
|
823
828
|
e.current,
|
|
824
829
|
n.current,
|
|
825
830
|
t,
|
|
@@ -827,27 +832,27 @@ function Re(e, t) {
|
|
|
827
832
|
)
|
|
828
833
|
),
|
|
829
834
|
[e, n, t, i]
|
|
830
|
-
),
|
|
835
|
+
), f = C(
|
|
831
836
|
() => ({
|
|
832
|
-
traceAction:
|
|
833
|
-
getSelectionAccordingToActions:
|
|
834
|
-
onResetTestCase:
|
|
835
|
-
setEditorHtml:
|
|
837
|
+
traceAction: a,
|
|
838
|
+
getSelectionAccordingToActions: u,
|
|
839
|
+
onResetTestCase: o,
|
|
840
|
+
setEditorHtml: l
|
|
836
841
|
}),
|
|
837
842
|
[
|
|
838
|
-
|
|
839
|
-
c,
|
|
843
|
+
a,
|
|
840
844
|
u,
|
|
841
|
-
|
|
845
|
+
o,
|
|
846
|
+
l
|
|
842
847
|
]
|
|
843
848
|
);
|
|
844
849
|
return {
|
|
845
850
|
testRef: n,
|
|
846
|
-
utilities:
|
|
851
|
+
utilities: f
|
|
847
852
|
};
|
|
848
853
|
}
|
|
849
854
|
function Be(e) {
|
|
850
|
-
return
|
|
855
|
+
return he[e.key.key_type] || "";
|
|
851
856
|
}
|
|
852
857
|
function De(e) {
|
|
853
858
|
switch (e.key.key_type) {
|
|
@@ -858,6 +863,8 @@ function De(e) {
|
|
|
858
863
|
return "command";
|
|
859
864
|
case 3:
|
|
860
865
|
return "custom";
|
|
866
|
+
case 4:
|
|
867
|
+
return "emoji";
|
|
861
868
|
default:
|
|
862
869
|
return "unknown";
|
|
863
870
|
}
|
|
@@ -869,133 +876,125 @@ function $e(e) {
|
|
|
869
876
|
type: De(e)
|
|
870
877
|
};
|
|
871
878
|
}
|
|
872
|
-
const
|
|
879
|
+
const x = `
|
|
873
880
|
`, Ue = (e) => {
|
|
874
881
|
let t = e;
|
|
875
|
-
return t.endsWith(
|
|
882
|
+
return t.endsWith(x) && (t = t.slice(0, -1)), t.replaceAll(/\\/g, "");
|
|
876
883
|
};
|
|
877
|
-
async function
|
|
884
|
+
async function Ge(e, t) {
|
|
878
885
|
if (e.length === 0)
|
|
879
886
|
return "";
|
|
880
|
-
await
|
|
881
|
-
const n =
|
|
887
|
+
await O();
|
|
888
|
+
const n = w();
|
|
882
889
|
n.set_content_from_html(e);
|
|
883
|
-
const
|
|
884
|
-
return Ue(
|
|
890
|
+
const s = t ? n.get_content_as_message_markdown() : n.get_content_as_markdown();
|
|
891
|
+
return Ue(s);
|
|
885
892
|
}
|
|
886
|
-
async function
|
|
893
|
+
async function Ve(e, t) {
|
|
887
894
|
if (e.length === 0)
|
|
888
895
|
return "";
|
|
889
|
-
await
|
|
890
|
-
const n = He(e),
|
|
891
|
-
return
|
|
896
|
+
await O();
|
|
897
|
+
const n = He(e), s = w();
|
|
898
|
+
return s.set_content_from_markdown(n), t ? s.get_content_as_message_html() : s.get_content_as_html();
|
|
892
899
|
}
|
|
893
900
|
function He(e) {
|
|
894
|
-
var i, l, m;
|
|
895
901
|
const { body: t } = new DOMParser().parseFromString(
|
|
896
902
|
e,
|
|
897
903
|
"text/html"
|
|
898
904
|
), n = document.createNodeIterator(
|
|
899
905
|
t,
|
|
900
906
|
void 0,
|
|
901
|
-
|
|
907
|
+
Pe
|
|
902
908
|
);
|
|
903
|
-
let
|
|
904
|
-
for (;
|
|
905
|
-
const
|
|
906
|
-
if (
|
|
907
|
-
|
|
908
|
-
else if (
|
|
909
|
-
let
|
|
910
|
-
|
|
909
|
+
let s = n.nextNode(), r = "";
|
|
910
|
+
for (; s !== null; ) {
|
|
911
|
+
const i = s.nodeName === "#text", c = s.nodeName === "A", l = s.nodeName === "DIV" && s.childNodes.length === 1 && s.firstChild?.nodeName === "BR", a = !Fe.includes(s.nodeName);
|
|
912
|
+
if (l)
|
|
913
|
+
r += x;
|
|
914
|
+
else if (i) {
|
|
915
|
+
let u = s.textContent;
|
|
916
|
+
j(s) && (u += x), r += u;
|
|
911
917
|
} else if (c) {
|
|
912
|
-
let
|
|
913
|
-
|
|
914
|
-
} else a && console.debug(`Converting unexpected node type ${
|
|
915
|
-
|
|
918
|
+
let u = s.firstChild?.parentElement?.outerHTML ?? "";
|
|
919
|
+
j(s) && (u += x), r += u;
|
|
920
|
+
} else a && console.debug(`Converting unexpected node type ${s.nodeName}`);
|
|
921
|
+
s = n.nextNode();
|
|
916
922
|
}
|
|
917
|
-
return
|
|
923
|
+
return r.endsWith(x.repeat(2)) && (r = r.slice(0, -1)), r;
|
|
918
924
|
}
|
|
919
925
|
const Fe = ["#text", "BR", "A", "DIV", "BODY"];
|
|
920
|
-
function
|
|
921
|
-
|
|
922
|
-
const t = e.nextSibling || ((n = e.parentElement) == null ? void 0 : n.nextSibling);
|
|
923
|
-
return (t == null ? void 0 : t.nodeName) === "DIV";
|
|
926
|
+
function j(e) {
|
|
927
|
+
return (e.nextSibling || e.parentElement?.nextSibling)?.nodeName === "DIV";
|
|
924
928
|
}
|
|
925
|
-
function
|
|
926
|
-
|
|
927
|
-
return e.nodeName === "#text" && ((t = e.parentElement) != null && t.hasAttribute("data-mention-type")) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
|
|
929
|
+
function Pe(e) {
|
|
930
|
+
return e.nodeName === "#text" && e.parentElement?.hasAttribute("data-mention-type") ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
|
|
928
931
|
}
|
|
929
932
|
function Ke(e, t = !1) {
|
|
930
|
-
|
|
933
|
+
h(() => {
|
|
931
934
|
if (t) {
|
|
932
|
-
const n = setTimeout(() =>
|
|
933
|
-
var r;
|
|
934
|
-
return (r = e.current) == null ? void 0 : r.focus();
|
|
935
|
-
}, 200);
|
|
935
|
+
const n = setTimeout(() => e.current?.focus(), 200);
|
|
936
936
|
return () => clearTimeout(n);
|
|
937
937
|
}
|
|
938
938
|
}, [e, t]);
|
|
939
939
|
}
|
|
940
940
|
function We() {
|
|
941
|
-
const e =
|
|
942
|
-
return
|
|
943
|
-
|
|
944
|
-
(t = e.current) != null && t.childElementCount || (n = e.current) == null || n.appendChild(document.createElement("br"));
|
|
941
|
+
const e = b(null);
|
|
942
|
+
return h(() => {
|
|
943
|
+
e.current?.childElementCount || e.current?.appendChild(document.createElement("br"));
|
|
945
944
|
}, [e]), e;
|
|
946
945
|
}
|
|
947
|
-
function
|
|
948
|
-
const t = e
|
|
946
|
+
function q(e) {
|
|
947
|
+
const t = e?.keys();
|
|
949
948
|
return t ? Array.from(t) : [];
|
|
950
949
|
}
|
|
951
|
-
function
|
|
952
|
-
const t = We(), n =
|
|
953
|
-
|
|
950
|
+
function Xe(e) {
|
|
951
|
+
const t = We(), n = b(null), [s, r] = E(
|
|
952
|
+
q(e?.emojiSuggestions)
|
|
954
953
|
);
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
}, [e
|
|
958
|
-
const { composerModel: i, onError:
|
|
954
|
+
h(() => {
|
|
955
|
+
r(q(e?.emojiSuggestions));
|
|
956
|
+
}, [e?.emojiSuggestions]);
|
|
957
|
+
const { composerModel: i, onError: c } = Le(
|
|
959
958
|
t,
|
|
960
|
-
e
|
|
961
|
-
|
|
962
|
-
), { testRef:
|
|
959
|
+
e?.initialContent,
|
|
960
|
+
s
|
|
961
|
+
), { testRef: l, utilities: a } = Re(
|
|
963
962
|
t,
|
|
964
963
|
i
|
|
965
|
-
),
|
|
964
|
+
), u = we(t, i), { content: o, actionStates: f, areListenersReady: m, suggestion: d } = Se(
|
|
966
965
|
t,
|
|
967
966
|
n,
|
|
968
967
|
i,
|
|
969
|
-
|
|
968
|
+
a,
|
|
969
|
+
u,
|
|
970
970
|
c,
|
|
971
|
-
|
|
972
|
-
e
|
|
973
|
-
e == null ? void 0 : e.emojiSuggestions
|
|
971
|
+
e?.inputEventProcessor,
|
|
972
|
+
e?.emojiSuggestions
|
|
974
973
|
);
|
|
975
|
-
Ke(t, e
|
|
976
|
-
const
|
|
977
|
-
() => $e(
|
|
978
|
-
[
|
|
974
|
+
Ke(t, e?.isAutoFocusEnabled);
|
|
975
|
+
const g = C(
|
|
976
|
+
() => $e(d),
|
|
977
|
+
[d]
|
|
979
978
|
);
|
|
980
979
|
return {
|
|
981
980
|
ref: t,
|
|
982
|
-
isWysiwygReady:
|
|
983
|
-
wysiwyg:
|
|
984
|
-
content:
|
|
985
|
-
actionStates:
|
|
981
|
+
isWysiwygReady: m,
|
|
982
|
+
wysiwyg: u,
|
|
983
|
+
content: o,
|
|
984
|
+
actionStates: f,
|
|
986
985
|
debug: {
|
|
987
986
|
modelRef: n,
|
|
988
|
-
testRef:
|
|
989
|
-
resetTestCase:
|
|
990
|
-
traceAction:
|
|
987
|
+
testRef: l,
|
|
988
|
+
resetTestCase: a.onResetTestCase,
|
|
989
|
+
traceAction: a.traceAction
|
|
991
990
|
},
|
|
992
|
-
suggestion:
|
|
993
|
-
messageContent:
|
|
991
|
+
suggestion: g,
|
|
992
|
+
messageContent: i?.get_content_as_message_html() ?? null
|
|
994
993
|
};
|
|
995
994
|
}
|
|
996
995
|
export {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
996
|
+
O as initOnce,
|
|
997
|
+
Ve as plainToRich,
|
|
998
|
+
Ge as richToPlain,
|
|
999
|
+
Xe as useWysiwyg
|
|
1001
1000
|
};
|