|
|
|
@ -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 {EditorService} from '../../../service/editor.service';
|
|
|
|
|
import {v4} from 'uuid';
|
|
|
|
|
import {EditorComponent} from 'ngx-monaco-editor';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'editor-markdown',
|
|
|
|
@ -12,6 +13,8 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
|
|
|
|
|
// @ViewChild('editable') editable;
|
|
|
|
|
@Input() nodeId: string;
|
|
|
|
|
@Input() editorUUID?: string;
|
|
|
|
|
@ViewChild('editor') editor: EditorComponent;
|
|
|
|
|
@ViewChild('editorContainer') editorContainer: ElementRef;
|
|
|
|
|
|
|
|
|
|
// public isFocused = false;
|
|
|
|
|
public initialValue = 'Click to edit...';
|
|
|
|
@ -21,6 +24,7 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
|
|
|
|
|
public showEditor = false;
|
|
|
|
|
protected hadOneFocusOut = false;
|
|
|
|
|
public singleColumn = false;
|
|
|
|
|
public containerHeight = 540;
|
|
|
|
|
|
|
|
|
|
public editorOptions = {
|
|
|
|
|
theme: this.isDark() ? 'vs-dark' : 'vs',
|
|
|
|
@ -29,6 +33,10 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
|
|
|
|
|
readOnly: false,
|
|
|
|
|
automaticLayout: true,
|
|
|
|
|
wordWrap: 'on',
|
|
|
|
|
scrollBeyondLastLine: false,
|
|
|
|
|
scrollbar: {
|
|
|
|
|
alwaysConsumeMouseWheel: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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> {
|
|
|
|
|
return this.dirtyOverride || this.contents !== this.savedValue;
|
|
|
|
|
}
|
|
|
|
|