@wordpress/block-library
Version:
Block library for the WordPress editor.
45 lines (44 loc) • 1.98 kB
JavaScript
import { useSelect } from "@wordpress/data";
import { store, useEntityProp } from "@wordpress/core-data";
import { BlockControls, HeadingLevelDropdown, RichText, useBlockProps } from "@wordpress/block-editor";
import { __ } from "@wordpress/i18n";
import { createBlock, getDefaultBlockName } from "@wordpress/blocks";
import useDeprecatedTextAlign from "../utils/deprecated-text-align-attributes.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/site-tagline/edit.jsx
function SiteTaglineEdit(props) {
useDeprecatedTextAlign(props);
const { attributes, setAttributes, insertBlocksAfter } = props;
const { level, levelOptions } = attributes;
const canUserEdit = useSelect((select) => select(store).canUser("update", {
kind: "root",
name: "site"
}), []);
const [tagline, setTagline] = useEntityProp("root", canUserEdit ? "site" : "__unstableBase", "description", void 0);
const TagName = level === 0 ? "p" : `h${level}`;
const blockProps = useBlockProps({ className: !canUserEdit && !tagline && "wp-block-site-tagline__placeholder" });
const siteTaglineContent = canUserEdit ? /* @__PURE__ */ jsx(RichText, {
allowedFormats: [],
onChange: setTagline,
"aria-label": __("Site tagline text"),
placeholder: __("Write site tagline…"),
tagName: TagName,
value: tagline,
disableLineBreaks: true,
__unstableOnSplitAtEnd: insertBlocksAfter ? () => insertBlocksAfter(createBlock(getDefaultBlockName())) : void 0,
...blockProps
}) : /* @__PURE__ */ jsx(TagName, {
...blockProps,
children: tagline || __("Site Tagline placeholder")
});
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(BlockControls, {
group: "block",
children: /* @__PURE__ */ jsx(HeadingLevelDropdown, {
value: level,
options: levelOptions,
onChange: (newLevel) => setAttributes({ level: newLevel })
})
}), siteTaglineContent] });
}
export { SiteTaglineEdit as default };
//# sourceMappingURL=edit.mjs.map