Update monaco and refactor usage to remove all internal scrollbars
continuous-integration/drone/push Build is passing Details

master
Garrett Mills 4 years ago
parent 3fd6a54622
commit 99a1f0103f
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -30,11 +30,8 @@
"input": "node_modules/ionicons/dist/ionicons/svg", "input": "node_modules/ionicons/dist/ionicons/svg",
"output": "./svg" "output": "./svg"
}, },
{ { "glob": "**/*", "input": "node_modules/ngx-monaco-editor/assets/monaco", "output": "./assets/monaco/" },
"glob": "**/*",
"input": "node_modules/ngx-monaco-editor/assets/monaco",
"output": "./assets/monaco/"
},
"src/manifest.webmanifest" "src/manifest.webmanifest"
], ],
"styles": [ "styles": [

16544
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -38,7 +38,7 @@
"moment": "^2.24.0", "moment": "^2.24.0",
"ng-connection-service": "^1.0.4", "ng-connection-service": "^1.0.4",
"ngx-markdown": "^10.1.1", "ngx-markdown": "^10.1.1",
"ngx-monaco-editor": "^8.1.1", "ngx-monaco-editor": "^9.0.0",
"rxjs": "~6.6.3", "rxjs": "~6.6.3",
"tslib": "^1.9.0", "tslib": "^1.9.0",
"uuid": "^3.4.0", "uuid": "^3.4.0",

@ -1,4 +1,4 @@
<div class="code-wrapper" style="width: 100%; height: 600px; margin-top: 10px;" *ngIf="!notAvailableOffline"> <div class="code-wrapper" style="width: 100%; margin-top: 10px;" *ngIf="!notAvailableOffline">
<ion-toolbar> <ion-toolbar>
<ion-item> <ion-item>
<ion-label position="floating">Language</ion-label> <ion-label position="floating">Language</ion-label>
@ -7,12 +7,14 @@
</ion-select> </ion-select>
</ion-item> </ion-item>
</ion-toolbar> </ion-toolbar>
<div class="ed-wrapper" style="width: 100%; height: 540px;"> <div class="editor-container" #editorContainer>
<ngx-monaco-editor style="width: 100%; height: 100%;" <ngx-monaco-editor style="width: 100%; height: 100%;"
[options]="editorOptions" [options]="editorOptions"
[(ngModel)]="editorValue" [(ngModel)]="editorValue"
(ngModelChange)="onEditorModelChange($event)" (onInit)="onMonacoEditorInit($event)"
#theEditor (ngModelChange)="onEditorModelChange($event)"
#theEditor
class="editor"
></ngx-monaco-editor> ></ngx-monaco-editor>
</div> </div>
</div> </div>

@ -1,8 +1,9 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {v4} from 'uuid'; import {v4} from 'uuid';
import {ApiService, ResourceNotAvailableOfflineError} from '../../../service/api.service'; import {ApiService, ResourceNotAvailableOfflineError} from '../../../service/api.service';
import {EditorNodeContract} from '../../nodes/EditorNode.contract'; import {EditorNodeContract} from '../../nodes/EditorNode.contract';
import {EditorService} from '../../../service/editor.service'; import {EditorService} from '../../../service/editor.service';
import {EditorComponent} from 'ngx-monaco-editor';
@Component({ @Component({
selector: 'editor-code', selector: 'editor-code',
@ -12,16 +13,24 @@ import {EditorService} from '../../../service/editor.service';
export class CodeComponent extends EditorNodeContract implements OnInit { export class CodeComponent extends EditorNodeContract implements OnInit {
@Input() nodeId: string; @Input() nodeId: string;
@Input() editorUUID?: string; @Input() editorUUID?: string;
@ViewChild('theEditor') theEditor: EditorComponent;
@ViewChild('editorContainer') editorContainer: ElementRef;
public dirty = false; public dirty = false;
protected dbRecord: any = {}; protected dbRecord: any = {};
protected codeRefId!: string; protected codeRefId!: string;
public notAvailableOffline = false; public notAvailableOffline = false;
public containerHeight = 540;
public editorOptions = { public editorOptions = {
theme: this.isDark() ? 'vs-dark' : 'vs', theme: this.isDark() ? 'vs-dark' : 'vs',
language: 'javascript', language: 'javascript',
uri: v4(), uri: v4(),
readOnly: false, readOnly: false,
automaticLayout: true,
scrollBeyondLastLine: false,
scrollbar: {
alwaysConsumeMouseWheel: false,
},
}; };
public editorValue = ''; public editorValue = '';
@ -195,6 +204,24 @@ export class CodeComponent extends EditorNodeContract implements OnInit {
}); });
} }
onMonacoEditorInit(editor) {
let ignoreEvent = false;
const updateHeight = () => {
const contentHeight = Math.max(540, editor.getContentHeight());
this.containerHeight = contentHeight;
try {
ignoreEvent = true;
editor.layout({ width: this.editorContainer.nativeElement.offsetWidth, height: contentHeight });
} finally {
ignoreEvent = false;
}
};
editor.onDidContentSizeChange(updateHeight);
updateHeight();
}
public onEditorModelChange($event) { public onEditorModelChange($event) {
if ( this.editorValue !== this.dbRecord.code ) { if ( this.editorValue !== this.dbRecord.code ) {
this.dirty = true; this.dirty = true;

@ -1,9 +1,10 @@
<div class="container" (dblclick)="onFocusIn()" (resized)="onEditorHostResize($event)"> <div class="container" (dblclick)="onFocusIn()" (resized)="onEditorHostResize($event)">
<div class="editor-container" *ngIf="showEditor"> <div class="editor-container" *ngIf="showEditor" #editorContainer>
<ngx-monaco-editor class="editor" <ngx-monaco-editor class="editor"
[options]="editorOptions" [options]="editorOptions"
[(ngModel)]="contents" [(ngModel)]="contents"
(ngModelChange)="onContentsChanged($event)" (ngModelChange)="onContentsChanged($event)"
(onInit)="onMonacoEditorInit($event)"
#editor #editor
></ngx-monaco-editor> ></ngx-monaco-editor>
</div> </div>

@ -1,7 +1,8 @@
import {Component, HostListener, Input, OnInit, ViewChild} from '@angular/core'; import {Component, ElementRef, HostListener, Input, OnInit, ViewChild} from '@angular/core';
import {EditorNodeContract} from '../EditorNode.contract'; import {EditorNodeContract} from '../EditorNode.contract';
import {EditorService} from '../../../service/editor.service'; import {EditorService} from '../../../service/editor.service';
import {v4} from 'uuid'; import {v4} from 'uuid';
import {EditorComponent} from 'ngx-monaco-editor';
@Component({ @Component({
selector: 'editor-markdown', selector: 'editor-markdown',
@ -12,6 +13,8 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
// @ViewChild('editable') editable; // @ViewChild('editable') editable;
@Input() nodeId: string; @Input() nodeId: string;
@Input() editorUUID?: string; @Input() editorUUID?: string;
@ViewChild('editor') editor: EditorComponent;
@ViewChild('editorContainer') editorContainer: ElementRef;
// public isFocused = false; // public isFocused = false;
public initialValue = 'Click to edit...'; public initialValue = 'Click to edit...';
@ -21,6 +24,7 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
public showEditor = false; public showEditor = false;
protected hadOneFocusOut = false; protected hadOneFocusOut = false;
public singleColumn = false; public singleColumn = false;
public containerHeight = 540;
public editorOptions = { public editorOptions = {
theme: this.isDark() ? 'vs-dark' : 'vs', theme: this.isDark() ? 'vs-dark' : 'vs',
@ -29,6 +33,10 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
readOnly: false, readOnly: false,
automaticLayout: true, automaticLayout: true,
wordWrap: 'on', wordWrap: 'on',
scrollBeyondLastLine: false,
scrollbar: {
alwaysConsumeMouseWheel: false,
},
}; };
constructor( constructor(
@ -59,6 +67,24 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
}); });
} }
onMonacoEditorInit(editor) {
let ignoreEvent = false;
const updateHeight = () => {
const contentHeight = Math.max(540, editor.getContentHeight());
this.containerHeight = contentHeight;
try {
ignoreEvent = true;
editor.layout({ width: this.editorContainer.nativeElement.offsetWidth, height: contentHeight });
} finally {
ignoreEvent = false;
}
};
editor.onDidContentSizeChange(updateHeight);
updateHeight();
}
public isDirty(): boolean | Promise<boolean> { public isDirty(): boolean | Promise<boolean> {
return this.dirtyOverride || this.contents !== this.savedValue; return this.dirtyOverride || this.contents !== this.savedValue;
} }

Loading…
Cancel
Save