@rickcedwhat/playwright-smart-table 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,55 @@
1
1
  export * from './pagination';
2
2
  export * from './sorting';
3
+ export * from './columns';
4
+ export * from './headers';
5
+ export * from './fill';
6
+ export * from './resolution';
7
+ export declare const Strategies: {
8
+ Pagination: {
9
+ clickNext: (nextButtonSelector: import("..").Selector, timeout?: number) => import("..").PaginationStrategy;
10
+ clickLoadMore: (buttonSelector: import("..").Selector, timeout?: number) => import("..").PaginationStrategy;
11
+ infiniteScroll: (timeout?: number) => import("..").PaginationStrategy;
12
+ };
13
+ Sorting: {
14
+ AriaSort: () => import("..").SortingStrategy;
15
+ };
16
+ Column: {
17
+ default: () => Promise<void>;
18
+ keyboard: (context: import("..").StrategyContext & {
19
+ column: string;
20
+ index: number;
21
+ rowIndex?: number;
22
+ }) => Promise<void>;
23
+ };
24
+ CellNavigation: {
25
+ default: () => Promise<void>;
26
+ keyboard: (context: import("..").StrategyContext & {
27
+ column: string;
28
+ index: number;
29
+ rowIndex?: number;
30
+ }) => Promise<void>;
31
+ };
32
+ Header: {
33
+ visible: ({ config, resolve, root }: import("..").StrategyContext) => Promise<string[]>;
34
+ scrollRight: (context: import("..").StrategyContext, options?: {
35
+ limit?: number;
36
+ selector?: string;
37
+ scrollAmount?: number;
38
+ }) => Promise<string[]>;
39
+ keyboard: (context: import("..").StrategyContext, options?: {
40
+ limit?: number;
41
+ maxSilentClicks?: number;
42
+ }) => Promise<string[]>;
43
+ };
44
+ Fill: {
45
+ default: ({ row, columnName, value, fillOptions }: Parameters<import("..").FillStrategy>[0]) => Promise<void>;
46
+ };
47
+ Resolution: {
48
+ default: import("./resolution").ColumnResolutionStrategy;
49
+ };
50
+ DeprecatedPagination: {
51
+ clickNext: (nextButtonSelector: import("..").Selector, timeout?: number) => import("..").PaginationStrategy;
52
+ clickLoadMore: (buttonSelector: import("..").Selector, timeout?: number) => import("..").PaginationStrategy;
53
+ infiniteScroll: (timeout?: number) => import("..").PaginationStrategy;
54
+ };
55
+ };
@@ -14,6 +14,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- // src/strategies/index.ts
17
+ exports.Strategies = void 0;
18
+ const pagination_1 = require("./pagination");
19
+ const sorting_1 = require("./sorting");
20
+ const columns_1 = require("./columns");
21
+ const headers_1 = require("./headers");
22
+ const fill_1 = require("./fill");
23
+ const resolution_1 = require("./resolution");
18
24
  __exportStar(require("./pagination"), exports);
19
25
  __exportStar(require("./sorting"), exports);
