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