@mui/x-tree-view
Version:
The community edition of the MUI X Tree View components.
106 lines (95 loc) • 6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectorItemParentId = exports.selectorItemOrderedChildrenIds = exports.selectorItemModel = exports.selectorItemMetaLookup = exports.selectorItemMeta = exports.selectorItemIndex = exports.selectorItemDepth = exports.selectorIsTreeViewLoading = exports.selectorIsItemDisabled = exports.selectorGetTreeViewError = exports.selectorDisabledItemFocusable = exports.selectorCanItemBeFocused = void 0;
var _selectors = require("../../utils/selectors");
var _useTreeViewItems = require("./useTreeViewItems.utils");
const selectorTreeViewItemsState = state => state.items;
/**
* Get the loading state for the Tree View.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @returns {boolean} The loading state for the Tree View.
*/
const selectorIsTreeViewLoading = exports.selectorIsTreeViewLoading = (0, _selectors.createSelector)(selectorTreeViewItemsState, items => items.loading);
/**
* Get the error state for the Tree View.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @returns {boolean} The error state for the Tree View.
*/
const selectorGetTreeViewError = exports.selectorGetTreeViewError = (0, _selectors.createSelector)(selectorTreeViewItemsState, items => items.error);
/**
* Get the meta-information of all items.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @returns {TreeViewItemMetaLookup} The meta-information of all items.
*/
const selectorItemMetaLookup = exports.selectorItemMetaLookup = (0, _selectors.createSelector)(selectorTreeViewItemsState, items => items.itemMetaLookup);
const EMPTY_CHILDREN = [];
/**
* Get the ordered children ids of a given item.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to get the children of.
* @returns {TreeViewItemId[]} The ordered children ids of the item.
*/
const selectorItemOrderedChildrenIds = exports.selectorItemOrderedChildrenIds = (0, _selectors.createSelector)([selectorTreeViewItemsState, (_, itemId) => itemId], (itemsState, itemId) => itemsState.itemOrderedChildrenIdsLookup[itemId ?? _useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID] ?? EMPTY_CHILDREN);
/**
* Get the model of an item.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to get the model of.
* @returns {R} The model of the item.
*/
const selectorItemModel = exports.selectorItemModel = (0, _selectors.createSelector)([selectorTreeViewItemsState, (_, itemId) => itemId], (itemsState, itemId) => itemsState.itemModelLookup[itemId]);
/**
* Get the meta-information of an item.
* Check the `TreeViewItemMeta` type for more information.
* @param {TreeViewState<[UseTreeViewItemsSignature]>}
* @param {TreeViewItemId} itemId The id of the item to get the meta-information of.
* @returns {TreeViewItemMeta | null} The meta-information of the item.
*/
const selectorItemMeta = exports.selectorItemMeta = (0, _selectors.createSelector)([selectorItemMetaLookup, (_, itemId) => itemId], (itemMetaLookup, itemId) => itemMetaLookup[itemId ?? _useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID] ?? null);
/**
* Check if an item is disabled.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to check.
* @returns {boolean} `true` if the item is disabled, `false` otherwise.
*/
const selectorIsItemDisabled = exports.selectorIsItemDisabled = (0, _selectors.createSelector)([selectorItemMetaLookup, (_, itemId) => itemId], _useTreeViewItems.isItemDisabled);
/**
* Get the index of an item in its parent's children.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to get the index of.
* @returns {number} The index of the item in its parent's children.
*/
const selectorItemIndex = exports.selectorItemIndex = (0, _selectors.createSelector)([selectorTreeViewItemsState, selectorItemMeta], (itemsState, itemMeta) => {
if (itemMeta == null) {
return -1;
}
const parentIndexes = itemsState.itemChildrenIndexesLookup[itemMeta.parentId ?? _useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID];
return parentIndexes[itemMeta.id];
});
/**
* Get the id of the parent of an item.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to get the parent id of.
* @returns {TreeViewItemId | null} The id of the parent of the item.
*/
const selectorItemParentId = exports.selectorItemParentId = (0, _selectors.createSelector)([selectorItemMeta], itemMeta => itemMeta?.parentId ?? null);
/**
* Get the depth of an item (items at the root level have a depth of 0).
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to get the depth of.
* @returns {number} The depth of the item.
*/
const selectorItemDepth = exports.selectorItemDepth = (0, _selectors.createSelector)([selectorItemMeta], itemMeta => itemMeta?.depth ?? 0);
/**
* Check if the disabled items are focusable.
* @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
* @returns {boolean} Whether the disabled items are focusable.
*/
const selectorDisabledItemFocusable = exports.selectorDisabledItemFocusable = (0, _selectors.createSelector)([selectorTreeViewItemsState], itemsState => itemsState.disabledItemsFocusable);
const selectorCanItemBeFocused = exports.selectorCanItemBeFocused = (0, _selectors.createSelector)([selectorDisabledItemFocusable, selectorIsItemDisabled], (disabledItemsFocusable, isDisabled) => {
if (disabledItemsFocusable) {
return true;
}
return !isDisabled;
});