26
+ __exportStar(require("./columns"), exports);
27
+ __exportStar(require("./headers"), exports);
28
+ __exportStar(require("./fill"), exports);
29
+ __exportStar(require("./resolution"), exports);
30
+ exports.Strategies = {
31
+ Pagination: pagination_1.PaginationStrategies,
32
+ Sorting: sorting_1.SortingStrategies,
33
+ Column: columns_1.ColumnStrategies,
34
+ CellNavigation: columns_1.CellNavigationStrategies,
35
+ Header: headers_1.HeaderStrategies,
36
+ Fill: fill_1.FillStrategies,
37
+ Resolution: resolution_1.ResolutionStrategies,
38
+ // Alias for backward compatibility if needed, though we are encouraging the new structure
39
+ DeprecatedPagination: pagination_1.DeprecatedPaginationStrategies
40
+ };
@@ -16,7 +16,7 @@ export declare const PaginationStrategies: {
16
16
  /**
17
17
  * @deprecated Use `PaginationStrategies` instead. This alias will be removed in a future major version.
18
18
  */
19
- export declare const TableStrategies: {
19
+ export declare const DeprecatedPaginationStrategies: {
20
20
  /**
21
21
  * Strategy: Clicks a "Next" button and waits for the first row of data to change.
22
22
  */
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TableStrategies = exports.PaginationStrategies = void 0;
12
+ exports.DeprecatedPaginationStrategies = exports.PaginationStrategies = void 0;
13
13
  const utils_1 = require("../utils");
14
14
  exports.PaginationStrategies = {
15
15
  /**
@@ -69,4 +69,4 @@ exports.PaginationStrategies = {
69
69
  /**
70
70
  * @deprecated Use `PaginationStrategies` instead. This alias will be removed in a future major version.
71
71
  */
72
- exports.TableStrategies = exports.PaginationStrategies;
72
+ exports.DeprecatedPaginationStrategies = exports.PaginationStrategies;
@@ -0,0 +1,22 @@
1
+ import { StrategyContext } from '../types';
2
+ export interface ColumnResolutionStrategy {
3
+ /**
4
+ * Resolves a column name (string or Regex) to a column index.
5
+ * Returns undefined if not found.
6
+ */
7
+ resolveIndex(options: {
8
+ query: string | RegExp;
9
+ headerMap: Map<string, number>;
10
+ context: StrategyContext;
11
+ }): number | undefined;
12
+ /**
13
+ * Resolves a column name to a clean string name (for error messages or debugging).
14
+ */
15
+ resolveName(options: {
16
+ query: string | RegExp;
17
+ headerMap: Map<string, number>;
18
+ }): string;
19
+ }
20
+ export declare const ResolutionStrategies: {
21
+ default: ColumnResolutionStrategy;
22
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResolutionStrategies = void 0;
4
+ exports.ResolutionStrategies = {
5
+ default: {
6
+ resolveIndex: ({ query, headerMap }) => {
7
+ // 1. Exact / String Match
8
+ if (typeof query === 'string') {
9
+ if (headerMap.has(query))
10
+ return headerMap.get(query);
11
+ }
12
+ // 2. Regex Match
13
+ if (query instanceof RegExp) {
14
+ for (const [colName, idx] of headerMap.entries()) {
15
+ if (query.test(colName))
16
+ return idx;
17
+ }
18
+ return undefined;
19
+ }
20
+ // 3. (Optional) Fuzzy String Match fallback could go here
21
+ // But for strict default strategy, we might want to keep it simple first
22
+ // The original code didn't do fuzzy *resolution* logic inside the get(), it just did strict get().
23
+ // The fuzzy logic was only for *suggestions* on error.
24
+ return undefined;
25
+ },
26
+ resolveName: ({ query }) => {
27
+ return query.toString();
28
+ }
29
+ }
30
+ };
@@ -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 = "\nexport type Selector = string | ((root: Locator | Page) => Locator);\n\nexport type SmartRow = Locator & {\n getRequestIndex(): number | undefined; // Helper to get the row index if known\n rowIndex?: number;\n getCell(column: string): Locator;\n toJSON(): Promise<Record<string, string>>;\n /**\n * Fills the row with data. Automatically detects input types (text input, select, checkbox, etc.).\n */\n fill: (data: Record<string, any>, options?: FillOptions) => Promise<void>;\n /**\n * Alias for fill() to avoid conflict with Locator.fill() \n */\n smartFill: (data: Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\nexport interface TableContext {\n root: Locator;\n config: FinalTableConfig;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n}\n\nexport type PaginationStrategy = (context: TableContext) => Promise<boolean>;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n includeTypes?: boolean;\n}\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport type { HeaderStrategy } from './strategies/headers';\nexport type { ColumnStrategy } from './strategies/columns';\n\n/**\n * Configuration options for useTable.\n */\nexport interface TableConfig {\n /** Selector for the table headers */\n headerSelector?: string;\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string;\n /** Strategy for filling forms within the table */\n fillStrategy?: FillStrategy;\n /** Strategy for discovering headers */\n headerStrategy?: HeaderStrategy;\n /** Strategy for navigating to columns */\n columnStrategy?: ColumnStrategy;\n /** Number of pages to scan for verification */\n maxPages?: number;\n\n /** Pagination Strategy */\n pagination?: PaginationStrategy;\n /** Sorting Strategy */\n sorting?: SortingStrategy;\n /** \n * Hook to rename columns dynamically.\n */\n headerTransformer?: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Enable debug logs */\n debug?: boolean;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /**\n * Custom resolver for finding a cell. \n * Overrides cellSelector logic if provided.\n * Useful for virtualized tables where nth() index doesn't match DOM index.\n */\n cellResolver?: (args: { row: Locator, columnName: string, columnIndex: number, rowIndex?: number }) => Locator;\n}\n\nexport interface FinalTableConfig extends TableConfig {\n headerSelector: string;\n rowSelector: string;\n cellSelector: string;\n fillStrategy: FillStrategy;\n headerStrategy: HeaderStrategy;\n columnStrategy: ColumnStrategy;\n maxPages: number;\n pagination: PaginationStrategy;\n autoScroll: boolean;\n debug: boolean;\n headerTransformer: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n cellResolver?: (args: { row: Locator, columnName: string, columnIndex: number, rowIndex?: number }) => Locator;\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\nexport interface TableResult {\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 getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getByRow: {\n (index: number): SmartRow;\n (\n filters: Record<string, string | RegExp | number>,\n options?: { exact?: boolean }\n ): SmartRow;\n };\n\n /**\n * Searches for a row across all available data using the configured strategy (pagination, scroll, etc.).\n * Auto-initializes if needed.\n */\n searchForRow: (\n filters: Record<string, string | RegExp | number>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * Manually scrolls to a column using the configured ColumnStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n getAllCurrentRows: <T extends { asJSON?: boolean }>(\n options?: { filter?: Record<string, any>, exact?: boolean } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n /**\n * @deprecated Use getAllCurrentRows instead. This method will be removed in a future major version.\n */\n getAllRows: <T extends { asJSON?: boolean }>(\n options?: { filter?: Record<string, any>, exact?: boolean } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n generateStrategyPrompt: (options?: PromptOptions) => Promise<void>;\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRow[];\n allData: T[];\n table: RestrictedTableResult;\n }) => T | Promise<T>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n onFirst?: (context: { index: number, rows: SmartRow[], allData: any[] }) => void | Promise<void>;\n onLast?: (context: { index: number, rows: SmartRow[], allData: any[] }) => void | Promise<void>;\n }\n ) => Promise<T[]>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult = Omit<TableResult, 'searchForRow' | 'iterateThroughTable' | 'reset' | 'getAllRows'>;\n";
6
+ export declare const TYPE_CONTEXT = "\nexport type Selector = string | ((root: Locator | Page) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\nexport type SmartRow<T = any> = Locator & {\n getRequestIndex(): number | undefined;\n rowIndex?: number;\n getCell(column: string): Locator;\n toJSON(options?: { columns?: string[] }): Promise<T>;\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known.\n */\n bringIntoView(): Promise<void>;\n /**\n * Fills the row with data. Automatically detects input types.\n */\n fill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n /**\n * Alias for fill() to avoid conflict with Locator.fill()\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\nexport interface TableContext {\n root: Locator;\n config: FinalTableConfig;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n}\n\nexport type PaginationStrategy = (context: TableContext) => Promise<boolean>;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n includeTypes?: boolean;\n}\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport type { HeaderStrategy } from './strategies/headers';\nexport type { CellNavigationStrategy } from './strategies/columns';\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: string | RegExp | number };\n colIndex: number;\n tableContext: TableContext;\n }): Locator;\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 /** Strategy for navigating to specific cells (row + column) */\n cellNavigation?: CellNavigationStrategy;\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 /** Function to get a cell locator */\n getCellLocator?: GetCellLocatorFn;\n /** Function to get the currently active/focused cell */\n getActiveCell?: GetActiveCellFn;\n}\n\n/**\n * Configuration options for useTable.\n */\nexport interface TableConfig {\n /** Selector for the table headers */\n headerSelector?: string;\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 }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Enable debug logs */\n debug?: boolean;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n}\n\nexport interface FinalTableConfig extends TableConfig {\n headerSelector: string;\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug: boolean;\n headerTransformer: (args: { text: string, index: number, locator: Locator }) => 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\nexport interface TableResult<T = any> {\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n 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 getByRow: (\n filters: Record<string, string | RegExp | number>,\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 getByRowIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\n ) => SmartRow;\n\n /**\n * Searches for a row across all available data using the configured strategy (pagination, scroll, etc.).\n * Auto-initializes if needed.\n */\n searchForRow: (\n filters: Record<string, string | RegExp | number>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n getAllCurrentRows: <T extends { asJSON?: boolean }>(\n options?: { filter?: Record<string, any>, exact?: boolean } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n /**\n * @deprecated Use getAllCurrentRows instead. This method will be removed in a future major version.\n */\n getAllRows: <T extends { asJSON?: boolean }>(\n options?: { filter?: Record<string, any>, exact?: boolean } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n generateStrategyPrompt: (options?: PromptOptions) => Promise<void>;\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRow[];\n allData: T[];\n table: RestrictedTableResult;\n }) => T | Promise<T>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n onFirst?: (context: { index: number, rows: SmartRow[], allData: any[] }) => void | Promise<void>;\n onLast?: (context: { index: number, rows: SmartRow[], allData: any[] }) => void | Promise<void>;\n }\n ) => Promise<T[]>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset' | 'getAllRows'>;\n";
@@ -9,19 +9,48 @@ exports.TYPE_CONTEXT = void 0;
9
9
  exports.TYPE_CONTEXT = `
10
10
  export type Selector = string | ((root: Locator | Page) => Locator);
11
11
 
12
- export type SmartRow = Locator & {
13
- getRequestIndex(): number | undefined; // Helper to get the row index if known
12
+ /**
13
+ * Function to get a cell locator given row, column info.
14
+ * Replaces the old cellResolver.
15
+ */
16
+ export type GetCellLocatorFn = (args: {
17
+ row: Locator;
18
+ columnName: string;
19
+ columnIndex: number;
20
+ rowIndex?: number;
21
+ page: Page;
22
+ }) => Locator;
23
+
24
+ /**
25
+ * Function to get the currently active/focused cell.
26
+ * Returns null if no cell is active.
27
+ */
28
+ export type GetActiveCellFn = (args: TableContext) => Promise<{
29
+ rowIndex: number;
30
+ columnIndex: number;
31
+ columnName?: string;
32
+ locator: Locator;
33
+ } | null>;
34
+
35
+
36
+ export type SmartRow<T = any> = Locator & {
37
+ getRequestIndex(): number | undefined;
14
38
  rowIndex?: number;
15
39
  getCell(column: string): Locator;
16
- toJSON(): Promise<Record<string, string>>;
40
+ toJSON(options?: { columns?: string[] }): Promise<T>;
17
41
  /**
18
- * Fills the row with data. Automatically detects input types (text input, select, checkbox, etc.).
42
+ * Scrolls/paginates to bring this row into view.
43
+ * Only works if rowIndex is known.
19
44
  */
20
- fill: (data: Record<string, any>, options?: FillOptions) => Promise<void>;
45
+ bringIntoView(): Promise<void>;
21
46
  /**
22
- * Alias for fill() to avoid conflict with Locator.fill()
47
+ * Fills the row with data. Automatically detects input types.
23
48
  */
24
- smartFill: (data: Record<string, any>, options?: FillOptions) => Promise<void>;
49
+ fill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;
50
+ /**
51
+ * Alias for fill() to avoid conflict with Locator.fill()
52
+ */
53
+ smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;
25
54
  };
26
55
 
27
56
  export type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };
@@ -81,7 +110,44 @@ export type FillStrategy = (options: {
81
110
  }) => Promise<void>;
82
111
 
83
112
  export type { HeaderStrategy } from './strategies/headers';
84
- export type { ColumnStrategy } from './strategies/columns';
113
+ export type { CellNavigationStrategy } from './strategies/columns';
114
+
115
+ /**
116
+ * Strategy to resolve column names (string or regex) to their index.
117
+ */
118
+ export type { ColumnResolutionStrategy } from './strategies/resolution';
119
+
120
+ /**
121
+ * Strategy to filter rows based on criteria.
122
+ */
123
+ export interface FilterStrategy {
124
+ apply(options: {
125
+ rows: Locator;
126
+ filter: { column: string, value: string | RegExp | number };
127
+ colIndex: number;
128
+ tableContext: TableContext;
129
+ }): Locator;
130
+ }
131
+
132
+ /**
133
+ * Organized container for all table interaction strategies.
134
+ */
135
+ export interface TableStrategies {
136
+ /** Strategy for discovering/scanning headers */
137
+ header?: HeaderStrategy;
138
+ /** Strategy for navigating to specific cells (row + column) */
139
+ cellNavigation?: CellNavigationStrategy;
140
+ /** Strategy for filling form inputs */
141
+ fill?: FillStrategy;
142
+ /** Strategy for paginating through data */
143
+ pagination?: PaginationStrategy;
144
+ /** Strategy for sorting columns */
145
+ sorting?: SortingStrategy;
146
+ /** Function to get a cell locator */
147
+ getCellLocator?: GetCellLocatorFn;
148
+ /** Function to get the currently active/focused cell */
149
+ getActiveCell?: GetActiveCellFn;
150
+ }
85
151
 
86
152
  /**
87
153
  * Configuration options for useTable.
@@ -93,22 +159,9 @@ export interface TableConfig {
93
159
  rowSelector?: string;
94
160
  /** Selector for the cells within a row */
95
161
  cellSelector?: string;
96
- /** Strategy for filling forms within the table */
97
- fillStrategy?: FillStrategy;
98
- /** Strategy for discovering headers */
99
- headerStrategy?: HeaderStrategy;
100
- /** Strategy for navigating to columns */
101
- columnStrategy?: ColumnStrategy;
102
162
  /** Number of pages to scan for verification */
103
163
  maxPages?: number;
104
-
105
- /** Pagination Strategy */
106
- pagination?: PaginationStrategy;
107
- /** Sorting Strategy */
108
- sorting?: SortingStrategy;
109
- /**
110
- * Hook to rename columns dynamically.
111
- */
164
+ /** Hook to rename columns dynamically */
112
165
  headerTransformer?: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;
113
166
  /** Automatically scroll to table on init */
114
167
  autoScroll?: boolean;
@@ -116,30 +169,23 @@ export interface TableConfig {
116
169
  debug?: boolean;
117
170
  /** Reset hook */
118
171
  onReset?: (context: TableContext) => Promise<void>;
119
- /**
120
- * Custom resolver for finding a cell.
121
- * Overrides cellSelector logic if provided.
122
- * Useful for virtualized tables where nth() index doesn't match DOM index.
123
- */
124
- cellResolver?: (args: { row: Locator, columnName: string, columnIndex: number, rowIndex?: number }) => Locator;
172
+ /** All interaction strategies */
173
+ strategies?: TableStrategies;
125
174
  }
126
175
 
127
176
  export interface FinalTableConfig extends TableConfig {
128
177
  headerSelector: string;
129
178
  rowSelector: string;
130
179
  cellSelector: string;
131
- fillStrategy: FillStrategy;
132
- headerStrategy: HeaderStrategy;
133
- columnStrategy: ColumnStrategy;
134
180
  maxPages: number;
135
- pagination: PaginationStrategy;
136
181
  autoScroll: boolean;
137
182
  debug: boolean;
138
183
  headerTransformer: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;
139
184
  onReset: (context: TableContext) => Promise<void>;
140
- cellResolver?: (args: { row: Locator, columnName: string, columnIndex: number, rowIndex?: number }) => Locator;
185
+ strategies: TableStrategies;
141
186
  }
142
187
 
188
+
143
189
  export interface FillOptions {
144
190
  /**
145
191
  * Custom input mappers for specific columns.
@@ -148,7 +194,7 @@ export interface FillOptions {
148
194
  inputMappers?: Record<string, (cell: Locator) => Locator>;
149
195
  }
150
196
 
151
- export interface TableResult {
197
+ export interface TableResult<T = any> {
152
198
  /**
153
199
  * Initializes the table by resolving headers. Must be called before using sync methods.
154
200
  * @param options Optional timeout for header resolution (default: 3000ms)
@@ -159,16 +205,24 @@ export interface TableResult {
159
205
  getHeaderCell: (columnName: string) => Promise<Locator>;
160
206
 
161
207
  /**
162
- * Finds a row on the current page only. Returns immediately (sync).
208
+ * Finds a row by filters on the current page only. Returns immediately (sync).
163
209
  * Throws error if table is not initialized.
164
210
  */
165
- getByRow: {
166
- (index: number): SmartRow;
167
- (
168
- filters: Record<string, string | RegExp | number>,
169
- options?: { exact?: boolean }
170
- ): SmartRow;
171
- };
211
+ getByRow: (
212
+ filters: Record<string, string | RegExp | number>,
213
+ options?: { exact?: boolean }
214
+ ) => SmartRow;
215
+
216
+ /**
217
+ * Gets a row by 1-based index on the current page.
218
+ * Throws error if table is not initialized.
219
+ * @param index 1-based row index
220
+ * @param options Optional settings including bringIntoView
221
+ */
222
+ getByRowIndex: (
223
+ index: number,
224
+ options?: { bringIntoView?: boolean }
225
+ ) => SmartRow;
172
226
 
173
227
  /**
174
228
  * Searches for a row across all available data using the configured strategy (pagination, scroll, etc.).
@@ -180,7 +234,7 @@ export interface TableResult {
180
234
  ) => Promise<SmartRow>;
181
235
 
182
236
  /**
183
- * Manually scrolls to a column using the configured ColumnStrategy.
237
+ * Navigates to a specific column using the configured CellNavigationStrategy.
184
238
  */
185
239
  scrollToColumn: (columnName: string) => Promise<void>;
186
240
 
@@ -203,6 +257,12 @@ export interface TableResult {
203
257
  */
204
258
  reset: () => Promise<void>;
205
259
 
260
+ /**
261
+ * Revalidates the table's structure (headers, columns) without resetting pagination or state.
262
+ * Useful when columns change visibility or order dynamically.
263
+ */
264
+ revalidate: () => Promise<void>;
265
+
206
266
  /**
207
267
  * Scans a specific column across all pages and returns the values.
208
268
  */
@@ -254,5 +314,5 @@ export interface TableResult {
254
314
  /**
255
315
  * Restricted table result that excludes methods that shouldn't be called during iteration.
256
316
  */
257
- export type RestrictedTableResult = Omit<TableResult, 'searchForRow' | 'iterateThroughTable' | 'reset' | 'getAllRows'>;
317
+ export type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset' | 'getAllRows'>;
258
318
  `;