@rickcedwhat/playwright-smart-table 6.7.1 → 6.7.3

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.
@@ -13,6 +13,7 @@ exports.RowFinder = void 0;
13
13
  const debugUtils_1 = require("../utils/debugUtils");
14
14
  const smartRowArray_1 = require("../utils/smartRowArray");
15
15
  const validation_1 = require("../strategies/validation");
16
+ const elementTracker_1 = require("../utils/elementTracker");
16
17
  class RowFinder {
17
18
  constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }) {
18
19
  this.rootLocator = rootLocator;
@@ -53,54 +54,62 @@ class RowFinder {
53
54
  const allRows = [];
54
55
  const effectiveMaxPages = (_b = (_a = options === null || options === void 0 ? void 0 : options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages) !== null && _b !== void 0 ? _b : Infinity;
55
56
  let pagesScanned = 1;
56
- const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
57
- var _a, _b;
58
- // ... logic ...
59
- let rowLocators = this.resolve(this.config.rowSelector, this.rootLocator);
60
- // Only apply filters if we have them
61
- if (Object.keys(filtersRecord).length > 0) {
62
- rowLocators = this.filterEngine.applyFilters(rowLocators, filtersRecord, map, (_a = options === null || options === void 0 ? void 0 : options.exact) !== null && _a !== void 0 ? _a : false, this.rootLocator.page());
63
- }
64
- const currentRows = yield rowLocators.all();
65
- const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
66
- for (let i = 0; i < currentRows.length; i++) {
67
- const smartRow = this.makeSmartRow(currentRows[i], map, allRows.length + i, this.tableState.currentPageIndex);
68
- if (isRowLoading && (yield isRowLoading(smartRow)))
69
- continue;
70
- allRows.push(smartRow);
71
- }
72
- });
73
- // Scan first page
74
- yield collectMatches();
75
- // Pagination Loop - Corrected logic
76
- // We always scan at least 1 page.
77
- // If maxPages > 1, and we have a pagination strategy, we try to go next.
78
- while (pagesScanned < effectiveMaxPages && this.config.strategies.pagination) {
79
- const context = {
80
- root: this.rootLocator,
81
- config: this.config,
82
- resolve: this.resolve,
83
- page: this.rootLocator.page()
84
- };
85
- // Check if we should stop? (e.g. if we found enough rows? No, findRows finds ALL)
86
- let paginationResult;
87
- if (typeof this.config.strategies.pagination === 'function') {
88
- paginationResult = yield this.config.strategies.pagination(context);
89
- }
90
- else {
91
- // It's a PaginationPrimitives object, use goNext by default for findRows
92
- if (!this.config.strategies.pagination.goNext) {
93
- break; // Cannot paginate forward
57
+ const tracker = new elementTracker_1.ElementTracker('findRows');
58
+ try {
59
+ const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
60
+ var _a, _b;
61
+ let rowLocators = this.resolve(this.config.rowSelector, this.rootLocator);
62
+ // Only apply filters if we have them
63
+ if (Object.keys(filtersRecord).length > 0) {
64
+ rowLocators = this.filterEngine.applyFilters(rowLocators, filtersRecord, map, (_a = options === null || options === void 0 ? void 0 : options.exact) !== null && _a !== void 0 ? _a : false, this.rootLocator.page());
94
65
  }
95
- paginationResult = yield this.config.strategies.pagination.goNext(context);
96
- }
97
- const didPaginate = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
98
- if (!didPaginate)
99
- break;
100
- this.tableState.currentPageIndex++;
101
- pagesScanned++;
102
- // Wait for reload logic if needed? Usually pagination handles it.
66
+ // Get only newly seen matched rows
67
+ const newIndices = yield tracker.getUnseenIndices(rowLocators);
68
+ const currentRows = yield rowLocators.all();
69
+ const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
70
+ for (const idx of newIndices) {
71
+ const smartRow = this.makeSmartRow(currentRows[idx], map, allRows.length, this.tableState.currentPageIndex);
72
+ if (isRowLoading && (yield isRowLoading(smartRow)))
73
+ continue;
74
+ allRows.push(smartRow);
75
+ }
76
+ });
77
+ // Scan first page
103
78
  yield collectMatches();
79
+ // Pagination Loop
80
+ while (pagesScanned < effectiveMaxPages && this.config.strategies.pagination) {
81
+ const context = {
82
+ root: this.rootLocator,
83
+ config: this.config,
84
+ resolve: this.resolve,
85
+ page: this.rootLocator.page()
86
+ };
87
+ let paginationResult;
88
+ if (typeof this.config.strategies.pagination === 'function') {
89
+ paginationResult = yield this.config.strategies.pagination(context);
90
+ }
91
+ 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
+ }
101
+ }
102
+ const didPaginate = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
103
+ if (!didPaginate)
104
+ break;
105
+ const pagesJumped = typeof paginationResult === 'number' ? paginationResult : 1;
106
+ this.tableState.currentPageIndex += pagesJumped;
107
+ pagesScanned += pagesJumped;
108
+ yield collectMatches();
109
+ }
110
+ }
111
+ finally {
112
+ yield tracker.cleanup(this.rootLocator.page());
104
113
  }
