yet-another-react-lightbox 3.5.1 → 3.5.3
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/dist/core/modules/Controller.js +1 -1
- package/dist/plugins/download/index.d.ts +1 -0
- package/dist/plugins/slideshow/SlideshowContext.d.ts +1 -1
- package/dist/plugins/slideshow/SlideshowContext.js +13 -1
- package/dist/plugins/slideshow/index.d.ts +7 -1
- package/dist/plugins/video/VideoSlide.js +14 -10
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ export function Controller({ children, ...props }) {
|
|
|
12
12
|
var _a;
|
|
13
13
|
const { carousel, animation, controller, on, styles, render } = props;
|
|
14
14
|
const [toolbarWidth, setToolbarWidth] = React.useState();
|
|
15
|
-
const
|
|
15
|
+
const state = useLightboxState();
|
|
16
16
|
const dispatch = useLightboxDispatch();
|
|
17
17
|
const [swipeState, setSwipeState] = React.useState(SwipeState.NONE);
|
|
18
18
|
const swipeOffset = React.useRef(0);
|
|
@@ -2,4 +2,4 @@ import * as React from "react";
|
|
|
2
2
|
import { ComponentProps, SlideshowRef } from "../../types.js";
|
|
3
3
|
export declare const SlideshowContext: React.Context<SlideshowRef | null>;
|
|
4
4
|
export declare const useSlideshow: () => SlideshowRef;
|
|
5
|
-
export declare function SlideshowContextProvider({ slideshow, carousel: { finite }, children }: ComponentProps): JSX.Element;
|
|
5
|
+
export declare function SlideshowContextProvider({ slideshow, carousel: { finite }, on, children }: ComponentProps): JSX.Element;
|
|
@@ -3,8 +3,9 @@ import { ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE
|
|
|
3
3
|
import { resolveSlideshowProps } from "./props.js";
|
|
4
4
|
export const SlideshowContext = React.createContext(null);
|
|
5
5
|
export const useSlideshow = makeUseContext("useSlideshow", "SlideshowContext", SlideshowContext);
|
|
6
|
-
export function SlideshowContextProvider({ slideshow, carousel: { finite }, children }) {
|
|
6
|
+
export function SlideshowContextProvider({ slideshow, carousel: { finite }, on, children }) {
|
|
7
7
|
const { autoplay, delay, ref } = resolveSlideshowProps(slideshow);
|
|
8
|
+
const wasPlaying = React.useRef(autoplay);
|
|
8
9
|
const [playing, setPlaying] = React.useState(autoplay);
|
|
9
10
|
const scheduler = React.useRef();
|
|
10
11
|
const slideStatus = React.useRef();
|
|
@@ -48,6 +49,17 @@ export function SlideshowContextProvider({ slideshow, carousel: { finite }, chil
|
|
|
48
49
|
setPlaying(false);
|
|
49
50
|
}
|
|
50
51
|
}, [currentIndex, playing, disabled]);
|
|
52
|
+
const onSlideshowStart = useEventCallback(() => { var _a; return (_a = on.slideshowStart) === null || _a === void 0 ? void 0 : _a.call(on); });
|
|
53
|
+
const onSlideshowStop = useEventCallback(() => { var _a; return (_a = on.slideshowStop) === null || _a === void 0 ? void 0 : _a.call(on); });
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (playing) {
|
|
56
|
+
onSlideshowStart();
|
|
57
|
+
}
|
|
58
|
+
else if (wasPlaying.current) {
|
|
59
|
+
onSlideshowStop();
|
|
60
|
+
}
|
|
61
|
+
wasPlaying.current = playing;
|
|
62
|
+
}, [playing, onSlideshowStart, onSlideshowStop]);
|
|
51
63
|
React.useEffect(() => cleanup(cancelScheduler, subscribe(ACTIVE_SLIDE_LOADING, () => {
|
|
52
64
|
slideStatus.current = SLIDE_STATUS_LOADING;
|
|
53
65
|
cancelScheduler();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
import { PLUGIN_SLIDESHOW } from "../../core/index.js";
|
|
3
3
|
import { Slideshow } from "./Slideshow.js";
|
|
4
4
|
declare module "../../types.js" {
|
|
@@ -21,6 +21,12 @@ declare module "../../types.js" {
|
|
|
21
21
|
/** render custom Slideshow button */
|
|
22
22
|
buttonSlideshow?: RenderFunction<SlideshowRef>;
|
|
23
23
|
}
|
|
24
|
+
interface Callbacks {
|
|
25
|
+
/** a callback called on slideshow playback start */
|
|
26
|
+
slideshowStart?: Callback;
|
|
27
|
+
/** a callback called on slideshow playback stop */
|
|
28
|
+
slideshowStop?: Callback;
|
|
29
|
+
}
|
|
24
30
|
interface ToolbarButtonKeys {
|
|
25
31
|
[PLUGIN_SLIDESHOW]: null;
|
|
26
32
|
}
|
|
@@ -30,16 +30,20 @@ export function VideoSlide({ slide, offset }) {
|
|
|
30
30
|
}, [handleVideoRef]);
|
|
31
31
|
const { width, height, poster, sources } = slide;
|
|
32
32
|
const scaleWidthAndHeight = () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
const scalingProps = {};
|
|
34
|
+
scalingProps.style = { maxWidth: "100%", maxHeight: "100%" };
|
|
35
|
+
if (width && height && containerRect) {
|
|
36
|
+
const widthBound = width / height > containerRect.width / containerRect.height;
|
|
37
|
+
const elementWidth = widthBound ? containerRect.width : Math.round((containerRect.height / height) * width);
|
|
38
|
+
const elementHeight = !widthBound
|
|
39
|
+
? containerRect.height
|
|
40
|
+
: Math.round((containerRect.width / width) * height);
|
|
41
|
+
scalingProps.width = elementWidth;
|
|
42
|
+
scalingProps.height = elementHeight;
|
|
43
|
+
scalingProps.style.width = elementWidth;
|
|
44
|
+
scalingProps.style.height = elementHeight;
|
|
45
|
+
}
|
|
46
|
+
return scalingProps;
|
|
43
47
|
};
|
|
44
48
|
const resolveBoolean = (attr) => {
|
|
45
49
|
if (slide[attr] === false)
|