docs/.vitepress/theme/components/extrepo/RepoRow.vue

ba4f23d3bab9e2bb3b8efdb22317c8cc8f353ec5
wotaku/docs/.vitepress/theme/components/extrepo/RepoRow.vue history · blame · raw

278 lines · 7995 bytes

  1<script setup lang="ts">
  2import { computed, ref } from 'vue'
  3import { NOT_EXPANDABLE_REPOS } from './constants'
  4import { groupSites } from './groupSites'
  5import { stripHtml } from './helpers'
  6import {
  7  copyValue,
  8  hasCopyButton,
  9  installHref,
 10  isBrowseOnly,
 11  mangayomiCopyValue,
 12  mangayomiHref,
 13  mangayomiLiveContainerHref
 14} from './install'
 15import RepoVariantRow from './RepoVariantRow.vue'
 16import SiteGrid from './SiteGrid.vue'
 17import type { Repo } from './types'
 18import { useCopy } from './useCopy'
 19import { useRepoStore } from './useRepoStore'
 20import { useTooltip } from './useTooltip'
 21
 22const { show: showTooltip, hide: hideTooltip } = useTooltip()
 23const { copiedKey, copy } = useCopy()
 24const { store } = useRepoStore()
 25
 26const repoData = computed(() => store.value?.sites ?? {})
 27
 28const props = defineProps<{
 29  repo: Repo
 30  scheme: string
 31  showBroken?: boolean
 32}>()
 33
 34const open = ref(false)
 35
 36const sites = computed(() => {
 37  const dataUrl = props.repo.data ?? props.repo.indexUrl
 38  const all = repoData.value[dataUrl]?.sites ?? []
 39  return props.showBroken ? all : all.filter(site => !site.isBroken)
 40})
 41const siteCount = computed(() => {
 42  const countFor = (url: string | null | undefined) => {
 43    const all = url ? repoData.value[url]?.sites ?? [] : []
 44    const visible = props.showBroken
 45      ? all
 46      : all.filter(site => !site.isBroken)
 47    return groupSites(visible).length
 48  }
 49  if (props.repo.variants?.length) {
 50    return props.repo.variants.reduce(
 51      (total, variant) => total + countFor(mangayomiCopyValue(variant)),
 52      0
 53    )
 54  }
 55  return countFor(props.repo.data ?? props.repo.indexUrl)
 56})
 57const siteCountTitle = computed(
 58  () =>
 59    `${siteCount.value} extension${siteCount.value === 1 ? '' : 's'} available`
 60)
 61const repoName = computed(() => stripHtml(props.repo.name))
 62const isExpandable = computed(() => !NOT_EXPANDABLE_REPOS.has(repoName.value))
 63const installUrl = computed(() =>
 64  installHref(props.scheme, props.repo, {
 65    suwatteV6: repoData.value[props.repo.indexUrl]?.suwatteV6,
 66    suwatteListUrl: repoData.value[props.repo.indexUrl]?.suwatteListUrl
 67  })
 68)
 69const showActions = computed(() => !isBrowseOnly(props.scheme))
 70
 71const headerVariant = computed(() =>
 72  showActions.value ? props.repo.variants?.[0] : undefined
 73)
 74const headerCopyValue = computed(() =>
 75  headerVariant.value ? mangayomiCopyValue(headerVariant.value) : null
 76)
 77const headerInstallUrl = computed(() =>
 78  headerVariant.value ? mangayomiHref(props.repo, headerVariant.value) : null
 79)
 80const headerLiveUrl = computed(() =>
 81  headerVariant.value
 82    ? mangayomiLiveContainerHref(props.repo, headerVariant.value)
 83    : null
 84)
 85const subVariants = computed(() => {
 86  if (!props.repo.variants?.length) return []
 87  return showActions.value && props.repo.variants.length > 1
 88    ? props.repo.variants.slice(1)
 89    : props.repo.variants
 90})
 91
 92async function copyUrl() {
 93  await copy(props.repo.indexUrl, copyValue(props.scheme, props.repo.indexUrl))
 94}
 95
 96async function copyHeaderVariantUrl() {
 97  if (!headerVariant.value || !headerCopyValue.value) return
 98  await copy(headerVariant.value.label, headerCopyValue.value)
 99}
