From 9e6c9d9082d93dec1a67b47aa89c07dbd78efcc7 Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:05:38 +0300 Subject: [PATCH] Update Swiper Lib (#363) * Update Swiper Lib --- package-lock.json | 17 +-- package.json | 2 +- .../_shared/SolidSwiper/ArticleCardSwiper.tsx | 3 +- .../_shared/SolidSwiper/EditorSwiper.tsx | 3 +- .../_shared/SolidSwiper/ImageSwiper.tsx | 104 +++++++++--------- .../_shared/SolidSwiper/Swiper.module.scss | 69 ++++-------- .../_shared/SolidSwiper/swiper.d.ts | 6 + 7 files changed, 84 insertions(+), 120 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7f88e173..f25bccad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -115,7 +115,7 @@ "stylelint-config-standard-scss": "11.1.0", "stylelint-order": "6.0.3", "stylelint-scss": "5.3.1", - "swiper": "9.4.1", + "swiper": "11.0.5", "throttle-debounce": "5.0.0", "typescript": "5.2.2", "typograf": "7.1.0", @@ -17436,12 +17436,6 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, - "node_modules/ssr-window": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/ssr-window/-/ssr-window-4.0.2.tgz", - "integrity": "sha512-ISv/Ch+ig7SOtw7G2+qkwfVASzazUnvlDTwypdLoPoySv+6MqlOV10VwPSE6EWkGjhW50lUmghPmpYZXMu/+AQ==", - "dev": true - }, "node_modules/stack-utils": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", @@ -17934,9 +17928,9 @@ } }, "node_modules/swiper": { - "version": "9.4.1", - "resolved": "https://registry.npmjs.org/swiper/-/swiper-9.4.1.tgz", - "integrity": "sha512-1nT2T8EzUpZ0FagEqaN/YAhRj33F2x/lN6cyB0/xoYJDMf8KwTFT3hMOeoB8Tg4o3+P/CKqskP+WX0Df046fqA==", + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/swiper/-/swiper-11.0.5.tgz", + "integrity": "sha512-rhCwupqSyRnWrtNzWzemnBLMoyYuoDgGgspAm/8iBD3jCvAWycPLH4Z3TB0O5520DHLzMx94yUMH/B9Efpa48w==", "dev": true, "funding": [ { @@ -17948,9 +17942,6 @@ "url": "http://opencollective.com/swiper" } ], - "dependencies": { - "ssr-window": "^4.0.2" - }, "engines": { "node": ">= 4.7.0" } diff --git a/package.json b/package.json index 52328787..1c9101ed 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "stylelint-config-standard-scss": "11.1.0", "stylelint-order": "6.0.3", "stylelint-scss": "5.3.1", - "swiper": "9.4.1", + "swiper": "11.0.5", "throttle-debounce": "5.0.0", "typescript": "5.2.2", "typograf": "7.1.0", diff --git a/src/components/_shared/SolidSwiper/ArticleCardSwiper.tsx b/src/components/_shared/SolidSwiper/ArticleCardSwiper.tsx index df4d44be..60adf711 100644 --- a/src/components/_shared/SolidSwiper/ArticleCardSwiper.tsx +++ b/src/components/_shared/SolidSwiper/ArticleCardSwiper.tsx @@ -1,6 +1,7 @@ import { clsx } from 'clsx' import { For, onMount, Show } from 'solid-js' -import SwiperCore, { Manipulation, Navigation, Pagination } from 'swiper' +import SwiperCore from 'swiper' +import { Manipulation, Navigation, Pagination } from 'swiper/modules' import { Shout } from '../../../graphql/types.gen' import { ArticleCard } from '../../Feed/ArticleCard' diff --git a/src/components/_shared/SolidSwiper/EditorSwiper.tsx b/src/components/_shared/SolidSwiper/EditorSwiper.tsx index dc9f06e6..6c5c7670 100644 --- a/src/components/_shared/SolidSwiper/EditorSwiper.tsx +++ b/src/components/_shared/SolidSwiper/EditorSwiper.tsx @@ -1,7 +1,8 @@ import { createFileUploader } from '@solid-primitives/upload' import { clsx } from 'clsx' import { createEffect, createSignal, For, Show, on, onMount, lazy } from 'solid-js' -import SwiperCore, { Manipulation, Navigation, Pagination } from 'swiper' +import SwiperCore from 'swiper' +import { Manipulation, Navigation, Pagination } from 'swiper/modules' import { useLocalize } from '../../../context/localize' import { useSnackbar } from '../../../context/snackbar' diff --git a/src/components/_shared/SolidSwiper/ImageSwiper.tsx b/src/components/_shared/SolidSwiper/ImageSwiper.tsx index 5364e47b..2aa782ff 100644 --- a/src/components/_shared/SolidSwiper/ImageSwiper.tsx +++ b/src/components/_shared/SolidSwiper/ImageSwiper.tsx @@ -1,6 +1,7 @@ import { clsx } from 'clsx' import { createEffect, createSignal, For, Show, on, onMount, onCleanup } from 'solid-js' -import SwiperCore, { Manipulation, Navigation, Pagination } from 'swiper' +import SwiperCore from 'swiper' +import { Manipulation, Navigation, Pagination } from 'swiper/modules' import { throttle } from 'throttle-debounce' import { MediaItem } from '../../../pages/types' @@ -27,7 +28,6 @@ export const ImageSwiper = (props: Props) => { const mainSwipeRef: { current: SwiperRef } = { current: null } const thumbSwipeRef: { current: SwiperRef } = { current: null } const swiperMainContainer: { current: HTMLDivElement } = { current: null } - const [slideIndex, setSlideIndex] = createSignal(0) const [isMobileView, setIsMobileView] = createSignal(false) const [selectedImage, setSelectedImage] = createSignal('') @@ -52,18 +52,13 @@ export const ImageSwiper = (props: Props) => { const { register } = await import('swiper/element/bundle') register() SwiperCore.use([Pagination, Navigation, Manipulation]) + mainSwipeRef.current.swiper.on('slideChange', handleSlideChange) }) onMount(() => { const updateDirection = () => { const width = window.innerWidth - const direction = width > MIN_WIDTH ? 'vertical' : 'horizontal' - if (direction === 'horizontal') { - setIsMobileView(true) - } else { - setIsMobileView(false) - } - thumbSwipeRef.current?.swiper?.changeDirection(direction) + setIsMobileView(width < MIN_WIDTH) } updateDirection() @@ -96,13 +91,58 @@ export const ImageSwiper = (props: Props) => {