@siberiacancode/reactuse 0.2.26 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs +2 -0
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -0
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs +2 -0
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs.map +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs +20 -16
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs +22 -8
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs +36 -0
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -0
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs +30 -0
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs.map +1 -0
- package/dist/esm/index.mjs +276 -272
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/helpers/createStore/createStore.d.ts +12 -8
- package/dist/types/hooks/browser.d.ts +1 -0
- package/dist/types/hooks/elements.d.ts +1 -0
- package/dist/types/hooks/useAsync/useAsync.d.ts +2 -2
- package/dist/types/hooks/useImage/useImage.d.ts +6 -6
- package/dist/types/hooks/useVirtualKeyboard/useVirtualKeyboard.d.ts +41 -0
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
1
|
+
type StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;
|
|
2
|
+
type StoreListener<Value> = (state: Value, prevState: Value) => void;
|
|
3
|
+
type StoreCreator<Value> = (set: (action: StoreSetAction<Value>) => void, get: () => Value) => Value;
|
|
3
4
|
export interface StoreApi<Value> {
|
|
4
5
|
getInitialState: () => Value;
|
|
5
6
|
getState: () => Value;
|
|
6
|
-
setState: (action:
|
|
7
|
-
subscribe: (listener:
|
|
7
|
+
setState: (action: StoreSetAction<Value>) => void;
|
|
8
|
+
subscribe: (listener: StoreListener<Value>) => () => void;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* @name createStore
|
|
@@ -21,10 +22,13 @@ export interface StoreApi<Value> {
|
|
|
21
22
|
* increment: () => set(state => ({ count: state.count + 1 }))
|
|
22
23
|
* }));
|
|
23
24
|
*/
|
|
24
|
-
export declare const createStore: <Value>(createState:
|
|
25
|
-
set: (action:
|
|
25
|
+
export declare const createStore: <Value>(createState: StoreCreator<Value> | Value) => {
|
|
26
|
+
set: (action: StoreSetAction<Value>) => void;
|
|
26
27
|
get: () => Value;
|
|
27
|
-
use:
|
|
28
|
-
|
|
28
|
+
use: {
|
|
29
|
+
(): Value;
|
|
30
|
+
<Selected>(selector: (state: Value) => Selected): Selected;
|
|
31
|
+
};
|
|
32
|
+
subscribe: (listener: StoreListener<Value>) => () => boolean;
|
|
29
33
|
};
|
|
30
34
|
export {};
|
|
@@ -28,5 +28,6 @@ export * from './useShare/useShare';
|
|
|
28
28
|
export * from './useSpeechRecognition/useSpeechRecognition';
|
|
29
29
|
export * from './useSpeechSynthesis/useSpeechSynthesis';
|
|
30
30
|
export * from './useVibrate/useVibrate';
|
|
31
|
+
export * from './useVirtualKeyboard/useVirtualKeyboard';
|
|
31
32
|
export * from './useWakeLock/useWakeLock';
|
|
32
33
|
export * from './useWebSocket/useWebSocket';
|
|
@@ -9,6 +9,7 @@ export * from './useHover/useHover';
|
|
|
9
9
|
export * from './useImage/useImage';
|
|
10
10
|
export * from './useLongPress/useLongPress';
|
|
11
11
|
export * from './usePaint/usePaint';
|
|
12
|
+
export * from './useRightClick/useRightClick';
|
|
12
13
|
export * from './useScript/useScript';
|
|
13
14
|
export * from './useSticky/useSticky';
|
|
14
15
|
export * from './useTextDirection/useTextDirection';
|
|
@@ -11,10 +11,10 @@ export interface UseAsyncReturn<Data> {
|
|
|
11
11
|
* @category Async
|
|
12
12
|
*
|
|
13
13
|
* @param {() => Promise<Data>} callback The async callback
|
|
14
|
-
* @param {DependencyList} deps The dependencies of the callback
|
|
14
|
+
* @param {DependencyList} [deps=[]] The dependencies of the callback
|
|
15
15
|
* @returns {UseAsyncReturn<Data>} The state of the async callback
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);
|
|
19
19
|
*/
|
|
20
|
-
export declare const useAsync: <Data>(callback: () => Promise<Data>, deps
|
|
20
|
+
export declare const useAsync: <Data>(callback: () => Promise<Data>, deps?: DependencyList) => UseAsyncReturn<Data>;
|
|
@@ -31,14 +31,14 @@ export type UseImageReturn = UseQueryReturn<HTMLImageElement>;
|
|
|
31
31
|
* @param {HTMLImageElement['loading']} [options.loading] The loading of the image
|
|
32
32
|
* @param {string} [options.crossorigin] The crossorigin of the image
|
|
33
33
|
* @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image
|
|
34
|
-
* @param {DependencyList} [
|
|
35
|
-
* @param {(data: Data) => void} [
|
|
36
|
-
* @param {(error: Error) => void} [
|
|
37
|
-
* @param {number} [
|
|
38
|
-
* @param {boolean | number} [
|
|
34
|
+
* @param {DependencyList} [options.keys] The dependencies for the hook
|
|
35
|
+
* @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success
|
|
36
|
+
* @param {(error: Error) => void} [options.onError] The callback function to be invoked on error
|
|
37
|
+
* @param {number} [options.refetchInterval] The refetch interval
|
|
38
|
+
* @param {boolean | number} [options.retry] The retry count of requests
|
|
39
39
|
* @returns {UseImageReturn} An object with the state of the image
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');
|
|
43
43
|
*/
|
|
44
|
-
export declare const useImage: (src: string, options?: UseImageOptions
|
|
44
|
+
export declare const useImage: (src: string, options?: UseImageOptions & Omit<UseQueryOptions<HTMLImageElement, HTMLImageElement>, "initialData" | "placeholderData" | "select">) => UseQueryReturn<HTMLImageElement>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Navigator {
|
|
3
|
+
virtualKeyboard?: {
|
|
4
|
+
boundingRect: DOMRect;
|
|
5
|
+
overlaysContent: boolean;
|
|
6
|
+
show: () => void;
|
|
7
|
+
hide: () => void;
|
|
8
|
+
addEventListener: (type: 'geometrychange', listener: EventListener) => void;
|
|
9
|
+
removeEventListener: (type: 'geometrychange', listener: EventListener) => void;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The use virtual keyboard return type */
|
|
14
|
+
export interface UseVirtualKeyboardReturn {
|
|
15
|
+
/** Whether the virtual keyboard is currently open */
|
|
16
|
+
opened: boolean;
|
|
17
|
+
/** Whether the VirtualKeyboard API is supported */
|
|
18
|
+
supported: boolean;
|
|
19
|
+
/** Change the overlays content */
|
|
20
|
+
changeOverlaysContent: (overlaysContent: boolean) => void;
|
|
21
|
+
/** Hide the virtual keyboard */
|
|
22
|
+
hide: () => void;
|
|
23
|
+
/** Show the virtual keyboard */
|
|
24
|
+
show: () => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @name useVirtualKeyboard
|
|
28
|
+
* @description - Hook that manages virtual keyboard state
|
|
29
|
+
* @category Browser
|
|
30
|
+
*
|
|
31
|
+
* @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard
|
|
32
|
+
*
|
|
33
|
+
* @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.
|
|
34
|
+
*
|
|
35
|
+
* @param {boolean} [initialValue=false] The initial state value for keyboard visibility
|
|
36
|
+
* @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();
|
|
40
|
+
*/
|
|
41
|
+
export declare const useVirtualKeyboard: (initialValue?: boolean) => UseVirtualKeyboardReturn;
|