|
1 | 1 | import type { ReactiveController, ReactiveControllerHost } from 'lit'; |
2 | 2 | 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'; |
4 | 7 |
|
5 | 8 | export type ResizeMode = 'immediate' | 'deferred'; |
6 | 9 |
|
@@ -57,6 +60,11 @@ class ResizeController implements ReactiveController { |
57 | 60 | protected _initialState!: DOMRect; |
58 | 61 | private _state!: DOMRect; |
59 | 62 |
|
| 63 | + private _initialPointerX!: number; |
| 64 | + private _initialPointerY!: number; |
| 65 | + private _minWidth!: string; |
| 66 | + private _minHeight!: string; |
| 67 | + |
60 | 68 | protected get _element() { |
61 | 69 | return this._config?.ref ? this._config.ref.value! : this._host; |
62 | 70 | } |
@@ -92,10 +100,21 @@ class ResizeController implements ReactiveController { |
92 | 100 | } |
93 | 101 |
|
94 | 102 | 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(); |
96 | 106 | this._initialState = structuredClone(rect); |
97 | 107 | this._state = rect; |
| 108 | + this._initialPointerX = event.clientX; |
| 109 | + this._initialPointerY = event.clientY; |
98 | 110 | 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 | + ); |
99 | 118 | } |
100 | 119 |
|
101 | 120 | private _createCallbackParams(event: PointerEvent): ResizeCallbackParams { |
@@ -150,8 +169,17 @@ class ResizeController implements ReactiveController { |
150 | 169 | // REVIEW: Sequencing |
151 | 170 |
|
152 | 171 | 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 | + ); |
155 | 183 |
|
156 | 184 | this._config.resize.call(this._host, this._createCallbackParams(event)); |
157 | 185 | } |
|
0 commit comments