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

7b774cae81351666b54bdca55c379582beb10043
wotaku/docs/.vitepress/theme/components/extrepo/SiteGrid.vue

80 lines · 2036 bytes

 1<script setup lang="ts">
 2import { computed, ref } from 'vue'
 3import SiteCell from './SiteCell.vue'
 4import SiteGroupCell from './SiteGroupCell.vue'
 5import type { RepoSite } from './types'
 6
 7const props = defineProps<{
 8  sites: (RepoSite & { repoName?: string })[]
 9  emptyText: string
10  scheme?: string
11}>()
12
13interface SiteGroup {
14  key: string
15  sites: (RepoSite & { repoName?: string })[]
16}
17
18const groups = computed<SiteGroup[]>(() => {
19  const map = new Map<string, SiteGroup>()
20  props.sites.forEach((site, i) => {
21    const key = site.url ? `${site.repoName ?? ''}-${site.url}` : `no-url-${i}`
22    let group = map.get(key)
23    if (!group) {
24      group = { key, sites: [] }
25      map.set(key, group)
26    }
27    group.sites.push(site)
28  })
29  return [...map.values()]
30})
31
32const openGroups = ref<Set<string>>(new Set())
33
34function toggleGroup(key: string) {
35  const next = new Set(openGroups.value)
36  if (next.has(key)) next.delete(key)
37  else next.add(key)
38  openGroups.value = next
39}
40</script>
41
42<template>
43  <div class="ext-site-grid">
44    <div v-if="sites.length === 0" class="ext-site-empty">
45      {{ emptyText }}
46    </div>
47    <template v-for="group in groups" :key="group.key">
48      <SiteCell v-if="group.sites.length === 1" :site="group.sites[0]" :scheme="scheme" />
49      <template v-else>
50        <SiteGroupCell
51          :sites="group.sites"
52          :open="openGroups.has(group.key)"
53          @toggle="toggleGroup(group.key)"
54        />
55        <template v-if="openGroups.has(group.key)">
56          <SiteCell v-for="site in group.sites" :key="`${group.key}-${site.lang}`" :site="site" :scheme="scheme" />
57        </template>
58      </template>
59    </template>
60  </div>
61</template>
62
63<style scoped>
64.ext-site-grid {
65  display: grid;
66  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
67  gap: 6px;
68  padding: 10px;
69  max-height: 340px;
70  overflow-y: auto;
71  background-color: var(--vp-c-bg);
72}
73
74.ext-site-empty {
75  grid-column: 1 / -1;
76  color: var(--vp-c-text-2);
77  font-size: 13px;
78  padding: 8px 4px;
79}
80</style>
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