dt-react-monaco-editor
v2.0.0
Published
Monaco editor for React.
Readme
Monaco Editor React Components
简体中文 | English
简介
提供 MonacoEditor 组件和 MonacoDiffEditor 组件,让在 React 中使用 Monaco Editor 更轻松。
安装
使用 npm
npm install dt-react-monaco-editor或者使用 yarn
yarn add dt-react-monaco-editor或者使用 pnpm
pnpm install dt-react-monaco-editor集成
使用
MonacoEditor 组件
import { MonacoEditor } from 'dt-react-monaco-editor';
function App() {
const editorRef = useRef();
return (
<MonacoEditor
value=""
language="javascript"
style={{ height: 400, width: 600 }}
onChange={(value) => {
console.log(value);
}}
editorDidMount={(ins) => (editorRef.current = ins)}
/>
);
}MonacoDiffEditor 组件
import { MonacoDiffEditor } from 'dt-react-monaco-editor';
function App() {
const editorRef = useRef();
return (
<MonacoDiffEditor
original="const a = 1;"
value="const a = 2;"
language="sql"
style={{ height: 400, width: 1200 }}
onChange={(value) => {
console.log(value);
}}
editorDidMount={(ins) => (editorRef.current = ins)}
/>
);
}属性
公共属性
公共属性在 MonacoEditor 和 MonacoDiffEditor 上都可以使用。
theme编辑器在渲染时应用的主题, 默认是vs。language编辑器的语言类型, 默认是sql。sync当value属性变化时是否将新的value同步到编辑器中,如果sync属性是true,编辑器就是受控的, 默认时false。onChange当编辑器的值变化时,触发这个回调。
MonacoEditor 属性
value编辑器的值。optionsMonaco Editor 的选项, 关联 monaco 接口IStandaloneEditorConstructionOptions。- [deprecated]
editorInstanceRef获取MonacoEditor内部的 editor 实例。 onCursorSelection当编辑器选中的内容发生变化时,触发这个回调。onFocus当编辑器聚焦时,触发这个回调。onBlur当编辑器失焦时,触发这个回调。editorWillMount在编辑器即将挂载时调用(类似于 React 的 componentWillMount)。editorDidMount当编辑器挂载完成时调用 (类似于 React 的 componentDidMount)。editorWillUnMount当编辑器即将销毁时调用 (类似于 React 的 componentWillUnmount)。
MonacoDiffEditor 属性
valuemodifiedEditor(右边的编辑器) 的值。originaloriginalEditor(左边的编辑器) 的值。optionsMonaco DiffEditor 的选项, 关联 monaco 接口 IStandaloneDiffEditorConstructionOptions.- [deprecated]
diffEditorInstanceRef获取MonacoDiffEditor内部的 diffEditor 实例。 editorWillMount在编辑器即将挂载时调用(类似于 React 的 componentWillMount)。editorDidMount当编辑器挂载完成时调用 (类似于 React 的 componentDidMount)。editorWillUnMount当编辑器即将销毁时调用 (类似于 React 的 componentWillUnmount)。
支持更多 SQL 语言功能
monaco-sql-languages 为大数据领域的多种 SQL 类型提供了高亮、自动错误提示以及自动补全 功能,它支持按需引入并且很容易集成。
