yet-another-react-lightbox 1.0.0 → 1.0.1

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/Lightbox.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { LightboxDefaultProps, LightboxPropTypes } from "./types.js";
3
3
  import { CarouselModule, ControllerModule, CoreModule, createNode, NavigationModule, NoScrollModule, PortalModule, ToolbarModule, withPlugins, } from "./core/index.js";
4
- const renderNode = (node, props) => React.createElement(node.module.component, { key: node.module.name, ...props }, node.children?.map((child) => renderNode(child, props)));
4
+ const renderNode = (node, props) => {
5
+ var _a;
6
+ return React.createElement(node.module.component, { key: node.module.name, ...props }, (_a = node.children) === null || _a === void 0 ? void 0 : _a.map((child) => renderNode(child, props)));
7
+ };
5
8
  const LightboxComponent = (props) => {
6
9
  const { plugins } = props;
7
10
  const { config, augmentation } = withPlugins([
@@ -4,6 +4,7 @@ import { useLatest } from "../hooks/index.js";
4
4
  import { ErrorIcon, LoadingIcon } from "./Icons.js";
5
5
  import { useController } from "../modules/Controller.js";
6
6
  export const ImageSlide = ({ slide: image }) => {
7
+ var _a, _b, _c;
7
8
  const [state, setState] = React.useState("loading");
8
9
  const latestState = useLatest(state);
9
10
  const imageRef = React.useRef(null);
@@ -23,7 +24,7 @@ export const ImageSlide = ({ slide: image }) => {
23
24
  }, [latestState]);
24
25
  const setImageRef = React.useCallback((img) => {
25
26
  imageRef.current = img;
26
- if (img?.complete) {
27
+ if (img === null || img === void 0 ? void 0 : img.complete) {
27
28
  handleLoading(img);
28
29
  }
29
30
  }, [handleLoading]);
@@ -48,9 +49,9 @@ export const ImageSlide = ({ slide: image }) => {
48
49
  },
49
50
  }
50
51
  : {
51
- style: (imageRef.current?.naturalWidth ?? 0) > 0
52
+ style: ((_b = (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.naturalWidth) !== null && _b !== void 0 ? _b : 0) > 0
52
53
  ? {
53
- maxWidth: `${imageRef.current?.naturalWidth}px`,
54
+ maxWidth: `${(_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalWidth}px`,
54
55
  }
55
56
  : undefined,
56
57
  }), src: image.src }),
@@ -12,12 +12,12 @@ const traverseNode = (node, target, apply) => {
12
12
  }
13
13
  if (node.children) {
14
14
  return [
15
- createNode(node.module, node.children.flatMap((n) => traverseNode(n, target, apply) ?? [])),
15
+ createNode(node.module, node.children.flatMap((n) => { var _a; return (_a = traverseNode(n, target, apply)) !== null && _a !== void 0 ? _a : []; })),
16
16
  ];
17
17
  }
18
18
  return [node];
19
19
  };
