@node-projects/web-component-designer-codeview-ace 0.1.2 → 0.3.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.
|
@@ -4,6 +4,9 @@ export declare class CodeViewAce extends BaseCustomWebComponentLazyAppend implem
|
|
|
4
4
|
canvasElement: HTMLElement;
|
|
5
5
|
elementsToPackages: Map<string, string>;
|
|
6
6
|
code: string;
|
|
7
|
+
private _disposed;
|
|
8
|
+
private _observer;
|
|
9
|
+
private _focusFrame;
|
|
7
10
|
onTextChanged: TypedEvent<string>;
|
|
8
11
|
private _aceEditor;
|
|
9
12
|
private _editor;
|
|
@@ -17,7 +17,10 @@ class CodeViewAceCompleter {
|
|
|
17
17
|
export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
18
18
|
canvasElement;
|
|
19
19
|
elementsToPackages;
|
|
20
|
-
code;
|
|
20
|
+
code = '';
|
|
21
|
+
_disposed = false;
|
|
22
|
+
_observer;
|
|
23
|
+
_focusFrame;
|
|
21
24
|
onTextChanged = new TypedEvent();
|
|
22
25
|
_aceEditor;
|
|
23
26
|
_editor;
|
|
@@ -38,9 +41,17 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
38
41
|
this.shadowRoot.appendChild(this._editor);
|
|
39
42
|
}
|
|
40
43
|
dispose() {
|
|
44
|
+
if (this._disposed)
|
|
45
|
+
return;
|
|
46
|
+
this._disposed = true;
|
|
47
|
+
cancelAnimationFrame(this._focusFrame);
|
|
48
|
+
this._observer?.disconnect();
|
|
41
49
|
this._aceEditor?.destroy();
|
|
50
|
+
this._aceEditor = null;
|
|
42
51
|
}
|
|
43
52
|
executeCommand(command) {
|
|
53
|
+
if (!this._aceEditor)
|
|
54
|
+
return;
|
|
44
55
|
switch (command.type) {
|
|
45
56
|
case CommandType.undo:
|
|
46
57
|
this._aceEditor.execCommand('undo');
|
|
@@ -55,7 +66,7 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
55
66
|
break;
|
|
56
67
|
case CommandType.paste:
|
|
57
68
|
navigator.clipboard.readText().then(text => {
|
|
58
|
-
this._aceEditor
|
|
69
|
+
this._aceEditor?.execCommand("paste", text);
|
|
59
70
|
});
|
|
60
71
|
break;
|
|
61
72
|
case CommandType.cut:
|
|
@@ -69,6 +80,8 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
canExecuteCommand(command) {
|
|
83
|
+
if (!this._aceEditor)
|
|
84
|
+
return false;
|
|
72
85
|
switch (command.type) {
|
|
73
86
|
case CommandType.undo:
|
|
74
87
|
case CommandType.redo:
|
|
@@ -81,9 +94,12 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
81
94
|
return false;
|
|
82
95
|
}
|
|
83
96
|
focusEditor() {
|
|
84
|
-
|
|
97
|
+
cancelAnimationFrame(this._focusFrame);
|
|
98
|
+
this._focusFrame = requestAnimationFrame(() => {
|
|
99
|
+
if (this._disposed)
|
|
100
|
+
return;
|
|
85
101
|
this.focus();
|
|
86
|
-
this._aceEditor
|
|
102
|
+
this._aceEditor?.focus();
|
|
87
103
|
});
|
|
88
104
|
}
|
|
89
105
|
oneTimeSetup() {
|
|
@@ -92,11 +108,13 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
92
108
|
langTools.addCompleter(new CodeViewAceCompleter());
|
|
93
109
|
}
|
|
94
110
|
ready() {
|
|
111
|
+
if (this._disposed)
|
|
112
|
+
return;
|
|
95
113
|
//@ts-ignore
|
|
96
114
|
this._aceEditor = ace.edit(this._editor, {
|
|
97
115
|
theme: "ace/theme/chrome",
|
|
98
116
|
mode: "ace/mode/html",
|
|
99
|
-
value:
|
|
117
|
+
value: this.code ?? '',
|
|
100
118
|
autoScrollEditorIntoView: true,
|
|
101
119
|
fontSize: "14px",
|
|
102
120
|
showPrintMargin: false,
|
|
@@ -107,22 +125,30 @@ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
|
|
|
107
125
|
});
|
|
108
126
|
//own snippet completer: http://plnkr.co/edit/6MVntVmXYUbjR0DI82Cr?p=preview
|
|
109
127
|
this._aceEditor.renderer.attachToShadowRoot();
|
|
110
|
-
|
|
128
|
+
this._observer = new MutationObserver((m) => {
|
|
111
129
|
this._aceEditor.setAutoScrollEditorIntoView(false);
|
|
112
130
|
this._aceEditor.setAutoScrollEditorIntoView(true);
|
|
113
131
|
});
|
|
114
132
|
let config = { attributes: true, childList: true, characterData: true };
|
|
115
|
-
|
|
116
|
-
this._aceEditor.on('change', () =>
|
|
133
|
+
this._observer.observe(this.shadowRoot.querySelector('.ace_content'), config);
|
|
134
|
+
this._aceEditor.on('change', () => {
|
|
135
|
+
this.code = this._aceEditor.getValue();
|
|
136
|
+
this.onTextChanged.emit(this.code);
|
|
137
|
+
});
|
|
117
138
|
}
|
|
118
139
|
update(code) {
|
|
119
|
-
this.
|
|
120
|
-
|
|
140
|
+
if (this._disposed)
|
|
141
|
+
return;
|
|
142
|
+
this.code = code;
|
|
143
|
+
this._aceEditor?.setValue(code);
|
|
144
|
+
this._aceEditor?.clearSelection();
|
|
121
145
|
}
|
|
122
146
|
getText() {
|
|
123
|
-
return this._aceEditor
|
|
147
|
+
return this._aceEditor?.getValue() ?? this.code ?? '';
|
|
124
148
|
}
|
|
125
149
|
setSelection(position) {
|
|
150
|
+
if (!this._aceEditor || !position)
|
|
151
|
+
return;
|
|
126
152
|
let point1 = this._aceEditor.session.getDocument().indexToPosition(position.start, 0);
|
|
127
153
|
let point2 = this._aceEditor.session.getDocument().indexToPosition(position.start + position.length, 0);
|
|
128
154
|
//@ts-ignore
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "web-component-designer addon: Code Editor using ACE",
|
|
3
3
|
"name": "@node-projects/web-component-designer-codeview-ace",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/widgets/codeView/code-view-ace.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"tsc": "tsc",
|
|
11
11
|
"build": "tsc",
|
|
12
|
+
"link": "npm link",
|
|
12
13
|
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"ace-builds": "^1.
|
|
16
|
-
"@node-projects/base-custom-webcomponent": "
|
|
17
|
-
"@node-projects/web-component-designer": "
|
|
16
|
+
"ace-builds": "^1.36.3",
|
|
17
|
+
"@node-projects/base-custom-webcomponent": ">=0.27.8",
|
|
18
|
+
"@node-projects/web-component-designer": ">=0.1.224"
|
|
18
19
|
},
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|