UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

32 lines (31 loc) 2.17 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.checkIsFormatMenuHidden = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _memoizeOne = _interopRequireDefault(require("memoize-one")); var _utils = require("@atlaskit/editor-prosemirror/utils"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var getDisabledNodeTypes = (0, _memoizeOne.default)(function (nodes) { return [nodes.rule].concat((0, _toConsumableArray2.default)((0, _expValEquals.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 = (0, _utils.findSelectedNodeOfType)(getDisabledNodeTypes(nodes))(selection); return !!disabledNode; }; var checkIsFormatMenuHidden = exports.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); };