docthub-core-components 3.0.0 → 3.1.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.
- package/dist/components/overrides/ui/auto-complete.js +466 -0
- package/dist/components/overrides/ui/autocomplete-checkbox.js +480 -0
- package/dist/components/overrides/ui/chips/doct-chip.js +157 -0
- package/dist/components/overrides/ui/circular-progress.js +32 -0
- package/dist/components/overrides/ui/composed/address-form-section.js +67 -0
- package/dist/components/overrides/ui/composed/contact-form-section.js +56 -0
- package/dist/components/overrides/ui/composed/search-filter-section.js +132 -0
- package/dist/components/overrides/ui/composed/user-registration-section.js +77 -0
- package/dist/components/overrides/ui/currencyInput/currency-input.js +69 -0
- package/dist/components/overrides/ui/doct-animation-loader.js +13 -0
- package/dist/components/overrides/ui/expandable-card.js +115 -0
- package/dist/components/overrides/ui/footer/doct-footer.js +35 -0
- package/dist/components/overrides/ui/footer/footer-desktop.js +92 -0
- package/dist/components/overrides/ui/footer/footer-mobile.js +123 -0
- package/dist/components/overrides/ui/footer/footer-routes.js +87 -0
- package/dist/components/overrides/ui/footer/footer-shared.js +137 -0
- package/dist/components/overrides/ui/footer/presets.js +269 -0
- package/dist/components/overrides/ui/inputs/labeled-input.js +92 -0
- package/dist/components/overrides/ui/inputs/otp-input.js +101 -0
- package/dist/components/overrides/ui/inputs/password-input.js +77 -0
- package/dist/components/overrides/ui/inputs/phone-input.js +336 -0
- package/dist/components/overrides/ui/navigation-menu/doct-navigation-menu.js +22 -0
- package/dist/components/overrides/ui/navigation-menu/individual-nav-routes.js +46 -0
- package/dist/components/overrides/ui/navigation-menu/individual-navigation-menu-desktop.js +109 -0
- package/dist/components/overrides/ui/navigation-menu/individual-navigation-menu-mobile.js +231 -0
- package/dist/components/overrides/ui/navigation-menu/individual-navigation-menu.js +44 -0
- package/dist/components/overrides/ui/navigation-menu/nav-env.js +64 -0
- package/dist/components/overrides/ui/navigation-menu/navigation-menu-adapter.js +55 -0
- package/dist/components/overrides/ui/navigation-menu/navigation-menu-internal.js +36 -0
- package/dist/components/overrides/ui/navigation-menu/organization-nav-routes.js +34 -0
- package/dist/components/overrides/ui/navigation-menu/organization-navigation-menu-desktop.js +109 -0
- package/dist/components/overrides/ui/navigation-menu/organization-navigation-menu-mobile.js +231 -0
- package/dist/components/overrides/ui/navigation-menu/organization-navigation-menu.js +44 -0
- package/dist/components/overrides/ui/navigation-menu/presets.js +238 -0
- package/dist/components/overrides/ui/navigation-menu/types.js +6 -0
- package/dist/components/overrides/ui/pickers/date-picker-field.js +361 -0
- package/dist/components/overrides/ui/pickers/date-range-picker-field.js +288 -0
- package/dist/components/overrides/ui/pickers/day-picker-bounds.js +38 -0
- package/dist/components/overrides/ui/pickers/select-field.js +158 -0
- package/dist/components/overrides/ui/search/auto-complete.js +64 -0
- package/dist/components/overrides/ui/search/search-input.js +65 -0
- package/dist/components/overrides/ui/showcase/component-section.js +45 -0
- package/dist/components/ui/alert.js +94 -0
- package/dist/components/ui/avatar.js +69 -0
- package/dist/components/ui/badge.js +37 -0
- package/dist/components/ui/breadcrumb.js +117 -0
- package/dist/components/ui/button.js +223 -0
- package/dist/components/ui/calendar.js +100 -0
- package/dist/components/ui/checkbox.js +57 -0
- package/dist/components/ui/collapsible.js +25 -0
- package/dist/components/ui/command.js +132 -0
- package/dist/components/ui/dialog.js +230 -0
- package/dist/components/ui/drawer.js +119 -0
- package/dist/components/ui/dropdown-menu.js +216 -0
- package/dist/components/ui/input.js +48 -0
- package/dist/components/ui/label.js +22 -0
- package/dist/components/ui/popover.js +181 -0
- package/dist/components/ui/progress.js +91 -0
- package/dist/components/ui/radio-group.js +49 -0
- package/dist/components/ui/select.js +169 -0
- package/dist/components/ui/skeleton.js +91 -0
- package/dist/components/ui/spinner.js +32 -0
- package/dist/components/ui/tabs.js +68 -0
- package/dist/components/ui/textarea.js +73 -0
- package/dist/components/ui/timeline.js +177 -0
- package/dist/components/ui/toast.js +82 -0
- package/dist/components/ui/tooltip.js +91 -0
- package/dist/components/ui/typography.js +213 -0
- package/dist/hooks/use-exclusive-dropdown.js +53 -0
- package/dist/hooks/use-mobile.js +19 -0
- package/dist/hooks/useAutocompleteCheckbox.js +204 -0
- package/dist/index.js +187 -0
- package/dist/lib/dropdown-manager.js +17 -0
- package/dist/lib/get-floating-dropdown-position.js +32 -0
- package/dist/lib/get-scroll-parents.js +20 -0
- package/dist/lib/slot.js +40 -0
- package/dist/lib/utils.js +9 -0
- package/dist/util/getInputClasses.js +19 -0
- package/package.json +4 -4
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as a, jsxs as q, Fragment as Ie } from "react/jsx-runtime";
|
|
3
|
+
import { c as fe } from "react-compiler-runtime";
|
|
4
|
+
import { X as Re, ChevronDown as Ce, Check as er } from "lucide-react";
|
|
5
|
+
import { useState as Z, useEffect as p, useDeferredValue as rr, useRef as O, useId as tr, useMemo as J, useCallback as P, memo as sr } from "react";
|
|
6
|
+
import { createPortal as cr } from "react-dom";
|
|
7
|
+
import { Input as or } from "../../ui/input.js";
|
|
8
|
+
import { useExclusiveDropdown as ir } from "../../../hooks/use-exclusive-dropdown.js";
|
|
9
|
+
import { getFloatingDropdownPosition as lr } from "../../../lib/get-floating-dropdown-position.js";
|
|
10
|
+
import { getScrollParentClipRects as dr, getScrollParents as ar } from "../../../lib/get-scroll-parents.js";
|
|
11
|
+
const nr = {
|
|
12
|
+
small: "h-8 text-xs px-2",
|
|
13
|
+
medium: "h-10 text-sm px-3",
|
|
14
|
+
large: "h-12 text-base px-4"
|
|
15
|
+
}, fr = {
|
|
16
|
+
outlined: "border border-input",
|
|
17
|
+
filled: "border-0 bg-accent",
|
|
18
|
+
standard: "border-0 border-b border-input rounded-none"
|
|
19
|
+
}, ur = (l, e) => e && typeof l == "object" && l !== null ? l[e.text] : typeof l == "string" ? l : (l == null ? void 0 : l.label) || "", mr = (l, e) => e && typeof l == "object" && l !== null ? l[e.value] : typeof l == "string" ? l : (l == null ? void 0 : l.value) || l, yr = (l, e, t, d) => t(l, d) === t(e, d), ke = (l) => {
|
|
20
|
+
if (l == null) return "";
|
|
21
|
+
try {
|
|
22
|
+
return String(l).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
23
|
+
} catch {
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
}, br = (l, e, t, d) => {
|
|
27
|
+
if (!e) return l;
|
|
28
|
+
const i = ke(e);
|
|
29
|
+
return l.filter((s) => {
|
|
30
|
+
const S = t(s, d);
|
|
31
|
+
return ke(S).includes(i);
|
|
32
|
+
});
|
|
33
|
+
}, Se = sr((l) => {
|
|
34
|
+
const e = fe(10);
|
|
35
|
+
let t, d, i, s;
|
|
36
|
+
e[0] !== l ? ({
|
|
37
|
+
className: i,
|
|
38
|
+
variant: s,
|
|
39
|
+
children: t,
|
|
40
|
+
...d
|
|
41
|
+
} = l, e[0] = l, e[1] = t, e[2] = d, e[3] = i, e[4] = s) : (t = e[1], d = e[2], i = e[3], s = e[4]);
|
|
42
|
+
const S = i === void 0 ? "" : i, c = s === void 0 ? "default" : s;
|
|
43
|
+
let x;
|
|
44
|
+
e[5] === Symbol.for("react.memo_cache_sentinel") ? (x = {
|
|
45
|
+
default: "border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
|
46
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
47
|
+
destructive: "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
|
48
|
+
outline: "text-foreground border-border bg-background hover:bg-accent hover:text-accent-foreground"
|
|
49
|
+
}, e[5] = x) : x = e[5];
|
|
50
|
+
const f = `inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 ${x[c]} ${S}`;
|
|
51
|
+
let u;
|
|
52
|
+
return e[6] !== t || e[7] !== d || e[8] !== f ? (u = /* @__PURE__ */ a("div", { className: f, ...d, children: t }), e[6] = t, e[7] = d, e[8] = f, e[9] = u) : u = e[9], u;
|
|
53
|
+
});
|
|
54
|
+
Se.displayName = "Badge";
|
|
55
|
+
const Te = (l) => {
|
|
56
|
+
const e = fe(17), {
|
|
57
|
+
option: t,
|
|
58
|
+
index: d,
|
|
59
|
+
isSelected: i,
|
|
60
|
+
isHighlighted: s,
|
|
61
|
+
onSelect: S,
|
|
62
|
+
getOptionLabel: c,
|
|
63
|
+
renderOption: x
|
|
64
|
+
} = l;
|
|
65
|
+
let y;
|
|
66
|
+
e[0] !== S || e[1] !== t ? (y = () => {
|
|
67
|
+
S(t);
|
|
68
|
+
}, e[0] = S, e[1] = t, e[2] = y) : y = e[2];
|
|
69
|
+
const f = y;
|
|
70
|
+
let u;
|
|
71
|
+
e[3] !== f ? (u = (H) => {
|
|
72
|
+
(H.key === "Enter" || H.key === " ") && (H.preventDefault(), f());
|
|
73
|
+
}, e[3] = f, e[4] = u) : u = e[4];
|
|
74
|
+
const T = u, V = `
|
|
75
|
+
px-3 py-2 cursor-pointer flex items-center justify-between
|
|
76
|
+
text-sm transition-colors mb-[0.4vh]
|
|
77
|
+
${s ? "bg-accent text-accent-foreground" : ""}
|
|
78
|
+
${i ? "bg-primary/10" : ""}
|
|
79
|
+
hover:bg-accent hover:text-accent-foreground
|
|
80
|
+
`;
|
|
81
|
+
let N;
|
|
82
|
+
e[5] !== c || e[6] !== d || e[7] !== i || e[8] !== t || e[9] !== x ? (N = x ? x(t, d) : /* @__PURE__ */ q(Ie, { children: [
|
|
83
|
+
/* @__PURE__ */ a("span", { children: c(t) }),
|
|
84
|
+
i && /* @__PURE__ */ a(er, { className: "h-4 w-4 text-primary" })
|
|
85
|
+
] }), e[5] = c, e[6] = d, e[7] = i, e[8] = t, e[9] = x, e[10] = N) : N = e[10];
|
|
86
|
+
let b;
|
|
87
|
+
return e[11] !== f || e[12] !== T || e[13] !== i || e[14] !== V || e[15] !== N ? (b = /* @__PURE__ */ a("div", { role: "option", "aria-selected": i, onClick: f, onKeyDown: T, tabIndex: 0, className: V, children: N }), e[11] = f, e[12] = T, e[13] = i, e[14] = V, e[15] = N, e[16] = b) : b = e[16], b;
|
|
88
|
+
};
|
|
89
|
+
Te.displayName = "AutocompleteOption";
|
|
90
|
+
const Fe = (l) => {
|
|
91
|
+
const e = fe(20), {
|
|
92
|
+
tag: t,
|
|
93
|
+
index: d,
|
|
94
|
+
getOptionLabel: i,
|
|
95
|
+
onRemove: s,
|
|
96
|
+
chipClassName: S
|
|
97
|
+
} = l;
|
|
98
|
+
let c;
|
|
99
|
+
e[0] !== s || e[1] !== t ? (c = (te) => {
|
|
100
|
+
te.stopPropagation(), s(t);
|
|
101
|
+
}, e[0] = s, e[1] = t, e[2] = c) : c = e[2];
|
|
102
|
+
const x = c, y = `text-xs ${S ?? ""}`;
|
|
103
|
+
let f;
|
|
104
|
+
e[3] !== y ? (f = y.trim(), e[3] = y, e[4] = f) : f = e[4];
|
|
105
|
+
let u;
|
|
106
|
+
e[5] !== i || e[6] !== t ? (u = i(t), e[5] = i, e[6] = t, e[7] = u) : u = e[7];
|
|
107
|
+
let T;
|
|
108
|
+
e[8] !== i || e[9] !== t ? (T = i(t), e[8] = i, e[9] = t, e[10] = T) : T = e[10];
|
|
109
|
+
const V = `Remove ${T}`;
|
|
110
|
+
let N;
|
|
111
|
+
e[11] === Symbol.for("react.memo_cache_sentinel") ? (N = /* @__PURE__ */ a(Re, { className: "h-3 w-3" }), e[11] = N) : N = e[11];
|
|
112
|
+
let b;
|
|
113
|
+
e[12] !== x || e[13] !== V ? (b = /* @__PURE__ */ a("button", { type: "button", onClick: x, className: "ml-1 hover:bg-secondary-foreground/20 rounded-full p-0.5", "data-testid": "tag-remove", "aria-label": V, children: N }), e[12] = x, e[13] = V, e[14] = b) : b = e[14];
|
|
114
|
+
let H;
|
|
115
|
+
return e[15] !== d || e[16] !== f || e[17] !== u || e[18] !== b ? (H = /* @__PURE__ */ q(Se, { variant: "secondary", className: f, children: [
|
|
116
|
+
u,
|
|
117
|
+
b
|
|
118
|
+
] }, d), e[15] = d, e[16] = f, e[17] = u, e[18] = b, e[19] = H) : H = e[19], H;
|
|
119
|
+
};
|
|
120
|
+
Fe.displayName = "AutocompleteTag";
|
|
121
|
+
const Sr = ({
|
|
122
|
+
options: l = [],
|
|
123
|
+
dataSource: e = [],
|
|
124
|
+
// Default to empty array
|
|
125
|
+
value: t = null,
|
|
126
|
+
onChange: d,
|
|
127
|
+
change: i,
|
|
128
|
+
// New prop for stories
|
|
129
|
+
onInputChange: s,
|
|
130
|
+
placeholder: S = "Search...",
|
|
131
|
+
multiple: c = !1,
|
|
132
|
+
freeSolo: x = !1,
|
|
133
|
+
disabled: y = !1,
|
|
134
|
+
loading: f = !1,
|
|
135
|
+
size: u = "medium",
|
|
136
|
+
variant: T = "outlined",
|
|
137
|
+
label: V = "",
|
|
138
|
+
helperText: N = "",
|
|
139
|
+
error: b,
|
|
140
|
+
required: H = !1,
|
|
141
|
+
fullWidth: te = !0,
|
|
142
|
+
clearable: ue = !0,
|
|
143
|
+
disableCloseOnSelect: se = !1,
|
|
144
|
+
filterOptions: ce,
|
|
145
|
+
getOptionLabel: E = (n) => ur(n, L),
|
|
146
|
+
getOptionValue: j = (n) => mr(n, L),
|
|
147
|
+
isOptionEqualToValue: me,
|
|
148
|
+
renderOption: Pe,
|
|
149
|
+
renderTags: oe,
|
|
150
|
+
fields: L,
|
|
151
|
+
// New prop for field mapping
|
|
152
|
+
noOptionsText: Ve = "No options",
|
|
153
|
+
emptyMessage: He,
|
|
154
|
+
className: Ke = "",
|
|
155
|
+
inputClassName: ye = "",
|
|
156
|
+
chipClassName: be,
|
|
157
|
+
debounceMs: ie = 0,
|
|
158
|
+
// New: Debounce filtering
|
|
159
|
+
minSearchLength: xe = 0,
|
|
160
|
+
// New prop: Min chars before search
|
|
161
|
+
ntt: pe = !1,
|
|
162
|
+
clearInputOnSelect: xr = !0,
|
|
163
|
+
onPointerDown: _,
|
|
164
|
+
...ze
|
|
165
|
+
}) => {
|
|
166
|
+
const [n, w] = Z(!1), [k, A] = Z(""), [je, we] = Z(""), [z, g] = Z(-1), [I, R] = Z(!1), [M, Be] = Z({
|
|
167
|
+
top: 0,
|
|
168
|
+
left: 0,
|
|
169
|
+
width: 0,
|
|
170
|
+
maxHeight: 0,
|
|
171
|
+
placement: "bottom"
|
|
172
|
+
}), {
|
|
173
|
+
containerProps: Ue,
|
|
174
|
+
onOpenChange: ve
|
|
175
|
+
} = ir();
|
|
176
|
+
p(() => {
|
|
177
|
+
if (ie <= 0) {
|
|
178
|
+
we(k);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const r = setTimeout(() => we(k), ie);
|
|
182
|
+
return () => clearTimeout(r);
|
|
183
|
+
}, [k, ie]);
|
|
184
|
+
const G = rr(je), v = O(null), Ne = O(null), Q = O(null), W = O(null), Y = O(!1), Ee = tr(), X = e.length > 0 ? e : l, F = J(() => me || ((r, o) => yr(r, o, j, L)), [me, j, L]), C = P((r) => {
|
|
185
|
+
if (r == null) return "";
|
|
186
|
+
if (typeof r == "object") return E(r);
|
|
187
|
+
const o = X.find((m) => F(m, r));
|
|
188
|
+
if (o) return E(o);
|
|
189
|
+
try {
|
|
190
|
+
return String(r);
|
|
191
|
+
} catch {
|
|
192
|
+
return "";
|
|
193
|
+
}
|
|
194
|
+
}, [X, E, F]), B = J(() => {
|
|
195
|
+
if (G.length < xe)
|
|
196
|
+
return X;
|
|
197
|
+
let r = X;
|
|
198
|
+
return c && Array.isArray(t) && (r = X.filter((o) => !t.some((m) => F(o, m)))), !c && !I && t && G === E(t) ? r : ce ? ce(r, {
|
|
199
|
+
inputValue: G
|
|
200
|
+
}) : br(r, G, E, L);
|
|
201
|
+
}, [
|
|
202
|
+
X,
|
|
203
|
+
t,
|
|
204
|
+
G,
|
|
205
|
+
// Use deferred value
|
|
206
|
+
ce,
|
|
207
|
+
E,
|
|
208
|
+
c,
|
|
209
|
+
F,
|
|
210
|
+
L,
|
|
211
|
+
I,
|
|
212
|
+
xe
|
|
213
|
+
]), qe = P((r) => {
|
|
214
|
+
const o = r.target.value;
|
|
215
|
+
R(!0), A(o), s == null || s(r, o), !n && o && w(!0);
|
|
216
|
+
}, [n, s]);
|
|
217
|
+
p(() => {
|
|
218
|
+
if (c || I) return;
|
|
219
|
+
const r = C(t);
|
|
220
|
+
A(r);
|
|
221
|
+
}, [t, c, I, C]), p(() => {
|
|
222
|
+
i && process.env.NODE_ENV !== "production" && console.warn('[DoctAutocomplete] The "change" prop is deprecated. Please use "onChange" instead. "change" will be removed in v3.0.');
|
|
223
|
+
}, [i]);
|
|
224
|
+
const ee = P((r) => {
|
|
225
|
+
if (c) {
|
|
226
|
+
const o = Array.isArray(t) ? t : [], m = o.some((D) => F(r, D));
|
|
227
|
+
let $;
|
|
228
|
+
m ? $ = o.filter((D) => !F(r, D)) : $ = [...o, r], d == null || d(null, $), i == null || i({
|
|
229
|
+
itemData: $
|
|
230
|
+
}), R(!1), se || w(!1), setTimeout(() => {
|
|
231
|
+
var D;
|
|
232
|
+
(D = v.current) == null || D.focus();
|
|
233
|
+
}, 0);
|
|
234
|
+
} else
|
|
235
|
+
d == null || d(null, r), i == null || i({
|
|
236
|
+
itemData: r
|
|
237
|
+
}), A(E(r)), R(!1), se || w(!1);
|
|
238
|
+
g(-1);
|
|
239
|
+
}, [c, t, F, d, i, se, E]), le = P((r) => {
|
|
240
|
+
if (c && Array.isArray(t)) {
|
|
241
|
+
const o = t.filter((m) => !F(r, m));
|
|
242
|
+
d == null || d(null, o), i == null || i({
|
|
243
|
+
itemData: o
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}, [c, t, F, d, i]), Le = P((r) => {
|
|
247
|
+
r.stopPropagation(), c ? (A(""), R(!1), s == null || s({
|
|
248
|
+
target: {
|
|
249
|
+
value: ""
|
|
250
|
+
}
|
|
251
|
+
}, ""), setTimeout(() => {
|
|
252
|
+
v.current && (v.current.value = "", v.current.focus());
|
|
253
|
+
}, 0), w(!1)) : (d == null || d(null, null), i == null || i({
|
|
254
|
+
itemData: null
|
|
255
|
+
}), A(""), R(!1), s == null || s({
|
|
256
|
+
target: {
|
|
257
|
+
value: ""
|
|
258
|
+
}
|
|
259
|
+
}, ""), setTimeout(() => {
|
|
260
|
+
v.current && (v.current.value = "", v.current.focus());
|
|
261
|
+
}, 0), w(!1));
|
|
262
|
+
}, [d, i, c, s]), Ae = J(() => c ? Array.isArray(t) && t.length > 0 : t != null, [c, t]), Ge = J(() => !ue || y ? !1 : c ? k !== "" : Ae, [ue, y, c, k, Ae]), Xe = P((r) => {
|
|
263
|
+
if (!n && (r.key === "ArrowDown" || r.key === "ArrowUp")) {
|
|
264
|
+
w(!0);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (n)
|
|
268
|
+
switch (r.key) {
|
|
269
|
+
case "ArrowDown":
|
|
270
|
+
r.preventDefault(), g((o) => o < B.length - 1 ? o + 1 : 0);
|
|
271
|
+
break;
|
|
272
|
+
case "ArrowUp":
|
|
273
|
+
r.preventDefault(), g((o) => o > 0 ? o - 1 : B.length - 1);
|
|
274
|
+
break;
|
|
275
|
+
case "Enter":
|
|
276
|
+
r.preventDefault(), z >= 0 && B[z] ? ee(B[z]) : x && k && ee(k);
|
|
277
|
+
break;
|
|
278
|
+
case "Escape":
|
|
279
|
+
w(!1), g(-1), c && (A(""), R(!1), s == null || s({
|
|
280
|
+
target: {
|
|
281
|
+
value: ""
|
|
282
|
+
}
|
|
283
|
+
}, ""));
|
|
284
|
+
break;
|
|
285
|
+
case "Tab":
|
|
286
|
+
w(!1), c && (A(""), R(!1), s == null || s({
|
|
287
|
+
target: {
|
|
288
|
+
value: ""
|
|
289
|
+
}
|
|
290
|
+
}, ""));
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}, [n, B, z, ee, x, k, c, s]), K = P(() => {
|
|
294
|
+
const r = Ne.current ?? W.current;
|
|
295
|
+
if (!r) return;
|
|
296
|
+
const o = r.getBoundingClientRect(), m = dr(r);
|
|
297
|
+
Be(lr({
|
|
298
|
+
anchorRect: o,
|
|
299
|
+
placement: "auto",
|
|
300
|
+
strategy: "absolute",
|
|
301
|
+
clipRects: m
|
|
302
|
+
}));
|
|
303
|
+
}, []), Ze = P(() => {
|
|
304
|
+
n || (K(), k === "" && (s == null || s({
|
|
305
|
+
target: {
|
|
306
|
+
value: ""
|
|
307
|
+
}
|
|
308
|
+
}, ""))), w(!n);
|
|
309
|
+
}, [n, K, k, s]), Je = P(() => {
|
|
310
|
+
if (Y.current) {
|
|
311
|
+
Y.current = !1, K(), R(!1), !c && !t && (A(""), s == null || s({
|
|
312
|
+
target: {
|
|
313
|
+
value: ""
|
|
314
|
+
}
|
|
315
|
+
}, ""));
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
K(), R(!1), w(!0), !c && !t && (A(""), s == null || s({
|
|
319
|
+
target: {
|
|
320
|
+
value: ""
|
|
321
|
+
}
|
|
322
|
+
}, ""));
|
|
323
|
+
}, [K, c, t, s]), Me = P((r) => {
|
|
324
|
+
document.activeElement === v.current && w((o) => !o), _ == null || _(r);
|
|
325
|
+
}, [_]);
|
|
326
|
+
p(() => {
|
|
327
|
+
const r = (o) => {
|
|
328
|
+
const m = o.target;
|
|
329
|
+
if (!(n || c && k !== "")) return;
|
|
330
|
+
const D = W.current ? !W.current.contains(m) : !0, de = Q.current ? !Q.current.contains(m) : !0;
|
|
331
|
+
if (D && de) {
|
|
332
|
+
if (w(!1), R(!1), c) {
|
|
333
|
+
A(""), s == null || s({
|
|
334
|
+
target: {
|
|
335
|
+
value: ""
|
|
336
|
+
}
|
|
337
|
+
}, "");
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const h = C(t);
|
|
341
|
+
A(h), s == null || s({
|
|
342
|
+
target: {
|
|
343
|
+
value: h
|
|
344
|
+
}
|
|
345
|
+
}, h);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
return document.addEventListener("pointerdown", r, !0), () => {
|
|
349
|
+
document.removeEventListener("pointerdown", r, !0);
|
|
350
|
+
};
|
|
351
|
+
}, [c, s, C, t, n, k]), p(() => {
|
|
352
|
+
if (!n || typeof window > "u") return;
|
|
353
|
+
const r = () => {
|
|
354
|
+
K();
|
|
355
|
+
}, o = W.current, m = ar(o), $ = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
|
|
356
|
+
K();
|
|
357
|
+
});
|
|
358
|
+
return $ == null || $.observe(o ?? document.body), m.forEach((D) => {
|
|
359
|
+
D.addEventListener("scroll", r, {
|
|
360
|
+
passive: !0
|
|
361
|
+
});
|
|
362
|
+
}), window.addEventListener("resize", r), () => {
|
|
363
|
+
$ == null || $.disconnect(), m.forEach((D) => {
|
|
364
|
+
D.removeEventListener("scroll", r);
|
|
365
|
+
}), window.removeEventListener("resize", r);
|
|
366
|
+
};
|
|
367
|
+
}, [n, K]), p(() => {
|
|
368
|
+
if (n && z >= 0 && Q.current) {
|
|
369
|
+
const r = Q.current.children[z];
|
|
370
|
+
r && r.scrollIntoView({
|
|
371
|
+
block: "nearest"
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}, [z, n]), p(() => {
|
|
375
|
+
if (!n || !c) return;
|
|
376
|
+
const r = requestAnimationFrame(() => {
|
|
377
|
+
K();
|
|
378
|
+
});
|
|
379
|
+
return () => cancelAnimationFrame(r);
|
|
380
|
+
}, [n, c, t, K]), p(() => {
|
|
381
|
+
w(!1);
|
|
382
|
+
}, []), p(() => {
|
|
383
|
+
ve(n);
|
|
384
|
+
}, [n, ve]);
|
|
385
|
+
const $e = P(() => {
|
|
386
|
+
var r;
|
|
387
|
+
document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
|
|
388
|
+
target: {
|
|
389
|
+
value: ""
|
|
390
|
+
}
|
|
391
|
+
}, "")), (r = v.current) == null || r.focus();
|
|
392
|
+
}, [c, s]), Qe = J(() => !c || !Array.isArray(t) || t.length === 0 ? null : oe ? oe(t, le) : (
|
|
393
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: chips container wraps nested buttons (tag remove)
|
|
394
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: Escape/click-outside already close; click is convenience
|
|
395
|
+
/* @__PURE__ */ a("div", { className: "flex flex-wrap gap-1 mb-1 min-h-0", onClick: $e, children: t.map((r, o) => {
|
|
396
|
+
const m = j ? String(j(r)) : `${E(r)}-${o}`;
|
|
397
|
+
return /* @__PURE__ */ a(Fe, { tag: r, index: o, getOptionLabel: E, onRemove: le, chipClassName: be }, m);
|
|
398
|
+
}) })
|
|
399
|
+
), [c, t, oe, le, $e, E, j, be]), We = J(() => `
|
|
400
|
+
relative flex items-center rounded-md
|
|
401
|
+
${b ? "border border-destructive" : fr[T]}
|
|
402
|
+
${nr[u]}
|
|
403
|
+
${y ? "opacity-50 cursor-not-allowed" : "cursor-text"}
|
|
404
|
+
transition-colors ${ye}
|
|
405
|
+
`, [T, u, b, y, ye]), Ye = He ?? Ve;
|
|
406
|
+
return /* @__PURE__ */ q("div", { className: `relative ${te ? "w-full" : "w-auto"} ${Ke}`, ref: W, children: [
|
|
407
|
+
V && /* @__PURE__ */ q("label", { htmlFor: Ee, className: "block text-sm font-medium mb-1 w-full", onClick: (r) => {
|
|
408
|
+
var o;
|
|
409
|
+
r.preventDefault(), document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
|
|
410
|
+
target: {
|
|
411
|
+
value: ""
|
|
412
|
+
}
|
|
413
|
+
}, "")), (o = v.current) == null || o.focus();
|
|
414
|
+
}, onKeyDown: (r) => {
|
|
415
|
+
var o;
|
|
416
|
+
(r.key === "Enter" || r.key === " ") && (r.preventDefault(), document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
|
|
417
|
+
target: {
|
|
418
|
+
value: ""
|
|
419
|
+
}
|
|
420
|
+
}, "")), (o = v.current) == null || o.focus());
|
|
421
|
+
}, children: [
|
|
422
|
+
V,
|
|
423
|
+
H && /* @__PURE__ */ a("span", { className: "text-destructive ml-1", children: "*" })
|
|
424
|
+
] }),
|
|
425
|
+
/* @__PURE__ */ a("div", { ...Ue, children: /* @__PURE__ */ q("div", { className: "relative overflow-visible", children: [
|
|
426
|
+
Qe,
|
|
427
|
+
/* @__PURE__ */ q("div", { ref: Ne, className: We, children: [
|
|
428
|
+
/* @__PURE__ */ a(or, { id: Ee, ref: v, value: k, onChange: qe, onKeyDown: Xe, onFocus: Je, onPointerDown: Me, placeholder: S, disabled: y, className: "px-0 border-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent rounded-md", ...ze }),
|
|
429
|
+
/* @__PURE__ */ q("div", { className: "flex items-center gap-1 ml-auto", children: [
|
|
430
|
+
f && /* @__PURE__ */ a("div", { className: "animate-spin rounded-full h-4 w-4 border-2 border-muted-foreground border-t-transparent" }),
|
|
431
|
+
Ge && /* @__PURE__ */ a("button", { type: "button", onClick: Le, className: "p-1 hover:bg-accent rounded-sm transition-colors", tabIndex: -1, "data-testid": "autocomplete-clear", children: /* @__PURE__ */ a(Re, { className: "h-4 w-4 text-muted-foreground" }) }),
|
|
432
|
+
/* @__PURE__ */ a("button", { type: "button", disabled: y, onClick: Ze, className: `p-1 hover:bg-accent rounded-sm transition-colors ${y ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}`, tabIndex: -1, "data-testid": "autocomplete-toggle", children: /* @__PURE__ */ a(Ce, { className: `h-4 w-4 text-muted-foreground transition-transform ${n ? "rotate-180" : ""}` }) })
|
|
433
|
+
] })
|
|
434
|
+
] }),
|
|
435
|
+
n && M.maxHeight > 0 && cr(/* @__PURE__ */ a("div", { className: `
|
|
436
|
+
absolute bg-popover border border-border rounded-md shadow-lg
|
|
437
|
+
max-h-60 overflow-auto z-[9999]
|
|
438
|
+
|
|
439
|
+
`, style: {
|
|
440
|
+
top: M.top,
|
|
441
|
+
left: M.left,
|
|
442
|
+
width: M.width,
|
|
443
|
+
maxHeight: M.maxHeight
|
|
444
|
+
}, ref: Q, children: B.length === 0 ? /* @__PURE__ */ a("div", { className: "p-3 text-sm text-muted-foreground text-center", children: Ye }) : B.map((r, o) => {
|
|
445
|
+
const m = c ? Array.isArray(t) && t.some((U) => F(r, U)) : F(r, t), $ = o === z, D = j ? String(j(r)) : `${E(r)}-${o}`, de = (U) => U.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), h = (U) => {
|
|
446
|
+
const ae = E(U), ne = pe ? String(G || "").trim() : "";
|
|
447
|
+
if (!ne) return /* @__PURE__ */ a("span", { children: ae });
|
|
448
|
+
try {
|
|
449
|
+
const he = new RegExp(`(${de(ne)})`, "ig"), Oe = ae.split(he);
|
|
450
|
+
return /* @__PURE__ */ a("span", { children: Oe.map((re, _e) => {
|
|
451
|
+
const ge = re.toLowerCase() === ne.toLowerCase(), De = `${re}-${_e}`;
|
|
452
|
+
return ge ? /* @__PURE__ */ a("span", { className: "font-bold", children: re }, De) : /* @__PURE__ */ a("span", { children: re }, De);
|
|
453
|
+
}) });
|
|
454
|
+
} catch {
|
|
455
|
+
return /* @__PURE__ */ a("span", { children: ae });
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
return /* @__PURE__ */ a(Te, { option: r, index: o, isSelected: m, isHighlighted: $, onSelect: ee, getOptionLabel: E, renderOption: Pe || ((U) => h(U)) }, D);
|
|
459
|
+
}) }), document.body)
|
|
460
|
+
] }) }),
|
|
461
|
+
(N || b) && /* @__PURE__ */ a("p", { className: `mt-1 text-xs ${b ? "text-destructive" : "text-muted-foreground"}`, children: b || N })
|
|
462
|
+
] });
|
|
463
|
+
};
|
|
464
|
+
export {
|
|
465
|
+
Sr as DoctAutocomplete
|
|
466
|
+
};
|