UNPKG

@vuesax-alpha/nightly

Version:
1 lines 1.49 kB
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-group-inject/index.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, onUnmounted } from 'vue'\nimport type { ParentProvide } from '@vuesax-alpha/tokens'\nimport type { InjectionKey } from 'vue'\n\nexport const useGroupInject = <T extends Record<string, unknown>>(\n key: InjectionKey<ParentProvide<T>>\n) => {\n const instance = getCurrentInstance()\n if (!instance) {\n throw new Error(\n 'useInject hook must be called inside setup function or <script setup>'\n )\n }\n\n const parent = inject(key, undefined)\n const index = computed(() => parent?.children.indexOf(instance) || 0)\n\n parent?.insert(instance)\n\n onUnmounted(() => {\n parent?.remove(instance)\n })\n\n return parent ? { ...parent, index } : undefined\n}\n"],"names":[],"mappings":";;AAIa,MAAA,cAAA,GAAiB,CAC5B,GACG,KAAA;AACH,EAAA,MAAM,WAAW,kBAAmB,EAAA,CAAA;AACpC,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEA,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,GAAA,EAAK,KAAS,CAAA,CAAA,CAAA;AACpC,EAAA,MAAM,QAAQ,QAAS,CAAA,MAAA,CAAM,iCAAQ,QAAS,CAAA,OAAA,CAAQ,cAAa,CAAC,CAAA,CAAA;AAEpE,EAAA,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAQ,MAAO,CAAA,QAAA,CAAA,CAAA;AAEf,EAAA,WAAA,CAAY,MAAM;AAChB,IAAA,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAQ,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,GAChB,CAAA,CAAA;AAED,EAAA,OAAO,MAAS,GAAA,EAAE,GAAG,MAAA,EAAQ,OAAU,GAAA,KAAA,CAAA,CAAA;AACzC;;;;"}