Commit caa6b58017
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/HomeFeatures.vue +126 −90
| @@ -5,18 +5,16 @@ import type { HomeCard } from '../../configs/constants' | ||
| 5 | 5 | |
| 6 | 6 | const props = defineProps<{ cards: HomeCard[] }>() |
| 7 | 7 | |
| 8 | const STORAGE_KEY = 'wotaku-home-cards-v1' | |
| 8 | const STORAGE_KEY = 'wotaku-home-cards-v2' | |
| 9 | 9 | const PREFS_KEY = 'wotaku-home-prefs-v1' |
| 10 | 10 | |
| 11 | 11 | interface CardState { |
| 12 | order: string[] | |
| 13 | hidden: string[] | |
| 12 | homepage: string[] | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | function defaultState(): CardState { |
| 17 | 16 | return { |
| 18 | order: props.cards.map((c) => c.id), | |
| 19 | hidden: props.cards.filter((c) => !c.featured).map((c) => c.id) | |
| 17 | homepage: props.cards.filter((c) => c.featured).map((c) => c.id) | |
| 20 | 18 | } |
| 21 | 19 | } |
| 22 | 20 | |
| @@ -28,12 +26,8 @@ onMounted(() => { | ||
| 28 | 26 | try { |
| 29 | 27 | const parsed: CardState = JSON.parse(raw) |
| 30 | 28 | const allIds = new Set(props.cards.map((c) => c.id)) |
| 31 | const validOrder = parsed.order.filter((id) => allIds.has(id)) | |
| 32 | const seenIds = new Set(validOrder) | |
| 33 | const newIds = props.cards.map((c) => c.id).filter((id) => !seenIds.has(id)) | |
| 34 | 29 | state.value = { |
| 35 | order: [...validOrder, ...newIds], | |
| 36 | hidden: (parsed.hidden ?? []).filter((id: string) => allIds.has(id)) | |
| 30 | homepage: (parsed.homepage ?? []).filter((id) => allIds.has(id)) | |
| 37 | 31 | } |
| 38 | 32 | } catch {} |
| 39 | 33 | }) |
| @@ -44,16 +38,11 @@ function save() { | ||
| 44 | 38 | |
| 45 | 39 | const cardMap = computed(() => new Map(props.cards.map((c) => [c.id, c]))) |
| 46 | 40 | |
| 47 | const orderedCards = computed(() => | |
| 48 | state.value.order.map((id) => cardMap.value.get(id)!).filter(Boolean) | |
| 49 | ) | |
| 50 | ||
| 51 | const hiddenSet = computed(() => new Set(state.value.hidden)) | |
| 41 | const homepageSet = computed(() => new Set(state.value.homepage)) | |
| 52 | 42 | |
| 53 | const visibleCards = computed(() => { | |
| 54 | const base = sortMode.value === 'default' ? props.cards : orderedCards.value | |
| 55 | return base.filter((c) => !hiddenSet.value.has(c.id)) | |
| 56 | }) | |
| 43 | const visibleCards = computed(() => | |
| 44 | state.value.homepage.map((id) => cardMap.value.get(id)!).filter(Boolean) | |
| 45 | ) | |
| 57 | 46 | |
| 58 | 47 | const grid = computed(() => { |
| 59 | 48 | const n = visibleCards.value.length |
| @@ -73,59 +62,61 @@ function cardIcon(card: HomeCard) { | ||
| 73 | 62 | /* ── Manager panel ── */ |
| 74 | 63 | const panelOpen = ref(false) |
| 75 | 64 | const dropdownOpen = ref(false) |
| 76 | const sortMode = ref<'default' | 'user' | 'active'>('default') | |
| 77 | 65 | const columnMode = ref<'default' | 'max'>('default') |
| 78 | 66 | const viewMode = ref<'default' | 'mini'>('default') |
| 79 | 67 | |
| 80 | 68 | onMounted(() => { |
| 81 | 69 | try { |
| 82 | 70 | const prefs = JSON.parse(localStorage.getItem(PREFS_KEY) ?? '{}') |
| 83 | if (prefs.sortMode === 'user') sortMode.value = 'user' | |
| 84 | else if (prefs.sortMode === 'active') sortMode.value = 'active' | |
| 85 | 71 | if (prefs.columnMode === 'max') columnMode.value = 'max' |
| 86 | 72 | if (prefs.viewMode === 'mini') viewMode.value = 'mini' |
| 87 | 73 | } catch {} |
| 88 | 74 | }) |
| 89 | 75 | |
| 90 | watch([sortMode, columnMode, viewMode], () => { | |
| 76 | watch([columnMode, viewMode], () => { | |
| 91 | 77 | localStorage.setItem(PREFS_KEY, JSON.stringify({ |
| 92 | sortMode: sortMode.value, | |
| 93 | 78 | columnMode: columnMode.value, |
| 94 | 79 | viewMode: viewMode.value |
| 95 | 80 | })) |
| 96 | 81 | }) |
| 97 | 82 | |
| 98 | const panelCards = computed(() => { | |
| 99 | if (sortMode.value === 'active') { | |
| 100 | const visible = orderedCards.value.filter((c) => !hiddenSet.value.has(c.id)) | |
| 101 | const hidden = orderedCards.value.filter((c) => hiddenSet.value.has(c.id)) | |
| 102 | return [...visible, ...hidden] | |
| 83 | const homepageSectionCards = computed(() => | |
| 84 | state.value.homepage.map((id) => cardMap.value.get(id)!).filter(Boolean) | |
| 85 | ) | |
| 86 | ||
| 87 | const otherSections = computed(() => { | |
| 88 | const sectionMap = new Map<string, HomeCard[]>() | |
| 89 | for (const card of props.cards) { | |
| 90 | const s = card.section ?? 'Pages' | |
| 91 | if (!sectionMap.has(s)) sectionMap.set(s, []) | |
| 92 | if (!homepageSet.value.has(card.id)) sectionMap.get(s)!.push(card) | |
| 103 | 93 | } |
| 104 | if (sortMode.value === 'user') return orderedCards.value | |
| 105 | return props.cards | |
| 94 | return Array.from(sectionMap.entries()).map(([label, cards]) => ({ label, cards })) | |
| 106 | 95 | }) |
| 107 | 96 | |
| 108 | 97 | function toggleCard(id: string) { |
| 109 | const h = state.value.hidden | |
| 110 | const i = h.indexOf(id) | |
| 111 | if (i === -1) h.push(id) | |
| 112 | else h.splice(i, 1) | |
| 98 | if (homepageSet.value.has(id)) { | |
| 99 | state.value.homepage = state.value.homepage.filter((hid) => hid !== id) | |
| 100 | } else { | |
| 101 | state.value.homepage.push(id) | |
| 102 | } | |
| 113 | 103 | save() |
| 114 | 104 | } |
| 115 | 105 | |
| 116 | 106 | function showAll() { |
| 117 | state.value.hidden = [] | |
| 107 | const current = new Set(state.value.homepage) | |
| 108 | const toAdd = props.cards.filter((c) => !current.has(c.id)).map((c) => c.id) | |
| 109 | state.value.homepage = [...state.value.homepage, ...toAdd] | |
| 118 | 110 | save() |
| 119 | 111 | } |
| 120 | 112 | |
| 121 | 113 | function hideAll() { |
| 122 | state.value.hidden = props.cards.map((c) => c.id) | |
| 114 | state.value.homepage = [] | |
| 123 | 115 | save() |
| 124 | 116 | } |
| 125 | 117 | |
| 126 | 118 | function resetDefaults() { |
| 127 | 119 | state.value = defaultState() |
| 128 | sortMode.value = 'default' | |
| 129 | 120 | columnMode.value = 'default' |
| 130 | 121 | viewMode.value = 'default' |
| 131 | 122 | save() |
| @@ -142,17 +133,7 @@ function hideCardTooltip() { | ||
| 142 | 133 | cardTooltip.value = null |
| 143 | 134 | } |
| 144 | 135 | |
| 145 | const panelSections = computed(() => { | |
| 146 | const map = new Map<string, typeof panelCards.value>() | |
| 147 | for (const card of panelCards.value) { | |
| 148 | const s = card.section ?? 'Pages' | |
| 149 | if (!map.has(s)) map.set(s, []) | |
| 150 | map.get(s)!.push(card) | |
| 151 | } | |
| 152 | return Array.from(map.entries()).map(([label, cards]) => ({ label, cards })) | |
| 153 | }) | |
| 154 | ||
| 155 | /* ── Drag-to-reorder (pointer events — works on mouse & touch) ── */ | |
| 136 | /* ── Drag-to-reorder (homepage only, pointer events) ── */ | |
| 156 | 137 | const dragging = ref<string | null>(null) |
| 157 | 138 | const dragTarget = ref<string | null>(null) |
| 158 | 139 | const cardListEl = ref<HTMLElement | null>(null) |
| @@ -186,15 +167,14 @@ function onHandlePointerMove(e: PointerEvent) { | ||
| 186 | 167 | |
| 187 | 168 | function onHandlePointerUp() { |
| 188 | 169 | if (dragging.value && dragTarget.value) { |
| 189 | const order = [...state.value.order] | |
| 170 | const order = [...state.value.homepage] | |
| 190 | 171 | const from = order.indexOf(dragging.value) |
| 191 | 172 | const to = order.indexOf(dragTarget.value) |
| 192 | 173 | if (from !== -1 && to !== -1) { |
| 193 | 174 | order.splice(from, 1) |
| 194 | 175 | order.splice(to, 0, dragging.value) |
| 195 | state.value.order = order | |
| 176 | state.value.homepage = order | |
| 196 | 177 | save() |
| 197 | if (sortMode.value === 'default') sortMode.value = 'user' | |
| 198 | 178 | } |
| 199 | 179 | } |
| 200 | 180 | dragging.value = null |
| @@ -242,41 +222,69 @@ function onHandlePointerUp() { | ||
| 242 | 222 | </button> |
| 243 | 223 | </div> |
| 244 | 224 | |
| 245 | <div ref="cardListEl" class="card-sections"> | |
| 246 | <template v-for="section in panelSections" :key="section.label"> | |
| 247 | <div v-if="panelSections.length > 1" class="section-label">{{ section.label }}</div> | |
| 225 | <div class="card-sections"> | |
| 226 | <!-- Homepage section (draggable) --> | |
| 227 | <div class="section-label">Homepage</div> | |
| 228 | <ul ref="cardListEl" class="card-list" :class="grid"> | |
| 229 | <li v-if="homepageSectionCards.length === 0" class="empty-box"> | |
| 230 | <span class="empty-hint">No cards selected — add some from below</span> | |
| 231 | </li> | |
| 232 | <li | |
| 233 | v-for="card in homepageSectionCards" | |
| 234 | :key="card.id" | |
| 235 | :data-card-id="card.id" | |
| 236 | class="card-row" | |
| 237 | @mouseenter="showCardTooltip($event, card.title)" | |
| 238 | @mouseleave="hideCardTooltip" | |
| 239 | :class="{ | |
| 240 | 'is-dragging': dragging === card.id, | |
| 241 | 'is-over': dragTarget === card.id && dragging !== card.id | |
| 242 | }" | |
| 243 | > | |
| 244 | <span | |
| 245 | class="row-handle" | |
| 246 | aria-hidden="true" | |
| 247 | @pointerdown="onHandlePointerDown($event, card.id)" | |
| 248 | @pointermove="onHandlePointerMove" | |
| 249 | @pointerup="onHandlePointerUp" | |
| 250 | > | |
| 251 | <span class="i-lucide-grip-vertical" /> | |
| 252 | </span> | |
| 253 | <span class="row-icon" v-html="cardIcon(card)" /> | |
| 254 | <span class="row-name">{{ card.title }}</span> | |
| 255 | <button | |
| 256 | class="row-toggle active" | |
| 257 | aria-label="Remove from homepage" | |
| 258 | @click="toggleCard(card.id)" | |
| 259 | > | |
| 260 | <span class="i-lucide-eye" /> | |
| 261 | </button> | |
| 262 | </li> | |
| 263 | </ul> | |
| 264 | ||
| 265 | <!-- Other sections (Pages, Extensions, Other…) --> | |
| 266 | <template v-for="section in otherSections" :key="section.label"> | |
| 267 | <div class="section-label">{{ section.label }}</div> | |
| 248 | 268 | <ul class="card-list" :class="grid"> |
| 269 | <li v-if="section.cards.length === 0" class="empty-box"> | |
| 270 | <span class="empty-hint">All cards from this section have been selected</span> | |
| 271 | </li> | |
| 249 | 272 | <li |
| 250 | 273 | v-for="card in section.cards" |
| 251 | 274 | :key="card.id" |
| 252 | :data-card-id="card.id" | |
| 253 | class="card-row" | |
| 275 | class="card-row card-row-unselected" | |
| 254 | 276 | @mouseenter="showCardTooltip($event, card.title)" |
| 255 | 277 | @mouseleave="hideCardTooltip" |
| 256 | :class="{ | |
| 257 | 'is-dragging': dragging === card.id, | |
| 258 | 'is-over': dragTarget === card.id && dragging !== card.id, | |
| 259 | 'is-hidden': hiddenSet.has(card.id) | |
| 260 | }" | |
| 261 | 278 | > |
| 262 | <span | |
| 263 | class="row-handle" | |
| 264 | aria-hidden="true" | |
| 265 | @pointerdown="onHandlePointerDown($event, card.id)" | |
| 266 | @pointermove="onHandlePointerMove" | |
| 267 | @pointerup="onHandlePointerUp" | |
| 268 | > | |
| 269 | <span class="i-lucide-grip-vertical" /> | |
| 270 | </span> | |
| 279 | <span class="row-handle-spacer" aria-hidden="true" /> | |
| 271 | 280 | <span class="row-icon" v-html="cardIcon(card)" /> |
| 272 | 281 | <span class="row-name">{{ card.title }}</span> |
| 273 | 282 | <button |
| 274 | 283 | class="row-toggle" |
| 275 | :class="{ active: !hiddenSet.has(card.id) }" | |
| 276 | :aria-label="hiddenSet.has(card.id) ? 'Show' : 'Hide'" | |
| 284 | aria-label="Add to homepage" | |
| 277 | 285 | @click="toggleCard(card.id)" |
| 278 | 286 | > |
| 279 | <span :class="hiddenSet.has(card.id) ? 'i-lucide-eye-off' : 'i-lucide-eye'" /> | |
| 287 | <span class="i-lucide-eye-off" /> | |
| 280 | 288 | </button> |
| 281 | 289 | </li> |
| 282 | 290 | </ul> |
| @@ -296,14 +304,6 @@ function onHandlePointerUp() { | ||
| 296 | 304 | <div class="settings-wrap"> |
| 297 | 305 | <div v-if="dropdownOpen" class="dropdown-overlay" @click="dropdownOpen = false" /> |
| 298 | 306 | <div v-if="dropdownOpen" class="settings-dropdown"> |
| 299 | <div class="dropdown-section"> | |
| 300 | <span class="dropdown-label">Sort</span> | |
| 301 | <div class="dropdown-group"> | |
| 302 | <button class="tool-btn" :class="{ 'is-active': sortMode === 'default' }" @click="sortMode = 'default'">Default</button> | |
| 303 | <button class="tool-btn" :class="{ 'is-active': sortMode === 'user' }" @click="sortMode = 'user'">User</button> | |
| 304 | <button class="tool-btn" :class="{ 'is-active': sortMode === 'active' }" @click="sortMode = 'active'">Active</button> | |
| 305 | </div> | |
| 306 | </div> | |
| 307 | 307 | <div class="dropdown-section"> |
| 308 | 308 | <span class="dropdown-label">View</span> |
| 309 | 309 | <div class="dropdown-group"> |
| @@ -637,13 +637,16 @@ function onHandlePointerUp() { | ||
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | @media (min-width: 640px) { |
| 640 | .card-list { grid-template-columns: 1fr 1fr; } | |
| 640 | .card-list.grid-2, | |
| 641 | .card-list.grid-4, | |
| 642 | .card-list.grid-6, | |
| 643 | .card-list.grid-max { grid-template-columns: 1fr 1fr; } | |
| 641 | 644 | } |
| 642 | 645 | |
| 643 | 646 | @media (min-width: 768px) { |
| 644 | .card-list { grid-template-columns: 1fr 1fr 1fr; } | |
| 645 | .card-list.grid-2, | |
| 646 | .card-list.grid-4 { grid-template-columns: 1fr 1fr; } | |
| 647 | .card-list.grid-3, | |
| 648 | .card-list.grid-6, | |
| 649 | .card-list.grid-max { grid-template-columns: 1fr 1fr 1fr; } | |
| 647 | 650 | } |
| 648 | 651 | |
| 649 | 652 | @media (min-width: 960px) { |
| @@ -666,6 +669,38 @@ function onHandlePointerUp() { | ||
| 666 | 669 | background: var(--vp-c-bg-soft); |
| 667 | 670 | } |
| 668 | 671 | |
| 672 | .card-row-unselected { | |
| 673 | opacity: 0.45; | |
| 674 | } | |
| 675 | ||
| 676 | .card-row-unselected:hover { | |
| 677 | opacity: 1; | |
| 678 | } | |
| 679 | ||
| 680 | .empty-box { | |
| 681 | grid-column: 1 / -1; | |
| 682 | list-style: none; | |
| 683 | border-radius: 8px; | |
| 684 | padding: 14px 16px; | |
| 685 | display: flex; | |
| 686 | align-items: center; | |
| 687 | justify-content: center; | |
| 688 | background-image: | |
| 689 | linear-gradient(90deg, var(--vp-c-divider) 6px, transparent 6px), | |
| 690 | linear-gradient(90deg, var(--vp-c-divider) 6px, transparent 6px), | |
| 691 | linear-gradient(0deg, var(--vp-c-divider) 6px, transparent 6px), | |
| 692 | linear-gradient(0deg, var(--vp-c-divider) 6px, transparent 6px); | |
| 693 | background-size: 10px 1px, 10px 1px, 1px 10px, 1px 10px; | |
| 694 | background-position: top left, bottom left, top left, top right; | |
| 695 | background-repeat: repeat-x, repeat-x, repeat-y, repeat-y; | |
| 696 | } | |
| 697 | ||
| 698 | .empty-hint { | |
| 699 | font-size: 13px; | |
| 700 | color: var(--vp-c-text-3, var(--vp-c-text-2)); | |
| 701 | font-style: italic; | |
| 702 | } | |
| 703 | ||
| 669 | 704 | .card-tooltip { |
| 670 | 705 | position: fixed; |
| 671 | 706 | z-index: 9999; |
| @@ -691,10 +726,6 @@ function onHandlePointerUp() { | ||
| 691 | 726 | outline-offset: -2px; |
| 692 | 727 | } |
| 693 | 728 | |
| 694 | .card-row.is-hidden { | |
| 695 | opacity: 0.45; | |
| 696 | } | |
| 697 | ||
| 698 | 729 | .row-handle { |
| 699 | 730 | color: var(--vp-c-text-3, var(--vp-c-text-2)); |
| 700 | 731 | font-size: 16px; |
| @@ -709,6 +740,11 @@ function onHandlePointerUp() { | ||
| 709 | 740 | cursor: grabbing; |
| 710 | 741 | } |
| 711 | 742 | |
| 743 | .row-handle-spacer { | |
| 744 | width: 16px; | |
| 745 | flex-shrink: 0; | |
| 746 | } | |
| 747 | ||
| 712 | 748 | .row-icon { |
| 713 | 749 | font-size: 18px; |
| 714 | 750 | flex-shrink: 0; |