@wordpress/block-library
Version:
Block library for the WordPress editor.
30 lines (29 loc) • 1.22 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_data = require("@wordpress/data");
let _wordpress_core_data = require("@wordpress/core-data");
// packages/block-library/src/gallery/use-get-media.js
const EMPTY_IMAGE_MEDIA = [];
/**
* Retrieves the extended media info for each gallery image from the store. This is used to
* determine which image size options are available for the current gallery.
*
* @param {Array} innerBlockImages An array of the innerBlock images currently in the gallery.
*
* @return {Array} An array of media info options for each gallery image.
*/
function useGetMedia(innerBlockImages) {
return (0, _wordpress_data.useSelect)((select) => {
const imageIds = innerBlockImages.map((imageBlock) => imageBlock.attributes.id).filter((id) => id !== void 0).sort((a, b) => a - b);
if (imageIds.length === 0) return EMPTY_IMAGE_MEDIA;
return select(_wordpress_core_data.store).getEntityRecords("postType", "attachment", {
include: imageIds.join(","),
per_page: -1
}) ?? EMPTY_IMAGE_MEDIA;
}, [innerBlockImages]);
}
exports.default = useGetMedia;
//# sourceMappingURL=use-get-media.cjs.map