@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 1.73 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/query-title/use-post-type-label.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Hook to fetch the singular label for the current post type.\n *\n * @param {string} contextPostType Context provided post type.\n */\nexport function usePostTypeLabel( contextPostType ) {\n\tconst currentPostType = useSelect( ( select ) => {\n\t\t// Access core/editor by string to avoid @wordpress/editor dependency.\n\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\tconst { getCurrentPostType } = select( 'core/editor' );\n\t\treturn getCurrentPostType();\n\t}, [] );\n\n\t// Fetch the post type label from the core data store\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst postTypeSlug = contextPostType || currentPostType;\n\t\t\tconst postType = getPostType( postTypeSlug );\n\n\t\t\t// Return the singular name of the post type\n\t\t\treturn {\n\t\t\t\tpostTypeLabel: postType ? postType.labels.singular_name : '',\n\t\t\t};\n\t\t},\n\t\t[ contextPostType, currentPostType ]\n\t);\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AACnC,kBAA0B;AAOnB,SAAS,iBAAkB,iBAAkB;AACnD,QAAM,sBAAkB,uBAAW,CAAE,WAAY;AAGhD,UAAM,EAAE,mBAAmB,IAAI,OAAQ,aAAc;AACrD,WAAO,mBAAmB;AAAA,EAC3B,GAAG,CAAC,CAAE;AAGN,aAAO;AAAA,IACN,CAAE,WAAY;AACb,YAAM,EAAE,YAAY,IAAI,OAAQ,iBAAAA,KAAU;AAC1C,YAAM,eAAe,mBAAmB;AACxC,YAAM,WAAW,YAAa,YAAa;AAG3C,aAAO;AAAA,QACN,eAAe,WAAW,SAAS,OAAO,gBAAgB;AAAA,MAC3D;AAAA,IACD;AAAA,IACA,CAAE,iBAAiB,eAAgB;AAAA,EACpC;AACD;",
"names": ["coreStore"]
}