UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

47 lines (44 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isItemDisabled = exports.buildSiblingIndexes = exports.TREE_VIEW_ROOT_PARENT_ID = void 0; const TREE_VIEW_ROOT_PARENT_ID = exports.TREE_VIEW_ROOT_PARENT_ID = '__TREE_VIEW_ROOT_PARENT_ID__'; const buildSiblingIndexes = siblings => { const siblingsIndexLookup = {}; siblings.forEach((childId, index) => { siblingsIndexLookup[childId] = index; }); return siblingsIndexLookup; }; /** * Check if an item is disabled. * This method should only be used in selectors that are checking if several items are disabled. * Otherwise, use the `selectorIsItemDisabled` selector. * @returns */ exports.buildSiblingIndexes = buildSiblingIndexes; const isItemDisabled = (itemMetaLookup, itemId) => { if (itemId == null) { return false; } let itemMeta = itemMetaLookup[itemId]; // This can be called before the item has been added to the item map. if (!itemMeta) { return false; } if (itemMeta.disabled) { return true; } while (itemMeta.parentId != null) { itemMeta = itemMetaLookup[itemMeta.parentId]; if (!itemMeta) { return false; } if (itemMeta.disabled) { return true; } } return false; }; exports.isItemDisabled = isItemDisabled;