@connectedxm/entity-editor 0.0.4 → 0.0.8

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