@vef-framework/hooks 1.0.5

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 (46) hide show
  1. package/README.md +25 -0
  2. package/dist/index.d.ts +21 -0
  3. package/dist/index.js +3 -0
  4. package/dist/lib.d.ts +2 -0
  5. package/dist/lib.js +3 -0
  6. package/dist/use-authorized-items.d.ts +21 -0
  7. package/dist/use-authorized-items.js +3 -0
  8. package/dist/use-color-tokens.d.ts +19 -0
  9. package/dist/use-color-tokens.js +3 -0
  10. package/dist/use-computed-action-buttons.d.ts +36 -0
  11. package/dist/use-computed-action-buttons.js +3 -0
  12. package/dist/use-computed-options.d.ts +91 -0
  13. package/dist/use-computed-options.js +3 -0
  14. package/dist/use-context-disabled.d.ts +6 -0
  15. package/dist/use-context-disabled.js +3 -0
  16. package/dist/use-data-query.d.ts +10 -0
  17. package/dist/use-data-query.js +3 -0
  18. package/dist/use-deep-compare-callback.d.ts +10 -0
  19. package/dist/use-deep-compare-callback.js +3 -0
  20. package/dist/use-deep-compare-memo.d.ts +10 -0
  21. package/dist/use-deep-compare-memo.js +3 -0
  22. package/dist/use-fallback-options.d.ts +35 -0
  23. package/dist/use-fallback-options.js +3 -0
  24. package/dist/use-gap-size-normalizer.d.ts +8 -0
  25. package/dist/use-gap-size-normalizer.js +3 -0
  26. package/dist/use-normalized-gap-size.d.ts +9 -0
  27. package/dist/use-normalized-gap-size.js +3 -0
  28. package/dist/use-normalized-menu-items.d.ts +9 -0
  29. package/dist/use-normalized-menu-items.js +3 -0
  30. package/dist/use-normalized-options.d.ts +34 -0
  31. package/dist/use-normalized-options.js +3 -0
  32. package/dist/use-option-filter.d.ts +8 -0
  33. package/dist/use-option-filter.js +3 -0
  34. package/dist/use-remote-filter.d.ts +10 -0
  35. package/dist/use-remote-filter.js +3 -0
  36. package/dist/use-shallow-compare-callback.d.ts +10 -0
  37. package/dist/use-shallow-compare-callback.js +3 -0
  38. package/dist/use-shallow-compare-memo.d.ts +10 -0
  39. package/dist/use-shallow-compare-memo.js +3 -0
  40. package/dist/use-singleton.d.ts +7 -0
  41. package/dist/use-singleton.js +3 -0
  42. package/dist/use-theme-tokens.d.ts +6 -0
  43. package/dist/use-theme-tokens.js +3 -0
  44. package/dist/use-window-size.d.ts +17 -0
  45. package/dist/use-window-size.js +3 -0
  46. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # The Shared foundations of VEF Framework
