react-grid-layout 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -362,7 +362,11 @@ function GridItem(props) {
362
362
  getConstraintContext()
363
363
  );
364
364
  handler(i, newW, newH, {
365
- e: e.nativeEvent,
365
+ // react-resizable forwards react-draggable's callback event, which is
366
+ // already a native MouseEvent/TouchEvent and has no `nativeEvent`.
367
+ // Reading it unconditionally handed consumers `undefined` (#2264).
368
+ // The drag handlers above pass the raw event for the same reason.
369
+ e: e.nativeEvent ?? e,
366
370
  node,
367
371
  size: updatedSize,
368
372
  handle: resizeHandle2
@@ -5,6 +5,20 @@ var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
5
5
  var react = require('react');
6
6
  var fastEquals = require('fast-equals');
7
7
 
8
+ function getContentWidth(node) {
9
+ const style = typeof globalThis.getComputedStyle === "function" ? globalThis.getComputedStyle(node) : null;
10
+ if (!style) return node.clientWidth;
11
+ const px = (value) => {
12
+ const parsed = Number.parseFloat(value);
13
+ return Number.isFinite(parsed) ? parsed : 0;
14
+ };
15
+ const computed = Number.parseFloat(style.width);
16
+ if (Number.isFinite(computed)) return Math.max(0, computed);
17
+ return Math.max(
18
+ 0,
19
+ node.clientWidth - px(style.paddingLeft) - px(style.paddingRight)
20
+ );
21
+ }
8
22
  function useContainerWidth(options = {}) {
9
23
  const { measureBeforeMount = false, initialWidth = 1280 } = options;
10
24
  const [width, setWidth] = react.useState(initialWidth);
@@ -14,8 +28,8 @@ function useContainerWidth(options = {}) {
14
28
  const measureWidth = react.useCallback(() => {
15
29
  const node = containerRef.current;
16
30
  if (node) {
17
- const newWidth = node.offsetWidth;
18
- setWidth(newWidth);
31
+ const newWidth = Math.round(getContentWidth(node));
32
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
19
33
  if (!mounted) {
20
34
  setMounted(true);
21
35
  }
@@ -30,12 +44,12 @@ function useContainerWidth(options = {}) {
30
44
  observerRef.current = new ResizeObserver((entries) => {
31
45
  const entry = entries[0];
32
46
  if (entry) {
33
- const newWidth = entry.contentRect.width;
47
+ const newWidth = Math.round(entry.contentRect.width);
34
48
  if (rafId !== null) {
35
49
  cancelAnimationFrame(rafId);
36
50
  }
37
51
  rafId = requestAnimationFrame(() => {
38
- setWidth(newWidth);
52
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
39
53
  rafId = null;
40
54
  });
41
55
  }
@@ -3,6 +3,20 @@ import { correctBounds, cloneLayout, getLayoutItem, cloneLayoutItem, moveElement
3
3
  import { useState, useRef, useCallback, useEffect, useMemo } from 'react';
4
4
  import { deepEqual } from 'fast-equals';
5
5
 
6
+ function getContentWidth(node) {
7
+ const style = typeof globalThis.getComputedStyle === "function" ? globalThis.getComputedStyle(node) : null;
8
+ if (!style) return node.clientWidth;
9
+ const px = (value) => {
10
+ const parsed = Number.parseFloat(value);
11
+ return Number.isFinite(parsed) ? parsed : 0;
12
+ };
13
+ const computed = Number.parseFloat(style.width);
14
+ if (Number.isFinite(computed)) return Math.max(0, computed);
15
+ return Math.max(
16
+ 0,
17
+ node.clientWidth - px(style.paddingLeft) - px(style.paddingRight)
18
+ );
19
+ }
6
20
  function useContainerWidth(options = {}) {
7
21
  const { measureBeforeMount = false, initialWidth = 1280 } = options;
8
22
  const [width, setWidth] = useState(initialWidth);
@@ -12,8 +26,8 @@ function useContainerWidth(options = {}) {
12
26
  const measureWidth = useCallback(() => {
13
27
  const node = containerRef.current;
14
28
  if (node) {
15
- const newWidth = node.offsetWidth;
16
- setWidth(newWidth);
29
+ const newWidth = Math.round(getContentWidth(node));
30
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
17
31
  if (!mounted) {
18
32
  setMounted(true);
19
33
  }
@@ -28,12 +42,12 @@ function useContainerWidth(options = {}) {
28
42
  observerRef.current = new ResizeObserver((entries) => {
29
43
  const entry = entries[0];
30
44
  if (entry) {
31
- const newWidth = entry.contentRect.width;
45
+ const newWidth = Math.round(entry.contentRect.width);
32
46
  if (rafId !== null) {
33
47
  cancelAnimationFrame(rafId);
34
48
  }
35
49
  rafId = requestAnimationFrame(() => {
36
- setWidth(newWidth);
50
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
37
51
  rafId = null;
38
52
  });
39
53
  }
@@ -369,7 +369,11 @@ function GridItem(props) {
369
369
  getConstraintContext()
370
370
  );
371
371
  handler(i, newW, newH, {
372
- e: e.nativeEvent,
372
+ // react-resizable forwards react-draggable's callback event, which is
373
+ // already a native MouseEvent/TouchEvent and has no `nativeEvent`.
374
+ // Reading it unconditionally handed consumers `undefined` (#2264).
375
+ // The drag handlers above pass the raw event for the same reason.
376
+ e: e.nativeEvent ?? e,
373
377
  node,
374
378
  size: updatedSize,
375
379
  handle: resizeHandle2
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var chunk7MZZ6T4J_js = require('./chunk-7MZZ6T4J.js');
5
+ var chunkBMN6M2VL_js = require('./chunk-BMN6M2VL.js');
6
6
  require('./chunk-ZJHF4QM5.js');
7
- var chunkBPZQUJ7Y_js = require('./chunk-BPZQUJ7Y.js');
7
+ var chunkQAWP6PEK_js = require('./chunk-QAWP6PEK.js');
8
8
  var chunk55DQUWLA_js = require('./chunk-55DQUWLA.js');
9
9
  var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
10
10
 
@@ -12,47 +12,47 @@ var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
12
12
 
13
13
  Object.defineProperty(exports, "DEFAULT_BREAKPOINTS", {
14
14
  enumerable: true,
15
- get: function () { return chunk7MZZ6T4J_js.DEFAULT_BREAKPOINTS; }
15
+ get: function () { return chunkBMN6M2VL_js.DEFAULT_BREAKPOINTS; }
16
16
  });
17
17
  Object.defineProperty(exports, "DEFAULT_COLS", {
18
18
  enumerable: true,
19
- get: function () { return chunk7MZZ6T4J_js.DEFAULT_COLS; }
19
+ get: function () { return chunkBMN6M2VL_js.DEFAULT_COLS; }
20
20
  });
21
21
  Object.defineProperty(exports, "useContainerWidth", {
22
22
  enumerable: true,
23
- get: function () { return chunk7MZZ6T4J_js.useContainerWidth; }
23
+ get: function () { return chunkBMN6M2VL_js.useContainerWidth; }
24
24
  });
25
25
  Object.defineProperty(exports, "useGridLayout", {
26
26
  enumerable: true,
27
- get: function () { return chunk7MZZ6T4J_js.useGridLayout; }
27
+ get: function () { return chunkBMN6M2VL_js.useGridLayout; }
28
28
  });
29
29
  Object.defineProperty(exports, "useResponsiveLayout", {
30
30
  enumerable: true,
31
- get: function () { return chunk7MZZ6T4J_js.useResponsiveLayout; }
31
+ get: function () { return chunkBMN6M2VL_js.useResponsiveLayout; }
32
32
  });
33
33
  Object.defineProperty(exports, "GridItem", {
34
34
  enumerable: true,
35
- get: function () { return chunkBPZQUJ7Y_js.GridItem; }
35
+ get: function () { return chunkQAWP6PEK_js.GridItem; }
36
36
  });
37
37
  Object.defineProperty(exports, "GridLayout", {
38
38
  enumerable: true,
39
- get: function () { return chunkBPZQUJ7Y_js.GridLayout; }
39
+ get: function () { return chunkQAWP6PEK_js.GridLayout; }
40
40
  });
41
41
  Object.defineProperty(exports, "ReactGridLayout", {
42
42
  enumerable: true,
43
- get: function () { return chunkBPZQUJ7Y_js.GridLayout; }
43
+ get: function () { return chunkQAWP6PEK_js.GridLayout; }
44
44
  });
45
45
  Object.defineProperty(exports, "Responsive", {
46
46
  enumerable: true,
47
- get: function () { return chunkBPZQUJ7Y_js.ResponsiveGridLayout; }
47
+ get: function () { return chunkQAWP6PEK_js.ResponsiveGridLayout; }
48
48
  });
49
49
  Object.defineProperty(exports, "ResponsiveGridLayout", {
50
50
  enumerable: true,
51
- get: function () { return chunkBPZQUJ7Y_js.ResponsiveGridLayout; }
51
+ get: function () { return chunkQAWP6PEK_js.ResponsiveGridLayout; }
52
52
  });
53
53
  Object.defineProperty(exports, "default", {
54
54
  enumerable: true,
55
- get: function () { return chunkBPZQUJ7Y_js.GridLayout; }
55
+ get: function () { return chunkQAWP6PEK_js.GridLayout; }
56
56
  });
57
57
  Object.defineProperty(exports, "findOrGenerateResponsiveLayout", {
58
58
  enumerable: true,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { DEFAULT_BREAKPOINTS, DEFAULT_COLS, useContainerWidth, useGridLayout, useResponsiveLayout } from './chunk-PZLKKWSX.mjs';
1
+ export { DEFAULT_BREAKPOINTS, DEFAULT_COLS, useContainerWidth, useGridLayout, useResponsiveLayout } from './chunk-LY5GT7Q2.mjs';
2
2
  import './chunk-O3KX3VYW.mjs';
3
- export { GridItem, GridLayout, GridLayout as ReactGridLayout, ResponsiveGridLayout as Responsive, ResponsiveGridLayout, GridLayout as default } from './chunk-WGL5FSZH.mjs';
3
+ export { GridItem, GridLayout, GridLayout as ReactGridLayout, ResponsiveGridLayout as Responsive, ResponsiveGridLayout, GridLayout as default } from './chunk-7ZM5LVH2.mjs';
4
4
  export { findOrGenerateResponsiveLayout, getBreakpointFromWidth, getColsFromBreakpoint, getCompactor, horizontalCompactor, noCompactor, setTopLeft, setTransform, verticalCompactor } from './chunk-KDANGDDL.mjs';
5
5
  export { bottom, calcGridItemPosition, calcWH, calcXY, cloneLayout, cloneLayoutItem, collides, getAllCollisions, getFirstCollision, getLayoutItem, moveElement, sortLayoutItems, sortLayoutItemsByColRow, sortLayoutItemsByRowCol, validateLayout } from './chunk-76RTO6EO.mjs';
package/dist/legacy.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var chunkBPZQUJ7Y_js = require('./chunk-BPZQUJ7Y.js');
5
+ var chunkQAWP6PEK_js = require('./chunk-QAWP6PEK.js');
6
6
  var chunk55DQUWLA_js = require('./chunk-55DQUWLA.js');
7
7
  require('./chunk-A5WIFECI.js');
8
8
  var react = require('react');
@@ -106,7 +106,7 @@ function ReactGridLayout(props) {
106
106
  const compactor = chunk55DQUWLA_js.getCompactor(compactType, allowOverlap, preventCollision);
107
107
  const constraints = isBounded ? [...chunk55DQUWLA_js.defaultConstraints, chunk55DQUWLA_js.containerBounds] : chunk55DQUWLA_js.defaultConstraints;
108
108
  return /* @__PURE__ */ jsxRuntime.jsx(
109
- chunkBPZQUJ7Y_js.GridLayout,
109
+ chunkQAWP6PEK_js.GridLayout,
110
110
  {
111
111
  width,
112
112
  gridConfig,
@@ -224,7 +224,7 @@ function ResponsiveReactGridLayout(props) {
224
224
  }
225
225
  const compactor = chunk55DQUWLA_js.getCompactor(compactType, allowOverlap, preventCollision);
226
226
  return /* @__PURE__ */ jsxRuntime.jsx(
227
- chunkBPZQUJ7Y_js.ResponsiveGridLayout,
227
+ chunkQAWP6PEK_js.ResponsiveGridLayout,
228
228
  {
229
229
  width,
230
230
  breakpoint,
@@ -279,12 +279,12 @@ function WidthProvider(ComposedComponent) {
279
279
  let rafId = null;
280
280
  const observer = new ResizeObserver((entries) => {
281
281
  if (entries[0]) {
282
- const newWidth = entries[0].contentRect.width;
282
+ const newWidth = Math.round(entries[0].contentRect.width);
283
283
  if (rafId !== null) {
284
284
  cancelAnimationFrame(rafId);
285
285
  }
286
286
  rafId = requestAnimationFrame(() => {
287
- setWidth(newWidth);
287
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
288
288
  rafId = null;
289
289
  });
290
290
  }
package/dist/legacy.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { GridLayout, ResponsiveGridLayout } from './chunk-WGL5FSZH.mjs';
1
+ import { GridLayout, ResponsiveGridLayout } from './chunk-7ZM5LVH2.mjs';
2
2
  import { createScaledStrategy, getCompactor, defaultConstraints, containerBounds, absoluteStrategy, transformStrategy } from './chunk-KDANGDDL.mjs';
3
3
  import './chunk-76RTO6EO.mjs';
4
4
  import { useState, useRef, useEffect } from 'react';
@@ -271,12 +271,12 @@ function WidthProvider(ComposedComponent) {
271
271
  let rafId = null;
272
272
  const observer = new ResizeObserver((entries) => {
273
273
  if (entries[0]) {
274
- const newWidth = entries[0].contentRect.width;
274
+ const newWidth = Math.round(entries[0].contentRect.width);
275
275
  if (rafId !== null) {
276
276
  cancelAnimationFrame(rafId);
277
277
  }
278
278
  rafId = requestAnimationFrame(() => {
279
- setWidth(newWidth);
279
+ setWidth((prev) => prev === newWidth ? prev : newWidth);
280
280
  rafId = null;
281
281
  });
282
282
  }
package/dist/react.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk7MZZ6T4J_js = require('./chunk-7MZZ6T4J.js');
3
+ var chunkBMN6M2VL_js = require('./chunk-BMN6M2VL.js');
4
4
  require('./chunk-ZJHF4QM5.js');
5
- var chunkBPZQUJ7Y_js = require('./chunk-BPZQUJ7Y.js');
5
+ var chunkQAWP6PEK_js = require('./chunk-QAWP6PEK.js');
6
6
  var chunk55DQUWLA_js = require('./chunk-55DQUWLA.js');
7
7
  var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
8
8
 
@@ -10,35 +10,35 @@ var chunkA5WIFECI_js = require('./chunk-A5WIFECI.js');
10
10
 
11
11
  Object.defineProperty(exports, "DEFAULT_BREAKPOINTS", {
12
12
  enumerable: true,
13
- get: function () { return chunk7MZZ6T4J_js.DEFAULT_BREAKPOINTS; }
13
+ get: function () { return chunkBMN6M2VL_js.DEFAULT_BREAKPOINTS; }
14
14
  });
15
15
  Object.defineProperty(exports, "DEFAULT_COLS", {
16
16
  enumerable: true,
17
- get: function () { return chunk7MZZ6T4J_js.DEFAULT_COLS; }
17
+ get: function () { return chunkBMN6M2VL_js.DEFAULT_COLS; }
18
18
  });
19
19
  Object.defineProperty(exports, "useContainerWidth", {
20
20
  enumerable: true,
21
- get: function () { return chunk7MZZ6T4J_js.useContainerWidth; }
21
+ get: function () { return chunkBMN6M2VL_js.useContainerWidth; }
22
22
  });
23
23
  Object.defineProperty(exports, "useGridLayout", {
24
24
  enumerable: true,
25
- get: function () { return chunk7MZZ6T4J_js.useGridLayout; }
25
+ get: function () { return chunkBMN6M2VL_js.useGridLayout; }
26
26
  });
27
27
  Object.defineProperty(exports, "useResponsiveLayout", {
28
28
  enumerable: true,
29
- get: function () { return chunk7MZZ6T4J_js.useResponsiveLayout; }
29
+ get: function () { return chunkBMN6M2VL_js.useResponsiveLayout; }
30
30
  });
31
31
  Object.defineProperty(exports, "GridItem", {
32
32
  enumerable: true,
33
- get: function () { return chunkBPZQUJ7Y_js.GridItem; }
33
+ get: function () { return chunkQAWP6PEK_js.GridItem; }
34
34
  });
35
35
  Object.defineProperty(exports, "GridLayout", {
36
36
  enumerable: true,
37
- get: function () { return chunkBPZQUJ7Y_js.GridLayout; }
37
+ get: function () { return chunkQAWP6PEK_js.GridLayout; }
38
38
  });
39
39
  Object.defineProperty(exports, "ResponsiveGridLayout", {
40
40
  enumerable: true,
41
- get: function () { return chunkBPZQUJ7Y_js.ResponsiveGridLayout; }
41
+ get: function () { return chunkQAWP6PEK_js.ResponsiveGridLayout; }
42
42
  });
43
43
  Object.defineProperty(exports, "getCompactor", {
44
44
  enumerable: true,
package/dist/react.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { DEFAULT_BREAKPOINTS, DEFAULT_COLS, useContainerWidth, useGridLayout, useResponsiveLayout } from './chunk-PZLKKWSX.mjs';
1
+ export { DEFAULT_BREAKPOINTS, DEFAULT_COLS, useContainerWidth, useGridLayout, useResponsiveLayout } from './chunk-LY5GT7Q2.mjs';
2
2
  import './chunk-O3KX3VYW.mjs';
3
- export { GridItem, GridLayout, ResponsiveGridLayout } from './chunk-WGL5FSZH.mjs';
3
+ export { GridItem, GridLayout, ResponsiveGridLayout } from './chunk-7ZM5LVH2.mjs';
4
4
  export { getCompactor, horizontalCompactor, noCompactor, setTopLeft, setTransform, verticalCompactor } from './chunk-KDANGDDL.mjs';
5
5
  export { bottom, calcGridItemPosition, calcWH, calcXY, cloneLayout, cloneLayoutItem, getLayoutItem } from './chunk-76RTO6EO.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grid-layout",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",