@overdoser/react-toolkit 0.18.0 → 0.20.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.
- package/AGENTS.md +51 -7
- package/CHANGELOG.md +162 -0
- package/components/Accordion/Accordion.d.ts +94 -0
- package/components/Accordion/Accordion.js +180 -0
- package/components/Accordion/Accordion.module.scss.js +36 -0
- package/components/Accordion/index.d.ts +2 -0
- package/components/Alert/Alert.d.ts +29 -1
- package/components/Alert/Alert.js +44 -30
- package/components/Alert/Alert.module.scss.js +24 -16
- package/components/Alert/index.d.ts +1 -1
- package/components/Card/Card.d.ts +86 -0
- package/components/Card/Card.js +132 -0
- package/components/Card/Card.module.scss.js +60 -0
- package/components/Card/index.d.ts +2 -0
- package/components/Chip/Chip.d.ts +86 -0
- package/components/Chip/Chip.js +141 -0
- package/components/Chip/Chip.module.scss.js +59 -0
- package/components/Chip/index.d.ts +2 -0
- package/components/CodeBlock/CodeBlock.d.ts +78 -0
- package/components/CodeBlock/CodeBlock.js +120 -0
- package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
- package/components/CodeBlock/index.d.ts +2 -0
- package/components/CommandPalette/CommandPalette.d.ts +141 -0
- package/components/CommandPalette/CommandPalette.js +397 -0
- package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
- package/components/CommandPalette/index.d.ts +2 -0
- package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
- package/components/ConfirmDialog/ConfirmDialog.js +201 -0
- package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
- package/components/ConfirmDialog/index.d.ts +2 -0
- package/components/Drawer/Drawer.d.ts +1 -0
- package/components/Drawer/Drawer.js +35 -36
- package/components/Drawer/Drawer.module.scss.js +20 -18
- package/components/Dropdown/Dropdown.d.ts +47 -7
- package/components/Dropdown/Dropdown.js +174 -81
- package/components/Dropdown/Dropdown.module.scss.js +40 -22
- package/components/Dropdown/DropdownItem.d.ts +31 -2
- package/components/Dropdown/DropdownItem.js +54 -27
- package/components/Dropdown/DropdownLabel.d.ts +11 -0
- package/components/Dropdown/DropdownLabel.js +11 -0
- package/components/Dropdown/DropdownSeparator.d.ts +12 -0
- package/components/Dropdown/DropdownSeparator.js +11 -0
- package/components/Dropdown/dropdownContext.d.ts +6 -0
- package/components/Dropdown/dropdownContext.js +5 -0
- package/components/Dropdown/index.d.ts +8 -2
- package/components/Dropdown/useContextMenu.d.ts +32 -0
- package/components/Dropdown/useContextMenu.js +18 -0
- package/components/EmptyState/EmptyState.d.ts +53 -0
- package/components/EmptyState/EmptyState.js +55 -0
- package/components/EmptyState/EmptyState.module.scss.js +25 -0
- package/components/EmptyState/index.d.ts +2 -0
- package/components/Form/FormField.js +25 -24
- package/components/ImageViewer/ImageViewer.d.ts +105 -0
- package/components/ImageViewer/ImageViewer.js +201 -0
- package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
- package/components/ImageViewer/index.d.ts +4 -0
- package/components/ImageViewer/useZoomPan.d.ts +94 -0
- package/components/ImageViewer/useZoomPan.js +141 -0
- package/components/Kbd/Kbd.d.ts +26 -0
- package/components/Kbd/Kbd.js +22 -0
- package/components/Kbd/Kbd.module.scss.js +17 -0
- package/components/Kbd/index.d.ts +2 -0
- package/components/KeyValueList/KeyValueList.d.ts +84 -0
- package/components/KeyValueList/KeyValueList.js +127 -0
- package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
- package/components/KeyValueList/index.d.ts +2 -0
- package/components/Modal/Modal.d.ts +1 -0
- package/components/Modal/Modal.js +40 -41
- package/components/Modal/Modal.module.scss.js +18 -16
- package/components/PageHeader/PageHeader.d.ts +61 -0
- package/components/PageHeader/PageHeader.js +73 -0
- package/components/PageHeader/PageHeader.module.scss.js +43 -0
- package/components/PageHeader/index.d.ts +2 -0
- package/components/ProgressBar/ProgressBar.d.ts +74 -0
- package/components/ProgressBar/ProgressBar.js +90 -0
- package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
- package/components/ProgressBar/index.d.ts +2 -0
- package/components/RelativeTime/RelativeTime.d.ts +45 -0
- package/components/RelativeTime/RelativeTime.js +43 -0
- package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
- package/components/RelativeTime/index.d.ts +2 -0
- package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
- package/components/SegmentedControl/SegmentedControl.js +131 -0
- package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
- package/components/SegmentedControl/index.d.ts +2 -0
- package/components/SplitPane/SplitPane.d.ts +61 -0
- package/components/SplitPane/SplitPane.js +171 -0
- package/components/SplitPane/SplitPane.module.scss.js +25 -0
- package/components/SplitPane/index.d.ts +2 -0
- package/components/StatCard/StatCard.d.ts +105 -0
- package/components/StatCard/StatCard.js +127 -0
- package/components/StatCard/StatCard.module.scss.js +72 -0
- package/components/StatCard/index.d.ts +2 -0
- package/components/StatusDot/StatusDot.d.ts +33 -0
- package/components/StatusDot/StatusDot.js +39 -0
- package/components/StatusDot/StatusDot.module.scss.js +32 -0
- package/components/StatusDot/index.d.ts +2 -0
- package/components/Table/Table.d.ts +140 -17
- package/components/Table/Table.js +382 -210
- package/components/Table/Table.module.scss.js +68 -46
- package/components/Table/index.d.ts +1 -1
- package/components/Table/useTableSort.d.ts +1 -1
- package/components/ThemeToggle/ThemeToggle.d.ts +40 -0
- package/components/ThemeToggle/ThemeToggle.js +98 -0
- package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
- package/components/ThemeToggle/index.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.js +29 -28
- package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
- package/components/inputs/Input/Input.d.ts +33 -1
- package/components/inputs/Input/Input.js +94 -35
- package/components/inputs/Input/Input.module.scss.js +14 -12
- package/components/inputs/Radio/Radio.d.ts +5 -4
- package/components/inputs/Radio/Radio.js +55 -50
- package/components/inputs/Radio/Radio.module.scss.js +12 -10
- package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
- package/components/inputs/SearchInput/SearchInput.js +116 -0
- package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
- package/components/inputs/SearchInput/index.d.ts +2 -0
- package/components/inputs/Select/Select.d.ts +52 -0
- package/components/inputs/Select/Select.js +494 -385
- package/components/inputs/Select/Select.module.scss.js +34 -30
- package/components/inputs/Switch/Switch.d.ts +15 -0
- package/components/inputs/Switch/Switch.js +8 -0
- package/components/inputs/Switch/index.d.ts +2 -0
- package/hooks/useDebouncedValue.d.ts +15 -0
- package/hooks/useDebouncedValue.js +15 -0
- package/hooks/useElementSize.d.ts +20 -0
- package/hooks/useElementSize.js +23 -0
- package/hooks/useKeyboard.d.ts +49 -5
- package/hooks/useKeyboard.js +66 -16
- package/hooks/useMediaQuery.d.ts +14 -0
- package/hooks/useMediaQuery.js +16 -0
- package/hooks/useNow.d.ts +14 -0
- package/hooks/useNow.js +35 -0
- package/hooks/usePersistedState.d.ts +30 -0
- package/hooks/usePersistedState.js +99 -0
- package/hooks/useResizable.d.ts +66 -0
- package/hooks/useResizable.js +105 -0
- package/hooks/useTheme.d.ts +33 -0
- package/hooks/useTheme.js +25 -0
- package/index.css +1 -1
- package/index.d.ts +58 -4
- package/index.js +208 -132
- package/index.layered.css +1 -1
- package/llms.txt +620 -26
- package/manifest.json +1795 -99
- package/package.json +1 -1
- package/recipes/confirm-modal.tsx +65 -53
- package/recipes/floating-copy-button.tsx +32 -28
- package/utils/formatBytes.d.ts +21 -0
- package/utils/formatBytes.js +14 -0
- package/utils/index.d.ts +6 -0
- package/utils/themeScript.d.ts +19 -0
- package/utils/themeScript.js +9 -0
- package/utils/timeAgo.d.ts +33 -0
- 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",
|
|
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:
|
|
9
|
-
searchableWrapper:
|
|
8
|
+
arrow: n,
|
|
9
|
+
searchableWrapper: l,
|
|
10
10
|
hiddenSelect: o,
|
|
11
11
|
searchableTrigger: a,
|
|
12
12
|
triggerOpen: m,
|
|
13
13
|
triggerLabel: g,
|
|
14
|
-
placeholder:
|
|
15
|
-
arrowInline:
|
|
14
|
+
placeholder: h,
|
|
15
|
+
arrowInline: d,
|
|
16
16
|
disabled: k,
|
|
17
|
-
visuallyHidden:
|
|
18
|
-
menu:
|
|
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:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
56
|
+
u as menu,
|
|
54
57
|
b as menuEnter,
|
|
55
58
|
w as menuItems,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
+
l as searchableWrapper,
|
|
64
67
|
r as sm,
|
|
68
|
+
v as spinner,
|
|
65
69
|
g as triggerLabel,
|
|
66
70
|
m as triggerOpen,
|
|
67
|
-
|
|
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,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
|
+
};
|
package/hooks/useKeyboard.d.ts
CHANGED
|
@@ -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
|
|
34
|
+
* Registers keydown listeners keyed by key name or chord.
|
|
3
35
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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:
|
|
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,
|
|
55
|
+
export declare function useKeyboard(handlers: Record<string, KeyboardHandler>, options?: boolean | UseKeyboardOptions): void;
|
|
56
|
+
export {};
|
package/hooks/useKeyboard.js
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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;
|
package/hooks/useNow.js
ADDED
|
@@ -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,99 @@
|
|
|
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}`;
|
|
5
|
+
}
|
|
6
|
+
function p(e) {
|
|
7
|
+
try {
|
|
8
|
+
return typeof window > "u" ? null : e === "local" ? window.localStorage : window.sessionStorage;
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function v(e, s) {
|
|
14
|
+
f.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
|
+
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
|
+
}));
|
|
26
|
+
}
|
|
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];
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
$ as usePersistedState
|
|
99
|
+
};
|
|
@@ -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;
|