Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | // Get {x, y} positions from event. export function getControlPosition(e) { return offsetXYFromParentOf(e); } // Get from offsetParent export function offsetXYFromParentOf(evt) { const offsetParent = evt.target.offsetParent || document.body; const offsetParentRect = evt.offsetParent === document.body ? {left: 0, top: 0} : offsetParent.getBoundingClientRect(); const x = evt.clientX + offsetParent.scrollLeft - offsetParentRect.left; const y = evt.clientY + offsetParent.scrollTop - offsetParentRect.top; /*const x = Math.round(evt.clientX + offsetParent.scrollLeft - offsetParentRect.left); const y = Math.round(evt.clientY + offsetParent.scrollTop - offsetParentRect.top);*/ return {x, y}; } // Create an data object exposed by <DraggableCore>'s events export function createCoreData(lastX, lastY, x, y) { // State changes are often (but not always!) async. We want the latest value. const isStart = !isNum(lastX); if (isStart) { // If this is our first move, use the x and y as last coords. return { deltaX: 0, deltaY: 0, lastX: x, lastY: y, x: x, y: y }; } else { // Otherwise calculate proper values. return { deltaX: x - lastX, deltaY: y - lastY, lastX: lastX, lastY: lastY, x: x, y: y }; } } function isNum(num) { return typeof num === 'number' && !isNaN(num); } |