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