@wordpress/block-library
Version:
Block library for the WordPress editor.
32 lines (31 loc) • 1.09 kB
JavaScript
// packages/block-library/src/gallery/shared.js
function defaultColumnsNumber(imageCount) {
return imageCount ? Math.min(3, imageCount) : 3;
}
function isObject(value) {
return !!value && typeof value === "object" && !Array.isArray(value);
}
function isGalleryFlexLayout(layout) {
const layoutType = isObject(layout) ? layout.type : void 0;
return typeof layoutType !== "string" || layoutType === "" || layoutType === "flex";
}
var pickRelevantMediaFiles = (image, sizeSlug = "large") => {
const imageProps = Object.fromEntries(
Object.entries(image ?? {}).filter(
([key]) => ["alt", "id", "link"].includes(key)
)
);
imageProps.url = image?.sizes?.[sizeSlug]?.url || image?.media_details?.sizes?.[sizeSlug]?.source_url || image?.url || image?.source_url;
const fullUrl = image?.sizes?.full?.url || image?.media_details?.sizes?.full?.source_url;
if (fullUrl) {
imageProps.fullUrl = fullUrl;
}
return imageProps;
};
export {
defaultColumnsNumber,
isGalleryFlexLayout,
isObject,
pickRelevantMediaFiles
};
//# sourceMappingURL=shared.mjs.map