docs/.vitepress/theme/composables/useTooltips.ts

10815556308f046864859f2254bfeb1e61bf271b
wotaku/docs/.vitepress/theme/composables/useTooltips.ts
taskylizard wotaku 2bea9706e6c 1 year ago

32 lines · 860 bytes

 1/**
 2 *  All Rights Reserved
 3 *
 4 *  Copyright (c) 2025 taskylizard
 5 *
 6 *  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7 */
 8import { getTooltip, type TooltipData } from 'virtual:tooltips'
 9import { ref } from 'vue'
10
11const tooltipCache = ref<Map<string, TooltipData>>(new Map())
12
13export function useTooltips() {
14  const getTooltipData = (id: string): TooltipData | null => {
15    if (tooltipCache.value.has(id)) {
16      return tooltipCache.value.get(id)!
17    }
18
19    const tooltip = getTooltip(id)
20    if (tooltip) {
21      tooltipCache.value.set(id, tooltip)
22      return tooltip
23    }
24
25    console.warn(`Tooltip with id "${id}" not found`)
26    return null
27  }
28
29  return {
30    getTooltipData
31  }
32}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form