yet-another-react-lightbox 2.6.2 → 3.0.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/Lightbox.d.ts +1 -1
- package/dist/Lightbox.js +17 -13
- package/dist/core/components/IconButton.js +2 -2
- package/dist/core/components/ImageSlide.js +0 -3
- package/dist/core/config.d.ts +3 -3
- package/dist/core/config.js +18 -13
- package/dist/core/consts.d.ts +2 -4
- package/dist/core/consts.js +2 -4
- package/dist/core/contexts/Events.d.ts +3 -2
- package/dist/core/contexts/Events.js +3 -3
- package/dist/core/contexts/LightboxProps.d.ts +6 -0
- package/dist/core/contexts/LightboxProps.js +7 -0
- package/dist/core/contexts/LightboxState.d.ts +15 -15
- package/dist/core/contexts/LightboxState.js +33 -20
- package/dist/core/contexts/Timeouts.d.ts +1 -0
- package/dist/core/contexts/Timeouts.js +3 -3
- package/dist/core/contexts/index.d.ts +1 -0
- package/dist/core/contexts/index.js +1 -0
- package/dist/core/hooks/useAnimation.d.ts +4 -1
- package/dist/core/hooks/useAnimation.js +12 -3
- package/dist/core/hooks/useLoseFocus.js +3 -3
- package/dist/core/modules/Carousel.d.ts +1 -1
- package/dist/core/modules/Carousel.js +19 -24
- package/dist/core/modules/Controller.d.ts +15 -16
- package/dist/core/modules/Controller.js +68 -34
- package/dist/core/modules/Navigation.d.ts +4 -5
- package/dist/core/modules/Navigation.js +15 -12
- package/dist/core/modules/Portal.js +5 -4
- package/dist/core/modules/Root.d.ts +4 -0
- package/dist/core/modules/Root.js +7 -0
- package/dist/core/modules/Toolbar.d.ts +0 -6
- package/dist/core/modules/Toolbar.js +6 -8
- package/dist/core/modules/index.d.ts +1 -1
- package/dist/core/modules/index.js +1 -1
- package/dist/core/utils.d.ts +7 -10
- package/dist/core/utils.js +14 -14
- package/dist/plugins/captions/Captions.d.ts +2 -6
- package/dist/plugins/captions/Captions.js +17 -20
- package/dist/plugins/captions/Description.d.ts +2 -2
- package/dist/plugins/captions/Description.js +5 -3
- package/dist/plugins/captions/Title.js +2 -3
- package/dist/plugins/captions/captions.css +1 -0
- package/dist/plugins/captions/index.d.ts +2 -2
- package/dist/plugins/captions/props.d.ts +9 -0
- package/dist/plugins/captions/props.js +8 -0
- package/dist/plugins/captions/utils.d.ts +1 -1
- package/dist/plugins/captions/utils.js +1 -3
- package/dist/plugins/fullscreen/Fullscreen.d.ts +2 -2
- package/dist/plugins/fullscreen/Fullscreen.js +5 -3
- package/dist/plugins/fullscreen/FullscreenButton.js +8 -5
- package/dist/plugins/fullscreen/FullscreenContext.d.ts +5 -9
- package/dist/plugins/fullscreen/FullscreenContext.js +16 -26
- package/dist/plugins/fullscreen/index.d.ts +21 -10
- package/dist/plugins/fullscreen/props.d.ts +10 -0
- package/dist/plugins/fullscreen/props.js +8 -0
- package/dist/plugins/inline/Inline.d.ts +2 -2
- package/dist/plugins/inline/Inline.js +4 -7
- package/dist/plugins/inline/InlineContainer.d.ts +4 -0
- package/dist/plugins/inline/InlineContainer.js +5 -0
- package/dist/plugins/inline/index.d.ts +1 -1
- package/dist/plugins/slideshow/Slideshow.d.ts +2 -6
- package/dist/plugins/slideshow/Slideshow.js +7 -10
- package/dist/plugins/slideshow/SlideshowButton.js +7 -5
- package/dist/plugins/slideshow/SlideshowContext.d.ts +5 -9
- package/dist/plugins/slideshow/SlideshowContext.js +21 -12
- package/dist/plugins/slideshow/index.d.ts +16 -11
- package/dist/plugins/slideshow/props.d.ts +12 -0
- package/dist/plugins/slideshow/props.js +9 -0
- package/dist/plugins/thumbnails/Thumbnail.d.ts +3 -7
- package/dist/plugins/thumbnails/Thumbnail.js +7 -3
- package/dist/plugins/thumbnails/Thumbnails.d.ts +2 -13
- package/dist/plugins/thumbnails/Thumbnails.js +6 -19
- package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +1 -1
- package/dist/plugins/thumbnails/ThumbnailsContainer.js +10 -10
- package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +4 -6
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +16 -14
- package/dist/plugins/thumbnails/index.d.ts +5 -5
- package/dist/plugins/thumbnails/props.d.ts +34 -0
- package/dist/plugins/thumbnails/props.js +20 -0
- package/dist/plugins/video/Video.d.ts +2 -6
- package/dist/plugins/video/Video.js +11 -11
- package/dist/plugins/video/VideoSlide.d.ts +1 -1
- package/dist/plugins/video/VideoSlide.js +3 -3
- package/dist/plugins/video/index.d.ts +39 -42
- package/dist/plugins/video/props.d.ts +29 -0
- package/dist/plugins/video/props.js +13 -0
- package/dist/plugins/zoom/ResponsiveImage.js +23 -15
- package/dist/plugins/zoom/Zoom.d.ts +0 -11
- package/dist/plugins/zoom/Zoom.js +11 -33
- package/dist/plugins/zoom/ZoomButton.d.ts +6 -5
- package/dist/plugins/zoom/ZoomButton.js +11 -33
- package/dist/plugins/zoom/ZoomButtonsGroup.d.ts +1 -4
- package/dist/plugins/zoom/ZoomButtonsGroup.js +6 -7
- package/dist/plugins/zoom/ZoomController.d.ts +12 -0
- package/dist/plugins/zoom/ZoomController.js +17 -0
- package/dist/plugins/zoom/ZoomToolbarControl.d.ts +2 -0
- package/dist/plugins/zoom/ZoomToolbarControl.js +12 -0
- package/dist/plugins/zoom/ZoomWrapper.d.ts +5 -0
- package/dist/plugins/zoom/ZoomWrapper.js +36 -0
- package/dist/plugins/zoom/hooks/index.d.ts +6 -0
- package/dist/plugins/zoom/hooks/index.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.d.ts +2 -0
- package/dist/plugins/zoom/hooks/useZoomAnimation.js +39 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.d.ts +1 -0
- package/dist/plugins/zoom/hooks/useZoomCallback.js +12 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.d.ts +5 -0
- package/dist/plugins/zoom/hooks/useZoomImageRect.js +41 -0
- package/dist/plugins/zoom/hooks/useZoomProps.d.ts +13 -0
- package/dist/plugins/zoom/hooks/useZoomProps.js +6 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.d.ts +3 -0
- package/dist/plugins/zoom/hooks/useZoomSensors.js +154 -0
- package/dist/plugins/zoom/hooks/useZoomState.d.ts +12 -0
- package/dist/plugins/zoom/hooks/useZoomState.js +63 -0
- package/dist/plugins/zoom/index.d.ts +37 -24
- package/dist/plugins/zoom/index.js +0 -2
- package/dist/plugins/zoom/props.d.ts +25 -0
- package/dist/plugins/zoom/props.js +15 -0
- package/dist/props.d.ts +0 -4
- package/dist/props.js +10 -5
- package/dist/types.d.ts +173 -117
- package/package.json +41 -11
- package/dist/core/modules/Core.d.ts +0 -4
- package/dist/core/modules/Core.js +0 -10
- package/dist/plugins/captions/CaptionsContext.d.ts +0 -7
- package/dist/plugins/captions/CaptionsContext.js +0 -11
- package/dist/plugins/zoom/ZoomContainer.d.ts +0 -9
- package/dist/plugins/zoom/ZoomContainer.js +0 -316
- package/dist/plugins/zoom/ZoomContext.d.ts +0 -11
- package/dist/plugins/zoom/ZoomContext.js +0 -20
package/dist/Lightbox.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LightboxExternalProps } from "./types.js";
|
|
3
3
|
/** Lightbox component */
|
|
4
|
-
export declare function Lightbox(
|
|
4
|
+
export declare function Lightbox({ carousel, animation, render, toolbar, controller, on, plugins, slides, index, ...restProps }: LightboxExternalProps): JSX.Element | null;
|
package/dist/Lightbox.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { LightboxDefaultProps } from "./props.js";
|
|
3
|
-
import { CarouselModule, ControllerModule,
|
|
3
|
+
import { CarouselModule, ControllerModule, createNode, EventsProvider, LightboxPropsProvider, LightboxStateProvider, NavigationModule, NoScrollModule, PortalModule, RootModule, TimeoutsProvider, ToolbarModule, withPlugins, } from "./core/index.js";
|
|
4
4
|
function renderNode(node, props) {
|
|
5
5
|
var _a;
|
|
6
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
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function mergeAnimation(defaultAnimation, animation = {}) {
|
|
9
|
+
const { easing: defaultAnimationEasing, ...restDefaultAnimation } = defaultAnimation;
|
|
10
|
+
const { easing, ...restAnimation } = animation;
|
|
9
11
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
...
|
|
12
|
+
easing: { ...defaultAnimationEasing, ...easing },
|
|
13
|
+
...restDefaultAnimation,
|
|
14
|
+
...restAnimation,
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
|
-
export function Lightbox(
|
|
16
|
-
const {
|
|
17
|
-
const { carousel: defaultCarousel, animation: defaultAnimation, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, ...restDefaultProps } = LightboxDefaultProps;
|
|
17
|
+
export function Lightbox({ carousel, animation, render, toolbar, controller, on, plugins, slides, index, ...restProps }) {
|
|
18
|
+
const { animation: defaultAnimation, carousel: defaultCarousel, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, slides: defaultSlides, index: defaultIndex, plugins: defaultPlugins, ...restDefaultProps } = LightboxDefaultProps;
|
|
18
19
|
const { config, augmentation } = withPlugins([
|
|
19
20
|
createNode(PortalModule, [
|
|
20
21
|
createNode(NoScrollModule, [
|
|
@@ -25,10 +26,10 @@ export function Lightbox(props) {
|
|
|
25
26
|
]),
|
|
26
27
|
]),
|
|
27
28
|
]),
|
|
28
|
-
], plugins
|
|
29
|
-
const
|
|
29
|
+
], plugins || defaultPlugins);
|
|
30
|
+
const props = augmentation({
|
|
31
|
+
animation: mergeAnimation(defaultAnimation, animation),
|
|
30
32
|
carousel: { ...defaultCarousel, ...carousel },
|
|
31
|
-
animation: { ...defaultAnimation, ...animation },
|
|
32
33
|
render: { ...defaultRender, ...render },
|
|
33
34
|
toolbar: { ...defaultToolbar, ...toolbar },
|
|
34
35
|
controller: { ...defaultController, ...controller },
|
|
@@ -36,7 +37,10 @@ export function Lightbox(props) {
|
|
|
36
37
|
...restDefaultProps,
|
|
37
38
|
...restProps,
|
|
38
39
|
});
|
|
39
|
-
if (!
|
|
40
|
+
if (!props.open)
|
|
40
41
|
return null;
|
|
41
|
-
return React.createElement(
|
|
42
|
+
return (React.createElement(LightboxPropsProvider, { ...props },
|
|
43
|
+
React.createElement(LightboxStateProvider, { slides: slides || defaultSlides, index: index || defaultIndex },
|
|
44
|
+
React.createElement(TimeoutsProvider, null,
|
|
45
|
+
React.createElement(EventsProvider, null, renderNode(createNode(RootModule, config), props))))));
|
|
42
46
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { clsx, cssClass } from "../utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useLightboxProps } from "../contexts/index.js";
|
|
4
4
|
import { ELEMENT_BUTTON, ELEMENT_ICON } from "../consts.js";
|
|
5
5
|
export const IconButton = React.forwardRef(({ label, className, icon: Icon, renderIcon, onClick, style, ...rest }, ref) => {
|
|
6
|
-
const { styles } =
|
|
6
|
+
const { styles } = useLightboxProps();
|
|
7
7
|
return (React.createElement("button", { ref: ref, type: "button", "aria-label": label, className: clsx(cssClass(ELEMENT_BUTTON), className), onClick: onClick, style: { ...style, ...styles.button }, ...rest }, renderIcon ? renderIcon() : React.createElement(Icon, { className: cssClass(ELEMENT_ICON), style: styles.icon })));
|
|
8
8
|
});
|
|
9
9
|
IconButton.displayName = "IconButton";
|
|
@@ -18,9 +18,6 @@ export function ImageSlide({ slide: image, offset, render, rect, imageFit, onCli
|
|
|
18
18
|
}
|
|
19
19
|
}, [offset, status, publish]);
|
|
20
20
|
const handleLoading = useEventCallback((img) => {
|
|
21
|
-
if (status === SLIDE_STATUS_COMPLETE) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
21
|
("decode" in img ? img.decode() : Promise.resolve())
|
|
25
22
|
.catch(() => { })
|
|
26
23
|
.then(() => {
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Augmentation, Component, Module, Node, Plugin } from "../types.js";
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
2
|
+
export declare function createModule(name: string, component: Component): Module;
|
|
3
|
+
export declare function createNode(module: Module, children?: Node[]): Node;
|
|
4
|
+
export declare function withPlugins(root: Node[], plugins?: Plugin[], augmentations?: Augmentation[]): {
|
|
5
5
|
config: Node[];
|
|
6
6
|
augmentation: Augmentation;
|
|
7
7
|
};
|
package/dist/core/config.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
component
|
|
4
|
-
}
|
|
5
|
-
export
|
|
6
|
-
module,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const traverseNode = (node, target, apply) => {
|
|
1
|
+
import { MODULE_CONTROLLER } from "./consts.js";
|
|
2
|
+
export function createModule(name, component) {
|
|
3
|
+
return { name, component };
|
|
4
|
+
}
|
|
5
|
+
export function createNode(module, children) {
|
|
6
|
+
return { module, children };
|
|
7
|
+
}
|
|
8
|
+
function traverseNode(node, target, apply) {
|
|
10
9
|
if (node.module.name === target) {
|
|
11
10
|
return apply(node);
|
|
12
11
|
}
|
|
@@ -16,9 +15,11 @@ const traverseNode = (node, target, apply) => {
|
|
|
16
15
|
];
|
|
17
16
|
}
|
|
18
17
|
return [node];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
}
|
|
19
|
+
function traverse(nodes, target, apply) {
|
|
20
|
+
return nodes.flatMap((node) => { var _a; return (_a = traverseNode(node, target, apply)) !== null && _a !== void 0 ? _a : []; });
|
|
21
|
+
}
|
|
22
|
+
export function withPlugins(root, plugins = [], augmentations = []) {
|
|
22
23
|
let config = root;
|
|
23
24
|
const contains = (target) => {
|
|
24
25
|
const nodes = [...config];
|
|
@@ -60,6 +61,9 @@ export const withPlugins = (root, plugins = [], augmentations = []) => {
|
|
|
60
61
|
...(!precede ? [createNode(module)] : []),
|
|
61
62
|
]);
|
|
62
63
|
};
|
|
64
|
+
const addModule = (module) => {
|
|
65
|
+
append(MODULE_CONTROLLER, module);
|
|
66
|
+
};
|
|
63
67
|
const replace = (target, module) => {
|
|
64
68
|
config = traverse(config, target, (node) => [createNode(module, node.children)]);
|
|
65
69
|
};
|
|
@@ -76,6 +80,7 @@ export const withPlugins = (root, plugins = [], augmentations = []) => {
|
|
|
76
80
|
append,
|
|
77
81
|
addChild,
|
|
78
82
|
addSibling,
|
|
83
|
+
addModule,
|
|
79
84
|
replace,
|
|
80
85
|
remove,
|
|
81
86
|
augment,
|
|
@@ -85,4 +90,4 @@ export const withPlugins = (root, plugins = [], augmentations = []) => {
|
|
|
85
90
|
config,
|
|
86
91
|
augmentation: (props) => augmentations.reduce((acc, augmentation) => augmentation(acc), props),
|
|
87
92
|
};
|
|
88
|
-
}
|
|
93
|
+
}
|
package/dist/core/consts.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export declare const MODULE_CAROUSEL = "carousel";
|
|
2
2
|
export declare const MODULE_CONTROLLER = "controller";
|
|
3
|
-
export declare const MODULE_CORE = "core";
|
|
4
3
|
export declare const MODULE_NAVIGATION = "navigation";
|
|
5
4
|
export declare const MODULE_NO_SCROLL = "no-scroll";
|
|
6
5
|
export declare const MODULE_PORTAL = "portal";
|
|
6
|
+
export declare const MODULE_ROOT = "root";
|
|
7
7
|
export declare const MODULE_TOOLBAR = "toolbar";
|
|
8
|
-
export declare const PLUGIN_CAPTIONS = "captions";
|
|
9
8
|
export declare const PLUGIN_FULLSCREEN = "fullscreen";
|
|
10
9
|
export declare const PLUGIN_INLINE = "inline";
|
|
11
10
|
export declare const PLUGIN_SLIDESHOW = "slideshow";
|
|
@@ -22,8 +21,6 @@ export declare const ACTIVE_SLIDE_LOADING: "active-slide-loading";
|
|
|
22
21
|
export declare const ACTIVE_SLIDE_PLAYING: "active-slide-playing";
|
|
23
22
|
export declare const ACTIVE_SLIDE_ERROR: "active-slide-error";
|
|
24
23
|
export declare const ACTIVE_SLIDE_COMPLETE: "active-slide-complete";
|
|
25
|
-
export declare const YARL_EVENT_BACKDROP_CLICK = "backdrop_click";
|
|
26
|
-
export declare const YARL_EVENT_TOOLBAR_WIDTH = "toolbar-width";
|
|
27
24
|
export declare const CLASS_FULLSIZE = "fullsize";
|
|
28
25
|
export declare const CLASS_FLEX_CENTER = "flex_center";
|
|
29
26
|
export declare const CLASS_NO_SCROLL = "no_scroll";
|
|
@@ -47,3 +44,4 @@ export declare const ELEMENT_BUTTON = "button";
|
|
|
47
44
|
export declare const ELEMENT_ICON = "icon";
|
|
48
45
|
export declare const IMAGE_FIT_CONTAIN = "contain";
|
|
49
46
|
export declare const IMAGE_FIT_COVER = "cover";
|
|
47
|
+
export declare const UNKNOWN_ACTION_TYPE = "Unknown action type";
|
package/dist/core/consts.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export const MODULE_CAROUSEL = "carousel";
|
|
2
2
|
export const MODULE_CONTROLLER = "controller";
|
|
3
|
-
export const MODULE_CORE = "core";
|
|
4
3
|
export const MODULE_NAVIGATION = "navigation";
|
|
5
4
|
export const MODULE_NO_SCROLL = "no-scroll";
|
|
6
5
|
export const MODULE_PORTAL = "portal";
|
|
6
|
+
export const MODULE_ROOT = "root";
|
|
7
7
|
export const MODULE_TOOLBAR = "toolbar";
|
|
8
|
-
export const PLUGIN_CAPTIONS = "captions";
|
|
9
8
|
export const PLUGIN_FULLSCREEN = "fullscreen";
|
|
10
9
|
export const PLUGIN_INLINE = "inline";
|
|
11
10
|
export const PLUGIN_SLIDESHOW = "slideshow";
|
|
@@ -21,8 +20,6 @@ export const ACTIVE_SLIDE_LOADING = activeSlideStatus(SLIDE_STATUS_LOADING);
|
|
|
21
20
|
export const ACTIVE_SLIDE_PLAYING = activeSlideStatus(SLIDE_STATUS_PLAYING);
|
|
22
21
|
export const ACTIVE_SLIDE_ERROR = activeSlideStatus(SLIDE_STATUS_ERROR);
|
|
23
22
|
export const ACTIVE_SLIDE_COMPLETE = activeSlideStatus(SLIDE_STATUS_COMPLETE);
|
|
24
|
-
export const YARL_EVENT_BACKDROP_CLICK = "backdrop_click";
|
|
25
|
-
export const YARL_EVENT_TOOLBAR_WIDTH = "toolbar-width";
|
|
26
23
|
export const CLASS_FULLSIZE = "fullsize";
|
|
27
24
|
export const CLASS_FLEX_CENTER = "flex_center";
|
|
28
25
|
export const CLASS_NO_SCROLL = "no_scroll";
|
|
@@ -46,3 +43,4 @@ export const ELEMENT_BUTTON = "button";
|
|
|
46
43
|
export const ELEMENT_ICON = "icon";
|
|
47
44
|
export const IMAGE_FIT_CONTAIN = "contain";
|
|
48
45
|
export const IMAGE_FIT_COVER = "cover";
|
|
46
|
+
export const UNKNOWN_ACTION_TYPE = "Unknown action type";
|
|
@@ -3,14 +3,15 @@ export interface EventTypes {
|
|
|
3
3
|
}
|
|
4
4
|
export type Topic = keyof EventTypes;
|
|
5
5
|
export type Event<T extends Topic> = EventTypes[T];
|
|
6
|
-
export type Callback<T extends Topic> = (event
|
|
6
|
+
export type Callback<T extends Topic> = (...args: Event<T> extends void ? [] : [event: Event<T>]) => void;
|
|
7
7
|
export type Subscribe = <T extends Topic>(topic: T, callback: Callback<T>) => () => void;
|
|
8
8
|
export type Unsubscribe = <T extends Topic>(topic: T, callback: Callback<T>) => void;
|
|
9
|
-
export type Publish = <T extends Topic>(topic: T, event
|
|
9
|
+
export type Publish = <T extends Topic>(...args: Event<T> extends void ? [topic: T] : [topic: T, event: Event<T>]) => void;
|
|
10
10
|
export type EventsContextType = {
|
|
11
11
|
subscribe: Subscribe;
|
|
12
12
|
unsubscribe: Unsubscribe;
|
|
13
13
|
publish: Publish;
|
|
14
14
|
};
|
|
15
|
+
export declare const EventsContext: React.Context<EventsContextType | null>;
|
|
15
16
|
export declare const useEvents: () => EventsContextType;
|
|
16
17
|
export declare function EventsProvider({ children }: React.PropsWithChildren): JSX.Element;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { makeUseContext } from "../utils.js";
|
|
3
|
-
const EventsContext = React.createContext(null);
|
|
3
|
+
export const EventsContext = React.createContext(null);
|
|
4
4
|
export const useEvents = makeUseContext("useEvents", "EventsContext", EventsContext);
|
|
5
5
|
export function EventsProvider({ children }) {
|
|
6
6
|
const [subscriptions] = React.useState({});
|
|
7
7
|
React.useEffect(() => () => {
|
|
8
|
-
Object.keys(subscriptions).forEach((
|
|
8
|
+
Object.keys(subscriptions).forEach((topic) => delete subscriptions[topic]);
|
|
9
9
|
}, [subscriptions]);
|
|
10
10
|
const context = React.useMemo(() => {
|
|
11
11
|
const unsubscribe = (topic, callback) => {
|
|
@@ -19,7 +19,7 @@ export function EventsProvider({ children }) {
|
|
|
19
19
|
subscriptions[topic].push(callback);
|
|
20
20
|
return () => unsubscribe(topic, callback);
|
|
21
21
|
};
|
|
22
|
-
const publish = (topic, event) => {
|
|
22
|
+
const publish = (...[topic, event]) => {
|
|
23
23
|
var _a;
|
|
24
24
|
(_a = subscriptions[topic]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(event));
|
|
25
25
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ComponentProps } from "../../types.js";
|
|
3
|
+
export type LightboxPropsContextType = Omit<ComponentProps, "children">;
|
|
4
|
+
export declare const LightboxPropsContext: React.Context<LightboxPropsContextType | null>;
|
|
5
|
+
export declare const useLightboxProps: () => LightboxPropsContextType;
|
|
6
|
+
export declare function LightboxPropsProvider({ children, ...props }: ComponentProps): JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { makeUseContext } from "../utils.js";
|
|
3
|
+
export const LightboxPropsContext = React.createContext(null);
|
|
4
|
+
export const useLightboxProps = makeUseContext("useLightboxProps", "LightboxPropsContext", LightboxPropsContext);
|
|
5
|
+
export function LightboxPropsProvider({ children, ...props }) {
|
|
6
|
+
return React.createElement(LightboxPropsContext.Provider, { value: props }, children);
|
|
7
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** @deprecated use `animation.duration` */
|
|
6
|
-
animationDuration: number;
|
|
7
|
-
animation?: LightboxStateAction;
|
|
8
|
-
};
|
|
9
|
-
export type LightboxStateAction = {
|
|
2
|
+
import { LightboxProps, LightboxState, Slide } from "../../types.js";
|
|
3
|
+
export type LightboxStateSwipeAction = {
|
|
4
|
+
type: "swipe";
|
|
10
5
|
increment: number;
|
|
11
6
|
duration?: number;
|
|
12
7
|
easing?: string;
|
|
13
|
-
}
|
|
14
|
-
export
|
|
8
|
+
};
|
|
9
|
+
export type LightboxStateUpdateAction = {
|
|
10
|
+
type: "update";
|
|
11
|
+
slides: Slide[];
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
export type LightboxStateAction = LightboxStateSwipeAction | LightboxStateUpdateAction;
|
|
15
|
+
export type LightboxStateContextType = {
|
|
15
16
|
state: LightboxState;
|
|
16
17
|
dispatch: React.Dispatch<LightboxStateAction>;
|
|
17
18
|
};
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
export declare function LightboxStateProvider({ initialIndex, slidesCount, children }: LightboxStateProviderProps): JSX.Element;
|
|
19
|
+
export declare const LightboxStateContext: React.Context<LightboxStateContextType | null>;
|
|
20
|
+
export declare const useLightboxState: () => LightboxStateContextType;
|
|
21
|
+
export type LightboxStateProviderProps = React.PropsWithChildren<Pick<LightboxProps, "slides" | "index">>;
|
|
22
|
+
export declare function LightboxStateProvider({ slides, index, children }: LightboxStateProviderProps): JSX.Element;
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { getSlideIndex, makeUseContext } from "../utils.js";
|
|
3
|
-
|
|
3
|
+
import { UNKNOWN_ACTION_TYPE } from "../consts.js";
|
|
4
|
+
export const LightboxStateContext = React.createContext(null);
|
|
4
5
|
export const useLightboxState = makeUseContext("useLightboxState", "LightboxStateContext", LightboxStateContext);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
function reducer(state, action) {
|
|
7
|
+
switch (action.type) {
|
|
8
|
+
case "swipe": {
|
|
9
|
+
const { slides } = state;
|
|
10
|
+
const increment = (action === null || action === void 0 ? void 0 : action.increment) || 0;
|
|
11
|
+
const globalIndex = state.globalIndex + increment;
|
|
12
|
+
const currentIndex = getSlideIndex(globalIndex, slides.length);
|
|
13
|
+
const animation = increment || action.duration
|
|
14
|
+
? {
|
|
15
|
+
increment,
|
|
16
|
+
duration: action.duration,
|
|
17
|
+
easing: action.easing,
|
|
18
|
+
}
|
|
19
|
+
: undefined;
|
|
20
|
+
return { slides, currentIndex, globalIndex, animation };
|
|
21
|
+
}
|
|
22
|
+
case "update":
|
|
23
|
+
return {
|
|
24
|
+
slides: action.slides,
|
|
25
|
+
currentIndex: action.index,
|
|
26
|
+
globalIndex: action.index,
|
|
27
|
+
};
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(UNKNOWN_ACTION_TYPE);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function LightboxStateProvider({ slides, index, children }) {
|
|
33
|
+
const [state, dispatch] = React.useReducer(reducer, { slides, currentIndex: index, globalIndex: index });
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
dispatch({ type: "update", slides, index });
|
|
36
|
+
}, [slides, index]);
|
|
24
37
|
const context = React.useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
|
25
38
|
return React.createElement(LightboxStateContext.Provider, { value: context }, children);
|
|
26
39
|
}
|
|
@@ -3,5 +3,6 @@ export type TimeoutsContextType = {
|
|
|
3
3
|
setTimeout: (fn: () => void, delay?: number) => number;
|
|
4
4
|
clearTimeout: (id?: number) => void;
|
|
5
5
|
};
|
|
6
|
+
export declare const TimeoutsContext: React.Context<TimeoutsContextType | null>;
|
|
6
7
|
export declare const useTimeouts: () => TimeoutsContextType;
|
|
7
8
|
export declare function TimeoutsProvider({ children }: React.PropsWithChildren): JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
const TimeoutsContext = React.createContext(null);
|
|
2
|
+
import { makeUseContext } from "../utils.js";
|
|
3
|
+
export const TimeoutsContext = React.createContext(null);
|
|
4
4
|
export const useTimeouts = makeUseContext("useTimeouts", "TimeoutsContext", TimeoutsContext);
|
|
5
5
|
export function TimeoutsProvider({ children }) {
|
|
6
6
|
const [timeouts] = React.useState([]);
|
|
@@ -21,7 +21,7 @@ export function TimeoutsProvider({ children }) {
|
|
|
21
21
|
return id;
|
|
22
22
|
};
|
|
23
23
|
const clearTimeout = (id) => {
|
|
24
|
-
if (
|
|
24
|
+
if (id !== undefined) {
|
|
25
25
|
removeTimeout(id);
|
|
26
26
|
window.clearTimeout(id);
|
|
27
27
|
}
|
|
@@ -9,4 +9,7 @@ export type ComputeAnimation<T> = (snapshot: T, rect: DOMRect, translate: {
|
|
|
9
9
|
easing?: string;
|
|
10
10
|
onfinish?: () => void;
|
|
11
11
|
} | undefined;
|
|
12
|
-
export declare function useAnimation<T>(nodeRef: React.RefObject<HTMLElement | null>, computeAnimation: ComputeAnimation<T>):
|
|
12
|
+
export declare function useAnimation<T>(nodeRef: React.RefObject<HTMLElement | null>, computeAnimation: ComputeAnimation<T>): {
|
|
13
|
+
prepareAnimation: (currentSnapshot: T | undefined) => void;
|
|
14
|
+
isAnimationPlaying: () => boolean;
|
|
15
|
+
};
|
|
@@ -31,7 +31,13 @@ export function useAnimation(nodeRef, computeAnimation) {
|
|
|
31
31
|
const { keyframes, duration, easing, onfinish } = computeAnimation(snapshot.current, nodeRef.current.getBoundingClientRect(), currentTransformation(nodeRef.current)) || {};
|
|
32
32
|
if (keyframes && duration) {
|
|
33
33
|
(_a = animation.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
34
|
-
animation.current =
|
|
34
|
+
animation.current = undefined;
|
|
35
|
+
try {
|
|
36
|
+
animation.current = (_c = (_b = nodeRef.current).animate) === null || _c === void 0 ? void 0 : _c.call(_b, keyframes, { duration, easing });
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
}
|
|
35
41
|
if (animation.current) {
|
|
36
42
|
animation.current.onfinish = () => {
|
|
37
43
|
animation.current = undefined;
|
|
@@ -42,7 +48,10 @@ export function useAnimation(nodeRef, computeAnimation) {
|
|
|
42
48
|
}
|
|
43
49
|
snapshot.current = undefined;
|
|
44
50
|
});
|
|
45
|
-
return
|
|
46
|
-
|
|
51
|
+
return {
|
|
52
|
+
prepareAnimation: (currentSnapshot) => {
|
|
53
|
+
snapshot.current = currentSnapshot;
|
|
54
|
+
},
|
|
55
|
+
isAnimationPlaying: () => { var _a; return ((_a = animation.current) === null || _a === void 0 ? void 0 : _a.playState) === "running"; },
|
|
47
56
|
};
|
|
48
57
|
}
|
|
@@ -3,12 +3,12 @@ import { useLayoutEffect } from "./useLayoutEffect.js";
|
|
|
3
3
|
import { useController } from "../modules/Controller.js";
|
|
4
4
|
export function useLoseFocus(disabled = false) {
|
|
5
5
|
const focused = React.useRef(disabled);
|
|
6
|
-
const {
|
|
6
|
+
const { focus } = useController();
|
|
7
7
|
useLayoutEffect(() => {
|
|
8
8
|
if (disabled) {
|
|
9
|
-
|
|
9
|
+
focus();
|
|
10
10
|
}
|
|
11
|
-
}, [disabled,
|
|
11
|
+
}, [disabled, focus]);
|
|
12
12
|
const onFocus = React.useCallback(() => {
|
|
13
13
|
focused.current = true;
|
|
14
14
|
}, []);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ComponentProps } from "../../types.js";
|
|
3
|
-
export declare function Carousel({
|
|
3
|
+
export declare function Carousel({ carousel: { finite, preload, padding, spacing } }: ComponentProps): JSX.Element;
|
|
4
4
|
export declare const CarouselModule: import("../../types.js").Module;
|
|
@@ -3,40 +3,40 @@ import { createModule } from "../config.js";
|
|
|
3
3
|
import { clsx, composePrefix, cssClass, cssVar, isImageSlide, parseLengthPercentage } from "../utils.js";
|
|
4
4
|
import { ImageSlide } from "../components/index.js";
|
|
5
5
|
import { useController } from "./Controller.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, MODULE_CAROUSEL, YARL_EVENT_BACKDROP_CLICK } from "../consts.js";
|
|
6
|
+
import { useLightboxProps, useLightboxState } from "../contexts/index.js";
|
|
7
|
+
import { CLASS_FLEX_CENTER, CLASS_FULLSIZE, MODULE_CAROUSEL } from "../consts.js";
|
|
9
8
|
function cssPrefix(value) {
|
|
10
9
|
return composePrefix(MODULE_CAROUSEL, value);
|
|
11
10
|
}
|
|
12
11
|
function cssSlidePrefix(value) {
|
|
13
12
|
return composePrefix("slide", value);
|
|
14
13
|
}
|
|
15
|
-
function CarouselSlide({ slide, offset
|
|
14
|
+
function CarouselSlide({ slide, offset }) {
|
|
16
15
|
const containerRef = React.useRef(null);
|
|
17
|
-
const { publish } = useEvents();
|
|
18
16
|
const { currentIndex } = useLightboxState().state;
|
|
19
|
-
const {
|
|
17
|
+
const { slideRect, close } = useController();
|
|
18
|
+
const { render, carousel: { imageFit }, on: { click: onClick }, controller: { closeOnBackdropClick }, } = useLightboxProps();
|
|
20
19
|
const renderSlide = () => {
|
|
21
20
|
var _a, _b, _c, _d;
|
|
22
|
-
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, slide, offset, rect);
|
|
21
|
+
let rendered = (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, { slide, offset, rect: slideRect });
|
|
23
22
|
if (!rendered && isImageSlide(slide)) {
|
|
24
|
-
rendered = (React.createElement(ImageSlide, { slide: slide, offset: offset, render: render, rect:
|
|
23
|
+
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 }));
|
|
25
24
|
}
|
|
26
25
|
return rendered ? (React.createElement(React.Fragment, null, (_b = render.slideHeader) === null || _b === void 0 ? void 0 :
|
|
27
|
-
_b.call(render, slide),
|
|
28
|
-
((_c = render.slideContainer) !== null && _c !== void 0 ? _c : ((
|
|
29
|
-
_d.call(render, slide))) : null;
|
|
26
|
+
_b.call(render, { slide }),
|
|
27
|
+
((_c = render.slideContainer) !== null && _c !== void 0 ? _c : (({ children }) => children))({ slide, children: rendered }), (_d = render.slideFooter) === null || _d === void 0 ? void 0 :
|
|
28
|
+
_d.call(render, { slide }))) : null;
|
|
30
29
|
};
|
|
31
30
|
const handleBackdropClick = (event) => {
|
|
32
31
|
const container = containerRef.current;
|
|
33
32
|
const target = event.target instanceof HTMLElement ? event.target : undefined;
|
|
34
|
-
if (
|
|
33
|
+
if (closeOnBackdropClick &&
|
|
34
|
+
target &&
|
|
35
35
|
container &&
|
|
36
36
|
(target === container ||
|
|
37
37
|
(Array.from(container.children).find((x) => x === target) &&
|
|
38
38
|
target.classList.contains(cssClass(CLASS_FULLSIZE))))) {
|
|
39
|
-
|
|
39
|
+
close();
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
return (React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssSlidePrefix()), offset === 0 && cssClass(cssSlidePrefix("current")), cssClass(CLASS_FLEX_CENTER)), onClick: handleBackdropClick }, renderSlide()));
|
|
@@ -44,26 +44,21 @@ function CarouselSlide({ slide, offset, rect }) {
|
|
|
44
44
|
function Placeholder() {
|
|
45
45
|
return React.createElement("div", { className: cssClass("slide") });
|
|
46
46
|
}
|
|
47
|
-
export function Carousel({
|
|
48
|
-
const { currentIndex, globalIndex } = useLightboxState().state;
|
|
49
|
-
const { setCarouselRef
|
|
47
|
+
export function Carousel({ carousel: { finite, preload, padding, spacing } }) {
|
|
48
|
+
const { slides, currentIndex, globalIndex } = useLightboxState().state;
|
|
49
|
+
const { setCarouselRef } = useController();
|
|
50
50
|
const spacingValue = parseLengthPercentage(spacing);
|
|
51
51
|
const paddingValue = parseLengthPercentage(padding);
|
|
52
|
-
const paddingPixels = paddingValue.percent !== undefined ? (containerRect.width / 100) * paddingValue.percent : paddingValue.pixel;
|
|
53
|
-
const rect = {
|
|
54
|
-
width: Math.max(containerRect.width - 2 * paddingPixels, 0),
|
|
55
|
-
height: Math.max(containerRect.height - 2 * paddingPixels, 0),
|
|
56
|
-
};
|
|
57
52
|
const items = [];
|
|
58
53
|
if ((slides === null || slides === void 0 ? void 0 : slides.length) > 0) {
|
|
59
54
|
for (let i = currentIndex - preload; i < currentIndex; i += 1) {
|
|
60
55
|
const key = globalIndex + i - currentIndex;
|
|
61
|
-
items.push(!finite || i >= 0 ? (React.createElement(CarouselSlide, { key: key, slide: slides[(i + preload * slides.length) % slides.length],
|
|
56
|
+
items.push(!finite || i >= 0 ? (React.createElement(CarouselSlide, { key: key, slide: slides[(i + preload * slides.length) % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
|
|
62
57
|
}
|
|
63
|
-
items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex],
|
|
58
|
+
items.push(React.createElement(CarouselSlide, { key: globalIndex, slide: slides[currentIndex], offset: 0 }));
|
|
64
59
|
for (let i = currentIndex + 1; i <= currentIndex + preload; i += 1) {
|
|
65
60
|
const key = globalIndex + i - currentIndex;
|
|
66
|
-
items.push(!finite || i <= slides.length - 1 ? (React.createElement(CarouselSlide, { key: key, slide: slides[i % slides.length],
|
|
61
|
+
items.push(!finite || i <= slides.length - 1 ? (React.createElement(CarouselSlide, { key: key, slide: slides[i % slides.length], offset: i - currentIndex })) : (React.createElement(Placeholder, { key: key })));
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
return (React.createElement("div", { ref: setCarouselRef, className: clsx(cssClass(cssPrefix()), items.length > 0 && cssClass(cssPrefix("with_slides"))), style: {
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { ComponentProps, ContainerRect } from "../../types.js";
|
|
2
|
+
import { Callback, ComponentProps, ContainerRect, ControllerRef, NavigationAction } from "../../types.js";
|
|
3
3
|
import { SubscribeSensors } from "../hooks/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE
|
|
6
|
-
|
|
7
|
-
count?: number;
|
|
8
|
-
};
|
|
9
|
-
declare module "../" {
|
|
4
|
+
import { LightboxStateSwipeAction } from "../contexts/index.js";
|
|
5
|
+
import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE } from "../consts.js";
|
|
6
|
+
declare module "../index.js" {
|
|
10
7
|
interface EventTypes {
|
|
11
|
-
[ACTION_PREV]: NavigationAction;
|
|
12
|
-
[ACTION_NEXT]: NavigationAction;
|
|
13
|
-
[ACTION_SWIPE]:
|
|
8
|
+
[ACTION_PREV]: NavigationAction | void;
|
|
9
|
+
[ACTION_NEXT]: NavigationAction | void;
|
|
10
|
+
[ACTION_SWIPE]: LightboxStateSwipeAction;
|
|
14
11
|
[ACTION_CLOSE]: void;
|
|
15
|
-
[YARL_EVENT_BACKDROP_CLICK]: void;
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
export type ControllerContextType = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
transferFocus: () => void;
|
|
14
|
+
export type ControllerContextType = Pick<ControllerRef, "prev" | "next" | "close"> & {
|
|
15
|
+
focus: Callback;
|
|
16
|
+
slideRect: ContainerRect;
|
|
22
17
|
containerRect: ContainerRect;
|
|
18
|
+
subscribeSensors: SubscribeSensors<HTMLDivElement>;
|
|
23
19
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
24
20
|
setCarouselRef: React.Ref<HTMLDivElement>;
|
|
21
|
+
toolbarWidth: number | undefined;
|
|
22
|
+
setToolbarWidth: (width: number | undefined) => void;
|
|
25
23
|
};
|
|
26
|
-
export declare const
|
|
24
|
+
export declare const ControllerContext: React.Context<ControllerContextType | null>;
|
|
25
|
+
export declare const useController: () => NonNullable<ControllerContextType>;
|
|
27
26
|
export declare function Controller({ children, ...props }: ComponentProps): JSX.Element;
|
|
28
27
|
export declare const ControllerModule: import("../../types.js").Module;
|