UNPKG

@wordpress/block-library

Version:
83 lines (82 loc) • 2.65 kB
import { store, useEntityProp } from "@wordpress/core-data"; import { TextControl } from "@wordpress/components"; import { SelectControl } from "@wordpress/ui"; import { __, sprintf } from "@wordpress/i18n"; import { useSelect } from "@wordpress/data"; import { privateApis } from "@wordpress/block-editor"; import { TemplatePartImportControls } from "./import-controls.mjs"; import { unlock } from "../../lock-unlock.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/template-part/edit/advanced-controls.jsx const { HTMLElementControl } = unlock(privateApis); const DEFAULT_TAG_NAME = "__default"; function TemplatePartAdvancedControls({ tagName, setAttributes, isEntityAvailable, templatePartId, defaultWrapper, hasInnerBlocks, clientId }) { const [area, setArea] = useEntityProp("postType", "wp_template_part", "area", templatePartId); const [title, setTitle] = useEntityProp("postType", "wp_template_part", "title", templatePartId); const areaOptions = useSelect((select) => select(store).getCurrentTheme()?.default_template_part_areas || [], []).map(({ label, area: _area }) => ({ label, value: _area })); return /* @__PURE__ */ jsxs(Fragment, { children: [ isEntityAvailable && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(TextControl, { label: __("Title"), value: title, onChange: (value) => { setTitle(value); }, onFocus: (event) => event.target.select() }), /* @__PURE__ */ jsx(SelectControl, { label: __("Area"), items: areaOptions, value: areaOptions.find((item) => item.value === area) ?? null, onValueChange: (item) => { if (item && item.value !== area) setArea(item.value); } })] }), /* @__PURE__ */ jsx(HTMLElementControl, { tagName: tagName || DEFAULT_TAG_NAME, onChange: (value) => setAttributes({ tagName: value === DEFAULT_TAG_NAME ? "" : value }), clientId, options: [ { label: sprintf(__("Default based on area (%s)"), `<${defaultWrapper}>`), value: DEFAULT_TAG_NAME }, { label: "<header>", value: "header" }, { label: "<main>", value: "main" }, { label: "<section>", value: "section" }, { label: "<article>", value: "article" }, { label: "<aside>", value: "aside" }, { label: "<footer>", value: "footer" }, { label: "<div>", value: "div" } ] }), !hasInnerBlocks && /* @__PURE__ */ jsx(TemplatePartImportControls, { area, setAttributes }) ] }); } export { TemplatePartAdvancedControls }; //# sourceMappingURL=advanced-controls.mjs.map