@placetopay/lightbox-sdk 0.1.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/README.md +19 -0
- package/dist/lib/core/LightboxApp/index.d.ts +3 -0
- package/dist/lib/core/LightboxApp/index.js +5 -0
- package/dist/lib/core/LightboxClient/assemblers.d.ts +3 -0
- package/dist/lib/core/LightboxClient/assemblers.js +35 -0
- package/dist/lib/core/LightboxClient/index.d.ts +4 -0
- package/dist/lib/core/LightboxClient/index.js +18 -0
- package/dist/lib/core/constants.d.ts +9 -0
- package/dist/lib/core/constants.js +9 -0
- package/dist/lib/core/index.d.ts +2 -0
- package/dist/lib/core/index.js +2 -0
- package/dist/lib/core/types.d.ts +28 -0
- package/dist/lib/core/types.js +1 -0
- package/dist/lib/styles/styles.css +19 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
- LightboxClient
|
|
7
|
+
- LightboxApp
|
|
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 style of the lightbox
|
|
15
|
+
- It will define the callbacks for each lightbox event
|
|
16
|
+
|
|
17
|
+
On site B LightboxApp will be used (site that will be shown in a lightbox)
|
|
18
|
+
|
|
19
|
+
- Define the event emission logic
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Styles, Ids } from '@/constants';
|
|
2
|
+
export var mountListener = function (callbacks) {
|
|
3
|
+
if (!callbacks)
|
|
4
|
+
return;
|
|
5
|
+
var listener = function (event) {
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.data);
|
|
8
|
+
unmountLightbox(listener);
|
|
9
|
+
};
|
|
10
|
+
globalThis.addEventListener('message', listener);
|
|
11
|
+
};
|
|
12
|
+
export var mountIFrameElement = function (url, styles) {
|
|
13
|
+
var wrapper = document.createElement('div');
|
|
14
|
+
wrapper.id = Ids.WRAPPER_ID;
|
|
15
|
+
var iframe = document.createElement('iframe');
|
|
16
|
+
iframe.src = url;
|
|
17
|
+
iframe.id = Ids.IFRAME_ID;
|
|
18
|
+
mountStyles(styles);
|
|
19
|
+
document.body.appendChild(wrapper);
|
|
20
|
+
wrapper.appendChild(iframe);
|
|
21
|
+
};
|
|
22
|
+
var mountStyles = function (styles) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
24
|
+
var 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, function (m, r, g, b) { return '#' + r + r + g + g + b + b; }).substring(1).match(/.{2}/g)) === null || _c === void 0 ? void 0 : _c.map(function (x) { return parseInt(x, 16); })) !== null && _d !== void 0 ? _d : [107, 114, 128];
|
|
25
|
+
background.push((_f = (_e = styles.background) === null || _e === void 0 ? void 0 : _e.opacity) !== null && _f !== void 0 ? _f : 0.75);
|
|
26
|
+
document.documentElement.style.setProperty(Styles.BACKGROUND_COLOR, "rgb(".concat(background.join(', '), ")"));
|
|
27
|
+
var rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
|
|
28
|
+
document.documentElement.style.setProperty(Styles.ROUNDED, "".concat(rounded.toString(), "px"));
|
|
29
|
+
};
|
|
30
|
+
var unmountLightbox = function (listener) {
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = document.getElementById(Ids.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
33
|
+
globalThis.removeEventListener('message', listener);
|
|
34
|
+
document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
|
|
35
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mountIFrameElement, mountListener } from './assemblers';
|
|
2
|
+
export var LightboxClient = {
|
|
3
|
+
init: function (url, options) {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
var lightbox = {
|
|
6
|
+
callbacks: (_a = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _a !== void 0 ? _a : {},
|
|
7
|
+
styles: (_b = options === null || options === void 0 ? void 0 : options.styles) !== null && _b !== void 0 ? _b : {},
|
|
8
|
+
open: function () {
|
|
9
|
+
mountListener(lightbox.callbacks);
|
|
10
|
+
mountIFrameElement(url, lightbox.styles);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
if (options === null || options === void 0 ? void 0 : options.dispatch)
|
|
14
|
+
lightbox.open();
|
|
15
|
+
console.log("lightbox-sdk | client initialized (".concat(url, ")"));
|
|
16
|
+
return lightbox;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var Styles = {
|
|
2
|
+
BACKGROUND_COLOR: '--placetopay-lightbox-background-color',
|
|
3
|
+
ROUNDED: '--placetopay-lightbox-border-radius',
|
|
4
|
+
};
|
|
5
|
+
export var Ids = {
|
|
6
|
+
WRAPPER_ID: 'placetopay_lightbox_wrapper',
|
|
7
|
+
IFRAME_ID: 'placetopay_lightbox',
|
|
8
|
+
STYLES_ID: 'placetopay-lightbox',
|
|
9
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare type ClientCallback = (data: unknown) => void;
|
|
2
|
+
export declare type ClientCallbacks = {
|
|
3
|
+
[key: string]: ClientCallback | undefined;
|
|
4
|
+
};
|
|
5
|
+
export declare type ClientStyles = {
|
|
6
|
+
background?: {
|
|
7
|
+
color?: string;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
};
|
|
10
|
+
rounded?: number;
|
|
11
|
+
dimension?: 'sm' | 'md' | 'lg';
|
|
12
|
+
height?: number;
|
|
13
|
+
width?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare type InitOptions = {
|
|
16
|
+
dispatch?: boolean;
|
|
17
|
+
callbacks?: ClientCallbacks;
|
|
18
|
+
styles?: ClientStyles;
|
|
19
|
+
};
|
|
20
|
+
export declare type ApiStructure = {
|
|
21
|
+
data: unknown;
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
export declare type LightboxInstance = {
|
|
25
|
+
styles: ClientStyles;
|
|
26
|
+
callbacks: ClientCallbacks;
|
|
27
|
+
open: () => void;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#placetopay_lightbox_wrapper {
|
|
2
|
+
background: var(--placetopay-lightbox-background-color);
|
|
3
|
+
position: fixed;
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
align-items: center;
|
|
7
|
+
top: 0;
|
|
8
|
+
left: 0;
|
|
9
|
+
width: 100vw;
|
|
10
|
+
height: 100vh;
|
|
11
|
+
z-index: 999;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#placetopay_lightbox {
|
|
15
|
+
border: 0;
|
|
16
|
+
border-radius: var(--placetopay-lightbox-border-radius);
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
background-color: white;
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@placetopay/lightbox-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Small javascript library to encapsulate websites in a lightbox with configurable styles and behaviors",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist/lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "vite",
|
|
12
|
+
"prebuild": "npm run clean-build",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"postbuild": "copyfiles -u 1 src/**/*.css dist/",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
|
+
"clean-build": "rimraf dist/",
|
|
17
|
+
"format": "npx prettier --write .",
|
|
18
|
+
"format:check": "npx prettier --check .",
|
|
19
|
+
"lint": "npx eslint --ext .ts --fix ./",
|
|
20
|
+
"lint:check": "npx eslint --ext .ts .",
|
|
21
|
+
"foli": "npm run format & npm run lint",
|
|
22
|
+
"foli:check": "npm run format:check & npm run lint:check"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://JuanZea@bitbucket.org/placetopay/lightbox-sdk.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"lightbox",
|
|
30
|
+
"sdk",
|
|
31
|
+
"javascript",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "JuanZea",
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://bitbucket.org/placetopay/lightbox-sdk/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://bitbucket.org/placetopay/lightbox-sdk#readme",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^18.7.23",
|
|
42
|
+
"@types/react": "^18.0.21",
|
|
43
|
+
"@types/react-dom": "^18.0.6",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
|
45
|
+
"@typescript-eslint/parser": "^5.38.1",
|
|
46
|
+
"@vitejs/plugin-react": "^2.1.0",
|
|
47
|
+
"copyfiles": "^2.4.1",
|
|
48
|
+
"eslint": "^8.24.0",
|
|
49
|
+
"prettier": "^2.7.1",
|
|
50
|
+
"react": "^18.2.0",
|
|
51
|
+
"react-dom": "^18.2.0",
|
|
52
|
+
"rimraf": "^3.0.2",
|
|
53
|
+
"typescript": "^4.8.3",
|
|
54
|
+
"vite": "^3.1.4"
|
|
55
|
+
}
|
|
56
|
+
}
|