@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
70 lines (68 loc) • 2.26 kB
JavaScript
/**
* WordPress dependencies
*/
import { CheckboxControl, PanelRow } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { getTemplateInfo } from '../../utils/get-template-info';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export default function EntityRecordItem({
record,
checked,
onChange
}) {
const {
name,
kind,
title,
key
} = record;
// Handle templates that might use default descriptive titles.
const {
entityRecordTitle,
hasPostMetaChanges
} = useSelect(select => {
var _select$getCurrentThe;
if ('postType' !== kind || 'wp_template' !== name) {
return {
entityRecordTitle: title,
hasPostMetaChanges: unlock(select(editorStore)).hasPostMetaChanges(name, key)
};
}
const template = select(coreStore).getEditedEntityRecord(kind, name, key);
const {
default_template_types: templateTypes = []
} = (_select$getCurrentThe = select(coreStore).getCurrentTheme()) !== null && _select$getCurrentThe !== void 0 ? _select$getCurrentThe : {};
return {
entityRecordTitle: getTemplateInfo({
template,
templateTypes
}).title,
hasPostMetaChanges: unlock(select(editorStore)).hasPostMetaChanges(name, key)
};
}, [name, kind, title, key]);
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(PanelRow, {
children: /*#__PURE__*/_jsx(CheckboxControl, {
__nextHasNoMarginBottom: true,
label: decodeEntities(entityRecordTitle) || __('Untitled'),
checked: checked,
onChange: onChange,
className: "entities-saved-states__change-control"
})
}), hasPostMetaChanges && /*#__PURE__*/_jsx("ul", {
className: "entities-saved-states__changes",
children: /*#__PURE__*/_jsx("li", {
children: __('Post Meta.')
})
})]
});
}
//# sourceMappingURL=entity-record-item.js.map