schummar-table 0.5.1 → 0.5.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
@@ -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]);
@@ -926,13 +927,15 @@ function calcProps(props) {
926
927
  }
927
928
  function cleanupState(state) {
928
929
  useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.itemsById, state2.activeItemsById, state2.activeColumns], ([columns, itemsById, activeItemsById, activeColumns], draft) => {
929
- var _a, _b, _c, _d, _e, _f;
930
930
  const columnIds = new Set(columns.map((column) => column.id));
931
931
  const activeColumnIds = new Set(activeColumns.map((column) => column.id));
932
932
  const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
933
933
  if (newSort.length < draft.sort.length) {
934
934
  draft.sort = newSort;
935
- (_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
935
+ setTimeout(() => {
936
+ var _a, _b;
937
+ (_b = (_a = state.getState().props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
938
+ });
936
939
  }
937
940
  for (const id of draft.filters.keys()) {
938
941
  if (!activeColumnIds.has(id))
@@ -958,12 +961,18 @@ function cleanupState(state) {
958
961
  const newSelection = intersect(draft.selection, activeItemsById);
959
962
  if (newSelection.size !== draft.selection.size) {
960
963
  draft.selection = newSelection;
961
- (_d = (_c = draft.props).onSelectionChange) == null ? void 0 : _d.call(_c, newSelection);
964
+ setTimeout(() => {
965
+ var _a, _b;
966
+ (_b = (_a = state.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
967
+ });
962
968
  }
963
969
  const newExpanded = intersect(draft.expanded, itemsById);
964
970
  if (newExpanded.size < draft.expanded.size) {
965
971
  draft.expanded = newExpanded;
966
- (_f = (_e = draft.props).onExpandedChange) == null ? void 0 : _f.call(_e, newExpanded);
972
+ setTimeout(() => {
973
+ var _a, _b;
974
+ (_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
975
+ });
967
976
  }
968
977
  }
969
978
  }, { runNow: true }), [state]);
@@ -973,9 +982,8 @@ function filterColumns(state) {
973
982
  draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
974
983
  }, { runNow: true }), [state]);
975
984
  }
976
- function syncSelections(state) {
977
- useEffect(() => state.addReaction((state2) => [state2.props.selectSyncChildren, state2.selection, state2.activeItems], ([selectSyncChildren, selection, activeItems], state2) => {
978
- var _a, _b;
985
+ function syncSelections(table) {
986
+ useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
979
987
  if (!selectSyncChildren)
980
988
  return;
981
989
  const newSelection = new Set(selection);
@@ -985,10 +993,13 @@ function syncSelections(state) {
985
993
  }
986
994
  }
987
995
  if (newSelection.size !== selection.size) {
988
- state2.selection = newSelection;
989
- (_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
996
+ state.selection = newSelection;
997
+ setTimeout(() => {
998
+ var _a, _b;
999
+ (_b = (_a = table.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
1000
+ });
990
1001
  }
991
- }, { runNow: true }), [state]);
1002
+ }, { runNow: true }), [table]);
992
1003
  }
993
1004
  function useTableState(_props) {
994
1005
  const props = calcProps(_props);