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