@rickcedwhat/playwright-smart-table 6.5.0 → 6.7.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 +68 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +8 -18
- package/dist/smartRow.js +3 -3
- package/dist/strategies/index.d.ts +10 -12
- package/dist/strategies/pagination.d.ts +2 -18
- package/dist/strategies/pagination.js +2 -17
- package/dist/strategies/sorting.js +19 -32
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +90 -64
- package/dist/types.d.ts +73 -73
- package/dist/useTable.js +248 -231
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,13 +76,66 @@ const email = await row.getCell('Email').textContent();
|
|
|
76
76
|
const allActive = await table.findRows({ Status: 'Active' });
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
### Iterating Across Pages
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// forEach — sequential, safe for interactions (parallel: false default)
|
|
83
|
+
await table.forEach(async ({ row, rowIndex, stop }) => {
|
|
84
|
+
if (await row.getCell('Status').innerText() === 'Done') stop();
|
|
85
|
+
await row.getCell('Checkbox').click();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// map — parallel within page, safe for reads (parallel: true default)
|
|
89
|
+
const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
90
|
+
|
|
91
|
+
// filter — async predicate across all pages, returns SmartRowArray
|
|
92
|
+
const active = await table.filter(async ({ row }) =>
|
|
93
|
+
await row.getCell('Status').innerText() === 'Active'
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// for await...of — low-level page-by-page iteration
|
|
97
|
+
for await (const { row, rowIndex } of table) {
|
|
98
|
+
console.log(rowIndex, await row.getCell('Name').innerText());
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
> **`map` + UI interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,
|
|
103
|
+
> fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid overlapping interactions.
|
|
104
|
+
|
|
105
|
+
### `filter` vs `findRows`
|
|
106
|
+
|
|
107
|
+
| Use case | Best tool |
|
|
108
|
+
|---|---|
|
|
109
|
+
| Match by column value / regex / locator | `findRows` |
|
|
110
|
+
| Computed value (math, range, derived) | `filter` |
|
|
111
|
+
| Cross-column OR logic | `filter` |
|
|
112
|
+
| Multi-step interaction in predicate (click, read, close) | `filter` |
|
|
113
|
+
| Early exit after N matches | `filter` + `stop()` |
|
|
114
|
+
|
|
115
|
+
**`findRows` is faster** for column-value matches — Playwright evaluates the locator natively with no DOM reads. **`filter` is more flexible** for logic that a CSS selector can't express.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// findRows — structural match, no DOM reads, fast
|
|
119
|
+
const notStarted = await table.findRows({
|
|
120
|
+
Status: (cell) => cell.locator('[class*="gray"]')
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// filter — arbitrary async logic
|
|
124
|
+
const expensive = await table.filter(async ({ row }) => {
|
|
125
|
+
const price = parseFloat(await row.getCell('Price').innerText());
|
|
126
|
+
const qty = parseFloat(await row.getCell('Qty').innerText());
|
|
127
|
+
return price * qty > 1000;
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
79
131
|
## Key Features
|
|
80
132
|
|
|
81
133
|
- 🎯 **Smart Locators** - Find rows by content, not position
|
|
82
|
-
- 🧠 **Fuzzy Matching** - Smart suggestions for typos
|
|
134
|
+
- 🧠 **Fuzzy Matching** - Smart suggestions for typos in column names
|
|
83
135
|
- ⚡ **Smart Initialization** - Handles loading states and dynamic headers automatically
|
|
84
136
|
- 📄 **Auto-Pagination** - Search across all pages automatically
|
|
85
137
|
- 🔍 **Column-Aware Access** - Access cells by column name
|
|
138
|
+
- 🔁 **Iteration Methods** - `forEach`, `map`, `filter`, and `for await...of` across all pages
|
|
86
139
|
- 🛠️ **Debug Mode** - Visual debugging with slow motion and logging
|
|
87
140
|
- 🔌 **[Extensible Strategies](docs/concepts/strategies.md)** - Support any table implementation
|
|
88
141
|
- 💪 **Type-Safe** - Full TypeScript support
|
|
@@ -108,11 +161,21 @@ const allActive = await table.findRows({ Status: 'Active' });
|
|
|
108
161
|
|
|
109
162
|
### ⚠️ Important Note on Pagination & Interactions
|
|
110
163
|
|
|
111
|
-
When
|
|
164
|
+
When `findRows` or `filter` paginates across pages, returned `SmartRow` locators point to rows that may be off the current DOM page.
|
|
112
165
|
|
|
113
|
-
- **Data
|
|
114
|
-
- **Interactions
|
|
115
|
-
|
|
166
|
+
- **Data extraction:** Safe — `toJSON()` and cell reads work while the row is visible during iteration.
|
|
167
|
+
- **Interactions after pagination:** Use `await row.bringIntoView()` first — it navigates back to the page the row was originally found on, then you can safely click/fill.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const active = await table.filter(async ({ row }) =>
|
|
171
|
+
await row.getCell('Status').innerText() === 'Active'
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
for (const row of active) {
|
|
175
|
+
await row.bringIntoView(); // navigate back to the row's page
|
|
176
|
+
await row.getCell('Checkbox').click(); // safe to interact
|
|
177
|
+
}
|
|
178
|
+
```
|
|
116
179
|
|
|
117
180
|
## Documentation
|
|
118
181
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { useTable } from './useTable';
|
|
2
|
+
export type { TableConfig, TableResult, SmartRow, Selector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, } from './types';
|
|
3
|
+
export { Strategies } from './strategies';
|
|
4
|
+
export { Plugins } from './plugins';
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
exports.Plugins = exports.Strategies = exports.useTable = void 0;
|
|
4
|
+
var useTable_1 = require("./useTable");
|
|
5
|
+
Object.defineProperty(exports, "useTable", { enumerable: true, get: function () { return useTable_1.useTable; } });
|
|
6
|
+
// Export namespace-like strategy collections
|
|
7
|
+
var strategies_1 = require("./strategies");
|
|
8
|
+
Object.defineProperty(exports, "Strategies", { enumerable: true, get: function () { return strategies_1.Strategies; } });
|
|
9
|
+
var plugins_1 = require("./plugins");
|
|
10
|
+
Object.defineProperty(exports, "Plugins", { enumerable: true, get: function () { return plugins_1.Plugins; } });
|
package/dist/smartRow.js
CHANGED
|
@@ -122,16 +122,16 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
122
122
|
return resolve(config.cellSelector, rowLocator).nth(idx);
|
|
123
123
|
};
|
|
124
124
|
smart.toJSON = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
-
var _a
|
|
125
|
+
var _a;
|
|
126
126
|
const result = {};
|
|
127
127
|
const page = rootLocator.page();
|
|
128
128
|
for (const [col, idx] of map.entries()) {
|
|
129
129
|
if ((options === null || options === void 0 ? void 0 : options.columns) && !options.columns.includes(col)) {
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
|
-
// Check if we have a column override
|
|
132
|
+
// Check if we have a column override for this column
|
|
133
133
|
const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[col];
|
|
134
|
-
const mapper =
|
|
134
|
+
const mapper = columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.read;
|
|
135
135
|
if (mapper) {
|
|
136
136
|
// Use custom mapper
|
|
137
137
|
// Ensure we have the cell first (same navigation logic)
|
|
@@ -8,25 +8,23 @@ export * from './dedupe';
|
|
|
8
8
|
export * from './loading';
|
|
9
9
|
export declare const Strategies: {
|
|
10
10
|
Pagination: {
|
|
11
|
-
clickNext: (nextButtonSelector: import("..").Selector, options?: {
|
|
12
|
-
stabilization?: import("./stabilization").StabilizationStrategy;
|
|
13
|
-
timeout?: number;
|
|
14
|
-
}) => import("..").PaginationStrategy;
|
|
15
11
|
click: (selectors: {
|
|
16
12
|
next?: import("..").Selector;
|
|
17
13
|
previous?: import("..").Selector;
|
|
14
|
+
nextBulk?: import("..").Selector;
|
|
15
|
+
previousBulk?: import("..").Selector;
|
|
18
16
|
first?: import("..").Selector;
|
|
19
17
|
}, options?: {
|
|
20
18
|
stabilization?: import("./stabilization").StabilizationStrategy;
|
|
21
19
|
timeout?: number;
|
|
22
|
-
}) => import("
|
|
20
|
+
}) => import("../types").PaginationStrategy;
|
|
23
21
|
infiniteScroll: (options?: {
|
|
24
22
|
action?: "scroll" | "js-scroll";
|
|
25
23
|
scrollTarget?: import("..").Selector;
|
|
26
24
|
scrollAmount?: number;
|
|
27
25
|
stabilization?: import("./stabilization").StabilizationStrategy;
|
|
28
26
|
timeout?: number;
|
|
29
|
-
}) => import("
|
|
27
|
+
}) => import("../types").PaginationStrategy;
|
|
30
28
|
};
|
|
31
29
|
Sorting: {
|
|
32
30
|
AriaSort: () => import("..").SortingStrategy;
|
|
@@ -35,21 +33,21 @@ export declare const Strategies: {
|
|
|
35
33
|
default: () => Promise<void>;
|
|
36
34
|
};
|
|
37
35
|
Header: {
|
|
38
|
-
visible: ({ config, resolve, root }: import("
|
|
36
|
+
visible: ({ config, resolve, root }: import("../types").StrategyContext) => Promise<string[]>;
|
|
39
37
|
};
|
|
40
38
|
Fill: {
|
|
41
|
-
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("
|
|
39
|
+
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("../types").FillStrategy>[0]) => Promise<void>;
|
|
42
40
|
};
|
|
43
41
|
Resolution: {
|
|
44
42
|
default: import("./resolution").ColumnResolutionStrategy;
|
|
45
43
|
};
|
|
46
44
|
Dedupe: {
|
|
47
|
-
byTopPosition: (tolerance?: number) => import("
|
|
45
|
+
byTopPosition: (tolerance?: number) => import("../types").DedupeStrategy;
|
|
48
46
|
};
|
|
49
47
|
Loading: {
|
|
50
48
|
Table: {
|
|
51
|
-
hasSpinner: (selector?: string) => ({ root }: import("
|
|
52
|
-
custom: (fn: (context: import("
|
|
49
|
+
hasSpinner: (selector?: string) => ({ root }: import("../types").TableContext) => Promise<boolean>;
|
|
50
|
+
custom: (fn: (context: import("../types").TableContext) => Promise<boolean>) => (context: import("../types").TableContext) => Promise<boolean>;
|
|
53
51
|
never: () => Promise<boolean>;
|
|
54
52
|
};
|
|
55
53
|
Row: {
|
|
@@ -59,7 +57,7 @@ export declare const Strategies: {
|
|
|
59
57
|
never: () => Promise<boolean>;
|
|
60
58
|
};
|
|
61
59
|
Headers: {
|
|
62
|
-
stable: (duration?: number) => (context: import("
|
|
60
|
+
stable: (duration?: number) => (context: import("../types").TableContext) => Promise<boolean>;
|
|
63
61
|
never: () => Promise<boolean>;
|
|
64
62
|
};
|
|
65
63
|
};
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
import type { PaginationStrategy, Selector } from '../types';
|
|
2
2
|
import { StabilizationStrategy } from './stabilization';
|
|
3
3
|
export declare const PaginationStrategies: {
|
|
4
|
-
/**
|
|
5
|
-
* Strategy: Clicks a "Next" button and waits for stabilization.
|
|
6
|
-
* Backward compatibility for when only a single 'next' selector was needed.
|
|
7
|
-
* @deprecated Use `click` with `{ next: selector }` instead.
|
|
8
|
-
*/
|
|
9
|
-
clickNext: (nextButtonSelector: Selector, options?: {
|
|
10
|
-
stabilization?: StabilizationStrategy;
|
|
11
|
-
timeout?: number;
|
|
12
|
-
}) => PaginationStrategy;
|
|
13
|
-
/**
|
|
14
|
-
* Strategy: Classic Pagination Buttons.
|
|
15
|
-
* Clicks 'Next', 'Previous', or 'First' buttons and waits for stabilization.
|
|
16
|
-
*
|
|
17
|
-
* @param selectors Selectors for pagination buttons.
|
|
18
|
-
* @param options.stabilization Strategy to determine when the page has updated.
|
|
19
|
-
* Defaults to `contentChanged({ scope: 'first' })`.
|
|
20
|
-
* @param options.timeout Timeout for the click action.
|
|
21
|
-
*/
|
|
22
4
|
click: (selectors: {
|
|
23
5
|
next?: Selector;
|
|
24
6
|
previous?: Selector;
|
|
7
|
+
nextBulk?: Selector;
|
|
8
|
+
previousBulk?: Selector;
|
|
25
9
|
first?: Selector;
|
|
26
10
|
}, options?: {
|
|
27
11
|
stabilization?: StabilizationStrategy;
|
|
@@ -12,23 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PaginationStrategies = void 0;
|
|
13
13
|
const stabilization_1 = require("./stabilization");
|
|
14
14
|
exports.PaginationStrategies = {
|
|
15
|
-
/**
|
|
16
|
-
* Strategy: Clicks a "Next" button and waits for stabilization.
|
|
17
|
-
* Backward compatibility for when only a single 'next' selector was needed.
|
|
18
|
-
* @deprecated Use `click` with `{ next: selector }` instead.
|
|
19
|
-
*/
|
|
20
|
-
clickNext: (nextButtonSelector, options = {}) => {
|
|
21
|
-
return exports.PaginationStrategies.click({ next: nextButtonSelector }, options);
|
|
22
|
-
},
|
|
23
|
-
/**
|
|
24
|
-
* Strategy: Classic Pagination Buttons.
|
|
25
|
-
* Clicks 'Next', 'Previous', or 'First' buttons and waits for stabilization.
|
|
26
|
-
*
|
|
27
|
-
* @param selectors Selectors for pagination buttons.
|
|
28
|
-
* @param options.stabilization Strategy to determine when the page has updated.
|
|
29
|
-
* Defaults to `contentChanged({ scope: 'first' })`.
|
|
30
|
-
* @param options.timeout Timeout for the click action.
|
|
31
|
-
*/
|
|
32
15
|
click: (selectors, options = {}) => {
|
|
33
16
|
var _a;
|
|
34
17
|
const defaultStabilize = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.contentChanged({ scope: 'first', timeout: options.timeout });
|
|
@@ -49,6 +32,8 @@ exports.PaginationStrategies = {
|
|
|
49
32
|
return {
|
|
50
33
|
goNext: createClicker(selectors.next),
|
|
51
34
|
goPrevious: createClicker(selectors.previous),
|
|
35
|
+
goNextBulk: createClicker(selectors.nextBulk),
|
|
36
|
+
goPreviousBulk: createClicker(selectors.previousBulk),
|
|
52
37
|
goToFirst: createClicker(selectors.first)
|
|
53
38
|
};
|
|
54
39
|
},
|
|
@@ -23,44 +23,31 @@ exports.SortingStrategies = {
|
|
|
23
23
|
return {
|
|
24
24
|
doSort(_a) {
|
|
25
25
|
return __awaiter(this, arguments, void 0, function* ({ columnName, direction, context }) {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
throw new Error(`[AriaSort] Header with text "${columnName}" not found.`);
|
|
33
|
-
}
|
|
34
|
-
const targetHeader = headers[columnIndex];
|
|
35
|
-
// Click repeatedly to cycle through sort states
|
|
36
|
-
for (let i = 0; i < 3; i++) { // Max 3 clicks to prevent infinite loops (none -> asc -> desc)
|
|
37
|
-
const currentState = yield targetHeader.getAttribute('aria-sort');
|
|
38
|
-
const mappedState = currentState === 'ascending' ? 'asc' : currentState === 'descending' ? 'desc' : 'none';
|
|
39
|
-
if (mappedState === direction) {
|
|
40
|
-
return; // Desired state achieved
|
|
41
|
-
}
|
|
42
|
-
yield targetHeader.click();
|
|
43
|
-
}
|
|
44
|
-
throw new Error(`[AriaSort] Could not achieve sort direction "${direction}" for column "${columnName}" after 3 clicks.`);
|
|
26
|
+
const { getHeaderCell } = context;
|
|
27
|
+
if (!getHeaderCell)
|
|
28
|
+
throw new Error('getHeaderCell is required in StrategyContext for sorting.');
|
|
29
|
+
// The table engine handles verify-and-retry. We only provide the trigger here.
|
|
30
|
+
const targetHeader = yield getHeaderCell(columnName);
|
|
31
|
+
yield targetHeader.click();
|
|
45
32
|
});
|
|
46
33
|
},
|
|
47
34
|
getSortState(_a) {
|
|
48
35
|
return __awaiter(this, arguments, void 0, function* ({ columnName, context }) {
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
const { getHeaderCell } = context;
|
|
37
|
+
try {
|
|
38
|
+
if (!getHeaderCell)
|
|
39
|
+
throw new Error('getHeaderCell is required');
|
|
40
|
+
const targetHeader = yield getHeaderCell(columnName);
|
|
41
|
+
const ariaSort = yield targetHeader.getAttribute('aria-sort');
|
|
42
|
+
if (ariaSort === 'ascending')
|
|
43
|
+
return 'asc';
|
|
44
|
+
if (ariaSort === 'descending')
|
|
45
|
+
return 'desc';
|
|
46
|
+
return 'none';
|
|
47
|
+
}
|
|
48
|
+
catch (_b) {
|
|
55
49
|
return 'none'; // Header not found, so it's not sorted
|
|
56
50
|
}
|
|
57
|
-
const targetHeader = headers[columnIndex];
|
|
58
|
-
const ariaSort = yield targetHeader.getAttribute('aria-sort');
|
|
59
|
-
if (ariaSort === 'ascending')
|
|
60
|
-
return 'asc';
|
|
61
|
-
if (ariaSort === 'descending')
|
|
62
|
-
return 'desc';
|
|
63
|
-
return 'none';
|
|
64
51
|
});
|
|
65
52
|
},
|
|
66
53
|
};
|
package/dist/typeContext.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* This file is generated by scripts/embed-types.js
|
|
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 * 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\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\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}\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 /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to specific page index (0-indexed) */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n}\n\nexport type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | 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. (Replaces dataMapper logic)\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.\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.\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 /** Custom helper to check if a table is fully loaded/ready */\n isTableLoaded?: (args: TableContext) => Promise<boolean>;\n /** Custom helper to check if a row is fully loaded/ready */\n isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;\n /** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */\n isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;\n /** Strategy for detecting loading states */\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;\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 * @deprecated Use `columnOverrides` instead. `dataMapper` will be removed in v7.0.0.\n * Custom data mappers for specific columns.\n * Allows extracting complex data types (boolean, number) instead of just string.\n */\n dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;\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;\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 * Options for generateConfigPrompt\n */\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n /**\n * Include TypeScript type definitions in the prompt\n * @default true\n */\n includeTypes?: boolean;\n}\n\nexport interface TableResult<T = any> {\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 */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\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\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 * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\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 * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRowArray;\n allData: T[];\n table: RestrictedTableResult;\n batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n\n }) => T | T[] | Promise<T | T[]>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n batchSize?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n /**\n * If true, flattens array results from callback into the main data array.\n * If false (default), pushes the return value as-is (preserves batching/arrays).\n */\n autoFlatten?: boolean;\n }\n ) => Promise<T[]>;\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 */\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;\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 * 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\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n /** Helper to reliably get a header cell locator by name */\n getHeaderCell?: (headerName: string) => Promise<Locator>;\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}\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 */\n goNextBulk?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip backward multiple pages at once */\n goPreviousBulk?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to specific page index (0-indexed) */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n}\n\nexport type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | 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. (Replaces dataMapper logic)\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.\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.\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 /** Custom helper to check if a table is fully loaded/ready */\n isTableLoaded?: (args: TableContext) => Promise<boolean>;\n /** Custom helper to check if a row is fully loaded/ready */\n isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;\n /** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */\n isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;\n /** Strategy for detecting loading states */\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;\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;\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\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 */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\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\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 generateConfigPrompt: () => Promise<void>;\n}\n";
|