|
1 | 1 | <script lang="ts"> |
2 | 2 | import { is_component_message, is_last_bot_message } from "../shared/utils"; |
3 | | - import { File } from "@gradio/icons"; |
| 3 | +
|
4 | 4 | import { Image } from "@gradio/image/shared"; |
5 | | - import Component from "./Component.svelte"; |
6 | 5 | import type { FileData, Client } from "@gradio/client"; |
7 | 6 | import type { NormalisedMessage } from "../types"; |
8 | | - import MessageBox from "./MessageBox.svelte"; |
9 | | - import { MarkdownCode as Markdown } from "@gradio/markdown-code"; |
| 7 | +
|
10 | 8 | import type { I18nFormatter } from "js/core/src/gradio_helper"; |
11 | 9 | import type { ComponentType, SvelteComponent } from "svelte"; |
12 | 10 | import ButtonPanel from "./ButtonPanel.svelte"; |
| 11 | + import MessageContent from "./MessageContent.svelte"; |
| 12 | + import MessageBox from "./MessageBox.svelte"; |
13 | 13 |
|
14 | 14 | export let value: NormalisedMessage[]; |
15 | 15 | export let avatar_img: FileData | null; |
|
148 | 148 | dir={rtl ? "rtl" : "ltr"} |
149 | 149 | aria-label={role + "'s message: " + get_message_label_data(message)} |
150 | 150 | > |
151 | | - {#if message.type === "text"} |
152 | | - <div class="message-content"> |
153 | | - {#if message?.metadata?.title} |
154 | | - <MessageBox |
155 | | - title={message.metadata.title} |
156 | | - expanded={is_last_bot_message([message], value)} |
157 | | - > |
158 | | - <Markdown |
159 | | - message={message.content} |
160 | | - {latex_delimiters} |
161 | | - {sanitize_html} |
162 | | - {render_markdown} |
163 | | - {line_breaks} |
164 | | - on:load={scroll} |
165 | | - {root} |
166 | | - /> |
167 | | - </MessageBox> |
168 | | - {:else} |
169 | | - <Markdown |
170 | | - message={message.content} |
171 | | - {latex_delimiters} |
172 | | - {sanitize_html} |
173 | | - {render_markdown} |
174 | | - {line_breaks} |
175 | | - on:load={scroll} |
176 | | - {root} |
177 | | - /> |
178 | | - {/if} |
179 | | - </div> |
180 | | - {:else if message.type === "component" && message.content.component in _components} |
181 | | - <Component |
| 151 | + {#if message?.metadata?.title} |
| 152 | + <MessageBox |
| 153 | + title={message.metadata.title} |
| 154 | + expanded={is_last_bot_message([message], value)} |
| 155 | + {rtl} |
| 156 | + > |
| 157 | + <MessageContent |
| 158 | + {message} |
| 159 | + {sanitize_html} |
| 160 | + {latex_delimiters} |
| 161 | + {render_markdown} |
| 162 | + {_components} |
| 163 | + {upload} |
| 164 | + {thought_index} |
| 165 | + {target} |
| 166 | + {root} |
| 167 | + {theme_mode} |
| 168 | + {_fetch} |
| 169 | + {scroll} |
| 170 | + {allow_file_downloads} |
| 171 | + {display_consecutive_in_same_bubble} |
| 172 | + {i18n} |
| 173 | + {line_breaks} |
| 174 | + /> |
| 175 | + </MessageBox> |
| 176 | + {:else} |
| 177 | + <MessageContent |
| 178 | + {message} |
| 179 | + {sanitize_html} |
| 180 | + {latex_delimiters} |
| 181 | + {render_markdown} |
| 182 | + {_components} |
| 183 | + {upload} |
| 184 | + {thought_index} |
182 | 185 | {target} |
| 186 | + {root} |
183 | 187 | {theme_mode} |
184 | | - props={message.content.props} |
185 | | - type={message.content.component} |
186 | | - components={_components} |
187 | | - value={message.content.value} |
188 | | - display_icon_button_wrapper_top_corner={thought_index > 0 && |
189 | | - display_consecutive_in_same_bubble} |
190 | | - {i18n} |
191 | | - {upload} |
192 | 188 | {_fetch} |
193 | | - on:load={() => scroll()} |
| 189 | + {scroll} |
194 | 190 | {allow_file_downloads} |
| 191 | + {display_consecutive_in_same_bubble} |
| 192 | + {i18n} |
| 193 | + {line_breaks} |
195 | 194 | /> |
196 | | - {:else if message.type === "component" && message.content.component === "file"} |
197 | | - <div class="file-container"> |
198 | | - <div class="file-icon"> |
199 | | - <File /> |
200 | | - </div> |
201 | | - <div class="file-info"> |
202 | | - <a |
203 | | - data-testid="chatbot-file" |
204 | | - class="file-link" |
205 | | - href={message.content.value.url} |
206 | | - target="_blank" |
207 | | - download={window.__is_colab__ |
208 | | - ? null |
209 | | - : message.content.value?.orig_name || |
210 | | - message.content.value?.path.split("/").pop() || |
211 | | - "file"} |
212 | | - > |
213 | | - <span class="file-name" |
214 | | - >{message.content.value?.orig_name || |
215 | | - message.content.value?.path.split("/").pop() || |
216 | | - "file"}</span |
217 | | - > |
218 | | - </a> |
219 | | - <span class="file-type" |
220 | | - >{( |
221 | | - message.content.value?.orig_name || |
222 | | - message.content.value?.path || |
223 | | - "" |
224 | | - ) |
225 | | - .split(".") |
226 | | - .pop() |
227 | | - .toUpperCase()}</span |
228 | | - > |
229 | | - </div> |
230 | | - </div> |
231 | 195 | {/if} |
232 | 196 | </button> |
233 | 197 | </div> |
|
447 | 411 | } |
448 | 412 | } |
449 | 413 |
|
450 | | - .message-content { |
451 | | - padding: var(--spacing-sm) var(--spacing-xl); |
452 | | - } |
453 | | -
|
454 | 414 | .avatar-container { |
455 | 415 | align-self: flex-start; |
456 | 416 | position: relative; |
|
594 | 554 | .panel .message { |
595 | 555 | margin-bottom: var(--spacing-md); |
596 | 556 | } |
597 | | -
|
598 | | - .file-container { |
599 | | - display: flex; |
600 | | - align-items: center; |
601 | | - gap: var(--spacing-lg); |
602 | | - padding: var(--spacing-lg); |
603 | | - border-radius: var(--radius-lg); |
604 | | - width: fit-content; |
605 | | - margin: var(--spacing-sm) 0; |
606 | | - } |
607 | | -
|
608 | | - .file-icon { |
609 | | - display: flex; |
610 | | - align-items: center; |
611 | | - justify-content: center; |
612 | | - color: var(--body-text-color); |
613 | | - } |
614 | | -
|
615 | | - .file-icon :global(svg) { |
616 | | - width: var(--size-7); |
617 | | - height: var(--size-7); |
618 | | - } |
619 | | -
|
620 | | - .file-info { |
621 | | - display: flex; |
622 | | - flex-direction: column; |
623 | | - } |
624 | | -
|
625 | | - .file-link { |
626 | | - text-decoration: none; |
627 | | - color: var(--body-text-color); |
628 | | - display: flex; |
629 | | - flex-direction: column; |
630 | | - gap: var(--spacing-xs); |
631 | | - } |
632 | | -
|
633 | | - .file-name { |
634 | | - font-family: var(--font); |
635 | | - font-size: var(--text-md); |
636 | | - font-weight: 500; |
637 | | - } |
638 | | -
|
639 | | - .file-type { |
640 | | - font-family: var(--font); |
641 | | - font-size: var(--text-sm); |
642 | | - color: var(--body-text-color-subdued); |
643 | | - text-transform: uppercase; |
644 | | - } |
645 | 557 | </style> |
0 commit comments