UNPKG

@wordpress/block-library

Version:
73 lines (57 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultColumnsNumber = defaultColumnsNumber; exports.isGalleryV2Enabled = isGalleryV2Enabled; exports.pickRelevantMediaFiles = void 0; var _lodash = require("lodash"); var _element = require("@wordpress/element"); /** * External dependencies */ /** * WordPress dependencies */ function defaultColumnsNumber(imageCount) { return imageCount ? Math.min(3, imageCount) : 3; } const pickRelevantMediaFiles = function (image) { let sizeSlug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'large'; const imageProps = (0, _lodash.pick)(image, ['alt', 'id', 'link']); imageProps.url = (0, _lodash.get)(image, ['sizes', sizeSlug, 'url']) || (0, _lodash.get)(image, ['media_details', 'sizes', sizeSlug, 'source_url']) || image.url || image.source_url; const fullUrl = (0, _lodash.get)(image, ['sizes', 'full', 'url']) || (0, _lodash.get)(image, ['media_details', 'sizes', 'full', 'source_url']); if (fullUrl) { imageProps.fullUrl = fullUrl; } return imageProps; }; exports.pickRelevantMediaFiles = pickRelevantMediaFiles; 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. */ function isGalleryV2Enabled() { // The logic for the native version is located in a different if statement // due to a lint rule that prohibits a single conditional combining // `process.env.IS_GUTENBERG_PLUGIN` with a native platform check. if (_element.Platform.isNative) { return getGalleryBlockV2Enabled(); } // Only run the Gallery version compat check if the plugin is running, otherwise // assume we are in 5.9 core and enable by default. if (process.env.IS_GUTENBERG_PLUGIN) { return getGalleryBlockV2Enabled(); } return true; } //# sourceMappingURL=shared.js.map