schummar-table 0.5.2 → 0.5.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/es/index.js CHANGED
@@ -619,6 +619,7 @@ class Queue {
619
619
  }
620
620
  }
621
621
  const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
622
+ const storageName = (id) => `schummar-table_state-v1_${id}`;
622
623
  function stringify(value) {
623
624
  function prepare(value2) {
624
625
  if (value2 instanceof Date) {
@@ -667,8 +668,8 @@ function useTableStateStorage() {
667
668
  (async () => {
668
669
  var _a, _b;
669
670
  try {
670
- const { storage, id = "table", include, exclude } = persist;
671
- const json = await storage.getItem(`${id}_state`);
671
+ const { storage, id, include, exclude } = persist;
672
+ const json = await storage.getItem(storageName(id));
672
673
  if (isCanceled || !json)
673
674
  return;
674
675
  const data = parse(json);
@@ -710,7 +711,7 @@ function useTableStateStorage() {
710
711
  var _a, _b;
711
712
  if (!state.props.persist)
712
713
  return;
713
- const { storage, id = "table", include, exclude } = state.props.persist;
714
+ const { storage, id, include, exclude } = state.props.persist;
714
715
  const data = {};
715
716
  for (const key of KEYS) {
716
717
  if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
@@ -734,7 +735,7 @@ function useTableStateStorage() {
734
735
  const { storage, id, data } = props;
735
736
  (_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
736
737
  q.run(async () => {
737
- await storage.setItem(`${id}_state`, stringify(data));
738
+ await storage.setItem(storageName(id), stringify(data));
738
739
  }, true);
739
740
  }, { throttle: 1e3 });
740
741
  }, [isHydrated]);
@@ -933,7 +934,7 @@ function cleanupState(state) {
933
934
  draft.sort = newSort;
934
935
  setTimeout(() => {
935
936
  var _a, _b;
936
- (_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
937
+ (_b = (_a = state.getState().props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
937
938
  });
938
939
  }
939
940
  for (const id of draft.filters.keys()) {
@@ -962,7 +963,7 @@ function cleanupState(state) {
962
963
  draft.selection = newSelection;
963
964
  setTimeout(() => {
964
965
  var _a, _b;
965
- (_b = (_a = draft.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
966
+ (_b = (_a = state.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
966
967
  });
967
968
  }
968
969
  const newExpanded = intersect(draft.expanded, itemsById);
@@ -970,7 +971,7 @@ function cleanupState(state) {
970
971
  draft.expanded = newExpanded;
971
972
  setTimeout(() => {
972
973
  var _a, _b;
973
- (_b = (_a = draft.props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
974
+ (_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
974
975
  });
975
976
  }
976
977
  }
@@ -981,8 +982,8 @@ function filterColumns(state) {
981
982
  draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
982
983
  }, { runNow: true }), [state]);
983
984
  }
984
- function syncSelections(state) {
985
- useEffect(() => state.addReaction((state2) => [state2.props.selectSyncChildren, state2.selection, state2.activeItems], ([selectSyncChildren, selection, activeItems], state2) => {
985
+ function syncSelections(table) {
986
+ useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
986
987
  if (!selectSyncChildren)
987
988
  return;
988
989
  const newSelection = new Set(selection);
@@ -992,13 +993,13 @@ function syncSelections(state) {
992
993
  }
993
994
  }
994
995
  if (newSelection.size !== selection.size) {
995
- state2.selection = newSelection;
996
+ state.selection = newSelection;
996
997
  setTimeout(() => {
997
998
  var _a, _b;
998
- (_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
999
+ (_b = (_a = table.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
999
1000
  });
1000
1001
  }
1001
- }, { runNow: true }), [state]);
1002
+ }, { runNow: true }), [table]);
1002
1003
  }
1003
1004
  function useTableState(_props) {
1004
1005
  const props = calcProps(_props);
@@ -1923,8 +1924,10 @@ function Virtualized(_e) {
1923
1924
  if (!virtual || !probeRef.current)
1924
1925
  return;
1925
1926
  window.addEventListener("scroll", incCounter, true);
1927
+ window.addEventListener("resize", incCounter, true);
1926
1928
  return () => {
1927
1929
  window.removeEventListener("scroll", incCounter, true);
1930
+ window.removeEventListener("resize", incCounter, true);
1928
1931
  };
1929
1932
  }, [probeRef.current, incCounter]);
1930
1933
  (_d = (_c = table.getState().props).debugRender) == null ? void 0 : _d.call(_c, `Virtualalized render ${from} to ${to}`);
@@ -2191,7 +2194,6 @@ function debounce(fn, ms) {
2191
2194
  });
2192
2195
  }
2193
2196
  function useFilter(impl) {
2194
- var _a;
2195
2197
  const table = useTableContext();
2196
2198
  const columnId = useColumnContext();
2197
2199
  useEffect(() => {
@@ -2213,7 +2215,7 @@ function useFilter(impl) {
2213
2215
  state.filters.delete(columnId);
2214
2216
  });
2215
2217
  };
2216
- }, [table, columnId, ...(_a = impl.dependencies) != null ? _a : [impl]]);
2218
+ }, [table, columnId, impl]);
2217
2219
  const value = table.useState((state) => state.filterValues.get(columnId));
2218
2220
  const [dirtyValue, setDirtyValue] = useState();
2219
2221
  const implRef = useRef(impl);
@@ -2305,5 +2307,5 @@ function TextFilter(_i) {
2305
2307
  })
2306
2308
  });
2307
2309
  }
2308
- export { AutoFocusTextField, ColumnContext, DateFilter, SelectFilter, Table, TableContext, TextFilter, termMatch, textMatch, useColumnContext, useFilter, useTableContext, useTheme };
2310
+ export { AutoFocusTextField, ColumnContext, DateFilter, DatePicker, SelectFilter, Table, TableContext, TextFilter, dateIntersect, endOfDay, startOfDay, termMatch, textMatch, useColumnContext, useFilter, useTableContext, useTheme };
2309
2311
  //# sourceMappingURL=index.js.map