yet-another-react-lightbox 3.13.1 → 3.14.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 CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { LightboxExternalProps, LightboxProps, Labels, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, CarouselSettings, Component, Module, Node, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, 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';
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, NoScrollSettings, 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
- declare function Lightbox({ carousel, animation, render, toolbar, controller, on, plugins, slides, index, ...restProps }: LightboxExternalProps): React.JSX.Element | null;
6
+ declare function Lightbox({ carousel, animation, render, toolbar, controller, noScroll, on, plugins, slides, index, ...restProps }: LightboxExternalProps): React.JSX.Element | null;
7
7
 
8
8
  declare const LightboxDefaultProps: LightboxProps;
9
9
 
@@ -248,7 +248,7 @@ declare function useNavigationState(): {
248
248
  nextDisabled: boolean;
249
249
  };
250
250
 
251
- declare function NoScroll({ children }: ComponentProps): React.JSX.Element;
251
+ declare function NoScroll({ noScroll: { disabled }, children }: ComponentProps): React.JSX.Element;
252
252
  declare const NoScrollModule: Module;
253
253
 
254
254
  declare function Portal({ children, animation, styles, className, on, portal, close }: ComponentProps): React.ReactPortal | null;
package/dist/index.js CHANGED
@@ -39,6 +39,9 @@ const LightboxDefaultProps = {
39
39
  closeOnBackdropClick: false,
40
40
  },
41
41
  portal: {},
42
+ noScroll: {
43
+ disabled: false,
44
+ },
42
45
  on: {},
43
46
  styles: {},
44
47
  className: "",
@@ -424,9 +427,9 @@ function useAnimation(nodeRef, computeAnimation) {
424
427
  }
425
428
 
426
429
  function useContainerRect() {
427
- const [containerRect, setContainerRect] = React.useState();
428
430
  const containerRef = React.useRef(null);
429
431
  const observerRef = React.useRef();
432
+ const [containerRect, setContainerRect] = React.useState();
430
433
  const setContainerRef = React.useCallback((node) => {
431
434
  containerRef.current = node;
432
435
  if (observerRef.current) {
@@ -452,11 +455,7 @@ function useContainerRect() {
452
455
  observerRef.current.observe(node);
453
456
  }
454
457
  }, []);
455
- return React.useMemo(() => ({
456
- setContainerRef,
457
- containerRef,
458
- containerRect,
459
- }), [setContainerRef, containerRef, containerRect]);
458
+ return { setContainerRef, containerRef, containerRect };
460
459
  }
461
460
 
462
461
  function useDelay() {
@@ -520,39 +519,36 @@ function useRTL() {
520
519
 
521
520
  function useSensors() {
522
521
  const [subscribers] = React.useState({});
523
- return React.useMemo(() => {
524
- const notifySubscribers = (type, event) => {
525
- var _a;
526
- (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => {
527
- if (!event.isPropagationStopped())
528
- listener(event);
529
- });
530
- };
531
- return {
532
- registerSensors: {
533
- onPointerDown: (event) => notifySubscribers(EVENT_ON_POINTER_DOWN, event),
534
- onPointerMove: (event) => notifySubscribers(EVENT_ON_POINTER_MOVE, event),
535
- onPointerUp: (event) => notifySubscribers(EVENT_ON_POINTER_UP, event),
536
- onPointerLeave: (event) => notifySubscribers(EVENT_ON_POINTER_LEAVE, event),
537
- onPointerCancel: (event) => notifySubscribers(EVENT_ON_POINTER_CANCEL, event),
538
- onKeyDown: (event) => notifySubscribers(EVENT_ON_KEY_DOWN, event),
539
- onKeyUp: (event) => notifySubscribers(EVENT_ON_KEY_UP, event),
540
- onWheel: (event) => notifySubscribers(EVENT_ON_WHEEL, event),
541
- },
542
- subscribeSensors: (type, callback) => {
543
- if (!subscribers[type]) {
544
- subscribers[type] = [];
545
- }
546
- subscribers[type].unshift(callback);
547
- return () => {
548
- const listeners = subscribers[type];
549
- if (listeners) {
550
- listeners.splice(0, listeners.length, ...listeners.filter((el) => el !== callback));
551
- }
552
- };
553
- },
522
+ const notifySubscribers = React.useCallback((type, event) => {
523
+ var _a;
524
+ (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => {
525
+ if (!event.isPropagationStopped())
526
+ listener(event);
527
+ });
528
+ }, [subscribers]);
529
+ const registerSensors = React.useMemo(() => ({
530
+ onPointerDown: (event) => notifySubscribers(EVENT_ON_POINTER_DOWN, event),
531
+ onPointerMove: (event) => notifySubscribers(EVENT_ON_POINTER_MOVE, event),
532
+ onPointerUp: (event) => notifySubscribers(EVENT_ON_POINTER_UP, event),
533
+ onPointerLeave: (event) => notifySubscribers(EVENT_ON_POINTER_LEAVE, event),
534
+ onPointerCancel: (event) => notifySubscribers(EVENT_ON_POINTER_CANCEL, event),
535
+ onKeyDown: (event) => notifySubscribers(EVENT_ON_KEY_DOWN, event),
536
+ onKeyUp: (event) => notifySubscribers(EVENT_ON_KEY_UP, event),
537
+ onWheel: (event) => notifySubscribers(EVENT_ON_WHEEL, event),
538
+ }), [notifySubscribers]);
539
+ const subscribeSensors = React.useCallback((type, callback) => {
540
+ if (!subscribers[type]) {
541
+ subscribers[type] = [];
542
+ }
543
+ subscribers[type].unshift(callback);
544
+ return () => {
545
+ const listeners = subscribers[type];
546
+ if (listeners) {
547
+ listeners.splice(0, listeners.length, ...listeners.filter((el) => el !== callback));
548
+ }
554
549
  };
555
550
  }, [subscribers]);
551
+ return { registerSensors, subscribeSensors };
556
552
  }
557
553
 
558
554
  function useThrottle(callback, delay) {
@@ -642,11 +638,9 @@ var SwipeState;
642
638
  })(SwipeState || (SwipeState = {}));
643
639
 
644
640
  function usePointerEvents(subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled) {
645
- React.useEffect(() => {
646
- if (disabled)
647
- return () => { };
648
- return cleanup(subscribeSensors(EVENT_ON_POINTER_DOWN, onPointerDown), subscribeSensors(EVENT_ON_POINTER_MOVE, onPointerMove), subscribeSensors(EVENT_ON_POINTER_UP, onPointerUp), subscribeSensors(EVENT_ON_POINTER_LEAVE, onPointerUp), subscribeSensors(EVENT_ON_POINTER_CANCEL, onPointerUp));
649
- }, [subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled]);
641
+ React.useEffect(() => !disabled
642
+ ? cleanup(subscribeSensors(EVENT_ON_POINTER_DOWN, onPointerDown), subscribeSensors(EVENT_ON_POINTER_MOVE, onPointerMove), subscribeSensors(EVENT_ON_POINTER_UP, onPointerUp), subscribeSensors(EVENT_ON_POINTER_LEAVE, onPointerUp), subscribeSensors(EVENT_ON_POINTER_CANCEL, onPointerUp))
643
+ : () => { }, [subscribeSensors, onPointerDown, onPointerMove, onPointerUp, disabled]);
650
644
  }
651
645
 
652
646
  var Gesture;
@@ -1269,9 +1263,11 @@ function padScrollbar(element, padding, rtl) {
1269
1263
  }
1270
1264
  };
1271
1265
  }
1272
- function NoScroll({ children }) {
1266
+ function NoScroll({ noScroll: { disabled }, children }) {
1273
1267
  const rtl = useRTL();
1274
1268
  useLayoutEffect(() => {
1269
+ if (disabled)
1270
+ return () => { };
1275
1271
  const cleanup = [];
1276
1272
  const { body, documentElement } = document;
1277
1273
  const scrollbar = Math.round(window.innerWidth - documentElement.clientWidth);
@@ -1292,7 +1288,7 @@ function NoScroll({ children }) {
1292
1288
  body.classList.remove(noScroll);
1293
1289
  cleanup.forEach((clean) => clean());
1294
1290
  };
1295
- }, [rtl]);
1291
+ }, [rtl, disabled]);
1296
1292
  return React.createElement(React.Fragment, null, children);
1297
1293
  }
1298
1294
  const NoScrollModule = createModule(MODULE_NO_SCROLL, NoScroll);
@@ -1418,8 +1414,8 @@ function mergeAnimation(defaultAnimation, animation = {}) {
1418
1414
  ...restAnimation,
1419
1415
  };
1420
1416
  }
1421
- function Lightbox({ carousel, animation, render, toolbar, controller, on, plugins, slides, index, ...restProps }) {
1422
- const { animation: defaultAnimation, carousel: defaultCarousel, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, slides: defaultSlides, index: defaultIndex, plugins: defaultPlugins, ...restDefaultProps } = LightboxDefaultProps;
1417
+ function Lightbox({ carousel, animation, render, toolbar, controller, noScroll, on, plugins, slides, index, ...restProps }) {
1418
+ const { animation: defaultAnimation, carousel: defaultCarousel, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, noScroll: defaultNoScroll, on: defaultOn, slides: defaultSlides, index: defaultIndex, plugins: defaultPlugins, ...restDefaultProps } = LightboxDefaultProps;
1423
1419
  const { config, augmentation } = withPlugins([
1424
1420
  createNode(PortalModule, [
1425
1421
  createNode(NoScrollModule, [
@@ -1437,6 +1433,7 @@ function Lightbox({ carousel, animation, render, toolbar, controller, on, plugin
1437
1433
  render: { ...defaultRender, ...render },
1438
1434
  toolbar: { ...defaultToolbar, ...toolbar },
1439
1435
  controller: { ...defaultController, ...controller },
1436
+ noScroll: { ...defaultNoScroll, ...noScroll },
1440
1437
  on: { ...defaultOn, ...on },
1441
1438
  ...restDefaultProps,
1442
1439
  ...restProps,
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<DeepPartial<DeepPartial<LightboxProps, "animation" | "toolbar">, "carousel", "imageProps">, "controller", "ref">;
56
+ type LightboxExternalProps = DeepPartial<DeepPartial<DeepPartial<LightboxProps, "animation" | "toolbar" | "noScroll">, "carousel", "imageProps">, "controller", "ref">;
57
57
  /** Lightbox properties */
58
58
  interface LightboxProps {
59
59
  /** if `true`, the lightbox is open */
@@ -80,6 +80,8 @@ interface LightboxProps {
80
80
  controller: ControllerSettings;
81
81
  /** portal settings */
82
82
  portal: PortalSettings;
83
+ /** NoScroll module settings */
84
+ noScroll: NoScrollSettings;
83
85
  /** lifecycle callbacks */
84
86
  on: Callbacks;
85
87
  /** customization styles */
@@ -251,6 +253,11 @@ interface PortalSettings {
251
253
  /** portal mount point */
252
254
  root?: DocumentFragment | Element | null;
253
255
  }
256
+ /** NoScroll module settings */
257
+ interface NoScrollSettings {
258
+ /** if `true`, the NoScroll module functionality is disabled */
259
+ disabled: boolean;
260
+ }
254
261
  /** Lightbox navigation action */
255
262
  interface NavigationAction {
256
263
  /** navigate through the specified number of slides */
@@ -414,4 +421,4 @@ type DeepPartialValue<T, E extends string = never> = T extends any[] ? T : T ext
414
421
  [P in keyof T]?: P extends E ? T[P] : DeepPartialValue<T[P], E>;
415
422
  } : T;
416
423
 
417
- 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, 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 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 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 };
424
+ 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, 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 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.13.1",
3
+ "version": "3.14.0",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",