@itrocks/table 0.2.4 → 0.2.6

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.
Files changed (3) hide show
  1. package/feed.d.ts +2 -0
  2. package/feed.js +23 -1
  3. package/package.json +2 -2
package/feed.d.ts CHANGED
@@ -3,6 +3,8 @@ import { Table } from './table.js';
3
3
  export declare class TableFeed extends Plugin<Table> {
4
4
  observer: IntersectionObserver | undefined;
5
5
  feed(): Promise<void>;
6
+ fieldSelector(fields: string): string;
6
7
  init(): void;
7
8
  observe(): void;
9
+ params(offset: number): URLSearchParams;
8
10
  }
package/feed.js CHANGED
@@ -8,7 +8,8 @@ export class TableFeed extends Plugin {
8
8
  if (!tbody || !url)
9
9
  return;
10
10
  const offset = tbody.querySelectorAll(':scope > tr').length;
11
- const offsetUrl = url + (url.includes('?') ? '&' : '?') + 'offset=' + offset;
11
+ const params = this.params(offset);
12
+ const offsetUrl = url + (url.includes('?') ? '&' : '?') + params.toString();
12
13
  const visibleRows = Math.ceil(tbody.clientHeight / offset);
13
14
  const requestInit = { headers: { 'xhr-info': JSON.stringify({ visibleRows }) } };
14
15
  const loaded = document.createElement('div');
@@ -21,6 +22,15 @@ export class TableFeed extends Plugin {
21
22
  }
22
23
  this.observe();
23
24
  }
25
+ fieldSelector(fields) {
26
+ return fields.split(/\s+/).filter(Boolean).map(field => {
27
+ const start = field.startsWith('*');
28
+ const end = field.endsWith('*');
29
+ const operator = start ? (end ? '*=' : '$=') : (end ? '^=' : '=');
30
+ const name = field.slice(start ? 1 : 0, end ? -1 : undefined);
31
+ return `:is(input, select, textarea)[name${operator}"${CSS.escape(name)}"]`;
32
+ }).join(', ');
33
+ }
24
34
  init() {
25
35
  this.observe();
26
36
  }
@@ -34,4 +44,16 @@ export class TableFeed extends Plugin {
34
44
  this.observer = new IntersectionObserver(async (entries) => entries[0].isIntersecting && this.feed(), { root: table, threshold: .1 });
35
45
  this.observer.observe(lastCell);
36
46
  }
47
+ params(offset) {
48
+ const params = new URLSearchParams({ offset: offset.toString() });
49
+ const table = this.of.element;
50
+ const selector = this.fieldSelector(table.dataset.feedFields ?? '');
51
+ if (!selector)
52
+ return params;
53
+ const fields = table.querySelectorAll(selector);
54
+ for (const field of fields) {
55
+ params.append(field.name, field.value);
56
+ }
57
+ return params;
58
+ }
37
59
  }
package/package.json CHANGED
@@ -50,7 +50,7 @@
50
50
  "url": "git+https://github.com/itrocks-ts/table.git"
51
51
  },
52
52
  "scripts": {
53
- "build": "tsc && sass --no-source-map demo:demo && ../prepare-module/prepare-module.js"
53
+ "build": "tsc && sass --no-source-map demo:demo && node ../prepare-module/prepare-module.js"
54
54
  },
55
- "version": "0.2.4"
55
+ "version": "0.2.6"
56
56
  }