react-grid-layout 1.4.4 → 1.5.1

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
@@ -1,5 +1,6 @@
1
1
  // @flow
2
2
  import React from "react";
3
+ import { flushSync } from "react-dom";
3
4
  import PropTypes from "prop-types";
4
5
  import { DraggableCore } from "react-draggable";
5
6
  import { Resizable } from "react-resizable";
@@ -293,11 +294,15 @@ export default class GridItem extends React.Component<Props, State> {
293
294
  const deltaX = droppingPosition.left - dragging.left;
294
295
  const deltaY = droppingPosition.top - dragging.top;
295
296
 
296
- this.onDrag(droppingPosition.e, {
297
- node,
298
- deltaX,
299
- deltaY
300
- });
297
+ this.onDrag(
298
+ droppingPosition.e,
299
+ {
300
+ node,
301
+ deltaX,
302
+ deltaY
303
+ },
304
+ true // dontFLush: avoid flushSync to temper warnings
305
+ );
301
306
  }
302
307
  }
303
308
 
@@ -481,10 +486,12 @@ export default class GridItem extends React.Component<Props, State> {
481
486
  * onDrag event handler
482
487
  * @param {Event} e event data
483
488
  * @param {Object} callbackData an object with node, delta and position information
489
+ * @param {boolean} dontFlush if true, will not call flushSync
484
490
  */
485
- onDrag: (Event, ReactDraggableCallbackData) => void = (
491
+ onDrag: (Event, ReactDraggableCallbackData, boolean) => void = (
486
492
  e,
487
- { node, deltaX, deltaY }
493
+ { node, deltaX, deltaY },
494
+ dontFlush
488
495
  ) => {
489
496
  const { onDrag } = this.props;
490
497
  if (!onDrag) return;
@@ -516,17 +523,18 @@ export default class GridItem extends React.Component<Props, State> {
516
523
  }
517
524
 
518
525
  const newPosition: PartialPosition = { top, left };
519
- this.setState({ dragging: newPosition });
526
+
527
+ // dontFlush is set if we're calling from inside
528
+ if (dontFlush) {
529
+ this.setState({ dragging: newPosition });
530
+ } else {
531
+ flushSync(() => {
532
+ this.setState({ dragging: newPosition });
533
+ });
534
+ }
520
535
 
521
536
  // Call callback with this data
522
- const { containerPadding } = this.props;
523
- const { x, y } = calcXY(
524
- positionParams,
525
- top - containerPadding[1],
526
- left - containerPadding[0],
527
- w,
528
- h
529
- );
537
+ const { x, y } = calcXY(positionParams, top, left, w, h);
530
538
  return onDrag.call(this, i, x, y, {
531
539
  e,
532
540
  node,
@@ -546,18 +554,12 @@ export default class GridItem extends React.Component<Props, State> {
546
554
  if (!this.state.dragging) {
547
555
  throw new Error("onDragEnd called before onDragStart.");
548
556
  }
549
- const { w, h, i, containerPadding } = this.props;
557
+ const { w, h, i } = this.props;
550
558
  const { left, top } = this.state.dragging;
551
559
  const newPosition: PartialPosition = { top, left };
552
560
  this.setState({ dragging: null });
553
561
 
554
- const { x, y } = calcXY(
555
- this.getPositionParams(),
556
- top - containerPadding[1],
557
- left - containerPadding[0],
558
- w,
559
- h
560
- );
562
+ const { x, y } = calcXY(this.getPositionParams(), top, left, w, h);
561
563
 
562
564
  return onDragStop.call(this, i, x, y, {
563
565
  e,
@@ -605,8 +607,10 @@ export default class GridItem extends React.Component<Props, State> {
605
607
  size,
606
608
  containerWidth
607
609
  );
608
- this.setState({
609
- resizing: handlerName === "onResizeStop" ? null : updatedSize
610
+ flushSync(() => {
611
+ this.setState({
612
+ resizing: handlerName === "onResizeStop" ? null : updatedSize
613
+ });
610
614
  });
611
615
  }
612
616
 
@@ -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
@@ -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.4",
3
+ "version": "1.5.1",
4
4
  "description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
5
5
  "main": "index.js",
6
6
  "scripts": {