1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
Object . defineProperty ( exports , "__esModule" , {
4
4
value : true
5
5
} ) ;
6
- exports . withResizeDetector = undefined ;
6
+ exports . default = exports . withResizeDetector = void 0 ;
7
7
8
- var _createClass = function ( ) { 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 ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
8
+ var _react = _interopRequireWildcard ( require ( "react" ) ) ;
9
9
10
- var _react = require ( 'react' ) ;
10
+ var _propTypes = _interopRequireDefault ( require ( "prop-types" ) ) ;
11
11
12
- var _react2 = _interopRequireDefault ( _react ) ;
12
+ var _resizeObserverPolyfill = _interopRequireDefault ( require ( "resize-observer-polyfill" ) ) ;
13
13
14
- var _propTypes = require ( 'prop-types' ) ;
14
+ var _lodash = _interopRequireDefault ( require ( "lodash.debounce" ) ) ;
15
15
16
- var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
16
+ var _lodash2 = _interopRequireDefault ( require ( "lodash.throttle" ) ) ;
17
17
18
- var _resizeObserverPolyfill = require ( 'resize-observer-polyfill' ) ;
18
+ var _lodash3 = _interopRequireDefault ( require ( "lodash.isfunction" ) ) ;
19
19
20
- var _resizeObserverPolyfill2 = _interopRequireDefault ( _resizeObserverPolyfill ) ;
20
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
21
21
22
- var _lodash = require ( 'lodash.debounce' ) ;
22
+ function _interopRequireWildcard ( obj ) { if ( obj && obj . __esModule ) { return obj ; } else { var newObj = { } ; if ( obj != null ) { for ( var key in obj ) { if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) { var desc = Object . defineProperty && Object . getOwnPropertyDescriptor ? Object . getOwnPropertyDescriptor ( obj , key ) : { } ; if ( desc . get || desc . set ) { Object . defineProperty ( newObj , key , desc ) ; } else { newObj [ key ] = obj [ key ] ; } } } } newObj . default = obj ; return newObj ; } }
23
23
24
- var _lodash2 = _interopRequireDefault ( _lodash ) ;
24
+ 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 ) ; }
25
25
26
- var _lodash3 = require ( 'lodash.throttle' ) ;
26
+ function _toConsumableArray ( arr ) { return _arrayWithoutHoles ( arr ) || _iterableToArray ( arr ) || _nonIterableSpread ( ) ; }
27
27
28
- var _lodash4 = _interopRequireDefault ( _lodash3 ) ;
28
+ function _nonIterableSpread ( ) { throw new TypeError ( "Invalid attempt to spread non-iterable instance" ) ; }
29
29
30
- var _lodash5 = require ( 'lodash.isfunction' ) ;
30
+ function _iterableToArray ( iter ) { if ( Symbol . iterator in Object ( iter ) || Object . prototype . toString . call ( iter ) === "[object Arguments]" ) return Array . from ( iter ) ; }
31
31
32
- var _lodash6 = _interopRequireDefault ( _lodash5 ) ;
32
+ function _arrayWithoutHoles ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = new Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } }
33
33
34
- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
34
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
35
35
36
- function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
36
+ 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 ) ; } }
37
37
38
- function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
38
+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
39
+
40
+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
39
41
40
- 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 ; }
42
+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
41
43
42
- 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 ; }
44
+ 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 ) ; }
43
45
44
- var listMode = { debounce : _lodash2 . default , throttle : _lodash4 . default } ;
46
+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
45
47
48
+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
49
+
50
+ 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 ; }
51
+
52
+ var listMode = {
53
+ debounce : _lodash . default ,
54
+ throttle : _lodash2 . default
55
+ } ;
46
56
var styles = {
47
57
position : 'absolute' ,
48
58
width : 0 ,
49
59
height : 0 ,
50
60
visibility : 'hidden' ,
51
61
display : 'none'
52
62
} ;
53
-
54
63
/**
55
64
* detect component's children and convert them to array
56
65
* @param {* } children - component's children
57
66
*/
67
+
58
68
function convertChildrenToArray ( children ) {
59
69
if ( ! children ) return [ ] ;
60
70
if ( ! Array . isArray ( children ) ) return [ children ] ;
61
71
return children ;
62
72
}
63
73
64
- var ResizeDetector = function ( _PureComponent ) {
74
+ var ResizeDetector =
75
+ /*#__PURE__*/
76
+ function ( _PureComponent ) {
65
77
_inherits ( ResizeDetector , _PureComponent ) ;
66
78
67
79
function ResizeDetector ( props ) {
80
+ var _this ;
81
+
68
82
_classCallCheck ( this , ResizeDetector ) ;
69
83
70
- var _this = _possibleConstructorReturn ( this , ( ResizeDetector . __proto__ || Object . getPrototypeOf ( ResizeDetector ) ) . call ( this , props ) ) ;
84
+ _this = _possibleConstructorReturn ( this , _getPrototypeOf ( ResizeDetector ) . call ( this , props ) ) ;
71
85
72
- _this . getElement = function ( ) {
86
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "getElement" , function ( ) {
73
87
var resizableElementId = _this . props . resizableElementId ;
74
-
75
-
76
88
var otherElement = resizableElementId && document . getElementById ( resizableElementId ) ;
77
89
var parentElement = _this . el && _this . el . parentElement ;
78
-
79
90
var resizableElement = otherElement || parentElement ;
80
-
81
91
return resizableElement ;
82
- } ;
92
+ } ) ;
83
93
84
- _this . createResizeHandler = function ( entries ) {
94
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "createResizeHandler" , function ( entries ) {
85
95
var _this$props = _this . props ,
86
96
handleWidth = _this$props . handleWidth ,
87
97
handleHeight = _this$props . handleHeight ,
88
98
onResize = _this$props . onResize ;
89
-
90
99
entries . forEach ( function ( entry ) {
91
100
var _entry$contentRect = entry . contentRect ,
92
101
width = _entry$contentRect . width ,
93
102
height = _entry$contentRect . height ;
94
-
95
103
var notifyWidth = handleWidth && _this . state . width !== width ;
96
104
var notifyHeight = handleHeight && _this . state . height !== height ;
105
+
97
106
if ( ! _this . skipOnMount && ( notifyWidth || notifyHeight ) && typeof window !== 'undefined' ) {
98
107
_this . animationFrameID = window . requestAnimationFrame ( function ( ) {
99
108
onResize ( width , height ) ;
100
- _this . setState ( { width : width , height : height } ) ;
109
+
110
+ _this . setState ( {
111
+ width : width ,
112
+ height : height
113
+ } ) ;
101
114
} ) ;
102
115
}
116
+
103
117
_this . skipOnMount = false ;
104
118
} ) ;
105
- } ;
119
+ } ) ;
106
120
107
- _this . handleRenderProp = function ( ) {
121
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "handleRenderProp" , function ( ) {
108
122
var _this$state = _this . state ,
109
123
width = _this$state . width ,
110
124
height = _this$state . height ;
111
125
var render = _this . props . render ;
112
126
113
127
if ( render && typeof render === 'function' ) {
114
- return ( 0 , _react . cloneElement ) ( render ( { width : width , height : height } ) , { key : 'render' } ) ;
128
+ return ( 0 , _react . cloneElement ) ( render ( {
129
+ width : width ,
130
+ height : height
131
+ } ) , {
132
+ key : 'render'
133
+ } ) ;
115
134
}
116
135
117
136
return undefined ;
118
- } ;
137
+ } ) ;
119
138
120
- _this . renderChildren = function ( ) {
139
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "renderChildren" , function ( ) {
121
140
var _this$state2 = _this . state ,
122
141
width = _this$state2 . width ,
123
142
height = _this$state2 . height ;
124
143
var children = _this . props . children ;
125
-
126
144
return convertChildrenToArray ( children ) . filter ( function ( child ) {
127
145
return ! ! child ;
128
146
} ) . map ( function ( child , key ) {
129
- if ( ( 0 , _lodash6 . default ) ( child ) ) return ( 0 , _react . cloneElement ) ( child ( width , height ) , { key : key } ) ;
130
- if ( ( 0 , _react . isValidElement ) ( child ) ) return ( 0 , _react . cloneElement ) ( child , { width : width , height : height , key : key } ) ;
147
+ if ( ( 0 , _lodash3 . default ) ( child ) ) return ( 0 , _react . cloneElement ) ( child ( width , height ) , {
148
+ key : key
149
+ } ) ;
150
+ if ( ( 0 , _react . isValidElement ) ( child ) ) return ( 0 , _react . cloneElement ) ( child , {
151
+ width : width ,
152
+ height : height ,
153
+ key : key
154
+ } ) ;
131
155
return child ;
132
156
} ) ;
133
- } ;
157
+ } ) ;
134
158
135
159
var skipOnMount = props . skipOnMount ,
136
160
refreshMode = props . refreshMode ,
137
161
refreshRate = props . refreshRate ;
138
-
139
-
140
162
_this . state = {
141
163
width : undefined ,
142
164
height : undefined
143
165
} ;
144
-
145
166
_this . skipOnMount = skipOnMount ;
146
167
_this . animationFrameID = null ;
147
-
148
168
_this . resizeHandler = listMode [ refreshMode ] && listMode [ refreshMode ] ( _this . createResizeHandler , refreshRate ) || _this . createResizeHandler ;
149
-
150
- _this . ro = new _resizeObserverPolyfill2 . default ( _this . resizeHandler ) ;
169
+ _this . ro = new _resizeObserverPolyfill . default ( _this . resizeHandler ) ;
151
170
return _this ;
152
171
}
153
172
154
173
_createClass ( ResizeDetector , [ {
155
- key : ' componentDidMount' ,
174
+ key : " componentDidMount" ,
156
175
value : function componentDidMount ( ) {
157
176
var resizableElement = this . getElement ( ) ;
158
177
if ( resizableElement ) this . ro . observe ( resizableElement ) ;
159
178
}
160
179
} , {
161
- key : ' componentWillUnmount' ,
180
+ key : " componentWillUnmount" ,
162
181
value : function componentWillUnmount ( ) {
163
182
var resizableElement = this . getElement ( ) ;
164
183
if ( resizableElement ) this . ro . unobserve ( resizableElement ) ;
184
+
165
185
if ( typeof window !== 'undefined' && this . animationFrameID ) {
166
186
window . cancelAnimationFrame ( this . animationFrameID ) ;
167
187
}
188
+
168
189
if ( this . resizeHandler && this . resizeHandler . cancel ) {
169
190
// cancel debounced handler
170
191
this . resizeHandler . cancel ( ) ;
171
192
}
172
193
}
173
194
} , {
174
- key : ' render' ,
195
+ key : " render" ,
175
196
value : function render ( ) {
176
197
var _this2 = this ;
177
198
178
- return [ _react2 . default . createElement ( ' div' , {
179
- key : ' resize-detector' ,
199
+ return [ _react . default . createElement ( " div" , {
200
+ key : " resize-detector" ,
180
201
style : styles ,
181
202
ref : function ref ( el ) {
182
203
_this2 . el = el ;
@@ -189,17 +210,17 @@ var ResizeDetector = function (_PureComponent) {
189
210
} ( _react . PureComponent ) ;
190
211
191
212
ResizeDetector . propTypes = {
192
- handleWidth : _propTypes2 . default . bool ,
193
- handleHeight : _propTypes2 . default . bool ,
194
- skipOnMount : _propTypes2 . default . bool ,
195
- refreshRate : _propTypes2 . default . number ,
196
- refreshMode : _propTypes2 . default . string ,
197
- resizableElementId : _propTypes2 . default . string ,
198
- onResize : _propTypes2 . default . func ,
199
- render : _propTypes2 . default . func ,
200
- children : _propTypes2 . default . any // eslint-disable-line react/forbid-prop-types
201
- } ;
213
+ handleWidth : _propTypes . default . bool ,
214
+ handleHeight : _propTypes . default . bool ,
215
+ skipOnMount : _propTypes . default . bool ,
216
+ refreshRate : _propTypes . default . number ,
217
+ refreshMode : _propTypes . default . string ,
218
+ resizableElementId : _propTypes . default . string ,
219
+ onResize : _propTypes . default . func ,
220
+ render : _propTypes . default . func ,
221
+ children : _propTypes . default . any // eslint-disable-line react/forbid-prop-types
202
222
223
+ } ;
203
224
ResizeDetector . defaultProps = {
204
225
handleWidth : false ,
205
226
handleHeight : false ,
@@ -214,27 +235,27 @@ ResizeDetector.defaultProps = {
214
235
children : null
215
236
} ;
216
237
217
- var withResizeDetector = exports . withResizeDetector = function withResizeDetector ( WrappedComponent ) {
218
- var props = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { handleWidth : true , handleHeight : true } ;
238
+ var withResizeDetector = function withResizeDetector ( WrappedComponent ) {
239
+ var props = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : {
240
+ handleWidth : true ,
241
+ handleHeight : true
242
+ } ;
219
243
return (
244
+ /*#__PURE__*/
220
245
// eslint-disable-next-line
221
246
function ( _Component ) {
222
247
_inherits ( ResizeDetectorHOC , _Component ) ;
223
248
224
249
function ResizeDetectorHOC ( ) {
225
250
_classCallCheck ( this , ResizeDetectorHOC ) ;
226
251
227
- return _possibleConstructorReturn ( this , ( ResizeDetectorHOC . __proto__ || Object . getPrototypeOf ( ResizeDetectorHOC ) ) . apply ( this , arguments ) ) ;
252
+ return _possibleConstructorReturn ( this , _getPrototypeOf ( ResizeDetectorHOC ) . apply ( this , arguments ) ) ;
228
253
}
229
254
230
255
_createClass ( ResizeDetectorHOC , [ {
231
- key : ' render' ,
256
+ key : " render" ,
232
257
value : function render ( ) {
233
- return _react2 . default . createElement (
234
- ResizeDetector ,
235
- props ,
236
- _react2 . default . createElement ( WrappedComponent , this . props )
237
- ) ;
258
+ return _react . default . createElement ( ResizeDetector , props , _react . default . createElement ( WrappedComponent , this . props ) ) ;
238
259
}
239
260
} ] ) ;
240
261
@@ -243,4 +264,6 @@ var withResizeDetector = exports.withResizeDetector = function withResizeDetecto
243
264
) ;
244
265
} ;
245
266
246
- exports . default = ResizeDetector ;
267
+ exports . withResizeDetector = withResizeDetector ;
268
+ var _default = ResizeDetector ;
269
+ exports . default = _default ;
0 commit comments