UNPKG

vuestic-ui

Version:
49 lines (48 loc) 1.83 kB
import { computed } from "vue"; import { i as injectChildPropsFromParent } from "../../composables/useChildComponents.js"; import { r as renderSlotNode, m as makeVNode } from "./createRenderFn.js"; const SLOT_PREFIX = "slot:"; const createSlots = (instance, propsFromConfig) => { const instanceSlots = instance.slots; const childPropsFromParent = injectChildPropsFromParent(); const slotsFromConfig = computed(() => { return Object.keys(propsFromConfig.value).reduce((acc, key) => { if (key.startsWith(SLOT_PREFIX)) { acc[key.slice(SLOT_PREFIX.length)] = propsFromConfig.value[key]; } return acc; }, {}); }); return new Proxy(instanceSlots, { get: (target, key) => { var _a, _b; if (typeof key !== "string") { return target[key]; } const prefixedKey = `${SLOT_PREFIX}${key}`; const childSlot = (_a = childPropsFromParent == null ? void 0 : childPropsFromParent.value) == null ? void 0 : _a[prefixedKey]; if (childSlot !== void 0) { return renderSlotNode(makeVNode(childSlot)); } const originalSlot = target[key]; if (originalSlot !== void 0) { return originalSlot; } const propFromConfig = (_b = slotsFromConfig.value) == null ? void 0 : _b[key]; if (propFromConfig !== void 0) { return renderSlotNode(makeVNode(propFromConfig)); } return originalSlot; }, ownKeys(target) { return [.../* @__PURE__ */ new Set([...Object.keys(instanceSlots), ...Object.keys(slotsFromConfig.value)])]; }, getOwnPropertyDescriptor(target, key) { return Reflect.getOwnPropertyDescriptor(slotsFromConfig.value, key) ?? Reflect.getOwnPropertyDescriptor(instanceSlots, key); } }); }; export { createSlots as c }; //# sourceMappingURL=createSlots.js.map