UNPKG

@taiga-ui/kit

Version:
755 lines (721 loc) • 43.5 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@taiga-ui/cdk'), require('@taiga-ui/core'), require('@taiga-ui/kit/tokens'), require('@taiga-ui/kit/utils/files'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('@tinkoff/ng-polymorpheus'), require('@angular/platform-browser')) : typeof define === 'function' && define.amd ? define('@taiga-ui/kit/components/input-file', ['exports', '@angular/core', '@angular/forms', '@taiga-ui/cdk', '@taiga-ui/core', '@taiga-ui/kit/tokens', '@taiga-ui/kit/utils/files', 'rxjs', 'rxjs/operators', '@angular/common', '@tinkoff/ng-polymorpheus', '@angular/platform-browser'], factory) : (global = global || self, factory((global['taiga-ui'] = global['taiga-ui'] || {}, global['taiga-ui'].kit = global['taiga-ui'].kit || {}, global['taiga-ui'].kit.components = global['taiga-ui'].kit.components || {}, global['taiga-ui'].kit.components['input-file'] = {}), global.ng.core, global.ng.forms, global.cdk, global.core$1, global['taiga-ui'].kit.tokens, global['taiga-ui'].kit.utils.files, global.rxjs, global.rxjs.operators, global.ng.common, global.ngPolymorpheus, global.ng.platformBrowser)); }(this, (function (exports, core, forms, cdk, core$1, tokens, files, rxjs, operators, common, ngPolymorpheus, platformBrowser) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(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; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __createBinding(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; } function __exportStar(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } var DEFAULT_MAX_SIZE = 30 * 1000 * 1000; // 30 MB // @dynamic var TuiInputFileComponent = /** @class */ (function (_super) { __extends(TuiInputFileComponent, _super); function TuiInputFileComponent(control, changeDetectorRef, isMobile, inputFileTexts$, mode$, units$) { var _this = _super.call(this, control, changeDetectorRef) || this; _this.isMobile = isMobile; _this.inputFileTexts$ = inputFileTexts$; _this.mode$ = mode$; _this.units$ = units$; _this.link = ''; _this.label = ''; _this.accept = ''; _this.multiple = false; _this.size = 'm'; _this.showSize = true; _this.maxFileSize = DEFAULT_MAX_SIZE; _this.loadingFiles = []; _this.rejectedFiles = []; _this.rejectedFilesChange = new core.EventEmitter(); _this.dataTransfer = null; return _this; } TuiInputFileComponent_1 = TuiInputFileComponent; Object.defineProperty(TuiInputFileComponent.prototype, "nativeFocusableElement", { get: function () { return this.input ? this.input.nativeElement : null; }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "focused", { get: function () { return cdk.isNativeFocused(this.nativeFocusableElement); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "allowDelete", { get: function () { return !this.computedDisabled && !this.readOnly; }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "computedLink$", { get: function () { return this.computeLink$(this.fileDragged, this.multiple, this.link); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "computedLabel$", { get: function () { return this.computeLabel$(this.isMobile, this.fileDragged, this.multiple, this.label); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "fileDragged", { // @bad TODO: refactor after IE is dropped get: function () { return (!!this.dataTransfer && Array.prototype.indexOf.call(this.dataTransfer.types, 'Files') !== -1); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "acceptArray", { get: function () { return this.getAcceptArray(this.accept); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "arrayValue", { get: function () { return this.getValueArray(this.value); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "readyFiles", { get: function () { return this.getReadyFiles(this.arrayValue, this.loadingFiles); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "computedLoading", { get: function () { return this.getLoadingFiles(this.arrayValue, this.loadingFiles); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputFileComponent.prototype, "hasFiles", { get: function () { return !!this.rejectedFiles.length || !!this.arrayValue.length; }, enumerable: true, configurable: true }); TuiInputFileComponent.prototype.onHovered = function (hovered) { this.updateHovered(hovered); }; TuiInputFileComponent.prototype.onFocused = function (focused) { this.updateFocused(focused); }; TuiInputFileComponent.prototype.onPressed = function (pressed) { this.updatePressed(pressed); }; // TODO: refactor i18n messages TuiInputFileComponent.prototype.onFilesSelected = function (input, texts, units) { this.processSelectedFiles(input.files, texts, units); input.value = ''; }; TuiInputFileComponent.prototype.onDropped = function (event, texts, units) { this.processSelectedFiles(event.files, texts, units); }; TuiInputFileComponent.prototype.onDragOver = function (dataTransfer) { this.dataTransfer = dataTransfer; }; TuiInputFileComponent.prototype.removeFile = function (removedFile) { this.updateValue(this.multiple ? this.arrayValue.filter(function (file) { return file !== removedFile; }) : null); }; TuiInputFileComponent.prototype.removeRejectedFile = function (removedFile) { this.updateRejectedFiles(this.rejectedFiles.filter(function (file) { return file !== removedFile; })); }; TuiInputFileComponent.prototype.getAppearance = function (mode) { return mode === null ? '' : "outline" /* Outline */; }; TuiInputFileComponent.prototype.computeLink$ = function (fileDragged, multiple, link) { if (fileDragged) { return rxjs.of(''); } return this.inputFileTexts$.pipe(operators.map(function (texts) { return multiple && link === '' ? texts.defaultLinkMultiple : link || texts.defaultLinkSingle; })); }; TuiInputFileComponent.prototype.computeLabel$ = function (isMobile, fileDragged, multiple, label) { if (isMobile) { return rxjs.of(''); } if (fileDragged) { return this.inputFileTexts$.pipe(operators.map(function (texts) { return (multiple ? texts.dropMultiple : texts.drop); })); } return this.inputFileTexts$.pipe(operators.map(function (texts) { return multiple && label === '' ? texts.defaultLabelMultiple : label || texts.defaultLabelSingle; })); }; TuiInputFileComponent.prototype.getValueArray = function (value) { if (!value) { return cdk.EMPTY_ARRAY; } return value instanceof Array ? value : [value]; }; TuiInputFileComponent.prototype.getReadyFiles = function (value, loading) { return value.filter(function (file) { return loading.indexOf(file) === -1; }); }; TuiInputFileComponent.prototype.getLoadingFiles = function (value, loading) { return loading.filter(function (file) { return value.indexOf(file) !== -1; }); }; TuiInputFileComponent.prototype.getAcceptArray = function (accept) { return accept.toLowerCase().split(','); }; TuiInputFileComponent.prototype.processSelectedFiles = function (files$1, texts, units) { var _this = this; // IE11 after selecting a file through the open dialog generates a second event passing an empty FileList. if (files$1 === null || files$1.length === 0) { return; } var newFiles = this.multiple ? Array.from(files$1) : [files$1[0]]; var tooBigFiles = newFiles.filter(function (file) { return file.size > _this.maxFileSize; }); var wrongFormatFiles = newFiles.filter(function (file) { return !_this.isFormatAcceptable(file) && tooBigFiles.indexOf(file) === -1; }); var acceptedFiles = newFiles.filter(function (file) { return tooBigFiles.indexOf(file) === -1 && wrongFormatFiles.indexOf(file) === -1; }); this.updateRejectedFiles(__spread(tooBigFiles.map(function (file) { return ({ name: file.name, type: file.type, size: file.size, content: texts.maxSizeRejectionReason + files.formatSize(units, _this.maxFileSize), }); }), wrongFormatFiles.map(function (file) { return ({ name: file.name, type: file.type, size: file.size, content: texts.formatRejectionReason, }); }))); this.updateValue(this.multiple ? __spread(this.arrayValue, acceptedFiles) : acceptedFiles[0] || null); }; TuiInputFileComponent.prototype.isFormatAcceptable = function (file) { if (!this.accept) { return true; } var extension = '.' + (file.name.split('.').pop() || '').toLowerCase(); return this.acceptArray.some(function (format) { return format === extension || format === file.type || (format.split('/')[1] === '*' && file.type.split('/')[0] === format.split('/')[0]); }); }; TuiInputFileComponent.prototype.updateRejectedFiles = function (rejectedFiles) { this.rejectedFiles = rejectedFiles; this.rejectedFilesChange.emit(rejectedFiles); }; var TuiInputFileComponent_1; TuiInputFileComponent.ctorParameters = function () { return [ { type: forms.NgControl, decorators: [{ type: core.Optional }, { type: core.Self }, { type: core.Inject, args: [forms.NgControl,] }] }, { type: core.ChangeDetectorRef, decorators: [{ type: core.Inject, args: [core.ChangeDetectorRef,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_MOBILE,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [tokens.TUI_INPUT_FILE_TEXTS,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [core$1.TUI_MODE,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [tokens.TUI_DIGITAL_INFORMATION_UNITS,] }] } ]; }; __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "link", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "label", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "accept", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "multiple", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "size", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "showSize", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "maxFileSize", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "loadingFiles", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiInputFileComponent.prototype, "rejectedFiles", void 0); __decorate([ core.Output() ], TuiInputFileComponent.prototype, "rejectedFilesChange", void 0); __decorate([ core.ViewChild('input') ], TuiInputFileComponent.prototype, "input", void 0); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "computeLink$", null); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "computeLabel$", null); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "getValueArray", null); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "getReadyFiles", null); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "getLoadingFiles", null); __decorate([ cdk.tuiPure ], TuiInputFileComponent.prototype, "getAcceptArray", null); TuiInputFileComponent = TuiInputFileComponent_1 = __decorate([ core.Component({ selector: 'tui-input-file', template: "<tui-wrapper\n *ngIf=\"multiple || !value\"\n class=\"wrapper\"\n [class.wrapper_mobile]=\"isMobile\"\n [class.wrapper_has-files]=\"hasFiles\"\n [appearance]=\"getAppearance(mode$ | async)\"\n [focused]=\"computedFocused\"\n [hovered]=\"computedHovered || fileDragged\"\n [pressed]=\"computedPressed\"\n [readOnly]=\"readOnly\"\n [disabled]=\"computedDisabled\"\n>\n <label\n *ngIf=\"(units$ | async) as units\"\n automation-id=\"tui-input-file__label\"\n >\n <a tuiLink>\n <span\n polymorpheus-outlet\n class=\"inline\"\n [content]=\"computedLink$ | async\"\n ></span>\n </a>\n <ng-container *ngIf=\"computedLabel$ | async as computedLabel\">\n <span>&nbsp;</span>\n <span\n polymorpheus-outlet\n class=\"inline\"\n [content]=\"computedLabel\"\n ></span>\n </ng-container>\n <input\n *ngIf=\"!readOnly && !computedDisabled && (inputFileTexts$ | async) as texts\"\n #input\n class=\"native\"\n type=\"file\"\n tuiPreventDefault=\"mousedown\"\n [id]=\"id\"\n [accept]=\"accept\"\n [multiple]=\"multiple\"\n [tuiFocusable]=\"focusable\"\n (change)=\"onFilesSelected(input, texts, units)\"\n (tuiHoveredChange)=\"onHovered($event)\"\n (tuiFocusedChange)=\"onFocused($event)\"\n (tuiPressedChange)=\"onPressed($event)\"\n (tuiDroppableDropped)=\"onDropped($event, texts, units)\"\n (tuiDroppableDragOverChange)=\"onDragOver($event)\"\n />\n </label>\n</tui-wrapper>\n\n<section\n *tuiLet=\"mode$ | async as mode\"\n tuiGroup\n class=\"files\"\n orientation=\"vertical\"\n [collapsed]=\"true\"\n>\n <tui-file\n *ngFor=\"let file of rejectedFiles\"\n automation-id=\"tui-input-file__error\"\n state=\"error\"\n [attr.data-mode]=\"mode\"\n [showSize]=\"showSize\"\n [allowDelete]=\"allowDelete\"\n [size]=\"size\"\n [file]=\"file\"\n (fileRemoved)=\"removeRejectedFile(file)\"\n ></tui-file>\n <tui-file\n *ngFor=\"let file of computedLoading\"\n automation-id=\"tui-input-file__loading\"\n state=\"loading\"\n [attr.data-mode]=\"mode\"\n [showSize]=\"showSize\"\n [allowDelete]=\"allowDelete\"\n [size]=\"size\"\n [file]=\"file\"\n (fileRemoved)=\"removeFile(file)\"\n ></tui-file>\n <tui-file\n *ngFor=\"let file of readyFiles\"\n automation-id=\"tui-input-file__file\"\n [attr.data-mode]=\"mode\"\n [showSize]=\"showSize\"\n [allowDelete]=\"allowDelete\"\n [size]=\"size\"\n [file]=\"file\"\n (fileRemoved)=\"removeFile(file)\"\n ></tui-file>\n</section>\n", changeDetection: core.ChangeDetectionStrategy.OnPush, providers: [ core$1.MODE_PROVIDER, { provide: cdk.TUI_FOCUSABLE_ITEM_ACCESSOR, useExisting: core.forwardRef(function () { return TuiInputFileComponent_1; }), }, ], styles: [":host{font:var(--tui-font-text-m);display:block;word-wrap:break-word;color:var(--tui-text-02)}.native{position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;cursor:pointer}.native::-webkit-file-upload-button{display:none}.inline{display:inline}.wrapper{display:flex;flex:1;justify-content:center;align-items:center;min-height:var(--tui-height-l);border-radius:var(--tui-radius-m);padding:16px 8px;box-sizing:border-box}.wrapper:after{border:1px dashed;color:var(--tui-link)}.wrapper_mobile:after{border-style:solid}.wrapper_has-files{margin-bottom:8px}.wrapper[data-state=hovered]{background:var(--tui-secondary)}.wrapper[data-state=hovered]:after{color:var(--tui-link-hover)}.wrapper[data-state=pressed]{background:var(--tui-secondary-hover)}.wrapper[data-state=readonly]{pointer-events:none}.wrapper[data-state=readonly]:after{color:var(--tui-text-03)}.wrapper[data-state=disabled]{opacity:var(--tui-disabled-opacity);pointer-events:none}.wrapper[data-state=disabled]:after{color:var(--tui-text-03)}.wrapper._focused:after{border-style:solid;border-width:2px;color:var(--tui-focus)}.files{display:flex}"] }), __param(0, core.Optional()), __param(0, core.Self()), __param(0, core.Inject(forms.NgControl)), __param(1, core.Inject(core.ChangeDetectorRef)), __param(2, core.Inject(cdk.TUI_IS_MOBILE)), __param(3, core.Inject(tokens.TUI_INPUT_FILE_TEXTS)), __param(4, core.Inject(core$1.TUI_MODE)), __param(5, core.Inject(tokens.TUI_DIGITAL_INFORMATION_UNITS)) ], TuiInputFileComponent); return TuiInputFileComponent; }(cdk.AbstractTuiNullableControl)); // @dynamic var TuiFileComponent = /** @class */ (function () { function TuiFileComponent(isMobile, sanitizer, fileTexts$, units$) { this.isMobile = isMobile; this.sanitizer = sanitizer; this.fileTexts$ = fileTexts$; this.units$ = units$; this.file = { name: '' }; this.state = "normal" /* Normal */; this.size = 'm'; this.allowDelete = true; this.showSize = true; this.fileRemoved = new core.EventEmitter(); this.focused = false; } Object.defineProperty(TuiFileComponent.prototype, "preview", { get: function () { return this.isBig ? this.createPreview(this.file, this.sanitizer) : ''; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "isBig", { get: function () { return this.size === 'l'; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "isLoading", { get: function () { return this.state === "loading" /* Loading */; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "isError", { get: function () { return this.state === "error" /* Error */; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "isDeleted", { get: function () { return this.state === "deleted" /* Deleted */; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "icon", { get: function () { if (this.state === "normal" /* Normal */ && this.isBig) { return 'tuiIconDefaultDocLarge'; } switch (this.state) { case "deleted" /* Deleted */: return 'tuiIconTrashLarge'; case "error" /* Error */: return 'tuiIconAlertCircleLarge'; default: return 'tuiIconCheckCircleLarge'; } }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "src", { get: function () { return this.file.src || ''; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "name", { get: function () { return this.file.name.split('.').slice(0, -1).join('.'); }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "type", { get: function () { return '.' + this.file.name.split('.').pop() || ''; }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "content$", { get: function () { return this.calculateContent$(this.state, this.file, this.fileTexts$); }, enumerable: true, configurable: true }); Object.defineProperty(TuiFileComponent.prototype, "fileSize$", { get: function () { return this.calculateFileSize$(this.file, this.units$); }, enumerable: true, configurable: true }); TuiFileComponent.prototype.onRemoveClick = function () { this.fileRemoved.emit(); }; TuiFileComponent.prototype.onFocusVisible = function (focusVisible) { this.focused = focusVisible; }; TuiFileComponent.prototype.calculateContent$ = function (state, file, fileTexts$) { return state === "error" /* Error */ && !file.content ? fileTexts$.pipe(operators.map(function (texts) { return texts.loadingError; })) : rxjs.of(this.file.content || ''); }; TuiFileComponent.prototype.calculateFileSize$ = function (file, units$) { return units$.pipe(operators.map(function (units) { return files.formatSize(units, file.size); })); }; TuiFileComponent.prototype.createPreview = function (file, sanitizer) { if (file.src) { return file.src; } if (file instanceof File && file.type && file.type.startsWith('image/')) { return sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(file)); } return ''; }; TuiFileComponent.ctorParameters = function () { return [ { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_MOBILE,] }] }, { type: platformBrowser.DomSanitizer, decorators: [{ type: core.Inject, args: [platformBrowser.DomSanitizer,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [tokens.TUI_FILE_TEXTS,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [tokens.TUI_DIGITAL_INFORMATION_UNITS,] }] } ]; }; __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiFileComponent.prototype, "file", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiFileComponent.prototype, "state", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiFileComponent.prototype, "size", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiFileComponent.prototype, "allowDelete", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiFileComponent.prototype, "showSize", void 0); __decorate([ core.Output() ], TuiFileComponent.prototype, "fileRemoved", void 0); __decorate([ core.HostBinding('class._focused') ], TuiFileComponent.prototype, "focused", void 0); __decorate([ core.HostBinding('class._link') ], TuiFileComponent.prototype, "src", null); __decorate([ cdk.tuiPure ], TuiFileComponent.prototype, "calculateContent$", null); __decorate([ cdk.tuiPure ], TuiFileComponent.prototype, "calculateFileSize$", null); __decorate([ cdk.tuiPure ], TuiFileComponent.prototype, "createPreview", null); TuiFileComponent = __decorate([ core.Component({ selector: 'tui-file', changeDetection: core.ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"!src; else withLink\">\n <ng-container *ngTemplateOutlet=\"fileInfoTemplate\"></ng-container>\n</ng-container>\n\n<ng-template #withLink>\n <a\n class=\"link\"\n rel=\"noreferrer noopener\"\n target=\"_blank\"\n [href]=\"src\"\n (tuiFocusVisibleChange)=\"onFocusVisible($event)\"\n >\n <ng-container *ngTemplateOutlet=\"fileInfoTemplate\"></ng-container>\n </a>\n</ng-template>\n\n<ng-template #fileInfoTemplate>\n <div class=\"preview\" [class.preview_big]=\"isBig\">\n <img\n *ngIf=\"preview && (fileTexts$ | async) as texts; else loader\"\n automation-id=\"tui-file__preview\"\n class=\"image\"\n [alt]=\"texts.preview\"\n [src]=\"preview\"\n />\n <ng-template #loader>\n <tui-loader\n *ngIf=\"isLoading; else svg\"\n automation-id=\"tui-file__loader\"\n class=\"loader\"\n [inheritColor]=\"isBig\"\n ></tui-loader>\n </ng-template>\n <ng-template #svg>\n <tui-svg\n class=\"icon\"\n automation-id=\"tui-file__icon\"\n [class.icon_deleted]=\"isDeleted\"\n [class.icon_error]=\"isError\"\n [src]=\"icon\"\n ></tui-svg>\n </ng-template>\n </div>\n <div class=\"wrapper\">\n <div class=\"text\">\n <div automation-id=\"tui-file__name\" class=\"name\">{{name}}</div>\n <div automation-id=\"tui-file__type\" class=\"type\">{{type}}</div>\n <div\n *ngIf=\"showSize && (fileSize$ | async) as fileSize\"\n automation-id=\"tui-file__size\"\n class=\"size\"\n >\n {{fileSize}}\n </div>\n </div>\n <div\n polymorpheus-outlet\n *ngIf=\"content$ | async as content\"\n automation-id=\"tui-file__content\"\n class=\"content\"\n [content]=\"content\"\n ></div>\n </div>\n <button\n *ngIf=\"allowDelete && (fileTexts$ | async) as texts\"\n automation-id=\"tui-file__remove\"\n tuiIconButton\n type=\"button\"\n size=\"xs\"\n icon=\"tuiIconCloseLarge\"\n appearance=\"icon\"\n class=\"remove\"\n [title]=\"texts.remove\"\n [class.remove_mobile]=\"isMobile\"\n (click.prevent)=\"onRemoveClick()\"\n ></button>\n</ng-template>\n", styles: [":host{font:var(--tui-font-text-m);position:relative;display:flex;border:1px solid var(--tui-base-03);border-radius:var(--tui-radius-m)}:host[data-mode=onDark]{color:var(--tui-text-01-night)}:host:not(._link){padding:9px 35px 9px 9px}:host:hover .remove{opacity:1}:host._focused{border-color:var(--tui-focus);box-shadow:0 0 0 1px inset var(--tui-focus)}.link{display:flex;flex:1;padding:9px 35px 9px 9px;text-decoration:none;outline:0;cursor:pointer;color:var(--tui-text-01);max-width:calc(100% - 44px)}.link:hover{background-color:var(--tui-base-02)}.preview{position:relative;display:flex;align-items:center;justify-content:center;flex-shrink:0;width:24px;height:24px;margin-right:12px;border-radius:var(--tui-radius-m);overflow:hidden;color:rgba(0,0,0,.24)}.preview_big{width:64px;height:64px;margin-right:16px}.preview_big:before{position:absolute;top:0;left:0;width:100%;height:100%;content:'';background:#333;opacity:.08}.image{max-width:100%;max-height:100%}.loader{position:absolute;top:0;left:0;width:100%;height:100%}.icon{position:absolute;top:0;left:0;width:100%;height:100%;color:var(--tui-success-fill)}.icon_error{color:var(--tui-error-fill)}.icon_deleted{color:var(--tui-base-06)}.remove{transition-property:opacity;transition-duration:.3s;transition-timing-function:ease-in-out;position:absolute;top:10px;right:10px;opacity:0}.remove:focus,.remove_mobile{opacity:1}.wrapper{display:flex;flex-direction:column;justify-content:center;overflow:hidden}.text{display:flex}.size{flex-shrink:0;opacity:var(--tui-disabled-opacity);margin-left:8px}.type{flex-shrink:0}.name{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.content{font:var(--tui-font-text-s);color:var(--tui-error-fill)}"] }), __param(0, core.Inject(cdk.TUI_IS_MOBILE)), __param(1, core.Inject(platformBrowser.DomSanitizer)), __param(2, core.Inject(tokens.TUI_FILE_TEXTS)), __param(3, core.Inject(tokens.TUI_DIGITAL_INFORMATION_UNITS)) ], TuiFileComponent); return TuiFileComponent; }()); var TuiInputFileModule = /** @class */ (function () { function TuiInputFileModule() { } TuiInputFileModule = __decorate([ core.NgModule({ imports: [ common.CommonModule, ngPolymorpheus.PolymorpheusModule, cdk.TuiLetModule, cdk.TuiFocusedModule, cdk.TuiFocusVisibleModule, cdk.TuiPressedModule, cdk.TuiHoveredModule, cdk.TuiFocusableModule, cdk.TuiDroppableModule, core$1.TuiWrapperModule, core$1.TuiSvgModule, core$1.TuiLinkModule, core$1.TuiLoaderModule, core$1.TuiButtonModule, cdk.TuiPreventDefaultModule, core$1.TuiGroupModule, ], declarations: [TuiFileComponent, TuiInputFileComponent], exports: [TuiInputFileComponent], }) ], TuiInputFileModule); return TuiInputFileModule; }()); exports.TuiFileComponent = TuiFileComponent; exports.TuiInputFileComponent = TuiInputFileComponent; exports.TuiInputFileModule = TuiInputFileModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=taiga-ui-kit-components-input-file.umd.js.map