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

Gallery: Convert Gallery block to use Image blocks instead of having its own nested image format #25940

Merged
merged 158 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
c01bbfb
Refactor gallery to nested image blocks
Apr 11, 2021
038b22d
Fix issue with images not loading on first selection from media gallery
Nov 4, 2020
331c302
Remove the default columns setting as we don't have access to innerBl…
Nov 4, 2020
ee7da0a
Revert "Remove the default columns setting as we don't have access to…
Nov 4, 2020
c9fe911
Add image count so we can work out default columns as innerBlocks not…
Nov 4, 2020
a00a544
Disable the innerBlocks dropzones so drag drop works same as existing…
Nov 5, 2020
0c8742f
Lint changes
Nov 5, 2020
a77854c
Revert "Lint changes"
Nov 6, 2020
1965514
Revert "Disable the innerBlocks dropzones so drag drop works same as …
Nov 6, 2020
e5e1420
Suggested solution for handling multiple file drop into gallery
Nov 6, 2020
1d6c559
Remove non image files from drag and drop and disable individual imag…
Jan 21, 2021
39cecec
Fix transform to individual images
Nov 8, 2020
d9ec2b0
Fix transform from individual images
Nov 8, 2020
3742af8
Revert drag and drop transform changes
Nov 9, 2020
3acb223
Add gallery transform to image block to override the default gallery …
Nov 9, 2020
084e6c7
Move handling of file uploads to Gallery from media placeholder
Apr 11, 2021
cff6727
split innerblocks mapping into separate effect to reduce chatter
Nov 17, 2020
f1606cc
Add useMemo to currentImageOptions
Nov 17, 2020
1140646
reuse existing innerBlocks rather than recreating with every new imag…
Nov 17, 2020
6d23628
Switch to useMemo for updating local image const instead of local com…
Nov 17, 2020
f7a1ff4
Fix issue with image sizing not being available on initial load of co…
Nov 17, 2020
974ad90
Memoise the useImageSizes hook
Nov 17, 2020
5ac143b
Fix issue with media browser defaulting to edit gallery view
Nov 17, 2020
8ceaa3d
Fix missed incorrect use of addToGallery
Nov 17, 2020
8d7159b
Add some extra effects for getting the imageData as the getMedia call…
Nov 18, 2020
dbda7e9
Simplify the imageData by using a useSelect
Nov 19, 2020
342695e
Another optimisation - only return a new imageData reference if all i…
Nov 19, 2020
0744b59
Refactored Gallery: Add loading state to gallery image size options (…
aaronrobertshaw Nov 19, 2020
dad1b0b
Initial deprecations commit
Jan 13, 2021
bcf6664
Fix issue with linkDestination not being applied in migration
Nov 19, 2020
921fecc
Refactor gallery deprecations
aaronrobertshaw Nov 20, 2020
7920a45
Fix missing attributes from migration
aaronrobertshaw Nov 20, 2020
c97630c
Update deprecation to set allowResize
aaronrobertshaw Nov 22, 2020
2724965
Fix issue with crop not working when certain plugins are loaded
Mar 22, 2021
098ba86
Fix SCSS lint errors
aaronrobertshaw Nov 22, 2020
49f9d6b
Update the block example
Nov 23, 2020
88c096b
Linting fixes
Nov 23, 2020
37b4b4e
Fix the e2e test and the accessibility issue with having aria group r…
Mar 22, 2021
0c5e720
Fix the e2e test and the accessibility issue with having aria group r…
Mar 22, 2021
5840a1c
Fix frontend omission of wp-block-image class
aaronrobertshaw Nov 24, 2020
e1e6a8a
change deprecation to use imageCount as isEligible check as it seems …
Nov 25, 2020
d7187b4
Move back to a single deprecations file and reorder in array
Nov 26, 2020
b648b10
Remove additional check in v5 isEligible
Nov 26, 2020
f1454f2
Fix the v4 migration
Nov 26, 2020
e76bb06
Fix styles for Safari compatibility
aaronrobertshaw Nov 30, 2020
b969e3f
Remove unnecessary gallery editor styles
aaronrobertshaw Nov 30, 2020
0ff156a
Fix typo in deprecations
aaronrobertshaw Nov 30, 2020
309f9f0
Restore styles to render deprecated gallery versions
Mar 22, 2021
e6d1301
Avoid applying flex styles to IE11
aaronrobertshaw Dec 1, 2020
4953a0c
Add additional selector to prevent the hidden individual image drop z…
Mar 22, 2021
d259127
IE11 styling improvements
aaronrobertshaw Dec 2, 2020
1a16354
Apply default style class to new images added to gallery
Dec 11, 2020
9aadf8f
fix linting issues
Dec 11, 2020
e879978
Move block props to the outer wrapper
Dec 13, 2020
f072943
Revert "Move block props to the outer wrapper"
Dec 13, 2020
c4d06ee
Revert "Revert "Move block props to the outer wrapper""
Dec 13, 2020
82eee6e
Fetch media if isListItem is true
Apr 11, 2021
601119c
Change context from isListItem to isGrouped
Apr 11, 2021
4f1ddb4
Remove wrapper div
Mar 22, 2021
a6603cf
remove extra wrapper around media placeholder and caption and use fle…
Jan 13, 2021
9b8d498
Revert "remove extra wrapper around media placeholder and caption and…
Jan 13, 2021
bd88cb2
Revert "Remove external div wrapper by moving InnerBlocks to a fragment"
Mar 22, 2021
abcb029
another update to image wrapper
Jan 13, 2021
939456d
put media uploader outside figure so structure matches front end
Dec 17, 2020
bf0aec2
Replace div with View for the sake of native code
Dec 17, 2020
0938b5e
Move setting of attributes to the child images
Apr 11, 2021
94d9877
Gallery Block Refactor: Account for null image ids in gallery migrati…
glendaviesnz Dec 22, 2020
17ca088
Remove the gradient and put caption under image if is-rounded style a…
glendaviesnz Dec 24, 2020
2c2b38e
Remove outer div wrapper
Mar 22, 2021
82ef52a
Keep image margins while dragging sibling
aaronrobertshaw Jan 14, 2021
bc61288
Fix e2e test expected markup to match new structure
Jan 18, 2021
7af15db
Gallery Block Refactor: Add handling of short code transforms
Feb 15, 2021
1e1752e
Removed unused prop
Jan 20, 2021
726e48c
Account for undefined block and innerblocks in conversion to reusable…
Apr 11, 2021
21bd032
Add custom gutter sizes to refactored gallery (#28377)
aaronrobertshaw Jan 21, 2021
a9453d2
Adjust editor styles to match new dom structure
Mar 22, 2021
83b9074
Remove redundant styles that are duplicated in nested image blocks
Jan 21, 2021
e3a6c29
Fix issue with Image block dragged out of Gallery still having inheri…
Jan 22, 2021
d34dcdb
When dragging an image block into a gallery make sure we don't wipe a…
Jan 25, 2021
72e9c2b
fix issue with variable declaration order
Jan 25, 2021
e291f91
Fix bug with custom link being overwritten by gallery linkTo changes
Jan 26, 2021
795a568
Fix application of gutter size CSS var (#28759)
aaronrobertshaw Feb 5, 2021
9580649
Fix mobile width for gallery images
aaronrobertshaw Feb 10, 2021
74072f0
Add missing dependency to inner images selector
aaronrobertshaw Feb 10, 2021
cf4dc34
remove conversion to cover block if image in gallery
Mar 22, 2021
f90965c
Add fallback to old gallery edit and save for existing gallery (#28961)
glendaviesnz Feb 15, 2021
be75a36
Remove duplicate import
Feb 15, 2021
780e9e7
Remove need for temporary imageUploads attribute as we can just creat…
Feb 15, 2021
fd1e27d
Remove handling of gallery attribute updates from child images
Feb 16, 2021
652557e
Move updating of attributes back to gallery and show snackbar to indi…
Feb 16, 2021
1da955d
Update transforms to work with both versions of gallery
Feb 16, 2021
5b809d5
Remove redundant changes
Feb 16, 2021
b3fb72c
Remove redundant changes
Feb 16, 2021
b5ca5ef
Remove unused method
Feb 16, 2021
d5f5cba
Merge similar Image transforms.
Feb 16, 2021
82b97b8
Fix some issues missed when moving attribute setting back to gallery.
Feb 18, 2021
d9b1733
Simplify handling of images from media placeholder now that drag and …
Feb 19, 2021
ee6bef7
Fix typo
aaronrobertshaw Feb 19, 2021
9e0b05c
Fix broken upload from media placeholder
Feb 19, 2021
f27e872
Fix issue with new file uploads overwriting existing blocks
Feb 19, 2021
30dc02f
Remove isGrouped dependency from call to get image as not needed now …
Feb 22, 2021
3d47210
Remove custom gutter size feature
aaronrobertshaw Feb 22, 2021
fd56523
Use getMediaItems instead of getMedia for getting image data for all …
Feb 23, 2021
657ba78
Add back missing context prop from rebase conflict
Feb 23, 2021
a111532
Make use of new uniqueByBlock flag on updateBlockAttributes to batch …
Feb 23, 2021
6370194
Move the setting of the default attributes on new blocks to a single …
glendaviesnz Mar 1, 2021
e23ddb0
Add snackbar notice ids (#29364)
aaronrobertshaw Mar 1, 2021
fc2b2a0
Account for people adding and removing images from media browser so …
Mar 1, 2021
716ea1b
Changes from PR feedback
Mar 1, 2021
44df5dd
Fix issue with deprecated constants
Mar 3, 2021
3a75fb0
Fix linting and e2e test failures
Mar 3, 2021
84ebe2e
Some more e2e fixes
Mar 4, 2021
6b06732
Add transform from old gallery to new format
Mar 4, 2021
6caef45
Memoize the allowedBlocks
aaronrobertshaw Mar 8, 2021
8eceac7
Add warning about image formats required if uploading to gallery
Mar 8, 2021
efd0705
Move allowedBlocks outside of component to avoid useMemo use
aaronrobertshaw Mar 8, 2021
82cf526
Re-apply uncropped alignment changes lost in rebase
Mar 9, 2021
d133db7
Fix issue with non-cropped images in deprecated gallery
Mar 9, 2021
651ff59
Don't show media library buttons while images are still uploading as …
Apr 11, 2021
6209e6e
Remove gallerRef that was no longer doing anything
Mar 9, 2021
eaa0c7a
Respect sort order from Media Library (#30070)
glendaviesnz Mar 22, 2021
20477de
Gallery block refactor: make invalid file type errors consistent (#30…
glendaviesnz Mar 31, 2021
6195768
Fix issue with invalid type message when adding files via media brows…
Apr 6, 2021
9cfb170
Gallery block refactor: check for new images by clientId instead of i…
glendaviesnz Apr 8, 2021
772691d
Apply changes from rebase to deprecated gallery
Apr 11, 2021
d71011b
Apply patch from rebase to not select all items in media library when…
Apr 12, 2021
991437d
Copy caption across from image selected from media library (#30784)
glendaviesnz Apr 13, 2021
a2253ec
Add data-id to image to help with compatibility of refactored gallery…
glendaviesnz Apr 22, 2021
d225aca
Revert "Add data-id to image to help with compatibility of refactored…
Apr 23, 2021
fc06639
fix bug with image style being lost when gallery grouped (#31068)
glendaviesnz Apr 23, 2021
1067a0c
Only add RichText component if the figcaption is clicked to prevent i…
glendaviesnz Apr 28, 2021
ff4fadc
Fix bug with alt text not being copied from media library (#31066)
glendaviesnz Apr 30, 2021
b976235
Merge branch 'trunk' of github.com:WordPress/gutenberg into refactor/…
May 19, 2021
1a4345a
Gallery refactor - Infer version from existing content (#32270)
mkevins May 30, 2021
e5420c6
Merge branch 'trunk' into refactor/gallery-to-nested-image-blocks-ups…
mkevins Jun 3, 2021
e183dcb
Resolve merge conflicts
mkevins Jun 3, 2021
b2031f2
Use non-deprecated hook when possible
mkevins Jun 4, 2021
71b249c
Merge branch 'trunk' into refactor/gallery-to-nested-image-blocks-ups…
mkevins Jun 16, 2021
c72984f
Resolve conflict in block editor default settings
mkevins Jun 16, 2021
7da0c1b
Merge branch 'trunk' into refactor/gallery-to-nested-image-blocks-ups…
mkevins Jul 8, 2021
797cb28
Resolve conflict in image.js
mkevins Jul 8, 2021
fad851a
Minor changes from code review:
Jul 16, 2021
a83b106
Improve naming of save and deprecated save methods
Jul 19, 2021
a424509
Rename __experimentalGalleryRefactor flag to __unstableGalleryWithInn…
Jul 19, 2021
c69f2d5
Remove the isGrouped context as no longer needed.
Jul 20, 2021
887b6b4
Rename __unstableGalleryWithInnerBlocks to _unstableGalleryWithImageB…
Jul 22, 2021
c4eb362
Gallery block refactor: remove the imageCount attribute (#33677)
glendaviesnz Jul 26, 2021
55e8bf6
Merge branch 'trunk' of github.com:WordPress/gutenberg into refactor/…
Jul 27, 2021
8b1bd7d
Fix broken scss
Jul 28, 2021
0b9d8b2
Fix php linting error
Jul 28, 2021
6a58538
Merge mobile refactor of gallery to nested image blocks into desktop …
mkevins Aug 3, 2021
8529284
Merge branch 'trunk' of github.com:WordPress/gutenberg into refactor/…
Aug 3, 2021
a41edeb
Fix issue with upload spinner not displaying correctly on v1 gallery …
Aug 9, 2021
0273b7b
Gallery block: Add a filter to automatically convert transforms to an…
glendaviesnz Aug 12, 2021
5cbaedd
Merge branch 'trunk' of github.com:WordPress/gutenberg into refactor/…
Aug 16, 2021
78472d9
Fix issue with image to cover block conversion
Aug 16, 2021
fd0f7ec
Add imageCrop to gallery context
mkevins Aug 17, 2021
d55be9e
Fix exceptions caused by useBlocksProps running after block has been …
glendaviesnz Aug 19, 2021
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
32 changes: 32 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-navigation',
)
);
add_settings_field(
'gutenberg-gallery-refactor',
__( 'Gallery block experiment', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test a new gallery block that uses nested image blocks', 'gutenberg' ),
'id' => 'gutenberg-gallery-refactor',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down Expand Up @@ -88,3 +99,24 @@ function gutenberg_display_experiment_section() {

<?php
}

/**
* Extends default editor settings with experiments settings.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_experiments_editor_settings( $settings ) {
$experiments_exist = get_option( 'gutenberg-experiments' );
$experiments_settings = array(
'__experimentalGalleryRefactor' => $experiments_exist ? array_key_exists( 'gutenberg-gallery-refactor', get_option( 'gutenberg-experiments' ) ) : false,
);
return array_merge( $settings, $experiments_settings );
talldan marked this conversation as resolved.
Show resolved Hide resolved
}
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_experiments_editor_settings' );
} else {
add_filter( 'block_editor_settings', 'gutenberg_experiments_editor_settings' );
}
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ _Properties_
- _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory
- _\_\_experimentalBlockPatterns_ `Array`: Array of objects representing the block patterns
- _\_\_experimentalBlockPatternCategories_ `Array`: Array of objects representing the block pattern categories
- _\_\_experimentalGalleryRefactor_ `boolean`: Whether the user has enabled the refactored gallery block which uses InnerBlocks
talldan marked this conversation as resolved.
Show resolved Hide resolved

<a name="SkipToSelectedBlock" href="#SkipToSelectedBlock">#</a> **SkipToSelectedBlock**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ Callback called when urls can be configured. No media insertion from url will be
- Required: No
- Platform: Web

### handleUpload

When set to false the handling of the upload is left to the calling component.

- Type: `Boolean`
- Required: No
- Default: `true`
- Platform: Web

## Extend

It includes a `wp.hooks` filter `editor.MediaPlaceholder` that enables developers to replace or extend it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function MediaPlaceholder( {
accept,
addToGallery,
multiple = false,
handleUpload = true,
talldan marked this conversation as resolved.
Show resolved Hide resolved
dropZoneUIOnly,
disableDropZone,
disableMediaButtons,
Expand Down Expand Up @@ -118,6 +119,9 @@ export function MediaPlaceholder( {
};

const onFilesUpload = ( files ) => {
if ( ! handleUpload ) {
return onSelect( files );
}
onFilesPreUpload( files );
let setMedia;
if ( multiple ) {
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const PREFERENCES_DEFAULTS = {
* @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory
* @property {Array} __experimentalBlockPatterns Array of objects representing the block patterns
* @property {Array} __experimentalBlockPatternCategories Array of objects representing the block pattern categories
* @property {boolean} __experimentalGalleryRefactor Whether the user has enabled the refactored gallery block which uses InnerBlocks
*/
export const SETTINGS_DEFAULTS = {
alignWide: false,
Expand Down Expand Up @@ -155,6 +156,7 @@ export const SETTINGS_DEFAULTS = {
__experimentalBlockPatterns: [],
__experimentalBlockPatternCategories: [],
__experimentalSpotlightEntityBlocks: [],
__experimentalGalleryRefactor: false,

// gradients setting is not used anymore now defaults are passed from theme.json on the server and core has its own defaults.
// The setting is only kept for backward compatibility purposes.
Expand Down
26 changes: 26 additions & 0 deletions packages/block-library/src/gallery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
},
"default": []
},
"shortCodeTransforms": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this about?

Copy link
Contributor Author

@glendaviesnz glendaviesnz Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When transforming a shortcode there is no transform method available, so no opportunity to create the innerBlocks as part of the transform process. The only workaround I could see for this was to add the data to a temporary attribute like with the file drag and drop, and process this in the editor when detected and then remove the attribute. Let me know if there is a way that I have overlooked to take the image ids from a shortcode and create the innerBlocks as part of the transform process instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as above I guess, so there's already a solution in the image block itself.

Copy link
Contributor Author

@glendaviesnz glendaviesnz Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of the gallery short codes all we have is an id, and in the absence of a transform method there is no way to convert that id into a url - i did just try handing an id only to the Image block but it requires a url of some form - will take another look at this as well though in case I missed something.

Copy link
Contributor

@youknowriad youknowriad Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. It seems it's different than upload. though, I wonder if we should apply a similar technique:

If we detect an image block with an id but no url, triggers some effect in the image edit to get the remaining attributes right. We may need a "loading" state in the placeholder or something.

That said, the current approach is not that bad, it's just that attributes are meant to persist and this is changing that a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have had another look at this and the issue is that a shortcode transform provides no opportunity to return a block as there is no transform method as part of the transformation as noted here - #17758.

If there was a transform method with shortcode transformations we could do as you suggested and just create the Image innerBlocks with an id only and let the Image block handle getting the url, etc. but currently the only way I can see to do this would be a two stage transform, eg. go from shortcode to core/shortcode block and then from core/shortcode to core/gallery ... but that seems like a messy user experience. Do you know why it is that shortcode transformations have no option to return a block from a transform method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix would know more here but I guess the response is that the schema was sufficient for the transforms we had to support so far

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply, going through a bunch of notifications. Maybe there was never a need for it so far? I don't mind if we add a transform option.

"type": "array",
"default": [],
"items": {
"type": "object"
}
},
"columns": {
"type": "number",
"minimum": 1,
Expand All @@ -72,14 +79,33 @@
"type": "boolean",
"default": true
},
"linkTarget": {
"type": "string"
},
"linkTo": {
"type": "string"
},
"sizeSlug": {
"type": "string",
"default": "large"
},
"allowResize": {
"type": "boolean",
"default": false
},
"isGrouped": {
"type": "boolean",
"default": true
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something to address, but just an observation. The way these attributes work via context is interesting. They're never serialized in the gallery because they're never set to anything other than the default, which is a positive thing considering this quite a new way to pass contextual configuration to a child block (and we don't want to require a deprecation if there's a small change to this).

It makes me wonder if there could be a shorthand via block context so that they're truly constants:

"providesContextConstants": {
    "allowResize": false,
    "isGrouped": true
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to introduce this context at all, isn't this the same thing as checking that the image is a children of a gallery block using the data module? (We already do something similar for "post blocks" inside Query blocks, the behavior of post blocks can change slightly if they are children of query blocks or not)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@talldan, @youknowriad - I agree that it would be good to explore alternatives to this. I wonder if coupling it tightly to a specific parent blocks via the data module is a better way forward though? ie. by passing in the new context values any new block can group images without having to modify the image block, but using the data module the image block would need updating to add new parent blocks - I may be misunderstanding what you are suggesting though.

Either way, since we are not serializing these values, so no deprecations needed for changes, would you both be happy if we handle this as a follow up PR soon after this one is merged? I think it will be easier to explore options for this in isolation from all the other changes in this PR. I have added an issue for it. Let me know if you think it needs following up before merging.

Copy link
Contributor Author

@glendaviesnz glendaviesnz Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out that isGrouped was not actually needed anymore since we moved away from using an ordered list for display, and since the convert to cover block image toolbar option was made more specific - so removed here. So just the allowResize context left.

"imageCount": {
"type": "number",
"default": 0
talldan marked this conversation as resolved.
Show resolved Hide resolved
}
},
"providesContext": {
"allowResize": "allowResize",
"isGrouped": "isGrouped"
},
"supports": {
"anchor": true,
"align": true
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/gallery/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const LINK_DESTINATION_NONE = 'none';
export const LINK_DESTINATION_MEDIA = 'file';
export const LINK_DESTINATION_ATTACHMENT = 'post';
export const LINK_DESTINATION_MEDIA = 'media';
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
22 changes: 15 additions & 7 deletions packages/block-library/src/gallery/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ import { map, some } from 'lodash';
import { RichText } from '@wordpress/block-editor';

/**
* Internal dependencies
* Original function to determine default number of columns from a block's
* attributes.
*
* Used in deprecations: v1-6, for versions of the gallery block that didn't use inner blocks.
*
* @param {Object} attributes Block attributes.
* @return {number} Default number of columns for the gallery.
*/
import { defaultColumnsNumber } from './shared';
export function defaultColumnsNumberV1( attributes ) {
return Math.min( 3, attributes.images.length );
}

const deprecated = [
{
Expand Down Expand Up @@ -114,7 +122,7 @@ const deprecated = [
save( { attributes } ) {
const {
images,
columns = defaultColumnsNumber( attributes ),
columns = defaultColumnsNumberV1( attributes ),
imageCrop,
caption,
linkTo,
Expand Down Expand Up @@ -270,7 +278,7 @@ const deprecated = [
save( { attributes } ) {
const {
images,
columns = defaultColumnsNumber( attributes ),
columns = defaultColumnsNumberV1( attributes ),
imageCrop,
caption,
linkTo,
Expand Down Expand Up @@ -409,7 +417,7 @@ const deprecated = [
save( { attributes } ) {
const {
images,
columns = defaultColumnsNumber( attributes ),
columns = defaultColumnsNumberV1( attributes ),
imageCrop,
linkTo,
} = attributes;
Expand Down Expand Up @@ -549,7 +557,7 @@ const deprecated = [
save( { attributes } ) {
const {
images,
columns = defaultColumnsNumber( attributes ),
columns = defaultColumnsNumberV1( attributes ),
imageCrop,
linkTo,
} = attributes;
Expand Down Expand Up @@ -655,7 +663,7 @@ const deprecated = [
save( { attributes } ) {
const {
images,
columns = defaultColumnsNumber( attributes ),
columns = defaultColumnsNumberV1( attributes ),
align,
imageCrop,
linkTo,
Expand Down
149 changes: 149 additions & 0 deletions packages/block-library/src/gallery/deprecated.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Deprecated gallery styles pre refactoring to use nested image blocks.
// https://github.com/WordPress/gutenberg/pull/25940.
.wp-block-gallery,
.blocks-gallery-grid {
display: flex;
flex-wrap: wrap;
list-style-type: none;
padding: 0;
// Some themes give all <ul> default margin instead of padding.
margin: 0;

.blocks-gallery-image,
.blocks-gallery-item {
// Add space between thumbnails, and unset right most thumbnails later.
margin: 0 1em 1em 0;
display: flex;
flex-grow: 1;
flex-direction: column;
justify-content: center;
position: relative;

// On mobile and responsive viewports, we allow only 1 or 2 columns at the most.
width: calc(50% - 1em);

&:nth-of-type(even) {
margin-right: 0;
}

figure {
margin: 0;
height: 100%;

// IE doesn't support flex so omit that.
@supports (position: sticky) {
display: flex;
align-items: flex-end;
justify-content: flex-start;
}
}

img {
display: block;
max-width: 100%;
height: auto;

// IE doesn't handle cropping, so we need an explicit width here.
width: 100%;

// IE11 doesn't read rules inside this query. They are applied only to modern browsers.
@supports (position: sticky) {
width: auto;
}
}

figcaption {
position: absolute;
bottom: 0;
width: 100%;
max-height: 100%;
overflow: auto;
padding: 3em 0.77em 0.7em;
color: $white;
text-align: center;
font-size: 0.8em;
background: linear-gradient(0deg, rgba($color: $black, $alpha: 0.7) 0, rgba($color: $black, $alpha: 0.3) 70%, transparent);
box-sizing: border-box;
margin: 0;
z-index: 2;
img {
display: inline;
}
}
}

figcaption {
flex-grow: 1;
}

// Cropped
&.is-cropped .blocks-gallery-image,
&.is-cropped .blocks-gallery-item {
a,
img {
// IE11 doesn't support object-fit, so just make sure images aren't skewed.
// The following rules are for all browsers.
width: 100%;

// IE11 doesn't read rules inside this query. They are applied only to modern browsers.
@supports (position: sticky) {
height: 100%;
flex: 1;
object-fit: cover;
}
}
}

&.columns-1 .blocks-gallery-image,
&.columns-1 .blocks-gallery-item {
width: 100%;
margin-right: 0;
}

// Beyond mobile viewports, we allow up to 8 columns.
@include break-small {
@for $i from 3 through 8 {
&.columns-#{ $i } .blocks-gallery-image,
&.columns-#{ $i } .blocks-gallery-item {
width: calc(#{ 100% / $i } - #{ 1em * ( $i - 1 ) / $i });
margin-right: 1em;
}
}

// Unset the right margin on every rightmost gallery item to ensure center balance.
@for $column-count from 1 through 8 {
&.columns-#{ $column-count } .blocks-gallery-image:nth-of-type(#{ $column-count }n),
&.columns-#{ $column-count } .blocks-gallery-item:nth-of-type(#{ $column-count }n) {
margin-right: 0;
}
}
}

// Last item always needs margins reset.
.blocks-gallery-image:last-child,
.blocks-gallery-item:last-child {
margin-right: 0;
}

// Apply max-width to floated items that have no intrinsic width.
&.alignleft,
&.alignright {
max-width: $content-width / 2;
width: 100%;
}

// If the gallery is centered, center the content inside as well.
&.aligncenter {
.blocks-gallery-item figure {
justify-content: center;
}
}
}
.wp-block-gallery {
// Non cropped images.
&:not(.is-cropped) {
.blocks-gallery-item {
align-self: flex-start;
}
}
}
Loading