@dxos/react-hooks 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/lib/index.mjs +141 -54
  2. package/dist/lib/index.mjs.map +1 -1
  3. package/dist/types/src/composeEventHandlers.d.ts +10 -0
  4. package/dist/types/src/composeEventHandlers.d.ts.map +1 -0
  5. package/dist/types/src/composeEventHandlers.test.d.ts +2 -0
  6. package/dist/types/src/composeEventHandlers.test.d.ts.map +1 -0
  7. package/dist/types/src/createContext.d.ts +9 -0
  8. package/dist/types/src/createContext.d.ts.map +1 -0
  9. package/dist/types/src/createContext.test.d.ts +2 -0
  10. package/dist/types/src/createContext.test.d.ts.map +1 -0
  11. package/dist/types/src/index.d.ts +23 -19
  12. package/dist/types/src/index.d.ts.map +1 -1
  13. package/dist/types/src/useAtomState.d.ts +1 -1
  14. package/dist/types/src/useAtomState.d.ts.map +1 -1
  15. package/dist/types/src/useComposedRefs.d.ts +12 -0
  16. package/dist/types/src/useComposedRefs.d.ts.map +1 -0
  17. package/dist/types/src/useComposedRefs.test.d.ts +2 -0
  18. package/dist/types/src/useComposedRefs.test.d.ts.map +1 -0
  19. package/dist/types/src/useControllableState.d.ts +12 -0
  20. package/dist/types/src/useControllableState.d.ts.map +1 -0
  21. package/dist/types/src/useControllableState.test.d.ts +2 -0
  22. package/dist/types/src/useControllableState.test.d.ts.map +1 -0
  23. package/dist/types/src/useControlledState.d.ts +1 -1
  24. package/dist/types/src/useForwardedRef.d.ts +2 -2
  25. package/dist/types/src/useForwardedRef.d.ts.map +1 -1
  26. package/dist/types/src/useStable.d.ts +9 -0
  27. package/dist/types/src/useStable.d.ts.map +1 -0
  28. package/dist/types/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +6 -7
  30. package/src/composeEventHandlers.test.ts +22 -0
  31. package/src/composeEventHandlers.ts +20 -0
  32. package/src/createContext.test.tsx +33 -0
  33. package/src/createContext.ts +46 -0
  34. package/src/index.ts +23 -19
  35. package/src/useAtomState.ts +1 -1
  36. package/src/useComposedRefs.test.tsx +22 -0
  37. package/src/useComposedRefs.ts +22 -0
  38. package/src/useControllableState.test.tsx +36 -0
  39. package/src/useControllableState.ts +61 -0
  40. package/src/useControlledState.ts +2 -2
  41. package/src/useForwardedRef.ts +2 -2
  42. package/src/useMediaQuery.stories.tsx +5 -5
  43. package/src/useMulticastObservable.test.ts +1 -1
  44. package/src/useStable.ts +21 -0
@@ -1,12 +1,45 @@
1
- import { useComposedRefs } from "@radix-ui/react-compose-refs";
2
1
  import { useScroller, useSize } from "mini-virtual-list";
