@@ -524,6 +524,8 @@ var _safeHTMLElement = __webpack_require__(8);
524
524
525
525
var _safeHTMLElement2 = _interopRequireDefault ( _safeHTMLElement ) ;
526
526
527
+ var _reactLifecyclesCompat = __webpack_require__ ( 22 ) ;
528
+
527
529
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 ) ) newObj [ key ] = obj [ key ] ; } } newObj . default = obj ; return newObj ; } }
528
530
529
531
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
@@ -586,31 +588,37 @@ var Modal = function (_Component) {
586
588
! isReact16 && this . renderPortal ( this . props ) ;
587
589
}
588
590
} , {
589
- key : "componentWillReceiveProps" ,
590
- value : function componentWillReceiveProps ( newProps ) {
591
+ key : "getSnapshotBeforeUpdate" ,
592
+ value : function getSnapshotBeforeUpdate ( prevProps ) {
593
+ var prevParent = getParentElement ( prevProps . parentSelector ) ;
594
+ var nextParent = getParentElement ( this . props . parentSelector ) ;
595
+ return { prevParent : prevParent , nextParent : nextParent } ;
596
+ }
597
+ } , {
598
+ key : "componentDidUpdate" ,
599
+ value : function componentDidUpdate ( prevProps , _ , snapshot ) {
591
600
if ( ! _safeHTMLElement . canUseDOM ) return ;
592
- var isOpen = newProps . isOpen ;
593
- // Stop unnecessary renders if modal is remaining closed
594
-
595
- if ( ! this . props . isOpen && ! isOpen ) return ;
601
+ var _props = this . props ,
602
+ isOpen = _props . isOpen ,
603
+ portalClassName = _props . portalClassName ;
596
604
597
- var currentParent = getParentElement ( this . props . parentSelector ) ;
598
- var newParent = getParentElement ( newProps . parentSelector ) ;
599
605
600
- if ( newParent !== currentParent ) {
601
- currentParent . removeChild ( this . node ) ;
602
- newParent . appendChild ( this . node ) ;
606
+ if ( prevProps . portalClassName !== portalClassName ) {
607
+ this . node . className = portalClassName ;
603
608
}
604
609
605
- ! isReact16 && this . renderPortal ( newProps ) ;
606
- }
607
- } , {
608
- key : "componentWillUpdate" ,
609
- value : function componentWillUpdate ( newProps ) {
610
- if ( ! _safeHTMLElement . canUseDOM ) return ;
611
- if ( newProps . portalClassName !== this . props . portalClassName ) {
612
- this . node . className = newProps . portalClassName ;
610
+ // Stop unnecessary renders if modal is remaining closed
611
+ if ( ! prevProps . isOpen && ! isOpen ) return ;
612
+
613
+ var prevParent = snapshot . prevParent ,
614
+ nextParent = snapshot . nextParent ;
615
+
616
+ if ( nextParent !== prevParent ) {
617
+ prevParent . removeChild ( this . node ) ;
618
+ nextParent . appendChild ( this . node ) ;
613
619
}
620
+
621
+ ! isReact16 && this . renderPortal ( this . props ) ;
614
622
}
615
623
} , {
616
624
key : "componentWillUnmount" ,
@@ -735,6 +743,10 @@ Modal.defaultStyles = {
735
743
padding : "20px"
736
744
}
737
745
} ;
746
+
747
+
748
+ ( 0 , _reactLifecyclesCompat . polyfill ) ( Modal ) ;
749
+
738
750
exports . default = Modal ;
739
751
740
752
/***/ } ) ,
@@ -1594,10 +1606,6 @@ var ModalPortal = function (_Component) {
1594
1606
1595
1607
var _this = _possibleConstructorReturn ( this , ( ModalPortal . __proto__ || Object . getPrototypeOf ( ModalPortal ) ) . call ( this , props ) ) ;
1596
1608
1597
- _this . setFocusAfterRender = function ( focus ) {
1598
- _this . focusAfterRender = _this . props . shouldFocusAfterRender && focus ;
1599
- } ;
1600
-
1601
1609
_this . setOverlayRef = function ( overlay ) {
1602
1610
_this . overlay = overlay ;
1603
1611
_this . props . overlayRef && _this . props . overlayRef ( overlay ) ;
@@ -1713,16 +1721,6 @@ var ModalPortal = function (_Component) {
1713
1721
}
1714
1722
}
1715
1723
_this . shouldClose = null ;
1716
- _this . moveFromContentToOverlay = null ;
1717
- } ;
1718
-
1719
- _this . handleOverlayOnMouseUp = function ( ) {
1720
- if ( _this . moveFromContentToOverlay === null ) {
1721
- _this . shouldClose = false ;
1722
- }
1723
- if ( _this . props . shouldCloseOnOverlayClick ) {
1724
- _this . shouldClose = true ;
1725
- }
1726
1724
} ;
1727
1725
1728
1726
_this . handleContentOnMouseUp = function ( ) {
@@ -1733,7 +1731,6 @@ var ModalPortal = function (_Component) {
1733
1731
if ( ! _this . props . shouldCloseOnOverlayClick && event . target == _this . overlay ) {
1734
1732
event . preventDefault ( ) ;
1735
1733
}
1736
- _this . moveFromContentToOverlay = false ;
1737
1734
} ;
1738
1735
1739
1736
_this . handleContentOnClick = function ( ) {
@@ -1742,7 +1739,6 @@ var ModalPortal = function (_Component) {
1742
1739
1743
1740
_this . handleContentOnMouseDown = function ( ) {
1744
1741
_this . shouldClose = false ;
1745
- _this . moveFromContentToOverlay = false ;
1746
1742
} ;
1747
1743
1748
1744
_this . requestClose = function ( event ) {
@@ -1797,39 +1793,33 @@ var ModalPortal = function (_Component) {
1797
1793
_createClass ( ModalPortal , [ {
1798
1794
key : "componentDidMount" ,
1799
1795
value : function componentDidMount ( ) {
1800
- // Focus needs to be set when mounting and already open
1801
1796
if ( this . props . isOpen ) {
1802
- this . setFocusAfterRender ( true ) ;
1803
1797
this . open ( ) ;
1804
1798
}
1805
1799
}
1806
1800
} , {
1807
- key : "componentWillReceiveProps " ,
1808
- value : function componentWillReceiveProps ( newProps ) {
1801
+ key : "componentDidUpdate " ,
1802
+ value : function componentDidUpdate ( prevProps , prevState ) {
1809
1803
if ( undefined !== "production" ) {
1810
- if ( newProps . bodyOpenClassName !== this . props . bodyOpenClassName ) {
1804
+ if ( prevProps . bodyOpenClassName !== this . props . bodyOpenClassName ) {
1811
1805
// eslint-disable-next-line no-console
1812
1806
console . warn ( 'React-Modal: "bodyOpenClassName" prop has been modified. ' + "This may cause unexpected behavior when multiple modals are open." ) ;
1813
1807
}
1814
- if ( newProps . htmlOpenClassName !== this . props . htmlOpenClassName ) {
1808
+ if ( prevProps . htmlOpenClassName !== this . props . htmlOpenClassName ) {
1815
1809
// eslint-disable-next-line no-console
1816
1810
console . warn ( 'React-Modal: "htmlOpenClassName" prop has been modified. ' + "This may cause unexpected behavior when multiple modals are open." ) ;
1817
1811
}
1818
1812
}
1819
- // Focus only needs to be set once when the modal is being opened
1820
- if ( ! this . props . isOpen && newProps . isOpen ) {
1821
- this . setFocusAfterRender ( true ) ;
1813
+
1814
+ if ( this . props . isOpen && ! prevProps . isOpen ) {
1822
1815
this . open ( ) ;
1823
- } else if ( this . props . isOpen && ! newProps . isOpen ) {
1816
+ } else if ( ! this . props . isOpen && prevProps . isOpen ) {
1824
1817
this . close ( ) ;
1825
1818
}
1826
- }
1827
- } , {
1828
- key : "componentDidUpdate" ,
1829
- value : function componentDidUpdate ( ) {
1830
- if ( this . focusAfterRender ) {
1819
+
1820
+ // Focus only needs to be set once when the modal is being opened
1821
+ if ( this . props . shouldFocusAfterRender && this . state . isOpen && ! prevState . isOpen ) {
1831
1822
this . focusContent ( ) ;
1832
- this . setFocusAfterRender ( false ) ;
1833
1823
}
1834
1824
}
1835
1825
} , {
@@ -1880,7 +1870,6 @@ var ModalPortal = function (_Component) {
1880
1870
style : _extends ( { } , overlayStyles , this . props . style . overlay ) ,
1881
1871
onClick : this . handleOverlayOnClick ,
1882
1872
onMouseDown : this . handleOverlayOnMouseDown ,
1883
- onMouseUp : this . handleOverlayOnMouseUp ,
1884
1873
"aria-modal" : "true"
1885
1874
} ,
1886
1875
_react2 . default . createElement (
@@ -2355,6 +2344,170 @@ var __WEBPACK_AMD_DEFINE_RESULT__;/*!
2355
2344
} ( ) ) ;
2356
2345
2357
2346
2347
+ /***/ } ) ,
2348
+ /* 22 */
2349
+ /***/ ( function ( module , __webpack_exports__ , __webpack_require__ ) {
2350
+
2351
+ "use strict" ;
2352
+ Object . defineProperty ( __webpack_exports__ , "__esModule" , { value : true } ) ;
2353
+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "polyfill" , function ( ) { return polyfill ; } ) ;
2354
+ /**
2355
+ * Copyright (c) 2013-present, Facebook, Inc.
2356
+ *
2357
+ * This source code is licensed under the MIT license found in the
2358
+ * LICENSE file in the root directory of this source tree.
2359
+ */
2360
+
2361
+ function componentWillMount ( ) {
2362
+ // Call this.constructor.gDSFP to support sub-classes.
2363
+ var state = this . constructor . getDerivedStateFromProps ( this . props , this . state ) ;
2364
+ if ( state !== null && state !== undefined ) {
2365
+ this . setState ( state ) ;
2366
+ }
2367
+ }
2368
+
2369
+ function componentWillReceiveProps ( nextProps ) {
2370
+ // Call this.constructor.gDSFP to support sub-classes.
2371
+ var state = this . constructor . getDerivedStateFromProps ( nextProps , this . state ) ;
2372
+ if ( state !== null && state !== undefined ) {
2373
+ this . setState ( state ) ;
2374
+ }
2375
+ }
2376
+
2377
+ function componentWillUpdate ( nextProps , nextState ) {
2378
+ try {
2379
+ var prevProps = this . props ;
2380
+ var prevState = this . state ;
2381
+ this . props = nextProps ;
2382
+ this . state = nextState ;
2383
+ this . __reactInternalSnapshotFlag = true ;
2384
+ this . __reactInternalSnapshot = this . getSnapshotBeforeUpdate (
2385
+ prevProps ,
2386
+ prevState
2387
+ ) ;
2388
+ } finally {
2389
+ this . props = prevProps ;
2390
+ this . state = prevState ;
2391
+ }
2392
+ }
2393
+
2394
+ // React may warn about cWM/cWRP/cWU methods being deprecated.
2395
+ // Add a flag to suppress these warnings for this special case.
2396
+ componentWillMount . __suppressDeprecationWarning = true ;
2397
+ componentWillReceiveProps . __suppressDeprecationWarning = true ;
2398
+ componentWillUpdate . __suppressDeprecationWarning = true ;
2399
+
2400
+ function polyfill ( Component ) {
2401
+ var prototype = Component . prototype ;
2402
+
2403
+ if ( ! prototype || ! prototype . isReactComponent ) {
2404
+ throw new Error ( 'Can only polyfill class components' ) ;
2405
+ }
2406
+
2407
+ if (
2408
+ typeof Component . getDerivedStateFromProps !== 'function' &&
2409
+ typeof prototype . getSnapshotBeforeUpdate !== 'function'
2410
+ ) {
2411
+ return Component ;
2412
+ }
2413
+
2414
+ // If new component APIs are defined, "unsafe" lifecycles won't be called.
2415
+ // Error if any of these lifecycles are present,
2416
+ // Because they would work differently between older and newer (16.3+) versions of React.
2417
+ var foundWillMountName = null ;
2418
+ var foundWillReceivePropsName = null ;
2419
+ var foundWillUpdateName = null ;
2420
+ if ( typeof prototype . componentWillMount === 'function' ) {
2421
+ foundWillMountName = 'componentWillMount' ;
2422
+ } else if ( typeof prototype . UNSAFE_componentWillMount === 'function' ) {
2423
+ foundWillMountName = 'UNSAFE_componentWillMount' ;
2424
+ }
2425
+ if ( typeof prototype . componentWillReceiveProps === 'function' ) {
2426
+ foundWillReceivePropsName = 'componentWillReceiveProps' ;
2427
+ } else if ( typeof prototype . UNSAFE_componentWillReceiveProps === 'function' ) {
2428
+ foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps' ;
2429
+ }
2430
+ if ( typeof prototype . componentWillUpdate === 'function' ) {
2431
+ foundWillUpdateName = 'componentWillUpdate' ;
2432
+ } else if ( typeof prototype . UNSAFE_componentWillUpdate === 'function' ) {
2433
+ foundWillUpdateName = 'UNSAFE_componentWillUpdate' ;
2434
+ }
2435
+ if (
2436
+ foundWillMountName !== null ||
2437
+ foundWillReceivePropsName !== null ||
2438
+ foundWillUpdateName !== null
2439
+ ) {
2440
+ var componentName = Component . displayName || Component . name ;
2441
+ var newApiName =
2442
+ typeof Component . getDerivedStateFromProps === 'function'
2443
+ ? 'getDerivedStateFromProps()'
2444
+ : 'getSnapshotBeforeUpdate()' ;
2445
+
2446
+ throw Error (
2447
+ 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
2448
+ componentName +
2449
+ ' uses ' +
2450
+ newApiName +
2451
+ ' but also contains the following legacy lifecycles:' +
2452
+ ( foundWillMountName !== null ? '\n ' + foundWillMountName : '' ) +
2453
+ ( foundWillReceivePropsName !== null
2454
+ ? '\n ' + foundWillReceivePropsName
2455
+ : '' ) +
2456
+ ( foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '' ) +
2457
+ '\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
2458
+ 'https://fb.me/react-async-component-lifecycle-hooks'
2459
+ ) ;
2460
+ }
2461
+
2462
+ // React <= 16.2 does not support static getDerivedStateFromProps.
2463
+ // As a workaround, use cWM and cWRP to invoke the new static lifecycle.
2464
+ // Newer versions of React will ignore these lifecycles if gDSFP exists.
2465
+ if ( typeof Component . getDerivedStateFromProps === 'function' ) {
2466
+ prototype . componentWillMount = componentWillMount ;
2467
+ prototype . componentWillReceiveProps = componentWillReceiveProps ;
2468
+ }
2469
+
2470
+ // React <= 16.2 does not support getSnapshotBeforeUpdate.
2471
+ // As a workaround, use cWU to invoke the new lifecycle.
2472
+ // Newer versions of React will ignore that lifecycle if gSBU exists.
2473
+ if ( typeof prototype . getSnapshotBeforeUpdate === 'function' ) {
2474
+ if ( typeof prototype . componentDidUpdate !== 'function' ) {
2475
+ throw new Error (
2476
+ 'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
2477
+ ) ;
2478
+ }
2479
+
2480
+ prototype . componentWillUpdate = componentWillUpdate ;
2481
+
2482
+ var componentDidUpdate = prototype . componentDidUpdate ;
2483
+
2484
+ prototype . componentDidUpdate = function componentDidUpdatePolyfill (
2485
+ prevProps ,
2486
+ prevState ,
2487
+ maybeSnapshot
2488
+ ) {
2489
+ // 16.3+ will not execute our will-update method;
2490
+ // It will pass a snapshot value to did-update though.
2491
+ // Older versions will require our polyfilled will-update value.
2492
+ // We need to handle both cases, but can't just check for the presence of "maybeSnapshot",
2493
+ // Because for <= 15.x versions this might be a "prevContext" object.
2494
+ // We also can't just check "__reactInternalSnapshot",
2495
+ // Because get-snapshot might return a falsy value.
2496
+ // So check for the explicit __reactInternalSnapshotFlag flag to determine behavior.
2497
+ var snapshot = this . __reactInternalSnapshotFlag
2498
+ ? this . __reactInternalSnapshot
2499
+ : maybeSnapshot ;
2500
+
2501
+ componentDidUpdate . call ( this , prevProps , prevState , snapshot ) ;
2502
+ } ;
2503
+ }
2504
+
2505
+ return Component ;
2506
+ }
2507
+
2508
+
2509
+
2510
+
2358
2511
/***/ } )
2359
2512
/******/ ] ) ;
2360
2513
} ) ;
0 commit comments