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

Method _getChange

src/dd-resizable.ts:254–309  ·  view source on GitHub ↗

@internal

(event: MouseEvent, dir: string)

Source from the content-addressed store, hash-verified

252
253 /** @internal */
254 protected _getChange(event: MouseEvent, dir: string): TemporalRect {
255 const oEvent = this.startEvent;
256 const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
257 width: this.originalRect.width,
258 height: this.originalRect.height + this.scrolled,
259 left: this.originalRect.left,
260 right: this.originalRect.right,
261 top: this.originalRect.top - this.scrolled,
262 };
263
264 const offsetX = event.clientX - oEvent.clientX;
265 const offsetY = this.sizeToContent ? 0 : event.clientY - oEvent.clientY; // prevent vert resize
266 let moveLeft: boolean;
267 let moveUp: boolean;
268
269 const isRtl = this.option.rtl;
270
271 if (!isRtl && dir.indexOf('e') > -1) {
272 newRect.width += offsetX;
273 } else if (isRtl && dir.indexOf('w') > -1) {
274 newRect.width -= offsetX;
275 } else if (!isRtl && dir.indexOf('w') > -1) {
276 newRect.width -= offsetX;
277 newRect.left += offsetX;
278 moveLeft = true;
279 } else if (isRtl && dir.indexOf('e') > -1) {
280 newRect.width += offsetX;
281 newRect.right += offsetX;
282 moveLeft = true;
283 }
284
285 if (dir.indexOf('s') > -1) {
286 newRect.height += offsetY;
287 } else if (dir.indexOf('n') > -1) {
288 newRect.height -= offsetY;
289 newRect.top += offsetY
290 moveUp = true;
291 }
292
293 const constrain = this._constrainSize(newRect.width, newRect.height, moveLeft, moveUp);
294 if (Math.round(newRect.width) !== Math.round(constrain.width)) { // round to ignore slight round-off errors
295 if (!isRtl && dir.indexOf('w') > -1) {
296 newRect.left += newRect.width - constrain.width;
297 } else if (isRtl && dir.indexOf('e') > -1) {
298 newRect.right -= newRect.width - constrain.width;
299 }
300 newRect.width = constrain.width;
301 }
302 if (Math.round(newRect.height) !== Math.round(constrain.height)) {
303 if (dir.indexOf('n') > -1) {
304 newRect.top += newRect.height - constrain.height;
305 }
306 newRect.height = constrain.height;
307 }
308 return newRect;
309 }
310
311 /** @internal constrain the size to the set min/max values */

Callers 1

_resizingMethod · 0.95

Calls 1

_constrainSizeMethod · 0.95

Tested by

no test coverage detected