@rickcedwhat/playwright-smart-table 6.6.0 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -5
- package/dist/engine/rowFinder.d.ts +1 -4
- package/dist/engine/rowFinder.js +9 -40
- package/dist/engine/tableMapper.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +8 -18
- package/dist/plugins.d.ts +0 -1
- package/dist/smartRow.js +59 -25
- package/dist/strategies/index.d.ts +6 -8
- package/dist/strategies/pagination.d.ts +2 -18
- package/dist/strategies/pagination.js +2 -17
- package/dist/strategies/rdg.d.ts +0 -5
- package/dist/strategies/rdg.js +1 -18
- package/dist/strategies/sorting.js +15 -33
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +72 -78
- package/dist/types.d.ts +63 -87
- package/dist/useTable.js +87 -321
- package/dist/utils/elementTracker.d.ts +15 -0
- package/dist/utils/elementTracker.js +60 -0
- package/package.json +1 -1
package/dist/typeContext.d.ts
CHANGED
|
@@ -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 * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /** Jump to specific page index (0-indexed) */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n}\n\nexport type PaginationStrategy = ((context: TableContext) => Promise<boolean>) | PaginationPrimitives;\n\nexport type DedupeStrategy = (row: SmartRow) => string | number | Promise<string | number>;\n\n\n\nexport type FillStrategy = (options: {\n row: SmartRow;\n columnName: string;\n value: any;\n index: number;\n page: Page;\n rootLocator: Locator;\n config: FinalTableConfig<any>;\n table: TableResult; // The parent table instance\n fillOptions?: FillOptions;\n}) => Promise<void>;\n\nexport interface ColumnOverride<TValue = any> {\n /** \n * How to extract the value from the cell. (Replaces dataMapper logic)\n */\n read?: (cell: Locator) => Promise<TValue> | TValue;\n\n /** \n * How to fill the cell with a new value. (Replaces smartFill default logic)\n * Provides the current value (via `read`) if a `write` wants to check state first.\n */\n write?: (params: {\n cell: Locator;\n targetValue: TValue;\n currentValue?: TValue;\n row: SmartRow<any>;\n }) => Promise<void>;\n}\n\nexport type { HeaderStrategy } from './strategies/headers';\n\n/**\n * Strategy to resolve column names (string or regex) to their index.\n */\nexport type { ColumnResolutionStrategy } from './strategies/resolution';\n\n/**\n * Strategy to filter rows based on criteria.\n */\nexport interface FilterStrategy {\n apply(options: {\n rows: Locator;\n filter: { column: string, value: FilterValue };\n colIndex: number;\n tableContext: TableContext;\n }): Locator;\n}\n\n/**\n * Strategy to check if the table or rows are loading.\n */\nexport interface LoadingStrategy {\n isTableLoading?: (context: TableContext) => Promise<boolean>;\n isRowLoading?: (row: SmartRow) => Promise<boolean>;\n isHeaderLoading?: (context: TableContext) => Promise<boolean>;\n}\n\n/**\n * Organized container for all table interaction strategies.\n */\nexport interface TableStrategies {\n /** Strategy for discovering/scanning headers */\n header?: HeaderStrategy;\n /** Primitive navigation functions (goUp, goDown, goLeft, goRight, goHome) */\n navigation?: NavigationPrimitives;\n\n /** Strategy for filling form inputs */\n fill?: FillStrategy;\n /** Strategy for paginating through data */\n pagination?: PaginationStrategy;\n /** Strategy for sorting columns */\n sorting?: SortingStrategy;\n /** Strategy for deduplicating rows during iteration/scrolling */\n dedupe?: DedupeStrategy;\n /** Function to get a cell locator */\n getCellLocator?: GetCellLocatorFn;\n /** Function to get the currently active/focused cell */\n getActiveCell?: GetActiveCellFn;\n /** Custom helper to check if a table is fully loaded/ready */\n isTableLoaded?: (args: TableContext) => Promise<boolean>;\n /** Custom helper to check if a row is fully loaded/ready */\n isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;\n /** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */\n isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;\n /** Strategy for detecting loading states */\n loading?: LoadingStrategy;\n}\n\n\nexport interface TableConfig<T = any> {\n /** Selector for the table headers */\n headerSelector?: string | ((root: Locator) => Locator);\n /** Selector for the table rows */\n rowSelector?: string;\n /** Selector for the cells within a row */\n cellSelector?: string;\n /** Number of pages to scan for verification */\n maxPages?: number;\n /** Hook to rename columns dynamically */\n headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n /** Automatically scroll to table on init */\n autoScroll?: boolean;\n /** Debug options for development and troubleshooting */\n debug?: DebugConfig;\n /** Reset hook */\n onReset?: (context: TableContext) => Promise<void>;\n /** All interaction strategies */\n strategies?: TableStrategies;\n /**\n * @deprecated Use `columnOverrides` instead. `dataMapper` will be removed in v7.0.0.\n * Custom data mappers for specific columns.\n * Allows extracting complex data types (boolean, number) instead of just string.\n */\n dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;\n\n /**\n * Unified interface for reading and writing data to specific columns.\n * Overrides both default extraction (toJSON) and filling (smartFill) logic.\n */\n columnOverrides?: Partial<Record<keyof T, ColumnOverride<T[keyof T]>>>;\n}\n\nexport interface FinalTableConfig<T = any> extends TableConfig<T> {\n headerSelector: string | ((root: Locator) => Locator);\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n/**\n * Options for generateConfigPrompt\n */\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n /**\n * Include TypeScript type definitions in the prompt\n * @default true\n */\n includeTypes?: boolean;\n}\n\n/** Callback context passed to forEach, map, and filter. */\nexport type RowIterationContext<T = any> = {\n row: SmartRow<T>;\n rowIndex: number;\n stop: () => void;\n};\n\n/** Shared options for forEach, map, and filter. */\nexport type RowIterationOptions = {\n /** Maximum number of pages to iterate. Defaults to config.maxPages. */\n maxPages?: number;\n /**\n * Whether to process rows within a page concurrently.\n * @default false for forEach/filter, true for map\n */\n parallel?: boolean;\n /**\n * Deduplication strategy. Use when rows may repeat across iterations\n * (e.g. infinite scroll tables). Returns a unique key per row.\n */\n dedupe?: DedupeStrategy;\n};\n\nexport interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>; rowIndex: number }> {\n /**\n * Represents the current page index of the table's DOM.\n * Starts at 0. Automatically maintained by the library during pagination and bringIntoView.\n */\n currentPageIndex: number;\n\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 1-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 1-based row index\n * @param options Optional settings including bringIntoView\n */\n getRowByIndex: (\n index: number,\n options?: { bringIntoView?: boolean }\n ) => SmartRow;\n\n /**\n * ASYNC: Searches for a single row across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRow>;\n\n /**\n * ASYNC: Searches for all matching rows across pages using pagination.\n * Auto-initializes the table if not already initialized.\n * @param filters - The filter criteria to match\n * @param options - Search options including exact match and max pages\n */\n findRows: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean, maxPages?: number }\n ) => Promise<SmartRowArray<T>>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Iterates every row across all pages, calling the callback for side effects.\n * Execution is sequential by default (safe for interactions like clicking/filling).\n * Call `stop()` in the callback to end iteration early.\n *\n * @example\n * await table.forEach(async ({ row, stop }) => {\n * if (await row.getCell('Status').innerText() === 'Done') stop();\n * await row.getCell('Checkbox').click();\n * });\n */\n forEach(\n callback: (ctx: RowIterationContext<T>) => void | Promise<void>,\n options?: RowIterationOptions\n ): Promise<void>;\n\n /**\n * Transforms every row across all pages into a value. Returns a flat array.\n * Execution is parallel within each page by default (safe for reads).\n * Call `stop()` to halt after the current page finishes.\n *\n * @example\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n * @deprecated Use `table.map(({ row }) => row.getCell(column).innerText())` instead.\n * Will be removed in v7.0.0.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n * @deprecated Use `forEach`, `map`, or `filter` instead for cleaner cross-page iteration.\n * Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).\n * Will be removed in v7.0.0.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRowArray;\n allData: T[];\n table: RestrictedTableResult;\n batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n\n }) => T | T[] | Promise<T | T[]>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n batchSize?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n /**\n * If true, flattens array results from callback into the main data array.\n * If false (default), pushes the return value as-is (preserves batching/arrays).\n */\n autoFlatten?: boolean;\n }\n ) => Promise<T[]>;\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n */\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;\n";
|
|
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";
|
package/dist/typeContext.js
CHANGED
|
@@ -43,6 +43,32 @@ export type GetCellLocatorFn = (args: {
|
|
|
43
43
|
page: Page;
|
|
44
44
|
}) => Locator;
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Hook called before each cell value is read in toJSON (and columnOverrides.read).
|
|
48
|
+
* Use this to scroll off-screen columns into view in horizontally virtualized tables,
|
|
49
|
+
* wait for lazy-rendered content, or perform any pre-read setup.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Scroll the column header into view to trigger horizontal virtualization render
|
|
53
|
+
* strategies: {
|
|
54
|
+
* beforeCellRead: async ({ columnName, getHeaderCell }) => {
|
|
55
|
+
* const header = await getHeaderCell(columnName);
|
|
56
|
+
* await header.scrollIntoViewIfNeeded();
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
export type BeforeCellReadFn = (args: {
|
|
61
|
+
/** The resolved cell locator */
|
|
62
|
+
cell: Locator;
|
|
63
|
+
columnName: string;
|
|
64
|
+
columnIndex: number;
|
|
65
|
+
row: Locator;
|
|
66
|
+
page: Page;
|
|
67
|
+
root: Locator;
|
|
68
|
+
/** Resolves a column name to its header cell locator */
|
|
69
|
+
getHeaderCell: (columnName: string) => Promise<Locator>;
|
|
70
|
+
}) => Promise<void>;
|
|
71
|
+
|
|
46
72
|
/**
|
|
47
73
|
* Function to get the currently active/focused cell.
|
|
48
74
|
* Returns null if no cell is active.
|
|
@@ -126,9 +152,17 @@ export type SmartRow<T = any> = Locator & {
|
|
|
126
152
|
* );
|
|
127
153
|
*/
|
|
128
154
|
smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Returns whether the row exists in the DOM (i.e. is not a sentinel row).
|
|
158
|
+
*/
|
|
159
|
+
wasFound(): boolean;
|
|
129
160
|
};
|
|
130
161
|
|
|
131
|
-
export type StrategyContext = TableContext & {
|
|
162
|
+
export type StrategyContext = TableContext & {
|
|
163
|
+
rowLocator?: Locator;
|
|
164
|
+
rowIndex?: number;
|
|
165
|
+
};
|
|
132
166
|
|
|
133
167
|
/**
|
|
134
168
|
* Defines the contract for a sorting strategy.
|
|
@@ -182,6 +216,12 @@ export interface TableContext<T = any> {
|
|
|
182
216
|
config: FinalTableConfig<T>;
|
|
183
217
|
page: Page;
|
|
184
218
|
resolve: (selector: Selector, parent: Locator | Page) => Locator;
|
|
219
|
+
/** Resolves a column name to its header cell locator. Available after table is initialized. */
|
|
220
|
+
getHeaderCell?: (columnName: string) => Promise<Locator>;
|
|
221
|
+
/** Returns all column names in order. Available after table is initialized. */
|
|
222
|
+
getHeaders?: () => Promise<string[]>;
|
|
223
|
+
/** Scrolls the table horizontally to bring the given column's header into view. */
|
|
224
|
+
scrollToColumn?: (columnName: string) => Promise<void>;
|
|
185
225
|
}
|
|
186
226
|
|
|
187
227
|
export interface PaginationPrimitives {
|
|
@@ -191,6 +231,12 @@ export interface PaginationPrimitives {
|
|
|
191
231
|
/** Classic "Previous Page" or "Scroll Up" */
|
|
192
232
|
goPrevious?: (context: TableContext) => Promise<boolean>;
|
|
193
233
|
|
|
234
|
+
/** Bulk skip forward multiple pages at once */
|
|
235
|
+
goNextBulk?: (context: TableContext) => Promise<boolean>;
|
|
236
|
+
|
|
237
|
+
/** Bulk skip backward multiple pages at once */
|
|
238
|
+
goPreviousBulk?: (context: TableContext) => Promise<boolean>;
|
|
239
|
+
|
|
194
240
|
/** Jump to first page / scroll to top */
|
|
195
241
|
goToFirst?: (context: TableContext) => Promise<boolean>;
|
|
196
242
|
|
|
@@ -218,7 +264,7 @@ export type FillStrategy = (options: {
|
|
|
218
264
|
|
|
219
265
|
export interface ColumnOverride<TValue = any> {
|
|
220
266
|
/**
|
|
221
|
-
* How to extract the value from the cell.
|
|
267
|
+
* How to extract the value from the cell.
|
|
222
268
|
*/
|
|
223
269
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
224
270
|
|
|
@@ -283,6 +329,12 @@ export interface TableStrategies {
|
|
|
283
329
|
getCellLocator?: GetCellLocatorFn;
|
|
284
330
|
/** Function to get the currently active/focused cell */
|
|
285
331
|
getActiveCell?: GetActiveCellFn;
|
|
332
|
+
/**
|
|
333
|
+
* Hook called before each cell value is read in toJSON and columnOverrides.read.
|
|
334
|
+
* Fires for both the default innerText extraction and custom read mappers.
|
|
335
|
+
* Useful for scrolling off-screen columns into view in horizontally virtualized tables.
|
|
336
|
+
*/
|
|
337
|
+
beforeCellRead?: BeforeCellReadFn;
|
|
286
338
|
/** Custom helper to check if a table is fully loaded/ready */
|
|
287
339
|
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
288
340
|
/** Custom helper to check if a row is fully loaded/ready */
|
|
@@ -313,12 +365,6 @@ export interface TableConfig<T = any> {
|
|
|
313
365
|
onReset?: (context: TableContext) => Promise<void>;
|
|
314
366
|
/** All interaction strategies */
|
|
315
367
|
strategies?: TableStrategies;
|
|
316
|
-
/**
|
|
317
|
-
* @deprecated Use \`columnOverrides\` instead. \`dataMapper\` will be removed in v7.0.0.
|
|
318
|
-
* Custom data mappers for specific columns.
|
|
319
|
-
* Allows extracting complex data types (boolean, number) instead of just string.
|
|
320
|
-
*/
|
|
321
|
-
dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
|
|
322
368
|
|
|
323
369
|
/**
|
|
324
370
|
* Unified interface for reading and writing data to specific columns.
|
|
@@ -348,22 +394,7 @@ export interface FillOptions {
|
|
|
348
394
|
inputMappers?: Record<string, (cell: Locator) => Locator>;
|
|
349
395
|
}
|
|
350
396
|
|
|
351
|
-
|
|
352
|
-
* Options for generateConfigPrompt
|
|
353
|
-
*/
|
|
354
|
-
export interface PromptOptions {
|
|
355
|
-
/**
|
|
356
|
-
* Output Strategy:
|
|
357
|
-
* - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).
|
|
358
|
-
* - 'console': Standard console logs (Default).
|
|
359
|
-
*/
|
|
360
|
-
output?: 'console' | 'error';
|
|
361
|
-
/**
|
|
362
|
-
* Include TypeScript type definitions in the prompt
|
|
363
|
-
* @default true
|
|
364
|
-
*/
|
|
365
|
-
includeTypes?: boolean;
|
|
366
|
-
}
|
|
397
|
+
|
|
367
398
|
|
|
368
399
|
/** Callback context passed to forEach, map, and filter. */
|
|
369
400
|
export type RowIterationContext<T = any> = {
|
|
@@ -426,8 +457,7 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
426
457
|
* @param options Optional settings including bringIntoView
|
|
427
458
|
*/
|
|
428
459
|
getRowByIndex: (
|
|
429
|
-
index: number
|
|
430
|
-
options?: { bringIntoView?: boolean }
|
|
460
|
+
index: number
|
|
431
461
|
) => SmartRow;
|
|
432
462
|
|
|
433
463
|
/**
|
|
@@ -491,8 +521,22 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
491
521
|
* Execution is parallel within each page by default (safe for reads).
|
|
492
522
|
* Call \`stop()\` to halt after the current page finishes.
|
|
493
523
|
*
|
|
524
|
+
* > **⚠️ UI Interactions:** \`map\` defaults to \`parallel: true\`. If your callback opens popovers,
|
|
525
|
+
* > fills inputs, or otherwise mutates UI state, pass \`{ parallel: false }\` to avoid concurrent
|
|
526
|
+
* > interactions interfering with each other.
|
|
527
|
+
*
|
|
494
528
|
* @example
|
|
529
|
+
* // Data extraction — parallel is safe
|
|
495
530
|
* const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* // UI interactions — must use parallel: false
|
|
534
|
+
* const assignees = await table.map(async ({ row }) => {
|
|
535
|
+
* await row.getCell('Assignee').locator('button').click();
|
|
536
|
+
* const name = await page.locator('.popover .name').innerText();
|
|
537
|
+
* await page.keyboard.press('Escape');
|
|
538
|
+
* return name;
|
|
539
|
+
* }, { parallel: false });
|
|
496
540
|
*/
|
|
497
541
|
map<R>(
|
|
498
542
|
callback: (ctx: RowIterationContext<T>) => R | Promise<R>,
|
|
@@ -514,13 +558,6 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
514
558
|
options?: RowIterationOptions
|
|
515
559
|
): Promise<SmartRowArray<T>>;
|
|
516
560
|
|
|
517
|
-
/**
|
|
518
|
-
* Scans a specific column across all pages and returns the values.
|
|
519
|
-
* @deprecated Use \`table.map(({ row }) => row.getCell(column).innerText())\` instead.
|
|
520
|
-
* Will be removed in v7.0.0.
|
|
521
|
-
*/
|
|
522
|
-
getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;
|
|
523
|
-
|
|
524
561
|
/**
|
|
525
562
|
* Provides access to sorting actions and assertions.
|
|
526
563
|
*/
|
|
@@ -539,54 +576,11 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
539
576
|
getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;
|
|
540
577
|
};
|
|
541
578
|
|
|
542
|
-
/**
|
|
543
|
-
* Iterates through paginated table data, calling the callback for each iteration.
|
|
544
|
-
* Callback return values are automatically appended to allData, which is returned.
|
|
545
|
-
* @deprecated Use \`forEach\`, \`map\`, or \`filter\` instead for cleaner cross-page iteration.
|
|
546
|
-
* Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).
|
|
547
|
-
* Will be removed in v7.0.0.
|
|
548
|
-
*/
|
|
549
|
-
iterateThroughTable: <T = any>(
|
|
550
|
-
callback: (context: {
|
|
551
|
-
index: number;
|
|
552
|
-
isFirst: boolean;
|
|
553
|
-
isLast: boolean;
|
|
554
|
-
rows: SmartRowArray;
|
|
555
|
-
allData: T[];
|
|
556
|
-
table: RestrictedTableResult;
|
|
557
|
-
batchInfo?: {
|
|
558
|
-
startIndex: number;
|
|
559
|
-
endIndex: number;
|
|
560
|
-
size: number;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
}) => T | T[] | Promise<T | T[]>,
|
|
564
|
-
options?: {
|
|
565
|
-
pagination?: PaginationStrategy;
|
|
566
|
-
dedupeStrategy?: DedupeStrategy;
|
|
567
|
-
maxIterations?: number;
|
|
568
|
-
batchSize?: number;
|
|
569
|
-
getIsFirst?: (context: { index: number }) => boolean;
|
|
570
|
-
getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;
|
|
571
|
-
beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
572
|
-
afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
573
|
-
/**
|
|
574
|
-
* If true, flattens array results from callback into the main data array.
|
|
575
|
-
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
576
|
-
*/
|
|
577
|
-
autoFlatten?: boolean;
|
|
578
|
-
}
|
|
579
|
-
) => Promise<T[]>;
|
|
580
|
-
|
|
581
579
|
/**
|
|
582
580
|
* Generate an AI-friendly configuration prompt for debugging.
|
|
583
581
|
* Outputs table HTML and TypeScript definitions to help AI assistants generate config.
|
|
582
|
+
* Automatically throws an Error containing the prompt.
|
|
584
583
|
*/
|
|
585
|
-
generateConfigPrompt: (
|
|
584
|
+
generateConfigPrompt: () => Promise<void>;
|
|
586
585
|
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Restricted table result that excludes methods that shouldn't be called during iteration.
|
|
590
|
-
*/
|
|
591
|
-
export type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;
|
|
592
586
|
`;
|
package/dist/types.d.ts
CHANGED
|
@@ -33,6 +33,31 @@ export type GetCellLocatorFn = (args: {
|
|
|
33
33
|
rowIndex?: number;
|
|
34
34
|
page: Page;
|
|
35
35
|
}) => Locator;
|
|
36
|
+
/**
|
|
37
|
+
* Hook called before each cell value is read in toJSON (and columnOverrides.read).
|
|
38
|
+
* Use this to scroll off-screen columns into view in horizontally virtualized tables,
|
|
39
|
+
* wait for lazy-rendered content, or perform any pre-read setup.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Scroll the column header into view to trigger horizontal virtualization render
|
|
43
|
+
* strategies: {
|
|
44
|
+
* beforeCellRead: async ({ columnName, getHeaderCell }) => {
|
|
45
|
+
* const header = await getHeaderCell(columnName);
|
|
46
|
+
* await header.scrollIntoViewIfNeeded();
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
export type BeforeCellReadFn = (args: {
|
|
51
|
+
/** The resolved cell locator */
|
|
52
|
+
cell: Locator;
|
|
53
|
+
columnName: string;
|
|
54
|
+
columnIndex: number;
|
|
55
|
+
row: Locator;
|
|
56
|
+
page: Page;
|
|
57
|
+
root: Locator;
|
|
58
|
+
/** Resolves a column name to its header cell locator */
|
|
59
|
+
getHeaderCell: (columnName: string) => Promise<Locator>;
|
|
60
|
+
}) => Promise<void>;
|
|
36
61
|
/**
|
|
37
62
|
* Function to get the currently active/focused cell.
|
|
38
63
|
* Returns null if no cell is active.
|
|
@@ -110,6 +135,10 @@ export type SmartRow<T = any> = Locator & {
|
|
|
110
135
|
* );
|
|
111
136
|
*/
|
|
112
137
|
smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns whether the row exists in the DOM (i.e. is not a sentinel row).
|
|
140
|
+
*/
|
|
141
|
+
wasFound(): boolean;
|
|
113
142
|
};
|
|
114
143
|
export type StrategyContext = TableContext & {
|
|
115
144
|
rowLocator?: Locator;
|
|
@@ -164,12 +193,22 @@ export interface TableContext<T = any> {
|
|
|
164
193
|
config: FinalTableConfig<T>;
|
|
165
194
|
page: Page;
|
|
166
195
|
resolve: (selector: Selector, parent: Locator | Page) => Locator;
|
|
196
|
+
/** Resolves a column name to its header cell locator. Available after table is initialized. */
|
|
197
|
+
getHeaderCell?: (columnName: string) => Promise<Locator>;
|
|
198
|
+
/** Returns all column names in order. Available after table is initialized. */
|
|
199
|
+
getHeaders?: () => Promise<string[]>;
|
|
200
|
+
/** Scrolls the table horizontally to bring the given column's header into view. */
|
|
201
|
+
scrollToColumn?: (columnName: string) => Promise<void>;
|
|
167
202
|
}
|
|
168
203
|
export interface PaginationPrimitives {
|
|
169
204
|
/** Classic "Next Page" or "Scroll Down" */
|
|
170
205
|
goNext?: (context: TableContext) => Promise<boolean>;
|
|
171
206
|
/** Classic "Previous Page" or "Scroll Up" */
|
|
172
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>;
|
|
173
212
|
/** Jump to first page / scroll to top */
|
|
174
213
|
goToFirst?: (context: TableContext) => Promise<boolean>;
|
|
175
214
|
/** Jump to specific page index (0-indexed) */
|
|
@@ -190,7 +229,7 @@ export type FillStrategy = (options: {
|
|
|
190
229
|
}) => Promise<void>;
|
|
191
230
|
export interface ColumnOverride<TValue = any> {
|
|
192
231
|
/**
|
|
193
|
-
* How to extract the value from the cell.
|
|
232
|
+
* How to extract the value from the cell.
|
|
194
233
|
*/
|
|
195
234
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
196
235
|
/**
|
|
@@ -253,6 +292,12 @@ export interface TableStrategies {
|
|
|
253
292
|
getCellLocator?: GetCellLocatorFn;
|
|
254
293
|
/** Function to get the currently active/focused cell */
|
|
255
294
|
getActiveCell?: GetActiveCellFn;
|
|
295
|
+
/**
|
|
296
|
+
* Hook called before each cell value is read in toJSON and columnOverrides.read.
|
|
297
|
+
* Fires for both the default innerText extraction and custom read mappers.
|
|
298
|
+
* Useful for scrolling off-screen columns into view in horizontally virtualized tables.
|
|
299
|
+
*/
|
|
300
|
+
beforeCellRead?: BeforeCellReadFn;
|
|
256
301
|
/** Custom helper to check if a table is fully loaded/ready */
|
|
257
302
|
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
258
303
|
/** Custom helper to check if a row is fully loaded/ready */
|
|
@@ -293,12 +338,6 @@ export interface TableConfig<T = any> {
|
|
|
293
338
|
onReset?: (context: TableContext) => Promise<void>;
|
|
294
339
|
/** All interaction strategies */
|
|
295
340
|
strategies?: TableStrategies;
|
|
296
|
-
/**
|
|
297
|
-
* @deprecated Use `columnOverrides` instead. `dataMapper` will be removed in v7.0.0.
|
|
298
|
-
* Custom data mappers for specific columns.
|
|
299
|
-
* Allows extracting complex data types (boolean, number) instead of just string.
|
|
300
|
-
*/
|
|
301
|
-
dataMapper?: Partial<Record<keyof T, (cell: Locator) => Promise<T[keyof T]> | T[keyof T]>>;
|
|
302
341
|
/**
|
|
303
342
|
* Unified interface for reading and writing data to specific columns.
|
|
304
343
|
* Overrides both default extraction (toJSON) and filling (smartFill) logic.
|
|
@@ -328,22 +367,6 @@ export interface FillOptions {
|
|
|
328
367
|
*/
|
|
329
368
|
inputMappers?: Record<string, (cell: Locator) => Locator>;
|
|
330
369
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Options for generateConfigPrompt
|
|
333
|
-
*/
|
|
334
|
-
export interface PromptOptions {
|
|
335
|
-
/**
|
|
336
|
-
* Output Strategy:
|
|
337
|
-
* - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).
|
|
338
|
-
* - 'console': Standard console logs (Default).
|
|
339
|
-
*/
|
|
340
|
-
output?: 'console' | 'error';
|
|
341
|
-
/**
|
|
342
|
-
* Include TypeScript type definitions in the prompt
|
|
343
|
-
* @default true
|
|
344
|
-
*/
|
|
345
|
-
includeTypes?: boolean;
|
|
346
|
-
}
|
|
347
370
|
/** Callback context passed to forEach, map, and filter. */
|
|
348
371
|
export type RowIterationContext<T = any> = {
|
|
349
372
|
row: SmartRow<T>;
|
|
@@ -401,9 +424,7 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
401
424
|
* @param index 1-based row index
|
|
402
425
|
* @param options Optional settings including bringIntoView
|
|
403
426
|
*/
|
|
404
|
-
getRowByIndex: (index: number
|
|
405
|
-
bringIntoView?: boolean;
|
|
406
|
-
}) => SmartRow;
|
|
427
|
+
getRowByIndex: (index: number) => SmartRow;
|
|
407
428
|
/**
|
|
408
429
|
* ASYNC: Searches for a single row across pages using pagination.
|
|
409
430
|
* Auto-initializes the table if not already initialized.
|
|
@@ -454,8 +475,22 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
454
475
|
* Execution is parallel within each page by default (safe for reads).
|
|
455
476
|
* Call `stop()` to halt after the current page finishes.
|
|
456
477
|
*
|
|
478
|
+
* > **⚠️ UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,
|
|
479
|
+
* > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent
|
|
480
|
+
* > interactions interfering with each other.
|
|
481
|
+
*
|
|
457
482
|
* @example
|
|
483
|
+
* // Data extraction — parallel is safe
|
|
458
484
|
* const emails = await table.map(({ row }) => row.getCell('Email').innerText());
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* // UI interactions — must use parallel: false
|
|
488
|
+
* const assignees = await table.map(async ({ row }) => {
|
|
489
|
+
* await row.getCell('Assignee').locator('button').click();
|
|
490
|
+
* const name = await page.locator('.popover .name').innerText();
|
|
491
|
+
* await page.keyboard.press('Escape');
|
|
492
|
+
* return name;
|
|
493
|
+
* }, { parallel: false });
|
|
459
494
|
*/
|
|
460
495
|
map<R>(callback: (ctx: RowIterationContext<T>) => R | Promise<R>, options?: RowIterationOptions): Promise<R[]>;
|
|
461
496
|
/**
|
|
@@ -469,15 +504,6 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
469
504
|
* );
|
|
470
505
|
*/
|
|
471
506
|
filter(predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>, options?: RowIterationOptions): Promise<SmartRowArray<T>>;
|
|
472
|
-
/**
|
|
473
|
-
* Scans a specific column across all pages and returns the values.
|
|
474
|
-
* @deprecated Use `table.map(({ row }) => row.getCell(column).innerText())` instead.
|
|
475
|
-
* Will be removed in v7.0.0.
|
|
476
|
-
*/
|
|
477
|
-
getColumnValues: <V = string>(column: string, options?: {
|
|
478
|
-
mapper?: (cell: Locator) => Promise<V> | V;
|
|
479
|
-
maxPages?: number;
|
|
480
|
-
}) => Promise<V[]>;
|
|
481
507
|
/**
|
|
482
508
|
* Provides access to sorting actions and assertions.
|
|
483
509
|
*/
|
|
@@ -495,60 +521,10 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
495
521
|
*/
|
|
496
522
|
getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;
|
|
497
523
|
};
|
|
498
|
-
/**
|
|
499
|
-
* Iterates through paginated table data, calling the callback for each iteration.
|
|
500
|
-
* Callback return values are automatically appended to allData, which is returned.
|
|
501
|
-
* @deprecated Use `forEach`, `map`, or `filter` instead for cleaner cross-page iteration.
|
|
502
|
-
* Only use this for advanced scenarios (batchSize, beforeFirst/afterLast hooks).
|
|
503
|
-
* Will be removed in v7.0.0.
|
|
504
|
-
*/
|
|
505
|
-
iterateThroughTable: <T = any>(callback: (context: {
|
|
506
|
-
index: number;
|
|
507
|
-
isFirst: boolean;
|
|
508
|
-
isLast: boolean;
|
|
509
|
-
rows: SmartRowArray;
|
|
510
|
-
allData: T[];
|
|
511
|
-
table: RestrictedTableResult;
|
|
512
|
-
batchInfo?: {
|
|
513
|
-
startIndex: number;
|
|
514
|
-
endIndex: number;
|
|
515
|
-
size: number;
|
|
516
|
-
};
|
|
517
|
-
}) => T | T[] | Promise<T | T[]>, options?: {
|
|
518
|
-
pagination?: PaginationStrategy;
|
|
519
|
-
dedupeStrategy?: DedupeStrategy;
|
|
520
|
-
maxIterations?: number;
|
|
521
|
-
batchSize?: number;
|
|
522
|
-
getIsFirst?: (context: {
|
|
523
|
-
index: number;
|
|
524
|
-
}) => boolean;
|
|
525
|
-
getIsLast?: (context: {
|
|
526
|
-
index: number;
|
|
527
|
-
paginationResult: boolean;
|
|
528
|
-
}) => boolean;
|
|
529
|
-
beforeFirst?: (context: {
|
|
530
|
-
index: number;
|
|
531
|
-
rows: SmartRowArray;
|
|
532
|
-
allData: any[];
|
|
533
|
-
}) => void | Promise<void>;
|
|
534
|
-
afterLast?: (context: {
|
|
535
|
-
index: number;
|
|
536
|
-
rows: SmartRowArray;
|
|
537
|
-
allData: any[];
|
|
538
|
-
}) => void | Promise<void>;
|
|
539
|
-
/**
|
|
540
|
-
* If true, flattens array results from callback into the main data array.
|
|
541
|
-
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
542
|
-
*/
|
|
543
|
-
autoFlatten?: boolean;
|
|
544
|
-
}) => Promise<T[]>;
|
|
545
524
|
/**
|
|
546
525
|
* Generate an AI-friendly configuration prompt for debugging.
|
|
547
526
|
* Outputs table HTML and TypeScript definitions to help AI assistants generate config.
|
|
527
|
+
* Automatically throws an Error containing the prompt.
|
|
548
528
|
*/
|
|
549
|
-
generateConfigPrompt: (
|
|
529
|
+
generateConfigPrompt: () => Promise<void>;
|
|
550
530
|
}
|
|
551
|
-
/**
|
|
552
|
-
* Restricted table result that excludes methods that shouldn't be called during iteration.
|
|
553
|
-
*/
|
|
554
|
-
export type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;
|