mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-17 14:55:23 +00:00
refac
This commit is contained in:
parent
18adb28da0
commit
5e4e1cf662
4 changed files with 48 additions and 12 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
import Source from './Source.svelte';
|
import Source from './Source.svelte';
|
||||||
import HtmlToken from './HTMLToken.svelte';
|
import HtmlToken from './HTMLToken.svelte';
|
||||||
import TextToken from './MarkdownInlineTokens/TextToken.svelte';
|
import TextToken from './MarkdownInlineTokens/TextToken.svelte';
|
||||||
|
import CodespanToken from './MarkdownInlineTokens/CodespanToken.svelte';
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
export let done = true;
|
export let done = true;
|
||||||
|
|
@ -30,7 +31,7 @@
|
||||||
{:else if token.type === 'link'}
|
{:else if token.type === 'link'}
|
||||||
{#if token.tokens}
|
{#if token.tokens}
|
||||||
<a href={token.href} target="_blank" rel="nofollow" title={token.title}>
|
<a href={token.href} target="_blank" rel="nofollow" title={token.title}>
|
||||||
<svelte:self id={`${id}-a`} tokens={token.tokens} {onSourceClick} />
|
<svelte:self id={`${id}-a`} tokens={token.tokens} {onSourceClick} {done} />
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<a href={token.href} target="_blank" rel="nofollow" title={token.title}>{token.text}</a>
|
<a href={token.href} target="_blank" rel="nofollow" title={token.title}>{token.text}</a>
|
||||||
|
|
@ -42,15 +43,7 @@
|
||||||
{:else if token.type === 'em'}
|
{:else if token.type === 'em'}
|
||||||
<em><svelte:self id={`${id}-em`} tokens={token.tokens} {onSourceClick} /></em>
|
<em><svelte:self id={`${id}-em`} tokens={token.tokens} {onSourceClick} /></em>
|
||||||
{:else if token.type === 'codespan'}
|
{:else if token.type === 'codespan'}
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<CodespanToken {token} {done} />
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
||||||
<code
|
|
||||||
class="codespan cursor-pointer"
|
|
||||||
on:click={() => {
|
|
||||||
copyToClipboard(unescapeHtml(token.text));
|
|
||||||
toast.success($i18n.t('Copied to clipboard'));
|
|
||||||
}}>{unescapeHtml(token.text)}</code
|
|
||||||
>
|
|
||||||
{:else if token.type === 'br'}
|
{:else if token.type === 'br'}
|
||||||
<br />
|
<br />
|
||||||
{:else if token.type === 'del'}
|
{:else if token.type === 'del'}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { copyToClipboard, unescapeHtml } from '$lib/utils';
|
||||||
|
import { toast } from 'svelte-sonner';
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
export let token;
|
||||||
|
export let done = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
|
{#if done}
|
||||||
|
<code
|
||||||
|
class="codespan cursor-pointer"
|
||||||
|
on:click={() => {
|
||||||
|
copyToClipboard(unescapeHtml(token.text));
|
||||||
|
toast.success($i18n.t('Copied to clipboard'));
|
||||||
|
}}>{unescapeHtml(token.text)}</code
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<code
|
||||||
|
transition:fade={{ duration: 100 }}
|
||||||
|
class="codespan cursor-pointer"
|
||||||
|
on:click={() => {
|
||||||
|
copyToClipboard(unescapeHtml(token.text));
|
||||||
|
toast.success($i18n.t('Copied to clipboard'));
|
||||||
|
}}>{unescapeHtml(token.text)}</code
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
{token?.raw}
|
{token?.raw}
|
||||||
{:else}
|
{:else}
|
||||||
{#each texts as text}
|
{#each texts as text}
|
||||||
<span class="" transition:fade>
|
<span class="" transition:fade={{ duration: 100 }}>
|
||||||
{text}
|
{text}
|
||||||
</span>
|
</span>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,13 @@
|
||||||
<AlertRenderer {token} {alert} />
|
<AlertRenderer {token} {alert} />
|
||||||
{:else}
|
{:else}
|
||||||
<blockquote dir="auto">
|
<blockquote dir="auto">
|
||||||
<svelte:self id={`${id}-${tokenIdx}`} tokens={token.tokens} {onTaskClick} {onSourceClick} />
|
<svelte:self
|
||||||
|
id={`${id}-${tokenIdx}`}
|
||||||
|
tokens={token.tokens}
|
||||||
|
{done}
|
||||||
|
{onTaskClick}
|
||||||
|
{onSourceClick}
|
||||||
|
/>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if token.type === 'list'}
|
{:else if token.type === 'list'}
|
||||||
|
|
@ -222,6 +228,7 @@
|
||||||
id={`${id}-${tokenIdx}-${itemIdx}`}
|
id={`${id}-${tokenIdx}-${itemIdx}`}
|
||||||
tokens={item.tokens}
|
tokens={item.tokens}
|
||||||
top={token.loose}
|
top={token.loose}
|
||||||
|
{done}
|
||||||
{onTaskClick}
|
{onTaskClick}
|
||||||
{onSourceClick}
|
{onSourceClick}
|
||||||
/>
|
/>
|
||||||
|
|
@ -254,6 +261,7 @@
|
||||||
id={`${id}-${tokenIdx}-${itemIdx}`}
|
id={`${id}-${tokenIdx}-${itemIdx}`}
|
||||||
tokens={item.tokens}
|
tokens={item.tokens}
|
||||||
top={token.loose}
|
top={token.loose}
|
||||||
|
{done}
|
||||||
{onTaskClick}
|
{onTaskClick}
|
||||||
{onSourceClick}
|
{onSourceClick}
|
||||||
/>
|
/>
|
||||||
|
|
@ -263,6 +271,7 @@
|
||||||
id={`${id}-${tokenIdx}-${itemIdx}`}
|
id={`${id}-${tokenIdx}-${itemIdx}`}
|
||||||
tokens={item.tokens}
|
tokens={item.tokens}
|
||||||
top={token.loose}
|
top={token.loose}
|
||||||
|
{done}
|
||||||
{onTaskClick}
|
{onTaskClick}
|
||||||
{onSourceClick}
|
{onSourceClick}
|
||||||
/>
|
/>
|
||||||
|
|
@ -284,6 +293,7 @@
|
||||||
id={`${id}-${tokenIdx}-d`}
|
id={`${id}-${tokenIdx}-d`}
|
||||||
tokens={marked.lexer(token.text)}
|
tokens={marked.lexer(token.text)}
|
||||||
attributes={token?.attributes}
|
attributes={token?.attributes}
|
||||||
|
{done}
|
||||||
{onTaskClick}
|
{onTaskClick}
|
||||||
{onSourceClick}
|
{onSourceClick}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue