@wordpress/block-library
Version:
Block library for the WordPress editor.
93 lines (91 loc) • 3.54 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-library/src/query/edit/inspector-controls/format-controls.js
var format_controls_exports = {};
__export(format_controls_exports, {
default: () => FormatControls
});
module.exports = __toCommonJS(format_controls_exports);
var import_components = require("@wordpress/components");
var import_data = require("@wordpress/data");
var import_core_data = require("@wordpress/core-data");
var import_i18n = require("@wordpress/i18n");
var import_jsx_runtime = require("react/jsx-runtime");
var POST_FORMATS = [
{ value: "aside", label: (0, import_i18n.__)("Aside") },
{ value: "audio", label: (0, import_i18n.__)("Audio") },
{ value: "chat", label: (0, import_i18n.__)("Chat") },
{ value: "gallery", label: (0, import_i18n.__)("Gallery") },
{ value: "image", label: (0, import_i18n.__)("Image") },
{ value: "link", label: (0, import_i18n.__)("Link") },
{ value: "quote", label: (0, import_i18n.__)("Quote") },
{ value: "standard", label: (0, import_i18n.__)("Standard") },
{ value: "status", label: (0, import_i18n.__)("Status") },
{ value: "video", label: (0, import_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, import_data.useSelect)((select) => {
const themeSupports = select(import_core_data.store).getThemeSupports();
return {
supportedFormats: themeSupports.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, import_jsx_runtime.jsx)(
import_components.FormTokenField,
{
label: (0, import_i18n.__)("Formats"),
value: values,
suggestions,
onChange: (newValues) => {
onChange({
format: formatNamesToValues(newValues, formats)
});
},
__experimentalShowHowTo: false,
__experimentalExpandOnFocus: true,
__next40pxDefaultSize: true
}
);
}
//# sourceMappingURL=format-controls.js.map