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

Push intended bounds for empty elements #4359

Merged
merged 54 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f601c5c
push intended bounds for empty elements (wip)
ruggi Oct 11, 2023
fddaca4
fix equality
ruggi Oct 11, 2023
3aa55da
rename
ruggi Oct 12, 2023
0ce006a
simplify map
ruggi Oct 12, 2023
c1a2cd4
use jsx props
ruggi Oct 12, 2023
f0e3808
trim commands
ruggi Oct 12, 2023
4a73f9f
rename
ruggi Oct 12, 2023
84e10ac
rename true_up_groups
ruggi Oct 12, 2023
0d2985a
more logic split
ruggi Oct 12, 2023
ecd7d28
rename types
ruggi Oct 12, 2023
d07400a
rename queue true up
ruggi Oct 12, 2023
95e58b1
update comment
ruggi Oct 12, 2023
d49a347
rename file
ruggi Oct 12, 2023
96161ad
rename file
ruggi Oct 12, 2023
9e1b221
test
ruggi Oct 12, 2023
16d6458
local frame
ruggi Oct 12, 2023
c8ad3fe
rename
ruggi Oct 12, 2023
bc7894f
accommodate for absolute children inside hugging container
ruggi Oct 12, 2023
2d09803
use isCollapsingParent, apply on status change
ruggi Oct 12, 2023
867b653
prune flex props
ruggi Oct 12, 2023
8080f3a
Merge branch 'master' into feat/true-up-empty
ruggi Oct 12, 2023
347cefd
fix tests
ruggi Oct 12, 2023
6fd4b68
Merge branch 'master' into feat/true-up-empty
ruggi Oct 12, 2023
fdd85cf
fix usage
ruggi Oct 12, 2023
5b75fbe
fix unwrap and in-flex position
ruggi Oct 13, 2023
61b8b0f
update fixtures
ruggi Oct 13, 2023
e616a5c
Merge branch 'master' into feat/true-up-empty
ruggi Oct 13, 2023
156d789
fix import
ruggi Oct 13, 2023
6a6b249
update fixture
ruggi Oct 13, 2023
57f8031
fix flaky test
ruggi Oct 13, 2023
93a7baa
more checks for the flaky madness
ruggi Oct 13, 2023
2c57bd4
use relative offsets
ruggi Oct 13, 2023
a9d4338
add toasts
ruggi Oct 13, 2023
371451d
Merge branch 'master' into feat/true-up-empty
balazsbajorics Oct 17, 2023
f647305
rename for clarity
ruggi Oct 19, 2023
4cfebc4
split command
ruggi Oct 23, 2023
5d7ec5c
push patches
ruggi Oct 23, 2023
c701f20
extend CanvasAndFrame
ruggi Oct 23, 2023
8e23c6d
rename type
ruggi Oct 23, 2023
e188cd2
rename spec
ruggi Oct 23, 2023
9808e42
move down
ruggi Oct 23, 2023
f85dac3
refactor to restore diff
ruggi Oct 23, 2023
3eadcc0
fix imports
ruggi Oct 23, 2023
d7fd82c
remove unused param
ruggi Oct 23, 2023
c3c9274
single imports
ruggi Oct 23, 2023
72b5913
Merge branch 'master' into feat/true-up-empty
ruggi Oct 23, 2023
749f95b
export
ruggi Oct 23, 2023
ab5c996
move to ts
ruggi Oct 23, 2023
3b83b7e
return commands
ruggi Oct 24, 2023
1c95d38
one file per command
ruggi Oct 24, 2023
3eda6ad
remove unused code
ruggi Oct 24, 2023
c11e4bd
imports, restore old command
ruggi Oct 24, 2023
98b7212
fix imports
ruggi Oct 24, 2023
6ea21c1
rename getUpdateResizeHuggingElementsCommands
ruggi Oct 24, 2023
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 @@ -39,15 +39,15 @@ import type {
PastePostActionMenuData,
PasteToReplacePostActionMenuData,
} from '../../../editor/store/editor-state'
import { trueUpElementChanged } from '../../../editor/store/editor-state'
import { trueUpGroupElementChanged } from '../../../editor/store/editor-state'
import {
childInsertionPath,
replaceWithElementsWrappedInFragmentBehaviour,
} from '../../../editor/store/insertion-path'
import type { CanvasCommand } from '../../commands/commands'
import { foldAndApplyCommandsInner } from '../../commands/commands'
import { deleteElement } from '../../commands/delete-element-command'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import { showToastCommand } from '../../commands/show-toast-command'
import { updateFunctionCommand } from '../../commands/update-function-command'
import { updateSelectedViews } from '../../commands/update-selected-views-command'
Expand Down Expand Up @@ -354,7 +354,7 @@ export function staticReparentAndUpdatePosition(
},
},
}),
...groupTrueUpPaths.map((path) => queueGroupTrueUp([trueUpElementChanged(path)])),
...groupTrueUpPaths.map((path) => queueTrueUpElement([trueUpGroupElementChanged(path)])),
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { ElementPath } from '../../../../core/shared/project-file-types'
import type { AllElementProps } from '../../../editor/store/editor-state'
import {
getJSXElementFromProjectContents,
trueUpElementChanged,
trueUpGroupElementChanged,
} from '../../../editor/store/editor-state'
import {
detectFillHugFixedState,
Expand All @@ -25,7 +25,7 @@ import type { EdgePosition } from '../../canvas-types'
import { EdgePositionLeft, EdgePositionTop, EdgePositionTopLeft } from '../../canvas-types'
import { isEdgePositionEqualTo } from '../../canvas-utils'
import { pushIntendedBoundsAndUpdateGroups } from '../../commands/push-intended-bounds-and-update-groups-command'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import { setCursorCommand } from '../../commands/set-cursor-command'
import { setElementsToRerenderCommand } from '../../commands/set-elements-to-rerender-command'
import { setSnappingGuidelines } from '../../commands/set-snapping-guidelines-command'
Expand Down Expand Up @@ -261,7 +261,7 @@ export function absoluteResizeBoundingBoxStrategy(
[{ target: selectedElement, frame: newFrame }],
'starting-metadata',
),
queueGroupTrueUp(childGroups.map(trueUpElementChanged)),
queueTrueUpElement(childGroups.map(trueUpGroupElementChanged)),
]
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from '../../canvas-utils'
import type { LengthPropertyToAdjust } from '../../commands/adjust-css-length-command'
import {
AdjustCssLengthProperties,
adjustCssLengthProperties,
lengthPropertyToAdjust,
} from '../../commands/adjust-css-length-command'
Expand Down Expand Up @@ -52,12 +51,9 @@ import {
resizeBoundingBox,
} from './resize-helpers'
import { pushIntendedBoundsAndUpdateGroups } from '../../commands/push-intended-bounds-and-update-groups-command'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import { treatElementAsGroupLike } from './group-helpers'
import {
trueUpChildrenOfElementChanged,
trueUpElementChanged,
} from '../../../editor/store/editor-state'
import { trueUpGroupElementChanged } from '../../../editor/store/editor-state'

