@rickcedwhat/playwright-smart-table 2.0.9 → 2.1.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/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +7 -1
- package/dist/types.d.ts +11 -1
- package/dist/useTable.js +14 -5
- 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 = "\nexport type Selector = string | ((root: Locator | Page) => Locator);\n\nexport type SmartRow = Locator & {\n getCell(column: string): Locator;\n toJSON(): Promise<Record<string, string>>;\n};\n\nexport interface TableContext {\n root: Locator;\n config: Required<TableConfig>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n}\n\nexport type PaginationStrategy = (context: TableContext) => Promise<boolean>;\n\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (Best for Cloud/QA Wolf to get clean text).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n includeTypes?: boolean;\n}\n\nexport interface TableConfig {\n rowSelector?: Selector;\n headerSelector?: Selector;\n cellSelector?: Selector;\n pagination?: PaginationStrategy;\n maxPages?: number;\n headerTransformer?: (text: string, index: number) => string
|
|
6
|
+
export declare const TYPE_CONTEXT = "\nexport type Selector = string | ((root: Locator | Page) => Locator);\n\nexport type SmartRow = Locator & {\n getCell(column: string): Locator;\n toJSON(): Promise<Record<string, string>>;\n};\n\nexport interface TableContext {\n root: Locator;\n config: Required<TableConfig>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n}\n\nexport type PaginationStrategy = (context: TableContext) => Promise<boolean>;\n\nexport interface PromptOptions {\n /**\n * Output Strategy:\n * - 'error': Throws an error with the prompt (Best for Cloud/QA Wolf to get clean text).\n * - 'console': Standard console logs (Default).\n */\n output?: 'console' | 'error';\n includeTypes?: boolean;\n}\n\nexport interface TableConfig {\n rowSelector?: Selector;\n headerSelector?: Selector;\n cellSelector?: Selector;\n pagination?: PaginationStrategy;\n maxPages?: number;\n /**\n * Hook to rename columns dynamically.\n * * @param args.text - The default innerText of the header.\n * @param args.index - The column index.\n * @param args.locator - The specific header cell locator.\n */\n headerTransformer?: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;\n autoScroll?: boolean;\n}\n\nexport interface TableResult {\n getHeaders: () => Promise<string[]>;\n getHeaderCell: (columnName: string) => Promise<Locator>;\n\n getByRow: <T extends { asJSON?: boolean }>(\n filters: Record<string, string | RegExp | number>, \n options?: { exact?: boolean, maxPages?: number } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string> : SmartRow>;\n\n getAllRows: <T extends { asJSON?: boolean }>(\n options?: { filter?: Record<string, any>, exact?: boolean } & T\n ) => Promise<T['asJSON'] extends true ? Record<string, string>[] : SmartRow[]>;\n\n generateConfigPrompt: (options?: PromptOptions) => Promise<void>;\n generateStrategyPrompt: (options?: PromptOptions) => Promise<void>;\n}\n";
|
package/dist/typeContext.js
CHANGED
|
@@ -39,7 +39,13 @@ export interface TableConfig {
|
|
|
39
39
|
cellSelector?: Selector;
|
|
40
40
|
pagination?: PaginationStrategy;
|
|
41
41
|
maxPages?: number;
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Hook to rename columns dynamically.
|
|
44
|
+
* * @param args.text - The default innerText of the header.
|
|
45
|
+
* @param args.index - The column index.
|
|
46
|
+
* @param args.locator - The specific header cell locator.
|
|
47
|
+
*/
|
|
48
|
+
headerTransformer?: (args: { text: string, index: number, locator: Locator }) => string | Promise<string>;
|
|
43
49
|
autoScroll?: boolean;
|
|
44
50
|
}
|
|
45
51
|
|
package/dist/types.d.ts
CHANGED
|
@@ -26,7 +26,17 @@ export interface TableConfig {
|
|
|
26
26
|
cellSelector?: Selector;
|
|
27
27
|
pagination?: PaginationStrategy;
|
|
28
28
|
maxPages?: number;
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Hook to rename columns dynamically.
|
|
31
|
+
* * @param args.text - The default innerText of the header.
|
|
32
|
+
* @param args.index - The column index.
|
|
33
|
+
* @param args.locator - The specific header cell locator.
|
|
34
|
+
*/
|
|
35
|
+
headerTransformer?: (args: {
|
|
36
|
+
text: string;
|
|
37
|
+
index: number;
|
|
38
|
+
locator: Locator;
|
|
39
|
+
}) => string | Promise<string>;
|
|
30
40
|
autoScroll?: boolean;
|
|
31
41
|
}
|
|
32
42
|
export interface TableResult {
|
package/dist/useTable.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.useTable = void 0;
|
|
13
13
|
const typeContext_1 = require("./typeContext");
|
|
14
14
|
const useTable = (rootLocator, configOptions = {}) => {
|
|
15
|
-
const config = Object.assign({ rowSelector: "tbody tr", headerSelector: "th", cellSelector: "td", pagination: () => __awaiter(void 0, void 0, void 0, function* () { return false; }), maxPages: 1, headerTransformer: (text) => text, autoScroll: true }, configOptions);
|
|
15
|
+
const config = Object.assign({ rowSelector: "tbody tr", headerSelector: "th", cellSelector: "td", pagination: () => __awaiter(void 0, void 0, void 0, function* () { return false; }), maxPages: 1, headerTransformer: ({ text, index, locator }) => text, autoScroll: true }, configOptions);
|
|
16
16
|
const resolve = (item, parent) => {
|
|
17
17
|
if (typeof item === 'string')
|
|
18
18
|
return parent.locator(item);
|
|
@@ -35,13 +35,22 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
35
35
|
yield headerLoc.first().waitFor({ state: 'visible', timeout: 3000 });
|
|
36
36
|
}
|
|
37
37
|
catch (e) { /* Ignore hydration */ }
|
|
38
|
+
// 1. Fetch data efficiently
|
|
38
39
|
const texts = yield headerLoc.allInnerTexts();
|
|
39
|
-
|
|
40
|
+
const locators = yield headerLoc.all(); // Need specific locators for the transformer
|
|
41
|
+
// 2. Map Headers (Async)
|
|
42
|
+
const entries = yield Promise.all(texts.map((t, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
43
|
let text = t.trim() || `__col_${i}`;
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
if (config.headerTransformer) {
|
|
45
|
+
text = yield config.headerTransformer({
|
|
46
|
+
text,
|
|
47
|
+
index: i,
|
|
48
|
+
locator: locators[i]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
43
51
|
return [text, i];
|
|
44
|
-
}));
|
|
52
|
+
})));
|
|
53
|
+
_headerMap = new Map(entries);
|
|
45
54
|
return _headerMap;
|
|
46
55
|
});
|
|
47
56
|
const _makeSmart = (rowLocator, map) => {
|
package/package.json
CHANGED