@reactuses/core 6.0.7 → 6.1.0-beta.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.md +18 -29
- package/dist/index.cjs +199 -26
- package/dist/index.d.cts +139 -2
- package/dist/index.d.mts +139 -2
- package/dist/index.d.ts +139 -2
- package/dist/index.mjs +195 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
<h1 align = "center">
|
|
3
|
-
reactuse
|
|
4
|
-
</h1>
|
|
5
|
-
</div>
|
|
1
|
+
# reactuse
|
|
6
2
|
|
|
7
3
|
<p align="center">
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
</a>
|
|
14
|
-
<a aria-label="NPM version" href="https://www.npmjs.com/package/@reactuses/core">
|
|
15
|
-
<img alt="NPM Version" src="https://img.shields.io/npm/v/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
16
|
-
</a>
|
|
17
|
-
<a aria-label="License" href="https://jaredlunde.mit-license.org/">
|
|
18
|
-
<img alt="UnLicense" src="https://img.shields.io/npm/l/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
19
|
-
</a>
|
|
4
|
+
<img alt="NPM Version" src="https://img.shields.io/npm/v/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
5
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@reactuses/core?color=50a36f&label=&style=for-the-badge&labelColor=24292e">
|
|
6
|
+
<img alt="UnLicense" src="https://img.shields.io/npm/l/@reactuses/core?style=for-the-badge&labelColor=24292e">
|
|
7
|
+
<img alt="Tree Shaking Friendly" src="https://img.shields.io/badge/Tree%20Shaking-Friendly-brightgreen?style=for-the-badge&labelColor=24292e">
|
|
8
|
+
<img alt="TypeScript Support" src="https://img.shields.io/badge/TypeScript-Support-blue?style=for-the-badge&labelColor=24292e">
|
|
20
9
|
</p>
|
|
21
10
|
|
|
22
|
-
|
|
11
|
+
```bash
|
|
12
|
+
npm i @reactuses/core
|
|
13
|
+
```
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
Collection of essential React Hooks Utilities.
|
|
26
|
-
</p>
|
|
15
|
+
**Collection of essential React Hooks Utilities.**
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
---
|
|
29
18
|
|
|
30
19
|
## MCP Support
|
|
31
20
|
|
|
@@ -62,26 +51,26 @@ function Demo() {
|
|
|
62
51
|
|
|
63
52
|
Refer to [documentations](https://reactuse.com/) for more details.
|
|
64
53
|
|
|
65
|
-
|
|
54
|
+
---
|
|
66
55
|
|
|
67
56
|
## Who's Using This
|
|
68
57
|
|
|
69
58
|
[](https://www.pinduoduo.com/)
|
|
70
59
|
[](https://www.ctrip.com/)
|
|
71
60
|
|
|
72
|
-
|
|
61
|
+
---
|
|
73
62
|
|
|
74
63
|
## Documentation & Live Examples
|
|
75
64
|
|
|
76
65
|
- [Documentation](https://reactuse.com/)
|
|
77
66
|
|
|
78
|
-
|
|
67
|
+
---
|
|
79
68
|
|
|
80
69
|
## Feedback
|
|
81
70
|
|
|
82
71
|
You can submit an [issue](https://github.com/childrentime/reactuse/issues) or provide feedback on [Discord](https://discord.gg/HMsq6cFkKp).
|
|
83
72
|
|
|
84
|
-
|
|
73
|
+
---
|
|
85
74
|
|
|
86
75
|
## Contribute
|
|
87
76
|
|
|
@@ -91,7 +80,7 @@ See the [**Contributing Guide**](https://github.com/childrentime/reactuse/blob/m
|
|
|
91
80
|
|
|
92
81
|
See the [**ChangeLog**](https://github.com/childrentime/reactuse/blob/main/packages/core/changelog.md)
|
|
93
82
|
|
|
94
|
-
|
|
83
|
+
---
|
|
95
84
|
|
|
96
85
|
## Thanks
|
|
97
86
|
|
|
@@ -101,10 +90,10 @@ This project is heavily inspired by the following awesome projects.
|
|
|
101
90
|
- [ahooks](https://github.com/alibaba/hooks)
|
|
102
91
|
- [vueuse](https://github.com/vueuse/vueuse)
|
|
103
92
|
|
|
104
|
-
|
|
93
|
+
---
|
|
105
94
|
|
|
106
95
|
## Sponsor Me
|
|
107
96
|
|
|
108
97
|
If my work has helped you, consider buying me a cup of coffee. Thank you very much🥰!.
|
|
109
98
|
|
|
110
|
-
[Buy me a coffee](https://www.buymeacoffee.com/lianwenwu)
|
|
99
|
+
[Buy me a coffee](https://www.buymeacoffee.com/lianwenwu)
|
package/dist/index.cjs
CHANGED
|
@@ -713,49 +713,132 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
713
713
|
];
|
|
714
714
|
}
|
|
715
715
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
716
|
+
const useColorMode = (options)=>{
|
|
717
|
+
const { selector = 'html', attribute = 'class', modes, defaultValue, storageKey = 'reactuses-color-mode', storage = ()=>isBrowser ? localStorage : undefined, initialValueDetector, modeClassNames = {} } = options;
|
|
718
|
+
const initialValueDetectorRef = useLatest(initialValueDetector);
|
|
719
|
+
// Validate modes array
|
|
720
|
+
if (!modes || modes.length === 0) {
|
|
721
|
+
throw new Error('useColorMode: modes array cannot be empty');
|
|
722
|
+
}
|
|
723
|
+
// Get initial value from detector or use first mode as fallback
|
|
724
|
+
const getInitialValue = React.useCallback(()=>{
|
|
725
|
+
if (initialValueDetectorRef.current) {
|
|
726
|
+
const initialValueDetector = initialValueDetectorRef.current;
|
|
727
|
+
try {
|
|
728
|
+
const detectedValue = initialValueDetector();
|
|
729
|
+
return modes.includes(detectedValue) ? detectedValue : modes[0];
|
|
730
|
+
} catch (e) {
|
|
731
|
+
return modes[0];
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return defaultValue && modes.includes(defaultValue) ? defaultValue : modes[0];
|
|
735
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
736
|
+
}, [
|
|
737
|
+
defaultValue,
|
|
738
|
+
JSON.stringify(modes)
|
|
739
|
+
]);
|
|
740
|
+
const [colorMode, setColorMode] = useStorage(storageKey, defaultValue, storage, {
|
|
741
|
+
mountStorageValue: getInitialValue
|
|
723
742
|
});
|
|
724
|
-
|
|
743
|
+
// Apply color mode to DOM element
|
|
744
|
+
useDeepCompareEffect(()=>{
|
|
725
745
|
var _window;
|
|
746
|
+
if (!colorMode) return;
|
|
726
747
|
const element = (_window = window) == null ? void 0 : _window.document.querySelector(selector);
|
|
727
|
-
if (!element)
|
|
728
|
-
|
|
729
|
-
|
|
748
|
+
if (!element) return;
|
|
749
|
+
// Remove all existing mode classes/attributes
|
|
750
|
+
modes.forEach((mode)=>{
|
|
751
|
+
const className = modeClassNames[mode] || mode;
|
|
752
|
+
if (attribute === 'class') {
|
|
753
|
+
element.classList.remove(className);
|
|
754
|
+
} else {
|
|
755
|
+
element.removeAttribute(attribute);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
// Apply current mode class/attribute
|
|
759
|
+
const currentClassName = modeClassNames[colorMode] || colorMode;
|
|
730
760
|
if (attribute === 'class') {
|
|
731
|
-
|
|
732
|
-
!dark && classNameLight && element.classList.add(classNameLight);
|
|
761
|
+
element.classList.add(currentClassName);
|
|
733
762
|
} else {
|
|
734
|
-
|
|
735
|
-
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
763
|
+
element.setAttribute(attribute, currentClassName);
|
|
736
764
|
}
|
|
737
765
|
return ()=>{
|
|
738
|
-
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
766
|
+
// Cleanup: remove current mode class/attribute
|
|
741
767
|
if (attribute === 'class') {
|
|
742
|
-
|
|
743
|
-
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
768
|
+
element.classList.remove(currentClassName);
|
|
744
769
|
} else {
|
|
745
|
-
|
|
746
|
-
!dark && classNameLight && element.removeAttribute(attribute);
|
|
770
|
+
element.removeAttribute(attribute);
|
|
747
771
|
}
|
|
748
772
|
};
|
|
749
773
|
}, [
|
|
774
|
+
colorMode,
|
|
775
|
+
selector,
|
|
776
|
+
attribute,
|
|
777
|
+
modes,
|
|
778
|
+
modeClassNames
|
|
779
|
+
]);
|
|
780
|
+
const cycle = useEvent(()=>{
|
|
781
|
+
if (!colorMode) return;
|
|
782
|
+
const currentIndex = modes.indexOf(colorMode);
|
|
783
|
+
const nextIndex = (currentIndex + 1) % modes.length;
|
|
784
|
+
setColorMode(modes[nextIndex]);
|
|
785
|
+
});
|
|
786
|
+
return [
|
|
787
|
+
colorMode,
|
|
788
|
+
setColorMode,
|
|
789
|
+
cycle
|
|
790
|
+
];
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
function getSystemPreference() {
|
|
794
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
795
|
+
}
|
|
796
|
+
const useDarkMode = (options)=>{
|
|
797
|
+
const { selector = 'html', attribute = 'class', classNameDark = '', classNameLight = '', storageKey = 'reactuses-color-scheme', storage = ()=>isBrowser ? localStorage : undefined, defaultValue = false } = options;
|
|
798
|
+
// Convert boolean-based options to string-based options for useColorMode
|
|
799
|
+
const [colorMode, setColorMode] = useColorMode({
|
|
800
|
+
selector,
|
|
750
801
|
attribute,
|
|
751
|
-
|
|
752
|
-
|
|
802
|
+
modes: [
|
|
803
|
+
'light',
|
|
804
|
+
'dark'
|
|
805
|
+
],
|
|
806
|
+
defaultValue: defaultValue ? 'dark' : 'light',
|
|
807
|
+
storageKey,
|
|
808
|
+
storage,
|
|
809
|
+
initialValueDetector: getSystemPreference,
|
|
810
|
+
modeClassNames: {
|
|
811
|
+
dark: classNameDark,
|
|
812
|
+
light: classNameLight
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
// Convert string mode back to boolean
|
|
816
|
+
const dark = colorMode === 'dark';
|
|
817
|
+
// Toggle function that switches between dark and light
|
|
818
|
+
const toggle = React.useCallback(()=>{
|
|
819
|
+
setColorMode(dark ? 'light' : 'dark');
|
|
820
|
+
}, [
|
|
753
821
|
dark,
|
|
754
|
-
|
|
822
|
+
setColorMode
|
|
823
|
+
]);
|
|
824
|
+
// Set function that accepts boolean value
|
|
825
|
+
const setDark = React.useCallback((value)=>{
|
|
826
|
+
if (typeof value === 'function') {
|
|
827
|
+
const currentDark = colorMode === 'dark';
|
|
828
|
+
const newDark = value(currentDark);
|
|
829
|
+
if (newDark !== null) {
|
|
830
|
+
setColorMode(newDark ? 'dark' : 'light');
|
|
831
|
+
}
|
|
832
|
+
} else if (value !== null) {
|
|
833
|
+
setColorMode(value ? 'dark' : 'light');
|
|
834
|
+
}
|
|
835
|
+
}, [
|
|
836
|
+
colorMode,
|
|
837
|
+
setColorMode
|
|
755
838
|
]);
|
|
756
839
|
return [
|
|
757
840
|
dark,
|
|
758
|
-
|
|
841
|
+
toggle,
|
|
759
842
|
setDark
|
|
760
843
|
];
|
|
761
844
|
};
|
|
@@ -3725,6 +3808,29 @@ const useBroadcastChannel = (options)=>{
|
|
|
3725
3808
|
};
|
|
3726
3809
|
};
|
|
3727
3810
|
|
|
3811
|
+
const useBoolean = (initialValue = false)=>{
|
|
3812
|
+
const [value, setValue] = React.useState(initialValue);
|
|
3813
|
+
const setTrue = useEvent(()=>{
|
|
3814
|
+
setValue(true);
|
|
3815
|
+
});
|
|
3816
|
+
const setFalse = useEvent(()=>{
|
|
3817
|
+
setValue(false);
|
|
3818
|
+
});
|
|
3819
|
+
const toggle = useEvent(()=>{
|
|
3820
|
+
setValue((prev)=>!prev);
|
|
3821
|
+
});
|
|
3822
|
+
const handleSetValue = useEvent((newValue)=>{
|
|
3823
|
+
setValue(newValue);
|
|
3824
|
+
});
|
|
3825
|
+
return {
|
|
3826
|
+
value,
|
|
3827
|
+
setValue: handleSetValue,
|
|
3828
|
+
setTrue,
|
|
3829
|
+
setFalse,
|
|
3830
|
+
toggle
|
|
3831
|
+
};
|
|
3832
|
+
};
|
|
3833
|
+
|
|
3728
3834
|
const useDevicePixelRatio = ()=>{
|
|
3729
3835
|
const [pixelRatio, setPixelRatio] = React.useState(1);
|
|
3730
3836
|
const observe = React.useCallback(()=>{
|
|
@@ -4036,17 +4142,83 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4036
4142
|
};
|
|
4037
4143
|
};
|
|
4038
4144
|
|
|
4145
|
+
const useMap = (initialValue)=>{
|
|
4146
|
+
// avoid exec init code every render
|
|
4147
|
+
const initFunc = ()=>{
|
|
4148
|
+
if (typeof initialValue === 'function') {
|
|
4149
|
+
const result = initialValue();
|
|
4150
|
+
return result instanceof Map ? new Map(result) : new Map(result);
|
|
4151
|
+
}
|
|
4152
|
+
if (initialValue instanceof Map) {
|
|
4153
|
+
return new Map(initialValue);
|
|
4154
|
+
}
|
|
4155
|
+
if (Array.isArray(initialValue)) {
|
|
4156
|
+
return new Map(initialValue);
|
|
4157
|
+
}
|
|
4158
|
+
return new Map();
|
|
4159
|
+
};
|
|
4160
|
+
const [map, setMap] = React.useState(initFunc);
|
|
4161
|
+
const set = useEvent((key, value)=>{
|
|
4162
|
+
setMap((prevMap)=>{
|
|
4163
|
+
const newMap = new Map(prevMap);
|
|
4164
|
+
newMap.set(key, value);
|
|
4165
|
+
return newMap;
|
|
4166
|
+
});
|
|
4167
|
+
});
|
|
4168
|
+
const get = React.useCallback((key)=>{
|
|
4169
|
+
return map.get(key);
|
|
4170
|
+
}, [
|
|
4171
|
+
map
|
|
4172
|
+
]);
|
|
4173
|
+
const remove = useEvent((key)=>{
|
|
4174
|
+
const hasKey = map.has(key);
|
|
4175
|
+
if (hasKey) {
|
|
4176
|
+
setMap((prevMap)=>{
|
|
4177
|
+
const newMap = new Map(prevMap);
|
|
4178
|
+
newMap.delete(key);
|
|
4179
|
+
return newMap;
|
|
4180
|
+
});
|
|
4181
|
+
}
|
|
4182
|
+
return hasKey;
|
|
4183
|
+
});
|
|
4184
|
+
const has = React.useCallback((key)=>{
|
|
4185
|
+
return map.has(key);
|
|
4186
|
+
}, [
|
|
4187
|
+
map
|
|
4188
|
+
]);
|
|
4189
|
+
const clear = useEvent(()=>{
|
|
4190
|
+
setMap(new Map());
|
|
4191
|
+
});
|
|
4192
|
+
const reset = useEvent(()=>{
|
|
4193
|
+
setMap(initFunc());
|
|
4194
|
+
});
|
|
4195
|
+
return {
|
|
4196
|
+
map,
|
|
4197
|
+
set,
|
|
4198
|
+
get,
|
|
4199
|
+
remove,
|
|
4200
|
+
has,
|
|
4201
|
+
clear,
|
|
4202
|
+
reset,
|
|
4203
|
+
size: map.size
|
|
4204
|
+
};
|
|
4205
|
+
};
|
|
4206
|
+
|
|
4039
4207
|
exports.assignRef = assignRef;
|
|
4040
4208
|
exports.defaultOptions = defaultOptions;
|
|
4041
4209
|
exports.mergeRefs = mergeRefs;
|
|
4042
4210
|
exports.use = use;
|
|
4043
4211
|
exports.useActiveElement = useActiveElement;
|
|
4044
4212
|
exports.useAsyncEffect = useAsyncEffect;
|
|
4213
|
+
exports.useBoolean = useBoolean;
|
|
4045
4214
|
exports.useBroadcastChannel = useBroadcastChannel;
|
|
4215
|
+
exports.useClickAway = useClickOutside;
|
|
4046
4216
|
exports.useClickOutside = useClickOutside;
|
|
4047
4217
|
exports.useClipboard = useClipboard;
|
|
4218
|
+
exports.useColorMode = useColorMode;
|
|
4048
4219
|
exports.useControlled = useControlled;
|
|
4049
4220
|
exports.useCookie = useCookie;
|
|
4221
|
+
exports.useCopyToClipboard = useClipboard;
|
|
4050
4222
|
exports.useCountDown = useCountDown;
|
|
4051
4223
|
exports.useCounter = useCounter;
|
|
4052
4224
|
exports.useCssVar = useCssVar;
|
|
@@ -4090,6 +4262,7 @@ exports.useLatest = useLatest;
|
|
|
4090
4262
|
exports.useLocalStorage = useLocalStorage;
|
|
4091
4263
|
exports.useLocationSelector = useLocationSelector;
|
|
4092
4264
|
exports.useLongPress = useLongPress;
|
|
4265
|
+
exports.useMap = useMap;
|
|
4093
4266
|
exports.useMeasure = useMeasure;
|
|
4094
4267
|
exports.useMediaDevices = useMediaDevices;
|
|
4095
4268
|
exports.useMediaQuery = useMediaQuery;
|
package/dist/index.d.cts
CHANGED
|
@@ -2953,6 +2953,36 @@ interface UseBroadcastChannelReturn<D, P> {
|
|
|
2953
2953
|
|
|
2954
2954
|
declare const useBroadcastChannel: UseBroadcastChannel;
|
|
2955
2955
|
|
|
2956
|
+
/**
|
|
2957
|
+
* @title useBoolean
|
|
2958
|
+
* @returns_en An object with the following properties:
|
|
2959
|
+
* - value: The current boolean value.
|
|
2960
|
+
* - setValue: A function to set the boolean value directly.
|
|
2961
|
+
* - setTrue: A function to set the value to true.
|
|
2962
|
+
* - setFalse: A function to set the value to false.
|
|
2963
|
+
* - toggle: A function to toggle the boolean value.
|
|
2964
|
+
* @returns 包含以下属性的对象:
|
|
2965
|
+
* - value: 当前的布尔值。
|
|
2966
|
+
* - setValue: 直接设置布尔值的函数。
|
|
2967
|
+
* - setTrue: 将值设置为 true 的函数。
|
|
2968
|
+
* - setFalse: 将值设置为 false 的函数。
|
|
2969
|
+
* - toggle: 切换布尔值的函数。
|
|
2970
|
+
*/
|
|
2971
|
+
type UseBoolean = (
|
|
2972
|
+
/**
|
|
2973
|
+
* @zh 初始值,默认为 false
|
|
2974
|
+
* @en The initial boolean value. Defaults to false.
|
|
2975
|
+
*/
|
|
2976
|
+
initialValue?: boolean) => {
|
|
2977
|
+
readonly value: boolean;
|
|
2978
|
+
readonly setValue: (value: boolean) => void;
|
|
2979
|
+
readonly setTrue: () => void;
|
|
2980
|
+
readonly setFalse: () => void;
|
|
2981
|
+
readonly toggle: () => void;
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
declare const useBoolean: UseBoolean;
|
|
2985
|
+
|
|
2956
2986
|
/**
|
|
2957
2987
|
* @title UseDevicePixelRatio
|
|
2958
2988
|
*/
|
|
@@ -3189,6 +3219,113 @@ options?: UseFetchEventSourceOptions) => UseFetchEventSourceReturn;
|
|
|
3189
3219
|
|
|
3190
3220
|
declare const useFetchEventSource: UseFetchEventSource;
|
|
3191
3221
|
|
|
3222
|
+
/**
|
|
3223
|
+
* @title useMap
|
|
3224
|
+
* @returns_en An object with the following properties:
|
|
3225
|
+
* - map: The current Map instance.
|
|
3226
|
+
* - set: A function to set a key-value pair in the map.
|
|
3227
|
+
* - get: A function to get a value by key from the map.
|
|
3228
|
+
* - remove: A function to remove a key from the map and return whether it existed.
|
|
3229
|
+
* - has: A function to check if a key exists in the map.
|
|
3230
|
+
* - clear: A function to clear all entries from the map.
|
|
3231
|
+
* - reset: A function to reset the map to its initial state.
|
|
3232
|
+
* - size: The current size of the map.
|
|
3233
|
+
* @returns 包含以下属性的对象:
|
|
3234
|
+
* - map: 当前的 Map 实例。
|
|
3235
|
+
* - set: 在 map 中设置键值对的函数。
|
|
3236
|
+
* - get: 通过键从 map 中获取值的函数。
|
|
3237
|
+
* - remove: 从 map 中删除键并返回是否存在的函数。
|
|
3238
|
+
* - has: 检查键是否存在于 map 中的函数。
|
|
3239
|
+
* - clear: 清除 map 中所有条目的函数。
|
|
3240
|
+
* - reset: 将 map 重置为其初始状态的函数。
|
|
3241
|
+
* - size: map 的当前大小。
|
|
3242
|
+
*/
|
|
3243
|
+
type UseMap<K = any, V = any> = (
|
|
3244
|
+
/**
|
|
3245
|
+
* @zh 初始值,可以为 Map 实例、数组或者一个初始化的函数
|
|
3246
|
+
* @en The initial value of the map. It can be a Map instance, an array of key-value pairs, or a function that returns initial entries.
|
|
3247
|
+
*/
|
|
3248
|
+
initialValue?: Map<K, V> | readonly (readonly [K, V])[] | (() => Map<K, V> | readonly (readonly [K, V])[])) => {
|
|
3249
|
+
readonly map: Map<K, V>;
|
|
3250
|
+
readonly set: (key: K, value: V) => void;
|
|
3251
|
+
readonly get: (key: K) => V | undefined;
|
|
3252
|
+
readonly remove: (key: K) => boolean;
|
|
3253
|
+
readonly has: (key: K) => boolean;
|
|
3254
|
+
readonly clear: () => void;
|
|
3255
|
+
readonly reset: () => void;
|
|
3256
|
+
readonly size: number;
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
declare const useMap: UseMap;
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* @title UseColorModeOptions
|
|
3263
|
+
*/
|
|
3264
|
+
interface UseColorModeOptions<T extends string = string> {
|
|
3265
|
+
/**
|
|
3266
|
+
* @en CSS Selector for the target element applying to
|
|
3267
|
+
* @zh 适用于目标元素的 CSS 选择器
|
|
3268
|
+
* @defaultValue 'html'
|
|
3269
|
+
*/
|
|
3270
|
+
selector?: string;
|
|
3271
|
+
/**
|
|
3272
|
+
* @en HTML attribute applying the target element
|
|
3273
|
+
* @zh 应用到目标元素的 html 属性
|
|
3274
|
+
* @defaultValue 'class'
|
|
3275
|
+
*/
|
|
3276
|
+
attribute?: string;
|
|
3277
|
+
/**
|
|
3278
|
+
* @en Available color modes
|
|
3279
|
+
* @zh 可用的颜色模式
|
|
3280
|
+
*/
|
|
3281
|
+
modes: T[];
|
|
3282
|
+
/**
|
|
3283
|
+
* @en Default color mode
|
|
3284
|
+
* @zh 默认颜色模式
|
|
3285
|
+
*/
|
|
3286
|
+
defaultValue?: T;
|
|
3287
|
+
/**
|
|
3288
|
+
* @en Key to persist the data into localStorage/sessionStorage.
|
|
3289
|
+
* @zh 将数据持久保存到 localStorage/sessionStorage 的键值
|
|
3290
|
+
* @defaultValue 'reactuses-color-mode'
|
|
3291
|
+
*/
|
|
3292
|
+
storageKey?: string;
|
|
3293
|
+
/**
|
|
3294
|
+
* @en Storage object, can be localStorage or sessionStorage
|
|
3295
|
+
* @zh 存储对象,可以是localStorage或sessionStorage
|
|
3296
|
+
* @defaultValue `localStorage`
|
|
3297
|
+
*/
|
|
3298
|
+
storage?: () => Storage | undefined;
|
|
3299
|
+
/**
|
|
3300
|
+
* @en Function to get initial color mode from system preference
|
|
3301
|
+
* @zh 从系统偏好获取初始颜色模式的函数
|
|
3302
|
+
*/
|
|
3303
|
+
initialValueDetector?: () => T;
|
|
3304
|
+
/**
|
|
3305
|
+
* @en Mapping of color modes to their corresponding class names or attribute values
|
|
3306
|
+
* @zh 颜色模式到对应类名或属性值的映射
|
|
3307
|
+
*/
|
|
3308
|
+
modeClassNames?: Partial<Record<T, string>>;
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
* @title useColorMode
|
|
3312
|
+
* @returns_en A tuple with the following elements:
|
|
3313
|
+
* - The current color mode value.
|
|
3314
|
+
* - A function to set the color mode.
|
|
3315
|
+
* - A function to cycle through available modes.
|
|
3316
|
+
* @returns 包含以下元素的元组:
|
|
3317
|
+
* - 当前颜色模式值。
|
|
3318
|
+
* - 设置颜色模式的函数。
|
|
3319
|
+
* - 循环切换可用模式的函数。
|
|
3320
|
+
*/
|
|
3321
|
+
type UseColorMode<T extends string = string> = (options: UseColorModeOptions<T>) => readonly [
|
|
3322
|
+
T | null,
|
|
3323
|
+
React.Dispatch<React.SetStateAction<T | null>>,
|
|
3324
|
+
() => void
|
|
3325
|
+
];
|
|
3326
|
+
|
|
3327
|
+
declare const useColorMode: UseColorMode;
|
|
3328
|
+
|
|
3192
3329
|
/**
|
|
3193
3330
|
* @title useDocumentVisiblity
|
|
3194
3331
|
* @returns_en document visibility
|
|
@@ -3596,5 +3733,5 @@ type Use = <T>(
|
|
|
3596
3733
|
*/
|
|
3597
3734
|
usable: Usable<T>) => T;
|
|
3598
3735
|
|
|
3599
|
-
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
-
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
|
3736
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBoolean, useBroadcastChannel, useClickOutside as useClickAway, useClickOutside, useClipboard, useColorMode, useControlled, useCookie, useClipboard as useCopyToClipboard, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMap, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3737
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBoolean, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseColorMode, UseColorModeOptions, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMap, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.d.mts
CHANGED
|
@@ -2953,6 +2953,36 @@ interface UseBroadcastChannelReturn<D, P> {
|
|
|
2953
2953
|
|
|
2954
2954
|
declare const useBroadcastChannel: UseBroadcastChannel;
|
|
2955
2955
|
|
|
2956
|
+
/**
|
|
2957
|
+
* @title useBoolean
|
|
2958
|
+
* @returns_en An object with the following properties:
|
|
2959
|
+
* - value: The current boolean value.
|
|
2960
|
+
* - setValue: A function to set the boolean value directly.
|
|
2961
|
+
* - setTrue: A function to set the value to true.
|
|
2962
|
+
* - setFalse: A function to set the value to false.
|
|
2963
|
+
* - toggle: A function to toggle the boolean value.
|
|
2964
|
+
* @returns 包含以下属性的对象:
|
|
2965
|
+
* - value: 当前的布尔值。
|
|
2966
|
+
* - setValue: 直接设置布尔值的函数。
|
|
2967
|
+
* - setTrue: 将值设置为 true 的函数。
|
|
2968
|
+
* - setFalse: 将值设置为 false 的函数。
|
|
2969
|
+
* - toggle: 切换布尔值的函数。
|
|
2970
|
+
*/
|
|
2971
|
+
type UseBoolean = (
|
|
2972
|
+
/**
|
|
2973
|
+
* @zh 初始值,默认为 false
|
|
2974
|
+
* @en The initial boolean value. Defaults to false.
|
|
2975
|
+
*/
|
|
2976
|
+
initialValue?: boolean) => {
|
|
2977
|
+
readonly value: boolean;
|
|
2978
|
+
readonly setValue: (value: boolean) => void;
|
|
2979
|
+
readonly setTrue: () => void;
|
|
2980
|
+
readonly setFalse: () => void;
|
|
2981
|
+
readonly toggle: () => void;
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
declare const useBoolean: UseBoolean;
|
|
2985
|
+
|
|
2956
2986
|
/**
|
|
2957
2987
|
* @title UseDevicePixelRatio
|
|
2958
2988
|
*/
|
|
@@ -3189,6 +3219,113 @@ options?: UseFetchEventSourceOptions) => UseFetchEventSourceReturn;
|
|
|
3189
3219
|
|
|
3190
3220
|
declare const useFetchEventSource: UseFetchEventSource;
|
|
3191
3221
|
|
|
3222
|
+
/**
|
|
3223
|
+
* @title useMap
|
|
3224
|
+
* @returns_en An object with the following properties:
|
|
3225
|
+
* - map: The current Map instance.
|
|
3226
|
+
* - set: A function to set a key-value pair in the map.
|
|
3227
|
+
* - get: A function to get a value by key from the map.
|
|
3228
|
+
* - remove: A function to remove a key from the map and return whether it existed.
|
|
3229
|
+
* - has: A function to check if a key exists in the map.
|
|
3230
|
+
* - clear: A function to clear all entries from the map.
|
|
3231
|
+
* - reset: A function to reset the map to its initial state.
|
|
3232
|
+
* - size: The current size of the map.
|
|
3233
|
+
* @returns 包含以下属性的对象:
|
|
3234
|
+
* - map: 当前的 Map 实例。
|
|
3235
|
+
* - set: 在 map 中设置键值对的函数。
|
|
3236
|
+
* - get: 通过键从 map 中获取值的函数。
|
|
3237
|
+
* - remove: 从 map 中删除键并返回是否存在的函数。
|
|
3238
|
+
* - has: 检查键是否存在于 map 中的函数。
|
|
3239
|
+
* - clear: 清除 map 中所有条目的函数。
|
|
3240
|
+
* - reset: 将 map 重置为其初始状态的函数。
|
|
3241
|
+
* - size: map 的当前大小。
|
|
3242
|
+
*/
|
|
3243
|
+
type UseMap<K = any, V = any> = (
|
|
3244
|
+
/**
|
|
3245
|
+
* @zh 初始值,可以为 Map 实例、数组或者一个初始化的函数
|
|
3246
|
+
* @en The initial value of the map. It can be a Map instance, an array of key-value pairs, or a function that returns initial entries.
|
|
3247
|
+
*/
|
|
3248
|
+
initialValue?: Map<K, V> | readonly (readonly [K, V])[] | (() => Map<K, V> | readonly (readonly [K, V])[])) => {
|
|
3249
|
+
readonly map: Map<K, V>;
|
|
3250
|
+
readonly set: (key: K, value: V) => void;
|
|
3251
|
+
readonly get: (key: K) => V | undefined;
|
|
3252
|
+
readonly remove: (key: K) => boolean;
|
|
3253
|
+
readonly has: (key: K) => boolean;
|
|
3254
|
+
readonly clear: () => void;
|
|
3255
|
+
readonly reset: () => void;
|
|
3256
|
+
readonly size: number;
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
declare const useMap: UseMap;
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* @title UseColorModeOptions
|
|
3263
|
+
*/
|
|
3264
|
+
interface UseColorModeOptions<T extends string = string> {
|
|
3265
|
+
/**
|
|
3266
|
+
* @en CSS Selector for the target element applying to
|
|
3267
|
+
* @zh 适用于目标元素的 CSS 选择器
|
|
3268
|
+
* @defaultValue 'html'
|
|
3269
|
+
*/
|
|
3270
|
+
selector?: string;
|
|
3271
|
+
/**
|
|
3272
|
+
* @en HTML attribute applying the target element
|
|
3273
|
+
* @zh 应用到目标元素的 html 属性
|
|
3274
|
+
* @defaultValue 'class'
|
|
3275
|
+
*/
|
|
3276
|
+
attribute?: string;
|
|
3277
|
+
/**
|
|
3278
|
+
* @en Available color modes
|
|
3279
|
+
* @zh 可用的颜色模式
|
|
3280
|
+
*/
|
|
3281
|
+
modes: T[];
|
|
3282
|
+
/**
|
|
3283
|
+
* @en Default color mode
|
|
3284
|
+
* @zh 默认颜色模式
|
|
3285
|
+
*/
|
|
3286
|
+
defaultValue?: T;
|
|
3287
|
+
/**
|
|
3288
|
+
* @en Key to persist the data into localStorage/sessionStorage.
|
|
3289
|
+
* @zh 将数据持久保存到 localStorage/sessionStorage 的键值
|
|
3290
|
+
* @defaultValue 'reactuses-color-mode'
|
|
3291
|
+
*/
|
|
3292
|
+
storageKey?: string;
|
|
3293
|
+
/**
|
|
3294
|
+
* @en Storage object, can be localStorage or sessionStorage
|
|
3295
|
+
* @zh 存储对象,可以是localStorage或sessionStorage
|
|
3296
|
+
* @defaultValue `localStorage`
|
|
3297
|
+
*/
|
|
3298
|
+
storage?: () => Storage | undefined;
|
|
3299
|
+
/**
|
|
3300
|
+
* @en Function to get initial color mode from system preference
|
|
3301
|
+
* @zh 从系统偏好获取初始颜色模式的函数
|
|
3302
|
+
*/
|
|
3303
|
+
initialValueDetector?: () => T;
|
|
3304
|
+
/**
|
|
3305
|
+
* @en Mapping of color modes to their corresponding class names or attribute values
|
|
3306
|
+
* @zh 颜色模式到对应类名或属性值的映射
|
|
3307
|
+
*/
|
|
3308
|
+
modeClassNames?: Partial<Record<T, string>>;
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
* @title useColorMode
|
|
3312
|
+
* @returns_en A tuple with the following elements:
|
|
3313
|
+
* - The current color mode value.
|
|
3314
|
+
* - A function to set the color mode.
|
|
3315
|
+
* - A function to cycle through available modes.
|
|
3316
|
+
* @returns 包含以下元素的元组:
|
|
3317
|
+
* - 当前颜色模式值。
|
|
3318
|
+
* - 设置颜色模式的函数。
|
|
3319
|
+
* - 循环切换可用模式的函数。
|
|
3320
|
+
*/
|
|
3321
|
+
type UseColorMode<T extends string = string> = (options: UseColorModeOptions<T>) => readonly [
|
|
3322
|
+
T | null,
|
|
3323
|
+
React.Dispatch<React.SetStateAction<T | null>>,
|
|
3324
|
+
() => void
|
|
3325
|
+
];
|
|
3326
|
+
|
|
3327
|
+
declare const useColorMode: UseColorMode;
|
|
3328
|
+
|
|
3192
3329
|
/**
|
|
3193
3330
|
* @title useDocumentVisiblity
|
|
3194
3331
|
* @returns_en document visibility
|
|
@@ -3596,5 +3733,5 @@ type Use = <T>(
|
|
|
3596
3733
|
*/
|
|
3597
3734
|
usable: Usable<T>) => T;
|
|
3598
3735
|
|
|
3599
|
-
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
-
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
|
3736
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBoolean, useBroadcastChannel, useClickOutside as useClickAway, useClickOutside, useClipboard, useColorMode, useControlled, useCookie, useClipboard as useCopyToClipboard, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMap, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3737
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBoolean, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseColorMode, UseColorModeOptions, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMap, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.d.ts
CHANGED
|
@@ -2953,6 +2953,36 @@ interface UseBroadcastChannelReturn<D, P> {
|
|
|
2953
2953
|
|
|
2954
2954
|
declare const useBroadcastChannel: UseBroadcastChannel;
|
|
2955
2955
|
|
|
2956
|
+
/**
|
|
2957
|
+
* @title useBoolean
|
|
2958
|
+
* @returns_en An object with the following properties:
|
|
2959
|
+
* - value: The current boolean value.
|
|
2960
|
+
* - setValue: A function to set the boolean value directly.
|
|
2961
|
+
* - setTrue: A function to set the value to true.
|
|
2962
|
+
* - setFalse: A function to set the value to false.
|
|
2963
|
+
* - toggle: A function to toggle the boolean value.
|
|
2964
|
+
* @returns 包含以下属性的对象:
|
|
2965
|
+
* - value: 当前的布尔值。
|
|
2966
|
+
* - setValue: 直接设置布尔值的函数。
|
|
2967
|
+
* - setTrue: 将值设置为 true 的函数。
|
|
2968
|
+
* - setFalse: 将值设置为 false 的函数。
|
|
2969
|
+
* - toggle: 切换布尔值的函数。
|
|
2970
|
+
*/
|
|
2971
|
+
type UseBoolean = (
|
|
2972
|
+
/**
|
|
2973
|
+
* @zh 初始值,默认为 false
|
|
2974
|
+
* @en The initial boolean value. Defaults to false.
|
|
2975
|
+
*/
|
|
2976
|
+
initialValue?: boolean) => {
|
|
2977
|
+
readonly value: boolean;
|
|
2978
|
+
readonly setValue: (value: boolean) => void;
|
|
2979
|
+
readonly setTrue: () => void;
|
|
2980
|
+
readonly setFalse: () => void;
|
|
2981
|
+
readonly toggle: () => void;
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
declare const useBoolean: UseBoolean;
|
|
2985
|
+
|
|
2956
2986
|
/**
|
|
2957
2987
|
* @title UseDevicePixelRatio
|
|
2958
2988
|
*/
|
|
@@ -3189,6 +3219,113 @@ options?: UseFetchEventSourceOptions) => UseFetchEventSourceReturn;
|
|
|
3189
3219
|
|
|
3190
3220
|
declare const useFetchEventSource: UseFetchEventSource;
|
|
3191
3221
|
|
|
3222
|
+
/**
|
|
3223
|
+
* @title useMap
|
|
3224
|
+
* @returns_en An object with the following properties:
|
|
3225
|
+
* - map: The current Map instance.
|
|
3226
|
+
* - set: A function to set a key-value pair in the map.
|
|
3227
|
+
* - get: A function to get a value by key from the map.
|
|
3228
|
+
* - remove: A function to remove a key from the map and return whether it existed.
|
|
3229
|
+
* - has: A function to check if a key exists in the map.
|
|
3230
|
+
* - clear: A function to clear all entries from the map.
|
|
3231
|
+
* - reset: A function to reset the map to its initial state.
|
|
3232
|
+
* - size: The current size of the map.
|
|
3233
|
+
* @returns 包含以下属性的对象:
|
|
3234
|
+
* - map: 当前的 Map 实例。
|
|
3235
|
+
* - set: 在 map 中设置键值对的函数。
|
|
3236
|
+
* - get: 通过键从 map 中获取值的函数。
|
|
3237
|
+
* - remove: 从 map 中删除键并返回是否存在的函数。
|
|
3238
|
+
* - has: 检查键是否存在于 map 中的函数。
|
|
3239
|
+
* - clear: 清除 map 中所有条目的函数。
|
|
3240
|
+
* - reset: 将 map 重置为其初始状态的函数。
|
|
3241
|
+
* - size: map 的当前大小。
|
|
3242
|
+
*/
|
|
3243
|
+
type UseMap<K = any, V = any> = (
|
|
3244
|
+
/**
|
|
3245
|
+
* @zh 初始值,可以为 Map 实例、数组或者一个初始化的函数
|
|
3246
|
+
* @en The initial value of the map. It can be a Map instance, an array of key-value pairs, or a function that returns initial entries.
|
|
3247
|
+
*/
|
|
3248
|
+
initialValue?: Map<K, V> | readonly (readonly [K, V])[] | (() => Map<K, V> | readonly (readonly [K, V])[])) => {
|
|
3249
|
+
readonly map: Map<K, V>;
|
|
3250
|
+
readonly set: (key: K, value: V) => void;
|
|
3251
|
+
readonly get: (key: K) => V | undefined;
|
|
3252
|
+
readonly remove: (key: K) => boolean;
|
|
3253
|
+
readonly has: (key: K) => boolean;
|
|
3254
|
+
readonly clear: () => void;
|
|
3255
|
+
readonly reset: () => void;
|
|
3256
|
+
readonly size: number;
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
declare const useMap: UseMap;
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* @title UseColorModeOptions
|
|
3263
|
+
*/
|
|
3264
|
+
interface UseColorModeOptions<T extends string = string> {
|
|
3265
|
+
/**
|
|
3266
|
+
* @en CSS Selector for the target element applying to
|
|
3267
|
+
* @zh 适用于目标元素的 CSS 选择器
|
|
3268
|
+
* @defaultValue 'html'
|
|
3269
|
+
*/
|
|
3270
|
+
selector?: string;
|
|
3271
|
+
/**
|
|
3272
|
+
* @en HTML attribute applying the target element
|
|
3273
|
+
* @zh 应用到目标元素的 html 属性
|
|
3274
|
+
* @defaultValue 'class'
|
|
3275
|
+
*/
|
|
3276
|
+
attribute?: string;
|
|
3277
|
+
/**
|
|
3278
|
+
* @en Available color modes
|
|
3279
|
+
* @zh 可用的颜色模式
|
|
3280
|
+
*/
|
|
3281
|
+
modes: T[];
|
|
3282
|
+
/**
|
|
3283
|
+
* @en Default color mode
|
|
3284
|
+
* @zh 默认颜色模式
|
|
3285
|
+
*/
|
|
3286
|
+
defaultValue?: T;
|
|
3287
|
+
/**
|
|
3288
|
+
* @en Key to persist the data into localStorage/sessionStorage.
|
|
3289
|
+
* @zh 将数据持久保存到 localStorage/sessionStorage 的键值
|
|
3290
|
+
* @defaultValue 'reactuses-color-mode'
|
|
3291
|
+
*/
|
|
3292
|
+
storageKey?: string;
|
|
3293
|
+
/**
|
|
3294
|
+
* @en Storage object, can be localStorage or sessionStorage
|
|
3295
|
+
* @zh 存储对象,可以是localStorage或sessionStorage
|
|
3296
|
+
* @defaultValue `localStorage`
|
|
3297
|
+
*/
|
|
3298
|
+
storage?: () => Storage | undefined;
|
|
3299
|
+
/**
|
|
3300
|
+
* @en Function to get initial color mode from system preference
|
|
3301
|
+
* @zh 从系统偏好获取初始颜色模式的函数
|
|
3302
|
+
*/
|
|
3303
|
+
initialValueDetector?: () => T;
|
|
3304
|
+
/**
|
|
3305
|
+
* @en Mapping of color modes to their corresponding class names or attribute values
|
|
3306
|
+
* @zh 颜色模式到对应类名或属性值的映射
|
|
3307
|
+
*/
|
|
3308
|
+
modeClassNames?: Partial<Record<T, string>>;
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
* @title useColorMode
|
|
3312
|
+
* @returns_en A tuple with the following elements:
|
|
3313
|
+
* - The current color mode value.
|
|
3314
|
+
* - A function to set the color mode.
|
|
3315
|
+
* - A function to cycle through available modes.
|
|
3316
|
+
* @returns 包含以下元素的元组:
|
|
3317
|
+
* - 当前颜色模式值。
|
|
3318
|
+
* - 设置颜色模式的函数。
|
|
3319
|
+
* - 循环切换可用模式的函数。
|
|
3320
|
+
*/
|
|
3321
|
+
type UseColorMode<T extends string = string> = (options: UseColorModeOptions<T>) => readonly [
|
|
3322
|
+
T | null,
|
|
3323
|
+
React.Dispatch<React.SetStateAction<T | null>>,
|
|
3324
|
+
() => void
|
|
3325
|
+
];
|
|
3326
|
+
|
|
3327
|
+
declare const useColorMode: UseColorMode;
|
|
3328
|
+
|
|
3192
3329
|
/**
|
|
3193
3330
|
* @title useDocumentVisiblity
|
|
3194
3331
|
* @returns_en document visibility
|
|
@@ -3596,5 +3733,5 @@ type Use = <T>(
|
|
|
3596
3733
|
*/
|
|
3597
3734
|
usable: Usable<T>) => T;
|
|
3598
3735
|
|
|
3599
|
-
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBroadcastChannel, useClickOutside, useClipboard, useControlled, useCookie, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3600
|
-
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
|
3736
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBoolean, useBroadcastChannel, useClickOutside as useClickAway, useClickOutside, useClipboard, useColorMode, useControlled, useCookie, useClipboard as useCopyToClipboard, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMap, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|
|
3737
|
+
export type { ColorScheme, Contrast, DepsEqualFnType, EventSourceStatus, EventType, INetworkInformation, IUseNetworkState, KeyModifier, Pausable, Platform, PossibleRef, Use, UseActiveElement, UseAsyncEffect, UseBoolean, UseBroadcastChannel, UseBroadcastChannelOptions, UseBroadcastChannelReturn, UseClickOutside, UseClipboard, UseColorMode, UseColorModeOptions, UseControlled, UseCookie, UseCookieState, UseCountDown, UseCounter, UseCssVar, UseCssVarOptions, UseCustomCompareEffect, UseCycleList, UseDarkMode, UseDarkOptions, UseDebounce, UseDebounceFn, UseDeepCompareEffect, UseDevicePixelRatio, UseDevicePixelRatioReturn, UseDisclosure, UseDisclosureProps, UseDocumentVisibility, UseDoubleClick, UseDoubleClickProps, UseDraggable, UseDraggableOptions, UseDropZone, UseElementBounding, UseElementBoundingOptions, UseElementBoundingReturn, UseElementByPoint, UseElementByPointOptions, UseElementByPointReturn, UseElementSize, UseElementVisibility, UseEvent, UseEventEmitter, UseEventEmitterDisposable, UseEventEmitterEvent, UseEventEmitterEventOnce, UseEventEmitterListener, UseEventEmitterReturn, UseEventListener, UseEventSource, UseEventSourceAutoReconnectOptions, UseEventSourceOptions, UseEventSourceReturn, UseEyeDropper, UseEyeDropperOpenOptions, UseEyeDropperOpenReturnType, UseFavicon, UseFetchEventSource, UseFetchEventSourceAutoReconnectOptions, UseFetchEventSourceMessage, UseFetchEventSourceOptions, UseFetchEventSourceReturn, UseFetchEventSourceStatus, UseFileDialog, UseFileDialogOptions, UseFirstMountState, UseFocus, UseFps, UseFpsOptions, UseFullScreenOptions, UseFullscreen, UseGeolocation, UseHover, UseIdle, UseInfiniteScroll, UseInfiniteScrollArrivedState, UseInfiniteScrollDirection, UseInfiniteScrollLoadMore, UseInfiniteScrollOptions, UseIntersectionObserver, UseInterval, UseIntervalOptions, UseKeyModifier, UseLatest, UseLocalStorage, UseLocalStorageOptions, UseLocalStorageSerializer, UseLocationSelector, UseLongPress, UseLongPressOptions, UseMap, UseMeasure, UseMeasureRect, UseMediaDeviceOptions, UseMediaDevices, UseMediaQuery, UseMergedRef, UseMobileLandscape, UseModifierOptions, UseMount, UseMountedState, UseMouse, UseMouseCursorState, UseMousePressed, UseMousePressedOptions, UseMousePressedSourceType, UseMutationObserver, UseNetwork, UseObjectUrl, UseOnline, UseOrientation, UseOrientationLockType, UseOrientationState, UseOrientationType, UsePageLeave, UsePermission, UsePermissionDescriptorNamePolyfill, UsePermissionGeneralPermissionDescriptor, UsePermissionState, UsePlatform, UsePlatformProps, UsePlatformReturn, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePrevious, UseRafFn, UseRafState, UseReducedMotion, UseResizeObserver, UseScreenSafeArea, UseScriptTag, UseScriptTagOptions, UseScriptTagStatus, UseScroll, UseScrollArrivedState, UseScrollDirection, UseScrollIntoView, UseScrollIntoViewAnimation, UseScrollIntoViewParams, UseScrollLock, UseScrollOffset, UseScrollOptions, UseSessionStorage, UseSessionStorageOptions, UseSessionStorageSerializer, UseSetState, UseSticky, UseStickyParams, UseSupported, UseTextDirection, UseTextDirectionOptions, UseTextDirectionValue, UseTextSelection, UseThrottle, UseThrottleFn, UseTimeout, UseTimeoutFn, UseTimeoutFnOptions, UseTimeoutOptions, UseTitle, UseToggle, UseUnmount, UseUpdate, UseWebNotification, UseWebNotificationReturn, UseWebNotificationShow, UseWindowScroll, UseWindowScrollState, UseWindowSize, UseWindowsFocus };
|
package/dist/index.mjs
CHANGED
|
@@ -705,49 +705,132 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
705
705
|
];
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
708
|
+
const useColorMode = (options)=>{
|
|
709
|
+
const { selector = 'html', attribute = 'class', modes, defaultValue, storageKey = 'reactuses-color-mode', storage = ()=>isBrowser ? localStorage : undefined, initialValueDetector, modeClassNames = {} } = options;
|
|
710
|
+
const initialValueDetectorRef = useLatest(initialValueDetector);
|
|
711
|
+
// Validate modes array
|
|
712
|
+
if (!modes || modes.length === 0) {
|
|
713
|
+
throw new Error('useColorMode: modes array cannot be empty');
|
|
714
|
+
}
|
|
715
|
+
// Get initial value from detector or use first mode as fallback
|
|
716
|
+
const getInitialValue = useCallback(()=>{
|
|
717
|
+
if (initialValueDetectorRef.current) {
|
|
718
|
+
const initialValueDetector = initialValueDetectorRef.current;
|
|
719
|
+
try {
|
|
720
|
+
const detectedValue = initialValueDetector();
|
|
721
|
+
return modes.includes(detectedValue) ? detectedValue : modes[0];
|
|
722
|
+
} catch (e) {
|
|
723
|
+
return modes[0];
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return defaultValue && modes.includes(defaultValue) ? defaultValue : modes[0];
|
|
727
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
728
|
+
}, [
|
|
729
|
+
defaultValue,
|
|
730
|
+
JSON.stringify(modes)
|
|
731
|
+
]);
|
|
732
|
+
const [colorMode, setColorMode] = useStorage(storageKey, defaultValue, storage, {
|
|
733
|
+
mountStorageValue: getInitialValue
|
|
715
734
|
});
|
|
716
|
-
|
|
735
|
+
// Apply color mode to DOM element
|
|
736
|
+
useDeepCompareEffect(()=>{
|
|
717
737
|
var _window;
|
|
738
|
+
if (!colorMode) return;
|
|
718
739
|
const element = (_window = window) == null ? void 0 : _window.document.querySelector(selector);
|
|
719
|
-
if (!element)
|
|
720
|
-
|
|
721
|
-
|
|
740
|
+
if (!element) return;
|
|
741
|
+
// Remove all existing mode classes/attributes
|
|
742
|
+
modes.forEach((mode)=>{
|
|
743
|
+
const className = modeClassNames[mode] || mode;
|
|
744
|
+
if (attribute === 'class') {
|
|
745
|
+
element.classList.remove(className);
|
|
746
|
+
} else {
|
|
747
|
+
element.removeAttribute(attribute);
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
// Apply current mode class/attribute
|
|
751
|
+
const currentClassName = modeClassNames[colorMode] || colorMode;
|
|
722
752
|
if (attribute === 'class') {
|
|
723
|
-
|
|
724
|
-
!dark && classNameLight && element.classList.add(classNameLight);
|
|
753
|
+
element.classList.add(currentClassName);
|
|
725
754
|
} else {
|
|
726
|
-
|
|
727
|
-
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
755
|
+
element.setAttribute(attribute, currentClassName);
|
|
728
756
|
}
|
|
729
757
|
return ()=>{
|
|
730
|
-
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
758
|
+
// Cleanup: remove current mode class/attribute
|
|
733
759
|
if (attribute === 'class') {
|
|
734
|
-
|
|
735
|
-
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
760
|
+
element.classList.remove(currentClassName);
|
|
736
761
|
} else {
|
|
737
|
-
|
|
738
|
-
!dark && classNameLight && element.removeAttribute(attribute);
|
|
762
|
+
element.removeAttribute(attribute);
|
|
739
763
|
}
|
|
740
764
|
};
|
|
741
765
|
}, [
|
|
766
|
+
colorMode,
|
|
767
|
+
selector,
|
|
768
|
+
attribute,
|
|
769
|
+
modes,
|
|
770
|
+
modeClassNames
|
|
771
|
+
]);
|
|
772
|
+
const cycle = useEvent(()=>{
|
|
773
|
+
if (!colorMode) return;
|
|
774
|
+
const currentIndex = modes.indexOf(colorMode);
|
|
775
|
+
const nextIndex = (currentIndex + 1) % modes.length;
|
|
776
|
+
setColorMode(modes[nextIndex]);
|
|
777
|
+
});
|
|
778
|
+
return [
|
|
779
|
+
colorMode,
|
|
780
|
+
setColorMode,
|
|
781
|
+
cycle
|
|
782
|
+
];
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
function getSystemPreference() {
|
|
786
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
787
|
+
}
|
|
788
|
+
const useDarkMode = (options)=>{
|
|
789
|
+
const { selector = 'html', attribute = 'class', classNameDark = '', classNameLight = '', storageKey = 'reactuses-color-scheme', storage = ()=>isBrowser ? localStorage : undefined, defaultValue = false } = options;
|
|
790
|
+
// Convert boolean-based options to string-based options for useColorMode
|
|
791
|
+
const [colorMode, setColorMode] = useColorMode({
|
|
792
|
+
selector,
|
|
742
793
|
attribute,
|
|
743
|
-
|
|
744
|
-
|
|
794
|
+
modes: [
|
|
795
|
+
'light',
|
|
796
|
+
'dark'
|
|
797
|
+
],
|
|
798
|
+
defaultValue: defaultValue ? 'dark' : 'light',
|
|
799
|
+
storageKey,
|
|
800
|
+
storage,
|
|
801
|
+
initialValueDetector: getSystemPreference,
|
|
802
|
+
modeClassNames: {
|
|
803
|
+
dark: classNameDark,
|
|
804
|
+
light: classNameLight
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
// Convert string mode back to boolean
|
|
808
|
+
const dark = colorMode === 'dark';
|
|
809
|
+
// Toggle function that switches between dark and light
|
|
810
|
+
const toggle = useCallback(()=>{
|
|
811
|
+
setColorMode(dark ? 'light' : 'dark');
|
|
812
|
+
}, [
|
|
745
813
|
dark,
|
|
746
|
-
|
|
814
|
+
setColorMode
|
|
815
|
+
]);
|
|
816
|
+
// Set function that accepts boolean value
|
|
817
|
+
const setDark = useCallback((value)=>{
|
|
818
|
+
if (typeof value === 'function') {
|
|
819
|
+
const currentDark = colorMode === 'dark';
|
|
820
|
+
const newDark = value(currentDark);
|
|
821
|
+
if (newDark !== null) {
|
|
822
|
+
setColorMode(newDark ? 'dark' : 'light');
|
|
823
|
+
}
|
|
824
|
+
} else if (value !== null) {
|
|
825
|
+
setColorMode(value ? 'dark' : 'light');
|
|
826
|
+
}
|
|
827
|
+
}, [
|
|
828
|
+
colorMode,
|
|
829
|
+
setColorMode
|
|
747
830
|
]);
|
|
748
831
|
return [
|
|
749
832
|
dark,
|
|
750
|
-
|
|
833
|
+
toggle,
|
|
751
834
|
setDark
|
|
752
835
|
];
|
|
753
836
|
};
|
|
@@ -3717,6 +3800,29 @@ const useBroadcastChannel = (options)=>{
|
|
|
3717
3800
|
};
|
|
3718
3801
|
};
|
|
3719
3802
|
|
|
3803
|
+
const useBoolean = (initialValue = false)=>{
|
|
3804
|
+
const [value, setValue] = useState(initialValue);
|
|
3805
|
+
const setTrue = useEvent(()=>{
|
|
3806
|
+
setValue(true);
|
|
3807
|
+
});
|
|
3808
|
+
const setFalse = useEvent(()=>{
|
|
3809
|
+
setValue(false);
|
|
3810
|
+
});
|
|
3811
|
+
const toggle = useEvent(()=>{
|
|
3812
|
+
setValue((prev)=>!prev);
|
|
3813
|
+
});
|
|
3814
|
+
const handleSetValue = useEvent((newValue)=>{
|
|
3815
|
+
setValue(newValue);
|
|
3816
|
+
});
|
|
3817
|
+
return {
|
|
3818
|
+
value,
|
|
3819
|
+
setValue: handleSetValue,
|
|
3820
|
+
setTrue,
|
|
3821
|
+
setFalse,
|
|
3822
|
+
toggle
|
|
3823
|
+
};
|
|
3824
|
+
};
|
|
3825
|
+
|
|
3720
3826
|
const useDevicePixelRatio = ()=>{
|
|
3721
3827
|
const [pixelRatio, setPixelRatio] = useState(1);
|
|
3722
3828
|
const observe = useCallback(()=>{
|
|
@@ -4028,4 +4134,66 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4028
4134
|
};
|
|
4029
4135
|
};
|
|
4030
4136
|
|
|
4031
|
-
|
|
4137
|
+
const useMap = (initialValue)=>{
|
|
4138
|
+
// avoid exec init code every render
|
|
4139
|
+
const initFunc = ()=>{
|
|
4140
|
+
if (typeof initialValue === 'function') {
|
|
4141
|
+
const result = initialValue();
|
|
4142
|
+
return result instanceof Map ? new Map(result) : new Map(result);
|
|
4143
|
+
}
|
|
4144
|
+
if (initialValue instanceof Map) {
|
|
4145
|
+
return new Map(initialValue);
|
|
4146
|
+
}
|
|
4147
|
+
if (Array.isArray(initialValue)) {
|
|
4148
|
+
return new Map(initialValue);
|
|
4149
|
+
}
|
|
4150
|
+
return new Map();
|
|
4151
|
+
};
|
|
4152
|
+
const [map, setMap] = useState(initFunc);
|
|
4153
|
+
const set = useEvent((key, value)=>{
|
|
4154
|
+
setMap((prevMap)=>{
|
|
4155
|
+
const newMap = new Map(prevMap);
|
|
4156
|
+
newMap.set(key, value);
|
|
4157
|
+
return newMap;
|
|
4158
|
+
});
|
|
4159
|
+
});
|
|
4160
|
+
const get = useCallback((key)=>{
|
|
4161
|
+
return map.get(key);
|
|
4162
|
+
}, [
|
|
4163
|
+
map
|
|
4164
|
+
]);
|
|
4165
|
+
const remove = useEvent((key)=>{
|
|
4166
|
+
const hasKey = map.has(key);
|
|
4167
|
+
if (hasKey) {
|
|
4168
|
+
setMap((prevMap)=>{
|
|
4169
|
+
const newMap = new Map(prevMap);
|
|
4170
|
+
newMap.delete(key);
|
|
4171
|
+
return newMap;
|
|
4172
|
+
});
|
|
4173
|
+
}
|
|
4174
|
+
return hasKey;
|
|
4175
|
+
});
|
|
4176
|
+
const has = useCallback((key)=>{
|
|
4177
|
+
return map.has(key);
|
|
4178
|
+
}, [
|
|
4179
|
+
map
|
|
4180
|
+
]);
|
|
4181
|
+
const clear = useEvent(()=>{
|
|
4182
|
+
setMap(new Map());
|
|
4183
|
+
});
|
|
4184
|
+
const reset = useEvent(()=>{
|
|
4185
|
+
setMap(initFunc());
|
|
4186
|
+
});
|
|
4187
|
+
return {
|
|
4188
|
+
map,
|
|
4189
|
+
set,
|
|
4190
|
+
get,
|
|
4191
|
+
remove,
|
|
4192
|
+
has,
|
|
4193
|
+
clear,
|
|
4194
|
+
reset,
|
|
4195
|
+
size: map.size
|
|
4196
|
+
};
|
|
4197
|
+
};
|
|
4198
|
+
|
|
4199
|
+
export { assignRef, defaultOptions, mergeRefs, use, useActiveElement, useAsyncEffect, useBoolean, useBroadcastChannel, useClickOutside as useClickAway, useClickOutside, useClipboard, useColorMode, useControlled, useCookie, useClipboard as useCopyToClipboard, useCountDown, useCounter, useCssVar, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDevicePixelRatio, useDisclosure, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetchEventSource, useFileDialog, useFirstMountState, useFocus, useFps, useFullscreen, useGeolocation, useHover, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLocationSelector, useLongPress, useMap, useMeasure, useMediaDevices, useMediaQuery, useMergedRefs, useMobileLandscape, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePlatform, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|