Skip to content

Commit 9d8fca1

Browse files
committed
style(*): runs initial format and lint on codebase
1 parent 575d0e0 commit 9d8fca1

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export {
1111
SortableEvent,
1212
SortableOptions,
1313
Swap,
14-
Utils
14+
Utils,
1515
} from "sortablejs";
1616
export { ReactSortable } from "./react-sortable";
1717
export * from "./types";

src/react-sortable.tsx

+38-36
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createElement,
77
createRef,
88
ReactElement,
9-
RefObject
9+
RefObject,
1010
} from "react";
1111
import Sortable, { MoveEvent, Options, SortableEvent } from "sortablejs";
1212
import invariant from "tiny-invariant";
@@ -16,7 +16,7 @@ import {
1616
ItemInterface,
1717
ReactSortableProps,
1818
Store,
19-
UnHandledMethodNames
19+
UnHandledMethodNames,
2020
} from "./types";
2121
import {
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?
3435
const 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;

src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {
22
CSSProperties,
33
ForwardRefExoticComponent,
44
ReactHTML,
5-
RefAttributes
5+
RefAttributes,
66
} from "react";
77
import Sortable, { MoveEvent, Options, SortableEvent } from "sortablejs";
88
import { ReactSortable } from "./react-sortable";
9-
import { Omit } from './util';
9+
import { Omit } from "./util";
1010

1111
// @todo: remove dynamic types and create declarative types instead for readability of user.
1212
// add these in docs as well

src/util.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export function handleDOMChanges<T extends ItemInterface>(
3838
}
3939

4040
export function removeNodes<T extends ItemInterface>(customs: Normalized<T>[]) {
41-
customs.forEach(curr => removeNode(curr.element));
41+
customs.forEach((curr) => removeNode(curr.element));
4242
}
4343

4444
export function insertNodes<T extends ItemInterface>(customs: Normalized<T>[]) {
45-
customs.forEach(curr => {
45+
customs.forEach((curr) => {
4646
insertNodeAt(curr.parentElement, curr.element, curr.oldIndex);
4747
});
4848
}
@@ -60,7 +60,7 @@ export function createCustoms<T extends ItemInterface>(
6060
element: evt.item,
6161
newIndex: evt.newIndex!,
6262
oldIndex: evt.oldIndex!,
63-
parentElement: evt.from
63+
parentElement: evt.from,
6464
};
6565
custom = [item];
6666
break;
@@ -69,13 +69,13 @@ export function createCustoms<T extends ItemInterface>(
6969
element: evt.item,
7070
oldIndex: evt.oldIndex!,
7171
newIndex: evt.newIndex!,
72-
...parentElement
72+
...parentElement,
7373
};
7474
const swap: Input = {
7575
element: evt.swapItem!,
7676
oldIndex: evt.newIndex!,
7777
newIndex: evt.oldIndex!,
78-
...parentElement
78+
...parentElement,
7979
};
8080
custom = [drag, swap];
8181
break;
@@ -84,7 +84,7 @@ export function createCustoms<T extends ItemInterface>(
8484
element: curr.multiDragElement,
8585
oldIndex: curr.index,
8686
newIndex: evt.newIndicies[index].index,
87-
...parentElement
87+
...parentElement,
8888
}));
8989
break;
9090
}
@@ -110,7 +110,7 @@ export function handleStateRemove<T extends ItemInterface>(
110110
normalized
111111
.concat()
112112
.reverse()
113-
.forEach(curr => newList.splice(curr.oldIndex, 1));
113+
.forEach((curr) => newList.splice(curr.oldIndex, 1));
114114
return newList;
115115
}
116116

@@ -121,9 +121,9 @@ export function handleStateAdd<T extends ItemInterface>(
121121
clone?: ((currentItem: T, evt: Sortable.SortableEvent) => T) | undefined
122122
): T[] {
123123
const newList = [...list];
124-
normalized.forEach(curr => {
125-
const newItem = (clone && evt) && clone(curr.item, evt);
126-
newList.splice(curr.newIndex, 0, newItem || curr.item)
124+
normalized.forEach((curr) => {
125+
const newItem = clone && evt && clone(curr.item, evt);
126+
newList.splice(curr.newIndex, 0, newItem || curr.item);
127127
});
128128
return newList;
129129
}
@@ -139,7 +139,7 @@ export function createNormalized<T extends ItemInterface>(
139139
list: T[]
140140
): Normalized<T>[] {
141141
const normalized = inputs
142-
.map<Normalized<T>>(curr => ({ ...curr, item: list[curr.oldIndex] }))
142+
.map<Normalized<T>>((curr) => ({ ...curr, item: list[curr.oldIndex] }))
143143
.sort((a, b) => a.oldIndex - b.oldIndex);
144144
return normalized;
145145
}
@@ -197,4 +197,4 @@ export function destructurePropsForOptions<T>(
197197
* Construct a type with the properties of T except for those in type K.
198198
* Including this allows for backwards compatibility with earlier versions of TS.
199199
*/
200-
export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
200+
export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

0 commit comments

Comments
 (0)