UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

177 lines 13.1 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { NzI18nService } from 'ng-zorro-antd/i18n'; import { NzAutosizeDirective } from 'ng-zorro-antd/input'; export class NzTextEditComponent { /** * @param {?} host * @param {?} cdr * @param {?} i18n */ constructor(host, cdr, i18n) { this.host = host; this.cdr = cdr; this.i18n = i18n; this.editing = false; // tslint:disable-next-line:no-any this.locale = {}; this.destroy$ = new Subject(); this.startEditing = new EventEmitter(); this.endEditing = new EventEmitter(); this.nativeElement = this.host.nativeElement; } /** * @return {?} */ ngOnInit() { this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe((/** * @return {?} */ () => { this.locale = this.i18n.getLocaleData('Text'); this.cdr.markForCheck(); })); } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } /** * @return {?} */ onClick() { this.beforeText = this.text; this.currentText = this.beforeText; this.editing = true; this.startEditing.emit(); this.focusAndSetValue(); } /** * @return {?} */ confirm() { this.editing = false; this.endEditing.emit(this.currentText); } /** * @param {?} event * @return {?} */ onInput(event) { /** @type {?} */ const target = (/** @type {?} */ (event.target)); this.currentText = target.value; } /** * @param {?} event * @return {?} */ onEnter(event) { event.stopPropagation(); event.preventDefault(); this.confirm(); } /** * @return {?} */ onCancel() { this.currentText = this.beforeText; this.confirm(); } /** * @return {?} */ focusAndSetValue() { setTimeout((/** * @return {?} */ () => { if (this.textarea && this.textarea.nativeElement) { this.textarea.nativeElement.focus(); this.textarea.nativeElement.value = this.currentText; this.autosizeDirective.resizeToFitContent(); } })); } } NzTextEditComponent.decorators = [ { type: Component, args: [{ selector: 'nz-text-edit', exportAs: 'nzTextEdit', template: "<button\n *ngIf=\"!editing\"\n [nzTitle]=\"locale?.edit\"\n nz-tooltip\n nz-trans-button\n class=\"ant-typography-edit\"\n (click)=\"onClick()\">\n <i nz-icon nzType=\"edit\"></i>\n</button>\n<ng-container *ngIf=\"editing\">\n <textarea #textarea\n nz-input\n nzAutosize\n (input)=\"onInput($event)\"\n (blur)=\"confirm()\"\n (keydown.esc)=\"onCancel()\"\n (keydown.enter)=\"onEnter($event)\">\n </textarea>\n <button nz-trans-button class=\"ant-typography-edit-content-confirm\" (click)=\"confirm()\">\n <i nz-icon nzType=\"enter\"></i>\n </button>\n</ng-container>\n", changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false }] } ]; /** @nocollapse */ NzTextEditComponent.ctorParameters = () => [ { type: ElementRef }, { type: ChangeDetectorRef }, { type: NzI18nService } ]; NzTextEditComponent.propDecorators = { text: [{ type: Input }], startEditing: [{ type: Output }], endEditing: [{ type: Output }], textarea: [{ type: ViewChild, args: ['textarea', { static: false },] }], autosizeDirective: [{ type: ViewChild, args: [NzAutosizeDirective, { static: false },] }] }; if (false) { /** @type {?} */ NzTextEditComponent.prototype.editing; /** @type {?} */ NzTextEditComponent.prototype.locale; /** * @type {?} * @private */ NzTextEditComponent.prototype.destroy$; /** @type {?} */ NzTextEditComponent.prototype.text; /** @type {?} */ NzTextEditComponent.prototype.startEditing; /** @type {?} */ NzTextEditComponent.prototype.endEditing; /** @type {?} */ NzTextEditComponent.prototype.textarea; /** @type {?} */ NzTextEditComponent.prototype.autosizeDirective; /** @type {?} */ NzTextEditComponent.prototype.beforeText; /** @type {?} */ NzTextEditComponent.prototype.currentText; /** @type {?} */ NzTextEditComponent.prototype.nativeElement; /** * @type {?} * @private */ NzTextEditComponent.prototype.host; /** * @type {?} * @private */ NzTextEditComponent.prototype.cdr; /** * @type {?} * @private */ NzTextEditComponent.prototype.i18n; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnotdGV4dC1lZGl0LmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL25nLXpvcnJvLWFudGQvdHlwb2dyYXBoeS8iLCJzb3VyY2VzIjpbIm56LXRleHQtZWRpdC5jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFRQSxPQUFPLEVBQ0wsdUJBQXVCLEVBQ3ZCLGlCQUFpQixFQUNqQixTQUFTLEVBQ1QsVUFBVSxFQUNWLFlBQVksRUFDWixLQUFLLEVBR0wsTUFBTSxFQUNOLFNBQVMsRUFDVCxpQkFBaUIsRUFDbEIsTUFBTSxlQUFlLENBQUM7QUFFdkIsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUMvQixPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFM0MsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ25ELE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBVTFELE1BQU0sT0FBTyxtQkFBbUI7Ozs7OztJQWU5QixZQUFvQixJQUFnQixFQUFVLEdBQXNCLEVBQVUsSUFBbUI7UUFBN0UsU0FBSSxHQUFKLElBQUksQ0FBWTtRQUFVLFFBQUcsR0FBSCxHQUFHLENBQW1CO1FBQVUsU0FBSSxHQUFKLElBQUksQ0FBZTtRQWRqRyxZQUFPLEdBQUcsS0FBSyxDQUFDOztRQUVoQixXQUFNLEdBQVEsRUFBRSxDQUFDO1FBQ1QsYUFBUSxHQUFHLElBQUksT0FBTyxFQUFFLENBQUM7UUFHZCxpQk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