react-grid-layout 0.16.4 → 0.17.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.
@@ -1,94 +1,137 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
4
-
5
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
-
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
7
6
  exports.default = WidthProvider;
8
7
 
9
- var _react = require("react");
8
+ var _react = _interopRequireDefault(require("react"));
10
9
 
11
- var _react2 = _interopRequireDefault(_react);
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
11
 
13
- var _propTypes = require("prop-types");
12
+ var _reactDom = _interopRequireDefault(require("react-dom"));
14
13
 
15
- var _propTypes2 = _interopRequireDefault(_propTypes);
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
15
 
17
- var _reactDom = require("react-dom");
16
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
18
17
 
19
- var _reactDom2 = _interopRequireDefault(_reactDom);
18
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
20
19
 
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
22
21
 
23
- function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
22
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
24
23
 
25
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
25
 
27
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
27
+
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
29
+
30
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
28
31
 
29
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
32
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
37
+
38
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
+
40
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
41
 
31
42
  /*
32
43
  * A simple HOC that provides facility for listening to container resizes.
33
44
  */
34
- function WidthProvider(ComposedComponent) {
35
- var _class, _temp2;
36
-
37
- return _temp2 = _class = function (_React$Component) {
45
+ function WidthProvider
46
+ /*:: <
47
+ Props,
48
+ ComposedProps: { ...Props, ...WPProps }
49
+ >*/
50
+ (ComposedComponent
51
+ /*: ReactComponentType<Props>*/
52
+ )
53
+ /*: ReactComponentType<ComposedProps>*/
54
+ {
55
+ var _class, _temp;
56
+
57
+ return _temp = _class =
58
+ /*#__PURE__*/
59
+ function (_React$Component) {
38
60
  _inherits(WidthProvider, _React$Component);
39
61
 
40
62
  function WidthProvider() {
41
- var _temp, _this, _ret;
63
+ var _getPrototypeOf2;
64
+
65
+ var _this;
42
66
 
43
67
  _classCallCheck(this, WidthProvider);
44
68
 
45
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
69
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46
70
  args[_key] = arguments[_key];
47
71
  }
48
72
 
49
- return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
73
+ _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(WidthProvider)).call.apply(_getPrototypeOf2, [this].concat(args)));
74
+
75
+ _defineProperty(_assertThisInitialized(_this), "state", {
50
76
  width: 1280
51
- }, _this.mounted = false, _this.onWindowResize = function () {
52
- if (!_this.mounted) return;
53
- // eslint-disable-next-line
54
- var node = _reactDom2.default.findDOMNode(_this); // Flow casts this to Text | Element
55
- if (node instanceof HTMLElement) _this.setState({ width: node.offsetWidth });
56
- }, _temp), _possibleConstructorReturn(_this, _ret);
57
- }
77
+ });
58
78
 
