@placetopay/lightbox-sdk 0.3.3 → 1.2.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/{LightboxClient → LightboxSdk}/assemblers.d.ts +0 -0
- package/dist/{LightboxClient → LightboxSdk}/assemblers.js +22 -12
- package/dist/LightboxSdk/index.d.ts +12 -0
- package/dist/{LightboxClient → LightboxSdk}/index.js +22 -1
- package/dist/constants.d.ts +4 -4
- package/dist/constants.js +4 -4
- package/dist/css/styles.css +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/types.d.ts +0 -12
- package/package.json +1 -1
- package/dist/LightboxApp/index.d.ts +0 -10
- package/dist/LightboxApp/index.js +0 -20
- package/dist/LightboxClient/index.d.ts +0 -4
|
File without changes
|
|
@@ -4,27 +4,33 @@ export const mountListener = (callbacks, styles) => {
|
|
|
4
4
|
if (!callbacks)
|
|
5
5
|
return;
|
|
6
6
|
const listener = (event) => {
|
|
7
|
-
var _a, _b;
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
let receivedStyles;
|
|
8
9
|
switch (event.data.type) {
|
|
9
10
|
case LightboxAppEvents.CLOSE:
|
|
10
|
-
unmountLightbox(listener);
|
|
11
|
+
unmountLightbox(listener, (_a = event.data.payload) !== null && _a !== void 0 ? _a : event.origin);
|
|
11
12
|
break;
|
|
12
|
-
case LightboxAppEvents.
|
|
13
|
-
(
|
|
13
|
+
case LightboxAppEvents.CLOSE_OR_REDIRECT:
|
|
14
|
+
unmountLightbox(listener, event.origin);
|
|
14
15
|
break;
|
|
15
16
|
case LightboxAppEvents.SEND_STYLES:
|
|
16
|
-
|
|
17
|
+
receivedStyles = event.data.payload;
|
|
18
|
+
mountStyles(Object.assign(Object.assign(Object.assign({}, receivedStyles), styles), { background: Object.assign(Object.assign({}, receivedStyles === null || receivedStyles === void 0 ? void 0 : receivedStyles.background), styles.background) }));
|
|
17
19
|
break;
|
|
18
20
|
case LightboxAppEvents.HIDE_CLOSE_BUTTON:
|
|
19
21
|
(_b = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _b === void 0 ? void 0 : _b.remove();
|
|
20
22
|
break;
|
|
23
|
+
default:
|
|
24
|
+
(_c = callbacks[event.data.type]) === null || _c === void 0 ? void 0 : _c.call(callbacks, event.data.payload);
|
|
25
|
+
break;
|
|
21
26
|
}
|
|
22
27
|
};
|
|
23
28
|
globalThis.addEventListener('message', listener);
|
|
24
29
|
};
|
|
25
30
|
export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
26
31
|
const wrapper = document.createElement('div');
|
|
27
|
-
wrapper.id =
|
|
32
|
+
wrapper.id = new URL(url).origin;
|
|
33
|
+
wrapper.className = ElementIds.WRAPPER_ID;
|
|
28
34
|
const iframe = document.createElement('iframe');
|
|
29
35
|
iframe.src = url;
|
|
30
36
|
iframe.id = ElementIds.IFRAME_ID;
|
|
@@ -35,7 +41,7 @@ export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
|
35
41
|
const closeButton = document.createElement('button');
|
|
36
42
|
closeButton.id = ElementIds.CLOSE_BUTTON_ID;
|
|
37
43
|
closeButton.addEventListener('click', () => {
|
|
38
|
-
globalThis.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
44
|
+
globalThis.postMessage({ type: LightboxAppEvents.CLOSE, payload: new URL(url).origin }, '*');
|
|
39
45
|
});
|
|
40
46
|
const closeButtonContent = document.createElement('span');
|
|
41
47
|
closeButtonContent.classList.add('placetopay-close-button-content');
|
|
@@ -60,9 +66,13 @@ const mountStyles = (styles) => {
|
|
|
60
66
|
width = Dimensions[styles.dimension.toUpperCase()].width;
|
|
61
67
|
document.documentElement.style.setProperty(Styles.MAX_WIDTH, `${width.toString()}px`);
|
|
62
68
|
};
|
|
63
|
-
const unmountLightbox = (listener) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
const unmountLightbox = (listener, origin) => {
|
|
70
|
+
const element = document.getElementById(origin);
|
|
71
|
+
if (element) {
|
|
72
|
+
element.remove();
|
|
73
|
+
globalThis.removeEventListener('message', listener);
|
|
74
|
+
document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
throw new Error(`Frame from "${origin}" not found`);
|
|
68
78
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InitOptions, LightboxInstance, LightboxStyles } from '../types';
|
|
2
|
+
export declare const LightboxSdk: {
|
|
3
|
+
isInside: () => boolean;
|
|
4
|
+
close: (frame?: string) => void;
|
|
5
|
+
sendStyles: (styles: LightboxStyles) => void;
|
|
6
|
+
hideCloseButton: () => void;
|
|
7
|
+
closeOrRedirect: (url?: string) => void;
|
|
8
|
+
emit: (type: string, payload: unknown) => {
|
|
9
|
+
close: (frame?: string) => void;
|
|
10
|
+
};
|
|
11
|
+
init: (url: string, options?: InitOptions) => LightboxInstance;
|
|
12
|
+
};
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { LightboxAppEvents } from '../constants';
|
|
1
2
|
import { redirectBasedOnDriver } from '../helpers';
|
|
2
3
|
import { mountLightbox, mountListener } from './assemblers';
|
|
3
|
-
export const
|
|
4
|
+
export const LightboxSdk = {
|
|
5
|
+
isInside: () => globalThis.location !== globalThis.parent.location,
|
|
6
|
+
close: (frame) => {
|
|
7
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE, payload: frame }, '*');
|
|
8
|
+
},
|
|
9
|
+
sendStyles: (styles) => {
|
|
10
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
11
|
+
},
|
|
12
|
+
hideCloseButton: () => {
|
|
13
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
14
|
+
},
|
|
15
|
+
closeOrRedirect: (url) => {
|
|
16
|
+
if (!url || LightboxSdk.isInside())
|
|
17
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE_OR_REDIRECT }, '*');
|
|
18
|
+
else
|
|
19
|
+
globalThis.location.href = url;
|
|
20
|
+
},
|
|
21
|
+
emit: (type, payload) => {
|
|
22
|
+
globalThis.parent.postMessage({ type, payload }, '*');
|
|
23
|
+
return { close: LightboxSdk.close };
|
|
24
|
+
},
|
|
4
25
|
init: (url, options) => {
|
|
5
26
|
var _a, _b, _c, _d;
|
|
6
27
|
const lightbox = {
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ export declare enum ElementIds {
|
|
|
5
5
|
STYLES_ID = "placetopay-lightbox"
|
|
6
6
|
}
|
|
7
7
|
export declare enum LightboxAppEvents {
|
|
8
|
-
CLOSE = "close",
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
CLOSE = "lightbox:close",
|
|
9
|
+
SEND_STYLES = "lightbox:sendStyles",
|
|
10
|
+
HIDE_CLOSE_BUTTON = "lightbox:hideCloseButton",
|
|
11
|
+
CLOSE_OR_REDIRECT = "lightbox:closeOrRedirect"
|
|
12
12
|
}
|
|
13
13
|
export declare enum Styles {
|
|
14
14
|
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
package/dist/constants.js
CHANGED
|
@@ -7,10 +7,10 @@ export var ElementIds;
|
|
|
7
7
|
})(ElementIds || (ElementIds = {}));
|
|
8
8
|
export var LightboxAppEvents;
|
|
9
9
|
(function (LightboxAppEvents) {
|
|
10
|
-
LightboxAppEvents["CLOSE"] = "close";
|
|
11
|
-
LightboxAppEvents["
|
|
12
|
-
LightboxAppEvents["
|
|
13
|
-
LightboxAppEvents["
|
|
10
|
+
LightboxAppEvents["CLOSE"] = "lightbox:close";
|
|
11
|
+
LightboxAppEvents["SEND_STYLES"] = "lightbox:sendStyles";
|
|
12
|
+
LightboxAppEvents["HIDE_CLOSE_BUTTON"] = "lightbox:hideCloseButton";
|
|
13
|
+
LightboxAppEvents["CLOSE_OR_REDIRECT"] = "lightbox:closeOrRedirect";
|
|
14
14
|
})(LightboxAppEvents || (LightboxAppEvents = {}));
|
|
15
15
|
export var Styles;
|
|
16
16
|
(function (Styles) {
|
package/dist/css/styles.css
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { LightboxAppEvents } from './constants';
|
|
2
1
|
export declare type ClientCallback = (data: unknown) => void;
|
|
3
2
|
export declare type ClientCallbacks = {
|
|
4
3
|
[key: string]: ClientCallback | undefined;
|
|
@@ -26,14 +25,3 @@ export declare type ApiStructure = {
|
|
|
26
25
|
export declare type LightboxInstance = Required<InitOptions> & {
|
|
27
26
|
open: () => void;
|
|
28
27
|
};
|
|
29
|
-
export declare type LightboxEvents = {
|
|
30
|
-
type: LightboxAppEvents.CLOSE;
|
|
31
|
-
} | {
|
|
32
|
-
type: LightboxAppEvents.EMIT;
|
|
33
|
-
payload: ApiStructure;
|
|
34
|
-
} | {
|
|
35
|
-
type: LightboxAppEvents.SEND_STYLES;
|
|
36
|
-
payload: LightboxStyles;
|
|
37
|
-
} | {
|
|
38
|
-
type: LightboxAppEvents.HIDE_CLOSE_BUTTON;
|
|
39
|
-
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { LightboxStyles } from '../types';
|
|
2
|
-
export declare const LightboxApp: {
|
|
3
|
-
close: (url?: string) => void;
|
|
4
|
-
isInside: () => boolean;
|
|
5
|
-
emit: (type: string, payload: unknown) => {
|
|
6
|
-
close: (url?: string) => void;
|
|
7
|
-
};
|
|
8
|
-
sendStyles: (styles: LightboxStyles) => void;
|
|
9
|
-
hideCloseButton: () => void;
|
|
10
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LightboxAppEvents } from '../constants';
|
|
2
|
-
export const LightboxApp = {
|
|
3
|
-
close: (url) => {
|
|
4
|
-
if (!url || LightboxApp.isInside())
|
|
5
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
6
|
-
else
|
|
7
|
-
globalThis.location.href = url;
|
|
8
|
-
},
|
|
9
|
-
isInside: () => globalThis.location !== globalThis.parent.location,
|
|
10
|
-
emit: (type, payload) => {
|
|
11
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.EMIT, payload: { type, payload } }, '*');
|
|
12
|
-
return { close: LightboxApp.close };
|
|
13
|
-
},
|
|
14
|
-
sendStyles: (styles) => {
|
|
15
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
16
|
-
},
|
|
17
|
-
hideCloseButton: () => {
|
|
18
|
-
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
19
|
-
},
|
|
20
|
-
};
|