From 7f2c48b6b67a19652a6c876a612294551c3d0ba1 Mon Sep 17 00:00:00 2001 From: Pedro Figueroa <59029273+mardelnet@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:15:04 +0100 Subject: [PATCH] PLANET-7446: Remove lightbox (#1259) PLANET-7446: Force no lightbox - Remove lightbox from paragraphs by class name --- assets/src/blocks/Gallery/GalleryFrontend.js | 30 +- assets/src/components/Lightbox/Lightbox.js | 118 ---- .../Lightbox/setupLightboxForImages.js | 54 -- assets/src/components/Lightbox/useLightbox.js | 18 - assets/src/frontendIndex.js | 3 - assets/src/styles/lightbox.scss | 1 - .../vendors/photoswipe/_main-settings.scss | 19 - .../src/styles/vendors/photoswipe/main.scss | 189 ------ .../styles/vendors/photoswipe/p4-skin.scss | 601 ------------------ .../photoswipe/planet4-photoswipe.scss | 5 - classes/class-loader.php | 7 - .../vendors/photoswipe/default-skin.png | Bin 547 -> 0 bytes .../vendors/photoswipe/default-skin.svg | 1 - .../images/vendors/photoswipe/preloader.gif | Bin 866 -> 0 bytes webpack.config.js | 1 - 15 files changed, 3 insertions(+), 1044 deletions(-) delete mode 100644 assets/src/components/Lightbox/Lightbox.js delete mode 100644 assets/src/components/Lightbox/setupLightboxForImages.js delete mode 100644 assets/src/components/Lightbox/useLightbox.js delete mode 100644 assets/src/styles/lightbox.scss delete mode 100644 assets/src/styles/vendors/photoswipe/_main-settings.scss delete mode 100644 assets/src/styles/vendors/photoswipe/main.scss delete mode 100644 assets/src/styles/vendors/photoswipe/p4-skin.scss delete mode 100644 assets/src/styles/vendors/photoswipe/planet4-photoswipe.scss delete mode 100644 public/images/vendors/photoswipe/default-skin.png delete mode 100644 public/images/vendors/photoswipe/default-skin.svg delete mode 100644 public/images/vendors/photoswipe/preloader.gif diff --git a/assets/src/blocks/Gallery/GalleryFrontend.js b/assets/src/blocks/Gallery/GalleryFrontend.js index 57deb8569..32e47c3ca 100644 --- a/assets/src/blocks/Gallery/GalleryFrontend.js +++ b/assets/src/blocks/Gallery/GalleryFrontend.js @@ -3,34 +3,15 @@ import {GalleryCarousel} from './GalleryCarousel'; import {GalleryThreeColumns} from './GalleryThreeColumns'; import {GalleryGrid} from './GalleryGrid'; import {getGalleryLayout, GALLERY_BLOCK_CLASSES} from './getGalleryLayout'; -import {getCaptionWithCredits} from './getCaptionWithCredits.js'; -import {Lightbox} from '../../components/Lightbox/Lightbox'; -import {useLightbox} from '../../components/Lightbox/useLightbox'; - -const imagesToItems = images => images.map( - image => ({ - src: image.image_src, - w: 0, - h: 0, - title: getCaptionWithCredits(image), - }) -); export const GalleryFrontend = ({ attributes = {}, - renderLightbox = false, }) => { const [images, setImages] = useState([]); - const [items, setItems] = useState([]); - const {isOpen, index, openLightbox, closeLightbox} = useLightbox(); const className = attributes.className ?? ''; const layout = getGalleryLayout(className, attributes.gallery_block_style ?? ''); const postType = document.body.getAttribute('data-post-type'); - useEffect(() => { - setItems(imagesToItems(images)); - }, [images]); - useEffect(() => { if (attributes.image_data.length && attributes.images.length) { setImages(attributes.images); @@ -54,16 +35,11 @@ export const GalleryFrontend = ({ {images.length ? ( <> - {layout === 'slider' && } - {layout === 'three-columns' && } - {layout === 'grid' && } + {layout === 'slider' && } + {layout === 'three-columns' && } + {layout === 'grid' && } ) : null} - - {(renderLightbox && items.length) ? - : - null - } ); }; diff --git a/assets/src/components/Lightbox/Lightbox.js b/assets/src/components/Lightbox/Lightbox.js deleted file mode 100644 index 40ee3b2be..000000000 --- a/assets/src/components/Lightbox/Lightbox.js +++ /dev/null @@ -1,118 +0,0 @@ -import {useEffect, useRef, useState} from '@wordpress/element'; - -import PhotoSwipe from '../../../../node_modules/photoswipe/dist/photoswipe.js'; -import PhotoSwipeUI_Default from '../../../../node_modules/photoswipe/dist/photoswipe-ui-default.js'; - -// `items` should be an array of object with this shape: -// [{ src, w, h, title }, ...] -// See: https://photoswipe.com/documentation/getting-started.html -export const Lightbox = ({index, isOpen, items, onClose = () => {}}) => { - let photoSwipeElement = useRef(null); - - const photoSwipeOptions = { - index: index || 0, - closeOnScroll: false, - history: false, - fullscreenEl: false, - zoomEl: false, - shareEl: false, - counterEl: false, - }; - - const [currentIndex, setCurrentIndex] = useState(photoSwipeOptions.index); - - useEffect(() => { - if (!isOpen) { - return; - } - - const photoSwipe = new PhotoSwipe(photoSwipeElement, PhotoSwipeUI_Default, items, photoSwipeOptions); - - // eslint-disable-next-line no-shadow - photoSwipe.listen('gettingData', (index, galleryItem) => { - if (galleryItem.w < 1 || galleryItem.h < 1) { - const imageSizeHandler = new Image(); - imageSizeHandler.onload = function() { - galleryItem.w = this.width; - galleryItem.h = this.height; - photoSwipe.updateSize(true); - }; - imageSizeHandler.src = galleryItem.src; - } - }); - - photoSwipe.listen('destroy', () => { - onClose(); - }); - - photoSwipe.listen('close', () => { - onClose(); - }); - - photoSwipe.listen('afterChange', () => { - setCurrentIndex(photoSwipe.getCurrentIndex()); - }); - - photoSwipe.init(); - }, [items, isOpen, index]); - - return wp.element.createPortal( -