UNPKG

reka-ui

Version:

Vue port for Radix UI Primitives.

1 lines 2.9 kB
{"version":3,"file":"Slot.cjs","sources":["../../src/Primitive/Slot.ts"],"sourcesContent":["import { Comment, cloneVNode, defineComponent, mergeProps } from 'vue'\nimport { renderSlotFragments } from '@/shared'\n\nexport const Slot = defineComponent({\n name: 'PrimitiveSlot',\n inheritAttrs: false,\n setup(_, { attrs, slots }) {\n return () => {\n if (!slots.default)\n return null\n\n const childrens = renderSlotFragments(slots.default())\n const firstNonCommentChildrenIndex = childrens.findIndex(child => child.type !== Comment)\n if (firstNonCommentChildrenIndex === -1)\n return childrens\n\n const firstNonCommentChildren = childrens[firstNonCommentChildrenIndex]\n\n // Remove props ref from being inferred\n delete firstNonCommentChildren.props?.ref\n\n const mergedProps = firstNonCommentChildren.props\n ? mergeProps(attrs, firstNonCommentChildren.props)\n : attrs\n // Remove class to prevent duplicated\n if (attrs.class && firstNonCommentChildren.props?.class)\n delete firstNonCommentChildren.props.class\n const cloned = cloneVNode(firstNonCommentChildren, mergedProps)\n\n // Explicitly override props starting with `on`.\n // It seems cloneVNode from Vue doesn't like overriding `onXXX` props.\n // So we have to do it manually.\n for (const prop in mergedProps) {\n if (prop.startsWith('on')) {\n cloned.props ||= {}\n cloned.props[prop] = mergedProps[prop]\n }\n }\n\n if (childrens.length === 1)\n return cloned\n\n childrens[firstNonCommentChildrenIndex] = cloned\n return childrens\n }\n },\n})\n"],"names":["defineComponent","renderSlotFragments","Comment","mergeProps","cloneVNode"],"mappings":";;;;;AAGO,MAAM,OAAOA,mBAAgB,CAAA;AAAA,EAClC,IAAM,EAAA,eAAA;AAAA,EACN,YAAc,EAAA,KAAA;AAAA,EACd,KAAM,CAAA,CAAA,EAAG,EAAE,KAAA,EAAO,OAAS,EAAA;AACzB,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,CAAC,KAAM,CAAA,OAAA;AACT,QAAO,OAAA,IAAA;AAET,MAAA,MAAM,SAAY,GAAAC,8CAAA,CAAoB,KAAM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