@huin-core/react-compose-refs 1.0.1 → 1.0.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 +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +20 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
|
3
|
+
type PossibleRef<T> = React.Ref<T> | undefined;
|
4
|
+
/**
|
5
|
+
* A utility to compose multiple refs together
|
6
|
+
* Accepts callback refs and RefObject(s)
|
7
|
+
*/
|
8
|
+
declare function composeRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
9
|
+
/**
|
10
|
+
* A custom hook that composes multiple refs
|
11
|
+
* Accepts callback refs and RefObject(s)
|
12
|
+
*/
|
13
|
+
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
14
|
+
|
15
|
+
export { composeRefs, useComposedRefs };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
|
3
|
+
type PossibleRef<T> = React.Ref<T> | undefined;
|
4
|
+
/**
|
5
|
+
* A utility to compose multiple refs together
|
6
|
+
* Accepts callback refs and RefObject(s)
|
7
|
+
*/
|
8
|
+
declare function composeRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
9
|
+
/**
|
10
|
+
* A custom hook that composes multiple refs
|
11
|
+
* Accepts callback refs and RefObject(s)
|
12
|
+
*/
|
13
|
+
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
14
|
+
|
15
|
+
export { composeRefs, useComposedRefs };
|
package/dist/index.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// packages/react/compose-refs/src/index.ts
|
31
|
+
var src_exports = {};
|
32
|
+
__export(src_exports, {
|
33
|
+
composeRefs: () => composeRefs,
|
34
|
+
useComposedRefs: () => useComposedRefs
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
37
|
+
|
38
|
+
// packages/react/compose-refs/src/composeRefs.tsx
|
39
|
+
var React = __toESM(require("react"));
|
40
|
+
function setRef(ref, value) {
|
41
|
+
if (typeof ref === "function") {
|
42
|
+
ref(value);
|
43
|
+
} else if (ref !== null && ref !== void 0) {
|
44
|
+
ref.current = value;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
function composeRefs(...refs) {
|
48
|
+
return (node) => refs.forEach((ref) => setRef(ref, node));
|
49
|
+
}
|
50
|
+
function useComposedRefs(...refs) {
|
51
|
+
return React.useCallback(composeRefs(...refs), refs);
|
52
|
+
}
|
53
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 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 ref(value);\n } else if (ref !== null && ref !== undefined) {\n (ref as React.MutableRefObject<T>).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: T) => refs.forEach((ref) => setRef(ref, node));\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>[]) {\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,QAAI,KAAK;AAAA,EACX,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,IAAC,IAAkC,UAAU;AAAA,EAC/C;AACF;AAMA,SAAS,eAAkB,MAAwB;AACjD,SAAO,CAAC,SAAY,KAAK,QAAQ,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC;AAC7D;AAMA,SAAS,mBAAsB,MAAwB;AAErD,SAAa,kBAAY,YAAY,GAAG,IAAI,GAAG,IAAI;AACrD;",
|
6
|
+
"names": []
|
7
|
+
}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
// packages/react/compose-refs/src/composeRefs.tsx
|
2
|
+
import * as React from "react";
|
3
|
+
function setRef(ref, value) {
|
4
|
+
if (typeof ref === "function") {
|
5
|
+
ref(value);
|
6
|
+
} else if (ref !== null && ref !== void 0) {
|
7
|
+
ref.current = value;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
function composeRefs(...refs) {
|
11
|
+
return (node) => refs.forEach((ref) => setRef(ref, node));
|
12
|
+
}
|
13
|
+
function useComposedRefs(...refs) {
|
14
|
+
return React.useCallback(composeRefs(...refs), refs);
|
15
|
+
}
|
16
|
+
export {
|
17
|
+
composeRefs,
|
18
|
+
useComposedRefs
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 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 ref(value);\n } else if (ref !== null && ref !== undefined) {\n (ref as React.MutableRefObject<T>).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: T) => refs.forEach((ref) => setRef(ref, node));\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>[]) {\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,QAAI,KAAK;AAAA,EACX,WAAW,QAAQ,QAAQ,QAAQ,QAAW;AAC5C,IAAC,IAAkC,UAAU;AAAA,EAC/C;AACF;AAMA,SAAS,eAAkB,MAAwB;AACjD,SAAO,CAAC,SAAY,KAAK,QAAQ,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC;AAC7D;AAMA,SAAS,mBAAsB,MAAwB;AAErD,SAAa,kBAAY,YAAY,GAAG,IAAI,GAAG,IAAI;AACrD;",
|
6
|
+
"names": []
|
7
|
+
}
|