@ubnt/store.core 10.20.0-alpha.22 → 10.20.0-alpha.24

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.
Files changed (184) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/assets/ai-360.jpg +0 -0
  3. package/lib/assets/ai-3602.jpg +0 -0
  4. package/lib/assets/ai-dslr.jpg +0 -0
  5. package/lib/assets/ai-dslr2.jpg +0 -0
  6. package/lib/assets/ai-lpr.jpg +0 -0
  7. package/lib/assets/ai-lpr2.jpg +0 -0
  8. package/lib/assets/ai-turret.jpg +0 -0
  9. package/lib/assets/ai-turret2.jpg +0 -0
  10. package/lib/assets/attention.svg +5 -5
  11. package/lib/assets/attention2.svg +5 -5
  12. package/lib/assets/door-hub.jpg +0 -0
  13. package/lib/assets/door-hub2.jpg +0 -0
  14. package/lib/assets/express.jpg +0 -0
  15. package/lib/assets/express2.jpg +0 -0
  16. package/lib/assets/g2-reader-pro.jpg +0 -0
  17. package/lib/assets/g2-reader-pro2.jpg +0 -0
  18. package/lib/assets/g3-reader-pro.jpg +0 -0
  19. package/lib/assets/g3-reader-pro2.jpg +0 -0
  20. package/lib/assets/g3-starter-kit.jpg +0 -0
  21. package/lib/assets/g3-starter-kit2.jpg +0 -0
  22. package/lib/assets/interior-design.svg +2 -2
  23. package/lib/assets/interior-design2.svg +2 -2
  24. package/lib/assets/minus4.svg +8 -8
  25. package/lib/assets/minus5.svg +8 -8
  26. package/lib/assets/pause.svg +3 -3
  27. package/lib/assets/pause2.svg +3 -3
  28. package/lib/assets/plus4.svg +9 -9
  29. package/lib/assets/plus5.svg +9 -9
  30. package/lib/assets/ptz2.svg +2 -2
  31. package/lib/assets/ptz3.svg +2 -2
  32. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  33. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  34. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  35. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  36. package/lib/components/ModelCompareV4/CompareTable/CompareTable.js +5 -9
  37. package/lib/components/ModelCompareV4/CompareTable/CompareTable.js.map +1 -1
  38. package/lib/components/ModelCompareV4/CompareTable/CompareTable.mjs +5 -9
  39. package/lib/components/ModelCompareV4/CompareTable/CompareTable.mjs.map +1 -1
  40. package/lib/components/ModelCompareV4/CompareTable/CompareTable.styles.d.ts +21 -21
  41. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/CompareTableMarkup.js +17 -19
  42. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/CompareTableMarkup.js.map +1 -1
  43. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/CompareTableMarkup.mjs +17 -19
  44. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/CompareTableMarkup.mjs.map +1 -1
  45. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/CompareTableOverflowScrollButton.js +21 -20
  46. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/CompareTableOverflowScrollButton.js.map +1 -1
  47. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/CompareTableOverflowScrollButton.mjs +21 -20
  48. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/CompareTableOverflowScrollButton.mjs.map +1 -1
  49. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/EmptyColumnHeader/EmptyColumnHeader.js +1 -1
  50. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/EmptyColumnHeader/EmptyColumnHeader.js.map +1 -1
  51. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/EmptyColumnHeader/EmptyColumnHeader.mjs +1 -1
  52. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/EmptyColumnHeader/EmptyColumnHeader.mjs.map +1 -1
  53. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/HeaderShadow.js +11 -11
  54. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/HeaderShadow.js.map +1 -1
  55. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/HeaderShadow.mjs +11 -11
  56. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/HeaderShadow.mjs.map +1 -1
  57. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/ProductHeader/ProductHeader.js +7 -7
  58. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/ProductHeader/ProductHeader.js.map +1 -1
  59. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/ProductHeader/ProductHeader.mjs +7 -7
  60. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/ProductHeader/ProductHeader.mjs.map +1 -1
  61. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/PropertyValueGridItem.js.map +1 -1
  62. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/PropertyValueGridItem.mjs.map +1 -1
  63. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridBody.js +6 -6
  64. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridBody.js.map +1 -1
  65. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridBody.mjs +6 -6
  66. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridBody.mjs.map +1 -1
  67. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridHeader.js +9 -9
  68. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridHeader.js.map +1 -1
  69. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridHeader.mjs +9 -9
  70. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridHeader.mjs.map +1 -1
  71. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridItem.d.ts +1 -1
  72. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridItem.js +5 -5
  73. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridItem.js.map +1 -1
  74. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridItem.mjs +5 -5
  75. package/lib/components/ModelCompareV4/CompareTable/CompareTableMarkup/components/StickyGrid/StickyGridItem.mjs.map +1 -1
  76. package/lib/components/ModelCompareV4/ModelCompareV4.js +18 -9
  77. package/lib/components/ModelCompareV4/ModelCompareV4.js.map +1 -1
  78. package/lib/components/ModelCompareV4/ModelCompareV4.mjs +18 -9
  79. package/lib/components/ModelCompareV4/ModelCompareV4.mjs.map +1 -1
  80. package/lib/components/ModelCompareV4/ProductList/ProductList.js +11 -7
  81. package/lib/components/ModelCompareV4/ProductList/ProductList.js.map +1 -1
  82. package/lib/components/ModelCompareV4/ProductList/ProductList.mjs +12 -8
  83. package/lib/components/ModelCompareV4/ProductList/ProductList.mjs.map +1 -1
  84. package/lib/components/ModelCompareV4/ProductList/components/Product/Product.js +2 -0
  85. package/lib/components/ModelCompareV4/ProductList/components/Product/Product.js.map +1 -1
  86. package/lib/components/ModelCompareV4/ProductList/components/Product/Product.mjs +2 -0
  87. package/lib/components/ModelCompareV4/ProductList/components/Product/Product.mjs.map +1 -1
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  91. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  92. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  93. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  94. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  95. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  96. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  97. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  98. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  99. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  100. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  101. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  102. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  103. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  104. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  105. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  106. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  107. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  108. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  109. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  110. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  111. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  112. package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.js +1 -1
  113. package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.mjs +2 -2
  114. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.js +1 -1
  115. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.mjs +2 -2
  116. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express.jpg.js +5 -5
  117. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express.jpg.mjs +2 -2
  118. package/lib/constants/modelCompareData/assets/Consoles/express.jpg.js +1 -1
  119. package/lib/constants/modelCompareData/assets/Consoles/express.jpg.mjs +2 -2
  120. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
  121. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
  122. package/lib/constants/modelCompareData/assets/DomeTurret/ai-turret.jpg.js +1 -1
  123. package/lib/constants/modelCompareData/assets/DomeTurret/ai-turret.jpg.mjs +2 -2
  124. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.js +1 -1
  125. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.mjs +2 -2
  126. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.js +1 -1
  127. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.mjs +2 -2
  128. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.js +1 -1
  129. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.mjs +2 -2
  130. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.js +1 -1
  131. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.mjs +2 -2
  132. package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
  133. package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
  134. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.js +1 -1
  135. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.mjs +2 -2
  136. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.js +1 -1
  137. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.mjs +2 -2
  138. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
  139. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
  140. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-turret.jpg.js +1 -1
  141. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-turret.jpg.mjs +2 -2
  142. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.js +1 -1
  143. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.mjs +2 -2
  144. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.js +1 -1
  145. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.mjs +2 -2
  146. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.js +1 -1
  147. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.mjs +2 -2
  148. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.js +1 -1
  149. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.mjs +2 -2
  150. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
  151. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
  152. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.js +1 -1
  153. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.mjs +2 -2
  154. package/lib/constants/modelCompareData/assets/ptz.svg.js +1 -1
  155. package/lib/constants/modelCompareData/assets/ptz.svg.mjs +2 -2
  156. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +3 -3
  157. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +2 -2
  158. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
  159. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
  160. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.js +1 -1
  161. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.mjs +1 -1
  162. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
  163. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
  164. package/lib/constants/modelCompareData/data/product-list-groups/ptz.js +1 -1
  165. package/lib/constants/modelCompareData/data/product-list-groups/ptz.mjs +1 -1
  166. package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
  167. package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
  168. package/lib/constants/modelCompareData/data/products/aiDslr.js +2 -2
  169. package/lib/constants/modelCompareData/data/products/aiDslr.mjs +2 -2
  170. package/lib/constants/modelCompareData/data/products/aiLpr.js +2 -2
  171. package/lib/constants/modelCompareData/data/products/aiLpr.mjs +2 -2
  172. package/lib/constants/modelCompareData/data/products/aiTurret.js +2 -2
  173. package/lib/constants/modelCompareData/data/products/aiTurret.mjs +2 -2
  174. package/lib/constants/modelCompareData/data/products/doorHub.js +2 -2
  175. package/lib/constants/modelCompareData/data/products/doorHub.mjs +2 -2
  176. package/lib/constants/modelCompareData/data/products/express.js +1 -1
  177. package/lib/constants/modelCompareData/data/products/express.mjs +1 -1
  178. package/lib/constants/modelCompareData/data/products/g2ReaderPro.js +2 -2
  179. package/lib/constants/modelCompareData/data/products/g2ReaderPro.mjs +2 -2
  180. package/lib/constants/modelCompareData/data/products/g3ReaderPro.js +2 -2
  181. package/lib/constants/modelCompareData/data/products/g3ReaderPro.mjs +2 -2
  182. package/lib/constants/modelCompareData/data/products/g3StarterKit.js +2 -2
  183. package/lib/constants/modelCompareData/data/products/g3StarterKit.mjs +2 -2
  184. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ModelCompareV4.js","sources":["../../../src/components/ModelCompareV4/ModelCompareV4.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useWindowScroll } from \"react-use\";\n\nimport type {\n ProductListGroupId,\n SelectedProduct,\n} from \"../../constants/modelCompareData/types\";\nimport { CompareTable } from \"./CompareTable/CompareTable\";\nimport { SELECTED_PRODUCTS_LIMIT } from \"./constants\";\nimport * as S from \"./ModelCompareV4.styles\";\nimport type { ModelCompareV4Props } from \"./ModelCompareV4.types\";\nimport { ProductList } from \"./ProductList/ProductList\";\n\nexport const MODEL_COMPARE_V4_ANCHOR = \"compare-table-v4\";\n\nexport const ModelCompareV4 = ({\n headerStickOffset,\n overlayTopOffset,\n showBuyButton,\n onLinkClick,\n linkToStoreTitleClick,\n additionalProductData,\n section,\n defaultSelectedProductsCount = 2,\n selectedProducts: externalSelectedProducts,\n setSelectedProducts: setExternalSelectedProducts,\n anchorScrollOffset,\n}: ModelCompareV4Props) => {\n const hasProductList = useMemo(\n () => section.products.length > 5 && !section.isStaticTable,\n [section.products, section.isStaticTable],\n );\n\n const INTERSECTION_OBSERVER_THRESHOLD = 0.35;\n\n const intersectionObserverObjectRef = useRef<HTMLDivElement | null>(null);\n\n const { y: scrollPositionY } = useWindowScroll();\n\n let userIsUnderneathIntersectionObserver = false;\n\n if (\n intersectionObserverObjectRef.current &&\n !userIsUnderneathIntersectionObserver\n ) {\n userIsUnderneathIntersectionObserver =\n intersectionObserverObjectRef.current.getBoundingClientRect().bottom <\n scrollPositionY;\n }\n\n // TODO: Improve the name and logic of this variable and related code. Currently, this variable is used whether ModelCompareV4 has a product list or not. It should only be used if hasProductList is `true`. Why? Because if hasProductList is `false` then selecting/deselecting products isn't possible. The gap between the name of the variable and what it does can be confusing for future devs.\n const defaultSelectedProducts = section.products\n .map((product) => ({ productId: product.id }))\n .slice(\n 0,\n hasProductList ? defaultSelectedProductsCount : section.products.length,\n );\n // TODO: rewrite the \"default selected products\" feature so we don't need to use a `useEffect` to update the state of V4. We'll be able to remove this hackie `useRef` as a side-effect.\n const defaultSelectedProductsRef = useRef(defaultSelectedProducts);\n\n const selectedProductsLimit = useMemo(() => {\n return section.products.length < SELECTED_PRODUCTS_LIMIT\n ? section.products.length\n : SELECTED_PRODUCTS_LIMIT;\n }, [section.products.length]);\n\n const [selectedProducts, setSelectedProducts] = useState<SelectedProduct[]>(\n [],\n );\n\n const [hasBeenObserved, setHasBeenObserved] = useState(false);\n\n const showProductGroups = section.showProductGroups !== false;\n\n // #############################################################################\n // Sets selectedProducts value\n // #############################################################################\n\n useEffect(() => {\n defaultSelectedProductsRef.current = defaultSelectedProducts;\n }, [defaultSelectedProducts]);\n\n useEffect(() => {\n setSelectedProducts(\n externalSelectedProducts ||\n (defaultSelectedProductsRef.current as SelectedProduct[]),\n );\n }, [section, externalSelectedProducts]);\n\n // #############################################################################\n // Intersection Observer Logic\n // #############################################################################\n\n const observerCallback = useCallback<IntersectionObserverCallback>(\n (entries) => {\n entries.forEach(\n (entry) =>\n entry.isIntersecting && !hasBeenObserved && setHasBeenObserved(true),\n );\n },\n [setHasBeenObserved, hasBeenObserved],\n );\n\n useEffect(() => {\n const observer = new IntersectionObserver(observerCallback, {\n threshold: hasProductList ? INTERSECTION_OBSERVER_THRESHOLD : 0,\n });\n\n if (intersectionObserverObjectRef.current)\n observer.observe(intersectionObserverObjectRef.current);\n }, [observerCallback, hasProductList]);\n\n return (\n <S.Container>\n <S.Anchor\n id={`${MODEL_COMPARE_V4_ANCHOR}`}\n $scrollOffset={anchorScrollOffset}\n />\n {hasProductList && (\n <ProductList\n isOverviewPage={Boolean(section.isOverviewPage)}\n initialActiveGroup={\n section.products[0]?.productListGroup?.id as ProductListGroupId\n }\n products={section.products}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalSelectedProducts}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n />\n )}\n <CompareTable\n headerStickOffset={headerStickOffset}\n overlayTopOffset={overlayTopOffset}\n showBuyButton={showBuyButton}\n onLinkClick={onLinkClick}\n linkToStoreTitleClick={linkToStoreTitleClick}\n additionalProductData={additionalProductData}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalSelectedProducts={setExternalSelectedProducts}\n section={section}\n products={section.products}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n isOverviewPage={Boolean(section.isOverviewPage)}\n isStaticTable={Boolean(section.isStaticTable)}\n />\n <S.InterSectionObserverObject\n ref={intersectionObserverObjectRef}\n // $hasProductList={hasProductList}\n />\n </S.Container>\n );\n};\n"],"names":["MODEL_COMPARE_V4_ANCHOR","ModelCompareV4","headerStickOffset","overlayTopOffset","showBuyButton","onLinkClick","linkToStoreTitleClick","additionalProductData","section","defaultSelectedProductsCount","selectedProducts","externalSelectedProducts","setSelectedProducts","setExternalSelectedProducts","anchorScrollOffset","hasProductList","useMemo","products","length","isStaticTable","INTERSECTION_OBSERVER_THRESHOLD","intersectionObserverObjectRef","useRef","y","scrollPositionY","useWindowScroll","userIsUnderneathIntersectionObserver","current","getBoundingClientRect","bottom","defaultSelectedProducts","map","product","productId","id","slice","defaultSelectedProductsRef","selectedProductsLimit","SELECTED_PRODUCTS_LIMIT","useState","hasBeenObserved","setHasBeenObserved","showProductGroups","useEffect","observerCallback","useCallback","entries","forEach","entry","isIntersecting","observer","IntersectionObserver","threshold","observe","jsxs","S.Container","children","jsx","S.Anchor","Anchor","$scrollOffset","ProductList","isOverviewPage","Boolean","initialActiveGroup","productListGroup","setExternalState","CompareTable","S.InterSectionObserverObject","InterSectionObserverObject","ref"],"mappings":";;;;;;;;;;AAaO,MAAMA,uBAA0B,GAAA,kBAAA;AAEhC,MAAMC,iBAAiBA,CAAC;EAC7BC,iBAAA;EACAC,gBAAA;EACAC,aAAA;EACAC,WAAA;EACAC,qBAAA;EACAC,qBAAA;EACAC,OAAA;EACAC,4BAA+B,GAAA,CAAA;EAC/BC,gBAAkB,EAAAC,wBAAA;EAClBC,mBAAqB,EAAAC,2BAAA;EACrBC;AACF,CAA2B,KAAA;EACzB,MAAMC,cAAiB,GAAAC,KAAA,CAAAA,OAAA,CACrB,MAAMR,OAAQ,CAAAS,QAAA,CAASC,MAAS,GAAA,CAAA,IAAK,CAACV,OAAQ,CAAAW,aAAA,EAC9C,CAACX,OAAA,CAAQS,QAAU,EAAAT,OAAA,CAAQW,aAAa,CAC1C,CAAA;EAEA,MAAMC,+BAAkC,GAAA,IAAA;EAElC,MAAAC,6BAAA,GAAgCC,aAA8B,IAAI,CAAA;EAExE,MAAM;IAAEC,CAAA,EAAGC;EAAgB,CAAA,GAAIC,wBAAgB,CAAA,CAAA;EAE/C,IAAIC,oCAAuC,GAAA,KAAA;EAGzC,IAAAL,6BAAA,CAA8BM,OAC9B,IAAA,CAACD,oCACD,EAAA;IACAA,oCAAA,GACEL,6BAA8B,CAAAM,OAAA,CAAQC,qBAAsB,CAAA,CAAA,CAAEC,MAC9D,GAAAL,eAAA;EAAA;EAIE,MAAAM,uBAAA,GAA0BtB,OAAQ,CAAAS,QAAA,CACrCc,GAAI,CAACC,OAAa,KAAA;IA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,CAAAvD,OAAA,CAAQsD,cAAc,CAAA;MAC9C3C,aAAA,EAAe4C,OAAQ,CAAAvD,OAAA,CAAQW,aAAa;IAAA,CAC9C,CAAA,EAAA,eACAsC,UAAA,CAAAA,GAAA,CAACW,qBAAE,CAAAC,0BAAA,EAAF;MACCC,GAAK,EAAAjD;IAAA,CAAA,CAAA;GAGT,CAAA;AAEJ,CAAA;;"}
