schummar-table 0.10.2 → 0.10.5
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,39 @@ 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, _c, _d, _e;
|
|
547
|
+
let expanded = state.expanded;
|
|
548
|
+
let hasChanged = false;
|
|
549
|
+
const allAncestors = [...expanded].map((id) => {
|
|
550
|
+
const item = itemsById.get(id);
|
|
551
|
+
return {
|
|
552
|
+
id,
|
|
553
|
+
ancestors: item ? getAncestors(itemsById, item) : /* @__PURE__ */ new Set()
|
|
554
|
+
};
|
|
555
|
+
});
|
|
556
|
+
if (expandOnlyOne) {
|
|
557
|
+
const withMostAncestors = orderBy(allAncestors, [(x) => x.ancestors.size], ["desc"])[0];
|
|
558
|
+
if ([...expanded].some((id) => id !== (withMostAncestors == null ? void 0 : withMostAncestors.id) && !(withMostAncestors == null ? void 0 : withMostAncestors.ancestors.has(id)))) {
|
|
559
|
+
expanded = state.expanded = (_a = withMostAncestors == null ? void 0 : withMostAncestors.ancestors) != null ? _a : /* @__PURE__ */ new Set();
|
|
560
|
+
(_c = (_b = state.props).onExpandedChange) == null ? void 0 : _c.call(_b, expanded);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
for (const { ancestors } of allAncestors) {
|
|
565
|
+
for (const ancestor of ancestors != null ? ancestors : []) {
|
|
566
|
+
if (!expanded.has(ancestor)) {
|
|
567
|
+
expanded.add(ancestor);
|
|
568
|
+
hasChanged = true;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (hasChanged) {
|
|
573
|
+
(_e = (_d = state.props).onExpandedChange) == null ? void 0 : _e.call(_d, new Set(expanded));
|
|
574
|
+
}
|
|
575
|
+
}, { runNow: true }), [table]);
|
|
576
|
+
}
|
|
544
577
|
function syncSelections(table) {
|
|
545
578
|
useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
|
|
546
579
|
if (!selectSyncChildren)
|
|
@@ -586,6 +619,7 @@ function useTableState(_props) {
|
|
|
586
619
|
}, []);
|
|
587
620
|
filterColumns(state);
|
|
588
621
|
calcItems(state);
|
|
622
|
+
normalizeExpanded(state);
|
|
589
623
|
syncSelections(state);
|
|
590
624
|
cleanupState(state);
|
|
591
625
|
useEffect(() => {
|
|
@@ -1266,17 +1300,18 @@ function ExpandControl({
|
|
|
1266
1300
|
activeItemsById
|
|
1267
1301
|
} = table.getState();
|
|
1268
1302
|
const newExpanded = new Set(expanded);
|
|
1269
|
-
if (expandOnlyOne)
|
|
1303
|
+
if (expandOnlyOne) {
|
|
1270
1304
|
newExpanded.clear();
|
|
1271
|
-
if (isExpanded)
|
|
1272
|
-
newExpanded.delete(itemId);
|
|
1273
|
-
else {
|
|
1274
|
-
newExpanded.add(itemId);
|
|
1275
1305
|
const item = activeItemsById.get(itemId);
|
|
1276
1306
|
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
1277
1307
|
newExpanded.add(ancestor);
|
|
1278
1308
|
}
|
|
1279
1309
|
}
|
|
1310
|
+
if (isExpanded) {
|
|
1311
|
+
newExpanded.delete(itemId);
|
|
1312
|
+
} else {
|
|
1313
|
+
newExpanded.add(itemId);
|
|
1314
|
+
}
|
|
1280
1315
|
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
1281
1316
|
if (!controlledExpanded) {
|
|
1282
1317
|
table.update((state) => {
|