Skip to content
Closed
Show file tree
Hide file tree
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
Use an experiment toggle
  • Loading branch information
talldan committed Apr 18, 2023
commit 25dd8bd729d32e140e1232f28850eb1a35e86f7f
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-details-blocks', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableDetailsBlocks = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-image-block-alignment-snapping', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableImageBlockAlignmentSnapping = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-image-block-alignment-snapping',
__( 'Image block snapping ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test new guides for snapping to alignment sizes when resizing the image block.', 'gutenberg' ),
'id' => 'gutenberg-image-block-alignment-snapping',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ function ResizableAlignmentControls( {
useDispatch( blockEditorStore )
);

const isSnappingExperimentEnabled =
window.__experimentalEnableImageBlockAlignmentSnapping;
const showAlignmentVisualizer =
isSnappingExperimentEnabled && isAlignmentVisualizerVisible;

const rootClientId = useSelect(
( select ) =>
select( blockEditorStore ).getBlockRootClientId( clientId ),
Expand Down Expand Up @@ -136,7 +141,7 @@ function ResizableAlignmentControls( {
return (
<>
<AnimatePresence>
{ isAlignmentVisualizerVisible && (
{ showAlignmentVisualizer && (
<motion.div
initial={ { opacity: 0 } }
animate={ { opacity: 1 } }
Expand Down Expand Up @@ -171,22 +176,25 @@ function ResizableAlignmentControls( {
hideBlockInterface();

if (
resizeDirection === 'right' ||
resizeDirection === 'left'
isSnappingExperimentEnabled &&
( resizeDirection === 'right' ||
resizeDirection === 'left' )
) {
setIsAlignmentVisualizerVisible( true );
}
} }
onResize={ ( event, resizeDirection, resizableElement ) => {
// Detect if snapping is happening.
const newSnappedAlignment = detectSnapping(
resizableElement,
resizeDirection
);
if (
newSnappedAlignment?.name !== snappedAlignment?.name
) {
setSnappedAlignment( newSnappedAlignment );
if ( showAlignmentVisualizer ) {
// Detect if snapping is happening.
const newSnappedAlignment = detectSnapping(
resizableElement,
resizeDirection
);
if (
newSnappedAlignment?.name !== snappedAlignment?.name
) {
setSnappedAlignment( newSnappedAlignment );
}
}
} }
onResizeStop={ ( ...resizeArgs ) => {
Expand All @@ -195,13 +203,15 @@ function ResizableAlignmentControls( {
} else {
onResizeStop( ...resizeArgs );
}
setIsAlignmentVisualizerVisible( false );
if ( isSnappingExperimentEnabled ) {
setIsAlignmentVisualizerVisible( false );
}
showBlockInterface();
setSnappedAlignment( null );
} }
resizeRatio={ currentAlignment === 'center' ? 2 : 1 }
>
{ isAlignmentVisualizerVisible && (
{ showAlignmentVisualizer && (
<>
<motion.div
layout
Expand All @@ -217,7 +227,7 @@ function ResizableAlignmentControls( {
</motion.div>
</>
) }
{ ! isAlignmentVisualizerVisible && children }
{ ! showAlignmentVisualizer && children }
</ResizableBox>
</>
);
Expand Down