@rickcedwhat/playwright-smart-table 6.7.7 → 6.7.8
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/engine/rowFinder.js +13 -2
- package/dist/engine/tableIteration.js +58 -12
- package/dist/engine/tableMapper.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -1
- package/dist/plugins/index.d.ts +57 -8
- package/dist/plugins/index.js +10 -8
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/index.js +10 -0
- package/dist/presets/mui.d.ts +22 -0
- package/dist/presets/mui.js +266 -0
- package/dist/{plugins/rdg/index.d.ts → presets/rdg.d.ts} +2 -2
- package/dist/{plugins/rdg/index.js → presets/rdg.js} +2 -2
- package/dist/smartRow.js +5 -1
- package/dist/strategies/headers.d.ts +9 -0
- package/dist/strategies/headers.js +60 -1
- package/dist/strategies/index.d.ts +5 -0
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/useTable.js +14 -2
- package/package.json +26 -7
- package/dist/plugins/mui/index.d.ts +0 -8
- package/dist/plugins/mui/index.js +0 -25
- /package/dist/{plugins → presets}/glide/columns.d.ts +0 -0
- /package/dist/{plugins → presets}/glide/columns.js +0 -0
- /package/dist/{plugins → presets}/glide/headers.d.ts +0 -0
- /package/dist/{plugins → presets}/glide/headers.js +0 -0
- /package/dist/{plugins → presets}/glide/index.d.ts +0 -0
- /package/dist/{plugins → presets}/glide/index.js +0 -0
package/dist/engine/rowFinder.js
CHANGED
|
@@ -55,6 +55,7 @@ class RowFinder {
|
|
|
55
55
|
const allRows = [];
|
|
56
56
|
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;
|
|
57
57
|
let pagesScanned = 1;
|
|
58
|
+
this.log(`findRows: starting (maxPages=${effectiveMaxPages}, filters=${JSON.stringify(filtersRecord)})`);
|
|
58
59
|
const tracker = new elementTracker_1.ElementTracker('findRows');
|
|
59
60
|
try {
|
|
60
61
|
const collectMatches = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -68,12 +69,17 @@ class RowFinder {
|
|
|
68
69
|
const newIndices = yield tracker.getUnseenIndices(rowLocators);
|
|
69
70
|
const currentRows = yield rowLocators.all();
|
|
70
71
|
const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
|
|
72
|
+
let added = 0;
|
|
71
73
|
for (const idx of newIndices) {
|
|
72
74
|
const smartRow = this.makeSmartRow(currentRows[idx], map, allRows.length, this.tableState.currentPageIndex);
|
|
73
|
-
if (isRowLoading && (yield isRowLoading(smartRow)))
|
|
75
|
+
if (isRowLoading && (yield isRowLoading(smartRow))) {
|
|
76
|
+
this.log(`findRows: page ${this.tableState.currentPageIndex} — row skipped (isRowLoading=true)`);
|
|
74
77
|
continue;
|
|
78
|
+
}
|
|
75
79
|
allRows.push(smartRow);
|
|
80
|
+
added++;
|
|
76
81
|
}
|
|
82
|
+
this.log(`findRows: page ${this.tableState.currentPageIndex} — ${added} new match(es) (total: ${allRows.length})`);
|
|
77
83
|
});
|
|
78
84
|
// Scan first page
|
|
79
85
|
yield collectMatches();
|
|
@@ -93,20 +99,25 @@ class RowFinder {
|
|
|
93
99
|
paginationResult = yield this.config.strategies.pagination.goNext(context);
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
102
|
+
this.log(`findRows: no pagination primitive — stopping`);
|
|
96
103
|
break;
|
|
97
104
|
}
|
|
98
105
|
const didPaginate = (0, validation_1.validatePaginationResult)(paginationResult, 'Pagination Strategy');
|
|
99
|
-
if (!didPaginate)
|
|
106
|
+
if (!didPaginate) {
|
|
107
|
+
this.log(`findRows: pagination returned false — end of data`);
|
|
100
108
|
break;
|
|
109
|
+
}
|
|
101
110
|
const pagesJumped = typeof paginationResult === 'number' ? paginationResult : 1;
|
|
102
111
|
this.tableState.currentPageIndex += pagesJumped;
|
|
103
112
|
pagesScanned += pagesJumped;
|
|
113
|
+
this.log(`findRows: advanced ${pagesJumped} page(s), now at page ${this.tableState.currentPageIndex}`);
|
|
104
114
|
yield collectMatches();
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
finally {
|
|
108
118
|
yield tracker.cleanup(this.rootLocator.page());
|
|
109
119
|
}
|
|
120
|
+
this.log(`findRows: done — ${allRows.length} row(s) collected across ${pagesScanned} page(s)`);
|
|
110
121
|
return (0, smartRowArray_1.createSmartRowArray)(allRows);
|
|
111
122
|
});
|
|
112
123
|
}
|
|
@@ -13,6 +13,10 @@ exports.runForEach = runForEach;
|
|
|
13
13
|
exports.runMap = runMap;
|
|
14
14
|
exports.runFilter = runFilter;
|
|
15
15
|
const elementTracker_1 = require("../utils/elementTracker");
|
|
16
|
+
const debugUtils_1 = require("../utils/debugUtils");
|
|
17
|
+
function log(config, msg) {
|
|
18
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', msg);
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
21
|
* Shared row-iteration loop used by forEach, map, and filter.
|
|
18
22
|
*/
|
|
@@ -26,27 +30,36 @@ function runForEach(env_1, callback_1) {
|
|
|
26
30
|
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
|
|
27
31
|
const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
|
|
28
32
|
const tracker = new elementTracker_1.ElementTracker('forEach');
|
|
33
|
+
log(env.config, `forEach: starting (maxPages=${effectiveMaxPages}, parallel=${parallel}, dedupe=${!!dedupeStrategy})`);
|
|
29
34
|
try {
|
|
30
35
|
let rowIndex = 0;
|
|
31
36
|
let stopped = false;
|
|
32
37
|
let pagesScanned = 1;
|
|
33
|
-
|
|
38
|
+
let totalProcessed = 0;
|
|
39
|
+
const stop = () => {
|
|
40
|
+
log(env.config, `forEach: stop() called — halting after current page`);
|
|
41
|
+
stopped = true;
|
|
42
|
+
};
|
|
34
43
|
while (!stopped) {
|
|
35
44
|
const rowLocators = env.getRowLocators();
|
|
36
45
|
const newIndices = yield tracker.getUnseenIndices(rowLocators);
|
|
37
46
|
const pageRows = yield rowLocators.all();
|
|
38
47
|
const smartRows = newIndices.map((idx, i) => env.makeSmartRow(pageRows[idx], map, rowIndex + i));
|
|
48
|
+
log(env.config, `forEach: page ${pagesScanned} — ${newIndices.length} new row(s) found`);
|
|
39
49
|
if (parallel) {
|
|
40
50
|
yield Promise.all(smartRows.map((row) => __awaiter(this, void 0, void 0, function* () {
|
|
41
51
|
if (stopped)
|
|
42
52
|
return;
|
|
43
53
|
if (dedupeKeys && dedupeStrategy) {
|
|
44
54
|
const key = yield dedupeStrategy(row);
|
|
45
|
-
if (dedupeKeys.has(key))
|
|
55
|
+
if (dedupeKeys.has(key)) {
|
|
56
|
+
log(env.config, `forEach: dedupe skip key="${key}"`);
|
|
46
57
|
return;
|
|
58
|
+
}
|
|
47
59
|
dedupeKeys.add(key);
|
|
48
60
|
}
|
|
49
61
|
yield callback({ row, rowIndex: row.rowIndex, stop });
|
|
62
|
+
totalProcessed++;
|
|
50
63
|
})));
|
|
51
64
|
}
|
|
52
65
|
else {
|
|
@@ -55,20 +68,27 @@ function runForEach(env_1, callback_1) {
|
|
|
55
68
|
break;
|
|
56
69
|
if (dedupeKeys && dedupeStrategy) {
|
|
57
70
|
const key = yield dedupeStrategy(row);
|
|
58
|
-
if (dedupeKeys.has(key))
|
|
71
|
+
if (dedupeKeys.has(key)) {
|
|
72
|
+
log(env.config, `forEach: dedupe skip key="${key}"`);
|
|
59
73
|
continue;
|
|
74
|
+
}
|
|
60
75
|
dedupeKeys.add(key);
|
|
61
76
|
}
|
|
62
77
|
yield callback({ row, rowIndex: row.rowIndex, stop });
|
|
78
|
+
totalProcessed++;
|
|
63
79
|
}
|
|
64
80
|
}
|
|
65
81
|
rowIndex += smartRows.length;
|
|
66
82
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
67
83
|
break;
|
|
68
|
-
|
|
84
|
+
log(env.config, `forEach: advancing to next page (${pagesScanned} → ${pagesScanned + 1})`);
|
|
85
|
+
if (!(yield env.advancePage(useBulk))) {
|
|
86
|
+
log(env.config, `forEach: no more pages — done`);
|
|
69
87
|
break;
|
|
88
|
+
}
|
|
70
89
|
pagesScanned++;
|
|
71
90
|
}
|
|
91
|
+
log(env.config, `forEach: complete — ${totalProcessed} row(s) processed across ${pagesScanned} page(s)`);
|
|
72
92
|
}
|
|
73
93
|
finally {
|
|
74
94
|
yield tracker.cleanup(env.getPage());
|
|
@@ -88,24 +108,31 @@ function runMap(env_1, callback_1) {
|
|
|
88
108
|
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : true;
|
|
89
109
|
const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
|
|
90
110
|
const tracker = new elementTracker_1.ElementTracker('map');
|
|
111
|
+
log(env.config, `map: starting (maxPages=${effectiveMaxPages}, parallel=${parallel}, dedupe=${!!dedupeStrategy})`);
|
|
91
112
|
const results = [];
|
|
92
113
|
const SKIP = Symbol('skip');
|
|
93
114
|
try {
|
|
94
115
|
let rowIndex = 0;
|
|
95
116
|
let stopped = false;
|
|
96
117
|
let pagesScanned = 1;
|
|
97
|
-
const stop = () => {
|
|
118
|
+
const stop = () => {
|
|
119
|
+
log(env.config, `map: stop() called — halting after current page`);
|
|
120
|
+
stopped = true;
|
|
121
|
+
};
|
|
98
122
|
while (!stopped) {
|
|
99
123
|
const rowLocators = env.getRowLocators();
|
|
100
124
|
const newIndices = yield tracker.getUnseenIndices(rowLocators);
|
|
101
125
|
const pageRows = yield rowLocators.all();
|
|
102
126
|
const smartRows = newIndices.map((idx, i) => env.makeSmartRow(pageRows[idx], map, rowIndex + i));
|
|
127
|
+
log(env.config, `map: scanning page ${pagesScanned} — ${newIndices.length} new row(s)`);
|
|
103
128
|
if (parallel) {
|
|
104
129
|
const pageResults = yield Promise.all(smartRows.map((row) => __awaiter(this, void 0, void 0, function* () {
|
|
105
130
|
if (dedupeKeys && dedupeStrategy) {
|
|
106
131
|
const key = yield dedupeStrategy(row);
|
|
107
|
-
if (dedupeKeys.has(key))
|
|
132
|
+
if (dedupeKeys.has(key)) {
|
|
133
|
+
log(env.config, `map: dedupe skip key="${key}"`);
|
|
108
134
|
return SKIP;
|
|
135
|
+
}
|
|
109
136
|
dedupeKeys.add(key);
|
|
110
137
|
}
|
|
111
138
|
return callback({ row, rowIndex: row.rowIndex, stop });
|
|
@@ -121,8 +148,10 @@ function runMap(env_1, callback_1) {
|
|
|
121
148
|
break;
|
|
122
149
|
if (dedupeKeys && dedupeStrategy) {
|
|
123
150
|
const key = yield dedupeStrategy(row);
|
|
124
|
-
if (dedupeKeys.has(key))
|
|
151
|
+
if (dedupeKeys.has(key)) {
|
|
152
|
+
log(env.config, `map: dedupe skip key="${key}"`);
|
|
125
153
|
continue;
|
|
154
|
+
}
|
|
126
155
|
dedupeKeys.add(key);
|
|
127
156
|
}
|
|
128
157
|
results.push(yield callback({ row, rowIndex: row.rowIndex, stop }));
|
|
@@ -131,10 +160,14 @@ function runMap(env_1, callback_1) {
|
|
|
131
160
|
rowIndex += smartRows.length;
|
|
132
161
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
133
162
|
break;
|
|
134
|
-
|
|
163
|
+
log(env.config, `map: advancing to next page (${pagesScanned} → ${pagesScanned + 1})`);
|
|
164
|
+
if (!(yield env.advancePage(useBulk))) {
|
|
165
|
+
log(env.config, `map: no more pages — done`);
|
|
135
166
|
break;
|
|
167
|
+
}
|
|
136
168
|
pagesScanned++;
|
|
137
169
|
}
|
|
170
|
+
log(env.config, `map: complete — ${results.length} result(s) across ${pagesScanned} page(s)`);
|
|
138
171
|
}
|
|
139
172
|
finally {
|
|
140
173
|
yield tracker.cleanup(env.getPage());
|
|
@@ -155,23 +188,30 @@ function runFilter(env_1, predicate_1) {
|
|
|
155
188
|
const parallel = (_c = options.parallel) !== null && _c !== void 0 ? _c : false;
|
|
156
189
|
const useBulk = (_d = options.useBulkPagination) !== null && _d !== void 0 ? _d : false;
|
|
157
190
|
const tracker = new elementTracker_1.ElementTracker('filter');
|
|
191
|
+
log(env.config, `filter: starting (maxPages=${effectiveMaxPages}, parallel=${parallel}, dedupe=${!!dedupeStrategy})`);
|
|
158
192
|
const matched = [];
|
|
159
193
|
try {
|
|
160
194
|
let rowIndex = 0;
|
|
161
195
|
let stopped = false;
|
|
162
196
|
let pagesScanned = 1;
|
|
163
|
-
const stop = () => {
|
|
197
|
+
const stop = () => {
|
|
198
|
+
log(env.config, `filter: stop() called — halting after current page`);
|
|
199
|
+
stopped = true;
|
|
200
|
+
};
|
|
164
201
|
while (!stopped) {
|
|
165
202
|
const rowLocators = env.getRowLocators();
|
|
166
203
|
const newIndices = yield tracker.getUnseenIndices(rowLocators);
|
|
167
204
|
const pageRows = yield rowLocators.all();
|
|
168
205
|
const smartRows = newIndices.map((idx, i) => env.makeSmartRow(pageRows[idx], map, rowIndex + i, pagesScanned - 1));
|
|
206
|
+
log(env.config, `filter: scanning page ${pagesScanned} — ${newIndices.length} new row(s)`);
|
|
169
207
|
if (parallel) {
|
|
170
208
|
const flags = yield Promise.all(smartRows.map((row) => __awaiter(this, void 0, void 0, function* () {
|
|
171
209
|
if (dedupeKeys && dedupeStrategy) {
|
|
172
210
|
const key = yield dedupeStrategy(row);
|
|
173
|
-
if (dedupeKeys.has(key))
|
|
211
|
+
if (dedupeKeys.has(key)) {
|
|
212
|
+
log(env.config, `filter: dedupe skip key="${key}"`);
|
|
174
213
|
return false;
|
|
214
|
+
}
|
|
175
215
|
dedupeKeys.add(key);
|
|
176
216
|
}
|
|
177
217
|
return predicate({ row, rowIndex: row.rowIndex, stop });
|
|
@@ -185,8 +225,10 @@ function runFilter(env_1, predicate_1) {
|
|
|
185
225
|
break;
|
|
186
226
|
if (dedupeKeys && dedupeStrategy) {
|
|
187
227
|
const key = yield dedupeStrategy(row);
|
|
188
|
-
if (dedupeKeys.has(key))
|
|
228
|
+
if (dedupeKeys.has(key)) {
|
|
229
|
+
log(env.config, `filter: dedupe skip key="${key}"`);
|
|
189
230
|
continue;
|
|
231
|
+
}
|
|
190
232
|
dedupeKeys.add(key);
|
|
191
233
|
}
|
|
192
234
|
if (yield predicate({ row, rowIndex: row.rowIndex, stop })) {
|
|
@@ -197,10 +239,14 @@ function runFilter(env_1, predicate_1) {
|
|
|
197
239
|
rowIndex += smartRows.length;
|
|
198
240
|
if (stopped || pagesScanned >= effectiveMaxPages)
|
|
199
241
|
break;
|
|
200
|
-
|
|
242
|
+
log(env.config, `filter: advancing to next page (${pagesScanned} → ${pagesScanned + 1})`);
|
|
243
|
+
if (!(yield env.advancePage(useBulk))) {
|
|
244
|
+
log(env.config, `filter: no more pages — done`);
|
|
201
245
|
break;
|
|
246
|
+
}
|
|
202
247
|
pagesScanned++;
|
|
203
248
|
}
|
|
249
|
+
log(env.config, `filter: complete — ${matched.length} match(es) across ${pagesScanned} page(s)`);
|
|
204
250
|
}
|
|
205
251
|
finally {
|
|
206
252
|
yield tracker.cleanup(env.getPage());
|
|
@@ -73,7 +73,7 @@ class TableMapper {
|
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
75
|
lastError = e;
|
|
76
|
-
this.log(`Header mapping failed (
|
|
76
|
+
this.log(`Header mapping failed. Attempt ${Math.floor((Date.now() - startTime) / 100)}: ${e.message}`);
|
|
77
77
|
yield new Promise(r => setTimeout(r, 100));
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { useTable } from './useTable';
|
|
2
2
|
export type { TableConfig, TableResult, SmartRow, Selector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, TableContext, StrategyContext, BeforeCellReadFn, GetCellLocatorFn, GetActiveCellFn, DebugConfig, } from './types';
|
|
3
3
|
export { Strategies } from './strategies';
|
|
4
|
+
export * as presets from './presets';
|
|
5
|
+
/** @deprecated Use `presets` instead. Plugins will be removed in v7.0.0. */
|
|
4
6
|
export { Plugins } from './plugins';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Plugins = exports.Strategies = exports.useTable = void 0;
|
|
36
|
+
exports.Plugins = exports.presets = exports.Strategies = exports.useTable = void 0;
|
|
4
37
|
var useTable_1 = require("./useTable");
|
|
5
38
|
Object.defineProperty(exports, "useTable", { enumerable: true, get: function () { return useTable_1.useTable; } });
|
|
6
39
|
// Export namespace-like strategy collections
|
|
7
40
|
var strategies_1 = require("./strategies");
|
|
8
41
|
Object.defineProperty(exports, "Strategies", { enumerable: true, get: function () { return strategies_1.Strategies; } });
|
|
42
|
+
exports.presets = __importStar(require("./presets"));
|
|
43
|
+
/** @deprecated Use `presets` instead. Plugins will be removed in v7.0.0. */
|
|
9
44
|
var plugins_1 = require("./plugins");
|
|
10
45
|
Object.defineProperty(exports, "Plugins", { enumerable: true, get: function () { return plugins_1.Plugins; } });
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,16 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @deprecated Use `presets` instead. Plugins will be removed in v7.0.0.
|
|
2
3
|
* Presets for specific table/grid libraries. Each plugin exposes:
|
|
3
|
-
* - Plugins.X — full preset (selectors + headerTransformer if any + strategies). Spread: useTable(loc, { ...
|
|
4
|
-
* - Plugins.X.Strategies — strategies only. Use with your own selectors: useTable(loc, { rowSelector: '...', strategies:
|
|
4
|
+
* - Plugins.X — full preset (selectors + headerTransformer if any + strategies). Spread: useTable(loc, { ...Presets.MUI, maxPages: 5 }).
|
|
5
|
+
* - Plugins.X.Strategies — strategies only. Use with your own selectors: useTable(loc, { rowSelector: '...', strategies: Presets.MUI.Strategies }).
|
|
5
6
|
*/
|
|
6
7
|
export declare const Plugins: {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/** @deprecated Use `presets.rdg` */
|
|
9
|
+
RDG: {
|
|
10
|
+
Strategies: import("../types").TableStrategies | undefined;
|
|
11
|
+
headerSelector?: string | ((root: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
12
|
+
rowSelector?: string | undefined;
|
|
13
|
+
cellSelector?: string | ((row: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
14
|
+
maxPages?: number | undefined;
|
|
15
|
+
headerTransformer?: ((args: {
|
|
16
|
+
text: string;
|
|
17
|
+
index: number;
|
|
18
|
+
locator: import("playwright-core").Locator;
|
|
19
|
+
seenHeaders: Set<string>;
|
|
20
|
+
}) => string | Promise<string>) | undefined;
|
|
21
|
+
autoScroll?: boolean | undefined;
|
|
22
|
+
debug?: import("..").DebugConfig | undefined;
|
|
23
|
+
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
24
|
+
strategies?: import("../types").TableStrategies | undefined;
|
|
25
|
+
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
9
26
|
};
|
|
10
|
-
|
|
11
|
-
|
|
27
|
+
/** @deprecated Use `presets.glide` */
|
|
28
|
+
Glide: {
|
|
29
|
+
Strategies: import("../types").TableStrategies | undefined;
|
|
30
|
+
headerSelector?: string | ((root: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
31
|
+
rowSelector?: string | undefined;
|
|
32
|
+
cellSelector?: string | ((row: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
33
|
+
maxPages?: number | undefined;
|
|
34
|
+
headerTransformer?: ((args: {
|
|
35
|
+
text: string;
|
|
36
|
+
index: number;
|
|
37
|
+
locator: import("playwright-core").Locator;
|
|
38
|
+
seenHeaders: Set<string>;
|
|
39
|
+
}) => string | Promise<string>) | undefined;
|
|
40
|
+
autoScroll?: boolean | undefined;
|
|
41
|
+
debug?: import("..").DebugConfig | undefined;
|
|
42
|
+
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
43
|
+
strategies?: import("../types").TableStrategies | undefined;
|
|
44
|
+
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
12
45
|
};
|
|
13
|
-
|
|
14
|
-
|
|
46
|
+
/** @deprecated Use `presets.muiDataGrid` */
|
|
47
|
+
MUI: {
|
|
48
|
+
Strategies: import("../types").TableStrategies | undefined;
|
|
49
|
+
headerSelector?: string | ((root: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
50
|
+
rowSelector?: string | undefined;
|
|
51
|
+
cellSelector?: string | ((row: import("playwright-core").Locator) => import("playwright-core").Locator) | undefined;
|
|
52
|
+
maxPages?: number | undefined;
|
|
53
|
+
headerTransformer?: ((args: {
|
|
54
|
+
text: string;
|
|
55
|
+
index: number;
|
|
56
|
+
locator: import("playwright-core").Locator;
|
|
57
|
+
seenHeaders: Set<string>;
|
|
58
|
+
}) => string | Promise<string>) | undefined;
|
|
59
|
+
autoScroll?: boolean | undefined;
|
|
60
|
+
debug?: import("..").DebugConfig | undefined;
|
|
61
|
+
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
62
|
+
strategies?: import("../types").TableStrategies | undefined;
|
|
63
|
+
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
15
64
|
};
|
|
16
65
|
};
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Plugins = void 0;
|
|
4
|
-
const
|
|
5
|
-
const glide_1 = require("./glide");
|
|
6
|
-
const mui_1 = require("./mui");
|
|
4
|
+
const presets_1 = require("../presets");
|
|
7
5
|
/**
|
|
6
|
+
* @deprecated Use `presets` instead. Plugins will be removed in v7.0.0.
|
|
8
7
|
* Presets for specific table/grid libraries. Each plugin exposes:
|
|
9
|
-
* - Plugins.X — full preset (selectors + headerTransformer if any + strategies). Spread: useTable(loc, { ...
|
|
10
|
-
* - Plugins.X.Strategies — strategies only. Use with your own selectors: useTable(loc, { rowSelector: '...', strategies:
|
|
8
|
+
* - Plugins.X — full preset (selectors + headerTransformer if any + strategies). Spread: useTable(loc, { ...Presets.MUI, maxPages: 5 }).
|
|
9
|
+
* - Plugins.X.Strategies — strategies only. Use with your own selectors: useTable(loc, { rowSelector: '...', strategies: Presets.MUI.Strategies }).
|
|
11
10
|
*/
|
|
12
11
|
exports.Plugins = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/** @deprecated Use `presets.rdg` */
|
|
13
|
+
RDG: Object.assign(Object.assign({}, presets_1.rdg), { Strategies: presets_1.rdg.strategies }),
|
|
14
|
+
/** @deprecated Use `presets.glide` */
|
|
15
|
+
Glide: Object.assign(Object.assign({}, presets_1.glide), { Strategies: presets_1.glide.strategies }),
|
|
16
|
+
/** @deprecated Use `presets.muiDataGrid` */
|
|
17
|
+
MUI: Object.assign(Object.assign({}, presets_1.muiDataGrid), { Strategies: presets_1.muiDataGrid.strategies }),
|
|
16
18
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.glide = exports.rdg = exports.muiDataGrid = exports.muiTable = void 0;
|
|
4
|
+
var mui_1 = require("./mui");
|
|
5
|
+
Object.defineProperty(exports, "muiTable", { enumerable: true, get: function () { return mui_1.muiTable; } });
|
|
6
|
+
Object.defineProperty(exports, "muiDataGrid", { enumerable: true, get: function () { return mui_1.muiDataGrid; } });
|
|
7
|
+
var rdg_1 = require("./rdg");
|
|
8
|
+
Object.defineProperty(exports, "rdg", { enumerable: true, get: function () { return rdg_1.RDG; } });
|
|
9
|
+
var glide_1 = require("./glide");
|
|
10
|
+
Object.defineProperty(exports, "glide", { enumerable: true, get: function () { return glide_1.Glide; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TableConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Preset configuration for the standard Material UI `<Table />` component.
|
|
4
|
+
*
|
|
5
|
+
* Handles:
|
|
6
|
+
* - Selectors for `.MuiTableRow-root`, `.MuiTableCell-head`, etc.
|
|
7
|
+
* - Pagination via the standard `.MuiTablePagination-actions` footer.
|
|
8
|
+
* - Sorting via the `.MuiTableSortLabel-root` header classes.
|
|
9
|
+
* - Virtualized DOM deduplication (falls back to cell text if unvirtualized).
|
|
10
|
+
*/
|
|
11
|
+
export declare const muiTable: Partial<TableConfig>;
|
|
12
|
+
/**
|
|
13
|
+
* Preset configuration for the MUI DataGrid component (@mui/x-data-grid).
|
|
14
|
+
*
|
|
15
|
+
* Handles:
|
|
16
|
+
* - Selectors for `.MuiDataGrid-row`, `.MuiDataGrid-cell`, and `.MuiDataGrid-columnHeader`.
|
|
17
|
+
* - Pagination via the `.MuiDataGrid-footerContainer` (handling React's async rendering).
|
|
18
|
+
* - Sorting via `aria-sort` on column headers.
|
|
19
|
+
* - Vertical Virtualization deduplication using `data-rowindex`.
|
|
20
|
+
* - Horizontal Virtualization support via `aria-colindex`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const muiDataGrid: Partial<TableConfig>;
|
|
@@ -0,0 +1,266 @@
|
|
|
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.muiDataGrid = exports.muiTable = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Safely wait for MUI pagination to stabilize.
|
|
15
|
+
* Polls for displayed row text changes and waits for loading overlays to disappear.
|
|
16
|
+
*/
|
|
17
|
+
function waitForMuiPaginationStabilization(context, displayedRows, oldText) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
let retries = 50; // 5 second timeout for client-side render
|
|
21
|
+
while (oldText && retries-- > 0 && (yield displayedRows.innerText().catch(() => '')) === oldText) {
|
|
22
|
+
yield context.page.waitForTimeout(100);
|
|
23
|
+
}
|
|
24
|
+
// Standard MUI loading strategy check
|
|
25
|
+
if ((_a = context.config.strategies.loading) === null || _a === void 0 ? void 0 : _a.isTableLoading) {
|
|
26
|
+
let loadingRetries = 30;
|
|
27
|
+
while (loadingRetries-- > 0 && (yield context.config.strategies.loading.isTableLoading(context))) {
|
|
28
|
+
yield context.page.waitForTimeout(100);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// DataGrid specific fallback (if not using loading strategy)
|
|
32
|
+
const overlay = context.root.locator('.MuiDataGrid-overlay');
|
|
33
|
+
if ((yield overlay.count()) > 0) {
|
|
34
|
+
let loadingRetries = 30;
|
|
35
|
+
while (loadingRetries-- > 0 && (yield overlay.isVisible().catch(() => false))) {
|
|
36
|
+
yield context.page.waitForTimeout(100);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** safely locate the pagination container related to our table context */
|
|
42
|
+
function getPaginationRoot(context) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
// 1. If the user initialized useTable on the layout wrapper itself
|
|
45
|
+
const inside = context.root.locator('.MuiTablePagination-root').first();
|
|
46
|
+
if ((yield inside.count()) > 0)
|
|
47
|
+
return inside;
|
|
48
|
+
// 2. If the user initialized on the Table, look up to the closest Paper wrapper
|
|
49
|
+
const paper = context.root.locator('xpath=ancestor::*[contains(@class, "MuiPaper-root")][1]').first();
|
|
50
|
+
if ((yield paper.count()) > 0) {
|
|
51
|
+
const inPaper = paper.locator('.MuiTablePagination-root').first();
|
|
52
|
+
if ((yield inPaper.count()) > 0)
|
|
53
|
+
return inPaper;
|
|
54
|
+
}
|
|
55
|
+
// 3. Fallback: find the first pagination footer that follows this context in the DOM
|
|
56
|
+
return context.root.locator('xpath=following::div[contains(@class, "MuiTablePagination-root")][1]').first();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Preset configuration for the standard Material UI `<Table />` component.
|
|
61
|
+
*
|
|
62
|
+
* Handles:
|
|
63
|
+
* - Selectors for `.MuiTableRow-root`, `.MuiTableCell-head`, etc.
|
|
64
|
+
* - Pagination via the standard `.MuiTablePagination-actions` footer.
|
|
65
|
+
* - Sorting via the `.MuiTableSortLabel-root` header classes.
|
|
66
|
+
* - Virtualized DOM deduplication (falls back to cell text if unvirtualized).
|
|
67
|
+
*/
|
|
68
|
+
exports.muiTable = {
|
|
69
|
+
rowSelector: 'tbody tr, tbody .MuiTableRow-root',
|
|
70
|
+
cellSelector: 'td, th, .MuiTableCell-body',
|
|
71
|
+
headerSelector: 'thead th, .MuiTableCell-head',
|
|
72
|
+
headerTransformer: ({ text }) => text.replace(/\s*sorted\s+(a|de)scending/i, '').trim(),
|
|
73
|
+
strategies: {
|
|
74
|
+
pagination: {
|
|
75
|
+
goNext: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const root = yield getPaginationRoot(context);
|
|
77
|
+
const nextBtn = root.locator('button[aria-label="Go to next page"]');
|
|
78
|
+
if ((yield nextBtn.count()) === 0 || (yield nextBtn.isDisabled()))
|
|
79
|
+
return false;
|
|
80
|
+
const displayedRows = root.locator('.MuiTablePagination-displayedRows');
|
|
81
|
+
const oldText = yield displayedRows.innerText().catch(() => '');
|
|
82
|
+
// Force click ignores cookie banners obscuring the footer
|
|
83
|
+
yield nextBtn.click({ force: true });
|
|
84
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, oldText);
|
|
85
|
+
return true;
|
|
86
|
+
}),
|
|
87
|
+
goPrevious: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const root = yield getPaginationRoot(context);
|
|
89
|
+
const prevBtn = root.locator('button[aria-label="Go to previous page"]');
|
|
90
|
+
if ((yield prevBtn.count()) === 0 || (yield prevBtn.isDisabled()))
|
|
91
|
+
return false;
|
|
92
|
+
const displayedRows = root.locator('.MuiTablePagination-displayedRows');
|
|
93
|
+
const oldText = yield displayedRows.innerText().catch(() => '');
|
|
94
|
+
yield prevBtn.click({ force: true });
|
|
95
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, oldText);
|
|
96
|
+
return true;
|
|
97
|
+
}),
|
|
98
|
+
goToFirst: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const root = yield getPaginationRoot(context);
|
|
100
|
+
const prevBtn = root.locator('button[aria-label="Go to previous page"]');
|
|
101
|
+
const displayedRows = root.locator('.MuiTablePagination-displayedRows');
|
|
102
|
+
let maxRetries = 50;
|
|
103
|
+
let clicked = false;
|
|
104
|
+
while (maxRetries-- > 0 && (yield prevBtn.count()) > 0 && !(yield prevBtn.isDisabled())) {
|
|
105
|
+
const oldText = yield displayedRows.innerText().catch(() => '');
|
|
106
|
+
yield prevBtn.click();
|
|
107
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, oldText);
|
|
108
|
+
clicked = true;
|
|
109
|
+
}
|
|
110
|
+
return clicked;
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
sorting: {
|
|
114
|
+
getSortState: (_a) => __awaiter(void 0, [_a], void 0, function* ({ columnName, context }) {
|
|
115
|
+
if (!context.getHeaderCell)
|
|
116
|
+
return 'none';
|
|
117
|
+
const header = yield context.getHeaderCell(columnName);
|
|
118
|
+
const sortLabel = header.locator('.MuiTableSortLabel-root').first();
|
|
119
|
+
if (!(yield sortLabel.isVisible().catch(() => false)))
|
|
120
|
+
return 'none';
|
|
121
|
+
const className = (yield sortLabel.getAttribute('class')) || '';
|
|
122
|
+
if (className.includes('directionAsc'))
|
|
123
|
+
return 'asc';
|
|
124
|
+
if (className.includes('directionDesc'))
|
|
125
|
+
return 'desc';
|
|
126
|
+
// Often, if the label is active but lacks explicit direction classes, MUI defaults to ascending
|
|
127
|
+
if (className.includes('active'))
|
|
128
|
+
return 'asc';
|
|
129
|
+
return 'none';
|
|
130
|
+
}),
|
|
131
|
+
doSort: (_a) => __awaiter(void 0, [_a], void 0, function* ({ columnName, direction, context }) {
|
|
132
|
+
var _b, _c;
|
|
133
|
+
if (!context.getHeaderCell)
|
|
134
|
+
return;
|
|
135
|
+
const header = yield context.getHeaderCell(columnName);
|
|
136
|
+
const sortLabel = header.locator('.MuiTableSortLabel-root').first();
|
|
137
|
+
const target = (yield sortLabel.isVisible().catch(() => false)) ? sortLabel : header;
|
|
138
|
+
let current = (yield ((_b = context.config.strategies.sorting) === null || _b === void 0 ? void 0 : _b.getSortState({ columnName, context }))) || 'none';
|
|
139
|
+
let attempts = 0;
|
|
140
|
+
// Click until the state matches the target direction, max 3 times (none -> asc -> desc)
|
|
141
|
+
while (current !== direction && attempts < 3) {
|
|
142
|
+
yield target.click();
|
|
143
|
+
yield context.page.waitForTimeout(100);
|
|
144
|
+
current = (yield ((_c = context.config.strategies.sorting) === null || _c === void 0 ? void 0 : _c.getSortState({ columnName, context }))) || 'none';
|
|
145
|
+
attempts++;
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
dedupe: (row) => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
// MUI virtualized tables attach data-index to rows
|
|
151
|
+
const dataIndex = yield row.getAttribute('data-index');
|
|
152
|
+
if (dataIndex !== null)
|
|
153
|
+
return dataIndex;
|
|
154
|
+
// Unvirtualized tables don't recycle nodes, but if they do duplicate, fallback to first cell's text
|
|
155
|
+
const text = yield row.locator('td, th').first().innerText().catch(() => '');
|
|
156
|
+
return text || String(Math.random());
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Preset configuration for the MUI DataGrid component (@mui/x-data-grid).
|
|
162
|
+
*
|
|
163
|
+
* Handles:
|
|
164
|
+
* - Selectors for `.MuiDataGrid-row`, `.MuiDataGrid-cell`, and `.MuiDataGrid-columnHeader`.
|
|
165
|
+
* - Pagination via the `.MuiDataGrid-footerContainer` (handling React's async rendering).
|
|
166
|
+
* - Sorting via `aria-sort` on column headers.
|
|
167
|
+
* - Vertical Virtualization deduplication using `data-rowindex`.
|
|
168
|
+
* - Horizontal Virtualization support via `aria-colindex`.
|
|
169
|
+
*/
|
|
170
|
+
exports.muiDataGrid = {
|
|
171
|
+
rowSelector: '.MuiDataGrid-row',
|
|
172
|
+
cellSelector: '.MuiDataGrid-cell',
|
|
173
|
+
headerSelector: '.MuiDataGrid-columnHeader',
|
|
174
|
+
strategies: {
|
|
175
|
+
pagination: {
|
|
176
|
+
goNext: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
const footer = context.root.locator('.MuiDataGrid-footerContainer');
|
|
178
|
+
const nextBtn = footer.locator('button[aria-label="Go to next page"]');
|
|
179
|
+
try {
|
|
180
|
+
yield nextBtn.waitFor({ state: 'visible', timeout: 2000 });
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
if (yield nextBtn.isDisabled())
|
|
186
|
+
return false;
|
|
187
|
+
const displayedRows = footer.locator('.MuiTablePagination-displayedRows');
|
|
188
|
+
const oldText = yield displayedRows.innerText().catch(() => '');
|
|
189
|
+
yield nextBtn.scrollIntoViewIfNeeded().catch(() => { });
|
|
190
|
+
yield nextBtn.click({ force: true });
|
|
191
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, oldText);
|
|
192
|
+
return true;
|
|
193
|
+
}),
|
|
194
|
+
goPrevious: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
|
+
const footer = context.root.locator('.MuiDataGrid-footerContainer');
|
|
196
|
+
const prevBtn = footer.locator('button[aria-label="Go to previous page"]');
|
|
197
|
+
try {
|
|
198
|
+
yield prevBtn.waitFor({ state: 'visible', timeout: 2000 });
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (yield prevBtn.isDisabled())
|
|
204
|
+
return false;
|
|
205
|
+
const displayedRows = footer.locator('.MuiTablePagination-displayedRows');
|
|
206
|
+
const oldText = yield displayedRows.innerText().catch(() => '');
|
|
207
|
+
yield prevBtn.scrollIntoViewIfNeeded().catch(() => { });
|
|
208
|
+
yield prevBtn.click({ force: true });
|
|
209
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, oldText);
|
|
210
|
+
return true;
|
|
211
|
+
})
|
|
212
|
+
},
|
|
213
|
+
sorting: {
|
|
214
|
+
getSortState: (_a) => __awaiter(void 0, [_a], void 0, function* ({ columnName, context }) {
|
|
215
|
+
if (!context.getHeaderCell)
|
|
216
|
+
return 'none';
|
|
217
|
+
const header = yield context.getHeaderCell(columnName);
|
|
218
|
+
const sortAttr = yield header.getAttribute('aria-sort');
|
|
219
|
+
if (sortAttr === 'ascending')
|
|
220
|
+
return 'asc';
|
|
221
|
+
if (sortAttr === 'descending')
|
|
222
|
+
return 'desc';
|
|
223
|
+
return 'none';
|
|
224
|
+
}),
|
|
225
|
+
doSort: (_a) => __awaiter(void 0, [_a], void 0, function* ({ columnName, direction, context }) {
|
|
226
|
+
var _b, _c;
|
|
227
|
+
if (!context.getHeaderCell)
|
|
228
|
+
return;
|
|
229
|
+
const header = yield context.getHeaderCell(columnName);
|
|
230
|
+
let current = (yield ((_b = context.config.strategies.sorting) === null || _b === void 0 ? void 0 : _b.getSortState({ columnName, context }))) || 'none';
|
|
231
|
+
let attempts = 0;
|
|
232
|
+
while (current !== direction && attempts < 3) {
|
|
233
|
+
const clickTarget = header.locator('.MuiDataGrid-columnHeaderTitleContainer').first();
|
|
234
|
+
if (yield clickTarget.isVisible()) {
|
|
235
|
+
yield clickTarget.click({ force: true });
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
yield header.click({ force: true });
|
|
239
|
+
}
|
|
240
|
+
// Sorting can trigger large re-renders/virtualization shifts
|
|
241
|
+
yield context.page.waitForTimeout(500);
|
|
242
|
+
// Wait for stabilization (using DataGrid specific overlay check inside helper)
|
|
243
|
+
const displayedRows = context.root.locator('.MuiTablePagination-displayedRows');
|
|
244
|
+
const text = yield displayedRows.innerText().catch(() => '');
|
|
245
|
+
yield waitForMuiPaginationStabilization(context, displayedRows, text);
|
|
246
|
+
current = (yield ((_c = context.config.strategies.sorting) === null || _c === void 0 ? void 0 : _c.getSortState({ columnName, context }))) || 'none';
|
|
247
|
+
attempts++;
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
},
|
|
251
|
+
dedupe: (row) => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
+
var _a;
|
|
253
|
+
// DataGrid uses data-rowindex for its own virtualization management
|
|
254
|
+
return (_a = (yield row.getAttribute('data-rowindex').catch(() => null))) !== null && _a !== void 0 ? _a : '';
|
|
255
|
+
}),
|
|
256
|
+
getCellLocator: ({ row, columnIndex }) => {
|
|
257
|
+
// Horizontal virtualization uses aria-colindex (1-indexed)
|
|
258
|
+
return row.locator(`[aria-colindex="${columnIndex + 1}"]`);
|
|
259
|
+
},
|
|
260
|
+
loading: {
|
|
261
|
+
isTableLoading: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
return yield context.root.locator('.MuiDataGrid-overlay').isVisible().catch(() => false);
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TableContext, TableConfig } from '
|
|
1
|
+
import { TableContext, TableConfig } from '../types';
|
|
2
2
|
/** Full strategies for React Data Grid. Use when you want to supply your own selectors: strategies: Plugins.RDG.Strategies */
|
|
3
3
|
export declare const RDGStrategies: {
|
|
4
4
|
header: (context: TableContext) => Promise<string[]>;
|
|
@@ -10,7 +10,7 @@ export declare const RDGStrategies: {
|
|
|
10
10
|
goUp: ({ root, page }: any) => Promise<void>;
|
|
11
11
|
goHome: ({ root, page }: any) => Promise<void>;
|
|
12
12
|
};
|
|
13
|
-
pagination: import("
|
|
13
|
+
pagination: import("../types").PaginationPrimitives;
|
|
14
14
|
};
|
|
15
15
|
export declare const RDG: Partial<TableConfig> & {
|
|
16
16
|
Strategies: typeof RDGStrategies;
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RDG = exports.RDGStrategies = void 0;
|
|
13
|
-
const pagination_1 = require("
|
|
14
|
-
const stabilization_1 = require("
|
|
13
|
+
const pagination_1 = require("../strategies/pagination");
|
|
14
|
+
const stabilization_1 = require("../strategies/stabilization");
|
|
15
15
|
/**
|
|
16
16
|
* Scrolls the grid horizontally to collect all column headers.
|
|
17
17
|
* Handles empty headers by labeling them (e.g. "Checkbox").
|
package/dist/smartRow.js
CHANGED
|
@@ -32,7 +32,7 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
32
32
|
});
|
|
33
33
|
// Optimization: Check if we are ALREADY at the target cell
|
|
34
34
|
if (activeCell && activeCell.rowIndex === rowIndex && activeCell.columnIndex === index) {
|
|
35
|
-
|
|
35
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', `_navigateToCell: Already at target cell {row: ${rowIndex}, col: ${index}}`);
|
|
36
36
|
return activeCell.locator;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -61,18 +61,22 @@ const _navigateToCell = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
61
61
|
// Navigate vertically
|
|
62
62
|
for (let i = 0; i < Math.abs(rowDiff); i++) {
|
|
63
63
|
if (rowDiff > 0 && nav.goDown) {
|
|
64
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving down');
|
|
64
65
|
yield nav.goDown(context);
|
|
65
66
|
}
|
|
66
67
|
else if (rowDiff < 0 && nav.goUp) {
|
|
68
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving up');
|
|
67
69
|
yield nav.goUp(context);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
// Navigate horizontally
|
|
71
73
|
for (let i = 0; i < Math.abs(colDiff); i++) {
|
|
72
74
|
if (colDiff > 0 && nav.goRight) {
|
|
75
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving right');
|
|
73
76
|
yield nav.goRight(context);
|
|
74
77
|
}
|
|
75
78
|
else if (colDiff < 0 && nav.goLeft) {
|
|
79
|
+
(0, debugUtils_1.logDebug)(config, 'verbose', '_navigateToCell: moving left');
|
|
76
80
|
yield nav.goLeft(context);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
@@ -10,4 +10,13 @@ export declare const HeaderStrategies: {
|
|
|
10
10
|
* This is fast but won't find virtualized columns off-screen.
|
|
11
11
|
*/
|
|
12
12
|
visible: ({ config, resolve, root }: StrategyContext) => Promise<string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Physically scrolls the table horizontally to force virtualized columns to mount,
|
|
15
|
+
* collecting their names along the way.
|
|
16
|
+
*/
|
|
17
|
+
horizontalScroll: (options?: {
|
|
18
|
+
limit?: number;
|
|
19
|
+
selector?: string;
|
|
20
|
+
scrollAmount?: number;
|
|
21
|
+
}) => HeaderStrategy;
|
|
13
22
|
};
|
|
@@ -26,5 +26,64 @@ exports.HeaderStrategies = {
|
|
|
26
26
|
}
|
|
27
27
|
const texts = yield headerLoc.allInnerTexts();
|
|
28
28
|
return texts.map(t => t.trim());
|
|
29
|
-
})
|
|
29
|
+
}),
|
|
30
|
+
/**
|
|
31
|
+
* Physically scrolls the table horizontally to force virtualized columns to mount,
|
|
32
|
+
* collecting their names along the way.
|
|
33
|
+
*/
|
|
34
|
+
horizontalScroll: (options) => {
|
|
35
|
+
return (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const { resolve, config, root, page } = context;
|
|
38
|
+
const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 20;
|
|
39
|
+
const scrollAmount = (_b = options === null || options === void 0 ? void 0 : options.scrollAmount) !== null && _b !== void 0 ? _b : 300;
|
|
40
|
+
const collectedHeaders = new Set();
|
|
41
|
+
const getVisible = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const headerLoc = resolve(config.headerSelector, root);
|
|
43
|
+
const texts = yield headerLoc.allInnerTexts();
|
|
44
|
+
return texts.map(t => t.trim());
|
|
45
|
+
});
|
|
46
|
+
let currentHeaders = yield getVisible();
|
|
47
|
+
currentHeaders.forEach(h => collectedHeaders.add(h));
|
|
48
|
+
const scrollerHandle = yield root.evaluateHandle((el, selector) => {
|
|
49
|
+
if (selector && el.matches(selector))
|
|
50
|
+
return el;
|
|
51
|
+
// Try finding common scrollable containers or fallback to root
|
|
52
|
+
const effectiveSelector = selector || '.dvn-scroller, .rdg-viewport, [role="grid"]';
|
|
53
|
+
const ancestor = el.closest(effectiveSelector);
|
|
54
|
+
if (ancestor)
|
|
55
|
+
return ancestor;
|
|
56
|
+
const child = el.querySelector(effectiveSelector);
|
|
57
|
+
if (child)
|
|
58
|
+
return child;
|
|
59
|
+
return el;
|
|
60
|
+
}, options === null || options === void 0 ? void 0 : options.selector);
|
|
61
|
+
const isScrollerFound = yield scrollerHandle.evaluate(el => !!el);
|
|
62
|
+
if (isScrollerFound) {
|
|
63
|
+
yield scrollerHandle.evaluate(el => el.scrollLeft = 0);
|
|
64
|
+
yield page.waitForTimeout(200);
|
|
65
|
+
for (let i = 0; i < limit; i++) {
|
|
66
|
+
const sizeBefore = collectedHeaders.size;
|
|
67
|
+
yield scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
|
|
68
|
+
yield page.waitForTimeout(300);
|
|
69
|
+
const newHeaders = yield getVisible();
|
|
70
|
+
newHeaders.forEach(h => collectedHeaders.add(h));
|
|
71
|
+
if (collectedHeaders.size === sizeBefore) {
|
|
72
|
+
yield scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
|
|
73
|
+
yield page.waitForTimeout(300);
|
|
74
|
+
const retryHeaders = yield getVisible();
|
|
75
|
+
retryHeaders.forEach(h => collectedHeaders.add(h));
|
|
76
|
+
if (collectedHeaders.size === sizeBefore)
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.warn("HeaderStrategies.horizontalScroll: Could not find scroller. Returning visible headers.");
|
|
83
|
+
}
|
|
84
|
+
yield scrollerHandle.evaluate(el => el.scrollLeft = 0);
|
|
85
|
+
yield page.waitForTimeout(200);
|
|
86
|
+
return Array.from(collectedHeaders);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
30
89
|
};
|
|
@@ -38,6 +38,11 @@ export declare const Strategies: {
|
|
|
38
38
|
};
|
|
39
39
|
Header: {
|
|
40
40
|
visible: ({ config, resolve, root }: import("..").StrategyContext) => Promise<string[]>;
|
|
41
|
+
horizontalScroll: (options?: {
|
|
42
|
+
limit?: number;
|
|
43
|
+
selector?: string;
|
|
44
|
+
scrollAmount?: number;
|
|
45
|
+
}) => import("./headers").HeaderStrategy;
|
|
41
46
|
};
|
|
42
47
|
Fill: {
|
|
43
48
|
default: ({ row, columnName, value, fillOptions, config, table }: Parameters<import("../types").FillStrategy>[0]) => Promise<void>;
|
package/dist/typeContext.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* This file is generated by scripts/embed-types.mjs
|
|
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 * 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. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /**\n * Jump to specific page index (0-indexed).\n * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6\u201314).\n * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.\n */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n\n /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */\n nextBulkPages?: number;\n\n /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */\n previousBulkPages?: number;\n}\n\nexport type PaginationStrategy = 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. Applied when using getRow/findRow/findRows with filters.\n * The default engine handles string, RegExp, number, and function (cell) => Locator filters.\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. Used after pagination/sort to wait for content.\n * E.g. isHeaderLoading for init stability; isTableLoading after sort/pagination.\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 * Strategy for filtering rows. If present, FilterEngine will delegate filter application\n * to this pluggable strategy.\n */\n filter?: FilterStrategy;\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 /**\n * Strategy for detecting loading states. Use this for table-, row-, and header-level readiness.\n * E.g. after sort/pagination, the engine uses loading.isTableLoading when present.\n */\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 | ((row: Locator) => Locator);\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 | ((row: Locator) => Locator);\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 * When true, use goNextBulk (if present) to advance pages during iteration.\n * @default false \u2014 uses goNext for one-page-at-a-time advancement\n */\n useBulkPagination?: boolean;\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 * @note The returned SmartRow may have `rowIndex` as 0 when the match is not the first row.\n * Use getRowByIndex(index) when you need a known index (e.g. for bringIntoView()).\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 0-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 0-based row index\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 (omit or pass {} for all rows)\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 generateConfig: () => Promise<void>;\n\n /**\n * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.\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. Returns number of pages skipped. */\n goNextBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Bulk skip backward multiple pages at once. Returns number of pages skipped. */\n goPreviousBulk?: (context: TableContext) => Promise<boolean | number>;\n\n /** Jump to first page / scroll to top */\n goToFirst?: (context: TableContext) => Promise<boolean>;\n\n /**\n * Jump to specific page index (0-indexed).\n * Can be full-range (e.g. page number input: any page works) or windowed (e.g. only visible links 6\u201314).\n * Return false when the page is not reachable in the current UI; the library will step toward the target (goNextBulk/goNext or goPreviousBulk/goPrevious) and retry goToPage until it succeeds.\n */\n goToPage?: (pageIndex: number, context: TableContext) => Promise<boolean>;\n\n /** How many pages one goNextBulk() advances. Used by navigation path planner for optimal bringIntoView. */\n nextBulkPages?: number;\n\n /** How many pages one goPreviousBulk() goes back. Used by navigation path planner for optimal bringIntoView. */\n previousBulkPages?: number;\n}\n\nexport type PaginationStrategy = 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 * `context` provides access to the parent row, permitting multi-cell logic or bypassing the default cell locator.\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. Applied when using getRow/findRow/findRows with filters.\n * The default engine handles string, RegExp, number, and function (cell) => Locator filters.\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. Used after pagination/sort to wait for content.\n * E.g. isHeaderLoading for init stability; isTableLoading after sort/pagination.\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 * Strategy for filtering rows. If present, FilterEngine will delegate filter application\n * to this pluggable strategy.\n */\n filter?: FilterStrategy;\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 /**\n * Strategy for detecting loading states. Use this for table-, row-, and header-level readiness.\n * E.g. after sort/pagination, the engine uses loading.isTableLoading when present.\n */\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 | ((row: Locator) => Locator);\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 | ((row: Locator) => Locator);\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 * When true, use goNextBulk (if present) to advance pages during iteration.\n * @default false \u2014 uses goNext for one-page-at-a-time advancement\n */\n useBulkPagination?: boolean;\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 * @note The returned SmartRow may have `rowIndex` as 0 when the match is not the first row.\n * Use getRowByIndex(index) when you need a known index (e.g. for bringIntoView()).\n */\n getRow: (\n filters: Record<string, FilterValue>,\n options?: { exact?: boolean }\n ) => SmartRow;\n\n /**\n * Gets a row by 0-based index on the current page.\n * Throws error if table is not initialized.\n * @param index 0-based row index\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 (omit or pass {} for all rows)\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 generateConfig: () => Promise<void>;\n\n /**\n * @deprecated Use `generateConfig()` instead. Will be removed in v7.0.0.\n */\n generateConfigPrompt: () => Promise<void>;\n}\n";
|
package/dist/typeContext.js
CHANGED
|
@@ -275,6 +275,7 @@ export type FillStrategy = (options: {
|
|
|
275
275
|
export interface ColumnOverride<TValue = any> {
|
|
276
276
|
/**
|
|
277
277
|
* How to extract the value from the cell.
|
|
278
|
+
* \`context\` provides access to the parent row, permitting multi-cell logic or bypassing the default cell locator.
|
|
278
279
|
*/
|
|
279
280
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
280
281
|
|
package/dist/types.d.ts
CHANGED
|
@@ -238,6 +238,7 @@ export type FillStrategy = (options: {
|
|
|
238
238
|
export interface ColumnOverride<TValue = any> {
|
|
239
239
|
/**
|
|
240
240
|
* How to extract the value from the cell.
|
|
241
|
+
* `context` provides access to the parent row, permitting multi-cell logic or bypassing the default cell locator.
|
|
241
242
|
*/
|
|
242
243
|
read?: (cell: Locator) => Promise<TValue> | TValue;
|
|
243
244
|
/**
|
package/dist/useTable.js
CHANGED
|
@@ -137,19 +137,31 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
137
137
|
const context = createStrategyContext();
|
|
138
138
|
const pagination = config.strategies.pagination;
|
|
139
139
|
let rawResult;
|
|
140
|
+
let primitive;
|
|
140
141
|
if (useBulk && (pagination === null || pagination === void 0 ? void 0 : pagination.goNextBulk)) {
|
|
142
|
+
primitive = 'goNextBulk';
|
|
141
143
|
rawResult = yield pagination.goNextBulk(context);
|
|
142
144
|
}
|
|
143
145
|
else if (pagination === null || pagination === void 0 ? void 0 : pagination.goNext) {
|
|
146
|
+
primitive = 'goNext';
|
|
144
147
|
rawResult = yield pagination.goNext(context);
|
|
145
148
|
}
|
|
146
149
|
else if (pagination === null || pagination === void 0 ? void 0 : pagination.goNextBulk) {
|
|
150
|
+
primitive = 'goNextBulk (fallback)';
|
|
147
151
|
rawResult = yield pagination.goNextBulk(context);
|
|
148
152
|
}
|
|
153
|
+
else {
|
|
154
|
+
log('_advancePage: no pagination primitive available — returning false');
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
149
157
|
const didAdvance = rawResult !== undefined && (0, validation_1.validatePaginationResult)(rawResult, 'Pagination Strategy');
|
|
150
158
|
const pagesJumped = typeof rawResult === 'number' ? rawResult : (didAdvance ? 1 : 0);
|
|
151
159
|
if (pagesJumped > 0) {
|
|
152
160
|
tableState.currentPageIndex += pagesJumped;
|
|
161
|
+
log(`_advancePage: ${primitive} advanced ${pagesJumped} page(s) — now at page ${tableState.currentPageIndex}`);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
log(`_advancePage: ${primitive} returned false — end of data`);
|
|
153
165
|
}
|
|
154
166
|
return didAdvance;
|
|
155
167
|
});
|
|
@@ -211,7 +223,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
211
223
|
getRow: (filters, options = { exact: false }) => {
|
|
212
224
|
const map = tableMapper.getMapSync();
|
|
213
225
|
if (!map)
|
|
214
|
-
throw new Error('
|
|
226
|
+
throw new Error('Initialization Error: You attempted to access a row before the table structure was mapped. Please call "await table.init()" once before using synchronous row access.');
|
|
215
227
|
const allRows = resolve(config.rowSelector, rootLocator);
|
|
216
228
|
const matchedRows = filterEngine.applyFilters(allRows, filters, map, options.exact || false, rootLocator.page(), rootLocator);
|
|
217
229
|
const rowLocator = matchedRows.first();
|
|
@@ -220,7 +232,7 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
220
232
|
getRowByIndex: (index) => {
|
|
221
233
|
const map = tableMapper.getMapSync();
|
|
222
234
|
if (!map)
|
|
223
|
-
throw new Error('
|
|
235
|
+
throw new Error('Initialization Error: You attempted to access a row before the table structure was mapped. Please call "await table.init()" once before using synchronous row access.');
|
|
224
236
|
const rowLocator = resolve(config.rowSelector, rootLocator).nth(index);
|
|
225
237
|
return _makeSmart(rowLocator, map, index);
|
|
226
238
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rickcedwhat/playwright-smart-table",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.8",
|
|
4
4
|
"description": "Smart, column-aware table interactions for Playwright",
|
|
5
5
|
"author": "Cedrick Catalan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,11 +29,28 @@
|
|
|
29
29
|
"test": "npm run test:unit && npx playwright test",
|
|
30
30
|
"test:unit": "vitest run --coverage --reporter=verbose --reporter=html",
|
|
31
31
|
"test:unit:ui": "vitest --ui",
|
|
32
|
+
"test:mutate": "npx stryker run",
|
|
32
33
|
"pretest:e2e": "npm run clean-port",
|
|
33
34
|
"posttest:e2e": "npm run clean-port",
|
|
34
35
|
"test:e2e": "npx playwright test",
|
|
36
|
+
"dev:playground": "cd playground && npm run dev",
|
|
37
|
+
"dev:mui": "cd tests/apps/mui-datagrid && npm run dev",
|
|
35
38
|
"prepare": "husky install"
|
|
36
39
|
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./presets": {
|
|
46
|
+
"types": "./dist/presets/index.d.ts",
|
|
47
|
+
"default": "./dist/presets/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./presets/mui": {
|
|
50
|
+
"types": "./dist/presets/mui.d.ts",
|
|
51
|
+
"default": "./dist/presets/mui.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
37
54
|
"keywords": [
|
|
38
55
|
"playwright",
|
|
39
56
|
"testing",
|
|
@@ -44,14 +61,16 @@
|
|
|
44
61
|
"@playwright/test": "^1.40.0"
|
|
45
62
|
},
|
|
46
63
|
"devDependencies": {
|
|
47
|
-
"@playwright/test": "^1.
|
|
48
|
-
"@
|
|
49
|
-
"@vitest
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
64
|
+
"@playwright/test": "^1.58.2",
|
|
65
|
+
"@stryker-mutator/core": "^9.6.0",
|
|
66
|
+
"@stryker-mutator/vitest-runner": "^9.6.0",
|
|
67
|
+
"@types/node": "^25.3.5",
|
|
68
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
69
|
+
"@vitest/ui": "^4.1.0",
|
|
70
|
+
"happy-dom": "^20.8.3",
|
|
52
71
|
"husky": "^9.1.7",
|
|
53
72
|
"typescript": "^5.7.2",
|
|
54
73
|
"vitepress": "^1.6.4",
|
|
55
|
-
"vitest": "^4.0
|
|
74
|
+
"vitest": "^4.1.0"
|
|
56
75
|
}
|
|
57
76
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { TableConfig } from '../../types';
|
|
2
|
-
/** Full strategies for MUI Data Grid. Use when you want to supply your own selectors: strategies: Plugins.MUI.Strategies */
|
|
3
|
-
export declare const MUIStrategies: {
|
|
4
|
-
pagination: import("../../types").PaginationPrimitives;
|
|
5
|
-
};
|
|
6
|
-
export declare const MUI: Partial<TableConfig> & {
|
|
7
|
-
Strategies: typeof MUIStrategies;
|
|
8
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MUI = exports.MUIStrategies = void 0;
|
|
4
|
-
const pagination_1 = require("../../strategies/pagination");
|
|
5
|
-
/** Default strategies for the MUI preset (used when you spread Plugins.MUI). */
|
|
6
|
-
const MUIDefaultStrategies = {
|
|
7
|
-
pagination: pagination_1.PaginationStrategies.click({
|
|
8
|
-
next: (root) => root.getByRole('button', { name: 'Go to next page' }),
|
|
9
|
-
}),
|
|
10
|
-
};
|
|
11
|
-
/** Full strategies for MUI Data Grid. Use when you want to supply your own selectors: strategies: Plugins.MUI.Strategies */
|
|
12
|
-
exports.MUIStrategies = MUIDefaultStrategies;
|
|
13
|
-
/**
|
|
14
|
-
* Full preset for MUI Data Grid (selectors + headerTransformer + default strategies).
|
|
15
|
-
* Spread: useTable(loc, { ...Plugins.MUI, maxPages: 5 }).
|
|
16
|
-
* Strategies only: useTable(loc, { rowSelector: '...', strategies: Plugins.MUI.Strategies }).
|
|
17
|
-
*/
|
|
18
|
-
const MUIPreset = {
|
|
19
|
-
rowSelector: '.MuiDataGrid-row',
|
|
20
|
-
headerSelector: '.MuiDataGrid-columnHeader',
|
|
21
|
-
cellSelector: '.MuiDataGrid-cell',
|
|
22
|
-
headerTransformer: ({ text }) => (text.includes('__col_') ? 'Actions' : text),
|
|
23
|
-
strategies: MUIDefaultStrategies,
|
|
24
|
-
};
|
|
25
|
-
exports.MUI = Object.defineProperty(MUIPreset, 'Strategies', { get: () => exports.MUIStrategies, enumerable: false });
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|