diff --git a/editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-strategy.ts b/editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-strategy.ts index 98dec9e736a4..9d6b99516b3e 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-strategy.ts +++ b/editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-strategy.ts @@ -8,11 +8,7 @@ import type { GridContainerProperties, GridElementProperties, } from '../../../../core/shared/element-template' -import { - getJSXAttribute, - gridPositionValue, - isJSXElement, -} from '../../../../core/shared/element-template' +import { gridPositionValue, isJSXElement } from '../../../../core/shared/element-template' import { isInfinityRectangle } from '../../../../core/shared/math-utils' import { absolute } from '../../../../utils/utils' import type { CanvasCommand } from '../../commands/commands' @@ -241,9 +237,9 @@ export function runGridChangeElementLocation( const gridProps: Partial = { gridColumnStart: gridPositionValue(targetRootCell.column), - gridColumnEnd: gridPositionValue(targetRootCell.column + originalCellBounds.height), + gridColumnEnd: gridPositionValue(targetRootCell.column + originalCellBounds.width), gridRowStart: gridPositionValue(targetRootCell.row), - gridRowEnd: gridPositionValue(targetRootCell.row + originalCellBounds.width), + gridRowEnd: gridPositionValue(targetRootCell.row + originalCellBounds.height), } // TODO: Remove this logic once there is a fix for the handling of the track end fields. @@ -256,17 +252,30 @@ export function runGridChangeElementLocation( .compose(fromField('props')), selectedElementMetadata, (elementProperties) => { - const gridColumnEnd = getJSXAttributesAtPath( - elementProperties, - PP.create('style', 'gridColumnEnd'), - ) - if (gridColumnEnd.attribute.type === 'ATTRIBUTE_NOT_FOUND') { - keepGridColumnEnd = false - } - const gridRowEnd = getJSXAttributesAtPath(elementProperties, PP.create('style', 'gridRowEnd')) - if (gridRowEnd.attribute.type === 'ATTRIBUTE_NOT_FOUND') { - keepGridRowEnd = false + function shouldKeep(shorthandProp: 'gridColumn' | 'gridRow'): boolean { + const longhandProp = shorthandProp === 'gridColumn' ? 'gridColumnEnd' : 'gridRowEnd' + + const shorthand = getJSXAttributesAtPath( + elementProperties, + PP.create('style', shorthandProp), + ) + if ( + shorthand.attribute.type === 'ATTRIBUTE_VALUE' && + typeof shorthand.attribute.value === 'string' && + shorthand.attribute.value.includes('/') + ) { + return true + } + + const longhand = getJSXAttributesAtPath(elementProperties, PP.create('style', longhandProp)) + if (longhand.attribute.type !== 'ATTRIBUTE_NOT_FOUND') { + return true + } + + return false } + keepGridColumnEnd = shouldKeep('gridColumn') + keepGridRowEnd = shouldKeep('gridRow') }, ) diff --git a/editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx b/editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx index ed21826d1673..13fb04febe05 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx @@ -163,6 +163,29 @@ describe('grid element change location strategy', () => { }) }) + it('can change the location of a multicell element (shorthand)', async () => { + const editor = await renderTestEditorWithCode( + ProjectCodeReorderwithMultiCellChildShorthand, + 'await-first-dom-report', + ) + + const testId = 'orange' + const { gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd } = await runMoveTest(editor, { + scale: 1, + pathString: `sb/scene/grid/${testId}`, + testId: testId, + tab: true, + targetCell: { row: 3, column: 1 }, + }) + + expect({ gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd }).toEqual({ + gridColumnStart: '1', + gridColumnEnd: '3', + gridRowStart: '3', + gridRowEnd: 'auto', + }) + }) + it('can change the location of elements on a grid (zoom out)', async () => { const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report') @@ -1271,7 +1294,7 @@ export var storyboard = ( height: '100%', }} data-uid='pink' - data-testid='pink' + data-testid='pink' data-label='pink' />
@@ -1466,3 +1489,82 @@ export var storyboard = ( ) ` + +const ProjectCodeReorderwithMultiCellChildShorthand = `import * as React from 'react' +import { Scene, Storyboard } from 'utopia-api' + +export var storyboard = ( + + +
+
+
+
+
+
+ + +) +` diff --git a/editor/src/components/canvas/canvas-strategies/strategies/grid-helpers.ts b/editor/src/components/canvas/canvas-strategies/strategies/grid-helpers.ts index c889849c6d79..fbfef128c77e 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/grid-helpers.ts +++ b/editor/src/components/canvas/canvas-strategies/strategies/grid-helpers.ts @@ -154,10 +154,11 @@ function getGridChildCellCoordBoundsFromProps( } return propValue.numericalPosition ?? innerFallback } + const column = getGridProperty('gridColumnStart', fallback.column) - const height = getGridProperty('gridColumnEnd', fallback.column + (fallback.width ?? 1)) - column + const width = getGridProperty('gridColumnEnd', fallback.column + (fallback.width ?? 1)) - column const row = getGridProperty('gridRowStart', fallback.row) - const width = getGridProperty('gridRowEnd', fallback.row + (fallback.height ?? 1)) - row + const height = getGridProperty('gridRowEnd', fallback.row + (fallback.height ?? 1)) - row return { row,