svelte-tably 1.1.0 → 1.1.2

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.
@@ -200,9 +200,13 @@
200
200
  elements.selects.scrollTop = target?.scrollTop
201
201
  }
202
202
 
203
- if (!elements.headers) return
204
- elements.headers.scrollLeft = target.scrollLeft
205
- elements.statusbar.scrollLeft = target.scrollLeft
203
+ if (elements.headers) {
204
+ elements.headers.scrollLeft = target.scrollLeft
205
+ }
206
+
207
+ if (elements.statusbar) {
208
+ elements.statusbar.scrollLeft = target.scrollLeft
209
+ }
206
210
  }
207
211
 
208
212
  // * --- CSV --- *
@@ -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.push(state);
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.push(state);
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.push(state);
89
+ insertBySavedOrder(this.positions.sticky, state, this.#positions.sticky);
74
90
  }
75
91
  else {
76
- this.positions.scroll.push(state);
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
- Object.values(this.positions).map(v => v.length);
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-tably",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A high performant dynamic table for Svelte 5",
5
5
  "license": "MIT",
6
6
  "repository": {