import { BuilderGroupedChildNode } from "../interfaces" ; export interface SortedIdsAfterDropped { nodeUids : number [ ] ; nodeIds : string [ ] ; } export interface DroppingInfo { draggingNodeUid : number | number [ ] ; draggingNodeId : string | null ; draggingIndex ? : number ; droppingMountPoint : string ; droppingSiblingGroups : BuilderGroupedChildNode [ ] ; droppingIndex : number ; } remark param droppingInfo returns export function getSortedIdsAfterDropped ( droppingInfo ) { const { draggingNodeUid , draggingNodeId , draggingIndex , droppingMountPoint , droppingSiblingGroups , droppingIndex , } = droppingInfo ; const draggingNodeUids = Array . isArray ( draggingNodeUid ) ? draggingNodeUid : [ draggingNodeUid ] ; const fullChildNodes = droppingSiblingGroups . flatMap ( ( group ) => group . childNodes ) ; const nodeUids = droppingSiblingGroups . flatMap ( ( group ) => { const uids = group . childNodes . map ( ( item ) => item . $$uid ) . filter ( ( uid ) => ! draggingNodeUids . includes ( uid ) ) ; if ( group . mountPoint === droppingMountPoint ) { uids . splice ( ( draggingIndex ?? - 1 ) >= 0 && droppingIndex > draggingIndex ? droppingIndex - 1 : droppingIndex , 0 , ... draggingNodeUids ) ; } return uids ; } ) ; const nodeIds = nodeUids . map ( ( uid ) => draggingNodeUids . includes ( uid ) ? draggingNodeId : fullChildNodes . find ( ( item ) => item . $$uid === uid ) . id ) ; return { nodeUids , nodeIds } ; }