UNPKG

@wordpress/block-library

Version:
1 lines • 1.7 kB
{"version":3,"file":"use-post-terms.cjs","names":["useSelect","coreStore"],"sources":["../../src/post-terms/use-post-terms.js"],"sourcesContent":["import { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nconst EMPTY_ARRAY = [];\n\nexport default function usePostTerms( { postId, term } ) {\n\tconst { slug } = term;\n\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst visible = term?.visibility?.publicly_queryable;\n\t\t\tif ( ! visible || ! postId ) {\n\t\t\t\treturn {\n\t\t\t\t\tpostTerms: EMPTY_ARRAY,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t\thasPostTerms: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { getEntityRecords, isResolving } = select( coreStore );\n\t\t\tconst taxonomyArgs = [\n\t\t\t\t'taxonomy',\n\t\t\t\tslug,\n\t\t\t\t{\n\t\t\t\t\tpost: postId,\n\t\t\t\t\tper_page: -1,\n\t\t\t\t\tcontext: 'view',\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst terms = getEntityRecords( ...taxonomyArgs );\n\n\t\t\treturn {\n\t\t\t\tpostTerms: terms,\n\t\t\t\tisLoading: isResolving( 'getEntityRecords', taxonomyArgs ),\n\t\t\t\thasPostTerms: !! terms?.length,\n\t\t\t};\n\t\t},\n\t\t[ postId, term?.visibility?.publicly_queryable, slug ]\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,MAAM,cAAc,CAAC;AAErB,SAAwB,aAAc,EAAE,QAAQ,QAAS;CACxD,MAAM,EAAE,SAAS;CAEjB,QAAA,GAAOA,gBAAAA,UAAAA,EACJ,WAAY;EAEb,IAAK,CADW,MAAM,YAAY,sBAChB,CAAE,QACnB,OAAO;GACN,WAAW;GACX,WAAW;GACX,cAAc;EACf;EAGD,MAAM,EAAE,kBAAkB,gBAAgB,OAAQC,qBAAAA,KAAU;EAC5D,MAAM,eAAe;GACpB;GACA;GACA;IACC,MAAM;IACN,UAAU;IACV,SAAS;GACV;EACD;EACA,MAAM,QAAQ,iBAAkB,GAAG,YAAa;EAEhD,OAAO;GACN,WAAW;GACX,WAAW,YAAa,oBAAoB,YAAa;GACzD,cAAc,CAAC,CAAE,OAAO;EACzB;CACD,GACA;EAAE;EAAQ,MAAM,YAAY;EAAoB;CAAK,CACtD;AACD"}