@rickcedwhat/playwright-smart-table 6.6.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 +29 -75
- package/dist/types.d.ts +22 -83
- package/dist/useTable.js +60 -273
- 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\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 * @example\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\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 * Scans a specific column across all pages and returns the values.\n * @deprecated Use `table.map(({ row }) => row.getCell(column).innerText())` instead.\n * Will be removed in v7.0.0.\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 * @deprecated Use `forEach`, `map`, or `filter` instead for cleaner cross-page iteration.\n * Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).\n * Will be removed in v7.0.0.\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";
|
package/dist/typeContext.js
CHANGED
|
@@ -128,7 +128,12 @@ export type SmartRow<T = any> = Locator & {
|
|
|
128
128
|
smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
export type StrategyContext = TableContext & {
|
|
131
|
+
export type StrategyContext = TableContext & {
|
|
132
|
+
rowLocator?: Locator;
|
|
133
|
+
rowIndex?: number;
|
|
134
|
+
/** Helper to reliably get a header cell locator by name */
|
|
135
|
+
getHeaderCell?: (headerName: string) => Promise<Locator>;
|
|
136
|
+
};
|
|
132
137
|
|
|
133
138
|
/**
|
|
134
139
|
* Defines the contract for a sorting strategy.
|
|
@@ -191,6 +196,12 @@ export interface PaginationPrimitives {
|
|
|
191
196
|
/** Classic "Previous Page" or "Scroll Up" */
|
|
192
197
|
goPrevious?: (context: TableContext) => Promise<boolean>;
|
|
193
198
|
|
|
199
|
+
/** Bulk skip forward multiple pages at once */
|
|
200
|
+
goNextBulk?: (context: TableContext) => Promise<boolean>;
|
|
201
|
+
|
|
202
|
+
/** Bulk skip backward multiple pages at once */
|
|
203
|
+
goPreviousBulk?: (context: TableContext) => Promise<boolean>;
|
|
204
|
+
|
|
194
205
|
/** Jump to first page / scroll to top */
|
|
195
206
|
goToFirst?: (context: TableContext) => Promise<boolean>;
|
|
196
207
|
|
|
@@ -313,12 +324,6 @@ export interface TableConfig<T = any> {
|
|
|
313
324
|
onReset?: (context: TableContext) => Promise<void>;
|
|
314
325
|
/** All interaction strategies */
|
|
315
326
|
strategies?: TableStrategies;
|
|
316
|
-
/**
|
|
317
|
-
* @deprecated Use \`columnOverrides\` instead. \`dataMapper\` will be removed in v7.0.0.
|
|
318
|
-
* Custom data mappers for specific columns.
|
|
319
|
-
* Allows extracting complex data types (boolean, number) instead of just string.
|
|
320
|
-
*/
|
|
321
|
-
dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
|
|
322
327
|
|
|
323
328
|
/**
|
|
324
329
|
* Unified interface for reading and writing data to specific columns.
|
|
@@ -348,22 +353,7 @@ export interface FillOptions {
|
|
|
348
353
|
inputMappers?: Record<string, (cell: Locator) => Locator>;
|
|
349
354
|
}
|
|
350
355
|
|
|
351
|
-
|
|
352
|
-
* Options for generateConfigPrompt
|
|
353
|
-
*/
|
|
354
|
-
export interface PromptOptions {
|
|
355
|
-
/**
|
|
356
|
-
* Output Strategy:
|
|
357
|
-
* - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).
|
|
358
|
-
* - 'console': Standard console logs (Default).
|
|
359
|
-
*/
|
|
360
|
-
output?: 'console' | 'error';
|
|
361
|
-
/**
|
|
362
|
-
* Include TypeScript type definitions in the prompt
|
|
363
|
-
* @default true
|
|
364
|
-
*/
|
|
365
|
-
includeTypes?: boolean;
|
|
366
|
-
}
|
|
356
|
+
|
|
367
357
|
|
|
368
358
|
/** Callback context passed to forEach, map, and filter. */
|
|
369
359
|
export type RowIterationContext<T = any> = {
|
|
@@ -491,8 +481,22 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
491
481
|
* Execution is parallel within each page by default (safe for reads).
|
|
492
482
|
* Call \`stop()\` to halt after the current page finishes.
|
|
493
483
|
*
|
|
484
|
+
* > **⚠️ UI Interactions:** \`map\` defaults to \`parallel: true\`. If your callback opens popovers,
|
|
485
|
+
* > fills inputs, or otherwise mutates UI state, pass \`{ parallel: false }\` to avoid concurrent
|
|
486
|
+
* > interactions interfering with each other.
|
|
487
|
+
*
|
|
494
488
|
* @example
|
|
489
|
+
* // Data extraction — parallel is safe
|
|
495
490
|
* const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* // UI interactions — must use parallel: false
|
|
494
|
+
* const assignees = await table.map(async ({ row }) => {
|
|
495
|
+
* await row.getCell('Assignee').locator('button').click();
|
|
496
|
+
* const name = await page.locator('.popover .name').innerText();
|
|
497
|
+
* await page.keyboard.press('Escape');
|
|
498
|
+
* return name;
|
|
499
|
+
* }, { parallel: false });
|
|
496
500
|
*/
|
|
497
501
|
map<R>(
|
|
498
502
|
callback: (ctx: RowIterationContext<T>) => R | Promise<R>,
|
|
@@ -514,13 +518,6 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
514
518
|
options?: RowIterationOptions
|
|
515
519
|
): Promise<SmartRowArray<T>>;
|
|
516
520
|
|
|
517
|
-
/**
|
|
518
|
-
* Scans a specific column across all pages and returns the values.
|
|
519
|
-
* @deprecated Use \`table.map(({ row }) => row.getCell(column).innerText())\` instead.
|
|
520
|
-
* Will be removed in v7.0.0.
|
|
521
|
-
*/
|
|
522
|
-
getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;
|
|
523
|
-
|
|
524
521
|
/**
|
|
525
522
|
* Provides access to sorting actions and assertions.
|
|
526
523
|
*/
|
|
@@ -539,54 +536,11 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
539
536
|
getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;
|
|
540
537
|
};
|
|
541
538
|
|
|
542
|
-
/**
|
|
543
|
-
* Iterates through paginated table data, calling the callback for each iteration.
|
|
544
|
-
* Callback return values are automatically appended to allData, which is returned.
|
|
545
|
-
* @deprecated Use \`forEach\`, \`map\`, or \`filter\` instead for cleaner cross-page iteration.
|
|
546
|
-
* Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).
|
|
547
|
-
* Will be removed in v7.0.0.
|
|
548
|
-
*/
|
|
549
|
-
iterateThroughTable: <T = any>(
|
|
550
|
-
callback: (context: {
|
|
551
|
-
index: number;
|
|
552
|
-
isFirst: boolean;
|
|
553
|
-
isLast: boolean;
|
|
554
|
-
rows: SmartRowArray;
|
|
555
|
-
allData: T[];
|
|
556
|
-
table: RestrictedTableResult;
|
|
557
|
-
batchInfo?: {
|
|
558
|
-
startIndex: number;
|
|
559
|
-
endIndex: number;
|
|
560
|
-
size: number;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
}) => T | T[] | Promise<T | T[]>,
|
|
564
|
-
options?: {
|
|
565
|
-
pagination?: PaginationStrategy;
|
|
566
|
-
dedupeStrategy?: DedupeStrategy;
|
|
567
|
-
maxIterations?: number;
|
|
568
|
-
batchSize?: number;
|
|
569
|
-
getIsFirst?: (context: { index: number }) => boolean;
|
|
570
|
-
getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;
|
|
571
|
-
beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
572
|
-
afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
573
|
-
/**
|
|
574
|
-
* If true, flattens array results from callback into the main data array.
|
|
575
|
-
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
576
|
-
*/
|
|
577
|
-
autoFlatten?: boolean;
|
|
578
|
-
}
|
|
579
|
-
) => Promise<T[]>;
|
|
580
|
-
|
|
581
539
|
/**
|
|
582
540
|
* Generate an AI-friendly configuration prompt for debugging.
|
|
583
541
|
* Outputs table HTML and TypeScript definitions to help AI assistants generate config.
|
|
542
|
+
* Automatically throws an Error containing the prompt.
|
|
584
543
|
*/
|
|
585
|
-
generateConfigPrompt: (
|
|
544
|
+
generateConfigPrompt: () => Promise<void>;
|
|
586
545
|
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Restricted table result that excludes methods that shouldn't be called during iteration.
|
|
590
|
-
*/
|
|
591
|
-
export type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;
|
|
592
546
|
`;
|
package/dist/types.d.ts
CHANGED
|
@@ -114,6 +114,8 @@ export type SmartRow<T = any> = Locator & {
|
|
|
114
114
|
export type StrategyContext = TableContext & {
|
|
115
115
|
rowLocator?: Locator;
|
|
116
116
|
rowIndex?: number;
|
|
117
|
+
/** Helper to reliably get a header cell locator by name */
|
|
118
|
+
getHeaderCell?: (headerName: string) => Promise<Locator>;
|
|
117
119
|
};
|
|
118
120
|
/**
|
|
119
121
|
* Defines the contract for a sorting strategy.
|
|
@@ -170,6 +172,10 @@ export interface PaginationPrimitives {
|
|
|
170
172
|
goNext?: (context: TableContext) => Promise<boolean>;
|
|
171
173
|
/** Classic "Previous Page" or "Scroll Up" */
|
|
172
174
|
goPrevious?: (context: TableContext) => Promise<boolean>;
|
|
175
|
+
/** Bulk skip forward multiple pages at once */
|
|
176
|
+
goNextBulk?: (context: TableContext) => Promise<boolean>;
|
|
177
|
+
/** Bulk skip backward multiple pages at once */
|
|
178
|
+
goPreviousBulk?: (context: TableContext) => Promise<boolean>;
|
|
173
179
|
/** Jump to first page / scroll to top */
|
|
174
180
|
goToFirst?: (context: TableContext) => Promise<boolean>;
|
|
175
181
|
/** Jump to specific page index (0-indexed) */
|
|
@@ -293,12 +299,6 @@ export interface TableConfig<T = any> {
|
|
|
293
299
|
onReset?: (context: TableContext) => Promise<void>;
|
|
294
300
|
/** All interaction strategies */
|
|
295
301
|
strategies?: TableStrategies;
|
|
296
|
-
/**
|
|
297
|
-
* @deprecated Use `columnOverrides` instead. `dataMapper` will be removed in v7.0.0.
|
|
298
|
-
* Custom data mappers for specific columns.
|
|
299
|
-
* Allows extracting complex data types (boolean, number) instead of just string.
|
|
300
|
-
*/
|
|
301
|
-
dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
|
|
302
302
|
/**
|
|
303
303
|
* Unified interface for reading and writing data to specific columns.
|
|
304
304
|
* Overrides both default extraction (toJSON) and filling (smartFill) logic.
|
|
@@ -328,22 +328,6 @@ export interface FillOptions {
|
|
|
328
328
|
*/
|
|
329
329
|
inputMappers?: Record<string, (cell: Locator) => Locator>;
|
|
330
330
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Options for generateConfigPrompt
|
|
333
|
-
*/
|
|
334
|
-
export interface PromptOptions {
|
|
335
|
-
/**
|
|
336
|
-
* Output Strategy:
|
|
337
|
-
* - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).
|
|
338
|
-
* - 'console': Standard console logs (Default).
|
|
339
|
-
*/
|
|
340
|
-
output?: 'console' | 'error';
|
|
341
|
-
/**
|
|
342
|
-
* Include TypeScript type definitions in the prompt
|
|
343
|
-
* @default true
|
|
344
|
-
*/
|
|
345
|
-
includeTypes?: boolean;
|
|
346
|
-
}
|
|
347
331
|
/** Callback context passed to forEach, map, and filter. */
|
|
348
332
|
export type RowIterationContext<T = any> = {
|
|
349
333
|
row: SmartRow<T>;
|
|
@@ -454,8 +438,22 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
454
438
|
* Execution is parallel within each page by default (safe for reads).
|
|
455
439
|
* Call `stop()` to halt after the current page finishes.
|
|
456
440
|
*
|
|
441
|
+
* > **⚠️ UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,
|
|
442
|
+
* > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent
|
|
443
|
+
* > interactions interfering with each other.
|
|
444
|
+
*
|
|
457
445
|
* @example
|
|
446
|
+
* // Data extraction — parallel is safe
|
|
458
447
|
* const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* // UI interactions — must use parallel: false
|
|
451
|
+
* const assignees = await table.map(async ({ row }) => {
|
|
452
|
+
* await row.getCell('Assignee').locator('button').click();
|
|
453
|
+
* const name = await page.locator('.popover .name').innerText();
|
|
454
|
+
* await page.keyboard.press('Escape');
|
|
455
|
+
* return name;
|
|
456
|
+
* }, { parallel: false });
|
|
459
457
|
*/
|
|
460
458
|
map<R>(callback: (ctx: RowIterationContext<T>) => R | Promise<R>, options?: RowIterationOptions): Promise<R[]>;
|
|
461
459
|
/**
|
|
@@ -469,15 +467,6 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
469
467
|
* );
|
|
470
468
|
*/
|
|
471
469
|
filter(predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>, options?: RowIterationOptions): Promise<SmartRowArray<T>>;
|
|
472
|
-
/**
|
|
473
|
-
* Scans a specific column across all pages and returns the values.
|
|
474
|
-
* @deprecated Use `table.map(({ row }) => row.getCell(column).innerText())` instead.
|
|
475
|
-
* Will be removed in v7.0.0.
|
|
476
|
-
*/
|
|
477
|
-
getColumnValues: <V = string>(column: string, options?: {
|
|
478
|
-
mapper?: (cell: Locator) => Promise<V> | V;
|
|
479
|
-
maxPages?: number;
|
|
480
|
-
}) => Promise<V[]>;
|
|
481
470
|
/**
|
|
482
471
|
* Provides access to sorting actions and assertions.
|
|
483
472
|
*/
|
|
@@ -495,60 +484,10 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
495
484
|
*/
|
|
496
485
|
getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;
|
|
497
486
|
};
|
|
498
|
-
/**
|
|
499
|
-
* Iterates through paginated table data, calling the callback for each iteration.
|
|
500
|
-
* Callback return values are automatically appended to allData, which is returned.
|
|
501
|
-
* @deprecated Use `forEach`, `map`, or `filter` instead for cleaner cross-page iteration.
|
|
502
|
-
* Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).
|
|
503
|
-
* Will be removed in v7.0.0.
|
|
504
|
-
*/
|
|
505
|
-
iterateThroughTable: <T = any>(callback: (context: {
|
|
506
|
-
index: number;
|
|
507
|
-
isFirst: boolean;
|
|
508
|
-
isLast: boolean;
|
|
509
|
-
rows: SmartRowArray;
|
|
510
|
-
allData: T[];
|
|
511
|
-
table: RestrictedTableResult;
|
|
512
|
-
batchInfo?: {
|
|
513
|
-
startIndex: number;
|
|
514
|
-
endIndex: number;
|
|
515
|
-
size: number;
|
|
516
|
-
};
|
|
517
|
-
}) => T | T[] | Promise<T | T[]>, options?: {
|
|
518
|
-
pagination?: PaginationStrategy;
|
|
519
|
-
dedupeStrategy?: DedupeStrategy;
|
|
520
|
-
maxIterations?: number;
|
|
521
|
-
batchSize?: number;
|
|
522
|
-
getIsFirst?: (context: {
|
|
523
|
-
index: number;
|
|
524
|
-
}) => boolean;
|
|
525
|
-
getIsLast?: (context: {
|
|
526
|
-
index: number;
|
|
527
|
-
paginationResult: boolean;
|
|
528
|
-
}) => boolean;
|
|
529
|
-
beforeFirst?: (context: {
|
|
530
|
-
index: number;
|
|
531
|
-
rows: SmartRowArray;
|
|
532
|
-
allData: any[];
|
|
533
|
-
}) => void | Promise<void>;
|
|
534
|
-
afterLast?: (context: {
|
|
535
|
-
index: number;
|
|
536
|
-
rows: SmartRowArray;
|
|
537
|
-
allData: any[];
|
|
538
|
-
}) => void | Promise<void>;
|
|
539
|
-
/**
|
|
540
|
-
* If true, flattens array results from callback into the main data array.
|
|
541
|
-
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
542
|
-
*/
|
|
543
|
-
autoFlatten?: boolean;
|
|
544
|
-
}) => Promise<T[]>;
|
|
545
487
|
/**
|
|
546
488
|
* Generate an AI-friendly configuration prompt for debugging.
|
|
547
489
|
* Outputs table HTML and TypeScript definitions to help AI assistants generate config.
|
|
490
|
+
* Automatically throws an Error containing the prompt.
|
|
548
491
|
*/
|
|
549
|
-
generateConfigPrompt: (
|
|
492
|
+
generateConfigPrompt: () => Promise<void>;
|
|
550
493
|
}
|
|
551
|
-
/**
|
|
552
|
-
* Restricted table result that excludes methods that shouldn't be called during iteration.
|
|
553
|
-
*/
|
|
554
|
-
export type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;
|
package/dist/useTable.js
CHANGED
|
@@ -24,7 +24,6 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.useTable = void 0;
|
|
26
26
|
const minimalConfigContext_1 = require("./minimalConfigContext");
|
|
27
|
-
const validation_1 = require("./strategies/validation");
|
|
28
27
|
const loading_1 = require("./strategies/loading");
|
|
29
28
|
const fill_1 = require("./strategies/fill");
|
|
30
29
|
const headers_1 = require("./strategies/headers");
|
|
@@ -116,17 +115,11 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
116
115
|
return clone.outerHTML;
|
|
117
116
|
});
|
|
118
117
|
});
|
|
119
|
-
const _handlePrompt = (
|
|
120
|
-
const { output = 'console', includeTypes = true } = options;
|
|
118
|
+
const _handlePrompt = (promptName, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
119
|
let finalPrompt = content;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (output === 'error') {
|
|
126
|
-
console.log(`⚠️ Throwing error to display [${promptName}] cleanly...`);
|
|
127
|
-
throw new Error(finalPrompt);
|
|
128
|
-
}
|
|
129
|
-
console.log(finalPrompt);
|
|
120
|
+
finalPrompt += `\n\n👇 Useful TypeScript Definitions 👇\n\`\`\`typescript\n${minimalConfigContext_1.MINIMAL_CONFIG_CONTEXT}\n\`\`\`\n`;
|
|
121
|
+
console.log(`⚠️ Throwing error to display [${promptName}] cleanly...`);
|
|
122
|
+
throw new Error(finalPrompt);
|
|
130
123
|
});
|
|
131
124
|
const _ensureInitialized = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
125
|
yield tableMapper.getMap();
|
|
@@ -165,10 +158,19 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
165
158
|
return resolve(config.headerSelector, rootLocator).nth(idx);
|
|
166
159
|
}),
|
|
167
160
|
reset: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
var _a;
|
|
168
162
|
log("Resetting table...");
|
|
169
163
|
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
170
164
|
yield config.onReset(context);
|
|
165
|
+
if (typeof config.strategies.pagination !== 'function' && ((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goToFirst)) {
|
|
166
|
+
log("Auto-navigating to first page...");
|
|
167
|
+
yield config.strategies.pagination.goToFirst(context);
|
|
168
|
+
}
|
|
169
|
+
else if (hasPaginationInConfig) {
|
|
170
|
+
log("No goToFirst strategy configured. Table may not be on page 1.");
|
|
171
|
+
}
|
|
171
172
|
_hasPaginated = false;
|
|
173
|
+
tableState.currentPageIndex = 0;
|
|
172
174
|
tableMapper.clear();
|
|
173
175
|
log("Table reset complete.");
|
|
174
176
|
}),
|
|
@@ -177,49 +179,6 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
177
179
|
yield tableMapper.remapHeaders();
|
|
178
180
|
log("Table revalidated.");
|
|
179
181
|
}),
|
|
180
|
-
getColumnValues: (column, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
-
var _a, _b;
|
|
182
|
-
const map = yield tableMapper.getMap();
|
|
183
|
-
const colIdx = map.get(column);
|
|
184
|
-
if (colIdx === undefined)
|
|
185
|
-
throw _createColumnError(column, map);
|
|
186
|
-
const mapper = (_a = options === null || options === void 0 ? void 0 : options.mapper) !== null && _a !== void 0 ? _a : ((c) => c.innerText());
|
|
187
|
-
const effectiveMaxPages = (_b = options === null || options === void 0 ? void 0 : options.maxPages) !== null && _b !== void 0 ? _b : config.maxPages;
|
|
188
|
-
let pagesScanned = 1;
|
|
189
|
-
const results = [];
|
|
190
|
-
log(`Getting column values for '${column}' (Pages: ${effectiveMaxPages})`);
|
|
191
|
-
while (true) {
|
|
192
|
-
const rows = yield resolve(config.rowSelector, rootLocator).all();
|
|
193
|
-
for (const row of rows) {
|
|
194
|
-
const cell = typeof config.cellSelector === 'string'
|
|
195
|
-
? row.locator(config.cellSelector).nth(colIdx)
|
|
196
|
-
: resolve(config.cellSelector, row).nth(colIdx);
|
|
197
|
-
results.push(yield mapper(cell));
|
|
198
|
-
}
|
|
199
|
-
if (pagesScanned < effectiveMaxPages) {
|
|
200
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
201
|
-
let pageRes;
|
|
202
|
-
if (typeof config.strategies.pagination === 'function') {
|
|
203
|
-
pageRes = yield config.strategies.pagination(context);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
if (!config.strategies.pagination.goNext) {
|
|
207
|
-
log('Cannot paginate: no goNext primitive found.');
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
pageRes = yield config.strategies.pagination.goNext(context);
|
|
211
|
-
}
|
|
212
|
-
if (yield (0, validation_1.validatePaginationResult)(pageRes, 'Pagination Strategy')) {
|
|
213
|
-
_hasPaginated = true;
|
|
214
|
-
tableState.currentPageIndex++;
|
|
215
|
-
pagesScanned++;
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
return results;
|
|
222
|
-
}),
|
|
223
182
|
getRow: (filters, options = { exact: false }) => {
|
|
224
183
|
const map = tableMapper.getMapSync();
|
|
225
184
|
if (!map)
|
|
@@ -248,18 +207,40 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
248
207
|
},
|
|
249
208
|
sorting: {
|
|
250
209
|
apply: (columnName, direction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
+
var _a;
|
|
251
211
|
yield _ensureInitialized();
|
|
252
212
|
if (!config.strategies.sorting)
|
|
253
213
|
throw new Error('No sorting strategy has been configured.');
|
|
254
214
|
log(`Applying sort for column "${columnName}" (${direction})`);
|
|
255
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
256
|
-
|
|
215
|
+
const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell };
|
|
216
|
+
const maxRetries = 3;
|
|
217
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
218
|
+
const currentState = yield config.strategies.sorting.getSortState({ columnName, context });
|
|
219
|
+
if (currentState === direction) {
|
|
220
|
+
log(`Sort for "${columnName}" is already "${direction}".`);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
yield config.strategies.sorting.doSort({ columnName, direction, context });
|
|
224
|
+
if ((_a = config.strategies.loading) === null || _a === void 0 ? void 0 : _a.isTableLoading) {
|
|
225
|
+
yield config.strategies.loading.isTableLoading(context);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
yield rootLocator.page().waitForTimeout(200);
|
|
229
|
+
}
|
|
230
|
+
yield (0, debugUtils_1.debugDelay)(config, 'default');
|
|
231
|
+
const newState = yield config.strategies.sorting.getSortState({ columnName, context });
|
|
232
|
+
if (newState === direction) {
|
|
233
|
+
log(`Successfully sorted "${columnName}" to "${direction}".`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Failed to sort column "${columnName}" to "${direction}" after ${maxRetries} attempts.`);
|
|
257
238
|
}),
|
|
258
239
|
getState: (columnName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
259
240
|
yield _ensureInitialized();
|
|
260
241
|
if (!config.strategies.sorting)
|
|
261
242
|
throw new Error('No sorting strategy has been configured.');
|
|
262
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
243
|
+
const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell };
|
|
263
244
|
return config.strategies.sorting.getSortState({ columnName, context });
|
|
264
245
|
})
|
|
265
246
|
},
|
|
@@ -297,12 +278,13 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
297
278
|
},
|
|
298
279
|
// ─── Private row-iteration engine ────────────────────────────────────────
|
|
299
280
|
forEach: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
|
|
300
|
-
var _a, _b, _c;
|
|
281
|
+
var _a, _b, _c, _d;
|
|
301
282
|
yield _ensureInitialized();
|
|
302
283
|
const map = tableMapper.getMapSync();
|
|
303
284
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
304
|
-
const
|
|
305
|
-
const
|
|
285
|
+
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
286
|
+
const dedupeKeys = dedupeStrategy ? new Set() : null;
|
|
287
|
+
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
|
|
306
288
|
let rowIndex = 0;
|
|
307
289
|
let stopped = false;
|
|
308
290
|
let pagesScanned = 1;
|
|
@@ -315,7 +297,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
315
297
|
if (stopped)
|
|
316
298
|
return;
|
|
317
299
|
if (dedupeKeys) {
|
|
318
|
-
const key = yield
|
|
300
|
+
const key = yield dedupeStrategy(row);
|
|
319
301
|
if (dedupeKeys.has(key))
|
|
320
302
|
return;
|
|
321
303
|
dedupeKeys.add(key);
|
|
@@ -328,7 +310,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
328
310
|
if (stopped)
|
|
329
311
|
break;
|
|
330
312
|
if (dedupeKeys) {
|
|
331
|
-
const key = yield
|
|
313
|
+
const key = yield dedupeStrategy(row);
|
|
332
314
|
if (dedupeKeys.has(key))
|
|
333
315
|
continue;
|
|
334
316
|
dedupeKeys.add(key);
|
|
@@ -345,7 +327,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
345
327
|
advanced = !!(yield config.strategies.pagination(context));
|
|
346
328
|
}
|
|
347
329
|
else {
|
|
348
|
-
advanced = !!(((
|
|
330
|
+
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
349
331
|
}
|
|
350
332
|
if (!advanced)
|
|
351
333
|
break;
|
|
@@ -354,12 +336,13 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
354
336
|
}
|
|
355
337
|
}),
|
|
356
338
|
map: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
|
|
357
|
-
var _a, _b, _c;
|
|
339
|
+
var _a, _b, _c, _d;
|
|
358
340
|
yield _ensureInitialized();
|
|
359
341
|
const map = tableMapper.getMapSync();
|
|
360
342
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
361
|
-
const
|
|
362
|
-
const
|
|
343
|
+
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
344
|
+
const dedupeKeys = dedupeStrategy ? new Set() : null;
|
|
345
|
+
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : true;
|
|
363
346
|
const results = [];
|
|
364
347
|
let rowIndex = 0;
|
|
365
348
|
let stopped = false;
|
|
@@ -372,7 +355,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
372
355
|
const SKIP = Symbol('skip');
|
|
373
356
|
const pageResults = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
|
|
374
357
|
if (dedupeKeys) {
|
|
375
|
-
const key = yield
|
|
358
|
+
const key = yield dedupeStrategy(row);
|
|
376
359
|
if (dedupeKeys.has(key))
|
|
377
360
|
return SKIP;
|
|
378
361
|
dedupeKeys.add(key);
|
|
@@ -389,7 +372,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
389
372
|
if (stopped)
|
|
390
373
|
break;
|
|
391
374
|
if (dedupeKeys) {
|
|
392
|
-
const key = yield
|
|
375
|
+
const key = yield dedupeStrategy(row);
|
|
393
376
|
if (dedupeKeys.has(key))
|
|
394
377
|
continue;
|
|
395
378
|
dedupeKeys.add(key);
|
|
@@ -406,7 +389,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
406
389
|
advanced = !!(yield config.strategies.pagination(context));
|
|
407
390
|
}
|
|
408
391
|
else {
|
|
409
|
-
advanced = !!(((
|
|
392
|
+
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
410
393
|
}
|
|
411
394
|
if (!advanced)
|
|
412
395
|
break;
|
|
@@ -416,12 +399,13 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
416
399
|
return results;
|
|
417
400
|
}),
|
|
418
401
|
filter: (predicate_1, ...args_1) => __awaiter(void 0, [predicate_1, ...args_1], void 0, function* (predicate, options = {}) {
|
|
419
|
-
var _a, _b, _c;
|
|
402
|
+
var _a, _b, _c, _d;
|
|
420
403
|
yield _ensureInitialized();
|
|
421
404
|
const map = tableMapper.getMapSync();
|
|
422
405
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
423
|
-
const
|
|
424
|
-
const
|
|
406
|
+
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
407
|
+
const dedupeKeys = dedupeStrategy ? new Set() : null;
|
|
408
|
+
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
|
|
425
409
|
const matched = [];
|
|
426
410
|
let rowIndex = 0;
|
|
427
411
|
let stopped = false;
|
|
@@ -433,7 +417,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
433
417
|
if (parallel) {
|
|
434
418
|
const flags = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
|
|
435
419
|
if (dedupeKeys) {
|
|
436
|
-
const key = yield
|
|
420
|
+
const key = yield dedupeStrategy(row);
|
|
437
421
|
if (dedupeKeys.has(key))
|
|
438
422
|
return false;
|
|
439
423
|
dedupeKeys.add(key);
|
|
@@ -467,7 +451,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
467
451
|
advanced = !!(yield config.strategies.pagination(context));
|
|
468
452
|
}
|
|
469
453
|
else {
|
|
470
|
-
advanced = !!(((
|
|
454
|
+
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
471
455
|
}
|
|
472
456
|
if (!advanced)
|
|
473
457
|
break;
|
|
@@ -476,208 +460,11 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
476
460
|
}
|
|
477
461
|
return (0, smartRowArray_1.createSmartRowArray)(matched);
|
|
478
462
|
}),
|
|
479
|
-
|
|
480
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
481
|
-
yield _ensureInitialized();
|
|
482
|
-
const paginationStrategy = (_a = options === null || options === void 0 ? void 0 : options.pagination) !== null && _a !== void 0 ? _a : config.strategies.pagination;
|
|
483
|
-
const hasPaginationInOptions = (options === null || options === void 0 ? void 0 : options.pagination) !== undefined;
|
|
484
|
-
if (!hasPaginationInOptions && !hasPaginationInConfig)
|
|
485
|
-
throw new Error('No pagination strategy provided.');
|
|
486
|
-
yield result.reset();
|
|
487
|
-
yield result.init();
|
|
488
|
-
const map = tableMapper.getMapSync();
|
|
489
|
-
const restrictedTable = {
|
|
490
|
-
get currentPageIndex() { return tableState.currentPageIndex; },
|
|
491
|
-
init: result.init,
|
|
492
|
-
getHeaders: result.getHeaders,
|
|
493
|
-
getHeaderCell: result.getHeaderCell,
|
|
494
|
-
getRow: result.getRow,
|
|
495
|
-
getRowByIndex: result.getRowByIndex,
|
|
496
|
-
findRow: result.findRow,
|
|
497
|
-
findRows: result.findRows,
|
|
498
|
-
getColumnValues: result.getColumnValues,
|
|
499
|
-
isInitialized: result.isInitialized,
|
|
500
|
-
sorting: result.sorting,
|
|
501
|
-
scrollToColumn: result.scrollToColumn,
|
|
502
|
-
revalidate: result.revalidate,
|
|
503
|
-
generateConfigPrompt: result.generateConfigPrompt,
|
|
504
|
-
forEach: result.forEach,
|
|
505
|
-
map: result.map,
|
|
506
|
-
filter: result.filter,
|
|
507
|
-
[Symbol.asyncIterator]: result[Symbol.asyncIterator].bind(result),
|
|
508
|
-
};
|
|
509
|
-
const getIsFirst = (_b = options === null || options === void 0 ? void 0 : options.getIsFirst) !== null && _b !== void 0 ? _b : (({ index }) => index === 0);
|
|
510
|
-
const getIsLast = (_c = options === null || options === void 0 ? void 0 : options.getIsLast) !== null && _c !== void 0 ? _c : (() => false);
|
|
511
|
-
const allData = [];
|
|
512
|
-
const effectiveMaxIterations = (_d = options === null || options === void 0 ? void 0 : options.maxIterations) !== null && _d !== void 0 ? _d : config.maxPages;
|
|
513
|
-
const batchSize = options === null || options === void 0 ? void 0 : options.batchSize;
|
|
514
|
-
const isBatching = batchSize !== undefined && batchSize > 1;
|
|
515
|
-
const autoFlatten = (_e = options === null || options === void 0 ? void 0 : options.autoFlatten) !== null && _e !== void 0 ? _e : false;
|
|
516
|
-
let index = 0;
|
|
517
|
-
let paginationResult = true;
|
|
518
|
-
let seenKeys = null;
|
|
519
|
-
let batchRows = [];
|
|
520
|
-
let batchStartIndex = 0;
|
|
521
|
-
log(`Starting iterateThroughTable (maxIterations: ${effectiveMaxIterations}, batchSize: ${batchSize !== null && batchSize !== void 0 ? batchSize : 'none'})`);
|
|
522
|
-
while (index < effectiveMaxIterations) {
|
|
523
|
-
const rowLocators = yield resolve(config.rowSelector, rootLocator).all();
|
|
524
|
-
const smartRowsArray = [];
|
|
525
|
-
const isRowLoading = (_f = config.strategies.loading) === null || _f === void 0 ? void 0 : _f.isRowLoading;
|
|
526
|
-
for (let i = 0; i < rowLocators.length; i++) {
|
|
527
|
-
const smartRow = _makeSmart(rowLocators[i], map, i);
|
|
528
|
-
if (isRowLoading && (yield isRowLoading(smartRow)))
|
|
529
|
-
continue;
|
|
530
|
-
smartRowsArray.push(smartRow);
|
|
531
|
-
}
|
|
532
|
-
let rows = (0, smartRowArray_1.createSmartRowArray)(smartRowsArray);
|
|
533
|
-
const dedupeStrategy = (_g = options === null || options === void 0 ? void 0 : options.dedupeStrategy) !== null && _g !== void 0 ? _g : config.strategies.dedupe;
|
|
534
|
-
if (dedupeStrategy && rows.length > 0) {
|
|
535
|
-
if (!seenKeys)
|
|
536
|
-
seenKeys = new Set();
|
|
537
|
-
const deduplicated = [];
|
|
538
|
-
for (const row of rows) {
|
|
539
|
-
const key = yield dedupeStrategy(row);
|
|
540
|
-
if (!seenKeys.has(key)) {
|
|
541
|
-
seenKeys.add(key);
|
|
542
|
-
deduplicated.push(row);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
rows = (0, smartRowArray_1.createSmartRowArray)(deduplicated);
|
|
546
|
-
log(`Deduplicated ${rowLocators.length} rows to ${rows.length} unique rows (total seen: ${seenKeys.size})`);
|
|
547
|
-
}
|
|
548
|
-
// Add rows to batch if batching is enabled
|
|
549
|
-
if (isBatching) {
|
|
550
|
-
batchRows.push(...rows);
|
|
551
|
-
}
|
|
552
|
-
const isLastIteration = index === effectiveMaxIterations - 1;
|
|
553
|
-
// Determine if we should invoke the callback
|
|
554
|
-
const batchComplete = isBatching && (index - batchStartIndex + 1) >= batchSize;
|
|
555
|
-
const shouldInvokeCallback = !isBatching || batchComplete || isLastIteration;
|
|
556
|
-
if (shouldInvokeCallback) {
|
|
557
|
-
const callbackRows = isBatching ? batchRows : rows;
|
|
558
|
-
const callbackIndex = isBatching ? batchStartIndex : index;
|
|
559
|
-
const isFirst = getIsFirst({ index: callbackIndex });
|
|
560
|
-
let isLast = getIsLast({ index: callbackIndex, paginationResult });
|
|
561
|
-
const isLastDueToMax = index === effectiveMaxIterations - 1;
|
|
562
|
-
if (isFirst && (options === null || options === void 0 ? void 0 : options.beforeFirst)) {
|
|
563
|
-
yield options.beforeFirst({ index: callbackIndex, rows: (0, smartRowArray_1.createSmartRowArray)(callbackRows), allData });
|
|
564
|
-
}
|
|
565
|
-
const batchInfo = isBatching ? {
|
|
566
|
-
startIndex: batchStartIndex,
|
|
567
|
-
endIndex: index,
|
|
568
|
-
size: index - batchStartIndex + 1
|
|
569
|
-
} : undefined;
|
|
570
|
-
const returnValue = yield callback({
|
|
571
|
-
index: callbackIndex,
|
|
572
|
-
isFirst,
|
|
573
|
-
isLast,
|
|
574
|
-
rows: (0, smartRowArray_1.createSmartRowArray)(callbackRows),
|
|
575
|
-
allData,
|
|
576
|
-
table: restrictedTable,
|
|
577
|
-
batchInfo
|
|
578
|
-
});
|
|
579
|
-
if (autoFlatten && Array.isArray(returnValue)) {
|
|
580
|
-
allData.push(...returnValue);
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
allData.push(returnValue);
|
|
584
|
-
}
|
|
585
|
-
// Determine if this is truly the last iteration
|
|
586
|
-
let finalIsLast = isLastDueToMax;
|
|
587
|
-
if (!isLastIteration) {
|
|
588
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
589
|
-
if (typeof paginationStrategy === 'function') {
|
|
590
|
-
paginationResult = yield paginationStrategy(context);
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
const pageObj = paginationStrategy;
|
|
594
|
-
if (!pageObj.goNext)
|
|
595
|
-
break;
|
|
596
|
-
paginationResult = yield pageObj.goNext(context);
|
|
597
|
-
}
|
|
598
|
-
(0, debugUtils_1.logDebug)(config, 'info', `Pagination ${paginationResult ? 'succeeded' : 'failed'}`);
|
|
599
|
-
yield (0, debugUtils_1.debugDelay)(config, 'pagination');
|
|
600
|
-
finalIsLast = getIsLast({ index: callbackIndex, paginationResult }) || !paginationResult;
|
|
601
|
-
if (paginationResult)
|
|
602
|
-
tableState.currentPageIndex++;
|
|
603
|
-
}
|
|
604
|
-
if (finalIsLast && (options === null || options === void 0 ? void 0 : options.afterLast)) {
|
|
605
|
-
yield options.afterLast({ index: callbackIndex, rows: (0, smartRowArray_1.createSmartRowArray)(callbackRows), allData });
|
|
606
|
-
}
|
|
607
|
-
if (finalIsLast || !paginationResult) {
|
|
608
|
-
log(`Reached last iteration (index: ${index}, paginationResult: ${paginationResult})`);
|
|
609
|
-
break;
|
|
610
|
-
}
|
|
611
|
-
// Reset batch
|
|
612
|
-
if (isBatching) {
|
|
613
|
-
batchRows = [];
|
|
614
|
-
batchStartIndex = index + 1;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
// Continue paginating even when batching
|
|
619
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
620
|
-
if (typeof paginationStrategy === 'function') {
|
|
621
|
-
paginationResult = yield paginationStrategy(context);
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
const pageObj = paginationStrategy;
|
|
625
|
-
if (!pageObj.goNext) {
|
|
626
|
-
log(`Cannot paginate: no goNext primitive found.`);
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
paginationResult = yield pageObj.goNext(context);
|
|
630
|
-
}
|
|
631
|
-
(0, debugUtils_1.logDebug)(config, 'info', `Pagination ${paginationResult ? 'succeeded' : 'failed'} (batching mode)`);
|
|
632
|
-
yield (0, debugUtils_1.debugDelay)(config, 'pagination');
|
|
633
|
-
if (paginationResult)
|
|
634
|
-
tableState.currentPageIndex++;
|
|
635
|
-
if (!paginationResult) {
|
|
636
|
-
// Pagination failed, invoke callback with current batch
|
|
637
|
-
const callbackIndex = batchStartIndex;
|
|
638
|
-
const isFirst = getIsFirst({ index: callbackIndex });
|
|
639
|
-
const isLast = true;
|
|
640
|
-
if (isFirst && (options === null || options === void 0 ? void 0 : options.beforeFirst)) {
|
|
641
|
-
yield options.beforeFirst({ index: callbackIndex, rows: (0, smartRowArray_1.createSmartRowArray)(batchRows), allData });
|
|
642
|
-
}
|
|
643
|
-
const batchInfo = {
|
|
644
|
-
startIndex: batchStartIndex,
|
|
645
|
-
endIndex: index,
|
|
646
|
-
size: index - batchStartIndex + 1
|
|
647
|
-
};
|
|
648
|
-
const returnValue = yield callback({
|
|
649
|
-
index: callbackIndex,
|
|
650
|
-
isFirst,
|
|
651
|
-
isLast,
|
|
652
|
-
rows: (0, smartRowArray_1.createSmartRowArray)(batchRows),
|
|
653
|
-
allData,
|
|
654
|
-
table: restrictedTable,
|
|
655
|
-
batchInfo
|
|
656
|
-
});
|
|
657
|
-
if (autoFlatten && Array.isArray(returnValue)) {
|
|
658
|
-
allData.push(...returnValue);
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
allData.push(returnValue);
|
|
662
|
-
}
|
|
663
|
-
if (options === null || options === void 0 ? void 0 : options.afterLast) {
|
|
664
|
-
yield options.afterLast({ index: callbackIndex, rows: (0, smartRowArray_1.createSmartRowArray)(batchRows), allData });
|
|
665
|
-
}
|
|
666
|
-
log(`Pagination failed mid-batch (index: ${index})`);
|
|
667
|
-
break;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
index++;
|
|
671
|
-
log(`Iteration ${index} completed, continuing...`);
|
|
672
|
-
}
|
|
673
|
-
log(`iterateThroughTable completed after ${index + 1} iterations, collected ${allData.length} items`);
|
|
674
|
-
return allData;
|
|
675
|
-
}),
|
|
676
|
-
generateConfigPrompt: (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
463
|
+
generateConfigPrompt: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
677
464
|
const html = yield _getCleanHtml(rootLocator);
|
|
678
465
|
const separator = "=".repeat(50);
|
|
679
466
|
const content = `\n${separator} \n🤖 COPY INTO GEMINI / ChatGPT 🤖\n${separator} \nI am using 'playwright-smart-table'.\nTarget Table Locator: ${rootLocator.toString()} \nGenerate config for: \n\`\`\`html\n${html.substring(0, 10000)} ...\n\`\`\`\n${separator}\n`;
|
|
680
|
-
yield _handlePrompt('Smart Table Config', content
|
|
467
|
+
yield _handlePrompt('Smart Table Config', content);
|
|
681
468
|
}),
|
|
682
469
|
};
|
|
683
470
|
finalTable = result;
|