@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
8 lines (7 loc) • 5.61 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/post-url/panel.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { Dropdown, Button, ExternalLink } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURIComponent } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostURLCheck from './check';\nimport PostURL from './index';\nimport PostPanelRow from '../post-panel-row';\nimport { store as editorStore } from '../../store';\n\n/**\n * Renders the `PostURLPanel` component.\n *\n * @return {React.ReactNode} The rendered PostURLPanel component.\n */\nexport default function PostURLPanel() {\n\tconst { isFrontPage } = useSelect( ( select ) => {\n\t\tconst { getCurrentPostId } = select( editorStore );\n\t\tconst { getEditedEntityRecord, canUser } = select( coreStore );\n\t\tconst siteSettings = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? getEditedEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\tconst _id = getCurrentPostId();\n\t\treturn {\n\t\t\tisFrontPage: siteSettings?.page_on_front === _id,\n\t\t};\n\t}, [] );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t\tplacement: 'left-start',\n\t\t\toffset: 36,\n\t\t\tshift: true,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst label = isFrontPage ? __( 'Link' ) : __( 'Slug' );\n\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PostPanelRow label={ label } ref={ setPopoverAnchor }>\n\t\t\t\t{ ! isFrontPage && (\n\t\t\t\t\t<Dropdown\n\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t\tclassName=\"editor-post-url__panel-dropdown\"\n\t\t\t\t\t\tcontentClassName=\"editor-post-url__panel-dialog\"\n\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t<PostURLToggle\n\t\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t<PostURL onClose={ onClose } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ isFrontPage && <FrontPageLink /> }\n\t\t\t</PostPanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst { slug } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tslug: select( editorStore ).getEditedPostSlug(),\n\t\t};\n\t}, [] );\n\tconst decodedSlug = safeDecodeURIComponent( slug );\n\treturn (\n\t\t<Button\n\t\t\tsize=\"compact\"\n\t\t\tclassName=\"editor-post-url__panel-toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\t// translators: %s: Current post link.\n\t\t\t\tsprintf( __( 'Change link: %s' ), decodedSlug )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t<>{ decodedSlug }</>\n\t\t</Button>\n\t);\n}\n\nfunction FrontPageLink() {\n\tconst { postLink } = useSelect( ( select ) => {\n\t\tconst { getCurrentPost } = select( editorStore );\n\t\treturn {\n\t\t\tpostLink: getCurrentPost()?.link,\n\t\t};\n\t}, [] );\n\n\tretur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