@code0-tech/pictor 0.16.0 → 0.17.1

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 (60) hide show
  1. package/dist/assets/components/alert/Alert.style.css +1 -1
  2. package/dist/assets/components/avatar/Avatar.style.css +1 -1
  3. package/dist/assets/components/badge/Badge.style.css +1 -1
  4. package/dist/assets/components/breadcrumb/Breadcrumb.style.css +1 -1
  5. package/dist/assets/components/button/Button.style.css +1 -1
  6. package/dist/assets/components/button-group/ButtonGroup.style.css +1 -1
  7. package/dist/assets/components/card/Card.style.css +1 -1
  8. package/dist/assets/components/chart/Chart.style.css +1 -1
  9. package/dist/assets/components/command/Command.style.css +1 -1
  10. package/dist/assets/components/context-menu/ContextMenu.style.css +1 -1
  11. package/dist/assets/components/data-table/DataTable.style.css +1 -1
  12. package/dist/assets/components/dialog/Dialog.style.css +1 -1
  13. package/dist/assets/components/editor/Editor.styles.css +1 -1
  14. package/dist/assets/components/file-tabs/FileTabs.style.css +1 -1
  15. package/dist/assets/components/form/ColorInput.style.css +1 -1
  16. package/dist/assets/components/form/DateInput.style.css +1 -1
  17. package/dist/assets/components/form/EditorInput.style.css +1 -1
  18. package/dist/assets/components/form/Input.style.css +1 -1
  19. package/dist/assets/components/form/InputWrapper.style.css +1 -1
  20. package/dist/assets/components/form/SelectInput.style.css +1 -1
  21. package/dist/assets/components/json-view/JsonView.style.css +1 -1
  22. package/dist/assets/components/menu/Menu.style.css +1 -1
  23. package/dist/assets/components/resizable/Resizable.style.css +1 -1
  24. package/dist/assets/components/segmented-control/SegmentedControl.style.css +1 -1
  25. package/dist/assets/components/spacing/Spacing.style.css +1 -1
  26. package/dist/assets/components/tab/Tab.style.css +1 -1
  27. package/dist/assets/components/text/Text.style.css +1 -1
  28. package/dist/assets/components/toast/Toast.style.css +1 -1
  29. package/dist/assets/components/tooltip/Tooltip.style.css +1 -1
  30. package/dist/components/command/Command.js +35 -38
  31. package/dist/components/form/DateInput.js +82 -86
  32. package/dist/components/form/EditorInput.d.ts +35 -10
  33. package/dist/components/form/EditorInput.js +535 -148
  34. package/dist/components/form/EmailInput.js +16 -15
  35. package/dist/components/form/Input.d.ts +0 -20
  36. package/dist/components/form/Input.js +47 -432
  37. package/dist/components/form/InputWrapper.d.ts +0 -1
  38. package/dist/components/form/InputWrapper.js +52 -48
  39. package/dist/components/form/NumberInput.js +17 -16
  40. package/dist/components/form/PasswordInput.js +23 -22
  41. package/dist/components/form/TagInput.d.ts +37 -0
  42. package/dist/components/form/TagInput.js +124 -0
  43. package/dist/components/form/TextInput.js +12 -11
  44. package/dist/components/form/index.d.ts +1 -2
  45. package/dist/components/form/index.js +77 -70
  46. package/dist/components/layout/Layout.js +37 -37
  47. package/dist/components/menu/Menu.d.ts +2 -2
  48. package/dist/components/menu/Menu.js +87 -87
  49. package/dist/components/scroll-area/ScrollArea.js +1 -1
  50. package/dist/index.js +220 -213
  51. package/dist/utils/index.js +11 -11
  52. package/dist/utils/size.d.ts +3 -3
  53. package/dist/utils/size.js +12 -6
  54. package/package.json +1 -1
  55. package/dist/components/form/Input.syntax.hook.d.ts +0 -10
  56. package/dist/components/form/Input.syntax.hook.js +0 -14
  57. package/dist/components/form/InputContentEditable.hook.d.ts +0 -52
  58. package/dist/components/form/InputContentEditable.hook.js +0 -449
  59. package/dist/components/form/InputSuggestion.d.ts +0 -27
  60. package/dist/components/form/InputSuggestion.js +0 -218
@@ -1,21 +1,22 @@
1
- import { jsx as o } from "react/jsx-runtime";
2
- import e from "react";
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import a from "react";
3
3
  import { Input as l } from "./Input.js";
