@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.
@@ -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,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 && 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
  );
@@ -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 && o.data)
80
+ if (i && a.data)
70
81
  return n(
71
82
  t.replace_text_suggestion(
72
- o.data,
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 a = document.getSelection();
88
- return a && (a.modify("extend", "backward", "lineboundary"), document.dispatchEvent(new CustomEvent("selectionchange"))), n(t.delete(), "backspace_line");
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 c(
131
+ return u(
121
132
  t,
122
133
  i,
123
- m
134
+ l
124
135
  ), n(t.enter(), "enter");
125
136
  case "insertReplacementText": {
126
- const a = s.innerHTML.slice(
137
+ const o = r.innerHTML.slice(
127
138
  0,
128
- s.innerHTML.length - 4
139
+ r.innerHTML.length - 4
129
140
  );
130
141
  return n(
131
- t.set_content_from_html(a),
142
+ t.set_content_from_html(o),
132
143
  "set_content_from_html",
133
- a
144
+ o
134
145
  );
135
146
  }
136
147
  case "insertCompositionText":
137
148
  case "insertFromComposition":
138
149
  case "insertText":
139
- if (o.data)
140
- return o.data == " " && c(
150
+ if (a.data)
151
+ return a.data == " " && u(
141
152
  t,
142
153
  i,
143
- m
154
+ l
144
155
  ), n(
145
- t.replace_text(o.data),
156
+ t.replace_text(a.data),
146
157
  "replace_text",
147
- o.data
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 (ue(o)) {
154
- const { text: a, url: d } = o.data;
164
+ if (le(a)) {
165
+ const { text: o, url: f } = a.data;
155
166
  return n(
156
- a ? t.set_link_with_text(d, a, /* @__PURE__ */ new Map()) : t.set_link(d, /* @__PURE__ */ new Map()),
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: ${o.inputType}`), console.error(e), null;
181
+ return console.error(`Unknown input type: ${a.inputType}`), console.error(e), null;
171
182
  }
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);
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 fe(e, t) {
190
+ function de(e, t) {
180
191
  e.innerHTML = "";
181
192
  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);
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 l.appendChild(u), u;
201
+ return c.appendChild(o), o;
191
202
  }
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,
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", f],
220
+ ["id", d],
210
221
  ["checked", null]
211
222
  ])
212
- ), s(
213
- h,
223
+ ), r(
224
+ g,
214
225
  "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,
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
- ), s(d, "span", `${u.text(t)}`), s(d, "span", '"', /* @__PURE__ */ new Map([["class", "quote"]]));
241
+ ), r(m, "span", `${o.text(t)}`), r(m, "span", '"', /* @__PURE__ */ new Map([["class", "quote"]]));
231
242
  } else
232
- console.error(`Unknown node type: ${a}`);
243
+ console.error(`Unknown node type: ${f}`);
233
244
  }
234
245
  }
235
246
  i(n, e);
236
247
  }
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))
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
- r.setStart(s.node, s.offset), r.setEnd(i.node, i.offset);
255
+ s.setStart(r.node, r.offset), s.setEnd(i.node, i.offset);
245
256
  } 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 ? {
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: L(
270
+ offset: T(
261
271
  e.previousSibling,
262
272
  1 / 0
263
273
  )
264
274
  } : {
265
- node: ((m = e.parentNode) == null ? void 0 : m.parentNode) ?? null,
275
+ node: e.parentNode?.parentNode ?? null,
266
276
  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 } : {
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 - (((c = e.textContent) == null ? void 0 : c.length) || 0) - f
282
+ offset: t - (e.textContent?.length || 0) - l
273
283
  };
274
284
  } else {
275
- if (r)
276
- return t <= (((u = e.textContent) == null ? void 0 : u.length) || 0) ? { node: e, offset: t } : {
285
+ if (s)
286
+ return t <= (e.textContent?.length || 0) ? { node: e, offset: t } : {
277
287
  node: null,
278
- offset: t - (((a = e.textContent) == null ? void 0 : a.length) || 0)
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 (_e(e) && t === 0)
295
+ if (ge(e) && t === 0)
286
296
  return { node: e, offset: t };
287
- for (const d of e.childNodes) {
288
- const f = y(
289
- d,
297
+ for (const c of e.childNodes) {
298
+ const l = I(
299
+ c,
290
300
  t
291
301
  );
292
- if (f.node)
293
- return { node: f.node, offset: f.offset };
294
- t = f.offset;
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 j(e, t) {
300
- var i;
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 r = t.anchorNode && F(
313
+ const s = t.anchorNode && F(
305
314
  e,
306
315
  t.anchorNode,
307
316
  t.anchorOffset
308
- ) || 0, s = t.focusNode && F(
317
+ ) || 0, r = t.focusNode && F(
309
318
  e,
310
319
  t.focusNode,
311
320
  t.focusOffset
312
321
  ) || 0;
313
- return [r, s];
322
+ return [s, r];
314
323
  }
315
- function L(e, t) {
316
- var n;
324
+ function T(e, t) {
317
325
  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;
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 r = 0, s = 0;
325
- for (const i of e.childNodes) {
332
+ let n = 0, s = 0;
333
+ for (const r of e.childNodes) {
326
334
  if (s === t)
327
335
  break;
328
- r += L(i, -1), s++;
336
+ n += T(r, -1), s++;
329
337
  }
330
- return r;
338
+ return n;
331
339
  }
332
340
  }
333
341
  }
334
342
  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");
343
+ const s = e.nodeType === Node.TEXT_NODE, r = e.parentElement?.hasAttribute("data-mention-type");
337
344
  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 } : {
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: (((m = e.textContent) == null ? void 0 : m.length) ?? 0) + c
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 o = 0;
356
+ let i = 0;
350
357
  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;
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: o };
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 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)
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 (s === 1)
369
- return L(e, -1) - 1;
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 N(e) {
380
+ function L(e) {
374
381
  if (e === null) return !1;
375
382
  let t = e;
376
- const n = w(t.parentNode);
383
+ const n = P(t.parentNode);
377
384
  for (; t; ) {
378
- const r = t.nextSibling;
379
- if (r && w(r) || n && r && !K(r) || r && r.nodeName === "BR")
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"], me = ["OL", "UL", "LI", "PRE", "BLOCKQUOTE", "P"];
388
- function w(e) {
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 me.includes(e.nodeName || "");
399
+ return _e.includes(e.nodeName || "");
393
400
  }
394
- function _e(e) {
395
- var t;
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
- 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;
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 he = [
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
- ], ge = ["@", "#", "/", ""];
420
- function pe() {
421
- return he.reduce((e, t) => (e[t] = "enabled", e), {});
424
+ ], he = ["@", "#", "/", ""];
425
+ function ye() {
426
+ return pe.reduce((e, t) => (e[t] = "enabled", e), {});
422
427
  }
423
- function P(e) {
428
+ function M(e) {
424
429
  const t = {};
425
- for (const [n, r] of e)
426
- t[n.substring(0, 1).toLowerCase() + n.substring(1)] = r.toLowerCase();
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 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 } })
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, r, s) {
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 z(
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
- r,
479
- s
483
+ s,
484
+ r
480
485
  ), null;
481
486
  }
482
- function Ce(e, t, n, r, s) {
487
+ function xe(e, t, n, s, r) {
483
488
  const i = ke(
484
489
  e,
485
490
  n,
486
- r,
491
+ s,
487
492
  t,
488
- s
493
+ r
489
494
  );
490
- i && M(t, i, e);
495
+ i && ee(t, i, e);
491
496
  }
492
- function ee(e) {
493
- return P(e.action_states);
497
+ function te(e) {
498
+ return M(e.action_states);
494
499
  }
495
- function xe(e, t, n, r, s, i, l, m, o) {
496
- var u;
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
- s.traceAction,
504
+ r.traceAction,
501
505
  i,
502
506
  t,
507
+ c,
503
508
  l,
504
- m,
505
- o
509
+ a
506
510
  );
507
- if (c) {
508
- const a = c.text_update().replace_all;
509
- a && (Q(
511
+ if (u) {
512
+ const o = u.text_update().replace_all;
513
+ o && (z(
510
514
  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;
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: a == null ? void 0 : a.replacement_html,
518
- actionStates: h,
519
- suggestion: C
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: 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)
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 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({
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: pe(),
540
+ actionStates: ye(),
537
541
  suggestion: null
538
- }), u = A(void 0), [a, d] = k(!1);
539
- return p(() => {
540
- n && (c({
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: P(
546
+ actionStates: M(
543
547
  n.action_states()
544
548
  ),
545
549
  suggestion: null
546
- }), u.current = n.get_content_as_plain_text());
547
- }, [n]), p(() => {
548
- const f = e.current;
549
- if (!n || !f)
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 h = (_) => {
555
+ const g = (_) => {
552
556
  try {
553
- const g = xe(
557
+ const p = Ce(
554
558
  _,
555
- f,
559
+ d,
556
560
  n,
557
561
  t.current,
558
- r,
559
562
  s,
560
- o.suggestion,
561
- l,
562
- m
563
+ r,
564
+ a.suggestion,
565
+ c,
566
+ l
563
567
  );
564
- g && (c((x) => {
565
- const re = g.content !== void 0 ? g.content : x.content, se = g.actionStates || x.actionStates, ie = g.suggestion;
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: se,
569
- suggestion: ie
572
+ actionStates: ie,
573
+ suggestion: oe
570
574
  };
571
- }), u.current = n.get_content_as_plain_text());
575
+ }), o.current = n.get_content_as_plain_text());
572
576
  } catch {
573
- i(u.current);
577
+ i(o.current);
574
578
  }
575
- }, C = (_) => {
576
- E(_) && !_.isComposing && h(_);
579
+ }, S = (_) => {
580
+ y(_) && !_.isComposing && g(_);
577
581
  };
578
- f.addEventListener("input", C);
579
- const b = (_) => {
580
- const g = E(_) && _.inputType === "insertFromPaste" && _.dataTransfer !== null;
581
- (X(_) || g) && (_.preventDefault(), _.stopPropagation(), h(_));
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
- f.addEventListener("paste", b);
584
- const B = (_) => {
585
- h({
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
- f.addEventListener("wysiwygInput", B);
591
- const D = (_) => {
592
- Ce(
594
+ d.addEventListener("wysiwygInput", R);
595
+ const B = (_) => {
596
+ xe(
593
597
  _,
594
- f,
598
+ d,
595
599
  n,
596
- s,
597
- l
600
+ r,
601
+ c
598
602
  );
599
603
  };
600
- f.addEventListener("keydown", D);
601
- const $ = () => {
604
+ d.addEventListener("keydown", B);
605
+ const D = () => {
602
606
  try {
603
607
  const _ = Te(
604
- f,
608
+ d,
605
609
  n,
606
- r
610
+ s
607
611
  );
608
- _ && c(({ content: g, suggestion: x }) => ({
609
- content: g,
612
+ _ && u(({ content: p, suggestion: k }) => ({
613
+ content: p,
610
614
  actionStates: _,
611
- suggestion: x
612
- })), u.current = n.get_content_as_plain_text();
615
+ suggestion: k
616
+ })), o.current = n.get_content_as_plain_text();
613
617
  } catch {
614
- i(u.current);
618
+ i(o.current);
615
619
  }
616
620
  };
617
- document.addEventListener("selectionchange", $);
618
- const U = (_) => {
619
- if (!(E(_) && _.isComposing))
620
- return b(_);
621
+ document.addEventListener("selectionchange", D);
622
+ const $ = (_) => {
623
+ if (!(y(_) && _.isComposing))
624
+ return v(_);
621
625
  };
622
- f.addEventListener("beforeinput", U);
623
- const H = (_) => {
624
- const g = new InputEvent("input", {
626
+ d.addEventListener("beforeinput", $);
627
+ const U = (_) => {
628
+ const p = new InputEvent("input", {
625
629
  data: _.data,
626
630
  inputType: "insertCompositionText"
627
631
  });
628
- C(g);
632
+ S(p);
629
633
  };
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", $);
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
- m,
639
+ l,
636
640
  n,
637
- s,
638
- t,
639
641
  r,
640
- l,
642
+ t,
643
+ s,
644
+ c,
641
645
  i,
642
- u,
643
- o.suggestion
644
- ]), { areListenersReady: a, ...o };
646
+ o,
647
+ a.suggestion
648
+ ]), { areListenersReady: f, ...a };
645
649
  }
646
- function Le(e, t) {
647
- return S(() => {
648
- const r = (s, i) => {
649
- e.current && M(
650
+ function we(e, t) {
651
+ return C(() => {
652
+ const s = (r, i) => {
653
+ e.current && ee(
650
654
  e.current,
651
- s,
655
+ r,
652
656
  void 0,
653
657
  i
654
658
  );
655
659
  };
656
660
  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 })
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, I = !1;
685
- async function R() {
686
- if (I)
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
- I && e(), setTimeout(t, 200);
692
+ N && e(), setTimeout(t, 200);
692
693
  }
693
694
  t();
694
695
  });
695
- W = !0, await oe(), I = !0;
696
+ W = !0, await ae(), N = !0;
696
697
  }
697
- function be(e, t, n) {
698
- const [r, s] = k(
698
+ function Le(e, t, n) {
699
+ const [s, r] = E(
699
700
  null
700
- ), i = O(
701
- async (l) => {
702
- await R();
703
- let m;
704
- if (l)
701
+ ), i = A(
702
+ async (c) => {
703
+ await O();
704
+ let l;
705
+ if (c)
705
706
  try {
706
- const o = V(
707
- l,
707
+ const a = G(
708
+ c,
708
709
  0,
709
- l.length
710
+ c.length
710
711
  );
711
- if (m = o, e.current) {
712
- const c = o.get_content_as_html();
713
- Q(
712
+ if (l = a, e.current) {
713
+ const u = a.get_content_as_html();
714
+ z(
714
715
  e.current,
715
- c,
716
+ u,
716
717
  0,
717
- c.length
718
+ u.length
718
719
  );
719
720
  }
720
721
  } catch {
721
- m = v();
722
+ l = w();
722
723
  }
723
724
  else
724
- m = v();
725
- s(m);
725
+ l = w();
726
+ r(l);
726
727
  },
727
- [s, e]
728
+ [r, e]
728
729
  );
729
- return p(() => {
730
- r && n && r.set_custom_suggestion_patterns(
730
+ return h(() => {
731
+ s && n && s.set_custom_suggestion_patterns(
731
732
  n
732
733
  );
733
- }, [r, n]), p(() => {
734
+ }, [s, n]), h(() => {
734
735
  e.current && i(t);
735
- }, [e, i, t]), { composerModel: r, onError: i };
736
+ }, [e, i, t]), { composerModel: s, onError: i };
736
737
  }
737
- function te(e) {
738
+ function ne(e) {
738
739
  return e[0] === "select";
739
740
  }
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);
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 Ne(e) {
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 (te(n))
748
+ if (ne(n))
748
749
  return [n[1], n[2]];
749
750
  }
750
751
  return [-1, -1];
751
752
  };
752
753
  }
753
- function ne(e, t, n, r) {
754
- n && n.text_update(), e.innerText = Ae(
755
- r,
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 Ae(e, t) {
760
+ function Ne(e, t) {
760
761
  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 ?? ""});
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 s() {
770
- const c = Ie(m, o[0], o[1]);
771
- n += `let mut model = cm("${c}");
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, 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(`
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
- f > -1 && (n = n.substring(0, f) + `
783
- `, r(u, a, d));
783
+ d > -1 && (n = n.substring(0, d) + `
784
+ `, s(o, f, m));
784
785
  } else
785
- r(u, a, d);
786
- i = u;
786
+ s(o, f, m);
787
+ i = o;
787
788
  }
788
- return l && s(), n += `assert_eq!(tx(&model), "${t}");
789
+ return c && r(), n += `assert_eq!(tx(&model), "${t}");
789
790
  `, n;
790
791
  }
791
- function Ie(e, t, n) {
792
- const r = V(e, -1, -1);
793
- return r.select(t, n), r.to_example_format();
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 Oe(e, t, n, r) {
796
- const [s, i] = j(e, document.getSelection()), l = [
797
- ["replace_text", r],
798
- ["select", s, i]
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 ne(t, n, null, l), l;
801
+ return se(t, n, null, c), c;
801
802
  }
802
- function ye(e) {
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 = A(null), [r, s] = k([]), [i, l] = k(""), m = O(
810
- (d) => {
811
- n.current && l(d);
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
- ), 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(
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
- ), a = S(
831
+ ), f = C(
831
832
  () => ({
832
- traceAction: o,
833
- getSelectionAccordingToActions: c,
834
- onResetTestCase: u,
835
- setEditorHtml: m
833
+ traceAction: a,
834
+ getSelectionAccordingToActions: u,
835
+ onResetTestCase: o,
836
+ setEditorHtml: l
836
837
  }),
837
838
  [
838
- o,
839
- c,
839
+ a,
840
840
  u,
841
- m
841
+ o,
842
+ l
842
843
  ]
843
844
  );
844
845
  return {
845
846
  testRef: n,
846
- utilities: a
847
+ utilities: f
847
848
  };
848
849
  }
849
850
  function Be(e) {
850
- return ge[e.key.key_type] || "";
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 T = `
873
+ const x = `
873
874
  `, Ue = (e) => {
874
875
  let t = e;
875
- return t.endsWith(T) && (t = t.slice(0, -1)), t.replaceAll(/\\/g, "");
876
+ return t.endsWith(x) && (t = t.slice(0, -1)), t.replaceAll(/\\/g, "");
876
877
  };
877
- async function Ve(e, t) {
878
+ async function Ge(e, t) {
878
879
  if (e.length === 0)
879
880
  return "";
880
- await R();
881
- const n = v();
881
+ await O();
882
+ const n = w();
882
883
  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);
884
+ const s = t ? n.get_content_as_message_markdown() : n.get_content_as_markdown();
885
+ return Ue(s);
885
886
  }
886
- async function Xe(e, t) {
887
+ async function Ve(e, t) {
887
888
  if (e.length === 0)
888
889
  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();
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
- we
901
+ Pe
902
902
  );
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;
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 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();
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 s.endsWith(T.repeat(2)) && (s = s.slice(0, -1)), s;
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
- var n;
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 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;
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
- p(() => {
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 = 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"));
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 G(e) {
948
- const t = e == null ? void 0 : e.keys();
940
+ function j(e) {
941
+ const t = e?.keys();
949
942
  return t ? Array.from(t) : [];
950
943
  }
951
- function ze(e) {
952
- const t = We(), n = A(null), [r, s] = k(
953
- G(e == null ? void 0 : e.emojiSuggestions)
944
+ function Xe(e) {
945
+ const t = We(), n = b(null), [s, r] = E(
946
+ j(e?.emojiSuggestions)
954
947
  );
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(
948
+ h(() => {
949
+ r(j(e?.emojiSuggestions));
950
+ }, [e?.emojiSuggestions]);
951
+ const { composerModel: i, onError: c } = Le(
959
952
  t,
960
- e == null ? void 0 : e.initialContent,
961
- r
962
- ), { testRef: m, utilities: o } = Re(
953
+ e?.initialContent,
954
+ s
955
+ ), { testRef: l, utilities: a } = Re(
963
956
  t,
964
957
  i
965
- ), c = Le(t, i), { content: u, actionStates: a, areListenersReady: d, suggestion: f } = Se(
958
+ ), u = we(t, i), { content: o, actionStates: f, areListenersReady: m, suggestion: d } = Se(
966
959
  t,
967
960
  n,
968
961
  i,
969
- o,
962
+ a,
963
+ u,
970
964
  c,
971
- l,
972
- e == null ? void 0 : e.inputEventProcessor,
973
- e == null ? void 0 : e.emojiSuggestions
965
+ e?.inputEventProcessor,
966
+ e?.emojiSuggestions
974
967
  );
975
- Ke(t, e == null ? void 0 : e.isAutoFocusEnabled);
976
- const h = S(
977
- () => $e(f),
978
- [f]
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: d,
983
- wysiwyg: c,
984
- content: u,
985
- actionStates: a,
975
+ isWysiwygReady: m,
976
+ wysiwyg: u,
977
+ content: o,
978
+ actionStates: f,
986
979
  debug: {
987
980
  modelRef: n,
988
- testRef: m,
989
- resetTestCase: o.onResetTestCase,
990
- traceAction: o.traceAction
981
+ testRef: l,
982
+ resetTestCase: a.onResetTestCase,
983
+ traceAction: a.traceAction
991
984
  },
992
- suggestion: h,
993
- messageContent: (i == null ? void 0 : i.get_content_as_message_html()) ?? null
985
+ suggestion: g,
986
+ messageContent: i?.get_content_as_message_html() ?? null
994
987
  };
995
988
  }
996
989
  export {
997
- R as initOnce,
998
- Xe as plainToRich,
999
- Ve as richToPlain,
1000
- ze as useWysiwyg
990
+ O as initOnce,
991
+ Ve as plainToRich,
992
+ Ge as richToPlain,
993
+ Xe as useWysiwyg
1001
994
  };