@itrocks/table 0.4.3 → 0.8.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/README.md +51 -13
- package/column-add.css +76 -5
- package/column-add.d.ts +35 -7
- package/column-add.js +288 -39
- package/column-reorder.d.ts +13 -3
- package/column-reorder.js +58 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -263,22 +263,45 @@ Callbacks own safe rendering, row identity and data access. If row elements chan
|
|
|
263
263
|
error rather than applying stale positional values. Before retry, the consumer updates its callbacks' row data to
|
|
264
264
|
match the current view.
|
|
265
265
|
|
|
266
|
-
- `add(source): Promise<'added' | 'existing'>` appends before right-frozen columns, reveals and highlights.
|
|
267
|
-
once the real placeholder column is committed, independently of optional values. A repeated id reveals/highlights its
|
|
266
|
+
- `add(source, options?): Promise<'added' | 'existing'>` appends before right-frozen columns, reveals and highlights.
|
|
267
|
+
It resolves once the real placeholder column is committed, independently of optional values. A repeated id reveals/highlights its
|
|
268
268
|
existing position, without invoking its creation/loading callbacks or issuing another commit.
|
|
269
269
|
- `reveal(id): void` scrolls the horizontal container only as needed, accounting for frozen bounds.
|
|
270
|
-
- `highlight(id): void` applies the same green/light/theme flash for new and existing columns, cleans up after
|
|
271
|
-
honours reduced motion and preserves keyboard focus and row selection.
|
|
270
|
+
- `highlight(id): void` applies the same green/light/theme flash for new and existing columns, cleans up after 350 ms,
|
|
271
|
+
honours reduced motion and preserves keyboard focus and row selection. Existing columns keep their content and 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.
|
|
278
|
+
- `remove(id, signal?): Promise<boolean>` reveals a column, shrinks it over 100 ms during a 300 ms red flash,
|
|
279
|
+
hiding cell content immediately, then removes the header, body/footer cells and matching `col`. It returns false for
|
|
280
|
+
a missing column or cancellation. Repeated calls share the pending removal; abort, disposal and reset clear the flash
|
|
281
|
+
without deletion. Late values cannot restore a removed column. Cancellation restores the natural width.
|
|
282
|
+
Reduced motion skips width animation and uses a static red outline.
|
|
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.
|
|
272
288
|
- `retry(id): Promise<void>` retries a failed value callback. Failure retains the committed column and marks it with
|
|
273
|
-
`.column-add-error`;
|
|
274
|
-
|
|
275
|
-
|
|
289
|
+
`.column-add-error`; data cells receive a discreet red background and the addition flash stops.
|
|
290
|
+
It never confirms another addition. The plugin adds no error text, retry control or automatic retry.
|
|
291
|
+
- `begin(source, options?): ColumnTransaction` creates a real provisional column without committing it.
|
|
292
|
+
Its `ready` promise waits for optional values and resolves after error notification as well. `moveTo(index)` reuses public reorder placement
|
|
276
293
|
and its existing boundaries. `commit()` validates it and returns `added` or `existing`; repeating commit returns
|
|
277
294
|
`existing`. `cancel()` aborts values, removes new provisional cells or restores an existing column's position.
|
|
278
295
|
Completed/cancelled handles cannot move a column. `begin()` itself installs no pointer transport.
|
|
279
296
|
- `dispose(): void` cancels provisional operations, aborts outstanding values and removes flash resources. Committed
|
|
280
297
|
columns remain. `Table.reset()` invokes disposal automatically; call disposal when removing the owning view.
|
|
281
298
|
|
|
299
|
+
`ColumnCreationOptions` is shared by `add` and `begin`. `hidden: true` inserts hidden cells and a hidden `col`;
|
|
300
|
+
loaded replacements retain that visibility. `effects: false` skips width animation, flash and automatic scroll for both
|
|
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.
|
|
304
|
+
|
|
282
305
|
`TableColumnAddOptions.identify(header)` defaults to `header.dataset.columnId`. Added and loaded headers carry this
|
|
283
306
|
opaque attribute so identity survives plugin resets. A custom callback can identify pre-existing columns differently.
|
|
284
307
|
`onChange(change)` runs synchronously for `provisional`, `committed`, `loaded`, `error` and `cancelled` observations;
|
|
@@ -288,10 +311,17 @@ An aborted or removed operation cannot be recreated by late values.
|
|
|
288
311
|
|
|
289
312
|
`TableColumnReorder.moveColumn(header, index)` is public placement without header gesture callbacks. It rejects an
|
|
290
313
|
active header interaction and clamps movement to that header's reorderable boundaries.
|
|
314
|
+
`TableColumnReorder.removeColumn(header): boolean` removes a reorderable column and its `col` without header callbacks.
|
|
315
|
+
It rejects an active header interaction and returns false for a missing or fixed column.
|
|
291
316
|
`TableColumnReorder.replaceCell(previous, replacement)`
|
|
292
317
|
preserves an active header gesture during asynchronous cell replacement. `TableFreeze.refresh()` recalculates sticky
|
|
293
318
|
offsets after structural changes. `Table.refreshStyleSheets()` reapplies the managed styles.
|
|
294
319
|
|
|
320
|
+
Internal and external drags share one placement rule. Hovering the source column leaves its position unchanged.
|
|
321
|
+
Over another column, moving left places the source before it; moving right places the source after it.
|
|
322
|
+
Placement uses the current pointer or automatic scrolling direction, without retaining the previous hovered column.
|
|
323
|
+
Cells and the corresponding `<col>` are moved only when the resulting index changes.
|
|
324
|
+
|
|
295
325
|
`TableColumnReorder.scrollContainer()` exposes the existing horizontal scroll owner for table plugins.
|
|
296
326
|
`TableFreeze.visibleInnerRect()` returns the area between rendered sticky cells, including tables configured through
|
|
297
327
|
`colgroup`. `reveal()` fully exposes columns that fit that area and uses its maximum width for wider columns, with
|
|
@@ -300,10 +330,10 @@ including header-backed tables after addition, asynchronous replacement or reset
|
|
|
300
330
|
|
|
301
331
|
### External pointer transport
|
|
302
332
|
|
|
303
|
-
`beginExternal(source, sample): ColumnOperation` immediately creates a hidden provisional column and starts
|
|
304
|
-
its values. The cells and optional `col` stay hidden until the pointer first enters the visible table; loaded replacements
|
|
333
|
+
`beginExternal(source, sample, options?): ColumnOperation` immediately creates a hidden provisional column and starts
|
|
334
|
+
loading its values. The cells and optional `col` stay hidden until the pointer first enters the visible table; loaded replacements
|
|
305
335
|
preserve that visibility. On entry, the column appears with any values already received and starts following reorder
|
|
306
|
-
geometry. Reusing an existing id
|
|
336
|
+
geometry. Reusing an existing id preserves its visibility, including a committed hidden column prepared with `begin`.
|
|
307
337
|
The structural `PointerSample` contains `pointerId`, `pointerType`, `clientX` and `clientY`. The source owns capture.
|
|
308
338
|
`move(sample)` uses the existing reorder engine, including frozen boundaries and visible-edge autoscroll.
|
|
309
339
|
`finish(sample)` resolves to `added`, `moved` or `cancelled`; an outside drop cancels without a fallback insertion.
|
|
@@ -315,9 +345,17 @@ Optional `ColumnSource.accept(signal)` validates host admission independently of
|
|
|
315
345
|
waiting for `load`. Rejection rolls back and rejects `finish`. An omitted callback accepts immediately. Value errors
|
|
316
346
|
remain retryable and do not reject a valid drop. The host must keep admission independent of its data request.
|
|
317
347
|
|
|
318
|
-
`TableColumnReorder.beginExternal(header, sample): ExternalColumnOperation` is the lower-level public
|
|
319
|
-
an already attached column. Its `move`, `hold`, `finish` and `cancel` methods share header-origin geometry and
|
|
348
|
+
`TableColumnReorder.beginExternal(header, sample, options?): ExternalColumnOperation` is the lower-level public
|
|
349
|
+
extension for an already attached column. Its `move`, `hold`, `finish` and `cancel` methods share header-origin geometry and
|
|
320
350
|
placement.
|
|
321
351
|
`hold(sample)` settles and pauses autoscroll while retaining exclusivity; it returns whether the target is valid.
|
|
322
|
-
`finish(sample)` releases the gesture and returns acceptance.
|
|
352
|
+
`finish(sample)` releases the gesture and returns acceptance. External reordering leaves persistence to its owner;
|
|
323
353
|
the owning addition transaction emits its distinct commit notification. Header-origin gestures retain their callbacks.
|
|
354
|
+
|
|
355
|
+
Both external entry points accept `ColumnDragOptions`. `adding: true` applies `.adding` for a green addition indicator
|
|
356
|
+
instead of `.moving`, and removes the newly created column on cancellation. `removal: true` enables the standard
|
|
357
|
+
header-origin removal on an outside drop, including a hidden column that never entered the table. Removal invokes
|
|
358
|
+
`onRemove` once; the higher-level operation resolves to `removed`. The defaults preserve preview cancellation.
|
|
359
|
+
Hidden cells and their `col` become visible on first pointer entry, without an opening animation or automatic reveal
|
|
360
|
+
scroll. `onReveal()` observes this transition; the addition wrapper also refreshes frozen geometry. Replacement cells
|
|
361
|
+
preserve hidden state and active indicators while values load.
|
package/column-add.css
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
1
2
|
table.itrocks > colgroup > col[hidden],
|
|
2
3
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td)[hidden] {
|
|
3
4
|
display: none !important;
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-highlight {
|
|
7
|
-
animation: itrocks-column-add-flash
|
|
8
|
+
animation: itrocks-column-add-flash var(--column-fade, 350ms) ease-out var(--column-delay, 0ms);
|
|
9
|
+
}
|
|
10
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-opening::after {
|
|
11
|
+
animation: itrocks-column-open 100ms ease-out both;
|
|
12
|
+
}
|
|
13
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
|
|
14
|
+
animation: itrocks-column-remove-flash 300ms ease-out;
|
|
15
|
+
}
|
|
16
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::after {
|
|
17
|
+
animation: itrocks-column-close 100ms ease-out both;
|
|
18
|
+
}
|
|
19
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight, table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-new:is(.column-add-opening, td, tbody th, tfoot th) {
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
font-size: 0 !important;
|
|
22
|
+
height: var(--column-height);
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
padding: 0 !important;
|
|
25
|
+
}
|
|
26
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight > *, table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-new:is(.column-add-opening, td, tbody th, tfoot th) > * {
|
|
27
|
+
display: none !important;
|
|
28
|
+
}
|
|
29
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::before, table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-new:is(.column-add-opening, td, tbody th, tfoot th)::before {
|
|
30
|
+
content: none !important;
|
|
31
|
+
}
|
|
32
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::after, table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-new:is(.column-add-opening, td, tbody th, tfoot th)::after {
|
|
33
|
+
content: " " !important;
|
|
34
|
+
display: block;
|
|
35
|
+
font-size: 1px;
|
|
36
|
+
line-height: 1px;
|
|
37
|
+
width: var(--column-width);
|
|
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;
|
|
8
44
|
}
|
|
9
45
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-loading {
|
|
10
46
|
cursor: progress;
|
|
@@ -12,11 +48,26 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-loading {
|
|
|
12
48
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-provisional {
|
|
13
49
|
background-color: color-mix(in srgb, #58b46b 5%, Canvas);
|
|
14
50
|
}
|
|
15
|
-
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error {
|
|
16
|
-
|
|
17
|
-
outline-offset: -2px;
|
|
51
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error:is(td, tbody th, tfoot th) {
|
|
52
|
+
background-color: color-mix(in srgb, #d33 12%, Canvas);
|
|
18
53
|
}
|
|
19
54
|
|
|
55
|
+
@keyframes itrocks-column-open {
|
|
56
|
+
from {
|
|
57
|
+
width: var(--column-from, 0px);
|
|
58
|
+
}
|
|
59
|
+
to {
|
|
60
|
+
width: var(--column-width);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
@keyframes itrocks-column-close {
|
|
64
|
+
from {
|
|
65
|
+
width: var(--column-width);
|
|
66
|
+
}
|
|
67
|
+
to {
|
|
68
|
+
width: 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
20
71
|
@keyframes itrocks-column-add-flash {
|
|
21
72
|
0% {
|
|
22
73
|
background-color: color-mix(in srgb, #58b46b 35%, Canvas);
|
|
@@ -25,9 +76,29 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error {
|
|
|
25
76
|
background-color: color-mix(in srgb, white 20%, Canvas);
|
|
26
77
|
}
|
|
27
78
|
}
|
|
79
|
+
@keyframes itrocks-column-remove-flash {
|
|
80
|
+
0% {
|
|
81
|
+
background-color: color-mix(in srgb, #d33 50%, Canvas);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
28
84
|
@media (prefers-reduced-motion: reduce) {
|
|
29
|
-
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-
|
|
85
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
|
|
86
|
+
animation: none;
|
|
87
|
+
}
|
|
88
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::after {
|
|
30
89
|
animation: none;
|
|
90
|
+
}
|
|
91
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
|
|
92
|
+
outline: 2px solid #c33;
|
|
93
|
+
outline-offset: -2px;
|
|
94
|
+
}
|
|
95
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening) {
|
|
96
|
+
animation: none;
|
|
97
|
+
}
|
|
98
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening)::after {
|
|
99
|
+
animation: none;
|
|
100
|
+
}
|
|
101
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening) {
|
|
31
102
|
outline: 2px solid color-mix(in srgb, #58b46b 65%, Canvas);
|
|
32
103
|
outline-offset: -2px;
|
|
33
104
|
}
|
package/column-add.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from '../plugin/plugin.js';
|
|
2
2
|
import { PluginOptions } from '../plugin/plugin.js';
|
|
3
|
+
import type { ColumnDragOptions } from './column-reorder.js';
|
|
3
4
|
import type { PointerSample } from './column-reorder.js';
|
|
4
5
|
import { TableColumnReorder } from './column-reorder.js';
|
|
5
6
|
import { Table } from './table.js';
|
|
@@ -13,9 +14,13 @@ export type ColumnContent = {
|
|
|
13
14
|
cells: readonly HTMLTableCellElement[];
|
|
14
15
|
header: HTMLTableCellElement;
|
|
15
16
|
};
|
|
17
|
+
export type ColumnCreationOptions = {
|
|
18
|
+
effects?: boolean | 'deferred';
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
};
|
|
16
21
|
export interface ColumnOperation {
|
|
17
22
|
cancel(): void;
|
|
18
|
-
finish(sample: PointerSample): Promise<'added' | 'moved' | 'cancelled'>;
|
|
23
|
+
finish(sample: PointerSample): Promise<'added' | 'moved' | 'removed' | 'cancelled'>;
|
|
19
24
|
move(sample: PointerSample): void;
|
|
20
25
|
}
|
|
21
26
|
export type ColumnResult = 'added' | 'existing';
|
|
@@ -35,41 +40,64 @@ export interface ColumnTransaction {
|
|
|
35
40
|
commit(): ColumnResult;
|
|
36
41
|
moveTo(index: number): void;
|
|
37
42
|
}
|
|
43
|
+
interface Highlight {
|
|
44
|
+
cells: Set<HTMLTableCellElement>;
|
|
45
|
+
started: number;
|
|
46
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
47
|
+
}
|
|
38
48
|
interface Pending {
|
|
39
49
|
abort: AbortController;
|
|
40
50
|
col?: HTMLTableColElement;
|
|
41
51
|
content: ColumnContent;
|
|
52
|
+
effects: boolean;
|
|
42
53
|
initial: number;
|
|
43
54
|
rows: HTMLTableRowElement[];
|
|
44
55
|
settled: boolean;
|
|
45
56
|
source: ColumnSource;
|
|
57
|
+
started?: number;
|
|
46
58
|
transaction: ColumnTransaction;
|
|
47
59
|
}
|
|
48
60
|
export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions> {
|
|
49
61
|
protected disposed: boolean;
|
|
50
62
|
protected external?: ColumnOperation;
|
|
51
|
-
protected highlights: Map<HTMLTableCellElement,
|
|
63
|
+
protected highlights: Map<HTMLTableCellElement, Highlight>;
|
|
52
64
|
protected identities: WeakMap<HTMLTableCellElement, string>;
|
|
53
65
|
protected pending: Map<string, Pending>;
|
|
66
|
+
protected removals: Map<string, {
|
|
67
|
+
abort: AbortController;
|
|
68
|
+
promise: Promise<boolean>;
|
|
69
|
+
}>;
|
|
54
70
|
protected reorder: TableColumnReorder;
|
|
55
|
-
|
|
71
|
+
protected scrollFrame?: number;
|
|
72
|
+
add(source: ColumnSource, options?: ColumnCreationOptions): Promise<ColumnResult>;
|
|
56
73
|
/** Create a provisional column without installing pointer transport. */
|
|
57
|
-
begin(source: ColumnSource): ColumnTransaction;
|
|
74
|
+
begin(source: ColumnSource, options?: ColumnCreationOptions): ColumnTransaction;
|
|
58
75
|
/** Add or move an opaque column through the existing reorder geometry. */
|
|
59
|
-
beginExternal(source: ColumnSource, sample: PointerSample): ColumnOperation;
|
|
60
|
-
protected create(source: ColumnSource,
|
|
76
|
+
beginExternal(source: ColumnSource, sample: PointerSample, options?: ColumnDragOptions): ColumnOperation;
|
|
77
|
+
protected create(source: ColumnSource, options?: ColumnCreationOptions): ColumnTransaction;
|
|
61
78
|
defaultOptions(): TableColumnAddOptions;
|
|
62
79
|
dispose(): void;
|
|
80
|
+
protected clearHighlight(cell: HTMLTableCellElement): void;
|
|
63
81
|
protected find(id: string): HTMLTableCellElement | undefined;
|
|
64
82
|
protected headers(): HTMLTableRowElement;
|
|
65
|
-
highlight(id: string): void;
|
|
83
|
+
highlight(id: string, opening?: boolean): void;
|
|
84
|
+
highlightMany(ids: readonly string[], opening?: boolean): void;
|
|
66
85
|
init(): void;
|
|
86
|
+
protected isLastColumn(header: HTMLTableCellElement): boolean;
|
|
67
87
|
protected live(entry: Pending): boolean;
|
|
68
88
|
protected load(entry: Pending): Promise<void>;
|
|
69
89
|
protected mark(entry: Pending, state: 'error' | 'loading' | 'provisional', present: boolean): void;
|
|
90
|
+
protected measureColumn(header: HTMLTableCellElement, width?: number): void;
|
|
70
91
|
protected notify(entry: Pending, state: ColumnState, error?: unknown): void;
|
|
71
92
|
protected refresh(): void;
|
|
93
|
+
/** Reveal and briefly mark a column in red before removing it. */
|
|
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>;
|
|
97
|
+
protected removeColumn(id: string, signal: AbortSignal): Promise<boolean>;
|
|
98
|
+
protected removeColumns(ids: readonly string[], signal: AbortSignal): Promise<boolean>;
|
|
72
99
|
reveal(id: string): void;
|
|
100
|
+
protected scrollToEnd(): void;
|
|
73
101
|
retry(id: string): Promise<void>;
|
|
74
102
|
protected validate(content: ColumnContent, rows: HTMLTableRowElement[]): void;
|
|
75
103
|
}
|
package/column-add.js
CHANGED
|
@@ -8,20 +8,24 @@ export class TableColumnAdd extends Plugin {
|
|
|
8
8
|
highlights = new Map();
|
|
9
9
|
identities = new WeakMap();
|
|
10
10
|
pending = new Map();
|
|
11
|
+
removals = new Map();
|
|
11
12
|
reorder;
|
|
12
|
-
|
|
13
|
+
scrollFrame;
|
|
14
|
+
add(source, options = {}) {
|
|
13
15
|
try {
|
|
14
16
|
if (this.disposed)
|
|
15
17
|
throw new Error('Column addition is disposed');
|
|
16
18
|
if (this.find(source.id)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
if (options.effects !== false) {
|
|
20
|
+
this.reveal(source.id);
|
|
21
|
+
this.highlight(source.id);
|
|
22
|
+
}
|
|
19
23
|
return Promise.resolve('existing');
|
|
20
24
|
}
|
|
21
|
-
const operation = this.begin(source);
|
|
25
|
+
const operation = this.begin(source, options);
|
|
22
26
|
const result = operation.commit();
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
if (options.effects !== false)
|
|
28
|
+
this.reveal(source.id);
|
|
25
29
|
return Promise.resolve(result);
|
|
26
30
|
}
|
|
27
31
|
catch (error) {
|
|
@@ -29,18 +33,17 @@ export class TableColumnAdd extends Plugin {
|
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
/** Create a provisional column without installing pointer transport. */
|
|
32
|
-
begin(source) {
|
|
33
|
-
return this.create(source);
|
|
36
|
+
begin(source, options = {}) {
|
|
37
|
+
return this.create(source, options);
|
|
34
38
|
}
|
|
35
39
|
/** Add or move an opaque column through the existing reorder geometry. */
|
|
36
|
-
beginExternal(source, sample) {
|
|
40
|
+
beginExternal(source, sample, options = {}) {
|
|
37
41
|
if (this.disposed || this.external)
|
|
38
42
|
throw new Error('Column addition is unavailable');
|
|
39
43
|
if (this.pending.get(source.id)?.transaction.state === 'provisional')
|
|
40
44
|
throw new Error('Column addition is pending');
|
|
41
45
|
const existing = this.find(source.id);
|
|
42
|
-
const
|
|
43
|
-
const transaction = existing ? undefined : this.create(source, true);
|
|
46
|
+
const transaction = existing ? undefined : this.create(source, { effects: false, hidden: true });
|
|
44
47
|
let reorder;
|
|
45
48
|
const enter = (point) => {
|
|
46
49
|
if (reorder || point.pointerId !== sample.pointerId)
|
|
@@ -57,7 +60,12 @@ export class TableColumnAdd extends Plugin {
|
|
|
57
60
|
entry.col.hidden = false;
|
|
58
61
|
this.refresh();
|
|
59
62
|
}
|
|
60
|
-
reorder = this.reorder.beginExternal(existing ?? transaction.header, point
|
|
63
|
+
reorder = this.reorder.beginExternal(existing ?? transaction.header, point, {
|
|
64
|
+
...options, onReveal: () => {
|
|
65
|
+
this.refresh();
|
|
66
|
+
options.onReveal?.();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
61
69
|
}
|
|
62
70
|
catch (error) {
|
|
63
71
|
operation.cancel();
|
|
@@ -77,8 +85,10 @@ export class TableColumnAdd extends Plugin {
|
|
|
77
85
|
complete = true;
|
|
78
86
|
abort.abort();
|
|
79
87
|
reorder?.cancel();
|
|
80
|
-
if (
|
|
81
|
-
this.
|
|
88
|
+
if (!this.find(source.id)) {
|
|
89
|
+
this.pending.get(source.id)?.abort.abort();
|
|
90
|
+
this.pending.delete(source.id);
|
|
91
|
+
}
|
|
82
92
|
transaction?.cancel();
|
|
83
93
|
this.external = undefined;
|
|
84
94
|
this.refresh();
|
|
@@ -107,6 +117,12 @@ export class TableColumnAdd extends Plugin {
|
|
|
107
117
|
}
|
|
108
118
|
complete = true;
|
|
109
119
|
this.external = undefined;
|
|
120
|
+
if (!this.find(source.id)) {
|
|
121
|
+
this.pending.get(source.id)?.abort.abort();
|
|
122
|
+
this.pending.delete(source.id);
|
|
123
|
+
this.refresh();
|
|
124
|
+
return 'removed';
|
|
125
|
+
}
|
|
110
126
|
if (transaction)
|
|
111
127
|
transaction.commit();
|
|
112
128
|
else
|
|
@@ -125,9 +141,10 @@ export class TableColumnAdd extends Plugin {
|
|
|
125
141
|
enter(sample);
|
|
126
142
|
return operation;
|
|
127
143
|
}
|
|
128
|
-
create(source,
|
|
144
|
+
create(source, options = {}) {
|
|
129
145
|
if (this.disposed)
|
|
130
146
|
throw new Error('Column addition is disposed');
|
|
147
|
+
const hidden = options.hidden ?? false;
|
|
131
148
|
const pending = this.pending.get(source.id);
|
|
132
149
|
if (pending && pending.content.header.parentElement === this.headers())
|
|
133
150
|
return pending.transaction;
|
|
@@ -177,6 +194,12 @@ export class TableColumnAdd extends Plugin {
|
|
|
177
194
|
this.mark(entry, 'provisional', false);
|
|
178
195
|
if (!existing || (entry.content.header.cellIndex !== entry.initial))
|
|
179
196
|
this.notify(entry, 'committed');
|
|
197
|
+
if (!existing && entry.effects && options.effects !== 'deferred') {
|
|
198
|
+
entry.started = performance.now();
|
|
199
|
+
this.highlight(source.id, true);
|
|
200
|
+
if (entry.settled && this.isLastColumn(entry.content.header))
|
|
201
|
+
this.scrollToEnd();
|
|
202
|
+
}
|
|
180
203
|
if (existing || !source.load || (entry.settled && !entry.content.header.classList.contains('column-add-error')))
|
|
181
204
|
this.pending.delete(source.id);
|
|
182
205
|
return existing ? 'existing' : 'added';
|
|
@@ -190,7 +213,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
190
213
|
this.refresh();
|
|
191
214
|
}
|
|
192
215
|
};
|
|
193
|
-
const entry = { abort, content, initial: existing?.cellIndex ?? -1,
|
|
216
|
+
const entry = { abort, content, effects: options.effects !== false, initial: existing?.cellIndex ?? -1,
|
|
194
217
|
rows, settled: false, source, transaction };
|
|
195
218
|
this.pending.set(source.id, entry);
|
|
196
219
|
if (existing)
|
|
@@ -223,18 +246,33 @@ export class TableColumnAdd extends Plugin {
|
|
|
223
246
|
dispose() {
|
|
224
247
|
this.external?.cancel();
|
|
225
248
|
this.disposed = true;
|
|
249
|
+
if (this.scrollFrame !== undefined)
|
|
250
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
251
|
+
this.scrollFrame = undefined;
|
|
252
|
+
for (const removal of this.removals.values())
|
|
253
|
+
removal.abort.abort();
|
|
254
|
+
this.removals.clear();
|
|
226
255
|
for (const entry of [...this.pending.values()]) {
|
|
227
256
|
entry.transaction.cancel();
|
|
228
257
|
entry.abort.abort();
|
|
229
258
|
this.mark(entry, 'loading', false);
|
|
230
259
|
}
|
|
231
260
|
this.pending.clear();
|
|
232
|
-
for (const [cell,
|
|
233
|
-
clearTimeout(timer);
|
|
234
|
-
cell.classList.remove('column-add-highlight');
|
|
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
|
+
cell.style?.removeProperty(`--column-${name}`);
|
|
235
266
|
}
|
|
236
267
|
this.highlights.clear();
|
|
237
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
|
+
}
|
|
238
276
|
find(id) {
|
|
239
277
|
return Array.from(this.headers().cells).find(header => (this.identities.get(header) ?? this.options.identify(header)) === id);
|
|
240
278
|
}
|
|
@@ -244,22 +282,63 @@ export class TableColumnAdd extends Plugin {
|
|
|
244
282
|
throw new Error('Column addition requires one header row');
|
|
245
283
|
return row;
|
|
246
284
|
}
|
|
247
|
-
highlight(id) {
|
|
248
|
-
|
|
249
|
-
|
|
285
|
+
highlight(id, opening = false) {
|
|
286
|
+
this.highlightMany([id], opening);
|
|
287
|
+
}
|
|
288
|
+
highlightMany(ids, opening = false) {
|
|
289
|
+
if (this.disposed)
|
|
250
290
|
return;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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');
|
|
340
|
+
this.refresh();
|
|
341
|
+
}, 100);
|
|
263
342
|
}
|
|
264
343
|
}
|
|
265
344
|
init() {
|
|
@@ -270,6 +349,11 @@ export class TableColumnAdd extends Plugin {
|
|
|
270
349
|
this.reorder = reorder;
|
|
271
350
|
this.of.onReset.push(() => this.dispose());
|
|
272
351
|
}
|
|
352
|
+
isLastColumn(header) {
|
|
353
|
+
const freeze = this.of.plugins.TableFreeze;
|
|
354
|
+
const right = freeze instanceof TableFreeze ? freeze.rightColumnCount : 0;
|
|
355
|
+
return header.cellIndex === this.headers().cells.length - right - 1;
|
|
356
|
+
}
|
|
273
357
|
live(entry) {
|
|
274
358
|
return !this.disposed && !entry.abort.signal.aborted && (this.pending.get(entry.source.id) === entry)
|
|
275
359
|
&& entry.content.header.parentElement === this.headers();
|
|
@@ -289,20 +373,57 @@ export class TableColumnAdd extends Plugin {
|
|
|
289
373
|
throw new Error('Column row view changed during loading');
|
|
290
374
|
}
|
|
291
375
|
const old = entry.content;
|
|
292
|
-
|
|
293
|
-
|
|
376
|
+
const width = old.header.getBoundingClientRect?.().width ?? 0;
|
|
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);
|
|
396
|
+
}
|
|
294
397
|
this.reorder.replaceCell(old.header, content.header);
|
|
295
398
|
old.cells.forEach((cell, index) => this.reorder.replaceCell(cell, content.cells[index]));
|
|
296
399
|
entry.content = content;
|
|
297
400
|
this.identities.set(content.header, entry.source.id);
|
|
298
401
|
content.header.dataset.columnId = entry.source.id;
|
|
299
|
-
const highlighted = old.header.classList.contains('column-add-highlight');
|
|
300
402
|
this.mark(entry, 'provisional', entry.transaction.state === 'provisional');
|
|
301
403
|
this.mark(entry, 'loading', false);
|
|
302
404
|
this.refresh();
|
|
405
|
+
if (removing) {
|
|
406
|
+
this.measureColumn(content.header, width);
|
|
407
|
+
for (const cell of [content.header, ...content.cells])
|
|
408
|
+
cell.classList.add('column-remove-highlight');
|
|
409
|
+
}
|
|
410
|
+
else if (entry.effects && this.highlights.has(content.header) && !this.isLastColumn(content.header)) {
|
|
411
|
+
this.measureColumn(content.header);
|
|
412
|
+
for (const cell of [content.header, ...content.cells]) {
|
|
413
|
+
cell.style?.setProperty('--column-from', `${width}px`);
|
|
414
|
+
cell.classList.add('column-add-new', 'column-add-opening');
|
|
415
|
+
}
|
|
416
|
+
setTimeout(() => {
|
|
417
|
+
if (!this.disposed && content.header.isConnected) {
|
|
418
|
+
content.header.classList.remove('column-add-opening');
|
|
419
|
+
this.refresh();
|
|
420
|
+
}
|
|
421
|
+
}, 100);
|
|
422
|
+
}
|
|
423
|
+
if (!removing && entry.effects && entry.transaction.state === 'committed'
|
|
424
|
+
&& this.isLastColumn(content.header))
|
|
425
|
+
this.scrollToEnd();
|
|
303
426
|
this.notify(entry, 'loaded');
|
|
304
|
-
if (highlighted)
|
|
305
|
-
this.highlight(entry.source.id);
|
|
306
427
|
}
|
|
307
428
|
catch (error) {
|
|
308
429
|
if (!this.live(entry))
|
|
@@ -310,6 +431,13 @@ export class TableColumnAdd extends Plugin {
|
|
|
310
431
|
this.mark(entry, 'loading', false);
|
|
311
432
|
this.mark(entry, 'error', true);
|
|
312
433
|
this.notify(entry, 'error', error);
|
|
434
|
+
for (const cell of [entry.content.header, ...entry.content.cells]) {
|
|
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'])
|
|
438
|
+
cell.style?.removeProperty(`--column-${name}`);
|
|
439
|
+
}
|
|
440
|
+
this.refresh();
|
|
313
441
|
}
|
|
314
442
|
finally {
|
|
315
443
|
entry.settled = true;
|
|
@@ -325,6 +453,17 @@ export class TableColumnAdd extends Plugin {
|
|
|
325
453
|
present ? cell.setAttribute('aria-busy', 'true') : cell.removeAttribute('aria-busy');
|
|
326
454
|
}
|
|
327
455
|
}
|
|
456
|
+
measureColumn(header, width) {
|
|
457
|
+
if (!header.ownerDocument)
|
|
458
|
+
return;
|
|
459
|
+
width ??= Math.max(header.getBoundingClientRect().width, parseFloat(header.style.getPropertyValue('--column-width')) || 0);
|
|
460
|
+
const cells = Array.from(this.of.element.rows).map(row => row.cells[header.cellIndex]);
|
|
461
|
+
const heights = cells.map(cell => cell.getBoundingClientRect().height);
|
|
462
|
+
cells.forEach((cell, index) => {
|
|
463
|
+
cell.style.setProperty('--column-width', `${width}px`);
|
|
464
|
+
cell.style.setProperty('--column-height', `${heights[index]}px`);
|
|
465
|
+
});
|
|
466
|
+
}
|
|
328
467
|
notify(entry, state, error) {
|
|
329
468
|
this.options.onChange?.({ error, header: entry.content.header, id: entry.source.id, state });
|
|
330
469
|
}
|
|
@@ -334,6 +473,89 @@ export class TableColumnAdd extends Plugin {
|
|
|
334
473
|
freeze.refresh();
|
|
335
474
|
this.of.refreshStyleSheets();
|
|
336
475
|
}
|
|
476
|
+
/** Reveal and briefly mark a column in red before removing it. */
|
|
477
|
+
remove(id, signal) {
|
|
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)))
|
|
489
|
+
return Promise.resolve(false);
|
|
490
|
+
if (this.external || names.some(id => this.removals.has(id)
|
|
491
|
+
|| this.pending.get(id)?.transaction.state === 'provisional'))
|
|
492
|
+
return Promise.reject(new Error('A column interaction is active'));
|
|
493
|
+
const abort = new AbortController();
|
|
494
|
+
const cancelled = AbortSignal.any([abort.signal, ...(signal ? [signal] : [])]);
|
|
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);
|
|
500
|
+
});
|
|
501
|
+
for (const id of names)
|
|
502
|
+
this.removals.set(id, { abort, promise });
|
|
503
|
+
return promise;
|
|
504
|
+
}
|
|
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
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
await new Promise(resolve => {
|
|
526
|
+
const finish = () => {
|
|
527
|
+
clearTimeout(timer);
|
|
528
|
+
signal.removeEventListener('abort', finish);
|
|
529
|
+
resolve();
|
|
530
|
+
};
|
|
531
|
+
const timer = setTimeout(finish, 300);
|
|
532
|
+
signal.addEventListener('abort', finish, { once: true });
|
|
533
|
+
});
|
|
534
|
+
if (this.disposed || signal.aborted || ids.some(id => !this.find(id)))
|
|
535
|
+
return false;
|
|
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
|
+
}
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
finally {
|
|
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
|
+
}
|
|
555
|
+
}
|
|
556
|
+
this.refresh();
|
|
557
|
+
}
|
|
558
|
+
}
|
|
337
559
|
reveal(id) {
|
|
338
560
|
const header = this.find(id);
|
|
339
561
|
if (!header || this.disposed)
|
|
@@ -355,6 +577,33 @@ export class TableColumnAdd extends Plugin {
|
|
|
355
577
|
else if ((rect.right > right) && (rect.left > left))
|
|
356
578
|
scroll.scrollLeft += Math.min(rect.right - right, rect.left - left);
|
|
357
579
|
}
|
|
580
|
+
scrollToEnd() {
|
|
581
|
+
if (this.scrollFrame !== undefined)
|
|
582
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
583
|
+
this.scrollFrame = undefined;
|
|
584
|
+
const scroll = this.reorder.scrollContainer();
|
|
585
|
+
if (!scroll || this.disposed)
|
|
586
|
+
return;
|
|
587
|
+
const from = scroll.scrollLeft;
|
|
588
|
+
const to = Math.max(from, scroll.scrollWidth - scroll.clientWidth);
|
|
589
|
+
if (to <= from)
|
|
590
|
+
return;
|
|
591
|
+
if (scroll.ownerDocument?.defaultView?.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
592
|
+
scroll.scrollLeft = to;
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const started = performance.now();
|
|
596
|
+
const step = (time) => {
|
|
597
|
+
this.scrollFrame = undefined;
|
|
598
|
+
if (this.disposed)
|
|
599
|
+
return;
|
|
600
|
+
const progress = Math.min(1, Math.max(0, (time - started) / 100));
|
|
601
|
+
scroll.scrollLeft = from + (to - from) * (1 - (1 - progress) ** 2);
|
|
602
|
+
if (progress < 1)
|
|
603
|
+
this.scrollFrame = requestAnimationFrame(step);
|
|
604
|
+
};
|
|
605
|
+
this.scrollFrame = requestAnimationFrame(step);
|
|
606
|
+
}
|
|
358
607
|
retry(id) {
|
|
359
608
|
const entry = this.pending.get(id);
|
|
360
609
|
if (!entry || !this.live(entry) || !entry.content.header.classList.contains('column-add-error'))
|
package/column-reorder.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Plugin } from '../plugin/plugin.js';
|
|
2
2
|
import { PluginOptions } from '../plugin/plugin.js';
|
|
3
3
|
import { Table } from './table.js';
|
|
4
|
+
export type ColumnDragOptions = {
|
|
5
|
+
adding?: boolean;
|
|
6
|
+
onReveal?(): void;
|
|
7
|
+
removal?: boolean;
|
|
8
|
+
};
|
|
4
9
|
export type PointerSample = {
|
|
5
10
|
pointerId: number;
|
|
6
11
|
pointerType: string;
|
|
@@ -15,14 +20,17 @@ export interface ExternalColumnOperation {
|
|
|
15
20
|
}
|
|
16
21
|
type Direction = -1 | 0 | 1;
|
|
17
22
|
interface Drag extends Press {
|
|
18
|
-
|
|
23
|
+
adding: boolean;
|
|
19
24
|
cells: HTMLTableCellElement[];
|
|
20
25
|
col?: HTMLTableColElement;
|
|
21
26
|
direction: Direction;
|
|
27
|
+
external: boolean;
|
|
22
28
|
index: number;
|
|
23
29
|
initial: number;
|
|
24
30
|
maximum: number;
|
|
25
31
|
minimum: number;
|
|
32
|
+
onReveal?: () => void;
|
|
33
|
+
removal: boolean;
|
|
26
34
|
remove: boolean;
|
|
27
35
|
rows: HTMLTableRowElement[];
|
|
28
36
|
scroll?: HTMLElement;
|
|
@@ -43,10 +51,12 @@ export declare class TableColumnReorder extends Plugin<Table, TableColumnReorder
|
|
|
43
51
|
protected suppressClick: boolean;
|
|
44
52
|
protected animate(time: number): void;
|
|
45
53
|
/** The source owns pointer capture; this operation owns target geometry and rollback. */
|
|
46
|
-
beginExternal(header: HTMLTableCellElement, sample: PointerSample): ExternalColumnOperation;
|
|
54
|
+
beginExternal(header: HTMLTableCellElement, sample: PointerSample, options?: ColumnDragOptions): ExternalColumnOperation;
|
|
47
55
|
defaultOptions(): TableColumnReorderOptions;
|
|
48
56
|
/** Move a column inside its existing reorderable boundaries, without committing a header gesture. */
|
|
49
57
|
moveColumn(header: HTMLTableCellElement, targetIndex: number): void;
|
|
58
|
+
/** Remove a reorderable column without committing a header gesture or invoking its callbacks. */
|
|
59
|
+
removeColumn(header: HTMLTableCellElement): boolean;
|
|
50
60
|
/** Retain the active gesture when asynchronous rendering replaces one of its cells. */
|
|
51
61
|
replaceCell(previous: HTMLTableCellElement, replacement: HTMLTableCellElement): void;
|
|
52
62
|
protected finish(commit: boolean): void;
|
|
@@ -58,7 +68,7 @@ export declare class TableColumnReorder extends Plugin<Table, TableColumnReorder
|
|
|
58
68
|
protected rows(): HTMLTableRowElement[];
|
|
59
69
|
protected scroll(drag: Drag, time: number): Direction;
|
|
60
70
|
scrollContainer(): HTMLElement | undefined;
|
|
61
|
-
protected start(press: Press, x: number, y: number, external?: boolean): void;
|
|
71
|
+
protected start(press: Press, x: number, y: number, external?: boolean, options?: ColumnDragOptions): void;
|
|
62
72
|
protected target(drag: Drag, direction: Direction): number;
|
|
63
73
|
protected triggerRow(): HTMLTableRowElement;
|
|
64
74
|
protected bounds(drag: Drag): {
|
package/column-reorder.js
CHANGED
|
@@ -3,7 +3,6 @@ import { PluginOptions } from '../plugin/plugin.js';
|
|
|
3
3
|
let activeDrag;
|
|
4
4
|
const clamp = (value) => Math.max(0, Math.min(1, value));
|
|
5
5
|
const maxScrollSpeed = 800;
|
|
6
|
-
const penetration = 10;
|
|
7
6
|
const scrollZone = 50;
|
|
8
7
|
export class TableColumnReorder extends Plugin {
|
|
9
8
|
drag;
|
|
@@ -14,21 +13,23 @@ export class TableColumnReorder extends Plugin {
|
|
|
14
13
|
this.frame = undefined;
|
|
15
14
|
const drag = this.drag;
|
|
16
15
|
this.updateState(drag);
|
|
16
|
+
if (drag.header.hidden)
|
|
17
|
+
return;
|
|
17
18
|
const pointerDirection = drag.direction;
|
|
18
19
|
drag.direction = 0;
|
|
19
20
|
const scrollDirection = this.scroll(drag, time);
|
|
20
21
|
if (scrollDirection)
|
|
21
22
|
this.requestFrame();
|
|
22
23
|
const direction = pointerDirection || scrollDirection;
|
|
23
|
-
const target =
|
|
24
|
+
const target = this.target(drag, direction);
|
|
24
25
|
if (target !== drag.index)
|
|
25
26
|
this.move(drag, target);
|
|
26
27
|
}
|
|
27
28
|
/** The source owns pointer capture; this operation owns target geometry and rollback. */
|
|
28
|
-
beginExternal(header, sample) {
|
|
29
|
+
beginExternal(header, sample, options = {}) {
|
|
29
30
|
if (activeDrag || this.press)
|
|
30
31
|
throw new Error('A column interaction is active');
|
|
31
|
-
this.start({ header, id: sample.pointerId, origin: header.getBoundingClientRect().left, y: sample.clientY }, sample.clientX, sample.clientY, true);
|
|
32
|
+
this.start({ header, id: sample.pointerId, origin: header.getBoundingClientRect().left, y: sample.clientY }, sample.clientX, sample.clientY, true, options);
|
|
32
33
|
const drag = this.drag;
|
|
33
34
|
if (!drag)
|
|
34
35
|
throw new Error('Column cannot be reordered');
|
|
@@ -51,7 +52,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
51
52
|
cancelAnimationFrame(this.frame);
|
|
52
53
|
this.frame = undefined;
|
|
53
54
|
held = true;
|
|
54
|
-
return !drag.remove && this.of.element.isConnected;
|
|
55
|
+
return (options.removal || !drag.remove) && this.of.element.isConnected;
|
|
55
56
|
};
|
|
56
57
|
return {
|
|
57
58
|
cancel: () => { if (live())
|
|
@@ -87,6 +88,19 @@ export class TableColumnReorder extends Plugin {
|
|
|
87
88
|
minimum--;
|
|
88
89
|
this.moveCells(index, Math.max(minimum, Math.min(maximum, Math.trunc(targetIndex))));
|
|
89
90
|
}
|
|
91
|
+
/** Remove a reorderable column without committing a header gesture or invoking its callbacks. */
|
|
92
|
+
removeColumn(header) {
|
|
93
|
+
if (this.drag || this.press)
|
|
94
|
+
throw new Error('A header interaction is active');
|
|
95
|
+
if (header.parentElement !== this.triggerRow() || !(this.options.isReorderable?.(header) ?? true))
|
|
96
|
+
return false;
|
|
97
|
+
const index = header.cellIndex;
|
|
98
|
+
const column = this.of.element.querySelectorAll(':scope > colgroup > col')[index];
|
|
99
|
+
for (const row of this.rows())
|
|
100
|
+
row.cells[index]?.remove();
|
|
101
|
+
column?.remove();
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
90
104
|
/** Retain the active gesture when asynchronous rendering replaces one of its cells. */
|
|
91
105
|
replaceCell(previous, replacement) {
|
|
92
106
|
if (this.press?.header === previous)
|
|
@@ -95,7 +109,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
95
109
|
if (this.drag.header === previous)
|
|
96
110
|
this.drag.header = replacement;
|
|
97
111
|
this.drag.cells = this.drag.cells.map(cell => cell === previous ? replacement : cell);
|
|
98
|
-
for (const name of ['column-reorder', 'moving', 'removing']) {
|
|
112
|
+
for (const name of ['adding', 'column-reorder', 'moving', 'removing']) {
|
|
99
113
|
if (previous.classList.contains(name))
|
|
100
114
|
replacement.classList.add(name);
|
|
101
115
|
}
|
|
@@ -114,7 +128,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
114
128
|
const changed = drag.index !== drag.initial;
|
|
115
129
|
if (!commit && changed)
|
|
116
130
|
this.move(drag, drag.initial);
|
|
117
|
-
const removed = commit && drag.remove &&
|
|
131
|
+
const removed = (commit && drag.remove) || (!commit && drag.adding);
|
|
118
132
|
if (removed) {
|
|
119
133
|
for (const row of this.rows()) {
|
|
120
134
|
row.cells[drag.index]?.remove();
|
|
@@ -122,7 +136,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
122
136
|
drag.col?.remove();
|
|
123
137
|
}
|
|
124
138
|
for (const cell of drag.cells) {
|
|
125
|
-
cell.classList.remove('column-reorder', 'moving', 'removing');
|
|
139
|
+
cell.classList.remove('adding', 'column-reorder', 'moving', 'removing');
|
|
126
140
|
}
|
|
127
141
|
document.documentElement.classList.remove('column-reorder');
|
|
128
142
|
activeDrag = undefined;
|
|
@@ -279,14 +293,13 @@ export class TableColumnReorder extends Plugin {
|
|
|
279
293
|
}
|
|
280
294
|
return undefined;
|
|
281
295
|
}
|
|
282
|
-
start(press, x, y, external = false) {
|
|
296
|
+
start(press, x, y, external = false, options = {}) {
|
|
283
297
|
if (activeDrag)
|
|
284
298
|
return;
|
|
285
299
|
const headers = Array.from(this.triggerRow().cells);
|
|
286
300
|
const initial = headers.indexOf(press.header);
|
|
287
301
|
const rows = this.rows();
|
|
288
302
|
const columns = this.of.element.querySelectorAll(':scope > colgroup > col');
|
|
289
|
-
const source = press.header.getBoundingClientRect();
|
|
290
303
|
const reorderable = headers.map(header => (external || !header.classList.contains('column-add-provisional'))
|
|
291
304
|
&& (this.options.isReorderable?.(header) ?? true));
|
|
292
305
|
if (!reorderable[initial])
|
|
@@ -301,11 +314,13 @@ export class TableColumnReorder extends Plugin {
|
|
|
301
314
|
this.of.element.setPointerCapture(press.id);
|
|
302
315
|
const drag = {
|
|
303
316
|
...press,
|
|
317
|
+
adding: options.adding ?? false,
|
|
318
|
+
onReveal: options.onReveal,
|
|
319
|
+
removal: options.removal ?? !external,
|
|
304
320
|
external,
|
|
305
321
|
cells: rows.map(row => row.cells[initial]),
|
|
306
322
|
col: columns[initial],
|
|
307
|
-
direction:
|
|
308
|
-
: Math.sign(x - press.origin),
|
|
323
|
+
direction: Math.sign(x - press.origin),
|
|
309
324
|
index: initial,
|
|
310
325
|
initial,
|
|
311
326
|
maximum,
|
|
@@ -327,16 +342,20 @@ export class TableColumnReorder extends Plugin {
|
|
|
327
342
|
this.requestFrame();
|
|
328
343
|
}
|
|
329
344
|
target(drag, direction) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
345
|
+
if (!direction)
|
|
346
|
+
return drag.index;
|
|
347
|
+
const headers = Array.from(this.triggerRow().cells);
|
|
348
|
+
const hovered = headers.slice(drag.minimum, drag.maximum + 1)
|
|
349
|
+
.find(header => drag.x < header.getBoundingClientRect().right) ?? headers[drag.maximum];
|
|
350
|
+
if (hovered === drag.header)
|
|
351
|
+
return drag.index;
|
|
352
|
+
let index = headers.indexOf(hovered);
|
|
353
|
+
// Removing the source shifts the hovered column's index when it was to its right.
|
|
354
|
+
if (drag.index < index)
|
|
355
|
+
index--;
|
|
356
|
+
if (direction > 0)
|
|
357
|
+
index++;
|
|
358
|
+
return index;
|
|
340
359
|
}
|
|
341
360
|
triggerRow() {
|
|
342
361
|
return this.of.element.tHead?.rows[0] ?? this.of.element.tBodies[0]?.rows[0];
|
|
@@ -344,8 +363,8 @@ export class TableColumnReorder extends Plugin {
|
|
|
344
363
|
bounds(drag) {
|
|
345
364
|
const rect = this.of.element.getBoundingClientRect();
|
|
346
365
|
const headers = this.triggerRow().cells;
|
|
347
|
-
const first = headers[drag.minimum].getBoundingClientRect();
|
|
348
|
-
const last = headers[drag.maximum].getBoundingClientRect();
|
|
366
|
+
const first = drag.header.hidden ? rect : headers[drag.minimum].getBoundingClientRect();
|
|
367
|
+
const last = drag.header.hidden ? rect : headers[drag.maximum].getBoundingClientRect();
|
|
349
368
|
const viewport = drag.external ? drag.scroll?.getBoundingClientRect() : undefined;
|
|
350
369
|
return {
|
|
351
370
|
left: Math.max(rect.left, first.left, headers[drag.minimum - 1]?.getBoundingClientRect().right ?? rect.left, viewport?.left ?? rect.left),
|
|
@@ -355,13 +374,25 @@ export class TableColumnReorder extends Plugin {
|
|
|
355
374
|
};
|
|
356
375
|
}
|
|
357
376
|
updateState(drag) {
|
|
377
|
+
if (drag.header.hidden) {
|
|
378
|
+
const table = this.of.element;
|
|
379
|
+
if (table.contains(table.ownerDocument.elementFromPoint(drag.x, drag.y))) {
|
|
380
|
+
for (const cell of drag.cells)
|
|
381
|
+
cell.hidden = false;
|
|
382
|
+
if (drag.col)
|
|
383
|
+
drag.col.hidden = false;
|
|
384
|
+
drag.onReveal?.();
|
|
385
|
+
drag.scroll = this.scrollContainer();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
358
388
|
if (this.options.onRemove || drag.external) {
|
|
359
389
|
const rect = this.bounds(drag);
|
|
360
390
|
drag.remove = (drag.x < rect.left) || (drag.x > rect.right) || (drag.y < rect.top) || (drag.y > rect.bottom);
|
|
361
391
|
}
|
|
362
392
|
for (const cell of drag.cells) {
|
|
363
|
-
cell.classList.toggle('
|
|
364
|
-
cell.classList.toggle('
|
|
393
|
+
cell.classList.toggle('adding', drag.adding && !drag.remove);
|
|
394
|
+
cell.classList.toggle('removing', drag.remove && drag.removal);
|
|
395
|
+
cell.classList.toggle('moving', !drag.adding && !drag.remove && (drag.index !== drag.initial)
|
|
365
396
|
&& !drag.header.classList.contains('column-add-provisional'));
|
|
366
397
|
}
|
|
367
398
|
}
|
|
@@ -369,9 +400,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
369
400
|
const drag = this.drag;
|
|
370
401
|
if ((x === drag.x) && (y === drag.y))
|
|
371
402
|
return;
|
|
372
|
-
|
|
373
|
-
drag.direction = source ? (x === drag.x ? 0 : x < source.left ? -1 : x > source.right ? 1 : 0)
|
|
374
|
-
: Math.sign(x - drag.x);
|
|
403
|
+
drag.direction = Math.sign(x - drag.x);
|
|
375
404
|
drag.x = x;
|
|
376
405
|
drag.y = y;
|
|
377
406
|
this.updateState(drag);
|
package/package.json
CHANGED