-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pintora-demo): ConfigEditor in live-editor
- Loading branch information
Showing
7 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useCallback } from 'react' | ||
import MonacoEditor from 'src/live-editor/components/MonacoEditor' | ||
import { useDispatch, connect } from 'react-redux' | ||
import { State, actions } from 'src/live-editor/redux/slice' | ||
// import './Editor.less' | ||
|
||
interface Props { | ||
editorCode: string | ||
show: boolean | ||
} | ||
|
||
const CONFIG_EDITOR_OPTIONS = { | ||
language: 'json', | ||
} | ||
|
||
function ConfigEditor(props: Props) { | ||
const { editorCode, show } = props | ||
const dispatch = useDispatch() | ||
|
||
const onCodeChange = useCallback((code) => { | ||
dispatch(actions.updateConfigCode({ code })) | ||
}, []) | ||
|
||
const style = { | ||
display: show ? 'flex': 'none', | ||
} | ||
return <div className="ConfigEditor Editor" style={style}> | ||
<MonacoEditor code={editorCode} onCodeChange={onCodeChange} editorOptions={CONFIG_EDITOR_OPTIONS}></MonacoEditor> | ||
</div> | ||
} | ||
|
||
export default connect((state: State) => { | ||
return { | ||
editorCode: state.configEditor.code, | ||
show: state.currentEditor === 'config', | ||
} as Props | ||
})(ConfigEditor) |
File renamed without changes.
18 changes: 14 additions & 4 deletions
18
demo/src/live-editor/components/Editor.tsx → ...c/live-editor/containers/Editor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
import React, { useCallback } from 'react' | ||
import MonacoEditor from './MonacoEditor' | ||
import MonacoEditor from 'src/live-editor/components/MonacoEditor' | ||
import { useDispatch, connect } from 'react-redux' | ||
import { State, actions } from 'src/live-editor/redux/slice' | ||
import './Editor.less' | ||
import classNames from 'classnames' | ||
|
||
interface Props { | ||
editorCode: string | ||
show: boolean | ||
} | ||
|
||
const CODE_EDITOR_OPTIONS = { | ||
language: 'pintora', | ||
} | ||
|
||
function Editor(props: Props) { | ||
const { editorCode } = props | ||
const { editorCode, show } = props | ||
const dispatch = useDispatch() | ||
|
||
const onCodeChange = useCallback((code) => { | ||
dispatch(actions.updateEditorCode({ code, syncToPreview: true })) | ||
}, []) | ||
|
||
return <div className="Editor"> | ||
<MonacoEditor code={editorCode} onCodeChange={onCodeChange}></MonacoEditor> | ||
const style = { | ||
display: show ? 'flex': 'none', | ||
} | ||
return <div className="Editor" style={style}> | ||
<MonacoEditor code={editorCode} onCodeChange={onCodeChange} editorOptions={CODE_EDITOR_OPTIONS}></MonacoEditor> | ||
</div> | ||
} | ||
|
||
export default connect((state: State) => { | ||
return { | ||
editorCode: state.editor.code, | ||
show: state.currentEditor === 'code', | ||
} as Props | ||
})(Editor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters