mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-21 19:42:07 +00:00
fix: simple prompt editor list render (#5717)
This commit is contained in:
@@ -132,7 +132,7 @@ export default function Editor({
|
|||||||
CodeNode,
|
CodeNode,
|
||||||
CodeHighlightNode
|
CodeHighlightNode
|
||||||
],
|
],
|
||||||
editorState: textToEditorState(value),
|
editorState: textToEditorState(value, isRichText),
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,7 @@ const PromptEditor = ({
|
|||||||
minH={400}
|
minH={400}
|
||||||
maxH={400}
|
maxH={400}
|
||||||
showOpenModal={false}
|
showOpenModal={false}
|
||||||
value={value}
|
value={formattedValue}
|
||||||
onChange={onChangeInput}
|
onChange={onChangeInput}
|
||||||
onChangeText={onChange}
|
onChangeText={onChange}
|
||||||
onBlur={onBlurInput}
|
onBlur={onBlurInput}
|
||||||
|
@@ -270,10 +270,42 @@ const buildListStructure = (items: ListItemInfo[]) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const textToEditorState = (text = '') => {
|
export const textToEditorState = (text = '', isRichText = false) => {
|
||||||
const lines = text.split('\n');
|
const lines = text.split('\n');
|
||||||
const children: Array<ParagraphEditorNode | ListEditorNode> = [];
|
const children: Array<ParagraphEditorNode | ListEditorNode> = [];
|
||||||
|
|
||||||
|
if (!isRichText) {
|
||||||
|
return JSON.stringify({
|
||||||
|
root: {
|
||||||
|
children: lines.map((p) => {
|
||||||
|
return {
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
detail: 0,
|
||||||
|
format: 0,
|
||||||
|
mode: 'normal',
|
||||||
|
style: '',
|
||||||
|
text: p,
|
||||||
|
type: 'text',
|
||||||
|
version: 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
direction: 'ltr',
|
||||||
|
format: '',
|
||||||
|
indent: 0,
|
||||||
|
type: 'paragraph',
|
||||||
|
version: 1
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
direction: 'ltr',
|
||||||
|
format: '',
|
||||||
|
indent: 0,
|
||||||
|
type: 'root',
|
||||||
|
version: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < lines.length) {
|
while (i < lines.length) {
|
||||||
const parsed = parseTextLine(lines[i]);
|
const parsed = parseTextLine(lines[i]);
|
||||||
|
Reference in New Issue
Block a user