@markput/react 0.2.0 → 0.4.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 +7 -2
  2. package/index.d.ts +11 -0
  3. package/index.js +791 -497
  4. package/package.json +15 -15
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 { 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";
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
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 = {
20
+ const It = "@", Pt = "@[__value__](__meta__)", x = {
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: x.Value },
73
+ { count: s.meta, max: 1, name: x.Meta },
74
+ { count: s.nested, max: 1, name: x.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 "${x.Value}" or "${x.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]: x.Value,
86
+ [N.Meta]: x.Meta,
87
+ [N.Nested]: x.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, 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];
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 Rt {
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 _t {
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 Rt(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 Bt(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 Vt {
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 = Bt(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 $t {
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,34 @@ class Et {
528
528
  };
529
529
  }
530
530
  }
531
- function $(s, t) {
531
+ function J(s, t) {
532
+ let e = "";
533
+ for (const n of s)
534
+ if (n.type === "text")
535
+ e += n.content;
536
+ else if (n.children.length > 0) {
537
+ const r = J(n.children, t), o = {
538
+ ...n,
539
+ value: r
540
+ };
541
+ e += t(o);
542
+ } else
543
+ e += t(n);
544
+ return e;
545
+ }
546
+ function j(s, t) {
532
547
  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;
548
+ 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;
534
549
  }
535
- function y(s) {
550
+ function I(s) {
536
551
  let t = "";
537
552
  for (const e of s) {
538
553
  if (e.type === "text") {
539
554
  t += e.content;
540
555
  continue;
541
556
  }
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, {
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, {
544
559
  value: e.value,
545
560
  meta: e.meta,
546
561
  nested: r
@@ -548,22 +563,7 @@ function y(s) {
548
563
  }
549
564
  return t;
550
565
  }
551
- function H(s, t) {
552
- let e = "";
553
- for (const n of s)
554
- if (n.type === "text")
555
- e += n.content;
556
- else if (n.children.length > 0) {
557
- const r = H(n.children, t), o = {
558
- ...n,
559
- value: r
560
- };
561
- e += t(o);
562
- } else
563
- e += t(n);
564
- return e;
565
- }
566
- class A {
566
+ class H {
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 Vt(this.registry.segments), this.patternMatcher = new _t(this.registry), this.treeBuilder = new $t();
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 H(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 He(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 H(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 Ht(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 = Ht(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 R(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 R(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 R(s, t) {
826
826
  const e = s.state.parser.get();
827
827
  return e ? e.parse(t) : [
828
828
  {
@@ -832,44 +832,44 @@ function P(s, t) {
832
832
  }
833
833
  ];
834
834
  }
835
- const Pt = (s, t) => s === t;
836
- class I {
837
- #t;
838
- #e = /* @__PURE__ */ new Set();
835
+ const Ut = (s, t) => s === t;
836
+ class _ {
837
+ #e;
838
+ #t = /* @__PURE__ */ new Set();
839
839
  #n;
840
840
  constructor(t, e) {
841
- this.#t = t, this.#n = e?.equals ?? Pt;
841
+ this.#e = t, this.#n = e?.equals ?? Ut;
842
842
  }
843
843
  static event() {
844
- return new I(void 0, { equals: !1 });
844
+ return new _(void 0, { equals: !1 });
845
845
  }
846
846
  get value() {
847
- return this.#t;
847
+ return this.#e;
848
848
  }
849
849
  set value(t) {
850
- (this.#n === !1 || !this.#n(this.#t, t)) && (this.#t = t, this.#e.forEach((e) => e(t)));
850
+ (this.#n === !1 || !this.#n(this.#e, t)) && (this.#e = t, this.#t.forEach((e) => e(t)));
851
851
  }
852
852
  on(t) {
853
- return this.#e.add(t), () => this.#e.delete(t);
853
+ return this.#t.add(t), () => this.#t.delete(t);
854
854
  }
855
855
  emit(t) {
856
- arguments.length > 0 && (this.#t = t), this.#e.forEach((e) => e(this.#t));
856
+ arguments.length > 0 && (this.#e = t), this.#t.forEach((e) => e(this.#e));
857
857
  }
858
858
  get() {
859
- return this.#t;
859
+ return this.#e;
860
860
  }
861
861
  set(t) {
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 _(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, _.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 = _.event(), e.set(r, o)), qt(o);
900
900
  }
901
901
  });
902
902
  }
903
- class $t {
904
- #t = 1;
905
- #e = /* @__PURE__ */ new WeakMap();
903
+ class Zt {
904
+ #e = 1;
905
+ #t = /* @__PURE__ */ new WeakMap();
906
906
  get(t) {
907
- return this.#e.has(t) ? this.#e.get(t) : (this.#e.set(t, this.#t), this.#t++);
907
+ return this.#t.has(t) ? this.#t.get(t) : (this.#t.set(t, this.#e), this.#e++);
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,24 +1042,24 @@ 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 {
1050
- #t;
1049
+ class B {
1051
1050
  #e;
1051
+ #t;
1052
1052
  get target() {
1053
- return this.#t;
1053
+ return this.#e;
1054
1054
  }
1055
1055
  set target(t) {
1056
- this.#t = t;
1056
+ this.#e = t;
1057
1057
  }
1058
1058
  get next() {
1059
- return new M(this.target?.nextSibling, this.#e);
1059
+ return new B(this.target?.nextSibling, this.#t);
1060
1060
  }
1061
1061
  get prev() {
1062
- return new M(this.target?.previousSibling, this.#e);
1062
+ return new B(this.target?.previousSibling, this.#t);
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;
@@ -1095,19 +1095,19 @@ class M {
1095
1095
  this.target && (this.target.textContent = t ?? "");
1096
1096
  }
1097
1097
  get head() {
1098
- return this.#e.refs.container?.firstChild;
1098
+ return this.#t.refs.container?.firstChild;
1099
1099
  }
1100
1100
  get tail() {
1101
- return this.#e.refs.container?.lastChild;
1101
+ return this.#t.refs.container?.lastChild;
1102
1102
  }
1103
1103
  get isFocused() {
1104
1104
  return this.target === document.activeElement;
1105
1105
  }
1106
1106
  constructor(t, e) {
1107
- this.target = t, this.#e = e;
1107
+ this.target = t, this.#t = 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,128 +1136,79 @@ 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
  }
1148
- #t;
1149
1148
  #e;
1149
+ #t;
1150
1150
  #n;
1151
1151
  enable() {
1152
- this.#t || (this.#t = this.store.events.change.on(() => {
1152
+ this.#e || (this.#e = this.store.events.change.on(() => {
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();
1157
- }), this.#e = this.store.events.delete.on((t) => {
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) => {
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
  }
1186
1186
  disable() {
1187
- this.#t?.(), this.#e?.(), this.#n?.(), this.#t = void 0, this.#e = void 0, this.#n = void 0;
1187
+ this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = 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
  }
1194
- #t;
1195
1194
  #e;
1196
- #n;
1197
- #s;
1198
- #r;
1199
- #o;
1200
- #i;
1201
- #a;
1202
- enableTrigger(t, e) {
1203
- if (this.#t) return;
1204
- this.#t = this.store.events.clearOverlay.on(() => {
1205
- e(void 0);
1206
- }), this.#e = this.store.events.checkOverlay.on(() => {
1207
- const r = F.find(this.store.state.options.get(), t);
1208
- e(r);
1209
- }), this.#n = this.store.events.change.on(() => {
1210
- const r = this.store.state.showOverlayOn.get(), o = "change";
1211
- (r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
1212
- }), this.#s = () => {
1213
- const r = this.store.state.showOverlayOn.get(), o = "selectionChange";
1214
- (r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
1215
- }, this.#r = () => {
1216
- document.addEventListener("selectionchange", this.#s);
1217
- }, this.#o = () => {
1218
- document.removeEventListener("selectionchange", this.#s);
1219
- };
1220
- const n = this.store.refs.container;
1221
- n && (n.addEventListener("focusin", this.#r), n.addEventListener("focusout", this.#o));
1222
- }
1223
- enableClose() {
1224
- this.#i || (this.#i = (t) => {
1225
- t.key === v.ESC && this.store.events.clearOverlay();
1226
- }, this.#a = (t) => {
1227
- const e = t.target;
1228
- this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
1229
- }, window.addEventListener("keydown", this.#i), document.addEventListener("click", this.#a, !0));
1230
- }
1231
- disableClose() {
1232
- this.#i && (window.removeEventListener("keydown", this.#i), document.removeEventListener("click", this.#a, !0), this.#i = void 0, this.#a = void 0);
1233
- }
1234
- disable() {
1235
- const t = this.store.refs.container;
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
- }
1238
- }
1239
- class Ft {
1240
- constructor(t) {
1241
- this.store = t;
1242
- }
1243
1195
  #t;
1244
- #e;
1245
1196
  #n;
1246
1197
  enable() {
1247
- if (this.#t) return;
1198
+ if (this.#e) return;
1248
1199
  const t = this.store.refs.container;
1249
- t && (this.#t = (e) => {
1200
+ t && (this.#e = (e) => {
1250
1201
  this.store.nodes.focus.target = e.target;
1251
- }, this.#e = () => {
1202
+ }, this.#t = () => {
1252
1203
  this.store.nodes.focus.target = void 0;
1253
1204
  }, this.#n = () => {
1254
1205
  const e = this.store.state.tokens.get();
1255
1206
  e.length === 1 && e[0].type === "text" && e[0].content === "" && this.store.refs.container?.firstElementChild?.focus();
1256
- }, t.addEventListener("focusin", this.#t), t.addEventListener("focusout", this.#e), t.addEventListener("click", this.#n));
1207
+ }, t.addEventListener("focusin", this.#e), t.addEventListener("focusout", this.#t), t.addEventListener("click", this.#n));
1257
1208
  }
1258
1209
  disable() {
1259
1210
  const t = this.store.refs.container;
1260
- !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);
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);
1261
1212
  }
1262
1213
  recover() {
1263
1214
  const t = this.store.state.recovery.get();
@@ -1281,20 +1232,36 @@ class Ft {
1281
1232
  this.store.nodes.focus.caret = n, this.store.state.recovery.set(void 0);
1282
1233
  }
1283
1234
  }
1284
- class Ut {
1235
+ function te(s, t) {
1236
+ const { focus: e } = s.nodes;
1237
+ if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
1238
+ const n = e.prev;
1239
+ return n.focus(), n.isFocused || (n.prev.focus(), t.preventDefault()), e.setCaretToEnd(), !0;
1240
+ }
1241
+ return !1;
1242
+ }
1243
+ function ee(s, t) {
1244
+ const { focus: e } = s.nodes;
1245
+ if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
1246
+ const n = e.next;
1247
+ return n.focus(), n.isFocused || (n.next.focus(), t.preventDefault()), !0;
1248
+ }
1249
+ return !1;
1250
+ }
1251
+ class ne {
1285
1252
  constructor(t) {
1286
1253
  this.store = t;
1287
1254
  }
1288
- #t;
1289
1255
  #e;
1256
+ #t;
1290
1257
  #n;
1291
1258
  #s;
1292
1259
  #r = null;
1293
1260
  #o = !1;
1294
1261
  enable() {
1295
- this.#t || (this.#t = (t) => {
1262
+ this.#e || (this.#e = (t) => {
1296
1263
  this.#r = t.target, this.#o = !0;
1297
- }, this.#e = (t) => {
1264
+ }, this.#t = (t) => {
1298
1265
  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);
1299
1266
  e && n && r && this.store.state.selecting.set("drag");
1300
1267
  }, this.#n = () => {
@@ -1303,13 +1270,13 @@ class Ut {
1303
1270
  if (this.store.state.selecting.get() !== "drag") return;
1304
1271
  const t = [...this.store.refs.container.children], e = t.map((n) => n.contentEditable);
1305
1272
  t.forEach((n) => n.contentEditable = "false"), t.forEach((n, r) => n.contentEditable = e[r]);
1306
- }, document.addEventListener("mousedown", this.#t), document.addEventListener("mousemove", this.#e), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#s));
1273
+ }, document.addEventListener("mousedown", this.#e), document.addEventListener("mousemove", this.#t), document.addEventListener("mouseup", this.#n), document.addEventListener("selectionchange", this.#s));
1307
1274
  }
1308
1275
  disable() {
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;
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;
1310
1277
  }
1311
1278
  }
1312
- function Wt(s, t) {
1279
+ function se(s, t) {
1313
1280
  if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
1314
1281
  t.preventDefault();
1315
1282
  const e = window.getSelection(), n = s.refs.container?.firstChild, r = s.refs.container?.lastChild;
@@ -1317,77 +1284,102 @@ function Wt(s, t) {
1317
1284
  e.setBaseAndExtent(n, 0, r, 1), s.state.selecting.set("all");
1318
1285
  }
1319
1286
  }
1320
- function Gt(s, t) {
1321
- const { focus: e } = s.nodes;
1322
- if (e.isMark && !e.isEditable || e.isCaretAtBeginning) {
1323
- const n = e.prev;
1324
- return n.focus(), n.isFocused || (n.prev.focus(), t.preventDefault()), e.setCaretToEnd(), !0;
1325
- }
1326
- return !1;
1327
- }
1328
- function Bt(s, t) {
1329
- const { focus: e } = s.nodes;
1330
- if (e.isMark && !e.isEditable || e.isCaretAtEnd) {
1331
- const n = e.next;
1332
- return n.focus(), n.isFocused || (n.next.focus(), t.preventDefault()), !0;
1333
- }
1334
- return !1;
1335
- }
1336
- class jt {
1287
+ class re {
1337
1288
  constructor(t) {
1338
1289
  this.store = t;
1339
1290
  }
1340
- #t;
1341
1291
  #e;
1292
+ #t;
1342
1293
  #n;
1343
1294
  enable() {
1344
- if (this.#t) return;
1295
+ if (this.#e) return;
1345
1296
  const t = this.store.refs.container;
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);
1348
- }, this.#e = (e) => {
1349
- zt(this.store, e);
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);
1350
1301
  }, this.#n = (e) => {
1351
- qt(this.store, e);
1352
- }, t.addEventListener("keydown", this.#t), t.addEventListener("paste", this.#e), t.addEventListener("beforeinput", this.#n, !0));
1302
+ oe(this.store, e);
1303
+ }, t.addEventListener("keydown", this.#e), t.addEventListener("paste", this.#t), t.addEventListener("beforeinput", this.#n, !0));
1353
1304
  }
1354
1305
  disable() {
1355
1306
  const t = this.store.refs.container;
1356
- !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);
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);
1357
1308
  }
1358
1309
  #s(t) {
1359
1310
  const { focus: e } = this.store.nodes;
1360
1311
  if (t.key === v.DELETE || t.key === v.BACKSPACE) {
1361
1312
  if (e.isMark) {
1362
- t.preventDefault(), _("self", this.store);
1313
+ if (e.isEditable && (t.key === v.BACKSPACE && !e.isCaretAtBeginning || t.key === v.DELETE && !e.isCaretAtEnd))
1314
+ return;
1315
+ t.preventDefault(), U("self", this.store);
1363
1316
  return;
1364
1317
  }
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));
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));
1366
1319
  }
1367
1320
  }
1368
1321
  }
1369
- function qt(s, t) {
1322
+ function oe(s, t) {
1370
1323
  const e = s.state.selecting.get();
1371
- if (e !== "all" || !Y(s)) {
1372
- e === "all" && s.state.selecting.set(void 0);
1324
+ if (e === "all" && ut(s)) {
1325
+ if (t.inputType === "insertFromPaste") {
1326
+ t.preventDefault();
1327
+ return;
1328
+ }
1329
+ t.preventDefault();
1330
+ const r = t.inputType.startsWith("delete") ? "" : t.data ?? "";
1331
+ ht(s, r);
1373
1332
  return;
1374
1333
  }
1375
- if (t.inputType === "insertFromPaste") return;
1376
- t.preventDefault();
1377
- const n = t.inputType.startsWith("delete") ? "" : t.data ?? "";
1378
- tt(s, n);
1334
+ e === "all" && s.state.selecting.set(void 0);
1335
+ const { focus: n } = s.nodes;
1336
+ !n.target || !n.isEditable || ie(n, t) && s.events.change();
1337
+ }
1338
+ function ie(s, t) {
1339
+ const e = s.caret, n = s.content;
1340
+ let r, o;
1341
+ switch (t.inputType) {
1342
+ case "insertText": {
1343
+ t.preventDefault();
1344
+ const i = t.data ?? "";
1345
+ r = n.slice(0, e) + i + n.slice(e), o = e + i.length;
1346
+ break;
1347
+ }
1348
+ case "deleteContentBackward":
1349
+ case "deleteContentForward":
1350
+ case "deleteWordBackward":
1351
+ case "deleteWordForward":
1352
+ case "deleteSoftLineBackward":
1353
+ case "deleteSoftLineForward": {
1354
+ const i = t.getTargetRanges();
1355
+ if (!i.length) return !1;
1356
+ const { startOffset: a, endOffset: c } = i[0];
1357
+ if (a === c) return !1;
1358
+ t.preventDefault(), r = n.slice(0, a) + n.slice(c), o = a;
1359
+ break;
1360
+ }
1361
+ case "insertFromPaste":
1362
+ case "insertReplacementText": {
1363
+ const i = t.dataTransfer?.getData("text/plain") ?? "", a = t.getTargetRanges(), c = a[0]?.startOffset ?? e, l = a[0]?.endOffset ?? e;
1364
+ t.preventDefault(), r = n.slice(0, c) + i + n.slice(l), o = c + i.length;
1365
+ break;
1366
+ }
1367
+ default:
1368
+ return !1;
1369
+ }
1370
+ return s.content = r, s.caret = o, !0;
1379
1371
  }
1380
- function zt(s, t) {
1372
+ function ae(s, t) {
1381
1373
  const e = s.state.selecting.get();
1382
- if (e !== "all" || !Y(s)) {
1374
+ if (e !== "all" || !ut(s)) {
1383
1375
  e === "all" && s.state.selecting.set(void 0);
1384
1376
  return;
1385
1377
  }
1386
1378
  t.preventDefault();
1387
1379
  const n = t.clipboardData?.getData("text/plain") ?? "";
1388
- tt(s, n);
1380
+ ht(s, n);
1389
1381
  }
1390
- function Y(s) {
1382
+ function ut(s) {
1391
1383
  const t = window.getSelection(), e = s.refs.container;
1392
1384
  if (!t?.rangeCount || !e?.firstChild || !e?.lastChild) return !1;
1393
1385
  try {
@@ -1397,7 +1389,7 @@ function Y(s) {
1397
1389
  return !1;
1398
1390
  }
1399
1391
  }
1400
- function tt(s, t) {
1392
+ function ht(s, t) {
1401
1393
  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
1394
  s.state.parser.get()?.parse(t) ?? [
1403
1395
  {
@@ -1414,41 +1406,41 @@ function tt(s, t) {
1414
1406
  }), e.focus());
1415
1407
  });
1416
1408
  }
1417
- class Xt {
1418
- #t = [];
1419
- #e = !1;
1409
+ class ce {
1410
+ #e = [];
1411
+ #t = !1;
1420
1412
  register(t) {
1421
- return this.#t.push(t), this;
1413
+ return this.#e.push(t), this;
1422
1414
  }
1423
1415
  enableAll() {
1424
- this.#e || (this.#e = !0, this.#t.forEach((t) => t.enable()));
1416
+ this.#t || (this.#t = !0, this.#e.forEach((t) => t.enable()));
1425
1417
  }
1426
1418
  disableAll() {
1427
- this.#e && (this.#e = !1, this.#t.forEach((t) => t.disable()));
1419
+ this.#t && (this.#t = !1, this.#e.forEach((t) => t.disable()));
1428
1420
  }
1429
1421
  }
1430
- const N = (s, t) => ({
1422
+ const V = (s, t) => ({
1431
1423
  name: s,
1432
1424
  enable: () => t.enable(),
1433
1425
  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;
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;
1437
1429
  };
1438
- class Jt {
1430
+ class de {
1439
1431
  constructor(t) {
1440
1432
  this.store = t;
1441
1433
  }
1442
- #t = [];
1443
- #e = !1;
1434
+ #e = [];
1435
+ #t = !1;
1444
1436
  enable(t) {
1445
- const { store: e } = this, n = Zt(e);
1446
- n.enableAll(), this.#t.push(() => n.disableAll()), this.#s(), this.#n(), t?.getTrigger && this.#r(t.getTrigger);
1437
+ const { store: e } = this, n = le(e);
1438
+ n.enableAll(), this.#e.push(() => n.disableAll()), this.#n(), t?.getTrigger && this.#s(t.getTrigger);
1447
1439
  }
1448
1440
  disable() {
1449
- for (const t of this.#t)
1441
+ for (const t of this.#e)
1450
1442
  t();
1451
- this.#t = [], this.#e = !1;
1443
+ this.#e = [], this.#t = !1;
1452
1444
  }
1453
1445
  /**
1454
1446
  * Synchronizes the parser with current options and handles parsing.
@@ -1457,12 +1449,12 @@ class Jt {
1457
1449
  */
1458
1450
  syncParser(t, e) {
1459
1451
  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) {
1452
+ if (r && r.some(Boolean) ? n.state.parser.set(new H(r)) : n.state.parser.set(void 0), this.#t) {
1461
1453
  n.state.recovery.get() || n.events.parse();
1462
1454
  return;
1463
1455
  }
1464
1456
  const o = t ?? n.state.defaultValue.get() ?? "";
1465
- n.state.tokens.set(P(n, o)), this.#e = !0;
1457
+ n.state.tokens.set(R(n, o)), this.#t = !0;
1466
1458
  }
1467
1459
  /**
1468
1460
  * Recovers focus after tokens change.
@@ -1473,55 +1465,98 @@ class Jt {
1473
1465
  this.store.state.Mark.get() && this.store.controllers.focus.recover();
1474
1466
  }
1475
1467
  #n() {
1476
- const t = this.store.refs.container;
1477
- if (!t) return;
1478
- const e = () => this.store.events.change();
1479
- t.addEventListener("input", e), this.#t.push(() => t.removeEventListener("input", e));
1480
- }
1481
- #s() {
1482
1468
  const { store: t } = this;
1483
- this.#t.push(
1469
+ this.#e.push(
1484
1470
  t.events.parse.on(() => {
1485
1471
  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);
1472
+ const e = I(t.state.tokens.get());
1473
+ t.state.tokens.set(R(t, e)), t.state.previousValue.set(e);
1488
1474
  return;
1489
1475
  }
1490
- t.state.tokens.set(t.nodes.focus.target ? It(t) : Mt(t));
1476
+ t.state.tokens.set(t.nodes.focus.target ? Ft(t) : Wt(t));
1491
1477
  })
1492
1478
  );
1493
1479
  }
1494
- #r(t) {
1480
+ #s(t) {
1495
1481
  const { store: e } = this;
1496
- e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#t.push(() => e.controllers.overlay.disable()), this.#t.push(
1482
+ e.controllers.overlay.enableTrigger(t, (n) => e.state.overlayMatch.set(n)), this.#e.push(() => e.controllers.overlay.disable()), this.#e.push(
1497
1483
  e.state.overlayMatch.on((n) => {
1498
1484
  n ? (e.nodes.input.target = e.nodes.focus.target, e.controllers.overlay.enableClose()) : e.controllers.overlay.disableClose();
1499
1485
  })
1500
1486
  );
1501
1487
  }
1502
1488
  }
1503
- class Qt {
1504
- key = new $t();
1489
+ class ue {
1490
+ constructor(t) {
1491
+ this.store = t;
1492
+ }
1493
+ #e;
1494
+ #t;
1495
+ #n;
1496
+ #s;
1497
+ #r;
1498
+ #o;
1499
+ #i;
1500
+ #a;
1501
+ enableTrigger(t, e) {
1502
+ if (this.#e) return;
1503
+ this.#e = this.store.events.clearOverlay.on(() => {
1504
+ e(void 0);
1505
+ }), this.#t = this.store.events.checkOverlay.on(() => {
1506
+ const r = Q.find(this.store.state.options.get(), t);
1507
+ e(r);
1508
+ }), this.#n = this.store.events.change.on(() => {
1509
+ const r = this.store.state.showOverlayOn.get(), o = "change";
1510
+ (r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
1511
+ }), this.#s = () => {
1512
+ const r = this.store.state.showOverlayOn.get(), o = "selectionChange";
1513
+ (r === o || Array.isArray(r) && r.includes(o)) && this.store.events.checkOverlay();
1514
+ }, this.#r = () => {
1515
+ document.addEventListener("selectionchange", this.#s);
1516
+ }, this.#o = () => {
1517
+ document.removeEventListener("selectionchange", this.#s);
1518
+ };
1519
+ const n = this.store.refs.container;
1520
+ n && (n.addEventListener("focusin", this.#r), n.addEventListener("focusout", this.#o));
1521
+ }
1522
+ enableClose() {
1523
+ this.#i || (this.#i = (t) => {
1524
+ t.key === v.ESC && this.store.events.clearOverlay();
1525
+ }, this.#a = (t) => {
1526
+ const e = t.target;
1527
+ this.store.refs.overlay?.contains(e) || this.store.refs.container?.contains(e) || this.store.events.clearOverlay();
1528
+ }, window.addEventListener("keydown", this.#i), document.addEventListener("click", this.#a, !0));
1529
+ }
1530
+ disableClose() {
1531
+ this.#i && (window.removeEventListener("keydown", this.#i), document.removeEventListener("click", this.#a, !0), this.#i = void 0, this.#a = void 0);
1532
+ }
1533
+ disable() {
1534
+ 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;
1536
+ }
1537
+ }
1538
+ class he {
1539
+ key = new Zt();
1505
1540
  nodes = {
1506
- focus: new M(void 0, this),
1507
- input: new M(void 0, this)
1541
+ focus: new B(void 0, this),
1542
+ input: new B(void 0, this)
1508
1543
  };
1509
1544
  state;
1510
- events = _t();
1545
+ events = Xt();
1511
1546
  refs = {
1512
1547
  container: null,
1513
1548
  overlay: null
1514
1549
  };
1515
1550
  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)
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)
1521
1556
  };
1522
- lifecycle = new Jt(this);
1557
+ lifecycle = new de(this);
1523
1558
  constructor(t) {
1524
- this.state = At(
1559
+ this.state = zt(
1525
1560
  {
1526
1561
  tokens: [],
1527
1562
  parser: void 0,
@@ -1560,13 +1595,13 @@ class Qt {
1560
1595
  };
1561
1596
  }
1562
1597
  }
1563
- class Kt {
1598
+ class fe {
1564
1599
  ref;
1565
- #t;
1566
1600
  #e;
1601
+ #t;
1567
1602
  #n;
1568
1603
  constructor(t) {
1569
- this.ref = t.ref, this.#t = t.store, this.#e = t.token;
1604
+ this.ref = t.ref, this.#e = t.store, this.#t = t.token;
1570
1605
  }
1571
1606
  get readOnly() {
1572
1607
  return this.#n;
@@ -1575,129 +1610,408 @@ class Kt {
1575
1610
  this.#n = t;
1576
1611
  }
1577
1612
  get content() {
1578
- return this.#e.content;
1613
+ return this.#t.content;
1579
1614
  }
1580
1615
  set content(t) {
1581
- this.#e.content = t, this.#s();
1616
+ this.#t.content = t, this.#s();
1582
1617
  }
1583
1618
  get value() {
1584
- return this.#e.value;
1619
+ return this.#t.value;
1585
1620
  }
1586
1621
  set value(t) {
1587
- this.#e.value = t ?? "", this.#s();
1622
+ this.#t.value = t ?? "", this.#s();
1588
1623
  }
1589
1624
  get meta() {
1590
- return this.#e.meta;
1625
+ return this.#t.meta;
1591
1626
  }
1592
1627
  set meta(t) {
1593
- this.#e.meta = t, this.#s();
1628
+ this.#t.meta = t, this.#s();
1594
1629
  }
1595
1630
  get depth() {
1596
- return V(this.#t.state.tokens.get(), this.#e).depth;
1631
+ return z(this.#e.state.tokens.get(), this.#t).depth;
1597
1632
  }
1598
1633
  get hasChildren() {
1599
- return this.#e.children.length > 0;
1634
+ return this.#t.children.length > 0;
1600
1635
  }
1601
1636
  get parent() {
1602
- return V(this.#t.state.tokens.get(), this.#e)?.parent;
1637
+ return z(this.#e.state.tokens.get(), this.#t)?.parent;
1603
1638
  }
1604
1639
  get tokens() {
1605
- return this.#e.children;
1640
+ return this.#t.children;
1606
1641
  }
1607
1642
  change = (t) => {
1608
- this.#e.content = t.content, this.#e.value = t.value ?? "", t.meta !== void 0 && (this.#e.meta = t.meta), this.#s();
1643
+ this.#t.content = t.content, this.#t.value = t.value ?? "", t.meta !== void 0 && (this.#t.meta = t.meta), this.#s();
1609
1644
  };
1610
- remove = () => this.#t.events.delete({ token: this.#e });
1645
+ remove = () => this.#e.events.delete({ token: this.#t });
1611
1646
  #s() {
1612
- this.#t.events.change();
1647
+ this.#e.events.change();
1648
+ }
1649
+ }
1650
+ let ft = 0;
1651
+ function rt(s) {
1652
+ return `block-${ft++}-${s}`;
1653
+ }
1654
+ function ge() {
1655
+ ft = 0;
1656
+ }
1657
+ function pe(s) {
1658
+ if (s.length === 0) return [];
1659
+ ge();
1660
+ const t = [];
1661
+ let e = [], n = -1;
1662
+ const r = (o) => {
1663
+ e.length !== 0 && (t.push({
1664
+ id: rt(n),
1665
+ tokens: [...e],
1666
+ startPos: n,
1667
+ endPos: o
1668
+ }), e = [], n = -1);
1669
+ };
1670
+ for (const o of s) {
1671
+ if (o.type === "mark") {
1672
+ o.content.endsWith(`
1673
+ `) ? (r(o.position.start), t.push({
1674
+ id: rt(o.position.start),
1675
+ tokens: [o],
1676
+ startPos: o.position.start,
1677
+ endPos: o.position.end
1678
+ })) : (n === -1 && (n = o.position.start), e.push(o));
1679
+ continue;
1680
+ }
1681
+ if (o.type !== "text") continue;
1682
+ const a = ve(o);
1683
+ for (let c = 0; c < a.length; c++) {
1684
+ const l = a[c];
1685
+ if (l.isNewline) {
1686
+ r(l.position.start);
1687
+ continue;
1688
+ }
1689
+ l.content.length !== 0 && (n === -1 && (n = l.position.start), e.push({
1690
+ type: "text",
1691
+ content: l.content,
1692
+ position: l.position
1693
+ }));
1694
+ }
1695
+ }
1696
+ if (e.length > 0) {
1697
+ const o = e[e.length - 1];
1698
+ r(o.position.end);
1699
+ }
1700
+ return t;
1701
+ }
1702
+ function ve(s) {
1703
+ const t = [], { content: e, position: n } = s;
1704
+ let r = n.start;
1705
+ const o = [], i = () => {
1706
+ if (o.length > 0) {
1707
+ const a = o.join("");
1708
+ t.push({
1709
+ content: a,
1710
+ position: { start: r, end: r + a.length },
1711
+ isNewline: !1
1712
+ }), r += a.length, o.length = 0;
1713
+ }
1714
+ };
1715
+ for (let a = 0; a < e.length; a++) {
1716
+ const c = e[a];
1717
+ c === `
1718
+ ` ? (i(), t.push({
1719
+ content: `
1720
+ `,
1721
+ position: { start: r, end: r + 1 },
1722
+ isNewline: !0
1723
+ }), r += 1) : c === "\r" ? a + 1 < e.length && e[a + 1] === `
1724
+ ` ? (i(), t.push({
1725
+ content: `
1726
+ `,
1727
+ position: { start: r, end: r + 2 },
1728
+ isNewline: !0
1729
+ }), r += 2, a++) : (i(), t.push({
1730
+ content: `
1731
+ `,
1732
+ position: { start: r, end: r + 1 },
1733
+ isNewline: !0
1734
+ }), r += 1) : o.push(c);
1735
+ }
1736
+ return i(), t;
1737
+ }
1738
+ function me(s, t, e, n) {
1739
+ 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);
1742
+ }
1743
+ function ye(s, t) {
1744
+ return t.map((e, n) => {
1745
+ const r = s.substring(e.startPos, e.endPos);
1746
+ let o = "";
1747
+ if (n < t.length - 1) {
1748
+ const i = t[n + 1];
1749
+ o = s.substring(e.endPos, i.startPos);
1750
+ }
1751
+ return {
1752
+ index: n,
1753
+ text: r,
1754
+ separatorAfter: o
1755
+ };
1756
+ });
1757
+ }
1758
+ function xe(s) {
1759
+ const t = [];
1760
+ for (let e = 0; e < s.length; e++) {
1761
+ const n = s[e], r = e === s.length - 1;
1762
+ let o = n.text;
1763
+ o.endsWith(`
1764
+ `) && (o = o.slice(0, -1)), t.push(o), r || t.push(n.separatorAfter || `
1765
+ `);
1766
+ }
1767
+ return t.join("");
1768
+ }
1769
+ function ke(s, t, e) {
1770
+ 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;
1772
+ }
1773
+ function we(s, t) {
1774
+ for (let e = 0; e < s.length - 1; e++) {
1775
+ const n = s[e].index, r = s[e + 1].index;
1776
+ if (Math.abs(n - r) === 1) {
1777
+ const o = Math.min(n, r), i = t[o].separatorAfter;
1778
+ s[e].separatorAfter = i.length > 0 ? i : `
1779
+ `;
1780
+ } else
1781
+ s[e].separatorAfter = `
1782
+ `;
1613
1783
  }
1614
1784
  }
1615
- const Yt = {
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;
1796
+ };
1797
+ function be(s, t) {
1798
+ St(t, () => s.createHandler(), [s]), M(() => (s.lifecycle.enable({
1799
+ getTrigger: (a) => a.overlay?.trigger
1800
+ }), () => 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(() => {
1803
+ s.lifecycle.syncParser(e, o);
1804
+ }, [e, o]);
1805
+ const i = s.state.tokens.use();
1806
+ M(() => {
1807
+ s.lifecycle.recoverFocus();
1808
+ }, [i]);
1809
+ }
1810
+ const K = at(void 0);
1811
+ K.displayName = "StoreContext";
1812
+ function E() {
1813
+ const s = ct(K);
1814
+ return bt(s), s;
1815
+ }
1816
+ const Ee = {
1616
1817
  container: "div",
1617
1818
  span: "span"
1618
1819
  };
1619
- function et(s, t) {
1620
- return t?.[s] ? t[s] : Yt[s];
1820
+ function Y(s, t) {
1821
+ return t?.[s] ? t[s] : Ee[s];
1621
1822
  }
1622
- function nt(s, t) {
1823
+ function tt(s, t) {
1623
1824
  const e = t?.[s];
1624
- return e ? ht(e) : void 0;
1625
- }
1626
- const U = X(void 0);
1627
- U.displayName = "StoreContext";
1628
- function k() {
1629
- const s = Z(U);
1630
- return dt(s), s;
1631
- }
1632
- const te = (s) => {
1633
- const t = X(void 0);
1825
+ return e ? Et(e) : void 0;
1826
+ }
1827
+ const q = {
1828
+ position: "absolute",
1829
+ left: -28,
1830
+ top: 2,
1831
+ width: 20,
1832
+ height: 20,
1833
+ display: "flex",
1834
+ alignItems: "center",
1835
+ justifyContent: "center",
1836
+ cursor: "grab",
1837
+ borderRadius: 4,
1838
+ opacity: 0,
1839
+ transition: "opacity 0.15s ease",
1840
+ userSelect: "none",
1841
+ color: "#9ca3af",
1842
+ flexShrink: 0,
1843
+ background: "none",
1844
+ border: "none",
1845
+ padding: 0,
1846
+ margin: 0,
1847
+ font: "inherit",
1848
+ lineHeight: 1
1849
+ }, gt = {
1850
+ ...q,
1851
+ opacity: 1
1852
+ }, Te = {
1853
+ ...gt,
1854
+ cursor: "grabbing"
1855
+ }, Ne = {
1856
+ position: "relative",
1857
+ paddingLeft: 4,
1858
+ transition: "opacity 0.2s ease"
1859
+ }, ot = {
1860
+ position: "absolute",
1861
+ left: 0,
1862
+ right: 0,
1863
+ height: 2,
1864
+ backgroundColor: "#3b82f6",
1865
+ borderRadius: 1,
1866
+ pointerEvents: "none",
1867
+ 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" })
1875
+ ] }));
1876
+ pt.displayName = "GripIcon";
1877
+ 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(
1879
+ (p) => {
1880
+ p.dataTransfer.effectAllowed = "move", p.dataTransfer.setData("text/plain", String(s)), a(!0), d.current && p.dataTransfer.setDragImage(d.current, 0, 0);
1881
+ },
1882
+ [s]
1883
+ ), m = k(() => {
1884
+ a(!1), l(null);
1885
+ }, []), C = k((p) => {
1886
+ 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");
1889
+ }, []), y = k((p) => {
1890
+ p.currentTarget.contains(p.relatedTarget) || l(null);
1891
+ }, []), b = k(
1892
+ (p) => {
1893
+ p.preventDefault();
1894
+ const D = parseInt(p.dataTransfer.getData("text/plain"), 10);
1895
+ if (isNaN(D)) return;
1896
+ const W = c === "before" ? s : s + 1;
1897
+ l(null), n(D, W);
1898
+ },
1899
+ [s, c, n]
1900
+ ), T = {
1901
+ ...Ne,
1902
+ opacity: i ? 0.4 : 1
1903
+ }, L = e ? { ...q, display: "none" } : i ? Te : r ? gt : q;
1904
+ return /* @__PURE__ */ Z(
1905
+ "div",
1906
+ {
1907
+ ref: d,
1908
+ style: T,
1909
+ onMouseEnter: g,
1910
+ onMouseLeave: u,
1911
+ onDragOver: C,
1912
+ onDragLeave: y,
1913
+ onDrop: b,
1914
+ children: [
1915
+ c === "before" && /* @__PURE__ */ f("div", { style: { ...ot, top: -1 } }),
1916
+ /* @__PURE__ */ f(
1917
+ "button",
1918
+ {
1919
+ type: "button",
1920
+ draggable: !e,
1921
+ onDragStart: h,
1922
+ onDragEnd: m,
1923
+ style: L,
1924
+ "aria-label": "Drag to reorder",
1925
+ children: /* @__PURE__ */ f(pt, {})
1926
+ }
1927
+ ),
1928
+ t,
1929
+ c === "after" && /* @__PURE__ */ f("div", { style: { ...ot, bottom: -1 } })
1930
+ ]
1931
+ }
1932
+ );
1933
+ });
1934
+ vt.displayName = "DraggableBlock";
1935
+ const Ie = (s) => {
1936
+ const t = at(void 0);
1634
1937
  return t.displayName = s, [() => {
1635
- const n = Z(t);
1938
+ const n = ct(t);
1636
1939
  if (n === void 0)
1637
1940
  throw new Error(`Context "${s}" not found. Make sure to wrap component in its Provider.`);
1638
1941
  return n;
1639
1942
  }, 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;
1943
+ }, [et, it] = Ie("NodeProvider");
1944
+ 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;
1646
1949
  if (!d)
1647
1950
  throw new Error(
1648
1951
  `No ${s} component found. Provide either option.${s}.slot, global ${s === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`
1649
1952
  );
1650
- return [d, c];
1953
+ return [d, l];
1651
1954
  }
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 = {
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 = {
1654
1957
  value: s.value,
1655
1958
  meta: s.meta,
1656
1959
  nested: s.nested?.content,
1657
1960
  children: s.children.length > 0 ? o : void 0
1658
- }, [a, l] = st("mark", r, i);
1659
- return /* @__PURE__ */ f(a, { ...l });
1961
+ }, [a, c] = mt("mark", r, i);
1962
+ return /* @__PURE__ */ f(a, { ...c });
1660
1963
  }
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]);
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]);
1663
1966
  if (s.type !== "text")
1664
1967
  throw new Error("TextSpan component expects a TextToken");
1665
- return ct(() => {
1968
+ return Ct(() => {
1666
1969
  e.current && e.current.textContent !== s.content && (e.current.textContent = s.content);
1667
- }, [s.content]), /* @__PURE__ */ f(
1668
- i,
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";
1973
+ 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;
1976
+ const C = k(
1977
+ (y, b) => {
1978
+ if (!a || !c) return;
1979
+ const T = m.current, L = me(a, T, y, b);
1980
+ if (L !== a) {
1981
+ const p = R(s, L);
1982
+ s.state.tokens.set(p), s.state.previousValue.set(L), c(L);
1983
+ }
1984
+ },
1985
+ [s, a, c]
1986
+ );
1987
+ return /* @__PURE__ */ f(
1988
+ g,
1669
1989
  {
1670
- ...a,
1671
- ref: e,
1672
- contentEditable: !n,
1673
- onPaste: se,
1674
- suppressContentEditableWarning: !0
1990
+ ref: (y) => d.container = y,
1991
+ ...u,
1992
+ className: r,
1993
+ 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))
1675
1995
  }
1676
1996
  );
1677
- };
1678
- function se(s) {
1679
- s.preventDefault();
1680
- const t = s.clipboardData.getData("text");
1681
- document.execCommand("insertText", !1, t);
1682
- }
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]);
1997
+ });
1998
+ yt.displayName = "BlockContainer";
1999
+ 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]);
1687
2001
  return /* @__PURE__ */ f(
1688
- l,
2002
+ c,
1689
2003
  {
1690
2004
  ref: (d) => a.container = d,
1691
- ...c,
2005
+ ...l,
1692
2006
  className: r,
1693
2007
  style: o,
1694
- children: t.map((d) => /* @__PURE__ */ f(G, { mark: d }, i.get(d)))
2008
+ children: t.map((d) => /* @__PURE__ */ f(F, { mark: d }, i.get(d)))
1695
2009
  }
1696
2010
  );
1697
2011
  });
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(
2012
+ xt.displayName = "Container";
2013
+ function Le() {
2014
+ const s = E(), t = s.state.overlayMatch.use(), e = w.getAbsolutePosition(), n = k(() => s.events.clearOverlay(), []), r = k(
1701
2015
  (i) => {
1702
2016
  const a = {
1703
2017
  type: "mark",
@@ -1715,7 +2029,7 @@ function re() {
1715
2029
  s.events.select({ mark: a, match: t }), s.events.clearOverlay();
1716
2030
  },
1717
2031
  [t]
1718
- ), o = C(
2032
+ ), o = S(
1719
2033
  () => ({
1720
2034
  get current() {
1721
2035
  return s.refs.overlay;
@@ -1728,136 +2042,116 @@ function re() {
1728
2042
  );
1729
2043
  return { match: t, style: e, select: r, close: n, ref: o };
1730
2044
  }
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(
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(
1737
2051
  () => a.filter((d) => d.toLowerCase().indexOf(t.value.toLowerCase()) > -1),
1738
2052
  [t.value, a]
1739
- ), c = l.length;
1740
- return S(() => {
2053
+ ), l = c.length;
2054
+ return M(() => {
1741
2055
  const d = s.refs.container;
1742
2056
  if (!d) return;
1743
- const u = (h) => {
1744
- switch (h.key) {
2057
+ const g = (u) => {
2058
+ switch (u.key) {
1745
2059
  case v.UP:
1746
- h.preventDefault(), i((g) => isNaN(g) ? 0 : (c + (g - 1) % c) % c);
2060
+ u.preventDefault(), i((h) => isNaN(h) ? 0 : (l + (h - 1) % l) % l);
1747
2061
  break;
1748
2062
  case v.DOWN:
1749
- h.preventDefault(), i((g) => isNaN(g) ? 0 : (g + 1) % c);
2063
+ u.preventDefault(), i((h) => isNaN(h) ? 0 : (h + 1) % l);
1750
2064
  break;
1751
2065
  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;
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;
1756
2070
  });
1757
2071
  break;
1758
2072
  }
1759
2073
  };
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;
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;
1763
2077
  return /* @__PURE__ */ f(
1764
2078
  "li",
1765
2079
  {
1766
- ref: (g) => {
1767
- h && g && g.scrollIntoView(!1);
2080
+ ref: (h) => {
2081
+ u && h && h.scrollIntoView(!1);
1768
2082
  },
1769
- className: h,
1770
- onClick: (g) => e({ value: d, meta: u.toString() }),
2083
+ className: u,
2084
+ onClick: (h) => e({ value: d, meta: g.toString() }),
1771
2085
  children: d
1772
2086
  },
1773
2087
  d
1774
2088
  );
1775
2089
  }) }) : 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);
2090
+ }, 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);
1778
2092
  if (e) return /* @__PURE__ */ f(n, { ...r ?? {} }, e);
1779
2093
  });
1780
- ot.displayName = "OverlayRenderer";
1781
- function le(s, t) {
1782
- lt(t, () => s.createHandler(), [s]), S(() => (s.lifecycle.enable({
1783
- getTrigger: (a) => a.overlay?.trigger
1784
- }), () => s.lifecycle.disable()), []);
1785
- const e = s.state.value.use(), n = s.state.Mark.use(), r = s.state.options.use(), o = n ? r : void 0;
1786
- S(() => {
1787
- s.lifecycle.syncParser(e, o);
1788
- }, [e, o]);
1789
- const i = s.state.tokens.use();
1790
- S(() => {
1791
- s.lifecycle.recoverFocus();
1792
- }, [i]);
1793
- }
1794
- const de = (s) => () => {
1795
- const [t, e] = L(() => s.get());
1796
- return S(() => s.on(e), [s]), t;
1797
- }, he = [
1798
- {
1799
- markup: pt,
1800
- overlay: {
1801
- trigger: ft,
1802
- data: []
1803
- }
1804
- }
1805
- ];
1806
- function me(s) {
2094
+ kt.displayName = "OverlayRenderer";
2095
+ function Fe(s) {
1807
2096
  const {
1808
2097
  ref: t,
1809
2098
  value: e,
1810
2099
  defaultValue: n,
1811
2100
  onChange: r,
1812
2101
  readOnly: o = !1,
1813
- Mark: i,
1814
- Overlay: a,
2102
+ block: i = !1,
2103
+ Mark: a,
2104
+ Overlay: c,
1815
2105
  slots: l,
1816
- slotProps: c,
1817
- options: d = he,
2106
+ slotProps: d,
2107
+ options: g = Se,
1818
2108
  showOverlayOn: u = "change",
1819
2109
  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({
2110
+ 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({
1823
2113
  value: e,
1824
2114
  defaultValue: n,
1825
2115
  onChange: r,
1826
2116
  readOnly: o,
1827
- options: d,
2117
+ options: g,
1828
2118
  showOverlayOn: u,
1829
- Mark: i,
1830
- Overlay: a,
1831
- className: w,
1832
- style: E,
2119
+ Mark: a,
2120
+ Overlay: c,
2121
+ className: C,
2122
+ style: y,
1833
2123
  slots: l,
1834
- slotProps: c
1835
- }), le(T, t), /* @__PURE__ */ at(U.Provider, { value: T, children: [
1836
- /* @__PURE__ */ f(rt, {}),
1837
- /* @__PURE__ */ f(ot, {})
2124
+ 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, {})
1838
2130
  ] });
1839
2131
  }
1840
- const xe = (s = {}) => {
1841
- const t = k(), e = W(), n = J(null);
2132
+ const We = (s = {}) => {
2133
+ const t = E(), e = et(), n = $(null);
1842
2134
  if (e.type !== "mark")
1843
2135
  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);
2136
+ const [r] = P(() => new fe({ ref: n, store: t, token: e }));
2137
+ _e(n, s, e);
1846
2138
  const o = t.state.readOnly.use();
1847
- return S(() => {
2139
+ return M(() => {
1848
2140
  r.readOnly = o;
1849
2141
  }, [o]), r;
1850
2142
  };
1851
- function ue(s, t, e) {
1852
- S(() => {
2143
+ function _e(s, t, e) {
2144
+ M(() => {
1853
2145
  s.current && !t.controlled && (s.current.textContent = e.content);
1854
2146
  }, []);
1855
2147
  }
1856
2148
  export {
1857
- Kt as MarkHandler,
1858
- me as MarkedInput,
1859
- $ as annotate,
1860
- ve as denote,
1861
- xe as useMark,
1862
- re as useOverlay
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
1863
2157
  };