@connectedxm/entity-editor 0.0.5 → 0.0.9

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