@rickcedwhat/playwright-smart-table 6.7.3 → 6.7.4

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
@@ -99,6 +99,8 @@ for await (const { row, rowIndex } of table) {
99
99
  }
100
100
  ```
101
101
 
102
+ When your pagination strategy supports bulk jumps (`goNextBulk`), pass `{ useBulkPagination: true }` to `map`/`forEach`/`filter` to advance by multiple pages at once.
103
+
102
104
  > **`map` + UI interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,
103
105
  > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid overlapping interactions.
104
106
 
@@ -48,7 +48,7 @@ class RowFinder {
48
48
  }
49
49
  findRows(filters, options) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
- var _a, _b;
51
+ var _a, _b, _c, _d;
52
52
  const filtersRecord = filters || {};
53
53
  const map = yield this.tableMapper.getMap();
54
54
  const allRows = [];
@@ -85,19 +85,14 @@ class RowFinder {
85
85
  page: this.rootLocator.page()
86
86
  };
87
87
  let paginationResult;
88
- if (typeof this.config.strategies.pagination === 'function') {
89
- paginationResult = yield this.config.strategies.pagination(context);
88
+ if ((_c = this.config.strategies.pagination) === null || _c === void 0 ? void 0 : _c.goNextBulk) {
89
+ paginationResult = yield this.config.strategies.pagination.goNextBulk(context);
90
+ }
91
+ else if ((_d = this.config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) {
92
+ paginationResult = yield this.config.strategies.pagination.goNext(context);
90
93
  }
91
94
  else {
92
- if (this.config.strategies.pagination.goNextBulk) {
93
- paginationResult = yield this.config.strategies.pagination.goNextBulk(context);
94
- }
95
- else if (this.config.strategies.pagination.goNext) {
96
- paginationResult = yield this.config.strategies.pagination.goNext(context);
97
- }
98
- else {
99
- break;
100
- }
95
+ break;
101
96
  }
102
97
  const didPaginate = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
103
98
  if (!didPaginate)
@@ -116,7 +111,7 @@ class RowFinder {
116
111
  }
117
112
  findRowLocator(filters_1) {
118
113
  return __awaiter(this, arguments, void 0, function* (filters, options = {}) {
119
- var _a, _b;
114
+ var _a, _b, _c, _d;
120
115
  const map = yield this.tableMapper.getMap();
121
116
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages;
122
117
  let pagesScanned = 1;
@@ -166,20 +161,15 @@ class RowFinder {
166
161
  page: this.rootLocator.page()
167
162
  };
168
163
  let paginationResult;
169
- if (typeof this.config.strategies.pagination === 'function') {
170
- paginationResult = yield this.config.strategies.pagination(context);
164
+ if ((_c = this.config.strategies.pagination) === null || _c === void 0 ? void 0 : _c.goNextBulk) {
165
+ paginationResult = yield this.config.strategies.pagination.goNextBulk(context);
166
+ }
167
+ else if ((_d = this.config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) {
168
+ paginationResult = yield this.config.strategies.pagination.goNext(context);
171
169
  }
172
170
  else {
173
- if (this.config.strategies.pagination.goNextBulk) {
174
- paginationResult = yield this.config.strategies.pagination.goNextBulk(context);
175
- }
176
- else if (this.config.strategies.pagination.goNext) {
177
- paginationResult = yield this.config.strategies.pagination.goNext(context);
178
- }
179
- else {
180
- this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (no goNext or goNextBulk primitive).`);
181
- return null;
182
- }
171
+ this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (no goNext or goNextBulk primitive).`);
172
+ return null;
183
173
  }
184
174
  const didLoadMore = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
185
175
  if (didLoadMore) {
@@ -3,4 +3,4 @@
3
3
  * This file is generated by scripts/embed-config-types.mjs
4
4
  * It contains minimal type definitions for config generation prompts.
5
5
  */
6
- export declare const MINIMAL_CONFIG_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string or function returning a Locator.\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 * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\n/**\n * Configuration options for useTable - focus on selectors and basic setup\n */\nexport interface TableConfig<T = any> {\n /** CSS selector or function for table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for table rows */\n rowSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for cells within a row */\n cellSelector?: string | ((row: Locator) => Locator);\n \n /** Transform header text (e.g., normalize, deduplicate) */\n headerTransformer?: (args: { \n text: string; \n index: number; \n locator: Locator;\n seenHeaders: Set<string>;\n }) => string | Promise<string>;\n \n /** Automatically scroll to table on init (default: true) */\n autoScroll?: boolean;\n \n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n \n /** Advanced: Custom strategies for pagination, sorting, navigation, etc. */\n strategies?: TableStrategies;\n \n /** Custom data mappers for extracting complex types (boolean, number) */\n dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;\n}\n\n/**\n * Example usage:\n */\n// const table = useTable(page.locator('table'), {\n// headerSelector: 'thead th',\n// rowSelector: 'tbody tr',\n// cellSelector: 'td',\n// headerTransformer: ({ text }) => text.trim()\n// });\n\n";
6
+ export declare const MINIMAL_CONFIG_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string or function returning a Locator.\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 * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\n/**\n * Configuration options for useTable - focus on selectors and basic setup\n */\nexport interface TableConfig<T = any> {\n /** CSS selector or function for table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for table rows */\n rowSelector?: string | ((root: Locator) => Locator);\n \n /** CSS selector or function for cells within a row */\n cellSelector?: string | ((row: Locator) => Locator);\n \n /** Transform header text (e.g., normalize, deduplicate) */\n headerTransformer?: (args: { \n text: string; \n index: number; \n locator: Locator;\n seenHeaders: Set<string>;\n }) => string | Promise<string>;\n \n /** Automatically scroll to table on init (default: true) */\n autoScroll?: boolean;\n \n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n \n /** Advanced: Custom strategies for pagination, sorting, navigation, etc. */\n strategies?: TableStrategies;\n}\n\n/**\n * Example usage:\n */\n// const table = useTable(page.locator('table'), {\n// headerSelector: 'thead th',\n// rowSelector: 'tbody tr',\n// cellSelector: 'td',\n// headerTransformer: ({ text }) => text.trim()\n// });\n\n";
@@ -60,9 +60,6 @@ export interface TableConfig<T = any> {
60
60
 
61
61
  /** Advanced: Custom strategies for pagination, sorting, navigation, etc. */
62
62
  strategies?: TableStrategies;
63
-
64
- /** Custom data mappers for extracting complex types (boolean, number) */
65
- dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
66
63
  }
67
64
 
68
65
  /**
package/dist/plugins.d.ts CHANGED
@@ -10,14 +10,14 @@ export declare const Plugins: {
10
10
  goUp: ({ root, page }: any) => Promise<void>;
11
11
  goHome: ({ root, page }: any) => Promise<void>;
12
12
  };
13
- pagination: import("./types").PaginationStrategy;
13
+ pagination: import("./types").PaginationPrimitives;
14
14
  };
15
15
  };
16
16
  Glide: {
17
17
  Strategies: {
18
18
  fill: import("./types").FillStrategy;
19
19
  fillSimple: import("./types").FillStrategy;
20
- pagination: import("./types").PaginationStrategy;
20
+ pagination: import("./types").PaginationPrimitives;
21
21
  header: (context: import("./types").StrategyContext, options?: {
22
22
  limit?: number;
23
23
  selector?: string;
package/dist/smartRow.js CHANGED
@@ -13,6 +13,7 @@ exports.createSmartRow = void 0;
13
13
  const fill_1 = require("./strategies/fill");
14
14
  const stringUtils_1 = require("./utils/stringUtils");
15
15
  const debugUtils_1 = require("./utils/debugUtils");
16
+ const paginationPath_1 = require("./utils/paginationPath");
16
17
  /**
17
18
  * Internal helper to navigate to a cell with active cell optimization.
18
19
  * Uses navigation primitives (goUp, goDown, goLeft, goRight, goHome) for orchestration.
@@ -257,43 +258,37 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
257
258
  throw new Error('Cannot bring row into view - row index is unknown. Use getRowByIndex() instead of getRow().');
258
259
  }
259
260
  const parentTable = smart.table;
260
- // Cross-page Navigation using PaginationPrimitives
261
+ // Cross-page Navigation: when goToPage exists use retry loop (supports windowed UIs); otherwise use path planner or goToFirst+goNext
261
262
  if (tablePageIndex !== undefined && config.strategies.pagination) {
262
263
  const primitives = config.strategies.pagination;
263
- // Only orchestrate if it's an object of primitives, not a single function
264
- if (typeof config.strategies.pagination !== 'function') {
265
- const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
266
- if (primitives.goToPage) {
267
- (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Jumping to page ${tablePageIndex} using goToPage primitive`);
268
- yield primitives.goToPage(tablePageIndex, context);
269
- }
270
- else if (primitives.goPrevious) {
271
- (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Looping goPrevious until we reach page ${tablePageIndex}`);
272
- const diff = parentTable.currentPageIndex - tablePageIndex;
273
- for (let i = 0; i < diff; i++) {
274
- const success = yield primitives.goPrevious(context);
275
- if (!success) {
276
- throw new Error(`bringIntoView: Failed to paginate backwards. Strategy aborted before reaching page ${tablePageIndex}.`);
277
- }
278
- }
264
+ const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
265
+ const getCurrent = () => parentTable.currentPageIndex;
266
+ const setCurrent = (n) => { parentTable.currentPageIndex = n; };
267
+ if (primitives.goToPage) {
268
+ (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Navigating to page ${tablePageIndex} (goToPage retry loop)`);
269
+ yield (0, paginationPath_1.executeNavigationWithGoToPageRetry)(tablePageIndex, primitives, context, getCurrent, setCurrent);
270
+ }
271
+ else {
272
+ const path = (0, paginationPath_1.planNavigationPath)(getCurrent(), tablePageIndex, primitives);
273
+ if (path.length > 0) {
274
+ (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: Executing navigation path to page ${tablePageIndex} (${path.length} step(s))`);
275
+ yield (0, paginationPath_1.executeNavigationPath)(path, primitives, context, getCurrent, setCurrent);
279
276
  }
280
- else if (primitives.goToFirst && primitives.goNext) {
277
+ else if (primitives.goToFirst && primitives.goNext && tablePageIndex >= 0) {
281
278
  (0, debugUtils_1.logDebug)(config, 'info', `bringIntoView: going to first page and looping goNext until we reach page ${tablePageIndex}`);
282
279
  yield primitives.goToFirst(context);
283
280
  for (let i = 0; i < tablePageIndex; i++) {
284
- yield primitives.goNext(context);
281
+ const ok = yield primitives.goNext(context);
282
+ if (!ok)
283
+ throw new Error(`bringIntoView: goNext failed before reaching page ${tablePageIndex}.`);
285
284
  }
285
+ parentTable.currentPageIndex = tablePageIndex;
286
286
  }
287
287
  else {
288
- (0, debugUtils_1.logDebug)(config, 'error', `Cannot bring row on page ${tablePageIndex} into view. No backwards pagination strategies (goToPage, goPrevious, or goToFirst) provided.`);
288
+ (0, debugUtils_1.logDebug)(config, 'error', `Cannot bring row on page ${tablePageIndex} into view. No backwards pagination strategies (goToPage, goPrevious, goPreviousBulk, or goToFirst+goNext) provided.`);
289
289
  throw new Error(`Cannot bring row on page ${tablePageIndex} into view: Row is on a different page and no backward pagination primitive found.`);
290
290
  }
291
291
  }
292
- else {
293
- 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.`);
294
- }
295
- // Successfully orchestrated backwards navigation, now update the state pointer
296
- parentTable.currentPageIndex = tablePageIndex;
297
292
  }
