UNPKG

@progress/kendo-angular-upload

Version:

Kendo UI Angular Upload Component

104 lines (103 loc) 4.31 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, HostListener, Input } from '@angular/core'; import { assignGuidToFiles, getAllFileInfo, isPresent } from './common/util'; import { validateFiles } from './common/validation-util'; import { DropZoneService } from './dropzone.service'; import { UploadComponent } from './upload.component'; import * as i0 from "@angular/core"; import * as i1 from "./dropzone.service"; export class UploadDropZoneDirective { dropZoneService; /** * Specifies the id of the drop zone used to associate it with * an existing Upload component. */ zoneId; /** * Specifies the id of the drop zone used to associate it with * an existing FileSelect component. */ fileSelectZoneId; constructor(dropZoneService) { this.dropZoneService = dropZoneService; } /** * @hidden */ onElementDragEnter() { return false; } /** * @hidden */ onElementDragOver() { return false; } /** * @hidden */ onDropListener(event) { const components = this.componentInstance; if (!isPresent(components)) { return; } components.forEach((component) => { const droppedFiles = event.dataTransfer.files; if (droppedFiles.length > 0 && !component.disabled) { let files = getAllFileInfo(droppedFiles); if (component instanceof UploadComponent) { files = assignGuidToFiles(files, !component.batch); } else { files = assignGuidToFiles(files, true); } if (!component.multiple) { files.splice(1, files.length - 1); component.clearFiles(); } validateFiles(files, component.restrictions); component.addFiles(files); } }); return false; } /** * @hidden */ get componentInstance() { const id = this.zoneId || this.fileSelectZoneId; return this.dropZoneService.getComponents(id); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UploadDropZoneDirective, deps: [{ token: i1.DropZoneService }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: UploadDropZoneDirective, isStandalone: true, selector: "[kendoUploadDropZone], [kendoFileSelectDropZone]", inputs: { zoneId: ["kendoUploadDropZone", "zoneId"], fileSelectZoneId: ["kendoFileSelectDropZone", "fileSelectZoneId"] }, host: { listeners: { "dragenter": "onElementDragEnter()", "dragover": "onElementDragOver()", "drop": "onDropListener($event)" } }, providers: [ DropZoneService ], ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UploadDropZoneDirective, decorators: [{ type: Directive, args: [{ providers: [ DropZoneService ], selector: '[kendoUploadDropZone], [kendoFileSelectDropZone]', standalone: true }] }], ctorParameters: function () { return [{ type: i1.DropZoneService }]; }, propDecorators: { zoneId: [{ type: Input, args: ['kendoUploadDropZone'] }], fileSelectZoneId: [{ type: Input, args: ['kendoFileSelectDropZone'] }], onElementDragEnter: [{ type: HostListener, args: ['dragenter'] }], onElementDragOver: [{ type: HostListener, args: ['dragover'] }], onDropListener: [{ type: HostListener, args: ['drop', ['$event']] }] } });