UNPKG

@atlaskit/editor-plugin-paste-options-toolbar

Version:

Paste options toolbar for @atlaskit/editor-core

42 lines (39 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasVisibleButton = exports.getVisibleKeys = void 0; var _isComponentOrAncestorHidden = function isComponentOrAncestorHidden(component, componentsByKey) { var _component$isHidden, _component$parents; if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) { return true; } return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(function (parent) { var parentComponent = componentsByKey.get(parent.key); return parentComponent ? _isComponentOrAncestorHidden(parentComponent, componentsByKey) : false; }); }; /** * Returns the keys of visible button/menu-item components in the list. * A component is visible when neither it nor any of its ancestors are hidden. */ var getVisibleKeys = exports.getVisibleKeys = function getVisibleKeys(components) { var types = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['menu-item']; var componentsByKey = new Map(components.map(function (c) { return [c.key, c]; })); return components.filter(function (c) { return types.includes(c.type); }).filter(function (c) { return !_isComponentOrAncestorHidden(c, componentsByKey); }).map(function (c) { return c.key; }); }; /** * Returns true when at least one menu-item button in the list is visible. * A button is visible when neither it nor any of its ancestors are hidden. */ var hasVisibleButton = exports.hasVisibleButton = function hasVisibleButton(components) { return getVisibleKeys(components).length > 0; };