UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

25 lines 1.84 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import memoizeOne from 'memoize-one'; import { findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; var getDisabledNodeTypes = memoizeOne(function (nodes) { return [nodes.rule].concat(_toConsumableArray(expValEquals('confluence_native_tabs_experiment', 'isEnabled', true) ? [nodes.multiBodiedExtension] : [])); }); var getIsFormatMenuHidden = function getIsFormatMenuHidden(selection, schema) { var nodes = schema.nodes; if (!nodes) { return false; } var disabledNode = findSelectedNodeOfType(getDisabledNodeTypes(nodes))(selection); return !!disabledNode; }; export var checkIsFormatMenuHidden = function checkIsFormatMenuHidden(api) { var _api$selection, _api$core$sharedState, _api$blockControls; var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection; var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema; var menuTriggerBy = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.menuTriggerBy; if (!selection || !schema || !menuTriggerBy) { return false; } return getIsFormatMenuHidden(selection, schema); };