@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 1.77 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/gallery/use-get-media.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\nconst EMPTY_IMAGE_MEDIA = [];\n\n/**\n * Retrieves the extended media info for each gallery image from the store. This is used to\n * determine which image size options are available for the current gallery.\n *\n * @param {Array} innerBlockImages An array of the innerBlock images currently in the gallery.\n *\n * @return {Array} An array of media info options for each gallery image.\n */\nexport default function useGetMedia( innerBlockImages ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst imageIds = innerBlockImages\n\t\t\t\t.map( ( imageBlock ) => imageBlock.attributes.id )\n\t\t\t\t.filter( ( id ) => id !== undefined );\n\n\t\t\tif ( imageIds.length === 0 ) {\n\t\t\t\treturn EMPTY_IMAGE_MEDIA;\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\t{\n\t\t\t\t\t\tinclude: imageIds.join( ',' ),\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\torderby: 'include',\n\t\t\t\t\t}\n\t\t\t\t) ?? EMPTY_IMAGE_MEDIA\n\t\t\t);\n\t\t},\n\t\t[ innerBlockImages ]\n\t);\n}\n"],
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAEnC,IAAM,oBAAoB,CAAC;AAUZ,SAAR,YAA8B,kBAAmB;AACvD,SAAO;AAAA,IACN,CAAE,WAAY;AACb,YAAM,WAAW,iBACf,IAAK,CAAE,eAAgB,WAAW,WAAW,EAAG,EAChD,OAAQ,CAAE,OAAQ,OAAO,MAAU;AAErC,UAAK,SAAS,WAAW,GAAI;AAC5B,eAAO;AAAA,MACR;AAEA,aACC,OAAQ,SAAU,EAAE;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,UACC,SAAS,SAAS,KAAM,GAAI;AAAA,UAC5B,UAAU;AAAA,UACV,SAAS;AAAA,QACV;AAAA,MACD,KAAK;AAAA,IAEP;AAAA,IACA,CAAE,gBAAiB;AAAA,EACpB;AACD;",
"names": []
}