Commit 15682beef3

15682beef36539cf78cba398b73940dd28c58650

parent: d96aa184f5

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-27 05:53 UTC

Add menu help

Layout: unified · split

docs/.vitepress/theme/components/Search.vue +283 −15
@@ -43,12 +43,15 @@ import {
4343 ArrowRight,
4444 ArrowRightToLine,
4545 ChevronRight,
46 Clock,
4647 File,
4748 Globe,
4849 Hash,
50 LayoutList,
4951 List,
5052 LocateOff,
5153 Regex,
54 Search,
5255 Settings2,
5356 TextAlignStart,
5457 X
@@ -336,6 +339,48 @@ const showSettingsPopup = ref(false)
336339const settingsButtonRef = ref<HTMLButtonElement>()
337340const settingsPopupRef = ref<HTMLDivElement>()
338341const settingsBounding = useElementBounding(settingsButtonRef)
342type HelpSection = 'search' | 'view' | 'history'
343const activeHelpSection = ref<HelpSection | null>(null)
344const helpPopupEl = ref<HTMLDivElement>()
345const helpPopupPos = ref({ top: -9999, left: -9999 })
346
347watch(showSettingsPopup, (val) => {
348 if (!val) {
349 activeHelpSection.value = null
350 helpPopupPos.value = { top: -9999, left: -9999 }
351 }
352})
353
354function toggleHelpSection(section: HelpSection, e: MouseEvent) {
355 if (activeHelpSection.value === section) {
356 activeHelpSection.value = null
357 helpPopupPos.value = { top: -9999, left: -9999 }
358 return
359 }
360 activeHelpSection.value = section
361 helpPopupPos.value = { top: -9999, left: -9999 }
362 const btn = e.currentTarget as HTMLElement
363 const rect = btn.getBoundingClientRect()
364 nextTick(() => {
365 const popupW = helpPopupEl.value?.offsetWidth || 260
366 const popupH = helpPopupEl.value?.offsetHeight || 200
367 const vw = window.innerWidth
368 const margin = 8
369 const isMobile = vw < 768
370 if (isMobile) {
371 const aboveTop = rect.top - popupH - margin
372 const belowTop = rect.bottom + margin
373 const top = aboveTop >= margin ? aboveTop : belowTop
374 const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin))
375 helpPopupPos.value = { top, left }
376 } else {
377 helpPopupPos.value = {
378 left: Math.max(margin, rect.left - popupW - 16),
379 top: rect.top,
380 }
381 }
382 })
383}
339384
340385const settingsPopupStyle = computed(() => ({
341386 top: `${settingsBounding.bottom.value + 8}px`,
@@ -2348,9 +2393,24 @@ function onMouseMove(e: MouseEvent) {
23482393 ref="settingsPopupRef"
23492394 class="search-settings-popup"
23502395 :style="settingsPopupStyle"
2396 @click="activeHelpSection = null"
23512397 >
23522398 <div class="settings-section">
2353 <div class="settings-section-label">Search</div>
2399 <div class="settings-section-header">
2400 <div class="settings-section-label">
2401 <Search :size="10" stroke-width="2.5" />
2402 Search
2403 </div>
2404 <button
2405 type="button"
2406 class="settings-help-btn"
2407 :class="{ active: activeHelpSection === 'search' }"
2408 aria-label="Search mode help"
2409 @click.stop="toggleHelpSection('search', $event)"
2410 >
2411 <span class="i-carbon:help-filled settings-help-icon" />
2412 </button>
2413 </div>
23542414 <div class="settings-options">
23552415 <button
23562416 type="button"
@@ -2382,7 +2442,21 @@ function onMouseMove(e: MouseEvent) {
23822442 v-if="!disableDetailedView && searchMode !== 'url'"
23832443 class="settings-section"
23842444 >
2385 <div class="settings-section-label">View</div>
2445 <div class="settings-section-header">
2446 <div class="settings-section-label">
2447 <LayoutList :size="10" stroke-width="2.5" />
2448 View
2449 </div>
2450 <button
2451 type="button"
2452 class="settings-help-btn"
2453 :class="{ active: activeHelpSection === 'view' }"
2454 aria-label="Result view help"
2455 @click.stop="toggleHelpSection('view', $event)"
2456 >
2457 <span class="i-carbon:help-filled settings-help-icon" />
2458 </button>
2459 </div>
23862460 <div class="settings-options">
23872461 <button
23882462 type="button"
@@ -2403,7 +2477,21 @@ function onMouseMove(e: MouseEvent) {
24032477 </div>
24042478 </div>
24052479 <div class="settings-section">
2406 <div class="settings-section-label">History</div>
2480 <div class="settings-section-header">
2481 <div class="settings-section-label">
2482 <Clock :size="10" stroke-width="2.5" />
2483 History
2484 </div>
2485 <button
2486 type="button"
2487 class="settings-help-btn"
2488 :class="{ active: activeHelpSection === 'history' }"
2489 aria-label="Search history help"
2490 @click.stop="toggleHelpSection('history', $event)"
2491 >
2492 <span class="i-carbon:help-filled settings-help-icon" />
2493 </button>
2494 </div>
24072495 <div class="settings-options">
24082496 <button
24092497 type="button"
@@ -2425,6 +2513,75 @@ function onMouseMove(e: MouseEvent) {
24252513 </div>
24262514 </div>
24272515 </Transition>
2516 <Transition name="help-popup-fade">
2517 <div
2518 v-if="activeHelpSection && showSettingsPopup"
2519 ref="helpPopupEl"
2520 class="search-help-popup"
2521 :style="{ top: helpPopupPos.top + 'px', left: helpPopupPos.left + 'px' }"
2522 >
2523 <template v-if="activeHelpSection === 'search'">
2524 <h4 class="sh-title">
2525 <Search :size="14" stroke-width="1.75" class="sh-title-icon" />
2526 Search Mode
2527 </h4>
2528 <p class="sh-desc">Choose how queries are matched against content.</p>
2529 <div class="sh-options">
2530 <div class="sh-option">
2531 <strong>
2532 <Regex :size="12" stroke-width="1.5" />
2533 Exact
2534 </strong>
2535 <span>Matches the exact phrase you type</span>
2536 </div>
2537 <div class="sh-option">
2538 <strong>
2539 <LocateOff :size="12" stroke-width="1.5" />
2540 Fuzzy
2541 </strong>
2542 <span>Approximate matching that tolerates typos</span>
2543 </div>
2544 <div class="sh-option">
2545 <strong>
2546 <Globe :size="12" stroke-width="1.5" />
2547 URL
2548 </strong>
2549 <span>Searches page URLs and link destinations</span>
2550 </div>
2551 </div>
2552 </template>
2553 <template v-else-if="activeHelpSection === 'view'">
2554 <h4 class="sh-title">
2555 <LayoutList :size="14" stroke-width="1.75" class="sh-title-icon" />
2556 Result View
2557 </h4>
2558 <p class="sh-desc">Controls how search results are displayed.</p>
2559 <div class="sh-options">
2560 <div class="sh-option">
2561 <strong>
2562 <TextAlignStart :size="12" stroke-width="1.5" />
2563 Detail
2564 </strong>
2565 <span>Shows a content excerpt below each result. Uses more memory.</span>
2566 </div>
2567 <div class="sh-option">
2568 <strong>
2569 <List :size="12" stroke-width="1.5" />
2570 List
2571 </strong>
2572 <span>Compact list of titles only. Uses less memory.</span>
2573 </div>
2574 </div>
2575 </template>
2576 <template v-else-if="activeHelpSection === 'history'">
2577 <h4 class="sh-title">
2578 <Clock :size="14" stroke-width="1.75" class="sh-title-icon" />
2579 Search History
2580 </h4>
2581 <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p>
2582 </template>
2583 </div>
2584 </Transition>
24282585 </Teleport>
24292586 </component>
24302587 </AnimatePresence>
@@ -3142,38 +3299,149 @@ svg {
31423299 z-index: 200;
31433300 background: var(--vp-c-bg);
31443301 border: 1px solid var(--vp-c-divider);
3145 border-radius: 10px;
3146 padding: 10px;
3302 border-radius: 12px;
3303 padding: 14px;
31473304 box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
31483305 display: flex;
31493306 flex-direction: column;
3150 min-width: 196px;
3307 min-width: 224px;
31513308}
31523309
31533310.settings-section {
31543311 display: flex;
31553312 flex-direction: column;
3156 gap: 6px;
3313 gap: 8px;
31573314}
31583315
31593316.settings-section + .settings-section {
31603317 border-top: 1px solid var(--vp-c-divider);
3161 margin-top: 8px;
3162 padding-top: 8px;
3318 margin-top: 10px;
3319 padding-top: 10px;
3320}
3321
3322.settings-section-header {
3323 display: flex;
3324 align-items: center;
3325 justify-content: space-between;
3326 margin-bottom: 2px;
31633327}
31643328
31653329.settings-section-label {
3166 font-size: 11px;
3330 display: flex;
3331 align-items: center;
3332 gap: 4px;
3333 font-size: 11.5px;
31673334 font-weight: 600;
31683335 text-transform: uppercase;
31693336 letter-spacing: 0.06em;
31703337 color: var(--vp-c-text-3, var(--vp-c-text-2));
3171 margin-bottom: 2px;
3338}
3339
3340.settings-help-btn {
3341 display: flex;
3342 align-items: center;
3343 justify-content: center;
3344 padding: 3px;
3345 background: transparent;
3346 border: none;
3347 cursor: pointer;
3348 color: var(--vp-c-text-3);
3349 opacity: 0.5;
3350 transition: opacity 0.15s, color 0.15s;
3351 border-radius: 3px;
3352 line-height: 1;
3353}
3354
3355.settings-help-btn:hover,
3356.settings-help-btn.active {
3357 opacity: 1;
3358 color: var(--vp-c-text-1);
3359}
3360
3361.settings-help-icon {
3362 display: block;
3363 width: 14px;
3364 height: 14px;
3365}
3366
3367/* Help popup */
3368.search-help-popup {
3369 position: fixed;
3370 z-index: 9999;
3371 width: 260px;
3372 background: var(--vp-c-bg-elv);
3373 border: 1px solid var(--vp-c-divider);
3374 border-radius: 12px;
3375 padding: 16px;
3376 box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
3377 pointer-events: none;
3378}
3379
3380.help-popup-fade-enter-active,
3381.help-popup-fade-leave-active {
3382 transition: opacity 0.15s ease;
3383}
3384
3385.help-popup-fade-enter-from,
3386.help-popup-fade-leave-to {
3387 opacity: 0;
3388}
3389
3390.sh-title {
3391 display: flex;
3392 align-items: center;
3393 gap: 6px;
3394 font-size: 0.875rem;
3395 font-weight: 600;
3396 color: var(--vp-c-text-1);
3397 margin: 0 0 6px;
3398}
3399
3400.sh-title-icon {
3401 flex-shrink: 0;
3402 opacity: 0.8;
3403}
3404
3405.sh-desc {
3406 font-size: 0.78rem;
3407 color: var(--vp-c-text-2);
3408 margin: 0 0 10px;
3409 line-height: 1.5;
3410}
3411
3412.sh-options {
3413 display: flex;
3414 flex-direction: column;
3415 gap: 5px;
3416}
3417
3418.sh-option {
3419 display: flex;
3420 flex-direction: column;
3421 gap: 2px;
3422 background: var(--vp-c-bg-soft);
3423 border-radius: 6px;
3424 padding: 7px 9px;
3425}
3426
3427.sh-option strong {
3428 display: flex;
3429 align-items: center;
3430 gap: 5px;
3431 font-size: 0.78rem;
3432 font-weight: 600;
3433 color: var(--vp-c-text-1);
3434}
3435
3436.sh-option span {
3437 font-size: 0.74rem;
3438 color: var(--vp-c-text-2);
3439 line-height: 1.4;
31723440}
31733441
31743442.settings-options {
31753443 display: flex;
3176 gap: 4px;
3444 gap: 5px;
31773445}
31783446
31793447.settings-option {
@@ -3181,13 +3449,13 @@ svg {
31813449 align-items: center;
31823450 justify-content: center;
31833451 gap: 5px;
3184 padding: 5px 6px;
3452 padding: 7px 8px;
31853453 background: transparent;
31863454 border: none;
3187 border-radius: 5px;
3455 border-radius: 6px;
31883456 cursor: pointer;
31893457 color: var(--vp-c-text-2);
3190 font-size: 14px;
3458 font-size: 14.5px;
31913459 font-weight: 500;
31923460 transition: background-color 0.15s, color 0.15s;
31933461 flex: 1;