Skip to content

Commit b3ff5f7

Browse files
committed
fix: correctly resize ghost element on resize
1 parent 1f6067d commit b3ff5f7

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/components/tile-manager/resize-controller.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { ReactiveController, ReactiveControllerHost } from 'lit';
22
import type { Ref } from 'lit/directives/ref.js';
3-
import { findElementFromEventPath } from '../common/util.js';
3+
import {
4+
findElementFromEventPath,
5+
getElementByIdFromRoot,
6+
} from '../common/util.js';
47

58
export type ResizeMode = 'immediate' | 'deferred';
69

@@ -57,6 +60,11 @@ class ResizeController implements ReactiveController {
5760
protected _initialState!: DOMRect;
5861
private _state!: DOMRect;
5962

63+
private _initialPointerX!: number;
64+
private _initialPointerY!: number;
65+
private _minWidth!: string;
66+
private _minHeight!: string;
67+
6068
protected get _element() {
6169
return this._config?.ref ? this._config.ref.value! : this._host;
6270
}
@@ -92,10 +100,21 @@ class ResizeController implements ReactiveController {
92100
}
93101

94102
private _setInitialState(event: PointerEvent) {
95-
const rect = this._host.getBoundingClientRect();
103+
const resizableElement = this._host.querySelector('div[part~="base"]');
104+
105+
const rect = resizableElement!.getBoundingClientRect();
96106
this._initialState = structuredClone(rect);
97107
this._state = rect;
108+
this._initialPointerX = event.clientX;
109+
this._initialPointerY = event.clientY;
98110
this._id = event.pointerId;
111+
112+
this._minWidth = getComputedStyle(resizableElement!).getPropertyValue(
113+
'--ig-min-col-width'
114+
);
115+
this._minHeight = getComputedStyle(resizableElement!).getPropertyValue(
116+
'--ig-min-row-height'
117+
);
99118
}
100119

101120
private _createCallbackParams(event: PointerEvent): ResizeCallbackParams {
@@ -150,8 +169,17 @@ class ResizeController implements ReactiveController {
150169
// REVIEW: Sequencing
151170

152171
if (this._config?.resize) {
153-
this._state.width = event.clientX;
154-
this._state.height = event.clientY;
172+
const deltaX = event.clientX - this._initialPointerX;
173+
const deltaY = event.clientY - this._initialPointerY;
174+
175+
this._state.width = Math.max(
176+
this._initialState.width + deltaX,
177+
Number.parseFloat(this._minWidth)
178+
);
179+
this._state.height = Math.max(
180+
this._initialState.height + deltaY,
181+
Number.parseFloat(this._minHeight)
182+
);
155183

156184
this._config.resize.call(this._host, this._createCallbackParams(event));
157185
}

0 commit comments

Comments
 (0)