UNPKG

@wordpress/block-editor

Version:
254 lines (252 loc) 11.8 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-lock/modal.js var modal_exports = {}; __export(modal_exports, { default: () => BlockLockModal }); module.exports = __toCommonJS(modal_exports); var import_i18n = require("@wordpress/i18n"); var import_element = require("@wordpress/element"); var import_components = require("@wordpress/components"); var import_icons = require("@wordpress/icons"); var import_data = require("@wordpress/data"); var import_blocks = require("@wordpress/blocks"); var import_use_block_lock = __toESM(require("./use-block-lock")); var import_use_block_display_information = __toESM(require("../use-block-display-information")); var import_store = require("../../store"); var import_jsx_runtime = require("react/jsx-runtime"); var ALLOWS_EDIT_LOCKING = ["core/navigation"]; function getTemplateLockValue(lock) { if (lock.remove && lock.move) { return "all"; } if (lock.remove && !lock.move) { return "insert"; } return false; } function BlockLockModal({ clientId, onClose }) { const [lock, setLock] = (0, import_element.useState)({ move: false, remove: false }); const { isEditLocked, isMoveLocked, isRemoveLocked } = (0, import_use_block_lock.default)(clientId); const { allowsEditLocking, templateLock, hasTemplateLock } = (0, import_data.useSelect)( (select) => { const { getBlockName, getBlockAttributes } = select(import_store.store); const blockName = getBlockName(clientId); const blockType = (0, import_blocks.getBlockType)(blockName); return { allowsEditLocking: ALLOWS_EDIT_LOCKING.includes(blockName), templateLock: getBlockAttributes(clientId)?.templateLock, hasTemplateLock: !!blockType?.attributes?.templateLock }; }, [clientId] ); const [applyTemplateLock, setApplyTemplateLock] = (0, import_element.useState)( !!templateLock ); const { updateBlockAttributes } = (0, import_data.useDispatch)(import_store.store); const blockInformation = (0, import_use_block_display_information.default)(clientId); (0, import_element.useEffect)(() => { setLock({ move: isMoveLocked, remove: isRemoveLocked, ...allowsEditLocking ? { edit: isEditLocked } : {} }); }, [isEditLocked, isMoveLocked, isRemoveLocked, allowsEditLocking]); const isAllChecked = Object.values(lock).every(Boolean); const isMixed = Object.values(lock).some(Boolean) && !isAllChecked; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Modal, { title: (0, import_i18n.sprintf)( /* translators: %s: Name of the block. */ (0, import_i18n.__)("Lock %s"), blockInformation.title ), overlayClassName: "block-editor-block-lock-modal", onRequestClose: onClose, size: "small", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "form", { onSubmit: (event) => { event.preventDefault(); updateBlockAttributes([clientId], { lock, templateLock: applyTemplateLock ? getTemplateLockValue(lock) : void 0 }); onClose(); }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { className: "block-editor-block-lock-modal__options", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: (0, import_i18n.__)("Select the features you want to lock") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "ul", { role: "list", className: "block-editor-block-lock-modal__checklist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.CheckboxControl, { __nextHasNoMarginBottom: true, className: "block-editor-block-lock-modal__options-all", label: (0, import_i18n.__)("Lock all"), checked: isAllChecked, indeterminate: isMixed, onChange: (newValue) => setLock({ move: newValue, remove: newValue, ...allowsEditLocking ? { edit: newValue } : {} }) } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "ul", { role: "list", className: "block-editor-block-lock-modal__checklist", children: [ allowsEditLocking && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: "block-editor-block-lock-modal__checklist-item", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.CheckboxControl, { __nextHasNoMarginBottom: true, label: (0, import_i18n.__)("Lock editing"), checked: !!lock.edit, onChange: (edit) => setLock((prevLock) => ({ ...prevLock, edit })) } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Icon, { className: "block-editor-block-lock-modal__lock-icon", icon: lock.edit ? import_icons.lock : import_icons.unlock } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: "block-editor-block-lock-modal__checklist-item", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.CheckboxControl, { __nextHasNoMarginBottom: true, label: (0, import_i18n.__)("Lock movement"), checked: lock.move, onChange: (move) => setLock((prevLock) => ({ ...prevLock, move })) } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Icon, { className: "block-editor-block-lock-modal__lock-icon", icon: lock.move ? import_icons.lock : import_icons.unlock } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: "block-editor-block-lock-modal__checklist-item", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.CheckboxControl, { __nextHasNoMarginBottom: true, label: (0, import_i18n.__)("Lock removal"), checked: lock.remove, onChange: (remove) => setLock((prevLock) => ({ ...prevLock, remove })) } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Icon, { className: "block-editor-block-lock-modal__lock-icon", icon: lock.remove ? import_icons.lock : import_icons.unlock } ) ] }) ] } ) ] }) } ), hasTemplateLock && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.ToggleControl, { __nextHasNoMarginBottom: true, className: "block-editor-block-lock-modal__template-lock", label: (0, import_i18n.__)("Apply to all blocks inside"), checked: applyTemplateLock, disabled: lock.move && !lock.remove, onChange: () => setApplyTemplateLock(!applyTemplateLock) } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.Flex, { className: "block-editor-block-lock-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