{
  "version": 3,
  "sources": ["../../src/hooks/navigation-link-view-button.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__unstableBlockToolbarLastItem as BlockToolbarLastItem,\n\tstore as blockEditorStore,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n// Target blocks that should have the View button.\nconst SUPPORTED_BLOCKS = [ 'core/navigation-link', 'core/navigation-submenu' ];\n\n/**\n * Component that renders the View button for navigation blocks.\n *\n * @param {Object} props            Component props.\n * @param {Object} props.attributes Block attributes.\n * @return {React.JSX.Element} The View button component or null if not applicable.\n */\nfunction NavigationViewButton( { attributes } ) {\n\tconst { kind, id, type } = attributes;\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst onNavigateToEntityRecord = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().onNavigateToEntityRecord,\n\t\t[]\n\t);\n\n\tconst onViewPage = useCallback( () => {\n\t\tif (\n\t\t\tkind === 'post-type' &&\n\t\t\ttype === 'page' &&\n\t\t\tid &&\n\t\t\tonNavigateToEntityRecord\n\t\t) {\n\t\t\tonNavigateToEntityRecord( {\n\t\t\t\tpostId: id,\n\t\t\t\tpostType: type,\n\t\t\t} );\n\t\t}\n\t}, [ kind, id, type, onNavigateToEntityRecord ] );\n\n\t// Only show for page-type links, when navigation is available, and when in contentOnly mode.\n\tif (\n\t\tkind !== 'post-type' ||\n\t\ttype !== 'page' ||\n\t\t! id ||\n\t\t! onNavigateToEntityRecord ||\n\t\tblockEditingMode !== 'contentOnly'\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockToolbarLastItem>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tname=\"view\"\n\t\t\t\t\ttitle={ __( 'View' ) }\n\t\t\t\t\tonClick={ onViewPage }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'View' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockToolbarLastItem>\n\t);\n}\n\n/**\n * Higher-order component that adds the View button to navigation blocks.\n */\nconst withNavigationViewButton = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = SUPPORTED_BLOCKS.includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<NavigationViewButton { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withNavigationViewButton'\n);\n\n// Register the filter.\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-navigation-view-button',\n\twithNavigationViewButton\n);\n"],
  "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB;AAAA,EACC,kCAAkC;AAAA,EAClC,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,eAAe,oBAAoB;AAC5C,SAAS,iBAAiB;AAkDtB,SAoBD,UApBC,KAoBD,YApBC;AA/CJ,IAAM,mBAAmB,CAAE,wBAAwB,yBAA0B;AAS7E,SAAS,qBAAsB,EAAE,WAAW,GAAI;AAC/C,QAAM,EAAE,MAAM,IAAI,KAAK,IAAI;AAC3B,QAAM,mBAAmB,oBAAoB;AAE7C,QAAM,2BAA2B;AAAA,IAChC,CAAE,WACD,OAAQ,gBAAiB,EAAE,YAAY,EAAE;AAAA,IAC1C,CAAC;AAAA,EACF;AAEA,QAAM,aAAa,YAAa,MAAM;AACrC,QACC,SAAS,eACT,SAAS,UACT,MACA,0BACC;AACD,+BAA0B;AAAA,QACzB,QAAQ;AAAA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