@wordpress/edit-post
Version:
Edit Post module for WordPress.
86 lines (80 loc) • 3.18 kB
JavaScript
import { createElement, Fragment } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { EntitiesSavedStates, PostPublishPanel } from '@wordpress/editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { Button, createSlotFill } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import PluginPostPublishPanel from '../sidebar/plugin-post-publish-panel';
import PluginPrePublishPanel from '../sidebar/plugin-pre-publish-panel';
import { store as editPostStore } from '../../store';
const {
Fill,
Slot
} = createSlotFill('ActionsPanel');
export const ActionsPanelFill = Fill;
export default function ActionsPanel({
setEntitiesSavedStatesCallback,
closeEntitiesSavedStates,
isEntitiesSavedStatesOpen
}) {
const {
closePublishSidebar,
togglePublishSidebar
} = useDispatch(editPostStore);
const {
publishSidebarOpened,
hasActiveMetaboxes,
isSavingMetaBoxes,
hasNonPostEntityChanges
} = useSelect(select => {
return {
publishSidebarOpened: select(editPostStore).isPublishSidebarOpened(),
hasActiveMetaboxes: select(editPostStore).hasMetaBoxes(),
isSavingMetaBoxes: select(editPostStore).isSavingMetaBoxes(),
hasNonPostEntityChanges: select('core/editor').hasNonPostEntityChanges()
};
}, []);
const openEntitiesSavedStates = 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 = createElement(PostPublishPanel, {
onClose: closePublishSidebar,
forceIsDirty: hasActiveMetaboxes,
forceIsSaving: isSavingMetaBoxes,
PrePublishExtension: PluginPrePublishPanel.Slot,
PostPublishExtension: PluginPostPublishPanel.Slot
});
} else if (hasNonPostEntityChanges) {
unmountableContent = createElement("div", {
className: "edit-post-layout__toggle-entities-saved-states-panel"
}, createElement(Button, {
isSecondary: true,
className: "edit-post-layout__toggle-entities-saved-states-panel-button",
onClick: openEntitiesSavedStates,
"aria-expanded": false
}, __('Open save panel')));
} else {
unmountableContent = createElement("div", {
className: "edit-post-layout__toggle-publish-panel"
}, createElement(Button, {
isSecondary: true,
className: "edit-post-layout__toggle-publish-panel-button",
onClick: togglePublishSidebar,
"aria-expanded": false
}, __('Open publish panel')));
} // Since EntitiesSavedStates controls its own panel, we can keep it
// always mounted to retain its own component state (such as checkboxes).
return createElement(Fragment, null, isEntitiesSavedStatesOpen && createElement(EntitiesSavedStates, {
close: closeEntitiesSavedStates
}), createElement(Slot, {
bubblesVirtually: true
}), !isEntitiesSavedStatesOpen && unmountableContent);
}
//# sourceMappingURL=actions-panel.js.map