@node-projects/web-component-designer-codeview-ace 0.1.0 → 0.1.2

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.
@@ -0,0 +1,21 @@
1
+ import { BaseCustomWebComponentLazyAppend, TypedEvent } from '@node-projects/base-custom-webcomponent';
2
+ import { ICodeView, IDisposable, IUiCommand, IStringPosition } from '@node-projects/web-component-designer';
3
+ export declare class CodeViewAce extends BaseCustomWebComponentLazyAppend implements ICodeView, IDisposable {
4
+ canvasElement: HTMLElement;
5
+ elementsToPackages: Map<string, string>;
6
+ code: string;
7
+ onTextChanged: TypedEvent<string>;
8
+ private _aceEditor;
9
+ private _editor;
10
+ static readonly style: CSSStyleSheet;
11
+ constructor();
12
+ dispose(): void;
13
+ executeCommand(command: IUiCommand): void;
14
+ canExecuteCommand(command: IUiCommand): boolean;
15
+ focusEditor(): void;
16
+ oneTimeSetup(): void;
17
+ ready(): void;
18
+ update(code: any): void;
19
+ getText(): string;
20
+ setSelection(position: IStringPosition): void;
21
+ }
@@ -0,0 +1,134 @@
1
+ import { BaseCustomWebComponentLazyAppend, css, TypedEvent } from '@node-projects/base-custom-webcomponent';
2
+ import { CommandType } from '@node-projects/web-component-designer';
3
+ class CodeViewAceCompleter {
4
+ getCompletions(editor, session, pos, prefix, callback) {
5
+ if (prefix.length === 0) {
6
+ callback(null, []);
7
+ return;
8
+ }
9
+ let wordList = ['t-t', 'visu-conveyor']; //TODO: get word list from custom elements
10
+ {
11
+ callback(null, wordList.map((w) => {
12
+ return { name: w, value: w, score: 1, meta: "tag" };
13
+ }));
14
+ }
15
+ }
16
+ }
17
+ export class CodeViewAce extends BaseCustomWebComponentLazyAppend {
18
+ canvasElement;
19
+ elementsToPackages;
20
+ code;
21
+ onTextChanged = new TypedEvent();
22
+ _aceEditor;
23
+ _editor;
24
+ static style = css `
25
+ :host {
26
+ display: block;
27
+ height: 100%;
28
+ width: 100%;
29
+ }
30
+ `;
31
+ constructor() {
32
+ super();
33
+ this._restoreCachedInititalValues();
34
+ this.style.display = 'block';
35
+ this._editor = document.createElement("div");
36
+ this._editor.style.height = '100%';
37
+ this._editor.style.width = '100%';
38
+ this.shadowRoot.appendChild(this._editor);
39
+ }
40
+ dispose() {
41
+ this._aceEditor?.destroy();
42
+ }
43
+ executeCommand(command) {
44
+ switch (command.type) {
45
+ case CommandType.undo:
46
+ this._aceEditor.execCommand('undo');
47
+ break;
48
+ case CommandType.redo:
49
+ this._aceEditor.execCommand('redo');
50
+ break;
51
+ case CommandType.copy:
52
+ let text = this._aceEditor.getCopyText();
53
+ this._aceEditor.execCommand("copy");
54
+ navigator.clipboard.writeText(text);
55
+ break;
56
+ case CommandType.paste:
57
+ navigator.clipboard.readText().then(text => {
58
+ this._aceEditor.execCommand("paste", text);
59
+ });
60
+ break;
61
+ case CommandType.cut:
62
+ text = this._aceEditor.getCopyText();
63
+ this._aceEditor.execCommand("cut");
64
+ navigator.clipboard.writeText(text);
65
+ break;
66
+ case CommandType.delete:
67
+ this._aceEditor.execCommand("delete");
68
+ break;
69
+ }
70
+ }
71
+ canExecuteCommand(command) {
72
+ switch (command.type) {
73
+ case CommandType.undo:
74
+ case CommandType.redo:
75
+ case CommandType.copy:
76
+ case CommandType.paste:
77
+ case CommandType.cut:
78
+ case CommandType.delete:
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ focusEditor() {
84
+ requestAnimationFrame(() => {
85
+ this.focus();
86
+ this._aceEditor.focus();
87
+ });
88
+ }
89
+ oneTimeSetup() {
90
+ //@ts-ignore
91
+ let langTools = ace.require("ace/ext/language_tools");
92
+ langTools.addCompleter(new CodeViewAceCompleter());
93
+ }
94
+ ready() {
95
+ //@ts-ignore
96
+ this._aceEditor = ace.edit(this._editor, {
97
+ theme: "ace/theme/chrome",
98
+ mode: "ace/mode/html",
99
+ value: "",
100
+ autoScrollEditorIntoView: true,
101
+ fontSize: "14px",
102
+ showPrintMargin: false,
103
+ displayIndentGuides: true,
104
+ enableBasicAutocompletion: true,
105
+ enableSnippets: true,
106
+ enableLiveAutocompletion: true
107
+ });
108
+ //own snippet completer: http://plnkr.co/edit/6MVntVmXYUbjR0DI82Cr?p=preview
109
+ this._aceEditor.renderer.attachToShadowRoot();
110
+ let observer = new MutationObserver((m) => {
111
+ this._aceEditor.setAutoScrollEditorIntoView(false);
112
+ this._aceEditor.setAutoScrollEditorIntoView(true);
113
+ });
114
+ let config = { attributes: true, childList: true, characterData: true };
115
+ observer.observe(this.shadowRoot.querySelector('.ace_content'), config);
116
+ this._aceEditor.on('change', () => this.onTextChanged.emit(this._aceEditor.getValue()));
117
+ }
118
+ update(code) {
119
+ this._aceEditor.setValue(code);
120
+ this._aceEditor.clearSelection();
121
+ }
122
+ getText() {
123
+ return this._aceEditor.getValue();
124
+ }
125
+ setSelection(position) {
126
+ let point1 = this._aceEditor.session.getDocument().indexToPosition(position.start, 0);
127
+ let point2 = this._aceEditor.session.getDocument().indexToPosition(position.start + position.length, 0);
128
+ //@ts-ignore
129
+ this._aceEditor.selection.setRange({ start: point1, end: point2 });
130
+ //@ts-ignore
131
+ this._aceEditor.scrollToLine(point1.row);
132
+ }
133
+ }
134
+ customElements.define('node-projects-code-view-ace', CodeViewAce);
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.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "main": "./dist/widgets/codeView/code-view-ace.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "ace-builds": "^1.24.2",
16
- "@node-projects/base-custom-webcomponent": "^0.17.2",
17
- "@node-projects/web-component-designer": "^0.1.0"
16
+ "@node-projects/base-custom-webcomponent": "^0.18.1",
17
+ "@node-projects/web-component-designer": "^0.1.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",