@markput/react 0.2.0 → 0.3.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 (4) hide show
  1. package/README.md +3 -1
  2. package/index.d.ts +11 -0
  3. package/index.js +603 -329
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -1,109 +1,109 @@
1
1
  import "./index.css";
2
- import { jsx as f, Fragment as it, jsxs as at } from "react/jsx-runtime";
3
- import { createContext as X, useContext as Z, useRef as J, useMemo as C, useLayoutEffect as ct, memo as D, useCallback as B, useState as L, useEffect as S, useImperativeHandle as lt } from "react";
4
- function dt(s) {
2
+ import { jsx as f, Fragment as wt, jsxs as Z } from "react/jsx-runtime";
3
+ import { createContext as at, useContext as ct, useRef as H, useMemo as S, useLayoutEffect as St, memo as O, useState as P, useCallback as k, useEffect as M, useImperativeHandle as Ct } from "react";
4
+ function bt(s) {
5
5
  if (s == null) throw new Error("Value must be a non nullable!");
6
6
  }
7
- function ht(s) {
7
+ function Et(s) {
8
8
  return s ? Object.fromEntries(
9
9
  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
10
  ) : {};
11
11
  }
12
- function ut(...s) {
12
+ function Tt(...s) {
13
13
  return s.filter(Boolean).join(" ") || void 0;
14
14
  }
15
- function gt(...s) {
15
+ function Nt(...s) {
16
16
  const t = Object.assign({}, ...s.filter(Boolean));
17
17
  return Object.keys(t).length > 0 ? t : void 0;
18
18
  }
19
- 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 ft = "@", pt = "@[__value__](__meta__)", p = {
19
+ var x = /* @__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))(x || {});
20
+ const It = "@", Pt = "@[__value__](__meta__)", y = {
21
21
  Value: "__value__",
22
22
  Meta: "__meta__",
23
23
  Nested: "__nested__"
24
- }, x = {
24
+ }, N = {
25
25
  Value: "value",
26
26
  Meta: "meta",
27
27
  Nested: "nested"
28
28
  };
29
- function vt(s, t) {
30
- const { segments: e, gapTypes: n, counts: r, valueGapIndices: o } = mt(s);
31
- xt(r, s);
32
- const i = r.value === 2, { segments: a, gapTypes: l } = i ? yt(e, n, o) : { segments: e, gapTypes: n };
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 };
33
33
  return {
34
34
  markup: s,
35
35
  index: t,
36
36
  segments: a,
37
- gapTypes: l,
37
+ gapTypes: c,
38
38
  hasNested: r.nested === 1,
39
39
  hasTwoValues: i,
40
40
  segmentGlobalIndices: Array.from({ length: a.length })
41
41
  // Will be populated by MarkupRegistry
42
42
  };
43
43
  }
44
- function mt(s) {
44
+ function Lt(s) {
45
45
  const t = [], e = [], n = [], r = {
46
46
  value: 0,
47
47
  meta: 0,
48
48
  nested: 0
49
- }, o = [], i = [x.Value, x.Meta, x.Nested];
50
- for (const c of i) {
51
- const d = j[c];
52
- let u = s.indexOf(d);
53
- for (; u !== -1; )
54
- o.push({ type: c, position: u }), u = s.indexOf(d, u + d.length);
55
- }
56
- o.sort((c, d) => c.position - d.position);
49
+ }, o = [], i = [N.Value, N.Meta, N.Nested];
50
+ 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);
55
+ }
56
+ o.sort((l, d) => l.position - d.position);
57
57
  let a = 0;
58
- for (const c of o) {
59
- const d = s.substring(a, c.position);
60
- d.length > 0 && t.push(d), e.push(c.type), r[c.type]++, c.type === x.Value && n.push(e.length - 1), a = c.position + j[c.type].length;
58
+ for (const l of o) {
59
+ 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;
61
61
  }
62
- const l = s.substring(a);
63
- return l.length > 0 && t.push(l), {
62
+ const c = s.substring(a);
63
+ return c.length > 0 && t.push(c), {
64
64
  segments: t,
65
65
  gapTypes: e,
66
66
  counts: r,
67
67
  valueGapIndices: n
68
68
  };
69
69
  }
70
- function xt(s, t) {
70
+ function At(s, t) {
71
71
  const e = [
72
- { count: s.value, max: 2, name: p.Value },
73
- { count: s.meta, max: 1, name: p.Meta },
74
- { count: s.nested, max: 1, name: p.Nested }
72
+ { count: s.value, max: 2, name: y.Value },
73
+ { count: s.meta, max: 1, name: y.Meta },
74
+ { count: s.nested, max: 1, name: y.Nested }
75
75
  ];
76
76
  for (const { count: n, max: r, name: o } of e)
77
77
  if (n > r)
78
78
  throw new Error(`Invalid markup: "${t}". Max ${r} "${o}" placeholders, got ${n}`);
79
79
  if (s.value === 0 && s.nested === 0)
80
80
  throw new Error(
81
- `Invalid markup: "${t}". Need at least one "${p.Value}" or "${p.Nested}"`
81
+ `Invalid markup: "${t}". Need at least one "${y.Value}" or "${y.Nested}"`
82
82
  );
83
83
  }
84
- const j = {
85
- [x.Value]: p.Value,
86
- [x.Meta]: p.Meta,
87
- [x.Nested]: p.Nested
84
+ const nt = {
85
+ [N.Value]: y.Value,
86
+ [N.Meta]: y.Meta,
87
+ [N.Nested]: y.Nested
88
88
  };
89
- function yt(s, t, e) {
89
+ function Ot(s, t, e) {
90
90
  if (e.length !== 2)
91
91
  return { segments: s, gapTypes: t };
92
92
  const [n, r] = e, o = [], i = s[n], a = s[n + 1];
93
- i && a && o.push(u(i, a, s[n + 2]));
94
- for (let h = n + 2; h < r; h++)
95
- o.push(s[h]);
96
- const l = s[r], c = s[r + 1];
97
- l && c && o.push(u(l, c, s[r + 2]));
98
- const d = t.filter((h) => h !== x.Value);
93
+ i && a && o.push(g(i, a, s[n + 2]));
94
+ for (let u = n + 2; u < r; u++)
95
+ o.push(s[u]);
96
+ 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);
99
99
  return { segments: o, gapTypes: d };
100
- function u(h, g, w) {
101
- if (!w) return [h, g, ""];
102
- const E = w.charAt(0), T = E && !g.includes(E) && !w.startsWith(h) ? E : "";
103
- return [h, g, T];
100
+ function g(u, h, v) {
101
+ if (!v) return [u, h, ""];
102
+ const C = v.charAt(0), m = C && !h.includes(C) && !v.startsWith(u) ? C : "";
103
+ return [u, h, m];
104
104
  }
105
105
  }
106
- class kt {
106
+ class Dt {
107
107
  markups;
108
108
  descriptors;
109
109
  /** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */
@@ -116,7 +116,7 @@ class kt {
116
116
  this.descriptors = t.map((n, r) => {
117
117
  if (n === void 0)
118
118
  return null;
119
- const o = vt(n, r);
119
+ const o = Mt(n, r);
120
120
  return o.segments.forEach((i, a) => {
121
121
  this.processSegment(o, i, a, e);
122
122
  }), this.addToFirstSegmentIndexMap(o), o;
@@ -137,8 +137,8 @@ class kt {
137
137
  this.registerSegment(e, o, r);
138
138
  const i = r.get(o);
139
139
  if (t.segmentGlobalIndices[n] = i, typeof e != "string") {
140
- const [a, l] = e;
141
- a && this.registerSegment(a, a, r), l && this.registerSegment(l, l, r);
140
+ const [a, c] = e;
141
+ a && this.registerSegment(a, a, r), c && this.registerSegment(c, c, r);
142
142
  }
143
143
  }
144
144
  registerSegment(t, e, n) {
@@ -160,7 +160,7 @@ class kt {
160
160
  return e || n ? `${e}|${n}|${r}` : "";
161
161
  }
162
162
  }
163
- function Q(s, t) {
163
+ function lt(s, t) {
164
164
  if (!t)
165
165
  return s;
166
166
  let e = 5381;
@@ -168,7 +168,7 @@ function Q(s, t) {
168
168
  e = e * 33 ^ t.charCodeAt(n);
169
169
  return e = e >>> 0, s * 1e6 + (e & 1048575);
170
170
  }
171
- class wt {
171
+ class _t {
172
172
  constructor(t, e) {
173
173
  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
174
  this.captured = e.captured;
@@ -215,7 +215,7 @@ class wt {
215
215
  const t = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex], e = this.descriptor.segments[this.expectedSegmentIndex];
216
216
  if (typeof e == "object" && this.descriptor.hasTwoValues && this.captured && this.isAwaitingLastSegment) {
217
217
  const [n, r] = e, o = n + this.captured + r;
218
- return Q(t, o);
218
+ return lt(t, o);
219
219
  }
220
220
  return t;
221
221
  }
@@ -237,7 +237,7 @@ class wt {
237
237
  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
238
  }
239
239
  }
240
- class St {
240
+ class Rt {
241
241
  constructor(t) {
242
242
  this.registry = t;
243
243
  }
@@ -266,7 +266,7 @@ class St {
266
266
  }
267
267
  tryStartNewStates(t) {
268
268
  this.registry.firstSegmentIndexMap.get(t.index)?.forEach((e) => {
269
- const n = new wt(e, t);
269
+ const n = new _t(e, t);
270
270
  if (!n.isInvalid) {
271
271
  if (n.isCompleted) return this.addToCompleted(n);
272
272
  this.addToWaiting(n);
@@ -278,7 +278,7 @@ class St {
278
278
  * Uses value-specific index for dynamic segments, base index for static segments
279
279
  */
280
280
  dequeueWaitingMatch(t) {
281
- const e = t.captured ? Q(t.index, t.value) : t.index, n = this.completingStates.get(e);
281
+ const e = t.captured ? lt(t.index, t.value) : t.index, n = this.completingStates.get(e);
282
282
  if (n?.length) return n.pop();
283
283
  const r = this.pendingStates.get(e);
284
284
  if (r?.length) return r.pop();
@@ -311,12 +311,12 @@ class St {
311
311
  n < this.completedStates.length && this.completedStates[n].position === e ? this.completedStates[n].match = t : this.completedStates.splice(n, 0, { position: e, match: t });
312
312
  }
313
313
  }
314
- const b = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
315
- function Ct(s, t, e) {
316
- const n = b(s), r = b(t), o = b(t + e);
314
+ const A = (s) => s.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
315
+ function Vt(s, t, e) {
316
+ const n = A(s), r = A(t), o = A(t + e);
317
317
  return `${n}([^${o}]+?)${r}`;
318
318
  }
319
- class bt {
319
+ class $t {
320
320
  staticRegex;
321
321
  staticToIndex;
322
322
  dynamicRegex;
@@ -330,25 +330,25 @@ class bt {
330
330
  if (t.forEach((o, i) => {
331
331
  typeof o == "string" ? (e.push(o), r.set(o, i)) : n.push(o);
332
332
  }), e.length > 0) {
333
- const i = [...e].sort((a, l) => l.length - a.length).map(b);
333
+ const i = [...e].sort((a, c) => c.length - a.length).map(A);
334
334
  this.staticRegex = new RegExp(`(?:${i.join("|")})`, "gu"), this.staticToIndex = r;
335
335
  }
336
336
  if (n.length > 0) {
337
337
  const o = /* @__PURE__ */ new Set(), i = [];
338
338
  n.forEach((a) => {
339
- const l = t.indexOf(a);
339
+ const c = t.indexOf(a);
340
340
  if (typeof a == "string")
341
- i.push({ index: l, pattern: b(a), definition: a });
341
+ i.push({ index: c, pattern: A(a), definition: a });
342
342
  else {
343
- const [c, d, u] = a;
344
- o.add(l);
345
- const g = Ct(c, d, u).replace("(", `(?<content${l}>`);
346
- i.push({ index: l, pattern: g, definition: a });
343
+ const [l, d, g] = a;
344
+ o.add(c);
345
+ const h = Vt(l, d, g).replace("(", `(?<content${c}>`);
346
+ i.push({ index: c, pattern: h, definition: a });
347
347
  }
348
- }), i.sort((a, l) => {
349
- const c = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
350
- return (typeof l.definition == "string" ? l.definition.length : l.pattern.length) - c;
351
- }), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a, l) => `(?<seg${l}>${a.pattern})`).join("|"), "gu");
348
+ }), i.sort((a, c) => {
349
+ const l = typeof a.definition == "string" ? a.definition.length : a.pattern.length;
350
+ return (typeof c.definition == "string" ? c.definition.length : c.pattern.length) - l;
351
+ }), this.dynamicEntries = i, this.dynamicIndices = o, this.dynamicRegex = new RegExp(i.map((a, c) => `(?<seg${c}>${a.pattern})`).join("|"), "gu");
352
352
  }
353
353
  }
354
354
  search(t) {
@@ -366,20 +366,20 @@ class bt {
366
366
  if (this.dynamicRegex && this.dynamicEntries && this.dynamicIndices)
367
367
  for (const o of t.matchAll(this.dynamicRegex)) {
368
368
  const i = o[0], a = o.index;
369
- let l, c;
369
+ let c, l;
370
370
  if (o.groups) {
371
371
  for (let d = 0; d < this.dynamicEntries.length; d++)
372
372
  if (o.groups[`seg${d}`] !== void 0) {
373
- l = this.dynamicEntries[d].index, this.dynamicIndices.has(l) && (c = o.groups[`content${l}`]);
373
+ c = this.dynamicEntries[d].index, this.dynamicIndices.has(c) && (l = o.groups[`content${c}`]);
374
374
  break;
375
375
  }
376
376
  }
377
- l !== void 0 && n.push({
378
- index: l,
377
+ c !== void 0 && n.push({
378
+ index: c,
379
379
  start: a,
380
380
  end: a + i.length,
381
381
  value: i,
382
- captured: c
382
+ captured: l
383
383
  });
384
384
  }
385
385
  const r = [...n];
@@ -390,12 +390,12 @@ class bt {
390
390
  return r.sort((o, i) => o.start - i.start), r;
391
391
  }
392
392
  }
393
- const K = (s, t = 0, e = s.length) => ({
393
+ const dt = (s, t = 0, e = s.length) => ({
394
394
  type: "text",
395
395
  content: s.substring(t, e),
396
396
  position: { start: t, end: e }
397
397
  });
398
- class Et {
398
+ class Ht {
399
399
  // Instance fields - only what's needed for single pass
400
400
  input;
401
401
  // ===== PUBLIC API =====
@@ -432,30 +432,30 @@ class Et {
432
432
  if (r && i.conflictsWith(r))
433
433
  continue;
434
434
  for (r = i; n.length > 0; ) {
435
- const c = n[n.length - 1], d = this.getContentBounds(c.match);
435
+ const l = n[n.length - 1], d = this.getContentBounds(l.match);
436
436
  if (d.end <= i.start)
437
- this.finalizeParent(c, d.end), n.pop(), n.length > 0 ? n[n.length - 1].token.children.push(c.token) : e.push(c.token);
437
+ this.finalizeParent(l, d.end), n.pop(), n.length > 0 ? n[n.length - 1].token.children.push(l.token) : e.push(l.token);
438
438
  else
439
439
  break;
440
440
  }
441
441
  const a = n.length > 0 ? n[n.length - 1] : null;
442
442
  if (a) {
443
- const c = this.createTextToken(a.textPos, i.start);
444
- a.token.children.push(c), a.textPos = i.end;
443
+ const l = this.createTextToken(a.textPos, i.start);
444
+ a.token.children.push(l), a.textPos = i.end;
445
445
  } else {
446
- const c = this.createTextToken(o, i.start);
447
- e.push(c), o = i.end;
446
+ const l = this.createTextToken(o, i.start);
447
+ e.push(l), o = i.end;
448
448
  }
449
- const l = this.createMarkToken(i);
449
+ const c = this.createMarkToken(i);
450
450
  if (this.hasNestedContent(i)) {
451
- const c = this.getContentBounds(i);
451
+ const l = this.getContentBounds(i);
452
452
  n.push({
453
453
  match: i,
454
- token: l,
455
- textPos: c.start
454
+ token: c,
455
+ textPos: l.start
456
456
  });
457
457
  } else
458
- a ? a.token.children.push(l) : e.push(l);
458
+ a ? a.token.children.push(c) : e.push(c);
459
459
  }
460
460
  for (; n.length > 0; ) {
461
461
  const i = n.pop(), a = this.getContentBounds(i.match);
@@ -514,7 +514,7 @@ class Et {
514
514
  * Creates a text token for a range in the input
515
515
  */
516
516
  createTextToken(t, e) {
517
- return K(this.input, t, e);
517
+ return dt(this.input, t, e);
518
518
  }
519
519
  /**
520
520
  * Creates nested info object if nested content exists
@@ -528,19 +528,19 @@ class Et {
528
528
  };
529
529
  }
530
530
  }
531
- function $(s, t) {
531
+ function j(s, t) {
532
532
  let e = s;
533
- return t.value !== void 0 && (e = e.replaceAll(p.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(p.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(p.Nested, t.nested)), e;
533
+ return t.value !== void 0 && (e = e.replaceAll(y.Value, t.value)), t.meta !== void 0 && (e = e.replaceAll(y.Meta, t.meta)), t.nested !== void 0 && (e = e.replaceAll(y.Nested, t.nested)), e;
534
534
  }
535
- function y(s) {
535
+ function I(s) {
536
536
  let t = "";
537
537
  for (const e of s) {
538
538
  if (e.type === "text") {
539
539
  t += e.content;
540
540
  continue;
541
541
  }
542
- const n = e.descriptor.markup, r = n.includes(p.Nested) ? e.children.length > 0 ? y(e.children) : e.nested?.content : void 0;
543
- t += $(n, {
542
+ const n = e.descriptor.markup, r = n.includes(y.Nested) ? e.children.length > 0 ? I(e.children) : e.nested?.content : void 0;
543
+ t += j(n, {
544
544
  value: e.value,
545
545
  meta: e.meta,
546
546
  nested: r
@@ -548,13 +548,13 @@ function y(s) {
548
548
  }
549
549
  return t;
550
550
  }
551
- function H(s, t) {
551
+ function J(s, t) {
552
552
  let e = "";
553
553
  for (const n of s)
554
554
  if (n.type === "text")
555
555
  e += n.content;
556
556
  else if (n.children.length > 0) {
557
- const r = H(n.children, t), o = {
557
+ const r = J(n.children, t), o = {
558
558
  ...n,
559
559
  value: r
560
560
  };
@@ -563,7 +563,7 @@ function H(s, t) {
563
563
  e += t(n);
564
564
  return e;
565
565
  }
566
- class A {
566
+ class B {
567
567
  registry;
568
568
  segmentMatcher;
569
569
  patternMatcher;
@@ -588,7 +588,7 @@ class A {
588
588
  * ```
589
589
  */
590
590
  constructor(t) {
591
- this.registry = new kt(t), this.segmentMatcher = new bt(this.registry.segments), this.patternMatcher = new St(this.registry), this.treeBuilder = new Et();
591
+ this.registry = new Dt(t), this.segmentMatcher = new $t(this.registry.segments), this.patternMatcher = new Rt(this.registry), this.treeBuilder = new Ht();
592
592
  }
593
593
  /**
594
594
  * Parses text into tokens (static convenience method)
@@ -606,7 +606,7 @@ class A {
606
606
  */
607
607
  static parse(t, e) {
608
608
  const n = e?.markup;
609
- return !n || n.length === 0 ? [K(t)] : new A(n).parse(t);
609
+ return !n || n.length === 0 ? [dt(t)] : new B(n).parse(t);
610
610
  }
611
611
  /**
612
612
  * Converts tokens back to text (static convenience method)
@@ -620,7 +620,7 @@ class A {
620
620
  * ```
621
621
  */
622
622
  static stringify(t) {
623
- return y(t);
623
+ return I(t);
624
624
  }
625
625
  /**
626
626
  * Parses text into a nested token tree
@@ -667,7 +667,7 @@ class A {
667
667
  * ```
668
668
  */
669
669
  stringify(t) {
670
- return y(t);
670
+ return I(t);
671
671
  }
672
672
  /**
673
673
  * Transforms annotated text by processing all mark tokens with a callback
@@ -696,7 +696,7 @@ class A {
696
696
  */
697
697
  transform(t, e) {
698
698
  const n = this.parse(t);
699
- return H(n, e);
699
+ return J(n, e);
700
700
  }
701
701
  /**
702
702
  * Escapes markup segments in the given text using backslash
@@ -738,21 +738,21 @@ class A {
738
738
  return t.replaceAll(/\\(.)/g, "$1");
739
739
  }
740
740
  }
741
- function ve(s, t, e) {
741
+ function Be(s, t, e) {
742
742
  if (!e.length) return s;
743
- const n = new A(e).parse(s);
744
- return H(n, t);
743
+ const n = new B(e).parse(s);
744
+ return J(n, t);
745
745
  }
746
- function V(s, t, e = 0, n) {
746
+ function z(s, t, e = 0, n) {
747
747
  for (const r of s) {
748
748
  if (r === t) return { depth: e, parent: n };
749
749
  if (r.type === "mark") {
750
- const o = V(r.children, t, e + 1, r);
750
+ const o = z(r.children, t, e + 1, r);
751
751
  if (o) return o;
752
752
  }
753
753
  }
754
754
  }
755
- function Tt(s = "", t = "") {
755
+ function Bt(s = "", t = "") {
756
756
  if (s === t) return {};
757
757
  let e;
758
758
  for (let r = 0; r < s.length; r++)
@@ -768,7 +768,7 @@ function Tt(s = "", t = "") {
768
768
  }
769
769
  return { left: e, right: n };
770
770
  }
771
- function q(s, t) {
771
+ function st(s, t) {
772
772
  let e = -1, n = s.length;
773
773
  for (; n - e > 1; ) {
774
774
  const r = Math.round((e + n) / 2);
@@ -776,53 +776,53 @@ function q(s, t) {
776
776
  }
777
777
  return s[e] == t && (n = e), [e, n].filter((r) => s[r] !== void 0);
778
778
  }
779
- function It(s) {
779
+ function Ft(s) {
780
780
  const { focus: t } = s.nodes, e = s.state.parser.get(), n = s.state.tokens.get();
781
781
  if (!e)
782
782
  return n;
783
783
  const r = e.parse(t.content);
784
784
  return r.length === 1 ? n : n.toSpliced(t.index, 1, ...r);
785
785
  }
786
- function Mt(s) {
787
- const t = s.state.value.get(), e = Nt(s), n = Tt(s.state.previousValue.get(), t);
786
+ function Wt(s) {
787
+ const t = s.state.value.get(), e = Gt(s), n = Bt(s.state.previousValue.get(), t);
788
788
  if (!n.left && !n.right)
789
789
  return s.state.previousValue.set(t), s.state.tokens.get();
790
790
  s.state.previousValue.set(t);
791
791
  const r = s.state.tokens.get();
792
792
  switch (!0) {
793
793
  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 = O(s, o - 1, o);
794
+ const o = e.indexOf(n.left), i = G(s, o - 1, o);
795
795
  return r.toSpliced(o - 1, 2, ...i);
796
796
  }
797
797
  case n.left !== void 0: {
798
- const [o] = q(e, n.left), i = O(s, o);
798
+ const [o] = st(e, n.left), i = G(s, o);
799
799
  return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
800
800
  }
801
801
  case n.right !== void 0: {
802
- const [o] = q(e, n.right), i = O(s, o);
802
+ const [o] = st(e, n.right), i = G(s, o);
803
803
  return i.length === 1 ? r : r.toSpliced(o, 1, ...i);
804
804
  }
805
805
  default:
806
- return P(s, t ?? "");
806
+ return _(s, t ?? "");
807
807
  }
808
808
  }
809
- function O(s, ...t) {
809
+ function G(s, ...t) {
810
810
  let e = "";
811
811
  const n = s.state.tokens.get();
812
812
  for (const r of t) {
813
813
  const o = n[r];
814
814
  e += o.content;
815
815
  }
816
- return P(s, e);
816
+ return _(s, e);
817
817
  }
818
- function Nt(s) {
818
+ function Gt(s) {
819
819
  let t = 0;
820
820
  return s.state.tokens.get().map((n) => {
821
821
  const r = n.content.length;
822
822
  return t += r, t - r;
823
823
  }) ?? [];
824
824
  }
825
- function P(s, t) {
825
+ function _(s, t) {
826
826
  const e = s.state.parser.get();
827
827
  return e ? e.parse(t) : [
828
828
  {
@@ -832,16 +832,16 @@ function P(s, t) {
832
832
  }
833
833
  ];
834
834
  }
835
- const Pt = (s, t) => s === t;
836
- class I {
835
+ const Ut = (s, t) => s === t;
836
+ class R {
837
837
  #t;
838
838
  #e = /* @__PURE__ */ new Set();
839
839
  #n;
840
840
  constructor(t, e) {
841
- this.#t = t, this.#n = e?.equals ?? Pt;
841
+ this.#t = t, this.#n = e?.equals ?? Ut;
842
842
  }
843
843
  static event() {
844
- return new I(void 0, { equals: !1 });
844
+ return new R(void 0, { equals: !1 });
845
845
  }
846
846
  get value() {
847
847
  return this.#t;
@@ -862,14 +862,14 @@ class I {
862
862
  this.value = t;
863
863
  }
864
864
  }
865
- function Lt(s, t) {
865
+ function jt(s, t) {
866
866
  const e = {};
867
867
  return e.get = () => s.get(), e.set = (n) => s.set(n), e.on = (n) => s.on(n), e.use = t(e), e;
868
868
  }
869
- function At(s, t) {
869
+ function zt(s, t) {
870
870
  const e = /* @__PURE__ */ new Map();
871
871
  for (const n in s)
872
- e.set(n, new I(s[n]));
872
+ e.set(n, new R(s[n]));
873
873
  return new Proxy(s, {
874
874
  get(n, r) {
875
875
  if (r === "set")
@@ -879,35 +879,35 @@ function At(s, t) {
879
879
  };
880
880
  const o = e.get(r);
881
881
  if (o)
882
- return Lt(o, t);
882
+ return jt(o, t);
883
883
  }
884
884
  });
885
885
  }
886
- function Ot(s) {
886
+ function qt(s) {
887
887
  const t = function(e) {
888
888
  s.emit(e);
889
889
  };
890
890
  return t.on = (e) => s.on(e), t;
891
891
  }
892
- function _t(s) {
892
+ function Xt(s) {
893
893
  const t = [], e = /* @__PURE__ */ new Map();
894
894
  for (const n of t)
895
- e.set(n, I.event());
895
+ e.set(n, R.event());
896
896
  return new Proxy({}, {
897
897
  get(n, r) {
898
898
  let o = e.get(r);
899
- return o || (o = I.event(), e.set(r, o)), Ot(o);
899
+ return o || (o = R.event(), e.set(r, o)), qt(o);
900
900
  }
901
901
  });
902
902
  }
903
- class $t {
903
+ class Zt {
904
904
  #t = 1;
905
905
  #e = /* @__PURE__ */ new WeakMap();
906
906
  get(t) {
907
907
  return this.#e.has(t) ? this.#e.get(t) : (this.#e.set(t, this.#t), this.#t++);
908
908
  }
909
909
  }
910
- class m {
910
+ class w {
911
911
  static get isSelectedPosition() {
912
912
  const t = window.getSelection();
913
913
  if (t)
@@ -968,14 +968,14 @@ class m {
968
968
  r?.setStart(r.endContainer, e), r?.setEnd(r.endContainer, e);
969
969
  }
970
970
  }
971
- const Vt = new RegExp(/^\w*/);
972
- class F {
971
+ const Jt = new RegExp(/^\w*/);
972
+ class Q {
973
973
  span;
974
974
  node;
975
975
  dividedText;
976
976
  constructor() {
977
- const t = m.getCurrentPosition();
978
- this.node = m.getSelectedNode(), this.span = m.getFocusedSpan(), this.dividedText = this.getDividedTextBy(t);
977
+ const t = w.getCurrentPosition();
978
+ this.node = w.getSelectedNode(), this.span = w.getFocusedSpan(), this.dividedText = this.getDividedTextBy(t);
979
979
  }
980
980
  /**
981
981
  * Find overlay match in text using provided options and trigger extractor.
@@ -993,8 +993,8 @@ class F {
993
993
  * TriggerFinder.find(vueOptions, (opt) => opt.overlay?.trigger ?? '@')
994
994
  */
995
995
  static find(t, e) {
996
- if (t && m.isSelectedPosition)
997
- return new F().find(t, e);
996
+ if (t && w.isSelectedPosition)
997
+ return new Q().find(t, e);
998
998
  }
999
999
  getDividedTextBy(t) {
1000
1000
  return { left: this.span.slice(0, t), right: this.span.slice(t) };
@@ -1032,7 +1032,7 @@ class F {
1032
1032
  }
1033
1033
  matchRightPart() {
1034
1034
  const { right: t } = this.dividedText;
1035
- return { word: t.match(Vt)?.[0] };
1035
+ return { word: t.match(Jt)?.[0] };
1036
1036
  }
1037
1037
  matchLeftPart(t) {
1038
1038
  const e = this.makeTriggerRegex(t), { left: n } = this.dividedText, r = n.match(e);
@@ -1042,11 +1042,11 @@ class F {
1042
1042
  }
1043
1043
  //TODO new overlayMatch option if (isSpaceBeforeRequired) append space check for not first words '\\s'
1044
1044
  makeTriggerRegex(t) {
1045
- const e = b(t) + "(\\w*)$";
1045
+ const e = A(t) + "(\\w*)$";
1046
1046
  return new RegExp(e);
1047
1047
  }
1048
1048
  }
1049
- class M {
1049
+ class V {
1050
1050
  #t;
1051
1051
  #e;
1052
1052
  get target() {
@@ -1056,10 +1056,10 @@ class M {
1056
1056
  this.#t = t;
1057
1057
  }
1058
1058
  get next() {
1059
- return new M(this.target?.nextSibling, this.#e);
1059
+ return new V(this.target?.nextSibling, this.#e);
1060
1060
  }
1061
1061
  get prev() {
1062
- return new M(this.target?.previousSibling, this.#e);
1062
+ return new V(this.target?.previousSibling, this.#e);
1063
1063
  }
1064
1064
  get isSpan() {
1065
1065
  return this.index % 2 === 0;
@@ -1071,19 +1071,19 @@ class M {
1071
1071
  return this.target?.isContentEditable ?? !1;
1072
1072
  }
1073
1073
  get isCaretAtBeginning() {
1074
- return this.target ? m.getCaretIndex(this.target) === 0 : void 0;
1074
+ return this.target ? w.getCaretIndex(this.target) === 0 : void 0;
1075
1075
  }
1076
1076
  get isCaretAtEnd() {
1077
- return this.target ? m.getCaretIndex(this.target) === this.target.textContent?.length : void 0;
1077
+ return this.target ? w.getCaretIndex(this.target) === this.target.textContent?.length : void 0;
1078
1078
  }
1079
1079
  get index() {
1080
1080
  return this.target?.parentElement ? [...this.target.parentElement.children].indexOf(this.target) : -1;
1081
1081
  }
1082
1082
  get caret() {
1083
- return this.target ? m.getCaretIndex(this.target) : -1;
1083
+ return this.target ? w.getCaretIndex(this.target) : -1;
1084
1084
  }
1085
1085
  set caret(t) {
1086
- this.target && m.trySetIndex(this.target, t);
1086
+ this.target && w.trySetIndex(this.target, t);
1087
1087
  }
1088
1088
  get length() {
1089
1089
  return this.target?.textContent?.length ?? -1;
@@ -1107,7 +1107,7 @@ class M {
1107
1107
  this.target = t, this.#e = e;
1108
1108
  }
1109
1109
  setCaretToEnd() {
1110
- m.setCaretToEnd(this.target);
1110
+ w.setCaretToEnd(this.target);
1111
1111
  }
1112
1112
  focus() {
1113
1113
  this.target?.focus();
@@ -1116,19 +1116,19 @@ class M {
1116
1116
  this.target = void 0;
1117
1117
  }
1118
1118
  }
1119
- function Rt(s, t, e, n) {
1119
+ function Qt(s, t, e, n) {
1120
1120
  return s.slice(0, e) + t + s.slice(e + n.length);
1121
1121
  }
1122
- function _(s, t) {
1122
+ function U(s, t) {
1123
1123
  const n = {
1124
1124
  prev: 2,
1125
1125
  self: 1,
1126
1126
  next: 0
1127
- }[s], { focus: r } = t.nodes, o = t.state.tokens.get(), [i, , a] = o.splice(r.index - n, 3), l = (i.type === "text", i.content), c = (a.type === "text", a.content);
1127
+ }[s], { focus: r } = t.nodes, o = t.state.tokens.get(), [i, , a] = o.splice(r.index - n, 3), c = (i.type === "text", i.content), l = (a.type === "text", a.content);
1128
1128
  t.state.tokens.set(
1129
1129
  o.toSpliced(r.index - n, 0, {
1130
1130
  type: "text",
1131
- content: l + c,
1131
+ content: c + l,
1132
1132
  position: {
1133
1133
  start: i.position.start,
1134
1134
  end: a.position.end
@@ -1136,12 +1136,12 @@ function _(s, t) {
1136
1136
  })
1137
1137
  );
1138
1138
  let d = r;
1139
- for (let h = 0; h < n; h++)
1139
+ for (let u = 0; u < n; u++)
1140
1140
  d = d.prev;
1141
- const u = d.length;
1142
- t.state.recovery.set({ anchor: d.prev, caret: u }), t.state.onChange.get()?.(y(t.state.tokens.get()));
1141
+ const g = d.length;
1142
+ t.state.recovery.set({ anchor: d.prev, caret: g }), t.state.onChange.get()?.(I(t.state.tokens.get()));
1143
1143
  }
1144
- class Dt {
1144
+ class Kt {
1145
1145
  constructor(t) {
1146
1146
  this.store = t;
1147
1147
  }
@@ -1153,33 +1153,33 @@ class Dt {
1153
1153
  const t = this.store.state.onChange.get();
1154
1154
  if (!this.store.nodes.focus.target) return;
1155
1155
  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?.(y(e)), this.store.events.parse();
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
1157
  }), this.#e = this.store.events.delete.on((t) => {
1158
1158
  if (!t) return;
1159
1159
  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?.(y(this.store.state.tokens.get()));
1160
+ this.store.state.tokens.set(r.toSpliced(o, 1)), n?.(I(this.store.state.tokens.get()));
1161
1161
  }), this.#n = this.store.events.select.on((t) => {
1162
1162
  if (!t) return;
1163
1163
  const e = this.store.state.Mark.get(), n = this.store.state.onChange.get(), {
1164
1164
  mark: r,
1165
- match: { option: o, span: i, index: a, source: l }
1166
- } = t, c = r.type === "mark" ? $(o.markup, {
1165
+ match: { option: o, span: i, index: a, source: c }
1166
+ } = t, l = r.type === "mark" ? j(o.markup, {
1167
1167
  value: r.value,
1168
1168
  meta: r.meta
1169
- }) : $(o.markup, {
1169
+ }) : j(o.markup, {
1170
1170
  value: r.content
1171
- }), d = Rt(i, c, a, l);
1171
+ }), d = Qt(i, l, a, c);
1172
1172
  if (this.store.state.recovery.set(
1173
1173
  e ? {
1174
1174
  caret: 0,
1175
1175
  anchor: this.store.nodes.input.next,
1176
1176
  isNext: !0,
1177
1177
  childIndex: this.store.nodes.input.index
1178
- } : { caret: a + c.length, anchor: this.store.nodes.input }
1178
+ } : { caret: a + l.length, anchor: this.store.nodes.input }
1179
1179
  ), this.store.nodes.input.target) {
1180
1180
  this.store.nodes.input.content = d;
1181
- const u = this.store.state.tokens.get(), h = u[this.store.nodes.input.index];
1182
- h.type === "text" && (h.content = d), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(y(u)), this.store.events.parse();
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();
1183
1183
  }
1184
1184
  }));
1185
1185
  }
@@ -1187,7 +1187,7 @@ class Dt {
1187
1187
  this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
1188
1188
  }
1189
1189
  }
1190
- class Ht {
1190
+ class Yt {
1191
1191
  constructor(t) {
1192
1192
  this.store = t;
1193
1193
  }
@@ -1204,7 +1204,7 @@ class Ht {
1204
1204
  this.#t = this.store.events.clearOverlay.on(() => {
1205
1205
  e(void 0);
1206
1206
  }), this.#e = this.store.events.checkOverlay.on(() => {
1207
- const r = F.find(this.store.state.options.get(), t);
1207
+ const r = Q.find(this.store.state.options.get(), t);
1208
1208
  e(r);
1209
1209
  }), this.#n = this.store.events.change.on(() => {
1210
1210
  const r = this.store.state.showOverlayOn.get(), o = "change";
@@ -1222,7 +1222,7 @@ class Ht {
1222
1222
  }
1223
1223
  enableClose() {
1224
1224
  this.#i || (this.#i = (t) => {
1225
- t.key === v.ESC && this.store.events.clearOverlay();
1225
+ t.key === x.ESC && this.store.events.clearOverlay();
1226
1226
  }, this.#a = (t) => {
1227
1227
  const e = t.target;
1228
1228
  this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
@@ -1236,7 +1236,7 @@ class Ht {
1236
1236
  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;
1237
1237
  }
1238
1238
  }
1239
- class Ft {
1239
+ class te {
1240
1240
  constructor(t) {
1241
1241
  this.store = t;
1242
1242
  }
@@ -1281,7 +1281,7 @@ class Ft {
1281
1281
  this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
1282
1282
  }
1283
1283
  }
1284
- class Ut {
1284
+ class ee {
1285
1285
  constructor(t) {
1286
1286
  this.store = t;
1287
1287
  }
@@ -1309,7 +1309,7 @@ class Ut {
1309
1309
  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;
1310
1310
  }
1311
1311
  }
1312
- function Wt(s, t) {
1312
+ function ne(s, t) {
1313
1313
  if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
1314
1314
  t.preventDefault();
1315
1315
  const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
@@ -1317,7 +1317,7 @@ function Wt(s, t) {
1317
1317
  e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
1318
1318
  }
1319
1319
  }
1320
- function Gt(s, t) {
1320
+ function se(s, t) {
1321
1321
  const { focus: e } = s.nodes;
1322
1322
  if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
1323
1323
  const n = e.prev;
@@ -1325,7 +1325,7 @@ function Gt(s, t) {
1325
1325
  }
1326
1326
  return !1;
1327
1327
  }
1328
- function Bt(s, t) {
1328
+ function re(s, t) {
1329
1329
  const { focus: e } = s.nodes;
1330
1330
  if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
1331
1331
  const n = e.next;
@@ -1333,7 +1333,7 @@ function Bt(s, t) {
1333
1333
  }
1334
1334
  return !1;
1335
1335
  }
1336
- class jt {
1336
+ class oe {
1337
1337
  constructor(t) {
1338
1338
  this.store = t;
1339
1339
  }
@@ -1344,11 +1344,11 @@ class jt {
1344
1344
  if (this.#t) return;
1345
1345
  const t = this.store.refs.container;
1346
1346
  t && (this.#t = (e) => {
1347
- e.key === v.LEFT ? Gt(this.store, e) : e.key === v.RIGHT && Bt(this.store, e), this.#s(e), Wt(this.store, e);
1347
+ e.key === x.LEFT ? se(this.store, e) : e.key === x.RIGHT && re(this.store, e), this.#s(e), ne(this.store, e);
1348
1348
  }, this.#e = (e) => {
1349
- zt(this.store, e);
1349
+ ae(this.store, e);
1350
1350
  }, this.#n = (e) => {
1351
- qt(this.store, e);
1351
+ ie(this.store, e);
1352
1352
  }, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
1353
1353
  }
1354
1354
  disable() {
@@ -1357,37 +1357,37 @@ class jt {
1357
1357
  }
1358
1358
  #s(t) {
1359
1359
  const { focus: e } = this.store.nodes;
1360
- if (t.key === v.DELETE || t.key === v.BACKSPACE) {
1360
+ if (t.key === x.DELETE || t.key === x.BACKSPACE) {
1361
1361
  if (e.isMark) {
1362
- t.preventDefault(), _("self", this.store);
1362
+ t.preventDefault(), U("self", this.store);
1363
1363
  return;
1364
1364
  }
1365
- t.key === v.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), _("prev", this.store)), t.key === v.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), _("next", this.store));
1365
+ t.key === x.BACKSPACE && e.isSpan && e.isCaretAtBeginning && e.prev.target && (t.preventDefault(), U("prev", this.store)), t.key === x.DELETE && e.isSpan && e.isCaretAtEnd && e.next.target && (t.preventDefault(), U("next", this.store));
1366
1366
  }
1367
1367
  }
1368
1368
  }
1369
- function qt(s, t) {
1369
+ function ie(s, t) {
1370
1370
  const e = s.state.selecting.get();
1371
- if (e !== "all" || !Y(s)) {
1371
+ if (e !== "all" || !ut(s)) {
1372
1372
  e === "all" && s.state.selecting.set(void 0);
1373
1373
  return;
1374
1374
  }
1375
1375
  if (t.inputType === "insertFromPaste") return;
1376
1376
  t.preventDefault();
1377
1377
  const n = t.inputType.startsWith("delete") ? "" : t.data ?? "";
1378
- tt(s, n);
1378
+ ht(s, n);
1379
1379
  }
1380
- function zt(s, t) {
1380
+ function ae(s, t) {
1381
1381
  const e = s.state.selecting.get();
1382
- if (e !== "all" || !Y(s)) {
1382
+ if (e !== "all" || !ut(s)) {
1383
1383
  e === "all" && s.state.selecting.set(void 0);
1384
1384
  return;
1385
1385
  }
1386
1386
  t.preventDefault();
1387
1387
  const n = t.clipboardData?.getData("text/plain") ?? "";
1388
- tt(s, n);
1388
+ ht(s, n);
1389
1389
  }
1390
- function Y(s) {
1390
+ function ut(s) {
1391
1391
  const t = window.getSelection(), e = s.refs.container;
1392
1392
  if (!t?.rangeCount || !e?.firstChild || !e?.lastChild) return !1;
1393
1393
  try {
@@ -1397,7 +1397,7 @@ function Y(s) {
1397
1397
  return !1;
1398
1398
  }
1399
1399
  }
1400
- function tt(s, t) {
1400
+ function ht(s, t) {
1401
1401
  s.nodes.focus.target = null, s.state.selecting.set(void 0), s.state.onChange.get()?.(t), s.state.value.get() === void 0 && s.state.tokens.set(
1402
1402
  s.state.parser.get()?.parse(t) ?? [
1403
1403
  {
@@ -1414,7 +1414,7 @@ function tt(s, t) {
1414
1414
  }), e.focus());
1415
1415
  });
1416
1416
  }
1417
- class Xt {
1417
+ class ce {
1418
1418
  #t = [];
1419
1419
  #e = !1;
1420
1420
  register(t) {
@@ -1427,22 +1427,22 @@ class Xt {
1427
1427
  this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
1428
1428
  }
1429
1429
  }
1430
- const N = (s, t) => ({
1430
+ const $ = (s, t) => ({
1431
1431
  name: s,
1432
1432
  enable: () => t.enable(),
1433
1433
  disable: () => t.disable()
1434
- }), Zt = (s) => {
1435
- const t = new Xt();
1436
- return t.register(N("keydown", s.controllers.keydown)).register(N("system", s.controllers.system)).register(N("focus", s.controllers.focus)).register(N("textSelection", s.controllers.textSelection)), t;
1434
+ }), le = (s) => {
1435
+ const t = new ce();
1436
+ return t.register($("keydown", s.controllers.keydown)).register($("system", s.controllers.system)).register($("focus", s.controllers.focus)).register($("textSelection", s.controllers.textSelection)), t;
1437
1437
  };
1438
- class Jt {
1438
+ class de {
1439
1439
  constructor(t) {
1440
1440
  this.store = t;
1441
1441
  }
1442
1442
  #t = [];
1443
1443
  #e = !1;
1444
1444
  enable(t) {
1445
- const { store: e } = this, n = Zt(e);
1445
+ const { store: e } = this, n = le(e);
1446
1446
  n.enableAll(), this.#t.push(() => n.disableAll()), this.#s(), this.#n(), t?.getTrigger && this.#r(t.getTrigger);
1447
1447
  }
1448
1448
  disable() {
@@ -1457,12 +1457,12 @@ class Jt {
1457
1457
  */
1458
1458
  syncParser(t, e) {
1459
1459
  const { store: n } = this, r = e?.map((i) => i.markup);
1460
- if (r && r.some(Boolean) ? n.state.parser.set(new A(r)) : n.state.parser.set(void 0), this.#e) {
1460
+ if (r && r.some(Boolean) ? n.state.parser.set(new B(r)) : n.state.parser.set(void 0), this.#e) {
1461
1461
  n.state.recovery.get() || n.events.parse();
1462
1462
  return;
1463
1463
  }
1464
1464
  const o = t ?? n.state.defaultValue.get() ?? "";
1465
- n.state.tokens.set(P(n, o)), this.#e = !0;
1465
+ n.state.tokens.set(_(n, o)), this.#e = !0;
1466
1466
  }
1467
1467
  /**
1468
1468
  * Recovers focus after tokens change.
@@ -1483,11 +1483,11 @@ class Jt {
1483
1483
  this.#t.push(
1484
1484
  t.events.parse.on(() => {
1485
1485
  if (t.state.recovery.get()) {
1486
- const e = y(t.state.tokens.get());
1487
- t.state.tokens.set(P(t, e)), t.state.previousValue.set(e);
1486
+ const e = I(t.state.tokens.get());
1487
+ t.state.tokens.set(_(t, e)), t.state.previousValue.set(e);
1488
1488
  return;
1489
1489
  }
1490
- t.state.tokens.set(t.nodes.focus.target ? It(t) : Mt(t));
1490
+ t.state.tokens.set(t.nodes.focus.target ? Ft(t) : Wt(t));
1491
1491
  })
1492
1492
  );
1493
1493
  }
@@ -1500,28 +1500,28 @@ class Jt {
1500
1500
  );
1501
1501
  }
1502
1502
  }
1503
- class Qt {
1504
- key = new $t();
1503
+ class ue {
1504
+ key = new Zt();
1505
1505
  nodes = {
1506
- focus: new M(void 0, this),
1507
- input: new M(void 0, this)
1506
+ focus: new V(void 0, this),
1507
+ input: new V(void 0, this)
1508
1508
  };
1509
1509
  state;
1510
- events = _t();
1510
+ events = Xt();
1511
1511
  refs = {
1512
1512
  container: null,
1513
1513
  overlay: null
1514
1514
  };
1515
1515
  controllers = {
1516
- overlay: new Ht(this),
1517
- focus: new Ft(this),
1518
- keydown: new jt(this),
1519
- system: new Dt(this),
1520
- textSelection: new Ut(this)
1516
+ overlay: new Yt(this),
1517
+ focus: new te(this),
1518
+ keydown: new oe(this),
1519
+ system: new Kt(this),
1520
+ textSelection: new ee(this)
1521
1521
  };
1522
- lifecycle = new Jt(this);
1522
+ lifecycle = new de(this);
1523
1523
  constructor(t) {
1524
- this.state = At(
1524
+ this.state = zt(
1525
1525
  {
1526
1526
  tokens: [],
1527
1527
  parser: void 0,
@@ -1560,7 +1560,7 @@ class Qt {
1560
1560
  };
1561
1561
  }
1562
1562
  }
1563
- class Kt {
1563
+ class he {
1564
1564
  ref;
1565
1565
  #t;
1566
1566
  #e;
@@ -1593,13 +1593,13 @@ class Kt {
1593
1593
  this.#e.meta = t, this.#s();
1594
1594
  }
1595
1595
  get depth() {
1596
- return V(this.#t.state.tokens.get(), this.#e).depth;
1596
+ return z(this.#t.state.tokens.get(), this.#e).depth;
1597
1597
  }
1598
1598
  get hasChildren() {
1599
1599
  return this.#e.children.length > 0;
1600
1600
  }
1601
1601
  get parent() {
1602
- return V(this.#t.state.tokens.get(), this.#e)?.parent;
1602
+ return z(this.#t.state.tokens.get(), this.#e)?.parent;
1603
1603
  }
1604
1604
  get tokens() {
1605
1605
  return this.#e.children;
@@ -1612,57 +1612,192 @@ class Kt {
1612
1612
  this.#t.events.change();
1613
1613
  }
1614
1614
  }
1615
- const Yt = {
1615
+ let ft = 0;
1616
+ function rt(s) {
1617
+ return `block-${ft++}-${s}`;
1618
+ }
1619
+ function fe() {
1620
+ ft = 0;
1621
+ }
1622
+ function ge(s) {
1623
+ if (s.length === 0) return [];
1624
+ fe();
1625
+ const t = [];
1626
+ let e = [], n = -1;
1627
+ const r = (o) => {
1628
+ e.length !== 0 && (t.push({
1629
+ id: rt(n),
1630
+ tokens: [...e],
1631
+ startPos: n,
1632
+ endPos: o
1633
+ }), e = [], n = -1);
1634
+ };
1635
+ for (const o of s) {
1636
+ if (o.type === "mark") {
1637
+ o.content.endsWith(`
1638
+ `) ? (r(o.position.start), t.push({
1639
+ id: rt(o.position.start),
1640
+ tokens: [o],
1641
+ startPos: o.position.start,
1642
+ endPos: o.position.end
1643
+ })) : (n === -1 && (n = o.position.start), e.push(o));
1644
+ continue;
1645
+ }
1646
+ if (o.type !== "text") continue;
1647
+ const a = pe(o);
1648
+ for (let c = 0; c < a.length; c++) {
1649
+ const l = a[c];
1650
+ if (l.isNewline) {
1651
+ r(l.position.start);
1652
+ continue;
1653
+ }
1654
+ l.content.length !== 0 && (n === -1 && (n = l.position.start), e.push({
1655
+ type: "text",
1656
+ content: l.content,
1657
+ position: l.position
1658
+ }));
1659
+ }
1660
+ }
1661
+ if (e.length > 0) {
1662
+ const o = e[e.length - 1];
1663
+ r(o.position.end);
1664
+ }
1665
+ return t;
1666
+ }
1667
+ function pe(s) {
1668
+ const t = [], { content: e, position: n } = s;
1669
+ let r = n.start;
1670
+ const o = [], i = () => {
1671
+ if (o.length > 0) {
1672
+ const a = o.join("");
1673
+ t.push({
1674
+ content: a,
1675
+ position: { start: r, end: r + a.length },
1676
+ isNewline: !1
1677
+ }), r += a.length, o.length = 0;
1678
+ }
1679
+ };
1680
+ for (let a = 0; a < e.length; a++) {
1681
+ const c = e[a];
1682
+ c === `
1683
+ ` ? (i(), t.push({
1684
+ content: `
1685
+ `,
1686
+ position: { start: r, end: r + 1 },
1687
+ isNewline: !0
1688
+ }), r += 1) : c === "\r" ? a + 1 < e.length && e[a + 1] === `
1689
+ ` ? (i(), t.push({
1690
+ content: `
1691
+ `,
1692
+ position: { start: r, end: r + 2 },
1693
+ isNewline: !0
1694
+ }), r += 2, a++) : (i(), t.push({
1695
+ content: `
1696
+ `,
1697
+ position: { start: r, end: r + 1 },
1698
+ isNewline: !0
1699
+ }), r += 1) : o.push(c);
1700
+ }
1701
+ return i(), t;
1702
+ }
1703
+ function ve(s, t, e, n) {
1704
+ if (e === n || e === n - 1 || t.length < 2 || e < 0 || e >= t.length || n < 0 || n > t.length) return s;
1705
+ const r = me(s, t), o = xe(r, e, n);
1706
+ return ye(o);
1707
+ }
1708
+ function me(s, t) {
1709
+ return t.map((e, n) => {
1710
+ const r = s.substring(e.startPos, e.endPos);
1711
+ let o = "";
1712
+ if (n < t.length - 1) {
1713
+ const i = t[n + 1];
1714
+ o = s.substring(e.endPos, i.startPos);
1715
+ }
1716
+ return {
1717
+ index: n,
1718
+ text: r,
1719
+ separatorAfter: o
1720
+ };
1721
+ });
1722
+ }
1723
+ function ye(s) {
1724
+ const t = [];
1725
+ for (let e = 0; e < s.length; e++) {
1726
+ const n = s[e], r = e === s.length - 1;
1727
+ let o = n.text;
1728
+ o.endsWith(`
1729
+ `) && (o = o.slice(0, -1)), t.push(o), r || t.push(n.separatorAfter || `
1730
+ `);
1731
+ }
1732
+ return t.join("");
1733
+ }
1734
+ function xe(s, t, e) {
1735
+ const n = [...s], [r] = n.splice(t, 1), o = e > t ? e - 1 : e;
1736
+ return n.splice(o, 0, r), ke(n, s), n;
1737
+ }
1738
+ function ke(s, t) {
1739
+ for (let e = 0; e < s.length - 1; e++) {
1740
+ const n = s[e].index, r = s[e + 1].index;
1741
+ if (Math.abs(n - r) === 1) {
1742
+ const o = Math.min(n, r), i = t[o].separatorAfter;
1743
+ s[e].separatorAfter = i.length > 0 ? i : `
1744
+ `;
1745
+ } else
1746
+ s[e].separatorAfter = `
1747
+ `;
1748
+ }
1749
+ }
1750
+ const we = {
1616
1751
  container: "div",
1617
1752
  span: "span"
1618
1753
  };
1619
- function et(s, t) {
1620
- return t?.[s] ? t[s] : Yt[s];
1754
+ function K(s, t) {
1755
+ return t?.[s] ? t[s] : we[s];
1621
1756
  }
1622
- function nt(s, t) {
1757
+ function Y(s, t) {
1623
1758
  const e = t?.[s];
1624
- return e ? ht(e) : void 0;
1759
+ return e ? Et(e) : void 0;
1625
1760
  }
1626
- const U = X(void 0);
1627
- U.displayName = "StoreContext";
1628
- function k() {
1629
- const s = Z(U);
1630
- return dt(s), s;
1761
+ const tt = at(void 0);
1762
+ tt.displayName = "StoreContext";
1763
+ function E() {
1764
+ const s = ct(tt);
1765
+ return bt(s), s;
1631
1766
  }
1632
- const te = (s) => {
1633
- const t = X(void 0);
1767
+ const Se = (s) => {
1768
+ const t = at(void 0);
1634
1769
  return t.displayName = s, [() => {
1635
- const n = Z(t);
1770
+ const n = ct(t);
1636
1771
  if (n === void 0)
1637
1772
  throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
1638
1773
  return n;
1639
1774
  }, t.Provider, t];
1640
- }, [W, z] = te("NodeProvider");
1641
- function st(s, t, e, n) {
1642
- const r = k(), o = r.state.Mark.use(), i = r.state.Overlay.use(), a = s === "mark" ? o : i, l = s === "mark" ? t?.mark : t?.overlay;
1643
- let c;
1644
- l !== void 0 ? typeof l == "function" ? c = l(e) : c = l : c = e ?? {};
1645
- const d = c.slot || a || n;
1775
+ }, [et, ot] = Se("NodeProvider");
1776
+ function gt(s, t, e, n) {
1777
+ 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;
1778
+ let l;
1779
+ c !== void 0 ? typeof c == "function" ? l = c(e) : l = c : l = e ?? {};
1780
+ const d = l.slot || a || n;
1646
1781
  if (!d)
1647
1782
  throw new Error(
1648
1783
  `No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
1649
1784
  );
1650
- return [d, c];
1785
+ return [d, l];
1651
1786
  }
1652
- function ee() {
1653
- const s = W(), t = k(), e = t.state.options.use(), n = t.key, r = e?.[s.descriptor.index], o = s.children.map((c) => /* @__PURE__ */ f(G, { mark: c, isNested: !0 }, n.get(c))), i = {
1787
+ function Ce() {
1788
+ 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 = {
1654
1789
  value: s.value,
1655
1790
  meta: s.meta,
1656
1791
  nested: s.nested?.content,
1657
1792
  children: s.children.length > 0 ? o : void 0
1658
- }, [a, l] = st("mark", r, i);
1659
- return /* @__PURE__ */ f(a, { ...l });
1793
+ }, [a, c] = gt("mark", r, i);
1794
+ return /* @__PURE__ */ f(a, { ...c });
1660
1795
  }
1661
- const ne = () => {
1662
- const s = W(), t = k(), e = J(null), n = t.state.readOnly.use(), r = t.state.slots.use(), o = t.state.slotProps.use(), i = C(() => et("span", r), [r]), a = C(() => nt("span", o), [o]);
1796
+ const be = () => {
1797
+ const s = et(), t = E(), e = H(null), n = t.state.readOnly.use(), r = t.state.slots.use(), o = t.state.slotProps.use(), i = S(() => K("span", r), [r]), a = S(() => Y("span", o), [o]);
1663
1798
  if (s.type !== "text")
1664
1799
  throw new Error("TextSpan component expects a TextToken");
1665
- return ct(() => {
1800
+ return St(() => {
1666
1801
  e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
1667
1802
  }, [s.content]), /* @__PURE__ */ f(
1668
1803
  i,
@@ -1670,34 +1805,168 @@ const ne = () => {
1670
1805
  ...a,
1671
1806
  ref: e,
1672
1807
  contentEditable: !n,
1673
- onPaste: se,
1808
+ onPaste: Ee,
1674
1809
  suppressContentEditableWarning: !0
1675
1810
  }
1676
1811
  );
1677
1812
  };
1678
- function se(s) {
1813
+ function Ee(s) {
1679
1814
  s.preventDefault();
1680
1815
  const t = s.clipboardData.getData("text");
1681
1816
  document.execCommand("insertText", !1, t);
1682
1817
  }
1683
- const G = D(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ f(z, { value: s, children: /* @__PURE__ */ f(ee, {}) }) : t ? /* @__PURE__ */ f(it, { children: s.content }) : /* @__PURE__ */ f(z, { value: s, children: /* @__PURE__ */ f(ne, {}) }));
1684
- G.displayName = "Token";
1685
- const rt = D(() => {
1686
- const s = k(), 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, l = C(() => et("container", e), [e]), c = C(() => nt("container", n), [n]);
1818
+ const F = O(({ mark: s, isNested: t = !1 }) => s.type === "mark" ? /* @__PURE__ */ f(ot, { value: s, children: /* @__PURE__ */ f(Ce, {}) }) : t ? /* @__PURE__ */ f(wt, { children: s.content }) : /* @__PURE__ */ f(ot, { value: s, children: /* @__PURE__ */ f(be, {}) }));
1819
+ F.displayName = "Token";
1820
+ const pt = O(() => {
1821
+ 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(() => K("container", e), [e]), l = S(() => Y("container", n), [n]);
1687
1822
  return /* @__PURE__ */ f(
1688
- l,
1823
+ c,
1689
1824
  {
1690
1825
  ref: (d) => a.container = d,
1691
- ...c,
1826
+ ...l,
1827
+ className: r,
1828
+ style: o,
1829
+ children: t.map((d) => /* @__PURE__ */ f(F, { mark: d }, i.get(d)))
1830
+ }
1831
+ );
1832
+ });
1833
+ pt.displayName = "Container";
1834
+ const q = {
1835
+ position: "absolute",
1836
+ left: -28,
1837
+ top: 2,
1838
+ width: 20,
1839
+ height: 20,
1840
+ display: "flex",
1841
+ alignItems: "center",
1842
+ justifyContent: "center",
1843
+ cursor: "grab",
1844
+ borderRadius: 4,
1845
+ opacity: 0,
1846
+ transition: "opacity 0.15s ease",
1847
+ userSelect: "none",
1848
+ color: "#9ca3af",
1849
+ flexShrink: 0,
1850
+ background: "none",
1851
+ border: "none",
1852
+ padding: 0,
1853
+ margin: 0,
1854
+ font: "inherit",
1855
+ lineHeight: 1
1856
+ }, vt = {
1857
+ ...q,
1858
+ opacity: 1
1859
+ }, Te = {
1860
+ ...vt,
1861
+ cursor: "grabbing"
1862
+ }, Ne = {
1863
+ position: "relative",
1864
+ paddingLeft: 4,
1865
+ transition: "opacity 0.2s ease"
1866
+ }, it = {
1867
+ position: "absolute",
1868
+ left: 0,
1869
+ right: 0,
1870
+ height: 2,
1871
+ backgroundColor: "#3b82f6",
1872
+ borderRadius: 1,
1873
+ pointerEvents: "none",
1874
+ zIndex: 10
1875
+ }, mt = O(() => /* @__PURE__ */ Z("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", children: [
1876
+ /* @__PURE__ */ f("circle", { cx: "5", cy: "3", r: "1.5" }),
1877
+ /* @__PURE__ */ f("circle", { cx: "11", cy: "3", r: "1.5" }),
1878
+ /* @__PURE__ */ f("circle", { cx: "5", cy: "8", r: "1.5" }),
1879
+ /* @__PURE__ */ f("circle", { cx: "11", cy: "8", r: "1.5" }),
1880
+ /* @__PURE__ */ f("circle", { cx: "5", cy: "13", r: "1.5" }),
1881
+ /* @__PURE__ */ f("circle", { cx: "11", cy: "13", r: "1.5" })
1882
+ ] }));
1883
+ mt.displayName = "GripIcon";
1884
+ const yt = O(({ blockIndex: s, children: t, readOnly: e, onReorder: n }) => {
1885
+ const [r, o] = P(!1), [i, a] = P(!1), [c, l] = P(null), d = H(null), g = k(() => o(!0), []), u = k(() => o(!1), []), h = k(
1886
+ (p) => {
1887
+ p.dataTransfer.effectAllowed = "move", p.dataTransfer.setData("text/plain", String(s)), a(!0), d.current && p.dataTransfer.setDragImage(d.current, 0, 0);
1888
+ },
1889
+ [s]
1890
+ ), v = k(() => {
1891
+ a(!1), l(null);
1892
+ }, []), C = k((p) => {
1893
+ if (p.preventDefault(), p.dataTransfer.dropEffect = "move", !d.current) return;
1894
+ const D = d.current.getBoundingClientRect(), W = D.top + D.height / 2;
1895
+ l(p.clientY < W ? "before" : "after");
1896
+ }, []), m = k((p) => {
1897
+ p.currentTarget.contains(p.relatedTarget) || l(null);
1898
+ }, []), b = k(
1899
+ (p) => {
1900
+ p.preventDefault();
1901
+ const D = parseInt(p.dataTransfer.getData("text/plain"), 10);
1902
+ if (isNaN(D)) return;
1903
+ const W = c === "before" ? s : s + 1;
1904
+ l(null), n(D, W);
1905
+ },
1906
+ [s, c, n]
1907
+ ), T = {
1908
+ ...Ne,
1909
+ opacity: i ? 0.4 : 1
1910
+ }, L = e ? { ...q, display: "none" } : i ? Te : r ? vt : q;
1911
+ return /* @__PURE__ */ Z(
1912
+ "div",
1913
+ {
1914
+ ref: d,
1915
+ style: T,
1916
+ onMouseEnter: g,
1917
+ onMouseLeave: u,
1918
+ onDragOver: C,
1919
+ onDragLeave: m,
1920
+ onDrop: b,
1921
+ children: [
1922
+ c === "before" && /* @__PURE__ */ f("div", { style: { ...it, top: -1 } }),
1923
+ /* @__PURE__ */ f(
1924
+ "button",
1925
+ {
1926
+ type: "button",
1927
+ draggable: !e,
1928
+ onDragStart: h,
1929
+ onDragEnd: v,
1930
+ style: L,
1931
+ "aria-label": "Drag to reorder",
1932
+ children: /* @__PURE__ */ f(mt, {})
1933
+ }
1934
+ ),
1935
+ t,
1936
+ c === "after" && /* @__PURE__ */ f("div", { style: { ...it, bottom: -1 } })
1937
+ ]
1938
+ }
1939
+ );
1940
+ });
1941
+ yt.displayName = "DraggableBlock";
1942
+ const xt = O(() => {
1943
+ 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(() => K("container", e), [e]), u = S(() => Y("container", n), [n]), h = S(() => ge(t), [t]), v = H(h);
1944
+ v.current = h;
1945
+ const C = k(
1946
+ (m, b) => {
1947
+ if (!a || !c) return;
1948
+ const T = v.current, L = ve(a, T, m, b);
1949
+ if (L !== a) {
1950
+ const p = _(s, L);
1951
+ s.state.tokens.set(p), s.state.previousValue.set(L), c(L);
1952
+ }
1953
+ },
1954
+ [s, a, c]
1955
+ );
1956
+ return /* @__PURE__ */ f(
1957
+ g,
1958
+ {
1959
+ ref: (m) => d.container = m,
1960
+ ...u,
1692
1961
  className: r,
1693
1962
  style: o,
1694
- children: t.map((d) => /* @__PURE__ */ f(G, { mark: d }, i.get(d)))
1963
+ children: h.map((m, b) => /* @__PURE__ */ f(yt, { blockIndex: b, readOnly: i, onReorder: C, children: m.tokens.map((T) => /* @__PURE__ */ f(F, { mark: T }, l.get(T))) }, m.id))
1695
1964
  }
1696
1965
  );
1697
1966
  });
1698
- rt.displayName = "Container";
1699
- function re() {
1700
- const s = k(), t = s.state.overlayMatch.use(), e = m.getAbsolutePosition(), n = B(() => s.events.clearOverlay(), []), r = B(
1967
+ xt.displayName = "BlockContainer";
1968
+ function Ie() {
1969
+ const s = E(), t = s.state.overlayMatch.use(), e = w.getAbsolutePosition(), n = k(() => s.events.clearOverlay(), []), r = k(
1701
1970
  (i) => {
1702
1971
  const a = {
1703
1972
  type: "mark",
@@ -1715,7 +1984,7 @@ function re() {
1715
1984
  s.events.select({ mark: a, match: t }), s.events.clearOverlay();
1716
1985
  },
1717
1986
  [t]
1718
- ), o = C(
1987
+ ), o = S(
1719
1988
  () => ({
1720
1989
  get current() {
1721
1990
  return s.refs.overlay;
@@ -1728,136 +1997,141 @@ function re() {
1728
1997
  );
1729
1998
  return { match: t, style: e, select: r, close: n, ref: o };
1730
1999
  }
1731
- const oe = "_Container_1lmfr_1", ie = "_Suggestions_1lmfr_10", ae = "_suggestionActive_1lmfr_38", R = {
1732
- Container: oe,
1733
- Suggestions: ie,
1734
- suggestionActive: ae
1735
- }, ce = () => {
1736
- const s = k(), { match: t, select: e, style: n, ref: r } = re(), [o, i] = L(NaN), a = t.option.overlay?.data || [], l = C(
2000
+ const Pe = "_Container_1lmfr_1", Me = "_Suggestions_1lmfr_10", Le = "_suggestionActive_1lmfr_38", X = {
2001
+ Container: Pe,
2002
+ Suggestions: Me,
2003
+ suggestionActive: Le
2004
+ }, Ae = () => {
2005
+ const s = E(), { match: t, select: e, style: n, ref: r } = Ie(), [o, i] = P(NaN), a = t.option.overlay?.data || [], c = S(
1737
2006
  () => a.filter((d) => d.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
1738
2007
  [t.value, a]
1739
- ), c = l.length;
1740
- return S(() => {
2008
+ ), l = c.length;
2009
+ return M(() => {
1741
2010
  const d = s.refs.container;
1742
2011
  if (!d) return;
1743
- const u = (h) => {
1744
- switch (h.key) {
1745
- case v.UP:
1746
- h.preventDefault(), i((g) => isNaN(g) ? 0 : (c + (g - 1) % c) % c);
2012
+ const g = (u) => {
2013
+ switch (u.key) {
2014
+ case x.UP:
2015
+ u.preventDefault(), i((h) => isNaN(h) ? 0 : (l + (h - 1) % l) % l);
1747
2016
  break;
1748
- case v.DOWN:
1749
- h.preventDefault(), i((g) => isNaN(g) ? 0 : (g + 1) % c);
2017
+ case x.DOWN:
2018
+ u.preventDefault(), i((h) => isNaN(h) ? 0 : (h + 1) % l);
1750
2019
  break;
1751
- case v.ENTER:
1752
- h.preventDefault(), i((g) => {
1753
- if (isNaN(g)) return g;
1754
- const w = l[g];
1755
- return e({ value: w, meta: g.toString() }), g;
2020
+ case x.ENTER:
2021
+ u.preventDefault(), i((h) => {
2022
+ if (isNaN(h)) return h;
2023
+ const v = c[h];
2024
+ return e({ value: v, meta: h.toString() }), h;
1756
2025
  });
1757
2026
  break;
1758
2027
  }
1759
2028
  };
1760
- return d.addEventListener("keydown", u), () => d.removeEventListener("keydown", u);
1761
- }, [c, l]), l.length ? /* @__PURE__ */ f("ul", { ref: r, className: R.Suggestions, style: n, children: l.map((d, u) => {
1762
- const h = u === o ? R.suggestionActive : void 0;
2029
+ return d.addEventListener("keydown", g), () => d.removeEventListener("keydown", g);
2030
+ }, [l, c]), c.length ? /* @__PURE__ */ f("ul", { ref: r, className: X.Suggestions, style: n, children: c.map((d, g) => {
2031
+ const u = g === o ? X.suggestionActive : void 0;
1763
2032
  return /* @__PURE__ */ f(
1764
2033
  "li",
1765
2034
  {
1766
- ref: (g) => {
1767
- h && g && g.scrollIntoView(!1);
2035
+ ref: (h) => {
2036
+ u && h && h.scrollIntoView(!1);
1768
2037
  },
1769
- className: h,
1770
- onClick: (g) => e({ value: d, meta: u.toString() }),
2038
+ className: u,
2039
+ onClick: (h) => e({ value: d, meta: g.toString() }),
1771
2040
  children: d
1772
2041
  },
1773
2042
  d
1774
2043
  );
1775
2044
  }) }) : null;
1776
- }, ot = D(() => {
1777
- const s = k(), t = s.state.overlayMatch.use(), e = C(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = st("overlay", t?.option, void 0, ce);
2045
+ }, kt = O(() => {
2046
+ const s = E(), t = s.state.overlayMatch.use(), e = S(() => t ? s.key.get(t.option) : void 0, [t]), [n, r] = gt("overlay", t?.option, void 0, Ae);
1778
2047
  if (e) return /* @__PURE__ */ f(n, { ...r ?? {} }, e);
1779
2048
  });
1780
- ot.displayName = "OverlayRenderer";
1781
- function le(s, t) {
1782
- lt(t, () => s.createHandler(), [s]), S(() => (s.lifecycle.enable({
2049
+ kt.displayName = "OverlayRenderer";
2050
+ function Oe(s, t) {
2051
+ Ct(t, () => s.createHandler(), [s]), M(() => (s.lifecycle.enable({
1783
2052
  getTrigger: (a) => a.overlay?.trigger
1784
2053
  }), () => s.lifecycle.disable()), []);
1785
2054
  const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
1786
- S(() => {
2055
+ M(() => {
1787
2056
  s.lifecycle.syncParser(e, o);
1788
2057
  }, [e, o]);
1789
2058
  const i = s.state.tokens.use();
1790
- S(() => {
2059
+ M(() => {
1791
2060
  s.lifecycle.recoverFocus();
1792
2061
  }, [i]);
1793
2062
  }
1794
- const de = (s) => () => {
1795
- const [t, e] = L(() => s.get());
1796
- return S(() => s.on(e), [s]), t;
1797
- }, he = [
2063
+ const De = (s) => () => {
2064
+ const [t, e] = P(() => s.get());
2065
+ return M(() => s.on(e), [s]), t;
2066
+ }, _e = [
1798
2067
  {
1799
- markup: pt,
2068
+ markup: Pt,
1800
2069
  overlay: {
1801
- trigger: ft,
2070
+ trigger: It,
1802
2071
  data: []
1803
2072
  }
1804
2073
  }
1805
2074
  ];
1806
- function me(s) {
2075
+ function Fe(s) {
1807
2076
  const {
1808
2077
  ref: t,
1809
2078
  value: e,
1810
2079
  defaultValue: n,
1811
2080
  onChange: r,
1812
2081
  readOnly: o = !1,
1813
- Mark: i,
1814
- Overlay: a,
2082
+ block: i = !1,
2083
+ Mark: a,
2084
+ Overlay: c,
1815
2085
  slots: l,
1816
- slotProps: c,
1817
- options: d = he,
2086
+ slotProps: d,
2087
+ options: g = _e,
1818
2088
  showOverlayOn: u = "change",
1819
2089
  className: h,
1820
- style: g
1821
- } = s, w = ut(R.Container, h, c?.container?.className), E = gt(g, c?.container?.style), [T] = L(() => new Qt({ createUseHook: de }));
1822
- return T.state.set({
2090
+ style: v
2091
+ } = s, C = Tt(X.Container, h, d?.container?.className), m = Nt(v, d?.container?.style), [b] = P(() => new ue({ createUseHook: De }));
2092
+ b.state.set({
1823
2093
  value: e,
1824
2094
  defaultValue: n,
1825
2095
  onChange: r,
1826
2096
  readOnly: o,
1827
- options: d,
2097
+ options: g,
1828
2098
  showOverlayOn: u,
1829
- Mark: i,
1830
- Overlay: a,
1831
- className: w,
1832
- style: E,
2099
+ Mark: a,
2100
+ Overlay: c,
2101
+ className: C,
2102
+ style: m,
1833
2103
  slots: l,
1834
- slotProps: c
1835
- }), le(T, t), /* @__PURE__ */ at(U.Provider, { value: T, children: [
1836
- /* @__PURE__ */ f(rt, {}),
1837
- /* @__PURE__ */ f(ot, {})
2104
+ slotProps: d
2105
+ }), Oe(b, t);
2106
+ const T = i ? xt : pt;
2107
+ return /* @__PURE__ */ Z(tt.Provider, { value: b, children: [
2108
+ /* @__PURE__ */ f(T, {}),
2109
+ /* @__PURE__ */ f(kt, {})
1838
2110
  ] });
1839
2111
  }
1840
- const xe = (s = {}) => {
1841
- const t = k(), e = W(), n = J(null);
2112
+ const We = (s = {}) => {
2113
+ const t = E(), e = et(), n = H(null);
1842
2114
  if (e.type !== "mark")
1843
2115
  throw new Error("useMark can only be used with mark tokens");
1844
- const [r] = L(() => new Kt({ ref: n, store: t, token: e }));
1845
- ue(n, s, e);
2116
+ const [r] = P(() => new he({ ref: n, store: t, token: e }));
2117
+ Re(n, s, e);
1846
2118
  const o = t.state.readOnly.use();
1847
- return S(() => {
2119
+ return M(() => {
1848
2120
  r.readOnly = o;
1849
2121
  }, [o]), r;
1850
2122
  };
1851
- function ue(s, t, e) {
1852
- S(() => {
2123
+ function Re(s, t, e) {
2124
+ M(() => {
1853
2125
  s.current && !t.controlled && (s.current.textContent = e.content);
1854
2126
  }, []);
1855
2127
  }
1856
2128
  export {
1857
- Kt as MarkHandler,
1858
- me as MarkedInput,
1859
- $ as annotate,
1860
- ve as denote,
1861
- xe as useMark,
1862
- re as useOverlay
2129
+ he as MarkHandler,
2130
+ Fe as MarkedInput,
2131
+ j as annotate,
2132
+ Be as denote,
2133
+ ve as reorderBlocks,
2134
+ ge as splitTokensIntoBlocks,
2135
+ We as useMark,
2136
+ Ie as useOverlay
1863
2137
  };