UNPKG

@wordpress/editor

Version:
111 lines (106 loc) 4.11 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ActionsPanelFill = void 0; exports.default = SavePublishPanels; var _data = require("@wordpress/data"); var _components = require("@wordpress/components"); var _i18n = require("@wordpress/i18n"); var _element = require("@wordpress/element"); var _entitiesSavedStates = _interopRequireDefault(require("../entities-saved-states")); var _postPublishPanel = _interopRequireDefault(require("../post-publish-panel")); var _pluginPrePublishPanel = _interopRequireDefault(require("../plugin-pre-publish-panel")); var _pluginPostPublishPanel = _interopRequireDefault(require("../plugin-post-publish-panel")); var _store = require("../../store"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ const { Fill, Slot } = (0, _components.createSlotFill)('ActionsPanel'); const ActionsPanelFill = exports.ActionsPanelFill = Fill; function SavePublishPanels({ setEntitiesSavedStatesCallback, closeEntitiesSavedStates, isEntitiesSavedStatesOpen, forceIsDirtyPublishPanel }) { const { closePublishSidebar, togglePublishSidebar } = (0, _data.useDispatch)(_store.store); const { publishSidebarOpened, isPublishable, isDirty, hasOtherEntitiesChanges } = (0, _data.useSelect)(select => { const { isPublishSidebarOpened, isEditedPostPublishable, isCurrentPostPublished, isEditedPostDirty, hasNonPostEntityChanges } = select(_store.store); const _hasOtherEntitiesChanges = hasNonPostEntityChanges(); return { publishSidebarOpened: isPublishSidebarOpened(), isPublishable: !isCurrentPostPublished() && isEditedPostPublishable(), isDirty: _hasOtherEntitiesChanges || isEditedPostDirty(), hasOtherEntitiesChanges: _hasOtherEntitiesChanges }; }, []); const openEntitiesSavedStates = (0, _element.useCallback)(() => setEntitiesSavedStatesCallback(true), []); // It is ok for these components to be unmounted when not in visual use. // We don't want more than one present at a time, decide which to render. let unmountableContent; if (publishSidebarOpened) { unmountableContent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_postPublishPanel.default, { onClose: closePublishSidebar, forceIsDirty: forceIsDirtyPublishPanel, PrePublishExtension: _pluginPrePublishPanel.default.Slot, PostPublishExtension: _pluginPostPublishPanel.default.Slot }); } else if (isPublishable && !hasOtherEntitiesChanges) { unmountableContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "editor-layout__toggle-publish-panel", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, { __next40pxDefaultSize: true, variant: "secondary", onClick: togglePublishSidebar, "aria-expanded": false, children: (0, _i18n.__)('Open publish panel') }) }); } else { unmountableContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "editor-layout__toggle-entities-saved-states-panel", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, { __next40pxDefaultSize: true, variant: "secondary", onClick: openEntitiesSavedStates, "aria-expanded": false, disabled: !isDirty, accessibleWhenDisabled: true, children: (0, _i18n.__)('Open save panel') }) }); } // Since EntitiesSavedStates controls its own panel, we can keep it // always mounted to retain its own component state (such as checkboxes). return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [isEntitiesSavedStatesOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_entitiesSavedStates.default, { close: closeEntitiesSavedStates }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Slot, { bubblesVirtually: true }), !isEntitiesSavedStatesOpen && unmountableContent] }); } //# sourceMappingURL=index.js.map