@mui/x-tree-view
Version:
The community edition of the MUI X Tree View components.
72 lines (71 loc) • 2.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectionSelectors = void 0;
var _store = require("@mui/x-internals/store");
var _selectors = require("../items/selectors");
const selectedItemsSelector = (0, _store.createSelectorMemoized)(state => state.selectedItems, selectedItemsRaw => {
if (Array.isArray(selectedItemsRaw)) {
return selectedItemsRaw;
}
if (selectedItemsRaw != null) {
return [selectedItemsRaw];
}
return [];
});
const selectedItemsMapSelector = (0, _store.createSelectorMemoized)(selectedItemsSelector, selectedItems => {
const selectedItemsMap = new Map();
selectedItems.forEach(id => {
selectedItemsMap.set(id, true);
});
return selectedItemsMap;
});
const isItemSelectableSelector = (0, _store.createSelector)((state, itemId) => state.itemMetaLookup[itemId]?.selectable ?? true);
const selectionSelectors = exports.selectionSelectors = {
/**
* Gets the selected items as provided to the component.
*/
selectedItemsRaw: (0, _store.createSelector)(state => state.selectedItems),
/**
* Gets the selected items as an array.
*/
selectedItems: selectedItemsSelector,
/**
* Gets the selected items as a Map.
*/
selectedItemsMap: selectedItemsMapSelector,
/**
* Checks whether selection is enabled.
*/
enabled: (0, _store.createSelector)(state => !state.disableSelection),
/**
* Checks whether multi selection is enabled.
*/
isMultiSelectEnabled: (0, _store.createSelector)(state => state.multiSelect),
/**
* Checks whether checkbox selection is enabled.
*/
isCheckboxSelectionEnabled: (0, _store.createSelector)(state => state.checkboxSelection),
/**
* Gets the selection propagation rules.
*/
propagationRules: (0, _store.createSelector)(state => state.selectionPropagation),
/**
* Checks whether an item is selected.
*/
isItemSelected: (0, _store.createSelector)(selectedItemsMapSelector, (selectedItemsMap, itemId) => selectedItemsMap.has(itemId)),
/**
* Checks whether the selection feature is enabled for an item.
* Returns `true` when selection is enabled on the Tree View and the item is selectable (even if the item is disabled).
*/
isFeatureEnabledForItem: (0, _store.createSelector)(isItemSelectableSelector, state => !state.disableSelection, (isItemSelectable, isSelectionEnabled, _itemId) => isSelectionEnabled && isItemSelectable),
/**
* Checks whether an item can be selected (if selection is enabled, if the item is not disabled, and if the item is selectable).
*/
canItemBeSelected: (0, _store.createSelector)(_selectors.itemsSelectors.isItemDisabled, isItemSelectableSelector, state => !state.disableSelection, (isItemDisabled, isItemSelectable, isSelectionEnabled, _itemId) => isSelectionEnabled && !isItemDisabled && isItemSelectable),
/**
* Checks whether an item is selectable based on the `isItemSelectionDisabled` prop.
*/
isItemSelectable: isItemSelectableSelector
};