primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://gitter.im/primefaces/primeng?ut
171 lines • 8.93 kB
JavaScript
"use strict";
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");
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, domHandler) {
this.el = el;
this.domHandler = domHandler;
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 = this.domHandler.findSingle(this.el.nativeElement, 'div.ui-editor-content');
var toolbarElement = this.domHandler.findSingle(this.el.nativeElement, 'div.ui-editor-toolbar');
this.quill = new Quill(editorElement, {
modules: {
toolbar: toolbarElement
},
placeholder: this.placeholder,
readOnly: this.readonly,
theme: 'snow',
formats: this.formats
});
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 (text.length === 0) {
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),
__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.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 <div [ngClass]=\"'ui-widget ui-editor-container ui-corner-all'\" [class]=\"styleClass\">\n <div class=\"ui-editor-toolbar ui-widget-header ui-corner-top\" *ngIf=\"toolbar\">\n <ng-content select=\"p-header\"></ng-content>\n </div>\n <div class=\"ui-editor-toolbar ui-widget-header ui-corner-top\" *ngIf=\"!toolbar\">\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\"></button>\n <button class=\"ql-italic\" aria-label=\"Italic\"></button>\n <button class=\"ql-underline\" aria-label=\"Underline\"></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\"></button>\n <button class=\"ql-list\" value=\"bullet\" aria-label=\"Unordered List\"></button>\n <select class=\"ql-align\">\n <option selected></option>\n <option value=\"center\"></option>\n <option value=\"right\"></option>\n <option value=\"justify\"></option>\n </select>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-link\" aria-label=\"Insert Link\"></button>\n <button class=\"ql-image\" aria-label=\"Insert Image\"></button>\n <button class=\"ql-code-block\" aria-label=\"Insert Code Block\"></button>\n </span>\n <span class=\"ql-formats\">\n <button class=\"ql-clean\" aria-label=\"Remove Styles\"></button>\n </span>\n </div>\n <div class=\"ui-editor-content\" [ngStyle]=\"style\"></div>\n </div>\n ",
providers: [domhandler_1.DomHandler, exports.EDITOR_VALUE_ACCESSOR]
}),
__metadata("design:paramtypes", [core_1.ElementRef, domhandler_1.DomHandler])
], 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