@lavalogic/scoria 0.11.9 → 0.11.11
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.
|
@@ -147,7 +147,8 @@ export declare class TableContext<T extends object> {
|
|
|
147
147
|
private _filteredIndices;
|
|
148
148
|
get filteredIndices(): number[];
|
|
149
149
|
set filteredIndices(v: number[]);
|
|
150
|
-
|
|
150
|
+
private _filteredData;
|
|
151
|
+
get filteredData(): T[];
|
|
151
152
|
private _sortedData;
|
|
152
153
|
get sortedData(): T[];
|
|
153
154
|
readonly sortedRowModel: RowModel<T>;
|
|
@@ -67,13 +67,25 @@ export class TableContext {
|
|
|
67
67
|
this._dataRepo = $state(dataRepo);
|
|
68
68
|
// this.dataRepo.forceRefresh = this.forceVisibilityUpdate;
|
|
69
69
|
$effect(() => {
|
|
70
|
+
const fd = (() => {
|
|
71
|
+
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|
|
72
|
+
const data = this.showSelectedOnly
|
|
73
|
+
? // FIXME this will show the selected items by order of insertion to the selectedItems map.
|
|
74
|
+
[...this.selectedItems.values()]
|
|
75
|
+
: (this.filteredIndices.map((index) => {
|
|
76
|
+
return dataRepo.data[index];
|
|
77
|
+
}) ?? []);
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
return this.showSelectedOnly ? [...this.selectedItems.values()] : (dataRepo?.data ?? []);
|
|
81
|
+
})();
|
|
70
82
|
const sd = (() => {
|
|
71
83
|
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|
|
72
|
-
const state =
|
|
84
|
+
const state = dataRepo.sorting ?? [];
|
|
73
85
|
const sortedData = this.showSelectedOnly
|
|
74
86
|
? // FIXME this will show the selected items by order of insertion to the selectedItems map.
|
|
75
87
|
[...this.selectedItems.values()]
|
|
76
|
-
:
|
|
88
|
+
: fd.concat();
|
|
77
89
|
sortedData.sort((a, b) => {
|
|
78
90
|
const end = state.length;
|
|
79
91
|
for (let i = 0; i < end; i++) {
|
|
@@ -93,7 +105,7 @@ export class TableContext {
|
|
|
93
105
|
});
|
|
94
106
|
return sortedData;
|
|
95
107
|
}
|
|
96
|
-
return
|
|
108
|
+
return fd ?? [];
|
|
97
109
|
})();
|
|
98
110
|
const cpd = (() => {
|
|
99
111
|
if (dataRepo.paginationType != PaginationType.Local) {
|
|
@@ -102,13 +114,10 @@ export class TableContext {
|
|
|
102
114
|
return sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive);
|
|
103
115
|
})();
|
|
104
116
|
const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
}
|
|
117
|
+
this._filteredData = fd;
|
|
118
|
+
this._sortedData = sd;
|
|
119
|
+
this._currentPageData = cpd;
|
|
120
|
+
this._originalRowIndices = ori;
|
|
112
121
|
});
|
|
113
122
|
$effect(() => {
|
|
114
123
|
if (this._currentPageData) {
|
|
@@ -121,6 +130,9 @@ export class TableContext {
|
|
|
121
130
|
});
|
|
122
131
|
}
|
|
123
132
|
});
|
|
133
|
+
$effect(() => {
|
|
134
|
+
$inspect(this.sortedData, this._currentPageData, this._originalRowIndices);
|
|
135
|
+
});
|
|
124
136
|
if (defaultColumnDefs.remoteFilters) {
|
|
125
137
|
this.remoteFilters = defaultColumnDefs.remoteFilters;
|
|
126
138
|
}
|
|
@@ -665,18 +677,10 @@ export class TableContext {
|
|
|
665
677
|
set filteredIndices(v) {
|
|
666
678
|
this._filteredIndices = v;
|
|
667
679
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
[...this.selectedItems.values()]
|
|
673
|
-
: (this.filteredIndices.map((index) => {
|
|
674
|
-
return this.dataRepo.data[index];
|
|
675
|
-
}) ?? []);
|
|
676
|
-
return data;
|
|
677
|
-
}
|
|
678
|
-
return this.showSelectedOnly ? [...this.selectedItems.values()] : (this.dataRepo?.data ?? []);
|
|
679
|
-
});
|
|
680
|
+
_filteredData = $state([]);
|
|
681
|
+
get filteredData() {
|
|
682
|
+
return this._filteredData;
|
|
683
|
+
}
|
|
680
684
|
_sortedData = $state([]);
|
|
681
685
|
get sortedData() {
|
|
682
686
|
return this._sortedData;
|
|
@@ -686,8 +690,6 @@ export class TableContext {
|
|
|
686
690
|
const originalIndex = this._originalRowIndices.get(item);
|
|
687
691
|
const unsortedIndex = originalIndex ?? index;
|
|
688
692
|
if (originalIndex == null) {
|
|
689
|
-
$inspect(this.sortedData);
|
|
690
|
-
$inspect(this._originalRowIndices);
|
|
691
693
|
throw new Error(`Sorted Data not found in Original Row Indices: original index ${originalIndex}, index ${index}`);
|
|
692
694
|
}
|
|
693
695
|
return this.createRow(item, index, unsortedIndex);
|
|
@@ -713,8 +715,6 @@ export class TableContext {
|
|
|
713
715
|
const rows = sortedData.map((item, index) => {
|
|
714
716
|
const unsortedIndex = this._originalRowIndices.get(item) ?? index;
|
|
715
717
|
if (!item) {
|
|
716
|
-
console.log($state.snapshot(sortedData));
|
|
717
|
-
console.log($state.snapshot(this._originalRowIndices));
|
|
718
718
|
throw new Error(`No Item was found at index ${index}`);
|
|
719
719
|
}
|
|
720
720
|
const row = {
|
|
@@ -874,7 +874,7 @@ export class TableContext {
|
|
|
874
874
|
const item = this.sortedData[index];
|
|
875
875
|
// HACK: Please find why this is happening and fix it properly
|
|
876
876
|
if (!item) {
|
|
877
|
-
console.warn(`skipping update because there is a data mismatch
|
|
877
|
+
console.warn(`skipping update because there is a data mismatch (with selectable method)`);
|
|
878
878
|
return;
|
|
879
879
|
}
|
|
880
880
|
if (await selectableMethod(item, index)) {
|
|
@@ -887,7 +887,7 @@ export class TableContext {
|
|
|
887
887
|
const item = this.sortedData[index];
|
|
888
888
|
// HACK: Please find why this is happening and fix it properly
|
|
889
889
|
if (!item) {
|
|
890
|
-
console.warn(`skipping update because there is a data mismatch
|
|
890
|
+
console.warn(`skipping update because there is a data mismatch (no selectable method)`);
|
|
891
891
|
return;
|
|
892
892
|
}
|
|
893
893
|
updateSelectedItem(item);
|
|
@@ -902,10 +902,18 @@ export class TableContext {
|
|
|
902
902
|
this.recalculateAllSelectedInCurrentPage();
|
|
903
903
|
};
|
|
904
904
|
recalculateAllSelectedInCurrentPage = () => {
|
|
905
|
-
tick()
|
|
906
|
-
|
|
905
|
+
tick()
|
|
906
|
+
.then(() => {
|
|
907
|
+
this.allSelectedInCurrentPage
|
|
908
|
+
?.then(() => {
|
|
907
909
|
this.hasInvalidSelectedItems = [...this.selectedItems.keys()].some((key) => this._invalidValues.has(key));
|
|
910
|
+
})
|
|
911
|
+
.catch((e) => {
|
|
912
|
+
console.log(e);
|
|
908
913
|
});
|
|
914
|
+
})
|
|
915
|
+
.catch((e) => {
|
|
916
|
+
console.log(e);
|
|
909
917
|
});
|
|
910
918
|
};
|
|
911
919
|
selectAllInCurrentPage = async () => {
|
|
@@ -1720,7 +1728,6 @@ export class TableContext {
|
|
|
1720
1728
|
// #region private methods
|
|
1721
1729
|
createRow(item, index, unsortedIndex) {
|
|
1722
1730
|
if (!item) {
|
|
1723
|
-
console.log($state.snapshot(this._originalRowIndices));
|
|
1724
1731
|
throw new Error(`No Item was found at index ${index} (unsorted index ${unsortedIndex})`);
|
|
1725
1732
|
}
|
|
1726
1733
|
const row = {
|