Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af87cc0
Update experimental flag to block sites with use_BalanceTags option e…
Nov 4, 2021
09077a8
Remove update gallery modal
Nov 29, 2021
69b0899
Add check for gallery v2 compat to editor init so it is available whe…
Nov 5, 2021
ea46fd4
Remove references to gallery experimental flag
Nov 5, 2021
d1743b6
Revert "Remove references to gallery experimental flag"
Nov 9, 2021
cba6433
Abstract out the check for v2 gallery support and use the existing ex…
Nov 10, 2021
6e6e643
Add missing transformation updates
Nov 10, 2021
5e8db76
Update fixture to be compat with v2 of gallery block
Nov 10, 2021
40af59f
Fix unit tests
Nov 10, 2021
f5bed90
Fix issue with link destination not being set when block migrated
Nov 11, 2021
6cbc1f7
Check that we have a v1 gallery block before we send content through …
Nov 16, 2021
e79cdbe
Use `window.wp` global instead of store for gallery flag
mkevins Nov 16, 2021
857d01b
Remove unnecessary destructuring
mkevins Nov 16, 2021
970f717
Move the setting of wp.galleryBlockV2Enabled to directly after wp-dom…
Nov 16, 2021
2054a31
Add optional chaining operator to prevent error if images attribute n…
Nov 17, 2021
3b416e8
Simplify deprecations, etc. by always using using v1 methods if use_b…
Nov 17, 2021
d191bcb
Fix potential issue with attributes not being returned from v6 deprec…
Nov 17, 2021
7700d5c
Move assignment of gallery global flag to native Editor
mkevins Nov 19, 2021
9f06d77
Move mocking of the galleryBlockV2Enabled flag to the jest globals file
Nov 21, 2021
9774355
Explicitly check for galleryBlockV2Enabled being false and default to…
Nov 21, 2021
5bc1aa2
Fail early if window.wp.galleryBlockV2Enabled is not a boolean
Nov 22, 2021
de9d187
Default to `true` for gallery flag when not yet cached
mkevins Nov 23, 2021
9504e11
Only update gallery flag if fetch result is explicitly boolean
mkevins Nov 24, 2021
a6bfee5
Update editor settings response to the editor to include gallery flag
mkevins Nov 24, 2021
f2df281
Leave gallery flag `undefined` when not cached
mkevins Nov 25, 2021
2226e57
Update the wording of the mobile warning
Nov 28, 2021
06b540c
Add filter to prevent use_balanceTags being enabled on WP < 5.9
Nov 29, 2021
ad7ec30
Switch to using settings_error for use_balanceTags notice
Nov 29, 2021
cff2300
Add a CLI error message
Nov 29, 2021
c752d64
Fix linting error
Nov 29, 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
Prev Previous commit
Next Next commit
Abstract out the check for v2 gallery support and use the existing ex…
…perimental flag for mobile
  • Loading branch information
Glen Davies committed Nov 30, 2021
commit cba6433b14ee57019aaa7cc8f7654a9c9ab3079e
13 changes: 7 additions & 6 deletions packages/block-library/src/gallery/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
LINK_DESTINATION_MEDIA,
LINK_DESTINATION_NONE,
} from './constants';
import { isGalleryV2Enabled } from './shared';

const DEPRECATED_LINK_DESTINATION_MEDIA = 'file';
const DEPRECATED_LINK_DESTINATION_ATTACHMENT = 'post';
Expand Down Expand Up @@ -280,7 +281,7 @@ const v6 = {
);
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

