@itrocks/table 0.4.3 → 0.7.3

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 CHANGED
@@ -263,22 +263,42 @@ 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. It resolves
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 900 ms,
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
+ - Columns appended at the right edge (before any right-frozen columns) appear at full width immediately, with their
273
+ heading, filter and placeholder cells visible in green. Loaded values appear immediately and scroll the table to its
274
+ right edge over 100 ms if needed. Reduced motion makes this scroll immediate.
275
+ - Columns inserted between existing columns open from zero to their measured width over 100 ms.
276
+ The flash stays green until values arrive, then
277
+ fades over the remainder of 350 ms from opening, with a minimum fade of 100 ms. Content remains hidden until the
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.
281
+ - `remove(id, signal?): Promise<boolean>` reveals a column, shrinks it over 100 ms during a 300 ms red flash,
282
+ hiding cell content immediately, then removes the header, body/footer cells and matching `col`. It returns false for
283
+ a missing column or cancellation. Repeated calls share the pending removal; abort, disposal and reset clear the flash
284
+ without deletion. Late values cannot restore a removed column. Cancellation restores the natural width.
285
+ Reduced motion skips width animation and uses a static red outline.
286
+ The host persists the resulting configuration.
272
287
  - `retry(id): Promise<void>` retries a failed value callback. Failure retains the committed column and marks it with
273
- `.column-add-error`; the consumer presents the error and a retry control. It never confirms another addition.
274
- - `begin(source): ColumnTransaction` creates a real provisional column without committing it. Its `ready` promise waits
275
- for optional values and resolves after error notification as well. `moveTo(index)` reuses public reorder placement
288
+ `.column-add-error`; data cells receive a discreet red background and the addition flash stops.
289
+ It never confirms another addition. The plugin adds no error text, retry control or automatic retry.
290
+ - `begin(source, options?): ColumnTransaction` creates a real provisional column without committing it.
291
+ Its `ready` promise waits for optional values and resolves after error notification as well. `moveTo(index)` reuses public reorder placement
276
292
  and its existing boundaries. `commit()` validates it and returns `added` or `existing`; repeating commit returns
277
293
  `existing`. `cancel()` aborts values, removes new provisional cells or restores an existing column's position.
278
294
  Completed/cancelled handles cannot move a column. `begin()` itself installs no pointer transport.
279
295
  - `dispose(): void` cancels provisional operations, aborts outstanding values and removes flash resources. Committed
280
296
  columns remain. `Table.reset()` invokes disposal automatically; call disposal when removing the owning view.
281
297
 
298
+ `ColumnCreationOptions` is shared by `add` and `begin`. `hidden: true` inserts hidden cells and a hidden `col`;
299
+ loaded replacements retain that visibility. `effects: false` skips width animation, flash and automatic scroll for both
300
+ creation and loaded values. Loading still starts immediately. Pass both options to prepare a column for pointer entry.
301
+
282
302
  `TableColumnAddOptions.identify(header)` defaults to `header.dataset.columnId`. Added and loaded headers carry this
283
303
  opaque attribute so identity survives plugin resets. A custom callback can identify pre-existing columns differently.
284
304
  `onChange(change)` runs synchronously for `provisional`, `committed`, `loaded`, `error` and `cancelled` observations;
@@ -288,10 +308,17 @@ An aborted or removed operation cannot be recreated by late values.
288
308
 
289
309
  `TableColumnReorder.moveColumn(header, index)` is public placement without header gesture callbacks. It rejects an
290
310
  active header interaction and clamps movement to that header's reorderable boundaries.
311
+ `TableColumnReorder.removeColumn(header): boolean` removes a reorderable column and its `col` without header callbacks.
312
+ It rejects an active header interaction and returns false for a missing or fixed column.
291
313
  `TableColumnReorder.replaceCell(previous, replacement)`
292
314
  preserves an active header gesture during asynchronous cell replacement. `TableFreeze.refresh()` recalculates sticky
293
315
  offsets after structural changes. `Table.refreshStyleSheets()` reapplies the managed styles.
