MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / _onStartMoving

Method _onStartMoving

src/gridstack.ts:2822–2877  ·  view source on GitHub ↗

@internal handles actual drag/resize start

(el: GridItemHTMLElement, event: Event, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number)

Source from the content-addressed store, hash-verified

2820
2821 /** @internal handles actual drag/resize start */
2822 protected _onStartMoving(el: GridItemHTMLElement, event: Event, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number): void {
2823 this.engine.cleanNodes()
2824 .beginUpdate(node);
2825 // @ts-ignore
2826 this._writePosAttr(this.placeholder, node)
2827 this.el.appendChild(this.placeholder);
2828 this.placeholder.gridstackNode = node;
2829 // console.log('_onStartMoving placeholder') // TEST
2830
2831 // if the element is inside a grid, it has already been scaled
2832 // we can use that as a scale reference
2833 if (node.grid?.el) {
2834 this.dragTransform = Utils.getValuesFromTransformedElement(el);
2835 }
2836 // if the element is being dragged from outside (not from any grid)
2837 // we use the grid as the transformation reference, since the helper is not subject to transformation
2838 else if (this.placeholder && this.placeholder.closest('.grid-stack')) {
2839 const gridEl = this.placeholder.closest('.grid-stack') as HTMLElement;
2840 this.dragTransform = Utils.getValuesFromTransformedElement(gridEl);
2841 }
2842 // Fallback
2843 else {
2844 this.dragTransform = {
2845 xScale: 1,
2846 xOffset: 0,
2847 yScale: 1,
2848 yOffset: 0,
2849 }
2850 }
2851
2852 node.el = this.placeholder;
2853 node._lastUiPosition = ui.position;
2854 node._prevYPix = ui.position.top;
2855 node._moving = (event.type === 'dragstart'); // 'dropover' are not initially moving so they can go exactly where they enter (will push stuff out of the way)
2856 node._resizing = (event.type === 'resizestart');
2857 delete node._lastTried;
2858
2859 if (event.type === 'dropover' && node._temporaryRemoved) {
2860 // console.log('engine.addNode x=' + node.x); // TEST
2861 this.engine.addNode(node); // will add, fix collisions, update attr and clear _temporaryRemoved
2862 node._moving = true; // AFTER, mark as moving object (wanted fix location before)
2863 }
2864
2865 // set the min/max resize info taking into account the column count and position (so we don't resize outside the grid)
2866 this.engine.cacheRects(cellWidth, cellHeight, this.opts.marginTop as number, this.opts.marginRight as number, this.opts.marginBottom as number, this.opts.marginLeft as number);
2867 if (event.type === 'resizestart') {
2868 const colLeft = this.getColumn() - node.x;
2869 const rowLeft = (this.opts.maxRow || Number.MAX_SAFE_INTEGER) - node.y;
2870 dd.resizable(el, 'option', 'minWidth', cellWidth * Math.min(node.minW || 1, colLeft))
2871 .resizable(el, 'option', 'minHeight', cellHeight * Math.min(node.minH || 1, rowLeft))
2872 .resizable(el, 'option', 'maxWidth', cellWidth * Math.min(node.maxW || Number.MAX_SAFE_INTEGER, colLeft))
2873 .resizable(el, 'option', 'maxWidthMoveLeft', cellWidth * Math.min(node.maxW || Number.MAX_SAFE_INTEGER, node.x+node.w))
2874 .resizable(el, 'option', 'maxHeight', cellHeight * Math.min(node.maxH || Number.MAX_SAFE_INTEGER, rowLeft))
2875 .resizable(el, 'option', 'maxHeightMoveUp', cellHeight * Math.min(node.maxH || Number.MAX_SAFE_INTEGER, node.y+node.h));
2876 }
2877 }
2878
2879 /** @internal handles actual drag/resize */

Callers 2

onDragMethod · 0.95
onStartMovingMethod · 0.95

Calls 8

_writePosAttrMethod · 0.95
getColumnMethod · 0.95
beginUpdateMethod · 0.80
cleanNodesMethod · 0.80
addNodeMethod · 0.80
cacheRectsMethod · 0.80
resizableMethod · 0.45

Tested by

no test coverage detected