@pallasoft/ps-table-components 1.18.1 → 1.20.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.
Files changed (42) hide show
  1. package/dist/components/ps-data-table.js +86 -24
  2. package/dist/components/ps-table-pagination.d.ts +2 -1
  3. package/dist/components/ps-table-pagination.js +3 -2
  4. package/dist/constants/table-config.d.ts +9 -0
  5. package/dist/constants/table-config.js +6 -0
  6. package/dist/esm/components/ps-data-table.js +87 -25
  7. package/dist/esm/components/ps-table-pagination.js +3 -2
  8. package/dist/esm/constants/table-config.js +6 -0
  9. package/dist/esm/hooks/use-ps-incremental-count.js +17 -0
  10. package/dist/esm/hooks/use-ps-scroll-anchor.js +26 -0
  11. package/dist/esm/hooks/use-ps-streamed-rows.js +58 -15
  12. package/dist/esm/index.js +3 -0
  13. package/dist/esm/interfaces/table-scroll-anchor-target.js +1 -0
  14. package/dist/esm/interfaces/table-scroll-anchor.js +1 -0
  15. package/dist/esm/services/ps-table-query-service.js +25 -13
  16. package/dist/esm/services/ps-table-scroll-anchor-service.js +17 -0
  17. package/dist/esm/services/ps-table-scroll-service.js +18 -0
  18. package/dist/esm/services/ps-table-search-service.js +14 -4
  19. package/dist/esm/services/ps-table-stream-service.js +18 -0
  20. package/dist/hooks/use-ps-incremental-count.d.ts +5 -0
  21. package/dist/hooks/use-ps-incremental-count.js +21 -0
  22. package/dist/hooks/use-ps-scroll-anchor.d.ts +2 -0
  23. package/dist/hooks/use-ps-scroll-anchor.js +30 -0
  24. package/dist/hooks/use-ps-streamed-rows.js +57 -14
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +3 -0
  27. package/dist/interfaces/table-scroll-anchor-target.d.ts +10 -0
  28. package/dist/interfaces/table-scroll-anchor-target.js +2 -0
  29. package/dist/interfaces/table-scroll-anchor.d.ts +4 -0
  30. package/dist/interfaces/table-scroll-anchor.js +2 -0
  31. package/dist/interfaces/table-stream-state.d.ts +1 -0
  32. package/dist/services/ps-table-query-service.d.ts +2 -0
  33. package/dist/services/ps-table-query-service.js +25 -13
  34. package/dist/services/ps-table-scroll-anchor-service.d.ts +7 -0
  35. package/dist/services/ps-table-scroll-anchor-service.js +21 -0
  36. package/dist/services/ps-table-scroll-service.d.ts +5 -0
  37. package/dist/services/ps-table-scroll-service.js +22 -0
  38. package/dist/services/ps-table-search-service.d.ts +3 -0
  39. package/dist/services/ps-table-search-service.js +14 -4
  40. package/dist/services/ps-table-stream-service.d.ts +2 -0
  41. package/dist/services/ps-table-stream-service.js +18 -0
  42. package/package.json +2 -1
@@ -1,5 +1,8 @@
1
1
  export declare class PsTableSearchService {
2
+ private static readonly haystacks;
2
3
  static normalise(value: string): string;
3
4
  static tokens(query: string): string[];
4
5
  static matches(text: string, query: string): boolean;
6
+ static matchesTokens(haystack: string, tokens: string[]): boolean;
7
+ static haystack<RowData>(row: RowData, getSearchText: (row: RowData) => string): string;
5
8
  }
@@ -18,11 +18,21 @@ class PsTableSearchService {
18
18
  return normalised === '' ? [] : normalised.split(' ');
19
19
  }
20
20
  static matches(text, query) {
21
- const tokens = PsTableSearchService.tokens(query);
22
- if (tokens.length === 0)
23
- return true;
24
- const haystack = PsTableSearchService.normalise(text);
21
+ return PsTableSearchService.matchesTokens(PsTableSearchService.normalise(text), PsTableSearchService.tokens(query));
22
+ }
23
+ static matchesTokens(haystack, tokens) {
25
24
  return tokens.every((token) => haystack.includes(token));
26
25
  }
26
+ static haystack(row, getSearchText) {
27
+ if (typeof row !== 'object' || row === null)
28
+ return PsTableSearchService.normalise(getSearchText(row));
29
+ const cached = PsTableSearchService.haystacks.get(row);
30
+ if (cached !== undefined)
31
+ return cached;
32
+ const haystack = PsTableSearchService.normalise(getSearchText(row));
33
+ PsTableSearchService.haystacks.set(row, haystack);
34
+ return haystack;
35
+ }
27
36
  }
28
37
  exports.PsTableSearchService = PsTableSearchService;
38
+ PsTableSearchService.haystacks = new WeakMap();
@@ -1,5 +1,7 @@
1
1
  export declare class PsTableStreamService {
2
2
  static nextPage(loaded: number, total: number, pageSize: number): number | null;
3
+ static pages(loaded: number, total: number, pageSize: number): number[];
4
+ static unseen<RowData>(page: RowData[], seen: Set<string>, getRowId: (row: RowData) => string): RowData[];
3
5
  static merge<RowData>(fresh: RowData[], previous: RowData[], getRowId: (row: RowData) => string, total: number): RowData[];
4
6
  static carried<RowData>(rows: RowData[], previous: RowData[], getRowId: (row: RowData) => string, total: number, isSameScope: boolean): RowData[];
5
7
  static append<RowData>(rows: RowData[], page: RowData[], getRowId: (row: RowData) => string): RowData[];
@@ -5,7 +5,25 @@ class PsTableStreamService {
5
5
  static nextPage(loaded, total, pageSize) {
6
6
  return loaded < total ? Math.floor(loaded / pageSize) + 1 : null;
7
7
  }
8
+ static pages(loaded, total, pageSize) {
9
+ const first = PsTableStreamService.nextPage(loaded, total, pageSize);
10
+ if (first === null)
11
+ return [];
12
+ const last = Math.ceil(total / pageSize);
13
+ return Array.from({ length: last - first + 1 }, (_, index) => first + index);
14
+ }
15
+ static unseen(page, seen, getRowId) {
16
+ return page.filter((row) => {
17
+ const rowId = getRowId(row);
18
+ if (seen.has(rowId))
19
+ return false;
20
+ seen.add(rowId);
21
+ return true;
22
+ });
23
+ }
8
24
  static merge(fresh, previous, getRowId, total) {
25
+ if (previous.length === 0)
26
+ return fresh.length > total ? fresh.slice(0, total) : fresh;
9
27
  const freshIds = new Set(fresh.map(getRowId));
10
28
  return [...fresh, ...previous.filter((row) => !freshIds.has(getRowId(row)))].slice(0, total);
11
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-table-components",
3
- "version": "1.18.1",
3
+ "version": "1.20.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -78,6 +78,7 @@
78
78
  "@pallasoft/ps-icons": "^1.5.4",
79
79
  "@pallasoft/ps-input-components": "^1.14.0",
80
80
  "@pallasoft/ps-motion-components": "^1.2.0",
81
+ "@tanstack/react-virtual": "^3.14.13",
81
82
  "react-aria-components": "^1.21.1"
82
83
  }
83
84
  }