3
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
+ import { createContext as createContext$1, createElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
3
  import { useAtomSet, useAtomValue } from "@effect/atom-react/Hooks";
5
- import * as Atom from "effect/unstable/reactivity/Atom";
4
+ import * as Atom from "effect/reactivity/Atom";
6
5
  import { log } from "@dxos/log";
7
6
  import defaultsDeep from "lodash.defaultsdeep";
8
7
  import { downloadBlob } from "@dxos/util";
9
8
  import alea from "alea";
9
+ //#region src/composeEventHandlers.ts
10
+ /**
11
+ * Runs the consumer's handler first and skips ours when it called `preventDefault()`.
12
+ * Zag's `mergeProps` always invokes both, so this stays for the parts that honour the skip.
13
+ */
14
+ var composeEventHandlers = (originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) => {
15
+ return (event) => {
16
+ originalEventHandler?.(event);
17
+ if (!checkForDefaultPrevented || !event.defaultPrevented) return ourEventHandler?.(event);
18
+ };
19
+ };
20
+ //#endregion
21
+ //#region src/createContext.ts
22
+ /**
23
+ * A typed context whose provider takes the context fields as props.
24
+ * `useContext` throws a message naming the consumer and root when no provider is mounted and no default was given.
25
+ */
26
+ var createContext = (rootComponentName, defaultContext) => {
27
+ const Context = createContext$1(defaultContext);
28
+ const Provider = (props) => {
29
+ const { children, ...context } = props;
30
+ const value = useMemo(() => context, Object.values(context));
31
+ return createElement(Context.Provider, { value }, children);
32
+ };
33
+ Provider.displayName = `${rootComponentName}Provider`;
34
+ const useTypedContext = (consumerName) => {
35
+ const context = useContext(Context);
36
+ if (context) return context;
37
+ if (defaultContext !== void 0) return defaultContext;
38
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
39
+ };
40
+ return [Provider, useTypedContext];
41
+ };
42
+ //#endregion
10
43
  //#region src/useAsyncEffect.ts
11
44
  /**
12
45
  * Async version of useEffect.
@@ -68,6 +101,95 @@ var useAsyncState = (cb, deps = []) => {
68
101
  return [value, setValue];
69
102
  };
70
103
  //#endregion
104
+ //#region src/useForwardedRef.ts
105
+ /**
106
+ * Combines a possibly undefined forwarded ref with a locally defined ref.
107
+ * Returns a stable ref object that synchronizes with the forwarded ref.
108
+ *
109
+ * Best practice: This hook creates a stable local ref and synchronizes it with the forwarded ref.
110
+ * The returned ref object is stable across renders, preventing infinite loops caused by ref identity changes.
111
+ *
112
+ * NOTE: This pattern doesn't update refs once they are set. If this is required, use `useMergeRefs`.
113
+ */
114
+ var useForwardedRef = (forwardedRef) => {
115
+ const localRef = useRef(null);
116
+ useEffect(() => {
117
+ setRef(forwardedRef, localRef.current);
118
+ }, [forwardedRef]);
119
+ return localRef;
120
+ };
121
+ /**
122
+ * Sets a value on a React ref, handling both callback refs and ref objects.
123
+ * Returns a cleanup function if the ref is a callback ref.
124
+ */
125
+ function setRef(ref, value) {
126
+ if (typeof ref === "function") return ref(value);
127
+ else if (ref) ref.current = value;
128
+ }
129
+ /**
130
+ * Merges multiple refs into a single ref callback.
131
+ * Returns a ref callback that synchronizes all provided refs and handles cleanup.
132
+ */
133
+ var mergeRefs = (refs) => {
134
+ return (value) => {
135
+ const cleanups = [];
136
+ for (const ref of refs) {
137
+ const cleanup = setRef(ref, value);
138
+ cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
139
+ }
140
+ return () => {
141
+ for (const cleanup of cleanups) cleanup();
142
+ };
143
+ };
144
+ };
145
+ /**
146
+ * Hook that merges multiple refs into a single stable ref callback.
147
+ * The returned ref is memoized and only changes when the refs array changes.
148
+ */
149
+ var useMergeRefs = (refs) => {
150
+ return useMemo(() => mergeRefs(refs), [...refs]);
151
+ };
152
+ //#endregion
153
+ //#region src/useComposedRefs.ts
154
+ /**
155
+ * Composes several refs into one callback ref.
156
+ * Each ref receives the node; a callback ref that returns a cleanup keeps it (React 19).
157
+ */
158
+ var composeRefs = (...refs) => mergeRefs(refs);
159
+ /**
160
+ * Memoised {@link composeRefs}; the callback identity changes only when a ref does.
161
+ */
162
+ var useComposedRefs = (...refs) => useCallback(composeRefs(...refs), refs);
163
+ //#endregion
164
+ //#region src/useControllableState.ts
165
+ var isUpdater = (value) => typeof value === "function";
166
+ /**
167
+ * State that is controlled when `prop` is supplied and uncontrolled (seeded from `defaultProp`) otherwise.
168
+ * `onChange` fires for every change in either mode; in controlled mode the setter only reports, it never stores.
169
+ */
170
+ var useControllableState = ({ prop, defaultProp, onChange }) => {
171
+ const [uncontrolledProp, setUncontrolledProp] = useState(defaultProp);
172
+ const isControlled = prop !== void 0;
173
+ const value = isControlled ? prop : uncontrolledProp;
174
+ const onChangeRef = useRef(onChange);
175
+ useEffect(() => {
176
+ onChangeRef.current = onChange;
177
+ });
178
+ const prevValueRef = useRef(uncontrolledProp);
179
+ useEffect(() => {
180
+ if (prevValueRef.current !== uncontrolledProp) {
181
+ onChangeRef.current?.(uncontrolledProp);
182
+ prevValueRef.current = uncontrolledProp;
183
+ }
184
+ }, [uncontrolledProp]);
185
+ return [value, useCallback((nextValue) => {
186
+ if (isControlled) {
187
+ const next = isUpdater(nextValue) ? nextValue(prop) : nextValue;
188
+ if (next !== prop) onChangeRef.current?.(next);
189
+ } else setUncontrolledProp(nextValue);
190
+ }, [isControlled, prop])];
191
+ };
192
+ //#endregion
71
193
  //#region src/useDynamicRef.ts
72
194
  /**
73
195
  * Like `useState` but with an additional dynamic value.
@@ -104,7 +226,7 @@ var useDynamicRef = (value) => {
104
226
  //#region src/useControlledState.ts
105
227
  /**
106
228
  * A stateful hook with a controlled value.
107
- * NOTE: Consider using Radix's `useControllableState`.
229
+ * NOTE: Prefer `useControllableState` when the value has a controlled/uncontrolled split.
108
230
  */
109
231
  var useControlledState = (valueProp, onChange) => {
110
232
  const [value, setControlledValue] = useState(valueProp);
@@ -204,55 +326,6 @@ var useFileDownload = () => {
204
326
  }, []);
205
327
  };
