@wordpress/block-library
Version:
Block library for the WordPress editor.
59 lines (58 loc) • 2.24 kB
JavaScript
import { __ } from "@wordpress/i18n";
import { BlockControls, HeadingLevelDropdown, InspectorControls, useBlockProps } from "@wordpress/block-editor";
import { ToggleControl, __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components";
import { decodeEntities } from "@wordpress/html-entities";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
import { useTermName } from "./use-term-name.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/term-name/edit.jsx
function TermNameEdit({ attributes, setAttributes, context: { termId, taxonomy } }) {
const { level = 0, isLink, levelOptions } = attributes;
const { term } = useTermName(termId, taxonomy);
const termName = term?.name ? decodeEntities(term.name) : __("Term Name");
const blockProps = useBlockProps();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const TagName = level === 0 ? "p" : `h${level}`;
let termNameDisplay = termName;
if (isLink) termNameDisplay = /* @__PURE__ */ jsx("a", {
href: "#term-name-pseudo-link",
onClick: (e) => e.preventDefault(),
children: termName
});
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(BlockControls, {
group: "block",
children: /* @__PURE__ */ jsx(HeadingLevelDropdown, {
value: level,
options: levelOptions,
onChange: (newLevel) => {
setAttributes({ level: newLevel });
}
})
}),
/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(__experimentalToolsPanel, {
label: __("Settings"),
resetAll: () => {
setAttributes({ isLink: false });
},
dropdownMenuProps,
children: /* @__PURE__ */ jsx(__experimentalToolsPanelItem, {
hasValue: () => !!isLink,
label: __("Make term name a link"),
onDeselect: () => setAttributes({ isLink: false }),
isShownByDefault: true,
children: /* @__PURE__ */ jsx(ToggleControl, {
label: __("Make term name a link"),
onChange: () => setAttributes({ isLink: !isLink }),
checked: isLink
})
})
}) }),
/* @__PURE__ */ jsx(TagName, {
...blockProps,
children: termNameDisplay
})
] });
}
export { TermNameEdit as default };
//# sourceMappingURL=edit.mjs.map