diff --git a/.gitignore b/.gitignore index f70e855..c906835 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ temp dist # todo - get story book only when releasing. storybook-static -yarn.lock \ No newline at end of file +yarn.lock +package-lock.json \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index cc46cb8..934d362 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,4 @@ { "arrowParens": "always", - "semi": false + "semi": true } diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fc23cf..80ee3f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [6.1.1](https://github.com/SortableJS/react-sortablejs/compare/v6.1.0...v6.1.1) (2022-02-08) + + +### Bug Fixes + +* object-assign errors ([fde561e](https://github.com/SortableJS/react-sortablejs/commit/fde561e0b730dc7f7a664a48277b117e841c613a)) + + +### Reverts + +* prettier preserve semicolons ([a658d04](https://github.com/SortableJS/react-sortablejs/commit/a658d04e53e48f05ebdcbb3a137283899f277a78)) + # [6.1.0](https://github.com/SortableJS/react-sortablejs/compare/v6.0.4...v6.1.0) (2022-01-30) diff --git a/package.json b/package.json index 8c70df1..5ab8526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-sortablejs", - "version": "6.1.0", + "version": "6.1.1", "author": { "name": "Wayne Van Son", "email": "waynevanson@gmail.com" diff --git a/src/react-sortable.tsx b/src/react-sortable.tsx index 9d1e033..1a63522 100644 --- a/src/react-sortable.tsx +++ b/src/react-sortable.tsx @@ -49,14 +49,12 @@ export class ReactSortable extends Component< this.ref = createRef(); // 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( @@ -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[], (child, index) => { - if (child === undefined) return undefined - + if (child === undefined) return undefined; + const item = list[index] || {}; const { className: prevClassName } = child.props; @@ -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); } @@ -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); } @@ -324,12 +322,13 @@ 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); } @@ -337,12 +336,13 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl 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); } @@ -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) { @@ -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;