@lavalogic/scoria 0.11.6 → 0.11.8
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
|
-
|
|
151
|
+
private _sortedData;
|
|
152
|
+
get sortedData(): T[];
|
|
152
153
|
readonly sortedRowModel: RowModel<T>;
|
|
153
154
|
_currentPageData: T[];
|
|
154
155
|
get currentPageData(): T[];
|
|
@@ -66,19 +66,56 @@ export class TableContext {
|
|
|
66
66
|
}
|
|
67
67
|
this._dataRepo = $state(dataRepo);
|
|
68
68
|
// this.dataRepo.forceRefresh = this.forceVisibilityUpdate;
|
|
69
|
-
const [_currentPageData, _originalRowIndices] = $derived.by(() => {
|
|
70
|
-
const cpd = dataRepo.paginationType == PaginationType.Local
|
|
71
|
-
? this.sortedData.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
|
|
72
|
-
: (this.sortedData ?? []);
|
|
73
|
-
const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
|
|
74
|
-
return [cpd, ori];
|
|
75
|
-
});
|
|
76
69
|
$effect(() => {
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
})();
|
|
98
|
+
const cpd = (() => {
|
|
99
|
+
if (dataRepo.paginationType != PaginationType.Local) {
|
|
100
|
+
return sd ?? [];
|
|
101
|
+
}
|
|
102
|
+
if (dataRepo.pageEndIndexExclusive > sd.length - 1) {
|
|
103
|
+
console.error(`Data Repository reports more items than what exists: End index: ${dataRepo.pageEndIndexExclusive} sorted data:`, $state.snapshot(sd));
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive);
|
|
107
|
+
})();
|
|
108
|
+
const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
|
|
109
|
+
if (cpd != null) {
|
|
110
|
+
this._sortedData = sd;
|
|
111
|
+
this._currentPageData = cpd;
|
|
112
|
+
this._originalRowIndices = ori;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
}
|
|
79
116
|
});
|
|
80
117
|
$effect(() => {
|
|
81
|
-
if (_currentPageData) {
|
|
118
|
+
if (this._currentPageData) {
|
|
82
119
|
untrack(() => {
|
|
83
120
|
if (this.paginationRepo?.paginationState.pageIndex != undefined &&
|
|
84
121
|
this.paginationRepo?.paginationState.pageSize != undefined) {
|
|
@@ -326,12 +363,7 @@ export class TableContext {
|
|
|
326
363
|
return this._columnDefs;
|
|
327
364
|
}
|
|
328
365
|
set columnDefs(v) {
|
|
329
|
-
// if (this._columnDefs.length > 0 && v != this._columnDefs) {
|
|
330
|
-
// debugger;
|
|
331
|
-
// }
|
|
332
366
|
this._columnDefs = v;
|
|
333
|
-
// this causes an error...?
|
|
334
|
-
// this.table = createTable(this.tableOptions);
|
|
335
367
|
}
|
|
336
368
|
_columnPresets = $state([]);
|
|
337
369
|
get columnPresets() {
|
|
@@ -649,41 +681,17 @@ export class TableContext {
|
|
|
649
681
|
}
|
|
650
682
|
return this.showSelectedOnly ? [...this.selectedItems.values()] : (this.dataRepo?.data ?? []);
|
|
651
683
|
});
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
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
|
-
});
|
|
684
|
+
_sortedData = $state([]);
|
|
685
|
+
get sortedData() {
|
|
686
|
+
return this._sortedData;
|
|
687
|
+
}
|
|
680
688
|
sortedRowModel = $derived.by(() => {
|
|
681
689
|
const rows = this.sortedData.map((item, index) => {
|
|
682
690
|
const originalIndex = this._originalRowIndices.get(item);
|
|
683
691
|
const unsortedIndex = originalIndex ?? index;
|
|
684
692
|
if (originalIndex == null) {
|
|
685
|
-
|
|
686
|
-
|
|
693
|
+
$inspect(this.sortedData);
|
|
694
|
+
$inspect(this._originalRowIndices);
|
|
687
695
|
throw new Error(`Sorted Data not found in Original Row Indices: original index ${originalIndex}, index ${index}`);
|
|
688
696
|
}
|
|
689
697
|
return this.createRow(item, index, unsortedIndex);
|
|
@@ -962,7 +970,6 @@ export class TableContext {
|
|
|
962
970
|
onEditCell = async (item, coords, value) => {
|
|
963
971
|
const oldKey = this.selectionExtractor?.(item);
|
|
964
972
|
const wasSelected = oldKey != null && this.selectedItems.has(oldKey);
|
|
965
|
-
// debugger;
|
|
966
973
|
if (wasSelected) {
|
|
967
974
|
this.selectedItems.delete(oldKey);
|
|
968
975
|
}
|
|
@@ -1881,8 +1888,8 @@ export class TableContext {
|
|
|
1881
1888
|
for (const item of selectedRows) {
|
|
1882
1889
|
const rowIndex = this.sortedData.indexOf(item);
|
|
1883
1890
|
if (rowIndex == -1) {
|
|
1884
|
-
|
|
1885
|
-
|
|
1891
|
+
console.warn(`row index for highlighted row data not found`);
|
|
1892
|
+
continue;
|
|
1886
1893
|
}
|
|
1887
1894
|
indices.set(item, rowIndex);
|
|
1888
1895
|
}
|