@itrocks/table 0.11.0 → 0.13.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 +21 -0
- package/column-add.js +6 -1
- package/column-change.d.ts +1 -0
- package/column-change.js +3 -0
- package/column-reorder.d.ts +1 -0
- package/column-reorder.js +10 -7
- package/feed.js +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,23 @@ The callback receives the cell and its zero-based index in the row when the cell
|
|
|
74
74
|
Return its focusable control to keep it in the form, `null` to skip the cell, or `undefined` to use the text editor.
|
|
75
75
|
Clicking the cell background focuses its control and places the caret at the end of text fields.
|
|
76
76
|
|
|
77
|
+
### Loading more rows
|
|
78
|
+
|
|
79
|
+
Add the `TableFeed` plugin and set `data-feed` on the table to the URL that returns the next batch as an HTML table.
|
|
80
|
+
The table emits a `table-feed` event once after inserting each non-empty batch. The event's `detail.rows` array
|
|
81
|
+
contains the inserted `HTMLTableRowElement` instances in DOM order.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { TableFeed } from '@itrocks/table/feed.js'
|
|
85
|
+
import { tableByElement } from '@itrocks/table/table.js'
|
|
86
|
+
|
|
87
|
+
const element = document.querySelector('table[data-feed]')
|
|
88
|
+
element.addEventListener('table-feed', ({ detail: { rows } }) => {
|
|
89
|
+
console.log('Rows added', rows)
|
|
90
|
+
})
|
|
91
|
+
tableByElement(element, { plugins: [TableFeed] })
|
|
92
|
+
```
|
|
93
|
+
|
|
77
94
|
## API
|
|
78
95
|
|
|
79
96
|
The public API is intentionally small and focuses on a single `Table`
|
|
@@ -264,6 +281,10 @@ Import the public browser entry and stylesheet. Configure `TableColumnAdd` after
|
|
|
264
281
|
freeze plugins. The addition plugin consumes opaque string ids and callback-rendered cells; it has no dependency on
|
|
265
282
|
business objects, selectors, routes or storage.
|
|
266
283
|
|
|
284
|
+
Listen for `table-column-change` on the table element to receive the cells inserted, replaced or removed by the
|
|
285
|
+
column plugins. `event.detail.cells` contains the affected header and body or footer cells. A replacement includes
|
|
286
|
+
both the previous and replacement cells.
|
|
287
|
+
|
|
267
288
|
```ts
|
|
268
289
|
import { TableColumnAdd } from '@itrocks/table/column-add.js'
|
|
269
290
|
import { TableColumnReorder } from '@itrocks/table/column-reorder.js'
|
package/column-add.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from '../plugin/plugin.js';
|
|
2
2
|
import { PluginOptions } from '../plugin/plugin.js';
|
|
3
|
+
import { notifyColumnChange } from './column-change.js';
|
|
3
4
|
import { TableColumnReorder } from './column-reorder.js';
|
|
4
5
|
import { TableFreeze } from './freeze.js';
|
|
5
6
|
export class TableColumnAdd extends Plugin {
|
|
@@ -178,9 +179,11 @@ export class TableColumnAdd extends Plugin {
|
|
|
178
179
|
if (existing)
|
|
179
180
|
this.reorder.moveColumn(entry.content.header, entry.initial);
|
|
180
181
|
else {
|
|
181
|
-
|
|
182
|
+
const cells = [entry.content.header, ...entry.content.cells];
|
|
183
|
+
for (const cell of cells)
|
|
182
184
|
cell.remove();
|
|
183
185
|
entry.col?.remove();
|
|
186
|
+
notifyColumnChange(this.of.element, cells);
|
|
184
187
|
}
|
|
185
188
|
this.refresh();
|
|
186
189
|
this.notify(entry, 'cancelled');
|
|
@@ -235,6 +238,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
235
238
|
}
|
|
236
239
|
this.mark(entry, 'provisional', true);
|
|
237
240
|
this.refresh();
|
|
241
|
+
notifyColumnChange(this.of.element, [content.header, ...content.cells]);
|
|
238
242
|
this.notify(entry, 'provisional');
|
|
239
243
|
if (source.load)
|
|
240
244
|
ready = this.load(entry);
|
|
@@ -423,6 +427,7 @@ export class TableColumnAdd extends Plugin {
|
|
|
423
427
|
if (!removing && entry.effects && entry.transaction.state === 'committed'
|
|
424
428
|
&& this.isLastColumn(content.header))
|
|
425
429
|
this.scrollToEnd();
|
|
430
|
+
notifyColumnChange(this.of.element, pairs.flat());
|
|
426
431
|
this.notify(entry, 'loaded');
|
|
427
432
|
}
|
|
428
433
|
catch (error) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function notifyColumnChange(table: HTMLTableElement, cells: readonly HTMLTableCellElement[]): void;
|
package/column-change.js
ADDED
package/column-reorder.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export declare class TableColumnReorder extends Plugin<Table, TableColumnReorder
|
|
|
57
57
|
moveColumn(header: HTMLTableCellElement, targetIndex: number): void;
|
|
58
58
|
/** Remove a reorderable column without committing a header gesture or invoking its callbacks. */
|
|
59
59
|
removeColumn(header: HTMLTableCellElement): boolean;
|
|
60
|
+
private removeCells;
|
|
60
61
|
/** Retain the active gesture when asynchronous rendering replaces one of its cells. */
|
|
61
62
|
replaceCell(previous: HTMLTableCellElement, replacement: HTMLTableCellElement): void;
|
|
62
63
|
protected finish(commit: boolean): void;
|
package/column-reorder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from '../plugin/plugin.js';
|
|
2
2
|
import { PluginOptions } from '../plugin/plugin.js';
|
|
3
|
+
import { notifyColumnChange } from './column-change.js';
|
|
3
4
|
let activeDrag;
|
|
4
5
|
const clamp = (value) => Math.max(0, Math.min(1, value));
|
|
5
6
|
const maxScrollSpeed = 800;
|
|
@@ -96,11 +97,16 @@ export class TableColumnReorder extends Plugin {
|
|
|
96
97
|
return false;
|
|
97
98
|
const index = header.cellIndex;
|
|
98
99
|
const column = this.of.element.querySelectorAll(':scope > colgroup > col')[index];
|
|
99
|
-
|
|
100
|
-
row.cells[index]?.remove();
|
|
101
|
-
column?.remove();
|
|
100
|
+
this.removeCells(index, column);
|
|
102
101
|
return true;
|
|
103
102
|
}
|
|
103
|
+
removeCells(index, column) {
|
|
104
|
+
const cells = this.rows().map(row => row.cells[index]).filter(Boolean);
|
|
105
|
+
for (const cell of cells)
|
|
106
|
+
cell.remove();
|
|
107
|
+
column?.remove();
|
|
108
|
+
notifyColumnChange(this.of.element, cells);
|
|
109
|
+
}
|
|
104
110
|
/** Retain the active gesture when asynchronous rendering replaces one of its cells. */
|
|
105
111
|
replaceCell(previous, replacement) {
|
|
106
112
|
if (this.press?.header === previous)
|
|
@@ -130,10 +136,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
130
136
|
this.move(drag, drag.initial);
|
|
131
137
|
const removed = (commit && drag.remove) || (!commit && drag.adding);
|
|
132
138
|
if (removed) {
|
|
133
|
-
|
|
134
|
-
row.cells[drag.index]?.remove();
|
|
135
|
-
}
|
|
136
|
-
drag.col?.remove();
|
|
139
|
+
this.removeCells(drag.index, drag.col);
|
|
137
140
|
}
|
|
138
141
|
for (const cell of drag.cells) {
|
|
139
142
|
cell.classList.remove('adding', 'column-reorder', 'moving', 'removing');
|
package/feed.js
CHANGED
|
@@ -17,10 +17,18 @@ export class TableFeed extends Plugin {
|
|
|
17
17
|
const container = loaded.querySelector('tbody > tr')?.parentElement ?? loaded.querySelector('tr')?.parentElement;
|
|
18
18
|
if (!container)
|
|
19
19
|
return;
|
|
20
|
+
const rows = [];
|
|
20
21
|
while (container.firstChild) {
|
|
21
|
-
|
|
22
|
+
const node = container.firstChild;
|
|
23
|
+
tbody.append(node);
|
|
24
|
+
if (node instanceof HTMLTableRowElement) {
|
|
25
|
+
rows.push(node);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
this.observe();
|
|
29
|
+
if (rows.length) {
|
|
30
|
+
table.dispatchEvent(new CustomEvent('table-feed', { detail: { rows } }));
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
fieldSelector(fields) {
|
|
26
34
|
return fields.split(/\s+/).filter(Boolean).map(field => {
|
package/package.json
CHANGED
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsc && sass --no-source-map src/column-add.scss:column-add.css src/column-resize.scss:column-resize.css && node ../prepare-module/prepare-module.js && tsc -p tsconfig.demo.json && sass --no-source-map demo:demo"
|
|
56
56
|
},
|
|
57
|
-
"version": "0.
|
|
57
|
+
"version": "0.13.0"
|
|
58
58
|
}
|