@rickcedwhat/playwright-smart-table 6.4.0 → 6.5.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\nexport interface TableResult<T = any> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRowArray;\n allData: T[];\n table: RestrictedTableResult;\n batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n\n }) => T | T[] | Promise<T | T[]>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n batchSize?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n /**\n * If true, flattens array results from callback into the main data array.\n * If false (default), pushes the return value as-is (preserves batching/arrays).\n */\n autoFlatten?: boolean;\n }\n ) => Promise<T[]>;\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n */\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;\n";
@@ -16,7 +16,7 @@ exports.TYPE_CONTEXT = `
16
16
  * // Function selector
17
17
  * rowSelector: (root) => root.locator('[role="row"]')
18
18
  */
19
- export type Selector = string | ((root: Locator | Page) => Locator);
19
+ export type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);
20
20
 
21
21
  /**
22
22
  * Value used to filter rows.
@@ -71,6 +71,12 @@ export type SmartRow<T = any> = Locator & {
71
71
  /** Optional row index (0-based) if known */
72
72
  rowIndex?: number;
73
73
 
74
+ /** Optional page index this row was found on (0-based) */
75
+ tablePageIndex?: number;
76
+
77
+ /** Reference to the parent TableResult */
78
+ table: TableResult<T>;
79
+
74
80
  /**
75
81
  * Get a cell locator by column name.
76
82
  * @param column - Column name (case-sensitive)
@@ -178,7 +184,21 @@ export interface TableContext<T = any> {
178
184
  resolve: (selector: Selector, parent: Locator | Page) => Locator;
179
185
  }
180
186
 
181
- export type PaginationStrategy = (context: TableContext) => Promise<boolean>;
187
+ export interface PaginationPrimitives {
188
+ /** Classic "Next Page" or "Scroll Down" */
189
+ goNext?: (context: TableContext) => Promise<boolean>;
190
+
191
+ /** Classic "Previous Page" or "Scroll Up" */
192
+ goPrevious?: (context: TableContext) => Promise<boolean>;
193
+
194
+ /** Jump to first page / scroll to top */
195
+ goToFirst?: (context: TableContext) => Promise<boolean>;
196
+
197
+ /** Jump to specific page index (0-indexed) */
198
+ goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
199
+ }
200
+
201
+ export type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;
182
202
 
183
203
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
184
204
 
@@ -191,10 +211,29 @@ export type FillStrategy = (options: {
191
211
  index: number;
192
212
  page: Page;
193
213
  rootLocator: Locator;
214
+ config: FinalTableConfig<any>;
194
215
  table: TableResult; // The parent table instance
195
216
  fillOptions?: FillOptions;
196
217
  }) => Promise<void>;
197
218
 
219
+ export interface ColumnOverride<TValue = any> {
220
+ /**
221
+ * How to extract the value from the cell. (Replaces dataMapper logic)
222
+ */
223
+ read?: (cell: Locator) => Promise<TValue> | TValue;
224
+
225
+ /**
226
+ * How to fill the cell with a new value. (Replaces smartFill default logic)
227
+ * Provides the current value (via \`read\`) if a \`write\` wants to check state first.
228
+ */
229
+ write?: (params: {
230
+ cell: Locator;
231
+ targetValue: TValue;
232
+ currentValue?: TValue;
233
+ row: SmartRow<any>;
234
+ }) => Promise<void>;
235
+ }
236
+
198
237
  export type { HeaderStrategy } from './strategies/headers';
199
238
 
200
239
  /**
@@ -275,10 +314,17 @@ export interface TableConfig<T = any> {
275
314
  /** All interaction strategies */
276
315
  strategies?: TableStrategies;
277
316
  /**
317
+ * @deprecated Use \`columnOverrides\` instead. \`dataMapper\` will be removed in v7.0.0.
278
318
  * Custom data mappers for specific columns.
279
319
  * Allows extracting complex data types (boolean, number) instead of just string.
280
320
  */
281
321
  dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
322
+
323
+ /**
324
+ * Unified interface for reading and writing data to specific columns.
325
+ * Overrides both default extraction (toJSON) and filling (smartFill) logic.
326
+ */
327
+ columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;
282
328
  }
283
329
 
284
330
  export interface FinalTableConfig<T = any> extends TableConfig<T> {
@@ -320,6 +366,12 @@ export interface PromptOptions {
320
366
  }
321
367
 
322
368
  export interface TableResult<T = any> {
369
+ /**
370
+ * Represents the current page index of the table's DOM.
371
+ * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.
372
+ */
373
+ currentPageIndex: number;
374
+
323
375
  /**
324
376
  * Initializes the table by resolving headers. Must be called before using sync methods.
325
377
  * @param options Optional timeout for header resolution (default: 3000ms)
package/dist/types.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { SmartRowArray } from './utils/smartRowArray';
9
9
  * // Function selector
10
10
  * rowSelector: (root) => root.locator('[role="row"]')
11
11
  */
12
- export type Selector = string | ((root: Locator | Page) => Locator);
12
+ export type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);
13
13
  /**
14
14
  * Value used to filter rows.
15
15
  * - string/number/RegExp: filter by text content of the cell.
@@ -58,6 +58,10 @@ export type GetActiveCellFn = (args: TableContext) => Promise<{
58
58
  export type SmartRow<T = any> = Locator & {
59
59
  /** Optional row index (0-based) if known */
60
60
  rowIndex?: number;
61
+ /** Optional page index this row was found on (0-based) */
62
+ tablePageIndex?: number;
63
+ /** Reference to the parent TableResult */
64
+ table: TableResult<T>;
61
65
  /**
62
66
  * Get a cell locator by column name.
63
67
  * @param column - Column name (case-sensitive)
@@ -161,7 +165,17 @@ export interface TableContext<T = any> {
161
165
  page: Page;
162
166
  resolve: (selector: Selector, parent: Locator | Page) => Locator;
163
167
  }
164
- export type PaginationStrategy = (context: TableContext) => Promise<boolean>;
168
+ export interface PaginationPrimitives {
169
+ /** Classic "Next Page" or "Scroll Down" */
170
+ goNext?: (context: TableContext) => Promise<boolean>;
171
+ /** Classic "Previous Page" or "Scroll Up" */
172
+ goPrevious?: (context: TableContext) => Promise<boolean>;
173
+ /** Jump to first page / scroll to top */
174
+ goToFirst?: (context: TableContext) => Promise<boolean>;
175
+ /** Jump to specific page index (0-indexed) */
176
+ goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
177
+ }
178
+ export type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;
165
179
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
166
180
  export type FillStrategy = (options: {
167
181
  row: SmartRow;
@@ -170,9 +184,26 @@ export type FillStrategy = (options: {
170
184
  index: number;
171
185
  page: Page;
172
186
  rootLocator: Locator;
187
+ config: FinalTableConfig<any>;
173
188
  table: TableResult;
174
189
  fillOptions?: FillOptions;
175
190
  }) => Promise<void>;
191
+ export interface ColumnOverride<TValue = any> {
192
+ /**
193
+ * How to extract the value from the cell. (Replaces dataMapper logic)
194
+ */
195
+ read?: (cell: Locator) => Promise<TValue> | TValue;
196
+ /**
197
+ * How to fill the cell with a new value. (Replaces smartFill default logic)
198
+ * Provides the current value (via `read`) if a `write` wants to check state first.
199
+ */
200
+ write?: (params: {
201
+ cell: Locator;
202
+ targetValue: TValue;
203
+ currentValue?: TValue;
204
+ row: SmartRow<any>;
205
+ }) => Promise<void>;
206
+ }
176
207
  import { HeaderStrategy } from './strategies/headers';
177
208
  export type { HeaderStrategy } from './strategies/headers';
178
209
  import { NavigationPrimitives } from './strategies/columns';
@@ -263,10 +294,16 @@ export interface TableConfig<T = any> {
263
294
  /** All interaction strategies */
264
295
  strategies?: TableStrategies;
265
296
  /**
297
+ * @deprecated Use `columnOverrides` instead. `dataMapper` will be removed in v7.0.0.
266
298
  * Custom data mappers for specific columns.
267
299
  * Allows extracting complex data types (boolean, number) instead of just string.
268
300
  */
269
301
  dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
302
+ /**
303
+ * Unified interface for reading and writing data to specific columns.
304
+ * Overrides both default extraction (toJSON) and filling (smartFill) logic.
305
+ */
306
+ columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;
270
307
  }
271
308
  export interface FinalTableConfig<T = any> extends TableConfig<T> {
272
309
  headerSelector: string | ((root: Locator) => Locator);
@@ -308,6 +345,11 @@ export interface PromptOptions {
308
345
  includeTypes?: boolean;
309
346
  }
310
347
  export interface TableResult<T = any> {
348
+ /**
349
+ * Represents the current page index of the table's DOM.
350
+ * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.
351
+ */
352
+ currentPageIndex: number;
311
353
  /**
312
354
  * Initializes the table by resolving headers. Must be called before using sync methods.
313
355
  * @param options Optional timeout for header resolution (default: 3000ms)
package/dist/useTable.js CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useTable = void 0;
13
13
  const minimalConfigContext_1 = require("./minimalConfigContext");
14
+ const validation_1 = require("./strategies/validation");
14
15
  const loading_1 = require("./strategies/loading");
15
16
  const fill_1 = require("./strategies/fill");
16
17
  const headers_1 = require("./strategies/headers");
@@ -75,10 +76,11 @@ const useTable = (rootLocator, configOptions = {}) => {
75
76
  // Placeholder for the final table object
76
77
  let finalTable = null;
77
78
  // Helper factory
78
- const _makeSmart = (rowLocator, map, rowIndex) => {
79
- return (0, smartRow_1.createSmartRow)(rowLocator, map, rowIndex, config, rootLocator, resolve, finalTable);
79
+ const _makeSmart = (rowLocator, map, rowIndex, tablePageIndex) => {
80
+ return (0, smartRow_1.createSmartRow)(rowLocator, map, rowIndex, config, rootLocator, resolve, finalTable, tablePageIndex);
80
81
  };
81
- const rowFinder = new rowFinder_1.RowFinder(rootLocator, config, resolve, filterEngine, tableMapper, _makeSmart);
82
+ const tableState = { currentPageIndex: 0 };
83
+ const rowFinder = new rowFinder_1.RowFinder(rootLocator, config, resolve, filterEngine, tableMapper, _makeSmart, tableState);
82
84
  const _getCleanHtml = (loc) => __awaiter(void 0, void 0, void 0, function* () {
83
85
  return loc.evaluate((el) => {
84
86
  const clone = el.cloneNode(true);
@@ -117,6 +119,8 @@ const useTable = (rootLocator, configOptions = {}) => {
117
119
  yield tableMapper.getMap();
118
120
  });
119
121
  const result = {
122
+ get currentPageIndex() { return tableState.currentPageIndex; },
123
+ set currentPageIndex(v) { tableState.currentPageIndex = v; },
120
124
  init: (options) => __awaiter(void 0, void 0, void 0, function* () {
121
125
  if (tableMapper.isInitialized())
122
126
  return result;
@@ -168,7 +172,7 @@ const useTable = (rootLocator, configOptions = {}) => {
168
172
  throw _createColumnError(column, map);
169
173
  const mapper = (_a = options === null || options === void 0 ? void 0 : options.mapper) !== null && _a !== void 0 ? _a : ((c) => c.innerText());
170
174
  const effectiveMaxPages = (_b = options === null || options === void 0 ? void 0 : options.maxPages) !== null && _b !== void 0 ? _b : config.maxPages;
171
- let currentPage = 1;
175
+ let pagesScanned = 1;
172
176
  const results = [];
173
177
  log(`Getting column values for '${column}' (Pages: ${effectiveMaxPages})`);
174
178
  while (true) {
@@ -179,11 +183,23 @@ const useTable = (rootLocator, configOptions = {}) => {
179
183
  : resolve(config.cellSelector, row).nth(colIdx);
180
184
  results.push(yield mapper(cell));
181
185
  }
182
- if (currentPage < effectiveMaxPages) {
186
+ if (pagesScanned < effectiveMaxPages) {
183
187
  const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
184
- if (yield config.strategies.pagination(context)) {
188
+ let pageRes;
189
+ if (typeof config.strategies.pagination === 'function') {
190
+ pageRes = yield config.strategies.pagination(context);
191
+ }
192
+ else {
193
+ if (!config.strategies.pagination.goNext) {
194
+ log('Cannot paginate: no goNext primitive found.');
195
+ break;
196
+ }
197
+ pageRes = yield config.strategies.pagination.goNext(context);
198
+ }
199
+ if (yield (0, validation_1.validatePaginationResult)(pageRes, 'Pagination Strategy')) {
185
200
  _hasPaginated = true;
186
- currentPage++;
201
+ tableState.currentPageIndex++;
202
+ pagesScanned++;
187
203
  continue;
188
204
  }
189
205
  }
@@ -245,6 +261,7 @@ const useTable = (rootLocator, configOptions = {}) => {
245
261
  yield result.init();
246
262
  const map = tableMapper.getMapSync();
247
263
  const restrictedTable = {
264
+ get currentPageIndex() { return tableState.currentPageIndex; },
248
265
  init: result.init,
249
266
  getHeaders: result.getHeaders,
250
267
  getHeaderCell: result.getHeaderCell,
@@ -339,10 +356,20 @@ const useTable = (rootLocator, configOptions = {}) => {
339
356
  let finalIsLast = isLastDueToMax;
340
357
  if (!isLastIteration) {
341
358
  const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
342
- paginationResult = yield paginationStrategy(context);
359
+ if (typeof paginationStrategy === 'function') {
360
+ paginationResult = yield paginationStrategy(context);
361
+ }
362
+ else {
363
+ const pageObj = paginationStrategy;
364
+ if (!pageObj.goNext)
365
+ break;
366
+ paginationResult = yield pageObj.goNext(context);
367
+ }
343
368
  (0, debugUtils_1.logDebug)(config, 'info', `Pagination ${paginationResult ? 'succeeded' : 'failed'}`);
344
369
  yield (0, debugUtils_1.debugDelay)(config, 'pagination');
345
370
  finalIsLast = getIsLast({ index: callbackIndex, paginationResult }) || !paginationResult;
371
+ if (paginationResult)
372
+ tableState.currentPageIndex++;
346
373
  }
347
374
  if (finalIsLast && (options === null || options === void 0 ? void 0 : options.afterLast)) {
348
375
  yield options.afterLast({ index: callbackIndex, rows: (0, smartRowArray_1.createSmartRowArray)(callbackRows), allData });
@@ -360,9 +387,21 @@ const useTable = (rootLocator, configOptions = {}) => {
360
387
  else {
361
388
  // Continue paginating even when batching
362
389
  const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
363
- paginationResult = yield paginationStrategy(context);
390
+ if (typeof paginationStrategy === 'function') {
391
+ paginationResult = yield paginationStrategy(context);
392
+ }
393
+ else {
394
+ const pageObj = paginationStrategy;
395
+ if (!pageObj.goNext) {
396
+ log(`Cannot paginate: no goNext primitive found.`);
397
+ break;
398
+ }
399
+ paginationResult = yield pageObj.goNext(context);
400
+ }
364
401
  (0, debugUtils_1.logDebug)(config, 'info', `Pagination ${paginationResult ? 'succeeded' : 'failed'} (batching mode)`);
365
402
  yield (0, debugUtils_1.debugDelay)(config, 'pagination');
403
+ if (paginationResult)
404
+ tableState.currentPageIndex++;
366
405
  if (!paginationResult) {
367
406
  // Pagination failed, invoke callback with current batch
368
407
  const callbackIndex = batchStartIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.4.0",
3
+ "version": "6.5.0",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",