react-magma-dom 4.7.0-next.53 → 4.7.0-next.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,3 +4,4 @@ export * from './useTreeItem';
4
4
  export * from './useTreeView';
5
5
  export * from './utils';
6
6
  export * from './types';
7
+ export { TreeItemSelectedInterface, TreeViewApi } from './useTreeView';
@@ -6,6 +6,8 @@ export interface TreeViewApi {
6
6
  selectItem({ itemId, checkedStatus, }: Pick<TreeViewItemInterface, 'itemId' | 'checkedStatus'>): void;
7
7
  selectAll(): void;
8
8
  clearAll(): void;
9
+ showMore(): void;
10
+ showLess(): void;
9
11
  }
10
12
  export interface UseTreeViewProps {
11
13
  /**
@@ -73,6 +75,8 @@ export interface UseTreeViewProps {
73
75
  * selectItem({ itemId, checkedStatus }: Pick<TreeViewItemInterface, 'itemId' | 'checkedStatus'>): void - action that allows to change item selection,
74
76
  * selectAll(): void - action that allows to select all items,
75
77
  * clearAll(): void - action that allows to unselect all items.
78
+ * showMore(): void - action that gets called when a tree has hidden items and they get expanded.
79
+ * showLess(): void - action that gets called when a tree has hidden items and they get collapsed.
76
80
  */
77
81
  apiRef?: React.MutableRefObject<TreeViewApi | undefined>;
78
82
  /**
package/dist/esm/index.js CHANGED
@@ -28925,6 +28925,7 @@ function useTreeView(props) {
28925
28925
  }),
28926
28926
  hasIcons = _React$useState2[0];
28927
28927
  var selectedItems = useMemo(function () {
28928
+ console.log(items);
28928
28929
  return items.filter(function (item) {
28929
28930
  return item.checkedStatus === IndeterminateCheckboxStatus.checked;
28930
28931
  });
@@ -28956,7 +28957,12 @@ function useTreeView(props) {
28956
28957
  }, [items]);
28957
28958
  var prevSelectedItemsRef = useRef(null);
28958
28959
  var prevPreselectedItemsRef = useRef(preselectedItems);
28960
+ var prevChildrenRef = useRef(children);
28959
28961
  var initializationRef = useRef(true);
28962
+ // Used for showAll button
28963
+ var _React$useState3 = useState(null),
28964
+ itemsNeedUpdate = _React$useState3[0],
28965
+ setItemsNeedUpdate = _React$useState3[1];
28960
28966
  useEffect(function () {
28961
28967
  if (isEqualArrays(prevPreselectedItemsRef.current, preselectedItems)) {
28962
28968
  return;
@@ -29063,20 +29069,13 @@ function useTreeView(props) {
29063
29069
  if ([TreeViewSelectable.single, TreeViewSelectable.single].includes(selectable) || isDisabled) {
29064
29070
  return;
29065
29071
  }
29066
- setItems(function (prevItems) {
29067
- return toggleAllMulti({
29068
- items: items,
29069
- checkedStatus: IndeterminateCheckboxStatus.checked,
29070
- checkChildren: checkChildren,
29071
- checkParents: checkParents
29072
- });
29073
- });
29072
+ this.showMore(true);
29074
29073
  },
29075
29074
  clearAll: function clearAll() {
29076
29075
  if (isDisabled) {
29077
29076
  return;
29078
29077
  }
29079
- setItems(function (prevItems) {
29078
+ setItems(function () {
29080
29079
  return toggleAllMulti({
29081
29080
  items: items,
29082
29081
  checkedStatus: IndeterminateCheckboxStatus.unchecked,
@@ -29084,13 +29083,54 @@ function useTreeView(props) {
29084
29083
  checkParents: checkParents
29085
29084
  });
29086
29085
  });
29086
+ },
29087
+ showMore: function showMore(fromSelectAll) {
29088
+ if (fromSelectAll === void 0) {
29089
+ fromSelectAll = false;
29090
+ }
29091
+ if (fromSelectAll) {
29092
+ setItems(function () {
29093
+ return toggleAllMulti({
29094
+ items: items,
29095
+ checkedStatus: IndeterminateCheckboxStatus.checked,
29096
+ checkChildren: checkChildren,
29097
+ checkParents: checkParents
29098
+ });
29099
+ });
29100
+ } else {
29101
+ setItemsNeedUpdate(true);
29102
+ }
29103
+ },
29104
+ showLess: function showLess() {
29105
+ setItems(getInitialItems({
29106
+ children: children,
29107
+ preselectedItems: selectedItems,
29108
+ checkParents: checkParents,
29109
+ checkChildren: checkChildren,
29110
+ selectable: selectable,
29111
+ isDisabled: isDisabled
29112
+ }));
29087
29113
  }
29088
29114
  };
29089
29115
  }
29090
- }, [selectItem, isDisabled]);
29091
- var _React$useState3 = useState(false),
29092
- initialExpandedItemsNeedUpdate = _React$useState3[0],
29093
- setInitialExpandedItemsNeedUpdate = _React$useState3[1];
29116
+ }, [selectItem, isDisabled, children]);
29117
+ useEffect(function () {
29118
+ if (itemsNeedUpdate) {
29119
+ setItems(getInitialItems({
29120
+ children: children,
29121
+ preselectedItems: selectedItems,
29122
+ checkParents: checkParents,
29123
+ checkChildren: checkChildren,
29124
+ selectable: selectable,
29125
+ isDisabled: isDisabled
29126
+ }));
29127
+ prevChildrenRef.current = children;
29128
+ setItemsNeedUpdate(false);
29129
+ }
29130
+ }, [itemsNeedUpdate, children]);
29131
+ var _React$useState4 = useState(false),
29132
+ initialExpandedItemsNeedUpdate = _React$useState4[0],
29133
+ setInitialExpandedItemsNeedUpdate = _React$useState4[1];
29094
29134
  var _useDescendants = useDescendants(),
29095
29135
  treeItemRefArray = _useDescendants[0],
29096
29136
  registerTreeItem = _useDescendants[1];
@@ -29099,9 +29139,9 @@ function useTreeView(props) {
29099
29139
  setInitialExpandedItemsNeedUpdate(true);
29100
29140
  }
29101
29141
  }, []);
29102
- var _React$useState4 = useState(new Set(initialExpandedItems)),
29103
- expandedSet = _React$useState4[0],
29104
- setExpandedSet = _React$useState4[1];
29142
+ var _React$useState5 = useState(new Set(initialExpandedItems)),
29143
+ expandedSet = _React$useState5[0],
29144
+ setExpandedSet = _React$useState5[1];
29105
29145
  var handleExpandedChange = function handleExpandedChange(event, itemId) {
29106
29146
  setExpandedSet(function (prevExpandedSet) {
29107
29147
  var updatedExpandedSet = new Set(prevExpandedSet);