routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
// Composables
|
||||
import { useToggleScope } from "./toggleScope.js"; // Utilities
|
||||
import { inject, onScopeDispose, provide, reactive, readonly, shallowRef, toRaw, toRef, toValue, watchEffect } from 'vue';
|
||||
import { getCurrentInstance } from "../util/index.js"; // Types
|
||||
const StackSymbol = Symbol.for('vuetify:stack');
|
||||
const globalStack = reactive([]);
|
||||
export function useStack(isActive, zIndex, disableGlobalStack) {
|
||||
const vm = getCurrentInstance('useStack');
|
||||
const createStackEntry = !disableGlobalStack;
|
||||
const parent = inject(StackSymbol, undefined);
|
||||
const stack = reactive({
|
||||
activeChildren: new Set()
|
||||
});
|
||||
provide(StackSymbol, stack);
|
||||
const _zIndex = shallowRef(Number(toValue(zIndex)));
|
||||
useToggleScope(isActive, () => {
|
||||
const lastZIndex = globalStack.at(-1)?.[1];
|
||||
_zIndex.value = lastZIndex ? lastZIndex + 10 : Number(toValue(zIndex));
|
||||
if (createStackEntry) {
|
||||
globalStack.push([vm.uid, _zIndex.value]);
|
||||
}
|
||||
parent?.activeChildren.add(vm.uid);
|
||||
onScopeDispose(() => {
|
||||
if (createStackEntry) {
|
||||
const idx = toRaw(globalStack).findIndex(v => v[0] === vm.uid);
|
||||
globalStack.splice(idx, 1);
|
||||
}
|
||||
parent?.activeChildren.delete(vm.uid);
|
||||
});
|
||||
});
|
||||
const globalTop = shallowRef(true);
|
||||
if (createStackEntry) {
|
||||
watchEffect(() => {
|
||||
const _isTop = globalStack.at(-1)?.[0] === vm.uid;
|
||||
setTimeout(() => globalTop.value = _isTop);
|
||||
});
|
||||
}
|
||||
const localTop = toRef(() => !stack.activeChildren.size);
|
||||
return {
|
||||
globalTop: readonly(globalTop),
|
||||
localTop,
|
||||
stackStyles: toRef(() => ({
|
||||
zIndex: _zIndex.value
|
||||
}))
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=stack.js.map
|
||||
Reference in New Issue
Block a user