UNPKG

@wordpress/block-editor

Version:
127 lines (125 loc) 5.13 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/block-allowed-blocks/modal.js var modal_exports = {}; __export(modal_exports, { default: () => BlockAllowedBlocksModal }); module.exports = __toCommonJS(modal_exports); var import_components = require("@wordpress/components"); var import_element = require("@wordpress/element"); var import_i18n = require("@wordpress/i18n"); var import_data = require("@wordpress/data"); var import_store = require("../../store"); var import_block_manager = __toESM(require("../block-manager")); var import_jsx_runtime = require("react/jsx-runtime"); function BlockAllowedBlocksModal({ clientId, blockTypes, selectedBlockTypes, onClose }) { const [currentSelectedBlockTypes, setCurrentSelectedBlockTypes] = (0, import_element.useState)(selectedBlockTypes); const { updateBlockAttributes } = (0, import_data.useDispatch)(import_store.store); const handleSubmit = () => { const isFullySelected = currentSelectedBlockTypes.length === blockTypes.length; const newBlockNames = currentSelectedBlockTypes.map( ({ name }) => name ); updateBlockAttributes(clientId, { allowedBlocks: isFullySelected ? void 0 : newBlockNames }); onClose(); }; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Modal, { title: (0, import_i18n.__)("Manage allowed blocks"), onRequestClose: onClose, overlayClassName: "block-editor-block-allowed-blocks-modal", focusOnMount: "firstContentElement", size: "medium", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.__experimentalVStack, { as: "form", onSubmit: (e) => { e.preventDefault(); handleSubmit(); }, spacing: "4", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { children: (0, import_i18n.__)( "Select which blocks can be added inside this container." ) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_block_manager.default, { blockTypes, selectedBlockTypes: currentSelectedBlockTypes, onChange: (newSelectedBlockTypes) => { setCurrentSelectedBlockTypes(newSelectedBlockTypes); } } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.Flex, { className: "block-editor-block-allowed-blocks-modal__actions", justify: "flex-end", expanded: false, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { variant: "tertiary", onClick: onClose, __next40pxDefaultSize: true, children: (0, import_i18n.__)("Cancel") } ) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { variant: "primary", type: "submit", __next40pxDefaultSize: true, children: (0, import_i18n.__)("Apply") } ) }) ] } ) ] } ) } ); } //# sourceMappingURL=modal.js.map