UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 2.34 kB
{ "version": 3, "sources": ["../../src/utils/get-template-info.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { layout } from '@wordpress/icons';\n/**\n * Internal dependencies\n */\nimport { getTemplatePartIcon } from './get-template-part-icon';\nconst EMPTY_OBJECT = {};\n\n/**\n * Helper function to retrieve the corresponding template info for a given template.\n * @param {Object} params\n * @param {Array} params.templateTypes\n * @param {Array} [params.templateAreas]\n * @param {Object} params.template\n */\nexport const getTemplateInfo = ( params ) => {\n\tif ( ! params ) {\n\t\treturn EMPTY_OBJECT;\n\t}\n\n\tconst { templateTypes, templateAreas, template } = params;\n\n\tconst { description, slug, title, area } = template;\n\n\tconst { title: defaultTitle, description: defaultDescription } =\n\t\tObject.values( templateTypes ).find( ( type ) => type.slug === slug ) ??\n\t\tEMPTY_OBJECT;\n\n\tconst templateTitle = typeof title === 'string' ? title : title?.rendered;\n\tconst templateDescription =\n\t\ttypeof description === 'string' ? description : description?.raw;\n\n\tconst templateAreasWithIcon = templateAreas?.map( ( item ) => ( {\n\t\t...item,\n\t\ticon: getTemplatePartIcon( item.icon ),\n\t} ) );\n\n\tconst templateIcon =\n\t\ttemplateAreasWithIcon?.find( ( item ) => area === item.area )?.icon ||\n\t\tlayout;\n\n\treturn {\n\t\ttitle:\n\t\t\ttemplateTitle && templateTitle !== slug\n\t\t\t\t? templateTitle\n\t\t\t\t: defaultTitle || slug,\n\t\tdescription: templateDescription || defaultDescription,\n\t\ticon: templateIcon,\n\t};\n};\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuB;AAIvB,oCAAoC;AACpC,IAAM,eAAe,CAAC;AASf,IAAM,kBAAkB,CAAE,WAAY;AAC5C,MAAK,CAAE,QAAS;AACf,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,eAAe,eAAe,SAAS,IAAI;AAEnD,QAAM,EAAE,aAAa,MAAM,OAAO,KAAK,IAAI;AAE3C,QAAM,EAAE,OAAO,cAAc,aAAa,mBAAmB,IAC5D,OAAO,OAAQ,aAAc,EAAE,KAAM,CAAE,SAAU,KAAK,SAAS,IAAK,KACpE;AAED,QAAM,gBAAgB,OAAO,UAAU,WAAW,QAAQ,OAAO;AACjE,QAAM,sBACL,OAAO,gBAAgB,WAAW,cAAc,aAAa;AAE9D,QAAM,wBAAwB,eAAe,IAAK,CAAE,UAAY;AAAA,IAC/D,GAAG;AAAA,IACH,UAAM,mDAAqB,KAAK,IAAK;AAAA,EACtC,EAAI;AAEJ,QAAM,eACL,uBAAuB,KAAM,CAAE,SAAU,SAAS,KAAK,IAAK,GAAG,QAC/D;AAED,SAAO;AAAA,IACN,OACC,iBAAiB,kBAAkB,OAChC,gBACA,gBAAgB;AAAA,IACpB,aAAa,uBAAuB;AAAA,IACpC,MAAM;AAAA,EACP;AACD;", "names": [] }