105
114
  return (0, smartRowArray_1.createSmartRowArray)(allRows);
106
115
  });
@@ -161,16 +170,22 @@ class RowFinder {
161
170
  paginationResult = yield this.config.strategies.pagination(context);
162
171
  }
163
172
  else {
164
- if (!this.config.strategies.pagination.goNext) {
165
- this.log(`Page ${this.tableState.currentPageIndex}: Pagination failed (no goNext primitive).`);
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).`);
166
181
  return null;
167
182
  }
168
- paginationResult = yield this.config.strategies.pagination.goNext(context);
169
183
  }
170
184
  const didLoadMore = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
171
185
  if (didLoadMore) {
172
- this.tableState.currentPageIndex++;
173
- pagesScanned++;
186
+ const pagesJumped = typeof paginationResult === 'number' ? paginationResult : 1;
187
+ this.tableState.currentPageIndex += pagesJumped;
188
+ pagesScanned += pagesJumped;
174
189
  continue;
175
190
  }
176
191
  else {
package/dist/plugins.d.ts CHANGED
@@ -30,6 +30,9 @@ export declare const Plugins: {
30
30
  goRight: (context: import("./types").StrategyContext) => Promise<void>;
31
31
  goHome: (context: import("./types").StrategyContext) => Promise<void>;
32
32
  };
33
+ loading: {
34
+ isHeaderLoading: () => Promise<boolean>;
35
+ };
33
36
  getCellLocator: ({ row, columnIndex }: any) => any;
34
37
  getActiveCell: ({ page }: any) => Promise<{
35
38
  rowIndex: number;
@@ -33,6 +33,9 @@ export declare const GlideStrategies: {
33
33
  goRight: (context: import("../types").StrategyContext) => Promise<void>;
34
34
  goHome: (context: import("../types").StrategyContext) => Promise<void>;
35
35
  };
36
+ loading: {
37
+ isHeaderLoading: () => Promise<boolean>;
38
+ };
36
39
  getCellLocator: ({ row, columnIndex }: any) => any;
37
40
  getActiveCell: ({ page }: any) => Promise<{
38
41
  rowIndex: number;
@@ -115,6 +115,9 @@ exports.GlideStrategies = {
115
115
  goRight: columns_1.glideGoRight,
116
116
  goHome: columns_1.glideGoHome
117
117
  },
118
+ loading: {
119
+ isHeaderLoading: () => __awaiter(void 0, void 0, void 0, function* () { return false; }) // Glide renders headers on a canvas, there is no innerText delay
120
+ },
118
121
  getCellLocator: exports.glideGetCellLocator,
119
122
  getActiveCell: exports.glideGetActiveCell
120
123
  };
@@ -15,6 +15,8 @@ export declare const Strategies: {
15
15
  previousBulk?: import("..").Selector;
16
16
  first?: import("..").Selector;
17
17
  }, options?: {
18
+ nextBulkPages?: number;
19
+ previousBulkPages?: number;
18
20
  stabilization?: import("./stabilization").StabilizationStrategy;
19
21
  timeout?: number;
20
22
  }) => import("../types").PaginationStrategy;
@@ -8,6 +8,8 @@ export declare const PaginationStrategies: {
8
8
  previousBulk?: Selector;
9
9
  first?: Selector;
10
10
  }, options?: {
11
+ nextBulkPages?: number;
12
+ previousBulkPages?: number;
11
13
  stabilization?: StabilizationStrategy;
12
14
  timeout?: number;
13
15
  }) => PaginationStrategy;
@@ -13,9 +13,9 @@ exports.PaginationStrategies = void 0;
13
13
  const stabilization_1 = require("./stabilization");
14
14
  exports.PaginationStrategies = {
15
15
  click: (selectors, options = {}) => {
16
- var _a;
16
+ var _a, _b, _c;
17
17
  const defaultStabilize = (_a = options.stabilization) !== null && _a !== void 0 ? _a : stabilization_1.StabilizationStrategies.contentChanged({ scope: 'first', timeout: options.timeout });
18
- const createClicker = (selector) => {
18
+ const createClicker = (selector, returnVal = true) => {
19
19
  if (!selector)
20
20
  return undefined;
21
21
  return (context) => __awaiter(void 0, void 0, void 0, function* () {
@@ -26,14 +26,14 @@ exports.PaginationStrategies = {
26
26
  }
27
27
  return yield defaultStabilize(context, () => __awaiter(void 0, void 0, void 0, function* () {
28
28
  yield btn.click({ timeout: 2000 }).catch(() => { });
29
- }));
29
+ })).then(stabilized => stabilized ? returnVal : false);
30
30
  });
31
31
  };
32
32
  return {
33
33
  goNext: createClicker(selectors.next),
34
34
  goPrevious: createClicker(selectors.previous),
35
- goNextBulk: createClicker(selectors.nextBulk),
36
- goPreviousBulk: createClicker(selectors.previousBulk),
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
37
  goToFirst: createClicker(selectors.first)
38
38
  };
39
39
  },
@@ -10,10 +10,13 @@ exports.validateFillStrategy = validateFillStrategy;
10
10
  * @param strategyName - Name of the strategy for error messages
11
11
  */
12
12
  function validatePaginationResult(result, strategyName = 'Custom Pagination Strategy') {
13
- if (typeof result !== 'boolean') {
14
- throw new Error(`[${strategyName}] Pagination strategy must return a boolean (true if paginated, false if no more pages). ` +
13
+ if (typeof result !== 'boolean' && typeof result !== 'number') {
14
+ throw new Error(`[${strategyName}] Pagination strategy must return a boolean (true if paginated, false if no more pages) or a number (pages jumped). ` +
15
15
  `Received: ${typeof result} (${JSON.stringify(result)})`);
16
16
  }
17
+ if (typeof result === 'number') {
18
+ return result > 0;
19
+ }
17
20
  return result;
18
21
  }
19
22
  /**
@@ -3,4 +3,4 @@
3
3
  * This file is generated by scripts/embed-types.js
4
4
  * It contains the raw text of types.ts to provide context for LLM prompts.
5
5
  */
6
- export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * 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 */\n goNextBulk?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip backward multiple pages at once */\n goPreviousBulk?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to specific page index (0-indexed) */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n}\n\nexport type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell.\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 /** 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";
@@ -231,11 +231,11 @@ export interface PaginationPrimitives {
231
231
  /** Classic "Previous Page" or "Scroll Up" */
232
232
  goPrevious?: (context: TableContext) => Promise<boolean>;
233
233
 
234
- /** Bulk skip forward multiple pages at once */
235
- goNextBulk?: (context: TableContext) => Promise<boolean>;
234
+ /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */
235
+ goNextBulk?: (context: TableContext) => Promise<boolean | number>;
236
236
 
237
- /** Bulk skip backward multiple pages at once */
238
- goPreviousBulk?: (context: TableContext) => Promise<boolean>;
237
+ /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */
238
+ goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;
239
239
 
240
240
  /** Jump to first page / scroll to top */
241
241
  goToFirst?: (context: TableContext) => Promise<boolean>;
@@ -244,7 +244,7 @@ export interface PaginationPrimitives {
244
244
  goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
245
245
  }
246
246
 
247
- export type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;
247
+ export type PaginationStrategy = ((context: TableContext) => Promise<boolean | number>) | PaginationPrimitives;
248
248
 
249
249
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
250
250
 
package/dist/types.d.ts CHANGED
@@ -205,16 +205,16 @@ export interface PaginationPrimitives {
205
205
  goNext?: (context: TableContext) => Promise<boolean>;
206
206
  /** Classic "Previous Page" or "Scroll Up" */
207
207
  goPrevious?: (context: TableContext) => Promise<boolean>;
208
- /** Bulk skip forward multiple pages at once */
209
- goNextBulk?: (context: TableContext) => Promise<boolean>;
210
- /** Bulk skip backward multiple pages at once */
211
- goPreviousBulk?: (context: TableContext) => Promise<boolean>;
208
+ /** Bulk skip forward multiple pages at once. Returns number of pages skipped. */
209
+ goNextBulk?: (context: TableContext) => Promise<boolean | number>;
210
+ /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */
211
+ goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;
212
212
  /** Jump to first page / scroll to top */
213
213
  goToFirst?: (context: TableContext) => Promise<boolean>;
214
214
  /** Jump to specific page index (0-indexed) */
215
215
  goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;
216
216
  }
217
- export type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;
217
+ export type PaginationStrategy = ((context: TableContext) => Promise<boolean | number>) | PaginationPrimitives;
218
218
  export type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;
219
219
  export type FillStrategy = (options: {
220
220
  row: SmartRow;
package/dist/useTable.js CHANGED
@@ -33,6 +33,7 @@ const tableMapper_1 = require("./engine/tableMapper");
33
33
  const rowFinder_1 = require("./engine/rowFinder");
34
34
  const debugUtils_1 = require("./utils/debugUtils");
35
35
  const smartRowArray_1 = require("./utils/smartRowArray");
36
+ const elementTracker_1 = require("./utils/elementTracker");
36
37
  /**
37
38
  * Main hook to interact with a table.
38
39
  */
@@ -266,19 +267,27 @@ const useTable = (rootLocator, configOptions = {}) => {
266
267
  yield __await(_autoInit());
267
268
  const map = tableMapper.getMapSync();
268
269
  const effectiveMaxPages = config.maxPages;
269
- let rowIndex = 0;
270
- let pagesScanned = 1;
271
- while (true) {
272
- const pageRows = yield __await(resolve(config.rowSelector, rootLocator).all());
273
- for (const rowLocator of pageRows) {
274
- yield yield __await({ row: _makeSmart(rowLocator, map, rowIndex), rowIndex });
275
- rowIndex++;
270
+ const tracker = new elementTracker_1.ElementTracker('iterator');
271
+ try {
272
+ let rowIndex = 0;
273
+ let pagesScanned = 1;
274
+ while (true) {
275
+ const rowLocators = resolve(config.rowSelector, rootLocator);
276
+ const newIndices = yield __await(tracker.getUnseenIndices(rowLocators));
277
+ const pageRows = yield __await(rowLocators.all());
278
+ for (const idx of newIndices) {
279
+ yield yield __await({ row: _makeSmart(pageRows[idx], map, rowIndex), rowIndex });
280
+ rowIndex++;
281
+ }
282
+ if (pagesScanned >= effectiveMaxPages)
283
+ break;
284
+ if (!(yield __await(_advancePage())))
285
+ break;
286
+ pagesScanned++;
276
287
  }
277
- if (pagesScanned >= effectiveMaxPages)
278
- break;
279
- if (!(yield __await(_advancePage())))
280
- break;
281
- pagesScanned++;
288
+ }
289
+ finally {
290
+ yield __await(tracker.cleanup(rootLocator.page()));
282
291
  }
283
292
  });
284
293
  },
@@ -291,45 +300,53 @@ const useTable = (rootLocator, configOptions = {}) => {
291
300
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
292
301
  const dedupeKeys = dedupeStrategy ? new Set() : null;
293
302
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
294
- let rowIndex = 0;
295
- let stopped = false;
296
- let pagesScanned = 1;
297
- const stop = () => { stopped = true; };
298
- while (!stopped) {
299
- const pageRows = yield resolve(config.rowSelector, rootLocator).all();
300
- const smartRows = pageRows.map((r, i) => _makeSmart(r, map, rowIndex + i));
301
- if (parallel) {
302
- yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
303
- if (stopped)
304
- return;
305
- if (dedupeKeys) {
306
- const key = yield dedupeStrategy(row);
307
- if (dedupeKeys.has(key))
303
+ const tracker = new elementTracker_1.ElementTracker('forEach');
304
+ try {
305
+ let rowIndex = 0;
306
+ let stopped = false;
307
+ let pagesScanned = 1;
308
+ const stop = () => { stopped = true; };
309
+ while (!stopped) {
310
+ const rowLocators = resolve(config.rowSelector, rootLocator);
311
+ const newIndices = yield tracker.getUnseenIndices(rowLocators);
312
+ const pageRows = yield rowLocators.all();
313
+ const smartRows = newIndices.map((idx, i) => _makeSmart(pageRows[idx], map, rowIndex + i));
314
+ if (parallel) {
315
+ yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
316
+ if (stopped)
308
317
  return;
309
- dedupeKeys.add(key);
310
- }
311
- yield callback({ row, rowIndex: row.rowIndex, stop });
312
- })));
313
- }
314
- else {
315
- for (const row of smartRows) {
316
- if (stopped)
317
- break;
318
- if (dedupeKeys) {
319
- const key = yield dedupeStrategy(row);
320
- if (dedupeKeys.has(key))
321
- continue;
322
- dedupeKeys.add(key);
318
+ if (dedupeKeys) {
319
+ const key = yield dedupeStrategy(row);
320
+ if (dedupeKeys.has(key))
321
+ return;
322
+ dedupeKeys.add(key);
323
+ }
324
+ yield callback({ row, rowIndex: row.rowIndex, stop });
325
+ })));
326
+ }
327
+ else {
328
+ for (const row of smartRows) {
329
+ if (stopped)
330
+ break;
331
+ if (dedupeKeys) {
332
+ const key = yield dedupeStrategy(row);
333
+ if (dedupeKeys.has(key))
334
+ continue;
335
+ dedupeKeys.add(key);
336
+ }
337
+ yield callback({ row, rowIndex: row.rowIndex, stop });
323
338
  }
324
- yield callback({ row, rowIndex: row.rowIndex, stop });
325
339
  }
340
+ rowIndex += smartRows.length;
341
+ if (stopped || pagesScanned >= effectiveMaxPages)
342
+ break;
343
+ if (!(yield _advancePage()))
344
+ break;
345
+ pagesScanned++;
326
346
  }
327
- rowIndex += smartRows.length;
328
- if (stopped || pagesScanned >= effectiveMaxPages)
329
- break;
330
- if (!(yield _advancePage()))
331
- break;
332
- pagesScanned++;
347
+ }
348
+ finally {
349
+ yield tracker.cleanup(rootLocator.page());
333
350
  }
334
351
  }),
335
352
  map: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
@@ -340,49 +357,57 @@ const useTable = (rootLocator, configOptions = {}) => {
340
357
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
341
358
  const dedupeKeys = dedupeStrategy ? new Set() : null;
342
359
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : true;
360
+ const tracker = new elementTracker_1.ElementTracker('map');
343
361
  const results = [];
344
- let rowIndex = 0;
345
- let stopped = false;
346
- let pagesScanned = 1;
347
- const stop = () => { stopped = true; };
348
- while (!stopped) {
349
- const pageRows = yield resolve(config.rowSelector, rootLocator).all();
350
- const smartRows = pageRows.map((r, i) => _makeSmart(r, map, rowIndex + i));
351
- if (parallel) {
352
- const SKIP = Symbol('skip');
353
- const pageResults = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
354
- if (dedupeKeys) {
355
- const key = yield dedupeStrategy(row);
356
- if (dedupeKeys.has(key))
357
- return SKIP;
358
- dedupeKeys.add(key);
362
+ try {
363
+ let rowIndex = 0;
364
+ let stopped = false;
365
+ let pagesScanned = 1;
366
+ const stop = () => { stopped = true; };
367
+ while (!stopped) {
368
+ const rowLocators = resolve(config.rowSelector, rootLocator);
369
+ const newIndices = yield tracker.getUnseenIndices(rowLocators);
370
+ const pageRows = yield rowLocators.all();
371
+ const smartRows = newIndices.map((idx, i) => _makeSmart(pageRows[idx], map, rowIndex + i));
372
+ if (parallel) {
373
+ const SKIP = Symbol('skip');
374
+ const pageResults = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
375
+ if (dedupeKeys) {
376
+ const key = yield dedupeStrategy(row);
377
+ if (dedupeKeys.has(key))
378
+ return SKIP;
379
+ dedupeKeys.add(key);
380
+ }
381
+ return callback({ row, rowIndex: row.rowIndex, stop });
382
+ })));
383
+ for (const r of pageResults) {
384
+ if (r !== SKIP)
385
+ results.push(r);
359
386
  }
360
- return callback({ row, rowIndex: row.rowIndex, stop });
361
- })));
362
- for (const r of pageResults) {
363
- if (r !== SKIP)
364
- results.push(r);
365
387
  }
366
- }
367
- else {
368
- for (const row of smartRows) {
369
- if (stopped)
370
- break;
371
- if (dedupeKeys) {
372
- const key = yield dedupeStrategy(row);
373
- if (dedupeKeys.has(key))
374
- continue;
375
- dedupeKeys.add(key);
388
+ else {
389
+ for (const row of smartRows) {
390
+ if (stopped)
391
+ break;
392
+ if (dedupeKeys) {
393
+ const key = yield dedupeStrategy(row);
394
+ if (dedupeKeys.has(key))
395
+ continue;
396
+ dedupeKeys.add(key);
397
+ }
398
+ results.push(yield callback({ row, rowIndex: row.rowIndex, stop }));
376
399
  }
377
- results.push(yield callback({ row, rowIndex: row.rowIndex, stop }));
378
400
  }
401
+ rowIndex += smartRows.length;
402
+ if (stopped || pagesScanned >= effectiveMaxPages)
403
+ break;
404
+ if (!(yield _advancePage()))
405
+ break;
406
+ pagesScanned++;
379
407
  }
380
- rowIndex += smartRows.length;
381
- if (stopped || pagesScanned >= effectiveMaxPages)
382
- break;
383
- if (!(yield _advancePage()))
384
- break;
385
- pagesScanned++;
408
+ }
409
+ finally {
410
+ yield tracker.cleanup(rootLocator.page());
386
411
  }
387
412
  return results;
388
413
  }),
@@ -394,48 +419,56 @@ const useTable = (rootLocator, configOptions = {}) => {
394
419
  const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
395
420
  const dedupeKeys = dedupeStrategy ? new Set() : null;
396
421
  const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
422
+ const tracker = new elementTracker_1.ElementTracker('filter');
397
423
  const matched = [];
398
- let rowIndex = 0;
399
- let stopped = false;
400
- let pagesScanned = 1;
401
- const stop = () => { stopped = true; };
402
- while (!stopped) {
403
- const pageRows = yield resolve(config.rowSelector, rootLocator).all();
404
- const smartRows = pageRows.map((r, i) => _makeSmart(r, map, rowIndex + i, pagesScanned - 1));
405
- if (parallel) {
406
- const flags = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
407
- if (dedupeKeys) {
408
- const key = yield dedupeStrategy(row);
409
- if (dedupeKeys.has(key))
410
- return false;
411
- dedupeKeys.add(key);
412
- }
413
- return predicate({ row, rowIndex: row.rowIndex, stop });
414
- })));
415
- smartRows.forEach((row, i) => { if (flags[i])
416
- matched.push(row); });
417
- }
418
- else {
419
- for (const row of smartRows) {
420
- if (stopped)
421
- break;
422
- if (dedupeKeys) {
423
- const key = yield dedupeStrategy(row);
424
- if (dedupeKeys.has(key))
425
- continue;
426
- dedupeKeys.add(key);
427
- }
428
- if (yield predicate({ row, rowIndex: row.rowIndex, stop })) {
429
- matched.push(row);
424
+ try {
425
+ let rowIndex = 0;
426
+ let stopped = false;
427
+ let pagesScanned = 1;
428
+ const stop = () => { stopped = true; };
429
+ while (!stopped) {
430
+ const rowLocators = resolve(config.rowSelector, rootLocator);
431
+ const newIndices = yield tracker.getUnseenIndices(rowLocators);
432
+ const pageRows = yield rowLocators.all();
433
+ const smartRows = newIndices.map((idx, i) => _makeSmart(pageRows[idx], map, rowIndex + i, pagesScanned - 1));
434
+ if (parallel) {
435
+ const flags = yield Promise.all(smartRows.map((row) => __awaiter(void 0, void 0, void 0, function* () {
436
+ if (dedupeKeys) {
437
+ const key = yield dedupeStrategy(row);
438
+ if (dedupeKeys.has(key))
439
+ return false;
440
+ dedupeKeys.add(key);
441
+ }
442
+ return predicate({ row, rowIndex: row.rowIndex, stop });
443
+ })));
444
+ smartRows.forEach((row, i) => { if (flags[i])
445
+ matched.push(row); });
446
+ }
447
+ else {
448
+ for (const row of smartRows) {
449
+ if (stopped)
450
+ break;
451
+ if (dedupeKeys) {
452
+ const key = yield dedupeStrategy(row);
453
+ if (dedupeKeys.has(key))
454
+ continue;
455
+ dedupeKeys.add(key);
456
+ }
457
+ if (yield predicate({ row, rowIndex: row.rowIndex, stop })) {
458
+ matched.push(row);
459
+ }
430
460
  }
431
461
  }
462
+ rowIndex += smartRows.length;
463
+ if (stopped || pagesScanned >= effectiveMaxPages)
464
+ break;
465
+ if (!(yield _advancePage()))
466
+ break;
467
+ pagesScanned++;
432
468
  }
433
- rowIndex += smartRows.length;
434
- if (stopped || pagesScanned >= effectiveMaxPages)
435
- break;
436
- if (!(yield _advancePage()))
437
- break;
438
- pagesScanned++;
469
+ }
470
+ finally {
471
+ yield tracker.cleanup(rootLocator.page());
439
472
  }
440
473
  return (0, smartRowArray_1.createSmartRowArray)(matched);
441
474
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.7.1",
3
+ "version": "6.7.3",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",
@@ -23,11 +23,16 @@
23
23
  "docs:build": "vitepress build docs",
24
24
  "build": "npm run generate-types && npm run generate-config-types && npm run generate-docs && npm run generate-all-api-docs && npm run update-all-api-signatures && tsc",
25
25
  "prepublishOnly": "npm run build",
26
+ "clean-port": "lsof -ti:3000 | xargs kill -9 || true",
27
+ "pretest": "npm run clean-port",
28
+ "posttest": "npm run clean-port",
26
29
  "test": "npm run test:unit && npx playwright test",
27
30
  "test:unit": "vitest run --reporter=verbose --reporter=html",
28
31
  "test:unit:ui": "vitest --ui",
32
+ "pretest:e2e": "npm run clean-port",
33
+ "posttest:e2e": "npm run clean-port",
29
34
  "test:e2e": "npx playwright test",
30
- "test:compatibility": "npx playwright test compatibility",
35
+ "test:compatibility": "npm run clean-port && npx playwright test compatibility",
31
36
  "prepare": "husky install"
32
37
  },
33
38
  "keywords": [