@itrocks/table 0.7.3 → 0.8.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.
- package/README.md +13 -10
- package/column-add.css +7 -5
- package/column-add.d.ts +12 -2
- package/column-add.js +161 -101
- package/freeze.js +28 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -269,21 +269,22 @@ match the current view.
|
|
|
269
269
|
- `reveal(id): void` scrolls the horizontal container only as needed, accounting for frozen bounds.
|
|
270
270
|
- `highlight(id): void` applies the same green/light/theme flash for new and existing columns, cleans up after 350 ms,
|
|
271
271
|
honours reduced motion and preserves keyboard focus and row selection. Existing columns keep their content and width.
|
|
272
|
-
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
fade ends for value cells; the heading and filter become visible after the 100 ms opening. A non-breaking space
|
|
279
|
-
keeps masked cells painted and holds their measured width. Asynchronous values continue
|
|
280
|
-
opening from the current width towards the greater of the heading width and the loaded content width.
|
|
272
|
+
- New columns show their heading, filter and placeholder cells immediately, and start one 350 ms addition flash.
|
|
273
|
+
Values arriving during the flash update the measured target width and remain masked until the flash finishes.
|
|
274
|
+
Values arriving afterwards are displayed immediately without another flash. Data loading never extends the flash.
|
|
275
|
+
Columns inserted between existing columns open over 100 ms; incoming values retarget their width.
|
|
276
|
+
Appended columns appear at full heading width and scroll to the new right edge over 100 ms when values require it.
|
|
277
|
+
Reduced motion disables width animation and makes scrolling immediate.
|
|
281
278
|
- `remove(id, signal?): Promise<boolean>` reveals a column, shrinks it over 100 ms during a 300 ms red flash,
|
|
282
279
|
hiding cell content immediately, then removes the header, body/footer cells and matching `col`. It returns false for
|
|
283
280
|
a missing column or cancellation. Repeated calls share the pending removal; abort, disposal and reset clear the flash
|
|
284
281
|
without deletion. Late values cannot restore a removed column. Cancellation restores the natural width.
|
|
285
282
|
Reduced motion skips width animation and uses a static red outline.
|
|
286
283
|
The host persists the resulting configuration.
|
|
284
|
+
- `highlightMany(ids, opening?): void` starts addition highlights for all supplied columns in the same frame.
|
|
285
|
+
- `removeMany(ids, signal?): Promise<boolean>` prepares every column before starting their red flashes in the same
|
|
286
|
+
frame and removes them after one shared delay. Cancellation clears the whole group's flash without deletion.
|
|
287
|
+
Missing columns return false; overlapping group removals reject. Single-column calls share pending removal.
|
|
287
288
|
- `retry(id): Promise<void>` retries a failed value callback. Failure retains the committed column and marks it with
|
|
288
289
|
`.column-add-error`; data cells receive a discreet red background and the addition flash stops.
|
|
289
290
|
It never confirms another addition. The plugin adds no error text, retry control or automatic retry.
|
|
@@ -297,7 +298,9 @@ match the current view.
|
|
|
297
298
|
|
|
298
299
|
`ColumnCreationOptions` is shared by `add` and `begin`. `hidden: true` inserts hidden cells and a hidden `col`;
|
|
299
300
|
loaded replacements retain that visibility. `effects: false` skips width animation, flash and automatic scroll for both
|
|
300
|
-
creation and loaded values.
|
|
301
|
+
creation and loaded values. `effects: 'deferred'` lets a host create several columns, publish their selection state,
|
|
302
|
+
then call `highlightMany(ids, true)` to start one shared flash before starting their shared request. Loading still starts
|
|
303
|
+
immediately when a source provides it. Pass both options to prepare a column for pointer entry.
|
|
301
304
|
|
|
302
305
|
`TableColumnAddOptions.identify(header)` defaults to `header.dataset.columnId`. Added and loaded headers carry this
|
|
303
306
|
opaque attribute so identity survives plugin resets. A custom callback can identify pre-existing columns differently.
|
package/column-add.css
CHANGED
|
@@ -5,11 +5,7 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td)[hidden] {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-highlight {
|
|
8
|
-
animation: itrocks-column-add-flash var(--column-fade, 350ms) ease-out;
|
|
9
|
-
}
|
|
10
|
-
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-highlight.column-add-loading {
|
|
11
|
-
animation: none;
|
|
12
|
-
background-color: color-mix(in srgb, #58b46b 35%, Canvas);
|
|
8
|
+
animation: itrocks-column-add-flash var(--column-fade, 350ms) ease-out var(--column-delay, 0ms);
|
|
13
9
|
}
|
|
14
10
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-opening::after {
|
|
15
11
|
animation: itrocks-column-open 100ms ease-out both;
|
|
@@ -40,6 +36,12 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highli
|
|
|
40
36
|
line-height: 1px;
|
|
41
37
|
width: var(--column-width);
|
|
42
38
|
}
|
|
39
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-values-hidden {
|
|
40
|
+
color: transparent !important;
|
|
41
|
+
}
|
|
42
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-values-hidden > * {
|
|
43
|
+
visibility: hidden !important;
|
|
44
|
+
}
|
|
43
45
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-loading {
|
|
44
46
|
cursor: progress;
|
|
45
47
|
}
|
package/column-add.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type ColumnContent = {
|
|
|
15
15
|
header: HTMLTableCellElement;
|
|
16
16
|
};
|
|
17
17
|
export type ColumnCreationOptions = {
|
|
18
|
-
effects?: boolean;
|
|
18
|
+
effects?: boolean | 'deferred';
|
|
19
19
|
hidden?: boolean;
|
|
20
20
|
};
|
|
21
21
|
export interface ColumnOperation {
|
|
@@ -40,6 +40,11 @@ export interface ColumnTransaction {
|
|
|
40
40
|
commit(): ColumnResult;
|
|
41
41
|
moveTo(index: number): void;
|
|
42
42
|
}
|
|
43
|
+
interface Highlight {
|
|
44
|
+
cells: Set<HTMLTableCellElement>;
|
|
45
|
+
started: number;
|
|
46
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
47
|
+
}
|
|
43
48
|
interface Pending {
|
|
44
49
|
abort: AbortController;
|
|
45
50
|
col?: HTMLTableColElement;
|
|
@@ -55,7 +60,7 @@ interface Pending {
|
|
|
55
60
|
export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions> {
|
|
56
61
|
protected disposed: boolean;
|
|
57
62
|
protected external?: ColumnOperation;
|
|
58
|
-
protected highlights: Map<HTMLTableCellElement,
|
|
63
|
+
protected highlights: Map<HTMLTableCellElement, Highlight>;
|
|
59
64
|
protected identities: WeakMap<HTMLTableCellElement, string>;
|
|
60
65
|
protected pending: Map<string, Pending>;
|
|
61
66
|
protected removals: Map<string, {
|
|
@@ -72,9 +77,11 @@ export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions>
|
|
|
72
77
|
protected create(source: ColumnSource, options?: ColumnCreationOptions): ColumnTransaction;
|
|
73
78
|
defaultOptions(): TableColumnAddOptions;
|
|
74
79
|
dispose(): void;
|
|
80
|
+
protected clearHighlight(cell: HTMLTableCellElement): void;
|
|
75
81
|
protected find(id: string): HTMLTableCellElement | undefined;
|
|
76
82
|
protected headers(): HTMLTableRowElement;
|
|
77
83
|
highlight(id: string, opening?: boolean): void;
|
|
84
|
+
highlightMany(ids: readonly string[], opening?: boolean): void;
|
|
78
85
|
init(): void;
|
|
79
86
|
protected isLastColumn(header: HTMLTableCellElement): boolean;
|
|
80
87
|
protected live(entry: Pending): boolean;
|
|
@@ -85,7 +92,10 @@ export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions>
|
|
|
85
92
|
protected refresh(): void;
|
|
86
93
|
/** Reveal and briefly mark a column in red before removing it. */
|
|
87
94
|
remove(id: string, signal?: AbortSignal): Promise<boolean>;
|
|
95
|
+
/** Flash all requested columns together, then remove them after one shared delay. */
|
|
96
|
+
removeMany(ids: readonly string[], signal?: AbortSignal): Promise<boolean>;
|
|
88
97
|
protected removeColumn(id: string, signal: AbortSignal): Promise<boolean>;
|
|
98
|
+
protected removeColumns(ids: readonly string[], signal: AbortSignal): Promise<boolean>;
|
|
89
99
|
reveal(id: string): void;
|
|
90
100
|
protected scrollToEnd(): void;
|
|
91
101
|
retry(id: string): Promise<void>;
|
package/column-add.js
CHANGED
|
@@ -194,7 +194,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
194
194
|
this.mark(entry, 'provisional', false);
|
|
195
195
|
if (!existing || (entry.content.header.cellIndex !== entry.initial))
|
|
196
196
|
this.notify(entry, 'committed');
|
|
197
|
-
if (!existing && entry.effects) {
|
|
197
|
+
if (!existing && entry.effects && options.effects !== 'deferred') {
|
|
198
198
|
entry.started = performance.now();
|
|
199
199
|
this.highlight(source.id, true);
|
|
200
200
|
if (entry.settled && this.isLastColumn(entry.content.header))
|
|
@@ -213,7 +213,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
213
213
|
this.refresh();
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
-
const entry = { abort, content, effects: options.effects
|
|
216
|
+
const entry = { abort, content, effects: options.effects !== false, initial: existing?.cellIndex ?? -1,
|
|
217
217
|
rows, settled: false, source, transaction };
|
|
218
218
|
this.pending.set(source.id, entry);
|
|
219
219
|
if (existing)
|
|
@@ -258,14 +258,21 @@ export class TableColumnAdd extends Plugin {
|
|
|
258
258
|
this.mark(entry, 'loading', false);
|
|
259
259
|
}
|
|
260
260
|
this.pending.clear();
|
|
261
|
-
for (const [cell,
|
|
262
|
-
clearTimeout(timer);
|
|
263
|
-
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
|
|
264
|
-
for (const name of ['fade', 'from', 'height', 'width'])
|
|
261
|
+
for (const [cell, highlight] of this.highlights) {
|
|
262
|
+
clearTimeout(highlight.timer);
|
|
263
|
+
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening', 'column-add-values-hidden');
|
|
264
|
+
for (const name of ['delay', 'fade', 'from', 'height', 'width'])
|
|
265
265
|
cell.style?.removeProperty(`--column-${name}`);
|
|
266
266
|
}
|
|
267
267
|
this.highlights.clear();
|
|
268
268
|
}
|
|
269
|
+
clearHighlight(cell) {
|
|
270
|
+
const highlight = this.highlights.get(cell);
|
|
271
|
+
this.highlights.delete(cell);
|
|
272
|
+
highlight?.cells.delete(cell);
|
|
273
|
+
if (highlight && !highlight.cells.size)
|
|
274
|
+
clearTimeout(highlight.timer);
|
|
275
|
+
}
|
|
269
276
|
find(id) {
|
|
270
277
|
return Array.from(this.headers().cells).find(header => (this.identities.get(header) ?? this.options.identify(header)) === id);
|
|
271
278
|
}
|
|
@@ -276,46 +283,63 @@ export class TableColumnAdd extends Plugin {
|
|
|
276
283
|
return row;
|
|
277
284
|
}
|
|
278
285
|
highlight(id, opening = false) {
|
|
279
|
-
|
|
280
|
-
|
|
286
|
+
this.highlightMany([id], opening);
|
|
287
|
+
}
|
|
288
|
+
highlightMany(ids, opening = false) {
|
|
289
|
+
if (this.disposed)
|
|
281
290
|
return;
|
|
282
|
-
const started =
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
for (const
|
|
296
|
-
const cell
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
291
|
+
const started = performance.now();
|
|
292
|
+
const columns = [...new Set(ids)].flatMap(id => {
|
|
293
|
+
const header = this.find(id);
|
|
294
|
+
if (!header)
|
|
295
|
+
return [];
|
|
296
|
+
const entry = this.pending.get(id);
|
|
297
|
+
if (opening && entry)
|
|
298
|
+
entry.started = started;
|
|
299
|
+
return [{ header,
|
|
300
|
+
cells: Array.from(this.of.element.rows).map(row => row.cells[header.cellIndex]).filter(Boolean),
|
|
301
|
+
expanding: opening && !this.isLastColumn(header)
|
|
302
|
+
}];
|
|
303
|
+
});
|
|
304
|
+
for (const column of columns)
|
|
305
|
+
for (const cell of column.cells) {
|
|
306
|
+
this.clearHighlight(cell);
|
|
307
|
+
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening', 'column-add-values-hidden');
|
|
308
|
+
}
|
|
309
|
+
for (const column of columns)
|
|
310
|
+
this.measureColumn(column.header);
|
|
311
|
+
if (columns.length)
|
|
312
|
+
void columns[0].header.offsetWidth;
|
|
313
|
+
const highlight = { cells: new Set(columns.flatMap(column => column.cells)), started: performance.now() };
|
|
314
|
+
if (highlight.cells.size)
|
|
315
|
+
highlight.timer = setTimeout(() => {
|
|
316
|
+
for (const cell of highlight.cells) {
|
|
317
|
+
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening', 'column-add-values-hidden');
|
|
318
|
+
this.highlights.delete(cell);
|
|
319
|
+
for (const name of ['delay', 'fade', 'from', 'height', 'width'])
|
|
320
|
+
cell.style?.removeProperty(`--column-${name}`);
|
|
321
|
+
}
|
|
322
|
+
highlight.cells.clear();
|
|
323
|
+
this.refresh();
|
|
324
|
+
}, 350);
|
|
325
|
+
for (const { cells, expanding, header } of columns) {
|
|
326
|
+
for (const cell of cells) {
|
|
327
|
+
cell.classList.toggle('column-add-new', expanding);
|
|
328
|
+
cell.classList.toggle('column-add-opening', expanding);
|
|
329
|
+
cell.classList.toggle('column-add-values-hidden', opening && cell !== header);
|
|
330
|
+
cell.classList.add('column-add-highlight');
|
|
331
|
+
cell.style?.setProperty('--column-delay', '0ms');
|
|
332
|
+
cell.style?.setProperty('--column-fade', '350ms');
|
|
333
|
+
this.highlights.set(cell, highlight);
|
|
334
|
+
}
|
|
335
|
+
if (expanding && header.ownerDocument)
|
|
336
|
+
setTimeout(() => {
|
|
337
|
+
if (this.disposed || !header.isConnected)
|
|
338
|
+
return;
|
|
339
|
+
header.classList.remove('column-add-opening');
|
|
309
340
|
this.refresh();
|
|
310
|
-
|
|
341
|
+
}, 100);
|
|
311
342
|
}
|
|
312
|
-
if (expanding && header.ownerDocument)
|
|
313
|
-
setTimeout(() => {
|
|
314
|
-
if (this.disposed || !header.isConnected)
|
|
315
|
-
return;
|
|
316
|
-
header.classList.remove('column-add-opening');
|
|
317
|
-
this.refresh();
|
|
318
|
-
}, 100);
|
|
319
343
|
}
|
|
320
344
|
init() {
|
|
321
345
|
this.disposed = false;
|
|
@@ -349,41 +373,57 @@ export class TableColumnAdd extends Plugin {
|
|
|
349
373
|
throw new Error('Column row view changed during loading');
|
|
350
374
|
}
|
|
351
375
|
const old = entry.content;
|
|
352
|
-
const opening = old.header.classList.contains('column-add-opening');
|
|
353
376
|
const width = old.header.getBoundingClientRect?.().width ?? 0;
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
377
|
+
const removing = old.header.classList.contains('column-remove-highlight');
|
|
378
|
+
const animation = old.header.getAnimations?.().find(animation => animation.animationName === 'itrocks-column-add-flash');
|
|
379
|
+
const elapsed = typeof animation?.currentTime === 'number' ? animation.currentTime : 0;
|
|
380
|
+
const pairs = [[old.header, content.header], ...old.cells.map((cell, index) => [cell, content.cells[index]])];
|
|
381
|
+
for (const [previous, replacement] of pairs) {
|
|
382
|
+
replacement.hidden = previous.hidden;
|
|
383
|
+
const highlight = this.highlights.get(previous);
|
|
384
|
+
if (highlight && performance.now() < highlight.started + 350) {
|
|
385
|
+
highlight.cells.delete(previous);
|
|
386
|
+
highlight.cells.add(replacement);
|
|
387
|
+
this.highlights.delete(previous);
|
|
388
|
+
this.highlights.set(replacement, highlight);
|
|
389
|
+
replacement.classList.add('column-add-highlight');
|
|
390
|
+
replacement.classList.toggle('column-add-values-hidden', previous.classList.contains('column-add-values-hidden'));
|
|
391
|
+
replacement.style?.setProperty('--column-fade', '350ms');
|
|
392
|
+
replacement.style?.setProperty('--column-delay', `${-elapsed}ms`);
|
|
393
|
+
}
|
|
394
|
+
else
|
|
395
|
+
this.clearHighlight(previous);
|
|
358
396
|
}
|
|
359
|
-
for (const cell of [content.header, ...content.cells])
|
|
360
|
-
cell.hidden = old.header.hidden;
|
|
361
397
|
this.reorder.replaceCell(old.header, content.header);
|
|
362
398
|
old.cells.forEach((cell, index) => this.reorder.replaceCell(cell, content.cells[index]));
|
|
363
399
|
entry.content = content;
|
|
364
400
|
this.identities.set(content.header, entry.source.id);
|
|
365
401
|
content.header.dataset.columnId = entry.source.id;
|
|
366
|
-
|
|
402
|
+
this.mark(entry, 'provisional', entry.transaction.state === 'provisional');
|
|
403
|
+
this.mark(entry, 'loading', false);
|
|
404
|
+
this.refresh();
|
|
367
405
|
if (removing) {
|
|
368
406
|
this.measureColumn(content.header, width);
|
|
369
407
|
for (const cell of [content.header, ...content.cells])
|
|
370
408
|
cell.classList.add('column-remove-highlight');
|
|
371
409
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.refresh();
|
|
375
|
-
this.notify(entry, 'loaded');
|
|
376
|
-
if (!removing && entry.effects && entry.transaction.state === 'committed') {
|
|
410
|
+
else if (entry.effects && this.highlights.has(content.header) && !this.isLastColumn(content.header)) {
|
|
411
|
+
this.measureColumn(content.header);
|
|
377
412
|
for (const cell of [content.header, ...content.cells]) {
|
|
378
413
|
cell.style?.setProperty('--column-from', `${width}px`);
|
|
379
|
-
cell.
|
|
414
|
+
cell.classList.add('column-add-new', 'column-add-opening');
|
|
380
415
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
416
|
+
setTimeout(() => {
|
|
417
|
+
if (!this.disposed && content.header.isConnected) {
|
|
418
|
+
content.header.classList.remove('column-add-opening');
|
|
419
|
+
this.refresh();
|
|
420
|
+
}
|
|
421
|
+
}, 100);
|
|
386
422
|
}
|
|
423
|
+
if (!removing && entry.effects && entry.transaction.state === 'committed'
|
|
424
|
+
&& this.isLastColumn(content.header))
|
|
425
|
+
this.scrollToEnd();
|
|
426
|
+
this.notify(entry, 'loaded');
|
|
387
427
|
}
|
|
388
428
|
catch (error) {
|
|
389
429
|
if (!this.live(entry))
|
|
@@ -392,10 +432,9 @@ export class TableColumnAdd extends Plugin {
|
|
|
392
432
|
this.mark(entry, 'error', true);
|
|
393
433
|
this.notify(entry, 'error', error);
|
|
394
434
|
for (const cell of [entry.content.header, ...entry.content.cells]) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
for (const name of ['fade', 'from', 'height', 'width'])
|
|
435
|
+
this.clearHighlight(cell);
|
|
436
|
+
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening', 'column-add-values-hidden');
|
|
437
|
+
for (const name of ['delay', 'fade', 'from', 'height', 'width'])
|
|
399
438
|
cell.style?.removeProperty(`--column-${name}`);
|
|
400
439
|
}
|
|
401
440
|
this.refresh();
|
|
@@ -436,33 +475,52 @@ export class TableColumnAdd extends Plugin {
|
|
|
436
475
|
}
|
|
437
476
|
/** Reveal and briefly mark a column in red before removing it. */
|
|
438
477
|
remove(id, signal) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
478
|
+
return this.removeMany([id], signal);
|
|
479
|
+
}
|
|
480
|
+
/** Flash all requested columns together, then remove them after one shared delay. */
|
|
481
|
+
removeMany(ids, signal) {
|
|
482
|
+
const names = [...new Set(ids)];
|
|
483
|
+
if (names.length === 1) {
|
|
484
|
+
const pending = this.removals.get(names[0]);
|
|
485
|
+
if (pending)
|
|
486
|
+
return pending.promise;
|
|
487
|
+
}
|
|
488
|
+
if (!names.length || this.disposed || signal?.aborted || names.some(id => !this.find(id)))
|
|
443
489
|
return Promise.resolve(false);
|
|
444
|
-
if (this.external || this.
|
|
490
|
+
if (this.external || names.some(id => this.removals.has(id)
|
|
491
|
+
|| this.pending.get(id)?.transaction.state === 'provisional'))
|
|
445
492
|
return Promise.reject(new Error('A column interaction is active'));
|
|
446
493
|
const abort = new AbortController();
|
|
447
494
|
const cancelled = AbortSignal.any([abort.signal, ...(signal ? [signal] : [])]);
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
495
|
+
const operation = names.length === 1 ? this.removeColumn(names[0], cancelled) : this.removeColumns(names, cancelled);
|
|
496
|
+
const promise = operation.finally(() => {
|
|
497
|
+
for (const id of names)
|
|
498
|
+
if (this.removals.get(id)?.abort === abort)
|
|
499
|
+
this.removals.delete(id);
|
|
451
500
|
});
|
|
452
|
-
|
|
501
|
+
for (const id of names)
|
|
502
|
+
this.removals.set(id, { abort, promise });
|
|
453
503
|
return promise;
|
|
454
504
|
}
|
|
455
|
-
|
|
456
|
-
this.
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
this.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
this.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
505
|
+
removeColumn(id, signal) {
|
|
506
|
+
return this.removeColumns([id], signal);
|
|
507
|
+
}
|
|
508
|
+
async removeColumns(ids, signal) {
|
|
509
|
+
this.reveal(ids.at(-1));
|
|
510
|
+
const columns = ids.map(id => {
|
|
511
|
+
const header = this.find(id);
|
|
512
|
+
const cells = Array.from(this.of.element.rows).map(row => row.cells[header.cellIndex]).filter(Boolean);
|
|
513
|
+
return { cells, header, id, width: header.getBoundingClientRect?.().width ?? 0 };
|
|
514
|
+
});
|
|
515
|
+
// Finish every layout read before applying any removal class, so all animations start in the same frame.
|
|
516
|
+
for (const column of columns)
|
|
517
|
+
this.measureColumn(column.header, column.width);
|
|
518
|
+
for (const column of columns)
|
|
519
|
+
for (const cell of column.cells) {
|
|
520
|
+
this.clearHighlight(cell);
|
|
521
|
+
cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening', 'column-add-values-hidden');
|
|
522
|
+
cell.classList.add('column-remove-highlight');
|
|
523
|
+
}
|
|
466
524
|
try {
|
|
467
525
|
await new Promise(resolve => {
|
|
468
526
|
const finish = () => {
|
|
@@ -473,25 +531,27 @@ export class TableColumnAdd extends Plugin {
|
|
|
473
531
|
const timer = setTimeout(finish, 300);
|
|
474
532
|
signal.addEventListener('abort', finish, { once: true });
|
|
475
533
|
});
|
|
476
|
-
|
|
477
|
-
if (this.disposed || signal.aborted || !current)
|
|
478
|
-
return false;
|
|
479
|
-
if (!this.reorder.removeColumn(current))
|
|
534
|
+
if (this.disposed || signal.aborted || ids.some(id => !this.find(id)))
|
|
480
535
|
return false;
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
536
|
+
for (const id of ids) {
|
|
537
|
+
if (!this.reorder.removeColumn(this.find(id)))
|
|
538
|
+
return false;
|
|
539
|
+
const entry = this.pending.get(id);
|
|
540
|
+
entry?.abort.abort();
|
|
541
|
+
this.pending.delete(id);
|
|
542
|
+
}
|
|
485
543
|
return true;
|
|
486
544
|
}
|
|
487
545
|
finally {
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
cell
|
|
493
|
-
|
|
494
|
-
|
|
546
|
+
for (const column of columns) {
|
|
547
|
+
const current = this.find(column.id);
|
|
548
|
+
if (current)
|
|
549
|
+
column.cells.push(...Array.from(this.of.element.rows).map(row => row.cells[current.cellIndex]));
|
|
550
|
+
for (const cell of column.cells) {
|
|
551
|
+
cell?.classList.remove('column-remove-highlight');
|
|
552
|
+
for (const name of ['delay', 'fade', 'from', 'height', 'width'])
|
|
553
|
+
cell?.style?.removeProperty(`--column-${name}`);
|
|
554
|
+
}
|
|
495
555
|
}
|
|
496
556
|
this.refresh();
|
|
497
557
|
}
|
package/freeze.js
CHANGED
|
@@ -22,8 +22,9 @@ export class TableFreeze extends Plugin {
|
|
|
22
22
|
const styles = this.of.styleSheet;
|
|
23
23
|
for (const rule of this.rules) {
|
|
24
24
|
const index = styles.indexOf(rule);
|
|
25
|
-
if (index >= 0)
|
|
25
|
+
if (index >= 0) {
|
|
26
26
|
styles.splice(index, 1);
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
// Measure natural positions, including header-backed columns that were previously sticky.
|
|
29
30
|
this.of.refreshStyleSheets();
|
|
@@ -34,7 +35,9 @@ export class TableFreeze extends Plugin {
|
|
|
34
35
|
while (parent && (parent.scrollHeight <= parent.clientHeight)) {
|
|
35
36
|
parent = parent.parentElement;
|
|
36
37
|
}
|
|
37
|
-
return parent
|
|
38
|
+
return parent
|
|
39
|
+
? ((parent instanceof HTMLHtmlElement) ? window : parent)
|
|
40
|
+
: undefined;
|
|
38
41
|
}
|
|
39
42
|
countLeftColumns() {
|
|
40
43
|
let count = 0;
|
|
@@ -54,7 +57,9 @@ export class TableFreeze extends Plugin {
|
|
|
54
57
|
const table = this.of;
|
|
55
58
|
if (!table.element.tFoot?.rows.length)
|
|
56
59
|
return;
|
|
57
|
-
let counter = 1
|
|
60
|
+
let counter = 1;
|
|
61
|
+
let bottom = .0;
|
|
62
|
+
let previousBottom = table.element.getBoundingClientRect().bottom;
|
|
58
63
|
for (const row of Array.from(table.element.tFoot.querySelectorAll(':scope > tr')).reverse()) {
|
|
59
64
|
const actualBottom = row.getBoundingClientRect().bottom;
|
|
60
65
|
bottom += previousBottom - actualBottom;
|
|
@@ -79,7 +84,9 @@ export class TableFreeze extends Plugin {
|
|
|
79
84
|
if (!table.element.tHead?.rows.length)
|
|
80
85
|
return;
|
|
81
86
|
// Header measurements are in scrolled coordinates after refresh removes the sticky rules.
|
|
82
|
-
let counter = 1
|
|
87
|
+
let counter = 1;
|
|
88
|
+
let top = .0;
|
|
89
|
+
let previousTop = table.element.getBoundingClientRect().top - table.element.scrollTop;
|
|
83
90
|
table.element.tHead.querySelectorAll(':scope > tr').forEach(row => {
|
|
84
91
|
const actualTop = row.getBoundingClientRect().top;
|
|
85
92
|
top += actualTop - previousTop;
|
|
@@ -96,7 +103,7 @@ export class TableFreeze extends Plugin {
|
|
|
96
103
|
${table.selector} > thead > tr > * {
|
|
97
104
|
position: sticky;
|
|
98
105
|
${zIndex}
|
|
99
|
-
}
|
|
106
|
+
}
|
|
100
107
|
`);
|
|
101
108
|
}
|
|
102
109
|
freezeLeftColumns() {
|
|
@@ -105,7 +112,10 @@ export class TableFreeze extends Plugin {
|
|
|
105
112
|
const table = this.of;
|
|
106
113
|
const bodySel = [];
|
|
107
114
|
const cornerSel = [];
|
|
108
|
-
|
|
115
|
+
// A scrolling table keeps its own bounds fixed while its natural column positions move.
|
|
116
|
+
let counter = 1;
|
|
117
|
+
let left = .0;
|
|
118
|
+
let previousLeft = table.element.getBoundingClientRect().left - table.element.scrollLeft;
|
|
109
119
|
for (const colCell of Array.from(this.columns).slice(0, this.leftColumnCount)) {
|
|
110
120
|
const actualLeft = colCell.getBoundingClientRect().left;
|
|
111
121
|
left += actualLeft - previousLeft;
|
|
@@ -185,13 +195,18 @@ export class TableFreeze extends Plugin {
|
|
|
185
195
|
const tableElement = this.of.element;
|
|
186
196
|
const rect = tableElement.getBoundingClientRect();
|
|
187
197
|
// Cols supply configuration and layout widths; only rendered cells have sticky viewport positions.
|
|
188
|
-
const cells = tableElement.tHead?.rows[0]?.cells
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
198
|
+
const cells = tableElement.tHead?.rows[0]?.cells
|
|
199
|
+
?? tableElement.tBodies[0]?.rows[0]?.cells;
|
|
200
|
+
const left = (this.leftColumnCount && cells?.[this.leftColumnCount - 1])
|
|
201
|
+
? cells[this.leftColumnCount - 1].getBoundingClientRect().right
|
|
202
|
+
: rect.left;
|
|
203
|
+
const right = (this.rightColumnCount && cells?.[cells.length - this.rightColumnCount])
|
|
204
|
+
? cells[cells.length - this.rightColumnCount].getBoundingClientRect().left
|
|
205
|
+
: rect.right;
|
|
206
|
+
const top = tableElement.tHead?.lastElementChild?.firstElementChild?.getBoundingClientRect().bottom
|
|
207
|
+
?? rect.top;
|
|
208
|
+
const bottom = tableElement.tFoot?.firstElementChild?.firstElementChild?.getBoundingClientRect().top
|
|
209
|
+
?? rect.bottom;
|
|
195
210
|
rect.x = left;
|
|
196
211
|
rect.y = top;
|
|
197
212
|
rect.width = Math.max(0, right - left);
|
package/package.json
CHANGED