@rickcedwhat/playwright-smart-table 6.7.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 +26 -0
- 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 +1 -1
- package/dist/plugins.d.ts +0 -1
- package/dist/smartRow.js +56 -22
- package/dist/strategies/index.d.ts +4 -4
- package/dist/strategies/rdg.d.ts +0 -5
- package/dist/strategies/rdg.js +1 -18
- package/dist/strategies/sorting.js +4 -9
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +45 -5
- package/dist/types.d.ts +43 -6
- package/dist/useTable.js +36 -57
- package/dist/utils/elementTracker.d.ts +15 -0
- package/dist/utils/elementTracker.js +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,32 @@ const expensive = await table.filter(async ({ row }) => {
|
|
|
128
128
|
});
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
### Advanced: `columnOverrides`
|
|
132
|
+
|
|
133
|
+
For complex DOM structures, custom data extraction, or specialized input widgets, use `columnOverrides` to intercept how Smart Table interacts with specific columns:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const table = useTable(page.locator('#table'), {
|
|
137
|
+
columnOverrides: {
|
|
138
|
+
// Override how data is read from the 'Status' column (e.g., for .toJSON())
|
|
139
|
+
Status: {
|
|
140
|
+
read: async (cell) => {
|
|
141
|
+
const isChecked = await cell.locator('input[type="checkbox"]').isChecked();
|
|
142
|
+
return isChecked ? 'Active' : 'Inactive';
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// Override how data is written to the 'Tags' column (for .smartFill())
|
|
146
|
+
Tags: {
|
|
147
|
+
write: async (cell, value) => {
|
|
148
|
+
await cell.click();
|
|
149
|
+
await page.keyboard.type(value);
|
|
150
|
+
await page.keyboard.press('Enter');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
131
157
|
## Key Features
|
|
132
158
|
|
|
133
159
|
- 🎯 **Smart Locators** - Find rows by content, not position
|
|
@@ -19,10 +19,7 @@ export declare class RowFinder<T = any> {
|
|
|
19
19
|
exact?: boolean;
|
|
20
20
|
maxPages?: number;
|
|
21
21
|
}): Promise<SmartRow<T>>;
|
|
22
|
-
findRows(
|
|
23
|
-
exact?: boolean;
|
|
24
|
-
maxPages?: number;
|
|
25
|
-
}), legacyOptions?: {
|
|
22
|
+
findRows(filters?: Partial<T> | Record<string, FilterValue>, options?: {
|
|
26
23
|
exact?: boolean;
|
|
27
24
|
maxPages?: number;
|
|
28
25
|
}): Promise<SmartRowArray<T>>;
|
package/dist/engine/rowFinder.js
CHANGED
|
@@ -8,17 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
12
|
exports.RowFinder = void 0;
|
|
24
13
|
const debugUtils_1 = require("../utils/debugUtils");
|
|
@@ -51,46 +40,26 @@ class RowFinder {
|
|
|
51
40
|
yield (0, debugUtils_1.debugDelay)(this.config, 'findRow');
|
|
52
41
|
const sentinel = this.resolve(this.config.rowSelector, this.rootLocator)
|
|
53
42
|
.filter({ hasText: "___SENTINEL_ROW_NOT_FOUND___" + Date.now() });
|
|
54
|
-
|
|
43
|
+
const smartRow = this.makeSmartRow(sentinel, yield this.tableMapper.getMap(), 0);
|
|
44
|
+
smartRow._isSentinel = true;
|
|
45
|
+
return smartRow;
|
|
55
46
|
});
|
|
56
47
|
}
|
|
57
|
-
findRows(
|
|
58
|
-
// Deprecated: verify legacy usage pattern support
|
|
59
|
-
legacyOptions) {
|
|
48
|
+
findRows(filters, options) {
|
|
60
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
// Detect argument pattern:
|
|
62
|
-
// Pattern A: findRows({ Name: 'Alice' }, { maxPages: 5 })
|
|
63
|
-
// Pattern B: findRows({ maxPages: 5 }) <-- No filters, just options
|
|
64
|
-
// Pattern C: findRows({ Name: 'Alice' }) <-- Only filters
|
|
65
50
|
var _a, _b;
|
|
66
|
-
|
|
67
|
-
let options = {};
|
|
68
|
-
if (legacyOptions) {
|
|
69
|
-
// Pattern A
|
|
70
|
-
filters = filtersOrOptions;
|
|
71
|
-
options = legacyOptions;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Pattern B or C
|
|
75
|
-
// We need to separate unknown keys (filters) from known options (exact, maxPages)
|
|
76
|
-
// However, filtersOrOptions can be null/undefined
|
|
77
|
-
if (filtersOrOptions) {
|
|
78
|
-
const _c = filtersOrOptions, { exact, maxPages } = _c, rest = __rest(_c, ["exact", "maxPages"]);
|
|
79
|
-
options = { exact, maxPages };
|
|
80
|
-
filters = rest;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
51
|
+
const filtersRecord = filters || {};
|
|
83
52
|
const map = yield this.tableMapper.getMap();
|
|
84
53
|
const allRows = [];
|
|
85
|
-
const effectiveMaxPages = (_b = (_a = options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages) !== null && _b !== void 0 ? _b : Infinity;
|
|
54
|
+
const effectiveMaxPages = (_b = (_a = options === null || options === void 0 ? void 0 : options.maxPages) !== null && _a !== void 0 ? _a : this.config.maxPages) !== null && _b !== void 0 ? _b : Infinity;
|
|
86
55
|
let pagesScanned = 1;
|
|
87
56
|
const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
|
|
88
57
|
var _a, _b;
|
|
89
58
|
// ... logic ...
|
|
90
59
|
let rowLocators = this.resolve(this.config.rowSelector, this.rootLocator);
|
|
91
60
|
// Only apply filters if we have them
|
|
92
|
-
if (Object.keys(
|
|
93
|
-
rowLocators = this.filterEngine.applyFilters(rowLocators,
|
|
61
|
+
if (Object.keys(filtersRecord).length > 0) {
|
|
62
|
+
rowLocators = this.filterEngine.applyFilters(rowLocators, filtersRecord, map, (_a = options === null || options === void 0 ? void 0 : options.exact) !== null && _a !== void 0 ? _a : false, this.rootLocator.page());
|
|
94
63
|
}
|
|
95
64
|
const currentRows = yield rowLocators.all();
|
|
96
65
|
const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
|
|
@@ -125,7 +94,7 @@ class RowFinder {
|
|
|
125
94
|
}
|
|
126
95
|
paginationResult = yield this.config.strategies.pagination.goNext(context);
|
|
127
96
|
}
|
|
128
|
-
const didPaginate =
|
|
97
|
+
const didPaginate = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
|
|
129
98
|
if (!didPaginate)
|
|
130
99
|
break;
|
|
131
100
|
this.tableState.currentPageIndex++;
|
|
@@ -105,7 +105,7 @@ class TableMapper {
|
|
|
105
105
|
text = yield this.config.headerTransformer({
|
|
106
106
|
text,
|
|
107
107
|
index: i,
|
|
108
|
-
locator: this.
|
|
108
|
+
locator: this.resolve(this.config.headerSelector, this.rootLocator).nth(i),
|
|
109
109
|
seenHeaders
|
|
110
110
|
});
|
|
111
111
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { useTable } from './useTable';
|
|
2
|
-
export type { TableConfig, TableResult, SmartRow, Selector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, } from './types';
|
|
2
|
+
export type { TableConfig, TableResult, SmartRow, Selector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, TableContext, StrategyContext, BeforeCellReadFn, GetCellLocatorFn, GetActiveCellFn, } from './types';
|
|
3
3
|
export { Strategies } from './strategies';
|
|
4
4
|
export { Plugins } from './plugins';
|
package/dist/plugins.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare const Plugins: {
|
|
|
3
3
|
Strategies: {
|
|
4
4
|
header: (context: import("./types").TableContext) => Promise<string[]>;
|
|
5
5
|
getCellLocator: ({ row, columnIndex }: any) => any;
|
|
6
|
-
cellNavigation: ({ root, page, index }: any) => Promise<void>;
|
|
7
6
|
navigation: {
|
|
8
7
|
goRight: ({ root, page }: any) => Promise<void>;
|
|
9
8
|
goLeft: ({ root, page }: any) => Promise<void>;
|
package/dist/smartRow.js
CHANGED
|
@@ -16,7 +16,6 @@ const debugUtils_1 = require("./utils/debugUtils");
|
|
|
16
16
|
/**
|
|
17
17
|
* Internal helper to navigate to a cell with active cell optimization.
|
|
18
18
|
* Uses navigation primitives (goUp, goDown, goLeft, goRight, goHome) for orchestration.
|
|
19
|
-
* Falls back to cellNavigation for backward compatibility.
|
|
20
19
|
* Returns the target cell locator after navigation.
|
|
21
20
|
*/
|
|
22
21
|
const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -91,7 +90,6 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
91
90
|
}
|
|
92
91
|
return null;
|
|
93
92
|
}
|
|
94
|
-
;
|
|
95
93
|
return null;
|
|
96
94
|
});
|
|
97
95
|
/**
|
|
@@ -121,10 +119,23 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
121
119
|
}
|
|
122
120
|
return resolve(config.cellSelector, rowLocator).nth(idx);
|
|
123
121
|
};
|
|
122
|
+
smart.wasFound = () => {
|
|
123
|
+
return !smart._isSentinel;
|
|
124
|
+
};
|
|
124
125
|
smart.toJSON = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
126
|
var _a;
|
|
126
127
|
const result = {};
|
|
127
128
|
const page = rootLocator.page();
|
|
129
|
+
// Build a getHeaderCell helper for the beforeCellRead context.
|
|
130
|
+
// Uses the table reference if available, otherwise falls back to index-based lookup.
|
|
131
|
+
const getHeaderCell = (table === null || table === void 0 ? void 0 : table.getHeaderCell)
|
|
132
|
+
? table.getHeaderCell.bind(table)
|
|
133
|
+
: (colName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
const idx = map.get(colName);
|
|
135
|
+
if (idx === undefined)
|
|
136
|
+
throw new Error(`Column "${colName}" not found`);
|
|
137
|
+
return resolve(config.headerSelector, rootLocator).nth(idx);
|
|
138
|
+
});
|
|
128
139
|
for (const [col, idx] of map.entries()) {
|
|
129
140
|
if ((options === null || options === void 0 ? void 0 : options.columns) && !options.columns.includes(col)) {
|
|
130
141
|
continue;
|
|
@@ -132,13 +143,6 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
132
143
|
// Check if we have a column override for this column
|
|
133
144
|
const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[col];
|
|
134
145
|
const mapper = columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.read;
|
|
135
|
-
if (mapper) {
|
|
136
|
-
// Use custom mapper
|
|
137
|
-
// Ensure we have the cell first (same navigation logic)
|
|
138
|
-
// ... wait, the navigation logic below assumes we need to navigate.
|
|
139
|
-
// If we have a mapper, we still need the cell locator.
|
|
140
|
-
// Let's reuse the navigation logic to get targetCell
|
|
141
|
-
}
|
|
142
146
|
// --- Navigation Logic Start ---
|
|
143
147
|
const cell = config.strategies.getCellLocator
|
|
144
148
|
? config.strategies.getCellLocator({
|
|
@@ -168,6 +172,19 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
// --- Navigation Logic End ---
|
|
175
|
+
// Call beforeCellRead hook if configured.
|
|
176
|
+
// Fires for BOTH columnOverrides.read and the default innerText path.
|
|
177
|
+
if (config.strategies.beforeCellRead) {
|
|
178
|
+
yield config.strategies.beforeCellRead({
|
|
179
|
+
cell: targetCell,
|
|
180
|
+
columnName: col,
|
|
181
|
+
columnIndex: idx,
|
|
182
|
+
row: rowLocator,
|
|
183
|
+
page,
|
|
184
|
+
root: rootLocator,
|
|
185
|
+
getHeaderCell,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
171
188
|
if (mapper) {
|
|
172
189
|
// Apply mapper
|
|
173
190
|
const mappedValue = yield mapper(targetCell);
|
|
@@ -182,6 +199,7 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
182
199
|
return result;
|
|
183
200
|
});
|
|
184
201
|
smart.smartFill = (data, fillOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
|
+
var _a;
|
|
185
203
|
(0, debugUtils_1.logDebug)(config, 'info', 'Filling row', data);
|
|
186
204
|
for (const [colName, value] of Object.entries(data)) {
|
|
187
205
|
if (value === undefined)
|
|
@@ -200,19 +218,35 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
200
218
|
rowLocator,
|
|
201
219
|
rowIndex
|
|
202
220
|
});
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
221
|
+
const columnOverride = (_a = config.columnOverrides) === null || _a === void 0 ? void 0 : _a[colName];
|
|
222
|
+
if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
|
|
223
|
+
const cellLocator = smart.getCell(colName);
|
|
224
|
+
let currentValue;
|
|
225
|
+
if (columnOverride.read) {
|
|
226
|
+
currentValue = yield columnOverride.read(cellLocator);
|
|
227
|
+
}
|
|
228
|
+
yield columnOverride.write({
|
|
229
|
+
cell: cellLocator,
|
|
230
|
+
targetValue: value,
|
|
231
|
+
currentValue,
|
|
232
|
+
row: smart
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
const strategy = config.strategies.fill || fill_1.FillStrategies.default;
|
|
237
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', `Filling cell "${colName}" with value`, value);
|
|
238
|
+
yield strategy({
|
|
239
|
+
row: smart,
|
|
240
|
+
columnName: colName,
|
|
241
|
+
value,
|
|
242
|
+
index: rowIndex !== null && rowIndex !== void 0 ? rowIndex : -1,
|
|
243
|
+
page: rowLocator.page(),
|
|
244
|
+
rootLocator,
|
|
245
|
+
config,
|
|
246
|
+
table: table,
|
|
247
|
+
fillOptions
|
|
248
|
+
});
|
|
249
|
+
}
|
|
216
250
|
// Delay after filling
|
|
217
251
|
yield (0, debugUtils_1.debugDelay)(config, 'getCell');
|
|
218
252
|
}
|
|
@@ -33,7 +33,7 @@ export declare const Strategies: {
|
|
|
33
33
|
default: () => Promise<void>;
|
|
34
34
|
};
|
|
35
35
|
Header: {
|
|
36
|
-
visible: ({ config, resolve, root }: import("
|
|
36
|
+
visible: ({ config, resolve, root }: import("..").StrategyContext) => Promise<string[]>;
|
|
37
37
|
};
|
|
38
38
|
Fill: {
|
|
39
39
|
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("../types").FillStrategy>[0]) => Promise<void>;
|
|
@@ -46,8 +46,8 @@ export declare const Strategies: {
|
|
|
46
46
|
};
|
|
47
47
|
Loading: {
|
|
48
48
|
Table: {
|
|
49
|
-
hasSpinner: (selector?: string) => ({ root }: import("
|
|
50
|
-
custom: (fn: (context: import("
|
|
49
|
+
hasSpinner: (selector?: string) => ({ root }: import("..").TableContext) => Promise<boolean>;
|
|
50
|
+
custom: (fn: (context: import("..").TableContext) => Promise<boolean>) => (context: import("..").TableContext) => Promise<boolean>;
|
|
51
51
|
never: () => Promise<boolean>;
|
|
52
52
|
};
|
|
53
53
|
Row: {
|
|
@@ -57,7 +57,7 @@ export declare const Strategies: {
|
|
|
57
57
|
never: () => Promise<boolean>;
|
|
58
58
|
};
|
|
59
59
|
Headers: {
|
|
60
|
-
stable: (duration?: number) => (context: import("
|
|
60
|
+
stable: (duration?: number) => (context: import("..").TableContext) => Promise<boolean>;
|
|
61
61
|
never: () => Promise<boolean>;
|
|
62
62
|
};
|
|
63
63
|
};
|
package/dist/strategies/rdg.d.ts
CHANGED
|
@@ -9,10 +9,6 @@ export declare const scrollRightHeaderRDG: (context: TableContext) => Promise<st
|
|
|
9
9
|
* changing during pagination/scrolling.
|
|
10
10
|
*/
|
|
11
11
|
export declare const rdgGetCellLocator: ({ row, columnIndex }: any) => any;
|
|
12
|
-
/**
|
|
13
|
-
* Scrolls virtualized columns into view before reading.
|
|
14
|
-
*/
|
|
15
|
-
export declare const rdgCellNavigation: ({ root, page, index }: any) => Promise<void>;
|
|
16
12
|
/**
|
|
17
13
|
* Scrolls the grid vertically to load more virtualized rows.
|
|
18
14
|
*/
|
|
@@ -27,7 +23,6 @@ export declare const rdgNavigation: {
|
|
|
27
23
|
export declare const RDGStrategies: {
|
|
28
24
|
header: (context: TableContext) => Promise<string[]>;
|
|
29
25
|
getCellLocator: ({ row, columnIndex }: any) => any;
|
|
30
|
-
cellNavigation: ({ root, page, index }: any) => Promise<void>;
|
|
31
26
|
navigation: {
|
|
32
27
|
goRight: ({ root, page }: any) => Promise<void>;
|
|
33
28
|
goLeft: ({ root, page }: any) => Promise<void>;
|
package/dist/strategies/rdg.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RDGStrategies = exports.rdgNavigation = exports.rdgPaginationStrategy = exports.
|
|
12
|
+
exports.RDGStrategies = exports.rdgNavigation = exports.rdgPaginationStrategy = exports.rdgGetCellLocator = exports.scrollRightHeaderRDG = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* Scrolls the grid horizontally to collect all column headers.
|
|
15
15
|
* Handles empty headers by labeling them (e.g. "Checkbox").
|
|
@@ -64,22 +64,6 @@ const rdgGetCellLocator = ({ row, columnIndex }) => {
|
|
|
64
64
|
return row.locator(`[role="gridcell"][aria-colindex="${ariaColIndex}"]`);
|
|
65
65
|
};
|
|
66
66
|
exports.rdgGetCellLocator = rdgGetCellLocator;
|
|
67
|
-
/**
|
|
68
|
-
* Scrolls virtualized columns into view before reading.
|
|
69
|
-
*/
|
|
70
|
-
const rdgCellNavigation = (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, page, index }) {
|
|
71
|
-
// Check if the column header is visible and scroll horizontally if needed
|
|
72
|
-
const headerCell = root.locator(`[role="columnheader"][aria-colindex="${index + 1}"]`);
|
|
73
|
-
const isVisible = yield headerCell.isVisible().catch(() => false);
|
|
74
|
-
if (!isVisible) {
|
|
75
|
-
const estimatedScroll = index * 150;
|
|
76
|
-
yield root.evaluate((el, scrollAmount) => {
|
|
77
|
-
el.scrollLeft = scrollAmount;
|
|
78
|
-
}, estimatedScroll);
|
|
79
|
-
yield page.waitForTimeout(300);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
exports.rdgCellNavigation = rdgCellNavigation;
|
|
83
67
|
/**
|
|
84
68
|
* Scrolls the grid vertically to load more virtualized rows.
|
|
85
69
|
*/
|
|
@@ -136,7 +120,6 @@ exports.rdgNavigation = {
|
|
|
136
120
|
exports.RDGStrategies = {
|
|
137
121
|
header: exports.scrollRightHeaderRDG,
|
|
138
122
|
getCellLocator: exports.rdgGetCellLocator,
|
|
139
|
-
cellNavigation: exports.rdgCellNavigation,
|
|
140
123
|
navigation: exports.rdgNavigation,
|
|
141
124
|
pagination: exports.rdgPaginationStrategy
|
|
142
125
|
};
|
|
@@ -23,21 +23,16 @@ exports.SortingStrategies = {
|
|
|
23
23
|
return {
|
|
24
24
|
doSort(_a) {
|
|
25
25
|
return __awaiter(this, arguments, void 0, function* ({ columnName, direction, context }) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new Error('getHeaderCell is required in StrategyContext for sorting.');
|
|
26
|
+
// getHeaderCell is always present on TableContext after table is initialized
|
|
27
|
+
const targetHeader = yield context.getHeaderCell(columnName);
|
|
29
28
|
// The table engine handles verify-and-retry. We only provide the trigger here.
|
|
30
|
-
const targetHeader = yield getHeaderCell(columnName);
|
|
31
29
|
yield targetHeader.click();
|
|
32
30
|
});
|
|
33
31
|
},
|
|
34
32
|
getSortState(_a) {
|
|
35
33
|
return __awaiter(this, arguments, void 0, function* ({ columnName, context }) {
|
|
36
|
-
const { getHeaderCell } = context;
|
|
37
34
|
try {
|
|
38
|
-
|
|
39
|
-
throw new Error('getHeaderCell is required');
|
|
40
|
-
const targetHeader = yield getHeaderCell(columnName);
|
|
35
|
+
const targetHeader = yield context.getHeaderCell(columnName);
|
|
41
36
|
const ariaSort = yield targetHeader.getAttribute('aria-sort');
|
|
42
37
|
if (ariaSort === 'ascending')
|
|
43
38
|
return 'asc';
|
|
@@ -46,7 +41,7 @@ exports.SortingStrategies = {
|
|
|
46
41
|
return 'none';
|
|
47
42
|
}
|
|
48
43
|
catch (_b) {
|
|
49
|
-
return 'none'; // Header not found,
|
|
44
|
+
return 'none'; // Header not found, treat as unsorted
|
|
50
45
|
}
|
|
51
46
|
});
|
|
52
47
|
},
|
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 & {\n rowLocator?: Locator;\n rowIndex?: number;\n /** Helper to reliably get a header cell locator by name */\n getHeaderCell?: (headerName: string) => Promise<Locator>;\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}\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. (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 /**\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 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 * > **\u26A0\uFE0F UI Interactions:** `map` defaults to `parallel: true`. If your callback opens popovers,\n * > fills inputs, or otherwise mutates UI state, pass `{ parallel: false }` to avoid concurrent\n * > interactions interfering with each other.\n *\n * @example\n * // Data extraction \u2014 parallel is safe\n * const emails = await table.map(({ row }) => row.getCell('Email').innerText());\n *\n * @example\n * // UI interactions \u2014 must use parallel: false\n * const assignees = await table.map(async ({ row }) => {\n * await row.getCell('Assignee').locator('button').click();\n * const name = await page.locator('.popover .name').innerText();\n * await page.keyboard.press('Escape');\n * return name;\n * }, { parallel: false });\n */\n map<R>(\n callback: (ctx: RowIterationContext<T>) => R | Promise<R>,\n options?: RowIterationOptions\n ): Promise<R[]>;\n\n /**\n * Filters rows across all pages by an async predicate. Returns a SmartRowArray.\n * Rows are returned as-is \u2014 call `bringIntoView()` on each if needed.\n * Execution is sequential by default.\n *\n * @example\n * const active = await table.filter(async ({ row }) =>\n * await row.getCell('Status').innerText() === 'Active'\n * );\n */\n filter(\n predicate: (ctx: RowIterationContext<T>) => boolean | Promise<boolean>,\n options?: RowIterationOptions\n ): Promise<SmartRowArray<T>>;\n\n /**\n * Provides access to sorting actions and assertions.\n */\n sorting: {\n /**\n * Applies the configured sorting strategy to the specified column.\n * @param columnName The name of the column to sort.\n * @param direction The direction to sort ('asc' or 'desc').\n */\n apply(columnName: string, direction: 'asc' | 'desc'): Promise<void>;\n /**\n * Gets the current sort state of a column using the configured sorting strategy.\n * @param columnName The name of the column to check.\n * @returns A promise that resolves to 'asc', 'desc', or 'none'.\n */\n getState(columnName: string): Promise<'asc' | 'desc' | 'none'>;\n };\n\n /**\n * Generate an AI-friendly configuration prompt for debugging.\n * Outputs table HTML and TypeScript definitions to help AI assistants generate config.\n * Automatically throws an Error containing the prompt.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
|
|
6
|
+
export declare const TYPE_CONTEXT = "\n/**\n * Flexible selector type - can be a CSS string, function returning a Locator, or Locator itself.\n * @example\n * // String selector\n * rowSelector: 'tbody tr'\n * \n * // Function selector\n * rowSelector: (root) => root.locator('[role=\"row\"]')\n */\nexport type Selector = string | ((root: Locator | Page) => Locator) | ((root: Locator) => Locator);\n\n/**\n * Value used to filter rows.\n * - string/number/RegExp: filter by text content of the cell.\n * - function: filter by custom locator logic within the cell.\n * @example\n * // Text filter\n * { Name: 'John' }\n * \n * // Custom locator filter (e.g. checkbox is checked)\n * { Status: (cell) => cell.locator('input:checked') }\n */\nexport type FilterValue = string | RegExp | number | ((cell: Locator) => Locator);\n\n/**\n * Function to get a cell locator given row, column info.\n * Replaces the old cellResolver.\n */\nexport type GetCellLocatorFn = (args: {\n row: Locator;\n columnName: string;\n columnIndex: number;\n rowIndex?: number;\n page: Page;\n}) => Locator;\n\n/**\n * Hook called before each cell value is read in toJSON (and columnOverrides.read).\n * Use this to scroll off-screen columns into view in horizontally virtualized tables,\n * wait for lazy-rendered content, or perform any pre-read setup.\n *\n * @example\n * // Scroll the column header into view to trigger horizontal virtualization render\n * strategies: {\n * beforeCellRead: async ({ columnName, getHeaderCell }) => {\n * const header = await getHeaderCell(columnName);\n * await header.scrollIntoViewIfNeeded();\n * }\n * }\n */\nexport type BeforeCellReadFn = (args: {\n /** The resolved cell locator */\n cell: Locator;\n columnName: string;\n columnIndex: number;\n row: Locator;\n page: Page;\n root: Locator;\n /** Resolves a column name to its header cell locator */\n getHeaderCell: (columnName: string) => Promise<Locator>;\n}) => Promise<void>;\n\n/**\n * Function to get the currently active/focused cell.\n * Returns null if no cell is active.\n */\nexport type GetActiveCellFn = (args: TableContext) => Promise<{\n rowIndex: number;\n columnIndex: number;\n columnName?: string;\n locator: Locator;\n} | null>;\n\n\n/**\n * SmartRow - A Playwright Locator with table-aware methods.\n * \n * Extends all standard Locator methods (click, isVisible, etc.) with table-specific functionality.\n * \n * @example\n * const row = table.getRow({ Name: 'John Doe' });\n * await row.click(); // Standard Locator method\n * const email = row.getCell('Email'); // Table-aware method\n * const data = await row.toJSON(); // Extract all row data\n * await row.smartFill({ Name: 'Jane', Status: 'Active' }); // Fill form fields\n */\nexport type SmartRow<T = any> = Locator & {\n /** Optional row index (0-based) if known */\n rowIndex?: number;\n\n /** Optional page index this row was found on (0-based) */\n tablePageIndex?: number;\n\n /** Reference to the parent TableResult */\n table: TableResult<T>;\n\n /**\n * Get a cell locator by column name.\n * @param column - Column name (case-sensitive)\n * @returns Locator for the cell\n * @example\n * const emailCell = row.getCell('Email');\n * await expect(emailCell).toHaveText('john@example.com');\n */\n getCell(column: string): Locator;\n\n /**\n * Extract all cell data as a key-value object.\n * @param options - Optional configuration\n * @param options.columns - Specific columns to extract (extracts all if not specified)\n * @returns Promise resolving to row data\n * @example\n * const data = await row.toJSON();\n * // { Name: 'John', Email: 'john@example.com', ... }\n * \n * const partial = await row.toJSON({ columns: ['Name', 'Email'] });\n * // { Name: 'John', Email: 'john@example.com' }\n */\n toJSON(options?: { columns?: string[] }): Promise<T>;\n\n /**\n * Scrolls/paginates to bring this row into view.\n * Only works if rowIndex is known (e.g., from getRowByIndex).\n * @throws Error if rowIndex is unknown\n */\n bringIntoView(): Promise<void>;\n\n /**\n * Intelligently fills form fields in the row.\n * Automatically detects input types (text, select, checkbox, contenteditable).\n * \n * @param data - Column-value pairs to fill\n * @param options - Optional configuration\n * @param options.inputMappers - Custom input selectors per column\n * @example\n * // Auto-detection\n * await row.smartFill({ Name: 'John', Status: 'Active', Subscribe: true });\n * \n * // Custom input mappers\n * await row.smartFill(\n * { Name: 'John' },\n * { inputMappers: { Name: (cell) => cell.locator('.custom-input') } }\n * );\n */\n smartFill: (data: Partial<T> | Record<string, any>, options?: FillOptions) => Promise<void>;\n\n /**\n * Returns whether the row exists in the DOM (i.e. is not a sentinel row).\n */\n wasFound(): boolean;\n};\n\nexport type StrategyContext = TableContext & {\n rowLocator?: Locator;\n rowIndex?: number;\n};\n\n/**\n * Defines the contract for a sorting strategy.\n */\nexport interface SortingStrategy {\n /**\n * Performs the sort action on a column.\n */\n doSort(options: {\n columnName: string;\n direction: 'asc' | 'desc';\n context: StrategyContext;\n }): Promise<void>;\n\n /**\n * Retrieves the current sort state of a column.\n */\n getSortState(options: {\n columnName: string;\n context: StrategyContext;\n }): Promise<'asc' | 'desc' | 'none'>;\n}\n\n/**\n * Debug configuration for development and troubleshooting\n */\nexport type DebugConfig = {\n /**\n * Slow down operations for debugging\n * - number: Apply same delay to all operations (ms)\n * - object: Granular delays per operation type\n */\n slow?: number | {\n pagination?: number;\n getCell?: number;\n findRow?: number;\n default?: number;\n };\n /**\n * Log level for debug output\n * - 'verbose': All logs (verbose, info, error)\n * - 'info': Info and error logs only\n * - 'error': Error logs only\n * - 'none': No logs\n */\n logLevel?: 'verbose' | 'info' | 'error' | 'none';\n};\n\nexport interface TableContext<T = any> {\n root: Locator;\n config: FinalTableConfig<T>;\n page: Page;\n resolve: (selector: Selector, parent: Locator | Page) => Locator;\n /** Resolves a column name to its header cell locator. Available after table is initialized. */\n getHeaderCell?: (columnName: string) => Promise<Locator>;\n /** Returns all column names in order. Available after table is initialized. */\n getHeaders?: () => Promise<string[]>;\n /** Scrolls the table horizontally to bring the given column's header into view. */\n scrollToColumn?: (columnName: string) => Promise<void>;\n}\n\nexport interface PaginationPrimitives {\n /** Classic \"Next Page\" or \"Scroll Down\" */\n goNext?: (context: TableContext) => Promise<boolean>;\n\n /** Classic \"Previous Page\" or \"Scroll Up\" */\n goPrevious?: (context: TableContext) => Promise<boolean>;\n\n /** Bulk skip forward multiple pages at once */\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,13 +152,16 @@ 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
162
|
export type StrategyContext = TableContext & {
|
|
132
163
|
rowLocator?: Locator;
|
|
133
164
|
rowIndex?: number;
|
|
134
|
-
/** Helper to reliably get a header cell locator by name */
|
|
135
|
-
getHeaderCell?: (headerName: string) => Promise<Locator>;
|
|
136
165
|
};
|
|
137
166
|
|
|
138
167
|
/**
|
|
@@ -187,6 +216,12 @@ export interface TableContext<T = any> {
|
|
|
187
216
|
config: FinalTableConfig<T>;
|
|
188
217
|
page: Page;
|
|
189
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>;
|
|
190
225
|
}
|
|
191
226
|
|
|
192
227
|
export interface PaginationPrimitives {
|
|
@@ -229,7 +264,7 @@ export type FillStrategy = (options: {
|
|
|
229
264
|
|
|
230
265
|
export interface ColumnOverride<TValue = any> {
|
|
231
266
|
/**
|
|
232
|
-
* How to extract the value from the cell.
|
|
267
|
+
* How to extract the value from the cell.
|
|
233
268
|
*/
|
|
234
269
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
235
270
|
|
|
@@ -294,6 +329,12 @@ export interface TableStrategies {
|
|
|
294
329
|
getCellLocator?: GetCellLocatorFn;
|
|
295
330
|
/** Function to get the currently active/focused cell */
|
|
296
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;
|
|
297
338
|
/** Custom helper to check if a table is fully loaded/ready */
|
|
298
339
|
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
299
340
|
/** Custom helper to check if a row is fully loaded/ready */
|
|
@@ -416,8 +457,7 @@ export interface TableResult<T = any> extends AsyncIterable<{ row: SmartRow<T>;
|
|
|
416
457
|
* @param options Optional settings including bringIntoView
|
|
417
458
|
*/
|
|
418
459
|
getRowByIndex: (
|
|
419
|
-
index: number
|
|
420
|
-
options?: { bringIntoView?: boolean }
|
|
460
|
+
index: number
|
|
421
461
|
) => SmartRow;
|
|
422
462
|
|
|
423
463
|
/**
|
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,12 +135,14 @@ 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;
|
|
116
145
|
rowIndex?: number;
|
|
117
|
-
/** Helper to reliably get a header cell locator by name */
|
|
118
|
-
getHeaderCell?: (headerName: string) => Promise<Locator>;
|
|
119
146
|
};
|
|
120
147
|
/**
|
|
121
148
|
* Defines the contract for a sorting strategy.
|
|
@@ -166,6 +193,12 @@ export interface TableContext<T = any> {
|
|
|
166
193
|
config: FinalTableConfig<T>;
|
|
167
194
|
page: Page;
|
|
168
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>;
|
|
169
202
|
}
|
|
170
203
|
export interface PaginationPrimitives {
|
|
171
204
|
/** Classic "Next Page" or "Scroll Down" */
|
|
@@ -196,7 +229,7 @@ export type FillStrategy = (options: {
|
|
|
196
229
|
}) => Promise<void>;
|
|
197
230
|
export interface ColumnOverride<TValue = any> {
|
|
198
231
|
/**
|
|
199
|
-
* How to extract the value from the cell.
|
|
232
|
+
* How to extract the value from the cell.
|
|
200
233
|
*/
|
|
201
234
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
202
235
|
/**
|
|
@@ -259,6 +292,12 @@ export interface TableStrategies {
|
|
|
259
292
|
getCellLocator?: GetCellLocatorFn;
|
|
260
293
|
/** Function to get the currently active/focused cell */
|
|
261
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;
|
|
262
301
|
/** Custom helper to check if a table is fully loaded/ready */
|
|
263
302
|
isTableLoaded?: (args: TableContext) => Promise<boolean>;
|
|
264
303
|
/** Custom helper to check if a row is fully loaded/ready */
|
|
@@ -385,9 +424,7 @@ export interface TableResult<T = any> extends AsyncIterable<{
|
|
|
385
424
|
* @param index 1-based row index
|
|
386
425
|
* @param options Optional settings including bringIntoView
|
|
387
426
|
*/
|
|
388
|
-
getRowByIndex: (index: number
|
|
389
|
-
bringIntoView?: boolean;
|
|
390
|
-
}) => SmartRow;
|
|
427
|
+
getRowByIndex: (index: number) => SmartRow;
|
|
391
428
|
/**
|
|
392
429
|
* ASYNC: Searches for a single row across pages using pagination.
|
|
393
430
|
* Auto-initializes the table if not already initialized.
|
package/dist/useTable.js
CHANGED
|
@@ -121,9 +121,24 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
121
121
|
console.log(`⚠️ Throwing error to display [${promptName}] cleanly...`);
|
|
122
122
|
throw new Error(finalPrompt);
|
|
123
123
|
});
|
|
124
|
-
const
|
|
124
|
+
const _autoInit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
125
|
yield tableMapper.getMap();
|
|
126
126
|
});
|
|
127
|
+
const _advancePage = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
var _a;
|
|
129
|
+
const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell, getHeaders: result.getHeaders, scrollToColumn: result.scrollToColumn };
|
|
130
|
+
let advanced;
|
|
131
|
+
if (typeof config.strategies.pagination === 'function') {
|
|
132
|
+
advanced = !!(yield config.strategies.pagination(context));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
advanced = !!(((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
136
|
+
}
|
|
137
|
+
if (advanced) {
|
|
138
|
+
tableState.currentPageIndex++;
|
|
139
|
+
}
|
|
140
|
+
return advanced;
|
|
141
|
+
});
|
|
127
142
|
const result = {
|
|
128
143
|
get currentPageIndex() { return tableState.currentPageIndex; },
|
|
129
144
|
set currentPageIndex(v) { tableState.currentPageIndex = v; },
|
|
@@ -160,7 +175,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
160
175
|
reset: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
176
|
var _a;
|
|
162
177
|
log("Resetting table...");
|
|
163
|
-
const context = { root: rootLocator, config, page: rootLocator.page(), resolve };
|
|
178
|
+
const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell };
|
|
164
179
|
yield config.onReset(context);
|
|
165
180
|
if (typeof config.strategies.pagination !== 'function' && ((_a = config.strategies.pagination) === null || _a === void 0 ? void 0 : _a.goToFirst)) {
|
|
166
181
|
log("Auto-navigating to first page...");
|
|
@@ -172,7 +187,8 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
172
187
|
_hasPaginated = false;
|
|
173
188
|
tableState.currentPageIndex = 0;
|
|
174
189
|
tableMapper.clear();
|
|
175
|
-
log("Table reset complete.");
|
|
190
|
+
log("Table reset complete. Calling autoInit to restore state.");
|
|
191
|
+
yield _autoInit();
|
|
176
192
|
}),
|
|
177
193
|
revalidate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
194
|
log("Revalidating table structure...");
|
|
@@ -182,16 +198,16 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
182
198
|
getRow: (filters, options = { exact: false }) => {
|
|
183
199
|
const map = tableMapper.getMapSync();
|
|
184
200
|
if (!map)
|
|
185
|
-
throw new Error('Table not initialized. Call await table.init() first, or use async methods like table.findRow() or table.
|
|
201
|
+
throw new Error('Table not initialized. Call await table.init() first, or use async methods like table.findRow() or table.findRows() which auto-initialize.');
|
|
186
202
|
const allRows = resolve(config.rowSelector, rootLocator);
|
|
187
203
|
const matchedRows = filterEngine.applyFilters(allRows, filters, map, options.exact || false, rootLocator.page());
|
|
188
204
|
const rowLocator = matchedRows.first();
|
|
189
205
|
return _makeSmart(rowLocator, map, 0); // fallback index 0
|
|
190
206
|
},
|
|
191
|
-
getRowByIndex: (index
|
|
207
|
+
getRowByIndex: (index) => {
|
|
192
208
|
const map = tableMapper.getMapSync();
|
|
193
209
|
if (!map)
|
|
194
|
-
throw new Error('Table not initialized. Call await table.init() first, or use async methods like table.findRow() or table.
|
|
210
|
+
throw new Error('Table not initialized. Call await table.init() first, or use async methods like table.findRow() or table.findRows() which auto-initialize.');
|
|
195
211
|
const rowLocator = resolve(config.rowSelector, rootLocator).nth(index);
|
|
196
212
|
return _makeSmart(rowLocator, map, index);
|
|
197
213
|
},
|
|
@@ -208,7 +224,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
208
224
|
sorting: {
|
|
209
225
|
apply: (columnName, direction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
226
|
var _a;
|
|
211
|
-
yield
|
|
227
|
+
yield _autoInit();
|
|
212
228
|
if (!config.strategies.sorting)
|
|
213
229
|
throw new Error('No sorting strategy has been configured.');
|
|
214
230
|
log(`Applying sort for column "${columnName}" (${direction})`);
|
|
@@ -237,7 +253,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
237
253
|
throw new Error(`Failed to sort column "${columnName}" to "${direction}" after ${maxRetries} attempts.`);
|
|
238
254
|
}),
|
|
239
255
|
getState: (columnName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
-
yield
|
|
256
|
+
yield _autoInit();
|
|
241
257
|
if (!config.strategies.sorting)
|
|
242
258
|
throw new Error('No sorting strategy has been configured.');
|
|
243
259
|
const context = { root: rootLocator, config, page: rootLocator.page(), resolve, getHeaderCell: result.getHeaderCell };
|
|
@@ -247,8 +263,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
247
263
|
// ─── Shared async row iterator ───────────────────────────────────────────
|
|
248
264
|
[Symbol.asyncIterator]() {
|
|
249
265
|
return __asyncGenerator(this, arguments, function* _a() {
|
|
250
|
-
|
|
251
|
-
yield __await(_ensureInitialized());
|
|
266
|
+
yield __await(_autoInit());
|
|
252
267
|
const map = tableMapper.getMapSync();
|
|
253
268
|
const effectiveMaxPages = config.maxPages;
|
|
254
269
|
let rowIndex = 0;
|
|
@@ -261,25 +276,16 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
261
276
|
}
|
|
262
277
|
if (pagesScanned >= effectiveMaxPages)
|
|
263
278
|
break;
|
|
264
|
-
|
|
265
|
-
let advanced;
|
|
266
|
-
if (typeof config.strategies.pagination === 'function') {
|
|
267
|
-
advanced = !!(yield __await(config.strategies.pagination(context)));
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
advanced = !!(((_b = config.strategies.pagination) === null || _b === void 0 ? void 0 : _b.goNext) && (yield __await(config.strategies.pagination.goNext(context))));
|
|
271
|
-
}
|
|
272
|
-
if (!advanced)
|
|
279
|
+
if (!(yield __await(_advancePage())))
|
|
273
280
|
break;
|
|
274
|
-
tableState.currentPageIndex++;
|
|
275
281
|
pagesScanned++;
|
|
276
282
|
}
|
|
277
283
|
});
|
|
278
284
|
},
|
|
279
285
|
// ─── Private row-iteration engine ────────────────────────────────────────
|
|
280
286
|
forEach: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
|
|
281
|
-
var _a, _b, _c
|
|
282
|
-
yield
|
|
287
|
+
var _a, _b, _c;
|
|
288
|
+
yield _autoInit();
|
|
283
289
|
const map = tableMapper.getMapSync();
|
|
284
290
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
285
291
|
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
@@ -321,23 +327,14 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
321
327
|
rowIndex += smartRows.length;
|
|
322
328
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
323
329
|
break;
|
|
324
|
-
|
|
325
|
-
let advanced;
|
|
326
|
-
if (typeof config.strategies.pagination === 'function') {
|
|
327
|
-
advanced = !!(yield config.strategies.pagination(context));
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
331
|
-
}
|
|
332
|
-
if (!advanced)
|
|
330
|
+
if (!(yield _advancePage()))
|
|
333
331
|
break;
|
|
334
|
-
tableState.currentPageIndex++;
|
|
335
332
|
pagesScanned++;
|
|
336
333
|
}
|
|
337
334
|
}),
|
|
338
335
|
map: (callback_1, ...args_1) => __awaiter(void 0, [callback_1, ...args_1], void 0, function* (callback, options = {}) {
|
|
339
|
-
var _a, _b, _c
|
|
340
|
-
yield
|
|
336
|
+
var _a, _b, _c;
|
|
337
|
+
yield _autoInit();
|
|
341
338
|
const map = tableMapper.getMapSync();
|
|
342
339
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
343
340
|
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
@@ -383,24 +380,15 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
383
380
|
rowIndex += smartRows.length;
|
|
384
381
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
385
382
|
break;
|
|
386
|
-
|
|
387
|
-
let advanced;
|
|
388
|
-
if (typeof config.strategies.pagination === 'function') {
|
|
389
|
-
advanced = !!(yield config.strategies.pagination(context));
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
393
|
-
}
|
|
394
|
-
if (!advanced)
|
|
383
|
+
if (!(yield _advancePage()))
|
|
395
384
|
break;
|
|
396
|
-
tableState.currentPageIndex++;
|
|
397
385
|
pagesScanned++;
|
|
398
386
|
}
|
|
399
387
|
return results;
|
|
400
388
|
}),
|
|
401
389
|
filter: (predicate_1, ...args_1) => __awaiter(void 0, [predicate_1, ...args_1], void 0, function* (predicate, options = {}) {
|
|
402
|
-
var _a, _b, _c
|
|
403
|
-
yield
|
|
390
|
+
var _a, _b, _c;
|
|
391
|
+
yield _autoInit();
|
|
404
392
|
const map = tableMapper.getMapSync();
|
|
405
393
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : config.maxPages;
|
|
406
394
|
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : config.strategies.dedupe;
|
|
@@ -432,7 +420,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
432
420
|
if (stopped)
|
|
433
421
|
break;
|
|
434
422
|
if (dedupeKeys) {
|
|
435
|
-
const key = yield
|
|
423
|
+
const key = yield dedupeStrategy(row);
|
|
436
424
|
if (dedupeKeys.has(key))
|
|
437
425
|
continue;
|
|
438
426
|
dedupeKeys.add(key);
|
|
@@ -445,17 +433,8 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
445
433
|
rowIndex += smartRows.length;
|
|
446
434
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
447
435
|
break;
|
|
448
|
-
|
|
449
|
-
let advanced;
|
|
450
|
-
if (typeof config.strategies.pagination === 'function') {
|
|
451
|
-
advanced = !!(yield config.strategies.pagination(context));
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
advanced = !!(((_d = config.strategies.pagination) === null || _d === void 0 ? void 0 : _d.goNext) && (yield config.strategies.pagination.goNext(context)));
|
|
455
|
-
}
|
|
456
|
-
if (!advanced)
|
|
436
|
+
if (!(yield _advancePage()))
|
|
457
437
|
break;
|
|
458
|
-
tableState.currentPageIndex++;
|
|
459
438
|
pagesScanned++;
|
|
460
439
|
}
|
|
461
440
|
return (0, smartRowArray_1.createSmartRowArray)(matched);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Locator } from '@playwright/test';
|
|
2
|
+
export declare class ElementTracker {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
constructor(prefix?: string);
|
|
5
|
+
/**
|
|
6
|
+
* Finds the indices of newly seen elements in the browser, storing their text signature
|
|
7
|
+
* in a WeakMap. This gracefully handles both append-only DOMs (by identity) and
|
|
8
|
+
* virtualized DOMs (by text signature if nodes are recycled).
|
|
9
|
+
*/
|
|
10
|
+
getUnseenIndices(locators: Locator): Promise<number[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Cleans up the tracking map from the browser window object.
|
|
13
|
+
*/
|
|
14
|
+
cleanup(page: any): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ElementTracker = void 0;
|
|
13
|
+
class ElementTracker {
|
|
14
|
+
constructor(prefix = 'tracker') {
|
|
15
|
+
this.id = `__smartTable_${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds the indices of newly seen elements in the browser, storing their text signature
|
|
19
|
+
* in a WeakMap. This gracefully handles both append-only DOMs (by identity) and
|
|
20
|
+
* virtualized DOMs (by text signature if nodes are recycled).
|
|
21
|
+
*/
|
|
22
|
+
getUnseenIndices(locators) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return yield locators.evaluateAll((elements, trackerId) => {
|
|
25
|
+
const win = window;
|
|
26
|
+
if (!win[trackerId]) {
|
|
27
|
+
win[trackerId] = new WeakMap();
|
|
28
|
+
}
|
|
29
|
+
const seenMap = win[trackerId];
|
|
30
|
+
const newIndices = [];
|
|
31
|
+
elements.forEach((el, index) => {
|
|
32
|
+
// Determine a lightweight signature for the row (textContent strips HTML, fast)
|
|
33
|
+
const signature = el.textContent || '';
|
|
34
|
+
// If it's a new element, OR a recycled element with new data
|
|
35
|
+
if (seenMap.get(el) !== signature) {
|
|
36
|
+
seenMap.set(el, signature);
|
|
37
|
+
newIndices.push(index);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return newIndices;
|
|
41
|
+
}, this.id);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Cleans up the tracking map from the browser window object.
|
|
46
|
+
*/
|
|
47
|
+
cleanup(page) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
yield page.evaluate((trackerId) => {
|
|
51
|
+
delete window[trackerId];
|
|
52
|
+
}, this.id);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
// Ignore context destroyed errors during cleanup
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ElementTracker = ElementTracker;
|