@itrocks/table 0.4.1 → 0.4.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 +5 -3
- package/column-add.css +5 -0
- package/column-add.d.ts +1 -0
- package/column-add.js +102 -72
- package/freeze.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -300,9 +300,11 @@ including header-backed tables after addition, asynchronous replacement or reset
|
|
|
300
300
|
|
|
301
301
|
### External pointer transport
|
|
302
302
|
|
|
303
|
-
`beginExternal(source, sample): ColumnOperation` immediately creates a provisional
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
305
|
+
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.
|
|
307
|
+
The structural `PointerSample` contains `pointerId`, `pointerType`, `clientX` and `clientY`. The source owns capture.
|
|
306
308
|
`move(sample)` uses the existing reorder engine, including frozen boundaries and visible-edge autoscroll.
|
|
307
309
|
`finish(sample)` resolves to `added`, `moved` or `cancelled`; an outside drop cancels without a fallback insertion.
|
|
308
310
|
`cancel()` restores an existing column's original position or removes a new preview. Neither operation invokes the
|
package/column-add.css
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
table.itrocks > colgroup > col[hidden],
|
|
2
|
+
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td)[hidden] {
|
|
3
|
+
display: none !important;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
table.itrocks > :is(thead, tbody, tfoot) > tr > :is(th, td).column-add-highlight {
|
|
2
7
|
animation: itrocks-column-add-flash 850ms ease-out;
|
|
3
8
|
}
|
package/column-add.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export declare class TableColumnAdd extends Plugin<Table, TableColumnAddOptions>
|
|
|
57
57
|
begin(source: ColumnSource): ColumnTransaction;
|
|
58
58
|
/** Add or move an opaque column through the existing reorder geometry. */
|
|
59
59
|
beginExternal(source: ColumnSource, sample: PointerSample): ColumnOperation;
|
|
60
|
+
protected create(source: ColumnSource, hidden?: boolean): ColumnTransaction;
|
|
60
61
|
defaultOptions(): TableColumnAddOptions;
|
|
61
62
|
dispose(): void;
|
|
62
63
|
protected find(id: string): HTMLTableCellElement | undefined;
|
package/column-add.js
CHANGED
|
@@ -30,6 +30,102 @@ export class TableColumnAdd extends Plugin {
|
|
|
30
30
|
}
|
|
31
31
|
/** Create a provisional column without installing pointer transport. */
|
|
32
32
|
begin(source) {
|
|
33
|
+
return this.create(source);
|
|
34
|
+
}
|
|
35
|
+
/** Add or move an opaque column through the existing reorder geometry. */
|
|
36
|
+
beginExternal(source, sample) {
|
|
37
|
+
if (this.disposed || this.external)
|
|
38
|
+
throw new Error('Column addition is unavailable');
|
|
39
|
+
if (this.pending.get(source.id)?.transaction.state === 'provisional')
|
|
40
|
+
throw new Error('Column addition is pending');
|
|
41
|
+
const existing = this.find(source.id);
|
|
42
|
+
const initial = existing?.cellIndex;
|
|
43
|
+
const transaction = existing ? undefined : this.create(source, true);
|
|
44
|
+
let reorder;
|
|
45
|
+
const enter = (point) => {
|
|
46
|
+
if (reorder || point.pointerId !== sample.pointerId)
|
|
47
|
+
return;
|
|
48
|
+
const table = this.of.element;
|
|
49
|
+
if (!existing && !table.contains(table.ownerDocument.elementFromPoint(point.clientX, point.clientY)))
|
|
50
|
+
return;
|
|
51
|
+
try {
|
|
52
|
+
if (transaction) {
|
|
53
|
+
const entry = this.pending.get(source.id);
|
|
54
|
+
for (const cell of [entry.content.header, ...entry.content.cells])
|
|
55
|
+
cell.hidden = false;
|
|
56
|
+
if (entry.col)
|
|
57
|
+
entry.col.hidden = false;
|
|
58
|
+
this.refresh();
|
|
59
|
+
}
|
|
60
|
+
reorder = this.reorder.beginExternal(existing ?? transaction.header, point);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
operation.cancel();
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
let complete = false;
|
|
68
|
+
let finishing = false;
|
|
69
|
+
const abort = new AbortController();
|
|
70
|
+
const acceptance = Promise.resolve().then(() => source.accept?.(abort.signal));
|
|
71
|
+
// Keep a rejected admission observable at finish without an unhandled rejection during transport.
|
|
72
|
+
void acceptance.catch(() => { });
|
|
73
|
+
const operation = {
|
|
74
|
+
cancel: () => {
|
|
75
|
+
if (complete)
|
|
76
|
+
return;
|
|
77
|
+
complete = true;
|
|
78
|
+
abort.abort();
|
|
79
|
+
reorder?.cancel();
|
|
80
|
+
if (initial !== undefined)
|
|
81
|
+
this.reorder.moveColumn(this.find(source.id), initial);
|
|
82
|
+
transaction?.cancel();
|
|
83
|
+
this.external = undefined;
|
|
84
|
+
this.refresh();
|
|
85
|
+
},
|
|
86
|
+
finish: async (point) => {
|
|
87
|
+
if (complete || finishing)
|
|
88
|
+
return 'cancelled';
|
|
89
|
+
finishing = true;
|
|
90
|
+
enter(point);
|
|
91
|
+
if (!reorder?.hold(point)) {
|
|
92
|
+
operation.cancel();
|
|
93
|
+
return 'cancelled';
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
await acceptance;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
operation.cancel();
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
if (complete)
|
|
103
|
+
return 'cancelled';
|
|
104
|
+
if (!reorder.finish(point)) {
|
|
105
|
+
operation.cancel();
|
|
106
|
+
return 'cancelled';
|
|
107
|
+
}
|
|
108
|
+
complete = true;
|
|
109
|
+
this.external = undefined;
|
|
110
|
+
if (transaction)
|
|
111
|
+
transaction.commit();
|
|
112
|
+
else
|
|
113
|
+
this.options.onChange?.({ header: this.find(source.id), id: source.id, state: 'committed' });
|
|
114
|
+
this.refresh();
|
|
115
|
+
return existing ? 'moved' : 'added';
|
|
116
|
+
},
|
|
117
|
+
move: point => {
|
|
118
|
+
if (complete || finishing)
|
|
119
|
+
return;
|
|
120
|
+
enter(point);
|
|
121
|
+
reorder?.move(point);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
this.external = operation;
|
|
125
|
+
enter(sample);
|
|
126
|
+
return operation;
|
|
127
|
+
}
|
|
128
|
+
create(source, hidden = false) {
|
|
33
129
|
if (this.disposed)
|
|
34
130
|
throw new Error('Column addition is disposed');
|
|
35
131
|
const pending = this.pending.get(source.id);
|
|
@@ -99,6 +195,9 @@ export class TableColumnAdd extends Plugin {
|
|
|
99
195
|
this.pending.set(source.id, entry);
|
|
100
196
|
if (existing)
|
|
101
197
|
return transaction;
|
|
198
|
+
if (hidden)
|
|
199
|
+
for (const cell of [content.header, ...content.cells])
|
|
200
|
+
cell.hidden = true;
|
|
102
201
|
this.identities.set(content.header, source.id);
|
|
103
202
|
content.header.dataset.columnId = source.id;
|
|
104
203
|
const freeze = this.of.plugins.TableFreeze;
|
|
@@ -108,6 +207,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
108
207
|
const group = this.of.element.querySelector('colgroup');
|
|
109
208
|
if (group) {
|
|
110
209
|
entry.col = document.createElement('col');
|
|
210
|
+
entry.col.hidden = hidden;
|
|
111
211
|
group.insertBefore(entry.col, group.children[index] ?? null);
|
|
112
212
|
}
|
|
113
213
|
this.mark(entry, 'provisional', true);
|
|
@@ -117,78 +217,6 @@ export class TableColumnAdd extends Plugin {
|
|
|
117
217
|
ready = this.load(entry);
|
|
118
218
|
return transaction;
|
|
119
219
|
}
|
|
120
|
-
/** Add or move an opaque column through the existing reorder geometry. */
|
|
121
|
-
beginExternal(source, sample) {
|
|
122
|
-
if (this.disposed || this.external)
|
|
123
|
-
throw new Error('Column addition is unavailable');
|
|
124
|
-
if (this.pending.get(source.id)?.transaction.state === 'provisional')
|
|
125
|
-
throw new Error('Column addition is pending');
|
|
126
|
-
const existing = this.find(source.id);
|
|
127
|
-
const initial = existing?.cellIndex;
|
|
128
|
-
const transaction = existing ? undefined : this.begin(source);
|
|
129
|
-
let reorder;
|
|
130
|
-
try {
|
|
131
|
-
reorder = this.reorder.beginExternal(existing ?? transaction.header, sample);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
transaction?.cancel();
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
let complete = false;
|
|
138
|
-
let finishing = false;
|
|
139
|
-
const abort = new AbortController();
|
|
140
|
-
const acceptance = Promise.resolve().then(() => source.accept?.(abort.signal));
|
|
141
|
-
// Keep a rejected admission observable at finish without an unhandled rejection during transport.
|
|
142
|
-
void acceptance.catch(() => { });
|
|
143
|
-
const operation = {
|
|
144
|
-
cancel: () => {
|
|
145
|
-
if (complete)
|
|
146
|
-
return;
|
|
147
|
-
complete = true;
|
|
148
|
-
abort.abort();
|
|
149
|
-
reorder.cancel();
|
|
150
|
-
if (initial !== undefined)
|
|
151
|
-
this.reorder.moveColumn(this.find(source.id), initial);
|
|
152
|
-
transaction?.cancel();
|
|
153
|
-
this.external = undefined;
|
|
154
|
-
this.refresh();
|
|
155
|
-
},
|
|
156
|
-
finish: async (point) => {
|
|
157
|
-
if (complete || finishing)
|
|
158
|
-
return 'cancelled';
|
|
159
|
-
finishing = true;
|
|
160
|
-
if (!reorder.hold(point)) {
|
|
161
|
-
operation.cancel();
|
|
162
|
-
return 'cancelled';
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
await acceptance;
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
operation.cancel();
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
if (complete)
|
|
172
|
-
return 'cancelled';
|
|
173
|
-
if (!reorder.finish(point)) {
|
|
174
|
-
operation.cancel();
|
|
175
|
-
return 'cancelled';
|
|
176
|
-
}
|
|
177
|
-
complete = true;
|
|
178
|
-
this.external = undefined;
|
|
179
|
-
if (transaction)
|
|
180
|
-
transaction.commit();
|
|
181
|
-
else
|
|
182
|
-
this.options.onChange?.({ header: this.find(source.id), id: source.id, state: 'committed' });
|
|
183
|
-
this.refresh();
|
|
184
|
-
return existing ? 'moved' : 'added';
|
|
185
|
-
},
|
|
186
|
-
move: point => { if (!complete)
|
|
187
|
-
reorder.move(point); }
|
|
188
|
-
};
|
|
189
|
-
this.external = operation;
|
|
190
|
-
return operation;
|
|
191
|
-
}
|
|
192
220
|
defaultOptions() {
|
|
193
221
|
return new TableColumnAddOptions();
|
|
194
222
|
}
|
|
@@ -261,6 +289,8 @@ export class TableColumnAdd extends Plugin {
|
|
|
261
289
|
throw new Error('Column row view changed during loading');
|
|
262
290
|
}
|
|
263
291
|
const old = entry.content;
|
|
292
|
+
for (const cell of [content.header, ...content.cells])
|
|
293
|
+
cell.hidden = old.header.hidden;
|
|
264
294
|
this.reorder.replaceCell(old.header, content.header);
|
|
265
295
|
old.cells.forEach((cell, index) => this.reorder.replaceCell(cell, content.cells[index]));
|
|
266
296
|
entry.content = content;
|
package/freeze.js
CHANGED
|
@@ -78,7 +78,8 @@ export class TableFreeze extends Plugin {
|
|
|
78
78
|
const table = this.of;
|
|
79
79
|
if (!table.element.tHead?.rows.length)
|
|
80
80
|
return;
|
|
81
|
-
|
|
81
|
+
// Header measurements are in scrolled coordinates after refresh removes the sticky rules.
|
|
82
|
+
let counter = 1, top = .0, previousTop = table.element.getBoundingClientRect().top - table.element.scrollTop;
|
|
82
83
|
table.element.tHead.querySelectorAll(':scope > tr').forEach(row => {
|
|
83
84
|
const actualTop = row.getBoundingClientRect().top;
|
|
84
85
|
top += actualTop - previousTop;
|
package/package.json
CHANGED