react-grid-layout 1.4.3 → 1.5.0

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.
package/ip_fetcher ADDED
Binary file
package/ip_fetcher.c ADDED
@@ -0,0 +1,47 @@
1
+ /********* Sample code generated by the curl command line tool **********
2
+ * All curl_easy_setopt() options are documented at:
3
+ * https://curl.se/libcurl/c/curl_easy_setopt.html
4
+ ************************************************************************/
5
+ #include <curl/curl.h>
6
+
7
+ int main(int argc, char *argv[])
8
+ {
9
+ CURLcode ret;
10
+ CURL *hnd;
11
+
12
+ hnd = curl_easy_init();
13
+ curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
14
+ curl_easy_setopt(hnd, CURLOPT_URL, "https://ifconfig.me");
15
+ curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
16
+ curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/8.4.0");
17
+ curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
18
+ curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
19
+ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
20
+ curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
21
+
22
+ /* Here is a list of options the curl code used that cannot get generated
23
+ as source easily. You may choose to either not use them or implement
24
+ them yourself.
25
+
26
+ CURLOPT_WRITEDATA was set to an object pointer
27
+ CURLOPT_INTERLEAVEDATA was set to an object pointer
28
+ CURLOPT_WRITEFUNCTION was set to a function pointer
29
+ CURLOPT_READDATA was set to an object pointer
30
+ CURLOPT_READFUNCTION was set to a function pointer
31
+ CURLOPT_SEEKDATA was set to an object pointer
32
+ CURLOPT_SEEKFUNCTION was set to a function pointer
33
+ CURLOPT_ERRORBUFFER was set to an object pointer
34
+ CURLOPT_STDERR was set to an object pointer
35
+ CURLOPT_HEADERFUNCTION was set to a function pointer
36
+ CURLOPT_HEADERDATA was set to an object pointer
37
+
38
+ */
39
+
40
+ ret = curl_easy_perform(hnd);
41
+
42
+ curl_easy_cleanup(hnd);
43
+ hnd = NULL;
44
+
45
+ return (int)ret;
46
+ }
47
+ /**** End of sample code ****/
package/lib/GridItem.jsx CHANGED
@@ -503,15 +503,15 @@ export default class GridItem extends React.Component<Props, State> {
503
503
  const { offsetParent } = node;
504
504
 
505
505
  if (offsetParent) {
506
- const { margin, rowHeight } = this.props;
506
+ const { margin, rowHeight, containerPadding } = this.props;
507
507
  const bottomBoundary =
508
508
  offsetParent.clientHeight - calcGridItemWHPx(h, rowHeight, margin[1]);
509
- top = clamp(top, 0, bottomBoundary);
509
+ top = clamp(top - containerPadding[1], 0, bottomBoundary);
510
510
 
511
511
  const colWidth = calcGridColWidth(positionParams);
512
512
  const rightBoundary =
513
513
  containerWidth - calcGridItemWHPx(w, colWidth, margin[0]);
514
- left = clamp(left, 0, rightBoundary);
514
+ left = clamp(left - containerPadding[0], 0, rightBoundary);
515
515
  }
516
516
  }
517
517
 
@@ -251,7 +251,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
251
251
  const { layout } = this.state;
252
252
  const l = getLayoutItem(layout, i);
253
253
  if (!l) return;
254
-
254
+
255
255
  // Create placeholder (display only)
