|
1 | 1 | <h1 align="center">dt-react-monaco-editor</h1> |
2 | | -<h2 align="center"> |
| 2 | + |
| 3 | +<div align="center"> |
3 | 4 |
|
4 | 5 | [Monaco Editor](https://github.com/Microsoft/monaco-editor) React Components |
5 | 6 |
|
6 | | -</h2> |
| 7 | +[![NPM version][npm-image]][npm-url] [![NPM downloads][download-img]][download-url] |
| 8 | + |
| 9 | +[npm-image]: https://img.shields.io/npm/v/dt-react-monaco-editor.svg?style=flat-square |
| 10 | +[npm-url]: https://www.npmjs.com/package/dt-react-monaco-editor |
| 11 | +[download-img]: https://img.shields.io/npm/dm/dt-react-monaco-editor.svg?style=flat |
| 12 | +[download-url]: https://www.npmjs.com/package/dt-react-monaco-editor |
| 13 | + |
| 14 | +</div> |
7 | 15 |
|
8 | 16 | ## Introduction |
| 17 | + |
9 | 18 | Provides `MonacoEditor` and `MonacoDiffEditor` component, make it easier to use Monaco Editor in React. |
| 19 | + |
| 20 | +<br/> |
| 21 | + |
10 | 22 | ## Installation |
| 23 | + |
11 | 24 | use npm |
| 25 | + |
12 | 26 | ```bash |
13 | 27 | npm install dt-react-monaco-editor |
14 | 28 | ``` |
| 29 | + |
15 | 30 | or use yarn |
| 31 | + |
16 | 32 | ```bash |
17 | 33 | yarn add dt-react-monaco-editor |
18 | 34 | ``` |
| 35 | + |
19 | 36 | or use pnpm |
| 37 | + |
20 | 38 | ``` |
21 | 39 | pnpm install dt-react-monaco-editor |
22 | 40 | ``` |
23 | 41 |
|
| 42 | +<br/> |
| 43 | + |
24 | 44 | ## Integrating |
| 45 | + |
25 | 46 | See [Monaco Editor integrate Docs](https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md). |
26 | 47 |
|
| 48 | +<br/> |
| 49 | + |
27 | 50 | ## Usage |
| 51 | + |
28 | 52 | ### MonacoEditor Component |
| 53 | + |
29 | 54 | ```jsx |
30 | 55 | import { MonacoEditor } from 'dt-react-monaco-editor'; |
31 | 56 |
|
32 | | -function App () { |
33 | | - const editorRef = useRef(); |
34 | | - return( |
35 | | - <MonacoEditor |
36 | | - value='' |
37 | | - language='javascript' |
38 | | - style={{ height: 400, width: 600 }} |
39 | | - onChange={(value) => { console.log(value) }} |
40 | | - editorInstanceRef={ins => editorRef.current = ins} |
41 | | - /> |
42 | | - ) |
| 57 | +function App() { |
| 58 | + const editorRef = useRef(); |
| 59 | + return ( |
| 60 | + <MonacoEditor |
| 61 | + value="" |
| 62 | + language="javascript" |
| 63 | + style={{ height: 400, width: 600 }} |
| 64 | + onChange={(value) => { |
| 65 | + console.log(value); |
| 66 | + }} |
| 67 | + editorInstanceRef={(ins) => (editorRef.current = ins)} |
| 68 | + /> |
| 69 | + ); |
43 | 70 | } |
44 | 71 | ``` |
45 | 72 |
|
46 | 73 | ### MonacoDiffEditor Component |
| 74 | + |
47 | 75 | ```jsx |
48 | 76 | import { MonacoDiffEditor } from 'dt-react-monaco-editor'; |
49 | 77 |
|
50 | | -function App () { |
51 | | - const editorRef = useRef(); |
52 | | - return( |
53 | | - <MonacoDiffEditor |
54 | | - original='const a = 1;' |
55 | | - value='const a = 2;' |
56 | | - language='sql' |
57 | | - style={{ height: 400, width: 1200 }} |
58 | | - onChange={(value) => { console.log(value) }} |
59 | | - diffEditorInstanceRef={ins => editorRef.current = ins} |
60 | | - /> |
61 | | - ) |
| 78 | +function App() { |
| 79 | + const editorRef = useRef(); |
| 80 | + return ( |
| 81 | + <MonacoDiffEditor |
| 82 | + original="const a = 1;" |
| 83 | + value="const a = 2;" |
| 84 | + language="sql" |
| 85 | + style={{ height: 400, width: 1200 }} |
| 86 | + onChange={(value) => { |
| 87 | + console.log(value); |
| 88 | + }} |
| 89 | + diffEditorInstanceRef={(ins) => (editorRef.current = ins)} |
| 90 | + /> |
| 91 | + ); |
62 | 92 | } |
63 | 93 | ``` |
64 | 94 |
|
| 95 | +<br/> |
| 96 | + |
65 | 97 | ## Properties |
| 98 | + |
66 | 99 | ### Common Properties |
67 | | -common properties can be used on MonacoEditor and MonacoDiffEditor. |
68 | | -+ `theme` theme used when the editor renders, defaults to `vs`. |
69 | | -+ `language` language of model in editor, defaults to `sql`. |
70 | | -+ `sync` sync value to model when value change, if sync property is true, the editor is controlled. |
71 | | -+ `onChange` an event emitted when the value of the editor model has changed. |
| 100 | + |
| 101 | +common properties can be used on `MonacoEditor` and `MonacoDiffEditor`. |
| 102 | + |
| 103 | +- `theme` theme used when the editor renders, defaults to `vs`. |
| 104 | +- `language` language of model in editor, defaults to `sql`. |
| 105 | +- `sync` sync value to model when value change, if sync property is true, the editor is controlled. |
| 106 | +- `onChange` an event emitted when the value of the editor model has changed. |
72 | 107 |
|
73 | 108 | ### MonacoEditor Own Properties |
74 | | -+ `value` value of model in editor. |
75 | | -+ `options` options for monaco editor, refer to monaco interface [IStandaloneEditorConstructionOptions](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html). |
76 | | -+ `editorInstanceRef` get editor instance. |
77 | | -+ `onCursorSelection` an event emitted when the selection of the editor model has changed. |
78 | | -+ `onFocus` an event emitted when the editor is in focus. |
79 | | -+ `onBlur` an event emitted when the editor is out of focus. |
| 109 | + |
| 110 | +- `value` value of model in editor. |
| 111 | +- `options` options for monaco editor, refer to monaco interface [IStandaloneEditorConstructionOptions](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html). |
| 112 | +- **[deprecated]** `editorInstanceRef` get editor instance. |
| 113 | +- `onCursorSelection` an event emitted when the selection of the editor model has changed. |
| 114 | +- `onFocus` an event emitted when the editor is in focus. |
| 115 | +- `onBlur` an event emitted when the editor is out of focus. |
| 116 | +- `editorWillMount` called immediately before the editor is mounted (similar to componentWillMount of React). |
| 117 | +- `editorDidMount` called immediately after the editor is mounted (similar to componentDidMount of React). |
| 118 | +- `editorWillUnMount` called immediately before the editor is destroyed (similar to componentWillUnmount of React). |
80 | 119 |
|
81 | 120 | ### MonacoDiffEditor Own Properties |
82 | | -+ `value` value of model in modifiedEditor. |
83 | | -+ `original` value of model in originalEditor. |
84 | | -+ `options` options for monaco diff editor, refer to monaco interface [IStandaloneDiffEditorConstructionOptions](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneDiffEditorConstructionOptions.html). |
85 | | -+ `diffEditorInstanceRef` get diff editor instance. |
86 | | -+ `readOnly` set modified editor readonly. |
| 121 | + |
| 122 | +- `value` value of model in modifiedEditor. |
| 123 | +- `original` value of model in originalEditor. |
| 124 | +- `options` options for monaco diff editor, refer to monaco interface [IStandaloneDiffEditorConstructionOptions](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneDiffEditorConstructionOptions.html). |
| 125 | +- `readOnly` set modified editor readonly. |
| 126 | +- **[deprecated]** `diffEditorInstanceRef` get diff editor instance. |
| 127 | +- `editorWillMount` called immediately before the editor is mounted (similar to componentWillMount of React). |
| 128 | +- `editorDidMount` called immediately after the editor is mounted (similar to componentDidMount of React). |
| 129 | +- `editorWillUnMount` called immediately before the editor is destroyed (similar to componentWillUnmount of React). |
| 130 | + |
| 131 | +<br/> |
87 | 132 |
|
88 | 133 | ## Support more sql languages |
| 134 | + |
89 | 135 | Please See [monaco-sql-languages](https://github.com/DTStack/monaco-sql-languages). |
90 | 136 |
|
91 | 137 | `monaco-sql-languages` provides **highlighting**, **error prompts** and **auto-completion** functions for many kinds of SQL Languages for BigData domain. |
|
0 commit comments