@vef-framework/hooks 2.0.11 → 2.1.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/dist/cjs/index.cjs +1 -1
- package/dist/cjs/lib.cjs +1 -1
- package/dist/cjs/use-authorized-items/index.cjs +1 -1
- package/dist/cjs/use-breakpoints/index.cjs +1 -1
- package/dist/cjs/use-check-permission/index.cjs +1 -1
- package/dist/cjs/use-data-dict-query/index.cjs +1 -1
- package/dist/cjs/use-data-options/index.cjs +1 -1
- package/dist/cjs/use-deep-callback/index.cjs +1 -1
- package/dist/cjs/use-deep-compare/index.cjs +1 -1
- package/dist/cjs/use-deep-effect/index.cjs +1 -1
- package/dist/cjs/use-deep-isomorphic-effect/index.cjs +1 -1
- package/dist/cjs/use-deep-layout-effect/index.cjs +1 -1
- package/dist/cjs/use-deep-memo/index.cjs +1 -1
- package/dist/cjs/use-document-event/index.cjs +1 -1
- package/dist/cjs/use-emitter-event/index.cjs +1 -1
- package/dist/cjs/use-has-fetching/index.cjs +1 -1
- package/dist/cjs/use-has-mutating/index.cjs +1 -1
- package/dist/cjs/use-is-authorized/index.cjs +1 -1
- package/dist/cjs/use-latest/index.cjs +1 -1
- package/dist/cjs/use-raf-state/index.cjs +1 -1
- package/dist/cjs/use-shallow-callback/index.cjs +1 -1
- package/dist/cjs/use-shallow-compare/index.cjs +1 -1
- package/dist/cjs/use-shallow-effect/index.cjs +1 -1
- package/dist/cjs/use-shallow-isomorphic-effect/index.cjs +1 -1
- package/dist/cjs/use-shallow-layout-effect/index.cjs +1 -1
- package/dist/cjs/use-shallow-memo/index.cjs +1 -1
- package/dist/cjs/use-singleton/index.cjs +1 -1
- package/dist/cjs/use-viewport-size/index.cjs +1 -0
- package/dist/es/index.js +29 -85
- package/dist/es/lib.js +14 -60
- package/dist/es/use-authorized-items/index.js +11 -14
- package/dist/es/use-breakpoints/index.js +47 -53
- package/dist/es/use-check-permission/index.js +8 -11
- package/dist/es/use-data-dict-query/index.js +21 -25
- package/dist/es/use-data-options/index.js +46 -78
- package/dist/es/use-deep-callback/index.js +8 -7
- package/dist/es/use-deep-compare/index.js +15 -19
- package/dist/es/use-deep-effect/index.js +8 -7
- package/dist/es/use-deep-isomorphic-effect/index.js +8 -8
- package/dist/es/use-deep-layout-effect/index.js +7 -6
- package/dist/es/use-deep-memo/index.js +8 -7
- package/dist/es/use-document-event/index.js +20 -15
- package/dist/es/use-emitter-event/index.js +11 -15
- package/dist/es/use-has-fetching/index.js +11 -10
- package/dist/es/use-has-mutating/index.js +10 -9
- package/dist/es/use-is-authorized/index.js +8 -11
- package/dist/es/use-latest/index.js +7 -6
- package/dist/es/use-raf-state/index.js +14 -13
- package/dist/es/use-shallow-callback/index.js +8 -7
- package/dist/es/use-shallow-compare/index.js +15 -19
- package/dist/es/use-shallow-effect/index.js +8 -7
- package/dist/es/use-shallow-isomorphic-effect/index.js +8 -8
- package/dist/es/use-shallow-layout-effect/index.js +8 -7
- package/dist/es/use-shallow-memo/index.js +8 -7
- package/dist/es/use-singleton/index.js +7 -6
- package/dist/es/use-viewport-size/index.js +34 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/lib.d.ts +1 -0
- package/dist/types/src/index.d.ts +27 -0
- package/dist/types/src/lib.d.ts +7 -0
- package/dist/types/src/use-authorized-items/index.d.ts +22 -0
- package/dist/types/src/use-breakpoints/index.d.ts +55 -0
- package/dist/types/src/use-check-permission/index.d.ts +8 -0
- package/dist/types/src/use-data-dict-query/index.d.ts +15 -0
- package/dist/types/src/use-data-options/index.d.ts +86 -0
- package/dist/types/src/use-deep-callback/index.d.ts +11 -0
- package/dist/types/src/use-deep-compare/index.d.ts +9 -0
- package/dist/types/src/use-deep-effect/index.d.ts +10 -0
- package/dist/types/src/use-deep-isomorphic-effect/index.d.ts +11 -0
- package/dist/types/src/use-deep-layout-effect/index.d.ts +10 -0
- package/dist/types/src/use-deep-memo/index.d.ts +11 -0
- package/dist/types/src/use-document-event/index.d.ts +19 -0
- package/dist/types/src/use-emitter-event/index.d.ts +17 -0
- package/dist/types/src/use-has-fetching/index.d.ts +8 -0
- package/dist/types/src/use-has-mutating/index.d.ts +7 -0
- package/dist/types/src/use-is-authorized/index.d.ts +10 -0
- package/dist/types/src/use-latest/index.d.ts +21 -0
- package/dist/types/src/use-raf-state/index.d.ts +23 -0
- package/dist/types/src/use-shallow-callback/index.d.ts +14 -0
- package/dist/types/src/use-shallow-compare/index.d.ts +13 -0
- package/dist/types/src/use-shallow-effect/index.d.ts +13 -0
- package/dist/types/src/use-shallow-isomorphic-effect/index.d.ts +13 -0
- package/dist/types/src/use-shallow-layout-effect/index.d.ts +13 -0
- package/dist/types/src/use-shallow-memo/index.d.ts +14 -0
- package/dist/types/src/use-singleton/index.d.ts +18 -0
- package/dist/types/src/use-viewport-size/index.d.ts +20 -0
- package/dist/types/use-authorized-items/index.d.ts +5 -5
- package/dist/types/use-breakpoints/index.d.ts +15 -7
- package/dist/types/use-check-permission/index.d.ts +2 -2
- package/dist/types/use-data-dict-query/index.d.ts +1 -1
- package/dist/types/use-data-options/index.d.ts +8 -2
- package/dist/types/use-deep-callback/index.d.ts +7 -5
- package/dist/types/use-deep-compare/index.d.ts +4 -3
- package/dist/types/use-deep-effect/index.d.ts +5 -4
- package/dist/types/use-deep-isomorphic-effect/index.d.ts +6 -4
- package/dist/types/use-deep-layout-effect/index.d.ts +5 -4
- package/dist/types/use-deep-memo/index.d.ts +6 -4
- package/dist/types/use-document-event/index.d.ts +15 -4
- package/dist/types/use-emitter-event/index.d.ts +13 -5
- package/dist/types/use-is-authorized/index.d.ts +2 -2
- package/dist/types/use-latest/index.d.ts +18 -5
- package/dist/types/use-raf-state/index.d.ts +18 -3
- package/dist/types/use-shallow-callback/index.d.ts +10 -5
- package/dist/types/use-shallow-compare/index.d.ts +8 -3
- package/dist/types/use-shallow-effect/index.d.ts +8 -4
- package/dist/types/use-shallow-isomorphic-effect/index.d.ts +8 -4
- package/dist/types/use-shallow-layout-effect/index.d.ts +8 -4
- package/dist/types/use-shallow-memo/index.d.ts +8 -3
- package/dist/types/use-singleton/index.d.ts +14 -7
- package/dist/types/use-viewport-size/index.d.ts +20 -0
- package/package.json +8 -7
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.1.0 made by Venus | 2026-03-27T07:13:03.756Z */
|
|
2
|
+
import { useWindowEvent as e } from "../lib.js";
|
|
3
|
+
import { useRafState as t } from "../use-raf-state/index.js";
|
|
4
|
+
import { isUndefined as n } from "@vef-framework/shared";
|
|
5
|
+
import { useEffect as r } from "react";
|
|
6
|
+
//#region src/use-viewport-size/index.ts
|
|
7
|
+
var i = { passive: !0 };
|
|
8
|
+
function a() {
|
|
9
|
+
let a = !n(globalThis.window), [o, s] = t(() => ({
|
|
10
|
+
width: a ? window.innerWidth : 0,
|
|
11
|
+
height: a ? window.innerHeight : 0
|
|
12
|
+
}));
|
|
13
|
+
return r(() => {
|
|
14
|
+
function e() {
|
|
15
|
+
n(globalThis.window) || s({
|
|
16
|
+
width: window.innerWidth,
|
|
17
|
+
height: window.innerHeight
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
e();
|
|
21
|
+
}, [s]), e("resize", () => {
|
|
22
|
+
n(globalThis.window) || s({
|
|
23
|
+
width: window.innerWidth,
|
|
24
|
+
height: window.innerHeight
|
|
25
|
+
});
|
|
26
|
+
}, i), e("orientationchange", () => {
|
|
27
|
+
n(globalThis.window) || s({
|
|
28
|
+
width: window.innerWidth,
|
|
29
|
+
height: window.innerHeight
|
|
30
|
+
});
|
|
31
|
+
}, i), o;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { a as useViewportSize };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './lib';
|
|
2
2
|
export { useAuthorizedItems, type PermissionAware } from './use-authorized-items';
|
|
3
3
|
export { useBreakpoints, type Breakpoints, type UseBreakpointsOptions, type UseBreakpointsResult } from './use-breakpoints';
|
|
4
4
|
export { useCheckPermission } from './use-check-permission';
|
|
@@ -23,4 +23,5 @@ export { useShallowEffect } from './use-shallow-effect';
|
|
|
23
23
|
export { useShallowIsomorphicEffect } from './use-shallow-isomorphic-effect';
|
|
24
24
|
export { useShallowLayoutEffect } from './use-shallow-layout-effect';
|
|
25
25
|
export { useShallowMemo } from './use-shallow-memo';
|
|
26
|
-
export { useSingleton
|
|
26
|
+
export { useSingleton } from './use-singleton';
|
|
27
|
+
export { useViewportSize } from './use-viewport-size';
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { UseColorSchemeValue, UseMediaQueryOptions } from '@mantine/hooks';
|
|
|
2
2
|
export declare function useMediaQuery(query: string, initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
3
3
|
export declare function useColorScheme(initialValue?: UseColorSchemeValue, options?: UseMediaQueryOptions): UseColorSchemeValue;
|
|
4
4
|
export declare function useReducedMotion(initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
5
|
+
export { useChat, useCompletion, experimental_useObject as useObject, type Chat, type CreateUIMessage, type UIMessage, type UseChatHelpers, type UseChatOptions, type UseCompletionHelpers, type UseCompletionOptions, type Experimental_UseObjectHelpers as UseObjectHelpers, type Experimental_UseObjectOptions as UseObjectOptions } from '@ai-sdk/react';
|
|
5
6
|
export { assignRef, getHotkeyHandler, mergeRefs, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDidUpdate, useDocumentTitle, useElementSize, useEventListener, useFocusTrap, useFullscreen, useIntersection, useInterval, useIsFirstRender, useIsomorphicEffect, useMergedRef, useMounted, useMutationObserver, usePrevious, useResizeObserver, useTimeout, useWindowEvent } from '@mantine/hooks';
|
|
6
7
|
export { HotkeysProvider, useHotkeys, useHotkeysContext, useRecordHotkeys, type HotkeyCallback, type Options as HotkeysOptions } from 'react-hotkeys-hook';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './lib';
|
|
2
|
+
export { useAuthorizedItems, type PermissionAware } from './use-authorized-items';
|
|
3
|
+
export { useBreakpoints, type Breakpoints, type UseBreakpointsOptions, type UseBreakpointsResult } from './use-breakpoints';
|
|
4
|
+
export { useCheckPermission } from './use-check-permission';
|
|
5
|
+
export { useDataDictQuery, type UseDataDictQueryOptions } from './use-data-dict-query';
|
|
6
|
+
export { useDataOptionsQuery, type FieldExtractor, type UseDataOptionsQueryOptions, type UseDataOptionsQueryResult } from './use-data-options';
|
|
7
|
+
export { useDeepCallback } from './use-deep-callback';
|
|
8
|
+
export { useDeepCompare } from './use-deep-compare';
|
|
9
|
+
export { useDeepEffect } from './use-deep-effect';
|
|
10
|
+
export { useDeepIsomorphicEffect } from './use-deep-isomorphic-effect';
|
|
11
|
+
export { useDeepLayoutEffect } from './use-deep-layout-effect';
|
|
12
|
+
export { useDeepMemo } from './use-deep-memo';
|
|
13
|
+
export { useDocumentEvent } from './use-document-event';
|
|
14
|
+
export { useEmitterEvent } from './use-emitter-event';
|
|
15
|
+
export { useHasFetching } from './use-has-fetching';
|
|
16
|
+
export { useHasMutating } from './use-has-mutating';
|
|
17
|
+
export { useIsAuthorized } from './use-is-authorized';
|
|
18
|
+
export { useLatest } from './use-latest';
|
|
19
|
+
export { useRafState } from './use-raf-state';
|
|
20
|
+
export { useShallowCallback } from './use-shallow-callback';
|
|
21
|
+
export { useShallowCompare } from './use-shallow-compare';
|
|
22
|
+
export { useShallowEffect } from './use-shallow-effect';
|
|
23
|
+
export { useShallowIsomorphicEffect } from './use-shallow-isomorphic-effect';
|
|
24
|
+
export { useShallowLayoutEffect } from './use-shallow-layout-effect';
|
|
25
|
+
export { useShallowMemo } from './use-shallow-memo';
|
|
26
|
+
export { useSingleton } from './use-singleton';
|
|
27
|
+
export { useViewportSize } from './use-viewport-size';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UseColorSchemeValue, UseMediaQueryOptions } from '@mantine/hooks';
|
|
2
|
+
export declare function useMediaQuery(query: string, initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
3
|
+
export declare function useColorScheme(initialValue?: UseColorSchemeValue, options?: UseMediaQueryOptions): UseColorSchemeValue;
|
|
4
|
+
export declare function useReducedMotion(initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
5
|
+
export { useChat, useCompletion, experimental_useObject as useObject, type Chat, type CreateUIMessage, type UIMessage, type UseChatHelpers, type UseChatOptions, type UseCompletionHelpers, type UseCompletionOptions, type Experimental_UseObjectHelpers as UseObjectHelpers, type Experimental_UseObjectOptions as UseObjectOptions } from '@ai-sdk/react';
|
|
6
|
+
export { assignRef, getHotkeyHandler, mergeRefs, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDidUpdate, useDocumentTitle, useElementSize, useEventListener, useFocusTrap, useFullscreen, useIntersection, useInterval, useIsFirstRender, useIsomorphicEffect, useMergedRef, useMounted, useMutationObserver, usePrevious, useResizeObserver, useTimeout, useWindowEvent } from '@mantine/hooks';
|
|
7
|
+
export { HotkeysProvider, useHotkeys, useHotkeysContext, useRecordHotkeys, type HotkeyCallback, type Options as HotkeysOptions } from 'react-hotkeys-hook';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for items that have permission requirements.
|
|
5
|
+
*/
|
|
6
|
+
export interface PermissionAware {
|
|
7
|
+
/**
|
|
8
|
+
* The permission tokens to check.
|
|
9
|
+
*/
|
|
10
|
+
permTokens?: MaybeArray<string>;
|
|
11
|
+
/**
|
|
12
|
+
* The permission check mode (default: "any").
|
|
13
|
+
*/
|
|
14
|
+
checkMode?: PermissionCheckMode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hook to filter items based on user permissions.
|
|
18
|
+
*
|
|
19
|
+
* @param items - The items to filter based on permissions.
|
|
20
|
+
* @returns The filtered items that the user is authorized to access.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useAuthorizedItems<T extends PermissionAware>(items: T[]): T[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type BreakpointValue = number | string;
|
|
2
|
+
export type Breakpoints<T extends string = string> = Record<T, BreakpointValue>;
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by useBreakpoints hook
|
|
5
|
+
*/
|
|
6
|
+
export interface UseBreakpointsResult<T extends string = string> {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the current active breakpoint (largest matching)
|
|
9
|
+
*/
|
|
10
|
+
current?: T;
|
|
11
|
+
/**
|
|
12
|
+
* The numeric value of the current breakpoint
|
|
13
|
+
*/
|
|
14
|
+
value?: BreakpointValue;
|
|
15
|
+
/**
|
|
16
|
+
* Array of all matching breakpoint names
|
|
17
|
+
*/
|
|
18
|
+
matches: T[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for useBreakpoints hook
|
|
22
|
+
*/
|
|
23
|
+
export interface UseBreakpointsOptions<T extends string = string> {
|
|
24
|
+
/**
|
|
25
|
+
* Initial breakpoint name for SSR (server-side rendering)
|
|
26
|
+
* If not provided, will default to null during SSR
|
|
27
|
+
*/
|
|
28
|
+
initialBreakpoint?: T;
|
|
29
|
+
/**
|
|
30
|
+
* Get initial value in effect instead of on mount
|
|
31
|
+
* This helps avoid hydration mismatches in SSR
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
getInitialValueInEffect?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tracks active responsive breakpoints based on window width using media queries.
|
|
39
|
+
* Returns the current breakpoint and all matching breakpoints.
|
|
40
|
+
*
|
|
41
|
+
* @param breakpoints - Breakpoint configuration object mapping names to min-width values.
|
|
42
|
+
* @param options - Hook options for SSR and hydration handling.
|
|
43
|
+
* @returns Current breakpoint information including name, value, and all matches.
|
|
44
|
+
* @remarks
|
|
45
|
+
* Uses `min-width` media queries, so include a breakpoint starting from 0 to cover all viewport sizes.
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* const breakpoints = { xs: 0, sm: 640, md: 768, lg: 1024, xl: 1280 };
|
|
49
|
+
* const { current, matches } = useBreakpoints(breakpoints);
|
|
50
|
+
*
|
|
51
|
+
* // current: 'md' (largest matching breakpoint)
|
|
52
|
+
* // matches: ['xs', 'sm', 'md'] (all matching breakpoints)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function useBreakpoints<T extends string>(breakpoints: Breakpoints<T>, options?: UseBreakpointsOptions<T>): UseBreakpointsResult<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Hook that returns a function to check permissions imperatively.
|
|
5
|
+
*
|
|
6
|
+
* @returns A function that checks if the user has the specified permissions.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useCheckPermission(): (permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataOption, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
|
|
2
|
+
import { Except } from '@vef-framework/shared';
|
|
3
|
+
export type UseDataDictQueryOptions<TData = DataOption> = Except<UseQueryOptions<DataOption[], TData[], string>, "queryFn" | "queryKey" | "queryHash" | "queryKeyHashFn"> & {
|
|
4
|
+
dataDictKey?: string;
|
|
5
|
+
onFetch?: (data: TData[]) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A hook for querying data dictionary.
|
|
9
|
+
* Uses the dataDictQueryFn from app context to fetch data dictionary options.
|
|
10
|
+
*
|
|
11
|
+
* @param dataDictKey - The key of the data dictionary to query.
|
|
12
|
+
* @param options - Additional query options (excluding queryFn and queryKey).
|
|
13
|
+
* @returns The query result containing data dictionary options.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDataDictQuery<TData = DataOption>({ dataDictKey, onFetch, ...options }: UseDataDictQueryOptions<TData>): UseQueryResult<TData[]>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DataOption, DataOptionWithPinyin, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
|
|
2
|
+
import { Key, MaybeUndefined, Simplify } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Field extractor - can be a string path (e.g., "user.name") or a function
|
|
5
|
+
*/
|
|
6
|
+
export type FieldExtractor<TData, TValue> = string | ((item: TData) => TValue);
|
|
7
|
+
/**
|
|
8
|
+
* Base field mapping options
|
|
9
|
+
*/
|
|
10
|
+
export interface DataOptionsFieldMapping<TData = unknown> {
|
|
11
|
+
/**
|
|
12
|
+
* Field mapping for label
|
|
13
|
+
*
|
|
14
|
+
* @default "label"
|
|
15
|
+
*/
|
|
16
|
+
labelKey?: FieldExtractor<TData, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Field mapping for value
|
|
19
|
+
*
|
|
20
|
+
* @default "value"
|
|
21
|
+
*/
|
|
22
|
+
valueKey?: FieldExtractor<TData, Key>;
|
|
23
|
+
/**
|
|
24
|
+
* Field mapping for disabled
|
|
25
|
+
*
|
|
26
|
+
* @default "disabled"
|
|
27
|
+
*/
|
|
28
|
+
disabledKey?: FieldExtractor<TData, MaybeUndefined<boolean>>;
|
|
29
|
+
/**
|
|
30
|
+
* Field mapping for description
|
|
31
|
+
*
|
|
32
|
+
* @default "description"
|
|
33
|
+
*/
|
|
34
|
+
descriptionKey?: FieldExtractor<TData, MaybeUndefined<string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Field mapping for children
|
|
37
|
+
*
|
|
38
|
+
* @default "children"
|
|
39
|
+
*/
|
|
40
|
+
childrenKey?: FieldExtractor<TData, MaybeUndefined<TData[]>>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for useDataOptionsQuery with regular query
|
|
44
|
+
*/
|
|
45
|
+
export type UseDataOptionsQueryOptionsWithQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never> = DataOptionsFieldMapping<TData> & {
|
|
46
|
+
/**
|
|
47
|
+
* Options for fetching data using regular query
|
|
48
|
+
*/
|
|
49
|
+
queryOptions: UseQueryOptions<TQueryFnData[], TData[], TParams>;
|
|
50
|
+
/**
|
|
51
|
+
* Data dictionary key - should not be provided when using queryOptions
|
|
52
|
+
*/
|
|
53
|
+
dataDictKey?: never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Options for useDataOptionsQuery with data dictionary query
|
|
57
|
+
*/
|
|
58
|
+
export type UseDataOptionsQueryOptionsWithDataDict<TData = DataOption> = DataOptionsFieldMapping<TData> & {
|
|
59
|
+
/**
|
|
60
|
+
* Data dictionary key
|
|
61
|
+
*/
|
|
62
|
+
dataDictKey: string;
|
|
63
|
+
/**
|
|
64
|
+
* Regular query options - should not be provided when using dataDictKey
|
|
65
|
+
*/
|
|
66
|
+
queryOptions?: never;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Options for useDataOptionsQuery hook - supports both regular query and data dictionary query
|
|
70
|
+
*/
|
|
71
|
+
export type UseDataOptionsQueryOptions<TQueryFnData = unknown, TData = TQueryFnData, TParams = never> = UseDataOptionsQueryOptionsWithQuery<TQueryFnData, TData, TParams> | UseDataOptionsQueryOptionsWithDataDict<TData>;
|
|
72
|
+
/**
|
|
73
|
+
* Return type for useDataOptionsQuery hook
|
|
74
|
+
*/
|
|
75
|
+
export type UseDataOptionsQueryResult<TData, TOption> = Simplify<Omit<UseQueryResult<TData[]>, "data"> & {
|
|
76
|
+
options: TOption[];
|
|
77
|
+
}>;
|
|
78
|
+
export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(config: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams>): UseDataOptionsQueryResult<TData, DataOption<TData>>;
|
|
79
|
+
export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(options: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams> & {
|
|
80
|
+
/**
|
|
81
|
+
* Whether to add pinyin fields for label and description
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
withPinyin: boolean;
|
|
86
|
+
}): UseDataOptionsQueryResult<TData, DataOptionWithPinyin<TData>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes a callback function with deep comparison of dependencies.
|
|
4
|
+
* Unlike `useCallback`, this performs deep equality checks on dependency values,
|
|
5
|
+
* preventing unnecessary callback recreation when objects/arrays have the same content.
|
|
6
|
+
*
|
|
7
|
+
* @param callback - The callback function to memoize.
|
|
8
|
+
* @param dependencies - The dependency array to deeply compare for changes.
|
|
9
|
+
* @returns The memoized callback that only changes when dependencies are deeply different.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useDeepCallback<T extends (...args: any[]) => any>(callback: T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Performs deep comparison of dependency arrays to detect changes.
|
|
4
|
+
* Unlike React's default shallow comparison, this compares nested objects and arrays by value.
|
|
5
|
+
*
|
|
6
|
+
* @param dependencies - The dependency array to track for deep changes.
|
|
7
|
+
* @returns A memoized array containing a signal value that changes only when dependencies are deeply different.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepCompare(dependencies?: DependencyList): readonly [number];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs an effect with deep comparison of dependencies.
|
|
4
|
+
* Unlike `useEffect`, this performs deep equality checks on dependency values,
|
|
5
|
+
* preventing unnecessary effect execution when objects/arrays have the same content.
|
|
6
|
+
*
|
|
7
|
+
* @param effect - The effect callback to execute.
|
|
8
|
+
* @param dependencies - The dependency array to deeply compare for changes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDeepEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs an isomorphic effect with deep comparison of dependencies.
|
|
4
|
+
* Uses `useLayoutEffect` on the client and `useEffect` on the server.
|
|
5
|
+
* Unlike `useIsomorphicEffect`, this performs deep equality checks on dependency values,
|
|
6
|
+
* preventing unnecessary effect execution when objects/arrays have the same content.
|
|
7
|
+
*
|
|
8
|
+
* @param effect - The effect callback to execute.
|
|
9
|
+
* @param dependencies - The dependency array to deeply compare for changes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useDeepIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs a layout effect with deep comparison of dependencies.
|
|
4
|
+
* Unlike `useLayoutEffect`, this performs deep equality checks on dependency values,
|
|
5
|
+
* preventing unnecessary effect execution when objects/arrays have the same content.
|
|
6
|
+
*
|
|
7
|
+
* @param effect - The effect callback to execute synchronously after DOM mutations.
|
|
8
|
+
* @param dependencies - The dependency array to deeply compare for changes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDeepLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes a computed value with deep comparison of dependencies.
|
|
4
|
+
* Unlike `useMemo`, this performs deep equality checks on dependency values,
|
|
5
|
+
* preventing unnecessary recomputation when objects/arrays have the same content.
|
|
6
|
+
*
|
|
7
|
+
* @param factory - The factory function that computes the memoized value.
|
|
8
|
+
* @param dependencies - The dependency array to deeply compare for changes.
|
|
9
|
+
* @returns The memoized value that only recomputes when dependencies are deeply different.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useDeepMemo<T>(factory: () => T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attaches an event listener to the document with automatic cleanup.
|
|
3
|
+
* The listener function is always called with the latest version, preventing stale closures.
|
|
4
|
+
*
|
|
5
|
+
* @param type - Event type to listen for (e.g., 'click', 'keydown').
|
|
6
|
+
* @param listener - Event handler function.
|
|
7
|
+
* @param options - Event listener options (capture, passive, once).
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function Component() {
|
|
11
|
+
* useDocumentEvent('keydown', (event) => {
|
|
12
|
+
* if (event.key === 'Escape') {
|
|
13
|
+
* closeModal();
|
|
14
|
+
* }
|
|
15
|
+
* });
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDocumentEvent<TType extends string>(type: TType, listener: TType extends keyof DocumentEventMap ? (this: Document, event: DocumentEventMap[TType]) => void : (this: Document, event: CustomEvent) => void, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventHandler, EventType, EventEmitter } from '@vef-framework/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to an EventEmitter event with automatic cleanup.
|
|
4
|
+
*
|
|
5
|
+
* @param emitter - EventEmitter instance to subscribe to.
|
|
6
|
+
* @param eventType - Event type to listen for.
|
|
7
|
+
* @param eventListener - Event handler function.
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function Component({ emitter }) {
|
|
11
|
+
* useEmitterEvent(emitter, 'data', (data) => {
|
|
12
|
+
* console.log('Received:', data);
|
|
13
|
+
* });
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useEmitterEvent<TEvents extends Record<EventType, any>>(emitter: EventEmitter<TEvents>, eventType: keyof TEvents, eventListener: EventHandler<TEvents[keyof TEvents]>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook to check if there are any active queries fetching for a specific query key.
|
|
3
|
+
*
|
|
4
|
+
* @param key - The base query key to check for fetching status.
|
|
5
|
+
* @param params - Optional parameters to include in the query key for more specific filtering.
|
|
6
|
+
* @returns True if there are any active queries fetching with the specified key, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useHasFetching(key: string, params?: unknown): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook to check if there are any active mutations for a specific mutation key.
|
|
3
|
+
*
|
|
4
|
+
* @param key - The base mutation key to check for mutating status.
|
|
5
|
+
* @returns True if there are any active mutations with the specified key, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useHasMutating(key: string): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to check if the user is authorized based on permission tokens.
|
|
5
|
+
*
|
|
6
|
+
* @param permTokens - The permission tokens to check.
|
|
7
|
+
* @param checkMode - The check mode to use (default: "any").
|
|
8
|
+
* @returns Whether the user is authorized to access the resource identified by the permission token.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useIsAuthorized(permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a ref that always contains the latest value.
|
|
4
|
+
* Useful for accessing current props/state in callbacks without re-creating them.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The value to track.
|
|
7
|
+
* @returns A ref object containing the latest value.
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function Component({ onChange }) {
|
|
11
|
+
* const onChangeRef = useLatest(onChange);
|
|
12
|
+
*
|
|
13
|
+
* useEffect(() => {
|
|
14
|
+
* const handler = () => onChangeRef.current();
|
|
15
|
+
* window.addEventListener('resize', handler);
|
|
16
|
+
* return () => window.removeEventListener('resize', handler);
|
|
17
|
+
* }, []); // No need to include onChange in deps
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function useLatest<T>(value: T): MutableRefObject<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* State hook that batches updates using requestAnimationFrame.
|
|
4
|
+
* Useful for high-frequency updates (e.g., scroll, resize, mouse move) to prevent excessive re-renders.
|
|
5
|
+
*
|
|
6
|
+
* @param initialState - Initial state value or lazy initializer function.
|
|
7
|
+
* @returns Tuple of [state, setState] similar to useState.
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function Component() {
|
|
11
|
+
* const [position, setPosition] = useRafState({ x: 0, y: 0 });
|
|
12
|
+
*
|
|
13
|
+
* useEffect(() => {
|
|
14
|
+
* const handleMove = (e: MouseEvent) => {
|
|
15
|
+
* setPosition({ x: e.clientX, y: e.clientY });
|
|
16
|
+
* };
|
|
17
|
+
* window.addEventListener('mousemove', handleMove);
|
|
18
|
+
* return () => window.removeEventListener('mousemove', handleMove);
|
|
19
|
+
* }, []);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function useRafState<T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes a callback function with shallow comparison of dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Similar to React's useCallback, but uses shallow equality comparison for the
|
|
6
|
+
* dependency array instead of reference equality. This is useful when your
|
|
7
|
+
* dependencies are objects or arrays that may have the same content but
|
|
8
|
+
* different references.
|
|
9
|
+
*
|
|
10
|
+
* @param callback - The callback function to memoize.
|
|
11
|
+
* @param dependencies - Dependency array to compare shallowly.
|
|
12
|
+
* @returns The memoized callback function.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useShallowCallback<T extends (...args: any[]) => any>(callback: T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Performs shallow comparison of dependency arrays for React hooks.
|
|
4
|
+
* Returns a stable reference that only changes when dependencies are not shallowly equal.
|
|
5
|
+
*
|
|
6
|
+
* This is useful for optimizing hooks like useEffect, useMemo, and useCallback
|
|
7
|
+
* when you want to compare object/array dependencies by their shallow content
|
|
8
|
+
* rather than by reference identity.
|
|
9
|
+
*
|
|
10
|
+
* @param dependencies - The dependency array to compare.
|
|
11
|
+
* @returns A tuple containing a signal number that increments when dependencies change.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useShallowCompare(dependencies?: DependencyList): readonly [number];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs an effect with shallow comparison of dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Similar to React's useEffect, but uses shallow equality comparison for the
|
|
6
|
+
* dependency array instead of reference equality. This is useful when your
|
|
7
|
+
* dependencies are objects or arrays that may have the same content but
|
|
8
|
+
* different references.
|
|
9
|
+
*
|
|
10
|
+
* @param effect - The effect function to run.
|
|
11
|
+
* @param dependencies - Dependency array to compare shallowly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useShallowEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs an isomorphic effect with shallow comparison of dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Similar to useIsomorphicEffect (useLayoutEffect on client, useEffect on server),
|
|
6
|
+
* but uses shallow equality comparison for the dependency array instead of reference
|
|
7
|
+
* equality. This is useful when your dependencies are objects or arrays that may
|
|
8
|
+
* have the same content but different references.
|
|
9
|
+
*
|
|
10
|
+
* @param effect - The effect function to run.
|
|
11
|
+
* @param dependencies - Dependency array to compare shallowly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useShallowIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Runs a layout effect with shallow comparison of dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Similar to React's useLayoutEffect, but uses shallow equality comparison for the
|
|
6
|
+
* dependency array instead of reference equality. This is useful when your
|
|
7
|
+
* dependencies are objects or arrays that may have the same content but
|
|
8
|
+
* different references.
|
|
9
|
+
*
|
|
10
|
+
* @param effect - The effect function to run synchronously after DOM mutations.
|
|
11
|
+
* @param dependencies - Dependency array to compare shallowly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useShallowLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes a value with shallow comparison of dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Similar to React's useMemo, but uses shallow equality comparison for the
|
|
6
|
+
* dependency array instead of reference equality. This is useful when your
|
|
7
|
+
* dependencies are objects or arrays that may have the same content but
|
|
8
|
+
* different references.
|
|
9
|
+
*
|
|
10
|
+
* @param factory - Function that returns the value to memoize.
|
|
11
|
+
* @param dependencies - Dependency array to compare shallowly.
|
|
12
|
+
* @returns The memoized value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useShallowMemo<T>(factory: () => T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a singleton value that persists across renders and is initialized only once.
|
|
4
|
+
* The initializer function is called only on the first render.
|
|
5
|
+
*
|
|
6
|
+
* @param initializer - Function that creates the singleton value.
|
|
7
|
+
* @returns A ref object containing the singleton value.
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function Component() {
|
|
11
|
+
* const emitter = useSingleton(() => new EventEmitter());
|
|
12
|
+
* const id = useSingleton(() => Math.random());
|
|
13
|
+
*
|
|
14
|
+
* // emitter.current and id.current are stable across renders
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function useSingleton<T>(initializer: () => T): RefObject<T>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ViewportSize {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Tracks the current viewport dimensions (window.innerWidth/innerHeight).
|
|
7
|
+
* Automatically updates on window resize and orientation change events.
|
|
8
|
+
* Uses requestAnimationFrame to batch updates and prevent excessive re-renders.
|
|
9
|
+
*
|
|
10
|
+
* @returns Current viewport size object with width and height.
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function Component() {
|
|
14
|
+
* const { width, height } = useViewportSize();
|
|
15
|
+
*
|
|
16
|
+
* return <div>Viewport: {width}x{height}</div>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function useViewportSize(): ViewportSize;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
2
|
import { MaybeArray } from '@vef-framework/shared';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Interface for items that have permission requirements.
|
|
5
5
|
*/
|
|
6
6
|
export interface PermissionAware {
|
|
7
7
|
/**
|
|
@@ -9,14 +9,14 @@ export interface PermissionAware {
|
|
|
9
9
|
*/
|
|
10
10
|
permTokens?: MaybeArray<string>;
|
|
11
11
|
/**
|
|
12
|
-
* The permission check mode.
|
|
12
|
+
* The permission check mode (default: "any").
|
|
13
13
|
*/
|
|
14
14
|
checkMode?: PermissionCheckMode;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Hook to filter items based on user permissions.
|
|
18
18
|
*
|
|
19
|
-
* @param items - The items to filter.
|
|
20
|
-
* @returns The filtered items.
|
|
19
|
+
* @param items - The items to filter based on permissions.
|
|
20
|
+
* @returns The filtered items that the user is authorized to access.
|
|
21
21
|
*/
|
|
22
22
|
export declare function useAuthorizedItems<T extends PermissionAware>(items: T[]): T[];
|