@rickcedwhat/playwright-smart-table 6.20.1-next.230dedf → 6.20.1-next.6671496

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.
@@ -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.230dedf";
6
+ export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.20.1-next.6671496";
@@ -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.230dedf";
9
+ exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.20.1-next.6671496";
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.20.1-next.230dedf",
3
+ "version": "6.20.1-next.6671496",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",