20
- const traverse = (nodes, target, apply) => nodes.flatMap((node) => traverseNode(node, target, apply) ?? []);
20
+ const traverse = (nodes, target, apply) => nodes.flatMap((node) => { var _a; return (_a = traverseNode(node, target, apply)) !== null && _a !== void 0 ? _a : []; });
21
21
  export const withPlugins = (root, plugins) => {
22
22
  let config = root;
23
23
  const augmentations = [];
@@ -29,13 +29,16 @@ export const withPlugins = (root, plugins) => {
29
29
  config = traverse(config, target, (node) => [createNode(module, [node])]);
30
30
  };
31
31
  const addChild = (target, module, precede) => {
32
- config = traverse(config, target, (node) => [
33
- createNode(node.module, [
34
- ...(precede ? [createNode(module)] : []),
35
- ...(node.children ?? []),
36
- ...(!precede ? [createNode(module)] : []),
37
- ]),
38
- ]);
32
+ config = traverse(config, target, (node) => {
33
+ var _a;
34
+ return [
35
+ createNode(node.module, [
36
+ ...(precede ? [createNode(module)] : []),
37
+ ...((_a = node.children) !== null && _a !== void 0 ? _a : []),
38
+ ...(!precede ? [createNode(module)] : []),
39
+ ]),
40
+ ];
41
+ });
39
42
  };
40
43
  const addSibling = (target, module, precede) => {
41
44
  config = traverse(config, target, (node) => [
@@ -53,7 +56,7 @@ export const withPlugins = (root, plugins) => {
53
56
  const augment = (augmentation) => {
54
57
  augmentations.push(augmentation);
55
58
  };
56
- plugins?.forEach((plugin) => {
59
+ plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => {
57
60
  plugin({
58
61
  addParent,
59
62
  addChild,
@@ -17,7 +17,8 @@ export const EventsProvider = ({ children }) => {
17
17
  return () => unsubscribe(topic, callback);
18
18
  };
19
19
  const publish = (topic, event) => {
20
- subscriptions.current[topic]?.forEach((callback) => callback(topic, event));
20
+ var _a;
21
+ (_a = subscriptions.current[topic]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(topic, event));
21
22
  };
22
23
  React.useEffect(() => () => {
23
24
  subscriptions.current = {};
@@ -10,8 +10,8 @@ export const useContainerRect = () => {
10
10
  observerRef.current = undefined;
11
11
  }
12
12
  const updateContainerRect = () => {
13
- const width = node?.clientWidth;
14
- const height = node?.clientHeight;
13
+ const width = node === null || node === void 0 ? void 0 : node.clientWidth;
14
+ const height = node === null || node === void 0 ? void 0 : node.clientHeight;
15
15
  setContainerRect(width !== undefined && height !== undefined
16
16
  ? {
17
17
  width,
@@ -3,7 +3,8 @@ export const useSensors = () => {
3
3
  const [subscribers] = React.useState({});
4
4
  return React.useMemo(() => {
5
5
  const notifySubscribers = (type, event) => {
6
- subscribers[type]?.forEach((listener) => listener(event));
6
+ var _a;
7
+ (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
7
8
  };
8
9
  return {
9
10
  registerSensors: {
@@ -21,10 +22,11 @@ export const useSensors = () => {
21
22
  onWheel: (event) => notifySubscribers("onWheel", event),
22
23
  },
23
24
  subscribeSensors: (type, callback) => {
25
+ var _a;
24
26
  if (!subscribers[type]) {
25
27
  subscribers[type] = [];
26
28
  }
27
- subscribers[type]?.push(callback);
29
+ (_a = subscribers[type]) === null || _a === void 0 ? void 0 : _a.push(callback);
28
30
  return () => {
29
31
  const listeners = subscribers[type];
30
32
  if (listeners) {
@@ -9,7 +9,7 @@ export const Carousel = (props) => {
9
9
  const { slides, carousel: { finite, preload, padding, spacing }, render: { slide: renderSlide }, } = props;
10
10
  const { currentIndex, globalIndex } = useController();
11
11
  const items = [];
12
- if (slides?.length > 0) {
12
+ if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
13
13
  for (let i = currentIndex - preload; i < currentIndex; i += 1) {
14
14
  if (!finite || i >= 0) {
15
15
  items.push(React.createElement(CarouselSlide, { key: globalIndex + i - currentIndex, slide: slides[(i + preload * slides.length) % slides.length], offset: i - currentIndex, renderSlide: renderSlide }));
@@ -41,18 +41,20 @@ export const Controller = ({ children, ...props }) => {
41
41
  };
42
42
  }, [containerRef]);
43
43
  React.useEffect(() => {
44
- containerRef.current?.focus();
44
+ var _a;
45
+ (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
45
46
  }, [containerRef]);
46
47
  React.useEffect(() => subscribe("close", () => {
47
48
  setTimeout(refs.current.props.close, refs.current.props.animation.fade);
48
49
  }), [subscribe, setTimeout]);
49
50
  const updateSwipeOffset = React.useCallback(() => {
51
+ var _a, _b;
50
52
  const offsetVar = cssVar("swipe_offset");
51
53
  if (refs.current.swipeOffset !== 0) {
52
- containerRef.current?.style.setProperty(offsetVar, `${Math.round(refs.current.swipeOffset)}px`);
54
+ (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.style.setProperty(offsetVar, `${Math.round(refs.current.swipeOffset)}px`);
53
55
  }
54
56
  else {
55
- containerRef.current?.style.removeProperty(offsetVar);
57
+ (_b = containerRef.current) === null || _b === void 0 ? void 0 : _b.style.removeProperty(offsetVar);
56
58
  }
57
59
  }, [containerRef]);
58
60
  useEnhancedEffect(() => {
@@ -77,6 +79,7 @@ export const Controller = ({ children, ...props }) => {
77
79
  ((offset > 0 && currentIndex === 0) || (offset < 0 && currentIndex === slides.length - 1)));
78
80
  }, []);
79
81
  const swipe = React.useCallback((direction) => {
82
+ var _a;
80
83
  const { current } = refs;
81
84
  const slidesCount = current.props.slides.length;
82
85
  const swipeAnimationDuration = current.props.animation.swipe;
@@ -85,7 +88,7 @@ export const Controller = ({ children, ...props }) => {
85
88
  let newSwipeState = "swipe-animation";
86
89
  let newSwipeAnimationDuration = swipeAnimationDuration;
87
90
  if (!direction) {
88
- const containerWidth = current.containerRect?.width;
91
+ const containerWidth = (_a = current.containerRect) === null || _a === void 0 ? void 0 : _a.width;
89
92
  const elapsedTime = current.swipeStartTime ? Date.now() - current.swipeStartTime : 0;
90
93
  const expectedTime = containerWidth
91
94
  ? (swipeAnimationDuration / containerWidth) * Math.abs(swipeOffset)
@@ -194,6 +197,7 @@ export const Controller = ({ children, ...props }) => {
194
197
  }, [clearPointer, swipe]);
195
198
  React.useEffect(() => cleanup(subscribeSensors("onPointerDown", onPointerDown), subscribeSensors("onPointerMove", onPointerMove), subscribeSensors("onPointerUp", onPointerUp), subscribeSensors("onPointerLeave", onPointerUp), subscribeSensors("onPointerCancel", onPointerUp)), [subscribeSensors, onPointerDown, onPointerMove, onPointerUp]);
196
199
  const onWheel = React.useCallback((event) => {
200
+ var _a;
197
201
  if (event.ctrlKey) {
198
202
  return;
199
203
  }
@@ -223,7 +227,7 @@ export const Controller = ({ children, ...props }) => {
223
227
  }
224
228
  }
225
229
  else if (current.swipeState === "swipe") {
226
- const containerWidth = current.containerRect?.width;
230
+ const containerWidth = (_a = current.containerRect) === null || _a === void 0 ? void 0 : _a.width;
227
231
  if (containerWidth) {
228
232
  current.swipeOffset -= event.deltaX;
229
233
  current.swipeOffset =
@@ -5,6 +5,6 @@ import { useEvents } from "../contexts/index.js";
5
5
  import { CloseIcon, IconButton } from "../components/index.js";
6
6
  export const Toolbar = ({ toolbar: { buttons }, labels }) => {
7
7
  const { publish } = useEvents();
8
- return (React.createElement("div", { className: cssClass("toolbar") }, buttons?.map((button) => button === "close" ? (React.createElement(IconButton, { key: "close", label: label(labels, "Close"), icon: CloseIcon, onClick: () => publish("close") })) : (button))));
8
+ return (React.createElement("div", { className: cssClass("toolbar") }, buttons === null || buttons === void 0 ? void 0 : buttons.map((button) => button === "close" ? (React.createElement(IconButton, { key: "close", label: label(labels, "Close"), icon: CloseIcon, onClick: () => publish("close") })) : (button))));
9
9
  };
10
10
  export const ToolbarModule = createModule("toolbar", Toolbar);
@@ -6,16 +6,13 @@ export const FullscreenButton = ({ auto, labels }) => {
6
6
  const [fullscreen, setFullscreen] = React.useState(false);
7
7
  const { containerRef } = useController();
8
8
  const isFullscreenEnabled = () => {
9
- return (document.fullscreenEnabled ??
10
- document.webkitFullscreenEnabled ??
11
- document.mozFullScreenEnabled ??
12
- document.msFullscreenEnabled ??
13
- false);
9
+ var _a, _b, _c, _d;
10
+ return ((_d = (_c = (_b = (_a = document.fullscreenEnabled) !== null && _a !== void 0 ? _a : document.webkitFullscreenEnabled) !== null && _b !== void 0 ? _b : document.mozFullScreenEnabled) !== null && _c !== void 0 ? _c : document.msFullscreenEnabled) !== null && _d !== void 0 ? _d : false);
14
11
  };
15
- const getFullscreenElement = React.useCallback(() => document.fullscreenElement ??
16
- document.webkitFullscreenElement ??
17
- document.mozFullScreenElement ??
18
- document.msFullscreenElement, []);
12
+ const getFullscreenElement = React.useCallback(() => {
13
+ var _a, _b, _c;
14
+ return (_c = (_b = (_a = document.fullscreenElement) !== null && _a !== void 0 ? _a : document.webkitFullscreenElement) !== null && _b !== void 0 ? _b : document.mozFullScreenElement) !== null && _c !== void 0 ? _c : document.msFullscreenElement;
15
+ }, []);
19
16
  const requestFullscreen = React.useCallback(() => {
20
17
  const container = containerRef.current;
21
18
  if (container) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Modern lightbox component for React",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",