@lavalogic/scoria 0.11.11 → 0.11.13

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.
@@ -167,6 +167,7 @@ export declare class TableContext<T extends object> {
167
167
  setSelectionMap: (set: SvelteMap<unknown, T>) => void;
168
168
  readonly updateSelectedItems: () => Promise<void>;
169
169
  readonly resetSelectedItems: () => void;
170
+ private lastIncrement;
170
171
  readonly recalculateAllSelectedInCurrentPage: () => void;
171
172
  readonly selectAllInCurrentPage: () => Promise<void>;
172
173
  readonly onHighlightAll: () => void;
@@ -121,11 +121,13 @@ export class TableContext {
121
121
  });
122
122
  $effect(() => {
123
123
  if (this._currentPageData) {
124
+ void this.selectedItems;
124
125
  untrack(() => {
125
126
  if (this.paginationRepo?.paginationState.pageIndex != undefined &&
126
127
  this.paginationRepo?.paginationState.pageSize != undefined) {
127
128
  this.updateSelectedItems();
128
129
  this.resetHighlightedRows();
130
+ this.recalculateAllSelectedInCurrentPage();
129
131
  }
130
132
  });
131
133
  }
@@ -796,22 +798,6 @@ export class TableContext {
796
798
  }
797
799
  return this.selectedItems.has(this.selectionExtractor(item));
798
800
  };
799
- // public readonly HACK__reselectItem = (item: T) => {
800
- // if (!this.selectionExtractor) {
801
- // throw new Error('No selection extractor was supplied');
802
- // }
803
- // if (!this.isSelectable) {
804
- // return true;
805
- // }
806
- // const key = this.selectionExtractor(item);
807
- // if (this.selectedItems.has(key)) {
808
- // this.selectedItems.delete(key);
809
- // this.selectedItems.set(key, item);
810
- // } else {
811
- // this.selectedItems.set(key, item);
812
- // this.selectedItems.delete(key);
813
- // }
814
- // };
815
801
  addInvalidValue = (item) => {
816
802
  this.invalidValues.set(this.selectionExtractor(item), item);
817
803
  };
@@ -830,13 +816,6 @@ export class TableContext {
830
816
  this.highlightedItems.set(key, item);
831
817
  }
832
818
  };
833
- // public readonly toggleHighlightedRow = (rowIndex: number) => {
834
- // if (this.highlightedRowIndexIds.has(rowIndex)) {
835
- // this.highlightedRowIndexIds.delete(rowIndex);
836
- // } else {
837
- // this.highlightedRowIndexIds.add(rowIndex);
838
- // }
839
- // };
840
819
  resetHighlightedRows = () => {
841
820
  this.highlightedItems.clear();
842
821
  };
@@ -848,7 +827,6 @@ export class TableContext {
848
827
  else {
849
828
  this.selectedItems.delete(key);
850
829
  }
851
- this.recalculateAllSelectedInCurrentPage();
852
830
  };
853
831
  setSelectionMap = (set) => {
854
832
  this.selectedItems = set;
@@ -893,7 +871,6 @@ export class TableContext {
893
871
  updateSelectedItem(item);
894
872
  }
895
873
  }
896
- this.recalculateAllSelectedInCurrentPage();
897
874
  };
898
875
  resetSelectedItems = () => {
899
876
  for (const key of this.selectedItems.keys()) {
@@ -901,16 +878,23 @@ export class TableContext {
901
878
  }
902
879
  this.recalculateAllSelectedInCurrentPage();
903
880
  };
881
+ lastIncrement = Number.MIN_SAFE_INTEGER;
904
882
  recalculateAllSelectedInCurrentPage = () => {
905
- tick()
906
- .then(() => {
907
- this.allSelectedInCurrentPage
908
- ?.then(() => {
909
- this.hasInvalidSelectedItems = [...this.selectedItems.keys()].some((key) => this._invalidValues.has(key));
910
- })
911
- .catch((e) => {
912
- console.log(e);
913
- });
883
+ const invalidValues = this._invalidValues;
884
+ const allSelectedInCurrentPage = [...this.selectedItems.keys()];
885
+ const currentIncrement = ++this.lastIncrement;
886
+ this.allSelectedInCurrentPage
887
+ ?.then(() => {
888
+ if (this.lastIncrement == currentIncrement) {
889
+ this.hasInvalidSelectedItems = allSelectedInCurrentPage.some((key) => {
890
+ return invalidValues.has(key);
891
+ });
892
+ }
893
+ else {
894
+ if (dev) {
895
+ console.log('skipping recalculation due to stale data');
896
+ }
897
+ }
914
898
  })
915
899
  .catch((e) => {
916
900
  console.log(e);
@@ -954,7 +938,6 @@ export class TableContext {
954
938
  }
955
939
  }
956
940
  }
957
- this.recalculateAllSelectedInCurrentPage();
958
941
  };
959
942
  onHighlightAll = () => {
960
943
  if (!this.dataRepo) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lavalogic/scoria",
3
3
  "description": "Svelte components used for the FloWMS Web Frontend",
4
- "version": "0.11.11",
4
+ "version": "0.11.13",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },