mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-18 05:25:53 +08:00
refac
This commit is contained in:
parent
667d26ca12
commit
794919e91d
@ -1,18 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import hljs from 'highlight.js';
|
|
||||||
import { loadPyodide } from 'pyodide';
|
|
||||||
import mermaid from 'mermaid';
|
import mermaid from 'mermaid';
|
||||||
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
import {
|
import { getContext, onMount, tick, onDestroy } from 'svelte';
|
||||||
getContext,
|
|
||||||
getAllContexts,
|
|
||||||
onMount,
|
|
||||||
tick,
|
|
||||||
createEventDispatcher,
|
|
||||||
onDestroy
|
|
||||||
} from 'svelte';
|
|
||||||
import { copyToClipboard } from '$lib/utils';
|
import { copyToClipboard } from '$lib/utils';
|
||||||
|
|
||||||
import 'highlight.js/styles/github-dark.min.css';
|
import 'highlight.js/styles/github-dark.min.css';
|
||||||
@ -25,10 +16,12 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
export let id = '';
|
export let id = '';
|
||||||
|
|
||||||
|
export let onSave = (e) => {};
|
||||||
|
export let onCode = (e) => {};
|
||||||
|
|
||||||
export let save = false;
|
export let save = false;
|
||||||
export let run = true;
|
export let run = true;
|
||||||
|
|
||||||
@ -71,7 +64,7 @@
|
|||||||
saved = true;
|
saved = true;
|
||||||
|
|
||||||
code = _code;
|
code = _code;
|
||||||
dispatch('save', code);
|
onSave(code);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
saved = false;
|
saved = false;
|
||||||
@ -344,7 +337,7 @@
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
$: dispatch('code', { lang, code });
|
$: onCode({ lang, code });
|
||||||
|
|
||||||
$: if (attributes) {
|
$: if (attributes) {
|
||||||
onAttributesUpdate();
|
onAttributesUpdate();
|
||||||
@ -380,7 +373,7 @@
|
|||||||
console.log('codeblock', lang, code);
|
console.log('codeblock', lang, code);
|
||||||
|
|
||||||
if (lang) {
|
if (lang) {
|
||||||
dispatch('code', { lang, code });
|
onCode({ lang, code });
|
||||||
}
|
}
|
||||||
if (document.documentElement.classList.contains('dark')) {
|
if (document.documentElement.classList.contains('dark')) {
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
|
@ -88,10 +88,10 @@
|
|||||||
code={token?.text ?? ''}
|
code={token?.text ?? ''}
|
||||||
{attributes}
|
{attributes}
|
||||||
{save}
|
{save}
|
||||||
on:code={(e) => {
|
onCode={(e) => {
|
||||||
dispatch('code', e.detail);
|
dispatch('code', e.detail);
|
||||||
}}
|
}}
|
||||||
on:save={(e) => {
|
onSave={(e) => {
|
||||||
dispatch('update', {
|
dispatch('update', {
|
||||||
raw: token.raw,
|
raw: token.raw,
|
||||||
oldContent: token.text,
|
oldContent: token.text,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user