Expand Down Expand Up @@ -370,7 +371,7 @@ const v5 = {
return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

Expand Down Expand Up @@ -533,7 +534,7 @@ const v4 = {
return ids && ids.some( ( id ) => typeof id === 'string' );
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

Expand Down Expand Up @@ -739,7 +740,7 @@ const v3 = {
);
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
},
Expand Down Expand Up @@ -807,7 +808,7 @@ const v2 = {
);
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
return {
Expand Down Expand Up @@ -971,7 +972,7 @@ const v1 = {
);
},
migrate( attributes ) {
if ( window.wp.galleryBlockV2Enabled ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

Expand Down
8 changes: 2 additions & 6 deletions packages/block-library/src/gallery/edit-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSelect } from '@wordpress/data';
*/
import EditWithInnerBlocks from './edit';
import EditWithoutInnerBlocks from './v1/edit';
import { isGalleryV2Enabled } from './shared';

/*
* Using a wrapper around the logic to load the edit for v1 of Gallery block
Expand All @@ -25,11 +26,6 @@ export default function GalleryEditWrapper( props ) {
[ clientId ]
);

const __unstableGalleryWithImageBlocks = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
return settings.__unstableGalleryWithImageBlocks;
}, [] );

// This logic is used to infer version information from content with higher
// precedence than the flag. New galleries (and existing empty galleries) will
// honor the flag.
Expand All @@ -38,7 +34,7 @@ export default function GalleryEditWrapper( props ) {
0 < attributes?.ids?.length || 0 < attributes?.images?.length;
if (
hasOldVersionContent ||
( ! hasNewVersionContent && ! __unstableGalleryWithImageBlocks )
( ! hasNewVersionContent && ! isGalleryV2Enabled() )
) {
return <EditWithoutInnerBlocks { ...props } />;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/gallery/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {
* Internal dependencies
*/
import saveWithoutInnerBlocks from './v1/save';
import { isGalleryV2Enabled } from './shared';

export default function saveWithInnerBlocks( { attributes } ) {
if ( ! window.wp.galleryBlockV2Enabled ) {
if ( ! isGalleryV2Enabled() ) {
return saveWithoutInnerBlocks( { attributes } );
}

Expand Down
20 changes: 20 additions & 0 deletions packages/block-library/src/gallery/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
*/
import { get, pick } from 'lodash';

/**
* WordPress dependencies
*/
import { Platform } from '@wordpress/element';
import { select } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

export function defaultColumnsNumber( imageCount ) {
return imageCount ? Math.min( 3, imageCount ) : 3;
}
Expand All @@ -21,3 +28,16 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
}
return imageProps;
};

export function isGalleryV2Enabled() {
if ( Platform.isWeb && window.wp.galleryBlockV2Enabled ) {
return true;
}

const settings = select( blockEditorStore ).getSettings();
if ( settings.__unstableGalleryWithImageBlocks ) {
return true;
}

return false;
}
28 changes: 7 additions & 21 deletions packages/block-library/src/gallery/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
LINK_DESTINATION_ATTACHMENT as DEPRECATED_LINK_DESTINATION_ATTACHMENT,
LINK_DESTINATION_MEDIA as DEPRECATED_LINK_DESTINATION_MEDIA,
} from './v1/constants';
import { pickRelevantMediaFiles } from './shared';
import { pickRelevantMediaFiles, isGalleryV2Enabled } from './shared';

const parseShortcodeIds = ( ids ) => {
if ( ! ids ) {
Expand All @@ -49,9 +49,8 @@ const parseShortcodeIds = ( ids ) => {
* @return {Block} The transformed block.
*/
function updateThirdPartyTransformToGallery( block ) {
const settings = select( blockEditorStore ).getSettings();
if (
settings.__unstableGalleryWithImageBlocks &&
isGalleryV2Enabled() &&
block.name === 'core/gallery' &&
block.attributes?.images.length > 0
) {
Expand Down Expand Up @@ -145,8 +144,7 @@ const transforms = {

const validImages = filter( attributes, ( { url } ) => url );

const settings = select( blockEditorStore ).getSettings();
if ( settings.__unstableGalleryWithImageBlocks ) {
if ( isGalleryV2Enabled() ) {
const innerBlocks = validImages.map( ( image ) => {
return createBlock( 'core/image', image );
} );
Expand Down Expand Up @@ -184,10 +182,7 @@ const transforms = {
images: {
type: 'array',
shortcode: ( { named: { ids } } ) => {
const settings = select(
blockEditorStore
).getSettings();
if ( ! settings.__unstableGalleryWithImageBlocks ) {
if ( ! isGalleryV2Enabled() ) {
return parseShortcodeIds( ids ).map( ( id ) => ( {
id: toString( id ),
} ) );
Expand All @@ -197,21 +192,15 @@ const transforms = {
ids: {
type: 'array',
shortcode: ( { named: { ids } } ) => {
const settings = select(
blockEditorStore
).getSettings();
if ( ! settings.__unstableGalleryWithImageBlocks ) {
if ( ! isGalleryV2Enabled() ) {
return parseShortcodeIds( ids );
}
},
},
shortCodeTransforms: {
type: 'array',
shortcode: ( { named: { ids } } ) => {
const settings = select(
blockEditorStore
).getSettings();
if ( settings.__unstableGalleryWithImageBlocks ) {
if ( isGalleryV2Enabled() ) {
return parseShortcodeIds( ids ).map( ( id ) => ( {
id: parseInt( id ),
} ) );
Expand All @@ -227,10 +216,7 @@ const transforms = {
linkTo: {
type: 'string',
shortcode: ( { named: { link } } ) => {
const settings = select(
blockEditorStore
).getSettings();
if ( ! settings.__unstableGalleryWithImageBlocks ) {
if ( ! isGalleryV2Enabled() ) {
switch ( link ) {
case 'post':
return DEPRECATED_LINK_DESTINATION_ATTACHMENT;
Expand Down