{"version":3,"file":"use-get-media.mjs","names":["coreStore"],"sources":["../../src/gallery/use-get-media.js"],"sourcesContent":["import { 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\t// Sorted so the query only changes when the set of images changes,\n\t\t\t// not when they're reordered: a reorder would otherwise be a new\n\t\t\t// query, and the records would read as empty until it resolved.\n\t\t\t// Consumers look records up by id, so the returned order doesn't\n\t\t\t// matter.\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\t\t\t\t.sort( ( a, b ) => a - b );\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}\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,MAAM,oBAAoB,CAAC;;;;;;;;;AAU3B,SAAwB,YAAa,kBAAmB;CACvD,OAAO,WACJ,WAAY;EAMb,MAAM,WAAW,iBACf,KAAO,eAAgB,WAAW,WAAW,EAAG,CAAC,CACjD,QAAU,OAAQ,OAAO,KAAA,CAAU,CAAC,CACpC,MAAQ,GAAG,MAAO,IAAI,CAAE;EAE1B,IAAK,SAAS,WAAW,GACxB,OAAO;EAGR,OACC,OAAQA,KAAU,CAAC,CAAC,iBACnB,YACA,cACA;GACC,SAAS,SAAS,KAAM,GAAI;GAC5B,UAAU;EACX,CACD,KAAK;CAEP,GACA,CAAE,gBAAiB,CACpB;AACD"}