From 16377c30cb21cbace35be261335ed7c2354d2797 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 1 Nov 2024 17:40:34 +0100 Subject: [PATCH 1/6] feat: render package search filters --- .../components/RuntimeCompatIndicator.tsx | 2 +- frontend/islands/GlobalSearch.tsx | 135 ++++++++++++++---- frontend/static/styles.css | 4 + 3 files changed, 110 insertions(+), 31 deletions(-) diff --git a/frontend/components/RuntimeCompatIndicator.tsx b/frontend/components/RuntimeCompatIndicator.tsx index 71ba035a..06fec054 100644 --- a/frontend/components/RuntimeCompatIndicator.tsx +++ b/frontend/components/RuntimeCompatIndicator.tsx @@ -17,7 +17,7 @@ export const RUNTIME_COMPAT_KEYS: [ ["node", "Node.js", "/logos/node.svg", 256, 292], ["workerd", "Cloudflare Workers", "/logos/cloudflare-workers.svg", 416, 375], ["bun", "Bun", "/logos/bun.svg", 435, 435], -]; +] as const; export function RuntimeCompatIndicator( { runtimeCompat, hideUnknown, compact }: { diff --git a/frontend/islands/GlobalSearch.tsx b/frontend/islands/GlobalSearch.tsx index 4ca63792..74df27cd 100644 --- a/frontend/islands/GlobalSearch.tsx +++ b/frontend/islands/GlobalSearch.tsx @@ -7,7 +7,7 @@ import { Highlight } from "@orama/highlight"; import { IS_BROWSER } from "$fresh/runtime.ts"; import type { OramaPackageHit, SearchKind } from "../util.ts"; import { api, path } from "../utils/api.ts"; -import { List, Package } from "../utils/api_types.ts"; +import type { List, Package, RuntimeCompat } from "../utils/api_types.ts"; import { PackageHit } from "../components/PackageHit.tsx"; import { useMacLike } from "../utils/os.ts"; import type { ListDisplayItem } from "../components/List.tsx"; @@ -170,6 +170,16 @@ export function GlobalSearch( }; function onKeyUp(e: KeyboardEvent) { + if ( + e.key === "ArrowRight" && + (e.currentTarget! as HTMLInputElement).selectionStart === + search.value.length && + tokenizeFilter(search.value).at(-1)?.kind !== "text" + ) { + search.value += " "; + return; + } + if (suggestions.value === null) return; if (e.key === "ArrowDown") { selectionIdx.value = Math.min( @@ -230,22 +240,38 @@ export function GlobalSearch( - isFocused.value = true} - autoComplete="off" - aria-expanded={showSuggestions} - aria-autocomplete="list" - aria-controls="package-search-results" - role="combobox" - id="global-search-input" - /> +
+ isFocused.value = true} + autoComplete="off" + aria-expanded={showSuggestions} + aria-autocomplete="list" + aria-controls="package-search-results" + role="combobox" + id="global-search-input" + /> + {kind === "packages" && ( +
+ {tokenizeFilter(search.value).map((token, i, arr) => ( + + + {token.raw} + + {((arr.length - 1) !== i) && " "} + + ))} +
+ )} +