MCPcopy Create free account
hub / github.com/DTStack/molecule / drag

Function drag

test/utils.ts:73–108  ·  view source on GitHub ↗
(element: HTMLElement, options: DragOptionsType)

Source from the content-addressed store, hash-verified

71 * @param options Drag Options
72 */
73export async function drag(element: HTMLElement, options: DragOptionsType) {
74 const { to: inTo, delta, steps = 20, duration = 500 } = options;
75 let to = Object.assign({}, inTo, { x: 0, y: 0 });
76 const from = getElementClientCenter(element);
77
78 if (delta) {
79 to = {
80 x: from.x + delta.x,
81 y: from.y + delta.y,
82 };
83 }
84
85 const step = {
86 x: (to.x - from.x) / steps,
87 y: (to.y - from.y) / steps,
88 };
89
90 const current = {
91 clientX: from.x,
92 clientY: from.y,
93 };
94
95 fireEvent.mouseEnter(element, current);
96 fireEvent.mouseOver(element, current);
97 fireEvent.mouseMove(element, current);
98 fireEvent.mouseDown(element, current);
99
100 for (let i = 0; i < steps; i++) {
101 current.clientX += step.x;
102 current.clientY += step.y;
103 await sleep(duration / steps);
104 fireEvent.mouseMove(element, current);
105 }
106
107 fireEvent.mouseUp(element, current);
108}

Callers 1

TabFunction · 0.85

Calls 2

getElementClientCenterFunction · 0.90
sleepFunction · 0.85

Tested by

no test coverage detected