@rickcedwhat/playwright-smart-table 6.23.1-next.3ae8c6f → 6.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.23.1-next.3ae8c6f";
6
+ export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.23.1";
@@ -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.23.1-next.3ae8c6f";
9
+ exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.23.1";
@@ -1,8 +1,6 @@
1
1
  import { StrategyContext } from '../../types';
2
2
  /**
3
- * Glide header discovery. Same scroll loop as `HeaderStrategies.horizontalScroll`, but the
4
- * `.dvn-scroller` is a sibling of the canvas root rather than an ancestor/descendant, so the
5
- * lookup falls back to a document-wide search.
3
+ * Scans for headers by finding a scrollable container and setting scrollLeft.
6
4
  */
7
5
  export declare const scrollRightHeader: (context: StrategyContext, options?: {
8
6
  limit?: number;
@@ -1,24 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.scrollRightHeader = void 0;
4
- const headerScroll_1 = require("../../utils/headerScroll");
4
+ const debugUtils_1 = require("../../utils/debugUtils");
5
5
  /**
6
- * Glide header discovery. Same scroll loop as `HeaderStrategies.horizontalScroll`, but the
7
- * `.dvn-scroller` is a sibling of the canvas root rather than an ancestor/descendant, so the
8
- * lookup falls back to a document-wide search.
6
+ * Scans for headers by finding a scrollable container and setting scrollLeft.
9
7
  */
10
8
  const scrollRightHeader = async (context, options) => {
11
- const findScroller = () => context.root.evaluateHandle((el, selector) => {
12
- var _a;
9
+ var _a, _b;
10
+ const { resolve, config, root, page } = context;
11
+ const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 20;
12
+ const scrollAmount = (_b = options === null || options === void 0 ? void 0 : options.scrollAmount) !== null && _b !== void 0 ? _b : 300;
13
+ const collectedHeaders = new Set();
14
+ const getVisible = async () => {
15
+ const headerLoc = resolve(config.headerSelector, root);
16
+ const texts = await headerLoc.allInnerTexts();
17
+ return texts.map(t => t.trim());
18
+ };
19
+ let currentHeaders = await getVisible();
20
+ currentHeaders.forEach(h => collectedHeaders.add(h));
21
+ const scrollerHandle = await root.evaluateHandle((el, selector) => {
13
22
  if (selector && el.matches(selector))
14
23
  return el;
15
24
  const effectiveSelector = selector || '.dvn-scroller';
16
- return (_a = el.closest(effectiveSelector)) !== null && _a !== void 0 ? _a : document.querySelector(effectiveSelector);
25
+ const ancestor = el.closest(effectiveSelector);
26
+ if (ancestor)
27
+ return ancestor;
28
+ return document.querySelector(effectiveSelector);
17
29
  }, options === null || options === void 0 ? void 0 : options.selector);
18
- return (0, headerScroll_1.scrollAndCollectHeaders)(context, findScroller, {
19
- limit: options === null || options === void 0 ? void 0 : options.limit,
20
- scrollAmount: options === null || options === void 0 ? void 0 : options.scrollAmount,
21
- notFoundMessage: 'HeaderStrategies.scrollRight: Could not find scroller. Returning visible headers.',
22
- });
30
+ const isScrollerFound = await scrollerHandle.evaluate(el => !!el);
31
+ if (isScrollerFound) {
32
+ await scrollerHandle.evaluate(el => el.scrollLeft = 0);
33
+ await page.waitForTimeout(200);
34
+ for (let i = 0; i < limit; i++) {
35
+ const sizeBefore = collectedHeaders.size;
36
+ await scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
37
+ await page.waitForTimeout(300);
38
+ const newHeaders = await getVisible();
39
+ newHeaders.forEach(h => collectedHeaders.add(h));
40
+ if (collectedHeaders.size === sizeBefore) {
41
+ await scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
42
+ await page.waitForTimeout(300);
43
+ const retryHeaders = await getVisible();
44
+ retryHeaders.forEach(h => collectedHeaders.add(h));
45
+ if (collectedHeaders.size === sizeBefore)
46
+ break;
47
+ }
48
+ }
49
+ }
50
+ else {
51
+ (0, debugUtils_1.logDebug)(config, 'info', "HeaderStrategies.scrollRight: Could not find scroller. Returning visible headers.");
52
+ }
53
+ if (isScrollerFound) {
54
+ await scrollerHandle.evaluate(el => el.scrollLeft = 0);
55
+ await page.waitForTimeout(200);
56
+ }
57
+ return Array.from(collectedHeaders);
23
58
  };
24
59
  exports.scrollRightHeader = scrollRightHeader;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HeaderStrategies = void 0;
4
4
  const debugUtils_1 = require("../utils/debugUtils");
5
- const headerScroll_1 = require("../utils/headerScroll");
6
5
  exports.HeaderStrategies = {
7
6
  /**
8
7
  * Default strategy: Returns only the headers currently visible in the DOM.
@@ -31,18 +30,62 @@ exports.HeaderStrategies = {
31
30
  */
32
31
  horizontalScroll: (options) => {
33
32
  return async (context) => {
33
+ var _a, _b;
34
+ const { resolve, config, root, page } = context;
35
+ const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 20;
36
+ const scrollAmount = (_b = options === null || options === void 0 ? void 0 : options.scrollAmount) !== null && _b !== void 0 ? _b : 300;
37
+ const collectedHeaders = new Set();
38
+ const getVisible = async () => {
39
+ const headerLoc = resolve(config.headerSelector, root);
40
+ const texts = await headerLoc.allInnerTexts();
41
+ return texts.map(t => t.trim());
42
+ };
43
+ let currentHeaders = await getVisible();
44
+ currentHeaders.forEach(h => collectedHeaders.add(h));
34
45
  const selector = options === null || options === void 0 ? void 0 : options.selector;
35
46
  if (!selector) {
36
- (0, debugUtils_1.logDebug)(context.config, 'info', 'HeaderStrategies.horizontalScroll: no selector provided — returning visible headers only. Pass { selector } for the scroll container (e.g. ".dvn-scroller").');
37
- return (0, headerScroll_1.readVisibleHeaders)(context);
47
+ (0, debugUtils_1.logDebug)(config, 'info', 'HeaderStrategies.horizontalScroll: no selector provided — returning visible headers only. Pass { selector } for the scroll container (e.g. ".dvn-scroller").');
48
+ return Array.from(collectedHeaders);
38
49
  }
39
- // Self, then ancestor, then descendant — scoped to the table, never document-wide.
40
- const findScroller = () => context.root.evaluateHandle((el, sel) => { var _a; return el.matches(sel) ? el : (_a = el.closest(sel)) !== null && _a !== void 0 ? _a : el.querySelector(sel); }, selector);
41
- return (0, headerScroll_1.scrollAndCollectHeaders)(context, findScroller, {
42
- limit: options === null || options === void 0 ? void 0 : options.limit,
43
- scrollAmount: options === null || options === void 0 ? void 0 : options.scrollAmount,
44
- notFoundMessage: `HeaderStrategies.horizontalScroll: Could not find scroller matching "${selector}". Returning visible headers.`,
45
- });
50
+ const scrollerHandle = await root.evaluateHandle((el, sel) => {
51
+ if (el.matches(sel))
52
+ return el;
53
+ const ancestor = el.closest(sel);
54
+ if (ancestor)
55
+ return ancestor;
56
+ const child = el.querySelector(sel);
57
+ if (child)
58
+ return child;
59
+ return null;
60
+ }, selector);
61
+ const isScrollerFound = await scrollerHandle.evaluate(el => !!el);
62
+ if (isScrollerFound) {
63
+ await scrollerHandle.evaluate(el => el.scrollLeft = 0);
64
+ await page.waitForTimeout(200);
65
+ for (let i = 0; i < limit; i++) {
66
+ const sizeBefore = collectedHeaders.size;
67
+ await scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
68
+ await page.waitForTimeout(300);
69
+ const newHeaders = await getVisible();
70
+ newHeaders.forEach(h => collectedHeaders.add(h));
71
+ if (collectedHeaders.size === sizeBefore) {
72
+ await scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
73
+ await page.waitForTimeout(300);
74
+ const retryHeaders = await getVisible();
75
+ retryHeaders.forEach(h => collectedHeaders.add(h));
76
+ if (collectedHeaders.size === sizeBefore)
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ else {
82
+ (0, debugUtils_1.logDebug)(config, 'info', `HeaderStrategies.horizontalScroll: Could not find scroller matching "${selector}". Returning visible headers.`);
83
+ }
84
+ if (isScrollerFound) {
85
+ await scrollerHandle.evaluate(el => el.scrollLeft = 0);
86
+ await page.waitForTimeout(200);
87
+ }
88
+ return Array.from(collectedHeaders);
46
89
  };
47
90
  }
48
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.23.1-next.3ae8c6f",
3
+ "version": "6.23.1",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",
@@ -1,13 +0,0 @@
1
- import type { JSHandle } from '@playwright/test';
2
- import type { StrategyContext } from '../types';
3
- export declare const readVisibleHeaders: ({ resolve, config, root }: StrategyContext) => Promise<string[]>;
4
- /**
5
- * Horizontal header discovery shared by `HeaderStrategies.horizontalScroll` and the Glide preset:
6
- * reset the scroller to the left, step right collecting headers until two consecutive steps add
7
- * nothing (or `limit` is hit), then scroll back. Callers differ only in how they find the scroller.
8
- */
9
- export declare function scrollAndCollectHeaders(context: StrategyContext, findScroller: () => Promise<JSHandle<Element | null>>, options: {
10
- limit?: number;
11
- scrollAmount?: number;
12
- notFoundMessage: string;
13
- }): Promise<string[]>;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readVisibleHeaders = void 0;
4
- exports.scrollAndCollectHeaders = scrollAndCollectHeaders;
5
- const debugUtils_1 = require("./debugUtils");
6
- const readVisibleHeaders = async ({ resolve, config, root }) => {
7
- const texts = await resolve(config.headerSelector, root).allInnerTexts();
8
- return texts.map(t => t.trim());
9
- };
10
- exports.readVisibleHeaders = readVisibleHeaders;
11
- /**
12
- * Horizontal header discovery shared by `HeaderStrategies.horizontalScroll` and the Glide preset:
13
- * reset the scroller to the left, step right collecting headers until two consecutive steps add
14
- * nothing (or `limit` is hit), then scroll back. Callers differ only in how they find the scroller.
15
- */
16
- async function scrollAndCollectHeaders(context, findScroller, options) {
17
- var _a, _b;
18
- const { config, page } = context;
19
- const limit = (_a = options.limit) !== null && _a !== void 0 ? _a : 20;
20
- const scrollAmount = (_b = options.scrollAmount) !== null && _b !== void 0 ? _b : 300;
21
- const collectedHeaders = new Set(await (0, exports.readVisibleHeaders)(context));
22
- const scrollerHandle = await findScroller();
23
- const isScrollerFound = await scrollerHandle.evaluate(el => !!el);
24
- if (!isScrollerFound) {
25
- (0, debugUtils_1.logDebug)(config, 'info', options.notFoundMessage);
26
- return Array.from(collectedHeaders);
27
- }
28
- const collectAfterStep = async () => {
29
- await scrollerHandle.evaluate((el, amount) => el.scrollLeft += amount, scrollAmount);
30
- await page.waitForTimeout(300);
31
- (await (0, exports.readVisibleHeaders)(context)).forEach(h => collectedHeaders.add(h));
32
- };
33
- await scrollerHandle.evaluate(el => el.scrollLeft = 0);
34
- await page.waitForTimeout(200);
35
- for (let i = 0; i < limit; i++) {
36
- const sizeBefore = collectedHeaders.size;
37
- await collectAfterStep();
38
- if (collectedHeaders.size === sizeBefore) {
39
- await collectAfterStep();
40
- if (collectedHeaders.size === sizeBefore)
41
- break;
42
- }
43
- }
44
- await scrollerHandle.evaluate(el => el.scrollLeft = 0);
45
- await page.waitForTimeout(200);
46
- return Array.from(collectedHeaders);
47
- }