diff --git a/packages/block-editor/src/components/global-styles/test/use-global-styles-context.native.js b/packages/block-editor/src/components/global-styles/test/use-global-styles-context.native.js index a247b4132b1ff..a8b1e9e1bdf1b 100644 --- a/packages/block-editor/src/components/global-styles/test/use-global-styles-context.native.js +++ b/packages/block-editor/src/components/global-styles/test/use-global-styles-context.native.js @@ -414,6 +414,7 @@ describe( 'getGlobalStyles', () => { expect( globalStyles ).toEqual( expect.objectContaining( { __experimentalFeatures: { + blocks: {}, color: { palette: RAW_FEATURES.color.palette, gradients, diff --git a/packages/block-editor/src/components/global-styles/use-global-styles-context.native.js b/packages/block-editor/src/components/global-styles/use-global-styles-context.native.js index 31bcd899fda7a..f4aedc378e1a7 100644 --- a/packages/block-editor/src/components/global-styles/use-global-styles-context.native.js +++ b/packages/block-editor/src/components/global-styles/use-global-styles-context.native.js @@ -410,6 +410,9 @@ export function getColorsAndGradients( return { __experimentalGlobalStylesBaseStyles: null, __experimentalFeatures: { + // Set an empty object to avoid errors from shared web components relying + // upon block settings. E.g., the Gallery block. + blocks: {}, color: { ...( ! features?.color ? { @@ -455,6 +458,9 @@ export function getGlobalStyles( rawStyles, rawFeatures ) { return { __experimentalFeatures: { + // Set an empty object to avoid errors from shared web components relying + // upon block settings. E.g., the Gallery block. + blocks: {}, color: { palette: colors?.palette, gradients, diff --git a/packages/block-library/src/gallery/constants.js b/packages/block-library/src/gallery/constants.js index f4a0691439313..19fc61cac8458 100644 --- a/packages/block-library/src/gallery/constants.js +++ b/packages/block-library/src/gallery/constants.js @@ -1,5 +1,6 @@ export const LINK_DESTINATION_NONE = 'none'; export const LINK_DESTINATION_MEDIA = 'media'; +export const LINK_DESTINATION_LIGHTBOX = 'lightbox'; export const LINK_DESTINATION_ATTACHMENT = 'attachment'; export const LINK_DESTINATION_MEDIA_WP_CORE = 'file'; export const LINK_DESTINATION_ATTACHMENT_WP_CORE = 'post'; diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index c73fe1977ce4c..7a0cc1de53c38 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -25,6 +25,7 @@ import { useInnerBlocksProps, BlockControls, MediaReplaceFlow, + useSettings, } from '@wordpress/block-editor'; import { Platform, useEffect, useMemo } from '@wordpress/element'; import { __, _x, sprintf } from '@wordpress/i18n'; @@ -38,6 +39,7 @@ import { customLink, image as imageIcon, linkOff, + fullscreen, } from '@wordpress/icons'; /** @@ -55,6 +57,7 @@ import { LINK_DESTINATION_ATTACHMENT, LINK_DESTINATION_MEDIA, LINK_DESTINATION_NONE, + LINK_DESTINATION_LIGHTBOX, } from './constants'; import useImageSizes from './use-image-sizes'; import useGetNewImages from './use-get-new-images'; @@ -62,7 +65,7 @@ import useGetMedia from './use-get-media'; import GapStyles from './gap-styles'; const MAX_COLUMNS = 8; -const linkOptions = [ +let linkOptions = [ { icon: customLink, label: __( 'Link images to attachment pages' ), @@ -75,6 +78,13 @@ const linkOptions = [ value: LINK_DESTINATION_MEDIA, noticeText: __( 'Media Files' ), }, + { + icon: fullscreen, + label: __( 'Expand on click' ), + value: LINK_DESTINATION_LIGHTBOX, + noticeText: __( 'Lightbox effect' ), + infoText: __( 'Scale images with a lightbox effect' ), + }, { icon: linkOff, label: _x( 'None', 'Media item link option' ), @@ -107,6 +117,14 @@ export default function GalleryEdit( props ) { onFocus, } = props; + const lightboxSetting = useSettings( 'blocks.core/image.lightbox' )[ 0 ]; + + if ( ! lightboxSetting?.allowEditing ) { + linkOptions = linkOptions.filter( + ( option ) => option.value !== LINK_DESTINATION_LIGHTBOX + ); + } + const { columns, imageCrop, randomOrder, linkTarget, linkTo, sizeSlug } = attributes; @@ -363,9 +381,13 @@ export default function GalleryEdit( props ) { const image = block.attributes.id ? imageData.find( ( { id } ) => id === block.attributes.id ) : null; + changedAttributes[ block.clientId ] = getHrefAndDestination( image, - value + value, + false, + block.attributes, + lightboxSetting ); } ); updateBlockAttributes( blocks, changedAttributes, true ); @@ -646,6 +668,7 @@ export default function GalleryEdit( props ) { onClose(); } } role="menuitemradio" + info={ linkItem.infoText } > { linkItem.label } diff --git a/packages/block-library/src/gallery/utils.js b/packages/block-library/src/gallery/utils.js index 15f2062ea943d..4b2aca81f6ffb 100644 --- a/packages/block-library/src/gallery/utils.js +++ b/packages/block-library/src/gallery/utils.js @@ -7,6 +7,7 @@ import { LINK_DESTINATION_NONE, LINK_DESTINATION_MEDIA_WP_CORE, LINK_DESTINATION_ATTACHMENT_WP_CORE, + LINK_DESTINATION_LIGHTBOX, } from './constants'; import { LINK_DESTINATION_ATTACHMENT as IMAGE_LINK_DESTINATION_ATTACHMENT, @@ -20,13 +21,18 @@ import { * * @param {Object} image Gallery image. * @param {string} galleryDestination Gallery's selected link destination. - * @param {Object} imageDestination Image blocks attributes. + * @param {Object} imageDestination Image block link destination attribute. + * @param {Object} attributes Block attributes. + * @param {Object} lightboxSetting Lightbox setting. + * * @return {Object} New attributes to assign to image block. */ export function getHrefAndDestination( image, galleryDestination, - imageDestination + imageDestination, + attributes, + lightboxSetting ) { // Gutenberg and WordPress use different constants so if image_default_link_type // option is set we need to map from the WP Core values. @@ -36,17 +42,32 @@ export function getHrefAndDestination( return { href: image?.source_url || image?.url, // eslint-disable-line camelcase linkDestination: IMAGE_LINK_DESTINATION_MEDIA, + lightbox: lightboxSetting?.enabled + ? { ...attributes?.lightbox, enabled: false } + : undefined, }; case LINK_DESTINATION_ATTACHMENT_WP_CORE: case LINK_DESTINATION_ATTACHMENT: return { href: image?.link, linkDestination: IMAGE_LINK_DESTINATION_ATTACHMENT, + lightbox: lightboxSetting?.enabled + ? { ...attributes?.lightbox, enabled: false } + : undefined, + }; + case LINK_DESTINATION_LIGHTBOX: + return { + href: undefined, + lightbox: ! lightboxSetting?.enabled + ? { ...attributes?.lightbox, enabled: true } + : undefined, + linkDestination: IMAGE_LINK_DESTINATION_NONE, }; case LINK_DESTINATION_NONE: return { href: undefined, linkDestination: IMAGE_LINK_DESTINATION_NONE, + lightbox: undefined, }; }