1
+ {"version":3,"file":"ModelCompareV4.js","sources":["../../../src/components/ModelCompareV4/ModelCompareV4.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useWindowScroll } from \"react-use\";\n\nimport type {\n ProductListGroupId,\n SelectedProduct,\n} from \"../../constants/modelCompareData/types\";\nimport { CompareTable } from \"./CompareTable/CompareTable\";\nimport { SELECTED_PRODUCTS_LIMIT } from \"./constants\";\nimport * as S from \"./ModelCompareV4.styles\";\nimport type { ModelCompareV4Props } from \"./ModelCompareV4.types\";\nimport { ProductList } from \"./ProductList/ProductList\";\n\nexport const MODEL_COMPARE_V4_ANCHOR = \"compare-table-v4\";\n\nconst INTERSECTION_OBSERVER_THRESHOLD = 0.35;\n\nexport const ModelCompareV4 = ({\n headerStickOffset,\n overlayTopOffset,\n showBuyButton,\n onLinkClick,\n linkToStoreTitleClick,\n additionalProductData,\n section,\n defaultSelectedProductsCount = 2,\n selectedProducts: externalSelectedProducts,\n setSelectedProducts: setExternalSelectedProducts,\n anchorScrollOffset,\n}: ModelCompareV4Props) => {\n const hasProductList = useMemo(\n () => section.products.length > 5 && !section.isStaticTable,\n [section.products, section.isStaticTable],\n );\n\n const intersectionObserverObjectRef = useRef<HTMLDivElement | null>(null);\n\n const { y: scrollPositionY } = useWindowScroll();\n\n const userIsUnderneathIntersectionObserver = useMemo(() => {\n if (!intersectionObserverObjectRef.current) return false;\n\n return (\n intersectionObserverObjectRef.current.getBoundingClientRect().bottom <\n scrollPositionY\n );\n }, [scrollPositionY]);\n\n /**\n * TODO: Improve the name and logic of this variable and related code.\n * Currently, this variable is used whether ModelCompareV4 has a product list or not.\n * It should only be used if hasProductList is `true`. Why? Because if hasProductList\n * is `false` then selecting/deselecting products isn't possible. The gap between the\n * name of the variable and what it does can be confusing for future devs.\n */\n const defaultSelectedProducts = useMemo(\n () =>\n section.products\n .map((product) => ({ productId: product.id }))\n .slice(\n 0,\n hasProductList\n ? defaultSelectedProductsCount\n : section.products.length,\n ),\n [defaultSelectedProductsCount, hasProductList, section.products],\n );\n /**\n * TODO: rewrite the \"default selected products\" feature so we don't need to use a `useEffect`\n * to update the state of V4. We'll be able to remove this hackie `useRef` as a side-effect.\n */\n const defaultSelectedProductsRef = useRef(defaultSelectedProducts);\n\n const selectedProductsLimit = useMemo(() => {\n return section.products.length < SELECTED_PRODUCTS_LIMIT\n ? section.products.length\n : SELECTED_PRODUCTS_LIMIT;\n }, [section.products.length]);\n\n const [selectedProducts, setSelectedProducts] = useState<SelectedProduct[]>(\n [],\n );\n\n const [hasBeenObserved, setHasBeenObserved] = useState(false);\n\n const showProductGroups = section.showProductGroups !== false;\n\n // #############################################################################\n // Sets selectedProducts value\n // #############################################################################\n\n useEffect(() => {\n defaultSelectedProductsRef.current = defaultSelectedProducts;\n }, [defaultSelectedProducts]);\n\n useEffect(() => {\n setSelectedProducts(\n externalSelectedProducts ||\n (defaultSelectedProductsRef.current as SelectedProduct[]),\n );\n }, [section, externalSelectedProducts]);\n\n // #############################################################################\n // Intersection Observer Logic\n // #############################################################################\n const observerCallback = useCallback<IntersectionObserverCallback>(\n (entries) => {\n entries.forEach(\n (entry) =>\n entry.isIntersecting && !hasBeenObserved && setHasBeenObserved(true),\n );\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [setHasBeenObserved],\n );\n\n useEffect(() => {\n const observer = new IntersectionObserver(observerCallback, {\n threshold: hasProductList ? INTERSECTION_OBSERVER_THRESHOLD : 0,\n });\n\n const intersectionObserverObjectRefCurrent =\n intersectionObserverObjectRef.current;\n\n if (intersectionObserverObjectRefCurrent)\n observer.observe(intersectionObserverObjectRefCurrent);\n\n return () => {\n if (intersectionObserverObjectRefCurrent) {\n observer.unobserve(intersectionObserverObjectRefCurrent);\n observer.disconnect();\n }\n };\n }, [observerCallback, hasProductList]);\n\n return (\n <S.Container>\n <S.Anchor\n id={`${MODEL_COMPARE_V4_ANCHOR}`}\n $scrollOffset={anchorScrollOffset}\n />\n {hasProductList && (\n <ProductList\n isOverviewPage={Boolean(section.isOverviewPage)}\n initialActiveGroup={\n section.products[0]?.productListGroup?.id as ProductListGroupId\n }\n products={section.products}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalSelectedProducts}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n />\n )}\n <CompareTable\n headerStickOffset={headerStickOffset}\n overlayTopOffset={overlayTopOffset}\n showBuyButton={showBuyButton}\n onLinkClick={onLinkClick}\n linkToStoreTitleClick={linkToStoreTitleClick}\n additionalProductData={additionalProductData}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalSelectedProducts={setExternalSelectedProducts}\n section={section}\n products={section.products}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n isOverviewPage={Boolean(section.isOverviewPage)}\n isStaticTable={Boolean(section.isStaticTable)}\n />\n <S.InterSectionObserverObject\n ref={intersectionObserverObjectRef}\n // $hasProductList={hasProductList}\n />\n </S.Container>\n );\n};\n"],"names":["MODEL_COMPARE_V4_ANCHOR","INTERSECTION_OBSERVER_THRESHOLD","ModelCompareV4","headerStickOffset","overlayTopOffset","showBuyButton","onLinkClick","linkToStoreTitleClick","additionalProductData","section","defaultSelectedProductsCount","selectedProducts","externalSelectedProducts","setSelectedProducts","setExternalSelectedProducts","anchorScrollOffset","hasProductList","useMemo","products","length","isStaticTable","intersectionObserverObjectRef","useRef","y","scrollPositionY","useWindowScroll","userIsUnderneathIntersectionObserver","current","getBoundingClientRect","bottom","defaultSelectedProducts","map","product","productId","id","slice","defaultSelectedProductsRef","selectedProductsLimit","SELECTED_PRODUCTS_LIMIT","useState","hasBeenObserved","setHasBeenObserved","showProductGroups","useEffect","observerCallback","useCallback","entries","forEach","entry","isIntersecting","observer","IntersectionObserver","threshold","intersectionObserverObjectRefCurrent","observe","unobserve","disconnect","jsxs","S.Container","children","jsx","S.Anchor","Anchor","$scrollOffset","ProductList","isOverviewPage","Boolean","initialActiveGroup","productListGroup","setExternalState","CompareTable","S.InterSectionObserverObject","InterSectionObserverObject","ref"],"mappings":";;;;;;;;;;AAaO,MAAMA,uBAA0B,GAAA,kBAAA;AAEvC,MAAMC,+BAAkC,GAAA,IAAA;AAEjC,MAAMC,iBAAiBA,CAAC;EAC7BC,iBAAA;EACAC,gBAAA;EACAC,aAAA;EACAC,WAAA;EACAC,qBAAA;EACAC,qBAAA;EACAC,OAAA;EACAC,4BAA+B,GAAA,CAAA;EAC/BC,gBAAkB,EAAAC,wBAAA;EAClBC,mBAAqB,EAAAC,2BAAA;EACrBC;AACF,CAA2B,KAAA;EACzB,MAAMC,cAAiB,GAAAC,KAAA,CAAAA,OAAA,CACrB,MAAMR,OAAQ,CAAAS,QAAA,CAASC,MAAS,GAAA,CAAA,IAAK,CAACV,OAAQ,CAAAW,aAAA,EAC9C,CAACX,OAAA,CAAQS,QAAU,EAAAT,OAAA,CAAQW,aAAa,CAC1C,CAAA;EAEM,MAAAC,6BAAA,GAAgCC,aAA8B,IAAI,CAAA;EAExE,MAAM;IAAEC,CAAA,EAAGC;EAAgB,CAAA,GAAIC,wBAAgB,CAAA,CAAA;EAEzC,MAAAC,oCAAA,GAAuCT,KAAAA,CAAAA,QAAQ,MAAM;IACrD,IAAA,CAACI,6BAA8B,CAAAM,OAAA,EAA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EAAA;MAEzChB,UAAUT,OAAQ,CAAAS,QAAA;MAClBP,gBAAA;MACAE,mBAAA;MACAwD,gBAAkB,EAAAvD,2BAAA;MAElB0B,iBACEA,eAAmB,IAAAd,oCAAA;MAErBW,qBAAA;MACAK;IAAA,CACF,CAAA,EAAA,eAEFkB,UAAA,CAAAA,GAAA,CAACU,YAAA,CAAAA,YAAA,EAAA;MACCnE,iBAAA;MACAC,gBAAA;MACAC,aAAA;MACAC,WAAA;MACAC,qBAAA;MACAC,qBAAA;MACAG,gBAAA;MACAE,mBAAA;MACAC,2BAAA;MACAL,OAAA;MACAS,UAAUT,OAAQ,CAAAS,QAAA;MAElBsB,iBACEA,eAAmB,IAAAd,oCAAA;MAErBW,qBAAA;MACA4B,cAAA,EAAgBC,OAAQ,CAAAzD,OAAA,CAAQwD,cAAc,CAAA;MAC9C7C,aAAA,EAAe8C,OAAQ,CAAAzD,OAAA,CAAQW,aAAa;IAAA,CAC9C,CAAA,EAAA,eACAwC,UAAA,CAAAA,GAAA,CAACW,qBAAE,CAAAC,0BAAA,EAAF;MACCC,GAAK,EAAApD;IAAA,CAAA,CAAA;GAGT,CAAA;AAEJ,CAAA;;"}
@@ -7,6 +7,7 @@ import { Container, Anchor, InterSectionObserverObject } from './ModelCompareV4.
7
7
  import { ProductList } from './ProductList/ProductList.mjs';
8
8
  "use strict";
9
9
  const MODEL_COMPARE_V4_ANCHOR = "compare-table-v4";
