UNPKG

@wordpress/editor

Version:
65 lines (59 loc) 1.74 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import { isEmpty, map } from 'lodash'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { SelectControl } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ import { store as editorStore } from '../../store'; export function PostTemplate({}) { const { availableTemplates, selectedTemplate, isViewable } = useSelect(select => { var _getPostType$viewable, _getPostType; const { getEditedPostAttribute, getEditorSettings, getCurrentPostType } = select(editorStore); const { getPostType } = select(coreStore); return { selectedTemplate: getEditedPostAttribute('template'), availableTemplates: getEditorSettings().availableTemplates, isViewable: (_getPostType$viewable = (_getPostType = getPostType(getCurrentPostType())) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false }; }, []); const { editPost } = useDispatch(editorStore); if (!isViewable || isEmpty(availableTemplates)) { return null; } return createElement(SelectControl, { label: __('Template:'), value: selectedTemplate, onChange: templateSlug => { editPost({ template: templateSlug || '' }); }, options: map(availableTemplates, (templateName, templateSlug) => ({ value: templateSlug, label: templateName })) }); } export default PostTemplate; //# sourceMappingURL=index.js.map