206
328
  //#endregion
207
- //#region src/useForwardedRef.ts
208
- /**
209
- * Combines a possibly undefined forwarded ref with a locally defined ref.
210
- * Returns a stable ref object that synchronizes with the forwarded ref.
211
- *
212
- * Best practice: This hook creates a stable local ref and synchronizes it with the forwarded ref.
213
- * The returned ref object is stable across renders, preventing infinite loops caused by ref identity changes.
214
- *
215
- * NOTE: This pattern doesn't update refs once they are set. If this is required, use `useMergeRefs`.
216
- */
217
- var useForwardedRef = (forwardedRef) => {
218
- const localRef = useRef(null);
219
- useEffect(() => {
220
- setRef(forwardedRef, localRef.current);
221
- }, [forwardedRef]);
222
- return localRef;
223
- };
224
- /**
225
- * Sets a value on a React ref, handling both callback refs and ref objects.
226
- * Returns a cleanup function if the ref is a callback ref.
227
- */
228
- function setRef(ref, value) {
229
- if (typeof ref === "function") return ref(value);
230
- else if (ref) ref.current = value;
231
- }
232
- /**
233
- * Merges multiple refs into a single ref callback.
234
- * Returns a ref callback that synchronizes all provided refs and handles cleanup.
235
- */
236
- var mergeRefs = (refs) => {
237
- return (value) => {
238
- const cleanups = [];
239
- for (const ref of refs) {
240
- const cleanup = setRef(ref, value);
241
- cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
242
- }
243
- return () => {
244
- for (const cleanup of cleanups) cleanup();
245
- };
246
- };
247
- };
248
- /**
249
- * Hook that merges multiple refs into a single stable ref callback.
250
- * The returned ref is memoized and only changes when the refs array changes.
251
- */
252
- var useMergeRefs = (refs) => {
253
- return useMemo(() => mergeRefs(refs), [...refs]);
254
- };
255
- //#endregion
256
329
  //#region src/useId.ts
257
330
  var prng = new alea("@dxos/react-hooks");
258
331
  var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
@@ -369,6 +442,20 @@ var useRefCallback = () => {
369
442
  };
370
443
  };
371
444
  //#endregion
445
+ //#region src/useStable.ts
446
+ /**
447
+ * Holds the previous reference for as long as `equals` accepts the incoming value, so a value the
448
+ * caller assembles inline keeps one identity across the caller's renders.
449
+ *
450
+ * A render React discards can leave the ref holding the discarded value, which costs identity
451
+ * stability on the next render but never correctness.
452
+ */
453
+ var useStable = (value, equals) => {
454
+ const ref = useRef(value);
455
+ if (!equals(ref.current, value)) ref.current = value;
456
+ return ref.current;
457
+ };
458
+ //#endregion
372
459
  //#region src/useViewportResize.ts
