@radix-ui/react-slot 0.1.1-rc.6 → 0.1.1

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- export interface SlotProps {
2
+ export interface SlotProps extends React.HTMLAttributes<HTMLElement> {
3
3
  children?: React.ReactNode;
4
4
  }
5
5
  export const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
@@ -1 +1 @@
1
- {"mappings":"A;AAOA;IACE,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFAyBJ,CAAC;AA+BH,OAAA,MAAM;cAAuC,MAAM,SAAS;iBAE3D,CAAC;AA8CF,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"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":"A;AAOA,0BAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3D,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFAyBJ,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"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e,n,t,r=require("@radix-ui/react-compose-refs").composeRefs,l=(e={},n=require("react"),Object.keys(n).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),e),o=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const c=/*#__PURE__*/l.forwardRef(((e,n)=>{const{children:t,...r}=e,c=l.Children.toArray(t);return c.some(i)?/*#__PURE__*/l.createElement(l.Fragment,null,c.map((e=>i(e)?/*#__PURE__*/l.createElement(s,o({},r,{ref:n}),e.props.children):e))):/*#__PURE__*/l.createElement(s,o({},r,{ref:n}),t)}));exports.Slot=c,c.displayName="Slot";const s=/*#__PURE__*/l.forwardRef(((e,n)=>{const{children:t,...o}=e;/*#__PURE__*/return l.isValidElement(t)?/*#__PURE__*/l.cloneElement(t,{...u(o,t.props),ref:r(n,t.ref)}):l.Children.count(t)>1?l.Children.only(null):null}));s.displayName="SlotClone";const a=({children:e})=>/*#__PURE__*/l.createElement(l.Fragment,null,e);function i(e){/*#__PURE__*/return l.isValidElement(e)&&e.type===a}function u(e,n){const t={...n};for(const r in n){const l=e[r],o=n[r];/^on[A-Z]/.test(r)?t[r]=f(o,l):"style"===r?t[r]={...l,...o}:"className"===r&&(t[r]=[l,o].filter(Boolean).join(" "))}return{...e,...t}}function f(e,n){return function(...t){null==e||e(...t);t[0]instanceof Event&&t[0].defaultPrevented||null==n||n(...t)}}exports.Slottable=a;const d=c;exports.Root=d;
1
+ var e,r,t,n=require("@radix-ui/react-compose-refs").composeRefs,l=(e={},r=require("react"),Object.keys(r).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e),o=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const s=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...n}=e,s=l.Children.toArray(t);return s.some(i)?/*#__PURE__*/l.createElement(l.Fragment,null,s.map((e=>i(e)?/*#__PURE__*/l.createElement(c,o({},n,{ref:r}),e.props.children):e))):/*#__PURE__*/l.createElement(c,o({},n,{ref:r}),t)}));exports.Slot=s,s.displayName="Slot";const c=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...o}=e;/*#__PURE__*/return l.isValidElement(t)?/*#__PURE__*/l.cloneElement(t,{...u(o,t.props),ref:n(r,t.ref)}):l.Children.count(t)>1?l.Children.only(null):null}));c.displayName="SlotClone";const a=({children:e})=>/*#__PURE__*/l.createElement(l.Fragment,null,e);function i(e){/*#__PURE__*/return l.isValidElement(e)&&e.type===a}function u(e,r){const t={...r};for(const n in r){const l=e[n],o=r[n];/^on[A-Z]/.test(n)?t[n]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===n?t[n]={...l,...o}:"className"===n&&(t[n]=[l,o].filter(Boolean).join(" "))}return{...e,...t}}exports.Slottable=a;const d=s;exports.Root=d;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,2DAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECUzC,MAAMU,eAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,qBAKPL,EAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,YAMxB,MAAMQ,EAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,EAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,GAK5B,SAASK,EAAgBI,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,wBAKvB,MAAMG,EAAO7C","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/slot/src/Slot.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\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] = composeHandlers(childPropValue, slotPropValue);\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\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","Slot","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$bd3c7a2329cce5affa12c89d44fd473$var$SlotClone","_babelRuntimeHelpersExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","composeHandlers","filter","Boolean","join","childHandler","slotHandler","args","Event","defaultPrevented","Root"],"version":3,"file":"index.js.map"}
1
+ {"mappings":"IAYgCA,EAAMC,EAZNC,2DAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECUzC,MAAMU,eAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,qBAKPL,EAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,YAMxB,MAAMQ,EAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,EAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,uBAG5B,MAAMS,EAAOxC","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/slot/src/Slot.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\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 childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\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":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","Slot","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$bd3c7a2329cce5affa12c89d44fd473$var$SlotClone","_babelRuntimeHelpersExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","Root"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,2 @@
1
- import{composeRefs as e}from"@radix-ui/react-compose-refs";import*as t from"react";import n from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:a,...c}=e,i=t.Children.toArray(a);return i.some(l)?/*#__PURE__*/t.createElement(t.Fragment,null,i.map((e=>l(e)?/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),e.props.children):e))):/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),a)}));Slot.displayName="Slot";const r=/*#__PURE__*/t.forwardRef(((n,r)=>{const{children:l,...a}=n;/*#__PURE__*/return t.isValidElement(l)?/*#__PURE__*/t.cloneElement(l,{...o(a,l.props),ref:e(r,l.ref)}):t.Children.count(l)>1?t.Children.only(null):null}));r.displayName="SlotClone";export const Slottable=({children:e})=>/*#__PURE__*/t.createElement(t.Fragment,null,e);function l(e){/*#__PURE__*/return t.isValidElement(e)&&e.type===Slottable}function o(e,t){const n={...t};for(const r in t){const l=e[r],o=t[r];/^on[A-Z]/.test(r)?n[r]=a(o,l):"style"===r?n[r]={...l,...o}:"className"===r&&(n[r]=[l,o].filter(Boolean).join(" "))}return{...e,...n}}function a(e,t){return function(...n){null==e||e(...n);n[0]instanceof Event&&n[0].defaultPrevented||null==t||t(...n)}}export const Root=Slot;
1
+ import{composeRefs as e}from"@radix-ui/react-compose-refs";import*as t from"react";import r from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:a,...s}=e,c=t.Children.toArray(a);return c.some(l)?/*#__PURE__*/t.createElement(t.Fragment,null,c.map((e=>l(e)?/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),e.props.children):e))):/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),a)}));Slot.displayName="Slot";const n=/*#__PURE__*/t.forwardRef(((r,n)=>{const{children:l,...a}=r;/*#__PURE__*/return t.isValidElement(l)?/*#__PURE__*/t.cloneElement(l,{...o(a,l.props),ref:e(n,l.ref)}):t.Children.count(l)>1?t.Children.only(null):null}));n.displayName="SlotClone";export const Slottable=({children:e})=>/*#__PURE__*/t.createElement(t.Fragment,null,e);function l(e){/*#__PURE__*/return t.isValidElement(e)&&e.type===Slottable}function o(e,t){const r={...t};for(const n in t){const l=e[n],o=t[n];/^on[A-Z]/.test(n)?r[n]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===n?r[n]={...l,...o}:"className"===n&&(r[n]=[l,o].filter(Boolean).join(" "))}return{...e,...r}}export const Root=Slot;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"4IAWA,MAAMA,kBAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,MAKPL,KAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,mBAMxB,MAAMQ,UAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,UAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,GAK5B,SAASK,EAAgBI,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,WAKvB,MAAMG,KAAO7C","sources":["./packages/react/slot/src/Slot.tsx"],"sourcesContent":["import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\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] = composeHandlers(childPropValue, slotPropValue);\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\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["Slot","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$d34e8c328cb3dd19ab7a2f6eafa6ad$var$SlotClone","_babelRuntimeHelpersEsmExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","composeHandlers","filter","Boolean","join","childHandler","slotHandler","args","Event","defaultPrevented","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"4IAWA,MAAMA,kBAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,MAKPL,KAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,mBAMxB,MAAMQ,UAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,UAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,UAG5B,MAAMS,KAAOxC","sources":["./packages/react/slot/src/Slot.tsx"],"sourcesContent":["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 childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\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","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$d34e8c328cb3dd19ab7a2f6eafa6ad$var$SlotClone","_babelRuntimeHelpersEsmExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","Root"],"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": "0.1.1-rc.6",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -29,6 +29,5 @@
29
29
  },
30
30
  "bugs": {
31
31
  "url": "https://github.com/radix-ui/primitives/issues"
32
- },
33
- "stableVersion": "0.1.0"
32
+ }
34
33
  }