@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 2.32 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;AACnF,KAAI,MAAM,WAAW,EACnB,QAAO,EAAE;CAGX,MAAM,SAAuC,EAAE;AAE/C,OAAM,SAAS,SAAS;EACtB,MAAM,OAAO,KAAK,uBAAuB;EACzC,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI;EAChC,MAAM,SAAS,KAAK,MAAM,KAAK,OAAO;AAEtC,MAAI,CAAC,OAAO,KACV,QAAO,OAAO;GACZ,0BAAU,IAAI,KAAkB;GAChC;GACA;GACD;MAED,QAAO,KAAK,SAAS,KAAK,IAAI,OAAO,KAAK,QAAQ,OAAO;AAG3D,SAAO,KAAK,SAAS,IAAI,KAAK;GAC9B;AAEF,QAAO;;AAET,SAAgB,oBACd,cACA,aAKO;AACP,KAAI,CAAC,aAAa,QAChB,QAAO;CAGT,MAAM,YAAY,aAAa;CAC/B,MAAM,WAAW,MAAM,KAAK,UAAU,SAAS,CAAC,QAC7C,UAAU,YAAY,YAAY,MACpC;AAED,KAAI,SAAS,WAAW,EACtB,QAAO;CAGT,MAAM,gBAAgB,wBAAwB,SAAS;AAGvD,QAAO;EAAE;EAAe,cAFH,OAAO,KAAK,cAAc,CAAC,IAAI,OAAO;EAErB;EAAU"}