373
460
  var useViewportResize = (cb, deps = [], delay = 800) => {
374
461
  const { handler: debouncedHandler, cancel } = useMemo(() => {
@@ -485,6 +572,6 @@ var useOnTransition = (currentValue, fromValue, toValue, callback) => {
485
572
  ]);
486
573
  };
487
574
  //#endregion
488
- export { makeId, mergeRefs, randomString, setRef, useAsyncEffect, useAsyncState, useAtomState, useComposedRefs, useControlledState, useDebugDeps, useDefaultValue, useDefaults, useDidTransition, useDynamicRef, useFileDownload, useForwardedRef, useId, useInterval, useIsFocused, useMediaQuery, useMergeRefs, useMulticastObservable, useOnTransition, useRefCallback, useScroller, useSize, useStateWithRef, useTimeout, useViewportResize };
575
+ export { composeEventHandlers, composeRefs, createContext, makeId, mergeRefs, randomString, setRef, useAsyncEffect, useAsyncState, useAtomState, useComposedRefs, useControllableState, useControlledState, useDebugDeps, useDefaultValue, useDefaults, useDidTransition, useDynamicRef, useFileDownload, useForwardedRef, useId, useInterval, useIsFocused, useMediaQuery, useMergeRefs, useMulticastObservable, useOnTransition, useRefCallback, useScroller, useSize, useStable, useStateWithRef, useTimeout, useViewportResize };
489
576
 
490
577
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/useAsyncEffect.ts","../../src/useAtomState.ts","../../src/useAsyncState.ts","../../src/useDynamicRef.ts","../../src/useControlledState.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"],"sourcesContent":["//\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 { useAtomSet, useAtomValue } from '@effect/atom-react/Hooks';\nimport * as Atom from 'effect/unstable/reactivity/Atom';\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 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 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 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\nimport { log } from '@dxos/log';\nimport { downloadBlob } from '@dxos/util';\n\n/**\n * Save a blob to disk.\n *\n * Goes through {@link downloadBlob}, so the download also works inside the Tauri webview, where\n * `<a download>` is silently dropped. Blob only: a URL would have to fall back to that anchor, and\n * a caller has no way to notice it did nothing.\n *\n * ```\n * const download = useFileDownload();\n * const handleDownload = (data: string) => {\n * download(new Blob([data], { type: 'text/plain' }), 'test.txt');\n * };\n * ```\n */\nexport const useFileDownload = (): ((data: Blob, filename: string) => void) => {\n return useMemo(\n () => (data: Blob, filename: string) => {\n void downloadBlob(data, filename).catch((err) => log.catch(err));\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 // Keyed on a stable string of the resolved queries (the array is rebuilt every render) so a\n // changed `query` re-seeds state and re-subscribes.\n const queryKey = queries.join('|');\n useEffect(() => {\n const mql = queries.map((query) => document.defaultView?.matchMedia(query));\n\n // Seed `media` from the MediaQueryList's own normalized string; change events carry the\n // normalized form, and a raw query that normalizes differently would never match in `handler`.\n setValue(\n mql.map((mql, index) => ({\n media: mql?.media ?? queries[index],\n matches: mql?.matches,\n })),\n );\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 }, [queryKey]);\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"],"mappings":";;;;;;;;;;;;;;;AAWA,IAAa,kBACX,IACA,SACG;CACH,gBAAgB;EACd,MAAM,aAAa,IAAI,gBAAgB;EACvC,IAAI;EAEJ,MAAM,IAAI,WAAW,YAAY;GAC/B,IAAI,CAAC,WAAW,OAAO,SACrB,UAAU,MAAM,GAAG,UAAU;EAEjC,CAAC;EAED,aAAa;GACX,aAAa,CAAC;GACd,WAAW,MAAM;GACjB,UAAU;EACZ;CACF,GAAG,QAAQ,CAAC,CAAC;AACf;;;;;;;ACbA,IAAa,gBAAmB,iBAAkC;CAChE,MAAM,CAAC,QAAQ,eAAe,KAAK,KAAK,YAAY,CAAC;CACrD,MAAM,QAAQ,aAAa,IAAI;CAC/B,MAAM,MAAM,WAAW,IAAI;CAC3B,OAAO,eAAe;EAAE;EAAM;EAAO;CAAI,IAAI;EAAC;EAAM;EAAO;CAAG,CAAC;AACjE;;;;;;ACdA,IAAa,iBACX,IACA,OAAc,CAAC,MAC8C;CAC7D,MAAM,CAAC,OAAO,YAAY,SAAwB;CAClD,gBAAgB;EACd,IAAI,WAAW;EACf,MAAM,IAAI,WAAW,YAAY;GAC/B,MAAM,OAAO,MAAM,GAAG;GACtB,IAAI,CAAC,UACH,SAAS,IAAI;EAEjB,CAAC;EAED,aAAa;GACX,WAAW;GACX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,UAAU;CAC1B,GAAG;EAAC;EAAc;EAAW;EAAS;CAAe,CAAC;CAEtD,OAAO;AACT;;;;;;;AASA,IAAa,mBACX,cACA,WACA,SACA,aACG;CACH,MAAM,QAAQ,OAAO,KAAK;CAC1B,MAAM,kBAAkB,iBAAiB,cAAc,WAAW,OAAO;CAEzE,gBAAgB;EACd,MAAM,UAAU;CAClB,GAAG,CAAC,cAAc,KAAK,CAAC;CAExB,gBAAgB;EACd,IAAI,mBAAmB,CAAC,MAAM,SAAS;GACrC,SAAS;GACT,MAAM,UAAU;EAClB;CACF,GAAG;EAAC;EAAiB;EAAO;CAAQ,CAAC;AACvC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/composeEventHandlers.ts","../../src/createContext.ts","../../src/useAsyncEffect.ts","../../src/useAtomState.ts","../../src/useAsyncState.ts","../../src/useForwardedRef.ts","../../src/useComposedRefs.ts","../../src/useControllableState.ts","../../src/useDynamicRef.ts","../../src/useControlledState.ts","../../src/useDebugDeps.ts","../../src/useDefaultValue.ts","../../src/useDefaults.ts","../../src/useFileDownload.ts","../../src/useId.ts","../../src/useIsFocused.ts","../../src/useMediaQuery.ts","../../src/useMulticastObservable.ts","../../src/useRefCallback.ts","../../src/useStable.ts","../../src/useViewportResize.ts","../../src/useTimeout.ts","../../src/useTransitions.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Runs the consumer's handler first and skips ours when it called `preventDefault()`.\n * Zag's `mergeProps` always invokes both, so this stays for the parts that honour the skip.\n */\nexport const composeEventHandlers = <E extends { defaultPrevented: boolean }>(\n originalEventHandler?: (event: E) => void,\n ourEventHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {},\n) => {\n return (event: E) => {\n originalEventHandler?.(event);\n if (!checkForDefaultPrevented || !event.defaultPrevented) {\n return ourEventHandler?.(event);\n }\n };\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport {\n type FC,\n type ReactNode,\n createElement,\n createContext as createReactContext,\n useContext,\n useMemo,\n} from 'react';\n\n/**\n * A typed context whose provider takes the context fields as props.\n * `useContext` throws a message naming the consumer and root when no provider is mounted and no default was given.\n */\nexport const createContext = <ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n): readonly [FC<ContextValueType & { children?: ReactNode }>, (consumerName: string) => ContextValueType] => {\n const Context = createReactContext<ContextValueType | undefined>(defaultContext);\n\n const Provider: FC<ContextValueType & { children?: ReactNode }> = (props) => {\n const { children, ...context } = props;\n // Memoised on the field values so a re-rendering root does not re-render every consumer.\n // The rest object is the context minus `children`, which TypeScript cannot relate back to the generic.\n const value = useMemo(() => context as ContextValueType, Object.values(context));\n return createElement(Context.Provider, { value }, children);\n };\n\n Provider.displayName = `${rootComponentName}Provider`;\n\n const useTypedContext = (consumerName: string): ContextValueType => {\n const context = useContext(Context);\n if (context) {\n return context;\n }\n if (defaultContext !== undefined) {\n return defaultContext;\n }\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n };\n\n return [Provider, useTypedContext] as const;\n};\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 { useAtomSet, useAtomValue } from '@effect/atom-react/Hooks';\nimport * as Atom from 'effect/reactivity/Atom';\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 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)[]): RefCallback<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)[]): RefCallback<T> => {\n return useMemo(() => mergeRefs(refs), [...refs]);\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Ref, type RefCallback, useCallback } from 'react';\n\nimport { mergeRefs } from './useForwardedRef.ts';\n\nexport type PossibleRef<T> = Ref<T> | undefined;\n\n/**\n * Composes several refs into one callback ref.\n * Each ref receives the node; a callback ref that returns a cleanup keeps it (React 19).\n */\nexport const composeRefs = <T>(...refs: PossibleRef<T>[]): RefCallback<T> => mergeRefs(refs);\n\n/**\n * Memoised {@link composeRefs}; the callback identity changes only when a ref does.\n */\nexport const useComposedRefs = <T>(...refs: PossibleRef<T>[]): RefCallback<T> =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useCallback(composeRefs(...refs), refs);\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\nexport type UseControllableStateParams<T> = {\n prop?: T | undefined;\n defaultProp?: T | undefined;\n onChange?: (state: T) => void;\n};\n\nconst isUpdater = <T>(value: SetStateAction<T>): value is (prev: T) => T => typeof value === 'function';\n\n/**\n * State that is controlled when `prop` is supplied and uncontrolled (seeded from `defaultProp`) otherwise.\n * `onChange` fires for every change in either mode; in controlled mode the setter only reports, it never stores.\n */\nexport const useControllableState = <T>({\n prop,\n defaultProp,\n onChange,\n}: UseControllableStateParams<T>): readonly [T | undefined, Dispatch<SetStateAction<T | undefined>>] => {\n const [uncontrolledProp, setUncontrolledProp] = useState(defaultProp);\n const isControlled = prop !== undefined;\n const value = isControlled ? prop : uncontrolledProp;\n\n const onChangeRef = useRef(onChange);\n useEffect(() => {\n onChangeRef.current = onChange;\n });\n\n // Uncontrolled changes are reported after commit so an updater resolves through React's own\n // batching rather than a stale snapshot.\n const prevValueRef = useRef(uncontrolledProp);\n useEffect(() => {\n if (prevValueRef.current !== uncontrolledProp) {\n // An updater may resolve to `undefined` (clearing), which a consumer's `onChange` is declared\n // not to take; the cast preserves that contract without widening every consumer's signature.\n onChangeRef.current?.(uncontrolledProp as T);\n prevValueRef.current = uncontrolledProp;\n }\n }, [uncontrolledProp]);\n\n const setValue = useCallback<Dispatch<SetStateAction<T | undefined>>>(\n (nextValue) => {\n if (isControlled) {\n const next = isUpdater(nextValue) ? nextValue(prop) : nextValue;\n if (next !== prop) {\n // See the cast above.\n onChangeRef.current?.(next as T);\n }\n } else {\n setUncontrolledProp(nextValue);\n }\n },\n [isControlled, prop],\n );\n\n return [value, setValue] as const;\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 2023 DXOS.org\n//\n\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useDynamicRef } from './useDynamicRef.ts';\n\n/**\n * A stateful hook with a controlled value.\n * NOTE: Prefer `useControllableState` when the value has a controlled/uncontrolled split.\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 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\nimport { log } from '@dxos/log';\nimport { downloadBlob } from '@dxos/util';\n\n/**\n * Save a blob to disk.\n *\n * Goes through {@link downloadBlob}, so the download also works inside the Tauri webview, where\n * `<a download>` is silently dropped. Blob only: a URL would have to fall back to that anchor, and\n * a caller has no way to notice it did nothing.\n *\n * ```\n * const download = useFileDownload();\n * const handleDownload = (data: string) => {\n * download(new Blob([data], { type: 'text/plain' }), 'test.txt');\n * };\n * ```\n */\nexport const useFileDownload = (): ((data: Blob, filename: string) => void) => {\n return useMemo(\n () => (data: Blob, filename: string) => {\n void downloadBlob(data, filename).catch((err) => log.catch(err));\n },\n [],\n );\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 // Keyed on a stable string of the resolved queries (the array is rebuilt every render) so a\n // changed `query` re-seeds state and re-subscribes.\n const queryKey = queries.join('|');\n useEffect(() => {\n const mql = queries.map((query) => document.defaultView?.matchMedia(query));\n\n // Seed `media` from the MediaQueryList's own normalized string; change events carry the\n // normalized form, and a raw query that normalizes differently would never match in `handler`.\n setValue(\n mql.map((mql, index) => ({\n media: mql?.media ?? queries[index],\n matches: mql?.matches,\n })),\n );\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 }, [queryKey]);\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 2026 DXOS.org\n//\n\nimport { useRef } from 'react';\n\n/**\n * Holds the previous reference for as long as `equals` accepts the incoming value, so a value the\n * caller assembles inline keeps one identity across the caller's renders.\n *\n * A render React discards can leave the ref holding the discarded value, which costs identity\n * stability on the next render but never correctness.\n */\n// `NoInfer` keeps `T` coming from `value`: a comparator declared over `unknown` would widen it.\nexport const useStable = <T>(value: T, equals: (a: NoInfer<T>, b: NoInfer<T>) => boolean): T => {\n const ref = useRef(value);\n if (!equals(ref.current, value)) {\n ref.current = value;\n }\n return ref.current;\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"],"mappings":";;;;;;;;;;;;;AAQA,IAAa,wBACX,sBACA,iBACA,EAAE,2BAA2B,SAAS,CAAC,MACpC;CACH,QAAQ,UAAa;EACnB,uBAAuB,KAAK;EAC5B,IAAI,CAAC,4BAA4B,CAAC,MAAM,kBACtC,OAAO,kBAAkB,KAAK;CAElC;AACF;;;;;;;ACFA,IAAa,iBACX,mBACA,mBAC2G;CAC3G,MAAM,UAAU,gBAAiD,cAAc;CAE/E,MAAM,YAA6D,UAAU;EAC3E,MAAM,EAAE,UAAU,GAAG,YAAY;EAGjC,MAAM,QAAQ,cAAc,SAA6B,OAAO,OAAO,OAAO,CAAC;EAC/E,OAAO,cAAc,QAAQ,UAAU,EAAE,MAAM,GAAG,QAAQ;CAC5D;CAEA,SAAS,cAAc,GAAG,kBAAkB;CAE5C,MAAM,mBAAmB,iBAA2C;EAClE,MAAM,UAAU,WAAW,OAAO;EAClC,IAAI,SACF,OAAO;EAET,IAAI,mBAAmB,KAAA,GACrB,OAAO;EAET,MAAM,IAAI,MAAM,KAAK,aAAa,2BAA2B,kBAAkB,GAAG;CACpF;CAEA,OAAO,CAAC,UAAU,eAAe;AACnC;;;;;;;;AClCA,IAAa,kBACX,IACA,SACG;CACH,gBAAgB;EACd,MAAM,aAAa,IAAI,gBAAgB;EACvC,IAAI;EAEJ,MAAM,IAAI,WAAW,YAAY;GAC/B,IAAI,CAAC,WAAW,OAAO,SACrB,UAAU,MAAM,GAAG,UAAU;EAEjC,CAAC;EAED,aAAa;GACX,aAAa,CAAC;GACd,WAAW,MAAM;GACjB,UAAU;EACZ;CACF,GAAG,QAAQ,CAAC,CAAC;AACf;;;;;;;ACbA,IAAa,gBAAmB,iBAAkC;CAChE,MAAM,CAAC,QAAQ,eAAe,KAAK,KAAK,YAAY,CAAC;CACrD,MAAM,QAAQ,aA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,iBACrC,mBAAmB,IAAI;OAClB,KAAK,CAAC,kBAAkB,CAAC,iBAAiB,iBAC/C,mBAAmB,KAAK;EAG1B,cAAc,UAAU;CAC1B,GAAG;EAAC;EAAc;EAAW;EAAS;CAAe,CAAC;CAEtD,OAAO;AACT;;;;;;;AASA,IAAa,mBACX,cACA,WACA,SACA,aACG;CACH,MAAM,QAAQ,OAAO,KAAK;CAC1B,MAAM,kBAAkB,iBAAiB,cAAc,WAAW,OAAO;CAEzE,gBAAgB;EACd,MAAM,UAAU;CAClB,GAAG,CAAC,cAAc,KAAK,CAAC;CAExB,gBAAgB;EACd,IAAI,mBAAmB,CAAC,MAAM,SAAS;GACrC,SAAS;GACT,MAAM,UAAU;EAClB;CACF,GAAG;EAAC;EAAiB;EAAO;CAAQ,CAAC;AACvC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Runs the consumer's handler first and skips ours when it called `preventDefault()`.
3
+ * Zag's `mergeProps` always invokes both, so this stays for the parts that honour the skip.
4
+ */
5
+ export declare const composeEventHandlers: <E extends {
6
+ defaultPrevented: boolean;
7
+ }>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, { checkForDefaultPrevented }?: {
8
+ checkForDefaultPrevented?: boolean | undefined;
9
+ }) => (event: E) => void;
10
+ //# sourceMappingURL=composeEventHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composeEventHandlers.d.ts","sourceRoot":"","sources":["../../../src/composeEventHandlers.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS;IAAE,gBAAgB,EAAE,OAAO,CAAA;CAAE,yBACnD,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,oBACvB,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;;cAGrB,CAAC,SAMjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=composeEventHandlers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composeEventHandlers.test.d.ts","sourceRoot":"","sources":["../../../src/composeEventHandlers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { type FC, type ReactNode } from 'react';
2
+ /**
3
+ * A typed context whose provider takes the context fields as props.
4
+ * `useContext` throws a message naming the consumer and root when no provider is mounted and no default was given.
5
+ */
6
+ export declare const createContext: <ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType) => readonly [FC<ContextValueType & {
7
+ children?: ReactNode;
8
+ }>, (consumerName: string) => ContextValueType];
9
+ //# sourceMappingURL=createContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../../../src/createContext.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EAAE,EACP,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,gBAAgB,SAAS,MAAM,GAAG,IAAI,qBAC/C,MAAM,mBACR,gBAAgB,KAChC,SAAS,CAAC,EAAE,CAAC,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,gBAAgB,CAyBvG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=createContext.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContext.test.d.ts","sourceRoot":"","sources":["../../../src/createContext.test.tsx"],"names":[],"mappings":""}
@@ -1,21 +1,25 @@
1
- export { useComposedRefs } from '@radix-ui/react-compose-refs';
2
1
  export { useScroller, useSize } from 'mini-virtual-list';
