@itrocks/table 0.0.15 → 0.0.17
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/feed.d.ts +8 -0
- package/feed.js +34 -0
- package/package.json +2 -2
package/feed.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '../../plugin/plugin.js';
|
|
2
|
+
import { Table } from './table.js';
|
|
3
|
+
export declare class TableFeed extends Plugin<Table> {
|
|
4
|
+
observer: IntersectionObserver | undefined;
|
|
5
|
+
constructor(table: Table);
|
|
6
|
+
feed(): Promise<void>;
|
|
7
|
+
observe(): void;
|
|
8
|
+
}
|
package/feed.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Plugin } from '../plugin/plugin.js';
|
|
2
|
+
export class TableFeed extends Plugin {
|
|
3
|
+
observer = undefined;
|
|
4
|
+
constructor(table) {
|
|
5
|
+
super(table);
|
|
6
|
+
this.observe();
|
|
7
|
+
}
|
|
8
|
+
async feed() {
|
|
9
|
+
const table = this.of.element;
|
|
10
|
+
const tbody = table.querySelector(':scope > tbody');
|
|
11
|
+
const url = table.dataset.feed ?? table.closest('form[action]')?.action;
|
|
12
|
+
if (!tbody || !url)
|
|
13
|
+
return;
|
|
14
|
+
const loaded = document.createElement('div');
|
|
15
|
+
const offsetUrl = url + (url.includes('?') ? '&' : '?') + 'offset=' + tbody.querySelectorAll(':scope > tr').length;
|
|
16
|
+
loaded.innerHTML = await (await fetch(offsetUrl)).text();
|
|
17
|
+
const loadedBody = loaded.querySelector('table > tbody');
|
|
18
|
+
if (!loadedBody)
|
|
19
|
+
return;
|
|
20
|
+
while (loadedBody.firstChild) {
|
|
21
|
+
tbody.append(loadedBody.firstChild);
|
|
22
|
+
}
|
|
23
|
+
this.observe();
|
|
24
|
+
}
|
|
25
|
+
observe() {
|
|
26
|
+
const table = this.of.element;
|
|
27
|
+
const lastCell = table.querySelector(':scope > tbody > tr:last-child > td:last-child');
|
|
28
|
+
if (!lastCell)
|
|
29
|
+
return;
|
|
30
|
+
this.observer?.disconnect();
|
|
31
|
+
this.observer = new IntersectionObserver(async (entries) => entries[0].isIntersecting && this.feed(), { root: table, threshold: .1 });
|
|
32
|
+
this.observer.observe(lastCell);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@itrocks/prepare-module": "latest",
|
|
13
13
|
"@types/node": "^22.9",
|
|
14
14
|
"sass": "^1.83",
|
|
15
|
-
"typescript": "5.
|
|
15
|
+
"typescript": "~5.8"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"LICENSE",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
},
|
|
50
50
|
"type": "module",
|
|
51
51
|
"types": "./table.d.ts",
|
|
52
|
-
"version": "0.0.
|
|
52
|
+
"version": "0.0.17"
|
|
53
53
|
}
|