4
4
  import { IconX as m } from "@tabler/icons-react";
5
- import { Button as f } from "../button/Button.js";
6
- import { clearInputElement as s } from "./Input.utils.js";
7
- const p = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/, I = (t) => p.test(t), _ = e.forwardRef((t, x) => {
8
- x = x || e.useRef(null);
5
+ import { Button as p } from "../button/Button.js";
6
+ import { clearInputElement as f } from "./Input.utils.js";
7
+ import { ButtonGroup as s } from "../button-group/ButtonGroup.js";
8
+ const u = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/, g = (o) => u.test(o), R = a.forwardRef((o, x) => {
9
+ x = x || a.useRef(null);
9
10
  const {
10
- clearable: r = !1,
11
- right: n,
12
- ...c
13
- } = t, i = () => {
14
- s(x.current);
15
- }, a = [n];
16
- return r && a.push(/* @__PURE__ */ o(f, { onClick: i, children: /* @__PURE__ */ o(m, { size: 13 }) })), /* @__PURE__ */ o(l, { right: a, type: "email", ref: x, ...c });
11
+ clearable: e = !1,
12
+ right: i,
13
+ ...n
14
+ } = o, c = () => {
15
+ f(x.current);
16
+ }, r = [i];
17
+ return e && r.push(/* @__PURE__ */ t(p, { color: "secondary", paddingSize: "xxs", onClick: c, children: /* @__PURE__ */ t(m, { size: 13 }) })), /* @__PURE__ */ t(l, { right: /* @__PURE__ */ t(s, { color: "primary", children: r }), type: "email", ref: x, ...n });
17
18
  });
18
19
  export {
19
- _ as EmailInput,
20
- I as emailValidation
20
+ R as EmailInput,
21
+ g as emailValidation
21
22
  };
@@ -1,21 +1,8 @@
1
1
  import { default as React } from 'react';
2
2
  import { Component } from '../../utils';
3
3
  import { ValidationProps } from './useForm';
4
- import { InputSuggestion } from './InputSuggestion';
5
- import { InputSyntaxSegment } from './Input.syntax.hook';
6
4
  export type Code0Input = Omit<Component<HTMLInputElement>, "left" | "right" | "title" | "defaultValue" | "value">;
7
5
  export interface InputProps<T> extends Code0Input, ValidationProps<T> {
8
- suggestions?: InputSuggestion[];
9
- suggestionsHeader?: React.ReactNode;
10
- suggestionsFooter?: React.ReactNode;
11
- onSuggestionSelect?: (suggestion: InputSuggestion) => void;
12
- transformSyntax?: (value: T, appliedSyntaxParts?: (InputSuggestion | any)[]) => InputSyntaxSegment[];
13
- validationUsesSyntax?: boolean;
14
- disableOnValue?: (value: T) => boolean;
15
- filterSuggestionsByLastToken?: boolean;
16
- onLastTokenChange?: (token: string | null) => void;
17
- enforceUniqueSuggestions?: boolean;
18
- suggestionsEmptyState?: React.ReactNode;
19
6
  wrapperComponent?: Component<HTMLDivElement>;
20
7
  right?: React.ReactNode;
21
8
  left?: React.ReactNode;
@@ -25,11 +12,4 @@ export interface InputProps<T> extends Code0Input, ValidationProps<T> {
25
12
  description?: React.ReactNode;
26
13
  }
27
14
  export type InputElement = HTMLInputElement | HTMLDivElement;
28
- export type InputActiveSuggestionSpan = {
29
- id: number;
30
- suggestion: InputSuggestion;
31
- text: string;
32
- start: number;
33
- end: number;
34
- };
35
15
  export declare const Input: React.FC<InputProps<any>>;
@@ -1,443 +1,58 @@
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";
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import a, { useRef as C } from "react";
3
3
  import "../../utils/contextStore.js";
4
- import { mergeComponentProps as ue } from "../../utils/component.js";
4
+ import { mergeComponentProps as _ } from "../../utils/component.js";
5
5
  import "js-md5";
6
6
  import '../../assets/components/form/Input.style.css';/* empty css */
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
- const x = u ?? "";
18
- return typeof x == "string" ? x : String(x);
19
- }, ie = (u) => {
20
- if (u == null) return "";
21
- if (typeof u == "string") return u;
22
- try {
23
- return JSON.stringify(u);
24
- } catch {
25
- return String(u ?? "");
26
- }
27
- }, bt = (u) => {
28
- if (u && typeof u == "object") {
29
- const {
30
- children: x,
31
- __contentHtml: G,
32
- ...T
33
- } = u;
34
- return T;
35
- }
36
- return {
37
- value: u
38
- };
39
- }, We = (u) => {
40
- if (!u) return null;
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
- return {
45
- token: C,
46
- start: H,
47
- end: X
48
- };
49
- }, kt = i.forwardRef((u, x) => {
7
+ import { InputWrapper as v } from "./InputWrapper.js";
8
+ const F = (i) => {
9
+ const o = i ?? "";
10
+ return typeof o == "string" ? o : String(o);
11
+ }, H = a.forwardRef((i, o) => {
50
12
  const {
51
- wrapperComponent: G = {},
52
- title: T,
53
- description: L,
54
- disabled: C = !1,
55
- left: H,
56
- right: X,
57
- leftType: Ue = "icon",
58
- rightType: He = "action",
59
- formValidation: M = {
13
+ wrapperComponent: b = {},
14
+ title: p,
15
+ description: I,
16
+ disabled: u = !1,
17
+ left: k,
18
+ right: x,
19
+ leftType: R = "icon",
20
+ rightType: P = "action",
21
+ formValidation: r = {
60
22
  valid: !0,
61
- notValidMessage: null,
62
- setValue: null
23
+ notValidMessage: null
63
24
  },
64
- suggestions: d,
65
- suggestionsHeader: xe,
66
- suggestionsFooter: we,
67
- onSuggestionSelect: Ve,
68
- disableOnValue: Ee = () => !1,
69
- transformSyntax: Y,
70
- validationUsesSyntax: le = !1,
71
- filterSuggestionsByLastToken: k = !1,
72
- enforceUniqueSuggestions: De = !1,
73
- onLastTokenChange: Ie,
74
- suggestionsEmptyState: Pe,
75
- ...Je
76
- } = u, {
77
- onFocus: Te,
78
- onBlur: Z,
79
- onKeyDown: _,
80
- onKeyDownCapture: ce,
81
- onChange: F,
82
- onInput: R,
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
25
+ initialValue: L,
26
+ ...T
27
+ } = i, {
28
+ onChange: d,
29
+ onInput: f,
30
+ ...t
31
+ } = T, w = a.useId(), O = t.id ?? w, m = p ? void 0 : t["aria-label"] ?? t.placeholder, h = {
32
+ id: O,
33
+ ...m ? {
34
+ "aria-label": m
91
35
  } : {}
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(() => {
99
- const {
100
- value: e,
101
- defaultValue: t,
102
- ...n
103
- } = c;
104
- return ue("input__control", n);
105
- }, [c]), te = i.useCallback(() => {
106
- const e = v.current;
107
- !e || C || I || e.focus({
108
- preventScroll: !0
109
- });
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,
123
- transformSyntax: Y,
124
- filterSuggestionsByLastToken: k,
125
- onLastTokenChange: Se,
126
- onStateChange: ({
127
- value: e,
128
- tokens: t,
129
- segments: n
130
- }) => {
131
- me(e), ye(t), Ze(n ?? null), J(e, n ?? null);
132
- }
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;
144
- const e = (t) => {
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);
147
- };
148
- return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
149
- }, [d, l]), P(() => {
150
- const e = ee.current;
151
- if (!e) return;
152
- const t = () => z();
153
- return e.addEventListener("focusin", t), () => e.removeEventListener("focusin", t);
154
- }, [z]);
155
- const Ne = i.useCallback((e, t, n) => {
156
- if (e.length === 0) return t <= n.length ? t : null;
157
- let o = n.indexOf(e);
158
- if (o === -1) return null;
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);
162
- return o;
163
- }, []), re = i.useCallback((e, t) => {
164
- const n = [];
165
- return e.forEach((o) => {
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({
170
- ...o,
171
- start: s,
172
- end: r
173
- });
174
- }), n;
175
- }, [Ne]);
176
- P(() => {
177
- if (a) return;
178
- const e = U(m.current?.value ?? y);
179
- Oe((t) => {
180
- const n = re(t, e);
181
- return ye(n.map((o) => o.suggestion)), n;
182
- });
183
- }, [a, re, y]), P(() => {
184
- if (!k || a) return;
185
- const e = m.current;
186
- if (!e) return;
187
- const t = () => Se(We(e)?.token ?? null);
188
- return e.addEventListener("input", t), e.addEventListener("keyup", t), e.addEventListener("mouseup", t), t(), () => {
189
- e.removeEventListener("input", t), e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t);
190
- };
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)));
201
- }
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) => {
205
- if (!m.current) return;
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;
211
- else
212
- switch (o) {
213
- case "append":
214
- r = `${s}${n}`, S = r.length, f = s.length;
215
- break;
216
- case "prepend":
217
- r = `${n}${s}`, S = n.length, f = 0;
218
- break;
219
- case "insert": {
220
- const {
221
- rawStart: p,
222
- rawEnd: $
223
- } = gt(m.current);
224
- r = `${s.slice(0, p)}${n}${s.slice($)}`, S = p + n.length, f = p;
225
- break;
226
- }
227
- default:
228
- r = n, S = n.length, f = 0;
229
- break;
230
- }
231
- ht(m.current, "value", r, "change"), Oe((p) => {
232
- const $ = U(r), ae = re(p, $), E = n.length ? {
233
- id: Ge.current++,
234
- suggestion: e,
235
- text: n,
236
- start: f,
237
- end: f + n.length
238
- } : null, se = E ? [...ae, E] : ae;
239
- return ye(se.map((rt) => rt.suggestion)), se;
240
- }), S !== null && requestAnimationFrame(() => {
241
- const p = m.current;
242
- p && (p.focus({
243
- preventScroll: !0
244
- }), mt(p, S, S));
245
- });
246
- }, [k, re, y]), je = i.useCallback((e) => {
247
- if (a ? h.applySuggestionValueSyntax(e) : ze(e), Ve?.(e), a) {
248
- const t = v.current;
249
- requestAnimationFrame(() => {
250
- if (!t) return;
251
- const n = {
252
- type: "change",
253
- target: t,
254
- currentTarget: t
255
- };
256
- t.dispatchEvent(new Event("input", {
257
- bubbles: !0
258
- })), R?.(n), F?.(n);
259
- });
260
- }
261
- l(!1), w.current = !1, requestAnimationFrame(() => {
262
- te();
263
- });
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);
269
- return;
270
- }
271
- if (w.current) {
272
- Z?.(e);
273
- return;
274
- }
275
- l(!1), Z?.(e);
276
- }, [Z, l]), be = i.useCallback((e) => {
277
- if (a) {
278
- h.handleKeyDownCapture(e), ce?.(e);
279
- return;
280
- }
281
- (e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), ce?.(e);
282
- }, [h, a, ce]), ke = i.useCallback((e) => {
283
- if (d) {
284
- if (e.key === "ArrowDown") {
285
- e.preventDefault(), e.stopPropagation(), B.current ? K.current?.highlightNextItem?.() : (l(!0), setTimeout(() => K.current?.focusFirstItem?.(), 0));
286
- return;
287
- }
288
- if (e.key === "ArrowUp") {
289
- e.preventDefault(), e.stopPropagation(), B.current ? K.current?.highlightPreviousItem?.() : (l(!0), setTimeout(() => K.current?.focusLastItem?.(), 0));
290
- return;
291
- }
292
- if (e.key === "Enter" && B.current) {
293
- e.preventDefault(), e.stopPropagation(), K.current?.selectActiveItem?.() && l(!1);
294
- return;
295
- }
296
- if (e.key === "Escape" && B.current) {
297
- e.preventDefault(), e.stopPropagation(), l(!1);
298
- return;
299
- }
300
- }
301
- if (a && h.handleKeyDown(e)) {
302
- if (e.key === "Backspace" || e.key === "Delete") {
303
- const n = v.current;
304
- if (n) {
305
- const o = {
306
- type: "change",
307
- target: n,
308
- currentTarget: n
309
- };
310
- R?.(o), F?.(o);
311
- }
312
- }
313
- _?.(e);
314
- return;
315
- }
316
- if (a && e.key === "Enter") {
317
- e.preventDefault(), _?.(e);
318
- return;
319
- }
320
- _?.(e);
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 = [];
324
- return n.forEach((r, S) => {
325
- const f = r.value ?? e.slice(r.start, r.end);
326
- if (r.type === "text") {
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);
329
- return;
330
- }
331
- const V = ie(f);
332
- let p;
333
- if (o.length) {
334
- const E = o[0], se = ie(E?.value ?? E);
335
- (V === "" || se === V) && (p = E, o.shift());
336
- }
337
- p || (p = {
338
- value: f
339
- });
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: [
342
- "​",
343
- /* @__PURE__ */ g("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify($), style: {
344
- display: "inline-flex",
345
- alignItems: "center",
346
- verticalAlign: "middle",
347
- userSelect: "text",
348
- WebkitUserSelect: "text"
349
- }, children: ae }),
350
- "​"
351
- ] }, `${S}-${V}`));
352
- }), s;
353
- }, [A, a, N, y]);
354
- ot(() => {
355
- if (!a) return;
356
- const e = O.current;
357
- if (!e) return;
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;
364
- return `${e}-${t}-${n}`;
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(() => {
367
- w.current = !1;
368
- }));
369
- const t = e.currentTarget, n = {
370
- type: "change",
371
- target: t,
372
- currentTarget: t
373
- };
374
- R?.(n), F?.(n);
36
+ }, s = C(null), g = C(null);
37
+ a.useImperativeHandle(o, () => s.current);
38
+ const V = a.useCallback((e) => {
39
+ if (!r?.setValue) return;
40
+ const n = t.type !== "checkbox" ? F(e) : e;
41
+ Object.is(g.current, n) || (g.current = n, r.setValue(n));
42
+ }, [r?.setValue, t.type]), l = a.useCallback((e) => {
43
+ const n = e.currentTarget, z = t.type === "checkbox" && "checked" in n ? n.checked : n.value;
44
+ V(z);
45
+ }, [t.type, V]), y = _("input-wrapper__control input__control", t), j = t.type === "textarea" ? /* @__PURE__ */ c("textarea", { ref: s, ...y, ...h, onInput: (e) => {
46
+ l(e), f?.(e);
375
47
  }, onChange: (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) => {
378
- ne(e), R?.(e);
48
+ l(e), d?.(e);
49
+ }, spellCheck: !1, disabled: u }) : /* @__PURE__ */ c("input", { ref: s, ...y, ...h, onInput: (e) => {
50
+ l(e), f?.(e);
379
51
  }, onChange: (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) => {
382
- ne(e), R?.(e);
383
- }, onChange: (e) => {
384
- ne(e), F?.(e);
385
- }, spellCheck: !1, disabled: C || I }), tt = i.useCallback((e) => {
386
- if (C || I) return;
387
- const t = e.target;
388
- pe.current?.contains(t) || (w.current = !0, te(), z());
389
- }, [C, I, te, z]);
390
- P(() => {
391
- const e = ee.current;
392
- if (!e) return;
393
- const t = (n) => {
394
- const o = n.relatedTarget;
395
- o && e.contains(o) || Q(n);
396
- };
397
- return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
398
- }, [Q]);
399
- const nt = D(() => /* @__PURE__ */ q(it, { open: Re, modal: !1, onOpenChange: (e) => {
400
- !e && w.current || l(e);
401
- }, children: [
402
- /* @__PURE__ */ g(lt, { asChild: !0, children: /* @__PURE__ */ g("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
403
- position: "absolute",
404
- inset: 0,
405
- opacity: 0,
406
- pointerEvents: "none"
407
- }, onMouseDown: (e) => e.preventDefault() }) }),
408
- ve,
409
- /* @__PURE__ */ g(ct, { children: /* @__PURE__ */ g("div", { ref: pe, onPointerDownCapture: () => {
410
- w.current = !0;
411
- }, onMouseDownCapture: (e) => {
412
- e.preventDefault(), w.current = !0;
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,
419
- {
420
- ref: K,
421
- inputRef: v,
422
- suggestions: oe,
423
- onSuggestionSelect: je
424
- }
425
- )
426
- ] }),
427
- we
428
- ] }) }) })
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 })
437
- ] }),
438
- !M?.valid && M?.notValidMessage && /* @__PURE__ */ g(ut, { children: M.notValidMessage })
439
- ] });
440
- }), Kt = kt;
52
+ l(e), d?.(e);
53
+ }, spellCheck: !1, disabled: u });
54
+ return /* @__PURE__ */ c(v, { type: t.type, title: p, description: I, left: k, right: x, leftType: R, rightType: P, formValidation: r, ...b, children: j });
55
+ }), E = H;
441
56
  export {
442
- Kt as Input
57
+ E as Input
443
58
  };
@@ -8,6 +8,5 @@ export interface InputWrapperProps<T = any> extends Omit<Component<HTMLElement>,
8
8
  rightType?: "action" | "placeholder" | "icon";
9
9
  title?: React.ReactNode;
10
10
  description?: React.ReactNode;
11
- wrapperComponent?: Component<HTMLDivElement>;
12
11
  }
13
12
  export declare const InputWrapper: React.ForwardRefExoticComponent<InputWrapperProps>;