UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

40 lines (36 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectorIsItemEditable = exports.selectorIsItemBeingEdited = exports.selectorIsAnyItemBeingEdited = void 0; var _selectors = require("../../utils/selectors"); var _useTreeViewItems = require("../useTreeViewItems/useTreeViewItems.selectors"); 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. */ const selectorIsItemEditable = exports.selectorIsItemEditable = (0, _selectors.createSelector)([selectorTreeViewLabelState, (state, itemId) => (0, _useTreeViewItems.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. */ const selectorIsItemBeingEdited = exports.selectorIsItemBeingEdited = (0, _selectors.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. */ const selectorIsAnyItemBeingEdited = exports.selectorIsAnyItemBeingEdited = (0, _selectors.createSelector)(selectorTreeViewLabelState, labelState => !!labelState?.editedItemId);