Skip to content

Commit

Permalink
Rename grid cell to grid item (#6623)
Browse files Browse the repository at this point in the history
**Problem:**
Sometimes we call the grid items "grid cells", which is incorrect (grid
cells are the positions in the grid, and not the child items).

**Fix:**
Rename

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Play mode
  • Loading branch information
gbalint authored Nov 7, 2024
1 parent 2c8aee3 commit 3148367
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function absoluteResizeBoundingBoxStrategy(
}

if (
retargetedTargets.some((path) => MetadataUtils.isGridCell(canvasState.startingMetadata, path))
retargetedTargets.some((path) => MetadataUtils.isGridItem(canvasState.startingMetadata, path))
) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function basicResizeStrategy(
const elementDimensionsProps = metadata != null ? getElementDimensions(metadata) : null
const elementParentBounds = metadata?.specialSizeMeasurements.immediateParentBounds ?? null

const isGridCell = MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)
const isGridCell = MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)
if (isGridCell && isFillOrStretchModeApplied(canvasState.startingMetadata, selectedElement)) {
return null
}
Expand Down Expand Up @@ -216,7 +216,7 @@ export function basicResizeStrategy(
)

const gridsToRerender = selectedElements
.filter((element) => MetadataUtils.isGridCell(canvasState.startingMetadata, element))
.filter((element) => MetadataUtils.isGridItem(canvasState.startingMetadata, element))
.map(EP.parentPath)

const elementsToRerender = [...selectedElements, ...gridsToRerender]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function convertToAbsoluteAndMoveStrategyFactory(setHuggingParentToFixed: SetHug
originalTargets,
).filter(
// don't show the siblings control for grid cells
(sibling) => !MetadataUtils.isGridCell(canvasState.startingMetadata, sibling.elementPath),
(sibling) => !MetadataUtils.isGridItem(canvasState.startingMetadata, sibling.elementPath),
)

const showSiblingsControl = autoLayoutSiblingsExceptGridCells.length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function flexResizeBasicStrategy(
elementParentBounds != null &&
(elementParentBounds.width !== 0 || elementParentBounds.height !== 0)

if (MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElements[0])) {
if (MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElements[0])) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function flexResizeStrategy(
elementParentBounds.width !== 0 &&
elementParentBounds.height !== 0

if (MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElements[0])) {
if (MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElements[0])) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const gridMoveAbsoluteStrategy: CanvasStrategyFactory = (
}

const selectedElement = selectedElements[0]
if (!MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)) {
if (!MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)) {
return null
}

