@alessiofrittoli/react-hooks 3.2.0-alpha.2 → 3.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/README.md +1249 -1223
- package/dist/index.d.mts +177 -31
- package/dist/index.d.ts +177 -31
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/license.md +20 -20
- package/package.json +134 -133
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import * as _alessiofrittoli_math_utils_helpers from '@alessiofrittoli/math-utils/helpers';
|
|
3
|
+
import { PaginateOptions } from '@alessiofrittoli/math-utils/helpers';
|
|
2
4
|
|
|
3
5
|
type Value<T> = T | undefined | null;
|
|
4
6
|
type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
|
|
@@ -27,6 +29,32 @@ declare const useLocalStorage: <T = string>(key: string, initial?: T) => [T | nu
|
|
|
27
29
|
*/
|
|
28
30
|
declare const useSessionStorage: <T = string>(key: string, initial?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
|
|
29
31
|
|
|
32
|
+
type Connection = 'online' | 'offline';
|
|
33
|
+
declare const getState: (online: boolean) => "online" | "offline";
|
|
34
|
+
interface UseConnectionReturnType {
|
|
35
|
+
/**
|
|
36
|
+
* Indicates the connections status.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
connection: Connection;
|
|
40
|
+
/**
|
|
41
|
+
* Indicates whether the current device is online.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
isOnline: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Indicates whether the current device is offline.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
isOffline: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get states about Internet Connection.
|
|
53
|
+
*
|
|
54
|
+
* @returns An object defining Internet Connection status. See {@link UseConnectionReturnType} for more info.
|
|
55
|
+
*/
|
|
56
|
+
declare const useConnection: () => UseConnectionReturnType;
|
|
57
|
+
|
|
30
58
|
interface UseDarkModeOutput {
|
|
31
59
|
/**
|
|
32
60
|
* Indicates whether dark mode is enabled.
|
|
@@ -736,36 +764,6 @@ declare const useInView: (target: React.RefObject<Element | null>, options?: Use
|
|
|
736
764
|
*/
|
|
737
765
|
declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
|
|
738
766
|
|
|
739
|
-
/**
|
|
740
|
-
* Modified version of `useEffect` that only run once on intial load.
|
|
741
|
-
*
|
|
742
|
-
* @param effect Imperative function that can return a cleanup function.
|
|
743
|
-
*/
|
|
744
|
-
declare const useEffectOnce: (effect: React.EffectCallback) => void;
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* Check if the React Hook or Component where this hook is executed is running in a browser environment.
|
|
748
|
-
*
|
|
749
|
-
* @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
|
|
750
|
-
*/
|
|
751
|
-
declare const useIsClient: () => boolean;
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Check if is first React Hook/Component render.
|
|
755
|
-
*
|
|
756
|
-
* @returns `true` at the mount time, then always `false`.
|
|
757
|
-
* - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
|
|
758
|
-
*/
|
|
759
|
-
declare const useIsFirstRender: () => boolean;
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Modified version of `useEffect` that skips the first render.
|
|
763
|
-
*
|
|
764
|
-
* @param effect Imperative function that can return a cleanup function.
|
|
765
|
-
* @param deps If present, effect will only activate if the values in the list change.
|
|
766
|
-
*/
|
|
767
|
-
declare const useUpdateEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
768
|
-
|
|
769
767
|
type InputType = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null;
|
|
770
768
|
interface InputState<I = unknown, O = I> {
|
|
771
769
|
/**
|
|
@@ -900,6 +898,154 @@ interface UseInputOutput<I = unknown, O = I> extends InputState<I, O> {
|
|
|
900
898
|
*/
|
|
901
899
|
declare const useInput: <I = unknown, O = I>(options?: UseInputOptions<I, O>) => UseInputOutput<I, O>;
|
|
902
900
|
|
|
901
|
+
/**
|
|
902
|
+
* Modified version of `useEffect` that only run once on intial load.
|
|
903
|
+
*
|
|
904
|
+
* @param effect Imperative function that can return a cleanup function.
|
|
905
|
+
*/
|
|
906
|
+
declare const useEffectOnce: (effect: React.EffectCallback) => void;
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Check if the React Hook or Component where this hook is executed is running in a browser environment.
|
|
910
|
+
*
|
|
911
|
+
* @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
|
|
912
|
+
*/
|
|
913
|
+
declare const useIsClient: () => boolean;
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Check if is first React Hook/Component render.
|
|
917
|
+
*
|
|
918
|
+
* @returns `true` at the mount time, then always `false`.
|
|
919
|
+
* - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
|
|
920
|
+
*/
|
|
921
|
+
declare const useIsFirstRender: () => boolean;
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Get pagination informations based on the given options.
|
|
925
|
+
*
|
|
926
|
+
* @param options An object defining pagination input data. See {@link PaginateOptions} for more information.
|
|
927
|
+
* @returns A memoized object containing pagination informations based on the given options.
|
|
928
|
+
*/
|
|
929
|
+
declare const usePagination: (options?: PaginateOptions) => _alessiofrittoli_math_utils_helpers.Pagination;
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Check if the given `entry` is in the selection.
|
|
933
|
+
*
|
|
934
|
+
* @template V The `entry` type.
|
|
935
|
+
*
|
|
936
|
+
* @param value The `entry` to check.
|
|
937
|
+
*/
|
|
938
|
+
type IsSelectedHandler<V> = (entry: V) => void;
|
|
939
|
+
/**
|
|
940
|
+
* A React Dispatch SetStateAction that allows custom selection update.
|
|
941
|
+
*
|
|
942
|
+
* @template V The `entry` type.
|
|
943
|
+
*/
|
|
944
|
+
type SetSelectionHandler<V> = React.Dispatch<React.SetStateAction<V[]>>;
|
|
945
|
+
/**
|
|
946
|
+
* Update selection by adding a new `entry` or removing the given `entry` if already exists in the selection.
|
|
947
|
+
*
|
|
948
|
+
* @template V The `entry` type.
|
|
949
|
+
*
|
|
950
|
+
* @param entry The entry to add/remove from selection.
|
|
951
|
+
*/
|
|
952
|
+
type SelectHandler<V> = (entry: V) => void;
|
|
953
|
+
/**
|
|
954
|
+
* Select all items from the given `array` starting from the first item in the selection up to the given `entry`.
|
|
955
|
+
*
|
|
956
|
+
* @template V The `entry` type.
|
|
957
|
+
*
|
|
958
|
+
* @param entry The final entry the selection will be updated to.
|
|
959
|
+
*/
|
|
960
|
+
type GroupSelectHandler<V> = (entry: V) => void;
|
|
961
|
+
/**
|
|
962
|
+
* Add all entries from the given `array` to the selection.
|
|
963
|
+
*
|
|
964
|
+
*/
|
|
965
|
+
type SelectAllHandler = () => void;
|
|
966
|
+
/**
|
|
967
|
+
* Removes all entries from the selection.
|
|
968
|
+
*
|
|
969
|
+
* @param initial If set to `true` will reset selection to the `initial` given value. Will empty the selection otherwise.
|
|
970
|
+
*/
|
|
971
|
+
type ResetSelectionHandler = (initial?: boolean) => void;
|
|
972
|
+
interface UseSelectionReturnType<V> {
|
|
973
|
+
/**
|
|
974
|
+
* The current selected items.
|
|
975
|
+
*
|
|
976
|
+
*/
|
|
977
|
+
selection: V[];
|
|
978
|
+
/**
|
|
979
|
+
* Indicates whether `selection` is not empty. Short-hand for `selection.length > 0`.
|
|
980
|
+
*
|
|
981
|
+
*/
|
|
982
|
+
hasSelection: boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Check if the given `entry` is in the selection.
|
|
985
|
+
*
|
|
986
|
+
* @template V The `entry` type.
|
|
987
|
+
*
|
|
988
|
+
* @param value The `entry` to check.
|
|
989
|
+
*/
|
|
990
|
+
isSelected: IsSelectedHandler<V>;
|
|
991
|
+
/**
|
|
992
|
+
* A React Dispatch SetStateAction that allows custom selection update.
|
|
993
|
+
*
|
|
994
|
+
* @template V The `entry` type.
|
|
995
|
+
*
|
|
996
|
+
* @param value The React.SetStateAction<V[]> value.
|
|
997
|
+
*/
|
|
998
|
+
setSelection: SetSelectionHandler<V>;
|
|
999
|
+
/**
|
|
1000
|
+
* Update selection by adding a new `entry` or removing the given `entry` if already exists in the selection.
|
|
1001
|
+
*
|
|
1002
|
+
* @template V The `entry` type.
|
|
1003
|
+
*
|
|
1004
|
+
* @param entry The entry to add/remove from selection.
|
|
1005
|
+
*/
|
|
1006
|
+
select: SelectHandler<V>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Select all items from the given `array` starting from the first item in the selection up to the given `entry`.
|
|
1009
|
+
*
|
|
1010
|
+
* @template V The `entry` type.
|
|
1011
|
+
*
|
|
1012
|
+
* @param entry The final entry the selection will be updated to.
|
|
1013
|
+
*/
|
|
1014
|
+
groupSelect: GroupSelectHandler<V>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Add all entries from the given `array` to the selection.
|
|
1017
|
+
*
|
|
1018
|
+
*/
|
|
1019
|
+
selectAll: SelectAllHandler;
|
|
1020
|
+
/**
|
|
1021
|
+
* Removes all entries from the selection.
|
|
1022
|
+
*
|
|
1023
|
+
* @param initial If set to `true` will reset selection to the `initial` given value. Will empty the selection otherwise.
|
|
1024
|
+
*/
|
|
1025
|
+
resetSelection: ResetSelectionHandler;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* A React hook for managing selection states in an array.
|
|
1029
|
+
*
|
|
1030
|
+
* Provides functionality for single and group selection, as well as resetting the selection.
|
|
1031
|
+
*
|
|
1032
|
+
* @template V The type of the values in the `array` (defaults to the value type of `T`).
|
|
1033
|
+
*
|
|
1034
|
+
* @param array The array of items to manage selection for.
|
|
1035
|
+
* @param initial The initial selection state (defaults to an empty array).
|
|
1036
|
+
*
|
|
1037
|
+
* @returns An object containing the selection state and handlers. See {@link UseSelectionReturnType} for more info.
|
|
1038
|
+
*/
|
|
1039
|
+
declare const useSelection: <V>(array: V[], initial?: V[]) => UseSelectionReturnType<V>;
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Modified version of `useEffect` that skips the first render.
|
|
1043
|
+
*
|
|
1044
|
+
* @param effect Imperative function that can return a cleanup function.
|
|
1045
|
+
* @param deps If present, effect will only activate if the values in the list change.
|
|
1046
|
+
*/
|
|
1047
|
+
declare const useUpdateEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
1048
|
+
|
|
903
1049
|
/**
|
|
904
1050
|
* The function called when the timer elapses.
|
|
905
1051
|
*
|
|
@@ -1188,4 +1334,4 @@ declare function useTimeout<T extends readonly unknown[]>(callback: TimerHandler
|
|
|
1188
1334
|
*/
|
|
1189
1335
|
declare const useLightTimeout: <T extends readonly unknown[]>(callback: TimerHandler<T>, options?: BasicTimerOptions<T>) => void;
|
|
1190
1336
|
|
|
1191
|
-
export { type AddEventListenerOptions, type BasicTimerOptions, type ChangeHandler, type CommonListenerOptions, type CustomEventListenerOptions, type DocumentEventListener, type DocumentListenerOptions, type ElementEventListener, type ElementListenerOptions, type InputState, type InputType, type IntersectionState, type ListenerOptions, type MarginType, type MarginValue, type MediaQueryChangeListener, type MediaQueryEventListener, type MediaQueryListenerOptions, type OnChangeHandler, type OnIntersectHandler, type OnIntersectStateHandler, type ParseValueHandler, type StartTimer, type StateTimerOptions, type StateTimerReturnType, type StopTimer, type TimerHandler, type TimerId, type TimerOptions, type TimerReturnType, type UseDarkModeOptions, type UseDarkModeOutput, type UseInViewOptions, type UseInViewReturnType, type UseInputOptions, type UseInputOutput, type UseIntervalWhenVisibleReturnType, type UseIntervalWhenVisibleStateReturnType, type UseMediaQueryOptions, type UseMediaQueryStateOptions, type ValidateValueHandler, type WindowEventListener, type WindowListenerOptions, useDarkMode, useDebounce, useEffectOnce, useEventListener, useFocusTrap, useInView, useInput, useInterval, useIntervalWhenVisible, useIsClient, useIsFirstRender, useIsPortrait, useLightInterval, useLightTimeout, useLocalStorage, useMediaQuery, useScrollBlock, useSessionStorage, useStorage, useTimeout, useUpdateEffect };
|
|
1337
|
+
export { type AddEventListenerOptions, type BasicTimerOptions, type ChangeHandler, type CommonListenerOptions, type Connection, type CustomEventListenerOptions, type DocumentEventListener, type DocumentListenerOptions, type ElementEventListener, type ElementListenerOptions, type GroupSelectHandler, type InputState, type InputType, type IntersectionState, type IsSelectedHandler, type ListenerOptions, type MarginType, type MarginValue, type MediaQueryChangeListener, type MediaQueryEventListener, type MediaQueryListenerOptions, type OnChangeHandler, type OnIntersectHandler, type OnIntersectStateHandler, type ParseValueHandler, type ResetSelectionHandler, type SelectAllHandler, type SelectHandler, type SetSelectionHandler, type StartTimer, type StateTimerOptions, type StateTimerReturnType, type StopTimer, type TimerHandler, type TimerId, type TimerOptions, type TimerReturnType, type UseConnectionReturnType, type UseDarkModeOptions, type UseDarkModeOutput, type UseInViewOptions, type UseInViewReturnType, type UseInputOptions, type UseInputOutput, type UseIntervalWhenVisibleReturnType, type UseIntervalWhenVisibleStateReturnType, type UseMediaQueryOptions, type UseMediaQueryStateOptions, type UseSelectionReturnType, type ValidateValueHandler, type WindowEventListener, type WindowListenerOptions, getState, useConnection, useDarkMode, useDebounce, useEffectOnce, useEventListener, useFocusTrap, useInView, useInput, useInterval, useIntervalWhenVisible, useIsClient, useIsFirstRender, useIsPortrait, useLightInterval, useLightTimeout, useLocalStorage, useMediaQuery, usePagination, useScrollBlock, useSelection, useSessionStorage, useStorage, useTimeout, useUpdateEffect };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import * as _alessiofrittoli_math_utils_helpers from '@alessiofrittoli/math-utils/helpers';
|
|
3
|
+
import { PaginateOptions } from '@alessiofrittoli/math-utils/helpers';
|
|
2
4
|
|
|
3
5
|
type Value<T> = T | undefined | null;
|
|
4
6
|
type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
|
|
@@ -27,6 +29,32 @@ declare const useLocalStorage: <T = string>(key: string, initial?: T) => [T | nu
|
|
|
27
29
|
*/
|
|
28
30
|
declare const useSessionStorage: <T = string>(key: string, initial?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
|
|
29
31
|
|
|
32
|
+
type Connection = 'online' | 'offline';
|
|
33
|
+
declare const getState: (online: boolean) => "online" | "offline";
|
|
34
|
+
interface UseConnectionReturnType {
|
|
35
|
+
/**
|
|
36
|
+
* Indicates the connections status.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
connection: Connection;
|
|
40
|
+
/**
|
|
41
|
+
* Indicates whether the current device is online.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
isOnline: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Indicates whether the current device is offline.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
isOffline: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get states about Internet Connection.
|
|
53
|
+
*
|
|
54
|
+
* @returns An object defining Internet Connection status. See {@link UseConnectionReturnType} for more info.
|
|
55
|
+
*/
|
|
56
|
+
declare const useConnection: () => UseConnectionReturnType;
|
|
57
|
+
|
|
30
58
|
interface UseDarkModeOutput {
|
|
31
59
|
/**
|
|
32
60
|
* Indicates whether dark mode is enabled.
|
|
@@ -736,36 +764,6 @@ declare const useInView: (target: React.RefObject<Element | null>, options?: Use
|
|
|
736
764
|
*/
|
|
737
765
|
declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
|
|
738
766
|
|
|
739
|
-
/**
|
|
740
|
-
* Modified version of `useEffect` that only run once on intial load.
|
|
741
|
-
*
|
|
742
|
-
* @param effect Imperative function that can return a cleanup function.
|
|
743
|
-
*/
|
|
744
|
-
declare const useEffectOnce: (effect: React.EffectCallback) => void;
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* Check if the React Hook or Component where this hook is executed is running in a browser environment.
|
|
748
|
-
*
|
|
749
|
-
* @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
|
|
750
|
-
*/
|
|
751
|
-
declare const useIsClient: () => boolean;
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Check if is first React Hook/Component render.
|
|
755
|
-
*
|
|
756
|
-
* @returns `true` at the mount time, then always `false`.
|
|
757
|
-
* - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
|
|
758
|
-
*/
|
|
759
|
-
declare const useIsFirstRender: () => boolean;
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Modified version of `useEffect` that skips the first render.
|
|
763
|
-
*
|
|
764
|
-
* @param effect Imperative function that can return a cleanup function.
|
|
765
|
-
* @param deps If present, effect will only activate if the values in the list change.
|
|
766
|
-
*/
|
|
767
|
-
declare const useUpdateEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
768
|
-
|
|
769
767
|
type InputType = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null;
|
|
770
768
|
interface InputState<I = unknown, O = I> {
|
|
771
769
|
/**
|
|
@@ -900,6 +898,154 @@ interface UseInputOutput<I = unknown, O = I> extends InputState<I, O> {
|
|
|
900
898
|
*/
|
|
901
899
|
declare const useInput: <I = unknown, O = I>(options?: UseInputOptions<I, O>) => UseInputOutput<I, O>;
|
|
902
900
|
|
|
901
|
+
/**
|
|
902
|
+
* Modified version of `useEffect` that only run once on intial load.
|
|
903
|
+
*
|
|
904
|
+
* @param effect Imperative function that can return a cleanup function.
|
|
905
|
+
*/
|
|
906
|
+
declare const useEffectOnce: (effect: React.EffectCallback) => void;
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Check if the React Hook or Component where this hook is executed is running in a browser environment.
|
|
910
|
+
*
|
|
911
|
+
* @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
|
|
912
|
+
*/
|
|
913
|
+
declare const useIsClient: () => boolean;
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Check if is first React Hook/Component render.
|
|
917
|
+
*
|
|
918
|
+
* @returns `true` at the mount time, then always `false`.
|
|
919
|
+
* - Note that if the React Hook/Component has no state updates, `useIsFirstRender` will always return `true`.
|
|
920
|
+
*/
|
|
921
|
+
declare const useIsFirstRender: () => boolean;
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Get pagination informations based on the given options.
|
|
925
|
+
*
|
|
926
|
+
* @param options An object defining pagination input data. See {@link PaginateOptions} for more information.
|
|
927
|
+
* @returns A memoized object containing pagination informations based on the given options.
|
|
928
|
+
*/
|
|
929
|
+
declare const usePagination: (options?: PaginateOptions) => _alessiofrittoli_math_utils_helpers.Pagination;
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Check if the given `entry` is in the selection.
|
|
933
|
+
*
|
|
934
|
+
* @template V The `entry` type.
|
|
935
|
+
*
|
|
936
|
+
* @param value The `entry` to check.
|
|
937
|
+
*/
|
|
938
|
+
type IsSelectedHandler<V> = (entry: V) => void;
|
|
939
|
+
/**
|
|
940
|
+
* A React Dispatch SetStateAction that allows custom selection update.
|
|
941
|
+
*
|
|
942
|
+
* @template V The `entry` type.
|
|
943
|
+
*/
|
|
944
|
+
type SetSelectionHandler<V> = React.Dispatch<React.SetStateAction<V[]>>;
|
|
945
|
+
/**
|
|
946
|
+
* Update selection by adding a new `entry` or removing the given `entry` if already exists in the selection.
|
|
947
|
+
*
|
|
948
|
+
* @template V The `entry` type.
|
|
949
|
+
*
|
|
950
|
+
* @param entry The entry to add/remove from selection.
|
|
951
|
+
*/
|
|
952
|
+
type SelectHandler<V> = (entry: V) => void;
|
|
953
|
+
/**
|
|
954
|
+
* Select all items from the given `array` starting from the first item in the selection up to the given `entry`.
|
|
955
|
+
*
|
|
956
|
+
* @template V The `entry` type.
|
|
957
|
+
*
|
|
958
|
+
* @param entry The final entry the selection will be updated to.
|
|
959
|
+
*/
|
|
960
|
+
type GroupSelectHandler<V> = (entry: V) => void;
|
|
961
|
+
/**
|
|
962
|
+
* Add all entries from the given `array` to the selection.
|
|
963
|
+
*
|
|
964
|
+
*/
|
|
965
|
+
type SelectAllHandler = () => void;
|
|
966
|
+
/**
|
|
967
|
+
* Removes all entries from the selection.
|
|
968
|
+
*
|
|
969
|
+
* @param initial If set to `true` will reset selection to the `initial` given value. Will empty the selection otherwise.
|
|
970
|
+
*/
|
|
971
|
+
type ResetSelectionHandler = (initial?: boolean) => void;
|
|
972
|
+
interface UseSelectionReturnType<V> {
|
|
973
|
+
/**
|
|
974
|
+
* The current selected items.
|
|
975
|
+
*
|
|
976
|
+
*/
|
|
977
|
+
selection: V[];
|
|
978
|
+
/**
|
|
979
|
+
* Indicates whether `selection` is not empty. Short-hand for `selection.length > 0`.
|
|
980
|
+
*
|
|
981
|
+
*/
|
|
982
|
+
hasSelection: boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Check if the given `entry` is in the selection.
|
|
985
|
+
*
|
|
986
|
+
* @template V The `entry` type.
|
|
987
|
+
*
|
|
988
|
+
* @param value The `entry` to check.
|
|
989
|
+
*/
|
|
990
|
+
isSelected: IsSelectedHandler<V>;
|
|
991
|
+
/**
|
|
992
|
+
* A React Dispatch SetStateAction that allows custom selection update.
|
|
993
|
+
*
|
|
994
|
+
* @template V The `entry` type.
|
|
995
|
+
*
|
|
996
|
+
* @param value The React.SetStateAction<V[]> value.
|
|
997
|
+
*/
|
|
998
|
+
setSelection: SetSelectionHandler<V>;
|
|
999
|
+
/**
|
|
1000
|
+
* Update selection by adding a new `entry` or removing the given `entry` if already exists in the selection.
|
|
1001
|
+
*
|
|
1002
|
+
* @template V The `entry` type.
|
|
1003
|
+
*
|
|
1004
|
+
* @param entry The entry to add/remove from selection.
|
|
1005
|
+
*/
|
|
1006
|
+
select: SelectHandler<V>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Select all items from the given `array` starting from the first item in the selection up to the given `entry`.
|
|
1009
|
+
*
|
|
1010
|
+
* @template V The `entry` type.
|
|
1011
|
+
*
|
|
1012
|
+
* @param entry The final entry the selection will be updated to.
|
|
1013
|
+
*/
|
|
1014
|
+
groupSelect: GroupSelectHandler<V>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Add all entries from the given `array` to the selection.
|
|
1017
|
+
*
|
|
1018
|
+
*/
|
|
1019
|
+
selectAll: SelectAllHandler;
|
|
1020
|
+
/**
|
|
1021
|
+
* Removes all entries from the selection.
|
|
1022
|
+
*
|
|
1023
|
+
* @param initial If set to `true` will reset selection to the `initial` given value. Will empty the selection otherwise.
|
|
1024
|
+
*/
|
|
1025
|
+
resetSelection: ResetSelectionHandler;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* A React hook for managing selection states in an array.
|
|
1029
|
+
*
|
|
1030
|
+
* Provides functionality for single and group selection, as well as resetting the selection.
|
|
1031
|
+
*
|
|
1032
|
+
* @template V The type of the values in the `array` (defaults to the value type of `T`).
|
|
1033
|
+
*
|
|
1034
|
+
* @param array The array of items to manage selection for.
|
|
1035
|
+
* @param initial The initial selection state (defaults to an empty array).
|
|
1036
|
+
*
|
|
1037
|
+
* @returns An object containing the selection state and handlers. See {@link UseSelectionReturnType} for more info.
|
|
1038
|
+
*/
|
|
1039
|
+
declare const useSelection: <V>(array: V[], initial?: V[]) => UseSelectionReturnType<V>;
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Modified version of `useEffect` that skips the first render.
|
|
1043
|
+
*
|
|
1044
|
+
* @param effect Imperative function that can return a cleanup function.
|
|
1045
|
+
* @param deps If present, effect will only activate if the values in the list change.
|
|
1046
|
+
*/
|
|
1047
|
+
declare const useUpdateEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
1048
|
+
|
|
903
1049
|
/**
|
|
904
1050
|
* The function called when the timer elapses.
|
|
905
1051
|
*
|
|
@@ -1188,4 +1334,4 @@ declare function useTimeout<T extends readonly unknown[]>(callback: TimerHandler
|
|
|
1188
1334
|
*/
|
|
1189
1335
|
declare const useLightTimeout: <T extends readonly unknown[]>(callback: TimerHandler<T>, options?: BasicTimerOptions<T>) => void;
|
|
1190
1336
|
|
|
1191
|
-
export { type AddEventListenerOptions, type BasicTimerOptions, type ChangeHandler, type CommonListenerOptions, type CustomEventListenerOptions, type DocumentEventListener, type DocumentListenerOptions, type ElementEventListener, type ElementListenerOptions, type InputState, type InputType, type IntersectionState, type ListenerOptions, type MarginType, type MarginValue, type MediaQueryChangeListener, type MediaQueryEventListener, type MediaQueryListenerOptions, type OnChangeHandler, type OnIntersectHandler, type OnIntersectStateHandler, type ParseValueHandler, type StartTimer, type StateTimerOptions, type StateTimerReturnType, type StopTimer, type TimerHandler, type TimerId, type TimerOptions, type TimerReturnType, type UseDarkModeOptions, type UseDarkModeOutput, type UseInViewOptions, type UseInViewReturnType, type UseInputOptions, type UseInputOutput, type UseIntervalWhenVisibleReturnType, type UseIntervalWhenVisibleStateReturnType, type UseMediaQueryOptions, type UseMediaQueryStateOptions, type ValidateValueHandler, type WindowEventListener, type WindowListenerOptions, useDarkMode, useDebounce, useEffectOnce, useEventListener, useFocusTrap, useInView, useInput, useInterval, useIntervalWhenVisible, useIsClient, useIsFirstRender, useIsPortrait, useLightInterval, useLightTimeout, useLocalStorage, useMediaQuery, useScrollBlock, useSessionStorage, useStorage, useTimeout, useUpdateEffect };
|
|
1337
|
+
export { type AddEventListenerOptions, type BasicTimerOptions, type ChangeHandler, type CommonListenerOptions, type Connection, type CustomEventListenerOptions, type DocumentEventListener, type DocumentListenerOptions, type ElementEventListener, type ElementListenerOptions, type GroupSelectHandler, type InputState, type InputType, type IntersectionState, type IsSelectedHandler, type ListenerOptions, type MarginType, type MarginValue, type MediaQueryChangeListener, type MediaQueryEventListener, type MediaQueryListenerOptions, type OnChangeHandler, type OnIntersectHandler, type OnIntersectStateHandler, type ParseValueHandler, type ResetSelectionHandler, type SelectAllHandler, type SelectHandler, type SetSelectionHandler, type StartTimer, type StateTimerOptions, type StateTimerReturnType, type StopTimer, type TimerHandler, type TimerId, type TimerOptions, type TimerReturnType, type UseConnectionReturnType, type UseDarkModeOptions, type UseDarkModeOutput, type UseInViewOptions, type UseInViewReturnType, type UseInputOptions, type UseInputOutput, type UseIntervalWhenVisibleReturnType, type UseIntervalWhenVisibleStateReturnType, type UseMediaQueryOptions, type UseMediaQueryStateOptions, type UseSelectionReturnType, type ValidateValueHandler, type WindowEventListener, type WindowListenerOptions, getState, useConnection, useDarkMode, useDebounce, useEffectOnce, useEventListener, useFocusTrap, useInView, useInput, useInterval, useIntervalWhenVisible, useIsClient, useIsFirstRender, useIsPortrait, useLightInterval, useLightTimeout, useLocalStorage, useMediaQuery, usePagination, useScrollBlock, useSelection, useSessionStorage, useStorage, useTimeout, useUpdateEffect };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var _LocalStorage = require('@alessiofrittoli/web-utils/storage/LocalStorage');var _SessionStorage = require('@alessiofrittoli/web-utils/storage/SessionStorage');var I=(e,r,t="local")=>{let s=_react.useCallback.call(void 0, ()=>_nullishCoalesce((t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).get(e), () => (r)),[t,e,r]),[i,a]=_react.useState.call(void 0, r),o=_react.useCallback.call(void 0, n=>{a(u=>{let c=n instanceof Function?n(u):n;return(typeof window<"u"&&t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).set(e,c),c})},[t,e]);return _react.useEffect.call(void 0, ()=>{a(s())},[s]),[i,o]};var F=(e,r)=>I(e,r,"local");var Qe=(e,r)=>I(e,r,"session");var h=()=>{let e=_react.useRef.call(void 0, !0);return e.current?(e.current=!1,!0):e.current};var Ge=e=>{let r=h();_react.useEffect.call(void 0, ()=>{if(r)return e()},[])};var $=()=>{let[e,r]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>r(!0),[]),e};var b=(e,r)=>{let t=h();_react.useEffect.call(void 0, ()=>{if(!t)return e()},r)};var _webutils = require('@alessiofrittoli/web-utils');var L=e=>typeof e=="string"?_webutils.isEmpty.call(void 0, e):!e,C={value:"",isTouched:!1,isValid:!0},j=(e,r)=>{switch(r.type){case"TOUCHED":return{...e,isTouched:!0};case"CHANGE":return{...e,value:r.value};case"BLUR":return{...e,value:e.value,isTouched:!L(_nullishCoalesce(e.value, () => ("")))};case"RESET":return C}};var ct=(e={})=>{let{inputRef:r}=e,{initialValue:t}=e,{touchTimeout:s=600}=e,{validate:i,parse:a}=e,{onChange:o}=e,[n,u]=_react.useReducer.call(void 0, j,{...C,value:t}),c=a?a(n.value):n.value,{isTouched:l}=n,p=L(c),m=typeof i=="function"?i(c):!0,f=!m&&l||!!t&&!m;b(()=>{let T=setTimeout(()=>{L(c)||u({type:"TOUCHED"})},s);return()=>clearTimeout(T)},[c,s]);let v=_react.useCallback.call(void 0, T=>{let{target:E}=T,{type:y}=E,O=y==="checkbox"?E.checked:E.value;u({type:"CHANGE",value:O}),_optionalChain([o, 'optionalCall', _2 => _2(a?a(O):O)])},[o,a]),k=_react.useCallback.call(void 0, ()=>{u({type:"BLUR"})},[]),S=_react.useCallback.call(void 0, ()=>{u({type:"TOUCHED"})},[]),M=_react.useCallback.call(void 0, T=>{u({type:"CHANGE",value:T})},[]),x=_react.useCallback.call(void 0, ()=>{_optionalChain([r, 'optionalAccess', _3 => _3.current, 'optionalAccess', _4 => _4.focus, 'call', _5 => _5()])},[r]),H=_react.useCallback.call(void 0, ()=>{u({type:"RESET"})},[]);return{value:c,isTouched:l,isValid:m,isEmpty:p,hasError:f,changeHandler:v,blurHandler:k,setValue:M,submit:S,focus:x,reset:H}};var _browserapi = require('@alessiofrittoli/web-utils/browser-api');function R(e,r={}){let{updateState:t=!0,onChange:s}=r,[i,a]=_react.useState.call(void 0, _browserapi.getMediaMatches.call(void 0, e)),o=_react.useCallback.call(void 0, ()=>{let n=_browserapi.getMediaMatches.call(void 0, e);t&&a(n),_optionalChain([s, 'optionalCall', _6 => _6(n)])},[e,t,s]);if(_react.useEffect.call(void 0, ()=>{let n=window.matchMedia(e),{matches:u}=n;return t&&a(u),_optionalChain([s, 'optionalCall', _7 => _7(u)]),n.addEventListener("change",o),()=>{n.removeEventListener("change",o)}},[e,t,s,o]),!!t)return i}var Ot=(e={})=>{let r=$(),t=R("(prefers-color-scheme: dark)"),{initial:s=t,docClassNames:i=[]}=e,[a,o]=F("dark-mode",s),n=_nullishCoalesce(a, () => (t)),[u,c]=i,l=_react.useRef.call(void 0, {light:"",dark:""});return b(()=>{o(t)},[t,o]),_react.useEffect.call(void 0, ()=>{u&&document.documentElement.classList.toggle(u,n),c&&document.documentElement.classList.toggle(c,!n)},[n,u,c]),_react.useEffect.call(void 0, ()=>{document.head.querySelectorAll('meta[name="theme-color"]').forEach(p=>{let m=p.getAttribute("media"),f=p.getAttribute("content");if(f){if(!m||m==="(prefers-color-scheme: light)"){l.current.light=f;return}l.current.dark=f}})},[]),b(()=>{let p=l.current.dark,m=l.current.light;a&&!p||!a&&!m||document.head.querySelectorAll('meta[name="theme-color"]').forEach(f=>{f.setAttribute("content",a?p:m)})},[a]),{isDarkMode:r?n:!1,isDarkOS:r?t:!1,toggleDarkMode:_react.useCallback.call(void 0, ()=>o(p=>!p),[o]),enableDarkMode:_react.useCallback.call(void 0, ()=>o(!0),[o]),disableDarkMode:_react.useCallback.call(void 0, ()=>o(!1),[o])}};function bt(e,r){let{target:t,query:s,options:i,listener:a,onLoad:o,onCleanUp:n}=r;_react.useEffect.call(void 0, ()=>{let u=Array.isArray(e)?e:[e],c=_nullishCoalesce((s?window.matchMedia(s):t&&"current"in t?t.current:t), () => (window));if(c.addEventListener)return _optionalChain([o, 'optionalCall', _8 => _8()]),u.map(l=>{c.addEventListener(l,a,i)}),()=>{u.map(l=>{c.removeEventListener(l,a,i)}),_optionalChain([n, 'optionalCall', _9 => _9()])}},[e,t,s,i,a,o,n])}var _device = require('@alessiofrittoli/web-utils/device');var kt=()=>R(_device.portraitMediaQuery);var fe=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),wt= exports.useFocusTrap =e=>{let[r,t]=_react.useState.call(void 0, !1),s=_react.useRef.call(void 0, null),i=_react.useCallback.call(void 0, o=>{s.current=document.activeElement;let n=o||_optionalChain([e, 'optionalAccess', _10 => _10.current])||!1;if(n)return t(n)},[e]),a=_react.useCallback.call(void 0, ()=>{_optionalChain([s, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.focus, 'call', _13 => _13()]),t(!1)},[]);return _react.useEffect.call(void 0, ()=>{if(!r)return;let o=n=>{if(n.key!=="Tab")return;let u=Array.from(r.querySelectorAll(fe)),c=u.at(0),l=u.at(-1);if(!n.shiftKey){document.activeElement===l&&(n.preventDefault(),_optionalChain([c, 'optionalAccess', _14 => _14.focus, 'call', _15 => _15()]));return}document.activeElement===c&&(n.preventDefault(),_optionalChain([l, 'optionalAccess', _16 => _16.focus, 'call', _17 => _17()]))};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[r]),[i,a]};var At=(e,r={})=>{let{initial:t=!1,once:s,amount:i,margin:a,root:o,enable:n=!0}=r,{onEnter:u,onExit:c,onIntersect:l}=r,p=_react.useRef.call(void 0, !0),[m,f]=_react.useState.call(void 0, t),[v,k]=_react.useState.call(void 0, n),S=_react.useRef.call(void 0, null),M=_react.useRef.call(void 0, !1),x=_react.useMemo.call(void 0, ()=>{if(!v||typeof IntersectionObserver>"u")return;let H=i==="all"?1:i==="some"?.5:i;try{return new IntersectionObserver(async([T],E)=>{if(!T)return;let y=T.isIntersecting;try{if(M.current=!y&&!!S.current,y&&u&&await u({entry:T,observer:E}),M.current&&c&&await c({entry:T,observer:E}),l&&(y||!y&&S.current!=null)){let O={isEntering:y,isExiting:M.current};await l({entry:T,observer:E,...O})}if(S.current=y,!p.current)return;f(y)}catch(O){console.error(O)}y&&s&&E.disconnect()},{root:o||void 0,rootMargin:a,threshold:H})}catch(T){console.error(T)}},[o,a,i,s,v,u,c,l]);return _react.useEffect.call(void 0, ()=>{if(p.current=!0,!(!v||!e.current||!x))return x.observe(e.current),()=>{p.current=!1,x.disconnect()}},[e,x,v]),{inView:m,enabled:v,observer:x,isExiting:M.current,setInView:f,setEnabled:k}};var _dom = require('@alessiofrittoli/web-utils/dom');var jt=e=>{let r=_react.useCallback.call(void 0, ()=>_dom.blockScroll.call(void 0, _optionalChain([e, 'optionalAccess', _18 => _18.current])||void 0),[e]),t=_react.useCallback.call(void 0, ()=>_dom.restoreScroll.call(void 0, _optionalChain([e, 'optionalAccess', _19 => _19.current])||void 0),[e]);return[r,t]};var z=(e,r={})=>{let{delay:t=1,args:s}=r;_react.useEffect.call(void 0, ()=>{let i=setTimeout(e,t,...s||[]);return()=>clearTimeout(i)},[t,s,e])};var Xt=(e,r=500)=>{let[t,s]=_react.useState.call(void 0, e),i=_react.useMemo.call(void 0, ()=>[e],[e]);return z(s,{delay:r,args:i}),t};function J(e,r={}){let{delay:t=1,args:s,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,n=_react.useRef.call(void 0, void 0),[u,c]=_react.useState.call(void 0, i),l=_react.useCallback.call(void 0, ()=>n.current?(clearInterval(n.current),n.current=void 0,!0):!1,[]),p=_react.useCallback.call(void 0, ()=>{let f=l();return a&&(s?e(...s):e()),n.current=setInterval(e,t,...s||[]),!f&&o&&c(!0),n.current},[t,s,o,a,e,l]),m=_react.useCallback.call(void 0, ()=>{l()&&o&&c(!1)},[o,l]);return _react.useEffect.call(void 0, ()=>{if(i)return p(),m},[i,p,m]),o?{isActive:u,start:p,stop:m}:{start:p,stop:m}}var rn=(e,r={})=>{let{delay:t=1,args:s}=r;_react.useEffect.call(void 0, ()=>{let i=setInterval(e,t,...s||[]);return()=>clearInterval(i)},[t,s,e])};function cn(e,r={}){let{autoplay:t=!0}=r,s=J(e,{autoplay:!1,...r}),{start:i,stop:a}=s,o=_react.useCallback.call(void 0, ()=>document.hidden?a():i(),[i,a]),n=_react.useCallback.call(void 0, ()=>{if(document.addEventListener("visibilitychange",o),!document.hidden)return i()},[i,o]),u=_react.useCallback.call(void 0, ()=>{a(),document.removeEventListener("visibilitychange",o)},[a,o]);return _react.useEffect.call(void 0, ()=>{if(t)return n(),u},[t,n,u]),{...s,start:n,stop:u}}function mn(e,r={}){let{delay:t=1,args:s,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,n=_react.useRef.call(void 0, void 0),[u,c]=_react.useState.call(void 0, i),l=_react.useCallback.call(void 0, ()=>n.current?(clearTimeout(n.current),n.current=void 0,!0):!1,[]),p=_react.useCallback.call(void 0, ()=>{let f=l();return a&&(s?e(...s):e()),n.current=setTimeout(()=>{if(n.current=void 0,o&&c(!1),s)return e(...s);e()},t),!f&&o&&c(!0),n.current},[t,s,o,a,e,l]),m=_react.useCallback.call(void 0, ()=>{l()&&o&&c(!1)},[o,l]);return _react.useEffect.call(void 0, ()=>{if(i)return p(),m},[i,p,m]),o?{isActive:u,start:p,stop:m}:{start:p,stop:m}}exports.useDarkMode = Ot; exports.useDebounce = Xt; exports.useEffectOnce = Ge; exports.useEventListener = bt; exports.useFocusTrap = wt; exports.useInView = At; exports.useInput = ct; exports.useInterval = J; exports.useIntervalWhenVisible = cn; exports.useIsClient = $; exports.useIsFirstRender = h; exports.useIsPortrait = kt; exports.useLightInterval = rn; exports.useLightTimeout = z; exports.useLocalStorage = F; exports.useMediaQuery = R; exports.useScrollBlock = jt; exports.useSessionStorage = Qe; exports.useStorage = I; exports.useTimeout = mn; exports.useUpdateEffect = b;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var _LocalStorage = require('@alessiofrittoli/web-utils/storage/LocalStorage');var _SessionStorage = require('@alessiofrittoli/web-utils/storage/SessionStorage');var H=(e,n,t="local")=>{let r=_react.useCallback.call(void 0, ()=>_nullishCoalesce((t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).get(e), () => (n)),[t,e,n]),[i,u]=_react.useState.call(void 0, n),s=_react.useCallback.call(void 0, o=>{u(c=>{let l=o instanceof Function?o(c):o;return(typeof window<"u"&&t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).set(e,l),l})},[t,e]);return _react.useEffect.call(void 0, ()=>{u(r())},[r]),[i,s]};var $=(e,n)=>H(e,n,"local");var qe=(e,n)=>H(e,n,"session");var j=e=>e?"online":"offline",Ze= exports.useConnection =()=>{let[e,n]=_react.useState.call(void 0, j(!0)),t=e==="online",r=e==="offline",i=_react.useCallback.call(void 0, ()=>n(j(navigator.onLine)),[]);return P(["online","offline"],{listener:i,onLoad:i}),{connection:e,isOnline:t,isOffline:r}};var h=()=>{let e=_react.useRef.call(void 0, !0);return e.current?(e.current=!1,!0):e.current};var I=(e,n)=>{let t=h();_react.useEffect.call(void 0, ()=>{if(!t)return e()},n)};var _webutils = require('@alessiofrittoli/web-utils');var R=e=>typeof e=="string"?_webutils.isEmpty.call(void 0, e):!e,C={value:"",isTouched:!1,isValid:!0},B=(e,n)=>{switch(n.type){case"TOUCHED":return{...e,isTouched:!0};case"CHANGE":return{...e,value:n.value};case"BLUR":return{...e,value:e.value,isTouched:!R(_nullishCoalesce(e.value, () => ("")))};case"RESET":return C}};var ft=(e={})=>{let{inputRef:n}=e,{initialValue:t}=e,{touchTimeout:r=600}=e,{validate:i,parse:u}=e,{onChange:s}=e,[o,c]=_react.useReducer.call(void 0, B,{...C,value:t}),l=u?u(o.value):o.value,{isTouched:a}=o,d=R(l),p=typeof i=="function"?i(l):!0,f=!p&&a||!!t&&!p;I(()=>{let T=setTimeout(()=>{R(l)||c({type:"TOUCHED"})},r);return()=>clearTimeout(T)},[l,r]);let y=_react.useCallback.call(void 0, T=>{let{target:x}=T,{type:v}=x,M=v==="checkbox"?x.checked:x.value;c({type:"CHANGE",value:M}),_optionalChain([s, 'optionalCall', _2 => _2(u?u(M):M)])},[s,u]),S=_react.useCallback.call(void 0, ()=>{c({type:"BLUR"})},[]),O=_react.useCallback.call(void 0, ()=>{c({type:"TOUCHED"})},[]),E=_react.useCallback.call(void 0, T=>{c({type:"CHANGE",value:T})},[]),g=_react.useCallback.call(void 0, ()=>{_optionalChain([n, 'optionalAccess', _3 => _3.current, 'optionalAccess', _4 => _4.focus, 'call', _5 => _5()])},[n]),V=_react.useCallback.call(void 0, ()=>{c({type:"RESET"})},[]);return{value:l,isTouched:a,isValid:p,isEmpty:d,hasError:f,changeHandler:y,blurHandler:S,setValue:E,submit:O,focus:g,reset:V}};var xt=e=>{let n=h();_react.useEffect.call(void 0, ()=>{if(n)return e()},[])};var N=()=>{let[e,n]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>n(!0),[]),e};var _helpers = require('@alessiofrittoli/math-utils/helpers');var ht=(e={})=>_react.useMemo.call(void 0, ()=>_helpers.paginate.call(void 0, e),[e]);var Vt=(e,n=[])=>{let[t,r]=_react.useState.call(void 0, n),i=t.length>0,u=a=>t.includes(a),s=_react.useCallback.call(void 0, a=>r(d=>{let p=new Set(d);return p.has(a)?p.delete(a):p.add(a),Array.from(p.values())}),[]),o=_react.useCallback.call(void 0, a=>{r(d=>{if(d.length===0)return[a];let p=[...e],f=p.indexOf(d.at(0)),y=p.indexOf(a);if(f>y){let S=[...p].reverse(),O=S.indexOf(d.at(0)),E=S.indexOf(a);return S.slice(O,E+1).reverse()}return p.slice(f,y+1)})},[e]),c=_react.useCallback.call(void 0, ()=>{r(e)},[e]),l=_react.useCallback.call(void 0, a=>r(a?n:[]),[n]);return{selection:t,hasSelection:i,isSelected:u,setSelection:r,select:s,groupSelect:o,selectAll:c,resetSelection:l}};var _browserapi = require('@alessiofrittoli/web-utils/browser-api');function k(e,n={}){let{updateState:t=!0,onChange:r}=n,[i,u]=_react.useState.call(void 0, _browserapi.getMediaMatches.call(void 0, e)),s=_react.useCallback.call(void 0, ()=>{let o=_browserapi.getMediaMatches.call(void 0, e);t&&u(o),_optionalChain([r, 'optionalCall', _6 => _6(o)])},[e,t,r]);if(_react.useEffect.call(void 0, ()=>{let o=window.matchMedia(e),{matches:c}=o;return t&&u(c),_optionalChain([r, 'optionalCall', _7 => _7(c)]),o.addEventListener("change",s),()=>{o.removeEventListener("change",s)}},[e,t,r,s]),!!t)return i}var jt=(e={})=>{let n=N(),t=k("(prefers-color-scheme: dark)"),{initial:r=t,docClassNames:i=[]}=e,[u,s]=$("dark-mode",r),o=_nullishCoalesce(u, () => (t)),[c,l]=i,a=_react.useRef.call(void 0, {light:"",dark:""});return I(()=>{s(t)},[t,s]),_react.useEffect.call(void 0, ()=>{c&&document.documentElement.classList.toggle(c,o),l&&document.documentElement.classList.toggle(l,!o)},[o,c,l]),_react.useEffect.call(void 0, ()=>{document.head.querySelectorAll('meta[name="theme-color"]').forEach(d=>{let p=d.getAttribute("media"),f=d.getAttribute("content");if(f){if(!p||p==="(prefers-color-scheme: light)"){a.current.light=f;return}a.current.dark=f}})},[]),I(()=>{let d=a.current.dark,p=a.current.light;u&&!d||!u&&!p||document.head.querySelectorAll('meta[name="theme-color"]').forEach(f=>{f.setAttribute("content",u?d:p)})},[u]),{isDarkMode:n?o:!1,isDarkOS:n?t:!1,toggleDarkMode:_react.useCallback.call(void 0, ()=>s(d=>!d),[s]),enableDarkMode:_react.useCallback.call(void 0, ()=>s(!0),[s]),disableDarkMode:_react.useCallback.call(void 0, ()=>s(!1),[s])}};function P(e,n){let{target:t,query:r,options:i,listener:u,onLoad:s,onCleanUp:o}=n;_react.useEffect.call(void 0, ()=>{let c=Array.isArray(e)?e:[e],l=_nullishCoalesce((r?window.matchMedia(r):t&&"current"in t?t.current:t), () => (window));if(l.addEventListener)return _optionalChain([s, 'optionalCall', _8 => _8()]),c.map(a=>{l.addEventListener(a,u,i)}),()=>{c.map(a=>{l.removeEventListener(a,u,i)}),_optionalChain([o, 'optionalCall', _9 => _9()])}},[e,t,r,i,u,s,o])}var _device = require('@alessiofrittoli/web-utils/device');var Xt=()=>k(_device.portraitMediaQuery);var ge=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),en= exports.useFocusTrap =e=>{let[n,t]=_react.useState.call(void 0, !1),r=_react.useRef.call(void 0, null),i=_react.useCallback.call(void 0, s=>{r.current=document.activeElement;let o=s||_optionalChain([e, 'optionalAccess', _10 => _10.current])||!1;if(o)return t(o)},[e]),u=_react.useCallback.call(void 0, ()=>{_optionalChain([r, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.focus, 'call', _13 => _13()]),t(!1)},[]);return _react.useEffect.call(void 0, ()=>{if(!n)return;let s=o=>{if(o.key!=="Tab")return;let c=Array.from(n.querySelectorAll(ge)),l=c.at(0),a=c.at(-1);if(!o.shiftKey){document.activeElement===a&&(o.preventDefault(),_optionalChain([l, 'optionalAccess', _14 => _14.focus, 'call', _15 => _15()]));return}document.activeElement===l&&(o.preventDefault(),_optionalChain([a, 'optionalAccess', _16 => _16.focus, 'call', _17 => _17()]))};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s)}},[n]),[i,u]};var on=(e,n={})=>{let{initial:t=!1,once:r,amount:i,margin:u,root:s,enable:o=!0}=n,{onEnter:c,onExit:l,onIntersect:a}=n,d=_react.useRef.call(void 0, !0),[p,f]=_react.useState.call(void 0, t),[y,S]=_react.useState.call(void 0, o),O=_react.useRef.call(void 0, null),E=_react.useRef.call(void 0, !1),g=_react.useMemo.call(void 0, ()=>{if(!y||typeof IntersectionObserver>"u")return;let V=i==="all"?1:i==="some"?.5:i;try{return new IntersectionObserver(async([T],x)=>{if(!T)return;let v=T.isIntersecting;try{if(E.current=!v&&!!O.current,v&&c&&await c({entry:T,observer:x}),E.current&&l&&await l({entry:T,observer:x}),a&&(v||!v&&O.current!=null)){let M={isEntering:v,isExiting:E.current};await a({entry:T,observer:x,...M})}if(O.current=v,!d.current)return;f(v)}catch(M){console.error(M)}v&&r&&x.disconnect()},{root:s||void 0,rootMargin:u,threshold:V})}catch(T){console.error(T)}},[s,u,i,r,y,c,l,a]);return _react.useEffect.call(void 0, ()=>{if(d.current=!0,!(!y||!e.current||!g))return g.observe(e.current),()=>{d.current=!1,g.disconnect()}},[e,g,y]),{inView:p,enabled:y,observer:g,isExiting:E.current,setInView:f,setEnabled:S}};var _dom = require('@alessiofrittoli/web-utils/dom');var ln=e=>{let n=_react.useCallback.call(void 0, ()=>_dom.blockScroll.call(void 0, _optionalChain([e, 'optionalAccess', _18 => _18.current])||void 0),[e]),t=_react.useCallback.call(void 0, ()=>_dom.restoreScroll.call(void 0, _optionalChain([e, 'optionalAccess', _19 => _19.current])||void 0),[e]);return[n,t]};var Y=(e,n={})=>{let{delay:t=1,args:r}=n;_react.useEffect.call(void 0, ()=>{let i=setTimeout(e,t,...r||[]);return()=>clearTimeout(i)},[t,r,e])};var En=(e,n=500)=>{let[t,r]=_react.useState.call(void 0, e),i=_react.useMemo.call(void 0, ()=>[e],[e]);return Y(r,{delay:n,args:i}),t};function Z(e,n={}){let{delay:t=1,args:r,autoplay:i=!0,runOnStart:u=!1,updateState:s=!1}=n,o=_react.useRef.call(void 0, void 0),[c,l]=_react.useState.call(void 0, i),a=_react.useCallback.call(void 0, ()=>o.current?(clearInterval(o.current),o.current=void 0,!0):!1,[]),d=_react.useCallback.call(void 0, ()=>{let f=a();return u&&(r?e(...r):e()),o.current=setInterval(e,t,...r||[]),!f&&s&&l(!0),o.current},[t,r,s,u,e,a]),p=_react.useCallback.call(void 0, ()=>{a()&&s&&l(!1)},[s,a]);return _react.useEffect.call(void 0, ()=>{if(i)return d(),p},[i,d,p]),s?{isActive:c,start:d,stop:p}:{start:d,stop:p}}var In=(e,n={})=>{let{delay:t=1,args:r}=n;_react.useEffect.call(void 0, ()=>{let i=setInterval(e,t,...r||[]);return()=>clearInterval(i)},[t,r,e])};function kn(e,n={}){let{autoplay:t=!0}=n,r=Z(e,{autoplay:!1,...n}),{start:i,stop:u}=r,s=_react.useCallback.call(void 0, ()=>document.hidden?u():i(),[i,u]),o=_react.useCallback.call(void 0, ()=>{if(document.addEventListener("visibilitychange",s),!document.hidden)return i()},[i,s]),c=_react.useCallback.call(void 0, ()=>{u(),document.removeEventListener("visibilitychange",s)},[u,s]);return _react.useEffect.call(void 0, ()=>{if(t)return o(),c},[t,o,c]),{...r,start:o,stop:c}}function Dn(e,n={}){let{delay:t=1,args:r,autoplay:i=!0,runOnStart:u=!1,updateState:s=!1}=n,o=_react.useRef.call(void 0, void 0),[c,l]=_react.useState.call(void 0, i),a=_react.useCallback.call(void 0, ()=>o.current?(clearTimeout(o.current),o.current=void 0,!0):!1,[]),d=_react.useCallback.call(void 0, ()=>{let f=a();return u&&(r?e(...r):e()),o.current=setTimeout(()=>{if(o.current=void 0,s&&l(!1),r)return e(...r);e()},t),!f&&s&&l(!0),o.current},[t,r,s,u,e,a]),p=_react.useCallback.call(void 0, ()=>{a()&&s&&l(!1)},[s,a]);return _react.useEffect.call(void 0, ()=>{if(i)return d(),p},[i,d,p]),s?{isActive:c,start:d,stop:p}:{start:d,stop:p}}exports.getState = j; exports.useConnection = Ze; exports.useDarkMode = jt; exports.useDebounce = En; exports.useEffectOnce = xt; exports.useEventListener = P; exports.useFocusTrap = en; exports.useInView = on; exports.useInput = ft; exports.useInterval = Z; exports.useIntervalWhenVisible = kn; exports.useIsClient = N; exports.useIsFirstRender = h; exports.useIsPortrait = Xt; exports.useLightInterval = In; exports.useLightTimeout = Y; exports.useLocalStorage = $; exports.useMediaQuery = k; exports.usePagination = ht; exports.useScrollBlock = ln; exports.useSelection = Vt; exports.useSessionStorage = qe; exports.useStorage = H; exports.useTimeout = Dn; exports.useUpdateEffect = I;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as Q,useEffect as ee,useState as te}from"react";import{LocalStorage as F}from"@alessiofrittoli/web-utils/storage/LocalStorage";import{SessionStorage as $}from"@alessiofrittoli/web-utils/storage/SessionStorage";var h=(e,n,t="local")=>{let r=Q(()=>(t==="local"?F:$).get(e)??n,[t,e,n]),[i,u]=te(n),s=Q(o=>{u(c=>{let l=o instanceof Function?o(c):o;return(typeof window<"u"&&t==="local"?F:$).set(e,l),l})},[t,e]);return ee(()=>{u(r())},[r]),[i,s]};var j=(e,n)=>h(e,n,"local");var ze=(e,n)=>h(e,n,"session");import{useCallback as ne,useState as re}from"react";var P=e=>e?"online":"offline",_e=()=>{let[e,n]=re(P(!0)),t=e==="online",r=e==="offline",i=ne(()=>n(P(navigator.onLine)),[]);return B(["online","offline"],{listener:i,onLoad:i}),{connection:e,isOnline:t,isOffline:r}};import{useCallback as D,useEffect as z,useRef as ve}from"react";import{useCallback as I,useReducer as ae}from"react";import{useEffect as se}from"react";import{useRef as oe}from"react";var R=()=>{let e=oe(!0);return e.current?(e.current=!1,!0):e.current};var H=(e,n)=>{let t=R();se(()=>{if(!t)return e()},n)};import{isEmpty as ie}from"@alessiofrittoli/web-utils";var L=e=>typeof e=="string"?ie(e):!e,w={value:"",isTouched:!1,isValid:!0},N=(e,n)=>{switch(n.type){case"TOUCHED":return{...e,isTouched:!0};case"CHANGE":return{...e,value:n.value};case"BLUR":return{...e,value:e.value,isTouched:!L(e.value??"")};case"RESET":return w}};var Tt=(e={})=>{let{inputRef:n}=e,{initialValue:t}=e,{touchTimeout:r=600}=e,{validate:i,parse:u}=e,{onChange:s}=e,[o,c]=ae(N,{...w,value:t}),l=u?u(o.value):o.value,{isTouched:a}=o,d=L(l),p=typeof i=="function"?i(l):!0,T=!p&&a||!!t&&!p;H(()=>{let y=setTimeout(()=>{L(l)||c({type:"TOUCHED"})},r);return()=>clearTimeout(y)},[l,r]);let v=I(y=>{let{target:S}=y,{type:E}=S,b=E==="checkbox"?S.checked:S.value;c({type:"CHANGE",value:b}),s?.(u?u(b):b)},[s,u]),O=I(()=>{c({type:"BLUR"})},[]),g=I(()=>{c({type:"TOUCHED"})},[]),x=I(y=>{c({type:"CHANGE",value:y})},[]),M=I(()=>{n?.current?.focus()},[n]),C=I(()=>{c({type:"RESET"})},[]);return{value:l,isTouched:a,isValid:p,isEmpty:d,hasError:T,changeHandler:v,blurHandler:O,setValue:x,submit:g,focus:M,reset:C}};import{useEffect as ue}from"react";var St=e=>{let n=R();ue(()=>{if(n)return e()},[])};import{useEffect as ce,useState as le}from"react";var G=()=>{let[e,n]=le(!1);return ce(()=>n(!0),[]),e};import{useMemo as pe}from"react";import{paginate as de}from"@alessiofrittoli/math-utils/helpers";var Rt=(e={})=>pe(()=>de(e),[e]);import{useCallback as k,useState as me}from"react";var Ct=(e,n=[])=>{let[t,r]=me(n),i=t.length>0,u=a=>t.includes(a),s=k(a=>r(d=>{let p=new Set(d);return p.has(a)?p.delete(a):p.add(a),Array.from(p.values())}),[]),o=k(a=>{r(d=>{if(d.length===0)return[a];let p=[...e],T=p.indexOf(d.at(0)),v=p.indexOf(a);if(T>v){let O=[...p].reverse(),g=O.indexOf(d.at(0)),x=O.indexOf(a);return O.slice(g,x+1).reverse()}return p.slice(T,v+1)})},[e]),c=k(()=>{r(e)},[e]),l=k(a=>r(a?n:[]),[n]);return{selection:t,hasSelection:i,isSelected:u,setSelection:r,select:s,groupSelect:o,selectAll:c,resetSelection:l}};import{useCallback as fe,useEffect as Te,useState as ye}from"react";import{getMediaMatches as q}from"@alessiofrittoli/web-utils/browser-api";function V(e,n={}){let{updateState:t=!0,onChange:r}=n,[i,u]=ye(q(e)),s=fe(()=>{let o=q(e);t&&u(o),r?.(o)},[e,t,r]);if(Te(()=>{let o=window.matchMedia(e),{matches:c}=o;return t&&u(c),r?.(c),o.addEventListener("change",s),()=>{o.removeEventListener("change",s)}},[e,t,r,s]),!!t)return i}var Pt=(e={})=>{let n=G(),t=V("(prefers-color-scheme: dark)"),{initial:r=t,docClassNames:i=[]}=e,[u,s]=j("dark-mode",r),o=u??t,[c,l]=i,a=ve({light:"",dark:""});return H(()=>{s(t)},[t,s]),z(()=>{c&&document.documentElement.classList.toggle(c,o),l&&document.documentElement.classList.toggle(l,!o)},[o,c,l]),z(()=>{document.head.querySelectorAll('meta[name="theme-color"]').forEach(d=>{let p=d.getAttribute("media"),T=d.getAttribute("content");if(T){if(!p||p==="(prefers-color-scheme: light)"){a.current.light=T;return}a.current.dark=T}})},[]),H(()=>{let d=a.current.dark,p=a.current.light;u&&!d||!u&&!p||document.head.querySelectorAll('meta[name="theme-color"]').forEach(T=>{T.setAttribute("content",u?d:p)})},[u]),{isDarkMode:n?o:!1,isDarkOS:n?t:!1,toggleDarkMode:D(()=>s(d=>!d),[s]),enableDarkMode:D(()=>s(!0),[s]),disableDarkMode:D(()=>s(!1),[s])}};import{useEffect as Ee}from"react";function B(e,n){let{target:t,query:r,options:i,listener:u,onLoad:s,onCleanUp:o}=n;Ee(()=>{let c=Array.isArray(e)?e:[e],l=(r?window.matchMedia(r):t&&"current"in t?t.current:t)??window;if(l.addEventListener)return s?.(),c.map(a=>{l.addEventListener(a,u,i)}),()=>{c.map(a=>{l.removeEventListener(a,u,i)}),o?.()}},[e,t,r,i,u,s,o])}import{portraitMediaQuery as xe}from"@alessiofrittoli/web-utils/device";var Yt=()=>V(xe);import{useCallback as J,useEffect as Se,useRef as Oe,useState as ge}from"react";var Me=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),tn=e=>{let[n,t]=ge(!1),r=Oe(null),i=J(s=>{r.current=document.activeElement;let o=s||e?.current||!1;if(o)return t(o)},[e]),u=J(()=>{r.current?.focus(),t(!1)},[]);return Se(()=>{if(!n)return;let s=o=>{if(o.key!=="Tab")return;let c=Array.from(n.querySelectorAll(Me)),l=c.at(0),a=c.at(-1);if(!o.shiftKey){document.activeElement===a&&(o.preventDefault(),l?.focus());return}document.activeElement===l&&(o.preventDefault(),a?.focus())};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s)}},[n]),[i,u]};import{useEffect as be,useMemo as Ie,useRef as U,useState as X}from"react";var sn=(e,n={})=>{let{initial:t=!1,once:r,amount:i,margin:u,root:s,enable:o=!0}=n,{onEnter:c,onExit:l,onIntersect:a}=n,d=U(!0),[p,T]=X(t),[v,O]=X(o),g=U(null),x=U(!1),M=Ie(()=>{if(!v||typeof IntersectionObserver>"u")return;let C=i==="all"?1:i==="some"?.5:i;try{return new IntersectionObserver(async([y],S)=>{if(!y)return;let E=y.isIntersecting;try{if(x.current=!E&&!!g.current,E&&c&&await c({entry:y,observer:S}),x.current&&l&&await l({entry:y,observer:S}),a&&(E||!E&&g.current!=null)){let b={isEntering:E,isExiting:x.current};await a({entry:y,observer:S,...b})}if(g.current=E,!d.current)return;T(E)}catch(b){console.error(b)}E&&r&&S.disconnect()},{root:s||void 0,rootMargin:u,threshold:C})}catch(y){console.error(y)}},[s,u,i,r,v,c,l,a]);return be(()=>{if(d.current=!0,!(!v||!e.current||!M))return M.observe(e.current),()=>{d.current=!1,M.disconnect()}},[e,M,v]),{inView:p,enabled:v,observer:M,isExiting:x.current,setInView:T,setEnabled:O}};import{useCallback as Y}from"react";import{blockScroll as He,restoreScroll as he}from"@alessiofrittoli/web-utils/dom";var pn=e=>{let n=Y(()=>He(e?.current||void 0),[e]),t=Y(()=>he(e?.current||void 0),[e]);return[n,t]};import{useMemo as Le,useState as ke}from"react";import{useEffect as Re}from"react";var Z=(e,n={})=>{let{delay:t=1,args:r}=n;Re(()=>{let i=setTimeout(e,t,...r||[]);return()=>clearTimeout(i)},[t,r,e])};var xn=(e,n=500)=>{let[t,r]=ke(e),i=Le(()=>[e],[e]);return Z(r,{delay:n,args:i}),t};import{useCallback as K,useEffect as Ve,useRef as Ce,useState as we}from"react";function _(e,n={}){let{delay:t=1,args:r,autoplay:i=!0,runOnStart:u=!1,updateState:s=!1}=n,o=Ce(void 0),[c,l]=we(i),a=K(()=>o.current?(clearInterval(o.current),o.current=void 0,!0):!1,[]),d=K(()=>{let T=a();return u&&(r?e(...r):e()),o.current=setInterval(e,t,...r||[]),!T&&s&&l(!0),o.current},[t,r,s,u,e,a]),p=K(()=>{a()&&s&&l(!1)},[s,a]);return Ve(()=>{if(i)return d(),p},[i,d,p]),s?{isActive:c,start:d,stop:p}:{start:d,stop:p}}import{useEffect as De}from"react";var Hn=(e,n={})=>{let{delay:t=1,args:r}=n;De(()=>{let i=setInterval(e,t,...r||[]);return()=>clearInterval(i)},[t,r,e])};import{useCallback as A,useEffect as Ue}from"react";function Vn(e,n={}){let{autoplay:t=!0}=n,r=_(e,{autoplay:!1,...n}),{start:i,stop:u}=r,s=A(()=>document.hidden?u():i(),[i,u]),o=A(()=>{if(document.addEventListener("visibilitychange",s),!document.hidden)return i()},[i,s]),c=A(()=>{u(),document.removeEventListener("visibilitychange",s)},[u,s]);return Ue(()=>{if(t)return o(),c},[t,o,c]),{...r,start:o,stop:c}}import{useCallback as W,useEffect as Ke,useRef as Ae,useState as We}from"react";function Un(e,n={}){let{delay:t=1,args:r,autoplay:i=!0,runOnStart:u=!1,updateState:s=!1}=n,o=Ae(void 0),[c,l]=We(i),a=W(()=>o.current?(clearTimeout(o.current),o.current=void 0,!0):!1,[]),d=W(()=>{let T=a();return u&&(r?e(...r):e()),o.current=setTimeout(()=>{if(o.current=void 0,s&&l(!1),r)return e(...r);e()},t),!T&&s&&l(!0),o.current},[t,r,s,u,e,a]),p=W(()=>{a()&&s&&l(!1)},[s,a]);return Ke(()=>{if(i)return d(),p},[i,d,p]),s?{isActive:c,start:d,stop:p}:{start:d,stop:p}}export{P as getState,_e as useConnection,Pt as useDarkMode,xn as useDebounce,St as useEffectOnce,B as useEventListener,tn as useFocusTrap,sn as useInView,Tt as useInput,_ as useInterval,Vn as useIntervalWhenVisible,G as useIsClient,R as useIsFirstRender,Yt as useIsPortrait,Hn as useLightInterval,Z as useLightTimeout,j as useLocalStorage,V as useMediaQuery,Rt as usePagination,pn as useScrollBlock,Ct as useSelection,ze as useSessionStorage,h as useStorage,Un as useTimeout,H as useUpdateEffect};
|
package/license.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2025 Alessio Frittoli.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 Alessio Frittoli.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|