🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: revert editor modal (#11484)
Arvin Xu909f4d864826
diff --git a/src/features/EditorModal/EditorCanvas.tsx b/src/features/EditorModal/EditorCanvas.tsxnew file mode 100644index 00000000000..56581ad535a--- /dev/null+++ b/src/features/EditorModal/EditorCanvas.tsx@@ -0,0 +1,62 @@+import {+ IEditor,+ ReactCodePlugin,+ ReactCodemirrorPlugin,+ ReactHRPlugin,+ ReactLinkPlugin,+ ReactListPlugin,+ ReactMathPlugin,+ ReactTablePlugin,+} from '@lobehub/editor';+import { Editor } from '@lobehub/editor/react';+import { Flexbox } from '@lobehub/ui';+import { FC } from 'react';++import TypoBar from './Typobar';++interface EditorCanvasProps {+ defaultValue?: string;+ editor?: IEditor;+}++const EditorCanvas: FC<EditorCanvasProps> = ({ defaultValue, editor }) => {+ return (+ <>+ <TypoBar editor={editor} />+ <Flexbox+ padding={16}+ style={{ cursor: 'text', maxHeight: '80vh', minHeight: '50vh', overflowY: 'auto' }}+ >+ <Editor+ autoFocus+ content={''}+ editor={editor}+ onInit={(editor) => {+ if (!editor || !defaultValue) return;+ try {+ editor?.setDocument('markdown', defaultValue);+ } catch (e) {+ console.error('setDocument error:', e);+ }+ }}+ plugins={[+ ReactListPlugin,+ ReactCodePlugin,+ ReactCodemirrorPlugin,+ ReactHRPlugin,+ ReactLinkPlugin,+ ReactTablePlugin,+ ReactMathPlugin,+ ]}+ style={{+ paddingBottom: 120,+ }}+ type={'text'}+ variant={'chat'}+ />+ </Flexbox>+ </>+ );+};++export default EditorCanvas;diff --git a/src/features/EditorModal/TextArea.tsx b/src/features/EditorModal/TextArea.tsxnew file mode 100644index 00000000000..c68b61864c6--- /dev/null+++ b/src/features/EditorModal/TextArea.tsx@@ -0,0 +1,30 @@+import { TextArea } from '@lobehub/ui';+import { FC } from 'react';++interface EditorCanvasProps {+ defaultValue?: string;+ onChange?: (value: string) => void;+ value?: string;+}++const EditorCanvas: FC<EditorCanvasProps> = ({ defaultValue, value, onChange }) => {+ return (+ <TextArea+ defaultValue={defaultValue}+ onChange={(e) => {+ onChange?.(e.target.value);+ }}+ style={{+ cursor: 'text',+ maxHeight: '80vh',+ minHeight: '50vh',+ overflowY: 'auto',+ padding: 16,+ }}+ value={value}+ variant={'borderless'}+ />+ );+};++export default EditorCanvas;diff --git a/src/features/EditorModal/Typobar.tsx b/src/features/EditorModal/Typobar.tsxnew file mode 100644index 00000000000..442adaf3123--- /dev/null+++ b/src/features/EditorModal/Typobar.tsx@@ -0,0 +1,139 @@+import { HotkeyEnum, type IEditor, getHotkeyById } from '@lobehub/editor';+import { useEditorState } from '@lobehub/editor/react';+import {+ ChatInputActionBar,+ ChatInputActions,+ type ChatInputActionsProps,+} from '@lobehub/editor/react';+import { cssVar } from 'antd-style';+import {+ BoldIcon,+ CodeXmlIcon,+ ItalicIcon,+ ListIcon,+ ListOrderedIcon,+ ListTodoIcon,+ MessageSquareQuote,+ SigmaIcon,+ SquareDashedBottomCodeIcon,+ StrikethroughIcon,+ UnderlineIcon,+} from 'lucide-react';+import { memo, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++const TypoBar = memo<{ editor?: IEditor }>(({ editor }) => {+ const { t } = useTranslation('editor');+ const editorState = useEditorState(editor);++ const items: ChatInputActionsProps['items'] = useMemo(+ () =>+ [+ {+ active: editorState.isBold,+ icon: BoldIcon,+ key: 'bold',+ label: t('typobar.bold'),+ onClick: editorState.bold,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Bold).keys },+ },+ {+ active: editorState.isItalic,+ icon: ItalicIcon,+ key: 'italic',+ label: t('typobar.italic'),+ onClick: editorState.italic,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Italic).keys },+ },+ {+ active: editorState.isUnderline,+ icon: UnderlineIcon,+ key: 'underline',+ label: t('typobar.underline'),+ onClick: editorState.underline,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Underline).keys },+ },+ {+ active: editorState.isStrikethrough,+ icon: StrikethroughIcon,+ key: 'strikethrough',+ label: t('typobar.strikethrough'),+ onClick: editorState.strikethrough,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.Strikethrough).keys },+ },+ {+ type: 'divider',+ },++ {+ icon: ListIcon,+ key: 'bulletList',+ label: t('typobar.bulletList'),+ onClick: editorState.bulletList,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.BulletList).keys },+ },+ {+ icon: ListOrderedIcon,+ key: 'numberlist',+ label: t('typobar.numberList'),+ onClick: editorState.numberList,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.NumberList).keys },+ },+ {+ icon: ListTodoIcon,+ key: 'tasklist',+ label: t('typobar.taskList'),+ onClick: editorState.checkList,+ },+ {+ type: 'divider',+ },+ {+ active: editorState.isBlockquote,+ icon: MessageSquareQuote,+ key: 'blockquote',+ label: t('typobar.blockquote'),+ onClick: editorState.blockquote,+ },+ {+ type: 'divider',+ },+ {+ icon: SigmaIcon,+ key: 'math',+ label: t('typobar.tex'),+ onClick: editorState.insertMath,+ },+ {+ active: editorState.isCode,+ icon: CodeXmlIcon,+ key: 'code',+ label: t('typobar.code'),+ onClick: editorState.code,+ tooltipProps: { hotkey: getHotkeyById(HotkeyEnum.CodeInline).keys },+ },+ {+ icon: SquareDashedBottomCodeIcon,+ key: 'codeblock',+ label: t('typobar.codeblock'),+ onClick: editorState.codeblock,+ },+ ].filter(Boolean) as ChatInputActionsProps['items'],+ [editorState],+ );++ return (+ <ChatInputActionBar+ left={<ChatInputActions items={items} />}+ style={{+ background: cssVar.colorFillQuaternary,+ borderTopLeftRadius: 8,+ borderTopRightRadius: 8,+ }}+ />+ );+});++TypoBar.displayName = 'TypoBar';++export default TypoBar;diff --git a/src/features/EditorModal/index.tsx b/src/features/EditorModal/index.tsxindex b717ad8f573..59065063012 100644--- a/src/features/EditorModal/index.tsx+++ b/src/features/EditorModal/index.tsx@@ -3,7 +3,11 @@ import { Modal, ModalProps, createRawModal } from '@lobehub/ui';import { memo, useState } from 'react';import { useTranslation } from 'react-i18next';-import { EditorCanvas } from '@/features/EditorCanvas';+import { useUserStore } from '@/store/user';+import { labPreferSelectors } from '@/store/user/selectors';++import EditorCanvas from './EditorCanvas';+import TextareCanvas from './TextArea';interface EditorModalProps extends ModalProps {onConfirm?: (value: string) => Promise<void>;@@ -13,7 +17,8 @@ interface EditorModalProps extends ModalProps {export const EditorModal = memo<EditorModalProps>(({ value, onConfirm, ...rest }) => {const [confirmLoading, setConfirmLoading] = useState(false);const { t } = useTranslation('common');-+ const [v, setV] = useState(value);+ const enableRichRender = useUserStore(labPreferSelectors.enableInputMarkdown);const editor = useEditor();return (@@ -25,12 +30,13 @@ export const EditorModal = memo<EditorModalProps>(({ value, onConfirm, ...rest }okText={t('ok')}onOk={async () => {setConfirmLoading(true);- try {- await onConfirm?.((editor?.getDocument('markdown') as unknown as string) || '');- } catch (e) {- console.error('EditorModal onOk error:', e);- onConfirm?.(value || '');+ let finalValue;+ if (enableRichRender) {+ finalValue = editor?.getDocument('markdown') as unknown as string;+ } else {+ finalValue = v;}+ await onConfirm?.(finalValue || '');setConfirmLoading(false);}}styles={{@@ -43,7 +49,11 @@ export const EditorModal = memo<EditorModalProps>(({ value, onConfirm, ...rest }width={'min(90vw, 920px)'}{...rest}>- <EditorCanvas editor={editor} editorData={{ content: value }} />+ {enableRichRender ? (+ <EditorCanvas defaultValue={value} editor={editor} />+ ) : (+ <TextareCanvas defaultValue={value} onChange={(v) => setV(v)} value={v} />+ )}</Modal>);});