294
316
 
317
+ Internal and external drags share one placement rule. Hovering the source column leaves its position unchanged.
318
+ Over another column, moving left places the source before it; moving right places the source after it.
319
+ Placement uses the current pointer or automatic scrolling direction, without retaining the previous hovered column.
320
+ Cells and the corresponding `<col>` are moved only when the resulting index changes.
321
+
295
322
  `TableColumnReorder.scrollContainer()` exposes the existing horizontal scroll owner for table plugins.
296
323
  `TableFreeze.visibleInnerRect()` returns the area between rendered sticky cells, including tables configured through
297
324
  `colgroup`. `reveal()` fully exposes columns that fit that area and uses its maximum width for wider columns, with
@@ -300,10 +327,10 @@ including header-backed tables after addition, asynchronous replacement or reset
300
327
 
301
328
  ### External pointer transport
302
329
 
303
- `beginExternal(source, sample): ColumnOperation` immediately creates a hidden provisional column and starts loading
304
- its values. The cells and optional `col` stay hidden until the pointer first enters the visible table; loaded replacements
330
+ `beginExternal(source, sample, options?): ColumnOperation` immediately creates a hidden provisional column and starts
331
+ loading its values. The cells and optional `col` stay hidden until the pointer first enters the visible table; loaded replacements
305
332
  preserve that visibility. On entry, the column appears with any values already received and starts following reorder
306
- geometry. Reusing an existing id keeps its column visible throughout the gesture.
333
+ geometry. Reusing an existing id preserves its visibility, including a committed hidden column prepared with `begin`.
307
334
  The structural `PointerSample` contains `pointerId`, `pointerType`, `clientX` and `clientY`. The source owns capture.
308
335
  `move(sample)` uses the existing reorder engine, including frozen boundaries and visible-edge autoscroll.
309
336
  `finish(sample)` resolves to `added`, `moved` or `cancelled`; an outside drop cancels without a fallback insertion.
@@ -315,9 +342,17 @@ Optional `ColumnSource.accept(signal)` validates host admission independently of
315
342
  waiting for `load`. Rejection rolls back and rejects `finish`. An omitted callback accepts immediately. Value errors
316
343
  remain retryable and do not reject a valid drop. The host must keep admission independent of its data request.
317
344
 
318
- `TableColumnReorder.beginExternal(header, sample): ExternalColumnOperation` is the lower-level public extension for
319
- an already attached column. Its `move`, `hold`, `finish` and `cancel` methods share header-origin geometry and
345
+ `TableColumnReorder.beginExternal(header, sample, options?): ExternalColumnOperation` is the lower-level public
346
+ extension for an already attached column. Its `move`, `hold`, `finish` and `cancel` methods share header-origin geometry and
320
347
  placement.
