@lavalogic/scoria 0.11.1 → 0.11.3

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.
@@ -141,7 +141,6 @@ export declare class TableContext<T extends object> {
141
141
  private set hasInvalidSelectedItems(value);
142
142
  private columnDefsById;
143
143
  private readonly getSortingFn;
144
- readonly originalRowIndices: Map<T, number>;
145
144
  private _filterTimer;
146
145
  private get filterTimer();
147
146
  private set filterTimer(value);
@@ -152,6 +151,8 @@ export declare class TableContext<T extends object> {
152
151
  readonly sortedData: T[];
153
152
  readonly sortedRowModel: RowModel<T>;
154
153
  _currentPageData: T[];
154
+ private _originalRowIndices;
155
+ get originalRowIndices(): Map<T, number>;
155
156
  readonly paginationRowModel: RowModel<T>;
156
157
  get currentPageData(): T[];
157
158
  readonly selectionContains: (item: T) => boolean;
@@ -66,6 +66,13 @@ 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)
72
+ : (this.sortedData ?? []);
73
+ const y = new Map((this.dataRepo?.data ?? []).map((item, index) => [item, index]));
74
+ return [x, y];
75
+ });
69
76
  if (defaultColumnDefs.remoteFilters) {
70
77
  this.remoteFilters = defaultColumnDefs.remoteFilters;
71
78
  }
@@ -600,9 +607,6 @@ export class TableContext {
600
607
  // }
601
608
  return comparableSortingFn(id, desc);
602
609
  };
603
- // FIXME this is most likely the cuplrit for add pod not working on receipt. It may be one tick behind the other values
604
- // eslint-disable-next-line svelte/prefer-svelte-reactivity
605
- originalRowIndices = $derived(new Map((this.dataRepo?.data ?? []).map((item, index) => [item, index])));
606
610
  // private _filterTimer: ReturnType<typeof setTimeout> | undefined;
607
611
  _filterTimer = 1;
608
612
  get filterTimer() {
@@ -660,7 +664,13 @@ export class TableContext {
660
664
  });
661
665
  sortedRowModel = $derived.by(() => {
662
666
  const rows = this.sortedData.map((item, index) => {
663
- const unsortedIndex = this.originalRowIndices.get(item) ?? index;
667
+ const originalIndex = this._originalRowIndices.get(item);
668
+ const unsortedIndex = originalIndex ?? index;
669
+ if (originalIndex == null) {
670
+ console.log($state.snapshot(this.sortedData));
671
+ console.log($state.snapshot(this._originalRowIndices));
672
+ throw new Error(`Sorted Data not found in Original Row Indices: original index ${originalIndex}, index ${index}`);
673
+ }
664
674
  return this.createRow(item, index, unsortedIndex);
665
675
  });
666
676
  return {
@@ -669,15 +679,21 @@ export class TableContext {
669
679
  rowsById: new Map(rows.map((it, index) => [index.toString(), it])) //FIXME should this be by sorted id or by original id?
670
680
  };
671
681
  });
672
- _currentPageData = $derived(this.dataRepo?.paginationType == PaginationType.Local
673
- ? this.sortedData.slice(this.dataRepo.pageStartIndex, this.dataRepo.pageEndIndexExclusive)
674
- : (this.sortedData ?? []));
682
+ _currentPageData;
683
+ // FIXME this is most likely the cuplrit for add pod not working on receipt. It may be one tick behind the other values
684
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
685
+ _originalRowIndices;
686
+ get originalRowIndices() {
687
+ return this._originalRowIndices;
688
+ }
675
689
  paginationRowModel = $derived.by(() => {
676
690
  const sortedData = this._currentPageData;
677
691
  const rows = sortedData.map((item, index) => {
678
- const unsortedIndex = this.originalRowIndices.get(item) ?? index;
692
+ const unsortedIndex = this._originalRowIndices.get(item) ?? index;
679
693
  if (!item) {
680
- throw new Error('No Item was found');
694
+ console.log($state.snapshot(sortedData));
695
+ console.log($state.snapshot(this._originalRowIndices));
696
+ throw new Error(`No Item was found at index ${index}`);
681
697
  }
682
698
  const row = {
683
699
  getValue: async (key) => {
@@ -1677,7 +1693,8 @@ export class TableContext {
1677
1693
  // #region private methods
1678
1694
  createRow(item, index, unsortedIndex) {
1679
1695
  if (!item) {
1680
- throw new Error('No Item was found');
1696
+ console.log($state.snapshot(this._originalRowIndices));
1697
+ throw new Error(`No Item was found at index ${index} (unsorted index ${unsortedIndex})`);
1681
1698
  }
1682
1699
  const row = {
1683
1700
  getValue: async (key) => {
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.1",
4
+ "version": "0.11.3",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },