@wordpress/block-library
Version:
Block library for the WordPress editor.
41 lines (40 loc) • 1.62 kB
JavaScript
import { __ } from "@wordpress/i18n";
import { useSelect } from "@wordpress/data";
import { privateApis, store } from "@wordpress/block-editor";
import DialogWrapper from "./dialog-wrapper.mjs";
import { unlock } from "../../lock-unlock.mjs";
import { jsx } from "react/jsx-runtime";
// packages/block-library/src/navigation-link/link-ui/block-inserter.jsx
const { PrivateQuickInserter: QuickInserter } = unlock(privateApis);
/**
* Component for inserting blocks within the Navigation Link UI.
*
* @param {Object} props Component props.
* @param {string} props.clientId Client ID of the navigation link block.
* @param {Function} props.onBack Callback when user wants to go back.
* @param {Function} props.onBlockInsert Callback when a block is inserted.
*/
function LinkUIBlockInserter({ clientId, onBack, onBlockInsert }) {
const { rootBlockClientId } = useSelect((select) => {
const { getBlockRootClientId } = select(store);
return { rootBlockClientId: getBlockRootClientId(clientId) };
}, [clientId]);
if (!clientId) return null;
return /* @__PURE__ */ jsx(DialogWrapper, {
className: "link-ui-block-inserter",
title: __("Add block"),
description: __("Choose a block to add to your Navigation."),
onBack,
children: /* @__PURE__ */ jsx(QuickInserter, {
rootClientId: rootBlockClientId,
clientId,
isAppender: false,
prioritizePatterns: false,
selectBlockOnInsert: !onBlockInsert,
onSelect: onBlockInsert ? onBlockInsert : void 0,
hasSearch: false
})
});
}
export { LinkUIBlockInserter as default };
//# sourceMappingURL=block-inserter.mjs.map