UNPKG

@wordpress/block-library

Version:
1 lines • 5.08 kB
{"version":3,"file":"form.mjs","names":["blockEditorStore","coreStore"],"sources":["../../src/post-comments-form/form.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tWarning,\n\tstore as blockEditorStore,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { Button } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useEntityProp, store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nconst CommentsFormPlaceholder = () => {\n\tconst instanceId = useInstanceId( CommentsFormPlaceholder );\n\n\treturn (\n\t\t<div className=\"comment-respond\">\n\t\t\t<h3 className=\"comment-reply-title\">{ __( 'Leave a Reply' ) }</h3>\n\t\t\t<form\n\t\t\t\tnoValidate\n\t\t\t\tclassName=\"comment-form\"\n\t\t\t\tonSubmit={ ( event ) => event.preventDefault() }\n\t\t\t>\n\t\t\t\t<p>\n\t\t\t\t\t<label htmlFor={ `comment-${ instanceId }` }>\n\t\t\t\t\t\t{ __( 'Comment' ) }\n\t\t\t\t\t</label>\n\t\t\t\t\t<textarea\n\t\t\t\t\t\tid={ `comment-${ instanceId }` }\n\t\t\t\t\t\tname=\"comment\"\n\t\t\t\t\t\tcols=\"45\"\n\t\t\t\t\t\trows=\"8\"\n\t\t\t\t\t\treadOnly\n\t\t\t\t\t/>\n\t\t\t\t</p>\n\t\t\t\t<p className=\"form-submit wp-block-button\">\n\t\t\t\t\t<input\n\t\t\t\t\t\tname=\"submit\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'wp-block-button__link',\n\t\t\t\t\t\t\t__experimentalGetElementClassName( 'button' )\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tlabel={ __( 'Post Comment' ) }\n\t\t\t\t\t\tvalue={ __( 'Post Comment' ) }\n\t\t\t\t\t\taria-disabled=\"true\"\n\t\t\t\t\t/>\n\t\t\t\t</p>\n\t\t\t</form>\n\t\t</div>\n\t);\n};\n\nconst CommentsForm = ( { postId, postType } ) => {\n\tconst [ commentStatus, setCommentStatus ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'comment_status',\n\t\tpostId\n\t);\n\n\tconst isSiteEditor = postType === undefined || postId === undefined;\n\n\tconst defaultCommentStatus = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t.__experimentalDiscussionSettings?.defaultCommentStatus,\n\t\t[]\n\t);\n\n\tconst postTypeSupportsComments = useSelect( ( select ) =>\n\t\tpostType\n\t\t\t? !! select( coreStore ).getPostType( postType )?.supports.comments\n\t\t\t: false\n\t);\n\n\tif ( ! isSiteEditor && 'open' !== commentStatus ) {\n\t\tif ( 'closed' === commentStatus ) {\n\t\t\tconst actions = [\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tkey=\"enableComments\"\n\t\t\t\t\tonClick={ () => setCommentStatus( 'open' ) }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t>\n\t\t\t\t\t{ _x(\n\t\t\t\t\t\t'Enable comments',\n\t\t\t\t\t\t'action that affects the current post'\n\t\t\t\t\t) }\n\t\t\t\t</Button>,\n\t\t\t];\n\t\t\treturn (\n\t\t\t\t<Warning actions={ actions }>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Post Comments Form block: Comments are not enabled for this item.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t);\n\t\t} else if ( ! postTypeSupportsComments ) {\n\t\t\treturn (\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t/* translators: %s: Post type (i.e. \"post\", \"page\") */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Post Comments Form block: Comments are not enabled for this post type (%s).'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tpostType\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t);\n\t\t} else if ( 'open' !== defaultCommentStatus ) {\n\t\t\treturn (\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Post Comments Form block: Comments are not enabled.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t);\n\t\t}\n\t}\n\n\treturn <CommentsFormPlaceholder />;\n};\n\nexport default CommentsForm;\n"],"mappings":";;;;;;;;;AAYA,MAAM,gCAAgC;CACrC,MAAM,aAAa,cAAe,uBAAwB;CAE1D,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACC,oBAAC,MAAD;GAAI,WAAU;GAAwB,UAAA,GAAI,eAAgB;EAAO,CAAA,GACjE,qBAAC,QAAD;GACC,YAAA;GACA,WAAU;GACV,WAAa,UAAW,MAAM,eAAe;GAH9C,UAAA,CAKC,qBAAC,KAAD,EAAA,UAAA,CACC,oBAAC,SAAD;IAAO,SAAU,WAAY;IAC1B,UAAA,GAAI,SAAU;GACV,CAAA,GACP,oBAAC,YAAD;IACC,IAAK,WAAY;IACjB,MAAK;IACL,MAAK;IACL,MAAK;IACL,UAAA;GACA,CAAA,CACC,EAAA,CAAA,GACH,oBAAC,KAAD;IAAG,WAAU;IACZ,UAAA,oBAAC,SAAD;KACC,MAAK;KACL,MAAK;KACL,WAAY,KACX,yBACA,kCAAmC,QAAS,CAC7C;KACA,OAAQ,GAAI,cAAe;KAC3B,OAAQ,GAAI,cAAe;KAC3B,iBAAc;IACd,CAAA;GACC,CAAA,CACE;EACF,CAAA,CAAA;;AAEP;AAEA,MAAM,gBAAiB,EAAE,QAAQ,eAAgB;CAChD,MAAM,CAAE,eAAe,oBAAqB,cAC3C,YACA,UACA,kBACA,MACD;CAEA,MAAM,eAAe,aAAa,KAAA,KAAa,WAAW,KAAA;CAE1D,MAAM,uBAAuB,WAC1B,WACD,OAAQA,KAAiB,CAAC,CAAC,YAAY,CAAC,CACtC,kCAAkC,sBACrC,CAAC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