From 3e8fc22abc21bb502f6724b80c337b8059431279 Mon Sep 17 00:00:00 2001 From: 1360151219 <1360151219@qq.com> Date: Thu, 12 Oct 2023 09:13:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=87=E6=8D=A2=E6=97=B6value?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/components/MonacoEditor/Editor.tsx | 18 ++++++++++-------- .../components/MonacoEditor/MultipleEditor.tsx | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/design/components/MonacoEditor/Editor.tsx b/packages/design/components/MonacoEditor/Editor.tsx index c66d331..7a63820 100644 --- a/packages/design/components/MonacoEditor/Editor.tsx +++ b/packages/design/components/MonacoEditor/Editor.tsx @@ -15,17 +15,19 @@ const FILENAME = 'index.tsx'; const MonacoEditor = (props: MocacoEditorProps) => { const { compilerWorker } = useWorkers(); - const [value, onChange] = useControlled(props, { - valuePropName: 'value', - changeName: 'onChange', - defaultValuePropName: 'defaultValue', - }); + // const [value, onChange] = useControlled(props, { + // valuePropName: 'value', + // changeName: 'onChange', + // defaultValuePropName: 'defaultValue', + // }); const { height = 400, defaultLanguage = CodeType.ts, path = FILENAME, theme = ThemeType['Visual Studio Dark'], modules, + onChange, + defaultValue, ...rest } = props; @@ -39,7 +41,7 @@ const MonacoEditor = (props: MocacoEditorProps) => { type: MessageChangeType.Compile, data: { filename: path, - code: value, + code: defaultValue, modules, }, }); @@ -64,11 +66,11 @@ const MonacoEditor = (props: MocacoEditorProps) => { height={height} path={path} defaultLanguage={defaultLanguage} - defaultValue={value} + defaultValue={defaultValue} theme={theme} onChange={handleEditorChange} onMount={handleEditorDidMount} - {...omit(rest, ['value', 'onChange'])} + {...rest} // beforeMount={handleEditorWillMount} // onValidate={handleEditorValidation} /> diff --git a/packages/design/components/MonacoEditor/MultipleEditor.tsx b/packages/design/components/MonacoEditor/MultipleEditor.tsx index a427aec..59a4e2c 100644 --- a/packages/design/components/MonacoEditor/MultipleEditor.tsx +++ b/packages/design/components/MonacoEditor/MultipleEditor.tsx @@ -35,8 +35,9 @@ const items = [ }`, }, ]; -// todo: 1.多文件引入(scss、tsx),引入scss -// 2.代码优化; +// todo: 1. 编译文件的独立性。现在修改css实际走的是tsx的编译 +// 2.引入scss +// 3.代码优化; const MultipleEditor = () => { const [tabsValue, setTabsValue] = useLocalStorage('tabs', { defaultValue: items, @@ -52,7 +53,7 @@ const MultipleEditor = () => { modules={tabsValue} path={String(item.label)} defaultLanguage={item.language} - value={item.value} + defaultValue={item.value} onChange={(value) => { const prevTabValue = tabsValue; const activeTab = _find(prevTabValue, item.key);