@overdoser/react-toolkit 0.17.0 → 0.19.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 (160) hide show
  1. package/AGENTS.md +51 -7
  2. package/CHANGELOG.md +149 -0
  3. package/components/Accordion/Accordion.d.ts +94 -0
  4. package/components/Accordion/Accordion.js +180 -0
  5. package/components/Accordion/Accordion.module.scss.js +36 -0
  6. package/components/Accordion/index.d.ts +2 -0
  7. package/components/Alert/Alert.d.ts +29 -1
  8. package/components/Alert/Alert.js +44 -30
  9. package/components/Alert/Alert.module.scss.js +24 -16
  10. package/components/Alert/index.d.ts +1 -1
  11. package/components/Card/Card.d.ts +86 -0
  12. package/components/Card/Card.js +132 -0
  13. package/components/Card/Card.module.scss.js +60 -0
  14. package/components/Card/index.d.ts +2 -0
  15. package/components/Chip/Chip.d.ts +86 -0
  16. package/components/Chip/Chip.js +141 -0
  17. package/components/Chip/Chip.module.scss.js +59 -0
  18. package/components/Chip/index.d.ts +2 -0
  19. package/components/CodeBlock/CodeBlock.d.ts +78 -0
  20. package/components/CodeBlock/CodeBlock.js +120 -0
  21. package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
  22. package/components/CodeBlock/index.d.ts +2 -0
  23. package/components/CommandPalette/CommandPalette.d.ts +141 -0
  24. package/components/CommandPalette/CommandPalette.js +397 -0
  25. package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
  26. package/components/CommandPalette/index.d.ts +2 -0
  27. package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
  28. package/components/ConfirmDialog/ConfirmDialog.js +201 -0
  29. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
  30. package/components/ConfirmDialog/index.d.ts +2 -0
  31. package/components/Drawer/Drawer.d.ts +1 -0
  32. package/components/Drawer/Drawer.js +35 -36
  33. package/components/Drawer/Drawer.module.scss.js +20 -18
  34. package/components/Dropdown/Dropdown.d.ts +47 -7
  35. package/components/Dropdown/Dropdown.js +174 -81
  36. package/components/Dropdown/Dropdown.module.scss.js +40 -22
  37. package/components/Dropdown/DropdownItem.d.ts +31 -2
  38. package/components/Dropdown/DropdownItem.js +54 -27
  39. package/components/Dropdown/DropdownLabel.d.ts +11 -0
  40. package/components/Dropdown/DropdownLabel.js +11 -0
  41. package/components/Dropdown/DropdownSeparator.d.ts +12 -0
  42. package/components/Dropdown/DropdownSeparator.js +11 -0
  43. package/components/Dropdown/dropdownContext.d.ts +6 -0
  44. package/components/Dropdown/dropdownContext.js +5 -0
  45. package/components/Dropdown/index.d.ts +8 -2
  46. package/components/Dropdown/useContextMenu.d.ts +32 -0
  47. package/components/Dropdown/useContextMenu.js +18 -0
  48. package/components/EmptyState/EmptyState.d.ts +53 -0
  49. package/components/EmptyState/EmptyState.js +55 -0
  50. package/components/EmptyState/EmptyState.module.scss.js +25 -0
  51. package/components/EmptyState/index.d.ts +2 -0
  52. package/components/Form/FormField.js +25 -24
  53. package/components/ImageViewer/ImageViewer.d.ts +105 -0
  54. package/components/ImageViewer/ImageViewer.js +201 -0
  55. package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
  56. package/components/ImageViewer/index.d.ts +4 -0
  57. package/components/ImageViewer/useZoomPan.d.ts +94 -0
  58. package/components/ImageViewer/useZoomPan.js +141 -0
  59. package/components/Kbd/Kbd.d.ts +26 -0
  60. package/components/Kbd/Kbd.js +22 -0
  61. package/components/Kbd/Kbd.module.scss.js +17 -0
  62. package/components/Kbd/index.d.ts +2 -0
  63. package/components/KeyValueList/KeyValueList.d.ts +84 -0
  64. package/components/KeyValueList/KeyValueList.js +127 -0
  65. package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
  66. package/components/KeyValueList/index.d.ts +2 -0
  67. package/components/Loader/Loader.d.ts +104 -0
  68. package/components/Loader/Loader.js +186 -0
  69. package/components/Loader/Loader.module.scss.js +70 -0
  70. package/components/Loader/index.d.ts +2 -0
  71. package/components/Modal/Modal.d.ts +1 -0
  72. package/components/Modal/Modal.js +40 -41
  73. package/components/Modal/Modal.module.scss.js +18 -16
  74. package/components/PageHeader/PageHeader.d.ts +61 -0
  75. package/components/PageHeader/PageHeader.js +73 -0
  76. package/components/PageHeader/PageHeader.module.scss.js +43 -0
  77. package/components/PageHeader/index.d.ts +2 -0
  78. package/components/ProgressBar/ProgressBar.d.ts +74 -0
  79. package/components/ProgressBar/ProgressBar.js +90 -0
  80. package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
  81. package/components/ProgressBar/index.d.ts +2 -0
  82. package/components/RelativeTime/RelativeTime.d.ts +45 -0
  83. package/components/RelativeTime/RelativeTime.js +43 -0
  84. package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
  85. package/components/RelativeTime/index.d.ts +2 -0
  86. package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
  87. package/components/SegmentedControl/SegmentedControl.js +131 -0
  88. package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
  89. package/components/SegmentedControl/index.d.ts +2 -0
  90. package/components/SplitPane/SplitPane.d.ts +61 -0
  91. package/components/SplitPane/SplitPane.js +171 -0
  92. package/components/SplitPane/SplitPane.module.scss.js +25 -0
  93. package/components/SplitPane/index.d.ts +2 -0
  94. package/components/StatCard/StatCard.d.ts +105 -0
  95. package/components/StatCard/StatCard.js +127 -0
  96. package/components/StatCard/StatCard.module.scss.js +72 -0
  97. package/components/StatCard/index.d.ts +2 -0
  98. package/components/StatusDot/StatusDot.d.ts +33 -0
  99. package/components/StatusDot/StatusDot.js +39 -0
  100. package/components/StatusDot/StatusDot.module.scss.js +32 -0
  101. package/components/StatusDot/index.d.ts +2 -0
  102. package/components/Table/Table.d.ts +100 -2
  103. package/components/Table/Table.js +371 -210
  104. package/components/Table/Table.module.scss.js +68 -46
  105. package/components/Table/index.d.ts +1 -1
  106. package/components/ThemeToggle/ThemeToggle.d.ts +38 -0
  107. package/components/ThemeToggle/ThemeToggle.js +97 -0
  108. package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
  109. package/components/ThemeToggle/index.d.ts +2 -0
  110. package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
  111. package/components/inputs/Checkbox/Checkbox.js +29 -28
  112. package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
  113. package/components/inputs/Input/Input.d.ts +33 -1
  114. package/components/inputs/Input/Input.js +94 -35
  115. package/components/inputs/Input/Input.module.scss.js +14 -12
  116. package/components/inputs/Radio/Radio.d.ts +5 -4
  117. package/components/inputs/Radio/Radio.js +55 -50
  118. package/components/inputs/Radio/Radio.module.scss.js +12 -10
  119. package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
  120. package/components/inputs/SearchInput/SearchInput.js +116 -0
  121. package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
  122. package/components/inputs/SearchInput/index.d.ts +2 -0
  123. package/components/inputs/Select/Select.d.ts +52 -0
  124. package/components/inputs/Select/Select.js +494 -385
  125. package/components/inputs/Select/Select.module.scss.js +34 -30
  126. package/components/inputs/Switch/Switch.d.ts +15 -0
  127. package/components/inputs/Switch/Switch.js +8 -0
  128. package/components/inputs/Switch/index.d.ts +2 -0
  129. package/hooks/useDebouncedValue.d.ts +15 -0
  130. package/hooks/useDebouncedValue.js +15 -0
  131. package/hooks/useElementSize.d.ts +20 -0
  132. package/hooks/useElementSize.js +23 -0
  133. package/hooks/useKeyboard.d.ts +49 -5
  134. package/hooks/useKeyboard.js +66 -16
  135. package/hooks/useMediaQuery.d.ts +14 -0
  136. package/hooks/useMediaQuery.js +16 -0
  137. package/hooks/useNow.d.ts +14 -0
  138. package/hooks/useNow.js +35 -0
  139. package/hooks/usePersistedState.d.ts +30 -0
  140. package/hooks/usePersistedState.js +96 -0
  141. package/hooks/useResizable.d.ts +66 -0
  142. package/hooks/useResizable.js +105 -0
  143. package/hooks/useTheme.d.ts +33 -0
  144. package/hooks/useTheme.js +27 -0
  145. package/index.css +1 -1
  146. package/index.d.ts +60 -4
  147. package/index.js +208 -130
  148. package/index.layered.css +1 -1
  149. package/llms.txt +659 -25
  150. package/manifest.json +1797 -76
  151. package/package.json +1 -1
  152. package/recipes/confirm-modal.tsx +65 -53
  153. package/recipes/floating-copy-button.tsx +32 -28
  154. package/utils/formatBytes.d.ts +21 -0
  155. package/utils/formatBytes.js +14 -0
  156. package/utils/index.d.ts +6 -0
  157. package/utils/themeScript.d.ts +17 -0
  158. package/utils/themeScript.js +9 -0
  159. package/utils/timeAgo.d.ts +33 -0
  160. package/utils/timeAgo.js +37 -0
