66 createElement ,
77 createRef ,
88 ReactElement ,
9- RefObject
9+ RefObject ,
1010} from "react" ;
1111import Sortable , { MoveEvent , Options , SortableEvent } from "sortablejs" ;
1212import invariant from "tiny-invariant" ;
@@ -16,7 +16,7 @@ import {
1616 ItemInterface ,
1717 ReactSortableProps ,
1818 Store ,
19- UnHandledMethodNames
19+ UnHandledMethodNames ,
2020} from "./types" ;
2121import {
2222 createCustoms ,
@@ -27,8 +27,9 @@ import {
2727 handleStateRemove ,
2828 insertNodes ,
2929 removeNode ,
30- removeNodes
30+ removeNodes ,
3131} from "./util" ;
32+
3233/** Holds a global reference for which react element is being dragged */
3334// @todo - use context to manage this. How does one use 2 different providers?
3435const store : Store = { dragging : null } ;
@@ -37,7 +38,7 @@ export class ReactSortable<T extends ItemInterface> extends Component<
3738 ReactSortableProps < T >
3839> {
3940 static defaultProps : Partial < ReactSortableProps < any > > = {
40- clone : item => item
41+ clone : ( item ) => item ,
4142 } ;
4243
4344 private ref : RefObject < HTMLElement > ;
@@ -47,10 +48,10 @@ export class ReactSortable<T extends ItemInterface> extends Component<
4748 this . ref = createRef < HTMLElement > ( ) ;
4849
4950 // make all state false because we can't change sortable unless a mouse gesture is made.
50- const newList = props . list . map ( item => ( {
51+ const newList = props . list . map ( ( item ) => ( {
5152 ...item ,
5253 chosen : false ,
53- selected : false
54+ selected : false ,
5455 } ) ) ;
5556
5657 props . setList ( newList , this . sortable , store ) ;
@@ -81,7 +82,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
8182 {
8283 // @todo - find a way (perhaps with the callback) to allow AntD components to work
8384 ref : this . ref ,
84- ...classicProps
85+ ...classicProps ,
8586 } ,
8687 this . getChildren ( )
8788 ) ;
@@ -98,27 +99,25 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
9899 ghostClass = "sortable-ghost" ,
99100 swapClass = "sortable-swap-highlight" ,
100101 filter = "sortable-filter" ,
101- list
102+ list,
102103 } = this . props ;
103104
104105 // if no children, don't do anything.
105106 if ( ! children || children == null ) return null ;
106107 const dataid = dataIdAttr || "data-id" ;
107108 return Children . map ( children as ReactElement < any > [ ] , ( child , index ) => {
108109 const item = list [ index ] ;
109- const {
110- className : prevClassName ,
111- } = child . props ;
110+ const { className : prevClassName } = child . props ;
112111
113112 // @todo - handle the function if avalable. I don't think anyone will be doing this soon.
114113 const filtered = typeof filter === "string" && {
115- [ filter . replace ( "." , "" ) ] : ! ! item . filtered
114+ [ filter . replace ( "." , "" ) ] : ! ! item . filtered ,
116115 } ;
117116
118117 const className = classNames ( prevClassName , {
119118 [ selectedClass ] : item . selected ,
120119 [ chosenClass ] : item . chosen ,
121- ...filtered
120+ ...filtered ,
122121 // [dragClass]: true,
123122 // [fallbackClass]: true,
124123 // [ghostClass]: true,
@@ -127,7 +126,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
127126
128127 return cloneElement ( child , {
129128 [ dataid ] : child . key ,
130- className
129+ className,
131130 } ) ;
132131 } ) ;
133132 }
@@ -136,7 +135,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
136135 private get sortable ( ) : Sortable | null {
137136 const el = this . ref . current ;
138137 if ( el === null ) return null ;
139- const key = Object . keys ( el ) . find ( k => k . includes ( "Sortable" ) ) ;
138+ const key = Object . keys ( el ) . find ( ( k ) => k . includes ( "Sortable" ) ) ;
140139 if ( ! key ) return null ;
141140 //@ts -ignore - I know what I'm doing.
142141 return el [ key ] as Sortable ;
@@ -154,35 +153,35 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
154153 "onSpill" ,
155154 "onStart" ,
156155 "onUnchoose" ,
157- "onUpdate"
156+ "onUpdate" ,
158157 ] ;
159158 const NonDOMHandlers : UnHandledMethodNames [ ] = [
160159 "onChange" ,
161160 "onClone" ,
162161 "onFilter" ,
163- "onSort"
162+ "onSort" ,
164163 ] ;
165164 const newOptions : Options = destructurePropsForOptions ( this . props ) ;
166165 DOMHandlers . forEach (
167- name => ( newOptions [ name ] = this . prepareOnHandlerPropAndDOM ( name ) )
166+ ( name ) => ( newOptions [ name ] = this . prepareOnHandlerPropAndDOM ( name ) )
168167 ) ;
169168 NonDOMHandlers . forEach (
170- name => ( newOptions [ name ] = this . prepareOnHandlerProp ( name ) )
169+ ( name ) => ( newOptions [ name ] = this . prepareOnHandlerProp ( name ) )
171170 ) ;
172171
173172 /** onMove has 2 arguments and needs to be handled seperately. */
174173 const onMove = ( evt : MoveEvent , originalEvt : Event ) => {
175174 const { onMove } = this . props ;
176175 const defaultValue = evt . willInsertAfter || - 1 ;
177176 if ( ! onMove ) return defaultValue ;
178- const result = onMove ( evt , originalEvt , this . sortable , store ) ;
179- if ( typeof result === ' undefined' ) return false
180- return result
177+ const result = onMove ( evt , originalEvt , this . sortable , store ) ;
178+ if ( typeof result === " undefined" ) return false ;
179+ return result ;
181180 } ;
182181
183182 return {
184183 ...newOptions ,
185- onMove
184+ onMove,
186185 } ;
187186 }
188187
@@ -220,7 +219,10 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
220219 const otherList = [ ...store . dragging ! . props . list ] ;
221220 const customs = createCustoms ( evt , otherList ) ;
222221 removeNodes ( customs ) ;
223- const newList = handleStateAdd ( customs , list , evt , clone ) . map ( item => ( { ...item , selected : false } ) ) ;
222+ const newList = handleStateAdd ( customs , list , evt , clone ) . map ( ( item ) => ( {
223+ ...item ,
224+ selected : false ,
225+ } ) ) ;
224226 setList ( newList , this . sortable , store ) ;
225227 }
226228
@@ -242,13 +244,13 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
242244 case "multidrag" :
243245 customClones = customs . map ( ( item , index ) => ( {
244246 ...item ,
245- element : evt . clones [ index ]
247+ element : evt . clones [ index ] ,
246248 } ) ) ;
247249 break ;
248250 case "normal" :
249251 customClones = customs . map ( ( item , index ) => ( {
250252 ...item ,
251- element : evt . clone
253+ element : evt . clone ,
252254 } ) ) ;
253255 break ;
254256 case "swap" :
@@ -262,15 +264,15 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
262264 removeNodes ( customClones ) ;
263265
264266 // replace selected items with cloned items
265- customs . forEach ( curr => {
267+ customs . forEach ( ( curr ) => {
266268 const index = curr . oldIndex ;
267269 const newItem = this . props . clone ! ( curr . item , evt ) ;
268270 newList . splice ( index , 1 , newItem ) ;
269271 } ) ;
270272 }
271273
272274 // remove item.selected from list
273- newList = newList . map ( item => ( { ...item , selected : false } ) ) ;
275+ newList = newList . map ( ( item ) => ( { ...item , selected : false } ) ) ;
274276 setList ( newList , this . sortable , store ) ;
275277 }
276278
@@ -298,7 +300,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
298300 return {
299301 ...item ,
300302 chosen : true ,
301- }
303+ } ;
302304 }
303305 return item ;
304306 } ) ;
@@ -312,7 +314,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
312314 return {
313315 ...item ,
314316 chosen : false ,
315- }
317+ } ;
316318 }
317319 return item ;
318320 } ) ;
@@ -326,15 +328,15 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
326328
327329 onSelect ( evt : MultiDragEvent ) {
328330 const { list, setList } = this . props ;
329- const newList = list . map ( item => ( { ...item , selected : false } ) ) ;
330- evt . newIndicies . forEach ( curr => {
331+ const newList = list . map ( ( item ) => ( { ...item , selected : false } ) ) ;
332+ evt . newIndicies . forEach ( ( curr ) => {
331333 const index = curr . index ;
332334 if ( index === - 1 ) {
333335 console . log (
334336 `"${ evt . type } " had indice of "${ curr . index } ", which is probably -1 and doesn't usually happen here.`
335337 ) ;
336- console . log ( evt )
337- return
338+ console . log ( evt ) ;
339+ return ;
338340 }
339341 newList [ index ] . selected = true ;
340342 } ) ;
@@ -343,8 +345,8 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
343345
344346 onDeselect ( evt : MultiDragEvent ) {
345347 const { list, setList } = this . props ;
346- const newList = list . map ( item => ( { ...item , selected : false } ) ) ;
347- evt . newIndicies . forEach ( curr => {
348+ const newList = list . map ( ( item ) => ( { ...item , selected : false } ) ) ;
349+ evt . newIndicies . forEach ( ( curr ) => {
348350 const index = curr . index ;
349351 if ( index === - 1 ) return ;
350352 newList [ index ] . selected = true ;
0 commit comments