298
293
  // Delay after pagination/finding before scrolling
299
294
  yield (0, debugUtils_1.debugDelay)(config, 'findRow');
@@ -10,7 +10,7 @@ export declare const glideFillStrategy: FillStrategy;
10
10
  * This is faster but may not work for all Glide configurations.
11
11
  */
12
12
  export declare const glideFillSimple: FillStrategy;
13
- export declare const glidePaginationStrategy: import("../types").PaginationStrategy;
13
+ export declare const glidePaginationStrategy: import("../types").PaginationPrimitives;
14
14
  export declare const glideGetCellLocator: ({ row, columnIndex }: any) => any;
15
15
  export declare const glideGetActiveCell: ({ page }: any) => Promise<{
16
16
  rowIndex: number;
@@ -20,7 +20,7 @@ export declare const glideGetActiveCell: ({ page }: any) => Promise<{
20
20
  export declare const GlideStrategies: {
21
21
  fill: FillStrategy;
22
22
  fillSimple: FillStrategy;
23
- pagination: import("../types").PaginationStrategy;
23
+ pagination: import("../types").PaginationPrimitives;
24
24
  header: (context: import("../types").StrategyContext, options?: {
25
25
  limit?: number;
26
26
  selector?: string;
@@ -29,12 +29,16 @@ exports.PaginationStrategies = {
29
29
  })).then(stabilized => stabilized ? returnVal : false);
30
30
  });
31
31
  };
32
+ const nextBulk = (_b = options.nextBulkPages) !== null && _b !== void 0 ? _b : 10;
33
+ const prevBulk = (_c = options.previousBulkPages) !== null && _c !== void 0 ? _c : 10;
32
34
  return {
33
35
  goNext: createClicker(selectors.next),
34
36
  goPrevious: createClicker(selectors.previous),
35
- goNextBulk: createClicker(selectors.nextBulk, (_b = options.nextBulkPages) !== null && _b !== void 0 ? _b : 10),
36
- goPreviousBulk: createClicker(selectors.previousBulk, (_c = options.previousBulkPages) !== null && _c !== void 0 ? _c : 10),
37
- goToFirst: createClicker(selectors.first)
37
+ goNextBulk: createClicker(selectors.nextBulk, nextBulk),
38
+ goPreviousBulk: createClicker(selectors.previousBulk, prevBulk),
39
+ goToFirst: createClicker(selectors.first),
40
+ nextBulkPages: nextBulk,
41
+ previousBulkPages: prevBulk,
38
42
  };
