UNPKG

@wordpress/editor

Version:
179 lines (174 loc) 6.13 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _components = require("@wordpress/components"); var _i18n = require("@wordpress/i18n"); var _element = require("@wordpress/element"); var _data = require("@wordpress/data"); var _url = require("@wordpress/url"); var _htmlEntities = require("@wordpress/html-entities"); var _compose = require("@wordpress/compose"); var _coreData = require("@wordpress/core-data"); var _label = _interopRequireDefault(require("../post-schedule/label")); var _store = require("../../store"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ const POSTNAME = '%postname%'; const PAGENAME = '%pagename%'; /** * Returns URL for a future post. * * @param {Object} post Post object. * * @return {string} PostPublish URL. */ const getFuturePostUrl = post => { const { slug } = post; if (post.permalink_template.includes(POSTNAME)) { return post.permalink_template.replace(POSTNAME, slug); } if (post.permalink_template.includes(PAGENAME)) { return post.permalink_template.replace(PAGENAME, slug); } return post.permalink_template; }; function CopyButton({ text, onCopy, children }) { const ref = (0, _compose.useCopyToClipboard)(text, onCopy); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, { __next40pxDefaultSize: true, variant: "secondary", ref: ref, children: children }); } class PostPublishPanelPostpublish extends _element.Component { constructor() { super(...arguments); this.state = { showCopyConfirmation: false }; this.onCopy = this.onCopy.bind(this); this.onSelectInput = this.onSelectInput.bind(this); this.postLink = (0, _element.createRef)(); } componentDidMount() { if (this.props.focusOnMount) { this.postLink.current.focus(); } } componentWillUnmount() { clearTimeout(this.dismissCopyConfirmation); } onCopy() { this.setState({ showCopyConfirmation: true }); clearTimeout(this.dismissCopyConfirmation); this.dismissCopyConfirmation = setTimeout(() => { this.setState({ showCopyConfirmation: false }); }, 4000); } onSelectInput(event) { event.target.select(); } render() { const { children, isScheduled, post, postType } = this.props; const postLabel = postType?.labels?.singular_name; const viewPostLabel = postType?.labels?.view_item; const addNewPostLabel = postType?.labels?.add_new_item; const link = post.status === 'future' ? getFuturePostUrl(post) : post.link; const addLink = (0, _url.addQueryArgs)('post-new.php', { post_type: post.type }); const postPublishNonLinkHeader = isScheduled ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [(0, _i18n.__)('is now scheduled. It will go live on'), ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_label.default, {}), "."] }) : (0, _i18n.__)('is now live.'); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "post-publish-panel__postpublish", children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.PanelBody, { className: "post-publish-panel__postpublish-header", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("a", { ref: this.postLink, href: link, children: (0, _htmlEntities.decodeEntities)(post.title) || (0, _i18n.__)('(no title)') }), ' ', postPublishNonLinkHeader] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.PanelBody, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", { className: "post-publish-panel__postpublish-subheader", children: /*#__PURE__*/(0, _jsxRuntime.jsx)("strong", { children: (0, _i18n.__)('What’s next?') }) }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "post-publish-panel__postpublish-post-address-container", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, { __next40pxDefaultSize: true, __nextHasNoMarginBottom: true, className: "post-publish-panel__postpublish-post-address", readOnly: true, label: (0, _i18n.sprintf)( /* translators: %s: post type singular name */ (0, _i18n.__)('%s address'), postLabel), value: (0, _url.safeDecodeURIComponent)(link), onFocus: this.onSelectInput }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "post-publish-panel__postpublish-post-address__copy-button-wrap", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CopyButton, { text: link, onCopy: this.onCopy, children: this.state.showCopyConfirmation ? (0, _i18n.__)('Copied!') : (0, _i18n.__)('Copy') }) })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "post-publish-panel__postpublish-buttons", children: [!isScheduled && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, { variant: "primary", href: link, __next40pxDefaultSize: true, children: viewPostLabel }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, { variant: isScheduled ? 'primary' : 'secondary', __next40pxDefaultSize: true, href: addLink, children: addNewPostLabel })] })] }), children] }); } } var _default = exports.default = (0, _data.withSelect)(select => { const { getEditedPostAttribute, getCurrentPost, isCurrentPostScheduled } = select(_store.store); const { getPostType } = select(_coreData.store); return { post: getCurrentPost(), postType: getPostType(getEditedPostAttribute('type')), isScheduled: isCurrentPostScheduled() }; })(PostPublishPanelPostpublish); //# sourceMappingURL=postpublish.js.map