@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,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-deep-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useDeepLayoutEffect(effect, dependencies) {
|
|
10
|
+
return react.useLayoutEffect(effect, index.useDeepCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useDeepLayoutEffect = useDeepLayoutEffect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-deep-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useDeepMemo(factory, dependencies) {
|
|
10
|
+
return react.useMemo(factory, index.useDeepCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useDeepMemo = useDeepMemo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const index = require('../use-latest/index.cjs');
|
|
7
|
+
const index$1 = require('../use-shallow-effect/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useDocumentEvent(type, listener, options) {
|
|
10
|
+
const listenerFn = index.useLatest(listener);
|
|
11
|
+
index$1.useShallowEffect(() => {
|
|
12
|
+
function handleEvent(event) {
|
|
13
|
+
listenerFn.current.call(this, event);
|
|
14
|
+
}
|
|
15
|
+
document.addEventListener(type, handleEvent, options);
|
|
16
|
+
return () => {
|
|
17
|
+
document.removeEventListener(type, handleEvent, options);
|
|
18
|
+
};
|
|
19
|
+
}, [type, options, listenerFn]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.useDocumentEvent = useDocumentEvent;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useEmitterEvent(emitter, eventType, eventListener) {
|
|
10
|
+
const listenerFn = react.useEffectEvent(eventListener);
|
|
11
|
+
react.useEffect(
|
|
12
|
+
() => {
|
|
13
|
+
const handler = (...args) => {
|
|
14
|
+
listenerFn(...args);
|
|
15
|
+
};
|
|
16
|
+
return emitter.on(eventType, handler);
|
|
17
|
+
},
|
|
18
|
+
[emitter, eventType]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.useEmitterEvent = useEmitterEvent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const core = require('@vef-framework/core');
|
|
7
|
+
|
|
8
|
+
function useHasFetching(key, params) {
|
|
9
|
+
const count = core.useIsFetching({
|
|
10
|
+
queryKey: params ? [key, params] : [key],
|
|
11
|
+
exact: false,
|
|
12
|
+
type: "active"
|
|
13
|
+
});
|
|
14
|
+
return count > 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.useHasFetching = useHasFetching;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const core = require('@vef-framework/core');
|
|
7
|
+
|
|
8
|
+
function useHasMutating(key) {
|
|
9
|
+
const count = core.useIsMutating({
|
|
10
|
+
mutationKey: [key],
|
|
11
|
+
exact: false
|
|
12
|
+
});
|
|
13
|
+
return count > 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.useHasMutating = useHasMutating;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const core = require('@vef-framework/core');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useIsAuthorized(permTokens, checkMode) {
|
|
10
|
+
const { hasPermission = () => true } = core.useAppContext();
|
|
11
|
+
const isAuthorized = react.useMemo(
|
|
12
|
+
() => core.checkPermission(hasPermission, permTokens, checkMode),
|
|
13
|
+
[permTokens, checkMode, hasPermission]
|
|
14
|
+
);
|
|
15
|
+
return isAuthorized;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.useIsAuthorized = useIsAuthorized;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
function useLatest(value) {
|
|
9
|
+
const ref = react.useRef(value);
|
|
10
|
+
ref.current = value;
|
|
11
|
+
return ref;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.useLatest = useLatest;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
function useRafState(initialState) {
|
|
9
|
+
const frameId = react.useRef(0);
|
|
10
|
+
const [state, setState] = react.useState(initialState);
|
|
11
|
+
const setRafState = react.useCallback((state2) => {
|
|
12
|
+
cancelAnimationFrame(frameId.current);
|
|
13
|
+
frameId.current = requestAnimationFrame(() => {
|
|
14
|
+
setState(state2);
|
|
15
|
+
});
|
|
16
|
+
}, []);
|
|
17
|
+
react.useEffect(() => () => {
|
|
18
|
+
cancelAnimationFrame(frameId.current);
|
|
19
|
+
}, []);
|
|
20
|
+
return [state, setRafState];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.useRafState = useRafState;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-shallow-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useShallowCallback(callback, dependencies) {
|
|
10
|
+
return react.useCallback(callback, index.useShallowCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useShallowCallback = useShallowCallback;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useShallowCompare(dependencies) {
|
|
10
|
+
const ref = react.useRef(void 0);
|
|
11
|
+
const signalRef = react.useRef(0);
|
|
12
|
+
if (!shallowCompare(ref.current, dependencies)) {
|
|
13
|
+
ref.current = dependencies;
|
|
14
|
+
signalRef.current += 1;
|
|
15
|
+
}
|
|
16
|
+
return [signalRef.current];
|
|
17
|
+
}
|
|
18
|
+
function shallowCompare(previous, current) {
|
|
19
|
+
if (!previous || !current) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (Object.is(previous, current)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (previous.length !== current.length) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (const [index, element] of previous.entries()) {
|
|
29
|
+
if (!shared.isShallowEqual(element, current[index])) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.useShallowCompare = useShallowCompare;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-shallow-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useShallowEffect(effect, dependencies) {
|
|
10
|
+
return react.useEffect(effect, index.useShallowCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useShallowEffect = useShallowEffect;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
require('../lib.cjs');
|
|
7
|
+
const index = require('../use-shallow-compare/index.cjs');
|
|
8
|
+
const hooks = require('@mantine/hooks');
|
|
9
|
+
|
|
10
|
+
function useShallowIsomorphicEffect(effect, dependencies) {
|
|
11
|
+
return hooks.useIsomorphicEffect(effect, index.useShallowCompare(dependencies));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.useShallowIsomorphicEffect = useShallowIsomorphicEffect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-shallow-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useShallowLayoutEffect(effect, dependencies) {
|
|
10
|
+
return react.useLayoutEffect(effect, index.useShallowCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useShallowLayoutEffect = useShallowLayoutEffect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const index = require('../use-shallow-compare/index.cjs');
|
|
8
|
+
|
|
9
|
+
function useShallowMemo(factory, dependencies) {
|
|
10
|
+
return react.useMemo(factory, index.useShallowCompare(dependencies));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useShallowMemo = useShallowMemo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
function useSingleton(initializer) {
|
|
9
|
+
const ref = react.useRef(null);
|
|
10
|
+
if (ref.current === null) {
|
|
11
|
+
ref.current = initializer();
|
|
12
|
+
}
|
|
13
|
+
return ref;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.useSingleton = useSingleton;
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
export { useColorScheme, useMediaQuery, useReducedMotion } from './lib.js';
|
|
3
|
+
export { useAuthorizedItems } from './use-authorized-items/index.js';
|
|
4
|
+
export { useBreakpoints } from './use-breakpoints/index.js';
|
|
5
|
+
export { useCheckPermission } from './use-check-permission/index.js';
|
|
6
|
+
export { useDataDictQuery } from './use-data-dict-query/index.js';
|
|
7
|
+
export { useDataOptionsQuery } from './use-data-options/index.js';
|
|
8
|
+
export { useDeepCallback } from './use-deep-callback/index.js';
|
|
9
|
+
export { useDeepCompare } from './use-deep-compare/index.js';
|
|
10
|
+
export { useDeepEffect } from './use-deep-effect/index.js';
|
|
11
|
+
export { useDeepIsomorphicEffect } from './use-deep-isomorphic-effect/index.js';
|
|
12
|
+
export { useDeepLayoutEffect } from './use-deep-layout-effect/index.js';
|
|
13
|
+
export { useDeepMemo } from './use-deep-memo/index.js';
|
|
14
|
+
export { useDocumentEvent } from './use-document-event/index.js';
|
|
15
|
+
export { useEmitterEvent } from './use-emitter-event/index.js';
|
|
16
|
+
export { useHasFetching } from './use-has-fetching/index.js';
|
|
17
|
+
export { useHasMutating } from './use-has-mutating/index.js';
|
|
18
|
+
export { useIsAuthorized } from './use-is-authorized/index.js';
|
|
19
|
+
export { useLatest } from './use-latest/index.js';
|
|
20
|
+
export { useRafState } from './use-raf-state/index.js';
|
|
21
|
+
export { useShallowCallback } from './use-shallow-callback/index.js';
|
|
22
|
+
export { useShallowCompare } from './use-shallow-compare/index.js';
|
|
23
|
+
export { useShallowEffect } from './use-shallow-effect/index.js';
|
|
24
|
+
export { useShallowIsomorphicEffect } from './use-shallow-isomorphic-effect/index.js';
|
|
25
|
+
export { useShallowLayoutEffect } from './use-shallow-layout-effect/index.js';
|
|
26
|
+
export { useShallowMemo } from './use-shallow-memo/index.js';
|
|
27
|
+
export { useSingleton } from './use-singleton/index.js';
|
|
28
|
+
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';
|
|
29
|
+
export { HotkeysProvider, useHotkeys, useHotkeysContext, useRecordHotkeys } from 'react-hotkeys-hook';
|
package/dist/es/lib.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useMediaQuery as useMediaQuery$1, useColorScheme as useColorScheme$1, useReducedMotion as useReducedMotion$1 } from '@mantine/hooks';
|
|
3
|
+
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';
|
|
4
|
+
export { HotkeysProvider, useHotkeys, useHotkeysContext, useRecordHotkeys } from 'react-hotkeys-hook';
|
|
5
|
+
|
|
6
|
+
function useMediaQuery(query, initialValue, options) {
|
|
7
|
+
const { getInitialValueInEffect = false } = options ?? {};
|
|
8
|
+
return useMediaQuery$1(
|
|
9
|
+
query,
|
|
10
|
+
initialValue,
|
|
11
|
+
{
|
|
12
|
+
getInitialValueInEffect
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function useColorScheme(initialValue, options) {
|
|
17
|
+
const { getInitialValueInEffect = false } = options ?? {};
|
|
18
|
+
return useColorScheme$1(
|
|
19
|
+
initialValue,
|
|
20
|
+
{
|
|
21
|
+
getInitialValueInEffect
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function useReducedMotion(initialValue, options) {
|
|
26
|
+
const { getInitialValueInEffect = false } = options ?? {};
|
|
27
|
+
return useReducedMotion$1(
|
|
28
|
+
initialValue,
|
|
29
|
+
{
|
|
30
|
+
getInitialValueInEffect
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { useColorScheme, useMediaQuery, useReducedMotion };
|
|
@@ -0,0 +1,16 @@
|
|
|
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 useAuthorizedItems(items) {
|
|
6
|
+
const { hasPermission = () => true } = useAppContext();
|
|
7
|
+
return useMemo(
|
|
8
|
+
() => items.filter((item) => {
|
|
9
|
+
const { permTokens, checkMode = "any" } = item;
|
|
10
|
+
return checkPermission(hasPermission, permTokens, checkMode);
|
|
11
|
+
}),
|
|
12
|
+
[items, hasPermission]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { useAuthorizedItems };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { isNumber } from '@vef-framework/shared';
|
|
3
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
function createMediaQuery(value) {
|
|
6
|
+
return `(min-width: ${isNumber(value) ? `${value}px` : value})`;
|
|
7
|
+
}
|
|
8
|
+
function useBreakpoints(breakpoints, options = {}) {
|
|
9
|
+
const { initialBreakpoint, getInitialValueInEffect = false } = options;
|
|
10
|
+
const sortedBreakpoints = useMemo(
|
|
11
|
+
() => Object.entries(breakpoints).map(([name, value]) => {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
value,
|
|
15
|
+
query: createMediaQuery(value),
|
|
16
|
+
order: isNumber(value) ? value : Number.parseInt(value)
|
|
17
|
+
};
|
|
18
|
+
}).toSorted((a, b) => a.order - b.order),
|
|
19
|
+
[breakpoints]
|
|
20
|
+
);
|
|
21
|
+
const [state, setState] = useState(() => {
|
|
22
|
+
if (globalThis.window === void 0 || getInitialValueInEffect) {
|
|
23
|
+
const initialEntry = sortedBreakpoints.find((bp) => bp.name === initialBreakpoint);
|
|
24
|
+
return {
|
|
25
|
+
current: initialBreakpoint,
|
|
26
|
+
value: initialEntry?.value,
|
|
27
|
+
matches: initialBreakpoint ? [initialBreakpoint] : []
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const matchingBreakpoints = sortedBreakpoints.filter((bp) => globalThis.matchMedia(bp.query).matches);
|
|
31
|
+
const currentBreakpoint = matchingBreakpoints.at(-1);
|
|
32
|
+
return {
|
|
33
|
+
current: currentBreakpoint?.name,
|
|
34
|
+
value: currentBreakpoint?.value,
|
|
35
|
+
matches: matchingBreakpoints.map((bp) => bp.name)
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const mediaQueryLists = sortedBreakpoints.map((bp) => {
|
|
40
|
+
return {
|
|
41
|
+
name: bp.name,
|
|
42
|
+
value: bp.value,
|
|
43
|
+
mql: globalThis.matchMedia(bp.query)
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const updateBreakpoint = () => {
|
|
47
|
+
const matchingBreakpoints = mediaQueryLists.filter((item) => item.mql.matches);
|
|
48
|
+
const currentBreakpoint = matchingBreakpoints.at(-1);
|
|
49
|
+
setState({
|
|
50
|
+
current: currentBreakpoint?.name,
|
|
51
|
+
value: currentBreakpoint?.value,
|
|
52
|
+
matches: matchingBreakpoints.map((mbp) => mbp.name)
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
if (getInitialValueInEffect) {
|
|
56
|
+
updateBreakpoint();
|
|
57
|
+
}
|
|
58
|
+
for (const item of mediaQueryLists) {
|
|
59
|
+
item.mql.addEventListener("change", updateBreakpoint);
|
|
60
|
+
}
|
|
61
|
+
return () => {
|
|
62
|
+
for (const item of mediaQueryLists) {
|
|
63
|
+
item.mql.removeEventListener("change", updateBreakpoint);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}, [getInitialValueInEffect, sortedBreakpoints]);
|
|
67
|
+
return state;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { useBreakpoints };
|
|
@@ -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 { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
function useCheckPermission() {
|
|
6
|
+
const { hasPermission = () => true } = useAppContext();
|
|
7
|
+
const checkPermission$1 = useCallback(
|
|
8
|
+
(permTokens, checkMode) => checkPermission(hasPermission, permTokens, checkMode),
|
|
9
|
+
[hasPermission]
|
|
10
|
+
);
|
|
11
|
+
return checkPermission$1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { useCheckPermission };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useAppContext, useQuery, skipQueryToken } from '@vef-framework/core';
|
|
3
|
+
import { isFunction, isEmpty } from '@vef-framework/shared';
|
|
4
|
+
import { useEffectEvent, useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
function useDataDictQuery({
|
|
7
|
+
dataDictKey,
|
|
8
|
+
onFetch,
|
|
9
|
+
...options
|
|
10
|
+
}) {
|
|
11
|
+
const { dataDictQueryFn } = useAppContext();
|
|
12
|
+
if (!isFunction(dataDictQueryFn)) {
|
|
13
|
+
throw new Error("Data dictionary query function is not provided in the app context.");
|
|
14
|
+
}
|
|
15
|
+
const result = useQuery({
|
|
16
|
+
...options,
|
|
17
|
+
queryFn: isEmpty(dataDictKey) ? skipQueryToken : dataDictQueryFn,
|
|
18
|
+
queryKey: [dataDictQueryFn.key, dataDictKey],
|
|
19
|
+
staleTime: options?.staleTime ?? Infinity
|
|
20
|
+
});
|
|
21
|
+
const onFetchFn = useEffectEvent((data) => {
|
|
22
|
+
onFetch?.(data);
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
result.promise.then(onFetchFn);
|
|
26
|
+
}, [result.promise]);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { useDataDictQuery };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { useQuery, skipQueryToken } from '@vef-framework/core';
|
|
3
|
+
import { isFunction, get, isNullish, withPinyin, isEmpty, isString } from '@vef-framework/shared';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { useDataDictQuery } from '../use-data-dict-query/index.js';
|
|
6
|
+
|
|
7
|
+
function extractField(item, extractor, defaultKey) {
|
|
8
|
+
if (!extractor) {
|
|
9
|
+
return item[defaultKey];
|
|
10
|
+
}
|
|
11
|
+
if (isFunction(extractor)) {
|
|
12
|
+
return extractor(item);
|
|
13
|
+
}
|
|
14
|
+
return get(item, extractor);
|
|
15
|
+
}
|
|
16
|
+
function transformDataItem(item, options, withPinyin$1) {
|
|
17
|
+
const {
|
|
18
|
+
labelKey,
|
|
19
|
+
valueKey,
|
|
20
|
+
disabledKey,
|
|
21
|
+
descriptionKey,
|
|
22
|
+
childrenKey
|
|
23
|
+
} = options;
|
|
24
|
+
const label = extractField(item, labelKey, "label");
|
|
25
|
+
const value = extractField(item, valueKey, "value");
|
|
26
|
+
const disabled = extractField(item, disabledKey, "disabled");
|
|
27
|
+
const description = extractField(item, descriptionKey, "description");
|
|
28
|
+
const children = extractField(item, childrenKey, "children");
|
|
29
|
+
const option = {
|
|
30
|
+
...item,
|
|
31
|
+
label,
|
|
32
|
+
value,
|
|
33
|
+
...!isNullish(disabled) && { disabled },
|
|
34
|
+
...!isNullish(description) && { description }
|
|
35
|
+
};
|
|
36
|
+
const optionWithPinyin = withPinyin$1 ? withPinyin(
|
|
37
|
+
option,
|
|
38
|
+
"label",
|
|
39
|
+
"description"
|
|
40
|
+
) : option;
|
|
41
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
42
|
+
optionWithPinyin.children = children.map((child) => transformDataItem(child, options, withPinyin$1));
|
|
43
|
+
}
|
|
44
|
+
return optionWithPinyin;
|
|
45
|
+
}
|
|
46
|
+
function transformData(data, options, withPinyin) {
|
|
47
|
+
if (!data || isEmpty(data)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
if (withPinyin) {
|
|
51
|
+
return data.map((item) => transformDataItem(item, options, true));
|
|
52
|
+
}
|
|
53
|
+
return data.map((item) => transformDataItem(item, options, false));
|
|
54
|
+
}
|
|
55
|
+
function useDataOptionsQuery({
|
|
56
|
+
queryOptions,
|
|
57
|
+
dataDictKey,
|
|
58
|
+
labelKey,
|
|
59
|
+
valueKey,
|
|
60
|
+
disabledKey,
|
|
61
|
+
descriptionKey,
|
|
62
|
+
childrenKey,
|
|
63
|
+
withPinyin = false
|
|
64
|
+
}) {
|
|
65
|
+
const isDataDictQuery = isString(dataDictKey) && dataDictKey.length > 0;
|
|
66
|
+
const queryResult = useQuery({
|
|
67
|
+
...queryOptions,
|
|
68
|
+
queryFn: isDataDictQuery ? skipQueryToken : queryOptions?.queryFn
|
|
69
|
+
});
|
|
70
|
+
const dictQueryResult = useDataDictQuery({
|
|
71
|
+
dataDictKey
|
|
72
|
+
});
|
|
73
|
+
const mergedResult = isDataDictQuery ? dictQueryResult : queryResult;
|
|
74
|
+
const { data, ...result } = mergedResult;
|
|
75
|
+
const options = useMemo(
|
|
76
|
+
() => {
|
|
77
|
+
if (withPinyin) {
|
|
78
|
+
return transformData(
|
|
79
|
+
data,
|
|
80
|
+
{
|
|
81
|
+
labelKey,
|
|
82
|
+
valueKey,
|
|
83
|
+
disabledKey,
|
|
84
|
+
descriptionKey,
|
|
85
|
+
childrenKey
|
|
86
|
+
},
|
|
87
|
+
true
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return transformData(
|
|
91
|
+
data,
|
|
92
|
+
{
|
|
93
|
+
labelKey,
|
|
94
|
+
valueKey,
|
|
95
|
+
disabledKey,
|
|
96
|
+
descriptionKey,
|
|
97
|
+
childrenKey
|
|
98
|
+
},
|
|
99
|
+
false
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
[
|
|
103
|
+
data,
|
|
104
|
+
labelKey,
|
|
105
|
+
valueKey,
|
|
106
|
+
disabledKey,
|
|
107
|
+
descriptionKey,
|
|
108
|
+
childrenKey,
|
|
109
|
+
withPinyin
|
|
110
|
+
]
|
|
111
|
+
);
|
|
112
|
+
return { options, ...result };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { useDataOptionsQuery };
|
|
@@ -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 { useDeepCompare } from '../use-deep-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useDeepCallback(callback, dependencies) {
|
|
6
|
+
return useCallback(callback, useDeepCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useDeepCallback };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*! @vef-framework/hooks v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:31.592Z */
|
|
2
|
+
import { isDeepEqual } from '@vef-framework/shared';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
function useDeepCompare(dependencies) {
|
|
6
|
+
const ref = useRef(void 0);
|
|
7
|
+
const signalRef = useRef(0);
|
|
8
|
+
if (!deepCompare(ref.current, dependencies)) {
|
|
9
|
+
ref.current = dependencies;
|
|
10
|
+
signalRef.current += 1;
|
|
11
|
+
}
|
|
12
|
+
return [signalRef.current];
|
|
13
|
+
}
|
|
14
|
+
function deepCompare(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 (!isDeepEqual(element, current[index])) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { useDeepCompare };
|
|
@@ -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 { useDeepCompare } from '../use-deep-compare/index.js';
|
|
4
|
+
|
|
5
|
+
function useDeepEffect(effect, dependencies) {
|
|
6
|
+
return useEffect(effect, useDeepCompare(dependencies));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useDeepEffect };
|