diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 50f7632e5221e2..d2fec837602d7b 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -62,6 +62,17 @@ function gutenberg_initialize_experiments_settings() { 'id' => 'gutenberg-widgets-in-customizer', ) ); + add_settings_field( + 'gutenberg-gallery-refactor', + __( 'Gallery Refactor', 'gutenberg' ), + 'gutenberg_display_experiment_field', + 'gutenberg-experiments', + 'gutenberg_experiments_section', + array( + 'label' => __( 'Enable the refactored gallery block', 'gutenberg' ), + 'id' => 'gutenberg-gallery-refactor', + ) + ); register_setting( 'gutenberg-experiments', 'gutenberg-experiments' @@ -99,3 +110,19 @@ function gutenberg_display_experiment_section() { $experiments_exist ? array_key_exists( 'gutenberg-gallery-refactor', get_option( 'gutenberg-experiments' ) ) : false, + ); + return array_merge( $settings, $experiments_settings ); +} +add_filter( 'block_editor_settings', 'gutenberg_experiments_editor_settings' ); diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 31c2dde299bb94..f3df2bfb6d7379 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -502,6 +502,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 # **SkipToSelectedBlock** diff --git a/packages/block-editor/src/components/media-placeholder/index.js b/packages/block-editor/src/components/media-placeholder/index.js index c602c4ca8fea72..a75520476b9eb6 100644 --- a/packages/block-editor/src/components/media-placeholder/index.js +++ b/packages/block-editor/src/components/media-placeholder/index.js @@ -64,6 +64,7 @@ export function MediaPlaceholder( { accept, addToGallery, multiple = false, + handleUpload = true, dropZoneUIOnly, disableDropZone, disableMediaButtons, @@ -118,6 +119,9 @@ export function MediaPlaceholder( { }; const onFilesUpload = ( files ) => { + if ( ! handleUpload ) { + return onSelect( files ); + } onFilesPreUpload( files ); let setMedia; if ( multiple ) { diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index ba608d34a35f87..a6c3d565c7d398 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -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, @@ -151,6 +152,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. diff --git a/packages/block-library/src/gallery/block.json b/packages/block-library/src/gallery/block.json index 8beac02827f612..119afc32e7c827 100644 --- a/packages/block-library/src/gallery/block.json +++ b/packages/block-library/src/gallery/block.json @@ -54,6 +54,13 @@ }, "default": [] }, + "shortCodeTransforms": { + "type": "array", + "default": [], + "items": { + "type": "object" + } + }, "columns": { "type": "number", "minimum": 1, @@ -68,14 +75,36 @@ "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 + }, + "imageCount": { + "type": "number", + "default": 0 + }, + "gutterSize": { + "type": "number" } }, + "providesContext": { + "allowResize": "allowResize", + "isGrouped": "isGrouped" + }, "supports": { "anchor": true, "align": true diff --git a/packages/block-library/src/gallery/constants.js b/packages/block-library/src/gallery/constants.js index f4b6e7af56d473..3ac422b3e95907 100644 --- a/packages/block-library/src/gallery/constants.js +++ b/packages/block-library/src/gallery/constants.js @@ -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'; diff --git a/packages/block-library/src/gallery/deprecated.js b/packages/block-library/src/gallery/deprecated.js index 1b82131b890850..f97adbdd300245 100644 --- a/packages/block-library/src/gallery/deprecated.js +++ b/packages/block-library/src/gallery/deprecated.js @@ -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. + * + * @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 = [ { @@ -114,7 +122,7 @@ const deprecated = [ save( { attributes } ) { const { images, - columns = defaultColumnsNumber( attributes ), + columns = defaultColumnsNumberV1( attributes ), imageCrop, caption, linkTo, @@ -270,7 +278,7 @@ const deprecated = [ save( { attributes } ) { const { images, - columns = defaultColumnsNumber( attributes ), + columns = defaultColumnsNumberV1( attributes ), imageCrop, caption, linkTo, @@ -409,7 +417,7 @@ const deprecated = [ save( { attributes } ) { const { images, - columns = defaultColumnsNumber( attributes ), + columns = defaultColumnsNumberV1( attributes ), imageCrop, linkTo, } = attributes; @@ -549,7 +557,7 @@ const deprecated = [ save( { attributes } ) { const { images, - columns = defaultColumnsNumber( attributes ), + columns = defaultColumnsNumberV1( attributes ), imageCrop, linkTo, } = attributes; @@ -655,7 +663,7 @@ const deprecated = [ save( { attributes } ) { const { images, - columns = defaultColumnsNumber( attributes ), + columns = defaultColumnsNumberV1( attributes ), align, imageCrop, linkTo, diff --git a/packages/block-library/src/gallery/deprecated.scss b/packages/block-library/src/gallery/deprecated.scss new file mode 100644 index 00000000000000..3adb4685c91f3b --- /dev/null +++ b/packages/block-library/src/gallery/deprecated.scss @@ -0,0 +1,141 @@ +// 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