yet-another-react-lightbox 3.29.0 → 3.29.2

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
@@ -15,7 +15,7 @@ declare function makeComposePrefix(base: string): (prefix?: string) => string;
15
15
  declare function translateLabel(labels: Labels | undefined, defaultLabel: Label): string;
16
16
  /** @deprecated - use `translateLabel` instead */
17
17
  declare function label(labels: Labels | undefined, defaultLabel: Label): string;
18
- declare function translateSlideCounter(labels: Labels | undefined, slides: Slide[], index: number): string;
18
+ declare function translateSlideCounter(labels: Labels | undefined, slides: readonly Slide[], index: number): string;
19
19
  declare function cleanup(...cleaners: (() => void)[]): () => void;
20
20
  declare function makeUseContext<T>(name: string, contextName: string, context: React.Context<T | null>): () => NonNullable<T>;
21
21
  declare function hasWindow(): boolean;
@@ -36,9 +36,9 @@ declare function computeSlideRect(containerRect: ContainerRect, padding: LengthO
36
36
  };
37
37
  declare function devicePixelRatio(): number;
38
38
  declare function getSlideIndex(index: number, slidesCount: number): number;
39
- declare function hasSlides(slides: Slide[]): slides is [Slide, ...Slide[]];
39
+ declare function hasSlides(slides: readonly Slide[]): slides is [Slide, ...Slide[]];
40
40
  declare function getSlide(slides: [Slide, ...Slide[]], index: number): SlideImage;
41
- declare function getSlideIfPresent(slides: Slide[], index: number): SlideImage | undefined;
41
+ declare function getSlideIfPresent(slides: readonly Slide[], index: number): SlideImage | undefined;
42
42
  declare function getSlideKey(slide: Slide): string | undefined;
43
43
  declare function addToolbarButton(toolbar: ToolbarSettings, key: string, button: React.ReactNode): ToolbarSettings;