39
43
  },
40
44
  /**
@@ -78,9 +82,26 @@ exports.PaginationStrategies = {
78
82
  return yield stabilization(context, doScroll);
79
83
  });
80
84
  };
85
+ const createGoToFirst = () => {
86
+ return (context) => __awaiter(void 0, void 0, void 0, function* () {
87
+ const { root, resolve } = context;
88
+ const scrollTarget = options.scrollTarget
89
+ ? resolve(options.scrollTarget, root)
90
+ : root;
91
+ const doScroll = () => __awaiter(void 0, void 0, void 0, function* () {
92
+ yield scrollTarget.evaluate((el) => {
93
+ el.scrollTop = 0;
94
+ el.scrollLeft = 0;
95
+ });
96
+ });
97
+ // Stabilization: Wait for content to reset
98
+ return yield stabilization(context, doScroll);
99
+ });
100
+ };
81
101
  return {
82
102
  goNext: createScroller(1),
83
- goPrevious: createScroller(-1)
103
+ goPrevious: createScroller(-1),
104
+ goToFirst: createGoToFirst()
84
105
  };
85
106
  }
86
107
  };
@@ -12,7 +12,7 @@ export declare const rdgGetCellLocator: ({ row, columnIndex }: any) => any;
12
12
  /**
13
13
  * Scrolls the grid vertically to load more virtualized rows.
14
14
  */
15
- export declare const rdgPaginationStrategy: import("../types").PaginationStrategy;
15
+ export declare const rdgPaginationStrategy: import("../types").PaginationPrimitives;
16
16
  export declare const rdgNavigation: {
17
17
  goRight: ({ root, page }: any) => Promise<void>;
18
18
  goLeft: ({ root, page }: any) => Promise<void>;
@@ -30,5 +30,5 @@ export declare const RDGStrategies: {
30
30
  goUp: ({ root, page }: any) => Promise<void>;
31
31
  goHome: ({ root, page }: any) => Promise<void>;
32
32
  };
33
- pagination: import("../types").PaginationStrategy;
33
+ pagination: import("../types").PaginationPrimitives;
34
34
  };
@@ -1,15 +1,10 @@
1
- import type { PaginationStrategy, SortingStrategy, FillStrategy } from '../types';
1
+ import type { SortingStrategy, FillStrategy } from '../types';
2
2
  /**
3
- * Validates that a pagination strategy returns a boolean.
3
+ * Validates that a pagination strategy returns a boolean or number (pages jumped).
4
4
  * @param result - The result from a pagination strategy
5
5
  * @param strategyName - Name of the strategy for error messages
6
6
  */
7
7
  export declare function validatePaginationResult(result: any, strategyName?: string): boolean;
8
- /**
9
- * Validates that a pagination strategy is properly configured.
10
- * @param strategy - The pagination strategy to validate
11
- */
12
- export declare function validatePaginationStrategy(strategy: any): strategy is PaginationStrategy;
13
8
  /**
14
9
  * Validates that a sorting strategy has the required methods.
15
10
  * @param strategy - The sorting strategy to validate
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePaginationResult = validatePaginationResult;
4
- exports.validatePaginationStrategy = validatePaginationStrategy;
5
4
  exports.validateSortingStrategy = validateSortingStrategy;
6
5
  exports.validateFillStrategy = validateFillStrategy;
7
6
  /**
8
- * Validates that a pagination strategy returns a boolean.
7
+ * Validates that a pagination strategy returns a boolean or number (pages jumped).
9
8
  * @param result - The result from a pagination strategy
10
9
  * @param strategyName - Name of the strategy for error messages
11
10
  */
@@ -19,16 +18,6 @@ function validatePaginationResult(result, strategyName = 'Custom Pagination Stra
19
18
  }
20
19
  return result;
21
20
  }
22
- /**
23
- * Validates that a pagination strategy is properly configured.
24
- * @param strategy - The pagination strategy to validate
25
- */
26
- function validatePaginationStrategy(strategy) {
27
- if (typeof strategy !== 'function') {
28
- throw new Error(`Pagination strategy must be a function. Received: ${typeof strategy}`);
29
- }
30
- return true;
31
- }
32
21
  /**
33
22
  * Validates that a sorting strategy has the required methods.
34
23
  * @param strategy - The sorting strategy to validate
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 🤖 AUTO-GENERATED FILE. DO NOT EDIT.
3
- * This file is generated by scripts/embed-types.js
3
+ * This file is generated by scripts/embed-types.mjs
4
4
  * It contains the raw text of types.ts to provide context for LLM prompts.
5
5
  */
