@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.cjs
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var lodashEs = require('lodash-es');
|
|
5
5
|
var Cookies = require('js-cookie');
|
|
6
|
-
var screenfull = require('screenfull');
|
|
7
6
|
var index_js = require('use-sync-external-store/shim/index.js');
|
|
7
|
+
var screenfull = require('screenfull');
|
|
8
8
|
var fetchEventSource = require('@microsoft/fetch-event-source');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -223,7 +223,7 @@ function useMountedState() {
|
|
|
223
223
|
return get;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
function asyncGeneratorStep$
|
|
226
|
+
function asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, key, arg) {
|
|
227
227
|
try {
|
|
228
228
|
var info = gen[key](arg);
|
|
229
229
|
var value = info.value;
|
|
@@ -237,16 +237,16 @@ function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
237
237
|
Promise.resolve(value).then(_next, _throw);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function _async_to_generator$
|
|
240
|
+
function _async_to_generator$8(fn) {
|
|
241
241
|
return function() {
|
|
242
242
|
var self = this, args = arguments;
|
|
243
243
|
return new Promise(function(resolve, reject) {
|
|
244
244
|
var gen = fn.apply(self, args);
|
|
245
245
|
function _next(value) {
|
|
246
|
-
asyncGeneratorStep$
|
|
246
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "next", value);
|
|
247
247
|
}
|
|
248
248
|
function _throw(err) {
|
|
249
|
-
asyncGeneratorStep$
|
|
249
|
+
asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, "throw", err);
|
|
250
250
|
}
|
|
251
251
|
_next(undefined);
|
|
252
252
|
});
|
|
@@ -255,7 +255,7 @@ function _async_to_generator$7(fn) {
|
|
|
255
255
|
const useAsyncEffect = (effect, cleanup = noop$1, deps)=>{
|
|
256
256
|
const mounted = useMountedState();
|
|
257
257
|
React.useEffect(()=>{
|
|
258
|
-
const execute = ()=>_async_to_generator$
|
|
258
|
+
const execute = ()=>_async_to_generator$8(function*() {
|
|
259
259
|
if (!mounted()) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -292,7 +292,7 @@ const useClickOutside = (target, handler, enabled = true)=>{
|
|
|
292
292
|
useEventListener('touchstart', listener, defaultWindow, listerOptions);
|
|
293
293
|
};
|
|
294
294
|
|
|
295
|
-
function getInitialState$
|
|
295
|
+
function getInitialState$4(key, defaultValue) {
|
|
296
296
|
// Prevent a React hydration mismatch when a default value is provided.
|
|
297
297
|
if (defaultValue !== undefined) {
|
|
298
298
|
return defaultValue;
|
|
@@ -306,7 +306,7 @@ function getInitialState$5(key, defaultValue) {
|
|
|
306
306
|
return '';
|
|
307
307
|
}
|
|
308
308
|
const useCookie = (key, options = defaultOptions$1, defaultValue)=>{
|
|
309
|
-
const [cookieValue, setCookieValue] = React.useState(getInitialState$
|
|
309
|
+
const [cookieValue, setCookieValue] = React.useState(getInitialState$4(key, defaultValue));
|
|
310
310
|
React.useEffect(()=>{
|
|
311
311
|
const getStoredValue = ()=>{
|
|
312
312
|
const raw = Cookies__default.default.get(key);
|
|
@@ -525,7 +525,7 @@ const defaultOptions = {
|
|
|
525
525
|
observe: false
|
|
526
526
|
};
|
|
527
527
|
|
|
528
|
-
function getInitialState$
|
|
528
|
+
function getInitialState$3(defaultValue) {
|
|
529
529
|
// Prevent a React hydration mismatch when a default value is provided.
|
|
530
530
|
if (defaultValue !== undefined) {
|
|
531
531
|
return defaultValue;
|
|
@@ -540,7 +540,7 @@ function getInitialState$4(defaultValue) {
|
|
|
540
540
|
}
|
|
541
541
|
const useCssVar = (prop, target, defaultValue, options = defaultOptions)=>{
|
|
542
542
|
const { observe } = options;
|
|
543
|
-
const [variable, setVariable] = React.useState(getInitialState$
|
|
543
|
+
const [variable, setVariable] = React.useState(getInitialState$3(defaultValue));
|
|
544
544
|
const observerRef = React.useRef();
|
|
545
545
|
const set = React.useCallback((v)=>{
|
|
546
546
|
const element = getTargetElement(target);
|
|
@@ -662,28 +662,6 @@ const StorageSerializers = {
|
|
|
662
662
|
write: (v)=>v.toISOString()
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
|
-
function getInitialState$3(key, defaultValue, storage, serializer, onError) {
|
|
666
|
-
// Prevent a React hydration mismatch when a default value is provided.
|
|
667
|
-
if (defaultValue !== undefined) {
|
|
668
|
-
return defaultValue;
|
|
669
|
-
}
|
|
670
|
-
if (isBrowser) {
|
|
671
|
-
try {
|
|
672
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
673
|
-
if (raw !== undefined && raw !== null) {
|
|
674
|
-
return serializer == null ? void 0 : serializer.read(raw);
|
|
675
|
-
}
|
|
676
|
-
return null;
|
|
677
|
-
} catch (error) {
|
|
678
|
-
onError == null ? void 0 : onError(error);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
// A default value has not been provided, and you are rendering on the server, warn of a possible hydration mismatch when defaulting to false.
|
|
682
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
683
|
-
console.warn('`createStorage` When server side rendering, defaultValue should be defined to prevent a hydration mismatches.');
|
|
684
|
-
}
|
|
685
|
-
return null;
|
|
686
|
-
}
|
|
687
665
|
function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStorage : undefined, options = defaultOptions$1) {
|
|
688
666
|
let storage;
|
|
689
667
|
const { onError = defaultOnError, effectStorageValue, mountStorageValue, listenToStorageChanges = true } = options;
|
|
@@ -697,65 +675,135 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
697
675
|
const type = guessSerializerType(defaultValue);
|
|
698
676
|
var _options_serializer;
|
|
699
677
|
const serializerRef = useLatest((_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type]);
|
|
700
|
-
|
|
701
|
-
|
|
678
|
+
// storageRef and defaultValueRef are updated synchronously each render so that
|
|
679
|
+
// the stable getSnapshot/getServerSnapshot closures always read current values.
|
|
680
|
+
const storageRef = React.useRef(storage);
|
|
681
|
+
storageRef.current = storage;
|
|
682
|
+
const defaultValueRef = React.useRef(defaultValue);
|
|
683
|
+
defaultValueRef.current = defaultValue;
|
|
684
|
+
// Cache for referential stability of deserialized values.
|
|
685
|
+
// lastRawRef uses three-state semantics:
|
|
686
|
+
// undefined → no cached value (initial state or after key change) — absent key yields defaultValue
|
|
687
|
+
// null → key was explicitly removed (setState(null) or cross-tab) — absent key yields null
|
|
688
|
+
// string → cached raw string — compared for referential stability
|
|
689
|
+
const lastRawRef = React.useRef(undefined);
|
|
690
|
+
const lastKeyRef = React.useRef(key);
|
|
691
|
+
const lastValueRef = React.useRef(defaultValue != null ? defaultValue : null);
|
|
692
|
+
// Reset per-key caches when the key changes (runs during render, before snapshot).
|
|
693
|
+
if (lastKeyRef.current !== key) {
|
|
694
|
+
lastKeyRef.current = key;
|
|
695
|
+
lastRawRef.current = undefined;
|
|
696
|
+
lastValueRef.current = defaultValue != null ? defaultValue : null;
|
|
697
|
+
}
|
|
698
|
+
// Internal per-instance subscriber callback stored so updateState can notify it.
|
|
699
|
+
const notifyRef = React.useRef(null);
|
|
700
|
+
const getSnapshot = React.useRef(()=>{
|
|
701
|
+
const currentStorage = storageRef.current;
|
|
702
|
+
var _defaultValueRef_current;
|
|
703
|
+
const fallback = (_defaultValueRef_current = defaultValueRef.current) != null ? _defaultValueRef_current : null;
|
|
704
|
+
if (!currentStorage) {
|
|
705
|
+
// Storage unavailable — act as an in-memory state holder using the same
|
|
706
|
+
// three-state lastRawRef semantics so updateState() still works.
|
|
707
|
+
if (lastRawRef.current === undefined) return fallback;
|
|
708
|
+
return lastRawRef.current === null ? null : lastValueRef.current;
|
|
709
|
+
}
|
|
710
|
+
try {
|
|
711
|
+
const raw = currentStorage.getItem(lastKeyRef.current);
|
|
712
|
+
if (raw === null) {
|
|
713
|
+
// lastRawRef === null means the key was explicitly removed; return null.
|
|
714
|
+
// lastRawRef !== null means the key is merely absent (e.g. after key change); return defaultValue.
|
|
715
|
+
return lastRawRef.current === null ? null : fallback;
|
|
716
|
+
}
|
|
717
|
+
if (raw === lastRawRef.current) return lastValueRef.current;
|
|
718
|
+
const deserialized = serializerRef.current.read(raw);
|
|
719
|
+
lastRawRef.current = raw;
|
|
720
|
+
lastValueRef.current = deserialized;
|
|
721
|
+
return deserialized;
|
|
722
|
+
} catch (e) {
|
|
723
|
+
onErrorRef.current(e);
|
|
724
|
+
return fallback;
|
|
725
|
+
}
|
|
726
|
+
}).current;
|
|
727
|
+
const getServerSnapshot = React.useRef(()=>{
|
|
728
|
+
var _defaultValueRef_current;
|
|
729
|
+
return (_defaultValueRef_current = defaultValueRef.current) != null ? _defaultValueRef_current : null;
|
|
730
|
+
}).current;
|
|
731
|
+
// subscribe is stable: it only registers/clears the React-provided callback.
|
|
732
|
+
// Cross-tab listener management is handled separately in a useEffect so that
|
|
733
|
+
// changes to listenToStorageChanges are properly reflected after mount.
|
|
734
|
+
const subscribe = React.useRef((callback)=>{
|
|
735
|
+
notifyRef.current = callback;
|
|
736
|
+
return ()=>{
|
|
737
|
+
notifyRef.current = null;
|
|
738
|
+
};
|
|
739
|
+
}).current;
|
|
740
|
+
const state = index_js.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
741
|
+
// Manage the cross-tab storage listener independently so that toggling
|
|
742
|
+
// listenToStorageChanges after mount correctly adds or removes the listener.
|
|
743
|
+
React.useEffect(()=>{
|
|
744
|
+
if (!listenToStorageChanges || !isBrowser) return;
|
|
745
|
+
const crossTabListener = (e)=>{
|
|
746
|
+
// e.key is null when storage.clear() is called from another tab (Web Storage
|
|
747
|
+
// spec). In that case all keys are affected, so always notify. Otherwise only
|
|
748
|
+
// notify when the event matches the current key.
|
|
749
|
+
// lastKeyRef is updated synchronously during render, so it always holds the
|
|
750
|
+
// latest key at the time this async event fires.
|
|
751
|
+
if (e.key !== null && e.key !== lastKeyRef.current) return;
|
|
752
|
+
// e.newValue is null when the key was removed (removeItem or clear).
|
|
753
|
+
// Update the in-memory caches now so getSnapshot returns null immediately
|
|
754
|
+
// rather than falling back to defaultValue, matching the old behavior where
|
|
755
|
+
// the cross-tab listener called updateState(null) for absent keys.
|
|
756
|
+
if (e.newValue === null) {
|
|
757
|
+
lastRawRef.current = null;
|
|
758
|
+
lastValueRef.current = null;
|
|
759
|
+
}
|
|
760
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
761
|
+
};
|
|
762
|
+
window.addEventListener('storage', crossTabListener);
|
|
763
|
+
return ()=>window.removeEventListener('storage', crossTabListener);
|
|
764
|
+
}, [
|
|
765
|
+
listenToStorageChanges
|
|
766
|
+
]);
|
|
767
|
+
// Write mountStorageValue / defaultValue to storage on mount when key is absent.
|
|
768
|
+
React.useEffect(()=>{
|
|
702
769
|
const serializer = serializerRef.current;
|
|
703
770
|
const storageValue = storageValueRef.current;
|
|
704
771
|
var _ref;
|
|
705
772
|
const data = (_ref = storageValue ? isFunction(storageValue) ? storageValue() : storageValue : defaultValue) != null ? _ref : null;
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
713
|
-
return data;
|
|
714
|
-
}
|
|
715
|
-
} catch (e) {
|
|
716
|
-
onErrorRef.current(e);
|
|
773
|
+
try {
|
|
774
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
775
|
+
if ((raw === null || raw === undefined) && data !== null) {
|
|
776
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
777
|
+
lastRawRef.current = undefined;
|
|
778
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
717
779
|
}
|
|
718
|
-
}
|
|
719
|
-
|
|
780
|
+
} catch (e) {
|
|
781
|
+
onErrorRef.current(e);
|
|
782
|
+
}
|
|
783
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
720
784
|
}, [
|
|
721
785
|
key,
|
|
722
786
|
storage
|
|
723
787
|
]);
|
|
724
788
|
const updateState = useEvent((valOrFunc)=>{
|
|
725
|
-
const currentState = isFunction(valOrFunc) ? valOrFunc(
|
|
726
|
-
setState(currentState);
|
|
789
|
+
const currentState = isFunction(valOrFunc) ? valOrFunc(getSnapshot()) : valOrFunc;
|
|
727
790
|
if (currentState === null) {
|
|
728
791
|
storage == null ? void 0 : storage.removeItem(key);
|
|
792
|
+
lastRawRef.current = null;
|
|
793
|
+
lastValueRef.current = null;
|
|
729
794
|
} else {
|
|
730
795
|
try {
|
|
731
|
-
|
|
796
|
+
const raw = serializerRef.current.write(currentState);
|
|
797
|
+
storage == null ? void 0 : storage.setItem(key, raw);
|
|
798
|
+
lastRawRef.current = raw;
|
|
799
|
+
lastValueRef.current = currentState;
|
|
732
800
|
} catch (e) {
|
|
733
801
|
onErrorRef.current(e);
|
|
802
|
+
return;
|
|
734
803
|
}
|
|
735
804
|
}
|
|
805
|
+
notifyRef.current == null ? void 0 : notifyRef.current.call(notifyRef);
|
|
736
806
|
});
|
|
737
|
-
const listener = useEvent(()=>{
|
|
738
|
-
try {
|
|
739
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
740
|
-
if (raw !== undefined && raw !== null) {
|
|
741
|
-
updateState(serializerRef.current.read(raw));
|
|
742
|
-
} else {
|
|
743
|
-
updateState(null);
|
|
744
|
-
}
|
|
745
|
-
} catch (e) {
|
|
746
|
-
onErrorRef.current(e);
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
React.useEffect(()=>{
|
|
750
|
-
if (listenToStorageChanges) {
|
|
751
|
-
window.addEventListener('storage', listener);
|
|
752
|
-
return ()=>window.removeEventListener('storage', listener);
|
|
753
|
-
}
|
|
754
|
-
return ()=>{};
|
|
755
|
-
}, [
|
|
756
|
-
listenToStorageChanges,
|
|
757
|
-
listener
|
|
758
|
-
]);
|
|
759
807
|
return [
|
|
760
808
|
state,
|
|
761
809
|
updateState
|
|
@@ -1360,7 +1408,7 @@ function useSupported(callback, sync = false) {
|
|
|
1360
1408
|
return supported;
|
|
1361
1409
|
}
|
|
1362
1410
|
|
|
1363
|
-
function asyncGeneratorStep$
|
|
1411
|
+
function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1364
1412
|
try {
|
|
1365
1413
|
var info = gen[key](arg);
|
|
1366
1414
|
var value = info.value;
|
|
@@ -1374,16 +1422,16 @@ function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1374
1422
|
Promise.resolve(value).then(_next, _throw);
|
|
1375
1423
|
}
|
|
1376
1424
|
}
|
|
1377
|
-
function _async_to_generator$
|
|
1425
|
+
function _async_to_generator$7(fn) {
|
|
1378
1426
|
return function() {
|
|
1379
1427
|
var self = this, args = arguments;
|
|
1380
1428
|
return new Promise(function(resolve, reject) {
|
|
1381
1429
|
var gen = fn.apply(self, args);
|
|
1382
1430
|
function _next(value) {
|
|
1383
|
-
asyncGeneratorStep$
|
|
1431
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "next", value);
|
|
1384
1432
|
}
|
|
1385
1433
|
function _throw(err) {
|
|
1386
|
-
asyncGeneratorStep$
|
|
1434
|
+
asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1387
1435
|
}
|
|
1388
1436
|
_next(undefined);
|
|
1389
1437
|
});
|
|
@@ -1391,7 +1439,7 @@ function _async_to_generator$6(fn) {
|
|
|
1391
1439
|
}
|
|
1392
1440
|
const useEyeDropper = ()=>{
|
|
1393
1441
|
const isSupported = useSupported(()=>typeof window !== 'undefined' && 'EyeDropper' in window, true);
|
|
1394
|
-
const open = React.useCallback((options = {})=>_async_to_generator$
|
|
1442
|
+
const open = React.useCallback((options = {})=>_async_to_generator$7(function*() {
|
|
1395
1443
|
if (!isSupported) {
|
|
1396
1444
|
return {
|
|
1397
1445
|
sRGBHex: ''
|
|
@@ -1426,7 +1474,7 @@ function useFavicon(href, baseUrl = '', rel = 'icon') {
|
|
|
1426
1474
|
]);
|
|
1427
1475
|
}
|
|
1428
1476
|
|
|
1429
|
-
function asyncGeneratorStep$
|
|
1477
|
+
function asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1430
1478
|
try {
|
|
1431
1479
|
var info = gen[key](arg);
|
|
1432
1480
|
var value = info.value;
|
|
@@ -1440,16 +1488,16 @@ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1440
1488
|
Promise.resolve(value).then(_next, _throw);
|
|
1441
1489
|
}
|
|
1442
1490
|
}
|
|
1443
|
-
function _async_to_generator$
|
|
1491
|
+
function _async_to_generator$6(fn) {
|
|
1444
1492
|
return function() {
|
|
1445
1493
|
var self = this, args = arguments;
|
|
1446
1494
|
return new Promise(function(resolve, reject) {
|
|
1447
1495
|
var gen = fn.apply(self, args);
|
|
1448
1496
|
function _next(value) {
|
|
1449
|
-
asyncGeneratorStep$
|
|
1497
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "next", value);
|
|
1450
1498
|
}
|
|
1451
1499
|
function _throw(err) {
|
|
1452
|
-
asyncGeneratorStep$
|
|
1500
|
+
asyncGeneratorStep$6(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1453
1501
|
}
|
|
1454
1502
|
_next(undefined);
|
|
1455
1503
|
});
|
|
@@ -1492,7 +1540,7 @@ const useFileDialog = (options = defaultOptions$1)=>{
|
|
|
1492
1540
|
return input;
|
|
1493
1541
|
}, []);
|
|
1494
1542
|
inputRef.current = initFn();
|
|
1495
|
-
const open = (localOptions)=>_async_to_generator$
|
|
1543
|
+
const open = (localOptions)=>_async_to_generator$6(function*() {
|
|
1496
1544
|
if (!inputRef.current) {
|
|
1497
1545
|
return;
|
|
1498
1546
|
}
|
|
@@ -1905,7 +1953,7 @@ const createUpdateEffect = (hook)=>(effect, deps)=>{
|
|
|
1905
1953
|
|
|
1906
1954
|
const useUpdateEffect = createUpdateEffect(React.useEffect);
|
|
1907
1955
|
|
|
1908
|
-
function asyncGeneratorStep$
|
|
1956
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1909
1957
|
try {
|
|
1910
1958
|
var info = gen[key](arg);
|
|
1911
1959
|
var value = info.value;
|
|
@@ -1919,16 +1967,16 @@ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
1919
1967
|
Promise.resolve(value).then(_next, _throw);
|
|
1920
1968
|
}
|
|
1921
1969
|
}
|
|
1922
|
-
function _async_to_generator$
|
|
1970
|
+
function _async_to_generator$5(fn) {
|
|
1923
1971
|
return function() {
|
|
1924
1972
|
var self = this, args = arguments;
|
|
1925
1973
|
return new Promise(function(resolve, reject) {
|
|
1926
1974
|
var gen = fn.apply(self, args);
|
|
1927
1975
|
function _next(value) {
|
|
1928
|
-
asyncGeneratorStep$
|
|
1976
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
1929
1977
|
}
|
|
1930
1978
|
function _throw(err) {
|
|
1931
|
-
asyncGeneratorStep$
|
|
1979
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1932
1980
|
}
|
|
1933
1981
|
_next(undefined);
|
|
1934
1982
|
});
|
|
@@ -1961,7 +2009,7 @@ const useInfiniteScroll = (target, onLoadMore, options = defaultOptions$1)=>{
|
|
|
1961
2009
|
const di = state[3][direction];
|
|
1962
2010
|
useUpdateEffect(()=>{
|
|
1963
2011
|
const element = getTargetElement(target);
|
|
1964
|
-
const fn = ()=>_async_to_generator$
|
|
2012
|
+
const fn = ()=>_async_to_generator$5(function*() {
|
|
1965
2013
|
var _element_scrollHeight, _element_scrollWidth;
|
|
1966
2014
|
const previous = {
|
|
1967
2015
|
height: (_element_scrollHeight = element == null ? void 0 : element.scrollHeight) != null ? _element_scrollHeight : 0,
|
|
@@ -2111,7 +2159,7 @@ const useMeasure = (target, options = defaultOptions$1)=>{
|
|
|
2111
2159
|
];
|
|
2112
2160
|
};
|
|
2113
2161
|
|
|
2114
|
-
function asyncGeneratorStep$
|
|
2162
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2115
2163
|
try {
|
|
2116
2164
|
var info = gen[key](arg);
|
|
2117
2165
|
var value = info.value;
|
|
@@ -2125,16 +2173,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
2125
2173
|
Promise.resolve(value).then(_next, _throw);
|
|
2126
2174
|
}
|
|
2127
2175
|
}
|
|
2128
|
-
function _async_to_generator$
|
|
2176
|
+
function _async_to_generator$4(fn) {
|
|
2129
2177
|
return function() {
|
|
2130
2178
|
var self = this, args = arguments;
|
|
2131
2179
|
return new Promise(function(resolve, reject) {
|
|
2132
2180
|
var gen = fn.apply(self, args);
|
|
2133
2181
|
function _next(value) {
|
|
2134
|
-
asyncGeneratorStep$
|
|
2182
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
2135
2183
|
}
|
|
2136
2184
|
function _throw(err) {
|
|
2137
|
-
asyncGeneratorStep$
|
|
2185
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2138
2186
|
}
|
|
2139
2187
|
_next(undefined);
|
|
2140
2188
|
});
|
|
@@ -2168,7 +2216,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2168
2216
|
});
|
|
2169
2217
|
}).catch(noop$1);
|
|
2170
2218
|
}, []);
|
|
2171
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
2219
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$4(function*() {
|
|
2172
2220
|
if (!isSupported) {
|
|
2173
2221
|
return false;
|
|
2174
2222
|
}
|
|
@@ -3257,7 +3305,10 @@ function useSticky(targetElement, { axis = 'y', nav = 0 }, scrollElement) {
|
|
|
3257
3305
|
}, [
|
|
3258
3306
|
targetKey,
|
|
3259
3307
|
scrollKey,
|
|
3260
|
-
scrollHandler
|
|
3308
|
+
scrollHandler,
|
|
3309
|
+
targetRef,
|
|
3310
|
+
scrollRef,
|
|
3311
|
+
axisRef
|
|
3261
3312
|
]);
|
|
3262
3313
|
return [
|
|
3263
3314
|
isSticky,
|
|
@@ -3407,7 +3458,7 @@ const useToggle = (initialValue)=>{
|
|
|
3407
3458
|
|
|
3408
3459
|
const useUpdateLayoutEffect = createUpdateEffect(React.useLayoutEffect);
|
|
3409
3460
|
|
|
3410
|
-
function asyncGeneratorStep$
|
|
3461
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3411
3462
|
try {
|
|
3412
3463
|
var info = gen[key](arg);
|
|
3413
3464
|
var value = info.value;
|
|
@@ -3421,16 +3472,16 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3421
3472
|
Promise.resolve(value).then(_next, _throw);
|
|
3422
3473
|
}
|
|
3423
3474
|
}
|
|
3424
|
-
function _async_to_generator$
|
|
3475
|
+
function _async_to_generator$3(fn) {
|
|
3425
3476
|
return function() {
|
|
3426
3477
|
var self = this, args = arguments;
|
|
3427
3478
|
return new Promise(function(resolve, reject) {
|
|
3428
3479
|
var gen = fn.apply(self, args);
|
|
3429
3480
|
function _next(value) {
|
|
3430
|
-
asyncGeneratorStep$
|
|
3481
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
3431
3482
|
}
|
|
3432
3483
|
function _throw(err) {
|
|
3433
|
-
asyncGeneratorStep$
|
|
3484
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3434
3485
|
}
|
|
3435
3486
|
_next(undefined);
|
|
3436
3487
|
});
|
|
@@ -3460,7 +3511,7 @@ const useWebNotification = (requestPermissions = false)=>{
|
|
|
3460
3511
|
}, [
|
|
3461
3512
|
isSupported
|
|
3462
3513
|
]);
|
|
3463
|
-
const ensurePermissions = React.useCallback(()=>_async_to_generator$
|
|
3514
|
+
const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
|
|
3464
3515
|
if (!isSupported) return;
|
|
3465
3516
|
if (!permissionGranted.current && Notification.permission !== 'denied') {
|
|
3466
3517
|
const result = yield Notification.requestPermission();
|
|
@@ -3571,7 +3622,7 @@ const useWindowSize = ()=>{
|
|
|
3571
3622
|
};
|
|
3572
3623
|
};
|
|
3573
3624
|
|
|
3574
|
-
function asyncGeneratorStep$
|
|
3625
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3575
3626
|
try {
|
|
3576
3627
|
var info = gen[key](arg);
|
|
3577
3628
|
var value = info.value;
|
|
@@ -3585,16 +3636,16 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
3585
3636
|
Promise.resolve(value).then(_next, _throw);
|
|
3586
3637
|
}
|
|
3587
3638
|
}
|
|
3588
|
-
function _async_to_generator$
|
|
3639
|
+
function _async_to_generator$2(fn) {
|
|
3589
3640
|
return function() {
|
|
3590
3641
|
var self = this, args = arguments;
|
|
3591
3642
|
return new Promise(function(resolve, reject) {
|
|
3592
3643
|
var gen = fn.apply(self, args);
|
|
3593
3644
|
function _next(value) {
|
|
3594
|
-
asyncGeneratorStep$
|
|
3645
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
3595
3646
|
}
|
|
3596
3647
|
function _throw(err) {
|
|
3597
|
-
asyncGeneratorStep$
|
|
3648
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3598
3649
|
}
|
|
3599
3650
|
_next(undefined);
|
|
3600
3651
|
});
|
|
@@ -3602,7 +3653,7 @@ function _async_to_generator$1(fn) {
|
|
|
3602
3653
|
}
|
|
3603
3654
|
const useClipboard = ()=>{
|
|
3604
3655
|
const [text, setText] = React.useState('');
|
|
3605
|
-
const updateText = React.useCallback(()=>_async_to_generator$
|
|
3656
|
+
const updateText = React.useCallback(()=>_async_to_generator$2(function*() {
|
|
3606
3657
|
// Check if document is focused before attempting to read clipboard
|
|
3607
3658
|
if (!document.hasFocus()) {
|
|
3608
3659
|
return;
|
|
@@ -3619,7 +3670,7 @@ const useClipboard = ()=>{
|
|
|
3619
3670
|
useEventListener('cut', updateText);
|
|
3620
3671
|
// Also listen for focus events to update clipboard when window regains focus
|
|
3621
3672
|
useEventListener('focus', updateText, window);
|
|
3622
|
-
const copy = React.useCallback((txt)=>_async_to_generator$
|
|
3673
|
+
const copy = React.useCallback((txt)=>_async_to_generator$2(function*() {
|
|
3623
3674
|
setText(txt);
|
|
3624
3675
|
try {
|
|
3625
3676
|
yield window.navigator.clipboard.writeText(txt);
|
|
@@ -4147,7 +4198,7 @@ const useElementByPoint = (options)=>{
|
|
|
4147
4198
|
};
|
|
4148
4199
|
};
|
|
4149
4200
|
|
|
4150
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4201
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4151
4202
|
try {
|
|
4152
4203
|
var info = gen[key](arg);
|
|
4153
4204
|
var value = info.value;
|
|
@@ -4161,16 +4212,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
4161
4212
|
Promise.resolve(value).then(_next, _throw);
|
|
4162
4213
|
}
|
|
4163
4214
|
}
|
|
4164
|
-
function _async_to_generator(fn) {
|
|
4215
|
+
function _async_to_generator$1(fn) {
|
|
4165
4216
|
return function() {
|
|
4166
4217
|
var self = this, args = arguments;
|
|
4167
4218
|
return new Promise(function(resolve, reject) {
|
|
4168
4219
|
var gen = fn.apply(self, args);
|
|
4169
4220
|
function _next(value) {
|
|
4170
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4221
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
4171
4222
|
}
|
|
4172
4223
|
function _throw(err) {
|
|
4173
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4224
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4174
4225
|
}
|
|
4175
4226
|
_next(undefined);
|
|
4176
4227
|
});
|
|
@@ -4221,7 +4272,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4221
4272
|
options.onClose == null ? void 0 : options.onClose.call(options);
|
|
4222
4273
|
}
|
|
4223
4274
|
});
|
|
4224
|
-
const open = useEvent(()=>_async_to_generator(function*() {
|
|
4275
|
+
const open = useEvent(()=>_async_to_generator$1(function*() {
|
|
4225
4276
|
close();
|
|
4226
4277
|
setStatus('CONNECTING');
|
|
4227
4278
|
explicitlyClosed.current = false;
|
|
@@ -4260,7 +4311,7 @@ const useFetchEventSource = (url, options = {})=>{
|
|
|
4260
4311
|
}
|
|
4261
4312
|
yield fetchEventSource.fetchEventSource(url.toString(), _extends({}, finalOptions, {
|
|
4262
4313
|
onopen (response) {
|
|
4263
|
-
return _async_to_generator(function*() {
|
|
4314
|
+
return _async_to_generator$1(function*() {
|
|
4264
4315
|
if (response.ok) {
|
|
4265
4316
|
setStatus('CONNECTED');
|
|
4266
4317
|
setError(null);
|
|
@@ -4509,6 +4560,115 @@ const useSpeechRecognition = (options = {})=>{
|
|
|
4509
4560
|
};
|
|
4510
4561
|
};
|
|
4511
4562
|
|
|
4563
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4564
|
+
try {
|
|
4565
|
+
var info = gen[key](arg);
|
|
4566
|
+
var value = info.value;
|
|
4567
|
+
} catch (error) {
|
|
4568
|
+
reject(error);
|
|
4569
|
+
return;
|
|
4570
|
+
}
|
|
4571
|
+
if (info.done) {
|
|
4572
|
+
resolve(value);
|
|
4573
|
+
} else {
|
|
4574
|
+
Promise.resolve(value).then(_next, _throw);
|
|
4575
|
+
}
|
|
4576
|
+
}
|
|
4577
|
+
function _async_to_generator(fn) {
|
|
4578
|
+
return function() {
|
|
4579
|
+
var self = this, args = arguments;
|
|
4580
|
+
return new Promise(function(resolve, reject) {
|
|
4581
|
+
var gen = fn.apply(self, args);
|
|
4582
|
+
function _next(value) {
|
|
4583
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
4584
|
+
}
|
|
4585
|
+
function _throw(err) {
|
|
4586
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
4587
|
+
}
|
|
4588
|
+
_next(undefined);
|
|
4589
|
+
});
|
|
4590
|
+
};
|
|
4591
|
+
}
|
|
4592
|
+
const useWakeLock = (options = {})=>{
|
|
4593
|
+
const { onRequest, onRelease, onError } = options;
|
|
4594
|
+
const isSupported = useSupported(()=>'wakeLock' in navigator);
|
|
4595
|
+
const [isActive, setIsActive] = React.useState(false);
|
|
4596
|
+
const sentinelRef = React.useRef(null);
|
|
4597
|
+
const requestedTypeRef = React.useRef(false);
|
|
4598
|
+
const forceRequest = useEvent(()=>_async_to_generator(function*() {
|
|
4599
|
+
if (!isSupported) return;
|
|
4600
|
+
try {
|
|
4601
|
+
var _sentinelRef_current;
|
|
4602
|
+
yield (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.release();
|
|
4603
|
+
const sentinel = yield navigator.wakeLock.request('screen');
|
|
4604
|
+
sentinelRef.current = sentinel;
|
|
4605
|
+
setIsActive(true);
|
|
4606
|
+
sentinel.addEventListener('release', ()=>{
|
|
4607
|
+
var _sentinelRef_current;
|
|
4608
|
+
var _sentinelRef_current_type;
|
|
4609
|
+
requestedTypeRef.current = (_sentinelRef_current_type = (_sentinelRef_current = sentinelRef.current) == null ? void 0 : _sentinelRef_current.type) != null ? _sentinelRef_current_type : false;
|
|
4610
|
+
sentinelRef.current = null;
|
|
4611
|
+
setIsActive(false);
|
|
4612
|
+
onRelease == null ? void 0 : onRelease();
|
|
4613
|
+
}, {
|
|
4614
|
+
once: true
|
|
4615
|
+
});
|
|
4616
|
+
onRequest == null ? void 0 : onRequest();
|
|
4617
|
+
} catch (error) {
|
|
4618
|
+
onError == null ? void 0 : onError(error);
|
|
4619
|
+
}
|
|
4620
|
+
})());
|
|
4621
|
+
const request = useEvent(()=>_async_to_generator(function*() {
|
|
4622
|
+
if (!isSupported) return;
|
|
4623
|
+
if (document.visibilityState === 'visible') {
|
|
4624
|
+
yield forceRequest();
|
|
4625
|
+
} else {
|
|
4626
|
+
requestedTypeRef.current = 'screen';
|
|
4627
|
+
}
|
|
4628
|
+
})());
|
|
4629
|
+
const release = useEvent(()=>_async_to_generator(function*() {
|
|
4630
|
+
requestedTypeRef.current = false;
|
|
4631
|
+
const s = sentinelRef.current;
|
|
4632
|
+
sentinelRef.current = null;
|
|
4633
|
+
setIsActive(false);
|
|
4634
|
+
try {
|
|
4635
|
+
yield s == null ? void 0 : s.release();
|
|
4636
|
+
} catch (error) {
|
|
4637
|
+
onError == null ? void 0 : onError(error);
|
|
4638
|
+
}
|
|
4639
|
+
})());
|
|
4640
|
+
React.useEffect(()=>{
|
|
4641
|
+
const handleVisibilityChange = ()=>{
|
|
4642
|
+
if (document.visibilityState === 'visible' && requestedTypeRef.current) {
|
|
4643
|
+
requestedTypeRef.current = false;
|
|
4644
|
+
forceRequest();
|
|
4645
|
+
}
|
|
4646
|
+
};
|
|
4647
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
4648
|
+
return ()=>{
|
|
4649
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
4650
|
+
};
|
|
4651
|
+
}, [
|
|
4652
|
+
forceRequest
|
|
4653
|
+
]);
|
|
4654
|
+
React.useEffect(()=>{
|
|
4655
|
+
return ()=>{
|
|
4656
|
+
requestedTypeRef.current = false;
|
|
4657
|
+
if (sentinelRef.current) {
|
|
4658
|
+
sentinelRef.current.release();
|
|
4659
|
+
sentinelRef.current = null;
|
|
4660
|
+
}
|
|
4661
|
+
};
|
|
4662
|
+
}, []);
|
|
4663
|
+
return {
|
|
4664
|
+
isSupported,
|
|
4665
|
+
isActive,
|
|
4666
|
+
request,
|
|
4667
|
+
release,
|
|
4668
|
+
forceRequest
|
|
4669
|
+
};
|
|
4670
|
+
};
|
|
4671
|
+
|
|
4512
4672
|
exports.assignRef = assignRef;
|
|
4513
4673
|
exports.defaultOptions = defaultOptions;
|
|
4514
4674
|
exports.mergeRefs = mergeRefs;
|
|
@@ -4619,6 +4779,7 @@ exports.useUnmount = useUnmount;
|
|
|
4619
4779
|
exports.useUpdate = useUpdate;
|
|
4620
4780
|
exports.useUpdateEffect = useUpdateEffect;
|
|
4621
4781
|
exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
|
|
4782
|
+
exports.useWakeLock = useWakeLock;
|
|
4622
4783
|
exports.useWebNotification = useWebNotification;
|
|
4623
4784
|
exports.useWindowScroll = useWindowScroll;
|
|
4624
4785
|
exports.useWindowSize = useWindowSize;
|