comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
58 lines (57 loc) • 1.82 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
require("../../utils/config.js");
const typescript = require("../../utils/typescript.js");
require("@vueuse/core");
const wrapTextContent = (s) => {
return vue.h("span", null, s);
};
const findFirstLegitChild = (node) => {
if (!node) return null;
for (const child of node) {
if (typescript.isObject(child)) {
switch (child.type) {
case vue.Comment:
continue;
case vue.Text:
case "svg":
return wrapTextContent(child);
case vue.Fragment:
if (child.children.length > 1) {
vue.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 = vue.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) {
vue.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) {
vue.warn("At least one element is required in the slot of the popover component");
return null;
}
return vue.cloneVNode(firstLegitChild, attrs);
};
}
});
exports.default = OnlyChild;