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/cjs/index.js CHANGED
@@ -621,6 +621,7 @@ class Queue {
621
621
  }
622
622
  }
623
623
  const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
624
+ const storageName = (id) => `schummar-table_state-v1_${id}`;
624
625
  function stringify(value) {
625
626
  function prepare(value2) {
626
627
  if (value2 instanceof Date) {
@@ -669,8 +670,8 @@ function useTableStateStorage() {
669
670
  (async () => {
670
671
  var _a, _b;
671
672
  try {
672
- const { storage, id = "table", include, exclude } = persist;
673
- const json = await storage.getItem(`${id}_state`);
673
+ const { storage, id, include, exclude } = persist;
674
+ const json = await storage.getItem(storageName(id));
674
675
  if (isCanceled || !json)
675
676
  return;
676
677
  const data = parse(json);
@@ -712,7 +713,7 @@ function useTableStateStorage() {
712
713
  var _a, _b;
713
714
  if (!state.props.persist)
714
715
  return;
715
- const { storage, id = "table", include, exclude } = state.props.persist;
716
+ const { storage, id, include, exclude } = state.props.persist;
716
717
  const data = {};
717
718
  for (const key of KEYS) {
718
719
  if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
@@ -736,7 +737,7 @@ function useTableStateStorage() {
736
737
  const { storage, id, data } = props;
737
738
  (_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
738
739
  q.run(async () => {
739
- await storage.setItem(`${id}_state`, stringify(data));
740
+ await storage.setItem(storageName(id), stringify(data));
740
741
  }, true);
741
742
  }, { throttle: 1e3 });
742
743
  }, [isHydrated]);
@@ -928,13 +929,15 @@ function calcProps(props) {
928
929
  }
929
930
  function cleanupState(state) {
930
931
  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
932
  const columnIds = new Set(columns.map((column) => column.id));
933
933
  const activeColumnIds = new Set(activeColumns.map((column) => column.id));
934
934
  const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
935
935
  if (newSort.length < draft.sort.length) {
936
936
  draft.sort = newSort;
937
- (_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
937
+ setTimeout(() => {
938
+ var _a, _b;
939
+ (_b = (_a = state.getState().props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
940
+ });
938
941
  }
939
942
  for (const id of draft.filters.keys()) {
940
943
  if (!activeColumnIds.has(id))
@@ -960,12 +963,18 @@ function cleanupState(state) {
960
963
  const newSelection = intersect(draft.selection, activeItemsById);
961
964
  if (newSelection.size !== draft.selection.size) {
962
965
  draft.selection = newSelection;
963
- (_d = (_c = draft.props).onSelectionChange) == null ? void 0 : _d.call(_c, newSelection);
966
+ setTimeout(() => {
967
+ var _a, _b;
968
+ (_b = (_a = state.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
969
+ });
964
970
  }
965
971
  const newExpanded = intersect(draft.expanded, itemsById);
966
972
  if (newExpanded.size < draft.expanded.size) {
967
973
  draft.expanded = newExpanded;
968
- (_f = (_e = draft.props).onExpandedChange) == null ? void 0 : _f.call(_e, newExpanded);
974
+ setTimeout(() => {
975
+ var _a, _b;
976
+ (_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
977
+ });
969
978
  }
970
979
  }
971
980
  }, { runNow: true }), [state]);
@@ -975,9 +984,8 @@ function filterColumns(state) {
975
984
  draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
976
985
  }, { runNow: true }), [state]);
977
986
  }
978
- function syncSelections(state) {
979
- react.useEffect(() => state.addReaction((state2) => [state2.props.selectSyncChildren, state2.selection, state2.activeItems], ([selectSyncChildren, selection, activeItems], state2) => {
980
- var _a, _b;
987
+ function syncSelections(table) {
988
+ react.useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
981
989
  if (!selectSyncChildren)
982
990
  return;
983
991
  const newSelection = new Set(selection);
@@ -987,10 +995,13 @@ function syncSelections(state) {
987
995
  }
988
996
  }
989
997
  if (newSelection.size !== selection.size) {
990
- state2.selection = newSelection;
991
- (_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
998
+ state.selection = newSelection;
999
+ setTimeout(() => {
1000
+ var _a, _b;
1001
+ (_b = (_a = table.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
1002
+ });
992
1003
  }
993
- }, { runNow: true }), [state]);
1004
+ }, { runNow: true }), [table]);
994
1005
  }
995
1006
  function useTableState(_props) {
996
1007
  const props = calcProps(_props);