@mui/x-tree-view
Version:
The community edition of the MUI X Tree View components.
67 lines • 2.3 kB
JavaScript
import { isItemDisabled, TREE_VIEW_ROOT_PARENT_ID } from "./utils.mjs";
const EMPTY_CHILDREN = [];
export const itemsSelectors = {
/**
* Gets the DOM structure of the Tree View.
*/
domStructure: state => state.domStructure,
/**
* Checks whether the disabled items are focusable.
*/
disabledItemFocusable: state => state.disabledItemsFocusable,
/**
* Gets the meta-information of all items.
*/
itemMetaLookup: state => state.itemMetaLookup,
/**
* Gets the ordered children ids of all items.
*/
itemOrderedChildrenIdsLookup: state => state.itemOrderedChildrenIdsLookup,
/**
* Gets the meta-information of an item.
*/
itemMeta: (state, itemId) => state.itemMetaLookup[itemId ?? TREE_VIEW_ROOT_PARENT_ID] ?? null,
/**
* Gets the ordered children ids of an item.
*/
itemOrderedChildrenIds: (state, itemId) => state.itemOrderedChildrenIdsLookup[itemId ?? TREE_VIEW_ROOT_PARENT_ID] ?? EMPTY_CHILDREN,
/**
* Gets the model of an item.
*/
itemModel: (state, itemId) => state.itemModelLookup[itemId],
/**
* Checks whether an item is disabled.
*/
isItemDisabled: (state, itemId) => isItemDisabled(state.itemMetaLookup, itemId),
/**
* Gets the index of an item in its parent's children.
*/
itemIndex: (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: (state, itemId) => state.itemMetaLookup[itemId]?.parentId ?? null,
/**
* Gets the depth of an item (items at the root level have a depth of 0).
*/
itemDepth: (state, itemId) => state.itemMetaLookup[itemId]?.depth ?? 0,
/**
* Checks whether an item can be focused.
*/
canItemBeFocused: (state, itemId) => state.disabledItemsFocusable || state.itemModelLookup[itemId] != null && !isItemDisabled(state.itemMetaLookup, itemId),
/**
* Gets the identation between an item and its children.
*/
itemChildrenIndentation: state => state.itemChildrenIndentation,
/**
* Gets the height of an individual item.
*/
itemHeight: state => state.itemHeight
};