@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
73 lines (72 loc) • 2.32 kB
JavaScript
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { TEMPLATE_POST_TYPE } from '../../store/constants';
import EditorInterface from '../editor-interface';
import { ExperimentalEditorProvider } from '../provider';
import Sidebar from '../sidebar';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
function Editor({
postType,
postId,
templateId,
settings,
children,
initialEdits,
// This could be part of the settings.
onActionPerformed,
// The following abstractions are not ideal but necessary
// to account for site editor and post editor differences for now.
extraContent,
extraSidebarPanels,
...props
}) {
const {
post,
template,
hasLoadedPost,
error
} = useSelect(select => {
const {
getEntityRecord,
getResolutionError,
hasFinishedResolution
} = select(coreStore);
const postArgs = ['postType', postType, postId];
return {
post: getEntityRecord(...postArgs),
template: templateId ? getEntityRecord('postType', TEMPLATE_POST_TYPE, templateId) : undefined,
hasLoadedPost: hasFinishedResolution('getEntityRecord', postArgs),
error: getResolutionError('getEntityRecord', postArgs)?.message
};
}, [postType, postId, templateId]);
return /*#__PURE__*/_jsxs(_Fragment, {
children: [hasLoadedPost && !post && /*#__PURE__*/_jsx(Notice, {
status: !!error ? 'error' : 'warning',
isDismissible: false,
children: !error ? __("You attempted to edit an item that doesn't exist. Perhaps it was deleted?") : error
}), !!post && /*#__PURE__*/_jsxs(ExperimentalEditorProvider, {
post: post,
__unstableTemplate: template,
settings: settings,
initialEdits: initialEdits,
useSubRegistry: false,
children: [/*#__PURE__*/_jsx(EditorInterface, {
...props,
children: extraContent
}), children, /*#__PURE__*/_jsx(Sidebar, {
onActionPerformed: onActionPerformed,
extraPanels: extraSidebarPanels
})]
})]
});
}
export default Editor;
//# sourceMappingURL=index.js.map