@vef-framework/hooks 1.0.135 → 2.0.1
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/index.cjs +172 -0
- package/dist/cjs/lib.cjs +148 -0
- package/dist/cjs/use-authorized-items/index.cjs +20 -0
- package/dist/cjs/use-breakpoints/index.cjs +74 -0
- package/dist/cjs/use-check-permission/index.cjs +18 -0
- package/dist/cjs/use-data-dict-query/index.cjs +34 -0
- package/dist/cjs/use-data-options/index.cjs +119 -0
- package/dist/cjs/use-deep-callback/index.cjs +13 -0
- package/dist/cjs/use-deep-compare/index.cjs +36 -0
- package/dist/cjs/use-deep-effect/index.cjs +13 -0
- package/dist/cjs/use-deep-isomorphic-effect/index.cjs +14 -0
- package/dist/cjs/use-deep-layout-effect/index.cjs +13 -0
- package/dist/cjs/use-deep-memo/index.cjs +13 -0
- package/dist/cjs/use-document-event/index.cjs +22 -0
- package/dist/cjs/use-emitter-event/index.cjs +22 -0
- package/dist/cjs/use-has-fetching/index.cjs +17 -0
- package/dist/cjs/use-has-mutating/index.cjs +16 -0
- package/dist/cjs/use-is-authorized/index.cjs +18 -0
- package/dist/cjs/use-latest/index.cjs +14 -0
- package/dist/cjs/use-raf-state/index.cjs +23 -0
- package/dist/cjs/use-shallow-callback/index.cjs +13 -0
- package/dist/cjs/use-shallow-compare/index.cjs +36 -0
- package/dist/cjs/use-shallow-effect/index.cjs +13 -0
- package/dist/cjs/use-shallow-isomorphic-effect/index.cjs +14 -0
- package/dist/cjs/use-shallow-layout-effect/index.cjs +13 -0
- package/dist/cjs/use-shallow-memo/index.cjs +13 -0
- package/dist/cjs/use-singleton/index.cjs +16 -0
- package/dist/es/index.js +29 -0
- package/dist/es/lib.js +35 -0
- package/dist/es/use-authorized-items/index.js +16 -0
- package/dist/es/use-breakpoints/index.js +70 -0
- package/dist/es/use-check-permission/index.js +14 -0
- package/dist/es/use-data-dict-query/index.js +30 -0
- package/dist/es/use-data-options/index.js +115 -0
- package/dist/es/use-deep-callback/index.js +9 -0
- package/dist/es/use-deep-compare/index.js +32 -0
- package/dist/es/use-deep-effect/index.js +9 -0
- package/dist/es/use-deep-isomorphic-effect/index.js +10 -0
- package/dist/es/use-deep-layout-effect/index.js +9 -0
- package/dist/es/use-deep-memo/index.js +9 -0
- package/dist/es/use-document-event/index.js +18 -0
- package/dist/es/use-emitter-event/index.js +18 -0
- package/dist/es/use-has-fetching/index.js +13 -0
- package/dist/es/use-has-mutating/index.js +12 -0
- package/dist/es/use-is-authorized/index.js +14 -0
- package/dist/es/use-latest/index.js +10 -0
- package/dist/es/use-raf-state/index.js +19 -0
- package/dist/es/use-shallow-callback/index.js +9 -0
- package/dist/es/use-shallow-compare/index.js +32 -0
- package/dist/es/use-shallow-effect/index.js +9 -0
- package/dist/es/use-shallow-isomorphic-effect/index.js +10 -0
- package/dist/es/use-shallow-layout-effect/index.js +9 -0
- package/dist/es/use-shallow-memo/index.js +9 -0
- package/dist/es/use-singleton/index.js +12 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/lib.d.ts +6 -0
- package/{types/use-authorized-items.d.ts → dist/types/use-authorized-items/index.d.ts} +4 -3
- package/dist/types/use-breakpoints/index.d.ts +47 -0
- package/dist/types/use-check-permission/index.d.ts +8 -0
- package/dist/types/use-data-dict-query/index.d.ts +15 -0
- package/dist/types/use-data-options/index.d.ts +80 -0
- package/dist/types/use-deep-callback/index.d.ts +9 -0
- package/dist/types/use-deep-compare/index.d.ts +8 -0
- package/dist/types/use-deep-effect/index.d.ts +9 -0
- package/dist/types/use-deep-isomorphic-effect/index.d.ts +9 -0
- package/dist/types/use-deep-layout-effect/index.d.ts +9 -0
- package/dist/types/use-deep-memo/index.d.ts +9 -0
- package/dist/types/use-document-event/index.d.ts +8 -0
- package/dist/types/use-emitter-event/index.d.ts +9 -0
- package/dist/types/use-has-fetching/index.d.ts +8 -0
- package/dist/types/use-has-mutating/index.d.ts +7 -0
- package/dist/types/use-is-authorized/index.d.ts +10 -0
- package/dist/types/use-latest/index.d.ts +8 -0
- package/dist/types/use-raf-state/index.d.ts +8 -0
- package/dist/types/use-shallow-callback/index.d.ts +9 -0
- package/dist/types/use-shallow-compare/index.d.ts +8 -0
- package/dist/types/use-shallow-effect/index.d.ts +9 -0
- package/dist/types/use-shallow-isomorphic-effect/index.d.ts +9 -0
- package/dist/types/use-shallow-layout-effect/index.d.ts +9 -0
- package/dist/types/use-shallow-memo/index.d.ts +9 -0
- package/dist/types/use-singleton/index.d.ts +11 -0
- package/package.json +46 -36
- package/README.md +0 -27
- package/cjs/index.cjs +0 -2
- package/cjs/lib.cjs +0 -2
- package/cjs/use-authorized-items.cjs +0 -2
- package/cjs/use-color-tokens.cjs +0 -2
- package/cjs/use-computed-action-buttons.cjs +0 -2
- package/cjs/use-computed-options.cjs +0 -2
- package/cjs/use-context-disabled.cjs +0 -2
- package/cjs/use-data-query.cjs +0 -2
- package/cjs/use-deep-callback.cjs +0 -2
- package/cjs/use-deep-memo.cjs +0 -2
- package/cjs/use-deep-selector.cjs +0 -2
- package/cjs/use-fallback-options.cjs +0 -2
- package/cjs/use-gap-size-normalizer.cjs +0 -2
- package/cjs/use-normalized-gap-size.cjs +0 -2
- package/cjs/use-normalized-menu-items.cjs +0 -2
- package/cjs/use-normalized-options.cjs +0 -2
- package/cjs/use-option-filter.cjs +0 -2
- package/cjs/use-remote-filter.cjs +0 -2
- package/cjs/use-shallow-callback.cjs +0 -2
- package/cjs/use-shallow-memo.cjs +0 -2
- package/cjs/use-shallow-selector.cjs +0 -2
- package/cjs/use-singleton.cjs +0 -2
- package/cjs/use-theme-tokens.cjs +0 -2
- package/cjs/use-transient-store.cjs +0 -2
- package/cjs/use-window-size.cjs +0 -2
- package/esm/index.js +0 -2
- package/esm/lib.js +0 -2
- package/esm/use-authorized-items.js +0 -2
- package/esm/use-color-tokens.js +0 -2
- package/esm/use-computed-action-buttons.js +0 -2
- package/esm/use-computed-options.js +0 -2
- package/esm/use-context-disabled.js +0 -2
- package/esm/use-data-query.js +0 -2
- package/esm/use-deep-callback.js +0 -2
- package/esm/use-deep-memo.js +0 -2
- package/esm/use-deep-selector.js +0 -2
- package/esm/use-fallback-options.js +0 -2
- package/esm/use-gap-size-normalizer.js +0 -2
- package/esm/use-normalized-gap-size.js +0 -2
- package/esm/use-normalized-menu-items.js +0 -2
- package/esm/use-normalized-options.js +0 -2
- package/esm/use-option-filter.js +0 -2
- package/esm/use-remote-filter.js +0 -2
- package/esm/use-shallow-callback.js +0 -2
- package/esm/use-shallow-memo.js +0 -2
- package/esm/use-shallow-selector.js +0 -2
- package/esm/use-singleton.js +0 -2
- package/esm/use-theme-tokens.js +0 -2
- package/esm/use-transient-store.js +0 -2
- package/esm/use-window-size.js +0 -2
- package/types/index.d.ts +0 -24
- package/types/lib.d.ts +0 -3
- package/types/use-color-tokens.d.ts +0 -19
- package/types/use-computed-action-buttons.d.ts +0 -35
- package/types/use-computed-options.d.ts +0 -54
- package/types/use-context-disabled.d.ts +0 -6
- package/types/use-data-query.d.ts +0 -9
- package/types/use-deep-callback.d.ts +0 -10
- package/types/use-deep-memo.d.ts +0 -10
- package/types/use-deep-selector.d.ts +0 -8
- package/types/use-fallback-options.d.ts +0 -34
- package/types/use-gap-size-normalizer.d.ts +0 -8
- package/types/use-normalized-gap-size.d.ts +0 -9
- package/types/use-normalized-menu-items.d.ts +0 -16
- package/types/use-normalized-options.d.ts +0 -33
- package/types/use-option-filter.d.ts +0 -8
- package/types/use-remote-filter.d.ts +0 -9
- package/types/use-shallow-callback.d.ts +0 -10
- package/types/use-shallow-memo.d.ts +0 -10
- package/types/use-shallow-selector.d.ts +0 -8
- package/types/use-singleton.d.ts +0 -7
- package/types/use-theme-tokens.d.ts +0 -6
- package/types/use-transient-store.d.ts +0 -34
- package/types/use-window-size.d.ts +0 -17
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import '../lib.js';
|
|
3
|
+
import { useDeepCompare } from '../use-deep-compare/index.js';
|
|
4
|
+
import { useIsomorphicEffect } from '@mantine/hooks';
|
|
5
|
+
|
|
6
|
+
function useDeepIsomorphicEffect(effect, dependencies) {
|
|
7
|
+
return useIsomorphicEffect(effect, useDeepCompare(dependencies));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { useDeepIsomorphicEffect };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useLayoutEffect } from 'react';
|
|
3
|
+
import { useDeepCompare } from '../use-deep-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useDeepLayoutEffect(effect, dependencies) {
|
|
6
|
+
return useLayoutEffect(effect, useDeepCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useDeepLayoutEffect };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useDeepCompare } from '../use-deep-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useDeepMemo(factory, dependencies) {
|
|
6
|
+
return useMemo(factory, useDeepCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useDeepMemo };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useLatest } from '../use-latest/index.js';
|
|
3
|
+
import { useShallowEffect } from '../use-shallow-effect/index.js';
|
|
4
|
+
|
|
5
|
+
function useDocumentEvent(type, listener, options) {
|
|
6
|
+
const listenerFn = useLatest(listener);
|
|
7
|
+
useShallowEffect(() => {
|
|
8
|
+
function handleEvent(event) {
|
|
9
|
+
listenerFn.current.call(this, event);
|
|
10
|
+
}
|
|
11
|
+
document.addEventListener(type, handleEvent, options);
|
|
12
|
+
return () => {
|
|
13
|
+
document.removeEventListener(type, handleEvent, options);
|
|
14
|
+
};
|
|
15
|
+
}, [type, options, listenerFn]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useDocumentEvent };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import '@vef-framework/shared';
|
|
3
|
+
import { useEffectEvent, useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
function useEmitterEvent(emitter, eventType, eventListener) {
|
|
6
|
+
const listenerFn = useEffectEvent(eventListener);
|
|
7
|
+
useEffect(
|
|
8
|
+
() => {
|
|
9
|
+
const handler = (...args) => {
|
|
10
|
+
listenerFn(...args);
|
|
11
|
+
};
|
|
12
|
+
return emitter.on(eventType, handler);
|
|
13
|
+
},
|
|
14
|
+
[emitter, eventType]
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useEmitterEvent };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useIsFetching } from '@vef-framework/core';
|
|
3
|
+
|
|
4
|
+
function useHasFetching(key, params) {
|
|
5
|
+
const count = useIsFetching({
|
|
6
|
+
queryKey: params ? [key, params] : [key],
|
|
7
|
+
exact: false,
|
|
8
|
+
type: "active"
|
|
9
|
+
});
|
|
10
|
+
return count > 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { useHasFetching };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useIsMutating } from '@vef-framework/core';
|
|
3
|
+
|
|
4
|
+
function useHasMutating(key) {
|
|
5
|
+
const count = useIsMutating({
|
|
6
|
+
mutationKey: [key],
|
|
7
|
+
exact: false
|
|
8
|
+
});
|
|
9
|
+
return count > 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useHasMutating };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useAppContext, checkPermission } from '@vef-framework/core';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
function useIsAuthorized(permTokens, checkMode) {
|
|
6
|
+
const { hasPermission = () => true } = useAppContext();
|
|
7
|
+
const isAuthorized = useMemo(
|
|
8
|
+
() => checkPermission(hasPermission, permTokens, checkMode),
|
|
9
|
+
[permTokens, checkMode, hasPermission]
|
|
10
|
+
);
|
|
11
|
+
return isAuthorized;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { useIsAuthorized };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function useRafState(initialState) {
|
|
5
|
+
const frameId = useRef(0);
|
|
6
|
+
const [state, setState] = useState(initialState);
|
|
7
|
+
const setRafState = useCallback((state2) => {
|
|
8
|
+
cancelAnimationFrame(frameId.current);
|
|
9
|
+
frameId.current = requestAnimationFrame(() => {
|
|
10
|
+
setState(state2);
|
|
11
|
+
});
|
|
12
|
+
}, []);
|
|
13
|
+
useEffect(() => () => {
|
|
14
|
+
cancelAnimationFrame(frameId.current);
|
|
15
|
+
}, []);
|
|
16
|
+
return [state, setRafState];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { useRafState };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useShallowCompare } from '../use-shallow-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useShallowCallback(callback, dependencies) {
|
|
6
|
+
return useCallback(callback, useShallowCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useShallowCallback };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { isShallowEqual } from '@vef-framework/shared';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
function useShallowCompare(dependencies) {
|
|
6
|
+
const ref = useRef(void 0);
|
|
7
|
+
const signalRef = useRef(0);
|
|
8
|
+
if (!shallowCompare(ref.current, dependencies)) {
|
|
9
|
+
ref.current = dependencies;
|
|
10
|
+
signalRef.current += 1;
|
|
11
|
+
}
|
|
12
|
+
return [signalRef.current];
|
|
13
|
+
}
|
|
14
|
+
function shallowCompare(previous, current) {
|
|
15
|
+
if (!previous || !current) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (Object.is(previous, current)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (previous.length !== current.length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
for (const [index, element] of previous.entries()) {
|
|
25
|
+
if (!isShallowEqual(element, current[index])) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { useShallowCompare };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useShallowCompare } from '../use-shallow-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useShallowEffect(effect, dependencies) {
|
|
6
|
+
return useEffect(effect, useShallowCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useShallowEffect };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import '../lib.js';
|
|
3
|
+
import { useShallowCompare } from '../use-shallow-compare/index.js';
|
|
4
|
+
import { useIsomorphicEffect } from '@mantine/hooks';
|
|
5
|
+
|
|
6
|
+
function useShallowIsomorphicEffect(effect, dependencies) {
|
|
7
|
+
return useIsomorphicEffect(effect, useShallowCompare(dependencies));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { useShallowIsomorphicEffect };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useLayoutEffect } from 'react';
|
|
3
|
+
import { useShallowCompare } from '../use-shallow-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useShallowLayoutEffect(effect, dependencies) {
|
|
6
|
+
return useLayoutEffect(effect, useShallowCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useShallowLayoutEffect };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useShallowCompare } from '../use-shallow-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useShallowMemo(factory, dependencies) {
|
|
6
|
+
return useMemo(factory, useShallowCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useShallowMemo };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
function useSingleton(initializer) {
|
|
5
|
+
const ref = useRef(null);
|
|
6
|
+
if (ref.current === null) {
|
|
7
|
+
ref.current = initializer();
|
|
8
|
+
}
|
|
9
|
+
return ref;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useSingleton };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { assignRef, getHotkeyHandler, HotkeysProvider, mergeRefs, useColorScheme, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDidUpdate, useDocumentTitle, useElementSize, useEventListener, useFocusTrap, useFullscreen, useHotkeys, useHotkeysContext, useIntersection, useInterval, useIsFirstRender, useIsomorphicEffect, useMediaQuery, useMergedRef, useMounted, useMutationObserver, usePrevious, useRecordHotkeys, useReducedMotion, useResizeObserver, useTimeout, useWindowEvent, type HotkeyCallback, type HotkeysOptions } from './lib';
|
|
2
|
+
export { useAuthorizedItems, type PermissionAware } from './use-authorized-items';
|
|
3
|
+
export { useBreakpoints, type Breakpoints, type UseBreakpointsOptions, type UseBreakpointsResult } from './use-breakpoints';
|
|
4
|
+
export { useCheckPermission } from './use-check-permission';
|
|
5
|
+
export { useDataDictQuery, type UseDataDictQueryOptions } from './use-data-dict-query';
|
|
6
|
+
export { useDataOptionsQuery, type FieldExtractor, type UseDataOptionsQueryOptions, type UseDataOptionsQueryResult } from './use-data-options';
|
|
7
|
+
export { useDeepCallback } from './use-deep-callback';
|
|
8
|
+
export { useDeepCompare } from './use-deep-compare';
|
|
9
|
+
export { useDeepEffect } from './use-deep-effect';
|
|
10
|
+
export { useDeepIsomorphicEffect } from './use-deep-isomorphic-effect';
|
|
11
|
+
export { useDeepLayoutEffect } from './use-deep-layout-effect';
|
|
12
|
+
export { useDeepMemo } from './use-deep-memo';
|
|
13
|
+
export { useDocumentEvent } from './use-document-event';
|
|
14
|
+
export { useEmitterEvent } from './use-emitter-event';
|
|
15
|
+
export { useHasFetching } from './use-has-fetching';
|
|
16
|
+
export { useHasMutating } from './use-has-mutating';
|
|
17
|
+
export { useIsAuthorized } from './use-is-authorized';
|
|
18
|
+
export { useLatest } from './use-latest';
|
|
19
|
+
export { useRafState } from './use-raf-state';
|
|
20
|
+
export { useShallowCallback } from './use-shallow-callback';
|
|
21
|
+
export { useShallowCompare } from './use-shallow-compare';
|
|
22
|
+
export { useShallowEffect } from './use-shallow-effect';
|
|
23
|
+
export { useShallowIsomorphicEffect } from './use-shallow-isomorphic-effect';
|
|
24
|
+
export { useShallowLayoutEffect } from './use-shallow-layout-effect';
|
|
25
|
+
export { useShallowMemo } from './use-shallow-memo';
|
|
26
|
+
export { useSingleton, type SingletonRefObject } from './use-singleton';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UseColorSchemeValue, UseMediaQueryOptions } from '@mantine/hooks';
|
|
2
|
+
export declare function useMediaQuery(query: string, initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
3
|
+
export declare function useColorScheme(initialValue?: UseColorSchemeValue, options?: UseMediaQueryOptions): UseColorSchemeValue;
|
|
4
|
+
export declare function useReducedMotion(initialValue?: boolean, options?: UseMediaQueryOptions): boolean;
|
|
5
|
+
export { assignRef, getHotkeyHandler, mergeRefs, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDidUpdate, useDocumentTitle, useElementSize, useEventListener, useFocusTrap, useFullscreen, useIntersection, useInterval, useIsFirstRender, useIsomorphicEffect, useMergedRef, useMounted, useMutationObserver, usePrevious, useResizeObserver, useTimeout, useWindowEvent } from '@mantine/hooks';
|
|
6
|
+
export { HotkeysProvider, useHotkeys, useHotkeysContext, useRecordHotkeys, type HotkeyCallback, type Options as HotkeysOptions } from 'react-hotkeys-hook';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
2
3
|
/**
|
|
3
4
|
* The permission aware interface.
|
|
4
5
|
*/
|
|
5
6
|
export interface PermissionAware {
|
|
6
7
|
/**
|
|
7
|
-
* The permission tokens.
|
|
8
|
+
* The permission tokens to check.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
permTokens?: MaybeArray<string>;
|
|
10
11
|
/**
|
|
11
12
|
* The permission check mode.
|
|
12
13
|
*/
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type BreakpointValue = number | string;
|
|
2
|
+
export type Breakpoints<T extends string = string> = Record<T, BreakpointValue>;
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by useBreakpoints hook
|
|
5
|
+
*/
|
|
6
|
+
export interface UseBreakpointsResult<T extends string = string> {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the current active breakpoint (largest matching)
|
|
9
|
+
*/
|
|
10
|
+
current?: T;
|
|
11
|
+
/**
|
|
12
|
+
* The numeric value of the current breakpoint
|
|
13
|
+
*/
|
|
14
|
+
value?: BreakpointValue;
|
|
15
|
+
/**
|
|
16
|
+
* Array of all matching breakpoint names
|
|
17
|
+
*/
|
|
18
|
+
matches: T[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for useBreakpoints hook
|
|
22
|
+
*/
|
|
23
|
+
export interface UseBreakpointsOptions<T extends string = string> {
|
|
24
|
+
/**
|
|
25
|
+
* Initial breakpoint name for SSR (server-side rendering)
|
|
26
|
+
* If not provided, will default to null during SSR
|
|
27
|
+
*/
|
|
28
|
+
initialBreakpoint?: T;
|
|
29
|
+
/**
|
|
30
|
+
* Get initial value in effect instead of on mount
|
|
31
|
+
* This helps avoid hydration mismatches in SSR
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
getInitialValueInEffect?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
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
|
|
42
|
+
*
|
|
43
|
+
* @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.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useBreakpoints<T extends string>(breakpoints: Breakpoints<T>, options?: UseBreakpointsOptions<T>): UseBreakpointsResult<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* The use check permission hook.
|
|
5
|
+
*
|
|
6
|
+
* @returns The check permission function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useCheckPermission(): (permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataOption, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
|
|
2
|
+
import { Except } from '@vef-framework/shared';
|
|
3
|
+
export type UseDataDictQueryOptions<TData = DataOption> = Except<UseQueryOptions<DataOption[], TData[]>, "queryFn" | "queryKey" | "queryHash" | "queryKeyHashFn"> & {
|
|
4
|
+
dataDictKey?: string;
|
|
5
|
+
onFetch?: (data: TData[]) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A hook for querying data dictionary.
|
|
9
|
+
* Uses the dataDictQueryFn from app context to fetch data dictionary options.
|
|
10
|
+
*
|
|
11
|
+
* @param dataDictKey - The key of the data dictionary to query.
|
|
12
|
+
* @param options - Additional query options (excluding queryFn and queryKey).
|
|
13
|
+
* @returns The query result containing data dictionary options.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDataDictQuery<TData = DataOption>({ dataDictKey, onFetch, ...options }: UseDataDictQueryOptions<TData>): UseQueryResult<TData[]>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DataOption, DataOptionWithPinyin, UseQueryOptions, UseQueryResult } from '@vef-framework/core';
|
|
2
|
+
import { Key, MaybeUndefined, Prettify } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Field extractor - can be a string path (e.g., "user.name") or a function
|
|
5
|
+
*/
|
|
6
|
+
export type FieldExtractor<TData, TValue> = string | ((item: TData) => TValue);
|
|
7
|
+
/**
|
|
8
|
+
* Base field mapping options
|
|
9
|
+
*/
|
|
10
|
+
export interface DataOptionsFieldMapping<TData = unknown> {
|
|
11
|
+
/**
|
|
12
|
+
* Field mapping for label
|
|
13
|
+
* @default "label"
|
|
14
|
+
*/
|
|
15
|
+
labelKey?: FieldExtractor<TData, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Field mapping for value
|
|
18
|
+
* @default "value"
|
|
19
|
+
*/
|
|
20
|
+
valueKey?: FieldExtractor<TData, Key>;
|
|
21
|
+
/**
|
|
22
|
+
* Field mapping for disabled
|
|
23
|
+
* @default "disabled"
|
|
24
|
+
*/
|
|
25
|
+
disabledKey?: FieldExtractor<TData, MaybeUndefined<boolean>>;
|
|
26
|
+
/**
|
|
27
|
+
* Field mapping for description
|
|
28
|
+
* @default "description"
|
|
29
|
+
*/
|
|
30
|
+
descriptionKey?: FieldExtractor<TData, MaybeUndefined<string>>;
|
|
31
|
+
/**
|
|
32
|
+
* Field mapping for children
|
|
33
|
+
* @default "children"
|
|
34
|
+
*/
|
|
35
|
+
childrenKey?: FieldExtractor<TData, MaybeUndefined<TData[]>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for useDataOptionsQuery with regular query
|
|
39
|
+
*/
|
|
40
|
+
export type UseDataOptionsQueryOptionsWithQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never> = DataOptionsFieldMapping<TData> & {
|
|
41
|
+
/**
|
|
42
|
+
* Options for fetching data using regular query
|
|
43
|
+
*/
|
|
44
|
+
queryOptions: UseQueryOptions<TQueryFnData[], TData[], TParams>;
|
|
45
|
+
/**
|
|
46
|
+
* Data dictionary key - should not be provided when using queryOptions
|
|
47
|
+
*/
|
|
48
|
+
dataDictKey?: never;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Options for useDataOptionsQuery with data dictionary query
|
|
52
|
+
*/
|
|
53
|
+
export type UseDataOptionsQueryOptionsWithDataDict<TData = DataOption> = DataOptionsFieldMapping<TData> & {
|
|
54
|
+
/**
|
|
55
|
+
* Data dictionary key
|
|
56
|
+
*/
|
|
57
|
+
dataDictKey: string;
|
|
58
|
+
/**
|
|
59
|
+
* Regular query options - should not be provided when using dataDictKey
|
|
60
|
+
*/
|
|
61
|
+
queryOptions?: never;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Options for useDataOptionsQuery hook - supports both regular query and data dictionary query
|
|
65
|
+
*/
|
|
66
|
+
export type UseDataOptionsQueryOptions<TQueryFnData = unknown, TData = TQueryFnData, TParams = never> = UseDataOptionsQueryOptionsWithQuery<TQueryFnData, TData, TParams> | UseDataOptionsQueryOptionsWithDataDict<TData>;
|
|
67
|
+
/**
|
|
68
|
+
* Return type for useDataOptionsQuery hook
|
|
69
|
+
*/
|
|
70
|
+
export type UseDataOptionsQueryResult<TData, TOption> = Prettify<Omit<UseQueryResult<TData[]>, "data"> & {
|
|
71
|
+
options: TOption[];
|
|
72
|
+
}>;
|
|
73
|
+
export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(config: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams>): UseDataOptionsQueryResult<TData, DataOption<TData>>;
|
|
74
|
+
export declare function useDataOptionsQuery<TQueryFnData = unknown, TData = TQueryFnData, TParams = never>(options: UseDataOptionsQueryOptions<TQueryFnData, TData, TParams> & {
|
|
75
|
+
/**
|
|
76
|
+
* Whether to add pinyin fields for label and description
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
withPinyin: boolean;
|
|
80
|
+
}): UseDataOptionsQueryResult<TData, DataOptionWithPinyin<TData>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep callback of the callback
|
|
4
|
+
*
|
|
5
|
+
* @param callback - The callback to memo.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The memoized callback.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepCallback<T extends Function>(callback: T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep compare of the dependencies
|
|
4
|
+
*
|
|
5
|
+
* @param dependencies - The dependencies to compare.
|
|
6
|
+
* @returns The signal of the dependencies.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDeepCompare(dependencies?: DependencyList): readonly [number];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep isomorphic effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep layout effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the deep memo of the factory
|
|
4
|
+
*
|
|
5
|
+
* @param factory - The factory to memo.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The memoized value.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDeepMemo<T>(factory: () => T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to listen for document events.
|
|
3
|
+
*
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDocumentEvent<TType extends string>(type: TType, listener: TType extends keyof DocumentEventMap ? (this: Document, event: DocumentEventMap[TType]) => void : (this: Document, event: CustomEvent) => void, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventHandler, EventType, EventEmitter } from '@vef-framework/shared';
|
|
2
|
+
/**
|
|
3
|
+
* A hook to listen to an event from an EventEmitter.
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useEmitterEvent<TEvents extends Record<EventType, unknown>>(emitter: EventEmitter<TEvents>, eventType: keyof TEvents, eventListener: EventHandler<TEvents[keyof TEvents]>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook to check if there are any active queries fetching for a specific query key.
|
|
3
|
+
*
|
|
4
|
+
* @param key - The base query key to check for fetching status.
|
|
5
|
+
* @param params - Optional parameters to include in the query key for more specific filtering.
|
|
6
|
+
* @returns True if there are any active queries fetching with the specified key, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useHasFetching(key: string, params?: unknown): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook to check if there are any active mutations for a specific mutation key.
|
|
3
|
+
*
|
|
4
|
+
* @param key - The base mutation key to check for mutating status.
|
|
5
|
+
* @returns True if there are any active mutations with the specified key, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useHasMutating(key: string): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PermissionCheckMode } from '@vef-framework/core';
|
|
2
|
+
import { MaybeArray } from '@vef-framework/shared';
|
|
3
|
+
/**
|
|
4
|
+
* The use is authorized hook.
|
|
5
|
+
*
|
|
6
|
+
* @param permTokens - The permission tokens to check.
|
|
7
|
+
* @param checkMode - The check mode to use.
|
|
8
|
+
* @returns Whether the user is authorized to access the resource identified by the permission token.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useIsAuthorized(permTokens?: MaybeArray<string>, checkMode?: PermissionCheckMode): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A hook to use the request animation frame state.
|
|
4
|
+
*
|
|
5
|
+
* @param initialState - The initial state.
|
|
6
|
+
* @returns The state and the set state function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useRafState<T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the shallow callback of the callback
|
|
4
|
+
*
|
|
5
|
+
* @param callback - The callback to memo.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The memoized callback.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useShallowCallback<T extends Function>(callback: T, dependencies: DependencyList): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the shallow compare of the dependencies
|
|
4
|
+
*
|
|
5
|
+
* @param dependencies - The dependencies to compare.
|
|
6
|
+
* @returns The signal of the dependencies.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useShallowCompare(dependencies?: DependencyList): readonly [number];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the shallow effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useShallowEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the shallow isomorphic effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useShallowIsomorphicEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Use the shallow layout effect of the effect
|
|
4
|
+
*
|
|
5
|
+
* @param effect - The effect to run.
|
|
6
|
+
* @param dependencies - The dependencies to compare.
|
|
7
|
+
* @returns The effect.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useShallowLayoutEffect(effect: EffectCallback, dependencies?: DependencyList): void;
|