schummar-table 0.10.1 → 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);
|
|
@@ -1268,17 +1298,18 @@ function ExpandControl({
|
|
|
1268
1298
|
activeItemsById
|
|
1269
1299
|
} = table.getState();
|
|
1270
1300
|
const newExpanded = new Set(expanded);
|
|
1271
|
-
if (expandOnlyOne)
|
|
1301
|
+
if (expandOnlyOne) {
|
|
1272
1302
|
newExpanded.clear();
|
|
1273
|
-
if (isExpanded)
|
|
1274
|
-
newExpanded.delete(itemId);
|
|
1275
|
-
else {
|
|
1276
|
-
newExpanded.add(itemId);
|
|
1277
1303
|
const item = activeItemsById.get(itemId);
|
|
1278
1304
|
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
1279
1305
|
newExpanded.add(ancestor);
|
|
1280
1306
|
}
|
|
1281
1307
|
}
|
|
1308
|
+
if (isExpanded) {
|
|
1309
|
+
newExpanded.delete(itemId);
|
|
1310
|
+
} else {
|
|
1311
|
+
newExpanded.add(itemId);
|
|
1312
|
+
}
|
|
1282
1313
|
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
1283
1314
|
if (!controlledExpanded) {
|
|
1284
1315
|
table.update((state) => {
|
|
@@ -1700,7 +1731,11 @@ const TableInner = react.memo(function TableInner2({
|
|
|
1700
1731
|
}), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1701
1732
|
className: classes == null ? void 0 : classes.headerCell,
|
|
1702
1733
|
css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1703
|
-
children: [enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && /* @__PURE__ */ jsxRuntime.jsx(ColumnSelection, {}), enableExport && /* @__PURE__ */ jsxRuntime.jsx(Export$1, {}), /* @__PURE__ */ jsxRuntime.jsx(
|
|
1734
|
+
children: [enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && /* @__PURE__ */ jsxRuntime.jsx(ColumnSelection, {}), enableExport && /* @__PURE__ */ jsxRuntime.jsx(Export$1, {}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1735
|
+
css: {
|
|
1736
|
+
flex: 1
|
|
1737
|
+
}
|
|
1738
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(ResizeHandleView, {})]
|
|
1704
1739
|
}), /* @__PURE__ */ jsxRuntime.jsx(ColumnHeaderContext.Provider, {
|
|
1705
1740
|
children: activeColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1706
1741
|
value: column.id,
|