(
selector: string,
datasetKey: IndexedDatasetKey
)
| 1717 | } |
| 1718 | |
| 1719 | function getIndexedElements( |
| 1720 | selector: string, |
| 1721 | datasetKey: IndexedDatasetKey |
| 1722 | ): HTMLElement[] { |
| 1723 | return [...document.querySelectorAll<HTMLElement>(selector)] |
| 1724 | .filter((el) => el.getClientRects().length > 0) |
| 1725 | .sort((a, b) => { |
| 1726 | const aRect = a.getBoundingClientRect() |
| 1727 | const bRect = b.getBoundingClientRect() |
| 1728 | const rowDelta = aRect.top - bRect.top |
| 1729 | |
| 1730 | // Follow the actual rendered row order first, then fall back |
| 1731 | // to the assigned index for stable ordering within the same row. |
| 1732 | if (Math.abs(rowDelta) > 2) return rowDelta |
| 1733 | |
| 1734 | const colDelta = aRect.left - bRect.left |
| 1735 | if (Math.abs(colDelta) > 2) return colDelta |
| 1736 | |
| 1737 | return getIndexedValue(a, datasetKey) - getIndexedValue(b, datasetKey) |
| 1738 | }) |
| 1739 | } |
| 1740 | |
| 1741 | function getIndexedValue( |
| 1742 | el: HTMLElement | null, |
no test coverage detected