1 | import * as monacoEditor from "monaco-editor/esm/vs/editor/editor.api";
|
2 | /**
|
3 | * @remarks
|
4 | * This will be `IStandaloneEditorConstructionOptions` in newer versions of monaco-editor, or
|
5 | * `IEditorConstructionOptions` in versions before that was introduced.
|
6 | */
|
7 | export type EditorConstructionOptions = NonNullable<Parameters<typeof monacoEditor.editor.create>[1]>;
|
8 | export type EditorWillMount = (monaco: typeof monacoEditor) => void | EditorConstructionOptions;
|
9 | export type EditorDidMount = (editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: typeof monacoEditor) => void;
|
10 | export type EditorWillUnmount = (editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: typeof monacoEditor) => void | EditorConstructionOptions;
|
11 | export type ChangeHandler = (value: string, event: monacoEditor.editor.IModelContentChangedEvent) => void;
|
12 | export interface MonacoEditorBaseProps {
|
13 | /**
|
14 | * Width of editor. Defaults to 100%.
|
15 | */
|
16 | width?: string | number;
|
17 | /**
|
18 | * Height of editor. Defaults to 100%.
|
19 | */
|
20 | height?: string | number;
|
21 | /**
|
22 | * The initial value of the auto created model in the editor.
|
23 | */
|
24 | defaultValue?: string;
|
25 | /**
|
26 | * The initial language of the auto created model in the editor. Defaults to 'javascript'.
|
27 | */
|
28 | language?: string;
|
29 | /**
|
30 | * Theme to be used for rendering.
|
31 | * The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'.
|
32 | * You can create custom themes via `monaco.editor.defineTheme`.
|
33 | */
|
34 | theme?: Theme | (string & NonNullable<unknown>) | null;
|
35 | /**
|
36 | * Optional string classname to append to the editor.
|
37 | */
|
38 | className?: string | null;
|
39 | }
|
40 | export interface MonacoEditorProps extends MonacoEditorBaseProps {
|
41 | /**
|
42 | * Value of the auto created model in the editor.
|
43 | * If you specify `null` or `undefined` for this property, the component behaves in uncontrolled mode.
|
44 | * Otherwise, it behaves in controlled mode.
|
45 | */
|
46 | value?: string | null;
|
47 | /**
|
48 | * Refer to Monaco interface {monaco.editor.IStandaloneEditorConstructionOptions}.
|
49 | */
|
50 | options?: monacoEditor.editor.IStandaloneEditorConstructionOptions;
|
51 | /**
|
52 | * Refer to Monaco interface {monaco.editor.IEditorOverrideServices}.
|
53 | */
|
54 | overrideServices?: monacoEditor.editor.IEditorOverrideServices;
|
55 | /**
|
56 | * An event emitted before the editor mounted (similar to componentWillMount of React).
|
57 | */
|
58 | editorWillMount?: EditorWillMount;
|
59 | /**
|
60 | * An event emitted when the editor has been mounted (similar to componentDidMount of React).
|
61 | */
|
62 | editorDidMount?: EditorDidMount;
|
63 | /**
|
64 | * An event emitted before the editor unmount (similar to componentWillUnmount of React).
|
65 | */
|
66 | editorWillUnmount?: EditorWillUnmount;
|
67 | /**
|
68 | * An event emitted when the content of the current model has changed.
|
69 | */
|
70 | onChange?: ChangeHandler;
|
71 | /**
|
72 | * Let the language be inferred from the uri
|
73 | */
|
74 | uri?: (monaco: typeof monacoEditor) => monacoEditor.Uri;
|
75 | }
|
76 | export type DiffEditorWillMount = (monaco: typeof monacoEditor) => void | monacoEditor.editor.IStandaloneEditorConstructionOptions;
|
77 | export type DiffEditorDidMount = (editor: monacoEditor.editor.IStandaloneDiffEditor, monaco: typeof monacoEditor) => void;
|
78 | export type DiffEditorWillUnmount = (editor: monacoEditor.editor.IStandaloneDiffEditor, monaco: typeof monacoEditor) => void;
|
79 | export type DiffChangeHandler = ChangeHandler;
|
80 | export interface MonacoDiffEditorProps extends MonacoEditorBaseProps {
|
81 | /**
|
82 | * The original value to compare against.
|
83 | */
|
84 | original?: string;
|
85 | /**
|
86 | * Value of the auto created model in the editor.
|
87 | * If you specify value property, the component behaves in controlled mode. Otherwise, it behaves in uncontrolled mode.
|
88 | */
|
89 | value?: string;
|
90 | /**
|
91 | * Refer to Monaco interface {monaco.editor.IDiffEditorConstructionOptions}.
|
92 | */
|
93 | options?: monacoEditor.editor.IDiffEditorConstructionOptions;
|
94 | /**
|
95 | * Refer to Monaco interface {monaco.editor.IEditorOverrideServices}.
|
96 | */
|
97 | overrideServices?: monacoEditor.editor.IEditorOverrideServices;
|
98 | /**
|
99 | * An event emitted before the editor mounted (similar to componentWillMount of React).
|
100 | */
|
101 | editorWillMount?: DiffEditorWillMount;
|
102 | /**
|
103 | * An event emitted when the editor has been mounted (similar to componentDidMount of React).
|
104 | */
|
105 | editorDidMount?: DiffEditorDidMount;
|
106 | /**
|
107 | * An event emitted before the editor unmount (similar to componentWillUnmount of React).
|
108 | */
|
109 | editorWillUnmount?: DiffEditorWillUnmount;
|
110 | /**
|
111 | * An event emitted when the content of the current model has changed.
|
112 | */
|
113 | onChange?: DiffChangeHandler;
|
114 | /**
|
115 | * Let the language be inferred from the uri
|
116 | */
|
117 | originalUri?: (monaco: typeof monacoEditor) => monacoEditor.Uri;
|
118 | /**
|
119 | * Let the language be inferred from the uri
|
120 | */
|
121 | modifiedUri?: (monaco: typeof monacoEditor) => monacoEditor.Uri;
|
122 | }
|
123 | export type Theme = "vs" | "vs-dark" | "hc-black";
|