@placetopay/lightbox-sdk 0.2.1 → 0.3.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/README.md +18 -0
- package/dist/LightboxApp/index.d.ts +5 -1
- package/dist/LightboxApp/index.js +12 -5
- package/dist/LightboxClient/assemblers.d.ts +2 -2
- package/dist/LightboxClient/assemblers.js +43 -39
- package/dist/LightboxClient/index.js +12 -14
- package/dist/config.js +1 -1
- package/dist/constants.d.ts +15 -12
- package/dist/constants.js +17 -12
- package/dist/css/close_button.css +34 -0
- package/dist/{styles → css}/styles.css +2 -0
- package/dist/helpers.js +1 -1
- package/dist/types.d.ts +16 -9
- package/package.json +1 -20
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Lightbox-sdk
|
|
2
|
+
Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors.
|
|
3
|
+
|
|
4
|
+
The library consists of 2 parts:
|
|
5
|
+
|
|
6
|
+
- LightboxApp
|
|
7
|
+
- LightboxClient
|
|
8
|
+
|
|
9
|
+
If you have a site A, and within it you want to display a site B using Lightbox-sdk:
|
|
10
|
+
|
|
11
|
+
On site A the LightboxClient will be used (site that will display a lightbox)
|
|
12
|
+
|
|
13
|
+
- It will define which site will be displayed in the lightbox
|
|
14
|
+
- It will define the callbacks for each lightbox event
|
|
15
|
+
|
|
16
|
+
On site B LightboxApp will be used (site that will be shown in a lightbox)
|
|
17
|
+
|
|
18
|
+
- Define the event emission logic
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ClientStyles } from '../types';
|
|
2
2
|
export declare const LightboxApp: {
|
|
3
|
-
|
|
3
|
+
close: () => void;
|
|
4
|
+
emit: (type: string, payload: unknown) => {
|
|
5
|
+
close: () => void;
|
|
6
|
+
};
|
|
4
7
|
sendStyles: (styles: ClientStyles) => void;
|
|
8
|
+
hideCloseButton: () => void;
|
|
5
9
|
};
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { LightboxAppEvents } from '../constants';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
globalThis.parent.postMessage({
|
|
2
|
+
export const LightboxApp = {
|
|
3
|
+
close: () => {
|
|
4
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
5
5
|
},
|
|
6
|
-
|
|
7
|
-
globalThis.parent.postMessage({
|
|
6
|
+
emit: (type, payload) => {
|
|
7
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.EMIT, payload: { type, payload } }, '*');
|
|
8
|
+
return { close: LightboxApp.close };
|
|
9
|
+
},
|
|
10
|
+
sendStyles: (styles) => {
|
|
11
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.SEND_STYLES, payload: styles }, '*');
|
|
12
|
+
},
|
|
13
|
+
hideCloseButton: () => {
|
|
14
|
+
globalThis.parent.postMessage({ type: LightboxAppEvents.HIDE_CLOSE_BUTTON }, '*');
|
|
8
15
|
},
|
|
9
16
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ClientCallbacks, ClientStyles } from '../types';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const mountListener: (callbacks: ClientCallbacks, styles: ClientStyles) => void;
|
|
3
|
+
export declare const mountLightbox: (url: string, styles: ClientStyles, closeButtonEnabled: boolean) => void;
|
|
@@ -1,62 +1,66 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { Config } from '../config';
|
|
13
2
|
import { Styles, ElementIds, Dimensions, LightboxAppEvents } from '../constants';
|
|
14
|
-
export
|
|
3
|
+
export const mountListener = (callbacks, styles) => {
|
|
15
4
|
if (!callbacks)
|
|
16
5
|
return;
|
|
17
|
-
|
|
18
|
-
var _a;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
const listener = (event) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
switch (event.data.type) {
|
|
9
|
+
case LightboxAppEvents.CLOSE:
|
|
10
|
+
unmountLightbox(listener);
|
|
11
|
+
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
|
+
case LightboxAppEvents.SEND_STYLES:
|
|
16
|
+
mountStyles(Object.assign(Object.assign(Object.assign({}, event.data.payload), styles), { background: Object.assign(Object.assign({}, event.data.payload.background), styles.background) }));
|
|
17
|
+
break;
|
|
18
|
+
case LightboxAppEvents.HIDE_CLOSE_BUTTON:
|
|
19
|
+
(_b = document.getElementById(ElementIds.CLOSE_BUTTON_ID)) === null || _b === void 0 ? void 0 : _b.remove();
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
29
22
|
};
|
|
30
|
-
globalThis.addEventListener('message',
|
|
31
|
-
globalThis.addEventListener('message', stylesListener);
|
|
23
|
+
globalThis.addEventListener('message', listener);
|
|
32
24
|
};
|
|
33
|
-
export
|
|
34
|
-
|
|
25
|
+
export const mountLightbox = (url, styles, closeButtonEnabled) => {
|
|
26
|
+
const wrapper = document.createElement('div');
|
|
35
27
|
wrapper.id = ElementIds.WRAPPER_ID;
|
|
36
|
-
|
|
28
|
+
const iframe = document.createElement('iframe');
|
|
37
29
|
iframe.src = url;
|
|
38
30
|
iframe.id = ElementIds.IFRAME_ID;
|
|
39
31
|
mountStyles(styles);
|
|
40
32
|
document.body.appendChild(wrapper);
|
|
41
33
|
wrapper.appendChild(iframe);
|
|
34
|
+
if (closeButtonEnabled) {
|
|
35
|
+
const closeButton = document.createElement('button');
|
|
36
|
+
closeButton.id = ElementIds.CLOSE_BUTTON_ID;
|
|
37
|
+
closeButton.addEventListener('click', () => {
|
|
38
|
+
globalThis.postMessage({ type: LightboxAppEvents.CLOSE }, '*');
|
|
39
|
+
});
|
|
40
|
+
const closeButtonContent = document.createElement('span');
|
|
41
|
+
closeButtonContent.classList.add('placetopay-close-button-content');
|
|
42
|
+
closeButtonContent.textContent = 'x';
|
|
43
|
+
closeButton.appendChild(closeButtonContent);
|
|
44
|
+
wrapper.appendChild(closeButton);
|
|
45
|
+
}
|
|
42
46
|
};
|
|
43
|
-
|
|
47
|
+
const mountStyles = (styles) => {
|
|
44
48
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
45
|
-
|
|
49
|
+
const background = (_d = (_c = (_b = (_a = styles.background) === null || _a === void 0 ? void 0 : _a.color) === null || _b === void 0 ? void 0 : _b.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b).substring(1).match(/.{2}/g)) === null || _c === void 0 ? void 0 : _c.map((x) => parseInt(x, 16))) !== null && _d !== void 0 ? _d : [107, 114, 128];
|
|
46
50
|
background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
|
|
47
|
-
document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR,
|
|
48
|
-
|
|
49
|
-
document.documentElement.style.setProperty(Styles.ROUNDED,
|
|
50
|
-
|
|
51
|
+
document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, `rgb(${background.join(', ')})`);
|
|
52
|
+
const rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
|
|
53
|
+
document.documentElement.style.setProperty(Styles.ROUNDED, `${rounded.toString()}px`);
|
|
54
|
+
let height = (_h = styles.height) !== null && _h !== void 0 ? _h : Config.defaultDimension.height;
|
|
51
55
|
if (styles.dimension)
|
|
52
56
|
height = Dimensions[styles.dimension.toUpperCase()].height;
|
|
53
|
-
document.documentElement.style.setProperty(Styles.MAX_HEIGHT,
|
|
54
|
-
|
|
57
|
+
document.documentElement.style.setProperty(Styles.MAX_HEIGHT, `${height.toString()}px`);
|
|
58
|
+
let width = (_j = styles.width) !== null && _j !== void 0 ? _j : Config.defaultDimension.width;
|
|
55
59
|
if (styles.dimension)
|
|
56
60
|
width = Dimensions[styles.dimension.toUpperCase()].width;
|
|
57
|
-
document.documentElement.style.setProperty(Styles.MAX_WIDTH,
|
|
61
|
+
document.documentElement.style.setProperty(Styles.MAX_WIDTH, `${width.toString()}px`);
|
|
58
62
|
};
|
|
59
|
-
|
|
63
|
+
const unmountLightbox = (listener) => {
|
|
60
64
|
var _a;
|
|
61
65
|
(_a = document.getElementById(ElementIds.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
62
66
|
globalThis.removeEventListener('message', listener);
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { redirectBasedOnDriver } from '../helpers';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
init:
|
|
5
|
-
var _a, _b, _c;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { mountLightbox, mountListener } from './assemblers';
|
|
3
|
+
export const LightboxClient = {
|
|
4
|
+
init: (url, options) => {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
const lightbox = {
|
|
7
|
+
allowRedirects: (_a = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _a !== void 0 ? _a : true,
|
|
8
|
+
callbacks: (_b = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _b !== void 0 ? _b : {},
|
|
9
|
+
closeButton: (_c = options === null || options === void 0 ? void 0 : options.closeButton) !== null && _c !== void 0 ? _c : true,
|
|
10
|
+
styles: (_d = options === null || options === void 0 ? void 0 : options.styles) !== null && _d !== void 0 ? _d : {},
|
|
11
|
+
open: () => {
|
|
11
12
|
if (lightbox.allowRedirects)
|
|
12
13
|
redirectBasedOnDriver(url);
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
mountListener(lightbox.callbacks, lightbox.styles);
|
|
15
|
+
mountLightbox(url, lightbox.styles, lightbox.closeButton);
|
|
15
16
|
},
|
|
16
17
|
};
|
|
17
|
-
if (options === null || options === void 0 ? void 0 : options.dispatch)
|
|
18
|
-
lightbox.open();
|
|
19
|
-
console.log("lightbox-sdk | client initialized (".concat(url, ")"));
|
|
20
18
|
return lightbox;
|
|
21
19
|
},
|
|
22
20
|
};
|
package/dist/config.js
CHANGED
package/dist/constants.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
WRAPPER_ID
|
|
3
|
-
IFRAME_ID
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare enum ElementIds {
|
|
2
|
+
WRAPPER_ID = "placetopay_lightbox_wrapper",
|
|
3
|
+
IFRAME_ID = "placetopay_lightbox",
|
|
4
|
+
CLOSE_BUTTON_ID = "placetopay_close_button",
|
|
5
|
+
STYLES_ID = "placetopay-lightbox"
|
|
6
|
+
}
|
|
6
7
|
export declare enum LightboxAppEvents {
|
|
8
|
+
CLOSE = "close",
|
|
7
9
|
EMIT = "emit",
|
|
8
|
-
SEND_STYLES = "sendStyles"
|
|
10
|
+
SEND_STYLES = "sendStyles",
|
|
11
|
+
HIDE_CLOSE_BUTTON = "hideCloseButton"
|
|
12
|
+
}
|
|
13
|
+
export declare enum Styles {
|
|
14
|
+
BACKGROUND_COLOR = "--placetopay-lightbox-background-color",
|
|
15
|
+
ROUNDED = "--placetopay-lightbox-border-radius",
|
|
16
|
+
MAX_HEIGHT = "--placetopay-lightbox-max-height",
|
|
17
|
+
MAX_WIDTH = "--placetopay-lightbox-max-width"
|
|
9
18
|
}
|
|
10
|
-
export declare const Styles: {
|
|
11
|
-
BACKGROUND_COLOR: string;
|
|
12
|
-
ROUNDED: string;
|
|
13
|
-
MAX_HEIGHT: string;
|
|
14
|
-
MAX_WIDTH: string;
|
|
15
|
-
};
|
|
16
19
|
export declare const Dimensions: {
|
|
17
20
|
SM: {
|
|
18
21
|
height: number;
|
package/dist/constants.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
export var ElementIds
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export var ElementIds;
|
|
2
|
+
(function (ElementIds) {
|
|
3
|
+
ElementIds["WRAPPER_ID"] = "placetopay_lightbox_wrapper";
|
|
4
|
+
ElementIds["IFRAME_ID"] = "placetopay_lightbox";
|
|
5
|
+
ElementIds["CLOSE_BUTTON_ID"] = "placetopay_close_button";
|
|
6
|
+
ElementIds["STYLES_ID"] = "placetopay-lightbox";
|
|
7
|
+
})(ElementIds || (ElementIds = {}));
|
|
6
8
|
export var LightboxAppEvents;
|
|
7
9
|
(function (LightboxAppEvents) {
|
|
10
|
+
LightboxAppEvents["CLOSE"] = "close";
|
|
8
11
|
LightboxAppEvents["EMIT"] = "emit";
|
|
9
12
|
LightboxAppEvents["SEND_STYLES"] = "sendStyles";
|
|
13
|
+
LightboxAppEvents["HIDE_CLOSE_BUTTON"] = "hideCloseButton";
|
|
10
14
|
})(LightboxAppEvents || (LightboxAppEvents = {}));
|
|
11
|
-
export var Styles
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export var Styles;
|
|
16
|
+
(function (Styles) {
|
|
17
|
+
Styles["BACKGROUND_COLOR"] = "--placetopay-lightbox-background-color";
|
|
18
|
+
Styles["ROUNDED"] = "--placetopay-lightbox-border-radius";
|
|
19
|
+
Styles["MAX_HEIGHT"] = "--placetopay-lightbox-max-height";
|
|
20
|
+
Styles["MAX_WIDTH"] = "--placetopay-lightbox-max-width";
|
|
21
|
+
})(Styles || (Styles = {}));
|
|
22
|
+
export const Dimensions = {
|
|
18
23
|
SM: { height: 400, width: 320 },
|
|
19
24
|
MD: { height: 640, width: 512 },
|
|
20
25
|
LG: { height: 1000, width: 800 },
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* Initial design from uiverse.io by @Voxybuns */
|
|
2
|
+
#placetopay_close_button {
|
|
3
|
+
/* Variables */
|
|
4
|
+
--button_radius: 100%;
|
|
5
|
+
--button_color: #e8e8e8;
|
|
6
|
+
--button_outline_color: #000000;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
padding: 0;
|
|
9
|
+
position: absolute;
|
|
10
|
+
right: 8px;
|
|
11
|
+
top: 8px;
|
|
12
|
+
font-size: 17px;
|
|
13
|
+
font-weight: bold;
|
|
14
|
+
border: none;
|
|
15
|
+
border-radius: var(--button_radius);
|
|
16
|
+
background: var(--button_outline_color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.placetopay-close-button-content {
|
|
20
|
+
display: block;
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
border: 2px solid var(--button_outline_color);
|
|
23
|
+
border-radius: var(--button_radius);
|
|
24
|
+
padding: 2px 7px;
|
|
25
|
+
background: var(--button_color);
|
|
26
|
+
color: var(--button_outline_color);
|
|
27
|
+
transform: translateY(-0.1em);
|
|
28
|
+
transition: transform 0.1s ease;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
button:active .placetopay-close-button-content {
|
|
32
|
+
/* Push the button downwards when pressed */
|
|
33
|
+
transform: translateY(0);
|
|
34
|
+
}
|
package/dist/helpers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const redirectBasedOnDriver = (url) => {
|
|
2
2
|
if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
|
|
3
3
|
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
|
|
4
4
|
) {
|
package/dist/types.d.ts
CHANGED
|
@@ -8,25 +8,32 @@ export declare type ClientStyles = {
|
|
|
8
8
|
color?: string;
|
|
9
9
|
opacity?: number;
|
|
10
10
|
};
|
|
11
|
-
rounded?: number;
|
|
12
11
|
dimension?: 'sm' | 'md' | 'lg';
|
|
13
12
|
height?: number;
|
|
13
|
+
rounded?: number;
|
|
14
14
|
width?: number;
|
|
15
15
|
};
|
|
16
16
|
export declare type InitOptions = {
|
|
17
|
-
dispatch?: boolean;
|
|
18
|
-
callbacks?: ClientCallbacks;
|
|
19
17
|
allowRedirects?: boolean;
|
|
18
|
+
callbacks?: ClientCallbacks;
|
|
19
|
+
closeButton?: boolean;
|
|
20
20
|
styles?: ClientStyles;
|
|
21
21
|
};
|
|
22
22
|
export declare type ApiStructure = {
|
|
23
|
-
|
|
24
|
-
data: unknown;
|
|
23
|
+
payload: unknown;
|
|
25
24
|
type: string;
|
|
26
25
|
};
|
|
27
|
-
export declare type LightboxInstance = {
|
|
28
|
-
styles: ClientStyles;
|
|
29
|
-
allowRedirects: boolean;
|
|
30
|
-
callbacks: ClientCallbacks;
|
|
26
|
+
export declare type LightboxInstance = Required<InitOptions> & {
|
|
31
27
|
open: () => void;
|
|
32
28
|
};
|
|
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: ClientStyles;
|
|
37
|
+
} | {
|
|
38
|
+
type: LightboxAppEvents.HIDE_CLOSE_BUTTON;
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placetopay/lightbox-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "npm run clean-build",
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"postbuild": "copyfiles -u 1 src/**/*.css dist/",
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
-
"clean-build": "rimraf dist/",
|
|
16
|
-
"format": "npx prettier --write .",
|
|
17
|
-
"format:check": "npx prettier --check .",
|
|
18
|
-
"lint": "npx eslint --ext .ts --fix ./",
|
|
19
|
-
"lint:check": "npx eslint --ext .ts .",
|
|
20
|
-
"foli": "npm run format & npm run lint",
|
|
21
|
-
"foli:check": "npm run format:check & npm run lint:check"
|
|
22
|
-
},
|
|
23
10
|
"repository": {
|
|
24
11
|
"type": "git",
|
|
25
12
|
"url": "git+https://JuanZea@bitbucket.org/placetopay/lightbox-sdk.git"
|
|
@@ -38,12 +25,6 @@
|
|
|
38
25
|
},
|
|
39
26
|
"homepage": "https://bitbucket.org/placetopay/lightbox-sdk#readme",
|
|
40
27
|
"devDependencies": {
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
|
42
|
-
"@typescript-eslint/parser": "^5.38.1",
|
|
43
|
-
"copyfiles": "^2.4.1",
|
|
44
|
-
"eslint": "^8.24.0",
|
|
45
|
-
"prettier": "^2.7.1",
|
|
46
|
-
"rimraf": "^3.0.2",
|
|
47
28
|
"typescript": "^4.8.3"
|
|
48
29
|
}
|
|
49
30
|
}
|