1 | {"version":3,"file":"primeng-editor.mjs","sources":["../../src/app/components/editor/editor.ts","../../src/app/components/editor/primeng-editor.ts"],"sourcesContent":["import {NgModule,Component,ElementRef,AfterViewInit,Input,Output,EventEmitter,ContentChild,forwardRef,ChangeDetectionStrategy, ViewEncapsulation, ContentChildren, QueryList, AfterContentInit, TemplateRef} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {SharedModule,Header, PrimeTemplate} from 'primeng/api'\nimport {DomHandler} from 'primeng/dom';\nimport {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';\nimport * as Quill from \"quill\";\n\nexport const EDITOR_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => Editor),\n multi: true\n};\n\n@Component({\n selector: 'p-editor',\n template: `\n <div [ngClass]=\"'p-editor-container'\" [class]=\"styleClass\">\n <div class=\"p-editor-toolbar\" *ngIf=\"toolbar || headerTemplate\">\n <ng-content select=\"p-header\"></ng-content>\n <ng-container *ngTemplateOutlet=\"headerTemplate\"></ng-container>\n </div>\n <div class=\"p-editor-toolbar\" *ngIf=\"!toolbar && !headerTemplate\">\n <span class=\"ql-formats\">\n <select class=\"ql-header\">\n <option value=\"1\">Heading</option>\n <option value=\"2\">Subheading</option>\n <option selected>Normal</option>\n </select>\n <select class=\"ql-font\">\n <option selected>Sans Serif</option>\n <option value=\"serif\">Serif</option>\n <option value=\"monospace\">Monospace</option>\n </select>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-bold\" aria-label=\"Bold\" type=\"button\"></button>\n <button class=\"ql-italic\" aria-label=\"Italic\" type=\"button\"></button>\n <button class=\"ql-underline\" aria-label=\"Underline\" type=\"button\"></button>\n </span>\n <span class=\"ql-formats\">\n <select class=\"ql-color\"></select>\n <select class=\"ql-background\"></select>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-list\" value=\"ordered\" aria-label=\"Ordered List\" type=\"button\"></button>\n <button class=\"ql-list\" value=\"bullet\" aria-label=\"Unordered List\" type=\"button\"></button>\n <select class=\"ql-align\">\n <option selected></option>\n <option value=\"center\">center</option>\n <option value=\"right\">right</option>\n <option value=\"justify\">justify</option>\n </select>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-link\" aria-label=\"Insert Link\" type=\"button\"></button>\n <button class=\"ql-image\" aria-label=\"Insert Image\" type=\"button\"></button>\n <button class=\"ql-code-block\" aria-label=\"Insert Code Block\" type=\"button\"></button>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-clean\" aria-label=\"Remove Styles\" type=\"button\"></button>\n </span>\n </div>\n <div class=\"p-editor-content\" [ngStyle]=\"style\"></div>\n </div>\n `,\n providers: [EDITOR_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n styleUrls: ['./editor.css'],\n encapsulation: ViewEncapsulation.None,\n host: {\n 'class': 'p-element'\n }\n})\nexport class Editor implements AfterViewInit,AfterContentInit,ControlValueAccessor {\n\n @Output() onTextChange: EventEmitter<any> = new EventEmitter();\n\n @Output() onSelectionChange: EventEmitter<any> = new EventEmitter();\n\n @ContentChild(Header) toolbar;\n\n @Input() style: any;\n\n @Input() styleClass: string;\n\n @Input() placeholder: string;\n\n @Input() formats: string[];\n\n @Input() modules: any;\n\n @Input() bounds: any;\n\n @Input() scrollingContainer: any;\n\n @Input() debug: string;\n\n @Output() onInit: EventEmitter<any> = new EventEmitter();\n\n @ContentChildren(PrimeTemplate) templates: QueryList<any>;\n\n value: string;\n\n _readonly: boolean;\n\n onModelChange: Function = () => {};\n\n onModelTouched: Function = () => {};\n\n quill: any;\n\n headerTemplate: TemplateRef<any>;\n\n constructor(public el: ElementRef) {}\n\n ngAfterViewInit() {\n let editorElement = DomHandler.findSingle(this.el.nativeElement ,'div.p-editor-content');\n let toolbarElement = DomHandler.findSingle(this.el.nativeElement ,'div.p-editor-toolbar');\n let defaultModule = {toolbar: toolbarElement};\n let modules = this.modules ? {...defaultModule, ...this.modules} : defaultModule;\n\n this.quill = new Quill(editorElement, {\n modules: modules,\n placeholder: this.placeholder,\n readOnly: this.readonly,\n theme: 'snow',\n formats: this.formats,\n bounds: this.bounds,\n debug: this.debug,\n scrollingContainer: this.scrollingContainer\n });\n\n if (this.value) {\n this.quill.setContents(this.quill.clipboard.convert(this.value));\n }\n\n this.quill.on('text-change', (delta, oldContents, source) => {\n if (source === 'user') {\n let html = DomHandler.findSingle(editorElement, '.ql-editor').innerHTML;\n let text = this.quill.getText().trim();\n if (html === '<p><br></p>') {\n html = null;\n }\n\n this.onTextChange.emit({\n htmlValue: html,\n textValue: text,\n delta: delta,\n source: source\n });\n\n this.onModelChange(html);\n this.onModelTouched();\n }\n });\n\n this.quill.on('selection-change', (range, oldRange, source) => {\n this.onSelectionChange.emit({\n range: range,\n oldRange: oldRange,\n source: source\n });\n });\n\n this.onInit.emit({\n editor: this.quill\n });\n }\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch(item.getType()) {\n case 'header':\n this.headerTemplate = item.template;\n break;\n }\n });\n }\n\n writeValue(value: any) : void {\n this.value = value;\n\n if (this.quill) {\n if (value)\n this.quill.setContents(this.quill.clipboard.convert(value));\n else\n this.quill.setText('');\n }\n }\n\n registerOnChange(fn: Function): void {\n this.onModelChange = fn;\n }\n\n registerOnTouched(fn: Function): void {\n this.onModelTouched = fn;\n }\n\n getQuill() {\n return this.quill;\n }\n\n @Input() get readonly(): boolean {\n return this._readonly;\n }\n\n set readonly(val:boolean) {\n this._readonly = val;\n\n if (this.quill) {\n if (this._readonly)\n this.quill.disable();\n else\n this.quill.enable();\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [Editor,SharedModule],\n declarations: [Editor]\n})\nexport class EditorModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;MAOa,qBAAqB,GAAQ;IACxC,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,UAAU,CAAC,MAAM,MAAM,CAAC;IAC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