Merge pull request #296 from SuanmoSuanyangTechnology/fix/release_web_zy
Fix/release web zy
This commit is contained in:
@@ -9,6 +9,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|||||||
import InitialValuePlugin from './plugin/InitialValuePlugin'
|
import InitialValuePlugin from './plugin/InitialValuePlugin'
|
||||||
import LineBreakPlugin from './plugin/LineBreakPlugin';
|
import LineBreakPlugin from './plugin/LineBreakPlugin';
|
||||||
import InsertTextPlugin from './plugin/InsertTextPlugin';
|
import InsertTextPlugin from './plugin/InsertTextPlugin';
|
||||||
|
import EditablePlugin from './plugin/EditablePlugin';
|
||||||
|
|
||||||
export interface EditorRef {
|
export interface EditorRef {
|
||||||
insertText: (text: string) => void;
|
insertText: (text: string) => void;
|
||||||
@@ -23,6 +24,7 @@ interface LexicalEditorProps {
|
|||||||
value?: string;
|
value?: string;
|
||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
height?: number;
|
height?: number;
|
||||||
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const theme = {
|
const theme = {
|
||||||
@@ -38,6 +40,7 @@ const EditorContent = forwardRef<EditorRef, LexicalEditorProps>(({
|
|||||||
value,
|
value,
|
||||||
placeholder = "请输入内容...",
|
placeholder = "请输入内容...",
|
||||||
onChange,
|
onChange,
|
||||||
|
disabled
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
@@ -92,7 +95,11 @@ const EditorContent = forwardRef<EditorRef, LexicalEditorProps>(({
|
|||||||
<RichTextPlugin
|
<RichTextPlugin
|
||||||
contentEditable={
|
contentEditable={
|
||||||
<ContentEditable
|
<ContentEditable
|
||||||
className={clsx("rb:outline-none rb:resize-none rb:text-[14px] rb:leading-5 rb:px-4 rb:py-5 rb:bg-[#FBFDFF] rb:border rb:border-[#DFE4ED] rb:rounded-lg rb:overflow-auto", className)}
|
className={clsx(
|
||||||
|
"rb:outline-none rb:resize-none rb:text-[14px] rb:leading-5 rb:px-4 rb:py-5 rb:bg-[#FBFDFF] rb:border rb:border-[#DFE4ED] rb:rounded-lg rb:overflow-auto",
|
||||||
|
disabled && "rb:cursor-not-allowed rb:bg-[#F6F8FC] rb:text-[#5B6167]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
placeholder={
|
placeholder={
|
||||||
@@ -105,6 +112,7 @@ const EditorContent = forwardRef<EditorRef, LexicalEditorProps>(({
|
|||||||
<LineBreakPlugin onChange={onChange} />
|
<LineBreakPlugin onChange={onChange} />
|
||||||
<InitialValuePlugin value={value} />
|
<InitialValuePlugin value={value} />
|
||||||
<InsertTextPlugin />
|
<InsertTextPlugin />
|
||||||
|
<EditablePlugin disabled={disabled} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -114,6 +122,7 @@ const Editor = forwardRef<EditorRef, LexicalEditorProps>((props, ref) => {
|
|||||||
namespace: 'Editor',
|
namespace: 'Editor',
|
||||||
theme,
|
theme,
|
||||||
nodes: [],
|
nodes: [],
|
||||||
|
editable: !props.disabled,
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ZhaoYing
|
||||||
|
* @Date: 2026-02-04 11:20:49
|
||||||
|
* @Last Modified by: ZhaoYing
|
||||||
|
* @Last Modified time: 2026-02-04 11:20:49
|
||||||
|
*/
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Props for the EditablePlugin component
|
||||||
|
*/
|
||||||
|
interface EditablePluginProps {
|
||||||
|
/** Whether the editor should be disabled (read-only mode) */
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditablePlugin - A Lexical editor plugin that controls the editable state of the editor
|
||||||
|
*
|
||||||
|
* This plugin allows you to dynamically toggle between editable and read-only modes.
|
||||||
|
* When disabled is true, the editor becomes read-only and users cannot modify content.
|
||||||
|
* When disabled is false or undefined, the editor is fully editable.
|
||||||
|
*
|
||||||
|
* @param {EditablePluginProps} props - Component props
|
||||||
|
* @param {boolean} [props.disabled] - Controls whether the editor is in read-only mode
|
||||||
|
* @returns {null} This plugin doesn't render any UI elements
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```tsx
|
||||||
|
* <LexicalComposer>
|
||||||
|
* <EditablePlugin disabled={isReadOnly} />
|
||||||
|
* </LexicalComposer>
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default function EditablePlugin({ disabled }: EditablePluginProps) {
|
||||||
|
// Get the editor instance from Lexical composer context
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
// Update editor's editable state whenever the disabled prop changes
|
||||||
|
useEffect(() => {
|
||||||
|
// Set editor to editable when disabled is false, read-only when disabled is true
|
||||||
|
editor.setEditable(!disabled);
|
||||||
|
}, [editor, disabled]);
|
||||||
|
|
||||||
|
// This plugin doesn't render any UI, it only manages editor state
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -140,7 +140,6 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
|
|||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(values)
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Form form={form}>
|
<Form form={form}>
|
||||||
@@ -199,12 +198,13 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
|
|||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
placeholder={t('prompt.promptPlaceholder')}
|
placeholder={t('prompt.promptPlaceholder')}
|
||||||
className="rb:h-[calc(100vh-260px)]"
|
className="rb:h-[calc(100vh-260px)]"
|
||||||
|
disabled={loading}
|
||||||
// onChange={(value) => form.setFieldValue('current_prompt', value)}
|
// onChange={(value) => form.setFieldValue('current_prompt', value)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<div className="rb:grid rb:grid-cols-2 rb:gap-4 rb:mt-6">
|
<div className="rb:grid rb:grid-cols-2 rb:gap-4 rb:mt-6">
|
||||||
<Button type="primary" block disabled={!values?.current_prompt} onClick={handleSave}>{t('common.save')}</Button>
|
<Button type="primary" block disabled={!values?.current_prompt || loading} onClick={handleSave}>{t('common.save')}</Button>
|
||||||
<Button block disabled={!values?.current_prompt} onClick={handleCopy}>{t('common.copy')}</Button>
|
<Button block disabled={!values?.current_prompt || loading} onClick={handleCopy}>{t('common.copy')}</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ const SpaceModal = forwardRef<SpaceModalRef, SpaceModalProps>(({
|
|||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
handleUpdate(formData)
|
handleUpdate(formData)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
handleUpdate(formData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -139,6 +141,7 @@ const SpaceModal = forwardRef<SpaceModalRef, SpaceModalProps>(({
|
|||||||
label={t('space.spaceIcon')}
|
label={t('space.spaceIcon')}
|
||||||
valuePropName="fileList"
|
valuePropName="fileList"
|
||||||
hidden={currentStep === 1}
|
hidden={currentStep === 1}
|
||||||
|
rules={[{ required: true, message: t('common.selectPlaceholder', { title: t('space.spaceIcon') }) }]}
|
||||||
>
|
>
|
||||||
<UploadImages />
|
<UploadImages />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ const Editor: FC<LexicalEditorProps> =({
|
|||||||
{enableLineNumbers && <LineNumberPlugin />}
|
{enableLineNumbers && <LineNumberPlugin />}
|
||||||
<AutocompletePlugin options={options} enableJinja2={enableJinja2} />
|
<AutocompletePlugin options={options} enableJinja2={enableJinja2} />
|
||||||
<CharacterCountPlugin setCount={(count) => { setCount(count) }} onChange={onChange} />
|
<CharacterCountPlugin setCount={(count) => { setCount(count) }} onChange={onChange} />
|
||||||
<InitialValuePlugin value={value} options={options} enableJinja2={enableJinja2} />
|
<InitialValuePlugin value={value} options={options} enableLineNumbers={enableLineNumbers} />
|
||||||
{enableLineNumbers && <BlurPlugin />}
|
{enableLineNumbers && <BlurPlugin />}
|
||||||
</div>
|
</div>
|
||||||
</LexicalComposer>
|
</LexicalComposer>
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import { type Suggestion } from '../plugin/AutocompletePlugin'
|
|||||||
interface InitialValuePluginProps {
|
interface InitialValuePluginProps {
|
||||||
value: string;
|
value: string;
|
||||||
options?: Suggestion[];
|
options?: Suggestion[];
|
||||||
enableJinja2?: boolean;
|
enableLineNumbers?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options = [], enableJinja2 = false }) => {
|
const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options = [], enableLineNumbers = false }) => {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
const prevValueRef = useRef<string>('');
|
const prevValueRef = useRef<string>('');
|
||||||
|
const prevEnableLineNumbersRef = useRef<boolean>(enableLineNumbers);
|
||||||
const isUserInputRef = useRef(false);
|
const isUserInputRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -32,7 +33,7 @@ const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options
|
|||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (value !== prevValueRef.current && !isUserInputRef.current) {
|
if ((value !== prevValueRef.current || enableLineNumbers !== prevEnableLineNumbersRef.current) && !isUserInputRef.current) {
|
||||||
queueMicrotask(() => {
|
queueMicrotask(() => {
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const root = $getRoot();
|
const root = $getRoot();
|
||||||
@@ -40,7 +41,7 @@ const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options
|
|||||||
|
|
||||||
const parts = value.split(/(\{\{[^}]+\}\})/);
|
const parts = value.split(/(\{\{[^}]+\}\})/);
|
||||||
|
|
||||||
if (enableJinja2) {
|
if (enableLineNumbers) {
|
||||||
// Handle newlines properly in Jinja2 mode
|
// Handle newlines properly in Jinja2 mode
|
||||||
const lines = value.split('\n');
|
const lines = value.split('\n');
|
||||||
lines.forEach((line) => {
|
lines.forEach((line) => {
|
||||||
@@ -104,8 +105,9 @@ const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options
|
|||||||
}
|
}
|
||||||
|
|
||||||
prevValueRef.current = value;
|
prevValueRef.current = value;
|
||||||
|
prevEnableLineNumbersRef.current = enableLineNumbers;
|
||||||
isUserInputRef.current = false;
|
isUserInputRef.current = false;
|
||||||
}, [value, options, editor, enableJinja2]);
|
}, [value, options, editor, enableLineNumbers]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export const useWorkflowGraph = ({
|
|||||||
nodeLibraryConfig.config[key].defaultValue = Object.entries(config[key]).map(([name, value]) => ({ name, value }))
|
nodeLibraryConfig.config[key].defaultValue = Object.entries(config[key]).map(([name, value]) => ({ name, value }))
|
||||||
} else if (type === 'code' && key === 'code' && config[key] && nodeLibraryConfig.config && nodeLibraryConfig.config[key]) {
|
} else if (type === 'code' && key === 'code' && config[key] && nodeLibraryConfig.config && nodeLibraryConfig.config[key]) {
|
||||||
try {
|
try {
|
||||||
nodeLibraryConfig.config[key].defaultValue = atob(config[key] as string)
|
nodeLibraryConfig.config[key].defaultValue = decodeURIComponent(atob(config[key] as string))
|
||||||
} catch {
|
} catch {
|
||||||
nodeLibraryConfig.config[key].defaultValue = config[key]
|
nodeLibraryConfig.config[key].defaultValue = config[key]
|
||||||
}
|
}
|
||||||
@@ -851,7 +851,7 @@ export const useWorkflowGraph = ({
|
|||||||
const code = data.config[key].defaultValue || ''
|
const code = data.config[key].defaultValue || ''
|
||||||
itemConfig = {
|
itemConfig = {
|
||||||
...itemConfig,
|
...itemConfig,
|
||||||
code: btoa(code || '')
|
code: btoa(encodeURIComponent(code || ''))
|
||||||
}
|
}
|
||||||
} else if (key === 'memory' && data.config[key] && 'defaultValue' in data.config[key]) {
|
} else if (key === 'memory' && data.config[key] && 'defaultValue' in data.config[key]) {
|
||||||
const { messages, ...rest } = data.config[key].defaultValue
|
const { messages, ...rest } = data.config[key].defaultValue
|
||||||
|
|||||||
Reference in New Issue
Block a user