react-spring-carousel 1.9.29-beta35 → 1.9.29-beta36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"useThumbsModule.js","sources":["../../src/modules/useThumbsModule.tsx"],"sourcesContent":["import { forwardRef, HTMLAttributes, useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport { useMount } from 'src/utils'\nimport {\n UseSpringCarouselProps,\n ReactSpringThumbItem,\n PrepareThumbsData,\n UseSpringCarouselItems,\n SlideActionType,\n} from '../types'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: UseSpringCarouselItems['items']\n withThumbs: boolean\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n springConfig: SpringConfig\n prepareThumbsData?: PrepareThumbsData\n itemsPerSlide?: UseSpringCarouselProps['itemsPerSlide']\n CustomThumbsWrapperComponent?: UseSpringCarouselProps['CustomThumbsWrapperComponent']\n getFluidWrapperScrollValue?(): number\n getSlideValue?(): number\n}\n\ntype WrapperProps = {\n children: React.ReactNode\n} & HTMLAttributes<HTMLDivElement>\n\nconst InternalWrapper = forwardRef<HTMLDivElement, WrapperProps>(\n ({ children, ...rest }, ref) => {\n return (\n <animated.div {...rest} ref={ref}>\n {children}\n </animated.div>\n )\n },\n)\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n prepareThumbsData,\n itemsPerSlide,\n getFluidWrapperScrollValue = () => 0,\n getSlideValue = () => 0,\n CustomThumbsWrapperComponent,\n}: Props) {\n const internalThumbsWrapperRef = useRef<HTMLDivElement | null>(null)\n const [thumbListStyles, setThumbListStyles] = useSpring(() => ({\n x: 0,\n y: 0,\n config: springConfig,\n onChange: ({ value }) => {\n if (internalThumbsWrapperRef.current) {\n internalThumbsWrapperRef.current[\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[thumbsSlideAxis])\n }\n },\n }))\n\n useMount(() => {\n if (withThumbs && !internalThumbsWrapperRef.current) {\n throw new Error(\n \"The thumbs wrapper is not defined. If you've passed a Functional component, be sure to wrap your component in forwardRef.\",\n )\n }\n })\n\n function getCurrentThumbScrollValue() {\n return internalThumbsWrapperRef.current![\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n function getThumbsTotalScrollableValue() {\n return Math.round(\n Number(\n internalThumbsWrapperRef.current?.[\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n ],\n ) -\n internalThumbsWrapperRef.current!.getBoundingClientRect()[\n thumbsSlideAxis === 'x' ? 'width' : 'height'\n ],\n )\n }\n\n function getThumbSlideValue() {\n const thumbSlideTotal = Math.round(getFluidWrapperScrollValue() / getSlideValue())\n const totalScrollableValue = getThumbsTotalScrollableValue()\n return totalScrollableValue / thumbSlideTotal\n }\n\n function handleThumbsScroll(activeItem: number, actionType?: SlideActionType) {\n if (itemsPerSlide === 'fluid') {\n const totalScrollableValue = getThumbsTotalScrollableValue()\n\n if (actionType === 'next') {\n const nextValue = getCurrentThumbScrollValue() + getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]:\n nextValue > totalScrollableValue ? totalScrollableValue : nextValue,\n },\n })\n }\n if (actionType === 'prev') {\n const nextValue = getCurrentThumbScrollValue() - getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]: nextValue < 0 ? 0 : nextValue,\n },\n })\n }\n } else {\n function getOffsetDirection() {\n return thumbsSlideAxis === 'x' ? 'offsetLeft' : 'offsetTop'\n }\n function getOffsetDimension() {\n return thumbsSlideAxis === 'x' ? 'offsetWidth' : 'offsetHeight'\n }\n function getScrollDirecton() {\n return thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n }\n function getThumbNode() {\n return internalThumbsWrapperRef.current!.querySelector(\n `#thumb-${items[activeItem].id}`,\n ) as HTMLElement\n }\n function getThumbOffsetPosition({\n thumbNode,\n offsetDirection,\n offsetDimension,\n }: {\n thumbNode: HTMLElement\n offsetDirection: OffsetDirection\n offsetDimension: OffsetDimension\n }) {\n return thumbNode[offsetDirection] + thumbNode[offsetDimension] / 2\n }\n function getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n offsetDimension: OffsetDimension\n }) {\n return thumbWrapper[offsetDimension] / 2\n }\n function getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }: {\n thumbWrapper: HTMLDivElement\n scrollDirection: ScrollDirection\n }) {\n return thumbWrapper[scrollDirection]\n }\n function getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n thumbOffsetPosition: number\n thumbScrollDimension: number\n offsetDimension: OffsetDimension\n }) {\n const scrollDimensionProperty =\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n\n if (\n activeItem === items.length - 1 ||\n thumbOffsetPosition - thumbScrollDimension >\n thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n ) {\n return thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n }\n if (activeItem === 0) {\n return 0\n }\n\n return thumbOffsetPosition - thumbScrollDimension\n }\n\n const thumbNode = getThumbNode()\n\n if (thumbNode) {\n const thumbWrapper = internalThumbsWrapperRef.current!\n const offsetDirection = getOffsetDirection()\n const offsetDimension = getOffsetDimension()\n const scrollDirection = getScrollDirecton()\n const thumbOffsetPosition = getThumbOffsetPosition({\n thumbNode,\n offsetDimension,\n offsetDirection,\n })\n const thumbScrollDimension = getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n })\n\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }),\n },\n to: {\n [thumbsSlideAxis]: getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }),\n },\n onChange: val => {\n if (thumbsSlideAxis === 'x') {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollLeft = val.x\n } else {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollTop = val.y\n }\n },\n })\n }\n }\n }\n function handlePrepareThumbsDate() {\n function getPreparedItems(\n _items: UseSpringCarouselItems['items'],\n ): ReactSpringThumbItem[] {\n return _items.map(i => ({\n id: i.id,\n renderThumb: i.renderThumb,\n }))\n }\n\n if (prepareThumbsData) {\n return prepareThumbsData(getPreparedItems(items))\n }\n return getPreparedItems(items)\n }\n\n const Wrapper = CustomThumbsWrapperComponent\n ? animated(CustomThumbsWrapperComponent)\n : InternalWrapper\n\n const thumbsFragment = withThumbs ? (\n <Wrapper\n ref={internalThumbsWrapperRef}\n className=\"use-spring-carousel-thumbs-wrapper\"\n onWheel={() => {\n thumbListStyles[thumbsSlideAxis].stop()\n }}\n style={{\n display: 'flex',\n flex: 1,\n position: 'relative',\n flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsDate().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId}>\n {renderThumb}\n </div>\n )\n })}\n </Wrapper>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n"],"names":["forwardRef","_jsx","animated","useRef","useSpring","useMount"],"mappings":";;;;;;;;;AA+BA,MAAM,eAAe,GAAGA,gBAAU,CAChC,CAAC,EAAE,QAAQ,EAA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