@wordpress/block-editor
Version:
72 lines (69 loc) • 2.41 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _store = require("../store");
var _components2 = require("../components");
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 ContentLockControlsPure({
clientId
}) {
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 {
stopEditingAsBlocks
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
const isContentLocked = !isLockedByParent && templateLock === 'contentOnly';
const stopEditingAsBlockCallback = (0, _element.useCallback)(() => {
stopEditingAsBlocks(clientId);
}, [clientId, stopEditingAsBlocks]);
if (!isContentLocked && !isEditingAsBlocks) {
return null;
}
const showStopEditingAsBlocks = isEditingAsBlocks && !isContentLocked;
return showStopEditingAsBlocks && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components2.BlockControls, {
group: "other",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
onClick: stopEditingAsBlockCallback,
children: (0, _i18n.__)('Done')
})
});
}
var _default = exports.default = {
edit: ContentLockControlsPure,
hasSupport() {
return true;
}
};
//# sourceMappingURL=content-lock-ui.js.map
;