2
+
3
+ VEF framework designed by Venus is built on top of React, and it provides a set of components that are essential for building a modern web application. These components are designed to be highly customizable and reusable, allowing developers to build complex and dynamic user interfaces with ease.
4
+
5
+ ## Installation
6
+
7
+ To install the VEF framework hooks foundations, you can use pnpm or any other package manager you like:
8
+
9
+ ```bash
10
+ pnpm add @vef-framework/hooks
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ To use the VEF framework hooks foundations in your project, you can import them from the package, for example:
16
+
17
+ ```ts
18
+ import { xxx } from "@vef-framework/hooks";
19
+
20
+ const result = xxx();
21
+ ```
22
+
23
+ ## Documentation
24
+
25
+ For more details on how to use the VEF framework hooks foundations, please refer to the [official documentation](https://vef.ilxqx.com/docs).
@@ -0,0 +1,21 @@
1
+ export * from "./lib";
2
+ export * from "./use-authorized-items";
3
+ export * from "./use-color-tokens";
4
+ export * from "./use-computed-action-buttons";
5
+ export * from "./use-computed-options";
6
+ export * from "./use-context-disabled";
7
+ export * from "./use-data-query";
8
+ export * from "./use-deep-compare-callback";
9
+ export * from "./use-deep-compare-memo";
10
+ export * from "./use-fallback-options";
11
+ export * from "./use-gap-size-normalizer";
12
+ export * from "./use-normalized-gap-size";
13
+ export * from "./use-normalized-menu-items";
14
+ export * from "./use-normalized-options";
15
+ export * from "./use-option-filter";
16
+ export * from "./use-remote-filter";
17
+ export * from "./use-shallow-compare-callback";
18
+ export * from "./use-shallow-compare-memo";
19
+ export * from "./use-singleton";
20
+ export * from "./use-theme-tokens";
21
+ export * from "./use-window-size";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import"./lib.js";export{useAuthorizedItems}from"./use-authorized-items.js";export{useColorTokens,useDefaultColorTokens,useSemanticColorTokens}from"./use-color-tokens.js";export{useComputedActionButtons}from"./use-computed-action-buttons.js";export{useComputedOptions}from"./use-computed-options.js";export{DisabledContextProvider,useContextDisabled}from"./use-context-disabled.js";export{useDataQuery}from"./use-data-query.js";export{useDeepCompareCallback}from"./use-deep-compare-callback.js";export{useDeepCompareMemo}from"./use-deep-compare-memo.js";export{useFallbackOptions}from"./use-fallback-options.js";export{useGapSizeNormalizer}from"./use-gap-size-normalizer.js";export{useNormalizedGapSize}from"./use-normalized-gap-size.js";export{useNormalizedMenuItems}from"./use-normalized-menu-items.js";export{useNormalizedDataOptions}from"./use-normalized-options.js";export{useOptionFilter}from"./use-option-filter.js";export{useRemoteFilter}from"./use-remote-filter.js";export{useShallowCompareCallback}from"./use-shallow-compare-callback.js";export{useShallowCompareMemo}from"./use-shallow-compare-memo.js";export{useSingleton}from"./use-singleton.js";export{useThemeTokens}from"./use-theme-tokens.js";export{useWindowSize}from"./use-window-size.js";export{useDeepCompareEffect,useDeepCompareLayoutEffect,useMount,useSize,useUnmount,useUpdate,useUpdateEffect,useUpdateLayoutEffect}from"ahooks";
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
package/dist/lib.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { useDeepCompareEffect, useDeepCompareLayoutEffect, useMount, useSize, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect } from "ahooks";
2
+ export { useDeepCompareEffect, useDeepCompareLayoutEffect, useMount, useSize, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, };
package/dist/lib.js ADDED
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ export{useDeepCompareEffect,useDeepCompareLayoutEffect,useMount,useSize,useUnmount,useUpdate,useUpdateEffect,useUpdateLayoutEffect}from"ahooks";
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,21 @@
1
+ import type { PermissionCheckMode } from "@vef-framework/shared";
2
+ /**
3
+ * The permission aware interface.
4
+ */
5
+ export interface PermissionAware {
6
+ /**
7
+ * The permission tokens.
8
+ */
9
+ permissions?: string[];
10
+ /**
11
+ * The permission check mode.
12
+ */
13
+ checkMode?: PermissionCheckMode;
14
+ }
15
+ /**
16
+ * The use authorized items hook.
17
+ *
18
+ * @param items - The items to filter.
19
+ * @returns The filtered items.
20
+ */
21
+ export declare function useAuthorizedItems<T extends PermissionAware>(items: T[]): T[];
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useAuthContext as r}from"@vef-framework/core";import{useMemo as e}from"react";function o(o){const{checkPermission:n}=r();return e((()=>o?.filter((r=>{const e=r.permissions;if(!e)return!0;return"any"===(r.checkMode??"any")?e.some((r=>n(r))):e.every((r=>n(r)))}))),[o,n])}export{o as useAuthorizedItems};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,19 @@
1
+ import type { ColorType, LiteralUnion } from "@vef-framework/shared";
2
+ /**
3
+ * Get default color tokens
4
+ *
5
+ * @returns Default color tokens
6
+ */
7
+ export declare function useDefaultColorTokens(): Map<LiteralUnion<"blue" | "purple" | "cyan" | "green" | "magenta" | "pink" | "red" | "orange" | "yellow" | "volcano" | "geekblue" | "gold" | "lime", string>, string>;
8
+ /**
9
+ * Get semantic color tokens
10
+ *
11
+ * @returns Semantic color tokens
12
+ */
13
+ export declare function useSemanticColorTokens(): Map<"primary" | "info" | "success" | "warning" | "error", string>;
14
+ /**
15
+ * Get color tokens
16
+ *
17
+ * @returns Color tokens
18
+ */
19
+ export declare function useColorTokens(): Map<LiteralUnion<ColorType, string>, string>;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{defaultColorTypes as e,semanticColorTypes as r,capitalize as t}from"@vef-framework/shared";import{useMemo as o}from"react";import{useThemeTokens as n}from"./use-theme-tokens.js";function c(){const r=n();return o((()=>e.reduce(((e,t)=>(e.set(t,r[t]),e)),new Map)),[r])}function s(){const e=n();return o((()=>r.reduce(((r,o)=>(r.set(o,e[`color${t(o)}`]),r)),new Map)),[e])}function u(){const e=c(),r=s();return o((()=>new Map([...e,...r])),[e,r])}export{u as useColorTokens,c as useDefaultColorTokens,s as useSemanticColorTokens};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,36 @@
1
+ import type { Except } from "@vef-framework/shared";
2
+ import { type ActionButton, type ConfirmationMode } from "@vef-framework/shared";
3
+ import { type ReactNode } from "react";
4
+ /**
5
+ * The computed action button.
6
+ */
7
+ export interface ComputedActionButton<T> extends Except<ActionButton<T>, "show" | "disabled" | "requireConfirmation" | "confirmationMode" | "confirmationTitle" | "confirmationContent" | "permissions" | "checkMode"> {
8
+ /**
9
+ * Whether the action button is disabled.
10
+ */
11
+ disabled: boolean;
12
+ /**
13
+ * Whether the action button requires confirmation.
14
+ */
15
+ requireConfirmation: boolean;
16
+ /**
17
+ * The confirmation mode of the action button.
18
+ */
19
+ confirmationMode: ConfirmationMode;
20
+ /**
21
+ * The confirmation title of the action button.
22
+ */
23
+ confirmationTitle: ReactNode;
24
+ /**
25
+ * The confirmation content of the action button.
26
+ */
27
+ confirmationContent: ReactNode;
28
+ }
29
+ /**
30
+ * The hook to compute the action buttons.
31
+ *
32
+ * @param buttons - The action buttons.
33
+ * @param context - The context.
34
+ * @returns The computed action buttons.
35
+ */
36
+ export declare function useComputedActionButtons<T>(buttons: Array<ActionButton<T>>, context: T): ComputedActionButton<T>[];
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{isFunction as o,defaultMessageTitle as i}from"@vef-framework/shared";import{useMemo as n}from"react";function r(r,t){return n((()=>r.filter((i=>{const{show:n}=i;return o(n)?n(t):n??!0})).map((n=>{const{disabled:r,requireConfirmation:e,confirmationMode:a,confirmationTitle:m,confirmationContent:f,...c}=n,l={...c,disabled:o(r)?r(t):r??!1,requireConfirmation:o(e)?e(t):e??!1,confirmationMode:o(a)?a(t):a??"simple",confirmationTitle:o(m)?m(t):m??i,confirmationContent:o(f)?f(t):f??`确定要${c.label}吗?`};return l.requireConfirmation&&!l.confirmationMode&&(l.confirmationMode="simple"),l.requireConfirmation&&!l.confirmationTitle&&(l.confirmationTitle=i),l.requireConfirmation&&!l.confirmationContent&&(l.confirmationContent=`确定要${l.label}吗?`),l}))),[r,t])}export{r as useComputedActionButtons};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,91 @@
1
+ import type { DataOption, DataOptionConfig, IdValue, Mapper, MaybePromise, ObjectType, PureDataOption, QueryApi, QueryConfig, QueryParamsWithKeyword, QueryParamsWithValues, StringKey } from "@vef-framework/shared";
2
+ import type { EmptyObject } from "@vef-framework/shared";
3
+ /**
4
+ * The config of the useComputedOptions hook.
5
+ */
6
+ export interface UseComputedOptionsConfig<T extends DataOption<T> = PureDataOption, P extends ObjectType = EmptyObject, R = T[], KK extends string = "keyword", VK extends string = "ids", FP extends ObjectType = EmptyObject> extends QueryConfig<T[], QueryParamsWithKeyword<P, KK>, R>, DataOptionConfig<StringKey<T>> {
7
+ /**
8
+ * Whether to allow filter.
9
+ */
10
+ filterable?: boolean;
11
+ /**
12
+ * Whether to filter from remote.
13
+ */
14
+ filterFromRemote?: boolean;
15
+ /**
16
+ * The parameter name of keyword.
17
+ * Only works when `filterFromRemote` is true.
18
+ */
19
+ keywordKey?: KK;
20
+ /**
21
+ * The parameter name of values.
22
+ */
23
+ valuesKey?: VK;
24
+ /**
25
+ * The API of fallback options.
26
+ */
27
+ fallbackOptionsApi?: Readonly<QueryApi<QueryParamsWithValues<FP>, T[]>>;
28
+ /**
29
+ * The API params of fallback options.
30
+ */
31
+ fallbackOptionsApiParams?: FP;
32
+ /**
33
+ * The function to resolve fallback options.
34
+ */
35
+ resolveFallbackOptions?: Mapper<IdValue[], MaybePromise<T[]>>;
36
+ /**
37
+ * Whether the options are grouped.
38
+ */
39
+ isGrouped?: boolean;
40
+ /**
41
+ * The selected option values.
42
+ */
43
+ selectedOptionValues?: IdValue[];
44
+ }
45
+ /**
46
+ * The hook to compute the options.
47
+ */
48
+ export declare function useComputedOptions<T extends DataOption<T> = PureDataOption, P extends ObjectType = EmptyObject, R = T[], KK extends string = "keyword", VK extends string = "ids", FP extends ObjectType = EmptyObject>({ labelField, valueField, descriptionField, childrenField, disabledField, defaultToFirst, filterable, filterFromRemote, keywordKey, valuesKey, fallbackOptionsApi, fallbackOptionsApiParams, resolveFallbackOptions, isGrouped, selectedOptionValues, apiParams, ...queryConfig }: UseComputedOptionsConfig<T, P, R, KK, VK, FP>): {
49
+ onFilterKeywordChange: import("radashi").DebounceFunction<[keyword: string]> | undefined;
50
+ isLoading: boolean;
51
+ normalizedOptions: ({
52
+ [x: string]: any;
53
+ description?: import("react").ReactNode;
54
+ labelText?: string | undefined;
55
+ descriptionText?: string | undefined;
56
+ label: string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | null;
57
+ value: IdValue;
58
+ disabled: boolean;
59
+ } & {
60
+ children?: import("@vef-framework/shared").NormalizedDataOption<PureDataOption>[] | undefined;
61
+ labelPinyin?: string;
62
+ descriptionPinyin?: string;
63
+ } & T)[] | ({
64
+ [x: string]: any;
65
+ description?: import("react").ReactNode;
66
+ labelText?: string | undefined;
67
+ descriptionText?: string | undefined;
68
+ label: string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | null;
69
+ value: IdValue;
70
+ disabled: boolean;
71
+ } & {
72
+ children?: import("@vef-framework/shared").NormalizedDataOption<PureDataOption>[] | undefined;
73
+ labelPinyin?: string;
74
+ descriptionPinyin?: string;
75
+ } & T)[];
76
+ defaultOption: ({
77
+ [x: string]: any;
78
+ description?: import("react").ReactNode;
79
+ labelText?: string | undefined;
80
+ descriptionText?: string | undefined;
81
+ label: string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | null;
82
+ value: IdValue;
83
+ disabled: boolean;
84
+ } & {
85
+ children?: import("@vef-framework/shared").NormalizedDataOption<PureDataOption>[] | undefined;
86
+ labelPinyin?: string;
87
+ descriptionPinyin?: string;
88
+ } & T) | undefined;
89
+ fallbackOptions: T[] | undefined;
90
+ isFallbackOptionsLoading: boolean;
91
+ };
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useDataQuery as e}from"./use-data-query.js";import{useFallbackOptions as i}from"./use-fallback-options.js";import{useNormalizedDataOptions as a}from"./use-normalized-options.js";import{useRemoteFilter as l}from"./use-remote-filter.js";function o({labelField:o,valueField:s,descriptionField:t,childrenField:d,disabledField:r,defaultToFirst:n,filterable:p=!1,filterFromRemote:u=!1,keywordKey:c="keyword",valuesKey:f="ids",fallbackOptionsApi:m,fallbackOptionsApiParams:F,resolveFallbackOptions:b,isGrouped:O=!1,selectedOptionValues:k,apiParams:y,...v}){const[g,P]=l(p&&u,y,c),{data:j,isLoading:A}=e({apiParams:g,...v}),[K,L,h]=a(j??[],{labelField:o,valueField:s,descriptionField:t,childrenField:d,disabledField:r,defaultToFirst:n},{isGrouped:O,parsePinyin:p&&!u,selectedOptionValues:k}),{data:w,isLoading:z}=i(L,{fallbackOptionsApi:m??v.api,fallbackOptionsApiParams:F,valuesKey:f,resolveFallbackOptions:b});return{onFilterKeywordChange:P,isLoading:A,normalizedOptions:K,defaultOption:h,fallbackOptions:w,isFallbackOptionsLoading:z}}export{o as useComputedOptions};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The hook to get the disabled context.
3
+ */
4
+ export declare function useContextDisabled(): boolean;
5
+ declare const DisabledContextProvider: import("react").Provider<boolean>;
6
+ export { DisabledContextProvider, };
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{createContext as r,useContext as o}from"react";const t=r(!1);function n(){return o(t)}const c=t.Provider;export{c as DisabledContextProvider,n as useContextDisabled};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { AnyValue, ObjectType, QueryConfig, QueryResult } from "@vef-framework/shared";
2
+ import type { EmptyObject } from "@vef-framework/shared";
3
+ /**
4
+ * A hook that fetches data from the API, data dictionary or a stub created from data.
5
+ *
6
+ * @param config - The query config
7
+ * @param config.onFetched - The callback function that is called when the data is fetched
8
+ * @returns The query result
9
+ */
10
+ export declare function useDataQuery<D = AnyValue, P extends ObjectType = EmptyObject, R = D>({ onFetched, ...config }: QueryConfig<D, P, R>): QueryResult<D>;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useApiContext as e}from"@vef-framework/core";import{useUnmount as a}from"ahooks";import{isNullish as t,isFunction as r}from"@vef-framework/shared";import{useMemo as i}from"react";function o({onFetched:o,...s}){const{useApiQuery:p,stubQueryApi:c,dataDictionaryQueryApi:u}=e(),[n,m,l]=function({data:e,dataDictionaryKey:a,api:r,apiParams:o,apiEnabled:s,staleTime:p,keepPreviousData:c,placeholderData:u},n,m){return i((()=>t(e)?t(a)?t(r)?[n,[],{keepPreviousData:!0,initialData:[]}]:[r,o,{enabled:s??!0,staleTime:p,keepPreviousData:c,placeholderData:u}]:[m,{...o,key:a},{enabled:s??!0,staleTime:p,keepPreviousData:c,placeholderData:u}]:[n,e,{keepPreviousData:!0,initialData:e}]),[e,a,r,n,m,o,s,p,c,u])}(s,c,u),d=p(n,m,l);a((()=>{Object.is(n,c)&&c.removeQueries(m)}));const{isSuccess:D,data:f,...k}=d,v=i((()=>D&&r(o)?o(f):f),[D,f,o]);return{...k,isSuccess:D,data:v}}export{o as useDataQuery};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { AnyFunction } from "@vef-framework/shared";
2
+ import { type DependencyList } from "react";
3
+ /**
4
+ * A hook that memoizes a callback based on deep comparison of its dependencies.
5
+ *
6
+ * @param callback The callback to be memoized.
7
+ * @param dependencies The dependencies array.
8
+ * @returns The memoized callback.
9
+ */
10
+ export declare function useDeepCompareCallback<T extends AnyFunction>(callback: T, dependencies: DependencyList): T;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useCallback as o}from"react";import{useDeepCompareMemo as r}from"./use-deep-compare-memo.js";function e(e,m){const t=r((()=>m),m);return o(e,t)}export{e as useDeepCompareCallback};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { Provider } from "@vef-framework/shared";
2
+ import { type DependencyList } from "react";
3
+ /**
4
+ * A hook that memoizes a value based on deep comparison of its dependencies.
5
+ *
6
+ * @param factory The factory function that returns the value to be memoized.
7
+ * @param dependencies The dependencies array.
8
+ * @returns The memoized value.
9
+ */
10
+ export declare function useDeepCompareMemo<T>(factory: Provider<T>, dependencies: DependencyList): T;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{isEqual as r}from"@vef-framework/shared";import{useRef as e,useMemo as t}from"react";function n(n,o){const c=e(),u=e(0);var a,f;return void 0!==c.current&&(a=o,f=c.current,a.length===f.length&&a.every(((e,t)=>r(e,f[t]))))||(u.current+=1),c.current=o,t(n,[u.current])}export{n as useDeepCompareMemo};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,35 @@
1
+ import type { Api, DataOption, IdValue, Mapper, MaybePromise, ObjectType, PureDataOption, QueryParamsWithValues } from "@vef-framework/shared";
2
+ import type { EmptyObject } from "@vef-framework/shared";
3
+ /**
4
+ * The config of the use fallback options hook.
5
+ */
6
+ export interface UseFallbackOptionsConfig<T extends DataOption<T> = PureDataOption, P extends ObjectType = EmptyObject, K extends string = "ids"> {
7
+ /**
8
+ * The API of fallback options.
9
+ */
10
+ fallbackOptionsApi?: Api<QueryParamsWithValues<P, K>, T[]>;
11
+ /**
12
+ * The API params of fallback options.
13
+ */
14
+ fallbackOptionsApiParams?: P;
15
+ /**
16
+ * The parameter name of values.
17
+ */
18
+ valuesKey?: K;
19
+ /**
20
+ * The function to resolve fallback options.
21
+ */
22
+ resolveFallbackOptions?: Mapper<IdValue[], MaybePromise<T[]>>;
23
+ }
24
+ /**
25
+ * The hook to resolve fallback options.
26
+ *
27
+ * @param missingOptionValues - The missing option values.
28
+ * @param config - The config of the hook.
29
+ * @param config.fallbackOptionsApi - The API of fallback options.
30
+ * @param config.fallbackOptionsApiParams - The API params of fallback options.
31
+ * @param config.valuesKey - The parameter key of values.
32
+ * @param config.resolveFallbackOptions - The function to resolve fallback options.
33
+ * @returns The API query result.
34
+ */
35
+ export declare function useFallbackOptions<T extends DataOption<T> = PureDataOption, P extends ObjectType = EmptyObject, K extends string = "ids">(missingOptionValues: IdValue[], { fallbackOptionsApi, fallbackOptionsApiParams, valuesKey, resolveFallbackOptions, }: UseFallbackOptionsConfig<T, P, K>): import("@vef-framework/shared").QueryResult<T[]>;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useApiContext as e}from"@vef-framework/core";import{useUnmount as a}from"ahooks";import{isFunction as r}from"@vef-framework/shared";import{useId as i,useMemo as o}from"react";function s(s,{fallbackOptionsApi:t,fallbackOptionsApiParams:p,valuesKey:l,resolveFallbackOptions:n}){const{useApiQuery:u,stubQueryApi:c,asyncFnQueryApi:f}=e(),[k,m,v]=function(e,{fallbackOptionsApi:a,fallbackOptionsApiParams:s,valuesKey:t,resolveFallbackOptions:p},l,n){const u=i();return o((()=>{if(r(p))return[n,{key:u,args:[e],fn:p},{keepPreviousData:!0}];if(a){const r={...s,[t??"ids"]:e};return[a,r,{keepPreviousData:!0}]}return[l,[],{keepPreviousData:!0,initialData:[]}]}),[p,a,l,u,e,n,s,t])}(s,{fallbackOptionsApi:t,fallbackOptionsApiParams:p,valuesKey:l,resolveFallbackOptions:n},c,f),b=u(k,m,v);return a((()=>{Object.is(k,c)&&c.removeQueries(m),Object.is(k,f)&&f.removeQueries(m)})),b}export{s as useFallbackOptions};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,8 @@
1
+ import type { GapSize } from "@vef-framework/shared";
2
+ import { type CSSProperties } from "react";
3
+ /**
4
+ * The hook to normalize the gap size.
5
+ *
6
+ * @returns The function to normalize the gap size.
7
+ */
8
+ export declare function useGapSizeNormalizer<T extends CSSProperties["gap"]>(): (gap: GapSize<T>) => number | (T & Record<never, never>);
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useCallback as d}from"react";import{useThemeTokens as n}from"./use-theme-tokens.js";function e(){const{paddingXS:e,paddingSM:i,padding:t,paddingMD:r,paddingLG:a}=n();return d((d=>"tiny"===d?e:"small"===d?i:"medium"===d?t:"large"===d?r:"huge"===d?a:d),[e,i,t,r,a])}export{e as useGapSizeNormalizer};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,9 @@
1
+ import type { GapSize } from "@vef-framework/shared";
2
+ import type { CSSProperties } from "react";
3
+ /**
4
+ * The hook to normalize the gap size.
5
+ *
6
+ * @param gap - The gap size.
7
+ * @returns The normalized gap size.
8
+ */
9
+ export declare function useNormalizedGapSize<T extends CSSProperties["gap"]>(gap: GapSize<T>): number | (T & Record<never, never>);
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useGapSizeNormalizer as r}from"./use-gap-size-normalizer.js";function e(e){return r()(e)}export{e as useNormalizedGapSize};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,9 @@
1
+ import type { MenuItem } from "@vef-framework/shared";
2
+ import type { ItemType } from "antd/es/menu/interface";
3
+ /**
4
+ * Normalize the menu items to the type of antd.
5
+ *
6
+ * @param items - The menu items.
7
+ * @returns The normalized menu items.
8
+ */
9
+ export declare function useNormalizedMenuItems(items: MenuItem[]): ItemType[];
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useMemo as e}from"react";function l(e){return"item"===e.type?{type:"item",key:e.key,label:e.label,disabled:e.disabled,icon:e.icon,extra:e.extra}:"subMenu"===e.type?{type:"submenu",key:e.key,label:e.label,disabled:e.disabled,icon:e.icon,children:e.children.map(l)}:"group"===e.type?{type:"group",key:e.key,label:e.label,children:e.children.map(l)}:{type:"divider",key:e.key}}function i(i){return e((()=>i.map(l)),[i])}export{i as useNormalizedMenuItems};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,34 @@
1
+ import type { Except } from "@vef-framework/shared";
2
+ import { type DataOption, type DataOptionConfig, type IdValue, type NormalizedDataOption, type PureDataOption, type StringKey } from "@vef-framework/shared";
3
+ /**
4
+ * The config of the useNormalizedDataOptions hook.
5
+ */
6
+ export interface UseNormalizedDataOptionsConfig {
7
+ /**
8
+ * Whether the options is a tree.
9
+ */
10
+ isTree?: boolean;
11
+ /**
12
+ * Whether the options are grouped.
13
+ */
14
+ isGrouped?: boolean;
15
+ /**
16
+ * Whether to parse the pinyin of the options's label and description.
17
+ */
18
+ parsePinyin?: boolean;
19
+ /**
20
+ * The values of the selected options used to find the missing options.
21
+ */
22
+ selectedOptionValues?: IdValue[];
23
+ }
24
+ /**
25
+ * The return type of the useNormalizedDataOptions hook.
26
+ */
27
+ type UseNormalizedDataOptionsReturn<T extends DataOption<T>, F extends boolean> = F extends true ? [Array<NormalizedDataOption & T>, IdValue[], NormalizedDataOption & T | undefined] : [Array<NormalizedDataOption & T>, IdValue[]];
28
+ /**
29
+ * The hook to normalize the data options.
30
+ */
31
+ export declare function useNormalizedDataOptions<T extends DataOption<T> = PureDataOption, F extends boolean = false>(options: T[], { labelField, valueField, childrenField, descriptionField, disabledField, defaultToFirst, }: Except<DataOptionConfig<StringKey<T>>, "defaultToFirst"> & {
32
+ defaultToFirst?: F;
33
+ }, { isTree, isGrouped, parsePinyin, selectedOptionValues, }?: UseNormalizedDataOptionsConfig): UseNormalizedDataOptionsReturn<T, F>;
34
+ export {};
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{isNullish as e,VefError as i,isString as r,parsePinyinFirstLetter as n,isArray as l}from"@vef-framework/shared";import{useMemo as t}from"react";function o(o,{labelField:d="label",valueField:a="value",childrenField:s="children",descriptionField:h="description",disabledField:c="disabled",defaultToFirst:u=!1},{isTree:f=!1,isGrouped:p=!1,parsePinyin:b=!1,selectedOptionValues:v=[]}={}){return t((()=>{const t=new Set(v),w=!f&&p,m=(o,u=!1)=>{const f=o[d];if(e(f)){if("label"===d)throw new i(-10001,"The label value of the option is required.");throw new i(-10001,`The label value pointed by '${d}' of the option is required.`)}const p=o[a];if(e(p)){if("value"===a)throw new i(-10002,"The value value of the option is required.");throw new i(-10002,`The value value pointed by '${a}' of the option is required.`)}const v=o[s],T=o[h],y=o[c]??!1,F={...o,label:f,value:p,children:v,description:T,disabled:y};if(b){const{labelText:e,descriptionText:i}=F;(r(f)||r(e))&&(F.labelPinyin=n(r(f)?f:e).join("")),(r(T)||r(i))&&(F.descriptionPinyin=n(r(T)?T:i).join(""))}return u&&w||!t.has(p)||t.delete(p),l(F.children)&&(F.children=F.children.map((e=>m(e)))),F},T=Array.from(t),y=o.map((e=>m(e,!0)));if(!u)return[y,T];if(w){const e=y.find((e=>l(e.children)&&e.children.length>0));return[y,T,e?.children?.[0]]}return[y,T,y[0]]}),[s,u,h,c,p,f,d,o,b,v,a])}export{o as useNormalizedDataOptions};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,8 @@
1
+ import type { DataOption, NormalizedDataOption, PureDataOption } from "@vef-framework/shared";
2
+ /**
3
+ * The hook to filter the options.
4
+ *
5
+ * @param filterable - Whether to allow filtering.
6
+ * @param filterFromRemote - Whether to filter from remote.
7
+ */
8
+ export declare function useOptionFilter<T extends DataOption<T> = PureDataOption>(filterable: boolean, filterFromRemote: boolean): false | ((filterValue: string, option: NormalizedDataOption<T>) => boolean) | undefined;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{isString as e}from"@vef-framework/shared";import{useMemo as i}from"react";function n(n,l){return i((()=>{if(n)return!l&&((i,n)=>(e(n.label)&&n.label.includes(i)||e(n.labelText)&&n.labelText.includes(i)||n.labelPinyin?.includes(i)||n.value.includes(i)||e(n.description)&&n.description.includes(i)||e(n.descriptionText)&&n.descriptionText.includes(i)||n.descriptionPinyin?.includes(i))??!1)}),[n,l])}export{n as useOptionFilter};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { ObjectType, QueryParamsWithKeyword } from "@vef-framework/shared";
2
+ import type { EmptyObject } from "@vef-framework/shared";
3
+ /**
4
+ * The hook to handle the remote filter.
5
+ *
6
+ * @param enabled - Whether to enable the remote filter.
7
+ * @param apiParams - The API params.
8
+ * @param keywordKey - The key of the keyword parameter.
9
+ */
10
+ export declare function useRemoteFilter<P extends ObjectType = EmptyObject, K extends string = "keyword">(enabled: boolean, apiParams?: QueryParamsWithKeyword<P, K>, keywordKey?: K): readonly [QueryParamsWithKeyword<P, K> | undefined, import("radashi").DebounceFunction<[keyword: string]> | undefined];
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{trim as r,debounce as e}from"@vef-framework/shared";import{useState as t,useMemo as o}from"react";function n(n,f,i="keyword"){const[m,u]=t();return[o((()=>{if(!n)return f;const e={...f},t=r(m);return t&&(e[i]=t),e}),[n,f,m,i]),o((()=>{if(n)return e({delay:500},(r=>{u(r)}))}),[n])]}export{n as useRemoteFilter};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { AnyFunction } from "@vef-framework/shared";
2
+ import { type DependencyList } from "react";
3
+ /**
4
+ * The hook to memoize a callback based on shallow comparison of dependencies.
5
+ *
6
+ * @param callback - The callback to be memoized.
7
+ * @param dependencies - The dependencies array.
8
+ * @returns The memoized callback.
9
+ */
10
+ export declare function useShallowCompareCallback<T extends AnyFunction>(callback: T, dependencies: DependencyList): T;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useCallback as o}from"react";import{useShallowCompareMemo as r}from"./use-shallow-compare-memo.js";function m(m,t){const e=r((()=>t),t);return o(m,e)}export{m as useShallowCompareCallback};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,10 @@
1
+ import type { Provider } from "@vef-framework/shared";
2
+ import { type DependencyList } from "react";
3
+ /**
4
+ * The hook to memoize a value based on shallow comparison of dependencies.
5
+ *
6
+ * @param factory - The factory function to create the value.
7
+ * @param dependencies - The dependencies array.
8
+ * @returns The memoized value.
9
+ */
10
+ export declare function useShallowCompareMemo<T>(factory: Provider<T>, dependencies: DependencyList): T;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useRef as r,useMemo as t}from"react";import{shallow as e}from"zustand/shallow";function n(n,o){const c=r(),u=r(0);var a,i;return void 0!==c.current&&(a=o,i=c.current,a.length===i.length&&a.every(((r,t)=>e(r,i[t]))))||(u.current+=1),c.current=o,t(n,[u.current])}export{n as useShallowCompareMemo};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The hook to create a singleton.
3
+ *
4
+ * @param factory - The factory function to create the singleton.
5
+ * @returns The singleton.
6
+ */
7
+ export declare function useSingleton<T>(factory: () => NonNullable<T>): NonNullable<T>;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{isNullish as r}from"@vef-framework/shared";import{useRef as t}from"react";function e(e){const o=t();return r(o.current)&&(o.current=e()),o.current}export{e as useSingleton};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get theme token
3
+ *
4
+ * @returns Theme token
5
+ */
6
+ export declare function useThemeTokens(): import("antd").GlobalToken;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{theme as n}from"antd";const{useToken:o}=n;function t(){const{token:n}=o();return n}export{t as useThemeTokens};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The size of the window.
3
+ */
4
+ export interface WindowSize {
5
+ /**
6
+ * The width of the window.
7
+ */
8
+ width: number;
9
+ /**
10
+ * The height of the window.
11
+ */
12
+ height: number;
13
+ }
14
+ /**
15
+ * The hook to get the size of the window.
16
+ */
17
+ export declare function useWindowSize(): WindowSize;
@@ -0,0 +1,3 @@
1
+ /*! VefFramework version: 1.0.5, build time: 2024-12-10T10:24:47.065Z, made by Venus. */
2
+ import{useRafState as i,useEventListener as n}from"ahooks";function t(){const[t,e]=i((()=>({width:window.innerWidth,height:window.innerHeight})));return n("resize",(()=>{e({width:window.innerWidth,height:window.innerHeight})})),t}export{t as useWindowSize};
3
+ /*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vef-framework/hooks",
3
+ "type": "module",
4
+ "version": "1.0.5",
5
+ "private": false,
6
+ "description": "Hooks fundamental to the VEF framework",
7
+ "author": "Venus",
8
+ "keywords": [
9
+ "vef",
10
+ "vef-framework",
11
+ "vef-hooks"
12
+ ],
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "*"
17
+ ],
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "scripts": {
22
+ "build": "pnpm clean && tsx build.ts",
23
+ "clean": "rimraf dist"
24
+ },
25
+ "peerDependencies": {
26
+ "react": "18.3.1",
27
+ "react-dom": "18.3.1",
28
+ "zustand": "5.0.1"
29
+ },
30
+ "dependencies": {
31
+ "@emotion/cache": "11.13.5",
32
+ "@emotion/react": "11.13.5",
33
+ "@emotion/styled": "11.13.5",
34
+ "antd": "5.22.3",
35
+ "tslib": "2.8.1",
36
+ "@vef-framework/core": "1.0.5",
37
+ "@vef-framework/shared": "1.0.5",
38
+ "ahooks": "3.8.4"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }