@atlaskit/editor-plugin-paste-options-toolbar
Version:
Paste options toolbar for @atlaskit/editor-core
27 lines (25 loc) • 1.27 kB
JavaScript
const 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(parent => {
const 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 const getVisibleKeys = (components, types = ['menu-item']) => {
const componentsByKey = new Map(components.map(c => [c.key, c]));
return components.filter(c => types.includes(c.type)).filter(c => !isComponentOrAncestorHidden(c, componentsByKey)).map(c => 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 const hasVisibleButton = components => {
return getVisibleKeys(components).length > 0;
};