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AA,GAAA,2CAAG,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY;IACvD,KAAK,KAAK,CAAC,MAAM,GAAG;IACpB,OAAO;AACT","sources":["packages/react-aria/src/virtualizer/useVirtualizerItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {isElementVisible} from '../utils/isElementVisible';\nimport {Key, RefObject} from '@react-types/shared';\nimport {LayoutInfo, Size} from 'react-stately/useVirtualizerState';\nimport {useCallback, useEffect} from 'react';\nimport {useEffectEvent} from '../utils/useEffectEvent';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\n\ninterface IVirtualizer {\n  updateItemSize(key: Key, size: Size): void;\n}\n\nexport interface VirtualizerItemOptions {\n  layoutInfo: LayoutInfo | null;\n  virtualizer: IVirtualizer;\n  ref: RefObject<HTMLElement | null>;\n  shouldObserveItemSize?: boolean;\n}\n\nexport function useVirtualizerItem(options: VirtualizerItemOptions): {updateSize: () => void} {\n  let {layoutInfo, virtualizer, ref, shouldObserveItemSize} = options;\n  let key = layoutInfo?.key;\n\n  let updateSize = useCallback(() => {\n    if (key != null && ref.current) {\n      // if the virtualized item is not visible (aka display none on virtualized collection),\n      // we want to avoid reporting size 0 otherwise we get into a state where the virtualizer renders 0 items\n      // when it is hidden and thus won't remeasure when it is is unhidden\n      if (!isElementVisible(ref.current)) {\n        return;\n      }\n      let size = getSize(ref.current);\n      virtualizer.updateItemSize(key, size);\n    }\n  }, [virtualizer, key, ref]);\n\n  let updateSizeEvent = useEffectEvent(updateSize);\n\n  useLayoutEffect(() => {\n    if (layoutInfo?.estimatedSize) {\n      updateSizeEvent();\n    }\n  });\n\n  // TODO: Consider using a MutationObserver in addition to ResizeObserver to detect\n  // when inner DOM structure changes cause an item's height to change.\n  // The current ResizeObserver only observes direct children,\n  // so mutations deeper in the tree won't trigger a remeasure, leading to stale cached heights and overlapping items.\n  // useResizeObserver observes one element via ref, but the wrapper height is fixed by layout\n  // and won't change when content grows. Observe direct children instead, then remeasure the\n  // wrapper in updateSize.\n  useEffect(() => {\n    if (!shouldObserveItemSize) {\n      return;\n    }\n\n    let el = ref.current;\n    if (!el || typeof ResizeObserver === 'undefined') {\n      return;\n    }\n\n    let resizeObserver = new ResizeObserver(entries => {\n      if (!entries.length) {\n        return;\n      }\n      updateSizeEvent();\n    });\n\n    for (let child of el.children) {\n      resizeObserver.observe(child);\n    }\n\n    return () => {\n      resizeObserver.disconnect();\n    };\n  }, [shouldObserveItemSize, ref, key]);\n\n  return {updateSize};\n}\n\nfunction getSize(node: HTMLElement): Size {\n  // Reset height before measuring so we get the intrinsic size\n  let height = node.style.height;\n  node.style.height = '';\n  let size = new Size(node.scrollWidth, node.scrollHeight);\n  node.style.height = height;\n  return size;\n}\n"],"names":[],"version":3,"file":"useVirtualizerItem.cjs.map"}