export const BASIC_RESIZE_STRATEGY_ID = 'BASIC_RESIZE'

Expand Down Expand Up @@ -228,7 +224,9 @@ export function basicResizeStrategy(
[{ target: selectedElement, frame: resizedBounds }],
'starting-metadata',
),
...groupChildren.map((c) => queueGroupTrueUp([trueUpElementChanged(c.elementPath)])),
...groupChildren.map((c) =>
queueTrueUpElement([trueUpGroupElementChanged(c.elementPath)]),
),
])
} else {
return strategyApplicationResult([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { showToastCommand } from '../../commands/show-toast-command'
import {
getConvertIndividualElementToAbsoluteCommands,
isHugFromStyleAttribute,
isHuggingParent,
sizeToVisualDimensions,
} from '../../../inspector/inspector-common'
import { getDescriptiveStrategyLabelWithRetargetedPaths } from '../canvas-strategies'
Expand Down Expand Up @@ -756,7 +757,3 @@ function createSetParentsToFixedSizeCommands(

return []
}

function isHuggingParent(element: JSXElement, property: 'width' | 'height') {
return isHugFromStyleAttribute(element.props, property, 'include-all-hugs')
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isInfinityRectangle } from '../../../../core/shared/math-utils'
import { stylePropPathMappingFn } from '../../../inspector/common/property-path-hooks'
import type { LengthPropertyToAdjust } from '../../commands/adjust-css-length-command'
import {
AdjustCssLengthProperties,
adjustCssLengthProperties,
lengthPropertyToAdjust,
} from '../../commands/adjust-css-length-command'
Expand Down Expand Up @@ -34,12 +33,11 @@ import {
pickCursorFromEdgePosition,
resizeBoundingBox,
} from './resize-helpers'
import { FlexDirection } from '../../../inspector/common/css-utils'
import { getElementDimensions } from './flex-resize-helpers'
import { pushIntendedBoundsAndUpdateGroups } from '../../commands/push-intended-bounds-and-update-groups-command'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import { treatElementAsGroupLike } from './group-helpers'
import { trueUpElementChanged } from '../../../editor/store/editor-state'
import { trueUpGroupElementChanged } from '../../../editor/store/editor-state'

export function flexResizeBasicStrategy(
canvasState: InteractionCanvasState,
Expand Down Expand Up @@ -227,7 +225,9 @@ export function flexResizeBasicStrategy(
[{ target: selectedElement, frame: resizedBounds }],
'starting-metadata',
),
...groupChildren.map((c) => queueGroupTrueUp([trueUpElementChanged(c.elementPath)])),
...groupChildren.map((c) =>
queueTrueUpElement([trueUpGroupElementChanged(c.elementPath)]),
),
])
} else {
return strategyApplicationResult([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ import { strictEvery, mapDropNulls } from '../../../../core/shared/array-utils'
import type { ElementPath } from '../../../../core/shared/project-file-types'
import type { ElementPathTrees } from '../../../../core/shared/element-path-tree'
import { treatElementAsGroupLike } from './group-helpers'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import { pushIntendedBoundsAndUpdateGroups } from '../../commands/push-intended-bounds-and-update-groups-command'
import { trueUpElementChanged } from '../../../editor/store/editor-state'
import { trueUpGroupElementChanged } from '../../../editor/store/editor-state'

export const FLEX_RESIZE_STRATEGY_ID = 'FLEX_RESIZE'

Expand Down Expand Up @@ -358,7 +358,9 @@ export function flexResizeStrategy(
[{ target: selectedElement, frame: newFrame }],
'starting-metadata',
),
...groupChildren.map((c) => queueGroupTrueUp([trueUpElementChanged(c.elementPath)])),
...groupChildren.map((c) =>
queueTrueUpElement([trueUpGroupElementChanged(c.elementPath)]),
),
])
} else {
return strategyApplicationResult([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ import type { AddToast, ApplyCommandsAction } from '../../../editor/action-types
import { applyCommandsAction, showToast } from '../../../editor/actions/action-creators'
import type { AllElementProps, NavigatorEntry } from '../../../editor/store/editor-state'
import {
trueUpChildrenOfElementChanged,
trueUpElementChanged,
trueUpChildrenOfGroupChanged,
trueUpGroupElementChanged,
} from '../../../editor/store/editor-state'
import {
childInsertionPath,
Expand All @@ -102,7 +102,7 @@ import { EdgePositionBottomRight } from '../../canvas-types'
import { addElement } from '../../commands/add-element-command'
import type { CanvasCommand } from '../../commands/commands'
import { deleteElement } from '../../commands/delete-element-command'
import { queueGroupTrueUp } from '../../commands/queue-group-true-up-command'
import { queueTrueUpElement } from '../../commands/queue-true-up-command'
import type { SetCssLengthProperty } from '../../commands/set-css-length-command'
import {
setCssLengthProperty,
Expand Down Expand Up @@ -733,7 +733,7 @@ export function convertFrameToGroup(
getConvertIndividualElementToAbsoluteCommandsFromMetadata(c, metadata, pathTrees),
),
...prunePropsCommands(flexContainerProps, elementPath), // flex-related stuff is pruned
queueGroupTrueUp([trueUpChildrenOfElementChanged(elementPath)]),
queueTrueUpElement([trueUpChildrenOfGroupChanged(elementPath)]),
showToastCommand(
'Converted to group and removed styling',
'INFO',
Expand Down Expand Up @@ -1092,7 +1092,7 @@ export function createWrapInGroupActions(
insertGroupCommand,
...pinChangeCommands,
selectNewGroup,
queueGroupTrueUp([trueUpElementChanged(groupPath)]),
queueTrueUpElement([trueUpGroupElementChanged(groupPath)]),
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export function groupJSXElement(children: JSXElementChildren): JSXElementWithout
'Group',
jsxAttributesFromMap({
style: jsExpressionValue(
// we need to add position: absolute and top, left so that the TRUE_UP_GROUPS action can correct these values later
// we need to add position: absolute and top, left so that the TRUE_UP_ELEMENTS action can correct these values later
{ position: 'absolute', left: 0, top: 0 },
emptyComments,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type { IndexPosition } from '../../../../utils/utils'
import { fastForEach } from '../../../../core/shared/utils'
import { addElements } from '../../commands/add-elements-command'
import type { ElementPathTrees } from '../../../../core/shared/element-path-tree'
import { getRequiredGroupTrueUps } from '../../commands/queue-group-true-up-command'
import { getRequiredGroupTrueUps } from '../../commands/queue-true-up-command'
import type { Either } from '../../../../core/shared/either'
import { left, right } from '../../../../core/shared/either'
import { maybeBranchConditionalCase } from '../../../../core/model/conditionals'
Expand Down
20 changes: 13 additions & 7 deletions editor/src/components/canvas/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import type { DuplicateElement } from './duplicate-element-command'
import { runDuplicateElement } from './duplicate-element-command'
import type { UpdateFunctionCommand } from './update-function-command'
import { runUpdateFunctionCommand } from './update-function-command'
import type { PushIntendedBoundsAndUpdateGroups } from './push-intended-bounds-and-update-groups-command'
import { runPushIntendedBoundsAndUpdateGroups } from './push-intended-bounds-and-update-groups-command'
import type { DeleteProperties } from './delete-properties-command'
import { runDeleteProperties } from './delete-properties-command'
import type { AddImportsToFile } from './add-imports-to-file-command'
Expand Down Expand Up @@ -81,8 +79,12 @@ import { runWrapInContainerCommand } from './wrap-in-container-command'
import { patchProjectContentsWithParsedFile } from './patch-utils'
import type { AddElements } from './add-elements-command'
import { runAddElements } from './add-elements-command'
import type { QueueGroupTrueUp } from './queue-group-true-up-command'
import { runQueueGroupTrueUp } from './queue-group-true-up-command'
import type { QueueTrueUpElement } from './queue-true-up-command'
import { runQueueTrueUpElement } from './queue-true-up-command'
import type { PushIntendedBoundsAndUpdateGroups } from './push-intended-bounds-and-update-groups-command'
import { runPushIntendedBoundsAndUpdateGroups } from './push-intended-bounds-and-update-groups-command'
import type { PushIntendedBoundsAndUpdateHuggingElements } from './push-intended-bounds-and-update-hugging-elements-command'
import { runPushIntendedBoundsAndUpdateHuggingElements } from './push-intended-bounds-and-update-hugging-elements-command'

export interface CommandFunctionResult {
editorStatePatches: Array<EditorStatePatch>
Expand Down Expand Up @@ -117,6 +119,7 @@ export type CanvasCommand =
| SetElementsToRerenderCommand
| AppendElementsToRerenderCommand
| PushIntendedBoundsAndUpdateGroups
| PushIntendedBoundsAndUpdateHuggingElements
| DeleteProperties
| SetProperty
| UpdatePropIfExists
Expand All @@ -133,7 +136,7 @@ export type CanvasCommand =
| RearrangeChildren
| DeleteElement
| WrapInContainerCommand
| QueueGroupTrueUp
| QueueTrueUpElement

export function runCanvasCommand(
editorState: EditorState,
Expand Down Expand Up @@ -179,6 +182,9 @@ export function runCanvasCommand(
return runAppendElementsToRerender(editorState, command)
case 'PUSH_INTENDED_BOUNDS_AND_UPDATE_GROUPS':
return runPushIntendedBoundsAndUpdateGroups(editorState, command, commandLifecycle)
case 'PUSH_INTENDED_BOUNDS_AND_UPDATE_HUGGING_ELEMENTS':
return runPushIntendedBoundsAndUpdateHuggingElements(editorState, command)

case 'DELETE_PROPERTIES':
return runDeleteProperties(editorState, command)
case 'SET_PROPERTY':
Expand Down Expand Up @@ -211,8 +217,8 @@ export function runCanvasCommand(
return runDeleteElement(editorState, command)
case 'WRAP_IN_CONTAINER':
return runWrapInContainerCommand(editorState, command)
case 'QUEUE_GROUP_TRUE_UP':
return runQueueGroupTrueUp(editorState, command)
case 'QUEUE_TRUE_UP_ELEMENT':
return runQueueTrueUpElement(editorState, command)
default:
const _exhaustiveCheck: never = command
throw new Error(`Unhandled canvas command ${JSON.stringify(command)}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
EditorState,
EditorStatePatch,
} from '../../editor/store/editor-state'
import { trueUpElementChanged } from '../../editor/store/editor-state'
import { trueUpGroupElementChanged } from '../../editor/store/editor-state'
import { cssPixelLength, type FlexDirection } from '../../inspector/common/css-utils'
import {
getConstraintsIncludingImplicitForElement,
Expand Down Expand Up @@ -107,8 +107,8 @@ export const runPushIntendedBoundsAndUpdateGroups = (
commandLifecycle === 'end-interaction' && !commandRanBecauseOfQueuedTrueUp
? [
{
trueUpGroupsForElementAfterDomWalkerRuns: {
$set: resizedGroupChildren.map((c) => trueUpElementChanged(c)),
trueUpElementsAfterDomWalkerRuns: {
$set: resizedGroupChildren.map((c) => trueUpGroupElementChanged(c)),
},
},
]
Expand Down
Loading
Loading