@@ -1,45 +1,47 @@
1
- const e = "crk-wrapper-SP2JE", r = "crk-sm-DqshL", c = "crk-md-j4AKI", t = "crk-lg-24Xd3", i = "crk-root-Uu9Ah", s = "crk-error-9oRU6", l = "crk-arrow-WU8ZW", n = "crk-searchableWrapper-7AL4l", o = "crk-hiddenSelect-s3DEx", a = "crk-searchableTrigger-m-GWV", m = "crk-triggerOpen-Lo8-j", g = "crk-triggerLabel-5rETZ", d = "crk-placeholder-teBBh", h = "crk-arrowInline-m-roG", k = "crk-disabled-pcSeq", u = "crk-visuallyHidden-2tTD5", p = "crk-menu--i-je", b = "crk-menuEnter-vJjLV", w = "crk-menuItems-VrZnE", S = "crk-item-fU3XI", T = "crk-itemHighlighted-MvR41", L = "crk-itemDisabled-KTUO8", D = "crk-itemSelected-42-BG", R = "crk-noResults-uicSW", v = "crk-multiTrigger-Pd3wJ", H = "crk-multiTriggerDisabled-9ajge", I = "crk-chip-TuYUB", W = "crk-chipLabel-H4JWu", E = "crk-chipRemove-Lfk0R", U = "crk-multiSearch-OrVeS", j = "crk-arrowMulti-Nh9Hr", B = "crk-itemCheck-DPB5A", O = {
1
+ const e = "crk-wrapper-SP2JE", r = "crk-sm-DqshL", c = "crk-md-j4AKI", t = "crk-lg-24Xd3", i = "crk-root-Uu9Ah", s = "crk-error-9oRU6", n = "crk-arrow-WU8ZW", l = "crk-searchableWrapper-7AL4l", o = "crk-hiddenSelect-s3DEx", a = "crk-searchableTrigger-m-GWV", m = "crk-triggerOpen-Lo8-j", g = "crk-triggerLabel-5rETZ", h = "crk-placeholder-teBBh", d = "crk-arrowInline-m-roG", k = "crk-disabled-pcSeq", p = "crk-visuallyHidden-2tTD5", u = "crk-menu--i-je", b = "crk-menuEnter-vJjLV", w = "crk-menuItems-VrZnE", S = "crk-item-fU3XI", T = "crk-itemHighlighted-MvR41", L = "crk-itemDisabled-KTUO8", D = "crk-itemSelected-42-BG", I = "crk-noResults-uicSW", R = "crk-match-Aej-J", v = "crk-spinner-I1ffm", H = "crk-multiTrigger-Pd3wJ", W = "crk-multiTriggerDisabled-9ajge", E = "crk-chip-TuYUB", j = "crk-chipLabel-H4JWu", U = "crk-chipRemove-Lfk0R", f = "crk-multiSearch-OrVeS", A = "crk-arrowMulti-Nh9Hr", B = "crk-itemCheck-DPB5A", J = {
2
2
  wrapper: e,
3
3
  sm: r,
4
4
  md: c,
5
5
  lg: t,
6
6
  root: i,
7
7
  error: s,
8
- arrow: l,
9
- searchableWrapper: n,
8
+ arrow: n,
9
+ searchableWrapper: l,
10
10
  hiddenSelect: o,
11
11
  searchableTrigger: a,
12
12
  triggerOpen: m,
13
13
  triggerLabel: g,
14
- placeholder: d,
15
- arrowInline: h,
14
+ placeholder: h,
15
+ arrowInline: d,
16
16
  disabled: k,
17
- visuallyHidden: u,
18
- menu: p,
17
+ visuallyHidden: p,
18
+ menu: u,
19
19
  menuEnter: b,
20
20
  menuItems: w,
21
21
  item: S,
22
22
  itemHighlighted: T,
23
23
  itemDisabled: L,
24
24
  itemSelected: D,
25
- noResults: R,
26
- multiTrigger: v,
27
- multiTriggerDisabled: H,
28
- chip: I,
29
- chipLabel: W,
30
- chipRemove: E,
31
- multiSearch: U,
32
- arrowMulti: j,
25
+ noResults: I,
26
+ match: R,
27
+ spinner: v,
28
+ multiTrigger: H,
29
+ multiTriggerDisabled: W,
30
+ chip: E,
31
+ chipLabel: j,
32
+ chipRemove: U,
33
+ multiSearch: f,
34
+ arrowMulti: A,
33
35
  itemCheck: B
34
36
  };
35
37
  export {
36
- l as arrow,
37
- h as arrowInline,
38
- j as arrowMulti,
39
- I as chip,
40
- W as chipLabel,
41
- E as chipRemove,
42
- O as default,
38
+ n as arrow,
39
+ d as arrowInline,
40
+ A as arrowMulti,
41
+ E as chip,
42
+ j as chipLabel,
43
+ U as chipRemove,
44
+ J as default,
43
45
  k as disabled,
44
46
  s as error,
45
47
  o as hiddenSelect,
@@ -49,21 +51,23 @@ export {
49
51
  T as itemHighlighted,
50
52
  D as itemSelected,
51
53
  t as lg,
54
+ R as match,
52
55
  c as md,
53
- p as menu,
56
+ u as menu,
54
57
  b as menuEnter,
55
58
  w as menuItems,
56
- U as multiSearch,
57
- v as multiTrigger,
58
- H as multiTriggerDisabled,
59
- R as noResults,
60
- d as placeholder,
59
+ f as multiSearch,
60
+ H as multiTrigger,
61
+ W as multiTriggerDisabled,
62
+ I as noResults,
63
+ h as placeholder,
61
64
  i as root,
62
65
  a as searchableTrigger,
63
- n as searchableWrapper,
66
+ l as searchableWrapper,
64
67
  r as sm,
68
+ v as spinner,
65
69
  g as triggerLabel,
66
70
  m as triggerOpen,
67
- u as visuallyHidden,
71
+ p as visuallyHidden,
68
72
  e as wrapper
69
73
  };
@@ -0,0 +1,15 @@
1
+ import { CheckboxProps, CheckboxClasses } from '../Checkbox/Checkbox';
2
+ /** Same props as `Checkbox` minus `variant` / `indeterminate` (fixed to the switch look). */
3
+ export type SwitchProps = Omit<CheckboxProps, 'variant' | 'indeterminate'>;
4
+ /** Same internal elements as `Checkbox`: `{ root, input, label }`. */
5
+ export type SwitchClasses = CheckboxClasses;
6
+ /**
7
+ * Toggle switch. A discoverable alias for `<Checkbox variant="switch">` —
8
+ * the underlying `<input type="checkbox">`, its accessibility and form
9
+ * behaviour are identical, so it binds inside `FormField` for a boolean field
10
+ * exactly like `Checkbox` does.
11
+ *
12
+ * @example
13
+ * <Switch label="Notifications" checked={on} onChange={(e) => setOn(e.target.checked)} />
14
+ */
15
+ export declare const Switch: import('react').ForwardRefExoticComponent<Omit<SwitchProps, "ref"> & import('react').RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,8 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import { forwardRef as i } from "react";
3
+ import { Checkbox as m } from "../Checkbox/Checkbox.js";
4
+ const a = i((o, r) => /* @__PURE__ */ t(m, { ref: r, variant: "switch", ...o }));
5
+ a.displayName = "Switch";
6
+ export {
7
+ a as Switch
8
+ };
@@ -0,0 +1,2 @@
1
+ export { Switch } from './Switch';
2
+ export type { SwitchProps, SwitchClasses } from './Switch';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Returns `value` after it has stopped changing for `delay` ms. The first
3
+ * render returns `value` immediately.
4
+ *
5
+ * @param value - The rapidly changing source value (an input's text).
6
+ * @param delay - Quiet period in ms. @default 300
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const [query, setQuery] = useState('');
11
+ * const debounced = useDebouncedValue(query, 250);
12
+ * useEffect(() => { search(debounced); }, [debounced]);
13
+ * ```
14
+ */
15
+ export declare function useDebouncedValue<T>(value: T, delay?: number): T;
@@ -0,0 +1,15 @@
1
+ import { useState as u, useEffect as c } from "react";
2
+ function i(e, t = 300) {
3
+ const [n, o] = u(e);
4
+ return c(() => {
5
+ if (t <= 0) {
6
+ o(e);
7
+ return;
8
+ }
9
+ const r = setTimeout(() => o(e), t);
10
+ return () => clearTimeout(r);
11
+ }, [e, t]), n;
12
+ }
13
+ export {
14
+ i as useDebouncedValue
15
+ };
@@ -0,0 +1,20 @@
1
+ import { RefObject } from 'react';
2
+ export interface ElementSize {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ /**
7
+ * Tracks an element's content-box size with `ResizeObserver`. Returns
8
+ * `{ width: 0, height: 0 }` until the element is measured.
9
+ *
10
+ * @param ref - Ref to the element to observe.
11
+ * @param box - Which box to report. @default 'content-box'
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const ref = useRef<HTMLDivElement>(null);
16
+ * const { width } = useElementSize(ref);
17
+ * return <div ref={ref}>{width < 480 ? <Compact /> : <Full />}</div>;
18
+ * ```
19
+ */
20
+ export declare function useElementSize<T extends HTMLElement>(ref: RefObject<T | null>, box?: 'content-box' | 'border-box'): ElementSize;
@@ -0,0 +1,23 @@
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;
20
+ }
21
+ export {
22
+ g as useElementSize
23
+ };
@@ -1,12 +1,56 @@
1
+ import { RefObject } from 'react';
2
+ export type KeyboardHandler = (e: KeyboardEvent) => void;
3
+ export interface UseKeyboardOptions {
4
+ /** Enable/disable the listener without unmounting. @default true */
5
+ active?: boolean;
6
+ /**
7
+ * Skip plain printable keys (`'k'`, `'/'`, `'?'`) while the user is typing
8
+ * in an `<input>`, `<textarea>`, `<select>` or `contenteditable` element.
9
+ * Named keys (`Escape`, `Enter`, arrows) and modifier chords (`mod+k`)
10
+ * still fire there. @default true
11
+ */
12
+ ignoreEditable?: boolean;
13
+ /**
14
+ * Call `event.preventDefault()` when a handler matches. `undefined` means
15
+ * "only for chords with a modifier" (so `mod+k` doesn't also focus the
16
+ * browser's address bar, while a bare `ArrowDown` keeps scrolling).
17
+ * @default undefined
18
+ */
19
+ preventDefault?: boolean;
20
+ /** Listen on this element instead of `document`. */
21
+ target?: RefObject<HTMLElement | null> | null;
22
+ }
23
+ interface ParsedChord {
24
+ key: string;
25
+ ctrl: boolean;
26
+ alt: boolean;
27
+ shift: boolean;
28
+ meta: boolean;
29
+ hasModifier: boolean;
30
+ }
31
+ /** Parse `'mod+shift+k'` / `'Escape'` / `'?'` into a comparable shape. */
32
+ export declare function parseChord(chord: string): ParsedChord;
1
33
  /**
2
- * Registers global keydown listeners for the specified keys.
34
+ * Registers keydown listeners keyed by key name or chord.
3
35
  *
4
- * @param handlers - Map of `KeyboardEvent.key` values to their handler functions.
5
- * @param active - Whether listeners are currently enabled (default: `true`).
36
+ * Keys are `KeyboardEvent.key` values (`'Escape'`, `'Enter'`, `'ArrowDown'`,
37
+ * `'k'`, `'?'`) or chords joined with `+`: `'mod+k'`, `'ctrl+shift+z'`,
38
+ * `'alt+ArrowUp'`. `mod` is ⌘ on macOS and Ctrl elsewhere. Single characters
39
+ * match case-insensitively; `'shift+/'` and `'?'` are both accepted.
40
+ *
41
+ * Handlers are read through a ref, so an inline object is fine — the listener
42
+ * is not re-subscribed on every render. Plain printable keys are skipped
43
+ * while typing in an editable element unless `ignoreEditable: false`.
44
+ *
45
+ * @param handlers - Map of key / chord → handler.
46
+ * @param options - `boolean` is shorthand for `{ active }` (kept for
47
+ * backwards compatibility).
6
48
  *
7
49
  * @example
8
50
  * ```tsx
9
- * useKeyboard({ Escape: () => close(), Enter: () => confirm() }, isOpen);
51
+ * useKeyboard({ Escape: close, Enter: confirm }, isOpen);
52
+ * useKeyboard({ 'mod+k': openPalette, '/': focusSearch, 'mod+shift+z': redo });
10
53
  * ```
11
54
  */
12
- export declare function useKeyboard(handlers: Record<string, (e: KeyboardEvent) => void>, active?: boolean): void;
55
+ export declare function useKeyboard(handlers: Record<string, KeyboardHandler>, options?: boolean | UseKeyboardOptions): void;
56
+ export {};
@@ -1,19 +1,69 @@
1
- import { useCallback as u, useEffect as d } from "react";
2
- function f(n, o = !0) {
3
- const e = u(
4
- (t) => {
5
- const r = n[t.key];
6
- r && r(t);
7
- },
8
- [n]
9
- );
10
- d(() => {
11
- if (o)
12
- return document.addEventListener("keydown", e), () => {
13
- document.removeEventListener("keydown", e);
14
- };
15
- }, [o, e]);
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: "+"
25
+ };
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;
35
+ }
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;
38
+ }
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;
43
+ }
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]);
16
65
  }
