@forgedevstack/bear 1.0.6 → 1.0.8
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/dist/components/Alert/Alert.cjs +1 -1
- package/dist/components/Alert/Alert.const.cjs +1 -1
- package/dist/components/Alert/Alert.const.d.ts +4 -0
- package/dist/components/Alert/Alert.const.js +9 -15
- package/dist/components/Alert/Alert.js +43 -38
- package/dist/components/AppBar/AppBar.cjs +1 -1
- package/dist/components/AppBar/AppBar.js +20 -16
- package/dist/components/BackTop/BackTop.cjs +1 -0
- package/dist/components/BackTop/BackTop.const.cjs +1 -0
- package/dist/components/BackTop/BackTop.const.d.ts +34 -0
- package/dist/components/BackTop/BackTop.const.js +29 -0
- package/dist/components/BackTop/BackTop.d.ts +21 -0
- package/dist/components/BackTop/BackTop.js +87 -0
- package/dist/components/BackTop/BackTop.types.d.ts +28 -0
- package/dist/components/BackTop/index.d.ts +3 -0
- package/dist/components/Badge/Badge.constants.d.ts +4 -4
- package/dist/components/Badge/Badge.types.d.ts +3 -3
- package/dist/components/BottomSheet/BottomSheet.cjs +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/dist/components/BottomSheet/BottomSheet.js +103 -0
- package/dist/components/BottomSheet/BottomSheet.types.d.ts +13 -0
- package/dist/components/BottomSheet/index.d.ts +2 -0
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.constants.cjs +38 -48
- package/dist/components/Button/Button.constants.d.ts +22 -3
- package/dist/components/Button/Button.constants.js +51 -50
- package/dist/components/Button/Button.d.ts +14 -7
- package/dist/components/Button/Button.js +123 -43
- package/dist/components/Button/Button.types.d.ts +26 -4
- package/dist/components/Calendar/Calendar.cjs +1 -1
- package/dist/components/Calendar/Calendar.js +3 -2
- package/dist/components/Card/Card.const.d.ts +2 -2
- package/dist/components/Card/Card.types.d.ts +2 -2
- package/dist/components/Chat/Chat.cjs +1 -0
- package/dist/components/Chat/Chat.const.cjs +1 -0
- package/dist/components/Chat/Chat.const.d.ts +26 -0
- package/dist/components/Chat/Chat.const.js +29 -0
- package/dist/components/Chat/Chat.d.ts +21 -0
- package/dist/components/Chat/Chat.js +179 -0
- package/dist/components/Chat/Chat.types.d.ts +55 -0
- package/dist/components/Chat/index.d.ts +2 -0
- package/dist/components/Confetti/Confetti.cjs +1 -0
- package/dist/components/Confetti/Confetti.const.cjs +1 -0
- package/dist/components/Confetti/Confetti.const.d.ts +16 -0
- package/dist/components/Confetti/Confetti.const.js +36 -0
- package/dist/components/Confetti/Confetti.d.ts +23 -0
- package/dist/components/Confetti/Confetti.js +94 -0
- package/dist/components/Confetti/Confetti.types.d.ts +50 -0
- package/dist/components/Confetti/index.d.ts +4 -0
- package/dist/components/Confetti/useConfetti.cjs +1 -0
- package/dist/components/Confetti/useConfetti.d.ts +13 -0
- package/dist/components/Confetti/useConfetti.js +12 -0
- package/dist/components/DatePicker/DatePicker.cjs +1 -1
- package/dist/components/DatePicker/DatePicker.js +3 -2
- package/dist/components/DiffViewer/DiffViewer.cjs +1 -0
- package/dist/components/DiffViewer/DiffViewer.const.cjs +1 -0
- package/dist/components/DiffViewer/DiffViewer.const.d.ts +18 -0
- package/dist/components/DiffViewer/DiffViewer.const.js +21 -0
- package/dist/components/DiffViewer/DiffViewer.d.ts +18 -0
- package/dist/components/DiffViewer/DiffViewer.js +127 -0
- package/dist/components/DiffViewer/DiffViewer.types.d.ts +40 -0
- package/dist/components/DiffViewer/DiffViewer.utils.cjs +3 -0
- package/dist/components/DiffViewer/DiffViewer.utils.d.ts +9 -0
- package/dist/components/DiffViewer/DiffViewer.utils.js +39 -0
- package/dist/components/DiffViewer/index.d.ts +2 -0
- package/dist/components/Drawer/Drawer.cjs +1 -1
- package/dist/components/Drawer/Drawer.js +35 -35
- package/dist/components/EmojiPicker/EmojiPicker.cjs +1 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.cjs +1 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.d.ts +5 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.js +10 -0
- package/dist/components/EmojiPicker/EmojiPicker.d.ts +3 -0
- package/dist/components/EmojiPicker/EmojiPicker.js +63 -0
- package/dist/components/EmojiPicker/EmojiPicker.types.d.ts +6 -0
- package/dist/components/EmojiPicker/index.d.ts +3 -0
- package/dist/components/FloatingChat/FloatingChat.cjs +1 -0
- package/dist/components/FloatingChat/FloatingChat.const.cjs +1 -0
- package/dist/components/FloatingChat/FloatingChat.const.d.ts +12 -0
- package/dist/components/FloatingChat/FloatingChat.const.js +15 -0
- package/dist/components/FloatingChat/FloatingChat.d.ts +19 -0
- package/dist/components/FloatingChat/FloatingChat.js +144 -0
- package/dist/components/FloatingChat/FloatingChat.types.d.ts +44 -0
- package/dist/components/FloatingChat/index.d.ts +2 -0
- package/dist/components/JsonViewer/JsonViewer.cjs +1 -0
- package/dist/components/JsonViewer/JsonViewer.const.cjs +1 -0
- package/dist/components/JsonViewer/JsonViewer.const.d.ts +4 -0
- package/dist/components/JsonViewer/JsonViewer.const.js +24 -0
- package/dist/components/JsonViewer/JsonViewer.d.ts +17 -0
- package/dist/components/JsonViewer/JsonViewer.js +195 -0
- package/dist/components/JsonViewer/JsonViewer.types.d.ts +54 -0
- package/dist/components/JsonViewer/index.d.ts +2 -0
- package/dist/components/Kanban/Kanban.cjs +1 -0
- package/dist/components/Kanban/Kanban.d.ts +3 -0
- package/dist/components/Kanban/Kanban.js +91 -0
- package/dist/components/Kanban/Kanban.types.d.ts +21 -0
- package/dist/components/Kanban/index.d.ts +2 -0
- package/dist/components/MentionsInput/MentionsInput.cjs +1 -0
- package/dist/components/MentionsInput/MentionsInput.d.ts +3 -0
- package/dist/components/MentionsInput/MentionsInput.js +140 -0
- package/dist/components/MentionsInput/MentionsInput.types.d.ts +21 -0
- package/dist/components/MentionsInput/index.d.ts +2 -0
- package/dist/components/QRCode/QRCode.cjs +1 -0
- package/dist/components/QRCode/QRCode.const.cjs +1 -0
- package/dist/components/QRCode/QRCode.const.d.ts +21 -0
- package/dist/components/QRCode/QRCode.const.js +11 -0
- package/dist/components/QRCode/QRCode.d.ts +29 -0
- package/dist/components/QRCode/QRCode.js +68 -0
- package/dist/components/QRCode/QRCode.types.d.ts +32 -0
- package/dist/components/QRCode/QRCode.utils.cjs +1 -0
- package/dist/components/QRCode/QRCode.utils.d.ts +12 -0
- package/dist/components/QRCode/QRCode.utils.js +74 -0
- package/dist/components/QRCode/index.d.ts +3 -0
- package/dist/components/RichEditor/RichEditor.cjs +1 -1
- package/dist/components/RichEditor/RichEditor.const.cjs +2 -2
- package/dist/components/RichEditor/RichEditor.const.d.ts +4 -1
- package/dist/components/RichEditor/RichEditor.const.js +51 -18
- package/dist/components/RichEditor/RichEditor.js +106 -105
- package/dist/components/RichEditor/components/ToolbarColorPicker/ToolbarColorPicker.cjs +1 -1
- package/dist/components/RichEditor/components/ToolbarColorPicker/ToolbarColorPicker.js +105 -95
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.cjs +1 -1
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.d.ts +2 -0
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.js +47 -29
- package/dist/components/SegmentedControl/SegmentedControl.cjs +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +3 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +58 -0
- package/dist/components/SegmentedControl/SegmentedControl.types.d.ts +16 -0
- package/dist/components/SegmentedControl/index.d.ts +2 -0
- package/dist/components/SignPad/SignPad.cjs +1 -1
- package/dist/components/SignPad/SignPad.js +98 -90
- package/dist/components/SliderRange/SliderRange.cjs +1 -0
- package/dist/components/SliderRange/SliderRange.d.ts +3 -0
- package/dist/components/SliderRange/SliderRange.js +142 -0
- package/dist/components/SliderRange/SliderRange.types.d.ts +17 -0
- package/dist/components/SliderRange/index.d.ts +2 -0
- package/dist/components/Spinner/Spinner.types.d.ts +2 -2
- package/dist/components/TagsInput/TagsInput.cjs +1 -0
- package/dist/components/TagsInput/TagsInput.d.ts +3 -0
- package/dist/components/TagsInput/TagsInput.js +100 -0
- package/dist/components/TagsInput/TagsInput.types.d.ts +16 -0
- package/dist/components/TagsInput/index.d.ts +2 -0
- package/dist/components/Terminal/Terminal.cjs +1 -0
- package/dist/components/Terminal/Terminal.const.cjs +1 -0
- package/dist/components/Terminal/Terminal.const.d.ts +32 -0
- package/dist/components/Terminal/Terminal.const.js +42 -0
- package/dist/components/Terminal/Terminal.d.ts +27 -0
- package/dist/components/Terminal/Terminal.js +155 -0
- package/dist/components/Terminal/Terminal.types.d.ts +49 -0
- package/dist/components/Terminal/index.d.ts +2 -0
- package/dist/components/Tour/Tour.cjs +1 -0
- package/dist/components/Tour/Tour.const.cjs +1 -0
- package/dist/components/Tour/Tour.const.d.ts +25 -0
- package/dist/components/Tour/Tour.const.js +38 -0
- package/dist/components/Tour/Tour.d.ts +17 -0
- package/dist/components/Tour/Tour.js +179 -0
- package/dist/components/Tour/Tour.types.d.ts +80 -0
- package/dist/components/Tour/index.d.ts +4 -0
- package/dist/components/Tour/useTour.cjs +1 -0
- package/dist/components/Tour/useTour.d.ts +14 -0
- package/dist/components/Tour/useTour.js +27 -0
- package/dist/components/Typography/Typography.cjs +1 -1
- package/dist/components/Typography/Typography.d.ts +5 -1
- package/dist/components/Typography/Typography.js +93 -57
- package/dist/components/Typography/Typography.types.d.ts +29 -2
- package/dist/components/VirtualList/VirtualList.cjs +1 -0
- package/dist/components/VirtualList/VirtualList.d.ts +3 -0
- package/dist/components/VirtualList/VirtualList.js +68 -0
- package/dist/components/VirtualList/VirtualList.types.d.ts +10 -0
- package/dist/components/VirtualList/index.d.ts +2 -0
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.d.ts +35 -1
- package/dist/components/index.js +240 -198
- package/dist/context/BearProvider.cjs +1 -1
- package/dist/context/BearProvider.d.ts +110 -5
- package/dist/context/BearProvider.js +198 -53
- package/dist/context/defaultTheme.cjs +1 -1
- package/dist/context/defaultTheme.js +11 -11
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/index.js +56 -35
- package/dist/hooks/useBearComponent/index.d.ts +2 -0
- package/dist/hooks/useBearComponent/useBearComponent.cjs +1 -0
- package/dist/hooks/useBearComponent/useBearComponent.d.ts +71 -0
- package/dist/hooks/useBearComponent/useBearComponent.js +54 -0
- package/dist/hooks/useBearComponent/useBearComponent.types.d.ts +40 -0
- package/dist/hooks/useDragDrop/index.d.ts +2 -0
- package/dist/hooks/useDragDrop/useDragDrop.cjs +1 -0
- package/dist/hooks/useDragDrop/useDragDrop.d.ts +22 -0
- package/dist/hooks/useDragDrop/useDragDrop.js +56 -0
- package/dist/hooks/useDragDrop/useDragDrop.types.d.ts +55 -0
- package/dist/hooks/useIdle/index.d.ts +2 -0
- package/dist/hooks/useIdle/useIdle.cjs +1 -0
- package/dist/hooks/useIdle/useIdle.d.ts +22 -0
- package/dist/hooks/useIdle/useIdle.js +66 -0
- package/dist/hooks/useIdle/useIdle.types.d.ts +29 -0
- package/dist/hooks/useLazyLoad/index.d.ts +2 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.cjs +1 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.d.ts +26 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.js +27 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.types.d.ts +25 -0
- package/dist/hooks/useLongPress/index.d.ts +2 -0
- package/dist/hooks/useLongPress/useLongPress.cjs +1 -0
- package/dist/hooks/useLongPress/useLongPress.d.ts +17 -0
- package/dist/hooks/useLongPress/useLongPress.js +44 -0
- package/dist/hooks/useLongPress/useLongPress.types.d.ts +26 -0
- package/dist/hooks/useOnline/index.d.ts +2 -0
- package/dist/hooks/useOnline/useOnline.cjs +1 -0
- package/dist/hooks/useOnline/useOnline.d.ts +16 -0
- package/dist/hooks/useOnline/useOnline.js +25 -0
- package/dist/hooks/useOnline/useOnline.types.d.ts +15 -0
- package/dist/hooks/usePageVisibility/index.d.ts +2 -0
- package/dist/hooks/usePageVisibility/usePageVisibility.cjs +1 -0
- package/dist/hooks/usePageVisibility/usePageVisibility.d.ts +19 -0
- package/dist/hooks/usePageVisibility/usePageVisibility.js +26 -0
- package/dist/hooks/usePageVisibility/usePageVisibility.types.d.ts +15 -0
- package/dist/hooks/useSpotlight/index.d.ts +2 -0
- package/dist/hooks/useSpotlight/useSpotlight.cjs +1 -0
- package/dist/hooks/useSpotlight/useSpotlight.d.ts +24 -0
- package/dist/hooks/useSpotlight/useSpotlight.js +49 -0
- package/dist/hooks/useSpotlight/useSpotlight.types.d.ts +23 -0
- package/dist/hooks/useWebSocket/index.d.ts +2 -0
- package/dist/hooks/useWebSocket/useWebSocket.cjs +1 -0
- package/dist/hooks/useWebSocket/useWebSocket.d.ts +22 -0
- package/dist/hooks/useWebSocket/useWebSocket.js +75 -0
- package/dist/hooks/useWebSocket/useWebSocket.types.d.ts +44 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +327 -264
- package/dist/styles.css +1 -1
- package/dist/types/component.types.d.ts +125 -42
- package/dist/types/theme.types.d.ts +82 -0
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { BearComponentOverrides, ButtonVariantsConfig } from '../../types/component.types';
|
|
3
|
+
import { UseBearComponentReturn, BearComponentContextValue } from './useBearComponent.types';
|
|
4
|
+
interface BearComponentProviderProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/** Initial component overrides */
|
|
7
|
+
components?: BearComponentOverrides;
|
|
8
|
+
/** Initial variant configurations */
|
|
9
|
+
variants?: {
|
|
10
|
+
Button?: ButtonVariantsConfig;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Provider for global component customization
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <BearComponentProvider
|
|
19
|
+
* components={{
|
|
20
|
+
* Button: {
|
|
21
|
+
* root: { borderRadius: '9999px' }
|
|
22
|
+
* }
|
|
23
|
+
* }}
|
|
24
|
+
* variants={{
|
|
25
|
+
* Button: {
|
|
26
|
+
* primary: {
|
|
27
|
+
* bg: '#ec4899',
|
|
28
|
+
* bgHover: '#db2777',
|
|
29
|
+
* text: '#ffffff'
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* }}
|
|
33
|
+
* >
|
|
34
|
+
* <App />
|
|
35
|
+
* </BearComponentProvider>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const BearComponentProvider: ({ children, components: initialComponents, variants: initialVariants, }: BearComponentProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
/**
|
|
40
|
+
* Access the component customization context
|
|
41
|
+
*/
|
|
42
|
+
export declare const useBearComponentContext: () => BearComponentContextValue | null;
|
|
43
|
+
/**
|
|
44
|
+
* Hook to get and apply component style overrides
|
|
45
|
+
*
|
|
46
|
+
* @param componentKey - The component key (e.g., 'Button', 'Input')
|
|
47
|
+
* @param defaultStyles - Optional default styles to merge with
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* // Inside a component
|
|
52
|
+
* const { getStyles, mergeStyles, hasOverrides } = useBearComponent('Button');
|
|
53
|
+
*
|
|
54
|
+
* return (
|
|
55
|
+
* <button style={mergeStyles('root', { padding: '8px' })}>
|
|
56
|
+
* <span style={getStyles('text')}>Click me</span>
|
|
57
|
+
* </button>
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const useBearComponent: <K extends keyof BearComponentOverrides>(componentKey: K, defaultStyles?: BearComponentOverrides[K]) => UseBearComponentReturn;
|
|
62
|
+
/**
|
|
63
|
+
* Shorthand alias for useBearComponent
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* const { getStyles } = useBC('Button');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const useBC: <K extends keyof BearComponentOverrides>(componentKey: K, defaultStyles?: BearComponentOverrides[K]) => UseBearComponentReturn;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as b } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as O, useState as d, useCallback as r, useMemo as y, useContext as x } from "react";
|
|
3
|
+
const v = O(null), h = ({
|
|
4
|
+
children: p,
|
|
5
|
+
components: m = {},
|
|
6
|
+
variants: u = {}
|
|
7
|
+
}) => {
|
|
8
|
+
const [t, c] = d(m), [a, l] = d(u), o = r((e, S) => {
|
|
9
|
+
c((i) => ({
|
|
10
|
+
...i,
|
|
11
|
+
[e]: {
|
|
12
|
+
...i[e] || {},
|
|
13
|
+
...S
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
}, []), n = r((e, S) => {
|
|
17
|
+
l((i) => ({
|
|
18
|
+
...i,
|
|
19
|
+
[e]: {
|
|
20
|
+
...i[e] || {},
|
|
21
|
+
...S
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
}, []), s = r((e) => t[e], [t]), C = r((e) => a[e], [a]), g = r(() => {
|
|
25
|
+
c({}), l({});
|
|
26
|
+
}, []), B = y(() => ({
|
|
27
|
+
components: t,
|
|
28
|
+
variants: a,
|
|
29
|
+
registerComponent: o,
|
|
30
|
+
registerVariant: n,
|
|
31
|
+
getComponentStyles: s,
|
|
32
|
+
getVariantConfig: C,
|
|
33
|
+
clearOverrides: g
|
|
34
|
+
}), [t, a, o, n, s, C, g]);
|
|
35
|
+
return /* @__PURE__ */ b(v.Provider, { value: B, children: p });
|
|
36
|
+
}, j = () => x(v), P = (p, m) => {
|
|
37
|
+
const u = x(v), t = u == null ? void 0 : u.components[p], c = r((o = "root") => {
|
|
38
|
+
const n = t, s = m, C = n == null ? void 0 : n[o];
|
|
39
|
+
return {
|
|
40
|
+
...(s == null ? void 0 : s[o]) || {},
|
|
41
|
+
...C || {}
|
|
42
|
+
};
|
|
43
|
+
}, [t, m]), a = r((o = "root", n) => ({
|
|
44
|
+
...c(o),
|
|
45
|
+
...n || {}
|
|
46
|
+
}), [c]), l = y(() => t !== void 0 && Object.keys(t).length > 0, [t]);
|
|
47
|
+
return { getStyles: c, mergeStyles: a, hasOverrides: l };
|
|
48
|
+
}, k = P;
|
|
49
|
+
export {
|
|
50
|
+
h as BearComponentProvider,
|
|
51
|
+
k as useBC,
|
|
52
|
+
P as useBearComponent,
|
|
53
|
+
j as useBearComponentContext
|
|
54
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { BearComponentOverrides, ButtonVariantsConfig } from '../../types/component.types';
|
|
3
|
+
/**
|
|
4
|
+
* Component part style definition
|
|
5
|
+
*/
|
|
6
|
+
export interface ComponentPartStyles {
|
|
7
|
+
[part: string]: CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Return type for useBearComponent hook
|
|
11
|
+
*/
|
|
12
|
+
export interface UseBearComponentReturn {
|
|
13
|
+
/** Get styles for a specific component part */
|
|
14
|
+
getStyles: (part?: string) => CSSProperties;
|
|
15
|
+
/** Merge with additional styles */
|
|
16
|
+
mergeStyles: (part: string | undefined, additionalStyles?: CSSProperties) => CSSProperties;
|
|
17
|
+
/** Check if component has overrides */
|
|
18
|
+
hasOverrides: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Context value for component customization
|
|
22
|
+
*/
|
|
23
|
+
export interface BearComponentContextValue {
|
|
24
|
+
/** Component style overrides */
|
|
25
|
+
components: BearComponentOverrides;
|
|
26
|
+
/** Variant configurations */
|
|
27
|
+
variants: {
|
|
28
|
+
Button?: ButtonVariantsConfig;
|
|
29
|
+
};
|
|
30
|
+
/** Register component overrides */
|
|
31
|
+
registerComponent: <K extends keyof BearComponentOverrides>(componentKey: K, styles: BearComponentOverrides[K]) => void;
|
|
32
|
+
/** Register variant overrides */
|
|
33
|
+
registerVariant: <K extends 'Button'>(componentKey: K, variantConfig: ButtonVariantsConfig) => void;
|
|
34
|
+
/** Get component styles */
|
|
35
|
+
getComponentStyles: <K extends keyof BearComponentOverrides>(componentKey: K) => BearComponentOverrides[K] | undefined;
|
|
36
|
+
/** Get variant config */
|
|
37
|
+
getVariantConfig: <K extends 'Button'>(componentKey: K) => ButtonVariantsConfig | undefined;
|
|
38
|
+
/** Clear all overrides */
|
|
39
|
+
clearOverrides: () => void;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),A="bear-dnd",E=(v={})=>{const{onDragStart:o,onDragEnd:c,onDrop:g,onDragOver:d,onDragLeave:f,disabled:a=!1,dragType:D=A}=v,[I,i]=n.useState(!1),[S,T]=n.useState(null),[y,p]=n.useState(null),s=n.useRef(null),P=n.useCallback((e,u,l)=>({draggable:!a,onDragStart:r=>{a||(r.dataTransfer.setData(D,String(e)),r.dataTransfer.effectAllowed="move",s.current={id:e,item:u,index:l},T(e),i(!0),o==null||o(e,u,l))},onDragEnd:r=>{a||(s.current=null,T(null),p(null),i(!1),c==null||c(e,u,l))},"data-drag-id":e}),[a,D,o,c]),R=n.useCallback((e,u,l)=>({onDragOver:r=>{var b;if(a||!r.dataTransfer.types.includes(D))return;r.preventDefault(),r.dataTransfer.dropEffect="move";const t=(b=s.current)==null?void 0:b.id;t!=null&&t!==e&&(p(e),d==null||d(t,e))},onDragLeave:r=>{r.currentTarget.contains(r.relatedTarget)||(p(null),f==null||f(e))},onDrop:r=>{if(a)return;r.preventDefault(),p(null);const t=s.current;!t||t.id===e||g==null||g(t.id,e,t.index,l,t.item,u)},"data-drop-id":e}),[a,D,d,f,g]);return{isDragging:I,draggedId:S,dragOverId:y,getDragProps:P,getDropProps:R,dragDataRef:s}};exports.useDragDrop=E;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UseDragDropOptions, UseDragDropReturn } from './useDragDrop.types';
|
|
2
|
+
/**
|
|
3
|
+
* useDragDrop - Hook for HTML5 drag and drop
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { getDragProps, getDropProps, isDragging } = useDragDrop({
|
|
8
|
+
* onDrop: (sourceId, targetId) => reorder(sourceId, targetId),
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* return (
|
|
12
|
+
* <div {...getDropProps('col-1', col, 0)}>
|
|
13
|
+
* {items.map((item, i) => (
|
|
14
|
+
* <div key={item.id} {...getDragProps(item.id, item, i)}>
|
|
15
|
+
* {item.label}
|
|
16
|
+
* </div>
|
|
17
|
+
* ))}
|
|
18
|
+
* </div>
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const useDragDrop: <T = unknown>(options?: UseDragDropOptions<T>) => UseDragDropReturn<T>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState as p, useRef as _, useCallback as I } from "react";
|
|
2
|
+
const y = "bear-dnd", S = (b = {}) => {
|
|
3
|
+
const {
|
|
4
|
+
onDragStart: u,
|
|
5
|
+
onDragEnd: o,
|
|
6
|
+
onDrop: g,
|
|
7
|
+
onDragOver: f,
|
|
8
|
+
onDragLeave: c,
|
|
9
|
+
disabled: a = !1,
|
|
10
|
+
dragType: d = y
|
|
11
|
+
} = b, [m, T] = p(!1), [A, i] = p(null), [E, D] = p(null), n = _(null), P = I(
|
|
12
|
+
(r, s, l) => ({
|
|
13
|
+
draggable: !a,
|
|
14
|
+
onDragStart: (e) => {
|
|
15
|
+
a || (e.dataTransfer.setData(d, String(r)), e.dataTransfer.effectAllowed = "move", n.current = { id: r, item: s, index: l }, i(r), T(!0), u == null || u(r, s, l));
|
|
16
|
+
},
|
|
17
|
+
onDragEnd: (e) => {
|
|
18
|
+
a || (n.current = null, i(null), D(null), T(!1), o == null || o(r, s, l));
|
|
19
|
+
},
|
|
20
|
+
"data-drag-id": r
|
|
21
|
+
}),
|
|
22
|
+
[a, d, u, o]
|
|
23
|
+
), R = I(
|
|
24
|
+
(r, s, l) => ({
|
|
25
|
+
onDragOver: (e) => {
|
|
26
|
+
var v;
|
|
27
|
+
if (a || !e.dataTransfer.types.includes(d)) return;
|
|
28
|
+
e.preventDefault(), e.dataTransfer.dropEffect = "move";
|
|
29
|
+
const t = (v = n.current) == null ? void 0 : v.id;
|
|
30
|
+
t != null && t !== r && (D(r), f == null || f(t, r));
|
|
31
|
+
},
|
|
32
|
+
onDragLeave: (e) => {
|
|
33
|
+
e.currentTarget.contains(e.relatedTarget) || (D(null), c == null || c(r));
|
|
34
|
+
},
|
|
35
|
+
onDrop: (e) => {
|
|
36
|
+
if (a) return;
|
|
37
|
+
e.preventDefault(), D(null);
|
|
38
|
+
const t = n.current;
|
|
39
|
+
!t || t.id === r || g == null || g(t.id, r, t.index, l, t.item, s);
|
|
40
|
+
},
|
|
41
|
+
"data-drop-id": r
|
|
42
|
+
}),
|
|
43
|
+
[a, d, f, c, g]
|
|
44
|
+
);
|
|
45
|
+
return {
|
|
46
|
+
isDragging: m,
|
|
47
|
+
draggedId: A,
|
|
48
|
+
dragOverId: E,
|
|
49
|
+
getDragProps: P,
|
|
50
|
+
getDropProps: R,
|
|
51
|
+
dragDataRef: n
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
S as useDragDrop
|
|
56
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Drag and drop item identifier
|
|
4
|
+
*/
|
|
5
|
+
export type DragDropId = string | number;
|
|
6
|
+
/**
|
|
7
|
+
* UseDragDrop options
|
|
8
|
+
*/
|
|
9
|
+
export interface UseDragDropOptions<T = unknown> {
|
|
10
|
+
/** Callback when drag starts */
|
|
11
|
+
onDragStart?: (id: DragDropId, item: T, index: number) => void;
|
|
12
|
+
/** Callback when drag ends */
|
|
13
|
+
onDragEnd?: (id: DragDropId, item: T, index: number) => void;
|
|
14
|
+
/** Callback when item is dropped on target */
|
|
15
|
+
onDrop?: (sourceId: DragDropId, targetId: DragDropId, sourceIndex: number, targetIndex: number, sourceItem: T, targetItem: T) => void;
|
|
16
|
+
/** Callback when hovering over drop target */
|
|
17
|
+
onDragOver?: (sourceId: DragDropId, targetId: DragDropId) => void;
|
|
18
|
+
/** Callback when leaving drop target */
|
|
19
|
+
onDragLeave?: (targetId: DragDropId) => void;
|
|
20
|
+
/** Whether dragging is disabled */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** HTML5 drag type (default: 'bear-dnd') */
|
|
23
|
+
dragType?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* UseDragDrop return value
|
|
27
|
+
*/
|
|
28
|
+
export interface UseDragDropReturn<T = unknown> {
|
|
29
|
+
/** Whether an item is currently being dragged */
|
|
30
|
+
isDragging: boolean;
|
|
31
|
+
/** ID of the item being dragged */
|
|
32
|
+
draggedId: DragDropId | null;
|
|
33
|
+
/** ID of the current drop target hovered */
|
|
34
|
+
dragOverId: DragDropId | null;
|
|
35
|
+
/** Props to spread on draggable element */
|
|
36
|
+
getDragProps: (id: DragDropId, item: T, index: number) => {
|
|
37
|
+
draggable: boolean;
|
|
38
|
+
onDragStart: (e: React.DragEvent) => void;
|
|
39
|
+
onDragEnd: (e: React.DragEvent) => void;
|
|
40
|
+
'data-drag-id': DragDropId;
|
|
41
|
+
};
|
|
42
|
+
/** Props to spread on drop target element */
|
|
43
|
+
getDropProps: (id: DragDropId, item: T, index: number) => {
|
|
44
|
+
onDragOver: (e: React.DragEvent) => void;
|
|
45
|
+
onDragLeave: (e: React.DragEvent) => void;
|
|
46
|
+
onDrop: (e: React.DragEvent) => void;
|
|
47
|
+
'data-drop-id': DragDropId;
|
|
48
|
+
};
|
|
49
|
+
/** Ref to store dragged item data (for cross-component) */
|
|
50
|
+
dragDataRef: MutableRefObject<{
|
|
51
|
+
id: DragDropId;
|
|
52
|
+
item: T;
|
|
53
|
+
index: number;
|
|
54
|
+
} | null>;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),y=["mousemove","mousedown","keydown","touchstart","scroll","wheel"],A=6e4;function L(S={}){const{timeout:a=A,events:f=y,initialState:k=!1,onIdle:d,onActive:m}=S,[w,v]=e.useState(k),[D,I]=e.useState(Date.now()),[h,T]=e.useState(a),[c,b]=e.useState(!1),o=e.useRef(null),r=e.useRef(null),l=e.useRef(d),i=e.useRef(m);e.useEffect(()=>{l.current=d,i.current=m},[d,m]);const u=e.useCallback(()=>{o.current&&(clearTimeout(o.current),o.current=null),r.current&&(clearInterval(r.current),r.current=null)},[]),t=e.useCallback(()=>{if(c)return;u();const s=Date.now();T(a),r.current=setInterval(()=>{const n=Date.now()-s;T(Math.max(0,a-n))},1e3),o.current=setTimeout(()=>{var n;v(!0),(n=l.current)==null||n.call(l),r.current&&clearInterval(r.current)},a)},[a,c,u]),E=e.useCallback(()=>{var n;if(c)return;const s=w;v(!1),I(Date.now()),t(),s&&((n=i.current)==null||n.call(i))},[c,w,t]),C=e.useCallback(()=>{v(!1),I(Date.now()),t()},[t]),R=e.useCallback(()=>{b(!0),u()},[u]),p=e.useCallback(()=>{b(!1),t()},[t]);return e.useEffect(()=>{if(!(typeof window>"u"))return t(),f.forEach(s=>{window.addEventListener(s,E,{passive:!0})}),()=>{u(),f.forEach(s=>{window.removeEventListener(s,E)})}},[f,E,t,u]),{isIdle:w,remaining:h,lastActive:D,reset:C,pause:R,resume:p}}exports.useIdle=L;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UseIdleOptions, UseIdleReturn } from './useIdle.types';
|
|
2
|
+
/**
|
|
3
|
+
* useIdle - Detect user inactivity
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { isIdle, remaining, reset } = useIdle({
|
|
8
|
+
* timeout: 30000, // 30 seconds
|
|
9
|
+
* onIdle: () => console.log('User is idle'),
|
|
10
|
+
* onActive: () => console.log('User is active'),
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <div>
|
|
15
|
+
* {isIdle ? 'User is idle' : `Active (${remaining}ms until idle)`}
|
|
16
|
+
* <button onClick={reset}>Reset</button>
|
|
17
|
+
* </div>
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function useIdle(options?: UseIdleOptions): UseIdleReturn;
|
|
22
|
+
export default useIdle;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useState as f, useRef as d, useEffect as A, useCallback as c } from "react";
|
|
2
|
+
const F = [
|
|
3
|
+
"mousemove",
|
|
4
|
+
"mousedown",
|
|
5
|
+
"keydown",
|
|
6
|
+
"touchstart",
|
|
7
|
+
"scroll",
|
|
8
|
+
"wheel"
|
|
9
|
+
], M = 6e4;
|
|
10
|
+
function R(L = {}) {
|
|
11
|
+
const {
|
|
12
|
+
timeout: o = M,
|
|
13
|
+
events: m = F,
|
|
14
|
+
initialState: y = !1,
|
|
15
|
+
onIdle: w,
|
|
16
|
+
onActive: v
|
|
17
|
+
} = L, [E, I] = f(y), [S, D] = f(Date.now()), [U, h] = f(o), [u, p] = f(!1), a = d(null), r = d(null), i = d(w), l = d(v);
|
|
18
|
+
A(() => {
|
|
19
|
+
i.current = w, l.current = v;
|
|
20
|
+
}, [w, v]);
|
|
21
|
+
const s = c(() => {
|
|
22
|
+
a.current && (clearTimeout(a.current), a.current = null), r.current && (clearInterval(r.current), r.current = null);
|
|
23
|
+
}, []), e = c(() => {
|
|
24
|
+
if (u) return;
|
|
25
|
+
s();
|
|
26
|
+
const t = Date.now();
|
|
27
|
+
h(o), r.current = setInterval(() => {
|
|
28
|
+
const n = Date.now() - t;
|
|
29
|
+
h(Math.max(0, o - n));
|
|
30
|
+
}, 1e3), a.current = setTimeout(() => {
|
|
31
|
+
var n;
|
|
32
|
+
I(!0), (n = i.current) == null || n.call(i), r.current && clearInterval(r.current);
|
|
33
|
+
}, o);
|
|
34
|
+
}, [o, u, s]), T = c(() => {
|
|
35
|
+
var n;
|
|
36
|
+
if (u) return;
|
|
37
|
+
const t = E;
|
|
38
|
+
I(!1), D(Date.now()), e(), t && ((n = l.current) == null || n.call(l));
|
|
39
|
+
}, [u, E, e]), g = c(() => {
|
|
40
|
+
I(!1), D(Date.now()), e();
|
|
41
|
+
}, [e]), k = c(() => {
|
|
42
|
+
p(!0), s();
|
|
43
|
+
}, [s]), x = c(() => {
|
|
44
|
+
p(!1), e();
|
|
45
|
+
}, [e]);
|
|
46
|
+
return A(() => {
|
|
47
|
+
if (!(typeof window > "u"))
|
|
48
|
+
return e(), m.forEach((t) => {
|
|
49
|
+
window.addEventListener(t, T, { passive: !0 });
|
|
50
|
+
}), () => {
|
|
51
|
+
s(), m.forEach((t) => {
|
|
52
|
+
window.removeEventListener(t, T);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}, [m, T, e, s]), {
|
|
56
|
+
isIdle: E,
|
|
57
|
+
remaining: U,
|
|
58
|
+
lastActive: S,
|
|
59
|
+
reset: g,
|
|
60
|
+
pause: k,
|
|
61
|
+
resume: x
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
R as useIdle
|
|
66
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useIdle hook types
|
|
3
|
+
*/
|
|
4
|
+
export interface UseIdleOptions {
|
|
5
|
+
/** Timeout in milliseconds before user is considered idle (default: 60000 = 1 min) */
|
|
6
|
+
timeout?: number;
|
|
7
|
+
/** Events to listen for as activity (default: mouse, keyboard, touch, scroll) */
|
|
8
|
+
events?: (keyof WindowEventMap)[];
|
|
9
|
+
/** Initial idle state */
|
|
10
|
+
initialState?: boolean;
|
|
11
|
+
/** Callback when user becomes idle */
|
|
12
|
+
onIdle?: () => void;
|
|
13
|
+
/** Callback when user becomes active */
|
|
14
|
+
onActive?: () => void;
|
|
15
|
+
}
|
|
16
|
+
export interface UseIdleReturn {
|
|
17
|
+
/** Whether the user is currently idle */
|
|
18
|
+
isIdle: boolean;
|
|
19
|
+
/** Time remaining until idle (ms) */
|
|
20
|
+
remaining: number;
|
|
21
|
+
/** Last activity timestamp */
|
|
22
|
+
lastActive: number;
|
|
23
|
+
/** Reset the idle timer */
|
|
24
|
+
reset: () => void;
|
|
25
|
+
/** Pause idle detection */
|
|
26
|
+
pause: () => void;
|
|
27
|
+
/** Resume idle detection */
|
|
28
|
+
resume: () => void;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),w=(a={})=>{const{rootMargin:r="100px",threshold:o=0,once:c=!0,enabled:i=!0}=a,t=e.useRef(null),[f,d]=e.useState(!1),[l,b]=e.useState(!1);return e.useEffect(()=>{if(!i||!t.current||typeof IntersectionObserver>"u")return;const s=new IntersectionObserver(([n])=>{const u=(n==null?void 0:n.isIntersecting)??!1;d(u),u&&(b(!0),c&&s.disconnect())},{rootMargin:r,threshold:o});return s.observe(t.current),()=>s.disconnect()},[i,r,o,c]),{ref:t,isInView:f,hasBeenViewed:l}};exports.useLazyLoad=w;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UseLazyLoadOptions, UseLazyLoadReturn } from './useLazyLoad.types';
|
|
2
|
+
/**
|
|
3
|
+
* useLazyLoad - Lazy load content when it enters the viewport.
|
|
4
|
+
* Useful for infinite scroll, lazy images, or deferring heavy renders.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const { ref, hasBeenViewed } = useLazyLoad();
|
|
9
|
+
*
|
|
10
|
+
* return (
|
|
11
|
+
* <div ref={ref}>
|
|
12
|
+
* {hasBeenViewed ? <HeavyComponent /> : <Skeleton />}
|
|
13
|
+
* </div>
|
|
14
|
+
* );
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const { ref, isInView } = useLazyLoad({ once: false });
|
|
20
|
+
* useEffect(() => {
|
|
21
|
+
* if (isInView) loadMore();
|
|
22
|
+
* }, [isInView]);
|
|
23
|
+
* return <div ref={ref}>Load more trigger</div>;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const useLazyLoad: <T extends HTMLElement = HTMLDivElement>(options?: UseLazyLoadOptions) => UseLazyLoadReturn<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useRef as I, useState as u, useEffect as b } from "react";
|
|
2
|
+
const p = (f = {}) => {
|
|
3
|
+
const {
|
|
4
|
+
rootMargin: t = "100px",
|
|
5
|
+
threshold: r = 0,
|
|
6
|
+
once: o = !0,
|
|
7
|
+
enabled: i = !0
|
|
8
|
+
} = f, e = I(null), [a, d] = u(!1), [l, w] = u(!1);
|
|
9
|
+
return b(() => {
|
|
10
|
+
if (!i || !e.current || typeof IntersectionObserver > "u") return;
|
|
11
|
+
const s = new IntersectionObserver(
|
|
12
|
+
([n]) => {
|
|
13
|
+
const c = (n == null ? void 0 : n.isIntersecting) ?? !1;
|
|
14
|
+
d(c), c && (w(!0), o && s.disconnect());
|
|
15
|
+
},
|
|
16
|
+
{ rootMargin: t, threshold: r }
|
|
17
|
+
);
|
|
18
|
+
return s.observe(e.current), () => s.disconnect();
|
|
19
|
+
}, [i, t, r, o]), {
|
|
20
|
+
ref: e,
|
|
21
|
+
isInView: a,
|
|
22
|
+
hasBeenViewed: l
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
p as useLazyLoad
|
|
27
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* useLazyLoad options
|
|
4
|
+
*/
|
|
5
|
+
export interface UseLazyLoadOptions {
|
|
6
|
+
/** Root margin for IntersectionObserver (e.g. '100px' to trigger before visible) */
|
|
7
|
+
rootMargin?: string;
|
|
8
|
+
/** Threshold 0–1 for how much must be visible */
|
|
9
|
+
threshold?: number;
|
|
10
|
+
/** Once in view, stay loaded (default: true) */
|
|
11
|
+
once?: boolean;
|
|
12
|
+
/** Enable observer */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* useLazyLoad return value
|
|
17
|
+
*/
|
|
18
|
+
export interface UseLazyLoadReturn<T extends HTMLElement> {
|
|
19
|
+
/** Ref to attach to the element to observe */
|
|
20
|
+
ref: RefObject<T | null>;
|
|
21
|
+
/** Whether element is currently in viewport */
|
|
22
|
+
isInView: boolean;
|
|
23
|
+
/** Whether element has ever been in view (stays true once loaded) */
|
|
24
|
+
hasBeenViewed: boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),p=400;function D(d={}){const{threshold:R=p,onLongPress:s,onClick:i,onStart:u,onFinish:c,onCancel:n,filterEvents:b,disabled:C=!1}=d,l=t.useRef(null),k=t.useRef(!1),r=t.useRef(!1),E=t.useRef(null),o=t.useCallback(()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]),a=t.useCallback(e=>{C||b&&!b(e)||(r.current=!0,k.current=!1,E.current=e,u==null||u(e),l.current=setTimeout(()=>{k.current=!0,s==null||s(e)},R))},[C,b,u,s,R]),T=t.useCallback(e=>{r.current&&(o(),r.current=!1,n==null||n(e))},[o,n]),f=t.useCallback(e=>{r.current&&(o(),r.current=!1,!k.current&&i&&i(e),c==null||c(e))},[o,i,c]),L=t.useCallback(e=>{e.button===0&&a(e)},[a]),g=t.useCallback(e=>{f(e)},[f]),m=t.useCallback(e=>{T(e)},[T]),M=t.useCallback(e=>{a(e)},[a]),h=t.useCallback(e=>{f(e)},[f]);return{onMouseDown:L,onMouseUp:g,onMouseLeave:m,onTouchStart:M,onTouchEnd:h}}exports.useLongPress=D;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UseLongPressOptions, UseLongPressReturn } from './useLongPress.types';
|
|
2
|
+
/**
|
|
3
|
+
* useLongPress - Detect long press gestures
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const longPressProps = useLongPress({
|
|
8
|
+
* threshold: 500,
|
|
9
|
+
* onLongPress: () => console.log('Long pressed!'),
|
|
10
|
+
* onClick: () => console.log('Clicked!'),
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* return <button {...longPressProps}>Hold me</button>;
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function useLongPress(options?: UseLongPressOptions): UseLongPressReturn;
|
|
17
|
+
export default useLongPress;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useRef as a, useCallback as t } from "react";
|
|
2
|
+
const H = 400;
|
|
3
|
+
function g(L = {}) {
|
|
4
|
+
const {
|
|
5
|
+
threshold: E = H,
|
|
6
|
+
onLongPress: n,
|
|
7
|
+
onClick: R,
|
|
8
|
+
onStart: c,
|
|
9
|
+
onFinish: s,
|
|
10
|
+
onCancel: u,
|
|
11
|
+
filterEvents: T,
|
|
12
|
+
disabled: d = !1
|
|
13
|
+
} = L, o = a(null), m = a(!1), e = a(!1), b = a(null), f = t(() => {
|
|
14
|
+
o.current && (clearTimeout(o.current), o.current = null);
|
|
15
|
+
}, []), l = t((r) => {
|
|
16
|
+
d || T && !T(r) || (e.current = !0, m.current = !1, b.current = r, c == null || c(r), o.current = setTimeout(() => {
|
|
17
|
+
m.current = !0, n == null || n(r);
|
|
18
|
+
}, E));
|
|
19
|
+
}, [d, T, c, n, E]), p = t((r) => {
|
|
20
|
+
e.current && (f(), e.current = !1, u == null || u(r));
|
|
21
|
+
}, [f, u]), i = t((r) => {
|
|
22
|
+
e.current && (f(), e.current = !1, !m.current && R && R(r), s == null || s(r));
|
|
23
|
+
}, [f, R, s]), h = t((r) => {
|
|
24
|
+
r.button === 0 && l(r);
|
|
25
|
+
}, [l]), D = t((r) => {
|
|
26
|
+
i(r);
|
|
27
|
+
}, [i]), M = t((r) => {
|
|
28
|
+
p(r);
|
|
29
|
+
}, [p]), k = t((r) => {
|
|
30
|
+
l(r);
|
|
31
|
+
}, [l]), A = t((r) => {
|
|
32
|
+
i(r);
|
|
33
|
+
}, [i]);
|
|
34
|
+
return {
|
|
35
|
+
onMouseDown: h,
|
|
36
|
+
onMouseUp: D,
|
|
37
|
+
onMouseLeave: M,
|
|
38
|
+
onTouchStart: k,
|
|
39
|
+
onTouchEnd: A
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
g as useLongPress
|
|
44
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MouseEvent, TouchEvent } from 'react';
|
|
2
|
+
export interface UseLongPressOptions {
|
|
3
|
+
/** Duration in ms to trigger long press (default: 400) */
|
|
4
|
+
threshold?: number;
|
|
5
|
+
/** Callback for long press */
|
|
6
|
+
onLongPress?: (event: MouseEvent | TouchEvent) => void;
|
|
7
|
+
/** Callback for regular click (if released before threshold) */
|
|
8
|
+
onClick?: (event: MouseEvent | TouchEvent) => void;
|
|
9
|
+
/** Callback when press starts */
|
|
10
|
+
onStart?: (event: MouseEvent | TouchEvent) => void;
|
|
11
|
+
/** Callback when press ends (regardless of long press) */
|
|
12
|
+
onFinish?: (event: MouseEvent | TouchEvent) => void;
|
|
13
|
+
/** Callback when press is cancelled (e.g., mouse leaves) */
|
|
14
|
+
onCancel?: (event: MouseEvent | TouchEvent) => void;
|
|
15
|
+
/** Filter function to determine if event should trigger */
|
|
16
|
+
filterEvents?: (event: MouseEvent | TouchEvent) => boolean;
|
|
17
|
+
/** Disable the long press */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface UseLongPressReturn {
|
|
21
|
+
onMouseDown: (event: MouseEvent) => void;
|
|
22
|
+
onMouseUp: (event: MouseEvent) => void;
|
|
23
|
+
onMouseLeave: (event: MouseEvent) => void;
|
|
24
|
+
onTouchStart: (event: TouchEvent) => void;
|
|
25
|
+
onTouchEnd: (event: TouchEvent) => void;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");function w(a={}){const{onOnline:o,onOffline:r}=a,[f,c]=e.useState(()=>typeof navigator<"u"?navigator.onLine:!0),[d,l]=e.useState(null),t=e.useRef(o),i=e.useRef(r);e.useEffect(()=>{t.current=o,i.current=r},[o,r]);const s=e.useCallback(()=>{var n;c(!0),l(Date.now()),(n=t.current)==null||n.call(t)},[]),u=e.useCallback(()=>{var n;c(!1),l(Date.now()),(n=i.current)==null||n.call(i)},[]);return e.useEffect(()=>{if(!(typeof window>"u"))return window.addEventListener("online",s),window.addEventListener("offline",u),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",u)}},[s,u]),{isOnline:f,since:d}}exports.useOnline=w;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UseOnlineOptions, UseOnlineReturn } from './useOnline.types';
|
|
2
|
+
/**
|
|
3
|
+
* useOnline - Detect online/offline network status
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { isOnline, since } = useOnline({
|
|
8
|
+
* onOnline: () => console.log('Back online!'),
|
|
9
|
+
* onOffline: () => console.log('Gone offline!'),
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* return <div>{isOnline ? '🟢 Online' : '🔴 Offline'}</div>;
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function useOnline(options?: UseOnlineOptions): UseOnlineReturn;
|
|
16
|
+
export default useOnline;
|