mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-27 02:30:17 +08:00
15da39fca0
* first pass * multimodal textbox * add changeset * remove file * more changes * changes * add changeset * revert demo * doc strings fix * update demo * file icons * more updates * format * add story * remove doc line * type fixes * chat interface * new demo * image upload fix * ui changes * addressing PR comments * format * type check * more pr fixes * format * format * test fixes * test fixes * Streaming fixes + other stuff * optional keys to dict value * final fixes * notebook * format * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * merge * backend fixes * story fix * ui test fix * format * story * format * demo fix * streaming test fix * stories fix * stories fix --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { tick } from "svelte";
|
|
|
|
interface Value {
|
|
lines: number;
|
|
max_lines: number;
|
|
text: string;
|
|
}
|
|
|
|
export async function resize(
|
|
target: HTMLTextAreaElement | HTMLInputElement,
|
|
lines: number,
|
|
max_lines: number
|
|
): Promise<void> {
|
|
await tick();
|
|
if (lines === max_lines) return;
|
|
|
|
let max =
|
|
max_lines === undefined
|
|
? false
|
|
: max_lines === undefined // default
|
|
? 21 * 11
|
|
: 21 * (max_lines + 1);
|
|
let min = 21 * (lines + 1);
|
|
|
|
target.style.height = "1px";
|
|
|
|
let scroll_height;
|
|
if (max && target.scrollHeight > max) {
|
|
scroll_height = max;
|
|
} else if (target.scrollHeight < min) {
|
|
scroll_height = min;
|
|
} else {
|
|
scroll_height = target.scrollHeight;
|
|
}
|
|
|
|
target.style.height = `${scroll_height}px`;
|
|
}
|
|
|
|
export function text_area_resize(
|
|
_el: HTMLTextAreaElement,
|
|
_value: Value
|
|
): any | undefined {
|
|
if (_value.lines === _value.max_lines) return;
|
|
_el.style.overflowY = "scroll";
|
|
_el.addEventListener("input", (event: Event) =>
|
|
resize(event.target as HTMLTextAreaElement, _value.lines, _value.max_lines)
|
|
);
|
|
|
|
if (!_value.text.trim()) return;
|
|
resize(_el, _value.lines, _value.max_lines);
|
|
|
|
return {
|
|
destroy: () =>
|
|
_el.removeEventListener("input", (e: Event) =>
|
|
resize(e.target as HTMLTextAreaElement, _value.lines, _value.max_lines)
|
|
)
|
|
};
|
|
}
|