{
  "version": 3,
  "sources": ["../../../../src/components/dataviews-layouts/utils/use-infinite-scroll.ts"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../dataviews-context';\n\n/**\n * Hook to set up an IntersectionObserver for infinite scroll items.\n * Observes the element and triggers the callback when the item becomes visible.\n *\n * @param elementRef - Ref to the DOM element to observe.\n * @param posinset   - The position of the item in the set (1-based index).\n */\nexport function useIntersectionObserver(\n\telementRef: React.RefObject< HTMLElement | null >,\n\tposinset: number | undefined\n) {\n\tconst { intersectionObserver } = useContext( DataViewsContext );\n\n\tuseEffect( () => {\n\t\tconst element = elementRef.current;\n\t\tif ( ! element || posinset === undefined || ! intersectionObserver ) {\n\t\t\treturn;\n\t\t}\n\n\t\tintersectionObserver.observe( element );\n\n\t\treturn () => {\n\t\t\tintersectionObserver.unobserve( element );\n\t\t};\n\t}, [ elementRef, intersectionObserver, posinset ] );\n}\n\n/**\n * Hook to calculate the number of placeholder items needed for the first row\n * in an infinite scroll grid layout.\n *\n * When items are loaded starting from a position other than 1, placeholders\n * are needed to maintain proper grid alignment.\n *\n * @param data             - The array of data items.\n * @param isInfiniteScroll - Whether infinite scroll is enabled.\n * @param gridColumns      - The number of columns in the grid.\n * @return The number of placeholder items needed.\n */\nexport function usePlaceholdersNeeded< Item >(\n\tdata: Item[],\n\tisInfiniteScroll: boolean,\n\tgridColumns: number\n): number {\n\tconst hasData = !! data?.length;\n\tconst firstItemPosition =\n\t\thasData && isInfiniteScroll\n\t\t\t? ( data[ 0 ] as { position?: number } ).position\n\t\t\t: undefined;\n\n\treturn firstItemPosition && gridColumns\n\t\t? ( firstItemPosition - 1 ) % gridColumns\n\t\t: 0;\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAsC;AAKtC,+BAA6B;AAStB,SAAS,wBACf,YACA,UACC;AACD,QAAM,EAAE,qBAAqB,QAAI,2BAAY,yBAAAA,OAAiB;AAE9D,gCAAW,MAAM;AAChB,UAAM,UAAU,WAAW;AAC3B,QAAK,CAAE,WAAW,aAAa,UAAa,CAAE,sBAAuB;AACpE;AAAA,IACD;AAEA,yBAAqB,QAAS,OAAQ;AAEtC,WAAO,MAAM;AACZ,2BAAqB,UAAW,OAAQ;AAAA,IACzC;AAAA,EACD,GAAG,CAAE,YAAY,sBAAsB,QAAS,CAAE;AACnD;AAcO,SAAS,sBACf,MACA,kBACA,aACS;AACT,QAAM,UAAU,CAAC,CAAE,MAAM;AACzB,QAAM,oBACL,WAAW,mBACN,KAAM,CAAE,EAA6B,WACvC;AAEJ,SAAO,qBAAqB,eACvB,oBAAoB,KAAM,cAC5B;AACJ;",
  "names": ["DataViewsContext"]
}
