schummar-table 0.5.0-beta-8 → 0.5.2

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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # schummar-table
2
+
3
+ [![](https://badgen.net/npm/v/schummar-table)](https://www.npmjs.com/package/schummar-table)
4
+ [![](https://badgen.net/bundlephobia/minzip/schummar-table)](https://bundlephobia.com/package/schummar-table)
package/dist/cjs/index.js CHANGED
@@ -928,13 +928,15 @@ function calcProps(props) {
928
928
  }
929
929
  function cleanupState(state) {
930
930
  react.useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.itemsById, state2.activeItemsById, state2.activeColumns], ([columns, itemsById, activeItemsById, activeColumns], draft) => {
931
- var _a, _b, _c, _d, _e, _f;
932
931
  const columnIds = new Set(columns.map((column) => column.id));
933
932
  const activeColumnIds = new Set(activeColumns.map((column) => column.id));
934
933
  const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
935
934
  if (newSort.length < draft.sort.length) {
936
935
  draft.sort = newSort;
937
- (_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
936
+ setTimeout(() => {
937
+ var _a, _b;
938
+ (_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
939
+ });
938
940
  }
939
941
  for (const id of draft.filters.keys()) {
940
942
  if (!activeColumnIds.has(id))
@@ -960,12 +962,18 @@ function cleanupState(state) {
960
962
  const newSelection = intersect(draft.selection, activeItemsById);
961
963
  if (newSelection.size !== draft.selection.size) {
962
964
  draft.selection = newSelection;
963
- (_d = (_c = draft.props).onSelectionChange) == null ? void 0 : _d.call(_c, newSelection);
965
+ setTimeout(() => {
966
+ var _a, _b;
967
+ (_b = (_a = draft.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
968
+ });
964
969
  }
965
970
  const newExpanded = intersect(draft.expanded, itemsById);
966
971
  if (newExpanded.size < draft.expanded.size) {
967
972
  draft.expanded = newExpanded;
968
- (_f = (_e = draft.props).onExpandedChange) == null ? void 0 : _f.call(_e, newExpanded);
973
+ setTimeout(() => {
974
+ var _a, _b;
975
+ (_b = (_a = draft.props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
976
+ });
969
977
  }
970
978
  }
971
979
  }, { runNow: true }), [state]);
@@ -977,7 +985,6 @@ function filterColumns(state) {
977
985
  }
978
986
  function syncSelections(state) {
979
987
  react.useEffect(() => state.addReaction((state2) => [state2.props.selectSyncChildren, state2.selection, state2.activeItems], ([selectSyncChildren, selection, activeItems], state2) => {
980
- var _a, _b;
981
988
  if (!selectSyncChildren)
982
989
  return;
983
990
  const newSelection = new Set(selection);
@@ -988,7 +995,10 @@ function syncSelections(state) {
988
995
  }
989
996
  if (newSelection.size !== selection.size) {
990
997
  state2.selection = newSelection;
991
- (_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
998
+ setTimeout(() => {
999
+ var _a, _b;
1000
+ (_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
1001
+ });
992
1002
  }
993
1003
  }, { runNow: true }), [state]);
994
1004
  }
@@ -1739,7 +1749,7 @@ function SortComponent({
1739
1749
  index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
1740
1750
  };
1741
1751
  });
1742
- function toggle2(e) {
1752
+ function toggle2(e, off) {
1743
1753
  const {
1744
1754
  props: {
1745
1755
  sort: controlledSort,
@@ -1747,16 +1757,21 @@ function SortComponent({
1747
1757
  }
1748
1758
  } = table.getState();
1749
1759
  const newDirection = direction === "asc" ? "desc" : "asc";
1750
- const newSort = (e.getModifierState("Control") ? table.getState().sort.filter((s) => s.columnId !== columnId) : []).concat({
1751
- columnId,
1752
- direction: newDirection
1753
- });
1760
+ const newSort = e.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
1761
+ if (!off) {
1762
+ newSort.push({
1763
+ columnId,
1764
+ direction: newDirection
1765
+ });
1766
+ }
1754
1767
  onSortChange == null ? void 0 : onSortChange(newSort);
1755
1768
  if (!controlledSort) {
1756
1769
  table.update((state) => {
1757
1770
  state.sort = newSort;
1758
1771
  });
1759
1772
  }
1773
+ e.preventDefault();
1774
+ return false;
1760
1775
  }
1761
1776
  return jsxRuntime.jsxs("div", {
1762
1777
  css: {
@@ -1770,7 +1785,8 @@ function SortComponent({
1770
1785
  textOverflow: "ellipsis"
1771
1786
  }
1772
1787
  },
1773
- onClick: toggle2,
1788
+ onClick: (e) => toggle2(e),
1789
+ onContextMenu: (e) => toggle2(e, true),
1774
1790
  children: [jsxRuntime.jsx("div", {
1775
1791
  children
1776
1792
  }), jsxRuntime.jsx(Badge, {
@@ -2014,10 +2030,10 @@ const TableInner = react.memo(function TableInner2({
2014
2030
  header: jsxRuntime.jsxs(jsxRuntime.Fragment, {
2015
2031
  children: [jsxRuntime.jsx("div", {
2016
2032
  className: classes == null ? void 0 : classes.headerCell,
2017
- css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky]
2033
+ css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
2018
2034
  }), jsxRuntime.jsxs("div", {
2019
2035
  className: classes == null ? void 0 : classes.headerCell,
2020
- css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky],
2036
+ css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
2021
2037
  children: [enableSelection && jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && jsxRuntime.jsx(ColumnSelection, {}), enableExport && jsxRuntime.jsx(Export, {}), jsxRuntime.jsx(ResizeHandleView, {})]
2022
2038
  }), jsxRuntime.jsx(ColumnHeaderContext.Provider, {
2023
2039
  children: activeColumns.map((column) => {
@@ -2026,7 +2042,7 @@ const TableInner = react.memo(function TableInner2({
2026
2042
  value: column.id,
2027
2043
  children: jsxRuntime.jsxs(ColumnHeader, {
2028
2044
  className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
2029
- css: [tableTheme.defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky],
2045
+ css: [tableTheme.defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
2030
2046
  children: [jsxRuntime.jsx(SortComponent, {
2031
2047
  children: column.header
2032
2048
  }), jsxRuntime.jsx("div", {
@@ -2039,7 +2055,7 @@ const TableInner = react.memo(function TableInner2({
2039
2055
  })
2040
2056
  }), jsxRuntime.jsx("div", {
2041
2057
  className: classes == null ? void 0 : classes.headerCell,
2042
- css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky]
2058
+ css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
2043
2059
  })]
2044
2060
  }),
2045
2061
  children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsxRuntime.jsx(Row, {