@wordpress/block-library
Version:
Block library for the WordPress editor.
67 lines (66 loc) • 2.17 kB
JavaScript
// packages/block-library/src/site-tagline/edit.jsx
import { useSelect } from "@wordpress/data";
import { store as coreStore, useEntityProp } from "@wordpress/core-data";
import {
useBlockProps,
BlockControls,
HeadingLevelDropdown,
RichText
} 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";
function SiteTaglineEdit(props) {
useDeprecatedTextAlign(props);
const { attributes, setAttributes, insertBlocksAfter } = props;
const { level, levelOptions } = attributes;
const canUserEdit = useSelect(
(select) => select(coreStore).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