6
- export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Hook called before each cell value is read in toJSON (and columnOverrides.read).\n * Use this to scroll off-screen columns into view in horizontally virtualized tables,\n * wait for lazy-rendered content, or perform any pre-read setup.\n *\n * @example\n * // Scroll the column header into view to trigger horizontal virtualization render\n * strategies: {\n * beforeCellRead: async ({ columnName, getHeaderCell }) => {\n * const header = await getHeaderCell(columnName);\n * await header.scrollIntoViewIfNeeded();\n * }\n * }\n */\nexport type BeforeCellReadFn = (args: {\n /** The resolved cell locator */\n cell: Locator;\n columnName: string;\n columnIndex: number;\n row: Locator;\n page: Page;\n root: Locator;\n /** Resolves a column name to its header cell locator */\n getHeaderCell: (columnName: string) => Promise<Locator>;\n}) => Promise<void>;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n\n /**\n * Returns whether the row exists in the DOM (i.e. is not a sentinel row).\n */\n wasFound(): boolean;\n};\n\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n};\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n /** Resolves a column name to its header cell locator. Available after table is initialized. */\n getHeaderCell?: (columnName: string) => Promise<Locator>;\n /** Returns all column names in order. Available after table is initialized. */\n getHeaders?: () => Promise<string[]>;\n /** Scrolls the table horizontally to bring the given column's header into view. */\n scrollToColumn?: (columnName: string) => Promise<void>;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to specific page index (0-indexed) */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n}\n\nexport type PaginationStrategy = ((context: TableContext) => Promise<boolean | number>) | PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell.\n */\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 /**\n * Hook called before each cell value is read in toJSON and columnOverrides.read.\n * Fires for both the default innerText extraction and custom read mappers.\n * Useful for scrolling off-screen columns into view in horizontally virtualized tables.\n */\n beforeCellRead?: BeforeCellReadFn;\n /** Custom helper to check if a table is fully loaded/ready */\n isTableLoaded?: (args: TableContext) => Promise<boolean>;\n /** Custom helper to check if a row is fully loaded/ready */\n isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;\n /** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */\n isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;\n /** Strategy for detecting loading states */\n loading?: LoadingStrategy;\n}\n\n\nexport interface TableConfig<T = any> {\n /** Selector for the table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string;\n /** Number of pages to scan for verification */\n maxPages?: number;\n /** Hook to rename columns dynamically */\n headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n\n /**\n * Unified interface for reading and writing data to specific columns.\n * Overrides both default extraction (toJSON) and filling (smartFill) logic.\n */\n columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;\n}\n\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n\n\n/** Callback context passed to forEach, map, and filter. */\nexport type RowIterationContext<T = any> = {\n row: SmartRow<T>;\n rowIndex: number;\n stop: () => void;\n};\n\n/** Shared options for forEach, map, and filter. */\nexport type RowIterationOptions = {\n /** Maximum number of pages to iterate. Defaults to config.maxPages. */\n maxPages?: number;\n /**\n * Whether to process rows within a page concurrently.\n * @default false for forEach/filter, true for map\n */\n parallel?: boolean;\n /**\n * Deduplication strategy. Use when rows may repeat across iterations\n * (e.g. infinite scroll tables). Returns a unique key per row.\n */\n dedupe?: DedupeStrategy;\n};\n\nexport interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Iterates every row across all pages, calling the callback for side effects.\n * Execution is sequential by default (safe for interactions like clicking/filling).\n * Call `stop()` in the callback to end iteration early.\n *\n * @example\n * await table.forEach(async ({ row, stop }) => {\n * if (await row.getCell('Status').innerText() === 'Done') stop();\n * await row.getCell('Checkbox').click();\n * });\n */\n forEach(\n callback: (ctx: RowIterationContext<T>) => void | Promise<void>,\n options?: RowIterationOptions\n ): Promise<void>;\n\n /**\n * Transforms every row across all pages into a value. Returns a flat array.\n * Execution is parallel within each page by default (safe for reads).\n * Call `stop()` to halt after the current page finishes.\n *\n * > **\u26A0\uFE0F UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,\n * > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent\n * > interactions interfering with each other.\n *\n * @example\n * // Data extraction \u2014 parallel is safe\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n *\n * @example\n * // UI interactions \u2014 must use parallel: false\n * const assignees = await table.map(async ({ row }) => {\n * await row.getCell('Assignee').locator('button').click();\n * const name = await page.locator('.popover .name').innerText();\n * await page.keyboard.press('Escape');\n * return name;\n * }, { parallel: false });\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n * Automatically throws an Error containing the prompt.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
6
+ export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Hook called before each cell value is read in toJSON (and columnOverrides.read).\n * Use this to scroll off-screen columns into view in horizontally virtualized tables,\n * wait for lazy-rendered content, or perform any pre-read setup.\n *\n * @example\n * // Scroll the column header into view to trigger horizontal virtualization render\n * strategies: {\n * beforeCellRead: async ({ columnName, getHeaderCell }) => {\n * const header = await getHeaderCell(columnName);\n * await header.scrollIntoViewIfNeeded();\n * }\n * }\n */\nexport type BeforeCellReadFn = (args: {\n /** The resolved cell locator */\n cell: Locator;\n columnName: string;\n columnIndex: number;\n row: Locator;\n page: Page;\n root: Locator;\n /** Resolves a column name to its header cell locator */\n getHeaderCell: (columnName: string) => Promise<Locator>;\n}) => Promise<void>;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n\n /**\n * Returns whether the row exists in the DOM (i.e. is not a sentinel row).\n */\n wasFound(): boolean;\n};\n\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n};\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n /** Resolves a column name to its header cell locator. Available after table is initialized. */\n getHeaderCell?: (columnName: string) => Promise<Locator>;\n /** Returns all column names in order. Available after table is initialized. */\n getHeaders?: () => Promise<string[]>;\n /** Scrolls the table horizontally to bring the given column's header into view. */\n scrollToColumn?: (columnName: string) => Promise<void>;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /**\n * Jump to specific page index (0-indexed).\n * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6\u201314).\n * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.\n */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n\n /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */\n nextBulkPages?: number;\n\n /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */\n previousBulkPages?: number;\n}\n\nexport type PaginationStrategy = PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell.\n */\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 /**\n * Hook called before each cell value is read in toJSON and columnOverrides.read.\n * Fires for both the default innerText extraction and custom read mappers.\n * Useful for scrolling off-screen columns into view in horizontally virtualized tables.\n */\n beforeCellRead?: BeforeCellReadFn;\n /** Custom helper to check if a table is fully loaded/ready */\n isTableLoaded?: (args: TableContext) => Promise<boolean>;\n /** Custom helper to check if a row is fully loaded/ready */\n isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;\n /** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */\n isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;\n /** Strategy for detecting loading states */\n loading?: LoadingStrategy;\n}\n\n\nexport interface TableConfig<T = any> {\n /** Selector for the table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string;\n /** Number of pages to scan for verification */\n maxPages?: number;\n /** Hook to rename columns dynamically */\n headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n\n /**\n * Unified interface for reading and writing data to specific columns.\n * Overrides both default extraction (toJSON) and filling (smartFill) logic.\n */\n columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;\n}\n\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n\n\n/** Callback context passed to forEach, map, and filter. */\nexport type RowIterationContext<T = any> = {\n row: SmartRow<T>;\n rowIndex: number;\n stop: () => void;\n};\n\n/** Shared options for forEach, map, and filter. */\nexport type RowIterationOptions = {\n /** Maximum number of pages to iterate. Defaults to config.maxPages. */\n maxPages?: number;\n /**\n * Whether to process rows within a page concurrently.\n * @default false for forEach/filter, true for map\n */\n parallel?: boolean;\n /**\n * Deduplication strategy. Use when rows may repeat across iterations\n * (e.g. infinite scroll tables). Returns a unique key per row.\n */\n dedupe?: DedupeStrategy;\n /**\n * When true, use goNextBulk (if present) to advance pages during iteration.\n * @default false \u2014 uses goNext for one-page-at-a-time advancement\n */\n useBulkPagination?: boolean;\n};\n\nexport interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 0-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 0-based row index\n */\n getRowByIndex: (\n index: number\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Iterates every row across all pages, calling the callback for side effects.\n * Execution is sequential by default (safe for interactions like clicking/filling).\n * Call `stop()` in the callback to end iteration early.\n *\n * @example\n * await table.forEach(async ({ row, stop }) => {\n * if (await row.getCell('Status').innerText() === 'Done') stop();\n * await row.getCell('Checkbox').click();\n * });\n */\n forEach(\n callback: (ctx: RowIterationContext<T>) => void | Promise<void>,\n options?: RowIterationOptions\n ): Promise<void>;\n\n /**\n * Transforms every row across all pages into a value. Returns a flat array.\n * Execution is parallel within each page by default (safe for reads).\n * Call `stop()` to halt after the current page finishes.\n *\n * > **\u26A0\uFE0F UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,\n * > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent\n * > interactions interfering with each other.\n *\n * @example\n * // Data extraction \u2014 parallel is safe\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n *\n * @example\n * // UI interactions \u2014 must use parallel: false\n * const assignees = await table.map(async ({ row }) => {\n * await row.getCell('Assignee').locator('button').click();\n * const name = await page.locator('.popover .name').innerText();\n * await page.keyboard.press('Escape');\n * return name;\n * }, { parallel: false });\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n * Automatically throws an Error containing the prompt.\n */\n generateConfig: () => Promise<void>;\n\n /**\n * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TYPE_CONTEXT = void 0;
4
4
  /**
5
5
  * 🤖 AUTO-GENERATED FILE. DO NOT EDIT.
6
- * This file is generated by scripts/embed-types.js
6
+ * This file is generated by scripts/embed-types.mjs
7
7
  * It contains the raw text of types.ts to provide context for LLM prompts.
8
8
  */
