@markput/react 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +11 -12
  2. package/index.js +844 -642
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -47,18 +47,18 @@ var x = /* @__PURE__ */ function(e) {
47
47
  }], C = {
48
48
  Value: "__value__",
49
49
  Meta: "__meta__",
50
- Nested: "__nested__"
50
+ Slot: "__slot__"
51
51
  }, w = {
52
52
  Value: "value",
53
53
  Meta: "meta",
54
- Nested: "nested"
54
+ Slot: "slot"
55
55
  };
56
56
  //#endregion
57
- //#region ../../common/core/src/features/parsing/ParserV2/core/MarkupDescriptor.ts
57
+ //#region ../../common/core/src/features/parsing/parser/core/MarkupDescriptor.ts
58
58
  function T(e, t) {
59
- let { segments: n, gapTypes: r, counts: i, valueGapIndices: a } = E(e);
60
- D(i, e);
61
- let o = i.value === 2, { segments: s, gapTypes: c } = o ? k(n, r, a) : {
59
+ let { segments: n, gapTypes: r, counts: i, valueGapIndices: a } = D(e);
60
+ O(i, e);
61
+ let o = i.value === 2, { segments: s, gapTypes: c } = o ? ee(n, r, a) : {
62
62
  segments: n,
63
63
  gapTypes: r
64
64
  };
@@ -67,23 +67,28 @@ function T(e, t) {
67
67
  index: t,
68
68
  segments: s,
69
69
  gapTypes: c,
70
- hasNested: i.nested === 1,
70
+ hasSlot: i.slot === 1,
71
71
  hasTwoValues: o,
72
72
  segmentGlobalIndices: Array.from({ length: s.length })
73
73
  };
74
74
  }
75
- function E(e) {
75
+ var E = {
76
+ [w.Value]: C.Value,
77
+ [w.Meta]: C.Meta,
78
+ [w.Slot]: C.Slot
79
+ };
80
+ function D(e) {
76
81
  let t = [], n = [], r = [], i = {
77
82
  value: 0,
78
83
  meta: 0,
79
- nested: 0
84
+ slot: 0
80
85
  }, a = [], o = [
81
86
  w.Value,
82
87
  w.Meta,
83
- w.Nested
88
+ w.Slot
84
89
  ];
85
90
  for (let t of o) {
86
- let n = O[t], r = e.indexOf(n);
91
+ let n = E[t], r = e.indexOf(n);
87
92
  for (; r !== -1;) a.push({
88
93
  type: t,
89
94
  position: r
@@ -93,7 +98,7 @@ function E(e) {
93
98
  let s = 0;
94
99
  for (let o of a) {
95
100
  let a = e.substring(s, o.position);
96
- a.length > 0 && t.push(a), n.push(o.type), i[o.type]++, o.type === w.Value && r.push(n.length - 1), s = o.position + O[o.type].length;
101
+ a.length > 0 && t.push(a), n.push(o.type), i[o.type]++, o.type === w.Value && r.push(n.length - 1), s = o.position + E[o.type].length;
97
102
  }
98
103
  let c = e.substring(s);
99
104
  return c.length > 0 && t.push(c), {
@@ -103,7 +108,7 @@ function E(e) {
103
108
  valueGapIndices: r
104
109
  };
105
110
  }
106
- function D(e, t) {
111
+ function O(e, t) {
107
112
  let n = [
108
113
  {
109
114
  count: e.value,
@@ -116,34 +121,29 @@ function D(e, t) {
116
121
  name: C.Meta
117
122
  },
118
123
  {
119
- count: e.nested,
124
+ count: e.slot,
120
125
  max: 1,
121
- name: C.Nested
126
+ name: C.Slot
122
127
  }
123
128
  ];
124
129
  for (let { count: e, max: r, name: i } of n) if (e > r) throw Error(`Invalid markup: "${t}". Max ${r} "${i}" placeholders, got ${e}`);
125
- if (e.value === 0 && e.nested === 0) throw Error(`Invalid markup: "${t}". Need at least one "${C.Value}" or "${C.Nested}"`);
130
+ if (e.value === 0 && e.slot === 0) throw Error(`Invalid markup: "${t}". Need at least one "${C.Value}" or "${C.Slot}"`);
126
131
  }
127
- var O = {
128
- [w.Value]: C.Value,
129
- [w.Meta]: C.Meta,
130
- [w.Nested]: C.Nested
131
- };
132
- function k(e, t, n) {
132
+ function ee(e, t, n) {
133
133
  if (n.length !== 2) return {
134
134
  segments: e,
135
135
  gapTypes: t
136
136
  };
137
137
  let [r, i] = n, a = [], o = e[r], s = e[r + 1];
138
- o && s && a.push(A(o, s, e[r + 2]));
138
+ o && s && a.push(k(o, s, e[r + 2]));
139
139
  for (let t = r + 2; t < i; t++) a.push(e[t]);
140
140
  let c = e[i], l = e[i + 1];
141
- return c && l && a.push(A(c, l, e[i + 2])), {
141
+ return c && l && a.push(k(c, l, e[i + 2])), {
142
142
  segments: a,
143
143
  gapTypes: t.filter((e) => e !== w.Value)
144
144
  };
145
145
  }
146
- function A(e, t, n) {
146
+ function k(e, t, n) {
147
147
  if (!n) return [
148
148
  e,
149
149
  t,
@@ -157,7 +157,11 @@ function A(e, t, n) {
157
157
  ];
158
158
  }
159
159
  //#endregion
160
- //#region ../../common/core/src/features/parsing/ParserV2/core/MarkupRegistry.ts
160
+ //#region ../../common/core/src/features/parsing/parser/core/MarkupRegistry.ts
161
+ function A(e, t) {
162
+ let n = e.get(t);
163
+ return n || (n = [], e.set(t, n)), n;
164
+ }
161
165
  var j = class {
162
166
  markups;
163
167
  descriptors;
@@ -176,9 +180,7 @@ var j = class {
176
180
  }
177
181
  addToFirstSegmentIndexMap(e) {
178
182
  let t = e.segmentGlobalIndices[0];
179
- if (t === void 0) return;
180
- let n = this.firstSegmentIndexMap.get(t);
181
- n ? n.push(e) : this.firstSegmentIndexMap.set(t, [e]);
183
+ t !== void 0 && A(this.firstSegmentIndexMap, t).push(e);
182
184
  }
183
185
  processSegment(e, t, n, r) {
184
186
  let i = this.getSegmentKey(t);
@@ -203,7 +205,7 @@ var j = class {
203
205
  }
204
206
  };
205
207
  //#endregion
206
- //#region ../../common/core/src/features/parsing/ParserV2/utils/getSegmentIndex.ts
208
+ //#region ../../common/core/src/features/parsing/parser/utils/getSegmentIndex.ts
207
209
  function M(e, t) {
208
210
  if (!t) return e;
209
211
  let n = 5381;
@@ -211,8 +213,8 @@ function M(e, t) {
211
213
  return n >>>= 0, e * 1e6 + (n & 1048575);
212
214
  }
213
215
  //#endregion
214
- //#region ../../common/core/src/features/parsing/ParserV2/core/Match.ts
215
- var ee = class {
216
+ //#region ../../common/core/src/features/parsing/parser/core/Match.ts
217
+ var te = class {
216
218
  gaps = {};
217
219
  captured;
218
220
  expectedSegmentIndex;
@@ -261,9 +263,16 @@ var ee = class {
261
263
  }, this.end = e.end, this.expectedSegmentIndex++, this.expectedSegmentIndex >= this.descriptor.segments.length && (this.expectedSegmentIndex = NaN);
262
264
  }
263
265
  conflictsWith(e) {
264
- return !e || this.start >= e.end ? !1 : !e.descriptor.hasNested || e.gaps.nested === void 0 ? !0 : !(this.start >= e.gaps.nested.start && this.end <= e.gaps.nested.end);
266
+ return !e || this.start >= e.end ? !1 : !e.descriptor.hasSlot || e.gaps.slot === void 0 ? !0 : !(this.start >= e.gaps.slot.start && this.end <= e.gaps.slot.end);
265
267
  }
266
- }, te = class {
268
+ };
269
+ //#endregion
270
+ //#region ../../common/core/src/features/parsing/parser/core/PatternMatcher.ts
271
+ function ne(e, t) {
272
+ let n = e.get(t);
273
+ return n || (n = [], e.set(t, n)), n;
274
+ }
275
+ var re = class {
267
276
  pendingStates = /* @__PURE__ */ new Map();
268
277
  completingStates = /* @__PURE__ */ new Map();
269
278
  completedStates = [];
@@ -284,7 +293,7 @@ var ee = class {
284
293
  }
285
294
  tryStartNewStates(e) {
286
295
  this.registry.firstSegmentIndexMap.get(e.index)?.forEach((t) => {
287
- let n = new ee(t, e);
296
+ let n = new te(t, e);
288
297
  if (!n.isInvalid) {
289
298
  if (n.isCompleted) return this.addToCompleted(n);
290
299
  this.addToWaiting(n);
@@ -299,13 +308,7 @@ var ee = class {
299
308
  }
300
309
  addToWaiting(e) {
301
310
  let t = e.nextSegment;
302
- if (e.isAwaitingLastSegment) {
303
- let n = this.completingStates.get(t) || [];
304
- n.length === 0 && this.completingStates.set(t, n), n.push(e);
305
- } else {
306
- let n = this.pendingStates.get(t) || [];
307
- n.length === 0 && this.pendingStates.set(t, n), n.push(e);
308
- }
311
+ ne(e.isAwaitingLastSegment ? this.completingStates : this.pendingStates, t).push(e);
309
312
  }
310
313
  addToCompleted(e) {
311
314
  let t = e.start, n = 0, r = this.completedStates.length;
@@ -320,92 +323,97 @@ var ee = class {
320
323
  }
321
324
  }, N = (e) => e.replace(/[.*+?^${}()|[\]\\\\]/g, "\\$&");
322
325
  //#endregion
323
- //#region ../../common/core/src/features/parsing/ParserV2/core/SegmentMatcher.ts
324
- function ne(e, t, n) {
326
+ //#region ../../common/core/src/features/parsing/parser/core/SegmentMatcher.ts
327
+ function P(e, t, n) {
325
328
  let r = N(e), i = N(t);
326
329
  return `${r}([^${N(t + n)}]+?)${i}`;
327
330
  }
328
- var re = class {
329
- staticRegex;
330
- staticToIndex;
331
- dynamicRegex;
332
- dynamicEntries;
333
- dynamicIndices;
331
+ var F = class {
332
+ static;
333
+ dynamic;
334
334
  constructor(e) {
335
335
  this.initializeDual(e);
336
336
  }
337
337
  initializeDual(e) {
338
338
  let t = [], n = [], r = /* @__PURE__ */ new Map();
339
339
  if (e.forEach((e, i) => {
340
- typeof e == "string" ? (t.push(e), r.set(e, i)) : n.push(e);
340
+ typeof e == "string" ? (t.push(e), r.set(e, i)) : n.push({
341
+ segment: e,
342
+ index: i
343
+ });
341
344
  }), t.length > 0) {
342
- let e = [...t].sort((e, t) => t.length - e.length).map(N);
343
- this.staticRegex = RegExp(`(?:${e.join("|")})`, "gu"), this.staticToIndex = r;
345
+ let e = [...t].toSorted((e, t) => t.length - e.length).map(N);
346
+ this.static = {
347
+ regex: RegExp(`(?:${e.join("|")})`, "gu"),
348
+ toIndex: r
349
+ };
344
350
  }
345
351
  if (n.length > 0) {
346
- let t = /* @__PURE__ */ new Set(), r = [];
347
- n.forEach((n) => {
348
- let i = e.indexOf(n);
349
- if (typeof n == "string") r.push({
350
- index: i,
351
- pattern: N(n),
352
+ let e = /* @__PURE__ */ new Set(), t = [];
353
+ n.forEach(({ segment: n, index: r }) => {
354
+ let [i, a, o] = n;
355
+ e.add(r);
356
+ let s = P(i, a, o).replace("(", `(?<content${r}>`);
357
+ t.push({
358
+ index: r,
359
+ pattern: s,
352
360
  definition: n
353
361
  });
354
- else {
355
- let [e, a, o] = n;
356
- t.add(i);
357
- let s = ne(e, a, o).replace("(", `(?<content${i}>`);
358
- r.push({
359
- index: i,
360
- pattern: s,
361
- definition: n
362
- });
363
- }
364
- }), r.sort((e, t) => {
362
+ }), t.sort((e, t) => {
365
363
  let n = typeof e.definition == "string" ? e.definition.length : e.pattern.length;
366
364
  return (typeof t.definition == "string" ? t.definition.length : t.pattern.length) - n;
367
- }), this.dynamicEntries = r, this.dynamicIndices = t, this.dynamicRegex = new RegExp(r.map((e, t) => `(?<seg${t}>${e.pattern})`).join("|"), "gu");
365
+ }), this.dynamic = {
366
+ entries: t,
367
+ indices: e,
368
+ regex: new RegExp(t.map((e, t) => `(?<seg${t}>${e.pattern})`).join("|"), "gu")
369
+ };
368
370
  }
369
371
  }
370
372
  search(e) {
371
373
  let t = [], n = [];
372
- if (this.staticRegex && this.staticToIndex) for (let n of e.matchAll(this.staticRegex)) {
373
- let e = this.staticToIndex.get(n[0]);
374
- e !== void 0 && t.push({
375
- index: e,
376
- start: n.index,
377
- end: n.index + n[0].length,
378
- value: n[0]
379
- });
374
+ if (this.static) {
375
+ let { regex: n, toIndex: r } = this.static;
376
+ for (let i of e.matchAll(n)) {
377
+ let e = r.get(i[0]);
378
+ e !== void 0 && t.push({
379
+ index: e,
380
+ start: i.index,
381
+ end: i.index + i[0].length,
382
+ value: i[0]
383
+ });
384
+ }
380
385
  }
381
- if (this.dynamicRegex && this.dynamicEntries && this.dynamicIndices) for (let t of e.matchAll(this.dynamicRegex)) {
382
- let e = t[0], r = t.index, i, a;
383
- if (t.groups) {
384
- for (let e = 0; e < this.dynamicEntries.length; e++) if (t.groups[`seg${e}`] !== void 0) {
385
- i = this.dynamicEntries[e].index, this.dynamicIndices.has(i) && (a = t.groups[`content${i}`]);
386
- break;
386
+ if (this.dynamic) {
387
+ let { regex: t, entries: r, indices: i } = this.dynamic;
388
+ for (let a of e.matchAll(t)) {
389
+ let e = a[0], t = a.index, o, s;
390
+ if (a.groups) {
391
+ for (let e = 0; e < r.length; e++) if (a.groups[`seg${e}`] !== void 0) {
392
+ o = r[e].index, i.has(o) && (s = a.groups[`content${o}`]);
393
+ break;
394
+ }
387
395
  }
396
+ o !== void 0 && n.push({
397
+ index: o,
398
+ start: t,
399
+ end: t + e.length,
400
+ value: e,
401
+ captured: s
402
+ });
388
403
  }
389
- i !== void 0 && n.push({
390
- index: i,
391
- start: r,
392
- end: r + e.length,
393
- value: e,
394
- captured: a
395
- });
396
404
  }
397
405
  let r = [...n];
398
406
  for (let e of t) n.some((t) => e.start < t.end && e.end > t.start) || r.push(e);
399
407
  return r.sort((e, t) => e.start - t.start), r;
400
408
  }
401
- }, ie = (e, t = 0, n = e.length) => ({
409
+ }, I = (e, t = 0, n = e.length) => ({
402
410
  type: "text",
403
411
  content: e.substring(t, n),
404
412
  position: {
405
413
  start: t,
406
414
  end: n
407
415
  }
408
- }), ae = class {
416
+ }), ie = class {
409
417
  input;
410
418
  build(e, t) {
411
419
  return this.input = t, e.length === 0 ? [this.createTextToken(0, t.length)] : this.buildSinglePass(e);
@@ -428,7 +436,7 @@ var re = class {
428
436
  t.push(e), i = a.end;
429
437
  }
430
438
  let o = this.createMarkToken(a);
431
- if (this.hasNestedContent(a)) {
439
+ if (this.hasSlotContent(a)) {
432
440
  let e = this.getContentBounds(a);
433
441
  n.push({
434
442
  match: a,
@@ -444,11 +452,10 @@ var re = class {
444
452
  return t.push(this.createTextToken(i, this.input.length)), t;
445
453
  }
446
454
  finalizeParent(e, t) {
447
- let n = this.createTextToken(e.textPos, t);
448
- e.token.children.push(n), e.token.children.some((e) => e.type === "mark") || (e.token.children = []);
455
+ e.token.children.push(this.createTextToken(e.textPos, t));
449
456
  }
450
457
  createMarkToken(e) {
451
- let t = this.extractSubstring(e.gaps.value?.start, e.gaps.value?.end), n = this.extractSubstring(e.gaps.nested?.start, e.gaps.nested?.end), r = this.extractSubstring(e.gaps.meta?.start, e.gaps.meta?.end), i = n || void 0, a = e.gaps.meta === void 0 ? void 0 : r, o = t || i || "";
458
+ let t = this.extractSubstring(e.gaps.value?.start, e.gaps.value?.end), n = this.extractSubstring(e.gaps.slot?.start, e.gaps.slot?.end), r = this.extractSubstring(e.gaps.meta?.start, e.gaps.meta?.end), i = n || void 0, a = e.gaps.meta === void 0 ? void 0 : r, o = t || i || "";
452
459
  return {
453
460
  type: "mark",
454
461
  content: this.input.substring(e.start, e.end),
@@ -460,39 +467,39 @@ var re = class {
460
467
  start: e.start,
461
468
  end: e.end
462
469
  },
463
- nested: this.createNestedInfo(e, i)
470
+ slot: this.createSlotSourceInfo(e, i)
464
471
  };
465
472
  }
466
473
  getContentBounds(e) {
467
- return e.gaps.nested ? e.gaps.nested : e.gaps.value ? e.gaps.value : {
474
+ return e.gaps.slot ? e.gaps.slot : e.gaps.value ? e.gaps.value : {
468
475
  start: e.start,
469
476
  end: e.start
470
477
  };
471
478
  }
472
- hasNestedContent(e) {
473
- return e.gaps.nested !== void 0;
479
+ hasSlotContent(e) {
480
+ return e.gaps.slot !== void 0;
474
481
  }
475
482
  extractSubstring(e, t) {
476
483
  return e !== void 0 && t !== void 0 ? this.input.substring(e, t) : "";
477
484
  }
478
485
  createTextToken(e, t) {
479
- return ie(this.input, e, t);
486
+ return I(this.input, e, t);
480
487
  }
481
- createNestedInfo(e, t) {
482
- if (!(!t || e.gaps.nested === void 0)) return {
488
+ createSlotSourceInfo(e, t) {
489
+ if (!(!t || e.gaps.slot === void 0)) return {
483
490
  content: t,
484
- start: e.gaps.nested.start,
485
- end: e.gaps.nested.end
491
+ start: e.gaps.slot.start,
492
+ end: e.gaps.slot.end
486
493
  };
487
494
  }
488
495
  };
489
496
  //#endregion
490
- //#region ../../common/core/src/features/parsing/ParserV2/utils/processTokens.ts
491
- function oe(e, t) {
497
+ //#region ../../common/core/src/features/parsing/parser/utils/processTokens.ts
498
+ function L(e, t) {
492
499
  let n = "";
493
500
  for (let r of e) if (r.type === "text") n += r.content;
494
501
  else if (r.children.length > 0) {
495
- let e = oe(r.children, t), i = {
502
+ let e = L(r.children, t), i = {
496
503
  ...r,
497
504
  value: e
498
505
  };
@@ -501,85 +508,85 @@ function oe(e, t) {
501
508
  return n;
502
509
  }
503
510
  //#endregion
504
- //#region ../../common/core/src/features/parsing/ParserV2/utils/annotate.ts
505
- function P(e, t) {
511
+ //#region ../../common/core/src/features/parsing/parser/utils/annotate.ts
512
+ function R(e, t) {
506
513
  let n = e;
507
- return t.value !== void 0 && (n = n.replaceAll(C.Value, t.value)), t.meta !== void 0 && (n = n.replaceAll(C.Meta, t.meta)), t.nested !== void 0 && (n = n.replaceAll(C.Nested, t.nested)), n;
514
+ return t.value !== void 0 && (n = n.replaceAll(C.Value, t.value)), t.meta !== void 0 && (n = n.replaceAll(C.Meta, t.meta)), t.slot !== void 0 && (n = n.replaceAll(C.Slot, t.slot)), n;
508
515
  }
509
516
  //#endregion
510
- //#region ../../common/core/src/features/parsing/ParserV2/utils/toString.ts
511
- function F(e) {
517
+ //#region ../../common/core/src/features/parsing/parser/utils/toString.ts
518
+ function z(e) {
512
519
  let t = "";
513
520
  for (let n of e) {
514
521
  if (n.type === "text") {
515
522
  t += n.content;
516
523
  continue;
517
524
  }
518
- let e = n.descriptor.markup, r = e.includes(C.Nested) ? n.children.length > 0 ? F(n.children) : n.nested?.content : void 0;
519
- t += P(e, {
525
+ let { markup: e, hasSlot: r } = n.descriptor, i = r ? n.children.length > 0 ? z(n.children) : n.slot?.content : void 0;
526
+ t += R(e, {
520
527
  value: n.value,
521
528
  meta: n.meta,
522
- nested: r
529
+ slot: i
523
530
  });
524
531
  }
525
532
  return t;
526
533
  }
527
534
  //#endregion
528
- //#region ../../common/core/src/features/parsing/ParserV2/Parser.ts
529
- var se = class e {
535
+ //#region ../../common/core/src/features/parsing/parser/Parser.ts
536
+ var B = class e {
530
537
  registry;
531
538
  segmentMatcher;
532
539
  patternMatcher;
533
540
  treeBuilder;
534
541
  constructor(e) {
535
- this.registry = new j(e), this.segmentMatcher = new re(this.registry.segments), this.patternMatcher = new te(this.registry), this.treeBuilder = new ae();
542
+ this.registry = new j(e), this.segmentMatcher = new F(this.registry.segments), this.patternMatcher = new re(this.registry), this.treeBuilder = new ie();
536
543
  }
537
544
  static parse(t, n) {
538
545
  let r = n?.markup;
539
- return !r || r.length === 0 ? [ie(t)] : new e(r).parse(t);
546
+ return !r || r.length === 0 ? [I(t)] : new e(r).parse(t);
540
547
  }
541
548
  static stringify(e) {
542
- return F(e);
549
+ return z(e);
543
550
  }
544
551
  parse(e) {
545
552
  let t = this.segmentMatcher.search(e), n = this.patternMatcher.process(t);
546
553
  return this.treeBuilder.build(n, e);
547
554
  }
548
555
  stringify(e) {
549
- return F(e);
556
+ return z(e);
550
557
  }
551
558
  transform(e, t) {
552
- return oe(this.parse(e), t);
559
+ return L(this.parse(e), t);
553
560
  }
554
561
  escape(e) {
555
- return this.registry.segments.filter((e) => typeof e == "string").sort((e, t) => t.length - e.length).reduce((e, t) => e.replaceAll(t, t.replace(/(.)/g, "\\$1")), e);
562
+ return this.registry.segments.filter((e) => typeof e == "string").toSorted((e, t) => t.length - e.length).reduce((e, t) => e.replaceAll(t, t.replace(/(.)/g, "\\$1")), e);
556
563
  }
557
564
  unescape(e) {
558
565
  return e.replaceAll(/\\(.)/g, "$1");
559
566
  }
560
567
  };
561
568
  //#endregion
562
- //#region ../../common/core/src/features/parsing/ParserV2/utils/denote.ts
563
- function ce(e, t, n) {
564
- return n.length ? oe(new se(n).parse(e), t) : e;
569
+ //#region ../../common/core/src/features/parsing/parser/utils/denote.ts
570
+ function ae(e, t, n) {
571
+ return n.length ? L(new B(n).parse(e), t) : e;
565
572
  }
566
573
  //#endregion
567
574
  //#region ../../common/core/src/features/parsing/utils/findToken.ts
568
- function I(e, t, n = 0, r) {
575
+ function V(e, t, n = 0, r) {
569
576
  for (let i of e) {
570
577
  if (i === t) return {
571
578
  depth: n,
572
579
  parent: r
573
580
  };
574
581
  if (i.type === "mark") {
575
- let e = I(i.children, t, n + 1, i);
582
+ let e = V(i.children, t, n + 1, i);
576
583
  if (e) return e;
577
584
  }
578
585
  }
579
586
  }
580
587
  //#endregion
581
- //#region ../../common/core/src/features/preparsing/utils/findGap.ts
582
- function le(e = "", t = "") {
588
+ //#region ../../common/core/src/features/parsing/preparsing/utils/findGap.ts
589
+ function oe(e = "", t = "") {
583
590
  if (e === t) return {};
584
591
  let n;
585
592
  for (let r = 0; r < e.length; r++) if (e[r] !== t[r]) {
@@ -597,8 +604,8 @@ function le(e = "", t = "") {
597
604
  };
598
605
  }
599
606
  //#endregion
600
- //#region ../../common/core/src/features/preparsing/utils/getClosestIndexes.ts
601
- function ue(e, t) {
607
+ //#region ../../common/core/src/features/parsing/preparsing/utils/getClosestIndexes.ts
608
+ function se(e, t) {
602
609
  let n = -1, r = e.length;
603
610
  for (; r - n > 1;) {
604
611
  let i = Math.round((n + r) / 2);
@@ -608,49 +615,49 @@ function ue(e, t) {
608
615
  }
609
616
  //#endregion
610
617
  //#region ../../common/core/src/features/parsing/utils/valueParser.ts
611
- function de(e) {
618
+ function ce(e) {
612
619
  let { focus: t } = e.nodes, n = e.state.parser.get(), r = e.state.tokens.get();
613
620
  if (!n) return r;
614
621
  let i = n.parse(t.content);
615
622
  return i.length === 1 ? r : r.toSpliced(t.index, 1, ...i);
616
623
  }
617
- function fe(e) {
618
- let t = e.state.value.get(), n = pe(e), r = le(e.state.previousValue.get(), t);
624
+ function le(e) {
625
+ let t = e.state.value.get(), n = de(e), r = oe(e.state.previousValue.get(), t);
619
626
  if (!r.left && !r.right) return e.state.previousValue.set(t), e.state.tokens.get();
620
627
  e.state.previousValue.set(t);
621
628
  let i = e.state.tokens.get();
622
629
  switch (!0) {
623
630
  case r.left !== void 0 && n.includes(r.left) && r.right !== void 0 && Math.abs(r.left - r.right) > 1: {
624
- let t = n.indexOf(r.left), a = L(e, t - 1, t);
631
+ let t = n.indexOf(r.left), a = ue(e, t - 1, t);
625
632
  return i.toSpliced(t - 1, 2, ...a);
626
633
  }
627
634
  case r.left !== void 0: {
628
- let [t] = ue(n, r.left), a = L(e, t);
635
+ let [t] = se(n, r.left), a = ue(e, t);
629
636
  return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
630
637
  }
631
638
  case r.right !== void 0: {
632
- let [t] = ue(n, r.right), a = L(e, t);
639
+ let [t] = se(n, r.right), a = ue(e, t);
633
640
  return a.length === 1 ? i : i.toSpliced(t, 1, ...a);
634
641
  }
635
- default: return R(e, t ?? "");
642
+ default: return H(e, t ?? "");
636
643
  }
637
644
  }
638
- function L(e, ...t) {
645
+ function ue(e, ...t) {
639
646
  let n = "", r = e.state.tokens.get();
640
647
  for (let e of t) {
641
648
  let t = r[e];
642
649
  n += t.content;
643
650
  }
644
- return R(e, n);
651
+ return H(e, n);
645
652
  }
646
- function pe(e) {
653
+ function de(e) {
647
654
  let t = 0;
648
655
  return e.state.tokens.get().map((e) => {
649
656
  let n = e.content.length;
650
657
  return t += n, t - n;
651
658
  }) ?? [];
652
659
  }
653
- function R(e, t) {
660
+ function H(e, t) {
654
661
  let n = e.state.parser.get();
655
662
  return n ? n.parse(t) : [{
656
663
  type: "text",
@@ -663,12 +670,12 @@ function R(e, t) {
663
670
  }
664
671
  //#endregion
665
672
  //#region ../../common/core/src/shared/classes/Reactive.ts
666
- var me = (e, t) => e === t, z = class e {
673
+ var fe = (e, t) => e === t, pe = class e {
667
674
  #e;
668
675
  #t = /* @__PURE__ */ new Set();
669
676
  #n;
670
677
  constructor(e, t) {
671
- this.#e = e, this.#n = t?.equals ?? me;
678
+ this.#e = e, this.#n = t?.equals ?? fe;
672
679
  }
673
680
  static event() {
674
681
  return new e(void 0, { equals: !1 });
@@ -694,46 +701,46 @@ var me = (e, t) => e === t, z = class e {
694
701
  };
695
702
  //#endregion
696
703
  //#region ../../common/core/src/shared/classes/defineState.ts
697
- function he(e, t) {
704
+ function me(e, t) {
698
705
  let n = {};
699
706
  return n.get = () => e.get(), n.set = (t) => e.set(t), n.on = (t) => e.on(t), n.use = t(n), n;
700
707
  }
701
- function ge(e, t) {
708
+ function he(e, t) {
702
709
  let n = /* @__PURE__ */ new Map();
703
- for (let t in e) n.set(t, new z(e[t]));
710
+ for (let t in e) n.set(t, new pe(e[t]));
704
711
  return new Proxy(e, { get(e, r) {
705
712
  if (r === "set") return (e) => {
706
713
  for (let t in e) n.get(t)?.set(e[t]);
707
714
  };
708
715
  let i = n.get(r);
709
- if (i) return he(i, t);
716
+ if (i) return me(i, t);
710
717
  } });
711
718
  }
712
719
  //#endregion
713
720
  //#region ../../common/core/src/shared/classes/defineEvents.ts
714
- function _e(e) {
721
+ function ge(e) {
715
722
  let t = function(t) {
716
723
  e.emit(t);
717
724
  };
718
725
  return t.on = (t) => e.on(t), t;
719
726
  }
720
- function ve(e) {
727
+ function _e(e) {
721
728
  let t = e ? Object.keys(e) : [], n = /* @__PURE__ */ new Map();
722
- for (let e of t) n.set(e, z.event());
729
+ for (let e of t) n.set(e, pe.event());
723
730
  return new Proxy({}, { get(e, t) {
724
731
  let r = n.get(t);
725
- return r || (r = z.event(), n.set(t, r)), _e(r);
732
+ return r || (r = pe.event(), n.set(t, r)), ge(r);
726
733
  } });
727
734
  }
728
735
  //#endregion
729
736
  //#region ../../common/core/src/shared/classes/KeyGenerator.ts
730
- var ye = class {
737
+ var ve = class {
731
738
  #e = 1;
732
739
  #t = /* @__PURE__ */ new WeakMap();
733
740
  get(e) {
734
741
  return this.#t.has(e) ? this.#t.get(e) : (this.#t.set(e, this.#e), this.#e++);
735
742
  }
736
- }, B = class {
743
+ }, U = class {
737
744
  static get isSelectedPosition() {
738
745
  let e = window.getSelection();
739
746
  if (e) return e.isCollapsed;
@@ -746,7 +753,7 @@ var ye = class {
746
753
  }
747
754
  static getSelectedNode() {
748
755
  let e = window.getSelection()?.anchorNode;
749
- if (e) return e;
756
+ if (e && document.contains(e)) return e;
750
757
  throw Error("Anchor node of selection is not exists!");
751
758
  }
752
759
  static getAbsolutePosition() {
@@ -838,16 +845,20 @@ var ye = class {
838
845
  let n = window.getSelection()?.getRangeAt(0);
839
846
  n?.setStart(n.endContainer, t), n?.setEnd(n.endContainer, t);
840
847
  }
841
- }, be = /* @__PURE__ */ new RegExp(/^\w*/), xe = class e {
848
+ }, ye = /* @__PURE__ */ new RegExp(/^\w*/), be = class e {
842
849
  span;
843
850
  node;
844
851
  dividedText;
845
852
  constructor() {
846
- let e = B.getCurrentPosition();
847
- this.node = B.getSelectedNode(), this.span = B.getFocusedSpan(), this.dividedText = this.getDividedTextBy(e);
853
+ let e = U.getCurrentPosition();
854
+ this.node = U.getSelectedNode(), this.span = U.getFocusedSpan(), this.dividedText = this.getDividedTextBy(e);
848
855
  }
849
856
  static find(t, n) {
850
- if (t && B.isSelectedPosition) return new e().find(t, n);
857
+ if (t && U.isSelectedPosition) try {
858
+ return new e().find(t, n);
859
+ } catch {
860
+ return;
861
+ }
851
862
  }
852
863
  getDividedTextBy(e) {
853
864
  return {
@@ -880,7 +891,7 @@ var ye = class {
880
891
  }
881
892
  matchRightPart() {
882
893
  let { right: e } = this.dividedText;
883
- return { word: e.match(be)?.[0] };
894
+ return { word: e.match(ye)?.[0] };
884
895
  }
885
896
  matchLeftPart(e) {
886
897
  let t = this.makeTriggerRegex(e), { left: n } = this.dividedText, r = n.match(t);
@@ -896,7 +907,7 @@ var ye = class {
896
907
  let t = N(e) + "(\\w*)$";
897
908
  return new RegExp(t);
898
909
  }
899
- }, Se = class e {
910
+ }, xe = class e {
900
911
  #e;
901
912
  #t;
902
913
  get target() {
@@ -921,19 +932,19 @@ var ye = class {
921
932
  return this.target?.isContentEditable ?? !1;
922
933
  }
923
934
  get isCaretAtBeginning() {
924
- if (this.target) return B.getCaretIndex(this.target) === 0;
935
+ if (this.target) return U.getCaretIndex(this.target) === 0;
925
936
  }
926
937
  get isCaretAtEnd() {
927
- if (this.target) return B.getCaretIndex(this.target) === this.target.textContent?.length;
938
+ if (this.target) return U.getCaretIndex(this.target) === this.target.textContent?.length;
928
939
  }
929
940
  get index() {
930
941
  return this.target?.parentElement ? [...this.target.parentElement.children].indexOf(this.target) : -1;
931
942
  }
932
943
  get caret() {
933
- return this.target ? B.getCaretIndex(this.target) : -1;
944
+ return this.target ? U.getCaretIndex(this.target) : -1;
934
945
  }
935
946
  set caret(e) {
936
- this.target && B.trySetIndex(this.target, e);
947
+ this.target && U.trySetIndex(this.target, e);
937
948
  }
938
949
  get length() {
939
950
  return this.target?.textContent?.length ?? -1;
@@ -957,7 +968,7 @@ var ye = class {
957
968
  this.target = e, this.#t = t;
958
969
  }
959
970
  setCaretToEnd() {
960
- B.setCaretToEnd(this.target);
971
+ U.setCaretToEnd(this.target);
961
972
  }
962
973
  focus() {
963
974
  this.target?.focus();
@@ -967,13 +978,13 @@ var ye = class {
967
978
  }
968
979
  };
969
980
  //#endregion
970
- //#region ../../common/core/src/features/text-manipulation/utils/createNewSpan.ts
971
- function Ce(e, t, n, r) {
981
+ //#region ../../common/core/src/features/editing/utils/createNewSpan.ts
982
+ function Se(e, t, n, r) {
972
983
  return e.slice(0, n) + t + e.slice(n + r.length);
973
984
  }
974
985
  //#endregion
975
- //#region ../../common/core/src/features/text-manipulation/utils/deleteMark.ts
976
- function V(e, t) {
986
+ //#region ../../common/core/src/features/editing/utils/deleteMark.ts
987
+ function Ce(e, t) {
977
988
  let n = {
978
989
  prev: 2,
979
990
  self: 1,
@@ -993,11 +1004,136 @@ function V(e, t) {
993
1004
  t.state.recovery.set({
994
1005
  anchor: l.prev,
995
1006
  caret: u
996
- }), t.state.onChange.get()?.(F(t.state.tokens.get()));
1007
+ }), t.state.onChange.get()?.(z(t.state.tokens.get()));
1008
+ }
1009
+ //#endregion
1010
+ //#region ../../common/core/src/features/blocks/config.ts
1011
+ function we(e) {
1012
+ return typeof e == "object" && !!e.alwaysShowHandle;
1013
+ }
1014
+ //#endregion
1015
+ //#region ../../common/core/src/features/blocks/splitTokensIntoDragRows.ts
1016
+ function Te(e) {
1017
+ let t = [], { content: n, position: r } = e, i = r.start, a = [], o = () => {
1018
+ if (a.length > 0) {
1019
+ let e = a.join("");
1020
+ t.push({
1021
+ content: e,
1022
+ position: {
1023
+ start: i,
1024
+ end: i + e.length
1025
+ },
1026
+ isBlockSeparator: !1
1027
+ }), i += e.length, a.length = 0;
1028
+ }
1029
+ };
1030
+ for (let e = 0; e < n.length; e++) {
1031
+ let r = n[e];
1032
+ r === "\n" ? e + 1 < n.length && n[e + 1] === "\n" ? (o(), t.push({
1033
+ content: "\n\n",
1034
+ position: {
1035
+ start: i,
1036
+ end: i + 2
1037
+ },
1038
+ isBlockSeparator: !0
1039
+ }), i += 2, e++) : (a.push(r), i++) : r === "\r" ? e + 1 < n.length && n[e + 1] === "\n" ? e + 2 < n.length && n[e + 2] === "\r" && e + 3 < n.length && n[e + 3] === "\n" ? (o(), t.push({
1040
+ content: "\n\n",
1041
+ position: {
1042
+ start: i,
1043
+ end: i + 4
1044
+ },
1045
+ isBlockSeparator: !0
1046
+ }), i += 4, e += 3) : (a.push("\n"), i += 2, e++) : (a.push("\n"), i++) : a.push(r);
1047
+ }
1048
+ return o(), t;
1049
+ }
1050
+ var Ee = 0;
1051
+ function W(e) {
1052
+ return `drag-${Ee++}-${e}`;
1053
+ }
1054
+ function De() {
1055
+ Ee = 0;
1056
+ }
1057
+ function G(e) {
1058
+ if (e.length === 0) return [];
1059
+ De();
1060
+ let t = [], n = null;
1061
+ for (let r of e) if (r.type === "mark") n = null, t.push({
1062
+ id: W(r.position.start),
1063
+ tokens: [r],
1064
+ startPos: r.position.start,
1065
+ endPos: r.position.end
1066
+ });
1067
+ else if (r.type === "text") {
1068
+ let e = Te(r);
1069
+ for (let r of e) r.isBlockSeparator ? (n !== null && t.push({
1070
+ id: W(n),
1071
+ tokens: [],
1072
+ startPos: n,
1073
+ endPos: n
1074
+ }), n = r.position.end) : r.content.trim().length > 0 && (n = null, t.push({
1075
+ id: W(r.position.start),
1076
+ tokens: [{
1077
+ type: "text",
1078
+ content: r.content,
1079
+ position: r.position
1080
+ }],
1081
+ startPos: r.position.start,
1082
+ endPos: r.position.end
1083
+ }));
1084
+ }
1085
+ return n !== null && t.push({
1086
+ id: W(n),
1087
+ tokens: [],
1088
+ startPos: n,
1089
+ endPos: n
1090
+ }), t;
1091
+ }
1092
+ //#endregion
1093
+ //#region ../../common/core/src/features/blocks/dragOperations.ts
1094
+ function K(e) {
1095
+ return e.tokens.length === 0 || e.tokens[0].type === "text";
1096
+ }
1097
+ function Oe(e, t) {
1098
+ return K(e) && K(t) ? "\n\n" : "";
1099
+ }
1100
+ function ke(e, t, n) {
1101
+ if (t.length === 0) return e + "\n\n";
1102
+ if (n >= t.length - 1) return e === "" ? "\n\n\n\n" : e + "\n\n";
1103
+ let r = t[n], i = t[n + 1];
1104
+ return i.startPos - r.endPos === 0 ? e.slice(0, r.endPos) + "\n\n\n\n" + e.slice(i.startPos) : e.slice(0, i.startPos) + "\n\n" + e.slice(i.startPos);
1105
+ }
1106
+ function Ae(e, t, n) {
1107
+ return t.length <= 1 ? "" : n >= t.length - 1 ? e.slice(0, t[n - 1].endPos) : e.slice(0, t[n].startPos) + e.slice(t[n + 1].startPos);
1108
+ }
1109
+ function je(e, t, n) {
1110
+ let r = t[n], i = e.substring(r.startPos, r.endPos);
1111
+ if (n >= t.length - 1) return e + (K(r), "\n\n") + i;
1112
+ let a = t[n + 1], o = a.startPos - r.endPos === 0 ? "" : "\n\n";
1113
+ return e.slice(0, a.startPos) + i + o + e.slice(a.startPos);
1114
+ }
1115
+ function Me(e, t) {
1116
+ return t <= 0 || t >= e.length ? 0 : e[t - 1].endPos;
1117
+ }
1118
+ function Ne(e, t, n) {
1119
+ if (n <= 0 || n >= t.length) return e;
1120
+ let r = t[n - 1], i = t[n];
1121
+ return e.slice(0, r.endPos) + e.slice(i.startPos);
1122
+ }
1123
+ function Pe(e, t, n, r) {
1124
+ if (n === r || n === r - 1 || t.length < 2 || n < 0 || n >= t.length || r < 0 || r > t.length) return e;
1125
+ let i = t.map((t) => e.substring(t.startPos, t.endPos)), a = [...t], [o] = a.splice(n, 1), [s] = i.splice(n, 1), c = r > n ? r - 1 : r;
1126
+ a.splice(c, 0, o), i.splice(c, 0, s);
1127
+ let l = [];
1128
+ for (let e = 0; e < i.length; e++) l.push(i[e]), e < i.length - 1 && l.push(Oe(a[e], a[e + 1]));
1129
+ return l.join("");
997
1130
  }
998
1131
  //#endregion
999
1132
  //#region ../../common/core/src/features/editable/ContentEditableController.ts
1000
- var we = class {
1133
+ function Fe(e) {
1134
+ return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
1135
+ }
1136
+ var Ie = class {
1001
1137
  #e;
1002
1138
  constructor(e) {
1003
1139
  this.store = e;
@@ -1011,10 +1147,65 @@ var we = class {
1011
1147
  sync() {
1012
1148
  let e = this.store.refs.container;
1013
1149
  if (!e) return;
1014
- let t = this.store.state.readOnly.get() ? "false" : "true", n = e.children, r = this.store.state.drag.get() ? 1 : 2;
1015
- for (let e = 0; e < n.length; e += r) n[e].contentEditable = t;
1150
+ let t = this.store.state.readOnly.get(), n = t ? "false" : "true", r = e.children, i = !!this.store.state.drag.get();
1151
+ if (i) {
1152
+ let e = G(this.store.state.tokens.get());
1153
+ for (let i = 0; i < e.length && i < r.length; i++) {
1154
+ let a = r[i];
1155
+ e[i].tokens.length === 1 && e[i].tokens[0].type === "mark" ? t || (a.tabIndex = 0) : a.contentEditable = n;
1156
+ }
1157
+ } else for (let e = 0; e < r.length; e += 2) r[e].contentEditable = n;
1158
+ let a = this.store.state.tokens.get();
1159
+ i ? this.#r(a, e, t) : this.#t(a, e);
1160
+ }
1161
+ #t(e, t) {
1162
+ let n = t.children;
1163
+ for (let t = 0; t < e.length; t++) {
1164
+ let r = e[t], i = n[t];
1165
+ i && (r.type === "text" ? i.textContent !== r.content && (i.textContent = r.content) : r.type === "mark" && r.children.length > 0 && this.#n(r.children, i));
1166
+ }
1167
+ }
1168
+ #n(e, t, n) {
1169
+ let r = t.children, i = 0;
1170
+ for (let t of e) if (t.type === "text") {
1171
+ for (; i < r.length;) {
1172
+ let e = r[i];
1173
+ if (Fe(e)) break;
1174
+ i++;
1175
+ }
1176
+ let e = r[i];
1177
+ e && (e.textContent !== t.content && (e.textContent = t.content), n !== void 0 && (e.contentEditable = n), i++);
1178
+ } else if (t.type === "mark" && t.children.length > 0) {
1179
+ for (; i < r.length;) {
1180
+ let e = r[i];
1181
+ if (!Fe(e)) break;
1182
+ i++;
1183
+ }
1184
+ let e = r[i];
1185
+ e && (this.#n(t.children, e, n), i++);
1186
+ }
1016
1187
  }
1017
- }, Te = class {
1188
+ #r(e, t, n) {
1189
+ let r = n ? "false" : "true", i = G(e);
1190
+ for (let e = 0; e < i.length; e++) {
1191
+ let a = i[e], o = t.children[e];
1192
+ if (!o) continue;
1193
+ if (a.tokens.length === 1 && a.tokens[0].type === "mark") {
1194
+ let e = a.tokens[0];
1195
+ if (e.type === "mark" && e.children.length > 0) {
1196
+ let t = o.hasAttribute("data-testid") ? o.children[n ? 0 : 1] : o;
1197
+ t && this.#n(e.children, t, r);
1198
+ }
1199
+ continue;
1200
+ }
1201
+ let s = n ? 0 : 1;
1202
+ for (let e = 0; e < a.tokens.length; e++) {
1203
+ let t = a.tokens[e], n = o.children[e + s];
1204
+ n && t.type === "text" && n.textContent !== t.content && (n.textContent = t.content);
1205
+ }
1206
+ }
1207
+ }
1208
+ }, Le = class {
1018
1209
  #e;
1019
1210
  #t;
1020
1211
  #n;
@@ -1023,20 +1214,24 @@ var we = class {
1023
1214
  }
1024
1215
  enable() {
1025
1216
  this.#e || (this.#e = this.store.events.change.on(() => {
1026
- let e = this.store.state.onChange.get();
1027
- if (!this.store.nodes.focus.target) return;
1028
- let t = this.store.state.tokens.get(), n = t[this.store.nodes.focus.index];
1029
- n.type === "text" ? n.content = this.store.nodes.focus.content : n.type === "mark" && (n.value = this.store.nodes.focus.content), e?.(F(t)), this.store.events.parse();
1217
+ let e = this.store.state.onChange.get(), { focus: t } = this.store.nodes;
1218
+ if (!t.target || !t.target.isContentEditable) {
1219
+ let t = this.store.state.tokens.get(), n = z(t);
1220
+ e?.(n), this.store.state.previousValue.set(n), this.store.state.tokens.set([...t]);
1221
+ return;
1222
+ }
1223
+ let n = this.store.state.tokens.get(), r = n[t.index];
1224
+ r.type === "text" ? r.content = t.content : r.type === "mark" && (r.value = t.content), e?.(z(n)), this.store.events.parse();
1030
1225
  }), this.#t = this.store.events.delete.on((e) => {
1031
1226
  if (!e) return;
1032
1227
  let { token: t } = e, n = this.store.state.onChange.get(), r = this.store.state.tokens.get(), i = r.indexOf(t);
1033
- this.store.state.tokens.set(r.toSpliced(i, 1)), n?.(F(this.store.state.tokens.get()));
1228
+ this.store.state.tokens.set(r.toSpliced(i, 1)), n?.(z(this.store.state.tokens.get()));
1034
1229
  }), this.#n = this.store.events.select.on((e) => {
1035
1230
  if (!e) return;
1036
- let t = this.store.state.Mark.get(), n = this.store.state.onChange.get(), { mark: r, match: { option: i, span: a, index: o, source: s } } = e, c = r.type === "mark" ? P(i.markup, {
1231
+ let t = this.store.state.Mark.get(), n = this.store.state.onChange.get(), { mark: r, match: { option: i, span: a, index: o, source: s } } = e, c = r.type === "mark" ? R(i.markup, {
1037
1232
  value: r.value,
1038
1233
  meta: r.meta
1039
- }) : P(i.markup, { value: r.content }), l = Ce(a, c, o, s);
1234
+ }) : R(i.markup, { value: r.content }), l = Se(a, c, o, s);
1040
1235
  if (this.store.state.recovery.set(t ? {
1041
1236
  caret: 0,
1042
1237
  anchor: this.store.nodes.input.next,
@@ -1048,14 +1243,14 @@ var we = class {
1048
1243
  }), this.store.nodes.input.target) {
1049
1244
  this.store.nodes.input.content = l;
1050
1245
  let e = this.store.state.tokens.get(), t = e[this.store.nodes.input.index];
1051
- t.type === "text" && (t.content = l), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(F(e)), this.store.events.parse();
1246
+ t.type === "text" && (t.content = l), this.store.nodes.focus.target = this.store.nodes.input.target, this.store.nodes.input.clear(), n?.(z(e)), this.store.events.parse();
1052
1247
  }
1053
1248
  }));
1054
1249
  }
1055
1250
  disable() {
1056
1251
  this.#e?.(), this.#t?.(), this.#n?.(), this.#e = void 0, this.#t = void 0, this.#n = void 0;
1057
1252
  }
1058
- }, Ee = class {
1253
+ }, Re = class {
1059
1254
  #e;
1060
1255
  #t;
1061
1256
  #n;
@@ -1100,150 +1295,49 @@ var we = class {
1100
1295
  }
1101
1296
  };
1102
1297
  //#endregion
1103
- //#region ../../common/core/src/features/blocks/config.ts
1104
- function De(e) {
1105
- return typeof e == "object" && !!e.alwaysShowHandle;
1106
- }
1107
- //#endregion
1108
- //#region ../../common/core/src/features/blocks/dragOperations.ts
1109
- function H(e) {
1110
- return e.tokens.length === 0 || e.tokens[0].type === "text";
1111
- }
1112
- function Oe(e, t) {
1113
- return H(e) && H(t) ? "\n\n" : "";
1114
- }
1115
- function ke(e, t, n) {
1116
- if (t.length === 0) return e + "\n\n";
1117
- if (n >= t.length - 1) return e === "" ? "\n\n\n\n" : e + "\n\n";
1118
- let r = t[n], i = t[n + 1];
1119
- return i.startPos - r.endPos === 0 ? e.slice(0, r.endPos) + "\n\n\n\n" + e.slice(i.startPos) : e.slice(0, i.startPos) + "\n\n" + e.slice(i.startPos);
1120
- }
1121
- function Ae(e, t, n) {
1122
- return t.length <= 1 ? "" : n >= t.length - 1 ? e.slice(0, t[n - 1].endPos) : e.slice(0, t[n].startPos) + e.slice(t[n + 1].startPos);
1123
- }
1124
- function je(e, t, n) {
1125
- let r = t[n], i = e.substring(r.startPos, r.endPos);
1126
- if (n >= t.length - 1) return e + (H(r), "\n\n") + i;
1127
- let a = t[n + 1], o = a.startPos - r.endPos === 0 ? "" : "\n\n";
1128
- return e.slice(0, a.startPos) + i + o + e.slice(a.startPos);
1129
- }
1130
- function Me(e, t) {
1131
- return t <= 0 || t >= e.length ? 0 : e[t - 1].endPos;
1132
- }
1133
- function U(e, t, n) {
1134
- if (n <= 0 || n >= t.length) return e;
1135
- let r = t[n - 1], i = t[n];
1136
- return e.slice(0, r.endPos) + e.slice(i.startPos);
1137
- }
1138
- function Ne(e, t, n, r) {
1139
- if (n === r || n === r - 1 || t.length < 2 || n < 0 || n >= t.length || r < 0 || r > t.length) return e;
1140
- let i = t.map((t) => e.substring(t.startPos, t.endPos)), a = [...t], [o] = a.splice(n, 1), [s] = i.splice(n, 1), c = r > n ? r - 1 : r;
1141
- a.splice(c, 0, o), i.splice(c, 0, s);
1142
- let l = [];
1143
- for (let e = 0; e < i.length; e++) l.push(i[e]), e < i.length - 1 && l.push(Oe(a[e], a[e + 1]));
1144
- return l.join("");
1145
- }
1146
- //#endregion
1147
- //#region ../../common/core/src/features/blocks/splitTokensIntoDragRows.ts
1148
- function Pe(e) {
1149
- let t = [], { content: n, position: r } = e, i = r.start, a = [], o = () => {
1150
- if (a.length > 0) {
1151
- let e = a.join("");
1152
- t.push({
1153
- content: e,
1154
- position: {
1155
- start: i,
1156
- end: i + e.length
1157
- },
1158
- isBlockSeparator: !1
1159
- }), i += e.length, a.length = 0;
1160
- }
1161
- };
1162
- for (let e = 0; e < n.length; e++) {
1163
- let r = n[e];
1164
- r === "\n" ? e + 1 < n.length && n[e + 1] === "\n" ? (o(), t.push({
1165
- content: "\n\n",
1166
- position: {
1167
- start: i,
1168
- end: i + 2
1169
- },
1170
- isBlockSeparator: !0
1171
- }), i += 2, e++) : (a.push(r), i++) : r === "\r" ? e + 1 < n.length && n[e + 1] === "\n" ? e + 2 < n.length && n[e + 2] === "\r" && e + 3 < n.length && n[e + 3] === "\n" ? (o(), t.push({
1172
- content: "\n\n",
1173
- position: {
1174
- start: i,
1175
- end: i + 4
1176
- },
1177
- isBlockSeparator: !0
1178
- }), i += 4, e += 3) : (a.push("\n"), i += 2, e++) : (a.push("\n"), i++) : a.push(r);
1179
- }
1180
- return o(), t;
1181
- }
1182
- var Fe = 0;
1183
- function W(e) {
1184
- return `drag-${Fe++}-${e}`;
1185
- }
1186
- function Ie() {
1187
- Fe = 0;
1188
- }
1189
- function G(e) {
1190
- if (e.length === 0) return [];
1191
- Ie();
1192
- let t = [], n = null;
1193
- for (let r of e) if (r.type === "mark") n = null, t.push({
1194
- id: W(r.position.start),
1195
- tokens: [r],
1196
- startPos: r.position.start,
1197
- endPos: r.position.end
1198
- });
1199
- else if (r.type === "text") {
1200
- let e = Pe(r);
1201
- for (let r of e) r.isBlockSeparator ? (n !== null && t.push({
1202
- id: W(n),
1203
- tokens: [],
1204
- startPos: n,
1205
- endPos: n
1206
- }), n = r.position.end) : r.content.trim().length > 0 && (n = null, t.push({
1207
- id: W(r.position.start),
1208
- tokens: [{
1209
- type: "text",
1210
- content: r.content,
1211
- position: r.position
1212
- }],
1213
- startPos: r.position.start,
1214
- endPos: r.position.end
1215
- }));
1216
- }
1217
- return n !== null && t.push({
1218
- id: W(n),
1219
- tokens: [],
1220
- startPos: n,
1221
- endPos: n
1222
- }), t;
1223
- }
1224
- //#endregion
1225
- //#region ../../common/core/src/features/navigation/index.ts
1226
- function Le(e, t) {
1298
+ //#region ../../common/core/src/features/navigation/navigation.ts
1299
+ function ze(e, t) {
1227
1300
  let { focus: n } = e.nodes;
1228
1301
  if (n.isMark && !n.isEditable || n.isCaretAtBeginning) {
1229
1302
  let e = n.prev;
1230
1303
  for (; e.target && e.isMark && !e.isEditable;) e = e.prev;
1231
- return e.target ? (t.preventDefault(), e.target.focus(), B.setCaretToEnd(e.target), !0) : !1;
1304
+ return e.target ? (t.preventDefault(), e.target.focus(), U.setCaretToEnd(e.target), !0) : !1;
1232
1305
  }
1233
1306
  return !1;
1234
1307
  }
1235
- function Re(e, t) {
1308
+ function Be(e, t) {
1236
1309
  let { focus: n } = e.nodes;
1237
1310
  if (n.isMark && !n.isEditable || n.isCaretAtEnd) {
1238
1311
  let e = n.next;
1239
1312
  for (; e.target && e.isMark && !e.isEditable;) e = e.next;
1240
- return e.target ? (t.preventDefault(), e.target.focus(), B.trySetIndex(e.target, 0), !0) : !1;
1313
+ return e.target ? (t.preventDefault(), e.target.focus(), U.trySetIndex(e.target, 0), !0) : !1;
1241
1314
  }
1242
1315
  return !1;
1243
1316
  }
1244
1317
  //#endregion
1318
+ //#region ../../common/core/src/features/selection/selectionHelpers.ts
1319
+ function Ve(e) {
1320
+ let t = window.getSelection(), n = e.refs.container;
1321
+ if (!t?.rangeCount || !n?.firstChild || !n?.lastChild) return !1;
1322
+ try {
1323
+ let e = t.getRangeAt(0);
1324
+ return n.contains(e.startContainer) && n.contains(e.endContainer) && e.toString().length > 0;
1325
+ } catch {
1326
+ return !1;
1327
+ }
1328
+ }
1329
+ function He(e, t) {
1330
+ if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
1331
+ if (e.state.drag.get()) return;
1332
+ t.preventDefault();
1333
+ let n = window.getSelection(), r = e.refs.container?.firstChild, i = e.refs.container?.lastChild;
1334
+ if (!n || !r || !i) return;
1335
+ n.setBaseAndExtent(r, 0, i, 1), e.state.selecting.set("all");
1336
+ }
1337
+ }
1338
+ //#endregion
1245
1339
  //#region ../../common/core/src/features/selection/TextSelectionController.ts
1246
- var ze = class {
1340
+ var Ue = class {
1247
1341
  #e;
1248
1342
  #t;
1249
1343
  #n;
@@ -1270,21 +1364,7 @@ var ze = class {
1270
1364
  disable() {
1271
1365
  this.#e && (document.removeEventListener("mousedown", this.#e), document.removeEventListener("mousemove", this.#t), document.removeEventListener("mouseup", this.#n), document.removeEventListener("selectionchange", this.#r), this.#e = void 0, this.#t = void 0, this.#n = void 0, this.#r = void 0), this.#i = null, this.#a = !1;
1272
1366
  }
1273
- };
1274
- //#endregion
1275
- //#region ../../common/core/src/features/selection/index.ts
1276
- function Be(e, t) {
1277
- if ((t.ctrlKey || t.metaKey) && t.code === "KeyA") {
1278
- if (e.state.drag.get()) return;
1279
- t.preventDefault();
1280
- let n = window.getSelection(), r = e.refs.container?.firstChild, i = e.refs.container?.lastChild;
1281
- if (!n || !r || !i) return;
1282
- n.setBaseAndExtent(r, 0, i, 1), e.state.selecting.set("all");
1283
- }
1284
- }
1285
- //#endregion
1286
- //#region ../../common/core/src/features/input/KeyDownController.ts
1287
- var Ve = class {
1367
+ }, We = class {
1288
1368
  #e;
1289
1369
  #t;
1290
1370
  #n;
@@ -1295,11 +1375,11 @@ var Ve = class {
1295
1375
  if (this.#e) return;
1296
1376
  let e = this.store.refs.container;
1297
1377
  e && (this.#e = (e) => {
1298
- e.key === x.LEFT ? Le(this.store, e) : e.key === x.RIGHT ? Re(this.store, e) : (e.key === x.UP || e.key === x.DOWN) && this.#a(e), this.#r(e), this.#i(e), Be(this.store, e);
1378
+ e.key === x.LEFT ? ze(this.store, e) : e.key === x.RIGHT ? Be(this.store, e) : (e.key === x.UP || e.key === x.DOWN) && this.#a(e), this.#r(e), this.#i(e), He(this.store, e);
1299
1379
  }, this.#t = (e) => {
1300
- We(this.store, e);
1380
+ Je(this.store, e);
1301
1381
  }, this.#n = (e) => {
1302
- He(this.store, e);
1382
+ Ke(this.store, e);
1303
1383
  }, e.addEventListener("keydown", this.#e), e.addEventListener("paste", this.#t), e.addEventListener("beforeinput", this.#n, !0));
1304
1384
  }
1305
1385
  disable() {
@@ -1311,15 +1391,15 @@ var Ve = class {
1311
1391
  if (!n && (e.key === x.DELETE || e.key === x.BACKSPACE)) {
1312
1392
  if (t.isMark) {
1313
1393
  if (t.isEditable && (e.key === x.BACKSPACE && !t.isCaretAtBeginning || e.key === x.DELETE && !t.isCaretAtEnd)) return;
1314
- e.preventDefault(), V("self", this.store);
1394
+ e.preventDefault(), Ce("self", this.store);
1315
1395
  return;
1316
1396
  }
1317
1397
  if (e.key === x.BACKSPACE && t.isSpan && t.isCaretAtBeginning && t.prev.target) {
1318
- e.preventDefault(), V("prev", this.store);
1398
+ e.preventDefault(), Ce("prev", this.store);
1319
1399
  return;
1320
1400
  }
1321
1401
  if (e.key === x.DELETE && t.isSpan && t.isCaretAtEnd && t.next.target) {
1322
- e.preventDefault(), V("next", this.store);
1402
+ e.preventDefault(), Ce("next", this.store);
1323
1403
  return;
1324
1404
  }
1325
1405
  }
@@ -1330,24 +1410,24 @@ var Ve = class {
1330
1410
  if (a === -1) return;
1331
1411
  let o = G(this.store.state.tokens.get());
1332
1412
  if (a >= o.length) return;
1333
- let s = o[a], c = this.store.state.value.get() ?? this.store.state.previousValue.get() ?? "";
1413
+ let s = o[a], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
1334
1414
  if (this.store.state.onChange.get()) {
1335
1415
  if (e.key === x.BACKSPACE) {
1336
- let t = i[a], n = B.getCaretIndex(t) === 0;
1416
+ let t = i[a], n = U.getCaretIndex(t) === 0;
1337
1417
  if (s.tokens.map((e) => "content" in e ? e.content : "").join("") === "") {
1338
1418
  e.preventDefault();
1339
1419
  let t = o.length <= 1 ? "" : a >= o.length - 1 ? c.slice(0, o[a - 1].endPos) : c.slice(0, o[a].startPos) + c.slice(o[a + 1].startPos);
1340
1420
  this.store.applyValue(t), queueMicrotask(() => {
1341
1421
  let e = r.children[Math.max(0, a - 1)];
1342
- e && (e.focus(), B.setCaretToEnd(e));
1422
+ e && (e.focus(), U.setCaretToEnd(e));
1343
1423
  });
1344
1424
  return;
1345
1425
  }
1346
1426
  if (n && a > 0) {
1347
1427
  let t = o[a - 1], n = o[a], s = n.startPos - t.endPos;
1348
- if (H(t) && H(n) && s === 2) {
1428
+ if (K(t) && K(n) && s === 2) {
1349
1429
  e.preventDefault();
1350
- let t = Me(o, a), n = U(c, o, a);
1430
+ let t = Me(o, a), n = Ne(c, o, a);
1351
1431
  this.store.applyValue(n), queueMicrotask(() => {
1352
1432
  let e = r.children[a - 1];
1353
1433
  if (e) {
@@ -1360,18 +1440,18 @@ var Ve = class {
1360
1440
  }
1361
1441
  e.preventDefault(), queueMicrotask(() => {
1362
1442
  let e = i[a - 1];
1363
- e && (e.focus(), B.setCaretToEnd(e));
1443
+ e && (e.focus(), U.setCaretToEnd(e));
1364
1444
  });
1365
1445
  return;
1366
1446
  }
1367
1447
  }
1368
1448
  if (e.key === x.DELETE) {
1369
- let t = i[a], n = B.getCaretIndex(t), s = n === t.textContent?.length;
1449
+ let t = i[a], n = U.getCaretIndex(t), s = n === t.textContent?.length;
1370
1450
  if (n === 0 && a > 0) {
1371
1451
  let t = o[a - 1], n = o[a], s = n.startPos - t.endPos;
1372
- if (H(t) && H(n) && s === 2) {
1452
+ if (K(t) && K(n) && s === 2) {
1373
1453
  e.preventDefault();
1374
- let t = Me(o, a), n = U(c, o, a);
1454
+ let t = Me(o, a), n = Ne(c, o, a);
1375
1455
  this.store.applyValue(n), queueMicrotask(() => {
1376
1456
  let e = r.children[a - 1];
1377
1457
  if (e) {
@@ -1384,15 +1464,15 @@ var Ve = class {
1384
1464
  }
1385
1465
  e.preventDefault(), queueMicrotask(() => {
1386
1466
  let e = i[a - 1];
1387
- e && (e.focus(), B.setCaretToEnd(e));
1467
+ e && (e.focus(), U.setCaretToEnd(e));
1388
1468
  });
1389
1469
  return;
1390
1470
  }
1391
1471
  if (s && a < o.length - 1) {
1392
1472
  let t = o[a], n = o[a + 1], s = n.startPos - t.endPos;
1393
- if (H(t) && H(n) && s === 2) {
1473
+ if (K(t) && K(n) && s === 2) {
1394
1474
  e.preventDefault();
1395
- let n = t.endPos, i = U(c, o, a + 1);
1475
+ let n = t.endPos, i = Ne(c, o, a + 1);
1396
1476
  this.store.applyValue(i), queueMicrotask(() => {
1397
1477
  let e = r.children[a];
1398
1478
  if (e) {
@@ -1405,7 +1485,7 @@ var Ve = class {
1405
1485
  }
1406
1486
  e.preventDefault(), queueMicrotask(() => {
1407
1487
  let e = i[a + 1];
1408
- e && (e.focus(), B.trySetIndex(e, 0));
1488
+ e && (e.focus(), U.trySetIndex(e, 0));
1409
1489
  });
1410
1490
  return;
1411
1491
  }
@@ -1427,25 +1507,25 @@ var Ve = class {
1427
1507
  if (i === -1) return;
1428
1508
  let a = G(this.store.state.tokens.get()), o = a[i];
1429
1509
  if (!o) return;
1430
- let s = r[i], c = this.store.state.value.get() ?? "";
1510
+ let s = r[i], c = this.store.state.previousValue.get() ?? this.store.state.value.get() ?? "";
1431
1511
  if (!this.store.state.onChange.get()) return;
1432
- if (!H(o)) {
1512
+ if (!K(o)) {
1433
1513
  let e = ke(c, a, i);
1434
1514
  this.store.applyValue(e), queueMicrotask(() => {
1435
1515
  let e = t.children, n = i + 1;
1436
1516
  if (n < e.length) {
1437
1517
  let t = e[n];
1438
- t.focus(), B.trySetIndex(t, 0);
1518
+ t.focus(), U.trySetIndex(t, 0);
1439
1519
  }
1440
1520
  });
1441
1521
  return;
1442
1522
  }
1443
- let l = K(s, o), u = l === o.startPos ? "\n\n\n\n" : "\n\n", d = c.slice(0, l) + u + c.slice(l);
1523
+ let l = Ge(s, o), u = l === o.startPos ? "\n\n\n\n" : "\n\n", d = c.slice(0, l) + u + c.slice(l);
1444
1524
  this.store.applyValue(d), queueMicrotask(() => {
1445
1525
  let e = t.children, n = i + 1;
1446
1526
  if (n < e.length) {
1447
1527
  let t = e[n];
1448
- t.focus(), B.trySetIndex(t, 0);
1528
+ t.focus(), U.trySetIndex(t, 0);
1449
1529
  }
1450
1530
  });
1451
1531
  }
@@ -1459,46 +1539,46 @@ var Ve = class {
1459
1539
  if (i === -1) return;
1460
1540
  let a = r[i];
1461
1541
  if (e.key === x.UP) {
1462
- if (!B.isCaretOnFirstLine(a) || i === 0) return;
1542
+ if (!U.isCaretOnFirstLine(a) || i === 0) return;
1463
1543
  e.preventDefault();
1464
- let t = B.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i - 1];
1544
+ let t = U.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i - 1];
1465
1545
  n.focus();
1466
1546
  let o = n.getBoundingClientRect();
1467
- B.setAtX(n, t, o.bottom - 4);
1547
+ U.setAtX(n, t, o.bottom - 4);
1468
1548
  } else if (e.key === x.DOWN) {
1469
- if (!B.isCaretOnLastLine(a) || i >= r.length - 1) return;
1549
+ if (!U.isCaretOnLastLine(a) || i >= r.length - 1) return;
1470
1550
  e.preventDefault();
1471
- let t = B.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i + 1];
1551
+ let t = U.getCaretRect()?.left ?? a.getBoundingClientRect().left, n = r[i + 1];
1472
1552
  n.focus();
1473
1553
  let o = n.getBoundingClientRect();
1474
- B.setAtX(n, t, o.top + 4);
1554
+ U.setAtX(n, t, o.top + 4);
1475
1555
  }
1476
1556
  }
1477
1557
  };
1478
- function K(e, t) {
1558
+ function Ge(e, t) {
1479
1559
  let n = window.getSelection();
1480
1560
  if (!n?.rangeCount) return t.endPos;
1481
1561
  let { focusNode: r, focusOffset: i } = n;
1482
1562
  return r ? J(r, i, e, t) : t.endPos;
1483
1563
  }
1484
- function He(e, t) {
1564
+ function Ke(e, t) {
1485
1565
  let n = e.state.selecting.get();
1486
- if (n === "all" && Ge(e)) {
1566
+ if (n === "all" && Ve(e)) {
1487
1567
  if (t.inputType === "insertFromPaste") {
1488
1568
  t.preventDefault();
1489
1569
  return;
1490
1570
  }
1491
- t.preventDefault(), Ke(e, t.inputType.startsWith("delete") ? "" : t.data ?? "");
1571
+ t.preventDefault(), Ye(e, t.inputType.startsWith("delete") ? "" : t.data ?? "");
1492
1572
  return;
1493
1573
  }
1494
1574
  if (n === "all" && e.state.selecting.set(void 0), e.state.drag.get()) {
1495
- qe(e, t);
1575
+ Xe(e, t);
1496
1576
  return;
1497
1577
  }
1498
1578
  let { focus: r } = e.nodes;
1499
- !r.target || !r.isEditable || Ue(r, t) && e.events.change();
1579
+ !r.target || !r.isEditable || qe(r, t) && e.events.change();
1500
1580
  }
1501
- function Ue(e, t) {
1581
+ function qe(e, t) {
1502
1582
  let n = e.caret, r = e.content, i, a;
1503
1583
  switch (t.inputType) {
1504
1584
  case "insertText": {
@@ -1530,25 +1610,15 @@ function Ue(e, t) {
1530
1610
  }
1531
1611
  return e.content = i, e.caret = a, !0;
1532
1612
  }
1533
- function We(e, t) {
1613
+ function Je(e, t) {
1534
1614
  let n = e.state.selecting.get();
1535
- if (n !== "all" || !Ge(e)) {
1615
+ if (n !== "all" || !Ve(e)) {
1536
1616
  n === "all" && e.state.selecting.set(void 0);
1537
1617
  return;
1538
1618
  }
1539
- t.preventDefault(), Ke(e, t.clipboardData?.getData("text/plain") ?? "");
1540
- }
1541
- function Ge(e) {
1542
- let t = window.getSelection(), n = e.refs.container;
1543
- if (!t?.rangeCount || !n?.firstChild || !n?.lastChild) return !1;
1544
- try {
1545
- let e = t.getRangeAt(0);
1546
- return n.contains(e.startContainer) && n.contains(e.endContainer) && e.toString().length > 0;
1547
- } catch {
1548
- return !1;
1549
- }
1619
+ t.preventDefault(), Ye(e, t.clipboardData?.getData("text/plain") ?? "");
1550
1620
  }
1551
- function Ke(e, t) {
1621
+ function Ye(e, t) {
1552
1622
  e.nodes.focus.target = null, e.state.selecting.set(void 0), e.state.onChange.get()?.(t), e.state.value.get() === void 0 && e.state.tokens.set(e.state.parser.get()?.parse(t) ?? [{
1553
1623
  type: "text",
1554
1624
  content: t,
@@ -1564,7 +1634,7 @@ function Ke(e, t) {
1564
1634
  }), n.focus());
1565
1635
  });
1566
1636
  }
1567
- function qe(e, t) {
1637
+ function Xe(e, t) {
1568
1638
  let n = e.refs.container;
1569
1639
  if (!n) return;
1570
1640
  let r = document.activeElement;
@@ -1573,7 +1643,7 @@ function qe(e, t) {
1573
1643
  if (a === -1) return;
1574
1644
  let o = i[a], s = G(e.state.tokens.get());
1575
1645
  if (a >= s.length) return;
1576
- let c = s[a], l = e.state.value.get() ?? e.state.previousValue.get() ?? "", u = (t) => {
1646
+ let c = s[a], l = e.state.previousValue.get() ?? e.state.value.get() ?? "", u = (t) => {
1577
1647
  queueMicrotask(() => {
1578
1648
  let r = n.children[a];
1579
1649
  if (!r) return;
@@ -1589,7 +1659,7 @@ function qe(e, t) {
1589
1659
  if (r.length > 0) {
1590
1660
  let e = J(r[0].startContainer, r[0].startOffset, o, c), t = J(r[0].endContainer, r[0].endOffset, o, c);
1591
1661
  [i, a] = e <= t ? [e, t] : [t, e];
1592
- } else i = a = K(o, c);
1662
+ } else i = a = Ge(o, c);
1593
1663
  e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
1594
1664
  break;
1595
1665
  }
@@ -1600,7 +1670,7 @@ function qe(e, t) {
1600
1670
  if (r.length > 0) {
1601
1671
  let e = J(r[0].startContainer, r[0].startOffset, o, c), t = J(r[0].endContainer, r[0].endOffset, o, c);
1602
1672
  [i, a] = e <= t ? [e, t] : [t, e];
1603
- } else i = a = K(o, c);
1673
+ } else i = a = Ge(o, c);
1604
1674
  e.applyValue(l.slice(0, i) + n + l.slice(a)), u(i + n.length);
1605
1675
  break;
1606
1676
  }
@@ -1619,20 +1689,31 @@ function qe(e, t) {
1619
1689
  }
1620
1690
  }
1621
1691
  }
1622
- function Je(e, t, n) {
1692
+ function Ze(e) {
1693
+ return e.tagName === "SPAN" && (e.attributes.length === 0 || e.attributes.length === 1 && e.hasAttribute("contenteditable"));
1694
+ }
1695
+ function Qe(e, t, n) {
1623
1696
  let r = window.getSelection();
1624
1697
  if (!r) return !1;
1625
- if (!t.children || t.children.length === 0) {
1626
- let i = t.nested?.start ?? t.position.start, a = t.nested?.end ?? t.position.end, o = Math.max(0, Math.min(n - i, a - i)), s = document.createTreeWalker(e, 4).nextNode();
1627
- if (!s) return !1;
1628
- let c = document.createRange();
1629
- return c.setStart(s, Math.min(o, s.length)), c.collapse(!0), r.removeAllRanges(), r.addRange(c), !0;
1630
- }
1631
1698
  let i = 0;
1632
1699
  for (let a of Array.from(e.childNodes)) {
1633
1700
  if (i >= t.children.length) break;
1634
1701
  let e = t.children[i];
1635
- if (a.nodeType === Node.TEXT_NODE && e.type === "text") {
1702
+ if (a.nodeType === Node.ELEMENT_NODE && e.type === "text") {
1703
+ if (!Ze(a)) continue;
1704
+ if (n >= e.position.start && n <= e.position.end) {
1705
+ let t = a.firstChild, i = n - e.position.start;
1706
+ if (t) {
1707
+ let e = document.createRange();
1708
+ e.setStart(t, Math.min(i, t.length)), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
1709
+ } else {
1710
+ let e = document.createRange();
1711
+ e.setStart(a, 0), e.collapse(!0), r.removeAllRanges(), r.addRange(e);
1712
+ }
1713
+ return !0;
1714
+ }
1715
+ i++;
1716
+ } else if (a.nodeType === Node.TEXT_NODE && e.type === "text") {
1636
1717
  if (n >= e.position.start && n <= e.position.end) {
1637
1718
  let t = Math.min(n - e.position.start, a.length), i = document.createRange();
1638
1719
  return i.setStart(a, t), i.collapse(!0), r.removeAllRanges(), r.addRange(i), !0;
@@ -1640,7 +1721,7 @@ function Je(e, t, n) {
1640
1721
  i++;
1641
1722
  } else if (a.nodeType === Node.ELEMENT_NODE && e.type === "mark") {
1642
1723
  let r = i + 1 < t.children.length ? t.children[i + 1] : null;
1643
- if (!(n === e.position.end && r?.position.start === n) && n >= e.position.start && n <= e.position.end) return Je(a, e, n);
1724
+ if (!(n === e.position.end && r?.position.start === n) && n >= e.position.start && n <= e.position.end) return Qe(a, e, n);
1644
1725
  i++;
1645
1726
  }
1646
1727
  }
@@ -1649,65 +1730,84 @@ function Je(e, t, n) {
1649
1730
  function q(e, t, n) {
1650
1731
  let r = window.getSelection();
1651
1732
  if (!r) return;
1652
- let i = Array.from(e.children);
1733
+ let i = Array.from(e.children), a = e.hasAttribute("data-testid");
1734
+ if (!a && t.tokens.length === 1 && t.tokens[0].type === "mark") {
1735
+ if (Qe(e, t.tokens[0], n)) return;
1736
+ U.setCaretToEnd(e);
1737
+ return;
1738
+ }
1653
1739
  for (let e = 0; e < t.tokens.length; e++) {
1654
- let a = t.tokens[e], o = i[e + 1];
1655
- if (!o) continue;
1656
- let s = t.tokens[e + 1];
1657
- if (!(s && n === a.position.end && n === s.position.start) && n >= a.position.start && n <= a.position.end) {
1658
- if (a.type === "text") {
1659
- let e = n - a.position.start, t = document.createTreeWalker(o, 4).nextNode();
1740
+ let o = t.tokens[e], s = i[e + (a ? 1 : 0)];
1741
+ if (!s) continue;
1742
+ let c = t.tokens[e + 1];
1743
+ if (!(c && n === o.position.end && n === c.position.start) && n >= o.position.start && n <= o.position.end) {
1744
+ if (o.type === "text") {
1745
+ let e = n - o.position.start, t = document.createTreeWalker(s, 4).nextNode();
1660
1746
  if (t) {
1661
1747
  let n = Math.min(e, t.length), i = document.createRange();
1662
1748
  i.setStart(t, n), i.collapse(!0), r.removeAllRanges(), r.addRange(i);
1663
1749
  return;
1664
1750
  }
1665
1751
  }
1666
- if (Je(o, a, n)) return;
1752
+ if (Qe(s, o, n)) return;
1667
1753
  break;
1668
1754
  }
1669
1755
  }
1670
- B.setCaretToEnd(e);
1756
+ U.setCaretToEnd(e);
1671
1757
  }
1672
1758
  function J(e, t, n, r) {
1673
1759
  if (e === n) {
1674
1760
  let e = window.getSelection();
1675
1761
  return e?.focusNode && e.focusNode !== n ? J(e.focusNode, e.focusOffset, n, r) : r.endPos;
1676
1762
  }
1763
+ if (e.nodeType === Node.TEXT_NODE && e.parentElement === n) {
1764
+ let i = r.tokens[0];
1765
+ return i?.type === "mark" ? Y(e, t, n, i) : i?.type === "text" ? i.position.start + Math.min(t, i.content.length) : r.endPos;
1766
+ }
1677
1767
  let i = e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement;
1678
1768
  for (; i && i.parentElement !== n;) i = i.parentElement;
1679
1769
  if (!i) return r.endPos;
1680
1770
  let a = Array.from(n.children).indexOf(i);
1681
1771
  if (a < 0) return r.endPos;
1682
- let o = a - 1;
1683
- if (o < 0) return r.startPos;
1684
- if (o >= r.tokens.length) return r.endPos;
1685
- let s = r.tokens[o];
1686
- return s.type === "text" ? s.position.start + Math.min(t, s.content.length) : Ye(e, t, i, s);
1687
- }
1688
- function Ye(e, t, n, r) {
1772
+ let o = n.hasAttribute("data-testid");
1773
+ if (!o && r.tokens.length === 1 && r.tokens[0].type === "mark") return Y(e, t, n, r.tokens[0]);
1774
+ let s = a - (o ? 1 : 0);
1775
+ if (s < 0) return r.startPos;
1776
+ if (s >= r.tokens.length) return r.endPos;
1777
+ let c = r.tokens[s];
1778
+ return c.type === "text" ? c.position.start + Math.min(t, c.content.length) : Y(e, t, i, c);
1779
+ }
1780
+ function Y(e, t, n, r) {
1689
1781
  if (!r.children || r.children.length === 0) {
1690
1782
  if (t === 0) return r.position.start;
1691
- let e = r.nested?.content.length ?? r.value.length;
1692
- return e > 0 && t >= e ? r.content.endsWith("\n\n") && r.nested ? r.nested.end : r.position.end : (r.nested?.start ?? r.position.start) + Math.min(t, e);
1783
+ let e = r.slot?.content.length ?? r.value.length;
1784
+ return e > 0 && t >= e ? r.content.endsWith("\n\n") && r.slot ? r.slot.end : r.position.end : (r.slot?.start ?? r.position.start) + Math.min(t, e);
1693
1785
  }
1694
1786
  let i = 0;
1695
1787
  for (let a of Array.from(n.childNodes)) {
1696
1788
  if (i >= r.children.length) break;
1697
1789
  let n = r.children[i];
1698
- if (a.nodeType === Node.TEXT_NODE && n.type === "text") {
1790
+ if (a.nodeType === Node.ELEMENT_NODE && n.type === "text") {
1791
+ if (!Ze(a)) continue;
1792
+ if (e === a) {
1793
+ let e = t === 0 ? 0 : n.content.length;
1794
+ return n.position.start + Math.min(e, n.content.length);
1795
+ }
1796
+ if (a.contains(e)) return n.position.start + Math.min(t, n.content.length);
1797
+ i++;
1798
+ } else if (a.nodeType === Node.TEXT_NODE && n.type === "text") {
1699
1799
  if (e === a) return n.position.start + Math.min(t, n.content.length);
1700
1800
  i++;
1701
1801
  } else if (a.nodeType === Node.ELEMENT_NODE && n.type === "mark") {
1702
- if (a === e || a.contains(e)) return Ye(e, t, a, n);
1802
+ if (a === e || a.contains(e)) return Y(e, t, a, n);
1703
1803
  i++;
1704
1804
  }
1705
1805
  }
1706
- return r.nested?.end ?? r.position.end;
1806
+ return r.slot?.end ?? r.position.end;
1707
1807
  }
1708
1808
  //#endregion
1709
- //#region ../../common/core/src/features/FeatureManager.ts
1710
- var Xe = class {
1809
+ //#region ../../common/core/src/features/feature-manager/FeatureManager.ts
1810
+ var $e = class {
1711
1811
  #e = [];
1712
1812
  #t = !1;
1713
1813
  register(e) {
@@ -1719,21 +1819,21 @@ var Xe = class {
1719
1819
  disableAll() {
1720
1820
  this.#t && (this.#t = !1, this.#e.forEach((e) => e.disable()));
1721
1821
  }
1722
- }, Y = (e, t) => ({
1822
+ }, X = (e, t) => ({
1723
1823
  name: e,
1724
1824
  enable: () => t.enable(),
1725
1825
  disable: () => t.disable()
1726
- }), Ze = (e) => {
1727
- let t = new Xe();
1728
- return t.register(Y("keydown", e.controllers.keydown)).register(Y("system", e.controllers.system)).register(Y("focus", e.controllers.focus)).register(Y("textSelection", e.controllers.textSelection)).register(Y("contentEditable", e.controllers.contentEditable)), t;
1729
- }, Qe = class {
1826
+ }), et = (e) => {
1827
+ let t = new $e();
1828
+ return t.register(X("keydown", e.controllers.keydown)).register(X("system", e.controllers.system)).register(X("focus", e.controllers.focus)).register(X("textSelection", e.controllers.textSelection)).register(X("contentEditable", e.controllers.contentEditable)), t;
1829
+ }, tt = class {
1730
1830
  #e = [];
1731
1831
  #t = !1;
1732
1832
  constructor(e) {
1733
1833
  this.store = e;
1734
1834
  }
1735
1835
  enable(e) {
1736
- let { store: t } = this, n = Ze(t);
1836
+ let { store: t } = this, n = et(t);
1737
1837
  n.enableAll(), this.#e.push(() => n.disableAll()), this.#n(), e?.getTrigger && this.#r(e.getTrigger);
1738
1838
  }
1739
1839
  disable() {
@@ -1742,12 +1842,12 @@ var Xe = class {
1742
1842
  }
1743
1843
  syncParser(e, t) {
1744
1844
  let { store: n } = this, r = t?.map((e) => e.markup);
1745
- if (r && r.some(Boolean) ? n.state.parser.set(new se(r)) : n.state.parser.set(void 0), this.#t) {
1845
+ if (r && r.some(Boolean) ? n.state.parser.set(new B(r)) : n.state.parser.set(void 0), this.#t) {
1746
1846
  n.state.recovery.get() || n.events.parse();
1747
1847
  return;
1748
1848
  }
1749
1849
  let i = e ?? n.state.defaultValue.get() ?? "";
1750
- n.state.tokens.set(R(n, i)), this.#t = !0;
1850
+ n.state.tokens.set(H(n, i)), this.#t = !0;
1751
1851
  }
1752
1852
  recoverFocus() {
1753
1853
  this.store.controllers.contentEditable.sync(), this.store.state.Mark.get() && this.store.controllers.focus.recover();
@@ -1756,11 +1856,11 @@ var Xe = class {
1756
1856
  let { store: e } = this;
1757
1857
  this.#e.push(e.events.parse.on(() => {
1758
1858
  if (e.state.recovery.get()) {
1759
- let t = F(e.state.tokens.get());
1760
- e.state.tokens.set(R(e, t)), e.state.previousValue.set(t);
1859
+ let t = z(e.state.tokens.get());
1860
+ e.state.tokens.set(H(e, t)), e.state.previousValue.set(t);
1761
1861
  return;
1762
1862
  }
1763
- e.state.tokens.set(e.nodes.focus.target ? de(e) : fe(e));
1863
+ e.state.tokens.set(e.nodes.focus.target ? ce(e) : le(e));
1764
1864
  }));
1765
1865
  }
1766
1866
  #r(e) {
@@ -1772,13 +1872,13 @@ var Xe = class {
1772
1872
  };
1773
1873
  //#endregion
1774
1874
  //#region ../../common/core/src/features/overlay/filterSuggestions.ts
1775
- function $e(e, t) {
1875
+ function nt(e, t) {
1776
1876
  let n = t.toLowerCase();
1777
1877
  return e.filter((e) => e.toLowerCase().includes(n));
1778
1878
  }
1779
1879
  //#endregion
1780
1880
  //#region ../../common/core/src/features/overlay/createMarkFromOverlay.ts
1781
- function et(e, t, n) {
1881
+ function rt(e, t, n) {
1782
1882
  let r = e.option.markup;
1783
1883
  if (!r) throw Error("createMarkFromOverlay: option.markup is required");
1784
1884
  return {
@@ -1795,17 +1895,17 @@ function et(e, t, n) {
1795
1895
  index: 0,
1796
1896
  segments: [],
1797
1897
  gapTypes: [],
1798
- hasNested: !1,
1898
+ hasSlot: !1,
1799
1899
  hasTwoValues: !1,
1800
1900
  segmentGlobalIndices: []
1801
1901
  },
1802
1902
  children: [],
1803
- nested: void 0
1903
+ slot: void 0
1804
1904
  };
1805
1905
  }
1806
1906
  //#endregion
1807
1907
  //#region ../../common/core/src/features/overlay/OverlayController.ts
1808
- var tt = class {
1908
+ var it = class {
1809
1909
  #e;
1810
1910
  #t;
1811
1911
  #n;
@@ -1822,7 +1922,7 @@ var tt = class {
1822
1922
  this.#e = this.store.events.clearOverlay.on(() => {
1823
1923
  t(void 0);
1824
1924
  }), this.#t = this.store.events.checkOverlay.on(() => {
1825
- t(xe.find(this.store.state.options.get(), e));
1925
+ t(be.find(this.store.state.options.get(), e));
1826
1926
  }), this.#n = this.store.events.change.on(() => {
1827
1927
  let e = this.store.state.showOverlayOn.get(), t = "change";
1828
1928
  (e === t || Array.isArray(e) && e.includes(t)) && this.store.events.checkOverlay();
@@ -1855,7 +1955,7 @@ var tt = class {
1855
1955
  };
1856
1956
  //#endregion
1857
1957
  //#region ../../common/core/src/features/overlay/suggestionNavigation.ts
1858
- function nt(e, t, n) {
1958
+ function at(e, t, n) {
1859
1959
  if (n === 0) return {
1860
1960
  action: "none",
1861
1961
  index: t
@@ -1885,29 +1985,29 @@ function nt(e, t, n) {
1885
1985
  }
1886
1986
  //#endregion
1887
1987
  //#region ../../common/core/src/features/store/Store.ts
1888
- var rt = class {
1889
- key = new ye();
1988
+ var ot = class {
1989
+ key = new ve();
1890
1990
  nodes = {
1891
- focus: new Se(void 0, this),
1892
- input: new Se(void 0, this)
1991
+ focus: new xe(void 0, this),
1992
+ input: new xe(void 0, this)
1893
1993
  };
1894
1994
  state;
1895
- events = ve();
1995
+ events = _e();
1896
1996
  refs = {
1897
1997
  container: null,
1898
1998
  overlay: null
1899
1999
  };
1900
2000
  controllers = {
1901
- overlay: new tt(this),
1902
- focus: new Ee(this),
1903
- keydown: new Ve(this),
1904
- system: new Te(this),
1905
- textSelection: new ze(this),
1906
- contentEditable: new we(this)
2001
+ overlay: new it(this),
2002
+ focus: new Re(this),
2003
+ keydown: new We(this),
2004
+ system: new Le(this),
2005
+ textSelection: new Ue(this),
2006
+ contentEditable: new Ie(this)
1907
2007
  };
1908
- lifecycle = new Qe(this);
2008
+ lifecycle = new tt(this);
1909
2009
  constructor(e) {
1910
- this.state = ge({
2010
+ this.state = he({
1911
2011
  tokens: [],
1912
2012
  parser: void 0,
1913
2013
  previousValue: void 0,
@@ -1920,6 +2020,7 @@ var rt = class {
1920
2020
  readOnly: !1,
1921
2021
  options: void 0,
1922
2022
  showOverlayOn: void 0,
2023
+ Span: void 0,
1923
2024
  Mark: void 0,
1924
2025
  Overlay: void 0,
1925
2026
  className: void 0,
@@ -1932,7 +2033,7 @@ var rt = class {
1932
2033
  applyValue(e) {
1933
2034
  let t = this.state.onChange.get();
1934
2035
  if (!t) return;
1935
- let n = R(this, e);
2036
+ let n = H(this, e);
1936
2037
  this.state.tokens.set(n), this.state.previousValue.set(e), t(e);
1937
2038
  }
1938
2039
  createHandler() {
@@ -1949,7 +2050,7 @@ var rt = class {
1949
2050
  }
1950
2051
  };
1951
2052
  }
1952
- }, it = class {
2053
+ }, st = class {
1953
2054
  ref;
1954
2055
  #e;
1955
2056
  #t;
@@ -1981,14 +2082,17 @@ var rt = class {
1981
2082
  set meta(e) {
1982
2083
  this.#t.meta = e, this.#r();
1983
2084
  }
2085
+ get slot() {
2086
+ return this.#t.slot?.content;
2087
+ }
1984
2088
  get depth() {
1985
- return I(this.#e.state.tokens.get(), this.#t).depth;
2089
+ return V(this.#e.state.tokens.get(), this.#t).depth;
1986
2090
  }
1987
2091
  get hasChildren() {
1988
- return this.#t.children.length > 0;
2092
+ return this.#t.children.some((e) => e.type === "mark");
1989
2093
  }
1990
2094
  get parent() {
1991
- return I(this.#e.state.tokens.get(), this.#t)?.parent;
2095
+ return V(this.#e.state.tokens.get(), this.#t)?.parent;
1992
2096
  }
1993
2097
  get tokens() {
1994
2098
  return this.#t.children;
@@ -2000,31 +2104,93 @@ var rt = class {
2000
2104
  #r() {
2001
2105
  this.#e.events.change();
2002
2106
  }
2003
- }, at = (e) => () => {
2107
+ }, ct = (e) => () => {
2004
2108
  let [t, n] = u(() => e.get());
2005
2109
  return a(() => e.on(n), [e]), t;
2006
2110
  };
2007
2111
  //#endregion
2008
2112
  //#region src/lib/hooks/useCoreFeatures.ts
2009
- function ot(e, t) {
2113
+ function lt(e, t) {
2010
2114
  o(t, () => e.createHandler(), [e]), a(() => (e.lifecycle.enable({ getTrigger: (e) => e.overlay?.trigger }), () => e.lifecycle.disable()), []);
2011
- let n = e.state.value.use(), r = e.state.Mark.use(), i = e.state.options.use(), s = r ? i : void 0, c = e.state.tokens.use();
2115
+ let n = e.state.value.use(), r = e.state.Mark.use(), i = e.state.options.use(), c = i?.some((e) => e.Mark != null), l = r || c ? i : void 0, u = e.state.tokens.use();
2012
2116
  a(() => {
2013
- e.lifecycle.syncParser(n, s);
2014
- }, [n, s]), a(() => {
2117
+ e.lifecycle.syncParser(n, l);
2118
+ }, [n, l]), s(() => {
2119
+ e.controllers.contentEditable.sync();
2120
+ }, [u]), a(() => {
2015
2121
  e.lifecycle.recoverFocus();
2016
- }, [c]);
2122
+ }, [u]);
2017
2123
  }
2018
2124
  //#endregion
2019
2125
  //#region src/lib/providers/StoreContext.ts
2020
- var st = t(void 0);
2021
- st.displayName = "StoreContext";
2022
- function X() {
2023
- let e = i(st);
2126
+ var ut = t(void 0);
2127
+ ut.displayName = "StoreContext";
2128
+ function Z() {
2129
+ let e = i(ut);
2024
2130
  if (e === void 0) throw Error("Store not found. Make sure to wrap component in StoreContext.");
2025
2131
  return e;
2026
2132
  }
2027
- var Z = {
2133
+ //#endregion
2134
+ //#region src/components/Span.tsx
2135
+ var dt = (e) => /* @__PURE__ */ f("span", {});
2136
+ //#endregion
2137
+ //#region src/lib/hooks/useSlot.ts
2138
+ function ft(e, t, n, r) {
2139
+ let i = Z();
2140
+ if (e === "span") {
2141
+ let e = i.state.slots.use(), t = i.state.slotProps.use();
2142
+ return [y("span", e), b("span", t)];
2143
+ }
2144
+ let a = i.state.Mark.use(), o = i.state.Overlay.use(), s = e === "mark" ? a : o, c = _(e === "mark" ? t?.mark : t?.overlay, n ?? {}), l = (e === "mark" ? t?.Mark : t?.Overlay) || s || r;
2145
+ if (!l) throw Error(`No ${e} component found. Provide either option.${e === "mark" ? "Mark" : "Overlay"}, global ${e === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`);
2146
+ return [l, c];
2147
+ }
2148
+ function pt(e) {
2149
+ let t = Z(), n = t.state.options.use(), r = t.state.Mark.use(), i = t.state.Span.use();
2150
+ if (e.type === "text") return [i ?? dt, { value: e.content }];
2151
+ let a = n?.[e.descriptor.index], o = {
2152
+ value: e.value,
2153
+ meta: e.meta
2154
+ }, s = _(a?.mark, o), c = a?.Mark || r;
2155
+ if (!c) throw Error("No mark component found. Provide either option.Mark or global Mark.");
2156
+ return [c, s];
2157
+ }
2158
+ //#endregion
2159
+ //#region src/lib/providers/TokenContext.ts
2160
+ var mt = t(void 0);
2161
+ mt.displayName = "TokenProvider";
2162
+ function ht() {
2163
+ let e = i(mt);
2164
+ if (e === void 0) throw Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
2165
+ return e;
2166
+ }
2167
+ //#endregion
2168
+ //#region src/components/Token.tsx
2169
+ var Q = n(({ mark: e }) => {
2170
+ let t = Z(), [n, r] = pt(e), i = e.type === "mark" && e.children.length > 0 ? e.children.map((e) => /* @__PURE__ */ f(Q, { mark: e }, t.key.get(e))) : void 0;
2171
+ return /* @__PURE__ */ f(mt, {
2172
+ value: e,
2173
+ children: /* @__PURE__ */ f(n, {
2174
+ ...r,
2175
+ children: i
2176
+ })
2177
+ });
2178
+ });
2179
+ Q.displayName = "Token";
2180
+ //#endregion
2181
+ //#region src/components/Container.tsx
2182
+ var gt = n(() => {
2183
+ let e = Z(), t = e.state.tokens.use(), n = e.state.slots.use(), r = e.state.slotProps.use(), i = e.state.className.use(), a = e.state.style.use(), o = e.key, s = e.refs;
2184
+ return /* @__PURE__ */ f(c(() => y("container", n), [n]), {
2185
+ ref: (e) => s.container = e,
2186
+ ...c(() => b("container", r), [r]),
2187
+ className: i,
2188
+ style: a,
2189
+ children: t.map((e) => /* @__PURE__ */ f(Q, { mark: e }, o.get(e)))
2190
+ });
2191
+ });
2192
+ gt.displayName = "Container";
2193
+ var $ = {
2028
2194
  Container: "_Container_1526r_1",
2029
2195
  Icon: "_Icon_1526r_5",
2030
2196
  IconGrip: "_IconGrip_1526r_16",
@@ -2033,7 +2199,7 @@ var Z = {
2033
2199
  IconTrash: "_IconTrash_1526r_22",
2034
2200
  Suggestions: "_Suggestions_1526r_43",
2035
2201
  suggestionActive: "_suggestionActive_1526r_71"
2036
- }, ct = `${Z.Icon} ${Z.IconGrip}`, lt = n(({ blockIndex: t, children: n, readOnly: i, alwaysShowHandle: a, onReorder: o, onRequestMenu: s }) => {
2202
+ }, _t = `${$.Icon} ${$.IconGrip}`, vt = n(({ blockIndex: t, children: n, readOnly: i, alwaysShowHandle: a, onReorder: o, onRequestMenu: s }) => {
2037
2203
  let [c, d] = u(!1), [m, h] = u(!1), [g, _] = u(null), v = l(null), y = l(null), b = r(() => d(!0), []), x = r(() => d(!1), []), S = r((e) => {
2038
2204
  e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", String(t)), h(!0), v.current && e.dataTransfer.setDragImage(v.current, 0, 0);
2039
2205
  }, [t]), C = r(() => {
@@ -2059,7 +2225,6 @@ var Z = {
2059
2225
  }, [t, s]), O = {
2060
2226
  position: "relative",
2061
2227
  marginLeft: 0,
2062
- paddingLeft: i ? 0 : 32,
2063
2228
  transition: "opacity 0.2s ease",
2064
2229
  opacity: m ? .4 : 1,
2065
2230
  background: "transparent",
@@ -2067,9 +2232,9 @@ var Z = {
2067
2232
  minHeight: "1.2em",
2068
2233
  userSelect: "none",
2069
2234
  outline: "none"
2070
- }, k = {
2235
+ }, ee = {
2071
2236
  position: "absolute",
2072
- left: 4,
2237
+ left: i ? 0 : -24,
2073
2238
  top: 0,
2074
2239
  bottom: 0,
2075
2240
  width: 24,
@@ -2078,7 +2243,7 @@ var Z = {
2078
2243
  opacity: a || c && !m ? 1 : 0,
2079
2244
  transition: a ? void 0 : "opacity 0.15s ease",
2080
2245
  pointerEvents: a || c ? "auto" : "none"
2081
- }, A = {
2246
+ }, k = {
2082
2247
  width: 24,
2083
2248
  height: 24,
2084
2249
  display: "flex",
@@ -2095,9 +2260,9 @@ var Z = {
2095
2260
  lineHeight: 1,
2096
2261
  flexShrink: 0,
2097
2262
  userSelect: "none"
2098
- }, j = {
2263
+ }, A = {
2099
2264
  position: "absolute",
2100
- left: i ? 0 : 32,
2265
+ left: 0,
2101
2266
  right: 0,
2102
2267
  height: 2,
2103
2268
  backgroundColor: "#3b82f6",
@@ -2116,11 +2281,11 @@ var Z = {
2116
2281
  onDrop: E,
2117
2282
  children: [
2118
2283
  g === "before" && /* @__PURE__ */ f("div", { style: {
2119
- ...j,
2284
+ ...A,
2120
2285
  top: -1
2121
2286
  } }),
2122
2287
  !i && /* @__PURE__ */ f("div", {
2123
- style: k,
2288
+ style: ee,
2124
2289
  children: /* @__PURE__ */ f("button", {
2125
2290
  ref: y,
2126
2291
  type: "button",
@@ -2129,83 +2294,41 @@ var Z = {
2129
2294
  onDragEnd: C,
2130
2295
  onClick: D,
2131
2296
  style: {
2132
- ...A,
2297
+ ...k,
2133
2298
  cursor: m ? "grabbing" : "grab"
2134
2299
  },
2135
2300
  "aria-label": "Drag to reorder or click for options",
2136
- children: /* @__PURE__ */ f("span", { className: ct })
2301
+ children: /* @__PURE__ */ f("span", { className: _t })
2137
2302
  })
2138
2303
  }),
2139
2304
  e.count(n) === 0 ? /* @__PURE__ */ f("br", {}) : n,
2140
2305
  g === "after" && /* @__PURE__ */ f("div", { style: {
2141
- ...j,
2306
+ ...A,
2142
2307
  bottom: -1
2143
2308
  } })
2144
2309
  ]
2145
2310
  });
2146
2311
  });
2147
- lt.displayName = "DraggableBlock";
2312
+ vt.displayName = "DragMark";
2148
2313
  //#endregion
2149
- //#region src/lib/providers/TokenContext.ts
2150
- var Q = t(void 0);
2151
- Q.displayName = "TokenProvider";
2152
- function ut() {
2153
- let e = i(Q);
2154
- if (e === void 0) throw Error("Token not found. Make sure to wrap component in TokenContext.Provider.");
2155
- return e;
2156
- }
2157
- //#endregion
2158
- //#region src/lib/hooks/useSlot.ts
2159
- function dt(e, t, n, r) {
2160
- let i = X(), a = i.state.Mark.use(), o = i.state.Overlay.use(), s = e === "mark" ? a : o, c = _(e === "mark" ? t?.mark : t?.overlay, n ?? {}), l = c.slot || s || r;
2161
- if (!l) throw Error(`No ${e} component found. Provide either option.${e}.slot, global ${e === "mark" ? "Mark" : "Overlay"}, or a defaultComponent.`);
2162
- return [l, c];
2163
- }
2164
- //#endregion
2165
- //#region src/components/MarkRenderer.tsx
2166
- function ft() {
2167
- let e = ut(), t = X(), n = t.state.options.use(), r = t.key, i = n?.[e.descriptor.index], a = e.children.map((e) => /* @__PURE__ */ f($, {
2168
- mark: e,
2169
- isNested: !0
2170
- }, r.get(e))), [o, s] = dt("mark", i, {
2171
- value: e.value,
2172
- meta: e.meta,
2173
- nested: e.nested?.content,
2174
- children: e.children.length > 0 ? a : void 0
2175
- });
2176
- return /* @__PURE__ */ f(o, { ...s });
2177
- }
2178
- //#endregion
2179
- //#region src/components/TextSpan.tsx
2180
- var pt = () => {
2181
- let e = ut(), t = X(), n = l(null), r = t.state.slots.use(), i = t.state.slotProps.use(), a = c(() => y("span", r), [r]), o = c(() => b("span", i), [i]);
2182
- if (e.type !== "text") throw Error("TextSpan component expects a TextToken");
2183
- return s(() => {
2184
- n.current && n.current.textContent !== e.content && (n.current.textContent = e.content);
2185
- }, [e.content]), /* @__PURE__ */ f(a, {
2186
- ...o,
2187
- ref: n
2188
- });
2189
- }, $ = n(({ mark: e, isNested: t = !1 }) => e.type === "mark" ? /* @__PURE__ */ f(Q, {
2190
- value: e,
2191
- children: /* @__PURE__ */ f(ft, {})
2192
- }) : t ? /* @__PURE__ */ f(d, { children: e.content }) : /* @__PURE__ */ f(Q, {
2193
- value: e,
2194
- children: /* @__PURE__ */ f(pt, {})
2195
- }));
2196
- $.displayName = "Token";
2197
- //#endregion
2198
- //#region src/components/BlockContainer.tsx
2199
- var mt = {
2314
+ //#region src/components/DragContainer.tsx
2315
+ var yt = `${$.Icon} ${$.IconGrip}`, bt = {
2200
2316
  id: "block-empty",
2201
2317
  tokens: [],
2202
2318
  startPos: 0,
2203
2319
  endPos: 0
2204
- }, ht = {
2320
+ }, xt = (e) => e.tokens.length === 1 && e.tokens[0].type === "mark";
2321
+ function St(e, t) {
2322
+ if (!t || !(t instanceof Node)) return -1;
2323
+ let n = t;
2324
+ for (; n && n.parentNode !== e;) n = n.parentNode;
2325
+ return n ? Array.from(e.children).indexOf(n) : -1;
2326
+ }
2327
+ var Ct = {
2205
2328
  height: 1,
2206
2329
  background: "rgba(55, 53, 47, 0.09)",
2207
2330
  margin: "4px 0"
2208
- }, gt = n(({ position: e, onAdd: t, onDelete: n, onDuplicate: r, onClose: i }) => {
2331
+ }, wt = n(({ position: e, onAdd: t, onDelete: n, onDuplicate: r, onClose: i }) => {
2209
2332
  let o = l(null), [s, c] = u(null), d = l(i);
2210
2333
  d.current = i, a(() => {
2211
2334
  let e = (e) => {
@@ -2253,7 +2376,7 @@ var mt = {
2253
2376
  onMouseDown: (e) => {
2254
2377
  e.preventDefault(), t(), i();
2255
2378
  },
2256
- children: [/* @__PURE__ */ f("span", { className: h(Z.Icon, Z.IconAdd) }), /* @__PURE__ */ f("span", { children: "Add below" })]
2379
+ children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconAdd) }), /* @__PURE__ */ f("span", { children: "Add below" })]
2257
2380
  }),
2258
2381
  /* @__PURE__ */ p("div", {
2259
2382
  style: g("duplicate"),
@@ -2262,9 +2385,9 @@ var mt = {
2262
2385
  onMouseDown: (e) => {
2263
2386
  e.preventDefault(), r(), i();
2264
2387
  },
2265
- children: [/* @__PURE__ */ f("span", { className: h(Z.Icon, Z.IconDuplicate) }), /* @__PURE__ */ f("span", { children: "Duplicate" })]
2388
+ children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconDuplicate) }), /* @__PURE__ */ f("span", { children: "Duplicate" })]
2266
2389
  }),
2267
- /* @__PURE__ */ f("div", { style: ht }),
2390
+ /* @__PURE__ */ f("div", { style: Ct }),
2268
2391
  /* @__PURE__ */ p("div", {
2269
2392
  style: g("delete"),
2270
2393
  onMouseEnter: () => c("delete"),
@@ -2272,108 +2395,188 @@ var mt = {
2272
2395
  onMouseDown: (e) => {
2273
2396
  e.preventDefault(), n(), i();
2274
2397
  },
2275
- children: [/* @__PURE__ */ f("span", { className: h(Z.Icon, Z.IconTrash) }), /* @__PURE__ */ f("span", { children: "Delete" })]
2398
+ children: [/* @__PURE__ */ f("span", { className: h($.Icon, $.IconTrash) }), /* @__PURE__ */ f("span", { children: "Delete" })]
2276
2399
  })
2277
2400
  ]
2278
2401
  });
2279
2402
  });
2280
- gt.displayName = "BlockMenu";
2281
- var _t = n(() => {
2282
- let e = X(), t = e.state.tokens.use(), n = e.state.slots.use(), i = e.state.slotProps.use(), a = e.state.className.use(), o = e.state.style.use(), s = e.state.readOnly.use(), m = De(e.state.drag.use()), h = e.state.value.use(), g = e.state.onChange.use(), _ = e.key, v = e.refs, [x, S] = u(null), C = c(() => y("container", n), [n]), w = c(() => b("container", i), [i]), T = c(() => {
2403
+ wt.displayName = "BlockMenu";
2404
+ var Tt = n(() => {
2405
+ let e = Z(), t = e.state.tokens.use(), n = e.state.slots.use(), i = e.state.slotProps.use(), a = e.state.className.use(), o = e.state.style.use(), s = e.state.readOnly.use(), m = we(e.state.drag.use()), h = e.key, g = e.refs, [_, v] = u(null), [x, S] = u(null), [C, w] = u(null), [T, E] = u(null), D = l(null), O = l(null), ee = c(() => y("container", n), [n]), k = c(() => b("container", i), [i]), A = c(() => {
2283
2406
  let e = G(t);
2284
- return e.length > 0 ? e : [mt];
2285
- }, [t]), E = l(T);
2286
- E.current = T;
2287
- let D = r((t, n) => {
2288
- if (h == null || !g) return;
2289
- let r = Ne(h, E.current, t, n);
2290
- r !== h && e.applyValue(r);
2291
- }, [
2292
- e,
2293
- h,
2294
- g
2295
- ]), O = r((t) => {
2296
- h == null || !g || (e.applyValue(ke(h, E.current, t)), queueMicrotask(() => {
2407
+ return e.length > 0 ? e : [bt];
2408
+ }, [t]), j = l(A);
2409
+ j.current = A;
2410
+ let M = r((t, n) => {
2411
+ let r = e.state.value.get();
2412
+ if (r == null || !e.state.onChange.get()) return;
2413
+ let i = Pe(r, j.current, t, n);
2414
+ i !== r && e.applyValue(i);
2415
+ }, [e]), te = r((t) => {
2416
+ let n = e.state.value.get();
2417
+ n == null || !e.state.onChange.get() || (e.applyValue(ke(n, j.current, t)), queueMicrotask(() => {
2297
2418
  let n = e.refs.container;
2298
2419
  if (!n) return;
2299
2420
  let r = t + 1;
2300
2421
  n.children[r]?.focus();
2301
2422
  }));
2302
- }, [
2303
- e,
2304
- h,
2305
- g
2306
- ]), k = r((t) => {
2307
- h == null || !g || e.applyValue(Ae(h, E.current, t));
2308
- }, [
2309
- e,
2310
- h,
2311
- g
2312
- ]), A = r((t) => {
2313
- h == null || !g || e.applyValue(je(h, E.current, t));
2314
- }, [
2315
- e,
2316
- h,
2317
- g
2318
- ]), j = r((e, t) => {
2319
- S({
2423
+ }, [e]), ne = r((t) => {
2424
+ let n = e.state.value.get();
2425
+ n == null || !e.state.onChange.get() || e.applyValue(Ae(n, j.current, t));
2426
+ }, [e]), re = r((t) => {
2427
+ let n = e.state.value.get();
2428
+ n == null || !e.state.onChange.get() || e.applyValue(je(n, j.current, t));
2429
+ }, [e]), N = r((e, t) => {
2430
+ v({
2320
2431
  index: e,
2321
2432
  position: {
2322
2433
  top: t.bottom + 4,
2323
2434
  left: t.left
2324
2435
  }
2325
2436
  });
2326
- }, []), M = r(() => S(null), []);
2327
- return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f(C, {
2328
- ref: (e) => v.container = e,
2329
- ...w,
2330
- className: a,
2331
- style: o,
2332
- children: T.map((e, t) => /* @__PURE__ */ f(lt, {
2333
- blockIndex: t,
2334
- readOnly: s,
2335
- alwaysShowHandle: m,
2336
- onReorder: D,
2337
- onRequestMenu: j,
2338
- children: e.tokens.map((e) => /* @__PURE__ */ f($, { mark: e }, _.get(e)))
2339
- }, e.id))
2340
- }), x && /* @__PURE__ */ f(gt, {
2341
- position: x.position,
2342
- onAdd: () => {
2343
- O(x.index), M();
2344
- },
2345
- onDelete: () => {
2346
- k(x.index), M();
2347
- },
2348
- onDuplicate: () => {
2349
- A(x.index), M();
2350
- },
2351
- onClose: M
2352
- })] });
2353
- });
2354
- _t.displayName = "BlockContainer";
2355
- //#endregion
2356
- //#region src/components/Container.tsx
2357
- var vt = n(() => {
2358
- let e = X(), t = e.state.tokens.use(), n = e.state.slots.use(), r = e.state.slotProps.use(), i = e.state.className.use(), a = e.state.style.use(), o = e.key, s = e.refs;
2359
- return /* @__PURE__ */ f(c(() => y("container", n), [n]), {
2360
- ref: (e) => s.container = e,
2361
- ...c(() => b("container", r), [r]),
2362
- className: i,
2363
- style: a,
2364
- children: t.map((e) => /* @__PURE__ */ f($, { mark: e }, o.get(e)))
2365
- });
2437
+ }, []), P = r(() => v(null), []), F = r(() => {
2438
+ O.current && clearTimeout(O.current), O.current = setTimeout(() => S(null), 120);
2439
+ }, []), I = r(() => {
2440
+ O.current && clearTimeout(O.current);
2441
+ }, []), ie = r((e) => {
2442
+ let t = g.container;
2443
+ if (!t) return;
2444
+ let n = St(t, e.target);
2445
+ if (n === -1 || !xt(j.current[n])) {
2446
+ F();
2447
+ return;
2448
+ }
2449
+ I(), S(n);
2450
+ }, [
2451
+ g,
2452
+ F,
2453
+ I
2454
+ ]), L = r(() => F(), [F]), R = r((e) => {
2455
+ let t = g.container;
2456
+ if (!t) return;
2457
+ let n = St(t, e.target);
2458
+ if (n === -1 || !xt(j.current[n])) return;
2459
+ e.preventDefault();
2460
+ let r = t.children[n].getBoundingClientRect(), i = r.left + r.width / 2;
2461
+ E({
2462
+ index: n,
2463
+ position: e.clientX < i ? "before" : "after"
2464
+ });
2465
+ }, [g]), z = r((e) => {
2466
+ g.container && (g.container.contains(e.relatedTarget) || E(null));
2467
+ }, [g]), B = r((e) => {
2468
+ if (!T) return;
2469
+ e.preventDefault();
2470
+ let t = parseInt(e.dataTransfer.getData("text/plain"), 10);
2471
+ if (isNaN(t)) return;
2472
+ let n = T.position === "before" ? T.index : T.index + 1;
2473
+ E(null), M(t, n);
2474
+ }, [T, M]), ae = r((e) => {
2475
+ if (x === null || !g.container) return;
2476
+ e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", String(x)), w(x);
2477
+ let t = g.container.children[x];
2478
+ t && e.dataTransfer.setDragImage(t, 0, 0);
2479
+ }, [x, g]), V = r(() => {
2480
+ w(null), E(null);
2481
+ }, []);
2482
+ return /* @__PURE__ */ p(d, { children: [
2483
+ /* @__PURE__ */ f(ee, {
2484
+ ref: (e) => g.container = e,
2485
+ ...k,
2486
+ className: a,
2487
+ style: s ? o : {
2488
+ paddingLeft: 24,
2489
+ ...o
2490
+ },
2491
+ onMouseOver: ie,
2492
+ onMouseLeave: L,
2493
+ onDragOver: R,
2494
+ onDragLeave: z,
2495
+ onDrop: B,
2496
+ children: A.map((e, t) => xt(e) ? /* @__PURE__ */ f(Q, { mark: e.tokens[0] }, h.get(e.tokens[0])) : /* @__PURE__ */ f(vt, {
2497
+ blockIndex: t,
2498
+ readOnly: s,
2499
+ alwaysShowHandle: m,
2500
+ onReorder: M,
2501
+ onRequestMenu: N,
2502
+ children: e.tokens.map((e) => /* @__PURE__ */ f(Q, { mark: e }, h.get(e)))
2503
+ }, e.id))
2504
+ }),
2505
+ x !== null && !s && (() => {
2506
+ let e = (g.container?.children[x])?.getBoundingClientRect();
2507
+ return e ? /* @__PURE__ */ f("button", {
2508
+ ref: D,
2509
+ type: "button",
2510
+ draggable: !0,
2511
+ onDragStart: ae,
2512
+ onDragEnd: V,
2513
+ onMouseEnter: I,
2514
+ onMouseLeave: F,
2515
+ onClick: (e) => {
2516
+ e.preventDefault(), D.current && N(x, D.current.getBoundingClientRect());
2517
+ },
2518
+ style: {
2519
+ position: "fixed",
2520
+ top: e.top + e.height / 2 - 12,
2521
+ left: e.left - 24,
2522
+ width: 24,
2523
+ height: 24,
2524
+ display: "flex",
2525
+ alignItems: "center",
2526
+ justifyContent: "center",
2527
+ cursor: C === null ? "grab" : "grabbing",
2528
+ borderRadius: 4,
2529
+ color: "#9ca3af",
2530
+ background: "none",
2531
+ border: "none",
2532
+ padding: 0,
2533
+ zIndex: 100,
2534
+ pointerEvents: "auto",
2535
+ userSelect: "none"
2536
+ },
2537
+ "aria-label": "Drag to reorder or click for options",
2538
+ children: /* @__PURE__ */ f("span", { className: yt })
2539
+ }) : null;
2540
+ })(),
2541
+ T !== null && (() => {
2542
+ let e = (g.container?.children[T.index])?.getBoundingClientRect();
2543
+ return e ? /* @__PURE__ */ f("div", { style: {
2544
+ position: "fixed",
2545
+ left: T.position === "before" ? e.left - 1 : e.right - 1,
2546
+ top: e.top,
2547
+ width: 2,
2548
+ height: e.height,
2549
+ backgroundColor: "#3b82f6",
2550
+ borderRadius: 1,
2551
+ pointerEvents: "none",
2552
+ zIndex: 10
2553
+ } }) : null;
2554
+ })(),
2555
+ _ && /* @__PURE__ */ f(wt, {
2556
+ position: _.position,
2557
+ onAdd: () => {
2558
+ te(_.index), P();
2559
+ },
2560
+ onDelete: () => {
2561
+ ne(_.index), P();
2562
+ },
2563
+ onDuplicate: () => {
2564
+ re(_.index), P();
2565
+ },
2566
+ onClose: P
2567
+ })
2568
+ ] });
2366
2569
  });
2367
- vt.displayName = "Container";
2570
+ Tt.displayName = "DragContainer";
2368
2571
  //#endregion
2369
2572
  //#region src/lib/hooks/useOverlay.tsx
2370
- function yt() {
2371
- let e = X(), t = e.state.overlayMatch.use(), n = B.getAbsolutePosition(), i = r(() => e.events.clearOverlay(), []);
2573
+ function Et() {
2574
+ let e = Z(), t = e.state.overlayMatch.use(), n = U.getAbsolutePosition(), i = r(() => e.events.clearOverlay(), []);
2372
2575
  return {
2373
2576
  match: t,
2374
2577
  style: n,
2375
2578
  select: r((n) => {
2376
- let r = et(t, n.value, n.meta);
2579
+ let r = rt(t, n.value, n.meta);
2377
2580
  e.events.select({
2378
2581
  mark: r,
2379
2582
  match: t
@@ -2392,15 +2595,15 @@ function yt() {
2392
2595
  }
2393
2596
  //#endregion
2394
2597
  //#region src/components/Suggestions/Suggestions.tsx
2395
- var bt = () => {
2396
- let e = X(), { match: t, select: n, style: r, ref: i } = yt(), [o, s] = u(NaN), d = t.option.overlay?.data || [], p = c(() => $e(d, t.value), [t.value, d]), m = p.length, h = l(o);
2598
+ var Dt = () => {
2599
+ let e = Z(), { match: t, select: n, style: r, ref: i } = Et(), [o, s] = u(NaN), d = t.option.overlay?.data || [], p = c(() => nt(d, t.value), [t.value, d]), m = p.length, h = l(o);
2397
2600
  h.current = o;
2398
2601
  let g = l(p);
2399
2602
  return g.current = p, a(() => {
2400
2603
  let t = e.refs.container;
2401
2604
  if (!t) return;
2402
2605
  let r = (e) => {
2403
- let t = nt(e.key, h.current, m);
2606
+ let t = at(e.key, h.current, m);
2404
2607
  switch (t.action) {
2405
2608
  case "up":
2406
2609
  case "down":
@@ -2420,10 +2623,10 @@ var bt = () => {
2420
2623
  return t.addEventListener("keydown", r), () => t.removeEventListener("keydown", r);
2421
2624
  }, [m, n]), p.length ? /* @__PURE__ */ f("ul", {
2422
2625
  ref: i,
2423
- className: Z.Suggestions,
2626
+ className: $.Suggestions,
2424
2627
  style: r,
2425
2628
  children: p.map((e, t) => {
2426
- let r = t === o ? Z.suggestionActive : void 0;
2629
+ let r = t === o ? $.suggestionActive : void 0;
2427
2630
  return /* @__PURE__ */ f("li", {
2428
2631
  ref: (e) => {
2429
2632
  r && e && e.scrollIntoView(!1);
@@ -2437,54 +2640,53 @@ var bt = () => {
2437
2640
  }, e);
2438
2641
  })
2439
2642
  }) : null;
2440
- }, xt = n(() => {
2441
- let e = X(), t = e.state.overlayMatch.use(), n = c(() => t ? e.key.get(t.option) : void 0, [t]), [r, i] = dt("overlay", t?.option, void 0, bt);
2643
+ }, Ot = n(() => {
2644
+ let e = Z(), t = e.state.overlayMatch.use(), n = c(() => t ? e.key.get(t.option) : void 0, [t]), [r, i] = ft("overlay", t?.option, void 0, Dt);
2442
2645
  if (n) return /* @__PURE__ */ f(r, { ...i ?? {} }, n);
2443
2646
  });
2444
- xt.displayName = "OverlayRenderer";
2647
+ Ot.displayName = "OverlayRenderer";
2445
2648
  //#endregion
2446
2649
  //#region src/components/MarkedInput.tsx
2447
- function St(e) {
2448
- let { ref: t, value: n, defaultValue: r, onChange: i, readOnly: a = !1, drag: o = !1, Mark: s, Overlay: c, slots: l, slotProps: d, options: m = S, showOverlayOn: _ = "change", className: v, style: y } = e, b = h(Z.Container, v, d?.container?.className), x = g(y, d?.container?.style), [C] = u(() => new rt({ createUseHook: at }));
2449
- return C.state.set({
2650
+ function kt(e) {
2651
+ let { ref: t, value: n, defaultValue: r, onChange: i, readOnly: a = !1, drag: o = !1, Span: s, Mark: c, Overlay: l, slots: d, slotProps: m, options: _ = S, showOverlayOn: v = "change", className: y, style: b } = e, x = h($.Container, y, m?.container?.className), C = g(b, m?.container?.style), [w] = u(() => new ot({ createUseHook: ct }));
2652
+ return w.state.set({
2450
2653
  value: n,
2451
2654
  defaultValue: r,
2452
2655
  onChange: i,
2453
2656
  readOnly: a,
2454
2657
  drag: o,
2455
- options: m,
2456
- showOverlayOn: _,
2457
- Mark: s,
2458
- Overlay: c,
2459
- className: b,
2460
- style: x,
2461
- slots: l,
2462
- slotProps: d
2463
- }), ot(C, t), /* @__PURE__ */ p(st, {
2464
- value: C,
2465
- children: [/* @__PURE__ */ f(o ? _t : vt, {}), /* @__PURE__ */ f(xt, {})]
2658
+ options: _,
2659
+ showOverlayOn: v,
2660
+ Span: s,
2661
+ Mark: c,
2662
+ Overlay: l,
2663
+ className: x,
2664
+ style: C,
2665
+ slots: d,
2666
+ slotProps: m
2667
+ }), lt(w, t), /* @__PURE__ */ p(ut, {
2668
+ value: w,
2669
+ children: [/* @__PURE__ */ f(o ? Tt : gt, {}), /* @__PURE__ */ f(Ot, {})]
2466
2670
  });
2467
2671
  }
2468
2672
  //#endregion
2469
2673
  //#region src/lib/hooks/useMark.tsx
2470
- var Ct = (e = {}) => {
2471
- let t = X(), n = ut(), r = l(null);
2472
- if (n.type !== "mark") throw Error("useMark can only be used with mark tokens");
2473
- let [i] = u(() => new it({
2674
+ var At = (e = {}) => {
2675
+ let t = Z(), n = ht(), r = l(null), [i] = u(() => new st({
2474
2676
  ref: r,
2475
2677
  store: t,
2476
2678
  token: n
2477
2679
  }));
2478
- wt(r, e, n);
2680
+ jt(r, e, n);
2479
2681
  let o = t.state.readOnly.use();
2480
2682
  return a(() => {
2481
2683
  i.readOnly = o;
2482
2684
  }, [o]), i;
2483
2685
  };
2484
- function wt(e, t, n) {
2686
+ function jt(e, t, n) {
2485
2687
  a(() => {
2486
2688
  e.current && !t.controlled && (e.current.textContent = n.content);
2487
2689
  }, []);
2488
2690
  }
2489
2691
  //#endregion
2490
- export { it as MarkHandler, St as MarkedInput, P as annotate, ce as denote, Ct as useMark, yt as useOverlay };
2692
+ export { st as MarkHandler, kt as MarkedInput, dt as Span, R as annotate, ae as denote, At as useMark, Et as useOverlay };