Skip to content

Commit eb74cf5

Browse files
youknowriadgeriux
and
geriux
authored
Gallery Block: Cleanup v1 code (#63285)
Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: geriux <geriux@git.wordpress.org>
1 parent 1b6ac9e commit eb74cf5

34 files changed

+71
-2052
lines changed

packages/block-editor/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ _Properties_
780780
- _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory
781781
- _\_\_experimentalBlockPatterns_ `Array`: Array of objects representing the block patterns
782782
- _\_\_experimentalBlockPatternCategories_ `Array`: Array of objects representing the block pattern categories
783-
- _\_\_unstableGalleryWithImageBlocks_ `boolean`: Whether the user has enabled the refactored gallery block which uses InnerBlocks
784783

785784
### SkipToSelectedBlock
786785

packages/block-editor/src/store/defaults.js

-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const PREFERENCES_DEFAULTS = {
3333
* @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory
3434
* @property {Array} __experimentalBlockPatterns Array of objects representing the block patterns
3535
* @property {Array} __experimentalBlockPatternCategories Array of objects representing the block pattern categories
36-
* @property {boolean} __unstableGalleryWithImageBlocks Whether the user has enabled the refactored gallery block which uses InnerBlocks
3736
*/
3837
export const SETTINGS_DEFAULTS = {
3938
alignWide: false,
@@ -168,7 +167,6 @@ export const SETTINGS_DEFAULTS = {
168167
__mobileEnablePageTemplates: false,
169168
__experimentalBlockPatterns: [],
170169
__experimentalBlockPatternCategories: [],
171-
__unstableGalleryWithImageBlocks: false,
172170
__unstableIsPreviewMode: false,
173171

174172
// These settings will be completely revamped in the future.

packages/block-editor/src/store/defaults.native.js

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ const SETTINGS_DEFAULTS = {
1010
...SETTINGS,
1111
// Don't add the default font sizes for standard themes
1212
fontSizes: undefined,
13-
// FOR TESTING ONLY - Later, this will come from a REST API
14-
// eslint-disable-next-line no-undef
15-
__unstableGalleryWithImageBlocks: __DEV__,
1613
alignWide: true,
1714
supportsLayout: false,
1815
__experimentalFeatures: {

packages/block-library/src/gallery/deprecated.js

+6-55
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
LINK_DESTINATION_MEDIA,
2323
LINK_DESTINATION_NONE,
2424
} from './constants';
25-
import { isGalleryV2Enabled } from './shared';
2625

2726
const DEPRECATED_LINK_DESTINATION_MEDIA = 'file';
2827
const DEPRECATED_LINK_DESTINATION_ATTACHMENT = 'post';
@@ -408,11 +407,7 @@ const v6 = {
408407
);
409408
},
410409
migrate( attributes ) {
411-
if ( isGalleryV2Enabled() ) {
412-
return runV2Migration( attributes );
413-
}
414-
415-
return attributes;
410+
return runV2Migration( attributes );
416411
},
417412
};
418413
const v5 = {
@@ -498,23 +493,7 @@ const v5 = {
498493
return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
499494
},
500495
migrate( attributes ) {
501-
if ( isGalleryV2Enabled() ) {
502-
return runV2Migration( attributes );
503-
}
504-
505-
let linkTo = attributes.linkTo;
506-
507-
if ( ! attributes.linkTo ) {
508-
linkTo = 'none';
509-
} else if ( attributes.linkTo === 'attachment' ) {
510-
linkTo = 'post';
511-
} else if ( attributes.linkTo === 'media' ) {
512-
linkTo = 'file';
513-
}
514-
return {
515-
...attributes,
516-
linkTo,
517-
};
496+
return runV2Migration( attributes );
518497
},
519498
save( { attributes } ) {
520499
const {
@@ -661,17 +640,7 @@ const v4 = {
661640
return ids && ids.some( ( id ) => typeof id === 'string' );
662641
},
663642
migrate( attributes ) {
664-
if ( isGalleryV2Enabled() ) {
665-
return runV2Migration( attributes );
666-
}
667-
668-
return {
669-
...attributes,
670-
ids: ( attributes.ids ?? [] ).map( ( id ) => {
671-
const parsedId = parseInt( id, 10 );
672-
return Number.isInteger( parsedId ) ? parsedId : null;
673-
} ),
674-
};
643+
return runV2Migration( attributes );
675644
},
676645
save( { attributes } ) {
677646
const {
@@ -867,10 +836,7 @@ const v3 = {
867836
);
868837
},
869838
migrate( attributes ) {
870-
if ( isGalleryV2Enabled() ) {
871-
return runV2Migration( attributes );
872-
}
873-
return attributes;
839+
return runV2Migration( attributes );
874840
},
875841
};
876842
const v2 = {
@@ -936,18 +902,7 @@ const v2 = {
936902
);
937903
},
938904
migrate( attributes ) {
939-
if ( isGalleryV2Enabled() ) {
940-
return runV2Migration( attributes );
941-
}
942-
return {
943-
...attributes,
944-
ids: ( attributes.images ?? [] ).map( ( { id } ) => {
945-
if ( ! id ) {
946-
return null;
947-
}
948-
return parseInt( id, 10 );
949-
} ),
950-
};
905+
return runV2Migration( attributes );
951906
},
952907
supports: {
953908
align: true,
@@ -1100,11 +1055,7 @@ const v1 = {
11001055
);
11011056
},
11021057
migrate( attributes ) {
1103-
if ( isGalleryV2Enabled() ) {
1104-
return runV2Migration( attributes );
1105-
}
1106-
1107-
return attributes;
1058+
return runV2Migration( attributes );
11081059
},
11091060
};
11101061

packages/block-library/src/gallery/edit-wrapper.js

-27
This file was deleted.

packages/block-library/src/gallery/edit.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ToggleControl,
1515
RangeControl,
1616
Spinner,
17+
withNotices,
1718
} from '@wordpress/components';
1819
import {
1920
store as blockEditorStore,
@@ -633,6 +634,7 @@ function GalleryEdit( props ) {
633634
</>
634635
);
635636
}
636-
export default compose( [ withViewportMatch( { isNarrow: '< small' } ) ] )(
637-
GalleryEdit
638-
);
637+
export default compose( [
638+
withNotices,
639+
withViewportMatch( { isNarrow: '< small' } ),
640+
] )( GalleryEdit );

packages/block-library/src/gallery/gallery-styles.native.scss

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import "./v1/gallery-styles.native.scss";
2-
31
.galleryAppender {
42
padding-top: $grid-unit-20;
53
}

packages/block-library/src/gallery/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { gallery as icon } from '@wordpress/icons';
88
*/
99
import initBlock from '../utils/init-block';
1010
import deprecated from './deprecated';
11-
import edit from './edit-wrapper';
11+
import edit from './edit';
1212
import metadata from './block.json';
1313
import save from './save';
1414
import transforms from './transforms';

packages/block-library/src/gallery/save.js

-10
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@ import {
1313
__experimentalGetElementClassName,
1414
} from '@wordpress/block-editor';
1515

16-
/**
17-
* Internal dependencies
18-
*/
19-
import saveWithoutInnerBlocks from './v1/save';
20-
import { isGalleryV2Enabled } from './shared';
21-
2216
export default function saveWithInnerBlocks( { attributes } ) {
23-
if ( ! isGalleryV2Enabled() ) {
24-
return saveWithoutInnerBlocks( { attributes } );
25-
}
26-
2717
const { caption, columns, imageCrop } = attributes;
2818

2919
const className = clsx( 'has-nested-images', {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* WordPress dependencies
3-
*/
4-
import { Platform } from '@wordpress/element';
5-
61
export function defaultColumnsNumber( imageCount ) {
72
return imageCount ? Math.min( 3, imageCount ) : 3;
83
}
@@ -27,26 +22,3 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
2722
}
2823
return imageProps;
2924
};
30-
31-
function getGalleryBlockV2Enabled() {
32-
// We want to fail early here, at least during beta testing phase, to ensure
33-
// there aren't instances where undefined values cause false negatives.
34-
if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) {
35-
throw 'window.wp.galleryBlockV2Enabled is not defined';
36-
}
37-
return window.wp.galleryBlockV2Enabled;
38-
}
39-
40-
/**
41-
* The new gallery block format is not compatible with the use_BalanceTags option
42-
* in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
43-
* window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
44-
* can be removed when minimum supported WP version >=5.9.
45-
*/
46-
export function isGalleryV2Enabled() {
47-
if ( Platform.isNative ) {
48-
return getGalleryBlockV2Enabled();
49-
}
50-
51-
return true;
52-
}

0 commit comments

Comments
 (0)