@overdoser/react-toolkit 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/AGENTS.md +2 -1
  2. package/CHANGELOG.md +41 -0
  3. package/components/Accordion/Accordion.js +160 -177
  4. package/components/Accordion/Accordion.module.scss.js +19 -35
  5. package/components/ActionButton/ActionButton.js +155 -209
  6. package/components/ActionButton/ActionButton.module.scss.js +24 -46
  7. package/components/ActionButton/CopyButton.js +52 -64
  8. package/components/Alert/Alert.js +93 -96
  9. package/components/Alert/Alert.module.scss.js +17 -32
  10. package/components/Avatar/Avatar.js +44 -55
  11. package/components/Avatar/Avatar.module.scss.js +22 -42
  12. package/components/Badge/Badge.js +15 -37
  13. package/components/Badge/Badge.module.scss.js +16 -30
  14. package/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  15. package/components/Breadcrumbs/Breadcrumbs.js +52 -48
  16. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +9 -16
  17. package/components/Button/Button.js +35 -57
  18. package/components/Button/Button.module.scss.js +24 -46
  19. package/components/Card/Card.js +94 -131
  20. package/components/Card/Card.module.scss.js +34 -59
  21. package/components/Chart/AreaChart.d.ts +1 -1
  22. package/components/Chart/AreaChart.js +248 -249
  23. package/components/Chart/Axis.d.ts +2 -2
  24. package/components/Chart/Axis.js +34 -43
  25. package/components/Chart/BarChart.d.ts +1 -1
  26. package/components/Chart/BarChart.js +307 -348
  27. package/components/Chart/Chart.module.scss.js +31 -60
  28. package/components/Chart/ChartContainer.js +33 -41
  29. package/components/Chart/ChartLegend.d.ts +1 -1
  30. package/components/Chart/ChartLegend.js +31 -30
  31. package/components/Chart/ChartTooltip.d.ts +1 -1
  32. package/components/Chart/ChartTooltip.js +45 -40
  33. package/components/Chart/LineChart.d.ts +1 -1
  34. package/components/Chart/LineChart.js +220 -232
  35. package/components/Chart/PieChart.d.ts +1 -1
  36. package/components/Chart/PieChart.js +224 -240
  37. package/components/Chart/RadarChart.d.ts +1 -1
  38. package/components/Chart/RadarChart.js +166 -215
  39. package/components/Chart/Sparkline.js +73 -68
  40. package/components/Chart/TradingChart.d.ts +1 -1
  41. package/components/Chart/TradingChart.js +804 -701
  42. package/components/Chart/scales.js +28 -35
  43. package/components/Chart/trading/indicators.js +61 -62
  44. package/components/Chart/trading/period.js +46 -68
  45. package/components/Chart/useChartDimensions.js +30 -22
  46. package/components/Chip/Chip.js +98 -141
  47. package/components/Chip/Chip.module.scss.js +31 -58
  48. package/components/CodeBlock/CodeBlock.js +111 -119
  49. package/components/CodeBlock/CodeBlock.module.scss.js +22 -42
  50. package/components/CommandPalette/CommandPalette.js +387 -392
  51. package/components/CommandPalette/CommandPalette.module.scss.js +27 -48
  52. package/components/ConfirmDialog/ConfirmDialog.d.ts +1 -1
  53. package/components/ConfirmDialog/ConfirmDialog.js +184 -199
  54. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +11 -20
  55. package/components/Divider/Divider.js +25 -36
  56. package/components/Divider/Divider.module.scss.js +16 -30
  57. package/components/Draggable/Draggable.d.ts +1 -1
  58. package/components/Draggable/Draggable.js +157 -164
  59. package/components/Draggable/Draggable.module.scss.js +9 -16
  60. package/components/Drawer/Drawer.js +104 -126
  61. package/components/Drawer/Drawer.module.scss.js +65 -118
  62. package/components/Dropdown/Dropdown.js +175 -234
  63. package/components/Dropdown/Dropdown.module.scss.js +28 -52
  64. package/components/Dropdown/DropdownItem.js +55 -58
  65. package/components/Dropdown/DropdownLabel.js +14 -11
  66. package/components/Dropdown/DropdownSeparator.js +13 -11
  67. package/components/Dropdown/dropdownContext.js +4 -5
  68. package/components/Dropdown/useContextMenu.js +27 -17
  69. package/components/Dropzone/Dropzone.js +99 -105
  70. package/components/Dropzone/Dropzone.module.scss.js +11 -20
  71. package/components/EmptyState/EmptyState.js +57 -54
  72. package/components/EmptyState/EmptyState.module.scss.js +13 -24
  73. package/components/Form/Form.d.ts +1 -1
  74. package/components/Form/Form.js +31 -34
  75. package/components/Form/Form.module.scss.js +15 -28
  76. package/components/Form/FormField.d.ts +1 -1
  77. package/components/Form/FormField.js +71 -75
  78. package/components/Form/FormRow.d.ts +1 -1
  79. package/components/Form/FormRow.js +11 -8
  80. package/components/Form/formFieldDefaults.js +4 -5
  81. package/components/ImageViewer/ImageViewer.js +312 -201
  82. package/components/ImageViewer/ImageViewer.module.scss.js +25 -46
  83. package/components/ImageViewer/useZoomPan.js +206 -137
  84. package/components/Kbd/Kbd.js +24 -21
  85. package/components/Kbd/Kbd.module.scss.js +9 -16
  86. package/components/KeyValueList/KeyValueList.js +119 -123
  87. package/components/KeyValueList/KeyValueList.module.scss.js +22 -42
  88. package/components/Link/Link.js +45 -59
  89. package/components/Link/Link.module.scss.js +9 -15
  90. package/components/List/List.js +22 -46
  91. package/components/List/List.module.scss.js +11 -20
  92. package/components/Loader/Loader.js +152 -182
  93. package/components/Loader/Loader.module.scss.js +39 -69
  94. package/components/Modal/Modal.js +93 -105
  95. package/components/Modal/Modal.module.scss.js +17 -32
  96. package/components/PageHeader/PageHeader.js +79 -73
  97. package/components/PageHeader/PageHeader.module.scss.js +22 -42
  98. package/components/Pagination/Pagination.js +62 -83
  99. package/components/Pagination/Pagination.module.scss.js +12 -22
  100. package/components/Pagination/paginationRange.js +15 -22
  101. package/components/Popover/Popover.js +110 -134
  102. package/components/Popover/Popover.module.scss.js +11 -20
  103. package/components/ProgressBar/ProgressBar.d.ts +15 -1
  104. package/components/ProgressBar/ProgressBar.js +56 -89
  105. package/components/ProgressBar/ProgressBar.module.scss.js +28 -50
  106. package/components/RelativeTime/RelativeTime.js +36 -43
  107. package/components/RelativeTime/RelativeTime.module.scss.js +3 -7
  108. package/components/SegmentedControl/SegmentedControl.js +93 -129
  109. package/components/SegmentedControl/SegmentedControl.module.scss.js +20 -38
  110. package/components/Skeleton/Skeleton.js +36 -50
  111. package/components/Skeleton/Skeleton.module.scss.js +14 -24
  112. package/components/Spinner/Spinner.js +25 -25
  113. package/components/Spinner/Spinner.module.scss.js +11 -19
  114. package/components/SplitButton/SplitButton.js +149 -196
  115. package/components/SplitButton/SplitButton.module.scss.js +30 -56
  116. package/components/SplitPane/SplitPane.js +134 -170
  117. package/components/SplitPane/SplitPane.module.scss.js +13 -24
  118. package/components/StatCard/StatCard.js +132 -125
  119. package/components/StatCard/StatCard.module.scss.js +41 -71
  120. package/components/StatusDot/StatusDot.js +28 -39
  121. package/components/StatusDot/StatusDot.module.scss.js +17 -31
  122. package/components/Table/Table.d.ts +1 -1
  123. package/components/Table/Table.js +381 -451
  124. package/components/Table/Table.module.scss.js +41 -80
  125. package/components/Table/useTableSort.js +51 -42
  126. package/components/Tabs/Tabs.js +109 -161
  127. package/components/Tabs/Tabs.module.scss.js +27 -52
  128. package/components/ThemeToggle/ThemeToggle.js +122 -98
  129. package/components/ThemeToggle/ThemeToggle.module.scss.js +12 -22
  130. package/components/Timeline/GanttTimeline.js +357 -318
  131. package/components/Timeline/GanttTimeline.module.scss.js +28 -54
  132. package/components/Timeline/HistoryTimeline.js +486 -450
  133. package/components/Timeline/HistoryTimeline.module.scss.js +30 -58
  134. package/components/Timeline/Timeline.module.scss.js +75 -140
  135. package/components/Timeline/TimelineShared.d.ts +7 -7
  136. package/components/Timeline/TimelineShared.js +288 -279
  137. package/components/Timeline/TraceEventDetails.d.ts +3 -3
  138. package/components/Timeline/TraceEventDetails.js +244 -177
  139. package/components/Timeline/TraceTimeline.js +823 -783
  140. package/components/Timeline/TraceTimeline.module.scss.js +97 -188
  141. package/components/Timeline/historyLayout.js +336 -263
  142. package/components/Timeline/timelineCore.js +208 -183
  143. package/components/Timeline/traceEvent.js +59 -61
  144. package/components/Timeline/traceLayout.js +101 -90
  145. package/components/Timeline/useTimeline.js +76 -79
  146. package/components/Timer/Timer.js +190 -156
  147. package/components/Timer/Timer.module.scss.js +28 -54
  148. package/components/Toast/Toast.d.ts +1 -1
  149. package/components/Toast/Toast.js +128 -128
  150. package/components/Toast/Toast.module.scss.js +36 -61
  151. package/components/Toast/toastStore.js +58 -62
  152. package/components/ToggleIconButton/ToggleIconButton.js +36 -58
  153. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +14 -26
  154. package/components/Tooltip/Tooltip.d.ts +1 -1
  155. package/components/Tooltip/Tooltip.js +76 -85
  156. package/components/Tooltip/Tooltip.module.scss.js +16 -29
  157. package/components/Typography/Typography.js +10 -35
  158. package/components/Typography/Typography.module.scss.js +29 -52
  159. package/components/inputs/Checkbox/Checkbox.js +27 -51
  160. package/components/inputs/Checkbox/Checkbox.module.scss.js +9 -16
  161. package/components/inputs/Checkbox/CheckboxGroup.js +53 -111
  162. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +16 -30
  163. package/components/inputs/DatePicker/CalendarPanel.d.ts +1 -1
  164. package/components/inputs/DatePicker/CalendarPanel.js +263 -286
  165. package/components/inputs/DatePicker/CalendarPanel.module.scss.js +22 -40
  166. package/components/inputs/DatePicker/DatePicker.js +115 -142
  167. package/components/inputs/DatePicker/DatePicker.module.scss.js +13 -24
  168. package/components/inputs/DatePicker/dateUtils.js +32 -41
  169. package/components/inputs/DateTimePicker/DateTimePicker.js +226 -232
  170. package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +19 -36
  171. package/components/inputs/DateTimePicker/DateTimeSegments.js +273 -252
  172. package/components/inputs/DateTimePicker/TimeField.d.ts +1 -1
  173. package/components/inputs/DateTimePicker/TimeField.js +131 -132
  174. package/components/inputs/DateTimePicker/timeZoneUtils.js +95 -92
  175. package/components/inputs/Input/Input.js +98 -109
  176. package/components/inputs/Input/Input.module.scss.js +14 -26
  177. package/components/inputs/NumberInput/NumberInput.js +112 -132
  178. package/components/inputs/NumberInput/NumberInput.module.scss.js +13 -24
  179. package/components/inputs/Radio/Radio.js +50 -73
  180. package/components/inputs/Radio/Radio.module.scss.js +8 -14
  181. package/components/inputs/SearchInput/SearchInput.js +98 -115
  182. package/components/inputs/SearchInput/SearchInput.module.scss.js +7 -12
  183. package/components/inputs/Select/Select.d.ts +55 -3
  184. package/components/inputs/Select/Select.js +696 -682
  185. package/components/inputs/Select/Select.module.scss.js +49 -72
  186. package/components/inputs/Slider/Slider.js +97 -128
  187. package/components/inputs/Slider/Slider.module.scss.js +8 -14
  188. package/components/inputs/Switch/Switch.js +11 -8
  189. package/components/inputs/Textarea/Textarea.js +42 -58
  190. package/components/inputs/Textarea/Textarea.module.scss.js +13 -24
  191. package/hooks/useClickOutside.js +17 -14
  192. package/hooks/useDebouncedValue.js +13 -14
  193. package/hooks/useElementSize.js +27 -22
  194. package/hooks/useEscapeLayer.js +28 -29
  195. package/hooks/useFocusTrap.js +27 -38
  196. package/hooks/useKeyboard.js +76 -64
  197. package/hooks/useMediaQuery.js +10 -15
  198. package/hooks/useNow.js +28 -33
  199. package/hooks/usePersistedState.js +98 -94
  200. package/hooks/usePortalPosition.d.ts +2 -1
  201. package/hooks/usePortalPosition.js +28 -19
  202. package/hooks/useResizable.js +106 -104
  203. package/hooks/useTheme.js +28 -23
  204. package/index.css +2 -1
  205. package/index.js +96 -214
  206. package/index.layered.css +2 -3
  207. package/llms.txt +28 -4
  208. package/manifest.json +41 -4
  209. package/package.json +1 -1
  210. package/utils/formatBytes.js +29 -13
  211. package/utils/themeScript.js +6 -8
  212. package/utils/timeAgo.js +59 -32
