"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var shared_1 = require("../common/shared"); var domhandler_1 = require("../dom/domhandler"); var forms_1 = require("@angular/forms"); var Quill = require("quill"); exports.EDITOR_VALUE_ACCESSOR = { provide: forms_1.NG_VALUE_ACCESSOR, useExisting: core_1.forwardRef(function () { return Editor; }), multi: true }; var Editor = /** @class */ (function () { function Editor(el) { this.el = el; this.onTextChange = new core_1.EventEmitter(); this.onSelectionChange = new core_1.EventEmitter(); this.onInit = new core_1.EventEmitter(); this.onModelChange = function () { }; this.onModelTouched = function () { }; } Editor.prototype.ngAfterViewInit = function () { var _this = this; var editorElement = domhandler_1.DomHandler.findSingle(this.el.nativeElement, 'div.ui-editor-content'); var toolbarElement = domhandler_1.DomHandler.findSingle(this.el.nativeElement, 'div.ui-editor-toolbar'); var defaultModule = { toolbar: toolbarElement }; var modules = this.modules ? __assign({}, defaultModule, this.modules) : defaultModule; this.quill = new Quill(editorElement, { modules: modules, placeholder: this.placeholder, readOnly: this.readonly, theme: 'snow', formats: this.formats, bounds: this.bounds, debug: this.debug, scrollingContainer: this.scrollingContainer }); if (this.value) { this.quill.pasteHTML(this.value); } this.quill.on('text-change', function (delta, oldContents, source) { if (source === 'user') { var html = editorElement.children[0].innerHTML; var text = _this.quill.getText().trim(); if (html === '


') { html = null; } _this.onTextChange.emit({ htmlValue: html, textValue: text, delta: delta, source: source }); _this.onModelChange(html); _this.onModelTouched(); } }); this.quill.on('selection-change', function (range, oldRange, source) { _this.onSelectionChange.emit({ range: range, oldRange: oldRange, source: source }); }); this.onInit.emit({ editor: this.quill }); }; Editor.prototype.writeValue = function (value) { this.value = value; if (this.quill) { if (value) this.quill.pasteHTML(value); else this.quill.setText(''); } }; Editor.prototype.registerOnChange = function (fn) { this.onModelChange = fn; }; Editor.prototype.registerOnTouched = function (fn) { this.onModelTouched = fn; }; Editor.prototype.getQuill = function () { return this.quill; }; Object.defineProperty(Editor.prototype, "readonly", { get: function () { return this._readonly; }, set: function (val) { this._readonly = val; if (this.quill) { if (this._readonly) this.quill.disable(); else this.quill.enable(); } }, enumerable: true, configurable: true }); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Editor.prototype, "onTextChange", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Editor.prototype, "onSelectionChange", void 0); __decorate([ core_1.ContentChild(shared_1.Header, { static: false }), __metadata("design:type", Object) ], Editor.prototype, "toolbar", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Editor.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Editor.prototype, "styleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Editor.prototype, "placeholder", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], Editor.prototype, "formats", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Editor.prototype, "modules", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Editor.prototype, "bounds", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Editor.prototype, "scrollingContainer", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Editor.prototype, "debug", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Editor.prototype, "onInit", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean), __metadata("design:paramtypes", [Boolean]) ], Editor.prototype, "readonly", null); Editor = __decorate([ core_1.Component({ selector: 'p-editor', template: "\n
\n
\n \n
\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n
\n
\n ", providers: [exports.EDITOR_VALUE_ACCESSOR] }), __metadata("design:paramtypes", [core_1.ElementRef]) ], Editor); return Editor; }()); exports.Editor = Editor; var EditorModule = /** @class */ (function () { function EditorModule() { } EditorModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [Editor, shared_1.SharedModule], declarations: [Editor] }) ], EditorModule); return EditorModule; }()); exports.EditorModule = EditorModule; //# sourceMappingURL=editor.js.map