@typefox/monaco-editor-react 7.2.0 → 7.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +126 -81
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +136 -88
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to npm module [@typefox/monaco-editor-react](https://www.npmjs.com/package/@typefox/monaco-editor-react) are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [7.3.0-next.1] - 2025-11-05
|
|
6
|
+
|
|
7
|
+
- Fixed re-rendering issues with React StrictMode [#986](https://github.com/TypeFox/monaco-languageclient/pull/986).
|
|
8
|
+
- Updated to `monaco-languageclient@10.3.0-next.1`.
|
|
9
|
+
- Updated all `@codingame/monaco-vscode` packages to `22.1.4`.
|
|
10
|
+
|
|
5
11
|
## [7.2.0] - 2025-10-20
|
|
6
12
|
|
|
7
13
|
- Updated to `monaco-languageclient@10.2.0`.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorApp, type EditorAppConfig, type TextContents } from 'monaco-languageclient/editorApp';
|
|
2
|
-
import { type LanguageClientConfig,
|
|
2
|
+
import { type LanguageClientConfig, LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
3
3
|
import { type MonacoVscodeApiConfig, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
4
4
|
import React, { type CSSProperties } from 'react';
|
|
5
5
|
export type ResolveFc = (value: void | PromiseLike<void>) => void;
|
|
@@ -9,9 +9,10 @@ export type MonacoEditorProps = {
|
|
|
9
9
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
10
10
|
editorAppConfig?: EditorAppConfig;
|
|
11
11
|
languageClientConfig?: LanguageClientConfig;
|
|
12
|
+
enforceDisposeLanguageClient?: boolean;
|
|
12
13
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
13
14
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
14
|
-
onLanguageClientsStartDone?: (lcsManager?:
|
|
15
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientManager) => void;
|
|
15
16
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
16
17
|
onError?: (error: Error) => void;
|
|
17
18
|
onDisposeEditor?: () => void;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,KAAK,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,KAAK,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAgC,KAAK,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAqB,MAAM,OAAO,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,qBAAqB,CAAC;IACvC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,mBAAmB,CAAC,EAAE,CAAC,sBAAsB,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC/E,iBAAiB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACpD,0BAA0B,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC1E,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAA;AAaD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAkQ7D,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,42 +3,62 @@
|
|
|
3
3
|
* Licensed under the MIT License. See LICENSE in the package root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
import { EditorApp } from 'monaco-languageclient/editorApp';
|
|
6
|
-
import {
|
|
6
|
+
import { LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
7
7
|
import { getEnhancedMonacoEnvironment, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
8
|
-
import React, { useEffect, useRef
|
|
8
|
+
import React, { useEffect, useRef } from 'react';
|
|
9
|
+
// All must be outside of the component as they ars valid across all instances and should not be re-created
|
|
10
|
+
let apiWrapper;
|
|
11
|
+
const lcsManager = new LanguageClientManager();
|
|
12
|
+
const haveEditorService = () => {
|
|
13
|
+
return apiWrapper?.getMonacoVscodeApiConfig().viewsConfig.$type === 'EditorService';
|
|
14
|
+
};
|
|
15
|
+
const runQueue = [];
|
|
16
|
+
let queueAwait = undefined;
|
|
17
|
+
let queueResolve = undefined;
|
|
9
18
|
export const MonacoEditorReactComp = (props) => {
|
|
10
|
-
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const editorAppRef = useRef(null);
|
|
14
|
-
const lcsManagerRef = useRef(null);
|
|
19
|
+
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, enforceDisposeLanguageClient, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
20
|
+
const currentEditorConfig = useRef(undefined);
|
|
21
|
+
const editorAppRef = useRef(undefined);
|
|
15
22
|
const containerRef = useRef(null);
|
|
16
23
|
const onTextChangedRef = useRef(onTextChanged);
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const executeQueue = (id, newfunc) => {
|
|
24
|
+
const modifiedCode = useRef(modifiedTextValue);
|
|
25
|
+
const originalCode = useRef(originalTextValue);
|
|
26
|
+
const addQueue = (id, func) => {
|
|
21
27
|
debugLogging(`Adding to queue: ${id}`);
|
|
22
|
-
debugLogging(`QUEUE SIZE before: ${runQueue.
|
|
23
|
-
runQueue.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.length}`);
|
|
29
|
+
runQueue.push({ id, func });
|
|
30
|
+
};
|
|
31
|
+
const triggerQueue = () => {
|
|
32
|
+
setInterval(() => {
|
|
33
|
+
if (queueAwait === undefined) {
|
|
34
|
+
queueAwait = new Promise((resolve) => {
|
|
35
|
+
queueResolve = resolve;
|
|
36
|
+
});
|
|
37
|
+
executeQueue();
|
|
38
|
+
}
|
|
39
|
+
}, 50);
|
|
40
|
+
};
|
|
41
|
+
const executeQueue = async () => {
|
|
42
|
+
while (runQueue.length > 0) {
|
|
43
|
+
const queueObj = runQueue.shift();
|
|
44
|
+
if (queueObj !== undefined) {
|
|
45
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE before: ${runQueue.length}`);
|
|
46
|
+
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
47
|
+
await queueObj.func();
|
|
48
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.length}`);
|
|
49
|
+
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
}
|
|
52
|
+
queueResolve?.();
|
|
53
|
+
queueAwait = undefined;
|
|
54
|
+
queueResolve = undefined;
|
|
35
55
|
};
|
|
36
56
|
const debugLogging = (id, useTime) => {
|
|
37
57
|
if (useTime === true) {
|
|
38
|
-
|
|
58
|
+
apiWrapper?.getLogger().debug(`${id}: ${Date.now()}`);
|
|
39
59
|
}
|
|
40
60
|
else {
|
|
41
|
-
|
|
61
|
+
apiWrapper?.getLogger().debug(id);
|
|
42
62
|
}
|
|
43
63
|
};
|
|
44
64
|
const performErrorHandling = (error) => {
|
|
@@ -51,23 +71,18 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
51
71
|
};
|
|
52
72
|
useEffect(() => {
|
|
53
73
|
// this is only available if EditorService is configured
|
|
54
|
-
if (modifiedTextValue !== undefined
|
|
55
|
-
|
|
74
|
+
if (haveEditorService() && modifiedTextValue !== undefined) {
|
|
75
|
+
modifiedCode.current = modifiedTextValue;
|
|
56
76
|
editorAppRef.current?.updateCode({ modified: modifiedTextValue });
|
|
57
77
|
}
|
|
58
78
|
}, [modifiedTextValue]);
|
|
59
79
|
useEffect(() => {
|
|
60
80
|
// this is only available if EditorService is configured
|
|
61
|
-
if (originalTextValue !== undefined
|
|
62
|
-
|
|
81
|
+
if (haveEditorService() && originalTextValue !== undefined) {
|
|
82
|
+
originalCode.current = originalTextValue;
|
|
63
83
|
editorAppRef.current?.updateCode({ original: originalTextValue });
|
|
64
84
|
}
|
|
65
85
|
}, [originalTextValue]);
|
|
66
|
-
const awaitGlobal = async () => {
|
|
67
|
-
// await global init if not completed before doing anything else
|
|
68
|
-
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
69
|
-
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
70
|
-
};
|
|
71
86
|
const performGlobalInit = async () => {
|
|
72
87
|
if (containerRef.current === null) {
|
|
73
88
|
performErrorHandling(new Error('No htmlContainer found! Aborting...'));
|
|
@@ -75,29 +90,51 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
75
90
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
76
91
|
// init will only performed once
|
|
77
92
|
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
93
|
+
apiWrapper = new MonacoVscodeApiWrapper(vscodeApiConfig);
|
|
78
94
|
const globalInitFunc = async () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
try {
|
|
96
|
+
debugLogging('GLOBAL INIT', true);
|
|
97
|
+
if (apiWrapper === undefined)
|
|
98
|
+
throw new Error('Unexpected error occurred: apiWrapper is not available! Aborting...');
|
|
99
|
+
if (haveEditorService()) {
|
|
100
|
+
apiWrapper.overrideViewsConfig({
|
|
101
|
+
$type: 'EditorService',
|
|
102
|
+
htmlContainer: containerRef.current
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
await apiWrapper.start();
|
|
106
|
+
lcsManager.setLogger(apiWrapper.getLogger());
|
|
107
|
+
onVscodeApiInitDone?.(apiWrapper);
|
|
108
|
+
triggerQueue();
|
|
109
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
performErrorHandling(error);
|
|
113
|
+
}
|
|
89
114
|
};
|
|
90
115
|
globalInitFunc();
|
|
91
116
|
}
|
|
117
|
+
else if (envEnhanced.vscodeApiInitialised === true) {
|
|
118
|
+
triggerQueue();
|
|
119
|
+
}
|
|
92
120
|
};
|
|
93
121
|
useEffect(() => {
|
|
122
|
+
// fast-fail
|
|
123
|
+
if (editorAppConfig === undefined)
|
|
124
|
+
return;
|
|
94
125
|
// always try to perform global init. Reason: we cannot ensure order
|
|
95
126
|
performGlobalInit();
|
|
127
|
+
// re-create editor if config changed
|
|
128
|
+
const recreateEditor = editorAppRef.current === undefined || currentEditorConfig.current === undefined ||
|
|
129
|
+
JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
96
130
|
const editorInitFunc = async () => {
|
|
97
131
|
try {
|
|
98
132
|
debugLogging('INIT', true);
|
|
99
133
|
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
100
|
-
if (haveEditorService
|
|
134
|
+
if (recreateEditor && haveEditorService()) {
|
|
135
|
+
debugLogging('INIT: Creating editor', true);
|
|
136
|
+
editorAppRef.current?.dispose();
|
|
137
|
+
currentEditorConfig.current = editorAppConfig;
|
|
101
138
|
editorAppRef.current = new EditorApp(editorAppConfig);
|
|
102
139
|
if (editorAppRef.current.isStarting() === true || editorAppRef.current.isDisposing() === true) {
|
|
103
140
|
await Promise.all([
|
|
@@ -107,10 +144,10 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
107
144
|
}
|
|
108
145
|
editorAppRef.current.registerOnTextChangedCallback((textChanges) => {
|
|
109
146
|
if (textChanges.modified !== undefined) {
|
|
110
|
-
|
|
147
|
+
modifiedCode.current = textChanges.modified;
|
|
111
148
|
}
|
|
112
149
|
if (textChanges.original !== undefined) {
|
|
113
|
-
|
|
150
|
+
originalCode.current = textChanges.original;
|
|
114
151
|
}
|
|
115
152
|
if (onTextChangedRef.current !== undefined) {
|
|
116
153
|
onTextChangedRef.current(textChanges);
|
|
@@ -118,11 +155,6 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
118
155
|
});
|
|
119
156
|
await editorAppRef.current.start(containerRef.current);
|
|
120
157
|
onEditorStartDone?.(editorAppRef.current);
|
|
121
|
-
// originalTextValue and modifiedTextValue useEffects may happen before
|
|
122
|
-
editorAppRef.current.updateCode({
|
|
123
|
-
original: originalCode,
|
|
124
|
-
modified: modifiedCode
|
|
125
|
-
});
|
|
126
158
|
}
|
|
127
159
|
debugLogging('INIT DONE', true);
|
|
128
160
|
}
|
|
@@ -130,52 +162,65 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
130
162
|
performErrorHandling(error);
|
|
131
163
|
}
|
|
132
164
|
};
|
|
133
|
-
|
|
165
|
+
addQueue('editorInit', editorInitFunc);
|
|
134
166
|
}, [editorAppConfig]);
|
|
135
167
|
useEffect(() => {
|
|
168
|
+
// fast-fail
|
|
169
|
+
if (languageClientConfig === undefined)
|
|
170
|
+
return;
|
|
136
171
|
// always try to perform global init. Reason: we cannot ensure order
|
|
137
172
|
performGlobalInit();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
executeQueue('lcInit', lcInitFunc);
|
|
153
|
-
}
|
|
173
|
+
const lcInitFunc = async () => {
|
|
174
|
+
try {
|
|
175
|
+
debugLogging('INIT LC2', true);
|
|
176
|
+
await lcsManager.setConfig(languageClientConfig);
|
|
177
|
+
await lcsManager.start();
|
|
178
|
+
onLanguageClientsStartDone?.(lcsManager);
|
|
179
|
+
debugLogging('INIT LC DONE', true);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
performErrorHandling(error);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
addQueue('lcInit', lcInitFunc);
|
|
154
186
|
}, [languageClientConfig]);
|
|
155
187
|
useEffect(() => {
|
|
188
|
+
// this part runs on mount (componentDidMount)
|
|
156
189
|
// always try to perform global init. Reason: we cannot ensure order
|
|
157
190
|
performGlobalInit();
|
|
191
|
+
// this part runs on unmount (componentWillUnmount)
|
|
158
192
|
return () => {
|
|
159
193
|
const disposeFunc = async () => {
|
|
160
|
-
// dispose editor
|
|
194
|
+
// dispose editor if used
|
|
195
|
+
debugLogging('DISPOSE', true);
|
|
196
|
+
await editorAppRef.current?.dispose();
|
|
197
|
+
editorAppRef.current = undefined;
|
|
198
|
+
onDisposeEditor?.();
|
|
199
|
+
debugLogging('DISPOSE DONE', true);
|
|
200
|
+
};
|
|
201
|
+
addQueue('dispose', disposeFunc);
|
|
202
|
+
};
|
|
203
|
+
}, []);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
206
|
+
performGlobalInit();
|
|
207
|
+
if (enforceDisposeLanguageClient === true) {
|
|
208
|
+
const disposeLCFunc = async () => {
|
|
209
|
+
// dispose editor if used
|
|
161
210
|
try {
|
|
162
|
-
debugLogging('DISPOSE', true);
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
lcsManagerRef.current?.dispose();
|
|
167
|
-
onDisposeLanguageClient?.();
|
|
168
|
-
}
|
|
169
|
-
debugLogging('DISPOSE DONE', true);
|
|
211
|
+
debugLogging('DISPOSE LC', true);
|
|
212
|
+
await lcsManager.dispose();
|
|
213
|
+
onDisposeLanguageClient?.();
|
|
214
|
+
debugLogging('DISPOSE LC DONE', true);
|
|
170
215
|
}
|
|
171
216
|
catch (error) {
|
|
172
217
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
173
218
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
174
219
|
}
|
|
175
220
|
};
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}, []);
|
|
221
|
+
addQueue('dispose lc', disposeLCFunc);
|
|
222
|
+
}
|
|
223
|
+
}, [enforceDisposeLanguageClient]);
|
|
179
224
|
return (React.createElement("div", { ref: containerRef, style: style, className: className }));
|
|
180
225
|
};
|
|
181
226
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAA2C,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAA6B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAA2C,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAA6B,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,4BAA4B,EAA8B,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAsB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAsBrE,2GAA2G;AAC3G,IAAI,UAA8C,CAAC;AACnD,MAAM,UAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAC/C,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC;IAC5B,OAAO,UAAU,EAAE,wBAAwB,EAAE,CAAC,WAAW,CAAC,KAAK,KAAK,eAAe,CAAC;AAAA,CACvF,CAAC;AAEF,MAAM,QAAQ,GAAmD,EAAE,CAAC;AACpE,IAAI,UAAU,GAA8B,SAAS,CAAC;AACtD,IAAI,YAAY,GAA4D,SAAS,CAAC;AAEtF,MAAM,CAAC,MAAM,qBAAqB,GAAgC,CAAC,KAAK,EAAE,EAAE,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C,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE,CAAC;QACZ,oEAAoE;QACpE,iBAAiB,EAAE,CAAC;QAEpB,IAAI,4BAA4B,KAAK,IAAI,EAAE,CAAC;YACxC,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE,CAAC;gBAC9B,yBAAyB;gBACzB,IAAI,CAAC;oBACD,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;oBAEjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;oBAC3B,uBAAuB,EAAE,EAAE,CAAC;oBAE5B,YAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;gBAC1C,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,yFAAyF;oBACzF,oBAAoB,CAAC,IAAI,KAAK,CAAC,qEAAqE,KAAK,EAAE,CAAC,CAAC,CAAC;gBAClH,CAAC;YAAA,CACJ,CAAC;YACF,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAC1C,CAAC;IAAA,CACJ,EAAE,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAEnC,OAAO,CACH,6BACI,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,GACtB,CACL,CAAC;AAAA,CACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typefox/monaco-editor-react",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React component for Monaco-Editor and Monaco Languageclient",
|
|
6
6
|
"keywords": [
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"npm": "10.9.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@codingame/monaco-vscode-editor-api": "^22.1.
|
|
49
|
+
"@codingame/monaco-vscode-editor-api": "^22.1.4",
|
|
50
50
|
"react": ">=18.0.0 || <20.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
package/src/index.tsx
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
|
|
6
6
|
import { EditorApp, type EditorAppConfig, type TextContents } from 'monaco-languageclient/editorApp';
|
|
7
|
-
import { type LanguageClientConfig,
|
|
7
|
+
import { type LanguageClientConfig, LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
8
8
|
import { getEnhancedMonacoEnvironment, type MonacoVscodeApiConfig, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
9
|
-
import React, { type CSSProperties, useEffect, useRef
|
|
9
|
+
import React, { type CSSProperties, useEffect, useRef } from 'react';
|
|
10
10
|
|
|
11
11
|
export type ResolveFc = (value: void | PromiseLike<void>) => void;
|
|
12
12
|
|
|
@@ -16,9 +16,10 @@ export type MonacoEditorProps = {
|
|
|
16
16
|
vscodeApiConfig: MonacoVscodeApiConfig;
|
|
17
17
|
editorAppConfig?: EditorAppConfig;
|
|
18
18
|
languageClientConfig?: LanguageClientConfig;
|
|
19
|
+
enforceDisposeLanguageClient?: boolean;
|
|
19
20
|
onVscodeApiInitDone?: (monacoVscodeApiManager: MonacoVscodeApiWrapper) => void;
|
|
20
21
|
onEditorStartDone?: (editorApp?: EditorApp) => void;
|
|
21
|
-
onLanguageClientsStartDone?: (lcsManager?:
|
|
22
|
+
onLanguageClientsStartDone?: (lcsManager?: LanguageClientManager) => void;
|
|
22
23
|
onTextChanged?: (textChanges: TextContents) => void;
|
|
23
24
|
onError?: (error: Error) => void;
|
|
24
25
|
onDisposeEditor?: () => void;
|
|
@@ -27,6 +28,17 @@ export type MonacoEditorProps = {
|
|
|
27
28
|
originalTextValue?: string;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
// All must be outside of the component as they ars valid across all instances and should not be re-created
|
|
32
|
+
let apiWrapper: MonacoVscodeApiWrapper | undefined;
|
|
33
|
+
const lcsManager = new LanguageClientManager();
|
|
34
|
+
const haveEditorService = () => {
|
|
35
|
+
return apiWrapper?.getMonacoVscodeApiConfig().viewsConfig.$type === 'EditorService';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const runQueue: Array<{id: string, func: () => Promise<void>}> = [];
|
|
39
|
+
let queueAwait: Promise<void> | undefined = undefined;
|
|
40
|
+
let queueResolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined;
|
|
41
|
+
|
|
30
42
|
export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
31
43
|
const {
|
|
32
44
|
style,
|
|
@@ -34,6 +46,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
34
46
|
vscodeApiConfig,
|
|
35
47
|
editorAppConfig,
|
|
36
48
|
languageClientConfig,
|
|
49
|
+
enforceDisposeLanguageClient,
|
|
37
50
|
onVscodeApiInitDone,
|
|
38
51
|
onEditorStartDone,
|
|
39
52
|
onLanguageClientsStartDone,
|
|
@@ -45,40 +58,51 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
45
58
|
originalTextValue
|
|
46
59
|
} = props;
|
|
47
60
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const editorAppRef = useRef<EditorApp>(null);
|
|
51
|
-
const lcsManagerRef = useRef<LanguageClientsManager>(null);
|
|
61
|
+
const currentEditorConfig = useRef<EditorAppConfig | undefined>(undefined);
|
|
62
|
+
const editorAppRef = useRef<EditorApp>(undefined);
|
|
52
63
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
53
64
|
const onTextChangedRef = useRef(onTextChanged);
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const runQueue = useRef<Array<() => Promise<void>>>([]);
|
|
65
|
+
const modifiedCode = useRef<string>(modifiedTextValue);
|
|
66
|
+
const originalCode = useRef<string>(originalTextValue);
|
|
58
67
|
|
|
59
|
-
const
|
|
68
|
+
const addQueue = (id: string, func: () => Promise<void>) => {
|
|
60
69
|
debugLogging(`Adding to queue: ${id}`);
|
|
61
|
-
debugLogging(`QUEUE SIZE before: ${runQueue.
|
|
62
|
-
runQueue.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.length}`);
|
|
71
|
+
runQueue.push({id, func});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const triggerQueue = () => {
|
|
75
|
+
setInterval(() => {
|
|
76
|
+
if (queueAwait === undefined) {
|
|
77
|
+
queueAwait = new Promise<void>((resolve) => {
|
|
78
|
+
queueResolve = resolve;
|
|
79
|
+
});
|
|
80
|
+
executeQueue();
|
|
72
81
|
}
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
}, 50);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const executeQueue = async () => {
|
|
86
|
+
while (runQueue.length > 0) {
|
|
87
|
+
const queueObj = runQueue.shift();
|
|
88
|
+
if (queueObj !== undefined) {
|
|
89
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE before: ${runQueue.length}`);
|
|
90
|
+
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
91
|
+
await queueObj.func();
|
|
92
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.length}`);
|
|
93
|
+
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
queueResolve?.();
|
|
97
|
+
queueAwait = undefined;
|
|
98
|
+
queueResolve = undefined;
|
|
75
99
|
};
|
|
76
100
|
|
|
77
101
|
const debugLogging = (id: string, useTime?: boolean) => {
|
|
78
102
|
if (useTime === true) {
|
|
79
|
-
|
|
103
|
+
apiWrapper?.getLogger().debug(`${id}: ${Date.now()}`);
|
|
80
104
|
} else {
|
|
81
|
-
|
|
105
|
+
apiWrapper?.getLogger().debug(id);
|
|
82
106
|
}
|
|
83
107
|
};
|
|
84
108
|
|
|
@@ -92,26 +116,20 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
92
116
|
|
|
93
117
|
useEffect(() => {
|
|
94
118
|
// this is only available if EditorService is configured
|
|
95
|
-
if (modifiedTextValue !== undefined
|
|
96
|
-
|
|
119
|
+
if (haveEditorService() && modifiedTextValue !== undefined) {
|
|
120
|
+
modifiedCode.current = modifiedTextValue;
|
|
97
121
|
editorAppRef.current?.updateCode({modified: modifiedTextValue});
|
|
98
122
|
}
|
|
99
123
|
}, [modifiedTextValue]);
|
|
100
124
|
|
|
101
125
|
useEffect(() => {
|
|
102
126
|
// this is only available if EditorService is configured
|
|
103
|
-
if (originalTextValue !== undefined
|
|
104
|
-
|
|
127
|
+
if (haveEditorService() && originalTextValue !== undefined) {
|
|
128
|
+
originalCode.current = originalTextValue;
|
|
105
129
|
editorAppRef.current?.updateCode({original: originalTextValue});
|
|
106
130
|
}
|
|
107
131
|
}, [originalTextValue]);
|
|
108
132
|
|
|
109
|
-
const awaitGlobal = async () => {
|
|
110
|
-
// await global init if not completed before doing anything else
|
|
111
|
-
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
112
|
-
return envEnhanced.vscodeApiGlobalInitAwait ?? Promise.resolve();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
133
|
const performGlobalInit = async () => {
|
|
116
134
|
if (containerRef.current === null) {
|
|
117
135
|
performErrorHandling(new Error('No htmlContainer found! Aborting...'));
|
|
@@ -121,36 +139,56 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
121
139
|
// init will only performed once
|
|
122
140
|
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
123
141
|
|
|
142
|
+
apiWrapper = new MonacoVscodeApiWrapper(vscodeApiConfig);
|
|
124
143
|
const globalInitFunc = async () => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
try {
|
|
145
|
+
debugLogging('GLOBAL INIT', true);
|
|
146
|
+
if (apiWrapper === undefined) throw new Error('Unexpected error occurred: apiWrapper is not available! Aborting...');
|
|
147
|
+
|
|
148
|
+
if (haveEditorService()) {
|
|
149
|
+
apiWrapper.overrideViewsConfig({
|
|
150
|
+
$type: 'EditorService',
|
|
151
|
+
htmlContainer: containerRef.current!
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
await apiWrapper.start();
|
|
135
155
|
|
|
136
|
-
|
|
156
|
+
lcsManager.setLogger(apiWrapper.getLogger());
|
|
137
157
|
|
|
138
|
-
|
|
158
|
+
onVscodeApiInitDone?.(apiWrapper);
|
|
159
|
+
triggerQueue();
|
|
160
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
performErrorHandling(error as Error);
|
|
163
|
+
}
|
|
139
164
|
};
|
|
140
165
|
globalInitFunc();
|
|
166
|
+
} else if (envEnhanced.vscodeApiInitialised === true) {
|
|
167
|
+
triggerQueue();
|
|
141
168
|
}
|
|
142
169
|
};
|
|
143
170
|
|
|
144
171
|
useEffect(() => {
|
|
172
|
+
// fast-fail
|
|
173
|
+
if (editorAppConfig === undefined) return;
|
|
174
|
+
|
|
145
175
|
// always try to perform global init. Reason: we cannot ensure order
|
|
146
176
|
performGlobalInit();
|
|
147
177
|
|
|
178
|
+
// re-create editor if config changed
|
|
179
|
+
const recreateEditor = editorAppRef.current === undefined || currentEditorConfig.current === undefined ||
|
|
180
|
+
JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
148
181
|
const editorInitFunc = async () => {
|
|
149
182
|
try {
|
|
150
183
|
debugLogging('INIT', true);
|
|
151
184
|
|
|
152
185
|
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
153
|
-
if (haveEditorService
|
|
186
|
+
if (recreateEditor && haveEditorService()) {
|
|
187
|
+
debugLogging('INIT: Creating editor', true);
|
|
188
|
+
|
|
189
|
+
editorAppRef.current?.dispose();
|
|
190
|
+
|
|
191
|
+
currentEditorConfig.current = editorAppConfig;
|
|
154
192
|
editorAppRef.current = new EditorApp(editorAppConfig);
|
|
155
193
|
if (editorAppRef.current.isStarting() === true || editorAppRef.current.isDisposing() === true) {
|
|
156
194
|
await Promise.all([
|
|
@@ -161,10 +199,10 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
161
199
|
|
|
162
200
|
editorAppRef.current.registerOnTextChangedCallback((textChanges) => {
|
|
163
201
|
if (textChanges.modified !== undefined) {
|
|
164
|
-
|
|
202
|
+
modifiedCode.current = textChanges.modified;
|
|
165
203
|
}
|
|
166
204
|
if (textChanges.original !== undefined) {
|
|
167
|
-
|
|
205
|
+
originalCode.current = textChanges.original;
|
|
168
206
|
}
|
|
169
207
|
if (onTextChangedRef.current !== undefined) {
|
|
170
208
|
onTextChangedRef.current(textChanges);
|
|
@@ -173,12 +211,6 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
173
211
|
await editorAppRef.current.start(containerRef.current!);
|
|
174
212
|
|
|
175
213
|
onEditorStartDone?.(editorAppRef.current);
|
|
176
|
-
|
|
177
|
-
// originalTextValue and modifiedTextValue useEffects may happen before
|
|
178
|
-
editorAppRef.current.updateCode({
|
|
179
|
-
original: originalCode,
|
|
180
|
-
modified: modifiedCode
|
|
181
|
-
});
|
|
182
214
|
}
|
|
183
215
|
|
|
184
216
|
debugLogging('INIT DONE', true);
|
|
@@ -186,61 +218,77 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
186
218
|
performErrorHandling(error as Error);
|
|
187
219
|
}
|
|
188
220
|
};
|
|
189
|
-
|
|
221
|
+
addQueue('editorInit', editorInitFunc);
|
|
190
222
|
}, [editorAppConfig]);
|
|
191
223
|
|
|
192
224
|
useEffect(() => {
|
|
225
|
+
// fast-fail
|
|
226
|
+
if (languageClientConfig === undefined) return;
|
|
227
|
+
|
|
193
228
|
// always try to perform global init. Reason: we cannot ensure order
|
|
194
229
|
performGlobalInit();
|
|
195
230
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
debugLogging('INIT LC', true);
|
|
200
|
-
|
|
201
|
-
lcsManagerRef.current = new LanguageClientsManager(apiWrapperRef.current.getLogger());
|
|
231
|
+
const lcInitFunc = async () => {
|
|
232
|
+
try {
|
|
233
|
+
debugLogging('INIT LC2', true);
|
|
202
234
|
|
|
203
|
-
|
|
204
|
-
|
|
235
|
+
await lcsManager.setConfig(languageClientConfig);
|
|
236
|
+
await lcsManager.start();
|
|
205
237
|
|
|
206
|
-
|
|
238
|
+
onLanguageClientsStartDone?.(lcsManager);
|
|
207
239
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
240
|
+
debugLogging('INIT LC DONE', true);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
performErrorHandling(error as Error);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
addQueue('lcInit', lcInitFunc);
|
|
215
246
|
}, [languageClientConfig]);
|
|
216
247
|
|
|
217
248
|
useEffect(() => {
|
|
249
|
+
// this part runs on mount (componentDidMount)
|
|
250
|
+
|
|
218
251
|
// always try to perform global init. Reason: we cannot ensure order
|
|
219
252
|
performGlobalInit();
|
|
220
253
|
|
|
254
|
+
// this part runs on unmount (componentWillUnmount)
|
|
221
255
|
return () => {
|
|
222
256
|
const disposeFunc = async () => {
|
|
223
|
-
// dispose editor
|
|
224
|
-
|
|
225
|
-
debugLogging('DISPOSE', true);
|
|
257
|
+
// dispose editor if used
|
|
258
|
+
debugLogging('DISPOSE', true);
|
|
226
259
|
|
|
227
|
-
|
|
228
|
-
|
|
260
|
+
await editorAppRef.current?.dispose();
|
|
261
|
+
editorAppRef.current = undefined;
|
|
262
|
+
onDisposeEditor?.();
|
|
229
263
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
264
|
+
debugLogging('DISPOSE DONE', true);
|
|
265
|
+
};
|
|
266
|
+
addQueue('dispose', disposeFunc);
|
|
267
|
+
};
|
|
268
|
+
}, []);
|
|
269
|
+
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
// always try to perform global init. Reason: we cannot ensure order
|
|
272
|
+
performGlobalInit();
|
|
273
|
+
|
|
274
|
+
if (enforceDisposeLanguageClient === true) {
|
|
275
|
+
const disposeLCFunc = async () => {
|
|
276
|
+
// dispose editor if used
|
|
277
|
+
try {
|
|
278
|
+
debugLogging('DISPOSE LC', true);
|
|
279
|
+
|
|
280
|
+
await lcsManager.dispose();
|
|
281
|
+
onDisposeLanguageClient?.();
|
|
234
282
|
|
|
235
|
-
debugLogging('DISPOSE DONE', true);
|
|
283
|
+
debugLogging('DISPOSE LC DONE', true);
|
|
236
284
|
} catch (error) {
|
|
237
285
|
// The language client may throw an error during disposal, but we want to continue anyway
|
|
238
286
|
performErrorHandling(new Error(`Unexpected error occurred during disposal of the language client: ${error}`));
|
|
239
287
|
}
|
|
240
288
|
};
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}, []);
|
|
289
|
+
addQueue('dispose lc', disposeLCFunc);
|
|
290
|
+
}
|
|
291
|
+
}, [enforceDisposeLanguageClient]);
|
|
244
292
|
|
|
245
293
|
return (
|
|
246
294
|
<div
|