@connectedxm/entity-editor 0.0.4 → 0.0.5

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,14 +1,5 @@
1
1
  import A, { useState as $e, useRef as me, useEffect as Ye } from "react";
2
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
3
  var Ae;
13
4
  function Fe() {
14
5
  if (Ae) return x;
@@ -31,16 +22,7 @@ function Fe() {
31
22
  }
32
23
  return x.Fragment = t, x.jsx = n, x.jsxs = n, x;
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
- */
25
+ var L = {};
44
26
  var Oe;
45
27
  function We() {
46
28
  return Oe || (Oe = 1, process.env.NODE_ENV !== "production" && (function() {
@@ -67,7 +49,7 @@ function We() {
67
49
  switch (typeof r.tag == "number" && console.error(
68
50
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
51
  ), r.$$typeof) {
70
- case v:
52
+ case b:
71
53
  return "Portal";
72
54
  case K:
73
55
  return (r.displayName || "Context") + ".Provider";
@@ -76,7 +58,7 @@ function We() {
76
58
  case ue:
77
59
  var l = r.render;
78
60
  return r = r.displayName, r || (r = l.displayName || l.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
79
- case S:
61
+ case w:
80
62
  return l = r.displayName || null, l !== null ? l : e(r.type) || "Memo";
81
63
  case I:
82
64
  l = r._payload, r = r._init;
@@ -99,11 +81,11 @@ function We() {
99
81
  }
100
82
  if (l) {
101
83
  l = console;
102
- var d = l.error, g = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
84
+ var d = l.error, R = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
103
85
  return d.call(
104
86
  l,
105
87
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
- g
88
+ R
107
89
  ), t(r);
108
90
  }
109
91
  }
@@ -150,13 +132,13 @@ function We() {
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
133
  )), r = this.props.ref, r !== void 0 ? r : null;
152
134
  }
153
- function m(r, l, d, g, R, w, de, Ee) {
154
- return d = w.ref, r = {
135
+ function m(r, l, d, R, _, v, de, Ee) {
136
+ return d = v.ref, r = {
155
137
  $$typeof: j,
156
138
  type: r,
157
139
  key: l,
158
- props: w,
159
- _owner: R
140
+ props: v,
141
+ _owner: _
160
142
  }, (d !== void 0 ? d : null) !== null ? Object.defineProperty(r, "ref", {
161
143
  enumerable: !1,
162
144
  get: f
@@ -182,13 +164,13 @@ function We() {
182
164
  value: Ee
183
165
  }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
184
166
  }
185
- function N(r, l, d, g, R, w, de, Ee) {
167
+ function N(r, l, d, R, _, v, de, Ee) {
186
168
  var k = l.children;
187
169
  if (k !== void 0)
188
- if (g)
170
+ if (R)
189
171
  if (fe(k)) {
190
- for (g = 0; g < k.length; g++)
191
- p(k[g]);
172
+ for (R = 0; R < k.length; R++)
173
+ p(k[R]);
192
174
  Object.freeze && Object.freeze(k);
193
175
  } else
194
176
  console.error(
@@ -197,21 +179,21 @@ function We() {
197
179
  else p(k);
198
180
  if (G.call(l, "key")) {
199
181
  k = e(r);
200
- var P = Object.keys(l).filter(function(Le) {
201
- return Le !== "key";
182
+ var P = Object.keys(l).filter(function(De) {
183
+ return De !== "key";
202
184
  });
203
- g = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", h[k + g] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
185
+ R = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", h[k + R] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
204
186
  `A props object containing a "key" prop is being spread into JSX:
205
187
  let props = %s;
206
188
  <%s {...props} />
207
189
  React keys must be passed directly to JSX without using spread:
208
190
  let props = %s;
209
191
  <%s key={someKey} {...props} />`,
210
- g,
192
+ R,
211
193
  k,
212
194
  P,
213
195
  k
214
- ), h[k + g] = !0);
196
+ ), h[k + R] = !0);
215
197
  }
216
198
  if (k = null, d !== void 0 && (n(d), k = "" + d), c(l) && (n(l.key), k = "" + l.key), "key" in l) {
217
199
  d = {};
@@ -224,8 +206,8 @@ React keys must be passed directly to JSX without using spread:
224
206
  ), m(
225
207
  r,
226
208
  k,
227
- w,
228
- R,
209
+ v,
210
+ _,
229
211
  o(),
230
212
  d,
231
213
  de,
@@ -235,58 +217,58 @@ React keys must be passed directly to JSX without using spread:
235
217
  function p(r) {
236
218
  typeof r == "object" && r !== null && r.$$typeof === j && r._store && (r._store.validated = 1);
237
219
  }
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() {
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() {
239
221
  return null;
240
222
  };
241
- C = {
223
+ y = {
242
224
  react_stack_bottom_frame: function(r) {
243
225
  return r();
244
226
  }
245
227
  };
246
- var J, a = {}, _ = C.react_stack_bottom_frame.bind(
247
- C,
228
+ var J, a = {}, g = y.react_stack_bottom_frame.bind(
229
+ y,
248
230
  i
249
231
  )(), E = T(s(i)), h = {};
250
- D.Fragment = O, D.jsx = function(r, l, d, g, R) {
251
- var w = 1e4 > M.recentlyCreatedOwnerStacks++;
232
+ L.Fragment = O, L.jsx = function(r, l, d, R, _) {
233
+ var v = 1e4 > M.recentlyCreatedOwnerStacks++;
252
234
  return N(
253
235
  r,
254
236
  l,
255
237
  d,
256
238
  !1,
257
- g,
258
239
  R,
259
- w ? Error("react-stack-top-frame") : _,
260
- w ? T(s(r)) : E
240
+ _,
241
+ v ? Error("react-stack-top-frame") : g,
242
+ v ? T(s(r)) : E
261
243
  );
262
- }, D.jsxs = function(r, l, d, g, R) {
263
- var w = 1e4 > M.recentlyCreatedOwnerStacks++;
244
+ }, L.jsxs = function(r, l, d, R, _) {
245
+ var v = 1e4 > M.recentlyCreatedOwnerStacks++;
264
246
  return N(
265
247
  r,
266
248
  l,
267
249
  d,
268
250
  !0,
269
- g,
270
251
  R,
271
- w ? Error("react-stack-top-frame") : _,
272
- w ? T(s(r)) : E
252
+ _,
253
+ v ? Error("react-stack-top-frame") : g,
254
+ v ? T(s(r)) : E
273
255
  );
274
256
  };
275
- })()), D;
257
+ })()), L;
276
258
  }
277
259
  var Ie;
278
260
  function Ke() {
279
261
  return Ie || (Ie = 1, process.env.NODE_ENV === "production" ? X.exports = Fe() : X.exports = We()), X.exports;
280
262
  }
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);
263
+ var C = Ke();
264
+ const Ce = (e) => {
265
+ const t = window.getSelection();
266
+ if (!t || !e) return { start: 0, end: 0 };
267
+ 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);
288
270
  const o = s.toString().length, i = n.cloneRange();
289
- i.selectNodeContents(t), i.setEnd(n.endContainer, n.endOffset);
271
+ i.selectNodeContents(e), i.setEnd(n.endContainer, n.endOffset);
290
272
  const c = i.toString().length;
291
273
  return { start: o, end: c };
292
274
  } else
@@ -319,7 +301,7 @@ const ye = () => {
319
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));
320
302
  let u = "";
321
303
  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) => {
304
+ }, ye = (e, t, n) => {
323
305
  if (t.length === 0)
324
306
  return e;
325
307
  let s = "", o = 0;
@@ -345,7 +327,7 @@ const ye = () => {
345
327
  type: "link",
346
328
  ...n
347
329
  } : 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) => {
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) => {
349
331
  const n = ve(
350
332
  e,
351
333
  t,
@@ -356,7 +338,7 @@ const ye = () => {
356
338
  type: "mention",
357
339
  ...n
358
340
  } : 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) => {
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) => {
360
342
  if (e === t) return null;
361
343
  let n = 0;
362
344
  for (; n < e.length && n < t.length && e[n] === t[n]; )
@@ -372,7 +354,7 @@ const ye = () => {
372
354
  }, ge = (e, t, n, s) => {
373
355
  let o = t;
374
356
  for (; o < e.length; ) {
375
- const c = b(e, o);
357
+ const c = S(e, o);
376
358
  if (n(c))
377
359
  e[o] = s(c, !1);
378
360
  else
@@ -381,7 +363,7 @@ const ye = () => {
381
363
  }
382
364
  let i = t - 1;
383
365
  for (; i >= 0; ) {
384
- const c = b(e, i);
366
+ const c = S(e, i);
385
367
  if (n(c))
386
368
  e[i] = s(c, !1);
387
369
  else
@@ -393,10 +375,10 @@ const ye = () => {
393
375
  if (!t) return e;
394
376
  const { position: s, deletedLength: o, insertedText: i } = t, c = i.length;
395
377
  let u = [...e];
396
- const f = b(u, s);
378
+ const f = S(u, s);
397
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) {
398
380
  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));
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));
400
382
  const N = new Array(c).fill(m);
401
383
  u.splice(s, 0, ...N);
402
384
  }
@@ -446,21 +428,21 @@ const ye = () => {
446
428
  const s = [];
447
429
  let o = 0;
448
430
  for (; o < t.length; ) {
449
- const i = b(t, o);
431
+ const i = S(t, o);
450
432
  if (i === 0 || i === 1) {
451
433
  o++;
452
434
  continue;
453
435
  }
454
436
  const c = o;
455
437
  let u = o;
456
- for (; u + 1 < t.length && b(t, u + 1) === i; )
438
+ for (; u + 1 < t.length && S(t, u + 1) === i; )
457
439
  u++;
458
440
  const f = rt(i, n), m = nt(i), N = {
459
441
  type: f,
460
442
  startIndex: c,
461
443
  endIndex: u + 1,
462
444
  marks: m,
463
- username: f === "mention" ? De(e, u)?.search.replace(ne, "") : void 0,
445
+ username: f === "mention" ? Le(e, u)?.search.replace(ne, "") : void 0,
464
446
  interest: f === "interest" ? Be(e, u)?.search.replace(
465
447
  ie,
466
448
  ""
@@ -470,14 +452,14 @@ const ye = () => {
470
452
  s.push(N), o = u + 1;
471
453
  }
472
454
  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) => {
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) => {
474
456
  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) => {
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) => {
477
459
  const n = e[t];
478
460
  return typeof n != "number" ? 0 : n;
479
461
  }, ot = (e, t, n) => {
480
- const s = b(e, t);
462
+ const s = S(e, t);
481
463
  switch (n) {
482
464
  case "mention":
483
465
  return _e(s, !0);
@@ -488,26 +470,26 @@ const ye = () => {
488
470
  }
489
471
  return s;
490
472
  }, st = (e, t, n, s) => {
491
- let o = b(e, t);
473
+ let o = S(e, t);
492
474
  switch (n) {
493
475
  case "bold":
494
476
  o = ke(o, s);
495
477
  break;
496
478
  case "italic":
497
- o = be(o, s);
479
+ o = Se(o, s);
498
480
  break;
499
481
  case "underline":
500
482
  o = we(o, s);
501
483
  break;
502
484
  case "strike":
503
- o = Se(o, s);
485
+ o = be(o, s);
504
486
  break;
505
487
  default:
506
488
  return e;
507
489
  }
508
490
  return e[t] = o, e;
509
491
  }, it = (e, t, n) => {
510
- const s = b(e, t);
492
+ const s = S(e, t);
511
493
  switch (n) {
512
494
  case "bold":
513
495
  return q(s);
@@ -526,9 +508,9 @@ const ye = () => {
526
508
  return !0;
527
509
  }, pe = (e) => oe(e) || ce(e) || te(e), lt = (e, t, n, s) => {
528
510
  let o = [...e];
529
- for (; pe(b(e, t - 1)) && t > 0; )
511
+ for (; pe(S(e, t - 1)) && t > 0; )
530
512
  t--;
531
- for (; pe(b(e, n)) && n < e.length; )
513
+ for (; pe(S(e, n)) && n < e.length; )
532
514
  n++;
533
515
  let i = !0;
534
516
  ct(t, n, s, o) && (i = !1);
@@ -543,7 +525,7 @@ const ye = () => {
543
525
  if (i) {
544
526
  i.type === "mention" ? o = _e(o, !0) : i.type === "interest" ? o = Ne(o, !0) : i.type === "link" && (o = Re(o, !0));
545
527
  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));
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));
547
529
  }
548
530
  n[s] = o;
549
531
  }
@@ -568,21 +550,21 @@ const ye = () => {
568
550
  options: m = {},
569
551
  entityStyles: N = {},
570
552
  placeholder: p = "",
571
- debug: C = !1,
553
+ debug: y = !1,
572
554
  ...j
573
555
  }) => {
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(
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(
575
557
  Me(t, s)
576
558
  );
577
559
  e.current = {
578
- selectEntity: (a, _, E, h) => {
579
- if (!v.current) return;
580
- let r = [...S];
560
+ selectEntity: (a, g, E, h) => {
561
+ if (!b.current) return;
562
+ let r = [...w];
581
563
  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);
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);
586
568
  n(l), I(r), f(null);
587
569
  },
588
570
  toggleMark: (a) => {
@@ -592,33 +574,33 @@ const ye = () => {
592
574
  n(""), I([]), o([]);
593
575
  }
594
576
  }, 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);
577
+ if (b.current) {
578
+ b.current.textContent = t;
579
+ const a = ye(t, s, N);
580
+ b.current.innerHTML = a, K || ue(!0);
599
581
  }
600
582
  }, []), 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]);
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]);
605
587
  const z = ut(O, 500);
606
588
  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;
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;
609
591
  let h = !0, r = !0, l = !0, d = !0;
610
- if (a === _)
592
+ if (a === g)
611
593
  if (a > 0) {
612
- const R = b(S, a - 1);
613
- h = q(R), r = H(R), l = Q(R), d = Z(R);
594
+ const _ = S(w, a - 1);
595
+ h = q(_), r = H(_), l = Q(_), d = Z(_);
614
596
  } else {
615
- const R = b(S, a);
616
- h = q(R), r = H(R), l = Q(R), d = Z(R);
597
+ const _ = S(w, a);
598
+ h = q(_), r = H(_), l = Q(_), d = Z(_);
617
599
  }
618
600
  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;
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;
622
604
  }
623
605
  c({
624
606
  bold: h,
@@ -628,33 +610,33 @@ const ye = () => {
628
610
  });
629
611
  }, [z]);
630
612
  const V = (a) => {
631
- if (W(!0), !v.current)
613
+ if (W(!0), !b.current)
632
614
  return;
633
- const { start: _, end: E } = O;
634
- if (_ !== E) {
635
- const r = lt(S, _, E, a);
615
+ const { start: g, end: E } = O;
616
+ if (g !== E) {
617
+ const r = lt(w, g, E, a);
636
618
  I(r);
637
619
  }
638
620
  const h = { ...i };
639
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);
640
622
  }, M = (a) => {
641
- if (!v.current) return;
623
+ if (!b.current) return;
642
624
  if (F && W(!1), a.target.textContent.length === 0) {
643
625
  n(""), I([]), o([]);
644
626
  return;
645
627
  }
646
- const _ = a.target.innerText || "", E = je(t, _);
628
+ const g = a.target.innerText || "", E = je(t, g);
647
629
  if (E) {
648
630
  const h = Pe(
649
- S,
631
+ w,
650
632
  E,
651
633
  i
652
634
  );
653
635
  I(h);
654
636
  }
655
- n(_);
637
+ n(g);
656
638
  }, G = (a) => {
657
- v.current && Ve(a, V);
639
+ b.current && Ve(a, V);
658
640
  }, fe = () => {
659
641
  U(!0);
660
642
  }, T = () => {
@@ -662,21 +644,20 @@ const ye = () => {
662
644
  };
663
645
  A.useEffect(() => {
664
646
  const a = () => {
665
- const _ = ye() ?? { start: 0, end: 0 };
666
- (_.start !== O.start || _.end !== O.end) && le(_);
647
+ const g = Ce(b.current);
648
+ g && (g.start !== O.start || g.end !== O.end) && le(g);
667
649
  };
668
650
  return document.addEventListener("selectionchange", a), () => {
669
651
  document.removeEventListener("selectionchange", a);
670
652
  };
671
653
  }, []);
672
654
  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(
655
+ return /* @__PURE__ */ C.jsxs(C.Fragment, { children: [
656
+ /* @__PURE__ */ C.jsxs("div", { style: { position: "relative" }, children: [
657
+ /* @__PURE__ */ C.jsx(
676
658
  "div",
677
659
  {
678
- id: "entity-editor",
679
- ref: v,
660
+ ref: b,
680
661
  style: { ...j.style, position: "relative", zIndex: 2 },
681
662
  className: j.className,
682
663
  contentEditable: !0,
@@ -688,7 +669,7 @@ const ye = () => {
688
669
  "aria-multiline": "true"
689
670
  }
690
671
  ),
691
- J && /* @__PURE__ */ y.jsx(
672
+ J && /* @__PURE__ */ C.jsx(
692
673
  "div",
693
674
  {
694
675
  style: {
@@ -701,11 +682,11 @@ const ye = () => {
701
682
  color: "#9ca3af"
702
683
  },
703
684
  "aria-hidden": "true",
704
- children: /* @__PURE__ */ y.jsx("p", { children: p })
685
+ children: /* @__PURE__ */ C.jsx("p", { children: p })
705
686
  }
706
687
  )
707
688
  ] }),
708
- C && /* @__PURE__ */ y.jsx("div", { style: {}, children: /* @__PURE__ */ y.jsx("pre", { children: JSON.stringify(S) }) })
689
+ y && /* @__PURE__ */ C.jsx("div", { style: {}, children: /* @__PURE__ */ C.jsx("pre", { children: JSON.stringify(w) }) })
709
690
  ] });
710
691
  };
711
692
  export {
@@ -1,4 +1,4 @@
1
1
  import { Entity, SelectionRange, StyleOptions } from '../interfaces';
2
- export declare const getSelection: () => SelectionRange | null;
2
+ export declare const getSelection: (editableDiv: HTMLElement | null) => SelectionRange | null;
3
3
  export declare const setSelection: (div: HTMLDivElement, selectionRange: SelectionRange) => void;
4
4
  export declare const buildHtml: (plainText: string, entities: Entity[], styles: StyleOptions) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedxm/entity-editor",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.umd.js",