59
- WidthProvider.prototype.componentDidMount = function componentDidMount() {
60
- this.mounted = true;
79
+ _defineProperty(_assertThisInitialized(_this), "mounted", false);
61
80
 
62
- window.addEventListener("resize", this.onWindowResize);
63
- // Call to properly set the breakpoint and resize the elements.
64
- // Note that if you're doing a full-width element, this can get a little wonky if a scrollbar
65
- // appears because of the grid. In that case, fire your own resize event, or set `overflow: scroll` on your body.
66
- this.onWindowResize();
67
- };
81
+ _defineProperty(_assertThisInitialized(_this), "onWindowResize", function () {
82
+ if (!_this.mounted) return; // eslint-disable-next-line react/no-find-dom-node
68
83
 
69
- WidthProvider.prototype.componentWillUnmount = function componentWillUnmount() {
70
- this.mounted = false;
71
- window.removeEventListener("resize", this.onWindowResize);
72
- };
84
+ var node = _reactDom.default.findDOMNode(_assertThisInitialized(_this)); // Flow casts this to Text | Element
73
85
 
74
- WidthProvider.prototype.render = function render() {
75
- var _props = this.props,
76
- measureBeforeMount = _props.measureBeforeMount,
77
- rest = _objectWithoutProperties(_props, ["measureBeforeMount"]);
78
86
 
79
- if (measureBeforeMount && !this.mounted) {
80
- return _react2.default.createElement("div", { className: this.props.className, style: this.props.style });
81
- }
87
+ if (node instanceof HTMLElement) _this.setState({
88
+ width: node.offsetWidth
89
+ });
90
+ });
91
+
92
+ return _this;
93
+ }
94
+
95
+ _createClass(WidthProvider, [{
96
+ key: "componentDidMount",
97
+ value: function componentDidMount() {
98
+ this.mounted = true;
99
+ window.addEventListener("resize", this.onWindowResize); // Call to properly set the breakpoint and resize the elements.
100
+ // Note that if you're doing a full-width element, this can get a little wonky if a scrollbar
101
+ // appears because of the grid. In that case, fire your own resize event, or set `overflow: scroll` on your body.
82
102
 
83
- return _react2.default.createElement(ComposedComponent, _extends({}, rest, this.state));
84
- };
103
+ this.onWindowResize();
104
+ }
105
+ }, {
106
+ key: "componentWillUnmount",
107
+ value: function componentWillUnmount() {
108
+ this.mounted = false;
109
+ window.removeEventListener("resize", this.onWindowResize);
110
+ }
111
+ }, {
112
+ key: "render",
113
+ value: function render() {
114
+ var _this$props = this.props,
115
+ measureBeforeMount = _this$props.measureBeforeMount,
116
+ rest = _objectWithoutProperties(_this$props, ["measureBeforeMount"]);
117
+
118
+ if (measureBeforeMount && !this.mounted) {
119
+ return _react.default.createElement("div", {
120
+ className: this.props.className,
121
+ style: this.props.style
122
+ });
123
+ }
124
+
125
+ return _react.default.createElement(ComposedComponent, _extends({}, rest, this.state));
126
+ }
127
+ }]);
85
128
 
86
129
  return WidthProvider;
87
- }(_react2.default.Component), _class.defaultProps = {
130
+ }(_react.default.Component), _defineProperty(_class, "defaultProps", {
88
131
  measureBeforeMount: false
89
- }, _class.propTypes = {
132
+ }), _defineProperty(_class, "propTypes", {
90
133
  // If true, will not render children until mounted. Useful for getting the exact width before
91
134
  // rendering, to prevent any unsightly resizing.
92
- measureBeforeMount: _propTypes2.default.bool
93
- }, _temp2;
135
+ measureBeforeMount: _propTypes.default.bool
136
+ }), _temp;
94
137
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.getBreakpointFromWidth = getBreakpointFromWidth;
5
7
  exports.getColsFromBreakpoint = getColsFromBreakpoint;
6
8
  exports.findOrGenerateResponsiveLayout = findOrGenerateResponsiveLayout;
@@ -15,16 +17,23 @@ var _utils = require("./utils");
15
17
  * @param {Number} width Screen width.
16
18
  * @return {String} Highest breakpoint that is less than width.
17
19
  */
