import { __decorate, __metadata } from 'tslib'; import { EventEmitter, Output, Input, Directive, ContentChildren, QueryList, NgZone, ViewChild, Component, forwardRef, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; /** * CKGroup component * Usage : * * * * */ var CKButtonDirective = /** @class */ (function () { function CKButtonDirective() { this.click = new EventEmitter(); } CKButtonDirective.prototype.initialize = function (editor) { var _this = this; editor.instance.addCommand(this.command, { exec: function (evt) { _this.click.emit(evt); }, }); editor.instance.ui.addButton(this.name, { label: this.label, command: this.command, toolbar: this.toolbar, icon: this.icon, }); }; CKButtonDirective.prototype.ngOnInit = function () { if (!this.name) throw new Error('Attribute "name" is required on '); if (!this.command) throw new Error('Attribute "command" is required on '); }; __decorate([ Output(), __metadata("design:type", Object) ], CKButtonDirective.prototype, "click", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKButtonDirective.prototype, "label", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKButtonDirective.prototype, "command", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKButtonDirective.prototype, "toolbar", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKButtonDirective.prototype, "name", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKButtonDirective.prototype, "icon", void 0); CKButtonDirective = __decorate([ Directive({ selector: 'ckbutton', }) ], CKButtonDirective); return CKButtonDirective; }()); /** * CKGroup component * Usage : * * * . * . * * */ var CKGroupDirective = /** @class */ (function () { function CKGroupDirective() { } CKGroupDirective.prototype.ngAfterContentInit = function () { var _this = this; // Reconfigure each button's toolbar property within ckgroup to hold its parent's name this.toolbarButtons.forEach(function (button) { return (button.toolbar = _this.name); }); }; CKGroupDirective.prototype.initialize = function (editor) { editor.instance.ui.addToolbarGroup(this.name, this.previous, this.subgroupOf); // Initialize each button within ckgroup this.toolbarButtons.forEach(function (button) { button.initialize(editor); }); }; __decorate([ Input(), __metadata("design:type", String) ], CKGroupDirective.prototype, "name", void 0); __decorate([ Input(), __metadata("design:type", Object) ], CKGroupDirective.prototype, "previous", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKGroupDirective.prototype, "subgroupOf", void 0); __decorate([ ContentChildren(CKButtonDirective), __metadata("design:type", QueryList) ], CKGroupDirective.prototype, "toolbarButtons", void 0); CKGroupDirective = __decorate([ Directive({ selector: 'ckgroup', }) ], CKGroupDirective); return CKGroupDirective; }()); /** * CKEditor component * Usage : * */ var CKEditorComponent = /** @class */ (function () { /** * Constructor */ function CKEditorComponent(zone) { this.zone = zone; this.change = new EventEmitter(); this.editorChange = new EventEmitter(); this.ready = new EventEmitter(); this.blur = new EventEmitter(); this.focus = new EventEmitter(); this.contentDom = new EventEmitter(); this.fileUploadRequest = new EventEmitter(); this.fileUploadResponse = new EventEmitter(); this.paste = new EventEmitter(); this.drop = new EventEmitter(); this._value = ''; } CKEditorComponent_1 = CKEditorComponent; Object.defineProperty(CKEditorComponent.prototype, "value", { get: function () { return this._value; }, set: function (v) { if (v !== this._value) { this._value = v; this.onChange(v); } }, enumerable: true, configurable: true }); CKEditorComponent.prototype.ngOnChanges = function (changes) { if (changes.readonly && this.instance) { this.instance.setReadOnly(changes.readonly.currentValue); } }; /** * On component destroy */ CKEditorComponent.prototype.ngOnDestroy = function () { if (this.instance) { this.instance.removeAllListeners(); CKEDITOR.instances[this.instance.name].destroy(); this.instance.destroy(); this.instance = null; } }; /** * On component view init */ CKEditorComponent.prototype.ngAfterViewInit = function () { this.ckeditorInit(this.config || {}); }; /** * On component view checked */ CKEditorComponent.prototype.ngAfterViewChecked = function () { this.ckeditorInit(this.config || {}); }; /** * Value update process */ CKEditorComponent.prototype.updateValue = function (value) { var _this = this; this.zone.run(function () { _this.value = value; _this.onChange(value); _this.onTouched(); _this.change.emit(value); }); }; /** * CKEditor init */ CKEditorComponent.prototype.ckeditorInit = function (config) { var _this = this; if (typeof CKEDITOR === 'undefined') { console.warn('CKEditor 4.x is missing (http://ckeditor.com/)'); } else { // Check textarea exists if (this.instance || !this.documentContains(this.host.nativeElement)) { return; } if (this.readonly) { config.readOnly = this.readonly; } // CKEditor replace textarea this.instance = CKEDITOR.replace(this.host.nativeElement, config); // Set initial value this.instance.setData(this.value); // listen for instanceReady event this.instance.on('instanceReady', function (evt) { // if value has changed while instance loading // update instance with current component value if (_this.instance.getData() !== _this.value) { _this.instance.setData(_this.value); } // send the evt to the EventEmitter _this.ready.emit(evt); }); // CKEditor change event this.instance.on('change', function (evt) { _this.onTouched(); var value = _this.instance.getData(); if (_this.value !== value) { // Debounce update if (_this.debounce) { if (_this.debounceTimeout) clearTimeout(_this.debounceTimeout); _this.debounceTimeout = setTimeout(function () { _this.updateValue(value); _this.debounceTimeout = null; }, parseInt(_this.debounce)); // Live update } else { _this.updateValue(value); } } // Original ckeditor event dispatch _this.editorChange.emit(evt); }); // CKEditor blur event this.instance.on('blur', function (evt) { _this.blur.emit(evt); }); // CKEditor focus event this.instance.on('focus', function (evt) { _this.focus.emit(evt); }); // CKEditor contentDom event this.instance.on('contentDom', function (evt) { _this.contentDom.emit(evt); }); // CKEditor fileUploadRequest event this.instance.on('fileUploadRequest', function (evt) { _this.fileUploadRequest.emit(evt); }); // CKEditor fileUploadResponse event this.instance.on('fileUploadResponse', function (evt) { _this.fileUploadResponse.emit(evt); }); // CKEditor paste event this.instance.on('paste', function (evt) { _this.paste.emit(evt); }); // CKEditor drop event this.instance.on('drop', function (evt) { _this.drop.emit(evt); }); // Add Toolbar Groups to Editor. This will also add Buttons within groups. this.toolbarGroups.forEach(function (group) { group.initialize(_this); }); // Add Toolbar Buttons to Editor. this.toolbarButtons.forEach(function (button) { button.initialize(_this); }); } }; /** * Implements ControlValueAccessor */ CKEditorComponent.prototype.writeValue = function (value) { this._value = value; if (this.instance) this.instance.setData(value); }; CKEditorComponent.prototype.onChange = function (_) { }; CKEditorComponent.prototype.onTouched = function () { }; CKEditorComponent.prototype.registerOnChange = function (fn) { this.onChange = fn; }; CKEditorComponent.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; CKEditorComponent.prototype.documentContains = function (node) { return document.contains ? document.contains(node) : document.body.contains(node); }; var CKEditorComponent_1; CKEditorComponent.ctorParameters = function () { return [ { type: NgZone } ]; }; __decorate([ Input(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "config", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], CKEditorComponent.prototype, "readonly", void 0); __decorate([ Input(), __metadata("design:type", String) ], CKEditorComponent.prototype, "debounce", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "change", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "editorChange", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "ready", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "blur", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "focus", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "contentDom", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "fileUploadRequest", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "fileUploadResponse", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "paste", void 0); __decorate([ Output(), __metadata("design:type", Object) ], CKEditorComponent.prototype, "drop", void 0); __decorate([ ViewChild('host', { static: false }), __metadata("design:type", Object) ], CKEditorComponent.prototype, "host", void 0); __decorate([ ContentChildren(CKButtonDirective), __metadata("design:type", QueryList) ], CKEditorComponent.prototype, "toolbarButtons", void 0); __decorate([ ContentChildren(CKGroupDirective), __metadata("design:type", QueryList) ], CKEditorComponent.prototype, "toolbarGroups", void 0); __decorate([ Input(), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], CKEditorComponent.prototype, "value", null); CKEditorComponent = CKEditorComponent_1 = __decorate([ Component({ selector: 'ckeditor', providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(function () { return CKEditorComponent_1; }), multi: true, }, ], template: "\n \n " }), __metadata("design:paramtypes", [NgZone]) ], CKEditorComponent); return CKEditorComponent; }()); /** * CKEditorModule */ var CKEditorModule = /** @class */ (function () { function CKEditorModule() { } CKEditorModule = __decorate([ NgModule({ imports: [CommonModule], declarations: [CKEditorComponent, CKButtonDirective, CKGroupDirective], exports: [CKEditorComponent, CKButtonDirective, CKGroupDirective], }) ], CKEditorModule); return CKEditorModule; }()); /** * Generated bundle index. Do not edit. */ export { CKEditorModule, CKEditorComponent as ɵa, CKButtonDirective as ɵb, CKGroupDirective as ɵc }; //# sourceMappingURL=ng2-ckeditor.js.map