@wordpress/block-library
Version:
Block library for the WordPress editor.
62 lines (61 loc) • 3.47 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let _wordpress_global_styles_engine = require("@wordpress/global-styles-engine");
let ___lock_unlock_ts = require("../lock-unlock.cjs");
let __responsive_styles_js = require("./responsive-styles.cjs");
// packages/block-library/src/gallery/gallery-styles.js
const { getResponsiveMediaQueries } = (0, ___lock_unlock_ts.unlock)(_wordpress_global_styles_engine.privateApis);
const { globalStylesDataKey } = (0, ___lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis);
const GALLERY_BLOCK_NAME = "core/gallery";
const FALLBACK_VALUE = `var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )`;
function getGalleryGapCustomPropertyStyle(selector, blockGap) {
let column = FALLBACK_VALUE;
if (blockGap) column = typeof blockGap === "string" ? (0, _wordpress_block_editor.__experimentalGetGapCSSValue)(blockGap) || FALLBACK_VALUE : (0, _wordpress_block_editor.__experimentalGetGapCSSValue)(blockGap?.left) || FALLBACK_VALUE;
return `${selector} {
--wp--style--unstable-gallery-gap: ${column === "0" ? "0px" : column}
}`;
}
function getBlockGapValue(style) {
if (!Object.hasOwn(style?.spacing || {}, "blockGap")) return;
return style.spacing.blockGap;
}
/**
* Renders the Gallery's instance styles: the gap custom property the Flex
* layout's column widths are calculated from, and the Gallery's responsive
* viewport CSS.
*
* @param {Object} props
* @param {Object} props.style Gallery block style attribute.
* @param {string} props.clientId Gallery block client ID.
* @param {boolean} props.isFlexLayout Whether the Gallery uses the Flex layout.
*/
function GalleryStyles({ style, clientId, isFlexLayout }) {
const selector = `.wp-block-gallery-${clientId}`;
const [viewportSettings] = (0, _wordpress_block_editor.useSettings)("viewport");
const globalStyles = (0, _wordpress_data.useSelect)((select) => select(_wordpress_block_editor.store).getSettings()?.[globalStylesDataKey], []);
const responsiveMediaQueries = getResponsiveMediaQueries(viewportSettings);
let css = "";
if (isFlexLayout) {
const globalGalleryStyles = globalStyles?.blocks?.[GALLERY_BLOCK_NAME] || {};
const styleBlockGap = getBlockGapValue(style);
const globalGalleryBlockGap = globalGalleryStyles?.spacing?.blockGap ?? FALLBACK_VALUE;
css += getGalleryGapCustomPropertyStyle(selector, styleBlockGap === void 0 ? globalGalleryBlockGap : styleBlockGap);
Object.entries(responsiveMediaQueries).forEach(([viewport, mediaQuery]) => {
const styleViewportBlockGap = getBlockGapValue(style?.[viewport]);
const globalViewportBlockGap = styleBlockGap === void 0 ? globalGalleryStyles?.[viewport]?.spacing?.blockGap : void 0;
const viewportBlockGap = styleViewportBlockGap === void 0 ? globalViewportBlockGap : styleViewportBlockGap;
if (viewportBlockGap === void 0 || viewportBlockGap === null) return;
css += `${mediaQuery}{${getGalleryGapCustomPropertyStyle(selector, viewportBlockGap)}}`;
});
}
css += (0, __responsive_styles_js.getGalleryResponsiveCSS)(selector, style, responsiveMediaQueries);
(0, _wordpress_block_editor.useStyleOverride)({ css });
return null;
}
exports.default = GalleryStyles;
//# sourceMappingURL=gallery-styles.cjs.map