18
- function getBreakpointFromWidth(breakpoints, width) {
20
+ function getBreakpointFromWidth(breakpoints
21
+ /*: Breakpoints*/
22
+ , width
23
+ /*: number*/
24
+ )
25
+ /*: Breakpoint*/
26
+ {
19
27
  var sorted = sortBreakpoints(breakpoints);
20
28
  var matching = sorted[0];
29
+
21
30
  for (var i = 1, len = sorted.length; i < len; i++) {
22
31
  var breakpointName = sorted[i];
23
32
  if (width > breakpoints[breakpointName]) matching = breakpointName;
24
33
  }
34
+
25
35
  return matching;
26
36
  }
27
-
28
37
  /**
29
38
  * Given a breakpoint, get the # of cols set for it.
30
39
  * @param {String} breakpoint Breakpoint name.
@@ -33,13 +42,19 @@ function getBreakpointFromWidth(breakpoints, width) {
33
42
  */
34
43
 
35
44
 
36
- function getColsFromBreakpoint(breakpoint, cols) {
45
+ function getColsFromBreakpoint(breakpoint
46
+ /*: Breakpoint*/
47
+ , cols
48
+ /*: Breakpoints*/
49
+ )
50
+ /*: number*/
51
+ {
37
52
  if (!cols[breakpoint]) {
38
53
  throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint " + breakpoint + " is missing!");
39
54
  }
55
+
40
56
  return cols[breakpoint];
41
57
  }
42
-
43
58
  /**
44
59
  * Given existing layouts and a new breakpoint, find or generate a new layout.
45
60
  *
@@ -54,24 +69,45 @@ function getColsFromBreakpoint(breakpoint, cols) {
54
69
  * vertically.
55
70
  * @return {Array} New layout.
56
71
  */
57
- function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBreakpoint, cols, compactType) {
72
+
73
+
74
+ function findOrGenerateResponsiveLayout(layouts
75
+ /*: ResponsiveLayout*/
76
+ , breakpoints
77
+ /*: Breakpoints*/
78
+ , breakpoint
79
+ /*: Breakpoint*/
80
+ , lastBreakpoint
81
+ /*: Breakpoint*/
82
+ , cols
83
+ /*: number*/
84
+ , compactType
85
+ /*: CompactType*/
86
+ )
87
+ /*: Layout*/
88
+ {
58
89
  // If it already exists, just return it.
59
- if (layouts[breakpoint]) return (0, _utils.cloneLayout)(layouts[breakpoint]);
60
- // Find or generate the next layout
90
+ if (layouts[breakpoint]) return (0, _utils.cloneLayout)(layouts[breakpoint]); // Find or generate the next layout
91
+
61
92
  var layout = layouts[lastBreakpoint];
62
93
  var breakpointsSorted = sortBreakpoints(breakpoints);
63
94
  var breakpointsAbove = breakpointsSorted.slice(breakpointsSorted.indexOf(breakpoint));
95
+
64
96
  for (var i = 0, len = breakpointsAbove.length; i < len; i++) {
65
97
  var b = breakpointsAbove[i];
98
+
66
99
  if (layouts[b]) {
67
100
  layout = layouts[b];
68
101
  break;
69
102
  }
70
103
  }
104
+
71
105
  layout = (0, _utils.cloneLayout)(layout || []); // clone layout so we don't modify existing items
72
- return (0, _utils.compact)((0, _utils.correctBounds)(layout, { cols: cols }), compactType, cols);
73
- }
74
106
 
107
+ return (0, _utils.compact)((0, _utils.correctBounds)(layout, {
108
+ cols: cols
109
+ }), compactType, cols);
110
+ }
75
111
  /**
76
112
  * Given breakpoints, return an array of breakpoints sorted by width. This is usually
77
113
  * e.g. ['xxs', 'xs', 'sm', ...]
@@ -79,8 +115,16 @@ function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBr
79
115
  * @param {Object} breakpoints Key/value pair of breakpoint names to widths.
80
116
  * @return {Array} Sorted breakpoints.
81
117
  */
82
- function sortBreakpoints(breakpoints) {
83
- var keys = Object.keys(breakpoints);
118
+
119
+
120
+ function sortBreakpoints(breakpoints
121
+ /*: Breakpoints*/
122
+ )
123
+ /*: Array<Breakpoint>*/
124
+ {
125
+ var keys
126
+ /*: Array<string>*/
127
+ = Object.keys(breakpoints);
84
128
  return keys.sort(function (a, b) {
85
129
  return breakpoints[a] - breakpoints[b];
86
130
  });