yet-another-react-lightbox 3.9.1 → 3.10.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/index.d.ts +5 -6
- package/dist/index.js +6 -4
- package/dist/plugins/zoom/index.js +1 -0
- package/dist/types.d.ts +7 -5
- package/package.json +1 -1
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, Component, Module, Node, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState,
|
|
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, Callbacks,
|
|
2
|
+
import { LightboxExternalProps, LightboxProps, Labels, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, Component, Module, Node, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, CarouselSettings, 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, 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, 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, on, plugins, slides, index, ...restProps }: LightboxExternalProps): React.JSX.Element | null;
|
|
@@ -183,17 +183,16 @@ declare const ErrorIcon: {
|
|
|
183
183
|
displayName: string;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
type ImageSlideProps = {
|
|
186
|
+
type ImageSlideProps = Partial<Pick<CarouselSettings, "imageFit" | "imageProps">> & {
|
|
187
187
|
slide: SlideImage;
|
|
188
188
|
offset?: number;
|
|
189
189
|
render?: Render;
|
|
190
190
|
rect?: ContainerRect;
|
|
191
|
-
imageFit?: ImageFit;
|
|
192
191
|
onClick?: () => void;
|
|
193
192
|
onLoad?: (image: HTMLImageElement) => void;
|
|
194
193
|
style?: React.CSSProperties;
|
|
195
194
|
};
|
|
196
|
-
declare function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }: ImageSlideProps): React.JSX.Element;
|
|
195
|
+
declare function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, style, }: ImageSlideProps): React.JSX.Element;
|
|
197
196
|
|
|
198
197
|
declare function Carousel({ carousel: { finite, preload, padding, spacing } }: ComponentProps): React.JSX.Element;
|
|
199
198
|
declare const CarouselModule: Module;
|
|
@@ -252,4 +251,4 @@ declare const RootModule: Module;
|
|
|
252
251
|
declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose } }: ComponentProps): React.JSX.Element;
|
|
253
252
|
declare const ToolbarModule: Module;
|
|
254
253
|
|
|
255
|
-
export { Augmentation, Callback, Carousel, CarouselModule, CloseIcon, Component, ComponentProps, ComputeAnimation, ContainerRect, Controller, ControllerContext, ControllerContextType, ControllerModule, ControllerRef, ErrorIcon, Event, EventCallback, EventTypes, EventsContext, EventsContextType, EventsProvider, IconButton, IconButtonProps,
|
|
254
|
+
export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, ComputeAnimation, ContainerRect, Controller, ControllerContext, ControllerContextType, ControllerModule, ControllerRef, ErrorIcon, Event, EventCallback, EventTypes, EventsContext, EventsContextType, EventsProvider, IconButton, IconButtonProps, ImageSlide, ImageSlideProps, KeyboardEventType, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, LightboxPropsContextType, LightboxPropsProvider, LightboxState, LightboxStateAction, LightboxStateContext, LightboxStateContextType, LightboxStateProvider, LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node, Plugin, PointerEventType, Portal, PortalModule, PreviousIcon, Publish, ReactEventType, RegisterSensors, Render, RenderFunction, Root, RootModule, SensorCallback, Slide, SlideImage, Subscribe, SubscribeSensors, SupportedEventType, SwipeState, TimeoutsContext, TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, Topic, Unsubscribe, UseSensors, WheelEventType, addToolbarButton, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useEventCallback, useEvents, useForkRef, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, usePointerSwipe, usePreventSwipeNavigation, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const LightboxDefaultProps = {
|
|
|
28
28
|
padding: "16px",
|
|
29
29
|
spacing: "30%",
|
|
30
30
|
imageFit: IMAGE_FIT_CONTAIN,
|
|
31
|
+
imageProps: {},
|
|
31
32
|
},
|
|
32
33
|
controller: {
|
|
33
34
|
ref: null,
|
|
@@ -566,7 +567,7 @@ function useThrottle(callback, delay) {
|
|
|
566
567
|
|
|
567
568
|
const slidePrefix = makeComposePrefix("slide");
|
|
568
569
|
const slideImagePrefix = makeComposePrefix("slide_image");
|
|
569
|
-
function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onLoad, style }) {
|
|
570
|
+
function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, style, }) {
|
|
570
571
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
571
572
|
const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
|
|
572
573
|
const { publish } = useEvents();
|
|
@@ -618,8 +619,9 @@ function ImageSlide({ slide: image, offset, render, rect, imageFit, onClick, onL
|
|
|
618
619
|
const srcSet = (_g = image.srcSet) === null || _g === void 0 ? void 0 : _g.sort((a, b) => a.width - b.width).map((item) => `${item.src} ${item.width}w`).join(", ");
|
|
619
620
|
const estimateActualWidth = () => rect && !cover && image.width && image.height ? (rect.height / image.height) * image.width : Number.MAX_VALUE;
|
|
620
621
|
const sizes = srcSet && rect && hasWindow() ? `${Math.round(Math.min(estimateActualWidth(), rect.width))}px` : undefined;
|
|
622
|
+
const { style: imagePropsStyle, className: imagePropsClassName, ...restImageProps } = imageProps || {};
|
|
621
623
|
return (React.createElement(React.Fragment, null,
|
|
622
|
-
React.createElement("img", { ref: setImageRef, onLoad: handleOnLoad, onError: onError, onClick: onClick, className: clsx(cssClass(slideImagePrefix()), cover && cssClass(slideImagePrefix("cover")), status !== SLIDE_STATUS_COMPLETE && cssClass(slideImagePrefix("loading"))
|
|
624
|
+
React.createElement("img", { ref: setImageRef, onLoad: handleOnLoad, onError: onError, onClick: onClick, draggable: false, className: clsx(cssClass(slideImagePrefix()), cover && cssClass(slideImagePrefix("cover")), status !== SLIDE_STATUS_COMPLETE && cssClass(slideImagePrefix("loading")), imagePropsClassName), style: { ...defaultStyle, ...style, ...imagePropsStyle }, ...restImageProps, alt: image.alt, sizes: sizes, srcSet: srcSet, src: image.src }),
|
|
623
625
|
status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass(slidePrefix(SLIDE_STATUS_PLACEHOLDER)) },
|
|
624
626
|
status === SLIDE_STATUS_LOADING &&
|
|
625
627
|
((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_LOADING))) }))),
|
|
@@ -1141,12 +1143,12 @@ function CarouselSlide({ slide, offset }) {
|
|
|
1141
1143
|
const containerRef = React.useRef(null);
|
|
1142
1144
|
const { currentIndex } = useLightboxState();
|
|
1143
1145
|
const { slideRect, close } = useController();
|
|
1144
|
-
const { render, carousel: { imageFit }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
|
|
1146
|
+
const { render, carousel: { imageFit, imageProps }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
|
|
1145
1147
|
const renderSlide = () => {
|
|
1146
1148
|
var _a, _b, _c, _d;
|
|
1147
1149
|
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect: slideRect });
|
|
1148
1150
|
if (!rendered && isImageSlide(slide)) {
|
|
1149
|
-
rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, onClick: offset === 0 ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
|
|
1151
|
+
rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect: slideRect, imageFit: imageFit, imageProps: imageProps, onClick: offset === 0 ? () => onClick === null || onClick === void 0 ? void 0 : onClick({ index: currentIndex }) : undefined }));
|
|
1150
1152
|
}
|
|
1151
1153
|
return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
|
|
1152
1154
|
_b.call(render, { slide }),
|
|
@@ -473,6 +473,7 @@ function ZoomWrapper({ render, slide, offset, rect }) {
|
|
|
473
473
|
rect,
|
|
474
474
|
render,
|
|
475
475
|
imageFit: carousel.imageFit,
|
|
476
|
+
imageProps: carousel.imageProps,
|
|
476
477
|
onClick: offset === 0 ? () => { var _a; return (_a = on.click) === null || _a === void 0 ? void 0 : _a.call(on, { index: currentIndex }); } : undefined,
|
|
477
478
|
};
|
|
478
479
|
rendered = isResponsiveImageSlide(slide) ? (React.createElement(ResponsiveImage, { key: slide.src, ...slideProps, slide: slide, rect: offset === 0 ? { width: rect.width * zoom, height: rect.height * zoom } : rect })) : (React.createElement(ImageSlide, { key: slide.src, onLoad: (img) => setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight }), ...slideProps }));
|
package/dist/types.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare const IMAGE_FIT_COVER = "cover";
|
|
|
53
53
|
declare const UNKNOWN_ACTION_TYPE = "Unknown action type";
|
|
54
54
|
|
|
55
55
|
/** Lightbox external props */
|
|
56
|
-
type LightboxExternalProps = DeepPartial<LightboxProps, "
|
|
56
|
+
type LightboxExternalProps = DeepPartial<DeepPartial<DeepPartial<LightboxProps, "animation" | "toolbar">, "carousel", "imageProps">, "controller", "ref">;
|
|
57
57
|
/** Lightbox properties */
|
|
58
58
|
interface LightboxProps {
|
|
59
59
|
/** if `true`, the lightbox is open */
|
|
@@ -184,6 +184,8 @@ interface CarouselSettings {
|
|
|
184
184
|
spacing: LengthOrPercentage;
|
|
185
185
|
/** `object-fit` setting for image slides */
|
|
186
186
|
imageFit: ImageFit;
|
|
187
|
+
/** custom image attributes */
|
|
188
|
+
imageProps: Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt" | "sizes" | "srcSet" | "onLoad" | "onError" | "onClick">;
|
|
187
189
|
}
|
|
188
190
|
type LengthOrPercentage = `${number}px` | `${number}%` | number;
|
|
189
191
|
/** Animation settings */
|
|
@@ -395,11 +397,11 @@ interface PluginProps {
|
|
|
395
397
|
/** Lightbox plugin */
|
|
396
398
|
type Plugin = (props: PluginProps) => void;
|
|
397
399
|
/** Deep partial utility type */
|
|
398
|
-
type DeepPartial<T extends {}, K extends keyof T> = Omit<Partial<T>, K> & {
|
|
399
|
-
[P in K]?: DeepPartialValue<T[P]>;
|
|
400
|
+
type DeepPartial<T extends {}, K extends keyof T = keyof T, E extends string = never> = Omit<Partial<T>, K> & {
|
|
401
|
+
[P in K]?: DeepPartialValue<T[P], E>;
|
|
400
402
|
};
|
|
401
|
-
type DeepPartialValue<T> = T extends any[] ? T : T extends (...props: any[]) => any ? T : T extends {} ? {
|
|
402
|
-
[P in keyof T]?: P extends
|
|
403
|
+
type DeepPartialValue<T, E extends string = never> = T extends any[] ? T : T extends (...props: any[]) => any ? T : T extends {} ? {
|
|
404
|
+
[P in keyof T]?: P extends E ? T[P] : DeepPartialValue<T[P], E>;
|
|
403
405
|
} : T;
|
|
404
406
|
|
|
405
407
|
export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, AnimationSettings, Augmentation, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, Callback, Callbacks, CarouselSettings, ClickCallbackProps, Component, ComponentProps, ContainerRect, ControllerRef, 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, EventTypes, GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, ImageFit, ImageSource, Labels, LengthOrPercentage, LightboxExternalProps, LightboxProps, LightboxState, LightboxStateSwipeAction, LightboxStateUpdateAction, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, Module, NavigationAction, Node, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, Plugin, PluginProps, PortalSettings, Render, RenderFunction, RenderSlideContainerProps, RenderSlideFooterProps, RenderSlideHeaderProps, RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, Slide, SlideImage, SlideStatus, SlideTypeKey, SlideTypes, Slot, SlotStyles, SlotType, ToolbarButtonKey, ToolbarButtonKeys, ToolbarSettings, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, ViewCallbackProps, activeSlideStatus };
|