UNPKG

@duoduo-oba/ng-devui

Version:

DevUI components based on Angular

1,287 lines (1,278 loc) 69.9 kB
import { EventEmitter, Component, Input, Output, ViewChild, Injectable, Directive, ElementRef, HostListener, NgModule } from '@angular/core'; import { __spread, __extends } from 'tslib'; import { toArray, mergeMap, map, last, debounceTime } from 'rxjs/operators'; import { from, merge, Observable } from 'rxjs'; import { I18nService } from '@duoduo-oba/ng-devui/i18n'; import { CommonModule } from '@angular/common'; import endsWith from 'lodash-es/endsWith'; import { ModalAlertComponent, ModalService, ModalModule } from '@duoduo-oba/ng-devui/modal'; import { ButtonModule } from '@duoduo-oba/ng-devui/button'; /** * @fileoverview added by tsickle * Generated from: file-uploader.types.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var IUploadOptions = /** @class */ (function () { function IUploadOptions() { } return IUploadOptions; }()); if (false) { /** @type {?} */ IUploadOptions.prototype.uri; /** @type {?} */ IUploadOptions.prototype.method; /** @type {?} */ IUploadOptions.prototype.maximumSize; /** @type {?} */ IUploadOptions.prototype.headers; /** @type {?} */ IUploadOptions.prototype.authToken; /** @type {?} */ IUploadOptions.prototype.authTokenHeader; /** @type {?} */ IUploadOptions.prototype.additionalParameter; /** @type {?} */ IUploadOptions.prototype.fileFieldName; /** @type {?} */ IUploadOptions.prototype.checkSameName; /** @type {?} */ IUploadOptions.prototype.withCredentials; } var IFileOptions = /** @class */ (function () { function IFileOptions() { } return IFileOptions; }()); if (false) { /** @type {?} */ IFileOptions.prototype.accept; /** @type {?} */ IFileOptions.prototype.multiple; } /** @enum {number} */ var UploadStatus = { preLoad: 0, uploading: 1, uploaded: 2, failed: 3, }; UploadStatus[UploadStatus.preLoad] = 'preLoad'; UploadStatus[UploadStatus.uploading] = 'uploading'; UploadStatus[UploadStatus.uploaded] = 'uploaded'; UploadStatus[UploadStatus.failed] = 'failed'; /** * @fileoverview added by tsickle * Generated from: file-uploader.class.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var FileUploader = /** @class */ (function () { function FileUploader(file, uploadOptions) { this.file = file; this.uploadOptions = uploadOptions; this.percentage = 0; this.file = file; this.uploadOptions = uploadOptions; this.status = UploadStatus.preLoad; } /** * @return {?} */ FileUploader.prototype.send = /** * @return {?} */ function () { var _this = this; return new Promise((/** * @param {?} resolve * @param {?} reject * @return {?} */ function (resolve, reject) { var _a = _this.uploadOptions, uri = _a.uri, method = _a.method, headers = _a.headers, authToken = _a.authToken, authTokenHeader = _a.authTokenHeader, additionalParameter = _a.additionalParameter, fileFieldName = _a.fileFieldName, withCredentials = _a.withCredentials; /** @type {?} */ var authTokenHeader_ = authTokenHeader || 'Authorization'; /** @type {?} */ var fileFieldName_ = fileFieldName || 'file'; _this.xhr = new XMLHttpRequest(); _this.xhr.open(method || 'POST', uri); if (withCredentials) { _this.xhr.withCredentials = withCredentials; } if (authToken) { _this.xhr.setRequestHeader(authTokenHeader_, authToken); } if (headers) { Object.keys(headers).forEach((/** * @param {?} key * @return {?} */ function (key) { _this.xhr.setRequestHeader(key, headers[key]); })); } _this.xhr.upload.onprogress = (/** * @param {?} e * @return {?} */ function (e) { _this.percentage = Math.round(e.loaded * 100 / e.total); }); /** @type {?} */ var formData = new FormData(); formData.append(fileFieldName_, _this.file); if (additionalParameter) { Object.keys(additionalParameter).forEach((/** * @param {?} key * @return {?} */ function (key) { formData.append(key, additionalParameter[key]); })); } _this.xhr.send(formData); _this.status = UploadStatus.uploading; _this.xhr.onabort = (/** * @return {?} */ function () { _this.status = UploadStatus.preLoad; _this.xhr = null; }); _this.xhr.onerror = (/** * @return {?} */ function () { _this.response = _this.xhr.response; _this.status = UploadStatus.failed; reject(new Error('Upload failed in some reason.')); }); _this.xhr.onload = (/** * @return {?} */ function () { if (_this.xhr.readyState === 4 && _this.xhr.status >= 200 && _this.xhr.status < 300) { _this.response = _this.xhr.response; _this.status = UploadStatus.uploaded; resolve({ file: _this.file, response: _this.xhr.response }); } else { _this.response = _this.xhr.response; _this.status = UploadStatus.failed; reject({ file: _this.file, response: _this.xhr.response }); } }); })); }; /** * @return {?} */ FileUploader.prototype.cancel = /** * @return {?} */ function () { if (this.xhr) { this.xhr.abort(); } }; return FileUploader; }()); if (false) { /** * @type {?} * @private */ FileUploader.prototype.xhr; /** @type {?} */ FileUploader.prototype.status; /** @type {?} */ FileUploader.prototype.response; /** @type {?} */ FileUploader.prototype.percentage; /** @type {?} */ FileUploader.prototype.file; /** * @type {?} * @private */ FileUploader.prototype.uploadOptions; } /** * @fileoverview added by tsickle * Generated from: upload.class.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var UploadComponent = /** @class */ (function () { function UploadComponent() { this.fileUploaders = []; this.filesWithSameName = []; } /** * @param {?} file * @param {?} options * @return {?} */ UploadComponent.prototype.addFile = /** * @param {?} file * @param {?} options * @return {?} */ function (file, options) { if (options.checkSameName) { if (this.checkFileSame(file.name)) { this.fileUploaders.push(new FileUploader(file, options)); } } else { this.fileUploaders.push(new FileUploader(file, options)); } }; /** * @param {?} fileName * @return {?} */ UploadComponent.prototype.checkFileSame = /** * @param {?} fileName * @return {?} */ function (fileName) { /** @type {?} */ var checkRel = true; for (var i = 0; i < this.fileUploaders.length; i++) { if (fileName === this.fileUploaders[i].file.name) { checkRel = false; if (this.filesWithSameName.indexOf(fileName) === -1) { this.filesWithSameName.push(fileName); } break; } } return checkRel; }; /** * @return {?} */ UploadComponent.prototype.getFiles = /** * @return {?} */ function () { return this.fileUploaders.map((/** * @param {?} fileUploader * @return {?} */ function (fileUploader) { return fileUploader.file; })); }; /** * @return {?} */ UploadComponent.prototype.upload = /** * @return {?} */ function () { /** @type {?} */ var uploads = this.fileUploaders .filter((/** * @param {?} fileUploader * @return {?} */ function (fileUploader) { return fileUploader.status !== UploadStatus.uploaded; })) .map((/** * @param {?} fileUploader * @return {?} */ function (fileUploader) { return from(fileUploader.send()); })); if (uploads.length > 0) { return merge.apply(void 0, __spread(uploads)).pipe(toArray()); } return from(Promise.reject('no files')); }; /** * @param {?} file * @return {?} */ UploadComponent.prototype.deleteFile = /** * @param {?} file * @return {?} */ function (file) { this.fileUploaders = this.fileUploaders.filter((/** * @param {?} fileUploader * @return {?} */ function (fileUploader) { return file !== fileUploader.file; })); }; /** * @return {?} */ UploadComponent.prototype.removeFiles = /** * @return {?} */ function () { this.fileUploaders = []; this.filesWithSameName = []; }; /** * @return {?} */ UploadComponent.prototype.getSameNameFiles = /** * @return {?} */ function () { return this.filesWithSameName.join(); }; /** * @return {?} */ UploadComponent.prototype.resetSameNameFiles = /** * @return {?} */ function () { this.filesWithSameName = []; }; return UploadComponent; }()); if (false) { /** @type {?} */ UploadComponent.prototype.fileUploaders; /** @type {?} */ UploadComponent.prototype.filesWithSameName; } /** * @fileoverview added by tsickle * Generated from: uploaded-files.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var UploadedFilesComponent = /** @class */ (function () { function UploadedFilesComponent(i18n) { var _this = this; this.i18n = i18n; this.uploadedFiles = []; this.deleteUploadedFileEvent = new EventEmitter(); // 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题 this.deleteFileProxy = (/** * @param {?} filePath * @return {?} */ function (filePath) { _this.deleteFile(filePath); }); this.i18nText = this.i18n.getI18nText().upload; this.i18nSubscription = this.i18n.langChange().subscribe((/** * @param {?} data * @return {?} */ function (data) { _this.i18nText = data.upload; })); } /** * @return {?} */ UploadedFilesComponent.prototype.cleanUploadedFiles = /** * @return {?} */ function () { this.uploadedFiles = []; }; /** * @param {?} file * @return {?} */ UploadedFilesComponent.prototype.addAndOverwriteFile = /** * @param {?} file * @return {?} */ function (file) { this.cleanUploadedFiles(); this.uploadedFiles.push(file); }; /** * @param {?} file * @return {?} */ UploadedFilesComponent.prototype.addFile = /** * @param {?} file * @return {?} */ function (file) { this.uploadedFiles.push(file); }; /** * @param {?} filePath * @return {?} */ UploadedFilesComponent.prototype.deleteFile = /** * @param {?} filePath * @return {?} */ function (filePath) { var _this = this; this.uploadedFiles = this.uploadedFiles.filter((/** * @param {?} file * @return {?} */ function (file) { return filePath !== ((/** @type {?} */ (file)))[_this.filePath]; })); this.deleteUploadedFileEvent.emit(filePath); }; /** * @return {?} */ UploadedFilesComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.i18nSubscription) { this.i18nSubscription.unsubscribe(); } }; UploadedFilesComponent.decorators = [ { type: Component, args: [{ selector: 'd-uploaded-files', exportAs: 'dUploadFiles', template: "<ng-template\r\n [ngTemplateOutlet]=\"uploadedFilesRef ? uploadedFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, uploadedFiles: uploadedFiles, filePath: filePath, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n\r\n<ng-template #default>\r\n <table class=\"devui-table\" *ngIf=\"uploadedFiles.length > 0\" [style.margin-bottom.px]=\"0\">\r\n <tbody>\r\n <tr *ngFor=\"let uploadedFile of uploadedFiles; let index = index\">\r\n <td width=\"50%\">\r\n <span>{{ uploadedFile.name }}</span>\r\n </td>\r\n <td width=\"25%\">\r\n <span>{{ i18nText?.upload }}</span>\r\n </td>\r\n <td>\r\n <d-button icon=\"trash\" bsStyle=\"danger\" bsSize=\"xs\" (btnClick)=\"deleteFile(uploadedFile[filePath])\">\r\n {{ i18nText?.delete }}\r\n </d-button>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n</ng-template>\r\n", styles: ["table.devui-table{width:100%;max-width:100%;margin-bottom:20px}table.devui-table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}.devui-upload-input{padding:5px 25px 5px 10px!important;cursor:pointer;text-overflow:ellipsis}"] }] } ]; /** @nocollapse */ UploadedFilesComponent.ctorParameters = function () { return [ { type: I18nService } ]; }; UploadedFilesComponent.propDecorators = { uploadedFiles: [{ type: Input }], uploadedFilesRef: [{ type: Input }], filePath: [{ type: Input }], deleteUploadedFileEvent: [{ type: Output }] }; return UploadedFilesComponent; }()); if (false) { /** @type {?} */ UploadedFilesComponent.prototype.uploadedFiles; /** @type {?} */ UploadedFilesComponent.prototype.uploadedFilesRef; /** @type {?} */ UploadedFilesComponent.prototype.filePath; /** @type {?} */ UploadedFilesComponent.prototype.deleteUploadedFileEvent; /** @type {?} */ UploadedFilesComponent.prototype.i18nText; /** @type {?} */ UploadedFilesComponent.prototype.i18nSubscription; /** @type {?} */ UploadedFilesComponent.prototype.deleteFileProxy; /** * @type {?} * @private */ UploadedFilesComponent.prototype.i18n; } /** * @fileoverview added by tsickle * Generated from: multiple-upload-view.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var MultipleUploadViewComponent = /** @class */ (function (_super) { __extends(MultipleUploadViewComponent, _super); function MultipleUploadViewComponent(i18n) { var _this = _super.call(this) || this; _this.i18n = i18n; _this.uploadedFiles = []; _this.deleteUploadedFileEvent = new EventEmitter(); _this.UploadStatus = UploadStatus; _this.fileUploaders = []; // 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题 _this.deleteFileProxy = (/** * @param {?} file * @return {?} */ function (file) { _this.deleteFile(file); }); _this.i18nText = _this.i18n.getI18nText().upload; _this.i18nSubscription = _this.i18n.langChange().subscribe((/** * @param {?} data * @return {?} */ function (data) { _this.i18nText = data.upload; })); return _this; } /** * @param {?} file * @return {?} */ MultipleUploadViewComponent.prototype.addFile = /** * @param {?} file * @return {?} */ function (file) { _super.prototype.addFile.call(this, file, this.uploadOptions); }; /** * @param {?} file * @return {?} */ MultipleUploadViewComponent.prototype.deleteFile = /** * @param {?} file * @return {?} */ function (file) { _super.prototype.deleteFile.call(this, file); this.deleteUploadedFileEvent.emit(file); }; /** * @return {?} */ MultipleUploadViewComponent.prototype.removeFiles = /** * @return {?} */ function () { _super.prototype.removeFiles.call(this); }; /** * @param {?} filePath * @return {?} */ MultipleUploadViewComponent.prototype._onDeleteUploadedFile = /** * @param {?} filePath * @return {?} */ function (filePath) { this.deleteUploadedFileEvent.emit(filePath); }; /** * @return {?} */ MultipleUploadViewComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.i18nSubscription) { this.i18nSubscription.unsubscribe(); } }; MultipleUploadViewComponent.decorators = [ { type: Component, args: [{ selector: 'd-multiple-upload-view', template: "<d-uploaded-files\r\n #dUploadedFiles\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [filePath]=\"filePath\"\r\n [uploadedFilesRef]=\"uploadedFilesRef\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-uploaded-files>\r\n<ng-template\r\n [ngTemplateOutlet]=\"preloadFilesRef ? preloadFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, fileUploaders: fileUploaders, UploadStatus: UploadStatus, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n<ng-template #default>\r\n <table class=\"devui-table\" *ngIf=\"fileUploaders.length > 0\">\r\n <tr *ngFor=\"let fileUploader of fileUploaders; let index = index\">\r\n <td width=\"50%\">\r\n <span>{{ fileUploader.file.name }}</span>\r\n </td>\r\n <td width=\"25%\">\r\n <span *ngIf=\"fileUploader.status === UploadStatus.preLoad\">{{ i18nText?.preload }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.uploading\">{{ i18nText?.uploading }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.uploaded\">{{ i18nText?.uploaded }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.failed\">{{ i18nText?.uploadFailed }}</span>\r\n </td>\r\n <td>\r\n <d-button\r\n bordered=\"true\"\r\n icon=\"trash\"\r\n bsStyle=\"danger\"\r\n bsSize=\"xs\"\r\n *ngIf=\"fileUploader.status !== UploadStatus.uploaded\"\r\n [disabled]=\"fileUploader.status === UploadStatus.uploading\"\r\n (btnClick)=\"deleteFile(fileUploader.file)\"\r\n >\r\n {{ i18nText?.delete }}\r\n </d-button>\r\n </td>\r\n </tr>\r\n </table>\r\n</ng-template>\r\n", styles: [".devui-table>tbody>tr:first-child td{border-top:none}table.devui-table{width:100%;max-width:100%;margin-bottom:20px}table.devui-table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}"] }] } ]; /** @nocollapse */ MultipleUploadViewComponent.ctorParameters = function () { return [ { type: I18nService } ]; }; MultipleUploadViewComponent.propDecorators = { uploadedFilesComponent: [{ type: ViewChild, args: ['dUploadedFiles', { static: true },] }], uploadOptions: [{ type: Input }], preloadFilesRef: [{ type: Input }], uploadedFiles: [{ type: Input }], uploadedFilesRef: [{ type: Input }], filePath: [{ type: Input }], deleteUploadedFileEvent: [{ type: Output }] }; return MultipleUploadViewComponent; }(UploadComponent)); if (false) { /** @type {?} */ MultipleUploadViewComponent.prototype.uploadedFilesComponent; /** @type {?} */ MultipleUploadViewComponent.prototype.uploadOptions; /** @type {?} */ MultipleUploadViewComponent.prototype.preloadFilesRef; /** @type {?} */ MultipleUploadViewComponent.prototype.uploadedFiles; /** @type {?} */ MultipleUploadViewComponent.prototype.uploadedFilesRef; /** @type {?} */ MultipleUploadViewComponent.prototype.filePath; /** @type {?} */ MultipleUploadViewComponent.prototype.deleteUploadedFileEvent; /** @type {?} */ MultipleUploadViewComponent.prototype.UploadStatus; /** @type {?} */ MultipleUploadViewComponent.prototype.fileUploaders; /** @type {?} */ MultipleUploadViewComponent.prototype.i18nText; /** @type {?} */ MultipleUploadViewComponent.prototype.i18nSubscription; /** @type {?} */ MultipleUploadViewComponent.prototype.deleteFileProxy; /** * @type {?} * @private */ MultipleUploadViewComponent.prototype.i18n; } /** * @fileoverview added by tsickle * Generated from: single-upload-view.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var SingleUploadViewComponent = /** @class */ (function (_super) { __extends(SingleUploadViewComponent, _super); function SingleUploadViewComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.uploadedFiles = []; _this.deleteUploadedFileEvent = new EventEmitter(); _this.UploadStatus = UploadStatus; _this.fileUploaders = []; // 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题 _this.deleteFileProxy = (/** * @param {?} file * @return {?} */ function (file) { _this.deleteFile(file); }); return _this; } /** * @param {?} file * @return {?} */ SingleUploadViewComponent.prototype.addFile = /** * @param {?} file * @return {?} */ function (file) { this.fileUploaders = []; _super.prototype.addFile.call(this, file, this.uploadOptions); }; /** * @param {?} file * @return {?} */ SingleUploadViewComponent.prototype.deleteFile = /** * @param {?} file * @return {?} */ function (file) { _super.prototype.deleteFile.call(this, file); this.deleteUploadedFileEvent.emit(file); }; /** * @param {?} filePath * @return {?} */ SingleUploadViewComponent.prototype._onDeleteUploadedFile = /** * @param {?} filePath * @return {?} */ function (filePath) { this.deleteUploadedFileEvent.emit(filePath); }; SingleUploadViewComponent.decorators = [ { type: Component, args: [{ selector: 'd-single-upload-view', exportAs: 'dSingleUploadView', template: "<d-uploaded-files\r\n #dUploadedFiles\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [filePath]=\"filePath\"\r\n [uploadedFilesRef]=\"uploadedFilesRef || default\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-uploaded-files>\r\n<ng-template\r\n [ngTemplateOutlet]=\"preloadFilesRef ? preloadFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, fileUploaders: fileUploaders, UploadStatus: UploadStatus, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n<ng-template #default> </ng-template>\r\n", styles: [".devui-table>tbody>tr:first-child td{border-top:none}"] }] } ]; SingleUploadViewComponent.propDecorators = { uploadOptions: [{ type: Input }], preloadFilesRef: [{ type: Input }], uploadedFiles: [{ type: Input }], uploadedFilesRef: [{ type: Input }], filePath: [{ type: Input }], deleteUploadedFileEvent: [{ type: Output }], uploadedFilesComponent: [{ type: ViewChild, args: ['dUploadedFiles', { static: true },] }] }; return SingleUploadViewComponent; }(UploadComponent)); if (false) { /** @type {?} */ SingleUploadViewComponent.prototype.uploadOptions; /** @type {?} */ SingleUploadViewComponent.prototype.preloadFilesRef; /** @type {?} */ SingleUploadViewComponent.prototype.uploadedFiles; /** @type {?} */ SingleUploadViewComponent.prototype.uploadedFilesRef; /** @type {?} */ SingleUploadViewComponent.prototype.filePath; /** @type {?} */ SingleUploadViewComponent.prototype.deleteUploadedFileEvent; /** @type {?} */ SingleUploadViewComponent.prototype.uploadedFilesComponent; /** @type {?} */ SingleUploadViewComponent.prototype.UploadStatus; /** @type {?} */ SingleUploadViewComponent.prototype.fileUploaders; /** @type {?} */ SingleUploadViewComponent.prototype.deleteFileProxy; } /** * @fileoverview added by tsickle * Generated from: select-files.utils.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var SelectFiles = /** @class */ (function () { function SelectFiles(i18n) { var _this = this; this.i18n = i18n; this.selectFiles = (/** * @param {?} __0 * @return {?} */ function (_a) { var multiple = _a.multiple, accept = _a.accept; return new Promise((/** * @param {?} resolve * @return {?} */ function (resolve) { /** @type {?} */ var tempNode = document.getElementById('d-upload-temp'); if (tempNode) { document.body.removeChild(tempNode); } /** @type {?} */ var input = document.createElement('input'); input.style.position = 'fixed'; input.style.left = '-2000px'; input.style.top = '-2000px'; input.setAttribute('id', 'd-upload-temp'); input.setAttribute('type', 'file'); if (multiple) { input.setAttribute('multiple', ''); } if (accept) { input.setAttribute('accept', accept); } input.addEventListener('change', (/** * @param {?} event * @return {?} */ function (event) { resolve(Array.prototype.slice.call(((/** @type {?} */ (event.target))).files)); })); document.body.appendChild(input); // Fix campatability issue with Internet Explorer 11 _this.simulateClickEvent(input); })); }); this.isAllowedFileType = (/** * @param {?} accept * @param {?} file * @return {?} */ function (accept, file) { if (accept) { /** @type {?} */ var acceptArr = accept.split(','); return acceptArr.reduce((/** * @param {?} result * @param {?} item * @return {?} */ function (result, item) { return result || file.type.indexOf(item.replace(/[\.*]/g, '')) > -1 || endsWith(file.name, item); }), false); } return true; }); this.beyondMaximalSize = (/** * @param {?} fileSize * @param {?} maximumSize * @return {?} */ function (fileSize, maximumSize) { if (maximumSize) { return fileSize > 1000000 * maximumSize; } return false; }); this.triggerSelectFiles = (/** * @param {?} fileOptions * @param {?} uploadOptions * @return {?} */ function (fileOptions, uploadOptions) { var multiple = fileOptions.multiple, accept = fileOptions.accept; return _this._validateFiles(from(_this.selectFiles({ multiple: multiple, accept: accept })), accept, uploadOptions); }); this.triggerDropFiles = (/** * @param {?} fileOptions * @param {?} uploadOptions * @param {?} files * @return {?} */ function (fileOptions, uploadOptions, files) { var multiple = fileOptions.multiple, accept = fileOptions.accept; return _this._validateFiles(new Observable((/** * @param {?} observer * @return {?} */ function (observer) { return observer.next(files); })), accept, uploadOptions); }); this.i18nText = this.i18n.getI18nText().upload; this.i18nSubscription = this.i18n.langChange().subscribe((/** * @param {?} data * @return {?} */ function (data) { _this.i18nText = data.upload; })); } /** * @param {?} observable * @param {?} accept * @param {?} uploadOptions * @return {?} */ SelectFiles.prototype._validateFiles = /** * @param {?} observable * @param {?} accept * @param {?} uploadOptions * @return {?} */ function (observable, accept, uploadOptions) { var _this = this; return observable.pipe(mergeMap((/** * @param {?} file * @return {?} */ function (file) { return (/** @type {?} */ (file)); })), map((/** * @param {?} file * @return {?} */ function (file) { if (!_this.isAllowedFileType(accept, (/** @type {?} */ (file)))) { _this.NOT_ALLOWED_FILE_TYPE_MSG = _this.i18nText.getNotAllowedFileTypeMsg(((/** @type {?} */ (file))).name, accept); throw new Error(_this.NOT_ALLOWED_FILE_TYPE_MSG); } if (_this.beyondMaximalSize(((/** @type {?} */ (file))).size, uploadOptions.maximumSize)) { _this.BEYOND_MAXIMAL_FILE_SIZE_MSG = _this.i18nText.getBeyondMaximalFileSizeMsg(((/** @type {?} */ (file))).size, uploadOptions.maximumSize); throw new Error(_this.BEYOND_MAXIMAL_FILE_SIZE_MSG); } return file; }))); }; /** * @param {?} input * @return {?} */ SelectFiles.prototype.simulateClickEvent = /** * @param {?} input * @return {?} */ function (input) { /** @type {?} */ var evt = document.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); input.dispatchEvent(evt); }; SelectFiles.decorators = [ { type: Injectable } ]; /** @nocollapse */ SelectFiles.ctorParameters = function () { return [ { type: I18nService } ]; }; return SelectFiles; }()); if (false) { /** @type {?} */ SelectFiles.prototype.NOT_ALLOWED_FILE_TYPE_MSG; /** @type {?} */ SelectFiles.prototype.BEYOND_MAXIMAL_FILE_SIZE_MSG; /** @type {?} */ SelectFiles.prototype.i18nText; /** @type {?} */ SelectFiles.prototype.i18nSubscription; /** @type {?} */ SelectFiles.prototype.selectFiles; /** @type {?} */ SelectFiles.prototype.isAllowedFileType; /** @type {?} */ SelectFiles.prototype.beyondMaximalSize; /** @type {?} */ SelectFiles.prototype.triggerSelectFiles; /** @type {?} */ SelectFiles.prototype.triggerDropFiles; /** * @type {?} * @private */ SelectFiles.prototype.i18n; } /** * @fileoverview added by tsickle * Generated from: single-upload.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var SingleUploadComponent = /** @class */ (function () { function SingleUploadComponent(modalService, i18n, selectFiles) { var _this = this; this.modalService = modalService; this.i18n = i18n; this.selectFiles = selectFiles; this.autoUpload = false; this.withoutBtn = false; this.uploadedFiles = []; this.enableDrop = false; this.successEvent = new EventEmitter(); this.errorEvent = new EventEmitter(); this.deleteUploadedFileEvent = new EventEmitter(); this.fileDrop = new EventEmitter(); this.fileOver = new EventEmitter(); this.UploadStatus = UploadStatus; this.isDropOVer = false; this.i18nText = this.i18n.getI18nText().upload; this.i18nCommonText = this.i18n.getI18nText().common; this.i18nSubscription = this.i18n.langChange().subscribe((/** * @param {?} data * @return {?} */ function (data) { _this.i18nText = data.upload; _this.i18nCommonText = data.common; })); } /** * @param {?} observale * @return {?} */ SingleUploadComponent.prototype._dealFiles = /** * @param {?} observale * @return {?} */ function (observale) { var _this = this; observale.pipe(map((/** * @param {?} file * @return {?} */ function (file) { _this.singleUploadViewComponent.addFile((/** @type {?} */ (file))); return file; }))).subscribe((/** * @return {?} */ function () { _this.singleUploadViewComponent.uploadedFilesComponent.cleanUploadedFiles(); if (_this.autoUpload) { _this.upload(); } }), (/** * @param {?} error * @return {?} */ function (error) { _this.alertMsg(error.message); })); }; /** * @param {?} $event * @return {?} */ SingleUploadComponent.prototype.onClick = /** * @param {?} $event * @return {?} */ function ($event) { this._dealFiles(this.selectFiles.triggerSelectFiles(this.fileOptions, this.uploadOptions)); }; Object.defineProperty(SingleUploadComponent.prototype, "filename", { get: /** * @return {?} */ function () { return (this.singleUploadViewComponent.getFiles()[0] || (/** @type {?} */ ({}))).name || ''; }, enumerable: true, configurable: true }); /** * @param {?} files * @return {?} */ SingleUploadComponent.prototype.onFileDrop = /** * @param {?} files * @return {?} */ function (files) { this.isDropOVer = false; this._dealFiles(this.selectFiles.triggerDropFiles(this.fileOptions, this.uploadOptions, files)); this.fileDrop.emit(files[0]); }; /** * @param {?} event * @return {?} */ SingleUploadComponent.prototype.onFileOver = /** * @param {?} event * @return {?} */ function (event) { this.isDropOVer = event; this.fileOver.emit(event); }; /** * @return {?} */ SingleUploadComponent.prototype.upload = /** * @return {?} */ function () { var _this = this; this.canUpload().then((/** * @param {?} canUpload * @return {?} */ function (canUpload) { if (!canUpload) { return; } _this.singleUploadViewComponent .upload() .pipe(last()).subscribe((/** * @param {?} results * @return {?} */ function (results) { _this.successEvent.emit(results); results.forEach((/** * @param {?} result * @return {?} */ function (result) { _this.singleUploadViewComponent.deleteFile(result.file); _this.singleUploadViewComponent.uploadedFilesComponent.addAndOverwriteFile(result.file); })); }), (/** * @param {?} error * @return {?} */ function (error) { _this.singleUploadViewComponent.uploadedFilesComponent.cleanUploadedFiles(); _this.errorEvent.emit(error); })); })); }; /** * @return {?} */ SingleUploadComponent.prototype.canUpload = /** * @return {?} */ function () { /** @type {?} */ var uploadResult = Promise.resolve(true); if (this.beforeUpload) { /** @type {?} */ var result = this.beforeUpload(this.singleUploadViewComponent.getFiles()[0] || (/** @type {?} */ ({}))); if (typeof result !== 'undefined') { if (result.then) { uploadResult = result; } else if (result.subscribe) { uploadResult = ((/** @type {?} */ (result))).toPromise(); } else { uploadResult = Promise.resolve(result); } } } return uploadResult; }; /** * @param {?} filePath * @return {?} */ SingleUploadComponent.prototype._onDeleteUploadedFile = /** * @param {?} filePath * @return {?} */ function (filePath) { this.deleteUploadedFileEvent.emit(filePath); }; /** * @param {?} $event * @return {?} */ SingleUploadComponent.prototype.deleteFile = /** * @param {?} $event * @return {?} */ function ($event) { $event.stopPropagation(); /** @type {?} */ var files = this.singleUploadViewComponent.getFiles(); this.singleUploadViewComponent.deleteFile(files[0]); }; /** * @param {?} errorMsg * @return {?} */ SingleUploadComponent.prototype.alertMsg = /** * @param {?} errorMsg * @return {?} */ function (errorMsg) { /** @type {?} */ var results = this.modalService.open({ width: '300px', backdropCloseable: false, showAnimate: true, component: ModalAlertComponent, data: { content: errorMsg, cancelBtnText: this.confirmText ? this.confirmText : this.i18nCommonText.btnConfirm, onClose: (/** * @param {?} event * @return {?} */ function (event) { results.modalInstance.hide(); }), }, }); }; /** * @return {?} */ SingleUploadComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.i18nSubscription) { this.i18nSubscription.unsubscribe(); } }; SingleUploadComponent.decorators = [ { type: Component, args: [{ selector: 'd-single-upload', template: "<div\r\n [style.display]=\"withoutBtn ? '' : '-webkit-inline-box'\"\r\n d-file-drop\r\n [enableDrop]=\"enableDrop\"\r\n [isSingle]=\"true\"\r\n (fileDrop)=\"onFileDrop($event)\"\r\n (fileOver)=\"onFileOver($event)\"\r\n [ngStyle]=\"{ border: isDropOVer ? '1px solid #15bf15' : '0' }\"\r\n>\r\n <div (click)=\"onClick($event)\" class=\"devui-input-group\">\r\n <input\r\n style=\"cursor: pointer\"\r\n class=\"devui-form-control devui-upload-input\"\r\n [placeholder]=\"placeholderText ? placeholderText : i18nText?.chooseFile\"\r\n [value]=\"filename\"\r\n [title]=\"filename\"\r\n readonly\r\n />\r\n <span\r\n *ngIf=\"!!filename\"\r\n class=\"icon-close devui-upload-delete-file-button devui-icon-close-position\"\r\n (click)=\"deleteFile($event)\"\r\n ></span>\r\n <span class=\"devui-input-group-addon\" style=\"cursor: pointer\">\r\n <svg class=\"svg-icon-dot\" height=\"1em\" width=\"1em\" viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path\r\n d=\"m400.31892 176.970574c0-61.574381 50.113351-111.680569 111.679545-111.680569 61.576427 0 111.680569 50.106188 111.680569 111.680569 0 61.568241-50.104141 111.679545-111.680569 111.679545-61.566194 0-111.679545-50.111304-111.679545-111.679545zm0 335.028403c0-61.568241 50.113351-111.678522 111.679545-111.678522 61.576427 0 111.680569 50.110281 111.680569 111.678522 0 61.574381-50.105165 111.682615-111.680569 111.682615-61.566194 0-111.679545-50.108235-111.679545-111.682615zm0 335.037612c0-61.572334 50.113351-111.679545 111.679545-111.679545 61.575404 0 111.680569 50.107211 111.680569 111.679545 0 61.567217-50.105165 111.672382-111.680569 111.672382-61.566194 0-111.679545-50.105164-111.679545-111.672382zm0 0\"\r\n />\r\n </svg>\r\n </span>\r\n </div>\r\n <d-button\r\n *ngIf=\"!autoUpload && !withoutBtn\"\r\n (btnClick)=\"upload()\"\r\n bsStyle=\"common\"\r\n [style.margin-left.px]=\"10\"\r\n [disabled]=\"\r\n dSingleUploadView.uploadedFilesComponent.uploadedFiles.length > 0 ||\r\n dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploading\r\n \"\r\n >\r\n <span *ngIf=\"!dSingleUploadView.fileUploaders[0] || dSingleUploadView.fileUploaders[0]?.status === UploadStatus.preLoad\">{{\r\n uploadText || i18nText?.upload\r\n }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploading\">{{ i18nText?.uploading }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploaded\">{{ i18nText?.uploaded }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.failed\">{{ i18nText?.uploadFailed }}</span>\r\n </d-button>\r\n</div>\r\n<d-single-upload-view\r\n #dSingleUploadView=\"dSingleUploadView\"\r\n [uploadOptions]=\"uploadOptions\"\r\n [filePath]=\"filePath\"\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [uploadedFilesRef]=\"uploadedFilesRef\"\r\n [preloadFilesRef]=\"preloadFilesRef\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-single-upload-view>\r\n", exportAs: 'dSingleUpload', styles: [".devui-input-group{position:relative;display:table;border-collapse:separate}.devui-input-group:hover .devui-input-group-addon{border-color:#344899;background-color:#dfe1e6;font-weight:700}.devui-input-group:hover .devui-form-control{border-color:#344899 #adb0b8 #344899 #344899}.devui-input-group .devui-input-group-addon:active{border-color:#344899 #adb0b8 #344899 #344899;background-color:#dfe1e6}.devui-input-group .devui-input-group-addon{width:1%;white-space:nowrap;vertical-align:middle;padding:5px 10px;font-size:14px;font-weight:400;line-height:1;color:#252b3a;text-align:center;background-color:#f8f8f8;border-top:1px solid #adb0b8;border-bottom:1px solid #adb0b8;border-right:1px solid #adb0b8;border-top-right-radius:1px;border-bottom-right-radius:1px;display:table-cell;-webkit-transition:border-color .15s ease-in-out;transition:border-color .15s ease-in-out;cursor:pointer}.devui-input-group .devui-form-control{cursor:pointer;display:block;width:100%;height:32px;padding:5px 10px;font-size:14px;line-height:1.42857143;color:#252b3a;background-image:none;border:1px solid #adb0b8;border-top-left-radius:1px;border-bottom-left-radius:1px;-webkit-transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}svg.svg-icon-dot>path{fill:#252b3a}.devui-form-control{outline:0}.devui-icon-close-position{position:absolute;top:calc(50% - 7px);right:50px}"] }] } ]; /** @nocollapse */ SingleUploadComponent.ctorParameters = function () { return [ { type: ModalService }, { type: I18nService }, { type: SelectFiles } ]; }; SingleUploadComponent.propDecorators = { uploadOptions: [{ type: Input }], fileOptions: [{ type: Input }], autoUpload: [{ type: Input }], withoutBtn: [{ type: Input }], uploadedFiles: [{ type: Input }], uploadedFilesRef: [{ type: Input }], preloadFilesRef: [{ type: Input }], filePath: [{ type: Input }], placeholderText: [{ type: Input }], uploadText: [{ type: Input }], confirmText: [{ type: Input }], beforeUpload: [{ type: Input }], enableDrop: [{ type: Input }], successEvent: [{ type: Output }], errorEvent: [{ type: Output }], deleteUploadedFileEvent: [{ type: Output }], fileDrop: [{ type: Output }], fileOver: [{ type: Output }], singleUploadViewComponent: [{ type: ViewChild, args: ['dSingleUploadView', { static: true },] }] }; return SingleUploadComponent; }()); if (false) { /** @type {?} */ SingleUploadComponent.prototype.dSingleUploadView; /** @type {?} */ SingleUploadComponent.prototype.uploadOptions; /** @type {?} */ SingleUploadComponent.prototype.fileOptions; /** @type {?} */ SingleUploadComponent.prototype.autoUpload; /** @type {?} */ SingleUploadComponent.prototype.withoutBtn; /** @type {?} */ SingleUploadComponent.prototype.uploadedFiles; /** @type {?} */ SingleUploadComponent.prototype.uploadedFilesRef; /** @type {?} */ SingleUploadComponent.prototype.preloadFilesRef; /** @type {?} */ SingleUploadComponent.prototype.filePath; /** @type {?} */ SingleUploadComponent.prototype.placeholderText; /** @type {?} */ SingleUploadComponent.prototype.uploadText; /** @type {?} */ SingleUploadComponent.prototype.confirmText; /** @type {?} */ SingleUploadComponent.prototype.beforeUpload; /** @type {?} */ SingleUploadComponent.prototype.enableDrop; /** @type {?} */ SingleUploadComponent.prototype.successEvent; /** @type {?} */ SingleUploadComponent.prototype.errorEvent; /** @type {?} */ SingleUploadComponent.prototype.deleteUploadedFileEvent; /** @type {?} */ SingleUploadComponent.prototype.fileDrop; /** @type {?} */ SingleUploadComponent.prototype.fileOver; /** @type {?} */ SingleUploadComponent.prototype.singleUploadViewComponent; /** @type {?} */ SingleUploadComponent.prototype.UploadStatus; /** @type {?} */ SingleUploadComponent.prototype.isDropOVer; /** @type {?} */ SingleUploadComponent.prototype.i18nText; /** @type {?} */ SingleUploadComponent.prototype.i18nCommonText; /** @type {?} */ SingleUploadComponent.prototype.i18nSubscription; /** * @type {?} * @private */ SingleUploadComponent.prototype.modalService; /** * @type {?} * @private */ SingleUploadComponent.prototype.i18n; /** * @type {?} * @private */ SingleUploadComponent.prototype.selectFiles; } /** * @fileoverview added by tsickle * Generated from: multiple-upload.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var MultipleUploadComponent = /** @class */ (function () { function MultipleUploadComponent(modalService, selectFiles, i18n) { var _this = this; this.modalService = modalService; this.selectFiles = selectFiles; this.i18n = i18n; this.autoUpload = false; this.withoutBtn = false; this.uploadedFiles = []; this.enableDrop = false; this.successEvent = new EventEmitter(); this.errorEvent = new EventEmitter(); this.deleteUploadedFileEvent = new EventEmitter(); this.fileDrop = new EventEmitter(); this.fileOver = new EventEmitter(); this.isDropOVer = false; this.i18nText = this.i18n.getI