1 | import * as React from "react";
|
2 | import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
|
3 |
|
4 | export type ChangeHandler = (
|
5 | value: string,
|
6 | event: monacoEditor.editor.IModelContentChangedEvent
|
7 | ) => void;
|
8 |
|
9 | export type EditorDidMount = (
|
10 | editor: monacoEditor.editor.IStandaloneCodeEditor,
|
11 | monaco: typeof monacoEditor
|
12 | ) => void;
|
13 |
|
14 | /**
|
15 | * @remarks
|
16 | * This will be `IStandaloneEditorConstructionOptions` in newer versions of monaco-editor, or
|
17 | * `IEditorConstructionOptions` in versions before that was introduced.
|
18 | */
|
19 | export type EditorConstructionOptions = NonNullable<Parameters<typeof monacoEditor.editor.create>[1]>;
|
20 |
|
21 | export type EditorWillMount = (monaco: typeof monacoEditor) => void | EditorConstructionOptions;
|
22 |
|
23 | declare interface MonacoEditorBaseProps {
|
24 | /**
|
25 | * Width of editor. Defaults to 100%.
|
26 | */
|
27 | width?: string | number;
|
28 |
|
29 | /**
|
30 | * Height of editor. Defaults to 500.
|
31 | */
|
32 | height?: string | number;
|
33 |
|
34 | /**
|
35 | * The initial value of the auto created model in the editor.
|
36 | */
|
37 | defaultValue?: string;
|
38 |
|
39 | /**
|
40 | * The initial language of the auto created model in the editor. Defaults to 'javascript'.
|
41 | */
|
42 | language?: string;
|
43 |
|
44 | /**
|
45 | * Theme to be used for rendering.
|
46 | * The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'.
|
47 | * You can create custom themes via `monaco.editor.defineTheme`.
|
48 | */
|
49 | theme?: string | null;
|
50 |
|
51 | /**
|
52 | * Optional, allow to pass a different context then the global window onto which the monaco instance will be loaded. Useful if you want to load the editor in an iframe.
|
53 | */
|
54 | context?: any;
|
55 | }
|
56 |
|
57 | export interface MonacoEditorProps extends MonacoEditorBaseProps {
|
58 | /**
|
59 | * Value of the auto created model in the editor.
|
60 | * If you specify `null` or `undefined` for this property, the component behaves in uncontrolled mode.
|
61 | * Otherwise, it behaves in controlled mode.
|
62 | */
|
63 | value?: string | null;
|
64 |
|
65 | /**
|
66 | * Refer to Monaco interface {monaco.editor.IEditorConstructionOptions}.
|
67 | */
|
68 | options?: monacoEditor.editor.IEditorConstructionOptions;
|
69 |
|
70 |
|
71 | /**
|
72 | * Refer to Monaco interface {monaco.editor.IEditorOverrideServices}.
|
73 | */
|
74 | overrideServices?: monacoEditor.editor.IEditorOverrideServices;
|
75 |
|
76 | /**
|
77 | * An event emitted when the editor has been mounted (similar to componentDidMount of React).
|
78 | */
|
79 | editorDidMount?: EditorDidMount;
|
80 |
|
81 | /**
|
82 | * An event emitted before the editor mounted (similar to componentWillMount of React).
|
83 | */
|
84 | editorWillMount?: EditorWillMount;
|
85 |
|
86 | /**
|
87 | * An event emitted when the content of the current model has changed.
|
88 | */
|
89 | onChange?: ChangeHandler;
|
90 | }
|
91 |
|
92 | export default class MonacoEditor extends React.Component<MonacoEditorProps> {
|
93 | editor?: monacoEditor.editor.IStandaloneCodeEditor;
|
94 | }
|
95 |
|
96 | // ============ Diff Editor ============
|
97 |
|
98 | export type DiffEditorDidMount = (
|
99 | editor: monacoEditor.editor.IStandaloneDiffEditor,
|
100 | monaco: typeof monacoEditor
|
101 | ) => void;
|
102 |
|
103 | export type DiffEditorWillMount = (monaco: typeof monacoEditor) => void;
|
104 |
|
105 | export type DiffChangeHandler = ChangeHandler;
|
106 |
|
107 | export interface MonacoDiffEditorProps extends MonacoEditorBaseProps {
|
108 | /**
|
109 | * The original value to compare against.
|
110 | */
|
111 | original?: string;
|
112 |
|
113 | /**
|
114 | * Value of the auto created model in the editor.
|
115 | * If you specify value property, the component behaves in controlled mode. Otherwise, it behaves in uncontrolled mode.
|
116 | */
|
117 | value?: string;
|
118 |
|
119 | /**
|
120 | * Refer to Monaco interface {monaco.editor.IDiffEditorConstructionOptions}.
|
121 | */
|
122 | options?: monacoEditor.editor.IDiffEditorConstructionOptions;
|
123 |
|
124 | /**
|
125 | * Refer to Monaco interface {monaco.editor.IEditorOverrideServices}.
|
126 | */
|
127 | overrideServices?: monacoEditor.editor.IEditorOverrideServices;
|
128 |
|
129 | /**
|
130 | * An event emitted when the editor has been mounted (similar to componentDidMount of React).
|
131 | */
|
132 | editorDidMount?: DiffEditorDidMount;
|
133 |
|
134 | /**
|
135 | * An event emitted before the editor mounted (similar to componentWillMount of React).
|
136 | */
|
137 | editorWillMount?: DiffEditorWillMount;
|
138 |
|
139 | /**
|
140 | * An event emitted when the content of the current model has changed.
|
141 | */
|
142 | onChange?: DiffChangeHandler;
|
143 | }
|
144 |
|
145 | export class MonacoDiffEditor extends React.Component<MonacoDiffEditorProps> {
|
146 | editor?: monacoEditor.editor.IStandaloneDiffEditor;
|
147 | }
|