UNPKG

@nbxx/nb-input

Version:
104 lines (103 loc) 3.49 kB
import { Component, forwardRef, Input } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { NbinputConfig, NbFieldType } from './nbinput.entity'; export class NbinputFroalaComponent { constructor() { this.FieldType = NbFieldType; this._config = new NbinputConfig(); this.onTouchedCallback = () => { }; this.onChangeCallback = (_) => { }; this.data = ''; this.type = NbFieldType.Html; this.readonly = false; this.refreshOption(); } set config(v) { if (v) { this._config = v; this.refreshOption(); } } get config() { return this._config; } refreshOption() { this.options = { placeholderText: '点击这里开始输入', imageUploadURL: this._config.uploadAPI + '?token=' + this._config.token, imageUploadParams: { token: this._config.token }, language: 'zh_cn', events: { 'froalaEditor.image.uploaded': (e, editor, response) => { try { const resp = JSON.parse(response); const url = resp && resp.data ? resp.data.url : ''; editor.image.insert((this._config ? this._config.downloadAPI : '') + url + (this._config.token && this._config.token.length > 0 ? '?token=' + this._config.token : ''), false, null, editor.image.get(), response); } catch (f) { console.warn('文件上传失败:', f); } return false; } } }; } get value() { return this.data; } ; set value(v) { if (v !== this.data) { this.data = v; this.onChangeCallback(v); } } registerOnChange(fn) { if (fn) { this.onChangeCallback = fn; } } registerOnTouched(fn) { if (fn) { this.onTouchedCallback = fn; } } setDisabledState(isDisabled) { this.disabled = isDisabled; } writeValue(obj) { if (obj) { this.data = obj; } } onChange(e) { this.onChangeCallback(e); } } NbinputFroalaComponent.decorators = [ { type: Component, args: [{ selector: 'nbinput-froala', template: ` <ng-container *ngIf="readonly;else ELSEBLOCK"> <div [froalaView]="data"></div> </ng-container> <ng-template #ELSEBLOCK> <textarea [froalaEditor]="options" (froalaModelChange)="onChange($event)" [(froalaModel)]="data" [disabled]="disabled" >{{placeholder}}</textarea> </ng-template> `, styles: [` `], providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NbinputFroalaComponent), multi: true } ] },] }, ]; /** @nocollapse */ NbinputFroalaComponent.ctorParameters = () => []; NbinputFroalaComponent.propDecorators = { config: [{ type: Input }], data: [{ type: Input }], disabled: [{ type: Input }], placeholder: [{ type: Input }], type: [{ type: Input }], readonly: [{ type: Input }] }; //# sourceMappingURL=nbinput-froala.component.js.map