@reactuses/core 6.1.12 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -37
- package/dist/index.cjs +271 -110
- package/dist/index.d.cts +91 -2
- package/dist/index.d.mts +91 -2
- package/dist/index.d.ts +91 -2
- package/dist/index.mjs +271 -111
- package/package.json +35 -5
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useLayoutEffect, useEffect, useRef, useReducer, useState, useCallback, useMemo } from 'react';
|
|
2
2
|
import { isEqual, debounce, throttle } from 'lodash-es';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
|
-
import screenfull from 'screenfull';
|
|
5
4
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
5
|
+
import screenfull from 'screenfull';
|
|
6
6
|
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
7
7
|
|
|
8
8
|
var _window_navigator, _window;
|
|
@@ -215,7 +215,7 @@ function useMountedState() {
|
|
|
215
215
|
return get;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
function asyncGeneratorStep$
|
|
218
|
+
function asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, key, arg) {
|
|
219
219
|
try {
|
|
220
220
|
var info = gen[key](arg);
|
|
221
221
|
var value = info.value;
|
|
@@ -229,16 +229,16 @@ function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
229
229
|
Promise.resolve(value).then(_next, _throw);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
function _async_to_generator$
|
|
232
|
+
function _async_to_generator$8(fn) {
|
|
233
233
|
return function() {
|
|
234
234
|
var self = this, args = arguments;
|
|
235
235
|
return new Promise(function(resolve, reject) {
|
|
236
236
|
var gen = fn.apply(self, args);
|
|
237
237
|
function _next(value) {
|
|
238
|
-
asyncGeneratorStep$
|
|
238
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "next", value);
|
|
239
239
|
}
|
|
240
240
|
function _throw(err) {
|
|
241
|
-
asyncGeneratorStep$
|
|
241
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "throw", err);
|
|
242
242
|
}
|
|
243
243
|
_next(undefined);
|
|
244
244
|
});
|
|
@@ -247,7 +247,7 @@ function _async_to_generator$7(fn) {
|
|
|
247
247
|
const useAsyncEffect = (effect, cleanup = noop$1, deps)=>{
|
|
248
248
|
const mounted = useMountedState();
|
|
249
249
|
useEffect(()=>{
|
|
250
|
-
const execute = ()=>_async_to_generator$
|
|
250
|
+
const execute = ()=>_async_to_generator$8(function*() {
|
|
251
251
|
if (!mounted()) {
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
@@ -284,7 +284,7 @@ const useClickOutside = (target, handler, enabled = true)=>{
|
|
|
284
284
|
useEventListener('touchstart', listener, defaultWindow, listerOptions);
|
|
285
285
|
};
|
|
286
286
|
|
|
287
|
-
function getInitialState$
|
|
287
|
+
function getInitialState$4(key, defaultValue) {
|
|
288
288
|
// Prevent a React hydration mismatch when a default value is provided.
|
|
289
289
|
if (defaultValue !== undefined) {
|
|
290
290
|
return defaultValue;
|
|
@@ -298,7 +298,7 @@ function getInitialState$5(key, defaultValue) {
|
|
|
298
298
|
return '';
|
|
299
299
|
}
|
|
300
300
|
const useCookie = (key, options = defaultOptions$1, defaultValue)=>{
|
|
301
|
-
const [cookieValue, setCookieValue] = useState(getInitialState$
|
|
301
|
+
const [cookieValue, setCookieValue] = useState(getInitialState$4(key, defaultValue));
|
|
302
302
|
useEffect(()=>{
|
|
303
303
|
const getStoredValue = ()=>{
|
|
304
304
|
const raw = Cookies.get(key);
|
|
@@ -517,7 +517,7 @@ const defaultOptions = {
|
|
|
517
517
|
observe: false
|
|
518
518
|
};
|
|
519
519
|
|
|
520
|
-
function getInitialState$
|
|
520
|
+
function getInitialState$3(defaultValue) {
|
|
521
521
|
// Prevent a React hydration mismatch when a default value is provided.
|
|
522
522
|
if (defaultValue !== undefined) {
|
|
523
523
|
return defaultValue;
|
|
@@ -532,7 +532,7 @@ function getInitialState$4(defaultValue) {
|
|
|
532
532
|
}
|
|
533
533
|
const useCssVar = (prop, target, defaultValue, options = defaultOptions)=>{
|
|
534
534
|
const { observe } = options;
|
|
535
|
-
const [variable, setVariable] = useState(getInitialState$
|
|
535
|
+
const [variable, setVariable] = useState(getInitialState$3(defaultValue));
|
|
536
536
|
const observerRef = useRef();
|
|
537
537
|
const set = useCallback((v)=>{
|
|
538
538
|
const element = getTargetElement(target);
|
|
@@ -654,28 +654,6 @@ const StorageSerializers = {
|
|
|
654
654
|
write: (v)=>v.toISOString()
|
|
655
655
|
}
|
|
656
656
|
};
|
|
657
|
-
function getInitialState$3(key, defaultValue, storage, serializer, onError) {
|
|
658
|
-
// Prevent a React hydration mismatch when a default value is provided.
|
|
659
|
-
if (defaultValue !== undefined) {
|
|
660
|
-
return defaultValue;
|
|
661
|
-
}
|
|
662
|
-
if (isBrowser) {
|
|
663
|
-
try {
|
|
664
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
665
|
-
if (raw !== undefined && raw !== null) {
|
|
666
|
-
return serializer == null ? void 0 : serializer.read(raw);
|
|
667
|
-
}
|
|
668
|
-
return null;
|
|
669
|
-
} catch (error) {
|
|
670
|
-
onError == null ? void 0 : onError(error);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
// A default value has not been provided, and you are rendering on the server, warn of a possible hydration mismatch when defaulting to false.
|
|
674
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
675
|
-
console.warn('`createStorage` When server side rendering, defaultValue should be defined to prevent a hydration mismatches.');
|
|
676
|
-
}
|
|
677
|
-
return null;
|
|
678
|
-
}
|
|
679
657
|
function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStorage : undefined, options = defaultOptions$1) {
|
|
680
658
|
let storage;
|
|
681
659
|
const { onError = defaultOnError, effectStorageValue, mountStorageValue, listenToStorageChanges = true } = options;
|
|
@@ -689,65 +667,135 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
689
667
|
const type = guessSerializerType(defaultValue);
|
|
690
668
|
var _options_serializer;
|
|
691
669
|
const serializerRef = useLatest((_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type]);
|
|
692
|
-
|
|
693
|
-
|
|
670
|
+
// storageRef and defaultValueRef are updated synchronously each render so that
|
|
671
|
+
// the stable getSnapshot/getServerSnapshot closures always read current values.
|
|
672
|
+
const storageRef = useRef(storage);
|
|
673
|
+
storageRef.current = storage;
|
|
674
|
+
const defaultValueRef = useRef(defaultValue);
|
|
675
|
+
defaultValueRef.current = defaultValue;
|
|
676
|
+
// Cache for referential stability of deserialized values.
|
|
677
|
+
// lastRawRef uses three-state semantics:
|
|
678
|
+
// undefined → no cached value (initial state or after key change) — absent key yields defaultValue
|
|
679
|
+
// null → key was explicitly removed (setState(null) or cross-tab) — absent key yields null
|
|
680
|
+
// string → cached raw string — compared for referential stability
|
|
681
|
+
const lastRawRef = useRef(undefined);
|
|
682
|
+
const lastKeyRef = useRef(key);
|
|
683
|
+
const lastValueRef = useRef(defaultValue != null ? defaultValue : null);
|
|
684
|
+
// Reset per-key caches when the key changes (runs during render, before snapshot).
|
|
685
|
+
if (lastKeyRef.current !== key) {
|
|
686
|
+
lastKeyRef.current = key;
|
|
687
|
+
lastRawRef.current = undefined;
|
|
688
|
+
lastValueRef.current = defaultValue != null ? defaultValue : null;
|
|
689
|
+
}
|
|
690
|
+
// Internal per-instance subscriber callback stored so updateState can notify it.
|
|
691
|
+
const notifyRef = useRef(null);
|
|
692
|
+
const getSnapshot = useRef(()=>{
|
|
693
|
+
const currentStorage = storageRef.current;
|
|
694
|
+
var _defaultValueRef_current;
|
|
695
|
+
const fallback = (_defaultValueRef_current = defaultValueRef.current) != null ? _defaultValueRef_current : null;
|
|
696
|
+
if (!currentStorage) {
|
|
697
|
+
// Storage unavailable — act as an in-memory state holder using the same
|
|
698
|
+
// three-state lastRawRef semantics so updateState() still works.
|
|
699
|
+
if (lastRawRef.current === undefined) return fallback;
|
|
700
|
+
return lastRawRef.current === null ? null : lastValueRef.current;
|
|
701
|
+
}
|
|
702
|
+
try {
|
|
703
|
+
const raw = currentStorage.getItem(lastKeyRef.current);
|
|
704
|
+
if (raw === null) {
|
|
705
|
+
// lastRawRef === null means the key was explicitly removed; return null.
|
|
706
|
+
// lastRawRef !== null means the key is merely absent (e.g. after key change); return defaultValue.
|
|
707
|
+
return lastRawRef.current === null ? null : fallback;
|
|
708
|
+
}
|
|
709
|
+
if (raw === lastRawRef.current) return lastValueRef.current;
|
|
710
|
+
const deserialized = serializerRef.current.read(raw);
|
|
711
|
+
lastRawRef.current = raw;
|
|
712
|
+
lastValueRef.current = deserialized;
|
|
713
|
+
return deserialized;
|
|
714
|
+
} catch (e) {
|
|
715
|
+
onErrorRef.current(e);
|
|
716
|
+
return fallback;
|
|
717
|
+
}
|
|
718
|
+
}).current;
|
|
719
|
+
const getServerSnapshot = useRef(()=>{
|
|
720
|
+
var _defaultValueRef_current;
|
|
721
|
+
return (_defaultValueRef_current = defaultValueRef.current) != null ? _defaultValueRef_current : null;
|
|
722
|
+
}).current;
|
|
723
|
+
// subscribe is stable: it only registers/clears the React-provided callback.
|
|
724
|
+
// Cross-tab listener management is handled separately in a useEffect so that
|
|
725
|
+
// changes to listenToStorageChanges are properly reflected after mount.
|
|
726
|
+
const subscribe = useRef((callback)=>{
|
|
727
|
+
notifyRef.current = callback;
|
|
728
|
+
return ()=>{
|
|
729
|
+
notifyRef.current = null;
|
|
730
|
+
};
|
|
731
|
+
}).current;
|
|
732
|
+
const state = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
733
|
+
// Manage the cross-tab storage listener independently so that toggling
|
|
734
|
+
// listenToStorageChanges after mount correctly adds or removes the listener.
|
|
735
|
+
useEffect(()=>{
|
|
736
|
+
if (!listenToStorageChanges || !isBrowser) return;
|
|
737
|
+
const crossTabListener = (e)=>{
|
|
738
|
+
// e.key is null when storage.clear() is called from another tab (Web Storage
|
|
739
|
+
// spec). In that case all keys are affected, so always notify. Otherwise only
|
|
740
|
+
// notify when the event matches the current key.
|
|
741
|
+
// lastKeyRef is updated synchronously during render, so it always holds the
|
|
742
|
+
// latest key at the time this async event fires.
|
|
743
|
+
if (e.key !== null && e.key !== lastKeyRef.current) return;
|
|
744
|
+
// e.newValue is null when the key was removed (removeItem or clear).
|
|
745
|
+
// Update the in-memory caches now so getSnapshot returns null immediately
|
|
746
|
+
// rather than falling back to defaultValue, matching the old behavior where
|
|
747
|
+
// the cross-tab listener called updateState(null) for absent keys.
|
|
748
|
+
if (e.newValue === null) {
|
|
749
|
+
lastRawRef.current = null;
|
|
750
|
+
lastValueRef.current = null;
|
|
751
|
+
}
|
|
752
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
753
|
+
};
|
|
754
|
+
window.addEventListener('storage', crossTabListener);
|
|
755
|
+
return ()=>window.removeEventListener('storage', crossTabListener);
|
|
756
|
+
}, [
|
|
757
|
+
listenToStorageChanges
|
|
758
|
+
]);
|
|
759
|
+
// Write mountStorageValue / defaultValue to storage on mount when key is absent.
|
|
760
|
+
useEffect(()=>{
|
|
694
761
|
const serializer = serializerRef.current;
|
|
695
762
|
const storageValue = storageValueRef.current;
|
|
696
763
|
var _ref;
|
|
697
764
|
const data = (_ref = storageValue ? isFunction(storageValue) ? storageValue() : storageValue : defaultValue) != null ? _ref : null;
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
705
|
-
return data;
|
|
706
|
-
}
|
|
707
|
-
} catch (e) {
|
|
708
|
-
onErrorRef.current(e);
|
|
765
|
+
try {
|
|
766
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
767
|
+
if ((raw === null || raw === undefined) && data !== null) {
|
|
768
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
769
|
+
lastRawRef.current = undefined;
|
|
770
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
709
771
|
}
|
|
710
|
-
}
|
|
711
|
-
|
|
772
|
+
} catch (e) {
|
|
773
|
+
onErrorRef.current(e);
|
|
774
|
+
}
|
|
775
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
712
776
|
}, [
|
|
713
777
|
key,
|
|
714
778
|
storage
|
|
715
779
|
]);
|
|
716
780
|
const updateState = useEvent((valOrFunc)=>{
|
|
717
|
-
const currentState = isFunction(valOrFunc) ? valOrFunc(
|
|
718
|
-
setState(currentState);
|
|
781
|
+
const currentState = isFunction(valOrFunc) ? valOrFunc(getSnapshot()) : valOrFunc;
|
|
719
782
|
if (currentState === null) {
|
|
720
783
|
storage == null ? void 0 : storage.removeItem(key);
|
|
784
|
+
lastRawRef.current = null;
|
|
785
|
+
lastValueRef.current = null;
|
|
721
786
|
} else {
|
|
722
787
|
try {
|
|
723
|
-
|
|
788
|
+
const raw = serializerRef.current.write(currentState);
|
|
789
|
+
storage == null ? void 0 : storage.setItem(key, raw);
|
|
790
|
+
lastRawRef.current = raw;
|
|
791
|
+
lastValueRef.current = currentState;
|
|
724
792
|
} catch (e) {
|
|
725
793
|
onErrorRef.current(e);
|
|
794
|
+
return;
|
|
726
795
|
}
|
|
727
796
|
}
|
|
797
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
728
798
|
});
|
|
729
|
-
const listener = useEvent(()=>{
|
|
730
|
-
try {
|
|
731
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
732
|
-
if (raw !== undefined && raw !== null) {
|
|
733
|
-
updateState(serializerRef.current.read(raw));
|
|
734
|
-
} else {
|
|
735
|
-
updateState(null);
|
|
736
|
-
}
|
|
737
|
-
} catch (e) {
|
|
738
|
-
onErrorRef.current(e);
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
useEffect(()=>{
|
|
742
|
-
if (listenToStorageChanges) {
|
|
743
|
-
window.addEventListener('storage', listener);
|
|
744
|
-
return ()=>window.removeEventListener('storage', listener);
|
|
745
|
-
}
|
|
746
|
-
return ()=>{};
|
|
747
|
-
}, [
|
|
748
|
-
listenToStorageChanges,
|
|
749
|
-
listener
|
|
750
|
-
]);
|
|
751
799
|
return [
|
|
752
800
|
state,
|
|
753
801
|
updateState
|
|
@@ -1352,7 +1400,7 @@ function useSupported(callback, sync = false) {
|
|
|
1352
1400
|
return supported;
|
|
1353
1401
|
}
|
|
1354
1402
|
|
|
1355
|
-
function asyncGeneratorStep$
|
|
1403
|
+
function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1356
1404
|
try {
|
|
1357
1405
|
var info = gen[key](arg);
|
|
1358
1406
|
var value = info.value;
|
|
@@ -1366,16 +1414,16 @@ function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1366
1414
|
Promise.resolve(value).then(_next, _throw);
|
|
1367
1415
|
}
|
|
1368
1416
|
}
|
|
1369
|
-
function _async_to_generator$
|
|
1417
|
+
function _async_to_generator$7(fn) {
|
|
1370
1418
|
return function() {
|
|
1371
1419
|
var self = this, args = arguments;
|
|
1372
1420
|
return new Promise(function(resolve, reject) {
|
|
1373
1421
|
var gen = fn.apply(self, args);
|
|
1374
1422
|
function _next(value) {
|
|
1375
|
-
asyncGeneratorStep$
|
|
1423
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "next", value);
|
|
1376
1424
|
}
|
|
1377
1425
|
function _throw(err) {
|
|
1378
|
-
asyncGeneratorStep$
|
|
1426
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1379
1427
|
}
|
|
1380
1428
|
_next(undefined);
|
|
1381
1429
|
});
|
|
@@ -1383,7 +1431,7 @@ function _async_to_generator$6(fn) {
|
|
|
1383
1431
|
}
|
|
1384
1432
|
const useEyeDropper = ()=>{
|
|
1385
1433
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1386
|
-
const open = useCallback((options = {})=>_async_to_generator$
|
|
1434
|
+
const open = useCallback((options = {})=>_async_to_generator$7(function*() {
|
|
1387
1435
|
if (!isSupported) {
|
|
1388
1436
|
return {
|
|
1389
1437
|
sRGBHex: ''
|
|
@@ -1418,7 +1466,7 @@ function useFavicon(href, baseUrl = '', rel = 'icon') {
|
|
|
1418
1466
|
]);
|
|
1419
1467
|
}
|
|
1420
1468
|
|
|
1421
|
-
function asyncGeneratorStep$
|
|
1469
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1422
1470
|
try {
|
|
1423
1471
|
var info = gen[key](arg);
|
|
1424
1472
|
var value = info.value;
|
|
@@ -1432,16 +1480,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1432
1480
|
Promise.resolve(value).then(_next, _throw);
|
|
1433
1481
|
}
|
|
1434
1482
|
}
|
|
1435
|
-
function _async_to_generator$
|
|
1483
|
+
function _async_to_generator$6(fn) {
|
|
1436
1484
|
return function() {
|
|
1437
1485
|
var self = this, args = arguments;
|
|
1438
1486
|
return new Promise(function(resolve, reject) {
|
|
1439
1487
|
var gen = fn.apply(self, args);
|
|
1440
1488
|
function _next(value) {
|
|
1441
|
-
asyncGeneratorStep$
|
|
1489
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
1442
1490
|
}
|
|
1443
1491
|
function _throw(err) {
|
|
1444
|
-
asyncGeneratorStep$
|
|
1492
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1445
1493
|
}
|
|
1446
1494
|
_next(undefined);
|
|
1447
1495
|
});
|
|
@@ -1484,7 +1532,7 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1484
1532
|
return input;
|
|
1485
1533
|
}, []);
|
|
1486
1534
|
inputRef.current = initFn();
|
|
1487
|
-
const open = (localOptions)=>_async_to_generator$
|
|
1535
|
+
const open = (localOptions)=>_async_to_generator$6(function*() {
|
|
1488
1536
|
if (!inputRef.current) {
|
|
1489
1537
|
return;
|
|
1490
1538
|
}
|
|
@@ -1897,7 +1945,7 @@ const createUpdateEffect = (hook)=>(effect, deps)=>{
|
|
|
1897
1945
|
|
|
1898
1946
|
const useUpdateEffect = createUpdateEffect(useEffect);
|
|
1899
1947
|
|
|
1900
|
-
function asyncGeneratorStep$
|
|
1948
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1901
1949
|
try {
|
|
1902
1950
|
var info = gen[key](arg);
|
|
1903
1951
|
var value = info.value;
|
|
@@ -1911,16 +1959,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1911
1959
|
Promise.resolve(value).then(_next, _throw);
|
|
1912
1960
|
}
|
|
1913
1961
|
}
|
|
1914
|
-
function _async_to_generator$
|
|
1962
|
+
function _async_to_generator$5(fn) {
|
|
1915
1963
|
return function() {
|
|
1916
1964
|
var self = this, args = arguments;
|
|
1917
1965
|
return new Promise(function(resolve, reject) {
|
|
1918
1966
|
var gen = fn.apply(self, args);
|
|
1919
1967
|
function _next(value) {
|
|
1920
|
-
asyncGeneratorStep$
|
|
1968
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1921
1969
|
}
|
|
1922
1970
|
function _throw(err) {
|
|
1923
|
-
asyncGeneratorStep$
|
|
1971
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1924
1972
|
}
|
|
1925
1973
|
_next(undefined);
|
|
1926
1974
|
});
|
|
@@ -1953,7 +2001,7 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1953
2001
|
const di = state[3][direction];
|
|
1954
2002
|
useUpdateEffect(()=>{
|
|
1955
2003
|
const element = getTargetElement(target);
|
|
1956
|
-
const fn = ()=>_async_to_generator$
|
|
2004
|
+
const fn = ()=>_async_to_generator$5(function*() {
|
|
1957
2005
|
var _element_scrollHeight, _element_scrollWidth;
|
|
1958
2006
|
const previous = {
|
|
1959
2007
|
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
@@ -2103,7 +2151,7 @@ const useMeasure = (target, options = defaultOptions$1)=>{
|
|
|
2103
2151
|
];
|
|
2104
2152
|
};
|
|
2105
2153
|
|
|
2106
|
-
function asyncGeneratorStep$
|
|
2154
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2107
2155
|
try {
|
|
2108
2156
|
var info = gen[key](arg);
|
|
2109
2157
|
var value = info.value;
|
|
@@ -2117,16 +2165,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
2117
2165
|
Promise.resolve(value).then(_next, _throw);
|
|
2118
2166
|
}
|
|
2119
2167
|
}
|
|
2120
|
-
function _async_to_generator$
|
|
2168
|
+
function _async_to_generator$4(fn) {
|
|
2121
2169
|
return function() {
|
|
2122
2170
|
var self = this, args = arguments;
|
|
2123
2171
|
return new Promise(function(resolve, reject) {
|
|
2124
2172
|
var gen = fn.apply(self, args);
|
|
2125
2173
|
function _next(value) {
|
|
2126
|
-
asyncGeneratorStep$
|
|
2174
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
2127
2175
|
}
|
|
2128
2176
|
function _throw(err) {
|
|
2129
|
-
asyncGeneratorStep$
|
|
2177
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2130
2178
|
}
|
|
2131
2179
|
_next(undefined);
|
|
2132
2180
|
});
|
|
@@ -2160,7 +2208,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2160
2208
|
});
|
|
2161
2209
|
}).catch(noop$1);
|
|
2162
2210
|
}, []);
|
|
2163
|
-
const ensurePermissions = useCallback(()=>_async_to_generator$
|
|
2211
|
+
const ensurePermissions = useCallback(()=>_async_to_generator$4(function*() {
|
|
2164
2212
|
if (!isSupported) {
|
|
2165
2213
|
return false;
|
|
2166
2214
|
}
|
|
@@ -3249,7 +3297,10 @@ function useSticky(targetElement, { axis = 'y', nav = 0 }, scrollElement) {
|
|
|
3249
3297
|
}, [
|
|
3250
3298
|
targetKey,
|
|
3251
3299
|
scrollKey,
|
|
3252
|
-
scrollHandler
|
|
3300
|
+
scrollHandler,
|
|
3301
|
+
targetRef,
|
|
3302
|
+
scrollRef,
|
|
3303
|
+
axisRef
|
|
3253
3304
|
]);
|
|
3254
3305
|
return [
|
|
3255
3306
|
isSticky,
|
|
@@ -3399,7 +3450,7 @@ const useToggle = (initialValue)=>{
|
|
|
3399
3450
|
|
|
3400
3451
|
const useUpdateLayoutEffect = createUpdateEffect(useLayoutEffect);
|
|
3401
3452
|
|
|
3402
|
-
function asyncGeneratorStep$
|
|
3453
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3403
3454
|
try {
|
|
3404
3455
|
var info = gen[key](arg);
|
|
3405
3456
|
var value = info.value;
|
|
@@ -3413,16 +3464,16 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3413
3464
|
Promise.resolve(value).then(_next, _throw);
|
|
3414
3465
|
}
|
|
3415
3466
|
}
|
|
3416
|
-
function _async_to_generator$
|
|
3467
|
+
function _async_to_generator$3(fn) {
|
|
3417
3468
|
return function() {
|
|
3418
3469
|
var self = this, args = arguments;
|
|
3419
3470
|
return new Promise(function(resolve, reject) {
|
|
3420
3471
|
var gen = fn.apply(self, args);
|
|
3421
3472
|
function _next(value) {
|
|
3422
|
-
asyncGeneratorStep$
|
|
3473
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
3423
3474
|
}
|
|
3424
3475
|
function _throw(err) {
|
|
3425
|
-
asyncGeneratorStep$
|
|
3476
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3426
3477
|
}
|
|
3427
3478
|
_next(undefined);
|
|
3428
3479
|
});
|
|
@@ -3452,7 +3503,7 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3452
3503
|
}, [
|
|
3453
3504
|
isSupported
|
|
3454
3505
|
]);
|
|
3455
|
-
const ensurePermissions = useCallback(()=>_async_to_generator$
|
|
3506
|
+
const ensurePermissions = useCallback(()=>_async_to_generator$3(function*() {
|
|
3456
3507
|
if (!isSupported) return;
|
|
3457
3508
|
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3458
3509
|
const result = yield Notification.requestPermission();
|
|
@@ -3563,7 +3614,7 @@ const useWindowSize = ()=>{
|
|
|
3563
3614
|
};
|
|
3564
3615
|
};
|
|
3565
3616
|
|
|
3566
|
-
function asyncGeneratorStep$
|
|
3617
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3567
3618
|
try {
|
|
3568
3619
|
var info = gen[key](arg);
|
|
3569
3620
|
var value = info.value;
|
|
@@ -3577,16 +3628,16 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3577
3628
|
Promise.resolve(value).then(_next, _throw);
|
|
3578
3629
|
}
|
|
3579
3630
|
}
|
|
3580
|
-
function _async_to_generator$
|
|
3631
|
+
function _async_to_generator$2(fn) {
|
|
3581
3632
|
return function() {
|
|
3582
3633
|
var self = this, args = arguments;
|
|
3583
3634
|
return new Promise(function(resolve, reject) {
|
|
3584
3635
|
var gen = fn.apply(self, args);
|
|
3585
3636
|
function _next(value) {
|
|
3586
|
-
asyncGeneratorStep$
|
|
3637
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
3587
3638
|
}
|
|
3588
3639
|
function _throw(err) {
|
|
3589
|
-
asyncGeneratorStep$
|
|
3640
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3590
3641
|
}
|
|
3591
3642
|
_next(undefined);
|
|
3592
3643
|
});
|
|
@@ -3594,7 +3645,7 @@ function _async_to_generator$1(fn) {
|
|
|
3594
3645
|
}
|
|
3595
3646
|
const useClipboard = ()=>{
|
|
3596
3647
|
const [text, setText] = useState('');
|
|
3597
|
-
const updateText = useCallback(()=>_async_to_generator$
|
|
3648
|
+
const updateText = useCallback(()=>_async_to_generator$2(function*() {
|
|
3598
3649
|
// Check if document is focused before attempting to read clipboard
|
|
3599
3650
|
if (!document.hasFocus()) {
|
|
3600
3651
|
return;
|
|
@@ -3611,7 +3662,7 @@ const useClipboard = ()=>{
|
|
|
3611
3662
|
useEventListener('cut', updateText);
|
|
3612
3663
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3613
3664
|
useEventListener('focus', updateText, window);
|
|
3614
|
-
const copy = useCallback((txt)=>_async_to_generator$
|
|
3665
|
+
const copy = useCallback((txt)=>_async_to_generator$2(function*() {
|
|
3615
3666
|
setText(txt);
|
|
3616
3667
|
try {
|
|
3617
3668
|
yield window.navigator.clipboard.writeText(txt);
|
|
@@ -4139,7 +4190,7 @@ const useElementByPoint = (options)=>{
|
|
|
4139
4190
|
};
|
|
4140
4191
|
};
|
|
4141
4192
|
|
|
4142
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4193
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4143
4194
|
try {
|
|
4144
4195
|
var info = gen[key](arg);
|
|
4145
4196
|
var value = info.value;
|
|
@@ -4153,16 +4204,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
4153
4204
|
Promise.resolve(value).then(_next, _throw);
|
|
4154
4205
|
}
|
|
4155
4206
|
}
|
|
4156
|
-
function _async_to_generator(fn) {
|
|
4207
|
+
function _async_to_generator$1(fn) {
|
|
4157
4208
|
return function() {
|
|
4158
4209
|
var self = this, args = arguments;
|
|
4159
4210
|
return new Promise(function(resolve, reject) {
|
|
4160
4211
|
var gen = fn.apply(self, args);
|
|
4161
4212
|
function _next(value) {
|
|
4162
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4213
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
4163
4214
|
}
|
|
4164
4215
|
function _throw(err) {
|
|
4165
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4216
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4166
4217
|
}
|
|
4167
4218
|
_next(undefined);
|
|
4168
4219
|
});
|
|
@@ -4213,7 +4264,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4213
4264
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
4214
4265
|
}
|
|
4215
4266
|
});
|
|
4216
|
-
const open = useEvent(()=>_async_to_generator(function*() {
|
|
4267
|
+
const open = useEvent(()=>_async_to_generator$1(function*() {
|
|
4217
4268
|
close();
|
|
4218
4269
|
setStatus('CONNECTING');
|
|
4219
4270
|
explicitlyClosed.current = false;
|
|
@@ -4252,7 +4303,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4252
4303
|
}
|
|
4253
4304
|
yield fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
4254
4305
|
onopen (response) {
|
|
4255
|
-
return _async_to_generator(function*() {
|
|
4306
|
+
return _async_to_generator$1(function*() {
|
|
4256
4307
|
if (response.ok) {
|
|
4257
4308
|
setStatus('CONNECTED');
|
|
4258
4309
|
setError(null);
|
|
@@ -4501,4 +4552,113 @@ const useSpeechRecognition = (options = {})=>{
|
|
|
4501
4552
|
};
|
|
4502
4553
|
};
|
|
4503
4554
|
|
|
4504
|
-
|
|
4555
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4556
|
+
try {
|
|
4557
|
+
var info = gen[key](arg);
|
|
4558
|
+
var value = info.value;
|
|
4559
|
+
} catch (error) {
|
|
4560
|
+
reject(error);
|
|
4561
|
+
return;
|
|
4562
|
+
}
|
|
4563
|
+
if (info.done) {
|
|
4564
|
+
resolve(value);
|
|
4565
|
+
} else {
|
|
4566
|
+
Promise.resolve(value).then(_next, _throw);
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
function _async_to_generator(fn) {
|
|
4570
|
+
return function() {
|
|
4571
|
+
var self = this, args = arguments;
|
|
4572
|
+
return new Promise(function(resolve, reject) {
|
|
4573
|
+
var gen = fn.apply(self, args);
|
|
4574
|
+
function _next(value) {
|
|
4575
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4576
|
+
}
|
|
4577
|
+
function _throw(err) {
|
|
4578
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4579
|
+
}
|
|
4580
|
+
_next(undefined);
|
|
4581
|
+
});
|
|
4582
|
+
};
|
|
4583
|
+
}
|
|
4584
|
+
const useWakeLock = (options = {})=>{
|
|
4585
|
+
const { onRequest, onRelease, onError } = options;
|
|
4586
|
+
const isSupported = useSupported(()=>'wakeLock' in navigator);
|
|
4587
|
+
const [isActive, setIsActive] = useState(false);
|
|
4588
|
+
const sentinelRef = useRef(null);
|
|
4589
|
+
const requestedTypeRef = useRef(false);
|
|
4590
|
+
const forceRequest = useEvent(()=>_async_to_generator(function*() {
|
|
4591
|
+
if (!isSupported) return;
|
|
4592
|
+
try {
|
|
4593
|
+
var _sentinelRef_current;
|
|
4594
|
+
yield (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.release();
|
|
4595
|
+
const sentinel = yield navigator.wakeLock.request('screen');
|
|
4596
|
+
sentinelRef.current = sentinel;
|
|
4597
|
+
setIsActive(true);
|
|
4598
|
+
sentinel.addEventListener('release', ()=>{
|
|
4599
|
+
var _sentinelRef_current;
|
|
4600
|
+
var _sentinelRef_current_type;
|
|
4601
|
+
requestedTypeRef.current = (_sentinelRef_current_type = (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.type) != null ? _sentinelRef_current_type : false;
|
|
4602
|
+
sentinelRef.current = null;
|
|
4603
|
+
setIsActive(false);
|
|
4604
|
+
onRelease == null ? void 0 : onRelease();
|
|
4605
|
+
}, {
|
|
4606
|
+
once: true
|
|
4607
|
+
});
|
|
4608
|
+
onRequest == null ? void 0 : onRequest();
|
|
4609
|
+
} catch (error) {
|
|
4610
|
+
onError == null ? void 0 : onError(error);
|
|
4611
|
+
}
|
|
4612
|
+
})());
|
|
4613
|
+
const request = useEvent(()=>_async_to_generator(function*() {
|
|
4614
|
+
if (!isSupported) return;
|
|
4615
|
+
if (document.visibilityState === 'visible') {
|
|
4616
|
+
yield forceRequest();
|
|
4617
|
+
} else {
|
|
4618
|
+
requestedTypeRef.current = 'screen';
|
|
4619
|
+
}
|
|
4620
|
+
})());
|
|
4621
|
+
const release = useEvent(()=>_async_to_generator(function*() {
|
|
4622
|
+
requestedTypeRef.current = false;
|
|
4623
|
+
const s = sentinelRef.current;
|
|
4624
|
+
sentinelRef.current = null;
|
|
4625
|
+
setIsActive(false);
|
|
4626
|
+
try {
|
|
4627
|
+
yield s == null ? void 0 : s.release();
|
|
4628
|
+
} catch (error) {
|
|
4629
|
+
onError == null ? void 0 : onError(error);
|
|
4630
|
+
}
|
|
4631
|
+
})());
|
|
4632
|
+
useEffect(()=>{
|
|
4633
|
+
const handleVisibilityChange = ()=>{
|
|
4634
|
+
if (document.visibilityState === 'visible' && requestedTypeRef.current) {
|
|
4635
|
+
requestedTypeRef.current = false;
|
|
4636
|
+
forceRequest();
|
|
4637
|
+
}
|
|
4638
|
+
};
|
|
4639
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
4640
|
+
return ()=>{
|
|
4641
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
4642
|
+
};
|
|
4643
|
+
}, [
|
|
4644
|
+
forceRequest
|
|
4645
|
+
]);
|
|
4646
|
+
useEffect(()=>{
|
|
4647
|
+
return ()=>{
|
|
4648
|
+
requestedTypeRef.current = false;
|
|
4649
|
+
if (sentinelRef.current) {
|
|
4650
|
+
sentinelRef.current.release();
|
|
4651
|
+
sentinelRef.current = null;
|
|
4652
|
+
}
|
|
4653
|
+
};
|
|
4654
|
+
}, []);
|
|
4655
|
+
return {
|
|
4656
|
+
isSupported,
|
|
4657
|
+
isActive,
|
|
4658
|
+
request,
|
|
4659
|
+
release,
|
|
4660
|
+
forceRequest
|
|
4661
|
+
};
|
|
4662
|
+
};
|
|
4663
|
+
|
|
4664
|
+
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, useScratch, useScreenSafeArea, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSpeechRecognition, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useWakeLock, useWebNotification, useWindowScroll, useWindowSize, useWindowsFocus };
|