@overdoser/react-toolkit 0.16.0 → 0.17.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,376 +1,425 @@
1
- import { jsx as s, jsxs as P, Fragment as me } from "react/jsx-runtime";
2
- import { forwardRef as ne, useState as U, useRef as w, useId as le, useCallback as S, useMemo as ae, useEffect as $ } from "react";
3
- import { createPortal as ie } from "react-dom";
4
- import f from "clsx";
1
+ import { jsx as s, jsxs as R, Fragment as xe } from "react/jsx-runtime";
2
+ import { forwardRef as ie, useState as X, useRef as N, useId as de, useCallback as M, useMemo as fe, useEffect as B } from "react";
3
+ import { createPortal as me } from "react-dom";
4
+ import h from "clsx";
5
5
  import e from "./Select.module.scss.js";
6
- import { usePortalPosition as se } from "../../../hooks/usePortalPosition.js";
7
- const oe = ne(
6
+ import { usePortalPosition as he } from "../../../hooks/usePortalPosition.js";
7
+ const pe = ie(
8
8
  ({
9
- inputSize: h = "md",
10
- error: b = !1,
11
- options: p,
12
- placeholder: q,
13
- classes: u,
14
- className: W,
15
- style: B,
16
- children: y,
9
+ inputSize: u = "md",
10
+ error: p = !1,
11
+ options: f,
12
+ placeholder: I,
13
+ classes: o,
14
+ className: E,
15
+ style: A,
16
+ children: v,
17
17
  searchable: g,
18
- searchPlaceholder: ee,
19
- onChange: te,
20
- onValueChange: v,
21
- ...L
22
- }, N) => {
23
- const M = te || v ? (o) => {
24
- te?.(o), v?.(o.target.value);
18
+ searchPlaceholder: y,
19
+ onChange: z,
20
+ onValueChange: x,
21
+ ...O
22
+ }, P) => {
23
+ const G = z || x ? (k) => {
24
+ z?.(k), x?.(k.target.value);
25
25
  } : void 0;
26
- return /* @__PURE__ */ P("div", { className: f(e.wrapper, e[h], b && e.error, u?.wrapper, W), style: B, children: [
27
- /* @__PURE__ */ P(
26
+ return /* @__PURE__ */ R("div", { className: h(e.wrapper, e[u], p && e.error, o?.wrapper, E), style: A, children: [
27
+ /* @__PURE__ */ R(
28
28
  "select",
29
29
  {
30
- ref: N,
31
- className: f(e.root, e[h], b && e.error, u?.root),
32
- onChange: M,
33
- ...L,
30
+ ref: P,
31
+ className: h(e.root, e[u], p && e.error, o?.root),
32
+ onChange: G,
33
+ ...O,
34
34
  children: [
35
- q && /* @__PURE__ */ s("option", { value: "", disabled: !0, children: q }),
36
- p ? p.map((o) => /* @__PURE__ */ s("option", { value: o.value, disabled: o.disabled, children: o.label }, o.value)) : y
35
+ I && /* @__PURE__ */ s("option", { value: "", disabled: !0, children: I }),
36
+ f ? f.map((k) => /* @__PURE__ */ s("option", { value: k.value, disabled: k.disabled, children: k.label }, k.value)) : v
37
37
  ]
38
38
  }
39
39
  ),
40
- /* @__PURE__ */ s("span", { className: f(e.arrow, u?.arrow) })
40
+ /* @__PURE__ */ s("span", { className: h(e.arrow, o?.arrow) })
41
41
  ] });
42
42
  }
43
43
  );
44
- oe.displayName = "NativeSelect";
45
- const ce = ne(
44
+ pe.displayName = "NativeSelect";
45
+ function ve(u) {
46
+ const { name: p, form: f, required: I, title: o, autoFocus: E, tabIndex: A } = u, v = { title: o, autoFocus: E, tabIndex: A };
47
+ I && (v["aria-required"] = !0);
48
+ for (const y of Object.keys(u))
49
+ (y.startsWith("aria-") || y.startsWith("data-")) && (v[y] = u[y]);
50
+ const g = {};
51
+ for (const y of Object.keys(v))
52
+ y.startsWith("aria-") && (g[y] = v[y]);
53
+ return { hidden: { name: p, form: f }, control: v, aria: g };
54
+ }
55
+ function be(u, p, f) {
56
+ const I = N(!1);
57
+ return {
58
+ onFocus: (o) => {
59
+ I.current || (I.current = !0, u?.(o));
60
+ },
61
+ onBlur: (o) => {
62
+ const E = o.relatedTarget;
63
+ E && f.some((A) => A.current?.contains(E)) || (I.current = !1, p?.(o));
64
+ }
65
+ };
66
+ }
67
+ const ge = ie(
46
68
  ({
47
- inputSize: h = "md",
48
- error: b = !1,
49
- options: p = [],
50
- placeholder: q = "Select...",
51
- classes: u,
52
- className: W,
53
- style: B,
54
- value: y,
69
+ inputSize: u = "md",
70
+ error: p = !1,
71
+ options: f = [],
72
+ placeholder: I = "Select...",
73
+ classes: o,
74
+ className: E,
75
+ style: A,
76
+ value: v,
55
77
  disabled: g,
56
- id: ee,
57
- searchPlaceholder: te = "Search...",
58
- onChange: v,
59
- onValueChange: L,
60
- portal: N = !0
61
- }, M) => {
62
- const [o, X] = U(!1), [A, T] = U(""), [c, d] = U(0), j = w(null), I = w(null), _ = w(null), R = w(null), k = w(null), Q = le(), K = se(j, o && N), H = w(null), re = (r) => {
63
- H.current = r, typeof M == "function" ? M(r) : M && (M.current = r);
64
- }, z = w(!1);
65
- $(() => {
66
- z.current && !o && _.current?.focus(), z.current = o;
67
- }, [o]);
68
- const C = S(() => {
69
- X(!1), T(""), d(0);
70
- }, []), G = S(() => {
71
- g || (X(!0), T(""), d(0), setTimeout(() => I.current?.focus(), 0));
72
- }, [g]), J = S(
78
+ id: y,
79
+ searchPlaceholder: z = "Search...",
80
+ onChange: x,
81
+ onValueChange: O,
82
+ portal: P = !0,
83
+ onFocus: G,
84
+ onBlur: k,
85
+ ...re
86
+ }, _) => {
87
+ const [b, ne] = X(!1), [U, F] = X(""), [c, d] = X(0), H = N(null), S = N(null), q = N(null), D = N(null), C = N(null), j = de(), K = he(H, b && P), { hidden: J, control: le, aria: Y } = ve(re), ae = be(G, k, [H, D]), T = N(null), oe = (r) => {
88
+ T.current = r, typeof _ == "function" ? _(r) : _ && (_.current = r);
89
+ }, Z = N(!1);
90
+ B(() => {
91
+ Z.current && !b && q.current?.focus(), Z.current = b;
92
+ }, [b]);
93
+ const W = M(() => {
94
+ ne(!1), F(""), d(0);
95
+ }, []), se = M(() => {
96
+ g || (ne(!0), F(""), d(0), setTimeout(() => S.current?.focus(), 0));
97
+ }, [g]), V = M(
73
98
  (r) => {
74
- if (L?.(r), H.current) {
99
+ if (O?.(r), T.current) {
75
100
  Object.getOwnPropertyDescriptor(
76
101
  HTMLSelectElement.prototype,
77
102
  "value"
78
- )?.set?.call(H.current, r);
103
+ )?.set?.call(T.current, r);
79
104
  const n = new Event("change", { bubbles: !0 });
80
- H.current.dispatchEvent(n), v?.(n);
105
+ T.current.dispatchEvent(n), x?.(n);
81
106
  }
82
- C();
107
+ W();
83
108
  },
84
- [L, v, H, C]
85
- ), x = ae(() => {
86
- if (!A) return p;
87
- const r = A.toLowerCase();
88
- return p.filter((a) => a.label.toLowerCase().includes(r));
89
- }, [p, A]);
90
- $(() => {
91
- const r = x.findIndex((a) => !a.disabled);
109
+ [O, x, T, W]
110
+ ), m = fe(() => {
111
+ if (!U) return f;
112
+ const r = U.toLowerCase();
113
+ return f.filter((l) => l.label.toLowerCase().includes(r));
114
+ }, [f, U]);
115
+ B(() => {
116
+ const r = m.findIndex((l) => !l.disabled);
92
117
  d(r >= 0 ? r : 0);
93
- }, [x]), $(() => {
94
- if (!o) return;
95
- const r = k.current;
118
+ }, [m]), B(() => {
119
+ if (!b) return;
120
+ const r = C.current;
96
121
  if (!r) return;
97
122
  r.querySelectorAll('[role="option"]')[c]?.scrollIntoView?.({ block: "nearest" });
98
- }, [c, o]);
99
- const E = S(
123
+ }, [c, b]);
124
+ const ee = M(
100
125
  (r) => {
101
- const a = x.map((n, m) => n.disabled ? -1 : m).filter((n) => n >= 0);
102
- if (a.length !== 0)
126
+ const l = m.map((n, w) => n.disabled ? -1 : w).filter((n) => n >= 0);
127
+ if (r.key === "Escape") {
128
+ r.preventDefault(), W();
129
+ return;
130
+ }
131
+ if (l.length !== 0) {
103
132
  if (r.key === "ArrowDown")
104
133
  r.preventDefault(), d((n) => {
105
- const m = a.indexOf(n);
106
- return m < a.length - 1 ? a[m + 1] : a[0];
134
+ const w = l.indexOf(n);
135
+ return w < l.length - 1 ? l[w + 1] : l[0];
107
136
  });
108
137
  else if (r.key === "ArrowUp")
109
138
  r.preventDefault(), d((n) => {
110
- const m = a.indexOf(n);
111
- return m > 0 ? a[m - 1] : a[a.length - 1];
139
+ const w = l.indexOf(n);
140
+ return w > 0 ? l[w - 1] : l[l.length - 1];
112
141
  });
113
142
  else if (r.key === "Enter") {
114
143
  r.preventDefault();
115
- const n = x[c];
116
- n && !n.disabled && J(n.value);
117
- } else r.key === "Escape" && (r.preventDefault(), C());
144
+ const n = m[c];
145
+ n && !n.disabled && V(n.value);
146
+ }
147
+ }
118
148
  },
119
- [x, c, J, C]
149
+ [m, c, V, W]
120
150
  );
121
- $(() => {
122
- if (!o) return;
123
- const r = (a) => {
124
- const n = a.target;
125
- j.current?.contains(n) || R.current?.contains(n) || C();
151
+ B(() => {
152
+ if (!b) return;
153
+ const r = (l) => {
154
+ const n = l.target;
155
+ H.current?.contains(n) || D.current?.contains(n) || W();
126
156
  };
127
157
  return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
128
- }, [o, C]);
129
- const O = p.find((r) => r.value === y)?.label, Y = x.filter((r) => !r.disabled);
130
- return /* @__PURE__ */ P(
158
+ }, [b, W]);
159
+ const $ = f.find((r) => r.value === v)?.label, ce = m.filter((r) => !r.disabled);
160
+ return /* @__PURE__ */ R(
131
161
  "div",
132
162
  {
133
- ref: j,
134
- className: f(
163
+ ref: H,
164
+ className: h(
135
165
  e.wrapper,
136
166
  e.searchableWrapper,
137
- e[h],
138
- b && e.error,
167
+ e[u],
168
+ p && e.error,
139
169
  g && e.disabled,
140
- u?.wrapper,
141
- W
170
+ o?.wrapper,
171
+ E
142
172
  ),
143
- style: B,
173
+ style: A,
174
+ ...ae,
144
175
  children: [
145
- /* @__PURE__ */ s(
176
+ /* @__PURE__ */ R(
146
177
  "select",
147
178
  {
148
- ref: re,
179
+ ref: oe,
149
180
  className: e.hiddenSelect,
150
- value: y ?? "",
181
+ value: v ?? "",
151
182
  disabled: g,
152
183
  tabIndex: -1,
153
184
  "aria-hidden": "true",
154
185
  onChange: () => {
155
186
  },
156
- children: p.map((r) => /* @__PURE__ */ s("option", { value: r.value, children: r.label }, r.value))
187
+ ...J,
188
+ children: [
189
+ /* @__PURE__ */ s("option", { value: "" }),
190
+ f.map((r) => /* @__PURE__ */ s("option", { value: r.value, children: r.label }, r.value))
191
+ ]
157
192
  }
158
193
  ),
159
- /* @__PURE__ */ P(
194
+ /* @__PURE__ */ R(
160
195
  "button",
161
196
  {
162
- ref: _,
163
- id: ee,
197
+ ref: q,
198
+ id: b ? void 0 : y,
164
199
  type: "button",
165
- className: f(
200
+ className: h(
166
201
  e.root,
167
202
  e.searchableTrigger,
168
- e[h],
169
- o && e.triggerOpen,
170
- b && e.error,
171
- o && e.visuallyHidden,
172
- u?.root
203
+ e[u],
204
+ b && e.triggerOpen,
205
+ p && e.error,
206
+ b && e.visuallyHidden,
207
+ o?.root
173
208
  ),
174
- onClick: G,
209
+ onClick: se,
175
210
  disabled: g,
176
- "aria-expanded": o,
211
+ "aria-expanded": b,
177
212
  "aria-haspopup": "listbox",
178
- "aria-controls": o ? Q : void 0,
213
+ "aria-controls": b ? j : void 0,
214
+ ...le,
179
215
  children: [
180
- /* @__PURE__ */ s("span", { className: f(e.triggerLabel, !O && e.placeholder), children: O || q }),
181
- /* @__PURE__ */ s("span", { className: f(e.arrow, e.arrowInline, u?.arrow) })
216
+ /* @__PURE__ */ s("span", { className: h(e.triggerLabel, !$ && e.placeholder), children: $ || I }),
217
+ /* @__PURE__ */ s("span", { className: h(e.arrow, e.arrowInline, o?.arrow) })
182
218
  ]
183
219
  }
184
220
  ),
185
- o && /* @__PURE__ */ s(
221
+ b && /* @__PURE__ */ s(
186
222
  "input",
187
223
  {
188
- ref: I,
224
+ ref: S,
225
+ id: y,
189
226
  type: "text",
190
227
  role: "combobox",
191
- className: f(
228
+ className: h(
192
229
  e.root,
193
230
  e.searchableTrigger,
194
- e[h],
231
+ e[u],
195
232
  e.triggerOpen,
196
- b && e.error,
197
- u?.root,
198
- u?.search
233
+ p && e.error,
234
+ o?.root,
235
+ o?.search
199
236
  ),
200
- placeholder: O || q,
201
- value: A,
202
- onChange: (r) => T(r.target.value),
203
- onKeyDown: E,
237
+ placeholder: $ || I,
238
+ value: U,
239
+ onChange: (r) => F(r.target.value),
240
+ onKeyDown: ee,
204
241
  "aria-expanded": !0,
205
242
  "aria-haspopup": "listbox",
206
- "aria-controls": Q,
207
- "aria-activedescendant": Y.length > 0 ? `select-option-${x[c]?.value}` : void 0
243
+ "aria-controls": j,
244
+ "aria-activedescendant": ce.length > 0 ? `select-option-${m[c]?.value}` : void 0,
245
+ "aria-label": Y["aria-labelledby"] || y ? void 0 : z,
246
+ ...Y
208
247
  }
209
248
  ),
210
- o && (() => {
211
- const r = N ? {
249
+ b && (() => {
250
+ const r = P ? {
212
251
  position: "fixed",
213
252
  top: K.top + 4,
214
253
  left: K.left,
215
254
  right: "auto",
216
255
  width: K.width,
217
256
  zIndex: "var(--crk-z-floating)"
218
- } : void 0, a = /* @__PURE__ */ s(
257
+ } : void 0, l = /* @__PURE__ */ s(
219
258
  "div",
220
259
  {
221
- id: Q,
222
- ref: R,
223
- className: f(e.menu, u?.menu),
260
+ id: j,
261
+ ref: D,
262
+ className: h(e.menu, o?.menu),
224
263
  style: r,
225
264
  role: "listbox",
226
- children: /* @__PURE__ */ s("div", { className: e.menuItems, ref: k, children: x.length === 0 ? /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }) : x.map((n, m) => /* @__PURE__ */ s(
265
+ children: /* @__PURE__ */ s("div", { className: e.menuItems, ref: C, children: m.length === 0 ? /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }) : m.map((n, w) => /* @__PURE__ */ s(
227
266
  "button",
228
267
  {
229
268
  id: `select-option-${n.value}`,
230
269
  type: "button",
231
270
  role: "option",
232
- "aria-selected": n.value === y,
233
- className: f(
271
+ "aria-selected": n.value === v,
272
+ className: h(
234
273
  e.item,
235
274
  n.disabled && e.itemDisabled,
236
- n.value === y && e.itemSelected,
237
- m === c && e.itemHighlighted,
238
- u?.item
275
+ n.value === v && e.itemSelected,
276
+ w === c && e.itemHighlighted,
277
+ o?.item
239
278
  ),
240
279
  disabled: n.disabled,
241
- onClick: () => J(n.value),
242
- onMouseEnter: () => d(m),
280
+ onClick: () => V(n.value),
281
+ onMouseEnter: () => d(w),
243
282
  children: n.content ?? n.label
244
283
  },
245
284
  n.value
246
285
  )) })
247
286
  }
248
287
  );
249
- return N && typeof document < "u" ? ie(a, document.body) : a;
288
+ return P && typeof document < "u" ? me(l, document.body) : l;
250
289
  })()
251
290
  ]
252
291
  }
253
292
  );
254
293
  }
255
294
  );
256
- ce.displayName = "SearchableSelect";
257
- const ue = ne(
295
+ ge.displayName = "SearchableSelect";
296
+ const ye = ie(
258
297
  ({
259
- inputSize: h = "md",
260
- error: b = !1,
261
- options: p = [],
262
- placeholder: q = "Select...",
263
- classes: u,
264
- className: W,
265
- style: B,
266
- value: y,
298
+ inputSize: u = "md",
299
+ error: p = !1,
300
+ options: f = [],
301
+ placeholder: I = "Select...",
302
+ classes: o,
303
+ className: E,
304
+ style: A,
305
+ value: v,
267
306
  disabled: g,
268
- id: ee,
269
- searchPlaceholder: te,
270
- onValuesChange: v,
271
- clearSearchOnSelect: L = !0,
272
- closeOnSelect: N = !0,
273
- allowCreate: M = !1,
274
- onCreate: o,
275
- createLabel: X,
276
- portal: A = !0
277
- }, T) => {
278
- const c = Array.isArray(y) ? y : y ? [y] : [], [d, j] = U(!1), [I, _] = U(""), [R, k] = U(0), Q = w(null), K = w(null), H = w(null), re = w(null), z = w(null), C = le(), G = se(z, d && A), J = w(null), x = (t) => {
279
- J.current = t, typeof T == "function" ? T(t) : T && (T.current = t);
280
- }, E = S(() => {
281
- j(!1), _(""), k(0);
282
- }, []), O = S(() => {
283
- g || (j(!0), _(""), k(0), setTimeout(() => K.current?.focus(), 0));
284
- }, [g]), Y = S(
307
+ id: y,
308
+ searchPlaceholder: z,
309
+ onValuesChange: x,
310
+ clearSearchOnSelect: O = !0,
311
+ closeOnSelect: P = !0,
312
+ allowCreate: G = !1,
313
+ onCreate: k,
314
+ createLabel: re,
315
+ portal: _ = !0,
316
+ onFocus: b,
317
+ onBlur: ne,
318
+ ...U
319
+ }, F) => {
320
+ const c = Array.isArray(v) ? v : v ? [v] : [], [d, H] = X(!1), [S, q] = X(""), [D, C] = X(0), j = N(null), K = N(null), J = N(null), le = N(null), Y = N(null), ae = de(), T = he(Y, d && _), { hidden: oe, control: Z } = ve(U), W = be(b, ne, [j, J]), se = N(null), V = (t) => {
321
+ se.current = t, typeof F == "function" ? F(t) : F && (F.current = t);
322
+ }, m = M(() => {
323
+ H(!1), q(""), C(0);
324
+ }, []), ee = M(() => {
325
+ g || (H(!0), q(""), C(0), setTimeout(() => K.current?.focus(), 0));
326
+ }, [g]), $ = M(
285
327
  (t) => {
286
- const i = c.includes(t) ? c.filter((l) => l !== t) : [...c, t];
287
- v?.(i), N ? E() : L && _("");
328
+ const i = c.includes(t) ? c.filter((a) => a !== t) : [...c, t];
329
+ x?.(i), P ? m() : O && q("");
288
330
  },
289
- [c, v, N, E, L]
290
- ), r = S(
331
+ [c, x, P, m, O]
332
+ ), ce = M(
291
333
  (t, i) => {
292
- i.stopPropagation(), v?.(c.filter((l) => l !== t));
334
+ i.stopPropagation(), x?.(c.filter((a) => a !== t));
293
335
  },
294
- [c, v]
295
- ), a = ae(() => {
296
- if (!I) return p;
297
- const t = I.toLowerCase();
298
- return p.filter((i) => i.label.toLowerCase().includes(t));
299
- }, [p, I]), n = I.trim(), m = M && n.length > 0 && !p.some(
300
- (t) => t.label.toLowerCase() === n.toLowerCase() || t.value === n
301
- ) && !c.includes(n), F = S(() => {
302
- n && (c.includes(n) || (o?.(n), v?.([...c, n]), N ? E() : L && _("")));
303
- }, [n, c, o, v, N, E, L]);
304
- $(() => {
305
- const t = a.findIndex((i) => !i.disabled);
306
- k(t >= 0 ? t : 0);
307
- }, [a]), $(() => {
336
+ [c, x]
337
+ ), r = fe(() => {
338
+ if (!S) return f;
339
+ const t = S.toLowerCase();
340
+ return f.filter((i) => i.label.toLowerCase().includes(t));
341
+ }, [f, S]), l = S.trim(), n = G && l.length > 0 && !f.some(
342
+ (t) => t.label.toLowerCase() === l.toLowerCase() || t.value === l
343
+ ) && !c.includes(l), w = M(() => {
344
+ l && (c.includes(l) || (k?.(l), x?.([...c, l]), P ? m() : O && q("")));
345
+ }, [l, c, k, x, P, m, O]);
346
+ B(() => {
347
+ const t = r.findIndex((i) => !i.disabled);
348
+ C(t >= 0 ? t : 0);
349
+ }, [r]), B(() => {
308
350
  if (!d) return;
309
- const t = re.current;
351
+ const t = le.current;
310
352
  if (!t) return;
311
- t.querySelectorAll('[role="option"]')[R]?.scrollIntoView?.({ block: "nearest" });
312
- }, [R, d]);
313
- const Z = a.length, de = S(
353
+ t.querySelectorAll('[role="option"]')[D]?.scrollIntoView?.({ block: "nearest" });
354
+ }, [D, d]);
355
+ const Q = r.length, we = M(
314
356
  (t) => {
315
- const i = a.map((l, D) => l.disabled ? -1 : D).filter((l) => l >= 0);
316
- if (m && i.push(Z), t.key === "Backspace" && I === "" && c.length > 0) {
317
- t.preventDefault(), v?.(c.slice(0, -1));
357
+ const i = r.map((a, L) => a.disabled ? -1 : L).filter((a) => a >= 0);
358
+ if (n && i.push(Q), t.key === "Backspace" && S === "" && c.length > 0) {
359
+ t.preventDefault(), x?.(c.slice(0, -1));
318
360
  return;
319
361
  }
320
- if (i.length !== 0)
362
+ if (t.key === "Escape") {
363
+ if (!d) return;
364
+ t.preventDefault(), m();
365
+ return;
366
+ }
367
+ if (i.length !== 0) {
321
368
  if (t.key === "ArrowDown") {
322
369
  if (t.preventDefault(), !d) {
323
- O();
370
+ ee();
324
371
  return;
325
372
  }
326
- k((l) => {
327
- const D = i.indexOf(l);
328
- return D < i.length - 1 ? i[D + 1] : i[0];
373
+ C((a) => {
374
+ const L = i.indexOf(a);
375
+ return L < i.length - 1 ? i[L + 1] : i[0];
329
376
  });
330
377
  } else if (t.key === "ArrowUp")
331
- t.preventDefault(), k((l) => {
332
- const D = i.indexOf(l);
333
- return D > 0 ? i[D - 1] : i[i.length - 1];
378
+ t.preventDefault(), C((a) => {
379
+ const L = i.indexOf(a);
380
+ return L > 0 ? i[L - 1] : i[i.length - 1];
334
381
  });
335
382
  else if (t.key === "Enter") {
336
- if (t.preventDefault(), m && R === Z) {
337
- F();
383
+ if (t.preventDefault(), n && D === Q) {
384
+ w();
338
385
  return;
339
386
  }
340
- const l = a[R];
341
- l && !l.disabled ? Y(l.value) : m && F();
342
- } else t.key === "Escape" && (t.preventDefault(), E());
387
+ const a = r[D];
388
+ a && !a.disabled ? $(a.value) : n && w();
389
+ }
390
+ }
343
391
  },
344
- [a, R, Y, E, I, c, v, d, O, m, F, Z]
392
+ [r, D, $, m, S, c, x, d, ee, n, w, Q]
345
393
  );
346
- $(() => {
394
+ B(() => {
347
395
  if (!d) return;
348
396
  const t = (i) => {
349
- const l = i.target;
350
- Q.current?.contains(l) || H.current?.contains(l) || E();
397
+ const a = i.target;
398
+ j.current?.contains(a) || J.current?.contains(a) || m();
351
399
  };
352
400
  return document.addEventListener("mousedown", t), () => document.removeEventListener("mousedown", t);
353
- }, [d, E]);
354
- const fe = c.map((t) => p.find((l) => l.value === t) ?? { value: t, label: t });
355
- return /* @__PURE__ */ P(
401
+ }, [d, m]);
402
+ const ue = c.map((t) => f.find((a) => a.value === t) ?? { value: t, label: t });
403
+ return /* @__PURE__ */ R(
356
404
  "div",
357
405
  {
358
- ref: Q,
359
- className: f(
406
+ ref: j,
407
+ className: h(
360
408
  e.wrapper,
361
409
  e.searchableWrapper,
362
- e[h],
363
- b && e.error,
410
+ e[u],
411
+ p && e.error,
364
412
  g && e.disabled,
365
- u?.wrapper,
366
- W
413
+ o?.wrapper,
414
+ E
367
415
  ),
368
- style: B,
416
+ style: A,
417
+ ...W,
369
418
  children: [
370
- /* @__PURE__ */ s(
419
+ /* @__PURE__ */ R(
371
420
  "select",
372
421
  {
373
- ref: x,
422
+ ref: V,
374
423
  className: e.hiddenSelect,
375
424
  multiple: !0,
376
425
  value: c,
@@ -379,37 +428,41 @@ const ue = ne(
379
428
  "aria-hidden": "true",
380
429
  onChange: () => {
381
430
  },
382
- children: p.map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value))
431
+ ...oe,
432
+ children: [
433
+ f.map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value)),
434
+ ue.filter((t) => !f.some((i) => i.value === t.value)).map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value))
435
+ ]
383
436
  }
384
437
  ),
385
- /* @__PURE__ */ P(
438
+ /* @__PURE__ */ R(
386
439
  "div",
387
440
  {
388
- ref: z,
389
- className: f(
441
+ ref: Y,
442
+ className: h(
390
443
  e.multiTrigger,
391
- e[h],
444
+ e[u],
392
445
  d && e.triggerOpen,
393
- b && e.error,
446
+ p && e.error,
394
447
  g && e.multiTriggerDisabled,
395
- u?.root
448
+ o?.root
396
449
  ),
397
450
  onClick: () => {
398
- d ? K.current?.focus() : O();
451
+ d ? K.current?.focus() : ee();
399
452
  },
400
453
  role: "combobox",
401
454
  "aria-expanded": d,
402
455
  "aria-haspopup": "listbox",
403
- "aria-controls": d ? C : void 0,
456
+ "aria-controls": d ? ae : void 0,
404
457
  children: [
405
- fe.map((t) => /* @__PURE__ */ P("span", { className: f(e.chip, u?.chip), children: [
458
+ ue.map((t) => /* @__PURE__ */ R("span", { className: h(e.chip, o?.chip), children: [
406
459
  /* @__PURE__ */ s("span", { className: e.chipLabel, children: t.content ?? t.label }),
407
460
  /* @__PURE__ */ s(
408
461
  "button",
409
462
  {
410
463
  type: "button",
411
- className: f(e.chipRemove, u?.chipRemove),
412
- onClick: (i) => r(t.value, i),
464
+ className: h(e.chipRemove, o?.chipRemove),
465
+ onClick: (i) => ce(t.value, i),
413
466
  "aria-label": `Remove ${t.label}`,
414
467
  tabIndex: -1,
415
468
  children: "×"
@@ -420,85 +473,87 @@ const ue = ne(
420
473
  "input",
421
474
  {
422
475
  ref: K,
423
- id: ee,
476
+ id: y,
424
477
  type: "text",
425
478
  className: e.multiSearch,
426
- placeholder: c.length === 0 ? q : "",
427
- value: I,
479
+ placeholder: c.length === 0 ? I : "",
480
+ value: S,
428
481
  onChange: (t) => {
429
- _(t.target.value), d || O();
482
+ q(t.target.value), d || H(!0);
430
483
  },
431
- onKeyDown: de,
484
+ onKeyDown: we,
432
485
  disabled: g,
433
- "aria-label": "Search options"
486
+ "aria-label": Z["aria-labelledby"] ? void 0 : "Search options",
487
+ ...Z
434
488
  }
435
489
  ),
436
- /* @__PURE__ */ s("span", { className: f(e.arrow, e.arrowMulti, u?.arrow) })
490
+ /* @__PURE__ */ s("span", { className: h(e.arrow, e.arrowMulti, o?.arrow) })
437
491
  ]
438
492
  }
439
493
  ),
440
494
  d && (() => {
441
- const t = A ? {
495
+ const t = _ ? {
442
496
  position: "fixed",
443
- top: G.top + 4,
444
- left: G.left,
497
+ top: T.top + 4,
498
+ left: T.left,
445
499
  right: "auto",
446
- width: G.width,
500
+ width: T.width,
447
501
  zIndex: "var(--crk-z-floating)"
448
502
  } : void 0, i = /* @__PURE__ */ s(
449
503
  "div",
450
504
  {
451
- id: C,
452
- ref: H,
453
- className: f(e.menu, u?.menu),
505
+ id: ae,
506
+ ref: J,
507
+ className: h(e.menu, o?.menu),
454
508
  style: t,
455
509
  role: "listbox",
456
510
  "aria-multiselectable": "true",
457
- children: /* @__PURE__ */ P("div", { className: e.menuItems, ref: re, children: [
458
- a.length === 0 && !m && /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }),
459
- a.map((l, D) => {
460
- const V = c.includes(l.value);
461
- return /* @__PURE__ */ P(
511
+ onMouseDown: (a) => a.preventDefault(),
512
+ children: /* @__PURE__ */ R("div", { className: e.menuItems, ref: le, children: [
513
+ r.length === 0 && !n && /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }),
514
+ r.map((a, L) => {
515
+ const te = c.includes(a.value);
516
+ return /* @__PURE__ */ R(
462
517
  "button",
463
518
  {
464
- id: `select-option-${l.value}`,
519
+ id: `select-option-${a.value}`,
465
520
  type: "button",
466
521
  role: "option",
467
- "aria-selected": V,
468
- className: f(
522
+ "aria-selected": te,
523
+ className: h(
469
524
  e.item,
470
- l.disabled && e.itemDisabled,
471
- V && e.itemSelected,
472
- D === R && e.itemHighlighted,
473
- u?.item
525
+ a.disabled && e.itemDisabled,
526
+ te && e.itemSelected,
527
+ L === D && e.itemHighlighted,
528
+ o?.item
474
529
  ),
475
- disabled: l.disabled,
476
- onClick: () => Y(l.value),
477
- onMouseEnter: () => k(D),
530
+ disabled: a.disabled,
531
+ onClick: () => $(a.value),
532
+ onMouseEnter: () => C(L),
478
533
  children: [
479
- V && /* @__PURE__ */ s("span", { className: e.itemCheck, "aria-hidden": "true" }),
480
- l.content ?? l.label
534
+ te && /* @__PURE__ */ s("span", { className: e.itemCheck, "aria-hidden": "true" }),
535
+ a.content ?? a.label
481
536
  ]
482
537
  },
483
- l.value
538
+ a.value
484
539
  );
485
540
  }),
486
- m && /* @__PURE__ */ s(
541
+ n && /* @__PURE__ */ s(
487
542
  "button",
488
543
  {
489
544
  type: "button",
490
545
  role: "option",
491
546
  "aria-selected": !1,
492
- className: f(
547
+ className: h(
493
548
  e.item,
494
- R === Z && e.itemHighlighted,
495
- u?.item
549
+ D === Q && e.itemHighlighted,
550
+ o?.item
496
551
  ),
497
- onClick: F,
498
- onMouseEnter: () => k(Z),
499
- children: X ? X(n) : /* @__PURE__ */ P(me, { children: [
552
+ onClick: w,
553
+ onMouseEnter: () => C(Q),
554
+ children: re ? re(l) : /* @__PURE__ */ R(xe, { children: [
500
555
  "Create “",
501
- /* @__PURE__ */ s("strong", { children: n }),
556
+ /* @__PURE__ */ s("strong", { children: l }),
502
557
  "”"
503
558
  ] })
504
559
  },
@@ -507,18 +562,18 @@ const ue = ne(
507
562
  ] })
508
563
  }
509
564
  );
510
- return A && typeof document < "u" ? ie(i, document.body) : i;
565
+ return _ && typeof document < "u" ? me(i, document.body) : i;
511
566
  })()
512
567
  ]
513
568
  }
514
569
  );
515
570
  }
516
571
  );
517
- ue.displayName = "MultiSelect";
518
- const he = ne(
519
- (h, b) => h.multiple ? /* @__PURE__ */ s(ue, { ref: b, ...h }) : h.searchable ? /* @__PURE__ */ s(ce, { ref: b, ...h }) : /* @__PURE__ */ s(oe, { ref: b, ...h })
572
+ ye.displayName = "MultiSelect";
573
+ const Ne = ie(
574
+ (u, p) => u.multiple ? /* @__PURE__ */ s(ye, { ref: p, ...u }) : u.searchable ? /* @__PURE__ */ s(ge, { ref: p, ...u }) : /* @__PURE__ */ s(pe, { ref: p, ...u })
520
575
  );
521
- he.displayName = "Select";
576
+ Ne.displayName = "Select";
522
577
  export {
523
- he as Select
578
+ Ne as Select
524
579
  };