@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
20 lines • 1.59 kB
JavaScript
import { findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
const getIsFormatMenuHidden = (selection, schema) => {
const nodes = schema.nodes;
if (!nodes) {
return false;
}
const disabledOnNodes = [nodes.rule];
const disabledNode = findSelectedNodeOfType(disabledOnNodes)(selection);
return !!disabledNode;
};
export const checkIsFormatMenuHidden = api => {
var _api$selection, _api$selection$shared, _api$selection$shared2, _api$core$sharedState, _api$blockControls, _api$blockControls$sh;
const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
const schema = api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
const menuTriggerBy = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.menuTriggerBy;
if (!selection || !schema || !menuTriggerBy) {
return false;
}
return getIsFormatMenuHidden(selection, schema);
};