docs/.vitepress/theme/components/extrepo/RepoVariantRow.vue
137 lines · 3862 bytes
1<script setup lang="ts">
2import { computed, ref } from 'vue'
3import { groupSites } from './groupSites'
4import {
5 mangayomiCopyValue,
6 mangayomiHref,
7 mangayomiLiveContainerHref
8} from './install'
9import SiteGrid from './SiteGrid.vue'
10import type { Repo, RepoVariant } from './types'
11import { useCopy } from './useCopy'
12import { useRepoStore } from './useRepoStore'
13import { useTooltip } from './useTooltip'
14
15const { show: showTooltip, hide: hideTooltip } = useTooltip()
16const { copiedKey, copy } = useCopy()
17const { store } = useRepoStore()
18
19const repoData = computed(() => store.value?.sites ?? {})
20
21const props = defineProps<{
22 repo: Repo
23 variant: RepoVariant
24 scheme: string
25 showActions: boolean
26 showBroken?: boolean
27}>()
28
29const open = ref(false)
30const copyValue = computed(() => mangayomiCopyValue(props.variant))
31const installUrl = computed(() => mangayomiHref(props.repo, props.variant))
32const liveUrl = computed(() =>
33 mangayomiLiveContainerHref(props.repo, props.variant)
34)
35
36const sites = computed(() => {
37 const url = copyValue.value
38 const all = url ? repoData.value[url]?.sites ?? [] : []
39 return props.showBroken ? all : all.filter(site => !site.isBroken)
40})
41const siteCount = computed(() => groupSites(sites.value).length)
42const siteCountTitle = computed(
43 () =>
44 `${siteCount.value} extension${siteCount.value === 1 ? '' : 's'} available`
45)
46
47async function copyVariantUrl() {
48 if (!copyValue.value) return
49 await copy(props.variant.label, copyValue.value)
50}
51</script>
52
53<template>
54 <div class="ext-repo-variant">
55 <div class="ext-repo-variant-row">
56 <span class="ext-repo-variant-label">
57 {{ variant.label }}
58 <span
59 v-if="siteCount"
60 class="ext-repo-count"
61 :title="siteCountTitle"
62 >{{ siteCount }}</span>
63 </span>
64 <div class="ext-repo-actions">
65 <template v-if="showActions">
66 <a class="ext-btn ext-btn-install" :href="installUrl">
67 <span class="i-lucide:download" />
68 <span class="ext-btn-install-label">Install</span>
69 </a>
70 <a
71 class="ext-btn ext-btn-livecontainer"
72 :href="liveUrl"
73 aria-label="Install via LiveContainer (iOS)"
74 @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
75 @mouseleave="hideTooltip"
76 >
77 <span class="i-mdi:apple" />
78 </a>
79 <button
80 v-if="copyValue"
81 class="ext-btn ext-btn-copy"
82 type="button"
83 @click="copyVariantUrl"
84 >
85 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
86 <span v-else class="i-lucide:copy" />
87 </button>
88 </template>
89 <button
90 v-else-if="copyValue"
91 class="ext-btn ext-btn-copy"
92 type="button"
93 @click="copyVariantUrl"
94 >
95 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
96 <span v-else class="i-lucide:copy" />
97 </button>
98 <button
99 class="ext-btn ext-btn-toggle"
100 type="button"
101 :class="{ open }"
102 :aria-expanded="open"
103 @click="open = !open"
104 >
105 <span class="i-lucide:chevron-down" />
106 </button>
107 </div>
108 </div>
109
110 <SiteGrid
111 v-if="open"
112 :sites="sites"
113 :scheme="scheme"
114 empty-text="No site data available."
115 />
116 </div>
117</template>
118
119<style scoped src="./repoRowShared.css"></style>
120
121<style scoped>
122.ext-repo-variant-row {
123 display: flex;
124 align-items: center;
125 justify-content: space-between;
126 gap: 12px;
127 padding: 8px 14px 8px 28px;
128 border-top: 1px solid var(--vp-c-divider);
129}
130.ext-repo-variant-label {
131 display: inline-flex;
132 align-items: center;
133 gap: 6px;
134 font-size: 13px;
135 color: var(--vp-c-text-2);
136}
137</style>