@sohanemon/utils 6.2.8 → 6.3.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/dist/components.d.ts +84 -0
- package/dist/components.js +1 -0
- package/dist/hooks-hkNH7WgA.js +1 -0
- package/dist/hooks.d.ts +309 -0
- package/dist/hooks.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +665 -0
- package/dist/index.d.ts +665 -2
- package/dist/index.js +1 -2
- package/package.json +49 -32
- package/dist/components/html-injector.d.ts +0 -50
- package/dist/components/html-injector.js +0 -108
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.js +0 -7
- package/dist/components/media-wrapper.d.ts +0 -10
- package/dist/components/media-wrapper.js +0 -14
- package/dist/components/responsive-indicator.d.ts +0 -2
- package/dist/components/responsive-indicator.js +0 -68
- package/dist/components/scrollable-marker.d.ts +0 -1
- package/dist/components/scrollable-marker.js +0 -56
- package/dist/functions/cookie.d.ts +0 -6
- package/dist/functions/cookie.js +0 -22
- package/dist/functions/deepmerge.d.ts +0 -59
- package/dist/functions/deepmerge.js +0 -116
- package/dist/functions/hydrate.d.ts +0 -15
- package/dist/functions/hydrate.js +0 -31
- package/dist/functions/index.d.ts +0 -8
- package/dist/functions/index.js +0 -8
- package/dist/functions/object.d.ts +0 -93
- package/dist/functions/object.js +0 -67
- package/dist/functions/poll.d.ts +0 -38
- package/dist/functions/poll.js +0 -69
- package/dist/functions/schedule.d.ts +0 -12
- package/dist/functions/schedule.js +0 -29
- package/dist/functions/shield.d.ts +0 -18
- package/dist/functions/shield.js +0 -15
- package/dist/functions/utils.d.ts +0 -243
- package/dist/functions/utils.js +0 -439
- package/dist/hooks/action.d.ts +0 -20
- package/dist/hooks/action.js +0 -84
- package/dist/hooks/async.d.ts +0 -30
- package/dist/hooks/async.js +0 -82
- package/dist/hooks/index.d.ts +0 -192
- package/dist/hooks/index.js +0 -533
- package/dist/hooks/schedule.d.ts +0 -36
- package/dist/hooks/schedule.js +0 -68
- package/dist/types/gates.d.ts +0 -133
- package/dist/types/gates.js +0 -1
- package/dist/types/guards.d.ts +0 -6
- package/dist/types/guards.js +0 -29
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -3
- package/dist/types/utilities.d.ts +0 -62
- package/dist/types/utilities.js +0 -1
package/dist/hooks/index.d.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export * from './action';
|
|
3
|
-
export * from './async';
|
|
4
|
-
export * from './schedule';
|
|
5
|
-
/**
|
|
6
|
-
* Hook to detect clicks outside of a referenced element.
|
|
7
|
-
* @param callback - A function to invoke when a click outside is detected.
|
|
8
|
-
* @returns A React ref object to attach to the target element.
|
|
9
|
-
*/
|
|
10
|
-
export declare const useClickOutside: (callback?: () => void) => React.RefObject<HTMLDivElement>;
|
|
11
|
-
/**
|
|
12
|
-
* Hook to match a media query based on Tailwind CSS breakpoints or custom queries.
|
|
13
|
-
* @param tailwindBreakpoint - The Tailwind breakpoint or custom query string.
|
|
14
|
-
* @returns A boolean indicating whether the media query matches.
|
|
15
|
-
*/
|
|
16
|
-
export declare function useMediaQuery(tailwindBreakpoint: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | `(${string})`): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Runs an effect only once when the component mounts.
|
|
19
|
-
* @param effect - The effect callback function.
|
|
20
|
-
*/
|
|
21
|
-
export declare function useEffectOnce(effect: React.EffectCallback): void;
|
|
22
|
-
/**
|
|
23
|
-
* Runs an effect only when dependencies update, excluding the initial render.
|
|
24
|
-
* @param effect - The effect callback function.
|
|
25
|
-
* @param deps - Dependency array for the effect.
|
|
26
|
-
*/
|
|
27
|
-
export declare function useUpdateEffect(effect: React.EffectCallback, deps: React.DependencyList): void;
|
|
28
|
-
/**
|
|
29
|
-
* Debounces a state value with a specified delay.
|
|
30
|
-
* @param state - The state value to debounce.
|
|
31
|
-
* @param delay - The debounce delay in milliseconds (default: 500ms).
|
|
32
|
-
* @returns The debounced state value.
|
|
33
|
-
*/
|
|
34
|
-
export declare function useDebounce<T>(state: T, delay?: number): T;
|
|
35
|
-
/**
|
|
36
|
-
* Hook to handle effects with layout synchronization in the browser.
|
|
37
|
-
*/
|
|
38
|
-
export declare const useIsomorphicEffect: typeof React.useEffect;
|
|
39
|
-
/**
|
|
40
|
-
* Hook to invoke a callback after a specified timeout.
|
|
41
|
-
* @param callback - The callback function to invoke.
|
|
42
|
-
* @param delay - The timeout delay in milliseconds (default: 1000ms).
|
|
43
|
-
*/
|
|
44
|
-
export declare function useTimeout(callback: () => void, delay?: number | null): void;
|
|
45
|
-
/**
|
|
46
|
-
* Hook to add and remove a window event listener.
|
|
47
|
-
* @param type - The type of the event to listen for.
|
|
48
|
-
* @param listener - The event listener callback.
|
|
49
|
-
* @param options - Options for the event listener.
|
|
50
|
-
*/
|
|
51
|
-
export declare function useWindowEvent<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
52
|
-
/**
|
|
53
|
-
* Tuple type for session storage value and updater.
|
|
54
|
-
*/
|
|
55
|
-
type SessionStorageValue<T> = [T, React.Dispatch<React.SetStateAction<T>>];
|
|
56
|
-
/**
|
|
57
|
-
* Hook to persist state in session storage.
|
|
58
|
-
* @param key - The key for session storage.
|
|
59
|
-
* @param defaultValue - The default value if no value is found in session storage.
|
|
60
|
-
* @returns A tuple of the stored value and an updater function.
|
|
61
|
-
*/
|
|
62
|
-
export declare const useSessionStorage: <T extends Record<string, any>>(key: string, defaultValue: T) => SessionStorageValue<T>;
|
|
63
|
-
/**
|
|
64
|
-
* Tuple type for local storage value and updater.
|
|
65
|
-
*/
|
|
66
|
-
type LocalStorageValue<T> = [T, React.Dispatch<React.SetStateAction<T>>];
|
|
67
|
-
/**
|
|
68
|
-
* Hook to persist state in local storage.
|
|
69
|
-
* @param key - The key for local storage.
|
|
70
|
-
* @param defaultValue - The default value if no value is found in local storage.
|
|
71
|
-
* @returns A tuple of the stored value and an updater function.
|
|
72
|
-
*/
|
|
73
|
-
export declare const useLocalStorage: <T extends Record<string, any>>(key: string, defaultValue: T) => LocalStorageValue<T>;
|
|
74
|
-
/**
|
|
75
|
-
* Hook to manage URL parameters as state.
|
|
76
|
-
* @param key - The URL parameter key.
|
|
77
|
-
* @param defaultValue - The default value if the parameter is not present.
|
|
78
|
-
* @returns A tuple of the parameter value and a setter function.
|
|
79
|
-
*/
|
|
80
|
-
export declare const useUrlParams: <T extends string | number | boolean>(key: string, defaultValue: T) => [T, (value: T) => void];
|
|
81
|
-
/**
|
|
82
|
-
* Hook to select a DOM element by CSS selector.
|
|
83
|
-
* @param selector - The CSS selector string.
|
|
84
|
-
* @returns The selected DOM element or null if not found.
|
|
85
|
-
*/
|
|
86
|
-
export declare const useQuerySelector: <T extends Element>(selector: string) => T | null;
|
|
87
|
-
/**
|
|
88
|
-
* Hook to detect if the code is running on the client side.
|
|
89
|
-
* @returns A boolean indicating whether the code is running on the client.
|
|
90
|
-
*/
|
|
91
|
-
export declare function useIsClient(): boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Hook to lock scroll by disabling body overflow.
|
|
94
|
-
*/
|
|
95
|
-
export declare function useLockScroll(): void;
|
|
96
|
-
/**
|
|
97
|
-
* Hook to copy text to the clipboard and track the copy status.
|
|
98
|
-
* @param timeout - The timeout duration in milliseconds to reset the copy status (default: 2000ms).
|
|
99
|
-
* @returns An object with the `isCopied` state and `copy` function.
|
|
100
|
-
*/
|
|
101
|
-
export declare function useCopyToClipboard({ timeout }: {
|
|
102
|
-
timeout?: number;
|
|
103
|
-
}): {
|
|
104
|
-
isCopied: boolean;
|
|
105
|
-
copy: (value: string) => void;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Properties for height calculation.
|
|
109
|
-
*/
|
|
110
|
-
type CalculationProps2 = {
|
|
111
|
-
blockIds: string[];
|
|
112
|
-
dynamic?: boolean | string;
|
|
113
|
-
margin?: number;
|
|
114
|
-
substract?: boolean;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
* Hook to calculate the height of an element based on viewport and other block heights.
|
|
119
|
-
* @param params - Configuration object for height calculation.
|
|
120
|
-
* @returns The calculated height.
|
|
121
|
-
*/
|
|
122
|
-
export declare const useHeightCalculation: ({ blockIds, margin, substract, dynamic, }: CalculationProps2) => number;
|
|
123
|
-
/**
|
|
124
|
-
* Properties for DOM calculation.
|
|
125
|
-
*/
|
|
126
|
-
type CalculationProps = {
|
|
127
|
-
blockIds: string[];
|
|
128
|
-
dynamic?: boolean | string;
|
|
129
|
-
margin?: number;
|
|
130
|
-
substract?: boolean;
|
|
131
|
-
onChange?: (results: {
|
|
132
|
-
blocksHeight: number;
|
|
133
|
-
blocksWidth: number;
|
|
134
|
-
remainingWidth: number;
|
|
135
|
-
remainingHeight: number;
|
|
136
|
-
}) => void;
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Hook to calculate dimensions (height and width) of an element based on viewport and other block dimensions.
|
|
140
|
-
* @param params - Configuration object for dimension calculation.
|
|
141
|
-
* @returns An object containing the calculated height and width.
|
|
142
|
-
*/
|
|
143
|
-
export declare const useDomCalculation: ({ blockIds, margin, substract, dynamic, onChange, }: CalculationProps) => {
|
|
144
|
-
height: number;
|
|
145
|
-
width: number;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Hook to detect if the user is scrolling.
|
|
149
|
-
* @returns An object containing the isScrolling state and a ref to the scrollable container.
|
|
150
|
-
*/
|
|
151
|
-
export declare const useIsScrolling: () => {
|
|
152
|
-
isScrolling: boolean;
|
|
153
|
-
scrollableContainerRef: React.RefObject<HTMLElement>;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Hook to detect if the user is at the top of the page.
|
|
157
|
-
* @returns An object containing the isAtTop state and a ref to the scrollable container.
|
|
158
|
-
*/
|
|
159
|
-
export declare const useIsAtTop: ({ offset }?: {
|
|
160
|
-
offset?: number;
|
|
161
|
-
}) => {
|
|
162
|
-
scrollableContainerRef: React.RefObject<HTMLElement>;
|
|
163
|
-
isAtTop: boolean;
|
|
164
|
-
};
|
|
165
|
-
interface UseIntersectionOptions extends IntersectionObserverInit {
|
|
166
|
-
onInteractionStart?: () => void;
|
|
167
|
-
onInteractionEnd?: () => void;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* React hook that tracks when an element enters or leaves the viewport
|
|
171
|
-
* using the Intersection Observer API.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```tsx
|
|
175
|
-
* const { ref, isIntersecting } = useIntersection({
|
|
176
|
-
* threshold: 0.1,
|
|
177
|
-
* onInteractionStart: () => console.log('👀 Element entered viewport'),
|
|
178
|
-
* onInteractionEnd: () => console.log('🙈 Element left viewport'),
|
|
179
|
-
* });
|
|
180
|
-
*
|
|
181
|
-
* return <div ref={ref}>Watch me</div>;
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
184
|
-
* @param options - Configuration for the intersection observer.
|
|
185
|
-
* @returns Object containing:
|
|
186
|
-
* - `ref`: React ref to attach to the observed element.
|
|
187
|
-
* - `isIntersecting`: Whether the element is currently visible.
|
|
188
|
-
*/
|
|
189
|
-
export declare const useIntersection: ({ threshold, root, rootMargin, onInteractionStart, onInteractionEnd, }?: UseIntersectionOptions) => {
|
|
190
|
-
ref: React.RefObject<any>;
|
|
191
|
-
isIntersecting: boolean;
|
|
192
|
-
};
|