@node-projects/web-component-designer-codeview-monaco 0.1.32 → 0.2.0
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.
|
@@ -3,10 +3,12 @@ import { IActivateable, ICodeView, InstanceServiceContainer, IStringPosition, IU
|
|
|
3
3
|
import type * as monacoType from 'monaco-editor';
|
|
4
4
|
export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend implements ICodeView, IActivateable, IUiCommandHandler {
|
|
5
5
|
#private;
|
|
6
|
-
static
|
|
6
|
+
private static _monaco;
|
|
7
|
+
private static _monacoStyle;
|
|
8
|
+
static getMonacoLib(): Promise<{
|
|
7
9
|
editor: typeof monacoType.editor;
|
|
8
10
|
Range: typeof monacoType.Range;
|
|
9
|
-
}
|
|
11
|
+
}>;
|
|
10
12
|
private _disableSelectionAfterSel;
|
|
11
13
|
dispose(): void;
|
|
12
14
|
canvasElement: HTMLElement;
|
|
@@ -37,9 +39,6 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
|
|
|
37
39
|
static readonly template: HTMLTemplateElement;
|
|
38
40
|
executeCommand(command: IUiCommand): void;
|
|
39
41
|
canExecuteCommand(command: IUiCommand): boolean;
|
|
40
|
-
static loadMonacoEditorViaRequire(path?: string): Promise<void>;
|
|
41
|
-
static loadMonacoEditorViaImport(): Promise<void>;
|
|
42
|
-
static setMonacoLibrary(monaco: any): void;
|
|
43
42
|
constructor();
|
|
44
43
|
ready(): Promise<void>;
|
|
45
44
|
focusEditor(): void;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { BaseCustomWebComponentLazyAppend, css,
|
|
1
|
+
import { BaseCustomWebComponentLazyAppend, css, html, TypedEvent } from '@node-projects/base-custom-webcomponent';
|
|
2
2
|
import { CommandType } from '@node-projects/web-component-designer';
|
|
3
3
|
export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
4
|
-
static
|
|
4
|
+
static _monaco;
|
|
5
|
+
static _monacoStyle;
|
|
6
|
+
static async getMonacoLib() {
|
|
7
|
+
if (CodeViewMonaco._monaco) {
|
|
8
|
+
return CodeViewMonaco._monaco;
|
|
9
|
+
}
|
|
10
|
+
const monaco = await import('monaco-editor');
|
|
11
|
+
CodeViewMonaco._monaco = monaco;
|
|
12
|
+
//@ts-ignore
|
|
13
|
+
CodeViewMonaco._monacoStyle = (await import("monaco-editor/min/vs/editor/editor.main.css", { with: { type: 'css' } })).default;
|
|
14
|
+
return monaco;
|
|
15
|
+
}
|
|
5
16
|
_disableSelectionAfterSel;
|
|
6
17
|
dispose() {
|
|
7
18
|
this._monacoEditor?.dispose();
|
|
@@ -17,9 +28,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
17
28
|
}
|
|
18
29
|
set theme(value) {
|
|
19
30
|
this._theme = value;
|
|
20
|
-
|
|
21
|
-
CodeViewMonaco.monacoLib ??= window.monaco;
|
|
22
|
-
CodeViewMonaco.monacoLib.editor.setTheme(value);
|
|
31
|
+
CodeViewMonaco.getMonacoLib().then(monaco => monaco.editor.setTheme(value));
|
|
23
32
|
}
|
|
24
33
|
#code = null;
|
|
25
34
|
get code() {
|
|
@@ -60,9 +69,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
60
69
|
width: 100%;
|
|
61
70
|
}
|
|
62
71
|
`;
|
|
63
|
-
static template = html
|
|
64
|
-
<div id="container" style="overflow: hidden; width: 100%; height: 100%; position: absolute;"></div>
|
|
65
|
-
`;
|
|
72
|
+
static template = html `<div id="container" style="overflow: hidden; width: 100%; height: 100%; position: absolute;"></div>`;
|
|
66
73
|
executeCommand(command) {
|
|
67
74
|
switch (command.type) {
|
|
68
75
|
case CommandType.undo:
|
|
@@ -95,25 +102,6 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
95
102
|
}
|
|
96
103
|
return false;
|
|
97
104
|
}
|
|
98
|
-
static loadMonacoEditorViaRequire(path = 'node_modules/monaco-editor/min/vs') {
|
|
99
|
-
return new Promise(async (resolve) => {
|
|
100
|
-
//@ts-ignore
|
|
101
|
-
require.config({ paths: { 'vs': path } });
|
|
102
|
-
//@ts-ignore
|
|
103
|
-
require(['vs/editor/editor.main'], () => {
|
|
104
|
-
//@ts-ignore
|
|
105
|
-
CodeViewMonaco.monacoLib = window.monaco;
|
|
106
|
-
resolve();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
static async loadMonacoEditorViaImport() {
|
|
111
|
-
let monaco = await import('monaco-editor');
|
|
112
|
-
CodeViewMonaco.monacoLib = monaco;
|
|
113
|
-
}
|
|
114
|
-
static setMonacoLibrary(monaco) {
|
|
115
|
-
CodeViewMonaco.monacoLib = monaco;
|
|
116
|
-
}
|
|
117
105
|
constructor() {
|
|
118
106
|
super();
|
|
119
107
|
this._restoreCachedInititalValues();
|
|
@@ -121,12 +109,9 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
121
109
|
}
|
|
122
110
|
async ready() {
|
|
123
111
|
this._parseAttributesToProperties();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.shadowRoot.adoptedStyleSheets = [cssFromString(style), this.constructor.style];
|
|
112
|
+
const monaco = await CodeViewMonaco.getMonacoLib();
|
|
113
|
+
this.shadowRoot.adoptedStyleSheets = [CodeViewMonaco._monacoStyle, this.constructor.style];
|
|
127
114
|
this._editor = this._getDomElement('container');
|
|
128
|
-
//@ts-ignore
|
|
129
|
-
CodeViewMonaco.monacoLib ??= window.monaco;
|
|
130
115
|
const resizeObserver = new ResizeObserver(() => {
|
|
131
116
|
if (this._editor.offsetWidth > 0) {
|
|
132
117
|
let options = {
|
|
@@ -156,7 +141,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
156
141
|
options.scrollbar.vertical = 'visible';
|
|
157
142
|
options.scrollbar.horizontal = 'visible';
|
|
158
143
|
}
|
|
159
|
-
this._monacoEditor =
|
|
144
|
+
this._monacoEditor = monaco.editor.create(this._editor, options);
|
|
160
145
|
let selectionTimeout;
|
|
161
146
|
let disableCursorChange;
|
|
162
147
|
let changeContentListener = this._monacoEditor.getModel().onDidChangeContent(e => {
|
|
@@ -229,9 +214,11 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
229
214
|
this._disableSelectionAfterUpd = true;
|
|
230
215
|
if (this._monacoEditor)
|
|
231
216
|
this._monacoEditor.setValue(code);
|
|
232
|
-
CodeViewMonaco.monacoLib.editor.setTheme(this._theme);
|
|
233
|
-
CodeViewMonaco.monacoLib.editor.setModelLanguage(this._monacoEditor.getModel(), this.language);
|
|
234
217
|
this._disableSelectionAfterUpd = false;
|
|
218
|
+
CodeViewMonaco.getMonacoLib().then(monaco => {
|
|
219
|
+
monaco.editor.setTheme(this._theme);
|
|
220
|
+
monaco.editor.setModelLanguage(this._monacoEditor.getModel(), this.language);
|
|
221
|
+
});
|
|
235
222
|
}
|
|
236
223
|
}
|
|
237
224
|
getText() {
|
|
@@ -245,7 +232,9 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
245
232
|
let point2 = model.getPositionAt(position.start + position.length);
|
|
246
233
|
setTimeout(() => {
|
|
247
234
|
this._monacoEditor.setSelection({ startLineNumber: point1.lineNumber, startColumn: point1.column, endLineNumber: point2.lineNumber, endColumn: point2.column });
|
|
248
|
-
|
|
235
|
+
CodeViewMonaco.getMonacoLib().then(monaco => {
|
|
236
|
+
this._monacoEditor.revealRangeInCenterIfOutsideViewport(new monaco.Range(point1.lineNumber, point1.column, point2.lineNumber, point2.column), 1);
|
|
237
|
+
});
|
|
249
238
|
setTimeout(() => {
|
|
250
239
|
this._disableSelectionAfterSel = false;
|
|
251
240
|
}, 50);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "web-component-designer addon: Code Editor using Monaco",
|
|
3
3
|
"name": "@node-projects/web-component-designer-codeview-monaco",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/widgets/codeView/code-view-monaco.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"monaco-editor": ">=0.
|
|
16
|
+
"monaco-editor": ">=0.50.0",
|
|
17
17
|
"@node-projects/base-custom-webcomponent": ">=0.19.0",
|
|
18
18
|
"@node-projects/web-component-designer": ">=0.1.224"
|
|
19
19
|
},
|