yet-another-react-lightbox 3.3.0 → 3.4.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/dist/core/consts.d.ts +1 -0
- package/dist/core/consts.js +1 -0
- package/dist/core/contexts/LightboxState.d.ts +7 -2
- package/dist/core/contexts/LightboxState.js +15 -5
- package/dist/core/modules/Carousel.js +2 -2
- package/dist/core/modules/Controller.js +3 -2
- package/dist/core/modules/Navigation.js +1 -1
- package/dist/core/utils.d.ts +3 -1
- package/dist/core/utils.js +3 -1
- package/dist/plugins/counter/Counter.js +1 -1
- package/dist/plugins/download/Download.d.ts +2 -0
- package/dist/plugins/download/Download.js +9 -0
- package/dist/plugins/download/DownloadButton.d.ts +2 -0
- package/dist/plugins/download/DownloadButton.js +17 -0
- package/dist/plugins/download/FileSaver.d.ts +1 -0
- package/dist/plugins/download/FileSaver.js +60 -0
- package/dist/plugins/download/index.d.ts +20 -0
- package/dist/plugins/download/index.js +3 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/slideshow/SlideshowContext.js +1 -1
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +3 -3
- package/dist/plugins/zoom/ZoomWrapper.js +1 -1
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +1 -1
- package/dist/plugins/zoom/hooks/useZoomSensors.js +1 -1
- package/dist/plugins/zoom/hooks/useZoomState.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +8 -1
package/dist/core/consts.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const MODULE_ROOT = "root";
|
|
|
7
7
|
export declare const MODULE_TOOLBAR = "toolbar";
|
|
8
8
|
export declare const PLUGIN_CAPTIONS = "captions";
|
|
9
9
|
export declare const PLUGIN_COUNTER = "counter";
|
|
10
|
+
export declare const PLUGIN_DOWNLOAD = "download";
|
|
10
11
|
export declare const PLUGIN_FULLSCREEN = "fullscreen";
|
|
11
12
|
export declare const PLUGIN_INLINE = "inline";
|
|
12
13
|
export declare const PLUGIN_SLIDESHOW = "slideshow";
|
package/dist/core/consts.js
CHANGED
|
@@ -7,6 +7,7 @@ export const MODULE_ROOT = "root";
|
|
|
7
7
|
export const MODULE_TOOLBAR = "toolbar";
|
|
8
8
|
export const PLUGIN_CAPTIONS = "captions";
|
|
9
9
|
export const PLUGIN_COUNTER = "counter";
|
|
10
|
+
export const PLUGIN_DOWNLOAD = "download";
|
|
10
11
|
export const PLUGIN_FULLSCREEN = "fullscreen";
|
|
11
12
|
export const PLUGIN_INLINE = "inline";
|
|
12
13
|
export const PLUGIN_SLIDESHOW = "slideshow";
|
|
@@ -12,11 +12,16 @@ export type LightboxStateUpdateAction = {
|
|
|
12
12
|
index: number;
|
|
13
13
|
};
|
|
14
14
|
export type LightboxStateAction = LightboxStateSwipeAction | LightboxStateUpdateAction;
|
|
15
|
-
export type LightboxStateContextType = {
|
|
15
|
+
export type LightboxStateContextType = LightboxState & {
|
|
16
|
+
/** @deprecated - use `useLightboxState` props directly */
|
|
16
17
|
state: LightboxState;
|
|
18
|
+
/** @deprecated - use `useLightboxDispatch` instead */
|
|
17
19
|
dispatch: React.Dispatch<LightboxStateAction>;
|
|
18
20
|
};
|
|
19
21
|
export declare const LightboxStateContext: React.Context<LightboxStateContextType | null>;
|
|
20
|
-
export declare const useLightboxState: () => LightboxStateContextType
|
|
22
|
+
export declare const useLightboxState: () => NonNullable<LightboxStateContextType>;
|
|
23
|
+
export type LightboxDispatchContextType = React.Dispatch<LightboxStateAction>;
|
|
24
|
+
export declare const LightboxDispatchContext: React.Context<LightboxDispatchContextType | null>;
|
|
25
|
+
export declare const useLightboxDispatch: () => LightboxDispatchContextType;
|
|
21
26
|
export type LightboxStateProviderProps = React.PropsWithChildren<Pick<LightboxProps, "slides" | "index">>;
|
|
22
27
|
export declare function LightboxStateProvider({ slides, index, children }: LightboxStateProviderProps): JSX.Element;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { getSlideIndex, makeUseContext } from "../utils.js";
|
|
2
|
+
import { getSlideIfPresent, getSlideIndex, makeUseContext } from "../utils.js";
|
|
3
3
|
import { UNKNOWN_ACTION_TYPE } from "../consts.js";
|
|
4
4
|
export const LightboxStateContext = React.createContext(null);
|
|
5
5
|
export const useLightboxState = makeUseContext("useLightboxState", "LightboxStateContext", LightboxStateContext);
|
|
6
|
+
export const LightboxDispatchContext = React.createContext(null);
|
|
7
|
+
export const useLightboxDispatch = makeUseContext("useLightboxDispatch", "LightboxDispatchContext", LightboxDispatchContext);
|
|
6
8
|
function reducer(state, action) {
|
|
7
9
|
switch (action.type) {
|
|
8
10
|
case "swipe": {
|
|
@@ -10,6 +12,7 @@ function reducer(state, action) {
|
|
|
10
12
|
const increment = (action === null || action === void 0 ? void 0 : action.increment) || 0;
|
|
11
13
|
const globalIndex = state.globalIndex + increment;
|
|
12
14
|
const currentIndex = getSlideIndex(globalIndex, slides.length);
|
|
15
|
+
const currentSlide = getSlideIfPresent(slides, currentIndex);
|
|
13
16
|
const animation = increment || action.duration
|
|
14
17
|
? {
|
|
15
18
|
increment,
|
|
@@ -17,23 +20,30 @@ function reducer(state, action) {
|
|
|
17
20
|
easing: action.easing,
|
|
18
21
|
}
|
|
19
22
|
: undefined;
|
|
20
|
-
return { slides, currentIndex, globalIndex, animation };
|
|
23
|
+
return { slides, currentIndex, globalIndex, currentSlide, animation };
|
|
21
24
|
}
|
|
22
25
|
case "update":
|
|
23
26
|
return {
|
|
24
27
|
slides: action.slides,
|
|
25
28
|
currentIndex: action.index,
|
|
26
29
|
globalIndex: action.index,
|
|
30
|
+
currentSlide: getSlideIfPresent(action.slides, action.index),
|
|
27
31
|
};
|
|
28
32
|
default:
|
|
29
33
|
throw new Error(UNKNOWN_ACTION_TYPE);
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
export function LightboxStateProvider({ slides, index, children }) {
|
|
33
|
-
const [state, dispatch] = React.useReducer(reducer, {
|
|
37
|
+
const [state, dispatch] = React.useReducer(reducer, {
|
|
38
|
+
slides,
|
|
39
|
+
currentIndex: index,
|
|
40
|
+
globalIndex: index,
|
|
41
|
+
currentSlide: getSlideIfPresent(slides, index),
|
|
42
|
+
});
|
|
34
43
|
React.useEffect(() => {
|
|
35
44
|
dispatch({ type: "update", slides, index });
|
|
36
45
|
}, [slides, index]);
|
|
37
|
-
const context = React.useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
|
38
|
-
return React.createElement(
|
|
46
|
+
const context = React.useMemo(() => ({ ...state, state, dispatch }), [state, dispatch]);
|
|
47
|
+
return (React.createElement(LightboxDispatchContext.Provider, { value: dispatch },
|
|
48
|
+
React.createElement(LightboxStateContext.Provider, { value: context }, children)));
|
|
39
49
|
}
|
|
@@ -13,7 +13,7 @@ function cssSlidePrefix(value) {
|
|
|
13
13
|
}
|
|
14
14
|
function CarouselSlide({ slide, offset }) {
|
|
15
15
|
const containerRef = React.useRef(null);
|
|
16
|
-
const { currentIndex } = useLightboxState()
|
|
16
|
+
const { currentIndex } = useLightboxState();
|
|
17
17
|
const { slideRect, close } = useController();
|
|
18
18
|
const { render, carousel: { imageFit }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
|
|
19
19
|
const renderSlide = () => {
|
|
@@ -45,7 +45,7 @@ function Placeholder() {
|
|
|
45
45
|
return React.createElement("div", { className: cssClass("slide") });
|
|
46
46
|
}
|
|
47
47
|
export function Carousel({ carousel: { finite, preload, padding, spacing } }) {
|
|
48
|
-
const { slides, currentIndex, globalIndex } = useLightboxState()
|
|
48
|
+
const { slides, currentIndex, globalIndex } = useLightboxState();
|
|
49
49
|
const { setCarouselRef } = useController();
|
|
50
50
|
const spacingValue = parseLengthPercentage(spacing);
|
|
51
51
|
const paddingValue = parseLengthPercentage(padding);
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { createModule } from "../config.js";
|
|
3
3
|
import { cleanup, clsx, computeSlideRect, cssClass, cssVar, makeComposePrefix, makeUseContext, parseLengthPercentage, } from "../utils.js";
|
|
4
4
|
import { useAnimation, useContainerRect, useDelay, useEventCallback, useForkRef, useRTL, useSensors, } from "../hooks/index.js";
|
|
5
|
-
import { useEvents, useLightboxState } from "../contexts/index.js";
|
|
5
|
+
import { useEvents, useLightboxDispatch, useLightboxState } from "../contexts/index.js";
|
|
6
6
|
import { SwipeState, usePointerSwipe, usePreventSwipeNavigation, useWheelSwipe } from "./controller/index.js";
|
|
7
7
|
import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, EVENT_ON_KEY_UP, MODULE_CONTROLLER, VK_ESCAPE, } from "../consts.js";
|
|
8
8
|
const cssContainerPrefix = makeComposePrefix("container");
|
|
@@ -12,7 +12,8 @@ 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 { state
|
|
15
|
+
const { state } = useLightboxState();
|
|
16
|
+
const dispatch = useLightboxDispatch();
|
|
16
17
|
const [swipeState, setSwipeState] = React.useState(SwipeState.NONE);
|
|
17
18
|
const swipeOffset = React.useRef(0);
|
|
18
19
|
const { registerSensors, subscribeSensors } = useSensors();
|
|
@@ -11,7 +11,7 @@ export function NavigationButton({ label, icon, renderIcon, action, onClick, dis
|
|
|
11
11
|
}
|
|
12
12
|
export function Navigation({ carousel: { finite }, animation, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) {
|
|
13
13
|
var _a;
|
|
14
|
-
const { slides, currentIndex } = useLightboxState()
|
|
14
|
+
const { slides, currentIndex } = useLightboxState();
|
|
15
15
|
const { prev, next, subscribeSensors } = useController();
|
|
16
16
|
const isRTL = useRTL();
|
|
17
17
|
const prevDisabled = slides.length === 0 || (finite && currentIndex === 0);
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -25,5 +25,7 @@ export declare function computeSlideRect(containerRect: ContainerRect, padding:
|
|
|
25
25
|
};
|
|
26
26
|
export declare const devicePixelRatio: () => number;
|
|
27
27
|
export declare const getSlideIndex: (index: number, slidesCount: number) => number;
|
|
28
|
-
export declare const
|
|
28
|
+
export declare const hasSlides: (slides: Slide[]) => slides is [Slide, ...Slide[]];
|
|
29
|
+
export declare const getSlide: (slides: [Slide, ...Slide[]], index: number) => Slide;
|
|
30
|
+
export declare const getSlideIfPresent: (slides: Slide[], index: number) => Slide | undefined;
|
|
29
31
|
export declare function addToolbarButton(toolbar: ToolbarSettings, key: string, button: React.ReactNode): ToolbarSettings;
|
package/dist/core/utils.js
CHANGED
|
@@ -45,8 +45,10 @@ export function computeSlideRect(containerRect, padding) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export const devicePixelRatio = () => (hasWindow() ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
|
|
48
|
-
export const getSlideIndex = (index, slidesCount) => ((index % slidesCount) + slidesCount) % slidesCount;
|
|
48
|
+
export const getSlideIndex = (index, slidesCount) => slidesCount > 0 ? ((index % slidesCount) + slidesCount) % slidesCount : 0;
|
|
49
|
+
export const hasSlides = (slides) => slides.length > 0;
|
|
49
50
|
export const getSlide = (slides, index) => slides[getSlideIndex(index, slides.length)];
|
|
51
|
+
export const getSlideIfPresent = (slides, index) => hasSlides(slides) ? getSlide(slides, index) : undefined;
|
|
50
52
|
export function addToolbarButton(toolbar, key, button) {
|
|
51
53
|
if (!button)
|
|
52
54
|
return toolbar;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { clsx, createModule, cssClass, MODULE_CONTROLLER, PLUGIN_COUNTER, useLightboxState } from "../../core/index.js";
|
|
3
3
|
export function CounterComponent({ counter: { className, ...rest } = {} }) {
|
|
4
|
-
const { slides, currentIndex } = useLightboxState()
|
|
4
|
+
const { slides, currentIndex } = useLightboxState();
|
|
5
5
|
if (slides.length === 0)
|
|
6
6
|
return null;
|
|
7
7
|
return (React.createElement("div", { className: clsx(cssClass("counter"), className), ...rest },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { addToolbarButton, PLUGIN_DOWNLOAD } from "../../core/index.js";
|
|
3
|
+
import { DownloadButton } from "./DownloadButton.js";
|
|
4
|
+
export function Download({ augment }) {
|
|
5
|
+
augment(({ toolbar, ...restProps }) => ({
|
|
6
|
+
toolbar: addToolbarButton(toolbar, PLUGIN_DOWNLOAD, React.createElement(DownloadButton, null)),
|
|
7
|
+
...restProps,
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { createIcon, IconButton, isImageSlide, useLightboxProps, useLightboxState } from "../../core/index.js";
|
|
3
|
+
import { saveAs } from "./FileSaver.js";
|
|
4
|
+
const DownloadIcon = createIcon("DownloadIcon", React.createElement("path", { d: "M18 15v3H6v-3H4v3c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-3h-2zm-1-4-1.41-1.41L13 12.17V4h-2v8.17L8.41 9.59 7 11l5 5 5-5z" }));
|
|
5
|
+
export function DownloadButton() {
|
|
6
|
+
const { render } = useLightboxProps();
|
|
7
|
+
const { currentSlide } = useLightboxState();
|
|
8
|
+
if (render.buttonDownload) {
|
|
9
|
+
return React.createElement(React.Fragment, null, render.buttonDownload());
|
|
10
|
+
}
|
|
11
|
+
const downloadUrl = (currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.downloadUrl) || (currentSlide && isImageSlide(currentSlide) ? currentSlide.src : undefined);
|
|
12
|
+
return (React.createElement(IconButton, { label: "Download", icon: DownloadIcon, renderIcon: render.iconDownload, disabled: !downloadUrl, onClick: () => {
|
|
13
|
+
if (downloadUrl) {
|
|
14
|
+
saveAs(downloadUrl, currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.downloadFilename);
|
|
15
|
+
}
|
|
16
|
+
} }));
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function saveAs(source: string | Blob, name?: string): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function download(url, name) {
|
|
2
|
+
const xhr = new XMLHttpRequest();
|
|
3
|
+
xhr.open("GET", url);
|
|
4
|
+
xhr.responseType = "blob";
|
|
5
|
+
xhr.onload = () => {
|
|
6
|
+
saveAs(xhr.response, name);
|
|
7
|
+
};
|
|
8
|
+
xhr.onerror = () => {
|
|
9
|
+
console.error("Failed to download file");
|
|
10
|
+
};
|
|
11
|
+
xhr.send();
|
|
12
|
+
}
|
|
13
|
+
function corsEnabled(url) {
|
|
14
|
+
const xhr = new XMLHttpRequest();
|
|
15
|
+
xhr.open("HEAD", url, false);
|
|
16
|
+
try {
|
|
17
|
+
xhr.send();
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
}
|
|
21
|
+
return xhr.status >= 200 && xhr.status <= 299;
|
|
22
|
+
}
|
|
23
|
+
function click(link) {
|
|
24
|
+
try {
|
|
25
|
+
link.dispatchEvent(new MouseEvent("click"));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
const event = document.createEvent("MouseEvents");
|
|
29
|
+
event.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
|
|
30
|
+
link.dispatchEvent(event);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function saveAs(source, name) {
|
|
34
|
+
const link = document.createElement("a");
|
|
35
|
+
link.rel = "noopener";
|
|
36
|
+
link.download = name || "";
|
|
37
|
+
if (!link.download) {
|
|
38
|
+
link.target = "_blank";
|
|
39
|
+
}
|
|
40
|
+
if (typeof source === "string") {
|
|
41
|
+
link.href = source;
|
|
42
|
+
if (link.origin !== window.location.origin) {
|
|
43
|
+
if (corsEnabled(link.href)) {
|
|
44
|
+
download(source, name);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
link.target = "_blank";
|
|
48
|
+
click(link);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
click(link);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
link.href = URL.createObjectURL(source);
|
|
57
|
+
setTimeout(() => URL.revokeObjectURL(link.href), 30000);
|
|
58
|
+
setTimeout(() => click(link), 0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PLUGIN_DOWNLOAD } from "../../core/index.js";
|
|
2
|
+
import { Download } from "./Download.js";
|
|
3
|
+
declare module "../../types.js" {
|
|
4
|
+
interface GenericSlide {
|
|
5
|
+
/** download url */
|
|
6
|
+
downloadUrl?: string;
|
|
7
|
+
/** download filename override */
|
|
8
|
+
downloadFilename?: string;
|
|
9
|
+
}
|
|
10
|
+
interface Render {
|
|
11
|
+
/** render custom Download button */
|
|
12
|
+
buttonDownload?: RenderFunction;
|
|
13
|
+
/** render custom Download icon */
|
|
14
|
+
iconDownload?: RenderFunction;
|
|
15
|
+
}
|
|
16
|
+
interface ToolbarButtonKeys {
|
|
17
|
+
[PLUGIN_DOWNLOAD]: null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export default Download;
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Captions } from "./captions/index.js";
|
|
2
2
|
export { default as Counter } from "./counter/index.js";
|
|
3
|
+
export { default as Download } from "./download/index.js";
|
|
3
4
|
export { default as Fullscreen } from "./fullscreen/index.js";
|
|
4
5
|
export { default as Inline } from "./inline/index.js";
|
|
5
6
|
export { default as Slideshow } from "./slideshow/index.js";
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Captions } from "./captions/index.js";
|
|
2
2
|
export { default as Counter } from "./counter/index.js";
|
|
3
|
+
export { default as Download } from "./download/index.js";
|
|
3
4
|
export { default as Fullscreen } from "./fullscreen/index.js";
|
|
4
5
|
export { default as Inline } from "./inline/index.js";
|
|
5
6
|
export { default as Slideshow } from "./slideshow/index.js";
|
|
@@ -8,7 +8,7 @@ export function SlideshowContextProvider({ slideshow, carousel: { finite }, chil
|
|
|
8
8
|
const [playing, setPlaying] = React.useState(autoplay);
|
|
9
9
|
const scheduler = React.useRef();
|
|
10
10
|
const slideStatus = React.useRef();
|
|
11
|
-
const { slides, currentIndex } = useLightboxState()
|
|
11
|
+
const { slides, currentIndex } = useLightboxState();
|
|
12
12
|
const { setTimeout, clearTimeout } = useTimeouts();
|
|
13
13
|
const { subscribe } = useEvents();
|
|
14
14
|
const { next } = useController();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, clsx, cssClass, cssVar, getSlide, useAnimation, useEventCallback, useEvents, useLightboxProps, useLightboxState, useRTL, } from "../../core/index.js";
|
|
2
|
+
import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, clsx, cssClass, cssVar, getSlide, hasSlides, useAnimation, useEventCallback, useEvents, useLightboxProps, useLightboxState, useRTL, } from "../../core/index.js";
|
|
3
3
|
import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
|
|
4
4
|
import { Thumbnail } from "./Thumbnail.js";
|
|
5
5
|
import { defaultThumbnailsProps, useThumbnailsProps } from "./props.js";
|
|
@@ -14,7 +14,7 @@ export function ThumbnailsTrack({ containerRef }) {
|
|
|
14
14
|
const track = React.useRef(null);
|
|
15
15
|
const { visible } = useThumbnails();
|
|
16
16
|
const { carousel, styles } = useLightboxProps();
|
|
17
|
-
const { slides, globalIndex, animation } = useLightboxState()
|
|
17
|
+
const { slides, globalIndex, animation } = useLightboxState();
|
|
18
18
|
const { publish, subscribe } = useEvents();
|
|
19
19
|
const isRTL = useRTL();
|
|
20
20
|
const thumbnails = useThumbnailsProps();
|
|
@@ -57,7 +57,7 @@ export function ThumbnailsTrack({ containerRef }) {
|
|
|
57
57
|
const { finite } = carousel;
|
|
58
58
|
const preload = Math.max(Math.min(carousel.preload, slides.length - 1), 0);
|
|
59
59
|
const items = [];
|
|
60
|
-
if (slides
|
|
60
|
+
if (hasSlides(slides)) {
|
|
61
61
|
if (offset < 0) {
|
|
62
62
|
for (let i = index - preload + offset; i < index - preload; i += 1) {
|
|
63
63
|
items.push({ slide: null, index: i, placeholder: true });
|
|
@@ -8,7 +8,7 @@ export function ZoomWrapper({ render, slide, offset, rect }) {
|
|
|
8
8
|
const zoomWrapperRef = React.useRef(null);
|
|
9
9
|
const { zoom, maxZoom, offsetX, offsetY, setZoomWrapper } = useZoom();
|
|
10
10
|
const { carousel, on } = useLightboxProps();
|
|
11
|
-
const { currentIndex } = useLightboxState()
|
|
11
|
+
const { currentIndex } = useLightboxState();
|
|
12
12
|
useLayoutEffect(() => {
|
|
13
13
|
if (offset === 0) {
|
|
14
14
|
setZoomWrapper({ zoomWrapperRef, imageDimensions });
|
|
@@ -4,7 +4,7 @@ export function useZoomImageRect(slideRect, imageDimensions) {
|
|
|
4
4
|
var _a, _b;
|
|
5
5
|
let imageRect = { width: 0, height: 0 };
|
|
6
6
|
let maxImageRect = { width: 0, height: 0 };
|
|
7
|
-
const { slides, currentIndex } = useLightboxState()
|
|
7
|
+
const { slides, currentIndex } = useLightboxState();
|
|
8
8
|
const { imageFit } = useLightboxProps().carousel;
|
|
9
9
|
const { maxZoomPixelRatio } = useZoomProps();
|
|
10
10
|
if (slideRect && currentIndex < slides.length) {
|
|
@@ -8,7 +8,7 @@ export function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffset
|
|
|
8
8
|
const activePointers = React.useRef([]);
|
|
9
9
|
const lastPointerDown = React.useRef(0);
|
|
10
10
|
const pinchZoomDistance = React.useRef();
|
|
11
|
-
const { globalIndex } = useLightboxState()
|
|
11
|
+
const { globalIndex } = useLightboxState();
|
|
12
12
|
const { containerRef, subscribeSensors } = useController();
|
|
13
13
|
const { keyboardMoveDistance, zoomInMultiplier, wheelZoomDistanceFactor, scrollToZoom, doubleTapDelay, doubleClickDelay, doubleClickMaxStops, pinchZoomDistanceFactor, } = useZoomProps();
|
|
14
14
|
const translateCoordinates = React.useCallback((event) => {
|
|
@@ -15,7 +15,7 @@ export function useZoomState(imageRect, maxZoom, zoomWrapperRef) {
|
|
|
15
15
|
const [offsetX, setOffsetX] = React.useState(0);
|
|
16
16
|
const [offsetY, setOffsetY] = React.useState(0);
|
|
17
17
|
const animate = useZoomAnimation(zoom, offsetX, offsetY, zoomWrapperRef);
|
|
18
|
-
const { slides, currentIndex, globalIndex } = useLightboxState()
|
|
18
|
+
const { slides, currentIndex, globalIndex } = useLightboxState();
|
|
19
19
|
const { containerRect, slideRect } = useController();
|
|
20
20
|
const { zoomInMultiplier } = useZoomProps();
|
|
21
21
|
const currentSource = getCurrentSource(slides, currentIndex);
|
package/dist/types.d.ts
CHANGED
|
@@ -190,6 +190,8 @@ export interface LightboxState {
|
|
|
190
190
|
currentIndex: number;
|
|
191
191
|
/** current slide index in the (-∞, +∞) range */
|
|
192
192
|
globalIndex: number;
|
|
193
|
+
/** current slide */
|
|
194
|
+
currentSlide: Slide | undefined;
|
|
193
195
|
/** current animation */
|
|
194
196
|
animation?: {
|
|
195
197
|
increment?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yet-another-react-lightbox",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Modern React lightbox component",
|
|
5
5
|
"author": "Igor Danchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"types": "./dist/plugins/counter/index.d.ts",
|
|
31
31
|
"default": "./dist/plugins/counter/index.js"
|
|
32
32
|
},
|
|
33
|
+
"./plugins/download": {
|
|
34
|
+
"types": "./dist/plugins/download/index.d.ts",
|
|
35
|
+
"default": "./dist/plugins/download/index.js"
|
|
36
|
+
},
|
|
33
37
|
"./plugins/fullscreen": {
|
|
34
38
|
"types": "./dist/plugins/fullscreen/index.d.ts",
|
|
35
39
|
"default": "./dist/plugins/fullscreen/index.js"
|
|
@@ -74,6 +78,9 @@
|
|
|
74
78
|
"plugins/counter": [
|
|
75
79
|
"dist/plugins/counter/index.d.ts"
|
|
76
80
|
],
|
|
81
|
+
"plugins/download": [
|
|
82
|
+
"dist/plugins/download/index.d.ts"
|
|
83
|
+
],
|
|
77
84
|
"plugins/fullscreen": [
|
|
78
85
|
"dist/plugins/fullscreen/index.d.ts"
|
|
79
86
|
],
|