@vector-im/matrix-wysiwyg 2.38.5 → 2.40.0

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