bootstrap-vue-next
Version:
BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.
47 lines (46 loc) • 1.45 kB
JavaScript
function findProvides(binding, vnode) {
var _a, _b;
const provides = (vnode.ctx === binding.instance.$ ? (_a = findComponentParent(vnode, binding.instance.$)) == null ? void 0 : _a.provides : (_b = vnode.ctx) == null ? void 0 : _b.provides) ?? binding.instance.$.provides;
return provides;
}
function findComponentParent(vnode, root) {
const stack = /* @__PURE__ */ new Set();
const walk = (children) => {
var _a, _b;
for (const child of children) {
if (!child) continue;
if (child === vnode || child.el && vnode.el && child.el === vnode.el) {
return true;
}
stack.add(child);
let result2;
if (child.suspense) {
result2 = walk([child.ssContent]);
} else if (Array.isArray(child.children)) {
result2 = walk(child.children);
} else if ((_a = child.component) == null ? void 0 : _a.vnode) {
result2 = walk([(_b = child.component) == null ? void 0 : _b.subTree]);
}
if (result2) {
return result2;
}
stack.delete(child);
}
return false;
};
if (!walk([root.subTree])) {
console.error("Could not find original vnode, will not inherit provides");
return root;
}
const result = Array.from(stack).reverse();
for (const child of result) {
if (child.component) {
return child.component;
}
}
return root;
}
export {
findProvides as f
};
//# sourceMappingURL=utils-DPq73bs8.mjs.map