@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,23 +1,28 @@
1
- import { useState as f, useEffect as z } from "react";
2
- function g(s, o = "content-box") {
3
- const [d, u] = f({ width: 0, height: 0 });
4
- return z(() => {
5
- const r = s.current;
6
- if (!r || typeof ResizeObserver > "u") return;
7
- const c = (i, e) => u((t) => t.width === i && t.height === e ? t : { width: i, height: e }), h = new ResizeObserver((i) => {
8
- const e = i[0];
9
- if (e)
10
- if (o === "border-box" && e.borderBoxSize?.length) {
11
- const t = e.borderBoxSize[0];
12
- c(t.inlineSize, t.blockSize);
13
- } else
14
- c(e.contentRect.width, e.contentRect.height);
15
- });
16
- h.observe(r, { box: o });
17
- const n = r.getBoundingClientRect();
18
- return (n.width || n.height) && c(n.width, n.height), () => h.disconnect();
19
- }, [s, o]), d;
1
+ import { useEffect as e, useState as t } from "react";
2
+ // src/hooks/useElementSize.ts
3
+ function n(n, r = "content-box") {
4
+ let [i, a] = t({
5
+ width: 0,
6
+ height: 0
7
+ });
8
+ return e(() => {
9
+ let e = n.current;
10
+ if (!e || typeof ResizeObserver > "u") return;
11
+ let t = (e, t) => a((n) => n.width === e && n.height === t ? n : {
12
+ width: e,
13
+ height: t
14
+ }), i = new ResizeObserver((e) => {
15
+ let n = e[0];
16
+ if (n) {
17
+ if (r === "border-box" && n.borderBoxSize?.length) {
18
+ let e = n.borderBoxSize[0];
19
+ t(e.inlineSize, e.blockSize);
20
+ } else t(n.contentRect.width, n.contentRect.height);
21
+ }
22
+ });
23
+ i.observe(e, { box: r });
24
+ let o = e.getBoundingClientRect();
25
+ return (o.width || o.height) && t(o.width, o.height), () => i.disconnect();
26
+ }, [n, r]), i;
20
27
  }
21
- export {
22
- g as useElementSize
23
- };
28
+ export { n as useElementSize };
@@ -1,33 +1,32 @@
1
- import { useRef as s, useContext as l, useEffect as a, createContext as d } from "react";
2
- const r = [], f = d(null), h = f.Provider;
3
- function i(e) {
4
- if (e.key !== "Escape" || e.defaultPrevented) return;
5
- const n = r[r.length - 1];
6
- n && n.handler.current(e);
1
+ import { createContext as e, useContext as t, useEffect as n, useRef as r } from "react";
2
+ // src/hooks/useEscapeLayer.ts
3
+ var i = [], a = e(null), o = a.Provider;
4
+ function s(e) {
5
+ if (e.key !== "Escape" || e.defaultPrevented) return;
6
+ let t = i[i.length - 1];
7
+ t && t.handler.current(e);
7
8
  }
8
- function p(e, n) {
9
- for (let t = e.parent; t; t = t.parent)
10
- if (t === n) return !0;
11
- return !1;
9
+ function c(e, t) {
10
+ for (let n = e.parent; n; n = n.parent) if (n === t) return !0;
11
+ return !1;
12
12
  }
13
- function y(e) {
14
- const n = r.findIndex((t) => p(t, e));
15
- return n === -1 ? r.length : n;
13
+ function l(e) {
14
+ let t = i.findIndex((t) => c(t, e));
15
+ return t === -1 ? i.length : t;
16
16
  }
17
- function m(e, n) {
18
- const t = s(e);
19
- t.current = e;
20
- const c = l(f), u = s(null);
21
- u.current === null && (u.current = { handler: t, parent: c });
22
- const o = u.current;
23
- return o.parent = c, a(() => {
24
- if (n)
25
- return r.length === 0 && document.addEventListener("keydown", i), r.splice(y(o), 0, o), () => {
26
- r.splice(r.indexOf(o), 1), r.length === 0 && document.removeEventListener("keydown", i);
27
- };
28
- }, [n, o]), o;
17
+ function u(e, o) {
18
+ let c = r(e);
19
+ c.current = e;
20
+ let u = t(a), d = r(null);
21
+ d.current === null && (d.current = {
22
+ handler: c,
23
+ parent: u
24
+ });
25
+ let f = d.current;
26
+ return f.parent = u, n(() => {
27
+ if (o) return i.length === 0 && document.addEventListener("keydown", s), i.splice(l(f), 0, f), () => {
28
+ i.splice(i.indexOf(f), 1), i.length === 0 && document.removeEventListener("keydown", s);
29
+ };
30
+ }, [o, f]), f;
29
31
  }
30
- export {
31
- h as EscapeLayerProvider,
32
- m as useEscapeLayer
33
- };
32
+ export { o as EscapeLayerProvider, u as useEscapeLayer };
@@ -1,39 +1,28 @@
1
- import { useRef as i, useCallback as a, useEffect as f } from "react";
2
- const s = [
3
- 'input:not([disabled]):not([type="hidden"])',
4
- "button:not([disabled])",
5
- "select:not([disabled])",
6
- "textarea:not([disabled])",
7
- "a[href]",
8
- '[tabindex]:not([tabindex="-1"])'
9
- ].join(", ");
10
- function m(t, u) {
11
- const o = i(null), r = a(
12
- (e) => {
13
- if (e.key !== "Tab" || !t.current)
14
- return;
15
- const n = Array.from(
16
- t.current.querySelectorAll(s)
17
- );
18
- if (n.length === 0) {
19
- e.preventDefault();
20
- return;
21
- }
22
- const c = n[0], l = n[n.length - 1];
23
- e.shiftKey ? document.activeElement === c && (e.preventDefault(), l.focus()) : document.activeElement === l && (e.preventDefault(), c.focus());
24
- },
25
- [t]
26
- );
27
- f(() => {
28
- if (!u || !t.current)
29
- return;
30
- o.current = document.activeElement;
31
- const e = t.current.querySelectorAll(s);
32
- return e.length > 0 && e[0].focus(), document.addEventListener("keydown", r), () => {
33
- document.removeEventListener("keydown", r), o.current instanceof HTMLElement && o.current.focus();
34
- };
35
- }, [u, t, r]);
1
+ import { useCallback as e, useEffect as t, useRef as n } from "react";
2
+ // src/hooks/useFocusTrap.ts
3
+ var r = "input:not([disabled]):not([type=\"hidden\"]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex=\"-1\"])";
4
+ function i(i, a) {
5
+ let o = n(null), s = e((e) => {
6
+ if (e.key !== "Tab" || !i.current) return;
7
+ let t = Array.from(i.current.querySelectorAll(r));
8
+ if (t.length === 0) {
9
+ e.preventDefault();
10
+ return;
11
+ }
12
+ let n = t[0], a = t[t.length - 1];
13
+ e.shiftKey ? document.activeElement === n && (e.preventDefault(), a.focus()) : document.activeElement === a && (e.preventDefault(), n.focus());
14
+ }, [i]);
15
+ t(() => {
16
+ if (!a || !i.current) return;
17
+ o.current = document.activeElement;
18
+ let e = i.current.querySelectorAll(r);
19
+ return e.length > 0 && e[0].focus(), document.addEventListener("keydown", s), () => {
20
+ document.removeEventListener("keydown", s), o.current instanceof HTMLElement && o.current.focus();
21
+ };
22
+ }, [
23
+ a,
24
+ i,
25
+ s
26
+ ]);
36
27
  }
37
- export {
38
- m as useFocusTrap
39
- };
28
+ export { i as useFocusTrap };
@@ -1,69 +1,81 @@
1
- import { useRef as y, useEffect as E } from "react";
2
- const b = () => typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform ?? ""), k = {
3
- esc: "Escape",
4
- escape: "Escape",
5
- enter: "Enter",
6
- return: "Enter",
7
- space: " ",
8
- tab: "Tab",
9
- backspace: "Backspace",
10
- delete: "Delete",
11
- del: "Delete",
12
- up: "ArrowUp",
13
- down: "ArrowDown",
14
- left: "ArrowLeft",
15
- right: "ArrowRight",
16
- arrowup: "ArrowUp",
17
- arrowdown: "ArrowDown",
18
- arrowleft: "ArrowLeft",
19
- arrowright: "ArrowRight",
20
- home: "Home",
21
- end: "End",
22
- pageup: "PageUp",
23
- pagedown: "PageDown",
24
- plus: "+"
1
+ import { useEffect as e, useRef as t } from "react";
2
+ // src/hooks/useKeyboard.ts
3
+ var n = () => typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform ?? ""), r = {
4
+ esc: "Escape",
5
+ escape: "Escape",
6
+ enter: "Enter",
7
+ return: "Enter",
8
+ space: " ",
9
+ tab: "Tab",
10
+ backspace: "Backspace",
11
+ delete: "Delete",
12
+ del: "Delete",
13
+ up: "ArrowUp",
14
+ down: "ArrowDown",
15
+ left: "ArrowLeft",
16
+ right: "ArrowRight",
17
+ arrowup: "ArrowUp",
18
+ arrowdown: "ArrowDown",
19
+ arrowleft: "ArrowLeft",
20
+ arrowright: "ArrowRight",
21
+ home: "Home",
22
+ end: "End",
23
+ pageup: "PageUp",
24
+ pagedown: "PageDown",
25
+ plus: "+"
25
26
  };
26
- function v(t) {
27
- const e = t.split("+").map((o) => o.trim()).filter((o) => o.length > 0);
28
- (e.length === 0 || t.endsWith("+")) && e.push("+");
29
- const r = { key: "", ctrl: !1, alt: !1, shift: !1, meta: !1, hasModifier: !1 };
30
- for (const o of e) {
31
- const n = o.toLowerCase();
32
- n === "mod" ? b() ? r.meta = !0 : r.ctrl = !0 : n === "ctrl" || n === "control" ? r.ctrl = !0 : n === "alt" || n === "option" ? r.alt = !0 : n === "shift" ? r.shift = !0 : n === "meta" || n === "cmd" || n === "command" || n === "super" || n === "win" ? r.meta = !0 : r.key = k[n] ?? (o.length === 1 ? o.toLowerCase() : o);
33
- }
34
- return r.hasModifier = r.ctrl || r.alt || r.meta, r;
27
+ function i(e) {
28
+ let t = e.split("+").map((e) => e.trim()).filter((e) => e.length > 0);
29
+ (t.length === 0 || e.endsWith("+")) && t.push("+");
30
+ let i = {
31
+ key: "",
32
+ ctrl: !1,
33
+ alt: !1,
34
+ shift: !1,
35
+ meta: !1,
36
+ hasModifier: !1
37
+ };
38
+ for (let e of t) {
39
+ let t = e.toLowerCase();
40
+ t === "mod" ? n() ? i.meta = !0 : i.ctrl = !0 : t === "ctrl" || t === "control" ? i.ctrl = !0 : t === "alt" || t === "option" ? i.alt = !0 : t === "shift" ? i.shift = !0 : t === "meta" || t === "cmd" || t === "command" || t === "super" || t === "win" ? i.meta = !0 : i.key = r[t] ?? (e.length === 1 ? e.toLowerCase() : e);
41
+ }
42
+ return i.hasModifier = i.ctrl || i.alt || i.meta, i;
35
43
  }
36
- function K(t, e) {
37
- return (e.key.length === 1 ? e.key.toLowerCase() : e.key) !== t.key ? !1 : t.hasModifier || t.shift ? e.ctrlKey === t.ctrl && e.altKey === t.alt && e.metaKey === t.meta && e.shiftKey === t.shift : !e.ctrlKey && !e.altKey && !e.metaKey;
44
+ function a(e, t) {
45
+ return (t.key.length === 1 ? t.key.toLowerCase() : t.key) === e.key ? e.hasModifier || e.shift ? t.ctrlKey === e.ctrl && t.altKey === e.alt && t.metaKey === e.meta && t.shiftKey === e.shift : !t.ctrlKey && !t.altKey && !t.metaKey : !1;
38
46
  }
39
- const A = 'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
40
- function D(t) {
41
- const e = t.target;
42
- return !e || typeof e.closest != "function" ? !1 : e.isContentEditable ? !0 : e.closest(A) !== null;
47
+ var o = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])";
48
+ function s(e) {
49
+ let t = e.target;
50
+ return !t || typeof t.closest != "function" ? !1 : t.isContentEditable ? !0 : t.closest(o) !== null;
43
51
  }
44
- function C(t, e = !0) {
45
- const r = typeof e == "boolean" ? { active: e } : e, { active: o = !0, ignoreEditable: n = !0, preventDefault: f, target: i = null } = r, u = y(t);
46
- u.current = t;
47
- const c = y({ ignoreEditable: n, preventDefault: f });
48
- c.current = { ignoreEditable: n, preventDefault: f }, E(() => {
49
- if (!o) return;
50
- const l = i ? i.current : document;
51
- if (!l) return;
52
- const p = (m) => {
53
- const a = m, d = u.current, h = c.current.ignoreEditable && D(a);
54
- for (const w of Object.keys(d)) {
55
- const s = v(w);
56
- if (!K(s, a)) continue;
57
- const g = s.key.length === 1 && !s.hasModifier;
58
- if (h && g) continue;
59
- (c.current.preventDefault ?? s.hasModifier) && a.preventDefault(), d[w](a);
60
- return;
61
- }
62
- };
63
- return l.addEventListener("keydown", p), () => l.removeEventListener("keydown", p);
64
- }, [o, i]);
52
+ function c(n, r = !0) {
53
+ let { active: o = !0, ignoreEditable: c = !0, preventDefault: l, target: u = null } = typeof r == "boolean" ? { active: r } : r, d = t(n);
54
+ d.current = n;
55
+ let f = t({
56
+ ignoreEditable: c,
57
+ preventDefault: l
58
+ });
59
+ f.current = {
60
+ ignoreEditable: c,
61
+ preventDefault: l
62
+ }, e(() => {
63
+ if (!o) return;
64
+ let e = u ? u.current : document;
65
+ if (!e) return;
66
+ let t = (e) => {
67
+ let t = e, n = d.current, r = f.current.ignoreEditable && s(t);
68
+ for (let e of Object.keys(n)) {
69
+ let o = i(e);
70
+ if (!a(o, t)) continue;
71
+ let s = o.key.length === 1 && !o.hasModifier;
72
+ if (!(r && s)) {
73
+ (f.current.preventDefault ?? o.hasModifier) && t.preventDefault(), n[e](t);
74
+ return;
75
+ }
76
+ }
77
+ };
78
+ return e.addEventListener("keydown", t), () => e.removeEventListener("keydown", t);
79
+ }, [o, u]);
65
80
  }
66
- export {
67
- v as parseChord,
68
- C as useKeyboard
69
- };
81
+ export { i as parseChord, c as useKeyboard };
@@ -1,16 +1,11 @@
1
- import { useCallback as o, useSyncExternalStore as a } from "react";
2
- function r(n, t = !1) {
3
- const d = o(
4
- (e) => {
5
- if (typeof window > "u" || typeof window.matchMedia != "function") return () => {
6
- };
7
- const i = window.matchMedia(n);
8
- return i.addEventListener("change", e), () => i.removeEventListener("change", e);
9
- },
10
- [n]
11
- ), c = o(() => typeof window > "u" || typeof window.matchMedia != "function" ? t : window.matchMedia(n).matches, [n, t]);
12
- return a(d, c, () => t);
1
+ import { useCallback as e, useSyncExternalStore as t } from "react";
2
+ // src/hooks/useMediaQuery.ts
3
+ function n(n, r = !1) {
4
+ let i = e((e) => {
5
+ if (typeof window > "u" || typeof window.matchMedia != "function") return () => {};
6
+ let t = window.matchMedia(n);
7
+ return t.addEventListener("change", e), () => t.removeEventListener("change", e);
8
+ }, [n]), a = e(() => typeof window > "u" || typeof window.matchMedia != "function" ? r : window.matchMedia(n).matches, [n, r]);
9
+ return t(i, a, () => r);
13
10
  }
14
- export {
15
- r as useMediaQuery
16
- };
11
+ export { n as useMediaQuery };
package/hooks/useNow.js CHANGED
@@ -1,35 +1,30 @@
1
- import { useRef as a, useCallback as u, useSyncExternalStore as i } from "react";
2
- const r = /* @__PURE__ */ new Map();
3
- function f(s, t) {
4
- let e = r.get(s);
5
- if (!e) {
6
- const n = {
7
- listeners: /* @__PURE__ */ new Set(),
8
- now: Date.now(),
9
- timer: setInterval(() => {
10
- n.now = Date.now(), n.listeners.forEach((c) => c());
11
- }, s)
12
- };
13
- r.set(s, n), e = n;
14
- }
15
- return e.listeners.add(t), () => {
16
- e.listeners.delete(t), e.listeners.size === 0 && (clearInterval(e.timer), r.delete(s));
17
- };
1
+ import { useCallback as e, useRef as t, useSyncExternalStore as n } from "react";
2
+ // src/hooks/useNow.ts
3
+ var r = /* @__PURE__ */ new Map();
4
+ function i(e, t) {
5
+ let n = r.get(e);
6
+ if (!n) {
7
+ let t = {
8
+ listeners: /* @__PURE__ */ new Set(),
9
+ now: Date.now(),
10
+ timer: setInterval(() => {
11
+ t.now = Date.now(), t.listeners.forEach((e) => e());
12
+ }, e)
13
+ };
14
+ r.set(e, t), n = t;
15
+ }
16
+ return n.listeners.add(t), () => {
17
+ n.listeners.delete(t), n.listeners.size === 0 && (clearInterval(n.timer), r.delete(e));
18
+ };
18
19
  }
19
- function d(s = 1e3, t = !0) {
20
- const e = Math.max(16, Math.floor(s)), n = a(Date.now()), c = u(
21
- (o) => t ? f(e, o) : () => {
22
- },
23
- [e, t]
24
- ), l = u(() => {
25
- if (t) {
26
- const o = r.get(e);
27
- o && (n.current = o.now);
28
- }
29
- return n.current;
30
- }, [e, t]);
31
- return i(c, l, l);
20
+ function a(a = 1e3, o = !0) {
21
+ let s = Math.max(16, Math.floor(a)), c = t(Date.now()), l = e((e) => o ? i(s, e) : () => {}, [s, o]), u = e(() => {
22
+ if (o) {
23
+ let e = r.get(s);
24
+ e && (c.current = e.now);
25
+ }
26
+ return c.current;
27
+ }, [s, o]);
28
+ return n(l, u, u);
32
29
  }
33
- export {
34
- d as useNow
35
- };
30
+ export { a as useNow };
@@ -1,99 +1,103 @@
1
- import { useMemo as A, useCallback as w, useSyncExternalStore as J } from "react";
2
- const f = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
3
- function I(e, s) {
4
- return `${e}:${s}`;
1
+ import { useCallback as e, useMemo as t, useSyncExternalStore as n } from "react";
2
+ // src/hooks/usePersistedState.ts
3
+ var r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
4
+ function a(e, t) {
5
+ return `${e}:${t}`;
5
6
  }
6
- function p(e) {
7
- try {
8
- return typeof window > "u" ? null : e === "local" ? window.localStorage : window.sessionStorage;
9
- } catch {
10
- return null;
11
- }
7
+ function o(e) {
8
+ try {
9
+ return typeof window > "u" ? null : e === "local" ? window.localStorage : window.sessionStorage;
10
+ } catch {
11
+ return null;
12
+ }
12
13
  }
13
- function v(e, s) {
14
- f.get(I(e, s))?.forEach((u) => u());
14
+ function s(e, t) {
15
+ r.get(a(e, t))?.forEach((e) => e());
15
16
  }
16
- let E = !1;
17
- function N() {
18
- E || typeof window > "u" || (E = !0, window.addEventListener("storage", (e) => {
19
- if (e.key === null) {
20
- f.forEach((u) => u.forEach((r) => r()));
21
- return;
22
- }
23
- const s = e.storageArea === window.sessionStorage ? "session" : "local";
24
- v(s, e.key);
25
- }));
17
+ var c = !1;
18
+ function l() {
19
+ c || typeof window > "u" || (c = !0, window.addEventListener("storage", (e) => {
20
+ e.key === null ? r.forEach((e) => e.forEach((e) => e())) : s(e.storageArea === window.sessionStorage ? "session" : "local", e.key);
21
+ }));
26
22
  }
27
- function $(e, s, u = {}) {
28
- const { storage: r = "local", serialize: S = JSON.stringify, deserialize: m = JSON.parse, sync: y = !0 } = u, n = I(r, e), d = A(
29
- () => typeof s == "function" ? s() : s,
30
- // Only the first initial value matters, as with useState.
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- []
33
- ), g = w(() => {
34
- const o = p(r);
35
- let t = null;
36
- try {
37
- t = o ? o.getItem(e) : null;
38
- } catch {
39
- t = null;
40
- }
41
- if (t === null) {
42
- const l = i.get(n);
43
- return l && l.raw === null ? l.value : d;
44
- }
45
- const a = i.get(n);
46
- if (a && a.raw === t) return a.value;
47
- let c;
48
- try {
49
- c = m(t);
50
- } catch {
51
- return d;
52
- }
53
- return i.set(n, { raw: t, value: c }), c;
54
- }, [r, e, n, d, m]), b = w(
55
- (o) => {
56
- let t = f.get(n);
57
- return t || (t = /* @__PURE__ */ new Set(), f.set(n, t)), t.add(o), y && N(), () => {
58
- t.delete(o), t.size === 0 && f.delete(n);
59
- };
60
- },
61
- [n, y]
62
- ), z = J(b, g, () => d), L = w(
63
- (o) => {
64
- const t = g(), a = typeof o == "function" ? o(t) : o;
65
- let c = null;
66
- try {
67
- c = S(a);
68
- } catch {
69
- c = null;
70
- }
71
- const l = p(r);
72
- let h = null;
73
- if (l) {
74
- try {
75
- c !== null && l.setItem(e, c);
76
- } catch {
77
- }
78
- try {
79
- h = l.getItem(e);
80
- } catch {
81
- h = null;
82
- }
83
- }
84
- i.set(n, { raw: h, value: a }), v(r, e);
85
- },
86
- [g, S, r, e, n]
87
- ), M = w(() => {
88
- const o = p(r);
89
- try {
90
- o?.removeItem(e);
91
- } catch {
92
- }
93
- i.delete(n), v(r, e);
94
- }, [r, e, n]);
95
- return [z, L, M];
23
+ function u(c, u, d = {}) {
24
+ let { storage: f = "local", serialize: p = JSON.stringify, deserialize: m = JSON.parse, sync: h = !0 } = d, g = a(f, c), _ = t(() => typeof u == "function" ? u() : u, []), v = e(() => {
25
+ let e = o(f), t = null;
26
+ try {
27
+ t = e ? e.getItem(c) : null;
28
+ } catch {
29
+ t = null;
30
+ }
31
+ if (t === null) {
32
+ let e = i.get(g);
33
+ return e && e.raw === null ? e.value : _;
34
+ }
35
+ let n = i.get(g);
36
+ if (n && n.raw === t) return n.value;
37
+ let r;
38
+ try {
39
+ r = m(t);
40
+ } catch {
41
+ return _;
42
+ }
43
+ return i.set(g, {
44
+ raw: t,
45
+ value: r
46
+ }), r;
47
+ }, [
48
+ f,
49
+ c,
50
+ g,
51
+ _,
52
+ m
53
+ ]), y = e((e) => {
54
+ let t = r.get(g);
55
+ return t || (t = /* @__PURE__ */ new Set(), r.set(g, t)), t.add(e), h && l(), () => {
56
+ t.delete(e), t.size === 0 && r.delete(g);
57
+ };
58
+ }, [g, h]);
59
+ return [
60
+ n(y, v, () => _),
61
+ e((e) => {
62
+ let t = v(), n = typeof e == "function" ? e(t) : e, r = null;
63
+ try {
64
+ r = p(n);
65
+ } catch {
66
+ r = null;
67
+ }
68
+ let a = o(f), l = null;
69
+ if (a) {
70
+ try {
71
+ r !== null && a.setItem(c, r);
72
+ } catch {}
73
+ try {
74
+ l = a.getItem(c);
75
+ } catch {
76
+ l = null;
77
+ }
78
+ }
79
+ i.set(g, {
80
+ raw: l,
81
+ value: n
82
+ }), s(f, c);
83
+ }, [
84
+ v,
85
+ p,
86
+ f,
87
+ c,
88
+ g
89
+ ]),
90
+ e(() => {
91
+ let e = o(f);
92
+ try {
93
+ e?.removeItem(c);
94
+ } catch {}
95
+ i.delete(g), s(f, c);
96
+ }, [
97
+ f,
98
+ c,
99
+ g
100
+ ])
101
+ ];
96
102
  }
97
- export {
98
- $ as usePersistedState
99
- };
103
+ export { u as usePersistedState };
@@ -10,7 +10,8 @@ export interface PortalPosition {
10
10
  /**
11
11
  * Tracks the trigger's bounding rect for a portaled popover-style menu.
12
12
  * Recomputes on scroll (capture phase, so nested scroll containers like a
13
- * Modal body are caught too) and on window resize.
13
+ * Modal body are caught too), on window resize, and when the trigger itself
14
+ * resizes.
14
15
  *
15
16
  * Returns viewport-relative coordinates intended for use with
16
17
  * `position: fixed` on the portaled menu.