100</script>
101
102<template>
103  <div class="ext-repo">
104    <div class="ext-repo-row">
105      <div class="ext-repo-name">
106        <span v-html="repo.name" />
107        <span
108          v-if="siteCount"
109          class="ext-repo-count"
110          :title="siteCountTitle"
111        >{{ siteCount }}</span>
112        <VTooltip v-if="repo.note" theme="vp-tooltip">
113          <button type="button" class="ext-note-btn" aria-label="Note">
114            <span class="i-lucide:lightbulb" />
115          </button>
116          <template #popper>
117            <div class="ext-note-popper" v-html="repo.note" />
118          </template>
119        </VTooltip>
120      </div>
121      <div class="ext-repo-actions">
122        <template v-if="headerVariant">
123          <a class="ext-btn ext-btn-install" :href="headerInstallUrl!">
124            <span class="i-lucide:download" />
125            <span class="ext-btn-install-label">Install</span>
126          </a>
127          <a
128            class="ext-btn ext-btn-livecontainer"
129            :href="headerLiveUrl!"
130            aria-label="Install via LiveContainer (iOS)"
131            @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
132            @mouseleave="hideTooltip"
133          >
134            <span class="i-mdi:apple" />
135          </a>
136          <button
137            v-if="headerCopyValue"
138            class="ext-btn ext-btn-copy"
139            type="button"
140            @click="copyHeaderVariantUrl"
141          >
142            <span
143              v-if="copiedKey === headerVariant.label"
144              class="i-lucide:check"
145            />
146            <span v-else class="i-lucide:copy" />
147          </button>
148          <button
149            v-else
150            class="ext-btn ext-btn-copy ext-btn-spacer"
151            tabindex="-1"
152            aria-hidden="true"
153          >
154            <span class="i-lucide:copy" />
155          </button>
156          <button
157            class="ext-btn ext-btn-toggle ext-btn-spacer"
158            tabindex="-1"
159            aria-hidden="true"
160          >
161            <span class="i-lucide:chevron-down" />
162          </button>
163        </template>
164        <template v-else-if="showActions">
165          <a
166            v-if="installUrl"
167            class="ext-btn ext-btn-install"
168            :href="installUrl"
169          >
170            <span class="i-lucide:download" />
171            <span class="ext-btn-install-label">Install</span>
172          </a>
173          <button
174            v-if="hasCopyButton(scheme)"
175            class="ext-btn ext-btn-copy"
176            type="button"
177            @click="copyUrl"
178          >
179            <span v-if="copiedKey === repo.indexUrl" class="i-lucide:check" />
180            <span v-else class="i-lucide:copy" />
181          </button>
182        </template>
183        <button
184          v-if="!repo.variants"
185          class="ext-btn ext-btn-toggle"
186          type="button"
187          :class="{ open, 'ext-btn-toggle-hidden': !isExpandable }"
188          :aria-expanded="open"
189          :aria-hidden="!isExpandable"
190          :tabindex="isExpandable ? undefined : -1"
191          @click="isExpandable && (open = !open)"
192        >
193          <span class="i-lucide:chevron-down" />
194        </button>
195      </div>
196    </div>
197
198    <div v-if="subVariants.length" class="ext-repo-variants">
199      <RepoVariantRow
200        v-for="variant in subVariants"
201        :key="variant.label"
202        :repo="repo"
203        :variant="variant"
204        :scheme="scheme"
205        :show-actions="showActions"
206        :show-broken="showBroken"
207      />
208    </div>
209
210    <SiteGrid
211      v-if="!repo.variants && isExpandable && open"
212      :sites="sites"
213      :scheme="scheme"
214      empty-text="No site data available."
215    />
216  </div>
217</template>
218
219<style scoped src="./repoRowShared.css"></style>
220
221<style scoped>
222.ext-repo + .ext-repo {
223  border-top: 1px solid var(--vp-c-divider);
224}
225.ext-repo-row {
226  display: flex;
227  align-items: center;
228  justify-content: space-between;
229  gap: 12px;
230  padding: 10px 14px;
231  background-color: var(--vp-c-bg-soft);
232}
233.ext-repo-name {
234  font-size: 14px;
235  font-weight: 600;
236  color: var(--vp-c-text-1);
237  display: flex;
238  align-items: center;
239  gap: 6px;
240  min-width: 0;
241}
242.ext-repo-name :deep(a) {
243  color: inherit;
244}
245.ext-note-btn {
246  display: inline-flex;
247  align-items: center;
248  justify-content: center;
249  padding: 0;
250  margin: 0;
251  border: none;
252  background: transparent;
253  color: var(--vp-c-brand-1);
254  cursor: pointer;
255  line-height: 0;
256  flex-shrink: 0;
257}
258.ext-note-btn span {
259  font-size: 13px;
260  vertical-align: 0;
261}
262.ext-note-popper {
263  max-width: 280px;
264  padding: 10px 12px;
265  border-radius: 8px;
266  border: 2px solid var(--vp-c-divider);
267  background-color: var(--vp-c-bg-elv, var(--vp-c-bg));
268  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
269  font-size: 13px;
270  font-weight: 400;
271  line-height: 1.5;
272  color: var(--vp-c-text-2);
273}
274.ext-repo-variants {
275  display: flex;
276  flex-direction: column;
277}
278</style>