@radix-ui/react-compose-refs 1.1.1-rc.2 → 1.1.1-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -4
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +12 -4
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,11 +5,11 @@ type PossibleRef<T> = React.Ref<T> | undefined;
|
|
|
5
5
|
* A utility to compose multiple refs together
|
|
6
6
|
* Accepts callback refs and RefObject(s)
|
|
7
7
|
*/
|
|
8
|
-
declare function composeRefs<T>(...refs: PossibleRef<T>[]):
|
|
8
|
+
declare function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
9
9
|
/**
|
|
10
10
|
* A custom hook that composes multiple refs
|
|
11
11
|
* Accepts callback refs and RefObject(s)
|
|
12
12
|
*/
|
|
13
|
-
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]):
|
|
13
|
+
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
14
14
|
|
|
15
15
|
export { composeRefs, useComposedRefs };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ type PossibleRef<T> = React.Ref<T> | undefined;
|
|
|
5
5
|
* A utility to compose multiple refs together
|
|
6
6
|
* Accepts callback refs and RefObject(s)
|
|
7
7
|
*/
|
|
8
|
-
declare function composeRefs<T>(...refs: PossibleRef<T>[]):
|
|
8
|
+
declare function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
9
9
|
/**
|
|
10
10
|
* A custom hook that composes multiple refs
|
|
11
11
|
* Accepts callback refs and RefObject(s)
|
|
12
12
|
*/
|
|
13
|
-
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]):
|
|
13
|
+
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
14
14
|
|
|
15
15
|
export { composeRefs, useComposedRefs };
|
package/dist/index.js
CHANGED
|
@@ -46,16 +46,24 @@ function setRef(ref, value) {
|
|
|
46
46
|
}
|
|
47
47
|
function composeRefs(...refs) {
|
|
48
48
|
return (node) => {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
let hasCleanup = false;
|
|
50
|
+
const cleanups = refs.map((ref) => {
|
|
51
|
+
const cleanup = setRef(ref, node);
|
|
52
|
+
if (!hasCleanup && typeof cleanup == "function") {
|
|
53
|
+
hasCleanup = true;
|
|
54
|
+
}
|
|
55
|
+
return cleanup;
|
|
56
|
+
});
|
|
57
|
+
if (hasCleanup) {
|
|
51
58
|
return () => {
|
|
52
|
-
cleanups.
|
|
59
|
+
for (let i = 0; i < cleanups.length; i++) {
|
|
60
|
+
const cleanup = cleanups[i];
|
|
53
61
|
if (typeof cleanup == "function") {
|
|
54
62
|
cleanup();
|
|
55
63
|
} else {
|
|
56
64
|
setRef(refs[i], null);
|
|
57
65
|
}
|
|
58
|
-
}
|
|
66
|
+
}
|
|
59
67
|
};
|
|
60
68
|
}
|
|
61
69
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/composeRefs.tsx"],
|
|
4
|
-
"sourcesContent": ["export { composeRefs, useComposedRefs } from './composeRefs';\n", "import * as React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nfunction setRef<T>(ref: PossibleRef<T>, value: T) {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref !== null && ref !== undefined) {\n ref.current = value;\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n */\nfunction composeRefs<T>(...refs: PossibleRef<T>[]) {\n return (node
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AAQvB,SAAS,OAAU,KAAqB,OAAU;AAChD,MAAI,OAAO,QAAQ,YAAY;AAC7B,WAAO,IAAI,KAAK;AAAA,EAClB,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,QAAI,UAAU;AAAA,EAChB;AACF;AAMA,SAAS,eAAkB,
|
|
4
|
+
"sourcesContent": ["export { composeRefs, useComposedRefs } from './composeRefs';\n", "import * as React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nfunction setRef<T>(ref: PossibleRef<T>, value: T) {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref !== null && ref !== undefined) {\n ref.current = value;\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n */\nfunction composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {\n return (node) => {\n let hasCleanup = false;\n const cleanups = refs.map((ref) => {\n const cleanup = setRef(ref, node);\n if (!hasCleanup && typeof cleanup == 'function') {\n hasCleanup = true;\n }\n return cleanup;\n });\n\n // React <19 will log an error to the console if a callback ref returns a\n // value. We don't use ref cleanups internally so this will only happen if a\n // user's ref callback returns a value, which we only expect if they are\n // using the cleanup functionality added in React 19.\n if (hasCleanup) {\n return () => {\n for (let i = 0; i < cleanups.length; i++) {\n const cleanup = cleanups[i];\n if (typeof cleanup == 'function') {\n cleanup();\n } else {\n setRef(refs[i], null);\n }\n }\n };\n }\n };\n}\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n */\nfunction useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(composeRefs(...refs), refs);\n}\n\nexport { composeRefs, useComposedRefs };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AAQvB,SAAS,OAAU,KAAqB,OAAU;AAChD,MAAI,OAAO,QAAQ,YAAY;AAC7B,WAAO,IAAI,KAAK;AAAA,EAClB,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,QAAI,UAAU;AAAA,EAChB;AACF;AAMA,SAAS,eAAkB,MAA8C;AACvE,SAAO,CAAC,SAAS;AACf,QAAI,aAAa;AACjB,UAAM,WAAW,KAAK,IAAI,CAAC,QAAQ;AACjC,YAAM,UAAU,OAAO,KAAK,IAAI;AAChC,UAAI,CAAC,cAAc,OAAO,WAAW,YAAY;AAC/C,qBAAa;AAAA,MACf;AACA,aAAO;AAAA,IACT,CAAC;AAMD,QAAI,YAAY;AACd,aAAO,MAAM;AACX,iBAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,gBAAM,UAAU,SAAS,CAAC;AAC1B,cAAI,OAAO,WAAW,YAAY;AAChC,oBAAQ;AAAA,UACV,OAAO;AACL,mBAAO,KAAK,CAAC,GAAG,IAAI;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAMA,SAAS,mBAAsB,MAA8C;AAE3E,SAAa,kBAAY,YAAY,GAAG,IAAI,GAAG,IAAI;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -9,16 +9,24 @@ function setRef(ref, value) {
|
|
|
9
9
|
}
|
|
10
10
|
function composeRefs(...refs) {
|
|
11
11
|
return (node) => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let hasCleanup = false;
|
|
13
|
+
const cleanups = refs.map((ref) => {
|
|
14
|
+
const cleanup = setRef(ref, node);
|
|
15
|
+
if (!hasCleanup && typeof cleanup == "function") {
|
|
16
|
+
hasCleanup = true;
|
|
17
|
+
}
|
|
18
|
+
return cleanup;
|
|
19
|
+
});
|
|
20
|
+
if (hasCleanup) {
|
|
14
21
|
return () => {
|
|
15
|
-
cleanups.
|
|
22
|
+
for (let i = 0; i < cleanups.length; i++) {
|
|
23
|
+
const cleanup = cleanups[i];
|
|
16
24
|
if (typeof cleanup == "function") {
|
|
17
25
|
cleanup();
|
|
18
26
|
} else {
|
|
19
27
|
setRef(refs[i], null);
|
|
20
28
|
}
|
|
21
|
-
}
|
|
29
|
+
}
|
|
22
30
|
};
|
|
23
31
|
}
|
|
24
32
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/composeRefs.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nfunction setRef<T>(ref: PossibleRef<T>, value: T) {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref !== null && ref !== undefined) {\n ref.current = value;\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n */\nfunction composeRefs<T>(...refs: PossibleRef<T>[]) {\n return (node
|
|
5
|
-
"mappings": ";AAAA,YAAY,WAAW;AAQvB,SAAS,OAAU,KAAqB,OAAU;AAChD,MAAI,OAAO,QAAQ,YAAY;AAC7B,WAAO,IAAI,KAAK;AAAA,EAClB,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,QAAI,UAAU;AAAA,EAChB;AACF;AAMA,SAAS,eAAkB,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nfunction setRef<T>(ref: PossibleRef<T>, value: T) {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (ref !== null && ref !== undefined) {\n ref.current = value;\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n */\nfunction composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {\n return (node) => {\n let hasCleanup = false;\n const cleanups = refs.map((ref) => {\n const cleanup = setRef(ref, node);\n if (!hasCleanup && typeof cleanup == 'function') {\n hasCleanup = true;\n }\n return cleanup;\n });\n\n // React <19 will log an error to the console if a callback ref returns a\n // value. We don't use ref cleanups internally so this will only happen if a\n // user's ref callback returns a value, which we only expect if they are\n // using the cleanup functionality added in React 19.\n if (hasCleanup) {\n return () => {\n for (let i = 0; i < cleanups.length; i++) {\n const cleanup = cleanups[i];\n if (typeof cleanup == 'function') {\n cleanup();\n } else {\n setRef(refs[i], null);\n }\n }\n };\n }\n };\n}\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n */\nfunction useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(composeRefs(...refs), refs);\n}\n\nexport { composeRefs, useComposedRefs };\n"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,WAAW;AAQvB,SAAS,OAAU,KAAqB,OAAU;AAChD,MAAI,OAAO,QAAQ,YAAY;AAC7B,WAAO,IAAI,KAAK;AAAA,EAClB,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,QAAI,UAAU;AAAA,EAChB;AACF;AAMA,SAAS,eAAkB,MAA8C;AACvE,SAAO,CAAC,SAAS;AACf,QAAI,aAAa;AACjB,UAAM,WAAW,KAAK,IAAI,CAAC,QAAQ;AACjC,YAAM,UAAU,OAAO,KAAK,IAAI;AAChC,UAAI,CAAC,cAAc,OAAO,WAAW,YAAY;AAC/C,qBAAa;AAAA,MACf;AACA,aAAO;AAAA,IACT,CAAC;AAMD,QAAI,YAAY;AACd,aAAO,MAAM;AACX,iBAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,gBAAM,UAAU,SAAS,CAAC;AAC1B,cAAI,OAAO,WAAW,YAAY;AAChC,oBAAQ;AAAA,UACV,OAAO;AACL,mBAAO,KAAK,CAAC,GAAG,IAAI;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAMA,SAAS,mBAAsB,MAA8C;AAE3E,SAAa,kBAAY,YAAY,GAAG,IAAI,GAAG,IAAI;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|