UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

66 lines (59 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasSuggestedSectionContent = exports.hasStructureSectionContent = exports.hasCreateSectionContent = exports.hasContentBeforeStructure = exports.hasContentBeforeHeadings = exports.hasContentBeforeCreate = void 0; var _blockMenu = require("@atlaskit/editor-common/block-menu"); var _utils = require("../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 = (0, _utils.buildChildrenMap)(blockMenuComponents); var sectionMapKey = (0, _utils.getChildrenMapKey)(sectionKey, 'block-menu-section'); var sectionChildren = childrenMap.get(sectionMapKey) || []; return sectionChildren.some(function (child) { return (0, _utils.willComponentRender)(child, childrenMap); }); }; /** * Checks if the Suggested section has any visible content */ var hasSuggestedSectionContent = exports.hasSuggestedSectionContent = function hasSuggestedSectionContent(api) { return hasSectionContent(_blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION.key, api); }; /** * Checks if the Create section has any visible content */ var hasCreateSectionContent = exports.hasCreateSectionContent = function hasCreateSectionContent(api) { return hasSectionContent(_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key, api); }; /** * Checks if the Structure section has any visible content */ var hasStructureSectionContent = exports.hasStructureSectionContent = function hasStructureSectionContent(api) { return hasSectionContent(_blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key, api); }; /** * Checks if there's any content before the Create section (i.e., Suggested section has content) */ var hasContentBeforeCreate = exports.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) */ var hasContentBeforeStructure = exports.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) */ var hasContentBeforeHeadings = exports.hasContentBeforeHeadings = function hasContentBeforeHeadings(api) { return hasStructureSectionContent(api) || hasCreateSectionContent(api) || hasSuggestedSectionContent(api); };