Skip to content

Commit c8871cc

Browse files
committed
more fix for #3241
* added proper type checking to #3241
1 parent 8ec3dc9 commit c8871cc

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Change log
137137
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
138138
## 12.4.3 (TBD)
139139
* fix: [#3237](https://github.com/gridstack/gridstack.js/pull/3237) updateOptions() fixes for columnOpts, maxRow. load() not cloning
140+
* fix: [#3241](https://github.com/gridstack/gridstack.js/pull/3241) drifting rounding issue when cellHeight is small/fraction
140141

141142
## 12.4.2 (2025-12-26)
142143
* regression: [#3214](https://github.com/gridstack/gridstack.js/issues/3214) touch device with real mouse event fix (caused by #3191 in last release)

src/dd-resizable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { DDResizableHandle } from './dd-resizable-handle';
77
import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
88
import { Utils } from './utils';
9-
import { DDResizeOpt, DDUIData, GridItemHTMLElement, Rect, Size } from './types';
9+
import { DDResizeOpt, DDUIData, GridItemHTMLElement, GridStackMouseEvent, Rect, Size } from './types';
1010
import { DDManager } from './dd-manager';
1111

1212
// import { GridItemHTMLElement } from './types'; let count = 0; // TEST
@@ -183,8 +183,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
183183
this.scrolled = this.scrollEl.scrollTop - this.scrollY;
184184
this.temporalRect = this._getChange(event, dir);
185185
this._applyChange();
186-
const ev = Utils.initEvent<MouseEvent>(event, { type: 'resize', target: this.el });
187-
(ev as any).resizeDir = dir; // expose handle direction so _dragOrResize can avoid position drift
186+
const ev = Utils.initEvent<GridStackMouseEvent>(event, { type: 'resize', target: this.el });
187+
ev.resizeDir = dir; // expose handle direction so _dragOrResize can avoid position drift
188188
if (this.option.resize) {
189189
this.option.resize(ev, this._ui());
190190
}

src/gridstack.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
gridDefaults, ColumnOptions, GridItemHTMLElement, GridStackElement, GridStackEventHandlerCallback,
1212
GridStackNode, GridStackWidget, numberOrString, DDUIData, DDDragOpt, GridStackPosition, GridStackOptions,
1313
GridStackEventHandler, GridStackNodesHandler, AddRemoveFcn, SaveFcn, CompactOptions, GridStackMoveOpts, ResizeToContentFcn, GridStackDroppedHandler, GridStackElementHandler,
14-
Position, RenderFcn
14+
Position, RenderFcn,
15+
GridStackMouseEvent
1516
} from './types';
1617

1718
/*
@@ -2872,7 +2873,7 @@ export class GridStack {
28722873
}
28732874

28742875
/** @internal handles actual drag/resize */
2875-
protected _dragOrResize(el: GridItemHTMLElement, event: MouseEvent, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number): void {
2876+
protected _dragOrResize(el: GridItemHTMLElement, event: GridStackMouseEvent, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number): void {
28762877
const p = { ...node._orig }; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
28772878
let resizing: boolean;
28782879
let mLeft = this.opts.marginLeft as number,
@@ -2931,8 +2932,8 @@ export class GridStack {
29312932
// only recalculate position for handles that move the top-left corner (N/W).
29322933
// for SE/S/E handles the top-left is anchored — recalculating from pixels causes
29332934
// rounding drift on fine grids where cellWidth/cellHeight are only a few pixels. #385 #1356
2934-
const dir = ((event as any).resizeDir || '') as string;
2935-
if (dir.includes('w') || dir.includes('n')) {
2935+
const dir = event.resizeDir;
2936+
if (dir && (dir.includes('w') || dir.includes('n'))) {
29362937
const left = ui.position.left + mLeft;
29372938
const top = ui.position.top + mTop;
29382939
if (dir.includes('w')) p.x = Math.round(left / cellWidth);

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,8 @@ export interface GridStackNode extends GridStackWidget {
574574
/** @internal had drag&drop been initialized */
575575
_initDD?: boolean;
576576
}
577+
578+
// add custom field to support drag/resize optimizations
579+
export interface GridStackMouseEvent extends MouseEvent {
580+
resizeDir?: string;
581+
}

0 commit comments

Comments
 (0)