schummar-table 0.10.3 → 0.10.4

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.
package/dist/es/index.js CHANGED
@@ -541,6 +541,35 @@ function filterColumns(state) {
541
541
  draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
542
542
  }, { runNow: true }), [state]);
543
543
  }
544
+ function normalizeExpanded(table) {
545
+ useEffect(() => table.addReaction((state) => [state.props.expandOnlyOne, state.expanded, state.itemsById], ([expandOnlyOne, , itemsById], state) => {
546
+ var _a, _b;
547
+ let expanded = state.expanded;
548
+ let last, lastItem;
549
+ let hasChanged = false;
550
+ if (expandOnlyOne && (last = [...expanded][expanded.size - 1]) && (lastItem = itemsById.get(last))) {
551
+ const ancestors = getAncestors(itemsById, lastItem);
552
+ if ([...expanded].slice(0, -1).some((id) => !ancestors.has(id))) {
553
+ expanded = state.expanded = new Set([...ancestors].concat(last));
554
+ hasChanged = true;
555
+ }
556
+ } else {
557
+ for (const id of expanded) {
558
+ const item = itemsById.get(id);
559
+ const ancestors = item && getAncestors(itemsById, item);
560
+ for (const ancestor of ancestors != null ? ancestors : []) {
561
+ if (!expanded.has(ancestor)) {
562
+ expanded.add(ancestor);
563
+ hasChanged = true;
564
+ }
565
+ }
566
+ }
567
+ }
568
+ if (hasChanged) {
569
+ (_b = (_a = state.props).onExpandedChange) == null ? void 0 : _b.call(_a, new Set(expanded));
570
+ }
571
+ }, { runNow: true }), [table]);
572
+ }
544
573
  function syncSelections(table) {
545
574
  useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
546
575
  if (!selectSyncChildren)
@@ -585,6 +614,7 @@ function useTableState(_props) {
585
614
  });
586
615
  }, []);
587
616
  filterColumns(state);
617
+ normalizeExpanded(state);
588
618
  calcItems(state);
589
619
  syncSelections(state);
590
620
  cleanupState(state);