@dxos/react-hooks 0.8.4-main.5ad4a44 → 0.8.4-main.60689f5b1c

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.
Files changed (52) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -0
  3. package/dist/lib/browser/index.mjs +198 -145
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/node-esm/index.mjs +198 -145
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/types/src/index.d.ts +4 -2
  10. package/dist/types/src/index.d.ts.map +1 -1
  11. package/dist/types/src/useAsyncEffect.d.ts.map +1 -1
  12. package/dist/types/src/useAsyncState.d.ts.map +1 -1
  13. package/dist/types/src/useAtomState.d.ts +12 -0
  14. package/dist/types/src/useAtomState.d.ts.map +1 -0
  15. package/dist/types/src/useControlledState.d.ts +2 -2
  16. package/dist/types/src/useControlledState.d.ts.map +1 -1
  17. package/dist/types/src/useDebugDeps.d.ts +1 -1
  18. package/dist/types/src/useDebugDeps.d.ts.map +1 -1
  19. package/dist/types/src/useDefaultValue.d.ts.map +1 -1
  20. package/dist/types/src/useDefaults.d.ts.map +1 -1
  21. package/dist/types/src/useDynamicRef.d.ts +3 -3
  22. package/dist/types/src/useDynamicRef.d.ts.map +1 -1
  23. package/dist/types/src/useForwardedRef.d.ts +23 -3
  24. package/dist/types/src/useForwardedRef.d.ts.map +1 -1
  25. package/dist/types/src/useId.d.ts.map +1 -1
  26. package/dist/types/src/useIsFocused.d.ts.map +1 -1
  27. package/dist/types/src/useMediaQuery.d.ts +1 -1
  28. package/dist/types/src/useMediaQuery.d.ts.map +1 -1
  29. package/dist/types/src/useMulticastObservable.d.ts.map +1 -1
  30. package/dist/types/src/useTimeout.d.ts.map +1 -1
  31. package/dist/types/src/useTransitions.d.ts.map +1 -1
  32. package/dist/types/src/useViewportResize.d.ts +3 -0
  33. package/dist/types/src/useViewportResize.d.ts.map +1 -0
  34. package/dist/types/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +19 -15
  36. package/src/index.ts +5 -2
  37. package/src/useAtomState.ts +23 -0
  38. package/src/useControlledState.ts +22 -12
  39. package/src/useDebugDeps.ts +17 -8
  40. package/src/useDynamicRef.ts +5 -6
  41. package/src/useForwardedRef.ts +50 -13
  42. package/src/useId.ts +3 -2
  43. package/src/useIsFocused.ts +1 -1
  44. package/src/useMediaQuery.ts +7 -7
  45. package/src/useMulticastObservable.test.ts +1 -1
  46. package/src/useViewportResize.ts +45 -0
  47. package/dist/types/src/useResize.d.ts +0 -3
  48. package/dist/types/src/useResize.d.ts.map +0 -1
  49. package/dist/types/src/useSignals.d.ts +0 -10
  50. package/dist/types/src/useSignals.d.ts.map +0 -1
  51. package/src/useResize.ts +0 -27
  52. package/src/useSignals.ts +0 -27
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
package/README.md CHANGED
@@ -3,4 +3,5 @@
3
3
  TypeScript types for DXOS UI and its themes.
4
4
 
5
5
  Ref
6
+
6
7
  - https://github.com/jaredLunde/react-hook
@@ -1,3 +1,7 @@
1
+ // src/index.ts
2
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
3
+ import { useSize, useScroller } from "mini-virtual-list";
4
+
1
5
  // src/useAsyncEffect.ts
2
6
  import { useEffect } from "react";
3
7
  var useAsyncEffect = (cb, deps) => {
@@ -17,10 +21,28 @@ var useAsyncEffect = (cb, deps) => {
17
21
  }, deps ?? []);
18
22
  };
19
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
+
20
42
  // src/useAsyncState.ts