9
9
  exports.TYPE_CONTEXT = `
@@ -240,11 +240,21 @@ export interface PaginationPrimitives {
240
240
  /** Jump to first page / scroll to top */
241
241
  goToFirst?: (context: TableContext) => Promise<boolean>;
242
242
 
243
- /** Jump to specific page index (0-indexed) */
243
+ /**
244
+ * Jump to specific page index (0-indexed).
245
+ * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6–14).
246
+ * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.
247
+ */
244
248
  goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
249
+
250
+ /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */
251
+ nextBulkPages?: number;
252
+
253
+ /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */
254
+ previousBulkPages?: number;
245
255
  }
246
256
 
247
- export type PaginationStrategy = ((context: TableContext) => Promise<boolean | number>) | PaginationPrimitives;
257
+ export type PaginationStrategy = PaginationPrimitives;
248
258
 
249
259
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
250
260
 
@@ -417,6 +427,11 @@ export type RowIterationOptions = {
417
427
  * (e.g. infinite scroll tables). Returns a unique key per row.
418
428
  */
419
429
  dedupe?: DedupeStrategy;
430
+ /**
431
+ * When true, use goNextBulk (if present) to advance pages during iteration.
432
+ * @default false — uses goNext for one-page-at-a-time advancement
433
+ */
434
+ useBulkPagination?: boolean;
420
435
  };
421
436
 
422
437
  export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {
@@ -451,10 +466,9 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
451
466
  ) => SmartRow;
452
467
 
453
468
  /**
454
- * Gets a row by 1-based index on the current page.
469
+ * Gets a row by 0-based index on the current page.
455
470
  * Throws error if table is not initialized.
456
- * @param index 1-based row index
457
- * @param options Optional settings including bringIntoView
471
+ * @param index 0-based row index
458
472
  */
459
473
  getRowByIndex: (
460
474
  index: number
@@ -581,6 +595,11 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
581
595
  * Outputs table HTML and TypeScript definitions to help AI assistants generate config.
582
596
  * Automatically throws an Error containing the prompt.
583
597
  */
598
+ generateConfig: () => Promise<void>;
599
+
600
+ /**
601
+ * @deprecated Use \`generateConfig()\` instead. Will be removed in v7.0.0.
602
+ */
584
603
  generateConfigPrompt: () => Promise<void>;
585
604
  }
586
605
  `;
package/dist/types.d.ts CHANGED
@@ -211,10 +211,18 @@ export interface PaginationPrimitives {
211
211
  goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;
212
212
  /** Jump to first page / scroll to top */
213
213
  goToFirst?: (context: TableContext) => Promise<boolean>;
214
- /** Jump to specific page index (0-indexed) */
214
+ /**
215
+ * Jump to specific page index (0-indexed).
216
+ * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6–14).
217
+ * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.
218
+ */
215
219
  goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
220
+ /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */
221
+ nextBulkPages?: number;
222
+ /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */
223
+ previousBulkPages?: number;
216
224
  }
