@siberiacancode/reactuse 0.0.3 → 0.0.5
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/cjs/_rollupPluginBabelHelpers-Cva0m6Ep.js +3 -0
- package/dist/cjs/_rollupPluginBabelHelpers-Cva0m6Ep.js.map +1 -0
- package/dist/cjs/hooks/index.js +2 -2
- package/dist/cjs/hooks/useBattery/useBattery.js +3 -0
- package/dist/cjs/hooks/useBattery/useBattery.js.map +1 -0
- package/dist/cjs/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js.map +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.js +2 -2
- package/dist/cjs/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.js +2 -2
- package/dist/cjs/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.js +2 -2
- package/dist/cjs/hooks/useHover/useHover.js.map +1 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/cjs/hooks/useKeyPress/useKeyPress.js.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/cjs/hooks/useMount/useMount.js +1 -1
- package/dist/cjs/hooks/useMutationObserver.js +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.js +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js +1 -1
- package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js.map +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.js +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/cjs/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/cjs/hooks/useStep/useStep.js +3 -0
- package/dist/cjs/hooks/useStep/useStep.js.map +1 -0
- package/dist/cjs/hooks/useStorage/useStorage.js +2 -2
- package/dist/cjs/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/cjs/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/cjs/hooks/useTimeout/useTimeout.js.map +1 -1
- package/dist/cjs/hooks/useToggle/useToggle.js +3 -0
- package/dist/cjs/hooks/useToggle/useToggle.js.map +1 -0
- package/dist/cjs/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/cjs/hooks/useWindowSize/useWindowSize.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/utils/helpers/debounce.js +1 -1
- package/dist/cjs/utils/helpers/index.js +1 -1
- package/dist/cjs/utils/helpers/isClient.js +1 -1
- package/dist/cjs/utils/helpers/isShallowEqual.js +1 -1
- package/dist/esm/{_rollupPluginBabelHelpers-BDc6tlcX.js → _rollupPluginBabelHelpers-8YyPIzj_.js} +3 -3
- package/dist/esm/_rollupPluginBabelHelpers-8YyPIzj_.js.map +1 -0
- package/dist/esm/hooks/index.js +2 -2
- package/dist/esm/hooks/useBattery/useBattery.js +3 -0
- package/dist/esm/hooks/useBattery/useBattery.js.map +1 -0
- package/dist/esm/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/esm/hooks/useClickOutside/useClickOutside.js +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.js +2 -2
- package/dist/esm/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.js +2 -2
- package/dist/esm/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/esm/hooks/useHover/useHover.js +2 -2
- package/dist/esm/hooks/useHover/useHover.js.map +1 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/esm/hooks/useKeyPress/useKeyPress.js.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/esm/hooks/useMount/useMount.js +1 -1
- package/dist/esm/hooks/useMutationObserver.js +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.js +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js +1 -1
- package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js.map +1 -1
- package/dist/esm/hooks/useOnline/useOnline.js +1 -1
- package/dist/esm/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/esm/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/esm/hooks/useStep/useStep.js +3 -0
- package/dist/esm/hooks/useStep/useStep.js.map +1 -0
- package/dist/esm/hooks/useStorage/useStorage.js +2 -2
- package/dist/esm/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/esm/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/esm/hooks/useTimeout/useTimeout.js.map +1 -1
- package/dist/esm/hooks/useToggle/useToggle.js +3 -0
- package/dist/esm/hooks/useToggle/useToggle.js.map +1 -0
- package/dist/esm/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/esm/hooks/useWindowSize/useWindowSize.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/helpers/debounce.js +1 -1
- package/dist/esm/utils/helpers/index.js +1 -1
- package/dist/esm/utils/helpers/isClient.js +1 -1
- package/dist/esm/utils/helpers/isShallowEqual.js +1 -1
- package/dist/index.d.ts +221 -45
- package/package.json +5 -5
- package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js +0 -3
- package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js.map +0 -1
- package/dist/cjs/hooks/useToggle.js +0 -3
- package/dist/cjs/hooks/useToggle.js.map +0 -1
- package/dist/esm/_rollupPluginBabelHelpers-BDc6tlcX.js.map +0 -1
- package/dist/esm/hooks/useToggle.js +0 -3
- package/dist/esm/hooks/useToggle.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
/** State for hook use battery */
|
|
4
|
+
interface UseBatteryStateReturn {
|
|
5
|
+
/** Is battery API supported? */
|
|
6
|
+
supported: boolean;
|
|
7
|
+
/** Is battery information loading? */
|
|
8
|
+
loading: boolean;
|
|
9
|
+
/** Is charging battery? */
|
|
10
|
+
charging: boolean;
|
|
11
|
+
/** Time until the battery is fully charged */
|
|
12
|
+
chargingTime: number;
|
|
13
|
+
/** Time until the battery is completely discharged */
|
|
14
|
+
dischargingTime: number;
|
|
15
|
+
/** Battery charge level from 0 to 1 */
|
|
16
|
+
level: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @name useBattery
|
|
20
|
+
* @description - Hook for getting information about battery status
|
|
21
|
+
*
|
|
22
|
+
* @returns {UseBatteryStateReturn} Object containing battery information & Battery API support
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const { supported, loading, charging, chargingTime, dischargingTime, level } = useBattery();
|
|
26
|
+
*/
|
|
27
|
+
declare const useBattery: () => UseBatteryStateReturn;
|
|
28
|
+
|
|
3
29
|
/** The use boolean return type */
|
|
4
30
|
type UseBooleanReturn = [
|
|
5
31
|
/** The current boolean state value */
|
|
@@ -25,23 +51,16 @@ type UseClickOutside = {
|
|
|
25
51
|
<Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(target: Target, callback: (event: Event) => void): void;
|
|
26
52
|
<Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(callback: (event: Event) => void, target?: never): UseClickOutsideReturn<Target>;
|
|
27
53
|
};
|
|
28
|
-
/**
|
|
29
|
-
* @name useClickOutside
|
|
30
|
-
* @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const { count, dec, inc, reset, set } = useCounter(5);
|
|
34
|
-
*/
|
|
35
54
|
declare const useClickOutside: UseClickOutside;
|
|
36
55
|
|
|
37
56
|
declare const legacyCopyToClipboard: (value: string) => void;
|
|
38
57
|
/** The use copy to clipboard return type */
|
|
39
|
-
|
|
58
|
+
interface UseCopyToClipboardReturn {
|
|
40
59
|
/** The copied value */
|
|
41
|
-
value: string | null
|
|
60
|
+
value: string | null;
|
|
42
61
|
/** Function to copy to clipboard */
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
copy: (value: string) => Promise<void>;
|
|
63
|
+
}
|
|
45
64
|
/**
|
|
46
65
|
* @name useCopyToClipboard
|
|
47
66
|
* @description - Hook that manages a copy to clipboard
|
|
@@ -49,7 +68,7 @@ type UseCopyToClipboardReturn = [
|
|
|
49
68
|
* @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state
|
|
50
69
|
*
|
|
51
70
|
* @example
|
|
52
|
-
* const
|
|
71
|
+
* const { value, copy } = useCopyToClipboard();
|
|
53
72
|
*/
|
|
54
73
|
declare const useCopyToClipboard: () => UseCopyToClipboardReturn;
|
|
55
74
|
|
|
@@ -91,11 +110,14 @@ type UseCounter = {
|
|
|
91
110
|
*
|
|
92
111
|
* @overload
|
|
93
112
|
* @param {number} [initialValue=0] The initial number value
|
|
94
|
-
* @param {
|
|
113
|
+
* @param {number} [options.min=Number.NEGATIVE_INFINITY] The min of count value
|
|
114
|
+
* @param {number} [options.max=Number.POSITIVE_INFINITY] The max of count value
|
|
95
115
|
* @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter
|
|
96
116
|
|
|
97
117
|
* @overload
|
|
98
|
-
* @param {
|
|
118
|
+
* @param {number} [params.initialValue=0] The initial number value
|
|
119
|
+
* @param {number} [params.min=Number.NEGATIVE_INFINITY] The min of count value
|
|
120
|
+
* @param {number} [params.max=Number.POSITIVE_INFINITY] The max of count value
|
|
99
121
|
* @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter
|
|
100
122
|
*
|
|
101
123
|
* @example
|
|
@@ -118,10 +140,12 @@ interface UseDebouncedValueOptions {
|
|
|
118
140
|
*/
|
|
119
141
|
declare const useDebouncedValue: <Value>(value: Value, delay: number, options?: UseDebouncedValueOptions) => readonly [Value, (value: Value) => void];
|
|
120
142
|
|
|
143
|
+
/** The use document title options type */
|
|
121
144
|
interface UseDocumentTitleOptions {
|
|
122
145
|
/** Restore the previous title on unmount */
|
|
123
146
|
restoreOnUnmount?: boolean;
|
|
124
147
|
}
|
|
148
|
+
/** The use document title return type */
|
|
125
149
|
type UseDocumentTitleReturn = [
|
|
126
150
|
/** The current title */
|
|
127
151
|
title: string,
|
|
@@ -133,7 +157,7 @@ type UseDocumentTitleReturn = [
|
|
|
133
157
|
* @description - Hook that manages the document title and allows updating it
|
|
134
158
|
*
|
|
135
159
|
* @param {string} [value] The initial title. If not provided, the current document title will be used
|
|
136
|
-
* @param {
|
|
160
|
+
* @param {boolean} [options.restoreOnUnmount] Restore the previous title on unmount
|
|
137
161
|
* @returns {UseDocumentTitleReturn} An array containing the current title and a function to update the title
|
|
138
162
|
*
|
|
139
163
|
* @example
|
|
@@ -141,16 +165,25 @@ type UseDocumentTitleReturn = [
|
|
|
141
165
|
*/
|
|
142
166
|
declare function useDocumentTitle(value?: string, options?: UseDocumentTitleOptions): UseDocumentTitleReturn;
|
|
143
167
|
|
|
168
|
+
/**
|
|
169
|
+
* @name useDocumentVisibility
|
|
170
|
+
* @description – Hook that provides the current visibility state of the document
|
|
171
|
+
*
|
|
172
|
+
* @returns {DocumentVisibilityState} The current visibility state of the document, which can be 'visible' or 'hidden'
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* const visibilityState = useDocumentVisibility();
|
|
176
|
+
*/
|
|
144
177
|
declare const useDocumentVisibility: () => DocumentVisibilityState;
|
|
145
178
|
|
|
146
179
|
type UseEventListenerTarget = React.RefObject<Element | null> | (() => Element) | Element | Window | Document;
|
|
147
180
|
type UseEventListenerOptions = boolean | AddEventListenerOptions;
|
|
148
181
|
type UseEventListenerReturn<Target extends UseEventListenerTarget = any> = React.RefObject<Target>;
|
|
149
182
|
type UseEventListener = {
|
|
150
|
-
<Event extends keyof WindowEventMap = keyof WindowEventMap>(target: Window, event: Event, listener: (this: Window, event: WindowEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
151
|
-
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: Document, event: Event, listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
152
|
-
<Target extends UseEventListenerTarget, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: Target, event: Event, listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
153
|
-
<Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event, listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
183
|
+
<Event extends keyof WindowEventMap = keyof WindowEventMap>(target: Window, event: Event | Event[], listener: (this: Window, event: WindowEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
184
|
+
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: Document, event: Event | Event[], listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
185
|
+
<Target extends UseEventListenerTarget, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: Target, event: Event | Event[], listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
186
|
+
<Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event | Event[], listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
154
187
|
};
|
|
155
188
|
/**
|
|
156
189
|
* @name useEventListener
|
|
@@ -161,6 +194,10 @@ type UseEventListener = {
|
|
|
161
194
|
*/
|
|
162
195
|
declare const useEventListener: UseEventListener;
|
|
163
196
|
|
|
197
|
+
interface UseHoverOptions {
|
|
198
|
+
onEntry?: () => void;
|
|
199
|
+
onLeave?: () => void;
|
|
200
|
+
}
|
|
164
201
|
type UseHoverTarget = React.RefObject<Element | null> | Element;
|
|
165
202
|
type UseHoverReturn<Target extends UseHoverTarget = any> = [
|
|
166
203
|
React.RefObject<Target>,
|
|
@@ -168,14 +205,31 @@ type UseHoverReturn<Target extends UseHoverTarget = any> = [
|
|
|
168
205
|
];
|
|
169
206
|
type UseHover = {
|
|
170
207
|
<Target extends UseHoverTarget>(target: Target, callback?: () => void): boolean;
|
|
208
|
+
<Target extends UseHoverTarget>(target: Target, options?: UseHoverOptions): boolean;
|
|
171
209
|
<Target extends UseHoverTarget>(callback?: () => void, target?: never): UseHoverReturn<Target>;
|
|
210
|
+
<Target extends UseHoverTarget>(options?: UseHoverOptions, target?: never): UseHoverReturn<Target>;
|
|
172
211
|
};
|
|
173
212
|
/**
|
|
174
213
|
* @name useHover
|
|
175
|
-
* @description - Hook that
|
|
214
|
+
* @description - Hook that defines the logic when hovering an element
|
|
176
215
|
*
|
|
177
216
|
* @example
|
|
178
|
-
* const
|
|
217
|
+
* const hovering = useHover(ref, () => console.log('callback'));
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const [ref, hovering] = useHover(() => console.log('callback'));
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const [ref, hovering] = useHover({
|
|
224
|
+
* onEntry: () => console.log('onEntry'),
|
|
225
|
+
* onLeave: () => console.log('onLeave'),
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* const hovering = useHover(ref, {
|
|
230
|
+
* onEntry: () => console.log('onEntry'),
|
|
231
|
+
* onLeave: () => console.log('onLeave'),
|
|
232
|
+
* });
|
|
179
233
|
*/
|
|
180
234
|
declare const useHover: UseHover;
|
|
181
235
|
|
|
@@ -186,12 +240,26 @@ declare const useHover: UseHover;
|
|
|
186
240
|
* @example
|
|
187
241
|
* useIsomorphicLayoutEffect(() => console.log('effect'), [])
|
|
188
242
|
*/
|
|
189
|
-
declare const useIsomorphicLayoutEffect: typeof React.
|
|
243
|
+
declare const useIsomorphicLayoutEffect: typeof React.useEffect;
|
|
190
244
|
|
|
245
|
+
/** The key or keys to listen for */
|
|
191
246
|
type UseKeyPressKey = string | string[];
|
|
247
|
+
/** The use key press options */
|
|
192
248
|
type UseKeyPressOptions = {
|
|
193
|
-
target
|
|
249
|
+
/** The target to attach the event listeners to */
|
|
250
|
+
target?: UseEventListenerTarget;
|
|
194
251
|
};
|
|
252
|
+
/**
|
|
253
|
+
* @name useKeyPress
|
|
254
|
+
* @description - Hook that listens for key press events
|
|
255
|
+
*
|
|
256
|
+
* @param {UseKeyPressKey} key The key or keys to listen for
|
|
257
|
+
* @param {UseEventListenerTarget} [options.target=window] The target to attach the event listeners to
|
|
258
|
+
* @returns {useKeyPressReturns} Return boolean type (`true` if the specified keys are currently pressed)
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* const isKeyPressed = useKeyPress('a');
|
|
262
|
+
*/
|
|
195
263
|
declare const useKeyPress: (key: UseKeyPressKey, options?: UseKeyPressOptions) => boolean;
|
|
196
264
|
|
|
197
265
|
type UseKeyPressEventKey = string | string[];
|
|
@@ -203,14 +271,41 @@ type UseKeyPressEvent = {
|
|
|
203
271
|
};
|
|
204
272
|
declare const useKeyPressEvent: UseKeyPressEvent;
|
|
205
273
|
|
|
206
|
-
|
|
274
|
+
/** The use keys pressed params */
|
|
275
|
+
interface UseKeysPressedParams {
|
|
276
|
+
/** The target to attach the event listeners to */
|
|
277
|
+
target?: UseEventListenerTarget;
|
|
278
|
+
/** Enable or disable the event listeners */
|
|
279
|
+
enabled?: boolean;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @name useKeysPressed
|
|
283
|
+
* @description - Hook that listens for key press events
|
|
284
|
+
*
|
|
285
|
+
* @param {UseEventListenerTarget} [params.target=window] The target to attach the event listeners to
|
|
286
|
+
* @param {boolean} [params.enabled=bollean] Enable or disable the event listeners
|
|
287
|
+
* @returns {useKeysPressedReturns} Array of strings with keys that were press
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* const pressedKeys = useKeysPressed();
|
|
291
|
+
*/
|
|
292
|
+
declare const useKeysPressed: (params?: UseKeysPressedParams) => {
|
|
293
|
+
key: string;
|
|
294
|
+
code: string;
|
|
295
|
+
}[];
|
|
207
296
|
|
|
208
297
|
type UseStorageInitialValue<Value> = Value | (() => Value);
|
|
209
298
|
interface UseStorageOptions<Value> {
|
|
210
299
|
serializer?: (value: Value) => string;
|
|
211
300
|
deserializer?: (value: string) => Value;
|
|
212
|
-
storage
|
|
301
|
+
storage?: Storage;
|
|
302
|
+
initialValue?: UseStorageInitialValue<Value>;
|
|
213
303
|
}
|
|
304
|
+
type UseStorageReturn<Value> = [
|
|
305
|
+
value: Value,
|
|
306
|
+
set: (value: Value) => void,
|
|
307
|
+
remove: () => void
|
|
308
|
+
];
|
|
214
309
|
declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
|
|
215
310
|
/**
|
|
216
311
|
* @name useStorage
|
|
@@ -219,34 +314,55 @@ declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
|
|
|
219
314
|
* @example
|
|
220
315
|
* text
|
|
221
316
|
*/
|
|
222
|
-
declare
|
|
223
|
-
value: Value;
|
|
224
|
-
set: (value: Value) => void;
|
|
225
|
-
clear: () => void;
|
|
226
|
-
};
|
|
317
|
+
declare const useStorage: <Value>(key: string, params?: UseStorageInitialValue<Value> | UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
|
|
227
318
|
|
|
228
|
-
declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) =>
|
|
229
|
-
value: Value;
|
|
230
|
-
set: (value: Value) => void;
|
|
231
|
-
clear: () => void;
|
|
232
|
-
};
|
|
319
|
+
declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
|
|
233
320
|
|
|
234
321
|
declare const useMount: (effect: React.EffectCallback) => void;
|
|
235
322
|
|
|
236
323
|
type ConnectionType = Connection['type'];
|
|
237
324
|
type ConnectionEffectiveType = Connection['effectiveType'];
|
|
325
|
+
/** The use network return type */
|
|
238
326
|
interface UseNetworkReturn {
|
|
327
|
+
/** Indicates if the device is currently online */
|
|
239
328
|
online: boolean;
|
|
329
|
+
/** The estimated downlink speed in megabits per seconds */
|
|
240
330
|
downlink?: Connection['downlink'];
|
|
331
|
+
/** The maximum downlink speed, if available */
|
|
241
332
|
downlinkMax?: Connection['downlinkMax'];
|
|
333
|
+
/** The effective type of connection (e.g., '2g', '3g', '4g') */
|
|
242
334
|
effectiveType?: Connection['effectiveType'];
|
|
335
|
+
/** The estimated round-trip time in milliseconds */
|
|
243
336
|
rtt?: Connection['rtt'];
|
|
337
|
+
/** Indicates if the user has enabled data saving mode */
|
|
244
338
|
saveData?: Connection['saveData'];
|
|
339
|
+
/** The type of network connection (e.g., 'wifi', 'cellular') */
|
|
245
340
|
type?: Connection['type'];
|
|
246
341
|
}
|
|
247
342
|
declare const getConnection: () => Connection;
|
|
343
|
+
/**
|
|
344
|
+
* @name useNetwork
|
|
345
|
+
* @description - Hook to track network status.
|
|
346
|
+
*
|
|
347
|
+
* @returns {UseNetworkReturn} An object containing the network status.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* const { online, downlink, downlinkMax, effectiveType, rtt, saveData, type } = useNetwork();
|
|
351
|
+
*/
|
|
248
352
|
declare const useNetwork: () => UseNetworkReturn;
|
|
249
353
|
|
|
354
|
+
/**
|
|
355
|
+
* @name useNonInitialEffect
|
|
356
|
+
* @description – Hook that behaves like useEffect, but skips the effect on the initial render
|
|
357
|
+
*
|
|
358
|
+
* @param {React.EffectCallback} effect The effect callback
|
|
359
|
+
* @param {React.DependencyList} [deps] The dependencies list for the effect
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* useNonInitialEffect(() => {
|
|
363
|
+
* console.log('this effect doesn't run on the initial render');
|
|
364
|
+
* });
|
|
365
|
+
*/
|
|
250
366
|
declare const useNonInitialEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
251
367
|
|
|
252
368
|
declare const useOnline: () => boolean;
|
|
@@ -267,23 +383,82 @@ declare const useOrientation: () => {
|
|
|
267
383
|
*/
|
|
268
384
|
declare const useRenderCount: () => number;
|
|
269
385
|
|
|
270
|
-
declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) =>
|
|
271
|
-
value: Value;
|
|
272
|
-
set: (value: Value) => void;
|
|
273
|
-
clear: () => void;
|
|
274
|
-
};
|
|
386
|
+
declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
|
|
275
387
|
|
|
276
|
-
|
|
388
|
+
/** The use step params */
|
|
389
|
+
interface UseStepParams {
|
|
390
|
+
/** Initial value for step */
|
|
391
|
+
initial: number;
|
|
392
|
+
/** Maximum value for step */
|
|
393
|
+
max: number;
|
|
394
|
+
}
|
|
395
|
+
/** The use step return type */
|
|
396
|
+
interface UseStepReturn {
|
|
397
|
+
/** Counts of steps */
|
|
398
|
+
counts: number;
|
|
399
|
+
/** Current value of step */
|
|
400
|
+
currentStep: number;
|
|
401
|
+
/** Boolean value if current step is first */
|
|
402
|
+
isFirst: boolean;
|
|
403
|
+
/** Boolean value if current step is last */
|
|
404
|
+
isLast: boolean;
|
|
405
|
+
/** Go to next step */
|
|
406
|
+
next: () => void;
|
|
407
|
+
/** Go to back step */
|
|
408
|
+
back: () => void;
|
|
409
|
+
/** Reset current step to initial value */
|
|
410
|
+
reset: () => void;
|
|
411
|
+
/** Go to custom step */
|
|
412
|
+
set: (value: number | 'last' | 'first') => void;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* @name useStep
|
|
416
|
+
* @description - Hook that create stepper
|
|
417
|
+
*
|
|
418
|
+
* @overload
|
|
419
|
+
* @param {number} max Maximum number of steps
|
|
420
|
+
* @returns {UseStepReturn} An object contains variables and functions to change the step
|
|
421
|
+
*
|
|
422
|
+
* @overload
|
|
423
|
+
* @param {number} params.max Maximum number of steps
|
|
424
|
+
* @param {number} params.initial Initial value for step
|
|
425
|
+
* @returns {UseStepReturn} An object contains variables and functions to change the step
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* const step = useStep(5);
|
|
429
|
+
* @example
|
|
430
|
+
* const stepper = useStep({ initial: 2, max: 5 });
|
|
431
|
+
*/
|
|
432
|
+
declare const useStep: (params: number | UseStepParams) => UseStepReturn;
|
|
433
|
+
|
|
434
|
+
/** The use timeout return type */
|
|
435
|
+
interface UseTimeoutReturn {
|
|
436
|
+
/** Timeout is ready state value */
|
|
277
437
|
ready: boolean;
|
|
438
|
+
/** Function to clear timeout */
|
|
278
439
|
clear: () => void;
|
|
279
|
-
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* @name useTimeout
|
|
443
|
+
* @description Hook that executes a callback function after a specified delay.
|
|
444
|
+
*
|
|
445
|
+
* @param {() => void} callback The function to be executed after the timeout.
|
|
446
|
+
* @param {number} delay The delay in milliseconds before the timeout executes the callback function.
|
|
447
|
+
* @returns {UseTimeoutReturn} An object with a `ready` boolean state value and a `clear` function to clear timeout.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* const { clear, ready } = useTimeout(() => {}, 5000)
|
|
451
|
+
*/
|
|
452
|
+
declare function useTimeout(callback: () => void, delay: number): UseTimeoutReturn;
|
|
453
|
+
|
|
454
|
+
type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];
|
|
455
|
+
declare const useToggle: <Value = boolean>(values?: readonly Value[]) => readonly [Value, (value?: Value) => void];
|
|
280
456
|
|
|
281
457
|
/**
|
|
282
458
|
* @name useUnmount
|
|
283
459
|
* @description - Hook that defines the logic when unmounting a component
|
|
284
460
|
*
|
|
285
461
|
* @param {() => void} callback The callback function to be invoked on component unmount
|
|
286
|
-
*
|
|
287
462
|
* @returns {void}
|
|
288
463
|
*
|
|
289
464
|
* @example
|
|
@@ -324,7 +499,8 @@ interface UseWindowSizeReturn {
|
|
|
324
499
|
* @name useWindowSize
|
|
325
500
|
* @description - Hook that manages a window size
|
|
326
501
|
*
|
|
327
|
-
* @param {
|
|
502
|
+
* @param {number} [params.initialWidth=Number.POSITIVE_INFINITY] The initial window width
|
|
503
|
+
* @param {number} [params.initialHeight=Number.POSITIVE_INFINITY] The initial window height
|
|
328
504
|
* @returns {UseWindowSizeReturn} An object containing the current window width and height
|
|
329
505
|
*
|
|
330
506
|
* @example
|
|
@@ -335,4 +511,4 @@ declare const useWindowSize: (params?: UseWindowSizeParams) => {
|
|
|
335
511
|
height: number;
|
|
336
512
|
};
|
|
337
513
|
|
|
338
|
-
export { type ConnectionEffectiveType, type ConnectionType, type UseClickOutside, type UseClickOutsideReturn, type UseCounter, type UseCounterOptions, type UseCounterParams, type UseCounterReturn, type UseDocumentTitleOptions, type UseDocumentTitleReturn, type UseEventListener, type UseEventListenerOptions, type UseEventListenerReturn, type UseEventListenerTarget, type UseHover, type UseHoverReturn, type UseHoverTarget, type UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseStorageInitialValue, type UseStorageOptions, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, legacyCopyToClipboard, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDocumentTitle, useDocumentVisibility, useEventListener, useHover, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useMount, useNetwork, useNonInitialEffect, useOnline, useOrientation, useRenderCount, useSessionStorage, useStorage, useTimeout, useUnmount, useWindowEvent, useWindowSize };
|
|
514
|
+
export { type ConnectionEffectiveType, type ConnectionType, type UseClickOutside, type UseClickOutsideReturn, type UseCounter, type UseCounterOptions, type UseCounterParams, type UseCounterReturn, type UseDocumentTitleOptions, type UseDocumentTitleReturn, type UseEventListener, type UseEventListenerOptions, type UseEventListenerReturn, type UseEventListenerTarget, type UseHover, type UseHoverOptions, type UseHoverReturn, type UseHoverTarget, type UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseStorageInitialValue, type UseStorageOptions, type UseStorageReturn, type UseToggleReturn, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, legacyCopyToClipboard, useBattery, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDocumentTitle, useDocumentVisibility, useEventListener, useHover, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useMount, useNetwork, useNonInitialEffect, useOnline, useOrientation, useRenderCount, useSessionStorage, useStep, useStorage, useTimeout, useToggle, useUnmount, useWindowEvent, useWindowSize };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Ultimate tool",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"type": "tsc --noEmit",
|
|
39
39
|
"pretty": "yarn type && yarn format && yarn lint",
|
|
40
40
|
"prepare": "husky install",
|
|
41
|
-
"unit-test": "
|
|
41
|
+
"unit-test": "vitest",
|
|
42
42
|
"docs:dev": "vitepress dev docs",
|
|
43
43
|
"docs:build": "vitepress build docs",
|
|
44
44
|
"docs:preview": "vitepress preview docs"
|
|
@@ -62,12 +62,10 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@siberiacancode/builder": "^1.3.0",
|
|
64
64
|
"@siberiacancode/eslint": "^1.1.0",
|
|
65
|
-
"@siberiacancode/jest": "^1.0.2",
|
|
66
65
|
"@siberiacancode/prettier": "^1.1.0",
|
|
67
66
|
"@testing-library/jest-dom": "^6.4.5",
|
|
68
67
|
"@testing-library/react": "^15.0.7",
|
|
69
68
|
"@types/doctrine": "^0.0.9",
|
|
70
|
-
"@types/jest": "^29.5.12",
|
|
71
69
|
"@types/node": "^20.11.19",
|
|
72
70
|
"@types/react": "^18.3.2",
|
|
73
71
|
"@types/react-dom": "^18.3.0",
|
|
@@ -75,6 +73,7 @@
|
|
|
75
73
|
"doctrine": "^3.0.0",
|
|
76
74
|
"eslint": "^8.56.0",
|
|
77
75
|
"husky": "^9.0.11",
|
|
76
|
+
"jsdom": "^24.1.0",
|
|
78
77
|
"lint-staged": "^15.2.2",
|
|
79
78
|
"markdown-table": "^3.0.3",
|
|
80
79
|
"react": "^18.2.0",
|
|
@@ -82,7 +81,8 @@
|
|
|
82
81
|
"shx": "^0.3.4",
|
|
83
82
|
"typescript": "^5.3.3",
|
|
84
83
|
"vite": "^5.1.3",
|
|
85
|
-
"vitepress": "^1.1.4"
|
|
84
|
+
"vitepress": "^1.1.4",
|
|
85
|
+
"vitest": "^1.6.0"
|
|
86
86
|
},
|
|
87
87
|
"keywords": [
|
|
88
88
|
"react",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.1 */
|
|
2
|
-
"use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function f(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{f({},"")}catch(t){f=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new k(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var y="suspendedStart",p="suspendedYield",v="executing",d="completed",g={};function m(){}function b(){}function w(){}var O={};f(O,c,(function(){return this}));var j=Object.getPrototypeOf,x=j&&j(j(G([])));x&&x!==n&&o.call(x,c)&&(O=x);var E=w.prototype=m.prototype=Object.create(O);function L(t){["next","throw","return"].forEach((function(r){f(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&o.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=y;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===y)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var l=h(r,e,n);if("normal"===l.type){if(o=n.done?d:p,l.arg===g)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(o=d,n.method="throw",n.arg=l.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function A(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function T(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function G(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=f(w,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,f(t,l,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},L(P.prototype),f(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(E),f(E,l,"Generator"),f(E,c,(function(){return this})),f(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=G,k.prototype={constructor:k,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),l=o.call(a,"finallyLoc");if(u&&l){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),g},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),T(e),g}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;T(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:G(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function e(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:String(r)}function n(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function o(t,r,n){return(r=e(r))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,t}function i(t,r){if(t){if("string"==typeof t)return a(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(t,r):void 0}}function a(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}exports._asyncToGenerator=function(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}},exports._objectSpread2=function(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){o(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r},exports._regeneratorRuntime=r,exports._slicedToArray=function(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,c=[],u=!0,l=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;u=!1}else for(;!(u=(n=i.call(e)).done)&&(c.push(n.value),c.length!==r);u=!0);}catch(t){l=!0,o=t}finally{try{if(!u&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}(t,r)||i(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()},exports._toConsumableArray=function(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()};
|
|
3
|
-
//# sourceMappingURL=_rollupPluginBabelHelpers-9eGFsb-q.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers-9eGFsb-q.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.1 */
|
|
2
|
-
"use strict";var e=require("../_rollupPluginBabelHelpers-9eGFsb-q.js"),r=require("react");exports.useToggle=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[!1,!0],n=r.useReducer((function(e,r){var i=r instanceof Function?r(e[0]):r,n=Math.abs(e.indexOf(i));return e.slice(n).concat(e.slice(0,n))}),i),c=e._slicedToArray(n,2);return[e._slicedToArray(c[0],1)[0],c[1]]};
|
|
3
|
-
//# sourceMappingURL=useToggle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToggle.js","sources":["../../../src/hooks/useToggle.ts"],"sourcesContent":["import React from 'react';\n\nexport type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];\n\nexport const useToggle = <Value = boolean>(values: readonly Value[] = [false, true] as any) => {\n const [[option], toggle] = React.useReducer(\n (state: Value[], action: React.SetStateAction<Value>) => {\n const value = action instanceof Function ? action(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n return state.slice(index).concat(state.slice(0, index));\n },\n values as Value[]\n );\n\n return [option, toggle as (value?: Value) => void] as const;\n};\n"],"names":["values","arguments","length","undefined","_React$useReducer","React","useReducer","state","action","value","Function","index","Math","abs","indexOf","slice","concat","_React$useReducer2","_slicedToArray"],"mappings":";4GAIyB,WAAsE,IAApDA,EAAwBC,UAAAC,eAAAC,IAAAF,UAAA,GAAAA,UAAG,GAAA,EAAC,GAAO,GAC5EG,EAA2BC,EAAMC,YAC/B,SAACC,EAAgBC,GACf,IAAMC,EAAQD,aAAkBE,SAAWF,EAAOD,EAAM,IAAMC,EACxDG,EAAQC,KAAKC,IAAIN,EAAMO,QAAQL,IACrC,OAAOF,EAAMQ,MAAMJ,GAAOK,OAAOT,EAAMQ,MAAM,EAAGJ,GACjD,GACDX,GACDiB,EAAAC,EAAAA,eAAAd,EAAA,GAED,MAAO,CAFNc,EAAAA,eAAAD,EAAA,GAAA,GAPa,GAASA,EAAA,GAUzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers-BDc6tlcX.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.1 */
|
|
2
|
-
import{_ as r}from"../_rollupPluginBabelHelpers-BDc6tlcX.js";import e from"react";var n=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[!1,!0],t=e.useReducer((function(r,e){var n=e instanceof Function?e(r[0]):e,t=Math.abs(r.indexOf(n));return r.slice(t).concat(r.slice(0,t))}),n),o=r(t,2);return[r(o[0],1)[0],o[1]]};export{n as useToggle};
|
|
3
|
-
//# sourceMappingURL=useToggle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToggle.js","sources":["../../../src/hooks/useToggle.ts"],"sourcesContent":["import React from 'react';\n\nexport type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];\n\nexport const useToggle = <Value = boolean>(values: readonly Value[] = [false, true] as any) => {\n const [[option], toggle] = React.useReducer(\n (state: Value[], action: React.SetStateAction<Value>) => {\n const value = action instanceof Function ? action(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n return state.slice(index).concat(state.slice(0, index));\n },\n values as Value[]\n );\n\n return [option, toggle as (value?: Value) => void] as const;\n};\n"],"names":["useToggle","values","arguments","length","undefined","_React$useReducer","React","useReducer","state","action","value","Function","index","Math","abs","indexOf","slice","concat","_React$useReducer2","_slicedToArray"],"mappings":";sFAIaA,EAAY,WAAsE,IAApDC,EAAwBC,UAAAC,eAAAC,IAAAF,UAAA,GAAAA,UAAG,GAAA,EAAC,GAAO,GAC5EG,EAA2BC,EAAMC,YAC/B,SAACC,EAAgBC,GACf,IAAMC,EAAQD,aAAkBE,SAAWF,EAAOD,EAAM,IAAMC,EACxDG,EAAQC,KAAKC,IAAIN,EAAMO,QAAQL,IACrC,OAAOF,EAAMQ,MAAMJ,GAAOK,OAAOT,EAAMQ,MAAM,EAAGJ,GACjD,GACDX,GACDiB,EAAAC,EAAAd,EAAA,GAED,MAAO,CAFNc,EAAAD,EAAA,GAAA,GAPa,GAASA,EAAA,GAUzB"}
|