@rickcedwhat/playwright-smart-table 6.20.1-next.4619a8b → 6.20.1-next.e170fdd

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.
@@ -24,6 +24,7 @@ export declare class RowFinder<T = any> {
24
24
  exact?: boolean;
25
25
  maxPages?: number;
26
26
  }): Promise<SmartRow<T>>;
27
+ private waitForTableReady;
27
28
  findRows(filters?: Record<string, FilterValue>, options?: {
28
29
  exact?: boolean;
29
30
  maxPages?: number;
@@ -104,6 +104,22 @@ class RowFinder {
104
104
  smartRow[sentinel_1.SENTINEL_ROW] = true;
105
105
  return smartRow;
106
106
  }
107
+ async waitForTableReady() {
108
+ var _a;
109
+ const isTableLoading = (_a = this.config.strategies.loading) === null || _a === void 0 ? void 0 : _a.isTableLoading;
110
+ if (!isTableLoading)
111
+ return;
112
+ const context = {
113
+ root: this.rootLocator,
114
+ config: this.config,
115
+ page: this.rootLocator.page(),
116
+ resolve: this.resolve
117
+ };
118
+ while (await isTableLoading(context)) {
119
+ (0, debugUtils_1.logDebug)(this.config, 'verbose', 'Table is loading... waiting');
120
+ await this.rootLocator.page().waitForTimeout(200);
121
+ }
122
+ }
107
123
  async findRows(filters = {}, options) {
108
124
  var _a, _b, _c;
109
125
  const filtersRecord = filters;
@@ -114,6 +130,7 @@ class RowFinder {
114
130
  (0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: starting (maxPages=${effectiveMaxPages}, filters=${JSON.stringify(filtersRecord)})`);
115
131
  const tracker = new elementTracker_1.ElementTracker('findRows');
116
132
  try {
133
+ await this.waitForTableReady();
117
134
  const { domFilters, overrideFilters, syntheticFilters } = this.splitFilters(filtersRecord);
118
135
  const hasOverrideFilters = Object.keys(overrideFilters).length > 0;
119
136
  const hasSyntheticFilters = Object.keys(syntheticFilters).length > 0;
@@ -186,26 +203,13 @@ class RowFinder {
186
203
  return (0, smartRowArray_1.createSmartRowArray)(allRows);
187
204
  }
188
205
  async findRowLocator(filters, options = {}) {
189
- var _a, _b, _c;
206
+ var _a, _b;
190
207
  const map = await this.tableMapper.getMap();
191
208
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages;
192
209
  let pagesScanned = 1;
193
210
  (0, debugUtils_1.logDebug)(this.config, 'verbose', `Looking for row: ${JSON.stringify(filters)} (MaxPages: ${effectiveMaxPages})`);
194
211
  while (true) {
195
- // Check Loading
196
- if ((_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isTableLoading) {
197
- const isLoading = await this.config.strategies.loading.isTableLoading({
198
- root: this.rootLocator,
199
- config: this.config,
200
- page: this.rootLocator.page(),
201
- resolve: this.resolve
202
- });
203
- if (isLoading) {
204
- (0, debugUtils_1.logDebug)(this.config, 'verbose', 'Table is loading... waiting');
205
- await this.rootLocator.page().waitForTimeout(200);
206
- continue;
207
- }
208
- }
212
+ await this.waitForTableReady();
209
213
  const allRows = this.resolve(this.config.rowSelector, this.rootLocator);
210
214
  const { domFilters, overrideFilters, syntheticFilters } = this.splitFilters(filters);
211
215
  const hasPostFilters = Object.keys(overrideFilters).length > 0 || Object.keys(syntheticFilters).length > 0;
@@ -242,7 +246,7 @@ class RowFinder {
242
246
  (0, debugUtils_1.logDebug)(this.config, 'verbose', `Page ${this.tableState.currentPageIndex}: Not found. Attempting pagination...`);
243
247
  // Default to single-step goNext; bulk is opt-in via useBulkPagination: true (#349).
244
248
  // Bulk-by-default made findRow jump past the page holding the target row.
245
- const useBulk = options.useBulkPagination === true && !!((_c = this.config.strategies.pagination) === null || _c === void 0 ? void 0 : _c.goNextBulk);
249
+ const useBulk = options.useBulkPagination === true && !!((_b = this.config.strategies.pagination) === null || _b === void 0 ? void 0 : _b.goNextBulk);
246
250
  const prevPage = this.tableState.currentPageIndex;
247
251
  const didLoadMore = await this.advancePage(useBulk);
248
252
  if (didLoadMore) {
@@ -3,4 +3,4 @@
3
3
  * Generated by scripts/embed-version.mjs from package.json
4
4
  */
5
5
  /** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
6
- export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.20.1-next.4619a8b";
6
+ export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.20.1-next.e170fdd";
@@ -6,4 +6,4 @@ exports.PLAYWRIGHT_SMART_TABLE_VERSION = void 0;
6
6
  * Generated by scripts/embed-version.mjs from package.json
7
7
  */
8
8
  /** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
9
- exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.20.1-next.4619a8b";
9
+ exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.20.1-next.e170fdd";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ViewportStrategies = void 0;
4
+ const debugUtils_1 = require("../utils/debugUtils");
4
5
  /**
5
6
  * Viewport strategies for tables where row and cell elements carry a DOM attribute
6
7
  * equal to their index (e.g. Braintrust logs table, TanStack-style grids).
@@ -11,6 +12,10 @@ exports.ViewportStrategies = void 0;
11
12
  * - scrollToColumn — aligns header's left edge to container left, waits for cell mount
12
13
  * - scrollToRow — scrolls row into view, waits for row mount
13
14
  *
15
+ * **Important:** `rowAttribute` must be present on the elements matched by `rowSelector`,
16
+ * not on child cells. If row elements lack the attribute, `getVisibleRowRange` returns
17
+ * `{first:0, last:0}` and logs a warning at the `error` log level.
18
+ *
14
19
  * @example
15
20
  * // TanStack / Braintrust (data-index, 0-based — default)
16
21
  * viewport: Strategies.Viewport.dataAttribute()
@@ -34,17 +39,22 @@ const dataAttribute = (options) => {
34
39
  getVisibleColumnRange: async ({ root, config }) => {
35
40
  const rowSel = config.rowSelector;
36
41
  const cellSel = typeof config.cellSelector === 'string' ? config.cellSelector : `[${colAttr}]`;
37
- return root.evaluate((el, { rowSel, cellSel, colAttr, colOffset }) => {
42
+ const result = await root.evaluate((el, { rowSel, cellSel, colAttr, colOffset }) => {
38
43
  const firstRow = el.querySelector(rowSel);
39
44
  if (!firstRow)
40
- return { first: 0, last: 0 };
41
- const indices = Array.from(firstRow.querySelectorAll(cellSel))
45
+ return { first: 0, last: 0, _cellCount: 0, _validCount: 0 };
46
+ const cells = Array.from(firstRow.querySelectorAll(cellSel));
47
+ const indices = cells
42
48
  .map(c => Number(c.getAttribute(colAttr)) - colOffset)
43
49
  .filter(n => !isNaN(n));
44
50
  if (!indices.length)
45
- return { first: 0, last: 0 };
46
- return { first: Math.min(...indices), last: Math.max(...indices) };
51
+ return { first: 0, last: 0, _cellCount: cells.length, _validCount: 0 };
52
+ return { first: Math.min(...indices), last: Math.max(...indices), _cellCount: cells.length, _validCount: indices.length };
47
53
  }, { rowSel, cellSel, colAttr, colOffset });
54
+ if (result._cellCount > 0 && result._validCount === 0) {
55
+ (0, debugUtils_1.logDebug)(config, 'error', `dataAttribute viewport: ${result._cellCount} cell(s) found but none have attribute "${colAttr}". Check that columnAttribute targets cell elements matched by cellSelector.`);
56
+ }
57
+ return { first: result.first, last: result.last };
48
58
  },
49
59
  getVisibleRowIndices: async ({ root, config }) => {
50
60
  const rowSel = config.rowSelector;
@@ -72,33 +82,30 @@ const dataAttribute = (options) => {
72
82
  },
73
83
  getVisibleRowRange: async ({ root, config }) => {
74
84
  const rowSel = config.rowSelector;
75
- return root.evaluate((el, { rowSel, rowAttr, rowOffset, containerSel }) => {
85
+ const result = await root.evaluate((el, { rowSel, rowAttr, rowOffset, containerSel }) => {
76
86
  const rows = Array.from(el.querySelectorAll(rowSel));
77
- // #353: report only rows actually within the scroll container's vertical
78
- // bounds, not every mounted row. Previously overscan rows (kept mounted by
79
- // the virtual scroller above/below the fold) were counted as "visible".
80
- // Inclusive: a row with ANY vertical overlap counts as visible; only rows
81
- // entirely above or below the container are dropped — so we never drop a
82
- // partially-visible real row.
83
87
  const container = el.closest(containerSel);
84
88
  const containerRect = container ? container.getBoundingClientRect() : null;
85
- const indices = rows
89
+ const visibleRows = rows
86
90
  .filter(r => {
87
- // Container not resolvable — can't measure, so keep all rows (safe
88
- // fallback, preserves pre-#353 behavior rather than risk dropping real rows).
89
91
  if (!containerRect)
90
92
  return true;
91
93
  const rect = r.getBoundingClientRect();
92
94
  if (rect.height === 0)
93
- return false; // unrendered / detached
95
+ return false;
94
96
  return rect.bottom > containerRect.top && rect.top < containerRect.bottom;
95
- })
97
+ });
98
+ const indices = visibleRows
96
99
  .map(r => Number(r.getAttribute(rowAttr)) - rowOffset)
97
100
  .filter(n => !isNaN(n));
98
101
  if (!indices.length)
99
- return { first: 0, last: 0 };
100
- return { first: Math.min(...indices), last: Math.max(...indices) };
102
+ return { first: 0, last: 0, _rowCount: visibleRows.length, _validCount: 0 };
103
+ return { first: Math.min(...indices), last: Math.max(...indices), _rowCount: visibleRows.length, _validCount: indices.length };
101
104
  }, { rowSel, rowAttr, rowOffset, containerSel });
105
+ if (result._rowCount > 0 && result._validCount === 0) {
106
+ (0, debugUtils_1.logDebug)(config, 'error', `dataAttribute viewport: ${result._rowCount} row(s) found but none have attribute "${rowAttr}". Check that rowAttribute targets row elements matched by rowSelector, not child cells. getVisibleRowRange returning {first:0, last:0}.`);
107
+ }
108
+ return { first: result.first, last: result.last };
102
109
  },
103
110
  scrollToColumn: async ({ root, config }, colIndex) => {
104
111
  const headerSel = typeof config.headerSelector === 'string' ? config.headerSelector : null;
package/dist/useTable.js CHANGED
@@ -301,7 +301,7 @@ const useTable = (rootLocator, configOptions = {}) => {
301
301
  return resolve(config.headerSelector, rootLocator).nth(idx);
302
302
  },
303
303
  countRows: async (filters, options) => {
304
- var _a, _b, _c, _d;
304
+ var _a, _b, _c, _d, _e;
305
305
  if (tableState.empty)
306
306
  return 0;
307
307
  await _autoInit();
@@ -359,6 +359,15 @@ const useTable = (rootLocator, configOptions = {}) => {
359
359
  }
360
360
  return count;
361
361
  };
362
+ // Wait for table to finish loading before counting
363
+ const isTableLoading = (_e = config.strategies.loading) === null || _e === void 0 ? void 0 : _e.isTableLoading;
364
+ if (isTableLoading) {
365
+ const ctx = createStrategyContext();
366
+ while (await isTableLoading(ctx)) {
367
+ log('countRows: table is loading... waiting');
368
+ await rootLocator.page().waitForTimeout(200);
369
+ }
370
+ }
362
371
  if (!hasPagination) {
363
372
  log(`countRows: counting rows in current viewport (no pagination)${hasFilters ? ` filters=${safeStringify(filtersRecord)}` : ''}`);
364
373
  if (!hasPostFilters)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.20.1-next.4619a8b",
3
+ "version": "6.20.1-next.e170fdd",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",