@wordpress/block-library
Version:
Block library for the WordPress editor.
86 lines (85 loc) • 2.62 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let _wordpress_core_data = require("@wordpress/core-data");
let _wordpress_i18n = require("@wordpress/i18n");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/query/edit/inspector-controls/format-controls.jsx
const POST_FORMATS = [
{
value: "aside",
label: (0, _wordpress_i18n.__)("Aside")
},
{
value: "audio",
label: (0, _wordpress_i18n.__)("Audio")
},
{
value: "chat",
label: (0, _wordpress_i18n.__)("Chat")
},
{
value: "gallery",
label: (0, _wordpress_i18n.__)("Gallery")
},
{
value: "image",
label: (0, _wordpress_i18n.__)("Image")
},
{
value: "link",
label: (0, _wordpress_i18n.__)("Link")
},
{
value: "quote",
label: (0, _wordpress_i18n.__)("Quote")
},
{
value: "standard",
label: (0, _wordpress_i18n.__)("Standard")
},
{
value: "status",
label: (0, _wordpress_i18n.__)("Status")
},
{
value: "video",
label: (0, _wordpress_i18n.__)("Video")
}
].sort((a, b) => {
const normalizedA = a.label.toUpperCase();
const normalizedB = b.label.toUpperCase();
if (normalizedA < normalizedB) return -1;
if (normalizedA > normalizedB) return 1;
return 0;
});
function formatNamesToValues(names, formats) {
return names.map((name) => {
return formats.find((item) => item.label.toLocaleLowerCase() === name.toLocaleLowerCase())?.value;
}).filter(Boolean);
}
function FormatControls({ onChange, query: { format } }) {
const normalizedFormats = Array.isArray(format) ? format : [format];
const { supportedFormats } = (0, _wordpress_data.useSelect)((select) => {
return { supportedFormats: select(_wordpress_core_data.store).getThemeSupports().formats };
}, []);
const formats = POST_FORMATS.filter((item) => supportedFormats.includes(item.value));
const values = normalizedFormats.map((name) => formats.find((item) => item.value === name)?.label).filter(Boolean);
const suggestions = formats.filter((item) => !normalizedFormats.includes(item.value)).map((item) => item.label);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.FormTokenField, {
label: (0, _wordpress_i18n.__)("Formats"),
value: values,
suggestions,
onChange: (newValues) => {
onChange({ format: formatNamesToValues(newValues, formats) });
},
help: "",
__experimentalExpandOnFocus: true
});
}
exports.default = FormatControls;
//# sourceMappingURL=format-controls.cjs.map