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