3
- export * from './useAsyncEffect';
4
- export * from './useAtomState';
5
- export * from './useAsyncState';
6
- export * from './useControlledState';
7
- export * from './useDebugDeps';
8
- export * from './useDefaultValue';
9
- export * from './useDefaults';
10
- export * from './useDynamicRef';
11
- export * from './useFileDownload';
12
- export * from './useForwardedRef';
13
- export * from './useId';
14
- export * from './useIsFocused';
15
- export * from './useMediaQuery';
16
- export * from './useMulticastObservable';
17
- export * from './useRefCallback';
18
- export * from './useViewportResize';
19
- export * from './useTimeout';
20
- export * from './useTransitions';
2
+ export * from './composeEventHandlers.ts';
3
+ export * from './createContext.ts';
4
+ export * from './useAsyncEffect.ts';
5
+ export * from './useAtomState.ts';
6
+ export * from './useAsyncState.ts';
7
+ export * from './useComposedRefs.ts';
8
+ export * from './useControllableState.ts';
9
+ export * from './useControlledState.ts';
10
+ export * from './useDebugDeps.ts';
11
+ export * from './useDefaultValue.ts';
12
+ export * from './useDefaults.ts';
13
+ export * from './useDynamicRef.ts';
14
+ export * from './useFileDownload.ts';
15
+ export * from './useForwardedRef.ts';
16
+ export * from './useId.ts';
17
+ export * from './useIsFocused.ts';
18
+ export * from './useMediaQuery.ts';
19
+ export * from './useMulticastObservable.ts';
20
+ export * from './useRefCallback.ts';
21
+ export * from './useStable.ts';
22
+ export * from './useViewportResize.ts';
23
+ export * from './useTimeout.ts';
24
+ export * from './useTransitions.ts';
21
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEzD,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEzD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -1,4 +1,4 @@
1
- import * as Atom from 'effect/unstable/reactivity/Atom';
1
+ import * as Atom from 'effect/reactivity/Atom';
2
2
  export type AtomState<T> = {
3
3
  atom: Atom.Writable<T>;
4
4
  value: T;
@@ -1 +1 @@
1
- {"version":3,"file":"useAtomState.d.ts","sourceRoot":"","sources":["../../../src/useAtomState.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,iCAAiC,CAAC;AAGxD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,CAAC;IACT,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,gBAAgB,CAAC,KAAG,SAAS,CAAC,CAAC,CAK5D,CAAC"}
1
+ {"version":3,"file":"useAtomState.d.ts","sourceRoot":"","sources":["../../../src/useAtomState.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAG/C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,CAAC;IACT,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,gBAAgB,CAAC,KAAG,SAAS,CAAC,CAAC,CAK5D,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type Ref, type RefCallback } from 'react';
2
+ export type PossibleRef<T> = Ref<T> | undefined;
3
+ /**
4
+ * Composes several refs into one callback ref.
5
+ * Each ref receives the node; a callback ref that returns a cleanup keeps it (React 19).
6
+ */
7
+ export declare const composeRefs: <T>(...refs: PossibleRef<T>[]) => RefCallback<T>;
8
+ /**
9
+ * Memoised {@link composeRefs}; the callback identity changes only when a ref does.
10
+ */
11
+ export declare const useComposedRefs: <T>(...refs: PossibleRef<T>[]) => RefCallback<T>;
12
+ //# sourceMappingURL=useComposedRefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComposedRefs.d.ts","sourceRoot":"","sources":["../../../src/useComposedRefs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAAe,MAAM,OAAO,CAAC;AAIhE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,WAAW,WAAW,CAAC,CAAC,CAAC,EAAE,KAAG,WAAW,CAAC,CAAC,CAAoB,CAAC;AAE7F;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,WAAW,WAAW,CAAC,CAAC,CAAC,EAAE,KAAG,WAAW,CAAC,CAAC,CAEnC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useComposedRefs.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComposedRefs.test.d.ts","sourceRoot":"","sources":["../../../src/useComposedRefs.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
+ export type UseControllableStateParams<T> = {
3
+ prop?: T | undefined;
4
+ defaultProp?: T | undefined;
5
+ onChange?: (state: T) => void;
6
+ };
7
+ /**
8
+ * State that is controlled when `prop` is supplied and uncontrolled (seeded from `defaultProp`) otherwise.
9
+ * `onChange` fires for every change in either mode; in controlled mode the setter only reports, it never stores.
10
+ */
11
+ export declare const useControllableState: <T>({ prop, defaultProp, onChange, }: UseControllableStateParams<T>) => readonly [T | undefined, Dispatch<SetStateAction<T | undefined>>];
12
+ //# sourceMappingURL=useControllableState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../../../src/useControllableState.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAA4C,MAAM,OAAO,CAAC;AAErG,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI;IAC1C,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,oCAInC,0BAA0B,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAsClG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useControllableState.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useControllableState.test.d.ts","sourceRoot":"","sources":["../../../src/useControllableState.test.tsx"],"names":[],"mappings":""}
@@ -1,7 +1,7 @@
1
1
  import { type Dispatch, type SetStateAction } from 'react';
2
2
  /**
3
3
  * A stateful hook with a controlled value.
4
- * NOTE: Consider using Radix's `useControllableState`.
4
+ * NOTE: Prefer `useControllableState` when the value has a controlled/uncontrolled split.
5
5
  */
6
6
  export declare const useControlledState: <T>(valueProp: T, onChange?: (value: T) => void) => [T, Dispatch<SetStateAction<T>>];
7
7
  //# sourceMappingURL=useControlledState.d.ts.map
@@ -18,10 +18,10 @@ export declare function setRef<T>(ref: Ref<T> | undefined | null, value: T | nul
18
18
  * Merges multiple refs into a single ref callback.
19
19
  * Returns a ref callback that synchronizes all provided refs and handles cleanup.
20
20
  */
21
- export declare const mergeRefs: <T>(refs: (Ref<T> | undefined)[]) => Ref<T>;
21
+ export declare const mergeRefs: <T>(refs: (Ref<T> | undefined)[]) => RefCallback<T>;
22
22
  /**
23
23
  * Hook that merges multiple refs into a single stable ref callback.
24
24
  * The returned ref is memoized and only changes when the refs array changes.
25
25
  */
26
- export declare const useMergeRefs: <T>(refs: (Ref<T> | undefined)[]) => Ref<T>;
26
+ export declare const useMergeRefs: <T>(refs: (Ref<T> | undefined)[]) => RefCallback<T>;
27
27
  //# sourceMappingURL=useForwardedRef.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useForwardedRef.d.ts","sourceRoot":"","sources":["../../../src/useForwardedRef.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAA8B,MAAM,OAAO,CAAC;AAElG;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,gBAAgB,YAAY,CAAC,CAAC,CAAC,iCAO/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAMrG;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,KAAG,GAAG,CAAC,CAAC,CAchE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,KAAG,GAAG,CAAC,CAAC,CAEnE,CAAC"}
1
+ {"version":3,"file":"useForwardedRef.d.ts","sourceRoot":"","sources":["../../../src/useForwardedRef.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAA8B,MAAM,OAAO,CAAC;AAElG;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,gBAAgB,YAAY,CAAC,CAAC,CAAC,iCAO/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAMrG;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,KAAG,WAAW,CAAC,CAAC,CAcxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,KAAG,WAAW,CAAC,CAAC,CAE3E,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Holds the previous reference for as long as `equals` accepts the incoming value, so a value the
3
+ * caller assembles inline keeps one identity across the caller's renders.
4
+ *
5
+ * A render React discards can leave the ref holding the discarded value, which costs identity
6
+ * stability on the next render but never correctness.
7
+ */
8
+ export declare const useStable: <T>(value: T, equals: (a: NoInfer<T>, b: NoInfer<T>) => boolean) => T;
9
+ //# sourceMappingURL=useStable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStable.d.ts","sourceRoot":"","sources":["../../../src/useStable.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AAEH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,KAAG,CAM1F,CAAC"}