svelte-tably 1.1.0 → 1.1.1
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.
|
@@ -42,6 +42,22 @@ export class TableState {
|
|
|
42
42
|
if (state instanceof ColumnState) {
|
|
43
43
|
const key = state.id;
|
|
44
44
|
this.columns[key] = state;
|
|
45
|
+
const insertBySavedOrder = (arr, item, savedOrder) => {
|
|
46
|
+
const idx = savedOrder.indexOf(item.id);
|
|
47
|
+
if (idx === -1) {
|
|
48
|
+
arr.push(item);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let i = 0;
|
|
52
|
+
for (; i < arr.length; i++) {
|
|
53
|
+
const otherIdx = savedOrder.indexOf(arr[i].id);
|
|
54
|
+
if (otherIdx === -1)
|
|
55
|
+
continue;
|
|
56
|
+
if (otherIdx > idx)
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
arr.splice(i, 0, item);
|
|
60
|
+
};
|
|
45
61
|
const clean = () => {
|
|
46
62
|
delete this.columns[key];
|
|
47
63
|
this.positions.fixed = this.positions.fixed.filter((column) => column !== state);
|
|
@@ -61,19 +77,19 @@ export class TableState {
|
|
|
61
77
|
const isSaved = Object.values(saved).some(v => v);
|
|
62
78
|
if ((!isSaved && state.options.fixed)
|
|
63
79
|
|| saved.fixed) {
|
|
64
|
-
this.positions.fixed.
|
|
80
|
+
insertBySavedOrder(this.positions.fixed, state, this.#positions.fixed);
|
|
65
81
|
return clean;
|
|
66
82
|
}
|
|
67
83
|
if ((!isSaved && state.defaults.show === false)
|
|
68
84
|
|| saved.hidden) {
|
|
69
|
-
this.positions.hidden.
|
|
85
|
+
insertBySavedOrder(this.positions.hidden, state, this.#positions.hidden);
|
|
70
86
|
}
|
|
71
87
|
if ((!isSaved && state.defaults.sticky)
|
|
72
88
|
|| saved.sticky) {
|
|
73
|
-
this.positions.sticky.
|
|
89
|
+
insertBySavedOrder(this.positions.sticky, state, this.#positions.sticky);
|
|
74
90
|
}
|
|
75
91
|
else {
|
|
76
|
-
this.positions.scroll.
|
|
92
|
+
insertBySavedOrder(this.positions.scroll, state, this.#positions.scroll);
|
|
77
93
|
}
|
|
78
94
|
return clean;
|
|
79
95
|
}
|
|
@@ -152,7 +168,8 @@ export class TableState {
|
|
|
152
168
|
}
|
|
153
169
|
$effect(() => {
|
|
154
170
|
Object.keys(this.columnWidths);
|
|
155
|
-
|
|
171
|
+
// Track order changes by observing the id sequences
|
|
172
|
+
Object.values(this.positions).map(arr => arr.map(c => c.id).join('|'));
|
|
156
173
|
this.dataState.sortby;
|
|
157
174
|
this.dataState.sortReverse;
|
|
158
175
|
this.#scheduleSave();
|