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