@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
61 lines (54 loc) • 2.47 kB
JavaScript
import { TRANSFORM_SUGGESTED_MENU_SECTION, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION } from '@atlaskit/editor-common/block-menu';
import { buildChildrenMap, getChildrenMapKey, willComponentRender } from '../block-menu-renderer/utils';
/**
* Checks if a section has any visible content (items that will render)
*/
var hasSectionContent = function hasSectionContent(sectionKey, api) {
var _api$blockMenu;
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
if (!blockMenuComponents) {
return false;
}
var childrenMap = buildChildrenMap(blockMenuComponents);
var sectionMapKey = getChildrenMapKey(sectionKey, 'block-menu-section');
var sectionChildren = childrenMap.get(sectionMapKey) || [];
return sectionChildren.some(function (child) {
return willComponentRender(child, childrenMap);
});
};
/**
* Checks if the Suggested section has any visible content
*/
export var hasSuggestedSectionContent = function hasSuggestedSectionContent(api) {
return hasSectionContent(TRANSFORM_SUGGESTED_MENU_SECTION.key, api);
};
/**
* Checks if the Create section has any visible content
*/
export var hasCreateSectionContent = function hasCreateSectionContent(api) {
return hasSectionContent(TRANSFORM_CREATE_MENU_SECTION.key, api);
};
/**
* Checks if the Structure section has any visible content
*/
export var hasStructureSectionContent = function hasStructureSectionContent(api) {
return hasSectionContent(TRANSFORM_STRUCTURE_MENU_SECTION.key, api);
};
/**
* Checks if there's any content before the Create section (i.e., Suggested section has content)
*/
export var hasContentBeforeCreate = function hasContentBeforeCreate(api) {
return hasSuggestedSectionContent(api);
};
/**
* Checks if there's any content before the Structure section (i.e., Create or Suggested sections have content)
*/
export var hasContentBeforeStructure = function hasContentBeforeStructure(api) {
return hasCreateSectionContent(api) || hasSuggestedSectionContent(api);
};
/**
* Checks if there's any content before the Headings section (i.e., Structure, Create, or Suggested sections have content)
*/
export var hasContentBeforeHeadings = function hasContentBeforeHeadings(api) {
return hasStructureSectionContent(api) || hasCreateSectionContent(api) || hasSuggestedSectionContent(api);
};