@dxos/react-hooks 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +25 -14
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +25 -14
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useControlledState.d.ts +1 -0
- package/dist/types/src/useControlledState.d.ts.map +1 -1
- package/dist/types/src/useDynamicRef.d.ts +3 -3
- package/dist/types/src/useDynamicRef.d.ts.map +1 -1
- package/dist/types/src/useForwardedRef.d.ts +3 -3
- package/dist/types/src/useForwardedRef.d.ts.map +1 -1
- package/dist/types/src/useMediaQuery.d.ts.map +1 -1
- package/dist/types/src/useTransitions.d.ts +2 -1
- package/dist/types/src/useTransitions.d.ts.map +1 -1
- package/dist/types/src/useViewportResize.d.ts +3 -0
- package/dist/types/src/useViewportResize.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/src/index.ts +3 -1
- package/src/useControlledState.ts +1 -0
- package/src/useDynamicRef.ts +3 -3
- package/src/useForwardedRef.ts +17 -14
- package/src/useMediaQuery.ts +1 -2
- package/src/useTransitions.ts +3 -1
- package/src/{useResize.ts → useViewportResize.ts} +1 -1
- package/dist/types/src/useResize.d.ts +0 -3
- package/dist/types/src/useResize.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-hooks",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ae835ea",
|
|
4
4
|
"description": "React hooks supporting DXOS React primitives.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
"@preact-signals/safe-react": "^0.9.0",
|
|
29
29
|
"alea": "^1.0.1",
|
|
30
30
|
"lodash.defaultsdeep": "^4.6.1",
|
|
31
|
-
"
|
|
32
|
-
"@dxos/
|
|
31
|
+
"mini-virtual-list": "^0.3.2",
|
|
32
|
+
"@dxos/async": "0.8.4-main.ae835ea",
|
|
33
|
+
"@dxos/log": "0.8.4-main.ae835ea"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
36
|
-
"@types/react": "~19.2.
|
|
37
|
-
"@types/react-dom": "~19.2.
|
|
37
|
+
"@types/react": "~19.2.2",
|
|
38
|
+
"@types/react-dom": "~19.2.2",
|
|
38
39
|
"react": "~19.2.0",
|
|
39
40
|
"react-dom": "~19.2.0"
|
|
40
41
|
},
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,9 @@ export * from './useIsFocused';
|
|
|
16
16
|
export * from './useMediaQuery';
|
|
17
17
|
export * from './useMulticastObservable';
|
|
18
18
|
export * from './useRefCallback';
|
|
19
|
-
export * from './
|
|
19
|
+
export * from './useViewportResize';
|
|
20
20
|
export * from './useSignals';
|
|
21
21
|
export * from './useTimeout';
|
|
22
22
|
export * from './useTransitions';
|
|
23
|
+
|
|
24
|
+
export { useSize, useScroller } from 'mini-virtual-list';
|
|
@@ -7,6 +7,7 @@ import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
|
7
7
|
/**
|
|
8
8
|
* A stateful hook with a controlled value.
|
|
9
9
|
* NOTE: Be careful not to provide an inlinde default array.
|
|
10
|
+
* @deprecated Use Radix `useControllableState`.
|
|
10
11
|
*/
|
|
11
12
|
export const useControlledState = <T>(
|
|
12
13
|
controlledValue: T,
|
package/src/useDynamicRef.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { useCallback } from '@preact-signals/safe-react/react';
|
|
6
|
-
import { type Dispatch, type
|
|
6
|
+
import { type Dispatch, type RefObject, type SetStateAction, useEffect, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Like `useState` but with an additional dynamic value.
|
|
10
10
|
*/
|
|
11
|
-
export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T>>,
|
|
11
|
+
export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>] => {
|
|
12
12
|
const [value, setValue] = useState<T>(valueParam);
|
|
13
13
|
const valueRef = useRef<T>(valueParam);
|
|
14
14
|
const setter = useCallback<Dispatch<SetStateAction<T>>>((value) => {
|
|
@@ -29,7 +29,7 @@ export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T
|
|
|
29
29
|
/**
|
|
30
30
|
* Ref that is updated by a dependency.
|
|
31
31
|
*/
|
|
32
|
-
export const useDynamicRef = <T>(value: T):
|
|
32
|
+
export const useDynamicRef = <T>(value: T): RefObject<T> => {
|
|
33
33
|
const valueRef = useRef<T>(value);
|
|
34
34
|
useEffect(() => {
|
|
35
35
|
valueRef.current = value;
|
package/src/useForwardedRef.ts
CHANGED
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type ForwardedRef, useEffect, useRef } from 'react';
|
|
5
|
+
import { type ForwardedRef, type RefObject, useEffect, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Combines a possibly undefined forwarded ref with a locally defined ref.
|
|
9
|
-
* @deprecated Use `useComposedRefs` from @radix-ui/react-compose-refs
|
|
10
9
|
*/
|
|
11
|
-
export const useForwardedRef = <T>(ref: ForwardedRef<T>) => {
|
|
12
|
-
const innerRef = useRef<T>(null);
|
|
10
|
+
export const useForwardedRef = <T>(ref: ForwardedRef<T>): RefObject<T | null> => {
|
|
11
|
+
const innerRef = useRef<T | null>(null);
|
|
13
12
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (typeof ref === 'function') {
|
|
19
|
-
ref(innerRef.current);
|
|
20
|
-
} else {
|
|
21
|
-
ref.current = innerRef.current;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
13
|
+
updateRef(ref, innerRef.current);
|
|
14
|
+
}, [ref]);
|
|
24
15
|
|
|
25
16
|
return innerRef;
|
|
26
17
|
};
|
|
18
|
+
|
|
19
|
+
export const updateRef = <T>(ref: ForwardedRef<T>, value: T): void => {
|
|
20
|
+
if (!ref) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof ref === 'function') {
|
|
25
|
+
ref(value);
|
|
26
|
+
} else {
|
|
27
|
+
ref.current = value;
|
|
28
|
+
}
|
|
29
|
+
};
|
package/src/useMediaQuery.ts
CHANGED
|
@@ -29,8 +29,7 @@ const breakpointMediaQueries: Record<string, string> = {
|
|
|
29
29
|
* @see Docs https://chakra-ui.com/docs/hooks/use-media-query
|
|
30
30
|
*/
|
|
31
31
|
export const useMediaQuery = (query: string | string[], options: UseMediaQueryOptions = {}): boolean[] => {
|
|
32
|
-
|
|
33
|
-
const { ssr = true, fallback } = options;
|
|
32
|
+
const { ssr = false, fallback } = options;
|
|
34
33
|
|
|
35
34
|
const queries = (Array.isArray(query) ? query : [query]).map((query) =>
|
|
36
35
|
query in breakpointMediaQueries ? breakpointMediaQueries[query] : query,
|
package/src/useTransitions.ts
CHANGED
|
@@ -48,7 +48,9 @@ export const useDidTransition = <T>(
|
|
|
48
48
|
* Executes a callback function when a specified transition occurs in a value.
|
|
49
49
|
*
|
|
50
50
|
* This function utilizes the `useDidTransition` hook to monitor changes in `currentValue`.
|
|
51
|
-
* When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed.
|
|
51
|
+
* When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed.
|
|
52
|
+
*/
|
|
53
|
+
// TODO(wittjosiah): Seems overwrought.
|
|
52
54
|
export const useOnTransition = <T>(
|
|
53
55
|
currentValue: T,
|
|
54
56
|
fromValue: T | ((value: T) => boolean),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useResize.d.ts","sourceRoot":"","sources":["../../../src/useResize.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAW,MAAM,OAAO,CAAC;AAEjD,eAAO,MAAM,SAAS,GACpB,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAChC,OAAM,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAM,EAChD,QAAO,MAAY,SAiBpB,CAAC"}
|