Skip to content

Commit

Permalink
Gallery Block: Cleanup v1 code (WordPress#63285)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: geriux <geriux@git.wordpress.org>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent 1b6ac9e commit eb74cf5
Show file tree
Hide file tree
Showing 34 changed files with 71 additions and 2,052 deletions.
1 change: 0 additions & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ _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
- _\_\_unstableGalleryWithImageBlocks_ `boolean`: Whether the user has enabled the refactored gallery block which uses InnerBlocks

### SkipToSelectedBlock

Expand Down
2 changes: 0 additions & 2 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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} __unstableGalleryWithImageBlocks Whether the user has enabled the refactored gallery block which uses InnerBlocks
*/
export const SETTINGS_DEFAULTS = {
alignWide: false,
Expand Down Expand Up @@ -168,7 +167,6 @@ export const SETTINGS_DEFAULTS = {
__mobileEnablePageTemplates: false,
__experimentalBlockPatterns: [],
__experimentalBlockPatternCategories: [],
__unstableGalleryWithImageBlocks: false,
__unstableIsPreviewMode: false,

// These settings will be completely revamped in the future.
Expand Down
3 changes: 0 additions & 3 deletions packages/block-editor/src/store/defaults.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const SETTINGS_DEFAULTS = {
...SETTINGS,
// Don't add the default font sizes for standard themes
fontSizes: undefined,
// FOR TESTING ONLY - Later, this will come from a REST API
// eslint-disable-next-line no-undef
__unstableGalleryWithImageBlocks: __DEV__,
alignWide: true,
supportsLayout: false,
__experimentalFeatures: {
Expand Down
61 changes: 6 additions & 55 deletions packages/block-library/src/gallery/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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 @@ -408,11 +407,7 @@ const v6 = {
);
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return attributes;
return runV2Migration( attributes );
},
};
const v5 = {
Expand Down Expand Up @@ -498,23 +493,7 @@ const v5 = {
return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

let linkTo = attributes.linkTo;

if ( ! attributes.linkTo ) {
linkTo = 'none';
} else if ( attributes.linkTo === 'attachment' ) {
linkTo = 'post';
} else if ( attributes.linkTo === 'media' ) {
linkTo = 'file';
}
return {
...attributes,
linkTo,
};
return runV2Migration( attributes );
},
save( { attributes } ) {
const {
Expand Down Expand Up @@ -661,17 +640,7 @@ const v4 = {
return ids && ids.some( ( id ) => typeof id === 'string' );
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return {
...attributes,
ids: ( attributes.ids ?? [] ).map( ( id ) => {
const parsedId = parseInt( id, 10 );
return Number.isInteger( parsedId ) ? parsedId : null;
} ),
};
return runV2Migration( attributes );
},
save( { attributes } ) {
const {
Expand Down Expand Up @@ -867,10 +836,7 @@ const v3 = {
);
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
return attributes;
return runV2Migration( attributes );
},
};
const v2 = {
Expand Down Expand Up @@ -936,18 +902,7 @@ const v2 = {
);
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
return {
...attributes,
ids: ( attributes.images ?? [] ).map( ( { id } ) => {
if ( ! id ) {
return null;
}
return parseInt( id, 10 );
} ),
};
return runV2Migration( attributes );
},
supports: {
align: true,
Expand Down Expand Up @@ -1100,11 +1055,7 @@ const v1 = {
);
},
migrate( attributes ) {
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return attributes;
return runV2Migration( attributes );
},
};

Expand Down
27 changes: 0 additions & 27 deletions packages/block-library/src/gallery/edit-wrapper.js

This file was deleted.

8 changes: 5 additions & 3 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ToggleControl,
RangeControl,
Spinner,
withNotices,
} from '@wordpress/components';
import {
store as blockEditorStore,
Expand Down Expand Up @@ -633,6 +634,7 @@ function GalleryEdit( props ) {
</>
);
}
export default compose( [ withViewportMatch( { isNarrow: '< small' } ) ] )(
GalleryEdit
);
export default compose( [
withNotices,
withViewportMatch( { isNarrow: '< small' } ),
] )( GalleryEdit );
2 changes: 0 additions & 2 deletions packages/block-library/src/gallery/gallery-styles.native.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "./v1/gallery-styles.native.scss";

.galleryAppender {
padding-top: $grid-unit-20;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { gallery as icon } from '@wordpress/icons';
*/
import initBlock from '../utils/init-block';
import deprecated from './deprecated';
import edit from './edit-wrapper';
import edit from './edit';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';
Expand Down
10 changes: 0 additions & 10 deletions packages/block-library/src/gallery/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ import {
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import saveWithoutInnerBlocks from './v1/save';
import { isGalleryV2Enabled } from './shared';

export default function saveWithInnerBlocks( { attributes } ) {
if ( ! isGalleryV2Enabled() ) {
return saveWithoutInnerBlocks( { attributes } );
}

const { caption, columns, imageCrop } = attributes;

const className = clsx( 'has-nested-images', {
Expand Down
28 changes: 0 additions & 28 deletions packages/block-library/src/gallery/shared.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { Platform } from '@wordpress/element';

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

function getGalleryBlockV2Enabled() {
// We want to fail early here, at least during beta testing phase, to ensure
// there aren't instances where undefined values cause false negatives.
if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) {
throw 'window.wp.galleryBlockV2Enabled is not defined';
}
return window.wp.galleryBlockV2Enabled;
}

/**
* The new gallery block format is not compatible with the use_BalanceTags option
* in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
* window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
* can be removed when minimum supported WP version >=5.9.
*/
export function isGalleryV2Enabled() {
if ( Platform.isNative ) {
return getGalleryBlockV2Enabled();
}

return true;
}
Loading

0 comments on commit eb74cf5

Please sign in to comment.