{"version":3,"file":"VirtualizedList.mjs","names":[],"sources":["../../../../../src/plugins/ChannelDetail/VirtualizedList/VirtualizedList.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { ComponentProps, ComponentType, ReactNode } from 'react';\nimport React, { forwardRef, useCallback, useMemo } from 'react';\nimport type { ComputeItemKey, VirtuosoProps } from 'react-virtuoso';\nimport { Virtuoso } from 'react-virtuoso';\n\n// Wraps the virtualized item list so views can attach padding to a stable class instead of\n// Virtuoso's internal markup.\nconst VirtualizedListContent = forwardRef<HTMLDivElement, ComponentProps<'div'>>(\n  function VirtualizedListContent({ className, ...props }, ref) {\n    return (\n      <div\n        {...props}\n        className={clsx('str-chat__virtualized-list__content', className)}\n        ref={ref}\n      />\n    );\n  },\n);\n\nexport type VirtualizedListProps<T> = {\n  /** Items to render. An empty array renders the `EmptyPlaceholder`. */\n  data: T[];\n  /** Renders a single item; do not add a React key, Virtuoso manages keys. */\n  itemContent: (index: number, item: T) => ReactNode;\n  'aria-label'?: string;\n  className?: string;\n  computeItemKey?: ComputeItemKey<T, unknown>;\n  /** Rendered in place of the list when `data` is empty. */\n  EmptyPlaceholder?: ComponentType;\n  /** Rendered below the items, e.g. a loading indicator for the next page. */\n  Footer?: ComponentType;\n  /** Called when the list is scrolled to the bottom to load the next page. */\n  loadNext?: () => void;\n  role?: string;\n  /** Escape hatch for passing additional props straight to Virtuoso. */\n  virtuosoProps?: VirtuosoProps<T, unknown>;\n};\n\n/** Wrapper around `react-virtuoso`'s `Virtuoso` for simple, append-only, flat lists. */\nexport const VirtualizedList = <T,>({\n  className,\n  computeItemKey,\n  data,\n  EmptyPlaceholder,\n  Footer,\n  itemContent,\n  loadNext,\n  virtuosoProps,\n  ...rest\n}: VirtualizedListProps<T>) => {\n  const atBottomStateChange = useCallback(\n    (atBottom: boolean) => {\n      if (atBottom) loadNext?.();\n    },\n    [loadNext],\n  );\n\n  const components = useMemo(\n    () => ({\n      EmptyPlaceholder,\n      Footer,\n      List: VirtualizedListContent,\n    }),\n    [EmptyPlaceholder, Footer],\n  );\n\n  return (\n    <Virtuoso\n      atBottomStateChange={atBottomStateChange}\n      className={clsx('str-chat__virtualized-list', className)}\n      components={components}\n      computeItemKey={computeItemKey}\n      data={data}\n      itemContent={itemContent}\n      {...rest}\n      {...virtuosoProps}\n    />\n  );\n};\n"],"mappings":";;;;;AAQA,IAAM,yBAAyB,WAC7B,SAAS,uBAAuB,EAAE,WAAW,GAAG,SAAS,KAAK;CAC5D,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,WAAW,KAAK,uCAAuC,SAAS;EAC3D;CACN,CAAA;AAEL,CACF;;AAsBA,IAAa,mBAAuB,EAClC,WACA,gBACA,MACA,kBACA,QACA,aACA,UACA,eACA,GAAG,WAC0B;CAC7B,MAAM,sBAAsB,aACzB,aAAsB;EACrB,IAAI,UAAU,WAAW;CAC3B,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,aAAa,eACV;EACL;EACA;EACA,MAAM;CACR,IACA,CAAC,kBAAkB,MAAM,CAC3B;CAEA,OACE,oBAAC,UAAD;EACuB;EACrB,WAAW,KAAK,8BAA8B,SAAS;EAC3C;EACI;EACV;EACO;EACb,GAAI;EACJ,GAAI;CACL,CAAA;AAEL"}