* chore: add dev container * feat: add drag handle when hovering cell * feat: add column drag and drop * feat: add support for row drag and drop * refactor: extract preview controllers * fix: hover issue * refactor: add handle controller * chore: f * chore: remove log * chore: remove dev files * feat: hide other drop indicators when table dnd working * feat: add auto scroll and bug fix * chore: f * fix: firefox
30 lines
853 B
TypeScript
30 lines
853 B
TypeScript
/**
|
|
* Move a row in an array of rows.
|
|
*
|
|
* @internal
|
|
*/
|
|
export function moveRowInArrayOfRows<T>(
|
|
rows: T[],
|
|
indexesOrigin: number[],
|
|
indexesTarget: number[],
|
|
directionOverride: -1 | 1 | 0,
|
|
): T[] {
|
|
const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1
|
|
|
|
const rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length)
|
|
const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0
|
|
let target: number
|
|
|
|
if (directionOverride === -1 && direction === 1) {
|
|
target = indexesTarget[0] - 1
|
|
} else if (directionOverride === 1 && direction === -1) {
|
|
target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1
|
|
} else {
|
|
target = direction === -1
|
|
? indexesTarget[0]
|
|
: indexesTarget[indexesTarget.length - 1] - positionOffset
|
|
}
|
|
|
|
rows.splice(target, 0, ...rowsExtracted)
|
|
return rows
|
|
}
|