@wordpress/block-library
Version:
Block library for the WordPress editor.
29 lines (28 loc) • 809 B
JavaScript
// packages/block-library/src/gallery/use-get-media.js
import { useSelect } from "@wordpress/data";
import { store as coreStore } from "@wordpress/core-data";
var EMPTY_IMAGE_MEDIA = [];
function useGetMedia(innerBlockImages) {
return useSelect(
(select) => {
const imageIds = innerBlockImages.map((imageBlock) => imageBlock.attributes.id).filter((id) => id !== void 0);
if (imageIds.length === 0) {
return EMPTY_IMAGE_MEDIA;
}
return select(coreStore).getEntityRecords(
"postType",
"attachment",
{
include: imageIds.join(","),
per_page: -1,
orderby: "include"
}
) ?? EMPTY_IMAGE_MEDIA;
},
[innerBlockImages]
);
}
export {
useGetMedia as default
};
//# sourceMappingURL=use-get-media.js.map