44
44
  declare function stopNavigationEventsPropagation(): {
@@ -46,7 +46,7 @@ declare function stopNavigationEventsPropagation(): {
46
46
  onKeyDown: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
47
47
  onWheel: (event: React.PointerEvent | React.KeyboardEvent | React.WheelEvent) => void;
48
48
  };
49
- declare function calculatePreload(carousel: CarouselSettings, slides: Slide[], minimum?: number): number;
49
+ declare function calculatePreload(carousel: CarouselSettings, slides: readonly Slide[], minimum?: number): number;
50
50
  declare function makeInertWhen(condition: boolean): {
51
51
  inert: boolean;
52
52
  };
@@ -54,7 +54,7 @@ declare function reflow(node: HTMLElement): void;
54
54
 
55
55
  declare function createModule(name: string, component: Component): Module;
56
56
  declare function createNode(module: Module, children?: Node$1[]): Node$1;
57
- declare function withPlugins(root: Node$1[], plugins?: Plugin[], augmentations?: Augmentation[]): {
57
+ declare function withPlugins(root: Node$1[], plugins?: readonly Plugin[], augmentations?: Augmentation[]): {
58
58
  config: Node$1[];
59
59
  augmentation: Augmentation;
60
60
  };
@@ -87,7 +87,7 @@ declare function useEventCallback<Args extends unknown[], Return>(fn: (...args:
87
87
  declare function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
88
88
  declare function useForkRef<InstanceA, InstanceB>(refA: React.Ref<InstanceA> | null | undefined, refB: React.Ref<InstanceB> | null | undefined): React.Ref<InstanceA & InstanceB> | null;
89
89
 
90
- declare const useLayoutEffect: typeof React.useLayoutEffect;
90
+ declare const useLayoutEffect: typeof React.useEffect;
91
91
 
92
92
  declare function useLoseFocus(focus: () => void, disabled?: boolean): {
93
93
  onFocus: () => void;
package/dist/index.js CHANGED
@@ -382,9 +382,13 @@ function LightboxStateProvider({ slides, index, children }) {
382
382
  globalIndex: index,
383
383
  currentSlide: getSlideIfPresent(slides, index),
384
384
  });
385
- React.useEffect(() => {
385
+ const [prevSlides, setPrevSlides] = React.useState(slides);
386
+ const [prevIndex, setPrevIndex] = React.useState(index);
387
+ if (slides !== prevSlides || index !== prevIndex) {
388
+ setPrevSlides(slides);
389
+ setPrevIndex(index);
386
390
  dispatch({ type: "update", slides, index });
387
- }, [slides, index]);
391
+ }
388
392
  const context = React.useMemo(() => ({ ...state, state, dispatch }), [state, dispatch]);
389
393
  return (React.createElement(LightboxDispatchContext.Provider, { value: dispatch },
390
394
  React.createElement(LightboxStateContext.Provider, { value: context }, children)));
@@ -715,7 +719,7 @@ function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps,
715
719
  maxWidth: "100%",
716
720
  maxHeight: "100%",
717
721
  };
718
- 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(", ");
722
+ const srcSet = (_g = image.srcSet) === null || _g === void 0 ? void 0 : _g.slice().sort((a, b) => a.width - b.width).map((item) => `${item.src} ${item.width}w`).join(", ");
719
723
  const estimateActualWidth = () => rect && !cover && image.width && image.height ? (rect.height / image.height) * image.width : Number.MAX_VALUE;
720
724
  const sizes = srcSet && rect && hasWindow() ? `${Math.round(Math.min(estimateActualWidth(), rect.width))}px` : undefined;
721
725
  const { style: imagePropsStyle, className: imagePropsClassName, ...restImageProps } = (typeof imageProps === "function" ? imageProps(image) : imageProps) || {};
@@ -1 +1 @@
1
- .yarl__counter{bottom:var(--yarl__counter_bottom,unset);color:var(--yarl__counter_color,var(--yarl__color_button,hsla(0,0%,100%,.8)));filter:var(--yarl__counter_filter,drop-shadow(2px 2px 2px rgba(0,0,0,.8)));left:var(--yarl__counter_left,0);line-height:var(--yarl__counter_line_height,var(--yarl__icon_size,32px));margin:var(--yarl__counter_margin,var(--yarl__toolbar_padding,8px));padding:var(--yarl__counter_padding,var(--yarl__button_padding,8px));position:var(--yarl__counter_position,absolute);right:var(--yarl__counter_right,unset);top:var(--yarl__counter_top,0);-webkit-user-select:var(--yarl__counter_user_select,none);-moz-user-select:var(--yarl__counter_user_select,none);user-select:var(--yarl__counter_user_select,none)}
1
+ .yarl__counter{bottom:var(--yarl__counter_bottom,unset);color:var(--yarl__counter_color,var(--yarl__color_button,hsla(0,0%,100%,.8)));filter:var(--yarl__counter_filter,drop-shadow(2px 2px 2px rgba(0,0,0,.8)));left:var(--yarl__counter_left,0);line-height:var(--yarl__counter_line_height,var(--yarl__icon_size,32px));margin:var(--yarl__counter_margin,var(--yarl__toolbar_padding,8px));padding:var(--yarl__counter_padding,var(--yarl__button_padding,8px));position:var(--yarl__counter_position,absolute);right:var(--yarl__counter_right,unset);top:var(--yarl__counter_top,0);-webkit-user-select:var(--yarl__counter_user_select,none);-moz-user-select:var(--yarl__counter_user_select,none);user-select:var(--yarl__counter_user_select,none)}[dir=rtl] .yarl__counter{left:var(--yarl__counter_rtl_left,unset);right:var(--yarl__counter_rtl_right,0)}
@@ -39,7 +39,7 @@ declare module "yet-another-react-lightbox" {
39
39
  /** disables the capability of remote playback */
40
40
  disableRemotePlayback?: boolean;
41
41
  /** an array of video files */
42
- sources: {
42
+ sources: readonly {
43
43
  /** video source URL */
44
44
  src: string;
45
45
  /** video source type (e.g., `video/mp4`) */
package/dist/types.d.ts CHANGED
@@ -66,13 +66,13 @@ interface LightboxProps {
66
66
  /** starting slide index */
67
67
  index: number;
68
68
  /** slides to display in the lightbox */
69
- slides: Slide[];
69
+ slides: readonly Slide[];
70
70
  /** custom render functions */
71
71
  render: Render;
72
72
  /** custom UI labels / translations */
73
73
  labels: Labels;
74
74
  /** enabled plugins */
75
- plugins: Plugin[];
75
+ plugins: readonly Plugin[];
76
76
  /** toolbar settings */
77
77
  toolbar: ToolbarSettings;
78
78
  /** carousel settings */
@@ -120,7 +120,7 @@ interface SlideImage extends GenericSlide {
120
120
  /** `object-fit` setting */
121
121
  imageFit?: ImageFit;
122
122
  /** alternative images to be passed to the 'srcSet' */
123
- srcSet?: ImageSource[];
123
+ srcSet?: readonly ImageSource[];
124
124
  }
125
125
  /** Image source */
126
126
  interface ImageSource {
@@ -285,13 +285,13 @@ type LightboxStateSwipeAction = {
285
285
  /** Lightbox state update action */
286
286
  type LightboxStateUpdateAction = {
287
287
  type: "update";
288
- slides: Slide[];
288
+ slides: readonly Slide[];
289
289
  index: number;
290
290
  };
291
291
  /** Lightbox state */
292
292
  interface LightboxState {
293
293
  /** lightbox slides */
294
- slides: Slide[];
294
+ slides: readonly Slide[];
295
295
  /** current slide index */
296
296
  currentIndex: number;
297
297
  /** current slide index in the (-∞, +∞) range */
@@ -408,7 +408,7 @@ type Label = keyof Labels;
408
408
  /** Toolbar settings */
409
409
  interface ToolbarSettings {
410
410
  /** buttons to render in the toolbar */
411
- buttons: (ToolbarButtonKey | React.ReactNode)[];
411
+ buttons: readonly (ToolbarButtonKey | React.ReactNode)[];
412
412
  }
413
413
  type ToolbarButtonKey = keyof ToolbarButtonKeys;
414
414
  interface ToolbarButtonKeys {
@@ -451,7 +451,7 @@ type Plugin = (props: PluginProps) => void;
451
451
  type DeepPartial<T extends object, K extends keyof T = keyof T, E extends string = never> = Omit<Partial<T>, K> & {
452
452
  [P in K]?: DeepPartialValue<T[P], E>;
453
453
  };
454
- type DeepPartialValue<T, E extends string = never> = T extends any[] ? T : T extends (...props: any[]) => any ? T : T extends object ? {
454
+ type DeepPartialValue<T, E extends string = never> = T extends readonly any[] ? T : T extends (...props: any[]) => any ? T : T extends object ? {
455
455
  [P in keyof T]?: P extends E ? T[P] : DeepPartialValue<T[P], E>;
456
456
  } : T;
457
457
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.29.0",
3
+ "version": "3.29.2",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",