@universal-ember/table 3.1.0 → 3.2.0
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.
- package/declarations/-private/column.d.ts +1 -1
- package/declarations/-private/column.d.ts.map +1 -1
- package/declarations/-private/interfaces/column.d.ts +1 -1
- package/declarations/-private/interfaces/column.d.ts.map +1 -1
- package/declarations/plugins/column-reordering/plugin.d.ts +43 -2
- package/declarations/plugins/column-reordering/plugin.d.ts.map +1 -1
- package/dist/plugins/column-reordering/plugin.js +138 -57
- package/dist/plugins/column-reordering/plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/-private/interfaces/column.ts +1 -1
- package/src/plugins/column-reordering/plugin.ts +206 -73
|
@@ -5,7 +5,7 @@ import type { ColumnConfig } from './interfaces';
|
|
|
5
5
|
export declare class Column<T = unknown> {
|
|
6
6
|
table: Table<T>;
|
|
7
7
|
config: ColumnConfig<T>;
|
|
8
|
-
get Cell(): import("@glint/template").ComponentLike | undefined;
|
|
8
|
+
get Cell(): import("@glint/template").ComponentLike<import("./interfaces").CellContext<T>> | undefined;
|
|
9
9
|
get key(): string;
|
|
10
10
|
get name(): string | undefined;
|
|
11
11
|
constructor(table: Table<T>, config: ColumnConfig<T>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/-private/column.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,qBAAa,MAAM,CAAC,CAAC,GAAG,OAAO;IAcpB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACf,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAdhC,IAAI,IAAI
|
|
1
|
+
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/-private/column.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,qBAAa,MAAM,CAAC,CAAC,GAAG,OAAO;IAcpB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACf,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAdhC,IAAI,IAAI,+FAEP;IAED,IAAI,GAAG,WAEN;IAED,IAAI,IAAI,uBAEP;gBAGQ,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAIhC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY;IAoBzC,OAAO,CAAC,eAAe;IAKvB,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;;;CAQ7B"}
|
|
@@ -36,7 +36,7 @@ export interface ColumnConfig<T = unknown> {
|
|
|
36
36
|
* Out-of-the-box, this property isn't used, but the provided type may be
|
|
37
37
|
* a convenience for consumers of the headless table
|
|
38
38
|
*/
|
|
39
|
-
Cell?: ComponentLike
|
|
39
|
+
Cell?: ComponentLike<CellContext<T>>;
|
|
40
40
|
/**
|
|
41
41
|
* The name or title of the column, shown in the column heading / th
|
|
42
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../../src/-private/interfaces/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EA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AAa,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -90,7 +90,8 @@ export declare class TableMeta {
|
|
|
90
90
|
* @private
|
|
91
91
|
* This isn't our data to expose, but it is useful to alias
|
|
92
92
|
*/
|
|
93
|
-
private get
|
|
93
|
+
private get visibleColumns();
|
|
94
|
+
private get allColumns();
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* @private
|
|
@@ -103,10 +104,47 @@ export declare class ColumnOrder {
|
|
|
103
104
|
*/
|
|
104
105
|
map: TrackedMap<string, number>;
|
|
105
106
|
constructor(args: {
|
|
107
|
+
/**
|
|
108
|
+
* All columns to track in the ordering.
|
|
109
|
+
*
|
|
110
|
+
* Backwards compatible usage (without ColumnVisibility):
|
|
111
|
+
* - Pass only the columns you want to display
|
|
112
|
+
* - All columns are treated as visible
|
|
113
|
+
*
|
|
114
|
+
* New usage (with ColumnVisibility):
|
|
115
|
+
* - Pass ALL columns (including hidden ones)
|
|
116
|
+
* - Provide `visibleColumns` to indicate which are visible
|
|
117
|
+
* - Hidden columns maintain their position when toggled
|
|
118
|
+
*/
|
|
106
119
|
columns: () => Column[];
|
|
120
|
+
/**
|
|
121
|
+
* Optional: Record of which columns are currently visible.
|
|
122
|
+
* When provided, moveLeft/moveRight will skip over hidden columns.
|
|
123
|
+
* When omitted, all columns from `columns` are treated as visible (backwards compatible).
|
|
124
|
+
*
|
|
125
|
+
* Example when using ColumnVisibility:
|
|
126
|
+
* ```ts
|
|
127
|
+
* visibleColumns: () => columns.reduce((acc, col) => {
|
|
128
|
+
* acc[col.key] = meta(col).ColumnVisibility?.isVisible !== false;
|
|
129
|
+
* return acc;
|
|
130
|
+
* }, {})
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
visibleColumns?: () => Record<string, boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Optional: Callback to persist the column order (e.g., to localStorage).
|
|
136
|
+
*/
|
|
107
137
|
save?: (order: Map<string, number>) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Optional: Previously saved column order to restore.
|
|
140
|
+
*/
|
|
108
141
|
existingOrder?: Map<string, number>;
|
|
109
142
|
});
|
|
143
|
+
/**
|
|
144
|
+
* @private
|
|
145
|
+
* Helper to get visible columns, defaulting to all columns if not specified
|
|
146
|
+
*/
|
|
147
|
+
private getVisibleColumns;
|
|
110
148
|
/**
|
|
111
149
|
* To account for columnVisibilty, we need to:
|
|
112
150
|
* - get the list of visible columns
|
|
@@ -139,7 +177,10 @@ export declare class ColumnOrder {
|
|
|
139
177
|
* @private
|
|
140
178
|
*
|
|
141
179
|
* Utility for helping determine the percieved order of a set of columns
|
|
142
|
-
* given the original (default) ordering, and then user-configurations
|
|
180
|
+
* given the original (default) ordering, and then user-configurations.
|
|
181
|
+
*
|
|
182
|
+
* This function adds missing columns but preserves extra columns in the map
|
|
183
|
+
* (they might be hidden, not deleted).
|
|
143
184
|
*/
|
|
144
185
|
export declare function orderOf(columns: {
|
|
145
186
|
key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/column-reordering/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAE,UAAU,EAAiB,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEpD,UAAU,2BAA4B,SAAQ,iBAAiB;IAC7D,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;CACH;AAED,OAAO,QAAQ,gC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AAO,EAAE,MAAM,MAAM,EAAE,CAAC;QACxB;;;;;;;;;;;;WAYG;QACH,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C;;WAEG;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;QAC5C;;WAEG;QACH,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACrC;IAeH;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAezB;;;;;;OAMG;IAEH,QAAQ,CAAC,GAAG,EAAE,MAAM;IAsCpB,MAAM,GAAI,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAahC;IAEF;;;;;;OAMG;IAEH,SAAS,CAAC,GAAG,EAAE,MAAM;IAkCrB;;OAEG;IAEH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA0EtC,GAAG,CAAC,GAAG,EAAE,MAAM;IAYf;;OAEG;IACH,IACI,UAAU,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAE5C;IAED,IACI,cAAc,IAAI,MAAM,EAAE,CAgC7B;CACF;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACrB,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,EAC1B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBrB"}
|
|
@@ -45,6 +45,8 @@ class ColumnMeta {
|
|
|
45
45
|
get position() {
|
|
46
46
|
return _classPrivateGetter(_ColumnMeta_brand, this, _get_tableMeta).getPosition(this.column);
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
// Swaps this column with the column in the new position
|
|
48
50
|
set position(value) {
|
|
49
51
|
_classPrivateGetter(_ColumnMeta_brand, this, _get_tableMeta).setPosition(this.column, value);
|
|
50
52
|
}
|
|
@@ -103,7 +105,8 @@ let TableMeta = (_class = class TableMeta {
|
|
|
103
105
|
reset() {
|
|
104
106
|
preferences.forTable(this.table, ColumnReordering).delete('order');
|
|
105
107
|
this.columnOrder = new ColumnOrder({
|
|
106
|
-
columns: () => this.
|
|
108
|
+
columns: () => this.allColumns,
|
|
109
|
+
visibleColumns: () => this.visibleColumns,
|
|
107
110
|
save: this.save
|
|
108
111
|
});
|
|
109
112
|
}
|
|
@@ -128,15 +131,21 @@ let TableMeta = (_class = class TableMeta {
|
|
|
128
131
|
return new Map(Object.entries(order));
|
|
129
132
|
}
|
|
130
133
|
get columns() {
|
|
131
|
-
return this.columnOrder.orderedColumns;
|
|
134
|
+
return this.columnOrder.orderedColumns.filter(column => this.visibleColumns[column.key]);
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
/**
|
|
135
138
|
* @private
|
|
136
139
|
* This isn't our data to expose, but it is useful to alias
|
|
137
140
|
*/
|
|
138
|
-
get
|
|
139
|
-
return columns.for(this.table, ColumnReordering)
|
|
141
|
+
get visibleColumns() {
|
|
142
|
+
return columns.for(this.table, ColumnReordering).reduce((acc, column) => {
|
|
143
|
+
acc[column.key] = true;
|
|
144
|
+
return acc;
|
|
145
|
+
}, {});
|
|
146
|
+
}
|
|
147
|
+
get allColumns() {
|
|
148
|
+
return this.table.columns.values();
|
|
140
149
|
}
|
|
141
150
|
}, _descriptor = _applyDecoratedDescriptor(_class.prototype, "columnOrder", [tracked], {
|
|
142
151
|
configurable: true,
|
|
@@ -144,7 +153,8 @@ let TableMeta = (_class = class TableMeta {
|
|
|
144
153
|
writable: true,
|
|
145
154
|
initializer: function () {
|
|
146
155
|
return new ColumnOrder({
|
|
147
|
-
columns: () => this.
|
|
156
|
+
columns: () => this.allColumns,
|
|
157
|
+
visibleColumns: () => this.visibleColumns,
|
|
148
158
|
save: this.save,
|
|
149
159
|
existingOrder: this.read()
|
|
150
160
|
});
|
|
@@ -162,6 +172,9 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
162
172
|
*/
|
|
163
173
|
_defineProperty(this, "map", new TrackedMap());
|
|
164
174
|
_defineProperty(this, "setAll", map => {
|
|
175
|
+
let allColumns = this.args.columns();
|
|
176
|
+
addMissingColumnsToMap(allColumns, map);
|
|
177
|
+
removeExtraColumnsFromMap(allColumns, map);
|
|
165
178
|
this.map.clear();
|
|
166
179
|
for (const [key, value] of map.entries()) {
|
|
167
180
|
this.map.set(key, value);
|
|
@@ -169,11 +182,33 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
169
182
|
this.args.save?.(map);
|
|
170
183
|
});
|
|
171
184
|
this.args = args;
|
|
185
|
+
let _allColumns = this.args.columns();
|
|
172
186
|
if (args.existingOrder) {
|
|
173
|
-
|
|
187
|
+
let newOrder = new Map(args.existingOrder.entries());
|
|
188
|
+
addMissingColumnsToMap(_allColumns, newOrder);
|
|
189
|
+
removeExtraColumnsFromMap(_allColumns, newOrder);
|
|
190
|
+
this.map = new TrackedMap(newOrder);
|
|
191
|
+
} else {
|
|
192
|
+
this.map = new TrackedMap(_allColumns.map((column, i) => [column.key, i]));
|
|
174
193
|
}
|
|
175
194
|
}
|
|
176
195
|
|
|
196
|
+
/**
|
|
197
|
+
* @private
|
|
198
|
+
* Helper to get visible columns, defaulting to all columns if not specified
|
|
199
|
+
*/
|
|
200
|
+
getVisibleColumns() {
|
|
201
|
+
if (this.args.visibleColumns) {
|
|
202
|
+
return this.args.visibleColumns();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Default: all columns are visible
|
|
206
|
+
return this.args.columns().reduce((acc, col) => {
|
|
207
|
+
acc[col.key] = true;
|
|
208
|
+
return acc;
|
|
209
|
+
}, {});
|
|
210
|
+
}
|
|
211
|
+
|
|
177
212
|
/**
|
|
178
213
|
* To account for columnVisibilty, we need to:
|
|
179
214
|
* - get the list of visible columns
|
|
@@ -183,20 +218,30 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
183
218
|
*/
|
|
184
219
|
moveLeft(key) {
|
|
185
220
|
const orderedColumns = this.orderedColumns;
|
|
221
|
+
if (this.map.get(key) === 0) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
186
224
|
let found = false;
|
|
187
|
-
let nextColumn;
|
|
188
225
|
for (const column of orderedColumns.reverse()) {
|
|
189
226
|
if (found) {
|
|
190
|
-
|
|
191
|
-
|
|
227
|
+
// Shift moved column left
|
|
228
|
+
let currentPosition = this.map.get(key);
|
|
229
|
+
assert('current key must exist in map', currentPosition !== undefined);
|
|
230
|
+
this.map.set(key, currentPosition - 1);
|
|
231
|
+
|
|
232
|
+
// Shift displayed column right
|
|
233
|
+
let displayedColumnPosition = this.map.get(column.key);
|
|
234
|
+
assert('displaced key must exist in map', displayedColumnPosition !== undefined);
|
|
235
|
+
this.map.set(column.key, displayedColumnPosition + 1);
|
|
236
|
+
if (this.getVisibleColumns()[column.key]) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
192
239
|
}
|
|
193
240
|
if (column.key === key) {
|
|
194
241
|
found = true;
|
|
195
242
|
}
|
|
196
243
|
}
|
|
197
|
-
|
|
198
|
-
const nextPosition = this.get(nextColumn.key);
|
|
199
|
-
this.swapWith(key, nextPosition);
|
|
244
|
+
this.args.save?.(this.map);
|
|
200
245
|
}
|
|
201
246
|
/**
|
|
202
247
|
* To account for columnVisibilty, we need to:
|
|
@@ -208,19 +253,26 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
208
253
|
moveRight(key) {
|
|
209
254
|
const orderedColumns = this.orderedColumns;
|
|
210
255
|
let found = false;
|
|
211
|
-
let nextColumn;
|
|
212
256
|
for (const column of orderedColumns) {
|
|
213
257
|
if (found) {
|
|
214
|
-
|
|
215
|
-
|
|
258
|
+
// Shift moved column right
|
|
259
|
+
let currentPosition = this.map.get(key);
|
|
260
|
+
assert('current key must exist in map', currentPosition !== undefined);
|
|
261
|
+
this.map.set(key, currentPosition + 1);
|
|
262
|
+
|
|
263
|
+
// Shift displaced column left
|
|
264
|
+
let displayedColumnPosition = this.map.get(column.key);
|
|
265
|
+
assert('displaced key must exist in map', displayedColumnPosition !== undefined);
|
|
266
|
+
this.map.set(column.key, displayedColumnPosition - 1);
|
|
267
|
+
if (this.getVisibleColumns()[column.key]) {
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
216
270
|
}
|
|
217
271
|
if (column.key === key) {
|
|
218
272
|
found = true;
|
|
219
273
|
}
|
|
220
274
|
}
|
|
221
|
-
|
|
222
|
-
const nextPosition = this.get(nextColumn.key);
|
|
223
|
-
this.swapWith(key, nextPosition);
|
|
275
|
+
this.args.save?.(this.map);
|
|
224
276
|
}
|
|
225
277
|
|
|
226
278
|
/**
|
|
@@ -241,7 +293,7 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
241
293
|
* by reading orderedMap
|
|
242
294
|
*/
|
|
243
295
|
const currentPosition = this.orderedMap.get(key);
|
|
244
|
-
assert(`Pre-existing position for ${key} could not be found. Does the column exist? ` + `The current positions are: ` + [...this.orderedMap.entries()].map(entry => entry.join(' => ')).join(', ') + ` and the
|
|
296
|
+
assert(`Pre-existing position for ${key} could not be found. Does the column exist? ` + `The current positions are: ` + [...this.orderedMap.entries()].map(entry => entry.join(' => ')).join(', ') + ` and the visibleColumns are: ` + Object.keys(this.getVisibleColumns()).join(', ') + ` and current "map" (${this.map.size}) is: ` + [...this.map.entries()].map(entry => entry.join(' => ')).join(', '), undefined !== currentPosition);
|
|
245
297
|
|
|
246
298
|
/**
|
|
247
299
|
* No need to change anything if the position is the same
|
|
@@ -291,21 +343,21 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
291
343
|
return orderOf(this.args.columns(), this.map);
|
|
292
344
|
}
|
|
293
345
|
get orderedColumns() {
|
|
294
|
-
const
|
|
295
|
-
const
|
|
346
|
+
const allColumns = this.args.columns();
|
|
347
|
+
const columnsByKey = allColumns.reduce((keyMap, column) => {
|
|
296
348
|
keyMap[column.key] = column;
|
|
297
349
|
return keyMap;
|
|
298
350
|
}, {});
|
|
299
|
-
const mergedOrder = orderOf(
|
|
351
|
+
const mergedOrder = orderOf(allColumns, this.map);
|
|
300
352
|
const result = Array.from({
|
|
301
|
-
length:
|
|
353
|
+
length: allColumns.length
|
|
302
354
|
});
|
|
303
355
|
for (const [key, position] of mergedOrder.entries()) {
|
|
304
|
-
const column =
|
|
356
|
+
const column = columnsByKey[key];
|
|
305
357
|
assert(`Could not find column for pair: ${key} @ @{position}`, column);
|
|
306
358
|
result[position] = column;
|
|
307
359
|
}
|
|
308
|
-
assert(`Generated orderedColumns' length (${result.filter(Boolean).length}) ` + `does not match the length of
|
|
360
|
+
assert(`Generated orderedColumns' length (${result.filter(Boolean).length}) ` + `does not match the length of all columns (${allColumns.length}). ` + `orderedColumns: ${result.filter(Boolean).map(c => c.key).join(', ')} -- ` + `all columns: ${allColumns.map(c => c.key).join(', ')}`, result.filter(Boolean).length === allColumns.length);
|
|
309
361
|
return result.filter(Boolean);
|
|
310
362
|
}
|
|
311
363
|
}, _applyDecoratedDescriptor(_class2.prototype, "moveLeft", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "moveLeft"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "moveRight", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "moveRight"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "swapWith", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "swapWith"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "get", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "get"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "orderedMap", [cached], Object.getOwnPropertyDescriptor(_class2.prototype, "orderedMap"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "orderedColumns", [cached], Object.getOwnPropertyDescriptor(_class2.prototype, "orderedColumns"), _class2.prototype), _class2);
|
|
@@ -314,45 +366,74 @@ let ColumnOrder = (_class2 = class ColumnOrder {
|
|
|
314
366
|
* @private
|
|
315
367
|
*
|
|
316
368
|
* Utility for helping determine the percieved order of a set of columns
|
|
317
|
-
* given the original (default) ordering, and then user-configurations
|
|
369
|
+
* given the original (default) ordering, and then user-configurations.
|
|
370
|
+
*
|
|
371
|
+
* This function adds missing columns but preserves extra columns in the map
|
|
372
|
+
* (they might be hidden, not deleted).
|
|
318
373
|
*/
|
|
319
374
|
function orderOf(columns, currentOrder) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const availableSet = new Set(availableColumns);
|
|
323
|
-
const current = new Map([...currentOrder.entries()].map(([key, position]) => [position, key]));
|
|
375
|
+
// Create a copy to avoid mutating the input
|
|
376
|
+
let workingOrder = new Map(currentOrder);
|
|
324
377
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
378
|
+
// Add any missing columns to the end
|
|
379
|
+
addMissingColumnsToMap(columns, workingOrder);
|
|
380
|
+
|
|
381
|
+
// DON'T remove extra columns - they might be hidden columns, not deleted ones
|
|
382
|
+
// The ColumnOrder constructor handles removal of truly deleted columns
|
|
383
|
+
|
|
384
|
+
// Ensure positions are consecutive and zero based
|
|
385
|
+
let inOrder = Array.from(workingOrder.entries()).sort(([_keyA, positionA], [_keyB, positionB]) => positionA - positionB);
|
|
386
|
+
let orderedColumns = new Map();
|
|
387
|
+
let position = 0;
|
|
388
|
+
for (let [key] of inOrder) {
|
|
389
|
+
orderedColumns.set(key, position++);
|
|
390
|
+
}
|
|
391
|
+
return orderedColumns;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @private
|
|
396
|
+
*
|
|
397
|
+
* Utility to add any missing columns to the position map. By calling this whenever
|
|
398
|
+
* data is passed in to the system we can simplify the code within the system because
|
|
399
|
+
* we know we are dealing with a full set of positions.
|
|
400
|
+
*
|
|
401
|
+
* @param columns - A list of all columns available to the table
|
|
402
|
+
* @param map - A Map of `key` to position (as a zero based integer)
|
|
403
|
+
*/
|
|
404
|
+
function addMissingColumnsToMap(columns, map) {
|
|
405
|
+
if (map.size < columns.length) {
|
|
406
|
+
let maxAssignedColumn = Math.max(...map.values());
|
|
407
|
+
for (let column of columns) {
|
|
408
|
+
if (map.get(column.key) === undefined) {
|
|
409
|
+
map.set(column.key, ++maxAssignedColumn);
|
|
344
410
|
}
|
|
345
|
-
break;
|
|
346
411
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @private
|
|
417
|
+
*
|
|
418
|
+
* Utility to remove any extra columns from the position map. By calling this whenever
|
|
419
|
+
* data is passed in to the system we can simplify the code within the system because
|
|
420
|
+
* we know we are dealing with a full set of positions.
|
|
421
|
+
*
|
|
422
|
+
* @param columns - A list of all columns available to the table
|
|
423
|
+
* @param map - A Map of `key` to position (as a zero based integer)
|
|
424
|
+
*/
|
|
425
|
+
function removeExtraColumnsFromMap(columns, map) {
|
|
426
|
+
let columnsLookup = columns.reduce(function (acc, {
|
|
427
|
+
key
|
|
428
|
+
}) {
|
|
429
|
+
acc[key] = true;
|
|
430
|
+
return acc;
|
|
431
|
+
}, {});
|
|
432
|
+
for (let key of map.keys()) {
|
|
433
|
+
if (!columnsLookup[key]) {
|
|
434
|
+
map.delete(key);
|
|
352
435
|
}
|
|
353
|
-
result.set(availableKey, i);
|
|
354
436
|
}
|
|
355
|
-
return result;
|
|
356
437
|
}
|
|
357
438
|
|
|
358
439
|
export { ColumnMeta, ColumnOrder, ColumnReordering, TableMeta, orderOf };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/plugins/column-reordering/plugin.ts"],"sourcesContent":["import { cached, tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { action } from '@ember/object';\n\nimport { TrackedMap } from 'tracked-built-ins';\n\nimport { preferences } from '../../plugins/index.ts';\n\nimport { BasePlugin, columns, meta } from '../-private/base.ts';\n\nimport type { PluginPreferences } from '../../plugins/index.ts';\nimport type { Column, Table } from '../../index.ts';\n\ninterface ColumnReorderingPreferences extends PluginPreferences {\n table: {\n order?: Record<string, number>;\n };\n}\n\ndeclare module '@universal-ember/table/plugins' {\n interface Registry {\n ColumnReordering?: ColumnReorderingPreferences;\n 'column-reordering'?: ColumnReorderingPreferences;\n }\n}\n\nexport interface Signature {\n Meta: {\n Column: ColumnMeta;\n Table: TableMeta;\n };\n}\n\nexport class ColumnReordering extends BasePlugin<Signature> {\n name = 'column-reordering';\n static features = ['columnOrder'];\n\n meta = {\n column: ColumnMeta,\n table: TableMeta,\n } as const;\n\n reset() {\n const tableMeta = meta.forTable(this.table, ColumnReordering);\n\n tableMeta.reset();\n }\n\n get columns() {\n return meta.forTable(this.table, ColumnReordering).columns;\n }\n}\n\nexport class ColumnMeta {\n constructor(private column: Column) {}\n\n get #tableMeta() {\n return meta.forTable(this.column.table, ColumnReordering);\n }\n\n get position() {\n return this.#tableMeta.getPosition(this.column);\n }\n\n set position(value: number) {\n this.#tableMeta.setPosition(this.column, value);\n }\n\n get canMoveLeft() {\n return this.#tableMeta.getPosition(this.column) !== 0;\n }\n\n get canMoveRight() {\n return (\n this.#tableMeta.getPosition(this.column) !==\n this.#tableMeta.columns.length - 1\n );\n }\n\n get cannotMoveLeft() {\n return !this.canMoveLeft;\n }\n\n get cannotMoveRight() {\n return !this.canMoveRight;\n }\n\n /**\n * Move the column one spot to the left\n */\n moveLeft = () => {\n this.#tableMeta.columnOrder.moveLeft(this.column.key);\n };\n\n /**\n * Move the column one spot to the right\n */\n moveRight = () => {\n this.#tableMeta.columnOrder.moveRight(this.column.key);\n };\n}\n\nexport class TableMeta {\n constructor(private table: Table) {}\n\n /**\n * @private\n *\n * We want to maintain the instance of this ColumnOrder class because\n * we allow the consumer of the table to swap out columns at any time.\n * When they do this, we want to maintain the order of the table, best we can.\n * This is also why the order of the columns is maintained via column key\n */\n @tracked\n columnOrder = new ColumnOrder({\n columns: () => this.availableColumns,\n save: this.save,\n existingOrder: this.read(),\n });\n\n /**\n * Get the curret order/position of a column\n */\n @action\n getPosition<DataType = unknown>(column: Column<DataType>) {\n return this.columnOrder.get(column.key);\n }\n\n /**\n * Swap the column with the column at `newPosition`\n */\n @action\n setPosition<DataType = unknown>(\n column: Column<DataType>,\n newPosition: number,\n ) {\n return this.columnOrder.swapWith(column.key, newPosition);\n }\n\n /**\n * Using a `ColumnOrder` instance, set the order of all columns\n */\n setOrder = (order: ColumnOrder) => {\n this.columnOrder.setAll(order.map);\n };\n\n /**\n * Revert to default config, delete preferences,\n * and clear the columnOrder\n */\n @action\n reset() {\n preferences.forTable(this.table, ColumnReordering).delete('order');\n this.columnOrder = new ColumnOrder({\n columns: () => this.availableColumns,\n save: this.save,\n });\n }\n\n /**\n * @private\n */\n @action\n save(map: Map<string, number>) {\n const order: Record<string, number> = {};\n\n for (const [key, position] of map.entries()) {\n order[key] = position;\n }\n\n preferences.forTable(this.table, ColumnReordering).set('order', order);\n }\n\n /**\n * @private\n */\n @action\n private read() {\n const order = preferences\n .forTable(this.table, ColumnReordering)\n .get('order');\n\n if (!order) return;\n\n return new Map<string, number>(Object.entries(order));\n }\n\n get columns() {\n return this.columnOrder.orderedColumns;\n }\n\n /**\n * @private\n * This isn't our data to expose, but it is useful to alias\n */\n private get availableColumns() {\n return columns.for(this.table, ColumnReordering);\n }\n}\n\n/**\n * @private\n * Used for keeping track of and updating column order\n */\nexport class ColumnOrder {\n /**\n * This map will be empty until we re-order something.\n */\n map = new TrackedMap<string, number>();\n\n constructor(\n private args: {\n columns: () => Column[];\n save?: (order: Map<string, number>) => void;\n existingOrder?: Map<string, number>;\n },\n ) {\n if (args.existingOrder) {\n this.map = new TrackedMap(args.existingOrder);\n }\n }\n\n /**\n * To account for columnVisibilty, we need to:\n * - get the list of visible columns\n * - get the column order (which preserves the order of hidden columns)\n * - skip over non-visible columns when determining the previous \"index\"\n * - set the position to whatever that is.\n */\n @action\n moveLeft(key: string) {\n const orderedColumns = this.orderedColumns;\n\n let found = false;\n let nextColumn: { key: string } | undefined;\n\n for (const column of orderedColumns.reverse()) {\n if (found) {\n nextColumn = column;\n\n break;\n }\n\n if (column.key === key) {\n found = true;\n }\n }\n\n if (!nextColumn) return;\n\n const nextPosition = this.get(nextColumn.key);\n\n this.swapWith(key, nextPosition);\n }\n\n setAll = (map: Map<string, number>) => {\n this.map.clear();\n\n for (const [key, value] of map.entries()) {\n this.map.set(key, value);\n }\n\n this.args.save?.(map);\n };\n\n /**\n * To account for columnVisibilty, we need to:\n * - get the list of visible columns\n * - get the column order (which preserves the order of hidden columns)\n * - skip over non-visible columns when determining the next \"index\"\n * - set the position to whatever that is.\n */\n @action\n moveRight(key: string) {\n const orderedColumns = this.orderedColumns;\n\n let found = false;\n let nextColumn: { key: string } | undefined;\n\n for (const column of orderedColumns) {\n if (found) {\n nextColumn = column;\n\n break;\n }\n\n if (column.key === key) {\n found = true;\n }\n }\n\n if (!nextColumn) return;\n\n const nextPosition = this.get(nextColumn.key);\n\n this.swapWith(key, nextPosition);\n }\n\n /**\n * Performs a swap of the column's position with the column at position\n */\n @action\n swapWith(key: string, position: number) {\n const validPositions = [...this.orderedMap.values()];\n\n /**\n * Position to swap to must exist\n */\n if (!validPositions.includes(position)) {\n return;\n }\n\n /**\n * Where did this column `key` come from? we can find out\n * by reading orderedMap\n */\n const currentPosition = this.orderedMap.get(key);\n\n assert(\n `Pre-existing position for ${key} could not be found. Does the column exist? ` +\n `The current positions are: ` +\n [...this.orderedMap.entries()]\n .map((entry) => entry.join(' => '))\n .join(', ') +\n ` and the availableColumns are: ` +\n this.args\n .columns()\n .map((column) => column.key)\n .join(', ') +\n ` and current \"map\" (${this.map.size}) is: ` +\n [...this.map.entries()].map((entry) => entry.join(' => ')).join(', '),\n undefined !== currentPosition,\n );\n\n /**\n * No need to change anything if the position is the same\n * This helps reduce @tracked invalidations, which in turn reduces DOM thrashing.\n */\n if (currentPosition === position) {\n return false;\n }\n\n const keyByPosition = new Map<number, string>(\n [...this.orderedMap.entries()].map(\n (entry) => entry.reverse() as [number, string],\n ),\n );\n\n for (const [existingPosition, key] of keyByPosition.entries()) {\n if (existingPosition === position) {\n /**\n * We swap positions because the positions are not incremental\n * meaning we can have gaps, intentionally, due to hidden columns\n */\n this.map.set(key, currentPosition);\n\n break;\n }\n }\n\n /**\n * Finally, set the position for the requested column\n */\n this.map.set(key, position);\n\n /**\n * Now that we've set the value for one column,\n * we need to make sure that all columns have a recorded position.\n */\n for (const [key, position] of this.orderedMap.entries()) {\n if (this.map.has(key)) continue;\n\n this.map.set(key, position);\n }\n\n this.args.save?.(this.map);\n }\n\n @action\n get(key: string) {\n const result = this.orderedMap.get(key);\n\n assert(\n `No position found for ${key}. Is the column used within this table?`,\n /* 0 is falsey, but it's a valid value for position */\n undefined !== result,\n );\n\n return result;\n }\n\n /**\n * The same as this.map, but with all the columns' information\n */\n @cached\n get orderedMap(): ReadonlyMap<string, number> {\n return orderOf(this.args.columns(), this.map);\n }\n\n @cached\n get orderedColumns(): Column[] {\n const availableColumns = this.args.columns();\n const availableByKey = availableColumns.reduce(\n (keyMap, column) => {\n keyMap[column.key] = column;\n\n return keyMap;\n },\n {} as Record<string, Column>,\n );\n const mergedOrder = orderOf(availableColumns, this.map);\n\n const result: Column[] = Array.from({ length: availableColumns.length });\n\n for (const [key, position] of mergedOrder.entries()) {\n const column = availableByKey[key];\n\n assert(`Could not find column for pair: ${key} @ @{position}`, column);\n result[position] = column;\n }\n\n assert(\n `Generated orderedColumns' length (${result.filter(Boolean).length}) ` +\n `does not match the length of available columns (${availableColumns.length}). ` +\n `orderedColumns: ${result\n .filter(Boolean)\n .map((c) => c.key)\n .join(', ')} -- ` +\n `available columns: ${availableColumns.map((c) => c.key).join(', ')}`,\n result.filter(Boolean).length === availableColumns.length,\n );\n\n return result.filter(Boolean);\n }\n}\n\n/**\n * @private\n *\n * Utility for helping determine the percieved order of a set of columns\n * given the original (default) ordering, and then user-configurations\n */\nexport function orderOf(\n columns: { key: string }[],\n currentOrder: Map<string, number>,\n): Map<string, number> {\n const result = new Map<string, number>();\n const availableColumns = columns.map((column) => column.key);\n const availableSet = new Set(availableColumns);\n const current = new Map<number, string>(\n [...currentOrder.entries()].map(([key, position]) => [position, key]),\n );\n\n /**\n * O(n * log(n)) ?\n */\n for (let i = 0; i < Math.max(columns.length, current.size); i++) {\n const orderedKey = current.get(i);\n\n if (orderedKey) {\n /**\n * If the currentOrder specifies columns not presently available,\n * ignore them\n */\n if (availableSet.has(orderedKey)) {\n result.set(orderedKey, i);\n continue;\n }\n }\n\n let availableKey: string | undefined;\n\n while ((availableKey = availableColumns.shift())) {\n if (result.has(availableKey) || currentOrder.has(availableKey)) {\n continue;\n }\n\n break;\n }\n\n if (!availableKey) {\n /**\n * The rest of our columns likely have their order set\n */\n continue;\n }\n\n result.set(availableKey, i);\n }\n\n return result;\n}\n"],"names":["ColumnReordering","BasePlugin","constructor","args","_defineProperty","column","ColumnMeta","table","TableMeta","reset","tableMeta","meta","forTable","columns","_ColumnMeta_brand","WeakSet","_classPrivateMethodInitSpec","_classPrivateGetter","_get_tableMeta","columnOrder","moveLeft","key","moveRight","position","getPosition","value","setPosition","canMoveLeft","canMoveRight","length","cannotMoveLeft","cannotMoveRight","_this","_class","_initializerDefineProperty","_descriptor","order","setAll","map","get","newPosition","swapWith","preferences","delete","ColumnOrder","availableColumns","save","entries","set","read","Map","Object","orderedColumns","for","_applyDecoratedDescriptor","prototype","tracked","configurable","enumerable","writable","initializer","existingOrder","action","getOwnPropertyDescriptor","_class2","TrackedMap","clear","found","nextColumn","reverse","nextPosition","validPositions","orderedMap","values","includes","currentPosition","assert","entry","join","size","undefined","keyByPosition","existingPosition","has","result","orderOf","availableByKey","reduce","keyMap","mergedOrder","Array","from","filter","Boolean","c","cached","currentOrder","availableSet","Set","current","i","Math","max","orderedKey","availableKey","shift"],"mappings":";;;;;;;;AAiCO,MAAMA,gBAAgB,SAASC,UAAU,CAAY;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CAAA;AAAAC,IAAAA,eAAA,eACnD,mBAAmB,CAAA;AAAAA,IAAAA,eAAA,CAGnB,IAAA,EAAA,MAAA,EAAA;AACLC,MAAAA,MAAM,EAAEC,UAAU;AAClBC,MAAAA,KAAK,EAAEC;KACR,CAAA;AAAA;AAEDC,EAAAA,KAAKA,GAAG;IACN,MAAMC,SAAS,GAAGC,IAAI,CAACC,QAAQ,CAAC,IAAI,CAACL,KAAK,EAAEP,gBAAgB,CAAC;IAE7DU,SAAS,CAACD,KAAK,EAAE;AACnB;EAEA,IAAII,OAAOA,GAAG;IACZ,OAAOF,IAAI,CAACC,QAAQ,CAAC,IAAI,CAACL,KAAK,EAAEP,gBAAgB,CAAC,CAACa,OAAO;AAC5D;AACF;AAACT,eAAA,CAlBYJ,gBAAgB,EAET,UAAA,EAAA,CAAC,aAAa,CAAC,CAAA;AAAA,IAAAc,iBAAA,oBAAAC,OAAA,EAAA;AAkB5B,MAAMT,UAAU,CAAC;EACtBJ,WAAWA,CAASG,MAAc,EAAE;AAAAW,IAAAA,2BAAA,OAAAF,iBAAA,CAAA;AAiCpC;AACF;AACA;AAFEV,IAAAA,eAAA,mBAGW,MAAM;AACfa,MAAAA,mBAAA,CAAAH,iBAAA,EAAA,IAAI,EAACI,cAAS,CAAC,CAACC,WAAW,CAACC,QAAQ,CAAC,IAAI,CAACf,MAAM,CAACgB,GAAG,CAAC;KACtD,CAAA;AAED;AACF;AACA;AAFEjB,IAAAA,eAAA,oBAGY,MAAM;AAChBa,MAAA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A;AACM,MAAA,IAAIN,YAAY,CAACd,GAAG,CAACoB,UAAU,CAAC,EAAE;AAChCnB,QAAAA,MAAM,CAACpC,GAAG,CAACuD,UAAU,EAAEH,CAAC,CAAC;AACzB,QAAA;AACF;AACF;AAEA,IAAA,IAAII,YAAgC;AAEpC,IAAA,OAAQA,YAAY,GAAG3D,gBAAgB,CAAC4D,KAAK,EAAE,EAAG;AAChD,MAAA,IAAIrB,MAAM,CAACD,GAAG,CAACqB,YAAY,CAAC,IAAIR,YAAY,CAACb,GAAG,CAACqB,YAAY,CAAC,EAAE;AAC9D,QAAA;AACF;AAEA,MAAA;AACF;IAEA,IAAI,CAACA,YAAY,EAAE;AACjB;AACN;AACA;AACM,MAAA;AACF;AAEApB,IAAAA,MAAM,CAACpC,GAAG,CAACwD,YAAY,EAAEJ,CAAC,CAAC;AAC7B;AAEA,EAAA,OAAOhB,MAAM;AACf;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../src/plugins/column-reordering/plugin.ts"],"sourcesContent":["import { cached, tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { action } from '@ember/object';\n\nimport { TrackedMap } from 'tracked-built-ins';\n\nimport { preferences } from '../../plugins/index.ts';\n\nimport { BasePlugin, columns, meta } from '../-private/base.ts';\n\nimport type { PluginPreferences } from '../../plugins/index.ts';\nimport type { Column, Table } from '../../index.ts';\n\ninterface ColumnReorderingPreferences extends PluginPreferences {\n table: {\n order?: Record<string, number>;\n };\n}\n\ndeclare module '@universal-ember/table/plugins' {\n interface Registry {\n ColumnReordering?: ColumnReorderingPreferences;\n 'column-reordering'?: ColumnReorderingPreferences;\n }\n}\n\nexport interface Signature {\n Meta: {\n Column: ColumnMeta;\n Table: TableMeta;\n };\n}\n\nexport class ColumnReordering extends BasePlugin<Signature> {\n name = 'column-reordering';\n static features = ['columnOrder'];\n\n meta = {\n column: ColumnMeta,\n table: TableMeta,\n } as const;\n\n reset() {\n const tableMeta = meta.forTable(this.table, ColumnReordering);\n\n tableMeta.reset();\n }\n\n get columns() {\n return meta.forTable(this.table, ColumnReordering).columns;\n }\n}\n\nexport class ColumnMeta {\n constructor(private column: Column) {}\n\n get #tableMeta() {\n return meta.forTable(this.column.table, ColumnReordering);\n }\n\n get position() {\n return this.#tableMeta.getPosition(this.column);\n }\n\n // Swaps this column with the column in the new position\n set position(value: number) {\n this.#tableMeta.setPosition(this.column, value);\n }\n\n get canMoveLeft() {\n return this.#tableMeta.getPosition(this.column) !== 0;\n }\n\n get canMoveRight() {\n return (\n this.#tableMeta.getPosition(this.column) !==\n this.#tableMeta.columns.length - 1\n );\n }\n\n get cannotMoveLeft() {\n return !this.canMoveLeft;\n }\n\n get cannotMoveRight() {\n return !this.canMoveRight;\n }\n\n /**\n * Move the column one spot to the left\n */\n moveLeft = () => {\n this.#tableMeta.columnOrder.moveLeft(this.column.key);\n };\n\n /**\n * Move the column one spot to the right\n */\n moveRight = () => {\n this.#tableMeta.columnOrder.moveRight(this.column.key);\n };\n}\n\nexport class TableMeta {\n constructor(private table: Table) {}\n\n /**\n * @private\n *\n * We want to maintain the instance of this ColumnOrder class because\n * we allow the consumer of the table to swap out columns at any time.\n * When they do this, we want to maintain the order of the table, best we can.\n * This is also why the order of the columns is maintained via column key\n */\n @tracked\n columnOrder = new ColumnOrder({\n columns: () => this.allColumns,\n visibleColumns: () => this.visibleColumns,\n save: this.save,\n existingOrder: this.read(),\n });\n\n /**\n * Get the curret order/position of a column\n */\n @action\n getPosition<DataType = unknown>(column: Column<DataType>) {\n return this.columnOrder.get(column.key);\n }\n\n /**\n * Swap the column with the column at `newPosition`\n */\n @action\n setPosition<DataType = unknown>(\n column: Column<DataType>,\n newPosition: number,\n ) {\n return this.columnOrder.swapWith(column.key, newPosition);\n }\n\n /**\n * Using a `ColumnOrder` instance, set the order of all columns\n */\n setOrder = (order: ColumnOrder) => {\n this.columnOrder.setAll(order.map);\n };\n\n /**\n * Revert to default config, delete preferences,\n * and clear the columnOrder\n */\n @action\n reset() {\n preferences.forTable(this.table, ColumnReordering).delete('order');\n this.columnOrder = new ColumnOrder({\n columns: () => this.allColumns,\n visibleColumns: () => this.visibleColumns,\n save: this.save,\n });\n }\n\n /**\n * @private\n */\n @action\n save(map: Map<string, number>) {\n const order: Record<string, number> = {};\n\n for (const [key, position] of map.entries()) {\n order[key] = position;\n }\n\n preferences.forTable(this.table, ColumnReordering).set('order', order);\n }\n\n /**\n * @private\n */\n @action\n private read() {\n const order = preferences\n .forTable(this.table, ColumnReordering)\n .get('order');\n\n if (!order) return;\n\n return new Map<string, number>(Object.entries(order));\n }\n\n get columns() {\n return this.columnOrder.orderedColumns.filter(\n (column) => this.visibleColumns[column.key],\n );\n }\n\n /**\n * @private\n * This isn't our data to expose, but it is useful to alias\n */\n private get visibleColumns() {\n return columns\n .for(this.table, ColumnReordering)\n .reduce<Record<string, boolean>>((acc, column) => {\n acc[column.key] = true;\n\n return acc;\n }, {});\n }\n\n private get allColumns() {\n return this.table.columns.values();\n }\n}\n\n/**\n * @private\n * Used for keeping track of and updating column order\n */\nexport class ColumnOrder {\n /**\n * This map will be empty until we re-order something.\n */\n map = new TrackedMap<string, number>();\n\n constructor(\n private args: {\n /**\n * All columns to track in the ordering.\n *\n * Backwards compatible usage (without ColumnVisibility):\n * - Pass only the columns you want to display\n * - All columns are treated as visible\n *\n * New usage (with ColumnVisibility):\n * - Pass ALL columns (including hidden ones)\n * - Provide `visibleColumns` to indicate which are visible\n * - Hidden columns maintain their position when toggled\n */\n columns: () => Column[];\n /**\n * Optional: Record of which columns are currently visible.\n * When provided, moveLeft/moveRight will skip over hidden columns.\n * When omitted, all columns from `columns` are treated as visible (backwards compatible).\n *\n * Example when using ColumnVisibility:\n * ```ts\n * visibleColumns: () => columns.reduce((acc, col) => {\n * acc[col.key] = meta(col).ColumnVisibility?.isVisible !== false;\n * return acc;\n * }, {})\n * ```\n */\n visibleColumns?: () => Record<string, boolean>;\n /**\n * Optional: Callback to persist the column order (e.g., to localStorage).\n */\n save?: (order: Map<string, number>) => void;\n /**\n * Optional: Previously saved column order to restore.\n */\n existingOrder?: Map<string, number>;\n },\n ) {\n let allColumns = this.args.columns();\n\n if (args.existingOrder) {\n let newOrder = new Map(args.existingOrder.entries());\n\n addMissingColumnsToMap(allColumns, newOrder);\n removeExtraColumnsFromMap(allColumns, newOrder);\n this.map = new TrackedMap(newOrder);\n } else {\n this.map = new TrackedMap(allColumns.map((column, i) => [column.key, i]));\n }\n }\n\n /**\n * @private\n * Helper to get visible columns, defaulting to all columns if not specified\n */\n private getVisibleColumns(): Record<string, boolean> {\n if (this.args.visibleColumns) {\n return this.args.visibleColumns();\n }\n\n // Default: all columns are visible\n return this.args.columns().reduce(\n (acc, col) => {\n acc[col.key] = true;\n return acc;\n },\n {} as Record<string, boolean>,\n );\n }\n\n /**\n * To account for columnVisibilty, we need to:\n * - get the list of visible columns\n * - get the column order (which preserves the order of hidden columns)\n * - skip over non-visible columns when determining the previous \"index\"\n * - set the position to whatever that is.\n */\n @action\n moveLeft(key: string) {\n const orderedColumns = this.orderedColumns;\n if (this.map.get(key) === 0) {\n return;\n }\n\n let found = false;\n\n for (const column of orderedColumns.reverse()) {\n if (found) {\n // Shift moved column left\n let currentPosition = this.map.get(key);\n\n assert('current key must exist in map', currentPosition !== undefined);\n this.map.set(key, currentPosition - 1);\n\n // Shift displayed column right\n let displayedColumnPosition = this.map.get(column.key);\n\n assert(\n 'displaced key must exist in map',\n displayedColumnPosition !== undefined,\n );\n this.map.set(column.key, displayedColumnPosition + 1);\n\n if (this.getVisibleColumns()[column.key]) {\n break;\n }\n }\n\n if (column.key === key) {\n found = true;\n }\n }\n\n this.args.save?.(this.map);\n }\n\n setAll = (map: Map<string, number>) => {\n let allColumns = this.args.columns();\n\n addMissingColumnsToMap(allColumns, map);\n removeExtraColumnsFromMap(allColumns, map);\n\n this.map.clear();\n\n for (const [key, value] of map.entries()) {\n this.map.set(key, value);\n }\n\n this.args.save?.(map);\n };\n\n /**\n * To account for columnVisibilty, we need to:\n * - get the list of visible columns\n * - get the column order (which preserves the order of hidden columns)\n * - skip over non-visible columns when determining the next \"index\"\n * - set the position to whatever that is.\n */\n @action\n moveRight(key: string) {\n const orderedColumns = this.orderedColumns;\n let found = false;\n\n for (const column of orderedColumns) {\n if (found) {\n // Shift moved column right\n let currentPosition = this.map.get(key);\n\n assert('current key must exist in map', currentPosition !== undefined);\n this.map.set(key, currentPosition + 1);\n\n // Shift displaced column left\n let displayedColumnPosition = this.map.get(column.key);\n\n assert(\n 'displaced key must exist in map',\n displayedColumnPosition !== undefined,\n );\n this.map.set(column.key, displayedColumnPosition - 1);\n\n if (this.getVisibleColumns()[column.key]) {\n break;\n }\n }\n\n if (column.key === key) {\n found = true;\n }\n }\n\n this.args.save?.(this.map);\n }\n\n /**\n * Performs a swap of the column's position with the column at position\n */\n @action\n swapWith(key: string, position: number) {\n const validPositions = [...this.orderedMap.values()];\n\n /**\n * Position to swap to must exist\n */\n if (!validPositions.includes(position)) {\n return;\n }\n\n /**\n * Where did this column `key` come from? we can find out\n * by reading orderedMap\n */\n const currentPosition = this.orderedMap.get(key);\n\n assert(\n `Pre-existing position for ${key} could not be found. Does the column exist? ` +\n `The current positions are: ` +\n [...this.orderedMap.entries()]\n .map((entry) => entry.join(' => '))\n .join(', ') +\n ` and the visibleColumns are: ` +\n Object.keys(this.getVisibleColumns()).join(', ') +\n ` and current \"map\" (${this.map.size}) is: ` +\n [...this.map.entries()].map((entry) => entry.join(' => ')).join(', '),\n undefined !== currentPosition,\n );\n\n /**\n * No need to change anything if the position is the same\n * This helps reduce @tracked invalidations, which in turn reduces DOM thrashing.\n */\n if (currentPosition === position) {\n return false;\n }\n\n const keyByPosition = new Map<number, string>(\n [...this.orderedMap.entries()].map(\n (entry) => entry.reverse() as [number, string],\n ),\n );\n\n for (const [existingPosition, key] of keyByPosition.entries()) {\n if (existingPosition === position) {\n /**\n * We swap positions because the positions are not incremental\n * meaning we can have gaps, intentionally, due to hidden columns\n */\n this.map.set(key, currentPosition);\n\n break;\n }\n }\n\n /**\n * Finally, set the position for the requested column\n */\n this.map.set(key, position);\n\n /**\n * Now that we've set the value for one column,\n * we need to make sure that all columns have a recorded position.\n */\n for (const [key, position] of this.orderedMap.entries()) {\n if (this.map.has(key)) continue;\n\n this.map.set(key, position);\n }\n\n this.args.save?.(this.map);\n }\n\n @action\n get(key: string) {\n const result = this.orderedMap.get(key);\n\n assert(\n `No position found for ${key}. Is the column used within this table?`,\n /* 0 is falsey, but it's a valid value for position */\n undefined !== result,\n );\n\n return result;\n }\n\n /**\n * The same as this.map, but with all the columns' information\n */\n @cached\n get orderedMap(): ReadonlyMap<string, number> {\n return orderOf(this.args.columns(), this.map);\n }\n\n @cached\n get orderedColumns(): Column[] {\n const allColumns = this.args.columns();\n const columnsByKey = allColumns.reduce(\n (keyMap, column) => {\n keyMap[column.key] = column;\n return keyMap;\n },\n {} as Record<string, Column>,\n );\n const mergedOrder = orderOf(allColumns, this.map);\n\n const result: Column[] = Array.from({ length: allColumns.length });\n\n for (const [key, position] of mergedOrder.entries()) {\n const column = columnsByKey[key];\n\n assert(`Could not find column for pair: ${key} @ @{position}`, column);\n result[position] = column;\n }\n\n assert(\n `Generated orderedColumns' length (${result.filter(Boolean).length}) ` +\n `does not match the length of all columns (${allColumns.length}). ` +\n `orderedColumns: ${result\n .filter(Boolean)\n .map((c) => c.key)\n .join(', ')} -- ` +\n `all columns: ${allColumns.map((c) => c.key).join(', ')}`,\n result.filter(Boolean).length === allColumns.length,\n );\n\n return result.filter(Boolean);\n }\n}\n\n/**\n * @private\n *\n * Utility for helping determine the percieved order of a set of columns\n * given the original (default) ordering, and then user-configurations.\n *\n * This function adds missing columns but preserves extra columns in the map\n * (they might be hidden, not deleted).\n */\nexport function orderOf(\n columns: { key: string }[],\n currentOrder: Map<string, number>,\n): Map<string, number> {\n // Create a copy to avoid mutating the input\n let workingOrder = new Map(currentOrder);\n\n // Add any missing columns to the end\n addMissingColumnsToMap(columns, workingOrder);\n\n // DON'T remove extra columns - they might be hidden columns, not deleted ones\n // The ColumnOrder constructor handles removal of truly deleted columns\n\n // Ensure positions are consecutive and zero based\n let inOrder = Array.from(workingOrder.entries()).sort(\n ([_keyA, positionA], [_keyB, positionB]) => positionA - positionB,\n );\n\n let orderedColumns = new Map<string, number>();\n\n let position = 0;\n\n for (let [key] of inOrder) {\n orderedColumns.set(key, position++);\n }\n\n return orderedColumns;\n}\n\n/**\n * @private\n *\n * Utility to add any missing columns to the position map. By calling this whenever\n * data is passed in to the system we can simplify the code within the system because\n * we know we are dealing with a full set of positions.\n *\n * @param columns - A list of all columns available to the table\n * @param map - A Map of `key` to position (as a zero based integer)\n */\nfunction addMissingColumnsToMap(\n columns: { key: string }[],\n map: Map<string, number>,\n): void {\n if (map.size < columns.length) {\n let maxAssignedColumn = Math.max(...map.values());\n\n for (let column of columns) {\n if (map.get(column.key) === undefined) {\n map.set(column.key, ++maxAssignedColumn);\n }\n }\n }\n}\n\n/**\n * @private\n *\n * Utility to remove any extra columns from the position map. By calling this whenever\n * data is passed in to the system we can simplify the code within the system because\n * we know we are dealing with a full set of positions.\n *\n * @param columns - A list of all columns available to the table\n * @param map - A Map of `key` to position (as a zero based integer)\n */\nfunction removeExtraColumnsFromMap(\n columns: { key: string }[],\n map: Map<string, number>,\n): void {\n let columnsLookup = columns.reduce(\n function (acc, { key }) {\n acc[key] = true;\n\n return acc;\n },\n {} as Record<string, boolean>,\n );\n\n for (let key of map.keys()) {\n if (!columnsLookup[key]) {\n map.delete(key);\n }\n }\n}\n"],"names":["ColumnReordering","BasePlugin","constructor","args","_defineProperty","column","ColumnMeta","table","TableMeta","reset","tableMeta","meta","forTable","columns","_ColumnMeta_brand","WeakSet","_classPrivateMethodInitSpec","_classPrivateGetter","_get_tableMeta","columnOrder","moveLeft","key","moveRight","position","getPosition","value","setPosition","canMoveLeft","canMoveRight","length","cannotMoveLeft","cannotMoveRight","_this","_class","_initializerDefineProperty","_descriptor","order","setAll","map","get","newPosition","swapWith","preferences","delete","ColumnOrder","allColumns","visibleColumns","save","entries","set","read","Map","Object","orderedColumns","filter","for","reduce","acc","values","_applyDecoratedDescriptor","prototype","tracked","configurable","enumerable","writable","initializer","existingOrder","action","getOwnPropertyDescriptor","_class2","TrackedMap","addMissingColumnsToMap","removeExtraColumnsFromMap","clear","newOrder","i","getVisibleColumns","col","found","reverse","currentPosition","assert","undefined","displayedColumnPosition","validPositions","orderedMap","includes","entry","join","keys","size","keyByPosition","existingPosition","has","result","orderOf","columnsByKey","keyMap","mergedOrder","Array","from","Boolean","c","cached","currentOrder","workingOrder","inOrder","sort","_keyA","positionA","_keyB","positionB","maxAssignedColumn","Math","max","columnsLookup"],"mappings":";;;;;;;;AAiCO,MAAMA,gBAAgB,SAASC,UAAU,CAAY;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CAAA;AAAAC,IAAAA,eAAA,eACnD,mBAAmB,CAAA;AAAAA,IAAAA,eAAA,CAGnB,IAAA,EAAA,MAAA,EAAA;AACLC,MAAAA,MAAM,EAAEC,UAAU;AAClBC,MAAAA,KAAK,EAAEC;KACR,CAAA;AAAA;AAEDC,EAAAA,KAAKA,GAAG;IACN,MAAMC,SAAS,GAAGC,IAAI,CAACC,QAAQ,CAAC,IAAI,CAACL,KAAK,EAAEP,gBAAgB,CAAC;IAE7DU,SAAS,CAACD,KAAK,EAAE;AACnB;EAEA,IAAII,OAAOA,GAAG;IACZ,OAAOF,IAAI,CAACC,QAAQ,CAAC,IAAI,CAACL,KAAK,EAAEP,gBAAgB,CAAC,CAACa,OAAO;AAC5D;AACF;AAACT,eAAA,CAlBYJ,gBAAgB,EAET,UAAA,EAAA,CAAC,aAAa,CAAC,CAAA;AAAA,IAAAc,iBAAA,oBAAAC,OAAA,EAAA;AAkB5B,MAAMT,UAAU,CAAC;EACtBJ,WAAWA,CAASG,MAAc,EAAE;AAAAW,IAAAA,2BAAA,OAAAF,iBAAA,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;"}
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ export interface ColumnConfig<T = unknown> {
|
|
|
44
44
|
* Out-of-the-box, this property isn't used, but the provided type may be
|
|
45
45
|
* a convenience for consumers of the headless table
|
|
46
46
|
*/
|
|
47
|
-
Cell?: ComponentLike
|
|
47
|
+
Cell?: ComponentLike<CellContext<T>>;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* The name or title of the column, shown in the column heading / th
|
|
@@ -62,6 +62,7 @@ export class ColumnMeta {
|
|
|
62
62
|
return this.#tableMeta.getPosition(this.column);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Swaps this column with the column in the new position
|
|
65
66
|
set position(value: number) {
|
|
66
67
|
this.#tableMeta.setPosition(this.column, value);
|
|
67
68
|
}
|
|
@@ -113,7 +114,8 @@ export class TableMeta {
|
|
|
113
114
|
*/
|
|
114
115
|
@tracked
|
|
115
116
|
columnOrder = new ColumnOrder({
|
|
116
|
-
columns: () => this.
|
|
117
|
+
columns: () => this.allColumns,
|
|
118
|
+
visibleColumns: () => this.visibleColumns,
|
|
117
119
|
save: this.save,
|
|
118
120
|
existingOrder: this.read(),
|
|
119
121
|
});
|
|
@@ -152,7 +154,8 @@ export class TableMeta {
|
|
|
152
154
|
reset() {
|
|
153
155
|
preferences.forTable(this.table, ColumnReordering).delete('order');
|
|
154
156
|
this.columnOrder = new ColumnOrder({
|
|
155
|
-
columns: () => this.
|
|
157
|
+
columns: () => this.allColumns,
|
|
158
|
+
visibleColumns: () => this.visibleColumns,
|
|
156
159
|
save: this.save,
|
|
157
160
|
});
|
|
158
161
|
}
|
|
@@ -186,15 +189,27 @@ export class TableMeta {
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
get columns() {
|
|
189
|
-
return this.columnOrder.orderedColumns
|
|
192
|
+
return this.columnOrder.orderedColumns.filter(
|
|
193
|
+
(column) => this.visibleColumns[column.key],
|
|
194
|
+
);
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
/**
|
|
193
198
|
* @private
|
|
194
199
|
* This isn't our data to expose, but it is useful to alias
|
|
195
200
|
*/
|
|
196
|
-
private get
|
|
197
|
-
return columns
|
|
201
|
+
private get visibleColumns() {
|
|
202
|
+
return columns
|
|
203
|
+
.for(this.table, ColumnReordering)
|
|
204
|
+
.reduce<Record<string, boolean>>((acc, column) => {
|
|
205
|
+
acc[column.key] = true;
|
|
206
|
+
|
|
207
|
+
return acc;
|
|
208
|
+
}, {});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private get allColumns() {
|
|
212
|
+
return this.table.columns.values();
|
|
198
213
|
}
|
|
199
214
|
}
|
|
200
215
|
|
|
@@ -210,14 +225,73 @@ export class ColumnOrder {
|
|
|
210
225
|
|
|
211
226
|
constructor(
|
|
212
227
|
private args: {
|
|
228
|
+
/**
|
|
229
|
+
* All columns to track in the ordering.
|
|
230
|
+
*
|
|
231
|
+
* Backwards compatible usage (without ColumnVisibility):
|
|
232
|
+
* - Pass only the columns you want to display
|
|
233
|
+
* - All columns are treated as visible
|
|
234
|
+
*
|
|
235
|
+
* New usage (with ColumnVisibility):
|
|
236
|
+
* - Pass ALL columns (including hidden ones)
|
|
237
|
+
* - Provide `visibleColumns` to indicate which are visible
|
|
238
|
+
* - Hidden columns maintain their position when toggled
|
|
239
|
+
*/
|
|
213
240
|
columns: () => Column[];
|
|
241
|
+
/**
|
|
242
|
+
* Optional: Record of which columns are currently visible.
|
|
243
|
+
* When provided, moveLeft/moveRight will skip over hidden columns.
|
|
244
|
+
* When omitted, all columns from `columns` are treated as visible (backwards compatible).
|
|
245
|
+
*
|
|
246
|
+
* Example when using ColumnVisibility:
|
|
247
|
+
* ```ts
|
|
248
|
+
* visibleColumns: () => columns.reduce((acc, col) => {
|
|
249
|
+
* acc[col.key] = meta(col).ColumnVisibility?.isVisible !== false;
|
|
250
|
+
* return acc;
|
|
251
|
+
* }, {})
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
visibleColumns?: () => Record<string, boolean>;
|
|
255
|
+
/**
|
|
256
|
+
* Optional: Callback to persist the column order (e.g., to localStorage).
|
|
257
|
+
*/
|
|
214
258
|
save?: (order: Map<string, number>) => void;
|
|
259
|
+
/**
|
|
260
|
+
* Optional: Previously saved column order to restore.
|
|
261
|
+
*/
|
|
215
262
|
existingOrder?: Map<string, number>;
|
|
216
263
|
},
|
|
217
264
|
) {
|
|
265
|
+
let allColumns = this.args.columns();
|
|
266
|
+
|
|
218
267
|
if (args.existingOrder) {
|
|
219
|
-
|
|
268
|
+
let newOrder = new Map(args.existingOrder.entries());
|
|
269
|
+
|
|
270
|
+
addMissingColumnsToMap(allColumns, newOrder);
|
|
271
|
+
removeExtraColumnsFromMap(allColumns, newOrder);
|
|
272
|
+
this.map = new TrackedMap(newOrder);
|
|
273
|
+
} else {
|
|
274
|
+
this.map = new TrackedMap(allColumns.map((column, i) => [column.key, i]));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @private
|
|
280
|
+
* Helper to get visible columns, defaulting to all columns if not specified
|
|
281
|
+
*/
|
|
282
|
+
private getVisibleColumns(): Record<string, boolean> {
|
|
283
|
+
if (this.args.visibleColumns) {
|
|
284
|
+
return this.args.visibleColumns();
|
|
220
285
|
}
|
|
286
|
+
|
|
287
|
+
// Default: all columns are visible
|
|
288
|
+
return this.args.columns().reduce(
|
|
289
|
+
(acc, col) => {
|
|
290
|
+
acc[col.key] = true;
|
|
291
|
+
return acc;
|
|
292
|
+
},
|
|
293
|
+
{} as Record<string, boolean>,
|
|
294
|
+
);
|
|
221
295
|
}
|
|
222
296
|
|
|
223
297
|
/**
|
|
@@ -230,15 +304,32 @@ export class ColumnOrder {
|
|
|
230
304
|
@action
|
|
231
305
|
moveLeft(key: string) {
|
|
232
306
|
const orderedColumns = this.orderedColumns;
|
|
307
|
+
if (this.map.get(key) === 0) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
233
310
|
|
|
234
311
|
let found = false;
|
|
235
|
-
let nextColumn: { key: string } | undefined;
|
|
236
312
|
|
|
237
313
|
for (const column of orderedColumns.reverse()) {
|
|
238
314
|
if (found) {
|
|
239
|
-
|
|
315
|
+
// Shift moved column left
|
|
316
|
+
let currentPosition = this.map.get(key);
|
|
240
317
|
|
|
241
|
-
|
|
318
|
+
assert('current key must exist in map', currentPosition !== undefined);
|
|
319
|
+
this.map.set(key, currentPosition - 1);
|
|
320
|
+
|
|
321
|
+
// Shift displayed column right
|
|
322
|
+
let displayedColumnPosition = this.map.get(column.key);
|
|
323
|
+
|
|
324
|
+
assert(
|
|
325
|
+
'displaced key must exist in map',
|
|
326
|
+
displayedColumnPosition !== undefined,
|
|
327
|
+
);
|
|
328
|
+
this.map.set(column.key, displayedColumnPosition + 1);
|
|
329
|
+
|
|
330
|
+
if (this.getVisibleColumns()[column.key]) {
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
242
333
|
}
|
|
243
334
|
|
|
244
335
|
if (column.key === key) {
|
|
@@ -246,14 +337,15 @@ export class ColumnOrder {
|
|
|
246
337
|
}
|
|
247
338
|
}
|
|
248
339
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const nextPosition = this.get(nextColumn.key);
|
|
252
|
-
|
|
253
|
-
this.swapWith(key, nextPosition);
|
|
340
|
+
this.args.save?.(this.map);
|
|
254
341
|
}
|
|
255
342
|
|
|
256
343
|
setAll = (map: Map<string, number>) => {
|
|
344
|
+
let allColumns = this.args.columns();
|
|
345
|
+
|
|
346
|
+
addMissingColumnsToMap(allColumns, map);
|
|
347
|
+
removeExtraColumnsFromMap(allColumns, map);
|
|
348
|
+
|
|
257
349
|
this.map.clear();
|
|
258
350
|
|
|
259
351
|
for (const [key, value] of map.entries()) {
|
|
@@ -273,15 +365,28 @@ export class ColumnOrder {
|
|
|
273
365
|
@action
|
|
274
366
|
moveRight(key: string) {
|
|
275
367
|
const orderedColumns = this.orderedColumns;
|
|
276
|
-
|
|
277
368
|
let found = false;
|
|
278
|
-
let nextColumn: { key: string } | undefined;
|
|
279
369
|
|
|
280
370
|
for (const column of orderedColumns) {
|
|
281
371
|
if (found) {
|
|
282
|
-
|
|
372
|
+
// Shift moved column right
|
|
373
|
+
let currentPosition = this.map.get(key);
|
|
283
374
|
|
|
284
|
-
|
|
375
|
+
assert('current key must exist in map', currentPosition !== undefined);
|
|
376
|
+
this.map.set(key, currentPosition + 1);
|
|
377
|
+
|
|
378
|
+
// Shift displaced column left
|
|
379
|
+
let displayedColumnPosition = this.map.get(column.key);
|
|
380
|
+
|
|
381
|
+
assert(
|
|
382
|
+
'displaced key must exist in map',
|
|
383
|
+
displayedColumnPosition !== undefined,
|
|
384
|
+
);
|
|
385
|
+
this.map.set(column.key, displayedColumnPosition - 1);
|
|
386
|
+
|
|
387
|
+
if (this.getVisibleColumns()[column.key]) {
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
285
390
|
}
|
|
286
391
|
|
|
287
392
|
if (column.key === key) {
|
|
@@ -289,11 +394,7 @@ export class ColumnOrder {
|
|
|
289
394
|
}
|
|
290
395
|
}
|
|
291
396
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const nextPosition = this.get(nextColumn.key);
|
|
295
|
-
|
|
296
|
-
this.swapWith(key, nextPosition);
|
|
397
|
+
this.args.save?.(this.map);
|
|
297
398
|
}
|
|
298
399
|
|
|
299
400
|
/**
|
|
@@ -322,11 +423,8 @@ export class ColumnOrder {
|
|
|
322
423
|
[...this.orderedMap.entries()]
|
|
323
424
|
.map((entry) => entry.join(' => '))
|
|
324
425
|
.join(', ') +
|
|
325
|
-
` and the
|
|
326
|
-
this.
|
|
327
|
-
.columns()
|
|
328
|
-
.map((column) => column.key)
|
|
329
|
-
.join(', ') +
|
|
426
|
+
` and the visibleColumns are: ` +
|
|
427
|
+
Object.keys(this.getVisibleColumns()).join(', ') +
|
|
330
428
|
` and current "map" (${this.map.size}) is: ` +
|
|
331
429
|
[...this.map.entries()].map((entry) => entry.join(' => ')).join(', '),
|
|
332
430
|
undefined !== currentPosition,
|
|
@@ -399,21 +497,20 @@ export class ColumnOrder {
|
|
|
399
497
|
|
|
400
498
|
@cached
|
|
401
499
|
get orderedColumns(): Column[] {
|
|
402
|
-
const
|
|
403
|
-
const
|
|
500
|
+
const allColumns = this.args.columns();
|
|
501
|
+
const columnsByKey = allColumns.reduce(
|
|
404
502
|
(keyMap, column) => {
|
|
405
503
|
keyMap[column.key] = column;
|
|
406
|
-
|
|
407
504
|
return keyMap;
|
|
408
505
|
},
|
|
409
506
|
{} as Record<string, Column>,
|
|
410
507
|
);
|
|
411
|
-
const mergedOrder = orderOf(
|
|
508
|
+
const mergedOrder = orderOf(allColumns, this.map);
|
|
412
509
|
|
|
413
|
-
const result: Column[] = Array.from({ length:
|
|
510
|
+
const result: Column[] = Array.from({ length: allColumns.length });
|
|
414
511
|
|
|
415
512
|
for (const [key, position] of mergedOrder.entries()) {
|
|
416
|
-
const column =
|
|
513
|
+
const column = columnsByKey[key];
|
|
417
514
|
|
|
418
515
|
assert(`Could not find column for pair: ${key} @ @{position}`, column);
|
|
419
516
|
result[position] = column;
|
|
@@ -421,13 +518,13 @@ export class ColumnOrder {
|
|
|
421
518
|
|
|
422
519
|
assert(
|
|
423
520
|
`Generated orderedColumns' length (${result.filter(Boolean).length}) ` +
|
|
424
|
-
`does not match the length of
|
|
521
|
+
`does not match the length of all columns (${allColumns.length}). ` +
|
|
425
522
|
`orderedColumns: ${result
|
|
426
523
|
.filter(Boolean)
|
|
427
524
|
.map((c) => c.key)
|
|
428
525
|
.join(', ')} -- ` +
|
|
429
|
-
`
|
|
430
|
-
result.filter(Boolean).length ===
|
|
526
|
+
`all columns: ${allColumns.map((c) => c.key).join(', ')}`,
|
|
527
|
+
result.filter(Boolean).length === allColumns.length,
|
|
431
528
|
);
|
|
432
529
|
|
|
433
530
|
return result.filter(Boolean);
|
|
@@ -438,55 +535,91 @@ export class ColumnOrder {
|
|
|
438
535
|
* @private
|
|
439
536
|
*
|
|
440
537
|
* Utility for helping determine the percieved order of a set of columns
|
|
441
|
-
* given the original (default) ordering, and then user-configurations
|
|
538
|
+
* given the original (default) ordering, and then user-configurations.
|
|
539
|
+
*
|
|
540
|
+
* This function adds missing columns but preserves extra columns in the map
|
|
541
|
+
* (they might be hidden, not deleted).
|
|
442
542
|
*/
|
|
443
543
|
export function orderOf(
|
|
444
544
|
columns: { key: string }[],
|
|
445
545
|
currentOrder: Map<string, number>,
|
|
446
546
|
): Map<string, number> {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
547
|
+
// Create a copy to avoid mutating the input
|
|
548
|
+
let workingOrder = new Map(currentOrder);
|
|
549
|
+
|
|
550
|
+
// Add any missing columns to the end
|
|
551
|
+
addMissingColumnsToMap(columns, workingOrder);
|
|
552
|
+
|
|
553
|
+
// DON'T remove extra columns - they might be hidden columns, not deleted ones
|
|
554
|
+
// The ColumnOrder constructor handles removal of truly deleted columns
|
|
555
|
+
|
|
556
|
+
// Ensure positions are consecutive and zero based
|
|
557
|
+
let inOrder = Array.from(workingOrder.entries()).sort(
|
|
558
|
+
([_keyA, positionA], [_keyB, positionB]) => positionA - positionB,
|
|
452
559
|
);
|
|
453
560
|
|
|
454
|
-
|
|
455
|
-
* O(n * log(n)) ?
|
|
456
|
-
*/
|
|
457
|
-
for (let i = 0; i < Math.max(columns.length, current.size); i++) {
|
|
458
|
-
const orderedKey = current.get(i);
|
|
561
|
+
let orderedColumns = new Map<string, number>();
|
|
459
562
|
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* If the currentOrder specifies columns not presently available,
|
|
463
|
-
* ignore them
|
|
464
|
-
*/
|
|
465
|
-
if (availableSet.has(orderedKey)) {
|
|
466
|
-
result.set(orderedKey, i);
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
563
|
+
let position = 0;
|
|
470
564
|
|
|
471
|
-
|
|
565
|
+
for (let [key] of inOrder) {
|
|
566
|
+
orderedColumns.set(key, position++);
|
|
567
|
+
}
|
|
472
568
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
569
|
+
return orderedColumns;
|
|
570
|
+
}
|
|
477
571
|
|
|
478
|
-
|
|
572
|
+
/**
|
|
573
|
+
* @private
|
|
574
|
+
*
|
|
575
|
+
* Utility to add any missing columns to the position map. By calling this whenever
|
|
576
|
+
* data is passed in to the system we can simplify the code within the system because
|
|
577
|
+
* we know we are dealing with a full set of positions.
|
|
578
|
+
*
|
|
579
|
+
* @param columns - A list of all columns available to the table
|
|
580
|
+
* @param map - A Map of `key` to position (as a zero based integer)
|
|
581
|
+
*/
|
|
582
|
+
function addMissingColumnsToMap(
|
|
583
|
+
columns: { key: string }[],
|
|
584
|
+
map: Map<string, number>,
|
|
585
|
+
): void {
|
|
586
|
+
if (map.size < columns.length) {
|
|
587
|
+
let maxAssignedColumn = Math.max(...map.values());
|
|
588
|
+
|
|
589
|
+
for (let column of columns) {
|
|
590
|
+
if (map.get(column.key) === undefined) {
|
|
591
|
+
map.set(column.key, ++maxAssignedColumn);
|
|
592
|
+
}
|
|
479
593
|
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
480
596
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
597
|
+
/**
|
|
598
|
+
* @private
|
|
599
|
+
*
|
|
600
|
+
* Utility to remove any extra columns from the position map. By calling this whenever
|
|
601
|
+
* data is passed in to the system we can simplify the code within the system because
|
|
602
|
+
* we know we are dealing with a full set of positions.
|
|
603
|
+
*
|
|
604
|
+
* @param columns - A list of all columns available to the table
|
|
605
|
+
* @param map - A Map of `key` to position (as a zero based integer)
|
|
606
|
+
*/
|
|
607
|
+
function removeExtraColumnsFromMap(
|
|
608
|
+
columns: { key: string }[],
|
|
609
|
+
map: Map<string, number>,
|
|
610
|
+
): void {
|
|
611
|
+
let columnsLookup = columns.reduce(
|
|
612
|
+
function (acc, { key }) {
|
|
613
|
+
acc[key] = true;
|
|
487
614
|
|
|
488
|
-
|
|
489
|
-
|
|
615
|
+
return acc;
|
|
616
|
+
},
|
|
617
|
+
{} as Record<string, boolean>,
|
|
618
|
+
);
|
|
490
619
|
|
|
491
|
-
|
|
620
|
+
for (let key of map.keys()) {
|
|
621
|
+
if (!columnsLookup[key]) {
|
|
622
|
+
map.delete(key);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
492
625
|
}
|