@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
80 lines (77 loc) • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PostFormatPanel;
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _coreData = require("@wordpress/core-data");
var _postFormat = require("../post-format");
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const getSuggestion = (supportedFormats, suggestedPostFormat) => {
const formats = _postFormat.POST_FORMATS.filter(format => supportedFormats?.includes(format.id));
return formats.find(format => format.id === suggestedPostFormat);
};
const PostFormatSuggestion = ({
suggestedPostFormat,
suggestionText,
onUpdatePostFormat
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
__next40pxDefaultSize: true,
variant: "link",
onClick: () => onUpdatePostFormat(suggestedPostFormat),
children: suggestionText
});
function PostFormatPanel() {
const {
currentPostFormat,
suggestion
} = (0, _data.useSelect)(select => {
var _select$getThemeSuppo;
const {
getEditedPostAttribute,
getSuggestedPostFormat
} = select(_store.store);
const supportedFormats = (_select$getThemeSuppo = select(_coreData.store).getThemeSupports().formats) !== null && _select$getThemeSuppo !== void 0 ? _select$getThemeSuppo : [];
return {
currentPostFormat: getEditedPostAttribute('format'),
suggestion: getSuggestion(supportedFormats, getSuggestedPostFormat())
};
}, []);
const {
editPost
} = (0, _data.useDispatch)(_store.store);
const onUpdatePostFormat = format => editPost({
format
});
const panelBodyTitle = [(0, _i18n.__)('Suggestion:'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
className: "editor-post-publish-panel__link",
children: (0, _i18n.__)('Use a post format')
}, "label")];
if (!suggestion || suggestion.id === currentPostFormat) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.PanelBody, {
initialOpen: false,
title: panelBodyTitle,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
children: (0, _i18n.__)('Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.')
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PostFormatSuggestion, {
onUpdatePostFormat: onUpdatePostFormat,
suggestedPostFormat: suggestion.id,
suggestionText: (0, _i18n.sprintf)( /* translators: %s: post format */
(0, _i18n.__)('Apply the "%1$s" format.'), suggestion.caption)
})
})]
});
}
//# sourceMappingURL=maybe-post-format-panel.js.map