@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 2.34 kB
Source Map (JSON)
{"version":3,"file":"get-row-position-data.cjs","names":[],"sources":["../../../src/components/OverflowList/get-row-position-data.ts"],"sourcesContent":["import React from 'react';\n\ninterface NodePosition {\n elements: Set<HTMLElement>;\n bottom: number;\n top: number;\n}\nfunction groupNodesByTopPosition(nodes: HTMLElement[]): Record<number, NodePosition> {\n if (nodes.length === 0) {\n return {};\n }\n\n const result: Record<number, NodePosition> = {};\n\n nodes.forEach((node) => {\n const rect = node.getBoundingClientRect();\n const top = Math.round(rect.top);\n const bottom = Math.round(rect.bottom);\n\n if (!result[top]) {\n result[top] = {\n elements: new Set<HTMLElement>(),\n bottom,\n top,\n };\n } else {\n result[top].bottom = Math.max(result[top].bottom, bottom);\n }\n\n result[top].elements.add(node);\n });\n\n return result;\n}\nexport function getRowPositionsData(\n containerRef: React.RefObject<HTMLElement | null>,\n overflowRef: React.RefObject<HTMLElement | null>\n): {\n itemsSizesMap: Record<number, NodePosition>;\n rowPositions: number[];\n children: HTMLElement[];\n} | null {\n if (!containerRef.current) {\n return null;\n }\n\n const container = containerRef.current;\n const children = Array.from(container.children).filter(\n (child) => overflowRef.current !== child\n ) as HTMLElement[];\n\n if (children.length === 0) {\n return null;\n }\n\n const itemsSizesMap = groupNodesByTopPosition(children);\n const rowPositions = Object.keys(itemsSizesMap).map(Number);\n\n return { itemsSizesMap, rowPositions, children };\n}\n"],"mappings":";;AAOA,SAAS,wBAAwB,OAAoD;CACnF,IAAI,MAAM,WAAW,GACnB,OAAO,CAAC;CAGV,MAAM,SAAuC,CAAC;CAE9C,MAAM,SAAS,SAAS;EACtB,MAAM,OAAO,KAAK,sBAAsB;EACxC,MAAM,MAAM,KAAK,MAAM,KAAK,GAAG;EAC/B,MAAM,SAAS,KAAK,MAAM,KAAK,MAAM;EAErC,IAAI,CAAC,OAAO,MACV,OAAO,OAAO;GACZ,0BAAU,IAAI,IAAiB;GAC/B;GACA;EACF;OAEA,OAAO,KAAK,SAAS,KAAK,IAAI,OAAO,KAAK,QAAQ,MAAM;EAG1D,OAAO,KAAK,SAAS,IAAI,IAAI;CAC/B,CAAC;CAED,OAAO;AACT;AACA,SAAgB,oBACd,cACA,aAKO;CACP,IAAI,CAAC,aAAa,SAChB,OAAO;CAGT,MAAM,YAAY,aAAa;CAC/B,MAAM,WAAW,MAAM,KAAK,UAAU,QAAQ,EAAE,QAC7C,UAAU,YAAY,YAAY,KACrC;CAEA,IAAI,SAAS,WAAW,GACtB,OAAO;CAGT,MAAM,gBAAgB,wBAAwB,QAAQ;CAGtD,OAAO;EAAE;EAAe,cAFH,OAAO,KAAK,aAAa,EAAE,IAAI,MAEjB;EAAG;CAAS;AACjD"}