UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

64 lines 2.42 kB
import { createSelector } from '@mui/x-internals/store'; import { isItemDisabled, TREE_VIEW_ROOT_PARENT_ID } from "./utils.js"; const EMPTY_CHILDREN = []; export const itemsSelectors = { /** * Gets the DOM structure of the Tree View. */ domStructure: createSelector(state => state.domStructure), /** * Checks whether the disabled items are focusable. */ disabledItemFocusable: createSelector(state => state.disabledItemsFocusable), /** * Gets the meta-information of all items. */ itemMetaLookup: createSelector(state => state.itemMetaLookup), /** * Gets the ordered children ids of all items. */ itemOrderedChildrenIdsLookup: createSelector(state => state.itemOrderedChildrenIdsLookup), /** * Gets the meta-information of an item. */ itemMeta: createSelector((state, itemId) => state.itemMetaLookup[itemId ?? TREE_VIEW_ROOT_PARENT_ID] ?? null), /** * Gets the ordered children ids of an item. */ itemOrderedChildrenIds: createSelector((state, itemId) => state.itemOrderedChildrenIdsLookup[itemId ?? TREE_VIEW_ROOT_PARENT_ID] ?? EMPTY_CHILDREN), /** * Gets the model of an item. */ itemModel: createSelector((state, itemId) => state.itemModelLookup[itemId]), /** * Checks whether an item is disabled. */ isItemDisabled: createSelector((state, itemId) => isItemDisabled(state.itemMetaLookup, itemId)), /** * Gets the index of an item in its parent's children. */ itemIndex: createSelector((state, itemId) => { const itemMeta = state.itemMetaLookup[itemId]; if (itemMeta == null) { return -1; } const parentIndexes = state.itemChildrenIndexesLookup[itemMeta.parentId ?? TREE_VIEW_ROOT_PARENT_ID]; return parentIndexes[itemMeta.id]; }), /** * Gets the id of an item's parent. */ itemParentId: createSelector((state, itemId) => state.itemMetaLookup[itemId]?.parentId ?? null), /** * Gets the depth of an item (items at the root level have a depth of 0). */ itemDepth: createSelector((state, itemId) => state.itemMetaLookup[itemId]?.depth ?? 0), /** * Checks whether an item can be focused. */ canItemBeFocused: createSelector((state, itemId) => state.disabledItemsFocusable || !isItemDisabled(state.itemMetaLookup, itemId)), /** * Gets the identation between an item and its children. */ itemChildrenIndentation: createSelector(state => state.itemChildrenIndentation) };