(event: DragEvent, el: GridItemHTMLElement, helper: GridItemHTMLElement)
| 2416 | let cellHeight: number, cellWidth: number; |
| 2417 | |
| 2418 | const onDrag = (event: DragEvent, el: GridItemHTMLElement, helper: GridItemHTMLElement) => { |
| 2419 | helper = helper || el; |
| 2420 | const node = helper.gridstackNode; |
| 2421 | if (!node) return; |
| 2422 | |
| 2423 | // if the element is being dragged from outside, scale it down to match the grid's scale |
| 2424 | // and slightly adjust its position relative to the mouse |
| 2425 | if (!node.grid?.el) { |
| 2426 | // this scales the helper down |
| 2427 | helper.style.transform = `scale(${1 / this.dragTransform.xScale},${1 / this.dragTransform.yScale})`; |
| 2428 | // this makes it so that the helper is well positioned relative to the mouse after scaling |
| 2429 | const helperRect = helper.getBoundingClientRect(); |
| 2430 | helper.style.left = helperRect.x + (this.dragTransform.xScale - 1) * (event.clientX - helperRect.x) / this.dragTransform.xScale + 'px'; |
| 2431 | helper.style.top = helperRect.y + (this.dragTransform.yScale - 1) * (event.clientY - helperRect.y) / this.dragTransform.yScale + 'px'; |
| 2432 | helper.style.transformOrigin = `0px 0px` |
| 2433 | } |
| 2434 | |
| 2435 | let { top, left } = helper.getBoundingClientRect(); |
| 2436 | const rect = this.el.getBoundingClientRect(); |
| 2437 | left -= rect.left; |
| 2438 | top -= rect.top; |
| 2439 | const ui: DDUIData = { |
| 2440 | position: { |
| 2441 | top: top * this.dragTransform.xScale, |
| 2442 | left: left * this.dragTransform.yScale |
| 2443 | } |
| 2444 | }; |
| 2445 | |
| 2446 | if (node._temporaryRemoved) { |
| 2447 | node.x = Math.max(0, Math.round(left / cellWidth)); |
| 2448 | node.y = Math.max(0, Math.round(top / cellHeight)); |
| 2449 | delete node.autoPosition; |
| 2450 | this.engine.nodeBoundFix(node); |
| 2451 | |
| 2452 | // don't accept *initial* location if doesn't fit #1419 (locked drop region, or can't grow), but maybe try if it will go somewhere |
| 2453 | if (!this.engine.willItFit(node)) { |
| 2454 | node.autoPosition = true; // ignore x,y and try for any slot... |
| 2455 | if (!this.engine.willItFit(node)) { |
| 2456 | dd.off(el, 'drag'); // stop calling us |
| 2457 | return; // full grid or can't grow |
| 2458 | } |
| 2459 | if (node._willFitPos) { |
| 2460 | // use the auto position instead #1687 |
| 2461 | Utils.copyPos(node, node._willFitPos); |
| 2462 | delete node._willFitPos; |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | // re-use the existing node dragging method |
| 2467 | this._onStartMoving(helper, event, ui, node, cellWidth, cellHeight); |
| 2468 | } else { |
| 2469 | // re-use the existing node dragging that does so much of the collision detection |
| 2470 | this._dragOrResize(helper, event, ui, node, cellWidth, cellHeight); |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | dd.droppable(this.el, { |
| 2475 | accept: (el: GridItemHTMLElement) => { |
nothing calls this directly
no test coverage detected