yet-another-react-lightbox 3.16.0 → 3.17.0

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
@@ -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);
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.0",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",