import { AfterViewInit, Component, ElementRef, EventEmitter, forwardRef, Input, OnChanges, Output, SimpleChanges, ViewEncapsulation } from '@angular/core'; import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'; import * as Quill from 'quill'; @Component({ selector: 'quill-editor', template: `
`, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => QuillEditorComponent), multi: true }], styles: [` .ql-container .ql-editor { min-height: 200px; padding-bottom: 50px; } `], encapsulation: ViewEncapsulation.None }) export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor, OnChanges { quillEditor: any; editorElem: HTMLElement; emptyArray: any[] = []; content: any; defaultModules = { toolbar: [ ['bold', 'italic', 'underline', 'strike'], // toggled buttons ['blockquote', 'code-block'], [{ 'header': 1 }, { 'header': 2 }], // custom button values [{ 'list': 'ordered'}, { 'list': 'bullet' }], [{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript [{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent [{ 'direction': 'rtl' }], // text direction [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'color': this.emptyArray.slice() }, { 'background': this.emptyArray.slice() }], // dropdown with defaults from theme [{ 'font': this.emptyArray.slice() }], [{ 'align': this.emptyArray.slice() }], ['clean'], // remove formatting button ['link', 'image', 'video'] // link and image, video ] }; @Input() theme: string; @Input() modules: Object; @Input() readOnly: boolean; @Input() placeholder: string; @Input() formats: string[]; @Output() onEditorCreated: EventEmitter