@wordpress/block-editor
Version:
46 lines (45 loc) • 1.72 kB
JavaScript
// packages/block-editor/src/components/content-lock/modify-content-lock-menu-item.js
import { MenuItem } from "@wordpress/components";
import { useDispatch, useSelect } from "@wordpress/data";
import { _x } from "@wordpress/i18n";
import { store as blockEditorStore } from "../../store";
import { unlock } from "../../lock-unlock";
import { jsx } from "react/jsx-runtime";
function ModifyContentOnlySectionMenuItem({ clientId, onClose }) {
const { templateLock, isLockedByParent, isEditingContentOnlySection } = useSelect(
(select) => {
const {
getContentLockingParent,
getTemplateLock,
getEditedContentOnlySection
} = unlock(select(blockEditorStore));
return {
templateLock: getTemplateLock(clientId),
isLockedByParent: !!getContentLockingParent(clientId),
isEditingContentOnlySection: getEditedContentOnlySection() === clientId
};
},
[clientId]
);
const blockEditorActions = useDispatch(blockEditorStore);
const isContentLocked = !isLockedByParent && templateLock === "contentOnly";
if (window?.__experimentalContentOnlyPatternInsertion || !isContentLocked && !isEditingContentOnlySection) {
return null;
}
const { editContentOnlySection } = unlock(blockEditorActions);
const showContentOnlyModifyButton = !isEditingContentOnlySection && isContentLocked;
return showContentOnlyModifyButton && /* @__PURE__ */ jsx(
MenuItem,
{
onClick: () => {
editContentOnlySection(clientId);
onClose();
},
children: _x("Modify", "Unlock content locked blocks")
}
);
}
export {
ModifyContentOnlySectionMenuItem
};
//# sourceMappingURL=modify-content-lock-menu-item.js.map