@vef-framework/hooks 2.0.10 → 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.
Files changed (111) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/lib.cjs +1 -1
  3. package/dist/cjs/use-authorized-items/index.cjs +1 -1
  4. package/dist/cjs/use-breakpoints/index.cjs +1 -1
  5. package/dist/cjs/use-check-permission/index.cjs +1 -1
  6. package/dist/cjs/use-data-dict-query/index.cjs +1 -1
  7. package/dist/cjs/use-data-options/index.cjs +1 -1
  8. package/dist/cjs/use-deep-callback/index.cjs +1 -1
  9. package/dist/cjs/use-deep-compare/index.cjs +1 -1
  10. package/dist/cjs/use-deep-effect/index.cjs +1 -1
  11. package/dist/cjs/use-deep-isomorphic-effect/index.cjs +1 -1
  12. package/dist/cjs/use-deep-layout-effect/index.cjs +1 -1
  13. package/dist/cjs/use-deep-memo/index.cjs +1 -1
  14. package/dist/cjs/use-document-event/index.cjs +1 -1
  15. package/dist/cjs/use-emitter-event/index.cjs +1 -1
  16. package/dist/cjs/use-has-fetching/index.cjs +1 -1
  17. package/dist/cjs/use-has-mutating/index.cjs +1 -1
  18. package/dist/cjs/use-is-authorized/index.cjs +1 -1
  19. package/dist/cjs/use-latest/index.cjs +1 -1
  20. package/dist/cjs/use-raf-state/index.cjs +1 -1
  21. package/dist/cjs/use-shallow-callback/index.cjs +1 -1
  22. package/dist/cjs/use-shallow-compare/index.cjs +1 -1
  23. package/dist/cjs/use-shallow-effect/index.cjs +1 -1
  24. package/dist/cjs/use-shallow-isomorphic-effect/index.cjs +1 -1
  25. package/dist/cjs/use-shallow-layout-effect/index.cjs +1 -1
  26. package/dist/cjs/use-shallow-memo/index.cjs +1 -1
  27. package/dist/cjs/use-singleton/index.cjs +1 -1
  28. package/dist/cjs/use-viewport-size/index.cjs +1 -0
  29. package/dist/es/index.js +29 -85
  30. package/dist/es/lib.js +14 -60
  31. package/dist/es/use-authorized-items/index.js +11 -14
  32. package/dist/es/use-breakpoints/index.js +47 -53
  33. package/dist/es/use-check-permission/index.js +8 -11
  34. package/dist/es/use-data-dict-query/index.js +21 -25
  35. package/dist/es/use-data-options/index.js +46 -78
  36. package/dist/es/use-deep-callback/index.js +8 -7
  37. package/dist/es/use-deep-compare/index.js +15 -19
  38. package/dist/es/use-deep-effect/index.js +8 -7
  39. package/dist/es/use-deep-isomorphic-effect/index.js +8 -8
  40. package/dist/es/use-deep-layout-effect/index.js +7 -6
  41. package/dist/es/use-deep-memo/index.js +8 -7
  42. package/dist/es/use-document-event/index.js +20 -15
  43. package/dist/es/use-emitter-event/index.js +11 -15
  44. package/dist/es/use-has-fetching/index.js +11 -10
  45. package/dist/es/use-has-mutating/index.js +10 -9
  46. package/dist/es/use-is-authorized/index.js +8 -11
  47. package/dist/es/use-latest/index.js +7 -6
  48. package/dist/es/use-raf-state/index.js +14 -13
  49. package/dist/es/use-shallow-callback/index.js +8 -7
  50. package/dist/es/use-shallow-compare/index.js +15 -19
  51. package/dist/es/use-shallow-effect/index.js +8 -7
  52. package/dist/es/use-shallow-isomorphic-effect/index.js +8 -8
  53. package/dist/es/use-shallow-layout-effect/index.js +8 -7
  54. package/dist/es/use-shallow-memo/index.js +8 -7
  55. package/dist/es/use-singleton/index.js +7 -6
  56. package/dist/es/use-viewport-size/index.js +34 -0
  57. package/dist/types/index.d.ts +3 -2
  58. package/dist/types/lib.d.ts +1 -0
  59. package/dist/types/src/index.d.ts +27 -0
  60. package/dist/types/src/lib.d.ts +7 -0
  61. package/dist/types/src/use-authorized-items/index.d.ts +22 -0
  62. package/dist/types/src/use-breakpoints/index.d.ts +55 -0
  63. package/dist/types/src/use-check-permission/index.d.ts +8 -0
  64. package/dist/types/src/use-data-dict-query/index.d.ts +15 -0
  65. package/dist/types/src/use-data-options/index.d.ts +86 -0
  66. package/dist/types/src/use-deep-callback/index.d.ts +11 -0
  67. package/dist/types/src/use-deep-compare/index.d.ts +9 -0
  68. package/dist/types/src/use-deep-effect/index.d.ts +10 -0
  69. package/dist/types/src/use-deep-isomorphic-effect/index.d.ts +11 -0
  70. package/dist/types/src/use-deep-layout-effect/index.d.ts +10 -0
  71. package/dist/types/src/use-deep-memo/index.d.ts +11 -0
  72. package/dist/types/src/use-document-event/index.d.ts +19 -0
  73. package/dist/types/src/use-emitter-event/index.d.ts +17 -0
  74. package/dist/types/src/use-has-fetching/index.d.ts +8 -0
  75. package/dist/types/src/use-has-mutating/index.d.ts +7 -0
  76. package/dist/types/src/use-is-authorized/index.d.ts +10 -0
  77. package/dist/types/src/use-latest/index.d.ts +21 -0
  78. package/dist/types/src/use-raf-state/index.d.ts +23 -0
  79. package/dist/types/src/use-shallow-callback/index.d.ts +14 -0
  80. package/dist/types/src/use-shallow-compare/index.d.ts +13 -0
  81. package/dist/types/src/use-shallow-effect/index.d.ts +13 -0
  82. package/dist/types/src/use-shallow-isomorphic-effect/index.d.ts +13 -0
  83. package/dist/types/src/use-shallow-layout-effect/index.d.ts +13 -0
  84. package/dist/types/src/use-shallow-memo/index.d.ts +14 -0
  85. package/dist/types/src/use-singleton/index.d.ts +18 -0
  86. package/dist/types/src/use-viewport-size/index.d.ts +20 -0
  87. package/dist/types/use-authorized-items/index.d.ts +5 -5
  88. package/dist/types/use-breakpoints/index.d.ts +15 -7
  89. package/dist/types/use-check-permission/index.d.ts +2 -2
  90. package/dist/types/use-data-dict-query/index.d.ts +1 -1
  91. package/dist/types/use-data-options/index.d.ts +8 -2
  92. package/dist/types/use-deep-callback/index.d.ts +7 -5
  93. package/dist/types/use-deep-compare/index.d.ts +4 -3
  94. package/dist/types/use-deep-effect/index.d.ts +5 -4
  95. package/dist/types/use-deep-isomorphic-effect/index.d.ts +6 -4
  96. package/dist/types/use-deep-layout-effect/index.d.ts +5 -4
  97. package/dist/types/use-deep-memo/index.d.ts +6 -4
  98. package/dist/types/use-document-event/index.d.ts +15 -4
  99. package/dist/types/use-emitter-event/index.d.ts +13 -5
  100. package/dist/types/use-is-authorized/index.d.ts +2 -2
  101. package/dist/types/use-latest/index.d.ts +18 -5
  102. package/dist/types/use-raf-state/index.d.ts +18 -3
  103. package/dist/types/use-shallow-callback/index.d.ts +10 -5
  104. package/dist/types/use-shallow-compare/index.d.ts +8 -3
  105. package/dist/types/use-shallow-effect/index.d.ts +8 -4
  106. package/dist/types/use-shallow-isomorphic-effect/index.d.ts +8 -4
  107. package/dist/types/use-shallow-layout-effect/index.d.ts +8 -4
  108. package/dist/types/use-shallow-memo/index.d.ts +8 -3
  109. package/dist/types/use-singleton/index.d.ts +14 -7
  110. package/dist/types/use-viewport-size/index.d.ts +20 -0
  111. package/package.json +8 -7