21
- import { useEffect as useEffect2, useState } from "react";
43
+ import { useEffect as useEffect2, useState as useState2 } from "react";
22
44
  var useAsyncState = (cb, deps = []) => {
23
- const [value, setValue] = useState();
45
+ const [value, setValue] = useState2();
24
46
  useEffect2(() => {
25
47
  let disposed = false;
26
48
  const t = setTimeout(async () => {
@@ -41,58 +63,102 @@ var useAsyncState = (cb, deps = []) => {
41
63
  };
42
64
 
43
65
  // src/useControlledState.ts
44
- import { useEffect as useEffect3, useState as useState2 } from "react";
45
- var useControlledState = (controlledValue, onChange, ...deps) => {
46
- const [value, setValue] = useState2(controlledValue);
47
- useEffect3(() => {
48
- if (controlledValue !== void 0) {
49
- setValue(controlledValue);
66
+ import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
67
+
68
+ // src/useDynamicRef.ts
69
+ import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
70
+ var useStateWithRef = (valueProp) => {
71
+ const [value, setValue] = useState3(valueProp);
72
+ const valueRef = useRef(valueProp);
73
+ const setter = useCallback((value2) => {
74
+ if (typeof value2 === "function") {
75
+ setValue((current) => {
76
+ valueRef.current = value2(current);
77
+ return valueRef.current;
78
+ });
79
+ } else {
80
+ valueRef.current = value2;
81
+ setValue(value2);
50
82
  }
83
+ }, []);
84
+ return [
85
+ value,
86
+ setter,
87
+ valueRef
88
+ ];
89
+ };
90
+ var useDynamicRef = (value) => {
91
+ const valueRef = useRef(value);
92
+ useEffect3(() => {
93
+ valueRef.current = value;
51
94
  }, [
52
- controlledValue,
53
- ...deps
95
+ value
54
96
  ]);
55
- useEffect3(() => {
56
- onChange?.(value);
97
+ return valueRef;
98
+ };
99
+
100
+ // src/useControlledState.ts
101
+ var useControlledState = (valueProp, onChange) => {
102
+ const [value, setControlledValue] = useState4(valueProp);
103
+ useEffect4(() => {
104
+ setControlledValue(valueProp);
57
105
  }, [
58
- value,
59
- onChange
106
+ valueProp
107
+ ]);
108
+ const onChangeRef = useRef2(onChange);
109
+ const valueRef = useDynamicRef(valueProp);
110
+ const setValue = useCallback2((nextValue) => {
111
+ const value2 = isFunction(nextValue) ? nextValue(valueRef.current) : nextValue;
112
+ setControlledValue(value2);
113
+ onChangeRef.current?.(value2);
114
+ }, [
115
+ valueRef,
116
+ onChangeRef
60
117
  ]);
61
118
  return [
62
119
  value,
63
120
  setValue
64
121
  ];
65
122
  };
123
+ function isFunction(value) {
124
+ return typeof value === "function";
125
+ }
66
126
 
67
127
  // src/useDebugDeps.ts
68
- import { useEffect as useEffect4, useRef } from "react";
69
- var useDebugDeps = (deps = [], active = true) => {
70
- const lastDeps = useRef([]);
71
- useEffect4(() => {
72
- console.group("deps changed", {
73
- previous: lastDeps.current.length,
74
- current: deps.length
75
- });
128
+ import { useEffect as useEffect5, useRef as useRef3 } from "react";
129
+ import { log } from "@dxos/log";
130
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-primitives/react-hooks/src/useDebugDeps.ts";
131
+ var useDebugDeps = (deps = [], label = "useDebugDeps", active = true) => {
132
+ const lastDeps = useRef3([]);
133
+ useEffect5(() => {
134
+ if (!active) {
135
+ return;
136
+ }
137
+ const diff = {};
76
138
  for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {
77
- if (lastDeps.current[i] !== deps[i] && active) {
78
- console.log("changed", {
79
- index: i,
139
+ if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {
140
+ diff[i] = {
80
141
  previous: lastDeps.current[i],
81
142
  current: deps[i]
82
- });
143
+ };
83
144
  }
84
145
  }
85
- console.groupEnd();
146
+ if (Object.keys(diff).length > 0) {
147
+ log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 24, S: void 0 });
148
+ }
86
149
  lastDeps.current = deps;
87
- }, deps);
150
+ }, [
151
+ ...deps,
152
+ active
153
+ ]);
88
154
  };
89
155
 
90
156
  // src/useDefaultValue.ts
91
- import { useEffect as useEffect5, useMemo, useState as useState3 } from "react";
157
+ import { useEffect as useEffect6, useMemo as useMemo2, useState as useState5 } from "react";
92
158
  var useDefaultValue = (reactiveValue, getDefaultValue) => {
93
- const stableDefaultValue = useMemo(getDefaultValue, []);
94
- const [value, setValue] = useState3(reactiveValue ?? stableDefaultValue);
95
- useEffect5(() => {
159
+ const stableDefaultValue = useMemo2(getDefaultValue, []);
160
+ const [value, setValue] = useState5(reactiveValue ?? stableDefaultValue);
161
+ useEffect6(() => {
96
162
  setValue(reactiveValue ?? stableDefaultValue);
97
163
  }, [
98
164
  reactiveValue,
@@ -103,51 +169,18 @@ var useDefaultValue = (reactiveValue, getDefaultValue) => {
103
169
 
104
170
  // src/useDefaults.ts
105
171
  import defaultsDeep from "lodash.defaultsdeep";
106
- import { useMemo as useMemo2 } from "react";
172
+ import { useMemo as useMemo3 } from "react";
107
173
  var useDefaults = (value, defaults) => {
108
- return useMemo2(() => defaultsDeep({}, defaults, value), [
174
+ return useMemo3(() => defaultsDeep({}, defaults, value), [
109
175
  value,
110
176
  defaults
111
177
  ]);
112
178
  };
113
179
 
114
- // src/useDynamicRef.ts
115
- import { useCallback } from "@preact-signals/safe-react/react";
116
- import { useEffect as useEffect6, useRef as useRef2, useState as useState4 } from "react";
117
- var useStateWithRef = (valueParam) => {
118
- const [value, setValue] = useState4(valueParam);
119
- const valueRef = useRef2(valueParam);
120
- const setter = useCallback((value2) => {
121
- if (typeof value2 === "function") {
122
- setValue((current) => {
123
- valueRef.current = value2(current);
124
- return valueRef.current;
125
- });
126
- } else {
127
- valueRef.current = value2;
128
- setValue(value2);
129
- }
130
- }, []);
131
- return [
132
- value,
133
- setter,
134
- valueRef
135
- ];
136
- };
137
- var useDynamicRef = (value) => {
138
- const valueRef = useRef2(value);
139
- useEffect6(() => {
140
- valueRef.current = value;
141
- }, [
142
- value
143
- ]);
144
- return valueRef;
145
- };
146
-
147
180
  // src/useFileDownload.ts
148
- import { useMemo as useMemo3 } from "react";
181
+ import { useMemo as useMemo4 } from "react";
149
182
  var useFileDownload = () => {
150
- return useMemo3(() => (data, filename) => {
183
+ return useMemo4(() => (data, filename) => {
151
184
  const url = typeof data === "string" ? data : URL.createObjectURL(data);
152
185
  const element = document.createElement("a");
153
186
  element.setAttribute("href", url);
@@ -158,38 +191,61 @@ var useFileDownload = () => {
158
191
  };
159
192
 
160
193
  // src/useForwardedRef.ts
161
- import { useEffect as useEffect7, useRef as useRef3 } from "react";
162
- var useForwardedRef = (ref) => {
163
- const innerRef = useRef3(null);
194
+ import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4 } from "react";
195
+ var useForwardedRef = (forwardedRef) => {
196
+ const localRef = useRef4(null);
164
197
  useEffect7(() => {
165
- if (!ref) {
166
- return;
167
- }
168
- if (typeof ref === "function") {
169
- ref(innerRef.current);
170
- } else {
171
- ref.current = innerRef.current;
198
+ setRef(forwardedRef, localRef.current);
199
+ }, [
200
+ forwardedRef
201
+ ]);
202
+ return localRef;
203
+ };
204
+ function setRef(ref, value) {
205
+ if (typeof ref === "function") {
206
+ return ref(value);
207
+ } else if (ref) {
208
+ ref.current = value;
209
+ }
210
+ }
211
+ var mergeRefs = (refs) => {
212
+ return (value) => {
213
+ const cleanups = [];
214
+ for (const ref of refs) {
215
+ const cleanup = setRef(ref, value);
216
+ cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
172
217
  }
173
- });
174
- return innerRef;
218
+ return () => {
219
+ for (const cleanup of cleanups) {
220
+ cleanup();
221
+ }
222
+ };
223
+ };
224
+ };
225
+ var useMergeRefs = (refs) => {
226
+ return useMemo5(() => mergeRefs(refs), [
227
+ ...refs
228
+ ]);
175
229
  };
176
230
 
177
231
  // src/useId.ts
178
232
  import alea from "alea";
179
- import { useMemo as useMemo4 } from "react";
233
+ import { useMemo as useMemo6 } from "react";
180
234
  var Alea = alea;
181
235
  var prng = new Alea("@dxos/react-hooks");
182
236
  var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
183
- var useId = (namespace, propsId, opts) => useMemo4(() => makeId(namespace, propsId, opts), [
184
- propsId
185
- ]);
237
+ var useId = (namespace, propsId, opts) => {
238
+ return useMemo6(() => makeId(namespace, propsId, opts), [
239
+ propsId
240
+ ]);
241
+ };
186
242
  var makeId = (namespace, propsId, opts) => propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;
187
243
 
188
244
  // src/useIsFocused.ts
189
- import { useEffect as useEffect8, useRef as useRef4, useState as useState5 } from "react";
245
+ import { useEffect as useEffect8, useRef as useRef5, useState as useState6 } from "react";
190
246
  var useIsFocused = (inputRef) => {
191
- const [isFocused, setIsFocused] = useState5(void 0);
192
- const isFocusedRef = useRef4(isFocused);
247
+ const [isFocused, setIsFocused] = useState6(void 0);
248
+ const isFocusedRef = useRef5(isFocused);
193
249
  isFocusedRef.current = isFocused;
194
250
  useEffect8(() => {
195
251
  const input = inputRef.current;
@@ -215,7 +271,7 @@ var useIsFocused = (inputRef) => {
215
271
  };
216
272
 
217
273
  // src/useMediaQuery.ts
218
- import { useEffect as useEffect9, useState as useState6 } from "react";
274
+ import { useEffect as useEffect9, useState as useState7 } from "react";
219
275
  var breakpointMediaQueries = {
220
276
  sm: "(min-width: 640px)",
221
277
  md: "(min-width: 768px)",
@@ -232,7 +288,7 @@ var useMediaQuery = (query, options = {}) => {
232
288
  fallback
233
289
  ];
234
290
  fallbackValues = fallbackValues.filter((v) => v != null);
235
- const [value, setValue] = useState6(() => {
291
+ const [value, setValue] = useState7(() => {
236
292
  return queries.map((query2, index) => ({
237
293
  media: query2,
238
294
  matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query2).matches
@@ -280,9 +336,9 @@ var useMediaQuery = (query, options = {}) => {
280
336
  };
281
337
 
282
338
  // src/useMulticastObservable.ts
283
- import { useMemo as useMemo5, useSyncExternalStore } from "react";
339
+ import { useMemo as useMemo7, useSyncExternalStore } from "react";
284
340
  var useMulticastObservable = (observable) => {
285
- const subscribeFn = useMemo5(() => (listener) => {
341
+ const subscribeFn = useMemo7(() => (listener) => {
286
342
  const subscription = observable.subscribe(listener);
287
343
  return () => subscription.unsubscribe();
288
344
  }, [
@@ -292,73 +348,65 @@ var useMulticastObservable = (observable) => {
292
348
  };
293
349
 
294
350
  // src/useRefCallback.ts
295
- import { useState as useState7 } from "react";
351
+ import { useState as useState8 } from "react";
296
352
  var useRefCallback = () => {
297
- const [value, setValue] = useState7(null);
353
+ const [value, setValue] = useState8(null);
298
354
  return {
299
355
  refCallback: (value2) => setValue(value2),
300
356
  value
301
357
  };
302
358
  };
303
359
 
304
- // src/useResize.ts
305
- import { useLayoutEffect, useMemo as useMemo6 } from "react";
306
- var useResize = (handler, deps = [], delay = 800) => {
307
- const debouncedHandler = useMemo6(() => {
360
+ // src/useViewportResize.ts
361
+ import { useLayoutEffect, useMemo as useMemo8 } from "react";
362
+ var useViewportResize = (cb, deps = [], delay = 800) => {
363
+ const { handler: debouncedHandler, cancel } = useMemo8(() => {
308
364
  let timeout;
309
- return (event) => {
310
- clearTimeout(timeout);
311
- timeout = setTimeout(() => {
312
- handler(event);
313
- }, delay);
365
+ return {
366
+ handler: (event) => {
367
+ if (timeout !== void 0) {
368
+ clearTimeout(timeout);
369
+ }
370
+ timeout = setTimeout(() => {
371
+ timeout = void 0;
372
+ cb(event);
373
+ }, delay);
374
+ },
375
+ cancel: () => {
376
+ if (timeout !== void 0) {
377
+ clearTimeout(timeout);
378
+ timeout = void 0;
379
+ }
380
+ }
314
381
  };
315
382
  }, [
316
- handler,
383
+ cb,
317
384
  delay
318
385
  ]);
319
386
  return useLayoutEffect(() => {
320
387
  window.visualViewport?.addEventListener("resize", debouncedHandler);
321
388
  debouncedHandler();
322
- return () => window.visualViewport?.removeEventListener("resize", debouncedHandler);
389
+ return () => {
390
+ window.visualViewport?.removeEventListener("resize", debouncedHandler);
391
+ cancel();
392
+ };
323
393
  }, [
324
394
  debouncedHandler,
395
+ cancel,
325
396
  ...deps
326
397
  ]);
327
398
  };
328
399
 
329
- // src/useSignals.ts
330
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
331
- import { computed, effect } from "@preact-signals/safe-react";
332
- import { useRef as useRef5 } from "@preact-signals/safe-react/react";
333
- import { useEffect as useEffect10, useMemo as useMemo7 } from "react";
334
- var useSignalsEffect = (cb, deps) => {
335
- const callback = useRef5(cb);
336
- callback.current = cb;
337
- useEffect10(() => {
338
- return effect(() => {
339
- return callback.current();
340
- });
341
- }, deps ?? []);
342
- };
343
- var useSignalsMemo = (cb, deps) => {
344
- var _effect = _useSignals();
345
- try {
346
- return useMemo7(() => computed(cb), deps ?? []).value;
347
- } finally {
348
- _effect.f();
349
- }
350
- };
351
-
352
400
  // src/useTimeout.ts
353
- import { useEffect as useEffect11, useRef as useRef6 } from "react";
401
+ import { useEffect as useEffect10, useRef as useRef6 } from "react";
354
402
  var useTimeout = (callback, delay = 0, deps = []) => {
355
403
  const callbackRef = useRef6(callback);
356
- useEffect11(() => {
404
+ useEffect10(() => {
357
405
  callbackRef.current = callback;
358
406
  }, [
359
407
  callback
360
408
  ]);
361
- useEffect11(() => {
409
+ useEffect10(() => {
362
410
  if (delay == null) {
363
411
  return;
364
412
  }
@@ -371,12 +419,12 @@ var useTimeout = (callback, delay = 0, deps = []) => {
371
419
  };
372
420
  var useInterval = (callback, delay = 0, deps = []) => {
373
421
  const callbackRef = useRef6(callback);
374
- useEffect11(() => {
422
+ useEffect10(() => {
375
423
  callbackRef.current = callback;
376
424
  }, [
377
425
  callback
378
426
  ]);
379
- useEffect11(() => {
427
+ useEffect10(() => {
380
428
  if (delay == null) {
381
429
  return;
382
430
  }
@@ -394,16 +442,16 @@ var useInterval = (callback, delay = 0, deps = []) => {
394
442
  };
395
443
 
396
444
  // src/useTransitions.ts
397
- import { useEffect as useEffect12, useRef as useRef7, useState as useState8 } from "react";
398
- var isFunction = (functionToCheck) => {
445
+ import { useEffect as useEffect11, useRef as useRef7, useState as useState9 } from "react";
446
+ var isFunction2 = (functionToCheck) => {
399
447
  return functionToCheck instanceof Function;
400
448
  };
401
449
  var useDidTransition = (currentValue, fromValue, toValue) => {
402
- const [hasTransitioned, setHasTransitioned] = useState8(false);
450
+ const [hasTransitioned, setHasTransitioned] = useState9(false);
403
451
  const previousValue = useRef7(currentValue);
404
- useEffect12(() => {
405
- const toValueValid = isFunction(toValue) ? toValue(currentValue) : toValue === currentValue;
406
- const fromValueValid = isFunction(fromValue) ? fromValue(previousValue.current) : fromValue === previousValue.current;
452
+ useEffect11(() => {
453
+ const toValueValid = isFunction2(toValue) ? toValue(currentValue) : toValue === currentValue;
454
+ const fromValueValid = isFunction2(fromValue) ? fromValue(previousValue.current) : fromValue === previousValue.current;
407
455
  if (fromValueValid && toValueValid && !hasTransitioned) {
408
456
  setHasTransitioned(true);
409
457
  } else if ((!fromValueValid || !toValueValid) && hasTransitioned) {
@@ -421,13 +469,13 @@ var useDidTransition = (currentValue, fromValue, toValue) => {
421
469
  var useOnTransition = (currentValue, fromValue, toValue, callback) => {
422
470
  const dirty = useRef7(false);
423
471
  const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);
424
- useEffect12(() => {
472
+ useEffect11(() => {
425
473
  dirty.current = false;
426
474
  }, [
427
475
  currentValue,
428
476
  dirty
429
477
  ]);
430
- useEffect12(() => {
478
+ useEffect11(() => {
431
479
  if (hasTransitioned && !dirty.current) {
432
480
  callback();
433
481
  dirty.current = true;
@@ -440,9 +488,13 @@ var useOnTransition = (currentValue, fromValue, toValue, callback) => {
440
488
  };
441
489
  export {
442
490
  makeId,
491
+ mergeRefs,
443
492
  randomString,
493
+ setRef,
444
494
  useAsyncEffect,
445
495
  useAsyncState,
496
+ useAtomState,
497
+ useComposedRefs,
446
498
  useControlledState,
447
499
  useDebugDeps,
448
500
  useDefaultValue,
@@ -455,13 +507,14 @@ export {
455
507
  useInterval,
456
508
  useIsFocused,
457
509
  useMediaQuery,
510
+ useMergeRefs,
458
511
  useMulticastObservable,
459
512
  useOnTransition,
460
513
  useRefCallback,
461
- useResize,
462
- useSignalsEffect,
463
- useSignalsMemo,
514
+ useScroller,
515
+ useSize,
464
516
  useStateWithRef,
465
- useTimeout
517
+ useTimeout,
518
+ useViewportResize
466
519
  };
467
520
  //# sourceMappingURL=index.mjs.map