@uxpin/html-dnd
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "@uxpin/html-dnd", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "HTML Drag and Drop Simulator for E2E testing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,6 +7,7 @@ namespace dnd { | ||
dropOffset?: Array<number>; | ||
middleStepOffset?: Array<number>; | ||
} | ||
export function simulate(draggable: Element, droppable: Element, dndSimulateConfig: DndSimulateConfig, middleStep?:Element): void { | ||
const {dragX, dragY, dropX, dropY} = calculateMousePositions(draggable, droppable, dndSimulateConfig); | ||
export function simulate(draggable: Element, droppable: Element, dndSimulateConfig: DndSimulateConfig, middleStep?: Element): void { | ||
const {dragX, dragY, dropX, dropY, middleStepX, middleStepY} = calculateMousePositions(draggable, droppable, dndSimulateConfig, middleStep); | ||
@@ -28,3 +29,3 @@ const store = new DragDataStore(); | ||
if (middleStep) { | ||
const dragOverEventMiddleStep = createEventWithDataTransfer("dragover", dataTransfer, 0, 0, 0, dropX, dropY, false, false, false, false, 0, null); | ||
const dragOverEventMiddleStep = createEventWithDataTransfer("dragover", dataTransfer, 0, 0, 0, middleStepX, middleStepY, false, false, false, false, 0, null); | ||
middleStep.dispatchEvent(dragOverEventMiddleStep); | ||
@@ -54,2 +55,4 @@ } | ||
dropY: number; | ||
middleStepX?: number; | ||
middleStepY?: number; | ||
} | ||
@@ -60,3 +63,3 @@ | ||
*/ | ||
function calculateMousePositions(draggable: Element, droppable: Element, dndSimulateConfig: DndSimulateConfig): MousePositions { | ||
function calculateMousePositions(draggable: Element, droppable: Element, dndSimulateConfig: DndSimulateConfig, middleStep?: Element): MousePositions { | ||
const dragElementPosition = draggable.getBoundingClientRect(); | ||
@@ -89,3 +92,20 @@ const dropElementPosition = droppable.getBoundingClientRect(); | ||
return {dragX, dragY, dropX, dropY}; | ||
if (middleStep) { | ||
let middleStepElementPosition = middleStep.getBoundingClientRect(); | ||
let middleStepX = middleStepElementPosition.left; | ||
let middleStepY = middleStepElementPosition.top; | ||
if (dndSimulateConfig && dndSimulateConfig.middleStepOffset) { | ||
middleStepX += dndSimulateConfig.middleStepOffset[0]; | ||
middleStepY += dndSimulateConfig.middleStepOffset[1]; | ||
} | ||
else { | ||
middleStepX += (middleStepElementPosition.width / 2); | ||
middleStepY += (middleStepElementPosition.height / 2); | ||
} | ||
return { dragX, dragY, dropX, dropY, middleStepX, middleStepY }; | ||
} | ||
return { dragX, dragY, dropX, dropY }; | ||
} | ||
@@ -92,0 +112,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204079
1174