@ox0/hooks 0.2.1 → 0.2.2
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/dist/index.js +95 -100
- package/dist/use-controllable-state.d.ts.map +1 -1
- package/dist/use-deferred-presence.d.ts.map +1 -1
- package/dist/use-long-press.d.ts.map +1 -1
- package/dist/use-previous.d.ts.map +1 -1
- package/dist/use-stored-state.d.ts +1 -1
- package/dist/use-stored-state.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__react_aria_interactions_8422cce9__ from "@react-aria/interactions";
|
|
1
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
2
|
function useBeforeUnloadWarning(enabled) {
|
|
4
|
-
|
|
5
|
-
if (!enabled || "
|
|
3
|
+
useEffect(()=>{
|
|
4
|
+
if (!enabled || "u" < typeof window) return;
|
|
6
5
|
const handle = (event)=>{
|
|
7
6
|
event.preventDefault();
|
|
8
7
|
event.returnValue = "";
|
|
@@ -16,7 +15,7 @@ function useBeforeUnloadWarning(enabled) {
|
|
|
16
15
|
const MOBILE_MAX = 767;
|
|
17
16
|
const TABLET_MAX = 1023;
|
|
18
17
|
function getBreakpoint() {
|
|
19
|
-
if ("
|
|
18
|
+
if ("u" < typeof window) return "desktop";
|
|
20
19
|
if (window.matchMedia(`(max-width: ${MOBILE_MAX}px)`).matches) return "mobile";
|
|
21
20
|
if (window.matchMedia(`(max-width: ${TABLET_MAX}px)`).matches) return "tablet";
|
|
22
21
|
return "desktop";
|
|
@@ -32,9 +31,9 @@ function toState(breakpoint) {
|
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
33
|
function useBreakpoint() {
|
|
35
|
-
const [state, setState] =
|
|
36
|
-
|
|
37
|
-
if ("
|
|
34
|
+
const [state, setState] = useState(()=>toState(getBreakpoint()));
|
|
35
|
+
useEffect(()=>{
|
|
36
|
+
if ("u" < typeof window) return;
|
|
38
37
|
const mobileQuery = window.matchMedia(`(max-width: ${MOBILE_MAX}px)`);
|
|
39
38
|
const tabletQuery = window.matchMedia(`(max-width: ${TABLET_MAX}px)`);
|
|
40
39
|
const handleChange = ()=>{
|
|
@@ -54,12 +53,12 @@ function useBreakpoint() {
|
|
|
54
53
|
return state;
|
|
55
54
|
}
|
|
56
55
|
function useContainerSize() {
|
|
57
|
-
const ref =
|
|
58
|
-
const [size, setSize] =
|
|
56
|
+
const ref = useRef(null);
|
|
57
|
+
const [size, setSize] = useState({
|
|
59
58
|
width: 0,
|
|
60
59
|
height: 0
|
|
61
60
|
});
|
|
62
|
-
|
|
61
|
+
useEffect(()=>{
|
|
63
62
|
const el = ref.current;
|
|
64
63
|
if (!el) return;
|
|
65
64
|
const observer = new ResizeObserver((entries)=>{
|
|
@@ -84,10 +83,10 @@ function useContainerSize() {
|
|
|
84
83
|
}
|
|
85
84
|
function useControllableState(options) {
|
|
86
85
|
const { defaultValue, onChange, value } = options;
|
|
87
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
86
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
88
87
|
const isControlled = void 0 !== value;
|
|
89
88
|
const currentValue = void 0 !== value ? value : uncontrolledValue;
|
|
90
|
-
|
|
89
|
+
useEffect(()=>{
|
|
91
90
|
if (!isControlled) setUncontrolledValue(defaultValue);
|
|
92
91
|
}, [
|
|
93
92
|
defaultValue,
|
|
@@ -103,12 +102,12 @@ function useControllableState(options) {
|
|
|
103
102
|
];
|
|
104
103
|
}
|
|
105
104
|
function useCopyToClipboard(resetMs = 2000) {
|
|
106
|
-
const [copied, setCopied] =
|
|
107
|
-
const timerRef =
|
|
108
|
-
|
|
105
|
+
const [copied, setCopied] = useState(false);
|
|
106
|
+
const timerRef = useRef(null);
|
|
107
|
+
useEffect(()=>()=>{
|
|
109
108
|
if (null !== timerRef.current) clearTimeout(timerRef.current);
|
|
110
109
|
}, []);
|
|
111
|
-
const copy =
|
|
110
|
+
const copy = useCallback(async (text)=>{
|
|
112
111
|
try {
|
|
113
112
|
await navigator.clipboard.writeText(text);
|
|
114
113
|
setCopied(true);
|
|
@@ -124,8 +123,8 @@ function useCopyToClipboard(resetMs = 2000) {
|
|
|
124
123
|
};
|
|
125
124
|
}
|
|
126
125
|
function useDebouncedValue(value, delay = 200) {
|
|
127
|
-
const [debouncedValue, setDebouncedValue] =
|
|
128
|
-
|
|
126
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
127
|
+
useEffect(()=>{
|
|
129
128
|
const timeoutId = window.setTimeout(()=>{
|
|
130
129
|
setDebouncedValue(value);
|
|
131
130
|
}, delay);
|
|
@@ -139,21 +138,18 @@ function useDebouncedValue(value, delay = 200) {
|
|
|
139
138
|
return debouncedValue;
|
|
140
139
|
}
|
|
141
140
|
function useDeferredPresence(isPresent, { delayMs, exitMs, minimumVisibleMs }) {
|
|
142
|
-
const [state, setState] =
|
|
141
|
+
const [state, setState] = useState({
|
|
143
142
|
phase: "hidden"
|
|
144
143
|
});
|
|
145
|
-
const timerRef =
|
|
146
|
-
|
|
144
|
+
const timerRef = useRef(void 0);
|
|
145
|
+
useEffect(()=>{
|
|
147
146
|
clearTimeout(timerRef.current);
|
|
148
147
|
if (isPresent) {
|
|
149
148
|
if ("visible" === state.phase) return;
|
|
150
|
-
if ("exiting" === state.phase) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
149
|
+
if ("exiting" === state.phase) return void setState({
|
|
150
|
+
phase: "visible",
|
|
151
|
+
shownAt: state.shownAt
|
|
152
|
+
});
|
|
157
153
|
timerRef.current = window.setTimeout(()=>{
|
|
158
154
|
setState({
|
|
159
155
|
phase: "visible",
|
|
@@ -183,14 +179,14 @@ function useDeferredPresence(isPresent, { delayMs, exitMs, minimumVisibleMs }) {
|
|
|
183
179
|
return state.phase;
|
|
184
180
|
}
|
|
185
181
|
function useDisclosure(initialOpen = false) {
|
|
186
|
-
const [isOpen, setIsOpen] =
|
|
187
|
-
const onClose =
|
|
182
|
+
const [isOpen, setIsOpen] = useState(initialOpen);
|
|
183
|
+
const onClose = useCallback(()=>{
|
|
188
184
|
setIsOpen(false);
|
|
189
185
|
}, []);
|
|
190
|
-
const onOpen =
|
|
186
|
+
const onOpen = useCallback(()=>{
|
|
191
187
|
setIsOpen(true);
|
|
192
188
|
}, []);
|
|
193
|
-
const onToggle =
|
|
189
|
+
const onToggle = useCallback(()=>{
|
|
194
190
|
setIsOpen((value)=>!value);
|
|
195
191
|
}, []);
|
|
196
192
|
return {
|
|
@@ -201,13 +197,13 @@ function useDisclosure(initialOpen = false) {
|
|
|
201
197
|
};
|
|
202
198
|
}
|
|
203
199
|
function useEventListener(type, listener, target) {
|
|
204
|
-
const listenerRef =
|
|
205
|
-
|
|
200
|
+
const listenerRef = useRef(listener);
|
|
201
|
+
useEffect(()=>{
|
|
206
202
|
listenerRef.current = listener;
|
|
207
203
|
}, [
|
|
208
204
|
listener
|
|
209
205
|
]);
|
|
210
|
-
|
|
206
|
+
useEffect(()=>{
|
|
211
207
|
const el = void 0 === target ? window : target && "current" in target ? target.current : target;
|
|
212
208
|
if (!el) return;
|
|
213
209
|
const handler = (e)=>listenerRef.current(e);
|
|
@@ -219,9 +215,9 @@ function useEventListener(type, listener, target) {
|
|
|
219
215
|
]);
|
|
220
216
|
}
|
|
221
217
|
function useHover() {
|
|
222
|
-
const ref =
|
|
223
|
-
const [hovered, setHovered] =
|
|
224
|
-
|
|
218
|
+
const ref = useRef(null);
|
|
219
|
+
const [hovered, setHovered] = useState(false);
|
|
220
|
+
useEffect(()=>{
|
|
225
221
|
const el = ref.current;
|
|
226
222
|
if (!el) return;
|
|
227
223
|
const enter = ()=>setHovered(true);
|
|
@@ -239,13 +235,13 @@ function useHover() {
|
|
|
239
235
|
];
|
|
240
236
|
}
|
|
241
237
|
function useInterval(callback, delay) {
|
|
242
|
-
const callbackRef =
|
|
243
|
-
|
|
238
|
+
const callbackRef = useRef(callback);
|
|
239
|
+
useEffect(()=>{
|
|
244
240
|
callbackRef.current = callback;
|
|
245
241
|
}, [
|
|
246
242
|
callback
|
|
247
243
|
]);
|
|
248
|
-
|
|
244
|
+
useEffect(()=>{
|
|
249
245
|
if (null === delay) return;
|
|
250
246
|
const id = window.setInterval(()=>callbackRef.current(), delay);
|
|
251
247
|
return ()=>window.clearInterval(id);
|
|
@@ -254,13 +250,13 @@ function useInterval(callback, delay) {
|
|
|
254
250
|
]);
|
|
255
251
|
}
|
|
256
252
|
function useKeyDown(key, callback, { ctrl = false, meta = false, shift = false, alt = false, enabled = true } = {}) {
|
|
257
|
-
const callbackRef =
|
|
258
|
-
|
|
253
|
+
const callbackRef = useRef(callback);
|
|
254
|
+
useEffect(()=>{
|
|
259
255
|
callbackRef.current = callback;
|
|
260
256
|
}, [
|
|
261
257
|
callback
|
|
262
258
|
]);
|
|
263
|
-
|
|
259
|
+
useEffect(()=>{
|
|
264
260
|
if (!enabled) return;
|
|
265
261
|
const handler = (e)=>{
|
|
266
262
|
if (e.key !== key) return;
|
|
@@ -302,7 +298,7 @@ function tabNotify(key, value) {
|
|
|
302
298
|
const crossTabSubscribers = new Map();
|
|
303
299
|
let broadcastChannel = null;
|
|
304
300
|
function getChannel() {
|
|
305
|
-
if ("
|
|
301
|
+
if ("u" < typeof window || "u" < typeof BroadcastChannel) return null;
|
|
306
302
|
if (!broadcastChannel) {
|
|
307
303
|
broadcastChannel = new BroadcastChannel("ox0:storage");
|
|
308
304
|
broadcastChannel.addEventListener("message", (e)=>{
|
|
@@ -326,7 +322,7 @@ function crossTabSubscribe(key, fn) {
|
|
|
326
322
|
};
|
|
327
323
|
}
|
|
328
324
|
function getTabId() {
|
|
329
|
-
if ("
|
|
325
|
+
if ("u" < typeof sessionStorage) return instanceId;
|
|
330
326
|
const existing = sessionStorage.getItem("ox0:tab-id");
|
|
331
327
|
if (existing) return existing;
|
|
332
328
|
const next = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
@@ -334,7 +330,7 @@ function getTabId() {
|
|
|
334
330
|
return next;
|
|
335
331
|
}
|
|
336
332
|
function getStorage(kind) {
|
|
337
|
-
if ("
|
|
333
|
+
if ("u" < typeof window) return null;
|
|
338
334
|
return "persistent" === kind ? window.localStorage : window.sessionStorage;
|
|
339
335
|
}
|
|
340
336
|
function makeStorageKey(key, kind, shared, scope) {
|
|
@@ -354,7 +350,7 @@ function readSafe(raw, parser, defaultValue, version, migrate) {
|
|
|
354
350
|
migrated: false
|
|
355
351
|
};
|
|
356
352
|
if (parsed.v !== version) return migrate ? {
|
|
357
|
-
value: migrate(parsed.value, parsed.v),
|
|
353
|
+
value: parser.parse(migrate(parsed.value, parsed.v)),
|
|
358
354
|
migrated: true
|
|
359
355
|
} : {
|
|
360
356
|
value: defaultValue,
|
|
@@ -382,49 +378,49 @@ function writeStorage(storage, key, value, version) {
|
|
|
382
378
|
} catch {}
|
|
383
379
|
return raw;
|
|
384
380
|
}
|
|
385
|
-
const StorageScopeContext =
|
|
381
|
+
const StorageScopeContext = createContext(void 0);
|
|
386
382
|
function StorageProvider({ scope, children }) {
|
|
387
|
-
return
|
|
383
|
+
return createElement(StorageScopeContext.Provider, {
|
|
388
384
|
value: scope
|
|
389
385
|
}, children);
|
|
390
386
|
}
|
|
391
387
|
function useStorageScope() {
|
|
392
|
-
const scope =
|
|
388
|
+
const scope = useContext(StorageScopeContext);
|
|
393
389
|
if (void 0 === scope) throw new Error("useStoredState: no StorageProvider found. Wrap your app with <StorageProvider scope={userId ?? null}>.");
|
|
394
390
|
return scope;
|
|
395
391
|
}
|
|
396
392
|
function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate }, shared) {
|
|
397
393
|
const scope = useStorageScope();
|
|
398
394
|
const storage = getStorage(kind);
|
|
399
|
-
const storageKey =
|
|
395
|
+
const storageKey = useMemo(()=>makeStorageKey(key, kind, shared, scope), [
|
|
400
396
|
key,
|
|
401
397
|
kind,
|
|
402
398
|
shared,
|
|
403
399
|
scope
|
|
404
400
|
]);
|
|
405
|
-
const parserRef =
|
|
406
|
-
const defaultValueRef =
|
|
407
|
-
const versionRef =
|
|
408
|
-
const migrateRef =
|
|
409
|
-
|
|
401
|
+
const parserRef = useRef(parser);
|
|
402
|
+
const defaultValueRef = useRef(defaultValue);
|
|
403
|
+
const versionRef = useRef(version);
|
|
404
|
+
const migrateRef = useRef(migrate);
|
|
405
|
+
useEffect(()=>{
|
|
410
406
|
parserRef.current = parser;
|
|
411
407
|
defaultValueRef.current = defaultValue;
|
|
412
408
|
versionRef.current = version;
|
|
413
409
|
migrateRef.current = migrate;
|
|
414
410
|
});
|
|
415
|
-
const [value, setValueState] =
|
|
411
|
+
const [value, setValueState] = useState(()=>{
|
|
416
412
|
const raw = storage?.getItem(storageKey) ?? null;
|
|
417
413
|
const result = readSafe(raw, parser, defaultValue, version, migrate);
|
|
418
414
|
if (result.migrated) writeStorage(storage, storageKey, result.value, version);
|
|
419
415
|
return result.value;
|
|
420
416
|
});
|
|
421
|
-
const valueRef =
|
|
422
|
-
|
|
417
|
+
const valueRef = useRef(value);
|
|
418
|
+
useEffect(()=>{
|
|
423
419
|
valueRef.current = value;
|
|
424
420
|
}, [
|
|
425
421
|
value
|
|
426
422
|
]);
|
|
427
|
-
|
|
423
|
+
useEffect(()=>{
|
|
428
424
|
const raw = storage?.getItem(storageKey) ?? null;
|
|
429
425
|
const result = readSafe(raw, parserRef.current, defaultValueRef.current, versionRef.current, migrateRef.current);
|
|
430
426
|
setValueState((prev)=>Object.is(prev, result.value) ? prev : result.value);
|
|
@@ -433,12 +429,12 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
|
|
|
433
429
|
storage,
|
|
434
430
|
storageKey
|
|
435
431
|
]);
|
|
436
|
-
|
|
432
|
+
useEffect(()=>tabSubscribe(storageKey, (next)=>{
|
|
437
433
|
setValueState((prev)=>Object.is(prev, next) ? prev : next);
|
|
438
434
|
}), [
|
|
439
435
|
storageKey
|
|
440
436
|
]);
|
|
441
|
-
|
|
437
|
+
useEffect(()=>{
|
|
442
438
|
if (!shared) return;
|
|
443
439
|
return crossTabSubscribe(storageKey, (msg)=>{
|
|
444
440
|
if (msg.storage !== kind || msg.sourceId === instanceId) return;
|
|
@@ -453,8 +449,8 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
|
|
|
453
449
|
storage,
|
|
454
450
|
storageKey
|
|
455
451
|
]);
|
|
456
|
-
|
|
457
|
-
if (!shared || "persistent" !== kind || "
|
|
452
|
+
useEffect(()=>{
|
|
453
|
+
if (!shared || "persistent" !== kind || "u" < typeof window) return;
|
|
458
454
|
const handler = (event)=>{
|
|
459
455
|
if (event.key !== storageKey) return;
|
|
460
456
|
const result = readSafe(event.newValue, parserRef.current, defaultValueRef.current, versionRef.current, migrateRef.current);
|
|
@@ -470,7 +466,7 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
|
|
|
470
466
|
storage,
|
|
471
467
|
storageKey
|
|
472
468
|
]);
|
|
473
|
-
const setValue =
|
|
469
|
+
const setValue = useCallback((next)=>{
|
|
474
470
|
const resolved = "function" == typeof next ? next(valueRef.current) : next;
|
|
475
471
|
if (Object.is(valueRef.current, resolved)) return;
|
|
476
472
|
valueRef.current = resolved;
|
|
@@ -507,10 +503,10 @@ function useSessionSharedState(key, parser, options) {
|
|
|
507
503
|
return useStoredState("session", key, parser, options, true);
|
|
508
504
|
}
|
|
509
505
|
function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, onLongPress }) {
|
|
510
|
-
const timerRef =
|
|
511
|
-
const pointerIdRef =
|
|
512
|
-
const startRef =
|
|
513
|
-
const triggeredRef =
|
|
506
|
+
const timerRef = useRef(null);
|
|
507
|
+
const pointerIdRef = useRef(null);
|
|
508
|
+
const startRef = useRef(null);
|
|
509
|
+
const triggeredRef = useRef(false);
|
|
514
510
|
const clearTimer = ()=>{
|
|
515
511
|
if (null == timerRef.current) return;
|
|
516
512
|
window.clearTimeout(timerRef.current);
|
|
@@ -521,7 +517,7 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
|
|
|
521
517
|
pointerIdRef.current = null;
|
|
522
518
|
startRef.current = null;
|
|
523
519
|
};
|
|
524
|
-
|
|
520
|
+
useEffect(()=>{
|
|
525
521
|
if (disabled) {
|
|
526
522
|
triggeredRef.current = false;
|
|
527
523
|
reset();
|
|
@@ -529,7 +525,7 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
|
|
|
529
525
|
}, [
|
|
530
526
|
disabled
|
|
531
527
|
]);
|
|
532
|
-
|
|
528
|
+
useEffect(()=>()=>clearTimer(), []);
|
|
533
529
|
return {
|
|
534
530
|
onPointerDown (event) {
|
|
535
531
|
if (disabled || 0 !== event.button) return;
|
|
@@ -571,10 +567,10 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
|
|
|
571
567
|
};
|
|
572
568
|
}
|
|
573
569
|
function useMediaQuery(query) {
|
|
574
|
-
const getMatches = ()=>"
|
|
575
|
-
const [matches, setMatches] =
|
|
576
|
-
|
|
577
|
-
if ("
|
|
570
|
+
const getMatches = ()=>"u" > typeof window && window.matchMedia(query).matches;
|
|
571
|
+
const [matches, setMatches] = useState(getMatches);
|
|
572
|
+
useEffect(()=>{
|
|
573
|
+
if ("u" < typeof window) return;
|
|
578
574
|
const mediaQuery = window.matchMedia(query);
|
|
579
575
|
const update = ()=>{
|
|
580
576
|
setMatches(mediaQuery.matches);
|
|
@@ -590,9 +586,9 @@ function useMediaQuery(query) {
|
|
|
590
586
|
return matches;
|
|
591
587
|
}
|
|
592
588
|
function useNavigatorOnline() {
|
|
593
|
-
const [isOnline, setIsOnline] =
|
|
594
|
-
|
|
595
|
-
if ("
|
|
589
|
+
const [isOnline, setIsOnline] = useState(()=>"u" < typeof navigator ? true : navigator.onLine);
|
|
590
|
+
useEffect(()=>{
|
|
591
|
+
if ("u" < typeof window) return;
|
|
596
592
|
const sync = ()=>setIsOnline(navigator.onLine);
|
|
597
593
|
window.addEventListener("online", sync);
|
|
598
594
|
window.addEventListener("offline", sync);
|
|
@@ -604,8 +600,8 @@ function useNavigatorOnline() {
|
|
|
604
600
|
return isOnline;
|
|
605
601
|
}
|
|
606
602
|
function useNow({ update = 1000 } = {}) {
|
|
607
|
-
const [now, setNow] =
|
|
608
|
-
|
|
603
|
+
const [now, setNow] = useState(()=>Date.now());
|
|
604
|
+
useEffect(()=>{
|
|
609
605
|
if (false === update) return;
|
|
610
606
|
const id = window.setInterval(()=>setNow(Date.now()), update);
|
|
611
607
|
return ()=>window.clearInterval(id);
|
|
@@ -615,7 +611,7 @@ function useNow({ update = 1000 } = {}) {
|
|
|
615
611
|
return now;
|
|
616
612
|
}
|
|
617
613
|
function detectOS() {
|
|
618
|
-
if ("
|
|
614
|
+
if ("u" < typeof navigator) return "windows";
|
|
619
615
|
const ua = navigator.userAgent.toLowerCase();
|
|
620
616
|
const platform = (navigator.platform ?? "").toLowerCase();
|
|
621
617
|
const combined = `${ua} ${platform}`;
|
|
@@ -626,7 +622,7 @@ function detectOS() {
|
|
|
626
622
|
return "windows";
|
|
627
623
|
}
|
|
628
624
|
function useOS(override) {
|
|
629
|
-
return
|
|
625
|
+
return useMemo(()=>override ?? detectOS(), [
|
|
630
626
|
override
|
|
631
627
|
]);
|
|
632
628
|
}
|
|
@@ -637,8 +633,8 @@ function usePrefersReducedMotion() {
|
|
|
637
633
|
return useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
638
634
|
}
|
|
639
635
|
function usePrevious(value) {
|
|
640
|
-
const ref =
|
|
641
|
-
|
|
636
|
+
const ref = useRef(void 0);
|
|
637
|
+
useEffect(()=>{
|
|
642
638
|
ref.current = value;
|
|
643
639
|
}, [
|
|
644
640
|
value
|
|
@@ -646,13 +642,13 @@ function usePrevious(value) {
|
|
|
646
642
|
return ref.current;
|
|
647
643
|
}
|
|
648
644
|
function useTimeout(callback, delay) {
|
|
649
|
-
const callbackRef =
|
|
650
|
-
|
|
645
|
+
const callbackRef = useRef(callback);
|
|
646
|
+
useEffect(()=>{
|
|
651
647
|
callbackRef.current = callback;
|
|
652
648
|
}, [
|
|
653
649
|
callback
|
|
654
650
|
]);
|
|
655
|
-
|
|
651
|
+
useEffect(()=>{
|
|
656
652
|
if (null === delay) return;
|
|
657
653
|
const id = window.setTimeout(()=>callbackRef.current(), delay);
|
|
658
654
|
return ()=>window.clearTimeout(id);
|
|
@@ -662,7 +658,7 @@ function useTimeout(callback, delay) {
|
|
|
662
658
|
}
|
|
663
659
|
const KEYBOARD_OPEN_DELTA = 150;
|
|
664
660
|
function getViewportState() {
|
|
665
|
-
if ("
|
|
661
|
+
if ("u" < typeof window) return {
|
|
666
662
|
visualViewportHeight: 0,
|
|
667
663
|
keyboardOpen: false
|
|
668
664
|
};
|
|
@@ -674,9 +670,9 @@ function getViewportState() {
|
|
|
674
670
|
};
|
|
675
671
|
}
|
|
676
672
|
function useViewport() {
|
|
677
|
-
const [state, setState] =
|
|
678
|
-
|
|
679
|
-
if ("
|
|
673
|
+
const [state, setState] = useState(()=>getViewportState());
|
|
674
|
+
useEffect(()=>{
|
|
675
|
+
if ("u" < typeof window) return;
|
|
680
676
|
const target = window.visualViewport ?? window;
|
|
681
677
|
const handleChange = ()=>{
|
|
682
678
|
setState((prev)=>{
|
|
@@ -695,7 +691,7 @@ function useViewport() {
|
|
|
695
691
|
return state;
|
|
696
692
|
}
|
|
697
693
|
function getWindowSize() {
|
|
698
|
-
if ("
|
|
694
|
+
if ("u" < typeof window) return {
|
|
699
695
|
width: 0,
|
|
700
696
|
height: 0
|
|
701
697
|
};
|
|
@@ -705,9 +701,9 @@ function getWindowSize() {
|
|
|
705
701
|
};
|
|
706
702
|
}
|
|
707
703
|
function useWindowSize() {
|
|
708
|
-
const [size, setSize] =
|
|
709
|
-
|
|
710
|
-
if ("
|
|
704
|
+
const [size, setSize] = useState(getWindowSize);
|
|
705
|
+
useEffect(()=>{
|
|
706
|
+
if ("u" < typeof window) return;
|
|
711
707
|
const handleResize = ()=>{
|
|
712
708
|
setSize((prev)=>{
|
|
713
709
|
const next = getWindowSize();
|
|
@@ -720,6 +716,5 @@ function useWindowSize() {
|
|
|
720
716
|
}, []);
|
|
721
717
|
return size;
|
|
722
718
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
export { StorageProvider, useBeforeUnloadWarning, useBreakpoint, useContainerSize, useControllableState, useCopyToClipboard, useDebouncedValue, useDeferredPresence, useDisclosure, useEventListener, useHover, useInterval, useKeyDown, useLongPress, useMediaQuery, useNavigatorOnline, useNow, useOS, usePersistentSharedState, usePersistentState, usePointerCoarse, usePrefersReducedMotion, usePrevious, useSessionSharedState, useSessionState, useTimeout, useViewport, useWindowSize, __webpack_exports__isFocusVisible as isFocusVisible, __webpack_exports__usePress as usePress };
|
|
719
|
+
export { isFocusVisible, usePress } from "@react-aria/interactions";
|
|
720
|
+
export { StorageProvider, useBeforeUnloadWarning, useBreakpoint, useContainerSize, useControllableState, useCopyToClipboard, useDebouncedValue, useDeferredPresence, useDisclosure, useEventListener, useHover, useInterval, useKeyDown, useLongPress, useMediaQuery, useNavigatorOnline, useNow, useOS, usePersistentSharedState, usePersistentState, usePointerCoarse, usePrefersReducedMotion, usePrevious, useSessionSharedState, useSessionState, useTimeout, useViewport, useWindowSize };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-controllable-state.d.ts","sourceRoot":"","sources":["../src/use-controllable-state.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B,CAAC,MAAM;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EACzC,OAAO,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAC3C,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"use-controllable-state.d.ts","sourceRoot":"","sources":["../src/use-controllable-state.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B,CAAC,MAAM;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EACzC,OAAO,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAC3C,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC,CAqBvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deferred-presence.d.ts","sourceRoot":"","sources":["../src/use-deferred-presence.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAIpE,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,OAAO,EAClB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,uBAAuB,GAC7D,qBAAqB,
|
|
1
|
+
{"version":3,"file":"use-deferred-presence.d.ts","sourceRoot":"","sources":["../src/use-deferred-presence.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAIpE,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,OAAO,EAClB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,uBAAuB,GAC7D,qBAAqB,CA+BvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-long-press.d.ts","sourceRoot":"","sources":["../src/use-long-press.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,eAAe,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAa,EACb,eAAmB,EACnB,QAAgB,EAChB,WAAW,GACZ,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"use-long-press.d.ts","sourceRoot":"","sources":["../src/use-long-press.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,eAAe,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAa,EACb,eAAmB,EACnB,QAAgB,EAChB,WAAW,GACZ,EAAE,mBAAmB;IA8BlB,aAAa,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAcnD,aAAa,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAMnD,WAAW,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAIjD,eAAe,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAIrD,cAAc,QAAQ,eAAe,CAAC,WAAW,CAAC;EAQrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-previous.d.ts","sourceRoot":"","sources":["../src/use-previous.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"use-previous.d.ts","sourceRoot":"","sources":["../src/use-previous.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAOtD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
/** Anything with a `.parse` method — Zod schemas
|
|
2
|
+
/** Anything with a `.parse` method that throws on invalid input — `@ox0/schema` and Zod schemas fit. */
|
|
3
3
|
export type Parser<T> = {
|
|
4
4
|
parse: (value: unknown) => T;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-stored-state.d.ts","sourceRoot":"","sources":["../src/use-stored-state.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,
|
|
1
|
+
{"version":3,"file":"use-stored-state.d.ts","sourceRoot":"","sources":["../src/use-stored-state.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,wGAAwG;AACxG,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAA;CAAE,CAAA;AAExD,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IAClC,YAAY,EAAE,CAAC,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC,CAAA;CACrD,CAAA;AA2HD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,QAAQ,EAAE,SAAS,CAAA;CACpB,sGAEA;AAuID,iCAAiC;AACjC,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,uCAzHO,IAAI,EA4H1C;AAED,wCAAwC;AACxC,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,uCAlIO,IAAI,EAqI1C;AAED,mCAAmC;AACnC,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,uCAxI1D,IAAI,EA0I1C;AAED,yCAAyC;AACzC,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,uCAhJO,IAAI,EAmJ1C"}
|