MCPcopy Create free account
hub / github.com/bvaughn/react-window / getRowElements

Function getRowElements

lib/components/list/getRowElements.ts:9–63  ·  view source on GitHub ↗
({
  elements,
  isFlowLayout,
  rowCount,
  startIndex,
  stopIndex
}: {
  elements: Element[];
  isFlowLayout: boolean;
  rowCount: number;
  startIndex: number;
  stopIndex: number;
})

Source from the content-addressed store, hash-verified

7 * they are rendered before additional children (e.g. overlays), except in flow layout.
8 */
9export function getRowElements({
10 elements,
11 isFlowLayout,
12 rowCount,
13 startIndex,
14 stopIndex
15}: {
16 elements: Element[];
17 isFlowLayout: boolean;
18 rowCount: number;
19 startIndex: number;
20 stopIndex: number;
21}): { element: Element; index: number }[] {
22 if (startIndex < 0 || stopIndex < startIndex) {
23 return [];
24 }
25
26 const rows: { element: Element; index: number }[] = [];
27 const indices = new Set<number>();
28 let isValid = true;
29 for (const element of elements) {
30 const posInSet = element.getAttribute("aria-posinset");
31 if (posInSet === null) {
32 continue;
33 }
34
35 // Values that don't match the rendered rows have been overridden (e.g. to number rows within groups)
36 // and can't be used to identify rows
37 const index = Number(posInSet) - 1;
38 if (
39 !/^\d+$/.test(posInSet) ||
40 index < startIndex ||
41 index > stopIndex ||
42 indices.has(index) ||
43 element.getAttribute("aria-setsize") !== `${rowCount}`
44 ) {
45 isValid = false;
46 break;
47 }
48
49 indices.add(index);
50 rows.push({ element, index });
51 }
52
53 if (isValid && rows.length > 0) {
54 return rows;
55 }
56
57 const count = Math.min(elements.length, stopIndex - startIndex + 1);
58 return (
59 isFlowLayout
60 ? elements.slice(elements.length - count)
61 : elements.slice(0, count)
62 ).map((element, offset) => ({ element, index: startIndex + offset }));
63}

Callers 2

ListComponentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected