Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid cleanup #6039

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
track target root cell
ruggi committed Jul 4, 2024
commit 3b0bed8e44aecfd896d8afc32b1cf198e73c4174
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ export interface CustomStrategyState {
export type GridCustomStrategyState = {
targetCell: GridCellCoordinates | null
draggingFromCell: GridCellCoordinates | null
rootCell: GridCellCoordinates | null
originalRootCell: GridCellCoordinates | null
currentRootCell: GridCellCoordinates | null
}

export type CustomStrategyStatePatch = Partial<CustomStrategyState>
@@ -43,7 +44,8 @@ export function defaultCustomStrategyState(): CustomStrategyState {
grid: {
targetCell: null,
draggingFromCell: null,
rootCell: null,
originalRootCell: null,
currentRootCell: null,
},
}
}
Original file line number Diff line number Diff line change
@@ -85,14 +85,16 @@ export function runGridRearrangeMove(
commands: CanvasCommand[]
targetCell: GridCellCoordinates | null
draggingFromCell: GridCellCoordinates | null
rootCell: GridCellCoordinates | null
originalRootCell: GridCellCoordinates | null
targetRootCell: GridCellCoordinates | null
} {
if (interactionData.drag == null) {
return {
commands: [],
targetCell: null,
rootCell: null,
originalRootCell: null,
draggingFromCell: null,
targetRootCell: null,
}
}

@@ -108,7 +110,8 @@ export function runGridRearrangeMove(
commands: [],
targetCell: null,
draggingFromCell: null,
rootCell: null,
originalRootCell: null,
targetRootCell: null,
}
}

@@ -120,8 +123,9 @@ export function runGridRearrangeMove(
return {
commands: [],
targetCell: null,
rootCell: null,
originalRootCell: null,
draggingFromCell: null,
targetRootCell: null,
}
}

@@ -131,14 +135,16 @@ export function runGridRearrangeMove(
// cell of the element, meaning the top-left-most cell the element occupies.
const draggingFromCell = customState.draggingFromCell ?? newTargetCell
const rootCell =
customState.rootCell ?? gridCellCoordinates(gridProperties.row, gridProperties.column)
customState.originalRootCell ?? gridCellCoordinates(gridProperties.row, gridProperties.column)
const coordsDiff = getCellCoordsDelta(draggingFromCell, rootCell)

// get the new adjusted row
const row = getCoordBounds(newTargetCell, 'row', gridProperties.width, coordsDiff.row)
// get the new adjusted column
const column = getCoordBounds(newTargetCell, 'column', gridProperties.height, coordsDiff.column)

const targetRootCell = gridCellCoordinates(row.start, column.start)

return {
commands: [
setProperty('always', targetElement, create('style', 'gridColumnStart'), column.start),
@@ -147,8 +153,9 @@ export function runGridRearrangeMove(
setProperty('always', targetElement, create('style', 'gridRowEnd'), row.end),
],
targetCell: newTargetCell,
rootCell: rootCell,
originalRootCell: rootCell,
draggingFromCell: draggingFromCell,
targetRootCell: targetRootCell,
}
}

Original file line number Diff line number Diff line change
@@ -89,7 +89,8 @@ export const gridRearrangeMoveDuplicateStrategy: CanvasStrategyFactory = (
commands: moveCommands,
targetCell: targetGridCell,
draggingFromCell,
rootCell,
originalRootCell,
targetRootCell,
} = runGridRearrangeMove(
targetElement,
selectedElement,
@@ -117,7 +118,8 @@ export const gridRearrangeMoveDuplicateStrategy: CanvasStrategyFactory = (
grid: {
targetCell: targetGridCell,
draggingFromCell: draggingFromCell,
rootCell: rootCell,
originalRootCell: originalRootCell,
currentRootCell: targetRootCell,
},
duplicatedElementNewUids: duplicatedElementNewUids,
},
Original file line number Diff line number Diff line change
@@ -73,7 +73,8 @@ export const gridRearrangeMoveStrategy: CanvasStrategyFactory = (
commands: moveCommands,
targetCell: targetGridCell,
draggingFromCell,
rootCell,
originalRootCell,
targetRootCell,
} = runGridRearrangeMove(
targetElement,
selectedElement,
@@ -92,7 +93,8 @@ export const gridRearrangeMoveStrategy: CanvasStrategyFactory = (
grid: {
targetCell: targetGridCell,
draggingFromCell: draggingFromCell,
rootCell: rootCell,
originalRootCell: originalRootCell,
currentRootCell: targetRootCell,
},
})
},