UNPKG

@wordpress/block-library

Version:
1 lines • 1.14 kB
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../../src/icon/components/custom-inserter/utils.js"],"sourcesContent":["/**\n * Groups icons by collection, in the order of `collections`.\n *\n * @param {Object[]} icons Icons, each with a `collection` slug.\n * @param {Object[]} collections Icon collections, each with a `slug` and `label`.\n * @return {Object[]} Groups, each with a `slug`, `label` and `icons`.\n */\nexport function groupIconsByCollection( icons, collections ) {\n\tconst groups = new Map(\n\t\tcollections.map( ( { slug, label } ) => [\n\t\t\tslug,\n\t\t\t{ slug, label, icons: [] },\n\t\t] )\n\t);\n\n\ticons.forEach( ( icon ) => {\n\t\tgroups.get( icon.collection )?.icons.push( icon );\n\t} );\n\n\treturn [ ...groups.values() ].filter( ( group ) => group.icons.length );\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,uBAAwB,OAAO,aAAc;CAC5D,MAAM,SAAS,IAAI,IAClB,YAAY,KAAO,EAAE,MAAM,YAAa,CACvC,MACA;EAAE;EAAM;EAAO,OAAO,CAAC;CAAE,CAC1B,CAAE,CACH;CAEA,MAAM,SAAW,SAAU;EAC1B,OAAO,IAAK,KAAK,UAAW,CAAC,EAAE,MAAM,KAAM,IAAK;CACjD,CAAE;CAEF,OAAO,CAAE,GAAG,OAAO,OAAO,CAAE,CAAC,CAAC,QAAU,UAAW,MAAM,MAAM,MAAO;AACvE"}