@@ -29,19 +29,27 @@ export interface UseBreakpointsOptions<T extends string = string> {
29
29
  /**
30
30
  * Get initial value in effect instead of on mount
31
31
  * This helps avoid hydration mismatches in SSR
32
+ *
32
33
  * @default false
33
34
  */
34
35
  getInitialValueInEffect?: boolean;
35
36
  }
36
37
  /**
37
- * Hook to track active breakpoints based on window width
38
- *
39
- * @param breakpoints - Breakpoint configuration object
40
- * @param options - Hook options
41
- * @returns Current breakpoint information
38
+ * Tracks active responsive breakpoints based on window width using media queries.
39
+ * Returns the current breakpoint and all matching breakpoints.
42
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.
43
44
  * @remarks
44
- * **Important**: Since this hook uses `min-width` media queries, you should include
45
- * a breakpoint starting from 0 to ensure all viewport sizes are covered.
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
+ * ```
46
54
  */
47
55
  export declare function useBreakpoints<T extends string>(breakpoints: Breakpoints<T>, options?: UseBreakpointsOptions<T>): UseBreakpointsResult<T>;
@@ -1,8 +1,8 @@
1
1
  import { PermissionCheckMode } from '@vef-framework/core';
2
2
  import { MaybeArray } from '@vef-framework/shared';
