Files
wehub-resource-sync adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:17:32 +08:00

104 lines
2.2 KiB
Svelte

<script lang="ts">
import type { HighlightedToken, ColorPair } from "./utils";
import { get_score_color } from "./utils";
let {
value = $bindable([]),
label_to_edit = $bindable(-1),
category,
active_legend,
color_map,
label_index,
token,
onchange,
is_scores_mode = false
}: {
value: HighlightedToken[];
label_to_edit: number;
category: string | number | null;
active_legend: string;
color_map: Record<string, ColorPair>;
label_index: number;
token: string;
onchange: () => void;
is_scores_mode?: boolean;
} = $props();
let input_value = $state(category?.toString() ?? "");
function get_background_color(): string {
if (is_scores_mode) {
const score =
typeof category === "number" ? category : parseFloat(category ?? "0");
return get_score_color(score);
}
if (category === null || (active_legend && active_legend !== category)) {
return "";
}
return color_map[category]?.primary ?? "";
}
function update_value(e: Event): void {
const target = e.target as HTMLInputElement;
const new_value = target.value.trim();
value = [
...value.slice(0, label_index),
{
token,
class_or_confidence:
new_value === ""
? null
: is_scores_mode
? Number(new_value)
: new_value
},
...value.slice(label_index + 1)
];
onchange();
}
function handle_keydown(e: KeyboardEvent): void {
if (e.key === "Enter") {
update_value(e);
label_to_edit = -1;
}
}
</script>
<input
class="label-input"
autofocus
type={is_scores_mode ? "number" : "text"}
step={is_scores_mode ? "0.1" : undefined}
placeholder={is_scores_mode ? undefined : "label"}
value={category}
style:background-color={get_background_color()}
style:width={is_scores_mode ? "7ch" : `${(input_value?.length || 4) + 4}ch`}
oninput={(e) => {
input_value = (e.target as HTMLInputElement).value;
}}
onblur={update_value}
onkeydown={handle_keydown}
/>
<style>
.label-input {
margin-top: 1px;
margin-left: 4px;
border: none;
border-radius: var(--radius-xs);
padding: 1px 5px;
color: var(--color-white);
font-weight: var(--weight-bold);
font-size: var(--text-sm);
text-transform: uppercase;
line-height: 1;
}
.label-input::placeholder {
color: rgba(255, 255, 255, 0.5);
}
</style>