1.3.7 • Published 10 days ago

react-monaco-editor-lite v1.3.7

Weekly downloads
-
License
MIT
Repository
-
Last release
10 days ago

monaco-base-ide

如何使用

安装

npm install react-monaco-editor-lite

使用

多文件编辑器

import { MultiEditor } from 'react-monaco-editor-lite';

function IDE() {
    const defaultFiles = {
        '/src/app.jsx': `
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

(async () => {
  const {Button} = await import('./Button.jsx');
  const root = document.getElementById('root');
  ReactDOM.render((
    <div>
      <Button>Direct</Button>
    </div>
  ), root);
})();
`,
        '/src/app.css': 'body { background: #fff }',
        '/index.html': `
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="root"></div>
<script type="importmap">
    {
    "imports": {
        "react": "https://cdn.skypack.dev/react",
        "react-dom": "https://cdn.skypack.dev/react-dom",
        "lodash": "https://cdn.skypack.dev/lodash"
    }
    }
</script>
<script type="module">
    import './app/index.jsx';
    import './index.js';
</script>
</body>
</html>
                    `,
        '/src/test.ts': `
import { add } from './cc';

const App = () => {
    console.log(add(1, 2));
};

export default App;
`,
        '/src/cc.ts': `
export function add(a, b) {
    return a + b;
}

export function minus(a, b) {
    return a - b;
}
`
    }
    return (
        <div style={{ width: '800px', height: '600px' }}>
            <MultiEditor 
                defaultFiles={defaultFiles}
                options={{
                    fontSize: 14,
                    automaticLayout: true,
                }} />
        </div>
    )
}

export default IDE;

单文件编辑器

import { SingleEditor } from 'react-monaco-editor-lite';
import React, { useState } from 'react';

function SingleIDE() {
    const [loc] = useState({
        start: {
            line: 3,
            column: 1
        },
        end: {
            line: 4,
            column: 1
        }
    });
    const [value, setValue] = useState(`
export function add(a, b) {
    return a + b;
}

export function minus(a, b) {
    return a - b;
}
    `);
    const onChange = (v) => {
        setValue(v);
    }

    return (
        <div style={{
            width: '800px',
            height: '800px',
        }}>
            <SingleEditor
                value={value}
                onChange={onChange}
                loc={loc}
                options={{
                }} />
        </div>
    )
};

export default SingleIDE;

搜索文件

快捷键:command/ctrl + p

搜索文本

快捷键:shift + command/ctrl + f

类型提示声明

MultiEditor 新增属性 extraLibs 配置额外的类型提示配置

文件/目录右键菜单功能

MultiEditor 新增属性 useFileMenu 用于是否启用文件/目录右键菜单功能

组件参数及方法

查看此文档

1.3.7

10 days ago

1.3.6

10 days ago

1.3.5

11 days ago

1.3.4

11 days ago

1.3.3

21 days ago

1.3.2

1 month ago

1.3.1

2 months ago

1.3.0

2 months ago

1.2.4

3 months ago

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

8 months ago

1.2.0

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.69-beta.0

2 years ago

1.0.69-beta.2

2 years ago

1.0.69-beta.1

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.63

2 years ago

1.0.59

2 years ago

1.0.69

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.67

2 years ago

1.0.56

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago