react-grid-layout 1.5.3 → 2.0.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.
Files changed (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
@@ -1,210 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resizeHandleType = exports.resizeHandleAxesType = exports.default = void 0;
7
- var _propTypes = _interopRequireDefault(require("prop-types"));
8
- var _react = _interopRequireDefault(require("react"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- /*:: import type {
11
- Ref,
12
- ChildrenArray as ReactChildrenArray,
13
- Element as ReactElement
14
- } from "react";*/
15
- /*:: import type {
16
- DragOverEvent,
17
- EventCallback,
18
- CompactType,
19
- Layout,
20
- LayoutItem,
21
- ResizeHandleAxis
22
- } from "./utils";*/
23
- /*:: export type ReactRef<T: HTMLElement> = {|
24
- +current: T | null
25
- |};*/
26
- // util
27
- /*:: export type ResizeHandle =
28
- | ReactElement<any>
29
- | ((
30
- resizeHandleAxis: ResizeHandleAxis,
31
- ref: ReactRef<HTMLElement>
32
- ) => ReactElement<any>);*/
33
- // Defines which resize handles should be rendered (default: 'se')
34
- // Allows for any combination of:
35
- // 's' - South handle (bottom-center)
36
- // 'w' - West handle (left-center)
37
- // 'e' - East handle (right-center)
38
- // 'n' - North handle (top-center)
39
- // 'sw' - Southwest handle (bottom-left)
40
- // 'nw' - Northwest handle (top-left)
41
- // 'se' - Southeast handle (bottom-right)
42
- // 'ne' - Northeast handle (top-right)
43
- const resizeHandleAxesType /*: ReactPropsChainableTypeChecker*/ = exports.resizeHandleAxesType = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"]));
44
- // Custom component for resize handles
45
- const resizeHandleType /*: ReactPropsChainableTypeChecker*/ = exports.resizeHandleType = _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
46
- /*:: export type Props = {|
47
- className: string,
48
- style: Object,
49
- width: number,
50
- autoSize: boolean,
51
- cols: number,
52
- draggableCancel: string,
53
- draggableHandle: string,
54
- verticalCompact: boolean,
55
- compactType: CompactType,
56
- layout: Layout,
57
- margin: [number, number],
58
- containerPadding: ?[number, number],
59
- rowHeight: number,
60
- maxRows: number,
61
- isBounded: boolean,
62
- isDraggable: boolean,
63
- isResizable: boolean,
64
- isDroppable: boolean,
65
- preventCollision: boolean,
66
- useCSSTransforms: boolean,
67
- transformScale: number,
68
- droppingItem: $Shape<LayoutItem>,
69
- resizeHandles: ResizeHandleAxis[],
70
- resizeHandle?: ResizeHandle,
71
- allowOverlap: boolean,
72
-
73
- // Callbacks
74
- onLayoutChange: Layout => void,
75
- onDrag: EventCallback,
76
- onDragStart: EventCallback,
77
- onDragStop: EventCallback,
78
- onResize: EventCallback,
79
- onResizeStart: EventCallback,
80
- onResizeStop: EventCallback,
81
- onDropDragOver: (e: DragOverEvent) => ?({| w?: number, h?: number |} | false),
82
- onDrop: (layout: Layout, item: ?LayoutItem, e: Event) => void,
83
- children: ReactChildrenArray<ReactElement<any>>,
84
- innerRef?: Ref<"div">
85
- |};*/
86
- /*:: export type DefaultProps = $Diff<
87
- Props,
88
- {
89
- children: ReactChildrenArray<ReactElement<any>>,
90
- width: number
91
- }
92
- >;*/
93
- var _default = exports.default = {
94
- //
95
- // Basic props
96
- //
97
- className: _propTypes.default.string,
98
- style: _propTypes.default.object,
99
- // This can be set explicitly. If it is not set, it will automatically
100
- // be set to the container width. Note that resizes will *not* cause this to adjust.
101
- // If you need that behavior, use WidthProvider.
102
- width: _propTypes.default.number,
103
- // If true, the container height swells and contracts to fit contents
104
- autoSize: _propTypes.default.bool,
105
- // # of cols.
106
- cols: _propTypes.default.number,
107
- // A selector that will not be draggable.
108
- draggableCancel: _propTypes.default.string,
109
- // A selector for the draggable handler
110
- draggableHandle: _propTypes.default.string,
111
- // Deprecated
112
- verticalCompact: function (props /*: Props*/) {
113
- if (props.verticalCompact === false && process.env.NODE_ENV !== "production") {
114
- console.warn(
115
- // eslint-disable-line no-console
116
- "`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. " + 'Use `compactType`: "horizontal" | "vertical" | null.');
117
- }
118
- },
119
- // Choose vertical or hotizontal compaction
120
- compactType: (_propTypes.default.oneOf(["vertical", "horizontal"]) /*: ReactPropsChainableTypeChecker*/),
121
- // layout is an array of object with the format:
122
- // {x: Number, y: Number, w: Number, h: Number, i: String}
123
- layout: function (props /*: Props*/) {
124
- var layout = props.layout;
125
- // I hope you're setting the data-grid property on the grid items
126
- if (layout === undefined) return;
127
- require("./utils").validateLayout(layout, "layout");
128
- },
129
- //
130
- // Grid Dimensions
131
- //
132
-
133
- // Margin between items [x, y] in px
134
- margin: (_propTypes.default.arrayOf(_propTypes.default.number) /*: ReactPropsChainableTypeChecker*/),
135
- // Padding inside the container [x, y] in px
136
- containerPadding: (_propTypes.default.arrayOf(_propTypes.default.number) /*: ReactPropsChainableTypeChecker*/),
137
- // Rows have a static height, but you can change this based on breakpoints if you like
138
- rowHeight: _propTypes.default.number,
139
- // Default Infinity, but you can specify a max here if you like.
140
- // Note that this isn't fully fleshed out and won't error if you specify a layout that
141
- // extends beyond the row capacity. It will, however, not allow users to drag/resize
142
- // an item past the barrier. They can push items beyond the barrier, though.
143
- // Intentionally not documented for this reason.
144
- maxRows: _propTypes.default.number,
145
- //
146
- // Flags
147
- //
148
- isBounded: _propTypes.default.bool,
149
- isDraggable: _propTypes.default.bool,
150
- isResizable: _propTypes.default.bool,
151
- // If true, grid can be placed one over the other.
152
- allowOverlap: _propTypes.default.bool,
153
- // If true, grid items won't change position when being dragged over.
154
- preventCollision: _propTypes.default.bool,
155
- // Use CSS transforms instead of top/left
156
- useCSSTransforms: _propTypes.default.bool,
157
- // parent layout transform scale
158
- transformScale: _propTypes.default.number,
159
- // If true, an external element can trigger onDrop callback with a specific grid position as a parameter
160
- isDroppable: _propTypes.default.bool,
161
- // Resize handle options
162
- resizeHandles: resizeHandleAxesType,
163
- resizeHandle: resizeHandleType,
164
- //
165
- // Callbacks
166
- //
167
-
168
- // Callback so you can save the layout. Calls after each drag & resize stops.
169
- onLayoutChange: _propTypes.default.func,
170
- // Calls when drag starts. Callback is of the signature (layout, oldItem, newItem, placeholder, e, ?node).
171
- // All callbacks below have the same signature. 'start' and 'stop' callbacks omit the 'placeholder'.
172
- onDragStart: _propTypes.default.func,
173
- // Calls on each drag movement.
174
- onDrag: _propTypes.default.func,
175
- // Calls when drag is complete.
176
- onDragStop: _propTypes.default.func,
177
- //Calls when resize starts.
178
- onResizeStart: _propTypes.default.func,
179
- // Calls when resize movement happens.
180
- onResize: _propTypes.default.func,
181
- // Calls when resize is complete.
182
- onResizeStop: _propTypes.default.func,
183
- // Calls when some element is dropped.
184
- onDrop: _propTypes.default.func,
185
- //
186
- // Other validations
187
- //
188
-
189
- droppingItem: (_propTypes.default.shape({
190
- i: _propTypes.default.string.isRequired,
191
- w: _propTypes.default.number.isRequired,
192
- h: _propTypes.default.number.isRequired
193
- }) /*: ReactPropsChainableTypeChecker*/),
194
- // Children must not have duplicate keys.
195
- children: function (props /*: Props*/, propName /*: string*/) {
196
- const children = props[propName];
197
-
198
- // Check children keys for duplicates. Throw if found.
199
- const keys = {};
200
- _react.default.Children.forEach(children, function (child) {
201
- if ((child === null || child === void 0 ? void 0 : child.key) == null) return;
202
- if (keys[child.key]) {
203
- throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
204
- }
205
- keys[child.key] = true;
206
- });
207
- },
208
- // Optional ref for getting a reference for the wrapping div.
209
- innerRef: _propTypes.default.any
210
- };
@@ -1,297 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _fastEquals = require("fast-equals");
10
- var _utils = require("./utils");
11
- var _responsiveUtils = require("./responsiveUtils");
12
- var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
13
- const _excluded = ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"];
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
17
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
18
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
19
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
22
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
23
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*:: import { type Layout, type Pick } from "./utils";*/ /*:: import { type ResponsiveLayout, type OnLayoutChangeCallback, type Breakpoints } from "./responsiveUtils";*/
24
- // $FlowFixMe[method-unbinding]
25
- const type = obj => Object.prototype.toString.call(obj);
26
-
27
- /**
28
- * Get a value of margin or containerPadding.
29
- *
30
- * @param {Array | Object} param Margin | containerPadding, e.g. [10, 10] | {lg: [10, 10], ...}.
31
- * @param {String} breakpoint Breakpoint: lg, md, sm, xs and etc.
32
- * @return {Array}
33
- */
34
- function getIndentationValue /*:: <T: ?[number, number]>*/(param /*: { [key: string]: T } | T*/, breakpoint /*: string*/) /*: T*/{
35
- // $FlowIgnore TODO fix this typedef
36
- if (param == null) return null;
37
- // $FlowIgnore TODO fix this typedef
38
- return Array.isArray(param) ? param : param[breakpoint];
39
- }
40
- /*:: type State = {
41
- layout: Layout,
42
- breakpoint: string,
43
- cols: number,
44
- layouts?: ResponsiveLayout<string>
45
- };*/
46
- /*:: type Props<Breakpoint: string = string> = {|
47
- ...React.ElementConfig<typeof ReactGridLayout>,
48
-
49
- // Responsive config
50
- breakpoint?: ?Breakpoint,
51
- breakpoints: Breakpoints<Breakpoint>,
52
- cols: { [key: Breakpoint]: number },
53
- layouts: ResponsiveLayout<Breakpoint>,
54
- width: number,
55
- margin: { [key: Breakpoint]: [number, number] } | [number, number],
56
- /* prettier-ignore *-/
57
- containerPadding: { [key: Breakpoint]: ?[number, number] } | ?[number, number],
58
-
59
- // Callbacks
60
- onBreakpointChange: (Breakpoint, cols: number) => void,
61
- onLayoutChange: OnLayoutChangeCallback,
62
- onWidthChange: (
63
- containerWidth: number,
64
- margin: [number, number],
65
- cols: number,
66
- containerPadding: ?[number, number]
67
- ) => void
68
- |};*/
69
- /*:: type DefaultProps = Pick<
70
- Props<>,
71
- {|
72
- allowOverlap: 0,
73
- breakpoints: 0,
74
- cols: 0,
75
- containerPadding: 0,
76
- layouts: 0,
77
- margin: 0,
78
- onBreakpointChange: 0,
79
- onLayoutChange: 0,
80
- onWidthChange: 0
81
- |}
82
- >;*/
83
- class ResponsiveReactGridLayout extends React.Component
84
- /*:: <
85
- Props<>,
86
- State
87
- >*/
88
- {
89
- constructor() {
90
- super(...arguments);
91
- _defineProperty(this, "state", this.generateInitialState());
92
- // wrap layouts so we do not need to pass layouts to child
93
- _defineProperty(this, "onLayoutChange", (layout /*: Layout*/) => {
94
- this.props.onLayoutChange(layout, _objectSpread(_objectSpread({}, this.props.layouts), {}, {
95
- [this.state.breakpoint]: layout
96
- }));
97
- });
98
- }
99
- generateInitialState() /*: State*/{
100
- const {
101
- width,
102
- breakpoints,
103
- layouts,
104
- cols
105
- } = this.props;
106
- const breakpoint = (0, _responsiveUtils.getBreakpointFromWidth)(breakpoints, width);
107
- const colNo = (0, _responsiveUtils.getColsFromBreakpoint)(breakpoint, cols);
108
- // verticalCompact compatibility, now deprecated
109
- const compactType = this.props.verticalCompact === false ? null : this.props.compactType;
110
- // Get the initial layout. This can tricky; we try to generate one however possible if one doesn't exist
111
- // for this layout.
112
- const initialLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(layouts, breakpoints, breakpoint, breakpoint, colNo, compactType);
113
- return {
114
- layout: initialLayout,
115
- breakpoint: breakpoint,
116
- cols: colNo
117
- };
118
- }
119
- static getDerivedStateFromProps(nextProps /*: Props<*>*/, prevState /*: State*/) /*: ?$Shape<State>*/{
120
- if (!(0, _fastEquals.deepEqual)(nextProps.layouts, prevState.layouts)) {
121
- // Allow parent to set layouts directly.
122
- const {
123
- breakpoint,
124
- cols
125
- } = prevState;
126
-
127
- // Since we're setting an entirely new layout object, we must generate a new responsive layout
128
- // if one does not exist.
129
- const newLayout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(nextProps.layouts, nextProps.breakpoints, breakpoint, breakpoint, cols, nextProps.compactType);
130
- return {
131
- layout: newLayout,
132
- layouts: nextProps.layouts
133
- };
134
- }
135
- return null;
136
- }
137
- componentDidUpdate(prevProps /*: Props<*>*/) {
138
- // Allow parent to set width or breakpoint directly.
139
- if (this.props.width != prevProps.width || this.props.breakpoint !== prevProps.breakpoint || !(0, _fastEquals.deepEqual)(this.props.breakpoints, prevProps.breakpoints) || !(0, _fastEquals.deepEqual)(this.props.cols, prevProps.cols)) {
140
- this.onWidthChange(prevProps);
141
- }
142
- }
143
- /**
144
- * When the width changes work through breakpoints and reset state with the new width & breakpoint.
145
- * Width changes are necessary to figure out the widget widths.
146
- */
147
- onWidthChange(prevProps /*: Props<*>*/) {
148
- const {
149
- breakpoints,
150
- cols,
151
- layouts,
152
- compactType
153
- } = this.props;
154
- const newBreakpoint = this.props.breakpoint || (0, _responsiveUtils.getBreakpointFromWidth)(this.props.breakpoints, this.props.width);
155
- const lastBreakpoint = this.state.breakpoint;
156
- const newCols /*: number*/ = (0, _responsiveUtils.getColsFromBreakpoint)(newBreakpoint, cols);
157
- const newLayouts = _objectSpread({}, layouts);
158
-
159
- // Breakpoint change
160
- if (lastBreakpoint !== newBreakpoint || prevProps.breakpoints !== breakpoints || prevProps.cols !== cols) {
161
- // Preserve the current layout if the current breakpoint is not present in the next layouts.
162
- if (!(lastBreakpoint in newLayouts)) newLayouts[lastBreakpoint] = (0, _utils.cloneLayout)(this.state.layout);
163
-
164
- // Find or generate a new layout.
165
- let layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType);
166
-
167
- // This adds missing items.
168
- layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType, this.props.allowOverlap);
169
-
170
- // Store the new layout.
171
- newLayouts[newBreakpoint] = layout;
172
-
173
- // callbacks
174
- this.props.onBreakpointChange(newBreakpoint, newCols);
175
- this.props.onLayoutChange(layout, newLayouts);
176
- this.setState({
177
- breakpoint: newBreakpoint,
178
- layout: layout,
179
- cols: newCols
180
- });
181
- }
182
- const margin = getIndentationValue(this.props.margin, newBreakpoint);
183
- const containerPadding = getIndentationValue(this.props.containerPadding, newBreakpoint);
184
-
185
- //call onWidthChange on every change of width, not only on breakpoint changes
186
- this.props.onWidthChange(this.props.width, margin, newCols, containerPadding);
187
- }
188
- render() /*: React.Element<typeof ReactGridLayout>*/{
189
- /* eslint-disable no-unused-vars */
190
- const _this$props = this.props,
191
- {
192
- breakpoint,
193
- breakpoints,
194
- cols,
195
- layouts,
196
- margin,
197
- containerPadding,
198
- onBreakpointChange,
199
- onLayoutChange,
200
- onWidthChange
201
- } = _this$props,
202
- other = _objectWithoutProperties(_this$props, _excluded);
203
- /* eslint-enable no-unused-vars */
204
-
205
- return /*#__PURE__*/React.createElement(_ReactGridLayout.default, _extends({}, other, {
206
- // $FlowIgnore should allow nullable here due to DefaultProps
207
- margin: getIndentationValue(margin, this.state.breakpoint),
208
- containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
209
- onLayoutChange: this.onLayoutChange,
210
- layout: this.state.layout,
211
- cols: this.state.cols
212
- }));
213
- }
214
- }
215
- exports.default = ResponsiveReactGridLayout;
216
- // This should only include propTypes needed in this code; RGL itself
217
- // will do validation of the rest props passed to it.
218
- _defineProperty(ResponsiveReactGridLayout, "propTypes", {
219
- //
220
- // Basic props
221
- //
222
-
223
- // Optional, but if you are managing width yourself you may want to set the breakpoint
224
- // yourself as well.
225
- breakpoint: _propTypes.default.string,
226
- // {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}
227
- breakpoints: _propTypes.default.object,
228
- allowOverlap: _propTypes.default.bool,
229
- // # of cols. This is a breakpoint -> cols map
230
- cols: _propTypes.default.object,
231
- // # of margin. This is a breakpoint -> margin map
232
- // e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
233
- // Margin between items [x, y] in px
234
- // e.g. [10, 10]
235
- margin: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object]),
236
- // # of containerPadding. This is a breakpoint -> containerPadding map
237
- // e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
238
- // Padding inside the container [x, y] in px
239
- // e.g. [10, 10]
240
- containerPadding: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.object]),
241
- // layouts is an object mapping breakpoints to layouts.
242
- // e.g. {lg: Layout, md: Layout, ...}
243
- layouts(props /*: Props<>*/, propName /*: string*/) {
244
- if (type(props[propName]) !== "[object Object]") {
245
- throw new Error("Layout property must be an object. Received: " + type(props[propName]));
246
- }
247
- Object.keys(props[propName]).forEach(key => {
248
- if (!(key in props.breakpoints)) {
249
- throw new Error("Each key in layouts must align with a key in breakpoints.");
250
- }
251
- (0, _utils.validateLayout)(props.layouts[key], "layouts." + key);
252
- });
253
- },
254
- // The width of this component.
255
- // Required in this propTypes stanza because generateInitialState() will fail without it.
256
- width: _propTypes.default.number.isRequired,
257
- //
258
- // Callbacks
259
- //
260
-
261
- // Calls back with breakpoint and new # cols
262
- onBreakpointChange: _propTypes.default.func,
263
- // Callback so you can save the layout.
264
- // Calls back with (currentLayout, allLayouts). allLayouts are keyed by breakpoint.
265
- onLayoutChange: _propTypes.default.func,
266
- // Calls back with (containerWidth, margin, cols, containerPadding)
267
- onWidthChange: _propTypes.default.func
268
- });
269
- _defineProperty(ResponsiveReactGridLayout, "defaultProps", {
270
- breakpoints: {
271
- lg: 1200,
272
- md: 996,
273
- sm: 768,
274
- xs: 480,
275
- xxs: 0
276
- },
277
- cols: {
278
- lg: 12,
279
- md: 10,
280
- sm: 6,
281
- xs: 4,
282
- xxs: 2
283
- },
284
- containerPadding: {
285
- lg: null,
286
- md: null,
287
- sm: null,
288
- xs: null,
289
- xxs: null
290
- },
291
- layouts: {},
292
- margin: [10, 10],
293
- allowOverlap: false,
294
- onBreakpointChange: _utils.noop,
295
- onLayoutChange: _utils.noop,
296
- onWidthChange: _utils.noop
297
- });
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calcGridColWidth = calcGridColWidth;
7
- exports.calcGridItemPosition = calcGridItemPosition;
8
- exports.calcGridItemWHPx = calcGridItemWHPx;
9
- exports.calcWH = calcWH;
10
- exports.calcXY = calcXY;
11
- exports.clamp = clamp;
12
- /*:: import type { Position } from "./utils";*/
13
- /*:: export type PositionParams = {
14
- margin: [number, number],
15
- containerPadding: [number, number],
16
- containerWidth: number,
17
- cols: number,
18
- rowHeight: number,
19
- maxRows: number
20
- };*/
21
- // Helper for generating column width
22
- function calcGridColWidth(positionParams /*: PositionParams*/) /*: number*/{
23
- const {
24
- margin,
25
- containerPadding,
26
- containerWidth,
27
- cols
28
- } = positionParams;
29
- return (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols;
30
- }
31
-
32
- // This can either be called:
33
- // calcGridItemWHPx(w, colWidth, margin[0])
34
- // or
35
- // calcGridItemWHPx(h, rowHeight, margin[1])
36
- function calcGridItemWHPx(gridUnits /*: number*/, colOrRowSize /*: number*/, marginPx /*: number*/) /*: number*/{
37
- // 0 * Infinity === NaN, which causes problems with resize contraints
38
- if (!Number.isFinite(gridUnits)) return gridUnits;
39
- return Math.round(colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx);
40
- }
41
-
42
- /**
43
- * Return position on the page given an x, y, w, h.
44
- * left, top, width, height are all in pixels.
45
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
46
- * @param {Number} x X coordinate in grid units.
47
- * @param {Number} y Y coordinate in grid units.
48
- * @param {Number} w W coordinate in grid units.
49
- * @param {Number} h H coordinate in grid units.
50
- * @return {Position} Object containing coords.
51
- */
52
- function calcGridItemPosition(positionParams /*: PositionParams*/, x /*: number*/, y /*: number*/, w /*: number*/, h /*: number*/, state /*: ?Object*/) /*: Position*/{
53
- const {
54
- margin,
55
- containerPadding,
56
- rowHeight
57
- } = positionParams;
58
- const colWidth = calcGridColWidth(positionParams);
59
- const out = {};
60
-
61
- // If resizing, use the exact width and height as returned from resizing callbacks.
62
- if (state && state.resizing) {
63
- out.width = Math.round(state.resizing.width);
64
- out.height = Math.round(state.resizing.height);
65
- }
66
- // Otherwise, calculate from grid units.
67
- else {
68
- out.width = calcGridItemWHPx(w, colWidth, margin[0]);
69
- out.height = calcGridItemWHPx(h, rowHeight, margin[1]);
70
- }
71
-
72
- // If dragging, use the exact width and height as returned from dragging callbacks.
73
- if (state && state.dragging) {
74
- out.top = Math.round(state.dragging.top);
75
- out.left = Math.round(state.dragging.left);
76
- } else if (state && state.resizing && typeof state.resizing.top === "number" && typeof state.resizing.left === "number") {
77
- out.top = Math.round(state.resizing.top);
78
- out.left = Math.round(state.resizing.left);
79
- }
80
- // Otherwise, calculate from grid units.
81
- else {
82
- out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
83
- out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
84
- }
85
- return out;
86
- }
87
-
88
- /**
89
- * Translate x and y coordinates from pixels to grid units.
90
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
91
- * @param {Number} top Top position (relative to parent) in pixels.
92
- * @param {Number} left Left position (relative to parent) in pixels.
93
- * @param {Number} w W coordinate in grid units.
94
- * @param {Number} h H coordinate in grid units.
95
- * @return {Object} x and y in grid units.
96
- */
97
- function calcXY(positionParams /*: PositionParams*/, top /*: number*/, left /*: number*/, w /*: number*/, h /*: number*/) /*: { x: number, y: number }*/{
98
- const {
99
- margin,
100
- containerPadding,
101
- cols,
102
- rowHeight,
103
- maxRows
104
- } = positionParams;
105
- const colWidth = calcGridColWidth(positionParams);
106
-
107
- // left = containerPaddingX + x * (colWidth + marginX)
108
- // x * (colWidth + marginX) = left - containerPaddingX
109
- // x = (left - containerPaddingX) / (colWidth + marginX)
110
- let x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
111
- let y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
112
-
113
- // Capping
114
- x = clamp(x, 0, cols - w);
115
- y = clamp(y, 0, maxRows - h);
116
- return {
117
- x,
118
- y
119
- };
120
- }
121
-
122
- /**
123
- * Given a height and width in pixel values, calculate grid units.
124
- * @param {PositionParams} positionParams Parameters of grid needed for coordinates calcluations.
125
- * @param {Number} height Height in pixels.
126
- * @param {Number} width Width in pixels.
127
- * @param {Number} x X coordinate in grid units.
128
- * @param {Number} y Y coordinate in grid units.
129
- * @param {String} handle Resize Handle.
130
- * @return {Object} w, h as grid units.
131
- */
132
- function calcWH(positionParams /*: PositionParams*/, width /*: number*/, height /*: number*/, x /*: number*/, y /*: number*/, handle /*: string*/) /*: { w: number, h: number }*/{
133
- const {
134
- margin,
135
- maxRows,
136
- cols,
137
- rowHeight
138
- } = positionParams;
139
- const colWidth = calcGridColWidth(positionParams);
140
-
141
- // width = colWidth * w - (margin * (w - 1))
142
- // ...
143
- // w = (width + margin) / (colWidth + margin)
144
- let w = Math.round((width + margin[0]) / (colWidth + margin[0]));
145
- let h = Math.round((height + margin[1]) / (rowHeight + margin[1]));
146
-
147
- // Capping
148
- let _w = clamp(w, 0, cols - x);
149
- let _h = clamp(h, 0, maxRows - y);
150
- if (["sw", "w", "nw"].indexOf(handle) !== -1) {
151
- _w = clamp(w, 0, cols);
152
- }
153
- if (["nw", "n", "ne"].indexOf(handle) !== -1) {
154
- _h = clamp(h, 0, maxRows);
155
- }
156
- return {
157
- w: _w,
158
- h: _h
159
- };
160
- }
161
-
162
- // Similar to _.clamp
163
- function clamp(num /*: number*/, lowerBound /*: number*/, upperBound /*: number*/) /*: number*/{
164
- return Math.max(Math.min(num, upperBound), lowerBound);
165
- }