@markput/react 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +2 -14
  2. package/index.js +433 -396
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,35 +1,54 @@
1
1
  import "./index.css";
2
- import { jsxs as Z, jsx as f, Fragment as wt } from "react/jsx-runtime";
3
- import { useState as P, useEffect as M, useImperativeHandle as St, createContext as at, useContext as ct, memo as O, useRef as $, useCallback as k, useMemo as S, useLayoutEffect as Ct } from "react";
2
+ import { jsxs as J, jsx as h, Fragment as wt } from "react/jsx-runtime";
3
+ import { useState as M, useEffect as P, useImperativeHandle as St, createContext as at, useContext as ct, memo as O, useRef as H, useCallback as k, useMemo as S, useLayoutEffect as Ct } from "react";
4
4
  function bt(s) {
5
- if (s == null) throw new Error("Value must be a non nullable!");
6
- }
7
- function Et(s) {
8
5
  return s ? Object.fromEntries(
9
6
  Object.entries(s).map(([t, e]) => t.startsWith("data") && t.length > 4 && t[4] === t[4].toUpperCase() ? [`data-${t.slice(4).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}`, e] : [t, e])
10
7
  ) : {};
11
8
  }
12
- function Tt(...s) {
9
+ function Et(...s) {
13
10
  return s.filter(Boolean).join(" ") || void 0;
14
11
  }
15
- function Nt(...s) {
12
+ function Tt(...s) {
16
13
  const t = Object.assign({}, ...s.filter(Boolean));
17
14
  return Object.keys(t).length > 0 ? t : void 0;
18
15
  }
16
+ function Nt(s, t) {
17
+ return s !== void 0 ? typeof s == "function" ? s(t) : s : t ?? {};
18
+ }
19
+ const It = {
20
+ container: "div",
21
+ span: "span"
22
+ };
23
+ function Q(s, t) {
24
+ return t?.[s] ?? It[s];
25
+ }
26
+ function K(s, t) {
27
+ const e = t?.[s];
28
+ return e ? bt(e) : void 0;
29
+ }
19
30
  var v = /* @__PURE__ */ ((s) => (s.UP = "ArrowUp", s.DOWN = "ArrowDown", s.LEFT = "ArrowLeft", s.RIGHT = "ArrowRight", s.END = "End", s.HOME = "Home", s.PAGE_DOWN = "PageDown", s.PAGE_UP = "PageUp", s.ENTER = "Enter", s.TAB = "Tab", s.SPACE = " ", s.BACKSPACE = "Backspace", s.DELETE = "Delete", s.COMMA = ",", s.ESC = "Escape", s))(v || {});
20
- const It = "@", Pt = "@[__value__](__meta__)", x = {
31
+ const Mt = "@", Pt = "@[__value__](__meta__)", Lt = [
32
+ {
33
+ markup: Pt,
34
+ overlay: {
35
+ trigger: Mt,
36
+ data: []
37
+ }
38
+ }
39
+ ], x = {
21
40
  Value: "__value__",
22
41
  Meta: "__meta__",
23
42
  Nested: "__nested__"
24
- }, N = {
43
+ }, T = {
25
44
  Value: "value",
26
45
  Meta: "meta",
27
46
  Nested: "nested"
28
47
  };
29
- function Mt(s, t) {
30
- const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = Lt(s);
31
- At(r, s);
32
- const i = r.value === 2, { segments: a, gapTypes: c } = i ? Ot(e, n, o) : { segments: e, gapTypes: n };
48
+ function At(s, t) {
49
+ const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = Ot(s);
50
+ Dt(r, s);
51
+ const i = r.value === 2, { segments: a, gapTypes: c } = i ? Rt(e, n, o) : { segments: e, gapTypes: n };
33
52
  return {
34
53
  markup: s,
35
54
  index: t,
@@ -41,23 +60,23 @@ function Mt(s, t) {
41
60
  // Will be populated by MarkupRegistry
42
61
  };
43
62
  }
44
- function Lt(s) {
63
+ function Ot(s) {
45
64
  const t = [], e = [], n = [], r = {
46
65
  value: 0,
47
66
  meta: 0,
48
67
  nested: 0
49
- }, o = [], i = [N.Value, N.Meta, N.Nested];
68
+ }, o = [], i = [T.Value, T.Meta, T.Nested];
50
69
  for (const l of i) {
51
- const d = nt[l];
52
- let g = s.indexOf(d);
53
- for (; g !== -1; )
54
- o.push({ type: l, position: g }), g = s.indexOf(d, g + d.length);
70
+ const d = st[l];
71
+ let f = s.indexOf(d);
72
+ for (; f !== -1; )
73
+ o.push({ type: l, position: f }), f = s.indexOf(d, f + d.length);
55
74
  }
56
75
  o.sort((l, d) => l.position - d.position);
57
76
  let a = 0;
58
77
  for (const l of o) {
59
78
  const d = s.substring(a, l.position);
60
- d.length > 0 && t.push(d), e.push(l.type), r[l.type]++, l.type === N.Value && n.push(e.length - 1), a = l.position + nt[l.type].length;
79
+ d.length > 0 && t.push(d), e.push(l.type), r[l.type]++, l.type === T.Value && n.push(e.length - 1), a = l.position + st[l.type].length;
61
80
  }
62
81
  const c = s.substring(a);
63
82
  return c.length > 0 && t.push(c), {
@@ -67,7 +86,7 @@ function Lt(s) {
67
86
  valueGapIndices: n
68
87
  };
69
88
  }
70
- function At(s, t) {
89
+ function Dt(s, t) {
71
90
  const e = [
72
91
  { count: s.value, max: 2, name: x.Value },
73
92
  { count: s.meta, max: 1, name: x.Meta },
@@ -81,29 +100,29 @@ function At(s, t) {
81
100
  `Invalid markup: "${t}". Need at least one "${x.Value}" or "${x.Nested}"`
82
101
  );
83
102
  }
84
- const nt = {
85
- [N.Value]: x.Value,
86
- [N.Meta]: x.Meta,
87
- [N.Nested]: x.Nested
103
+ const st = {
104
+ [T.Value]: x.Value,
105
+ [T.Meta]: x.Meta,
106
+ [T.Nested]: x.Nested
88
107
  };
89
- function Ot(s, t, e) {
108
+ function Rt(s, t, e) {
90
109
  if (e.length !== 2)
91
110
  return { segments: s, gapTypes: t };
92
111
  const [n, r] = e, o = [], i = s[n], a = s[n + 1];
93
- i && a && o.push(g(i, a, s[n + 2]));
112
+ i && a && o.push(f(i, a, s[n + 2]));
94
113
  for (let u = n + 2; u < r; u++)
95
114
  o.push(s[u]);
96
115
  const c = s[r], l = s[r + 1];
97
- c && l && o.push(g(c, l, s[r + 2]));
98
- const d = t.filter((u) => u !== N.Value);
116
+ c && l && o.push(f(c, l, s[r + 2]));
117
+ const d = t.filter((u) => u !== T.Value);
99
118
  return { segments: o, gapTypes: d };
100
- function g(u, h, m) {
101
- if (!m) return [u, h, ""];
102
- const C = m.charAt(0), y = C && !h.includes(C) && !m.startsWith(u) ? C : "";
103
- return [u, h, y];
119
+ function f(u, g, m) {
120
+ if (!m) return [u, g, ""];
121
+ const C = m.charAt(0), y = C && !g.includes(C) && !m.startsWith(u) ? C : "";
122
+ return [u, g, y];
104
123
  }
105
124
  }
106
- class Dt {
125
+ class _t {
107
126
  markups;
108
127
  descriptors;
109
128
  /** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */
@@ -116,7 +135,7 @@ class Dt {
116
135
  this.descriptors = t.map((n, r) => {
117
136
  if (n === void 0)
118
137
  return null;
119
- const o = Mt(n, r);
138
+ const o = At(n, r);
120
139
  return o.segments.forEach((i, a) => {
121
140
  this.processSegment(o, i, a, e);
122
141
  }), this.addToFirstSegmentIndexMap(o), o;
@@ -168,7 +187,7 @@ function lt(s, t) {
168
187
  e = e * 33 ^ t.charCodeAt(n);
169
188
  return e = e >>> 0, s * 1e6 + (e & 1048575);
170
189
  }
171
- class Rt {
190
+ class Bt {
172
191
  constructor(t, e) {
173
192
  if (this.descriptor = t, this.expectedSegmentIndex = 1, this.start = e.start, this.end = e.end, t.segments.length === 1 && (this.expectedSegmentIndex = NaN, this.gaps.value = { start: this.start, end: this.end }), t.hasTwoValues && e.captured) {
174
193
  this.captured = e.captured;
@@ -237,7 +256,7 @@ class Rt {
237
256
  return !t || this.start >= t.end ? !1 : !t.descriptor.hasNested || t.gaps.nested === void 0 ? !0 : !(this.start >= t.gaps.nested.start && this.end <= t.gaps.nested.end);
238
257
  }
239
258
  }
240
- class _t {
259
+ class Vt {
241
260
  constructor(t) {
242
261
  this.registry = t;
243
262
  }
@@ -266,7 +285,7 @@ class _t {
266
285
  }
267
286
  tryStartNewStates(t) {
268
287
  this.registry.firstSegmentIndexMap.get(t.index)?.forEach((e) => {
269
- const n = new Rt(e, t);
288
+ const n = new Bt(e, t);
270
289
  if (!n.isInvalid) {
271
290
  if (n.isCompleted) return this.addToCompleted(n);
272
291
  this.addToWaiting(n);
@@ -312,11 +331,11 @@ class _t {
312
331
  }
313
332
  }
314
333
  const A = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
315
- function Bt(s, t, e) {
334
+ function $t(s, t, e) {
316
335
  const n = A(s), r = A(t), o = A(t + e);
317
336
  return `${n}([^${o}]+?)${r}`;
318
337
  }
319
- class Vt {
338
+ class Ht {
320
339
  staticRegex;
321
340
  staticToIndex;
322
341
  dynamicRegex;
@@ -340,10 +359,10 @@ class Vt {
340
359
  if (typeof a == "string")
341
360
  i.push({ index: c, pattern: A(a), definition: a });
342
361
  else {
343
- const [l, d, g] = a;
362
+ const [l, d, f] = a;
344
363
  o.add(c);
345
- const h = Bt(l, d, g).replace("(", `(?<content${c}>`);
346
- i.push({ index: c, pattern: h, definition: a });
364
+ const g = $t(l, d, f).replace("(", `(?<content${c}>`);
365
+ i.push({ index: c, pattern: g, definition: a });
347
366
  }
348
367
  }), i.sort((a, c) => {
349
368
  const l = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
@@ -395,7 +414,7 @@ const dt = (s, t = 0, e = s.length) => ({
395
414
  content: s.substring(t, e),
396
415
  position: { start: t, end: e }
397
416
  });
398
- class $t {
417
+ class Ft {
399
418
  // Instance fields - only what's needed for single pass
400
419
  input;
401
420
  // ===== PUBLIC API =====
@@ -528,13 +547,13 @@ class $t {
528
547
  };
529
548
  }
530
549
  }
531
- function J(s, t) {
550
+ function Y(s, t) {
532
551
  let e = "";
533
552
  for (const n of s)
534
553
  if (n.type === "text")
535
554
  e += n.content;
536
555
  else if (n.children.length > 0) {
537
- const r = J(n.children, t), o = {
556
+ const r = Y(n.children, t), o = {
538
557
  ...n,
539
558
  value: r
540
559
  };
@@ -543,19 +562,19 @@ function J(s, t) {
543
562
  e += t(n);
544
563
  return e;
545
564
  }
546
- function j(s, t) {
565
+ function q(s, t) {
547
566
  let e = s;
548
567
  return t.value !== void 0 && (e = e.replaceAll(x.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(x.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(x.Nested, t.nested)), e;
549
568
  }
550
- function I(s) {
569
+ function N(s) {
551
570
  let t = "";
552
571
  for (const e of s) {
553
572
  if (e.type === "text") {
554
573
  t += e.content;
555
574
  continue;
556
575
  }
557
- const n = e.descriptor.markup, r = n.includes(x.Nested) ? e.children.length > 0 ? I(e.children) : e.nested?.content : void 0;
558
- t += j(n, {
576
+ const n = e.descriptor.markup, r = n.includes(x.Nested) ? e.children.length > 0 ? N(e.children) : e.nested?.content : void 0;
577
+ t += q(n, {
559
578
  value: e.value,
560
579
  meta: e.meta,
561
580
  nested: r
@@ -563,7 +582,7 @@ function I(s) {
563
582
  }
564
583
  return t;
565
584
  }
566
- class H {
585
+ class F {
567
586
  registry;
568
587
  segmentMatcher;
569
588
  patternMatcher;
@@ -588,7 +607,7 @@ class H {
588
607
  * ```
589
608
  */
590
609
  constructor(t) {
591
- this.registry = new Dt(t), this.segmentMatcher = new Vt(this.registry.segments), this.patternMatcher = new _t(this.registry), this.treeBuilder = new $t();
610
+ this.registry = new _t(t), this.segmentMatcher = new Ht(this.registry.segments), this.patternMatcher = new Vt(this.registry), this.treeBuilder = new Ft();
592
611
  }
593
612
  /**
594
613
  * Parses text into tokens (static convenience method)
@@ -606,7 +625,7 @@ class H {
606
625
  */
607
626
  static parse(t, e) {
608
627
  const n = e?.markup;
609
- return !n || n.length === 0 ? [dt(t)] : new H(n).parse(t);
628
+ return !n || n.length === 0 ? [dt(t)] : new F(n).parse(t);
610
629
  }
611
630
  /**
612
631
  * Converts tokens back to text (static convenience method)
@@ -620,7 +639,7 @@ class H {
620
639
  * ```
621
640
  */
622
641
  static stringify(t) {
623
- return I(t);
642
+ return N(t);
624
643
  }
625
644
  /**
626
645
  * Parses text into a nested token tree
@@ -667,7 +686,7 @@ class H {
667
686
  * ```
668
687
  */
669
688
  stringify(t) {
670
- return I(t);
689
+ return N(t);
671
690
  }
672
691
  /**
673
692
  * Transforms annotated text by processing all mark tokens with a callback
@@ -696,7 +715,7 @@ class H {
696
715
  */
697
716
  transform(t, e) {
698
717
  const n = this.parse(t);
699
- return J(n, e);
718
+ return Y(n, e);
700
719
  }
701
720
  /**
702
721
  * Escapes markup segments in the given text using backslash
@@ -738,10 +757,10 @@ class H {
738
757
  return t.replaceAll(/\\(.)/g, "$1");
739
758
  }
740
759
  }
741
- function He(s, t, e) {
760
+ function Ge(s, t, e) {
742
761
  if (!e.length) return s;
743
- const n = new H(e).parse(s);
744
- return J(n, t);
762
+ const n = new F(e).parse(s);
763
+ return Y(n, t);
745
764
  }
746
765
  function z(s, t, e = 0, n) {
747
766
  for (const r of s) {
@@ -752,7 +771,7 @@ function z(s, t, e = 0, n) {
752
771
  }
753
772
  }
754
773
  }
755
- function Ht(s = "", t = "") {
774
+ function Wt(s = "", t = "") {
756
775
  if (s === t) return {};
757
776
  let e;
758
777
  for (let r = 0; r < s.length; r++)
@@ -768,7 +787,7 @@ function Ht(s = "", t = "") {
768
787
  }
769
788
  return { left: e, right: n };
770
789
  }
771
- function st(s, t) {
790
+ function rt(s, t) {
772
791
  let e = -1, n = s.length;
773
792
  for (; n - e > 1; ) {
774
793
  const r = Math.round((e + n) / 2);
@@ -776,53 +795,53 @@ function st(s, t) {
776
795
  }
777
796
  return s[e] == t && (n = e), [e, n].filter((r) => s[r] !== void 0);
778
797
  }
779
- function Ft(s) {
798
+ function Gt(s) {
780
799
  const { focus: t } = s.nodes, e = s.state.parser.get(), n = s.state.tokens.get();
781
800
  if (!e)
782
801
  return n;
783
802
  const r = e.parse(t.content);
784
803
  return r.length === 1 ? n : n.toSpliced(t.index, 1, ...r);
785
804
  }
786
- function Wt(s) {
787
- const t = s.state.value.get(), e = Gt(s), n = Ht(s.state.previousValue.get(), t);
805
+ function Ut(s) {
806
+ const t = s.state.value.get(), e = jt(s), n = Wt(s.state.previousValue.get(), t);
788
807
  if (!n.left && !n.right)
789
808
  return s.state.previousValue.set(t), s.state.tokens.get();
790
809
  s.state.previousValue.set(t);
791
810
  const r = s.state.tokens.get();
792
811
  switch (!0) {
793
812
  case (n.left !== void 0 && e.includes(n.left) && n.right !== void 0 && Math.abs(n.left - n.right) > 1): {
794
- const o = e.indexOf(n.left), i = G(s, o - 1, o);
813
+ const o = e.indexOf(n.left), i = U(s, o - 1, o);
795
814
  return r.toSpliced(o - 1, 2, ...i);
796
815
  }
797
816
  case n.left !== void 0: {
798
- const [o] = st(e, n.left), i = G(s, o);
817
+ const [o] = rt(e, n.left), i = U(s, o);
799
818
  return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
800
819
  }
801
820
  case n.right !== void 0: {
802
- const [o] = st(e, n.right), i = G(s, o);
821
+ const [o] = rt(e, n.right), i = U(s, o);
803
822
  return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
804
823
  }
805
824
  default:
806
- return R(s, t ?? "");
825
+ return _(s, t ?? "");
807
826
  }
808
827
  }
809
- function G(s, ...t) {
828
+ function U(s, ...t) {
810
829
  let e = "";
811
830
  const n = s.state.tokens.get();
812
831
  for (const r of t) {
813
832
  const o = n[r];
814
833
  e += o.content;
815
834
  }
816
- return R(s, e);
835
+ return _(s, e);
817
836
  }
818
- function Gt(s) {
837
+ function jt(s) {
819
838
  let t = 0;
820
839
  return s.state.tokens.get().map((n) => {
821
840
  const r = n.content.length;
822
841
  return t += r, t - r;
823
842
  }) ?? [];
824
843
  }
825
- function R(s, t) {
844
+ function _(s, t) {
826
845
  const e = s.state.parser.get();
827
846
  return e ? e.parse(t) : [
828
847
  {
@@ -832,44 +851,44 @@ function R(s, t) {
832
851
  }
833
852
  ];
834
853
  }
835
- const Ut = (s, t) => s === t;
836
- class _ {
837
- #e;
838
- #t = /* @__PURE__ */ new Set();
854
+ const qt = (s, t) => s === t;
855
+ class B {
856
+ #t;
857
+ #e = /* @__PURE__ */ new Set();
839
858
  #n;
840
859
  constructor(t, e) {
841
- this.#e = t, this.#n = e?.equals ?? Ut;
860
+ this.#t = t, this.#n = e?.equals ?? qt;
842
861
  }
843
862
  static event() {
844
- return new _(void 0, { equals: !1 });
863
+ return new B(void 0, { equals: !1 });
845
864
  }
846
865
  get value() {
847
- return this.#e;
866
+ return this.#t;
848
867
  }
849
868
  set value(t) {
850
- (this.#n === !1 || !this.#n(this.#e, t)) && (this.#e = t, this.#t.forEach((e) => e(t)));
869
+ (this.#n === !1 || !this.#n(this.#t, t)) && (this.#t = t, this.#e.forEach((e) => e(t)));
851
870
  }
852
871
  on(t) {
853
- return this.#t.add(t), () => this.#t.delete(t);
872
+ return this.#e.add(t), () => this.#e.delete(t);
854
873
  }
855
874
  emit(t) {
856
- arguments.length > 0 && (this.#e = t), this.#t.forEach((e) => e(this.#e));
875
+ arguments.length > 0 && (this.#t = t), this.#e.forEach((e) => e(this.#t));
857
876
  }
858
877
  get() {
859
- return this.#e;
878
+ return this.#t;
860
879
  }
861
880
  set(t) {
862
881
  this.value = t;
863
882
  }
864
883
  }
865
- function jt(s, t) {
884
+ function zt(s, t) {
866
885
  const e = {};
867
886
  return e.get = () => s.get(), e.set = (n) => s.set(n), e.on = (n) => s.on(n), e.use = t(e), e;
868
887
  }
869
- function zt(s, t) {
888
+ function Xt(s, t) {
870
889
  const e = /* @__PURE__ */ new Map();
871
890
  for (const n in s)
872
- e.set(n, new _(s[n]));
891
+ e.set(n, new B(s[n]));
873
892
  return new Proxy(s, {
874
893
  get(n, r) {
875
894
  if (r === "set")
@@ -879,32 +898,32 @@ function zt(s, t) {
879
898
  };
880
899
  const o = e.get(r);
881
900
  if (o)
882
- return jt(o, t);
901
+ return zt(o, t);
883
902
  }
884
903
  });
885
904
  }
886
- function qt(s) {
905
+ function Zt(s) {
887
906
  const t = function(e) {
888
907
  s.emit(e);
889
908
  };
890
909
  return t.on = (e) => s.on(e), t;
891
910
  }
892
- function Xt(s) {
911
+ function Jt(s) {
893
912
  const t = [], e = /* @__PURE__ */ new Map();
894
913
  for (const n of t)
895
- e.set(n, _.event());
914
+ e.set(n, B.event());
896
915
  return new Proxy({}, {
897
916
  get(n, r) {
898
917
  let o = e.get(r);
899
- return o || (o = _.event(), e.set(r, o)), qt(o);
918
+ return o || (o = B.event(), e.set(r, o)), Zt(o);
900
919
  }
901
920
  });
902
921
  }
903
- class Zt {
904
- #e = 1;
905
- #t = /* @__PURE__ */ new WeakMap();
922
+ class Qt {
923
+ #t = 1;
924
+ #e = /* @__PURE__ */ new WeakMap();
906
925
  get(t) {
907
- return this.#t.has(t) ? this.#t.get(t) : (this.#t.set(t, this.#e), this.#e++);
926
+ return this.#e.has(t) ? this.#e.get(t) : (this.#e.set(t, this.#t), this.#t++);
908
927
  }
909
928
  }
910
929
  class w {
@@ -968,8 +987,8 @@ class w {
968
987
  r?.setStart(r.endContainer, e), r?.setEnd(r.endContainer, e);
969
988
  }
970
989
  }
971
- const Jt = new RegExp(/^\w*/);
972
- class Q {
990
+ const Kt = new RegExp(/^\w*/);
991
+ class tt {
973
992
  span;
974
993
  node;
975
994
  dividedText;
@@ -994,7 +1013,7 @@ class Q {
994
1013
  */
995
1014
  static find(t, e) {
996
1015
  if (t && w.isSelectedPosition)
997
- return new Q().find(t, e);
1016
+ return new tt().find(t, e);
998
1017
  }
999
1018
  getDividedTextBy(t) {
1000
1019
  return { left: this.span.slice(0, t), right: this.span.slice(t) };
@@ -1032,7 +1051,7 @@ class Q {
1032
1051
  }
1033
1052
  matchRightPart() {
1034
1053
  const { right: t } = this.dividedText;
1035
- return { word: t.match(Jt)?.[0] };
1054
+ return { word: t.match(Kt)?.[0] };
1036
1055
  }
1037
1056
  matchLeftPart(t) {
1038
1057
  const e = this.makeTriggerRegex(t), { left: n } = this.dividedText, r = n.match(e);
@@ -1046,20 +1065,20 @@ class Q {
1046
1065
  return new RegExp(e);
1047
1066
  }
1048
1067
  }
1049
- class B {
1050
- #e;
1068
+ class V {
1051
1069
  #t;
1070
+ #e;
1052
1071
  get target() {
1053
- return this.#e;
1072
+ return this.#t;
1054
1073
  }
1055
1074
  set target(t) {
1056
- this.#e = t;
1075
+ this.#t = t;
1057
1076
  }
1058
1077
  get next() {
1059
- return new B(this.target?.nextSibling, this.#t);
1078
+ return new V(this.target?.nextSibling, this.#e);
1060
1079
  }
1061
1080
  get prev() {
1062
- return new B(this.target?.previousSibling, this.#t);
1081
+ return new V(this.target?.previousSibling, this.#e);
1063
1082
  }
1064
1083
  get isSpan() {
1065
1084
  return this.index % 2 === 0;
@@ -1095,16 +1114,16 @@ class B {
1095
1114
  this.target && (this.target.textContent = t ?? "");
1096
1115
  }
1097
1116
  get head() {
1098
- return this.#t.refs.container?.firstChild;
1117
+ return this.#e.refs.container?.firstChild;
1099
1118
  }
1100
1119
  get tail() {
1101
- return this.#t.refs.container?.lastChild;
1120
+ return this.#e.refs.container?.lastChild;
1102
1121
  }
1103
1122
  get isFocused() {
1104
1123
  return this.target === document.activeElement;
1105
1124
  }
1106
1125
  constructor(t, e) {
1107
- this.target = t, this.#t = e;
1126
+ this.target = t, this.#e = e;
1108
1127
  }
1109
1128
  setCaretToEnd() {
1110
1129
  w.setCaretToEnd(this.target);
@@ -1116,10 +1135,10 @@ class B {
1116
1135
  this.target = void 0;
1117
1136
  }
1118
1137
  }
1119
- function Qt(s, t, e, n) {
1138
+ function Yt(s, t, e, n) {
1120
1139
  return s.slice(0, e) + t + s.slice(e + n.length);
1121
1140
  }
1122
- function U(s, t) {
1141
+ function j(s, t) {
1123
1142
  const n = {
1124
1143
  prev: 2,
1125
1144
  self: 1,
@@ -1138,37 +1157,56 @@ function U(s, t) {
1138
1157
  let d = r;
1139
1158
  for (let u = 0; u < n; u++)
1140
1159
  d = d.prev;
1141
- const g = d.length;
1142
- t.state.recovery.set({ anchor: d.prev, caret: g }), t.state.onChange.get()?.(I(t.state.tokens.get()));
1160
+ const f = d.length;
1161
+ t.state.recovery.set({ anchor: d.prev, caret: f }), t.state.onChange.get()?.(N(t.state.tokens.get()));
1143
1162
  }
1144
- class Kt {
1163
+ class te {
1164
+ constructor(t) {
1165
+ this.store = t;
1166
+ }
1167
+ #t;
1168
+ enable() {
1169
+ this.#t || (this.#t = this.store.state.readOnly.on(() => this.sync()), this.sync());
1170
+ }
1171
+ disable() {
1172
+ this.#t?.(), this.#t = void 0;
1173
+ }
1174
+ sync() {
1175
+ const t = this.store.refs.container;
1176
+ if (!t) return;
1177
+ const n = this.store.state.readOnly.get() ? "false" : "true", r = t.children;
1178
+ for (let o = 0; o < r.length; o += 2)
1179
+ r[o].contentEditable = n;
1180
+ }
1181
+ }
1182
+ class ee {
1145
1183
  constructor(t) {
1146
1184
  this.store = t;
1147
1185
  }
1148
- #e;
1149
1186
  #t;
1187
+ #e;
1150
1188
  #n;
1151
1189
  enable() {
1152
- this.#e || (this.#e = this.store.events.change.on(() => {
1190
+ this.#t || (this.#t = this.store.events.change.on(() => {
1153
1191
  const t = this.store.state.onChange.get();
1154
1192
  if (!this.store.nodes.focus.target) return;
1155
1193
  const e = this.store.state.tokens.get(), n = e[this.store.nodes.focus.index];
1156
- n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), t?.(I(e)), this.store.events.parse();
1157
- }), this.#t = this.store.events.delete.on((t) => {
1194
+ n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), t?.(N(e)), this.store.events.parse();
1195
+ }), this.#e = this.store.events.delete.on((t) => {
1158
1196
  if (!t) return;
1159
1197
  const { token: e } = t, n = this.store.state.onChange.get(), r = this.store.state.tokens.get(), o = r.indexOf(e);
1160
- this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(I(this.store.state.tokens.get()));
1198
+ this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(N(this.store.state.tokens.get()));
1161
1199
  }), this.#n = this.store.events.select.on((t) => {
1162
1200
  if (!t) return;
1163
1201
  const e = this.store.state.Mark.get(), n = this.store.state.onChange.get(), {
1164
1202
  mark: r,
1165
1203
  match: { option: o, span: i, index: a, source: c }
1166
- } = t, l = r.type === "mark" ? j(o.markup, {
1204
+ } = t, l = r.type === "mark" ? q(o.markup, {
1167
1205
  value: r.value,
1168
1206
  meta: r.meta
1169
- }) : j(o.markup, {
1207
+ }) : q(o.markup, {
1170
1208
  value: r.content
1171
- }), d = Qt(i, l, a, c);
1209
+ }), d = Yt(i, l, a, c);
1172
1210
  if (this.store.state.recovery.set(
1173
1211
  e ? {
1174
1212
  caret: 0,
@@ -1178,37 +1216,37 @@ class Kt {
1178
1216
  } : { caret: a + l.length, anchor: this.store.nodes.input }
1179
1217
  ), this.store.nodes.input.target) {
1180
1218
  this.store.nodes.input.content = d;
1181
- const g = this.store.state.tokens.get(), u = g[this.store.nodes.input.index];
1182
- u.type === "text" && (u.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(I(g)), this.store.events.parse();
1219
+ const f = this.store.state.tokens.get(), u = f[this.store.nodes.input.index];
1220
+ u.type === "text" && (u.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(N(f)), this.store.events.parse();
1183
1221
  }
1184
1222
  }));
1185
1223
  }
1186
1224
  disable() {
1187
- this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0;
1225
+ this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
1188
1226
  }
1189
1227
  }
1190
- class Yt {
1228
+ class ne {
1191
1229
  constructor(t) {
1192
1230
  this.store = t;
1193
1231
  }
1194
- #e;
1195
1232
  #t;
1233
+ #e;
1196
1234
  #n;
1197
1235
  enable() {
1198
- if (this.#e) return;
1236
+ if (this.#t) return;
1199
1237
  const t = this.store.refs.container;
1200
- t && (this.#e = (e) => {
1238
+ t && (this.#t = (e) => {
1201
1239
  this.store.nodes.focus.target = e.target;
1202
- }, this.#t = () => {
1240
+ }, this.#e = () => {
1203
1241
  this.store.nodes.focus.target = void 0;
1204
1242
  }, this.#n = () => {
1205
1243
  const e = this.store.state.tokens.get();
1206
1244
  e.length === 1 && e[0].type === "text" && e[0].content === "" && this.store.refs.container?.firstElementChild?.focus();
1207
- }, t.addEventListener("focusin", this.#e), t.addEventListener("focusout", this.#t), t.addEventListener("click", this.#n));
1245
+ }, t.addEventListener("focusin", this.#t), t.addEventListener("focusout", this.#e), t.addEventListener("click", this.#n));
1208
1246
  }
1209
1247
  disable() {
1210
1248
  const t = this.store.refs.container;
1211
- !t || !this.#e || (t.removeEventListener("focusin", this.#e), t.removeEventListener("focusout", this.#t), t.removeEventListener("click", this.#n), this.#e = void 0, this.#t = void 0, this.#n = void 0);
1249
+ !t || !this.#t || (t.removeEventListener("focusin", this.#t), t.removeEventListener("focusout", this.#e), t.removeEventListener("click", this.#n), this.#t = void 0, this.#e = void 0, this.#n = void 0);
1212
1250
  }
1213
1251
  recover() {
1214
1252
  const t = this.store.state.recovery.get();
@@ -1232,7 +1270,7 @@ class Yt {
1232
1270
  this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
1233
1271
  }
1234
1272
  }
1235
- function te(s, t) {
1273
+ function se(s, t) {
1236
1274
  const { focus: e } = s.nodes;
1237
1275
  if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
1238
1276
  const n = e.prev;
@@ -1240,7 +1278,7 @@ function te(s, t) {
1240
1278
  }
1241
1279
  return !1;
1242
1280
  }
1243
- function ee(s, t) {
1281
+ function re(s, t) {
1244
1282
  const { focus: e } = s.nodes;
1245
1283
  if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
1246
1284
  const n = e.next;
@@ -1248,20 +1286,20 @@ function ee(s, t) {
1248
1286
  }
1249
1287
  return !1;
1250
1288
  }
1251
- class ne {
1289
+ class oe {
1252
1290
  constructor(t) {
1253
1291
  this.store = t;
1254
1292
  }
1255
- #e;
1256
1293
  #t;
1294
+ #e;
1257
1295
  #n;
1258
1296
  #s;
1259
1297
  #r = null;
1260
1298
  #o = !1;
1261
1299
  enable() {
1262
- this.#e || (this.#e = (t) => {
1300
+ this.#t || (this.#t = (t) => {
1263
1301
  this.#r = t.target, this.#o = !0;
1264
- }, this.#t = (t) => {
1302
+ }, this.#e = (t) => {
1265
1303
  const e = this.#o, n = !this.store.refs.container?.contains(this.#r) || this.#r !== t.target, r = window.getSelection()?.containsNode(this.store.refs.container, !0);
1266
1304
  e && n && r && this.store.state.selecting.set("drag");
1267
1305
  }, this.#n = () => {
@@ -1270,13 +1308,13 @@ class ne {
1270
1308
  if (this.store.state.selecting.get() !== "drag") return;
1271
1309
  const t = [...this.store.refs.container.children], e = t.map((n) => n.contentEditable);
1272
1310
  t.forEach((n) => n.contentEditable = "false"), t.forEach((n, r) => n.contentEditable = e[r]);
1273
- }, document.addEventListener("mousedown", this.#e), document.addEventListener("mousemove", this.#t), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#s));
1311
+ }, document.addEventListener("mousedown", this.#t), document.addEventListener("mousemove", this.#e), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#s));
1274
1312
  }
1275
1313
  disable() {
1276
- this.#e && (document.removeEventListener("mousedown", this.#e), document.removeEventListener("mousemove", this.#t), document.removeEventListener("mouseup", this.#n), document.removeEventListener("selectionchange", this.#s), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#s = void 0), this.#r = null, this.#o = !1;
1314
+ this.#t && (document.removeEventListener("mousedown", this.#t), document.removeEventListener("mousemove", this.#e), document.removeEventListener("mouseup", this.#n), document.removeEventListener("selectionchange", this.#s), this.#t = void 0, this.#e = void 0, this.#n = void 0, this.#s = void 0), this.#r = null, this.#o = !1;
1277
1315
  }
1278
1316
  }
1279
- function se(s, t) {
1317
+ function ie(s, t) {
1280
1318
  if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
1281
1319
  t.preventDefault();
1282
1320
  const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
@@ -1284,27 +1322,27 @@ function se(s, t) {
1284
1322
  e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
1285
1323
  }
1286
1324
  }
1287
- class re {
1325
+ class ae {
1288
1326
  constructor(t) {
1289
1327
  this.store = t;
1290
1328
  }
1291
- #e;
1292
1329
  #t;
1330
+ #e;
1293
1331
  #n;
1294
1332
  enable() {
1295
- if (this.#e) return;
1333
+ if (this.#t) return;
1296
1334
  const t = this.store.refs.container;
1297
- t && (this.#e = (e) => {
1298
- e.key === v.LEFT ? te(this.store, e) : e.key === v.RIGHT && ee(this.store, e), this.#s(e), se(this.store, e);
1299
- }, this.#t = (e) => {
1300
- ae(this.store, e);
1335
+ t && (this.#t = (e) => {
1336
+ e.key === v.LEFT ? se(this.store, e) : e.key === v.RIGHT && re(this.store, e), this.#s(e), ie(this.store, e);
1337
+ }, this.#e = (e) => {
1338
+ de(this.store, e);
1301
1339
  }, this.#n = (e) => {
1302
- oe(this.store, e);
1303
- }, t.addEventListener("keydown", this.#e), t.addEventListener("paste", this.#t), t.addEventListener("beforeinput", this.#n, !0));
1340
+ ce(this.store, e);
1341
+ }, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
1304
1342
  }
1305
1343
  disable() {
1306
1344
  const t = this.store.refs.container;
1307
- !t || !this.#e || (t.removeEventListener("keydown", this.#e), t.removeEventListener("paste", this.#t), t.removeEventListener("beforeinput", this.#n, !0), this.#e = void 0, this.#t = void 0, this.#n = void 0);
1345
+ !t || !this.#t || (t.removeEventListener("keydown", this.#t), t.removeEventListener("paste", this.#e), t.removeEventListener("beforeinput", this.#n, !0), this.#t = void 0, this.#e = void 0, this.#n = void 0);
1308
1346
  }
1309
1347
  #s(t) {
1310
1348
  const { focus: e } = this.store.nodes;
@@ -1312,14 +1350,14 @@ class re {
1312
1350
  if (e.isMark) {
1313
1351
  if (e.isEditable && (t.key === v.BACKSPACE && !e.isCaretAtBeginning || t.key === v.DELETE && !e.isCaretAtEnd))
1314
1352
  return;
1315
- t.preventDefault(), U("self", this.store);
1353
+ t.preventDefault(), j("self", this.store);
1316
1354
  return;
1317
1355
  }
1318
- t.key === v.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), U("prev", this.store)), t.key === v.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), U("next", this.store));
1356
+ t.key === v.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), j("prev", this.store)), t.key === v.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), j("next", this.store));
1319
1357
  }
1320
1358
  }
1321
1359
  }
1322
- function oe(s, t) {
1360
+ function ce(s, t) {
1323
1361
  const e = s.state.selecting.get();
1324
1362
  if (e === "all" && ut(s)) {
1325
1363
  if (t.inputType === "insertFromPaste") {
@@ -1333,9 +1371,9 @@ function oe(s, t) {
1333
1371
  }
1334
1372
  e === "all" && s.state.selecting.set(void 0);
1335
1373
  const { focus: n } = s.nodes;
1336
- !n.target || !n.isEditable || ie(n, t) && s.events.change();
1374
+ !n.target || !n.isEditable || le(n, t) && s.events.change();
1337
1375
  }
1338
- function ie(s, t) {
1376
+ function le(s, t) {
1339
1377
  const e = s.caret, n = s.content;
1340
1378
  let r, o;
1341
1379
  switch (t.inputType) {
@@ -1369,7 +1407,7 @@ function ie(s, t) {
1369
1407
  }
1370
1408
  return s.content = r, s.caret = o, !0;
1371
1409
  }
1372
- function ae(s, t) {
1410
+ function de(s, t) {
1373
1411
  const e = s.state.selecting.get();
1374
1412
  if (e !== "all" || !ut(s)) {
1375
1413
  e === "all" && s.state.selecting.set(void 0);
@@ -1406,41 +1444,41 @@ function ht(s, t) {
1406
1444
  }), e.focus());
1407
1445
  });
1408
1446
  }
1409
- class ce {
1410
- #e = [];
1411
- #t = !1;
1447
+ class ue {
1448
+ #t = [];
1449
+ #e = !1;
1412
1450
  register(t) {
1413
- return this.#e.push(t), this;
1451
+ return this.#t.push(t), this;
1414
1452
  }
1415
1453
  enableAll() {
1416
- this.#t || (this.#t = !0, this.#e.forEach((t) => t.enable()));
1454
+ this.#e || (this.#e = !0, this.#t.forEach((t) => t.enable()));
1417
1455
  }
1418
1456
  disableAll() {
1419
- this.#t && (this.#t = !1, this.#e.forEach((t) => t.disable()));
1457
+ this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
1420
1458
  }
1421
1459
  }
1422
- const V = (s, t) => ({
1460
+ const R = (s, t) => ({
1423
1461
  name: s,
1424
1462
  enable: () => t.enable(),
1425
1463
  disable: () => t.disable()
1426
- }), le = (s) => {
1427
- const t = new ce();
1428
- return t.register(V("keydown", s.controllers.keydown)).register(V("system", s.controllers.system)).register(V("focus", s.controllers.focus)).register(V("textSelection", s.controllers.textSelection)), t;
1464
+ }), he = (s) => {
1465
+ const t = new ue();
1466
+ return t.register(R("keydown", s.controllers.keydown)).register(R("system", s.controllers.system)).register(R("focus", s.controllers.focus)).register(R("textSelection", s.controllers.textSelection)).register(R("contentEditable", s.controllers.contentEditable)), t;
1429
1467
  };
1430
- class de {
1468
+ class fe {
1431
1469
  constructor(t) {
1432
1470
  this.store = t;
1433
1471
  }
1434
- #e = [];
1435
- #t = !1;
1472
+ #t = [];
1473
+ #e = !1;
1436
1474
  enable(t) {
1437
- const { store: e } = this, n = le(e);
1438
- n.enableAll(), this.#e.push(() => n.disableAll()), this.#n(), t?.getTrigger && this.#s(t.getTrigger);
1475
+ const { store: e } = this, n = he(e);
1476
+ n.enableAll(), this.#t.push(() => n.disableAll()), this.#n(), t?.getTrigger && this.#s(t.getTrigger);
1439
1477
  }
1440
1478
  disable() {
1441
- for (const t of this.#e)
1479
+ for (const t of this.#t)
1442
1480
  t();
1443
- this.#e = [], this.#t = !1;
1481
+ this.#t = [], this.#e = !1;
1444
1482
  }
1445
1483
  /**
1446
1484
  * Synchronizes the parser with current options and handles parsing.
@@ -1449,12 +1487,12 @@ class de {
1449
1487
  */
1450
1488
  syncParser(t, e) {
1451
1489
  const { store: n } = this, r = e?.map((i) => i.markup);
1452
- if (r && r.some(Boolean) ? n.state.parser.set(new H(r)) : n.state.parser.set(void 0), this.#t) {
1490
+ if (r && r.some(Boolean) ? n.state.parser.set(new F(r)) : n.state.parser.set(void 0), this.#e) {
1453
1491
  n.state.recovery.get() || n.events.parse();
1454
1492
  return;
1455
1493
  }
1456
1494
  const o = t ?? n.state.defaultValue.get() ?? "";
1457
- n.state.tokens.set(R(n, o)), this.#t = !0;
1495
+ n.state.tokens.set(_(n, o)), this.#e = !0;
1458
1496
  }
1459
1497
  /**
1460
1498
  * Recovers focus after tokens change.
@@ -1462,36 +1500,63 @@ class de {
1462
1500
  * since focus recovery requires the new DOM to be committed.
1463
1501
  */
1464
1502
  recoverFocus() {
1465
- this.store.state.Mark.get() && this.store.controllers.focus.recover();
1503
+ this.store.controllers.contentEditable.sync(), this.store.state.Mark.get() && this.store.controllers.focus.recover();
1466
1504
  }
1467
1505
  #n() {
1468
1506
  const { store: t } = this;
1469
- this.#e.push(
1507
+ this.#t.push(
1470
1508
  t.events.parse.on(() => {
1471
1509
  if (t.state.recovery.get()) {
1472
- const e = I(t.state.tokens.get());
1473
- t.state.tokens.set(R(t, e)), t.state.previousValue.set(e);
1510
+ const e = N(t.state.tokens.get());
1511
+ t.state.tokens.set(_(t, e)), t.state.previousValue.set(e);
1474
1512
  return;
1475
1513
  }
1476
- t.state.tokens.set(t.nodes.focus.target ? Ft(t) : Wt(t));
1514
+ t.state.tokens.set(t.nodes.focus.target ? Gt(t) : Ut(t));
1477
1515
  })
1478
1516
  );
1479
1517
  }
1480
1518
  #s(t) {
1481
1519
  const { store: e } = this;
1482
- e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#e.push(() => e.controllers.overlay.disable()), this.#e.push(
1520
+ e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#t.push(() => e.controllers.overlay.disable()), this.#t.push(
1483
1521
  e.state.overlayMatch.on((n) => {
1484
1522
  n ? (e.nodes.input.target = e.nodes.focus.target, e.controllers.overlay.enableClose()) : e.controllers.overlay.disableClose();
1485
1523
  })
1486
1524
  );
1487
1525
  }
1488
1526
  }
1489
- class ue {
1527
+ function ge(s, t) {
1528
+ const e = t.toLowerCase();
1529
+ return s.filter((n) => n.toLowerCase().indexOf(e) > -1);
1530
+ }
1531
+ function pe(s, t, e) {
1532
+ return {
1533
+ type: "mark",
1534
+ value: t,
1535
+ meta: e,
1536
+ content: "",
1537
+ position: {
1538
+ start: s.index,
1539
+ end: s.index + s.span.length
1540
+ },
1541
+ descriptor: {
1542
+ markup: s.option.markup,
1543
+ index: 0,
1544
+ segments: [],
1545
+ gapTypes: [],
1546
+ hasNested: !1,
1547
+ hasTwoValues: !1,
1548
+ segmentGlobalIndices: []
1549
+ },
1550
+ children: [],
1551
+ nested: void 0
1552
+ };
1553
+ }
1554
+ class ve {
1490
1555
  constructor(t) {
1491
1556
  this.store = t;
1492
1557
  }
1493
- #e;
1494
1558
  #t;
1559
+ #e;
1495
1560
  #n;
1496
1561
  #s;
1497
1562
  #r;
@@ -1499,11 +1564,11 @@ class ue {
1499
1564
  #i;
1500
1565
  #a;
1501
1566
  enableTrigger(t, e) {
1502
- if (this.#e) return;
1503
- this.#e = this.store.events.clearOverlay.on(() => {
1567
+ if (this.#t) return;
1568
+ this.#t = this.store.events.clearOverlay.on(() => {
1504
1569
  e(void 0);
1505
- }), this.#t = this.store.events.checkOverlay.on(() => {
1506
- const r = Q.find(this.store.state.options.get(), t);
1570
+ }), this.#e = this.store.events.checkOverlay.on(() => {
1571
+ const r = tt.find(this.store.state.options.get(), t);
1507
1572
  e(r);
1508
1573
  }), this.#n = this.store.events.change.on(() => {
1509
1574
  const r = this.store.state.showOverlayOn.get(), o = "change";
@@ -1532,31 +1597,46 @@ class ue {
1532
1597
  }
1533
1598
  disable() {
1534
1599
  const t = this.store.refs.container;
1535
- t && this.#r && (t.removeEventListener("focusin", this.#r), t.removeEventListener("focusout", this.#o)), this.#s && document.removeEventListener("selectionchange", this.#s), this.disableClose(), this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#s = void 0, this.#r = void 0, this.#o = void 0;
1600
+ t && this.#r && (t.removeEventListener("focusin", this.#r), t.removeEventListener("focusout", this.#o)), this.#s && document.removeEventListener("selectionchange", this.#s), this.disableClose(), this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0, this.#s = void 0, this.#r = void 0, this.#o = void 0;
1601
+ }
1602
+ }
1603
+ function me(s, t, e) {
1604
+ if (e === 0) return { action: "none", index: t };
1605
+ const n = !isNaN(t);
1606
+ switch (s) {
1607
+ case v.UP:
1608
+ return { action: "up", index: n ? (e + (t - 1) % e) % e : 0 };
1609
+ case v.DOWN:
1610
+ return { action: "down", index: n ? (t + 1) % e : 0 };
1611
+ case v.ENTER:
1612
+ return n ? { action: "select", index: t } : { action: "none", index: t };
1613
+ default:
1614
+ return { action: "none", index: t };
1536
1615
  }
1537
1616
  }
1538
- class he {
1539
- key = new Zt();
1617
+ class ye {
1618
+ key = new Qt();
1540
1619
  nodes = {
1541
- focus: new B(void 0, this),
1542
- input: new B(void 0, this)
1620
+ focus: new V(void 0, this),
1621
+ input: new V(void 0, this)
1543
1622
  };
1544
1623
  state;
1545
- events = Xt();
1624
+ events = Jt();
1546
1625
  refs = {
1547
1626
  container: null,
1548
1627
  overlay: null
1549
1628
  };
1550
1629
  controllers = {
1551
- overlay: new ue(this),
1552
- focus: new Yt(this),
1553
- keydown: new re(this),
1554
- system: new Kt(this),
1555
- textSelection: new ne(this)
1630
+ overlay: new ve(this),
1631
+ focus: new ne(this),
1632
+ keydown: new ae(this),
1633
+ system: new ee(this),
1634
+ textSelection: new oe(this),
1635
+ contentEditable: new te(this)
1556
1636
  };
1557
- lifecycle = new de(this);
1637
+ lifecycle = new fe(this);
1558
1638
  constructor(t) {
1559
- this.state = zt(
1639
+ this.state = Xt(
1560
1640
  {
1561
1641
  tokens: [],
1562
1642
  parser: void 0,
@@ -1595,13 +1675,13 @@ class he {
1595
1675
  };
1596
1676
  }
1597
1677
  }
1598
- class fe {
1678
+ class xe {
1599
1679
  ref;
1600
- #e;
1601
1680
  #t;
1681
+ #e;
1602
1682
  #n;
1603
1683
  constructor(t) {
1604
- this.ref = t.ref, this.#e = t.store, this.#t = t.token;
1684
+ this.ref = t.ref, this.#t = t.store, this.#e = t.token;
1605
1685
  }
1606
1686
  get readOnly() {
1607
1687
  return this.#n;
@@ -1610,58 +1690,58 @@ class fe {
1610
1690
  this.#n = t;
1611
1691
  }
1612
1692
  get content() {
1613
- return this.#t.content;
1693
+ return this.#e.content;
1614
1694
  }
1615
1695
  set content(t) {
1616
- this.#t.content = t, this.#s();
1696
+ this.#e.content = t, this.#s();
1617
1697
  }
1618
1698
  get value() {
1619
- return this.#t.value;
1699
+ return this.#e.value;
1620
1700
  }
1621
1701
  set value(t) {
1622
- this.#t.value = t ?? "", this.#s();
1702
+ this.#e.value = t ?? "", this.#s();
1623
1703
  }
1624
1704
  get meta() {
1625
- return this.#t.meta;
1705
+ return this.#e.meta;
1626
1706
  }
1627
1707
  set meta(t) {
1628
- this.#t.meta = t, this.#s();
1708
+ this.#e.meta = t, this.#s();
1629
1709
  }
1630
1710
  get depth() {
1631
- return z(this.#e.state.tokens.get(), this.#t).depth;
1711
+ return z(this.#t.state.tokens.get(), this.#e).depth;
1632
1712
  }
1633
1713
  get hasChildren() {
1634
- return this.#t.children.length > 0;
1714
+ return this.#e.children.length > 0;
1635
1715
  }
1636
1716
  get parent() {
1637
- return z(this.#e.state.tokens.get(), this.#t)?.parent;
1717
+ return z(this.#t.state.tokens.get(), this.#e)?.parent;
1638
1718
  }
1639
1719
  get tokens() {
1640
- return this.#t.children;
1720
+ return this.#e.children;
1641
1721
  }
1642
1722
  change = (t) => {
1643
- this.#t.content = t.content, this.#t.value = t.value ?? "", t.meta !== void 0 && (this.#t.meta = t.meta), this.#s();
1723
+ this.#e.content = t.content, this.#e.value = t.value ?? "", t.meta !== void 0 && (this.#e.meta = t.meta), this.#s();
1644
1724
  };
1645
- remove = () => this.#e.events.delete({ token: this.#t });
1725
+ remove = () => this.#t.events.delete({ token: this.#e });
1646
1726
  #s() {
1647
- this.#e.events.change();
1727
+ this.#t.events.change();
1648
1728
  }
1649
1729
  }
1650
1730
  let ft = 0;
1651
- function rt(s) {
1731
+ function ot(s) {
1652
1732
  return `block-${ft++}-${s}`;
1653
1733
  }
1654
- function ge() {
1734
+ function ke() {
1655
1735
  ft = 0;
1656
1736
  }
1657
- function pe(s) {
1737
+ function we(s) {
1658
1738
  if (s.length === 0) return [];
1659
- ge();
1739
+ ke();
1660
1740
  const t = [];
1661
1741
  let e = [], n = -1;
1662
1742
  const r = (o) => {
1663
1743
  e.length !== 0 && (t.push({
1664
- id: rt(n),
1744
+ id: ot(n),
1665
1745
  tokens: [...e],
1666
1746
  startPos: n,
1667
1747
  endPos: o
@@ -1671,7 +1751,7 @@ function pe(s) {
1671
1751
  if (o.type === "mark") {
1672
1752
  o.content.endsWith(`
1673
1753
  `) ? (r(o.position.start), t.push({
1674
- id: rt(o.position.start),
1754
+ id: ot(o.position.start),
1675
1755
  tokens: [o],
1676
1756
  startPos: o.position.start,
1677
1757
  endPos: o.position.end
@@ -1679,7 +1759,7 @@ function pe(s) {
1679
1759
  continue;
1680
1760
  }
1681
1761
  if (o.type !== "text") continue;
1682
- const a = ve(o);
1762
+ const a = Se(o);
1683
1763
  for (let c = 0; c < a.length; c++) {
1684
1764
  const l = a[c];
1685
1765
  if (l.isNewline) {
@@ -1699,7 +1779,7 @@ function pe(s) {
1699
1779
  }
1700
1780
  return t;
1701
1781
  }
1702
- function ve(s) {
1782
+ function Se(s) {
1703
1783
  const t = [], { content: e, position: n } = s;
1704
1784
  let r = n.start;
1705
1785
  const o = [], i = () => {
@@ -1735,12 +1815,12 @@ function ve(s) {
1735
1815
  }
1736
1816
  return i(), t;
1737
1817
  }
1738
- function me(s, t, e, n) {
1818
+ function Ce(s, t, e, n) {
1739
1819
  if (e === n || e === n - 1 || t.length < 2 || e < 0 || e >= t.length || n < 0 || n > t.length) return s;
1740
- const r = ye(s, t), o = ke(r, e, n);
1741
- return xe(o);
1820
+ const r = be(s, t), o = Te(r, e, n);
1821
+ return Ee(o);
1742
1822
  }
1743
- function ye(s, t) {
1823
+ function be(s, t) {
1744
1824
  return t.map((e, n) => {
1745
1825
  const r = s.substring(e.startPos, e.endPos);
1746
1826
  let o = "";
@@ -1755,7 +1835,7 @@ function ye(s, t) {
1755
1835
  };
1756
1836
  });
1757
1837
  }
1758
- function xe(s) {
1838
+ function Ee(s) {
1759
1839
  const t = [];
1760
1840
  for (let e = 0; e < s.length; e++) {
1761
1841
  const n = s[e], r = e === s.length - 1;
@@ -1766,11 +1846,11 @@ function xe(s) {
1766
1846
  }
1767
1847
  return t.join("");
1768
1848
  }
1769
- function ke(s, t, e) {
1849
+ function Te(s, t, e) {
1770
1850
  const n = [...s], [r] = n.splice(t, 1), o = e > t ? e - 1 : e;
1771
- return n.splice(o, 0, r), we(n, s), n;
1851
+ return n.splice(o, 0, r), Ne(n, s), n;
1772
1852
  }
1773
- function we(s, t) {
1853
+ function Ne(s, t) {
1774
1854
  for (let e = 0; e < s.length - 1; e++) {
1775
1855
  const n = s[e].index, r = s[e + 1].index;
1776
1856
  if (Math.abs(n - r) === 1) {
@@ -1782,49 +1862,30 @@ function we(s, t) {
1782
1862
  `;
1783
1863
  }
1784
1864
  }
1785
- const Se = [
1786
- {
1787
- markup: Pt,
1788
- overlay: {
1789
- trigger: It,
1790
- data: []
1791
- }
1792
- }
1793
- ], Ce = (s) => () => {
1794
- const [t, e] = P(() => s.get());
1795
- return M(() => s.on(e), [s]), t;
1865
+ const Ie = (s) => () => {
1866
+ const [t, e] = M(() => s.get());
1867
+ return P(() => s.on(e), [s]), t;
1796
1868
  };
1797
- function be(s, t) {
1798
- St(t, () => s.createHandler(), [s]), M(() => (s.lifecycle.enable({
1869
+ function Me(s, t) {
1870
+ St(t, () => s.createHandler(), [s]), P(() => (s.lifecycle.enable({
1799
1871
  getTrigger: (a) => a.overlay?.trigger
1800
1872
  }), () => s.lifecycle.disable()), []);
1801
- const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
1802
- M(() => {
1873
+ const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0, i = s.state.tokens.use();
1874
+ P(() => {
1803
1875
  s.lifecycle.syncParser(e, o);
1804
- }, [e, o]);
1805
- const i = s.state.tokens.use();
1806
- M(() => {
1876
+ }, [e, o]), P(() => {
1807
1877
  s.lifecycle.recoverFocus();
1808
1878
  }, [i]);
1809
1879
  }
1810
- const K = at(void 0);
1811
- K.displayName = "StoreContext";
1880
+ const et = at(void 0);
1881
+ et.displayName = "StoreContext";
1812
1882
  function E() {
1813
- const s = ct(K);
1814
- return bt(s), s;
1883
+ const s = ct(et);
1884
+ if (s === void 0)
1885
+ throw new Error("Store not found. Make sure to wrap component in StoreContext.");
1886
+ return s;
1815
1887
  }
1816
- const Ee = {
1817
- container: "div",
1818
- span: "span"
1819
- };
1820
- function Y(s, t) {
1821
- return t?.[s] ? t[s] : Ee[s];
1822
- }
1823
- function tt(s, t) {
1824
- const e = t?.[s];
1825
- return e ? Et(e) : void 0;
1826
- }
1827
- const q = {
1888
+ const X = {
1828
1889
  position: "absolute",
1829
1890
  left: -28,
1830
1891
  top: 2,
@@ -1847,16 +1908,16 @@ const q = {
1847
1908
  font: "inherit",
1848
1909
  lineHeight: 1
1849
1910
  }, gt = {
1850
- ...q,
1911
+ ...X,
1851
1912
  opacity: 1
1852
- }, Te = {
1913
+ }, Pe = {
1853
1914
  ...gt,
1854
1915
  cursor: "grabbing"
1855
- }, Ne = {
1916
+ }, Le = {
1856
1917
  position: "relative",
1857
1918
  paddingLeft: 4,
1858
1919
  transition: "opacity 0.2s ease"
1859
- }, ot = {
1920
+ }, it = {
1860
1921
  position: "absolute",
1861
1922
  left: 0,
1862
1923
  right: 0,
@@ -1865,17 +1926,17 @@ const q = {
1865
1926
  borderRadius: 1,
1866
1927
  pointerEvents: "none",
1867
1928
  zIndex: 10
1868
- }, pt = O(() => /* @__PURE__ */ Z("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: [
1869
- /* @__PURE__ */ f("circle", { cx: "5", cy: "3", r: "1.5" }),
1870
- /* @__PURE__ */ f("circle", { cx: "11", cy: "3", r: "1.5" }),
1871
- /* @__PURE__ */ f("circle", { cx: "5", cy: "8", r: "1.5" }),
1872
- /* @__PURE__ */ f("circle", { cx: "11", cy: "8", r: "1.5" }),
1873
- /* @__PURE__ */ f("circle", { cx: "5", cy: "13", r: "1.5" }),
1874
- /* @__PURE__ */ f("circle", { cx: "11", cy: "13", r: "1.5" })
1929
+ }, pt = O(() => /* @__PURE__ */ J("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: [
1930
+ /* @__PURE__ */ h("circle", { cx: "5", cy: "3", r: "1.5" }),
1931
+ /* @__PURE__ */ h("circle", { cx: "11", cy: "3", r: "1.5" }),
1932
+ /* @__PURE__ */ h("circle", { cx: "5", cy: "8", r: "1.5" }),
1933
+ /* @__PURE__ */ h("circle", { cx: "11", cy: "8", r: "1.5" }),
1934
+ /* @__PURE__ */ h("circle", { cx: "5", cy: "13", r: "1.5" }),
1935
+ /* @__PURE__ */ h("circle", { cx: "11", cy: "13", r: "1.5" })
1875
1936
  ] }));
1876
1937
  pt.displayName = "GripIcon";
1877
1938
  const vt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
1878
- const [r, o] = P(!1), [i, a] = P(!1), [c, l] = P(null), d = $(null), g = k(() => o(!0), []), u = k(() => o(!1), []), h = k(
1939
+ const [r, o] = M(!1), [i, a] = M(!1), [c, l] = M(null), d = H(null), f = k(() => o(!0), []), u = k(() => o(!1), []), g = k(
1879
1940
  (p) => {
1880
1941
  p.dataTransfer.effectAllowed = "move", p.dataTransfer.setData("text/plain", String(s)), a(!0), d.current && p.dataTransfer.setDragImage(d.current, 0, 0);
1881
1942
  },
@@ -1884,8 +1945,8 @@ const vt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
1884
1945
  a(!1), l(null);
1885
1946
  }, []), C = k((p) => {
1886
1947
  if (p.preventDefault(), p.dataTransfer.dropEffect = "move", !d.current) return;
1887
- const D = d.current.getBoundingClientRect(), W = D.top + D.height / 2;
1888
- l(p.clientY < W ? "before" : "after");
1948
+ const D = d.current.getBoundingClientRect(), G = D.top + D.height / 2;
1949
+ l(p.clientY < G ? "before" : "after");
1889
1950
  }, []), y = k((p) => {
1890
1951
  p.currentTarget.contains(p.relatedTarget) || l(null);
1891
1952
  }, []), b = k(
@@ -1893,139 +1954,123 @@ const vt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
1893
1954
  p.preventDefault();
1894
1955
  const D = parseInt(p.dataTransfer.getData("text/plain"), 10);
1895
1956
  if (isNaN(D)) return;
1896
- const W = c === "before" ? s : s + 1;
1897
- l(null), n(D, W);
1957
+ const G = c === "before" ? s : s + 1;
1958
+ l(null), n(D, G);
1898
1959
  },
1899
1960
  [s, c, n]
1900
- ), T = {
1901
- ...Ne,
1961
+ ), I = {
1962
+ ...Le,
1902
1963
  opacity: i ? 0.4 : 1
1903
- }, L = e ? { ...q, display: "none" } : i ? Te : r ? gt : q;
1904
- return /* @__PURE__ */ Z(
1964
+ }, L = e ? { ...X, display: "none" } : i ? Pe : r ? gt : X;
1965
+ return /* @__PURE__ */ J(
1905
1966
  "div",
1906
1967
  {
1907
1968
  ref: d,
1908
- style: T,
1909
- onMouseEnter: g,
1969
+ style: I,
1970
+ onMouseEnter: f,
1910
1971
  onMouseLeave: u,
1911
1972
  onDragOver: C,
1912
1973
  onDragLeave: y,
1913
1974
  onDrop: b,
1914
1975
  children: [
1915
- c === "before" && /* @__PURE__ */ f("div", { style: { ...ot, top: -1 } }),
1916
- /* @__PURE__ */ f(
1976
+ c === "before" && /* @__PURE__ */ h("div", { style: { ...it, top: -1 } }),
1977
+ /* @__PURE__ */ h(
1917
1978
  "button",
1918
1979
  {
1919
1980
  type: "button",
1920
1981
  draggable: !e,
1921
- onDragStart: h,
1982
+ onDragStart: g,
1922
1983
  onDragEnd: m,
1923
1984
  style: L,
1924
1985
  "aria-label": "Drag to reorder",
1925
- children: /* @__PURE__ */ f(pt, {})
1986
+ children: /* @__PURE__ */ h(pt, {})
1926
1987
  }
1927
1988
  ),
1928
1989
  t,
1929
- c === "after" && /* @__PURE__ */ f("div", { style: { ...ot, bottom: -1 } })
1990
+ c === "after" && /* @__PURE__ */ h("div", { style: { ...it, bottom: -1 } })
1930
1991
  ]
1931
1992
  }
1932
1993
  );
1933
1994
  });
1934
1995
  vt.displayName = "DraggableBlock";
1935
- const Ie = (s) => {
1936
- const t = at(void 0);
1937
- return t.displayName = s, [() => {
1938
- const n = ct(t);
1939
- if (n === void 0)
1940
- throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
1941
- return n;
1942
- }, t.Provider, t];
1943
- }, [et, it] = Ie("NodeProvider");
1996
+ const $ = at(void 0);
1997
+ $.displayName = "TokenProvider";
1998
+ function nt() {
1999
+ const s = ct($);
2000
+ if (s === void 0)
2001
+ throw new Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
2002
+ return s;
2003
+ }
1944
2004
  function mt(s, t, e, n) {
1945
- const r = E(), o = r.state.Mark.use(), i = r.state.Overlay.use(), a = s === "mark" ? o : i, c = s === "mark" ? t?.mark : t?.overlay;
1946
- let l;
1947
- c !== void 0 ? typeof c == "function" ? l = c(e) : l = c : l = e ?? {};
1948
- const d = l.slot || a || n;
2005
+ const r = E(), o = r.state.Mark.use(), i = r.state.Overlay.use(), a = s === "mark" ? o : i, c = s === "mark" ? t?.mark : t?.overlay, l = Nt(c, e ?? {}), d = l.slot || a || n;
1949
2006
  if (!d)
1950
2007
  throw new Error(
1951
2008
  `No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
1952
2009
  );
1953
2010
  return [d, l];
1954
2011
  }
1955
- function Pe() {
1956
- const s = et(), t = E(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((l) => /* @__PURE__ */ f(F, { mark: l, isNested: !0 }, n.get(l))), i = {
2012
+ function Ae() {
2013
+ const s = nt(), t = E(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((l) => /* @__PURE__ */ h(W, { mark: l, isNested: !0 }, n.get(l))), i = {
1957
2014
  value: s.value,
1958
2015
  meta: s.meta,
1959
2016
  nested: s.nested?.content,
1960
2017
  children: s.children.length > 0 ? o : void 0
1961
2018
  }, [a, c] = mt("mark", r, i);
1962
- return /* @__PURE__ */ f(a, { ...c });
2019
+ return /* @__PURE__ */ h(a, { ...c });
1963
2020
  }
1964
- const Me = () => {
1965
- const s = et(), t = E(), e = $(null), n = t.state.readOnly.use(), r = t.state.slots.use(), o = t.state.slotProps.use(), i = S(() => Y("span", r), [r]), a = S(() => tt("span", o), [o]);
2021
+ const Oe = () => {
2022
+ const s = nt(), t = E(), e = H(null), n = t.state.slots.use(), r = t.state.slotProps.use(), o = S(() => Q("span", n), [n]), i = S(() => K("span", r), [r]);
1966
2023
  if (s.type !== "text")
1967
2024
  throw new Error("TextSpan component expects a TextToken");
1968
2025
  return Ct(() => {
1969
2026
  e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
1970
- }, [s.content]), /* @__PURE__ */ f(i, { ...a, ref: e, contentEditable: !n, suppressContentEditableWarning: !0 });
1971
- }, F = O(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ f(it, { value: s, children: /* @__PURE__ */ f(Pe, {}) }) : t ? /* @__PURE__ */ f(wt, { children: s.content }) : /* @__PURE__ */ f(it, { value: s, children: /* @__PURE__ */ f(Me, {}) }));
1972
- F.displayName = "Token";
2027
+ }, [s.content]), /* @__PURE__ */ h(o, { ...i, ref: e });
2028
+ }, W = O(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ h($, { value: s, children: /* @__PURE__ */ h(Ae, {}) }) : t ? /* @__PURE__ */ h(wt, { children: s.content }) : /* @__PURE__ */ h($, { value: s, children: /* @__PURE__ */ h(Oe, {}) }));
2029
+ W.displayName = "Token";
1973
2030
  const yt = O(() => {
1974
- const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.state.readOnly.use(), a = s.state.value.use(), c = s.state.onChange.use(), l = s.key, d = s.refs, g = S(() => Y("container", e), [e]), u = S(() => tt("container", n), [n]), h = S(() => pe(t), [t]), m = $(h);
1975
- m.current = h;
2031
+ const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.state.readOnly.use(), a = s.state.value.use(), c = s.state.onChange.use(), l = s.key, d = s.refs, f = S(() => Q("container", e), [e]), u = S(() => K("container", n), [n]), g = S(() => we(t), [t]), m = H(g);
2032
+ m.current = g;
1976
2033
  const C = k(
1977
2034
  (y, b) => {
1978
2035
  if (!a || !c) return;
1979
- const T = m.current, L = me(a, T, y, b);
2036
+ const I = m.current, L = Ce(a, I, y, b);
1980
2037
  if (L !== a) {
1981
- const p = R(s, L);
2038
+ const p = _(s, L);
1982
2039
  s.state.tokens.set(p), s.state.previousValue.set(L), c(L);
1983
2040
  }
1984
2041
  },
1985
2042
  [s, a, c]
1986
2043
  );
1987
- return /* @__PURE__ */ f(
1988
- g,
2044
+ return /* @__PURE__ */ h(
2045
+ f,
1989
2046
  {
1990
2047
  ref: (y) => d.container = y,
1991
2048
  ...u,
1992
2049
  className: r,
1993
2050
  style: o,
1994
- children: h.map((y, b) => /* @__PURE__ */ f(vt, { blockIndex: b, readOnly: i, onReorder: C, children: y.tokens.map((T) => /* @__PURE__ */ f(F, { mark: T }, l.get(T))) }, y.id))
2051
+ children: g.map((y, b) => /* @__PURE__ */ h(vt, { blockIndex: b, readOnly: i, onReorder: C, children: y.tokens.map((I) => /* @__PURE__ */ h(W, { mark: I }, l.get(I))) }, y.id))
1995
2052
  }
1996
2053
  );
1997
2054
  });
1998
2055
  yt.displayName = "BlockContainer";
1999
2056
  const xt = O(() => {
2000
- const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.key, a = s.refs, c = S(() => Y("container", e), [e]), l = S(() => tt("container", n), [n]);
2001
- return /* @__PURE__ */ f(
2057
+ const s = E(), t = s.state.tokens.use(), e = s.state.slots.use(), n = s.state.slotProps.use(), r = s.state.className.use(), o = s.state.style.use(), i = s.key, a = s.refs, c = S(() => Q("container", e), [e]), l = S(() => K("container", n), [n]);
2058
+ return /* @__PURE__ */ h(
2002
2059
  c,
2003
2060
  {
2004
2061
  ref: (d) => a.container = d,
2005
2062
  ...l,
2006
2063
  className: r,
2007
2064
  style: o,
2008
- children: t.map((d) => /* @__PURE__ */ f(F, { mark: d }, i.get(d)))
2065
+ children: t.map((d) => /* @__PURE__ */ h(W, { mark: d }, i.get(d)))
2009
2066
  }
2010
2067
  );
2011
2068
  });
2012
2069
  xt.displayName = "Container";
2013
- function Le() {
2070
+ function De() {
2014
2071
  const s = E(), t = s.state.overlayMatch.use(), e = w.getAbsolutePosition(), n = k(() => s.events.clearOverlay(), []), r = k(
2015
2072
  (i) => {
2016
- const a = {
2017
- type: "mark",
2018
- value: i.value,
2019
- meta: i.meta,
2020
- content: "",
2021
- position: { start: t.index, end: t.index + t.span.length },
2022
- descriptor: {
2023
- index: 0,
2024
- markup: t.option.markup
2025
- },
2026
- children: [],
2027
- nested: void 0
2028
- };
2073
+ const a = pe(t, i.value, i.meta);
2029
2074
  s.events.select({ mark: a, match: t }), s.events.clearOverlay();
2030
2075
  },
2031
2076
  [t]
@@ -2042,57 +2087,51 @@ function Le() {
2042
2087
  );
2043
2088
  return { match: t, style: e, select: r, close: n, ref: o };
2044
2089
  }
2045
- const Ae = "_Container_1lmfr_1", Oe = "_Suggestions_1lmfr_10", De = "_suggestionActive_1lmfr_38", X = {
2046
- Container: Ae,
2047
- Suggestions: Oe,
2048
- suggestionActive: De
2049
- }, Re = () => {
2050
- const s = E(), { match: t, select: e, style: n, ref: r } = Le(), [o, i] = P(NaN), a = t.option.overlay?.data || [], c = S(
2051
- () => a.filter((d) => d.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
2052
- [t.value, a]
2053
- ), l = c.length;
2054
- return M(() => {
2090
+ const Re = "_Container_1lmfr_1", _e = "_Suggestions_1lmfr_10", Be = "_suggestionActive_1lmfr_38", Z = {
2091
+ Container: Re,
2092
+ Suggestions: _e,
2093
+ suggestionActive: Be
2094
+ }, Ve = () => {
2095
+ const s = E(), { match: t, select: e, style: n, ref: r } = De(), [o, i] = M(NaN), a = t.option.overlay?.data || [], c = S(() => ge(a, t.value), [t.value, a]), l = c.length;
2096
+ return P(() => {
2055
2097
  const d = s.refs.container;
2056
2098
  if (!d) return;
2057
- const g = (u) => {
2058
- switch (u.key) {
2059
- case v.UP:
2060
- u.preventDefault(), i((h) => isNaN(h) ? 0 : (l + (h - 1) % l) % l);
2061
- break;
2062
- case v.DOWN:
2063
- u.preventDefault(), i((h) => isNaN(h) ? 0 : (h + 1) % l);
2099
+ const f = (u) => {
2100
+ const g = me(u.key, o, l);
2101
+ switch (g.action) {
2102
+ case "up":
2103
+ case "down":
2104
+ u.preventDefault(), i(g.index);
2064
2105
  break;
2065
- case v.ENTER:
2066
- u.preventDefault(), i((h) => {
2067
- if (isNaN(h)) return h;
2068
- const m = c[h];
2069
- return e({ value: m, meta: h.toString() }), h;
2070
- });
2106
+ case "select":
2107
+ u.preventDefault();
2108
+ const m = c[g.index];
2109
+ e({ value: m, meta: g.index.toString() });
2071
2110
  break;
2072
2111
  }
2073
2112
  };
2074
- return d.addEventListener("keydown", g), () => d.removeEventListener("keydown", g);
2075
- }, [l, c]), c.length ? /* @__PURE__ */ f("ul", { ref: r, className: X.Suggestions, style: n, children: c.map((d, g) => {
2076
- const u = g === o ? X.suggestionActive : void 0;
2077
- return /* @__PURE__ */ f(
2113
+ return d.addEventListener("keydown", f), () => d.removeEventListener("keydown", f);
2114
+ }, [l, c, o]), c.length ? /* @__PURE__ */ h("ul", { ref: r, className: Z.Suggestions, style: n, children: c.map((d, f) => {
2115
+ const u = f === o ? Z.suggestionActive : void 0;
2116
+ return /* @__PURE__ */ h(
2078
2117
  "li",
2079
2118
  {
2080
- ref: (h) => {
2081
- u && h && h.scrollIntoView(!1);
2119
+ ref: (g) => {
2120
+ u && g && g.scrollIntoView(!1);
2082
2121
  },
2083
2122
  className: u,
2084
- onClick: (h) => e({ value: d, meta: g.toString() }),
2123
+ onClick: (g) => e({ value: d, meta: f.toString() }),
2085
2124
  children: d
2086
2125
  },
2087
2126
  d
2088
2127
  );
2089
2128
  }) }) : null;
2090
2129
  }, kt = O(() => {
2091
- const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = mt("overlay", t?.option, void 0, Re);
2092
- if (e) return /* @__PURE__ */ f(n, { ...r ?? {} }, e);
2130
+ const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = mt("overlay", t?.option, void 0, Ve);
2131
+ if (e) return /* @__PURE__ */ h(n, { ...r ?? {} }, e);
2093
2132
  });
2094
2133
  kt.displayName = "OverlayRenderer";
2095
- function Fe(s) {
2134
+ function Ue(s) {
2096
2135
  const {
2097
2136
  ref: t,
2098
2137
  value: e,
@@ -2104,17 +2143,17 @@ function Fe(s) {
2104
2143
  Overlay: c,
2105
2144
  slots: l,
2106
2145
  slotProps: d,
2107
- options: g = Se,
2146
+ options: f = Lt,
2108
2147
  showOverlayOn: u = "change",
2109
- className: h,
2148
+ className: g,
2110
2149
  style: m
2111
- } = s, C = Tt(X.Container, h, d?.container?.className), y = Nt(m, d?.container?.style), [b] = P(() => new he({ createUseHook: Ce }));
2112
- b.state.set({
2150
+ } = s, C = Et(Z.Container, g, d?.container?.className), y = Tt(m, d?.container?.style), [b] = M(() => new ye({ createUseHook: Ie }));
2151
+ return b.state.set({
2113
2152
  value: e,
2114
2153
  defaultValue: n,
2115
2154
  onChange: r,
2116
2155
  readOnly: o,
2117
- options: g,
2156
+ options: f,
2118
2157
  showOverlayOn: u,
2119
2158
  Mark: a,
2120
2159
  Overlay: c,
@@ -2122,36 +2161,34 @@ function Fe(s) {
2122
2161
  style: y,
2123
2162
  slots: l,
2124
2163
  slotProps: d
2125
- }), be(b, t);
2126
- const T = i ? yt : xt;
2127
- return /* @__PURE__ */ Z(K.Provider, { value: b, children: [
2128
- /* @__PURE__ */ f(T, {}),
2129
- /* @__PURE__ */ f(kt, {})
2164
+ }), Me(b, t), /* @__PURE__ */ J(et, { value: b, children: [
2165
+ /* @__PURE__ */ h(i ? yt : xt, {}),
2166
+ /* @__PURE__ */ h(kt, {})
2130
2167
  ] });
2131
2168
  }
2132
- const We = (s = {}) => {
2133
- const t = E(), e = et(), n = $(null);
2169
+ const je = (s = {}) => {
2170
+ const t = E(), e = nt(), n = H(null);
2134
2171
  if (e.type !== "mark")
2135
2172
  throw new Error("useMark can only be used with mark tokens");
2136
- const [r] = P(() => new fe({ ref: n, store: t, token: e }));
2137
- _e(n, s, e);
2173
+ const [r] = M(() => new xe({ ref: n, store: t, token: e }));
2174
+ $e(n, s, e);
2138
2175
  const o = t.state.readOnly.use();
2139
- return M(() => {
2176
+ return P(() => {
2140
2177
  r.readOnly = o;
2141
2178
  }, [o]), r;
2142
2179
  };
2143
- function _e(s, t, e) {
2144
- M(() => {
2180
+ function $e(s, t, e) {
2181
+ P(() => {
2145
2182
  s.current && !t.controlled && (s.current.textContent = e.content);
2146
2183
  }, []);
2147
2184
  }
2148
2185
  export {
2149
- fe as MarkHandler,
2150
- Fe as MarkedInput,
2151
- j as annotate,
2152
- He as denote,
2153
- me as reorderBlocks,
2154
- pe as splitTokensIntoBlocks,
2155
- We as useMark,
2156
- Le as useOverlay
2186
+ xe as MarkHandler,
2187
+ Ue as MarkedInput,
2188
+ q as annotate,
2189
+ Ge as denote,
2190
+ Ce as reorderBlocks,
2191
+ we as splitTokensIntoBlocks,
2192
+ je as useMark,
2193
+ De as useOverlay
2157
2194
  };