UNPKG

@wordpress/editor

Version:
183 lines (181 loc) 7.83 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/editor/src/components/post-publish-panel/index.js var post_publish_panel_exports = {}; __export(post_publish_panel_exports, { default: () => PostPublishPanel }); module.exports = __toCommonJS(post_publish_panel_exports); var import_i18n = require("@wordpress/i18n"); var import_element = require("@wordpress/element"); var import_components = require("@wordpress/components"); var import_data = require("@wordpress/data"); var import_compose = require("@wordpress/compose"); var import_icons = require("@wordpress/icons"); var import_core_data = require("@wordpress/core-data"); var import_post_publish_button = __toESM(require("../post-publish-button/index.cjs")); var import_prepublish = __toESM(require("./prepublish.cjs")); var import_postpublish = __toESM(require("./postpublish.cjs")); var import_store = require("../../store/index.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function PostPublishPanel({ forceIsDirty, onClose, PostPublishExtension, PrePublishExtension, ...propsForPanel }) { const { hasPublishAction, isPostTypeViewable, isBeingScheduled, isDirty, isPublished, isPublishSidebarEnabled, isSaving, isSavingNonPostEntityChanges, isScheduled, currentPostId } = (0, import_data.useSelect)((select) => { const { getPostType } = select(import_core_data.store); const { getCurrentPost, getCurrentPostId, getEditedPostAttribute, isCurrentPostPublished, isCurrentPostScheduled, isEditedPostBeingScheduled, isEditedPostDirty, isAutosavingPost, isSavingPost, isSavingNonPostEntityChanges: _isSavingNonPostEntityChanges, isPublishSidebarEnabled: _isPublishSidebarEnabled } = select(import_store.store); const postType = getPostType(getEditedPostAttribute("type")); return { hasPublishAction: getCurrentPost()._links?.["wp:action-publish"] ?? false, isPostTypeViewable: postType?.viewable, isBeingScheduled: isEditedPostBeingScheduled(), isDirty: isEditedPostDirty(), isPublished: isCurrentPostPublished(), isPublishSidebarEnabled: _isPublishSidebarEnabled(), isSaving: isSavingPost() && !isAutosavingPost(), isSavingNonPostEntityChanges: _isSavingNonPostEntityChanges(), isScheduled: isCurrentPostScheduled(), currentPostId: getCurrentPostId() }; }, []); const { disablePublishSidebar, enablePublishSidebar } = (0, import_data.useDispatch)(import_store.store); const cancelButtonRef = (0, import_element.useRef)(null); const wrapperRef = (0, import_compose.useMergeRefs)([ (0, import_compose.useFocusReturn)(), (0, import_compose.useConstrainedTabbing)() ]); (0, import_element.useEffect)(() => { cancelButtonRef.current?.focus(); }, []); const prevPostIdRef = (0, import_element.useRef)(currentPostId); const stableOnClose = (0, import_compose.useEvent)(onClose); (0, import_element.useEffect)(() => { const postChanged = currentPostId !== prevPostIdRef.current; prevPostIdRef.current = currentPostId; if (postChanged || isPublished && !isSaving && isDirty) { stableOnClose(); } }, [isPublished, isSaving, isDirty, currentPostId, stableOnClose]); function onTogglePublishSidebar() { if (isPublishSidebarEnabled) { disablePublishSidebar(); } else { enablePublishSidebar(); } } function onSubmit() { if (!hasPublishAction || !isPostTypeViewable) { onClose(); } } const isPublishedOrScheduled = isPublished || isScheduled && isBeingScheduled; const isPrePublish = !isPublishedOrScheduled && !isSaving; const isPostPublish = isPublishedOrScheduled && !isSaving; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { ref: wrapperRef, tabIndex: -1, className: "editor-post-publish-panel", ...propsForPanel, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "editor-post-publish-panel__header", children: isPostPublish ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { size: "compact", onClick: onClose, icon: import_icons.closeSmall, label: (0, import_i18n.__)("Close panel") } ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "editor-post-publish-panel__header-cancel-button", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { ref: cancelButtonRef, accessibleWhenDisabled: true, disabled: isSavingNonPostEntityChanges, onClick: onClose, variant: "secondary", size: "compact", children: (0, import_i18n.__)("Cancel") } ) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "editor-post-publish-panel__header-publish-button", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_post_publish_button.default, { onSubmit, forceIsDirty } ) }) ] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "editor-post-publish-panel__content", children: [ isPrePublish && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_prepublish.default, { children: PrePublishExtension && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrePublishExtension, {}) }), isPostPublish && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_postpublish.default, { focusOnMount: true, children: PostPublishExtension && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PostPublishExtension, {}) }), isSaving && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "editor-post-publish-panel__footer", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.CheckboxControl, { label: (0, import_i18n.__)("Always show pre-publish checks."), checked: isPublishSidebarEnabled, onChange: onTogglePublishSidebar } ) }) ] } ); } //# sourceMappingURL=index.cjs.map