Commit 28adf8f579
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/BookmarksPanel.vue +184 −40
| @@ -79,7 +79,9 @@ function flattenSidebarPaths(items: DefaultTheme.SidebarItem[]): string[] { | |||
| 79 | return paths | 79 | return paths |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | const sidebarPathOrder = flattenSidebarPaths(Array.isArray(sidebar) ? sidebar : Object.values(sidebar).flat()) | 82 | const sidebarPathOrder = flattenSidebarPaths( |
| 83 | Array.isArray(sidebar) ? sidebar : Object.values(sidebar).flat() | ||
| 84 | ) | ||
| 83 | 85 | ||
| 84 | function sidebarIndex(path: string): number { | 86 | function sidebarIndex(path: string): number { |
| 85 | const exact = sidebarPathOrder.indexOf(path) | 87 | const exact = sidebarPathOrder.indexOf(path) |
| @@ -99,7 +101,10 @@ function getPageCard(path: string): HomeCard | null { | |||
| 99 | let best: HomeCard | null = null | 101 | let best: HomeCard | null = null |
| 100 | let bestLen = 0 | 102 | let bestLen = 0 |
| 101 | for (const card of homeCards) { | 103 | for (const card of homeCards) { |
| 102 | if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) { | 104 | if ( |
| 105 | (path === card.link || path.startsWith(card.link + '/')) && | ||
| 106 | card.link.length > bestLen | ||
| 107 | ) { | ||
| 103 | best = card | 108 | best = card |
| 104 | bestLen = card.link.length | 109 | bestLen = card.link.length |
| 105 | } | 110 | } |
| @@ -108,8 +113,18 @@ function getPageCard(path: string): HomeCard | null { | |||
| 108 | } | 113 | } |
| 109 | 114 | ||
| 110 | type PageGroup = { path: string; card: HomeCard | null; items: BookmarkItem[] } | 115 | type PageGroup = { path: string; card: HomeCard | null; items: BookmarkItem[] } |
| 111 | type TopLevelEntry = { type: 'page'; path: string; card: HomeCard | null; items: BookmarkItem[] } | 116 | type TopLevelEntry = { |
| 112 | type FolderEntry = { type: 'folder'; section: string; parentCard: HomeCard | null; pages: PageGroup[] } | 117 | type: 'page' |
| 118 | path: string | ||
| 119 | card: HomeCard | null | ||
| 120 | items: BookmarkItem[] | ||
| 121 | } | ||
| 122 | type FolderEntry = { | ||
| 123 | type: 'folder' | ||
| 124 | section: string | ||
| 125 | parentCard: HomeCard | null | ||
| 126 | pages: PageGroup[] | ||
| 127 | } | ||
| 113 | type GroupEntry = TopLevelEntry | FolderEntry | 128 | type GroupEntry = TopLevelEntry | FolderEntry |
| 114 | 129 | ||
| 115 | const grouped = computed((): GroupEntry[] => { | 130 | const grouped = computed((): GroupEntry[] => { |
| @@ -140,13 +155,27 @@ const grouped = computed((): GroupEntry[] => { | |||
| 140 | // Build folder entries, sorted by parent card's sidebar position | 155 | // Build folder entries, sorted by parent card's sidebar position |
| 141 | const folderEntries: FolderEntry[] = [...folderMap.entries()] | 156 | const folderEntries: FolderEntry[] = [...folderMap.entries()] |
| 142 | .map(([section, paths]) => { | 157 | .map(([section, paths]) => { |
| 143 | const parentCard = homeCards.find(c => c.title === section && !c.section) ?? null | 158 | const parentCard = homeCards.find(c => |
| 159 | c.title === section && !c.section | ||
| 160 | ) ?? null | ||
| 144 | const sortedPages = [...paths] | 161 | const sortedPages = [...paths] |
| 145 | .sort((a, b) => sidebarIndex(a) - sidebarIndex(b)) | 162 | .sort((a, b) => sidebarIndex(a) - sidebarIndex(b)) |
| 146 | .map(path => ({ path, card: getPageCard(path), items: byPath.get(path)! })) | 163 | .map(path => ({ |
| 147 | return { type: 'folder' as const, section, parentCard, pages: sortedPages } | 164 | path, |
| 165 | card: getPageCard(path), | ||
| 166 | items: byPath.get(path)! | ||
| 167 | })) | ||
| 168 | return { | ||
| 169 | type: 'folder' as const, | ||
| 170 | section, | ||
| 171 | parentCard, | ||
| 172 | pages: sortedPages | ||
| 173 | } | ||
| 148 | }) | 174 | }) |
| 149 | .sort((a, b) => sidebarIndex(a.parentCard?.link ?? '') - sidebarIndex(b.parentCard?.link ?? '')) | 175 | .sort((a, b) => |
| 176 | sidebarIndex(a.parentCard?.link ?? '') - | ||
| 177 | sidebarIndex(b.parentCard?.link ?? '') | ||
| 178 | ) | ||
| 150 | 179 | ||
| 151 | // Merge top-level and folder entries in sidebar order | 180 | // Merge top-level and folder entries in sidebar order |
| 152 | const topEntries: TopLevelEntry[] = topPages.map(path => ({ | 181 | const topEntries: TopLevelEntry[] = topPages.map(path => ({ |
| @@ -157,8 +186,12 @@ const grouped = computed((): GroupEntry[] => { | |||
| 157 | })) | 186 | })) |
| 158 | 187 | ||
| 159 | return [...topEntries, ...folderEntries].sort((a, b) => { | 188 | return [...topEntries, ...folderEntries].sort((a, b) => { |
| 160 | const ai = a.type === 'page' ? sidebarIndex(a.path) : sidebarIndex(a.parentCard?.link ?? '') | 189 | const ai = a.type === 'page' |
| 161 | const bi = b.type === 'page' ? sidebarIndex(b.path) : sidebarIndex(b.parentCard?.link ?? '') | 190 | ? sidebarIndex(a.path) |
| 191 | : sidebarIndex(a.parentCard?.link ?? '') | ||
| 192 | const bi = b.type === 'page' | ||
| 193 | ? sidebarIndex(b.path) | ||
| 194 | : sidebarIndex(b.parentCard?.link ?? '') | ||
| 162 | return ai - bi | 195 | return ai - bi |
| 163 | }) | 196 | }) |
| 164 | }) | 197 | }) |
| @@ -178,9 +211,21 @@ const grouped = computed((): GroupEntry[] => { | |||
| 178 | </button> | 211 | </button> |
| 179 | 212 | ||
| 180 | <Transition name="bookmarks-panel"> | 213 | <Transition name="bookmarks-panel"> |
| 181 | <div v-if="isOpen" ref="panelRef" class="bookmarks-panel" :style="panelStyle" role="dialog" aria-label="Bookmarks"> | 214 | <div |
| 215 | v-if="isOpen" | ||
| 216 | ref="panelRef" | ||
| 217 | class="bookmarks-panel" | ||
| 218 | :style="panelStyle" | ||
| 219 | role="dialog" | ||
| 220 | aria-label="Bookmarks" | ||
| 221 | > | ||
| 182 | <div class="bookmarks-mobile-header"> | 222 | <div class="bookmarks-mobile-header"> |
| 183 | <button type="button" class="bookmarks-mobile-back" aria-label="Back" @click="isOpen = false"> | 223 | <button |
| 224 | type="button" | ||
| 225 | class="bookmarks-mobile-back" | ||
| 226 | aria-label="Back" | ||
| 227 | @click="isOpen = false" | ||
| 228 | > | ||
| 184 | <ArrowLeft :size="18" :stroke-width="2" /> | 229 | <ArrowLeft :size="18" :stroke-width="2" /> |
| 185 | </button> | 230 | </button> |
| 186 | <span class="bookmarks-mobile-title">Bookmarks</span> | 231 | <span class="bookmarks-mobile-title">Bookmarks</span> |
| @@ -192,27 +237,81 @@ const grouped = computed((): GroupEntry[] => { | |||
| 192 | > | 237 | > |
| 193 | <div v-if="bookmarks.length === 0" class="bookmarks-empty"> | 238 | <div v-if="bookmarks.length === 0" class="bookmarks-empty"> |
| 194 | <span class="bookmarks-empty-kaomoji">(˶ᵔ ᵕ ᵔ˶)</span> | 239 | <span class="bookmarks-empty-kaomoji">(˶ᵔ ᵕ ᵔ˶)</span> |
| 195 | <p class="bookmarks-empty-hint bookmarks-empty-hint--desktop">Tip: Hover over any primary heading under <strong>On this page</strong> and click <Bookmark :size="13" :stroke-width="2" class="bookmarks-empty-inline-icon" /> to bookmark it.</p> | 240 | <p class="bookmarks-empty-hint bookmarks-empty-hint--desktop"> |
| 196 | <p class="bookmarks-empty-hint bookmarks-empty-hint--mobile">Tip: Tap <strong>On this page</strong> and press <Bookmark :size="13" :stroke-width="2" class="bookmarks-empty-inline-icon" /> next to any primary heading to bookmark it.</p> | 241 | Tip: Hover over any primary heading under <strong>On this |
| 242 | page</strong> and click <Bookmark | ||
| 243 | :size="13" | ||
| 244 | :stroke-width="2" | ||
| 245 | class="bookmarks-empty-inline-icon" | ||
| 246 | /> to bookmark it. | ||
| 247 | </p> | ||
| 248 | <p class="bookmarks-empty-hint bookmarks-empty-hint--mobile"> | ||
| 249 | Tip: Tap <strong>On this page</strong> and press <Bookmark | ||
| 250 | :size="13" | ||
| 251 | :stroke-width="2" | ||
| 252 | class="bookmarks-empty-inline-icon" | ||
| 253 | /> next to any primary heading to bookmark it. | ||
| 254 | </p> | ||
| 197 | </div> | 255 | </div> |
| 198 | <div v-else class="bookmarks-groups"> | 256 | <div v-else class="bookmarks-groups"> |
| 199 | <template v-for="group in grouped" :key="group.type === 'page' ? group.path : group.section"> | 257 | <template |
| 200 | 258 | v-for="group in grouped" | |
| 259 | :key="group.type === 'page' ? group.path : group.section" | ||
| 260 | > | ||
| 201 | <!-- Top-level page (no folder) --> | 261 | <!-- Top-level page (no folder) --> |
| 202 | <div v-if="group.type === 'page'" class="bookmarks-group"> | 262 | <div v-if="group.type === 'page'" class="bookmarks-group"> |
| 203 | <h3 class="bookmarks-group-title"> | 263 | <h3 class="bookmarks-group-title"> |
| 204 | <span v-if="group.card" :class="cardIconToClass(group.card.icon)" class="bookmarks-group-icon" /> | 264 | <span |
| 205 | <span v-else class="i-lucide:file-text bookmarks-group-icon" /> | 265 | v-if="group.card" |
| 206 | <span class="bookmarks-group-text">{{ group.card?.title ?? group.path }}</span> | 266 | :class="cardIconToClass(group.card.icon)" |
| 267 | class="bookmarks-group-icon" | ||
| 268 | /> | ||
| 269 | <span | ||
| 270 | v-else | ||
| 271 | class="i-lucide:file-text bookmarks-group-icon" | ||
| 272 | /> | ||
| 273 | <span class="bookmarks-group-text">{{ | ||
| 274 | group.card?.title ?? group.path | ||
| 275 | }}</span> | ||
| 207 | </h3> | 276 | </h3> |
| 208 | <ul class="bookmarks-list"> | 277 | <ul class="bookmarks-list"> |
| 209 | <li v-for="bm in group.items" :key="bm.anchor" class="bookmarks-item"> | 278 | <li |
| 210 | <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false"> | 279 | v-for="bm in group.items" |
| 211 | <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" /> | 280 | :key="bm.anchor" |
| 281 | class="bookmarks-item" | ||
| 282 | > | ||
| 283 | <a | ||
| 284 | class="bookmarks-item-link" | ||
| 285 | :href="bm.path + '#' + bm.anchor" | ||
| 286 | @click="isOpen = false" | ||
| 287 | > | ||
| 288 | <Hash | ||
| 289 | :size="12" | ||
| 290 | :stroke-width="2" | ||
| 291 | class="bookmarks-item-icon" | ||
| 292 | /> | ||
| 212 | {{ bm.title }} | 293 | {{ bm.title }} |
| 213 | </a> | 294 | </a> |
| 214 | <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)"> | 295 | <button |
| 215 | <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg> | 296 | type="button" |
| 297 | class="bookmarks-item-remove" | ||
| 298 | :aria-label="`Remove bookmark for ${bm.title}`" | ||
| 299 | @click.stop="remove(bm.anchor, bm.path)" | ||
| 300 | > | ||
| 301 | <svg | ||
| 302 | xmlns="http://www.w3.org/2000/svg" | ||
| 303 | width="11" | ||
| 304 | height="11" | ||
| 305 | viewBox="0 0 24 24" | ||
| 306 | fill="none" | ||
| 307 | stroke="currentColor" | ||
| 308 | stroke-width="2.5" | ||
| 309 | stroke-linecap="round" | ||
| 310 | stroke-linejoin="round" | ||
| 311 | > | ||
| 312 | <path d="M18 6 6 18" /> | ||
| 313 | <path d="m6 6 12 12" /> | ||
| 314 | </svg> | ||
| 216 | </button> | 315 | </button> |
| 217 | </li> | 316 | </li> |
| 218 | </ul> | 317 | </ul> |
| @@ -221,31 +320,73 @@ const grouped = computed((): GroupEntry[] => { | |||
| 221 | <!-- Folder group (e.g. Guides, Glossary) --> | 320 | <!-- Folder group (e.g. Guides, Glossary) --> |
| 222 | <div v-else class="bookmarks-group"> | 321 | <div v-else class="bookmarks-group"> |
| 223 | <h3 class="bookmarks-group-title"> | 322 | <h3 class="bookmarks-group-title"> |
| 224 | <span v-if="group.parentCard" :class="cardIconToClass(group.parentCard.icon)" class="bookmarks-group-icon" /> | 323 | <span |
| 324 | v-if="group.parentCard" | ||
| 325 | :class="cardIconToClass(group.parentCard.icon)" | ||
| 326 | class="bookmarks-group-icon" | ||
| 327 | /> | ||
| 225 | <span v-else class="i-lucide:folder bookmarks-group-icon" /> | 328 | <span v-else class="i-lucide:folder bookmarks-group-icon" /> |
| 226 | <span class="bookmarks-group-text">{{ group.section }}</span> | 329 | <span class="bookmarks-group-text">{{ group.section }}</span> |
| 227 | </h3> | 330 | </h3> |
| 228 | <div v-for="page in group.pages" :key="page.path" class="bookmarks-sub-group"> | 331 | <div |
| 229 | <h4 class="bookmarks-sub-title">{{ page.card?.title ?? page.path }}</h4> | 332 | v-for="page in group.pages" |
| 333 | :key="page.path" | ||
| 334 | class="bookmarks-sub-group" | ||
| 335 | > | ||
| 336 | <h4 class="bookmarks-sub-title"> | ||
| 337 | {{ page.card?.title ?? page.path }} | ||
| 338 | </h4> | ||
| 230 | <ul class="bookmarks-list"> | 339 | <ul class="bookmarks-list"> |
| 231 | <li v-for="bm in page.items" :key="bm.anchor" class="bookmarks-item"> | 340 | <li |
| 232 | <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false"> | 341 | v-for="bm in page.items" |
| 233 | <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" /> | 342 | :key="bm.anchor" |
| 343 | class="bookmarks-item" | ||
| 344 | > | ||
| 345 | <a | ||
| 346 | class="bookmarks-item-link" | ||
| 347 | :href="bm.path + '#' + bm.anchor" | ||
| 348 | @click="isOpen = false" | ||
| 349 | > | ||
| 350 | <Hash | ||
| 351 | :size="12" | ||
| 352 | :stroke-width="2" | ||
| 353 | class="bookmarks-item-icon" | ||
| 354 | /> | ||
| 234 | {{ bm.title }} | 355 | {{ bm.title }} |
| 235 | </a> | 356 | </a> |
| 236 | <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)"> | 357 | <button |
| 237 | <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg> | 358 | type="button" |
| 359 | class="bookmarks-item-remove" | ||
| 360 | :aria-label="`Remove bookmark for ${bm.title}`" | ||
| 361 | @click.stop="remove(bm.anchor, bm.path)" | ||
| 362 | > | ||
| 363 | <svg | ||
| 364 | xmlns="http://www.w3.org/2000/svg" | ||
| 365 | width="11" | ||
| 366 | height="11" | ||
| 367 | viewBox="0 0 24 24" | ||
| 368 | fill="none" | ||
| 369 | stroke="currentColor" | ||
| 370 | stroke-width="2.5" | ||
| 371 | stroke-linecap="round" | ||
| 372 | stroke-linejoin="round" | ||
| 373 | > | ||
| 374 | <path d="M18 6 6 18" /> | ||
| 375 | <path d="m6 6 12 12" /> | ||
| 376 | </svg> | ||
| 238 | </button> | 377 | </button> |
| 239 | </li> | 378 | </li> |
| 240 | </ul> | 379 | </ul> |
| 241 | </div> | 380 | </div> |
| 242 | </div> | 381 | </div> |
| 243 | |||
| 244 | </template> | 382 | </template> |
| 245 | </div> | 383 | </div> |
| 246 | </div> | 384 | </div> |
| 247 | <Transition name="bookmarks-fade"> | 385 | <Transition name="bookmarks-fade"> |
| 248 | <div v-if="showFade && bookmarks.length > 0" class="bookmarks-fade-overlay" /> | 386 | <div |
| 387 | v-if="showFade && bookmarks.length > 0" | ||
| 388 | class="bookmarks-fade-overlay" | ||
| 389 | /> | ||
| 249 | </Transition> | 390 | </Transition> |
| 250 | </div> | 391 | </div> |
| 251 | </Transition> | 392 | </Transition> |
| @@ -270,13 +411,15 @@ const grouped = computed((): GroupEntry[] => { | |||
| 270 | height: 100%; | 411 | height: 100%; |
| 271 | color: var(--vp-c-text-1); | 412 | color: var(--vp-c-text-1); |
| 272 | opacity: 0.55; | 413 | opacity: 0.55; |
| 273 | transition: | 414 | transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); |
| 274 | opacity 0.25s, | ||
| 275 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 276 | } | 415 | } |
| 277 | 416 | ||
| 278 | .bookmarks-btn:hover { opacity: 1; } | 417 | .bookmarks-btn:hover { |
| 279 | .bookmarks-btn:active { transform: scale(0.94); } | 418 | opacity: 1; |
| 419 | } | ||
| 420 | .bookmarks-btn:active { | ||
| 421 | transform: scale(0.94); | ||
| 422 | } | ||
| 280 | 423 | ||
| 281 | .bookmarks-panel { | 424 | .bookmarks-panel { |
| 282 | position: absolute; | 425 | position: absolute; |
| @@ -481,7 +624,8 @@ const grouped = computed((): GroupEntry[] => { | |||
| 481 | .bookmarks-panel-enter-from, | 624 | .bookmarks-panel-enter-from, |
| 482 | .bookmarks-panel-leave-to { | 625 | .bookmarks-panel-leave-to { |
| 483 | opacity: 0; | 626 | opacity: 0; |
| 484 | transform: translateX(var(--bookmarks-panel-shift, -50%)) scale(0.95) translateY(-4px); | 627 | transform: translateX(var(--bookmarks-panel-shift, -50%)) scale(0.95) |
| 628 | translateY(-4px); | ||
| 485 | } | 629 | } |
| 486 | 630 | ||
| 487 | .bookmarks-fade-enter-active, | 631 | .bookmarks-fade-enter-active, |
docs/.vitepress/theme/components/search/SearchRibbon.vue +207 −50
| @@ -1,7 +1,18 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { | ||
| 3 | onClickOutside, | ||
| 4 | useElementBounding, | ||
| 5 | useEventListener | ||
| 6 | } from '@vueuse/core' | ||
| 2 | import { ChevronLeft, ChevronRight, Menu } from 'lucide-vue-next' | 7 | import { ChevronLeft, ChevronRight, Menu } from 'lucide-vue-next' |
| 3 | import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' | 8 | import { |
| 4 | import { onClickOutside, useEventListener } from '@vueuse/core' | 9 | computed, |
| 10 | nextTick, | ||
| 11 | onBeforeUnmount, | ||
| 12 | ref, | ||
| 13 | shallowRef, | ||
| 14 | watch | ||
| 15 | } from 'vue' | ||
| 5 | import { homeCards } from '../../../configs/constants' | 16 | import { homeCards } from '../../../configs/constants' |
| 6 | import type { HomeCard } from '../../../configs/constants' | 17 | import type { HomeCard } from '../../../configs/constants' |
| 7 | 18 | ||
| @@ -34,7 +45,10 @@ function getPageCard(path: string): HomeCard | null { | |||
| 34 | let best: HomeCard | null = null | 45 | let best: HomeCard | null = null |
| 35 | let bestLen = 0 | 46 | let bestLen = 0 |
| 36 | for (const card of homeCards) { | 47 | for (const card of homeCards) { |
| 37 | if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) { | 48 | if ( |
| 49 | (path === card.link || path.startsWith(card.link + '/')) && | ||
| 50 | card.link.length > bestLen | ||
| 51 | ) { | ||
| 38 | best = card | 52 | best = card |
| 39 | bestLen = card.link.length | 53 | bestLen = card.link.length |
| 40 | } | 54 | } |
| @@ -74,6 +88,26 @@ const emit = defineEmits<{ | |||
| 74 | const showListMenu = ref(false) | 88 | const showListMenu = ref(false) |
| 75 | const listMenuButtonRef = ref<HTMLElement>() | 89 | const listMenuButtonRef = ref<HTMLElement>() |
| 76 | const listMenuRef = ref<HTMLElement>() | 90 | const listMenuRef = ref<HTMLElement>() |
| 91 | const showListMenuFade = ref(true) | ||
| 92 | const listMenuBounding = useElementBounding(listMenuRef) | ||
| 93 | const ribbonBounding = useElementBounding(() => | ||
| 94 | listMenuRef.value?.closest('.page-ribbon-list') | ||
| 95 | ) | ||
| 96 | |||
| 97 | const listMenuFadeStyle = computed(() => ({ | ||
| 98 | top: `${listMenuBounding.bottom.value - ribbonBounding.top.value - 56}px`, | ||
| 99 | left: `${listMenuBounding.left.value - ribbonBounding.left.value}px`, | ||
| 100 | width: `${listMenuBounding.width.value}px` | ||
| 101 | })) | ||
| 102 | |||
| 103 | const listMenuFadeReady = computed(() => listMenuBounding.width.value > 0) | ||
| 104 | |||
| 105 | function onListMenuScroll() { | ||
| 106 | const el = listMenuRef.value | ||
| 107 | if (!el) return | ||
| 108 | const { scrollTop, scrollHeight, clientHeight } = el | ||
| 109 | showListMenuFade.value = scrollTop + clientHeight < scrollHeight - 4 | ||
| 110 | } | ||
| 77 | 111 | ||
| 78 | // Tabs ribbon state | 112 | // Tabs ribbon state |
| 79 | const ribbonTrack = shallowRef<HTMLElement>() | 113 | const ribbonTrack = shallowRef<HTMLElement>() |
| @@ -100,7 +134,7 @@ function onDragStart(e: MouseEvent) { | |||
| 100 | // Don't drag if user clicked on a scroll arrow | 134 | // Don't drag if user clicked on a scroll arrow |
| 101 | const target = e.target as HTMLElement | 135 | const target = e.target as HTMLElement |
| 102 | if (target.closest('.page-ribbon-arrow')) return | 136 | if (target.closest('.page-ribbon-arrow')) return |
| 103 | 137 | ||
| 104 | isDragging.value = true | 138 | isDragging.value = true |
| 105 | dragStartX = e.clientX | 139 | dragStartX = e.clientX |
| 106 | dragStartScrollLeft = track.scrollLeft | 140 | dragStartScrollLeft = track.scrollLeft |
| @@ -115,13 +149,13 @@ function onDragMove(e: MouseEvent) { | |||
| 115 | if (!isDragging.value) return | 149 | if (!isDragging.value) return |
| 116 | const track = getRibbonTrack() | 150 | const track = getRibbonTrack() |
| 117 | if (!track) return | 151 | if (!track) return |
| 118 | 152 | ||
| 119 | const deltaX = e.clientX - dragStartX | 153 | const deltaX = e.clientX - dragStartX |
| 120 | const threshold = 4 | 154 | const threshold = 4 |
| 121 | if (!dragMoved && Math.abs(deltaX) > threshold) { | 155 | if (!dragMoved && Math.abs(deltaX) > threshold) { |
| 122 | dragMoved = true | 156 | dragMoved = true |
| 123 | } | 157 | } |
| 124 | 158 | ||
| 125 | if (dragMoved) { | 159 | if (dragMoved) { |
| 126 | track.scrollLeft = dragStartScrollLeft - deltaX | 160 | track.scrollLeft = dragStartScrollLeft - deltaX |
| 127 | updateRibbonOverflow() | 161 | updateRibbonOverflow() |
| @@ -152,7 +186,10 @@ function onTrackWheel(e: WheelEvent) { | |||
| 152 | if (!track) return | 186 | if (!track) return |
| 153 | const max = track.scrollWidth - track.clientWidth | 187 | const max = track.scrollWidth - track.clientWidth |
| 154 | if (max <= 0) return | 188 | if (max <= 0) return |
| 155 | const newScroll = Math.max(0, Math.min(max, track.scrollLeft + e.deltaX + e.deltaY)) | 189 | const newScroll = Math.max( |
| 190 | 0, | ||
| 191 | Math.min(max, track.scrollLeft + e.deltaX + e.deltaY) | ||
| 192 | ) | ||
| 156 | if (newScroll !== track.scrollLeft) { | 193 | if (newScroll !== track.scrollLeft) { |
| 157 | e.preventDefault() | 194 | e.preventDefault() |
| 158 | track.scrollLeft = newScroll | 195 | track.scrollLeft = newScroll |
| @@ -189,9 +226,14 @@ function onTouchEnd() { | |||
| 189 | 226 | ||
| 190 | function updateRibbonOverflow() { | 227 | function updateRibbonOverflow() { |
| 191 | const track = getRibbonTrack() | 228 | const track = getRibbonTrack() |
| 192 | if (!track) { ribbonCanScrollLeft.value = false; ribbonCanScrollRight.value = false; return } | 229 | if (!track) { |
| 230 | ribbonCanScrollLeft.value = false | ||
| 231 | ribbonCanScrollRight.value = false | ||
| 232 | return | ||
| 233 | } | ||
| 193 | ribbonCanScrollLeft.value = track.scrollLeft > 2 | 234 | ribbonCanScrollLeft.value = track.scrollLeft > 2 |
| 194 | ribbonCanScrollRight.value = track.scrollWidth - track.clientWidth - track.scrollLeft > 2 | 235 | ribbonCanScrollRight.value = |
| 236 | track.scrollWidth - track.clientWidth - track.scrollLeft > 2 | ||
| 195 | } | 237 | } |
| 196 | 238 | ||
| 197 | function getRibbonTrack(): HTMLElement | null { | 239 | function getRibbonTrack(): HTMLElement | null { |
| @@ -204,7 +246,9 @@ function scrollActivePagePillIntoView(direction = 0) { | |||
| 204 | const track = getRibbonTrack() | 246 | const track = getRibbonTrack() |
| 205 | if (!track) return | 247 | if (!track) return |
| 206 | const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')] | 248 | const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')] |
| 207 | const activeIndex = pills.findIndex((pill) => pill.classList.contains('active')) | 249 | const activeIndex = pills.findIndex((pill) => |
| 250 | pill.classList.contains('active') | ||
| 251 | ) | ||
| 208 | const active = pills[activeIndex] | 252 | const active = pills[activeIndex] |
| 209 | if (!active) return | 253 | if (!active) return |
| 210 | const trackRect = track.getBoundingClientRect() | 254 | const trackRect = track.getBoundingClientRect() |
| @@ -243,7 +287,11 @@ function scrollRibbon(direction: number) { | |||
| 243 | const to = Math.max(0, Math.min(max, from + amount)) | 287 | const to = Math.max(0, Math.min(max, from + amount)) |
| 244 | if (to === from) return | 288 | if (to === from) return |
| 245 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) | 289 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) |
| 246 | if (!props.searchAnimationsEnabled) { track.scrollLeft = to; updateRibbonOverflow(); return } | 290 | if (!props.searchAnimationsEnabled) { |
| 291 | track.scrollLeft = to | ||
| 292 | updateRibbonOverflow() | ||
| 293 | return | ||
| 294 | } | ||
| 247 | 295 | ||
| 248 | const duration = 280 | 296 | const duration = 280 |
| 249 | const start = performance.now() | 297 | const start = performance.now() |
| @@ -258,8 +306,23 @@ function scrollRibbon(direction: number) { | |||
| 258 | ribbonAnimHandle = requestAnimationFrame(step) | 306 | ribbonAnimHandle = requestAnimationFrame(step) |
| 259 | } | 307 | } |
| 260 | 308 | ||
| 261 | watch(() => props.pageGroups, () => { nextTick(updateRibbonOverflow) }) | 309 | watch(() => props.pageGroups, () => { |
| 262 | watch(() => props.urlPageGroups, () => { nextTick(updateRibbonOverflow) }) | 310 | nextTick(() => { |
| 311 | updateRibbonOverflow() | ||
| 312 | onListMenuScroll() | ||
| 313 | }) | ||
| 314 | }) | ||
| 315 | watch(() => props.urlPageGroups, () => { | ||
| 316 | nextTick(() => { | ||
| 317 | updateRibbonOverflow() | ||
| 318 | onListMenuScroll() | ||
| 319 | }) | ||
| 320 | }) | ||
| 321 | watch(showListMenu, async (open) => { | ||
| 322 | if (!open) return | ||
| 323 | await nextTick() | ||
| 324 | onListMenuScroll() | ||
| 325 | }) | ||
| 263 | useEventListener('resize', updateRibbonOverflow) | 326 | useEventListener('resize', updateRibbonOverflow) |
| 264 | 327 | ||
| 265 | onBeforeUnmount(() => { | 328 | onBeforeUnmount(() => { |
| @@ -304,11 +367,15 @@ const groupedMenuEntries = computed((): MenuEntry[] => { | |||
| 304 | // Build folder entries | 367 | // Build folder entries |
| 305 | const folderEntries: FolderGroup[] = [...folderMap.entries()] | 368 | const folderEntries: FolderGroup[] = [...folderMap.entries()] |
| 306 | .map(([section, pages]) => { | 369 | .map(([section, pages]) => { |
| 307 | const parentCard = homeCards.find((c) => c.title === section && !c.section) ?? null | 370 | const parentCard = homeCards.find((c) => |
| 371 | c.title === section && !c.section | ||
| 372 | ) ?? null | ||
| 308 | return { | 373 | return { |
| 309 | section, | 374 | section, |
| 310 | parentCard, | 375 | parentCard, |
| 311 | iconClass: parentCard ? cardIconToClass(parentCard.icon) : 'i-lucide:folder', | 376 | iconClass: parentCard |
| 377 | ? cardIconToClass(parentCard.icon) | ||
| 378 | : 'i-lucide:folder', | ||
| 312 | pages | 379 | pages |
| 313 | } | 380 | } |
| 314 | }) | 381 | }) |
| @@ -338,12 +405,20 @@ const activePageData = computed(() => { | |||
| 338 | const findInEntries = (key: string, fallbackCount: number) => { | 405 | const findInEntries = (key: string, fallbackCount: number) => { |
| 339 | for (const entry of groupedMenuEntries.value) { | 406 | for (const entry of groupedMenuEntries.value) { |
| 340 | if (entry.type === 'page' && entry.page.key === key) { | 407 | if (entry.type === 'page' && entry.page.key === key) { |
| 341 | return { label: entry.page.label, iconClass: entry.page.iconClass, count: entry.page.count } | 408 | return { |
| 409 | label: entry.page.label, | ||
| 410 | iconClass: entry.page.iconClass, | ||
| 411 | count: entry.page.count | ||
| 412 | } | ||
| 342 | } | 413 | } |
| 343 | if (entry.type === 'folder') { | 414 | if (entry.type === 'folder') { |
| 344 | const found = entry.folder.pages.find((p) => p.key === key) | 415 | const found = entry.folder.pages.find((p) => p.key === key) |
| 345 | if (found) { | 416 | if (found) { |
| 346 | return { label: found.label, iconClass: entry.folder.iconClass, count: found.count } | 417 | return { |
| 418 | label: found.label, | ||
| 419 | iconClass: entry.folder.iconClass, | ||
| 420 | count: found.count | ||
| 421 | } | ||
| 347 | } | 422 | } |
| 348 | } | 423 | } |
| 349 | } | 424 | } |
| @@ -352,17 +427,38 @@ const activePageData = computed(() => { | |||
| 352 | 427 | ||
| 353 | if (props.urlSearchMode) { | 428 | if (props.urlSearchMode) { |
| 354 | if (props.urlActivePageFilter === null) { | 429 | if (props.urlActivePageFilter === null) { |
| 355 | return { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength } | 430 | return { |
| 431 | label: 'All', | ||
| 432 | iconClass: 'i-lucide:text-search', | ||
| 433 | count: props.urlMatchesLength | ||
| 434 | } | ||
| 356 | } | 435 | } |
| 357 | const result = findInEntries(props.urlActivePageFilter, props.urlMatchesLength) | 436 | const result = findInEntries( |
| 358 | return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength } | 437 | props.urlActivePageFilter, |
| 438 | props.urlMatchesLength | ||
| 439 | ) | ||
| 440 | return result ?? | ||
| 441 | { | ||
| 442 | label: 'All', | ||
| 443 | iconClass: 'i-lucide:text-search', | ||
| 444 | count: props.urlMatchesLength | ||
| 445 | } | ||
| 359 | } | 446 | } |
| 360 | 447 | ||
| 361 | if (props.activePageFilter === null) { | 448 | if (props.activePageFilter === null) { |
| 362 | return { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength } | 449 | return { |
| 450 | label: 'All', | ||
| 451 | iconClass: 'i-lucide:text-search', | ||
| 452 | count: props.resultsLength | ||
| 453 | } | ||
| 363 | } | 454 | } |
| 364 | const result = findInEntries(props.activePageFilter, props.resultsLength) | 455 | const result = findInEntries(props.activePageFilter, props.resultsLength) |
| 365 | return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength } | 456 | return result ?? |
| 457 | { | ||
| 458 | label: 'All', | ||
| 459 | iconClass: 'i-lucide:text-search', | ||
| 460 | count: props.resultsLength | ||
| 461 | } | ||
| 366 | }) | 462 | }) |
| 367 | 463 | ||
| 368 | function toggleListMenu() { | 464 | function toggleListMenu() { |
| @@ -384,7 +480,9 @@ const allPages = computed((): (string | null)[] => { | |||
| 384 | }) | 480 | }) |
| 385 | 481 | ||
| 386 | const currentPageIndex = computed(() => { | 482 | const currentPageIndex = computed(() => { |
| 387 | const activeKey = props.urlSearchMode ? props.urlActivePageFilter : props.activePageFilter | 483 | const activeKey = props.urlSearchMode |
| 484 | ? props.urlActivePageFilter | ||
| 485 | : props.activePageFilter | ||
| 388 | return allPages.value.indexOf(activeKey) | 486 | return allPages.value.indexOf(activeKey) |
| 389 | }) | 487 | }) |
| 390 | 488 | ||
| @@ -451,40 +549,55 @@ function pageNav(delta: number) { | |||
| 451 | v-if="showListMenu" | 549 | v-if="showListMenu" |
| 452 | ref="listMenuRef" | 550 | ref="listMenuRef" |
| 453 | class="page-ribbon-list-menu" | 551 | class="page-ribbon-list-menu" |
| 552 | @scroll.passive="onListMenuScroll" | ||
| 454 | > | 553 | > |
| 455 | <!-- "All" item --> | 554 | <!-- "All" item --> |
| 456 | <button | 555 | <button |
| 457 | type="button" | 556 | type="button" |
| 458 | class="ribbon-menu-item all-item" | 557 | class="ribbon-menu-item all-item" |
| 459 | :class="{ active: urlSearchMode | 558 | :class="{ |
| 460 | ? urlActivePageFilter === null | 559 | active: urlSearchMode |
| 461 | : activePageFilter === null }" | 560 | ? urlActivePageFilter === null |
| 561 | : activePageFilter === null | ||
| 562 | }" | ||
| 462 | @click="urlSearchMode | 563 | @click="urlSearchMode |
| 463 | ? setUrlPageFilter(null) | 564 | ? setUrlPageFilter(null) |
| 464 | : setPageFilter(null)" | 565 | : setPageFilter(null)" |
| 465 | > | 566 | > |
| 466 | <span class="i-lucide:text-search ribbon-menu-item-icon" /> | 567 | <span class="i-lucide:text-search ribbon-menu-item-icon" /> |
| 467 | <span class="ribbon-menu-item-label">All</span> | 568 | <span class="ribbon-menu-item-label">All</span> |
| 468 | <span class="ribbon-menu-item-count">{{ urlSearchMode ? urlMatchesLength : resultsLength }}</span> | 569 | <span class="ribbon-menu-item-count">{{ |
| 570 | urlSearchMode ? urlMatchesLength : resultsLength | ||
| 571 | }}</span> | ||
| 469 | </button> | 572 | </button> |
| 470 | 573 | ||
| 471 | <div class="ribbon-menu-divider" /> | 574 | <div class="ribbon-menu-divider" /> |
| 472 | 575 | ||
| 473 | <!-- Grouped pages --> | 576 | <!-- Grouped pages --> |
| 474 | <template v-for="entry in groupedMenuEntries" :key="entry.type === 'page' ? entry.page.key : entry.folder.section"> | 577 | <template |
| 578 | v-for="entry in groupedMenuEntries" | ||
| 579 | :key="entry.type === 'page' | ||
| 580 | ? entry.page.key | ||
| 581 | : entry.folder.section" | ||
| 582 | > | ||
| 475 | <!-- Top-level page --> | 583 | <!-- Top-level page --> |
| 476 | <div v-if="entry.type === 'page'" class="ribbon-menu-group"> | 584 | <div v-if="entry.type === 'page'" class="ribbon-menu-group"> |
| 477 | <button | 585 | <button |
| 478 | type="button" | 586 | type="button" |
| 479 | class="ribbon-menu-item" | 587 | class="ribbon-menu-item" |
| 480 | :class="{ active: urlSearchMode | 588 | :class="{ |
| 481 | ? urlActivePageFilter === entry.page.key | 589 | active: urlSearchMode |
| 482 | : activePageFilter === entry.page.key }" | 590 | ? urlActivePageFilter === entry.page.key |
| 591 | : activePageFilter === entry.page.key | ||
| 592 | }" | ||
| 483 | @click="urlSearchMode | 593 | @click="urlSearchMode |
| 484 | ? setUrlPageFilter(entry.page.key) | 594 | ? setUrlPageFilter(entry.page.key) |
| 485 | : setPageFilter(entry.page.key)" | 595 | : setPageFilter(entry.page.key)" |
| 486 | > | 596 | > |
| 487 | <span :class="entry.page.iconClass" class="ribbon-menu-item-icon" /> | 597 | <span |
| 598 | :class="entry.page.iconClass" | ||
| 599 | class="ribbon-menu-item-icon" | ||
| 600 | /> | ||
| 488 | <span class="ribbon-menu-item-label">{{ entry.page.label }}</span> | 601 | <span class="ribbon-menu-item-label">{{ entry.page.label }}</span> |
| 489 | <span class="ribbon-menu-item-count">{{ entry.page.count }}</span> | 602 | <span class="ribbon-menu-item-count">{{ entry.page.count }}</span> |
| 490 | </button> | 603 | </button> |
| @@ -493,8 +606,13 @@ function pageNav(delta: number) { | |||
| 493 | <!-- Folder group --> | 606 | <!-- Folder group --> |
| 494 | <div v-else class="ribbon-menu-group"> | 607 | <div v-else class="ribbon-menu-group"> |
| 495 | <h4 class="ribbon-menu-group-title"> | 608 | <h4 class="ribbon-menu-group-title"> |
| 496 | <span :class="entry.folder.iconClass" class="ribbon-menu-group-icon" /> | 609 | <span |
| 497 | <span class="ribbon-menu-group-text">{{ entry.folder.section }}</span> | 610 | :class="entry.folder.iconClass" |
| 611 | class="ribbon-menu-group-icon" | ||
| 612 | /> | ||
| 613 | <span class="ribbon-menu-group-text">{{ | ||
| 614 | entry.folder.section | ||
| 615 | }}</span> | ||
| 498 | </h4> | 616 | </h4> |
| 499 | <div class="ribbon-menu-sub-items"> | 617 | <div class="ribbon-menu-sub-items"> |
| 500 | <button | 618 | <button |
| @@ -502,12 +620,14 @@ function pageNav(delta: number) { | |||
| 502 | :key="page.key" | 620 | :key="page.key" |
| 503 | type="button" | 621 | type="button" |
| 504 | class="ribbon-menu-item" | 622 | class="ribbon-menu-item" |
| 505 | :class="{ active: urlSearchMode | 623 | :class="{ |
| 506 | ? urlActivePageFilter === page.key | 624 | active: urlSearchMode |
| 507 | : activePageFilter === page.key }" | 625 | ? urlActivePageFilter === page.key |
| 626 | : activePageFilter === page.key | ||
| 627 | }" | ||
| 508 | @click="urlSearchMode | 628 | @click="urlSearchMode |
| 509 | ? setUrlPageFilter(page.key) | 629 | ? setUrlPageFilter(page.key) |
| 510 | : setPageFilter(page.key)" | 630 | : setPageFilter(page.key)" |
| 511 | > | 631 | > |
| 512 | <span class="ribbon-menu-item-label">{{ page.label }}</span> | 632 | <span class="ribbon-menu-item-label">{{ page.label }}</span> |
| 513 | <span class="ribbon-menu-item-count">{{ page.count }}</span> | 633 | <span class="ribbon-menu-item-count">{{ page.count }}</span> |
| @@ -517,6 +637,14 @@ function pageNav(delta: number) { | |||
| 517 | </template> | 637 | </template> |
| 518 | </div> | 638 | </div> |
| 519 | </Transition> | 639 | </Transition> |
| 640 | |||
| 641 | <Transition name="ribbon-menu-fade"> | ||
| 642 | <div | ||
| 643 | v-if="showListMenu && showListMenuFade && listMenuFadeReady" | ||
| 644 | class="page-ribbon-list-menu-fade" | ||
| 645 | :style="listMenuFadeStyle" | ||
| 646 | /> | ||
| 647 | </Transition> | ||
| 520 | </component> | 648 | </component> |
| 521 | 649 | ||
| 522 | <!-- Tabs ribbon style (original) --> | 650 | <!-- Tabs ribbon style (original) --> |
| @@ -652,7 +780,7 @@ function pageNav(delta: number) { | |||
| 652 | } | 780 | } |
| 653 | 781 | ||
| 654 | .page-ribbon::after { | 782 | .page-ribbon::after { |
| 655 | content: ''; | 783 | content: ""; |
| 656 | position: absolute; | 784 | position: absolute; |
| 657 | right: 0; | 785 | right: 0; |
| 658 | bottom: 0; | 786 | bottom: 0; |
| @@ -681,14 +809,22 @@ function pageNav(delta: number) { | |||
| 681 | left: 0; | 809 | left: 0; |
| 682 | justify-content: flex-start; | 810 | justify-content: flex-start; |
| 683 | padding-left: 6px; | 811 | padding-left: 6px; |
| 684 | background: linear-gradient(to right, var(--vp-local-search-bg) 60%, transparent); | 812 | background: linear-gradient( |
| 813 | to right, | ||
| 814 | var(--vp-local-search-bg) 60%, | ||
| 815 | transparent | ||
| 816 | ); | ||
| 685 | } | 817 | } |
| 686 | 818 | ||
| 687 | .page-ribbon-arrow.right { | 819 | .page-ribbon-arrow.right { |
| 688 | right: 0; | 820 | right: 0; |
| 689 | justify-content: flex-end; | 821 | justify-content: flex-end; |
| 690 | padding-right: 6px; | 822 | padding-right: 6px; |
| 691 | background: linear-gradient(to left, var(--vp-local-search-bg) 60%, transparent); | 823 | background: linear-gradient( |
| 824 | to left, | ||
| 825 | var(--vp-local-search-bg) 60%, | ||
| 826 | transparent | ||
| 827 | ); | ||
| 692 | } | 828 | } |
| 693 | 829 | ||
| 694 | .page-ribbon-arrow:hover { | 830 | .page-ribbon-arrow:hover { |
| @@ -728,7 +864,7 @@ function pageNav(delta: number) { | |||
| 728 | } | 864 | } |
| 729 | 865 | ||
| 730 | .page-pill::after { | 866 | .page-pill::after { |
| 731 | content: ''; | 867 | content: ""; |
| 732 | position: absolute; | 868 | position: absolute; |
| 733 | z-index: 1; | 869 | z-index: 1; |
| 734 | right: 8px; | 870 | right: 8px; |
| @@ -842,9 +978,7 @@ function pageNav(delta: number) { | |||
| 842 | opacity: 0.55; | 978 | opacity: 0.55; |
| 843 | padding: 8px 4px; | 979 | padding: 8px 4px; |
| 844 | cursor: pointer; | 980 | cursor: pointer; |
| 845 | transition: | 981 | transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); |
| 846 | opacity 0.25s, | ||
| 847 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 848 | border-radius: 0; | 982 | border-radius: 0; |
| 849 | line-height: 1; | 983 | line-height: 1; |
| 850 | } | 984 | } |
| @@ -903,6 +1037,29 @@ html.effects-disabled .ribbon-menu-btn:active { | |||
| 903 | display: none; | 1037 | display: none; |
| 904 | } | 1038 | } |
| 905 | 1039 | ||
| 1040 | .page-ribbon-list-menu-fade { | ||
| 1041 | position: absolute; | ||
| 1042 | z-index: 51; | ||
| 1043 | height: 56px; | ||
| 1044 | pointer-events: none; | ||
| 1045 | background: linear-gradient( | ||
| 1046 | to bottom, | ||
| 1047 | transparent, | ||
| 1048 | var(--vp-c-bg-elv) | ||
| 1049 | ); | ||
| 1050 | border-radius: 0 0 12px 12px; | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | .ribbon-menu-fade-enter-active, | ||
| 1054 | .ribbon-menu-fade-leave-active { | ||
| 1055 | transition: opacity 0.2s; | ||
| 1056 | } | ||
| 1057 | |||
| 1058 | .ribbon-menu-fade-enter-from, | ||
| 1059 | .ribbon-menu-fade-leave-to { | ||
| 1060 | opacity: 0; | ||
| 1061 | } | ||
| 1062 | |||
| 906 | .ribbon-menu-divider { | 1063 | .ribbon-menu-divider { |
| 907 | height: 1px; | 1064 | height: 1px; |
| 908 | background: var(--vp-c-divider); | 1065 | background: var(--vp-c-divider); |
docs/.vitepress/theme/components/search/SearchSettings.vue +89 −10
| @@ -35,17 +35,43 @@ const emit = defineEmits<{ | |||
| 35 | 35 | ||
| 36 | const settingsPopupRef = ref<HTMLDivElement>() | 36 | const settingsPopupRef = ref<HTMLDivElement>() |
| 37 | const settingsBounding = useElementBounding(() => props.settingsButtonRef) | 37 | const settingsBounding = useElementBounding(() => props.settingsButtonRef) |
| 38 | const settingsPopupBounding = useElementBounding(settingsPopupRef) | ||
| 39 | const showFade = ref(true) | ||
| 38 | 40 | ||
| 39 | type HelpSection = 'search' | 'view' | 'ribbon' | 'preload' | 'highlight' | 'history' | 41 | const settingsFadeStyle = computed(() => ({ |
| 42 | top: `${settingsPopupBounding.bottom.value - 56}px`, | ||
| 43 | left: `${settingsPopupBounding.left.value}px`, | ||
| 44 | width: `${settingsPopupBounding.width.value}px` | ||
| 45 | })) | ||
| 46 | |||
| 47 | const settingsFadeReady = computed(() => settingsPopupBounding.width.value > 0) | ||
| 48 | |||
| 49 | function onSettingsScroll() { | ||
| 50 | const el = settingsPopupRef.value | ||
| 51 | if (!el) return | ||
| 52 | const { scrollTop, scrollHeight, clientHeight } = el | ||
| 53 | showFade.value = scrollTop + clientHeight < scrollHeight - 4 | ||
| 54 | } | ||
| 55 | |||
| 56 | type HelpSection = | ||
| 57 | | 'search' | ||
| 58 | | 'view' | ||
| 59 | | 'ribbon' | ||
| 60 | | 'preload' | ||
| 61 | | 'highlight' | ||
| 62 | | 'history' | ||
| 40 | const activeHelpSection = ref<HelpSection | null>(null) | 63 | const activeHelpSection = ref<HelpSection | null>(null) |
| 41 | const helpPopupEl = ref<HTMLDivElement>() | 64 | const helpPopupEl = ref<HTMLDivElement>() |
| 42 | const helpPopupPos = ref({ top: -9999, left: -9999 }) | 65 | const helpPopupPos = ref({ top: -9999, left: -9999 }) |
| 43 | 66 | ||
| 44 | watch(() => props.showSettingsPopup, (val) => { | 67 | watch(() => props.showSettingsPopup, async (val) => { |
| 45 | if (!val) { | 68 | if (!val) { |
| 46 | activeHelpSection.value = null | 69 | activeHelpSection.value = null |
| 47 | helpPopupPos.value = { top: -9999, left: -9999 } | 70 | helpPopupPos.value = { top: -9999, left: -9999 } |
| 71 | return | ||
| 48 | } | 72 | } |
| 73 | await nextTick() | ||
| 74 | onSettingsScroll() | ||
| 49 | }) | 75 | }) |
| 50 | 76 | ||
| 51 | const canHoverHelp = () => | 77 | const canHoverHelp = () => |
| @@ -65,13 +91,16 @@ function positionHelpPopup(btn: HTMLElement) { | |||
| 65 | const aboveTop = rect.top - popupH - margin | 91 | const aboveTop = rect.top - popupH - margin |
| 66 | const belowTop = rect.bottom + margin | 92 | const belowTop = rect.bottom + margin |
| 67 | const top = aboveTop >= margin ? aboveTop : belowTop | 93 | const top = aboveTop >= margin ? aboveTop : belowTop |
| 68 | const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin)) | 94 | const left = Math.max( |
| 95 | margin, | ||
| 96 | Math.min((vw - popupW) / 2, vw - popupW - margin) | ||
| 97 | ) | ||
| 69 | helpPopupPos.value = { top, left } | 98 | helpPopupPos.value = { top, left } |
| 70 | } else { | 99 | } else { |
| 71 | const anchorLeft = menuRect ? menuRect.left : rect.left | 100 | const anchorLeft = menuRect ? menuRect.left : rect.left |
| 72 | helpPopupPos.value = { | 101 | helpPopupPos.value = { |
| 73 | left: Math.max(margin, anchorLeft - popupW - 16), | 102 | left: Math.max(margin, anchorLeft - popupW - 16), |
| 74 | top: rect.top, | 103 | top: rect.top |
| 75 | } | 104 | } |
| 76 | } | 105 | } |
| 77 | }) | 106 | }) |
| @@ -109,7 +138,7 @@ function onHelpLeave() { | |||
| 109 | 138 | ||
| 110 | const settingsPopupStyle = computed(() => ({ | 139 | const settingsPopupStyle = computed(() => ({ |
| 111 | top: `${settingsBounding.bottom.value + 8}px`, | 140 | top: `${settingsBounding.bottom.value + 8}px`, |
| 112 | right: `calc(100vw - ${settingsBounding.right.value}px)`, | 141 | right: `calc(100vw - ${settingsBounding.right.value}px)` |
| 113 | })) | 142 | })) |
| 114 | 143 | ||
| 115 | const settingsBtnEl = computed(() => props.settingsButtonRef) | 144 | const settingsBtnEl = computed(() => props.settingsButtonRef) |
| @@ -129,6 +158,7 @@ function setSearchMode(mode: string) { | |||
| 129 | ref="settingsPopupRef" | 158 | ref="settingsPopupRef" |
| 130 | class="search-settings-popup" | 159 | class="search-settings-popup" |
| 131 | :style="settingsPopupStyle" | 160 | :style="settingsPopupStyle" |
| 161 | @scroll.passive="onSettingsScroll" | ||
| 132 | @click="closeHelpSection" | 162 | @click="closeHelpSection" |
| 133 | > | 163 | > |
| 134 | <!-- Search Mode --> | 164 | <!-- Search Mode --> |
| @@ -415,6 +445,14 @@ function setSearchMode(mode: string) { | |||
| 415 | </div> | 445 | </div> |
| 416 | </Transition> | 446 | </Transition> |
| 417 | 447 | ||
| 448 | <Transition name="settings-fade"> | ||
| 449 | <div | ||
| 450 | v-if="showSettingsPopup && showFade && settingsFadeReady" | ||
| 451 | class="search-settings-fade-overlay" | ||
| 452 | :style="settingsFadeStyle" | ||
| 453 | /> | ||
| 454 | </Transition> | ||
| 455 | |||
| 418 | <!-- Help popups --> | 456 | <!-- Help popups --> |
| 419 | <Transition name="help-popup-fade"> | 457 | <Transition name="help-popup-fade"> |
| 420 | <div | 458 | <div |
| @@ -452,8 +490,10 @@ function setSearchMode(mode: string) { | |||
| 452 | <p class="sh-desc">Controls how search results are displayed.</p> | 490 | <p class="sh-desc">Controls how search results are displayed.</p> |
| 453 | <div class="sh-options"> | 491 | <div class="sh-options"> |
| 454 | <div class="sh-option"> | 492 | <div class="sh-option"> |
| 455 | <strong><TextAlignStart :size="14" stroke-width="1.5" /> Detail</strong> | 493 | <strong><TextAlignStart :size="14" stroke-width="1.5" /> |
| 456 | <span>Shows a content excerpt below each result. Uses more memory.</span> | 494 | Detail</strong> |
| 495 | <span>Shows a content excerpt below each result. Uses more | ||
| 496 | memory.</span> | ||
| 457 | </div> | 497 | </div> |
| 458 | <div class="sh-option"> | 498 | <div class="sh-option"> |
| 459 | <strong><List :size="14" stroke-width="1.5" /> List</strong> | 499 | <strong><List :size="14" stroke-width="1.5" /> List</strong> |
| @@ -466,7 +506,10 @@ function setSearchMode(mode: string) { | |||
| 466 | <Layers :size="16" stroke-width="1.75" class="sh-title-icon" /> | 506 | <Layers :size="16" stroke-width="1.75" class="sh-title-icon" /> |
| 467 | Excerpt Preload | 507 | Excerpt Preload |
| 468 | </h4> | 508 | </h4> |
| 469 | <p class="sh-desc">Renders excerpts for upcoming result pages ahead of time in Detail view.</p> | 509 | <p class="sh-desc"> |
| 510 | Renders excerpts for upcoming result pages ahead of time in Detail | ||
| 511 | view. | ||
| 512 | </p> | ||
| 470 | <div class="sh-options"> | 513 | <div class="sh-options"> |
| 471 | <div class="sh-option"> | 514 | <div class="sh-option"> |
| 472 | <strong>All</strong> | 515 | <strong>All</strong> |
| @@ -474,7 +517,8 @@ function setSearchMode(mode: string) { | |||
| 474 | </div> | 517 | </div> |
| 475 | <div class="sh-option"> | 518 | <div class="sh-option"> |
| 476 | <strong>Next</strong> | 519 | <strong>Next</strong> |
| 477 | <span>Also prepares the next page so flipping forward is instant</span> | 520 | <span>Also prepares the next page so flipping forward is |
| 521 | instant</span> | ||
| 478 | </div> | 522 | </div> |
| 479 | <div class="sh-option"> | 523 | <div class="sh-option"> |
| 480 | <strong>Off</strong> | 524 | <strong>Off</strong> |
| @@ -521,7 +565,9 @@ function setSearchMode(mode: string) { | |||
| 521 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> | 565 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> |
| 522 | Search History | 566 | Search History |
| 523 | </h4> | 567 | </h4> |
| 524 | <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p> | 568 | <p class="sh-desc"> |
| 569 | Saves recent searches and shows them when the search bar is empty. | ||
| 570 | </p> | ||
| 525 | </template> | 571 | </template> |
| 526 | </div> | 572 | </div> |
| 527 | </Transition> | 573 | </Transition> |
| @@ -543,6 +589,16 @@ function setSearchMode(mode: string) { | |||
| 543 | display: flex; | 589 | display: flex; |
| 544 | flex-direction: column; | 590 | flex-direction: column; |
| 545 | min-width: 196px; | 591 | min-width: 196px; |
| 592 | max-height: min(320px, 60vh); | ||
| 593 | overflow-y: auto; | ||
| 594 | overflow-x: hidden; | ||
| 595 | overscroll-behavior: contain; | ||
| 596 | scrollbar-width: none; | ||
| 597 | -ms-overflow-style: none; | ||
| 598 | } | ||
| 599 | |||
| 600 | .search-settings-popup::-webkit-scrollbar { | ||
| 601 | display: none; | ||
| 546 | } | 602 | } |
| 547 | 603 | ||
| 548 | .dark .search-settings-popup { | 604 | .dark .search-settings-popup { |
| @@ -662,6 +718,29 @@ function setSearchMode(mode: string) { | |||
| 662 | transform: scale(0.92) translateY(-4px); | 718 | transform: scale(0.92) translateY(-4px); |
| 663 | } | 719 | } |
| 664 | 720 | ||
| 721 | .search-settings-fade-overlay { | ||
| 722 | position: fixed; | ||
| 723 | z-index: 200; | ||
| 724 | height: 56px; | ||
| 725 | pointer-events: none; | ||
| 726 | background: linear-gradient( | ||
| 727 | to bottom, | ||
| 728 | transparent, | ||
| 729 | var(--vp-c-bg-elv) | ||
| 730 | ); | ||
| 731 | border-radius: 0 0 12px 12px; | ||
| 732 | } | ||
| 733 | |||
| 734 | .settings-fade-enter-active, | ||
| 735 | .settings-fade-leave-active { | ||
| 736 | transition: opacity 0.2s; | ||
| 737 | } | ||
| 738 | |||
| 739 | .settings-fade-enter-from, | ||
| 740 | .settings-fade-leave-to { | ||
| 741 | opacity: 0; | ||
| 742 | } | ||
| 743 | |||
| 665 | .search-help-popup { | 744 | .search-help-popup { |
| 666 | position: fixed; | 745 | position: fixed; |
| 667 | z-index: 9999; | 746 | z-index: 9999; |