UNPKG

@wordpress/editor

Version:
82 lines (79 loc) 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = PublishButtonLabel; var _i18n = require("@wordpress/i18n"); var _data = require("@wordpress/data"); var _compose = require("@wordpress/compose"); var _store = require("../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Renders the label for the publish button. * * @return {string} The label for the publish button. */ function PublishButtonLabel() { const isSmallerThanMediumViewport = (0, _compose.useViewportMatch)('medium', '<'); const { isPublished, isBeingScheduled, isSaving, isPublishing, hasPublishAction, isAutosaving, hasNonPostEntityChanges, postStatusHasChanged, postStatus } = (0, _data.useSelect)(select => { var _getCurrentPost$_link; const { isCurrentPostPublished, isEditedPostBeingScheduled, isSavingPost, isPublishingPost, getCurrentPost, getCurrentPostType, isAutosavingPost, getPostEdits, getEditedPostAttribute } = select(_store.store); return { isPublished: isCurrentPostPublished(), isBeingScheduled: isEditedPostBeingScheduled(), isSaving: isSavingPost(), isPublishing: isPublishingPost(), hasPublishAction: (_getCurrentPost$_link = getCurrentPost()._links?.['wp:action-publish']) !== null && _getCurrentPost$_link !== void 0 ? _getCurrentPost$_link : false, postType: getCurrentPostType(), isAutosaving: isAutosavingPost(), hasNonPostEntityChanges: select(_store.store).hasNonPostEntityChanges(), postStatusHasChanged: !!getPostEdits()?.status, postStatus: getEditedPostAttribute('status') }; }, []); if (isPublishing) { /* translators: button label text should, if possible, be under 16 characters. */ return (0, _i18n.__)('Publishing…'); } else if ((isPublished || isBeingScheduled) && isSaving && !isAutosaving) { /* translators: button label text should, if possible, be under 16 characters. */ return (0, _i18n.__)('Saving…'); } if (!hasPublishAction) { // TODO: this is because "Submit for review" string is too long in some languages. // @see https://github.com/WordPress/gutenberg/issues/10475 return isSmallerThanMediumViewport ? (0, _i18n.__)('Publish') : (0, _i18n.__)('Submit for Review'); } if (hasNonPostEntityChanges || isPublished || postStatusHasChanged && !['future', 'publish'].includes(postStatus) || !postStatusHasChanged && postStatus === 'future') { return (0, _i18n.__)('Save'); } if (isBeingScheduled) { return (0, _i18n.__)('Schedule'); } return (0, _i18n.__)('Publish'); } //# sourceMappingURL=label.js.map