@lavalogic/scoria 0.11.3 → 0.11.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.
@@ -151,10 +151,10 @@ export declare class TableContext<T extends object> {
151
151
  readonly sortedData: T[];
152
152
  readonly sortedRowModel: RowModel<T>;
153
153
  _currentPageData: T[];
154
+ get currentPageData(): T[];
154
155
  private _originalRowIndices;
155
156
  get originalRowIndices(): Map<T, number>;
156
157
  readonly paginationRowModel: RowModel<T>;
157
- get currentPageData(): T[];
158
158
  readonly selectionContains: (item: T) => boolean;
159
159
  readonly addInvalidValue: (item: T) => void;
160
160
  readonly removeInvalidValue: (item: T) => void;
@@ -66,13 +66,17 @@ export class TableContext {
66
66
  }
67
67
  this._dataRepo = $state(dataRepo);
68
68
  // this.dataRepo.forceRefresh = this.forceVisibilityUpdate;
69
- [this._currentPageData, this._originalRowIndices] = $derived.by(() => {
70
- const x = this.dataRepo?.paginationType == PaginationType.Local
71
- ? this.sortedData.slice(this.dataRepo.pageStartIndex, this.dataRepo.pageEndIndexExclusive)
69
+ const [_currentPageData, _originalRowIndices] = $derived.by(() => {
70
+ const x = dataRepo.paginationType == PaginationType.Local
71
+ ? this.sortedData.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
72
72
  : (this.sortedData ?? []);
73
- const y = new Map((this.dataRepo?.data ?? []).map((item, index) => [item, index]));
73
+ const y = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
74
74
  return [x, y];
75
75
  });
76
+ $effect(() => {
77
+ this._currentPageData = _currentPageData;
78
+ this._originalRowIndices = _originalRowIndices;
79
+ });
76
80
  if (defaultColumnDefs.remoteFilters) {
77
81
  this.remoteFilters = defaultColumnDefs.remoteFilters;
78
82
  }
@@ -679,10 +683,13 @@ export class TableContext {
679
683
  rowsById: new Map(rows.map((it, index) => [index.toString(), it])) //FIXME should this be by sorted id or by original id?
680
684
  };
681
685
  });
682
- _currentPageData;
686
+ _currentPageData = $state([]);
687
+ get currentPageData() {
688
+ return this._currentPageData;
689
+ }
683
690
  // FIXME this is most likely the cuplrit for add pod not working on receipt. It may be one tick behind the other values
684
691
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
685
- _originalRowIndices;
692
+ _originalRowIndices = $state(new Map());
686
693
  get originalRowIndices() {
687
694
  return this._originalRowIndices;
688
695
  }
@@ -763,9 +770,6 @@ export class TableContext {
763
770
  rowsById: new Map(rows.map((it, index) => [index.toString(), it])) //FIXME should this be by sorted id or by original id?
764
771
  };
765
772
  });
766
- get currentPageData() {
767
- return this._currentPageData;
768
- }
769
773
  // #endregion
770
774
  // #region public methods
771
775
  selectionContains = (item) => {
@@ -843,26 +847,35 @@ export class TableContext {
843
847
  ? Math.min(this.paginationRepo.pageEndIndexExclusive, this.sortedData.length)
844
848
  : this.sortedData.length;
845
849
  const selectableMethod = this.columnDefs.find((it) => it instanceof RowSelectionDef)?.isSelectable;
850
+ const updateSelectedItem = (item) => {
851
+ const key = this.selectionExtractor(item);
852
+ if (this.selectedItems.has(key)) {
853
+ //replace selected item with newer version of the same identity
854
+ this.selectedItems.set(key, item);
855
+ }
856
+ };
846
857
  if (selectableMethod) {
847
858
  for (let index = pageStartIndex; index < pageEndIndexExclusive; index++) {
848
859
  const item = this.sortedData[index];
860
+ // HACK: Please find why this is happening and fix it properly
861
+ if (!item) {
862
+ console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exlusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
863
+ return;
864
+ }
849
865
  if (await selectableMethod(item, index)) {
850
- const key = this.selectionExtractor(item);
851
- if (this.selectedItems.has(key)) {
852
- //replace selected item with newer version of the same identity
853
- this.selectedItems.set(key, item);
854
- }
866
+ updateSelectedItem(item);
855
867
  }
856
868
  }
857
869
  }
858
870
  else {
859
871
  for (let index = pageStartIndex; index < pageEndIndexExclusive; index++) {
860
872
  const item = this.sortedData[index];
861
- const key = this.selectionExtractor(item);
862
- if (this.selectedItems.has(key)) {
863
- //replace selected item with newer version of the same identity
864
- this.selectedItems.set(key, item);
873
+ // HACK: Please find why this is happening and fix it properly
874
+ if (!item) {
875
+ console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exlusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
876
+ return;
865
877
  }
878
+ updateSelectedItem(item);
866
879
  }
867
880
  }
868
881
  this.recalculateAllSelectedInCurrentPage();
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.3",
4
+ "version": "0.11.5",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },