yet-another-react-lightbox 3.21.8 → 3.22.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
@@ -24,7 +24,7 @@ extendable.
24
24
  - **TypeScript:** type definitions come built-in in the package
25
25
  - **RTL:** compatible with RTL layout
26
26
 
27
- ![Yet Another React Lightbox | Example](https://yet-another-react-lightbox.com/images/example.jpg)
27
+ ![Yet Another React Lightbox | Example](https://images.yet-another-react-lightbox.com/example.jpg)
28
28
 
29
29
  ## Documentation
30
30
 
package/dist/index.d.ts CHANGED
@@ -83,7 +83,7 @@ declare function useEventCallback<Args extends unknown[], Return>(fn: (...args:
83
83
  declare function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
84
84
  declare function useForkRef<InstanceA, InstanceB>(refA: React.Ref<InstanceA> | null | undefined, refB: React.Ref<InstanceB> | null | undefined): React.Ref<InstanceA & InstanceB> | null;
85
85
 
86
- declare const useLayoutEffect: typeof React.useEffect;
86
+ declare const useLayoutEffect: typeof React.useLayoutEffect;
87
87
 
88
88
  declare function useLoseFocus(focus: () => void, disabled?: boolean): {
89
89
  onFocus: () => void;
@@ -224,7 +224,7 @@ declare enum SwipeState {
224
224
  ANIMATION = 3
225
225
  }
226
226
 
227
- 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;
227
+ declare function usePointerSwipe<T extends Element = Element>({ disableSwipeNavigation }: ControllerSettings, 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;
228
228
 
229
229
  /**
230
230
  * Prevent default effects of the wheel events:
@@ -283,4 +283,5 @@ declare const RootModule: Module;
283
283
  declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose }, styles }: ComponentProps): React.JSX.Element;
284
284
  declare const ToolbarModule: Module;
285
285
 
286
- export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, type DocumentContextProviderProps, type DocumentContextType, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Label, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxRoot, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as 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, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeInertWhen, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
286
+ export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, ContainerRect, Controller, ControllerContext, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, ErrorIcon, EventTypes, EventsContext, EventsProvider, IconButton, ImageSlide, Label, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, LightboxExternalProps, LightboxProps, LightboxPropsContext, LightboxPropsProvider, LightboxRoot, LightboxState, LightboxStateContext, LightboxStateProvider, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as Node, Plugin, Portal, PortalModule, PreviousIcon, Render, RenderFunction, Root, RootModule, Slide, SlideImage, SwipeState, TimeoutsContext, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeInertWhen, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
287
+ export type { ComputeAnimation, ControllerContextType, DocumentContextProviderProps, DocumentContextType, Event, EventCallback, EventsContextType, IconButtonProps, ImageSlideProps, KeyboardEventType, LightboxDispatchContextType, LightboxPropsContextType, LightboxStateAction, LightboxStateContextType, LightboxStateProviderProps, NavigationButtonProps, PointerEventType, Publish, ReactEventType, RegisterSensors, SensorCallback, Subscribe, SubscribeSensors, SupportedEventType, TimeoutsContextType, Topic, Unsubscribe, UseSensors, WheelEventType };
package/dist/index.js CHANGED
@@ -156,6 +156,7 @@ const LightboxDefaultProps = {
156
156
  closeOnBackdropClick: false,
157
157
  preventDefaultWheelX: true,
158
158
  preventDefaultWheelY: false,
159
+ disableSwipeNavigation: false,
159
160
  },
160
161
  portal: {},
161
162
  noScroll: {
@@ -719,7 +720,7 @@ var Gesture;
719
720
  Gesture[Gesture["PULL"] = 2] = "PULL";
720
721
  })(Gesture || (Gesture = {}));
721
722
  const SWIPE_THRESHOLD = 30;
722
- function usePointerSwipe(subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel, pullUpEnabled, pullDownEnabled, onPullStart, onPullProgress, onPullFinish, onPullCancel) {
723
+ function usePointerSwipe({ disableSwipeNavigation }, subscribeSensors, isSwipeValid, containerWidth, swipeAnimationDuration, onSwipeStart, onSwipeProgress, onSwipeFinish, onSwipeCancel, pullUpEnabled, pullDownEnabled, onPullStart, onPullProgress, onPullFinish, onPullCancel) {
723
724
  const offset = React.useRef(0);
724
725
  const pointers = React.useRef([]);
725
726
  const activePointer = React.useRef(undefined);
@@ -791,8 +792,10 @@ function usePointerSwipe(subscribeSensors, isSwipeValid, containerWidth, swipeAn
791
792
  gesture.current = newGesture;
792
793
  };
793
794
  if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > SWIPE_THRESHOLD && isSwipeValid(deltaX)) {
794
- startGesture(Gesture.SWIPE);
795
- onSwipeStart();
795
+ if (!disableSwipeNavigation) {
796
+ startGesture(Gesture.SWIPE);
797
+ onSwipeStart();
798
+ }
796
799
  }
797
800
  else if (Math.abs(deltaY) > Math.abs(deltaX) && exceedsPullThreshold(deltaY, SWIPE_THRESHOLD)) {
798
801
  startGesture(Gesture.PULL);
@@ -1145,7 +1148,7 @@ function Controller({ children, ...props }) {
1145
1148
  (offset) => pull(offset),
1146
1149
  (offset) => pull(offset, true),
1147
1150
  ];
1148
- usePointerSwipe(...swipeParams, closeOnPullUp, closeOnPullDown, ...pullParams);
1151
+ usePointerSwipe(controller, ...swipeParams, closeOnPullUp, closeOnPullDown, ...pullParams);
1149
1152
  useWheelSwipe(swipeState, ...swipeParams);
1150
1153
  const focusOnMount = useEventCallback(() => {
1151
1154
  if (controller.focus &&
@@ -14,9 +14,9 @@ declare module "yet-another-react-lightbox" {
14
14
  maxZoomPixelRatio?: number;
15
15
  /** zoom-in multiplier */
16
16
  zoomInMultiplier?: number;
17
- /** double-tap maximum time delay */
17
+ /** @deprecated - double-tap maximum time delay */
18
18
  doubleTapDelay?: number;
19
- /** double-click maximum time delay */
19
+ /** @deprecated - double-click maximum time delay */
20
20
  doubleClickDelay?: number;
21
21
  /** maximum number of zoom-in stops via double-click or double-tap */
22
22
  doubleClickMaxStops?: number;
@@ -136,6 +136,8 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
136
136
  return [];
137
137
  }, [containerRef, getOwnerWindow]);
138
138
  const onKeyDown = useEventCallback((event) => {
139
+ const { key, metaKey, ctrlKey } = event;
140
+ const meta = metaKey || ctrlKey;
139
141
  const preventDefault = () => {
140
142
  event.preventDefault();
141
143
  event.stopPropagation();
@@ -145,16 +147,16 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
145
147
  preventDefault();
146
148
  changeOffsets(deltaX, deltaY);
147
149
  };
148
- if (event.key === "ArrowDown") {
150
+ if (key === "ArrowDown") {
149
151
  move(0, keyboardMoveDistance);
150
152
  }
151
- else if (event.key === "ArrowUp") {
153
+ else if (key === "ArrowUp") {
152
154
  move(0, -keyboardMoveDistance);
153
155
  }
154
- else if (event.key === "ArrowLeft") {
156
+ else if (key === "ArrowLeft") {
155
157
  move(-keyboardMoveDistance, 0);
156
158
  }
157
- else if (event.key === "ArrowRight") {
159
+ else if (key === "ArrowRight") {
158
160
  move(keyboardMoveDistance, 0);
159
161
  }
160
162
  }
@@ -162,14 +164,13 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
162
164
  preventDefault();
163
165
  changeZoom(zoomValue);
164
166
  };
165
- const hasMeta = () => event.getModifierState("Meta");
166
- if (event.key === "+" || (event.key === "=" && hasMeta())) {
167
+ if (key === "+" || (meta && key === "=")) {
167
168
  handleChangeZoom(zoom * zoomInMultiplier);
168
169
  }
169
- else if (event.key === "-" || (event.key === "_" && hasMeta())) {
170
+ else if (key === "-" || (meta && key === "_")) {
170
171
  handleChangeZoom(zoom / zoomInMultiplier);
171
172
  }
172
- else if (event.key === "0" && hasMeta()) {
173
+ else if (meta && key === "0") {
173
174
  handleChangeZoom(1);
174
175
  }
175
176
  });
package/dist/types.d.ts CHANGED
@@ -240,6 +240,8 @@ interface ControllerSettings {
240
240
  preventDefaultWheelX: boolean;
241
241
  /** if `true`, prevent default for vertical wheel scroll events (for internal use only) */
242
242
  preventDefaultWheelY: boolean;
243
+ /** if `true`, disable slide change on pointer swipe / drag */
244
+ disableSwipeNavigation: boolean;
243
245
  }
244
246
  /** Lightbox controller ref */
245
247
  interface ControllerRef {
@@ -432,4 +434,5 @@ type DeepPartialValue<T, E extends string = never> = T extends any[] ? T : T ext
432
434
  [P in keyof T]?: P extends E ? T[P] : DeepPartialValue<T[P], E>;
433
435
  } : T;
434
436
 
435
- export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, type AnimationSettings, type Augmentation, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, CLASS_SLIDE_WRAPPER_INTERACTIVE, type Callback, type Callbacks, type CarouselSettings, type ClickCallbackProps, type Component, type ComponentProps, type ContainerRect, type ControllerRef, type ControllerSettings, type DeepPartial, type 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, type EventTypes, type GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, type ImageFit, type ImageSource, type Label, type Labels, type LengthOrPercentage, type LightboxExternalProps, type LightboxProps, type LightboxState, type LightboxStateSwipeAction, type LightboxStateUpdateAction, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, type Module, type NavigationAction, type NoScrollSettings, type Node, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, type Plugin, type PluginProps, type PortalSettings, type Render, type RenderFunction, type RenderSlideContainerProps, type RenderSlideFooterProps, type RenderSlideHeaderProps, type RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, type Slide, type SlideImage, type SlideStatus, type SlideTypeKey, type SlideTypes, type Slot, type SlotStyles, type SlotType, type ToolbarButtonKey, type ToolbarButtonKeys, type ToolbarSettings, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, type ViewCallbackProps, activeSlideStatus };
437
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, CLASS_SLIDE_WRAPPER_INTERACTIVE, 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, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, activeSlideStatus };
438
+ export type { AnimationSettings, Augmentation, Callback, Callbacks, CarouselSettings, ClickCallbackProps, Component, ComponentProps, ContainerRect, ControllerRef, ControllerSettings, DeepPartial, DeepPartialValue, EventTypes, GenericSlide, ImageFit, ImageSource, Label, Labels, LengthOrPercentage, LightboxExternalProps, LightboxProps, LightboxState, LightboxStateSwipeAction, LightboxStateUpdateAction, Module, NavigationAction, NoScrollSettings, Node, Plugin, PluginProps, PortalSettings, Render, RenderFunction, RenderSlideContainerProps, RenderSlideFooterProps, RenderSlideHeaderProps, RenderSlideProps, Slide, SlideImage, SlideStatus, SlideTypeKey, SlideTypes, Slot, SlotStyles, SlotType, ToolbarButtonKey, ToolbarButtonKeys, ToolbarSettings, ViewCallbackProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.21.8",
3
+ "version": "3.22.0",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",