@treely/strapi-slices 6.1.1 → 6.2.1

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.
@@ -2526,6 +2526,17 @@ var ContextProvider = function ContextProvider(_ref) {
2526
2526
  }, children));
2527
2527
  };
2528
2528
 
2529
+ var shuffleElements = function shuffleElements(slides) {
2530
+ var slidesCopy = [].concat(slides); // Create a copy to avoid mutating the original array
2531
+ for (var i = slidesCopy.length - 1; i > 0; i--) {
2532
+ var j = Math.floor(Math.random() * (i + 1));
2533
+ var _ref = [slidesCopy[j], slidesCopy[i]];
2534
+ slidesCopy[i] = _ref[0];
2535
+ slidesCopy[j] = _ref[1];
2536
+ }
2537
+ return slidesCopy;
2538
+ };
2539
+
2529
2540
  var ITEM_GAP$1 = 24;
2530
2541
  var MAX_OFFSET_RIGHT$1 = 55;
2531
2542
  var TextCarousel = function TextCarousel(_ref) {
@@ -2542,9 +2553,12 @@ var TextCarousel = function TextCarousel(_ref) {
2542
2553
  windowWidth = _useWindowSize.width;
2543
2554
  var _useRouter = useRouter(),
2544
2555
  push = _useRouter.push;
2545
- var _useState = useState(0),
2546
- sliderIndex = _useState[0],
2547
- setSliderIndex = _useState[1];
2556
+ var _useState = useState(slice.slides),
2557
+ displaySlides = _useState[0],
2558
+ setDisplaySlides = _useState[1];
2559
+ var _useState2 = useState(0),
2560
+ sliderIndex = _useState2[0],
2561
+ setSliderIndex = _useState2[1];
2548
2562
  var numberOfItems = useMemo(function () {
2549
2563
  return slice.slides.length;
2550
2564
  }, [slice.slides.length]);
@@ -2564,6 +2578,14 @@ var TextCarousel = function TextCarousel(_ref) {
2564
2578
  var canMoveLeft = useMemo(function () {
2565
2579
  return sliderIndex !== 0;
2566
2580
  }, [sliderIndex]);
2581
+ var slides = slice.slides,
2582
+ _slice$isShuffled = slice.isShuffled,
2583
+ isShuffled = _slice$isShuffled === void 0 ? false : _slice$isShuffled;
2584
+ useEffect(function () {
2585
+ if (isShuffled && typeof window === 'undefined') {
2586
+ setDisplaySlides(shuffleElements(slides));
2587
+ }
2588
+ }, [slides, isShuffled]);
2567
2589
  return React.createElement(DefaultSectionContainer, {
2568
2590
  backgroundColor: primary50,
2569
2591
  title: slice.title
@@ -2598,7 +2620,7 @@ var TextCarousel = function TextCarousel(_ref) {
2598
2620
  duration: 0.3,
2599
2621
  ease: 'easeInOut'
2600
2622
  }
2601
- }, slice.slides.map(function (_ref2) {
2623
+ }, displaySlides.map(function (_ref2) {
2602
2624
  var id = _ref2.id,
2603
2625
  title = _ref2.title,
2604
2626
  text = _ref2.text,