🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@radix-ui/react-slot

Package Overview
Dependencies
Maintainers
4
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-slot - npm Package Compare versions

Comparing version
1.3.0
to
1.3.1
+14
-5
dist/index.d.mts
import * as React from 'react';
declare module 'react' {
interface ReactElement {
$$typeof?: symbol | string;
}
declare const mergeProps: <SlotProps extends AnyProps = AnyProps, ChildProps extends AnyProps = SlotProps, ReturnProps extends AnyProps = SlotProps & ChildProps>(slotProps: SlotProps, childProps: ChildProps) => ReturnProps;
interface MergePropsFunction<SlotProps extends AnyProps = UnknownProps, ChildProps extends AnyProps = SlotProps, ReturnProps extends AnyProps = SlotProps & ChildProps> {
(slotProps: SlotProps, childProps: ChildProps): ReturnProps;
}
type AnyProps = Record<string, any>;
type UnknownProps = Record<string, unknown>;
interface SlotProviderProps {
children: React.ReactNode;
mergeProps: MergePropsFunction<AnyProps, AnyProps, AnyProps>;
}
declare const SlotProvider: React.FC<SlotProviderProps>;
type SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {
children?: React.ReactNode;
mergeProps?: MergePropsFunction;
};

@@ -14,2 +22,3 @@ declare function createSlot<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>>(ownerName: string): React.ForwardRefExoticComponent<React.PropsWithoutRef<SlotProps<Elem, Props>> & React.RefAttributes<Elem>>;

children?: React.ReactNode;
mergeProps?: MergePropsFunction;
} & React.RefAttributes<HTMLElement>>;

