Branch pill opens a filterable switcher for branches and tags
Browse files at this commit02c773dc609d576aacc21e7312efda9731925ff5Parent: 93ac114- feat
- branch pill opens a filterable switcher for branches and tags
7 changed files +357 -74
- crates/forge-web/assets/nav.js +96 -0
- crates/forge-web/src/i18n/code.rs +16 -0
- crates/forge-web/src/pages/refs.rs +40 -28
- crates/forge-web/src/pages/repo.rs +25 -12
- crates/forge-web/src/pages/tree.rs +13 -2
- crates/forge-web/src/views/mod.rs +54 -21
- style/main.scss +113 -11
crates/forge-web/assets/nav.jsmodified+96 -0
| @@ -2024,6 +2024,102 @@ | ||
| 2024 | 2024 | if (btn) { e.preventDefault(); copyLog(btn); } |
| 2025 | 2025 | }, false); |
| 2026 | 2026 | |
| 2027 | + // ---- branch switcher ------------------------------------------------------------------------ | |
| 2028 | + // The ref popover in the browse bar: a filter over the active list, Branches and Tags tabs, and | |
| 2029 | + // arrow keys through the visible entries as in the file finder. Entries past the first REF_SHOWN | |
| 2030 | + // stay hidden until the filter narrows them, so the filter still reaches every name. | |
| 2031 | + | |
| 2032 | + var REF_SHOWN = 10; | |
| 2033 | + | |
| 2034 | + function refSwitchOf(el) { | |
| 2035 | + return el && el.closest ? el.closest('details[data-ref-switch]') : null; | |
| 2036 | + } | |
| 2037 | + | |
| 2038 | + function refPanelOf(sw) { | |
| 2039 | + var tab = sw.querySelector('[data-ref-tab][aria-selected="true"]'); | |
| 2040 | + var kind = tab ? tab.getAttribute('data-ref-tab') : 'branches'; | |
| 2041 | + return sw.querySelector('[data-ref-panel="' + kind + '"]'); | |
| 2042 | + } | |
| 2043 | + | |
| 2044 | + function refShown(panel) { | |
| 2045 | + return Array.prototype.filter.call(panel.querySelectorAll('[data-ref-item]'), function (li) { | |
| 2046 | + return !li.hidden; | |
| 2047 | + }); | |
| 2048 | + } | |
| 2049 | + | |
| 2050 | + // Applies the filter to the active panel: every match, or the first entries when it is empty. | |
| 2051 | + function refApply(sw) { | |
| 2052 | + var q = sw.querySelector('[data-ref-filter]').value.trim().toLowerCase(); | |
| 2053 | + var panel = refPanelOf(sw); | |
| 2054 | + var empty = panel.querySelector('[data-ref-empty]'); | |
| 2055 | + var shown = 0; | |
| 2056 | + Array.prototype.forEach.call(panel.querySelectorAll('[data-ref-item]'), function (li, i) { | |
| 2057 | + var show = q ? li.textContent.trim().toLowerCase().indexOf(q) >= 0 : i < REF_SHOWN; | |
| 2058 | + li.hidden = !show; | |
| 2059 | + li.removeAttribute('aria-selected'); | |
| 2060 | + if (show) { shown++; } | |
| 2061 | + }); | |
| 2062 | + if (empty) { empty.hidden = shown > 0; } | |
| 2063 | + refSelect(sw, 0); | |
| 2064 | + } | |
| 2065 | + | |
| 2066 | + function refSelect(sw, index) { | |
| 2067 | + var panel = refPanelOf(sw); | |
| 2068 | + var input = sw.querySelector('[data-ref-filter]'); | |
| 2069 | + var shown = refShown(panel); | |
| 2070 | + if (!shown.length) { input.removeAttribute('aria-activedescendant'); return; } | |
| 2071 | + index = Math.max(0, Math.min(shown.length - 1, index)); | |
| 2072 | + shown.forEach(function (li, i) { li.setAttribute('aria-selected', i === index ? 'true' : 'false'); }); | |
| 2073 | + input.setAttribute('aria-activedescendant', shown[index].id); | |
| 2074 | + shown[index].scrollIntoView({ block: 'nearest' }); | |
| 2075 | + panel.__sel = index; | |
| 2076 | + } | |
| 2077 | + | |
| 2078 | + // Opening the switcher clears the filter and focuses it. | |
| 2079 | + document.addEventListener('toggle', function (e) { | |
| 2080 | + var sw = e.target; | |
| 2081 | + if (!sw || !sw.hasAttribute || !sw.hasAttribute('data-ref-switch') || !sw.open) { return; } | |
| 2082 | + var input = sw.querySelector('[data-ref-filter]'); | |
| 2083 | + input.value = ''; | |
| 2084 | + refApply(sw); | |
| 2085 | + input.focus(); | |
| 2086 | + }, true); | |
| 2087 | + | |
| 2088 | + document.addEventListener('click', function (e) { | |
| 2089 | + var tab = e.target && e.target.closest ? e.target.closest('[data-ref-tab]') : null; | |
| 2090 | + if (!tab) { return; } | |
| 2091 | + var sw = refSwitchOf(tab); | |
| 2092 | + var kind = tab.getAttribute('data-ref-tab'); | |
| 2093 | + sw.querySelectorAll('[data-ref-tab]').forEach(function (t) { | |
| 2094 | + t.setAttribute('aria-selected', t === tab ? 'true' : 'false'); | |
| 2095 | + }); | |
| 2096 | + sw.querySelectorAll('[data-ref-panel]').forEach(function (p) { | |
| 2097 | + p.hidden = p.getAttribute('data-ref-panel') !== kind; | |
| 2098 | + }); | |
| 2099 | + refApply(sw); | |
| 2100 | + }, false); | |
| 2101 | + | |
| 2102 | + document.addEventListener('keydown', function (e) { | |
| 2103 | + var input = e.target && e.target.closest ? e.target.closest('[data-ref-filter]') : null; | |
| 2104 | + if (!input) { return; } | |
| 2105 | + var sw = refSwitchOf(input); | |
| 2106 | + var panel = refPanelOf(sw); | |
| 2107 | + var sel = panel.__sel || 0; | |
| 2108 | + if (e.key === 'ArrowDown') { e.preventDefault(); refSelect(sw, sel + 1); } | |
| 2109 | + else if (e.key === 'ArrowUp') { e.preventDefault(); refSelect(sw, sel - 1); } | |
| 2110 | + else if (e.key === 'Enter') { | |
| 2111 | + e.preventDefault(); | |
| 2112 | + var item = refShown(panel)[sel]; | |
| 2113 | + var link = item ? item.querySelector('a') : null; | |
| 2114 | + if (link) { sw.open = false; link.click(); } | |
| 2115 | + } | |
| 2116 | + }, false); | |
| 2117 | + | |
| 2118 | + document.addEventListener('input', function (e) { | |
| 2119 | + var input = e.target && e.target.closest ? e.target.closest('[data-ref-filter]') : null; | |
| 2120 | + if (input) { refApply(refSwitchOf(input)); } | |
| 2121 | + }, false); | |
| 2122 | + | |
| 2027 | 2123 | document.addEventListener('input', function (e) { |
| 2028 | 2124 | var input = e.target && e.target.closest ? e.target.closest('[data-finder-input]') : null; |
| 2029 | 2125 | if (input) { renderFinder(input.closest('dialog')); } |
crates/forge-web/src/i18n/code.rsmodified+16 -0
| @@ -23,6 +23,10 @@ pub enum K { | ||
| 23 | 23 | CloneTitle, |
| 24 | 24 | SshRequiresKey, |
| 25 | 25 | BranchesTitle, |
| 26 | + FilterRefs, | |
| 27 | + ViewAll, | |
| 28 | + ViewAllBranches, | |
| 29 | + ViewAllTags, | |
| 26 | 30 | EmptyRepoPush, |
| 27 | 31 | OverHttps, |
| 28 | 32 | OverSsh, |
| @@ -157,6 +161,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 157 | 161 | (SshRequiresKey, Tr) => "SSH (hesabınızda bir ed25519 veya ECDSA anahtarı olmalı)", |
| 158 | 162 | (BranchesTitle, En) => "Branches", |
| 159 | 163 | (BranchesTitle, Tr) => "Dallar", |
| 164 | + (FilterRefs, En) => "Filter branches and tags", | |
| 165 | + (FilterRefs, Tr) => "Dal ve etiketleri süz", | |
| 166 | + (ViewAll, En) => "View all", | |
| 167 | + (ViewAll, Tr) => "Tümünü gör", | |
| 168 | + (ViewAllBranches, En) => "View all branches", | |
| 169 | + (ViewAllBranches, Tr) => "Tüm dalları gör", | |
| 170 | + (ViewAllTags, En) => "View all tags", | |
| 171 | + (ViewAllTags, Tr) => "Tüm etiketleri gör", | |
| 160 | 172 | (EmptyRepoPush, En) => "This repository is empty. Push a branch to get started:", |
| 161 | 173 | (EmptyRepoPush, Tr) => "Bu depo boş. Başlamak için bir dal gönderin:", |
| 162 | 174 | (OverHttps, En) => "Over HTTPS", |
| @@ -530,6 +542,10 @@ mod tests { | ||
| 530 | 542 | K::CloneTitle, |
| 531 | 543 | K::SshRequiresKey, |
| 532 | 544 | K::BranchesTitle, |
| 545 | + K::FilterRefs, | |
| 546 | + K::ViewAll, | |
| 547 | + K::ViewAllBranches, | |
| 548 | + K::ViewAllTags, | |
| 533 | 549 | K::EmptyRepoPush, |
| 534 | 550 | K::OverHttps, |
| 535 | 551 | K::OverSsh, |
crates/forge-web/src/pages/refs.rsmodified+40 -28
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | //! Page: the tag list at `/{owner}/{repo}/tags` (branches are in `branches`). |
| 2 | 2 | //! Also the ref helpers shared with the tree page (the ref selector). |
| 3 | 3 | |
| 4 | +use std::cmp::Reverse; | |
| 4 | 5 | use std::path::PathBuf; |
| 5 | 6 | |
| 6 | 7 | use crate::state::AppState; |
| @@ -27,38 +28,49 @@ pub async fn load_refs(path: PathBuf) -> Result<Vec<RefInfo>> { | ||
| 27 | 28 | Ok(tokio::task::spawn_blocking(move || browse::list_refs(&path)).await??) |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | -/// Branch and tag links for the ref selector. The default branch sorts first. | |
| 31 | -pub fn ref_links( | |
| 32 | - refs: &[RefInfo], | |
| 31 | +/// Branch and tag links for the ref switcher, each with the commit time of its tip. The default | |
| 32 | +/// branch sorts first, the rest newest first. | |
| 33 | +pub async fn ref_links( | |
| 34 | + path: PathBuf, | |
| 35 | + refs: Vec<RefInfo>, | |
| 33 | 36 | current: &str, |
| 34 | 37 | default_branch: &str, |
| 35 | 38 | repo: &RepoRow, |
| 36 | -) -> (Vec<RefLink>, Vec<RefLink>) { | |
| 37 | - let branches = sorted(refs, RefKind::Branch, default_branch) | |
| 38 | - .into_iter() | |
| 39 | - .map(|r| ref_link(repo, &r.name, current)); | |
| 40 | - let tags = sorted(refs, RefKind::Tag, default_branch) | |
| 41 | - .into_iter() | |
| 42 | - .map(|r| ref_link(repo, &r.name, current)); | |
| 43 | - (branches.collect(), tags.collect()) | |
| 44 | -} | |
| 45 | - | |
| 46 | -fn ref_link(repo: &RepoRow, name: &str, current: &str) -> RefLink { | |
| 47 | - RefLink { | |
| 48 | - name: name.to_owned(), | |
| 49 | - href: repo_href(&repo.owner_name, &repo.name, "tree", name), | |
| 50 | - current: name == current, | |
| 51 | - } | |
| 52 | -} | |
| 53 | - | |
| 54 | -/// Refs of one kind: the default branch first, then by name. | |
| 55 | -fn sorted<'a>(refs: &'a [RefInfo], kind: RefKind, default_branch: &str) -> Vec<&'a RefInfo> { | |
| 56 | - let mut out: Vec<&RefInfo> = refs.iter().filter(|r| r.kind == kind).collect(); | |
| 57 | - out.sort_by(|a, b| { | |
| 58 | - (a.name != default_branch, a.name.as_str()) | |
| 59 | - .cmp(&(b.name != default_branch, b.name.as_str())) | |
| 39 | +) -> Result<(Vec<RefLink>, Vec<RefLink>)> { | |
| 40 | + let mut timed = tokio::task::spawn_blocking(move || -> forge_git::Result<_> { | |
| 41 | + refs.into_iter() | |
| 42 | + .map(|r| { | |
| 43 | + let updated = | |
| 44 | + browse::read_commit(&path, &r.target)?.map_or(0, |c| c.committer_time); | |
| 45 | + Ok((r, updated)) | |
| 46 | + }) | |
| 47 | + .collect::<forge_git::Result<Vec<(RefInfo, i64)>>>() | |
| 48 | + }) | |
| 49 | + .await??; | |
| 50 | + timed.sort_by(|(a, ta), (b, tb)| { | |
| 51 | + (a.name != default_branch, Reverse(*ta), a.name.as_str()).cmp(&( | |
| 52 | + b.name != default_branch, | |
| 53 | + Reverse(*tb), | |
| 54 | + b.name.as_str(), | |
| 55 | + )) | |
| 60 | 56 | }); |
| 61 | - out | |
| 57 | + let link = |(r, updated): &(RefInfo, i64)| RefLink { | |
| 58 | + name: r.name.clone(), | |
| 59 | + href: repo_href(&repo.owner_name, &repo.name, "tree", &r.name), | |
| 60 | + current: r.name == current, | |
| 61 | + updated: *updated, | |
| 62 | + }; | |
| 63 | + let branches = timed | |
| 64 | + .iter() | |
| 65 | + .filter(|(r, _)| r.kind == RefKind::Branch) | |
| 66 | + .map(link) | |
| 67 | + .collect(); | |
| 68 | + let tags = timed | |
| 69 | + .iter() | |
| 70 | + .filter(|(r, _)| r.kind == RefKind::Tag) | |
| 71 | + .map(link) | |
| 72 | + .collect(); | |
| 73 | + Ok((branches, tags)) | |
| 62 | 74 | } |
| 63 | 75 | |
| 64 | 76 | /// One row of the branch or tag table. |
crates/forge-web/src/pages/repo.rsmodified+25 -12
| @@ -26,18 +26,21 @@ use crate::pages::finder::file_finder; | ||
| 26 | 26 | use crate::pages::issue_parts::stamp_unix; |
| 27 | 27 | use crate::pages::notifications::watch_form; |
| 28 | 28 | use crate::pages::packages::{self, repo_packages_card}; |
| 29 | -use crate::pages::refs::load_refs; | |
| 29 | +use crate::pages::refs::{load_refs, ref_links}; | |
| 30 | 30 | use crate::pages::releases::latest_card; |
| 31 | 31 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 32 | 32 | use crate::pages::tree::{ |
| 33 | 33 | entry_rows, last_commits, latest_bar, load_readme, read_dir, readme_card, tree_table, |
| 34 | 34 | }; |
| 35 | 35 | use crate::state::AppState; |
| 36 | -use crate::views::{now_unix, relative_time, repo_href, repo_tabs, shell, user_link}; | |
| 36 | +use crate::views::{now_unix, ref_selector, relative_time, repo_href, repo_tabs, shell, user_link}; | |
| 37 | 37 | |
| 38 | 38 | path_param!(owner); |
| 39 | 39 | path_param!(repo); |
| 40 | 40 | |
| 41 | +/// Branches listed in the aside, most recently updated first. The switcher lists the rest. | |
| 42 | +const RECENT_BRANCHES: usize = 5; | |
| 43 | + | |
| 41 | 44 | /// HTTPS clone URL: `{base_url}/{owner}/{repo}.git`. |
| 42 | 45 | pub fn https_clone_url(config: &Config, owner: &str, name: &str) -> String { |
| 43 | 46 | format!( |
| @@ -416,6 +419,12 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 416 | 419 | let branch = repo.default_branch.clone(); |
| 417 | 420 | |
| 418 | 421 | let refs = load_refs(ctx.path.clone()).await?; |
| 422 | + let (branches, tags) = | |
| 423 | + ref_links(ctx.path.clone(), refs.clone(), &branch, &branch, repo).await?; | |
| 424 | + let mut recent = branches.clone(); | |
| 425 | + recent.sort_by_key(|link| std::cmp::Reverse(link.updated)); | |
| 426 | + recent.truncate(RECENT_BRANCHES); | |
| 427 | + let branch_names: Vec<String> = branches.iter().map(|link| link.name.clone()).collect(); | |
| 419 | 428 | let head = default_commit(ctx.path.clone(), branch.clone()).await?; |
| 420 | 429 | |
| 421 | 430 | let https = https_clone_url(&state.config, &repo.owner_name, &repo.name); |
| @@ -460,14 +469,10 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 460 | 469 | } |
| 461 | 470 | let follows = follows_branch(&refs, &branch); |
| 462 | 471 | let live = live_url(&repo.owner_name, &repo.name, &refs, &branch); |
| 463 | - let branch_names: Vec<String> = refs | |
| 464 | - .into_iter() | |
| 465 | - .filter(|r| r.kind == browse::RefKind::Branch) | |
| 466 | - .map(|r| r.name) | |
| 467 | - .collect(); | |
| 468 | - | |
| 469 | 472 | let owner_name = repo.owner_name.clone(); |
| 470 | 473 | let repo_name = repo.name.clone(); |
| 474 | + let branches_href = repo_href(&owner_name, &repo_name, "branches", ""); | |
| 475 | + let tags_href = repo_href(&owner_name, &repo_name, "tags", ""); | |
| 471 | 476 | let mut header = ctx.head(state, "code").await?; |
| 472 | 477 | header.live = live; |
| 473 | 478 | let latest = crate::pages::releases::latest_release_for_home(state, &ctx).await?; |
| @@ -486,8 +491,8 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 486 | 491 | } |
| 487 | 492 | if let Some(rows) = tree { |
| 488 | 493 | <div class="browse-bar" data-live-code=(follows.then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> |
| 489 | - <span class="muted small">(g::t(lang, K::BranchLabel))</span> | |
| 490 | - <code>(branch.clone())</code> | |
| 494 | + ref_selector(lang: lang, label: g::t(lang, K::BranchLabel), current: branch.clone(), branches: branches, tags: tags, | |
| 495 | + branches_href: branches_href.clone(), tags_href: tags_href) | |
| 491 | 496 | file_finder(lang: lang, owner: owner_name.clone(), repo: repo_name.clone(), |
| 492 | 497 | ref_name: branch.clone()) |
| 493 | 498 | archive_links(owner: owner_name, repo: repo_name, |
| @@ -508,10 +513,17 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 508 | 513 | <section> |
| 509 | 514 | <h2>(g::t(lang, K::BranchesTitle))</h2> |
| 510 | 515 | <ul class="branch-list"> |
| 511 | - for name in branch_names.into_iter() { | |
| 512 | - <li><code>(name)</code></li> | |
| 516 | + for link in recent.into_iter() { | |
| 517 | + <li> | |
| 518 | + if link.current { | |
| 519 | + <a class="current" aria-current="true" href=(link.href)>(link.name)</a> | |
| 520 | + } else { | |
| 521 | + <a href=(link.href)>(link.name)</a> | |
| 522 | + } | |
| 523 | + </li> | |
| 513 | 524 | } |
| 514 | 525 | </ul> |
| 526 | + <p class="small"><a href=(branches_href)>(g::t(lang, K::ViewAll))</a></p> | |
| 515 | 527 | </section> |
| 516 | 528 | </aside> |
| 517 | 529 | </div> |
| @@ -666,6 +678,7 @@ mod tests { | ||
| 666 | 678 | ); |
| 667 | 679 | assert!(body.contains("/tahinli/demo/archive/main.tar.gz")); |
| 668 | 680 | assert!(body.contains("/tahinli/demo/branches")); |
| 681 | + assert!(body.contains("data-ref-filter"), "branch switcher rendered"); | |
| 669 | 682 | |
| 670 | 683 | // Trees list their entries and link to subtrees and blobs. |
| 671 | 684 | let (status, body) = get(&router, "/tahinli/demo/tree/main/src").await; |
crates/forge-web/src/pages/tree.rsmodified+13 -2
| @@ -16,6 +16,7 @@ use topcoat::router::{page, path_param}; | ||
| 16 | 16 | use topcoat::view::{Unescaped, View, component, view}; |
| 17 | 17 | |
| 18 | 18 | use crate::i18n::code::{self as g, K}; |
| 19 | +use crate::i18n::misc::{self as mi, K as MK}; | |
| 19 | 20 | use crate::i18n::{self, Lang}; |
| 20 | 21 | use crate::pages::code_live::{follows_branch, live_url}; |
| 21 | 22 | use crate::pages::finder::file_finder; |
| @@ -547,7 +548,16 @@ async fn tree_page(cx: &Cx) -> Result<impl View> { | ||
| 547 | 548 | now_unix(), |
| 548 | 549 | ctx.viewer_tz(), |
| 549 | 550 | ); |
| 550 | - let (branches, tags) = ref_links(&refs, &ref_name, &repo.default_branch, repo); | |
| 551 | + let (branches, tags) = ref_links( | |
| 552 | + ctx.path.clone(), | |
| 553 | + refs.clone(), | |
| 554 | + &ref_name, | |
| 555 | + &repo.default_branch, | |
| 556 | + repo, | |
| 557 | + ) | |
| 558 | + .await?; | |
| 559 | + let branches_href = repo_href(&repo.owner_name, &repo.name, "branches", ""); | |
| 560 | + let tags_href = repo_href(&repo.owner_name, &repo.name, "tags", ""); | |
| 551 | 561 | let live = follows_branch(&refs, &ref_name) |
| 552 | 562 | .then(|| live_url(&repo.owner_name, &repo.name, &refs, &ref_name)); |
| 553 | 563 | |
| @@ -566,7 +576,8 @@ async fn tree_page(cx: &Cx) -> Result<impl View> { | ||
| 566 | 576 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 567 | 577 | repo_head(head: header) |
| 568 | 578 | <div class="browse-bar" data-live=(live.as_deref()) data-live-code=(live.is_some().then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> |
| 569 | - ref_selector(lang: lang, current: ref_name.clone(), branches: branches, tags: tags) | |
| 579 | + ref_selector(lang: lang, label: mi::t(lang, MK::RefLabel), current: ref_name.clone(), branches: branches, tags: tags, | |
| 580 | + branches_href: branches_href, tags_href: tags_href) | |
| 570 | 581 | breadcrumb(lang: lang, crumbs: crumbs) |
| 571 | 582 | file_finder(lang: lang, owner: finder_owner, repo: finder_repo, ref_name: finder_ref) |
| 572 | 583 | </div> |
crates/forge-web/src/views/mod.rsmodified+54 -21
| @@ -1120,51 +1120,84 @@ pub async fn repo_tabs( | ||
| 1120 | 1120 | }) |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | -/// A branch or tag in the ref selector. `href` points at its root tree. | |
| 1123 | +/// A branch or tag in the ref switcher. `href` points at its root tree; `updated` is the commit | |
| 1124 | +/// time of its tip (unix seconds). | |
| 1125 | +#[derive(Clone)] | |
| 1124 | 1126 | pub struct RefLink { |
| 1125 | 1127 | pub name: String, |
| 1126 | 1128 | pub href: String, |
| 1127 | 1129 | pub current: bool, |
| 1130 | + pub updated: i64, | |
| 1128 | 1131 | } |
| 1129 | 1132 | |
| 1133 | +/// Entries listed before the filter narrows the list. The rest stay in the page, hidden, so the | |
| 1134 | +/// filter still finds every name. | |
| 1135 | +pub const REF_SHOWN: usize = 10; | |
| 1136 | + | |
| 1137 | +/// One tab of the ref switcher: its entries, then the link to the full list. | |
| 1130 | 1138 | #[component] |
| 1131 | -async fn ref_group(title: &str, links: Vec<RefLink>) -> Result<impl View> { | |
| 1139 | +async fn ref_panel( | |
| 1140 | + lang: Lang, | |
| 1141 | + kind: &'static str, | |
| 1142 | + links: Vec<RefLink>, | |
| 1143 | + all_href: String, | |
| 1144 | + all_label: &'static str, | |
| 1145 | +) -> Result<impl View> { | |
| 1146 | + let empty = links.is_empty(); | |
| 1132 | 1147 | Ok(view! { |
| 1133 | - <p class="ref-heading">(title)</p> | |
| 1134 | - <ul class="ref-list"> | |
| 1135 | - for link in links.into_iter() { | |
| 1136 | - <li> | |
| 1137 | - if link.current { | |
| 1138 | - <a class="current" aria-current="true" href=(link.href)>(link.name)</a> | |
| 1139 | - } else { | |
| 1140 | - <a href=(link.href)>(link.name)</a> | |
| 1148 | + <div class="ref-panel" role="tabpanel" data-ref-panel=(kind) hidden=(kind != "branches")> | |
| 1149 | + if empty { | |
| 1150 | + <p class="muted small ref-note">(g::t(lang, K::NothingHere))</p> | |
| 1151 | + } else { | |
| 1152 | + <ul class="ref-list" role="listbox"> | |
| 1153 | + for (n, link) in links.into_iter().enumerate() { | |
| 1154 | + <li role="option" id=(format!("ref-{kind}-{n}")) data-ref-item="" hidden=((n >= REF_SHOWN).then_some(""))> | |
| 1155 | + if link.current { | |
| 1156 | + <a class="current" aria-current="true" href=(link.href)>(link.name)</a> | |
| 1157 | + } else { | |
| 1158 | + <a href=(link.href)>(link.name)</a> | |
| 1159 | + } | |
| 1160 | + </li> | |
| 1141 | 1161 | } |
| 1142 | - </li> | |
| 1162 | + </ul> | |
| 1163 | + <p class="muted small ref-note" data-ref-empty="" hidden=(true)>(g::t(lang, K::NoMatches))</p> | |
| 1143 | 1164 | } |
| 1144 | - </ul> | |
| 1165 | + <a class="ref-all" href=(all_href)>(all_label)</a> | |
| 1166 | + </div> | |
| 1145 | 1167 | }) |
| 1146 | 1168 | } |
| 1147 | 1169 | |
| 1148 | -/// Branch and tag selector. A plain `<details>` list, so it works without JavaScript. | |
| 1170 | +/// Branch and tag switcher for the browse bar: a button showing the current ref that opens a | |
| 1171 | +/// popover with a filter, Branches and Tags tabs, and a link to each full list. The filter, tabs and | |
| 1172 | +/// arrow keys are wired in `assets/nav.js`; without it the popover still lists the first entries. | |
| 1149 | 1173 | #[component] |
| 1150 | 1174 | pub async fn ref_selector( |
| 1151 | 1175 | lang: Lang, |
| 1176 | + label: &'static str, | |
| 1152 | 1177 | current: String, |
| 1153 | 1178 | branches: Vec<RefLink>, |
| 1154 | 1179 | tags: Vec<RefLink>, |
| 1180 | + branches_href: String, | |
| 1181 | + tags_href: String, | |
| 1155 | 1182 | ) -> Result<impl View> { |
| 1156 | - let has_tags = !tags.is_empty(); | |
| 1157 | 1183 | Ok(view! { |
| 1158 | - <details class="ref-select"> | |
| 1184 | + <details class="ref-select" data-ref-switch=""> | |
| 1159 | 1185 | <summary> |
| 1160 | - <span class="muted small">(mi::t(lang, MK::RefLabel))</span> | |
| 1161 | - <code>(current)</code> | |
| 1186 | + <span class="muted small">(label)</span> | |
| 1187 | + <code>(current.as_str())</code> | |
| 1162 | 1188 | </summary> |
| 1163 | 1189 | <div class="ref-menu"> |
| 1164 | - ref_group(title: g::t(lang, K::BranchesTitle), links: branches) | |
| 1165 | - if has_tags { | |
| 1166 | - ref_group(title: g::t(lang, K::TagsTitle), links: tags) | |
| 1167 | - } | |
| 1190 | + <div class="ref-top"> | |
| 1191 | + <input type="text" class="ref-filter" data-ref-filter="" autocomplete="off" spellcheck="false" | |
| 1192 | + placeholder=(g::t(lang, K::FilterRefs)) aria-label=(g::t(lang, K::FilterRefs)) | |
| 1193 | + role="combobox" aria-expanded="true" aria-autocomplete="list"> | |
| 1194 | + <div class="ref-tabs" role="tablist"> | |
| 1195 | + <button type="button" role="tab" aria-selected="true" data-ref-tab="branches">(g::t(lang, K::BranchesTitle))</button> | |
| 1196 | + <button type="button" role="tab" aria-selected="false" data-ref-tab="tags">(g::t(lang, K::TagsTitle))</button> | |
| 1197 | + </div> | |
| 1198 | + </div> | |
| 1199 | + ref_panel(lang: lang, kind: "branches", links: branches, all_href: branches_href, all_label: g::t(lang, K::ViewAllBranches)) | |
| 1200 | + ref_panel(lang: lang, kind: "tags", links: tags, all_href: tags_href, all_label: g::t(lang, K::ViewAllTags)) | |
| 1168 | 1201 | </div> |
| 1169 | 1202 | </details> |
| 1170 | 1203 | }) |
style/main.scssmodified+113 -11
| @@ -815,6 +815,12 @@ code { | ||
| 815 | 815 | padding: 6px 0; |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | +.branch-list a { | |
| 819 | + font-family: var(--mono); | |
| 820 | + font-size: 13.5px; | |
| 821 | + word-break: break-all; | |
| 822 | +} | |
| 823 | + | |
| 818 | 824 | // Tables |
| 819 | 825 | |
| 820 | 826 | .table-wrap { |
| @@ -1095,28 +1101,93 @@ code { | ||
| 1095 | 1101 | } |
| 1096 | 1102 | } |
| 1097 | 1103 | |
| 1104 | +// Branch switcher popover: filter and tabs on top, the entries below, scrolling inside. | |
| 1098 | 1105 | .ref-menu { |
| 1099 | 1106 | position: absolute; |
| 1100 | 1107 | left: 0; |
| 1101 | 1108 | top: calc(100% + 6px); |
| 1102 | 1109 | z-index: 10; |
| 1103 | - min-width: 240px; | |
| 1110 | + width: 300px; | |
| 1111 | + max-width: calc(100vw - 32px); | |
| 1104 | 1112 | max-height: 60vh; |
| 1105 | - overflow-y: auto; | |
| 1106 | - padding: 8px 0; | |
| 1113 | + display: flex; | |
| 1114 | + flex-direction: column; | |
| 1107 | 1115 | background: var(--surface); |
| 1108 | 1116 | border: 1px solid var(--border); |
| 1109 | 1117 | border-radius: var(--radius-lg); |
| 1110 | 1118 | box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); |
| 1111 | 1119 | } |
| 1112 | 1120 | |
| 1113 | -.ref-heading { | |
| 1114 | - margin: 6px 14px 4px; | |
| 1115 | - font-size: 0.75rem; | |
| 1116 | - font-weight: 600; | |
| 1117 | - color: var(--muted); | |
| 1118 | - text-transform: uppercase; | |
| 1119 | - letter-spacing: 0.04em; | |
| 1121 | +.ref-top { | |
| 1122 | + padding: 8px; | |
| 1123 | + border-bottom: 1px solid var(--border); | |
| 1124 | +} | |
| 1125 | + | |
| 1126 | +.ref-filter { | |
| 1127 | + width: 100%; | |
| 1128 | + height: var(--control-h); | |
| 1129 | + box-sizing: border-box; | |
| 1130 | + padding: 0 10px; | |
| 1131 | + font: inherit; | |
| 1132 | + font-size: 14px; | |
| 1133 | + color: var(--text); | |
| 1134 | + background: var(--surface-2); | |
| 1135 | + border: 1px solid var(--border); | |
| 1136 | + border-radius: var(--radius-md); | |
| 1137 | + | |
| 1138 | + &:focus-visible { | |
| 1139 | + outline: 2px solid var(--focus); | |
| 1140 | + outline-offset: 1px; | |
| 1141 | + } | |
| 1142 | +} | |
| 1143 | + | |
| 1144 | +.ref-tabs { | |
| 1145 | + display: flex; | |
| 1146 | + gap: 4px; | |
| 1147 | + margin-top: 8px; | |
| 1148 | + | |
| 1149 | + button { | |
| 1150 | + flex: 1 1 0; | |
| 1151 | + min-height: 32px; | |
| 1152 | + padding: 0 10px; | |
| 1153 | + font: inherit; | |
| 1154 | + font-size: 13px; | |
| 1155 | + color: var(--muted); | |
| 1156 | + background: none; | |
| 1157 | + border: 0; | |
| 1158 | + border-radius: var(--radius-md); | |
| 1159 | + cursor: pointer; | |
| 1160 | + | |
| 1161 | + &[aria-selected="true"] { | |
| 1162 | + color: var(--text); | |
| 1163 | + background: var(--accent-soft); | |
| 1164 | + font-weight: 600; | |
| 1165 | + } | |
| 1166 | + | |
| 1167 | + &:focus-visible { | |
| 1168 | + outline: 2px solid var(--focus); | |
| 1169 | + outline-offset: 1px; | |
| 1170 | + } | |
| 1171 | + } | |
| 1172 | +} | |
| 1173 | + | |
| 1174 | +.ref-panel { | |
| 1175 | + min-height: 0; | |
| 1176 | + overflow-y: auto; | |
| 1177 | + padding: 4px 0; | |
| 1178 | +} | |
| 1179 | + | |
| 1180 | +.ref-note { | |
| 1181 | + margin: 8px 14px; | |
| 1182 | +} | |
| 1183 | + | |
| 1184 | +.ref-all { | |
| 1185 | + display: block; | |
| 1186 | + margin-top: 4px; | |
| 1187 | + padding: 8px 14px; | |
| 1188 | + font-size: 13px; | |
| 1189 | + color: var(--text-2); | |
| 1190 | + border-top: 1px solid var(--border); | |
| 1120 | 1191 | } |
| 1121 | 1192 | |
| 1122 | 1193 | .ref-list { |
| @@ -1124,6 +1195,11 @@ code { | ||
| 1124 | 1195 | margin: 0; |
| 1125 | 1196 | padding: 0; |
| 1126 | 1197 | |
| 1198 | + li[aria-selected="true"] a, | |
| 1199 | + a:hover { | |
| 1200 | + background: var(--accent-soft); | |
| 1201 | + } | |
| 1202 | + | |
| 1127 | 1203 | a { |
| 1128 | 1204 | display: block; |
| 1129 | 1205 | padding: 6px 14px; |
| @@ -1855,8 +1931,34 @@ code { | ||
| 1855 | 1931 | margin-left: 0; |
| 1856 | 1932 | } |
| 1857 | 1933 | |
| 1934 | + // The branch switcher opens as a full-width sheet from the bottom, with larger tap targets. | |
| 1858 | 1935 | .ref-menu { |
| 1859 | - max-width: calc(100vw - 32px); | |
| 1936 | + position: fixed; | |
| 1937 | + top: auto; | |
| 1938 | + left: 0; | |
| 1939 | + right: 0; | |
| 1940 | + bottom: 0; | |
| 1941 | + width: auto; | |
| 1942 | + max-width: none; | |
| 1943 | + max-height: 75vh; | |
| 1944 | + border-radius: var(--radius-lg) var(--radius-lg) 0 0; | |
| 1945 | + } | |
| 1946 | + | |
| 1947 | + .ref-filter { | |
| 1948 | + height: 44px; | |
| 1949 | + font-size: 16px; | |
| 1950 | + } | |
| 1951 | + | |
| 1952 | + .ref-tabs button { | |
| 1953 | + min-height: 44px; | |
| 1954 | + } | |
| 1955 | + | |
| 1956 | + .ref-list a { | |
| 1957 | + padding: 12px 16px; | |
| 1958 | + } | |
| 1959 | + | |
| 1960 | + .ref-all { | |
| 1961 | + padding: 14px 16px; | |
| 1860 | 1962 | } |
| 1861 | 1963 | } |
| 1862 | 1964 |