yet-another-react-lightbox 3.16.0 → 3.17.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.
package/README.md CHANGED
@@ -34,6 +34,10 @@ extendable.
34
34
 
35
35
  [https://yet-another-react-lightbox.com/examples](https://yet-another-react-lightbox.com/examples)
36
36
 
37
+ ## Changelog
38
+
39
+ [https://github.com/igordanchenko/yet-another-react-lightbox/releases](https://github.com/igordanchenko/yet-another-react-lightbox/releases)
40
+
37
41
  ## Installation
38
42
 
39
43
  ```shell
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { LightboxExternalProps, LightboxProps, Labels, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, CarouselSettings, Component, Module, Node, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, Render, ControllerRef, Callback, RenderFunction } from './types.js';
3
- export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, AnimationSettings, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Callbacks, ClickCallbackProps, ControllerSettings, DeepPartial, DeepPartialValue, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, ImageFit, ImageSource, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, NavigationAction, NoScrollSettings, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, PluginProps, PortalSettings, RenderSlideContainerProps, RenderSlideFooterProps, RenderSlideHeaderProps, RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, SlideStatus, SlideTypeKey, SlideTypes, Slot, SlotStyles, SlotType, ToolbarButtonKey, ToolbarButtonKeys, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, ViewCallbackProps, activeSlideStatus } from './types.js';
2
+ import { LightboxExternalProps, LightboxProps, Labels, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, CarouselSettings, Component, Module, Node, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, Render, ControllerSettings, ControllerRef, Callback, RenderFunction } from './types.js';
3
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, AnimationSettings, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Callbacks, ClickCallbackProps, DeepPartial, DeepPartialValue, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, ImageFit, ImageSource, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, NavigationAction, NoScrollSettings, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, PluginProps, PortalSettings, RenderSlideContainerProps, RenderSlideFooterProps, RenderSlideHeaderProps, RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, SlideStatus, SlideTypeKey, SlideTypes, Slot, SlotStyles, SlotType, ToolbarButtonKey, ToolbarButtonKeys, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, ViewCallbackProps, activeSlideStatus } from './types.js';
4
4
 
5
5
  /** Lightbox component */
6
6
  declare function Lightbox({ carousel, animation, render, toolbar, controller, noScroll, on, plugins, slides, index, ...restProps }: LightboxExternalProps): React.JSX.Element | null;
@@ -208,9 +208,13 @@ declare enum SwipeState {
208
208
 
209
209
  declare function usePointerSwipe<T extends Element = Element>(subscribeSensors: UseSensors<T>["subscribeSensors"], isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void, pullUpEnabled: boolean, pullDownEnabled: boolean, onPullStart: () => void, onPullProgress: (offset: number) => void, onPullFinish: (offset: number, duration: number) => void, onPullCancel: (offset: number) => void): void;
210
210
 
211
- /** prevent browser back/forward navigation on touchpad left/right swipe (especially noticeable in Safari)
212
- * this has to be done via non-passive native event handler */
213
- declare function usePreventSwipeNavigation<T extends HTMLElement = HTMLElement>(): (node: T | null) => void;
211
+ /**
212
+ * Prevent default effects of the wheel events:
213
+ * - prevent browser back/forward navigation on touchpad left/right swipe (especially noticeable in Safari)
214
+ * - prevent vertical scroll in inline mode when `scrollToZoom` option is enabled
215
+ * - prevent page zoom when Zoom plugin is enabled
216
+ */
217
+ declare function usePreventWheelDefaults<T extends HTMLElement = HTMLElement>({ preventDefaultWheelX, preventDefaultWheelY, }: Pick<ControllerSettings, "preventDefaultWheelX" | "preventDefaultWheelY">): (node: T | null) => void;
214
218
 
215
219
  declare function useWheelSwipe<T extends Element = Element>(swipeState: SwipeState, subscribeSensors: UseSensors<T>["subscribeSensors"], isSwipeValid: (offset: number) => boolean, containerWidth: number, swipeAnimationDuration: number, onSwipeStart: () => void, onSwipeProgress: (offset: number) => void, onSwipeFinish: (offset: number, duration: number) => void, onSwipeCancel: (offset: number) => void): void;
216
220
 
@@ -261,4 +265,4 @@ declare const RootModule: Module;
261
265
  declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose }, styles }: ComponentProps): React.JSX.Element;
262
266
  declare const ToolbarModule: Module;
263
267
 
264
- export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventSwipeNavigation, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
268
+ export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
package/dist/index.js CHANGED
@@ -113,6 +113,8 @@ const LightboxDefaultProps = {
113
113
  closeOnPullUp: false,
114
114
  closeOnPullDown: false,
115
115
  closeOnBackdropClick: false,
116
+ preventDefaultWheelX: true,
117
+ preventDefaultWheelY: false,
116
118
  },
117
119
  portal: {},
118
120
  noScroll: {
@@ -752,24 +754,24 @@ function usePointerSwipe(subscribeSensors, isSwipeValid, containerWidth, swipeAn
752
754
  usePointerEvents(subscribeSensors, onPointerDown, onPointerMove, onPointerUp);
753
755
  }
754
756
 
755
- const WHEEL = "wheel";
756
- function preventDefault(event) {
757
- if (Math.abs(event.deltaX) > Math.abs(event.deltaY) || event.ctrlKey) {
758
- event.preventDefault();
759
- }
760
- }
761
- function usePreventSwipeNavigation() {
757
+ function usePreventWheelDefaults({ preventDefaultWheelX, preventDefaultWheelY, }) {
762
758
  const ref = React.useRef(null);
759
+ const listener = useEventCallback((event) => {
760
+ const horizontal = Math.abs(event.deltaX) > Math.abs(event.deltaY);
761
+ if ((horizontal && preventDefaultWheelX) || (!horizontal && preventDefaultWheelY) || event.ctrlKey) {
762
+ event.preventDefault();
763
+ }
764
+ });
763
765
  return React.useCallback((node) => {
764
766
  var _a;
765
767
  if (node) {
766
- node.addEventListener(WHEEL, preventDefault, { passive: false });
768
+ node.addEventListener("wheel", listener, { passive: false });
767
769
  }
768
770
  else {
769
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(WHEEL, preventDefault);
771
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("wheel", listener);
770
772
  }
771
773
  ref.current = node;
772
- }, []);
774
+ }, [listener]);
773
775
  }
774
776
 
775
777
  function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel) {
@@ -866,6 +868,7 @@ const useController = makeUseContext("useController", "ControllerContext", Contr
866
868
  function Controller({ children, ...props }) {
867
869
  var _a;
868
870
  const { carousel, animation, controller, on, styles, render } = props;
871
+ const { closeOnPullUp, closeOnPullDown, preventDefaultWheelX, preventDefaultWheelY } = controller;
869
872
  const [toolbarWidth, setToolbarWidth] = React.useState();
870
873
  const state = useLightboxState();
871
874
  const dispatch = useLightboxDispatch();
@@ -879,7 +882,7 @@ function Controller({ children, ...props }) {
879
882
  const cleanupSwipeOffset = useDelay();
880
883
  const cleanupPullOffset = useDelay();
881
884
  const { containerRef, setContainerRef, containerRect } = useContainerRect();
882
- const handleContainerRef = useForkRef(usePreventSwipeNavigation(), setContainerRef);
885
+ const handleContainerRef = useForkRef(usePreventWheelDefaults({ preventDefaultWheelX, preventDefaultWheelY }), setContainerRef);
883
886
  const carouselRef = React.useRef(null);
884
887
  const setCarouselRef = useForkRef(carouselRef, undefined);
885
888
  const isRTL = useRTL();
@@ -898,7 +901,6 @@ function Controller({ children, ...props }) {
898
901
  swipeOffset.current = offset;
899
902
  (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.style.setProperty(cssVar("swipe_offset"), `${Math.round(offset)}px`);
900
903
  };
901
- const { closeOnPullUp, closeOnPullDown } = controller;
902
904
  const setPullOffset = (offset) => {
903
905
  var _a, _b;
904
906
  pullOffset.current = offset;
@@ -1467,4 +1469,4 @@ function Lightbox({ carousel, animation, render, toolbar, controller, noScroll,
1467
1469
  React.createElement(EventsProvider, null, renderNode(createNode(RootModule, config), props))))));
1468
1470
  }
1469
1471
 
1470
- export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Carousel, CarouselModule, CloseIcon, Controller, ControllerContext, ControllerModule, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, ErrorIcon, EventsContext, EventsProvider, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, IconButton, ImageSlide, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxPropsContext, LightboxPropsProvider, LightboxStateContext, LightboxStateProvider, LoadingIcon, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, Navigation, NavigationButton, NavigationModule, NextIcon, NoScroll, NoScrollModule, Portal, PortalModule, PreviousIcon, Root, RootModule, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SwipeState, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerEvents, usePointerSwipe, usePreventSwipeNavigation, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
1472
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, Carousel, CarouselModule, CloseIcon, Controller, ControllerContext, ControllerModule, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, ErrorIcon, EventsContext, EventsProvider, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, IconButton, ImageSlide, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxPropsContext, LightboxPropsProvider, LightboxStateContext, LightboxStateProvider, LoadingIcon, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, Navigation, NavigationButton, NavigationModule, NextIcon, NoScroll, NoScrollModule, Portal, PortalModule, PreviousIcon, Root, RootModule, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SwipeState, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerEvents, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useLightboxState, cssClass, clsx, createModule } from '../../index.js';
2
+ import { useLightboxState, clsx, cssClass, createModule } from '../../index.js';
3
3
  import { MODULE_CONTROLLER, PLUGIN_COUNTER } from '../../types.js';
4
4
 
5
5
  const defaultCounterProps = {
@@ -22,6 +22,12 @@ declare module "yet-another-react-lightbox" {
22
22
  /** render custom Exit Fullscreen icon */
23
23
  iconExitFullscreen?: RenderFunction;
24
24
  }
25
+ interface Callbacks {
26
+ /** a callback called when the lightbox enters fullscreen mode */
27
+ enterFullscreen?: Callback;
28
+ /** a callback called when the lightbox exits fullscreen mode */
29
+ exitFullscreen?: Callback;
30
+ }
25
31
  interface ToolbarButtonKeys {
26
32
  [PLUGIN_FULLSCREEN]: null;
27
33
  }
@@ -1,4 +1,4 @@
1
- import { makeUseContext, useLayoutEffect, useEventCallback, cssClass, clsx, createIcon, useLightboxProps, IconButton, addToolbarButton, createModule } from '../../index.js';
1
+ import { makeUseContext, useLayoutEffect, useEventCallback, clsx, cssClass, createIcon, useLightboxProps, IconButton, addToolbarButton, createModule } from '../../index.js';
2
2
  import * as React from 'react';
3
3
  import { PLUGIN_FULLSCREEN, CLASS_FULLSIZE, PLUGIN_THUMBNAILS, MODULE_CONTROLLER } from '../../types.js';
4
4
 
@@ -13,11 +13,12 @@ const resolveFullscreenProps = (fullscreen) => ({
13
13
 
14
14
  const FullscreenContext = React.createContext(null);
15
15
  const useFullscreen = makeUseContext("useFullscreen", "FullscreenContext", FullscreenContext);
16
- function FullscreenContextProvider({ fullscreen: fullscreenProps, children }) {
16
+ function FullscreenContextProvider({ fullscreen: fullscreenProps, on, children }) {
17
17
  const { auto, ref } = resolveFullscreenProps(fullscreenProps);
18
18
  const containerRef = React.useRef(null);
19
- const [fullscreen, setFullscreen] = React.useState(false);
20
19
  const [disabled, setDisabled] = React.useState();
20
+ const [fullscreen, setFullscreen] = React.useState(false);
21
+ const wasFullscreen = React.useRef(false);
21
22
  useLayoutEffect(() => {
22
23
  var _a, _b, _c, _d;
23
24
  setDisabled(!((_d = (_c = (_b = (_a = document.fullscreenEnabled) !== null && _a !== void 0 ? _a : document.webkitFullscreenEnabled) !== null && _b !== void 0 ? _b : document.mozFullScreenEnabled) !== null && _c !== void 0 ? _c : document.msFullscreenEnabled) !== null && _d !== void 0 ? _d : false));
@@ -67,16 +68,11 @@ function FullscreenContextProvider({ fullscreen: fullscreenProps, children }) {
67
68
  }
68
69
  }
69
70
  }, [getFullscreenElement]);
70
- const fullscreenChangeListener = React.useCallback(() => {
71
- if (getFullscreenElement() === containerRef.current) {
72
- setFullscreen(true);
73
- }
74
- else {
75
- setFullscreen(false);
76
- }
77
- }, [getFullscreenElement]);
78
71
  React.useEffect(() => {
79
72
  const events = ["fullscreenchange", "webkitfullscreenchange", "mozfullscreenchange", "MSFullscreenChange"];
73
+ const fullscreenChangeListener = () => {
74
+ setFullscreen(getFullscreenElement() === containerRef.current);
75
+ };
80
76
  events.forEach((event) => {
81
77
  document.addEventListener(event, fullscreenChangeListener);
82
78
  });
@@ -85,7 +81,17 @@ function FullscreenContextProvider({ fullscreen: fullscreenProps, children }) {
85
81
  document.removeEventListener(event, fullscreenChangeListener);
86
82
  });
87
83
  };
88
- }, [fullscreenChangeListener]);
84
+ }, [getFullscreenElement]);
85
+ const onEnterFullscreen = useEventCallback(() => { var _a; return (_a = on.enterFullscreen) === null || _a === void 0 ? void 0 : _a.call(on); });
86
+ const onExitFullscreen = useEventCallback(() => { var _a; return (_a = on.exitFullscreen) === null || _a === void 0 ? void 0 : _a.call(on); });
87
+ React.useEffect(() => {
88
+ if (fullscreen) {
89
+ wasFullscreen.current = true;
90
+ }
91
+ if (wasFullscreen.current) {
92
+ (fullscreen ? onEnterFullscreen : onExitFullscreen)();
93
+ }
94
+ }, [fullscreen, onEnterFullscreen, onExitFullscreen]);
89
95
  const handleAutoFullscreen = useEventCallback(() => { var _a; return (_a = (auto ? enter : null)) === null || _a === void 0 ? void 0 : _a(); });
90
96
  React.useEffect(() => {
91
97
  handleAutoFullscreen();
@@ -1,4 +1,4 @@
1
- import { cssClass, clsx, createModule } from '../../index.js';
1
+ import { clsx, cssClass, createModule } from '../../index.js';
2
2
  import * as React from 'react';
3
3
  import { ACTION_CLOSE, MODULE_NO_SCROLL, MODULE_PORTAL, PLUGIN_INLINE } from '../../types.js';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useLightboxProps, useEvents, useContainerRect, useEventCallback, cssClass, clsx } from '../../index.js';
2
+ import { useLightboxProps, useEvents, useContainerRect, useEventCallback, clsx, cssClass } from '../../index.js';
3
3
  import { ACTIVE_SLIDE_LOADING, CLASS_FLEX_CENTER, CLASS_SLIDE_WRAPPER, ACTIVE_SLIDE_PLAYING, ACTIVE_SLIDE_COMPLETE } from '../../types.js';
4
4
 
5
5
  const defaultVideoProps = {
@@ -1,4 +1,4 @@
1
- import { useLightboxProps, useMotionPreference, useEventCallback, useLayoutEffect, useLightboxState, isImageSlide, isImageFitCover, round, useController, usePointerEvents, cleanup, makeUseContext, createIcon, IconButton, devicePixelRatio, ImageSlide, cssClass, clsx, addToolbarButton, createModule } from '../../index.js';
1
+ import { useLightboxProps, useMotionPreference, useEventCallback, useLayoutEffect, useLightboxState, isImageSlide, isImageFitCover, round, useController, usePointerEvents, cleanup, makeUseContext, createIcon, IconButton, devicePixelRatio, ImageSlide, clsx, cssClass, addToolbarButton, createModule } from '../../index.js';
2
2
  import * as React from 'react';
3
3
  import { EVENT_ON_KEY_DOWN, EVENT_ON_WHEEL, UNKNOWN_ACTION_TYPE, CLASS_FULLSIZE, CLASS_FLEX_CENTER, CLASS_SLIDE_WRAPPER, PLUGIN_ZOOM } from '../../types.js';
4
4
 
@@ -76,11 +76,11 @@ function useZoomImageRect(slideRect, imageDimensions) {
76
76
  var _a, _b;
77
77
  let imageRect = { width: 0, height: 0 };
78
78
  let maxImageRect = { width: 0, height: 0 };
79
- const { slides, currentIndex } = useLightboxState();
79
+ const { currentSlide } = useLightboxState();
80
80
  const { imageFit } = useLightboxProps().carousel;
81
81
  const { maxZoomPixelRatio } = useZoomProps();
82
- if (slideRect && currentIndex < slides.length) {
83
- const slide = { ...slides[currentIndex], ...imageDimensions };
82
+ if (slideRect && currentSlide) {
83
+ const slide = { ...currentSlide, ...imageDimensions };
84
84
  if (isImageSlide(slide)) {
85
85
  const cover = isImageFitCover(slide, imageFit);
86
86
  const width = Math.max(...(((_a = slide.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) || []).concat(slide.width ? [slide.width] : []));
@@ -265,23 +265,15 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
265
265
  }, [disabled, subscribeSensors, cleanupSensors, onKeyDown, onWheel]);
266
266
  }
267
267
 
268
- function getCurrentSource(slides, currentIndex) {
269
- if (currentIndex < slides.length) {
270
- const slide = slides[currentIndex];
271
- if (isImageSlide(slide))
272
- return slide.src;
273
- }
274
- return undefined;
275
- }
276
268
  function useZoomState(imageRect, maxZoom, zoomWrapperRef) {
277
269
  const [zoom, setZoom] = React.useState(1);
278
270
  const [offsetX, setOffsetX] = React.useState(0);
279
271
  const [offsetY, setOffsetY] = React.useState(0);
280
272
  const animate = useZoomAnimation(zoom, offsetX, offsetY, zoomWrapperRef);
281
- const { slides, currentIndex, globalIndex } = useLightboxState();
273
+ const { currentSlide, globalIndex } = useLightboxState();
282
274
  const { containerRect, slideRect } = useController();
283
275
  const { zoomInMultiplier } = useZoomProps();
284
- const currentSource = getCurrentSource(slides, currentIndex);
276
+ const currentSource = currentSlide && isImageSlide(currentSlide) ? currentSlide.src : undefined;
285
277
  const disabled = !currentSource || !(zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current);
286
278
  useLayoutEffect(() => {
287
279
  setZoom(1);
@@ -478,15 +470,19 @@ function ZoomWrapper({ render, slide, offset, rect }) {
478
470
  }
479
471
 
480
472
  const Zoom = ({ augment, addModule }) => {
481
- augment(({ toolbar, render, zoom, ...restProps }) => ({
482
- zoom: resolveZoomProps(zoom),
483
- toolbar: addToolbarButton(toolbar, PLUGIN_ZOOM, React.createElement(ZoomToolbarControl, null)),
484
- render: {
485
- ...render,
486
- slide: (props) => { var _a; return isImageSlide(props.slide) ? React.createElement(ZoomWrapper, { render: render, ...props }) : (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, props); },
487
- },
488
- ...restProps,
489
- }));
473
+ augment(({ zoom: zoomProps, toolbar, render, controller, ...restProps }) => {
474
+ const zoom = resolveZoomProps(zoomProps);
475
+ return {
476
+ zoom,
477
+ toolbar: addToolbarButton(toolbar, PLUGIN_ZOOM, React.createElement(ZoomToolbarControl, null)),
478
+ render: {
479
+ ...render,
480
+ slide: (props) => { var _a; return isImageSlide(props.slide) ? React.createElement(ZoomWrapper, { render: render, ...props }) : (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, props); },
481
+ },
482
+ controller: { ...controller, preventDefaultWheelY: zoom.scrollToZoom },
483
+ ...restProps,
484
+ };
485
+ });
490
486
  addModule(createModule(PLUGIN_ZOOM, ZoomContextProvider));
491
487
  };
492
488
 
package/dist/types.d.ts CHANGED
@@ -235,6 +235,10 @@ interface ControllerSettings {
235
235
  closeOnPullDown: boolean;
236
236
  /** if `true`, close the lightbox when the backdrop is clicked */
237
237
  closeOnBackdropClick: boolean;
238
+ /** if `true`, prevent default for horizontal wheel scroll events (for internal use only) */
239
+ preventDefaultWheelX: boolean;
240
+ /** if `true`, prevent default for vertical wheel scroll events (for internal use only) */
241
+ preventDefaultWheelY: boolean;
238
242
  }
239
243
  /** Lightbox controller ref */
240
244
  interface ControllerRef {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.16.0",
3
+ "version": "3.17.1",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",