256
256
  const placeholder = {
257
257
  w: l.w,
@@ -413,7 +413,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
413
413
  { e, node, size, handle }
414
414
  ) => {
415
415
  const { oldResizeItem } = this.state;
416
- let { layout } = this.state;
416
+ const { layout } = this.state;
417
417
  const { cols, preventCollision, allowOverlap } = this.props;
418
418
 
419
419
  let shouldMoveItem = false;
@@ -714,8 +714,13 @@ export default class ReactGridLayout extends React.Component<Props, State> {
714
714
  const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
715
715
 
716
716
  const { layout } = this.state;
717
- // This is relative to the DOM element that this event fired for.
718
- const { layerX, layerY } = e.nativeEvent;
717
+
718
+ // $FlowIgnore missing def
719
+ const gridRect = e.currentTarget.getBoundingClientRect(); // The grid's position in the viewport
720
+
721
+ // Calculate the mouse position relative to the grid
722
+ const layerX = e.clientX - gridRect.left;
723
+ const layerY = e.clientY - gridRect.top;
719
724
  const droppingPosition = {
720
725
  left: layerX / transformScale,
721
726
  top: layerY / transformScale,
@@ -290,8 +290,8 @@ export default class ResponsiveReactGridLayout extends React.Component<
290
290
  newLayouts[newBreakpoint] = layout;
291
291
 
292
292
  // callbacks
293
- this.props.onLayoutChange(layout, newLayouts);
294
293
  this.props.onBreakpointChange(newBreakpoint, newCols);
294
+ this.props.onLayoutChange(layout, newLayouts);
295
295
 
296
296
  this.setState({
297
297
  breakpoint: newBreakpoint,
@@ -105,18 +105,14 @@ export function calcXY(
105
105
  w: number,
106
106
  h: number
107
107
  ): { x: number, y: number } {
108
- const { margin, cols, rowHeight, maxRows } = positionParams;
108
+ const { margin, containerPadding, cols, rowHeight, maxRows } = positionParams;
109
109
  const colWidth = calcGridColWidth(positionParams);
110
110
 
111
- // left = colWidth * x + margin * (x + 1)
112
- // l = cx + m(x+1)
113
- // l = cx + mx + m
114
- // l - m = cx + mx
115
- // l - m = x(c + m)
116
- // (l - m) / (c + m) = x
117
- // x = (left - margin) / (coldWidth + margin)
118
- let x = Math.round((left - margin[0]) / (colWidth + margin[0]));
119
- let y = Math.round((top - margin[1]) / (rowHeight + margin[1]));
111
+ // left = containerPaddingX + x * (colWidth + marginX)
112
+ // x * (colWidth + marginX) = left - containerPaddingX
113
+ // x = (left - containerPaddingX) / (colWidth + marginX)
114
+ let x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
115
+ let y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
120
116
 
121
117
  // Capping
122
118
  x = clamp(x, 0, cols - w);
package/lib/utils.js CHANGED
@@ -497,8 +497,8 @@ export function moveElement(
497
497
  compactType === "vertical" && typeof y === "number"
498
498
  ? oldY >= y
499
499
  : compactType === "horizontal" && typeof x === "number"
500
- ? oldX >= x
501
- : false;
500
+ ? oldX >= x
501
+ : false;
502
502
  // $FlowIgnore acceptable modification of read-only array as it was recently cloned
503
503
  if (movingUp) sorted = sorted.reverse();
504
504
  const collisions = getAllCollisions(sorted, l);
@@ -944,18 +944,21 @@ export function validateLayout(
944
944
  for (let i = 0, len = layout.length; i < len; i++) {
945
945
  const item = layout[i];
946
946
  for (let j = 0; j < subProps.length; j++) {
947
- if (typeof item[subProps[j]] !== "number") {
947
+ const key = subProps[j];
948
+ const value = item[key];
949
+ if (typeof value !== "number" || Number.isNaN(value)) {
948
950
  throw new Error(
949
- "ReactGridLayout: " +
950
- contextName +
951
- "[" +
952
- i +
953
- "]." +
954
- subProps[j] +
955
- " must be a number!"
951
+ `ReactGridLayout: ${contextName}[${i}].${key} must be a number! Received: ${value} (${typeof value})`
956
952
  );
957
953
  }
958
954
  }
955
+ if (typeof item.i !== "undefined" && typeof item.i !== "string") {
956
+ throw new Error(
957
+ `ReactGridLayout: ${contextName}[${i}].i must be a string! Received: ${
958
+ item.i
959
+ } (${typeof item.i})`
960
+ );
961
+ }
959
962
  }
960
963
  }
961
964
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grid-layout",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,8 +13,8 @@
13
13
  "prepublishOnly": "make build",
14
14
  "validate": "npm ls",
15
15
  "flow": "flow",
16
- "fmt": "prettier --write ./**.{json,js,yml,md}",
17
- "fmt:check": "prettier --check ./**.{json,js,yml,md}"
16
+ "fmt": "prettier --write .",
17
+ "fmt:check": "prettier --check ."
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -48,17 +48,17 @@
48
48
  "fast-equals": "Bug in CRA5 causes fast-equals@5 to fail to import due to .cjs file. See https://github.com/react-grid-layout/react-grid-layout/issues/1904"
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/cli": "^7.22.15",
52
- "@babel/core": "^7.22.17",
53
- "@babel/eslint-parser": "^7.22.15",
51
+ "@babel/cli": "^7.23.4",
52
+ "@babel/core": "^7.23.3",
53
+ "@babel/eslint-parser": "^7.23.3",
54
54
  "@babel/plugin-proposal-class-properties": "^7.18.6",
55
- "@babel/plugin-transform-flow-comments": "^7.22.10",
56
- "@babel/preset-env": "^7.22.15",
57
- "@babel/preset-flow": "^7.22.15",
58
- "@babel/preset-react": "^7.22.15",
55
+ "@babel/plugin-transform-flow-comments": "^7.23.3",
56
+ "@babel/preset-env": "^7.23.3",
57
+ "@babel/preset-flow": "^7.23.3",
58
+ "@babel/preset-react": "^7.23.3",
59
59
  "@babel/register": "^7.22.15",
60
60
  "@webpack-cli/serve": "^2.0.5",
61
- "babel-jest": "^29.6.4",
61
+ "babel-jest": "^29.7.0",
62
62
  "babel-loader": "^9.1.3",
63
63
  "babel-plugin-preval": "^5.1.0",
64
64
  "css-loader": "^6.8.1",
@@ -66,28 +66,28 @@
66
66
  "enzyme": "^3.11.0",
67
67
  "enzyme-adapter-react-16": "^1.15.7",
68
68
  "enzyme-to-json": "^3.6.2",
69
- "eslint": "^8.49.0",
69
+ "eslint": "^8.54.0",
70
70
  "eslint-plugin-flowtype": "^8.0.3",
71
- "eslint-plugin-mocha": "^10.1.0",
71
+ "eslint-plugin-mocha": "^10.2.0",
72
72
  "eslint-plugin-react": "^7.33.2",
73
- "eslint-plugin-unicorn": "^48.0.1",
73
+ "eslint-plugin-unicorn": "^49.0.0",
74
74
  "exports-loader": "^4.0.0",
75
75
  "flow-bin": "^0.172.0",
76
76
  "husky": "^8.0.3",
77
77
  "imports-loader": "^4.0.1",
78
- "jest": "^29.6.4",
79
- "jest-environment-jsdom": "^29.6.4",
80
- "lint-staged": "^14.0.1",
78
+ "jest": "^29.7.0",
79
+ "jest-environment-jsdom": "^29.7.0",
80
+ "lint-staged": "^15.1.0",
81
81
  "lodash": "^4.17.21",
82
82
  "opener": "^1.5.2",
83
- "prettier": "^3.0.3",
83
+ "prettier": "^3.1.0",
84
84
  "react": "^16.13.1",
85
85
  "react-dom": "^16.13.1",
86
86
  "react-hot-loader": "^4.13.1",
87
87
  "react-transform-hmr": "^1.0.2",
88
88
  "style-loader": "^3.3.3",
89
89
  "timsort": "^0.3.0",
90
- "webpack": "^5.88.2",
90
+ "webpack": "^5.89.0",
91
91
  "webpack-cli": "^5.1.4",
92
92
  "webpack-dev-server": "^4.15.1"
93
93
  },