react-simplikit 0.0.53 → 0.2.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/CHANGELOG.md +126 -0
- package/README.md +2 -42
- package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +1 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +1 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +1 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +1 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +1 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +1 -0
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +24 -6
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts +17 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.d.mts +17 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +24 -6
- package/dist/hooks/useDoubleClick/useDoubleClick.cjs +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.d.cts +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.mjs +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.cjs +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.d.cts +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.d.mts +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.mjs +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.cjs +7 -5
- package/dist/hooks/useImpressionRef/useImpressionRef.d.cts +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.d.mts +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.mjs +7 -5
- package/dist/hooks/useInputState/useInputState.cjs +9 -3
- package/dist/hooks/useInputState/useInputState.d.cts +11 -4
- package/dist/hooks/useInputState/useInputState.d.mts +11 -4
- package/dist/hooks/useInputState/useInputState.mjs +9 -3
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.d.cts +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +1 -5
- package/dist/hooks/useList/useList.cjs +11 -8
- package/dist/hooks/useList/useList.d.cts +12 -9
- package/dist/hooks/useList/useList.d.mts +12 -9
- package/dist/hooks/useList/useList.mjs +11 -8
- package/dist/hooks/useLoading/useLoading.cjs +3 -5
- package/dist/hooks/useLoading/useLoading.d.cts +2 -5
- package/dist/hooks/useLoading/useLoading.d.mts +2 -5
- package/dist/hooks/useLoading/useLoading.mjs +3 -5
- package/dist/hooks/useLongPress/useLongPress.cjs +0 -4
- package/dist/hooks/useLongPress/useLongPress.d.cts +0 -4
- package/dist/hooks/useLongPress/useLongPress.d.mts +0 -4
- package/dist/hooks/useLongPress/useLongPress.mjs +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.cts +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.mts +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +0 -4
- package/dist/hooks/usePreservedReference/usePreservedReference.cjs +1 -0
- package/dist/hooks/usePreservedReference/usePreservedReference.mjs +1 -0
- package/dist/hooks/useRefEffect/useRefEffect.cjs +1 -0
- package/dist/hooks/useRefEffect/useRefEffect.mjs +1 -0
- package/dist/hooks/useSet/useSet.cjs +11 -2
- package/dist/hooks/useSet/useSet.d.cts +11 -2
- package/dist/hooks/useSet/useSet.d.mts +11 -2
- package/dist/hooks/useSet/useSet.mjs +11 -2
- package/dist/hooks/useStorageState/useStorageState.cjs +1 -0
- package/dist/hooks/useStorageState/useStorageState.d.cts +0 -4
- package/dist/hooks/useStorageState/useStorageState.d.mts +0 -4
- package/dist/hooks/useStorageState/useStorageState.mjs +1 -0
- package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +16 -9
- package/dist/hooks/useThrottledCallback/useThrottledCallback.d.cts +18 -11
- package/dist/hooks/useThrottledCallback/useThrottledCallback.d.mts +18 -11
- package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +16 -9
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.d.mts +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +2 -4
- package/dist/index.cjs +34 -0
- package/dist/index.d.cts +19 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.mjs +18 -1
- package/dist/mobile/hooks/useAvoidKeyboard/index.d.cts +3 -0
- package/dist/mobile/hooks/useAvoidKeyboard/index.d.mts +3 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.cjs +75 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.cts +89 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.mts +89 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.mjs +75 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.cjs +47 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.cts +37 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.mts +37 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.mjs +47 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.cjs +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.cts +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.mts +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.mjs +41 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.cjs +88 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.cts +77 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.mts +77 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.mjs +88 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.cjs +75 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.cts +64 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.mts +64 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.mjs +75 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.cjs +74 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.cts +55 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.mts +55 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.mjs +74 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.cjs +79 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.cts +40 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.mts +40 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.mjs +79 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.cjs +77 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.cts +89 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.mts +89 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.mjs +77 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.cjs +55 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.cts +22 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.mts +22 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.mjs +55 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.cjs +49 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.cts +23 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.mts +23 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.mjs +49 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.cjs +35 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.cts +28 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.mts +28 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.mjs +35 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.cjs +58 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.cts +44 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.mts +44 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.mjs +58 -0
- package/dist/mobile/utils/isAndroid/isAndroid.cjs +32 -0
- package/dist/mobile/utils/isAndroid/isAndroid.d.cts +27 -0
- package/dist/mobile/utils/isAndroid/isAndroid.d.mts +27 -0
- package/dist/mobile/utils/isAndroid/isAndroid.mjs +32 -0
- package/dist/mobile/utils/isIOS/isIOS.cjs +37 -0
- package/dist/mobile/utils/isIOS/isIOS.d.cts +30 -0
- package/dist/mobile/utils/isIOS/isIOS.d.mts +30 -0
- package/dist/mobile/utils/isIOS/isIOS.mjs +37 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.cjs +28 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.cts +25 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.mts +25 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.mjs +28 -0
- package/dist/mobile/utils/isServer/isServer.cjs +24 -0
- package/dist/mobile/utils/isServer/isServer.d.cts +22 -0
- package/dist/mobile/utils/isServer/isServer.d.mts +22 -0
- package/dist/mobile/utils/isServer/isServer.mjs +24 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.cjs +71 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.cts +64 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.mts +64 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.mjs +71 -0
- package/dist/utils/buildContext/buildContext.cjs +1 -0
- package/dist/utils/buildContext/buildContext.mjs +1 -0
- package/dist/utils/mergeProps/mergeProps.cjs +1 -1
- package/dist/utils/mergeProps/mergeProps.d.cts +1 -1
- package/dist/utils/mergeProps/mergeProps.d.mts +1 -1
- package/dist/utils/mergeProps/mergeProps.mjs +1 -1
- package/dist/utils/mergeRefs/mergeRefs.cjs +1 -1
- package/dist/utils/mergeRefs/mergeRefs.d.cts +1 -1
- package/dist/utils/mergeRefs/mergeRefs.d.mts +1 -1
- package/dist/utils/mergeRefs/mergeRefs.mjs +1 -1
- package/package.json +22 -10
|
@@ -6,10 +6,6 @@ import { useVisibilityEvent } from "../useVisibilityEvent/useVisibilityEvent.mjs
|
|
|
6
6
|
import { useRef } from "react";
|
|
7
7
|
//#region src/hooks/useImpressionRef/useImpressionRef.ts
|
|
8
8
|
/**
|
|
9
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (IntersectionObserver, Visibility API).
|
|
10
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
11
|
-
* This hook will be removed in a future major version.
|
|
12
|
-
*
|
|
13
9
|
* @description
|
|
14
10
|
* `useImpressionRef` is a React hook that measures the time a specific DOM element is visible on the screen and executes callbacks when the element enters or exits the viewport.
|
|
15
11
|
* It uses `IntersectionObserver` and the `Visibility API` to track the element's visibility.
|
|
@@ -41,10 +37,16 @@ function useImpressionRef({ onImpressionStart = () => {}, onImpressionEnd = () =
|
|
|
41
37
|
const impressionStartHandler = usePreservedCallback(onImpressionStart);
|
|
42
38
|
const impressionEndHandler = usePreservedCallback(onImpressionEnd);
|
|
43
39
|
const isIntersectingRef = useRef(false);
|
|
40
|
+
const hasImpressionStartedRef = useRef(false);
|
|
44
41
|
const impressionEventHandler = useDebouncedCallback({
|
|
45
42
|
timeThreshold,
|
|
46
43
|
onChange: (impressed) => {
|
|
47
|
-
(impressed
|
|
44
|
+
if (impressed) {
|
|
45
|
+
hasImpressionStartedRef.current = true;
|
|
46
|
+
impressionStartHandler();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (hasImpressionStartedRef.current) impressionEndHandler();
|
|
48
50
|
},
|
|
49
51
|
leading: true
|
|
50
52
|
});
|
|
@@ -4,19 +4,25 @@ let react = require("react");
|
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
7
|
+
* The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
|
|
7
8
|
*
|
|
8
9
|
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
9
10
|
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
10
11
|
* Defaults to an identity function that returns the input unchanged.
|
|
11
12
|
*
|
|
12
|
-
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
|
|
13
|
+
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
|
|
13
14
|
* - value `string` - The current state value;
|
|
14
|
-
* - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
|
|
15
|
+
* - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* function Example() {
|
|
18
19
|
* const [value, onChange] = useInputState('');
|
|
19
|
-
* return
|
|
20
|
+
* return (
|
|
21
|
+
* <>
|
|
22
|
+
* <input type="text" value={value} onChange={onChange} />
|
|
23
|
+
* <textarea value={value} onChange={onChange} />
|
|
24
|
+
* </>
|
|
25
|
+
* );
|
|
20
26
|
* }
|
|
21
27
|
*/
|
|
22
28
|
function useInputState(initialValue = "", transformValue = echo) {
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
|
|
2
2
|
import { ChangeEventHandler } from "react";
|
|
3
3
|
//#region src/hooks/useInputState/useInputState.d.ts
|
|
4
|
+
type InputLikeElement = HTMLInputElement | HTMLTextAreaElement;
|
|
4
5
|
/**
|
|
5
6
|
* @description
|
|
6
7
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
8
|
+
* The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
|
|
7
9
|
*
|
|
8
10
|
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
9
11
|
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
10
12
|
* Defaults to an identity function that returns the input unchanged.
|
|
11
13
|
*
|
|
12
|
-
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
|
|
14
|
+
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
|
|
13
15
|
* - value `string` - The current state value;
|
|
14
|
-
* - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
|
|
16
|
+
* - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* function Example() {
|
|
18
20
|
* const [value, onChange] = useInputState('');
|
|
19
|
-
* return
|
|
21
|
+
* return (
|
|
22
|
+
* <>
|
|
23
|
+
* <input type="text" value={value} onChange={onChange} />
|
|
24
|
+
* <textarea value={value} onChange={onChange} />
|
|
25
|
+
* </>
|
|
26
|
+
* );
|
|
20
27
|
* }
|
|
21
28
|
*/
|
|
22
|
-
declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<
|
|
29
|
+
declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<InputLikeElement>];
|
|
23
30
|
//#endregion
|
|
24
31
|
export { useInputState };
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
|
|
2
2
|
import { ChangeEventHandler } from "react";
|
|
3
3
|
//#region src/hooks/useInputState/useInputState.d.ts
|
|
4
|
+
type InputLikeElement = HTMLInputElement | HTMLTextAreaElement;
|
|
4
5
|
/**
|
|
5
6
|
* @description
|
|
6
7
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
8
|
+
* The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
|
|
7
9
|
*
|
|
8
10
|
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
9
11
|
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
10
12
|
* Defaults to an identity function that returns the input unchanged.
|
|
11
13
|
*
|
|
12
|
-
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
|
|
14
|
+
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
|
|
13
15
|
* - value `string` - The current state value;
|
|
14
|
-
* - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
|
|
16
|
+
* - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* function Example() {
|
|
18
20
|
* const [value, onChange] = useInputState('');
|
|
19
|
-
* return
|
|
21
|
+
* return (
|
|
22
|
+
* <>
|
|
23
|
+
* <input type="text" value={value} onChange={onChange} />
|
|
24
|
+
* <textarea value={value} onChange={onChange} />
|
|
25
|
+
* </>
|
|
26
|
+
* );
|
|
20
27
|
* }
|
|
21
28
|
*/
|
|
22
|
-
declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<
|
|
29
|
+
declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<InputLikeElement>];
|
|
23
30
|
//#endregion
|
|
24
31
|
export { useInputState };
|
|
@@ -4,19 +4,25 @@ import { useCallback, useState } from "react";
|
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
7
|
+
* The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
|
|
7
8
|
*
|
|
8
9
|
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
9
10
|
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
10
11
|
* Defaults to an identity function that returns the input unchanged.
|
|
11
12
|
*
|
|
12
|
-
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
|
|
13
|
+
* @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
|
|
13
14
|
* - value `string` - The current state value;
|
|
14
|
-
* - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
|
|
15
|
+
* - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* function Example() {
|
|
18
19
|
* const [value, onChange] = useInputState('');
|
|
19
|
-
* return
|
|
20
|
+
* return (
|
|
21
|
+
* <>
|
|
22
|
+
* <input type="text" value={value} onChange={onChange} />
|
|
23
|
+
* <textarea value={value} onChange={onChange} />
|
|
24
|
+
* </>
|
|
25
|
+
* );
|
|
20
26
|
* }
|
|
21
27
|
*/
|
|
22
28
|
function useInputState(initialValue = "", transformValue = echo) {
|
|
@@ -4,10 +4,6 @@ const require_useRefEffect = require("../useRefEffect/useRefEffect.cjs");
|
|
|
4
4
|
let react = require("react");
|
|
5
5
|
//#region src/hooks/useIntersectionObserver/useIntersectionObserver.ts
|
|
6
6
|
/**
|
|
7
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (IntersectionObserver).
|
|
8
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
9
|
-
* This hook will be removed in a future major version.
|
|
10
|
-
*
|
|
11
7
|
* @description
|
|
12
8
|
* `useIntersectionObserver` is a React hook that detects whether a specific DOM element is visible on the screen.
|
|
13
9
|
* It uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
@@ -15,7 +11,7 @@ let react = require("react");
|
|
|
15
11
|
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
16
12
|
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
17
13
|
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
18
|
-
* @param {
|
|
14
|
+
* @param {Element | Document | null} [options.root] - The element that is used as the viewport for checking visibility of the target.
|
|
19
15
|
* @param {string} [options.rootMargin] - Margin around the root.
|
|
20
16
|
* @param {number | number[]} [options.threshold] - Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed.
|
|
21
17
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/hooks/useIntersectionObserver/useIntersectionObserver.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (IntersectionObserver).
|
|
5
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
6
|
-
* This hook will be removed in a future major version.
|
|
7
|
-
*
|
|
8
4
|
* @description
|
|
9
5
|
* `useIntersectionObserver` is a React hook that detects whether a specific DOM element is visible on the screen.
|
|
10
6
|
* It uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
@@ -12,7 +8,7 @@
|
|
|
12
8
|
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
13
9
|
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
14
10
|
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
15
|
-
* @param {
|
|
11
|
+
* @param {Element | Document | null} [options.root] - The element that is used as the viewport for checking visibility of the target.
|
|
16
12
|
* @param {string} [options.rootMargin] - Margin around the root.
|
|
17
13
|
* @param {number | number[]} [options.threshold] - Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed.
|
|
18
14
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/hooks/useIntersectionObserver/useIntersectionObserver.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (IntersectionObserver).
|
|
5
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
6
|
-
* This hook will be removed in a future major version.
|
|
7
|
-
*
|
|
8
4
|
* @description
|
|
9
5
|
* `useIntersectionObserver` is a React hook that detects whether a specific DOM element is visible on the screen.
|
|
10
6
|
* It uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
@@ -12,7 +8,7 @@
|
|
|
12
8
|
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
13
9
|
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
14
10
|
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
15
|
-
* @param {
|
|
11
|
+
* @param {Element | Document | null} [options.root] - The element that is used as the viewport for checking visibility of the target.
|
|
16
12
|
* @param {string} [options.rootMargin] - Margin around the root.
|
|
17
13
|
* @param {number | number[]} [options.threshold] - Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed.
|
|
18
14
|
*
|
|
@@ -4,10 +4,6 @@ import { useRefEffect } from "../useRefEffect/useRefEffect.mjs";
|
|
|
4
4
|
import { useMemo } from "react";
|
|
5
5
|
//#region src/hooks/useIntersectionObserver/useIntersectionObserver.ts
|
|
6
6
|
/**
|
|
7
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (IntersectionObserver).
|
|
8
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
9
|
-
* This hook will be removed in a future major version.
|
|
10
|
-
*
|
|
11
7
|
* @description
|
|
12
8
|
* `useIntersectionObserver` is a React hook that detects whether a specific DOM element is visible on the screen.
|
|
13
9
|
* It uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
@@ -15,7 +11,7 @@ import { useMemo } from "react";
|
|
|
15
11
|
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
16
12
|
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
17
13
|
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
18
|
-
* @param {
|
|
14
|
+
* @param {Element | Document | null} [options.root] - The element that is used as the viewport for checking visibility of the target.
|
|
19
15
|
* @param {string} [options.rootMargin] - Margin around the root.
|
|
20
16
|
* @param {number | number[]} [options.threshold] - Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed.
|
|
21
17
|
*
|
|
@@ -8,15 +8,18 @@ let react = require("react");
|
|
|
8
8
|
* A React hook that manages an array as state.
|
|
9
9
|
* Provides efficient state management and stable action functions.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @template T - The type of the values held in the list.
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `
|
|
17
|
-
* - `
|
|
18
|
-
* - `
|
|
19
|
-
* - `
|
|
13
|
+
* @param {T[]} [initialState=[]] - Initial array state.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it.
|
|
16
|
+
* - list `ReadonlyArray<T>` - The current array state;
|
|
17
|
+
* - actions.push `(value: T) => void` - Appends a value to the end of the list;
|
|
18
|
+
* - actions.insertAt `(index: number, value: T) => void` - Inserts a value at the specified index;
|
|
19
|
+
* - actions.updateAt `(index: number, value: T) => void` - Updates the value at the specified index;
|
|
20
|
+
* - actions.removeAt `(index: number) => void` - Removes the value at the specified index;
|
|
21
|
+
* - actions.setAll `(values: T[]) => void` - Replaces the entire list with a new array;
|
|
22
|
+
* - actions.reset `() => void` - Resets the list to its initial state;
|
|
20
23
|
*
|
|
21
24
|
* @example
|
|
22
25
|
* ```tsx
|
|
@@ -14,15 +14,18 @@ type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
|
14
14
|
* A React hook that manages an array as state.
|
|
15
15
|
* Provides efficient state management and stable action functions.
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - `
|
|
23
|
-
* - `
|
|
24
|
-
* - `
|
|
25
|
-
* - `
|
|
17
|
+
* @template T - The type of the values held in the list.
|
|
18
|
+
*
|
|
19
|
+
* @param {T[]} [initialState=[]] - Initial array state.
|
|
20
|
+
*
|
|
21
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it.
|
|
22
|
+
* - list `ReadonlyArray<T>` - The current array state;
|
|
23
|
+
* - actions.push `(value: T) => void` - Appends a value to the end of the list;
|
|
24
|
+
* - actions.insertAt `(index: number, value: T) => void` - Inserts a value at the specified index;
|
|
25
|
+
* - actions.updateAt `(index: number, value: T) => void` - Updates the value at the specified index;
|
|
26
|
+
* - actions.removeAt `(index: number) => void` - Removes the value at the specified index;
|
|
27
|
+
* - actions.setAll `(values: T[]) => void` - Replaces the entire list with a new array;
|
|
28
|
+
* - actions.reset `() => void` - Resets the list to its initial state;
|
|
26
29
|
*
|
|
27
30
|
* @example
|
|
28
31
|
* ```tsx
|
|
@@ -14,15 +14,18 @@ type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
|
14
14
|
* A React hook that manages an array as state.
|
|
15
15
|
* Provides efficient state management and stable action functions.
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - `
|
|
23
|
-
* - `
|
|
24
|
-
* - `
|
|
25
|
-
* - `
|
|
17
|
+
* @template T - The type of the values held in the list.
|
|
18
|
+
*
|
|
19
|
+
* @param {T[]} [initialState=[]] - Initial array state.
|
|
20
|
+
*
|
|
21
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it.
|
|
22
|
+
* - list `ReadonlyArray<T>` - The current array state;
|
|
23
|
+
* - actions.push `(value: T) => void` - Appends a value to the end of the list;
|
|
24
|
+
* - actions.insertAt `(index: number, value: T) => void` - Inserts a value at the specified index;
|
|
25
|
+
* - actions.updateAt `(index: number, value: T) => void` - Updates the value at the specified index;
|
|
26
|
+
* - actions.removeAt `(index: number) => void` - Removes the value at the specified index;
|
|
27
|
+
* - actions.setAll `(values: T[]) => void` - Replaces the entire list with a new array;
|
|
28
|
+
* - actions.reset `() => void` - Resets the list to its initial state;
|
|
26
29
|
*
|
|
27
30
|
* @example
|
|
28
31
|
* ```tsx
|
|
@@ -8,15 +8,18 @@ import { useMemo, useState } from "react";
|
|
|
8
8
|
* A React hook that manages an array as state.
|
|
9
9
|
* Provides efficient state management and stable action functions.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @template T - The type of the values held in the list.
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `
|
|
17
|
-
* - `
|
|
18
|
-
* - `
|
|
19
|
-
* - `
|
|
13
|
+
* @param {T[]} [initialState=[]] - Initial array state.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it.
|
|
16
|
+
* - list `ReadonlyArray<T>` - The current array state;
|
|
17
|
+
* - actions.push `(value: T) => void` - Appends a value to the end of the list;
|
|
18
|
+
* - actions.insertAt `(index: number, value: T) => void` - Inserts a value at the specified index;
|
|
19
|
+
* - actions.updateAt `(index: number, value: T) => void` - Updates the value at the specified index;
|
|
20
|
+
* - actions.removeAt `(index: number) => void` - Removes the value at the specified index;
|
|
21
|
+
* - actions.setAll `(values: T[]) => void` - Replaces the entire list with a new array;
|
|
22
|
+
* - actions.reset `() => void` - Resets the list to its initial state;
|
|
20
23
|
*
|
|
21
24
|
* @example
|
|
22
25
|
* ```tsx
|
|
@@ -7,12 +7,9 @@ let react = require("react");
|
|
|
7
7
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
8
8
|
*
|
|
9
9
|
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
10
|
-
* - loading `boolean` - Represents the current loading state.
|
|
11
|
-
* : The initial value is `false`.
|
|
12
|
-
* : It is set to `true` when an asynchronous task is in progress;
|
|
10
|
+
* - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
|
|
13
11
|
*
|
|
14
|
-
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
15
|
-
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
12
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
16
13
|
*
|
|
17
14
|
* @example
|
|
18
15
|
* function ConfirmButton() {
|
|
@@ -48,6 +45,7 @@ function useLoading() {
|
|
|
48
45
|
return (0, react.useMemo)(() => [loading, startTransition], [loading, startTransition]);
|
|
49
46
|
}
|
|
50
47
|
function useIsMountedRef() {
|
|
48
|
+
"use no memo";
|
|
51
49
|
const ref = (0, react.useRef)({ isMounted: true }).current;
|
|
52
50
|
(0, react.useEffect)(function trackMountedState() {
|
|
53
51
|
ref.isMounted = true;
|
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
7
7
|
*
|
|
8
8
|
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
9
|
-
* - loading `boolean` - Represents the current loading state.
|
|
10
|
-
* : The initial value is `false`.
|
|
11
|
-
* : It is set to `true` when an asynchronous task is in progress;
|
|
9
|
+
* - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
|
|
12
10
|
*
|
|
13
|
-
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
14
|
-
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
11
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
15
12
|
*
|
|
16
13
|
* @example
|
|
17
14
|
* function ConfirmButton() {
|
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
7
7
|
*
|
|
8
8
|
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
9
|
-
* - loading `boolean` - Represents the current loading state.
|
|
10
|
-
* : The initial value is `false`.
|
|
11
|
-
* : It is set to `true` when an asynchronous task is in progress;
|
|
9
|
+
* - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
|
|
12
10
|
*
|
|
13
|
-
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
14
|
-
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
11
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
15
12
|
*
|
|
16
13
|
* @example
|
|
17
14
|
* function ConfirmButton() {
|
|
@@ -7,12 +7,9 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
7
7
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
8
8
|
*
|
|
9
9
|
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
10
|
-
* - loading `boolean` - Represents the current loading state.
|
|
11
|
-
* : The initial value is `false`.
|
|
12
|
-
* : It is set to `true` when an asynchronous task is in progress;
|
|
10
|
+
* - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
|
|
13
11
|
*
|
|
14
|
-
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
15
|
-
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
12
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
16
13
|
*
|
|
17
14
|
* @example
|
|
18
15
|
* function ConfirmButton() {
|
|
@@ -48,6 +45,7 @@ function useLoading() {
|
|
|
48
45
|
return useMemo(() => [loading, startTransition], [loading, startTransition]);
|
|
49
46
|
}
|
|
50
47
|
function useIsMountedRef() {
|
|
48
|
+
"use no memo";
|
|
51
49
|
const ref = useRef({ isMounted: true }).current;
|
|
52
50
|
useEffect(function trackMountedState() {
|
|
53
51
|
ref.isMounted = true;
|
|
@@ -3,10 +3,6 @@ const require_usePreservedCallback = require("../usePreservedCallback/usePreserv
|
|
|
3
3
|
let react = require("react");
|
|
4
4
|
//#region src/hooks/useLongPress/useLongPress.ts
|
|
5
5
|
/**
|
|
6
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
|
|
7
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
8
|
-
* This hook will be removed in a future major version.
|
|
9
|
-
*
|
|
10
6
|
* @description
|
|
11
7
|
* `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
|
|
12
8
|
* It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
|
|
@@ -12,10 +12,6 @@ type UseLongPressOptions<E extends HTMLElement> = {
|
|
|
12
12
|
onLongPressEnd?: Handler<E>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
|
|
16
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
17
|
-
* This hook will be removed in a future major version.
|
|
18
|
-
*
|
|
19
15
|
* @description
|
|
20
16
|
* `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
|
|
21
17
|
* It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
|
|
@@ -12,10 +12,6 @@ type UseLongPressOptions<E extends HTMLElement> = {
|
|
|
12
12
|
onLongPressEnd?: Handler<E>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
|
|
16
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
17
|
-
* This hook will be removed in a future major version.
|
|
18
|
-
*
|
|
19
15
|
* @description
|
|
20
16
|
* `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
|
|
21
17
|
* It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
|
|
@@ -3,10 +3,6 @@ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallba
|
|
|
3
3
|
import { useCallback, useRef } from "react";
|
|
4
4
|
//#region src/hooks/useLongPress/useLongPress.ts
|
|
5
5
|
/**
|
|
6
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
|
|
7
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
8
|
-
* This hook will be removed in a future major version.
|
|
9
|
-
*
|
|
10
6
|
* @description
|
|
11
7
|
* `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
|
|
12
8
|
* It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
|
|
@@ -3,10 +3,6 @@ const require_usePreservedCallback = require("../usePreservedCallback/usePreserv
|
|
|
3
3
|
let react = require("react");
|
|
4
4
|
//#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts
|
|
5
5
|
/**
|
|
6
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
|
|
7
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
8
|
-
* This hook will be removed in a future major version.
|
|
9
|
-
*
|
|
10
6
|
* @description
|
|
11
7
|
* `useOutsideClickEffect` is a React hook that triggers a callback when a click event occurs outside the specified container(s).
|
|
12
8
|
* It is useful for closing modals, dropdowns, tooltips, and other UI components when clicking outside.
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
//#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.d.ts
|
|
3
3
|
type OneOrMore<T> = T | T[];
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
|
|
6
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
7
|
-
* This hook will be removed in a future major version.
|
|
8
|
-
*
|
|
9
5
|
* @description
|
|
10
6
|
* `useOutsideClickEffect` is a React hook that triggers a callback when a click event occurs outside the specified container(s).
|
|
11
7
|
* It is useful for closing modals, dropdowns, tooltips, and other UI components when clicking outside.
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
//#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.d.ts
|
|
3
3
|
type OneOrMore<T> = T | T[];
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
|
|
6
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
7
|
-
* This hook will be removed in a future major version.
|
|
8
|
-
*
|
|
9
5
|
* @description
|
|
10
6
|
* `useOutsideClickEffect` is a React hook that triggers a callback when a click event occurs outside the specified container(s).
|
|
11
7
|
* It is useful for closing modals, dropdowns, tooltips, and other UI components when clicking outside.
|
|
@@ -3,10 +3,6 @@ import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallba
|
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
//#region src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts
|
|
5
5
|
/**
|
|
6
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, document).
|
|
7
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
8
|
-
* This hook will be removed in a future major version.
|
|
9
|
-
*
|
|
10
6
|
* @description
|
|
11
7
|
* `useOutsideClickEffect` is a React hook that triggers a callback when a click event occurs outside the specified container(s).
|
|
12
8
|
* It is useful for closing modals, dropdowns, tooltips, and other UI components when clicking outside.
|
|
@@ -42,6 +42,7 @@ let react = require("react");
|
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
44
|
function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
|
|
45
|
+
"use no memo";
|
|
45
46
|
const ref = (0, react.useRef)(value);
|
|
46
47
|
return (0, react.useMemo)(() => {
|
|
47
48
|
if (!areValuesEqual(ref.current, value)) ref.current = value;
|
|
@@ -42,6 +42,7 @@ import { useMemo, useRef } from "react";
|
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
44
|
function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
|
|
45
|
+
"use no memo";
|
|
45
46
|
const ref = useRef(value);
|
|
46
47
|
return useMemo(() => {
|
|
47
48
|
if (!areValuesEqual(ref.current, value)) ref.current = value;
|
|
@@ -28,6 +28,7 @@ let react = require("react");
|
|
|
28
28
|
* }
|
|
29
29
|
*/
|
|
30
30
|
function useRefEffect(callback, deps) {
|
|
31
|
+
"use no memo";
|
|
31
32
|
const preservedCallback = require_usePreservedCallback.usePreservedCallback(callback);
|
|
32
33
|
const cleanupCallbackRef = (0, react.useRef)(() => {});
|
|
33
34
|
return (0, react.useCallback)((element) => {
|
|
@@ -28,6 +28,7 @@ import { useCallback, useRef } from "react";
|
|
|
28
28
|
* }
|
|
29
29
|
*/
|
|
30
30
|
function useRefEffect(callback, deps) {
|
|
31
|
+
"use no memo";
|
|
31
32
|
const preservedCallback = usePreservedCallback(callback);
|
|
32
33
|
const cleanupCallbackRef = useRef(() => {});
|
|
33
34
|
return useCallback((element) => {
|
|
@@ -8,8 +8,17 @@ let react = require("react");
|
|
|
8
8
|
* A React hook that manages a Set as state.
|
|
9
9
|
* Provides efficient state management and stable action functions.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
11
|
+
* @template T - The type of the values held in the set.
|
|
12
|
+
*
|
|
13
|
+
* @param {SetOrValues<T>} [initialState=new Set()] - Initial Set state (Set object or array of values).
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseSetReturn<T>} A tuple containing the Set state and actions to manipulate it.
|
|
16
|
+
* - [0] `Omit<Set<T>, 'add' | 'clear' | 'delete'>` - The current Set state with mutation methods hidden;
|
|
17
|
+
* - [1].add `(value: T) => void` - Adds a value to the set;
|
|
18
|
+
* - [1].remove `(value: T) => void` - Removes a value from the set;
|
|
19
|
+
* - [1].toggle `(value: T) => void` - Adds the value if absent, removes it if present;
|
|
20
|
+
* - [1].setAll `(values: Set<T> | T[]) => void` - Replaces all values in the set;
|
|
21
|
+
* - [1].reset `() => void` - Resets the set to its initial state;
|
|
13
22
|
*
|
|
14
23
|
* @example
|
|
15
24
|
* ```tsx
|
|
@@ -14,8 +14,17 @@ type UseSetReturn<T> = [Omit<Set<T>, 'add' | 'clear' | 'delete'>, SetActions<T>]
|
|
|
14
14
|
* A React hook that manages a Set as state.
|
|
15
15
|
* Provides efficient state management and stable action functions.
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
17
|
+
* @template T - The type of the values held in the set.
|
|
18
|
+
*
|
|
19
|
+
* @param {SetOrValues<T>} [initialState=new Set()] - Initial Set state (Set object or array of values).
|
|
20
|
+
*
|
|
21
|
+
* @returns {UseSetReturn<T>} A tuple containing the Set state and actions to manipulate it.
|
|
22
|
+
* - [0] `Omit<Set<T>, 'add' | 'clear' | 'delete'>` - The current Set state with mutation methods hidden;
|
|
23
|
+
* - [1].add `(value: T) => void` - Adds a value to the set;
|
|
24
|
+
* - [1].remove `(value: T) => void` - Removes a value from the set;
|
|
25
|
+
* - [1].toggle `(value: T) => void` - Adds the value if absent, removes it if present;
|
|
26
|
+
* - [1].setAll `(values: Set<T> | T[]) => void` - Replaces all values in the set;
|
|
27
|
+
* - [1].reset `() => void` - Resets the set to its initial state;
|
|
19
28
|
*
|
|
20
29
|
* @example
|
|
21
30
|
* ```tsx
|