@rickcedwhat/playwright-smart-table 6.4.0 → 6.6.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 CHANGED
@@ -106,6 +106,14 @@ const allActive = await table.findRows({ Status: 'Active' });
106
106
  - ❌ You don't need to find a row based on a value in a cell
107
107
  - ❌ You don't need to find a cell based on a value in another cell in the same row
108
108
 
109
+ ### ⚠️ Important Note on Pagination & Interactions
110
+
111
+ When using `findRows` across multiple pages, the returned `SmartRow` locators represent elements that may no longer be attached to the current DOM if the table paginated past them.
112
+
113
+ - **Data Extraction:** Safe. You can use `table.iterateThroughTable()` to extract data (`await row.toJSON()`) while the row is visible.
114
+ - **Interactions:** Unsafe directly. You cannot do `await row.click()` if the row is on Page 1 but the table is currently showing Page 3.
115
+ - **Solution:** If you need to interact with a row found on a previous page, you may be able to use `await row.bringIntoView()` before interacting with it to force the table to paginate back to that row (Note: this specific cross-page interaction flow is currently under testing).
116
+
109
117
  ## Documentation
110
118
 
111
119
  **📚 Full documentation available at: https://rickcedwhat.github.io/playwright-smart-table/**
@@ -9,8 +9,11 @@ export declare class RowFinder<T = any> {
9
9
  private filterEngine;
10
10
  private tableMapper;
11
11
  private makeSmartRow;
12
+ private tableState;
12
13
  private resolve;
13
- constructor(rootLocator: Locator, config: FinalTableConfig, resolve: (item: Selector, parent: Locator | Page) => Locator, filterEngine: FilterEngine, tableMapper: TableMapper, makeSmartRow: (loc: Locator, map: Map<string, number>, index: number) => SmartRow<T>);
14
+ constructor(rootLocator: Locator, config: FinalTableConfig, resolve: (item: Selector, parent: Locator | Page) => Locator, filterEngine: FilterEngine, tableMapper: TableMapper, makeSmartRow: (loc: Locator, map: Map<string, number>, index: number, tablePageIndex?: number) => SmartRow<T>, tableState?: {
15
+ currentPageIndex: number;
16
+ });
14
17
  private log;
15
18
  findRow(filters: Record<string, FilterValue>, options?: {
16
19
  exact?: boolean;
@@ -25,12 +25,13 @@ const debugUtils_1 = require("../utils/debugUtils");
25
25
  const smartRowArray_1 = require("../utils/smartRowArray");
26
26
  const validation_1 = require("../strategies/validation");
27
27
  class RowFinder {
28
- constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow) {
28
+ constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }) {
29
29
  this.rootLocator = rootLocator;
30
30
  this.config = config;
31
31
  this.filterEngine = filterEngine;
32
32
  this.tableMapper = tableMapper;
33
33
  this.makeSmartRow = makeSmartRow;
34
+ this.tableState = tableState;
34
35
  this.resolve = resolve;
35
36
  }
36
37
  log(msg) {
@@ -82,7 +83,7 @@ class RowFinder {
82
83
  const map = yield this.tableMapper.getMap();
83
84
  const allRows = [];
84
85
  const effectiveMaxPages = (_b = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages) !== null && _b !== void 0 ? _b : Infinity;
85
- let pageCount = 0;
86
+ let pagesScanned = 1;
86
87
  const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
87
88
  var _a, _b;
88
89
  // ... logic ...
@@ -94,7 +95,7 @@ class RowFinder {
94
95
  const currentRows = yield rowLocators.all();
95
96
  const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
96
97
  for (let i = 0; i < currentRows.length; i++) {
97
- const smartRow = this.makeSmartRow(currentRows[i], map, allRows.length + i);
98
+ const smartRow = this.makeSmartRow(currentRows[i], map, allRows.length + i, this.tableState.currentPageIndex);
98
99
  if (isRowLoading && (yield isRowLoading(smartRow)))
99
100
  continue;
100
101
  allRows.push(smartRow);
@@ -105,7 +106,7 @@ class RowFinder {
105
106
  // Pagination Loop - Corrected logic
106
107
  // We always scan at least 1 page.
107
108
  // If maxPages > 1, and we have a pagination strategy, we try to go next.
108
- while (pageCount < effectiveMaxPages - 1 && this.config.strategies.pagination) {
109
+ while (pagesScanned < effectiveMaxPages && this.config.strategies.pagination) {
109
110
  const context = {
110
111
  root: this.rootLocator,
111
112
  config: this.config,
@@ -113,11 +114,22 @@ class RowFinder {
113
114
  page: this.rootLocator.page()
114
115
  };
115
116
  // Check if we should stop? (e.g. if we found enough rows? No, findRows finds ALL)
116
- const paginationResult = yield this.config.strategies.pagination(context);
117
+ let paginationResult;
118
+ if (typeof this.config.strategies.pagination === 'function') {
119
+ paginationResult = yield this.config.strategies.pagination(context);
120
+ }
121
+ else {
122
+ // It's a PaginationPrimitives object, use goNext by default for findRows
123
+ if (!this.config.strategies.pagination.goNext) {
124
+ break; // Cannot paginate forward
125
+ }
126
+ paginationResult = yield this.config.strategies.pagination.goNext(context);
127
+ }
117
128
  const didPaginate = yield (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
118
129
  if (!didPaginate)
119
130
  break;
120
- pageCount++;
131
+ this.tableState.currentPageIndex++;
132
+ pagesScanned++;
121
133
  // Wait for reload logic if needed? Usually pagination handles it.
122
134
  yield collectMatches();
123
135
  }
@@ -129,7 +141,7 @@ class RowFinder {
129
141
  var _a, _b;
130
142
  const map = yield this.tableMapper.getMap();
131
143
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages;
132
- let currentPage = 1;
144
+ let pagesScanned = 1;
133
145
  this.log(`Looking for row: ${JSON.stringify(filters)} (MaxPages: ${effectiveMaxPages})`);
134
146
  while (true) {
135
147
  // Check Loading
@@ -149,40 +161,51 @@ class RowFinder {
149
161
  const allRows = this.resolve(this.config.rowSelector, this.rootLocator);
150
162
  const matchedRows = this.filterEngine.applyFilters(allRows, filters, map, options.exact || false, this.rootLocator.page());
151
163
  const count = yield matchedRows.count();
152
- this.log(`Page ${currentPage}: Found ${count} matches.`);
164
+ this.log(`Page ${this.tableState.currentPageIndex}: Found ${count} matches.`);
153
165
  if (count > 1) {
154
166
  const sampleData = [];
155
167
  try {
156
168
  const firstFewRows = yield matchedRows.all();
157
169
  const sampleCount = Math.min(firstFewRows.length, 3);
158
170
  for (let i = 0; i < sampleCount; i++) {
159
- const rowData = yield this.makeSmartRow(firstFewRows[i], map, 0).toJSON();
171
+ const rowData = yield this.makeSmartRow(firstFewRows[i], map, 0, this.tableState.currentPageIndex).toJSON();
160
172
  sampleData.push(JSON.stringify(rowData));
161
173
  }
162
174
  }
163
175
  catch (e) { }
164
176
  const sampleMsg = sampleData.length > 0 ? `\nSample matching rows:\n${sampleData.map((d, i) => ` ${i + 1}. ${d}`).join('\n')}` : '';
165
- throw new Error(`Ambiguous Row: Found ${count} rows matching ${JSON.stringify(filters)} on page ${currentPage}. ` +
177
+ throw new Error(`Ambiguous Row: Found ${count} rows matching ${JSON.stringify(filters)} on page ${this.tableState.currentPageIndex}. ` +
166
178
  `Expected exactly one match. Try adding more filters to make your query unique.${sampleMsg}`);
167
179
  }
168
180
  if (count === 1)
169
181
  return matchedRows.first();
170
- if (currentPage < effectiveMaxPages) {
171
- this.log(`Page ${currentPage}: Not found. Attempting pagination...`);
182
+ if (pagesScanned < effectiveMaxPages) {
183
+ this.log(`Page ${this.tableState.currentPageIndex}: Not found. Attempting pagination...`);
172
184
  const context = {
173
185
  root: this.rootLocator,
174
186
  config: this.config,
175
187
  resolve: this.resolve,
176
188
  page: this.rootLocator.page()
177
189
  };
178
- const paginationResult = yield this.config.strategies.pagination(context);
190
+ let paginationResult;
191
+ if (typeof this.config.strategies.pagination === 'function') {
192
+ paginationResult = yield this.config.strategies.pagination(context);
193
+ }
194
+ else {
195
+ if (!this.config.strategies.pagination.goNext) {
196
+ this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (no goNext primitive).`);
197
+ return null;
198
+ }
199
+ paginationResult = yield this.config.strategies.pagination.goNext(context);
200
+ }
179
201
  const didLoadMore = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
180
202
  if (didLoadMore) {
181
- currentPage++;
203
+ this.tableState.currentPageIndex++;
204
+ pagesScanned++;
182
205
  continue;
183
206
  }
184
207
  else {
185
- this.log(`Page ${currentPage}: Pagination failed (end of data).`);
208
+ this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (end of data).`);
186
209
  }
187
210
  }
188
211
  return null;
@@ -25,10 +25,15 @@ class FilterEngine {
25
25
  // But for now, we implement the default logic or use custom if we add it to config later
26
26
  // Default Filter Logic
27
27
  const cellTemplate = this.resolve(this.config.cellSelector, page);
28
- // This logic assumes 1:1 row-to-cell mapping based on index.
29
- // filter({ has: ... }) checks if the row *contains* the matching cell.
30
- // But we need to be specific about WHICH cell.
31
- // Locator filtering by `has: locator.nth(index)` works if `locator` search is relative to the row.
28
+ // ⚠️ CRITICAL WARNING: DO NOT "FIX" OR REFACTOR THIS LOGIC. ⚠️
29
+ // At first glance, `cellTemplate.nth(colIndex)` looks like a global page selector
30
+ // that will return the Nth cell on the entire page, rather than the Nth cell in the row.
31
+ // THIS IS INTENTIONAL AND CORRECT.
32
+ // Playwright deeply understands nested locator scoping. When this global-looking locator
33
+ // is passed into `filtered.filter({ has: ... })` below, Playwright magically and
34
+ // automatically re-bases the `nth()` selector to be strictly relative to the ROW being evaluated.
35
+ // Attempting to manually force generic relative locators here will break complex function
36
+ // selectors and introduce regressions. Leave it as is.
32
37
  const targetCell = cellTemplate.nth(colIndex);
33
38
  if (typeof filterVal === 'function') {
34
39
  // Locator-based filter: (cell) => cell.locator(...)
@@ -4,4 +4,4 @@ import { SmartRow as SmartRowType, FinalTableConfig, TableResult } from './types
4
4
  * Factory to create a SmartRow by extending a Playwright Locator.
5
5
  * We avoid Class/Proxy to ensure full compatibility with Playwright's expect(locator) matchers.
6
6
  */
7
- export declare const createSmartRow: <T = any>(rowLocator: Locator, map: Map<string, number>, rowIndex: number | undefined, config: FinalTableConfig<T>, rootLocator: Locator, resolve: (item: any, parent: Locator | Page) => Locator, table: TableResult<T> | null) => SmartRowType<T>;
7
+ export declare const createSmartRow: <T = any>(rowLocator: Locator, map: Map<string, number>, rowIndex: number | undefined, config: FinalTableConfig<T>, rootLocator: Locator, resolve: (item: any, parent: Locator | Page) => Locator, table: TableResult<T> | null, tablePageIndex?: number) => SmartRowType<T>;
package/dist/smartRow.js CHANGED
@@ -98,10 +98,12 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
98
98
  * Factory to create a SmartRow by extending a Playwright Locator.
99
99
  * We avoid Class/Proxy to ensure full compatibility with Playwright's expect(locator) matchers.
100
100
  */
101
- const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table) => {
101
+ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve, table, tablePageIndex) => {
102
102
  const smart = rowLocator;
103
103
  // Attach State
104
104
  smart.rowIndex = rowIndex;
105
+ smart.tablePageIndex = tablePageIndex;
106
+ smart.table = table;
105
107
  // Attach Methods
106
108
  smart.getCell = (colName) => {
107
109
  const idx = map.get(colName);
@@ -120,15 +122,16 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
120
122
  return resolve(config.cellSelector, rowLocator).nth(idx);
121
123
  };
122
124
  smart.toJSON = (options) => __awaiter(void 0, void 0, void 0, function* () {
123
- var _a;
125
+ var _a, _b;
124
126
  const result = {};
125
127
  const page = rootLocator.page();
126
128
  for (const [col, idx] of map.entries()) {
127
129
  if ((options === null || options === void 0 ? void 0 : options.columns) && !options.columns.includes(col)) {
128
130
  continue;
129
131
  }
130
- // Check if we have a data mapper for this column
131
- const mapper = (_a = config.dataMapper) === null || _a === void 0 ? void 0 : _a[col];
132
+ // Check if we have a column override or data mapper for this column
133
+ const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[col];
134
+ const mapper = (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.read) || ((_b = config.dataMapper) === null || _b === void 0 ? void 0 : _b[col]);
132
135
  if (mapper) {
133
136
  // Use custom mapper
134
137
  // Ensure we have the cell first (same navigation logic)
@@ -206,6 +209,7 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
206
209
  index: rowIndex !== null && rowIndex !== void 0 ? rowIndex : -1,
207
210
  page: rowLocator.page(),
208
211
  rootLocator,
212
+ config,
209
213
  table: table,
210
214
  fillOptions
211
215
  });
@@ -218,6 +222,47 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
218
222
  if (rowIndex === undefined) {
219
223
  throw new Error('Cannot bring row into view - row index is unknown. Use getRowByIndex() instead of getRow().');
220
224
  }
225
+ const parentTable = smart.table;
226
+ // Cross-page Navigation using PaginationPrimitives
227
+ if (tablePageIndex !== undefined && config.strategies.pagination) {
228
+ const primitives = config.strategies.pagination;
229
+ // Only orchestrate if it's an object of primitives, not a single function
230
+ if (typeof config.strategies.pagination !== 'function') {
231
+ const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
232
+ if (primitives.goToPage) {
233
+ (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Jumping to page ${tablePageIndex} using goToPage primitive`);
234
+ yield primitives.goToPage(tablePageIndex, context);
235
+ }
236
+ else if (primitives.goPrevious) {
237
+ (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Looping goPrevious until we reach page ${tablePageIndex}`);
238
+ const diff = parentTable.currentPageIndex - tablePageIndex;
239
+ for (let i = 0; i < diff; i++) {
240
+ const success = yield primitives.goPrevious(context);
241
+ if (!success) {
242
+ throw new Error(`bringIntoView: Failed to paginate backwards. Strategy aborted before reaching page ${tablePageIndex}.`);
243
+ }
244
+ }
245
+ }
246
+ else if (primitives.goToFirst && primitives.goNext) {
247
+ (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: going to first page and looping goNext until we reach page ${tablePageIndex}`);
248
+ yield primitives.goToFirst(context);
249
+ for (let i = 0; i < tablePageIndex; i++) {
250
+ yield primitives.goNext(context);
251
+ }
252
+ }
253
+ else {
254
+ (0, debugUtils_1.logDebug)(config, 'error', `Cannot bring row on page ${tablePageIndex} into view. No backwards pagination strategies (goToPage, goPrevious, or goToFirst) provided.`);
255
+ throw new Error(`Cannot bring row on page ${tablePageIndex} into view: Row is on a different page and no backward pagination primitive found.`);
256
+ }
257
+ }
258
+ else {
259
+ throw new Error(`Cannot bring row on page ${tablePageIndex} into view: Pagination is a single function. Provide an object with 'goPrevious', 'goToPage', or 'goToFirst' primitives.`);
260
+ }
261
+ // Successfully orchestrated backwards navigation, now update the state pointer
262
+ parentTable.currentPageIndex = tablePageIndex;
263
+ }
264
+ // Delay after pagination/finding before scrolling
265
+ yield (0, debugUtils_1.debugDelay)(config, 'findRow');
221
266
  // Scroll row into view using Playwright's built-in method
222
267
  yield rowLocator.scrollIntoViewIfNeeded();
223
268
  });
@@ -3,5 +3,5 @@ export declare const FillStrategies: {
3
3
  /**
4
4
  * Default strategy: Detects input type and fills accordingly (Text, Select, Checkbox, ContentEditable).
5
5
  */
6
- default: ({ row, columnName, value, fillOptions }: Parameters<FillStrategy>[0]) => Promise<void>;
6
+ default: ({ row, columnName, value, fillOptions, config, table }: Parameters<FillStrategy>[0]) => Promise<void>;
7
7
  };
@@ -14,12 +14,28 @@ exports.FillStrategies = {
14
14
  /**
15
15
  * Default strategy: Detects input type and fills accordingly (Text, Select, Checkbox, ContentEditable).
16
16
  */
17
- default: (_a) => __awaiter(void 0, [_a], void 0, function* ({ row, columnName, value, fillOptions }) {
18
- var _b;
17
+ default: (_a) => __awaiter(void 0, [_a], void 0, function* ({ row, columnName, value, fillOptions, config, table }) {
18
+ var _b, _c;
19
19
  const cell = row.getCell(columnName);
20
+ // 1. Check for Unified Column Override
21
+ const columnOverride = (_b = config === null || config === void 0 ? void 0 : config.columnOverrides) === null || _b === void 0 ? void 0 : _b[columnName];
22
+ if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
23
+ let currentValue;
24
+ // Auto-sync: If read exists, fetch current state first
25
+ if (columnOverride.read) {
26
+ currentValue = yield columnOverride.read(cell);
27
+ }
28
+ yield columnOverride.write({
29
+ cell,
30
+ targetValue: value,
31
+ currentValue,
32
+ row
33
+ });
34
+ return;
35
+ }
20
36
  // Use custom input mapper for this column if provided, otherwise auto-detect
21
37
  let inputLocator;
22
- if ((_b = fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.inputMappers) === null || _b === void 0 ? void 0 : _b[columnName]) {
38
+ if ((_c = fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.inputMappers) === null || _c === void 0 ? void 0 : _c[columnName]) {
23
39
  inputLocator = fillOptions.inputMappers[columnName](cell);
24
40
  }
25
41
  else {
@@ -12,6 +12,14 @@ export declare const Strategies: {
12
12
  stabilization?: import("./stabilization").StabilizationStrategy;
13
13
  timeout?: number;
14
14
  }) => import("..").PaginationStrategy;
15
+ click: (selectors: {
16
+ next?: import("..").Selector;
17
+ previous?: import("..").Selector;
18
+ first?: import("..").Selector;
19
+ }, options?: {
20
+ stabilization?: import("./stabilization").StabilizationStrategy;
21
+ timeout?: number;
22
+ }) => import("..").PaginationStrategy;
15
23
  infiniteScroll: (options?: {
16
24
  action?: "scroll" | "js-scroll";
17
25
  scrollTarget?: import("..").Selector;
@@ -30,7 +38,7 @@ export declare const Strategies: {
30
38
  visible: ({ config, resolve, root }: import("..").StrategyContext) => Promise<string[]>;
31
39
  };
32
40
  Fill: {
33
- default: ({ row, columnName, value, fillOptions }: Parameters<import("..").FillStrategy>[0]) => Promise<void>;
41
+ default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("..").FillStrategy>[0]) => Promise<void>;
34
42
  };
35
43
  Resolution: {
36
44
  default: import("./resolution").ColumnResolutionStrategy;
@@ -3,12 +3,27 @@ import { StabilizationStrategy } from './stabilization';
3
3
  export declare const PaginationStrategies: {
4
4
  /**
5
5
  * Strategy: Clicks a "Next" button and waits for stabilization.
6
- * @param nextButtonSelector Selector for the next page button.
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.
7
18
  * @param options.stabilization Strategy to determine when the page has updated.
8
19
  * Defaults to `contentChanged({ scope: 'first' })`.
9
20
  * @param options.timeout Timeout for the click action.
10
21
  */
11
- clickNext: (nextButtonSelector: Selector, options?: {
22
+ click: (selectors: {
23
+ next?: Selector;
24
+ previous?: Selector;
25
+ first?: Selector;
26
+ }, options?: {
12
27
  stabilization?: StabilizationStrategy;
13
28
  timeout?: number;
14
29
  }) => PaginationStrategy;
@@ -14,27 +14,43 @@ const stabilization_1 = require("./stabilization");
14
14
  exports.PaginationStrategies = {
15
15
  /**
16
16
  * Strategy: Clicks a "Next" button and waits for stabilization.
17
- * @param nextButtonSelector Selector for the next page button.
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.
18
28
  * @param options.stabilization Strategy to determine when the page has updated.
19
29
  * Defaults to `contentChanged({ scope: 'first' })`.
20
30
  * @param options.timeout Timeout for the click action.
21
31
  */
22
- clickNext: (nextButtonSelector, options = {}) => {
23
- return (context) => __awaiter(void 0, void 0, void 0, function* () {
24
- var _a;
25
- const { root, resolve, page } = context;
26
- const nextBtn = resolve(nextButtonSelector, root).first();
27
- if (!(yield nextBtn.isVisible()) || !(yield nextBtn.isEnabled())) {
28
- return false;
29
- }
30
- // Default stabilization: Wait for first row content to change
31
- const stabilization = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.contentChanged({ scope: 'first', timeout: options.timeout });
32
- // Stabilization: Wrap action
33
- const success = yield stabilization(context, () => __awaiter(void 0, void 0, void 0, function* () {
34
- yield nextBtn.click({ timeout: 2000 }).catch(() => { });
35
- }));
36
- return success;
37
- });
32
+ click: (selectors, options = {}) => {
33
+ var _a;
34
+ const defaultStabilize = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.contentChanged({ scope: 'first', timeout: options.timeout });
35
+ const createClicker = (selector) => {
36
+ if (!selector)
37
+ return undefined;
38
+ return (context) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const { root, resolve } = context;
40
+ const btn = resolve(selector, root).first();
41
+ if (!btn || !(yield btn.isVisible()) || !(yield btn.isEnabled())) {
42
+ return false;
43
+ }
44
+ return yield defaultStabilize(context, () => __awaiter(void 0, void 0, void 0, function* () {
45
+ yield btn.click({ timeout: 2000 }).catch(() => { });
46
+ }));
47
+ });
48
+ };
49
+ return {
50
+ goNext: createClicker(selectors.next),
51
+ goPrevious: createClicker(selectors.previous),
52
+ goToFirst: createClicker(selectors.first)
53
+ };
38
54
  },
39
55
  /**
40
56
  * Strategy: Infinite Scroll (generic).
@@ -48,32 +64,38 @@ exports.PaginationStrategies = {
48
64
  * Use `contentChanged` for virtualization.
49
65
  */
50
66
  infiniteScroll: (options = {}) => {
51
- return (context) => __awaiter(void 0, void 0, void 0, function* () {
52
- var _a, _b;
53
- const { root, resolve, page } = context;
54
- const scrollTarget = options.scrollTarget
55
- ? resolve(options.scrollTarget, root)
56
- : root;
57
- // Default stabilization: Wait for row count to increase (Append mode)
58
- const stabilization = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.rowCountIncreased({ timeout: options.timeout });
59
- const amount = (_b = options.scrollAmount) !== null && _b !== void 0 ? _b : 500;
60
- const doScroll = () => __awaiter(void 0, void 0, void 0, function* () {
61
- const box = yield scrollTarget.boundingBox();
62
- // Action: Scroll
63
- if (options.action === 'js-scroll' || !box) {
64
- yield scrollTarget.evaluate((el, y) => {
65
- el.scrollTop += y;
66
- }, amount);
67
- }
68
- else {
69
- // Mouse Wheel
70
- yield page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
71
- yield page.mouse.wheel(0, amount);
72
- }
67
+ var _a, _b;
68
+ // Default stabilization: Wait for row count to increase (Append mode)
69
+ const stabilization = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.rowCountIncreased({ timeout: options.timeout });
70
+ const amount = (_b = options.scrollAmount) !== null && _b !== void 0 ? _b : 500;
71
+ const createScroller = (directionMultiplier) => {
72
+ return (context) => __awaiter(void 0, void 0, void 0, function* () {
73
+ const { root, resolve, page } = context;
74
+ const scrollTarget = options.scrollTarget
75
+ ? resolve(options.scrollTarget, root)
76
+ : root;
77
+ const doScroll = () => __awaiter(void 0, void 0, void 0, function* () {
78
+ const box = yield scrollTarget.boundingBox();
79
+ const scrollValue = amount * directionMultiplier;
80
+ // Action: Scroll
81
+ if (options.action === 'js-scroll' || !box) {
82
+ yield scrollTarget.evaluate((el, y) => {
83
+ el.scrollTop += y;
84
+ }, scrollValue);
85
+ }
86
+ else {
87
+ // Mouse Wheel
88
+ yield page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
89
+ yield page.mouse.wheel(0, scrollValue);
90
+ }
91
+ });
92
+ // Stabilization: Wait
93
+ return yield stabilization(context, doScroll);
73
94
  });
74
- // Stabilization: Wait
75
- const success = yield stabilization(context, doScroll);
76
- return success;
77
- });
95
+ };
96
+ return {
97
+ goNext: createScroller(1),
98
+ goPrevious: createScroller(-1)
99
+ };
78
100
  }
79
101
  };
@@ -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);\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 /**\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 type PaginationStrategy = (context: TableContext) => Promise<boolean>;\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 table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\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 * 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\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n/**\n * Options for generateConfigPrompt\n */\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n /**\n * Include TypeScript type definitions in the prompt\n * @default true\n */\n includeTypes?: boolean;\n}\n\nexport interface TableResult<T = any> {\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRowArray;\n allData: T[];\n table: RestrictedTableResult;\n batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n\n }) => T | T[] | Promise<T | T[]>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n batchSize?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n /**\n * If true, flattens array results from callback into the main data array.\n * If false (default), pushes the return value as-is (preserves batching/arrays).\n */\n autoFlatten?: boolean;\n }\n ) => Promise<T[]>;\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n */\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;\n";
6
+ export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { 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";