30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
import { renderSlotFragments } from "../shared/renderSlotFragments.js";
|
|
import { Comment, cloneVNode, defineComponent, mergeProps } from "vue";
|
|
|
|
//#region src/Primitive/Slot.ts
|
|
const Slot = defineComponent({
|
|
name: "PrimitiveSlot",
|
|
inheritAttrs: false,
|
|
setup(_, { attrs, slots }) {
|
|
return () => {
|
|
if (!slots.default) return null;
|
|
const children = renderSlotFragments(slots.default());
|
|
const firstNonCommentChildrenIndex = children.findIndex((child) => child.type !== Comment);
|
|
if (firstNonCommentChildrenIndex === -1) return children;
|
|
const firstNonCommentChildren = children[firstNonCommentChildrenIndex];
|
|
delete firstNonCommentChildren.props?.ref;
|
|
const mergedProps = firstNonCommentChildren.props ? mergeProps(attrs, firstNonCommentChildren.props) : attrs;
|
|
const cloned = cloneVNode({
|
|
...firstNonCommentChildren,
|
|
props: {}
|
|
}, mergedProps);
|
|
if (children.length === 1) return cloned;
|
|
children[firstNonCommentChildrenIndex] = cloned;
|
|
return children;
|
|
};
|
|
}
|
|
});
|
|
|
|
//#endregion
|
|
export { Slot };
|
|
//# sourceMappingURL=Slot.js.map
|