UNPKG

@wordpress/block-editor

Version:
71 lines (70 loc) 2.55 kB
// packages/block-editor/src/components/block-allowed-blocks/allowed-blocks-control.js import { BaseControl, Button } from "@wordpress/components"; import { __ } from "@wordpress/i18n"; import { useState } from "@wordpress/element"; import { useSelect } from "@wordpress/data"; import { hasBlockSupport, store as blocksStore } from "@wordpress/blocks"; import BlockAllowedBlocksModal from "./modal"; import { store as blockEditorStore } from "../../store"; import { jsx, jsxs } from "react/jsx-runtime"; function BlockAllowedBlocksControl({ clientId }) { const [isBlockControlOpened, setIsBlockControlOpened] = useState(false); const { blockTypes, selectedBlockNames } = useSelect( (select) => { const { getBlockAttributes } = select(blockEditorStore); return { blockTypes: select(blocksStore).getBlockTypes(), selectedBlockNames: getBlockAttributes(clientId)?.allowedBlocks }; }, [clientId] ); const filteredBlockTypes = blockTypes.filter( (blockType) => hasBlockSupport(blockType, "inserter", true) && (!blockType.parent || blockType.parent.includes("core/post-content")) ); if (!filteredBlockTypes) { return null; } const selectedBlockTypes = selectedBlockNames === void 0 ? filteredBlockTypes : filteredBlockTypes.filter( (blockType) => selectedBlockNames.includes(blockType.name) ); return /* @__PURE__ */ jsxs("div", { className: "block-editor-block-allowed-blocks-control", children: [ /* @__PURE__ */ jsxs( BaseControl, { help: __( "Specify which blocks are allowed inside this container." ), __nextHasNoMarginBottom: true, children: [ /* @__PURE__ */ jsx(BaseControl.VisualLabel, { children: __("Allowed Blocks") }), /* @__PURE__ */ jsx( Button, { __next40pxDefaultSize: true, variant: "secondary", onClick: () => { setIsBlockControlOpened(true); }, className: "block-editor-block-allowed-blocks-control__button", children: __("Manage allowed blocks") } ) ] } ), isBlockControlOpened && /* @__PURE__ */ jsx( BlockAllowedBlocksModal, { clientId, blockTypes: filteredBlockTypes, selectedBlockTypes, onClose: () => setIsBlockControlOpened(false) } ) ] }); } export { BlockAllowedBlocksControl as default }; //# sourceMappingURL=allowed-blocks-control.js.map