{"version":3,"file":"ironsource-fusion-ui-directives-drag-and-drop.mjs","sources":["../../../projects/fusion-ui/directives/drag-and-drop/drag-and-drop.service.ts","../../../projects/fusion-ui/directives/drag-and-drop/drag-and-drop.directive.ts","../../../projects/fusion-ui/directives/drag-and-drop/ironsource-fusion-ui-directives-drag-and-drop.ts"],"sourcesContent":["import {ElementRef, Injectable} from '@angular/core';\n\n@Injectable({\n    providedIn: 'root'\n})\nexport class DragAndDropService {\n    getDragAfterElement(y: number, hostElement: ElementRef): HTMLElement {\n        const draggableElements = [...hostElement.nativeElement.children].filter(child => !child.classList.contains('dragging'));\n        return draggableElements.reduce(\n            (closest, child) => {\n                const box = child.getBoundingClientRect();\n                const offset = y - box.top - box.height / 2;\n                return offset < 0 && offset > closest.offset ? {offset, element: child} : closest;\n            },\n            {offset: Number.NEGATIVE_INFINITY}\n        ).element;\n    }\n\n    onDragToEdgeOfScrollableContainer({dragElement, containerElement}: {dragElement: HTMLElement; containerElement: HTMLElement}) {\n        let pageY = 0;\n        let distanceFromTopOfContainer = 0;\n        if (dragElement) {\n            pageY = dragElement.getBoundingClientRect().top;\n            distanceFromTopOfContainer = pageY - containerElement.getBoundingClientRect().top;\n\n            if (distanceFromTopOfContainer < 30) {\n                this.scrollEntities({containerElement, action: 'scrollUp'});\n            } else if (distanceFromTopOfContainer > containerElement.clientHeight - 30) {\n                this.scrollEntities({containerElement, action: 'scrollDown'});\n            }\n        }\n    }\n\n    private scrollEntities({containerElement, action}: {containerElement: HTMLElement; action: string}) {\n        if (action === 'scrollDown') {\n            containerElement.scrollTop += 10;\n        } else if (action === 'scrollUp') {\n            containerElement.scrollTop -= 10;\n        }\n    }\n}\n","import {ContentChildren, Directive, ElementRef, EventEmitter, HostListener, Output, QueryList} from '@angular/core';\nimport {DragAndDropService} from './drag-and-drop.service';\nimport {DragAndDropListChanges} from './drag-and-drop.entities';\n\n@Directive({\n    selector: '[fusionDragAndDrop]',\n    standalone: true,\n    providers: [DragAndDropService]\n})\nexport class DragAndDropDirective {\n    @ContentChildren('draggableItem') set draggableListItems(value: QueryList<ElementRef>) {\n        this.setDraggableAttributeToItems(value);\n    }\n\n    @Output() dragElementDrop = new EventEmitter<DragAndDropListChanges>();\n    @Output() dragElementEnd = new EventEmitter<any>();\n    @Output() dragElementStart = new EventEmitter<any>();\n\n    private dragElement: HTMLElement;\n\n    private dragChanges: DragAndDropListChanges = {element: null, fromIndex: null, toIndex: null};\n\n    constructor(private hostElement: ElementRef, private readonly dragAndDropStableService: DragAndDropService) {}\n\n    @HostListener('dragstart', ['$event'])\n    onDragStart($event: any) {\n        const draggableElement = $event?.target?.closest('[draggable]');\n        $event.dataTransfer.effectAllowed = 'move';\n        if (draggableElement) {\n            this.dragChanges.fromIndex = this.getElementIndex(draggableElement);\n            this.dragElement = draggableElement;\n            this.dragElement.classList.add('dragging');\n            this.dragElementStart.emit(this.dragElement);\n        }\n    }\n\n    @HostListener('dragend', ['$event'])\n    onDragEnd($event: any) {\n        const draggableElement = $event?.target?.closest('[draggable]');\n        if (draggableElement) {\n            this.dragElement.classList.remove('dragging');\n            this.dragElement.classList.remove('dragging-transit');\n            this.dragElementEnd.emit();\n        }\n    }\n\n    @HostListener('dragover', ['$event'])\n    onDragOver($event: any) {\n        $event.preventDefault();\n        this.dragElement.classList.add('dragging-transit');\n        const afterElement = this.dragAndDropStableService.getDragAfterElement($event.clientY, this.hostElement);\n        if (!afterElement) {\n            this.hostElement.nativeElement.appendChild(this.dragElement);\n        } else {\n            this.hostElement.nativeElement.insertBefore(this.dragElement, afterElement);\n        }\n        this.dragAndDropStableService.onDragToEdgeOfScrollableContainer({\n            dragElement: this.dragElement,\n            containerElement: this.hostElement.nativeElement\n        });\n    }\n\n    @HostListener('drop', ['$event'])\n    onDrop($event: DragEvent) {\n        const draggableElement: HTMLElement = ($event?.target as HTMLElement)?.closest('[draggable]');\n        if (draggableElement) {\n            this.dragChanges.toIndex = this.getElementIndex(draggableElement);\n            this.dragChanges.element = draggableElement;\n            this.dragElement.classList.remove('dragging');\n            this.dragElement.classList.remove('dragging-transit');\n\n            if (this.dragChanges.toIndex !== this.dragChanges.fromIndex) {\n                this.dragElementDrop.emit(this.dragChanges);\n            }\n        }\n        this.dragChanges = {element: null, fromIndex: null, toIndex: null};\n    }\n\n    private getElementIndex(element: HTMLElement) {\n        return Array.from(this.hostElement.nativeElement.children).findIndex(child => child === element);\n    }\n\n    private setDraggableAttributeToItems(draggableItems: QueryList<ElementRef>) {\n        draggableItems.forEach(itemElement => {\n            const isDraggable = itemElement.nativeElement.getAttribute('draggable');\n            if (!isDraggable) {\n                itemElement.nativeElement.setAttribute('draggable', true);\n            }\n        });\n    }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.DragAndDropService"],"mappings":";;;MAKa,kBAAkB,CAAA;IAC3B,mBAAmB,CAAC,CAAS,EAAE,WAAuB,EAAA;QAClD,MAAM,iBAAiB,GAAG,CAAC,GAAG,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;QACzH,OAAO,iBAAiB,CAAC,MAAM,CAC3B,CAAC,OAAO,EAAE,KAAK,KAAI;AACf,YAAA,MAAM,GAAG,GAAG,KAAK,CAAC,qBAAqB,EAAE,CAAC;AAC1C,YAAA,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;YAC5C,OAAO,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAC,GAAG,OAAO,CAAC;SACrF,EACD,EAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,EAAC,CACrC,CAAC,OAAO,CAAC;KACb;AAED,IAAA,iCAAiC,CAAC,EAAC,WAAW,EAAE,gBA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