UNPKG

@wordpress/block-editor

Version:
85 lines (77 loc) 3.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useInspectorControlsTabs; var _components = require("@wordpress/components"); var _data = require("@wordpress/data"); var _groups = _interopRequireDefault(require("../inspector-controls/groups")); var _useIsListViewTabDisabled = _interopRequireDefault(require("./use-is-list-view-tab-disabled")); var _inspectorControls = require("../inspector-controls"); var _utils = require("./utils"); var _store = require("../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ const EMPTY_ARRAY = []; function getShowTabs(blockName, tabSettings = {}) { // Block specific setting takes precedence over generic default. if (tabSettings[blockName] !== undefined) { return tabSettings[blockName]; } // Use generic default if set over the Gutenberg experiment option. if (tabSettings.default !== undefined) { return tabSettings.default; } return true; } function useInspectorControlsTabs(blockName) { const tabs = []; const { bindings: bindingsGroup, border: borderGroup, color: colorGroup, default: defaultGroup, dimensions: dimensionsGroup, list: listGroup, position: positionGroup, styles: stylesGroup, typography: typographyGroup, effects: effectsGroup } = _groups.default; // List View Tab: If there are any fills for the list group add that tab. const listViewDisabled = (0, _useIsListViewTabDisabled.default)(blockName); const listFills = (0, _components.__experimentalUseSlotFills)(listGroup.name); const hasListFills = !listViewDisabled && !!listFills && listFills.length; // Styles Tab: Add this tab if there are any fills for block supports // e.g. border, color, spacing, typography, etc. const styleFills = [...((0, _components.__experimentalUseSlotFills)(borderGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(colorGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(dimensionsGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(stylesGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(typographyGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(effectsGroup.name) || [])]; const hasStyleFills = styleFills.length; // Settings Tab: If we don't have multiple tabs to display // (i.e. both list view and styles), check only the default and position // InspectorControls slots. If we have multiple tabs, we'll need to check // the advanced controls slot as well to ensure they are rendered. const advancedFills = [...((0, _components.__experimentalUseSlotFills)(_inspectorControls.InspectorAdvancedControls.slotName) || []), ...((0, _components.__experimentalUseSlotFills)(bindingsGroup.name) || [])]; const settingsFills = [...((0, _components.__experimentalUseSlotFills)(defaultGroup.name) || []), ...((0, _components.__experimentalUseSlotFills)(positionGroup.name) || []), ...(hasListFills && hasStyleFills > 1 ? advancedFills : [])]; // Add the tabs in the order that they will default to if available. // List View > Settings > Styles. if (hasListFills) { tabs.push(_utils.TAB_LIST_VIEW); } if (settingsFills.length) { tabs.push(_utils.TAB_SETTINGS); } if (hasStyleFills) { tabs.push(_utils.TAB_STYLES); } const tabSettings = (0, _data.useSelect)(select => { return select(_store.store).getSettings().blockInspectorTabs; }, []); const showTabs = getShowTabs(blockName, tabSettings); return showTabs ? tabs : EMPTY_ARRAY; } //# sourceMappingURL=use-inspector-controls-tabs.js.map