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

Only show grid lines when selecting grid or during child interaction #6647

Merged
merged 11 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import * as EP from '../../../../core/shared/element-path'
import {
getRectCenter,
localRectangle,
offsetPoint,
windowPoint,
} from '../../../../core/shared/math-utils'
import { offsetPoint, windowPoint } from '../../../../core/shared/math-utils'
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
import CanvasActions from '../../canvas-actions'
import { GridCellTestId } from '../../controls/grid-controls-for-strategies'
import { mouseDownAtPoint, mouseMoveToPoint, mouseUpAtPoint } from '../../event-helpers.test-utils'
import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
import { gridCellTargetId } from './grid-cell-bounds'
import { runGridMoveTest } from './grid.test-utils'

describe('grid element change location strategy', () => {
Expand All @@ -22,7 +16,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand Down Expand Up @@ -52,7 +46,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -79,7 +73,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
(ed) => {
Expand Down Expand Up @@ -109,7 +103,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid/',
testId: testId,
},
)
Expand All @@ -131,7 +125,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
targetCell: { row: 2, column: 1 },
draggedCell: { row: 2, column: 2 },
Expand All @@ -153,7 +147,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
tab: true,
},
Expand All @@ -178,7 +172,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
targetCell: { row: 3, column: 1 },
},
Expand All @@ -200,7 +194,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 0.5,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -220,7 +214,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 2,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -243,7 +237,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -267,7 +261,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -291,7 +285,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
targetCell: { row: 3, column: 2 },
},
Expand All @@ -316,7 +310,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -340,7 +334,7 @@ describe('grid element change location strategy', () => {
editor,
{
scale: 1,
pathString: `sb/scene/grid/${testId}`,
gridPath: 'sb/scene/grid',
testId: testId,
},
)
Expand All @@ -366,8 +360,6 @@ export var storyboard = (
data-testid='grid'
style={{
position: 'absolute',
left: -94,
top: 698,
display: 'grid',
gap: 10,
width: 600,
Expand Down Expand Up @@ -428,33 +420,11 @@ export var storyboard = (
)

const testId = 'grid-inside-grid'
const elementPathToDrag = EP.fromString(`sb/grid/${testId}`)

await selectComponentsForTest(editor, [elementPathToDrag])

const sourceGridCell = editor.renderedDOM.getByTestId(GridCellTestId(elementPathToDrag))
const targetGridCell = editor.renderedDOM.getByTestId(
gridCellTargetId(EP.fromString('sb/grid'), 2, 3),
)

const sourceRect = sourceGridCell.getBoundingClientRect()
const targetRect = targetGridCell.getBoundingClientRect()

const dragFrom = {
x: sourceRect.x + 10,
y: sourceRect.y + 10,
}
const dragTo = getRectCenter(
localRectangle({
x: targetRect.x,
y: targetRect.y,
width: targetRect.width,
height: targetRect.height,
}),
)
await mouseDownAtPoint(sourceGridCell, dragFrom)
await mouseMoveToPoint(sourceGridCell, dragTo)
await mouseUpAtPoint(sourceGridCell, dragTo)
await runGridMoveTest(editor, {
scale: 1,
gridPath: 'sb/grid',
testId: testId,
})

const { gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd } =
editor.renderedDOM.getByTestId(testId).style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
import type { GridCellCoordinates } from './grid-cell-bounds'
import { runGridMoveTest } from './grid.test-utils'
import * as EP from '../../../../core/shared/element-path'
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'

describe('grid reorder', () => {
it('reorders an element without setting positioning (inside contiguous area)', async () => {
Expand Down Expand Up @@ -111,6 +112,8 @@ describe('grid reorder', () => {

expect(first.cells).toEqual(['pink', 'cyan', 'blue', 'orange'])

await selectComponentsForTest(editor, [])

const second = await runReorderTest(
editor,
'sb/scene/grid',
Expand Down Expand Up @@ -242,7 +245,7 @@ describe('grid reorder', () => {

async function runReorderTest(
editor: EditorRenderResult,
gridTestId: string,
gridPath: string,
testId: string,
targetCell: GridCellCoordinates,
options?: { tab?: boolean },
Expand All @@ -251,22 +254,22 @@ async function runReorderTest(
editor,
{
scale: 1,
pathString: `${gridTestId}/${testId}`,
gridPath: gridPath,
testId: testId,
targetCell: targetCell,
tab: options?.tab,
},
)

const element = editor.getEditorState().editor.jsxMetadata[gridTestId]
if (isLeft(element.element) || !isJSXElement(element.element.value)) {
const grid = editor.getEditorState().editor.jsxMetadata[gridPath]
if (isLeft(grid.element) || !isJSXElement(grid.element.value)) {
throw new Error('expected jsx element')
}

const cells = MetadataUtils.getChildrenOrdered(
editor.getEditorState().editor.jsxMetadata,
editor.getEditorState().editor.elementPathTree,
element.elementPath,
EP.fromString(gridPath),
)

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
offsetPoint,
} from '../../../../core/shared/math-utils'
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
import { mouseDragFromPointToPoint } from '../../event-helpers.test-utils'
import { mouseDownAtPoint, mouseDragFromPointToPoint } from '../../event-helpers.test-utils'
import type { EditorRenderResult } from '../../ui-jsx.test-utils'
import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
import type { GridResizeEdge } from '../interaction-state'
Expand All @@ -34,6 +34,9 @@ async function runCellResizeTest(
const resizeControl = editor.renderedDOM.getByTestId(
ResizePointTestId(gridEdgeToEdgePosition(edge)),
)

const resizeControlBox = resizeControl.getBoundingClientRect()
await mouseDownAtPoint(resizeControl, { x: resizeControlBox.x + 5, y: resizeControlBox.y + 5 })
const targetGridCell = editor.renderedDOM.getByTestId(dragToCellTestId)

await mouseDragFromPointToPoint(
Expand Down
Loading
Loading