3
3
  /**
4
- * The use check permission hook.
4
+ * Hook that returns a function to check permissions imperatively.
5
5
  *
6
- * @returns The check permission function.
6
+ * @returns A function that checks if the user has the specified permissions.
7
7
  */
8
8
  export declare function useCheckPermission(): (permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode) => boolean;
@@ -1,6 +1,6 @@
1
1
  import { DataOption, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
2
2
  import { Except } from '@vef-framework/shared';
3
- export type UseDataDictQueryOptions<TData = DataOption> = Except<UseQueryOptions<DataOption[], TData[]>, "queryFn" | "queryKey" | "queryHash" | "queryKeyHashFn"> & {
3
+ export type UseDataDictQueryOptions<TData = DataOption> = Except<UseQueryOptions<DataOption[], TData[], string>, "queryFn" | "queryKey" | "queryHash" | "queryKeyHashFn"> & {
4
4
  dataDictKey?: string;
5
5
  onFetch?: (data: TData[]) => void;
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import { DataOption, DataOptionWithPinyin, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
2
- import { Key, MaybeUndefined, Prettify } from '@vef-framework/shared';
2
+ import { Key, MaybeUndefined, Simplify } from '@vef-framework/shared';
3
3
  /**
4
4
  * Field extractor - can be a string path (e.g., "user.name") or a function
5
5
  */
@@ -10,26 +10,31 @@ export type FieldExtractor<TData, TValue> = string | ((item: TData) => TValue);
10
10
  export interface DataOptionsFieldMapping<TData = unknown> {
11
11
  /**
12
12
  * Field mapping for label
13
+ *
13
14
  * @default "label"
14
15
  */
15
16
  labelKey?: FieldExtractor<TData, string>;
16
17
  /**
17
18
  * Field mapping for value
19
+ *
18
20
  * @default "value"
19
21
  */
20
22
  valueKey?: FieldExtractor<TData, Key>;
21
23
  /**
22
24
  * Field mapping for disabled
25
+ *
23
26
  * @default "disabled"
24
27
  */
25
28
  disabledKey?: FieldExtractor<TData, MaybeUndefined<boolean>>;
26
29
  /**
27
30
  * Field mapping for description
31
+ *
28
32
  * @default "description"
29
33
  */
30
34
  descriptionKey?: FieldExtractor<TData, MaybeUndefined<string>>;
31
35
  /**
32
36
  * Field mapping for children
37
+ *
33
38
  * @default "children"
34
39
  */
35
40
  childrenKey?: FieldExtractor<TData, MaybeUndefined<TData[]>>;
@@ -67,13 +72,14 @@ export type UseDataOptionsQueryOptions<TQueryFnData = unknown, TData = TQueryFnD
67
72
  /**
68
73
  * Return type for useDataOptionsQuery hook
69
74
  */
70
- export type UseDataOptionsQueryResult<TData, TOption> = Prettify<Omit<UseQueryResult<TData[]>, "data"> & {
75
+ export type UseDataOptionsQueryResult<TData, TOption> = Simplify<Omit<UseQueryResult<TData[]>, "data"> & {
71
76
  options: TOption[];
72
77
  }>;
73
78
  export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(config: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams>): UseDataOptionsQueryResult<TData, DataOption<TData>>;
74
79
  export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(options: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams> & {
75
80
  /**
76
81
  * Whether to add pinyin fields for label and description
82
+ *
77
83
  * @default false
78
84
  */
79
85
  withPinyin: boolean;
@@ -1,9 +1,11 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the deep callback of the callback
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.
4
6
  *
5
- * @param callback - The callback to memo.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The memoized callback.
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.
8
10
  */
9
- export declare function useDeepCallback<T extends Function>(callback: T, dependencies: DependencyList): T;
11
+ export declare function useDeepCallback<T extends (...args: any[]) => any>(callback: T, dependencies: DependencyList): T;
@@ -1,8 +1,9 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the deep compare of the dependencies
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.
4
5
  *
5
- * @param dependencies - The dependencies to compare.
6
- * @returns The signal of the dependencies.
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.
7
8
  */
8
9
  export declare function useDeepCompare(dependencies?: DependencyList): readonly [number];
@@ -1,9 +1,10 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the deep effect of the effect
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.
4
6
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
7
+ * @param effect - The effect callback to execute.
8
+ * @param dependencies - The dependency array to deeply compare for changes.
8
9
  */
9
10
  export declare function useDeepEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,11 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the deep isomorphic effect of the effect
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.
4
7
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
8
+ * @param effect - The effect callback to execute.
9
+ * @param dependencies - The dependency array to deeply compare for changes.
8
10
  */
9
11
  export declare function useDeepIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,10 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the deep layout effect of the effect
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.
4
6
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
7
+ * @param effect - The effect callback to execute synchronously after DOM mutations.
8
+ * @param dependencies - The dependency array to deeply compare for changes.
8
9
  */
9
10
  export declare function useDeepLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,11 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the deep memo of the factory
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.
4
6
  *
5
- * @param factory - The factory to memo.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The memoized value.
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.
8
10
  */
9
11
  export declare function useDeepMemo<T>(factory: () => T, dependencies: DependencyList): T;
@@ -1,8 +1,19 @@
1
1
  /**
2
- * Hook to listen for document events.
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.
3
4
  *
4
- * @param type - The type of event to listen for.
5
- * @param listener - The function to call when the event is triggered.
6
- * @param options - The options to pass to the event listener.
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
+ * ```
7
18
  */
8
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;
@@ -1,9 +1,17 @@
1
1
  import { EventHandler, EventType, EventEmitter } from '@vef-framework/shared';
2
2
  /**
3
- * A hook to listen to an event from an EventEmitter.
3
+ * Subscribes to an EventEmitter event with automatic cleanup.
4
4
  *
5
- * @param emitter - The EventEmitter instance to listen to.
6
- * @param eventType - The type of event to listen to.
7
- * @param eventListener - The function to call when the event is emitted.
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
+ * ```
8
16
  */
9
- export declare function useEmitterEvent<TEvents extends Record<EventType, unknown>>(emitter: EventEmitter<TEvents>, eventType: keyof TEvents, eventListener: EventHandler<TEvents[keyof TEvents]>): void;
17
+ export declare function useEmitterEvent<TEvents extends Record<EventType, any>>(emitter: EventEmitter<TEvents>, eventType: keyof TEvents, eventListener: EventHandler<TEvents[keyof TEvents]>): void;
@@ -1,10 +1,10 @@
1
1
  import { PermissionCheckMode } from '@vef-framework/core';
2
2
  import { MaybeArray } from '@vef-framework/shared';
3
3
  /**
4
- * The use is authorized hook.
4
+ * Hook to check if the user is authorized based on permission tokens.
5
5
  *
6
6
  * @param permTokens - The permission tokens to check.
7
- * @param checkMode - The check mode to use.
7
+ * @param checkMode - The check mode to use (default: "any").
8
8
  * @returns Whether the user is authorized to access the resource identified by the permission token.
9
9
  */
10
10
  export declare function useIsAuthorized(permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode): boolean;
@@ -1,8 +1,21 @@
1
- import { RefObject } from 'react';
1
+ import { MutableRefObject } from 'react';
2
2
  /**
3
- * Use the latest value of the ref
3
+ * Returns a ref that always contains the latest value.
4
+ * Useful for accessing current props/state in callbacks without re-creating them.
4
5
  *
5
- * @param value - The value to use.
6
- * @returns The latest value of the ref.
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
+ * ```
7
20
  */
8
- export declare function useLatest<T>(value: T): RefObject<T>;
21
+ export declare function useLatest<T>(value: T): MutableRefObject<T>;
@@ -1,8 +1,23 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  /**
3
- * A hook to use the request animation frame state.
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.
4
5
  *
5
- * @param initialState - The initial state.
6
- * @returns The state and the set state function.
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
+ * ```
7
22
  */
8
23
  export declare function useRafState<T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>];
@@ -1,9 +1,14 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the shallow callback of the callback
3
+ * Memoizes a callback function with shallow comparison of dependencies.
4
4
  *
5
- * @param callback - The callback to memo.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The memoized callback.
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.
8
13
  */
9
- export declare function useShallowCallback<T extends Function>(callback: T, dependencies: DependencyList): T;
14
+ export declare function useShallowCallback<T extends (...args: any[]) => any>(callback: T, dependencies: DependencyList): T;
@@ -1,8 +1,13 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the shallow compare of the dependencies
3
+ * Performs shallow comparison of dependency arrays for React hooks.
4
+ * Returns a stable reference that only changes when dependencies are not shallowly equal.
4
5
  *
5
- * @param dependencies - The dependencies to compare.
6
- * @returns The signal of the dependencies.
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.
7
12
  */
8
13
  export declare function useShallowCompare(dependencies?: DependencyList): readonly [number];
@@ -1,9 +1,13 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the shallow effect of the effect
3
+ * Runs an effect with shallow comparison of dependencies.
4
4
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
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.
8
12
  */
9
13
  export declare function useShallowEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,13 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the shallow isomorphic effect of the effect
3
+ * Runs an isomorphic effect with shallow comparison of dependencies.
4
4
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
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.
8
12
  */
9
13
  export declare function useShallowIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,13 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  /**
3
- * Use the shallow layout effect of the effect
3
+ * Runs a layout effect with shallow comparison of dependencies.
4
4
  *
5
- * @param effect - The effect to run.
6
- * @param dependencies - The dependencies to compare.
7
- * @returns The effect.
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.
8
12
  */
9
13
  export declare function useShallowLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
@@ -1,9 +1,14 @@
1
1
  import { DependencyList } from 'react';
2
2
  /**
3
- * Use the shallow memo of the factory
3
+ * Memoizes a value with shallow comparison of dependencies.
4
4
  *
5
- * @param factory - The factory to memo.
6
- * @param dependencies - The dependencies to compare.
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.
7
12
  * @returns The memoized value.
8
13
  */
9
14
  export declare function useShallowMemo<T>(factory: () => T, dependencies: DependencyList): T;
@@ -1,11 +1,18 @@
1
1
  import { RefObject } from 'react';
2
- export interface SingletonRefObject<T> extends RefObject<T> {
3
- readonly current: T;
4
- }
5
2
  /**
6
- * A hook that returns a singleton ref object.
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.
7
5
  *
8
- * @param initializer - The initializer for the singleton.
9
- * @returns The singleton ref object.
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
+ * ```
10
17
  */
11
- export declare function useSingleton<T>(initializer: () => T): SingletonRefObject<T>;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vef-framework/hooks",
3
3
  "type": "module",
4
- "version": "2.0.10",
4
+ "version": "2.1.0",
5
5
  "private": false,
6
6
  "description": "Hooks for VEF framework",
7
7
  "author": {
@@ -20,7 +20,7 @@
20
20
  "sideEffects": false,
21
21
  "exports": {
22
22
  ".": {
23
- "source": "./src/index.ts",
23
+ "vef": "./src/index.ts",
24
24
  "import": {
25
25
  "types": "./dist/types/index.d.ts",
26
26
  "default": "./dist/es/index.js"
@@ -48,13 +48,14 @@
48
48
  "react": ">=19"
49
49
  },
50
50
  "dependencies": {
51
- "@mantine/hooks": "^8.3.9",
52
- "react-hotkeys-hook": "^5.2.1",
53
- "@vef-framework/core": "2.0.10",
54
- "@vef-framework/shared": "2.0.10"
51
+ "@ai-sdk/react": "3.0.140",
52
+ "@mantine/hooks": "^8.3.18",
53
+ "react-hotkeys-hook": "^5.2.4",
54
+ "@vef-framework/shared": "2.1.0",
55
+ "@vef-framework/core": "2.1.0"
55
56
  },
56
57
  "devDependencies": {
57
- "react": "^19.2.0"
58
+ "react": "^19.2.4"
58
59
  },
59
60
  "scripts": {
60
61
  "clean": "rimraf dist",