(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/api'), require('primeng/dom'), require('@angular/forms'), require('quill')) :
typeof define === 'function' && define.amd ? define('primeng/editor', ['exports', '@angular/core', '@angular/common', 'primeng/api', 'primeng/dom', '@angular/forms', 'quill'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.editor = {}), global.ng.core, global.ng.common, global.primeng.api, global.primeng.dom, global.ng.forms, global.Quill));
}(this, (function (exports, core, common, api, dom, forms, Quill) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var Quill__namespace = /*#__PURE__*/_interopNamespace(Quill);
var EDITOR_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: core.forwardRef(function () { return Editor; }),
multi: true
};
var Editor = /** @class */ (function () {
function Editor(el) {
this.el = el;
this.onTextChange = new core.EventEmitter();
this.onSelectionChange = new core.EventEmitter();
this.onInit = new core.EventEmitter();
this.onModelChange = function () { };
this.onModelTouched = function () { };
}
Editor.prototype.ngAfterViewInit = function () {
var _this = this;
var editorElement = dom.DomHandler.findSingle(this.el.nativeElement, 'div.p-editor-content');
var toolbarElement = dom.DomHandler.findSingle(this.el.nativeElement, 'div.p-editor-toolbar');
var defaultModule = { toolbar: toolbarElement };
var modules = this.modules ? Object.assign(Object.assign({}, defaultModule), this.modules) : defaultModule;
this.quill = new Quill__namespace(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.ngAfterContentInit = function () {
var _this = this;
this.templates.forEach(function (item) {
switch (item.getType()) {
case 'toolbar':
_this.toolbarTemplate = item.template;
break;
}
});
};
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: false,
configurable: true
});
return Editor;
}());
Editor.decorators = [
{ type: core.Component, args: [{
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
\n ",
providers: [EDITOR_VALUE_ACCESSOR],
changeDetection: core.ChangeDetectionStrategy.OnPush,
encapsulation: core.ViewEncapsulation.None
},] }
];
Editor.ctorParameters = function () { return [
{ type: core.ElementRef }
]; };
Editor.propDecorators = {
onTextChange: [{ type: core.Output }],
onSelectionChange: [{ type: core.Output }],
toolbar: [{ type: core.ContentChild, args: [api.Header,] }],
style: [{ type: core.Input }],
styleClass: [{ type: core.Input }],
placeholder: [{ type: core.Input }],
formats: [{ type: core.Input }],
modules: [{ type: core.Input }],
bounds: [{ type: core.Input }],
scrollingContainer: [{ type: core.Input }],
debug: [{ type: core.Input }],
onInit: [{ type: core.Output }],
templates: [{ type: core.ContentChildren, args: [api.PrimeTemplate,] }],
readonly: [{ type: core.Input }]
};
var EditorModule = /** @class */ (function () {
function EditorModule() {
}
return EditorModule;
}());
EditorModule.decorators = [
{ type: core.NgModule, args: [{
imports: [common.CommonModule],
exports: [Editor, api.SharedModule],
declarations: [Editor]
},] }
];
/**
* Generated bundle index. Do not edit.
*/
exports.EDITOR_VALUE_ACCESSOR = EDITOR_VALUE_ACCESSOR;
exports.Editor = Editor;
exports.EditorModule = EditorModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=primeng-editor.umd.js.map