@radix-ui/react-slot 0.1.3-rc.8 → 1.0.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.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -27
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +17 -13
- package/dist/index.module.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAOA,0BAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3D,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,
|
|
1
|
+
{"mappings":";AAOA,0BAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3D,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFAoCJ,CAAC;AA+BH,OAAA,MAAM;cAAuC,MAAM,SAAS;iBAE3D,CAAC;AAqCF,OAAA,MAAM,mFAAW,CAAC","sources":["packages/react/slot/src/packages/react/slot/src/Slot.tsx","packages/react/slot/src/packages/react/slot/src/index.ts","packages/react/slot/src/index.ts"],"sourcesContent":[null,null,"export {\n Slot,\n Slottable,\n //\n Root,\n} from './Slot';\nexport type { SlotProps } from './Slot';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -2,33 +2,16 @@ var $dAvBt$babelruntimehelpersextends = require("@babel/runtime/helpers/extends"
|
|
|
2
2
|
var $dAvBt$react = require("react");
|
|
3
3
|
var $dAvBt$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
|
|
4
4
|
|
|
5
|
-
function $parcel$
|
|
6
|
-
Object.
|
|
7
|
-
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(dest, key, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function get() {
|
|
14
|
-
return source[key];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return dest;
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
20
7
|
}
|
|
21
8
|
function $parcel$interopDefault(a) {
|
|
22
9
|
return a && a.__esModule ? a.default : a;
|
|
23
10
|
}
|
|
24
|
-
function $parcel$export(e, n, v, s) {
|
|
25
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
26
|
-
}
|
|
27
|
-
var $82dc8d030dec7549$exports = {};
|
|
28
11
|
|
|
29
|
-
$parcel$export(
|
|
30
|
-
$parcel$export(
|
|
31
|
-
$parcel$export(
|
|
12
|
+
$parcel$export(module.exports, "Slot", () => $82dc8d030dec7549$export$8c6ed5c666ac1360);
|
|
13
|
+
$parcel$export(module.exports, "Slottable", () => $82dc8d030dec7549$export$d9f1ccf0bdb05d45);
|
|
14
|
+
$parcel$export(module.exports, "Root", () => $82dc8d030dec7549$export$be92b6f5f03c0fe9);
|
|
32
15
|
|
|
33
16
|
|
|
34
17
|
|
|
@@ -36,11 +19,23 @@ $parcel$export($82dc8d030dec7549$exports, "Root", () => $82dc8d030dec7549$export
|
|
|
36
19
|
* Slot
|
|
37
20
|
* -----------------------------------------------------------------------------------------------*/ const $82dc8d030dec7549$export$8c6ed5c666ac1360 = /*#__PURE__*/ $dAvBt$react.forwardRef((props, forwardedRef)=>{
|
|
38
21
|
const { children: children , ...slotProps } = props;
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const childrenArray = $dAvBt$react.Children.toArray(children);
|
|
23
|
+
const slottable = childrenArray.find($82dc8d030dec7549$var$isSlottable);
|
|
24
|
+
if (slottable) {
|
|
25
|
+
// the new element to render is the one passed as a child of `Slottable`
|
|
26
|
+
const newElement = slottable.props.children;
|
|
27
|
+
const newChildren = childrenArray.map((child)=>{
|
|
28
|
+
if (child === slottable) {
|
|
29
|
+
// because the new element will be the one rendered, we are only interested
|
|
30
|
+
// in grabbing its children (`newElement.props.children`)
|
|
31
|
+
if ($dAvBt$react.Children.count(newElement) > 1) return $dAvBt$react.Children.only(null);
|
|
32
|
+
return /*#__PURE__*/ $dAvBt$react.isValidElement(newElement) ? newElement.props.children : null;
|
|
33
|
+
} else return child;
|
|
34
|
+
});
|
|
35
|
+
return /*#__PURE__*/ $dAvBt$react.createElement($82dc8d030dec7549$var$SlotClone, ($parcel$interopDefault($dAvBt$babelruntimehelpersextends))({}, slotProps, {
|
|
41
36
|
ref: forwardedRef
|
|
42
|
-
}),
|
|
43
|
-
}
|
|
37
|
+
}), /*#__PURE__*/ $dAvBt$react.isValidElement(newElement) ? /*#__PURE__*/ $dAvBt$react.cloneElement(newElement, undefined, newChildren) : null);
|
|
38
|
+
}
|
|
44
39
|
return /*#__PURE__*/ $dAvBt$react.createElement($82dc8d030dec7549$var$SlotClone, ($parcel$interopDefault($dAvBt$babelruntimehelpersextends))({}, slotProps, {
|
|
45
40
|
ref: forwardedRef
|
|
46
41
|
}), children);
|
|
@@ -95,7 +90,6 @@ function $82dc8d030dec7549$var$mergeProps(slotProps, childProps) {
|
|
|
95
90
|
const $82dc8d030dec7549$export$be92b6f5f03c0fe9 = $82dc8d030dec7549$export$8c6ed5c666ac1360;
|
|
96
91
|
|
|
97
92
|
|
|
98
|
-
$parcel$exportWildcard(module.exports, $82dc8d030dec7549$exports);
|
|
99
93
|
|
|
100
94
|
|
|
101
95
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;A;;;ACGA;;oGAEA,CAMA,MAAMA,yCAAI,GAAA,aAAGG,CAAAA,uBAAA,CAAyC,CAACG,KAAD,EAAQC,YAAR,GAAyB;IAC7E,MA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AMG,aAAa,GAAGxB,SAAS,CAACuB,QAAD,CAA/B,AAAA;QACA,MAAME,cAAc,GAAGJ,UAAU,CAACE,QAAD,CAAjC,AAAA;QAEA,MAAMG,SAAS,GAAG,WAAWC,IAAX,CAAgBJ,QAAhB,CAAlB,AAJiC,EAKjC,uEADA;QAEA,IAAIG,SAAJ,EACEJ,aAAa,CAACC,QAAD,CAAb,GAA0B,CAAIK,GAAAA,IAAJ,GAAwB;YAChDH,cAAc,KAAA,IAAd,IAAAA,cAAc,KAAA,KAAA,CAAd,IAAAA,cAAc,IAAMG,IAAN,CAAd,CAAAH;YACAD,aAAa,KAAA,IAAb,IAAAA,aAAa,KAAA,KAAA,CAAb,IAAAA,aAAa,IAAMI,IAAN,CAAb,CAAAJ;SAFF,CAGC;aAGE,IAAID,QAAQ,KAAK,OAAjB,EACHD,aAAa,CAACC,QAAD,CAAb,GAA0B;YAAE,GAAGC,aAAL;YAAoB,GAAGC,cAAH;SAA9C,CAA0B;aACrB,IAAIF,QAAQ,KAAK,WAAjB,EACLD,aAAa,CAACC,QAAD,CAAb,GAA0B;YAACC,aAAD;YAAgBC,cAAhB;SAAA,CAAgCI,MAAhC,CAAuCC,OAAvC,CAAA,CAAgDC,IAAhD,CAAqD,GAArD,CAA1B,CAAAT;KAEH;IAED,OAAO;QAAE,GAAGtB,SAAL;QAAgB,GAAGsB,aAAH;KAAvB,CAAO;CACR;AAED,MAAM7B,yCAAI,GAAGF,yCAAb,AAAA;;ADrHA","sources":["packages/react/slot/src/index.ts","packages/react/slot/src/Slot.tsx"],"sourcesContent":["export {\n Slot,\n Slottable,\n //\n Root,\n} from './Slot';\nexport type { SlotProps } from './Slot';\n","import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childrenArray = React.Children.toArray(children);\n const slottable = childrenArray.find(isSlottable);\n\n if (slottable) {\n // the new element to render is the one passed as a child of `Slottable`\n const newElement = slottable.props.children as React.ReactNode;\n\n const newChildren = childrenArray.map((child) => {\n if (child === slottable) {\n // because the new element will be the one rendered, we are only interested\n // in grabbing its children (`newElement.props.children`)\n if (React.Children.count(newElement) > 1) return React.Children.only(null);\n return React.isValidElement(newElement)\n ? (newElement.props.children as React.ReactNode)\n : null;\n } else {\n return child;\n }\n });\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {React.isValidElement(newElement)\n ? React.cloneElement(newElement, undefined, newChildren)\n : null}\n </SlotClone>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["Slot","Slottable","Root","React","composeRefs","forwardRef","props","forwardedRef","children","slotProps","childrenArray","Children","toArray","slottable","find","isSlottable","newElement","newChildren","map","child","count","only","isValidElement","cloneElement","undefined","displayName","SlotClone","mergeProps","ref","type","childProps","overrideProps","propName","slotPropValue","childPropValue","isHandler","test","args","filter","Boolean","join"],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import $9IrjX$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import {forwardRef as $9IrjX$forwardRef, Children as $9IrjX$Children,
|
|
2
|
+
import {forwardRef as $9IrjX$forwardRef, Children as $9IrjX$Children, isValidElement as $9IrjX$isValidElement, createElement as $9IrjX$createElement, cloneElement as $9IrjX$cloneElement, Fragment as $9IrjX$Fragment} from "react";
|
|
3
3
|
import {composeRefs as $9IrjX$composeRefs} from "@radix-ui/react-compose-refs";
|
|
4
4
|
|
|
5
|
-
function $parcel$export(e, n, v, s) {
|
|
6
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
-
}
|
|
8
|
-
var $5e63c961fc1ce211$exports = {};
|
|
9
|
-
|
|
10
|
-
$parcel$export($5e63c961fc1ce211$exports, "Slot", () => $5e63c961fc1ce211$export$8c6ed5c666ac1360);
|
|
11
|
-
$parcel$export($5e63c961fc1ce211$exports, "Slottable", () => $5e63c961fc1ce211$export$d9f1ccf0bdb05d45);
|
|
12
|
-
$parcel$export($5e63c961fc1ce211$exports, "Root", () => $5e63c961fc1ce211$export$be92b6f5f03c0fe9);
|
|
13
5
|
|
|
14
6
|
|
|
15
7
|
|
|
@@ -17,11 +9,23 @@ $parcel$export($5e63c961fc1ce211$exports, "Root", () => $5e63c961fc1ce211$export
|
|
|
17
9
|
* Slot
|
|
18
10
|
* -----------------------------------------------------------------------------------------------*/ const $5e63c961fc1ce211$export$8c6ed5c666ac1360 = /*#__PURE__*/ $9IrjX$forwardRef((props, forwardedRef)=>{
|
|
19
11
|
const { children: children , ...slotProps } = props;
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const childrenArray = $9IrjX$Children.toArray(children);
|
|
13
|
+
const slottable = childrenArray.find($5e63c961fc1ce211$var$isSlottable);
|
|
14
|
+
if (slottable) {
|
|
15
|
+
// the new element to render is the one passed as a child of `Slottable`
|
|
16
|
+
const newElement = slottable.props.children;
|
|
17
|
+
const newChildren = childrenArray.map((child)=>{
|
|
18
|
+
if (child === slottable) {
|
|
19
|
+
// because the new element will be the one rendered, we are only interested
|
|
20
|
+
// in grabbing its children (`newElement.props.children`)
|
|
21
|
+
if ($9IrjX$Children.count(newElement) > 1) return $9IrjX$Children.only(null);
|
|
22
|
+
return /*#__PURE__*/ $9IrjX$isValidElement(newElement) ? newElement.props.children : null;
|
|
23
|
+
} else return child;
|
|
24
|
+
});
|
|
25
|
+
return /*#__PURE__*/ $9IrjX$createElement($5e63c961fc1ce211$var$SlotClone, $9IrjX$babelruntimehelpersesmextends({}, slotProps, {
|
|
22
26
|
ref: forwardedRef
|
|
23
|
-
}),
|
|
24
|
-
}
|
|
27
|
+
}), /*#__PURE__*/ $9IrjX$isValidElement(newElement) ? /*#__PURE__*/ $9IrjX$cloneElement(newElement, undefined, newChildren) : null);
|
|
28
|
+
}
|
|
25
29
|
return /*#__PURE__*/ $9IrjX$createElement($5e63c961fc1ce211$var$SlotClone, $9IrjX$babelruntimehelpersesmextends({}, slotProps, {
|
|
26
30
|
ref: forwardedRef
|
|
27
31
|
}), children);
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;A;;;ACGA;;oGAEA,CAMA,MAAMA,yCAAI,GAAA,aAAGG,CAAAA,iBAAA,CAAyC,CAACG,KAAD,EAAQC,YAAR,GAAyB;IAC7E,MAAM,E,UAAEC,QAAF,CAAA,EAAY,GAAGC,SAAH,EAAZ,GAA6BH,KAAnC,AAAM;IACN,MAAMI,aAAa,GAAGP,eAAA,CAAeS,OAAf,CAAuBJ,QAAvB,CAAtB,AAAA;IACA,MAAMK,SAAS,GAAGH,aAAa,CAACI,IAAd,CAAmBC,iCAAnB,CAAlB,AAAA;IAEA,IAAIF,SAAJ,EAAe;QACb,wEAAA;QACA,MAAMG,UAAU,GAAGH,SAAS,CAACP,KAAV,CAAgBE,QAAnC,AAAA;QAEA,MAAMS,WAAW,GAAGP,aAAa,CAACQ,GAAd,CAAmBC,CAAAA,KAAD,GAAW;YAC/C,IAAIA,KAAK,KAAKN,SAAd,EAAyB;gBACvB,2EAAA;gBACA,yDAAA;gBACA,IAAIV,eAAA,CAAeiB,KAAf,CAAqBJ,UAArB,CAAA,GAAmC,CAAvC,EAA0C,OAAOb,eAAA,CAAekB,IAAf,CAAoB,IAApB,CAAP,CAA1C;gBACA,OAAO,aAAAlB,CAAAA,qBAAA,CAAqBa,UAArB,CAAA,GACFA,UAAU,CAACV,KAAX,CAAiBE,QADf,GAEH,IAFJ,CAAA;aAJF,MAQE,OAAOW,KAAP,CAAA;SATgB,CAApB,AAWC;QAED,OAAA,aACE,CAAA,oBAAA,CAAC,+BAAD,EAAA,oCAAA,CAAA,EAAA,EAAeV,SAAf,EADF;YAC4B,GAAG,EAAEF,YAAL;SAA1B,CAAA,EACG,aAAA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AAb,AAAA;;ADrHA","sources":["packages/react/slot/src/index.ts","packages/react/slot/src/Slot.tsx"],"sourcesContent":["export {\n Slot,\n Slottable,\n //\n Root,\n} from './Slot';\nexport type { SlotProps } from './Slot';\n","import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childrenArray = React.Children.toArray(children);\n const slottable = childrenArray.find(isSlottable);\n\n if (slottable) {\n // the new element to render is the one passed as a child of `Slottable`\n const newElement = slottable.props.children as React.ReactNode;\n\n const newChildren = childrenArray.map((child) => {\n if (child === slottable) {\n // because the new element will be the one rendered, we are only interested\n // in grabbing its children (`newElement.props.children`)\n if (React.Children.count(newElement) > 1) return React.Children.only(null);\n return React.isValidElement(newElement)\n ? (newElement.props.children as React.ReactNode)\n : null;\n } else {\n return child;\n }\n });\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {React.isValidElement(newElement)\n ? React.cloneElement(newElement, undefined, newChildren)\n : null}\n </SlotClone>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["Slot","Slottable","Root","React","composeRefs","forwardRef","props","forwardedRef","children","slotProps","childrenArray","Children","toArray","slottable","find","isSlottable","newElement","newChildren","map","child","count","only","isValidElement","cloneElement","undefined","displayName","SlotClone","mergeProps","ref","type","childProps","overrideProps","propName","slotPropValue","childPropValue","isHandler","test","args","filter","Boolean","join"],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-slot",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime": "^7.13.10",
|
|
20
|
-
"@radix-ui/react-compose-refs": "
|
|
20
|
+
"@radix-ui/react-compose-refs": "1.0.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": "^16.8 || ^17.0 || ^18.0"
|
|
@@ -29,6 +29,5 @@
|
|
|
29
29
|
},
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/radix-ui/primitives/issues"
|
|
32
|
-
}
|
|
33
|
-
"stableVersion": "0.1.2"
|
|
32
|
+
}
|
|
34
33
|
}
|