33 */
44import { get , pick } from 'lodash' ;
55
6+ /**
7+ * WordPress dependencies
8+ */
9+ import { Platform } from '@wordpress/element' ;
10+
611export function defaultColumnsNumber ( imageCount ) {
712 return imageCount ? Math . min ( 3 , imageCount ) : 3 ;
813}
@@ -22,25 +27,33 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
2227 return imageProps ;
2328} ;
2429
30+ function getGalleryBlockV2Enabled ( ) {
31+ // We want to fail early here, at least during beta testing phase, to ensure
32+ // there aren't instances where undefined values cause false negatives.
33+ if ( ! window . wp || typeof window . wp . galleryBlockV2Enabled !== 'boolean' ) {
34+ throw 'window.wp.galleryBlockV2Enabled is not defined' ;
35+ }
36+ return window . wp . galleryBlockV2Enabled ;
37+ }
38+
2539/**
2640 * The new gallery block format is not compatible with the use_BalanceTags option
2741 * in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
2842 * window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
2943 * can be removed when minimum supported WP version >=5.9.
3044 */
3145export function isGalleryV2Enabled ( ) {
46+ // The logic for the native version is located in a different if statement
47+ // due to a lint rule that prohibits a single conditional combining
48+ // `process.env.IS_GUTENBERG_PLUGIN` with a native platform check.
49+ if ( Platform . isNative ) {
50+ return getGalleryBlockV2Enabled ( ) ;
51+ }
52+
3253 // Only run the Gallery version compat check if the plugin is running, otherwise
3354 // assume we are in 5.9 core and enable by default.
3455 if ( process . env . IS_GUTENBERG_PLUGIN ) {
35- // We want to fail early here, at least during beta testing phase, to ensure
36- // there aren't instances where undefined values cause false negatives.
37- if (
38- ! window . wp ||
39- typeof window . wp . galleryBlockV2Enabled !== 'boolean'
40- ) {
41- throw 'window.wp.galleryBlockV2Enabled is not defined' ;
42- }
43- return window . wp . galleryBlockV2Enabled ;
56+ return getGalleryBlockV2Enabled ( ) ;
4457 }
4558
4659 return true ;
0 commit comments