diff --git a/dist/util.d.ts b/dist/util.d.ts deleted file mode 100644 index 32deba2..0000000 --- a/dist/util.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { PropsWithChildren } from "react"; -import { Options } from "sortablejs"; -import { MultiDragEvent } from "./react-sortable"; -import { AllMethodNames, ItemInterface, ReactSortableProps } from "./types"; -/** - * Removes the `node` from the DOM - * @param node - */ -export declare function removeNode(node: HTMLElement): void; -/** - * Inserts the `newChild` node at the given index in a parent - * @param parent The parent HTML Element. - * @param newChild A HTML eement to add as a child of the parent. - * @param index index of the parent to place the new child in. - */ -export declare function insertNodeAt(parent: HTMLElement, newChild: HTMLElement, index: number): void; -/** removes stuff from the dom in a nice order */ -export declare function handleDOMChanges(customs: Normalized[]): void; -export declare function removeNodes(customs: Normalized[]): void; -export declare function insertNodes(customs: Normalized[]): void; -export declare function createCustoms(evt: MultiDragEvent, list: T[]): Normalized[]; -/** moves items form old index to new index without breaking anything ideally. */ -export declare function handleStateChanges(normalized: Normalized[], list: T[]): T[]; -export declare function handleStateRemove(normalized: Normalized[], list: T[]): T[]; -export declare function handleStateAdd(normalized: Normalized[], list: T[]): T[]; -export declare function getMode(evt: MultiDragEvent): "multidrag" | "swap" | "normal"; -export declare function createNormalized(inputs: Input[], list: T[]): Normalized[]; -export interface Input { - parentElement: HTMLElement; - element: HTMLElement; - oldIndex: number; - newIndex: number; -} -export interface Normalized extends Input { - item: T; -} -/** - * Removes the following group of properties from `props`, - * leaving only `Sortable.Options` without any `on` methods. - * @param props `ReactSortable.Props` - */ -export declare function destructurePropsForOptions(props: PropsWithChildren>): Exclude; -/** - * Construct a type with the properties of T except for those in type K. - * Including this allows for backwards compatibility with earlier versions of TS. - */ -export declare type Omit = Pick>; -//# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/examples/components/disable-sorting.tsx b/examples/components/disable-sorting.tsx deleted file mode 100644 index 21459f4..0000000 --- a/examples/components/disable-sorting.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React, { useState } from "react"; -import styled from "styled-components"; -import { ReactSortable } from "../../src/index"; -import { Item, threes, createId } from "../util"; - -export function DisableSorting() { - const [list1, setList1] = useState(threes); - const [list2, setList2] = useState(threes); - return ( - - ({ ...item, id: createId() })} - sort={false} - > - {list1.map(item => ( - {item.name} - ))} - - - {list2.map(item => ( - {item.name} - ))} - - - ); -} - -/** Wraps internal components for styling. */ -const Container = styled.div` - display: flex; - width: inherit; - & > * { - width: 100%; - margin-left: 0.3rem; - :first-child() { - margin-left: 0rem; - } - } -`; diff --git a/src/react-sortable.tsx b/src/react-sortable.tsx index 65b2869..ed74c96 100644 --- a/src/react-sortable.tsx +++ b/src/react-sortable.tsx @@ -216,11 +216,11 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl // SORTABLE DOM HANDLING onAdd(evt: MultiDragEvent) { - const { list, setList } = this.props; + const { list, setList, clone } = this.props; const otherList = [...store.dragging!.props.list]; const customs = createCustoms(evt, otherList); removeNodes(customs); - const newList = handleStateAdd(customs, list); + const newList = handleStateAdd(customs, list, evt, clone).map(item => ({ ...item, selected: false })); setList(newList, this.sortable, store); } diff --git a/src/util.ts b/src/util.ts index 27c2488..e459f6c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ import { PropsWithChildren } from "react"; -import { Options } from "sortablejs"; +import Sortable, { Options } from "sortablejs"; import { MultiDragEvent } from "./react-sortable"; import { AllMethodNames, ItemInterface, ReactSortableProps } from "./types"; @@ -116,10 +116,15 @@ export function handleStateRemove( export function handleStateAdd( normalized: Normalized[], - list: T[] + list: T[], + evt?: Sortable.SortableEvent, + clone?: ((currentItem: T, evt: Sortable.SortableEvent) => T) | undefined ): T[] { const newList = [...list]; - normalized.forEach(curr => newList.splice(curr.newIndex, 0, curr.item)); + normalized.forEach(curr => { + const newItem = (clone && evt) && clone(curr.item, evt); + newList.splice(curr.newIndex, 0, newItem || curr.item) + }); return newList; }