17
66
  export {
18
- f as useKeyboard
67
+ v as parseChord,
68
+ C as useKeyboard
19
69
  };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Subscribes to a CSS media query. SSR-safe: returns `serverValue` on the
3
+ * server and on the first client render before hydration completes.
4
+ *
5
+ * @param query - e.g. `'(max-width: 768px)'`, `'(prefers-color-scheme: dark)'`.
6
+ * @param serverValue - Value used where `matchMedia` is unavailable. @default false
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const isMobile = useMediaQuery('(max-width: 768px)');
11
+ * const prefersDark = useMediaQuery('(prefers-color-scheme: dark)');
12
+ * ```
13
+ */
14
+ export declare function useMediaQuery(query: string, serverValue?: boolean): boolean;
@@ -0,0 +1,16 @@
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);
13
+ }
14
+ export {
15
+ r as useMediaQuery
16
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The current time (ms since epoch), re-rendering every `interval` ms.
3
+ * Subscribers with the same interval share a single timer.
4
+ *
5
+ * @param interval - Tick period in ms. @default 1000
6
+ * @param active - Pause ticking (the last value is kept). @default true
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const now = useNow(60_000);
11
+ * return <span>{Math.round((now - startedAt) / 60_000)} min ago</span>;
12
+ * ```
13
+ */
14
+ export declare function useNow(interval?: number, active?: boolean): number;
@@ -0,0 +1,35 @@
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
+ };
18
+ }
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);
32
+ }
33
+ export {
34
+ d as useNow
35
+ };
@@ -0,0 +1,30 @@
1
+ export interface UsePersistedStateOptions<T> {
2
+ /** Which Web Storage to use. @default 'local' */
3
+ storage?: 'local' | 'session';
4
+ /** Serialize before writing. @default JSON.stringify */
5
+ serialize?: (value: T) => string;
6
+ /** Parse what was read. A throw falls back to the initial value. @default JSON.parse */
7
+ deserialize?: (raw: string) => T;
8
+ /** Follow changes made in other tabs (via the `storage` event). @default true */
9
+ sync?: boolean;
10
+ }
11
+ /**
12
+ * `useState` persisted to `localStorage` (or `sessionStorage`).
13
+ *
14
+ * - SSR-safe: the server snapshot is `initialValue`; hydration then reads storage.
15
+ * - Private-mode / quota safe: storage failures fall back to in-memory state.
16
+ * - Two hooks on the same key stay in sync in the same tab, and (by default)
17
+ * across tabs.
18
+ * - Built on `useSyncExternalStore`, so the value is read once per change and
19
+ * never tears.
20
+ *
21
+ * @returns `[value, setValue, remove]` — `setValue` accepts a value or an
22
+ * updater like `useState`; `remove` deletes the key and reverts to `initialValue`.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const [theme, setTheme] = usePersistedState<'light' | 'dark'>('theme', 'light');
27
+ * const [draft, setDraft, clearDraft] = usePersistedState('draft', '', { storage: 'session' });
28
+ * ```
29
+ */
30
+ export declare function usePersistedState<T>(key: string, initialValue: T | (() => T), options?: UsePersistedStateOptions<T>): [T, (next: T | ((prev: T) => T)) => void, () => void];
@@ -0,0 +1,96 @@
1
+ import { useMemo as A, useCallback as f, useSyncExternalStore as J } from "react";
2
+ const i = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
3
+ function I(e, s) {
4
+ return `${e}:${s}`;
5
+ }
6
+ function v(e) {
7
+ try {
8
+ return typeof window > "u" ? null : e === "local" ? window.localStorage : window.sessionStorage;
9
+ } catch {
10
+ return null;
11
+ }
12
+ }
13
+ function S(e, s) {
14
+ i.get(I(e, s))?.forEach((u) => u());
15
+ }
16
+ let E = !1;
17
+ function N() {
18
+ E || typeof window > "u" || (E = !0, window.addEventListener("storage", (e) => {
19
+ if (e.key === null) {
20
+ i.forEach((u) => u.forEach((n) => n()));
21
+ return;
22
+ }
23
+ const s = e.storageArea === window.sessionStorage ? "session" : "local";
24
+ S(s, e.key);
25
+ }));
26
+ }
27
+ function $(e, s, u = {}) {
28
+ const { storage: n = "local", serialize: m = JSON.stringify, deserialize: p = JSON.parse, sync: y = !0 } = u, r = I(n, e), l = 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
+ ), w = f(() => {
34
+ const o = v(n);
35
+ let t = null;
36
+ try {
37
+ t = o ? o.getItem(e) : null;
38
+ } catch {
39
+ t = null;
40
+ }
41
+ const a = d.get(r);
42
+ if (a && a.raw === t) return a.value;
43
+ let c = l;
44
+ if (t !== null)
45
+ try {
46
+ c = p(t);
47
+ } catch {
48
+ c = l;
49
+ }
50
+ return d.set(r, { raw: t, value: c }), c;
51
+ }, [n, e, r, l, p]), b = f(
52
+ (o) => {
53
+ let t = i.get(r);
54
+ return t || (t = /* @__PURE__ */ new Set(), i.set(r, t)), t.add(o), y && N(), () => {
55
+ t.delete(o), t.size === 0 && i.delete(r);
56
+ };
57
+ },
58
+ [r, y]
59
+ ), z = J(b, w, () => l), L = f(
60
+ (o) => {
61
+ const t = w(), a = typeof o == "function" ? o(t) : o;
62
+ let c = null;
63
+ try {
64
+ c = m(a);
65
+ } catch {
66
+ c = null;
67
+ }
68
+ const g = v(n);
69
+ let h = null;
70
+ if (g) {
71
+ try {
72
+ c !== null && g.setItem(e, c);
73
+ } catch {
74
+ }
75
+ try {
76
+ h = g.getItem(e);
77
+ } catch {
78
+ h = null;
79
+ }
80
+ }
81
+ d.set(r, { raw: h, value: a }), S(n, e);
82
+ },
83
+ [w, m, n, e, r]
84
+ ), M = f(() => {
85
+ const o = v(n);
86
+ try {
87
+ o?.removeItem(e);
88
+ } catch {
89
+ }
90
+ d.set(r, { raw: null, value: l }), S(n, e);
91
+ }, [n, e, r, l]);
92
+ return [z, L, M];
93
+ }
94
+ export {
95
+ $ as usePersistedState
96
+ };
@@ -0,0 +1,66 @@
1
+ import { KeyboardEvent, PointerEvent } from 'react';
2
+ export interface UseResizableOptions {
3
+ /** Controlled size (px). */
4
+ size?: number;
5
+ /** Initial size (px) when uncontrolled; also what `reset()` returns to. @default 0 */
6
+ defaultSize?: number;
7
+ /** Lower bound (px). @default 0 */
8
+ min?: number;
9
+ /** Upper bound (px), or a function read at the start of each drag / key press. @default Infinity */
10
+ max?: number | (() => number);
11
+ /** Drag axis. @default 'x' */
12
+ axis?: 'x' | 'y';
13
+ /** Dragging left/up grows the size (for a right- or bottom-anchored pane). @default false */
14
+ invert?: boolean;
15
+ /** Keyboard step in px (Shift = ×10). @default 16 */
16
+ step?: number;
17
+ /** Fires with every clamped size while dragging or on key presses; `raw` is the unclamped value. */
18
+ onResize?: (size: number, raw: number) => void;
19
+ /** Fires on pointer down / first key press. */
20
+ onResizeStart?: () => void;
21
+ /** Fires on pointer up / after a key press with the final size. */
22
+ onResizeEnd?: (size: number) => void;
23
+ /** Ignore pointer and keyboard input. @default false */
24
+ disabled?: boolean;
25
+ }
26
+ export interface UseResizableHandleProps {
27
+ onPointerDown: (e: PointerEvent<HTMLElement>) => void;
28
+ onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;
29
+ onDoubleClick: () => void;
30
+ role: 'separator';
31
+ 'aria-orientation': 'horizontal' | 'vertical';
32
+ 'aria-valuenow': number;
33
+ 'aria-valuemin': number;
34
+ 'aria-valuemax': number | undefined;
35
+ 'aria-disabled': boolean | undefined;
36
+ tabIndex: number;
37
+ }
38
+ export interface UseResizableResult {
39
+ /** Current clamped size (px). */
40
+ size: number;
41
+ /** Set the size programmatically (clamped). */
42
+ setSize: (size: number) => void;
43
+ /** True while a pointer drag is in progress. */
44
+ isResizing: boolean;
45
+ /** Spread onto the handle element. */
46
+ handleProps: UseResizableHandleProps;
47
+ /** Back to `defaultSize` (or the controlled value). */
48
+ reset: () => void;
49
+ }
50
+ /**
51
+ * Drag + keyboard engine for resizable panes, drawers and columns. Returns a
52
+ * clamped `size` and `handleProps` to spread on a `role="separator"` handle.
53
+ *
54
+ * - Pointer: capture on the handle, delta from the press point, `user-select`
55
+ * and the resize cursor applied to `<body>` while dragging.
56
+ * - Keyboard: Arrow keys ±`step` (Shift ×10), Home/End = min/max.
57
+ * - Double-click on the handle resets to `defaultSize`.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * const { size, handleProps } = useResizable({ defaultSize: 280, min: 160, max: () => el.clientWidth - 320 });
62
+ * <aside style={{ width: size }}>…</aside>
63
+ * <div {...handleProps} aria-label="Resize sidebar" className={styles.handle} />
64
+ * ```
65
+ */
66
+ export declare function useResizable(options?: UseResizableOptions): UseResizableResult;