@wordpress/block-editor
Version:
64 lines (60 loc) • 2.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ModifyContentLockMenuItem = ModifyContentLockMenuItem;
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
// The implementation of content locking is mainly in this file, although the mechanism
// to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect
// at block-editor/src/components/block-list/index.js.
// Besides the components on this file and the file referenced above the implementation
// also includes artifacts on the store (actions, reducers, and selector).
function ModifyContentLockMenuItem({
clientId,
onClose
}) {
const {
templateLock,
isLockedByParent,
isEditingAsBlocks
} = (0, _data.useSelect)(select => {
const {
getContentLockingParent,
getTemplateLock,
getTemporarilyEditingAsBlocks
} = (0, _lockUnlock.unlock)(select(_store.store));
return {
templateLock: getTemplateLock(clientId),
isLockedByParent: !!getContentLockingParent(clientId),
isEditingAsBlocks: getTemporarilyEditingAsBlocks() === clientId
};
}, [clientId]);
const blockEditorActions = (0, _data.useDispatch)(_store.store);
const isContentLocked = !isLockedByParent && templateLock === 'contentOnly';
if (!isContentLocked && !isEditingAsBlocks) {
return null;
}
const {
modifyContentLockBlock
} = (0, _lockUnlock.unlock)(blockEditorActions);
const showStartEditingAsBlocks = !isEditingAsBlocks && isContentLocked;
return showStartEditingAsBlocks && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
onClick: () => {
modifyContentLockBlock(clientId);
onClose();
},
children: (0, _i18n._x)('Modify', 'Unlock content locked blocks')
});
}
//# sourceMappingURL=modify-content-lock-menu-item.js.map
;