Skip to content

Commit f8007dd

Browse files
fix(grid-list): harden drag drop logic (#219)
1 parent 3b017cc commit f8007dd

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

projects/flosportsinc/ng-grid-list/common/ng-grid-list-drag-drop.directive.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ export class FloGridListDragDropDirective<TItem extends IFloGridListBaseItem, TE
6666
? maybe(this._document.getElementById(this.dragId))
6767
: maybe<HTMLElement>()
6868

69-
extractDisplayInfoFromDragEvent = (evt: DragEvent) => {
70-
const elm = evt.target as HTMLElement
71-
const clientRect = elm.getBoundingClientRect()
72-
return {
73-
offsetX: evt.clientX - clientRect.left,
74-
offsetY: evt.clientY - clientRect.top,
75-
height: `${elm.clientHeight}px`,
76-
width: `${elm.clientWidth}px`
77-
}
78-
}
69+
extractDisplayInfoFromDragEvent = (evt: DragEvent) =>
70+
maybe(evt.target)
71+
.map((elm: HTMLElement) => {
72+
const clientRect = elm.getBoundingClientRect()
73+
return {
74+
offsetX: evt.clientX - clientRect.left,
75+
offsetY: evt.clientY - clientRect.top,
76+
height: `${elm.clientHeight}px`,
77+
width: `${elm.clientWidth}px`
78+
}
79+
})
7980

8081
mutateClonedOffsetPlaceholder = (elm: HTMLDivElement) => {
8182
this.rd.setStyle(elm, 'position', 'absolute')
@@ -90,8 +91,11 @@ export class FloGridListDragDropDirective<TItem extends IFloGridListBaseItem, TE
9091
.tapSome(dt => {
9192
dt.setData('text', JSON.stringify({ index: this.floGridListDragDropIndex, value: this.floGridListDragDropItem }))
9293
this.maybeClonedExists()
93-
.tapSome(cloned => {
94-
const info = this.extractDisplayInfoFromDragEvent(evt)
94+
.flatMap(cloned => this.extractDisplayInfoFromDragEvent(evt)
95+
.map(info => ({ info, cloned })))
96+
.tapSome(details => {
97+
const cloned = details.cloned
98+
const info = details.info
9599
const zIndexPlus = Date.now().toString()
96100
this.rd.setStyle(cloned, 'height', info.height)
97101
this.rd.setStyle(cloned, 'width', info.width)

0 commit comments

Comments
 (0)