@code0-tech/pictor 0.14.0 → 0.16.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.
@@ -1,19 +1,19 @@
1
- import { jsxs as j, jsx as p } from "react/jsx-runtime";
2
- import l, { useRef as k, useState as q, useMemo as D, useEffect as T, useLayoutEffect as _e } from "react";
1
+ import { jsxs as q, jsx as g } from "react/jsx-runtime";
2
+ import i, { useRef as b, useState as W, useMemo as D, useEffect as P, useLayoutEffect as ot } from "react";
3
3
  import "../../utils/contextStore.js";
4
4
  import { mergeComponentProps as ue } from "../../utils/component.js";
5
5
  import "js-md5";
6
6
  import '../../assets/components/form/Input.style.css';/* empty css */
7
- import { InputLabel as et } from "./InputLabel.js";
8
- import { InputDescription as tt } from "./InputDescription.js";
9
- import { InputMessage as nt } from "./InputMessage.js";
10
- import { Menu as rt, MenuTrigger as ot, MenuPortal as st } from "../menu/Menu.js";
11
- import { InputSuggestionMenuContent as at, InputSuggestionMenuContentItems as ut } from "./InputSuggestion.js";
12
- import { buildDefaultSyntax as it } from "./Input.syntax.hook.js";
13
- import { getSelectionMetrics as lt, setElementKey as ct, setSelectionRangeSafe as ft } from "./Input.utils.js";
14
- import { Card as dt } from "../card/Card.js";
15
- import { useContentEditableController as pt, setSelectionOffsetsInValue as gt } from "./InputContentEditable.hook.js";
16
- const W = (u) => {
7
+ import { InputLabel as at } from "./InputLabel.js";
8
+ import { InputDescription as st } from "./InputDescription.js";
9
+ import { InputMessage as ut } from "./InputMessage.js";
10
+ import { Menu as it, MenuTrigger as lt, MenuPortal as ct } from "../menu/Menu.js";
11
+ import { InputSuggestionMenuContent as ft, InputSuggestionMenuContentItems as dt } from "./InputSuggestion.js";
12
+ import { buildDefaultSyntax as pt } from "./Input.syntax.hook.js";
13
+ import { getSelectionMetrics as gt, setElementKey as ht, setSelectionRangeSafe as mt } from "./Input.utils.js";
14
+ import { Card as yt } from "../card/Card.js";
15
+ import { useContentEditableController as St, setSelectionOffsetsInValue as Ct } from "./InputContentEditable.hook.js";
16
+ const U = (u) => {
17
17
  const x = u ?? "";
18
18
  return typeof x == "string" ? x : String(x);
19
19
  }, ie = (u) => {
@@ -24,219 +24,227 @@ const W = (u) => {
24
24
  } catch {
25
25
  return String(u ?? "");
26
26
  }
27
- }, ht = (u) => {
27
+ }, bt = (u) => {
28
28
  if (u && typeof u == "object") {
29
29
  const {
30
30
  children: x,
31
31
  __contentHtml: G,
32
- ...U
32
+ ...T
33
33
  } = u;
34
- return U;
34
+ return T;
35
35
  }
36
36
  return {
37
37
  value: u
38
38
  };
39
- }, Ne = (u) => {
39
+ }, We = (u) => {
40
40
  if (!u) return null;
41
- const x = u.value ?? "", G = u.selectionStart ?? x.length, P = x.slice(0, G).match(/\S+$/);
42
- if (!P || P.index === void 0) return null;
43
- const C = P[0], H = P.index, X = H + C.length;
41
+ const x = u.value ?? "", G = u.selectionStart ?? x.length, L = x.slice(0, G).match(/\S+$/);
42
+ if (!L || L.index === void 0) return null;
43
+ const C = L[0], H = L.index, X = H + C.length;
44
44
  return {
45
45
  token: C,
46
46
  start: H,
47
47
  end: X
48
48
  };
49
- }, mt = l.forwardRef((u, x) => {
49
+ }, kt = i.forwardRef((u, x) => {
50
50
  const {
51
51
  wrapperComponent: G = {},
52
- title: U,
53
- description: P,
52
+ title: T,
53
+ description: L,
54
54
  disabled: C = !1,
55
55
  left: H,
56
56
  right: X,
57
- leftType: ze = "icon",
58
- rightType: je = "action",
59
- formValidation: L = {
57
+ leftType: Ue = "icon",
58
+ rightType: He = "action",
59
+ formValidation: M = {
60
60
  valid: !0,
61
61
  notValidMessage: null,
62
62
  setValue: null
63
63
  },
64
- suggestions: f,
65
- suggestionsHeader: be,
66
- suggestionsFooter: ve,
67
- onSuggestionSelect: xe,
68
- disableOnValue: we = () => !1,
64
+ suggestions: d,
65
+ suggestionsHeader: xe,
66
+ suggestionsFooter: we,
67
+ onSuggestionSelect: Ve,
68
+ disableOnValue: Ee = () => !1,
69
69
  transformSyntax: Y,
70
70
  validationUsesSyntax: le = !1,
71
- filterSuggestionsByLastToken: b = !1,
72
- enforceUniqueSuggestions: Ve = !1,
73
- onLastTokenChange: Ee,
74
- suggestionsEmptyState: De,
75
- ...qe
71
+ filterSuggestionsByLastToken: k = !1,
72
+ enforceUniqueSuggestions: De = !1,
73
+ onLastTokenChange: Ie,
74
+ suggestionsEmptyState: Pe,
75
+ ...Je
76
76
  } = u, {
77
- onFocus: Ie,
77
+ onFocus: Te,
78
78
  onBlur: Z,
79
79
  onKeyDown: _,
80
80
  onKeyDownCapture: ce,
81
- onChange: M,
81
+ onChange: F,
82
82
  onInput: R,
83
- ...h
84
- } = qe, ee = k(null), m = k(null), $ = k(null), F = k(null), fe = k(null), w = k(!1), de = k(!1), We = k(0), Te = k(null), pe = h.value ?? u.initialValue ?? u.defaultValue, [Pe, Ue] = q(!1), K = k(!1), i = l.useCallback((e) => {
85
- K.current = e, Ue(e);
86
- }, []), [y, ge] = q(pe), [Le, Me] = q([]), [B, he] = q([]), [Re, He] = q(null), [A, Je] = q(null), s = !!Y, I = D(() => we(y), [we, y]), v = D(() => s ? $ : m, [s]);
87
- l.useImperativeHandle(x, () => v.current ?? null);
88
- const Oe = D(() => ({
89
- ...h
90
- }), [h]), Qe = D(() => {
83
+ ...c
84
+ } = Je, Qe = i.useId(), fe = c.id ?? Qe, Le = `${fe}-label`, Me = T ? void 0 : c["aria-label"] ?? c.placeholder, de = {
85
+ id: fe,
86
+ ...T ? {
87
+ "aria-labelledby": Le
88
+ } : {},
89
+ ...Me ? {
90
+ "aria-label": Me
91
+ } : {}
92
+ }, ee = b(null), m = b(null), O = b(null), K = b(null), pe = b(null), w = b(!1), ge = b(!1), Ge = b(0), Fe = b(null), he = c.value ?? u.initialValue ?? u.defaultValue, [Re, Xe] = W(!1), B = b(!1), l = i.useCallback((e) => {
93
+ B.current = e, Xe(e);
94
+ }, []), [y, me] = W(he), [$e, Oe] = W([]), [A, ye] = W([]), [Ke, Ye] = W(null), [N, Ze] = W(null), a = !!Y, I = D(() => Ee(y), [Ee, y]), v = D(() => a ? O : m, [a]);
95
+ i.useImperativeHandle(x, () => v.current ?? null);
96
+ const Be = D(() => ({
97
+ ...c
98
+ }), [c]), _e = D(() => {
91
99
  const {
92
100
  value: e,
93
101
  defaultValue: t,
94
102
  ...n
95
- } = h;
103
+ } = c;
96
104
  return ue("input__control", n);
97
- }, [h]), te = l.useCallback(() => {
105
+ }, [c]), te = i.useCallback(() => {
98
106
  const e = v.current;
99
107
  !e || C || I || e.focus({
100
108
  preventScroll: !0
101
109
  });
102
- }, [v, C, I]), N = l.useCallback(() => {
103
- f && i(!0);
104
- }, [f, i]), me = l.useCallback((e) => {
105
- b && (He(e), e && i(!0), Ee?.(e));
106
- }, [b, Ee, i]), J = l.useCallback((e, t) => {
107
- if (!L?.setValue) return;
108
- const n = h.type !== "checkbox" ? W(e) : e, o = le ? t : n;
109
- Object.is(Te.current, o) || (Te.current = o, L.setValue(o));
110
- }, [L?.setValue, h.type, le]), ne = l.useCallback((e) => {
111
- const t = e.currentTarget, n = h.type === "checkbox" && "checked" in t ? t.checked : t.value;
112
- ge(n), J(n, null);
113
- }, [h.type, J]), g = pt({
114
- editorRef: $,
110
+ }, [v, C, I]), z = i.useCallback(() => {
111
+ d && l(!0);
112
+ }, [d, l]), Se = i.useCallback((e) => {
113
+ k && (Ye(e), e && l(!0), Ie?.(e));
114
+ }, [k, Ie, l]), J = i.useCallback((e, t) => {
115
+ if (!M?.setValue) return;
116
+ const n = c.type !== "checkbox" ? U(e) : e, o = le ? t : n;
117
+ Object.is(Fe.current, o) || (Fe.current = o, M.setValue(o));
118
+ }, [M?.setValue, c.type, le]), ne = i.useCallback((e) => {
119
+ const t = e.currentTarget, n = c.type === "checkbox" && "checked" in t ? t.checked : t.value;
120
+ me(n), J(n, null);
121
+ }, [c.type, J]), h = St({
122
+ editorRef: O,
115
123
  transformSyntax: Y,
116
- filterSuggestionsByLastToken: b,
117
- onLastTokenChange: me,
124
+ filterSuggestionsByLastToken: k,
125
+ onLastTokenChange: Se,
118
126
  onStateChange: ({
119
127
  value: e,
120
128
  tokens: t,
121
129
  segments: n
122
130
  }) => {
123
- ge(e), he(t), Je(n ?? null), J(e, n ?? null);
131
+ me(e), ye(t), Ze(n ?? null), J(e, n ?? null);
124
132
  }
125
- }), $e = k(!1);
126
- T(() => {
127
- if (!s || !Y || $e.current) return;
128
- const e = W(pe);
129
- g.initializeFromExternalValue(e), $e.current = !0;
130
- }, [s, Y, pe, le, g]), T(() => {
131
- s || h.value !== void 0 && ge(h.value);
132
- }, [h.value, s]), T(() => {
133
- J(y, A);
134
- }, [J, A, y]), T(() => {
135
- if (!f) return;
133
+ }), Ae = b(!1);
134
+ P(() => {
135
+ if (!a || !Y || Ae.current) return;
136
+ const e = U(he);
137
+ h.initializeFromExternalValue(e), Ae.current = !0;
138
+ }, [a, Y, he, le, h]), P(() => {
139
+ a || c.value !== void 0 && me(c.value);
140
+ }, [c.value, a]), P(() => {
141
+ J(y, N);
142
+ }, [J, N, y]), P(() => {
143
+ if (!d) return;
136
144
  const e = (t) => {
137
- const n = t.target, o = !!$.current?.contains(n), a = !!m.current?.contains(n), r = !!fe.current?.contains(n), S = !!ee.current?.contains(n), c = o || a || r || S;
138
- w.current = c, !c && K.current && i(!1);
145
+ const n = t.target, o = !!O.current?.contains(n), s = !!m.current?.contains(n), r = !!pe.current?.contains(n), S = !!ee.current?.contains(n), f = o || s || r || S;
146
+ w.current = f, !f && B.current && l(!1);
139
147
  };
140
148
  return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
141
- }, [f, i]), T(() => {
149
+ }, [d, l]), P(() => {
142
150
  const e = ee.current;
143
151
  if (!e) return;
144
- const t = () => N();
152
+ const t = () => z();
145
153
  return e.addEventListener("focusin", t), () => e.removeEventListener("focusin", t);
146
- }, [N]);
147
- const Fe = l.useCallback((e, t, n) => {
154
+ }, [z]);
155
+ const Ne = i.useCallback((e, t, n) => {
148
156
  if (e.length === 0) return t <= n.length ? t : null;
149
157
  let o = n.indexOf(e);
150
158
  if (o === -1) return null;
151
- let a = o;
152
- for (; a !== -1; )
153
- Math.abs(a - t) < Math.abs(o - t) && (o = a), a = n.indexOf(e, a + 1);
159
+ let s = o;
160
+ for (; s !== -1; )
161
+ Math.abs(s - t) < Math.abs(o - t) && (o = s), s = n.indexOf(e, s + 1);
154
162
  return o;
155
- }, []), re = l.useCallback((e, t) => {
163
+ }, []), re = i.useCallback((e, t) => {
156
164
  const n = [];
157
165
  return e.forEach((o) => {
158
- const a = Fe(o.text, o.start, t);
159
- if (a === null) return;
160
- const r = a + o.text.length;
161
- t.slice(a, r) === o.text && n.push({
166
+ const s = Ne(o.text, o.start, t);
167
+ if (s === null) return;
168
+ const r = s + o.text.length;
169
+ t.slice(s, r) === o.text && n.push({
162
170
  ...o,
163
- start: a,
171
+ start: s,
164
172
  end: r
165
173
  });
166
174
  }), n;
167
- }, [Fe]);
168
- T(() => {
169
- if (s) return;
170
- const e = W(m.current?.value ?? y);
171
- Me((t) => {
175
+ }, [Ne]);
176
+ P(() => {
177
+ if (a) return;
178
+ const e = U(m.current?.value ?? y);
179
+ Oe((t) => {
172
180
  const n = re(t, e);
173
- return he(n.map((o) => o.suggestion)), n;
181
+ return ye(n.map((o) => o.suggestion)), n;
174
182
  });
175
- }, [s, re, y]), T(() => {
176
- if (!b || s) return;
183
+ }, [a, re, y]), P(() => {
184
+ if (!k || a) return;
177
185
  const e = m.current;
178
186
  if (!e) return;
179
- const t = () => me(Ne(e)?.token ?? null);
187
+ const t = () => Se(We(e)?.token ?? null);
180
188
  return e.addEventListener("input", t), e.addEventListener("keyup", t), e.addEventListener("mouseup", t), t(), () => {
181
189
  e.removeEventListener("input", t), e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t);
182
190
  };
183
- }, [b, s, me]);
184
- const z = D(() => {
185
- if (!b || !f) return f;
186
- const e = Re?.trim();
187
- return e?.length ? f.filter((t) => String(t?.value ?? "").toLowerCase().startsWith(e.toLowerCase())) : f;
188
- }, [b, Re, f]), oe = D(() => {
189
- if (!Ve || !z) return z;
190
- if (s) {
191
- const t = new Set((B ?? []).map((n) => ie(n?.value ?? n)));
192
- return z.filter((n) => !t.has(ie(n?.value ?? n)));
191
+ }, [k, a, Se]);
192
+ const j = D(() => {
193
+ if (!k || !d) return d;
194
+ const e = Ke?.trim();
195
+ return e?.length ? d.filter((t) => String(t?.value ?? "").toLowerCase().startsWith(e.toLowerCase())) : d;
196
+ }, [k, Ke, d]), oe = D(() => {
197
+ if (!De || !j) return j;
198
+ if (a) {
199
+ const t = new Set((A ?? []).map((n) => ie(n?.value ?? n)));
200
+ return j.filter((n) => !t.has(ie(n?.value ?? n)));
193
201
  }
194
- const e = new Set(Le.map((t) => t.suggestion));
195
- return z.filter((t) => !e.has(t));
196
- }, [Le, B, Ve, z, s]), Ke = l.useCallback((e) => {
202
+ const e = new Set($e.map((t) => t.suggestion));
203
+ return j.filter((t) => !e.has(t));
204
+ }, [$e, A, De, j, a]), ze = i.useCallback((e) => {
197
205
  if (!m.current) return;
198
- const t = typeof y == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), o = e.insertMode ?? "replace", a = m.current.value ?? "";
199
- let r = a, S = null, c = 0;
200
- const V = b ? Ne(m.current) : null;
201
- if (b && V)
202
- r = `${a.slice(0, V.start)}${n}${a.slice(V.end)}`, S = V.start + n.length, c = V.start;
206
+ const t = typeof y == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), o = e.insertMode ?? "replace", s = m.current.value ?? "";
207
+ let r = s, S = null, f = 0;
208
+ const V = k ? We(m.current) : null;
209
+ if (k && V)
210
+ r = `${s.slice(0, V.start)}${n}${s.slice(V.end)}`, S = V.start + n.length, f = V.start;
203
211
  else
204
212
  switch (o) {
205
213
  case "append":
206
- r = `${a}${n}`, S = r.length, c = a.length;
214
+ r = `${s}${n}`, S = r.length, f = s.length;
207
215
  break;
208
216
  case "prepend":
209
- r = `${n}${a}`, S = n.length, c = 0;
217
+ r = `${n}${s}`, S = n.length, f = 0;
210
218
  break;
211
219
  case "insert": {
212
220
  const {
213
- rawStart: d,
214
- rawEnd: O
215
- } = lt(m.current);
216
- r = `${a.slice(0, d)}${n}${a.slice(O)}`, S = d + n.length, c = d;
221
+ rawStart: p,
222
+ rawEnd: $
223
+ } = gt(m.current);
224
+ r = `${s.slice(0, p)}${n}${s.slice($)}`, S = p + n.length, f = p;
217
225
  break;
218
226
  }
219
227
  default:
220
- r = n, S = n.length, c = 0;
228
+ r = n, S = n.length, f = 0;
221
229
  break;
222
230
  }
223
- ct(m.current, "value", r, "change"), Me((d) => {
224
- const O = W(r), se = re(d, O), E = n.length ? {
225
- id: We.current++,
231
+ ht(m.current, "value", r, "change"), Oe((p) => {
232
+ const $ = U(r), ae = re(p, $), E = n.length ? {
233
+ id: Ge.current++,
226
234
  suggestion: e,
227
235
  text: n,
228
- start: c,
229
- end: c + n.length
230
- } : null, ae = E ? [...se, E] : se;
231
- return he(ae.map((Ze) => Ze.suggestion)), ae;
236
+ start: f,
237
+ end: f + n.length
238
+ } : null, se = E ? [...ae, E] : ae;
239
+ return ye(se.map((rt) => rt.suggestion)), se;
232
240
  }), S !== null && requestAnimationFrame(() => {
233
- const d = m.current;
234
- d && (d.focus({
241
+ const p = m.current;
242
+ p && (p.focus({
235
243
  preventScroll: !0
236
- }), ft(d, S, S));
244
+ }), mt(p, S, S));
237
245
  });
238
- }, [b, re, y]), Be = l.useCallback((e) => {
239
- if (s ? g.applySuggestionValueSyntax(e) : Ke(e), xe?.(e), s) {
246
+ }, [k, re, y]), je = i.useCallback((e) => {
247
+ if (a ? h.applySuggestionValueSyntax(e) : ze(e), Ve?.(e), a) {
240
248
  const t = v.current;
241
249
  requestAnimationFrame(() => {
242
250
  if (!t) return;
@@ -247,50 +255,50 @@ const W = (u) => {
247
255
  };
248
256
  t.dispatchEvent(new Event("input", {
249
257
  bubbles: !0
250
- })), R?.(n), M?.(n);
258
+ })), R?.(n), F?.(n);
251
259
  });
252
260
  }
253
- i(!1), w.current = !1, requestAnimationFrame(() => {
261
+ l(!1), w.current = !1, requestAnimationFrame(() => {
254
262
  te();
255
263
  });
256
- }, [v, Ke, g, te, s, xe, i, M, R]), ye = l.useCallback((e) => {
257
- N(), Ie?.(e);
258
- }, [N, Ie]), Q = l.useCallback((e) => {
259
- if (de.current) {
260
- de.current = !1, Z?.(e);
264
+ }, [v, ze, h, te, a, Ve, l, F, R]), Ce = i.useCallback((e) => {
265
+ z(), Te?.(e);
266
+ }, [z, Te]), Q = i.useCallback((e) => {
267
+ if (ge.current) {
268
+ ge.current = !1, Z?.(e);
261
269
  return;
262
270
  }
263
271
  if (w.current) {
264
272
  Z?.(e);
265
273
  return;
266
274
  }
267
- i(!1), Z?.(e);
268
- }, [Z, i]), Se = l.useCallback((e) => {
269
- if (s) {
270
- g.handleKeyDownCapture(e), ce?.(e);
275
+ l(!1), Z?.(e);
276
+ }, [Z, l]), be = i.useCallback((e) => {
277
+ if (a) {
278
+ h.handleKeyDownCapture(e), ce?.(e);
271
279
  return;
272
280
  }
273
281
  (e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), ce?.(e);
274
- }, [g, s, ce]), Ce = l.useCallback((e) => {
275
- if (f) {
282
+ }, [h, a, ce]), ke = i.useCallback((e) => {
283
+ if (d) {
276
284
  if (e.key === "ArrowDown") {
277
- e.preventDefault(), e.stopPropagation(), K.current ? F.current?.highlightNextItem?.() : (i(!0), setTimeout(() => F.current?.focusFirstItem?.(), 0));
285
+ e.preventDefault(), e.stopPropagation(), B.current ? K.current?.highlightNextItem?.() : (l(!0), setTimeout(() => K.current?.focusFirstItem?.(), 0));
278
286
  return;
279
287
  }
280
288
  if (e.key === "ArrowUp") {
281
- e.preventDefault(), e.stopPropagation(), K.current ? F.current?.highlightPreviousItem?.() : (i(!0), setTimeout(() => F.current?.focusLastItem?.(), 0));
289
+ e.preventDefault(), e.stopPropagation(), B.current ? K.current?.highlightPreviousItem?.() : (l(!0), setTimeout(() => K.current?.focusLastItem?.(), 0));
282
290
  return;
283
291
  }
284
- if (e.key === "Enter" && K.current) {
285
- e.preventDefault(), e.stopPropagation(), F.current?.selectActiveItem?.() && i(!1);
292
+ if (e.key === "Enter" && B.current) {
293
+ e.preventDefault(), e.stopPropagation(), K.current?.selectActiveItem?.() && l(!1);
286
294
  return;
287
295
  }
288
- if (e.key === "Escape" && K.current) {
289
- e.preventDefault(), e.stopPropagation(), i(!1);
296
+ if (e.key === "Escape" && B.current) {
297
+ e.preventDefault(), e.stopPropagation(), l(!1);
290
298
  return;
291
299
  }
292
300
  }
293
- if (s && g.handleKeyDown(e)) {
301
+ if (a && h.handleKeyDown(e)) {
294
302
  if (e.key === "Backspace" || e.key === "Delete") {
295
303
  const n = v.current;
296
304
  if (n) {
@@ -299,63 +307,63 @@ const W = (u) => {
299
307
  target: n,
300
308
  currentTarget: n
301
309
  };
302
- R?.(o), M?.(o);
310
+ R?.(o), F?.(o);
303
311
  }
304
312
  }
305
313
  _?.(e);
306
314
  return;
307
315
  }
308
- if (s && e.key === "Enter") {
316
+ if (a && e.key === "Enter") {
309
317
  e.preventDefault(), _?.(e);
310
318
  return;
311
319
  }
312
320
  _?.(e);
313
- }, [v, g, s, f, i, M, R, _]), Ae = D(() => {
314
- if (!s) return null;
315
- const e = W(y), t = (A ?? []).filter(Boolean).filter((r) => r && (r.type === "text" || r.type === "block") && Number.isFinite(r.start) && Number.isFinite(r.end) && r.start <= r.end), n = t.length ? t : it(e), o = (B ?? []).slice(), a = [];
321
+ }, [v, h, a, d, l, F, R, _]), qe = D(() => {
322
+ if (!a) return null;
323
+ const e = U(y), t = (N ?? []).filter(Boolean).filter((r) => r && (r.type === "text" || r.type === "block") && Number.isFinite(r.start) && Number.isFinite(r.end) && r.start <= r.end), n = t.length ? t : pt(e), o = (A ?? []).slice(), s = [];
316
324
  return n.forEach((r, S) => {
317
- const c = r.value ?? e.slice(r.start, r.end);
325
+ const f = r.value ?? e.slice(r.start, r.end);
318
326
  if (r.type === "text") {
319
- const E = typeof r.content == "string" ? r.content : typeof c == "string" ? c : e.slice(r.start, r.end);
320
- E?.length && a.push(E);
327
+ const E = typeof r.content == "string" ? r.content : typeof f == "string" ? f : e.slice(r.start, r.end);
328
+ E?.length && s.push(E);
321
329
  return;
322
330
  }
323
- const V = ie(c);
324
- let d;
331
+ const V = ie(f);
332
+ let p;
325
333
  if (o.length) {
326
- const E = o[0], ae = ie(E?.value ?? E);
327
- (V === "" || ae === V) && (d = E, o.shift());
334
+ const E = o[0], se = ie(E?.value ?? E);
335
+ (V === "" || se === V) && (p = E, o.shift());
328
336
  }
329
- d || (d = {
330
- value: c
337
+ p || (p = {
338
+ value: f
331
339
  });
332
- const O = ht(d), se = r.content && typeof r.content != "string" || typeof r.content == "string" ? r.content : O?.label ?? O?.value ?? "";
333
- a.push(/* @__PURE__ */ j(l.Fragment, { children: [
340
+ const $ = bt(p), ae = r.content && typeof r.content != "string" || typeof r.content == "string" ? r.content : $?.label ?? $?.value ?? "";
341
+ s.push(/* @__PURE__ */ q(i.Fragment, { children: [
334
342
  "​",
335
- /* @__PURE__ */ p("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify(O), style: {
343
+ /* @__PURE__ */ g("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify($), style: {
336
344
  display: "inline-flex",
337
345
  alignItems: "center",
338
346
  verticalAlign: "middle",
339
347
  userSelect: "text",
340
348
  WebkitUserSelect: "text"
341
- }, children: se }),
349
+ }, children: ae }),
342
350
  "​"
343
351
  ] }, `${S}-${V}`));
344
- }), a;
345
- }, [B, s, A, y]);
346
- _e(() => {
347
- if (!s) return;
348
- const e = $.current;
352
+ }), s;
353
+ }, [A, a, N, y]);
354
+ ot(() => {
355
+ if (!a) return;
356
+ const e = O.current;
349
357
  if (!e) return;
350
- const t = g.takePendingSelection();
351
- t && gt(e, t.start, t.end);
352
- }, [g, s, Ae]);
353
- const Ge = D(() => {
354
- if (!s) return "plain";
355
- const e = W(y), t = B?.length ?? 0, n = A?.length ?? 0;
358
+ const t = h.takePendingSelection();
359
+ t && Ct(e, t.start, t.end);
360
+ }, [h, a, qe]);
361
+ const et = D(() => {
362
+ if (!a) return "plain";
363
+ const e = U(y), t = A?.length ?? 0, n = N?.length ?? 0;
356
364
  return `${e}-${t}-${n}`;
357
- }, [B, s, A, y]), ke = s ? /* @__PURE__ */ p("div", { ref: $, ...Qe, contentEditable: !C && !I, suppressContentEditableWarning: !0, "aria-disabled": C || I, onInput: (e) => {
358
- g.updateEditorState($.current), f && (w.current = !0, de.current = !0, i(!0), requestAnimationFrame(() => {
365
+ }, [A, a, N, y]), ve = a ? /* @__PURE__ */ g("div", { ref: O, ..._e, ...de, contentEditable: !C && !I, suppressContentEditableWarning: !0, "aria-disabled": C || I, onInput: (e) => {
366
+ h.updateEditorState(O.current), d && (w.current = !0, ge.current = !0, l(!0), requestAnimationFrame(() => {
359
367
  w.current = !1;
360
368
  }));
361
369
  const t = e.currentTarget, n = {
@@ -363,23 +371,23 @@ const W = (u) => {
363
371
  target: t,
364
372
  currentTarget: t
365
373
  };
366
- R?.(n), M?.(n);
374
+ R?.(n), F?.(n);
367
375
  }, onChange: (e) => {
368
- g.handleChange(e);
369
- }, onPaste: g.handlePaste, onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, spellCheck: !1, children: Ae }, Ge) : u.type === "textarea" ? /* @__PURE__ */ p("textarea", { ref: m, ...ue("input__control", Oe), onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, onInput: (e) => {
376
+ h.handleChange(e);
377
+ }, onPaste: h.handlePaste, onFocus: Ce, onBlur: Q, onKeyDownCapture: be, onKeyDown: ke, spellCheck: !1, children: qe }, et) : u.type === "textarea" ? /* @__PURE__ */ g("textarea", { ref: m, ...ue("input__control", Be), ...de, onFocus: Ce, onBlur: Q, onKeyDownCapture: be, onKeyDown: ke, onInput: (e) => {
370
378
  ne(e), R?.(e);
371
379
  }, onChange: (e) => {
372
- ne(e), M?.(e);
373
- }, spellCheck: !1, disabled: C || I }) : /* @__PURE__ */ p("input", { ref: m, ...ue("input__control", Oe), onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, onInput: (e) => {
380
+ ne(e), F?.(e);
381
+ }, spellCheck: !1, disabled: C || I }) : /* @__PURE__ */ g("input", { ref: m, ...ue("input__control", Be), ...de, onFocus: Ce, onBlur: Q, onKeyDownCapture: be, onKeyDown: ke, onInput: (e) => {
374
382
  ne(e), R?.(e);
375
383
  }, onChange: (e) => {
376
- ne(e), M?.(e);
377
- }, spellCheck: !1, disabled: C || I }), Xe = l.useCallback((e) => {
384
+ ne(e), F?.(e);
385
+ }, spellCheck: !1, disabled: C || I }), tt = i.useCallback((e) => {
378
386
  if (C || I) return;
379
387
  const t = e.target;
380
- fe.current?.contains(t) || (w.current = !0, te(), N());
381
- }, [C, I, te, N]);
382
- T(() => {
388
+ pe.current?.contains(t) || (w.current = !0, te(), z());
389
+ }, [C, I, te, z]);
390
+ P(() => {
383
391
  const e = ee.current;
384
392
  if (!e) return;
385
393
  const t = (n) => {
@@ -388,48 +396,48 @@ const W = (u) => {
388
396
  };
389
397
  return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
390
398
  }, [Q]);
391
- const Ye = D(() => /* @__PURE__ */ j(rt, { open: Pe, modal: !1, onOpenChange: (e) => {
392
- !e && w.current || i(e);
399
+ const nt = D(() => /* @__PURE__ */ q(it, { open: Re, modal: !1, onOpenChange: (e) => {
400
+ !e && w.current || l(e);
393
401
  }, children: [
394
- /* @__PURE__ */ p(ot, { asChild: !0, children: /* @__PURE__ */ p("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
402
+ /* @__PURE__ */ g(lt, { asChild: !0, children: /* @__PURE__ */ g("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
395
403
  position: "absolute",
396
404
  inset: 0,
397
405
  opacity: 0,
398
406
  pointerEvents: "none"
399
407
  }, onMouseDown: (e) => e.preventDefault() }) }),
400
- ke,
401
- /* @__PURE__ */ p(st, { children: /* @__PURE__ */ p("div", { ref: fe, onPointerDownCapture: () => {
408
+ ve,
409
+ /* @__PURE__ */ g(ct, { children: /* @__PURE__ */ g("div", { ref: pe, onPointerDownCapture: () => {
402
410
  w.current = !0;
403
411
  }, onMouseDownCapture: (e) => {
404
412
  e.preventDefault(), w.current = !0;
405
- }, children: /* @__PURE__ */ j(at, { color: "secondary", inputRef: v, children: [
406
- be,
407
- /* @__PURE__ */ j(dt, { paddingSize: "xxs", mt: -0.2, mx: -0.2, children: [
408
- oe?.length === 0 && De,
409
- !!oe?.length && /* @__PURE__ */ p(
410
- ut,
413
+ }, children: /* @__PURE__ */ q(ft, { color: "secondary", inputRef: v, children: [
414
+ xe,
415
+ /* @__PURE__ */ q(yt, { paddingSize: "xxs", mt: -0.2, mx: -0.2, children: [
416
+ oe?.length === 0 && Pe,
417
+ !!oe?.length && /* @__PURE__ */ g(
418
+ dt,
411
419
  {
412
- ref: F,
420
+ ref: K,
413
421
  inputRef: v,
414
422
  suggestions: oe,
415
- onSuggestionSelect: Be
423
+ onSuggestionSelect: je
416
424
  }
417
425
  )
418
426
  ] }),
419
- ve
427
+ we
420
428
  ] }) }) })
421
- ] }), [Pe, ke, s, oe, be, ve, De, Be, v, i]);
422
- return /* @__PURE__ */ j("div", { children: [
423
- U && /* @__PURE__ */ p(et, { children: U }),
424
- P && /* @__PURE__ */ p(tt, { children: P }),
425
- /* @__PURE__ */ j("div", { ref: ee, ...ue(`input ${L?.valid ? "" : "input--not-valid"}`, G), onPointerDown: Xe, children: [
426
- H && /* @__PURE__ */ p("div", { className: `input__left input__left--${ze}`, children: H }),
427
- f ? Ye : ke,
428
- X && /* @__PURE__ */ p("div", { className: `input__right input__right--${je}`, children: X })
429
+ ] }), [Re, ve, a, oe, xe, we, Pe, je, v, l]);
430
+ return /* @__PURE__ */ q("div", { children: [
431
+ T && /* @__PURE__ */ g(at, { htmlFor: fe, id: Le, children: T }),
432
+ L && /* @__PURE__ */ g(st, { children: L }),
433
+ /* @__PURE__ */ q("div", { ref: ee, ...ue(`input ${M?.valid ? "" : "input--not-valid"}`, G), onPointerDown: tt, children: [
434
+ H && /* @__PURE__ */ g("div", { className: `input__left input__left--${Ue}`, children: H }),
435
+ d ? nt : ve,
436
+ X && /* @__PURE__ */ g("div", { className: `input__right input__right--${He}`, children: X })
429
437
  ] }),
430
- !L?.valid && L?.notValidMessage && /* @__PURE__ */ p(nt, { children: L.notValidMessage })
438
+ !M?.valid && M?.notValidMessage && /* @__PURE__ */ g(ut, { children: M.notValidMessage })
431
439
  ] });
432
- }), Mt = mt;
440
+ }), Kt = kt;
433
441
  export {
434
- Mt as Input
442
+ Kt as Input
435
443
  };