项目文件夹

文件
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

113 行
3.3 KiB
Svelte

<svelte:options accessors={true} />
<script context="module" lang="ts">
export { default as BaseTextbox } from "./shared/Textbox.svelte";
export { default as BaseExample } from "./Example.svelte";
</script>
<script lang="ts">
import { tick } from "svelte";
import TextBox from "./shared/Textbox.svelte";
import StatusTracker from "@gradio/statustracker";
import { Block } from "@gradio/atoms";
import { Gradio } from "@gradio/utils";
import type { TextboxProps, TextboxEvents } from "./types";
let _props = $props();
const gradio = new Gradio<TextboxEvents, TextboxProps>(_props);
let label = $derived(gradio.shared.label || "Textbox");
// Need to set the value to "" otherwise a change event gets
// dispatched when the child sets it to ""
gradio.props.value = gradio.props.value ?? "";
let old_value = $state(gradio.props.value);
async function dispatch_change() {
if (old_value !== gradio.props.value) {
old_value = gradio.props.value;
await tick();
gradio.dispatch("change", $state.snapshot(gradio.props.value));
}
}
async function handle_input(value: string): Promise<void> {
if (!gradio.shared || !gradio.props) return;
gradio.props.validation_error = null;
gradio.props.value = value;
await tick();
gradio.dispatch("input");
}
$effect(() => {
dispatch_change();
});
function handle_change(value: string): void {
if (!gradio.shared || !gradio.props) return;
gradio.props.validation_error = null;
gradio.props.value = value;
}
</script>
<Block
visible={gradio.shared.visible}
elem_id={gradio.shared.elem_id}
elem_classes={gradio.shared.elem_classes}
scale={gradio.shared.scale}
min_width={gradio.shared.min_width}
allow_overflow={false}
padding={gradio.shared.container}
rtl={gradio.props.rtl}
>
{#if gradio.shared.loading_status}
<StatusTracker
autoscroll={gradio.shared.autoscroll}
i18n={gradio.i18n}
{...gradio.shared.loading_status}
show_validation_error={false}
on_clear_status={() =>
gradio.dispatch("clear_status", gradio.shared.loading_status)}
/>
{/if}
<TextBox
bind:value={gradio.props.value}
{label}
info={gradio.props.info}
show_label={gradio.shared.show_label}
lines={gradio.props.lines}
type={gradio.props.type}
rtl={gradio.props.rtl}
text_align={gradio.props.text_align}
max_lines={gradio.props.max_lines}
placeholder={gradio.props.placeholder}
submit_btn={gradio.props.submit_btn}
stop_btn={gradio.props.stop_btn}
buttons={gradio.props.buttons}
autofocus={gradio.props.autofocus}
container={gradio.shared.container}
autoscroll={gradio.shared.autoscroll}
max_length={gradio.props.max_length}
html_attributes={gradio.props.html_attributes}
validation_error={gradio.shared?.loading_status?.validation_error ||
gradio.shared?.validation_error}
onchange={handle_change}
oninput={handle_input}
onsubmit={() => {
gradio.shared.validation_error = null;
gradio.dispatch("submit");
}}
onblur={() => gradio.dispatch("blur")}
onselect={(data) => gradio.dispatch("select", data)}
onfocus={() => gradio.dispatch("focus")}
onstop={() => gradio.dispatch("stop")}
oncopy={(data) => gradio.dispatch("copy", data)}
oncustombuttonclick={(id) => {
gradio.dispatch("custom_button_click", { id });
}}
disabled={!gradio.shared.interactive}
/>
</Block>
<!-- bind:value_is_output={gradio.props.value_is_output} -->