[Fix] Autoresize message boxes on browsers other than Chrome (#47)
Browse files
src/lib/components/InferencePlayground/InferencePlaygroundConversation.svelte
CHANGED
@@ -19,6 +19,19 @@
|
|
19 |
|
20 |
let messageContainer: HTMLDivElement | null = null;
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
function scrollToBottom() {
|
23 |
if (messageContainer) {
|
24 |
messageContainer.scrollTop = messageContainer.scrollHeight;
|
@@ -27,6 +40,7 @@
|
|
27 |
|
28 |
$: {
|
29 |
if (conversation.messages.at(-1)) {
|
|
|
30 |
scrollToBottom();
|
31 |
}
|
32 |
}
|
@@ -43,6 +57,7 @@
|
|
43 |
<Message
|
44 |
class="border-b"
|
45 |
{message}
|
|
|
46 |
on:delete={() => dispatch("deleteMessage", messageIdx)}
|
47 |
autofocus={!loading && messageIdx === conversation.messages.length - 1}
|
48 |
/>
|
|
|
19 |
|
20 |
let messageContainer: HTMLDivElement | null = null;
|
21 |
|
22 |
+
function resizeMessageTextAreas() {
|
23 |
+
// ideally we would use CSS "field-sizing:content". However, it is currently only supported on Chrome.
|
24 |
+
if (messageContainer) {
|
25 |
+
const containerScrollTop = messageContainer.scrollTop;
|
26 |
+
const textareaEls = messageContainer.querySelectorAll("textarea");
|
27 |
+
for (const textarea of textareaEls) {
|
28 |
+
textarea.style.height = "0px";
|
29 |
+
textarea.style.height = textarea.scrollHeight + "px";
|
30 |
+
}
|
31 |
+
messageContainer.scrollTop = containerScrollTop;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
function scrollToBottom() {
|
36 |
if (messageContainer) {
|
37 |
messageContainer.scrollTop = messageContainer.scrollHeight;
|
|
|
40 |
|
41 |
$: {
|
42 |
if (conversation.messages.at(-1)) {
|
43 |
+
resizeMessageTextAreas();
|
44 |
scrollToBottom();
|
45 |
}
|
46 |
}
|
|
|
57 |
<Message
|
58 |
class="border-b"
|
59 |
{message}
|
60 |
+
on:input={resizeMessageTextAreas}
|
61 |
on:delete={() => dispatch("deleteMessage", messageIdx)}
|
62 |
autofocus={!loading && messageIdx === conversation.messages.length - 1}
|
63 |
/>
|
src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
export let message: ChatCompletionInputMessage;
|
6 |
export let autofocus: boolean = false;
|
7 |
|
8 |
-
const dispatch = createEventDispatcher<{ delete: void }>();
|
9 |
</script>
|
10 |
|
11 |
<div
|
@@ -18,8 +18,11 @@
|
|
18 |
{autofocus}
|
19 |
bind:value={message.content}
|
20 |
placeholder="Enter {message.role} message"
|
21 |
-
class="resize-none rounded bg-transparent px-2 py-2.5 ring-gray-100
|
22 |
rows="1"
|
|
|
|
|
|
|
23 |
></textarea>
|
24 |
<button
|
25 |
tabindex="1"
|
|
|
5 |
export let message: ChatCompletionInputMessage;
|
6 |
export let autofocus: boolean = false;
|
7 |
|
8 |
+
const dispatch = createEventDispatcher<{ delete: void; input: void }>();
|
9 |
</script>
|
10 |
|
11 |
<div
|
|
|
18 |
{autofocus}
|
19 |
bind:value={message.content}
|
20 |
placeholder="Enter {message.role} message"
|
21 |
+
class="resize-none rounded bg-transparent px-2 py-2.5 ring-gray-100 hover:resize-y hover:bg-white focus:resize-y focus:bg-white focus:ring group-hover/message:ring @2xl:px-3 dark:ring-gray-600 dark:hover:bg-gray-900 dark:focus:bg-gray-900"
|
22 |
rows="1"
|
23 |
+
on:input={() => {
|
24 |
+
dispatch("input");
|
25 |
+
}}
|
26 |
></textarea>
|
27 |
<button
|
28 |
tabindex="1"
|