@dxos/react-hooks 0.8.4-staging.ac66bdf99f → 0.9.1-main.c7dcc2e112
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +76 -43
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +76 -43
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useAsyncEffect.d.ts.map +1 -1
- package/dist/types/src/useAsyncState.d.ts.map +1 -1
- package/dist/types/src/useAtomState.d.ts +12 -0
- package/dist/types/src/useAtomState.d.ts.map +1 -0
- package/dist/types/src/useControlledState.d.ts.map +1 -1
- package/dist/types/src/useDebugDeps.d.ts.map +1 -1
- package/dist/types/src/useDefaultValue.d.ts.map +1 -1
- package/dist/types/src/useDefaults.d.ts.map +1 -1
- package/dist/types/src/useDynamicRef.d.ts.map +1 -1
- package/dist/types/src/useForwardedRef.d.ts.map +1 -1
- package/dist/types/src/useId.d.ts.map +1 -1
- package/dist/types/src/useIsFocused.d.ts.map +1 -1
- package/dist/types/src/useMediaQuery.d.ts.map +1 -1
- package/dist/types/src/useMulticastObservable.d.ts.map +1 -1
- package/dist/types/src/useTimeout.d.ts.map +1 -1
- package/dist/types/src/useTransitions.d.ts.map +1 -1
- package/dist/types/src/useViewportResize.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/src/index.ts +1 -0
- package/src/useAtomState.ts +23 -0
- package/src/useForwardedRef.ts +3 -1
- package/src/useViewportResize.ts +34 -9
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -21,10 +21,28 @@ var useAsyncEffect = (cb, deps) => {
|
|
|
21
21
|
}, deps ?? []);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
// src/useAtomState.ts
|
|
25
|
+
import { Atom, useAtomSet, useAtomValue } from "@effect-atom/atom-react";
|
|
26
|
+
import { useMemo, useState } from "react";
|
|
27
|
+
var useAtomState = (initialValue) => {
|
|
28
|
+
const [atom] = useState(() => Atom.make(initialValue));
|
|
29
|
+
const value = useAtomValue(atom);
|
|
30
|
+
const set = useAtomSet(atom);
|
|
31
|
+
return useMemo(() => ({
|
|
32
|
+
atom,
|
|
33
|
+
value,
|
|
34
|
+
set
|
|
35
|
+
}), [
|
|
36
|
+
atom,
|
|
37
|
+
value,
|
|
38
|
+
set
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
|
|
24
42
|
// src/useAsyncState.ts
|
|
25
|
-
import { useEffect as useEffect2, useState } from "react";
|
|
43
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
26
44
|
var useAsyncState = (cb, deps = []) => {
|
|
27
|
-
const [value, setValue] =
|
|
45
|
+
const [value, setValue] = useState2();
|
|
28
46
|
useEffect2(() => {
|
|
29
47
|
let disposed = false;
|
|
30
48
|
const t = setTimeout(async () => {
|
|
@@ -45,12 +63,12 @@ var useAsyncState = (cb, deps = []) => {
|
|
|
45
63
|
};
|
|
46
64
|
|
|
47
65
|
// src/useControlledState.ts
|
|
48
|
-
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as
|
|
66
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
|
|
49
67
|
|
|
50
68
|
// src/useDynamicRef.ts
|
|
51
|
-
import { useCallback, useEffect as useEffect3, useRef, useState as
|
|
69
|
+
import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
52
70
|
var useStateWithRef = (valueProp) => {
|
|
53
|
-
const [value, setValue] =
|
|
71
|
+
const [value, setValue] = useState3(valueProp);
|
|
54
72
|
const valueRef = useRef(valueProp);
|
|
55
73
|
const setter = useCallback((value2) => {
|
|
56
74
|
if (typeof value2 === "function") {
|
|
@@ -81,7 +99,7 @@ var useDynamicRef = (value) => {
|
|
|
81
99
|
|
|
82
100
|
// src/useControlledState.ts
|
|
83
101
|
var useControlledState = (valueProp, onChange) => {
|
|
84
|
-
const [value, setControlledValue] =
|
|
102
|
+
const [value, setControlledValue] = useState4(valueProp);
|
|
85
103
|
useEffect4(() => {
|
|
86
104
|
setControlledValue(valueProp);
|
|
87
105
|
}, [
|
|
@@ -109,7 +127,6 @@ function isFunction(value) {
|
|
|
109
127
|
// src/useDebugDeps.ts
|
|
110
128
|
import { useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
111
129
|
import { log } from "@dxos/log";
|
|
112
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-primitives/react-hooks/src/useDebugDeps.ts";
|
|
113
130
|
var useDebugDeps = (deps = [], label = "useDebugDeps", active = true) => {
|
|
114
131
|
const lastDeps = useRef3([]);
|
|
115
132
|
useEffect5(() => {
|
|
@@ -126,12 +143,7 @@ var useDebugDeps = (deps = [], label = "useDebugDeps", active = true) => {
|
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
if (Object.keys(diff).length > 0) {
|
|
129
|
-
log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff
|
|
130
|
-
F: __dxlog_file,
|
|
131
|
-
L: 30,
|
|
132
|
-
S: void 0,
|
|
133
|
-
C: (f, a) => f(...a)
|
|
134
|
-
});
|
|
146
|
+
log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff);
|
|
135
147
|
}
|
|
136
148
|
lastDeps.current = deps;
|
|
137
149
|
}, [
|
|
@@ -141,10 +153,10 @@ var useDebugDeps = (deps = [], label = "useDebugDeps", active = true) => {
|
|
|
141
153
|
};
|
|
142
154
|
|
|
143
155
|
// src/useDefaultValue.ts
|
|
144
|
-
import { useEffect as useEffect6, useMemo, useState as
|
|
156
|
+
import { useEffect as useEffect6, useMemo as useMemo2, useState as useState5 } from "react";
|
|
145
157
|
var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
146
|
-
const stableDefaultValue =
|
|
147
|
-
const [value, setValue] =
|
|
158
|
+
const stableDefaultValue = useMemo2(getDefaultValue, []);
|
|
159
|
+
const [value, setValue] = useState5(reactiveValue ?? stableDefaultValue);
|
|
148
160
|
useEffect6(() => {
|
|
149
161
|
setValue(reactiveValue ?? stableDefaultValue);
|
|
150
162
|
}, [
|
|
@@ -156,18 +168,18 @@ var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
|
156
168
|
|
|
157
169
|
// src/useDefaults.ts
|
|
158
170
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
159
|
-
import { useMemo as
|
|
171
|
+
import { useMemo as useMemo3 } from "react";
|
|
160
172
|
var useDefaults = (value, defaults) => {
|
|
161
|
-
return
|
|
173
|
+
return useMemo3(() => defaultsDeep({}, defaults, value), [
|
|
162
174
|
value,
|
|
163
175
|
defaults
|
|
164
176
|
]);
|
|
165
177
|
};
|
|
166
178
|
|
|
167
179
|
// src/useFileDownload.ts
|
|
168
|
-
import { useMemo as
|
|
180
|
+
import { useMemo as useMemo4 } from "react";
|
|
169
181
|
var useFileDownload = () => {
|
|
170
|
-
return
|
|
182
|
+
return useMemo4(() => (data, filename) => {
|
|
171
183
|
const url = typeof data === "string" ? data : URL.createObjectURL(data);
|
|
172
184
|
const element = document.createElement("a");
|
|
173
185
|
element.setAttribute("href", url);
|
|
@@ -178,7 +190,7 @@ var useFileDownload = () => {
|
|
|
178
190
|
};
|
|
179
191
|
|
|
180
192
|
// src/useForwardedRef.ts
|
|
181
|
-
import { useEffect as useEffect7, useMemo as
|
|
193
|
+
import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4 } from "react";
|
|
182
194
|
var useForwardedRef = (forwardedRef) => {
|
|
183
195
|
const localRef = useRef4(null);
|
|
184
196
|
useEffect7(() => {
|
|
@@ -203,33 +215,35 @@ var mergeRefs = (refs) => {
|
|
|
203
215
|
cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
|
|
204
216
|
}
|
|
205
217
|
return () => {
|
|
206
|
-
for (const cleanup of cleanups)
|
|
218
|
+
for (const cleanup of cleanups) {
|
|
219
|
+
cleanup();
|
|
220
|
+
}
|
|
207
221
|
};
|
|
208
222
|
};
|
|
209
223
|
};
|
|
210
224
|
var useMergeRefs = (refs) => {
|
|
211
|
-
return
|
|
225
|
+
return useMemo5(() => mergeRefs(refs), [
|
|
212
226
|
...refs
|
|
213
227
|
]);
|
|
214
228
|
};
|
|
215
229
|
|
|
216
230
|
// src/useId.ts
|
|
217
231
|
import alea from "alea";
|
|
218
|
-
import { useMemo as
|
|
232
|
+
import { useMemo as useMemo6 } from "react";
|
|
219
233
|
var Alea = alea;
|
|
220
234
|
var prng = new Alea("@dxos/react-hooks");
|
|
221
235
|
var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
|
|
222
236
|
var useId = (namespace, propsId, opts) => {
|
|
223
|
-
return
|
|
237
|
+
return useMemo6(() => makeId(namespace, propsId, opts), [
|
|
224
238
|
propsId
|
|
225
239
|
]);
|
|
226
240
|
};
|
|
227
241
|
var makeId = (namespace, propsId, opts) => propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;
|
|
228
242
|
|
|
229
243
|
// src/useIsFocused.ts
|
|
230
|
-
import { useEffect as useEffect8, useRef as useRef5, useState as
|
|
244
|
+
import { useEffect as useEffect8, useRef as useRef5, useState as useState6 } from "react";
|
|
231
245
|
var useIsFocused = (inputRef) => {
|
|
232
|
-
const [isFocused, setIsFocused] =
|
|
246
|
+
const [isFocused, setIsFocused] = useState6(void 0);
|
|
233
247
|
const isFocusedRef = useRef5(isFocused);
|
|
234
248
|
isFocusedRef.current = isFocused;
|
|
235
249
|
useEffect8(() => {
|
|
@@ -256,7 +270,7 @@ var useIsFocused = (inputRef) => {
|
|
|
256
270
|
};
|
|
257
271
|
|
|
258
272
|
// src/useMediaQuery.ts
|
|
259
|
-
import { useEffect as useEffect9, useState as
|
|
273
|
+
import { useEffect as useEffect9, useState as useState7 } from "react";
|
|
260
274
|
var breakpointMediaQueries = {
|
|
261
275
|
sm: "(min-width: 640px)",
|
|
262
276
|
md: "(min-width: 768px)",
|
|
@@ -273,7 +287,7 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
273
287
|
fallback
|
|
274
288
|
];
|
|
275
289
|
fallbackValues = fallbackValues.filter((v) => v != null);
|
|
276
|
-
const [value, setValue] =
|
|
290
|
+
const [value, setValue] = useState7(() => {
|
|
277
291
|
return queries.map((query2, index) => ({
|
|
278
292
|
media: query2,
|
|
279
293
|
matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query2).matches
|
|
@@ -321,9 +335,9 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
321
335
|
};
|
|
322
336
|
|
|
323
337
|
// src/useMulticastObservable.ts
|
|
324
|
-
import { useMemo as
|
|
338
|
+
import { useMemo as useMemo7, useSyncExternalStore } from "react";
|
|
325
339
|
var useMulticastObservable = (observable) => {
|
|
326
|
-
const subscribeFn =
|
|
340
|
+
const subscribeFn = useMemo7(() => (listener) => {
|
|
327
341
|
const subscription = observable.subscribe(listener);
|
|
328
342
|
return () => subscription.unsubscribe();
|
|
329
343
|
}, [
|
|
@@ -333,9 +347,9 @@ var useMulticastObservable = (observable) => {
|
|
|
333
347
|
};
|
|
334
348
|
|
|
335
349
|
// src/useRefCallback.ts
|
|
336
|
-
import { useState as
|
|
350
|
+
import { useState as useState8 } from "react";
|
|
337
351
|
var useRefCallback = () => {
|
|
338
|
-
const [value, setValue] =
|
|
352
|
+
const [value, setValue] = useState8(null);
|
|
339
353
|
return {
|
|
340
354
|
refCallback: (value2) => setValue(value2),
|
|
341
355
|
value
|
|
@@ -343,15 +357,29 @@ var useRefCallback = () => {
|
|
|
343
357
|
};
|
|
344
358
|
|
|
345
359
|
// src/useViewportResize.ts
|
|
346
|
-
import { useLayoutEffect, useMemo as
|
|
360
|
+
import { useLayoutEffect, useMemo as useMemo8 } from "react";
|
|
347
361
|
var useViewportResize = (cb, deps = [], delay = 800) => {
|
|
348
|
-
const debouncedHandler =
|
|
362
|
+
const { handler: debouncedHandler, cancel } = useMemo8(() => {
|
|
349
363
|
let timeout;
|
|
350
|
-
return
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
return {
|
|
365
|
+
handler: (event) => {
|
|
366
|
+
if (timeout !== void 0) {
|
|
367
|
+
clearTimeout(timeout);
|
|
368
|
+
}
|
|
369
|
+
timeout = setTimeout(() => {
|
|
370
|
+
timeout = void 0;
|
|
371
|
+
if (typeof document === "undefined" || typeof getComputedStyle === "undefined") {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
cb(event);
|
|
375
|
+
}, delay);
|
|
376
|
+
},
|
|
377
|
+
cancel: () => {
|
|
378
|
+
if (timeout !== void 0) {
|
|
379
|
+
clearTimeout(timeout);
|
|
380
|
+
timeout = void 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
355
383
|
};
|
|
356
384
|
}, [
|
|
357
385
|
cb,
|
|
@@ -360,9 +388,13 @@ var useViewportResize = (cb, deps = [], delay = 800) => {
|
|
|
360
388
|
return useLayoutEffect(() => {
|
|
361
389
|
window.visualViewport?.addEventListener("resize", debouncedHandler);
|
|
362
390
|
debouncedHandler();
|
|
363
|
-
return () =>
|
|
391
|
+
return () => {
|
|
392
|
+
window.visualViewport?.removeEventListener("resize", debouncedHandler);
|
|
393
|
+
cancel();
|
|
394
|
+
};
|
|
364
395
|
}, [
|
|
365
396
|
debouncedHandler,
|
|
397
|
+
cancel,
|
|
366
398
|
...deps
|
|
367
399
|
]);
|
|
368
400
|
};
|
|
@@ -412,12 +444,12 @@ var useInterval = (callback, delay = 0, deps = []) => {
|
|
|
412
444
|
};
|
|
413
445
|
|
|
414
446
|
// src/useTransitions.ts
|
|
415
|
-
import { useEffect as useEffect11, useRef as useRef7, useState as
|
|
447
|
+
import { useEffect as useEffect11, useRef as useRef7, useState as useState9 } from "react";
|
|
416
448
|
var isFunction2 = (functionToCheck) => {
|
|
417
449
|
return functionToCheck instanceof Function;
|
|
418
450
|
};
|
|
419
451
|
var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
420
|
-
const [hasTransitioned, setHasTransitioned] =
|
|
452
|
+
const [hasTransitioned, setHasTransitioned] = useState9(false);
|
|
421
453
|
const previousValue = useRef7(currentValue);
|
|
422
454
|
useEffect11(() => {
|
|
423
455
|
const toValueValid = isFunction2(toValue) ? toValue(currentValue) : toValue === currentValue;
|
|
@@ -463,6 +495,7 @@ export {
|
|
|
463
495
|
setRef,
|
|
464
496
|
useAsyncEffect,
|
|
465
497
|
useAsyncState,
|
|
498
|
+
useAtomState,
|
|
466
499
|
useComposedRefs,
|
|
467
500
|
useControlledState,
|
|
468
501
|
useDebugDeps,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/useAsyncEffect.ts", "../../../src/useAsyncState.ts", "../../../src/useControlledState.ts", "../../../src/useDynamicRef.ts", "../../../src/useDebugDeps.ts", "../../../src/useDefaultValue.ts", "../../../src/useDefaults.ts", "../../../src/useFileDownload.ts", "../../../src/useForwardedRef.ts", "../../../src/useId.ts", "../../../src/useIsFocused.ts", "../../../src/useMediaQuery.ts", "../../../src/useMulticastObservable.ts", "../../../src/useRefCallback.ts", "../../../src/useViewportResize.ts", "../../../src/useTimeout.ts", "../../../src/useTransitions.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport { useComposedRefs } from '@radix-ui/react-compose-refs';\nexport { useSize, useScroller } from 'mini-virtual-list';\n\nexport * from './useAsyncEffect';\nexport * from './useAsyncState';\nexport * from './useControlledState';\nexport * from './useDebugDeps';\nexport * from './useDefaultValue';\nexport * from './useDefaults';\nexport * from './useDynamicRef';\nexport * from './useFileDownload';\nexport * from './useForwardedRef';\nexport * from './useId';\nexport * from './useIsFocused';\nexport * from './useMediaQuery';\nexport * from './useMulticastObservable';\nexport * from './useRefCallback';\nexport * from './useViewportResize';\nexport * from './useTimeout';\nexport * from './useTransitions';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DependencyList, type EffectCallback, useEffect } from 'react';\n\n/**\n * Async version of useEffect.\n * The `AbortController` can be used to detect if the component has been unmounted and\n * can be used to propagate abort signals to downstream async operations (e.g., `fetch`).\n */\nexport const useAsyncEffect = (\n cb: (controller: AbortController) => Promise<EffectCallback | void>,\n deps?: DependencyList,\n) => {\n useEffect(() => {\n const controller = new AbortController();\n let cleanup: EffectCallback | void;\n // NOTE: Timeout enables us to immediately cancel. if the component is unmounted.\n const t = setTimeout(async () => {\n if (!controller.signal.aborted) {\n cleanup = await cb(controller);\n }\n });\n\n return () => {\n clearTimeout(t);\n controller.abort();\n cleanup?.();\n };\n }, deps ?? []);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useEffect, useState } from 'react';\n\n/**\n * NOTE: Use with care and when necessary to be able to cancel an async operation when unmounting.\n */\nexport const useAsyncState = <T>(\n cb: () => Promise<T | undefined>,\n deps: any[] = [],\n): [T | undefined, Dispatch<SetStateAction<T | undefined>>] => {\n const [value, setValue] = useState<T | undefined>();\n useEffect(() => {\n let disposed = false;\n const t = setTimeout(async () => {\n const data = await cb();\n if (!disposed) {\n setValue(data);\n }\n });\n\n return () => {\n disposed = true;\n clearTimeout(t);\n };\n }, deps);\n\n return [value, setValue];\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useDynamicRef } from './useDynamicRef';\n\n/**\n * A stateful hook with a controlled value.\n * NOTE: Consider using Radix's `useControllableState`.\n */\nexport const useControlledState = <T>(\n valueProp: T,\n onChange?: (value: T) => void,\n): [T, Dispatch<SetStateAction<T>>] => {\n const [value, setControlledValue] = useState(valueProp);\n useEffect(() => {\n setControlledValue(valueProp);\n }, [valueProp]);\n\n const onChangeRef = useRef(onChange);\n const valueRef = useDynamicRef(valueProp);\n const setValue = useCallback<Dispatch<SetStateAction<T>>>(\n (nextValue) => {\n const value = isFunction(nextValue) ? nextValue(valueRef.current) : nextValue;\n setControlledValue(value);\n onChangeRef.current?.(value);\n },\n [valueRef, onChangeRef],\n );\n\n return [value, setValue];\n};\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Dispatch, type RefObject, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\n/**\n * Like `useState` but with an additional dynamic value.\n */\nexport const useStateWithRef = <T>(valueProp: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>] => {\n const [value, setValue] = useState<T>(valueProp);\n const valueRef = useRef<T>(valueProp);\n const setter = useCallback<Dispatch<SetStateAction<T>>>((value) => {\n if (typeof value === 'function') {\n setValue((current) => {\n valueRef.current = (value as Function)(current);\n return valueRef.current;\n });\n } else {\n valueRef.current = value;\n setValue(value);\n }\n }, []);\n\n return [value, setter, valueRef];\n};\n\n/**\n * Ref that is updated by a dependency.\n */\nexport const useDynamicRef = <T>(value: T): RefObject<T> => {\n const valueRef = useRef<T>(value);\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n return valueRef;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DependencyList, useEffect, useRef } from 'react';\n\nimport { log } from '@dxos/log';\n\n/**\n * Util to log deps that have changed.\n */\nexport const useDebugDeps = (deps: DependencyList = [], label = 'useDebugDeps', active = true) => {\n const lastDeps = useRef<DependencyList>([]);\n useEffect(() => {\n if (!active) {\n return;\n }\n\n const diff: Record<number, { previous: any; current: any }> = {};\n for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {\n if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {\n diff[i] = {\n previous: lastDeps.current[i],\n current: deps[i],\n };\n }\n }\n\n if (Object.keys(diff).length > 0) {\n log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff);\n }\n\n lastDeps.current = deps;\n }, [...deps, active]);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useMemo, useState } from 'react';\n\n/**\n * A custom React hook that provides a stable default value for a potentially undefined reactive value.\n * The defaultValue is memoized upon component mount and remains unchanged until the component unmounts,\n * ensuring stability across all re-renders, even if the defaultValue prop changes.\n *\n * Note: The defaultValue is not reactive. It retains the same value from the component's mount to unmount.\n *\n * @param reactiveValue - The value that may change over time.\n * @param defaultValue - The initial value used when the reactiveValue is undefined. This value is not reactive.\n * @returns - The reactiveValue if it's defined, otherwise the defaultValue.\n */\nexport const useDefaultValue = <T>(reactiveValue: T | undefined | null, getDefaultValue: () => T): T => {\n // Memoize defaultValue with an empty dependency array.\n // This ensures that the defaultValue instance remains stable across all re-renders,\n // regardless of whether the defaultValue changes.\n const stableDefaultValue = useMemo(getDefaultValue, []);\n const [value, setValue] = useState(reactiveValue ?? stableDefaultValue);\n useEffect(() => {\n setValue(reactiveValue ?? stableDefaultValue);\n }, [reactiveValue, stableDefaultValue]);\n\n return value;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport { useMemo } from 'react';\n\n/**\n * Returns a memo-ized deep-merged object of the default and value.\n * If value is undefined or null, then returns the default.\n */\nexport const useDefaults = <T>(value: T | undefined | null, defaults: T): T => {\n return useMemo(() => defaultsDeep({}, defaults, value), [value, defaults]);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\n/**\n * File download anchor.\n *\n * ```\n * const download = useDownload();\n * const handleDownload = (data: string) => {\n * download(new Blob([data], { type: 'text/plain' }), 'test.txt');\n * };\n * ```\n */\nexport const useFileDownload = (): ((data: Blob | string, filename: string) => void) => {\n return useMemo(\n () => (data: Blob | string, filename: string) => {\n const url = typeof data === 'string' ? data : URL.createObjectURL(data);\n const element = document.createElement('a');\n element.setAttribute('href', url);\n element.setAttribute('download', filename);\n element.setAttribute('target', 'download');\n element.click();\n },\n [],\n );\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type ForwardedRef, type Ref, type RefCallback, useEffect, useMemo, useRef } from 'react';\n\n/**\n * Combines a possibly undefined forwarded ref with a locally defined ref.\n * Returns a stable ref object that synchronizes with the forwarded ref.\n *\n * Best practice: This hook creates a stable local ref and synchronizes it with the forwarded ref.\n * The returned ref object is stable across renders, preventing infinite loops caused by ref identity changes.\n *\n * NOTE: This pattern doesn't update refs once they are set. If this is required, use `useMergeRefs`.\n */\nexport const useForwardedRef = <T>(forwardedRef: ForwardedRef<T>) => {\n const localRef = useRef<T>(null as T);\n useEffect(() => {\n setRef(forwardedRef, localRef.current);\n }, [forwardedRef]);\n\n return localRef;\n};\n\n/**\n * Sets a value on a React ref, handling both callback refs and ref objects.\n * Returns a cleanup function if the ref is a callback ref.\n */\nexport function setRef<T>(ref: Ref<T> | undefined | null, value: T | null): ReturnType<RefCallback<T>> {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref) {\n ref.current = value;\n }\n}\n\n/**\n * Merges multiple refs into a single ref callback.\n * Returns a ref callback that synchronizes all provided refs and handles cleanup.\n */\nexport const mergeRefs = <T>(refs: (Ref<T> | undefined)[]): Ref<T> => {\n return (value: T | null) => {\n const cleanups: (() => void)[] = [];\n for (const ref of refs) {\n const cleanup = setRef(ref, value);\n cleanups.push(typeof cleanup === 'function' ? cleanup : () => setRef(ref, null));\n }\n\n return () => {\n for (const cleanup of cleanups) cleanup();\n };\n };\n};\n\n/**\n * Hook that merges multiple refs into a single stable ref callback.\n * The returned ref is memoized and only changes when the refs array changes.\n */\nexport const useMergeRefs = <T>(refs: (Ref<T> | undefined)[]): Ref<T> => {\n return useMemo(() => mergeRefs(refs), [...refs]);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport alea from 'alea';\nimport { useMemo } from 'react';\n\ninterface PrngFactory {\n new (seed?: string): () => number;\n}\n\nconst Alea: PrngFactory = alea as unknown as PrngFactory;\n\nconst prng = new Alea('@dxos/react-hooks');\n\n// TODO(burdon): Replace with PublicKey.random().\nexport const randomString = (n = 4) =>\n prng()\n .toString(16)\n .slice(2, n + 2);\n\nexport const useId = (namespace: string, propsId?: string, opts?: Partial<{ n: number }>) => {\n return useMemo(() => makeId(namespace, propsId, opts), [propsId]);\n};\n\nexport const makeId = (namespace: string, propsId?: string, opts?: Partial<{ n: number }>) =>\n propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;\n", "//\n// Copyright 2022 DXOS.org\n//\n\n// Based upon the useIsFocused hook which is part of the `rci` project:\n/// https://github.com/leonardodino/rci/blob/main/packages/use-w-focused\n\nimport { type RefObject, useEffect, useRef, useState } from 'react';\n\nexport const useIsFocused = (inputRef: RefObject<HTMLInputElement | null>) => {\n const [isFocused, setIsFocused] = useState<boolean | undefined>(undefined);\n const isFocusedRef = useRef<boolean | undefined>(isFocused);\n\n isFocusedRef.current = isFocused;\n\n useEffect(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n const onFocus = () => setIsFocused(true);\n const onBlur = () => setIsFocused(false);\n input.addEventListener('focus', onFocus);\n input.addEventListener('blur', onBlur);\n\n if (isFocusedRef.current === undefined) {\n setIsFocused(document.activeElement === input);\n }\n\n return () => {\n input.removeEventListener('focus', onFocus);\n input.removeEventListener('blur', onBlur);\n };\n }, [inputRef, setIsFocused]);\n\n return isFocused;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// This hook is based on Chakra UI’s `useMediaQuery`: https://github.com/chakra-ui/chakra-ui/blob/main/packages/components/media-query/src/use-media-query.ts\n\nimport { useEffect, useState } from 'react';\n\n// TODO(thure): This should be derived from the same source of truth as the Tailwind theme config.\nconst breakpointMediaQueries: Record<string, string> = {\n sm: '(min-width: 640px)',\n md: '(min-width: 768px)',\n lg: '(min-width: 1024px)',\n xl: '(min-width: 1280px)',\n '2xl': '(min-width: 1536px)',\n};\n\nexport type UseMediaQueryOptions = {\n fallback?: boolean | boolean[];\n ssr?: boolean;\n};\n\n/**\n * React hook that tracks state of a CSS media query.\n *\n * @param query the media query to match, or a recognized breakpoint token\n * @param options the media query options { fallback, ssr }\n *\n * @see Docs https://chakra-ui.com/docs/hooks/use-media-query\n */\nexport const useMediaQuery = (query: string | string[], options: UseMediaQueryOptions = {}): boolean[] => {\n const { ssr = false, fallback } = options;\n\n const queries = (Array.isArray(query) ? query : [query]).map((query) =>\n query in breakpointMediaQueries ? breakpointMediaQueries[query] : query,\n );\n\n let fallbackValues = Array.isArray(fallback) ? fallback : [fallback];\n fallbackValues = fallbackValues.filter((v) => v != null) as boolean[];\n\n const [value, setValue] = useState(() => {\n return queries.map((query, index) => ({\n media: query,\n matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query).matches,\n }));\n });\n\n useEffect(() => {\n setValue(\n queries.map((query) => ({\n media: query,\n matches: document.defaultView?.matchMedia(query).matches,\n })),\n );\n\n const mql = queries.map((query) => document.defaultView?.matchMedia(query));\n\n const handler = (evt: MediaQueryListEvent) => {\n setValue((prev) => {\n return prev.slice().map((item) => {\n if (item.media === evt.media) {\n return { ...item, matches: evt.matches };\n }\n return item;\n });\n });\n };\n\n mql.forEach((mql) => {\n if (typeof mql?.addListener === 'function') {\n mql?.addListener(handler);\n } else {\n mql?.addEventListener('change', handler);\n }\n });\n\n return () => {\n mql.forEach((mql) => {\n if (typeof mql?.removeListener === 'function') {\n mql?.removeListener(handler);\n } else {\n mql?.removeEventListener('change', handler);\n }\n });\n };\n }, [document.defaultView]);\n\n return value.map((item) => !!item.matches);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type MulticastObservable } from '@dxos/async';\n\n/**\n * Subscribe to a MulticastObservable and return the latest value.\n * @param observable the observable to subscribe to. Will resubscribe if the observable changes.\n */\n// TODO(burdon): Move to react-hooks.\nexport const useMulticastObservable = <T>(observable: MulticastObservable<T>): T => {\n // Make sure useSyncExternalStore is stable in respect to the observable.\n const subscribeFn = useMemo(\n () => (listener: () => void) => {\n const subscription = observable.subscribe(listener);\n return () => subscription.unsubscribe();\n },\n [observable],\n );\n\n // useSyncExternalStore will resubscribe to the observable and update the value if the subscribeFn changes.\n return useSyncExternalStore(subscribeFn, () => observable.get());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type RefCallback, useState } from 'react';\n\n/**\n * Custom React Hook that creates a ref callback and a state variable.\n * The ref callback sets the state variable when the ref changes.\n *\n * @returns An object containing the ref callback and the current value of the ref.\n */\nexport const useRefCallback = <T = any>(): { refCallback: RefCallback<T>; value: T | null } => {\n const [value, setValue] = useState<T | null>(null);\n return { refCallback: (value: T) => setValue(value), value };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useLayoutEffect, useMemo } from 'react';\n\nexport const useViewportResize = (\n cb: (event?: Event) => void,\n deps: Parameters<typeof useLayoutEffect>[1] = [],\n delay: number = 800,\n) => {\n const debouncedHandler = useMemo(() => {\n let timeout: ReturnType<typeof setTimeout>;\n return (event?: Event) => {\n clearTimeout(timeout);\n timeout = setTimeout(() => {\n cb(event);\n }, delay);\n };\n }, [cb, delay]);\n\n return useLayoutEffect(() => {\n window.visualViewport?.addEventListener('resize', debouncedHandler);\n debouncedHandler();\n return () => window.visualViewport?.removeEventListener('resize', debouncedHandler);\n }, [debouncedHandler, ...deps]);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nexport const useTimeout = (callback?: () => Promise<void>, delay = 0, deps: any[] = []) => {\n const callbackRef = useRef(callback);\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n if (delay == null) {\n return;\n }\n\n const t = setTimeout(() => callbackRef.current?.(), delay);\n return () => clearTimeout(t);\n }, [delay, ...deps]);\n};\n\nexport const useInterval = (\n callback?: (() => Promise<void | boolean>) | (() => void | boolean),\n delay = 0,\n deps: any[] = [],\n) => {\n const callbackRef = useRef(callback);\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n if (delay == null) {\n return;\n }\n\n const i = setInterval(async () => {\n const result = await callbackRef.current?.();\n if (result === false) {\n clearInterval(i);\n }\n }, delay);\n return () => clearInterval(i);\n }, [delay, ...deps]);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useRef, useState } from 'react';\n\nconst isFunction = <T>(functionToCheck: any): functionToCheck is (value: T) => boolean => {\n return functionToCheck instanceof Function;\n};\n\n/**\n * This is an internal custom hook that checks if a value has transitioned from a specified 'from' value to a 'to' value.\n *\n * @param currentValue - The value that is being monitored for transitions.\n * @param fromValue - The *from* value or a predicate function that determines the start of the transition.\n * @param toValue - The *to* value or a predicate function that determines the end of the transition.\n * @returns A boolean indicating whether the transition from *fromValue* to *toValue* has occurred.\n *\n * @internal Consider using `useOnTransition` for handling transitions instead of this hook.\n */\nexport const useDidTransition = <T>(\n currentValue: T,\n fromValue: T | ((value: T) => boolean),\n toValue: T | ((value: T) => boolean),\n) => {\n const [hasTransitioned, setHasTransitioned] = useState(false);\n const previousValue = useRef<T>(currentValue);\n\n useEffect(() => {\n const toValueValid = isFunction<T>(toValue) ? toValue(currentValue) : toValue === currentValue;\n const fromValueValid = isFunction<T>(fromValue)\n ? fromValue(previousValue.current)\n : fromValue === previousValue.current;\n\n if (fromValueValid && toValueValid && !hasTransitioned) {\n setHasTransitioned(true);\n } else if ((!fromValueValid || !toValueValid) && hasTransitioned) {\n setHasTransitioned(false);\n }\n\n previousValue.current = currentValue;\n }, [currentValue, fromValue, toValue, hasTransitioned]);\n\n return hasTransitioned;\n};\n\n/**\n * Executes a callback function when a specified transition occurs in a value.\n *\n * This function utilizes the `useDidTransition` hook to monitor changes in `currentValue`.\n * When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed.\n */\n// TODO(wittjosiah): Seems overwrought.\nexport const useOnTransition = <T>(\n currentValue: T,\n fromValue: T | ((value: T) => boolean),\n toValue: T | ((value: T) => boolean),\n callback: () => void,\n) => {\n const dirty = useRef(false);\n const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);\n\n useEffect(() => {\n dirty.current = false;\n }, [currentValue, dirty]);\n\n useEffect(() => {\n if (hasTransitioned && !dirty.current) {\n callback();\n dirty.current = true;\n }\n }, [hasTransitioned, dirty, callback]);\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,uBAAuB;AAChC,SAASC,SAASC,mBAAmB;;;ACDrC,SAAmDC,iBAAiB;AAO7D,IAAMC,iBAAiB,CAC5BC,IACAC,SAAAA;
|
|
6
|
-
"names": ["useComposedRefs", "useSize", "useScroller", "useEffect", "useAsyncEffect", "cb", "deps", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/useAsyncEffect.ts", "../../../src/useAtomState.ts", "../../../src/useAsyncState.ts", "../../../src/useControlledState.ts", "../../../src/useDynamicRef.ts", "../../../src/useDebugDeps.ts", "../../../src/useDefaultValue.ts", "../../../src/useDefaults.ts", "../../../src/useFileDownload.ts", "../../../src/useForwardedRef.ts", "../../../src/useId.ts", "../../../src/useIsFocused.ts", "../../../src/useMediaQuery.ts", "../../../src/useMulticastObservable.ts", "../../../src/useRefCallback.ts", "../../../src/useViewportResize.ts", "../../../src/useTimeout.ts", "../../../src/useTransitions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport { useComposedRefs } from '@radix-ui/react-compose-refs';\nexport { useSize, useScroller } from 'mini-virtual-list';\n\nexport * from './useAsyncEffect';\nexport * from './useAtomState';\nexport * from './useAsyncState';\nexport * from './useControlledState';\nexport * from './useDebugDeps';\nexport * from './useDefaultValue';\nexport * from './useDefaults';\nexport * from './useDynamicRef';\nexport * from './useFileDownload';\nexport * from './useForwardedRef';\nexport * from './useId';\nexport * from './useIsFocused';\nexport * from './useMediaQuery';\nexport * from './useMulticastObservable';\nexport * from './useRefCallback';\nexport * from './useViewportResize';\nexport * from './useTimeout';\nexport * from './useTransitions';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DependencyList, type EffectCallback, useEffect } from 'react';\n\n/**\n * Async version of useEffect.\n * The `AbortController` can be used to detect if the component has been unmounted and\n * can be used to propagate abort signals to downstream async operations (e.g., `fetch`).\n */\nexport const useAsyncEffect = (\n cb: (controller: AbortController) => Promise<EffectCallback | void>,\n deps?: DependencyList,\n) => {\n useEffect(() => {\n const controller = new AbortController();\n let cleanup: EffectCallback | void;\n // NOTE: Timeout enables us to immediately cancel. if the component is unmounted.\n const t = setTimeout(async () => {\n if (!controller.signal.aborted) {\n cleanup = await cb(controller);\n }\n });\n\n return () => {\n clearTimeout(t);\n controller.abort();\n cleanup?.();\n };\n }, deps ?? []);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Atom, useAtomSet, useAtomValue } from '@effect-atom/atom-react';\nimport { useMemo, useState } from 'react';\n\nexport type AtomState<T> = {\n atom: Atom.Writable<T>;\n value: T;\n set: (value: T | ((value: T) => T)) => void;\n};\n\n/**\n * Wraps a writable atom together with its current value and setter.\n * The atom is created once on first render; `initialValue` is only used to seed it.\n */\nexport const useAtomState = <T>(initialValue: T): AtomState<T> => {\n const [atom] = useState(() => Atom.make(initialValue));\n const value = useAtomValue(atom);\n const set = useAtomSet(atom);\n return useMemo(() => ({ atom, value, set }), [atom, value, set]);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useEffect, useState } from 'react';\n\n/**\n * NOTE: Use with care and when necessary to be able to cancel an async operation when unmounting.\n */\nexport const useAsyncState = <T>(\n cb: () => Promise<T | undefined>,\n deps: any[] = [],\n): [T | undefined, Dispatch<SetStateAction<T | undefined>>] => {\n const [value, setValue] = useState<T | undefined>();\n useEffect(() => {\n let disposed = false;\n const t = setTimeout(async () => {\n const data = await cb();\n if (!disposed) {\n setValue(data);\n }\n });\n\n return () => {\n disposed = true;\n clearTimeout(t);\n };\n }, deps);\n\n return [value, setValue];\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useDynamicRef } from './useDynamicRef';\n\n/**\n * A stateful hook with a controlled value.\n * NOTE: Consider using Radix's `useControllableState`.\n */\nexport const useControlledState = <T>(\n valueProp: T,\n onChange?: (value: T) => void,\n): [T, Dispatch<SetStateAction<T>>] => {\n const [value, setControlledValue] = useState(valueProp);\n useEffect(() => {\n setControlledValue(valueProp);\n }, [valueProp]);\n\n const onChangeRef = useRef(onChange);\n const valueRef = useDynamicRef(valueProp);\n const setValue = useCallback<Dispatch<SetStateAction<T>>>(\n (nextValue) => {\n const value = isFunction(nextValue) ? nextValue(valueRef.current) : nextValue;\n setControlledValue(value);\n onChangeRef.current?.(value);\n },\n [valueRef, onChangeRef],\n );\n\n return [value, setValue];\n};\n\nfunction isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Dispatch, type RefObject, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\n/**\n * Like `useState` but with an additional dynamic value.\n */\nexport const useStateWithRef = <T>(valueProp: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>] => {\n const [value, setValue] = useState<T>(valueProp);\n const valueRef = useRef<T>(valueProp);\n const setter = useCallback<Dispatch<SetStateAction<T>>>((value) => {\n if (typeof value === 'function') {\n setValue((current) => {\n valueRef.current = (value as Function)(current);\n return valueRef.current;\n });\n } else {\n valueRef.current = value;\n setValue(value);\n }\n }, []);\n\n return [value, setter, valueRef];\n};\n\n/**\n * Ref that is updated by a dependency.\n */\nexport const useDynamicRef = <T>(value: T): RefObject<T> => {\n const valueRef = useRef<T>(value);\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n return valueRef;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DependencyList, useEffect, useRef } from 'react';\n\nimport { log } from '@dxos/log';\n\n/**\n * Util to log deps that have changed.\n */\nexport const useDebugDeps = (deps: DependencyList = [], label = 'useDebugDeps', active = true) => {\n const lastDeps = useRef<DependencyList>([]);\n useEffect(() => {\n if (!active) {\n return;\n }\n\n const diff: Record<number, { previous: any; current: any }> = {};\n for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {\n if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {\n diff[i] = {\n previous: lastDeps.current[i],\n current: deps[i],\n };\n }\n }\n\n if (Object.keys(diff).length > 0) {\n log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff);\n }\n\n lastDeps.current = deps;\n }, [...deps, active]);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useMemo, useState } from 'react';\n\n/**\n * A custom React hook that provides a stable default value for a potentially undefined reactive value.\n * The defaultValue is memoized upon component mount and remains unchanged until the component unmounts,\n * ensuring stability across all re-renders, even if the defaultValue prop changes.\n *\n * Note: The defaultValue is not reactive. It retains the same value from the component's mount to unmount.\n *\n * @param reactiveValue - The value that may change over time.\n * @param defaultValue - The initial value used when the reactiveValue is undefined. This value is not reactive.\n * @returns - The reactiveValue if it's defined, otherwise the defaultValue.\n */\nexport const useDefaultValue = <T>(reactiveValue: T | undefined | null, getDefaultValue: () => T): T => {\n // Memoize defaultValue with an empty dependency array.\n // This ensures that the defaultValue instance remains stable across all re-renders,\n // regardless of whether the defaultValue changes.\n const stableDefaultValue = useMemo(getDefaultValue, []);\n const [value, setValue] = useState(reactiveValue ?? stableDefaultValue);\n useEffect(() => {\n setValue(reactiveValue ?? stableDefaultValue);\n }, [reactiveValue, stableDefaultValue]);\n\n return value;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport { useMemo } from 'react';\n\n/**\n * Returns a memo-ized deep-merged object of the default and value.\n * If value is undefined or null, then returns the default.\n */\nexport const useDefaults = <T>(value: T | undefined | null, defaults: T): T => {\n return useMemo(() => defaultsDeep({}, defaults, value), [value, defaults]);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\n/**\n * File download anchor.\n *\n * ```\n * const download = useDownload();\n * const handleDownload = (data: string) => {\n * download(new Blob([data], { type: 'text/plain' }), 'test.txt');\n * };\n * ```\n */\nexport const useFileDownload = (): ((data: Blob | string, filename: string) => void) => {\n return useMemo(\n () => (data: Blob | string, filename: string) => {\n const url = typeof data === 'string' ? data : URL.createObjectURL(data);\n const element = document.createElement('a');\n element.setAttribute('href', url);\n element.setAttribute('download', filename);\n element.setAttribute('target', 'download');\n element.click();\n },\n [],\n );\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type ForwardedRef, type Ref, type RefCallback, useEffect, useMemo, useRef } from 'react';\n\n/**\n * Combines a possibly undefined forwarded ref with a locally defined ref.\n * Returns a stable ref object that synchronizes with the forwarded ref.\n *\n * Best practice: This hook creates a stable local ref and synchronizes it with the forwarded ref.\n * The returned ref object is stable across renders, preventing infinite loops caused by ref identity changes.\n *\n * NOTE: This pattern doesn't update refs once they are set. If this is required, use `useMergeRefs`.\n */\nexport const useForwardedRef = <T>(forwardedRef: ForwardedRef<T>) => {\n const localRef = useRef<T>(null as T);\n useEffect(() => {\n setRef(forwardedRef, localRef.current);\n }, [forwardedRef]);\n\n return localRef;\n};\n\n/**\n * Sets a value on a React ref, handling both callback refs and ref objects.\n * Returns a cleanup function if the ref is a callback ref.\n */\nexport function setRef<T>(ref: Ref<T> | undefined | null, value: T | null): ReturnType<RefCallback<T>> {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref) {\n ref.current = value;\n }\n}\n\n/**\n * Merges multiple refs into a single ref callback.\n * Returns a ref callback that synchronizes all provided refs and handles cleanup.\n */\nexport const mergeRefs = <T>(refs: (Ref<T> | undefined)[]): Ref<T> => {\n return (value: T | null) => {\n const cleanups: (() => void)[] = [];\n for (const ref of refs) {\n const cleanup = setRef(ref, value);\n cleanups.push(typeof cleanup === 'function' ? cleanup : () => setRef(ref, null));\n }\n\n return () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n };\n };\n};\n\n/**\n * Hook that merges multiple refs into a single stable ref callback.\n * The returned ref is memoized and only changes when the refs array changes.\n */\nexport const useMergeRefs = <T>(refs: (Ref<T> | undefined)[]): Ref<T> => {\n return useMemo(() => mergeRefs(refs), [...refs]);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport alea from 'alea';\nimport { useMemo } from 'react';\n\ninterface PrngFactory {\n new (seed?: string): () => number;\n}\n\nconst Alea: PrngFactory = alea as unknown as PrngFactory;\n\nconst prng = new Alea('@dxos/react-hooks');\n\n// TODO(burdon): Replace with PublicKey.random().\nexport const randomString = (n = 4) =>\n prng()\n .toString(16)\n .slice(2, n + 2);\n\nexport const useId = (namespace: string, propsId?: string, opts?: Partial<{ n: number }>) => {\n return useMemo(() => makeId(namespace, propsId, opts), [propsId]);\n};\n\nexport const makeId = (namespace: string, propsId?: string, opts?: Partial<{ n: number }>) =>\n propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;\n", "//\n// Copyright 2022 DXOS.org\n//\n\n// Based upon the useIsFocused hook which is part of the `rci` project:\n/// https://github.com/leonardodino/rci/blob/main/packages/use-w-focused\n\nimport { type RefObject, useEffect, useRef, useState } from 'react';\n\nexport const useIsFocused = (inputRef: RefObject<HTMLInputElement | null>) => {\n const [isFocused, setIsFocused] = useState<boolean | undefined>(undefined);\n const isFocusedRef = useRef<boolean | undefined>(isFocused);\n\n isFocusedRef.current = isFocused;\n\n useEffect(() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n\n const onFocus = () => setIsFocused(true);\n const onBlur = () => setIsFocused(false);\n input.addEventListener('focus', onFocus);\n input.addEventListener('blur', onBlur);\n\n if (isFocusedRef.current === undefined) {\n setIsFocused(document.activeElement === input);\n }\n\n return () => {\n input.removeEventListener('focus', onFocus);\n input.removeEventListener('blur', onBlur);\n };\n }, [inputRef, setIsFocused]);\n\n return isFocused;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// This hook is based on Chakra UI’s `useMediaQuery`: https://github.com/chakra-ui/chakra-ui/blob/main/packages/components/media-query/src/use-media-query.ts\n\nimport { useEffect, useState } from 'react';\n\n// TODO(thure): This should be derived from the same source of truth as the Tailwind theme config.\nconst breakpointMediaQueries: Record<string, string> = {\n sm: '(min-width: 640px)',\n md: '(min-width: 768px)',\n lg: '(min-width: 1024px)',\n xl: '(min-width: 1280px)',\n '2xl': '(min-width: 1536px)',\n};\n\nexport type UseMediaQueryOptions = {\n fallback?: boolean | boolean[];\n ssr?: boolean;\n};\n\n/**\n * React hook that tracks state of a CSS media query.\n *\n * @param query the media query to match, or a recognized breakpoint token\n * @param options the media query options { fallback, ssr }\n *\n * @see Docs https://chakra-ui.com/docs/hooks/use-media-query\n */\nexport const useMediaQuery = (query: string | string[], options: UseMediaQueryOptions = {}): boolean[] => {\n const { ssr = false, fallback } = options;\n\n const queries = (Array.isArray(query) ? query : [query]).map((query) =>\n query in breakpointMediaQueries ? breakpointMediaQueries[query] : query,\n );\n\n let fallbackValues = Array.isArray(fallback) ? fallback : [fallback];\n fallbackValues = fallbackValues.filter((v) => v != null) as boolean[];\n\n const [value, setValue] = useState(() => {\n return queries.map((query, index) => ({\n media: query,\n matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query).matches,\n }));\n });\n\n useEffect(() => {\n setValue(\n queries.map((query) => ({\n media: query,\n matches: document.defaultView?.matchMedia(query).matches,\n })),\n );\n\n const mql = queries.map((query) => document.defaultView?.matchMedia(query));\n\n const handler = (evt: MediaQueryListEvent) => {\n setValue((prev) => {\n return prev.slice().map((item) => {\n if (item.media === evt.media) {\n return { ...item, matches: evt.matches };\n }\n return item;\n });\n });\n };\n\n mql.forEach((mql) => {\n if (typeof mql?.addListener === 'function') {\n mql?.addListener(handler);\n } else {\n mql?.addEventListener('change', handler);\n }\n });\n\n return () => {\n mql.forEach((mql) => {\n if (typeof mql?.removeListener === 'function') {\n mql?.removeListener(handler);\n } else {\n mql?.removeEventListener('change', handler);\n }\n });\n };\n }, [document.defaultView]);\n\n return value.map((item) => !!item.matches);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type MulticastObservable } from '@dxos/async';\n\n/**\n * Subscribe to a MulticastObservable and return the latest value.\n * @param observable the observable to subscribe to. Will resubscribe if the observable changes.\n */\n// TODO(burdon): Move to react-hooks.\nexport const useMulticastObservable = <T>(observable: MulticastObservable<T>): T => {\n // Make sure useSyncExternalStore is stable in respect to the observable.\n const subscribeFn = useMemo(\n () => (listener: () => void) => {\n const subscription = observable.subscribe(listener);\n return () => subscription.unsubscribe();\n },\n [observable],\n );\n\n // useSyncExternalStore will resubscribe to the observable and update the value if the subscribeFn changes.\n return useSyncExternalStore(subscribeFn, () => observable.get());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type RefCallback, useState } from 'react';\n\n/**\n * Custom React Hook that creates a ref callback and a state variable.\n * The ref callback sets the state variable when the ref changes.\n *\n * @returns An object containing the ref callback and the current value of the ref.\n */\nexport const useRefCallback = <T = any>(): { refCallback: RefCallback<T>; value: T | null } => {\n const [value, setValue] = useState<T | null>(null);\n return { refCallback: (value: T) => setValue(value), value };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useLayoutEffect, useMemo } from 'react';\n\nexport const useViewportResize = (\n cb: (event?: Event) => void,\n deps: Parameters<typeof useLayoutEffect>[1] = [],\n delay: number = 800,\n) => {\n // The cleanup must cancel the pending debounce timeout. Otherwise, if the\n // component unmounts during the `delay` window (common in jsdom/happy-dom\n // test teardown), the callback fires against a torn-down DOM and surfaces\n // as `ReferenceError: getComputedStyle is not defined`.\n const { handler: debouncedHandler, cancel } = useMemo(() => {\n let timeout: ReturnType<typeof setTimeout> | undefined;\n return {\n handler: (event?: Event) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(() => {\n timeout = undefined;\n // The debounced callback can outlive the DOM realm: in jsdom/happy-dom test runs the\n // timer survives environment teardown (e.g. story roots that are never unmounted), and\n // callbacks here read DOM globals such as `getComputedStyle`. Skip dispatch once the\n // realm is gone.\n if (typeof document === 'undefined' || typeof getComputedStyle === 'undefined') {\n return;\n }\n cb(event);\n }, delay);\n },\n cancel: () => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n timeout = undefined;\n }\n },\n };\n }, [cb, delay]);\n\n return useLayoutEffect(() => {\n window.visualViewport?.addEventListener('resize', debouncedHandler);\n debouncedHandler();\n return () => {\n window.visualViewport?.removeEventListener('resize', debouncedHandler);\n cancel();\n };\n }, [debouncedHandler, cancel, ...deps]);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nexport const useTimeout = (callback?: () => Promise<void>, delay = 0, deps: any[] = []) => {\n const callbackRef = useRef(callback);\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n if (delay == null) {\n return;\n }\n\n const t = setTimeout(() => callbackRef.current?.(), delay);\n return () => clearTimeout(t);\n }, [delay, ...deps]);\n};\n\nexport const useInterval = (\n callback?: (() => Promise<void | boolean>) | (() => void | boolean),\n delay = 0,\n deps: any[] = [],\n) => {\n const callbackRef = useRef(callback);\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n if (delay == null) {\n return;\n }\n\n const i = setInterval(async () => {\n const result = await callbackRef.current?.();\n if (result === false) {\n clearInterval(i);\n }\n }, delay);\n return () => clearInterval(i);\n }, [delay, ...deps]);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useRef, useState } from 'react';\n\nconst isFunction = <T>(functionToCheck: any): functionToCheck is (value: T) => boolean => {\n return functionToCheck instanceof Function;\n};\n\n/**\n * This is an internal custom hook that checks if a value has transitioned from a specified 'from' value to a 'to' value.\n *\n * @param currentValue - The value that is being monitored for transitions.\n * @param fromValue - The *from* value or a predicate function that determines the start of the transition.\n * @param toValue - The *to* value or a predicate function that determines the end of the transition.\n * @returns A boolean indicating whether the transition from *fromValue* to *toValue* has occurred.\n *\n * @internal Consider using `useOnTransition` for handling transitions instead of this hook.\n */\nexport const useDidTransition = <T>(\n currentValue: T,\n fromValue: T | ((value: T) => boolean),\n toValue: T | ((value: T) => boolean),\n) => {\n const [hasTransitioned, setHasTransitioned] = useState(false);\n const previousValue = useRef<T>(currentValue);\n\n useEffect(() => {\n const toValueValid = isFunction<T>(toValue) ? toValue(currentValue) : toValue === currentValue;\n const fromValueValid = isFunction<T>(fromValue)\n ? fromValue(previousValue.current)\n : fromValue === previousValue.current;\n\n if (fromValueValid && toValueValid && !hasTransitioned) {\n setHasTransitioned(true);\n } else if ((!fromValueValid || !toValueValid) && hasTransitioned) {\n setHasTransitioned(false);\n }\n\n previousValue.current = currentValue;\n }, [currentValue, fromValue, toValue, hasTransitioned]);\n\n return hasTransitioned;\n};\n\n/**\n * Executes a callback function when a specified transition occurs in a value.\n *\n * This function utilizes the `useDidTransition` hook to monitor changes in `currentValue`.\n * When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed.\n */\n// TODO(wittjosiah): Seems overwrought.\nexport const useOnTransition = <T>(\n currentValue: T,\n fromValue: T | ((value: T) => boolean),\n toValue: T | ((value: T) => boolean),\n callback: () => void,\n) => {\n const dirty = useRef(false);\n const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);\n\n useEffect(() => {\n dirty.current = false;\n }, [currentValue, dirty]);\n\n useEffect(() => {\n if (hasTransitioned && !dirty.current) {\n callback();\n dirty.current = true;\n }\n }, [hasTransitioned, dirty, callback]);\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,uBAAuB;AAChC,SAASC,SAASC,mBAAmB;;;ACDrC,SAAmDC,iBAAiB;AAO7D,IAAMC,iBAAiB,CAC5BC,IACAC,SAAAA;AAEAH,YAAU,MAAA;AACR,UAAMI,aAAa,IAAIC,gBAAAA;AACvB,QAAIC;AAEJ,UAAMC,IAAIC,WAAW,YAAA;AACnB,UAAI,CAACJ,WAAWK,OAAOC,SAAS;AAC9BJ,kBAAU,MAAMJ,GAAGE,UAAAA;MACrB;IACF,CAAA;AAEA,WAAO,MAAA;AACLO,mBAAaJ,CAAAA;AACbH,iBAAWQ,MAAK;AAChBN,gBAAAA;IACF;EACF,GAAGH,QAAQ,CAAA,CAAE;AACf;;;AC3BA,SAASU,MAAMC,YAAYC,oBAAoB;AAC/C,SAASC,SAASC,gBAAgB;AAY3B,IAAMC,eAAe,CAAIC,iBAAAA;AAC9B,QAAM,CAACC,IAAAA,IAAQH,SAAS,MAAMJ,KAAKQ,KAAKF,YAAAA,CAAAA;AACxC,QAAMG,QAAQP,aAAaK,IAAAA;AAC3B,QAAMG,MAAMT,WAAWM,IAAAA;AACvB,SAAOJ,QAAQ,OAAO;IAAEI;IAAME;IAAOC;EAAI,IAAI;IAACH;IAAME;IAAOC;GAAI;AACjE;;;AClBA,SAA6CC,aAAAA,YAAWC,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A;AACrB,QAAMS,kBAAkBJ,iBAAiBC,cAAcC,WAAWC,OAAAA;AAElET,EAAAA,YAAU,MAAA;AACRkB,UAAMH,UAAU;EAClB,GAAG;IAACR;IAAcW;GAAM;AAExBlB,EAAAA,YAAU,MAAA;AACR,QAAIU,mBAAmB,CAACQ,MAAMH,SAAS;AACrCE,eAAAA;AACAC,YAAMH,UAAU;IAClB;EACF,GAAG;IAACL;IAAiBQ;IAAOD;GAAS;AACvC;",
|
|
6
|
+
"names": ["useComposedRefs", "useSize", "useScroller", "useEffect", "useAsyncEffect", "cb", "deps", "controller", "AbortController", "cleanup", "t", "setTimeout", "signal", "aborted", "clearTimeout", "abort", "Atom", "useAtomSet", "useAtomValue", "useMemo", "useState", "useAtomState", "initialValue", "atom", "make", "value", "set", "useEffect", "useState", "useAsyncState", "cb", "deps", "value", "setValue", "disposed", "t", "setTimeout", "data", "clearTimeout", "useCallback", "useEffect", "useRef", "useState", "useCallback", "useEffect", "useRef", "useState", "useStateWithRef", "valueProp", "value", "setValue", "valueRef", "setter", "current", "useDynamicRef", "useControlledState", "valueProp", "onChange", "value", "setControlledValue", "useState", "useEffect", "onChangeRef", "useRef", "valueRef", "useDynamicRef", "setValue", "useCallback", "nextValue", "isFunction", "current", "useEffect", "useRef", "log", "useDebugDeps", "deps", "label", "active", "lastDeps", "diff", "i", "Math", "max", "current", "length", "previous", "Object", "keys", "warn", "useEffect", "useMemo", "useState", "useDefaultValue", "reactiveValue", "getDefaultValue", "stableDefaultValue", "value", "setValue", "defaultsDeep", "useMemo", "useDefaults", "value", "defaults", "useMemo", "useFileDownload", "data", "filename", "url", "URL", "createObjectURL", "element", "document", "createElement", "setAttribute", "click", "useEffect", "useMemo", "useRef", "useForwardedRef", "forwardedRef", "localRef", "setRef", "current", "ref", "value", "mergeRefs", "refs", "cleanups", "cleanup", "push", "useMergeRefs", "alea", "useMemo", "Alea", "prng", "randomString", "n", "toString", "slice", "useId", "namespace", "propsId", "opts", "makeId", "useEffect", "useRef", "useState", "useIsFocused", "inputRef", "isFocused", "setIsFocused", "undefined", "isFocusedRef", "current", "input", "onFocus", "onBlur", "addEventListener", "document", "activeElement", "removeEventListener", "useEffect", "useState", "breakpointMediaQueries", "sm", "md", "lg", "xl", "useMediaQuery", "query", "options", "ssr", "fallback", "queries", "Array", "isArray", "map", "fallbackValues", "filter", "v", "value", "setValue", "index", "media", "matches", "document", "defaultView", "matchMedia", "mql", "handler", "evt", "prev", "slice", "item", "forEach", "addListener", "addEventListener", "removeListener", "removeEventListener", "useMemo", "useSyncExternalStore", "useMulticastObservable", "observable", "subscribeFn", "listener", "subscription", "subscribe", "unsubscribe", "get", "useState", "useRefCallback", "value", "setValue", "refCallback", "useLayoutEffect", "useMemo", "useViewportResize", "cb", "deps", "delay", "handler", "debouncedHandler", "cancel", "timeout", "event", "undefined", "clearTimeout", "setTimeout", "document", "getComputedStyle", "window", "visualViewport", "addEventListener", "removeEventListener", "useEffect", "useRef", "useTimeout", "callback", "delay", "deps", "callbackRef", "current", "t", "setTimeout", "clearTimeout", "useInterval", "i", "setInterval", "result", "clearInterval", "useEffect", "useRef", "useState", "isFunction", "functionToCheck", "Function", "useDidTransition", "currentValue", "fromValue", "toValue", "hasTransitioned", "setHasTransitioned", "previousValue", "toValueValid", "fromValueValid", "current", "useOnTransition", "callback", "dirty"]
|
|
7
7
|
}
|