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