217
- export type PaginationStrategy = ((context: TableContext) => Promise<boolean | number>) | PaginationPrimitives;
225
+ export type PaginationStrategy = PaginationPrimitives;
218
226
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
219
227
  export type FillStrategy = (options: {
220
228
  row: SmartRow;
@@ -387,6 +395,11 @@ export type RowIterationOptions = {
387
395
  * (e.g. infinite scroll tables). Returns a unique key per row.
388
396
  */
389
397
  dedupe?: DedupeStrategy;
398
+ /**
399
+ * When true, use goNextBulk (if present) to advance pages during iteration.
400
+ * @default false — uses goNext for one-page-at-a-time advancement
401
+ */
402
+ useBulkPagination?: boolean;
390
403
  };
391
404
  export interface TableResult<T = any> extends AsyncIterable<{
392
405
  row: SmartRow<T>;
@@ -419,10 +432,9 @@ export interface TableResult<T = any> extends AsyncIterable<{
419
432
  exact?: boolean;
420
433
  }) => SmartRow;
421
434
  /**
422
- * Gets a row by 1-based index on the current page.
435
+ * Gets a row by 0-based index on the current page.
423
436
  * Throws error if table is not initialized.
424
- * @param index 1-based row index
425
- * @param options Optional settings including bringIntoView
437
+ * @param index 0-based row index
426
438
  */
427
439
  getRowByIndex: (index: number) => SmartRow;
428
440
  /**
@@ -526,5 +538,9 @@ export interface TableResult<T = any> extends AsyncIterable<{
526
538
  * Outputs table HTML and TypeScript definitions to help AI assistants generate config.
527
539
  * Automatically throws an Error containing the prompt.
528
540
  */
541
+ generateConfig: () => Promise<void>;
542
+ /**
543
+ * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.
544
+ */
529
545
  generateConfigPrompt: () => Promise<void>;
530
546
  }
package/dist/useTable.js CHANGED
@@ -24,6 +24,7 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.useTable = void 0;
26
26
  const minimalConfigContext_1 = require("./minimalConfigContext");
27
+ const validation_1 = require("./strategies/validation");
27
28
  const loading_1 = require("./strategies/loading");
28
29
  const fill_1 = require("./strategies/fill");
29
30
  const headers_1 = require("./strategies/headers");
@@ -45,7 +46,7 @@ const useTable = (rootLocator, configOptions = {}) => {
45
46
  const defaultStrategies = {
46
47
  fill: fill_1.FillStrategies.default,
47
48
  header: headers_1.HeaderStrategies.visible,
48
- pagination: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
49
+ pagination: {},
49
50
  loading: {
50
51
  isHeaderLoading: loading_1.LoadingStrategies.Headers.stable(200)
51
52
  }
@@ -125,20 +126,26 @@ const useTable = (rootLocator, configOptions = {}) => {
125
126
  const _autoInit = () => __awaiter(void 0, void 0, void 0, function* () {
126
127
  yield tableMapper.getMap();
127
128
  });
128
- const _advancePage = () => __awaiter(void 0, void 0, void 0, function* () {
129
- var _a;
129
+ // Default: goNext (one page). Pass useBulk true to prefer goNextBulk. "How far" uses numeric return when strategy provides it.
130
+ const _advancePage = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (useBulk = false) {
130
131
  const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell, getHeaders: result.getHeaders, scrollToColumn: result.scrollToColumn };
131
- let advanced;
132
- if (typeof config.strategies.pagination === 'function') {
133
- advanced = !!(yield config.strategies.pagination(context));
132
+ const pagination = config.strategies.pagination;
133
+ let rawResult;
134
+ if (useBulk && (pagination === null || pagination === void 0 ? void 0 : pagination.goNextBulk)) {
135
+ rawResult = yield pagination.goNextBulk(context);
134
136
  }
135
- else {
136
- advanced = !!(((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goNext) && (yield config.strategies.pagination.goNext(context)));
137
+ else if (pagination === null || pagination === void 0 ? void 0 : pagination.goNext) {
138
+ rawResult = yield pagination.goNext(context);
137
139
  }
138
- if (advanced) {
139
- tableState.currentPageIndex++;
140
+ else if (pagination === null || pagination === void 0 ? void 0 : pagination.goNextBulk) {
141
+ rawResult = yield pagination.goNextBulk(context);
140
142
  }
141
- return advanced;
143
+ const didAdvance = rawResult !== undefined && (0, validation_1.validatePaginationResult)(rawResult, 'Pagination Strategy');
144
+ const pagesJumped = typeof rawResult === 'number' ? rawResult : (didAdvance ? 1 : 0);
145
+ if (pagesJumped > 0) {
146
+ tableState.currentPageIndex += pagesJumped;
147
+ }
148
+ return didAdvance;
142
149
  });
143
150
  const result = {
144
151
  get currentPageIndex() { return tableState.currentPageIndex; },
@@ -178,7 +185,7 @@ const useTable = (rootLocator, configOptions = {}) => {
178
185
  log("Resetting table...");
179
186
  const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell };
180
187
  yield config.onReset(context);
181
- if (typeof config.strategies.pagination !== 'function' && ((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goToFirst)) {
188
+ if ((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goToFirst) {
182
189
  log("Auto-navigating to first page...");
183
190
  yield config.strategies.pagination.goToFirst(context);
184
191
  }
@@ -268,6 +275,7 @@ const useTable = (rootLocator, configOptions = {}) => {
268
275
  const map = tableMapper.getMapSync();
269
276
  const effectiveMaxPages = config.maxPages;
270
277
  const tracker = new elementTracker_1.ElementTracker('iterator');
278
+ const useBulk = false; // iterator has no options; default goNext
271
279
  try {
272
280
  let rowIndex = 0;
273
281
  let pagesScanned = 1;
@@ -281,7 +289,7 @@ const useTable = (rootLocator, configOptions = {}) => {
281
289
  }
282
290
  if (pagesScanned >= effectiveMaxPages)
283
291
  break;
284
- if (!(yield __await(_advancePage())))
292
+ if (!(yield __await(_advancePage(useBulk))))
285
293
  break;
286
294
  pagesScanned++;
287
295
  }
@@ -293,13 +301,14 @@ const useTable = (rootLocator, configOptions = {}) => {
293
301
  },
294
302
  // ─── Private row-iteration engine ────────────────────────────────────────
295
303
  forEach: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
296
- var _a, _b, _c;
304
+ var _a, _b, _c, _d;
297
305
  yield _autoInit();
298
306
  const map = tableMapper.getMapSync();
299
307
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
300
308
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
301
309
  const dedupeKeys = dedupeStrategy ? new Set() : null;
302
310
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
311
+ const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
303
312
  const tracker = new elementTracker_1.ElementTracker('forEach');
304
313
  try {
305
314
  let rowIndex = 0;
@@ -340,7 +349,7 @@ const useTable = (rootLocator, configOptions = {}) => {
340
349
  rowIndex += smartRows.length;
341
350
  if (stopped || pagesScanned >= effectiveMaxPages)
342
351
  break;
343
- if (!(yield _advancePage()))
352
+ if (!(yield _advancePage(useBulk)))
344
353
  break;
345
354
  pagesScanned++;
346
355
  }
@@ -350,13 +359,14 @@ const useTable = (rootLocator, configOptions = {}) => {
350
359
  }
351
360
  }),
352
361
  map: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
353
- var _a, _b, _c;
362
+ var _a, _b, _c, _d;
354
363
  yield _autoInit();
355
364
  const map = tableMapper.getMapSync();
356
365
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
357
366
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
358
367
  const dedupeKeys = dedupeStrategy ? new Set() : null;
359
368
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : true;
369
+ const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
360
370
  const tracker = new elementTracker_1.ElementTracker('map');
361
371
  const results = [];
362
372
  try {
@@ -401,7 +411,7 @@ const useTable = (rootLocator, configOptions = {}) => {
401
411
  rowIndex += smartRows.length;
402
412
  if (stopped || pagesScanned >= effectiveMaxPages)
403
413
  break;
404
- if (!(yield _advancePage()))
414
+ if (!(yield _advancePage(useBulk)))
405
415
  break;
406
416
  pagesScanned++;
407
417
  }
@@ -412,13 +422,14 @@ const useTable = (rootLocator, configOptions = {}) => {
412
422
  return results;
413
423
  }),
414
424
  filter: (predicate_1, ...args_1) => __awaiter(void 0, [predicate_1, ...args_1], void 0, function* (predicate, options = {}) {
415
- var _a, _b, _c;
425
+ var _a, _b, _c, _d;
416
426
  yield _autoInit();
417
427
  const map = tableMapper.getMapSync();
418
428
  const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
419
429
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
420
430
  const dedupeKeys = dedupeStrategy ? new Set() : null;
421
431
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
432
+ const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
422
433
  const tracker = new elementTracker_1.ElementTracker('filter');
423
434
  const matched = [];
424
435
  try {
@@ -462,7 +473,7 @@ const useTable = (rootLocator, configOptions = {}) => {
462
473
  rowIndex += smartRows.length;
463
474
  if (stopped || pagesScanned >= effectiveMaxPages)
464
475
  break;
465
- if (!(yield _advancePage()))
476
+ if (!(yield _advancePage(useBulk)))
466
477
  break;
467
478
  pagesScanned++;
468
479
  }
@@ -472,12 +483,16 @@ const useTable = (rootLocator, configOptions = {}) => {
472
483
  }
473
484
  return (0, smartRowArray_1.createSmartRowArray)(matched);
474
485
  }),
475
- generateConfigPrompt: () => __awaiter(void 0, void 0, void 0, function* () {
486
+ generateConfig: () => __awaiter(void 0, void 0, void 0, function* () {
476
487
  const html = yield _getCleanHtml(rootLocator);
477
488
  const separator = "=".repeat(50);
478
489
  const content = `\n${separator} \n🤖 COPY INTO GEMINI / ChatGPT 🤖\n${separator} \nI am using 'playwright-smart-table'.\nTarget Table Locator: ${rootLocator.toString()} \nGenerate config for: \n\`\`\`html\n${html.substring(0, 10000)} ...\n\`\`\`\n${separator}\n`;
479
490
  yield _handlePrompt('Smart Table Config', content);
480
491
  }),
492
+ generateConfigPrompt: () => __awaiter(void 0, void 0, void 0, function* () {
493
+ console.warn('⚠️ [playwright-smart-table] generateConfigPrompt() is deprecated and will be removed in v7.0.0. Please use generateConfig() instead.');
494
+ return result.generateConfig();
495
+ }),
481
496
  };
482
497
  finalTable = result;
483
498
  return result;
@@ -0,0 +1,37 @@
1
+ import type { PaginationPrimitives, TableContext } from '../types';
2
+ /** A single step in a navigation plan (e.g. "goNextBulk 3 times"). */
3
+ export type NavigationStep = {
4
+ type: 'goToPage';
5
+ pageIndex: number;
6
+ } | {
7
+ type: 'goNextBulk';
8
+ count: number;
9
+ } | {
10
+ type: 'goNext';
11
+ count: number;
12
+ } | {
13
+ type: 'goPreviousBulk';
14
+ count: number;
15
+ } | {
16
+ type: 'goPrevious';
17
+ count: number;
18
+ };
19
+ /**
20
+ * Plans an optimal path from currentPageIndex to targetPageIndex using available primitives.
21
+ * Prefers goToPage when present; otherwise uses bulk steps (goNextBulk / goPreviousBulk) then
22
+ * single steps (goNext / goPrevious). May choose to overshoot with bulk then step back when
23
+ * that reduces total primitive calls (e.g. page 3 → 12 with bulk 10: goNextBulk once, goPrevious once).
24
+ */
25
+ export declare function planNavigationPath(currentPageIndex: number, targetPageIndex: number, primitives: PaginationPrimitives): NavigationStep[];
26
+ /**
27
+ * Navigate to targetPageIndex when goToPage is available but may be "windowed"
28
+ * (e.g. only works for visible page links 6–14). Tries goToPage(target); on false,
29
+ * steps once toward target (goNextBulk/goNext or goPreviousBulk/goPrevious), then retries.
30
+ * Example: from 3 to 38 with windowed goToPage → goToPage(38) false, goNextBulk(), goToPage(38) false, … goToPage(38) true.
31
+ */
32
+ export declare function executeNavigationWithGoToPageRetry(targetPageIndex: number, primitives: PaginationPrimitives, context: TableContext, getCurrentPage: () => number, setCurrentPage: (n: number) => void): Promise<void>;
33
+ /**
34
+ * Executes a navigation path by calling the corresponding primitives.
35
+ * Updates currentPageIndex via the provided setter as steps run.
36
+ */
37
+ export declare function executeNavigationPath(path: NavigationStep[], primitives: PaginationPrimitives, context: TableContext, getCurrentPage: () => number, setCurrentPage: (n: number) => void): Promise<void>;
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.planNavigationPath = planNavigationPath;
13
+ exports.executeNavigationWithGoToPageRetry = executeNavigationWithGoToPageRetry;
14
+ exports.executeNavigationPath = executeNavigationPath;
15
+ /**
16
+ * Plans an optimal path from currentPageIndex to targetPageIndex using available primitives.
17
+ * Prefers goToPage when present; otherwise uses bulk steps (goNextBulk / goPreviousBulk) then
18
+ * single steps (goNext / goPrevious). May choose to overshoot with bulk then step back when
19
+ * that reduces total primitive calls (e.g. page 3 → 12 with bulk 10: goNextBulk once, goPrevious once).
20
+ */
21
+ function planNavigationPath(currentPageIndex, targetPageIndex, primitives) {
22
+ var _a, _b;
23
+ if (currentPageIndex === targetPageIndex)
24
+ return [];
25
+ if (primitives.goToPage) {
26
+ return [{ type: 'goToPage', pageIndex: targetPageIndex }];
27
+ }
28
+ const nextBulkSize = (_a = primitives.nextBulkPages) !== null && _a !== void 0 ? _a : 1;
29
+ const prevBulkSize = (_b = primitives.previousBulkPages) !== null && _b !== void 0 ? _b : 1;
30
+ if (targetPageIndex > currentPageIndex) {
31
+ // Forward: current → target
32
+ const stepsForward = targetPageIndex - currentPageIndex;
33
+ const hasBulk = !!(primitives.goNextBulk && nextBulkSize > 0);
34
+ const hasPrev = !!primitives.goPrevious;
35
+ if (!hasBulk || nextBulkSize <= 0) {
36
+ if (primitives.goNext) {
37
+ return [{ type: 'goNext', count: stepsForward }];
38
+ }
39
+ return [];
40
+ }
41
+ const bulkCountA = Math.floor(stepsForward / nextBulkSize);
42
+ const remA = stepsForward % nextBulkSize;
43
+ const totalA = bulkCountA + remA;
44
+ let totalB = Infinity;
45
+ let bulkCountB = 0;
46
+ let overB = 0;
47
+ if (hasPrev && primitives.goPreviousBulk && prevBulkSize > 0) {
48
+ bulkCountB = Math.ceil(stepsForward / nextBulkSize);
49
+ overB = bulkCountB * nextBulkSize - stepsForward;
50
+ totalB = bulkCountB + overB;
51
+ }
52
+ if (totalB < totalA) {
53
+ const path = [];
54
+ if (bulkCountB > 0)
55
+ path.push({ type: 'goNextBulk', count: bulkCountB });
56
+ if (overB > 0)
57
+ path.push({ type: 'goPrevious', count: overB });
58
+ return path;
59
+ }
60
+ const path = [];
61
+ if (bulkCountA > 0)
62
+ path.push({ type: 'goNextBulk', count: bulkCountA });
63
+ if (remA > 0)
64
+ path.push({ type: 'goNext', count: remA });
65
+ return path;
66
+ }
67
+ // Backward: current → target
68
+ const stepsBack = currentPageIndex - targetPageIndex;
69
+ const hasPrevBulk = !!(primitives.goPreviousBulk && prevBulkSize > 0);
70
+ const hasNext = !!primitives.goNext;
71
+ if (!hasPrevBulk || prevBulkSize <= 0) {
72
+ if (primitives.goPrevious) {
73
+ return [{ type: 'goPrevious', count: stepsBack }];
74
+ }
75
+ // goToFirst + goNext loop is handled by caller (bringIntoView) when path is empty
76
+ return [];
77
+ }
78
+ const bulkCountA = Math.floor(stepsBack / prevBulkSize);
79
+ const remA = stepsBack % prevBulkSize;
80
+ const totalA = bulkCountA + remA;
81
+ let totalB = Infinity;
82
+ let bulkCountB = 0;
83
+ let overB = 0;
84
+ if (hasNext) {
85
+ bulkCountB = Math.ceil(stepsBack / prevBulkSize);
86
+ overB = bulkCountB * prevBulkSize - stepsBack;
87
+ totalB = bulkCountB + overB;
88
+ }
89
+ if (totalB < totalA) {
90
+ const path = [];
91
+ if (bulkCountB > 0)
92
+ path.push({ type: 'goPreviousBulk', count: bulkCountB });
93
+ if (overB > 0)
94
+ path.push({ type: 'goNext', count: overB });
95
+ return path;
96
+ }
97
+ const path = [];
98
+ if (bulkCountA > 0)
99
+ path.push({ type: 'goPreviousBulk', count: bulkCountA });
100
+ if (remA > 0)
101
+ path.push({ type: 'goPrevious', count: remA });
102
+ return path;
103
+ }
104
+ const MAX_GO_TO_PAGE_RETRIES = 200;
105
+ /**
106
+ * Navigate to targetPageIndex when goToPage is available but may be "windowed"
107
+ * (e.g. only works for visible page links 6–14). Tries goToPage(target); on false,
108
+ * steps once toward target (goNextBulk/goNext or goPreviousBulk/goPrevious), then retries.
109
+ * Example: from 3 to 38 with windowed goToPage → goToPage(38) false, goNextBulk(), goToPage(38) false, … goToPage(38) true.
110
+ */
111
+ function executeNavigationWithGoToPageRetry(targetPageIndex, primitives, context, getCurrentPage, setCurrentPage) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ var _a, _b;
114
+ if (!primitives.goToPage)
115
+ return;
116
+ for (let i = 0; i < MAX_GO_TO_PAGE_RETRIES; i++) {
117
+ const current = getCurrentPage();
118
+ if (current === targetPageIndex)
119
+ return;
120
+ const ok = yield primitives.goToPage(targetPageIndex, context);
121
+ if (ok) {
122
+ setCurrentPage(targetPageIndex);
123
+ return;
124
+ }
125
+ // Step once toward target. Don't use bulk if it would overshoot and we can't step back (no goPrevious/goNext).
126
+ if (targetPageIndex > current) {
127
+ const nextBulkSize = (_a = primitives.nextBulkPages) !== null && _a !== void 0 ? _a : 1;
128
+ const wouldOvershoot = (current + nextBulkSize) > targetPageIndex;
129
+ const canStepBack = !!primitives.goPrevious;
130
+ const useBulk = primitives.goNextBulk && (!wouldOvershoot || canStepBack);
131
+ if (useBulk && primitives.goNextBulk) {
132
+ const result = yield primitives.goNextBulk(context);
133
+ if (!result)
134
+ throw new Error('bringIntoView: goNextBulk failed during goToPage retry');
135
+ const jumped = typeof result === 'number' ? result : nextBulkSize;
136
+ setCurrentPage(getCurrentPage() + jumped);
137
+ }
138
+ else if (primitives.goNext) {
139
+ const stepped = yield primitives.goNext(context);
140
+ if (!stepped)
141
+ throw new Error('bringIntoView: goNext failed during goToPage retry');
142
+ setCurrentPage(getCurrentPage() + 1);
143
+ }
144
+ else {
145
+ throw new Error(`bringIntoView: goToPage(${targetPageIndex}) returned false and no goNext/goNextBulk to advance`);
146
+ }
147
+ }
148
+ else {
149
+ const prevBulkSize = (_b = primitives.previousBulkPages) !== null && _b !== void 0 ? _b : 1;
150
+ const wouldOvershoot = (current - prevBulkSize) < targetPageIndex;
151
+ const canStepBack = !!primitives.goNext;
152
+ const useBulk = primitives.goPreviousBulk && (!wouldOvershoot || canStepBack);
153
+ if (useBulk && primitives.goPreviousBulk) {
154
+ const result = yield primitives.goPreviousBulk(context);
155
+ if (!result)
156
+ throw new Error('bringIntoView: goPreviousBulk failed during goToPage retry');
157
+ const jumped = typeof result === 'number' ? result : prevBulkSize;
158
+ setCurrentPage(getCurrentPage() - jumped);
159
+ }
160
+ else if (primitives.goPrevious) {
161
+ const stepped = yield primitives.goPrevious(context);
162
+ if (!stepped)
163
+ throw new Error('bringIntoView: goPrevious failed during goToPage retry');
164
+ setCurrentPage(getCurrentPage() - 1);
165
+ }
166
+ else {
167
+ throw new Error(`bringIntoView: goToPage(${targetPageIndex}) returned false and no goPrevious/goPreviousBulk to step back`);
168
+ }
169
+ }
170
+ }
171
+ throw new Error(`bringIntoView: failed to reach page ${targetPageIndex} after ${MAX_GO_TO_PAGE_RETRIES} goToPage retries`);
172
+ });
173
+ }
174
+ /**
175
+ * Executes a navigation path by calling the corresponding primitives.
176
+ * Updates currentPageIndex via the provided setter as steps run.
177
+ */
178
+ function executeNavigationPath(path, primitives, context, getCurrentPage, setCurrentPage) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ for (const step of path) {
181
+ switch (step.type) {
182
+ case 'goToPage':
183
+ if (primitives.goToPage) {
184
+ const ok = yield primitives.goToPage(step.pageIndex, context);
185
+ if (!ok)
186
+ throw new Error(`goToPage(${step.pageIndex}) failed`);
187
+ setCurrentPage(step.pageIndex);
188
+ }
189
+ break;
190
+ case 'goNextBulk':
191
+ for (let i = 0; i < step.count && primitives.goNextBulk; i++) {
192
+ const result = yield primitives.goNextBulk(context);
193
+ if (!result)
194
+ throw new Error('goNextBulk failed');
195
+ const jumped = typeof result === 'number' ? result : 1;
196
+ setCurrentPage(getCurrentPage() + jumped);
197
+ }
198
+ break;
199
+ case 'goNext':
200
+ for (let i = 0; i < step.count && primitives.goNext; i++) {
201
+ const ok = yield primitives.goNext(context);
202
+ if (!ok)
203
+ throw new Error('goNext failed');
204
+ setCurrentPage(getCurrentPage() + 1);
205
+ }
206
+ break;
207
+ case 'goPreviousBulk':
208
+ for (let i = 0; i < step.count && primitives.goPreviousBulk; i++) {
209
+ const result = yield primitives.goPreviousBulk(context);
210
+ if (!result)
211
+ throw new Error('goPreviousBulk failed');
212
+ const jumped = typeof result === 'number' ? result : 1;
213
+ setCurrentPage(getCurrentPage() - jumped);
214
+ }
215
+ break;
216
+ case 'goPrevious':
217
+ for (let i = 0; i < step.count && primitives.goPrevious; i++) {
218
+ const ok = yield primitives.goPrevious(context);
219
+ if (!ok)
220
+ throw new Error('goPrevious failed');
221
+ setCurrentPage(getCurrentPage() - 1);
222
+ }
223
+ break;
224
+ }
225
+ }
226
+ });
227
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.7.3",
3
+ "version": "6.7.4",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",