@@ -753,18 +753,31 @@ export class GridUtils {
753753 * @param from The visible index to move from
754754 * @param to The visible index to move the item to
755755 * @param oldMovedItems The old reordered items
756- * @returns The new reordered items
756+ * @returns The new reordered items. The original array if the operation is a no-op.
757757 */
758+ static moveItem (
759+ from : VisibleIndex ,
760+ to : VisibleIndex ,
761+ oldMovedItems : MoveOperation [ ]
762+ ) : MoveOperation [ ] ;
763+
758764 static moveItem (
759765 from : VisibleIndex ,
760766 to : VisibleIndex ,
761767 oldMovedItems : readonly MoveOperation [ ]
762- ) : MoveOperation [ ] {
768+ ) : readonly MoveOperation [ ] ;
769+
770+ // The overloads are so we can return the original array if the operation is a no-op
771+ static moveItem (
772+ from : VisibleIndex ,
773+ to : VisibleIndex ,
774+ oldMovedItems : MoveOperation [ ] | readonly MoveOperation [ ]
775+ ) : MoveOperation [ ] | readonly MoveOperation [ ] {
763776 if ( from === to ) {
764- return [ ... oldMovedItems ] ;
777+ return oldMovedItems ;
765778 }
766779
767- const movedItems : MoveOperation [ ] = [ ...oldMovedItems ] ;
780+ const movedItems = [ ...oldMovedItems ] ;
768781 const lastMovedItem = movedItems [ movedItems . length - 1 ] ;
769782
770783 // Check if we should combine with the previous move
@@ -806,14 +819,29 @@ export class GridUtils {
806819 * E.g. Move range [0, 2] 1 item down (after element 3)
807820 * The move is [0, 2] -> 1 if this is false. [0, 2] -> 3 if this is true
808821 * Both will result in [0, 2] -> 1
809- * @returns The new reordered items
822+ * @returns The new reordered items. The original array if the operation is a no-op.
810823 */
824+ static moveRange (
825+ from : BoundedAxisRange ,
826+ to : VisibleIndex ,
827+ oldMovedItems : MoveOperation [ ] ,
828+ isPreMoveTo ?: boolean
829+ ) : MoveOperation [ ] ;
830+
811831 static moveRange (
812832 from : BoundedAxisRange ,
813833 toParam : VisibleIndex ,
814834 oldMovedItems : readonly MoveOperation [ ] ,
835+ isPreMoveTo ?: boolean
836+ ) : readonly MoveOperation [ ] ;
837+
838+ // The overloads are so we can return the original array if the operation is a no-op
839+ static moveRange (
840+ from : BoundedAxisRange ,
841+ toParam : VisibleIndex ,
842+ oldMovedItems : MoveOperation [ ] | readonly MoveOperation [ ] ,
815843 isPreMoveTo = false
816- ) : MoveOperation [ ] {
844+ ) : MoveOperation [ ] | readonly MoveOperation [ ] {
817845 if ( from [ 0 ] === from [ 1 ] ) {
818846 return GridUtils . moveItem ( from [ 0 ] , toParam , oldMovedItems ) ;
819847 }
@@ -825,7 +853,7 @@ export class GridUtils {
825853 }
826854
827855 if ( from [ 0 ] === to ) {
828- return [ ... oldMovedItems ] ;
856+ return oldMovedItems ;
829857 }
830858
831859 const movedItems : MoveOperation [ ] = [ ...oldMovedItems ] ;
@@ -863,8 +891,23 @@ export class GridUtils {
863891 from : VisibleIndex | BoundedAxisRange ,
864892 to : VisibleIndex ,
865893 oldMovedItems : MoveOperation [ ] ,
894+ isPreMoveTo ?: boolean
895+ ) : MoveOperation [ ] ;
896+
897+ static moveItemOrRange (
898+ from : VisibleIndex | BoundedAxisRange ,
899+ to : VisibleIndex ,
900+ oldMovedItems : readonly MoveOperation [ ] ,
901+ isPreMoveTo ?: boolean
902+ ) : readonly MoveOperation [ ] ;
903+
904+ // The overloads are so we can return the original array if the operation is a no-op
905+ static moveItemOrRange (
906+ from : VisibleIndex | BoundedAxisRange ,
907+ to : VisibleIndex ,
908+ oldMovedItems : MoveOperation [ ] | readonly MoveOperation [ ] ,
866909 isPreMoveTo = false
867- ) : MoveOperation [ ] {
910+ ) : MoveOperation [ ] | readonly MoveOperation [ ] {
868911 return Array . isArray ( from )
869912 ? GridUtils . moveRange ( from , to , oldMovedItems , isPreMoveTo )
870913 : GridUtils . moveItem ( from , to , oldMovedItems ) ;
0 commit comments