@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
59 lines (55 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PostViewLink;
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _icons = require("@wordpress/icons");
var _coreData = require("@wordpress/core-data");
var _data = require("@wordpress/data");
var _preferences = require("@wordpress/preferences");
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function PostViewLink() {
const {
hasLoaded,
permalink,
isPublished,
label,
showIconLabels
} = (0, _data.useSelect)(select => {
// Grab post type to retrieve the view_item label.
const postTypeSlug = select(_store.store).getCurrentPostType();
const postType = select(_coreData.store).getPostType(postTypeSlug);
const {
get
} = select(_preferences.store);
return {
permalink: select(_store.store).getPermalink(),
isPublished: select(_store.store).isCurrentPostPublished(),
label: postType?.labels.view_item,
hasLoaded: !!postType,
showIconLabels: get('core', 'showIconLabels')
};
}, []);
// Only render the view button if the post is published and has a permalink.
if (!isPublished || !permalink || !hasLoaded) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
icon: _icons.external,
label: label || (0, _i18n.__)('View post'),
href: permalink,
target: "_blank",
showTooltip: !showIconLabels,
size: "compact"
});
}
//# sourceMappingURL=index.js.map