@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 5.17 kB
Source Map (JSON)
{"version":3,"file":"edit.mjs","names":["coreStore","ToolsPanel","ToolsPanelItem"],"sources":["../../src/post-author-name/edit.jsx"],"sourcesContent":["import { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\nimport useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes';\n\nfunction PostAuthorNameEdit( props ) {\n\tuseDeprecatedTextAlign( props );\n\tconst {\n\t\tattributes: { isLink, linkTarget },\n\t\tsetAttributes,\n\t\tcontext: { postType, postId },\n\t} = props;\n\tconst { authorName, supportsAuthor } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, getUser, getPostType } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _authorId = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t)?.author;\n\n\t\t\treturn {\n\t\t\t\tauthorName: _authorId ? getUser( _authorId ) : null,\n\t\t\t\tsupportsAuthor:\n\t\t\t\t\tgetPostType( postType )?.supports?.author ?? false,\n\t\t\t};\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tconst blockProps = useBlockProps();\n\n\tconst displayName = authorName?.name || __( 'Author Name' );\n\n\tconst displayAuthor = isLink ? (\n\t\t<a\n\t\t\thref=\"#author-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\tclassName=\"wp-block-post-author-name__link\"\n\t\t>\n\t\t\t{ displayName }\n\t\t</a>\n\t) : (\n\t\tdisplayName\n\t);\n\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tisLink: false,\n\t\t\t\t\t\t\tlinkTarget: '_self',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Link to author archive' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => isLink }\n\t\t\t\t\t\tonDeselect={ () => setAttributes( { isLink: false } ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Link to author archive' ) }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { isLink: ! isLink } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tchecked={ isLink }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ isLink && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t\thasValue={ () => linkTarget !== '_self' }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { linkTarget: '_self' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tlinkTarget: value ? '_blank' : '_self',\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ ! supportsAuthor && postType !== undefined\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"post\".\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'This post type (%s) does not support the author.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tpostType\n\t\t\t\t\t\t)\n\t\t\t\t\t: displayAuthor }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default PostAuthorNameEdit;\n"],"mappings":";;;;;;;;;AAYA,SAAS,mBAAoB,OAAQ;CACpC,uBAAwB,KAAM;CAC9B,MAAM,EACL,YAAY,EAAE,QAAQ,cACtB,eACA,SAAS,EAAE,UAAU,aAClB;CACJ,MAAM,EAAE,YAAY,mBAAmB,WACpC,WAAY;EACb,MAAM,EAAE,uBAAuB,SAAS,gBACvC,OAAQA,KAAU;EACnB,MAAM,YAAY,sBACjB,YACA,UACA,MACD,CAAC,EAAE;EAEH,OAAO;GACN,YAAY,YAAY,QAAS,SAAU,IAAI;GAC/C,gBACC,YAAa,QAAS,CAAC,EAAE,UAAU,UAAU;EAC/C;CACD,GACA,CAAE,UAAU,MAAO,CACpB;CAEA,MAAM,aAAa,cAAc;CAEjC,MAAM,cAAc,YAAY,QAAQ,GAAI,aAAc;CAE1D,MAAM,gBAAgB,SACrB,oBAAC,KAAD;EACC,MAAK;EACL,UAAY,UAAW,MAAM,eAAe;EAC5C,WAAU;EAER,UAAA;CACA,CAAA,IAEH;CAGD,MAAM,oBAAoB,+BAA+B;CAEzD,OACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,mBAAD,EAAA,UACC,qBAACC,0BAAD;EACC,OAAQ,GAA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