@mui/x-tree-view
Version:
The community edition of the MUI X Tree View components.
87 lines (77 loc) • 4.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectorSelectionPropagationRules = exports.selectorSelectionModelArray = exports.selectorSelectionModel = exports.selectorIsSelectionEnabled = exports.selectorIsMultiSelectEnabled = exports.selectorIsItemSelectionEnabled = exports.selectorIsItemSelected = exports.selectorIsCheckboxSelectionEnabled = void 0;
var _selectors = require("../../utils/selectors");
var _useTreeViewItems = require("../useTreeViewItems/useTreeViewItems.selectors");
const selectorTreeViewSelectionState = state => state.selection;
/**
* Get the selected items.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {TreeViewSelectionValue<boolean>} The selected items.
*/
const selectorSelectionModel = exports.selectorSelectionModel = (0, _selectors.createSelector)([selectorTreeViewSelectionState], selectionState => selectionState.selectedItems);
/**
* Get the selected items as an array.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {TreeViewItemId[]} The selected items as an array.
*/
const selectorSelectionModelArray = exports.selectorSelectionModelArray = (0, _selectors.createSelector)([selectorSelectionModel], selectedItems => {
if (Array.isArray(selectedItems)) {
return selectedItems;
}
if (selectedItems != null) {
return [selectedItems];
}
return [];
});
/**
* Get the selected items as a map.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {Map<TreeViewItemId, true>} The selected items as a Map.
*/
const selectorSelectionModelMap = (0, _selectors.createSelector)([selectorSelectionModelArray], selectedItems => {
const selectedItemsMap = new Map();
selectedItems.forEach(id => {
selectedItemsMap.set(id, true);
});
return selectedItemsMap;
});
/**
* Check if an item is selected.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {boolean} `true` if the item is selected, `false` otherwise.
*/
const selectorIsItemSelected = exports.selectorIsItemSelected = (0, _selectors.createSelector)([selectorSelectionModelMap, (_, itemId) => itemId], (selectedItemsMap, itemId) => selectedItemsMap.has(itemId));
/**
* Check if multi selection is enabled.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {boolean} `true` if multi selection is enabled, `false` otherwise.
*/
const selectorIsMultiSelectEnabled = exports.selectorIsMultiSelectEnabled = (0, _selectors.createSelector)([selectorTreeViewSelectionState], selectionState => selectionState.isEnabled && selectionState.isMultiSelectEnabled);
/**
* Check if selection is enabled.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {boolean} `true` if selection is enabled, `false` otherwise.
*/
const selectorIsSelectionEnabled = exports.selectorIsSelectionEnabled = (0, _selectors.createSelector)([selectorTreeViewSelectionState], selectionState => selectionState.isEnabled);
/**
* Check if checkbox selection is enabled.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {boolean} `true` if checkbox selection is enabled, `false` otherwise.
*/
const selectorIsCheckboxSelectionEnabled = exports.selectorIsCheckboxSelectionEnabled = (0, _selectors.createSelector)([selectorTreeViewSelectionState], selectionState => selectionState.isCheckboxSelectionEnabled);
/**
* Check if selection is enabled for an item (if selection is enabled and if the item is not disabled).
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @param {string} itemId The id of the item to check.
* @returns {boolean} `true` if selection is enabled for the item, `false` otherwise.
*/
const selectorIsItemSelectionEnabled = exports.selectorIsItemSelectionEnabled = (0, _selectors.createSelector)([_useTreeViewItems.selectorIsItemDisabled, selectorIsSelectionEnabled], (isItemDisabled, isSelectionEnabled) => isSelectionEnabled && !isItemDisabled);
/**
* Get the selection propagation rules.
* @param {TreeViewState<[UseTreeViewSelectionSignature]>} state The state of the tree view.
* @returns {TreeViewSelectionPropagation} The selection propagation rules.
*/
const selectorSelectionPropagationRules = exports.selectorSelectionPropagationRules = (0, _selectors.createSelector)([selectorTreeViewSelectionState], selectionState => selectionState.selectionPropagation);