Skip to content

Commit

Permalink
fix: 切换时value不会改变
Browse files Browse the repository at this point in the history
  • Loading branch information
1360151219 committed Oct 12, 2023
1 parent c684f94 commit 3e8fc22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 10 additions & 8 deletions packages/design/components/MonacoEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const FILENAME = 'index.tsx';

const MonacoEditor = (props: MocacoEditorProps) => {
const { compilerWorker } = useWorkers();
const [value, onChange] = useControlled<string>(props, {
valuePropName: 'value',
changeName: 'onChange',
defaultValuePropName: 'defaultValue',
});
// const [value, onChange] = useControlled<string>(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;

Expand All @@ -39,7 +41,7 @@ const MonacoEditor = (props: MocacoEditorProps) => {
type: MessageChangeType.Compile,
data: {
filename: path,
code: value,
code: defaultValue,
modules,
},
});
Expand All @@ -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}
/>
Expand Down
7 changes: 4 additions & 3 deletions packages/design/components/MonacoEditor/MultipleEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 3e8fc22

Please sign in to comment.