10
+ const INTERSECTION_OBSERVER_THRESHOLD = 0.35;
10
11
  const ModelCompareV4 = ({
11
12
  headerStickOffset,
12
13
  overlayTopOffset,
@@ -21,18 +22,17 @@ const ModelCompareV4 = ({
21
22
  anchorScrollOffset
22
23
  }) => {
23
24
  const hasProductList = useMemo(() => section.products.length > 5 && !section.isStaticTable, [section.products, section.isStaticTable]);
24
- const INTERSECTION_OBSERVER_THRESHOLD = 0.35;
25
25
  const intersectionObserverObjectRef = useRef(null);
26
26
  const {
27
27
  y: scrollPositionY
28
28
  } = useWindowScroll();
29
- let userIsUnderneathIntersectionObserver = false;
30
- if (intersectionObserverObjectRef.current && !userIsUnderneathIntersectionObserver) {
31
- userIsUnderneathIntersectionObserver = intersectionObserverObjectRef.current.getBoundingClientRect().bottom < scrollPositionY;
32
- }
33
- const defaultSelectedProducts = section.products.map(product => ({
29
+ const userIsUnderneathIntersectionObserver = useMemo(() => {
30
+ if (!intersectionObserverObjectRef.current) return false;
31
+ return intersectionObserverObjectRef.current.getBoundingClientRect().bottom < scrollPositionY;
32
+ }, [scrollPositionY]);
33
+ const defaultSelectedProducts = useMemo(() => section.products.map(product => ({
34
34
  productId: product.id
35
- })).slice(0, hasProductList ? defaultSelectedProductsCount : section.products.length);
35
+ })).slice(0, hasProductList ? defaultSelectedProductsCount : section.products.length), [defaultSelectedProductsCount, hasProductList, section.products]);
36
36
  const defaultSelectedProductsRef = useRef(defaultSelectedProducts);
37
37
  const selectedProductsLimit = useMemo(() => {
38
38
  return section.products.length < SELECTED_PRODUCTS_LIMIT ? section.products.length : SELECTED_PRODUCTS_LIMIT;
@@ -48,12 +48,21 @@ const ModelCompareV4 = ({
48
48
  }, [section, externalSelectedProducts]);
49
49
  const observerCallback = useCallback(entries => {
50
50
  entries.forEach(entry => entry.isIntersecting && !hasBeenObserved && setHasBeenObserved(true));
51
- }, [setHasBeenObserved, hasBeenObserved]);
51
+ },
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ [setHasBeenObserved]);
52
54
  useEffect(() => {
53
55
  const observer = new IntersectionObserver(observerCallback, {
54
56
  threshold: hasProductList ? INTERSECTION_OBSERVER_THRESHOLD : 0
55
57
  });
56
- if (intersectionObserverObjectRef.current) observer.observe(intersectionObserverObjectRef.current);
58
+ const intersectionObserverObjectRefCurrent = intersectionObserverObjectRef.current;
59
+ if (intersectionObserverObjectRefCurrent) observer.observe(intersectionObserverObjectRefCurrent);
60
+ return () => {
61
+ if (intersectionObserverObjectRefCurrent) {
62
+ observer.unobserve(intersectionObserverObjectRefCurrent);
63
+ observer.disconnect();
64
+ }
65
+ };
57
66
  }, [observerCallback, hasProductList]);
58
67
  return /* @__PURE__ */jsxs(Container, {
59
68
  children: [/* @__PURE__ */jsx(Anchor, {
@@ -1 +1 @@
1
- {"version":3,"file":"ModelCompareV4.mjs","sources":["../../../src/components/ModelCompareV4/ModelCompareV4.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useWindowScroll } from \"react-use\";\n\nimport type {\n ProductListGroupId,\n SelectedProduct,\n} from \"../../constants/modelCompareData/types\";\nimport { CompareTable } from \"./CompareTable/CompareTable\";\nimport { SELECTED_PRODUCTS_LIMIT } from \"./constants\";\nimport * as S from \"./ModelCompareV4.styles\";\nimport type { ModelCompareV4Props } from \"./ModelCompareV4.types\";\nimport { ProductList } from \"./ProductList/ProductList\";\n\nexport const MODEL_COMPARE_V4_ANCHOR = \"compare-table-v4\";\n\nexport const ModelCompareV4 = ({\n headerStickOffset,\n overlayTopOffset,\n showBuyButton,\n onLinkClick,\n linkToStoreTitleClick,\n additionalProductData,\n section,\n defaultSelectedProductsCount = 2,\n selectedProducts: externalSelectedProducts,\n setSelectedProducts: setExternalSelectedProducts,\n anchorScrollOffset,\n}: ModelCompareV4Props) => {\n const hasProductList = useMemo(\n () => section.products.length > 5 && !section.isStaticTable,\n [section.products, section.isStaticTable],\n );\n\n const INTERSECTION_OBSERVER_THRESHOLD = 0.35;\n\n const intersectionObserverObjectRef = useRef<HTMLDivElement | null>(null);\n\n const { y: scrollPositionY } = useWindowScroll();\n\n let userIsUnderneathIntersectionObserver = false;\n\n if (\n intersectionObserverObjectRef.current &&\n !userIsUnderneathIntersectionObserver\n ) {\n userIsUnderneathIntersectionObserver =\n intersectionObserverObjectRef.current.getBoundingClientRect().bottom <\n scrollPositionY;\n }\n\n // TODO: Improve the name and logic of this variable and related code. Currently, this variable is used whether ModelCompareV4 has a product list or not. It should only be used if hasProductList is `true`. Why? Because if hasProductList is `false` then selecting/deselecting products isn't possible. The gap between the name of the variable and what it does can be confusing for future devs.\n const defaultSelectedProducts = section.products\n .map((product) => ({ productId: product.id }))\n .slice(\n 0,\n hasProductList ? defaultSelectedProductsCount : section.products.length,\n );\n // TODO: rewrite the \"default selected products\" feature so we don't need to use a `useEffect` to update the state of V4. We'll be able to remove this hackie `useRef` as a side-effect.\n const defaultSelectedProductsRef = useRef(defaultSelectedProducts);\n\n const selectedProductsLimit = useMemo(() => {\n return section.products.length < SELECTED_PRODUCTS_LIMIT\n ? section.products.length\n : SELECTED_PRODUCTS_LIMIT;\n }, [section.products.length]);\n\n const [selectedProducts, setSelectedProducts] = useState<SelectedProduct[]>(\n [],\n );\n\n const [hasBeenObserved, setHasBeenObserved] = useState(false);\n\n const showProductGroups = section.showProductGroups !== false;\n\n // #############################################################################\n // Sets selectedProducts value\n // #############################################################################\n\n useEffect(() => {\n defaultSelectedProductsRef.current = defaultSelectedProducts;\n }, [defaultSelectedProducts]);\n\n useEffect(() => {\n setSelectedProducts(\n externalSelectedProducts ||\n (defaultSelectedProductsRef.current as SelectedProduct[]),\n );\n }, [section, externalSelectedProducts]);\n\n // #############################################################################\n // Intersection Observer Logic\n // #############################################################################\n\n const observerCallback = useCallback<IntersectionObserverCallback>(\n (entries) => {\n entries.forEach(\n (entry) =>\n entry.isIntersecting && !hasBeenObserved && setHasBeenObserved(true),\n );\n },\n [setHasBeenObserved, hasBeenObserved],\n );\n\n useEffect(() => {\n const observer = new IntersectionObserver(observerCallback, {\n threshold: hasProductList ? INTERSECTION_OBSERVER_THRESHOLD : 0,\n });\n\n if (intersectionObserverObjectRef.current)\n observer.observe(intersectionObserverObjectRef.current);\n }, [observerCallback, hasProductList]);\n\n return (\n <S.Container>\n <S.Anchor\n id={`${MODEL_COMPARE_V4_ANCHOR}`}\n $scrollOffset={anchorScrollOffset}\n />\n {hasProductList && (\n <ProductList\n isOverviewPage={Boolean(section.isOverviewPage)}\n initialActiveGroup={\n section.products[0]?.productListGroup?.id as ProductListGroupId\n }\n products={section.products}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalSelectedProducts}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n />\n )}\n <CompareTable\n headerStickOffset={headerStickOffset}\n overlayTopOffset={overlayTopOffset}\n showBuyButton={showBuyButton}\n onLinkClick={onLinkClick}\n linkToStoreTitleClick={linkToStoreTitleClick}\n additionalProductData={additionalProductData}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalSelectedProducts={setExternalSelectedProducts}\n section={section}\n products={section.products}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n isOverviewPage={Boolean(section.isOverviewPage)}\n isStaticTable={Boolean(section.isStaticTable)}\n />\n <S.InterSectionObserverObject\n ref={intersectionObserverObjectRef}\n // $hasProductList={hasProductList}\n />\n </S.Container>\n );\n};\n"],"names":["MODEL_COMPARE_V4_ANCHOR","ModelCompareV4","headerStickOffset","overlayTopOffset","showBuyButton","onLinkClick","linkToStoreTitleClick","additionalProductData","section","defaultSelectedProductsCount","selectedProducts","externalSelectedProducts","setSelectedProducts","setExternalSelectedProducts","anchorScrollOffset","hasProductList","useMemo","products","length","isStaticTable","INTERSECTION_OBSERVER_THRESHOLD","intersectionObserverObjectRef","useRef","y","scrollPositionY","useWindowScroll","userIsUnderneathIntersectionObserver","current","getBoundingClientRect","bottom","defaultSelectedProducts","map","product","productId","id","slice","defaultSelectedProductsRef","selectedProductsLimit","SELECTED_PRODUCTS_LIMIT","useState","hasBeenObserved","setHasBeenObserved","showProductGroups","useEffect","observerCallback","useCallback","entries","forEach","entry","isIntersecting","observer","IntersectionObserver","threshold","observe","jsxs","S.Container","children","jsx","S.Anchor","$scrollOffset","ProductList","isOverviewPage","Boolean","initialActiveGroup","productListGroup","setExternalState","CompareTable","S.InterSectionObserverObject","ref"],"mappings":";;;;;;;;AAaO,MAAMA,uBAA0B,GAAA,kBAAA;AAEhC,MAAMC,iBAAiBA,CAAC;EAC7BC,iBAAA;EACAC,gBAAA;EACAC,aAAA;EACAC,WAAA;EACAC,qBAAA;EACAC,qBAAA;EACAC,OAAA;EACAC,4BAA+B,GAAA,CAAA;EAC/BC,gBAAkB,EAAAC,wBAAA;EAClBC,mBAAqB,EAAAC,2BAAA;EACrBC;AACF,CAA2B,KAAA;EACzB,MAAMC,cAAiB,GAAAC,OAAA,CACrB,MAAMR,OAAQ,CAAAS,QAAA,CAASC,MAAS,GAAA,CAAA,IAAK,CAACV,OAAQ,CAAAW,aAAA,EAC9C,CAACX,OAAA,CAAQS,QAAU,EAAAT,OAAA,CAAQW,aAAa,CAC1C,CAAA;EAEA,MAAMC,+BAAkC,GAAA,IAAA;EAElC,MAAAC,6BAAA,GAAgCC,OAA8B,IAAI,CAAA;EAExE,MAAM;IAAEC,CAAA,EAAGC;EAAgB,CAAA,GAAIC,eAAgB,CAAA,CAAA;EAE/C,IAAIC,oCAAuC,GAAA,KAAA;EAGzC,IAAAL,6BAAA,CAA8BM,OAC9B,IAAA,CAACD,oCACD,EAAA;IACAA,oCAAA,GACEL,6BAA8B,CAAAM,OAAA,CAAQC,qBAAsB,CAAA,CAAA,CAAEC,MAC9D,GAAAL,eAAA;EAAA;EAIE,MAAAM,uBAAA,GAA0BtB,OAAQ,CAAAS,QAAA,CACrCc,GAAI,CAACC,OAAa,KAAA;IAAEC,SAAW,EAAAD,OAAA,CAAQE;EAAG,CAAA,CAAE,CAC5C,CAAAC,KAAA,CACC,CAAA,EACApB,cAAA,GAAiBN,4BAA+B,GAAAD,OAAA,CAAQS,QAAS,CAAAC,MACnE,CAAA;EAEI,MAAAkB,0BAAA,GAA6Bd,OAAOQ,uBAAuB,CAAA;EAE3D,MAAAO,qBAAA,G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CC,QAAA,EAAA,CAAA,eAAAC,GAAA,CAACC,MAAE,EAAF;MACCxB,EAAA,EAAI,GAAGlC,uBAAuB,EAAA;MAC9B2D,aAAe,EAAA7C;IAAA,CACjB,CAAA,EACCC,cACC,mBAAA0C,GAAA,CAACG,WAAA,EAAA;MACCC,cAAA,EAAgBC,OAAQ,CAAAtD,OAAA,CAAQqD,cAAc,CAAA;MAC9CE,kBACE,EAAAvD,OAAA,CAAQS,QAAS,CAAA,CAAC,GAAG+C,gBAAkB,EAAA9B,EAAA;MAEzCjB,UAAUT,OAAQ,CAAAS,QAAA;MAClBP,gBAAA;MACAE,mBAAA;MACAqD,gBAAkB,EAAApD,2BAAA;MAElB2B,iBACEA,eAAmB,IAAAd,oCAAA;MAErBW,qBAAA;MACAK;IAAA,CACF,CAAA,EAAA,eAEFe,GAAA,CAACS,YAAA,EAAA;MACChE,iBAAA;MACAC,gBAAA;MACAC,aAAA;MACAC,WAAA;MACAC,qBAAA;MACAC,qBAAA;MACAG,gBAAA;MACAE,mBAAA;MACAC,2BAAA;MACAL,OAAA;MACAS,UAAUT,OAAQ,CAAAS,QAAA;MAElBuB,iBACEA,eAAmB,IAAAd,oCAAA;MAErBW,qBAAA;MACAwB,cAAA,EAAgBC,OAAQ,CAAAtD,OAAA,CAAQqD,cAAc,CAAA;MAC9C1C,aAAA,EAAe2C,OAAQ,CAAAtD,OAAA,CAAQW,aAAa;IAAA,CAC9C,CAAA,EAAA,eACAsC,GAAA,CAACU,0BAAE,EAAF;MACCC,GAAK,EAAA/C;IAAA,CAAA,CAAA;GAGT,CAAA;AAEJ,CAAA;"}
1
+ {"version":3,"file":"ModelCompareV4.mjs","sources":["../../../src/components/ModelCompareV4/ModelCompareV4.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useWindowScroll } from \"react-use\";\n\nimport type {\n ProductListGroupId,\n SelectedProduct,\n} from \"../../constants/modelCompareData/types\";\nimport { CompareTable } from \"./CompareTable/CompareTable\";\nimport { SELECTED_PRODUCTS_LIMIT } from \"./constants\";\nimport * as S from \"./ModelCompareV4.styles\";\nimport type { ModelCompareV4Props } from \"./ModelCompareV4.types\";\nimport { ProductList } from \"./ProductList/ProductList\";\n\nexport const MODEL_COMPARE_V4_ANCHOR = \"compare-table-v4\";\n\nconst INTERSECTION_OBSERVER_THRESHOLD = 0.35;\n\nexport const ModelCompareV4 = ({\n headerStickOffset,\n overlayTopOffset,\n showBuyButton,\n onLinkClick,\n linkToStoreTitleClick,\n additionalProductData,\n section,\n defaultSelectedProductsCount = 2,\n selectedProducts: externalSelectedProducts,\n setSelectedProducts: setExternalSelectedProducts,\n anchorScrollOffset,\n}: ModelCompareV4Props) => {\n const hasProductList = useMemo(\n () => section.products.length > 5 && !section.isStaticTable,\n [section.products, section.isStaticTable],\n );\n\n const intersectionObserverObjectRef = useRef<HTMLDivElement | null>(null);\n\n const { y: scrollPositionY } = useWindowScroll();\n\n const userIsUnderneathIntersectionObserver = useMemo(() => {\n if (!intersectionObserverObjectRef.current) return false;\n\n return (\n intersectionObserverObjectRef.current.getBoundingClientRect().bottom <\n scrollPositionY\n );\n }, [scrollPositionY]);\n\n /**\n * TODO: Improve the name and logic of this variable and related code.\n * Currently, this variable is used whether ModelCompareV4 has a product list or not.\n * It should only be used if hasProductList is `true`. Why? Because if hasProductList\n * is `false` then selecting/deselecting products isn't possible. The gap between the\n * name of the variable and what it does can be confusing for future devs.\n */\n const defaultSelectedProducts = useMemo(\n () =>\n section.products\n .map((product) => ({ productId: product.id }))\n .slice(\n 0,\n hasProductList\n ? defaultSelectedProductsCount\n : section.products.length,\n ),\n [defaultSelectedProductsCount, hasProductList, section.products],\n );\n /**\n * TODO: rewrite the \"default selected products\" feature so we don't need to use a `useEffect`\n * to update the state of V4. We'll be able to remove this hackie `useRef` as a side-effect.\n */\n const defaultSelectedProductsRef = useRef(defaultSelectedProducts);\n\n const selectedProductsLimit = useMemo(() => {\n return section.products.length < SELECTED_PRODUCTS_LIMIT\n ? section.products.length\n : SELECTED_PRODUCTS_LIMIT;\n }, [section.products.length]);\n\n const [selectedProducts, setSelectedProducts] = useState<SelectedProduct[]>(\n [],\n );\n\n const [hasBeenObserved, setHasBeenObserved] = useState(false);\n\n const showProductGroups = section.showProductGroups !== false;\n\n // #############################################################################\n // Sets selectedProducts value\n // #############################################################################\n\n useEffect(() => {\n defaultSelectedProductsRef.current = defaultSelectedProducts;\n }, [defaultSelectedProducts]);\n\n useEffect(() => {\n setSelectedProducts(\n externalSelectedProducts ||\n (defaultSelectedProductsRef.current as SelectedProduct[]),\n );\n }, [section, externalSelectedProducts]);\n\n // #############################################################################\n // Intersection Observer Logic\n // #############################################################################\n const observerCallback = useCallback<IntersectionObserverCallback>(\n (entries) => {\n entries.forEach(\n (entry) =>\n entry.isIntersecting && !hasBeenObserved && setHasBeenObserved(true),\n );\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [setHasBeenObserved],\n );\n\n useEffect(() => {\n const observer = new IntersectionObserver(observerCallback, {\n threshold: hasProductList ? INTERSECTION_OBSERVER_THRESHOLD : 0,\n });\n\n const intersectionObserverObjectRefCurrent =\n intersectionObserverObjectRef.current;\n\n if (intersectionObserverObjectRefCurrent)\n observer.observe(intersectionObserverObjectRefCurrent);\n\n return () => {\n if (intersectionObserverObjectRefCurrent) {\n observer.unobserve(intersectionObserverObjectRefCurrent);\n observer.disconnect();\n }\n };\n }, [observerCallback, hasProductList]);\n\n return (\n <S.Container>\n <S.Anchor\n id={`${MODEL_COMPARE_V4_ANCHOR}`}\n $scrollOffset={anchorScrollOffset}\n />\n {hasProductList && (\n <ProductList\n isOverviewPage={Boolean(section.isOverviewPage)}\n initialActiveGroup={\n section.products[0]?.productListGroup?.id as ProductListGroupId\n }\n products={section.products}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalSelectedProducts}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n />\n )}\n <CompareTable\n headerStickOffset={headerStickOffset}\n overlayTopOffset={overlayTopOffset}\n showBuyButton={showBuyButton}\n onLinkClick={onLinkClick}\n linkToStoreTitleClick={linkToStoreTitleClick}\n additionalProductData={additionalProductData}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalSelectedProducts={setExternalSelectedProducts}\n section={section}\n products={section.products}\n // TODO: rename this property now that `userIsUnderneathIntersectionObserver` has been added\n hasBeenObserved={\n hasBeenObserved || userIsUnderneathIntersectionObserver\n }\n selectedProductsLimit={selectedProductsLimit}\n isOverviewPage={Boolean(section.isOverviewPage)}\n isStaticTable={Boolean(section.isStaticTable)}\n />\n <S.InterSectionObserverObject\n ref={intersectionObserverObjectRef}\n // $hasProductList={hasProductList}\n />\n </S.Container>\n );\n};\n"],"names":["MODEL_COMPARE_V4_ANCHOR","INTERSECTION_OBSERVER_THRESHOLD","ModelCompareV4","headerStickOffset","overlayTopOffset","showBuyButton","onLinkClick","linkToStoreTitleClick","additionalProductData","section","defaultSelectedProductsCount","selectedProducts","externalSelectedProducts","setSelectedProducts","setExternalSelectedProducts","anchorScrollOffset","hasProductList","useMemo","products","length","isStaticTable","intersectionObserverObjectRef","useRef","y","scrollPositionY","useWindowScroll","userIsUnderneathIntersectionObserver","current","getBoundingClientRect","bottom","defaultSelectedProducts","map","product","productId","id","slice","defaultSelectedProductsRef","selectedProductsLimit","SELECTED_PRODUCTS_LIMIT","useState","hasBeenObserved","setHasBeenObserved","showProductGroups","useEffect","observerCallback","useCallback","entries","forEach","entry","isIntersecting","observer","IntersectionObserver","threshold","intersectionObserverObjectRefCurrent","observe","unobserve","disconnect","jsxs","S.Container","children","jsx","S.Anchor","$scrollOffset","ProductList","isOverviewPage","Boolean","initialActiveGroup","productListGroup","setExternalState","CompareTable","S.InterSectionObserverObject","ref"],"mappings":";;;;;;;;AAaO,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axScroll = require('./useIsAtMaxScroll.js');
13
13
  var ButtonGroup = require('./components/ButtonGroup/ButtonGroup.js');
14
14
  "use strict";
15
+ const CHECK_FOR_SCROLL_TIMEOUT = 150;
15
16
  const ProductList = ({
16
17
  products,
17
18
  selectedProducts,
@@ -23,7 +24,7 @@ const ProductList = ({
23
24
  showProductGroups,
24
25
  isOverviewPage
25
26
  }) => {
26
- const groupedGroups = groupProducts.groupProducts(products);
27
+ const groupedGroups = React.useMemo(() => groupProducts.groupProducts(products), [products]);
27
28
  const moreThanOneGroupExists = groupedGroups.length > 1;
28
29
  const containerRef = React.useRef(null);
29
30
  const productListRef = React.useRef(null);
@@ -34,7 +35,6 @@ const ProductList = ({
34
35
  const [isDragging, setIsDragging] = React.useState(false);
35
36
  const [overflowExists, setOverflowExists] = React.useState(true);
36
37
  const [endPosition, setEndPosition] = React.useState(0);
37
- const checkForScrollTimeout = 150;
38
38
  reactUse.useEffectOnce(() => {
39
39
  const refsExist = containerRef.current && productListRef.current;
40
40
  if (refsExist && containerRef.current?.getBoundingClientRect().width < productListRef.current?.getBoundingClientRect().width) {
@@ -53,14 +53,18 @@ const ProductList = ({
53
53
  }, [hasBeenObserved, setPlayAnimation, showProductGroups]);
54
54
  React.useEffect(() => {
55
55
  const productListInitialPosition = productListRef.current?.getBoundingClientRect().left;
56
+ let timeoutId;
56
57
  if (hasBeenObserved || buttonHasBeenClick) {
57
- setTimeout(() => {
58
+ timeoutId = setTimeout(() => {
58
59
  const currentPosition = productListRef.current?.getBoundingClientRect().left;
59
60
  if (productListInitialPosition === currentPosition) {
60
61
  return setPlayAnimation(true);
61
62
  }
62
- }, checkForScrollTimeout);
63
+ }, CHECK_FOR_SCROLL_TIMEOUT);
63
64
  }
65
+ return () => {
66
+ clearTimeout(timeoutId);
67
+ };
64
68
  }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);
65
69
  const dragStartingPosition = React.useRef(0);
66
70
  const scrollAmount = React.useRef(0);
@@ -97,7 +101,7 @@ const ProductList = ({
97
101
  isScrolling = setTimeout(function () {
98
102
  setPlayAnimation(true);
99
103
  setEndPosition(containerRef.current?.scrollLeft);
100
- }, checkForScrollTimeout);
104
+ }, CHECK_FOR_SCROLL_TIMEOUT);
101
105
  };
102
106
  containerRef.current.addEventListener("scroll", checkIsScrolling);
103
107
  return () => {
@@ -125,8 +129,8 @@ const ProductList = ({
125
129
  if (checkForScroll()) {
126
130
  setPlayAnimation(true);
127
131
  }
128
- }, checkForScrollTimeout);
129
- }, [containerRef, setPlayAnimation, setActiveGroup, checkForScrollTimeout]);
132
+ }, CHECK_FOR_SCROLL_TIMEOUT);
133
+ }, [containerRef, setPlayAnimation, setActiveGroup]);
130
134
  const scrollButtonHandler = ({
131
135
  isLeftArrow
132
136
  }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ProductList.js","sources":["../../../../src/components/ModelCompareV4/ProductList/ProductList.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useEffectOnce, useHoverDirty } from \"react-use\";\n\nimport type {\n ProductId,\n ProductListGroupId,\n} from \"../../../constants/modelCompareData/types\";\nimport { ButtonGroup } from \"./components/ButtonGroup\";\nimport { Product } from \"./components/Product/Product\";\nimport { groupProducts } from \"./components/ProductGroups/groupProducts\";\nimport { ProductGroups } from \"./components/ProductGroups/ProductGroups\";\nimport { ScrollButton } from \"./components/ScrollButton/ScrollButton\";\nimport * as S from \"./ProductList.styles\";\nimport type { ProductListProps } from \"./ProductList.types\";\nimport { useIsAtMaxScroll } from \"./useIsAtMaxScroll\";\n\nexport const ProductList = ({\n products,\n selectedProducts,\n setSelectedProducts,\n hasBeenObserved,\n selectedProductsLimit,\n initialActiveGroup,\n setExternalState,\n showProductGroups,\n isOverviewPage,\n}: ProductListProps) => {\n const groupedGroups = groupProducts(products);\n const moreThanOneGroupExists = groupedGroups.length > 1;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const productListRef = useRef<HTMLDivElement>(null);\n\n const [buttonHasBeenClick, setButtonHasBeenClicked] = useState(false);\n const [activeGroup, setActiveGroup] = useState(initialActiveGroup);\n const [playAnimation, setPlayAnimation] = useState(false);\n const isHovering = useHoverDirty(containerRef);\n const [isDragging, setIsDragging] = useState(false);\n const [overflowExists, setOverflowExists] = useState(true);\n const [endPosition, setEndPosition] = useState<number>(0);\n const checkForScrollTimeout = 150;\n\n useEffectOnce(() => {\n const refsExist = containerRef.current && productListRef.current;\n if (\n refsExist &&\n containerRef.current?.getBoundingClientRect().width <\n productListRef.current?.getBoundingClientRect().width\n ) {\n setOverflowExists(true);\n } else {\n setOverflowExists(false);\n }\n });\n\n // TODO: figure out how to remove this TODO. Currently, without this `useEffect` `activeGroup` isn't updating when toggling between different tables (`Section`s).\n // ModelCompareV4 is sometimes used to toggle between sets of data of type Section. In this situation, we need the initial active group to be updated when the new data is passed to ModelCompareV4\n useEffect(() => {\n setActiveGroup(products[0]?.productListGroup?.id as ProductListGroupId);\n }, [products]);\n\n // #############################################################################\n // Scroll-Specific useEffects\n // #############################################################################\n\n // if there aren't any product list group buttons then the ending state of the animations need to exist on the initial render\n useEffect(() => {\n if (!showProductGroups && hasBeenObserved) {\n setPlayAnimation(true);\n }\n }, [hasBeenObserved, setPlayAnimation, showProductGroups]);\n\n // plays animation when no scroll has occurred on the initial observe\n useEffect(() => {\n const productListInitialPosition =\n productListRef.current?.getBoundingClientRect().left;\n\n if (hasBeenObserved || buttonHasBeenClick) {\n setTimeout(() => {\n const currentPosition =\n productListRef.current?.getBoundingClientRect().left;\n if (productListInitialPosition === currentPosition) {\n return setPlayAnimation(true);\n }\n }, checkForScrollTimeout);\n }\n }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);\n\n // #############################################################################\n // Drag Logic\n // #############################################################################\n const dragStartingPosition = useRef(0);\n const scrollAmount = useRef(0);\n\n const dragHandler = useCallback(\n (event: MouseEvent) => {\n scrollAmount.current = dragStartingPosition.current - event.clientX;\n containerRef.current?.scrollTo(endPosition + scrollAmount.current, 0);\n },\n [endPosition],\n );\n\n const mouseUpHandler = useCallback(() => {\n setIsDragging(false);\n setEndPosition(containerRef.current?.scrollLeft ?? 0);\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n }, [dragHandler]);\n\n const mouseDownHandler = useCallback(\n (event: React.MouseEvent<Element, MouseEvent>) => {\n if (event.buttons === 1) {\n dragStartingPosition.current = event.clientX;\n setIsDragging(true);\n document.addEventListener(\"mousemove\", dragHandler);\n document.addEventListener(\"mouseup\", mouseUpHandler);\n }\n },\n [dragHandler, mouseUpHandler],\n );\n\n // Add cleanup for drag handlers on unmount\n useEffect(() => {\n return () => {\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n };\n }, [dragHandler, mouseUpHandler]);\n\n useEffect(() => {\n const container = containerRef.current;\n\n if (!container) return;\n\n let isScrolling: NodeJS.Timeout;\n\n const checkIsScrolling = () => {\n window.clearTimeout(isScrolling);\n\n // if scrolling occurs, animations are played after scrolling has completed\n // if scrolling occurs, the container's end position is tracked in state after scrolling has completed\n isScrolling = setTimeout(function () {\n setPlayAnimation(true);\n setEndPosition(containerRef.current?.scrollLeft as number);\n }, checkForScrollTimeout);\n };\n\n (containerRef.current as HTMLDivElement).addEventListener(\n \"scroll\",\n checkIsScrolling,\n );\n\n return () => {\n window.removeEventListener(\"resize\", checkIsScrolling);\n };\n }, []); // Empty dependency array since we want this to run once\n\n // #############################################################################\n // Click to Scroll Logic\n // #############################################################################\n\n const tabClickHandler = useCallback(\n ({ groupId }: { groupId: ProductListGroupId }) => {\n const initialScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n const checkForScroll = () => {\n const currentScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n return currentScrollPosition === initialScrollPosition;\n };\n\n const element = document.getElementById(groupId) as HTMLDivElement;\n\n setPlayAnimation(false);\n setActiveGroup(groupId);\n setButtonHasBeenClicked(true);\n element?.scrollIntoView({\n behavior: \"smooth\",\n inline: \"start\",\n block: \"nearest\",\n });\n\n // if no scroll occurs animations are played\n setTimeout(() => {\n if (checkForScroll()) {\n setPlayAnimation(true);\n }\n }, checkForScrollTimeout);\n },\n [containerRef, setPlayAnimation, setActiveGroup, checkForScrollTimeout],\n );\n\n const scrollButtonHandler = ({ isLeftArrow }: { isLeftArrow?: boolean }) => {\n if (containerRef.current) {\n const currentScrollPosition = containerRef.current?.scrollLeft;\n\n const scrollLength = isLeftArrow\n ? currentScrollPosition - S.PRODUCT_CARD_WIDTH - S.PRODUCT_LIST_GRID_GAP\n : currentScrollPosition +\n S.PRODUCT_CARD_WIDTH +\n S.PRODUCT_LIST_GRID_GAP;\n\n containerRef.current?.scrollTo(scrollLength, 0);\n }\n };\n\n const { isMaxLeft, isMaxRight } = useIsAtMaxScroll(containerRef);\n\n return (\n <S.Wrapper>\n {showProductGroups && moreThanOneGroupExists && (\n <ButtonGroup\n items={groupedGroups.map((group) => group.productListGroup)}\n activeButton={activeGroup as string}\n onClick={(id) => {\n tabClickHandler({ groupId: id as ProductListGroupId });\n }}\n />\n )}\n <S.Container\n ref={containerRef}\n $isHovering={isHovering}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n $isDragging={isDragging}\n >\n <S.ProductGroupProductListContainer>\n {moreThanOneGroupExists && (\n <ProductGroups\n products={products}\n activeGroup={activeGroup as ProductListGroupId}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n showProductGroups={showProductGroups}\n />\n )}\n <S.ProductList\n $columns={products.length}\n $isDragging={isDragging}\n $overflowExists={overflowExists}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n onMouseDown={(event) => mouseDownHandler(event)}\n onMouseUp={mouseUpHandler}\n ref={productListRef}\n >\n <ScrollButton\n color=\"white\"\n rotationDegrees={180}\n isVisible={!isMaxLeft}\n onClick={() => scrollButtonHandler({ isLeftArrow: true })}\n />\n <ScrollButton\n color=\"white\"\n rotationDegrees={0}\n isVisible={isMaxRight}\n isRightButton\n onClick={() => scrollButtonHandler({ isLeftArrow: false })}\n />\n {products.map((product, productsArrayIndex) => {\n const groupIsActive =\n product.productListGroup?.id === activeGroup;\n\n const productListGroup = products.filter(\n (product) => activeGroup === product.productListGroup?.id,\n );\n\n const groupIndex = productListGroup.findIndex(\n (item) => item.id === product.id,\n );\n\n return (\n <Product\n onClick={() =>\n setActiveGroup(\n product.productListGroup?.id as ProductListGroupId,\n )\n }\n key={product.id}\n groupIndex={groupIndex}\n groupLength={productListGroup.length}\n id={product?.id as ProductId}\n groupId={product.productListGroup?.id as ProductListGroupId}\n image={product.image ?? { src: \"\", width: 0, height: 0 }}\n name={product.title}\n description={product.description}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalState}\n groupIsActive={groupIsActive}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n isStaticProduct={productsArrayIndex === 0}\n isOverviewPage={isOverviewPage}\n />\n );\n })}\n </S.ProductList>\n </S.ProductGroupProductListContainer>\n </S.Container>\n </S.Wrapper>\n );\n};\n"],"names":["ProductList","products","selectedProducts","setSelectedProducts","hasBeenObserved","selectedProductsLimit","initialActiveGroup","setExternalState","showProductGroups","isOverviewPage","groupedGroups","groupProducts","moreThanOneGroupExists","length","containerRef","useRef","productListRef","buttonHasBeenClick","setButtonHasBeenClicked","useState","activeGroup","setActiveGroup","playAnimation","setPlayAnimation","isHovering","useHoverDirty","isDragging","setIsDragging","overflowExists","setOverflowExists","endPosition","setEndPosition","checkForScrollTimeout","useEffectOnce","refsExist","current","getBoundingClientRect","width","useEffect","productListGroup","id","productListInitialPosition","left","setTimeout","currentPosition","dragStartingPosition","scrollAmount","dragHandler","useCallback","event","clientX","scrollTo","mouseUpHandler","scrollLeft","document","removeEventListener","mouseDownHandler","buttons","addEventListener","container","isScrolling","checkIsScrolling","window","clearTimeout","tabClickHandler","groupId","initialScrollPosition","checkForScroll","currentScrollPosition","element","getElementById","scrollIntoView","behavior","inline","block","scrollButtonHandler","isLeftArrow","scrollLength","S.PRODUCT_CARD_WIDTH","PRODUCT_CARD_WIDTH","S.PRODUCT_LIST_GRID_GAP","PRODUCT_LIST_GRID_GAP","isMaxLeft","isMaxRight","useIsAtMaxScroll","jsxs","S.Wrapper","children","jsx","ButtonGroup","items","map","group","activeButton","onClick","S.Container","Container","ref","$isHovering","$moreThanOneGroupExists","$isDragging","S.ProductGroupProductListContainer","ProductGroups","canPlayAniimation","S.ProductList","$columns","$overflowExists","onMouseDown","onMouseUp","ScrollButton","color","rotationDegrees","isVisible","isRightButton","product","productsArrayIndex","groupIsActive","filter","groupIndex","findIndex","item","Product","groupLength","image","src","height","name","title","description","isStaticProduct"],"mappings":";;;;;;;;;;;;;;AAgBO,MAAMA,cAAcA,CAAC;EAC1BC,QAAA;EACAC,gBAAA;EACAC,mBAAA;EACAC,eAAA;EACAC,qBAAA;EACAC,kBAAA;EACAC,gBAAA;EACAC,iBAAA;EACAC;AACF,CAAwB,KAAA;EAChB,MAAAC,aAAA,GAAgBC,4BAAcV,QAAQ,CAAA;EACtC,MAAAW,sBAAA,GAAyBF,cAAcG,MAAS,GAAA,CAAA;EAEhD,MAAAC,YAAA,GAAeC,aAAuB,IAAI,CAAA;EAC1C,MAAAC,cAAA,GAAiBD,aAAuB,IAAI,CAAA;EAElD,MAAM,CAACE,kBAAA,EAAoBC,uBAAuB,CAAA,GAAIC,KAAAA,CAAAA,SAAS,KAAK,CAAA;EACpE,MAAM,CAACC,WAAA,EAAaC,cAAc,CAAA,GAAIF,KAAAA,CAAAA,SAASb,kBAAkB,CAAA;EACjE,MAAM,CAACgB,aAAA,EAAeC,gBAAgB,CAAA,GAAIJ,KAAAA,CAAAA,SAAS,KAAK,CAAA;EAClD,MAAAK,UAAA,GAAaC,uBAAcX,YAAY,CAAA;EAC7C,MAAM,CAACY,U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AA,CAAA;QAAA,CAAA,CAAA;MAEL,CAAA;IAAA,CAAA,CAAA;GAEJ,CAAA;AAEJ,CAAA;"}
1
+ {"version":3,"file":"ProductList.js","sources":["../../../../src/components/ModelCompareV4/ProductList/ProductList.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useEffectOnce, useHoverDirty } from \"react-use\";\n\nimport type {\n ProductId,\n ProductListGroupId,\n} from \"../../../constants/modelCompareData/types\";\nimport { ButtonGroup } from \"./components/ButtonGroup\";\nimport { Product } from \"./components/Product/Product\";\nimport { groupProducts } from \"./components/ProductGroups/groupProducts\";\nimport { ProductGroups } from \"./components/ProductGroups/ProductGroups\";\nimport { ScrollButton } from \"./components/ScrollButton/ScrollButton\";\nimport * as S from \"./ProductList.styles\";\nimport type { ProductListProps } from \"./ProductList.types\";\nimport { useIsAtMaxScroll } from \"./useIsAtMaxScroll\";\n\nconst CHECK_FOR_SCROLL_TIMEOUT = 150;\n\nexport const ProductList = ({\n products,\n selectedProducts,\n setSelectedProducts,\n hasBeenObserved,\n selectedProductsLimit,\n initialActiveGroup,\n setExternalState,\n showProductGroups,\n isOverviewPage,\n}: ProductListProps) => {\n const groupedGroups = useMemo(() => groupProducts(products), [products]);\n const moreThanOneGroupExists = groupedGroups.length > 1;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const productListRef = useRef<HTMLDivElement>(null);\n\n const [buttonHasBeenClick, setButtonHasBeenClicked] = useState(false);\n const [activeGroup, setActiveGroup] = useState(initialActiveGroup);\n const [playAnimation, setPlayAnimation] = useState(false);\n const isHovering = useHoverDirty(containerRef);\n const [isDragging, setIsDragging] = useState(false);\n const [overflowExists, setOverflowExists] = useState(true);\n const [endPosition, setEndPosition] = useState<number>(0);\n\n useEffectOnce(() => {\n const refsExist = containerRef.current && productListRef.current;\n if (\n refsExist &&\n containerRef.current?.getBoundingClientRect().width <\n productListRef.current?.getBoundingClientRect().width\n ) {\n setOverflowExists(true);\n } else {\n setOverflowExists(false);\n }\n });\n\n // TODO: figure out how to remove this TODO. Currently, without this `useEffect` `activeGroup` isn't updating when toggling between different tables (`Section`s).\n // ModelCompareV4 is sometimes used to toggle between sets of data of type Section. In this situation, we need the initial active group to be updated when the new data is passed to ModelCompareV4\n useEffect(() => {\n setActiveGroup(products[0]?.productListGroup?.id as ProductListGroupId);\n }, [products]);\n\n // #############################################################################\n // Scroll-Specific useEffects\n // #############################################################################\n\n // if there aren't any product list group buttons then the ending state of the animations need to exist on the initial render\n useEffect(() => {\n if (!showProductGroups && hasBeenObserved) {\n setPlayAnimation(true);\n }\n }, [hasBeenObserved, setPlayAnimation, showProductGroups]);\n\n // plays animation when no scroll has occurred on the initial observe\n useEffect(() => {\n const productListInitialPosition =\n productListRef.current?.getBoundingClientRect().left;\n\n let timeoutId: NodeJS.Timeout;\n\n if (hasBeenObserved || buttonHasBeenClick) {\n timeoutId = setTimeout(() => {\n const currentPosition =\n productListRef.current?.getBoundingClientRect().left;\n if (productListInitialPosition === currentPosition) {\n return setPlayAnimation(true);\n }\n }, CHECK_FOR_SCROLL_TIMEOUT);\n }\n\n return () => {\n clearTimeout(timeoutId);\n };\n }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);\n\n // #############################################################################\n // Drag Logic\n // #############################################################################\n const dragStartingPosition = useRef(0);\n const scrollAmount = useRef(0);\n\n const dragHandler = useCallback(\n (event: MouseEvent) => {\n scrollAmount.current = dragStartingPosition.current - event.clientX;\n containerRef.current?.scrollTo(endPosition + scrollAmount.current, 0);\n },\n [endPosition],\n );\n\n const mouseUpHandler = useCallback(() => {\n setIsDragging(false);\n setEndPosition(containerRef.current?.scrollLeft ?? 0);\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n }, [dragHandler]);\n\n const mouseDownHandler = useCallback(\n (event: React.MouseEvent<Element, MouseEvent>) => {\n if (event.buttons === 1) {\n dragStartingPosition.current = event.clientX;\n setIsDragging(true);\n document.addEventListener(\"mousemove\", dragHandler);\n document.addEventListener(\"mouseup\", mouseUpHandler);\n }\n },\n [dragHandler, mouseUpHandler],\n );\n\n // Add cleanup for drag handlers on unmount\n useEffect(() => {\n return () => {\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n };\n }, [dragHandler, mouseUpHandler]);\n\n useEffect(() => {\n const container = containerRef.current;\n\n if (!container) return;\n\n let isScrolling: NodeJS.Timeout;\n\n const checkIsScrolling = () => {\n window.clearTimeout(isScrolling);\n\n // if scrolling occurs, animations are played after scrolling has completed\n // if scrolling occurs, the container's end position is tracked in state after scrolling has completed\n isScrolling = setTimeout(function () {\n setPlayAnimation(true);\n setEndPosition(containerRef.current?.scrollLeft as number);\n }, CHECK_FOR_SCROLL_TIMEOUT);\n };\n\n (containerRef.current as HTMLDivElement).addEventListener(\n \"scroll\",\n checkIsScrolling,\n );\n\n return () => {\n window.removeEventListener(\"resize\", checkIsScrolling);\n };\n }, []); // Empty dependency array since we want this to run once\n\n // #############################################################################\n // Click to Scroll Logic\n // #############################################################################\n\n const tabClickHandler = useCallback(\n ({ groupId }: { groupId: ProductListGroupId }) => {\n const initialScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n const checkForScroll = () => {\n const currentScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n return currentScrollPosition === initialScrollPosition;\n };\n\n const element = document.getElementById(groupId) as HTMLDivElement;\n\n setPlayAnimation(false);\n setActiveGroup(groupId);\n setButtonHasBeenClicked(true);\n element?.scrollIntoView({\n behavior: \"smooth\",\n inline: \"start\",\n block: \"nearest\",\n });\n\n // if no scroll occurs animations are played\n setTimeout(() => {\n if (checkForScroll()) {\n setPlayAnimation(true);\n }\n }, CHECK_FOR_SCROLL_TIMEOUT);\n },\n [containerRef, setPlayAnimation, setActiveGroup],\n );\n\n const scrollButtonHandler = ({ isLeftArrow }: { isLeftArrow?: boolean }) => {\n if (containerRef.current) {\n const currentScrollPosition = containerRef.current?.scrollLeft;\n\n const scrollLength = isLeftArrow\n ? currentScrollPosition - S.PRODUCT_CARD_WIDTH - S.PRODUCT_LIST_GRID_GAP\n : currentScrollPosition +\n S.PRODUCT_CARD_WIDTH +\n S.PRODUCT_LIST_GRID_GAP;\n\n containerRef.current?.scrollTo(scrollLength, 0);\n }\n };\n\n const { isMaxLeft, isMaxRight } = useIsAtMaxScroll(containerRef);\n\n return (\n <S.Wrapper>\n {showProductGroups && moreThanOneGroupExists && (\n <ButtonGroup\n items={groupedGroups.map((group) => group.productListGroup)}\n activeButton={activeGroup as string}\n onClick={(id) => {\n tabClickHandler({ groupId: id as ProductListGroupId });\n }}\n />\n )}\n <S.Container\n ref={containerRef}\n $isHovering={isHovering}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n $isDragging={isDragging}\n >\n <S.ProductGroupProductListContainer>\n {moreThanOneGroupExists && (\n <ProductGroups\n products={products}\n activeGroup={activeGroup as ProductListGroupId}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n showProductGroups={showProductGroups}\n />\n )}\n <S.ProductList\n $columns={products.length}\n $isDragging={isDragging}\n $overflowExists={overflowExists}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n onMouseDown={(event) => mouseDownHandler(event)}\n onMouseUp={mouseUpHandler}\n ref={productListRef}\n >\n <ScrollButton\n color=\"white\"\n rotationDegrees={180}\n isVisible={!isMaxLeft}\n onClick={() => scrollButtonHandler({ isLeftArrow: true })}\n />\n <ScrollButton\n color=\"white\"\n rotationDegrees={0}\n isVisible={isMaxRight}\n isRightButton\n onClick={() => scrollButtonHandler({ isLeftArrow: false })}\n />\n {products.map((product, productsArrayIndex) => {\n const groupIsActive =\n product.productListGroup?.id === activeGroup;\n\n const productListGroup = products.filter(\n (product) => activeGroup === product.productListGroup?.id,\n );\n\n const groupIndex = productListGroup.findIndex(\n (item) => item.id === product.id,\n );\n\n return (\n <Product\n onClick={() =>\n setActiveGroup(\n product.productListGroup?.id as ProductListGroupId,\n )\n }\n key={product.id}\n groupIndex={groupIndex}\n groupLength={productListGroup.length}\n id={product?.id as ProductId}\n groupId={product.productListGroup?.id as ProductListGroupId}\n image={product.image ?? { src: \"\", width: 0, height: 0 }}\n name={product.title}\n description={product.description}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalState}\n groupIsActive={groupIsActive}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n isStaticProduct={productsArrayIndex === 0}\n isOverviewPage={isOverviewPage}\n />\n );\n })}\n </S.ProductList>\n </S.ProductGroupProductListContainer>\n </S.Container>\n </S.Wrapper>\n );\n};\n"],"names":["CHECK_FOR_SCROLL_TIMEOUT","ProductList","products","selectedProducts","setSelectedProducts","hasBeenObserved","selectedProductsLimit","initialActiveGroup","setExternalState","showProductGroups","isOverviewPage","groupedGroups","useMemo","groupProducts","moreThanOneGroupExists","length","containerRef","useRef","productListRef","buttonHasBeenClick","setButtonHasBeenClicked","useState","activeGroup","setActiveGroup","playAnimation","setPlayAnimation","isHovering","useHoverDirty","isDragging","setIsDragging","overflowExists","setOverflowExists","endPosition","setEndPosition","useEffectOnce","refsExist","current","getBoundingClientRect","width","useEffect","productListGroup","id","productListInitialPosition","left","timeoutId","setTimeout","currentPosition","clearTimeout","dragStartingPosition","scrollAmount","dragHandler","useCallback","event","clientX","scrollTo","mouseUpHandler","scrollLeft","document","removeEventListener","mouseDownHandler","buttons","addEventListener","container","isScrolling","checkIsScrolling","window","tabClickHandler","groupId","initialScrollPosition","checkForScroll","currentScrollPosition","element","getElementById","scrollIntoView","behavior","inline","block","scrollButtonHandler","isLeftArrow","scrollLength","S.PRODUCT_CARD_WIDTH","PRODUCT_CARD_WIDTH","S.PRODUCT_LIST_GRID_GAP","PRODUCT_LIST_GRID_GAP","isMaxLeft","isMaxRight","useIsAtMaxScroll","jsxs","S.Wrapper","children","jsx","ButtonGroup","items","map","group","activeButton","onClick","S.Container","Container","ref","$isHovering","$moreThanOneGroupExists","$isDragging","S.ProductGroupProductListContainer","ProductGroups","canPlayAniimation","S.ProductList","$columns","$overflowExists","onMouseDown","onMouseUp","ScrollButton","color","rotationDegrees","isVisible","isRightButton","product","productsArrayIndex","groupIsActive","filter","groupIndex","findIndex","item","Product","groupLength","image","src","height","name","title","description","isStaticProduct"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAMA,wBAA2B,GAAA,GAAA;AAE1B,MAAMC,cAAcA,CAAC;EAC1BC,QAAA;EACAC,gBAAA;EACAC,mBAAA;EACAC,eAAA;EACAC,qBAAA;EACAC,kBAAA;EACAC,gBAAA;EACAC,iBAAA;EACAC;AACF,CAAwB,KAAA;EAChB,MAAAC,aAAA,GAAgBC,KAAAA,CAAAA,QAAQ,MAAMC,aAAAA,CAAAA,aAAA,CAAcX,QAAQ,CAAG,EAAA,CAACA,QAAQ,CAAC,CAAA;EACjE,MAAAY,sBAAA,GAAyBH,cAAcI,MAAS,GAAA,CAAA;EAEhD,MAAAC,YAAA,GAAeC,aAAuB,IAAI,CAAA;EAC1C,MAAAC,cAAA,GAAiBD,aAAuB,IAAI,CAAA;EAElD,MAAM,CAACE,kBAAA,EAAoBC,uBAAuB,CAAA,GAAIC,KAAAA,CAAAA,SAAS,KAAK,CAAA;EACpE,MAAM,CAACC,WAAA,EAAaC,cAAc,CAAA,GAAIF,KAAAA,CAAAA,SAASd,kBAAkB,CAAA;EACjE,MAAM,CAACiB,aAAA,EAAeC,gBAAgB,CAAA,GAAIJ,KAAAA,CAAAA,SAAS,KAAK,CAAA;EAClD,MAAAK,UAAA,GAAaC,uBAAcX,YAAY,CAAA;EAC7C,MAAM,CAACY,UAAA,EAAYC,aAAa,CAAA,GAAIR,KAAAA,CAAAA,SAAS,KAAK,CAAA;EAClD,MAAM,CAACS,cAAA,EAAgBC,iBAAiB,CAAA,GAAIV,KAAAA,CAAAA,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}
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useRef, useState, useEffect, useCallback } from 'react';
2
+ import { useMemo, useRef, useState, useEffect, useCallback } from 'react';
3
3
  import { useHoverDirty, useEffectOnce } from 'react-use';
4
4
  import './components/ButtonGroup/index.mjs';
5
5
  import { Product } from './components/Product/Product.mjs';
@@ -10,6 +10,7 @@ import { PRODUCT_CARD_WIDTH, PRODUCT_LIST_GRID_GAP, Wrapper, Container, ProductG
10
10
  import { useIsAtMaxScroll } from './useIsAtMaxScroll.mjs';
11
11
  import { ButtonGroup } from './components/ButtonGroup/ButtonGroup.mjs';
12
12
  "use strict";
13
+ const CHECK_FOR_SCROLL_TIMEOUT = 150;
13
14
  const ProductList = ({
14
15
  products,
15
16
  selectedProducts,
@@ -21,7 +22,7 @@ const ProductList = ({
21
22
  showProductGroups,
22
23
  isOverviewPage
23
24
  }) => {
24
- const groupedGroups = groupProducts(products);
25
+ const groupedGroups = useMemo(() => groupProducts(products), [products]);
25
26
  const moreThanOneGroupExists = groupedGroups.length > 1;
26
27
  const containerRef = useRef(null);
27
28
  const productListRef = useRef(null);
@@ -32,7 +33,6 @@ const ProductList = ({
32
33
  const [isDragging, setIsDragging] = useState(false);
33
34
  const [overflowExists, setOverflowExists] = useState(true);
34
35
  const [endPosition, setEndPosition] = useState(0);
35
- const checkForScrollTimeout = 150;
36
36
  useEffectOnce(() => {
37
37
  const refsExist = containerRef.current && productListRef.current;
38
38
  if (refsExist && containerRef.current?.getBoundingClientRect().width < productListRef.current?.getBoundingClientRect().width) {
@@ -51,14 +51,18 @@ const ProductList = ({
51
51
  }, [hasBeenObserved, setPlayAnimation, showProductGroups]);
52
52
  useEffect(() => {
53
53
  const productListInitialPosition = productListRef.current?.getBoundingClientRect().left;
54
+ let timeoutId;
54
55
  if (hasBeenObserved || buttonHasBeenClick) {
55
- setTimeout(() => {
56
+ timeoutId = setTimeout(() => {
56
57
  const currentPosition = productListRef.current?.getBoundingClientRect().left;
57
58
  if (productListInitialPosition === currentPosition) {
58
59
  return setPlayAnimation(true);
59
60
  }
60
- }, checkForScrollTimeout);
61
+ }, CHECK_FOR_SCROLL_TIMEOUT);
61
62
  }
63
+ return () => {
64
+ clearTimeout(timeoutId);
65
+ };
62
66
  }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);
63
67
  const dragStartingPosition = useRef(0);
64
68
  const scrollAmount = useRef(0);
@@ -95,7 +99,7 @@ const ProductList = ({
95
99
  isScrolling = setTimeout(function () {
96
100
  setPlayAnimation(true);
97
101
  setEndPosition(containerRef.current?.scrollLeft);
98
- }, checkForScrollTimeout);
102
+ }, CHECK_FOR_SCROLL_TIMEOUT);
99
103
  };
100
104
  containerRef.current.addEventListener("scroll", checkIsScrolling);
101
105
  return () => {
@@ -123,8 +127,8 @@ const ProductList = ({
123
127
  if (checkForScroll()) {
124
128
  setPlayAnimation(true);
125
129
  }
126
- }, checkForScrollTimeout);
127
- }, [containerRef, setPlayAnimation, setActiveGroup, checkForScrollTimeout]);
130
+ }, CHECK_FOR_SCROLL_TIMEOUT);
131
+ }, [containerRef, setPlayAnimation, setActiveGroup]);
128
132
  const scrollButtonHandler = ({
129
133
  isLeftArrow
130
134
  }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ProductList.mjs","sources":["../../../../src/components/ModelCompareV4/ProductList/ProductList.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useEffectOnce, useHoverDirty } from \"react-use\";\n\nimport type {\n ProductId,\n ProductListGroupId,\n} from \"../../../constants/modelCompareData/types\";\nimport { ButtonGroup } from \"./components/ButtonGroup\";\nimport { Product } from \"./components/Product/Product\";\nimport { groupProducts } from \"./components/ProductGroups/groupProducts\";\nimport { ProductGroups } from \"./components/ProductGroups/ProductGroups\";\nimport { ScrollButton } from \"./components/ScrollButton/ScrollButton\";\nimport * as S from \"./ProductList.styles\";\nimport type { ProductListProps } from \"./ProductList.types\";\nimport { useIsAtMaxScroll } from \"./useIsAtMaxScroll\";\n\nexport const ProductList = ({\n products,\n selectedProducts,\n setSelectedProducts,\n hasBeenObserved,\n selectedProductsLimit,\n initialActiveGroup,\n setExternalState,\n showProductGroups,\n isOverviewPage,\n}: ProductListProps) => {\n const groupedGroups = groupProducts(products);\n const moreThanOneGroupExists = groupedGroups.length > 1;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const productListRef = useRef<HTMLDivElement>(null);\n\n const [buttonHasBeenClick, setButtonHasBeenClicked] = useState(false);\n const [activeGroup, setActiveGroup] = useState(initialActiveGroup);\n const [playAnimation, setPlayAnimation] = useState(false);\n const isHovering = useHoverDirty(containerRef);\n const [isDragging, setIsDragging] = useState(false);\n const [overflowExists, setOverflowExists] = useState(true);\n const [endPosition, setEndPosition] = useState<number>(0);\n const checkForScrollTimeout = 150;\n\n useEffectOnce(() => {\n const refsExist = containerRef.current && productListRef.current;\n if (\n refsExist &&\n containerRef.current?.getBoundingClientRect().width <\n productListRef.current?.getBoundingClientRect().width\n ) {\n setOverflowExists(true);\n } else {\n setOverflowExists(false);\n }\n });\n\n // TODO: figure out how to remove this TODO. Currently, without this `useEffect` `activeGroup` isn't updating when toggling between different tables (`Section`s).\n // ModelCompareV4 is sometimes used to toggle between sets of data of type Section. In this situation, we need the initial active group to be updated when the new data is passed to ModelCompareV4\n useEffect(() => {\n setActiveGroup(products[0]?.productListGroup?.id as ProductListGroupId);\n }, [products]);\n\n // #############################################################################\n // Scroll-Specific useEffects\n // #############################################################################\n\n // if there aren't any product list group buttons then the ending state of the animations need to exist on the initial render\n useEffect(() => {\n if (!showProductGroups && hasBeenObserved) {\n setPlayAnimation(true);\n }\n }, [hasBeenObserved, setPlayAnimation, showProductGroups]);\n\n // plays animation when no scroll has occurred on the initial observe\n useEffect(() => {\n const productListInitialPosition =\n productListRef.current?.getBoundingClientRect().left;\n\n if (hasBeenObserved || buttonHasBeenClick) {\n setTimeout(() => {\n const currentPosition =\n productListRef.current?.getBoundingClientRect().left;\n if (productListInitialPosition === currentPosition) {\n return setPlayAnimation(true);\n }\n }, checkForScrollTimeout);\n }\n }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);\n\n // #############################################################################\n // Drag Logic\n // #############################################################################\n const dragStartingPosition = useRef(0);\n const scrollAmount = useRef(0);\n\n const dragHandler = useCallback(\n (event: MouseEvent) => {\n scrollAmount.current = dragStartingPosition.current - event.clientX;\n containerRef.current?.scrollTo(endPosition + scrollAmount.current, 0);\n },\n [endPosition],\n );\n\n const mouseUpHandler = useCallback(() => {\n setIsDragging(false);\n setEndPosition(containerRef.current?.scrollLeft ?? 0);\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n }, [dragHandler]);\n\n const mouseDownHandler = useCallback(\n (event: React.MouseEvent<Element, MouseEvent>) => {\n if (event.buttons === 1) {\n dragStartingPosition.current = event.clientX;\n setIsDragging(true);\n document.addEventListener(\"mousemove\", dragHandler);\n document.addEventListener(\"mouseup\", mouseUpHandler);\n }\n },\n [dragHandler, mouseUpHandler],\n );\n\n // Add cleanup for drag handlers on unmount\n useEffect(() => {\n return () => {\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n };\n }, [dragHandler, mouseUpHandler]);\n\n useEffect(() => {\n const container = containerRef.current;\n\n if (!container) return;\n\n let isScrolling: NodeJS.Timeout;\n\n const checkIsScrolling = () => {\n window.clearTimeout(isScrolling);\n\n // if scrolling occurs, animations are played after scrolling has completed\n // if scrolling occurs, the container's end position is tracked in state after scrolling has completed\n isScrolling = setTimeout(function () {\n setPlayAnimation(true);\n setEndPosition(containerRef.current?.scrollLeft as number);\n }, checkForScrollTimeout);\n };\n\n (containerRef.current as HTMLDivElement).addEventListener(\n \"scroll\",\n checkIsScrolling,\n );\n\n return () => {\n window.removeEventListener(\"resize\", checkIsScrolling);\n };\n }, []); // Empty dependency array since we want this to run once\n\n // #############################################################################\n // Click to Scroll Logic\n // #############################################################################\n\n const tabClickHandler = useCallback(\n ({ groupId }: { groupId: ProductListGroupId }) => {\n const initialScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n const checkForScroll = () => {\n const currentScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n return currentScrollPosition === initialScrollPosition;\n };\n\n const element = document.getElementById(groupId) as HTMLDivElement;\n\n setPlayAnimation(false);\n setActiveGroup(groupId);\n setButtonHasBeenClicked(true);\n element?.scrollIntoView({\n behavior: \"smooth\",\n inline: \"start\",\n block: \"nearest\",\n });\n\n // if no scroll occurs animations are played\n setTimeout(() => {\n if (checkForScroll()) {\n setPlayAnimation(true);\n }\n }, checkForScrollTimeout);\n },\n [containerRef, setPlayAnimation, setActiveGroup, checkForScrollTimeout],\n );\n\n const scrollButtonHandler = ({ isLeftArrow }: { isLeftArrow?: boolean }) => {\n if (containerRef.current) {\n const currentScrollPosition = containerRef.current?.scrollLeft;\n\n const scrollLength = isLeftArrow\n ? currentScrollPosition - S.PRODUCT_CARD_WIDTH - S.PRODUCT_LIST_GRID_GAP\n : currentScrollPosition +\n S.PRODUCT_CARD_WIDTH +\n S.PRODUCT_LIST_GRID_GAP;\n\n containerRef.current?.scrollTo(scrollLength, 0);\n }\n };\n\n const { isMaxLeft, isMaxRight } = useIsAtMaxScroll(containerRef);\n\n return (\n <S.Wrapper>\n {showProductGroups && moreThanOneGroupExists && (\n <ButtonGroup\n items={groupedGroups.map((group) => group.productListGroup)}\n activeButton={activeGroup as string}\n onClick={(id) => {\n tabClickHandler({ groupId: id as ProductListGroupId });\n }}\n />\n )}\n <S.Container\n ref={containerRef}\n $isHovering={isHovering}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n $isDragging={isDragging}\n >\n <S.ProductGroupProductListContainer>\n {moreThanOneGroupExists && (\n <ProductGroups\n products={products}\n activeGroup={activeGroup as ProductListGroupId}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n showProductGroups={showProductGroups}\n />\n )}\n <S.ProductList\n $columns={products.length}\n $isDragging={isDragging}\n $overflowExists={overflowExists}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n onMouseDown={(event) => mouseDownHandler(event)}\n onMouseUp={mouseUpHandler}\n ref={productListRef}\n >\n <ScrollButton\n color=\"white\"\n rotationDegrees={180}\n isVisible={!isMaxLeft}\n onClick={() => scrollButtonHandler({ isLeftArrow: true })}\n />\n <ScrollButton\n color=\"white\"\n rotationDegrees={0}\n isVisible={isMaxRight}\n isRightButton\n onClick={() => scrollButtonHandler({ isLeftArrow: false })}\n />\n {products.map((product, productsArrayIndex) => {\n const groupIsActive =\n product.productListGroup?.id === activeGroup;\n\n const productListGroup = products.filter(\n (product) => activeGroup === product.productListGroup?.id,\n );\n\n const groupIndex = productListGroup.findIndex(\n (item) => item.id === product.id,\n );\n\n return (\n <Product\n onClick={() =>\n setActiveGroup(\n product.productListGroup?.id as ProductListGroupId,\n )\n }\n key={product.id}\n groupIndex={groupIndex}\n groupLength={productListGroup.length}\n id={product?.id as ProductId}\n groupId={product.productListGroup?.id as ProductListGroupId}\n image={product.image ?? { src: \"\", width: 0, height: 0 }}\n name={product.title}\n description={product.description}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalState}\n groupIsActive={groupIsActive}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n isStaticProduct={productsArrayIndex === 0}\n isOverviewPage={isOverviewPage}\n />\n );\n })}\n </S.ProductList>\n </S.ProductGroupProductListContainer>\n </S.Container>\n </S.Wrapper>\n );\n};\n"],"names":["ProductList","products","selectedProducts","setSelectedProducts","hasBeenObserved","selectedProductsLimit","initialActiveGroup","setExternalState","showProductGroups","isOverviewPage","groupedGroups","groupProducts","moreThanOneGroupExists","length","containerRef","useRef","productListRef","buttonHasBeenClick","setButtonHasBeenClicked","useState","activeGroup","setActiveGroup","playAnimation","setPlayAnimation","isHovering","useHoverDirty","isDragging","setIsDragging","overflowExists","setOverflowExists","endPosition","setEndPosition","checkForScrollTimeout","useEffectOnce","refsExist","current","getBoundingClientRect","width","useEffect","productListGroup","id","productListInitialPosition","left","setTimeout","currentPosition","dragStartingPosition","scrollAmount","dragHandler","useCallback","event","clientX","scrollTo","mouseUpHandler","scrollLeft","document","removeEventListener","mouseDownHandler","buttons","addEventListener","container","isScrolling","checkIsScrolling","window","clearTimeout","tabClickHandler","groupId","initialScrollPosition","checkForScroll","currentScrollPosition","element","getElementById","scrollIntoView","behavior","inline","block","scrollButtonHandler","isLeftArrow","scrollLength","S.PRODUCT_CARD_WIDTH","S.PRODUCT_LIST_GRID_GAP","isMaxLeft","isMaxRight","useIsAtMaxScroll","jsxs","S.Wrapper","children","jsx","ButtonGroup","items","map","group","activeButton","onClick","S.Container","ref","$isHovering","$moreThanOneGroupExists","$isDragging","S.ProductGroupProductListContainer","ProductGroups","canPlayAniimation","S.ProductList","$columns","$overflowExists","onMouseDown","onMouseUp","ScrollButton","color","rotationDegrees","isVisible","isRightButton","product","productsArrayIndex","groupIsActive","filter","groupIndex","findIndex","item","Product","groupLength","image","src","height","name","title","description","isStaticProduct"],"mappings":";;;;;;;;;;;;AAgBO,MAAMA,cAAcA,CAAC;EAC1BC,QAAA;EACAC,gBAAA;EACAC,mBAAA;EACAC,eAAA;EACAC,qBAAA;EACAC,kBAAA;EACAC,gBAAA;EACAC,iBAAA;EACAC;AACF,CAAwB,KAAA;EAChB,MAAAC,aAAA,GAAgBC,cAAcV,QAAQ,CAAA;EACtC,MAAAW,sBAAA,GAAyBF,cAAcG,MAAS,GAAA,CAAA;EAEhD,MAAAC,YAAA,GAAeC,OAAuB,IAAI,CAAA;EAC1C,MAAAC,cAAA,GAAiBD,OAAuB,IAAI,CAAA;EAElD,MAAM,CAACE,kBAAA,EAAoBC,uBAAuB,CAAA,GAAIC,SAAS,KAAK,CAAA;EACpE,MAAM,CAAC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,WAAA;YAEnC,MAAMmB,mBAAmBtC,QAAS,CAAAiH,MAAA,CAC/BH,QAAAA,IAAY3F,WAAgB2F,KAAAA,QAAAA,CAAQxE,gBAAkB,EAAAC,EACzD,CAAA;YAEA,MAAM2E,aAAa5E,gBAAiB,CAAA6E,SAAA,CACjCC,IAAA,IAASA,IAAK,CAAA7E,EAAA,KAAOuE,OAAQ,CAAAvE,EAChC,CAAA;YAGE,sBAAA8C,GAAA,CAACgC,OAAA,EAAA;cACC1B,SAASA,CAAA,KACPvE,cAAA,CACE0F,QAAQxE,gBAAkB,EAAAC,EAC5B,CAAA;cAGF2E,UAAA;cACAI,aAAahF,gBAAiB,CAAA1B,MAAA;cAC9B2B,IAAIuE,OAAS,EAAAvE,EAAA;cACbyB,OAAA,EAAS8C,QAAQxE,gBAAkB,EAAAC,EAAA;cACnCgF,KAAA,EAAOT,QAAQS,KAAS,IAAA;gBAAEC,KAAK,EAAI;gBAAApF,KAAA,EAAO,CAAG;gBAAAqF,MAAA,EAAQ;cAAE,CAAA;cACvDC,MAAMZ,OAAQ,CAAAa,KAAA;cACdC,aAAad,OAAQ,CAAAc,WAAA;cACrB3H,gBAAA;cACAC,mBAAA;cACAI,gBAAA;cACA0G,aAAA;cACA3F,aAAA;cACA8E,mBAAmBhG,eAAmB,IAAAa,kBAAA;cACtCZ,qBAAA;cACAG,iBAAA;cACAsH,iBAAiBd,kBAAuB,KAAA,CAAA;cACxCvG;YAAA,CAAA,EAjBKsG,OAAQ,CAAAvE,EAkBf,CAAA;UAEH,CAAA,CAAA;QAAA,CAAA,CAAA;MAEL,CAAA;IAAA,CAAA,CAAA;GAEJ,CAAA;AAEJ,CAAA;"}
1
+ {"version":3,"file":"ProductList.mjs","sources":["../../../../src/components/ModelCompareV4/ProductList/ProductList.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useEffectOnce, useHoverDirty } from \"react-use\";\n\nimport type {\n ProductId,\n ProductListGroupId,\n} from \"../../../constants/modelCompareData/types\";\nimport { ButtonGroup } from \"./components/ButtonGroup\";\nimport { Product } from \"./components/Product/Product\";\nimport { groupProducts } from \"./components/ProductGroups/groupProducts\";\nimport { ProductGroups } from \"./components/ProductGroups/ProductGroups\";\nimport { ScrollButton } from \"./components/ScrollButton/ScrollButton\";\nimport * as S from \"./ProductList.styles\";\nimport type { ProductListProps } from \"./ProductList.types\";\nimport { useIsAtMaxScroll } from \"./useIsAtMaxScroll\";\n\nconst CHECK_FOR_SCROLL_TIMEOUT = 150;\n\nexport const ProductList = ({\n products,\n selectedProducts,\n setSelectedProducts,\n hasBeenObserved,\n selectedProductsLimit,\n initialActiveGroup,\n setExternalState,\n showProductGroups,\n isOverviewPage,\n}: ProductListProps) => {\n const groupedGroups = useMemo(() => groupProducts(products), [products]);\n const moreThanOneGroupExists = groupedGroups.length > 1;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const productListRef = useRef<HTMLDivElement>(null);\n\n const [buttonHasBeenClick, setButtonHasBeenClicked] = useState(false);\n const [activeGroup, setActiveGroup] = useState(initialActiveGroup);\n const [playAnimation, setPlayAnimation] = useState(false);\n const isHovering = useHoverDirty(containerRef);\n const [isDragging, setIsDragging] = useState(false);\n const [overflowExists, setOverflowExists] = useState(true);\n const [endPosition, setEndPosition] = useState<number>(0);\n\n useEffectOnce(() => {\n const refsExist = containerRef.current && productListRef.current;\n if (\n refsExist &&\n containerRef.current?.getBoundingClientRect().width <\n productListRef.current?.getBoundingClientRect().width\n ) {\n setOverflowExists(true);\n } else {\n setOverflowExists(false);\n }\n });\n\n // TODO: figure out how to remove this TODO. Currently, without this `useEffect` `activeGroup` isn't updating when toggling between different tables (`Section`s).\n // ModelCompareV4 is sometimes used to toggle between sets of data of type Section. In this situation, we need the initial active group to be updated when the new data is passed to ModelCompareV4\n useEffect(() => {\n setActiveGroup(products[0]?.productListGroup?.id as ProductListGroupId);\n }, [products]);\n\n // #############################################################################\n // Scroll-Specific useEffects\n // #############################################################################\n\n // if there aren't any product list group buttons then the ending state of the animations need to exist on the initial render\n useEffect(() => {\n if (!showProductGroups && hasBeenObserved) {\n setPlayAnimation(true);\n }\n }, [hasBeenObserved, setPlayAnimation, showProductGroups]);\n\n // plays animation when no scroll has occurred on the initial observe\n useEffect(() => {\n const productListInitialPosition =\n productListRef.current?.getBoundingClientRect().left;\n\n let timeoutId: NodeJS.Timeout;\n\n if (hasBeenObserved || buttonHasBeenClick) {\n timeoutId = setTimeout(() => {\n const currentPosition =\n productListRef.current?.getBoundingClientRect().left;\n if (productListInitialPosition === currentPosition) {\n return setPlayAnimation(true);\n }\n }, CHECK_FOR_SCROLL_TIMEOUT);\n }\n\n return () => {\n clearTimeout(timeoutId);\n };\n }, [hasBeenObserved, setPlayAnimation, buttonHasBeenClick]);\n\n // #############################################################################\n // Drag Logic\n // #############################################################################\n const dragStartingPosition = useRef(0);\n const scrollAmount = useRef(0);\n\n const dragHandler = useCallback(\n (event: MouseEvent) => {\n scrollAmount.current = dragStartingPosition.current - event.clientX;\n containerRef.current?.scrollTo(endPosition + scrollAmount.current, 0);\n },\n [endPosition],\n );\n\n const mouseUpHandler = useCallback(() => {\n setIsDragging(false);\n setEndPosition(containerRef.current?.scrollLeft ?? 0);\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n }, [dragHandler]);\n\n const mouseDownHandler = useCallback(\n (event: React.MouseEvent<Element, MouseEvent>) => {\n if (event.buttons === 1) {\n dragStartingPosition.current = event.clientX;\n setIsDragging(true);\n document.addEventListener(\"mousemove\", dragHandler);\n document.addEventListener(\"mouseup\", mouseUpHandler);\n }\n },\n [dragHandler, mouseUpHandler],\n );\n\n // Add cleanup for drag handlers on unmount\n useEffect(() => {\n return () => {\n document.removeEventListener(\"mousemove\", dragHandler);\n document.removeEventListener(\"mouseup\", mouseUpHandler);\n };\n }, [dragHandler, mouseUpHandler]);\n\n useEffect(() => {\n const container = containerRef.current;\n\n if (!container) return;\n\n let isScrolling: NodeJS.Timeout;\n\n const checkIsScrolling = () => {\n window.clearTimeout(isScrolling);\n\n // if scrolling occurs, animations are played after scrolling has completed\n // if scrolling occurs, the container's end position is tracked in state after scrolling has completed\n isScrolling = setTimeout(function () {\n setPlayAnimation(true);\n setEndPosition(containerRef.current?.scrollLeft as number);\n }, CHECK_FOR_SCROLL_TIMEOUT);\n };\n\n (containerRef.current as HTMLDivElement).addEventListener(\n \"scroll\",\n checkIsScrolling,\n );\n\n return () => {\n window.removeEventListener(\"resize\", checkIsScrolling);\n };\n }, []); // Empty dependency array since we want this to run once\n\n // #############################################################################\n // Click to Scroll Logic\n // #############################################################################\n\n const tabClickHandler = useCallback(\n ({ groupId }: { groupId: ProductListGroupId }) => {\n const initialScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n const checkForScroll = () => {\n const currentScrollPosition = (containerRef.current as HTMLDivElement)\n .scrollLeft;\n\n return currentScrollPosition === initialScrollPosition;\n };\n\n const element = document.getElementById(groupId) as HTMLDivElement;\n\n setPlayAnimation(false);\n setActiveGroup(groupId);\n setButtonHasBeenClicked(true);\n element?.scrollIntoView({\n behavior: \"smooth\",\n inline: \"start\",\n block: \"nearest\",\n });\n\n // if no scroll occurs animations are played\n setTimeout(() => {\n if (checkForScroll()) {\n setPlayAnimation(true);\n }\n }, CHECK_FOR_SCROLL_TIMEOUT);\n },\n [containerRef, setPlayAnimation, setActiveGroup],\n );\n\n const scrollButtonHandler = ({ isLeftArrow }: { isLeftArrow?: boolean }) => {\n if (containerRef.current) {\n const currentScrollPosition = containerRef.current?.scrollLeft;\n\n const scrollLength = isLeftArrow\n ? currentScrollPosition - S.PRODUCT_CARD_WIDTH - S.PRODUCT_LIST_GRID_GAP\n : currentScrollPosition +\n S.PRODUCT_CARD_WIDTH +\n S.PRODUCT_LIST_GRID_GAP;\n\n containerRef.current?.scrollTo(scrollLength, 0);\n }\n };\n\n const { isMaxLeft, isMaxRight } = useIsAtMaxScroll(containerRef);\n\n return (\n <S.Wrapper>\n {showProductGroups && moreThanOneGroupExists && (\n <ButtonGroup\n items={groupedGroups.map((group) => group.productListGroup)}\n activeButton={activeGroup as string}\n onClick={(id) => {\n tabClickHandler({ groupId: id as ProductListGroupId });\n }}\n />\n )}\n <S.Container\n ref={containerRef}\n $isHovering={isHovering}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n $isDragging={isDragging}\n >\n <S.ProductGroupProductListContainer>\n {moreThanOneGroupExists && (\n <ProductGroups\n products={products}\n activeGroup={activeGroup as ProductListGroupId}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n showProductGroups={showProductGroups}\n />\n )}\n <S.ProductList\n $columns={products.length}\n $isDragging={isDragging}\n $overflowExists={overflowExists}\n $moreThanOneGroupExists={moreThanOneGroupExists}\n onMouseDown={(event) => mouseDownHandler(event)}\n onMouseUp={mouseUpHandler}\n ref={productListRef}\n >\n <ScrollButton\n color=\"white\"\n rotationDegrees={180}\n isVisible={!isMaxLeft}\n onClick={() => scrollButtonHandler({ isLeftArrow: true })}\n />\n <ScrollButton\n color=\"white\"\n rotationDegrees={0}\n isVisible={isMaxRight}\n isRightButton\n onClick={() => scrollButtonHandler({ isLeftArrow: false })}\n />\n {products.map((product, productsArrayIndex) => {\n const groupIsActive =\n product.productListGroup?.id === activeGroup;\n\n const productListGroup = products.filter(\n (product) => activeGroup === product.productListGroup?.id,\n );\n\n const groupIndex = productListGroup.findIndex(\n (item) => item.id === product.id,\n );\n\n return (\n <Product\n onClick={() =>\n setActiveGroup(\n product.productListGroup?.id as ProductListGroupId,\n )\n }\n key={product.id}\n groupIndex={groupIndex}\n groupLength={productListGroup.length}\n id={product?.id as ProductId}\n groupId={product.productListGroup?.id as ProductListGroupId}\n image={product.image ?? { src: \"\", width: 0, height: 0 }}\n name={product.title}\n description={product.description}\n selectedProducts={selectedProducts}\n setSelectedProducts={setSelectedProducts}\n setExternalState={setExternalState}\n groupIsActive={groupIsActive}\n playAnimation={playAnimation}\n canPlayAniimation={hasBeenObserved || buttonHasBeenClick}\n selectedProductsLimit={selectedProductsLimit}\n showProductGroups={showProductGroups}\n isStaticProduct={productsArrayIndex === 0}\n isOverviewPage={isOverviewPage}\n />\n );\n })}\n </S.ProductList>\n </S.ProductGroupProductListContainer>\n </S.Container>\n </S.Wrapper>\n );\n};\n"],"names":["CHECK_FOR_SCROLL_TIMEOUT","ProductList","products","selectedProducts","setSelectedProducts","hasBeenObserved","selectedProductsLimit","initialActiveGroup","setExternalState","showProductGroups","isOverviewPage","groupedGroups","useMemo","groupProducts","moreThanOneGroupExists","length","containerRef","useRef","productListRef","buttonHasBeenClick","setButtonHasBeenClicked","useState","activeGroup","setActiveGroup","playAnimation","setPlayAnimation","isHovering","useHoverDirty","isDragging","setIsDragging","overflowExists","setOverflowExists","endPosition","setEndPosition","useEffectOnce","refsExist","current","getBoundingClientRect","width","useEffect","productListGroup","id","productListInitialPosition","left","timeoutId","setTimeout","currentPosition","clearTimeout","dragStartingPosition","scrollAmount","dragHandler","useCallback","event","clientX","scrollTo","mouseUpHandler","scrollLeft","document","removeEventListener","mouseDownHandler","buttons","addEventListener","container","isScrolling","checkIsScrolling","window","tabClickHandler","groupId","initialScrollPosition","checkForScroll","currentScrollPosition","element","getElementById","scrollIntoView","behavior","inline","block","scrollButtonHandler","isLeftArrow","scrollLength","S.PRODUCT_CARD_WIDTH","S.PRODUCT_LIST_GRID_GAP","isMaxLeft","isMaxRight","useIsAtMaxScroll","jsxs","S.Wrapper","children","jsx","ButtonGroup","items","map","group","activeButton","onClick","S.Container","ref","$isHovering","$moreThanOneGroupExists","$isDragging","S.ProductGroupProductListContainer","ProductGroups","canPlayAniimation","S.ProductList","$columns","$overflowExists","onMouseDown","onMouseUp","ScrollButton","color","rotationDegrees","isVisible","isRightButton","product","productsArrayIndex","groupIsActive","filter","groupIndex","findIndex","item","Product","groupLength","image","src","height","name","title","description","isStaticProduct"],"mappings":";;;;;;;;;;;;AAgBA,MAAMA,wBAA2B,GAA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;cACdC,aAAad,OAAQ,CAAAc,WAAA;cACrB5H,gBAAA;cACAC,mBAAA;cACAI,gBAAA;cACA2G,aAAA;cACA3F,aAAA;cACA8E,mBAAmBjG,eAAmB,IAAAc,kBAAA;cACtCb,qBAAA;cACAG,iBAAA;cACAuH,iBAAiBd,kBAAuB,KAAA,CAAA;cACxCxG;YAAA,CAAA,EAjBKuG,OAAQ,CAAAxE,EAkBf,CAAA;UAEH,CAAA,CAAA;QAAA,CAAA,CAAA;MAEL,CAAA;IAAA,CAAA,CAAA;GAEJ,CAAA;AAEJ,CAAA;"}
@@ -75,6 +75,8 @@ const Product = ({
75
75
  onPointerDown: event => setStartingClickPosition(event.clientX),
76
76
  onPointerUp: event => onPointerUpHandler(event)
77
77
  }), image.src && /* @__PURE__ */jsxRuntime.jsx(ProductList_styles.Image, {
78
+ loading: "lazy",
79
+ decoding: "async",
78
80
  src: asset.imageSrc(image.src),
79
81
  alt: name,
80
82
  width: image.width,
@@ -1 +1 @@
1
- {"version":3,"file":"Product.js","sources":["../../../../../../src/components/ModelCompareV4/ProductList/components/Product/Product.tsx"],"sourcesContent":["import type React from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport plusIcon from \"../../../../../constants/modelCompareData/assets/plus.svg\";\nimport { useModelCompareTranslation } from \"../../../../../constants/modelCompareData/translations/useModelCompareTranslation\";\nimport { imageSrc } from \"../../../../../utils/asset\";\nimport * as S from \"../../ProductList.styles\";\nimport type { ProductProps } from \"./Product.types\";\n\nexport const Product = ({\n id,\n groupId,\n image,\n name,\n description,\n selectedProducts,\n setSelectedProducts,\n groupIsActive,\n groupIndex,\n groupLength,\n playAnimation,\n canPlayAniimation,\n selectedProductsLimit,\n setExternalState,\n showProductGroups,\n isStaticProduct,\n isOverviewPage,\n onClick,\n}: ProductProps) => {\n const { formatMessage } = useModelCompareTranslation();\n const [startingClickPosition, setStartingClickPosition] = useState(0);\n const [hasBeenClicked, setHasBeenClicked] = useState(false);\n\n const isSelected = useMemo(\n () => selectedProducts.some((product) => product.productId === id),\n [selectedProducts, id],\n );\n const isOnlySelectedProduct = useMemo(\n () => isSelected && selectedProducts.length === 1,\n [isSelected, selectedProducts],\n );\n const isDisabled = useMemo(\n () =>\n (!isSelected && selectedProducts.length === selectedProductsLimit) ||\n isOnlySelectedProduct,\n [\n isSelected,\n selectedProducts,\n selectedProductsLimit,\n isOnlySelectedProduct,\n ],\n );\n\n const buttonClickHandler = useCallback(() => {\n const newProductList = selectedProducts.filter(\n (product) => product.productId !== id,\n );\n if (setExternalState) {\n setExternalState((prev) =>\n isSelected\n ? newProductList\n : [...prev, { productId: id, groupId: groupId }],\n );\n }\n\n setSelectedProducts((prev) =>\n isSelected\n ? newProductList\n : [...prev, { productId: id, groupId: groupId }],\n );\n }, [\n selectedProducts,\n id,\n groupId,\n isSelected,\n setExternalState,\n setSelectedProducts,\n ]);\n\n const onPointerUpHandler = (event: React.PointerEvent<HTMLDivElement>) => {\n if (event.clientX === startingClickPosition) setHasBeenClicked(true);\n };\n\n useEffect(() => {\n if (hasBeenClicked) {\n onClick();\n setHasBeenClicked(false);\n }\n }, [hasBeenClicked, onClick]);\n\n return (\n <S.Product\n $isActive={groupIsActive}\n $groupIndex={groupIndex}\n $groupLength={groupLength}\n $playAnimation={playAnimation}\n $canPlayAniimation={canPlayAniimation}\n $productGroupsSelectorExists={showProductGroups}\n >\n <S.ProductCardOnClickArea\n onPointerDown={(event) => setStartingClickPosition(event.clientX)}\n onPointerUp={(event) => onPointerUpHandler(event)}\n />\n {image.src && (\n <S.Image\n src={imageSrc(image.src)}\n alt={name}\n width={image.width}\n height={image.height}\n />\n )}\n <S.DescriptionButtonContainer>\n <S.Name>{formatMessage(name)}</S.Name>\n {description && (\n <S.Description>{formatMessage(description)}</S.Description>\n )}\n\n <S.Button\n $isStaticProduct={!isOverviewPage && isStaticProduct}\n $isSelected={isSelected}\n $disabled={isDisabled}\n type=\"button\"\n disabled={isDisabled}\n onClick={buttonClickHandler}\n >\n <S.ButtonIcon\n $isSelected={isSelected}\n src={plusIcon}\n width={20}\n height={20}\n />\n <S.ButtonCopy>\n {formatMessage(\n `commons.productList.button.${isSelected ? \"active\" : \"inactive\"}`,\n )}\n {isSelected && <S.CopyWhiteSpace />}\n </S.ButtonCopy>\n </S.Button>\n </S.DescriptionButtonContainer>\n </S.Product>\n );\n};\n"],"names":["Product","id","groupId","image","name","description","selectedProducts","setSelectedProducts","groupIsActive","groupIndex","groupLength","playAnimation","canPlayAniimation","selectedProductsLimit","setExternalState","showProductGroups","isStaticProduct","isOverviewPage","onClick","formatMessage","useModelCompareTranslation","startingClickPosition","setStartingClickPosition","useState","hasBeenClicked","setHasBeenClicked","isSelected","useMemo","some","product","productId","isOnlySelectedProduct","length","isDisabled","buttonClickHandler","useCallback","newProductList","filter","prev","onPointerUpHandler","event","clientX","useEffect","jsxs","S.Product","$isActive","$groupIndex","$groupLength","$playAnimation","$canPlayAniimation","$productGroupsSelectorExists","children","jsx","S.ProductCardOnClickArea","ProductCardOnClickArea","onPointerDown","onPointerUp","src","S.Image","Image","imageSrc","alt","width","height","S.DescriptionButtonContainer","S.Name","Name","S.Description","S.Button","Button","$isStaticProduct","$isSelected","$disabled","type","disabled","S.ButtonIcon","ButtonIcon","plusIcon","S.ButtonCopy","S.CopyWhiteSpace"],"mappings":";;;;;;;;;;;;;;;;AASO,MAAMA,UAAUA,CAAC;EACtBC,EAAA;EACAC,OAAA;EACAC,KAAA;EACAC,IAAA;EACAC,WAAA;EACAC,gBAAA;EACAC,mBAAA;EACAC,aAAA;EACAC,UAAA;EACAC,WAAA;EACAC,aAAA;EACAC,iBAAA;EACAC,qBAAA;EACAC,gBAAA;EACAC,iBAAA;EACAC,eAAA;EACAC,cAAA;EACAC;AACF,CAAoB,KAAA;EACZ,MAAA;IAAEC;EAAc,CAAA,GAAIC,qDAA2B,CAAA,CAAA;EACrD,MAAM,CAACC,qBAAA,EAAuBC,wBAAwB,CAAA,GAAIC,KAAAA,CAAAA,SAA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AAI;MAAE,CAAA,CAAA,EAC5BC,8BACE+C,UAAA,CAAAA,GAAA,CAAAe,gCAAA;QAAehB,QAAA,EAAAhC,aAAA,CAAcd,WAAW;OAAE,CAAA,EAAA,eAG7CsC,UAAA,CAAAA,IAAA,CAACyB,kBAAE,CAAAC,MAAA,EAAF;QACCC,gBAAA,EAAkB,CAACrD,cAAkB,IAAAD,eAAA;QACrCuD,WAAa,EAAA7C,UAAA;QACb8C,SAAW,EAAAvC,UAAA;QACXwC,IAAK,EAAA,QAAA;QACLC,QAAU,EAAAzC,UAAA;QACVf,OAAS,EAAAgB,kBAAA;QAETiB,QAAA,EAAA,CAAA,eAAAC,UAAA,CAAAA,GAAA,CAACuB,kBAAE,CAAAC,UAAA,EAAF;UACCL,WAAa,EAAA7C,UAAA;UACb+B,GAAK,EAAAoB,iBAAA,CAAA,SAAA,CAAA;UACLf,KAAO,EAAA,EAAA;UACPC,MAAQ,EAAA;QAAA,CACV,CAAA,EAAA,eACApB,eAAA,CAACmC,kBAAAA,CAAAA,UAAE,EAAF;UACE3B,QAAA,EAAA,CAAAhC,aAAA,CACC,8BAA8BO,UAAa,GAAA,QAAA,GAAW,UAAU,EAClE,CAAA,EACCA,UAAc,IAAA0B,eAAAA,UAAAA,CAAAA,GAAA,CAAC2B,kBAAAA,CAAAA,cAAE,EAAF,CAAiB,CAAA,CAAA;QACnC,CAAA,CAAA;MAAA,CAAA,CAAA;IAEJ,CAAA,CAAA;EAAA,CACF,CAAA;AAEJ,CAAA;"}
1
+ {"version":3,"file":"Product.js","sources":["../../../../../../src/components/ModelCompareV4/ProductList/components/Product/Product.tsx"],"sourcesContent":["import type React from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport plusIcon from \"../../../../../constants/modelCompareData/assets/plus.svg\";\nimport { useModelCompareTranslation } from \"../../../../../constants/modelCompareData/translations/useModelCompareTranslation\";\nimport { imageSrc } from \"../../../../../utils/asset\";\nimport * as S from \"../../ProductList.styles\";\nimport type { ProductProps } from \"./Product.types\";\n\nexport const Product = ({\n id,\n groupId,\n image,\n name,\n description,\n selectedProducts,\n setSelectedProducts,\n groupIsActive,\n groupIndex,\n groupLength,\n playAnimation,\n canPlayAniimation,\n selectedProductsLimit,\n setExternalState,\n showProductGroups,\n isStaticProduct,\n isOverviewPage,\n onClick,\n}: ProductProps) => {\n const { formatMessage } = useModelCompareTranslation();\n const [startingClickPosition, setStartingClickPosition] = useState(0);\n const [hasBeenClicked, setHasBeenClicked] = useState(false);\n\n const isSelected = useMemo(\n () => selectedProducts.some((product) => product.productId === id),\n [selectedProducts, id],\n );\n const isOnlySelectedProduct = useMemo(\n () => isSelected && selectedProducts.length === 1,\n [isSelected, selectedProducts],\n );\n const isDisabled = useMemo(\n () =>\n (!isSelected && selectedProducts.length === selectedProductsLimit) ||\n isOnlySelectedProduct,\n [\n isSelected,\n selectedProducts,\n selectedProductsLimit,\n isOnlySelectedProduct,\n ],\n );\n\n const buttonClickHandler = useCallback(() => {\n const newProductList = selectedProducts.filter(\n (product) => product.productId !== id,\n );\n if (setExternalState) {\n setExternalState((prev) =>\n isSelected\n ? newProductList\n : [...prev, { productId: id, groupId: groupId }],\n );\n }\n\n setSelectedProducts((prev) =>\n isSelected\n ? newProductList\n : [...prev, { productId: id, groupId: groupId }],\n );\n }, [\n selectedProducts,\n id,\n groupId,\n isSelected,\n setExternalState,\n setSelectedProducts,\n ]);\n\n const onPointerUpHandler = (event: React.PointerEvent<HTMLDivElement>) => {\n if (event.clientX === startingClickPosition) setHasBeenClicked(true);\n };\n\n useEffect(() => {\n if (hasBeenClicked) {\n onClick();\n setHasBeenClicked(false);\n }\n }, [hasBeenClicked, onClick]);\n\n return (\n <S.Product\n $isActive={groupIsActive}\n $groupIndex={groupIndex}\n $groupLength={groupLength}\n $playAnimation={playAnimation}\n $canPlayAniimation={canPlayAniimation}\n $productGroupsSelectorExists={showProductGroups}\n >\n <S.ProductCardOnClickArea\n onPointerDown={(event) => setStartingClickPosition(event.clientX)}\n onPointerUp={(event) => onPointerUpHandler(event)}\n />\n {image.src && (\n <S.Image\n loading=\"lazy\"\n decoding=\"async\"\n src={imageSrc(image.src)}\n alt={name}\n width={image.width}\n height={image.height}\n />\n )}\n <S.DescriptionButtonContainer>\n <S.Name>{formatMessage(name)}</S.Name>\n {description && (\n <S.Description>{formatMessage(description)}</S.Description>\n )}\n\n <S.Button\n $isStaticProduct={!isOverviewPage && isStaticProduct}\n $isSelected={isSelected}\n $disabled={isDisabled}\n type=\"button\"\n disabled={isDisabled}\n onClick={buttonClickHandler}\n >\n <S.ButtonIcon\n $isSelected={isSelected}\n src={plusIcon}\n width={20}\n height={20}\n />\n <S.ButtonCopy>\n {formatMessage(\n `commons.productList.button.${isSelected ? \"active\" : \"inactive\"}`,\n )}\n {isSelected && <S.CopyWhiteSpace />}\n </S.ButtonCopy>\n </S.Button>\n </S.DescriptionButtonContainer>\n </S.Product>\n );\n};\n"],"names":["Product","id","groupId","image","name","description","selectedProducts","setSelectedProducts","groupIsActive","groupIndex","groupLength","playAnimation","canPlayAniimation","selectedProductsLimit","setExternalState","showProductGroups","isStaticProduct","isOverviewPage","onClick","formatMessage","useModelCompareTranslation","startingClickPosition","setStartingClickPosition","useState","hasBeenClicked","setHasBeenClicked","isSelected","useMemo","some","product","productId","isOnlySelectedProduct","length","isDisabled","buttonClickHandler","useCallback","newProductList","filter","prev","onPointerUpHandler","event","clientX","useEffect","jsxs","S.Product","$isActive","$groupIndex","$groupLength","$playAnimation","$canPlayAniimation","$productGroupsSelectorExists","children","jsx","S.ProductCardOnClickArea","ProductCardOnClickArea","onPointerDown","onPointerUp","src","S.Image","Image","loading","decoding","imageSrc","alt","width","height","S.DescriptionButtonContainer","S.Name","Name","S.Description","S.Button","Button","$isStaticProduct","$isSelected","$disabled","type","disabled","S.ButtonIcon","ButtonIcon","plusIcon","S.ButtonCopy","S.CopyWhiteSpace"],"mappings":";;;;;;;;;;;;;;;;AASO,MAAMA,UAAUA,CAAC;EACtBC,EAA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,EAAF,CAAiB,CAAA,CAAA;QACnC,CAAA,CAAA;MAAA,CAAA,CAAA;IAEJ,CAAA,CAAA;EAAA,CACF,CAAA;AAEJ,CAAA;"}
@@ -67,6 +67,8 @@ const Product = ({
67
67
  onPointerDown: event => setStartingClickPosition(event.clientX),
68
68
  onPointerUp: event => onPointerUpHandler(event)
69
69
  }), image.src && /* @__PURE__ */jsx(Image, {
70
+ loading: "lazy",
71
+ decoding: "async",
70
72
  src: imageSrc(image.src),
71
73
  alt: name,
72
74
  width: image.width,