MCPcopy Create free account
hub / github.com/adobe/react-spectrum / readLayout

Function readLayout

perf/app/layout.mjs:74–111  ·  view source on GitHub ↗
(expected)

Source from the content-addressed store, hash-verified

72// Called once per animation frame, never from the MutationObserver. Reads are
73// bounded by the rendered virtualized window, not the full dataset.
74export function readLayout(expected) {
75 let viewport = document.querySelector(expected.viewport);
76 if (!viewport) {
77 return null;
78 }
79 let bounds = viewport.getBoundingClientRect();
80 let columns = expected.columns && [...viewport.querySelectorAll('[role="columnheader"]')];
81 let headingHeight = columns?.length ? columns[0].parentElement.getBoundingClientRect().height : 0;
82 let snapshot = {
83 width: bounds.width,
84 contentWidth: columns
85 ? columns.reduce((total, column) => total + column.getBoundingClientRect().width, 0)
86 : viewport.clientWidth,
87 height: viewport.clientHeight - headingHeight,
88 scrollTop: viewport.scrollTop,
89 ...(columns && {columns: columns.map(column => column.getBoundingClientRect().width)}),
90 rows: [...viewport.querySelectorAll('[data-record]')].map(node => {
91 let rect = (columns ? node.parentElement : node).getBoundingClientRect();
92 let id = node.getAttribute('data-record');
93 return {
94 id,
95 index: Number(id.slice(5)),
96 top: rect.top - bounds.top - viewport.clientTop - headingHeight,
97 height: rect.height,
98 width: rect.width,
99 allocatedHeight: node.parentElement.getBoundingClientRect().height,
100 ...(columns && {
101 contentHeight: Math.max(
102 ...[...node.querySelectorAll('[role="gridcell"], [role="rowheader"]')].map(
103 cellContentHeight
104 )
105 )
106 })
107 };
108 })
109 };
110 return validLayout(snapshot, expected) ? snapshot : null;
111}
112
113export function layoutSignature(snapshot) {
114 // Virtualizers may reorder DOM nodes or recycle offscreen rows without moving

Callers 3

tickFunction · 0.90
readFunction · 0.90
settleLayoutFunction · 0.85

Calls 2

validLayoutFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected