bootstrap-vue-next
Version:
BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.
1 lines • 3.15 kB
Source Map (JSON)
{"version":3,"file":"utils-DAHbMzJg.mjs","sources":["../src/directives/utils.ts"],"sourcesContent":["import type {ComponentInternalInstance, DirectiveBinding, VNode} from 'vue'\n\ninterface _ComponentInternalInstance extends ComponentInternalInstance {\n provides?: Record<string, unknown>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setupState?: any\n}\n\ninterface _VNode extends VNode {\n ctx?: _ComponentInternalInstance | null\n ssContent?: VNode | null\n}\n\n// taken from vuetify https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/composables/directiveComponent.ts\n\nexport function findProvides(binding: DirectiveBinding, vnode: _VNode): Record<string, unknown> {\n const provides =\n (vnode.ctx === binding.instance!.$\n ? findComponentParent(vnode, binding.instance!.$)?.provides\n : vnode.ctx?.provides) ?? binding.instance!.$.provides\n\n return provides\n}\n\nexport function findComponentParent(\n vnode: VNode,\n root: ComponentInternalInstance\n): _ComponentInternalInstance | null {\n // Walk the tree from root until we find the child vnode\n const stack = new Set<VNode>()\n const walk = (children: _VNode[]): boolean => {\n for (const child of children) {\n if (!child) continue\n\n if (child === vnode || (child.el && vnode.el && child.el === vnode.el)) {\n return true\n }\n\n stack.add(child)\n let result\n if (child.suspense) {\n result = walk([child.ssContent!])\n } else if (Array.isArray(child.children)) {\n result = walk(child.children as VNode[])\n } else if (child.component?.vnode) {\n result = walk([child.component?.subTree])\n }\n if (result) {\n return result\n }\n stack.delete(child)\n }\n\n return false\n }\n if (!walk([root.subTree])) {\n // eslint-disable-next-line no-console\n console.error('Could not find original vnode, will not inherit provides')\n return root\n }\n\n // Return the first component parent\n const result = Array.from(stack).reverse()\n for (const child of result) {\n if (child.component) {\n return child.component\n }\n }\n return root\n}\n"],"names":["result"],"mappings":"AAeO,SAAS,aAAa,SAA2B,OAAwC;AAC9F,QAAM,YACH,MAAM,QAAQ,QAAQ,SAAU,IAC7B,oBAAoB,OAAO,QAAQ,SAAU,CAAC,GAAG,WACjD,MAAM,KAAK,aAAa,QAAQ,SAAU,EAAE;AAElD,SAAO;AACT;AAEO,SAAS,oBACd,OACA,MACmC;AAEnC,QAAM,4BAAY,IAAA;AAClB,QAAM,OAAO,CAAC,aAAgC;AAC5C,eAAW,SAAS,UAAU;AAC5B,UAAI,CAAC,MAAO;AAEZ,UAAI,UAAU,SAAU,MAAM,MAAM,MAAM,MAAM,MAAM,OAAO,MAAM,IAAK;AACtE,eAAO;AAAA,MACT;AAEA,YAAM,IAAI,KAAK;AACf,UAAIA;AACJ,UAAI,MAAM,UAAU;AAClBA,kBAAS,KAAK,CAAC,MAAM,SAAU,CAAC;AAAA,MAClC,WAAW,MAAM,QAAQ,MAAM,QAAQ,GAAG;AACxCA,kBAAS,KAAK,MAAM,QAAmB;AAAA,MACzC,WAAW,MAAM,WAAW,OAAO;AACjCA,kBAAS,KAAK,CAAC,MAAM,WAAW,OAAO,CAAC;AAAA,MAC1C;AACA,UAAIA,SAAQ;AACV,eAAOA;AAAAA,MACT;AACA,YAAM,OAAO,KAAK;AAAA,IACpB;AAEA,WAAO;AAAA,EACT;AACA,MAAI,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,GAAG;AAEzB,YAAQ,MAAM,2DAA2D;AACzE,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,MAAM,KAAK,KAAK,EAAE,QAAA;AACjC,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,WAAW;AACnB,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AACA,SAAO;AACT;"}