123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { storeToRefs } from 'pinia'
- import { computed, ref, watch, type Ref } from 'vue'
- import type { UserTaskbarTab } from '#desktop/components/UserTaskbarTabs/types.ts'
- import { useUserCurrentTaskbarTabsStore } from '#desktop/entities/user/current/stores/taskbarTabs.ts'
- type CommonLinkInstance = {
- $el?: HTMLElement
- }
- export const useUserTaskbarTabLink = (
- taskbarTab: Ref<UserTaskbarTab>,
- exactActiveCallback?: () => void,
- ) => {
- const tabLinkInstance = ref<CommonLinkInstance>()
- const { activeTaskbarTabEntityKey } = storeToRefs(
- useUserCurrentTaskbarTabsStore(),
- )
- const taskbarTabActive = computed(
- () => activeTaskbarTabEntityKey.value === taskbarTab.value.tabEntityKey,
- )
- watch(
- [taskbarTabActive, tabLinkInstance],
- ([isActive, instance]) => {
- if (!isActive || !instance) return
- exactActiveCallback?.()
-
-
- setTimeout(() => {
-
- if (instance.$el?.checkVisibility?.() ?? true) {
- instance.$el?.scrollIntoView?.({ block: 'nearest' })
- }
- }, 0)
- },
- { immediate: true, flush: 'post' },
- )
- return {
- tabLinkInstance,
- taskbarTabActive,
- }
- }
|