{"version":3,"file":"edit.cjs","names":["useEntityProp","useBlockProps","useSelect","blockEditorStore","useToolsPanelDropdownMenuProps","usePostCommentsCount","BlockControls","HeadingLevelDropdown","InspectorControls","ToolsPanel","__","ToolsPanelItem","ToggleControl","sprintf","_n"],"sources":["../../src/comments-title/edit.jsx"],"sourcesContent":["import {\n\tBlockControls,\n\tuseBlockProps,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { useEntityProp } from '@wordpress/core-data';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tusePostCommentsCount,\n\tuseToolsPanelDropdownMenuProps,\n} from '../utils/hooks';\nimport useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes';\n\nexport default function Edit( props ) {\n\tuseDeprecatedTextAlign( props );\n\tconst { attributes, setAttributes, context } = props;\n\tconst {\n\t\tshowPostTitle,\n\t\tshowCommentsCount,\n\t\tlevel = 2,\n\t\tlevelOptions,\n\t} = attributes;\n\tconst { postId, postType } = context;\n\tconst TagName = 'h' + level;\n\tconst [ rawTitle ] = useEntityProp( 'postType', postType, 'title', postId );\n\tconst isSiteEditor = typeof postId === 'undefined';\n\tconst blockProps = useBlockProps();\n\n\tconst {\n\t\tthreadCommentsDepth,\n\t\tthreadComments,\n\t\tcommentsPerPage,\n\t\tpageComments,\n\t} = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().__experimentalDiscussionSettings ?? {};\n\t}, [] );\n\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst { totalItems, hasResolved } = usePostCommentsCount( postId );\n\tlet commentsCount;\n\tif ( isSiteEditor ) {\n\t\t// Match the number of comments that will be shown in the comment-template/edit.js placeholder\n\n\t\tconst nestedCommentsNumber = threadComments\n\t\t\t? Math.min( threadCommentsDepth, 3 ) - 1\n\t\t\t: 0;\n\t\tconst topLevelCommentsNumber = pageComments ? commentsPerPage : 3;\n\n\t\tconst commentsNumber =\n\t\t\tparseInt( nestedCommentsNumber ) +\n\t\t\tparseInt( topLevelCommentsNumber );\n\n\t\tcommentsCount = Math.min( commentsNumber, 3 );\n\t} else {\n\t\t// A failed request has no total.\n\t\tcommentsCount = totalItems ?? ( hasResolved ? 0 : undefined );\n\t}\n\n\tconst blockControls = (\n\t\t<BlockControls group=\"block\">\n\t\t\t<HeadingLevelDropdown\n\t\t\t\tvalue={ level }\n\t\t\t\toptions={ levelOptions }\n\t\t\t\tonChange={ ( newLevel ) =>\n\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t}\n\t\t\t/>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<ToolsPanel\n\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\tresetAll={ () => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tshowPostTitle: true,\n\t\t\t\t\t\tshowCommentsCount: true,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Show post title' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => ! showPostTitle }\n\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\tsetAttributes( { showPostTitle: true } )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show post title' ) }\n\t\t\t\t\t\tchecked={ showPostTitle }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { showPostTitle: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Show comments count' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => ! showCommentsCount }\n\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\tsetAttributes( { showCommentsCount: true } )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show comments count' ) }\n\t\t\t\t\t\tchecked={ showCommentsCount }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { showCommentsCount: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t</ToolsPanel>\n\t\t</InspectorControls>\n\t);\n\n\tconst postTitle = isSiteEditor ? __( 'Post Title' ) : rawTitle;\n\n\tlet placeholder;\n\tif ( showCommentsCount && commentsCount !== undefined ) {\n\t\tif ( showPostTitle ) {\n\t\t\tif ( commentsCount === 1 ) {\n\t\t\t\tplaceholder = sprintf(\n\t\t\t\t\t/* translators: %s: Post title. */\n\t\t\t\t\t__( 'One response to \"%s\"' ),\n\t\t\t\t\tpostTitle\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tplaceholder = sprintf(\n\t\t\t\t\t/* translators: 1: Number of comments, 2: Post title. */\n\t\t\t\t\t_n(\n\t\t\t\t\t\t'%1$s response to \"%2$s\"',\n\t\t\t\t\t\t'%1$s responses to \"%2$s\"',\n\t\t\t\t\t\tcommentsCount\n\t\t\t\t\t),\n\t\t\t\t\tcommentsCount,\n\t\t\t\t\tpostTitle\n\t\t\t\t);\n\t\t\t}\n\t\t} else if ( commentsCount === 1 ) {\n\t\t\tplaceholder = __( 'One response' );\n\t\t} else {\n\t\t\tplaceholder = sprintf(\n\t\t\t\t/* translators: %s: Number of comments. */\n\t\t\t\t_n( '%s response', '%s responses', commentsCount ),\n\t\t\t\tcommentsCount\n\t\t\t);\n\t\t}\n\t} else if ( showPostTitle ) {\n\t\tif ( commentsCount === 1 ) {\n\t\t\t/* translators: %s: Post title. */\n\t\t\tplaceholder = sprintf( __( 'Response to \"%s\"' ), postTitle );\n\t\t} else {\n\t\t\t/* translators: %s: Post title. */\n\t\t\tplaceholder = sprintf( __( 'Responses to \"%s\"' ), postTitle );\n\t\t}\n\t} else if ( commentsCount === 1 ) {\n\t\tplaceholder = __( 'Response' );\n\t} else {\n\t\tplaceholder = __( 'Responses' );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ blockControls }\n\t\t\t{ inspectorControls }\n\t\t\t<TagName { ...blockProps }>{ placeholder }</TagName>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAwB,KAAM,OAAQ;CACrC,CAAA,GAAA,6CAAA,QAAA,CAAwB,KAAM;CAC9B,MAAM,EAAE,YAAY,eAAe,YAAY;CAC/C,MAAM,EACL,eACA,mBACA,QAAQ,GACR,iBACG;CACJ,MAAM,EAAE,QAAQ,aAAa;CAC7B,MAAM,UAAU,MAAM;CACtB,MAAM,CAAE,aAAA,GAAaA,qBAAAA,cAAAA,CAAe,YAAY,UAAU,SAAS,MAAO;CAC1E,MAAM,eAAe,OAAO,WAAW;CACvC,MAAM,cAAA,GAAaC,wBAAAA,cAAAA,CAAc;CAEjC,MAAM,EACL,qBACA,gBACA,iBACA,kBAAA,GACGC,gBAAAA,UAAAA,EAAa,WAAY;EAC5B,MAAM,EAAE,gBAAgB,OAAQC,wBAAAA,KAAiB;EACjD,OAAO,YAAY,CAAC,CAAC,oCAAoC,CAAC;CAC3D,GAAG,CAAC,CAAE;CAEN,MAAM,qBAAA,GAAoBC,kBAAAA,+BAAAA,CAA+B;CAEzD,MAAM,EAAE,YAAY,iBAAA,GAAgBC,kBAAAA,qBAAAA,CAAsB,MAAO;CACjE,IAAI;CACJ,IAAK,cAAe;EAGnB,MAAM,uBAAuB,iBAC1B,KAAK,IAAK,qB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