@connectedxm/entity-editor 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,796 +1,652 @@
1
- import a from "react";
2
- var ue = { exports: {} }, Z = {};
3
- var Me;
4
- function Ze() {
5
- if (Me) return Z;
6
- Me = 1;
7
- var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function s(o, r, c) {
9
- var i = null;
10
- if (c !== void 0 && (i = "" + c), r.key !== void 0 && (i = "" + r.key), "key" in r) {
11
- c = {};
12
- for (var u in r)
13
- u !== "key" && (c[u] = r[u]);
14
- } else c = r;
15
- return r = c.ref, {
16
- $$typeof: e,
17
- type: o,
18
- key: i,
19
- ref: r !== void 0 ? r : null,
20
- props: c
21
- };
22
- }
23
- return Z.Fragment = t, Z.jsx = s, Z.jsxs = s, Z;
24
- }
25
- var Q = {};
26
- var $e;
27
- function Qe() {
28
- return $e || ($e = 1, process.env.NODE_ENV !== "production" && (function() {
29
- function e(n) {
30
- if (n == null) return null;
31
- if (typeof n == "function")
32
- return n.$$typeof === ie ? null : n.displayName || n.name || null;
33
- if (typeof n == "string") return n;
34
- switch (n) {
35
- case O:
36
- return "Fragment";
37
- case T:
38
- return "Profiler";
39
- case oe:
40
- return "StrictMode";
41
- case P:
42
- return "Suspense";
43
- case V:
44
- return "SuspenseList";
45
- case we:
46
- return "Activity";
47
- }
48
- if (typeof n == "object")
49
- switch (typeof n.tag == "number" && console.error(
50
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
- ), n.$$typeof) {
52
- case D:
53
- return "Portal";
54
- case ce:
55
- return n.displayName || "Context";
56
- case z:
57
- return (n._context.displayName || "Context") + ".Consumer";
58
- case be:
59
- var l = n.render;
60
- return n = n.displayName, n || (n = l.displayName || l.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
61
- case X:
62
- return l = n.displayName || null, l !== null ? l : e(n.type) || "Memo";
63
- case q:
64
- l = n._payload, n = n._init;
65
- try {
66
- return e(n(l));
67
- } catch {
68
- }
69
- }
70
- return null;
71
- }
72
- function t(n) {
73
- return "" + n;
74
- }
75
- function s(n) {
76
- try {
77
- t(n);
78
- var l = !1;
79
- } catch {
80
- l = !0;
81
- }
82
- if (l) {
83
- l = console;
84
- var m = l.error, S = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
85
- return m.call(
86
- l,
87
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
- S
89
- ), t(n);
90
- }
91
- }
92
- function o(n) {
93
- if (n === O) return "<>";
94
- if (typeof n == "object" && n !== null && n.$$typeof === q)
95
- return "<...>";
96
- try {
97
- var l = e(n);
98
- return l ? "<" + l + ">" : "<...>";
99
- } catch {
100
- return "<...>";
101
- }
102
- }
103
- function r() {
104
- var n = x.A;
105
- return n === null ? null : n.getOwner();
106
- }
107
- function c() {
108
- return Error("react-stack-top-frame");
109
- }
110
- function i(n) {
111
- if (j.call(n, "key")) {
112
- var l = Object.getOwnPropertyDescriptor(n, "key").get;
113
- if (l && l.isReactWarning) return !1;
114
- }
115
- return n.key !== void 0;
116
- }
117
- function u(n, l) {
118
- function m() {
119
- G || (G = !0, console.error(
120
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
- l
122
- ));
123
- }
124
- m.isReactWarning = !0, Object.defineProperty(n, "key", {
125
- get: m,
126
- configurable: !0
127
- });
128
- }
129
- function f() {
130
- var n = e(this.type);
131
- return H[n] || (H[n] = !0, console.error(
132
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
- )), n = this.props.ref, n !== void 0 ? n : null;
134
- }
135
- function R(n, l, m, S, F, K) {
136
- var k = m.ref;
137
- return n = {
138
- $$typeof: v,
139
- type: n,
140
- key: l,
141
- props: m,
142
- _owner: S
143
- }, (k !== void 0 ? k : null) !== null ? Object.defineProperty(n, "ref", {
144
- enumerable: !1,
145
- get: f
146
- }) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
147
- configurable: !1,
148
- enumerable: !1,
149
- writable: !0,
150
- value: 0
151
- }), Object.defineProperty(n, "_debugInfo", {
152
- configurable: !1,
153
- enumerable: !1,
154
- writable: !0,
155
- value: null
156
- }), Object.defineProperty(n, "_debugStack", {
157
- configurable: !1,
158
- enumerable: !1,
159
- writable: !0,
160
- value: F
161
- }), Object.defineProperty(n, "_debugTask", {
162
- configurable: !1,
163
- enumerable: !1,
164
- writable: !0,
165
- value: K
166
- }), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
167
- }
168
- function y(n, l, m, S, F, K) {
169
- var k = l.children;
170
- if (k !== void 0)
171
- if (S)
172
- if (L(k)) {
173
- for (S = 0; S < k.length; S++)
174
- se(k[S]);
175
- Object.freeze && Object.freeze(k);
176
- } else
177
- console.error(
178
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
- );
180
- else se(k);
181
- if (j.call(l, "key")) {
182
- k = e(n);
183
- var C = Object.keys(l).filter(function(ve) {
184
- return ve !== "key";
185
- });
186
- S = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", $[k + S] || (C = 0 < C.length ? "{" + C.join(": ..., ") + ": ...}" : "{}", console.error(
187
- `A props object containing a "key" prop is being spread into JSX:
188
- let props = %s;
189
- <%s {...props} />
190
- React keys must be passed directly to JSX without using spread:
191
- let props = %s;
192
- <%s key={someKey} {...props} />`,
193
- S,
194
- k,
195
- C,
196
- k
197
- ), $[k + S] = !0);
198
- }
199
- if (k = null, m !== void 0 && (s(m), k = "" + m), i(l) && (s(l.key), k = "" + l.key), "key" in l) {
200
- m = {};
201
- for (var U in l)
202
- U !== "key" && (m[U] = l[U]);
203
- } else m = l;
204
- return k && u(
205
- m,
206
- typeof n == "function" ? n.displayName || n.name || "Unknown" : n
207
- ), R(
208
- n,
209
- k,
210
- m,
211
- r(),
212
- F,
213
- K
214
- );
215
- }
216
- function se(n) {
217
- W(n) ? n._store && (n._store.validated = 1) : typeof n == "object" && n !== null && n.$$typeof === q && (n._payload.status === "fulfilled" ? W(n._payload.value) && n._payload.value._store && (n._payload.value._store.validated = 1) : n._store && (n._store.validated = 1));
218
- }
219
- function W(n) {
220
- return typeof n == "object" && n !== null && n.$$typeof === v;
221
- }
222
- var w = a, v = /* @__PURE__ */ Symbol.for("react.transitional.element"), D = /* @__PURE__ */ Symbol.for("react.portal"), O = /* @__PURE__ */ Symbol.for("react.fragment"), oe = /* @__PURE__ */ Symbol.for("react.strict_mode"), T = /* @__PURE__ */ Symbol.for("react.profiler"), z = /* @__PURE__ */ Symbol.for("react.consumer"), ce = /* @__PURE__ */ Symbol.for("react.context"), be = /* @__PURE__ */ Symbol.for("react.forward_ref"), P = /* @__PURE__ */ Symbol.for("react.suspense"), V = /* @__PURE__ */ Symbol.for("react.suspense_list"), X = /* @__PURE__ */ Symbol.for("react.memo"), q = /* @__PURE__ */ Symbol.for("react.lazy"), we = /* @__PURE__ */ Symbol.for("react.activity"), ie = /* @__PURE__ */ Symbol.for("react.client.reference"), x = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, L = Array.isArray, Y = console.createTask ? console.createTask : function() {
223
- return null;
224
- };
225
- w = {
226
- react_stack_bottom_frame: function(n) {
227
- return n();
228
- }
229
- };
230
- var G, H = {}, J = w.react_stack_bottom_frame.bind(
231
- w,
232
- c
233
- )(), M = Y(o(c)), $ = {};
234
- Q.Fragment = O, Q.jsx = function(n, l, m) {
235
- var S = 1e4 > x.recentlyCreatedOwnerStacks++;
236
- return y(
237
- n,
238
- l,
239
- m,
240
- !1,
241
- S ? Error("react-stack-top-frame") : J,
242
- S ? Y(o(n)) : M
243
- );
244
- }, Q.jsxs = function(n, l, m) {
245
- var S = 1e4 > x.recentlyCreatedOwnerStacks++;
246
- return y(
247
- n,
248
- l,
249
- m,
250
- !0,
251
- S ? Error("react-stack-top-frame") : J,
252
- S ? Y(o(n)) : M
253
- );
254
- };
255
- })()), Q;
256
- }
257
- var Be;
258
- function et() {
259
- return Be || (Be = 1, process.env.NODE_ENV === "production" ? ue.exports = Ze() : ue.exports = Qe()), ue.exports;
260
- }
261
- var B = et();
262
- const De = (e) => {
263
- const t = window.getSelection();
264
- if (!t || !e) return { start: 0, end: 0 };
265
- if (t.anchorNode && e.contains(t.anchorNode)) {
266
- const s = t.getRangeAt(0), o = s.cloneRange();
267
- o.selectNodeContents(e), o.setEnd(s.startContainer, s.startOffset);
268
- const r = o.toString().length, c = s.cloneRange();
269
- c.selectNodeContents(e), c.setEnd(s.endContainer, s.endOffset);
270
- const i = c.toString().length;
271
- return { start: r, end: i };
272
- } else
273
- return null;
274
- }, tt = (e, t) => {
275
- const s = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
276
- let o = 0, r = s.nextNode(), c = null, i = null, u = 0, f = 0;
277
- for (; r; ) {
278
- const R = o + (r.textContent?.length || 0);
279
- if (!c && R >= t.start && (c = r, u = t.start - o), !i && R >= t.end) {
280
- i = r, f = t.end - o;
281
- break;
282
- }
283
- o = R, r = s.nextNode();
284
- }
285
- if (c && i) {
286
- const R = document.createRange();
287
- R.setStart(
288
- c,
289
- Math.min(u, c.textContent?.length || 0)
290
- ), R.setEnd(
291
- i,
292
- Math.min(f, i.textContent?.length || 0)
293
- );
294
- const y = window.getSelection();
295
- y?.removeAllRanges(), y?.addRange(R);
296
- }
297
- }, nt = (e, t, s) => {
298
- let o = "", r = "", c = "", i = "";
299
- t.includes("bold") && (r = "bold"), t.includes("italic") && (c = "italic"), (t.includes("underline") || e === "link") && (i += "underline"), t.includes("strike") && (i += " line-through"), e !== "segment" && (o = "#1da1f2", e === "mention" && s.mentionColor ? o = s.mentionColor : e === "interest" && s.interestColor ? o = s.interestColor : e === "link" && s.linkColor && (o = s.linkColor));
300
- let u = "";
301
- return o && (u += `color: ${o}; `), r && (u += `font-weight: ${r}; `), c && (u += `font-style: ${c}; `), i && (u += `text-decoration: ${i}; `), u;
302
- }, Ye = (e, t, s) => {
303
- if (t.length === 0)
304
- return e;
305
- let o = "", r = 0;
306
- return t.forEach((c) => {
307
- r < c.startIndex && (o += e.slice(r, c.startIndex));
308
- const i = e.slice(c.startIndex, c.endIndex), u = nt(c.type, c.marks, s);
309
- o += `<span style="${u}">${i}</span>`, r = c.endIndex;
310
- }), o += e.slice(r), o;
311
- }, rt = (e, t) => {
312
- let s = !1;
313
- e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"), s = !0) : (e.metaKey || e.ctrlKey) && (e.key === "b" ? (t("bold"), s = !0) : e.key === "i" ? (t("italic"), s = !0) : e.key === "u" ? (t("underline"), s = !0) : e.key === "s" && (t("strike"), s = !0)), s && e.preventDefault();
314
- }, he = 128, st = "()[]{}", We = "", ot = new RegExp(
315
- "^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$",
316
- "i"
317
- ), ze = (e, t) => {
318
- const s = je(
319
- e,
320
- t,
321
- st,
322
- We
323
- );
324
- return s?.search.match(ot) ? s : null;
325
- }, me = (e) => (e & he) !== 0, pe = (e, t) => t ? e | he : e & ~he, Re = 32, ct = /^@[a-zA-Z0-9_'-]+$/, it = `.,!?;()[]{}"'<>#`, ge = "@", Ve = (e, t) => {
326
- const s = je(
327
- e,
328
- t,
329
- it,
330
- ge
331
- );
332
- return s?.search.match(ct) ? {
333
- type: "mention",
334
- ...s
335
- } : null;
336
- }, ke = (e) => (e & Re) !== 0, ye = (e, t) => t ? e | Re : e & ~Re, ee = 2, ae = (e) => (e & ee) !== 0, Oe = (e, t) => t ? e | ee : e & ~ee, te = 4, fe = (e) => (e & te) !== 0, Te = (e, t) => t ? e | te : e & ~te, ne = 16, de = (e) => (e & ne) !== 0, Ce = (e, t) => t ? e | ne : e & ~ne, re = 8, Ee = (e) => (e & re) !== 0, Pe = (e, t) => t ? e | re : e & ~re, Fe = (e, t) => {
337
- if (e === t) return null;
338
- let s = 0;
339
- for (; s < e.length && s < t.length && e[s] === t[s]; )
340
- s++;
341
- let o = e.length, r = t.length;
342
- for (; o > s && r > s && e[o - 1] === t[r - 1]; )
343
- o--, r--;
344
- return {
345
- position: s,
346
- deletedLength: o - s,
347
- insertedText: t.slice(s, r)
348
- };
349
- }, xe = (e, t, s, o) => {
350
- let r = t;
351
- for (; r < e.length; ) {
352
- const i = A(e, r);
353
- if (s(i))
354
- e[r] = o(i, !1);
355
- else
356
- break;
357
- r++;
358
- }
359
- let c = t - 1;
360
- for (; c >= 0; ) {
361
- const i = A(e, c);
362
- if (s(i))
363
- e[c] = o(i, !1);
364
- else
365
- break;
366
- c--;
367
- }
368
- return e;
369
- }, Ke = (e, t, s) => {
370
- if (!t) return e;
371
- const { position: o, deletedLength: r, insertedText: c } = t, i = c.length;
372
- let u = [...e];
373
- const f = A(u, o);
374
- if (ke(f) ? u = xe(u, o, ke, ye) : Ie(f) ? u = xe(u, o, Ie, Le) : me(f) && (u = xe(u, o, me, pe)), r > 0 && u.splice(o, r), i > 0) {
375
- let R = 0;
376
- s.bold && (R = Oe(R, !0)), s.italic && (R = Te(R, !0)), s.underline && (R = Pe(R, !0)), s.strike && (R = Ce(R, !0));
377
- const y = new Array(i).fill(R);
378
- u.splice(o, 0, ...y);
379
- }
380
- return u;
381
- }, lt = (e) => /\s/.test(e) || /[\u2000-\u200B\u2028\u2029\u3000]/.test(e), je = (e, t, s, o) => {
382
- if (t <= 0 || t > e.length)
383
- return null;
384
- let r = "", c = t - 1, i = t;
385
- const u = (f) => lt(f) || s.includes(f);
386
- for (let f = c; f >= 0; f--) {
387
- if (u(e[f])) {
388
- c = f + 1;
389
- break;
390
- }
391
- f === 0 && (c = 0), r = e[f] + r;
392
- }
393
- for (let f = i; f < e.length; f++) {
394
- if (u(e[f])) {
395
- i = f;
396
- break;
397
- }
398
- if (o && e[f] === o) {
399
- i = f;
400
- break;
401
- }
402
- f === e.length - 1 && (i = e.length), r = r + e[f];
403
- }
404
- return {
405
- search: e.slice(c, i),
406
- startIndex: c,
407
- endIndex: i
408
- };
409
- }, _e = 64, ut = `.,!?;()[]{}"'<>@`, at = /^#[a-zA-Z0-9-]+$/, Se = "#", Je = (e, t) => {
410
- const s = je(
411
- e,
412
- t,
413
- ut,
414
- Se
415
- );
416
- return s?.search.match(at) ? s : null;
417
- }, Ie = (e) => (e & _e) !== 0, Le = (e, t) => t ? e | _e : e & ~_e, ft = (e, t) => e.find(
418
- (s) => s.startIndex <= t && s.endIndex > t
419
- ), dt = (e, t, s) => {
420
- const o = [];
421
- let r = 0;
422
- for (; r < t.length; ) {
423
- const c = A(t, r);
424
- if (c === 0 || c === 1) {
425
- r++;
426
- continue;
427
- }
428
- const i = r;
429
- let u = r;
430
- for (; u + 1 < t.length && A(t, u + 1) === c; )
431
- u++;
432
- const f = Et(c, s), R = ht(c), y = {
433
- type: f,
434
- startIndex: i,
435
- endIndex: u + 1,
436
- marks: R,
437
- username: f === "mention" ? Ve(e, u)?.search.replace(ge, "") : void 0,
438
- interest: f === "interest" ? Je(e, u)?.search.replace(Se, "").toLowerCase() : void 0,
439
- href: f === "link" ? ze(e, u)?.search : void 0
440
- };
441
- o.push(y), r = u + 1;
442
- }
443
- return o;
444
- }, Et = (e, t) => e & Re && t.mentions ? "mention" : e & _e && t.interests ? "interest" : e & he && t.links ? "link" : (e & (ee | te | re | ne), "segment"), ht = (e) => {
445
- const t = [];
446
- return e & ee && t.push("bold"), e & te && t.push("italic"), e & re && t.push("underline"), e & ne && t.push("strike"), t;
447
- }, A = (e, t) => {
448
- const s = e[t];
449
- return typeof s != "number" ? 0 : s;
450
- }, Ne = (e, t, s) => {
451
- const o = A(e, t);
452
- switch (s) {
453
- case "mention":
454
- return ye(o, !0);
455
- case "interest":
456
- return Le(o, !0);
457
- case "link":
458
- return pe(o, !0);
459
- }
460
- return o;
461
- }, mt = (e, t, s, o) => {
462
- let r = A(e, t);
463
- switch (s) {
464
- case "bold":
465
- r = Oe(r, o);
466
- break;
467
- case "italic":
468
- r = Te(r, o);
469
- break;
470
- case "underline":
471
- r = Pe(r, o);
472
- break;
473
- case "strike":
474
- r = Ce(r, o);
475
- break;
476
- default:
477
- return e;
478
- }
479
- return e[t] = r, e;
480
- }, Rt = (e, t, s) => {
481
- const o = A(e, t);
482
- switch (s) {
483
- case "bold":
484
- return ae(o);
485
- case "italic":
486
- return fe(o);
487
- case "underline":
488
- return Ee(o);
489
- case "strike":
490
- return de(o);
491
- default:
492
- throw Error(`Invalid mark type: ${s}`);
493
- }
494
- }, gt = (e, t, s, o) => {
495
- for (let r = e; r < t; r++)
496
- if (!Rt(o, r, s)) return !1;
497
- return !0;
498
- }, Ue = (e) => ke(e) || Ie(e) || me(e), kt = (e, t, s, o) => {
499
- let r = [...e];
500
- for (; Ue(A(e, t - 1)) && t > 0; )
501
- t--;
502
- for (; Ue(A(e, s)) && s < e.length; )
503
- s++;
504
- let c = !0;
505
- gt(t, s, o, r) && (c = !1);
506
- for (let i = t; i < s; i++)
507
- r = mt(r, i, o, c);
508
- return r;
509
- }, Ae = (e, t) => {
510
- const s = new Array(e.length).fill(0);
511
- for (let o = 0; o < e.length; o++) {
512
- let r = 0;
513
- const c = ft(t, o);
514
- if (c) {
515
- c.type === "mention" ? r = ye(r, !0) : c.type === "interest" ? r = Le(r, !0) : c.type === "link" && (r = pe(r, !0));
516
- for (const i of c.marks)
517
- i === "bold" ? r = Oe(r, !0) : i === "italic" ? r = Te(r, !0) : i === "underline" ? r = Pe(r, !0) : i === "strike" && (r = Ce(r, !0));
518
- }
519
- s[o] = r;
520
- }
521
- return s;
522
- }, _t = {}, St = {}, bt = ({
523
- ref: e,
524
- initialPlainText: t = "",
525
- initialEntities: s = [],
526
- onMentionSearch: o,
527
- onMarkStateChange: r,
528
- onLinkCreated: c,
529
- onInterestCreated: i,
530
- onGetState: u,
531
- options: f = _t,
532
- entityStyles: R = St,
533
- placeholder: y = "",
534
- debug: se = !1,
535
- ...W
536
- }) => {
537
- const w = a.useRef(null), [v, D] = a.useState(t), [O, oe] = a.useState({
538
- bold: !1,
539
- italic: !1,
540
- underline: !1,
541
- strike: !1
542
- }), [T, z] = a.useState(null), [ce, be] = a.useState({ start: 0, end: 0 }), [P, V] = a.useState(!1), [X, q] = a.useState(!1), [we, ie] = a.useState(!1), [x, j] = a.useState(
543
- Ae(t, s)
544
- ), L = a.useMemo(() => dt(v, x, f), [v, x, f]), Y = a.useRef(o), G = a.useRef(r), H = a.useRef(P), J = a.useRef(!1), M = a.useRef({
545
- start: 0,
546
- end: 0
547
- }), $ = a.useRef(null), n = a.useRef(!1), l = a.useRef(null), m = a.useRef(!1), S = a.useRef(null), F = a.useRef(null), K = a.useRef(c), k = a.useRef(i), C = a.useRef(u);
548
- a.useEffect(() => {
549
- Y.current = o;
550
- }, [o]), a.useEffect(() => {
551
- G.current = r;
552
- }, [r]), a.useEffect(() => {
553
- K.current = c;
554
- }, [c]), a.useEffect(() => {
555
- k.current = i;
556
- }, [i]), a.useEffect(() => {
557
- C.current = u;
558
- }, [u]), a.useEffect(() => {
559
- H.current = P;
560
- }, [P]), a.useEffect(() => {
561
- if (l.current && clearTimeout(l.current), T === null) {
562
- Y.current?.(null);
563
- return;
564
- }
565
- return l.current = setTimeout(() => {
566
- Y.current?.(T);
567
- }, 300), () => {
568
- l.current && clearTimeout(l.current);
569
- };
570
- }, [T]), a.useEffect(() => {
571
- G.current?.(O);
572
- }, [O]);
573
- const U = a.useCallback(
574
- (h) => {
575
- if (V(!0), !w.current)
576
- return;
577
- const { start: I, end: b } = M.current;
578
- if (I !== b) {
579
- const d = kt(x, I, b, h);
580
- j(d);
581
- }
582
- oe((d) => {
583
- const g = { ...d };
584
- return h === "bold" ? g.bold = !d.bold : h === "italic" ? g.italic = !d.italic : h === "underline" ? g.underline = !d.underline : h === "strike" && (g.strike = !d.strike), g;
585
- });
586
- },
587
- [x]
588
- );
589
- a.useImperativeHandle(
590
- e,
591
- () => ({
592
- selectEntity: (h, I, b, d) => {
593
- if (!w.current) return;
594
- let g = [...x];
595
- h === "mention" ? d = ge + d : h === "interest" ? d = Se + d : h === "link" && (d = We + d);
596
- const E = v.slice(0, I) + d + v.slice(b), p = Fe(v, E);
597
- p ? g = Ke(x, p, O) : g = Ae(E, L);
598
- for (let _ = I; _ < I + d.length; _++)
599
- g[_] = Ne(g, _, h);
600
- const N = I + d.length;
601
- M.current = {
602
- start: N,
603
- end: N
604
- }, m.current = !0, D(E), j(g), z(null);
605
- },
606
- toggleMark: U,
607
- clear: () => {
608
- D(""), j([]);
609
- },
610
- reset: () => {
611
- D(t), j(Ae(t, s)), z(null);
612
- },
613
- focus: () => {
614
- w.current?.focus();
615
- },
616
- getState: () => (C.current && C.current({
617
- plainText: v,
618
- entities: L,
619
- markState: O
620
- }), {
621
- plainText: v,
622
- entities: L,
623
- markState: O
624
- })
625
- }),
626
- [x, v, L, O, U]
627
- ), a.useEffect(() => {
628
- if (w.current && !X) {
629
- w.current.textContent = v;
630
- const h = Ye(v, L, R);
631
- w.current.innerHTML = h, q(!0);
632
- }
633
- }, []), a.useLayoutEffect(() => {
634
- if (!w.current || !X) return;
635
- const h = m.current ? M.current : De(w.current) ?? M.current;
636
- m.current = !1;
637
- const I = Ye(v, L, R);
638
- n.current = !0, w.current.innerHTML = I, tt(w.current, h), queueMicrotask(() => {
639
- n.current = !1;
640
- });
641
- }, [L, R, X]), a.useEffect(() => {
642
- let { start: h, end: I } = ce, b = null;
643
- if (f.mentions && !ke(A(x, h - 1))) {
644
- const _ = Ve(v, h);
645
- _ && (b = {
646
- type: "mention",
647
- search: _.search.replace(ge, ""),
648
- startIndex: _.startIndex,
649
- endIndex: _.endIndex
650
- });
651
- }
652
- if (b ? (!T || b.startIndex !== T.startIndex || b.endIndex !== T.endIndex || b.search !== T.search) && z(b) : T && z(null), P) return;
653
- let d = !0, g = !0, E = !0, p = !0;
654
- if (h === I)
655
- if (h > 0) {
656
- const _ = A(x, h - 1);
657
- d = ae(_), g = fe(_), E = Ee(_), p = de(_);
658
- } else {
659
- const _ = A(x, h);
660
- d = ae(_), g = fe(_), E = Ee(_), p = de(_);
661
- }
662
- else
663
- for (let _ = h; _ < I; _++) {
664
- const le = A(x, _);
665
- d = ae(le) ? d : !1, g = fe(le) ? g : !1, E = Ee(le) ? E : !1, p = de(le) ? p : !1;
666
- }
667
- oe({
668
- bold: d,
669
- italic: g,
670
- underline: E,
671
- strike: p
672
- });
673
- }, [ce, x, v, P]);
674
- const ve = (h) => {
675
- if (!w.current) return;
676
- if (h.target.textContent.length === 0) {
677
- D(""), j([]), P && V(!1);
678
- return;
679
- }
680
- const I = h.target.innerText || "", b = Fe(v, I);
681
- if (b) {
682
- let d = Ke(x, b, O);
683
- if (b.deletedLength === 0 && b.insertedText === " " && b.position > 0) {
684
- const g = b.position;
685
- if (f.links && !me(A(d, g - 1))) {
686
- const E = ze(I, g);
687
- if (E && E.endIndex === g) {
688
- const p = `${E.startIndex}:${E.endIndex}:${E.search}`;
689
- if (S.current !== p) {
690
- for (let N = E.startIndex; N < E.endIndex; N++)
691
- d[N] = Ne(d, N, "link");
692
- if (S.current = p, K.current) {
693
- const N = {
694
- type: "link",
695
- startIndex: E.startIndex,
696
- endIndex: E.endIndex,
697
- marks: [],
698
- href: E.search
699
- };
700
- K.current(N);
701
- }
702
- }
703
- }
704
- }
705
- if (f.interests && !Ie(A(d, g - 1))) {
706
- const E = Je(I, g);
707
- if (E && E.endIndex === g) {
708
- const p = `${E.startIndex}:${E.endIndex}:${E.search}`;
709
- if (F.current !== p) {
710
- for (let N = E.startIndex; N < E.endIndex; N++)
711
- d[N] = Ne(d, N, "interest");
712
- if (F.current = p, k.current) {
713
- const N = {
714
- type: "interest",
715
- startIndex: E.startIndex,
716
- endIndex: E.endIndex,
717
- marks: [],
718
- interest: E.search.replace(Se, "").toLowerCase()
719
- };
720
- k.current(N);
721
- }
722
- }
723
- }
724
- }
725
- }
726
- j(d), J.current = !0, setTimeout(() => {
727
- J.current = !1;
728
- }, 50);
729
- } else P && V(!1);
730
- D(I);
731
- }, Xe = (h) => {
732
- w.current && rt(h, U);
733
- }, qe = () => {
734
- ie(!0);
735
- }, Ge = () => {
736
- ie(!1);
737
- };
738
- a.useEffect(() => {
739
- const h = () => {
740
- if (n.current) return;
741
- const I = De(w.current) ?? {
742
- start: 0,
743
- end: 0
744
- }, b = M.current;
745
- (I.start !== b.start || I.end !== b.end) && (M.current = I, H.current && !J.current && V(!1), $.current && clearTimeout($.current), $.current = setTimeout(() => {
746
- be(I);
747
- }, 500));
748
- };
749
- return document.addEventListener("selectionchange", h), () => {
750
- document.removeEventListener("selectionchange", h), $.current && clearTimeout($.current);
751
- };
752
- }, []);
753
- const He = v.length === 0 && y && !we;
754
- return /* @__PURE__ */ B.jsxs(B.Fragment, { children: [
755
- /* @__PURE__ */ B.jsxs("div", { style: { position: "relative" }, children: [
756
- /* @__PURE__ */ B.jsx(
757
- "div",
758
- {
759
- ref: w,
760
- style: { ...W.style, position: "relative", zIndex: 2 },
761
- className: W.className,
762
- contentEditable: !0,
763
- onKeyDown: Xe,
764
- onInput: ve,
765
- onFocus: qe,
766
- onBlur: Ge,
767
- role: "textbox",
768
- "aria-multiline": "true",
769
- autoCapitalize: "off",
770
- autoFocus: !1
771
- }
772
- ),
773
- He && /* @__PURE__ */ B.jsx(
774
- "div",
775
- {
776
- style: {
777
- ...W.style,
778
- position: "absolute",
779
- top: 0,
780
- left: 0,
781
- right: 0,
782
- bottom: 0,
783
- color: "#9ca3af",
784
- pointerEvents: "none"
785
- },
786
- "aria-hidden": "true",
787
- children: /* @__PURE__ */ B.jsx("p", { style: { margin: 0 }, children: y })
788
- }
789
- )
790
- ] }),
791
- se && /* @__PURE__ */ B.jsx("div", { style: {}, children: /* @__PURE__ */ B.jsx("pre", { children: JSON.stringify(x) }) })
792
- ] });
793
- };
794
- export {
795
- bt as Editor
1
+ import e from "react";
2
+ //#region \0rolldown/runtime.js
3
+ var t = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), n = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
+ if (typeof require < "u") return require.apply(this, arguments);
5
+ throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
+ }), r = (e) => {
7
+ let t = window.getSelection();
8
+ if (!t || !e) return {
9
+ start: 0,
10
+ end: 0
11
+ };
12
+ if (t.anchorNode && e.contains(t.anchorNode)) {
13
+ let n = t.getRangeAt(0), r = n.cloneRange();
14
+ r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset);
15
+ let i = r.toString().length, a = n.cloneRange();
16
+ return a.selectNodeContents(e), a.setEnd(n.endContainer, n.endOffset), {
17
+ start: i,
18
+ end: a.toString().length
19
+ };
20
+ } else return null;
21
+ }, i = (e, t) => {
22
+ let n = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = 0, i = n.nextNode(), a = null, o = null, s = 0, c = 0;
23
+ for (; i;) {
24
+ let e = r + (i.textContent?.length || 0);
25
+ if (!a && e >= t.start && (a = i, s = t.start - r), !o && e >= t.end) {
26
+ o = i, c = t.end - r;
27
+ break;
28
+ }
29
+ r = e, i = n.nextNode();
30
+ }
31
+ if (a && o) {
32
+ let e = document.createRange();
33
+ e.setStart(a, Math.min(s, a.textContent?.length || 0)), e.setEnd(o, Math.min(c, o.textContent?.length || 0));
34
+ let t = window.getSelection();
35
+ t?.removeAllRanges(), t?.addRange(e);
36
+ }
37
+ }, a = (e, t, n) => {
38
+ let r = "", i = "", a = "", o = "";
39
+ t.includes("bold") && (i = "bold"), t.includes("italic") && (a = "italic"), (t.includes("underline") || e === "link") && (o += "underline"), t.includes("strike") && (o += " line-through"), e !== "segment" && (r = "#1da1f2", e === "mention" && n.mentionColor ? r = n.mentionColor : e === "interest" && n.interestColor ? r = n.interestColor : e === "link" && n.linkColor && (r = n.linkColor));
40
+ let s = "";
41
+ return r && (s += `color: ${r}; `), i && (s += `font-weight: ${i}; `), a && (s += `font-style: ${a}; `), o && (s += `text-decoration: ${o}; `), s;
42
+ }, o = (e, t, n) => {
43
+ if (t.length === 0) return e;
44
+ let r = "", i = 0;
45
+ return t.forEach((t) => {
46
+ i < t.startIndex && (r += e.slice(i, t.startIndex));
47
+ let o = e.slice(t.startIndex, t.endIndex), s = a(t.type, t.marks, n);
48
+ r += `<span style="${s}">${o}</span>`, i = t.endIndex;
49
+ }), r += e.slice(i), r;
50
+ }, s = (e, t) => {
51
+ let n = !1;
52
+ e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), document.execCommand("insertLineBreak"), n = !0) : (e.metaKey || e.ctrlKey) && (e.key === "b" ? (t("bold"), n = !0) : e.key === "i" ? (t("italic"), n = !0) : e.key === "u" ? (t("underline"), n = !0) : e.key === "s" && (t("strike"), n = !0)), n && e.preventDefault();
53
+ }, c = "()[]{}", l = /* @__PURE__ */ RegExp("^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$", "i"), u = (e, t) => {
54
+ let n = k(e, t, c, "");
55
+ return n?.search.match(l) ? n : null;
56
+ }, d = (e) => (e & 128) != 0, f = (e, t) => t ? e | 128 : e & -129, p = /^@[a-zA-Z0-9_'-]+$/, m = ".,!?;()[]{}\"'<>#", h = (e, t) => {
57
+ let n = k(e, t, m, "@");
58
+ return n?.search.match(p) ? {
59
+ type: "mention",
60
+ ...n
61
+ } : null;
62
+ }, g = (e) => (e & 32) != 0, _ = (e, t) => t ? e | 32 : e & -33, v = (e) => (e & 2) != 0, y = (e, t) => t ? e | 2 : e & -3, b = (e) => (e & 4) != 0, x = (e, t) => t ? e | 4 : e & -5, S = (e) => (e & 16) != 0, C = (e, t) => t ? e | 16 : e & -17, w = (e) => (e & 8) != 0, T = (e, t) => t ? e | 8 : e & -9, E = (e, t) => {
63
+ if (e === t) return null;
64
+ let n = 0;
65
+ for (; n < e.length && n < t.length && e[n] === t[n];) n++;
66
+ let r = e.length, i = t.length;
67
+ for (; r > n && i > n && e[r - 1] === t[i - 1];) r--, i--;
68
+ return {
69
+ position: n,
70
+ deletedLength: r - n,
71
+ insertedText: t.slice(n, i)
72
+ };
73
+ }, D = (e, t, n, r) => {
74
+ let i = t;
75
+ for (; i < e.length;) {
76
+ let t = R(e, i);
77
+ if (n(t)) e[i] = r(t, !1);
78
+ else break;
79
+ i++;
80
+ }
81
+ let a = t - 1;
82
+ for (; a >= 0;) {
83
+ let t = R(e, a);
84
+ if (n(t)) e[a] = r(t, !1);
85
+ else break;
86
+ a--;
87
+ }
88
+ return e;
89
+ }, ee = (e, t, n) => {
90
+ if (!t) return e;
91
+ let { position: r, deletedLength: i, insertedText: a } = t, o = a.length, s = [...e], c = R(s, r);
92
+ if (g(c) ? s = D(s, r, g, _) : N(c) ? s = D(s, r, N, P) : d(c) && (s = D(s, r, d, f)), i > 0 && s.splice(r, i), o > 0) {
93
+ let e = 0;
94
+ n.bold && (e = y(e, !0)), n.italic && (e = x(e, !0)), n.underline && (e = T(e, !0)), n.strike && (e = C(e, !0));
95
+ let t = Array(o).fill(e);
96
+ s.splice(r, 0, ...t);
97
+ }
98
+ return s;
99
+ }, O = (e) => /\s/.test(e) || /[\u2000-\u200B\u2028\u2029\u3000]/.test(e), k = (e, t, n, r) => {
100
+ if (t <= 0 || t > e.length) return null;
101
+ let i = "", a = t - 1, o = t, s = (e) => O(e) || n.includes(e);
102
+ for (let t = a; t >= 0; t--) {
103
+ if (s(e[t])) {
104
+ a = t + 1;
105
+ break;
106
+ }
107
+ t === 0 && (a = 0), i = e[t] + i;
108
+ }
109
+ for (let t = o; t < e.length; t++) {
110
+ if (s(e[t])) {
111
+ o = t;
112
+ break;
113
+ }
114
+ if (r && e[t] === r) {
115
+ o = t;
116
+ break;
117
+ }
118
+ t === e.length - 1 && (o = e.length), i += e[t];
119
+ }
120
+ return {
121
+ search: e.slice(a, o),
122
+ startIndex: a,
123
+ endIndex: o
124
+ };
125
+ }, A = ".,!?;()[]{}\"'<>@", j = /^#[a-zA-Z0-9-]+$/, M = (e, t) => {
126
+ let n = k(e, t, A, "#");
127
+ return n?.search.match(j) ? n : null;
128
+ }, N = (e) => (e & 64) != 0, P = (e, t) => t ? e | 64 : e & -65, F = (e, t) => e.find((e) => e.startIndex <= t && e.endIndex > t), I = (e, t, n) => {
129
+ let r = [], i = 0;
130
+ for (; i < t.length;) {
131
+ let a = R(t, i);
132
+ if (a === 0 || a === 1) {
133
+ i++;
134
+ continue;
135
+ }
136
+ let o = i, s = i;
137
+ for (; s + 1 < t.length && R(t, s + 1) === a;) s++;
138
+ let c = L(a, n), l = te(a), d = {
139
+ type: c,
140
+ startIndex: o,
141
+ endIndex: s + 1,
142
+ marks: l,
143
+ username: c === "mention" ? h(e, s)?.search.replace("@", "") : void 0,
144
+ interest: c === "interest" ? M(e, s)?.search.replace("#", "").toLowerCase() : void 0,
145
+ href: c === "link" ? u(e, s)?.search : void 0
146
+ };
147
+ r.push(d), i = s + 1;
148
+ }
149
+ return r;
150
+ }, L = (e, t) => e & 32 && t.mentions ? "mention" : e & 64 && t.interests ? "interest" : e & 128 && t.links ? "link" : (e & 30, "segment"), te = (e) => {
151
+ let t = [];
152
+ return e & 2 && t.push("bold"), e & 4 && t.push("italic"), e & 8 && t.push("underline"), e & 16 && t.push("strike"), t;
153
+ }, R = (e, t) => {
154
+ let n = e[t];
155
+ return typeof n == "number" ? n : 0;
156
+ }, z = (e, t, n) => {
157
+ let r = R(e, t);
158
+ switch (n) {
159
+ case "mention": return _(r, !0);
160
+ case "interest": return P(r, !0);
161
+ case "link": return f(r, !0);
162
+ }
163
+ return r;
164
+ }, B = (e, t, n, r) => {
165
+ let i = R(e, t);
166
+ switch (n) {
167
+ case "bold":
168
+ i = y(i, r);
169
+ break;
170
+ case "italic":
171
+ i = x(i, r);
172
+ break;
173
+ case "underline":
174
+ i = T(i, r);
175
+ break;
176
+ case "strike":
177
+ i = C(i, r);
178
+ break;
179
+ default: return e;
180
+ }
181
+ return e[t] = i, e;
182
+ }, V = (e, t, n) => {
183
+ let r = R(e, t);
184
+ switch (n) {
185
+ case "bold": return v(r);
186
+ case "italic": return b(r);
187
+ case "underline": return w(r);
188
+ case "strike": return S(r);
189
+ default: throw Error(`Invalid mark type: ${n}`);
190
+ }
191
+ }, H = (e, t, n, r) => {
192
+ for (let i = e; i < t; i++) if (!V(r, i, n)) return !1;
193
+ return !0;
194
+ }, ne = (e) => g(e) || N(e) || d(e), re = (e, t, n, r) => {
195
+ let i = [...e];
196
+ for (; ne(R(e, t - 1)) && t > 0;) t--;
197
+ for (; ne(R(e, n)) && n < e.length;) n++;
198
+ let a = !0;
199
+ H(t, n, r, i) && (a = !1);
200
+ for (let e = t; e < n; e++) i = B(i, e, r, a);
201
+ return i;
202
+ }, U = (e, t) => {
203
+ let n = Array(e.length).fill(0);
204
+ for (let r = 0; r < e.length; r++) {
205
+ let e = 0, i = F(t, r);
206
+ if (i) {
207
+ i.type === "mention" ? e = _(e, !0) : i.type === "interest" ? e = P(e, !0) : i.type === "link" && (e = f(e, !0));
208
+ for (let t of i.marks) t === "bold" ? e = y(e, !0) : t === "italic" ? e = x(e, !0) : t === "underline" ? e = T(e, !0) : t === "strike" && (e = C(e, !0));
209
+ }
210
+ n[r] = e;
211
+ }
212
+ return n;
213
+ }, ie = /* @__PURE__ */ t(((e) => {
214
+ var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
215
+ function r(e, n, r) {
216
+ var i = null;
217
+ if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
218
+ else r = n;
219
+ return n = r.ref, {
220
+ $$typeof: t,
221
+ type: e,
222
+ key: i,
223
+ ref: n === void 0 ? null : n,
224
+ props: r
225
+ };
226
+ }
227
+ e.Fragment = n, e.jsx = r, e.jsxs = r;
228
+ })), W = /* @__PURE__ */ t(((e) => {
229
+ process.env.NODE_ENV !== "production" && (function() {
230
+ function t(e) {
231
+ if (e == null) return null;
232
+ if (typeof e == "function") return e.$$typeof === O ? null : e.displayName || e.name || null;
233
+ if (typeof e == "string") return e;
234
+ switch (e) {
235
+ case v: return "Fragment";
236
+ case b: return "Profiler";
237
+ case y: return "StrictMode";
238
+ case w: return "Suspense";
239
+ case T: return "SuspenseList";
240
+ case ee: return "Activity";
241
+ }
242
+ if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
243
+ case _: return "Portal";
244
+ case S: return e.displayName || "Context";
245
+ case x: return (e._context.displayName || "Context") + ".Consumer";
246
+ case C:
247
+ var n = e.render;
248
+ return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
249
+ case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
250
+ case D:
251
+ n = e._payload, e = e._init;
252
+ try {
253
+ return t(e(n));
254
+ } catch {}
255
+ }
256
+ return null;
257
+ }
258
+ function r(e) {
259
+ return "" + e;
260
+ }
261
+ function i(e) {
262
+ try {
263
+ r(e);
264
+ var t = !1;
265
+ } catch {
266
+ t = !0;
267
+ }
268
+ if (t) {
269
+ t = console;
270
+ var n = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
271
+ return n.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), r(e);
272
+ }
273
+ }
274
+ function a(e) {
275
+ if (e === v) return "<>";
276
+ if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
277
+ try {
278
+ var n = t(e);
279
+ return n ? "<" + n + ">" : "<...>";
280
+ } catch {
281
+ return "<...>";
282
+ }
283
+ }
284
+ function o() {
285
+ var e = k.A;
286
+ return e === null ? null : e.getOwner();
287
+ }
288
+ function s() {
289
+ return Error("react-stack-top-frame");
290
+ }
291
+ function c(e) {
292
+ if (A.call(e, "key")) {
293
+ var t = Object.getOwnPropertyDescriptor(e, "key").get;
294
+ if (t && t.isReactWarning) return !1;
295
+ }
296
+ return e.key !== void 0;
297
+ }
298
+ function l(e, t) {
299
+ function n() {
300
+ N || (N = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
301
+ }
302
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
303
+ get: n,
304
+ configurable: !0
305
+ });
306
+ }
307
+ function u() {
308
+ var e = t(this.type);
309
+ return P[e] || (P[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
310
+ }
311
+ function d(e, t, n, r, i, a) {
312
+ var o = n.ref;
313
+ return e = {
314
+ $$typeof: g,
315
+ type: e,
316
+ key: t,
317
+ props: n,
318
+ _owner: r
319
+ }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
320
+ enumerable: !1,
321
+ value: null
322
+ }) : Object.defineProperty(e, "ref", {
323
+ enumerable: !1,
324
+ get: u
325
+ }), e._store = {}, Object.defineProperty(e._store, "validated", {
326
+ configurable: !1,
327
+ enumerable: !1,
328
+ writable: !0,
329
+ value: 0
330
+ }), Object.defineProperty(e, "_debugInfo", {
331
+ configurable: !1,
332
+ enumerable: !1,
333
+ writable: !0,
334
+ value: null
335
+ }), Object.defineProperty(e, "_debugStack", {
336
+ configurable: !1,
337
+ enumerable: !1,
338
+ writable: !0,
339
+ value: i
340
+ }), Object.defineProperty(e, "_debugTask", {
341
+ configurable: !1,
342
+ enumerable: !1,
343
+ writable: !0,
344
+ value: a
345
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
346
+ }
347
+ function f(e, n, r, a, s, u) {
348
+ var f = n.children;
349
+ if (f !== void 0) if (a) if (j(f)) {
350
+ for (a = 0; a < f.length; a++) p(f[a]);
351
+ Object.freeze && Object.freeze(f);
352
+ } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
353
+ else p(f);
354
+ if (A.call(n, "key")) {
355
+ f = t(e);
356
+ var m = Object.keys(n).filter(function(e) {
357
+ return e !== "key";
358
+ });
359
+ a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", L[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), L[f + a] = !0);
360
+ }
361
+ if (f = null, r !== void 0 && (i(r), f = "" + r), c(n) && (i(n.key), f = "" + n.key), "key" in n) for (var h in r = {}, n) h !== "key" && (r[h] = n[h]);
362
+ else r = n;
363
+ return f && l(r, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, r, o(), s, u);
364
+ }
365
+ function p(e) {
366
+ m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
367
+ }
368
+ function m(e) {
369
+ return typeof e == "object" && !!e && e.$$typeof === g;
370
+ }
371
+ var h = n("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), ee = Symbol.for("react.activity"), O = Symbol.for("react.client.reference"), k = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, A = Object.prototype.hasOwnProperty, j = Array.isArray, M = console.createTask ? console.createTask : function() {
372
+ return null;
373
+ };
374
+ h = { react_stack_bottom_frame: function(e) {
375
+ return e();
376
+ } };
377
+ var N, P = {}, F = h.react_stack_bottom_frame.bind(h, s)(), I = M(a(s)), L = {};
378
+ e.Fragment = v, e.jsx = function(e, t, n) {
379
+ var r = 1e4 > k.recentlyCreatedOwnerStacks++;
380
+ return f(e, t, n, !1, r ? Error("react-stack-top-frame") : F, r ? M(a(e)) : I);
381
+ }, e.jsxs = function(e, t, n) {
382
+ var r = 1e4 > k.recentlyCreatedOwnerStacks++;
383
+ return f(e, t, n, !0, r ? Error("react-stack-top-frame") : F, r ? M(a(e)) : I);
384
+ };
385
+ })();
386
+ })), G = (/* @__PURE__ */ t(((e, t) => {
387
+ process.env.NODE_ENV === "production" ? t.exports = ie() : t.exports = W();
388
+ })))(), ae = {}, oe = {}, K = ({ ref: t, initialPlainText: n = "", initialEntities: a = [], onMentionSearch: c, onMarkStateChange: l, onLinkCreated: f, onInterestCreated: p, onGetState: m, options: _ = ae, entityStyles: y = oe, placeholder: x = "", debug: C = !1, ...T }) => {
389
+ let D = e.useRef(null), [O, k] = e.useState(n), [A, j] = e.useState({
390
+ bold: !1,
391
+ italic: !1,
392
+ underline: !1,
393
+ strike: !1
394
+ }), [P, F] = e.useState(null), [L, te] = e.useState({
395
+ start: 0,
396
+ end: 0
397
+ }), [B, V] = e.useState(!1), [H, ne] = e.useState(!1), [ie, W] = e.useState(!1), [K, q] = e.useState(U(n, a)), J = e.useMemo(() => I(O, K, _), [
398
+ O,
399
+ K,
400
+ _
401
+ ]), Y = e.useRef(c), se = e.useRef(l), ce = e.useRef(B), X = e.useRef(!1), Z = e.useRef({
402
+ start: 0,
403
+ end: 0
404
+ }), Q = e.useRef(null), le = e.useRef(!1), $ = e.useRef(null), ue = e.useRef(!1), de = e.useRef(null), fe = e.useRef(null), pe = e.useRef(f), me = e.useRef(p), he = e.useRef(m);
405
+ e.useEffect(() => {
406
+ Y.current = c;
407
+ }, [c]), e.useEffect(() => {
408
+ se.current = l;
409
+ }, [l]), e.useEffect(() => {
410
+ pe.current = f;
411
+ }, [f]), e.useEffect(() => {
412
+ me.current = p;
413
+ }, [p]), e.useEffect(() => {
414
+ he.current = m;
415
+ }, [m]), e.useEffect(() => {
416
+ ce.current = B;
417
+ }, [B]), e.useEffect(() => {
418
+ if ($.current && clearTimeout($.current), P === null) {
419
+ Y.current?.(null);
420
+ return;
421
+ }
422
+ return $.current = setTimeout(() => {
423
+ Y.current?.(P);
424
+ }, 300), () => {
425
+ $.current && clearTimeout($.current);
426
+ };
427
+ }, [P]), e.useEffect(() => {
428
+ se.current?.(A);
429
+ }, [A]);
430
+ let ge = e.useCallback((e) => {
431
+ if (V(!0), !D.current) return;
432
+ let { start: t, end: n } = Z.current;
433
+ t !== n && q(re(K, t, n, e)), j((t) => {
434
+ let n = { ...t };
435
+ return e === "bold" ? n.bold = !t.bold : e === "italic" ? n.italic = !t.italic : e === "underline" ? n.underline = !t.underline : e === "strike" && (n.strike = !t.strike), n;
436
+ });
437
+ }, [K]);
438
+ e.useImperativeHandle(t, () => ({
439
+ selectEntity: (e, t, n, r) => {
440
+ if (!D.current) return;
441
+ let i = [...K];
442
+ e === "mention" ? r = "@" + r : e === "interest" ? r = "#" + r : e === "link" && (r = "" + r);
443
+ let a = O.slice(0, t) + r + O.slice(n), o = E(O, a);
444
+ i = o ? ee(K, o, A) : U(a, J);
445
+ for (let n = t; n < t + r.length; n++) i[n] = z(i, n, e);
446
+ let s = t + r.length;
447
+ Z.current = {
448
+ start: s,
449
+ end: s
450
+ }, ue.current = !0, k(a), q(i), F(null);
451
+ },
452
+ toggleMark: ge,
453
+ clear: () => {
454
+ k(""), q([]);
455
+ },
456
+ reset: () => {
457
+ k(n), q(U(n, a)), F(null);
458
+ },
459
+ focus: () => {
460
+ D.current?.focus();
461
+ },
462
+ getState: () => (he.current && he.current({
463
+ plainText: O,
464
+ entities: J,
465
+ markState: A
466
+ }), {
467
+ plainText: O,
468
+ entities: J,
469
+ markState: A
470
+ })
471
+ }), [
472
+ K,
473
+ O,
474
+ J,
475
+ A,
476
+ ge
477
+ ]), e.useEffect(() => {
478
+ if (D.current && !H) {
479
+ D.current.textContent = O;
480
+ let e = o(O, J, y);
481
+ D.current.innerHTML = e, ne(!0);
482
+ }
483
+ }, []), e.useLayoutEffect(() => {
484
+ if (!D.current || !H) return;
485
+ let e = ue.current ? Z.current : r(D.current) ?? Z.current;
486
+ ue.current = !1;
487
+ let t = o(O, J, y);
488
+ le.current = !0, D.current.innerHTML = t, i(D.current, e), queueMicrotask(() => {
489
+ le.current = !1;
490
+ });
491
+ }, [
492
+ J,
493
+ y,
494
+ H
495
+ ]), e.useEffect(() => {
496
+ let { start: e, end: t } = L, n = null;
497
+ if (_.mentions && !g(R(K, e - 1))) {
498
+ let t = h(O, e);
499
+ t && (n = {
500
+ type: "mention",
501
+ search: t.search.replace("@", ""),
502
+ startIndex: t.startIndex,
503
+ endIndex: t.endIndex
504
+ });
505
+ }
506
+ if (n ? (!P || n.startIndex !== P.startIndex || n.endIndex !== P.endIndex || n.search !== P.search) && F(n) : P && F(null), B) return;
507
+ let r = !0, i = !0, a = !0, o = !0;
508
+ if (e === t) if (e > 0) {
509
+ let t = R(K, e - 1);
510
+ r = v(t), i = b(t), a = w(t), o = S(t);
511
+ } else {
512
+ let t = R(K, e);
513
+ r = v(t), i = b(t), a = w(t), o = S(t);
514
+ }
515
+ else for (let n = e; n < t; n++) {
516
+ let e = R(K, n);
517
+ r = v(e) ? r : !1, i = b(e) ? i : !1, a = w(e) ? a : !1, o = S(e) ? o : !1;
518
+ }
519
+ j({
520
+ bold: r,
521
+ italic: i,
522
+ underline: a,
523
+ strike: o
524
+ });
525
+ }, [
526
+ L,
527
+ K,
528
+ O,
529
+ B
530
+ ]);
531
+ let _e = (e) => {
532
+ if (!D.current) return;
533
+ let t = e.currentTarget;
534
+ if (t.textContent?.length === 0) {
535
+ k(""), q([]), B && V(!1);
536
+ return;
537
+ }
538
+ let n = t.innerText || "", r = E(O, n);
539
+ if (r) {
540
+ let e = ee(K, r, A);
541
+ if (r.deletedLength === 0 && r.insertedText === " " && r.position > 0) {
542
+ let t = r.position;
543
+ if (_.links && !d(R(e, t - 1))) {
544
+ let r = u(n, t);
545
+ if (r && r.endIndex === t) {
546
+ let t = `${r.startIndex}:${r.endIndex}:${r.search}`;
547
+ if (de.current !== t) {
548
+ for (let t = r.startIndex; t < r.endIndex; t++) e[t] = z(e, t, "link");
549
+ if (de.current = t, pe.current) {
550
+ let e = {
551
+ type: "link",
552
+ startIndex: r.startIndex,
553
+ endIndex: r.endIndex,
554
+ marks: [],
555
+ href: r.search
556
+ };
557
+ pe.current(e);
558
+ }
559
+ }
560
+ }
561
+ }
562
+ if (_.interests && !N(R(e, t - 1))) {
563
+ let r = M(n, t);
564
+ if (r && r.endIndex === t) {
565
+ let t = `${r.startIndex}:${r.endIndex}:${r.search}`;
566
+ if (fe.current !== t) {
567
+ for (let t = r.startIndex; t < r.endIndex; t++) e[t] = z(e, t, "interest");
568
+ if (fe.current = t, me.current) {
569
+ let e = {
570
+ type: "interest",
571
+ startIndex: r.startIndex,
572
+ endIndex: r.endIndex,
573
+ marks: [],
574
+ interest: r.search.replace("#", "").toLowerCase()
575
+ };
576
+ me.current(e);
577
+ }
578
+ }
579
+ }
580
+ }
581
+ }
582
+ q(e), X.current = !0, setTimeout(() => {
583
+ X.current = !1;
584
+ }, 50);
585
+ } else B && V(!1);
586
+ k(n);
587
+ }, ve = (e) => {
588
+ D.current && s(e, ge);
589
+ }, ye = () => {
590
+ W(!0);
591
+ }, be = () => {
592
+ W(!1);
593
+ };
594
+ e.useEffect(() => {
595
+ let e = () => {
596
+ if (le.current) return;
597
+ let e = r(D.current) ?? {
598
+ start: 0,
599
+ end: 0
600
+ }, t = Z.current;
601
+ (e.start !== t.start || e.end !== t.end) && (Z.current = e, ce.current && !X.current && V(!1), Q.current && clearTimeout(Q.current), Q.current = setTimeout(() => {
602
+ te(e);
603
+ }, 500));
604
+ };
605
+ return document.addEventListener("selectionchange", e), () => {
606
+ document.removeEventListener("selectionchange", e), Q.current && clearTimeout(Q.current);
607
+ };
608
+ }, []);
609
+ let xe = O.length === 0 && x && !ie;
610
+ return /* @__PURE__ */ (0, G.jsxs)(G.Fragment, { children: [/* @__PURE__ */ (0, G.jsxs)("div", {
611
+ style: { position: "relative" },
612
+ children: [/* @__PURE__ */ (0, G.jsx)("div", {
613
+ ref: D,
614
+ style: {
615
+ ...T.style,
616
+ position: "relative",
617
+ zIndex: 2
618
+ },
619
+ className: T.className,
620
+ contentEditable: !0,
621
+ onKeyDown: ve,
622
+ onInput: _e,
623
+ onFocus: ye,
624
+ onBlur: be,
625
+ role: "textbox",
626
+ "aria-multiline": "true",
627
+ autoCapitalize: "off",
628
+ autoFocus: !1
629
+ }), xe && /* @__PURE__ */ (0, G.jsx)("div", {
630
+ style: {
631
+ ...T.style,
632
+ position: "absolute",
633
+ top: 0,
634
+ left: 0,
635
+ right: 0,
636
+ bottom: 0,
637
+ color: "#9ca3af",
638
+ pointerEvents: "none"
639
+ },
640
+ "aria-hidden": "true",
641
+ children: /* @__PURE__ */ (0, G.jsx)("p", {
642
+ style: { margin: 0 },
643
+ children: x
644
+ })
645
+ })]
646
+ }), C && /* @__PURE__ */ (0, G.jsx)("div", {
647
+ style: {},
648
+ children: /* @__PURE__ */ (0, G.jsx)("pre", { children: JSON.stringify(K) })
649
+ })] });
796
650
  };
651
+ //#endregion
652
+ export { K as Editor };