UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 2.52 kB
{ "version": 3, "sources": ["../../../src/components/post-view-link/index.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { external } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostViewLink() {\n\tconst { hasLoaded, permalink, isPublished, label, showIconLabels } =\n\t\tuseSelect( ( select ) => {\n\t\t\t// Grab post type to retrieve the view_item label.\n\t\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\treturn {\n\t\t\t\tpermalink: select( editorStore ).getPermalink(),\n\t\t\t\tisPublished: select( editorStore ).isCurrentPostPublished(),\n\t\t\t\tlabel: postType?.labels.view_item,\n\t\t\t\thasLoaded: !! postType,\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t}, [] );\n\n\t// Only render the view button if the post is published and has a permalink.\n\tif ( ! isPublished || ! permalink || ! hasLoaded ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\ticon={ external }\n\t\t\tlabel={ label || __( 'View post' ) }\n\t\t\thref={ permalink }\n\t\t\ttarget=\"_blank\"\n\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\tsize=\"compact\"\n\t\t/>\n\t);\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,wBAAuB;AACvB,mBAAyB;AACzB,uBAAmC;AACnC,kBAA0B;AAC1B,yBAA0C;AAK1C,mBAAqC;AAyBnC;AAvBa,SAAR,eAAgC;AACtC,QAAM,EAAE,WAAW,WAAW,aAAa,OAAO,eAAe,QAChE,uBAAW,CAAE,WAAY;AAExB,UAAM,eAAe,OAAQ,aAAAA,KAAY,EAAE,mBAAmB;AAC9D,UAAM,WAAW,OAAQ,iBAAAC,KAAU,EAAE,YAAa,YAAa;AAC/D,UAAM,EAAE,IAAI,IAAI,OAAQ,mBAAAC,KAAiB;AAEzC,WAAO;AAAA,MACN,WAAW,OAAQ,aAAAF,KAAY,EAAE,aAAa;AAAA,MAC9C,aAAa,OAAQ,aAAAA,KAAY,EAAE,uBAAuB;AAAA,MAC1D,OAAO,UAAU,OAAO;AAAA,MACxB,WAAW,CAAC,CAAE;AAAA,MACd,gBAAgB,IAAK,QAAQ,gBAAiB;AAAA,IAC/C;AAAA,EACD,GAAG,CAAC,CAAE;AAGP,MAAK,CAAE,eAAe,CAAE,aAAa,CAAE,WAAY;AAClD,WAAO;AAAA,EACR;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAO;AAAA,MACP,OAAQ,aAAS,gBAAI,WAAY;AAAA,MACjC,MAAO;AAAA,MACP,QAAO;AAAA,MACP,aAAc,CAAE;AAAA,MAChB,MAAK;AAAA;AAAA,EACN;AAEF;", "names": ["editorStore", "coreStore", "preferencesStore"] }