| @@ -1,7 +1,9 @@ |
| 1 | 1 | <script setup lang="ts"> |
| 2 | | import { ChevronRight } from 'lucide-vue-next' |
| 3 | | import { nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' |
| 4 | | import { useEventListener } from '@vueuse/core' |
| 2 | import { ChevronRight, Menu } from 'lucide-vue-next' |
| 3 | import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' |
| 4 | import { onClickOutside, useEventListener } from '@vueuse/core' |
| 5 | import { homeCards } from '../../../configs/constants' |
| 6 | import type { HomeCard } from '../../../configs/constants' |
| 5 | 7 | |
| 6 | 8 | interface PageGroup { |
| 7 | 9 | key: string |
| @@ -9,7 +11,48 @@ interface PageGroup { |
| 9 | 11 | count: number |
| 10 | 12 | } |
| 11 | 13 | |
| 14 | interface GroupedPage { |
| 15 | key: string |
| 16 | label: string |
| 17 | count: number |
| 18 | card: HomeCard | null |
| 19 | iconClass: string |
| 20 | } |
| 21 | |
| 22 | interface FolderGroup { |
| 23 | section: string |
| 24 | parentCard: HomeCard | null |
| 25 | iconClass: string |
| 26 | pages: GroupedPage[] |
| 27 | } |
| 28 | |
| 29 | type MenuEntry = |
| 30 | | { type: 'page'; page: GroupedPage } |
| 31 | | { type: 'folder'; folder: FolderGroup } |
| 32 | |
| 33 | function getPageCard(path: string): HomeCard | null { |
| 34 | let best: HomeCard | null = null |
| 35 | let bestLen = 0 |
| 36 | for (const card of homeCards) { |
| 37 | if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) { |
| 38 | best = card |
| 39 | bestLen = card.link.length |
| 40 | } |
| 41 | } |
| 42 | return best |
| 43 | } |
| 44 | |
| 45 | function cardIconToClass(icon: string): string { |
| 46 | const m = icon.match(/^:(.+):$/) |
| 47 | if (!m) return 'i-lucide:file-text' |
| 48 | const name = m[1] |
| 49 | const dash = name.indexOf('-') |
| 50 | if (dash === -1) return 'i-lucide:file-text' |
| 51 | return `i-${name.slice(0, dash)}:${name.slice(dash + 1)}` |
| 52 | } |
| 53 | |
| 12 | 54 | const props = defineProps<{ |
| 55 | ribbonStyle: 'tabs' | 'list' |
| 13 | 56 | searchMotionDiv: string | object |
| 14 | 57 | ribbonMotion: Record<string, unknown> |
| 15 | 58 | searchAnimationsEnabled: boolean |
| @@ -27,6 +70,12 @@ const emit = defineEmits<{ |
| 27 | 70 | selectPage: [key: string | null] |
| 28 | 71 | }>() |
| 29 | 72 | |
| 73 | // List ribbon state |
| 74 | const showListMenu = ref(false) |
| 75 | const listMenuButtonRef = ref<HTMLElement>() |
| 76 | const listMenuRef = ref<HTMLElement>() |
| 77 | |
| 78 | // Tabs ribbon state |
| 30 | 79 | const ribbonTrack = shallowRef<HTMLElement>() |
| 31 | 80 | const ribbonCanScrollLeft = ref(false) |
| 32 | 81 | const ribbonCanScrollRight = ref(false) |
| @@ -39,6 +88,10 @@ let touchStartX = 0 |
| 39 | 88 | let touchStartScrollLeft = 0 |
| 40 | 89 | let touchDragMoved = false |
| 41 | 90 | |
| 91 | onClickOutside(listMenuRef, () => { |
| 92 | showListMenu.value = false |
| 93 | }, { ignore: [listMenuButtonRef] }) |
| 94 | |
| 42 | 95 | function onDragStart(e: MouseEvent) { |
| 43 | 96 | // Only respond to primary (left) button |
| 44 | 97 | if (e.button !== 0) return |
| @@ -146,6 +199,7 @@ function getRibbonTrack(): HTMLElement | null { |
| 146 | 199 | } |
| 147 | 200 | |
| 148 | 201 | function scrollActivePagePillIntoView(direction = 0) { |
| 202 | if (props.ribbonStyle === 'list') return |
| 149 | 203 | nextTick(() => { |
| 150 | 204 | const track = getRibbonTrack() |
| 151 | 205 | if (!track) return |
| @@ -218,23 +272,211 @@ onBeforeUnmount(() => { |
| 218 | 272 | |
| 219 | 273 | defineExpose({ scrollActivePagePillIntoView }) |
| 220 | 274 | |
| 275 | const groupedMenuEntries = computed((): MenuEntry[] => { |
| 276 | const groups = props.urlSearchMode ? props.urlPageGroups : props.pageGroups |
| 277 | if (!groups.length) return [] |
| 278 | |
| 279 | // Wrap each group with card info |
| 280 | const withCards: GroupedPage[] = groups.map((g) => { |
| 281 | const card = getPageCard(g.key) |
| 282 | return { |
| 283 | key: g.key, |
| 284 | label: g.label, |
| 285 | count: g.count, |
| 286 | card, |
| 287 | iconClass: card ? cardIconToClass(card.icon) : 'i-lucide:file-text' |
| 288 | } |
| 289 | }) |
| 290 | |
| 291 | // Separate into top-level (no section) and folder (has section) |
| 292 | const topPages: GroupedPage[] = [] |
| 293 | const folderMap = new Map<string, GroupedPage[]>() |
| 294 | |
| 295 | for (const p of withCards) { |
| 296 | if (p.card?.section) { |
| 297 | if (!folderMap.has(p.card.section)) folderMap.set(p.card.section, []) |
| 298 | folderMap.get(p.card.section)!.push(p) |
| 299 | } else { |
| 300 | topPages.push(p) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // Build folder entries |
| 305 | const folderEntries: FolderGroup[] = [...folderMap.entries()] |
| 306 | .map(([section, pages]) => { |
| 307 | const parentCard = homeCards.find((c) => c.title === section && !c.section) ?? null |
| 308 | return { |
| 309 | section, |
| 310 | parentCard, |
| 311 | iconClass: parentCard ? cardIconToClass(parentCard.icon) : 'i-lucide:folder', |
| 312 | pages |
| 313 | } |
| 314 | }) |
| 315 | |
| 316 | // Merge: top-level pages first, then folder groups |
| 317 | const entries: MenuEntry[] = [ |
| 318 | ...topPages.map((p) => ({ type: 'page' as const, page: p })), |
| 319 | ...folderEntries.map((f) => ({ type: 'folder' as const, folder: f })) |
| 320 | ] |
| 321 | |
| 322 | return entries |
| 323 | }) |
| 324 | |
| 221 | 325 | function setUrlPageFilter(key: string | null) { |
| 222 | 326 | emit('selectUrlPage', key) |
| 327 | showListMenu.value = false |
| 223 | 328 | nextTick(updateRibbonOverflow) |
| 224 | 329 | } |
| 225 | 330 | |
| 226 | 331 | function setPageFilter(key: string | null) { |
| 227 | 332 | emit('selectPage', key) |
| 333 | showListMenu.value = false |
| 228 | 334 | nextTick(updateRibbonOverflow) |
| 229 | 335 | } |
| 336 | |
| 337 | const activePageData = computed(() => { |
| 338 | const findInEntries = (key: string, fallbackCount: number) => { |
| 339 | for (const entry of groupedMenuEntries.value) { |
| 340 | if (entry.type === 'page' && entry.page.key === key) { |
| 341 | return { label: entry.page.label, iconClass: entry.page.iconClass, count: entry.page.count } |
| 342 | } |
| 343 | if (entry.type === 'folder') { |
| 344 | const found = entry.folder.pages.find((p) => p.key === key) |
| 345 | if (found) { |
| 346 | return { label: found.label, iconClass: entry.folder.iconClass, count: found.count } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | return null |
| 351 | } |
| 352 | |
| 353 | if (props.urlSearchMode) { |
| 354 | if (props.urlActivePageFilter === null) { |
| 355 | return { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength } |
| 356 | } |
| 357 | const result = findInEntries(props.urlActivePageFilter, props.urlMatchesLength) |
| 358 | return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength } |
| 359 | } |
| 360 | |
| 361 | if (props.activePageFilter === null) { |
| 362 | return { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength } |
| 363 | } |
| 364 | const result = findInEntries(props.activePageFilter, props.resultsLength) |
| 365 | return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength } |
| 366 | }) |
| 367 | |
| 368 | function toggleListMenu() { |
| 369 | showListMenu.value = !showListMenu.value |
| 370 | } |
| 230 | 371 | </script> |
| 231 | 372 | |
| 232 | 373 | <template> |
| 374 | <!-- List ribbon style --> |
| 375 | <component |
| 376 | :is="searchMotionDiv" |
| 377 | v-if="ribbonStyle === 'list' && (urlSearchMode |
| 378 | ? urlPageGroups.length > 1 |
| 379 | : pageGroups.length > 1)" |
| 380 | class="page-ribbon page-ribbon-list" |
| 381 | v-bind="ribbonMotion" |
| 382 | > |
| 383 | <div class="page-ribbon-list-label"> |
| 384 | <span :class="activePageData.iconClass" class="page-ribbon-list-icon" /> |
| 385 | <span class="page-ribbon-list-name">{{ activePageData.label }}</span> |
| 386 | <span class="page-ribbon-list-badge">{{ activePageData.count }}</span> |
| 387 | </div> |
| 388 | |
| 389 | <button |
| 390 | ref="listMenuButtonRef" |
| 391 | type="button" |
| 392 | class="ribbon-menu-btn" |
| 393 | :class="{ active: showListMenu }" |
| 394 | title="Filter by page" |
| 395 | @click.stop="toggleListMenu" |
| 396 | > |
| 397 | <Menu :size="18" stroke-width="2" /> |
| 398 | </button> |
| 399 | |
| 400 | <!-- List menu dropdown --> |
| 401 | <Transition name="ribbon-menu-popup"> |
| 402 | <div |
| 403 | v-if="showListMenu" |
| 404 | ref="listMenuRef" |
| 405 | class="page-ribbon-list-menu" |
| 406 | > |
| 407 | <!-- "All" item --> |
| 408 | <button |
| 409 | type="button" |
| 410 | class="ribbon-menu-item all-item" |
| 411 | :class="{ active: urlSearchMode |
| 412 | ? urlActivePageFilter === null |
| 413 | : activePageFilter === null }" |
| 414 | @click="urlSearchMode |
| 415 | ? setUrlPageFilter(null) |
| 416 | : setPageFilter(null)" |
| 417 | > |
| 418 | <span class="i-lucide:text-search ribbon-menu-item-icon" /> |
| 419 | <span class="ribbon-menu-item-label">All</span> |
| 420 | <span class="ribbon-menu-item-count">{{ urlSearchMode ? urlMatchesLength : resultsLength }}</span> |
| 421 | </button> |
| 422 | |
| 423 | <div class="ribbon-menu-divider" /> |
| 424 | |
| 425 | <!-- Grouped pages --> |
| 426 | <template v-for="entry in groupedMenuEntries" :key="entry.type === 'page' ? entry.page.key : entry.folder.section"> |
| 427 | <!-- Top-level page --> |
| 428 | <div v-if="entry.type === 'page'" class="ribbon-menu-group"> |
| 429 | <button |
| 430 | type="button" |
| 431 | class="ribbon-menu-item" |
| 432 | :class="{ active: urlSearchMode |
| 433 | ? urlActivePageFilter === entry.page.key |
| 434 | : activePageFilter === entry.page.key }" |
| 435 | @click="urlSearchMode |
| 436 | ? setUrlPageFilter(entry.page.key) |
| 437 | : setPageFilter(entry.page.key)" |
| 438 | > |
| 439 | <span :class="entry.page.iconClass" class="ribbon-menu-item-icon" /> |
| 440 | <span class="ribbon-menu-item-label">{{ entry.page.label }}</span> |
| 441 | <span class="ribbon-menu-item-count">{{ entry.page.count }}</span> |
| 442 | </button> |
| 443 | </div> |
| 444 | |
| 445 | <!-- Folder group --> |
| 446 | <div v-else class="ribbon-menu-group"> |
| 447 | <h4 class="ribbon-menu-group-title"> |
| 448 | <span :class="entry.folder.iconClass" class="ribbon-menu-group-icon" /> |
| 449 | <span class="ribbon-menu-group-text">{{ entry.folder.section }}</span> |
| 450 | </h4> |
| 451 | <div class="ribbon-menu-sub-items"> |
| 452 | <button |
| 453 | v-for="page in entry.folder.pages" |
| 454 | :key="page.key" |
| 455 | type="button" |
| 456 | class="ribbon-menu-item" |
| 457 | :class="{ active: urlSearchMode |
| 458 | ? urlActivePageFilter === page.key |
| 459 | : activePageFilter === page.key }" |
| 460 | @click="urlSearchMode |
| 461 | ? setUrlPageFilter(page.key) |
| 462 | : setPageFilter(page.key)" |
| 463 | > |
| 464 | <span class="ribbon-menu-item-label">{{ page.label }}</span> |
| 465 | <span class="ribbon-menu-item-count">{{ page.count }}</span> |
| 466 | </button> |
| 467 | </div> |
| 468 | </div> |
| 469 | </template> |
| 470 | </div> |
| 471 | </Transition> |
| 472 | </component> |
| 473 | |
| 474 | <!-- Tabs ribbon style (original) --> |
| 233 | 475 | <component |
| 234 | 476 | :is="searchMotionDiv" |
| 235 | | v-if="urlSearchMode |
| 477 | v-if="ribbonStyle !== 'list' && (urlSearchMode |
| 236 | 478 | ? urlPageGroups.length > 1 |
| 237 | | : pageGroups.length > 1" |
| 479 | : pageGroups.length > 1)" |
| 238 | 480 | class="page-ribbon" |
| 239 | 481 | :class="{ |
| 240 | 482 | 'can-scroll-left': ribbonCanScrollLeft, |
| @@ -482,4 +724,237 @@ function setPageFilter(key: string | null) { |
| 482 | 724 | font-size: 0.8rem; |
| 483 | 725 | } |
| 484 | 726 | } |
| 727 | |
| 728 | /* List ribbon style */ |
| 729 | .page-ribbon-list { |
| 730 | justify-content: space-between; |
| 731 | padding: 6px 12px 4px; |
| 732 | overflow: visible; |
| 733 | } |
| 734 | |
| 735 | .page-ribbon-list-label { |
| 736 | display: flex; |
| 737 | align-items: center; |
| 738 | gap: 6px; |
| 739 | font-size: 0.9rem; |
| 740 | font-weight: 500; |
| 741 | color: var(--vp-c-text-2); |
| 742 | font-variant-numeric: tabular-nums; |
| 743 | line-height: 1; |
| 744 | min-width: 0; |
| 745 | } |
| 746 | |
| 747 | .page-ribbon-list-icon { |
| 748 | flex: none; |
| 749 | font-size: 16px; |
| 750 | width: 1em; |
| 751 | height: 1em; |
| 752 | color: var(--vp-c-text-1); |
| 753 | } |
| 754 | |
| 755 | .page-ribbon-list-name { |
| 756 | overflow: hidden; |
| 757 | text-overflow: ellipsis; |
| 758 | white-space: nowrap; |
| 759 | min-width: 0; |
| 760 | color: var(--vp-c-text-1); |
| 761 | font-weight: 600; |
| 762 | } |
| 763 | |
| 764 | .page-ribbon-list-badge { |
| 765 | flex-shrink: 0; |
| 766 | font-variant-numeric: tabular-nums; |
| 767 | font-size: 0.72rem; |
| 768 | padding: 1px 7px; |
| 769 | border-radius: 4px; |
| 770 | background: rgba(128, 128, 128, 0.15); |
| 771 | color: var(--vp-c-text-1); |
| 772 | line-height: 1.5; |
| 773 | font-weight: 600; |
| 774 | } |
| 775 | |
| 776 | .ribbon-menu-btn { |
| 777 | display: flex; |
| 778 | align-items: center; |
| 779 | justify-content: center; |
| 780 | border: none; |
| 781 | background: transparent; |
| 782 | color: var(--vp-c-text-1); |
| 783 | opacity: 0.55; |
| 784 | padding: 8px 4px; |
| 785 | cursor: pointer; |
| 786 | transition: |
| 787 | opacity 0.25s, |
| 788 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); |
| 789 | border-radius: 0; |
| 790 | line-height: 1; |
| 791 | } |
| 792 | |
| 793 | .ribbon-menu-btn:hover, |
| 794 | .ribbon-menu-btn.active { |
| 795 | color: var(--vp-c-text-1); |
| 796 | opacity: 1; |
| 797 | background: transparent; |
| 798 | } |
| 799 | |
| 800 | .ribbon-menu-btn:active { |
| 801 | transform: scale(0.94); |
| 802 | } |
| 803 | |
| 804 | html.effects-disabled .ribbon-menu-btn { |
| 805 | transition: none; |
| 806 | } |
| 807 | |
| 808 | html.effects-disabled .ribbon-menu-btn:active { |
| 809 | transform: none; |
| 810 | } |
| 811 | |
| 812 | .page-ribbon-list-menu { |
| 813 | position: absolute; |
| 814 | top: 100%; |
| 815 | right: 4px; |
| 816 | z-index: 50; |
| 817 | width: 228px; |
| 818 | max-height: 320px; |
| 819 | overflow-y: auto; |
| 820 | overflow-x: hidden; |
| 821 | background: var(--vp-c-bg-elv); |
| 822 | border: 1px solid var(--vp-c-divider); |
| 823 | border-radius: 12px; |
| 824 | box-shadow: var(--vp-shadow-3); |
| 825 | padding: 8px; |
| 826 | overscroll-behavior: contain; |
| 827 | scrollbar-width: none; |
| 828 | -ms-overflow-style: none; |
| 829 | } |
| 830 | |
| 831 | .page-ribbon-list-menu::-webkit-scrollbar { |
| 832 | display: none; |
| 833 | } |
| 834 | |
| 835 | .ribbon-menu-divider { |
| 836 | height: 1px; |
| 837 | background: var(--vp-c-divider); |
| 838 | margin: 4px 0; |
| 839 | } |
| 840 | |
| 841 | .ribbon-menu-item { |
| 842 | display: flex; |
| 843 | align-items: center; |
| 844 | gap: 8px; |
| 845 | padding: 6px 8px; |
| 846 | border: none; |
| 847 | background: transparent; |
| 848 | border-radius: 6px; |
| 849 | color: var(--vp-c-text-2); |
| 850 | font-size: 0.82rem; |
| 851 | font-weight: 500; |
| 852 | cursor: pointer; |
| 853 | transition: background-color 0.15s, color 0.15s; |
| 854 | text-align: left; |
| 855 | width: 100%; |
| 856 | } |
| 857 | |
| 858 | .ribbon-menu-item:hover { |
| 859 | background: var(--vp-c-default-soft); |
| 860 | color: var(--vp-c-text-1); |
| 861 | } |
| 862 | |
| 863 | .ribbon-menu-item.active { |
| 864 | color: var(--vp-c-brand-1); |
| 865 | background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); |
| 866 | font-weight: 600; |
| 867 | } |
| 868 | |
| 869 | .ribbon-menu-item-icon { |
| 870 | flex: none; |
| 871 | font-size: 15px; |
| 872 | color: var(--vp-c-text-1); |
| 873 | width: 1em; |
| 874 | height: 1em; |
| 875 | } |
| 876 | |
| 877 | .ribbon-menu-item-label { |
| 878 | flex: 1; |
| 879 | overflow: hidden; |
| 880 | text-overflow: ellipsis; |
| 881 | white-space: nowrap; |
| 882 | min-width: 0; |
| 883 | } |
| 884 | |
| 885 | .all-item { |
| 886 | font-weight: 600; |
| 887 | font-size: 0.85rem; |
| 888 | } |
| 889 | |
| 890 | .ribbon-menu-item-count { |
| 891 | flex-shrink: 0; |
| 892 | font-variant-numeric: tabular-nums; |
| 893 | font-size: 0.68rem; |
| 894 | padding: 1px 6px; |
| 895 | border-radius: 3px; |
| 896 | background: rgba(128, 128, 128, 0.12); |
| 897 | color: var(--vp-c-text-3); |
| 898 | line-height: 1.4; |
| 899 | margin-left: auto; |
| 900 | } |
| 901 | |
| 902 | .ribbon-menu-item.active .ribbon-menu-item-count { |
| 903 | color: var(--vp-c-text-2); |
| 904 | background: rgba(128, 128, 128, 0.18); |
| 905 | } |
| 906 | |
| 907 | .ribbon-menu-group + .ribbon-menu-group { |
| 908 | margin-top: 2px; |
| 909 | } |
| 910 | |
| 911 | .ribbon-menu-group-title { |
| 912 | display: flex; |
| 913 | align-items: center; |
| 914 | gap: 6px; |
| 915 | font-size: 11px; |
| 916 | font-weight: 700; |
| 917 | letter-spacing: 0.02em; |
| 918 | color: var(--vp-c-text-1); |
| 919 | margin: 8px 0 2px; |
| 920 | padding: 0 8px 4px; |
| 921 | user-select: none; |
| 922 | border-bottom: 1px solid var(--vp-c-divider); |
| 923 | } |
| 924 | |
| 925 | .ribbon-menu-group-icon { |
| 926 | font-size: 13px; |
| 927 | flex: none; |
| 928 | width: 1em; |
| 929 | height: 1em; |
| 930 | color: var(--vp-c-text-1); |
| 931 | } |
| 932 | |
| 933 | .ribbon-menu-group-text { |
| 934 | flex: 1; |
| 935 | min-width: 0; |
| 936 | overflow: hidden; |
| 937 | white-space: nowrap; |
| 938 | text-overflow: ellipsis; |
| 939 | text-transform: uppercase; |
| 940 | letter-spacing: 0.06em; |
| 941 | } |
| 942 | |
| 943 | .ribbon-menu-sub-items { |
| 944 | display: flex; |
| 945 | flex-direction: column; |
| 946 | gap: 1px; |
| 947 | } |
| 948 | |
| 949 | .ribbon-menu-popup-enter-active, |
| 950 | .ribbon-menu-popup-leave-active { |
| 951 | transition: opacity 0.12s ease, transform 0.12s ease; |
| 952 | transform-origin: top right; |
| 953 | } |
| 954 | |
| 955 | .ribbon-menu-popup-enter-from, |
| 956 | .ribbon-menu-popup-leave-to { |
| 957 | opacity: 0; |
| 958 | transform: scale(0.92) translateY(-4px); |
| 959 | } |
| 485 | 960 | </style> |