Expand Down Expand Up @@ -215,7 +215,7 @@ function runGridMoveAbsolute(

// if moving an absolutely-positioned child which does not have pinning
// props, do not set them at all.
if (MetadataUtils.hasNoGridCellPositioning(selectedElementMetadata.specialSizeMeasurements)) {
if (MetadataUtils.hasNoGridItemPositioning(selectedElementMetadata.specialSizeMeasurements)) {
return [
showGridControls('mid-interaction', gridPath, targetCellCoords, targetRootCell),
...gridChildAbsoluteMoveCommands(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const gridMoveRearrangeDuplicateStrategy: CanvasStrategyFactory = (
}

const selectedElement = selectedElements[0]
if (!MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)) {
if (!MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
}

const selectedElement = selectedElements[0]
if (!MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)) {
if (!MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const gridMoveReorderStrategy: CanvasStrategyFactory = (
}

const selectedElement = selectedElements[0]
if (!MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)) {
if (!MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function gridRearrangeResizeKeyboardStrategy(

const target = selectedElements[0]

if (!MetadataUtils.isGridCell(canvasState.startingMetadata, target)) {
if (!MetadataUtils.isGridItem(canvasState.startingMetadata, target)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const gridResizeElementStrategy: CanvasStrategyFactory = (
if (selectedElementMetadata == null) {
return null
}
const isElementInsideGrid = MetadataUtils.isGridCell(
const isElementInsideGrid = MetadataUtils.isGridItem(
canvasState.startingMetadata,
selectedElement,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function keyboardAbsoluteResizeStrategy(
return null
}

if (MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElements[0])) {
if (MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElements[0])) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,13 @@ function pasteIntoNextGridCell(
// if the copied elements are grid cells and the target is a grid cell, paste next to it

const copyDataElementsAreGridCells = copyData.elementPaste.every(({ originalElementPath }) =>
MetadataUtils.isGridCell(copyData.originalContextMetadata, originalElementPath),
MetadataUtils.isGridItem(copyData.originalContextMetadata, originalElementPath),
)
if (!copyDataElementsAreGridCells) {
return null
}

const targetIsGridChild = MetadataUtils.isGridCell(metadata, selectedView)
const targetIsGridChild = MetadataUtils.isGridItem(metadata, selectedView)
if (!targetIsGridChild) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const resizeGridStrategy: CanvasStrategyFactory = (
'some',
)

const isGridCell = MetadataUtils.isGridCell(canvasState.startingMetadata, selectedElement)
const isGridCell = MetadataUtils.isGridItem(canvasState.startingMetadata, selectedElement)
const isGrid = MetadataUtils.isGridLayoutedContainer(
MetadataUtils.findElementByElementPath(canvasState.startingMetadata, selectedElement),
)
Expand Down
2 changes: 1 addition & 1 deletion editor/src/components/canvas/controls/grid-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ const GridControl = React.memo<GridControlProps>(({ grid, controlsVisible }) =>
Substores.metadata,
(store) =>
store.editor.selectedViews.every((elementPath) =>
MetadataUtils.isGridCellWithPositioning(store.editor.jsxMetadata, elementPath),
MetadataUtils.isGridItemWithPositioning(store.editor.jsxMetadata, elementPath),
),
'GridControl targetsAreCellsWithPositioning',
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const AbsoluteResizeControl = controlForStrategyMemoized(
let diagonally = true

for (const element of selectedElementsRef.current) {
if (MetadataUtils.isGridCell(metadata, element)) {
if (MetadataUtils.isGridItem(metadata, element)) {
if (isFillOrStretchModeAppliedOnAnySide(metadata, element)) {
diagonally = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ function useSelectOrLiveModeSelectAndHover(
foundTarget != null &&
draggingAllowed &&
// grid has its own drag handling
!MetadataUtils.isGridCell(
!MetadataUtils.isGridItem(
editorStoreRef.current.editor.jsxMetadata,
foundTarget.elementPath,
)
Expand Down
4 changes: 2 additions & 2 deletions editor/src/components/inspector/inspector-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ export function detectFillHugFixedState(
getSimpleAttributeAtPath(right(element.element.value.props), PP.create('style', 'height')),
)

if (MetadataUtils.isGridCell(metadata, elementPath)) {
if (MetadataUtils.isGridItem(metadata, elementPath)) {
const isStretchingExplicitly =
(element.specialSizeMeasurements.alignSelf === 'stretch' &&
axis === 'horizontal' &&
Expand Down Expand Up @@ -1205,7 +1205,7 @@ export function getFixedFillHugOptionsForElement(
? 'hug'
: null,
fillContainerApplicable(metadata, selectedView)
? MetadataUtils.isGridCell(metadata, selectedView)
? MetadataUtils.isGridItem(metadata, selectedView)
? 'stretch'
: 'fill'
: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const fillContainerStrategyGridParent = (
name: 'Set to Fill Container, in grid layout',
strategy: () => {
const elements = elementPaths.filter(
(path) => fillContainerApplicable(metadata, path) && MetadataUtils.isGridCell(metadata, path),
(path) => fillContainerApplicable(metadata, path) && MetadataUtils.isGridItem(metadata, path),
)

if (elements.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const SimplifiedLayoutSubsection = React.memo(() => {
Substores.metadata,
(store) =>
store.editor.selectedViews.length === 1 &&
MetadataUtils.isGridCell(store.editor.jsxMetadata, store.editor.selectedViews[0]),
MetadataUtils.isGridItem(store.editor.jsxMetadata, store.editor.selectedViews[0]),
'Inspector shouldShowGridCellSection',
)

Expand Down
12 changes: 6 additions & 6 deletions editor/src/core/model/element-metadata-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,19 @@ export const MetadataUtils = {
isGridLayoutedContainer(instance: ElementInstanceMetadata | null): boolean {
return instance?.specialSizeMeasurements.layoutSystemForChildren === 'grid'
},
isGridCell(metadata: ElementInstanceMetadataMap, path: ElementPath): boolean {
isGridItem(metadata: ElementInstanceMetadataMap, path: ElementPath): boolean {
const elementMetadata = MetadataUtils.findElementByElementPath(metadata, path)
return elementMetadata?.specialSizeMeasurements.parentLayoutSystem === 'grid'
},
isGridCellWithPositioning(metadata: ElementInstanceMetadataMap, path: ElementPath): boolean {
isGridItemWithPositioning(metadata: ElementInstanceMetadataMap, path: ElementPath): boolean {
const element = MetadataUtils.findElementByElementPath(metadata, path)
return (
MetadataUtils.isGridCell(metadata, path) &&
MetadataUtils.isGridItem(metadata, path) &&
element != null &&
!MetadataUtils.hasNoGridCellPositioning(element.specialSizeMeasurements)
!MetadataUtils.hasNoGridItemPositioning(element.specialSizeMeasurements)
)
},
hasNoGridCellPositioning(specialSizeMeasurements: SpecialSizeMeasurements): boolean {
hasNoGridItemPositioning(specialSizeMeasurements: SpecialSizeMeasurements): boolean {
return (
specialSizeMeasurements.elementGridPropertiesFromProps.gridColumnStart == null &&
specialSizeMeasurements.elementGridPropertiesFromProps.gridColumnEnd == null &&
Expand Down Expand Up @@ -632,7 +632,7 @@ export const MetadataUtils = {
return (
MetadataUtils.isFlexLayoutedContainer(
MetadataUtils.findElementByElementPath(jsxMetadata, EP.parentPath(path)),
) || MetadataUtils.isGridCell(jsxMetadata, path)
) || MetadataUtils.isGridItem(jsxMetadata, path)
)
},
getRelativeAlignJustify: function (
Expand Down

0 comments on commit 3148367

Please sign in to comment.