@rickcedwhat/playwright-smart-table 6.7.8 → 6.8.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.
- package/README.md +13 -9
- package/dist/engine/tableIteration.d.ts +7 -9
- package/dist/engine/tableIteration.js +89 -191
- package/dist/engine/tableMapper.js +1 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/presets/glide/columns.d.ts +4 -1
- package/dist/presets/glide/columns.js +29 -18
- package/dist/presets/glide/index.d.ts +2 -0
- package/dist/presets/glide/index.js +26 -3
- package/dist/smartRow.d.ts +2 -1
- package/dist/smartRow.js +191 -63
- package/dist/strategies/columns.d.ts +11 -0
- package/dist/strategies/fill.js +1 -1
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +34 -7
- package/dist/types.d.ts +33 -7
- package/dist/useTable.js +8 -6
- package/dist/utils/mutex.d.ts +8 -0
- package/dist/utils/mutex.js +31 -0
- package/dist/utils/navigationBarrier.d.ts +21 -0
- package/dist/utils/navigationBarrier.js +82 -0
- package/package.json +14 -2
package/dist/smartRow.js
CHANGED
|
@@ -16,11 +16,12 @@ const paginationPath_1 = require("./utils/paginationPath");
|
|
|
16
16
|
const sentinel_1 = require("./utils/sentinel");
|
|
17
17
|
/**
|
|
18
18
|
* Internal helper to navigate to a cell with active cell optimization.
|
|
19
|
-
* Uses navigation primitives (goUp
|
|
19
|
+
* Uses `strategies.navigation` primitives (goUp/goDown/goLeft/goRight, optional snap/seek/goHome).
|
|
20
20
|
* Returns the target cell locator after navigation.
|
|
21
21
|
*/
|
|
22
22
|
const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
const { config, rootLocator, page, resolve, column, index, rowLocator, rowIndex } = params;
|
|
23
|
+
const { config, rootLocator, page, resolve, column, index, rowLocator, rowIndex, barrier } = params;
|
|
24
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', `_navigateToCell: navigating to column "${column}" (index ${index})`);
|
|
24
25
|
// Get active cell if strategy is available
|
|
25
26
|
let activeCell = null;
|
|
26
27
|
if (config.strategies.getActiveCell) {
|
|
@@ -43,70 +44,196 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
43
44
|
if (typeof rowIndex !== 'number') {
|
|
44
45
|
throw new Error('Row index is required for navigation');
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Navigate vertically
|
|
62
|
-
for (let i = 0; i < Math.abs(rowDiff); i++) {
|
|
63
|
-
if (rowDiff > 0 && nav.goDown) {
|
|
47
|
+
const navigateOnce = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
// Get current position again to be sure
|
|
49
|
+
let currRow = 0;
|
|
50
|
+
let currCol = 0;
|
|
51
|
+
if (config.strategies.getActiveCell) {
|
|
52
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
53
|
+
if (ac) {
|
|
54
|
+
currRow = ac.rowIndex;
|
|
55
|
+
currCol = ac.columnIndex;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const rDiff = rowIndex - currRow;
|
|
59
|
+
const cDiff = index - currCol;
|
|
60
|
+
// Move one step vertically
|
|
61
|
+
if (rDiff > 0 && nav.goDown) {
|
|
64
62
|
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving down');
|
|
65
63
|
yield nav.goDown(context);
|
|
66
64
|
}
|
|
67
|
-
else if (
|
|
65
|
+
else if (rDiff < 0 && nav.goUp) {
|
|
68
66
|
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving up');
|
|
69
67
|
yield nav.goUp(context);
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < Math.abs(colDiff); i++) {
|
|
74
|
-
if (colDiff > 0 && nav.goRight) {
|
|
69
|
+
// Move one step horizontally
|
|
70
|
+
if (cDiff > 0 && nav.goRight) {
|
|
75
71
|
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving right');
|
|
76
72
|
yield nav.goRight(context);
|
|
77
73
|
}
|
|
78
|
-
else if (
|
|
74
|
+
else if (cDiff < 0 && nav.goLeft) {
|
|
79
75
|
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving left');
|
|
80
76
|
yield nav.goLeft(context);
|
|
81
77
|
}
|
|
78
|
+
});
|
|
79
|
+
const targetReached = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
if (config.strategies.getActiveCell) {
|
|
81
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
82
|
+
if (ac && ac.rowIndex === rowIndex && ac.columnIndex === index)
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
// Locator presence: virtualized grids (e.g. Glide) often attach the target `td` after scroll
|
|
86
|
+
// while focus id lags; do not require getActiveCell to match for this to count as reached.
|
|
87
|
+
const cell = config.strategies.getCellLocator
|
|
88
|
+
? config.strategies.getCellLocator({ row: rowLocator, columnName: column, columnIndex: index, page })
|
|
89
|
+
: resolve(config.cellSelector, rowLocator).nth(index);
|
|
90
|
+
return ((yield cell.count()) > 0);
|
|
91
|
+
});
|
|
92
|
+
if (yield targetReached()) {
|
|
93
|
+
// Already there. If we have a barrier, check-in to stay in lock-step.
|
|
94
|
+
if (barrier)
|
|
95
|
+
yield barrier.sync(index);
|
|
96
|
+
const cell = config.strategies.getCellLocator
|
|
97
|
+
? config.strategies.getCellLocator({ row: rowLocator, columnName: column, columnIndex: index, page })
|
|
98
|
+
: resolve(config.cellSelector, rowLocator).nth(index);
|
|
99
|
+
return cell;
|
|
82
100
|
}
|
|
83
|
-
//
|
|
101
|
+
// If getActiveCell is present but returns null (no focus), and cell is in DOM,
|
|
102
|
+
// try to focus it once before entering navigation loop.
|
|
84
103
|
if (config.strategies.getActiveCell) {
|
|
104
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
105
|
+
if (!ac) {
|
|
106
|
+
const cell = resolve(config.cellSelector, rowLocator).nth(index);
|
|
107
|
+
if ((yield cell.count()) > 0) {
|
|
108
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', `_navigateToCell: cell "${column}" found but not focused; focusing.`);
|
|
109
|
+
yield cell.focus();
|
|
110
|
+
// Re-check target
|
|
111
|
+
if (yield targetReached()) {
|
|
112
|
+
if (barrier)
|
|
113
|
+
yield barrier.sync(index);
|
|
114
|
+
return cell;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const navigateUntilReached = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
let currRow = 0;
|
|
121
|
+
let currCol = 0;
|
|
122
|
+
if (config.strategies.getActiveCell) {
|
|
123
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
124
|
+
if (ac) {
|
|
125
|
+
currRow = ac.rowIndex;
|
|
126
|
+
currCol = ac.columnIndex;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const rDiff = rowIndex - currRow;
|
|
130
|
+
// Navigate vertically (tight loop)
|
|
131
|
+
for (let i = 0; i < Math.abs(rDiff); i++) {
|
|
132
|
+
if (rDiff > 0 && nav.goDown)
|
|
133
|
+
yield nav.goDown(context);
|
|
134
|
+
else if (rDiff < 0 && nav.goUp)
|
|
135
|
+
yield nav.goUp(context);
|
|
136
|
+
}
|
|
137
|
+
if (config.strategies.getActiveCell) {
|
|
138
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
139
|
+
if (ac) {
|
|
140
|
+
currRow = ac.rowIndex;
|
|
141
|
+
currCol = ac.columnIndex;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (index === 0 && nav.snapFirstColumnIntoView) {
|
|
145
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: snapFirstColumnIntoView for column index 0');
|
|
146
|
+
yield nav.snapFirstColumnIntoView(context);
|
|
147
|
+
if (config.strategies.getActiveCell) {
|
|
148
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
149
|
+
if (ac) {
|
|
150
|
+
currRow = ac.rowIndex;
|
|
151
|
+
currCol = ac.columnIndex;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Home moves a11y focus within the current row to column 0. If focus row !== target row
|
|
155
|
+
// (e.g. still on previous row), Home jumps to grid origin and breaks `tr.nth(k)` reads.
|
|
156
|
+
if (typeof rowIndex === 'number' && currRow === rowIndex) {
|
|
157
|
+
yield rootLocator.evaluate((el) => {
|
|
158
|
+
var _a;
|
|
159
|
+
const canvas = el.closest('canvas') || ((_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.querySelector('canvas'));
|
|
160
|
+
if (canvas instanceof HTMLCanvasElement) {
|
|
161
|
+
canvas.tabIndex = 0;
|
|
162
|
+
canvas.focus();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
yield page.keyboard.press('Home');
|
|
166
|
+
yield page.waitForTimeout(120);
|
|
167
|
+
if (config.strategies.getActiveCell) {
|
|
168
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
169
|
+
if (ac) {
|
|
170
|
+
currRow = ac.rowIndex;
|
|
171
|
+
currCol = ac.columnIndex;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
let cDiff = index - currCol;
|
|
177
|
+
if (Math.abs(cDiff) > 12 && nav.seekColumnIndex) {
|
|
178
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', `_navigateToCell: seekColumnIndex approx for column ${index}`);
|
|
179
|
+
yield nav.seekColumnIndex(context, index);
|
|
180
|
+
if (config.strategies.getActiveCell) {
|
|
181
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
182
|
+
if (ac) {
|
|
183
|
+
currRow = ac.rowIndex;
|
|
184
|
+
currCol = ac.columnIndex;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
cDiff = index - currCol;
|
|
188
|
+
}
|
|
189
|
+
for (let i = 0; i < Math.abs(cDiff); i++) {
|
|
190
|
+
if (cDiff > 0 && nav.goRight)
|
|
191
|
+
yield nav.goRight(context);
|
|
192
|
+
else if (cDiff < 0 && nav.goLeft)
|
|
193
|
+
yield nav.goLeft(context);
|
|
194
|
+
}
|
|
195
|
+
const horizontalSteps = Math.abs(cDiff);
|
|
196
|
+
if (horizontalSteps > 0) {
|
|
197
|
+
const settleMs = Math.min(2500, 60 + horizontalSteps * 12);
|
|
198
|
+
yield page.waitForTimeout(settleMs);
|
|
199
|
+
}
|
|
200
|
+
// Wait for active cell to match target: poll getActiveCell or fallback to fixed delay
|
|
201
|
+
// This is the "Midas Touch" buffer needed for Glide's async accessibility updates.
|
|
85
202
|
const pollIntervalMs = 10;
|
|
86
|
-
const maxWaitMs =
|
|
203
|
+
const maxWaitMs = Math.min(6000, 250 + horizontalSteps * 25);
|
|
87
204
|
const start = Date.now();
|
|
88
205
|
while (Date.now() - start < maxWaitMs) {
|
|
89
|
-
|
|
90
|
-
config,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
if (
|
|
96
|
-
|
|
206
|
+
if (config.strategies.getActiveCell) {
|
|
207
|
+
const ac = yield config.strategies.getActiveCell({ config, root: rootLocator, page, resolve });
|
|
208
|
+
if (ac && ac.rowIndex === rowIndex && ac.columnIndex === index) {
|
|
209
|
+
return ac.locator;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (yield targetReached()) {
|
|
213
|
+
break;
|
|
97
214
|
}
|
|
98
215
|
yield page.waitForTimeout(pollIntervalMs);
|
|
99
216
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
if (final)
|
|
107
|
-
return final.locator;
|
|
108
|
-
return null;
|
|
217
|
+
});
|
|
218
|
+
// Not there, perform (coordinated) navigation
|
|
219
|
+
let navResult;
|
|
220
|
+
if (barrier) {
|
|
221
|
+
navResult = yield barrier.sync(index, navigateUntilReached);
|
|
109
222
|
}
|
|
223
|
+
else {
|
|
224
|
+
navResult = yield navigateUntilReached();
|
|
225
|
+
}
|
|
226
|
+
if (navResult instanceof Object && navResult._isLocator) {
|
|
227
|
+
const loc = navResult;
|
|
228
|
+
if ((yield loc.count()) > 0)
|
|
229
|
+
return loc;
|
|
230
|
+
}
|
|
231
|
+
// Return final locator if reached
|
|
232
|
+
const finalCell = config.strategies.getCellLocator
|
|
233
|
+
? config.strategies.getCellLocator({ row: rowLocator, columnName: column, columnIndex: index, page })
|
|
234
|
+
: resolve(config.cellSelector, rowLocator).nth(index);
|
|
235
|
+
if ((yield finalCell.count()) > 0)
|
|
236
|
+
return finalCell;
|
|
110
237
|
return null;
|
|
111
238
|
}
|
|
112
239
|
return null;
|
|
@@ -119,12 +246,13 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
119
246
|
* @internal Internal factory for creating SmartRow objects.
|
|
120
247
|
* Not part of the public package surface; tests and consumers should use public APIs.
|
|
121
248
|
*/
|
|
122
|
-
const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table, tablePageIndex) => {
|
|
249
|
+
const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table, tablePageIndex, barrier) => {
|
|
123
250
|
const smart = rowLocator;
|
|
124
251
|
// Attach State
|
|
125
252
|
smart.rowIndex = rowIndex;
|
|
126
253
|
smart.tablePageIndex = tablePageIndex;
|
|
127
254
|
smart.table = table;
|
|
255
|
+
smart._barrier = barrier;
|
|
128
256
|
// Attach Methods
|
|
129
257
|
smart.getCell = (colName) => {
|
|
130
258
|
const idx = map.get(colName);
|
|
@@ -177,22 +305,21 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
177
305
|
})
|
|
178
306
|
: resolve(config.cellSelector, rowLocator).nth(idx);
|
|
179
307
|
let targetCell = cell;
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
308
|
+
// Always call _navigateToCell to ensure Lock-Step synchronization
|
|
309
|
+
// even if the cell is already present (it handles check-in inside)
|
|
310
|
+
const navigatedCell = yield _navigateToCell({
|
|
311
|
+
config,
|
|
312
|
+
rootLocator,
|
|
313
|
+
page,
|
|
314
|
+
resolve,
|
|
315
|
+
column: col,
|
|
316
|
+
index: idx,
|
|
317
|
+
rowLocator,
|
|
318
|
+
rowIndex,
|
|
319
|
+
barrier: smart._barrier
|
|
320
|
+
});
|
|
321
|
+
if (navigatedCell) {
|
|
322
|
+
targetCell = navigatedCell;
|
|
196
323
|
}
|
|
197
324
|
// --- Navigation Logic End ---
|
|
198
325
|
// Call beforeCellRead hook if configured.
|
|
@@ -239,7 +366,8 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
239
366
|
column: colName,
|
|
240
367
|
index: colIdx,
|
|
241
368
|
rowLocator,
|
|
242
|
-
rowIndex
|
|
369
|
+
rowIndex,
|
|
370
|
+
barrier: smart._barrier
|
|
243
371
|
});
|
|
244
372
|
const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[colName];
|
|
245
373
|
if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
|
|
@@ -10,6 +10,17 @@ export interface NavigationPrimitives {
|
|
|
10
10
|
goLeft?: (context: StrategyContext) => Promise<void>;
|
|
11
11
|
goRight?: (context: StrategyContext) => Promise<void>;
|
|
12
12
|
goHome?: (context: StrategyContext) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* After vertical moves, run before horizontal steps when the target column index is 0.
|
|
15
|
+
* Use for horizontally virtualized a11y tables (e.g. Glide) so `td[aria-colindex="1"]` exists again.
|
|
16
|
+
* Do not reset vertical scroll here — RDG-style `goHome` is often unsuitable.
|
|
17
|
+
*/
|
|
18
|
+
snapFirstColumnIntoView?: (context: StrategyContext) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Coarse horizontal reposition before goLeft/goRight steps (virtualized a11y grids).
|
|
21
|
+
* Implementations should leave a small delta for the caller to correct with primitives.
|
|
22
|
+
*/
|
|
23
|
+
seekColumnIndex?: (context: StrategyContext, columnIndex: number) => Promise<void>;
|
|
13
24
|
}
|
|
14
25
|
/**
|
|
15
26
|
* @deprecated Use NavigationPrimitives instead. This will be removed in a future version.
|
package/dist/strategies/fill.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.FillStrategies = {
|
|
|
21
21
|
const columnOverride = (_b = config === null || config === void 0 ? void 0 : config.columnOverrides) === null || _b === void 0 ? void 0 : _b[columnName];
|
|
22
22
|
if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
|
|
23
23
|
let currentValue;
|
|
24
|
-
// Auto-sync: If read exists,
|
|
24
|
+
// Auto-sync: If read exists, get current state first
|
|
25
25
|
if (columnOverride.read) {
|
|
26
26
|
currentValue = yield columnOverride.read(cell);
|
|
27
27
|
}
|
package/dist/typeContext.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* This file is generated by scripts/embed-types.mjs
|
|
4
4
|
* It contains the raw text of types.ts to provide context for LLM prompts.
|
|
5
5
|
*/
|
|
6
|
-
export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Hook called before each cell value is read in toJSON (and columnOverrides.read).\n * Use this to scroll off-screen columns into view in horizontally virtualized tables,\n * wait for lazy-rendered content, or perform any pre-read setup.\n *\n * @example\n * // Scroll the column header into view to trigger horizontal virtualization render\n * strategies: {\n * beforeCellRead: async ({ columnName, getHeaderCell }) => {\n * const header = await getHeaderCell(columnName);\n * await header.scrollIntoViewIfNeeded();\n * }\n * }\n */\nexport type BeforeCellReadFn = (args: {\n /** The resolved cell locator */\n cell: Locator;\n columnName: string;\n columnIndex: number;\n row: Locator;\n page: Page;\n root: Locator;\n /** Resolves a column name to its header cell locator */\n getHeaderCell: (columnName: string) => Promise<Locator>;\n}) => Promise<void>;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n\n /**\n * Returns whether the row exists in the DOM (i.e. is not a sentinel row).\n */\n wasFound(): boolean;\n};\n\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n};\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n /** Resolves a column name to its header cell locator. Available after table is initialized. */\n getHeaderCell?: (columnName: string) => Promise<Locator>;\n /** Returns all column names in order. Available after table is initialized. */\n getHeaders?: () => Promise<string[]>;\n /** Scrolls the table horizontally to bring the given column's header into view. */\n scrollToColumn?: (columnName: string) => Promise<void>;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /**\n * Jump to specific page index (0-indexed).\n * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6\u201314).\n * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.\n */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n\n /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */\n nextBulkPages?: number;\n\n /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */\n previousBulkPages?: number;\n}\n\nexport type PaginationStrategy = PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell.\n * `context` provides access to the parent row, permitting multi-cell logic or bypassing the default cell locator.\n */\n read?: (cell: Locator) => Promise<TValue> | TValue;\n\n /** \n * How to fill the cell with a new value. (Replaces smartFill default logic)\n * Provides the current value (via `read`) if a `write` wants to check state first.\n */\n write?: (params: {\n cell: Locator;\n targetValue: TValue;\n currentValue?: TValue;\n row: SmartRow<any>;\n }) => Promise<void>;\n}\n\nexport type { HeaderStrategy } from './strategies/headers';\n\n/**\n * Strategy to resolve column names (string or regex) to their index.\n */\nexport type { ColumnResolutionStrategy } from './strategies/resolution';\n\n/**\n * Strategy to filter rows based on criteria. Applied when using getRow/findRow/findRows with filters.\n * The default engine handles string, RegExp, number, and function (cell) => Locator filters.\n */\nexport interface FilterStrategy {\n apply(options: {\n rows: Locator;\n filter: { column: string, value: FilterValue };\n colIndex: number;\n tableContext: TableContext;\n }): Locator;\n}\n\n/**\n * Strategy to check if the table or rows are loading. Used after pagination/sort to wait for content.\n * E.g. isHeaderLoading for init stability; isTableLoading after sort/pagination.\n */\nexport interface LoadingStrategy {\n isTableLoading?: (context: TableContext) => Promise<boolean>;\n isRowLoading?: (row: SmartRow) => Promise<boolean>;\n isHeaderLoading?: (context: TableContext) => Promise<boolean>;\n}\n\n/**\n * Organized container for all table interaction strategies.\n */\nexport interface TableStrategies {\n /** Strategy for discovering/scanning headers */\n header?: HeaderStrategy;\n /** Primitive navigation functions (goUp, goDown, goLeft, goRight, goHome) */\n navigation?: NavigationPrimitives;\n\n /** Strategy for filling form inputs */\n fill?: FillStrategy;\n /** Strategy for paginating through data */\n pagination?: PaginationStrategy;\n /** Strategy for sorting columns */\n sorting?: SortingStrategy;\n /** Strategy for deduplicating rows during iteration/scrolling */\n dedupe?: DedupeStrategy;\n /** Function to get a cell locator */\n getCellLocator?: GetCellLocatorFn;\n /** Function to get the currently active/focused cell */\n getActiveCell?: GetActiveCellFn;\n /**\n * Strategy for filtering rows. If present, FilterEngine will delegate filter application\n * to this pluggable strategy.\n */\n filter?: FilterStrategy;\n /**\n * Hook called before each cell value is read in toJSON and columnOverrides.read.\n * Fires for both the default innerText extraction and custom read mappers.\n * Useful for scrolling off-screen columns into view in horizontally virtualized tables.\n */\n beforeCellRead?: BeforeCellReadFn;\n /**\n * Strategy for detecting loading states. Use this for table-, row-, and header-level readiness.\n * E.g. after sort/pagination, the engine uses loading.isTableLoading when present.\n */\n loading?: LoadingStrategy;\n}\n\n\nexport interface TableConfig<T = any> {\n /** Selector for the table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string | ((row: Locator) => Locator);\n /** Number of pages to scan for verification */\n maxPages?: number;\n /** Hook to rename columns dynamically */\n headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n\n /**\n * Unified interface for reading and writing data to specific columns.\n * Overrides both default extraction (toJSON) and filling (smartFill) logic.\n */\n columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;\n}\n\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string | ((row: Locator) => Locator);\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n\n\n/** Callback context passed to forEach, map, and filter. */\nexport type RowIterationContext<T = any> = {\n row: SmartRow<T>;\n rowIndex: number;\n stop: () => void;\n};\n\n/** Shared options for forEach, map, and filter. */\nexport type RowIterationOptions = {\n /** Maximum number of pages to iterate. Defaults to config.maxPages. */\n maxPages?: number;\n /**\n * Whether to process rows within a page concurrently.\n * @default false for forEach/filter, true for map\n */\n parallel?: boolean;\n /**\n * Deduplication strategy. Use when rows may repeat across iterations\n * (e.g. infinite scroll tables). Returns a unique key per row.\n */\n dedupe?: DedupeStrategy;\n /**\n * When true, use goNextBulk (if present) to advance pages during iteration.\n * @default false \u2014 uses goNext for one-page-at-a-time advancement\n */\n useBulkPagination?: boolean;\n};\n\nexport interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n * @note The returned SmartRow may have `rowIndex` as 0 when the match is not the first row.\n * Use getRowByIndex(index) when you need a known index (e.g. for bringIntoView()).\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 0-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 0-based row index\n */\n getRowByIndex: (\n index: number\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match (omit or pass {} for all rows)\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters?: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Iterates every row across all pages, calling the callback for side effects.\n * Execution is sequential by default (safe for interactions like clicking/filling).\n * Call `stop()` in the callback to end iteration early.\n *\n * @example\n * await table.forEach(async ({ row, stop }) => {\n * if (await row.getCell('Status').innerText() === 'Done') stop();\n * await row.getCell('Checkbox').click();\n * });\n */\n forEach(\n callback: (ctx: RowIterationContext<T>) => void | Promise<void>,\n options?: RowIterationOptions\n ): Promise<void>;\n\n /**\n * Transforms every row across all pages into a value. Returns a flat array.\n * Execution is parallel within each page by default (safe for reads).\n * Call `stop()` to halt after the current page finishes.\n *\n * > **\u26A0\uFE0F UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,\n * > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent\n * > interactions interfering with each other.\n *\n * @example\n * // Data extraction \u2014 parallel is safe\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n *\n * @example\n * // UI interactions \u2014 must use parallel: false\n * const assignees = await table.map(async ({ row }) => {\n * await row.getCell('Assignee').locator('button').click();\n * const name = await page.locator('.popover .name').innerText();\n * await page.keyboard.press('Escape');\n * return name;\n * }, { parallel: false });\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n * Automatically throws an Error containing the prompt.\n */\n generateConfig: () => Promise<void>;\n\n /**\n * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
|
|
6
|
+
export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Hook called before each cell value is read in toJSON (and columnOverrides.read).\n * Use this to scroll off-screen columns into view in horizontally virtualized tables,\n * wait for lazy-rendered content, or perform any pre-read setup.\n *\n * @example\n * // Scroll the column header into view to trigger horizontal virtualization render\n * strategies: {\n * beforeCellRead: async ({ columnName, getHeaderCell }) => {\n * const header = await getHeaderCell(columnName);\n * await header.scrollIntoViewIfNeeded();\n * }\n * }\n */\nexport type BeforeCellReadFn = (args: {\n /** The resolved cell locator */\n cell: Locator;\n columnName: string;\n columnIndex: number;\n row: Locator;\n page: Page;\n root: Locator;\n /** Resolves a column name to its header cell locator */\n getHeaderCell: (columnName: string) => Promise<Locator>;\n}) => Promise<void>;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n\n /**\n * Returns whether the row exists in the DOM (i.e. is not a sentinel row).\n */\n wasFound(): boolean;\n};\n\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n};\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n /** Resolves a column name to its header cell locator. Available after table is initialized. */\n getHeaderCell?: (columnName: string) => Promise<Locator>;\n /** Returns all column names in order. Available after table is initialized. */\n getHeaders?: () => Promise<string[]>;\n /** Scrolls the table horizontally to bring the given column's header into view. */\n scrollToColumn?: (columnName: string) => Promise<void>;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /**\n * Jump to specific page index (0-indexed).\n * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6\u201314).\n * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.\n */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n\n /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */\n nextBulkPages?: number;\n\n /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */\n previousBulkPages?: number;\n}\n\nexport type PaginationStrategy = PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell.\n * `context` provides access to the parent row, permitting multi-cell logic or bypassing the default cell locator.\n */\n read?: (cell: Locator) => Promise<TValue> | TValue;\n\n /** \n * How to fill the cell with a new value. (Replaces smartFill default logic)\n * Provides the current value (via `read`) if a `write` wants to check state first.\n */\n write?: (params: {\n cell: Locator;\n targetValue: TValue;\n currentValue?: TValue;\n row: SmartRow<any>;\n }) => Promise<void>;\n}\n\nexport type { HeaderStrategy } from './strategies/headers';\n\n/**\n * Strategy to resolve column names (string or regex) to their index.\n */\nexport type { ColumnResolutionStrategy } from './strategies/resolution';\n\n/**\n * Strategy to filter rows based on criteria. Applied when using getRow/findRow/findRows with filters.\n * The default engine handles string, RegExp, number, and function (cell) => Locator filters.\n */\nexport interface FilterStrategy {\n apply(options: {\n rows: Locator;\n filter: { column: string, value: FilterValue };\n colIndex: number;\n tableContext: TableContext;\n }): Locator;\n}\n\n/**\n * Strategy to check if the table or rows are loading. Used after pagination/sort to wait for content.\n * E.g. isHeaderLoading for init stability; isTableLoading after sort/pagination.\n */\nexport interface LoadingStrategy {\n isTableLoading?: (context: TableContext) => Promise<boolean>;\n isRowLoading?: (row: SmartRow) => Promise<boolean>;\n isHeaderLoading?: (context: TableContext) => Promise<boolean>;\n}\n\n/**\n * Organized container for all table interaction strategies.\n */\nexport interface TableStrategies {\n /** Strategy for discovering/scanning headers */\n header?: HeaderStrategy;\n /** Primitive navigation functions (goUp, goDown, goLeft, goRight, goHome) */\n navigation?: NavigationPrimitives;\n\n /** Strategy for filling form inputs */\n fill?: FillStrategy;\n /** Strategy for paginating through data */\n pagination?: PaginationStrategy;\n /** Strategy for sorting columns */\n sorting?: SortingStrategy;\n /** Strategy for deduplicating rows during iteration/scrolling */\n dedupe?: DedupeStrategy;\n /** Function to get a cell locator */\n getCellLocator?: GetCellLocatorFn;\n /** Function to get the currently active/focused cell */\n getActiveCell?: GetActiveCellFn;\n /**\n * Strategy for filtering rows. If present, FilterEngine will delegate filter application\n * to this pluggable strategy.\n */\n filter?: FilterStrategy;\n /**\n * Hook called before each cell value is read in toJSON and columnOverrides.read.\n * Fires for both the default innerText extraction and custom read mappers.\n * Useful for scrolling off-screen columns into view in horizontally virtualized tables.\n */\n beforeCellRead?: BeforeCellReadFn;\n /**\n * Strategy for detecting loading states. Use this for table-, row-, and header-level readiness.\n * E.g. after sort/pagination, the engine uses loading.isTableLoading when present.\n */\n loading?: LoadingStrategy;\n}\n\n\nexport interface TableConfig<T = any> {\n /** Selector for the table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string | ((row: Locator) => Locator);\n /** Number of pages to scan for verification */\n maxPages?: number;\n /**\n * Default concurrency strategy for iteration methods.\n * Can be overridden by the options passed to forEach, map, or filter.\n */\n concurrency?: RowIterationMode;\n /** Hook to rename columns dynamically */\n headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n\n /**\n * Unified interface for reading and writing data to specific columns.\n * Overrides both default extraction (toJSON) and filling (smartFill) logic.\n */\n columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;\n}\n\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string | ((row: Locator) => Locator);\n maxPages: number;\n autoScroll: boolean;\n concurrency?: RowIterationMode;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n\n\n/** Callback context passed to forEach, map, and filter. */\nexport type RowIterationContext<T = any> = {\n row: SmartRow<T>;\n rowIndex: number;\n stop: () => void;\n};\n\n/** Concurrency modes for row iteration. */\nexport type RowIterationMode = 'parallel' | 'sequential' | 'synchronized';\n\n/** Shared options for forEach, map, and filter. */\nexport type RowIterationOptions = {\n /** Maximum number of pages to iterate. Defaults to config.maxPages. */\n maxPages?: number;\n /**\n * @deprecated Use 'concurrency' mode instead.\n * - parallel: true -> concurrency: 'parallel'\n * - parallel: false -> concurrency: 'sequential'\n */\n parallel?: boolean;\n /**\n * Concurrency strategy for iteration.\n * - 'parallel': Full parallel execution of both navigation and actions.\n * - 'synchronized': Parallel navigation (lock-step) with serial actions.\n * - 'sequential': Strictly serial one-at-a-time execution. No parallel navigation.\n * @default 'parallel' (for map), 'sequential' (for forEach/filter)\n */\n concurrency?: RowIterationMode;\n /**\n * Deduplication strategy. Use when rows may repeat across iterations\n * (e.g. infinite scroll tables). Returns a unique key per row.\n */\n dedupe?: DedupeStrategy;\n /**\n * When true, use goNextBulk (if present) to advance pages during iteration.\n * @default false \u2014 uses goNext for one-page-at-a-time advancement\n */\n useBulkPagination?: boolean;\n};\n\nexport interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n * @note The returned SmartRow may have `rowIndex` as 0 when the match is not the first row.\n * Use getRowByIndex(index) when you need a known index (e.g. for bringIntoView()).\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 0-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 0-based row index\n */\n getRowByIndex: (\n index: number\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match (omit or pass {} for all rows)\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters?: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Iterates every row across all pages, calling the callback for side effects.\n * Execution is sequential by default (safe for interactions like clicking/filling).\n * Call `stop()` in the callback to end iteration early.\n *\n * @param callback - Function receiving { row, rowIndex, stop }\n * @param options - maxPages, concurrency, dedupe, useBulkPagination (`parallel` is deprecated; use `concurrency`)\n *\n * @example\n * await table.forEach(async ({ row, stop }) => {\n * if (await row.getCell('Status').innerText() === 'Done') stop();\n * await row.getCell('Checkbox').click();\n * });\n */\n forEach(\n callback: (ctx: RowIterationContext<T>) => void | Promise<void>,\n options?: RowIterationOptions\n ): Promise<void>;\n\n /**\n * Transforms every row across all pages into a value. Returns a flat array.\n * Execution is parallel within each page by default (safe for reads).\n * Call `stop()` to halt after the current page finishes.\n *\n * > **\u26A0\uFE0F UI Interactions:** `map` defaults to `concurrency: 'parallel'`. If your callback opens popovers,\n * > fills inputs, or otherwise mutates UI state, pass `concurrency: 'sequential'` (or `'synchronized'`\n * > when navigation must stay lock-step) to avoid overlapping interactions.\n *\n * @param callback - Function receiving { row, rowIndex, stop }\n * @param options - maxPages, concurrency, dedupe, useBulkPagination (`parallel` is deprecated; use `concurrency`)\n *\n * @example\n * // Data extraction \u2014 parallel is safe\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n *\n * @example\n * // UI interactions \u2014 use sequential (or synchronized) concurrency\n * const assignees = await table.map(async ({ row }) => {\n * await row.getCell('Assignee').locator('button').click();\n * const name = await page.locator('.popover .name').innerText();\n * await page.keyboard.press('Escape');\n * return name;\n * }, { concurrency: 'sequential' });\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @param predicate - Function receiving { row, rowIndex, stop }\n * @param options - maxPages, concurrency, dedupe, useBulkPagination (`parallel` is deprecated; use `concurrency`)\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n * Automatically throws an Error containing the prompt.\n */\n generateConfig: () => Promise<void>;\n\n /**\n * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
|
package/dist/typeContext.js
CHANGED
|
@@ -370,6 +370,11 @@ export interface TableConfig<T = any> {
|
|
|
370
370
|
cellSelector?: string | ((row: Locator) => Locator);
|
|
371
371
|
/** Number of pages to scan for verification */
|
|
372
372
|
maxPages?: number;
|
|
373
|
+
/**
|
|
374
|
+
* Default concurrency strategy for iteration methods.
|
|
375
|
+
* Can be overridden by the options passed to forEach, map, or filter.
|
|
376
|
+
*/
|
|
377
|
+
concurrency?: RowIterationMode;
|
|
373
378
|
/** Hook to rename columns dynamically */
|
|
374
379
|
headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;
|
|
375
380
|
/** Automatically scroll to table on init */
|
|
@@ -394,6 +399,7 @@ export interface FinalTableConfig<T = any> extends TableConfig<T> {
|
|
|
394
399
|
cellSelector: string | ((row: Locator) => Locator);
|
|
395
400
|
maxPages: number;
|
|
396
401
|
autoScroll: boolean;
|
|
402
|
+
concurrency?: RowIterationMode;
|
|
397
403
|
debug?: TableConfig['debug'];
|
|
398
404
|
headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;
|
|
399
405
|
onReset: (context: TableContext) => Promise<void>;
|
|
@@ -418,15 +424,27 @@ export type RowIterationContext<T = any> = {
|
|
|
418
424
|
stop: () => void;
|
|
419
425
|
};
|
|
420
426
|
|
|
427
|
+
/** Concurrency modes for row iteration. */
|
|
428
|
+
export type RowIterationMode = 'parallel' | 'sequential' | 'synchronized';
|
|
429
|
+
|
|
421
430
|
/** Shared options for forEach, map, and filter. */
|
|
422
431
|
export type RowIterationOptions = {
|
|
423
432
|
/** Maximum number of pages to iterate. Defaults to config.maxPages. */
|
|
424
433
|
maxPages?: number;
|
|
425
434
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
435
|
+
* @deprecated Use 'concurrency' mode instead.
|
|
436
|
+
* - parallel: true -> concurrency: 'parallel'
|
|
437
|
+
* - parallel: false -> concurrency: 'sequential'
|
|
428
438
|
*/
|
|
429
439
|
parallel?: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Concurrency strategy for iteration.
|
|
442
|
+
* - 'parallel': Full parallel execution of both navigation and actions.
|
|
443
|
+
* - 'synchronized': Parallel navigation (lock-step) with serial actions.
|
|
444
|
+
* - 'sequential': Strictly serial one-at-a-time execution. No parallel navigation.
|
|
445
|
+
* @default 'parallel' (for map), 'sequential' (for forEach/filter)
|
|
446
|
+
*/
|
|
447
|
+
concurrency?: RowIterationMode;
|
|
430
448
|
/**
|
|
431
449
|
* Deduplication strategy. Use when rows may repeat across iterations
|
|
432
450
|
* (e.g. infinite scroll tables). Returns a unique key per row.
|
|
@@ -526,6 +544,9 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
526
544
|
* Execution is sequential by default (safe for interactions like clicking/filling).
|
|
527
545
|
* Call \`stop()\` in the callback to end iteration early.
|
|
528
546
|
*
|
|
547
|
+
* @param callback - Function receiving { row, rowIndex, stop }
|
|
548
|
+
* @param options - maxPages, concurrency, dedupe, useBulkPagination (\`parallel\` is deprecated; use \`concurrency\`)
|
|
549
|
+
*
|
|
529
550
|
* @example
|
|
530
551
|
* await table.forEach(async ({ row, stop }) => {
|
|
531
552
|
* if (await row.getCell('Status').innerText() === 'Done') stop();
|
|
@@ -542,22 +563,25 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
542
563
|
* Execution is parallel within each page by default (safe for reads).
|
|
543
564
|
* Call \`stop()\` to halt after the current page finishes.
|
|
544
565
|
*
|
|
545
|
-
* > **⚠️ UI Interactions:** \`map\` defaults to \`
|
|
546
|
-
* > fills inputs, or otherwise mutates UI state, pass \`
|
|
547
|
-
* >
|
|
566
|
+
* > **⚠️ UI Interactions:** \`map\` defaults to \`concurrency: 'parallel'\`. If your callback opens popovers,
|
|
567
|
+
* > fills inputs, or otherwise mutates UI state, pass \`concurrency: 'sequential'\` (or \`'synchronized'\`
|
|
568
|
+
* > when navigation must stay lock-step) to avoid overlapping interactions.
|
|
569
|
+
*
|
|
570
|
+
* @param callback - Function receiving { row, rowIndex, stop }
|
|
571
|
+
* @param options - maxPages, concurrency, dedupe, useBulkPagination (\`parallel\` is deprecated; use \`concurrency\`)
|
|
548
572
|
*
|
|
549
573
|
* @example
|
|
550
574
|
* // Data extraction — parallel is safe
|
|
551
575
|
* const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
552
576
|
*
|
|
553
577
|
* @example
|
|
554
|
-
* // UI interactions —
|
|
578
|
+
* // UI interactions — use sequential (or synchronized) concurrency
|
|
555
579
|
* const assignees = await table.map(async ({ row }) => {
|
|
556
580
|
* await row.getCell('Assignee').locator('button').click();
|
|
557
581
|
* const name = await page.locator('.popover .name').innerText();
|
|
558
582
|
* await page.keyboard.press('Escape');
|
|
559
583
|
* return name;
|
|
560
|
-
* }, {
|
|
584
|
+
* }, { concurrency: 'sequential' });
|
|
561
585
|
*/
|
|
562
586
|
map<R>(
|
|
563
587
|
callback: (ctx: RowIterationContext<T>) => R | Promise<R>,
|
|
@@ -569,6 +593,9 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
569
593
|
* Rows are returned as-is — call \`bringIntoView()\` on each if needed.
|
|
570
594
|
* Execution is sequential by default.
|
|
571
595
|
*
|
|
596
|
+
* @param predicate - Function receiving { row, rowIndex, stop }
|
|
597
|
+
* @param options - maxPages, concurrency, dedupe, useBulkPagination (\`parallel\` is deprecated; use \`concurrency\`)
|
|
598
|
+
*
|
|
572
599
|
* @example
|
|
573
600
|
* const active = await table.filter(async ({ row }) =>
|
|
574
601
|
* await row.getCell('Status').innerText() === 'Active'
|