You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
import {Component, ViewChild} from '@angular/core';
|
|
import {EditorNodeContract} from '../EditorNode.contract';
|
|
|
|
@Component({
|
|
selector: 'editor-norm',
|
|
templateUrl: './norm.component.html',
|
|
styleUrls: ['./norm.component.scss'],
|
|
})
|
|
export class NormComponent extends EditorNodeContract {
|
|
@ViewChild('editable') editable;
|
|
public isFocused = false;
|
|
public initialValue = 'Content editable now...';
|
|
public contents = '';
|
|
private dirtyOverride = false;
|
|
|
|
constructor() {
|
|
super();
|
|
console.log('norm compt', this);
|
|
this.contents = this.initialValue;
|
|
}
|
|
|
|
public isDirty(): boolean | Promise<boolean> {
|
|
return this.dirtyOverride || this.contents !== this.initialValue;
|
|
}
|
|
|
|
onFocusIn(event: MouseEvent) {
|
|
this.isFocused = true;
|
|
}
|
|
|
|
onFocusOut(event: MouseEvent) {
|
|
this.isFocused = false;
|
|
}
|
|
|
|
documentCommand(cmd: string) {
|
|
// Yes, technically this is deprecated, but it'll be poly-filled if necessary. Bite me.
|
|
document.execCommand(cmd, false, '');
|
|
}
|
|
|
|
onContentsChanged(contents: string) {
|
|
const innerHTML = this.editable.nativeElement.innerHTML;
|
|
if ( this.contents !== innerHTML ) {
|
|
this.contents = innerHTML;
|
|
}
|
|
}
|
|
}
|