1 |
- {"version":3,"file":"stack.mjs","names":["useToggleScope","computed","inject","onScopeDispose","provide","reactive","readonly","shallowRef","toRaw","watchEffect","getCurrentInstance","StackSymbol","Symbol","for","globalStack","useStack","isActive","zIndex","disableGlobalStack","vm","createStackEntry","parent","undefined","stack","activeChildren","Set","_zIndex","value","lastZIndex","at","push","uid","add","idx","findIndex","v","splice","delete","globalTop","_isTop","setTimeout","localTop","size","stackStyles"],"sources":["../../src/composables/stack.ts"],"sourcesContent":["// Composables\nimport { useToggleScope } from '@/composables/toggleScope'\n\n// Utilities\nimport { computed, inject, onScopeDispose, provide, reactive, readonly, shallowRef, toRaw, watchEffect } from 'vue'\nimport { getCurrentInstance } from '@/util'\n\n// Types\nimport type { InjectionKey, Ref } from 'vue'\n\nconst StackSymbol: InjectionKey<StackProvide> = Symbol.for('vuetify:stack')\n\ninterface StackProvide {\n activeChildren: Set<number>\n}\n\nconst globalStack = reactive<[uid: number, zIndex: number][]>([])\n\nexport function useStack (\n isActive: Readonly<Ref<boolean>>,\n zIndex: Readonly<Ref<string | number>>,\n disableGlobalStack: boolean\n) {\n const vm = getCurrentInstance('useStack')\n const createStackEntry = !disableGlobalStack\n\n const parent = inject(StackSymbol, undefined)\n const stack: StackProvide = reactive({\n activeChildren: new Set<number>(),\n })\n provide(StackSymbol, stack)\n\n const _zIndex = shallowRef(+zIndex.value)\n useToggleScope(isActive, () => {\n const lastZIndex = globalStack.at(-1)?.[1]\n _zIndex.value = lastZIndex ? lastZIndex + 10 : +zIndex.value\n\n if (createStackEntry) {\n globalStack.push([vm.uid, _zIndex.value])\n }\n\n parent?.activeChildren.add(vm.uid)\n\n onScopeDispose(() => {\n if (createStackEntry) {\n const idx = toRaw(globalStack).findIndex(v => v[0] === vm.uid)\n globalStack.splice(idx, 1)\n }\n\n parent?.activeChildren.delete(vm.uid)\n })\n })\n\n const globalTop = shallowRef(true)\n if (createStackEntry) {\n watchEffect(() => {\n const _isTop = globalStack.at(-1)?.[0] === vm.uid\n setTimeout(() => globalTop.value = _isTop)\n })\n }\n\n const localTop = computed(() => !stack.activeChildren.size)\n\n return {\n globalTop: readonly(globalTop),\n localTop,\n stackStyles: computed(() => ({ zIndex: _zIndex.value })),\n }\n}\n"],"mappings":"AAAA;AAAA,SACSA,cAAc,6BAEvB;AACA,SAASC,QAAQ,EAAEC,MAAM,EAAEC,cAAc,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,KAAK,EAAEC,WAAW,QAAQ,KAAK;AAAA,SAC1GC,kBAAkB,6BAE3B;AAGA,MAAMC,WAAuC,GAAGC,MAAM,CAACC,GAAG,CAAC,eAAe,CAAC;AAM3E,MAAMC,WAAW,GAAGT,QAAQ,CAAkC,EAAE,CAAC;AAEjE,OAAO,SAASU,QAAQA,CACtBC,QAAgC,EAChCC,MAAsC,EACtCC,kBAA2B,EAC3B;EACA,MAAMC,EAAE,GAAGT,kBAAkB,CAAC,UAAU,CAAC;EACzC,MAAMU,gBAAgB,GAAG,CAACF,kBAAkB;EAE5C,MAAMG,MAAM,GAAGnB,MAAM,CAACS,WAAW,EAAEW,SAAS,CAAC;EAC7C,MAAMC,KAAmB,GAAGlB,QAAQ,CAAC;IACnCmB,cAAc,EAAE,IAAIC,GAAG;EACzB,CAAC,CAAC;EACFrB,OAAO,CAACO,WAAW,EAAEY,KAAK,CAAC;EAE3B,MAAMG,OAAO,GAAGnB,UAAU,CAAC,CAACU,MAAM,CAACU,KAAK,CAAC;EACzC3B,cAAc,CAACgB,QAAQ,EAAE,MAAM;IAC7B,MAAMY,UAAU,GAAGd,WAAW,CAACe,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1CH,OAAO,CAACC,KAAK,GAAGC,UAAU,GAAGA,UAAU,GAAG,EAAE,GAAG,CAACX,MAAM,CAACU,KAAK;IAE5D,IAAIP,gBAAgB,EAAE;MACpBN,WAAW,CAACgB,IAAI,CAAC,CAACX,EAAE,CAACY,GAAG,EAAE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