321
348
  `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. It never calls header reorder/removal notifications;
349
+ `finish(sample)` releases the gesture and returns acceptance. External reordering leaves persistence to its owner;
323
350
  the owning addition transaction emits its distinct commit notification. Header-origin gestures retain their callbacks.
351
+
352
+ Both external entry points accept `ColumnDragOptions`. `adding: true` applies `.adding` for a green addition indicator
353
+ instead of `.moving`, and removes the newly created column on cancellation. `removal: true` enables the standard
354
+ header-origin removal on an outside drop, including a hidden column that never entered the table. Removal invokes
355
+ `onRemove` once; the higher-level operation resolves to `removed`. The defaults preserve preview cancellation.
356
+ Hidden cells and their `col` become visible on first pointer entry, without an opening animation or automatic reveal
357
+ scroll. `onReveal()` observes this transition; the addition wrapper also refreshes frozen geometry. Replacement cells
358
+ preserve hidden state and active indicators while values load.
package/column-add.css CHANGED
@@ -1,10 +1,44 @@
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 850ms ease-out;
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);
13
+ }
14
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-opening::after {
15
+ animation: itrocks-column-open 100ms ease-out both;
16
+ }
17
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
18
+ animation: itrocks-column-remove-flash 300ms ease-out;
19
+ }
20
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::after {
21
+ animation: itrocks-column-close 100ms ease-out both;
22
+ }
23
+ 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) {
24
+ box-sizing: border-box;
25
+ font-size: 0 !important;
26
+ height: var(--column-height);
27
+ overflow: hidden;
28
+ padding: 0 !important;
29
+ }
30
+ 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) > * {
31
+ display: none !important;
32
+ }
33
+ 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 {
34
+ content: none !important;
35
+ }
36
+ 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 {
37
+ content: " " !important;
38
+ display: block;
39
+ font-size: 1px;
40
+ line-height: 1px;
41
+ width: var(--column-width);
8
42
  }
9
43
  table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-loading {
10
44
  cursor: progress;
@@ -12,11 +46,26 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-loading {
12
46
  table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-provisional {
13
47
  background-color: color-mix(in srgb, #58b46b 5%, Canvas);
14
48
  }
15
- table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error {
16
- outline: 1px solid #c33;
17
- outline-offset: -2px;
49
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error:is(td, tbody th, tfoot th) {
50
+ background-color: color-mix(in srgb, #d33 12%, Canvas);
18
51
  }
19
52
 
53
+ @keyframes itrocks-column-open {
54
+ from {
55
+ width: var(--column-from, 0px);
56
+ }
57
+ to {
58
+ width: var(--column-width);
59
+ }
60
+ }
61
+ @keyframes itrocks-column-close {
62
+ from {
63
+ width: var(--column-width);
64
+ }
65
+ to {
66
+ width: 0;
67
+ }
68
+ }
20
69
  @keyframes itrocks-column-add-flash {
21
70
  0% {
22
71
  background-color: color-mix(in srgb, #58b46b 35%, Canvas);
@@ -25,9 +74,29 @@ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-error {
25
74
  background-color: color-mix(in srgb, white 20%, Canvas);
26
75
  }
27
76
  }
77
+ @keyframes itrocks-column-remove-flash {
78
+ 0% {
79
+ background-color: color-mix(in srgb, #d33 50%, Canvas);
80
+ }
81
+ }
28
82
  @media (prefers-reduced-motion: reduce) {
29
- table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-highlight {
83
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
30
84
  animation: none;
85
+ }
86
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight::after {
87
+ animation: none;
88
+ }
89
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-remove-highlight {
90
+ outline: 2px solid #c33;
91
+ outline-offset: -2px;
92
+ }
93
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening) {
94
+ animation: none;
95
+ }
96
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening)::after {
97
+ animation: none;
98
+ }
99
+ table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td):is(.column-add-highlight, .column-add-opening) {
31
100
  outline: 2px solid color-mix(in srgb, #58b46b 65%, Canvas);
32
101
  outline-offset: -2px;
33
102
  }
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;
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';
@@ -39,37 +44,50 @@ interface Pending {
39
44
  abort: AbortController;
40
45
  col?: HTMLTableColElement;
41
46
  content: ColumnContent;
47
+ effects: boolean;
42
48
  initial: number;
43
49
  rows: HTMLTableRowElement[];
44
50
  settled: boolean;
45
51
  source: ColumnSource;
52
+ started?: number;
46
53
  transaction: ColumnTransaction;
47
54
  }
48
55
  export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions> {
49
56
  protected disposed: boolean;
50
57
  protected external?: ColumnOperation;
51
- protected highlights: Map<HTMLTableCellElement, number>;
58
+ protected highlights: Map<HTMLTableCellElement, number | undefined>;
52
59
  protected identities: WeakMap<HTMLTableCellElement, string>;
53
60
  protected pending: Map<string, Pending>;
61
+ protected removals: Map<string, {
62
+ abort: AbortController;
63
+ promise: Promise<boolean>;
64
+ }>;
54
65
  protected reorder: TableColumnReorder;
55
- add(source: ColumnSource): Promise<ColumnResult>;
66
+ protected scrollFrame?: number;
67
+ add(source: ColumnSource, options?: ColumnCreationOptions): Promise<ColumnResult>;
56
68
  /** Create a provisional column without installing pointer transport. */
57
- begin(source: ColumnSource): ColumnTransaction;
69
+ begin(source: ColumnSource, options?: ColumnCreationOptions): ColumnTransaction;
58
70
  /** Add or move an opaque column through the existing reorder geometry. */
59
- beginExternal(source: ColumnSource, sample: PointerSample): ColumnOperation;
60
- protected create(source: ColumnSource, hidden?: boolean): ColumnTransaction;
71
+ beginExternal(source: ColumnSource, sample: PointerSample, options?: ColumnDragOptions): ColumnOperation;
72
+ protected create(source: ColumnSource, options?: ColumnCreationOptions): ColumnTransaction;
61
73
  defaultOptions(): TableColumnAddOptions;
62
74
  dispose(): void;
63
75
  protected find(id: string): HTMLTableCellElement | undefined;
64
76
  protected headers(): HTMLTableRowElement;
65
- highlight(id: string): void;
77
+ highlight(id: string, opening?: boolean): void;
66
78
  init(): void;
79
+ protected isLastColumn(header: HTMLTableCellElement): boolean;
67
80
  protected live(entry: Pending): boolean;
68
81
  protected load(entry: Pending): Promise<void>;
69
82
  protected mark(entry: Pending, state: 'error' | 'loading' | 'provisional', present: boolean): void;
83
+ protected measureColumn(header: HTMLTableCellElement, width?: number): void;
70
84
  protected notify(entry: Pending, state: ColumnState, error?: unknown): void;
71
85
  protected refresh(): void;
86
+ /** Reveal and briefly mark a column in red before removing it. */
87
+ remove(id: string, signal?: AbortSignal): Promise<boolean>;
88
+ protected removeColumn(id: string, signal: AbortSignal): Promise<boolean>;
72
89
  reveal(id: string): void;
90
+ protected scrollToEnd(): void;
73
91
  retry(id: string): Promise<void>;
74
92
  protected validate(content: ColumnContent, rows: HTMLTableRowElement[]): void;
75
93
  }
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
- add(source) {
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
- this.reveal(source.id);
18
- this.highlight(source.id);
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
- this.reveal(source.id);
24
- this.highlight(source.id);
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 initial = existing?.cellIndex;
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 (initial !== undefined)
81
- this.reorder.moveColumn(this.find(source.id), initial);
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, hidden = false) {
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) {
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 ?? true, initial: existing?.cellIndex ?? -1,
194
217
  rows, settled: false, source, transaction };
195
218
  this.pending.set(source.id, entry);
196
219
  if (existing)
@@ -223,6 +246,12 @@ 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();
@@ -231,7 +260,9 @@ export class TableColumnAdd extends Plugin {
231
260
  this.pending.clear();
232
261
  for (const [cell, timer] of this.highlights) {
233
262
  clearTimeout(timer);
234
- cell.classList.remove('column-add-highlight');
263
+ cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
264
+ for (const name of ['fade', 'from', 'height', 'width'])
265
+ cell.style?.removeProperty(`--column-${name}`);
235
266
  }
236
267
  this.highlights.clear();
237
268
  }
@@ -244,23 +275,47 @@ export class TableColumnAdd extends Plugin {
244
275
  throw new Error('Column addition requires one header row');
245
276
  return row;
246
277
  }
247
- highlight(id) {
278
+ highlight(id, opening = false) {
248
279
  const header = this.find(id);
249
280
  if (!header || this.disposed)
250
281
  return;
282
+ const started = opening ? this.pending.get(id)?.started : undefined;
283
+ const duration = started === undefined ? 350 : Math.max(100, 350 - (performance.now() - started));
284
+ const waiting = opening && header.classList.contains('column-add-loading');
285
+ const expanding = opening && !this.isLastColumn(header);
251
286
  for (const row of Array.from(this.of.element.rows)) {
252
287
  const cell = row.cells[header.cellIndex];
253
288
  if (!cell)
254
289
  continue;
255
290
  clearTimeout(this.highlights.get(cell));
256
- cell.classList.remove('column-add-highlight');
257
- void cell.offsetWidth;
291
+ cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
292
+ }
293
+ this.measureColumn(header);
294
+ void header.offsetWidth;
295
+ for (const row of Array.from(this.of.element.rows)) {
296
+ const cell = row.cells[header.cellIndex];
297
+ if (!cell)
298
+ continue;
299
+ cell.classList.toggle('column-add-new', expanding);
300
+ cell.classList.toggle('column-add-opening', expanding);
258
301
  cell.classList.add('column-add-highlight');
259
- this.highlights.set(cell, setTimeout(() => {
260
- cell.classList.remove('column-add-highlight');
302
+ cell.style?.setProperty('--column-fade', `${duration}ms`);
303
+ this.highlights.set(cell, waiting ? undefined : setTimeout(() => {
304
+ cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
261
305
  this.highlights.delete(cell);
262
- }, 900));
306
+ for (const name of ['fade', 'from', 'height', 'width'])
307
+ cell.style?.removeProperty(`--column-${name}`);
308
+ if (!this.highlights.size)
309
+ this.refresh();
310
+ }, duration));
263
311
  }
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);
264
319
  }
265
320
  init() {
266
321
  this.disposed = false;
@@ -270,6 +325,11 @@ export class TableColumnAdd extends Plugin {
270
325
  this.reorder = reorder;
271
326
  this.of.onReset.push(() => this.dispose());
272
327
  }
328
+ isLastColumn(header) {
329
+ const freeze = this.of.plugins.TableFreeze;
330
+ const right = freeze instanceof TableFreeze ? freeze.rightColumnCount : 0;
331
+ return header.cellIndex === this.headers().cells.length - right - 1;
332
+ }
273
333
  live(entry) {
274
334
  return !this.disposed && !entry.abort.signal.aborted && (this.pending.get(entry.source.id) === entry)
275
335
  && entry.content.header.parentElement === this.headers();
@@ -289,6 +349,13 @@ export class TableColumnAdd extends Plugin {
289
349
  throw new Error('Column row view changed during loading');
290
350
  }
291
351
  const old = entry.content;
352
+ const opening = old.header.classList.contains('column-add-opening');
353
+ const width = old.header.getBoundingClientRect?.().width ?? 0;
354
+ const target = parseFloat(old.header.style?.getPropertyValue('--column-width') ?? '') || width;
355
+ for (const cell of [old.header, ...old.cells]) {
356
+ clearTimeout(this.highlights.get(cell));
357
+ this.highlights.delete(cell);
358
+ }
292
359
  for (const cell of [content.header, ...content.cells])
293
360
  cell.hidden = old.header.hidden;
294
361
  this.reorder.replaceCell(old.header, content.header);
@@ -296,13 +363,27 @@ export class TableColumnAdd extends Plugin {
296
363
  entry.content = content;
297
364
  this.identities.set(content.header, entry.source.id);
298
365
  content.header.dataset.columnId = entry.source.id;
299
- const highlighted = old.header.classList.contains('column-add-highlight');
366
+ const removing = old.header.classList.contains('column-remove-highlight');
367
+ if (removing) {
368
+ this.measureColumn(content.header, width);
369
+ for (const cell of [content.header, ...content.cells])
370
+ cell.classList.add('column-remove-highlight');
371
+ }
300
372
  this.mark(entry, 'provisional', entry.transaction.state === 'provisional');
301
373
  this.mark(entry, 'loading', false);
302
374
  this.refresh();
303
375
  this.notify(entry, 'loaded');
304
- if (highlighted)
305
- this.highlight(entry.source.id);
376
+ if (!removing && entry.effects && entry.transaction.state === 'committed') {
377
+ for (const cell of [content.header, ...content.cells]) {
378
+ cell.style?.setProperty('--column-from', `${width}px`);
379
+ cell.style?.setProperty('--column-width', `${target}px`);
380
+ }
381
+ this.highlight(entry.source.id, true);
382
+ if (!opening)
383
+ content.header.classList.remove('column-add-opening');
384
+ if (this.isLastColumn(content.header))
385
+ this.scrollToEnd();
386
+ }
306
387
  }
307
388
  catch (error) {
308
389
  if (!this.live(entry))
@@ -310,6 +391,14 @@ export class TableColumnAdd extends Plugin {
310
391
  this.mark(entry, 'loading', false);
311
392
  this.mark(entry, 'error', true);
312
393
  this.notify(entry, 'error', error);
394
+ for (const cell of [entry.content.header, ...entry.content.cells]) {
395
+ clearTimeout(this.highlights.get(cell));
396
+ this.highlights.delete(cell);
397
+ cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
398
+ for (const name of ['fade', 'from', 'height', 'width'])
399
+ cell.style?.removeProperty(`--column-${name}`);
400
+ }
401
+ this.refresh();
313
402
  }
314
403
  finally {
315
404
  entry.settled = true;
@@ -325,6 +414,17 @@ export class TableColumnAdd extends Plugin {
325
414
  present ? cell.setAttribute('aria-busy', 'true') : cell.removeAttribute('aria-busy');
326
415
  }
327
416
  }
417
+ measureColumn(header, width) {
418
+ if (!header.ownerDocument)
419
+ return;
420
+ width ??= Math.max(header.getBoundingClientRect().width, parseFloat(header.style.getPropertyValue('--column-width')) || 0);
421
+ const cells = Array.from(this.of.element.rows).map(row => row.cells[header.cellIndex]);
422
+ const heights = cells.map(cell => cell.getBoundingClientRect().height);
423
+ cells.forEach((cell, index) => {
424
+ cell.style.setProperty('--column-width', `${width}px`);
425
+ cell.style.setProperty('--column-height', `${heights[index]}px`);
426
+ });
427
+ }
328
428
  notify(entry, state, error) {
329
429
  this.options.onChange?.({ error, header: entry.content.header, id: entry.source.id, state });
330
430
  }
@@ -334,6 +434,68 @@ export class TableColumnAdd extends Plugin {
334
434
  freeze.refresh();
335
435
  this.of.refreshStyleSheets();
336
436
  }
437
+ /** Reveal and briefly mark a column in red before removing it. */
438
+ remove(id, signal) {
439
+ const pending = this.removals.get(id);
440
+ if (pending)
441
+ return pending.promise;
442
+ if (this.disposed || signal?.aborted || !this.find(id))
443
+ return Promise.resolve(false);
444
+ if (this.external || this.pending.get(id)?.transaction.state === 'provisional')
445
+ return Promise.reject(new Error('A column interaction is active'));
446
+ const abort = new AbortController();
447
+ const cancelled = AbortSignal.any([abort.signal, ...(signal ? [signal] : [])]);
448
+ const promise = this.removeColumn(id, cancelled).finally(() => {
449
+ if (this.removals.get(id)?.abort === abort)
450
+ this.removals.delete(id);
451
+ });
452
+ this.removals.set(id, { abort, promise });
453
+ return promise;
454
+ }
455
+ async removeColumn(id, signal) {
456
+ this.reveal(id);
457
+ const header = this.find(id);
458
+ const cells = Array.from(this.of.element.rows).map(row => row.cells[header.cellIndex]).filter(Boolean);
459
+ this.measureColumn(header, header.getBoundingClientRect?.().width ?? 0);
460
+ for (const cell of cells) {
461
+ clearTimeout(this.highlights.get(cell));
462
+ this.highlights.delete(cell);
463
+ cell.classList.remove('column-add-highlight', 'column-add-new', 'column-add-opening');
464
+ cell.classList.add('column-remove-highlight');
465
+ }
466
+ try {
467
+ await new Promise(resolve => {
468
+ const finish = () => {
469
+ clearTimeout(timer);
470
+ signal.removeEventListener('abort', finish);
471
+ resolve();
472
+ };
473
+ const timer = setTimeout(finish, 300);
474
+ signal.addEventListener('abort', finish, { once: true });
475
+ });
476
+ const current = this.find(id);
477
+ if (this.disposed || signal.aborted || !current)
478
+ return false;
479
+ if (!this.reorder.removeColumn(current))
480
+ return false;
481
+ const entry = this.pending.get(id);
482
+ entry?.abort.abort();
483
+ this.pending.delete(id);
484
+ this.refresh();
485
+ return true;
486
+ }
487
+ finally {
488
+ const current = this.find(id);
489
+ if (current)
490
+ cells.push(...Array.from(this.of.element.rows).map(row => row.cells[current.cellIndex]));
491
+ for (const cell of cells) {
492
+ cell?.classList.remove('column-remove-highlight');
493
+ for (const name of ['fade', 'from', 'height', 'width'])
494
+ cell?.style?.removeProperty(`--column-${name}`);
495
+ }
496
+ this.refresh();
497
+ }
498
+ }
337
499
  reveal(id) {
338
500
  const header = this.find(id);
339
501
  if (!header || this.disposed)
@@ -355,6 +517,33 @@ export class TableColumnAdd extends Plugin {
355
517
  else if ((rect.right > right) && (rect.left > left))
356
518
  scroll.scrollLeft += Math.min(rect.right - right, rect.left - left);
357
519
  }
520
+ scrollToEnd() {
521
+ if (this.scrollFrame !== undefined)
522
+ cancelAnimationFrame(this.scrollFrame);
523
+ this.scrollFrame = undefined;
524
+ const scroll = this.reorder.scrollContainer();
525
+ if (!scroll || this.disposed)
526
+ return;
527
+ const from = scroll.scrollLeft;
528
+ const to = Math.max(from, scroll.scrollWidth - scroll.clientWidth);
529
+ if (to <= from)
530
+ return;
531
+ if (scroll.ownerDocument?.defaultView?.matchMedia('(prefers-reduced-motion: reduce)').matches) {
532
+ scroll.scrollLeft = to;
533
+ return;
534
+ }
535
+ const started = performance.now();
536
+ const step = (time) => {
537
+ this.scrollFrame = undefined;
538
+ if (this.disposed)
539
+ return;
540
+ const progress = Math.min(1, Math.max(0, (time - started) / 100));
541
+ scroll.scrollLeft = from + (to - from) * (1 - (1 - progress) ** 2);
542
+ if (progress < 1)
543
+ this.scrollFrame = requestAnimationFrame(step);
544
+ };
545
+ this.scrollFrame = requestAnimationFrame(step);
546
+ }
358
547
  retry(id) {
359
548
  const entry = this.pending.get(id);
360
549
  if (!entry || !this.live(entry) || !entry.content.header.classList.contains('column-add-error'))
@@ -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
- external: boolean;
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 = direction ? this.target(drag, direction) : drag.index;
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 && !drag.external;
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: external ? (x < source.left ? -1 : x > source.right ? 1 : 0)
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
- const headers = this.triggerRow().cells;
331
- let target = drag.index;
332
- for (let index = drag.index + direction; (index >= drag.minimum) && (index <= drag.maximum); index += direction) {
333
- const rect = headers[index].getBoundingClientRect();
334
- const edge = direction > 0 ? rect.left : rect.right;
335
- if (direction * (drag.x - edge) < penetration)
336
- break;
337
- target = index;
338
- }
339
- return target;
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('removing', drag.remove && !drag.external);
364
- cell.classList.toggle('moving', !drag.remove && (drag.index !== drag.initial)
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
- const source = drag.external ? drag.header.getBoundingClientRect() : undefined;
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
@@ -53,5 +53,5 @@
53
53
  "scripts": {
54
54
  "build": "tsc && sass --no-source-map demo:demo src/column-add.scss:column-add.css && node ../prepare-module/prepare-module.js"
55
55
  },
56
- "version": "0.4.3"
56
+ "version": "0.7.3"
57
57
  }