Spaces:
Runtime error
Runtime error
Use arrow keys to select models
Browse files12345673 unmodified lines111213141516171819202122232418 unmodified lines434445464748491 unmodified line515253545556577 unmodified lines6566676869707172737413 unmodified lines88899091929394959697<script lang="ts">import type { ModelEntryWithTokenizer } from "./types";import { createEventDispatcher } from "svelte";import { FEATUED_MODELS_IDS } from "./inferencePlaygroundUtils";import IconSearch from "../Icons/IconSearch.svelte";3 unmodified lineslet backdropEl: HTMLDivElement;let query = "";const dispatch = createEventDispatcher<{ modelSelected: string; close: void }>();function handleKeydown(event: KeyboardEvent) {const { key } = event;if (key === "Escape") {event.preventDefault();dispatch("close");}}18 unmodified lines);</script><svelte:window on:keydown={handleKeydown} /><divclass="fixed inset-0 z-10 flex h-screen items-start justify-center bg-black/85 pt-32"1 unmodified lineon:click|stopPropagation={handleBackdropClick}><div class="flex w-full max-w-[600px] items-start justify-center p-10 whitespace-nowrap overflow-hidden"><div class="flex h-full w-full flex-col overflow-hidden rounded-lg border bg-white text-gray-900 shadow-md"><div class="flex items-center border-b px-3"><IconSearch classNames="mr-2 text-sm" /><input7 unmodified lines<div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Trending</div><div>{#each featuredModels as model}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex w-full cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"on:click={() => {dispatch("modelSelected", model.id);dispatch("close");13 unmodified lines<div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Other Models</div><div>{#each otherModels as model}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex w-full cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"on:click={() => {dispatch("modelSelected", model.id);dispatch("close");12345673 unmodified lines11121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606118 unmodified lines808182838485861 unmodified line888990919293947 unmodified lines10210310410510610710810911011111211311413 unmodified lines128129130131132133134135136137138139140141<script lang="ts">import type { ModelEntryWithTokenizer } from "./types";import { createEventDispatcher, tick } from "svelte";import { FEATUED_MODELS_IDS } from "./inferencePlaygroundUtils";import IconSearch from "../Icons/IconSearch.svelte";3 unmodified lineslet backdropEl: HTMLDivElement;let query = "";let highlightIdx = 0;let ignoreCursorHighlight = false;let containerEl: HTMLDivElement;const dispatch = createEventDispatcher<{ modelSelected: string; close: void }>();function handleKeydown(event: KeyboardEvent) {const { key } = event;let scrollLogicalPosition: ScrollLogicalPosition = "end";if (key === "Escape") {event.preventDefault();dispatch("close");} else if (key === "Enter") {const searchEls = (containerEl.firstChild?.childNodes ?? []) as HTMLAnchorElement[];searchEls?.[highlightIdx].click();} else if (key === "ArrowUp") {event.preventDefault();highlightIdx--;scrollLogicalPosition = "start";ignoreCursorHighlight = true;} else if (key === "ArrowDown") {event.preventDefault();highlightIdx++;ignoreCursorHighlight = true;}const n = models.length;highlightIdx = ((highlightIdx % n) + n) % n;scrollToResult(scrollLogicalPosition);}async function scrollToResult(block: ScrollLogicalPosition) {await tick();const highlightedEl = document.querySelector(".highlighted");if (containerEl && highlightedEl) {const { bottom: containerBottom, top: containerTop } = containerEl.getBoundingClientRect();const { bottom: highlightedBottom, top: highlightedTop } = highlightedEl.getBoundingClientRect();if (highlightedBottom > containerBottom || containerTop > highlightedTop) {highlightedEl.scrollIntoView({ block });}}}function highlightRow(idx: number) {if (!ignoreCursorHighlight) {highlightIdx = idx;}}18 unmodified lines);</script><svelte:window on:keydown={handleKeydown} on:mousemove={() => (ignoreCursorHighlight = false)} /><divclass="fixed inset-0 z-10 flex h-screen items-start justify-center bg-black/85 pt-32"1 unmodified lineon:click|stopPropagation={handleBackdropClick}><div class="flex w-full max-w-[600px] items-start justify-center p-10 whitespace-nowrap overflow-hidden"><div class="flex h-full w-full flex-col overflow-hidden rounded-lg border bg-white text-gray-900 shadow-md" bind:this={containerEl}><div class="flex items-center border-b px-3"><IconSearch classNames="mr-2 text-sm" /><input7 unmodified lines<div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Trending</div><div>{#each featuredModels as model, idx}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex w-full cursor-pointer items-center px-2 py-1.5 text-sm {highlightIdx === idx? 'highlighted bg-gray-100': ''}"on:mouseenter={() => highlightRow(idx)}on:click={() => {dispatch("modelSelected", model.id);dispatch("close");13 unmodified lines<div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Other Models</div><div>{#each otherModels as model, _idx}{@const [nameSpace, modelName] = model.id.split("/")}{@const idx = featuredModels.length + _idx}<buttonclass="flex w-full cursor-pointer items-center px-2 py-1.5 text-sm {highlightIdx === idx? 'highlighted bg-gray-100': ''}"on:mouseenter={() => highlightRow(idx)}on:click={() => {dispatch("modelSelected", model.id);dispatch("close");
src/lib/components/InferencePlayground/InferencePlaygroundModelSelectorModal.svelte+51-7