@@ -1,688 +1,702 @@
1
- import { jsx as c, jsxs as k, Fragment as De } from "react/jsx-runtime";
2
- import { forwardRef as Ne, useState as ae, useRef as y, useId as Ee, useCallback as A, useEffect as B, useMemo as $e } from "react";
3
- import { createPortal as Le } from "react-dom";
4
- import f from "clsx";
5
- import t from "./Select.module.scss.js";
6
- import { usePortalPosition as Me } from "../../../hooks/usePortalPosition.js";
7
- import { Spinner as Oe } from "../../Spinner/Spinner.js";
8
- const Pe = Ne(
9
- ({
10
- inputSize: n = "md",
11
- error: a = !1,
12
- options: d,
13
- placeholder: m,
14
- classes: r,
15
- className: _,
16
- style: R,
17
- children: u,
18
- searchable: v,
19
- searchPlaceholder: w,
20
- // Custom-mode-only props. Swallowed here so they never reach the DOM
21
- // `<select>` (React warns on unknown handlers / non-boolean attributes).
22
- // `FormField` always injects `onValuesChange`, so this path is hot.
23
- onValuesChange: _e,
24
- clearSearchOnSelect: C,
25
- closeOnSelect: j,
26
- allowCreate: F,
27
- onCreate: fe,
28
- createLabel: oe,
29
- portal: G,
30
- onSearch: J,
31
- searchDebounce: Y,
32
- minSearchLength: me,
33
- searchPrompt: K,
34
- loading: he,
35
- loadingMessage: Z,
36
- noResultsMessage: pe,
37
- highlightMatches: q,
38
- selectedLabels: ke,
39
- onChange: ie,
40
- onValueChange: se,
41
- ...be
42
- }, Re) => {
43
- const Ce = ie || se ? (H) => {
44
- ie?.(H), se?.(H.target.value);
45
- } : void 0;
46
- return /* @__PURE__ */ k("div", { className: f(t.wrapper, t[n], a && t.error, r?.wrapper, _), style: R, children: [
47
- /* @__PURE__ */ k(
48
- "select",
49
- {
50
- ref: Re,
51
- className: f(t.root, t[n], a && t.error, r?.root),
52
- onChange: Ce,
53
- ...be,
54
- children: [
55
- m && /* @__PURE__ */ c("option", { value: "", disabled: !0, children: m }),
56
- d ? d.map((H) => /* @__PURE__ */ c("option", { value: H.value, disabled: H.disabled, children: H.label }, H.value)) : u
57
- ]
58
- }
59
- ),
60
- /* @__PURE__ */ c("span", { className: f(t.arrow, r?.arrow) })
61
- ] });
62
- }
63
- );
64
- Pe.displayName = "NativeSelect";
65
- function Te(n) {
66
- const { name: a, form: d, required: m, title: r, autoFocus: _, tabIndex: R } = n, u = { title: r, autoFocus: _, tabIndex: R };
67
- m && (u["aria-required"] = !0);
68
- for (const w of Object.keys(n))
69
- (w.startsWith("aria-") || w.startsWith("data-")) && (u[w] = n[w]);
70
- const v = {};
71
- for (const w of Object.keys(u))
72
- w.startsWith("aria-") && (v[w] = u[w]);
73
- return { hidden: { name: a, form: d }, control: u, aria: v };
1
+ import { forwardRef as e, useCallback as t, useEffect as n, useId as r, useMemo as i, useRef as a, useState as o } from "react";
2
+ import { createPortal as s } from "react-dom";
3
+ import c from "clsx";
4
+ import l from "./Select.module.scss.js";
5
+ import { usePortalPosition as ee } from "../../../hooks/usePortalPosition.js";
6
+ import { Spinner as te } from "../../Spinner/Spinner.js";
7
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
8
+ // src/components/inputs/Select/Select.tsx
9
+ var p = e(({ inputSize: e = "md", error: t = !1, options: n, placeholder: r, classes: i, className: a, style: o, children: s, searchable: ee, searchPlaceholder: te, onValuesChange: u, clearSearchOnSelect: p, closeOnSelect: ne, allowCreate: re, onCreate: ie, createLabel: ae, portal: oe, onSearch: se, searchDebounce: ce, minSearchLength: m, searchPrompt: le, loading: ue, loadingMessage: h, noResultsMessage: g, highlightMatches: _, selectedLabels: v, checklist: de, selectAllLabel: fe, deselectAllLabel: y, maxVisibleChips: b, moreChipsLabel: pe, onChange: x, onValueChange: S, ...C }, me) => {
10
+ let he = x || S ? (e) => {
11
+ x?.(e), S?.(e.target.value);
12
+ } : void 0;
13
+ return /* @__PURE__ */ f("div", {
14
+ className: c(l.wrapper, l[e], t && l.error, i?.wrapper, a),
15
+ style: o,
16
+ children: [/* @__PURE__ */ f("select", {
17
+ ref: me,
18
+ className: c(l.root, l[e], t && l.error, i?.root),
19
+ onChange: he,
20
+ ...C,
21
+ children: [r && /* @__PURE__ */ d("option", {
22
+ value: "",
23
+ disabled: !0,
24
+ children: r
25
+ }), n ? n.map((e) => /* @__PURE__ */ d("option", {
26
+ value: e.value,
27
+ disabled: e.disabled,
28
+ children: e.label
29
+ }, e.value)) : s]
30
+ }), /* @__PURE__ */ d("span", { className: c(l.arrow, i?.arrow) })]
31
+ });
32
+ });
33
+ p.displayName = "NativeSelect";
34
+ function ne(e) {
35
+ let { name: t, form: n, required: r, title: i, autoFocus: a, tabIndex: o } = e, s = {
36
+ title: i,
37
+ autoFocus: a,
38
+ tabIndex: o
39
+ };
40
+ r && (s["aria-required"] = !0);
41
+ for (let t of Object.keys(e)) (t.startsWith("aria-") || t.startsWith("data-")) && (s[t] = e[t]);
42
+ let c = {};
43
+ for (let e of Object.keys(s)) e.startsWith("aria-") && (c[e] = s[e]);
44
+ return {
45
+ hidden: {
46
+ name: t,
47
+ form: n
48
+ },
49
+ control: s,
50
+ aria: c
51
+ };
74
52
  }
75
- function Ae(n, a, d) {
76
- const m = y(!1);
77
- return {
78
- onFocus: (r) => {
79
- m.current || (m.current = !0, n?.(r));
80
- },
81
- onBlur: (r) => {
82
- const _ = r.relatedTarget;
83
- _ && d.some((R) => R.current?.contains(_)) || (m.current = !1, a?.(r));
84
- }
85
- };
53
+ function re(e, t, n) {
54
+ let r = a(!1);
55
+ return {
56
+ onFocus: (t) => {
57
+ r.current || (r.current = !0, e?.(t));
58
+ },
59
+ onBlur: (e) => {
60
+ let i = e.relatedTarget;
61
+ i && n.some((e) => e.current?.contains(i)) || (r.current = !1, t?.(e));
62
+ }
63
+ };
86
64
  }
87
- function Fe(n, a, d, m, r) {
88
- const _ = y(n);
89
- _.current = n;
90
- const R = y(null), u = !!n;
91
- B(() => {
92
- if (!u || !d || a.length < r) return;
93
- const v = () => {
94
- R.current !== a && (R.current = a, _.current?.(a));
95
- };
96
- if (m <= 0 || a === "") {
97
- v();
98
- return;
99
- }
100
- const w = setTimeout(v, m);
101
- return () => clearTimeout(w);
102
- }, [u, d, a, m, r]);
65
+ function ie(e, t, r, i, o) {
66
+ let s = a(e);
67
+ s.current = e;
68
+ let c = a(null), l = !!e;
69
+ n(() => {
70
+ if (!l || !r || t.length < o) return;
71
+ let e = () => {
72
+ c.current !== t && (c.current = t, s.current?.(t));
73
+ };
74
+ if (i <= 0 || t === "") {
75
+ e();
76
+ return;
77
+ }
78
+ let n = setTimeout(e, i);
79
+ return () => clearTimeout(n);
80
+ }, [
81
+ l,
82
+ r,
83
+ t,
84
+ i,
85
+ o
86
+ ]);
103
87
  }
104
- function He(n, a, d) {
105
- return $e(() => {
106
- if (d || !a) return n;
107
- const m = a.toLowerCase();
108
- return n.filter((r) => r.label.toLowerCase().includes(m));
109
- }, [n, a, d]);
88
+ function ae(e, t, n) {
89
+ return i(() => {
90
+ if (n || !t) return e;
91
+ let r = t.toLowerCase();
92
+ return e.filter((e) => e.label.toLowerCase().includes(r));
93
+ }, [
94
+ e,
95
+ t,
96
+ n
97
+ ]);
110
98
  }
111
- function We(n, a, d, m) {
112
- if (n.content !== void 0) return n.content;
113
- if (!d || !a) return n.label;
114
- const r = n.label.toLowerCase().indexOf(a.toLowerCase());
115
- return r < 0 ? n.label : /* @__PURE__ */ k(De, { children: [
116
- n.label.slice(0, r),
117
- /* @__PURE__ */ c("mark", { className: f(t.match, m), children: n.label.slice(r, r + a.length) }),
118
- n.label.slice(r + a.length)
119
- ] });
99
+ function oe(e, t) {
100
+ return `${e}-opt-${t}`;
120
101
  }
121
- function je(n) {
122
- return n.loading ? n.loadingMessage : n.remote && n.query.length < n.minSearchLength ? n.searchPrompt : n.empty ? n.noResultsMessage : null;
102
+ function se(e, t, n, r) {
103
+ if (e.content !== void 0) return e.content;
104
+ if (!n || !t) return e.label;
105
+ let i = e.label.toLowerCase().indexOf(t.toLowerCase());
106
+ return i < 0 ? e.label : /* @__PURE__ */ f(u, { children: [
107
+ e.label.slice(0, i),
108
+ /* @__PURE__ */ d("mark", {
109
+ className: c(l.match, r),
110
+ children: e.label.slice(i, i + t.length)
111
+ }),
112
+ e.label.slice(i + t.length)
113
+ ] });
123
114
  }
124
- const Be = Ne(
125
- ({
126
- inputSize: n = "md",
127
- error: a = !1,
128
- options: d = [],
129
- placeholder: m = "Select...",
130
- classes: r,
131
- className: _,
132
- style: R,
133
- value: u,
134
- disabled: v,
135
- id: w,
136
- searchPlaceholder: _e = "Search...",
137
- onChange: C,
138
- onValueChange: j,
139
- portal: F = !0,
140
- onFocus: fe,
141
- onBlur: oe,
142
- onSearch: G,
143
- searchDebounce: J = 250,
144
- minSearchLength: Y = 0,
145
- searchPrompt: me = "Type to search",
146
- loading: K = !1,
147
- loadingMessage: he = "Loading…",
148
- noResultsMessage: Z = "No results",
149
- highlightMatches: pe = !1,
150
- selectedLabels: q,
151
- // Multi-only props: not spread onto the DOM.
152
- multiple: ke,
153
- onValuesChange: ie,
154
- clearSearchOnSelect: se,
155
- closeOnSelect: be,
156
- allowCreate: Re,
157
- onCreate: Ce,
158
- createLabel: H,
159
- ...Ie
160
- }, ee) => {
161
- const O = !!G, [b, g] = ae(!1), [h, $] = ae(""), S = K || O && h.length < Y, [I, W] = ae(0), D = y(null), P = y(null), te = y(null), Q = y(null), ne = y(null), re = Ee(), le = Me(D, b && F), { hidden: ge, control: ce, aria: ve } = Te(Ie), we = Ae(fe, oe, [D, Q]), z = y(null), Se = (l) => {
162
- z.current = l, typeof ee == "function" ? ee(l) : ee && (ee.current = l);
163
- }, ye = y(!1);
164
- B(() => {
165
- ye.current && !b && te.current?.focus(), ye.current = b;
166
- }, [b]);
167
- const x = A(() => {
168
- g(!1), $(""), W(0);
169
- }, []), ue = A(() => {
170
- v || (g(!0), $(""), W(0), setTimeout(() => P.current?.focus(), 0));
171
- }, [v]), U = A(
172
- (l) => {
173
- if (j?.(l), z.current) {
174
- Object.getOwnPropertyDescriptor(
175
- HTMLSelectElement.prototype,
176
- "value"
177
- )?.set?.call(z.current, l);
178
- const s = new Event("change", { bubbles: !0 });
179
- z.current.dispatchEvent(s), C?.(s);
180
- }
181
- x();
182
- },
183
- [j, C, z, x]
184
- ), L = He(d, h, O);
185
- Fe(G, h, b, J, Y), B(() => {
186
- const l = L.findIndex((p) => !p.disabled);
187
- W(l >= 0 ? l : 0);
188
- }, [L]), B(() => {
189
- if (!b) return;
190
- const l = ne.current;
191
- if (!l) return;
192
- l.querySelectorAll('[role="option"]')[I]?.scrollIntoView?.({ block: "nearest" });
193
- }, [I, b]);
194
- const T = A(
195
- (l) => {
196
- const p = L.map((s, e) => s.disabled ? -1 : e).filter((s) => s >= 0);
197
- if (l.key === "Escape") {
198
- l.preventDefault(), x();
199
- return;
200
- }
201
- if (p.length !== 0) {
202
- if (l.key === "ArrowDown")
203
- l.preventDefault(), W((s) => {
204
- const e = p.indexOf(s);
205
- return e < p.length - 1 ? p[e + 1] : p[0];
206
- });
207
- else if (l.key === "ArrowUp")
208
- l.preventDefault(), W((s) => {
209
- const e = p.indexOf(s);
210
- return e > 0 ? p[e - 1] : p[p.length - 1];
211
- });
212
- else if (l.key === "Enter") {
213
- if (l.preventDefault(), S) return;
214
- const s = L[I];
215
- s && !s.disabled && U(s.value);
216
- }
217
- }
218
- },
219
- [L, I, U, x, S]
220
- );
221
- B(() => {
222
- if (!b) return;
223
- const l = (p) => {
224
- const s = p.target;
225
- D.current?.contains(s) || Q.current?.contains(s) || x();
226
- };
227
- return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
228
- }, [b, x]);
229
- const N = d.find((l) => l.value === u), M = N?.label ?? (u ? q?.[u] ?? (O ? u : void 0) : void 0), V = typeof M == "string" ? M : void 0, X = L.filter((l) => !l.disabled), xe = je({
230
- loading: K,
231
- loadingMessage: he,
232
- remote: O,
233
- query: h,
234
- minSearchLength: Y,
235
- searchPrompt: me,
236
- empty: L.length === 0,
237
- noResultsMessage: Z
238
- });
239
- return /* @__PURE__ */ k(
240
- "div",
241
- {
242
- ref: D,
243
- className: f(
244
- t.wrapper,
245
- t.searchableWrapper,
246
- t[n],
247
- a && t.error,
248
- v && t.disabled,
249
- r?.wrapper,
250
- _
251
- ),
252
- style: R,
253
- ...we,
254
- children: [
255
- /* @__PURE__ */ k(
256
- "select",
257
- {
258
- ref: Se,
259
- className: t.hiddenSelect,
260
- value: u ?? "",
261
- disabled: v,
262
- tabIndex: -1,
263
- "aria-hidden": "true",
264
- onChange: () => {
265
- },
266
- ...ge,
267
- children: [
268
- /* @__PURE__ */ c("option", { value: "" }),
269
- d.map((l) => /* @__PURE__ */ c("option", { value: l.value, children: l.label }, l.value)),
270
- u && !N && /* @__PURE__ */ c("option", { value: u, children: V ?? u })
271
- ]
272
- }
273
- ),
274
- /* @__PURE__ */ k(
275
- "button",
276
- {
277
- ref: te,
278
- id: b ? void 0 : w,
279
- type: "button",
280
- className: f(
281
- t.root,
282
- t.searchableTrigger,
283
- t[n],
284
- b && t.triggerOpen,
285
- a && t.error,
286
- b && t.visuallyHidden,
287
- r?.root
288
- ),
289
- onClick: ue,
290
- disabled: v,
291
- "aria-expanded": b,
292
- "aria-haspopup": "listbox",
293
- "aria-controls": b ? re : void 0,
294
- ...ce,
295
- children: [
296
- /* @__PURE__ */ c("span", { className: f(t.triggerLabel, !M && t.placeholder), children: M || m }),
297
- K && /* @__PURE__ */ c(Oe, { size: "sm", label: "", "aria-hidden": "true", className: f(t.spinner, r?.spinner) }),
298
- /* @__PURE__ */ c("span", { className: f(t.arrow, t.arrowInline, r?.arrow) })
299
- ]
300
- }
301
- ),
302
- b && /* @__PURE__ */ c(
303
- "input",
304
- {
305
- ref: P,
306
- id: w,
307
- type: "text",
308
- role: "combobox",
309
- className: f(
310
- t.root,
311
- t.searchableTrigger,
312
- t[n],
313
- t.triggerOpen,
314
- a && t.error,
315
- r?.root,
316
- r?.search
317
- ),
318
- placeholder: V || (typeof m == "string" ? m : void 0),
319
- value: h,
320
- onChange: (l) => $(l.target.value),
321
- onKeyDown: T,
322
- "aria-expanded": !0,
323
- "aria-haspopup": "listbox",
324
- "aria-controls": re,
325
- "aria-activedescendant": X.length > 0 ? `select-option-${L[I]?.value}` : void 0,
326
- "aria-label": ve["aria-labelledby"] || w ? void 0 : _e,
327
- ...ve
328
- }
329
- ),
330
- b && (() => {
331
- const l = F ? {
332
- position: "fixed",
333
- top: le.top + 4,
334
- left: le.left,
335
- right: "auto",
336
- width: le.width,
337
- zIndex: "var(--crk-z-floating)"
338
- } : void 0, p = /* @__PURE__ */ c(
339
- "div",
340
- {
341
- id: re,
342
- ref: Q,
343
- className: f(t.menu, r?.menu),
344
- style: l,
345
- role: "listbox",
346
- children: /* @__PURE__ */ c("div", { className: t.menuItems, ref: ne, children: xe !== null ? /* @__PURE__ */ c("div", { className: f(t.noResults, r?.message), role: "status", children: xe }) : L.map((s, e) => /* @__PURE__ */ c(
347
- "button",
348
- {
349
- id: `select-option-${s.value}`,
350
- type: "button",
351
- role: "option",
352
- "aria-selected": s.value === u,
353
- className: f(
354
- t.item,
355
- s.disabled && t.itemDisabled,
356
- s.value === u && t.itemSelected,
357
- e === I && t.itemHighlighted,
358
- r?.item
359
- ),
360
- disabled: s.disabled,
361
- onClick: () => U(s.value),
362
- onMouseEnter: () => W(e),
363
- children: We(s, h, pe && !O, r?.match)
364
- },
365
- s.value
366
- )) })
367
- }
368
- );
369
- return F && typeof document < "u" ? Le(p, document.body) : p;
370
- })()
371
- ]
372
- }
373
- );
374
- }
375
- );
376
- Be.displayName = "SearchableSelect";
377
- const Ke = Ne(
378
- ({
379
- inputSize: n = "md",
380
- error: a = !1,
381
- options: d = [],
382
- placeholder: m = "Select...",
383
- classes: r,
384
- className: _,
385
- style: R,
386
- value: u,
387
- disabled: v,
388
- id: w,
389
- searchPlaceholder: _e,
390
- onValuesChange: C,
391
- clearSearchOnSelect: j = !0,
392
- closeOnSelect: F = !0,
393
- allowCreate: fe = !1,
394
- onCreate: oe,
395
- createLabel: G,
396
- portal: J = !0,
397
- onFocus: Y,
398
- onBlur: me,
399
- onSearch: K,
400
- searchDebounce: he = 250,
401
- minSearchLength: Z = 0,
402
- searchPrompt: pe = "Type to search",
403
- loading: q = !1,
404
- loadingMessage: ke = "Loading…",
405
- noResultsMessage: ie = "No results",
406
- highlightMatches: se = !1,
407
- selectedLabels: be,
408
- // Single-mode props: not spread onto the DOM.
409
- multiple: Re,
410
- searchable: Ce,
411
- onChange: H,
412
- onValueChange: Ie,
413
- ...ee
414
- }, O) => {
415
- const b = !!K, g = Array.isArray(u) ? u : u ? [u] : [], [h, $] = ae(!1), [S, I] = ae(""), W = q || b && S.length < Z, [D, P] = ae(0), te = y(null), Q = y(null), ne = y(null), re = y(null), le = y(null), ge = Ee(), ce = Me(le, h && J), { hidden: ve, control: we } = Te(ee), z = Ae(Y, me, [te, ne]), Se = y(null), ye = (e) => {
416
- Se.current = e, typeof O == "function" ? O(e) : O && (O.current = e);
417
- }, x = A(() => {
418
- $(!1), I(""), P(0);
419
- }, []), ue = A(() => {
420
- v || ($(!0), I(""), P(0), setTimeout(() => Q.current?.focus(), 0));
421
- }, [v]), U = A(
422
- (e) => {
423
- const i = g.includes(e) ? g.filter((o) => o !== e) : [...g, e];
424
- C?.(i), F ? x() : j && I("");
425
- },
426
- [g, C, F, x, j]
427
- ), L = A(
428
- (e, i) => {
429
- i.stopPropagation(), C?.(g.filter((o) => o !== e));
430
- },
431
- [g, C]
432
- ), T = He(d, S, b);
433
- Fe(K, S, h, he, Z);
434
- const N = S.trim(), M = fe && N.length > 0 && !d.some(
435
- (e) => e.label.toLowerCase() === N.toLowerCase() || e.value === N
436
- ) && !g.includes(N), V = A(() => {
437
- N && (g.includes(N) || (oe?.(N), C?.([...g, N]), F ? x() : j && I("")));
438
- }, [N, g, oe, C, F, x, j]);
439
- B(() => {
440
- const e = T.findIndex((i) => !i.disabled);
441
- P(e >= 0 ? e : 0);
442
- }, [T]), B(() => {
443
- if (!h) return;
444
- const e = re.current;
445
- if (!e) return;
446
- e.querySelectorAll('[role="option"]')[D]?.scrollIntoView?.({ block: "nearest" });
447
- }, [D, h]);
448
- const X = T.length, xe = A(
449
- (e) => {
450
- const i = T.map((o, E) => o.disabled ? -1 : E).filter((o) => o >= 0);
451
- if (M && i.push(X), e.key === "Backspace" && S === "" && g.length > 0) {
452
- e.preventDefault(), C?.(g.slice(0, -1));
453
- return;
454
- }
455
- if (e.key === "Escape") {
456
- if (!h) return;
457
- e.preventDefault(), x();
458
- return;
459
- }
460
- if (i.length !== 0) {
461
- if (e.key === "ArrowDown") {
462
- if (e.preventDefault(), !h) {
463
- ue();
464
- return;
465
- }
466
- P((o) => {
467
- const E = i.indexOf(o);
468
- return E < i.length - 1 ? i[E + 1] : i[0];
469
- });
470
- } else if (e.key === "ArrowUp")
471
- e.preventDefault(), P((o) => {
472
- const E = i.indexOf(o);
473
- return E > 0 ? i[E - 1] : i[i.length - 1];
474
- });
475
- else if (e.key === "Enter") {
476
- if (e.preventDefault(), W) return;
477
- if (M && D === X) {
478
- V();
479
- return;
480
- }
481
- const o = T[D];
482
- o && !o.disabled ? U(o.value) : M && V();
483
- }
484
- }
485
- },
486
- [T, D, U, x, S, g, C, h, ue, M, V, X, W]
487
- );
488
- B(() => {
489
- if (!h) return;
490
- const e = (i) => {
491
- const o = i.target;
492
- te.current?.contains(o) || ne.current?.contains(o) || x();
493
- };
494
- return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
495
- }, [h, x]);
496
- const l = g.map((e) => {
497
- const i = d.find((E) => E.value === e);
498
- if (i) return i;
499
- const o = be?.[e];
500
- return typeof o == "string" ? { value: e, label: o } : { value: e, label: e, content: o };
501
- }), p = je({
502
- loading: q,
503
- loadingMessage: ke,
504
- remote: b,
505
- query: S,
506
- minSearchLength: Z,
507
- searchPrompt: pe,
508
- empty: T.length === 0 && !M,
509
- noResultsMessage: ie
510
- }), s = p === null;
511
- return /* @__PURE__ */ k(
512
- "div",
513
- {
514
- ref: te,
515
- className: f(
516
- t.wrapper,
517
- t.searchableWrapper,
518
- t[n],
519
- a && t.error,
520
- v && t.disabled,
521
- r?.wrapper,
522
- _
523
- ),
524
- style: R,
525
- ...z,
526
- children: [
527
- /* @__PURE__ */ k(
528
- "select",
529
- {
530
- ref: ye,
531
- className: t.hiddenSelect,
532
- multiple: !0,
533
- value: g,
534
- disabled: v,
535
- tabIndex: -1,
536
- "aria-hidden": "true",
537
- onChange: () => {
538
- },
539
- ...ve,
540
- children: [
541
- d.map((e) => /* @__PURE__ */ c("option", { value: e.value, children: e.label }, e.value)),
542
- l.filter((e) => !d.some((i) => i.value === e.value)).map((e) => /* @__PURE__ */ c("option", { value: e.value, children: e.label }, e.value))
543
- ]
544
- }
545
- ),
546
- /* @__PURE__ */ k(
547
- "div",
548
- {
549
- ref: le,
550
- className: f(
551
- t.multiTrigger,
552
- t[n],
553
- h && t.triggerOpen,
554
- a && t.error,
555
- v && t.multiTriggerDisabled,
556
- r?.root
557
- ),
558
- onClick: () => {
559
- h ? Q.current?.focus() : ue();
560
- },
561
- role: "combobox",
562
- "aria-expanded": h,
563
- "aria-haspopup": "listbox",
564
- "aria-controls": h ? ge : void 0,
565
- children: [
566
- l.map((e) => /* @__PURE__ */ k("span", { className: f(t.chip, r?.chip), children: [
567
- /* @__PURE__ */ c("span", { className: t.chipLabel, children: e.content ?? e.label }),
568
- /* @__PURE__ */ c(
569
- "button",
570
- {
571
- type: "button",
572
- className: f(t.chipRemove, r?.chipRemove),
573
- onClick: (i) => L(e.value, i),
574
- "aria-label": `Remove ${e.label}`,
575
- tabIndex: -1,
576
- children: "×"
577
- }
578
- )
579
- ] }, e.value)),
580
- /* @__PURE__ */ c(
581
- "input",
582
- {
583
- ref: Q,
584
- id: w,
585
- type: "text",
586
- className: t.multiSearch,
587
- placeholder: g.length === 0 ? m : "",
588
- value: S,
589
- onChange: (e) => {
590
- I(e.target.value), h || $(!0);
591
- },
592
- onKeyDown: xe,
593
- disabled: v,
594
- "aria-label": we["aria-labelledby"] ? void 0 : "Search options",
595
- ...we
596
- }
597
- ),
598
- q && /* @__PURE__ */ c(Oe, { size: "sm", label: "", "aria-hidden": "true", className: f(t.spinner, r?.spinner) }),
599
- /* @__PURE__ */ c("span", { className: f(t.arrow, t.arrowMulti, r?.arrow) })
600
- ]
601
- }
602
- ),
603
- h && (() => {
604
- const e = J ? {
605
- position: "fixed",
606
- top: ce.top + 4,
607
- left: ce.left,
608
- right: "auto",
609
- width: ce.width,
610
- zIndex: "var(--crk-z-floating)"
611
- } : void 0, i = /* @__PURE__ */ c(
612
- "div",
613
- {
614
- id: ge,
615
- ref: ne,
616
- className: f(t.menu, r?.menu),
617
- style: e,
618
- role: "listbox",
619
- "aria-multiselectable": "true",
620
- onMouseDown: (o) => o.preventDefault(),
621
- children: /* @__PURE__ */ k("div", { className: t.menuItems, ref: re, children: [
622
- p !== null && /* @__PURE__ */ c("div", { className: f(t.noResults, r?.message), role: "status", children: p }),
623
- s && T.map((o, E) => {
624
- const de = g.includes(o.value);
625
- return /* @__PURE__ */ k(
626
- "button",
627
- {
628
- id: `select-option-${o.value}`,
629
- type: "button",
630
- role: "option",
631
- "aria-selected": de,
632
- className: f(
633
- t.item,
634
- o.disabled && t.itemDisabled,
635
- de && t.itemSelected,
636
- E === D && t.itemHighlighted,
637
- r?.item
638
- ),
639
- disabled: o.disabled,
640
- onClick: () => U(o.value),
641
- onMouseEnter: () => P(E),
642
- children: [
643
- de && /* @__PURE__ */ c("span", { className: t.itemCheck, "aria-hidden": "true" }),
644
- We(o, S, se && !b, r?.match)
645
- ]
646
- },
647
- o.value
648
- );
649
- }),
650
- s && M && /* @__PURE__ */ c(
651
- "button",
652
- {
653
- type: "button",
654
- role: "option",
655
- "aria-selected": !1,
656
- className: f(
657
- t.item,
658
- D === X && t.itemHighlighted,
659
- r?.item
660
- ),
661
- onClick: V,
662
- onMouseEnter: () => P(X),
663
- children: G ? G(N) : /* @__PURE__ */ k(De, { children: [
664
- "Create “",
665
- /* @__PURE__ */ c("strong", { children: N }),
666
- "”"
667
- ] })
668
- },
669
- "__create__"
670
- )
671
- ] })
672
- }
673
- );
674
- return J && typeof document < "u" ? Le(i, document.body) : i;
675
- })()
676
- ]
677
- }
678
- );
679
- }
680
- );
681
- Ke.displayName = "MultiSelect";
682
- const Qe = Ne(
683
- (n, a) => n.multiple ? /* @__PURE__ */ c(Ke, { ref: a, ...n }) : n.searchable ? /* @__PURE__ */ c(Be, { ref: a, ...n }) : /* @__PURE__ */ c(Pe, { ref: a, ...n })
684
- );
685
- Qe.displayName = "Select";
686
- export {
687
- Qe as Select
688
- };
115
+ function ce(e) {
116
+ return e.loading ? e.loadingMessage : e.remote && e.query.length < e.minSearchLength ? e.searchPrompt : e.empty ? e.noResultsMessage : null;
117
+ }
118
+ var m = e(({ inputSize: e = "md", error: i = !1, options: u = [], placeholder: p = "Select...", classes: m, className: le, style: ue, value: h, disabled: g, id: _, searchPlaceholder: v = "Search...", onChange: de, onValueChange: fe, portal: y = !0, onFocus: b, onBlur: pe, onSearch: x, searchDebounce: S = 250, minSearchLength: C = 0, searchPrompt: me = "Type to search", loading: he = !1, loadingMessage: ge = "Loading…", noResultsMessage: _e = "No results", highlightMatches: ve = !1, selectedLabels: ye, multiple: be, onValuesChange: xe, clearSearchOnSelect: Se, closeOnSelect: Ce, allowCreate: we, onCreate: Te, createLabel: Ee, checklist: De, selectAllLabel: Oe, deselectAllLabel: ke, maxVisibleChips: w, moreChipsLabel: Ae, ...je }, T) => {
119
+ let E = !!x, [D, Me] = o(!1), [O, Ne] = o(""), Pe = he || E && O.length < C, [k, A] = o(0), j = a(null), M = a(null), N = a(null), P = a(null), F = a(null), I = r(), L = ee(j, D && y), { hidden: Fe, control: R, aria: z } = ne(je), Ie = re(b, pe, [j, P]), B = a(null), V = (e) => {
120
+ B.current = e, typeof T == "function" ? T(e) : T && (T.current = e);
121
+ }, Le = a(!1);
122
+ n(() => {
123
+ Le.current && !D && N.current?.focus(), Le.current = D;
124
+ }, [D]);
125
+ let H = t(() => {
126
+ Me(!1), Ne(""), A(0);
127
+ }, []), Re = t(() => {
128
+ g || (Me(!0), Ne(""), A(0), setTimeout(() => M.current?.focus(), 0));
129
+ }, [g]), U = t((e) => {
130
+ if (fe?.(e), B.current) {
131
+ (Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, "value")?.set)?.call(B.current, e);
132
+ let t = new Event("change", { bubbles: !0 });
133
+ B.current.dispatchEvent(t), de?.(t);
134
+ }
135
+ H();
136
+ }, [
137
+ fe,
138
+ de,
139
+ B,
140
+ H
141
+ ]), W = ae(u, O, E);
142
+ ie(x, O, D, S, C), n(() => {
143
+ let e = W.findIndex((e) => !e.disabled);
144
+ A(e >= 0 ? e : 0);
145
+ }, [W]), n(() => {
146
+ if (!D) return;
147
+ let e = F.current;
148
+ e && e.querySelectorAll("[role=\"option\"]")[k]?.scrollIntoView?.({ block: "nearest" });
149
+ }, [k, D]);
150
+ let ze = t((e) => {
151
+ let t = W.map((e, t) => e.disabled ? -1 : t).filter((e) => e >= 0);
152
+ if (e.key === "Escape") e.preventDefault(), H();
153
+ else if (t.length !== 0) {
154
+ if (e.key === "ArrowDown") e.preventDefault(), A((e) => {
155
+ let n = t.indexOf(e);
156
+ return n < t.length - 1 ? t[n + 1] : t[0];
157
+ });
158
+ else if (e.key === "ArrowUp") e.preventDefault(), A((e) => {
159
+ let n = t.indexOf(e);
160
+ return n > 0 ? t[n - 1] : t[t.length - 1];
161
+ });
162
+ else if (e.key === "Enter") {
163
+ if (e.preventDefault(), Pe) return;
164
+ let t = W[k];
165
+ t && !t.disabled && U(t.value);
166
+ }
167
+ }
168
+ }, [
169
+ W,
170
+ k,
171
+ U,
172
+ H,
173
+ Pe
174
+ ]);
175
+ n(() => {
176
+ if (!D) return;
177
+ let e = (e) => {
178
+ let t = e.target;
179
+ j.current?.contains(t) || P.current?.contains(t) || H();
180
+ };
181
+ return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
182
+ }, [D, H]);
183
+ let G = u.find((e) => e.value === h), Be = G?.label ?? (h ? ye?.[h] ?? (E ? h : void 0) : void 0), Ve = typeof Be == "string" ? Be : void 0, He = W.filter((e) => !e.disabled), K = ce({
184
+ loading: he,
185
+ loadingMessage: ge,
186
+ remote: E,
187
+ query: O,
188
+ minSearchLength: C,
189
+ searchPrompt: me,
190
+ empty: W.length === 0,
191
+ noResultsMessage: _e
192
+ });
193
+ return /* @__PURE__ */ f("div", {
194
+ ref: j,
195
+ className: c(l.wrapper, l.searchableWrapper, l[e], i && l.error, g && l.disabled, m?.wrapper, le),
196
+ style: ue,
197
+ ...Ie,
198
+ children: [
199
+ /* @__PURE__ */ f("select", {
200
+ ref: V,
201
+ className: l.hiddenSelect,
202
+ value: h ?? "",
203
+ disabled: g,
204
+ tabIndex: -1,
205
+ "aria-hidden": "true",
206
+ onChange: () => {},
207
+ ...Fe,
208
+ children: [
209
+ /* @__PURE__ */ d("option", { value: "" }),
210
+ u.map((e) => /* @__PURE__ */ d("option", {
211
+ value: e.value,
212
+ children: e.label
213
+ }, e.value)),
214
+ h && !G && /* @__PURE__ */ d("option", {
215
+ value: h,
216
+ children: Ve ?? h
217
+ })
218
+ ]
219
+ }),
220
+ /* @__PURE__ */ f("button", {
221
+ ref: N,
222
+ id: D ? void 0 : _,
223
+ type: "button",
224
+ className: c(l.root, l.searchableTrigger, l[e], D && l.triggerOpen, i && l.error, D && l.visuallyHidden, m?.root),
225
+ onClick: Re,
226
+ disabled: g,
227
+ "aria-expanded": D,
228
+ "aria-haspopup": "listbox",
229
+ "aria-controls": D ? I : void 0,
230
+ ...R,
231
+ children: [
232
+ /* @__PURE__ */ d("span", {
233
+ className: c(l.triggerLabel, !Be && l.placeholder),
234
+ children: Be || p
235
+ }),
236
+ he && /* @__PURE__ */ d(te, {
237
+ size: "sm",
238
+ label: "",
239
+ "aria-hidden": "true",
240
+ className: c(l.spinner, m?.spinner)
241
+ }),
242
+ /* @__PURE__ */ d("span", { className: c(l.arrow, l.arrowInline, m?.arrow) })
243
+ ]
244
+ }),
245
+ D && /* @__PURE__ */ d("input", {
246
+ ref: M,
247
+ id: _,
248
+ type: "text",
249
+ role: "combobox",
250
+ className: c(l.root, l.searchableTrigger, l[e], l.triggerOpen, i && l.error, m?.root, m?.search),
251
+ placeholder: Ve || (typeof p == "string" ? p : void 0),
252
+ value: O,
253
+ onChange: (e) => Ne(e.target.value),
254
+ onKeyDown: ze,
255
+ "aria-expanded": !0,
256
+ "aria-haspopup": "listbox",
257
+ "aria-controls": I,
258
+ "aria-activedescendant": He.length > 0 && W[k] ? oe(I, k) : void 0,
259
+ "aria-label": z["aria-labelledby"] || _ ? void 0 : v,
260
+ ...z
261
+ }),
262
+ D && (() => {
263
+ let e = y ? {
264
+ position: "fixed",
265
+ top: L.top + 4,
266
+ left: L.left,
267
+ right: "auto",
268
+ width: L.width,
269
+ zIndex: "var(--crk-z-floating)"
270
+ } : void 0, t = /* @__PURE__ */ d("div", {
271
+ id: I,
272
+ ref: P,
273
+ className: c(l.menu, m?.menu),
274
+ style: e,
275
+ role: "listbox",
276
+ children: /* @__PURE__ */ d("div", {
277
+ className: l.menuItems,
278
+ ref: F,
279
+ children: K === null ? W.map((e, t) => /* @__PURE__ */ d("button", {
280
+ id: oe(I, t),
281
+ type: "button",
282
+ role: "option",
283
+ "aria-selected": e.value === h,
284
+ className: c(l.item, e.disabled && l.itemDisabled, e.value === h && l.itemSelected, t === k && l.itemHighlighted, m?.item),
285
+ disabled: e.disabled,
286
+ onClick: () => U(e.value),
287
+ onMouseEnter: () => A(t),
288
+ children: se(e, O, ve && !E, m?.match)
289
+ }, e.value)) : /* @__PURE__ */ d("div", {
290
+ className: c(l.noResults, m?.message),
291
+ role: "status",
292
+ children: K
293
+ })
294
+ })
295
+ });
296
+ return y && typeof document < "u" ? s(t, document.body) : t;
297
+ })()
298
+ ]
299
+ });
300
+ });
301
+ m.displayName = "SearchableSelect";
302
+ var le = /* @__PURE__ */ new Set(), ue = (e) => `+${e} more`, h = ({ className: e }) => /* @__PURE__ */ f("svg", {
303
+ className: e,
304
+ viewBox: "0 0 20 20",
305
+ fill: "none",
306
+ stroke: "currentColor",
307
+ strokeWidth: "1.8",
308
+ "aria-hidden": "true",
309
+ children: [/* @__PURE__ */ d("circle", {
310
+ cx: "8.5",
311
+ cy: "8.5",
312
+ r: "5.5"
313
+ }), /* @__PURE__ */ d("path", {
314
+ d: "M12.8 12.8L17 17",
315
+ strokeLinecap: "round"
316
+ })]
317
+ });
318
+ function g(e, t) {
319
+ let n = t?.[e];
320
+ return typeof n == "string" ? {
321
+ value: e,
322
+ label: n
323
+ } : {
324
+ value: e,
325
+ label: e,
326
+ content: n
327
+ };
328
+ }
329
+ var _ = e(({ inputSize: e = "md", error: p = !1, options: m = [], placeholder: _ = "Select...", classes: v, className: de, style: fe, value: y, disabled: b, id: pe, searchPlaceholder: x = "Search...", onValuesChange: S, clearSearchOnSelect: C, closeOnSelect: me, allowCreate: he = !1, onCreate: ge, createLabel: _e, portal: ve = !0, onFocus: ye, onBlur: be, onSearch: xe, searchDebounce: Se = 250, minSearchLength: Ce = 0, searchPrompt: we = "Type to search", loading: Te = !1, loadingMessage: Ee = "Loading…", noResultsMessage: De = "No results", highlightMatches: Oe = !1, selectedLabels: ke, checklist: w = !1, selectAllLabel: Ae, deselectAllLabel: je = "Deselect all", maxVisibleChips: T, moreChipsLabel: E = ue, multiple: D, searchable: Me, onChange: O, onValueChange: Ne, ...Pe }, k) => {
330
+ let A = !!xe, j = me ?? !w, M = C ?? !w, N = Array.isArray(y) ? y : y ? [y] : [], [P, F] = o(!1), [I, L] = o(""), Fe = Te || A && I.length < Ce, [R, z] = o(0), Ie = a(null), B = a(null), V = a(null), Le = a(null), H = a(null), Re = a(null), U = r(), W = ee(H, P && ve), { hidden: ze, control: G } = ne(Pe), Be = re(ye, be, [Ie, V]), Ve = a(null), He = (e) => {
331
+ Ve.current = e, typeof k == "function" ? k(e) : k && (k.current = e);
332
+ }, K = t((e = !1) => {
333
+ F(!1), L(""), z(0), e && Re.current?.focus();
334
+ }, []), Ue = t(() => {
335
+ b || (F(!0), L(""), z(0), setTimeout(() => B.current?.focus(), 0));
336
+ }, [b]), We = t((e) => {
337
+ let t = N.includes(e) ? N.filter((t) => t !== e) : [...N, e];
338
+ S?.(t), j ? K(w) : M && L("");
339
+ }, [
340
+ N,
341
+ S,
342
+ j,
343
+ K,
344
+ M,
345
+ w
346
+ ]), Ge = t((e, t) => {
347
+ t.stopPropagation(), S?.(N.filter((t) => t !== e));
348
+ }, [N, S]), q = ae(m, I, A);
349
+ ie(xe, I, P, Se, Ce);
350
+ let Ke = i(() => new Map(m.map((e) => [e.value, e])), [m]), qe = w && P ? I : null, [Je, Ye] = o({
351
+ key: null,
352
+ values: le
353
+ }), J = Je.values;
354
+ Je.key !== qe && (J = qe === null ? le : new Set(N), Ye({
355
+ key: qe,
356
+ values: J
357
+ }));
358
+ let Y = i(() => {
359
+ if (J.size === 0) return q;
360
+ let e = new Set(q.map((e) => e.value)), t = A ? q : m.filter((t) => e.has(t.value) || J.has(t.value)), n = [...J].filter((e) => !Ke.has(e)).map((e) => g(e, ke));
361
+ return n.length > 0 ? [...t, ...n] : t;
362
+ }, [
363
+ q,
364
+ J,
365
+ A,
366
+ m,
367
+ Ke,
368
+ ke
369
+ ]), X = I.trim(), Z = he && X.length > 0 && !m.some((e) => e.label.toLowerCase() === X.toLowerCase() || e.value === X) && !N.includes(X), Xe = t(() => {
370
+ X && (N.includes(X) || (ge?.(X), S?.([...N, X]), j ? K(w) : M && L("")));
371
+ }, [
372
+ X,
373
+ N,
374
+ ge,
375
+ S,
376
+ j,
377
+ K,
378
+ M,
379
+ w
380
+ ]);
381
+ n(() => {
382
+ let e = Y.findIndex((e) => !e.disabled);
383
+ z(e >= 0 ? e : 0);
384
+ }, [q, J]), n(() => {
385
+ if (!P) return;
386
+ let e = Le.current;
387
+ e && e.querySelectorAll("[role=\"option\"]")[R]?.scrollIntoView?.({ block: "nearest" });
388
+ }, [R, P]);
389
+ let Q = Y.length, Ze = t((e) => {
390
+ let t = Y.map((e, t) => e.disabled ? -1 : t).filter((e) => e >= 0);
391
+ if (Z && t.push(Q), !w && e.key === "Backspace" && I === "" && N.length > 0) e.preventDefault(), S?.(N.slice(0, -1));
392
+ else if (e.key === "Escape") {
393
+ if (!P) return;
394
+ e.preventDefault(), K(w);
395
+ } else if (t.length !== 0) {
396
+ if (e.key === "ArrowDown") {
397
+ if (e.preventDefault(), !P) {
398
+ Ue();
399
+ return;
400
+ }
401
+ z((e) => {
402
+ let n = t.indexOf(e);
403
+ return n < t.length - 1 ? t[n + 1] : t[0];
404
+ });
405
+ } else if (e.key === "ArrowUp") e.preventDefault(), z((e) => {
406
+ let n = t.indexOf(e);
407
+ return n > 0 ? t[n - 1] : t[t.length - 1];
408
+ });
409
+ else if (e.key === "Enter") {
410
+ if (e.preventDefault(), Fe) return;
411
+ if (Z && R === Q) {
412
+ Xe();
413
+ return;
414
+ }
415
+ let t = Y[R];
416
+ t && !t.disabled ? We(t.value) : Z && Xe();
417
+ }
418
+ }
419
+ }, [
420
+ Y,
421
+ R,
422
+ We,
423
+ K,
424
+ I,
425
+ N,
426
+ S,
427
+ P,
428
+ Ue,
429
+ Z,
430
+ Xe,
431
+ Q,
432
+ Fe,
433
+ w
434
+ ]), Qe = (e) => {
435
+ e.key === "ArrowDown" || e.key === "ArrowUp" ? (e.preventDefault(), Ue()) : e.key === "Backspace" && N.length > 0 && (e.preventDefault(), S?.(N.slice(0, -1)));
436
+ }, $e = (e) => {
437
+ if (e.defaultPrevented) return;
438
+ if (e.key === "Escape") {
439
+ e.preventDefault(), K(!0);
440
+ return;
441
+ }
442
+ if (e.key !== "Tab") return;
443
+ let t = Array.from(V.current?.querySelectorAll("input, button:not(:disabled):not([tabindex=\"-1\"])") ?? []);
444
+ e.shiftKey && e.target === t[0] ? (e.preventDefault(), K(!0)) : !e.shiftKey && e.target === t[t.length - 1] && K(!0);
445
+ };
446
+ n(() => {
447
+ if (!P) return;
448
+ let e = (e) => {
449
+ let t = e.target;
450
+ if (Ie.current?.contains(t) || V.current?.contains(t)) return;
451
+ let n = document.activeElement;
452
+ n instanceof HTMLElement && V.current?.contains(n) && n.blur(), K();
453
+ };
454
+ return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
455
+ }, [P, K]);
456
+ let $ = N.map((e) => Ke.get(e) ?? g(e, ke)), et = T !== void 0 && $.length > T ? Math.max(0, T) : $.length, tt = $.slice(0, et), nt = $.slice(et), rt = ce({
457
+ loading: Te,
458
+ loadingMessage: Ee,
459
+ remote: A,
460
+ query: I,
461
+ minSearchLength: Ce,
462
+ searchPrompt: we,
463
+ empty: Y.length === 0 && !Z,
464
+ noResultsMessage: De
465
+ }), it = rt === null, at = new Set(N), ot = it ? q.filter((e) => !e.disabled && !at.has(e.value)).map((e) => e.value) : [], st = new Set(m.filter((e) => e.disabled).map((e) => e.value)), ct = (e) => w && Ke.has(e.value) ? e.label : e.content ?? e.label, lt = N.filter((e) => !st.has(e)), ut = it ? Z && R === Q ? `${U}-create` : Y[R] ? oe(U, R) : void 0 : void 0, dt = /* @__PURE__ */ f(u, { children: [tt.map((e) => /* @__PURE__ */ f("span", {
466
+ className: c(l.chip, v?.chip),
467
+ children: [/* @__PURE__ */ d("span", {
468
+ className: l.chipLabel,
469
+ children: ct(e)
470
+ }), /* @__PURE__ */ d("button", {
471
+ type: "button",
472
+ className: c(l.chipRemove, v?.chipRemove),
473
+ onClick: (t) => Ge(e.value, t),
474
+ "aria-label": `Remove ${e.label}`,
475
+ tabIndex: -1,
476
+ children: "×"
477
+ })]
478
+ }, e.value)), nt.length > 0 && /* @__PURE__ */ d("span", {
479
+ className: c(l.chip, l.moreChip, v?.chip, v?.moreChip),
480
+ title: nt.map((e) => e.label).join(", "),
481
+ children: E(nt.length)
482
+ })] });
483
+ return /* @__PURE__ */ f("div", {
484
+ ref: Ie,
485
+ className: c(l.wrapper, l.searchableWrapper, l[e], p && l.error, b && l.disabled, v?.wrapper, de),
486
+ style: fe,
487
+ ...Be,
488
+ children: [
489
+ /* @__PURE__ */ f("select", {
490
+ ref: He,
491
+ className: l.hiddenSelect,
492
+ multiple: !0,
493
+ value: N,
494
+ disabled: b,
495
+ tabIndex: -1,
496
+ "aria-hidden": "true",
497
+ onChange: () => {},
498
+ ...ze,
499
+ children: [m.map((e) => /* @__PURE__ */ d("option", {
500
+ value: e.value,
501
+ children: e.label
502
+ }, e.value)), $.filter((e) => !Ke.has(e.value)).map((e) => /* @__PURE__ */ d("option", {
503
+ value: e.value,
504
+ children: e.label
505
+ }, e.value))]
506
+ }),
507
+ w ? /* @__PURE__ */ f("div", {
508
+ ref: H,
509
+ className: c(l.multiTrigger, l.checklistTrigger, l[e], P && l.triggerOpen, p && l.error, b && l.multiTriggerDisabled, v?.root),
510
+ onClick: () => {
511
+ P ? B.current?.focus() : Ue();
512
+ },
513
+ onMouseDown: P ? (e) => e.preventDefault() : void 0,
514
+ children: [
515
+ dt,
516
+ /* @__PURE__ */ d("button", {
517
+ ref: Re,
518
+ id: pe,
519
+ type: "button",
520
+ role: "combobox",
521
+ className: c(l.checklistButton, N.length === 0 && l.placeholder),
522
+ disabled: b,
523
+ onKeyDown: Qe,
524
+ "aria-expanded": P,
525
+ "aria-haspopup": "listbox",
526
+ "aria-controls": P ? U : void 0,
527
+ "aria-label": G["aria-labelledby"] || pe ? void 0 : _,
528
+ ...G,
529
+ children: N.length === 0 ? _ : /* @__PURE__ */ d("span", {
530
+ className: l.visuallyHidden,
531
+ children: $.map((e) => e.label).join(", ")
532
+ })
533
+ }),
534
+ Te && /* @__PURE__ */ d(te, {
535
+ size: "sm",
536
+ label: "",
537
+ "aria-hidden": "true",
538
+ className: c(l.spinner, v?.spinner)
539
+ }),
540
+ /* @__PURE__ */ d("span", { className: c(l.arrow, l.arrowMulti, v?.arrow) })
541
+ ]
542
+ }) : /* @__PURE__ */ f("div", {
543
+ ref: H,
544
+ className: c(l.multiTrigger, l[e], P && l.triggerOpen, p && l.error, b && l.multiTriggerDisabled, v?.root),
545
+ onClick: () => {
546
+ P ? B.current?.focus() : Ue();
547
+ },
548
+ role: "combobox",
549
+ "aria-expanded": P,
550
+ "aria-haspopup": "listbox",
551
+ "aria-controls": P ? U : void 0,
552
+ children: [
553
+ dt,
554
+ /* @__PURE__ */ d("input", {
555
+ ref: B,
556
+ id: pe,
557
+ type: "text",
558
+ className: l.multiSearch,
559
+ placeholder: N.length === 0 ? _ : "",
560
+ value: I,
561
+ onChange: (e) => {
562
+ L(e.target.value), P || F(!0);
563
+ },
564
+ onKeyDown: Ze,
565
+ disabled: b,
566
+ "aria-label": G["aria-labelledby"] ? void 0 : "Search options",
567
+ ...G
568
+ }),
569
+ Te && /* @__PURE__ */ d(te, {
570
+ size: "sm",
571
+ label: "",
572
+ "aria-hidden": "true",
573
+ className: c(l.spinner, v?.spinner)
574
+ }),
575
+ /* @__PURE__ */ d("span", { className: c(l.arrow, l.arrowMulti, v?.arrow) })
576
+ ]
577
+ }),
578
+ P && (() => {
579
+ let e = ve ? {
580
+ position: "fixed",
581
+ top: W.top + 4,
582
+ left: W.left,
583
+ right: "auto",
584
+ width: W.width,
585
+ zIndex: "var(--crk-z-floating)"
586
+ } : void 0, t = {
587
+ id: U,
588
+ role: "listbox",
589
+ "aria-multiselectable": !0
590
+ }, n = /* @__PURE__ */ f("div", {
591
+ ref: V,
592
+ className: c(l.menu, w && l.menuChecklist, v?.menu),
593
+ style: e,
594
+ ...w ? {} : t,
595
+ onMouseDown: (e) => {
596
+ e.target !== B.current && e.preventDefault();
597
+ },
598
+ onKeyDown: w ? $e : void 0,
599
+ children: [w && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("div", {
600
+ className: l.menuSearchRow,
601
+ children: [/* @__PURE__ */ d(h, { className: l.menuSearchIcon }), /* @__PURE__ */ d("input", {
602
+ ref: B,
603
+ type: "text",
604
+ className: c(l.menuSearch, v?.search),
605
+ placeholder: x,
606
+ value: I,
607
+ onChange: (e) => L(e.target.value),
608
+ onKeyDown: Ze,
609
+ "aria-label": x,
610
+ "aria-controls": U,
611
+ "aria-autocomplete": "list",
612
+ "aria-activedescendant": ut
613
+ })]
614
+ }), /* @__PURE__ */ f("div", {
615
+ className: c(l.menuHeader, v?.menuHeader),
616
+ children: [/* @__PURE__ */ d("button", {
617
+ type: "button",
618
+ className: c(l.menuAction, v?.menuAction),
619
+ disabled: ot.length === 0,
620
+ onClick: () => {
621
+ S?.([...N, ...ot]), B.current?.focus();
622
+ },
623
+ children: Ae ?? (I ? "Select all matching" : "Select all")
624
+ }), /* @__PURE__ */ d("button", {
625
+ type: "button",
626
+ className: c(l.menuAction, v?.menuAction),
627
+ disabled: lt.length === 0,
628
+ onClick: () => {
629
+ S?.(N.filter((e) => st.has(e))), B.current?.focus();
630
+ },
631
+ children: je
632
+ })]
633
+ })] }), /* @__PURE__ */ f("div", {
634
+ className: l.menuItems,
635
+ ref: Le,
636
+ ...w ? t : {},
637
+ children: [
638
+ rt !== null && /* @__PURE__ */ d("div", {
639
+ className: c(l.noResults, v?.message),
640
+ role: "status",
641
+ children: rt
642
+ }),
643
+ it && Y.map((e, t) => {
644
+ let n = at.has(e.value);
645
+ return /* @__PURE__ */ d("button", {
646
+ id: oe(U, t),
647
+ type: "button",
648
+ role: "option",
649
+ "aria-selected": n,
650
+ className: c(l.item, e.disabled && l.itemDisabled, n && l.itemSelected, t === R && l.itemHighlighted, v?.item),
651
+ disabled: e.disabled,
652
+ tabIndex: w ? -1 : void 0,
653
+ onClick: () => We(e.value),
654
+ onMouseEnter: () => z(t),
655
+ children: w ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("span", {
656
+ className: c(l.checkbox, n && l.checkboxChecked, v?.checkbox),
657
+ "aria-hidden": "true"
658
+ }), /* @__PURE__ */ d("span", {
659
+ className: l.itemBody,
660
+ children: se(e, I, Oe && !A, v?.match)
661
+ })] }) : /* @__PURE__ */ f(u, { children: [n && /* @__PURE__ */ d("span", {
662
+ className: l.itemCheck,
663
+ "aria-hidden": "true"
664
+ }), se(e, I, Oe && !A, v?.match)] })
665
+ }, e.value);
666
+ }),
667
+ it && Z && /* @__PURE__ */ d("button", {
668
+ id: `${U}-create`,
669
+ type: "button",
670
+ role: "option",
671
+ "aria-selected": !1,
672
+ className: c(l.item, R === Q && l.itemHighlighted, v?.item),
673
+ tabIndex: w ? -1 : void 0,
674
+ onClick: Xe,
675
+ onMouseEnter: () => z(Q),
676
+ children: _e ? _e(X) : /* @__PURE__ */ f(u, { children: [
677
+ "Create “",
678
+ /* @__PURE__ */ d("strong", { children: X }),
679
+ "”"
680
+ ] })
681
+ }, "__create__")
682
+ ]
683
+ })]
684
+ });
685
+ return ve && typeof document < "u" ? s(n, document.body) : n;
686
+ })()
687
+ ]
688
+ });
689
+ });
690
+ _.displayName = "MultiSelect";
691
+ var v = e((e, t) => e.multiple ? /* @__PURE__ */ d(_, {
692
+ ref: t,
693
+ ...e
694
+ }) : e.searchable ? /* @__PURE__ */ d(m, {
695
+ ref: t,
696
+ ...e
697
+ }) : /* @__PURE__ */ d(p, {
698
+ ref: t,
699
+ ...e
700
+ }));
701
+ v.displayName = "Select";
702
+ export { v as Select };