schummar-table 0.46.7 → 0.46.9

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/index.cjs CHANGED
@@ -3936,13 +3936,7 @@ var import_react28 = require("react");
3936
3936
  function filterColumns(state) {
3937
3937
  (0, import_react28.useEffect)(
3938
3938
  () => state.addReaction(
3939
- (state2) => [
3940
- state2.props.columns,
3941
- state2.hiddenColumns,
3942
- state2.columnOrder,
3943
- state2.displaySize,
3944
- state2.displaySizePx
3945
- ],
3939
+ (state2) => [state2.props.columns, state2.hiddenColumns, state2.columnOrder, state2.displaySize],
3946
3940
  ([columns, hiddenColumns, columnOrder, displaySize], draft) => {
3947
3941
  draft.activeColumns = orderBy(
3948
3942
  columns.filter((column) => {
@@ -4038,24 +4032,34 @@ function syncSelections(table) {
4038
4032
  // src/internalState/watchDisplaySize.ts
4039
4033
  var import_immer5 = require("immer");
4040
4034
  var import_react31 = require("react");
4041
- var DEFAULT_DISPLAY_SIZES = {
4042
- mobile: 400,
4043
- desktop: Infinity
4044
- };
4045
4035
  function watchDisplaySize(state) {
4036
+ (0, import_react31.useEffect)(() => {
4037
+ var _a;
4038
+ function onResize() {
4039
+ state.update((draft) => {
4040
+ draft.displaySizePx = window.innerWidth;
4041
+ });
4042
+ }
4043
+ onResize();
4044
+ (_a = document.defaultView) == null ? void 0 : _a.addEventListener("resize", onResize);
4045
+ return () => {
4046
+ var _a2;
4047
+ return (_a2 = document.defaultView) == null ? void 0 : _a2.removeEventListener("resize", onResize);
4048
+ };
4049
+ }, [state]);
4046
4050
  (0, import_react31.useEffect)(
4047
4051
  () => state.addReaction(
4048
4052
  (state2) => ({
4049
4053
  displaySizePx: state2.displaySizePx,
4050
4054
  displaySize: state2.props.displaySize
4051
4055
  }),
4052
- ({ displaySizePx, displaySize = DEFAULT_DISPLAY_SIZES }, draft) => {
4056
+ ({ displaySizePx, displaySize }, draft) => {
4053
4057
  if (displaySizePx === void 0) {
4054
4058
  return;
4055
4059
  }
4056
4060
  if (typeof displaySize === "object") {
4057
4061
  const entry = Object.entries(displaySize).find(
4058
- ([, maxWidth]) => maxWidth >= displaySizePx
4062
+ ([, maxWidth]) => maxWidth !== void 0 && maxWidth >= displaySizePx
4059
4063
  );
4060
4064
  draft.displaySize = entry == null ? void 0 : entry[0];
4061
4065
  } else {
@@ -4593,7 +4597,11 @@ function ColumnSelection() {
4593
4597
  const cssVariables = useCssVariables();
4594
4598
  const table = useTableContext();
4595
4599
  const reset = (0, import_react36.useContext)(TableResetContext);
4596
- const columns = table.useState((state) => state.props.columns);
4600
+ const columns = table.useState(
4601
+ (state) => state.props.columns.filter(
4602
+ (column) => state.displaySize === void 0 || column.displaySize === void 0 || column.displaySize.includes(state.displaySize)
4603
+ )
4604
+ );
4597
4605
  const hiddenColumns = table.useState((state) => state.hiddenColumns);
4598
4606
  const [anchorElement, setAnchorElement] = (0, import_react36.useState)(null);
4599
4607
  const toggle2 = (column, state) => {
@@ -5110,8 +5118,7 @@ function Virtualized(_a) {
5110
5118
  const itemIds2 = state.activeItems.map((item) => item.id);
5111
5119
  const root = probeRef.current && findScrollRoot(probeRef.current);
5112
5120
  if (!state.props.virtual) return { itemIds: itemIds2 };
5113
- if (!probeRef.current || !root || !document.contains(root) || state.displaySizePx === void 0)
5114
- return {};
5121
+ if (!probeRef.current || !root || !document.contains(root)) return {};
5115
5122
  const {
5116
5123
  rowHeight,
5117
5124
  initalRowHeight,
@@ -5150,23 +5157,6 @@ function Virtualized(_a) {
5150
5157
  );
5151
5158
  const throttleScroll = (_b2 = (_a2 = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a2.throttleScroll) != null ? _b2 : 16;
5152
5159
  const update = (0, import_react42.useMemo)(() => throttle2(() => setId({}), throttleScroll), [throttleScroll]);
5153
- (0, import_react42.useEffect)(() => {
5154
- var _a3;
5155
- const tableElem = (_a3 = probeRef.current) == null ? void 0 : _a3.parentElement;
5156
- if (!tableElem) return;
5157
- const update2 = () => {
5158
- table.update((state) => {
5159
- state.displaySizePx = tableElem.clientWidth;
5160
- });
5161
- };
5162
- const ro = new ResizeObserver(update2);
5163
- ro.observe(tableElem);
5164
- window.addEventListener("resize", update2, true);
5165
- return () => {
5166
- ro.disconnect();
5167
- window.removeEventListener("resize", update2, true);
5168
- };
5169
- }, [table, probeRef.current]);
5170
5160
  (0, import_react42.useEffect)(() => {
5171
5161
  if (!virtual || !probeRef.current) return;
5172
5162
  window.addEventListener("scroll", update, true);
@@ -5249,12 +5239,8 @@ var TableInner = (0, import_react43.memo)(function TableInner2({ hidden }) {
5249
5239
  const stickyHeader = table.useState((state) => state.props.stickyHeader);
5250
5240
  const stickyFooter = table.useState((state) => state.props.stickyFooter);
5251
5241
  const enableSelection = table.useState((state) => state.props.enableSelection);
5252
- const enableColumnSelection = table.useState(
5253
- (state) => Array.isArray(state.props.enableColumnSelection) ? !state.displaySize || state.props.enableColumnSelection.includes(state.displaySize) : state.props.enableColumnSelection
5254
- );
5255
- const enableExport = table.useState(
5256
- (state) => typeof state.props.enableExport === "object" && !("exporters" in state.props.enableExport) ? !state.displaySize || !!state.props.enableExport[state.displaySize] : !!state.props.enableExport
5257
- );
5242
+ const enableColumnSelection = table.useState((state) => state.props.enableColumnSelection);
5243
+ const enableExport = table.useState((state) => state.props.enableExport);
5258
5244
  const cssVariables = useCssVariables();
5259
5245
  const enableClearFiltersButton = table.useState((state) => state.props.enableClearFiltersButton);
5260
5246
  (0, import_react43.useLayoutEffect)(() => {