1+ ( function webpackUniversalModuleDefinition ( root , factory ) {
2+ if ( typeof exports === 'object' && typeof module === 'object' )
3+ module . exports = factory ( require ( "react" ) , require ( "react-dom" ) , require ( "sortablejs" ) ) ;
4+ else if ( typeof define === 'function' && define . amd )
5+ define ( [ "react" , "react-dom" , "sortablejs" ] , factory ) ;
6+ else if ( typeof exports === 'object' )
7+ exports [ "SortableMixin" ] = factory ( require ( "react" ) , require ( "react-dom" ) , require ( "sortablejs" ) ) ;
8+ else
9+ root [ "SortableMixin" ] = factory ( root [ "React" ] , root [ "ReactDOM" ] , root [ "Sortable" ] ) ;
10+ } ) ( this , function ( __WEBPACK_EXTERNAL_MODULE_1__ , __WEBPACK_EXTERNAL_MODULE_2__ , __WEBPACK_EXTERNAL_MODULE_3__ ) {
11+ return /******/ ( function ( modules ) { // webpackBootstrap
12+ /******/ // The module cache
13+ /******/ var installedModules = { } ;
14+
15+ /******/ // The require function
16+ /******/ function __webpack_require__ ( moduleId ) {
17+
18+ /******/ // Check if module is in cache
19+ /******/ if ( installedModules [ moduleId ] )
20+ /******/ return installedModules [ moduleId ] . exports ;
21+
22+ /******/ // Create a new module (and put it into the cache)
23+ /******/ var module = installedModules [ moduleId ] = {
24+ /******/ exports : { } ,
25+ /******/ id : moduleId ,
26+ /******/ loaded : false
27+ /******/ } ;
28+
29+ /******/ // Execute the module function
30+ /******/ modules [ moduleId ] . call ( module . exports , module , module . exports , __webpack_require__ ) ;
31+
32+ /******/ // Flag the module as loaded
33+ /******/ module . loaded = true ;
34+
35+ /******/ // Return the exports of the module
36+ /******/ return module . exports ;
37+ /******/ }
38+
39+
40+ /******/ // expose the modules object (__webpack_modules__)
41+ /******/ __webpack_require__ . m = modules ;
42+
43+ /******/ // expose the module cache
44+ /******/ __webpack_require__ . c = installedModules ;
45+
46+ /******/ // __webpack_public_path__
47+ /******/ __webpack_require__ . p = "" ;
48+
49+ /******/ // Load entry module and return exports
50+ /******/ return __webpack_require__ ( 0 ) ;
51+ /******/ } )
52+ /************************************************************************/
53+ /******/ ( [
54+ /* 0 */
55+ /***/ function ( module , exports , __webpack_require__ ) {
56+
57+ 'use strict' ;
58+
59+ Object . defineProperty ( exports , "__esModule" , {
60+ value : true
61+ } ) ;
62+
63+ 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 ; } ;
64+
65+ 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 ; } ; } ( ) ;
66+
67+ var _react = __webpack_require__ ( 1 ) ;
68+
69+ var _react2 = _interopRequireDefault ( _react ) ;
70+
71+ var _reactDom = __webpack_require__ ( 2 ) ;
72+
73+ var _reactDom2 = _interopRequireDefault ( _reactDom ) ;
74+
75+ var _sortablejs = __webpack_require__ ( 3 ) ;
76+
77+ var _sortablejs2 = _interopRequireDefault ( _sortablejs ) ;
78+
79+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
80+
81+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
82+
83+ 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 ; }
84+
85+ 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 ; }
86+
87+ var defaultOptions = {
88+ ref : 'list' ,
89+ model : 'items' ,
90+ onStart : 'handleStart' ,
91+ onEnd : 'handleEnd' ,
92+ onAdd : 'handleAdd' ,
93+ onUpdate : 'handleUpdate' ,
94+ onRemove : 'handleRemove' ,
95+ onSort : 'handleSort' ,
96+ onFilter : 'handleFilter' ,
97+ onMove : 'handleMove'
98+ } ;
99+
100+ var _nextSibling = null ;
101+ var _activeWrapperComponent = null ;
102+
103+ var refName = 'sortableComponent' ;
104+
105+ var getModelItems = function getModelItems ( wrapperComponent ) {
106+ var model = wrapperComponent . sortableOptions . model ;
107+ var sortableComponent = wrapperComponent . refs [ refName ] ;
108+ var _sortableComponent$st = sortableComponent . state ;
109+ var state = _sortableComponent$st === undefined ? { } : _sortableComponent$st ;
110+ var _sortableComponent$pr = sortableComponent . props ;
111+ var props = _sortableComponent$pr === undefined ? { } : _sortableComponent$pr ;
112+
113+ var items = state [ model ] || props [ model ] || [ ] ;
114+ return items . slice ( ) ; // returns a shallow copy of the items array
115+ } ;
116+
117+ var extend = function extend ( target ) {
118+ for ( var _len = arguments . length , sources = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
119+ sources [ _key - 1 ] = arguments [ _key ] ;
120+ }
121+
122+ sources . forEach ( function ( source ) {
123+ for ( var key in source ) {
124+ if ( source . hasOwnProperty ( key ) ) {
125+ target [ key ] = source [ key ] ;
126+ }
127+ }
128+ } ) ;
129+
130+ return target ;
131+ } ;
132+
133+ var SortableMixin = function SortableMixin ( ) {
134+ var options = arguments . length <= 0 || arguments [ 0 ] === undefined ? defaultOptions : arguments [ 0 ] ;
135+ return function ( Component ) {
136+ return function ( _React$Component ) {
137+ _inherits ( _class2 , _React$Component ) ;
138+
139+ function _class2 ( ) {
140+ var _Object$getPrototypeO ;
141+
142+ var _temp , _this , _ret ;
143+
144+ _classCallCheck ( this , _class2 ) ;
145+
146+ for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
147+ args [ _key2 ] = arguments [ _key2 ] ;
148+ }
149+
150+ return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _Object$getPrototypeO = Object . getPrototypeOf ( _class2 ) ) . call . apply ( _Object$getPrototypeO , [ this ] . concat ( args ) ) ) , _this ) , _this . state = {
151+ sortableInstance : null
152+ } , _this . sortableOptions = extend ( { } , defaultOptions , options ) , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
153+ }
154+
155+ _createClass ( _class2 , [ {
156+ key : 'componentDidMount' ,
157+ value : function componentDidMount ( ) {
158+ var _this2 = this ;
159+
160+ var sortableComponent = this . refs [ refName ] ;
161+ var emitEvent = function emitEvent ( type , evt ) {
162+ var methodName = _this2 . sortableOptions [ type ] ;
163+ var method = sortableComponent [ methodName ] ;
164+ method && method . call ( sortableComponent , evt , _this2 . state . sortableInstance ) ;
165+ } ;
166+
167+ var copyOptions = extend ( { } , this . sortableOptions ) ;
168+
169+ [ // Bind callbacks
170+ 'onStart' , 'onEnd' , 'onAdd' , 'onSort' , 'onUpdate' , 'onRemove' , 'onFilter' , 'onMove' ] . forEach ( function ( name ) {
171+ copyOptions [ name ] = function ( evt ) {
172+ if ( name === 'onStart' ) {
173+ _nextSibling = evt . item . nextElementSibling ;
174+ _activeWrapperComponent = _this2 ;
175+ } else if ( name === 'onAdd' || name === 'onUpdate' ) {
176+ evt . from . insertBefore ( evt . item , _nextSibling ) ;
177+
178+ var oldIndex = evt . oldIndex ;
179+ var newIndex = evt . newIndex ;
180+ var newState = { } ;
181+ var remoteState = { } ;
182+ var items = getModelItems ( _this2 ) ;
183+
184+ if ( name === 'onAdd' ) {
185+ var remoteItems = getModelItems ( _activeWrapperComponent ) ;
186+ var item = remoteItems . splice ( oldIndex , 1 ) [ 0 ] ;
187+ items . splice ( newIndex , 0 , item ) ;
188+
189+ remoteState [ _activeWrapperComponent . sortableOptions . model ] = remoteItems ;
190+ } else {
191+ items . splice ( newIndex , 0 , items . splice ( oldIndex , 1 ) [ 0 ] ) ;
192+ }
193+
194+ newState [ _this2 . sortableOptions . model ] = items ;
195+
196+ if ( copyOptions . stateHandler ) {
197+ sortableComponent [ copyOptions . stateHandler ] ( newState ) ;
198+ } else {
199+ sortableComponent . setState ( newState ) ;
200+ }
201+
202+ if ( _activeWrapperComponent !== _this2 ) {
203+ _activeWrapperComponent . refs [ refName ] . setState ( remoteState ) ;
204+ }
205+ }
206+
207+ setTimeout ( function ( ) {
208+ emitEvent ( name , evt ) ;
209+ } , 0 ) ;
210+ } ;
211+ } ) ;
212+ this . populatedOptions = copyOptions ;
213+ this . initSortable ( sortableComponent ) ;
214+ }
215+ } , {
216+ key : 'componentWillReceiveProps' ,
217+ value : function componentWillReceiveProps ( nextProps ) {
218+ var sortableComponent = this . refs [ refName ] ;
219+ var model = this . sortableOptions . model ;
220+ var items = nextProps [ model ] ;
221+
222+ if ( items ) {
223+ var newState = { } ;
224+ newState [ model ] = items ;
225+ sortableComponent . setState ( newState ) ;
226+ }
227+ }
228+ } , {
229+ key : 'componentDidUpdate' ,
230+ value : function componentDidUpdate ( prevProps ) {
231+ var model = this . sortableOptions . model ;
232+ var prevItems = prevProps [ model ] ;
233+ var currItems = this . props [ model ] ;
234+ if ( prevItems !== currItems ) {
235+ this . initSortable ( this . refs [ refName ] ) ;
236+ }
237+ }
238+ } , {
239+ key : 'componentWillUnmount' ,
240+ value : function componentWillUnmount ( ) {
241+ this . destroySortable ( ) ;
242+ }
243+ } , {
244+ key : 'initSortable' ,
245+ value : function initSortable ( sortableComponent ) {
246+ this . destroySortable ( ) ;
247+ var domNode = _reactDom2 . default . findDOMNode ( sortableComponent . refs [ this . sortableOptions . ref ] || sortableComponent ) ;
248+ var sortableInstance = _sortablejs2 . default . create ( domNode , this . populatedOptions ) ;
249+ this . setState ( { sortableInstance : sortableInstance } ) ;
250+ }
251+ } , {
252+ key : 'destroySortable' ,
253+ value : function destroySortable ( ) {
254+ if ( this . state . sortableInstance ) {
255+ this . state . sortableInstance . destroy ( ) ;
256+ this . setState ( { sortableInstance : null } ) ;
257+ }
258+ }
259+ } , {
260+ key : 'render' ,
261+ value : function render ( ) {
262+ return _react2 . default . createElement ( Component , _extends ( { ref : refName } , this . props , this . state ) ) ;
263+ }
264+ } ] ) ;
265+
266+ return _class2 ;
267+ } ( _react2 . default . Component ) ;
268+ } ;
269+ } ;
270+
271+ exports . default = SortableMixin ;
272+
273+ /***/ } ,
274+ /* 1 */
275+ /***/ function ( module , exports ) {
276+
277+ module . exports = __WEBPACK_EXTERNAL_MODULE_1__ ;
278+
279+ /***/ } ,
280+ /* 2 */
281+ /***/ function ( module , exports ) {
282+
283+ module . exports = __WEBPACK_EXTERNAL_MODULE_2__ ;
284+
285+ /***/ } ,
286+ /* 3 */
287+ /***/ function ( module , exports ) {
288+
289+ module . exports = __WEBPACK_EXTERNAL_MODULE_3__ ;
290+
291+ /***/ }
292+ /******/ ] )
293+ } ) ;
294+ ;
0 commit comments