@node-projects/web-component-designer-codeview-monaco 0.1.17 → 0.1.19
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/README.md
CHANGED
|
@@ -12,20 +12,20 @@ This uses the Monaco Editor for the Webcomponent Designer Codeview
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
serviceContainer.config.codeViewWidget =
|
|
15
|
+
import { CodeViewMonaco } from '@node-projects/web-component-designer-codeview-monaco';
|
|
16
|
+
serviceContainer.config.codeViewWidget = CodeViewMonaco;
|
|
17
17
|
|
|
18
18
|
You need to load the monaco manualy and call
|
|
19
19
|
|
|
20
|
-
await
|
|
20
|
+
await CodeViewMonaco.setMonacoLibrary(...);
|
|
21
21
|
|
|
22
22
|
or via
|
|
23
23
|
|
|
24
|
-
await
|
|
24
|
+
await CodeViewMonaco.loadMonacoEditorViaRequire();
|
|
25
25
|
|
|
26
26
|
or
|
|
27
27
|
|
|
28
|
-
await
|
|
28
|
+
await CodeViewMonaco.loadMonacoEditorViaImport();
|
|
29
29
|
|
|
30
30
|
or
|
|
31
31
|
|
|
@@ -2,6 +2,7 @@ import { BaseCustomWebComponentLazyAppend, TypedEvent } from '@node-projects/bas
|
|
|
2
2
|
import { IActivateable, ICodeView, InstanceServiceContainer, IStringPosition, IUiCommand, IUiCommandHandler } from '@node-projects/web-component-designer';
|
|
3
3
|
import type * as monacoType from 'monaco-editor';
|
|
4
4
|
export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend implements ICodeView, IActivateable, IUiCommandHandler {
|
|
5
|
+
#private;
|
|
5
6
|
private static _initalized;
|
|
6
7
|
static monacoLib: {
|
|
7
8
|
editor: typeof monacoType.editor;
|
|
@@ -13,13 +14,18 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
|
|
|
13
14
|
code: string;
|
|
14
15
|
onTextChanged: TypedEvent<string>;
|
|
15
16
|
language: string;
|
|
17
|
+
singleRow: boolean;
|
|
16
18
|
private _theme;
|
|
17
19
|
get theme(): string;
|
|
18
20
|
set theme(value: string);
|
|
21
|
+
get readOnly(): boolean;
|
|
22
|
+
set readOnly(v: boolean);
|
|
19
23
|
static readonly properties: {
|
|
20
24
|
code: StringConstructor;
|
|
21
25
|
language: StringConstructor;
|
|
22
26
|
theme: StringConstructor;
|
|
27
|
+
singleRow: BooleanConstructor;
|
|
28
|
+
readOnly: BooleanConstructor;
|
|
23
29
|
};
|
|
24
30
|
private _monacoEditor;
|
|
25
31
|
private _editor;
|
|
@@ -2,7 +2,6 @@ import { BaseCustomWebComponentLazyAppend, css, cssFromString, html, TypedEvent
|
|
|
2
2
|
import { CommandType } from '@node-projects/web-component-designer';
|
|
3
3
|
export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
4
4
|
static _initalized;
|
|
5
|
-
//@ts-ignore
|
|
6
5
|
static monacoLib;
|
|
7
6
|
dispose() {
|
|
8
7
|
this._monacoEditor?.dispose();
|
|
@@ -12,6 +11,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
12
11
|
code;
|
|
13
12
|
onTextChanged = new TypedEvent();
|
|
14
13
|
language = 'html';
|
|
14
|
+
singleRow = false;
|
|
15
15
|
_theme = 'webComponentDesignerTheme';
|
|
16
16
|
get theme() {
|
|
17
17
|
return this._theme;
|
|
@@ -22,10 +22,21 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
22
22
|
CodeViewMonaco.monacoLib ??= window.monaco;
|
|
23
23
|
CodeViewMonaco.monacoLib.editor.setTheme(value);
|
|
24
24
|
}
|
|
25
|
+
#readOnly = false;
|
|
26
|
+
get readOnly() {
|
|
27
|
+
return this.#readOnly;
|
|
28
|
+
}
|
|
29
|
+
set readOnly(v) {
|
|
30
|
+
this.#readOnly = v;
|
|
31
|
+
if (this._monacoEditor)
|
|
32
|
+
this._monacoEditor.updateOptions({ readOnly: v });
|
|
33
|
+
}
|
|
25
34
|
static properties = {
|
|
26
35
|
code: String,
|
|
27
36
|
language: String,
|
|
28
|
-
theme: String
|
|
37
|
+
theme: String,
|
|
38
|
+
singleRow: Boolean,
|
|
39
|
+
readOnly: Boolean
|
|
29
40
|
};
|
|
30
41
|
_monacoEditor;
|
|
31
42
|
_editor;
|
|
@@ -121,19 +132,18 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
121
132
|
this._editor = this._getDomElement('container');
|
|
122
133
|
//@ts-ignore
|
|
123
134
|
CodeViewMonaco.monacoLib ??= window.monaco;
|
|
135
|
+
CodeViewMonaco.initMonacoEditor(CodeViewMonaco.monacoLib);
|
|
124
136
|
const resizeObserver = new ResizeObserver(() => {
|
|
125
137
|
if (this._editor.offsetWidth > 0) {
|
|
126
|
-
|
|
138
|
+
let options = {
|
|
127
139
|
automaticLayout: true,
|
|
128
|
-
wordWrapColumn: 1000,
|
|
129
|
-
//wordWrap: 'wordWrapColumn',
|
|
130
|
-
fontLigatures: '',
|
|
131
|
-
value: this.code,
|
|
132
140
|
language: this.language,
|
|
141
|
+
value: this.code,
|
|
142
|
+
fixedOverflowWidgets: true,
|
|
133
143
|
minimap: {
|
|
134
144
|
size: 'fill'
|
|
135
145
|
},
|
|
136
|
-
|
|
146
|
+
readOnly: this.#readOnly,
|
|
137
147
|
scrollbar: {
|
|
138
148
|
useShadows: false,
|
|
139
149
|
verticalHasArrows: true,
|
|
@@ -141,12 +151,19 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
141
151
|
vertical: 'visible',
|
|
142
152
|
horizontal: 'visible'
|
|
143
153
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
154
|
+
};
|
|
155
|
+
if (this.singleRow) {
|
|
156
|
+
options.minimap.enabled = false;
|
|
157
|
+
options.lineNumbers = 'off';
|
|
158
|
+
options.glyphMargin = false;
|
|
159
|
+
options.folding = false;
|
|
160
|
+
options.lineDecorationsWidth = 0;
|
|
161
|
+
options.lineNumbersMinChars = 0;
|
|
162
|
+
}
|
|
163
|
+
this._monacoEditor = CodeViewMonaco.monacoLib.editor.create(this._editor, options);
|
|
146
164
|
let selectionTimeout;
|
|
147
165
|
let disableCursorChange;
|
|
148
166
|
let changeContentListener = this._monacoEditor.getModel().onDidChangeContent(e => {
|
|
149
|
-
console.log('text change');
|
|
150
167
|
if (selectionTimeout) {
|
|
151
168
|
clearTimeout(selectionTimeout);
|
|
152
169
|
selectionTimeout = null;
|
|
@@ -160,7 +177,6 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
160
177
|
this._monacoEditor.onDidChangeModel(e => {
|
|
161
178
|
changeContentListener.dispose();
|
|
162
179
|
changeContentListener = this._monacoEditor.getModel().onDidChangeContent(e => {
|
|
163
|
-
console.log('text change');
|
|
164
180
|
if (selectionTimeout) {
|
|
165
181
|
clearTimeout(selectionTimeout);
|
|
166
182
|
selectionTimeout = null;
|
|
@@ -205,7 +221,6 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
205
221
|
this._monacoEditor.layout();
|
|
206
222
|
}
|
|
207
223
|
update(code, instanceServiceContainer) {
|
|
208
|
-
console.log('update text');
|
|
209
224
|
this.code = code;
|
|
210
225
|
this._instanceServiceContainer = instanceServiceContainer;
|
|
211
226
|
if (this._monacoEditor) {
|
|
@@ -221,7 +236,6 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
221
236
|
return this._monacoEditor.getValue();
|
|
222
237
|
}
|
|
223
238
|
setSelection(position) {
|
|
224
|
-
console.log('set selection');
|
|
225
239
|
if (this._monacoEditor && !this._disableSelection) {
|
|
226
240
|
let model = this._monacoEditor.getModel();
|
|
227
241
|
let point1 = model.getPositionAt(position.start);
|
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.1.
|
|
4
|
+
"version": "0.1.19",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/widgets/codeView/code-view-monaco.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|