UNPKG

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

Version:

Paste options toolbar for @atlaskit/editor-core

36 lines (34 loc) 1.53 kB
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. */ export var 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. */ export var hasVisibleButton = function hasVisibleButton(components) { return getVisibleKeys(components).length > 0; };