mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
4.8 preview (#1288)
* Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * perf: workflow ux * system config * Newflow (#89) * docs: Add doc for Xinference (#1266) Signed-off-by: Carson Yang <yangchuansheng33@gmail.com> * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * perf: workflow ux * system config * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * rename code * move code * update flow * input type selector * perf: workflow runtime * feat: node adapt newflow * feat: adapt plugin * feat: 360 connection * check workflow * perf: flow 性能 * change plugin input type (#81) * change plugin input type * plugin label mode * perf: nodecard * debug * perf: debug ui * connection ui * change workflow ui (#82) * feat: workflow debug * adapt openAPI for new workflow (#83) * adapt openAPI for new workflow * i18n * perf: plugin debug * plugin input ui * delete * perf: global variable select * fix rebase * perf: workflow performance * feat: input render type icon * input icon * adapt flow (#84) * adapt newflow * temp * temp * fix * feat: app schedule trigger * feat: app schedule trigger * perf: schedule ui * feat: ioslatevm run js code * perf: workflow varialbe table ui * feat: adapt simple mode * feat: adapt input params * output * feat: adapt tamplate * fix: ts * add if-else module (#86) * perf: worker * if else node * perf: tiktoken worker * fix: ts * perf: tiktoken * fix if-else node (#87) * fix if-else node * type * fix * perf: audio render * perf: Parallel worker * log * perf: if else node * adapt plugin * prompt * perf: reference ui * reference ui * handle ux * template ui and plugin tool * adapt v1 workflow * adapt v1 workflow completions * perf: time variables * feat: workflow keyboard shortcuts * adapt v1 workflow * update workflow example doc (#88) * fix: simple mode select tool --------- Signed-off-by: Carson Yang <yangchuansheng33@gmail.com> Co-authored-by: Carson Yang <yangchuansheng33@gmail.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com> * doc * perf: extract node * extra node field * update plugin version * doc * variable * change doc & fix prompt editor (#90) * fold workflow code * value type label --------- Signed-off-by: Carson Yang <yangchuansheng33@gmail.com> Co-authored-by: Carson Yang <yangchuansheng33@gmail.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -17,9 +17,11 @@ import { EditorVariablePickerType } from './type.d';
|
||||
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
||||
import FocusPlugin from './plugins/FocusPlugin';
|
||||
import { textToEditorState } from './utils';
|
||||
import { MaxLengthPlugin } from './plugins/MaxLengthPlugin';
|
||||
|
||||
export default function Editor({
|
||||
h = 200,
|
||||
maxLength,
|
||||
showResize = true,
|
||||
showOpenModal = true,
|
||||
onOpenModal,
|
||||
@@ -27,9 +29,11 @@ export default function Editor({
|
||||
onChange,
|
||||
onBlur,
|
||||
value,
|
||||
placeholder = ''
|
||||
placeholder = '',
|
||||
isFlow
|
||||
}: {
|
||||
h?: number;
|
||||
maxLength?: number;
|
||||
showResize?: boolean;
|
||||
showOpenModal?: boolean;
|
||||
onOpenModal?: () => void;
|
||||
@@ -38,6 +42,7 @@ export default function Editor({
|
||||
onBlur?: (editor: LexicalEditor) => void;
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
isFlow?: boolean;
|
||||
}) {
|
||||
const [key, setKey] = useState(getNanoid(6));
|
||||
const [_, startSts] = useTransition();
|
||||
@@ -81,7 +86,11 @@ export default function Editor({
|
||||
<Box position={'relative'} width={'full'} h={`${height}px`} cursor={'text'}>
|
||||
<LexicalComposer initialConfig={initialConfig} key={key}>
|
||||
<PlainTextPlugin
|
||||
contentEditable={<ContentEditable className={styles.contentEditable} />}
|
||||
contentEditable={
|
||||
<ContentEditable
|
||||
className={isFlow ? styles.contentEditable_isFlow : styles.contentEditable}
|
||||
/>
|
||||
}
|
||||
placeholder={
|
||||
<Box
|
||||
position={'absolute'}
|
||||
@@ -95,8 +104,8 @@ export default function Editor({
|
||||
overflow={'overlay'}
|
||||
>
|
||||
<Box
|
||||
color={'myGray.500'}
|
||||
fontSize={'xs'}
|
||||
color={'myGray.400'}
|
||||
fontSize={'11px'}
|
||||
userSelect={'none'}
|
||||
whiteSpace={'pre-wrap'}
|
||||
wordBreak={'break-all'}
|
||||
@@ -109,6 +118,7 @@ export default function Editor({
|
||||
ErrorBoundary={LexicalErrorBoundary}
|
||||
/>
|
||||
<HistoryPlugin />
|
||||
<MaxLengthPlugin maxLength={maxLength || 999999} />
|
||||
<FocusPlugin focus={focus} setFocus={setFocus} />
|
||||
<OnChangePlugin
|
||||
onChange={(editorState, editor) => {
|
||||
@@ -138,7 +148,7 @@ export default function Editor({
|
||||
<Box
|
||||
zIndex={10}
|
||||
position={'absolute'}
|
||||
bottom={1}
|
||||
bottom={0}
|
||||
right={2}
|
||||
cursor={'pointer'}
|
||||
onClick={onOpenModal}
|
||||
|
@@ -6,7 +6,19 @@
|
||||
border-radius: var(--chakra-radii-md);
|
||||
padding: 8px 12px;
|
||||
background: var(--chakra-colors-gray-50);
|
||||
font-size: 13px;
|
||||
font-size: 14px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.contentEditable_isFlow {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
border: 1px solid var(--chakra-colors-myGray-200);
|
||||
border-radius: var(--chakra-radii-sm);
|
||||
padding: 6px 8px;
|
||||
background: #fff;
|
||||
font-size: 14px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@@ -14,7 +26,13 @@
|
||||
outline: none;
|
||||
border: 1px solid;
|
||||
border-color: var(--chakra-colors-primary-600);
|
||||
background: #fff;
|
||||
box-shadow: 0px 0px 0px 2.4px rgba(51, 112, 255, 0.15);
|
||||
}
|
||||
|
||||
.contentEditable_isFlow:focus {
|
||||
outline: none;
|
||||
border: 1px solid;
|
||||
border-color: var(--chakra-colors-primary-600);
|
||||
box-shadow: 0px 0px 0px 2.4px rgba(51, 112, 255, 0.15);
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,10 @@ const PromptEditor = ({
|
||||
onChange,
|
||||
onBlur,
|
||||
h,
|
||||
maxLength,
|
||||
placeholder,
|
||||
title
|
||||
title,
|
||||
isFlow
|
||||
}: {
|
||||
showOpenModal?: boolean;
|
||||
showResize?: boolean;
|
||||
@@ -26,8 +28,10 @@ const PromptEditor = ({
|
||||
onChange?: (text: string) => void;
|
||||
onBlur?: (text: string) => void;
|
||||
h?: number;
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
title?: string;
|
||||
isFlow?: boolean;
|
||||
}) => {
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
const [, startSts] = useTransition();
|
||||
@@ -52,15 +56,18 @@ const PromptEditor = ({
|
||||
onOpenModal={onOpen}
|
||||
variables={variables}
|
||||
h={h}
|
||||
maxLength={maxLength}
|
||||
value={value}
|
||||
onChange={onChangeInput}
|
||||
onBlur={onBlurInput}
|
||||
placeholder={placeholder}
|
||||
isFlow={isFlow}
|
||||
/>
|
||||
<MyModal isOpen={isOpen} onClose={onClose} iconSrc="modal/edit" title={title} w={'full'}>
|
||||
<ModalBody>
|
||||
<Editor
|
||||
h={400}
|
||||
maxLength={maxLength}
|
||||
showResize
|
||||
showOpenModal={false}
|
||||
variables={variables}
|
||||
|
@@ -48,7 +48,7 @@ export default function ComfirmVar({
|
||||
border={'1px solid rgba(0, 0, 0, 0.1)'}
|
||||
mx={4}
|
||||
>
|
||||
<Image alt={''} src={'/imgs/module/variable.png'} objectFit={'contain'} w={'20px'} />
|
||||
<Image alt={''} src={'/imgs/workflow/variable.png'} objectFit={'contain'} w={'20px'} />
|
||||
</Box>
|
||||
<Box>引用了未定义的变量,是否自动添加?</Box>
|
||||
</Box>
|
||||
|
@@ -0,0 +1,41 @@
|
||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||
import { trimTextContentFromAnchor } from '@lexical/selection';
|
||||
import { $restoreEditorState } from '@lexical/utils';
|
||||
import { $getSelection, $isRangeSelection, EditorState, RootNode } from 'lexical';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function MaxLengthPlugin({ maxLength }: { maxLength: number }): null {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
|
||||
useEffect(() => {
|
||||
let lastRestoredEditorState: EditorState | null = null;
|
||||
|
||||
return editor.registerNodeTransform(RootNode, (rootNode: RootNode) => {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
|
||||
return;
|
||||
}
|
||||
const prevEditorState = editor.getEditorState();
|
||||
const prevTextContentSize = prevEditorState.read(() => rootNode.getTextContentSize());
|
||||
const textContentSize = rootNode.getTextContentSize();
|
||||
if (prevTextContentSize !== textContentSize) {
|
||||
const delCount = textContentSize - maxLength;
|
||||
const anchor = selection.anchor;
|
||||
|
||||
if (delCount > 0) {
|
||||
// Restore the old editor state instead if the last
|
||||
// text content was already at the limit.
|
||||
if (prevTextContentSize === maxLength && lastRestoredEditorState !== prevEditorState) {
|
||||
lastRestoredEditorState = prevEditorState;
|
||||
$restoreEditorState(editor, prevEditorState);
|
||||
} else {
|
||||
//@ts-ignore
|
||||
trimTextContentFromAnchor(editor, anchor, delCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}, [editor, maxLength]);
|
||||
|
||||
return null;
|
||||
}
|
@@ -171,8 +171,9 @@ export function registerLexicalTextEntity<T extends TextNode>(
|
||||
return [removePlainTextTransform, removeReverseNodeTransform];
|
||||
}
|
||||
|
||||
export function textToEditorState(text: string = '') {
|
||||
const paragraph = text?.split('\n');
|
||||
export function textToEditorState(text = '') {
|
||||
const paragraph = typeof text === 'string' ? text?.split('\n') : [''];
|
||||
|
||||
return JSON.stringify({
|
||||
root: {
|
||||
children: paragraph.map((p) => {
|
||||
|
Reference in New Issue
Block a user