@rickcedwhat/playwright-smart-table 6.25.0-next.c784f2c → 6.25.0-next.d8860d0
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/cellNavigation.d.ts +24 -0
- package/dist/engine/cellNavigation.js +329 -0
- package/dist/engine/countRows.d.ts +28 -0
- package/dist/engine/countRows.js +149 -0
- package/dist/engine/rowByIndex.d.ts +20 -0
- package/dist/engine/rowByIndex.js +79 -0
- package/dist/engine/rowFinder.d.ts +3 -1
- package/dist/engine/rowFinder.js +5 -7
- package/dist/engine/rowResolution.d.ts +2 -2
- package/dist/engine/rowResolution.js +11 -7
- package/dist/engine/rowSnapshot.d.ts +28 -0
- package/dist/engine/rowSnapshot.js +422 -0
- package/dist/engine/scanPages.d.ts +7 -2
- package/dist/engine/scanPages.js +11 -0
- package/dist/engine/sorting.d.ts +11 -0
- package/dist/engine/sorting.js +51 -0
- package/dist/engine/tableIteration.js +1 -0
- package/dist/engine/tableMapper.js +16 -5
- package/dist/index.d.ts +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/smartRow.js +12 -692
- package/dist/strategies/columns.d.ts +1 -1
- package/dist/strategies/contentReady.d.ts +19 -1
- package/dist/strategies/contentReady.js +81 -0
- package/dist/strategies/dedupe.d.ts +5 -2
- package/dist/strategies/dedupe.js +5 -2
- package/dist/strategies/index.d.ts +5 -0
- package/dist/types.d.ts +36 -8
- package/dist/useTable.js +41 -289
- package/dist/utils/deadline.d.ts +2 -0
- package/dist/utils/deadline.js +19 -0
- package/dist/utils/memoizeViewport.d.ts +6 -0
- package/dist/utils/memoizeViewport.js +28 -0
- package/dist/utils/navigationBarrier.js +0 -1
- package/dist/utils/safeStringify.d.ts +2 -0
- package/dist/utils/safeStringify.js +18 -0
- package/dist/utils/smartRowArray.d.ts +1 -1
- package/dist/utils/smartRowArray.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySort = applySort;
|
|
4
|
+
exports.getSortState = getSortState;
|
|
5
|
+
const debugUtils_1 = require("../utils/debugUtils");
|
|
6
|
+
const loadingWait_1 = require("../utils/loadingWait");
|
|
7
|
+
const MAX_SORT_ATTEMPTS = 3;
|
|
8
|
+
function requireSorting(config) {
|
|
9
|
+
if (!config.strategies.sorting)
|
|
10
|
+
throw new Error('No sorting strategy has been configured.');
|
|
11
|
+
return config.strategies.sorting;
|
|
12
|
+
}
|
|
13
|
+
/** Waits for the table to settle after `doSort`: `isTableLoading` when configured, otherwise a fixed delay. */
|
|
14
|
+
async function waitForSortToSettle(env, context) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const loading = env.config.strategies.loading;
|
|
17
|
+
if (loading === null || loading === void 0 ? void 0 : loading.isTableLoading) {
|
|
18
|
+
const timeout = (_b = (_a = loading.sortStabilizationTimeout) !== null && _a !== void 0 ? _a : loading.loadingTimeout) !== null && _b !== void 0 ? _b : 10000;
|
|
19
|
+
const pollInterval = (_c = loading.sortStabilizationPollInterval) !== null && _c !== void 0 ? _c : 100;
|
|
20
|
+
await (0, loadingWait_1.waitWhileTableLoading)(env.config, context, env.getPage(), 'sorting.apply', { timeout, pollInterval });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await env.getPage().waitForTimeout((_d = loading === null || loading === void 0 ? void 0 : loading.sortStabilizationFallbackDelay) !== null && _d !== void 0 ? _d : 200);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Drives the sorting strategy until `columnName` reports `direction`, retrying up to 3 times. */
|
|
27
|
+
async function applySort(env, columnName, direction) {
|
|
28
|
+
const sorting = requireSorting(env.config);
|
|
29
|
+
(0, debugUtils_1.logDebug)(env.config, 'verbose', `Applying sort for column "${columnName}" (${direction})`);
|
|
30
|
+
const context = env.getContext();
|
|
31
|
+
for (let i = 0; i < MAX_SORT_ATTEMPTS; i++) {
|
|
32
|
+
const currentState = await sorting.getSortState({ columnName, context });
|
|
33
|
+
if (currentState === direction) {
|
|
34
|
+
(0, debugUtils_1.logDebug)(env.config, 'verbose', `Sort for "${columnName}" is already "${direction}".`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await sorting.doSort({ columnName, direction, context });
|
|
38
|
+
await waitForSortToSettle(env, context);
|
|
39
|
+
await (0, debugUtils_1.debugDelay)(env.config, 'default');
|
|
40
|
+
const newState = await sorting.getSortState({ columnName, context });
|
|
41
|
+
if (newState === direction) {
|
|
42
|
+
(0, debugUtils_1.logDebug)(env.config, 'verbose', `Successfully sorted "${columnName}" to "${direction}".`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Failed to sort column "${columnName}" to "${direction}" after ${MAX_SORT_ATTEMPTS} attempts.`);
|
|
47
|
+
}
|
|
48
|
+
async function getSortState(env, columnName) {
|
|
49
|
+
const sorting = requireSorting(env.config);
|
|
50
|
+
return sorting.getSortState({ columnName, context: env.getContext() });
|
|
51
|
+
}
|
|
@@ -196,6 +196,7 @@ async function runMap(env, callback, options = {}, label = 'map') {
|
|
|
196
196
|
useBulk,
|
|
197
197
|
label,
|
|
198
198
|
finalScanOnEof: true,
|
|
199
|
+
signal: options.signal,
|
|
199
200
|
});
|
|
200
201
|
log(env.config, `${label}: complete — ${results.length} result(s) across ${pagesScanned} page(s)`);
|
|
201
202
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TableMapper = void 0;
|
|
4
4
|
const headers_1 = require("../strategies/headers");
|
|
5
5
|
const debugUtils_1 = require("../utils/debugUtils");
|
|
6
|
+
const deadline_1 = require("../utils/deadline");
|
|
6
7
|
class TableMapper {
|
|
7
8
|
constructor(rootLocator, config, resolve) {
|
|
8
9
|
this._headerMap = null;
|
|
@@ -21,9 +22,11 @@ class TableMapper {
|
|
|
21
22
|
this.log('Mapping headers...');
|
|
22
23
|
const headerTimeout = timeout !== null && timeout !== void 0 ? timeout : 3000;
|
|
23
24
|
const startTime = Date.now();
|
|
25
|
+
const deadline = startTime + headerTimeout;
|
|
26
|
+
const remaining = () => Math.max(0, deadline - Date.now());
|
|
24
27
|
if (this.config.autoScroll) {
|
|
25
28
|
try {
|
|
26
|
-
await this.rootLocator.scrollIntoViewIfNeeded({ timeout: 1000 });
|
|
29
|
+
await (0, deadline_1.withinDeadline)(() => this.rootLocator.scrollIntoViewIfNeeded({ timeout: Math.max(1, Math.min(1000, remaining())) }), deadline, undefined);
|
|
27
30
|
}
|
|
28
31
|
catch (e) { }
|
|
29
32
|
}
|
|
@@ -39,22 +42,29 @@ class TableMapper {
|
|
|
39
42
|
while (Date.now() - startTime < headerTimeout) {
|
|
40
43
|
// 1. Wait for visibility
|
|
41
44
|
try {
|
|
42
|
-
await headerLoc.first().waitFor({ state: 'visible', timeout: 200 });
|
|
45
|
+
await (0, deadline_1.withinDeadline)(() => headerLoc.first().waitFor({ state: 'visible', timeout: Math.max(1, Math.min(200, remaining())) }), deadline, undefined);
|
|
43
46
|
}
|
|
44
47
|
catch (e) {
|
|
45
48
|
// Continue to check existing/loading state even if not strictly "visible" yet
|
|
46
49
|
}
|
|
50
|
+
if (remaining() <= 0)
|
|
51
|
+
break;
|
|
47
52
|
// 2. Check Smart Loading State
|
|
48
53
|
if ((_a = this.config.strategies.loading) === null || _a === void 0 ? void 0 : _a.isHeaderLoading) {
|
|
49
|
-
const isStable = !(await this.config.strategies.loading.isHeaderLoading(context));
|
|
54
|
+
const isStable = !(await (0, deadline_1.withinDeadline)(() => this.config.strategies.loading.isHeaderLoading(context), deadline, true));
|
|
50
55
|
if (!isStable) {
|
|
51
56
|
this.log('Headers are loading/unstable... waiting');
|
|
52
|
-
|
|
57
|
+
if (remaining() > 0)
|
|
58
|
+
await new Promise(r => setTimeout(r, Math.min(100, remaining())));
|
|
53
59
|
continue;
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
// 3. Attempt Scan
|
|
63
|
+
if (remaining() <= 0)
|
|
64
|
+
break;
|
|
57
65
|
try {
|
|
66
|
+
// Preserve long-running discovery strategies (e.g. horizontal header scans).
|
|
67
|
+
// The deadline bounds readiness and retries, not a strategy's own operation.
|
|
58
68
|
const rawHeaders = await strategy(context);
|
|
59
69
|
const entries = await this.processHeaders(rawHeaders);
|
|
60
70
|
// Success — validate before caching so a collision doesn't leave stale state
|
|
@@ -72,7 +82,8 @@ class TableMapper {
|
|
|
72
82
|
catch (e) {
|
|
73
83
|
lastError = e;
|
|
74
84
|
this.log(`Header mapping failed. Attempt ${Math.floor((Date.now() - startTime) / 100)}: ${e.message}`);
|
|
75
|
-
|
|
85
|
+
if (remaining() > 0)
|
|
86
|
+
await new Promise(r => setTimeout(r, Math.min(100, remaining())));
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
throw lastError || new Error(`Timed out waiting for headers after ${headerTimeout}ms`);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PLAYWRIGHT_SMART_TABLE_VERSION } from './packageVersion';
|
|
2
2
|
export { useTable } from './useTable';
|
|
3
|
-
export type { TableConfig, TableResult, SmartRow, SmartCell, Selector, TableSelector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, TableContext, StrategyContext, BeforeCellReadFn, GetCellLocatorFn, GetActiveCellFn, DebugConfig, SyntheticColumnDef, ColumnOverride, ColumnOverrideReadContext, TableStrategies, LoadingStrategy, ViewportStrategy, FilterStrategy, NavigationPrimitives, DedupeStrategy, ContentReadyStrategy, FillStrategy, PaginationStrategy, HeaderStrategy, } from './types';
|
|
3
|
+
export type { TableConfig, TableResult, SmartRow, SmartCell, Selector, TableSelector, FilterValue, PaginationPrimitives, SortingStrategy, FillOptions, RowIterationContext, RowIterationOptions, TableContext, StrategyContext, BeforeCellReadFn, GetCellLocatorFn, GetActiveCellFn, DebugConfig, SyntheticColumnDef, ColumnOverride, ColumnOverrideReadContext, TableStrategies, LoadingStrategy, ViewportStrategy, FilterStrategy, NavigationPrimitives, DedupeStrategy, ContentReadyStrategy, RowReadyPredicate, FillStrategy, PaginationStrategy, HeaderStrategy, } from './types';
|
|
4
4
|
export { Strategies } from './strategies';
|
|
5
5
|
export * as presets from './presets';
|
|
6
6
|
/**
|
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.25.0-next.
|
|
6
|
+
export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.25.0-next.d8860d0";
|
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.25.0-next.
|
|
9
|
+
exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.25.0-next.d8860d0";
|