UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

35 lines (34 loc) 1.12 kB
"use client"; //#region packages/@mantine/core/src/components/OverflowList/get-row-position-data.ts function groupNodesByTopPosition(nodes) { if (nodes.length === 0) return {}; const result = {}; nodes.forEach((node) => { const rect = node.getBoundingClientRect(); const top = Math.round(rect.top); const bottom = Math.round(rect.bottom); if (!result[top]) result[top] = { elements: /* @__PURE__ */ new Set(), bottom, top }; else result[top].bottom = Math.max(result[top].bottom, bottom); result[top].elements.add(node); }); return result; } function getRowPositionsData(containerRef, overflowRef) { if (!containerRef.current) return null; const container = containerRef.current; const children = Array.from(container.children).filter((child) => overflowRef.current !== child); if (children.length === 0) return null; const itemsSizesMap = groupNodesByTopPosition(children); return { itemsSizesMap, rowPositions: Object.keys(itemsSizesMap).map(Number), children }; } //#endregion exports.getRowPositionsData = getRowPositionsData; //# sourceMappingURL=get-row-position-data.cjs.map