@vef-framework/core 1.0.134 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +15 -0
- package/dist/cjs/api/client.cjs +171 -0
- package/dist/cjs/api/constants.cjs +13 -0
- package/dist/cjs/api/helpers.cjs +12 -0
- package/dist/cjs/api/index.cjs +14 -0
- package/dist/cjs/auth/helpers.cjs +19 -0
- package/dist/cjs/auth/index.cjs +10 -0
- package/dist/cjs/common/index.cjs +3 -0
- package/dist/cjs/context/api-client.cjs +25 -0
- package/dist/cjs/context/app.cjs +15 -0
- package/dist/cjs/context/context-selector.cjs +65 -0
- package/dist/cjs/context/disabled.cjs +15 -0
- package/dist/cjs/context/index.cjs +19 -0
- package/dist/cjs/dnd/index.cjs +102 -0
- package/dist/cjs/http/client.cjs +445 -0
- package/dist/cjs/http/errors.cjs +23 -0
- package/dist/cjs/http/helpers.cjs +17 -0
- package/dist/cjs/http/index.cjs +17 -0
- package/dist/cjs/immer/index.cjs +40 -0
- package/dist/cjs/index.cjs +306 -0
- package/dist/cjs/motion/features.cjs +13 -0
- package/dist/cjs/motion/index.cjs +48 -0
- package/dist/cjs/motion/motion-provider.cjs +29 -0
- package/dist/cjs/query/constants.cjs +8 -0
- package/dist/cjs/query/helpers.cjs +67 -0
- package/dist/cjs/query/hooks.cjs +52 -0
- package/dist/cjs/query/index.cjs +20 -0
- package/dist/cjs/state/index.cjs +41 -0
- package/dist/cjs/state-machine/index.cjs +35 -0
- package/dist/cjs/store/bound.cjs +42 -0
- package/dist/cjs/store/index.cjs +20 -0
- package/dist/cjs/store/unbound.cjs +74 -0
- package/dist/cjs/store/use-deep.cjs +17 -0
- package/dist/es/api/client.js +167 -0
- package/dist/es/api/constants.js +8 -0
- package/dist/es/api/helpers.js +8 -0
- package/dist/es/api/index.js +4 -0
- package/dist/es/auth/helpers.js +15 -0
- package/dist/es/auth/index.js +2 -0
- package/dist/es/common/index.js +1 -0
- package/dist/es/context/api-client.js +20 -0
- package/dist/es/context/app.js +10 -0
- package/dist/es/context/context-selector.js +61 -0
- package/dist/es/context/disabled.js +10 -0
- package/dist/es/context/index.js +5 -0
- package/dist/es/dnd/index.js +7 -0
- package/dist/es/http/client.js +439 -0
- package/dist/es/http/errors.js +19 -0
- package/dist/es/http/helpers.js +12 -0
- package/dist/es/http/index.js +4 -0
- package/dist/es/immer/index.js +8 -0
- package/dist/es/index.js +43 -0
- package/dist/es/motion/features.js +2 -0
- package/dist/es/motion/index.js +5 -0
- package/dist/es/motion/motion-provider.js +25 -0
- package/dist/es/query/constants.js +4 -0
- package/dist/es/query/helpers.js +60 -0
- package/dist/es/query/hooks.js +27 -0
- package/dist/es/query/index.js +4 -0
- package/dist/es/state/index.js +2 -0
- package/dist/es/state-machine/index.js +12 -0
- package/dist/es/store/bound.js +37 -0
- package/dist/es/store/index.js +5 -0
- package/dist/es/store/unbound.js +70 -0
- package/dist/es/store/use-deep.js +13 -0
- package/dist/types/api/client.d.ts +75 -0
- package/dist/types/api/constants.d.ts +8 -0
- package/dist/types/api/helpers.d.ts +9 -0
- package/dist/types/api/index.d.ts +4 -0
- package/dist/types/api/types.d.ts +48 -0
- package/dist/types/auth/helpers.d.ts +11 -0
- package/dist/types/auth/index.d.ts +2 -0
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/common/types.d.ts +95 -0
- package/dist/types/context/api-client.d.ts +18 -0
- package/dist/types/context/app.d.ts +4 -0
- package/dist/types/context/context-selector.d.ts +44 -0
- package/dist/types/context/disabled.d.ts +9 -0
- package/dist/types/context/index.d.ts +5 -0
- package/dist/types/context/types.d.ts +27 -0
- package/dist/types/dnd/index.d.ts +6 -0
- package/dist/types/http/client.d.ts +144 -0
- package/dist/types/http/errors.d.ts +14 -0
- package/dist/types/http/helpers.d.ts +17 -0
- package/dist/types/http/index.d.ts +4 -0
- package/dist/types/http/types.d.ts +101 -0
- package/dist/types/immer/index.d.ts +2 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/motion/features.d.ts +1 -0
- package/dist/types/motion/index.d.ts +4 -0
- package/dist/types/motion/motion-provider.d.ts +5 -0
- package/dist/types/query/constants.d.ts +1 -0
- package/dist/types/query/helpers.d.ts +10 -0
- package/dist/types/query/hooks.d.ts +66 -0
- package/dist/types/query/index.d.ts +4 -0
- package/dist/types/query/types.d.ts +51 -0
- package/dist/types/state/index.d.ts +1 -0
- package/dist/types/state-machine/index.d.ts +14 -0
- package/dist/types/store/bound.d.ts +28 -0
- package/dist/types/store/index.d.ts +5 -0
- package/dist/types/store/types.d.ts +50 -0
- package/dist/types/store/unbound.d.ts +26 -0
- package/dist/types/store/use-deep.d.ts +7 -0
- package/package.json +59 -36
- package/README.md +0 -25
- package/cjs/api/api-client.cjs +0 -2
- package/cjs/api/api-context.cjs +0 -2
- package/cjs/api/index.cjs +0 -2
- package/cjs/api/query-client.cjs +0 -2
- package/cjs/api/request-client.cjs +0 -2
- package/cjs/auth/auth-context.cjs +0 -2
- package/cjs/auth/index.cjs +0 -2
- package/cjs/expr/compiler.cjs +0 -2
- package/cjs/expr/helpers.cjs +0 -2
- package/cjs/index.cjs +0 -2
- package/cjs/middleware/dispatcher.cjs +0 -2
- package/esm/api/api-client.js +0 -2
- package/esm/api/api-context.js +0 -2
- package/esm/api/index.js +0 -2
- package/esm/api/query-client.js +0 -2
- package/esm/api/request-client.js +0 -2
- package/esm/auth/auth-context.js +0 -2
- package/esm/auth/index.js +0 -2
- package/esm/expr/compiler.js +0 -2
- package/esm/expr/helpers.js +0 -2
- package/esm/index.js +0 -2
- package/esm/middleware/dispatcher.js +0 -2
- package/types/api/api-client.d.ts +0 -203
- package/types/api/api-context.d.ts +0 -167
- package/types/api/index.d.ts +0 -3
- package/types/api/query-client.d.ts +0 -27
- package/types/api/request-client.d.ts +0 -95
- package/types/auth/auth-context.d.ts +0 -29
- package/types/auth/index.d.ts +0 -1
- package/types/expr/compiler.d.ts +0 -35
- package/types/expr/helpers.d.ts +0 -58
- package/types/index.d.ts +0 -3
- package/types/middleware/dispatcher.d.ts +0 -22
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { identity, constantCase } from '@vef-framework/shared';
|
|
3
|
+
import { create } from 'zustand';
|
|
4
|
+
import { subscribeWithSelector, persist, createJSONStorage } from 'zustand/middleware';
|
|
5
|
+
import { immer } from 'zustand/middleware/immer';
|
|
6
|
+
|
|
7
|
+
function createStore(initializer) {
|
|
8
|
+
const useStore = create()(
|
|
9
|
+
subscribeWithSelector(
|
|
10
|
+
immer(initializer)
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
return useStore;
|
|
14
|
+
}
|
|
15
|
+
function createPersistedStore(initializer, persistenceOptions) {
|
|
16
|
+
const {
|
|
17
|
+
name,
|
|
18
|
+
storage,
|
|
19
|
+
selector
|
|
20
|
+
} = persistenceOptions;
|
|
21
|
+
const useStore = create()(
|
|
22
|
+
subscribeWithSelector(
|
|
23
|
+
persist(
|
|
24
|
+
immer(initializer),
|
|
25
|
+
{
|
|
26
|
+
name: `__VEF_STORE__${constantCase(name)}__`,
|
|
27
|
+
version: 1,
|
|
28
|
+
storage: createJSONStorage(() => storage === "local" ? localStorage : sessionStorage),
|
|
29
|
+
partialize: selector ?? identity
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
return useStore;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { createPersistedStore, createStore };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
export { createPersistedStore, createStore } from './bound.js';
|
|
3
|
+
export { createComponentStore } from './unbound.js';
|
|
4
|
+
export { useDeep } from './use-deep.js';
|
|
5
|
+
export { useShallow } from 'zustand/shallow';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
3
|
+
import { isPlainObject, mergeWith } from '@vef-framework/shared';
|
|
4
|
+
import { useIsomorphicLayoutEffect } from 'motion/react';
|
|
5
|
+
import { createContext, useRef, use } from 'react';
|
|
6
|
+
import { createStore, useStore } from 'zustand';
|
|
7
|
+
import { subscribeWithSelector } from 'zustand/middleware';
|
|
8
|
+
import { immer } from 'zustand/middleware/immer';
|
|
9
|
+
|
|
10
|
+
const contextCache = /* @__PURE__ */ new Map();
|
|
11
|
+
function createComponentStore(name, initializer) {
|
|
12
|
+
const contextKey = `${name}StoreContext`;
|
|
13
|
+
let Context = contextCache.get(contextKey);
|
|
14
|
+
if (!Context) {
|
|
15
|
+
Context = createContext(null);
|
|
16
|
+
Context.displayName = contextKey;
|
|
17
|
+
contextCache.set(contextKey, Context);
|
|
18
|
+
}
|
|
19
|
+
function StoreProvider(props) {
|
|
20
|
+
const { children } = props;
|
|
21
|
+
const storeRef = useRef(null);
|
|
22
|
+
const storeInitializedRef = useRef(false);
|
|
23
|
+
const latestInitialStateRef = useRef(void 0);
|
|
24
|
+
latestInitialStateRef.current = props.initialState;
|
|
25
|
+
if (!storeRef.current || !storeInitializedRef.current) {
|
|
26
|
+
storeRef.current = createStore()(
|
|
27
|
+
subscribeWithSelector(
|
|
28
|
+
immer(initializer)
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
storeInitializedRef.current = true;
|
|
32
|
+
}
|
|
33
|
+
useIsomorphicLayoutEffect(() => {
|
|
34
|
+
if (!isPlainObject(latestInitialStateRef.current)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (storeRef.current) {
|
|
38
|
+
storeRef.current.setState((state) => {
|
|
39
|
+
mergeWith(
|
|
40
|
+
state,
|
|
41
|
+
latestInitialStateRef.current,
|
|
42
|
+
true
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
return /* @__PURE__ */ jsx(Context, { value: storeRef.current, children });
|
|
48
|
+
}
|
|
49
|
+
function useStoreApi() {
|
|
50
|
+
const store = use(Context);
|
|
51
|
+
if (!store) {
|
|
52
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
53
|
+
const errorMessage = `${name}Store is not found in the React context, please check if the store is wrapped in a ${name}StoreProvider`;
|
|
54
|
+
const devHint = isDev ? "\n\nDev hint: If you're seeing this error after hot reload, it might be a React Fast Refresh issue. Try refreshing the page." : "";
|
|
55
|
+
throw new Error(errorMessage + devHint);
|
|
56
|
+
}
|
|
57
|
+
return store;
|
|
58
|
+
}
|
|
59
|
+
function useStore$1(selector) {
|
|
60
|
+
const store = useStoreApi();
|
|
61
|
+
return useStore(store, selector);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
StoreProvider,
|
|
65
|
+
useStoreApi,
|
|
66
|
+
useStore: useStore$1
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { createComponentStore };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { isDeepEqual } from '@vef-framework/shared';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
function useDeep(selector) {
|
|
6
|
+
const prevRef = useRef(null);
|
|
7
|
+
return (state) => {
|
|
8
|
+
const next = selector(state);
|
|
9
|
+
return isDeepEqual(prevRef.current, next) ? prevRef.current : prevRef.current = next;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { useDeep };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FetchQueryOptions, MutationOptions, QueryClient, QueryMeta } from '@tanstack/react-query';
|
|
2
|
+
import { Awaitable, Except, If, IsNever, IsOptional } from '@vef-framework/shared';
|
|
3
|
+
import { HttpClient } from '../http';
|
|
4
|
+
import { ApiClientOptions, MutationFunction, QueryFunction, QueryKey } from './types';
|
|
5
|
+
import { QUERY_CLIENT } from './constants';
|
|
6
|
+
/**
|
|
7
|
+
* The API client.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ApiClient {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* The query client.
|
|
13
|
+
*/
|
|
14
|
+
get [QUERY_CLIENT](): QueryClient;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new API client.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The options for the API client.
|
|
19
|
+
*/
|
|
20
|
+
constructor(options: ApiClientOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new query function.
|
|
23
|
+
*
|
|
24
|
+
* @param key - The key of the query function.
|
|
25
|
+
* @param factory - The factory function.
|
|
26
|
+
* @returns The query function.
|
|
27
|
+
*/
|
|
28
|
+
createQueryFn<TResult = unknown, TParams = never, TPageParam = never>(key: string, factory: (http: Readonly<HttpClient>) => (queryParams: TParams, pageParam: TPageParam, meta?: QueryMeta) => Awaitable<TResult>): QueryFunction<TResult, TParams, TPageParam>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new mutation function.
|
|
31
|
+
*
|
|
32
|
+
* @param key - The key of the mutation function.
|
|
33
|
+
* @param factory - The factory function.
|
|
34
|
+
* @returns The mutation function.
|
|
35
|
+
*/
|
|
36
|
+
createMutationFn<TResult = unknown, TParams = never>(key: string, factory: (http: Readonly<HttpClient>) => (params: TParams) => Awaitable<TResult>): MutationFunction<TResult, TParams>;
|
|
37
|
+
/**
|
|
38
|
+
* Fetches a query.
|
|
39
|
+
*
|
|
40
|
+
* @param options - The options for the query.
|
|
41
|
+
* @returns The result of the query.
|
|
42
|
+
*/
|
|
43
|
+
fetchQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = unknown, TPageParam = never>(options: Except<FetchQueryOptions<TQueryFnData, Error, TData, QueryKey<TParams>, TPageParam>, "queryHash" | "queryKeyHashFn">): Promise<TData>;
|
|
44
|
+
/**
|
|
45
|
+
* Prefetches a query and stores the result in cache.
|
|
46
|
+
*
|
|
47
|
+
* @param options - The options for the query.
|
|
48
|
+
* @returns A promise that resolves when the prefetch is complete.
|
|
49
|
+
*/
|
|
50
|
+
prefetchQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = unknown, TPageParam = never>(options: Except<FetchQueryOptions<TQueryFnData, Error, TData, QueryKey<TParams>, TPageParam>, "queryHash" | "queryKeyHashFn">): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Executes a mutation outside of React components.
|
|
53
|
+
*
|
|
54
|
+
* This method allows you to execute mutations imperatively without using the `useMutation` hook.
|
|
55
|
+
* Useful for scenarios like login flows, event handlers, or any code outside React components.
|
|
56
|
+
*
|
|
57
|
+
* @template TData - The type of data returned by the mutation
|
|
58
|
+
* @template TParams - The type of parameters passed to the mutation function
|
|
59
|
+
* @template TOnMutateResult - The type of result returned by onMutate callback
|
|
60
|
+
*
|
|
61
|
+
* @param options - The mutation options including mutationFn, onSuccess, onError, etc.
|
|
62
|
+
* @param variables - The variables to pass to the mutation function. Omit this argument when the mutation does not require parameters.
|
|
63
|
+
* @remarks This reuses TanStack Query's imperative mutation execution so lifecycle callbacks (onMutate, onSuccess, etc.) still fire.
|
|
64
|
+
* @returns A promise that resolves with the mutation result
|
|
65
|
+
*/
|
|
66
|
+
executeMutation<TData = unknown, TParams = unknown, TOnMutateResult = unknown>({ mutationFn, params, ...options }: Except<MutationOptions<TData, Error, TParams, TOnMutateResult>, "mutationKey" | "mutationFn"> & {
|
|
67
|
+
mutationFn: MutationFunction<TData, TParams>;
|
|
68
|
+
} & If<IsNever<TParams>, {
|
|
69
|
+
params?: never;
|
|
70
|
+
}, If<IsOptional<TParams>, {
|
|
71
|
+
params?: TParams;
|
|
72
|
+
}, {
|
|
73
|
+
params: TParams;
|
|
74
|
+
}>>): Promise<TData>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiClientOptions } from './types';
|
|
2
|
+
import { ApiClient } from './client';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new API client.
|
|
5
|
+
*
|
|
6
|
+
* @param options - The options for the API client.
|
|
7
|
+
* @returns The API client.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createApiClient(options: ApiClientOptions): ApiClient;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MutationFunction as MutationFunctionInternal, QueryFunction as QueryFunctionInternal } from '@tanstack/react-query';
|
|
2
|
+
import { If, IsNever, Key } from '@vef-framework/shared';
|
|
3
|
+
import { HttpClientOptions } from '../http';
|
|
4
|
+
import { QueryClientOptions } from '../query';
|
|
5
|
+
/**
|
|
6
|
+
* The options for the API client.
|
|
7
|
+
*/
|
|
8
|
+
export interface ApiClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The options for the HTTP client.
|
|
11
|
+
*/
|
|
12
|
+
http: HttpClientOptions;
|
|
13
|
+
/**
|
|
14
|
+
* The options for the query client.
|
|
15
|
+
*/
|
|
16
|
+
query?: QueryClientOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The key of the query.
|
|
20
|
+
*
|
|
21
|
+
* @param TParams - The parameters of the query.
|
|
22
|
+
*/
|
|
23
|
+
export type QueryKey<TParams = never> = readonly [Key, ...If<IsNever<TParams>, [], [TParams]>];
|
|
24
|
+
/**
|
|
25
|
+
* The query function.
|
|
26
|
+
*
|
|
27
|
+
* @param TResult - The result of the query.
|
|
28
|
+
* @param TParams - The parameters of the query.
|
|
29
|
+
* @param TPageParam - The page parameter of the query.
|
|
30
|
+
*/
|
|
31
|
+
export interface QueryFunction<TData = unknown, TParams = never, TPageParam = never> extends QueryFunctionInternal<TData, QueryKey<TParams>, TPageParam> {
|
|
32
|
+
/**
|
|
33
|
+
* The API identifier.
|
|
34
|
+
*/
|
|
35
|
+
key: Key;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The mutation function.
|
|
39
|
+
*
|
|
40
|
+
* @param TResult - The result of the mutation.
|
|
41
|
+
* @param TParams - The parameters of the mutation.
|
|
42
|
+
*/
|
|
43
|
+
export interface MutationFunction<TData = unknown, TParams = never> extends MutationFunctionInternal<TData, TParams> {
|
|
44
|
+
/**
|
|
45
|
+
* The API identifier.
|
|
46
|
+
*/
|
|
47
|
+
key: Key;
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
2
|
+
import { PermissionCheckMode } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Check if the user is authorized to access the resource identified by the permission token.
|
|
5
|
+
*
|
|
6
|
+
* @param hasPermission - The function to check if the user has the permission to access the resource identified by the token.
|
|
7
|
+
* @param permTokens - The permission tokens to check.
|
|
8
|
+
* @param checkMode - The check mode to use.
|
|
9
|
+
* @returns Whether the user is authorized to access the resource identified by the permission token.
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkPermission(hasPermission: (token: string) => boolean, permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PermissionCheckMode = "any" | "all";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AnyObject, EmptyObject, Except, Key } from '@vef-framework/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination parameters for list queries.
|
|
4
|
+
* Used to specify which page and how many items per page to retrieve.
|
|
5
|
+
*/
|
|
6
|
+
export interface PaginationParams {
|
|
7
|
+
/**
|
|
8
|
+
* The page number, starting from 1
|
|
9
|
+
* @default 1
|
|
10
|
+
*/
|
|
11
|
+
page?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The number of items per page
|
|
14
|
+
* @default 15
|
|
15
|
+
*/
|
|
16
|
+
size?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Pagination result wrapper for paginated list responses.
|
|
20
|
+
* Contains the items for the current page and the total count across all pages.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The type of items in the paginated list
|
|
23
|
+
*/
|
|
24
|
+
export interface PaginationResult<T = unknown> {
|
|
25
|
+
/**
|
|
26
|
+
* Total number of items across all pages
|
|
27
|
+
*/
|
|
28
|
+
readonly total: number;
|
|
29
|
+
/**
|
|
30
|
+
* Items in the current page
|
|
31
|
+
*/
|
|
32
|
+
readonly items: T[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Base data option type for select, tree-select, cascader and other data-driven components.
|
|
36
|
+
*
|
|
37
|
+
* @template T - Additional custom fields that can be merged into the option
|
|
38
|
+
* @template M - Type of the metadata field
|
|
39
|
+
*/
|
|
40
|
+
export type DataOption<T = EmptyObject, M extends AnyObject = AnyObject> = T & {
|
|
41
|
+
/**
|
|
42
|
+
* Display text of the option
|
|
43
|
+
*/
|
|
44
|
+
label: string;
|
|
45
|
+
/**
|
|
46
|
+
* Unique identifier of the option
|
|
47
|
+
*/
|
|
48
|
+
value: Key;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the option is disabled
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Additional description or help text for the option
|
|
56
|
+
*/
|
|
57
|
+
description?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Additional metadata for the option
|
|
60
|
+
*/
|
|
61
|
+
meta?: M;
|
|
62
|
+
/**
|
|
63
|
+
* Child options for tree-like structures (e.g., TreeSelect, Cascader)
|
|
64
|
+
*/
|
|
65
|
+
children?: Array<DataOption<T, M>>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Data option with pinyin fields for Chinese character search and sorting.
|
|
69
|
+
* Extends {@link DataOption} with pinyin support to enable fuzzy search by pronunciation.
|
|
70
|
+
*
|
|
71
|
+
* @template T - Additional custom fields that can be merged into the option
|
|
72
|
+
* @template M - Type of the metadata field
|
|
73
|
+
*/
|
|
74
|
+
export type DataOptionWithPinyin<T = EmptyObject, M extends AnyObject = AnyObject> = Except<DataOption<T, M>, "children"> & {
|
|
75
|
+
/**
|
|
76
|
+
* Pinyin representation of the label
|
|
77
|
+
*/
|
|
78
|
+
labelPinyin: string;
|
|
79
|
+
/**
|
|
80
|
+
* Initials of the pinyin representation of the label
|
|
81
|
+
*/
|
|
82
|
+
labelPinyinInitials: string;
|
|
83
|
+
/**
|
|
84
|
+
* Pinyin representation of the description
|
|
85
|
+
*/
|
|
86
|
+
descriptionPinyin?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Initials of the pinyin representation of the description
|
|
89
|
+
*/
|
|
90
|
+
descriptionPinyinInitials?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Child options with pinyin support
|
|
93
|
+
*/
|
|
94
|
+
children?: Array<DataOptionWithPinyin<T, M>>;
|
|
95
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MaybeNull, SetFieldType } from '@vef-framework/shared';
|
|
2
|
+
import { ComponentProps, Context } from 'react';
|
|
3
|
+
import { ApiClient } from '../api';
|
|
4
|
+
declare const Context: Context<MaybeNull<ApiClient>>;
|
|
5
|
+
/**
|
|
6
|
+
* The provider for the API client.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The props for the provider.
|
|
9
|
+
* @returns The provider for the API client.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ApiClientProvider({ value, children }: SetFieldType<ComponentProps<typeof Context.Provider>, "value", ApiClient>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* The hook for the API client.
|
|
14
|
+
*
|
|
15
|
+
* @returns The API client.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useApiClient(): ApiClient;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the selector context provider component
|
|
4
|
+
*/
|
|
5
|
+
export interface SelectorContextProviderProps<TValue> extends PropsWithChildren {
|
|
6
|
+
/**
|
|
7
|
+
* The value to provide to child components
|
|
8
|
+
*/
|
|
9
|
+
value: TValue;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Context hook interface with optional selector support
|
|
13
|
+
*/
|
|
14
|
+
export interface UseSelectorContext<in out TValue> {
|
|
15
|
+
/**
|
|
16
|
+
* Use context without selector, returns the full value
|
|
17
|
+
*/
|
|
18
|
+
<TStrictValue extends TValue = TValue>(): TStrictValue;
|
|
19
|
+
/**
|
|
20
|
+
* Use context with selector, returns the selected portion of the value
|
|
21
|
+
*/
|
|
22
|
+
<TStrictValue extends TValue = TValue, TSelected = TStrictValue>(selector: (value: TStrictValue) => TSelected): NoInfer<TSelected>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Result of creating a selector context
|
|
26
|
+
*/
|
|
27
|
+
export interface SelectorContextResult<TValue> {
|
|
28
|
+
/**
|
|
29
|
+
* Provider component to wrap child components
|
|
30
|
+
*/
|
|
31
|
+
Provider: ComponentType<SelectorContextProviderProps<TValue>>;
|
|
32
|
+
/**
|
|
33
|
+
* Hook to access context value with optional selector
|
|
34
|
+
*/
|
|
35
|
+
useContext: UseSelectorContext<TValue>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a context with selector support
|
|
39
|
+
* Allows consuming components to select specific parts of the context value for optimal re-rendering
|
|
40
|
+
*
|
|
41
|
+
* @param defaultValue - The default value for the context
|
|
42
|
+
* @returns An object containing the Provider component and useContext hook
|
|
43
|
+
*/
|
|
44
|
+
export declare function createContextWithSelector<TValue>(defaultValue: TValue): SelectorContextResult<TValue>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ApiClientProvider, useApiClient } from './api-client';
|
|
2
|
+
export { AppContextProvider, useAppContext } from './app';
|
|
3
|
+
export { createContextWithSelector, type SelectorContextProviderProps, type SelectorContextResult, type UseSelectorContext } from './context-selector';
|
|
4
|
+
export { DisabledProvider, useDisabled } from './disabled';
|
|
5
|
+
export type * from './types';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { QueryFunction } from '../api';
|
|
2
|
+
import { DataOption } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* The context of the vef app.
|
|
5
|
+
*/
|
|
6
|
+
export interface AppContext {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the user is authorized to access the resource identified by the token.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const isAuthorized = hasPermission("user:query");
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param token - The permission token.
|
|
16
|
+
* @returns Whether the user has the permission to access the resource identified by the token.
|
|
17
|
+
*/
|
|
18
|
+
hasPermission?: (token: string) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The query function for the data dictionary.
|
|
21
|
+
*/
|
|
22
|
+
dataDictQueryFn?: QueryFunction<DataOption[], string>;
|
|
23
|
+
/**
|
|
24
|
+
* The base URL for file access.
|
|
25
|
+
*/
|
|
26
|
+
fileBaseUrl?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AxisModifier, restrictShapeToBoundingRectangle, RestrictToHorizontalAxis, RestrictToVerticalAxis, SnapModifier } from '@dnd-kit/abstract/modifiers';
|
|
2
|
+
export { RestrictToElement, RestrictToWindow } from '@dnd-kit/dom/modifiers';
|
|
3
|
+
export { arrayMove as moveArrayItem, move as moveDragItem, arraySwap as swapArrayItem, swap as swapDragItem } from '@dnd-kit/helpers';
|
|
4
|
+
export { DragDropProvider, DragOverlay, KeyboardSensor, PointerSensor, useDragDropMonitor, useDraggable, useDroppable, type DragDropEventHandlers, type DragDropEvents } from '@dnd-kit/react';
|
|
5
|
+
export { useSortable } from '@dnd-kit/react/sortable';
|
|
6
|
+
export { DragDropContext, Draggable, Droppable, type DragDropContextProps, type DraggableChildrenFn, type DraggableId, type DraggableLocation, type DraggableProps, type DraggableProvided, type DraggableProvidedDraggableProps, type DraggableProvidedDragHandleProps, type DraggableRubric, type DraggableStateSnapshot, type DroppableId, type DroppableProps, type DroppableProvided, type DroppableProvidedProps, type DroppableStateSnapshot, type DropResult, type OnBeforeCaptureResponder, type OnBeforeDragStartResponder, type OnDragEndResponder, type OnDragStartResponder, type OnDragUpdateResponder } from '@hello-pangea/dnd';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { AxiosProgressEvent } from 'axios';
|
|
2
|
+
import { ApiResult, HttpClientOptions, RequestOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The header name for the skip authentication.
|
|
5
|
+
*/
|
|
6
|
+
export declare const skipAuthenticationHeader = "X-Skip-Authentication";
|
|
7
|
+
/**
|
|
8
|
+
* The header value for the skip authentication.
|
|
9
|
+
*/
|
|
10
|
+
export declare const skipAuthenticationValue = "1";
|
|
11
|
+
/**
|
|
12
|
+
* The HTTP client.
|
|
13
|
+
*/
|
|
14
|
+
export declare class HttpClient {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(options: HttpClientOptions);
|
|
17
|
+
private initInterceptors;
|
|
18
|
+
/**
|
|
19
|
+
* Check if the code belongs to the target.
|
|
20
|
+
*
|
|
21
|
+
* @param code - The code.
|
|
22
|
+
* @param target - The target.
|
|
23
|
+
* @returns The result.
|
|
24
|
+
*/
|
|
25
|
+
private isBelongsTo;
|
|
26
|
+
/**
|
|
27
|
+
* Handle the request.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The axios request config.
|
|
30
|
+
* @returns The axios request config.
|
|
31
|
+
*/
|
|
32
|
+
private handleRequest;
|
|
33
|
+
/**
|
|
34
|
+
* Handle the request error.
|
|
35
|
+
*
|
|
36
|
+
* @param error - The axios error.
|
|
37
|
+
*/
|
|
38
|
+
private handleRequestError;
|
|
39
|
+
/**
|
|
40
|
+
* Handle the response.
|
|
41
|
+
*
|
|
42
|
+
* @param response - The axios response.
|
|
43
|
+
* @returns The axios response.
|
|
44
|
+
*/
|
|
45
|
+
private handleResponse;
|
|
46
|
+
/**
|
|
47
|
+
* Handle the response error.
|
|
48
|
+
*
|
|
49
|
+
* @param error - The axios error.
|
|
50
|
+
*/
|
|
51
|
+
private handleResponseError;
|
|
52
|
+
/**
|
|
53
|
+
* Injects access token into request Authorization header.
|
|
54
|
+
*
|
|
55
|
+
* @param config - The axios request config.
|
|
56
|
+
*/
|
|
57
|
+
private setAccessToken;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the path parameters in the URL.
|
|
60
|
+
*
|
|
61
|
+
* @param config - The axios request config.
|
|
62
|
+
* @returns The axios request config.
|
|
63
|
+
*/
|
|
64
|
+
private replacePathParams;
|
|
65
|
+
/**
|
|
66
|
+
* Try to refresh the token using the provided refresh callback.
|
|
67
|
+
*
|
|
68
|
+
* @returns True if token refresh succeeded, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
private tryRefreshToken;
|
|
71
|
+
/**
|
|
72
|
+
* Retry the request.
|
|
73
|
+
*
|
|
74
|
+
* @param config - The axios request config.
|
|
75
|
+
* @returns The axios response.
|
|
76
|
+
*/
|
|
77
|
+
private retryRequest;
|
|
78
|
+
/**
|
|
79
|
+
* Get the resource.
|
|
80
|
+
*
|
|
81
|
+
* @param url - The url.
|
|
82
|
+
* @param options - The options for the request.
|
|
83
|
+
* @returns The response data.
|
|
84
|
+
*/
|
|
85
|
+
get<R = unknown, P = unknown>(url: string, options?: RequestOptions & {
|
|
86
|
+
params?: P;
|
|
87
|
+
}): Promise<ApiResult<R>>;
|
|
88
|
+
/**
|
|
89
|
+
* Post the resource.
|
|
90
|
+
*
|
|
91
|
+
* @param url - The url.
|
|
92
|
+
* @param options - The options for the request.
|
|
93
|
+
* @returns The response data.
|
|
94
|
+
*/
|
|
95
|
+
post<R = unknown, D = unknown, P = unknown>(url: string, options?: RequestOptions & {
|
|
96
|
+
data?: D;
|
|
97
|
+
params?: P;
|
|
98
|
+
}): Promise<ApiResult<R>>;
|
|
99
|
+
/**
|
|
100
|
+
* Update the resource.
|
|
101
|
+
*
|
|
102
|
+
* @param url - The url.
|
|
103
|
+
* @param options - The options for the request.
|
|
104
|
+
* @returns The response data.
|
|
105
|
+
*/
|
|
106
|
+
put<R = unknown, D = unknown, P = unknown>(url: string, options?: RequestOptions & {
|
|
107
|
+
data?: D;
|
|
108
|
+
params?: P;
|
|
109
|
+
}): Promise<ApiResult<R>>;
|
|
110
|
+
/**
|
|
111
|
+
* Delete the resource.
|
|
112
|
+
*
|
|
113
|
+
* @param url - The url.
|
|
114
|
+
* @param options - The options for the request.
|
|
115
|
+
* @returns The response data.
|
|
116
|
+
*/
|
|
117
|
+
delete<R = unknown, P = unknown>(url: string, options?: RequestOptions & {
|
|
118
|
+
params?: P;
|
|
119
|
+
}): Promise<ApiResult<R>>;
|
|
120
|
+
/**
|
|
121
|
+
* Upload the file.
|
|
122
|
+
*
|
|
123
|
+
* @param url - The url.
|
|
124
|
+
* @param options - The options for the request.
|
|
125
|
+
* @returns The response data.
|
|
126
|
+
*/
|
|
127
|
+
upload<R = unknown, P = unknown>(url: string, options?: RequestOptions & {
|
|
128
|
+
params?: P;
|
|
129
|
+
data: FormData;
|
|
130
|
+
onProgress?: (event: AxiosProgressEvent) => void;
|
|
131
|
+
}): Promise<ApiResult<R>>;
|
|
132
|
+
/**
|
|
133
|
+
* Download the file.
|
|
134
|
+
*
|
|
135
|
+
* @param url - The url.
|
|
136
|
+
* @param options - The options for the request.
|
|
137
|
+
* @returns The response data.
|
|
138
|
+
*/
|
|
139
|
+
download<P = unknown>(url: string, options?: RequestOptions & {
|
|
140
|
+
params?: P;
|
|
141
|
+
onProgress?: (progress: AxiosProgressEvent) => void;
|
|
142
|
+
filename?: string | ((filename: string) => string);
|
|
143
|
+
}): Promise<void>;
|
|
144
|
+
}
|