@wordpress/block-editor
Version:
95 lines (93 loc) • 3.71 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-editor/src/components/html-element-control/index.js
var html_element_control_exports = {};
__export(html_element_control_exports, {
default: () => HTMLElementControl
});
module.exports = __toCommonJS(html_element_control_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_data = require("@wordpress/data");
var import_store = require("../../store");
var import_messages = require("./messages");
var import_jsx_runtime = require("react/jsx-runtime");
function HTMLElementControl({
tagName,
onChange,
clientId,
options = [
{ label: (0, import_i18n.__)("Default (<div>)"), value: "div" },
{ label: "<header>", value: "header" },
{ label: "<main>", value: "main" },
{ label: "<section>", value: "section" },
{ label: "<article>", value: "article" },
{ label: "<aside>", value: "aside" },
{ label: "<footer>", value: "footer" }
]
}) {
const checkForMainTag = !!clientId && options.some((option) => option.value === "main");
const hasMainElementElsewhere = (0, import_data.useSelect)(
(select) => {
if (!checkForMainTag) {
return false;
}
const { getClientIdsWithDescendants, getBlockAttributes } = select(import_store.store);
return getClientIdsWithDescendants().some((id) => {
if (id === clientId) {
return false;
}
return getBlockAttributes(id)?.tagName === "main";
});
},
[clientId, checkForMainTag]
);
const modifiedOptions = options.map((option) => {
if (option.value === "main" && hasMainElementElsewhere && tagName !== "main") {
return {
...option,
disabled: true,
label: (0, import_i18n.sprintf)(
/* translators: %s: HTML element name */
(0, import_i18n.__)("%s (Already in use)"),
option.label
)
};
}
return option;
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 2, className: "block-editor-html-element-control", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.SelectControl,
{
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
label: (0, import_i18n.__)("HTML element"),
options: modifiedOptions,
value: tagName,
onChange,
help: import_messages.htmlElementMessages[tagName]
}
),
tagName === "main" && hasMainElementElsewhere && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Notice, { status: "warning", isDismissible: false, children: (0, import_i18n.__)(
"Multiple <main> elements detected. The duplicate may be in your content or template. This is not valid HTML and may cause accessibility issues. Please change this HTML element."
) })
] });
}
//# sourceMappingURL=index.js.map