@lavalogic/scoria 0.11.6 → 0.11.7

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.
@@ -148,7 +148,8 @@ export declare class TableContext<T extends object> {
148
148
  get filteredIndices(): number[];
149
149
  set filteredIndices(v: number[]);
150
150
  readonly filteredData: T[];
151
- readonly sortedData: T[];
151
+ private _sortedData;
152
+ get sortedData(): T[];
152
153
  readonly sortedRowModel: RowModel<T>;
153
154
  _currentPageData: T[];
154
155
  get currentPageData(): T[];
@@ -66,14 +66,43 @@ export class TableContext {
66
66
  }
67
67
  this._dataRepo = $state(dataRepo);
68
68
  // this.dataRepo.forceRefresh = this.forceVisibilityUpdate;
69
- const [_currentPageData, _originalRowIndices] = $derived.by(() => {
69
+ const [_sortedData, _currentPageData, _originalRowIndices] = $derived.by(() => {
70
+ const sd = (() => {
71
+ if (this.paginationRepo?.paginationType == PaginationType.Local) {
72
+ const state = this.dataRepo?.sorting ?? [];
73
+ const sortedData = this.showSelectedOnly
74
+ ? // FIXME this will show the selected items by order of insertion to the selectedItems map.
75
+ [...this.selectedItems.values()]
76
+ : this.filteredData.concat();
77
+ sortedData.sort((a, b) => {
78
+ const end = state.length;
79
+ for (let i = 0; i < end; i++) {
80
+ const { id, desc } = state[i];
81
+ const sortingFn = this.getSortingFn(id, desc);
82
+ if (sortingFn) {
83
+ const result = sortingFn(a, b);
84
+ if (result != 0) {
85
+ return result;
86
+ }
87
+ }
88
+ else {
89
+ console.warn('no sorting fn found for ' + id);
90
+ }
91
+ }
92
+ return 0;
93
+ });
94
+ return sortedData;
95
+ }
96
+ return this.filteredData ?? [];
97
+ })();
70
98
  const cpd = dataRepo.paginationType == PaginationType.Local
71
- ? this.sortedData.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
72
- : (this.sortedData ?? []);
99
+ ? sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
100
+ : (sd ?? []);
73
101
  const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
74
- return [cpd, ori];
102
+ return [sd, cpd, ori];
75
103
  });
76
104
  $effect(() => {
105
+ this._sortedData = _sortedData;
77
106
  this._currentPageData = _currentPageData;
78
107
  this._originalRowIndices = _originalRowIndices;
79
108
  });
@@ -649,41 +678,17 @@ export class TableContext {
649
678
  }
650
679
  return this.showSelectedOnly ? [...this.selectedItems.values()] : (this.dataRepo?.data ?? []);
651
680
  });
652
- sortedData = $derived.by(() => {
653
- if (this.paginationRepo?.paginationType == PaginationType.Local) {
654
- const state = this.dataRepo?.sorting ?? [];
655
- const sortedData = this.showSelectedOnly
656
- ? // FIXME this will show the selected items by order of insertion to the selectedItems map.
657
- [...this.selectedItems.values()]
658
- : this.filteredData.concat();
659
- sortedData.sort((a, b) => {
660
- const end = state.length;
661
- for (let i = 0; i < end; i++) {
662
- const { id, desc } = state[i];
663
- const sortingFn = this.getSortingFn(id, desc);
664
- if (sortingFn) {
665
- const result = sortingFn(a, b);
666
- if (result != 0) {
667
- return result;
668
- }
669
- }
670
- else {
671
- console.warn('no sorting fn found for ' + id);
672
- }
673
- }
674
- return 0;
675
- });
676
- return sortedData;
677
- }
678
- return this.filteredData ?? [];
679
- });
681
+ _sortedData = $state([]);
682
+ get sortedData() {
683
+ return this._sortedData;
684
+ }
680
685
  sortedRowModel = $derived.by(() => {
681
686
  const rows = this.sortedData.map((item, index) => {
682
687
  const originalIndex = this._originalRowIndices.get(item);
683
688
  const unsortedIndex = originalIndex ?? index;
684
689
  if (originalIndex == null) {
685
- console.log($state.snapshot(this.sortedData));
686
- console.log($state.snapshot(this._originalRowIndices));
690
+ $inspect(this.sortedData);
691
+ $inspect(this._originalRowIndices);
687
692
  throw new Error(`Sorted Data not found in Original Row Indices: original index ${originalIndex}, index ${index}`);
688
693
  }
689
694
  return this.createRow(item, index, unsortedIndex);
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.6",
4
+ "version": "0.11.7",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },