Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a00b7a4
Add initial visualizer popover, sized to the full-width
talldan Oct 18, 2022
fa9c580
Make snapping more magnetic, requiring a longer dwell time from the u…
talldan Mar 15, 2023
94a401f
Show a tooltip above the snapped alignment
talldan Mar 28, 2023
96f47a3
Avoid horizontal scrollbar when resizing
talldan Mar 28, 2023
f556dbb
Ensure block assumes the correct height when snapping
talldan Mar 28, 2023
cb24c0b
Fix typo
talldan Mar 28, 2023
ccefece
Remove unused CSS
talldan Mar 28, 2023
97e30c5
Remove unused code
talldan Mar 29, 2023
7bef33f
Fix image not inheriting correct size
talldan Apr 3, 2023
975bbeb
Prevent image layout animation unless alignment visualizer is visible
talldan Apr 3, 2023
8671b30
Remove duplicate code
talldan Apr 3, 2023
dc6471f
Fix label wrapping
talldan Apr 4, 2023
e2e478b
Make ResizableAlignmentControls a private api
talldan Apr 4, 2023
25dd8bd
Use an experiment toggle
talldan Apr 4, 2023
1342830
Remove popover usage
talldan Apr 4, 2023
c19f072
Revert changes to Popover
talldan Apr 4, 2023
c18891c
Nest entire visualizer in shadow dom container
talldan Apr 4, 2023
8bcef22
Fix merge conflict issue
talldan Apr 18, 2023
7290e20
Fix aspect ratio calculation
talldan Apr 18, 2023
af59e3b
Fix docs. Not sure how this is related to this branch, so :shrug:
talldan Apr 18, 2023
816f517
Remove restrictions that hide resize tools when at wide or full align…
talldan Apr 18, 2023
be71e52
Increase max width buffer for wide or full alignments
talldan Apr 18, 2023
0bf7c33
Try an undefined maxWidth and maxHeight
talldan Apr 18, 2023
89f4521
Fix maintaining height when resizing
talldan Apr 20, 2023
b189af4
Unset the alignment when starting a drag
talldan Apr 20, 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
Prev Previous commit
Next Next commit
Ensure block assumes the correct height when snapping
  • Loading branch information
talldan committed Apr 18, 2023
commit f556dbb1c27892061a367b48800ad99875557d2c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function ResizableAlignmentControls( {
size,
} ) {
const resizableRef = useRef();
const aspect = useRef( size.height / size.width );
const detectSnapping = useDetectSnapping();
const [ isAlignmentVisualizerVisible, setIsAlignmentVisualizerVisible ] =
useState( false );
Expand All @@ -95,23 +96,43 @@ function ResizableAlignmentControls( {
[ clientId ]
);

// Compute the styles of the content when snapped or unsnapped.
const contentStyle = useMemo( () => {
if ( ! snappedAlignment ) {
// By default the content takes up the full width of the resizable box.
return { width: '100%' };
}

const contentRect = getScreenRect( resizableRef.current );
// Calculate the positioning of the snapped image.
const resizableRect = getScreenRect( resizableRef.current );
const alignmentRect = snappedAlignment.rect;

return {
position: 'absolute',
left: alignmentRect.left - contentRect.left,
top: alignmentRect.top - contentRect.top,
left: alignmentRect.left - resizableRect.left,
top: alignmentRect.top - resizableRect.top,
width: alignmentRect.width,
};
}, [ snappedAlignment ] );

// Because the `contentStyle` is absolutely positioned when snapping occurs
// the block won't have the correct height. A separate div is used to provide
// the correct height, calculated here.
const heightStyle = useMemo( () => {
if ( ! snappedAlignment ) {
// This is a bit hacky, but using `float: left` ensures the element
// isn't part of the layout but still gives a height to the
// container.
return { float: 'left', height: 'inherit' };
}

const alignmentRect = snappedAlignment.rect;

return {
float: 'left',
height: alignmentRect.width * aspect.current,
};
}, [ snappedAlignment ] );

return (
<>
<AnimatePresence>
Expand Down Expand Up @@ -180,6 +201,11 @@ function ResizableAlignmentControls( {
} }
resizeRatio={ currentAlignment === 'center' ? 2 : 1 }
>
<motion.div
layout
style={ heightStyle }
transition={ { duration: 0.2 } }
/>
<motion.div
layout
style={ contentStyle }
Expand Down