UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

58 lines (57 loc) 1.71 kB
import { defineComponent, warn, cloneVNode, Fragment, Text, Comment, h } from "vue"; import "../../utils/config.mjs"; import { isObject } from "../../utils/typescript.mjs"; import "@vueuse/core"; const wrapTextContent = (s) => { return h("span", null, s); }; const findFirstLegitChild = (node) => { if (!node) return null; for (const child of node) { if (isObject(child)) { switch (child.type) { case Comment: continue; case Text: case "svg": return wrapTextContent(child); case Fragment: if (child.children.length > 1) { warn( "There can only be one trigger for popover, and any extra triggers will not trigger the effect even if they exist" ); } return findFirstLegitChild(child.children); default: return child; } } return wrapTextContent(child); } return null; }; const OnlyChild = defineComponent({ name: "SlotChild", setup(_, { slots, attrs }) { return () => { var _a; const defaultSlot = (_a = slots.default) == null ? void 0 : _a.call(slots, attrs); if (!defaultSlot) return null; if (defaultSlot.length > 1) { warn( "There can only be one trigger for popover, and any extra triggers will not trigger the effect even if they exist" ); return null; } const firstLegitChild = findFirstLegitChild(defaultSlot); if (!firstLegitChild) { warn("At least one element is required in the slot of the popover component"); return null; } return cloneVNode(firstLegitChild, attrs); }; } }); export { OnlyChild as default };