@mui/x-tree-view
Version:
The community edition of the MUI X Tree View components.
34 lines (31 loc) • 1.65 kB
JavaScript
import { createSelector } from "../../utils/selectors.js";
import { selectorItemModel } from "../useTreeViewItems/useTreeViewItems.selectors.js";
const selectorTreeViewLabelState = state => state.label;
/**
* Check if an item is editable.
* @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 editable, `false` otherwise.
*/
export const selectorIsItemEditable = createSelector([selectorTreeViewLabelState, (state, itemId) => selectorItemModel(state, itemId)], (labelState, itemModel) => {
if (!itemModel || !labelState) {
return false;
}
if (typeof labelState.isItemEditable === 'boolean') {
return labelState.isItemEditable;
}
return labelState.isItemEditable(itemModel);
});
/**
* Check if the given item is being edited.
* @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
* @param {TreeViewItemId} itemId The id of the item to check.
* @returns {boolean} `true` if the item is being edited, `false` otherwise.
*/
export const selectorIsItemBeingEdited = createSelector([selectorTreeViewLabelState, (_, itemId) => itemId], (labelState, itemId) => itemId ? labelState?.editedItemId === itemId : false);
/**
* Check if an item is being edited.
* @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
* @returns {boolean} `true` if an item is being edited, `false` otherwise.
*/
export const selectorIsAnyItemBeingEdited = createSelector(selectorTreeViewLabelState, labelState => !!labelState?.editedItemId);