@placetopay/lightbox-sdk 0.3.3 → 1.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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LightboxStyles } from '../types';
|
|
2
2
|
export declare const LightboxApp: {
|
|
3
|
-
close: (url?: string) => void;
|
|
4
3
|
isInside: () => boolean;
|
|
4
|
+
sendStyles: (styles: LightboxStyles) => void;
|
|
5
|
+
hideCloseButton: () => void;
|
|
6
|
+
close: (url?: string) => void;
|
|
5
7
|
emit: (type: string, payload: unknown) => {
|
|
6
8
|
close: (url?: string) => void;
|
|
7
9
|
};
|
|
8
|
-
sendStyles: (styles: LightboxStyles) => void;
|
|
9
|
-
hideCloseButton: () => void;
|
|
10
10
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { LightboxAppEvents } from '../constants';
|
|
2
2
|
export const LightboxApp = {
|
|
3
|
+
isInside: () => globalThis.location !== globalThis.parent.location,
|
|
4
|
+
sendStyles: (styles) => {
|
|
5
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
6
|
+
},
|
|
7
|
+
hideCloseButton: () => {
|
|
8
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
9
|
+
},
|
|
3
10
|
close: (url) => {
|
|
4
11
|
if (!url || LightboxApp.isInside())
|
|
5
12
|
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
6
13
|
else
|
|
7
14
|
globalThis.location.href = url;
|
|
8
15
|
},
|
|
9
|
-
isInside: () => globalThis.location !== globalThis.parent.location,
|
|
10
16
|
emit: (type, payload) => {
|
|
11
|
-
globalThis.parent.postMessage({ type
|
|
17
|
+
globalThis.parent.postMessage({ type, payload }, '*');
|
|
12
18
|
return { close: LightboxApp.close };
|
|
13
19
|
},
|
|
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
20
|
};
|
|
@@ -5,18 +5,20 @@ export const mountListener = (callbacks, styles) => {
|
|
|
5
5
|
return;
|
|
6
6
|
const listener = (event) => {
|
|
7
7
|
var _a, _b;
|
|
8
|
+
let receivedStyles;
|
|
8
9
|
switch (event.data.type) {
|
|
9
10
|
case LightboxAppEvents.CLOSE:
|
|
10
11
|
unmountLightbox(listener);
|
|
11
12
|
break;
|
|
12
|
-
case LightboxAppEvents.EMIT:
|
|
13
|
-
(_a = callbacks[event.data.payload.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.payload.payload);
|
|
14
|
-
break;
|
|
15
13
|
case LightboxAppEvents.SEND_STYLES:
|
|
16
|
-
|
|
14
|
+
receivedStyles = event.data.payload;
|
|
15
|
+
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
16
|
break;
|
|
18
17
|
case LightboxAppEvents.HIDE_CLOSE_BUTTON:
|
|
19
|
-
(
|
|
18
|
+
(_a = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
(_b = callbacks[event.data.type]) === null || _b === void 0 ? void 0 : _b.call(callbacks, event.data.payload);
|
|
20
22
|
break;
|
|
21
23
|
}
|
|
22
24
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,10 +5,9 @@ export declare enum ElementIds {
|
|
|
5
5
|
STYLES_ID = "placetopay-lightbox"
|
|
6
6
|
}
|
|
7
7
|
export declare enum LightboxAppEvents {
|
|
8
|
-
CLOSE = "close",
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
HIDE_CLOSE_BUTTON = "hideCloseButton"
|
|
8
|
+
CLOSE = "lightbox:close",
|
|
9
|
+
SEND_STYLES = "lightbox:sendStyles",
|
|
10
|
+
HIDE_CLOSE_BUTTON = "lightbox:hideCloseButton"
|
|
12
11
|
}
|
|
13
12
|
export declare enum Styles {
|
|
14
13
|
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
package/dist/constants.js
CHANGED
|
@@ -7,10 +7,9 @@ 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["HIDE_CLOSE_BUTTON"] = "hideCloseButton";
|
|
10
|
+
LightboxAppEvents["CLOSE"] = "lightbox:close";
|
|
11
|
+
LightboxAppEvents["SEND_STYLES"] = "lightbox:sendStyles";
|
|
12
|
+
LightboxAppEvents["HIDE_CLOSE_BUTTON"] = "lightbox:hideCloseButton";
|
|
14
13
|
})(LightboxAppEvents || (LightboxAppEvents = {}));
|
|
15
14
|
export var Styles;
|
|
16
15
|
(function (Styles) {
|
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