Skip to content

Commit

Permalink
Merge pull request #230 from SortableJS/infra-2
Browse files Browse the repository at this point in the history
  • Loading branch information
andresin87 committed Feb 8, 2022
2 parents 43b721a + a658d04 commit c1f444d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ temp
dist
# todo - get story book only when releasing.
storybook-static
yarn.lock
yarn.lock
package-lock.json
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"arrowParens": "always",
"semi": false
"semi": true
}
57 changes: 28 additions & 29 deletions src/react-sortable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ export class ReactSortable<T extends ItemInterface> extends Component<
this.ref = createRef<HTMLElement>();

// make all state false because we can't change sortable unless a mouse gesture is made.
const newList = [...props.list];

newList.forEach((item: T) => {
const newList = [...props.list].map((item) =>
Object.assign(item, {
chosen: false,
selected: false,
});
})
})
);

props.setList(newList, this.sortable, store);
invariant(
Expand Down Expand Up @@ -120,8 +118,8 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const dataid = dataIdAttr || "data-id";
/* eslint-disable-next-line */
return Children.map(children as ReactElement<any>[], (child, index) => {
if (child === undefined) return undefined
if (child === undefined) return undefined;

const item = list[index] || {};
const { className: prevClassName } = child.props;

Expand Down Expand Up @@ -239,13 +237,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const customs = createCustoms(evt, otherList);
removeNodes(customs);

const newList = handleStateAdd(customs, list, evt, clone)

newList.forEach((item) => {
const newList = handleStateAdd(customs, list, evt, clone).map((item) =>
Object.assign(item, {
selected: false,
});
});
})
);

setList(newList, this.sortable, store);
}

Expand Down Expand Up @@ -296,11 +293,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
}

// remove item.selected from list
newList.forEach((item: T) => {
newList = newList.map((item: T) =>
Object.assign(item, {
selected: false,
});
})
})
);

setList(newList, this.sortable, store);
}

Expand All @@ -324,25 +322,27 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
onChoose(evt: SortableEvent): void {
const { list, setList } = this.props;
const newList = list.map((item, index) => {
let newItem = item;
if (index === evt.oldIndex) {
Object.assign(item, {
newItem = Object.assign(item, {
chosen: true,
});
}
return item;
return newItem;
});
setList(newList, this.sortable, store);
}

onUnchoose(evt: SortableEvent): void {
const { list, setList } = this.props;
const newList = list.map((item, index) => {
let newItem = item;
if (index === evt.oldIndex) {
Object.assign(item, {
newItem = Object.assign(newItem, {
chosen: false,
});
}
return item;
return newItem;
});
setList(newList, this.sortable, store);
}
Expand All @@ -354,12 +354,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onSelect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = [...list];
newList.forEach((item) => {
const newList = list.map((item) =>
Object.assign(item, {
chosen: false,
});
});
selected: false,
})
);

evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) {
Expand All @@ -376,12 +376,11 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onDeselect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = [...list];
newList.forEach((item) => {
const newList = list.map((item) =>
Object.assign(item, {
chosen: false,
});
});
selected: false,
})
);
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) return;
Expand Down

0 comments on commit c1f444d

Please sign in to comment.