@rickcedwhat/playwright-smart-table 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/engine/rowFinder.d.ts +26 -0
- package/dist/engine/rowFinder.js +161 -0
- package/dist/engine/tableMapper.d.ts +16 -0
- package/dist/engine/tableMapper.js +136 -0
- package/dist/{examples/glide-strategies → strategies/glide}/columns.d.ts +1 -1
- package/dist/{examples/glide-strategies → strategies/glide}/headers.d.ts +1 -1
- package/dist/{src/strategies → strategies}/glide.js +2 -2
- package/dist/strategies/index.d.ts +33 -2
- package/dist/strategies/index.js +6 -0
- package/dist/{src/strategies → strategies}/loading.d.ts +14 -0
- package/dist/{src/strategies → strategies}/loading.js +31 -0
- package/dist/strategies/pagination.d.ts +26 -4
- package/dist/strategies/pagination.js +52 -23
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +32 -7
- package/dist/types.d.ts +37 -5
- package/dist/useTable.d.ts +32 -3
- package/dist/useTable.js +81 -224
- package/dist/utils/stringUtils.js +12 -3
- package/package.json +10 -5
- package/dist/src/filterEngine.d.ts +0 -11
- package/dist/src/filterEngine.js +0 -39
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -18
- package/dist/src/smartRow.d.ts +0 -7
- package/dist/src/smartRow.js +0 -160
- package/dist/src/strategies/columns.d.ts +0 -18
- package/dist/src/strategies/columns.js +0 -21
- package/dist/src/strategies/fill.d.ts +0 -7
- package/dist/src/strategies/fill.js +0 -88
- package/dist/src/strategies/headers.d.ts +0 -13
- package/dist/src/strategies/headers.js +0 -30
- package/dist/src/strategies/index.d.ts +0 -54
- package/dist/src/strategies/index.js +0 -43
- package/dist/src/strategies/pagination.d.ts +0 -33
- package/dist/src/strategies/pagination.js +0 -79
- package/dist/src/strategies/resolution.d.ts +0 -22
- package/dist/src/strategies/resolution.js +0 -30
- package/dist/src/strategies/sorting.d.ts +0 -12
- package/dist/src/strategies/sorting.js +0 -68
- package/dist/src/strategies/validation.d.ts +0 -22
- package/dist/src/strategies/validation.js +0 -54
- package/dist/src/strategies/virtualizedPagination.d.ts +0 -32
- package/dist/src/strategies/virtualizedPagination.js +0 -80
- package/dist/src/typeContext.d.ts +0 -6
- package/dist/src/typeContext.js +0 -465
- package/dist/src/types.d.ts +0 -458
- package/dist/src/types.js +0 -2
- package/dist/src/useTable.d.ts +0 -44
- package/dist/src/useTable.js +0 -641
- package/dist/src/utils/debugUtils.d.ts +0 -17
- package/dist/src/utils/debugUtils.js +0 -62
- package/dist/src/utils/smartRowArray.d.ts +0 -14
- package/dist/src/utils/smartRowArray.js +0 -22
- package/dist/src/utils/stringUtils.d.ts +0 -22
- package/dist/src/utils/stringUtils.js +0 -73
- package/dist/src/utils.d.ts +0 -7
- package/dist/src/utils.js +0 -29
- package/dist/utils/traceUtils.d.ts +0 -11
- package/dist/utils/traceUtils.js +0 -47
- /package/dist/{src/plugins.d.ts → plugins.d.ts} +0 -0
- /package/dist/{src/plugins.js → plugins.js} +0 -0
- /package/dist/{src/strategies → strategies}/dedupe.d.ts +0 -0
- /package/dist/{src/strategies → strategies}/dedupe.js +0 -0
- /package/dist/{examples/glide-strategies → strategies/glide}/columns.js +0 -0
- /package/dist/{examples/glide-strategies → strategies/glide}/headers.js +0 -0
- /package/dist/{src/strategies → strategies}/glide.d.ts +0 -0
- /package/dist/{src/strategies → strategies}/rdg.d.ts +0 -0
- /package/dist/{src/strategies → strategies}/rdg.js +0 -0
- /package/dist/{src/strategies → strategies}/stabilization.d.ts +0 -0
- /package/dist/{src/strategies → strategies}/stabilization.js +0 -0
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);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext {\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 /** 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\nexport interface FinalTableConfig extends TableConfig {\n headerSelector: string;\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 }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n/**\n * Options for generateConfigPrompt\n */\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n /**\n * Include TypeScript type definitions in the prompt\n * @default true\n */\n includeTypes?: boolean;\n}\n\nexport interface TableResult<T = any> {\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, 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 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, string | RegExp | number>,\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, max pages, and asJSON\n */\n findRows: <R extends { asJSON?: boolean }>(\n filters: Record<string, string | RegExp | number>,\n options?: { exact?: boolean, maxPages?: number } & R\n ) => Promise<R['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n /**\n * Gets all rows on the current page only (does not paginate).\n * Auto-initializes the table if not already initialized.\n * Returns a SmartRowArray which extends Array with a toJSON() helper method.\n * @param options - Filter options\n */\n getRows: (options?: { filter?: Record<string, any>, exact?: boolean }) => Promise<SmartRowArray>;\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 batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n }) => T | Promise<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: SmartRow[], allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRow[], allData: any[] }) => void | Promise<void>;\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);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n};\n\nexport type StrategyContext = TableContext & { rowLocator?: Locator; rowIndex?: number };\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext {\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 * 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 /** 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 /** 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/**\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, 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\nexport interface FinalTableConfig extends TableConfig {\n headerSelector: string;\n rowSelector: string;\n cellSelector: string;\n maxPages: number;\n autoScroll: boolean;\n debug?: TableConfig['debug'];\n headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;\n onReset: (context: TableContext) => Promise<void>;\n strategies: TableStrategies;\n}\n\n\nexport interface FillOptions {\n /**\n * Custom input mappers for specific columns.\n * Maps column names to functions that return the input locator for that cell.\n */\n inputMappers?: Record<string, (cell: Locator) => Locator>;\n}\n\n/**\n * Options for generateConfigPrompt\n */\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (useful for platforms that capture error output cleanly).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n /**\n * Include TypeScript type definitions in the prompt\n * @default true\n */\n includeTypes?: boolean;\n}\n\nexport interface TableResult<T = any> {\n /**\n * Initializes the table by resolving headers. Must be called before using sync methods.\n * @param options Optional timeout for header resolution (default: 3000ms)\n */\n init(options?: { timeout?: number }): Promise<TableResult>;\n\n /**\n * SYNC: Checks if the table has been initialized.\n * @returns true if init() has been called and completed, false otherwise\n */\n isInitialized(): boolean;\n\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n /**\n * Finds a row by filters on the current page only. Returns immediately (sync).\n * Throws error if table is not initialized.\n */\n getRow: (\n filters: Record<string, 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 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, string | RegExp | number>,\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, max pages, and asJSON\n */\n findRows: <R extends { asJSON?: boolean }>(\n filters: Record<string, string | RegExp | number>,\n options?: { exact?: boolean, maxPages?: number } & R\n ) => Promise<R['asJSON'] extends true ? Record<string, string>[] : SmartRowArray>;\n\n /**\n * Navigates to a specific column using the configured CellNavigationStrategy.\n */\n scrollToColumn: (columnName: string) => Promise<void>;\n\n /**\n * Gets all rows on the current page only (does not paginate).\n * Auto-initializes the table if not already initialized.\n * Returns a SmartRowArray which extends Array with a toJSON() helper method.\n * @param options - Filter options\n */\n getRows: (options?: { filter?: Record<string, any>, exact?: boolean }) => Promise<SmartRowArray>;\n\n /**\n * Resets the table state (clears cache, flags) and invokes the onReset strategy.\n */\n reset: () => Promise<void>;\n\n /**\n * Revalidates the table's structure (headers, columns) without resetting pagination or state.\n * Useful when columns change visibility or order dynamically.\n */\n revalidate: () => Promise<void>;\n\n /**\n * Scans a specific column across all pages and returns the values.\n */\n getColumnValues: <V = string>(column: string, options?: { mapper?: (cell: Locator) => Promise<V> | V, maxPages?: number }) => Promise<V[]>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Iterates through paginated table data, calling the callback for each iteration.\n * Callback return values are automatically appended to allData, which is returned.\n */\n iterateThroughTable: <T = any>(\n callback: (context: {\n index: number;\n isFirst: boolean;\n isLast: boolean;\n rows: SmartRowArray;\n allData: T[];\n table: RestrictedTableResult;\n batchInfo?: {\n startIndex: number;\n endIndex: number;\n size: number;\n };\n\n }) => T | T[] | Promise<T | T[]>,\n options?: {\n pagination?: PaginationStrategy;\n dedupeStrategy?: DedupeStrategy;\n maxIterations?: number;\n batchSize?: number;\n getIsFirst?: (context: { index: number }) => boolean;\n getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;\n beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;\n /**\n * If true, flattens array results from callback into the main data array.\n * If false (default), pushes the return value as-is (preserves batching/arrays).\n */\n autoFlatten?: boolean;\n }\n ) => Promise<T[]>;\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n */\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n}\n\n/**\n * Restricted table result that excludes methods that shouldn't be called during iteration.\n */\nexport type RestrictedTableResult<T = any> = Omit<TableResult<T>, 'searchForRow' | 'iterateThroughTable' | 'reset'>;\n";
|
package/dist/typeContext.js
CHANGED
|
@@ -210,6 +210,15 @@ export interface FilterStrategy {
|
|
|
210
210
|
}): Locator;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Strategy to check if the table or rows are loading.
|
|
215
|
+
*/
|
|
216
|
+
export interface LoadingStrategy {
|
|
217
|
+
isTableLoading?: (context: TableContext) => Promise<boolean>;
|
|
218
|
+
isRowLoading?: (row: SmartRow) => Promise<boolean>;
|
|
219
|
+
isHeaderLoading?: (context: TableContext) => Promise<boolean>;
|
|
220
|
+
}
|
|
221
|
+
|
|
213
222
|
/**
|
|
214
223
|
* Organized container for all table interaction strategies.
|
|
215
224
|
*/
|
|
@@ -224,10 +233,20 @@ export interface TableStrategies {
|
|
|
224
233
|
pagination?: PaginationStrategy;
|
|
225
234
|
/** Strategy for sorting columns */
|
|
226
235
|
sorting?: SortingStrategy;
|
|
236
|
+
/** Strategy for deduplicating rows during iteration/scrolling */
|
|
237
|
+
dedupe?: DedupeStrategy;
|
|
227
238
|
/** Function to get a cell locator */
|
|
228
239
|
getCellLocator?: GetCellLocatorFn;
|
|
229
240
|
/** Function to get the currently active/focused cell */
|
|
230
241
|
getActiveCell?: GetActiveCellFn;
|
|
242
|
+
/** Custom helper to check if a table is fully loaded/ready */
|
|
243
|
+
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
244
|
+
/** Custom helper to check if a row is fully loaded/ready */
|
|
245
|
+
isRowLoaded?: (args: { row: Locator, index: number }) => Promise<boolean>;
|
|
246
|
+
/** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */
|
|
247
|
+
isCellLoaded?: (args: { cell: Locator, column: string, row: Locator }) => Promise<boolean>;
|
|
248
|
+
/** Strategy for detecting loading states */
|
|
249
|
+
loading?: LoadingStrategy;
|
|
231
250
|
}
|
|
232
251
|
|
|
233
252
|
/**
|
|
@@ -243,7 +262,7 @@ export interface TableConfig {
|
|
|
243
262
|
/** Number of pages to scan for verification */
|
|
244
263
|
maxPages?: number;
|
|
245
264
|
/** Hook to rename columns dynamically */
|
|
246
|
-
headerTransformer?: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;
|
|
265
|
+
headerTransformer?: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;
|
|
247
266
|
/** Automatically scroll to table on init */
|
|
248
267
|
autoScroll?: boolean;
|
|
249
268
|
/** Debug options for development and troubleshooting */
|
|
@@ -261,7 +280,7 @@ export interface FinalTableConfig extends TableConfig {
|
|
|
261
280
|
maxPages: number;
|
|
262
281
|
autoScroll: boolean;
|
|
263
282
|
debug?: TableConfig['debug'];
|
|
264
|
-
headerTransformer: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;
|
|
283
|
+
headerTransformer: (args: { text: string, index: number, locator: Locator, seenHeaders: Set<string> }) => string | Promise<string>;
|
|
265
284
|
onReset: (context: TableContext) => Promise<void>;
|
|
266
285
|
strategies: TableStrategies;
|
|
267
286
|
}
|
|
@@ -348,7 +367,7 @@ export interface TableResult<T = any> {
|
|
|
348
367
|
findRows: <R extends { asJSON?: boolean }>(
|
|
349
368
|
filters: Record<string, string | RegExp | number>,
|
|
350
369
|
options?: { exact?: boolean, maxPages?: number } & R
|
|
351
|
-
) => Promise<R['asJSON'] extends true ? Record<string, string>[] :
|
|
370
|
+
) => Promise<R['asJSON'] extends true ? Record<string, string>[] : SmartRowArray>;
|
|
352
371
|
|
|
353
372
|
/**
|
|
354
373
|
* Navigates to a specific column using the configured CellNavigationStrategy.
|
|
@@ -406,7 +425,7 @@ export interface TableResult<T = any> {
|
|
|
406
425
|
index: number;
|
|
407
426
|
isFirst: boolean;
|
|
408
427
|
isLast: boolean;
|
|
409
|
-
rows:
|
|
428
|
+
rows: SmartRowArray;
|
|
410
429
|
allData: T[];
|
|
411
430
|
table: RestrictedTableResult;
|
|
412
431
|
batchInfo?: {
|
|
@@ -414,7 +433,8 @@ export interface TableResult<T = any> {
|
|
|
414
433
|
endIndex: number;
|
|
415
434
|
size: number;
|
|
416
435
|
};
|
|
417
|
-
|
|
436
|
+
|
|
437
|
+
}) => T | T[] | Promise<T | T[]>,
|
|
418
438
|
options?: {
|
|
419
439
|
pagination?: PaginationStrategy;
|
|
420
440
|
dedupeStrategy?: DedupeStrategy;
|
|
@@ -422,8 +442,13 @@ export interface TableResult<T = any> {
|
|
|
422
442
|
batchSize?: number;
|
|
423
443
|
getIsFirst?: (context: { index: number }) => boolean;
|
|
424
444
|
getIsLast?: (context: { index: number, paginationResult: boolean }) => boolean;
|
|
425
|
-
beforeFirst?: (context: { index: number, rows:
|
|
426
|
-
afterLast?: (context: { index: number, rows:
|
|
445
|
+
beforeFirst?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
446
|
+
afterLast?: (context: { index: number, rows: SmartRowArray, allData: any[] }) => void | Promise<void>;
|
|
447
|
+
/**
|
|
448
|
+
* If true, flattens array results from callback into the main data array.
|
|
449
|
+
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
450
|
+
*/
|
|
451
|
+
autoFlatten?: boolean;
|
|
427
452
|
}
|
|
428
453
|
) => Promise<T[]>;
|
|
429
454
|
|
package/dist/types.d.ts
CHANGED
|
@@ -192,6 +192,14 @@ export interface FilterStrategy {
|
|
|
192
192
|
tableContext: TableContext;
|
|
193
193
|
}): Locator;
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Strategy to check if the table or rows are loading.
|
|
197
|
+
*/
|
|
198
|
+
export interface LoadingStrategy {
|
|
199
|
+
isTableLoading?: (context: TableContext) => Promise<boolean>;
|
|
200
|
+
isRowLoading?: (row: SmartRow) => Promise<boolean>;
|
|
201
|
+
isHeaderLoading?: (context: TableContext) => Promise<boolean>;
|
|
202
|
+
}
|
|
195
203
|
/**
|
|
196
204
|
* Organized container for all table interaction strategies.
|
|
197
205
|
*/
|
|
@@ -206,10 +214,27 @@ export interface TableStrategies {
|
|
|
206
214
|
pagination?: PaginationStrategy;
|
|
207
215
|
/** Strategy for sorting columns */
|
|
208
216
|
sorting?: SortingStrategy;
|
|
217
|
+
/** Strategy for deduplicating rows during iteration/scrolling */
|
|
218
|
+
dedupe?: DedupeStrategy;
|
|
209
219
|
/** Function to get a cell locator */
|
|
210
220
|
getCellLocator?: GetCellLocatorFn;
|
|
211
221
|
/** Function to get the currently active/focused cell */
|
|
212
222
|
getActiveCell?: GetActiveCellFn;
|
|
223
|
+
/** Custom helper to check if a table is fully loaded/ready */
|
|
224
|
+
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
225
|
+
/** Custom helper to check if a row is fully loaded/ready */
|
|
226
|
+
isRowLoaded?: (args: {
|
|
227
|
+
row: Locator;
|
|
228
|
+
index: number;
|
|
229
|
+
}) => Promise<boolean>;
|
|
230
|
+
/** Custom helper to check if a cell is fully loaded/ready (e.g. for editing) */
|
|
231
|
+
isCellLoaded?: (args: {
|
|
232
|
+
cell: Locator;
|
|
233
|
+
column: string;
|
|
234
|
+
row: Locator;
|
|
235
|
+
}) => Promise<boolean>;
|
|
236
|
+
/** Strategy for detecting loading states */
|
|
237
|
+
loading?: LoadingStrategy;
|
|
213
238
|
}
|
|
214
239
|
/**
|
|
215
240
|
* Configuration options for useTable.
|
|
@@ -228,6 +253,7 @@ export interface TableConfig {
|
|
|
228
253
|
text: string;
|
|
229
254
|
index: number;
|
|
230
255
|
locator: Locator;
|
|
256
|
+
seenHeaders: Set<string>;
|
|
231
257
|
}) => string | Promise<string>;
|
|
232
258
|
/** Automatically scroll to table on init */
|
|
233
259
|
autoScroll?: boolean;
|
|
@@ -249,6 +275,7 @@ export interface FinalTableConfig extends TableConfig {
|
|
|
249
275
|
text: string;
|
|
250
276
|
index: number;
|
|
251
277
|
locator: Locator;
|
|
278
|
+
seenHeaders: Set<string>;
|
|
252
279
|
}) => string | Promise<string>;
|
|
253
280
|
onReset: (context: TableContext) => Promise<void>;
|
|
254
281
|
strategies: TableStrategies;
|
|
@@ -328,7 +355,7 @@ export interface TableResult<T = any> {
|
|
|
328
355
|
}>(filters: Record<string, string | RegExp | number>, options?: {
|
|
329
356
|
exact?: boolean;
|
|
330
357
|
maxPages?: number;
|
|
331
|
-
} & R) => Promise<R['asJSON'] extends true ? Record<string, string>[] :
|
|
358
|
+
} & R) => Promise<R['asJSON'] extends true ? Record<string, string>[] : SmartRowArray>;
|
|
332
359
|
/**
|
|
333
360
|
* Navigates to a specific column using the configured CellNavigationStrategy.
|
|
334
361
|
*/
|
|
@@ -384,7 +411,7 @@ export interface TableResult<T = any> {
|
|
|
384
411
|
index: number;
|
|
385
412
|
isFirst: boolean;
|
|
386
413
|
isLast: boolean;
|
|
387
|
-
rows:
|
|
414
|
+
rows: SmartRowArray;
|
|
388
415
|
allData: T[];
|
|
389
416
|
table: RestrictedTableResult;
|
|
390
417
|
batchInfo?: {
|
|
@@ -392,7 +419,7 @@ export interface TableResult<T = any> {
|
|
|
392
419
|
endIndex: number;
|
|
393
420
|
size: number;
|
|
394
421
|
};
|
|
395
|
-
}) => T | Promise<T>, options?: {
|
|
422
|
+
}) => T | T[] | Promise<T | T[]>, options?: {
|
|
396
423
|
pagination?: PaginationStrategy;
|
|
397
424
|
dedupeStrategy?: DedupeStrategy;
|
|
398
425
|
maxIterations?: number;
|
|
@@ -406,14 +433,19 @@ export interface TableResult<T = any> {
|
|
|
406
433
|
}) => boolean;
|
|
407
434
|
beforeFirst?: (context: {
|
|
408
435
|
index: number;
|
|
409
|
-
rows:
|
|
436
|
+
rows: SmartRowArray;
|
|
410
437
|
allData: any[];
|
|
411
438
|
}) => void | Promise<void>;
|
|
412
439
|
afterLast?: (context: {
|
|
413
440
|
index: number;
|
|
414
|
-
rows:
|
|
441
|
+
rows: SmartRowArray;
|
|
415
442
|
allData: any[];
|
|
416
443
|
}) => void | Promise<void>;
|
|
444
|
+
/**
|
|
445
|
+
* If true, flattens array results from callback into the main data array.
|
|
446
|
+
* If false (default), pushes the return value as-is (preserves batching/arrays).
|
|
447
|
+
*/
|
|
448
|
+
autoFlatten?: boolean;
|
|
417
449
|
}) => Promise<T[]>;
|
|
418
450
|
/**
|
|
419
451
|
* Generate an AI-friendly configuration prompt for debugging.
|
package/dist/useTable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Locator } from '@playwright/test';
|
|
2
|
-
import { TableConfig, Selector, TableResult, PaginationStrategy } from './types';
|
|
2
|
+
import { TableConfig, TableContext, Selector, TableResult, SmartRow as SmartRowType, DedupeStrategy, PaginationStrategy } from './types';
|
|
3
3
|
import { FillStrategies } from './strategies/fill';
|
|
4
4
|
import { HeaderStrategies } from './strategies/headers';
|
|
5
5
|
import { CellNavigationStrategies } from './strategies/columns';
|
|
@@ -10,10 +10,39 @@ import { Strategies } from './strategies';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const useTable: <T = any>(rootLocator: Locator, configOptions?: TableConfig) => TableResult<T>;
|
|
12
12
|
export declare const PaginationStrategies: {
|
|
13
|
-
clickNext: (nextButtonSelector: Selector,
|
|
14
|
-
|
|
13
|
+
clickNext: (nextButtonSelector: Selector, options?: {
|
|
14
|
+
stabilization?: import("./strategies/stabilization").StabilizationStrategy;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}) => PaginationStrategy;
|
|
17
|
+
infiniteScroll: (options?: {
|
|
18
|
+
action?: "scroll" | "js-scroll";
|
|
19
|
+
scrollTarget?: Selector;
|
|
20
|
+
scrollAmount?: number;
|
|
21
|
+
stabilization?: import("./strategies/stabilization").StabilizationStrategy;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
}) => PaginationStrategy;
|
|
24
|
+
};
|
|
25
|
+
export declare const LoadingStrategies: {
|
|
26
|
+
Table: {
|
|
27
|
+
hasSpinner: (selector?: string) => ({ root }: TableContext) => Promise<boolean>;
|
|
28
|
+
custom: (fn: (context: TableContext) => Promise<boolean>) => (context: TableContext) => Promise<boolean>;
|
|
29
|
+
never: () => Promise<boolean>;
|
|
30
|
+
};
|
|
31
|
+
Row: {
|
|
32
|
+
hasClass: (className?: string) => (row: SmartRowType) => Promise<boolean>;
|
|
33
|
+
hasText: (text?: string | RegExp) => (row: SmartRowType) => Promise<boolean>;
|
|
34
|
+
hasEmptyCells: () => (row: SmartRowType) => Promise<boolean>;
|
|
35
|
+
never: () => Promise<boolean>;
|
|
36
|
+
};
|
|
37
|
+
Headers: {
|
|
38
|
+
stable: (duration?: number) => (context: TableContext) => Promise<boolean>;
|
|
39
|
+
never: () => Promise<boolean>;
|
|
40
|
+
};
|
|
15
41
|
};
|
|
16
42
|
export declare const SortingStrategies: {
|
|
17
43
|
AriaSort: () => import("./types").SortingStrategy;
|
|
18
44
|
};
|
|
45
|
+
export declare const DedupeStrategies: {
|
|
46
|
+
byTopPosition: (tolerance?: number) => DedupeStrategy;
|
|
47
|
+
};
|
|
19
48
|
export { FillStrategies, HeaderStrategies, CellNavigationStrategies, ResolutionStrategies, Strategies };
|