mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
};
|
||||
|
||||
let command = '';
|
||||
$: command = prompt.split(' ')?.at(-1) ?? '';
|
||||
$: command = prompt?.split('\n').pop()?.split(' ')?.pop() ?? '';
|
||||
</script>
|
||||
|
||||
{#if ['/', '#', '@'].includes(command?.charAt(0)) || '\\#' === command.slice(0, 2)}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list'; // Import from prosemirror-schema-list
|
||||
import { keymap } from 'prosemirror-keymap';
|
||||
import { baseKeymap, chainCommands } from 'prosemirror-commands';
|
||||
import { DOMParser, DOMSerializer, Schema } from 'prosemirror-model';
|
||||
import { DOMParser, DOMSerializer, Schema, Fragment } from 'prosemirror-model';
|
||||
|
||||
import { marked } from 'marked'; // Import marked for markdown parsing
|
||||
import { dev } from '$app/environment';
|
||||
@@ -69,7 +69,10 @@
|
||||
|
||||
// Method to convert markdown content to ProseMirror-compatible document
|
||||
function markdownToProseMirrorDoc(markdown: string) {
|
||||
return defaultMarkdownParser.parse(value || '');
|
||||
console.log('Markdown:', markdown);
|
||||
// Parse the Markdown content into a ProseMirror document
|
||||
let doc = defaultMarkdownParser.parse(markdown || '');
|
||||
return doc;
|
||||
}
|
||||
|
||||
// Utility function to convert ProseMirror content back to markdown text
|
||||
@@ -399,6 +402,7 @@
|
||||
// Reinitialize the editor if the value is externally changed (i.e. when `value` is updated)
|
||||
$: if (view && value !== serializeEditorContent(view.state.doc)) {
|
||||
const newDoc = markdownToProseMirrorDoc(value || '');
|
||||
|
||||
const newState = EditorState.create({
|
||||
doc: newDoc,
|
||||
schema,
|
||||
@@ -407,15 +411,17 @@
|
||||
});
|
||||
view.updateState(newState);
|
||||
|
||||
// After updating the state, try to find and select the next template
|
||||
setTimeout(() => {
|
||||
const templateFound = selectNextTemplate(view.state, view.dispatch);
|
||||
if (!templateFound) {
|
||||
// If no template found, set cursor at the end
|
||||
const endPos = view.state.doc.content.size;
|
||||
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, endPos)));
|
||||
}
|
||||
}, 0);
|
||||
if (value !== '') {
|
||||
// After updating the state, try to find and select the next template
|
||||
setTimeout(() => {
|
||||
const templateFound = selectNextTemplate(view.state, view.dispatch);
|
||||
if (!templateFound) {
|
||||
// If no template found, set cursor at the end
|
||||
const endPos = view.state.doc.content.size;
|
||||
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, endPos)));
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy ProseMirror instance on unmount
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
class=" bg-gradient-to-b via-50% from-white via-white to-transparent dark:from-gray-900 dark:via-gray-900 dark:to-transparent pointer-events-none absolute inset-0 -bottom-7 z-[-1] blur"
|
||||
></div>
|
||||
|
||||
<div class=" flex max-w-full w-full mx-auto px-5 pt-0.5 md:px-[1rem] bg-transparen">
|
||||
<div class=" flex max-w-full w-full mx-auto px-2 pt-0.5 md:px-[1rem] bg-transparent">
|
||||
<div class="flex items-center w-full max-w-full">
|
||||
<div
|
||||
class="{$showSidebar
|
||||
|
||||
Reference in New Issue
Block a user