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

Resize a Grid Element #6038

Merged
merged 22 commits into from
Jul 10, 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
Expand Up @@ -66,6 +66,7 @@ import { MetadataUtils } from '../../../core/model/element-metadata-utils'
import { gridRearrangeMoveStrategy } from './strategies/grid-rearrange-move-strategy'
import { resizeGridStrategy } from './strategies/resize-grid-strategy'
import { rearrangeGridSwapStrategy } from './strategies/rearrange-grid-swap-strategy'
import { gridResizeElementStrategy } from './strategies/grid-resize-element-strategy'
import { gridRearrangeMoveDuplicateStrategy } from './strategies/grid-rearrange-move-duplicate-strategy'

export type CanvasStrategyFactory = (
Expand Down Expand Up @@ -115,6 +116,7 @@ const resizeStrategies: MetaCanvasStrategy = (
flexResizeStrategy,
basicResizeStrategy,
resizeGridStrategy,
gridResizeElementStrategy,
],
)
}
bkrmendy marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -521,7 +523,7 @@ export function isResizableStrategy(canvasStrategy: CanvasStrategy): boolean {
case 'FLEX_RESIZE_BASIC':
case 'FLEX_RESIZE':
case 'BASIC_RESIZE':
// TODO add grid cell resize
case 'GRID-CELL-RESIZE-STRATEGY':
return true
default:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,23 @@ export function gridCellHandle(params: { id: string }): GridCellHandle {
}
}

export const GridResizeEdges = ['row-start', 'row-end', 'column-start', 'column-end'] as const
export type GridResizeEdge = (typeof GridResizeEdges)[number]

export interface GridResizeHandle {
type: 'GRID_RESIZE_HANDLE'
id: string
edge: GridResizeEdge
}

export function gridResizeHandle(id: string, edge: GridResizeEdge): GridResizeHandle {
return {
type: 'GRID_RESIZE_HANDLE',
id: id,
edge: edge,
}
}

export type CanvasControlType =
| BoundingArea
| ResizeHandle
Expand All @@ -638,6 +655,7 @@ export type CanvasControlType =
| BorderRadiusResizeHandle
| GridCellHandle
| GridAxisHandle
| GridResizeHandle

export function isDragToPan(
interaction: InteractionSession | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ElementInstanceMetadata,
ElementInstanceMetadataMap,
GridElementProperties,
GridPosition,
} from '../../../../core/shared/element-template'
import type { CanvasVector } from '../../../../core/shared/math-utils'
import {
Expand All @@ -12,15 +13,18 @@ import {
windowRectangle,
type WindowPoint,
} from '../../../../core/shared/math-utils'
import { create } from '../../../../core/shared/property-path'
import * as PP from '../../../../core/shared/property-path'
import type { CanvasCommand } from '../../commands/commands'
import { setProperty } from '../../commands/set-property-command'
import { canvasPointToWindowPoint } from '../../dom-lookup'
import type { DragInteractionData } from '../interaction-state'
import { stripNulls } from '../../../../core/shared/array-utils'
import { optionalMap } from '../../../../core/shared/optional-utils'
import type { GridCustomStrategyState } from '../canvas-strategy-types'
import type { GridCellCoordinates } from '../../controls/grid-controls'
import { gridCellCoordinates } from '../../controls/grid-controls'
import * as EP from '../../../../core/shared/element-path'
import { deleteProperties } from '../../commands/delete-properties-command'

export function getGridCellUnderMouse(mousePoint: WindowPoint) {
return getGridCellAtPoint(mousePoint, false)
Expand Down Expand Up @@ -162,10 +166,10 @@ export function runGridRearrangeMove(

return {
commands: [
setProperty('always', targetElement, create('style', 'gridColumnStart'), column.start),
setProperty('always', targetElement, create('style', 'gridColumnEnd'), column.end),
setProperty('always', targetElement, create('style', 'gridRowStart'), row.start),
setProperty('always', targetElement, create('style', 'gridRowEnd'), row.end),
setProperty('always', targetElement, PP.create('style', 'gridColumnStart'), column.start),
setProperty('always', targetElement, PP.create('style', 'gridColumnEnd'), column.end),
setProperty('always', targetElement, PP.create('style', 'gridRowStart'), row.start),
setProperty('always', targetElement, PP.create('style', 'gridRowEnd'), row.end),
],
targetCell: newTargetCell,
originalRootCell: rootCell,
Expand All @@ -174,6 +178,45 @@ export function runGridRearrangeMove(
}
}

export function gridPositionToValue(p: GridPosition | null | undefined): string | number | null {
if (p == null) {
return null
}
if (p === 'auto') {
return 'auto'
}

return p.numericalPosition
}

export function setGridPropsCommands(
elementPath: ElementPath,
gridProps: Partial<GridElementProperties>,
): CanvasCommand[] {
return stripNulls([
deleteProperties('always', elementPath, [
PP.create('style', 'gridColumn'),
PP.create('style', 'gridRow'),
]),
optionalMap(
(s) => setProperty('always', elementPath, PP.create('style', 'gridColumnStart'), s),
gridPositionToValue(gridProps?.gridColumnStart),
),
optionalMap(
(s) => setProperty('always', elementPath, PP.create('style', 'gridColumnEnd'), s),
gridPositionToValue(gridProps?.gridColumnEnd),
),
optionalMap(
(s) => setProperty('always', elementPath, PP.create('style', 'gridRowStart'), s),
gridPositionToValue(gridProps?.gridRowStart),
),
optionalMap(
(s) => setProperty('always', elementPath, PP.create('style', 'gridRowEnd'), s),
gridPositionToValue(gridProps?.gridRowEnd),
),
])
}

function getTargetCell(
previousTargetCell: GridCellCoordinates | null,
duplicating: boolean,
Expand Down
Loading
Loading