@@ -30,2 +39,2 @@ type SlottableChildrenProps = {

export { Slot as Root, Slot, type SlotProps, Slottable, createSlot, createSlottable };
export { type MergePropsFunction, SlotProvider as Provider, Slot as Root, Slot, type SlotProps, SlotProvider, Slottable, createSlot, createSlottable, mergeProps };
import * as React from 'react';
declare module 'react' {
interface ReactElement {
$$typeof?: symbol | string;
}
declare const mergeProps: <SlotProps extends AnyProps = AnyProps, ChildProps extends AnyProps = SlotProps, ReturnProps extends AnyProps = SlotProps & ChildProps>(slotProps: SlotProps, childProps: ChildProps) => ReturnProps;
interface MergePropsFunction<SlotProps extends AnyProps = UnknownProps, ChildProps extends AnyProps = SlotProps, ReturnProps extends AnyProps = SlotProps & ChildProps> {
(slotProps: SlotProps, childProps: ChildProps): ReturnProps;
}
type AnyProps = Record<string, any>;
type UnknownProps = Record<string, unknown>;
interface SlotProviderProps {
children: React.ReactNode;
mergeProps: MergePropsFunction<AnyProps, AnyProps, AnyProps>;
}
declare const SlotProvider: React.FC<SlotProviderProps>;
type SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {
children?: React.ReactNode;
mergeProps?: MergePropsFunction;
};

@@ -14,2 +22,3 @@ declare function createSlot<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>>(ownerName: string): React.ForwardRefExoticComponent<React.PropsWithoutRef<SlotProps<Elem, Props>> & React.RefAttributes<Elem>>;

children?: React.ReactNode;
mergeProps?: MergePropsFunction;
} & React.RefAttributes<HTMLElement>>;

@@ -30,2 +39,2 @@ type SlottableChildrenProps = {

export { Slot as Root, Slot, type SlotProps, Slottable, createSlot, createSlottable };
export { type MergePropsFunction, SlotProvider as Provider, Slot as Root, Slot, type SlotProps, SlotProvider, Slottable, createSlot, createSlottable, mergeProps };

@@ -8,2 +8,3 @@ "use strict";

var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {

@@ -34,7 +35,10 @@ for (var name in all)

__export(index_exports, {
Provider: () => SlotProvider,
Root: () => Slot,
Slot: () => Slot,
SlotProvider: () => SlotProvider,
Slottable: () => Slottable,
createSlot: () => createSlot,
createSlottable: () => createSlottable
createSlottable: () => createSlottable,
mergeProps: () => mergeProps
});

@@ -46,6 +50,69 @@ module.exports = __toCommonJS(index_exports);

var import_react_compose_refs = require("@radix-ui/react-compose-refs");
// src/merge-props.ts
var import_is_development = require("@radix-ui/primitive/is-development");
var mergeProps = /* @__PURE__ */ __name(((slotProps, childProps) => {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
const slotIsFunction = typeof slotPropValue === "function";
const childIsFunction = typeof childPropValue === "function";
if (import_is_development.IS_DEVELOPMENT) {
if (!slotIsFunction || !childIsFunction) {
console.warn(
`Slot: Expected a function for ${propName}, but received ${[typeof slotPropValue, typeof childPropValue].filter((v) => v !== "function").join(" and ")}.`
);
}
}
overrideProps[propName] = (...args) => {
const result = childIsFunction ? childPropValue(...args) : void 0;
if (slotIsFunction) {
slotPropValue(...args);
}
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = {
...typeof slotPropValue === "object" ? slotPropValue : null,
...typeof childPropValue === "object" ? childPropValue : null
};
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
} else if (propName === "aria-describedby") {
overrideProps[propName] = concatAriaDescribedby(childPropValue, slotPropValue);
}
}
return { ...slotProps, ...overrideProps };
}), "mergeProps");
function concatAriaDescribedby(...values) {
const ids = /* @__PURE__ */ new Set();
for (const value of values) {
if (typeof value !== "string") continue;
for (const id of String(value).trim().split(/\s+/)) {
if (id) ids.add(id);
}
}
return ids.size > 0 ? Array.from(ids).join(" ") : void 0;
}
__name(concatAriaDescribedby, "concatAriaDescribedby");
// src/slot.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var SlotContext = React.createContext(mergeProps);
SlotContext.displayName = "SlotContext";
var SlotProvider = /* @__PURE__ */ __name(({ children, mergeProps: mergeProps2 }) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotContext.Provider, { value: mergeProps2, children });
}, "SlotProvider");
// @__NO_SIDE_EFFECTS__
function createSlot(ownerName) {
const Slot2 = React.forwardRef((props, forwardedRef) => {
let { children, ...slotProps } = props;
const context = React.useContext(SlotContext);
let { children, mergeProps: mergePropsProp = context, ...slotProps } = props;
let slottableElement = null;

@@ -92,3 +159,6 @@ let hasSlottable = false;

}
const mergedProps = mergeProps(slotProps, slottableElement.props ?? {});
const mergedProps = mergePropsProp(
slotProps,
slottableElement.props ?? {}
);
if (slottableElement.type !== React.Fragment) {

@@ -102,2 +172,3 @@ mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;

}
__name(createSlot, "createSlot");
var Slot = /* @__PURE__ */ createSlot("Slot");

@@ -107,3 +178,3 @@ var SLOTTABLE_IDENTIFIER = Symbol.for("radix.slottable");

function createSlottable(ownerName) {
const Slottable2 = (props) => "child" in props ? props.children(props.child) : props.children;
const Slottable2 = /* @__PURE__ */ __name((props) => "child" in props ? props.children(props.child) : props.children, "Slottable");
Slottable2.displayName = `${ownerName}.Slottable`;

@@ -113,4 +184,5 @@ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;

}
__name(createSlottable, "createSlottable");
var Slottable = /* @__PURE__ */ createSlottable("Slottable");
var getSlottableElementFromSlottable = (slottable, child) => {
var getSlottableElementFromSlottable = /* @__PURE__ */ __name((slottable, child) => {
if ("child" in slottable.props) {

@@ -122,27 +194,3 @@ const child2 = slottable.props.child;

return React.isValidElement(child) ? child : null;
};
function mergeProps(slotProps, childProps) {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
overrideProps[propName] = (...args) => {
const result = childPropValue(...args);
slotPropValue(...args);
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
}
}
return { ...slotProps, ...overrideProps };
}
}, "getSlottableElementFromSlottable");
function getElementRef(element) {

@@ -161,5 +209,7 @@ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;

}
__name(getElementRef, "getElementRef");
function isSlottable(child) {
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
}
__name(isSlottable, "isSlottable");
var REACT_LAZY_TYPE = Symbol.for("react.lazy");

@@ -169,12 +219,14 @@ function isLazyComponent(element) {

}
__name(isLazyComponent, "isLazyComponent");
function isPromiseLike(value) {
return typeof value === "object" && value !== null && "then" in value;
}
var createSlotError = (ownerName) => {
__name(isPromiseLike, "isPromiseLike");
var createSlotError = /* @__PURE__ */ __name((ownerName) => {
return `${ownerName} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`;
};
var createSlottableError = (ownerName) => {
}, "createSlotError");
var createSlottableError = /* @__PURE__ */ __name((ownerName) => {
return `${ownerName} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`;
};
}, "createSlottableError");
var use = React[" use ".trim().toString()];
//# sourceMappingURL=index.js.map
{
"version": 3,
"sources": ["../src/index.ts", "../src/slot.tsx"],
"sourcesContent": ["export {\n Slot,\n Slottable,\n //\n Root,\n createSlot,\n createSlottable,\n} from './slot';\nexport type { SlotProps } from './slot';\n", "import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\n\ndeclare module 'react' {\n interface ReactElement {\n $$typeof?: symbol | string;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type Usable<T> = PromiseLike<T> | React.Context<T>;\n\ntype SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {\n children?: React.ReactNode;\n};\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlot<\n Elem extends Element = HTMLElement,\n Props = React.HTMLAttributes<Elem>,\n>(ownerName: string) {\n const Slot = React.forwardRef<Elem, SlotProps<Elem, Props>>((props, forwardedRef) => {\n let { children, ...slotProps } = props;\n let slottableElement: React.ReactElement | null = null;\n let hasSlottable = false;\n const newChildren: React.ReactNode[] = [];\n\n if (isLazyComponent(children) && typeof use === 'function') {\n children = use(children._payload);\n }\n\n React.Children.forEach(children, (maybeSlottable) => {\n if (isSlottable(maybeSlottable)) {\n hasSlottable = true;\n const slottable = maybeSlottable;\n let child = 'child' in slottable.props ? slottable.props.child : slottable.props.children;\n\n if (isLazyComponent(child) && typeof use === 'function') {\n child = use(child._payload);\n }\n\n slottableElement = getSlottableElementFromSlottable(slottable, child);\n newChildren.push((slottableElement?.props as any)?.children);\n } else {\n newChildren.push(maybeSlottable);\n }\n });\n\n if (slottableElement) {\n slottableElement = React.cloneElement(slottableElement, undefined, newChildren);\n } else if (\n // A `Slottable` was found but it didn't resolve to a single element (e.g.\n // it wrapped multiple elements, text, or a render-prop `child` that\n // wasn't an element). Don't fall back to treating the `Slottable` wrapper\n // itself as the slot target \u2014 throw a descriptive error below instead.\n !hasSlottable &&\n React.Children.count(children) === 1 &&\n React.isValidElement(children)\n ) {\n slottableElement = children;\n }\n\n const slottableElementRef = slottableElement ? getElementRef(slottableElement) : undefined;\n const composedRef = useComposedRefs(forwardedRef, slottableElementRef);\n\n if (!slottableElement) {\n // Empty/falsy children (`null`, `undefined`, `false`, no children, etc.) are valid and\n // render nothing. Anything else is content we couldn't slot onto a single element, which\n // is a usage error, so we fail loudly with a clear message.\n if (children || children === 0) {\n throw new Error(\n hasSlottable ? createSlottableError(ownerName) : createSlotError(ownerName),\n );\n }\n return children;\n }\n\n const mergedProps = mergeProps(slotProps, slottableElement.props ?? {});\n\n // do not pass ref to React.Fragment for React 19 compatibility\n if (slottableElement.type !== React.Fragment) {\n mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;\n }\n\n return React.cloneElement(slottableElement, mergedProps);\n });\n\n Slot.displayName = `${ownerName}.Slot`;\n return Slot;\n}\n\nconst Slot = createSlot('Slot');\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst SLOTTABLE_IDENTIFIER = Symbol.for('radix.slottable');\n\ntype SlottableChildrenProps = { children: React.ReactNode };\ntype SlottableRenderFnProps = {\n child: React.ReactNode;\n children: (slottable: React.ReactNode) => React.ReactNode;\n};\n\ntype SlottableProps = SlottableRenderFnProps | SlottableChildrenProps;\ninterface SlottableComponent extends React.FC<SlottableProps> {\n __radixId: symbol;\n}\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlottable(ownerName: string) {\n const Slottable: SlottableComponent = (props) =>\n 'child' in props ? props.children(props.child) : props.children;\n\n Slottable.displayName = `${ownerName}.Slottable`;\n Slottable.__radixId = SLOTTABLE_IDENTIFIER;\n return Slottable;\n}\n\nconst Slottable = createSlottable('Slottable');\n\n/* -------------------------------------------------------------------------------------------------\n * getSlottableElementFromSlottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst getSlottableElementFromSlottable = (slottable: SlottableElement, child: React.ReactNode) => {\n if ('child' in slottable.props) {\n const child = slottable.props.child;\n if (!React.isValidElement<React.PropsWithChildren>(child)) return null;\n return React.cloneElement(child, undefined, slottable.props.children(child.props.children));\n }\n\n return React.isValidElement(child) ? child : null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * mergeProps\n * -----------------------------------------------------------------------------------------------*/\n\ntype AnyProps = Record<string, any>;\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 (isHandler) {\n // if the handler exists on both, we compose them\n if (slotPropValue && childPropValue) {\n overrideProps[propName] = (...args: unknown[]) => {\n const result = childPropValue(...args);\n slotPropValue(...args);\n return result;\n };\n }\n // but if it exists only on the slot, we use only this one\n else if (slotPropValue) {\n overrideProps[propName] = slotPropValue;\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\n/* -------------------------------------------------------------------------------------------------\n * getElementRef\n * -----------------------------------------------------------------------------------------------*/\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element.props as { ref?: React.Ref<unknown> }).ref;\n }\n\n // Not DEV\n return (element.props as { ref?: React.Ref<unknown> }).ref || (element as any).ref;\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype SlottableElement = React.ReactElement<SlottableProps, SlottableComponent>;\n\nfunction isSlottable(\n child: React.ReactNode,\n): child is React.ReactElement<SlottableProps, typeof Slottable> {\n return (\n React.isValidElement(child) &&\n typeof child.type === 'function' &&\n '__radixId' in child.type &&\n child.type.__radixId === SLOTTABLE_IDENTIFIER\n );\n}\n\nconst REACT_LAZY_TYPE = Symbol.for('react.lazy');\n\ninterface LazyReactElement extends React.ReactElement {\n $$typeof: typeof REACT_LAZY_TYPE;\n _payload: PromiseLike<Exclude<React.ReactNode, PromiseLike<any>>>;\n}\n\nfunction isLazyComponent(element: React.ReactNode): element is LazyReactElement {\n return (\n element != null &&\n typeof element === 'object' &&\n '$$typeof' in element &&\n element.$$typeof === REACT_LAZY_TYPE &&\n '_payload' in element &&\n isPromiseLike(element._payload)\n );\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return typeof value === 'object' && value !== null && 'then' in value;\n}\n\nconst createSlotError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its children. Expected a single React element child or \\`Slottable\\`.`;\n};\n\nconst createSlottableError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its \\`Slottable\\`. Expected \\`Slottable\\` to receive a single React element child.`;\n};\n\nconst use: typeof React.use | undefined = (React as any)[' use '.trim().toString()];\n\nexport {\n Slot,\n Slottable,\n //\n Slot as Root,\n};\nexport type { SlotProps };\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,gCAAgC;AAAA;AAkBE,SAAS,WAGzC,WAAmB;AACnB,QAAMA,QAAa,iBAAyC,CAAC,OAAO,iBAAiB;AACnF,QAAI,EAAE,UAAU,GAAG,UAAU,IAAI;AACjC,QAAI,mBAA8C;AAClD,QAAI,eAAe;AACnB,UAAM,cAAiC,CAAC;AAExC,QAAI,gBAAgB,QAAQ,KAAK,OAAO,QAAQ,YAAY;AAC1D,iBAAW,IAAI,SAAS,QAAQ;AAAA,IAClC;AAEA,IAAM,eAAS,QAAQ,UAAU,CAAC,mBAAmB;AACnD,UAAI,YAAY,cAAc,GAAG;AAC/B,uBAAe;AACf,cAAM,YAAY;AAClB,YAAI,QAAQ,WAAW,UAAU,QAAQ,UAAU,MAAM,QAAQ,UAAU,MAAM;AAEjF,YAAI,gBAAgB,KAAK,KAAK,OAAO,QAAQ,YAAY;AACvD,kBAAQ,IAAI,MAAM,QAAQ;AAAA,QAC5B;AAEA,2BAAmB,iCAAiC,WAAW,KAAK;AACpE,oBAAY,KAAM,kBAAkB,OAAe,QAAQ;AAAA,MAC7D,OAAO;AACL,oBAAY,KAAK,cAAc;AAAA,MACjC;AAAA,IACF,CAAC;AAED,QAAI,kBAAkB;AACp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M,KAAK,cAAc;AAE7B;AAEA,IAAM,kBAAkB,OAAO,IAAI,YAAY;AAO/C,SAAS,gBAAgB,SAAuD;AAC9E,SACE,WAAW,QACX,OAAO,YAAY,YACnB,cAAc,WACd,QAAQ,aAAa,mBACrB,cAAc,WACd,cAAc,QAAQ,QAAQ;AAElC;AAEA,SAAS,cAAc,OAA+C;AACpE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AAClE;AAEA,IAAM,kBAAkB,CAAC,cAAsB;AAC7C,SAAO,GAAG,SAAS;AACrB;AAEA,IAAM,uBAAuB,CAAC,cAAsB;AAClD,SAAO,GAAG,SAAS;AACrB;AAEA,IAAM,MAAqC,MAAc,QAAQ,KAAK,EAAE,SAAS,CAAC;",
"names": ["Slot", "Slottable", "child"]
"sources": ["../src/index.ts", "../src/slot.tsx", "../src/merge-props.ts"],
"sourcesContent": ["export {\n Slot,\n Slottable,\n SlotProvider,\n //\n Root,\n Provider,\n //\n createSlot,\n createSlottable,\n //\n mergeProps,\n} from './slot';\nexport type { SlotProps, MergePropsFunction } from './slot';\n", "import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport type { AnyProps, MergePropsFunction } from './merge-props';\nimport { mergeProps } from './merge-props';\n\ndeclare module 'react' {\n interface ReactElement {\n $$typeof?: symbol | string;\n }\n}\n\ntype SlotContextValue = MergePropsFunction;\n\nconst SlotContext = React.createContext<SlotContextValue>(mergeProps);\nSlotContext.displayName = 'SlotContext';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProviderProps {\n children: React.ReactNode;\n mergeProps: MergePropsFunction<AnyProps, AnyProps, AnyProps>;\n}\n\nconst SlotProvider: React.FC<SlotProviderProps> = ({ children, mergeProps }) => {\n return <SlotContext.Provider value={mergeProps}>{children}</SlotContext.Provider>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type Usable<T> = PromiseLike<T> | React.Context<T>;\n\ntype SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {\n children?: React.ReactNode;\n mergeProps?: MergePropsFunction;\n};\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlot<\n Elem extends Element = HTMLElement,\n Props = React.HTMLAttributes<Elem>,\n>(ownerName: string) {\n const Slot = React.forwardRef<Elem, SlotProps<Elem, Props>>((props, forwardedRef) => {\n const context = React.useContext(SlotContext);\n let { children, mergeProps: mergePropsProp = context, ...slotProps } = props;\n let slottableElement: React.ReactElement | null = null;\n let hasSlottable = false;\n const newChildren: React.ReactNode[] = [];\n\n if (isLazyComponent(children) && typeof use === 'function') {\n children = use(children._payload);\n }\n\n React.Children.forEach(children, (maybeSlottable) => {\n if (isSlottable(maybeSlottable)) {\n hasSlottable = true;\n const slottable = maybeSlottable;\n let child = 'child' in slottable.props ? slottable.props.child : slottable.props.children;\n\n if (isLazyComponent(child) && typeof use === 'function') {\n child = use(child._payload);\n }\n\n slottableElement = getSlottableElementFromSlottable(slottable, child);\n newChildren.push((slottableElement?.props as any)?.children);\n } else {\n newChildren.push(maybeSlottable);\n }\n });\n\n if (slottableElement) {\n slottableElement = React.cloneElement(slottableElement, undefined, newChildren);\n } else if (\n // A `Slottable` was found but it didn't resolve to a single element (e.g.\n // it wrapped multiple elements, text, or a render-prop `child` that\n // wasn't an element). Don't fall back to treating the `Slottable` wrapper\n // itself as the slot target \u2014 throw a descriptive error below instead.\n !hasSlottable &&\n React.Children.count(children) === 1 &&\n React.isValidElement(children)\n ) {\n slottableElement = children;\n }\n\n const slottableElementRef = slottableElement ? getElementRef(slottableElement) : undefined;\n const composedRef = useComposedRefs(forwardedRef, slottableElementRef);\n\n if (!slottableElement) {\n // Empty/falsy children (`null`, `undefined`, `false`, no children, etc.)\n // are valid and render nothing. Anything else is content we couldn't slot\n // onto a single element, which is a usage error, so we fail loudly with a\n // clear message.\n if (children || children === 0) {\n throw new Error(\n hasSlottable ? createSlottableError(ownerName) : createSlotError(ownerName),\n );\n }\n return children;\n }\n\n const mergedProps = mergePropsProp(\n slotProps,\n (slottableElement.props ?? {}) as Record<string, unknown>,\n );\n\n // do not pass ref to React.Fragment for React 19 compatibility\n if (slottableElement.type !== React.Fragment) {\n mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;\n }\n\n return React.cloneElement(slottableElement, mergedProps);\n });\n\n Slot.displayName = `${ownerName}.Slot`;\n return Slot;\n}\n\nconst Slot = createSlot('Slot');\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst SLOTTABLE_IDENTIFIER = Symbol.for('radix.slottable');\n\ntype SlottableChildrenProps = { children: React.ReactNode };\ntype SlottableRenderFnProps = {\n child: React.ReactNode;\n children: (slottable: React.ReactNode) => React.ReactNode;\n};\n\ntype SlottableProps = SlottableRenderFnProps | SlottableChildrenProps;\ninterface SlottableComponent extends React.FC<SlottableProps> {\n __radixId: symbol;\n}\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlottable(ownerName: string) {\n const Slottable: SlottableComponent = (props) =>\n 'child' in props ? props.children(props.child) : props.children;\n\n Slottable.displayName = `${ownerName}.Slottable`;\n Slottable.__radixId = SLOTTABLE_IDENTIFIER;\n return Slottable;\n}\n\nconst Slottable = createSlottable('Slottable');\n\n/* -------------------------------------------------------------------------------------------------\n * getSlottableElementFromSlottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst getSlottableElementFromSlottable = (slottable: SlottableElement, child: React.ReactNode) => {\n if ('child' in slottable.props) {\n const child = slottable.props.child;\n if (!React.isValidElement<React.PropsWithChildren>(child)) return null;\n return React.cloneElement(child, undefined, slottable.props.children(child.props.children));\n }\n\n return React.isValidElement(child) ? child : null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * getElementRef\n * -----------------------------------------------------------------------------------------------*/\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element.props as { ref?: React.Ref<unknown> }).ref;\n }\n\n // Not DEV\n return (element.props as { ref?: React.Ref<unknown> }).ref || (element as any).ref;\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype SlottableElement = React.ReactElement<SlottableProps, SlottableComponent>;\n\nfunction isSlottable(\n child: React.ReactNode,\n): child is React.ReactElement<SlottableProps, typeof Slottable> {\n return (\n React.isValidElement(child) &&\n typeof child.type === 'function' &&\n '__radixId' in child.type &&\n child.type.__radixId === SLOTTABLE_IDENTIFIER\n );\n}\n\nconst REACT_LAZY_TYPE = Symbol.for('react.lazy');\n\ninterface LazyReactElement extends React.ReactElement {\n $$typeof: typeof REACT_LAZY_TYPE;\n _payload: PromiseLike<Exclude<React.ReactNode, PromiseLike<any>>>;\n}\n\nfunction isLazyComponent(element: React.ReactNode): element is LazyReactElement {\n return (\n element != null &&\n typeof element === 'object' &&\n '$$typeof' in element &&\n element.$$typeof === REACT_LAZY_TYPE &&\n '_payload' in element &&\n isPromiseLike(element._payload)\n );\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return typeof value === 'object' && value !== null && 'then' in value;\n}\n\nconst createSlotError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its children. Expected a single React element child or \\`Slottable\\`.`;\n};\n\nconst createSlottableError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its \\`Slottable\\`. Expected \\`Slottable\\` to receive a single React element child.`;\n};\n\nconst use: typeof React.use | undefined = (React as any)[' use '.trim().toString()];\n\nexport {\n Slot,\n Slottable,\n SlotProvider,\n //\n Slot as Root,\n SlotProvider as Provider,\n //\n mergeProps,\n};\nexport type { SlotProps };\nexport type { MergePropsFunction } from './merge-props';\n", "import { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\n\nconst mergeProps = (<\n SlotProps extends AnyProps = AnyProps,\n ChildProps extends AnyProps = SlotProps,\n ReturnProps extends AnyProps = SlotProps & ChildProps,\n>(\n slotProps: SlotProps,\n childProps: ChildProps,\n): ReturnProps => {\n const overrideProps = { ...childProps };\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 (isHandler) {\n // if the handler exists on both, we compose them\n if (slotPropValue && childPropValue) {\n const slotIsFunction = typeof slotPropValue === 'function';\n const childIsFunction = typeof childPropValue === 'function';\n if (IS_DEVELOPMENT) {\n if (!slotIsFunction || !childIsFunction) {\n console.warn(\n `Slot: Expected a function for ${propName}, but received ${[typeof slotPropValue, typeof childPropValue].filter((v) => v !== 'function').join(' and ')}.`,\n );\n }\n }\n\n // @ts-expect-error - we don't know the type of the function. This\n // technically makes the return signature a lie, not sure if it's worth\n // handling.\n overrideProps[propName] = (...args: unknown[]) => {\n const result = childIsFunction ? childPropValue(...args) : undefined;\n if (slotIsFunction) {\n slotPropValue(...args);\n }\n return result;\n };\n }\n // but if it exists only on the slot, we use only this one\n else if (slotPropValue) {\n overrideProps[propName] = slotPropValue;\n }\n }\n\n // if it's `style`, we merge them\n else if (propName === 'style') {\n (overrideProps as any)[propName] = {\n ...(typeof slotPropValue === 'object' ? slotPropValue : null),\n ...(typeof childPropValue === 'object' ? childPropValue : null),\n };\n } else if (propName === 'className') {\n (overrideProps as any)[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n } else if (propName === 'aria-describedby') {\n (overrideProps as any)[propName] = concatAriaDescribedby(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps } as ReturnProps;\n}) satisfies MergePropsFunction;\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\ninterface MergePropsFunction<\n SlotProps extends AnyProps = UnknownProps,\n ChildProps extends AnyProps = SlotProps,\n ReturnProps extends AnyProps = SlotProps & ChildProps,\n> {\n (slotProps: SlotProps, childProps: ChildProps): ReturnProps;\n}\n\ntype AnyProps = Record<string, any>;\ntype UnknownProps = Record<string, unknown>;\n\nexport { mergeProps };\nexport type { MergePropsFunction, AnyProps, UnknownProps };\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,gCAAgC;;;ACDhC,4BAA+B;AAE/B,IAAM,aAAc,yBAKlB,WACA,eACgB;AAChB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,aAAW,YAAY,YAAY;AACjC,UAAM,gBAAgB,UAAU,QAAQ;AACxC,UAAM,iBAAiB,WAAW,QAAQ;AAE1C,UAAM,YAAY,WAAW,KAAK,QAAQ;AAC1C,QAAI,WAAW;AAEb,UAAI,iBAAiB,gBAAgB;AACnC,cAAM,iBAAiB,OAAO,kBAAkB;AAChD,cAAM,kBAAkB,OAAO,mBAAmB;AAClD,YAAI,sCAAgB;AAClB,cAAI,CAAC,kBAAkB,CAAC,iBAAiB;AACvC,oBAAQ;AAAA,cACN,iCAAiC,QAAQ,kBAAkB,CAAC,OAAO,eAAe,OAAO,cAAc,EAAE,OAAO,CAAC,MAAM,MAAM,UAAU,EAAE,KAAK,OAAO,CAAC;AAAA,YACxJ;AA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Q,MAAuC,OAAQ,QAAgB;AACjF;AAjBS;AAuBT,SAAS,YACP,OAC+D;AAC/D,SACQ,qBAAe,KAAK,KAC1B,OAAO,MAAM,SAAS,cACtB,eAAe,MAAM,QACrB,MAAM,KAAK,cAAc;AAE7B;AATS;AAWT,IAAM,kBAAkB,OAAO,IAAI,YAAY;AAO/C,SAAS,gBAAgB,SAAuD;AAC9E,SACE,WAAW,QACX,OAAO,YAAY,YACnB,cAAc,WACd,QAAQ,aAAa,mBACrB,cAAc,WACd,cAAc,QAAQ,QAAQ;AAElC;AATS;AAWT,SAAS,cAAc,OAA+C;AACpE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AAClE;AAFS;AAIT,IAAM,kBAAkB,wBAAC,cAAsB;AAC7C,SAAO,GAAG,SAAS;AACrB,GAFwB;AAIxB,IAAM,uBAAuB,wBAAC,cAAsB;AAClD,SAAO,GAAG,SAAS;AACrB,GAF6B;AAI7B,IAAM,MAAqC,MAAc,QAAQ,KAAK,EAAE,SAAS,CAAC;",
"names": ["mergeProps", "Slot", "Slottable", "child"]
}

@@ -0,8 +1,74 @@

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/slot.tsx
import * as React from "react";
import { useComposedRefs } from "@radix-ui/react-compose-refs";
// src/merge-props.ts
import { IS_DEVELOPMENT } from "@radix-ui/primitive/is-development";
var mergeProps = /* @__PURE__ */ __name(((slotProps, childProps) => {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
const slotIsFunction = typeof slotPropValue === "function";
const childIsFunction = typeof childPropValue === "function";
if (IS_DEVELOPMENT) {
if (!slotIsFunction || !childIsFunction) {
console.warn(
`Slot: Expected a function for ${propName}, but received ${[typeof slotPropValue, typeof childPropValue].filter((v) => v !== "function").join(" and ")}.`
);
}
}
overrideProps[propName] = (...args) => {
const result = childIsFunction ? childPropValue(...args) : void 0;
if (slotIsFunction) {
slotPropValue(...args);
}
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = {
...typeof slotPropValue === "object" ? slotPropValue : null,
...typeof childPropValue === "object" ? childPropValue : null
};
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
} else if (propName === "aria-describedby") {
overrideProps[propName] = concatAriaDescribedby(childPropValue, slotPropValue);
}
}
return { ...slotProps, ...overrideProps };
}), "mergeProps");
function concatAriaDescribedby(...values) {
const ids = /* @__PURE__ */ new Set();
for (const value of values) {
if (typeof value !== "string") continue;
for (const id of String(value).trim().split(/\s+/)) {
if (id) ids.add(id);
}
}
return ids.size > 0 ? Array.from(ids).join(" ") : void 0;
}
__name(concatAriaDescribedby, "concatAriaDescribedby");
// src/slot.tsx
import { jsx } from "react/jsx-runtime";
var SlotContext = React.createContext(mergeProps);
SlotContext.displayName = "SlotContext";
var SlotProvider = /* @__PURE__ */ __name(({ children, mergeProps: mergeProps2 }) => {
return /* @__PURE__ */ jsx(SlotContext.Provider, { value: mergeProps2, children });
}, "SlotProvider");
// @__NO_SIDE_EFFECTS__
function createSlot(ownerName) {
const Slot2 = React.forwardRef((props, forwardedRef) => {
let { children, ...slotProps } = props;
const context = React.useContext(SlotContext);
let { children, mergeProps: mergePropsProp = context, ...slotProps } = props;
let slottableElement = null;

@@ -49,3 +115,6 @@ let hasSlottable = false;

}
const mergedProps = mergeProps(slotProps, slottableElement.props ?? {});
const mergedProps = mergePropsProp(
slotProps,
slottableElement.props ?? {}
);
if (slottableElement.type !== React.Fragment) {

@@ -59,2 +128,3 @@ mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;

}
__name(createSlot, "createSlot");
var Slot = /* @__PURE__ */ createSlot("Slot");

@@ -64,3 +134,3 @@ var SLOTTABLE_IDENTIFIER = Symbol.for("radix.slottable");

function createSlottable(ownerName) {
const Slottable2 = (props) => "child" in props ? props.children(props.child) : props.children;
const Slottable2 = /* @__PURE__ */ __name((props) => "child" in props ? props.children(props.child) : props.children, "Slottable");
Slottable2.displayName = `${ownerName}.Slottable`;

@@ -70,4 +140,5 @@ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;

}
__name(createSlottable, "createSlottable");
var Slottable = /* @__PURE__ */ createSlottable("Slottable");
var getSlottableElementFromSlottable = (slottable, child) => {
var getSlottableElementFromSlottable = /* @__PURE__ */ __name((slottable, child) => {
if ("child" in slottable.props) {

@@ -79,27 +150,3 @@ const child2 = slottable.props.child;

return React.isValidElement(child) ? child : null;
};
function mergeProps(slotProps, childProps) {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
overrideProps[propName] = (...args) => {
const result = childPropValue(...args);
slotPropValue(...args);
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
}
}
return { ...slotProps, ...overrideProps };
}
}, "getSlottableElementFromSlottable");
function getElementRef(element) {

@@ -118,5 +165,7 @@ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;

}
__name(getElementRef, "getElementRef");
function isSlottable(child) {
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
}
__name(isSlottable, "isSlottable");
var REACT_LAZY_TYPE = Symbol.for("react.lazy");

@@ -126,19 +175,24 @@ function isLazyComponent(element) {

}
__name(isLazyComponent, "isLazyComponent");
function isPromiseLike(value) {
return typeof value === "object" && value !== null && "then" in value;
}
var createSlotError = (ownerName) => {
__name(isPromiseLike, "isPromiseLike");
var createSlotError = /* @__PURE__ */ __name((ownerName) => {
return `${ownerName} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`;
};
var createSlottableError = (ownerName) => {
}, "createSlotError");
var createSlottableError = /* @__PURE__ */ __name((ownerName) => {
return `${ownerName} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`;
};
}, "createSlottableError");
var use = React[" use ".trim().toString()];
export {
SlotProvider as Provider,
Slot as Root,
Slot,
SlotProvider,
Slottable,
createSlot,
createSlottable
createSlottable,
mergeProps
};
//# sourceMappingURL=index.mjs.map
{
"version": 3,
"sources": ["../src/slot.tsx"],
"sourcesContent": ["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\n\ndeclare module 'react' {\n interface ReactElement {\n $$typeof?: symbol | string;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type Usable<T> = PromiseLike<T> | React.Context<T>;\n\ntype SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {\n children?: React.ReactNode;\n};\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlot<\n Elem extends Element = HTMLElement,\n Props = React.HTMLAttributes<Elem>,\n>(ownerName: string) {\n const Slot = React.forwardRef<Elem, SlotProps<Elem, Props>>((props, forwardedRef) => {\n let { children, ...slotProps } = props;\n let slottableElement: React.ReactElement | null = null;\n let hasSlottable = false;\n const newChildren: React.ReactNode[] = [];\n\n if (isLazyComponent(children) && typeof use === 'function') {\n children = use(children._payload);\n }\n\n React.Children.forEach(children, (maybeSlottable) => {\n if (isSlottable(maybeSlottable)) {\n hasSlottable = true;\n const slottable = maybeSlottable;\n let child = 'child' in slottable.props ? slottable.props.child : slottable.props.children;\n\n if (isLazyComponent(child) && typeof use === 'function') {\n child = use(child._payload);\n }\n\n slottableElement = getSlottableElementFromSlottable(slottable, child);\n newChildren.push((slottableElement?.props as any)?.children);\n } else {\n newChildren.push(maybeSlottable);\n }\n });\n\n if (slottableElement) {\n slottableElement = React.cloneElement(slottableElement, undefined, newChildren);\n } else if (\n // A `Slottable` was found but it didn't resolve to a single element (e.g.\n // it wrapped multiple elements, text, or a render-prop `child` that\n // wasn't an element). Don't fall back to treating the `Slottable` wrapper\n // itself as the slot target \u2014 throw a descriptive error below instead.\n !hasSlottable &&\n React.Children.count(children) === 1 &&\n React.isValidElement(children)\n ) {\n slottableElement = children;\n }\n\n const slottableElementRef = slottableElement ? getElementRef(slottableElement) : undefined;\n const composedRef = useComposedRefs(forwardedRef, slottableElementRef);\n\n if (!slottableElement) {\n // Empty/falsy children (`null`, `undefined`, `false`, no children, etc.) are valid and\n // render nothing. Anything else is content we couldn't slot onto a single element, which\n // is a usage error, so we fail loudly with a clear message.\n if (children || children === 0) {\n throw new Error(\n hasSlottable ? createSlottableError(ownerName) : createSlotError(ownerName),\n );\n }\n return children;\n }\n\n const mergedProps = mergeProps(slotProps, slottableElement.props ?? {});\n\n // do not pass ref to React.Fragment for React 19 compatibility\n if (slottableElement.type !== React.Fragment) {\n mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;\n }\n\n return React.cloneElement(slottableElement, mergedProps);\n });\n\n Slot.displayName = `${ownerName}.Slot`;\n return Slot;\n}\n\nconst Slot = createSlot('Slot');\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst SLOTTABLE_IDENTIFIER = Symbol.for('radix.slottable');\n\ntype SlottableChildrenProps = { children: React.ReactNode };\ntype SlottableRenderFnProps = {\n child: React.ReactNode;\n children: (slottable: React.ReactNode) => React.ReactNode;\n};\n\ntype SlottableProps = SlottableRenderFnProps | SlottableChildrenProps;\ninterface SlottableComponent extends React.FC<SlottableProps> {\n __radixId: symbol;\n}\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlottable(ownerName: string) {\n const Slottable: SlottableComponent = (props) =>\n 'child' in props ? props.children(props.child) : props.children;\n\n Slottable.displayName = `${ownerName}.Slottable`;\n Slottable.__radixId = SLOTTABLE_IDENTIFIER;\n return Slottable;\n}\n\nconst Slottable = createSlottable('Slottable');\n\n/* -------------------------------------------------------------------------------------------------\n * getSlottableElementFromSlottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst getSlottableElementFromSlottable = (slottable: SlottableElement, child: React.ReactNode) => {\n if ('child' in slottable.props) {\n const child = slottable.props.child;\n if (!React.isValidElement<React.PropsWithChildren>(child)) return null;\n return React.cloneElement(child, undefined, slottable.props.children(child.props.children));\n }\n\n return React.isValidElement(child) ? child : null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * mergeProps\n * -----------------------------------------------------------------------------------------------*/\n\ntype AnyProps = Record<string, any>;\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 (isHandler) {\n // if the handler exists on both, we compose them\n if (slotPropValue && childPropValue) {\n overrideProps[propName] = (...args: unknown[]) => {\n const result = childPropValue(...args);\n slotPropValue(...args);\n return result;\n };\n }\n // but if it exists only on the slot, we use only this one\n else if (slotPropValue) {\n overrideProps[propName] = slotPropValue;\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\n/* -------------------------------------------------------------------------------------------------\n * getElementRef\n * -----------------------------------------------------------------------------------------------*/\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element.props as { ref?: React.Ref<unknown> }).ref;\n }\n\n // Not DEV\n return (element.props as { ref?: React.Ref<unknown> }).ref || (element as any).ref;\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype SlottableElement = React.ReactElement<SlottableProps, SlottableComponent>;\n\nfunction isSlottable(\n child: React.ReactNode,\n): child is React.ReactElement<SlottableProps, typeof Slottable> {\n return (\n React.isValidElement(child) &&\n typeof child.type === 'function' &&\n '__radixId' in child.type &&\n child.type.__radixId === SLOTTABLE_IDENTIFIER\n );\n}\n\nconst REACT_LAZY_TYPE = Symbol.for('react.lazy');\n\ninterface LazyReactElement extends React.ReactElement {\n $$typeof: typeof REACT_LAZY_TYPE;\n _payload: PromiseLike<Exclude<React.ReactNode, PromiseLike<any>>>;\n}\n\nfunction isLazyComponent(element: React.ReactNode): element is LazyReactElement {\n return (\n element != null &&\n typeof element === 'object' &&\n '$$typeof' in element &&\n element.$$typeof === REACT_LAZY_TYPE &&\n '_payload' in element &&\n isPromiseLike(element._payload)\n );\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return typeof value === 'object' && value !== null && 'then' in value;\n}\n\nconst createSlotError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its children. Expected a single React element child or \\`Slottable\\`.`;\n};\n\nconst createSlottableError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its \\`Slottable\\`. Expected \\`Slottable\\` to receive a single React element child.`;\n};\n\nconst use: typeof React.use | undefined = (React as any)[' use '.trim().toString()];\n\nexport {\n Slot,\n Slottable,\n //\n Slot as Root,\n};\nexport type { SlotProps };\n"],
"mappings": ";AAAA,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAAA;AAkBE,SAAS,WAGzC,WA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sourcesContent": ["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport type { AnyProps, MergePropsFunction } from './merge-props';\nimport { mergeProps } from './merge-props';\n\ndeclare module 'react' {\n interface ReactElement {\n $$typeof?: symbol | string;\n }\n}\n\ntype SlotContextValue = MergePropsFunction;\n\nconst SlotContext = React.createContext<SlotContextValue>(mergeProps);\nSlotContext.displayName = 'SlotContext';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProviderProps {\n children: React.ReactNode;\n mergeProps: MergePropsFunction<AnyProps, AnyProps, AnyProps>;\n}\n\nconst SlotProvider: React.FC<SlotProviderProps> = ({ children, mergeProps }) => {\n return <SlotContext.Provider value={mergeProps}>{children}</SlotContext.Provider>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type Usable<T> = PromiseLike<T> | React.Context<T>;\n\ntype SlotProps<Elem extends Element = HTMLElement, Props = React.HTMLAttributes<Elem>> = Props & {\n children?: React.ReactNode;\n mergeProps?: MergePropsFunction;\n};\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlot<\n Elem extends Element = HTMLElement,\n Props = React.HTMLAttributes<Elem>,\n>(ownerName: string) {\n const Slot = React.forwardRef<Elem, SlotProps<Elem, Props>>((props, forwardedRef) => {\n const context = React.useContext(SlotContext);\n let { children, mergeProps: mergePropsProp = context, ...slotProps } = props;\n let slottableElement: React.ReactElement | null = null;\n let hasSlottable = false;\n const newChildren: React.ReactNode[] = [];\n\n if (isLazyComponent(children) && typeof use === 'function') {\n children = use(children._payload);\n }\n\n React.Children.forEach(children, (maybeSlottable) => {\n if (isSlottable(maybeSlottable)) {\n hasSlottable = true;\n const slottable = maybeSlottable;\n let child = 'child' in slottable.props ? slottable.props.child : slottable.props.children;\n\n if (isLazyComponent(child) && typeof use === 'function') {\n child = use(child._payload);\n }\n\n slottableElement = getSlottableElementFromSlottable(slottable, child);\n newChildren.push((slottableElement?.props as any)?.children);\n } else {\n newChildren.push(maybeSlottable);\n }\n });\n\n if (slottableElement) {\n slottableElement = React.cloneElement(slottableElement, undefined, newChildren);\n } else if (\n // A `Slottable` was found but it didn't resolve to a single element (e.g.\n // it wrapped multiple elements, text, or a render-prop `child` that\n // wasn't an element). Don't fall back to treating the `Slottable` wrapper\n // itself as the slot target \u2014 throw a descriptive error below instead.\n !hasSlottable &&\n React.Children.count(children) === 1 &&\n React.isValidElement(children)\n ) {\n slottableElement = children;\n }\n\n const slottableElementRef = slottableElement ? getElementRef(slottableElement) : undefined;\n const composedRef = useComposedRefs(forwardedRef, slottableElementRef);\n\n if (!slottableElement) {\n // Empty/falsy children (`null`, `undefined`, `false`, no children, etc.)\n // are valid and render nothing. Anything else is content we couldn't slot\n // onto a single element, which is a usage error, so we fail loudly with a\n // clear message.\n if (children || children === 0) {\n throw new Error(\n hasSlottable ? createSlottableError(ownerName) : createSlotError(ownerName),\n );\n }\n return children;\n }\n\n const mergedProps = mergePropsProp(\n slotProps,\n (slottableElement.props ?? {}) as Record<string, unknown>,\n );\n\n // do not pass ref to React.Fragment for React 19 compatibility\n if (slottableElement.type !== React.Fragment) {\n mergedProps.ref = forwardedRef ? composedRef : slottableElementRef;\n }\n\n return React.cloneElement(slottableElement, mergedProps);\n });\n\n Slot.displayName = `${ownerName}.Slot`;\n return Slot;\n}\n\nconst Slot = createSlot('Slot');\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst SLOTTABLE_IDENTIFIER = Symbol.for('radix.slottable');\n\ntype SlottableChildrenProps = { children: React.ReactNode };\ntype SlottableRenderFnProps = {\n child: React.ReactNode;\n children: (slottable: React.ReactNode) => React.ReactNode;\n};\n\ntype SlottableProps = SlottableRenderFnProps | SlottableChildrenProps;\ninterface SlottableComponent extends React.FC<SlottableProps> {\n __radixId: symbol;\n}\n\n/* @__NO_SIDE_EFFECTS__ */ export function createSlottable(ownerName: string) {\n const Slottable: SlottableComponent = (props) =>\n 'child' in props ? props.children(props.child) : props.children;\n\n Slottable.displayName = `${ownerName}.Slottable`;\n Slottable.__radixId = SLOTTABLE_IDENTIFIER;\n return Slottable;\n}\n\nconst Slottable = createSlottable('Slottable');\n\n/* -------------------------------------------------------------------------------------------------\n * getSlottableElementFromSlottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst getSlottableElementFromSlottable = (slottable: SlottableElement, child: React.ReactNode) => {\n if ('child' in slottable.props) {\n const child = slottable.props.child;\n if (!React.isValidElement<React.PropsWithChildren>(child)) return null;\n return React.cloneElement(child, undefined, slottable.props.children(child.props.children));\n }\n\n return React.isValidElement(child) ? child : null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * getElementRef\n * -----------------------------------------------------------------------------------------------*/\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element.props as { ref?: React.Ref<unknown> }).ref;\n }\n\n // Not DEV\n return (element.props as { ref?: React.Ref<unknown> }).ref || (element as any).ref;\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype SlottableElement = React.ReactElement<SlottableProps, SlottableComponent>;\n\nfunction isSlottable(\n child: React.ReactNode,\n): child is React.ReactElement<SlottableProps, typeof Slottable> {\n return (\n React.isValidElement(child) &&\n typeof child.type === 'function' &&\n '__radixId' in child.type &&\n child.type.__radixId === SLOTTABLE_IDENTIFIER\n );\n}\n\nconst REACT_LAZY_TYPE = Symbol.for('react.lazy');\n\ninterface LazyReactElement extends React.ReactElement {\n $$typeof: typeof REACT_LAZY_TYPE;\n _payload: PromiseLike<Exclude<React.ReactNode, PromiseLike<any>>>;\n}\n\nfunction isLazyComponent(element: React.ReactNode): element is LazyReactElement {\n return (\n element != null &&\n typeof element === 'object' &&\n '$$typeof' in element &&\n element.$$typeof === REACT_LAZY_TYPE &&\n '_payload' in element &&\n isPromiseLike(element._payload)\n );\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return typeof value === 'object' && value !== null && 'then' in value;\n}\n\nconst createSlotError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its children. Expected a single React element child or \\`Slottable\\`.`;\n};\n\nconst createSlottableError = (ownerName: string) => {\n return `${ownerName} failed to slot onto its \\`Slottable\\`. Expected \\`Slottable\\` to receive a single React element child.`;\n};\n\nconst use: typeof React.use | undefined = (React as any)[' use '.trim().toString()];\n\nexport {\n Slot,\n Slottable,\n SlotProvider,\n //\n Slot as Root,\n SlotProvider as Provider,\n //\n mergeProps,\n};\nexport type { SlotProps };\nexport type { MergePropsFunction } from './merge-props';\n", "import { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\n\nconst mergeProps = (<\n SlotProps extends AnyProps = AnyProps,\n ChildProps extends AnyProps = SlotProps,\n ReturnProps extends AnyProps = SlotProps & ChildProps,\n>(\n slotProps: SlotProps,\n childProps: ChildProps,\n): ReturnProps => {\n const overrideProps = { ...childProps };\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 (isHandler) {\n // if the handler exists on both, we compose them\n if (slotPropValue && childPropValue) {\n const slotIsFunction = typeof slotPropValue === 'function';\n const childIsFunction = typeof childPropValue === 'function';\n if (IS_DEVELOPMENT) {\n if (!slotIsFunction || !childIsFunction) {\n console.warn(\n `Slot: Expected a function for ${propName}, but received ${[typeof slotPropValue, typeof childPropValue].filter((v) => v !== 'function').join(' and ')}.`,\n );\n }\n }\n\n // @ts-expect-error - we don't know the type of the function. This\n // technically makes the return signature a lie, not sure if it's worth\n // handling.\n overrideProps[propName] = (...args: unknown[]) => {\n const result = childIsFunction ? childPropValue(...args) : undefined;\n if (slotIsFunction) {\n slotPropValue(...args);\n }\n return result;\n };\n }\n // but if it exists only on the slot, we use only this one\n else if (slotPropValue) {\n overrideProps[propName] = slotPropValue;\n }\n }\n\n // if it's `style`, we merge them\n else if (propName === 'style') {\n (overrideProps as any)[propName] = {\n ...(typeof slotPropValue === 'object' ? slotPropValue : null),\n ...(typeof childPropValue === 'object' ? childPropValue : null),\n };\n } else if (propName === 'className') {\n (overrideProps as any)[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n } else if (propName === 'aria-describedby') {\n (overrideProps as any)[propName] = concatAriaDescribedby(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps } as ReturnProps;\n}) satisfies MergePropsFunction;\n\n// TODO: Move to primitive once that package exposed individual sub-modules\nfunction concatAriaDescribedby(...values: unknown[]): string | undefined {\n const ids = new Set<string>();\n for (const value of values) {\n if (typeof value !== 'string') continue;\n for (const id of String(value).trim().split(/\\s+/)) {\n if (id) ids.add(id);\n }\n }\n\n return ids.size > 0 ? Array.from(ids).join(' ') : undefined;\n}\n\ninterface MergePropsFunction<\n SlotProps extends AnyProps = UnknownProps,\n ChildProps extends AnyProps = SlotProps,\n ReturnProps extends AnyProps = SlotProps & ChildProps,\n> {\n (slotProps: SlotProps, childProps: ChildProps): ReturnProps;\n}\n\ntype AnyProps = Record<string, any>;\ntype UnknownProps = Record<string, unknown>;\n\nexport { mergeProps };\nexport type { MergePropsFunction, AnyProps, UnknownProps };\n"],
"mappings": ";;;;AAAA,YAAY,WAAW;AACvB,SAAS,uBAAuB;;;ACDhC,SAAS,sBAAsB;AAE/B,IAAM,aAAc,yBAKlB,WACA,eACgB;AAChB,QAAM,gBAAgB,EAAE,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@ "source": "./src/index.ts",

"dependencies": {
"@radix-ui/react-compose-refs": "1.1.3"
"@radix-ui/primitive": "1.1.7",
"@radix-ui/react-compose-refs": "1.1.4"
},
"devDependencies": {
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"@types/react": "^19.2.17",
"@types/react-dom": "^19.2.3",
"react": "^19.2.7",
"react-dom": "^19.2.7",
"typescript": "^5.9.3",
"@repo/typescript-config": "0.0.0",
"@repo/builder": "0.0.0"
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0"
},

@@ -26,0 +27,0 @@ "peerDependencies": {