@rickcedwhat/playwright-smart-table 6.17.1 → 6.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine/rowFinder.d.ts +10 -0
- package/dist/engine/rowFinder.js +40 -61
- package/dist/engine/rowResolution.d.ts +28 -0
- package/dist/engine/rowResolution.js +73 -0
- package/dist/engine/tableIteration.d.ts +3 -1
- package/dist/engine/tableIteration.js +53 -13
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/plugins/index.d.ts +3 -0
- package/dist/presets/mui.js +25 -0
- package/dist/smartRow.js +172 -11
- package/dist/strategies/fill.js +5 -1
- package/dist/strategies/viewport.js +46 -3
- package/dist/typeContext.d.ts +1 -1
- package/dist/typeContext.js +117 -13
- package/dist/types.d.ts +110 -11
- package/dist/useTable.js +117 -8
- package/package.json +16 -6
|
@@ -27,4 +27,14 @@ export declare class RowFinder<T = any> {
|
|
|
27
27
|
}): Promise<SmartRowArray<T>>;
|
|
28
28
|
private findRowLocator;
|
|
29
29
|
private resolveRowIndex;
|
|
30
|
+
/**
|
|
31
|
+
* Fallback for findRow when no resolveRowIndex strategy is configured: find the row's
|
|
32
|
+
* position in the current DOM order in a SINGLE roundtrip. Previously this looped over
|
|
33
|
+
* every row calling elementHandle() + evaluate() per row (O(n) CDP roundtrips, and
|
|
34
|
+
* elementHandle() is soft-deprecated). We resolve the target once and let evaluateAll
|
|
35
|
+
* compare it against the full row set in the browser. The row set is resolved through the
|
|
36
|
+
* same selector/scope as everywhere else, so a string, function, or Locator rowSelector
|
|
37
|
+
* all behave identically. (#350)
|
|
38
|
+
*/
|
|
39
|
+
private scanDomPosition;
|
|
30
40
|
}
|
package/dist/engine/rowFinder.js
CHANGED
|
@@ -6,6 +6,7 @@ const smartRowArray_1 = require("../utils/smartRowArray");
|
|
|
6
6
|
const elementTracker_1 = require("../utils/elementTracker");
|
|
7
7
|
const sentinel_1 = require("../utils/sentinel");
|
|
8
8
|
const navigationBarrier_1 = require("../utils/navigationBarrier");
|
|
9
|
+
const rowResolution_1 = require("./rowResolution");
|
|
9
10
|
class RowFinder {
|
|
10
11
|
constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }, advancePage = async () => false) {
|
|
11
12
|
this.rootLocator = rootLocator;
|
|
@@ -47,7 +48,7 @@ class RowFinder {
|
|
|
47
48
|
const tracker = new elementTracker_1.ElementTracker('findRows');
|
|
48
49
|
try {
|
|
49
50
|
const collectMatches = async () => {
|
|
50
|
-
var _a, _b
|
|
51
|
+
var _a, _b;
|
|
51
52
|
let rowLocators = this.resolve(this.config.rowSelector, this.rootLocator);
|
|
52
53
|
// Only apply filters if we have them
|
|
53
54
|
if (Object.keys(filtersRecord).length > 0) {
|
|
@@ -56,56 +57,22 @@ class RowFinder {
|
|
|
56
57
|
// Get only newly seen matched rows
|
|
57
58
|
const newIndices = await tracker.getUnseenIndices(rowLocators);
|
|
58
59
|
const currentRows = await rowLocators.all();
|
|
59
|
-
const isRowLoading = (_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.isRowLoading;
|
|
60
|
-
const rawRowTimeout = (_c = this.config.strategies.loading) === null || _c === void 0 ? void 0 : _c.rowLoadingTimeout;
|
|
61
|
-
// undefined = unset (legacy skip); 0 = no wait (immediate check); >0 = wait up to N ms
|
|
62
|
-
// Non-finite values are treated as unset (defensive guard against Infinity/NaN)
|
|
63
|
-
const rowLoadingTimeout = rawRowTimeout !== undefined && Number.isFinite(rawRowTimeout) && rawRowTimeout >= 0
|
|
64
|
-
? rawRowTimeout
|
|
65
|
-
: undefined;
|
|
66
|
-
const onRowLoadingTimeout = (_e = (_d = this.config.strategies.loading) === null || _d === void 0 ? void 0 : _d.onRowLoadingTimeout) !== null && _e !== void 0 ? _e : 'read-as-is';
|
|
67
60
|
let added = 0;
|
|
68
61
|
// One barrier per batch — synchronizes cell navigation across all rows in this page's results
|
|
69
62
|
const useBarrier = this.config.concurrency === 'synchronized' && newIndices.length > 1;
|
|
70
63
|
const barrier = useBarrier ? new navigationBarrier_1.NavigationBarrier(newIndices.length) : undefined;
|
|
71
64
|
for (const idx of newIndices) {
|
|
72
|
-
|
|
73
|
-
// Without a strategy, fall back to sequential position to avoid the O(n)
|
|
74
|
-
// elementHandle scan that resolveRowIndex() would otherwise perform per row.
|
|
75
|
-
const rowIndex = this.config.strategies.resolveRowIndex
|
|
76
|
-
? ((_f = await this.config.strategies.resolveRowIndex(currentRows[idx])) !== null && _f !== void 0 ? _f : allRows.length)
|
|
77
|
-
: allRows.length;
|
|
65
|
+
const rowIndex = await (0, rowResolution_1.resolveLogicalRowIndex)(currentRows[idx], this.config, () => allRows.length);
|
|
78
66
|
const smartRow = this.makeSmartRow(currentRows[idx], map, rowIndex, this.tableState.currentPageIndex, barrier);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Wait up to rowLoadingTimeout ms (0 = one immediate re-check, no polling)
|
|
87
|
-
(0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: row ${allRows.length} — waiting up to ${rowLoadingTimeout}ms for row to load`);
|
|
88
|
-
const deadline = Date.now() + rowLoadingTimeout;
|
|
89
|
-
let resolved = !(await isRowLoading(smartRow)); // immediate check (handles timeout=0)
|
|
90
|
-
while (!resolved && Date.now() < deadline) {
|
|
91
|
-
await currentRows[idx].page().waitForTimeout(100);
|
|
92
|
-
resolved = !(await isRowLoading(smartRow));
|
|
93
|
-
}
|
|
94
|
-
if (!resolved) {
|
|
95
|
-
(0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: row ${allRows.length} — still loading after ${rowLoadingTimeout}ms, action: ${onRowLoadingTimeout}`);
|
|
96
|
-
if (onRowLoadingTimeout === 'skip') {
|
|
97
|
-
barrier === null || barrier === void 0 ? void 0 : barrier.markFinished();
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (onRowLoadingTimeout === 'throw') {
|
|
101
|
-
barrier === null || barrier === void 0 ? void 0 : barrier.markFinished();
|
|
102
|
-
throw new Error(`[SmartTable] Row ${allRows.length} did not finish loading within ${rowLoadingTimeout}ms`);
|
|
103
|
-
}
|
|
104
|
-
// 'read-as-is': fall through and add the row
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
(0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: row ${allRows.length} — finished loading`);
|
|
67
|
+
// findRows skips a still-loading row when no timeout is configured (legacy
|
|
68
|
+
// behavior) — see resolveRowLoading's `noTimeoutAction: 'skip'`.
|
|
69
|
+
const loadingOutcome = await (0, rowResolution_1.resolveRowLoading)(smartRow, this.config.strategies.loading, 'skip', (msg) => (0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: ${msg}`));
|
|
70
|
+
if (loadingOutcome !== 'process') {
|
|
71
|
+
barrier === null || barrier === void 0 ? void 0 : barrier.markFinished();
|
|
72
|
+
if (loadingOutcome === 'throw') {
|
|
73
|
+
throw new Error(`[SmartTable] Row ${allRows.length} did not finish loading within ${(_b = this.config.strategies.loading) === null || _b === void 0 ? void 0 : _b.rowLoadingTimeout}ms`);
|
|
108
74
|
}
|
|
75
|
+
continue; // 'skip'
|
|
109
76
|
}
|
|
110
77
|
allRows.push(smartRow);
|
|
111
78
|
added++;
|
|
@@ -116,7 +83,11 @@ class RowFinder {
|
|
|
116
83
|
await collectMatches();
|
|
117
84
|
// Pagination Loop
|
|
118
85
|
while (pagesScanned < effectiveMaxPages && this.config.strategies.pagination) {
|
|
119
|
-
|
|
86
|
+
// Default to single-step goNext; bulk is opt-in via useBulkPagination: true (#349).
|
|
87
|
+
// Bulk-by-default made findRows jump N pages per advance and silently skip the
|
|
88
|
+
// rows on intermediate pages. When only a bulk primitive exists, _advancePage
|
|
89
|
+
// still falls back to it.
|
|
90
|
+
const useBulk = (options === null || options === void 0 ? void 0 : options.useBulkPagination) === true && !!((_c = this.config.strategies.pagination) === null || _c === void 0 ? void 0 : _c.goNextBulk);
|
|
120
91
|
const prevPage = this.tableState.currentPageIndex;
|
|
121
92
|
const didPaginate = await this.advancePage(useBulk);
|
|
122
93
|
if (!didPaginate) {
|
|
@@ -180,7 +151,9 @@ class RowFinder {
|
|
|
180
151
|
return matchedRows.first();
|
|
181
152
|
if (pagesScanned < effectiveMaxPages) {
|
|
182
153
|
(0, debugUtils_1.logDebug)(this.config, 'verbose', `Page ${this.tableState.currentPageIndex}: Not found. Attempting pagination...`);
|
|
183
|
-
|
|
154
|
+
// Default to single-step goNext; bulk is opt-in via useBulkPagination: true (#349).
|
|
155
|
+
// Bulk-by-default made findRow jump past the page holding the target row.
|
|
156
|
+
const useBulk = options.useBulkPagination === true && !!((_c = this.config.strategies.pagination) === null || _c === void 0 ? void 0 : _c.goNextBulk);
|
|
184
157
|
const prevPage = this.tableState.currentPageIndex;
|
|
185
158
|
const didLoadMore = await this.advancePage(useBulk);
|
|
186
159
|
if (didLoadMore) {
|
|
@@ -197,25 +170,31 @@ class RowFinder {
|
|
|
197
170
|
return null;
|
|
198
171
|
}
|
|
199
172
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
173
|
+
resolveRowIndex(rowLocator) {
|
|
174
|
+
// Shared resolver: resolveRowIndex strategy first, else the DOM-position fallback.
|
|
175
|
+
return (0, rowResolution_1.resolveLogicalRowIndex)(rowLocator, this.config, () => this.scanDomPosition(rowLocator));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Fallback for findRow when no resolveRowIndex strategy is configured: find the row's
|
|
179
|
+
* position in the current DOM order in a SINGLE roundtrip. Previously this looped over
|
|
180
|
+
* every row calling elementHandle() + evaluate() per row (O(n) CDP roundtrips, and
|
|
181
|
+
* elementHandle() is soft-deprecated). We resolve the target once and let evaluateAll
|
|
182
|
+
* compare it against the full row set in the browser. The row set is resolved through the
|
|
183
|
+
* same selector/scope as everywhere else, so a string, function, or Locator rowSelector
|
|
184
|
+
* all behave identically. (#350)
|
|
185
|
+
*/
|
|
186
|
+
async scanDomPosition(rowLocator) {
|
|
209
187
|
const targetHandle = await rowLocator.elementHandle();
|
|
210
188
|
if (!targetHandle)
|
|
211
189
|
return undefined;
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
190
|
+
try {
|
|
191
|
+
const rowsLocator = this.resolve(this.config.rowSelector, this.rootLocator);
|
|
192
|
+
const index = await rowsLocator.evaluateAll((rows, target) => rows.indexOf(target), targetHandle);
|
|
193
|
+
return index >= 0 ? index : undefined;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
await targetHandle.dispose();
|
|
217
197
|
}
|
|
218
|
-
return undefined;
|
|
219
198
|
}
|
|
220
199
|
}
|
|
221
200
|
exports.RowFinder = RowFinder;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Locator } from '@playwright/test';
|
|
2
|
+
import type { FinalTableConfig, LoadingStrategy, SmartRow } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Single source of truth for "what is this row's logical index?" (#362 consolidation).
|
|
5
|
+
*
|
|
6
|
+
* Uses the configured `resolveRowIndex` strategy when present (e.g. MUI's `data-rowindex`);
|
|
7
|
+
* otherwise, and when the strategy returns `undefined`, defers to the caller-provided
|
|
8
|
+
* `fallback` — a running counter for iteration/`findRows`, or a DOM-position scan for `findRow`.
|
|
9
|
+
*
|
|
10
|
+
* This replaces the three inline variants that previously answered the index question
|
|
11
|
+
* (findRow's private method, findRows' inline expression, and — later — map's counter).
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveLogicalRowIndex(row: Locator, config: Pick<FinalTableConfig, 'strategies'>, fallback: () => number | undefined | Promise<number | undefined>): Promise<number | undefined>;
|
|
14
|
+
/** What the caller should do with a row after checking its loading state. */
|
|
15
|
+
export type RowLoadingOutcome = 'process' | 'skip' | 'throw';
|
|
16
|
+
/**
|
|
17
|
+
* Single source of truth for the per-row loading wait (#362 consolidation).
|
|
18
|
+
*
|
|
19
|
+
* Collapses the two near-identical blocks in `findRows` (RowFinder) and `runMap`
|
|
20
|
+
* (tableIteration). The only real difference between the callers is the behavior when no
|
|
21
|
+
* `rowLoadingTimeout` is configured: `findRows` skips a still-loading row (`noTimeoutAction:
|
|
22
|
+
* 'skip'`), while `map`/`forEach`/`filter` process it as-is (`'process'`) — and map, in that
|
|
23
|
+
* case, never even probes `isRowLoading`. Both are preserved exactly.
|
|
24
|
+
*
|
|
25
|
+
* The helper never throws and never touches the navigation barrier; it returns a decision so
|
|
26
|
+
* each caller keeps its own barrier bookkeeping and error message.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveRowLoading(row: SmartRow, loading: LoadingStrategy | undefined, noTimeoutAction: 'skip' | 'process', log?: (msg: string) => void): Promise<RowLoadingOutcome>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLogicalRowIndex = resolveLogicalRowIndex;
|
|
4
|
+
exports.resolveRowLoading = resolveRowLoading;
|
|
5
|
+
/**
|
|
6
|
+
* Single source of truth for "what is this row's logical index?" (#362 consolidation).
|
|
7
|
+
*
|
|
8
|
+
* Uses the configured `resolveRowIndex` strategy when present (e.g. MUI's `data-rowindex`);
|
|
9
|
+
* otherwise, and when the strategy returns `undefined`, defers to the caller-provided
|
|
10
|
+
* `fallback` — a running counter for iteration/`findRows`, or a DOM-position scan for `findRow`.
|
|
11
|
+
*
|
|
12
|
+
* This replaces the three inline variants that previously answered the index question
|
|
13
|
+
* (findRow's private method, findRows' inline expression, and — later — map's counter).
|
|
14
|
+
*/
|
|
15
|
+
async function resolveLogicalRowIndex(row, config, fallback) {
|
|
16
|
+
const strategy = config.strategies.resolveRowIndex;
|
|
17
|
+
if (strategy) {
|
|
18
|
+
const resolved = await strategy(row);
|
|
19
|
+
if (resolved !== undefined)
|
|
20
|
+
return resolved;
|
|
21
|
+
// Strategy returned undefined — fall through to the caller's fallback.
|
|
22
|
+
}
|
|
23
|
+
return fallback();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Single source of truth for the per-row loading wait (#362 consolidation).
|
|
27
|
+
*
|
|
28
|
+
* Collapses the two near-identical blocks in `findRows` (RowFinder) and `runMap`
|
|
29
|
+
* (tableIteration). The only real difference between the callers is the behavior when no
|
|
30
|
+
* `rowLoadingTimeout` is configured: `findRows` skips a still-loading row (`noTimeoutAction:
|
|
31
|
+
* 'skip'`), while `map`/`forEach`/`filter` process it as-is (`'process'`) — and map, in that
|
|
32
|
+
* case, never even probes `isRowLoading`. Both are preserved exactly.
|
|
33
|
+
*
|
|
34
|
+
* The helper never throws and never touches the navigation barrier; it returns a decision so
|
|
35
|
+
* each caller keeps its own barrier bookkeeping and error message.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveRowLoading(row, loading, noTimeoutAction, log) {
|
|
38
|
+
var _a;
|
|
39
|
+
const isRowLoading = loading === null || loading === void 0 ? void 0 : loading.isRowLoading;
|
|
40
|
+
if (!isRowLoading)
|
|
41
|
+
return 'process';
|
|
42
|
+
const rawTimeout = loading === null || loading === void 0 ? void 0 : loading.rowLoadingTimeout;
|
|
43
|
+
// undefined = unset (legacy skip / process-as-is); 0 = one immediate re-check; >0 = poll up to N ms.
|
|
44
|
+
// Non-finite values are treated as unset (defensive guard against Infinity/NaN).
|
|
45
|
+
const timeout = rawTimeout !== undefined && Number.isFinite(rawTimeout) && rawTimeout >= 0
|
|
46
|
+
? rawTimeout
|
|
47
|
+
: undefined;
|
|
48
|
+
// map's fast path: with no timeout and a process-default, it never probes isRowLoading.
|
|
49
|
+
if (timeout === undefined && noTimeoutAction === 'process')
|
|
50
|
+
return 'process';
|
|
51
|
+
if (!(await isRowLoading(row)))
|
|
52
|
+
return 'process';
|
|
53
|
+
// Row is loading with no timeout configured → legacy skip (findRows).
|
|
54
|
+
if (timeout === undefined)
|
|
55
|
+
return 'skip';
|
|
56
|
+
log === null || log === void 0 ? void 0 : log(`row ${row.rowIndex} — waiting up to ${timeout}ms for row to load`);
|
|
57
|
+
const deadline = Date.now() + timeout;
|
|
58
|
+
let resolved = !(await isRowLoading(row)); // immediate check (handles timeout=0)
|
|
59
|
+
while (!resolved && Date.now() < deadline) {
|
|
60
|
+
// Page accessed lazily (only while actually polling), matching the pre-refactor code.
|
|
61
|
+
await row.page().waitForTimeout(100);
|
|
62
|
+
resolved = !(await isRowLoading(row));
|
|
63
|
+
}
|
|
64
|
+
if (resolved)
|
|
65
|
+
return 'process';
|
|
66
|
+
const onTimeout = (_a = loading === null || loading === void 0 ? void 0 : loading.onRowLoadingTimeout) !== null && _a !== void 0 ? _a : 'read-as-is';
|
|
67
|
+
log === null || log === void 0 ? void 0 : log(`row ${row.rowIndex} — still loading after ${timeout}ms, action: ${onTimeout}`);
|
|
68
|
+
if (onTimeout === 'skip')
|
|
69
|
+
return 'skip';
|
|
70
|
+
if (onTimeout === 'throw')
|
|
71
|
+
return 'throw';
|
|
72
|
+
return 'process'; // 'read-as-is'
|
|
73
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Locator, Page } from '@playwright/test';
|
|
2
|
-
import type { SmartRow, RowIterationContext, RowIterationOptions } from '../types';
|
|
2
|
+
import type { SmartRow, RowIterationContext, RowIterationOptions, TableContext } from '../types';
|
|
3
3
|
import type { FinalTableConfig } from '../types';
|
|
4
4
|
import type { SmartRowArray } from '../utils/smartRowArray';
|
|
5
5
|
import { NavigationBarrier } from '../utils/navigationBarrier';
|
|
@@ -12,6 +12,8 @@ export interface TableIterationEnv<T = any> {
|
|
|
12
12
|
config: FinalTableConfig<T>;
|
|
13
13
|
getPage: () => Page;
|
|
14
14
|
getCurrentPageIndex: () => number;
|
|
15
|
+
/** Builds a TableContext for strategy calls (e.g. the viewport visible-row oracle). */
|
|
16
|
+
getContext: () => TableContext;
|
|
15
17
|
}
|
|
16
18
|
/** Delegates to {@link runMap}; void results are discarded. */
|
|
17
19
|
export declare function runForEach<T>(env: TableIterationEnv<T>, callback: (ctx: RowIterationContext<T>) => void | Promise<void>, options?: RowIterationOptions): Promise<void>;
|
|
@@ -7,6 +7,7 @@ const elementTracker_1 = require("../utils/elementTracker");
|
|
|
7
7
|
const debugUtils_1 = require("../utils/debugUtils");
|
|
8
8
|
const navigationBarrier_1 = require("../utils/navigationBarrier");
|
|
9
9
|
const mutex_1 = require("../utils/mutex");
|
|
10
|
+
const rowResolution_1 = require("./rowResolution");
|
|
10
11
|
function log(config, msg) {
|
|
11
12
|
(0, debugUtils_1.logDebug)(config, 'verbose', msg);
|
|
12
13
|
}
|
|
@@ -20,7 +21,7 @@ async function runForEach(env, callback, options = {}) {
|
|
|
20
21
|
* Concurrency: `parallel` | `synchronized` | `sequential` (see RowIterationOptions).
|
|
21
22
|
*/
|
|
22
23
|
async function runMap(env, callback, options = {}, label = 'map') {
|
|
23
|
-
var _a, _b, _c, _d, _e;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
24
25
|
const map = env.getMap();
|
|
25
26
|
const effectiveMaxPages = (_a = options.maxPages) !== null && _a !== void 0 ? _a : env.config.maxPages;
|
|
26
27
|
const dedupeStrategy = (_b = options.dedupe) !== null && _b !== void 0 ? _b : env.config.strategies.dedupe;
|
|
@@ -52,12 +53,26 @@ async function runMap(env, callback, options = {}, label = 'map') {
|
|
|
52
53
|
const rowLocators = env.getRowLocators();
|
|
53
54
|
const allIndices = await tracker.peekUnseenIndices(rowLocators);
|
|
54
55
|
const pageRows = await rowLocators.all();
|
|
56
|
+
// A2 (#353 part 2 / #357): when the viewport can report which rows are within the visible
|
|
57
|
+
// bounds, drop overscan rows from collection. They are left uncommitted (still unseen), so
|
|
58
|
+
// they're picked up on a later page once scrolled into view — preventing overscan from
|
|
59
|
+
// being ingested (#353) or double-collected via node recycling (#357). No-op when no
|
|
60
|
+
// viewport reports visible rows.
|
|
61
|
+
let candidateIndices = allIndices;
|
|
62
|
+
const getVisibleRowIndices = (_f = env.config.strategies.viewport) === null || _f === void 0 ? void 0 : _f.getVisibleRowIndices;
|
|
63
|
+
if (getVisibleRowIndices) {
|
|
64
|
+
const visible = new Set(await getVisibleRowIndices(env.getContext()));
|
|
65
|
+
candidateIndices = allIndices.filter(idx => visible.has(idx));
|
|
66
|
+
if (candidateIndices.length !== allIndices.length) {
|
|
67
|
+
log(env.config, `${label}: viewport visible filter — ${candidateIndices.length}/${allIndices.length} row(s) in view`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
55
70
|
// In synchronized mode, overscan rows rendered beyond the visible viewport by virtual
|
|
56
71
|
// scrollers can be evicted when the horizontal barrier fires snapFirstColumnIntoView.
|
|
57
72
|
// Filter them out before committing so they stay unseen and are picked up on the next page.
|
|
58
73
|
const newIndices = concurrency === 'synchronized'
|
|
59
|
-
? (await Promise.all(
|
|
60
|
-
:
|
|
74
|
+
? (await Promise.all(candidateIndices.map(async (idx) => ({ idx, present: pageRows[idx] != null && (await pageRows[idx].count()) > 0 })))).filter(r => r.present).map(r => r.idx)
|
|
75
|
+
: candidateIndices;
|
|
61
76
|
await tracker.commitIndices(rowLocators, newIndices);
|
|
62
77
|
const batchSize = newIndices.length;
|
|
63
78
|
if (batchSize === 0) {
|
|
@@ -67,11 +82,36 @@ async function runMap(env, callback, options = {}, label = 'map') {
|
|
|
67
82
|
log(env.config, `${label}: scanning page ${pagesScanned} — ${batchSize} new row(s)`);
|
|
68
83
|
const barrier = useBarrier ? new navigationBarrier_1.NavigationBarrier(batchSize) : undefined;
|
|
69
84
|
const actionMutex = useMutex ? new mutex_1.Mutex() : null;
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
// `index` (ctx.index) is the enumeration counter — the order rows are visited,
|
|
86
|
+
// contiguous and monotonic. It drives the internal stop()/ordering logic.
|
|
87
|
+
const positionBase = rowIndex;
|
|
88
|
+
// B-hybrid (#362): the row's rowIndex is its logical/data-model index when a
|
|
89
|
+
// resolveRowIndex strategy is configured (so bringIntoView and position math are
|
|
90
|
+
// correct on virtualized tables); otherwise it equals the enumeration counter.
|
|
91
|
+
const smartRows = await Promise.all(newIndices.map(async (idx, i) => {
|
|
92
|
+
var _a;
|
|
93
|
+
const logicalIndex = (_a = await (0, rowResolution_1.resolveLogicalRowIndex)(pageRows[idx], env.config, () => positionBase + i)) !== null && _a !== void 0 ? _a : (positionBase + i);
|
|
94
|
+
const sr = env.makeSmartRow(pageRows[idx], map, logicalIndex, env.getCurrentPageIndex(), barrier);
|
|
95
|
+
// Mark as part of an iteration batch so toJSON's #366 re-pin uses rescan-only recovery
|
|
96
|
+
// (no scroll-back) — scrolling here would disrupt sibling rows' positional locators.
|
|
97
|
+
sr._inBatch = true;
|
|
98
|
+
return sr;
|
|
99
|
+
}));
|
|
100
|
+
// enumIndex = visit-order counter (ctx.index); row.rowIndex = logical (ctx.rowIndex).
|
|
101
|
+
const processRow = async (row, enumIndex) => {
|
|
102
|
+
var _a;
|
|
72
103
|
try {
|
|
73
|
-
if (stopped &&
|
|
104
|
+
if (stopped && enumIndex > stoppedIndex) {
|
|
105
|
+
return SKIP;
|
|
106
|
+
}
|
|
107
|
+
// Wait for the row to finish loading BEFORE evaluating its dedupe key (Bug #355).
|
|
108
|
+
// map/forEach/filter process a still-loading row when no timeout is set (unlike
|
|
109
|
+
// findRows, which skips) — see resolveRowLoading's `noTimeoutAction`.
|
|
110
|
+
const loadingOutcome = await (0, rowResolution_1.resolveRowLoading)(row, env.config.strategies.loading, 'process', (msg) => log(env.config, `${label}: ${msg}`));
|
|
111
|
+
if (loadingOutcome === 'skip')
|
|
74
112
|
return SKIP;
|
|
113
|
+
if (loadingOutcome === 'throw') {
|
|
114
|
+
throw new Error(`[SmartTable] Row ${row.rowIndex} did not finish loading within ${(_a = env.config.strategies.loading) === null || _a === void 0 ? void 0 : _a.rowLoadingTimeout}ms`);
|
|
75
115
|
}
|
|
76
116
|
if (dedupeKeys && dedupeStrategy) {
|
|
77
117
|
const key = await dedupeStrategy(row);
|
|
@@ -83,10 +123,10 @@ async function runMap(env, callback, options = {}, label = 'map') {
|
|
|
83
123
|
}
|
|
84
124
|
// Execute callback (optionally serialized via mutex)
|
|
85
125
|
const runCallback = async () => {
|
|
86
|
-
if (stopped &&
|
|
126
|
+
if (stopped && enumIndex > stoppedIndex)
|
|
87
127
|
return SKIP;
|
|
88
|
-
log(env.config, `${label}: processing row ${row.rowIndex}`);
|
|
89
|
-
return await callback({ row, index:
|
|
128
|
+
log(env.config, `${label}: processing row (index ${enumIndex}, rowIndex ${row.rowIndex})`);
|
|
129
|
+
return await callback({ row, index: enumIndex, rowIndex: row.rowIndex, pageIndex: env.getCurrentPageIndex(), stop: () => stop(enumIndex) });
|
|
90
130
|
};
|
|
91
131
|
if (actionMutex) {
|
|
92
132
|
return await actionMutex.run(runCallback);
|
|
@@ -102,16 +142,16 @@ async function runMap(env, callback, options = {}, label = 'map') {
|
|
|
102
142
|
};
|
|
103
143
|
const pageResults = [];
|
|
104
144
|
if (concurrency === 'sequential') {
|
|
105
|
-
for (
|
|
106
|
-
pageResults.push(await processRow(
|
|
145
|
+
for (let i = 0; i < smartRows.length; i++) {
|
|
146
|
+
pageResults.push(await processRow(smartRows[i], positionBase + i));
|
|
107
147
|
}
|
|
108
148
|
}
|
|
109
149
|
else {
|
|
110
|
-
const results = await Promise.all(smartRows.map(processRow));
|
|
150
|
+
const results = await Promise.all(smartRows.map((row, i) => processRow(row, positionBase + i)));
|
|
111
151
|
pageResults.push(...results);
|
|
112
152
|
}
|
|
113
153
|
for (let i = 0; i < pageResults.length; i++) {
|
|
114
|
-
if (
|
|
154
|
+
if (positionBase + i > stoppedIndex)
|
|
115
155
|
break;
|
|
116
156
|
const r = pageResults[i];
|
|
117
157
|
if (r !== SKIP)
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Generated by scripts/embed-version.mjs from package.json
|
|
4
4
|
*/
|
|
5
5
|
/** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
|
|
6
|
-
export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.
|
|
6
|
+
export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.19.0";
|
package/dist/packageVersion.js
CHANGED
|
@@ -6,4 +6,4 @@ exports.PLAYWRIGHT_SMART_TABLE_VERSION = void 0;
|
|
|
6
6
|
* Generated by scripts/embed-version.mjs from package.json
|
|
7
7
|
*/
|
|
8
8
|
/** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
|
|
9
|
-
exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.
|
|
9
|
+
exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.19.0";
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare const Plugins: {
|
|
|
24
24
|
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
25
25
|
strategies?: import("../types").TableStrategies | undefined;
|
|
26
26
|
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
27
|
+
emptyState?: import("@playwright/test").Locator | undefined;
|
|
27
28
|
};
|
|
28
29
|
/** @deprecated Use `presets.glide` */
|
|
29
30
|
Glide: {
|
|
@@ -44,6 +45,7 @@ export declare const Plugins: {
|
|
|
44
45
|
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
45
46
|
strategies?: import("../types").TableStrategies | undefined;
|
|
46
47
|
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
48
|
+
emptyState?: import("@playwright/test").Locator | undefined;
|
|
47
49
|
};
|
|
48
50
|
/** @deprecated Use `presets.muiDataGrid` */
|
|
49
51
|
MUI: {
|
|
@@ -64,5 +66,6 @@ export declare const Plugins: {
|
|
|
64
66
|
onReset?: ((context: import("..").TableContext) => Promise<void>) | undefined;
|
|
65
67
|
strategies?: import("../types").TableStrategies | undefined;
|
|
66
68
|
columnOverrides?: Partial<Record<string | number | symbol, import("../types").ColumnOverride<any>>> | undefined;
|
|
69
|
+
emptyState?: import("@playwright/test").Locator | undefined;
|
|
67
70
|
};
|
|
68
71
|
};
|
package/dist/presets/mui.js
CHANGED
|
@@ -353,6 +353,31 @@ function createMuiDataGrid(opts) {
|
|
|
353
353
|
return { first: Math.min(...indices), last: Math.max(...indices) };
|
|
354
354
|
}, rowSel);
|
|
355
355
|
},
|
|
356
|
+
// Geometry-based visible-row set for the iteration engine (A2, #353/#357). Returns
|
|
357
|
+
// the DOM positions of rows overlapping the virtualScroller's bounds so map/forEach
|
|
358
|
+
// skip the overscan rows MUI keeps mounted above/below the fold. The scroller is a
|
|
359
|
+
// descendant of root, so querySelector (not closest).
|
|
360
|
+
getVisibleRowIndices: async ({ root, config }) => {
|
|
361
|
+
const rowSel = config.rowSelector;
|
|
362
|
+
return root.evaluate((el, rowSel) => {
|
|
363
|
+
const scroller = el.querySelector('.MuiDataGrid-virtualScroller');
|
|
364
|
+
const rows = Array.from(el.querySelectorAll(rowSel));
|
|
365
|
+
const scrollerRect = scroller ? scroller.getBoundingClientRect() : null;
|
|
366
|
+
const visible = [];
|
|
367
|
+
rows.forEach((r, i) => {
|
|
368
|
+
if (!scrollerRect) {
|
|
369
|
+
visible.push(i);
|
|
370
|
+
return;
|
|
371
|
+
} // can't measure → keep all
|
|
372
|
+
const rect = r.getBoundingClientRect();
|
|
373
|
+
if (rect.height === 0)
|
|
374
|
+
return;
|
|
375
|
+
if (rect.bottom > scrollerRect.top && rect.top < scrollerRect.bottom)
|
|
376
|
+
visible.push(i);
|
|
377
|
+
});
|
|
378
|
+
return visible;
|
|
379
|
+
}, rowSel);
|
|
380
|
+
},
|
|
356
381
|
getVisibleColumnRange: async ({ root, config }) => {
|
|
357
382
|
const rowSel = config.rowSelector;
|
|
358
383
|
const cellSel = typeof config.cellSelector === 'string' ? config.cellSelector : '[aria-colindex]';
|