react-simplikit 0.0.50 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ImpressionArea/ImpressionArea.cjs +57 -0
- package/{esm/components/ImpressionArea/index.d.ts → dist/components/ImpressionArea/ImpressionArea.d.cts} +9 -8
- package/dist/components/ImpressionArea/ImpressionArea.d.mts +48 -0
- package/dist/components/ImpressionArea/ImpressionArea.mjs +57 -0
- package/dist/components/ImpressionArea/index.d.cts +2 -46
- package/dist/components/ImpressionArea/index.d.mts +3 -0
- package/dist/components/Separated/Separated.cjs +38 -0
- package/{esm/components/Separated/index.d.ts → dist/components/Separated/Separated.d.cts} +7 -7
- package/dist/components/Separated/Separated.d.mts +38 -0
- package/dist/components/Separated/Separated.mjs +38 -0
- package/dist/components/Separated/index.d.cts +2 -37
- package/dist/components/Separated/index.d.mts +3 -0
- package/dist/components/SwitchCase/SwitchCase.cjs +40 -0
- package/{esm/components/SwitchCase/index.d.ts → dist/components/SwitchCase/SwitchCase.d.cts} +7 -8
- package/dist/components/SwitchCase/SwitchCase.d.mts +45 -0
- package/dist/components/SwitchCase/SwitchCase.mjs +40 -0
- package/dist/components/SwitchCase/index.d.cts +2 -45
- package/dist/components/SwitchCase/index.d.mts +3 -0
- package/dist/hooks/useAsyncEffect/index.d.cts +2 -24
- package/dist/hooks/useAsyncEffect/index.d.mts +3 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +39 -0
- package/{esm/hooks/useAsyncEffect/index.d.ts → dist/hooks/useAsyncEffect/useAsyncEffect.d.cts} +4 -3
- package/dist/hooks/useAsyncEffect/useAsyncEffect.d.mts +26 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +39 -0
- package/dist/hooks/useBooleanState/useBooleanState.cjs +36 -0
- package/dist/hooks/useBooleanState/{index.d.cts → useBooleanState.d.cts} +4 -2
- package/{esm/hooks/useBooleanState/index.d.ts → dist/hooks/useBooleanState/useBooleanState.d.mts} +4 -2
- package/dist/hooks/useBooleanState/useBooleanState.mjs +36 -0
- package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -39
- package/dist/hooks/useCallbackOncePerRender/index.d.mts +3 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +52 -0
- package/{esm/hooks/useCallbackOncePerRender/index.d.ts → dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.cts} +4 -3
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.mts +41 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +52 -0
- package/dist/hooks/useConditionalEffect/index.d.cts +2 -42
- package/dist/hooks/useConditionalEffect/index.d.mts +3 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +57 -0
- package/{esm/hooks/useConditionalEffect/index.d.ts → dist/hooks/useConditionalEffect/useConditionalEffect.d.cts} +4 -3
- package/dist/hooks/useConditionalEffect/useConditionalEffect.d.mts +44 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +57 -0
- package/dist/hooks/useControlledState/index.d.cts +2 -50
- package/dist/hooks/useControlledState/index.d.mts +3 -0
- package/dist/hooks/useControlledState/useControlledState.cjs +60 -0
- package/{esm/hooks/useControlledState/index.d.ts → dist/hooks/useControlledState/useControlledState.d.cts} +11 -10
- package/dist/hooks/useControlledState/useControlledState.d.mts +52 -0
- package/dist/hooks/useControlledState/useControlledState.mjs +60 -0
- package/dist/hooks/useCounter/useCounter.cjs +75 -0
- package/{esm/hooks/useCounter/index.d.ts → dist/hooks/useCounter/useCounter.d.cts} +12 -10
- package/dist/hooks/useCounter/{index.d.cts → useCounter.d.mts} +12 -10
- package/dist/hooks/useCounter/useCounter.mjs +75 -0
- package/dist/hooks/useDebounce/debounce.cjs +49 -0
- package/dist/hooks/useDebounce/debounce.d.cts +8 -0
- package/dist/hooks/useDebounce/debounce.d.mts +8 -0
- package/dist/hooks/useDebounce/debounce.mjs +49 -0
- package/dist/hooks/useDebounce/useDebounce.cjs +66 -0
- package/{esm/hooks/useDebounce/index.d.ts → dist/hooks/useDebounce/useDebounce.d.cts} +6 -8
- package/dist/hooks/useDebounce/{index.d.cts → useDebounce.d.mts} +6 -8
- package/dist/hooks/useDebounce/useDebounce.mjs +66 -0
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +62 -0
- package/{esm/hooks/useDebouncedCallback/index.d.ts → dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts} +9 -7
- package/dist/hooks/useDebouncedCallback/{index.d.cts → useDebouncedCallback.d.mts} +9 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +62 -0
- package/dist/hooks/useDoubleClick/index.d.cts +2 -45
- package/dist/hooks/useDoubleClick/index.d.mts +3 -0
- package/dist/hooks/useDoubleClick/useDoubleClick.cjs +64 -0
- package/{esm/hooks/useDoubleClick/index.d.ts → dist/hooks/useDoubleClick/useDoubleClick.d.cts} +8 -7
- package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +47 -0
- package/dist/hooks/useDoubleClick/useDoubleClick.mjs +64 -0
- package/dist/hooks/useGeolocation/useGeolocation.cjs +210 -0
- package/{esm/hooks/useGeolocation/index.d.ts → dist/hooks/useGeolocation/useGeolocation.d.cts} +26 -24
- package/dist/hooks/useGeolocation/{index.d.cts → useGeolocation.d.mts} +26 -24
- package/dist/hooks/useGeolocation/useGeolocation.mjs +209 -0
- package/dist/hooks/useImpressionRef/useImpressionRef.cjs +67 -0
- package/{esm/hooks/useImpressionRef/index.d.ts → dist/hooks/useImpressionRef/useImpressionRef.d.cts} +10 -8
- package/dist/hooks/useImpressionRef/{index.d.cts → useImpressionRef.d.mts} +10 -8
- package/dist/hooks/useImpressionRef/useImpressionRef.mjs +67 -0
- package/dist/hooks/useInputState/index.d.cts +2 -22
- package/dist/hooks/useInputState/index.d.mts +3 -0
- package/dist/hooks/useInputState/useInputState.cjs +32 -0
- package/{esm/hooks/useInputState/index.d.ts → dist/hooks/useInputState/useInputState.d.cts} +4 -3
- package/dist/hooks/useInputState/useInputState.d.mts +24 -0
- package/dist/hooks/useInputState/useInputState.mjs +32 -0
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +58 -0
- package/dist/hooks/useIntersectionObserver/{index.d.cts → useIntersectionObserver.d.cts} +4 -2
- package/{esm/hooks/useIntersectionObserver/index.d.ts → dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts} +4 -2
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +58 -0
- package/dist/hooks/useInterval/useInterval.cjs +65 -0
- package/dist/hooks/useInterval/{index.d.cts → useInterval.d.cts} +7 -5
- package/{esm/hooks/useInterval/index.d.ts → dist/hooks/useInterval/useInterval.d.mts} +7 -5
- package/dist/hooks/useInterval/useInterval.mjs +65 -0
- package/dist/hooks/useIsClient/useIsClient.cjs +49 -0
- package/dist/hooks/useIsClient/{index.d.cts → useIsClient.d.cts} +4 -2
- package/{esm/hooks/useIsClient/index.d.ts → dist/hooks/useIsClient/useIsClient.d.mts} +4 -2
- package/dist/hooks/useIsClient/useIsClient.mjs +49 -0
- package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +2 -24
- package/dist/hooks/useIsomorphicLayoutEffect/index.d.mts +3 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +25 -0
- package/{esm/hooks/useIsomorphicLayoutEffect/index.d.ts → dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.cts} +4 -3
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.mts +26 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +25 -0
- package/dist/hooks/useList/useList.cjs +94 -0
- package/{esm/hooks/useList/index.d.ts → dist/hooks/useList/useList.d.cts} +10 -8
- package/dist/hooks/useList/{index.d.cts → useList.d.mts} +10 -8
- package/dist/hooks/useList/useList.mjs +94 -0
- package/dist/hooks/useLoading/useLoading.cjs +61 -0
- package/dist/hooks/useLoading/{index.d.cts → useLoading.d.cts} +4 -2
- package/{esm/hooks/useLoading/index.d.ts → dist/hooks/useLoading/useLoading.d.mts} +4 -2
- package/dist/hooks/useLoading/useLoading.mjs +61 -0
- package/dist/hooks/useLongPress/index.d.cts +2 -73
- package/dist/hooks/useLongPress/index.d.mts +3 -0
- package/dist/hooks/useLongPress/useLongPress.cjs +133 -0
- package/{esm/hooks/useLongPress/index.d.ts → dist/hooks/useLongPress/useLongPress.d.cts} +18 -17
- package/dist/hooks/useLongPress/useLongPress.d.mts +75 -0
- package/dist/hooks/useLongPress/useLongPress.mjs +133 -0
- package/dist/hooks/useMap/useMap.cjs +64 -0
- package/dist/hooks/useMap/{index.d.cts → useMap.d.cts} +12 -10
- package/{esm/hooks/useMap/index.d.ts → dist/hooks/useMap/useMap.d.mts} +12 -10
- package/dist/hooks/useMap/useMap.mjs +64 -0
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +51 -0
- package/{esm/hooks/useOutsideClickEffect/index.d.ts → dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.cts} +4 -2
- package/dist/hooks/useOutsideClickEffect/{index.d.cts → useOutsideClickEffect.d.mts} +4 -2
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +51 -0
- package/dist/hooks/usePreservedCallback/usePreservedCallback.cjs +41 -0
- package/dist/hooks/usePreservedCallback/{index.d.cts → usePreservedCallback.d.cts} +4 -2
- package/{esm/hooks/usePreservedCallback/index.d.ts → dist/hooks/usePreservedCallback/usePreservedCallback.d.mts} +4 -2
- package/dist/hooks/usePreservedCallback/usePreservedCallback.mjs +41 -0
- package/dist/hooks/usePreservedReference/usePreservedReference.cjs +55 -0
- package/dist/hooks/usePreservedReference/{index.d.cts → usePreservedReference.d.cts} +4 -2
- package/{esm/hooks/usePreservedReference/index.d.ts → dist/hooks/usePreservedReference/usePreservedReference.d.mts} +4 -2
- package/dist/hooks/usePreservedReference/usePreservedReference.mjs +55 -0
- package/dist/hooks/usePrevious/usePrevious.cjs +38 -0
- package/{esm/hooks/usePrevious/index.d.ts → dist/hooks/usePrevious/usePrevious.d.cts} +4 -2
- package/dist/hooks/usePrevious/{index.d.cts → usePrevious.d.mts} +4 -2
- package/dist/hooks/usePrevious/usePrevious.mjs +38 -0
- package/dist/hooks/useRefEffect/index.d.cts +2 -30
- package/dist/hooks/useRefEffect/index.d.mts +3 -0
- package/dist/hooks/useRefEffect/useRefEffect.cjs +42 -0
- package/{esm/hooks/useRefEffect/index.d.ts → dist/hooks/useRefEffect/useRefEffect.d.cts} +4 -3
- package/dist/hooks/useRefEffect/useRefEffect.d.mts +32 -0
- package/dist/hooks/useRefEffect/useRefEffect.mjs +42 -0
- package/dist/hooks/useSet/useSet.cjs +79 -0
- package/dist/hooks/useSet/{index.d.cts → useSet.d.cts} +9 -7
- package/{esm/hooks/useSet/index.d.ts → dist/hooks/useSet/useSet.d.mts} +9 -7
- package/dist/hooks/useSet/useSet.mjs +79 -0
- package/dist/hooks/useStorageState/index.d.cts +2 -60
- package/dist/hooks/useStorageState/index.d.mts +3 -0
- package/dist/hooks/useStorageState/storage.cjs +85 -0
- package/dist/hooks/useStorageState/storage.d.cts +10 -0
- package/dist/hooks/useStorageState/storage.d.mts +10 -0
- package/dist/hooks/useStorageState/storage.mjs +80 -0
- package/dist/hooks/useStorageState/useStorageState.cjs +81 -0
- package/{esm/hooks/useStorageState/index.d.ts → dist/hooks/useStorageState/useStorageState.d.cts} +10 -15
- package/dist/hooks/useStorageState/useStorageState.d.mts +56 -0
- package/dist/hooks/useStorageState/useStorageState.mjs +81 -0
- package/dist/hooks/useThrottle/throttle.cjs +19 -0
- package/dist/hooks/useThrottle/throttle.d.cts +19 -0
- package/dist/hooks/useThrottle/throttle.d.mts +19 -0
- package/dist/hooks/useThrottle/throttle.mjs +19 -0
- package/dist/hooks/useThrottle/useThrottle.cjs +49 -0
- package/dist/hooks/useThrottle/{index.d.cts → useThrottle.d.cts} +6 -19
- package/{esm/hooks/useThrottle/index.d.ts → dist/hooks/useThrottle/useThrottle.d.mts} +6 -19
- package/dist/hooks/useThrottle/useThrottle.mjs +49 -0
- package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +57 -0
- package/{esm/hooks/useThrottledCallback/index.d.ts → dist/hooks/useThrottledCallback/useThrottledCallback.d.cts} +8 -6
- package/dist/hooks/useThrottledCallback/{index.d.cts → useThrottledCallback.d.mts} +8 -6
- package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +57 -0
- package/dist/hooks/useTimeout/useTimeout.cjs +40 -0
- package/dist/hooks/useTimeout/{index.d.cts → useTimeout.d.cts} +4 -2
- package/{esm/hooks/useTimeout/index.d.ts → dist/hooks/useTimeout/useTimeout.d.mts} +4 -2
- package/dist/hooks/useTimeout/useTimeout.mjs +40 -0
- package/dist/hooks/useToggle/useToggle.cjs +34 -0
- package/dist/hooks/useToggle/{index.d.cts → useToggle.d.cts} +4 -4
- package/{esm/hooks/useToggle/index.d.ts → dist/hooks/useToggle/useToggle.d.mts} +4 -4
- package/dist/hooks/useToggle/useToggle.mjs +34 -0
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +42 -0
- package/{esm/hooks/useVisibilityEvent/index.d.ts → dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts} +5 -3
- package/dist/hooks/useVisibilityEvent/{index.d.cts → useVisibilityEvent.d.mts} +5 -3
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +42 -0
- package/dist/index.cjs +77 -1382
- package/dist/index.d.cts +56 -40
- package/dist/index.d.mts +56 -0
- package/dist/index.mjs +40 -0
- package/dist/utils/buildContext/buildContext.cjs +50 -0
- package/{esm/utils/buildContext/index.d.ts → dist/utils/buildContext/buildContext.d.cts} +7 -7
- package/dist/utils/buildContext/buildContext.d.mts +38 -0
- package/dist/utils/buildContext/buildContext.mjs +50 -0
- package/dist/utils/buildContext/index.d.cts +2 -37
- package/dist/utils/buildContext/index.d.mts +3 -0
- package/dist/utils/mergeProps/index.d.cts +2 -25
- package/dist/utils/mergeProps/index.d.mts +3 -0
- package/dist/utils/mergeProps/mergeProps.cjs +53 -0
- package/{esm/utils/mergeProps/index.d.ts → dist/utils/mergeProps/mergeProps.d.cts} +7 -8
- package/dist/utils/mergeProps/mergeProps.d.mts +25 -0
- package/dist/utils/mergeProps/mergeProps.mjs +53 -0
- package/dist/utils/mergeRefs/index.d.cts +2 -38
- package/dist/utils/mergeRefs/index.d.mts +3 -0
- package/dist/utils/mergeRefs/mergeRefs.cjs +50 -0
- package/{esm/utils/mergeRefs/index.d.ts → dist/utils/mergeRefs/mergeRefs.d.cts} +4 -3
- package/dist/utils/mergeRefs/mergeRefs.d.mts +40 -0
- package/dist/utils/mergeRefs/mergeRefs.mjs +50 -0
- package/package.json +9 -11
- package/dist/components/ImpressionArea/index.cjs +0 -295
- package/dist/components/Separated/index.cjs +0 -41
- package/dist/components/SwitchCase/index.cjs +0 -36
- package/dist/hooks/useAsyncEffect/index.cjs +0 -44
- package/dist/hooks/useBooleanState/index.cjs +0 -46
- package/dist/hooks/useCallbackOncePerRender/index.cjs +0 -63
- package/dist/hooks/useConditionalEffect/index.cjs +0 -51
- package/dist/hooks/useControlledState/index.cjs +0 -57
- package/dist/hooks/useCounter/index.cjs +0 -70
- package/dist/hooks/useDebounce/index.cjs +0 -130
- package/dist/hooks/useDebouncedCallback/index.cjs +0 -148
- package/dist/hooks/useDoubleClick/index.cjs +0 -79
- package/dist/hooks/useGeolocation/index.cjs +0 -154
- package/dist/hooks/useImpressionRef/index.cjs +0 -258
- package/dist/hooks/useInputState/index.cjs +0 -46
- package/dist/hooks/useIntersectionObserver/index.cjs +0 -95
- package/dist/hooks/useInterval/index.cjs +0 -74
- package/dist/hooks/useIsClient/index.cjs +0 -40
- package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +0 -35
- package/dist/hooks/useList/index.cjs +0 -104
- package/dist/hooks/useLoading/index.cjs +0 -65
- package/dist/hooks/useLongPress/index.cjs +0 -127
- package/dist/hooks/useMap/index.cjs +0 -78
- package/dist/hooks/useOutsideClickEffect/index.cjs +0 -74
- package/dist/hooks/usePreservedCallback/index.cjs +0 -45
- package/dist/hooks/usePreservedReference/index.cjs +0 -45
- package/dist/hooks/usePrevious/index.cjs +0 -48
- package/dist/hooks/useRefEffect/index.cjs +0 -72
- package/dist/hooks/useSet/index.cjs +0 -105
- package/dist/hooks/useStorageState/index.cjs +0 -196
- package/dist/hooks/useThrottle/index.cjs +0 -151
- package/dist/hooks/useThrottledCallback/index.cjs +0 -172
- package/dist/hooks/useTimeout/index.cjs +0 -57
- package/dist/hooks/useToggle/index.cjs +0 -37
- package/dist/hooks/useVisibilityEvent/index.cjs +0 -47
- package/dist/utils/buildContext/index.cjs +0 -56
- package/dist/utils/mergeProps/index.cjs +0 -71
- package/dist/utils/mergeRefs/index.cjs +0 -46
- package/esm/components/ImpressionArea/index.js +0 -269
- package/esm/components/Separated/index.js +0 -15
- package/esm/components/SwitchCase/index.js +0 -10
- package/esm/hooks/useAsyncEffect/index.js +0 -18
- package/esm/hooks/useBooleanState/index.js +0 -20
- package/esm/hooks/useCallbackOncePerRender/index.js +0 -37
- package/esm/hooks/useConditionalEffect/index.js +0 -25
- package/esm/hooks/useControlledState/index.js +0 -31
- package/esm/hooks/useCounter/index.js +0 -44
- package/esm/hooks/useDebounce/index.js +0 -104
- package/esm/hooks/useDebouncedCallback/index.js +0 -122
- package/esm/hooks/useDoubleClick/index.js +0 -53
- package/esm/hooks/useGeolocation/index.js +0 -128
- package/esm/hooks/useImpressionRef/index.js +0 -232
- package/esm/hooks/useInputState/index.js +0 -20
- package/esm/hooks/useIntersectionObserver/index.js +0 -69
- package/esm/hooks/useInterval/index.js +0 -48
- package/esm/hooks/useIsClient/index.js +0 -14
- package/esm/hooks/useIsomorphicLayoutEffect/index.js +0 -9
- package/esm/hooks/useList/index.js +0 -78
- package/esm/hooks/useLoading/index.js +0 -39
- package/esm/hooks/useLongPress/index.js +0 -101
- package/esm/hooks/useMap/index.js +0 -52
- package/esm/hooks/useOutsideClickEffect/index.js +0 -48
- package/esm/hooks/usePreservedCallback/index.js +0 -19
- package/esm/hooks/usePreservedReference/index.js +0 -19
- package/esm/hooks/usePrevious/index.js +0 -22
- package/esm/hooks/useRefEffect/index.js +0 -46
- package/esm/hooks/useSet/index.js +0 -79
- package/esm/hooks/useStorageState/index.js +0 -170
- package/esm/hooks/useThrottle/index.js +0 -125
- package/esm/hooks/useThrottledCallback/index.js +0 -146
- package/esm/hooks/useTimeout/index.js +0 -31
- package/esm/hooks/useToggle/index.js +0 -11
- package/esm/hooks/useVisibilityEvent/index.js +0 -21
- package/esm/index.d.ts +0 -40
- package/esm/index.js +0 -1320
- package/esm/utils/buildContext/index.js +0 -30
- package/esm/utils/mergeProps/index.js +0 -45
- package/esm/utils/mergeRefs/index.js +0 -20
package/dist/index.d.cts
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import
|
|
40
|
-
import
|
|
1
|
+
|
|
2
|
+
import { useImpressionRef } from "./hooks/useImpressionRef/useImpressionRef.cjs";
|
|
3
|
+
import { ImpressionArea } from "./components/ImpressionArea/ImpressionArea.cjs";
|
|
4
|
+
import "./components/ImpressionArea/index.cjs";
|
|
5
|
+
import { Separated } from "./components/Separated/Separated.cjs";
|
|
6
|
+
import "./components/Separated/index.cjs";
|
|
7
|
+
import { SwitchCase } from "./components/SwitchCase/SwitchCase.cjs";
|
|
8
|
+
import "./components/SwitchCase/index.cjs";
|
|
9
|
+
import { useAsyncEffect } from "./hooks/useAsyncEffect/useAsyncEffect.cjs";
|
|
10
|
+
import "./hooks/useAsyncEffect/index.cjs";
|
|
11
|
+
import { useBooleanState } from "./hooks/useBooleanState/useBooleanState.cjs";
|
|
12
|
+
import { useCallbackOncePerRender } from "./hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs";
|
|
13
|
+
import "./hooks/useCallbackOncePerRender/index.cjs";
|
|
14
|
+
import { useConditionalEffect } from "./hooks/useConditionalEffect/useConditionalEffect.cjs";
|
|
15
|
+
import "./hooks/useConditionalEffect/index.cjs";
|
|
16
|
+
import { useControlledState } from "./hooks/useControlledState/useControlledState.cjs";
|
|
17
|
+
import "./hooks/useControlledState/index.cjs";
|
|
18
|
+
import { useCounter } from "./hooks/useCounter/useCounter.cjs";
|
|
19
|
+
import { useDebounce } from "./hooks/useDebounce/useDebounce.cjs";
|
|
20
|
+
import { useDebouncedCallback } from "./hooks/useDebouncedCallback/useDebouncedCallback.cjs";
|
|
21
|
+
import { useDoubleClick } from "./hooks/useDoubleClick/useDoubleClick.cjs";
|
|
22
|
+
import "./hooks/useDoubleClick/index.cjs";
|
|
23
|
+
import { useGeolocation } from "./hooks/useGeolocation/useGeolocation.cjs";
|
|
24
|
+
import { useInputState } from "./hooks/useInputState/useInputState.cjs";
|
|
25
|
+
import "./hooks/useInputState/index.cjs";
|
|
26
|
+
import { useIntersectionObserver } from "./hooks/useIntersectionObserver/useIntersectionObserver.cjs";
|
|
27
|
+
import { useInterval } from "./hooks/useInterval/useInterval.cjs";
|
|
28
|
+
import { useIsClient } from "./hooks/useIsClient/useIsClient.cjs";
|
|
29
|
+
import { useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs";
|
|
30
|
+
import "./hooks/useIsomorphicLayoutEffect/index.cjs";
|
|
31
|
+
import { useList } from "./hooks/useList/useList.cjs";
|
|
32
|
+
import { useLoading } from "./hooks/useLoading/useLoading.cjs";
|
|
33
|
+
import { useLongPress } from "./hooks/useLongPress/useLongPress.cjs";
|
|
34
|
+
import "./hooks/useLongPress/index.cjs";
|
|
35
|
+
import { useMap } from "./hooks/useMap/useMap.cjs";
|
|
36
|
+
import { useOutsideClickEffect } from "./hooks/useOutsideClickEffect/useOutsideClickEffect.cjs";
|
|
37
|
+
import { usePreservedCallback } from "./hooks/usePreservedCallback/usePreservedCallback.cjs";
|
|
38
|
+
import { usePreservedReference } from "./hooks/usePreservedReference/usePreservedReference.cjs";
|
|
39
|
+
import { usePrevious } from "./hooks/usePrevious/usePrevious.cjs";
|
|
40
|
+
import { useRefEffect } from "./hooks/useRefEffect/useRefEffect.cjs";
|
|
41
|
+
import "./hooks/useRefEffect/index.cjs";
|
|
42
|
+
import { useSet } from "./hooks/useSet/useSet.cjs";
|
|
43
|
+
import { useStorageState } from "./hooks/useStorageState/useStorageState.cjs";
|
|
44
|
+
import "./hooks/useStorageState/index.cjs";
|
|
45
|
+
import { useThrottle } from "./hooks/useThrottle/useThrottle.cjs";
|
|
46
|
+
import { useThrottledCallback } from "./hooks/useThrottledCallback/useThrottledCallback.cjs";
|
|
47
|
+
import { useTimeout } from "./hooks/useTimeout/useTimeout.cjs";
|
|
48
|
+
import { useToggle } from "./hooks/useToggle/useToggle.cjs";
|
|
49
|
+
import { useVisibilityEvent } from "./hooks/useVisibilityEvent/useVisibilityEvent.cjs";
|
|
50
|
+
import { buildContext } from "./utils/buildContext/buildContext.cjs";
|
|
51
|
+
import "./utils/buildContext/index.cjs";
|
|
52
|
+
import { mergeProps } from "./utils/mergeProps/mergeProps.cjs";
|
|
53
|
+
import "./utils/mergeProps/index.cjs";
|
|
54
|
+
import { mergeRefs } from "./utils/mergeRefs/mergeRefs.cjs";
|
|
55
|
+
import "./utils/mergeRefs/index.cjs";
|
|
56
|
+
export { ImpressionArea, Separated, SwitchCase, buildContext, mergeProps, mergeRefs, useAsyncEffect, useBooleanState, useCallbackOncePerRender, useConditionalEffect, useControlledState, useCounter, useDebounce, useDebouncedCallback, useDoubleClick, useGeolocation, useImpressionRef, useInputState, useIntersectionObserver, useInterval, useIsClient, useIsomorphicLayoutEffect, useList, useLoading, useLongPress, useMap, useOutsideClickEffect, usePreservedCallback, usePreservedReference, usePrevious, useRefEffect, useSet, useStorageState, useThrottle, useThrottledCallback, useTimeout, useToggle, useVisibilityEvent };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
import { useImpressionRef } from "./hooks/useImpressionRef/useImpressionRef.mjs";
|
|
3
|
+
import { ImpressionArea } from "./components/ImpressionArea/ImpressionArea.mjs";
|
|
4
|
+
import "./components/ImpressionArea/index.mjs";
|
|
5
|
+
import { Separated } from "./components/Separated/Separated.mjs";
|
|
6
|
+
import "./components/Separated/index.mjs";
|
|
7
|
+
import { SwitchCase } from "./components/SwitchCase/SwitchCase.mjs";
|
|
8
|
+
import "./components/SwitchCase/index.mjs";
|
|
9
|
+
import { useAsyncEffect } from "./hooks/useAsyncEffect/useAsyncEffect.mjs";
|
|
10
|
+
import "./hooks/useAsyncEffect/index.mjs";
|
|
11
|
+
import { useBooleanState } from "./hooks/useBooleanState/useBooleanState.mjs";
|
|
12
|
+
import { useCallbackOncePerRender } from "./hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs";
|
|
13
|
+
import "./hooks/useCallbackOncePerRender/index.mjs";
|
|
14
|
+
import { useConditionalEffect } from "./hooks/useConditionalEffect/useConditionalEffect.mjs";
|
|
15
|
+
import "./hooks/useConditionalEffect/index.mjs";
|
|
16
|
+
import { useControlledState } from "./hooks/useControlledState/useControlledState.mjs";
|
|
17
|
+
import "./hooks/useControlledState/index.mjs";
|
|
18
|
+
import { useCounter } from "./hooks/useCounter/useCounter.mjs";
|
|
19
|
+
import { useDebounce } from "./hooks/useDebounce/useDebounce.mjs";
|
|
20
|
+
import { useDebouncedCallback } from "./hooks/useDebouncedCallback/useDebouncedCallback.mjs";
|
|
21
|
+
import { useDoubleClick } from "./hooks/useDoubleClick/useDoubleClick.mjs";
|
|
22
|
+
import "./hooks/useDoubleClick/index.mjs";
|
|
23
|
+
import { useGeolocation } from "./hooks/useGeolocation/useGeolocation.mjs";
|
|
24
|
+
import { useInputState } from "./hooks/useInputState/useInputState.mjs";
|
|
25
|
+
import "./hooks/useInputState/index.mjs";
|
|
26
|
+
import { useIntersectionObserver } from "./hooks/useIntersectionObserver/useIntersectionObserver.mjs";
|
|
27
|
+
import { useInterval } from "./hooks/useInterval/useInterval.mjs";
|
|
28
|
+
import { useIsClient } from "./hooks/useIsClient/useIsClient.mjs";
|
|
29
|
+
import { useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
30
|
+
import "./hooks/useIsomorphicLayoutEffect/index.mjs";
|
|
31
|
+
import { useList } from "./hooks/useList/useList.mjs";
|
|
32
|
+
import { useLoading } from "./hooks/useLoading/useLoading.mjs";
|
|
33
|
+
import { useLongPress } from "./hooks/useLongPress/useLongPress.mjs";
|
|
34
|
+
import "./hooks/useLongPress/index.mjs";
|
|
35
|
+
import { useMap } from "./hooks/useMap/useMap.mjs";
|
|
36
|
+
import { useOutsideClickEffect } from "./hooks/useOutsideClickEffect/useOutsideClickEffect.mjs";
|
|
37
|
+
import { usePreservedCallback } from "./hooks/usePreservedCallback/usePreservedCallback.mjs";
|
|
38
|
+
import { usePreservedReference } from "./hooks/usePreservedReference/usePreservedReference.mjs";
|
|
39
|
+
import { usePrevious } from "./hooks/usePrevious/usePrevious.mjs";
|
|
40
|
+
import { useRefEffect } from "./hooks/useRefEffect/useRefEffect.mjs";
|
|
41
|
+
import "./hooks/useRefEffect/index.mjs";
|
|
42
|
+
import { useSet } from "./hooks/useSet/useSet.mjs";
|
|
43
|
+
import { useStorageState } from "./hooks/useStorageState/useStorageState.mjs";
|
|
44
|
+
import "./hooks/useStorageState/index.mjs";
|
|
45
|
+
import { useThrottle } from "./hooks/useThrottle/useThrottle.mjs";
|
|
46
|
+
import { useThrottledCallback } from "./hooks/useThrottledCallback/useThrottledCallback.mjs";
|
|
47
|
+
import { useTimeout } from "./hooks/useTimeout/useTimeout.mjs";
|
|
48
|
+
import { useToggle } from "./hooks/useToggle/useToggle.mjs";
|
|
49
|
+
import { useVisibilityEvent } from "./hooks/useVisibilityEvent/useVisibilityEvent.mjs";
|
|
50
|
+
import { buildContext } from "./utils/buildContext/buildContext.mjs";
|
|
51
|
+
import "./utils/buildContext/index.mjs";
|
|
52
|
+
import { mergeProps } from "./utils/mergeProps/mergeProps.mjs";
|
|
53
|
+
import "./utils/mergeProps/index.mjs";
|
|
54
|
+
import { mergeRefs } from "./utils/mergeRefs/mergeRefs.mjs";
|
|
55
|
+
import "./utils/mergeRefs/index.mjs";
|
|
56
|
+
export { ImpressionArea, Separated, SwitchCase, buildContext, mergeProps, mergeRefs, useAsyncEffect, useBooleanState, useCallbackOncePerRender, useConditionalEffect, useControlledState, useCounter, useDebounce, useDebouncedCallback, useDoubleClick, useGeolocation, useImpressionRef, useInputState, useIntersectionObserver, useInterval, useIsClient, useIsomorphicLayoutEffect, useList, useLoading, useLongPress, useMap, useOutsideClickEffect, usePreservedCallback, usePreservedReference, usePrevious, useRefEffect, useSet, useStorageState, useThrottle, useThrottledCallback, useTimeout, useToggle, useVisibilityEvent };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { usePreservedCallback } from "./hooks/usePreservedCallback/usePreservedCallback.mjs";
|
|
3
|
+
import { useDebouncedCallback } from "./hooks/useDebouncedCallback/useDebouncedCallback.mjs";
|
|
4
|
+
import { useRefEffect } from "./hooks/useRefEffect/useRefEffect.mjs";
|
|
5
|
+
import { useIntersectionObserver } from "./hooks/useIntersectionObserver/useIntersectionObserver.mjs";
|
|
6
|
+
import { useVisibilityEvent } from "./hooks/useVisibilityEvent/useVisibilityEvent.mjs";
|
|
7
|
+
import { useImpressionRef } from "./hooks/useImpressionRef/useImpressionRef.mjs";
|
|
8
|
+
import { mergeRefs } from "./utils/mergeRefs/mergeRefs.mjs";
|
|
9
|
+
import { ImpressionArea } from "./components/ImpressionArea/ImpressionArea.mjs";
|
|
10
|
+
import { Separated } from "./components/Separated/Separated.mjs";
|
|
11
|
+
import { SwitchCase } from "./components/SwitchCase/SwitchCase.mjs";
|
|
12
|
+
import { useAsyncEffect } from "./hooks/useAsyncEffect/useAsyncEffect.mjs";
|
|
13
|
+
import { useBooleanState } from "./hooks/useBooleanState/useBooleanState.mjs";
|
|
14
|
+
import { useCallbackOncePerRender } from "./hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs";
|
|
15
|
+
import { useConditionalEffect } from "./hooks/useConditionalEffect/useConditionalEffect.mjs";
|
|
16
|
+
import { useControlledState } from "./hooks/useControlledState/useControlledState.mjs";
|
|
17
|
+
import { useCounter } from "./hooks/useCounter/useCounter.mjs";
|
|
18
|
+
import { useDebounce } from "./hooks/useDebounce/useDebounce.mjs";
|
|
19
|
+
import { useDoubleClick } from "./hooks/useDoubleClick/useDoubleClick.mjs";
|
|
20
|
+
import { useGeolocation } from "./hooks/useGeolocation/useGeolocation.mjs";
|
|
21
|
+
import { useInputState } from "./hooks/useInputState/useInputState.mjs";
|
|
22
|
+
import { useInterval } from "./hooks/useInterval/useInterval.mjs";
|
|
23
|
+
import { useIsClient } from "./hooks/useIsClient/useIsClient.mjs";
|
|
24
|
+
import { useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
25
|
+
import { usePreservedReference } from "./hooks/usePreservedReference/usePreservedReference.mjs";
|
|
26
|
+
import { useList } from "./hooks/useList/useList.mjs";
|
|
27
|
+
import { useLoading } from "./hooks/useLoading/useLoading.mjs";
|
|
28
|
+
import { useLongPress } from "./hooks/useLongPress/useLongPress.mjs";
|
|
29
|
+
import { useMap } from "./hooks/useMap/useMap.mjs";
|
|
30
|
+
import { useOutsideClickEffect } from "./hooks/useOutsideClickEffect/useOutsideClickEffect.mjs";
|
|
31
|
+
import { usePrevious } from "./hooks/usePrevious/usePrevious.mjs";
|
|
32
|
+
import { useSet } from "./hooks/useSet/useSet.mjs";
|
|
33
|
+
import { useStorageState } from "./hooks/useStorageState/useStorageState.mjs";
|
|
34
|
+
import { useThrottle } from "./hooks/useThrottle/useThrottle.mjs";
|
|
35
|
+
import { useThrottledCallback } from "./hooks/useThrottledCallback/useThrottledCallback.mjs";
|
|
36
|
+
import { useTimeout } from "./hooks/useTimeout/useTimeout.mjs";
|
|
37
|
+
import { useToggle } from "./hooks/useToggle/useToggle.mjs";
|
|
38
|
+
import { buildContext } from "./utils/buildContext/buildContext.mjs";
|
|
39
|
+
import { mergeProps } from "./utils/mergeProps/mergeProps.mjs";
|
|
40
|
+
export { ImpressionArea, Separated, SwitchCase, buildContext, mergeProps, mergeRefs, useAsyncEffect, useBooleanState, useCallbackOncePerRender, useConditionalEffect, useControlledState, useCounter, useDebounce, useDebouncedCallback, useDoubleClick, useGeolocation, useImpressionRef, useInputState, useIntersectionObserver, useInterval, useIsClient, useIsomorphicLayoutEffect, useList, useLoading, useLongPress, useMap, useOutsideClickEffect, usePreservedCallback, usePreservedReference, usePrevious, useRefEffect, useSet, useStorageState, useThrottle, useThrottledCallback, useTimeout, useToggle, useVisibilityEvent };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
//#region src/utils/buildContext/buildContext.tsx
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} contextName - The name of the context.
|
|
10
|
+
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
11
|
+
*
|
|
12
|
+
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
13
|
+
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
14
|
+
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
18
|
+
*
|
|
19
|
+
* function Inner() {
|
|
20
|
+
* const { title } = useContext();
|
|
21
|
+
* return <div>{title}</div>;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* function Page() {
|
|
25
|
+
* return (
|
|
26
|
+
* <Provider title="Hello">
|
|
27
|
+
* <Inner />
|
|
28
|
+
* </Provider>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
function buildContext(contextName, defaultContextValues) {
|
|
33
|
+
const Context = (0, react.createContext)(defaultContextValues ?? void 0);
|
|
34
|
+
function Provider({ children, ...contextValues }) {
|
|
35
|
+
const value = (0, react.useMemo)(() => Object.keys(contextValues).length > 0 ? contextValues : null, [...Object.values(contextValues)]);
|
|
36
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Context.Provider, {
|
|
37
|
+
value,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useInnerContext() {
|
|
42
|
+
const context = (0, react.useContext)(Context);
|
|
43
|
+
if (context != null) return context;
|
|
44
|
+
if (defaultContextValues != null) return defaultContextValues;
|
|
45
|
+
throw new Error(`\`${contextName}Context\` must be used within \`${contextName}Provider\``);
|
|
46
|
+
}
|
|
47
|
+
return [Provider, useInnerContext];
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.buildContext = buildContext;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
1
|
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/utils/buildContext/buildContext.d.ts
|
|
4
4
|
type ProviderProps<ContextValuesType> = (ContextValuesType & {
|
|
5
|
-
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
}) | {
|
|
7
|
-
|
|
7
|
+
children: ReactNode;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* @description
|
|
@@ -33,6 +33,6 @@ type ProviderProps<ContextValuesType> = (ContextValuesType & {
|
|
|
33
33
|
* );
|
|
34
34
|
* }
|
|
35
35
|
*/
|
|
36
|
-
declare function buildContext<ContextValuesType extends object>(contextName: string, defaultContextValues?: ContextValuesType): readonly [({ children, ...contextValues }: ProviderProps<ContextValuesType>) =>
|
|
37
|
-
|
|
38
|
-
export { buildContext };
|
|
36
|
+
declare function buildContext<ContextValuesType extends object>(contextName: string, defaultContextValues?: ContextValuesType): readonly [({ children, ...contextValues }: ProviderProps<ContextValuesType>) => import("react/jsx-runtime").JSX.Element, () => ContextValuesType];
|
|
37
|
+
//#endregion
|
|
38
|
+
export { buildContext };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/utils/buildContext/buildContext.d.ts
|
|
4
|
+
type ProviderProps<ContextValuesType> = (ContextValuesType & {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}) | {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} contextName - The name of the context.
|
|
14
|
+
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
15
|
+
*
|
|
16
|
+
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
17
|
+
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
18
|
+
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
22
|
+
*
|
|
23
|
+
* function Inner() {
|
|
24
|
+
* const { title } = useContext();
|
|
25
|
+
* return <div>{title}</div>;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* function Page() {
|
|
29
|
+
* return (
|
|
30
|
+
* <Provider title="Hello">
|
|
31
|
+
* <Inner />
|
|
32
|
+
* </Provider>
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
*/
|
|
36
|
+
declare function buildContext<ContextValuesType extends object>(contextName: string, defaultContextValues?: ContextValuesType): readonly [({ children, ...contextValues }: ProviderProps<ContextValuesType>) => import("react/jsx-runtime").JSX.Element, () => ContextValuesType];
|
|
37
|
+
//#endregion
|
|
38
|
+
export { buildContext };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useMemo } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/utils/buildContext/buildContext.tsx
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} contextName - The name of the context.
|
|
10
|
+
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
11
|
+
*
|
|
12
|
+
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
13
|
+
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
14
|
+
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
18
|
+
*
|
|
19
|
+
* function Inner() {
|
|
20
|
+
* const { title } = useContext();
|
|
21
|
+
* return <div>{title}</div>;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* function Page() {
|
|
25
|
+
* return (
|
|
26
|
+
* <Provider title="Hello">
|
|
27
|
+
* <Inner />
|
|
28
|
+
* </Provider>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
function buildContext(contextName, defaultContextValues) {
|
|
33
|
+
const Context = createContext(defaultContextValues ?? void 0);
|
|
34
|
+
function Provider({ children, ...contextValues }) {
|
|
35
|
+
const value = useMemo(() => Object.keys(contextValues).length > 0 ? contextValues : null, [...Object.values(contextValues)]);
|
|
36
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
37
|
+
value,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useInnerContext() {
|
|
42
|
+
const context = useContext(Context);
|
|
43
|
+
if (context != null) return context;
|
|
44
|
+
if (defaultContextValues != null) return defaultContextValues;
|
|
45
|
+
throw new Error(`\`${contextName}Context\` must be used within \`${contextName}Provider\``);
|
|
46
|
+
}
|
|
47
|
+
return [Provider, useInnerContext];
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { buildContext };
|
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
1
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}) | {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @description
|
|
11
|
-
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
12
|
-
*
|
|
13
|
-
* @param {string} contextName - The name of the context.
|
|
14
|
-
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
15
|
-
*
|
|
16
|
-
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
17
|
-
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
18
|
-
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
22
|
-
*
|
|
23
|
-
* function Inner() {
|
|
24
|
-
* const { title } = useContext();
|
|
25
|
-
* return <div>{title}</div>;
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* function Page() {
|
|
29
|
-
* return (
|
|
30
|
-
* <Provider title="Hello">
|
|
31
|
-
* <Inner />
|
|
32
|
-
* </Provider>
|
|
33
|
-
* );
|
|
34
|
-
* }
|
|
35
|
-
*/
|
|
36
|
-
declare function buildContext<ContextValuesType extends object>(contextName: string, defaultContextValues?: ContextValuesType): readonly [({ children, ...contextValues }: ProviderProps<ContextValuesType>) => react_jsx_runtime.JSX.Element, () => ContextValuesType];
|
|
37
|
-
|
|
38
|
-
export { buildContext };
|
|
2
|
+
import { buildContext } from "./buildContext.cjs";
|
|
3
|
+
export { buildContext };
|
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
};
|
|
7
|
-
type TupleToIntersection<T extends Record<string, unknown>[]> = {
|
|
8
|
-
[I in keyof T]: (x: T[I]) => void;
|
|
9
|
-
}[number] extends (x: infer I) => void ? I : never;
|
|
10
|
-
/**
|
|
11
|
-
* @description
|
|
12
|
-
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
13
|
-
* It handles merging of `className`, `style`, and `function` properties.
|
|
14
|
-
*
|
|
15
|
-
* @template PropsList - The type of the props objects to merge.
|
|
16
|
-
*
|
|
17
|
-
* @param {PropsList} props - The props objects to merge.
|
|
18
|
-
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
22
|
-
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
23
|
-
*/
|
|
24
|
-
declare function mergeProps<PropsList extends BaseProps[]>(...props: PropsList): TupleToIntersection<PropsList>;
|
|
25
|
-
|
|
26
|
-
export { mergeProps };
|
|
2
|
+
import { mergeProps } from "./mergeProps.cjs";
|
|
3
|
+
export { mergeProps };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/utils/mergeProps/mergeProps.ts
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
6
|
+
* It handles merging of `className`, `style`, and `function` properties.
|
|
7
|
+
*
|
|
8
|
+
* @template PropsList - The type of the props objects to merge.
|
|
9
|
+
*
|
|
10
|
+
* @param {PropsList} props - The props objects to merge.
|
|
11
|
+
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
15
|
+
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
16
|
+
*/
|
|
17
|
+
function mergeProps(...props) {
|
|
18
|
+
return props.reduce(pushProp, {});
|
|
19
|
+
}
|
|
20
|
+
function pushProp(prev, curr) {
|
|
21
|
+
for (const key in curr) {
|
|
22
|
+
if (curr[key] === void 0) continue;
|
|
23
|
+
switch (key) {
|
|
24
|
+
case "className":
|
|
25
|
+
prev[key] = [prev[key], curr[key]].join(" ").trim();
|
|
26
|
+
break;
|
|
27
|
+
case "style":
|
|
28
|
+
prev[key] = mergeStyle(prev[key], curr[key]);
|
|
29
|
+
break;
|
|
30
|
+
default: {
|
|
31
|
+
const mergedFunction = mergeFunction(prev[key], curr[key]);
|
|
32
|
+
if (mergedFunction) prev[key] = mergedFunction;
|
|
33
|
+
else if (curr[key] !== void 0) prev[key] = curr[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return prev;
|
|
38
|
+
}
|
|
39
|
+
function mergeStyle(a, b) {
|
|
40
|
+
if (a == null) return b;
|
|
41
|
+
return {
|
|
42
|
+
...a,
|
|
43
|
+
...b
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function mergeFunction(a, b) {
|
|
47
|
+
if (typeof a === "function" && typeof b === "function") return (...args) => {
|
|
48
|
+
a(...args);
|
|
49
|
+
b(...args);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.mergeProps = mergeProps;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
2
1
|
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
//#region src/utils/mergeProps/mergeProps.d.ts
|
|
3
4
|
type BaseProps = {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
[key: string]: unknown;
|
|
6
7
|
};
|
|
7
|
-
type TupleToIntersection<T extends Record<string, unknown>[]> = {
|
|
8
|
-
[I in keyof T]: (x: T[I]) => void;
|
|
9
|
-
}[number] extends (x: infer I) => void ? I : never;
|
|
8
|
+
type TupleToIntersection<T extends Record<string, unknown>[]> = { [I in keyof T]: (x: T[I]) => void; }[number] extends ((x: infer I) => void) ? I : never;
|
|
10
9
|
/**
|
|
11
10
|
* @description
|
|
12
11
|
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
@@ -22,5 +21,5 @@ type TupleToIntersection<T extends Record<string, unknown>[]> = {
|
|
|
22
21
|
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
23
22
|
*/
|
|
24
23
|
declare function mergeProps<PropsList extends BaseProps[]>(...props: PropsList): TupleToIntersection<PropsList>;
|
|
25
|
-
|
|
26
|
-
export { mergeProps };
|
|
24
|
+
//#endregion
|
|
25
|
+
export { mergeProps };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
//#region src/utils/mergeProps/mergeProps.d.ts
|
|
4
|
+
type BaseProps = {
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type TupleToIntersection<T extends Record<string, unknown>[]> = { [I in keyof T]: (x: T[I]) => void; }[number] extends ((x: infer I) => void) ? I : never;
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
12
|
+
* It handles merging of `className`, `style`, and `function` properties.
|
|
13
|
+
*
|
|
14
|
+
* @template PropsList - The type of the props objects to merge.
|
|
15
|
+
*
|
|
16
|
+
* @param {PropsList} props - The props objects to merge.
|
|
17
|
+
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
21
|
+
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
22
|
+
*/
|
|
23
|
+
declare function mergeProps<PropsList extends BaseProps[]>(...props: PropsList): TupleToIntersection<PropsList>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { mergeProps };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/utils/mergeProps/mergeProps.ts
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
6
|
+
* It handles merging of `className`, `style`, and `function` properties.
|
|
7
|
+
*
|
|
8
|
+
* @template PropsList - The type of the props objects to merge.
|
|
9
|
+
*
|
|
10
|
+
* @param {PropsList} props - The props objects to merge.
|
|
11
|
+
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
15
|
+
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
16
|
+
*/
|
|
17
|
+
function mergeProps(...props) {
|
|
18
|
+
return props.reduce(pushProp, {});
|
|
19
|
+
}
|
|
20
|
+
function pushProp(prev, curr) {
|
|
21
|
+
for (const key in curr) {
|
|
22
|
+
if (curr[key] === void 0) continue;
|
|
23
|
+
switch (key) {
|
|
24
|
+
case "className":
|
|
25
|
+
prev[key] = [prev[key], curr[key]].join(" ").trim();
|
|
26
|
+
break;
|
|
27
|
+
case "style":
|
|
28
|
+
prev[key] = mergeStyle(prev[key], curr[key]);
|
|
29
|
+
break;
|
|
30
|
+
default: {
|
|
31
|
+
const mergedFunction = mergeFunction(prev[key], curr[key]);
|
|
32
|
+
if (mergedFunction) prev[key] = mergedFunction;
|
|
33
|
+
else if (curr[key] !== void 0) prev[key] = curr[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return prev;
|
|
38
|
+
}
|
|
39
|
+
function mergeStyle(a, b) {
|
|
40
|
+
if (a == null) return b;
|
|
41
|
+
return {
|
|
42
|
+
...a,
|
|
43
|
+
...b
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function mergeFunction(a, b) {
|
|
47
|
+
if (typeof a === "function" && typeof b === "function") return (...args) => {
|
|
48
|
+
a(...args);
|
|
49
|
+
b(...args);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { mergeProps };
|