@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 2.38 kB
Source Map (JSON)
{"version":3,"file":"edit.mjs","names":["coreStore"],"sources":["../../src/post-comments-link/edit.jsx"],"sourcesContent":["import { useBlockProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { usePostCommentsCount } from '../utils/hooks';\n\nfunction PostCommentsLinkEdit( { context } ) {\n\tconst { postType, postId } = context;\n\tconst { totalItems: commentsCount } = usePostCommentsCount( postId );\n\n\tconst blockProps = useBlockProps();\n\n\tconst post = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t),\n\t\t[ postType, postId ]\n\t);\n\n\tlet commentsText;\n\tif ( commentsCount !== null ) {\n\t\tconst commentsNumber = parseInt( commentsCount );\n\n\t\tif ( commentsNumber === 0 ) {\n\t\t\tcommentsText = __( 'No comments' );\n\t\t} else {\n\t\t\tcommentsText = sprintf(\n\t\t\t\t/* translators: %s: Number of comments */\n\t\t\t\t_n( '%s comment', '%s comments', commentsNumber ),\n\t\t\t\tcommentsNumber.toLocaleString()\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ post?.link && commentsText !== undefined ? (\n\t\t\t\t<a\n\t\t\t\t\thref={ post?.link + '#comments' }\n\t\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t\t>\n\t\t\t\t\t{ commentsText }\n\t\t\t\t</a>\n\t\t\t) : (\n\t\t\t\t<a\n\t\t\t\t\thref=\"#post-comments-link-pseudo-link\"\n\t\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'No comments' ) }\n\t\t\t\t</a>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default PostCommentsLinkEdit;\n"],"mappings":";;;;;;;AAMA,SAAS,qBAAsB,EAAE,WAAY;CAC5C,MAAM,EAAE,UAAU,WAAW;CAC7B,MAAM,EAAE,YAAY,kBAAkB,qBAAsB,MAAO;CAEnE,MAAM,aAAa,cAAc;CAEjC,MAAM,OAAO,WACV,WACD,OAAQA,KAAU,CAAC,CAAC,sBACnB,YACA,UACA,MACD,GACD,CAAE,UAAU,MAAO,CACpB;CAEA,IAAI;CACJ,IAAK,kBAAkB,MAAO;EAC7B,MAAM,iBAAiB,SAAU,aAAc;EAE/C,IAAK,mBAAmB,GACvB,eAAe,GAAI,aAAc;OAEjC,eAAe,QAEd,GAAI,cAAc,eAAe,cAAe,GAChD,eAAe,eAAe,CAC/B;CAEF;CAEA,OACC,oBAAC,OAAD;EAAK,GAAK;EACP,UAAA,MAAM,QAAQ,iBAAiB,KAAA,IAChC,oBAAC,KAAD;GACC,MAAO,MAAM,OAAO;GACpB,UAAY,UAAW,MAAM,eAAe;GAE1C,UAAA;EACA,CAAA,IAEH,oBAAC,KAAD;GACC,MAAK;GACL,UAAY,UAAW,MAAM,eAAe;GAE1C,UAAA,GAAI,aAAc;EAClB,CAAA;CAEA,CAAA;AAEP"}